@wcstack/state 1.23.0 → 1.25.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.d.ts +0 -2
- package/dist/index.esm.js +417 -159
- 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
|
-
function e(){const e=document.documentElement;return!!e&&e.hasAttribute("data-wcs-server")}const t={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,enableDirectionalInitialSync:!0,enablePropagationContext:!0,enableContractAnalyzer:!1,sameValueGuard:!0},n=t;function o(){return n}const s=new WeakMap,r=new WeakSet;let i=0;async function a(e){const t=function(e){let t,n=s.get(e)||null;if(null!==n)return n;const o=new Promise(e=>{t=e});return n={id:++i,promise:o,resolve:t},s.set(e,n),r.has(e)&&n.resolve(),n}(e);await t.promise}function l(e){const t=s.get(e);void 0===t?r.add(e):t.resolve()}const c=".",d="*",u=128,f="|",p={};for(let e=0;e<128;e++)p[`$${e+1}`]=e;const h=Object.freeze(p),m="$connectedCallback",g="$disconnectedCallback",y="$updatedCallback",b="$stateReadyCallback",w="$bindables",v="$commandTokens",N="$command",S="$eventTokens",x="$on",I="$streams",A="$streamStatus",P="$streamError",_="data-wc-definition",$=new Map;let T=0;function k(e){let t=$.get(e);return void 0!==t||(t=Object.freeze(new C(e)),$.set(e,t)),t}class C{id=++T;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:k(t),n=e.split("."),o=[],s=[],r=[],i={},a=[],l=[],c=[],u=[];let f="",p="",h=0;for(let e=0;e<n.length;e++)f+=n[e],n[e]===d&&(r.push(f),i[f]=h,a.push(t(f)),l.push(p),c.push(t(p)),u.push(e),h++),o.push(f),s.push(t(f)),p=f,f+=".";const m=r.length>0?r[r.length-1]:null,g=o.length>1?o[o.length-2]:null;this.path=e,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=o,this.cumulativePathSet=new Set(o),this.cumulativePathInfos=s,this.cumulativePathInfoSet=new Set(s),this.wildcardPaths=r,this.wildcardPathSet=new Set(r),this.indexByWildcardPath=i,this.wildcardPathInfos=a,this.wildcardPathInfoSet=new Set(a),this.wildcardParentPaths=l,this.wildcardParentPathSet=new Set(l),this.wildcardParentPathInfos=c,this.wildcardParentPathInfoSet=new Set(c),this.wildcardPositions=u,this.lastWildcardPath=m,this.lastWildcardInfo=m?t(m):null,this.parentPath=g,this.parentPathInfo=g?t(g):null,this.wildcardCount=h}}const E=new WeakMap;function M(e){const t=E.get(e);if(void 0!==t)return t;let n=null;try{if(e.nodeType!==Node.ELEMENT_NODE)return n;const t=e,o=t.tagName.toLowerCase();if(o.includes("-"))return n=o;if(t.hasAttribute("is")){const e=t.getAttribute("is");if(e.includes("-"))return n=e}return n}finally{E.set(e,n)}}function O(e=null){const t=globalThis.customElements,n=e?.customElements??t;if("object"!=typeof n||null===n)return null;const o=n;return"function"!=typeof o.get||"function"!=typeof o.whenDefined?null:o}function D(e,t){e.upgrade?.(t)}function R(e){try{if(null===e||"object"!=typeof e&&"function"!=typeof e)return null;const t=e,n=t.addEventListener,o=t.removeEventListener,s=t.constructor?.wcBindable;if("function"!=typeof n||"function"!=typeof o)return null;if("wc-bindable"!==s?.protocol)return null;if(!Number.isInteger(s.version)||s.version<1)return null;const r=j(s.properties,L);if(null===r)return null;const i=void 0===s.inputs?new Map:j(s.inputs,W);if(null===i)return null;const a=void 0===s.commands?new Map:j(s.commands,B);return null===a?null:{target:e,liveDeclaration:s,knownProperties:r,declaredInputs:i,declaredCommands:a}}catch{return null}}function L(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&("string"==typeof t.event&&0!==t.event.length&&(void 0===t.getter||"function"==typeof t.getter))}function W(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.attribute||"string"==typeof t.attribute)}function B(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.async||"boolean"==typeof t.async)}function j(e,t){if(!Array.isArray(e))return null;const n=new Map;for(const o of e){if(!t(o)||n.has(o.name))return null;n.set(o.name,o)}return n}function F(e){throw new Error(`[@wcstack/state] ${e}`)}function z(e,t,n){const o="."===t?`.${e}`:`${t}.${e}`;return{propName:e,propSegments:[e],propModifiers:[],statePathName:o,statePathInfo:k(o),stateName:n,inFilters:[],outFilters:[],bindingType:"prop"}}function q(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function U(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 V=new WeakMap;function H(e){return V.get(e)||null}function G(e,t){V.set(e,t)}const J=new Set(["if","elseif","else","for"]);function K(e){F(`filter ${e} requires at least one option`)}function X(e){F(`filter ${e} requires a number as option`)}function Y(e){F(`filter ${e} requires a number value`)}function Q(e){F(`filter ${e} requires a date value`)}function Z(e){return!(!e||isNaN(Number(e)))}const ee={eq:e=>{const t=e?.[0]??K("eq");return e=>"number"==typeof e?(Z(t)||X("eq"),e===Number(t)):e===t},ne:e=>{const t=e?.[0]??K("ne");return e=>"number"==typeof e?(Z(t)||X("ne"),e!==Number(t)):e!==t},not:e=>e=>("boolean"!=typeof e&&F(`filter ${"not"} requires a boolean value`),!e),lt:e=>{const t=e?.[0]??K("lt");return Z(t)||X("lt"),e=>("number"!=typeof e&&Y("lt"),e<Number(t))},le:e=>{const t=e?.[0]??K("le");return Z(t)||X("le"),e=>("number"!=typeof e&&Y("le"),e<=Number(t))},gt:e=>{const t=e?.[0]??K("gt");return Z(t)||X("gt"),e=>("number"!=typeof e&&Y("gt"),e>Number(t))},ge:e=>{const t=e?.[0]??K("ge");return Z(t)||X("ge"),e=>("number"!=typeof e&&Y("ge"),e>=Number(t))},inc:e=>{const t=e?.[0]??K("inc");return Z(t)||X("inc"),e=>("number"!=typeof e&&Y("inc"),e+Number(t))},dec:e=>{const t=e?.[0]??K("dec");return Z(t)||X("dec"),e=>("number"!=typeof e&&Y("dec"),e-Number(t))},mul:e=>{const t=e?.[0]??K("mul");return Z(t)||X("mul"),e=>("number"!=typeof e&&Y("mul"),e*Number(t))},div:e=>{const t=e?.[0]??K("div");return Z(t)||X("div"),e=>("number"!=typeof e&&Y("div"),e/Number(t))},mod:e=>{const t=e?.[0]??K("mod");return Z(t)||X("mod"),e=>("number"!=typeof e&&Y("mod"),e%Number(t))},fix:e=>{const t=e?.[0]??"0";return Z(t)||X("fix"),e=>("number"!=typeof e&&Y("fix"),e.toFixed(Number(t)))},locale:e=>{const t=e?.[0]??n.locale;return e=>("number"!=typeof e&&Y("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]??K("slice");Z(n)||X("slice"),t.push(Number(n));const o=e?.[1];return void 0!==o&&(Z(o)||X("slice"),t.push(Number(o))),e=>String(e).slice(...t)},substr:e=>{const t=e?.[0]??K("substr");Z(t)||X("substr");const n=e?.[1]??K("substr");return Z(n)||X("substr"),e=>String(e).substr(Number(t),Number(n))},pad:e=>{const t=e?.[0]??K("pad");Z(t)||X("pad");const n=e?.[1]??"0";return e=>String(e).padStart(Number(t),n)},rep:e=>{const t=e?.[0]??K("rep");return Z(t)||X("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 Z(t)||X("round"),e=>{"number"!=typeof e&&Y("round");const n=Math.pow(10,Number(t));return Math.round(e*n)/n}},floor:e=>{const t=e?.[0]??"0";return Z(t)||X("floor"),e=>{"number"!=typeof e&&Y("floor");const n=Math.pow(10,Number(t));return Math.floor(e*n)/n}},ceil:e=>{const t=e?.[0]??"0";return Z(t)||X("ceil"),e=>{"number"!=typeof e&&Y("ceil");const n=Math.pow(10,Number(t));return Math.ceil(e*n)/n}},percent:e=>{const t=e?.[0]??"0";return Z(t)||X("percent"),e=>("number"!=typeof e&&Y("percent"),`${(100*e).toFixed(Number(t))}%`)},date:e=>{const t=e?.[0]??n.locale;return e=>(e instanceof Date||Q("date"),e.toLocaleDateString(t))},time:e=>{const t=e?.[0]??n.locale;return e=>(e instanceof Date||Q("time"),e.toLocaleTimeString(t))},datetime:e=>{const t=e?.[0]??n.locale;return e=>(e instanceof Date||Q("datetime"),e.toLocaleString(t))},ymd:e=>{const t=e?.[0]??"-";return e=>{e instanceof Date||Q("ymd");const n=e.getFullYear().toString(),o=(e.getMonth()+1).toString().padStart(2,"0"),s=e.getDate().toString().padStart(2,"0");return`${n}${t}${o}${t}${s}`}},falsy:e=>e=>!1===e||null==e||0===e||""===e||Number.isNaN(e),truthy:e=>e=>!1!==e&&null!=e&&0!==e&&""!==e&&!Number.isNaN(e),defaults:e=>{const t=e?.[0]??K("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},te=ee,ne={input:ee,output:te},oe=(e,t)=>n=>{const o=n[e];return o||F(`filter not found: ${e}`),o(t)};const se=new Map;function re(e,t){const n=ne[t];return e.map(e=>{const o=e.indexOf("("),s=e.lastIndexOf(")");if(-1!==o&&-1===s&&F(`Invalid filter format: missing closing parenthesis in "${e}"`),-1!==s&&-1===o&&F(`Invalid filter format: missing opening parenthesis in "${e}"`),-1===o){const o=e.trim(),s=`${o}():${t}`;let r=se.get(s);return void 0===r&&(r=oe(o,[])(n),se.set(s,r)),{filterName:o,args:[],filterFn:r}}{const r=e.substring(o+1,s),i=e.substring(0,o).trim(),a=function(e){const t=[];let n="",o=null,s=!1;for(let r=0;r<e.length;r++){const i=e[r];o?i===o?o=null:n+=i:'"'===i||"'"===i?(o=i,s=!0):","===i?(t.push(n.trim()),n="",s=!1):n+=i}const r=n.trim();return(r||s)&&t.push(r),t}(r),l=`${i}(${a.join(",")}):${t}`;let c=se.get(l);return void 0===c&&(c=oe(i,a)(n),se.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const ie=e=>e.trim(),ae=new Map;const le=new Map;function ce(e){const t=e.indexOf(f);let n="",o=[],s="",r=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),le.has(s)?r=le.get(s):(o=s.split(f).map(ie),r=re(o,"output"),le.set(s,r))):n=e.trim();const[i,a="default"]=n.split("@").map(ie);return{stateName:a,statePathName:i,statePathInfo:k(i),outFilters:r}}function de(e){const[...t]=e.split(";").map(ie).filter(e=>e.length>0),n=t.map(e=>{const t=e.indexOf(":");-1===t&&F(`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`);const n=e.slice(0,t).trim(),o=e.slice(t+1).trim();if("else"===n){return{propName:"else",propSegments:["else"],propModifiers:[],statePathName:"#else",statePathInfo:k("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("..."===n){const t=ce(o);return t.outFilters.length>0&&F(`Invalid spread binding "${e}": filters are not allowed on spread targets.`),0===t.statePathName.length&&F(`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:[],...ce(o),bindingType:n}}{const e=ce(o),t=function(e){const t=e.indexOf(f);let n="",o=[],s="",r=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),ae.has(s)?r=ae.get(s):(o=s.split(f).map(ie),r=re(o,"input"),ae.set(s,r))):n=e.trim();const[i,a]=n.split("#").map(ie),l=i.split(c).map(ie);return{propName:i,propSegments:l,propModifiers:a?a.split(",").map(ie):[],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=>J.has(e.bindingType))&&F(`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return n}const ue=new WeakMap,fe=new Set([n.commentTextPrefix,n.commentForPrefix,n.commentIfPrefix,n.commentElseIfPrefix,n.commentElsePrefix]),pe=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function he(e){const t=ue.get(e);if("string"==typeof t)return t;if(e.nodeType!==Node.COMMENT_NODE)return null;const o=e.data.trim(),s=pe.exec(o);if(null===s)return null;const r=s[1]||n.commentTextPrefix;return fe.has(r)?(ue.set(e,s[2]),s[2]):null}const me=new Map;function ge(e,t,n){if(null===n)me.delete(e);else{me.set(e,n);const o=n.parseBindTextResult,s=Zs(t,o.stateName);null===s&&F(`State element with name "${o.stateName}" not found for fragment info.`),s.setPathInfo(o.statePathName,o.bindingType);for(const e of n.nodeInfos)for(const n of e.parseBindTextResults){const e=Zs(t,n.stateName);null===e&&F(`State element with name "${n.stateName}" not found for fragment info node.`),e.setPathInfo(n.statePathName,n.bindingType)}}}function ye(e){return me.get(e)||null}function be(e){if(e.nodeType===Node.ELEMENT_NODE){return de(e.getAttribute(n.bindAttributeName)||"")}if(e.nodeType===Node.COMMENT_NODE){const t=he(e);null===t&&F("Comment node binding text not found.");const n=ye(t);let o=n?.parseBindTextResult??null,s=null;return null===o?(o={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...ce(t),bindingType:"text"},s=null):s=t,[{...o,uuid:s}]}return[]}function we(e){const t=[],o=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(e){if(e.nodeType===Node.ELEMENT_NODE){return e.hasAttribute(n.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==he(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;o.nextNode();)t.push(o.currentNode);return t}const ve=new WeakSet;function Ne(e,t,o){const s=function(e,t,o={}){const s=o.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&&F("Spread binding requires an element node.");const t=e,o=M(t);null===o&&F(`Spread binding "${n.statePathName}" requires a custom element with wcBindable, but <${t.tagName.toLowerCase()}> is not a custom element.`);const a=O();if(null===a&&F(`CustomElementRegistry is unavailable for <${o}>.`),void 0===a.get(o)){s||F(`Spread binding "${n.statePathName}" requires <${o}> to be registered. Define the custom element before initializing this binding.`),r.push(n);continue}D(a,t);const l=R(t);null===l&&F(`Spread binding "${n.statePathName}" requires <${o}> to expose a valid wcBindable declaration.`);const c=n.statePathName,d=n.stateName,u=new Set;for(const e of l.knownProperties.keys()){if(u.has(e))continue;u.add(e);const t=z(e,c,d);i.add(t),r.push(t)}for(const e of l.declaredInputs.keys()){if(u.has(e))continue;u.add(e);const t=z(e,c,d);i.add(t),r.push(t)}}const a=new Map;for(let e=0;e<r.length;e++){const t=q(r[e]);null!==t&&a.set(t,e)}const l=[];for(let t=0;t<r.length;t++){const o=q(r[t]);if(null!==o){if(a.get(o)===t)l.push(r[t]);else if(n.debug&&i.has(r[t])){const n=r[a.get(o)],s=e.nodeType===Node.ELEMENT_NODE?`<${e.tagName.toLowerCase()}>`:"node";console.debug(`[@wcstack/state] spread: prop "${r[t].propName}" of ${s} overridden by explicit binding (statePath: "${n.statePathName}").`)}}else l.push(r[t])}return l}(e,t,{allowDeferred:o.allowDeferred});if(s.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?M(e):null;return null===n&&F("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t}}}ve.add(e);const r=function(e,t){const n=[];for(const o of t)if("text"!==o.bindingType)n.push({...o,node:e,replaceNode:e});else{const t=e.nodeType===Node.TEXT_NODE?e:document.createTextNode("");n.push({...o,node:e,replaceNode:t})}return n}(e,s);return G(e,r),l(e),{bindings:r,deferred:null}}function Se(e){const t=we(e),n=[],o=[];for(const e of t){if(ve.has(e))continue;const t=Ne(e,be(e),{allowDeferred:!0});null===t.deferred?n.push(...t.bindings):o.push(t.deferred)}return[t,n,o]}function xe(e){ve.add(e)}function Ie(e){const{node:t,parseResults:n}=e;!function(e){ve.delete(e)}(t);return Ne(t,n,{allowDeferred:!1}).bindings}const Ae=new WeakMap;function Pe(e){let t=e;for(;t;){const e=Ae.get(t);if(e)return e;t=t.parentNode}return null}function _e(e,t){null!==t?Ae.set(e,t):Ae.delete(e)}const $e=new WeakMap;function Te(e){return $e.get(e)??[]}function ke(e,t){$e.set(e,t)}const Ce=Symbol("$$setLoopContextAsync"),Ee=Symbol("$$setLoopContext"),Me=Symbol("$$getByAddress"),Oe=Symbol("$$hasByAddress"),De=Symbol("$$setByAddress"),Re=Symbol("$$connectedCallback"),Le=Symbol("$$disconnectedCallback"),We=Symbol("$$updatedCallback"),Be=new WeakMap;function je(e,t){if(Be.has(e)){const n=Be.get(e);if(n.has(t))return n.get(t)}else Be.set(e,new WeakMap);const n=Object.freeze(new Fe(e,t));return Be.get(e).set(t,n),n}class Fe{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=je(e,t.parentPathInfo)}}const ze=new WeakMap,qe=new WeakMap;class Ue{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]===d?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAbsoluteAddress=Ve(e,t)}}function Ve(e,t){if(null===t){let t=qe.get(e);return void 0!==t||(t=new Ue(e,null),qe.set(e,t)),t}{let n=ze.get(t);void 0===n&&(n=new WeakMap,ze.set(t,n));let o=n.get(e);return void 0!==o||(o=new Ue(e,t),n.set(e,o)),o}}const He=new WeakMap;function Ge(e,t){null===t?He.delete(e):He.set(e,t)}function Je(e){return He.get(e)||null}const Ke=new Map;function Xe(e,t){let n,o;if(0===e.wildcardCount||0===t.wildcardCount)return 0;if(1===e.wildcardCount&&t.wildcardCount>0&&t.wildcardPathSet.has(e.path))return 1;e.id<t.id?(n=e,o=t):(n=t,o=e);const s=`${n.path}\t${o.path}`;let r=Ke.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Ke.set(s,r),r}const Ye=new WeakMap;function Qe(e){const t=Pe(e.node);if(null===t)return null;let n=Ye.get(t);if(void 0===n)n=new WeakMap,Ye.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let o=null;try{const n=Xe(t.pathInfo,e.statePathInfo);return n>0&&(o=t.listIndex.at(n-1)),o}finally{n.set(e,o)}}const Ze=new WeakMap;function et(e,t){if(null!=t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=Je(n);null===t?F(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}return n}function tt(e,t){let n=null;if(n=Ze.get(e)||null,null!==n)return n;const o=et(e,t),s=Qe(e),r=Zs(o,e.stateName);null===r&&F(`State element with name "${e.stateName}" not found for binding.`);return n=Ve(je(r,e.statePathInfo),s),Ze.set(e,n),n}function nt(e){Ze.delete(e)}let ot=null;const st=new WeakMap;function rt(e,t){const n=st.get(e);void 0===n?st.set(e,t):n instanceof Set?n.add(t):n!==t&&st.set(e,new Set([n,t])),null!==ot&&ot({type:"state:binding-added",absoluteAddress:e,binding:t})}function it(e,t){const n=st.get(e);void 0!==n&&(n instanceof Set?n.delete(t):n===t&&st.delete(e),null!==ot&&ot({type:"state:binding-removed",absoluteAddress:e,binding:t}))}const at=new WeakMap;function lt(e){const t=st.get(e);return void 0!==t?t:null!==e.listIndex?at.get(e.absolutePathInfo)?.get(e.listIndex):void 0}const ct=new WeakMap,dt=new WeakMap;class ut{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]===d?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=ft(e,t)}}function ft(e,t){if(null===t){let t=dt.get(e);return void 0!==t||(t=new ut(e,null),dt.set(e,t)),t}{let n=ct.get(t);void 0===n&&(n=new WeakMap,ct.set(t,n));let o=n.get(e);return void 0!==o||(o=new ut(e,t),n.set(e,o)),o}}const pt=new WeakMap;function ht(e){let t=null;if(t=pt.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=Qe(e);null===n&&F(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=ft(e.statePathInfo,n)}else t=ft(e.statePathInfo,null);return pt.set(e,t),t}function mt(e){pt.delete(e)}function gt(){const e=new Map,t=new Map;return{add(n,o){let s=e.get(n);return void 0===s&&(s=new WeakSet,e.set(n,s)),!s.has(o)&&(s.add(o),t.set(n,(t.get(n)??0)+1),!0)},remove(n,o){const s=e.get(n);if(void 0===s||!s.has(o))return!1;s.delete(o);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 yt=new Map,bt=gt();function wt(e,t){const n=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.statePathName}::${t}::${n}`}function vt(e){let t="input";for(const n of e.propModifiers)n.startsWith("on")&&(t=n.slice(2));return t}function Nt(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf("ro")){const s=vt(e),r=wt(e,s);let i=yt.get(r);return void 0===i&&(t=e.stateName,n=e.statePathName,o=e.inFilters,i=e=>{const s=e.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==s.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const r=s.checked;let i=s.value;for(const e of o)i=e.filterFn(i);const a=Zs(s.getRootNode(),t);null===a&&F(`State element with name "${t}" not found for two-way binding.`);const l=Pe(s);a.createState("writable",e=>{e[Ee](l,()=>{let t=e[n];if(Array.isArray(t))if(r)-1===t.indexOf(i)&&(e[n]=t.concat(i));else{const o=t.indexOf(i);-1!==o&&(e[n]=t.toSpliced(o,1))}else e[n]=r?[i]:[]})})},yt.set(r,i)),e.node.addEventListener(s,i),bt.add(r,e),!0}var t,n,o;return!1}class St{_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 xt extends St{_ownerStateName;constructor(e,t){super(e),this._ownerStateName=t??null}emit(...e){return null!==ot&&ot({type:"state:token-emit",kind:"event",stateName:this._ownerStateName,tokenName:this.name,args:e,subscriberCount:this.size}),super.emit(...e)}}const It=new WeakMap;function At(e,t){let n=It.get(e);void 0===n&&(n=new Map,It.set(e,n));let o=n.get(t);return void 0===o&&(o=new xt(t,e.name),n.set(t,o)),o}function Pt(e){It.delete(e)}const _t=new WeakMap;function $t(e){if("eventToken"!==e.propSegments[0])return!1;const t=e.node,n=M(t),o=O();if(null!==n&&void 0===o?.get(n))return null===o&&F(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(_t.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||F('eventToken binding requires a property name (e.g., "eventToken.error").');const r=function(e){return null===M(e)?null:R(e)}(t);null===r&&F(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const i=r.knownProperties.get(s);void 0===i&&F(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.`);const a=i.event,l=e.statePathName,c=e.stateName,d=e.propModifiers,u=e=>{d.includes("prevent")&&e.preventDefault(),d.includes("stop")&&e.stopPropagation();const n=Zs(t.getRootNode(),c);null===n&&F(`State element with name "${c}" not found for eventToken handler.`),n.eventTokenNames.has(l)||F(`eventToken "${l}" is not declared in $eventTokens of state "${c}".`);const o=Pe(t);n.createStateAsync("writable",async t=>{t[Ee](o,()=>{const s=o?.listIndex.indexes??[];return At(n,l).emit(t,e,...s)})})};return t.addEventListener(a,u),_t.set(e,{eventName:a,handler:u}),!0}class Tt extends St{_ownerStateName;constructor(e,t){super(e),this._ownerStateName=t??null}emit(...e){return null!==ot&&ot({type:"state:token-emit",kind:"command",stateName:this._ownerStateName,tokenName:this.name,args:e,subscriberCount:this.size}),super.emit(...e)}}function kt(e){return e instanceof Tt}const Ct=new Map,Et=gt();function Mt(e){const t=e.propModifiers.filter(e=>"prevent"===e||"stop"===e).sort().join(",");return`${e.stateName}::${e.statePathName}::${t}`}const Ot=(e,t,n,o)=>s=>{n.includes("prevent")&&s.preventDefault(),n.includes("stop")&&s.stopPropagation();const r=s.target,i=Zs(r.getRootNode(),e);null===i&&F(`State element with name "${e}" not found for event handler.`);const a=Pe(r),l=t.startsWith(N+".");i.createStateAsync("writable",async n=>{n[Ee](a,()=>{const r=a?.listIndex.indexes??[];if(l){const e=n[Me](ft(o,null));return kt(e)||F(`Event binding "${t}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),e.emit(s,...r)}const i=n[t];return"function"!=typeof i&&F(`Handler "${t}" is not a function on state "${e}".`),Reflect.apply(i,n,[s,...r])})})};function Dt(e){if(!e.propName.startsWith("on"))return!1;const t=Mt(e);let n=Ct.get(t);void 0===n&&(n=Ot(e.stateName,e.statePathName,e.propModifiers,e.statePathInfo),Ct.set(t,n));const o=e.propName.slice(2);return e.node.addEventListener(o,n),Et.add(t,e),!0}const Rt=new Map,Lt=gt();function Wt(e,t){const n=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.statePathName}::${t}::${n}`}function Bt(e){let t="input";for(const n of e.propModifiers)n.startsWith("on")&&(t=n.slice(2));return t}function jt(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf("ro")){const s=Bt(e),r=Wt(e,s);let i=Rt.get(r);return void 0===i&&(t=e.stateName,n=e.statePathName,o=e.inFilters,i=e=>{const s=e.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==s.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===s.checked)return;let r=s.value;for(const e of o)r=e.filterFn(r);const i=Zs(s.getRootNode(),t);null===i&&F(`State element with name "${t}" not found for two-way binding.`);const a=Pe(s);i.createState("writable",e=>{e[Ee](a,()=>{e[n]=r})})},Rt.set(r,i)),e.node.addEventListener(s,i),Lt.add(r,e),!0}var t,n,o;return!1}const Ft=new Set(["radio","checkbox"]),zt=new Set(["value","valueAsNumber","valueAsDate"]);function qt(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return!1;const n=e,o=n.tagName.toLowerCase();if("input"===o){const e=(n.getAttribute("type")||"text").toLowerCase();if("button"===e)return!1;if(Ft.has(e)&&"checked"===t)return!0;if(zt.has(t))return!0}if("select"===o&&"value"===t)return!0;if("textarea"===o&&"value"===t)return!0;const s=M(n);if(null!==s){const e=O()?.get(s);void 0===e&&F(`Custom element <${s}> is not defined. Cannot determine if property "${t}" is suitable for two-way binding.`);const o=R(n);if(o?.knownProperties.has(t))return!0}return!1}let Ut=1,Vt=1,Ht=1;const Gt=new WeakMap;function Jt(e,t,n,o){let s=Gt.get(e);void 0===s&&(s=new Map,Gt.set(e,s));const r=function(e,t,n){return`${t}::${n}::${e}`}(t,n,o);let i=s.get(r);return void 0===i&&(i=Ut++,s.set(r,i)),i}function Kt(e,t){return"to-element"===t?2*e:2*e+1}const Xt=new Set;function Yt(e){return{transactionId:Vt++,originBindingId:e,visitedEdges:Xt,hop:0}}function Qt(e,t){const n=new Set(e.visitedEdges);return n.add(t),{transactionId:e.transactionId,originBindingId:e.originBindingId,visitedEdges:n,hop:e.hop+1}}let Zt=null;function en(){return Zt}function tn(e,t){const n=Zt;Zt=e;try{return t()}finally{Zt=n}}const nn=[];const on=new Map,sn=gt(),rn=new WeakMap,an=e=>e.detail;function ln(e,t,n){const o=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.propName}::${e.statePathName}::${t}::${o}::${n?"g":"n"}`}function cn(e){let t="select"===e.node.tagName.toLowerCase()?"change":"input";const n=M(e.node);if(null!==n){const o=O()?.get(n);void 0===o&&F(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=R(e.node)?.knownProperties.get(e.propName);s&&(t=s.event)}for(const n of e.propModifiers)n.startsWith("on")&&(t=n.slice(2));return t}function dn(e){if(null!==M(e.node)){const t=R(e.node)?.knownProperties.get(e.propName);if(t)return t.getter??an}return null}const un=(e,t,o,s,r)=>i=>{const a=i.target;if(null===a)return void console.warn("[@wcstack/state] event.target is null.");let l;if(null!==r)l=r(i);else{if(!(t in a))return void console.warn(`[@wcstack/state] Property "${t}" does not exist on target element.`);l=a[t]}let c=l;for(const e of s)c=e.filterFn(c);const d=rn.get(a)?.get(t);if(void 0!==d)for(const e of d)e(c);let u=null;if(n.enablePropagationContext){const s=Jt(a,t,e,o),r=function(e,t){for(let n=nn.length-1;n>=0;n--){const o=nn[n];if(o.node===e&&o.receipt.member===t)return o.receipt}return null}(a,t);if(null!==r&&Object.is(r.writtenValue,l))return n.debug&&console.debug("[@wcstack/state] propagation: write confirmation suppressed echo.",{node:a,propName:t,statePathName:o,transactionId:r.transactionId,coveredBySameValueGuard:n.sameValueGuard&&(null===c||"object"!=typeof c)}),void(null!==ot&&ot({type:"propagation:suppressed",reason:"confirmation",transactionId:r.transactionId,edgeId:Kt(s,"to-state"),node:a,member:t}));const i=Kt(s,"to-state"),d=en();if(null!==d&&d.visitedEdges.has(i))return void(null!==ot&&ot({type:"propagation:suppressed",reason:"visited-edge",transactionId:d.transactionId,edgeId:i,node:a,member:t}));u=Qt(d??Yt(s),i)}const f=Zs(a.getRootNode(),e);null===f&&F(`State element with name "${e}" not found for two-way binding.`);const p=Pe(a),h=()=>{f.createState("writable",e=>{e[Ee](p,()=>{e[o]=c})})};null!==u?tn(u,h):h()};const fn=new WeakSet;function pn(e){fn.add(e)}function hn(e){return!!fn.has(e)&&(fn.delete(e),!0)}const mn=new WeakSet;function gn(e){mn.add(e)}function yn(e){return!!mn.has(e)&&(mn.delete(e),!0)}let bn=0;function wn(){bn--}function vn(){return bn>0}class Nn{registry;entries=new Map;constructor(e){this.registry=e}wait(e,t,n=()=>{}){const o=e.toLowerCase();let s=this.entries.get(o);void 0===s&&(s={waiters:new Set},this.entries.set(o,s),this.registry.whenDefined(o).then(()=>this.settle(o,null),e=>this.settle(o,e)));const r={active:!0,resolve:t,reject:n};return s.waiters.add(r),()=>{r.active&&(r.active=!1,s?.waiters.delete(r))}}pendingCount(e){return this.entries.get(e.toLowerCase())?.waiters.size??0}settle(e,t){const n=this.entries.get(e);if(void 0===n)return;this.entries.delete(e);const o=Array.from(n.waiters);n.waiters.clear();for(const e of o)e.active&&(e.active=!1,null===t?e.resolve():e.reject(t))}}const Sn=new WeakMap;function xn(e){let t=Sn.get(e);return void 0===t&&(t=new Nn(e),Sn.set(e,t)),t}function In(e,t){let n=null;for(const o of e.propModifiers){const e=o.indexOf("=");if(e<0)continue;const s=o.slice(0,e).trim(),r=o.slice(e+1).trim();"init"!==s&&"sync"!==s&&F(`Unknown binding modifier "${s}" in "${o}".`),s===t&&(null!==n&&F(`Binding modifier "${t}" may only be specified once.`),n=r)}return n}function An(e){return e.propModifiers.some(e=>e.includes("="))}const Pn=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),_n=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function $n(e,t){return"state"===e&&"call"===t?Pn:{authority:e,syncOn:t,observable:!1,outputOnly:!1}}function Tn(e){if(!n.enableDirectionalInitialSync)return An(e)&&F("init=/sync= modifiers require enableDirectionalInitialSync."),Pn;const t=null===(o=In(e,"init"))?null:"state"===o||"element"===o||"auto"===o||"none"===o?o:F(`Invalid init modifier value "${o}".`);var o;const s=function(e){return null===e||"call"===e?"call":"connect"===e?"connect":F(`Invalid sync modifier value "${e}".`)}(In(e,"sync"));if("event"===e.bindingType)return null!==t&&"none"!==t&&F("Event bindings only allow init=none."),"call"===s?_n:{authority:"none",syncOn:s,observable:!1,outputOnly:!1};if("command"===e.propSegments[0])return $n("state",s);if("prop"!==e.bindingType)return null!==t&&"state"!==t&&"none"!==t&&F(`Binding type "${e.bindingType}" does not support init=${t}.`),$n(t??"state",s);const r=R(e.node);if(null===r)return $n(t??"state",s);const i=r.knownProperties.has(e.propName),a=r.declaredInputs.has(e.propName);i||a||F(`Property "${e.propName}" is not declared by wcBindable.`);const l=t??(i&&!a?"element":"state");return(i&&a?new Set(["state","element","auto","none"]):i?new Set(["element","none"]):new Set(["state","none"])).has(l)||F(`init=${l} is incompatible with wcBindable member "${e.propName}".`),"connect"!==s||i||F(`sync=connect requires observable property "${e.propName}".`),{authority:l,syncOn:s,observable:i,outputOnly:i&&!a}}function kn(e,t){return"auto"!==t?t:function(e){const t=Zs(e.replaceNode.getRootNode(),e.stateName);null===t&&F(`State element with name "${e.stateName}" not found for binding.`);const n=ht(e);let o=!1;return t.createState("readonly",e=>{o=e[Oe](n)}),o}(e)?"state":"element"}let Cn=0,En=0;const Mn=new WeakMap,On=new WeakMap,Dn=new WeakMap,Rn=new WeakMap;function Ln(e,t){const n=Rn.get(e);void 0!==n?n!==t&&(n instanceof Set?n.add(t):Rn.set(e,new Set([n,t]))):Rn.set(e,t)}function Wn(e,t){const n=Rn.get(e);if(void 0!==n)if(n instanceof Set)for(const e of Array.from(n))t(e);else t(n)}function Bn(e,t){if(t(e),null!==e.firstChild)for(const n of Array.from(e.childNodes))Bn(n,t)}function jn(e){if("object"!=typeof e||null===e)return!1;const t=e;return 9===t.nodeType||11===t.nodeType&&"host"in t}class Fn{root;observer;constructor(e){this.root=e;const t=globalThis.MutationObserver;this.observer="function"==typeof t?new t(e=>this.handleMutations(e)):null,this.observer?.observe(e,{childList:!0,subtree:!0})}handleMutations(e){const t=[],n=[];for(const o of e)t.push(...Array.from(o.removedNodes)),n.push(...Array.from(o.addedNodes));const o=[];for(const e of t)hn(e)||Bn(e,e=>{Wn(e,t=>{this.root.contains(e)||t.handleRemovedNode(e)})});for(const e of n)yn(e)&&!vn()||Bn(e,e=>{Wn(e,t=>{this.root.contains(e)&&t.handleAddedNode(e,o)})});o.length>0&&ps(o)}}const zn=new WeakMap;function qn(e){let t=zn.get(e);return void 0===t&&(t=new Fn(e),zn.set(e,t)),t}function Un(e){const t=e.inFilters.map(e=>`${e.filterName}(${e.args.join(",")})`).join("|"),n=e.outFilters.map(e=>`${e.filterName}(${e.args.join(",")})`).join("|");return[e.bindingType,e.propName,e.propModifiers.join(","),e.stateName,e.statePathName,t,n,e.uuid??""].join("\0")}function Vn(e,t){null===e.teardowns&&(e.teardowns=new Set),e.teardowns.add(t)}class Hn{records=new Set;rowPlan=null;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;constructor(e=null){null!==e&&this.observe(e)}initialize(e,t={},n){const o=t.registerAddress??!0,s={registerAddress:o,registerPathInfo:t.registerPathInfo??o,applyOnReconnect:t.applyOnReconnect??!0},r=[];for(const t of e){const e=this.remember(t,s),o=Mn.get(e);void 0===o||"disposed"===o.phase||"failed"===o.phase?(this.start(e,s,n),r.push(e)):(this.observe(o.anchor),s.registerAddress&&null===o.address&&null===o.patternListIndex&&(o.options.registerAddress=!0,this.registerAddress(o)),"active"===o.phase&&this.settleInitialRecord(o),this.settleConnectedSnapshot(o))}return r.filter(e=>this.shouldApplyState(e))}activate(e,t){if(jn(t)&&qn(t),null===this.rowPlan)for(const n of e){const e=Mn.get(n);if(void 0!==e&&e.session===this&&"disposed"!==e.phase&&"failed"!==e.phase){null===e.address&&null===e.patternListIndex&&(e.options.registerAddress=!0,this.registerAddress(e,t)),"active"===e.phase&&this.settleInitialRecord(e),this.settleConnectedSnapshot(e);continue}const o=this.optionsByBinding.get(n);void 0!==o?(o.registerAddress=!0,this.start(n,o,t)):this.initialize([n],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}else this.activatePlanRows(this.rowPlan,e,t)}shouldApplyState(e){if(!n.enableDirectionalInitialSync)return An(e)&&Tn(e),!0;const t=Mn.get(e);return void 0===t||t.session!==this||(!t.options.registerAddress||"waiting-definition"===t.phase||"failed"!==t.phase&&("active"===t.phase&&this.settleInitialRecord(t),t.initialApplyDone?"state"===t.resolvedAuthority||!t.outputOnlyMember&&!t.observationPending:(t.initialApplyDone=!0,"state"===t.resolvedAuthority)))}getRecord(e){const t=Mn.get(e);return t?.session===this?t:null}addTeardown(e,t){const n=Mn.get(e);return!(void 0===n||!this.isAlive(n,n.generation))&&(Vn(n,t),!0)}deferUntilDefined(e,t,n,o=()=>{}){const s=O();null===s&&F(`CustomElementRegistry is unavailable for <${t}>.`),this.observe(e),Ln(e,this);const r={node:e,active:!0,cancel:null};let i=this.deferredByNode.get(e);void 0===i&&(i=new Set,this.deferredByNode.set(e,i)),i.add(r),this.deferred.add(r);const a=()=>!!r.active&&(r.active=!1,i?.delete(r),this.deferred.delete(r),!0);return r.cancel=xn(s).wait(t,()=>{if(a())try{D(s,e),n()}catch(e){o(e)}},e=>{a()&&o(e)}),()=>{a()&&r.cancel?.()}}disposeBinding(e){const t=Mn.get(e);void 0!==t&&t.session===this&&this.disposeRecord(t)}dispose(){for(const e of Array.from(this.records))this.disposeRecord(e);for(const e of Array.from(this.deferred))e.active=!1,e.cancel?.(),this.deferred.delete(e),this.deferredByNode.get(e.node)?.delete(e)}canWholesaleDestroy(){if(this.deferred.size>0)return!1;for(const e of this.records)if(e.pendingDefinitions>0||e.observationPending)return!1;return!0}destroyRecords(){for(const e of this.records)null!==e.address&&(it(e.address,e.info),e.address=null),e.phase="disposed",e.teardowns=null;this.records.clear()}observe(e){const t=function(e){const t=e.getRootNode();return jn(t)?t:null}(e);null!==t&&qn(t)}handleMutations(e,t,n){for(const n of t)Bn(n,t=>{e.contains(t)||this.handleRemovedNode(t)});const o=[];for(const t of n)Bn(t,t=>{e.contains(t)&&this.handleAddedNode(t,o)});o.length>0&&ps(o)}handleRemovedNode(e){const t=this.knownBindingsByNode.get(e);if(void 0!==t)if(t instanceof Map)for(const e of t.values())this.disposeBinding(e);else this.disposeBinding(t);const n=this.deferredByNode.get(e);if(void 0!==n)for(const e of Array.from(n))e.active=!1,e.cancel?.(),n.delete(e),this.deferred.delete(e)}handleAddedNode(e,t){const n=this.knownBindingsByNode.get(e);if(void 0===n)return;const o=n instanceof Map?n.values():[n];for(const e of o){const n=Mn.get(e);if("active"===n?.phase){this.settleConnectedSnapshot(n);continue}if("disposed"!==n?.phase)continue;const o=this.optionsByBinding.get(e);if(void 0!==o)try{this.start(e,o),o.applyOnReconnect&&this.shouldApplyState(e)&&t.push(e)}catch{}}}knownMapFor(e){const t=this.knownBindingsByNode.get(e);if(t instanceof Map)return t;const n=new Map;if(void 0!==t){let e=Dn.get(t);void 0===e&&(e=Un(t),Dn.set(t,e)),n.set(e,t)}return this.knownBindingsByNode.set(e,n),n}remember(e,t){const n=e.replaceNode;Ln(n,this);const o=this.knownMapFor(n);let s=Dn.get(e);void 0===s&&(s=Un(e),Dn.set(e,s));const r=o.get(s);if(void 0!==r){const e=this.optionsByBinding.get(r);return void 0!==e&&(e.registerAddress||=t.registerAddress,e.registerPathInfo||=t.registerPathInfo,e.applyOnReconnect||=t.applyOnReconnect),r}return o.set(s,e),this.optionsByBinding.set(e,{...t}),e}initializeRow(e,t){this.rowPlan=e;const n={registerAddress:!1,registerPathInfo:!1,applyOnReconnect:!1},o=e.slots;for(let e=0;e<t.length;e++){const s=t[e],r=o[e],i=s.replaceNode;Ln(i,this),this.addKnownRowBinding(i,s,e),this.optionsByBinding.set(s,n);const a={id:++Cn,info:s,generation:++En,phase:"active",teardowns:null,session:this,anchor:i,options:n,address:null,patternPathInfo:null,patternListIndex:null,pendingDefinitions:0,initialPolicy:r.policy,resolvedAuthority:r.authority,initialSettled:!0,initialApplyDone:!1,outputOnlyMember:r.policy.outputOnly,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};if(Mn.set(s,a),this.records.add(a),r.isEvent){try{Dt(s)}catch(e){throw a.phase="failed",this.runTeardowns(a),this.records.delete(a),e}a.eventAttached=!0}}}activatePlanRows(e,t,n){const o=e.slots;for(let e=0;e<t.length;e++){const s=t[e],r=Mn.get(s);if(void 0!==r&&r.session===this){if(r.options.registerAddress=!0,"disposed"===r.phase||"failed"===r.phase){const t=o[e];if(r.generation=++En,r.phase="active",r.initialPolicy=t.policy,r.resolvedAuthority=t.authority,r.initialSettled=!0,r.initialApplyDone=!1,r.outputOnlyMember=t.policy.outputOnly,this.records.add(r),t.isEvent){try{Dt(s)}catch(e){throw r.phase="failed",this.runTeardowns(r),this.records.delete(r),e}r.eventAttached=!0}this.registerAddress(r,n);continue}null===r.address&&null===r.patternListIndex&&this.registerAddress(r,n)}else this.initialize([s],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}}addKnownRowBinding(e,t,n){const o=this.knownBindingsByNode.get(e);if(void 0===o)return void this.knownBindingsByNode.set(e,t);if(o instanceof Map)return void o.set("@plan:"+n,t);const s=new Map;s.set("@plan:first",o),s.set("@plan:"+n,t),this.knownBindingsByNode.set(e,s)}start(e,t,n){!function(e){const t=e.node,n=e.replaceNode;t!==n&&null!==t.parentNode&&t.parentNode.replaceChild(n,t)}(e);const o=this.optionsByBinding.get(e)??{...t},s={id:++Cn,info:e,generation:++En,phase:"discovered",teardowns:null,session:this,anchor:e.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,pendingDefinitions:0,initialPolicy:null,resolvedAuthority:null,initialSettled:!1,initialApplyDone:!1,outputOnlyMember:!1,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};Mn.set(e,s),this.records.add(s),void 0===n&&this.observe(s.anchor);try{s.phase="attaching",this.attachListeners(s),s.options.registerAddress&&this.registerAddress(s,n),0===s.pendingDefinitions&&(s.phase="active")}catch(e){throw s.phase="failed",this.runTeardowns(s),this.records.delete(s),e}}attachListeners(e){const t=e.info;Dt(t)?e.eventAttached=!0:"eventToken"!==t.propSegments[0]?(jt(t)&&Vn(e,()=>function(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf("ro")){const t=Bt(e),n=Wt(e,t),o=Rt.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==Lt.countOf(n)&&(Lt.remove(n,e)&&Rt.delete(n),!0))}return!1}(t)),Nt(t)&&Vn(e,()=>function(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf("ro")){const t=vt(e),n=wt(e,t),o=yt.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==bt.countOf(n)&&(bt.remove(n,e)&&yt.delete(n),!0))}return!1}(t)),this.attachAfterDefinition(e,()=>{if(n.enableDirectionalInitialSync&&qt(t.node,t.propName)&&-1===t.propModifiers.indexOf("ro")){const n=function(e,t,n){let o=rn.get(e);void 0===o&&(o=new Map,rn.set(e,o));let s=o.get(t);return void 0===s&&(s=new Set,o.set(t,s)),s.add(n),()=>{s?.delete(n),0===s?.size&&o?.delete(t),0===o?.size&&rn.delete(e)}}(t.node,t.propName,t=>{this.isAlive(e,e.generation)&&(e.eventSequence+=1,e.hasProducerValue=!0,e.producerValue=t)});Vn(e,n)}!function(e){const t=M(e.node);if(null!==t){const e=O(),n=e?.get(t);if(void 0===n)return void(null===e&&F(`CustomElementRegistry is unavailable for <${t}>.`))}if(qt(e.node,e.propName)&&-1===e.propModifiers.indexOf("ro")){const t=cn(e),n=dn(e),o=ln(e,t,null!==n);let s=on.get(o);void 0===s&&(s=un(e.stateName,e.propName,e.statePathName,e.inFilters,n),on.set(o,s)),e.node.addEventListener(t,s),sn.add(o,e)}}(t),e.twowayAttached=!0})):this.attachAfterDefinition(e,()=>{$t(t)&&Vn(e,()=>function(e){if("eventToken"!==e.propSegments[0])return!1;const t=_t.get(e);return void 0!==t&&(e.node.removeEventListener(t.eventName,t.handler),_t.delete(e),!0)}(t))})}attachAfterDefinition(e,t){const n=M(e.info.node);if(null===n)return void t();const o=O();if(null===o&&F(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void t();e.phase="waiting-definition",e.pendingDefinitions+=1;const s=e.generation,r=xn(o).wait(n,()=>{if(this.isAlive(e,s))try{D(o,e.info.node),t(),e.pendingDefinitions-=1,0===e.pendingDefinitions&&(e.phase="active",this.settleInitialRecord(e))}catch{e.phase="failed",this.runTeardowns(e),this.records.delete(e)}},()=>{this.isAlive(e,s)&&(e.phase="failed",this.runTeardowns(e),this.records.delete(e))});Vn(e,r)}settleInitialRecord(e){if(n.enableDirectionalInitialSync&&!e.initialSettled&&e.options.registerAddress){e.phase="synchronizing";try{const t=Tn(e.info),n=kn(e.info,t.authority);if(e.initialPolicy=t,e.resolvedAuthority=n,e.initialSettled=!0,e.outputOnlyMember=t.outputOnly,e.phase="active",!t.observable)return;if("connect"===t.syncOn&&e.info.node instanceof HTMLElement&&!e.info.node.isConnected)return e.observationPending=!0,void bn++;this.readProducerSnapshot(e,"call"===t.syncOn)}catch(t){throw e.phase="failed",this.runTeardowns(e),this.records.delete(e),t}}}readProducerSnapshot(e,t){if(!this.isAlive(e,e.generation))return;const n=e.info.node,o=e.info.propName;if(!(o in n))return;const s=e.eventSequence,r=n[o];e.observationPending&&(e.observationPending=!1,wn()),t&&e.eventSequence!==s||(e.hasProducerValue=!0,e.producerValue=r,"element"===e.resolvedAuthority&&function(e,t){let n=t;for(const t of e.inFilters)n=t.filterFn(n);const o=Zs(e.node.getRootNode(),e.stateName);null===o&&F(`State element with name "${e.stateName}" not found for initial binding sync.`);const s=Pe(e.node);o.createState("writable",t=>{t[Ee](s,()=>{t[e.statePathName]=n})})}(e.info,r))}settleConnectedSnapshot(e){if(n.enableDirectionalInitialSync&&e.observationPending&&e.info.node instanceof HTMLElement&&e.info.node.isConnected)try{this.readProducerSnapshot(e,!1)}catch{e.phase="failed",this.runTeardowns(e),this.records.delete(e)}}registerAddress(e,t){if(null!==e.address||null!==e.patternListIndex)return;const n=e.info,o=Qe(n);if(null!==o){const s=Zs(et(n,t),n.stateName);null===s&&F(`State element with name "${n.stateName}" not found for binding.`);const r=je(s,n.statePathInfo);!function(e,t,n){let o=at.get(e);void 0===o&&(o=new WeakMap,at.set(e,o));const s=o.get(t);void 0===s?o.set(t,n):s instanceof Set?s.add(n):s!==n&&o.set(t,new Set([s,n])),null!==ot&&ot({type:"state:binding-added",absoluteAddress:Ve(e,t),binding:n})}(r,o,n),e.patternPathInfo=r,e.patternListIndex=o}else{const o=tt(n,t);rt(o,n),e.address=o}if(!e.options.registerPathInfo)return;const s=Zs(n.replaceNode.getRootNode(),n.stateName);null===s&&F(`State element with name "${n.stateName}" not found for binding.`),"event"!==n.bindingType&&s.setPathInfo(n.statePathName,n.bindingType)}isAlive(e,t){return e.generation===t&&Mn.get(e.info)===e&&"disposed"!==e.phase&&"failed"!==e.phase}disposeRecord(e){"disposed"!==e.phase&&(e.phase="disposed",this.runTeardowns(e),this.records.delete(e))}runTeardowns(e){e.observationPending&&(e.observationPending=!1,wn());const t=e.info;if(null!==e.address)try{it(e.address,t),e.address=null,mt(t),nt(t)}catch{}else if(null!==e.patternListIndex)try{!function(e,t,n){const o=at.get(e);if(void 0===o)return;const s=o.get(t);void 0!==s&&(s instanceof Set?s.delete(n):s===n&&o.delete(t),null!==ot&&ot({type:"state:binding-removed",absoluteAddress:Ve(e,t),binding:n}))}(e.patternPathInfo,e.patternListIndex,t),e.patternPathInfo=null,e.patternListIndex=null,mt(t),nt(t)}catch{}if(e.twowayAttached){e.twowayAttached=!1;try{!function(e){const t=M(e.node);if(null!==t){const e=O(),n=e?.get(t);if(void 0===n)return}if(qt(e.node,e.propName)&&-1===e.propModifiers.indexOf("ro")){const t=cn(e),n=ln(e,t,null!==dn(e)),o=on.get(n);if(void 0===o)return;e.node.removeEventListener(t,o),sn.remove(n,e)&&on.delete(n)}}(t)}catch{}}if(null!==e.teardowns){const t=Array.from(e.teardowns).reverse();e.teardowns=null;for(const e of t)try{e()}catch{}}if(e.eventAttached){e.eventAttached=!1;try{!function(e){if(!e.propName.startsWith("on"))return!1;const t=Mt(e),n=Ct.get(t);if(void 0===n)return!1;const o=e.propName.slice(2);e.node.removeEventListener(o,n),0!==Et.countOf(t)&&(Et.remove(t,e)&&Ct.delete(t))}(t)}catch{}}}}function Gn(e){let t=On.get(e);return void 0===t&&(t=new Hn(e),On.set(e,t)),t}function Jn(e){return Mn.get(e)?.session??null}const Kn=new WeakMap;function Xn(e,t){const n=Kn.get(e);return!!n&&!0===n.get(t)}function Yn(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const Qn=Object.freeze([]);const Zn=new WeakMap;const eo=new WeakMap;function to(e){return eo.get(e)??[]}function no(e,t){eo.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 oo=0;function so(){return`u${(oo++).toString(36)}`}let ro=0;class io{uuid=so();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=ro}get index(){return this._index}set index(e){this._index=e,this._version=++ro,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=ro),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 ao(e,t){return new io(e,t)}const lo=new WeakMap;function co(e){return lo.get(e)||null}function uo(e,t){null!==t?lo.set(e,t):lo.delete(e)}const fo=new WeakMap,po=Object.freeze([]),ho=new Set;function mo(e,t,n){const o=function(e,t,n){const o=Array.isArray(t)&&t.length>0?t:po,s=Array.isArray(n)&&n.length>0?n:po,r=function(e,t){const n=Array.isArray(e)&&e.length>0?e:po,o=Array.isArray(t)&&t.length>0?t:po;let s=fo.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=co(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:ho,deleteIndexSet:new Set(i),addIndexSet:ho};let t=co(s);if(0===o.length){if(null===t){t=[];for(let n=0;n<s.length;n++){const o=ao(e,n);t.push(o)}}return a={oldIndexes:i,newIndexes:t,changeIndexSet:ho,deleteIndexSet:ho,addIndexSet:new Set(t)}}if(function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(o,s))return a={oldIndexes:i,newIndexes:i,changeIndexSet:ho,deleteIndexSet:ho,addIndexSet:ho};if(null!==t)return function(e,t){const n=new Set(t),o=new Set(e),s=new Set,r=n.difference(o),i=o.difference(n),a=new Map;for(let t=0;t<e.length;t++)a.set(e[t],t);for(let e=0;e<t.length;e++){const n=t[e];r.has(n)||a.get(n)!==e&&s.add(n)}return{oldIndexes:e,newIndexes:t,changeIndexSet:s,deleteIndexSet:i,addIndexSet:r}}(i,t);t=[];const n=new Map;for(let e=0;e<o.length;e++){const t=o[e];let s=n.get(t);s||(s=[],n.set(t,s)),s.push(e)}const r=new Set,l=new Set;for(let o=0;o<s.length;o++){const a=s[o],c=n.get(a),d=c&&c.length>0?c.shift():void 0;if(void 0===d){const n=ao(e,o);t.push(n),l.add(n)}else{const e=i[d];d!==o&&r.add(e),t.push(e)}}return a={oldIndexes:i,newIndexes:t,changeIndexSet:r,deleteIndexSet:new Set(i).difference(new Set(t)),addIndexSet:l}}finally{void 0!==a&&(!function(e,t,n){let o=fo.get(e);o||(o=new WeakMap,fo.set(e,o)),o.set(t,n)}(o,s,a),uo(s,a.newIndexes))}}(e,t,n);return function(e){for(let t=0;t<e.length;t++)e[t].index!==t&&(e[t].index=t)}(o.newIndexes),o}function go(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=[],o=[];let s=-1,r=!0;for(const i of e.newIndexes){if(e.addIndexSet.has(i))continue;const a=t.get(i);if(void 0===a)return null;a<s&&(r=!1),s=a,n.push(i),o.push(a)}if(r)return null;const i=function(e){const t=e.length,n=[],o=new Array(t).fill(-1);for(let s=0;s<t;s++){const t=e[s];let r=0,i=n.length;for(;r<i;){const o=r+i>>1;e[n[o]]<t?r=o+1:i=o}r>0&&(o[s]=n[r-1]),n[r]=s}const s=[];let r=n.length>0?n[n.length-1]:-1;for(;r>=0;)s.push(r),r=o[r];return s.reverse(),s}(o),a=new Set;for(const e of i)a.add(n[e]);return a}const yo=new WeakMap;function bo(e){return yo.get(e)??[]}function wo(e,t){yo.set(e,t)}const vo=new WeakMap;function No(e){return vo.get(e)??null}function So(e,t){vo.set(e,t)}const xo=new WeakMap;function Io(e){return xo.get(e)??[]}function Ao(e,t){xo.set(e,t)}function Po(e,t){const n=Io(e);for(const e of n)_e(e,t)}function _o(e,t,n){Po(e,t);const o=bo(e),s=No(e);null!==s&&s.activate(o,n.rootNode);for(const e of o){if(null===s){rt(tt(e),e)}(null===s||s.shouldApplyState(e))&&fs(e,n)}}function $o(e){if(!e.mounted)return;const t=bo(e),n=No(e);for(const e of t)if(null!==n)n.disposeBinding(e);else{it(tt(e),e)}!function(e){const t=Io(e);for(const e of t)_e(e,null)}(e)}const To=new WeakMap,ko=Object.freeze(new Set);function Co(e,t){const n=To.get(e);n?n.add(t):To.set(e,new Set([t]))}function Eo(e){const t=To.get(e);return void 0!==t?t:ko}function Mo(e,t){const n=To.get(e);n&&(n.delete(t),0===n.size&&To.delete(e))}const Oo=new Set(["if","elseif","else","for"]);class Do{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;_ranged=!1;constructor(e,t=!1){this._content=e,this._ranged=t,this._childNodeArray=Array.from(this._content.childNodes),this._firstNode=this._childNodeArray.length>0?this._childNodeArray[0]:null,this._lastNode=this._childNodeArray.length>0?this._childNodeArray[this._childNodeArray.length-1]:null}get firstNode(){return this._firstNode}get lastNode(){return this._lastNode}get mounted(){return this._mounted}appendTo(e){for(const t of this._childNodeArray)gn(t),e.appendChild(t);this._mounted=!0}_movableNodes(){if(!this._ranged||!this._mounted)return this._childNodeArray;const e=this._firstNode,t=this._lastNode;if(null===e||null===t||null===e.parentNode)return this._childNodeArray;const n=[];for(let o=e;null!==o;o=o.nextSibling)if(n.push(o),o===t)return n;return this._childNodeArray}mountAfter(e){const t=e.parentNode;if(t){let n=e;for(const e of this._movableNodes())n.nextSibling!==e&&(gn(e),t.insertBefore(e,n.nextSibling)),n=e}this._mounted=!0}tryDestroy(){const e=No(this);if(null===e||!e.canWholesaleDestroy())return!1;e.destroyRecords();for(const e of this._childNodeArray)pn(e),null!==e.parentNode&&e.parentNode.removeChild(e);const t=bo(this);for(const e of t)if(Oo.has(e.bindingType)){const t=Eo(e.node);for(const e of t)e.tryDestroy()||e.unmount()}return this._mounted=!1,!0}unmount(){No(this)?.dispose();for(const e of this._childNodeArray)pn(e),null!==e.parentNode&&e.parentNode.removeChild(e);const e=bo(this);for(const t of e){if(Oo.has(t.bindingType)){const e=Eo(t.node);for(const t of e)t.unmount()}mt(t),nt(t)}this._mounted=!1}}function Ro(e){let t=e.topLevelStructural;return void 0===t&&(t=e.topLevelStructural=function(e){const t=new RegExp(`^@@(?:${n.commentForPrefix}|${n.commentIfPrefix}|${n.commentElseIfPrefix}|${n.commentElsePrefix}):`);for(let n=e.firstChild;null!==n;n=n.nextSibling)if(n.nodeType===Node.COMMENT_NODE&&t.test(n.data))return!0;return!1}(e.fragment)),t}function Lo(e){const t=document.createDocumentFragment(),n=new Do(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 Wo(e,t,n){const o=document.importNode(t.fragment,!0),s=t.nodeInfos,r=new Array(s.length);for(let e=0;e<s.length;e++){const t=U(o,s[e].nodePath);null===t&&F(`Node not found by path [${s[e].nodePath.join(", ")}] in fragment.`),xe(t),l(t),r[e]=t}const i=n.slots,a=new Array(i.length),c=[];for(let e=0;e<i.length;e++){const t=i[e],n=r[t.nodeIndex],o={...t.template,node:n,replaceNode:n};a[e]=o,t.isIndexBinding&&c.push(o)}const d=function(e,t){const n=new Hn;return n.initializeRow(e,t),n}(n,a),u=new Do(o);return So(u,d),wo(u,a),no(u,c),Ao(u,r),Co(e.node,u),u}function Bo(t){void 0!==t.uuid&&null!==t.uuid||F("BindingInfo.uuid is null.");const o=ye(t.uuid);o||F(`Fragment with UUID "${t.uuid}" not found.`);const s=!e()&&Ro(o);let r=o.rowPlan;if((void 0===r||null!==r&&r.directional!==n.enableDirectionalInitialSync)&&(r=o.rowPlan=function(e){const t=n.enableDirectionalInitialSync,o=[],s=e.nodeInfos;for(let t=0;t<s.length;t++){const n=s[t],r=U(e.fragment,n.nodePath);if(null===r)return null;for(const e of n.parseBindTextResults){const n=e.bindingType;if("text"!==n&&"prop"!==n&&"event"!==n)return null;const s=e.propSegments[0];if("command"===s||"eventToken"===s)return null;if("text"===n){if(r.nodeType!==Node.TEXT_NODE)return null}else if(null!==M(r))return null;if("prop"===n&&qt(r,e.propName))return null;let i;try{i=Tn({...e,node:r,replaceNode:r})}catch{return null}if(i.observable||"auto"===i.authority)return null;o.push({nodeIndex:t,template:e,isEvent:"event"===n,isIndexBinding:e.statePathName in h,policy:i,authority:i.authority})}}return{directional:t,slots:o}}(o)),null!==r)return Wo(t,o,r);const i=document.importNode(o.fragment,!0),a=function(e,t){const[n,o]=function(e,t){const n=[],o=[];for(const s of t){const t=U(e,s.nodePath);if(null===t&&F(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),ve.has(t))continue;const r=Ne(t,s.parseBindTextResults,{allowDeferred:!1});o.push(...r.bindings),n.push(t)}return[n,o]}(e,t),s=new Hn,r=s.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:r,bindingSession:s}}(i,o.nodeInfos);s&&function(e,t){e.appendChild(document.createComment(`wcs-row-end:${t}`))}(i,t.uuid);const l=new Do(i,s);So(l,a.bindingSession),wo(l,a.bindingInfos);const c=[];for(const e of a.bindingInfos)e.statePathName in h&&c.push(e);return no(l,c),Ao(l,a.nodes),Co(t.node,l),l}const jo=new WeakMap,Fo=new WeakMap,zo=new WeakMap,qo=new WeakMap;function Uo(e,t,n){!function(e,t,n){let o=Fo.get(e);if(void 0===o){if(null===n)return;o=new WeakMap,Fo.set(e,o)}null===n?o.delete(t):o.set(t,n)}(e,t,n)}function Vo(e,t){jo.set(e,t)}function Ho(e,t){let n=zo.get(e.node);void 0===n&&(n=[],zo.set(e.node,n)),n.length<1e3?n.push(t):Mo(e.node,t)}function Go(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 Jo(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function Ko(t,o,s){const r=Boolean(s);let i;const a=Eo(t.node);i=0===a.size?Bo(t):a.values().next().value;const l=e(),c=t.uuid??"",d=t.bindingType;if(r||(n.debug&&console.log(`unmount if content : ${Jo(t)}`),$o(i),i.unmount()),r){if(n.debug&&console.log(`mount if content : ${Jo(t)}`),l){const e=document.createComment(`@@wcs-${d}-start:${c}:${t.statePathName}`);t.node.parentNode.insertBefore(e,t.node.nextSibling),i.mountAfter(e);const n=document.createComment(`@@wcs-${d}-end:${c}:${t.statePathName}`),o=i.lastNode??e;o.parentNode.insertBefore(n,o.nextSibling)}else i.mountAfter(t.node);_o(i,Pe(t.node),o)}}const Xo=new WeakMap;function Yo(e){return Xo.get(e)??[]}const Qo=new Set;const Zo={value(e,t){"TEXTAREA"===e.tagName?e.textContent=String(t??""):e.setAttribute("value",String(t??""))},checked(e,t){t?e.setAttribute("checked",""):e.removeAttribute("checked")},selected(e,t){t?e.setAttribute("selected",""):e.removeAttribute("selected")},disabled(e,t){t?e.setAttribute("disabled",""):e.removeAttribute("disabled")},selectedIndex(e,t){const n=e.querySelectorAll("option"),o=Number(t);for(let e=0;e<n.length;e++)e===o?n[e].setAttribute("selected",""):n[e].removeAttribute("selected")}};function es(t,o,s){if(void 0===s)return void(n.debug&&console.debug("Skipped property write: state value is undefined.",{element:t.node,propSegments:t.propSegments,statePathName:t.statePathName}));const r=t.node,i=t.propSegments;if(1===i.length){const l=i[0];if(r[l]!==s){const e=()=>{let e=!1;try{r[l]=s,e=!0}catch(e){n.debug&&console.warn(`Failed to set property '${l}' on element.`,{element:r,newValue:s,error:e})}if(e){const e=function(e,t){const n=M(e);if(null===n)return null;const o=O()?.get(n);if(void 0===o)return null;const s=R(e)?.declaredInputs.get(t);return"string"==typeof s?.attribute&&s.attribute.length>0?s.attribute:null}(r,l);if(null!==e)try{!function(e,t,n){if(null==n)return void e.removeAttribute(t);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);e.setAttribute(t,o)}(r,e,s)}catch(t){n.debug&&console.warn(`Failed to mirror attribute '${e}' on element.`,{element:r,newValue:s,error:t})}}};if(n.enablePropagationContext&&qt(r,l)){const n=Jt(r,l,t.stateName,t.statePathName),i=Kt(n,"to-element"),a=o?.propagationContextByBinding?.get(t)??en()??Yt(n);if(a.visitedEdges.has(i))null!==ot&&ot({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:i,node:r,member:l});else{const t=Qt(a,i);tn(t,()=>function(e,t,n,o,s,r){const i={bindingId:o,bindingGeneration:0,member:t,transactionId:s,synchronousScopeId:Ht++,writtenValue:n};nn.push({receipt:i,node:e});try{return r()}finally{nn.pop()}}(r,l,s,n,t.transactionId,e))}}else e()}if(e()){const e=Zo[l];e?e(r,s):(!function(e,t,n){let o=Xo.get(e);o||(o=[],Xo.set(e,o));const s=o.find(e=>e.propName===t);s?s.value=n:o.push({propName:t,value:n})}(r,l,s),a=r,Qo.add(a))}return}var a;const l=i[0];let c=r[l];for(let e=1;e<i.length-1;e++){const t=i[e];if(null==c)return;c=c[t]}const d=c[i[i.length-1]];if(d!==s){if(Object.isFrozen(c))return void(n.debug&&console.warn("Attempting to set property on frozen object.",{element:r,propSegments:i,oldValue:d,newValue:s}));try{c[i[i.length-1]]=s}catch(e){n.debug&&console.warn("Failed to set property on sub-object.",{element:r,propSegments:i,oldValue:d,newValue:s,error:e})}}}const ts=new WeakSet;function ns(e,t,n){const o=e.node,s=e.propSegments;s.length<=1&&F(`Invalid propSegments for web component binding: ${s.join(".")}`);const[r,...i]=s,a=o[r];void 0===a&&F(`Property "${r}" not found on web component.`),a[i.join(".")]=n}function os(e,t){const n=ht(t);if(n.pathInfo.path in h){const e=Pe(t.node);return null===e&&F(`ListIndex not found for binding: ${t.statePathName}`),function(e,t){null===e.listIndex&&F("ListIndex not found for loopContext:");const n=h[t];void 0===n&&F(`Invalid index name: ${t}`);const o=e.listIndex.at(n);return null===o&&F(`Index not found at position ${n} for loopContext:`),o.index}(e,n.pathInfo.path)}return e[Me](n)}const ss=new WeakSet;function rs(e,t){console.error(`[@wcstack/state] deferred apply failed for <${e}>.`,t)}const is={class:function(e,t,n){const o=e.node,s=e.propSegments[1];"boolean"!=typeof n&&F("Invalid value for class application: expected boolean, got "+typeof n),o.classList.toggle(s,n)},attr:function(e,t,n){const o=e.node,s=e.propSegments[1];o.getAttribute(s)!==n&&o.setAttribute(s,n)},style:function(e,t,n){const o=e.propSegments[1],s=e.node.style;s[o]!==n&&(s[o]=n)},command:function(e,t,n){kt(n)||F("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=Zn.get(e);if(s&&s.token===o)return;const r=e.node,i=e.propSegments[1];"string"==typeof i&&0!==i.length||F('command binding requires a method name (e.g., "command.fetch").');const a=function(e){const t=M(e);if(null===t)return null;const n=O()?.get(t);return void 0===n&&F(`Custom element <${t}> is not defined for command binding.`),R(e)}(r);null===a&&F(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(i)||F(`Command "${i}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.`),s&&(s.unsubscribe(),Zn.delete(e));const l=new WeakRef(r);let c=null;c=o.subscribe((...t)=>{const n=l.deref();if(!n||!n.isConnected)return c?.(),void Zn.delete(e);const o=n[i];return"function"!=typeof o&&F(`Method "${i}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,t)}),Zn.set(e,{token:o,unsubscribe:c,elementRef:l})}},as={text:function(t,n,o){const s=null==o?"":String(o);if(t.replaceNode.nodeValue!==s&&(t.replaceNode.nodeValue=s),e()&&!ts.has(t.replaceNode)){ts.add(t.replaceNode);const e=t.replaceNode.parentNode;if(e){const n=t.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);e.insertBefore(o,t.replaceNode),e.insertBefore(s,t.replaceNode.nextSibling)}}},for:function(t,n,o){const s=t.statePathInfo,r=Qe(t),i=tt(t),a=Te(i),l=mo(r,a,o);n.newListValueByAbsAddress.set(i,Array.isArray(o)?o:[]);const c=Array.isArray(a)&&a.length===l.deleteIndexSet.size&&l.deleteIndexSet.size>0;if(c&&null!==t.node.parentNode){let e=qo.get(t.node);if(void 0===e){const n=jo.get(t.node)||t.node;e=function(e,t){let n=e.previousSibling,o=t.nextSibling,s=!0;for(;null!==n;){if(n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&""!==(n.textContent?.trim()??"")){s=!1;break}n=n.previousSibling}for(;null!==o;){if(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE&&""!==(o.textContent?.trim()??"")){s=!1;break}o=o.nextSibling}return s}(t.node,n),qo.set(t.node,e)}if(e){const e=t.node.parentNode;e.textContent="",e.appendChild(t.node)}}let u=Fo.get(t.node),f=c?1e3-function(e){return zo.get(e.node)||[]}(t).length:Number.POSITIVE_INFINITY;if(void 0!==u){for(const e of l.deleteIndexSet){const n=u.get(e);void 0!==n&&(f<=0&&n.tryDestroy()?Mo(t.node,n):($o(n),n.unmount(),Ho(t,n),f-=1),c||u.delete(e))}c&&(Fo.delete(t.node),u=void 0)}let p=t.node;const h=k(s.path+"."+d),m=n.stateElement.loopContextStack,g=go(l);let y=null;l.newIndexes.length==l.addIndexSet.size&&l.newIndexes.length>0&&p.isConnected&&(y=document.createDocumentFragment(),Ge(y,n.rootNode));const b=e(),w=t.uuid??"",v=zo.get(t.node);for(const e of l.newIndexes){let o;if(l.addIndexSet.has(e)){const r=ft(h,e);m.createLoopContext(r,r=>{if(o=void 0!==v?v.pop():void 0,void 0===o&&(o=Bo(t)),null!==y)b&&y.appendChild(document.createComment(`@@wcs-for-start:${w}:${s.path}:${e.index}`)),o.appendTo(y),b&&y.appendChild(document.createComment(`@@wcs-for-end:${w}:${s.path}:${e.index}`));else{if(p.nextSibling!==o.firstNode){if(b){const t=document.createComment(`@@wcs-for-start:${w}:${s.path}:${e.index}`);p.parentNode.insertBefore(t,p.nextSibling),p=t}o.mountAfter(p)}if(b){const t=document.createComment(`@@wcs-for-end:${w}:${s.path}:${e.index}`),n=o.lastNode??p;n.parentNode.insertBefore(t,n.nextSibling)}}_o(o,r,n)}),void 0===o&&F(`Content not found for ListIndex: ${e.index} at path "${s.path}"`)}else{if(o=void 0!==u?u.get(e)??null:null,l.changeIndexSet.has(e)){const e=to(o);for(const t of e)fs(t,n)}null===o&&F(`Content not found for ListIndex: ${e.index} at path "${s.path}"`);null!==g&&g.has(e)&&Go(p,o.firstNode)||p.nextSibling===o.firstNode||o.mountAfter(p)}p=o.lastNode||p,void 0===u&&(u=new WeakMap,Fo.set(t.node,u)),u.set(e,o)}jo.set(t.node,p),null!==y&&(t.node.parentNode.insertBefore(y,t.node.nextSibling),Ge(y,null))},if:Ko,else:Ko,elseif:Ko,radio:function(e,t,n){const o=e.node,s=Yn(o.value,e.inFilters);o.checked=n===s},checkbox:function(e,t,n){const o=e.node,s=Yn(o.value,e.inFilters),r=Array.isArray(n)?n:Qn;o.checked=r.includes(s)}},ls=new WeakMap,cs=new WeakMap,ds=new WeakMap;function us(e,t){const n=Yn(os(t.state,e),e.outFilters);if(!0===cs.get(e))return void t.deferredSelectBindings.push({binding:e,value:n});let o=ls.get(e);if(void 0===o){if(ls.has(e))return Xn(e.replaceNode,t.stateElement)?(o=ns,ls.set(e,o)):o=es,void o(e,t,n);if(o=as[e.bindingType],void 0===o){const n=e.propSegments[0];if(o=is[n],ls.set(e,o),void 0===o){M(e.replaceNode)?Xn(e.replaceNode,t.stateElement)?(o=ns,ls.set(e,o)):o=es:(o=es,ls.set(e,o))}}if(o===es){if("SELECT"===e.node.tagName){const o=e.propSegments[0];if("value"===o||"selectedIndex"===o)return t.deferredSelectBindings.push({binding:e,value:n}),void cs.set(e,!0)}}o(e,t,n)}else o(e,t,n)}function fs(e,t){if(t.appliedBindingSet.has(e))return;if(t.appliedBindingSet.add(e),!1!==t.stateElement.hasUpdatedCallback){const n=tt(e);if(t.updatedAbsAddressSetByStateElement.has(t.stateElement)){t.updatedAbsAddressSetByStateElement.get(t.stateElement).add(n)}else t.updatedAbsAddressSetByStateElement.set(t.stateElement,new Set([n]))}const n=Jn(e);if(null!==n&&!n.shouldApplyState(e))return;if("event"===e.bindingType)return;if(!0!==ds.get(e)){const t=M(e.replaceNode);if(t&&void 0===O()?.get(t))return void function(e,t){if(ss.has(e))return;ss.add(e);const n=()=>{ss.delete(e);const t=Jn(e);(null===t||t.shouldApplyState(e))&&ps([e])},o=n=>{ss.delete(e),rs(t,n)},s=Jn(e);if(null!==s){const r=s.deferUntilDefined(e.replaceNode,t,n,o);return void(s.addTeardown(e,()=>{ss.delete(e),r()})||(ss.delete(e),r()))}const r=O();if(null===r)return ss.delete(e),void rs(t,new Error("CustomElementRegistry is unavailable."));xn(r).wait(t,()=>{e.replaceNode.isConnected?n():ss.delete(e)},o)}(e,t);ds.set(e,!0)}if(!0===t.sameRootVerified&&e.stateName===t.stateName)return void us(e,t);let o=e.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=Je(o),null===o&&F("Root node for fragment not found for binding.")),e.stateName!==t.stateName||o!==t.rootNode){const n=Zs(o,e.stateName);null===n&&F(`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};us(e,r)})}else us(e,t)}function ps(e,t){let o=0;const s=new Set,r=new Map,i=new Map,a=[];for(;o<e.length;){let l=e[o];const c=l.stateName;if(!1===l.replaceNode.isConnected){n.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${l.bindingType} ${l.statePathName} on ${l.node.nodeName}`,l),o++;continue}let d=l.replaceNode.getRootNode();d instanceof DocumentFragment&&!(d instanceof ShadowRoot)&&(d=Je(d),null===d&&F("Root node for fragment not found for binding."));const u=Zs(d,c);null===u&&F(`State element with name "${c}" not found for binding.`),u.createState("readonly",n=>{const f={rootNode:d,stateName:c,stateElement:u,state:n,appliedBindingSet:s,newListValueByAbsAddress:r,updatedAbsAddressSetByStateElement:i,deferredSelectBindings:a,sameRootVerified:!0,propagationContextByBinding:t};for(;;){fs(l,f),o++;const t=e[o];if(!t)break;const n=t.replaceNode.getRootNode();if(t.stateName!==c||n!==f.rootNode)break;l=t}})}for(const{binding:e,value:n}of a)es(e,{propagationContextByBinding:t},n);for(const[e,t]of r.entries())ke(e,t);for(const[e,t]of i.entries())e.createState("writable",e=>{e[We](Array.from(t))})}function hs(e,t){const[n,o,s]=Se(e),r=Gn(e);for(const e of n)_e(e,t);ps(r.initialize(o)),function(e,t,n){for(const o of e)n.deferUntilDefined(o.node,o.tagName,()=>{const e=Ie(o);0!==e.length&&(_e(o.node,t),ps(n.initialize(e)))},e=>{console.error(`[@wcstack/state] deferred spread failed for <${o.tagName}>.`,e)})}(s,t,r)}const ms=/\{\{\s*(.+?)\s*\}\}/g,gs=new Set(["SCRIPT","STYLE"]);function ys(e){if(!n.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&&gs.has(e.parentElement.tagName)||bs(e)}(e);const t=Array.from(e.querySelectorAll("template"));for(const e of t)if("http://www.w3.org/2000/svg"===e.namespaceURI){const t=document.createElement("template"),n=Array.from(e.childNodes);for(let e=0;e<n.length;e++){const o=n[e];t.content.appendChild(o)}for(const n of e.attributes)t.setAttribute(n.name,n.value);e.replaceWith(t),ys(t.content)}else ys(e.content)}function bs(e){const t=e.data;if(ms.lastIndex=0,!ms.test(t))return;ms.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=ms.exec(t));){o.index>s&&n.appendChild(document.createTextNode(t.slice(s,o.index)));const e=o[1];n.appendChild(document.createComment(`@@: ${e}`)),s=o.index+o[0].length}s<t.length&&n.appendChild(document.createTextNode(t.slice(s))),e.parentNode.replaceChild(n,e)}let ws;function vs(){if(ws)return ws;const e=[],t=oe("not",e)(te);return ws={filterName:"not",args:e,filterFn:t},ws}const Ns=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Ss(e,t){const n=t+c+d,o=e.indexOf("|"),s=e.indexOf("@");let r,i;if(-1!==o?(r=e.slice(0,o).trim(),i=e.slice(o)):-1!==s?(r=e.slice(0,s).trim(),i=e.slice(s)):(r=e.trim(),i=""),"."===r)r=n;else{if(!r.startsWith("."))return e;r=n+c+r.slice(1)}return i.length>0?r+i:r}function xs(e,t){const n=Ns.exec(e);if(null===n)return e;const o=n[1],s=n[2],r=n[3];return o+Ss(s,t)+r}function Is(e,t){const n=e.split(";");let o=!1;const s=n.map(e=>{const n=e.trim();if(0===n.length)return e;const s=n.indexOf(":");if(-1===s)return e;const r=n.slice(0,s).trim(),i=n.slice(s+1).trim(),a=Ss(i,t);return a!==i?(o=!0,`${r}: ${a}`):e});return o?s.join(";"):e}function As(e,t){return Is(e,t)}function Ps(e,t){const o=n.bindAttributeName,s=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const e=s.currentNode;if(e.nodeType===Node.COMMENT_NODE){const n=e;n.data=xs(n.data,t);continue}const n=e;if(n instanceof HTMLTemplateElement)continue;const r=n.getAttribute(o);if(null!==r){const e=Is(r,t);e!==r&&n.setAttribute(o,e)}}}function _s(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 $s(e){const t=[],n=we(e);for(const e of n){const n=be(e);let o=e;if(e.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==e.parentNode){const t=document.createTextNode("");e.parentNode.replaceChild(t,e),o=t}t.push({nodePath:_s(o),parseBindTextResults:n})}return t}function Ts(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 ks=new Map([["for",n.commentForPrefix],["if",n.commentIfPrefix],["elseif",n.commentElseIfPrefix],["else",n.commentElsePrefix]]),Cs=vs();function Es(e,t){const n=t.outFilters;return{...t,outFilters:[...n,Cs],bindingType:e}}function Ms(e,t,n,o){Ts(t),"string"==typeof o&&Ps(t,o),Os(e,t,o);return{fragment:t,parseBindTextResult:n,nodeInfos:$s(t)}}function Os(e,t,o){const s=n.commentElsePrefix,r=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode(e){const t=e;if("template"===t.tagName.toLowerCase()){if((t.getAttribute(n.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let i=null;const a=[],l=[];for(;r.nextNode();){const e=r.currentNode;l.push(e)}for(const t of l){let r=t.getAttribute(n.bindAttributeName)||"";"string"==typeof o&&(r=As(r,o));let l=de(r)[0];const c=ks.get(l.bindingType);if(void 0===c)continue;const d=l.bindingType,u=t.content,f=so();let p=null;const h="for"===d?l.statePathName:o;if("else"===d){null===i&&F("'else' binding found without preceding 'if' or 'elseif' binding."),l=Es("else",i.parseBindTextResult),p=Ms(e,u,l,h),ge(f,e,p);const n=a.at(-1),o=document.createComment(`@@${c}:${f}`);void 0!==n?(t.remove(),n.fragment.appendChild(o),n.nodeInfos.push({nodePath:_s(o),parseBindTextResults:be(o)})):t.replaceWith(o)}else if("elseif"===d){null===i&&F("'elseif' binding found without preceding 'if' or 'elseif' binding."),p=Ms(e,u,l,h),ge(f,e,p);const n=document.createComment(`@@${c}:${f}`),o=so(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Es("else",i.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:_s(n),parseBindTextResults:be(n)}),ge(o,e,r);const d=a.at(-1);a.push(r);const m=document.createComment(`@@${s}:${o}`);void 0!==d?(t.remove(),d.fragment.appendChild(m),d.nodeInfos.push({nodePath:_s(m),parseBindTextResults:be(m)})):t.replaceWith(m)}else{p=Ms(e,u,l,h),ge(f,e,p);const n=document.createComment(`@@${c}:${f}`);t.replaceWith(n)}"if"===d?(a.length=0,i=p):"elseif"===d?i=p:"else"===d&&(i=null,a.length=0)}}async function Ds(e){const t=e.querySelectorAll(n.tagNames.state),o=[];await customElements.whenDefined(n.tagNames.state);for(const e of t){const t=e;o.push(t.initializePromise)}await Promise.all(o)}async function Rs(e){if(e===document)await Ds(document),ys(document),Os(document,document),hs(document.body,null);else{const t=e;t.host.hasAttribute(n.bindAttributeName)&&await a(t.host),await Ds(t),ys(t),Os(t,t),hs(t,null)}}const Ls="1.23.0",Ws="undefined"==typeof HTMLElement?class{}:HTMLElement,Bs=/^@@wcs-(?:for|if|elseif|else):[^-]/,js=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,Fs=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,zs=/^@@wcs-text-start:(.+)$/;function qs(e){return e.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class Us extends Ws{_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=Ls.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 o=n.tagNames.ssr,s=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!s)return null;return s.querySelector(`${o}[name="${t}"]`)}static extractStateData(e){const t=e.__state;if(!t||"object"!=typeof t)return{};const n={};for(const[e,o]of Object.entries(t))e.startsWith("$")||"function"==typeof o||(n[e]=o);return n}static buildContent(e,t){const o=document.createElement("script");o.setAttribute("type","application/json"),o.textContent=qs(JSON.stringify(t)),e.appendChild(o);const s=Array.from(me.keys());for(const t of s){const o=ye(t);if(!o)continue;const s=document.createElement("template");s.setAttribute("id",t);const r=o.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;s.setAttribute(n.bindAttributeName,i);const a=o.fragment.cloneNode(!0);s.content.appendChild(a),e.appendChild(s)}const r=Array.from(Qo);if(r.length>0){const t={};for(let e=0;e<r.length;e++){const n=r[e],o=Yo(n);if(0===o.length)continue;const s=`wcs-ssr-${e}`;n.setAttribute("data-wcs-ssr-id",s);const i={};for(const e of o)i[e.propName]=e.value;t[s]=i}if(Object.keys(t).length>0){const n=document.createElement("script");n.setAttribute("type","application/json"),n.setAttribute("data-wcs-ssr-props",""),n.textContent=qs(JSON.stringify(t)),e.appendChild(n)}}Qo.clear()}static removeBlockBoundaryComments(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),n=[];for(;t.nextNode();){const e=t.currentNode;(js.test(e.data)||Fs.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;Bs.test(e.data)&&n.push(e)}for(const e of n)e.remove()}static restoreTextBindings(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),n=[];for(;t.nextNode();){const e=t.currentNode,o=zs.exec(e.data);o&&n.push({comment:e,path:o[1]})}for(const{comment:e,path:t}of n){const n=document.createComment(`@@: ${t}`);e.parentNode.insertBefore(n,e);let o=e.nextSibling;e.remove();const s=`@@wcs-text-end:${t}`;for(;o;){const e=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===s){o.parentNode.removeChild(o);break}o.parentNode.removeChild(o),o=e}}}static cleanupDom(e){const t=document.body,o=e.querySelectorAll(n.tagNames.ssr),s=new Map;for(const e of o){const t=e.querySelectorAll("template[id]");for(const e of t){const t=e.getAttribute("id");t&&s.set(t,e)}}const r=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const e=r.currentNode;js.test(e.data)&&i.push(e)}for(const e of i){const t=js.exec(e.data),n=`@@wcs-${t[1]}-end:${t[2]}`;let o=e.nextSibling;for(;o;){const e=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===n){o.remove();break}o.remove(),o=e}e.remove()}Us.restoreTextBindings(t);const a=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const e=a.currentNode;if(Bs.test(e.data)){const t=e.data.split(":")[1];l.push({comment:e,uuid:t})}}for(const{comment:e,uuid:t}of l){const o=s.get(t);if(o){const t=document.createElement("template"),s=o.getAttribute(n.bindAttributeName);s&&t.setAttribute(n.bindAttributeName,s);const r=document.importNode(o.content,!0);if(r.childNodes.length>0)t.content.appendChild(r);else for(const e of Array.from(o.childNodes))t.content.appendChild(document.importNode(e,!0));e.parentNode.replaceChild(t,e)}}const c=e.querySelectorAll("[data-wcs-ssr-id]");for(const e of c)e.removeAttribute("data-wcs-ssr-id");for(const e of o)e.remove()}}const Vs=new Set(["for","if","elseif","else"]);function Hs(e){const t=new Hn;if(0===e.length)return{bindingInfos:[],subscriberNodes:[],bindingSession:t};const n=e[0].parentNode,o=e[e.length-1].nextSibling,s=document.createElement("div");for(const t of e)s.appendChild(t);const[r,i]=Se(s),a=t.initialize(i,{registerAddress:!1,applyOnReconnect:!1});if(n)for(;s.firstChild;)n.insertBefore(s.firstChild,o);return{bindingInfos:a,subscriberNodes:r,bindingSession:t}}function Gs(e,t,o){const s={for:n.commentForPrefix,if:n.commentIfPrefix,elseif:n.commentElseIfPrefix,else:n.commentElsePrefix}[t];if(!s)return null;const r=`@@${s}:${o}`,i=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const e=i.currentNode;if(e.data===r)return e}return null}function Js(e,t){const o=e;let s=null;for(const[e,r]of t.templates){let t=de(r.getAttribute(n.bindAttributeName)||"")[0];const i=t.bindingType;"else"===i&&s?t={...s,outFilters:[...s.outFilters,vs()],bindingType:"else"}:"elseif"===i&&s&&(t={...t,stateName:s.stateName}),"if"===i||"elseif"===i?s=t:"else"===i&&(s=null);const a=document.importNode(r.content,!0),l="for"===i?t.statePathName:void 0;Ts(a),"string"==typeof l&&Ps(a,l),Os(o,a,l);ge(e,o,{fragment:a,parseBindTextResult:t,nodeInfos:$s(a)})}}async function Ks(e){await Ds(e);const t=e.querySelectorAll(n.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="${Ls}". Falling back to full render.`),Us.cleanupDom(e),!1}for(const n of t)Js(e,n);const o=function(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const e of o){const n=js.exec(e.data);if(!n)continue;const o=n[1],s=n[2],r=s.split(":");let i,a,l=null;"for"===o?(i=r[0],a=r[1],l=parseInt(r[2],10)):(i=r[0],a=r.slice(1).join(":"));const c=[];let d=e.nextSibling;const u=`@@wcs-${o}-end:${s}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)c.push(d),d=d.nextSibling;t.push({type:o,uuid:i,path:a,index:l,nodes:c})}return t}(document.body);!function(e,t){const n=new Map;for(const o of t){if(0===o.nodes.length)continue;const t=Lo(o.nodes),{bindingInfos:s,subscriberNodes:r,bindingSession:i}=Hs(o.nodes);So(t,i);for(const e of r)e.nodeType===Node.ELEMENT_NODE&&e.setAttribute("data-wcs-completed","");wo(t,s),Ao(t,r);const a=[];for(const e of s)e.statePathName in h&&a.push(e);if(no(t,a),"for"===o.type&&null!==o.index){const r=Gs(e,"for",o.uuid);if(r){const e=ao(null,o.index);Uo(r,e,t),Vo(r,o.nodes[o.nodes.length-1]),Co(r,t),Po(t,ft(k(o.path+"."+d),e)),i.initialize(s,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});let a=n.get(o.uuid);a||(a=[],n.set(o.uuid,a)),a.push(e)}}else{const n=Gs(e,o.type,o.uuid);n&&(Co(n,t),i.initialize(s,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}))}}for(const[t,o]of n){const n=Gs(e,"for",t);if(!n)continue;const s=n.getRootNode(),r=ye(t);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=Zs(s,i);l&&l.createState("readonly",e=>{const t=e[a];Array.isArray(t)&&uo(t,o)})}}(document.body,o),Us.removeBlockBoundaryComments(document.body);const s=[];for(const e of t)e.parentNode&&(s.push({el:e,parent:e.parentNode,next:e.nextSibling}),e.remove());Us.restoreTextBindings(document.body);const[r,i]=Se(document.body);for(const e of r)if(e.nodeType===Node.ELEMENT_NODE){const t=e;t.hasAttribute("data-wcs-completed")||(_e(e,null),t.setAttribute("data-wcs-completed",""))}else _e(e,null);const a=[],l=[],c=Gn(document.body).initialize(i);for(const e of c)if("event"!==e.bindingType)if(Vs.has(e.bindingType))l.push(e);else{if(e.statePathName.includes(d))continue;a.push(e)}for(const e of l)if("for"===e.bindingType){const t=tt(e),n=Zs(e.replaceNode.getRootNode(),e.stateName);n&&n.createState("readonly",n=>{const o=n[e.statePathName];Array.isArray(o)&&ke(t,o)})}ps(a);for(const{el:e,parent:t,next:n}of s)t.insertBefore(e,n);const u=e.querySelectorAll(n.tagNames.ssr);for(const t of u){const n=t.hydrateProps;for(const[t,o]of Object.entries(n)){const n=e.querySelector(`[data-wcs-ssr-id="${t}"]`);if(n)for(const[e,t]of Object.entries(o))n[e]=t}}const f=e.querySelectorAll("[data-wcs-completed]");for(const e of f)e.removeAttribute("data-wcs-completed");return!0}const Xs=new WeakMap,Ys=new WeakMap,Qs=new Set;function Zs(e,t){let n=Xs.get(e);return n&&n.get(t)||null}function er(e){return Ys.get(e)??Promise.resolve()}function tr(t,o,s){let r=Xs.get(t);if(null===s){if(!r)return;const e=r.get(o);r.delete(o),0===r.size&&Xs.delete(t),void 0!==e&&(Qs.delete(e),null!==ot&&ot({type:"state:element-unregistered",name:o,rootNode:t,element:e})),n.debug&&console.debug(`State element unregistered: name="${o}"`)}else{if(!r){r=new Map,Xs.set(t,r);const n=!e()&&s.hasAttribute?.("enable-ssr");if("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{if(n){await Ks(t)||await Rs(t)}else await Rs(t);e()})});Ys.set(t,e)}else if("ShadowRoot"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{await Rs(t),e()})});Ys.set(t,e)}}r.has(o)&&F(`State element with name "${o}" is already registered.`),r.set(o,s),Qs.add(s),null!==ot&&ot({type:"state:element-registered",name:o,rootNode:t,element:s}),n.debug&&console.debug(`State element registered: name="${o}"`,s)}}const nr=new Set;function or(e){nr.add(e)}const sr=new class{_queueUpdateRecords=[];constructor(){}enqueueAbsoluteAddress(e,t=null){const n=0===this._queueUpdateRecords.length;this._queueUpdateRecords.push({absoluteAddress:e,context:t}),n&&queueMicrotask(()=>{const e=this._queueUpdateRecords;this._queueUpdateRecords=[],this._applyChange(e)})}testApplyChange(e,t){this._applyChange(e.map((e,n)=>({absoluteAddress:e,context:t?.[n]??null})))}_applyChange(e){const t=new Map;for(const n of e){const e=t.get(n.absoluteAddress);null!==ot&&null!=e&&null!==n.context&&e.transactionId!==n.context.transactionId&&ot({type:"propagation:coalesced",absoluteAddress:n.absoluteAddress,droppedTransactionId:e.transactionId,winnerTransactionId:n.context.transactionId}),t.set(n.absoluteAddress,n.context)}const n=[],o=new Map;for(const[e,s]of t){if(null!==s&&s.hop>=32){console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:e.absolutePathInfo.pathInfo.path,stateName:e.absolutePathInfo.stateName,transactionId:s.transactionId,hop:s.hop,maxHops:32}),null!==ot&&ot({type:"propagation:hop-limit",absoluteAddress:e,transactionId:s.transactionId,hop:s.hop});continue}const t=lt(e);if(void 0!==t)if(t instanceof Set)for(const e of t)!1!==e.replaceNode.isConnected&&(n.push(e),null!==s&&o.set(e,s));else!1!==t.replaceNode.isConnected&&(n.push(t),null!==s&&o.set(t,s))}o.size>0?ps(n,o):ps(n),function(e){for(const t of nr)t(e)}(new Set(t.keys()))}};function rr(){return sr}const ir="__WCSTACK_DEVTOOLS_HOOK__";function ar(){const e=globalThis,t=e[ir];if(void 0!==t)return 1!==t.version&&console.warn(`[wcstack/state] devtools hook registry version mismatch: found ${t.version}, expected 1. Keeping the existing registry (first-wins).`),t;const n=function(){const e=new Map,t=new Set,n=e=>{if(0===t.size)return void e._setSink(null);const n=e.id;e._setSink(e=>{for(const o of t)o.onEvent?.(n,e)})};return{version:1,sources:e,register(o){if(!e.has(o.id)){e.set(o.id,o),n(o);for(const e of t)e.onSourceRegistered?.(o)}},unregister(n){const o=e.get(n);if(void 0!==o){o._setSink(null),e.delete(n);for(const e of t)e.onSourceUnregistered?.(n)}},addListener(o){t.add(o);for(const t of e.values())n(t),o.onSourceRegistered?.(t);return()=>{if(t.delete(o))for(const t of e.values())n(t)}}}}();return e[ir]=n,n}const lr=e=>{null!==ot&&ot({type:"state:update-batch",addresses:e})};function cr(e){const t=null!==ot;!function(e){ot=e}(e);const n=null!==e;var o;n&&!t?or(lr):!n&&t&&(o=lr,nr.delete(o))}function dr(e){return{name:e.name,rootNode:e.rootNode,element:e,paths:{list:e.listPaths,element:e.elementPaths,getter:e.getterPaths,setter:e.setterPaths},commandTokenNames:e.commandTokenNames,eventTokenNames:e.eventTokenNames,staticDependency:e.staticDependency,dynamicDependency:e.dynamicDependency}}function ur(e,t){return Zs(t,e)??F(`devtools: state element not found: name="${e}"`)}let fr=null;function pr(){if(e())return;if(null!==fr)return;const t={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:Ls,getStateElements(){const e=[];for(const t of Qs)e.push(dr(t));return e},keys(e,t){const n=ur(e,t),o=[];return n.createState("readonly",e=>{for(const t of Object.keys(e))if(!t.includes("*")&&!t.startsWith("$")){try{if("function"==typeof e[t])continue}catch{}o.push(t)}}),o},read(e,t,n,o){let s;return ur(e,t).createState("readonly",e=>{s=e.$resolve(n,o??[])}),s},write(e,t,n,o,s){ur(e,t).createState("writable",e=>{void 0!==s&&s.length>0?e.$resolve(n,s,o):e[n]=o})},_setSink:cr};fr=t,ar().register(t)}async function hr(e,t){let n=null;const o=`\n//# sourceURL=${t}\n`;if("function"==typeof URL.createObjectURL){const t=new Blob([e.text+o],{type:"application/javascript"}),s=URL.createObjectURL(t);try{n=await import(s)}finally{URL.revokeObjectURL(s)}}else{const t=btoa(String.fromCodePoint(...(new TextEncoder).encode(e.text+o)));n=await import(`data:application/javascript;base64,${t}`)}return n&&"object"==typeof n.default?n.default:{}}async function mr(e){try{return(await import(e)).default||{}}catch(e){F(`Failed to load script file: ${e}`)}}class gr{_loopContextStack=Array(u).fill(void 0);_length=0;createLoopContext(e,t){null===e.listIndex&&F("Cannot create loop context for a state address that does not have a list index.");const n=e;this._length>=u&&F("Exceeded maximum loop context stack depth of 128. Possible infinite loop.");const o=this._loopContextStack[this._length-1];if(void 0!==o){o.pathInfo.wildcardCount+1!==n.pathInfo.wildcardCount&&F("Cannot push loop context for a list whose wildcard count is not exactly one more than the current active loop context.");const e=n.pathInfo.wildcardPathInfos[n.pathInfo.wildcardPathInfos.length-2];o.pathInfo!==e&&F("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else n.listIndex.length!==n.pathInfo.wildcardCount&&F(`Cannot push loop context when there is no active loop context: the list index chain (length ${n.listIndex.length}) does not cover the wildcard path (wildcard count ${n.pathInfo.wildcardCount}).`);let s;this._loopContextStack[this._length]=n,this._length++;try{s=t(n)}finally{s instanceof Promise?s.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return s}}const yr=new WeakMap;function br(e,t){let n=yr.get(e);void 0===n&&(n=new Map,yr.set(e,n));let o=n.get(t);return void 0===o&&(o=new Tt(t,e.name),n.set(t,o)),o}const wr=new WeakMap;function vr(e){const t=wr.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 br(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:br(e,n)}},set(){F("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){F("$command namespace is read-only; deleting from it is not allowed.")}});return wr.set(e,n),n}const Nr=Symbol("wcs-stream-last-notified-uncertain"),Sr=new WeakMap;function xr(e,t){const n=Sr.get(e);if(void 0!==n)for(const e of n.keys())t.has(e)||n.delete(e)}function Ir(e,t){const n=Sr.get(e);if(void 0===n)return;const o=n.get(t);void 0!==o&&n.set(t,{status:"idle"===o.status?o.status:Nr,error:Object.is(o.error,null)?null:Nr})}const Ar=new Set;function Pr(e){Ar.delete(e)}function _r(){return Ar}const $r=new WeakMap;function Tr(e){return $r.get(e)??new Map}function kr(e){Pr(e);const t=$r.get(e);if(void 0!==t)for(const n of t.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,Ir(e,n.name)}const Cr=(e,t)=>t,Er=new Set;function Mr(e,t){const n=t[I];if(void 0===n)return void xr(e,Er);"object"==typeof n&&null!==n||F(`${I} must be an object mapping stream names to stream definitions.`);const o=new Map;for(const[s,r]of Object.entries(n)){0===s.length&&F(`${I} entry name must be a non-empty string.`),s.includes(c)&&F(`${I} entry "${s}" must be a flat property name ("${c}" is not allowed).`),s.includes(d)&&F(`${I} entry "${s}" must be a flat property name ("${d}" is not allowed).`),s.startsWith("$")&&F(`${I} entry "${s}" must not start with "$" (reserved namespace).`),s in Object.prototype&&F(`${I} entry "${s}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),e.getterPaths.has(s)&&F(`${I} entry "${s}" conflicts with a getter declared on the state.`),e.setterPaths.has(s)&&F(`${I} entry "${s}" conflicts with a setter declared on the state.`),"object"==typeof r&&null!==r||F(`${I} entry "${s}" must be an object ({ args?, source, fold?, initial? }).`);const n=r;"function"!=typeof n.source&&F(`${I} entry "${s}" source must be a function.`);const i=void 0!==n.fold;i&&"function"!=typeof n.fold&&F(`${I} entry "${s}" fold must be a function.`),i&&!("initial"in n)&&F(`${I} entry "${s}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==n.args&&"function"!=typeof n.args&&F(`${I} entry "${s}" args must be a function.`);const a={name:s,definition:{args:n.args??null,source:n.source,fold:n.fold??Cr,initial:n.initial},status:"idle",error:null,controller:null,depAddresses:new Set};s in t||(t[s]=a.definition.initial),o.set(s,a)}!function(e,t){$r.set(e,t)}(e,o),xr(e,new Set(o.keys()))}const Or=new WeakMap,Dr=new WeakMap;function Rr(e,t,n){return new Proxy(Object.create(null),{get(t,o){if("string"!=typeof o)return;const s=Tr(e).get(o);return void 0!==s?n(s):void 0},has:(t,n)=>"string"==typeof n&&Tr(e).has(n),ownKeys:()=>Array.from(Tr(e).keys()),getOwnPropertyDescriptor(t,o){if("string"!=typeof o)return;const s=Tr(e).get(o);return void 0!==s?{configurable:!0,enumerable:!0,value:n(s)}:void 0},set(){F(`${t} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){F(`${t} namespace is read-only; deleting from it is not allowed.`)}})}function Lr(e){const t=Or.get(e);if(void 0!==t)return t;const n=Rr(e,A,e=>e.status);return Or.set(e,n),n}function Wr(e){const t=Dr.get(e);if(void 0!==t)return t;const n=Rr(e,P,e=>e.error);return Dr.set(e,n),n}function Br(e){Or.delete(e),Dr.delete(e)}let jr=null;async function Fr(e,t,n,o){let s=null,r=null;const i=()=>{if(s&&s!==r){r=s;try{s.return?.()?.then?.(void 0,()=>{})}catch{}}};n.addEventListener("abort",i,{once:!0});try{const r=await e(t,n);if(s=function(e,t){if("function"==typeof e?.getReader)return async function*(e,t){const n=e.getReader(),o=()=>{n.cancel().catch(()=>{})};t.addEventListener("abort",o,{once:!0});try{for(;;){const{done:e,value:t}=await n.read();if(e)return;yield t}}finally{t.removeEventListener("abort",o),n.releaseLock()}}(e,t);if("function"==typeof e?.[Symbol.asyncIterator])return e;throw new TypeError("[@wcstack/state] $streams: source must return an AsyncIterable or a ReadableStream (got neither).")}(r,n)[Symbol.asyncIterator](),n.aborted)return void i();for(;;){const e=await s.next();if(e.done)break;if(n.aborted)return;o.fold(e.value)}if(n.aborted)return;o.done()}catch(e){if(n.aborted)return;o.fail(e)}finally{n.removeEventListener("abort",i)}}function zr(e){const t=Tr(e);if(0!==t.size){!function(e){Ar.add(e)}(e);for(const n of t.values())qr(e,n)}}function qr(e,t){t.controller?.abort();const n=new AbortController;t.controller=n;const o=function(e,t){const n=t.definition.args;if(null===n)return void t.depAddresses.clear();const o=jr,s=new Set;let r;jr=s;try{e.createState("readonly",e=>{r=n(e)})}finally{jr=o}r instanceof Promise&&F(`${I} entry "${t.name}" args must be synchronous (it returned a Promise).`);const i=`${A}${c}${t.name}`,a=`${P}${c}${t.name}`;for(const n of s){const o=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==e||o.path!==t.name&&o.path!==i&&o.path!==a||F(`${I} entry "${t.name}" args must not read the stream itself ("${o.path}"): a self-dependency would restart the stream on its own writes (infinite loop).`),o.wildcardCount>0&&F(`${I} entry "${t.name}" args must not read wildcard paths ("${o.path}"): wildcard dependencies are out of scope.`)}return t.depAddresses=s,r}(e,t);e.createState("writable",e=>{e[t.name]=t.definition.initial}),Ur(e,t,"active",null);const s=t.definition,r={fold(n){e.createState("writable",e=>{e[t.name]=s.fold(e[t.name],n)})},done(){Ur(e,t,"done",null)},fail(o){Ur(e,t,"error",o),n.abort()}};Fr(s.source,o,n.signal,r)}function Ur(e,t,n,o){t.status=n,t.error=o;const s=function(e,t){return Sr.get(e)?.get(t)??{status:"idle",error:null}}(e,t.name),r=s.status!==n,i=!Object.is(s.error,o);(r||i)&&(!function(e,t,n,o){let s=Sr.get(e);void 0===s&&(s=new Map,Sr.set(e,s)),s.set(t,{status:n,error:o})}(e,t.name,n,o),e.createState("writable",e=>{r&&e.$postUpdate(`${A}${c}${t.name}`),i&&e.$postUpdate(`${P}${c}${t.name}`)}))}function Vr(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 Hr(e){return function(t){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[e]=t})})}}function Gr(e,t){return t?function(...t){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[e](...t)}).then(()=>o)})}:function(...t){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[e](...t)}),o})}}function Jr(e){return e.startsWith("$")}or(function(e){const t=_r();if(0===t.size)return;const n=[];for(const o of t)for(const t of Tr(o).values())for(const s of t.depAddresses)if(e.has(s)){n.push({stateElement:o,entry:t});break}for(const{stateElement:e,entry:o}of n)if(t.has(e)&&Tr(e).get(o.name)===o)try{qr(e,o)}catch(n){o.controller?.abort(),t.has(e)&&Tr(e).get(o.name)===o&&Ur(e,o,"error",n)}});const Kr=new Map;class Xr{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const t=e.split("."),n=t.slice();let o=0,s=0,r=0,i="none";const a=[];for(let e=0;e<t.length;e++){const i=t[e];if("*"===i)n[e]="*",a.push(null),o++,r++;else{const t=Number(i);Number.isNaN(t)||(n[e]="*",a.push(t),s++,r++)}}const l=k(n.join("."));(o>0||s>0)&&(i=o===r?"context":s===r?"all":"partial"),this.path=e,this.segments=t,this.wildcardCount=r,this.wildcardType=i,this.wildcardIndexes=a,this.pathInfo=l}}function Yr(e){let t;return Kr.get(e)??(Kr.set(e,t=new Xr(e)),t)}const Qr=new WeakMap;function Zr(e,t){null===t?Qr.delete(e):Qr.set(e,t)}function ei(e){const t=Qr.get(e);t&&(t.dirty=!0)}function ti(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 ni(e,t,n,o,s){const r=t.pathInfo.segments[0];if(r===N)return ti(vr(s),t.pathInfo.segments);if(r===A)return ti(Lr(s),t.pathInfo.segments);if(r===P)return ti(Wr(s),t.pathInfo.segments);if(!(t.pathInfo.path in e)){const s=si(e,t.parentAddress??F(`address.parentAddress is undefined path: ${t.pathInfo.path}`),n,o),r=t.pathInfo.segments[t.pathInfo.segments.length-1];if(r===d){const e=t.listIndex?.index??F(`address.listIndex?.index is undefined path: ${t.pathInfo.path}`);return Reflect.get(s,e)}return Reflect.get(s,r)}if(!s.getterPaths.has(t.pathInfo.path))return Reflect.get(e,t.pathInfo.path);o.pushAddress(t);try{return Reflect.get(e,t.pathInfo.path,n)}finally{o.popAddress()}}function oi(e,t,n,o,s){const r=Ve(je(s,t.pathInfo),t.listIndex),i=function(e){return Qr.get(e)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=ni(e,t,n,o,s);return Zr(r,{value:a,dirty:!1}),a}function si(e,t,n,o){!function(e,t){if(!e.untracking&&e.addressStackLength>0){const n=e.lastAddressStack,o=n?.pathInfo??null,s=e.stateElement;if(null!==o&&s.getterPaths.has(o.path)&&o.path!==t.pathInfo.path&&(s.addDynamicDependency(t.pathInfo.path,o.path),t.pathInfo.wildcardCount>0&&o.wildcardCount>0)){const e=Xe(t.pathInfo,o);if(e>0){let o=!1;for(let s=0;s<e;s++)if(t.listIndex?.at(s)!==n.listIndex?.at(s)){o=!0;break}if(o)for(let n=0;n<e;n++)s.addCrossRowListPath?.(t.pathInfo.wildcardParentPaths[n])}}}}(o,t),function(e,t){if(null===jr)return;const n=je(e,t.pathInfo);jr.add(Ve(n,t.listIndex))}(o.stateElement,t);const s=o.stateElement;return t.pathInfo.wildcardCount>0||s.getterPaths.has(t.pathInfo.path)?oi(e,t,n,o,s):ni(e,t,n,o,s)}function ri(e,t){if(0===e.addressStackLength)return null;const n=e.lastAddressStack;if(null===n)return null;const o=n.pathInfo.indexByWildcardPath[t];return void 0===o?null:n.listIndex?.at(o)??null}function ii(e,t,n,o){if(t.pathInfo.path in e)return!0;const s=t.parentAddress;if(null===s)return!1;const r=si(e,s,n,o);if(null===r||"object"!=typeof r&&"function"!=typeof r)return!1;const i=t.pathInfo.lastSegment;if(i===d){const e=t.listIndex?.index;return"number"==typeof e&&e in r}return i in r}const ai=new WeakMap;function li(e,t){null===t?ai.delete(e):ai.set(e,t)}function ci(e,t,o){const s=k(e.wildcardParentPaths[t]),r=je(e.stateElement,s),i=ft(s,o),a=Te(Ve(r,o)),l=e.stateProxy[Me](i),c=function(e,t){switch(t){case"old":return e.oldIndexes;case"new":return e.newIndexes;case"add":return e.addIndexSet;case"change":return e.changeIndexSet;case"delete":return e.deleteIndexSet;default:return n.debug&&console.log(`Invalid search type: ${t}`),[]}}(mo(i.listIndex,a,l),e.searchType);if(t===e.wildcardPaths.length-1)e.targetListIndexes.push(...c);else for(const n of c)ci(e,t+1,n)}const di=[];function ui(e,t,n,o,s){return"full"===e.listExpansion||e.stateElement.crossRowListPaths?.has(t)?{fullRows:s.newIndexes,movedRows:null}:0===s.addIndexSet.size&&0===s.changeIndexSet.size?0===s.deleteIndexSet.size?{fullRows:s.newIndexes,movedRows:null}:{fullRows:di,movedRows:null}:{fullRows:s.addIndexSet,movedRows:s.changeIndexSet}}const fi=[];function pi(e,t,n){const o=e.stateElement.indexDependentGetterPaths;if(!o||0===o.size)return fi;let s=null;const r=[t],i=new Set(r);for(let t=0;t<r.length;t++){const a=r[t];if(o.has(a)){const e=k(a);if(e.wildcardCount!==n.wildcardCount)return null;(s??=[]).push(e)}const l=e.staticMap.get(a);if(l)for(const e of l)i.has(e)||(i.add(e),r.push(e))}return s??fi}function hi(e,t,n,o,s,r,i,a,l,c){const u=n.pathInfo.path;if(!o.has(u)&&!s.has(u))return l(n),[];const f={stateElement:t,staticMap:o,dynamicMap:s,result:new Set,listPathSet:r,visited:new Set,stateProxy:i,searchType:a,listExpansion:c?.listExpansion??"full"};return function(e,t,n){const o=[{address:t,depth:0}];for(;o.length>0;){const{address:t,depth:s}=o.pop();if(s>1e3&&F(`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=s+1,a=[],l=e.staticMap.get(r);if(l)for(const n of l){const o=k(n);if(e.listPathSet.has(r)&&o.lastSegment===d){const s=e.stateProxy[Me](t),l=Te(Ve(je(e.stateElement,t.pathInfo),t.listIndex)),c=ui(e,r,0,0,mo(t.listIndex,l,s));for(const t of c.fullRows){const n=ft(o,t);e.result.add(n),a.push({address:n,depth:i})}if(null!==c.movedRows){const t=pi(e,n,o);if(null===t)for(const t of c.movedRows){const n=ft(o,t);e.result.add(n),a.push({address:n,depth:i})}else if(t.length>0)for(const n of c.movedRows)for(const o of t){const t=ft(o,n);e.result.add(t),a.push({address:t,depth:i})}}}else{const n=ft(o,t.listIndex);e.result.add(n),a.push({address:n,depth:i})}}const c=e.dynamicMap.get(r);if(c)for(const n of c){const o=k(n),s=[];if(o.wildcardCount>0){const n=Xe(t.pathInfo,o);if(o.wildcardCount-n>=1){let r;n>0?(null===t.listIndex&&F(`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:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};ci(i,n,r),s.push(...i.targetListIndexes)}else{null===t.listIndex&&F(`Cannot expand dynamic dependency with wildcard for non-list address: ${t.pathInfo.path}`);const e=t.listIndex.at(n-1);s.push(e)}}else s.push(null);for(const t of s){const n=ft(o,t);e.result.add(n),a.push({address:n,depth:i})}}for(let e=a.length-1;e>=0;e--)o.push(a[e])}}(f,n,l),Array.from(f.result)}function mi(e,t,o,s){const r=n.enablePropagationContext?en()??Yt(-1):null,i=rr();i.enqueueAbsoluteAddress(t,r),hi(s.stateName,s.stateElement,e,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,o,"new",t=>{if(t===e)return;const n=Ve(je(s.stateElement,t.pathInfo),t.listIndex);ei(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:"diff"})}function gi(e,t,n,o,s,r){try{if(!(t.pathInfo.path in e)){const n=t.parentAddress;if(null===n)return Reflect.set(e,t.pathInfo.path,o);const i=si(e,n,s,r),a=t.pathInfo.segments[t.pathInfo.segments.length-1];if(a===d){const e=t.listIndex?.index??F(`address.listIndex?.index is undefined path: ${t.pathInfo.path}`);return Reflect.set(i,e,o)}return Reflect.set(i,a,o)}if(!r.stateElement.setterPaths.has(t.pathInfo.path))return Reflect.set(e,t.pathInfo.path,o);r.pushAddress(t),r.beginUntrack();try{return Reflect.set(e,t.pathInfo.path,o,s)}finally{r.endUntrack(),r.popAddress()}}finally{mi(t,n,s,r)}}function yi(e,t,n,o,s,r){let i=t.parentAddress??F(`address.parentAddress is undefined path: ${t.pathInfo.path}`),a=function(e){return ai.get(e)??null}(i);if(null===a){const t=si(e,i,s,r)??[],n=co(t)??[];a={value:[...t],listIndexes:[...n]},li(i,a)}try{return gi(e,t,n,o,s,r)}finally{const n=a.value.indexOf(o),l=si(e,i,s,r)??[],c=Array.isArray(l)?co(l)??[]:[],d=t.listIndex.index,u=-1!==n?a.listIndexes[n]:ao(i.listIndex,-1);c[d]=u;if(new Set(l).size===a.value.length){for(let e=0;e<c.length;e++)c[e].index=e;li(i,null)}}}function bi(e,t,o,s,r){const i=r.stateElement,a=t.pathInfo.path;if(!(a in e)&&null!==t.parentAddress&&!i.elementPaths.has(a)){const l=si(e,t.parentAddress,s,r);if("object"==typeof l&&null!==l){const e=t.pathInfo.lastSegment,c=e===d?t.listIndex?.index:e;let u,f=!1;if(n.sameValueGuard&&(null===o||"object"!=typeof o)){const e=void 0!==c&&c in l,t=void 0!==c?l[c]:void 0;if(e&&Object.is(t,o))return!0;u=t,f=!0}const p=t.pathInfo.wildcardCount>0||i.getterPaths.has(a),h=Ve(je(i,t.pathInfo),t.listIndex);null!==ot&&ot({type:"state:write",absoluteAddress:h,value:o,oldValue:u,hasOldValue:f});try{return void 0===c&&F(`address.listIndex?.index is undefined path: ${a}`),Reflect.set(l,c,o)}finally{mi(t,h,s,r),p&&Zr(h,{value:o,dirty:!1});const e=i.bindableEventMap[a];if(e){const t=i.rootNode;t instanceof ShadowRoot&&t.host.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0}))}}}}let l,c=!1;if(n.sameValueGuard&&(null===o||"object"!=typeof o)){const n=si(e,t,s,r);if(ii(e,t,s,r)&&Object.is(n,o))return!0;l=n,c=!0}const u=i.elementPaths.has(t.pathInfo.path),f=t.pathInfo.wildcardCount>0||i.getterPaths.has(t.pathInfo.path),p=Ve(je(i,t.pathInfo),t.listIndex);null!==ot&&ot({type:"state:write",absoluteAddress:p,value:o,oldValue:l,hasOldValue:c});try{return u?yi(e,t,p,o,s,r):gi(e,t,p,o,s,r)}finally{f&&Zr(p,{value:o,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:o,bubbles:!0}))}}}function wi(e,t,n,o){return(t,s,r)=>{const i=k(t);if(o.addressStackLength>0){const e=o.lastAddressStack?.pathInfo??null,t=o.stateElement;null!==e&&e.path!==i.path&&t.getterPaths.has(e.path)&&t.addDynamicDependency(i.path,e.path)}i.wildcardParentPathInfos.length>s.length&&F(`indexes length is insufficient: ${t}`);let a=null;for(let t=0;t<i.wildcardParentPathInfos.length;t++){const r=i.wildcardParentPathInfos[t],l=ft(r,a),c=co(si(e,l,n,o));null==c&&F(`ListIndexes not found: ${r.path}`);a=c[s[t]]??F(`ListIndex not found: ${r.path}`)}const l=ft(i,a);if(!(void 0!==r))return si(e,l,n,o);bi(e,l,r,n,o)}}const vi=new WeakMap;function Ni(e,t,n,o){const s=t.pathInfo;switch(t.wildcardType){case"none":return null;case"context":return ri(o,s.wildcardPaths.at(-1)??F(`lastWildcardPath is null: ${t.pathInfo.path}`))??F(`ListIndex not found: ${t.pathInfo.path}`);case"all":{let s=null;for(let r=0;r<t.pathInfo.wildcardCount;r++){const i=t.pathInfo.wildcardParentPathInfos[r]??F(`wildcardParentPathInfo is null: ${t.pathInfo.path}`);s=(co(si(e,ft(i,s),n,o))??F(`ListIndex not found: ${i.path}`))[t.wildcardIndexes[r]??F(`wildcardIndex is null: ${t.pathInfo.path}`)]??F(`ListIndex not found: ${i.path}`)}return s}case"partial":F(`Partial wildcard type is not supported yet: ${t.pathInfo.path}`)}}function Si(e,t,n){void 0!==e.loopContext&&F("already in loop context"),e.setLoopContext(t);try{e.pushAddress(t);try{return n()}finally{e.popAddress()}}finally{e.clearLoopContext()}}const xi=`${A}${c}`,Ii=`${P}${c}`,Ai=new WeakMap;function Pi(e,t,n,o){const s=h[t];if(void 0!==s){0===o.addressStackLength&&F(`No active state reference to get list index for "${t.toString()}".`);const e=o.lastAddressStack,n=e?.pathInfo;n&&!o.untracking&&o.stateElement?.getterPaths.has(n.path)&&o.stateElement.addIndexDependentGetterPath?.(n.path);const r=e?.listIndex;return r?.indexes[s]??F(`ListIndex not found: ${t.toString()}`)}if("string"==typeof t){if("$"===t[0]){switch(t){case"$stateElement":return o.stateElement;case"$getAll":return(t,s)=>function(e,t,n,o){const s=wi(e,0,n,o);return(t,r)=>{const i=new Map,a=k(t);if(o.addressStackLength>0){const e=o.lastAddressStack?.pathInfo??null,t=o.stateElement;null!==e&&e.path!==a.path&&t.getterPaths.has(e.path)&&t.addDynamicDependency(a.path,e.path)}if(void 0===r){for(let e=0;e<a.wildcardParentPathInfos.length;e++){const t=a.wildcardParentPathInfos[e],n=ri(o,t.path);if(n){r=n.indexes;break}}void 0===r&&(r=[])}const l=(t,s,r,a,c,d,u)=>{const f=t[s]??null;if(null===f)return void u.push(d);const p=ft(f,r),h=vi.get(p),m=si(e,p,n,o),g=mo(r,h,m).newIndexes,y=a[c]??null;if(i.set(p,m),null===y)for(let e=0;e<g.length;e++){const n=g[e];l(t,s+1,n,a,c+1,d.concat(n.index),u)}else{const e=g[y]??F(`ListIndex not found: ${f.path}`);s+1<t.length?l(t,s+1,e,a,c+1,d.concat(e.index),u):u.push(d.concat(e.index))}},c=[];l(a.wildcardParentPathInfos,0,null,r,0,[],c);const d=[];for(let e=0;e<c.length;e++)d.push(s(a.path,c[e]));for(const[e,t]of i.entries())vi.set(e,t);return d}}(e,0,n,o)(t,s);case"$postUpdate":return t=>function(e,t,n,o){const s=o.stateElement;return t=>{const r=Yr(t),i=Ni(e,r,n,o),a=ft(r.pathInfo,i),l=Ve(je(s,a.pathInfo),a.listIndex),c=rr();c.enqueueAbsoluteAddress(l),hi(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",e=>{const t=Ve(je(s,e.pathInfo),e.listIndex);ei(t),c.enqueueAbsoluteAddress(t)})}}(e,0,n,o)(t);case"$resolve":return(t,s,r)=>wi(e,0,n,o)(t,s,r);case"$trackDependency":return e=>function(e,t,n,o){return e=>{0===o.addressStackLength&&F(`No active state reference to track dependency for path "${e}".`);const t=o.lastAddressStack?.pathInfo??F("Internal error: lastAddressStack is null"),n=o.stateElement;o.stateElement.getterPaths.has(t.path)&&t.path!==e&&n.addDynamicDependency(e,t.path)}}(0,0,0,o)(e);case"$untrackDependency":return e=>function(e,t,n,o){return e=>{o.beginUntrack();try{return e()}finally{o.endUntrack()}}}(0,0,0,o)(e);case N:return vr(o.stateElement);case A:return Lr(o.stateElement);case P:return Wr(o.stateElement)}if(!t.startsWith(xi)&&!t.startsWith(Ii))return}const s=Yr(t),r=Ni(e,s,n,o),i=ft(s.pathInfo,r);return si(e,i,n,o)}if("symbol"==typeof t){const s=function(e){let t=Ai.get(e);return void 0===t&&(t=new Map,Ai.set(e,t)),t}(o),r=s.get(t);if(void 0!==r)return r;let i;switch(t){case Ce:i=(e,t=async()=>{})=>async function(e,t,n){return await Si(e,t,n)}(o,e,t);break;case Ee:i=(e,t=()=>{})=>function(e,t,n){return Si(e,t,n)}(o,e,t);break;case Me:i=t=>si(e,t,n,o);break;case Oe:i=t=>ii(e,t,n,o);break;case De:i=(t,s)=>bi(e,t,s,n,o);break;case Re:i=()=>async function(e,t,n){const o=Reflect.get(e,m);"function"==typeof o&&await o.call(n)}(e,0,n);break;case Le:i=()=>function(e,t,n){const o=Reflect.get(e,g);"function"==typeof o&&o.call(n)}(e,0,n);break;case We:i=t=>function(e,t,n,o){const s=Reflect.get(e,y);if("function"==typeof s){const e=new Set,r={};for(const n of t){const t=n.absolutePathInfo.pathInfo;let s;if(s=n.absolutePathInfo.stateName===o.stateName?t.path:t.path+"@"+n.absolutePathInfo.stateName,e.add(s),t.wildcardCount>0){const e=n.listIndex.indexes??[],t=r[s];void 0===t?r[s]=[e]:t.push(e)}}return s.call(n,Array.from(e),r)}}(e,t,n,o);break;default:return Reflect.get(e,t,n)}return s.set(t,i),i}}class _i{_stateElement;_stateName;_addressStack=Array(u).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;_untrackDepth=0;constructor(e,t,n){this._stateName=t;const o=Zs(e,this._stateName);null===o&&F(`StateHandler: State element with name "${this._stateName}" not found.`),this._stateElement=o,this._mutability=n}get stateName(){return this._stateName}get stateElement(){return this._stateElement}get lastAddressStack(){let e;return this._addressStackIndex>=0&&(e=this._addressStack[this._addressStackIndex]),void 0===e&&F("Last address stack is undefined."),e}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(e){this._addressStackIndex++,this._addressStackIndex>=u&&F("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&&F(`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 untracking(){return this._untrackDepth>0}beginUntrack(){this._untrackDepth++}endUntrack(){this._untrackDepth--}get(e,t,n){return Pi(e,t,n,this)}set(e,t,n,o){return"readonly"===this._mutability&&F(`State "${this._stateName}" is readonly.`),function(e,t,n,o,s){if("string"==typeof t){const r=Yr(t),i=Ni(e,r,o,s);return bi(e,ft(r.pathInfo,i),n,o,s)}return Reflect.set(e,t,n,o)}(e,t,n,o,this)}has(e,t){return Reflect.has(e,t)}}const $i=new WeakMap;const Ti=new WeakMap;function ki(e,t){const n=Ti.get(e);return n?n.get(t)??null:null}const Ci=new WeakMap,Ei=new WeakMap,Mi=new WeakMap,Oi=new WeakMap;function Di(e,t){return{innerAbsPathInfo:je(e,k(t.propSegments.slice(1).join(c))),outerAbsPathInfo:tt(t).absolutePathInfo}}function Ri(e,t){let n=Ci.get(e);if(void 0===n&&(n=new Map,Ci.set(e,n)),n.has(t))return n.get(t);let o=Ei.get(e);void 0===o&&(o=new Map,Ei.set(e,o));const s=Mi.get(e);if(void 0===s)return null;let r=null;for(const e of s)if(t.pathInfo.cumulativePathInfoSet.has(e.innerAbsPathInfo.pathInfo)){e.innerAbsPathInfo.pathInfo.segments.length===t.pathInfo.segments.length&&F("Duplicate mapping rule for web component."),r=e;break}if(null===r)return null;const i=Oi.get(r);void 0===i&&F("Binding not found for primary mapping rule on web component.");const a=t.pathInfo.segments.slice(r.innerAbsPathInfo.pathInfo.segments.length),l=k(r.outerAbsPathInfo.pathInfo.segments.concat(a).join(c)),d=Zs(e.getRootNode(),i.stateName);null===d&&F(`State element with name "${i.stateName}" not found for web component.`);const u=je(d,l);n.set(t,u),o.set(u,t);return function(e,t){const n=H(e);null===n?G(e,[t]):n.push(t)}(e,{...i,propName:t.pathInfo.path,propSegments:t.pathInfo.segments,statePathName:u.pathInfo.path,statePathInfo:u.pathInfo}),u}function Li(e){return function(e){const t=Object.getPrototypeOf(e),n=Object.create(t),o=Object.getOwnPropertyDescriptors(e);for(const e in o){const t=o[e];!1===t.writable&&(t.writable=!0)}return Object.defineProperties(n,o),n}(e)}class Wi{_webComponent;_innerStateElement;constructor(e,t){this._webComponent=e,this._innerStateElement=ki(e,t)??F("State element not found for web component.")}get(e,t,n){if("string"!=typeof t)return Reflect.get(e,t,n);{if("then"===t)return;if("$"===t[0])return;if(this._innerStateElement.getterPaths.has(t)&&t in e)return Reflect.get(e,t,n);const o=k(t),s=je(this._innerStateElement,o),r=Ri(this._webComponent,s);if(null!==r){const e=Pe(this._webComponent);let t;return r.stateElement.createState("readonly",n=>{n[Ee](e,()=>{t=n[r.pathInfo.path];let o=null;null!==e&&null!==e.listIndex&&r.pathInfo.wildcardCount>0&&(o=e.listIndex.at(r.pathInfo.wildcardCount-1));!function(e,t){$i.set(e,t)}(Ve(r,o),t)})}),t}if(t in e)return Reflect.get(e,t,n);F(`Property "${t}" not found in inner state: no mapping rule and no local state property.`)}}set(e,t,n,o){if("string"!=typeof t)return Reflect.set(e,t,n,o);{if(this._innerStateElement.setterPaths.has(t)&&t in e)return Reflect.set(e,t,n,o);const s=k(t),r=je(this._innerStateElement,s),i=Ri(this._webComponent,r);if(null!==i){const e=Pe(this._webComponent);return i.stateElement.createState("writable",t=>{t[Ee](e,()=>{t[i.pathInfo.path]=n})}),!0}if(t in e)return Reflect.set(e,t,n,o);F(`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=k(t),o=je(this._innerStateElement,n);return null!==Ri(this._webComponent,o)||t in e}return Reflect.has(e,t)}}class Bi{_innerStateElement;constructor(e,t){this._innerStateElement=ki(e,t)??F("State element not found for web component.")}get(e,t,n){if("string"==typeof t){const e=k(t),n=Ve(je(this._innerStateElement,e),null);return o=n,$i.get(o)}return Reflect.get(e,t,n);var o}set(e,t,n,o){if("string"==typeof t){const e=k(t),n=je(this._innerStateElement,e);return this._innerStateElement.createState("readonly",e=>{e.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(e,t,n,o)}}class ji{_innerStateElement;constructor(e,t){this._innerStateElement=ki(e,t)??F("State element not found for web component.")}get(e,t,n){if("string"==typeof t){let e;return this._innerStateElement.createState("readonly",n=>{e=n[t]}),e}return Reflect.get(e,t,n)}set(e,t,n,o){return"string"==typeof t?(this._innerStateElement.createState("writable",e=>{e[t]=n}),!0):Reflect.set(e,t,n,o)}}const Fi=e=>()=>e;function zi(e,t,o,s){if(function(e,t,n){let o=Ti.get(e);o||(o=new Map,Ti.set(e,o)),o.set(t,n)}(t,o,e),t.hasAttribute(n.bindAttributeName)){const n=(H(t)??[]).filter(e=>e.propSegments[0]===o);!function(e,t,n){if(0===n.length)return;const o=ki(e,t);null===o&&F("State element not found for web component.");const s=new Map,r=new Map;for(const t of n){const n=Di(o,t);let i=Mi.get(e);void 0===i?Mi.set(e,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;Oi.set(n,t),s.set(a,l),r.set(l,a)}Ci.set(e,s),Ei.set(e,r)}(t,o,n);const s=function(e,t){const n=new Bi(e,t);return new Proxy({},n)}(t,o),r=function(e,t){const n=new Wi(e,t),o=ki(e,t);null===o&&F("State element not found for web component."),null===o.boundComponentStateProp&&F("State element is not bound to any component state prop."),o.boundComponentStateProp in e||F(`State element is not bound to a valid component state prop: ${o.boundComponentStateProp}`);const s=e[o.boundComponentStateProp];return"object"==typeof s&&null!==s||F(`Invalid state object for component state prop: ${o.boundComponentStateProp}`),new Proxy(Li(s),n)}(t,o);e.setInitialState(r),Object.defineProperty(t,o,{get:Fi(s),enumerable:!0,configurable:!0})}else{e.setInitialState(Li(s));const n=function(e,t){const n=new ji(e,t);return new Proxy({},n)}(t,o);Object.defineProperty(t,o,{get:Fi(n),enumerable:!0,configurable:!0})}if(function(e,t){let n=Kn.get(e);n||(n=new WeakMap,Kn.set(e,n)),n.set(t,!0)}(t,e),b in t){const e=t[b];"function"==typeof e?e.call(t,o).catch(e=>{F(`Error in ${b}: ${e instanceof Error?e.message:String(e)}`)}):F(`${b} is not a function.`)}}function qi(e){const t=new Set,n=new Set,o=function(e){let t={},n=e;for(;n&&n!==Object.prototype;)Object.assign(t,Object.getOwnPropertyDescriptors(n)),n=Object.getPrototypeOf(n);return t}(e);for(const[e,s]of Object.entries(o))"function"==typeof s.get&&t.add(e),"function"==typeof s.set&&n.add(e);return{getterPaths:t,setterPaths:n}}class Ui extends Ws{static hasConnectedCallbackPromise=!0;static getBindingsReady(e){return er(e)}__state;_hasUpdatedCallback=!1;_crossRowListPaths=new Set;_indexDependentGetterPaths=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 gr}();_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&&F(`${n.tagNames.state} _state is not initialized yet.`),this.__state}set _state(t){this._commandTokenNames=function(e){const t=new Set,n=e[v];if(void 0===n)return t;Array.isArray(n)||F(`${v} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||F(`${v} entries must be non-empty strings.`),e===N&&F(`${v} entry "${e}" conflicts with the reserved namespace name "${N}".`),t.has(e)&&F(`${v} entry "${e}" is duplicated.`),t.add(e);return t}(t),this._eventTokenNames=function(e){const t=new Set,n=e[S];if(void 0===n)return t;Array.isArray(n)||F(`${S} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||F(`${S} entries must be non-empty strings.`),t.has(e)&&F(`${S} entry "${e}" is duplicated.`),t.add(e);return t}(t),this.__state=t,this._hasUpdatedCallback=y in t,Pt(this),function(e,t,n){const o=t[x];if(void 0!==o){"object"==typeof o&&null!==o||F(`${x} must be an object mapping event-token names to handler functions.`);for(const[t,s]of Object.entries(o))n.has(t)||F(`${x} entry "${t}" is not declared in $eventTokens.`),"function"!=typeof s&&F(`${x} entry "${t}" must be a function.`),At(e,t).subscribe(s)}}(this,t,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const n=qi(t);for(const e of n.getterPaths)this._getterPaths.add(e);for(const e of n.setterPaths)this._setterPaths.add(e);var o;Br(this),kr(o=this),Pr(o),$r.delete(o),Mr(this,t),this._initialized&&null!==this._rootNode&&!e()&&(zr(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=Us.findByName(t,e);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null}async _initialize(){const t=e()?null:this._loadFromSsrElement();try{if(this.hasAttribute("state")){const 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){F("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||F(`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 mr(e):F(`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 hr(e,`${this._name}`);else{const e=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${n.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(e)}}}catch(e){F(`Failed to initialize state: ${e}`)}if(null!==t&&this.__state)for(const[e,n]of Object.entries(t)){if(e in this.__state){const t=Object.getOwnPropertyDescriptor(this.__state,e);if(t&&(t.get||t.set))continue;if("function"==typeof this.__state[e])continue}this.__state[e]=n}await this._loadingPromise,this._name=this.getAttribute("name")||"default",tr(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,o=t?M(t):null;null!==t&&null!==o||F(`"bind-component" requires <${n.tagNames.state}> to be a direct child of a custom element.`),e instanceof ShadowRoot||this.hasAttribute("name")||F('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const s=this.getAttribute("bind-component");await customElements.whenDefined(o.toLowerCase()),t.hasAttribute(n.bindAttributeName)&&await a(t),s in t||F(`Component does not have property "${s}" for state binding.`);const r=t[s];"object"==typeof r&&null!==r||F(`Component property "${s}" is not an object for state binding.`),this._boundComponent=t,this._boundComponentStateProp=s,zi(this,this._boundComponent,this._boundComponentStateProp,r)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async e=>{m in e&&await e[Re]()})}async _initializeDCC(e,t){let o;try{if(this.hasAttribute("src")){const e=this.getAttribute("src");e.endsWith(".js")?o=await mr(e):F(`DCC: Unsupported src type: ${e}`)}else{const t=this.querySelector('script[type="module"]');t?o=await hr(t,e.tagName.toLowerCase()):F(`DCC: No state source found for "${e.tagName.toLowerCase()}".`)}}catch(e){F(`DCC: Failed to load state: ${e}`)}!function(e,t,o){const s=e.tagName.toLowerCase();if(s.includes("-")||F(`DCC: "${s}" is not a valid custom element name (must contain a hyphen).`),customElements.get(s))return void console.warn(`[@wcstack/state] DCC: "${s}" is already registered. Skipping redefinition.`);const r=document.createElement("template");r.innerHTML=t.innerHTML;const i=t.mode,a=Array.isArray(o[w])?o[w]:[],l=a.length>0?function(e,t){return{protocol:"wc-bindable",version:1,properties:t.map(t=>({name:t,event:`${e}:${t}-changed`})),inputs:t.map(e=>({name:e}))}}(s,a):null,c=a.length>0?function(e,t){const n={};for(const o of t)n[o]=`${e}:${o}-changed`;return n}(s,a):{},d=`${n.tagNames.state}:not([name])`,u=class extends HTMLElement{static template=r;static shadowRootMode=i;static wcBindable=l;static bindableEventMap=c;_shadow=null;connectedCallback(){if(!this.hasAttribute(_)&&(this._shadow=this.attachShadow({mode:u.shadowRootMode}),this._shadow.appendChild(u.template.content.cloneNode(!0)),Object.keys(u.bindableEventMap).length>0)){const e=this._shadow.querySelector(d);e&&e.initializePromise.then(()=>{e.setBindableEventMap(u.bindableEventMap)})}}get stateElement(){return this._shadow?.querySelector(d)}},f=Object.getOwnPropertyDescriptors(o);for(const[e,t]of Object.entries(f)){if(Jr(e))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof t.value){const o="AsyncFunction"===t.value.constructor?.name;n.value=Gr(e,o)}else n.get=Vr(e),n.set=Hr(e);Object.defineProperty(u.prototype,e,n)}customElements.define(s,u)}(e,t,o),this._dcc=!0,this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",e=>{g in e&&e[Le]()})}async connectedCallback(){this._rootNode=this.getRootNode();const t=++this._connectGeneration;if(this._initialized)this._dcc||Zs(this._rootNode,this._name)===this||tr(this._rootNode,this._name,this);else{const e=this.parentNode;if(e instanceof ShadowRoot&&e.host.hasAttribute(_))return void await this._initializeDCC(e.host,e);await this._initializeBindWebComponent(),await this._initialize(),this._initialized=!0,this._resolveInitialize?.()}if(this.hasAttribute("enable-ssr")&&!e()||await this._callStateConnectedCallback(),e()&&this.hasAttribute("enable-ssr")){await er(this.rootNode);const e=this.getAttribute("name")||"default",t=Us.extractStateData(this),o=document.createElement(n.tagNames.ssr);o.setAttribute("name",e),o.setAttribute("version",Ls),Us.buildContent(o,t),this.parentNode?.insertBefore(o,this)}e()||null===this._rootNode||t!==this._connectGeneration||this._streamsStartedGeneration===t||zr(this),this._resolveConnectedCallback?.()}disconnectedCallback(){if(null!==this._rootNode)try{this._callStateDisconnectedCallback()}finally{tr(this.rootNode,this._name,null),e=this,yr.delete(e),function(e){wr.delete(e)}(this),Pt(this),kr(this),Br(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&&F("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 o=e.get(t);return void 0===o?(e.set(t,[n]),!0):!o.includes(n)&&(o.push(n),!0)}addDynamicDependency(e,t){return this._addDependency(this._dynamicDependency,e,t)}addStaticDependency(e,t){return this._addDependency(this._staticDependency,e,t)}setPathInfo(e,t){if("for"===t&&(this._listPaths.add(e),this._elementPaths.add(e+"."+d)),!this._pathSet.has(e)){const t=k(e);if(this._pathSet.add(e),null!==t.parentPath){let e=t;for(;null!==e.parentPath&&this.addStaticDependency(e.parentPath,e.path);)e=k(e.parentPath)}}}_createState(e,t,n){try{const o=function(e,t,n,o){const s=new _i(e,n,o);return new Proxy(t,s)}(e,this._state,this._name,t);return n(o)}finally{}}async createStateAsync(e,t){return await this._createState(this.rootNode,e,t)}createState(e,t){this._createState(this.rootNode,e,t)}nextVersion(){return this._version++,this._version}get hasUpdatedCallback(){return this._hasUpdatedCallback}get crossRowListPaths(){return this._crossRowListPaths}addCrossRowListPath(e){this._crossRowListPaths.add(e)}get indexDependentGetterPaths(){return this._indexDependentGetterPaths}addIndexDependentGetterPath(e){this._indexDependentGetterPaths.add(e)}bindProperty(e,t){Object.defineProperty(this._state,e,t),e===y&&(this._hasUpdatedCallback=!0)}setInitialState(e){this._initialized?this._state=e:this._resolveSetState?.(e)}}function Vi(){customElements.get(n.tagNames.ssr)||customElements.define(n.tagNames.ssr,Us),customElements.get(n.tagNames.state)||customElements.define(n.tagNames.state,Ui)}function Hi(e){var n;e&&((n=e).tagNames&&Object.assign(t.tagNames,n.tagNames),"string"==typeof n.bindAttributeName&&(t.bindAttributeName=n.bindAttributeName),"string"==typeof n.commentTextPrefix&&(t.commentTextPrefix=n.commentTextPrefix),"string"==typeof n.commentForPrefix&&(t.commentForPrefix=n.commentForPrefix),"string"==typeof n.commentIfPrefix&&(t.commentIfPrefix=n.commentIfPrefix),"string"==typeof n.commentElseIfPrefix&&(t.commentElseIfPrefix=n.commentElseIfPrefix),"string"==typeof n.commentElsePrefix&&(t.commentElsePrefix=n.commentElsePrefix),"string"==typeof n.locale&&(t.locale=n.locale),"boolean"==typeof n.debug&&(t.debug=n.debug),"boolean"==typeof n.enableMustache&&(t.enableMustache=n.enableMustache),"boolean"==typeof n.enableDirectionalInitialSync&&(t.enableDirectionalInitialSync=n.enableDirectionalInitialSync),"boolean"==typeof n.enablePropagationContext&&(t.enablePropagationContext=n.enablePropagationContext),"boolean"==typeof n.enableContractAnalyzer&&(t.enableContractAnalyzer=n.enableContractAnalyzer),"boolean"==typeof n.sameValueGuard&&(t.sameValueGuard=n.sameValueGuard)),Vi(),pr()}function Gi(e){return e}const Ji={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}},Ki=1;function Xi(){return{version:1,syntax:{bindAttribute:n.bindAttributeName,tagName:n.tagNames.state,pathDelimiter:c,wildcard:d,delimiters:{binding:";",propValue:":",modifier:"#",stateName:"@",filter:f},structuralDirectives:Array.from(J)},filters:Object.keys(te),filterMeta:Ji,reservedLifecycle:[m,g,y,b],reservedStateApi:[w,v,N,S,x,I,A,P]}}const Yi=new Set(["wcstack.types","wcstack.async","wcstack.platformCapabilities","wcstack.application"]),Qi=Object.freeze([]);function Zi(e){if(!n.enableContractAnalyzer)return Qi;const t=[];return function(e,t,n){const o=e.manifestExtensions;if(null===o||"object"!=typeof o)return;for(const e of Object.keys(o))Yi.has(e)||n({type:"contract:unsupported-extension",namespace:e});const s=o["wcstack.types"]?.components;if(null==s)return;for(const[e,o]of Object.entries(s)){const s=t(e);n({type:"contract:manifest-read",tag:e,loaded:null!==s}),null!==s?ea(e,o,s,n):n({type:"contract:drift",reason:"component-not-loaded",tag:e})}}(e,ta,e=>{t.push(e),null!==ot&&ot(e)}),t}function ea(e,t,n,o){const s=null!==t&&"object"==typeof t?t:{};for(const[t,r]of Object.entries(s.observables??{})){if(!n.propertyEvents.has(t)){o({type:"contract:drift",reason:"missing-member",tag:e,member:t});continue}const s=n.propertyEvents.get(t),i=r?.event;"string"==typeof i&&i!==s&&o({type:"contract:drift",reason:"event-mismatch",tag:e,member:t,sidecarEvent:i,liveEvent:s})}for(const t of Object.keys(s.inputs??{}))n.inputs.has(t)||o({type:"contract:drift",reason:"missing-member",tag:e,member:t});for(const t of Object.keys(s.commands??{}))n.commands.has(t)||o({type:"contract:drift",reason:"missing-member",tag:e,member:t})}function ta(e){const t=O(),n=t?.get(e);if(void 0===n)return null;const o=n.wcBindable;if(null===o||"object"!=typeof o||"wc-bindable"!==o.protocol)return null;const s=o,r=new Map;for(const e of Array.isArray(s.properties)?s.properties:[])"string"==typeof e?.name&&"string"==typeof e.event&&r.set(e.name,e.event);const i=new Set;for(const e of Array.isArray(s.inputs)?s.inputs:[])"string"==typeof e?.name&&i.add(e.name);const a=new Set;for(const e of Array.isArray(s.commands)?s.commands:[])"string"==typeof e?.name&&a.add(e.name);return{propertyEvents:r,inputs:i,commands:a}}export{Us as Ssr,Ls as VERSION,Ki as WCS_MANIFEST_VERSION,Zi as analyzeContract,Hi as bootstrapState,Rs as buildBindings,Ji as builtinFilterMeta,Gi as defineState,er as getBindingsReady,o as getConfig,Xi as getWcsManifest};
|
|
1
|
+
function e(){const e=document.documentElement;return!!e&&e.hasAttribute("data-wcs-server")}const t={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,enableDirectionalInitialSync:!0,enablePropagationContext:!0,enableContractAnalyzer:!1,sameValueGuard:!0},n=t;function o(){return n}const s=new WeakMap,r=new WeakSet;let i=0;async function a(e){const t=function(e){let t,n=s.get(e)||null;if(null!==n)return n;const o=new Promise(e=>{t=e});return n={id:++i,promise:o,resolve:t},s.set(e,n),r.has(e)&&n.resolve(),n}(e);await t.promise}function l(e){const t=s.get(e);void 0===t?r.add(e):t.resolve()}const c=".",d="*",u=128,f="|",p={};for(let e=0;e<128;e++)p[`$${e+1}`]=e;const h=Object.freeze(p),m="$connectedCallback",g="$disconnectedCallback",y="$updatedCallback",b="$stateReadyCallback",w="$bindables",v="$commandTokens",N="$command",S="$eventTokens",x="$on",I="$streams",A="$streamStatus",P="$streamError",_="data-wc-definition",$=new Map;let T=0;function k(e){let t=$.get(e);return void 0!==t||(t=Object.freeze(new C(e)),$.set(e,t)),t}class C{id=++T;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:k(t),n=e.split("."),o=[],s=[],r=[],i={},a=[],l=[],c=[],u=[];let f="",p="",h=0;for(let e=0;e<n.length;e++)f+=n[e],n[e]===d&&(r.push(f),i[f]=h,a.push(t(f)),l.push(p),c.push(t(p)),u.push(e),h++),o.push(f),s.push(t(f)),p=f,f+=".";const m=r.length>0?r[r.length-1]:null,g=o.length>1?o[o.length-2]:null;this.path=e,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=o,this.cumulativePathSet=new Set(o),this.cumulativePathInfos=s,this.cumulativePathInfoSet=new Set(s),this.wildcardPaths=r,this.wildcardPathSet=new Set(r),this.indexByWildcardPath=i,this.wildcardPathInfos=a,this.wildcardPathInfoSet=new Set(a),this.wildcardParentPaths=l,this.wildcardParentPathSet=new Set(l),this.wildcardParentPathInfos=c,this.wildcardParentPathInfoSet=new Set(c),this.wildcardPositions=u,this.lastWildcardPath=m,this.lastWildcardInfo=m?t(m):null,this.parentPath=g,this.parentPathInfo=g?t(g):null,this.wildcardCount=h}}const E=new WeakMap;function M(e){const t=E.get(e);if(void 0!==t)return t;let n=null;try{if(e.nodeType!==Node.ELEMENT_NODE)return n;const t=e,o=t.tagName.toLowerCase();if(o.includes("-"))return n=o;if(t.hasAttribute("is")){const e=t.getAttribute("is");if(e.includes("-"))return n=e}return n}finally{E.set(e,n)}}function O(e=null){const t=globalThis.customElements,n=e?.customElements??t;if("object"!=typeof n||null===n)return null;const o=n;return"function"!=typeof o.get||"function"!=typeof o.whenDefined?null:o}function D(e,t){e.upgrade?.(t)}function R(e){try{if(null===e||"object"!=typeof e&&"function"!=typeof e)return null;const t=e,n=t.addEventListener,o=t.removeEventListener,s=t.constructor?.wcBindable;if("function"!=typeof n||"function"!=typeof o)return null;if("wc-bindable"!==s?.protocol)return null;if(!Number.isInteger(s.version)||s.version<1)return null;const r=j(s.properties,L);if(null===r)return null;const i=void 0===s.inputs?new Map:j(s.inputs,W);if(null===i)return null;const a=void 0===s.commands?new Map:j(s.commands,B);return null===a?null:{target:e,liveDeclaration:s,knownProperties:r,declaredInputs:i,declaredCommands:a}}catch{return null}}function L(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&("string"==typeof t.event&&0!==t.event.length&&(void 0===t.getter||"function"==typeof t.getter))}function W(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.attribute||"string"==typeof t.attribute)}function B(e){if("object"!=typeof e||null===e)return!1;const t=e;return"string"==typeof t.name&&0!==t.name.length&&(void 0===t.async||"boolean"==typeof t.async)}function j(e,t){if(!Array.isArray(e))return null;const n=new Map;for(const o of e){if(!t(o)||n.has(o.name))return null;n.set(o.name,o)}return n}function F(e){throw new Error(`[@wcstack/state] ${e}`)}function z(e,t,n){const o="."===t?`.${e}`:`${t}.${e}`;return{propName:e,propSegments:[e],propModifiers:[],statePathName:o,statePathInfo:k(o),stateName:n,inFilters:[],outFilters:[],bindingType:"prop"}}function q(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function U(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 V=new WeakMap;function H(e){return V.get(e)||null}function G(e,t){V.set(e,t)}const J=new Set(["if","elseif","else","for"]);function K(e){F(`filter ${e} requires at least one option`)}function X(e){F(`filter ${e} requires a number as option`)}function Y(e){F(`filter ${e} requires a number value`)}function Q(e){F(`filter ${e} requires a date value`)}function Z(e){return!(!e||isNaN(Number(e)))}const ee={eq:e=>{const t=e?.[0]??K("eq");return e=>"number"==typeof e?(Z(t)||X("eq"),e===Number(t)):e===t},ne:e=>{const t=e?.[0]??K("ne");return e=>"number"==typeof e?(Z(t)||X("ne"),e!==Number(t)):e!==t},not:e=>e=>("boolean"!=typeof e&&F(`filter ${"not"} requires a boolean value`),!e),lt:e=>{const t=e?.[0]??K("lt");return Z(t)||X("lt"),e=>("number"!=typeof e&&Y("lt"),e<Number(t))},le:e=>{const t=e?.[0]??K("le");return Z(t)||X("le"),e=>("number"!=typeof e&&Y("le"),e<=Number(t))},gt:e=>{const t=e?.[0]??K("gt");return Z(t)||X("gt"),e=>("number"!=typeof e&&Y("gt"),e>Number(t))},ge:e=>{const t=e?.[0]??K("ge");return Z(t)||X("ge"),e=>("number"!=typeof e&&Y("ge"),e>=Number(t))},inc:e=>{const t=e?.[0]??K("inc");return Z(t)||X("inc"),e=>("number"!=typeof e&&Y("inc"),e+Number(t))},dec:e=>{const t=e?.[0]??K("dec");return Z(t)||X("dec"),e=>("number"!=typeof e&&Y("dec"),e-Number(t))},mul:e=>{const t=e?.[0]??K("mul");return Z(t)||X("mul"),e=>("number"!=typeof e&&Y("mul"),e*Number(t))},div:e=>{const t=e?.[0]??K("div");return Z(t)||X("div"),e=>("number"!=typeof e&&Y("div"),e/Number(t))},mod:e=>{const t=e?.[0]??K("mod");return Z(t)||X("mod"),e=>("number"!=typeof e&&Y("mod"),e%Number(t))},fix:e=>{const t=e?.[0]??"0";return Z(t)||X("fix"),e=>("number"!=typeof e&&Y("fix"),e.toFixed(Number(t)))},locale:e=>{const t=e?.[0]??n.locale;return e=>("number"!=typeof e&&Y("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]??K("slice");Z(n)||X("slice"),t.push(Number(n));const o=e?.[1];return void 0!==o&&(Z(o)||X("slice"),t.push(Number(o))),e=>String(e).slice(...t)},substr:e=>{const t=e?.[0]??K("substr");Z(t)||X("substr");const n=e?.[1]??K("substr");return Z(n)||X("substr"),e=>String(e).substr(Number(t),Number(n))},pad:e=>{const t=e?.[0]??K("pad");Z(t)||X("pad");const n=e?.[1]??"0";return e=>String(e).padStart(Number(t),n)},rep:e=>{const t=e?.[0]??K("rep");return Z(t)||X("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 Z(t)||X("round"),e=>{"number"!=typeof e&&Y("round");const n=Math.pow(10,Number(t));return Math.round(e*n)/n}},floor:e=>{const t=e?.[0]??"0";return Z(t)||X("floor"),e=>{"number"!=typeof e&&Y("floor");const n=Math.pow(10,Number(t));return Math.floor(e*n)/n}},ceil:e=>{const t=e?.[0]??"0";return Z(t)||X("ceil"),e=>{"number"!=typeof e&&Y("ceil");const n=Math.pow(10,Number(t));return Math.ceil(e*n)/n}},percent:e=>{const t=e?.[0]??"0";return Z(t)||X("percent"),e=>("number"!=typeof e&&Y("percent"),`${(100*e).toFixed(Number(t))}%`)},date:e=>{const t=e?.[0]??n.locale;return e=>(e instanceof Date||Q("date"),e.toLocaleDateString(t))},time:e=>{const t=e?.[0]??n.locale;return e=>(e instanceof Date||Q("time"),e.toLocaleTimeString(t))},datetime:e=>{const t=e?.[0]??n.locale;return e=>(e instanceof Date||Q("datetime"),e.toLocaleString(t))},ymd:e=>{const t=e?.[0]??"-";return e=>{e instanceof Date||Q("ymd");const n=e.getFullYear().toString(),o=(e.getMonth()+1).toString().padStart(2,"0"),s=e.getDate().toString().padStart(2,"0");return`${n}${t}${o}${t}${s}`}},falsy:e=>e=>!1===e||null==e||0===e||""===e||Number.isNaN(e),truthy:e=>e=>!1!==e&&null!=e&&0!==e&&""!==e&&!Number.isNaN(e),defaults:e=>{const t=e?.[0]??K("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},te=ee,ne={input:ee,output:te},oe=(e,t)=>n=>{const o=n[e];return o||F(`filter not found: ${e}`),o(t)};const se=new Map;function re(e,t){const n=ne[t];return e.map(e=>{const o=e.indexOf("("),s=e.lastIndexOf(")");if(-1!==o&&-1===s&&F(`Invalid filter format: missing closing parenthesis in "${e}"`),-1!==s&&-1===o&&F(`Invalid filter format: missing opening parenthesis in "${e}"`),-1===o){const o=e.trim(),s=`${o}():${t}`;let r=se.get(s);return void 0===r&&(r=oe(o,[])(n),se.set(s,r)),{filterName:o,args:[],filterFn:r}}{const r=e.substring(o+1,s),i=e.substring(0,o).trim(),a=function(e){const t=[];let n="",o=null,s=!1;for(let r=0;r<e.length;r++){const i=e[r];o?i===o?o=null:n+=i:'"'===i||"'"===i?(o=i,s=!0):","===i?(t.push(n.trim()),n="",s=!1):n+=i}const r=n.trim();return(r||s)&&t.push(r),t}(r),l=`${i}(${a.join(",")}):${t}`;let c=se.get(l);return void 0===c&&(c=oe(i,a)(n),se.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const ie=e=>e.trim(),ae=new Map;const le=new Map;function ce(e){const t=e.indexOf(f);let n="",o=[],s="",r=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),le.has(s)?r=le.get(s):(o=s.split(f).map(ie),r=re(o,"output"),le.set(s,r))):n=e.trim();const[i,a="default"]=n.split("@").map(ie);return{stateName:a,statePathName:i,statePathInfo:k(i),outFilters:r}}function de(e){const[...t]=e.split(";").map(ie).filter(e=>e.length>0),n=t.map(e=>{const t=e.indexOf(":");-1===t&&F(`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`);const n=e.slice(0,t).trim(),o=e.slice(t+1).trim();if("else"===n){return{propName:"else",propSegments:["else"],propModifiers:[],statePathName:"#else",statePathInfo:k("#else"),stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if("..."===n){const t=ce(o);return t.outFilters.length>0&&F(`Invalid spread binding "${e}": filters are not allowed on spread targets.`),0===t.statePathName.length&&F(`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:[],...ce(o),bindingType:n}}{const e=ce(o),t=function(e){const t=e.indexOf(f);let n="",o=[],s="",r=[];-1!==t?(n=e.slice(0,t).trim(),s=e.slice(t+1).trim(),ae.has(s)?r=ae.get(s):(o=s.split(f).map(ie),r=re(o,"input"),ae.set(s,r))):n=e.trim();const[i,a]=n.split("#").map(ie),l=i.split(c).map(ie);return{propName:i,propSegments:l,propModifiers:a?a.split(",").map(ie):[],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=>J.has(e.bindingType))&&F(`Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding.`)}return n}const ue=new WeakMap,fe=new Set([n.commentTextPrefix,n.commentForPrefix,n.commentIfPrefix,n.commentElseIfPrefix,n.commentElsePrefix]),pe=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function he(e){const t=ue.get(e);if("string"==typeof t)return t;if(e.nodeType!==Node.COMMENT_NODE)return null;const o=e.data.trim(),s=pe.exec(o);if(null===s)return null;const r=s[1]||n.commentTextPrefix;return fe.has(r)?(ue.set(e,s[2]),s[2]):null}const me=new Map;function ge(e,t,n){if(null===n)me.delete(e);else{me.set(e,n);const o=n.parseBindTextResult,s=nr(t,o.stateName);null===s&&F(`State element with name "${o.stateName}" not found for fragment info.`),s.setPathInfo(o.statePathName,o.bindingType);for(const e of n.nodeInfos)for(const n of e.parseBindTextResults){const e=nr(t,n.stateName);null===e&&F(`State element with name "${n.stateName}" not found for fragment info node.`),e.setPathInfo(n.statePathName,n.bindingType)}}}function ye(e){return me.get(e)||null}function be(e){if(e.nodeType===Node.ELEMENT_NODE){return de(e.getAttribute(n.bindAttributeName)||"")}if(e.nodeType===Node.COMMENT_NODE){const t=he(e);null===t&&F("Comment node binding text not found.");const n=ye(t);let o=n?.parseBindTextResult??null,s=null;return null===o?(o={propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...ce(t),bindingType:"text"},s=null):s=t,[{...o,uuid:s}]}return[]}function we(e){const t=[],o=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(e){if(e.nodeType===Node.ELEMENT_NODE){return e.hasAttribute(n.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==he(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;o.nextNode();)t.push(o.currentNode);return t}const ve=new WeakSet;function Ne(e,t,o){const s=function(e,t,o={}){const s=o.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&&F("Spread binding requires an element node.");const t=e,o=M(t);null===o&&F(`Spread binding "${n.statePathName}" requires a custom element with wcBindable, but <${t.tagName.toLowerCase()}> is not a custom element.`);const a=O();if(null===a&&F(`CustomElementRegistry is unavailable for <${o}>.`),void 0===a.get(o)){s||F(`Spread binding "${n.statePathName}" requires <${o}> to be registered. Define the custom element before initializing this binding.`),r.push(n);continue}D(a,t);const l=R(t);null===l&&F(`Spread binding "${n.statePathName}" requires <${o}> to expose a valid wcBindable declaration.`);const c=n.statePathName,d=n.stateName,u=new Set;for(const e of l.knownProperties.keys()){if(u.has(e))continue;u.add(e);const t=z(e,c,d);i.add(t),r.push(t)}for(const e of l.declaredInputs.keys()){if(u.has(e))continue;u.add(e);const t=z(e,c,d);i.add(t),r.push(t)}}const a=new Map;for(let e=0;e<r.length;e++){const t=q(r[e]);null!==t&&a.set(t,e)}const l=[];for(let t=0;t<r.length;t++){const o=q(r[t]);if(null!==o){if(a.get(o)===t)l.push(r[t]);else if(n.debug&&i.has(r[t])){const n=r[a.get(o)],s=e.nodeType===Node.ELEMENT_NODE?`<${e.tagName.toLowerCase()}>`:"node";console.debug(`[@wcstack/state] spread: prop "${r[t].propName}" of ${s} overridden by explicit binding (statePath: "${n.statePathName}").`)}}else l.push(r[t])}return l}(e,t,{allowDeferred:o.allowDeferred});if(s.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?M(e):null;return null===n&&F("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t}}}ve.add(e);const r=function(e,t){const n=[];for(const o of t)if("text"!==o.bindingType)n.push({...o,node:e,replaceNode:e});else{const t=e.nodeType===Node.TEXT_NODE?e:document.createTextNode("");n.push({...o,node:e,replaceNode:t})}return n}(e,s);return G(e,r),l(e),{bindings:r,deferred:null}}function Se(e){const t=we(e),n=[],o=[];for(const e of t){if(ve.has(e))continue;const t=Ne(e,be(e),{allowDeferred:!0});null===t.deferred?n.push(...t.bindings):o.push(t.deferred)}return[t,n,o]}function xe(e){ve.add(e)}function Ie(e){const{node:t,parseResults:n}=e;!function(e){ve.delete(e)}(t);return Ne(t,n,{allowDeferred:!1}).bindings}const Ae=new WeakMap;function Pe(e){let t=e;for(;t;){const e=Ae.get(t);if(e)return e;t=t.parentNode}return null}function _e(e,t){null!==t?Ae.set(e,t):Ae.delete(e)}const $e=new WeakMap;function Te(e){return $e.get(e)??[]}function ke(e,t){$e.set(e,t)}const Ce=Symbol("$$setLoopContext"),Ee=Symbol("$$getByAddress"),Me=Symbol("$$hasByAddress"),Oe=Symbol("$$setByAddress"),De=Symbol("$$connectedCallback"),Re=Symbol("$$disconnectedCallback"),Le=Symbol("$$updatedCallback"),We=new WeakMap;function Be(e,t){if(We.has(e)){const n=We.get(e);if(n.has(t))return n.get(t)}else We.set(e,new WeakMap);const n=Object.freeze(new je(e,t));return We.get(e).set(t,n),n}class je{pathInfo;stateName;stateElement;parentAbsolutePathInfo;constructor(e,t){this.pathInfo=t,this.stateName=e.name,this.stateElement=e,null===t.parentPathInfo?this.parentAbsolutePathInfo=null:this.parentAbsolutePathInfo=Be(e,t.parentPathInfo)}}const Fe=new WeakMap,ze=new WeakMap;class qe{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]===d?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAbsoluteAddress=Ue(e,t)}}function Ue(e,t){if(null===t){let t=ze.get(e);return void 0!==t||(t=new qe(e,null),ze.set(e,t)),t}{let n=Fe.get(t);void 0===n&&(n=new WeakMap,Fe.set(t,n));let o=n.get(e);return void 0!==o||(o=new qe(e,t),n.set(e,o)),o}}const Ve=new WeakMap;function He(e,t){null===t?Ve.delete(e):Ve.set(e,t)}function Ge(e){return Ve.get(e)||null}const Je=new Map;function Ke(e,t){let n,o;if(0===e.wildcardCount||0===t.wildcardCount)return 0;if(1===e.wildcardCount&&t.wildcardCount>0&&t.wildcardPathSet.has(e.path))return 1;e.id<t.id?(n=e,o=t):(n=t,o=e);const s=`${n.path}\t${o.path}`;let r=Je.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,Je.set(s,r),r}const Xe=new WeakMap;function Ye(e){const t=Pe(e.node);if(null===t)return null;let n=Xe.get(t);if(void 0===n)n=new WeakMap,Xe.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let o=null;try{const n=Ke(t.pathInfo,e.statePathInfo);return n>0&&(o=t.listIndex.at(n-1)),o}finally{n.set(e,o)}}const Qe=new WeakMap;function Ze(e,t){if(null!=t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=Ge(n);null===t?F(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}return n}function et(e,t){let n=null;if(n=Qe.get(e)||null,null!==n)return n;const o=Ze(e,t),s=Ye(e),r=nr(o,e.stateName);null===r&&F(`State element with name "${e.stateName}" not found for binding.`);return n=Ue(Be(r,e.statePathInfo),s),Qe.set(e,n),n}function tt(e){Qe.delete(e)}let nt=null;const ot=new WeakMap;function st(e,t){const n=ot.get(e);void 0===n?ot.set(e,t):n instanceof Set?n.add(t):n!==t&&ot.set(e,new Set([n,t])),null!==nt&&nt({type:"state:binding-added",absoluteAddress:e,binding:t})}function rt(e,t){const n=ot.get(e);void 0!==n&&(n instanceof Set?n.delete(t):n===t&&ot.delete(e),null!==nt&&nt({type:"state:binding-removed",absoluteAddress:e,binding:t}))}const it=new WeakMap;function at(e){const t=ot.get(e);return void 0!==t?t:null!==e.listIndex?it.get(e.absolutePathInfo)?.get(e.listIndex):void 0}const lt=new WeakMap,ct=new WeakMap;class dt{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]===d?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=ut(e,t)}}function ut(e,t){if(null===t){let t=ct.get(e);return void 0!==t||(t=new dt(e,null),ct.set(e,t)),t}{let n=lt.get(t);void 0===n&&(n=new WeakMap,lt.set(t,n));let o=n.get(e);return void 0!==o||(o=new dt(e,t),n.set(e,o)),o}}const ft=new WeakMap;function pt(e){let t=null;if(t=ft.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=Ye(e);null===n&&F(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=ut(e.statePathInfo,n)}else t=ut(e.statePathInfo,null);return ft.set(e,t),t}function ht(e){ft.delete(e)}function mt(){const e=new Map,t=new Map;return{add(n,o){let s=e.get(n);return void 0===s&&(s=new WeakSet,e.set(n,s)),!s.has(o)&&(s.add(o),t.set(n,(t.get(n)??0)+1),!0)},remove(n,o){const s=e.get(n);if(void 0===s||!s.has(o))return!1;s.delete(o);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 gt=new Map,yt=mt();function bt(e,t){const n=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.statePathName}::${t}::${n}`}function wt(e){let t="input";for(const n of e.propModifiers)n.startsWith("on")&&(t=n.slice(2));return t}function vt(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf("ro")){const s=wt(e),r=bt(e,s);let i=gt.get(r);return void 0===i&&(t=e.stateName,n=e.statePathName,o=e.inFilters,i=e=>{const s=e.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("checkbox"!==s.type)return void console.warn("[@wcstack/state] event.target is not a checkbox input element.");const r=s.checked;let i=s.value;for(const e of o)i=e.filterFn(i);const a=nr(s.getRootNode(),t);null===a&&F(`State element with name "${t}" not found for two-way binding.`);const l=Pe(s);a.createState("writable",e=>{e[Ce](l,()=>{let t=e[n];if(Array.isArray(t))if(r)-1===t.indexOf(i)&&(e[n]=t.concat(i));else{const o=t.indexOf(i);-1!==o&&(e[n]=t.toSpliced(o,1))}else e[n]=r?[i]:[]})})},gt.set(r,i)),e.node.addEventListener(s,i),yt.add(r,e),!0}var t,n,o;return!1}function Nt(e){return("object"==typeof e||"function"==typeof e)&&null!==e&&"function"==typeof e.then}function St(e,t){const n=Array.isArray(e)?e:[e];for(const e of n)Nt(e)&&Promise.resolve(e).catch(e=>{console.error(`[wcstack/state] ${t} rejected.`,e)})}class xt{_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 It extends xt{_ownerStateName;constructor(e,t){super(e),this._ownerStateName=t??null}emit(...e){return null!==nt&&nt({type:"state:token-emit",kind:"event",stateName:this._ownerStateName,tokenName:this.name,args:e,subscriberCount:this.size}),super.emit(...e)}}const At=new WeakMap;function Pt(e,t){let n=At.get(e);void 0===n&&(n=new Map,At.set(e,n));let o=n.get(t);return void 0===o&&(o=new It(t,e.name),n.set(t,o)),o}function _t(e){At.delete(e)}const $t=new WeakMap;function Tt(e){if("eventToken"!==e.propSegments[0])return!1;const t=e.node,n=M(t),o=O();if(null!==n&&void 0===o?.get(n))return null===o&&F(`CustomElementRegistry is unavailable for <${n}>.`),!0;if($t.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||F('eventToken binding requires a property name (e.g., "eventToken.error").');const r=function(e){return null===M(e)?null:R(e)}(t);null===r&&F(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const i=r.knownProperties.get(s);void 0===i&&F(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.`);const a=i.event,l=e.statePathName,c=e.stateName,d=e.propModifiers,u=e=>{d.includes("prevent")&&e.preventDefault(),d.includes("stop")&&e.stopPropagation();const n=nr(t.getRootNode(),c);null===n&&F(`State element with name "${c}" not found for eventToken handler.`),n.eventTokenNames.has(l)||F(`eventToken "${l}" is not declared in $eventTokens of state "${c}".`);const o=Pe(t);n.createStateAsync("writable",async t=>{St(t[Ce](o,()=>{const s=o?.listIndex.indexes??[];return Pt(n,l).emit(t,e,...s)}),`$on."${l}" of state "${c}"`)})};return t.addEventListener(a,u),$t.set(e,{eventName:a,handler:u}),!0}class kt extends xt{_ownerStateName;constructor(e,t){super(e),this._ownerStateName=t??null}emit(...e){return null!==nt&&nt({type:"state:token-emit",kind:"command",stateName:this._ownerStateName,tokenName:this.name,args:e,subscriberCount:this.size}),super.emit(...e)}}function Ct(e){return e instanceof kt}const Et=new Map,Mt=mt();function Ot(e){const t=e.propModifiers.filter(e=>"prevent"===e||"stop"===e).sort().join(",");return`${e.stateName}::${e.statePathName}::${t}`}const Dt=(e,t,n,o)=>s=>{n.includes("prevent")&&s.preventDefault(),n.includes("stop")&&s.stopPropagation();const r=s.target,i=nr(r.getRootNode(),e);null===i&&F(`State element with name "${e}" not found for event handler.`);const a=Pe(r),l=t.startsWith(N+".");i.createStateAsync("writable",async n=>{St(n[Ce](a,()=>{const r=a?.listIndex.indexes??[];if(l){const e=n[Ee](ut(o,null));return Ct(e)||F(`Event binding "${t}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),e.emit(s,...r)}const i=n[t];return"function"!=typeof i&&F(`Handler "${t}" is not a function on state "${e}".`),Reflect.apply(i,n,[s,...r])}),`"${t}" of state "${e}"`)})};function Rt(e){if(!e.propName.startsWith("on"))return!1;const t=Ot(e);let n=Et.get(t);void 0===n&&(n=Dt(e.stateName,e.statePathName,e.propModifiers,e.statePathInfo),Et.set(t,n));const o=e.propName.slice(2);return e.node.addEventListener(o,n),Mt.add(t,e),!0}const Lt=new Map,Wt=mt();function Bt(e,t){const n=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.statePathName}::${t}::${n}`}function jt(e){let t="input";for(const n of e.propModifiers)n.startsWith("on")&&(t=n.slice(2));return t}function Ft(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf("ro")){const s=jt(e),r=Bt(e,s);let i=Lt.get(r);return void 0===i&&(t=e.stateName,n=e.statePathName,o=e.inFilters,i=e=>{const s=e.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==s.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===s.checked)return;let r=s.value;for(const e of o)r=e.filterFn(r);const i=nr(s.getRootNode(),t);null===i&&F(`State element with name "${t}" not found for two-way binding.`);const a=Pe(s);i.createState("writable",e=>{e[Ce](a,()=>{e[n]=r})})},Lt.set(r,i)),e.node.addEventListener(s,i),Wt.add(r,e),!0}var t,n,o;return!1}const zt=new Set(["radio","checkbox"]),qt=new Set(["value","valueAsNumber","valueAsDate"]);function Ut(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return!1;const n=e,o=n.tagName.toLowerCase();if("input"===o){const e=(n.getAttribute("type")||"text").toLowerCase();if("button"===e)return!1;if(zt.has(e)&&"checked"===t)return!0;if(qt.has(t))return!0}if("select"===o&&"value"===t)return!0;if("textarea"===o&&"value"===t)return!0;const s=M(n);if(null!==s){const e=O()?.get(s);void 0===e&&F(`Custom element <${s}> is not defined. Cannot determine if property "${t}" is suitable for two-way binding.`);const o=R(n);if(o?.knownProperties.has(t))return!0}return!1}let Vt=1,Ht=1,Gt=1;const Jt=new WeakMap;function Kt(e,t,n,o){let s=Jt.get(e);void 0===s&&(s=new Map,Jt.set(e,s));const r=function(e,t,n){return`${t}::${n}::${e}`}(t,n,o);let i=s.get(r);return void 0===i&&(i=Vt++,s.set(r,i)),i}function Xt(e,t){return"to-element"===t?2*e:2*e+1}const Yt=new Set;function Qt(e){return{transactionId:Ht++,originBindingId:e,visitedEdges:Yt,hop:0}}function Zt(e,t){const n=new Set(e.visitedEdges);return n.add(t),{transactionId:e.transactionId,originBindingId:e.originBindingId,visitedEdges:n,hop:e.hop+1}}let en=null;function tn(){return en}function nn(e,t){const n=en;en=e;try{return t()}finally{en=n}}const on=[];let sn=!1;const rn=new Map,an=mt(),ln=new WeakMap,cn=e=>e.detail;function dn(e,t,n,o){const s=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.propName}::${e.statePathName}::${t}::${s}::${n?"g":"n"}::${o?"o":"s"}`}function un(e){let t="select"===e.node.tagName.toLowerCase()?"change":"input";const n=M(e.node);if(null!==n){const o=O()?.get(n);void 0===o&&F(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=R(e.node)?.knownProperties.get(e.propName);s&&(t=s.event)}for(const n of e.propModifiers)n.startsWith("on")&&(t=n.slice(2));return t}function fn(e){if(null!==M(e.node)){const t=R(e.node)?.knownProperties.get(e.propName);if(t)return t.getter??cn}return null}function pn(e){if(null===M(e.node))return!1;const t=R(e.node)?.knownProperties.get(e.propName);return"event"===t?.semantics}const hn=(e,t,o,s,r,i)=>a=>{const l=a.target;if(null===l)return void console.warn("[@wcstack/state] event.target is null.");let c;if(null!==r)c=r(a);else{if(!(t in l))return void console.warn(`[@wcstack/state] Property "${t}" does not exist on target element.`);c=l[t]}let d=c;for(const e of s)d=e.filterFn(d);const u=ln.get(l)?.get(t);if(void 0!==u)for(const e of u)e(d);let f=null;if(n.enablePropagationContext){const s=Kt(l,t,e,o),r=function(e,t){for(let n=on.length-1;n>=0;n--){const o=on[n];if(o.node===e&&o.receipt.member===t)return o.receipt}return null}(l,t);if(null!==r&&Object.is(r.writtenValue,c))return n.debug&&console.debug("[@wcstack/state] propagation: write confirmation suppressed echo.",{node:l,propName:t,statePathName:o,transactionId:r.transactionId,coveredBySameValueGuard:n.sameValueGuard&&(null===d||"object"!=typeof d)}),void(null!==nt&&nt({type:"propagation:suppressed",reason:"confirmation",transactionId:r.transactionId,edgeId:Xt(s,"to-state"),node:l,member:t}));const i=Xt(s,"to-state"),a=tn();if(null!==a&&a.visitedEdges.has(i))return void(null!==nt&&nt({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:i,node:l,member:t}));f=Zt(a??Qt(s),i)}const p=nr(l.getRootNode(),e);null===p&&F(`State element with name "${e}" not found for two-way binding.`);const h=Pe(l),m=()=>{i&&(sn=!0);try{p.createState("writable",e=>{e[Ce](h,()=>{e[o]=d})})}finally{i&&(sn=!1)}};null!==f?nn(f,m):m()};const mn=new WeakSet;function gn(e){mn.add(e)}function yn(e){return!!mn.has(e)&&(mn.delete(e),!0)}const bn=new WeakSet;function wn(e){bn.add(e)}function vn(e){return!!bn.has(e)&&(bn.delete(e),!0)}let Nn=0;function Sn(){Nn--}function xn(){return Nn>0}class In{registry;entries=new Map;constructor(e){this.registry=e}wait(e,t,n=()=>{}){const o=e.toLowerCase();let s=this.entries.get(o);void 0===s&&(s={waiters:new Set},this.entries.set(o,s),this.registry.whenDefined(o).then(()=>this.settle(o,null),e=>this.settle(o,e)));const r={active:!0,resolve:t,reject:n};return s.waiters.add(r),()=>{r.active&&(r.active=!1,s?.waiters.delete(r))}}pendingCount(e){return this.entries.get(e.toLowerCase())?.waiters.size??0}settle(e,t){const n=this.entries.get(e);if(void 0===n)return;this.entries.delete(e);const o=Array.from(n.waiters);n.waiters.clear();for(const e of o)e.active&&(e.active=!1,null===t?e.resolve():e.reject(t))}}const An=new WeakMap;function Pn(e){let t=An.get(e);return void 0===t&&(t=new In(e),An.set(e,t)),t}function _n(e,t){let n=null;for(const o of e.propModifiers){const e=o.indexOf("=");if(e<0)continue;const s=o.slice(0,e).trim(),r=o.slice(e+1).trim();"init"!==s&&"sync"!==s&&F(`Unknown binding modifier "${s}" in "${o}".`),s===t&&(null!==n&&F(`Binding modifier "${t}" may only be specified once.`),n=r)}return n}function $n(e){return e.propModifiers.some(e=>e.includes("="))}const Tn=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),kn=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function Cn(e,t){return"state"===e&&"call"===t?Tn:{authority:e,syncOn:t,observable:!1,outputOnly:!1}}function En(e){if(!n.enableDirectionalInitialSync)return $n(e)&&F("init=/sync= modifiers require enableDirectionalInitialSync."),Tn;const t=null===(o=_n(e,"init"))?null:"state"===o||"element"===o||"auto"===o||"none"===o?o:F(`Invalid init modifier value "${o}".`);var o;const s=function(e){return null===e||"call"===e?"call":"connect"===e?"connect":F(`Invalid sync modifier value "${e}".`)}(_n(e,"sync"));if("event"===e.bindingType)return null!==t&&"none"!==t&&F("Event bindings only allow init=none."),"call"===s?kn:{authority:"none",syncOn:s,observable:!1,outputOnly:!1};if("command"===e.propSegments[0])return Cn("state",s);if("prop"!==e.bindingType)return null!==t&&"state"!==t&&"none"!==t&&F(`Binding type "${e.bindingType}" does not support init=${t}.`),Cn(t??"state",s);const r=R(e.node);if(null===r)return Cn(t??"state",s);const i=r.knownProperties.has(e.propName),a=r.declaredInputs.has(e.propName);i||a||F(`Property "${e.propName}" is not declared by wcBindable.`);const l=t??(i&&!a?"element":"state");return(i&&a?new Set(["state","element","auto","none"]):i?new Set(["element","none"]):new Set(["state","none"])).has(l)||F(`init=${l} is incompatible with wcBindable member "${e.propName}".`),"connect"!==s||i||F(`sync=connect requires observable property "${e.propName}".`),{authority:l,syncOn:s,observable:i,outputOnly:i&&!a}}function Mn(e,t){return"auto"!==t?t:function(e){const t=nr(e.replaceNode.getRootNode(),e.stateName);null===t&&F(`State element with name "${e.stateName}" not found for binding.`);const n=pt(e);let o=!1;return t.createState("readonly",e=>{o=e[Me](n)}),o}(e)?"state":"element"}let On=0,Dn=0;const Rn=new WeakMap,Ln=new WeakMap,Wn=new WeakMap,Bn=new WeakMap;function jn(e,t){const n=Bn.get(e);void 0!==n?n!==t&&(n instanceof Set?n.add(t):Bn.set(e,new Set([n,t]))):Bn.set(e,t)}function Fn(e,t){const n=Bn.get(e);if(void 0!==n)if(n instanceof Set)for(const e of Array.from(n))t(e);else t(n)}function zn(e,t){if(t(e),null!==e.firstChild)for(const n of Array.from(e.childNodes))zn(n,t)}function qn(e){if("object"!=typeof e||null===e)return!1;const t=e;return 9===t.nodeType||11===t.nodeType&&"host"in t}class Un{root;observer;constructor(e){this.root=e;const t=globalThis.MutationObserver;this.observer="function"==typeof t?new t(e=>this.handleMutations(e)):null,this.observer?.observe(e,{childList:!0,subtree:!0})}handleMutations(e){const t=[],n=[];for(const o of e)t.push(...Array.from(o.removedNodes)),n.push(...Array.from(o.addedNodes));const o=[];for(const e of t)yn(e)||zn(e,e=>{Fn(e,t=>{this.root.contains(e)||t.handleRemovedNode(e)})});for(const e of n)vn(e)&&!xn()||zn(e,e=>{Fn(e,t=>{this.root.contains(e)&&t.handleAddedNode(e,o)})});o.length>0&&gs(o)}}const Vn=new WeakMap;function Hn(e){let t=Vn.get(e);return void 0===t&&(t=new Un(e),Vn.set(e,t)),t}function Gn(e){const t=e.inFilters.map(e=>`${e.filterName}(${e.args.join(",")})`).join("|"),n=e.outFilters.map(e=>`${e.filterName}(${e.args.join(",")})`).join("|");return[e.bindingType,e.propName,e.propModifiers.join(","),e.stateName,e.statePathName,t,n,e.uuid??""].join("\0")}function Jn(e,t){null===e.teardowns&&(e.teardowns=new Set),e.teardowns.add(t)}class Kn{records=new Set;rowPlan=null;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;constructor(e=null){null!==e&&this.observe(e)}initialize(e,t={},n){const o=t.registerAddress??!0,s={registerAddress:o,registerPathInfo:t.registerPathInfo??o,applyOnReconnect:t.applyOnReconnect??!0},r=[];for(const t of e){const e=this.remember(t,s),o=Rn.get(e);void 0===o||"disposed"===o.phase||"failed"===o.phase?(this.start(e,s,n),r.push(e)):(this.observe(o.anchor),s.registerAddress&&null===o.address&&null===o.patternListIndex&&(o.options.registerAddress=!0,this.registerAddress(o)),"active"===o.phase&&this.settleInitialRecord(o),this.settleConnectedSnapshot(o))}return r.filter(e=>this.shouldApplyState(e))}activate(e,t){if(qn(t)&&Hn(t),null===this.rowPlan)for(const n of e){const e=Rn.get(n);if(void 0!==e&&e.session===this&&"disposed"!==e.phase&&"failed"!==e.phase){null===e.address&&null===e.patternListIndex&&(e.options.registerAddress=!0,this.registerAddress(e,t)),"active"===e.phase&&this.settleInitialRecord(e),this.settleConnectedSnapshot(e);continue}const o=this.optionsByBinding.get(n);void 0!==o?(o.registerAddress=!0,this.start(n,o,t)):this.initialize([n],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}else this.activatePlanRows(this.rowPlan,e,t)}shouldApplyState(e){if(!n.enableDirectionalInitialSync)return $n(e)&&En(e),!0;const t=Rn.get(e);return void 0===t||t.session!==this||(!t.options.registerAddress||"waiting-definition"===t.phase||"failed"!==t.phase&&("active"===t.phase&&this.settleInitialRecord(t),t.initialApplyDone?"state"===t.resolvedAuthority||!t.outputOnlyMember&&!t.observationPending:(t.initialApplyDone=!0,"state"===t.resolvedAuthority)))}getRecord(e){const t=Rn.get(e);return t?.session===this?t:null}addTeardown(e,t){const n=Rn.get(e);return!(void 0===n||!this.isAlive(n,n.generation))&&(Jn(n,t),!0)}deferUntilDefined(e,t,n,o=()=>{}){const s=O();null===s&&F(`CustomElementRegistry is unavailable for <${t}>.`),this.observe(e),jn(e,this);const r={node:e,active:!0,cancel:null};let i=this.deferredByNode.get(e);void 0===i&&(i=new Set,this.deferredByNode.set(e,i)),i.add(r),this.deferred.add(r);const a=()=>!!r.active&&(r.active=!1,i?.delete(r),this.deferred.delete(r),!0);return r.cancel=Pn(s).wait(t,()=>{if(a())try{D(s,e),n()}catch(e){o(e)}},e=>{a()&&o(e)}),()=>{a()&&r.cancel?.()}}disposeBinding(e){const t=Rn.get(e);void 0!==t&&t.session===this&&this.disposeRecord(t)}dispose(){for(const e of Array.from(this.records))this.disposeRecord(e);for(const e of Array.from(this.deferred))e.active=!1,e.cancel?.(),this.deferred.delete(e),this.deferredByNode.get(e.node)?.delete(e)}canWholesaleDestroy(){if(this.deferred.size>0)return!1;for(const e of this.records)if(e.pendingDefinitions>0||e.observationPending)return!1;return!0}destroyRecords(){for(const e of this.records)null!==e.address&&(rt(e.address,e.info),e.address=null),e.phase="disposed",e.teardowns=null;this.records.clear()}observe(e){const t=function(e){const t=e.getRootNode();return qn(t)?t:null}(e);null!==t&&Hn(t)}handleMutations(e,t,n){for(const n of t)zn(n,t=>{e.contains(t)||this.handleRemovedNode(t)});const o=[];for(const t of n)zn(t,t=>{e.contains(t)&&this.handleAddedNode(t,o)});o.length>0&&gs(o)}handleRemovedNode(e){const t=this.knownBindingsByNode.get(e);if(void 0!==t)if(t instanceof Map)for(const e of t.values())this.disposeBinding(e);else this.disposeBinding(t);const n=this.deferredByNode.get(e);if(void 0!==n)for(const e of Array.from(n))e.active=!1,e.cancel?.(),n.delete(e),this.deferred.delete(e)}handleAddedNode(e,t){const n=this.knownBindingsByNode.get(e);if(void 0===n)return;const o=n instanceof Map?n.values():[n];for(const e of o){const n=Rn.get(e);if("active"===n?.phase){this.settleConnectedSnapshot(n);continue}if("disposed"!==n?.phase)continue;const o=this.optionsByBinding.get(e);if(void 0!==o)try{this.start(e,o),o.applyOnReconnect&&this.shouldApplyState(e)&&t.push(e)}catch{}}}knownMapFor(e){const t=this.knownBindingsByNode.get(e);if(t instanceof Map)return t;const n=new Map;if(void 0!==t){let e=Wn.get(t);void 0===e&&(e=Gn(t),Wn.set(t,e)),n.set(e,t)}return this.knownBindingsByNode.set(e,n),n}remember(e,t){const n=e.replaceNode;jn(n,this);const o=this.knownMapFor(n);let s=Wn.get(e);void 0===s&&(s=Gn(e),Wn.set(e,s));const r=o.get(s);if(void 0!==r){const e=this.optionsByBinding.get(r);return void 0!==e&&(e.registerAddress||=t.registerAddress,e.registerPathInfo||=t.registerPathInfo,e.applyOnReconnect||=t.applyOnReconnect),r}return o.set(s,e),this.optionsByBinding.set(e,{...t}),e}initializeRow(e,t){this.rowPlan=e;const n={registerAddress:!1,registerPathInfo:!1,applyOnReconnect:!1},o=e.slots;for(let e=0;e<t.length;e++){const s=t[e],r=o[e],i=s.replaceNode;jn(i,this),this.addKnownRowBinding(i,s,e),this.optionsByBinding.set(s,n);const a={id:++On,info:s,generation:++Dn,phase:"active",teardowns:null,session:this,anchor:i,options:n,address:null,patternPathInfo:null,patternListIndex:null,pendingDefinitions:0,initialPolicy:r.policy,resolvedAuthority:r.authority,initialSettled:!0,initialApplyDone:!1,outputOnlyMember:r.policy.outputOnly,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};if(Rn.set(s,a),this.records.add(a),r.isEvent){try{Rt(s)}catch(e){throw a.phase="failed",this.runTeardowns(a),this.records.delete(a),e}a.eventAttached=!0}}}activatePlanRows(e,t,n){const o=e.slots;for(let e=0;e<t.length;e++){const s=t[e],r=Rn.get(s);if(void 0!==r&&r.session===this){if(r.options.registerAddress=!0,"disposed"===r.phase||"failed"===r.phase){const t=o[e];if(r.generation=++Dn,r.phase="active",r.initialPolicy=t.policy,r.resolvedAuthority=t.authority,r.initialSettled=!0,r.initialApplyDone=!1,r.outputOnlyMember=t.policy.outputOnly,this.records.add(r),t.isEvent){try{Rt(s)}catch(e){throw r.phase="failed",this.runTeardowns(r),this.records.delete(r),e}r.eventAttached=!0}this.registerAddress(r,n);continue}null===r.address&&null===r.patternListIndex&&this.registerAddress(r,n)}else this.initialize([s],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}}addKnownRowBinding(e,t,n){const o=this.knownBindingsByNode.get(e);if(void 0===o)return void this.knownBindingsByNode.set(e,t);if(o instanceof Map)return void o.set("@plan:"+n,t);const s=new Map;s.set("@plan:first",o),s.set("@plan:"+n,t),this.knownBindingsByNode.set(e,s)}start(e,t,n){!function(e){const t=e.node,n=e.replaceNode;t!==n&&null!==t.parentNode&&t.parentNode.replaceChild(n,t)}(e);const o=this.optionsByBinding.get(e)??{...t},s={id:++On,info:e,generation:++Dn,phase:"discovered",teardowns:null,session:this,anchor:e.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,pendingDefinitions:0,initialPolicy:null,resolvedAuthority:null,initialSettled:!1,initialApplyDone:!1,outputOnlyMember:!1,observationPending:!1,eventSequence:0,hasProducerValue:!1,producerValue:void 0,eventAttached:!1,twowayAttached:!1};Rn.set(e,s),this.records.add(s),void 0===n&&this.observe(s.anchor);try{s.phase="attaching",this.attachListeners(s),s.options.registerAddress&&this.registerAddress(s,n),0===s.pendingDefinitions&&(s.phase="active")}catch(e){throw s.phase="failed",this.runTeardowns(s),this.records.delete(s),e}}attachListeners(e){const t=e.info;Rt(t)?e.eventAttached=!0:"eventToken"!==t.propSegments[0]?(Ft(t)&&Jn(e,()=>function(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf("ro")){const t=jt(e),n=Bt(e,t),o=Lt.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==Wt.countOf(n)&&(Wt.remove(n,e)&&Lt.delete(n),!0))}return!1}(t)),vt(t)&&Jn(e,()=>function(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf("ro")){const t=wt(e),n=bt(e,t),o=gt.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==yt.countOf(n)&&(yt.remove(n,e)&>.delete(n),!0))}return!1}(t)),this.attachAfterDefinition(e,()=>{if(n.enableDirectionalInitialSync&&Ut(t.node,t.propName)&&-1===t.propModifiers.indexOf("ro")){const n=function(e,t,n){let o=ln.get(e);void 0===o&&(o=new Map,ln.set(e,o));let s=o.get(t);return void 0===s&&(s=new Set,o.set(t,s)),s.add(n),()=>{s?.delete(n),0===s?.size&&o?.delete(t),0===o?.size&&ln.delete(e)}}(t.node,t.propName,t=>{this.isAlive(e,e.generation)&&(e.eventSequence+=1,e.hasProducerValue=!0,e.producerValue=t)});Jn(e,n)}!function(e){const t=M(e.node);if(null!==t){const e=O(),n=e?.get(t);if(void 0===n)return void(null===e&&F(`CustomElementRegistry is unavailable for <${t}>.`))}if(Ut(e.node,e.propName)&&-1===e.propModifiers.indexOf("ro")){const t=un(e),n=fn(e),o=pn(e),s=dn(e,t,null!==n,o);let r=rn.get(s);void 0===r&&(r=hn(e.stateName,e.propName,e.statePathName,e.inFilters,n,o),rn.set(s,r)),e.node.addEventListener(t,r),an.add(s,e)}}(t),e.twowayAttached=!0})):this.attachAfterDefinition(e,()=>{Tt(t)&&Jn(e,()=>function(e){if("eventToken"!==e.propSegments[0])return!1;const t=$t.get(e);return void 0!==t&&(e.node.removeEventListener(t.eventName,t.handler),$t.delete(e),!0)}(t))})}attachAfterDefinition(e,t){const n=M(e.info.node);if(null===n)return void t();const o=O();if(null===o&&F(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void t();e.phase="waiting-definition",e.pendingDefinitions+=1;const s=e.generation,r=Pn(o).wait(n,()=>{if(this.isAlive(e,s))try{D(o,e.info.node),t(),e.pendingDefinitions-=1,0===e.pendingDefinitions&&(e.phase="active",this.settleInitialRecord(e))}catch{e.phase="failed",this.runTeardowns(e),this.records.delete(e)}},()=>{this.isAlive(e,s)&&(e.phase="failed",this.runTeardowns(e),this.records.delete(e))});Jn(e,r)}settleInitialRecord(e){if(n.enableDirectionalInitialSync&&!e.initialSettled&&e.options.registerAddress){e.phase="synchronizing";try{const t=En(e.info),n=Mn(e.info,t.authority);if(e.initialPolicy=t,e.resolvedAuthority=n,e.initialSettled=!0,e.outputOnlyMember=t.outputOnly,e.phase="active",!t.observable)return;if("connect"===t.syncOn&&e.info.node instanceof HTMLElement&&!e.info.node.isConnected)return e.observationPending=!0,void Nn++;this.readProducerSnapshot(e,"call"===t.syncOn)}catch(t){throw e.phase="failed",this.runTeardowns(e),this.records.delete(e),t}}}readProducerSnapshot(e,t){if(!this.isAlive(e,e.generation))return;const n=e.info.node,o=e.info.propName;if(!(o in n))return;const s=e.eventSequence,r=n[o];e.observationPending&&(e.observationPending=!1,Sn()),t&&e.eventSequence!==s||(e.hasProducerValue=!0,e.producerValue=r,"element"===e.resolvedAuthority&&function(e,t){let n=t;for(const t of e.inFilters)n=t.filterFn(n);const o=nr(e.node.getRootNode(),e.stateName);null===o&&F(`State element with name "${e.stateName}" not found for initial binding sync.`);const s=Pe(e.node);o.createState("writable",t=>{t[Ce](s,()=>{t[e.statePathName]=n})})}(e.info,r))}settleConnectedSnapshot(e){if(n.enableDirectionalInitialSync&&e.observationPending&&e.info.node instanceof HTMLElement&&e.info.node.isConnected)try{this.readProducerSnapshot(e,!1)}catch{e.phase="failed",this.runTeardowns(e),this.records.delete(e)}}registerAddress(e,t){if(null!==e.address||null!==e.patternListIndex)return;const n=e.info,o=Ye(n);if(null!==o){const s=nr(Ze(n,t),n.stateName);null===s&&F(`State element with name "${n.stateName}" not found for binding.`);const r=Be(s,n.statePathInfo);!function(e,t,n){let o=it.get(e);void 0===o&&(o=new WeakMap,it.set(e,o));const s=o.get(t);void 0===s?o.set(t,n):s instanceof Set?s.add(n):s!==n&&o.set(t,new Set([s,n])),null!==nt&&nt({type:"state:binding-added",absoluteAddress:Ue(e,t),binding:n})}(r,o,n),e.patternPathInfo=r,e.patternListIndex=o}else{const o=et(n,t);st(o,n),e.address=o}if(!e.options.registerPathInfo)return;const s=nr(n.replaceNode.getRootNode(),n.stateName);null===s&&F(`State element with name "${n.stateName}" not found for binding.`),"event"!==n.bindingType&&s.setPathInfo(n.statePathName,n.bindingType)}isAlive(e,t){return e.generation===t&&Rn.get(e.info)===e&&"disposed"!==e.phase&&"failed"!==e.phase}disposeRecord(e){"disposed"!==e.phase&&(e.phase="disposed",this.runTeardowns(e),this.records.delete(e))}runTeardowns(e){e.observationPending&&(e.observationPending=!1,Sn());const t=e.info;if(null!==e.address)try{rt(e.address,t),e.address=null,ht(t),tt(t)}catch{}else if(null!==e.patternListIndex)try{!function(e,t,n){const o=it.get(e);if(void 0===o)return;const s=o.get(t);void 0!==s&&(s instanceof Set?s.delete(n):s===n&&o.delete(t),null!==nt&&nt({type:"state:binding-removed",absoluteAddress:Ue(e,t),binding:n}))}(e.patternPathInfo,e.patternListIndex,t),e.patternPathInfo=null,e.patternListIndex=null,ht(t),tt(t)}catch{}if(e.twowayAttached){e.twowayAttached=!1;try{!function(e){const t=M(e.node);if(null!==t){const e=O(),n=e?.get(t);if(void 0===n)return}if(Ut(e.node,e.propName)&&-1===e.propModifiers.indexOf("ro")){const t=un(e),n=dn(e,t,null!==fn(e),pn(e)),o=rn.get(n);if(void 0===o)return;e.node.removeEventListener(t,o),an.remove(n,e)&&rn.delete(n)}}(t)}catch{}}if(null!==e.teardowns){const t=Array.from(e.teardowns).reverse();e.teardowns=null;for(const e of t)try{e()}catch{}}if(e.eventAttached){e.eventAttached=!1;try{!function(e){if(!e.propName.startsWith("on"))return!1;const t=Ot(e),n=Et.get(t);if(void 0===n)return!1;const o=e.propName.slice(2);e.node.removeEventListener(o,n),0!==Mt.countOf(t)&&(Mt.remove(t,e)&&Et.delete(t))}(t)}catch{}}}}function Xn(e){let t=Ln.get(e);return void 0===t&&(t=new Kn(e),Ln.set(e,t)),t}function Yn(e){return Rn.get(e)?.session??null}const Qn=new WeakMap;function Zn(e,t){const n=Qn.get(e);return!!n&&!0===n.get(t)}function eo(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const to=Object.freeze([]);const no=new WeakMap;const oo=new WeakMap;function so(e){return oo.get(e)??[]}function ro(e,t){oo.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 io=0;function ao(){return`u${(io++).toString(36)}`}let lo=0;class co{uuid=ao();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=lo}get index(){return this._index}set index(e){this._index=e,this._version=++lo,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=lo),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 uo(e,t){return new co(e,t)}const fo=new WeakMap;function po(e){return fo.get(e)||null}function ho(e,t){null!==t?fo.set(e,t):fo.delete(e)}const mo=new WeakMap,go=Object.freeze([]),yo=new Set;function bo(e,t,n){const o=function(e,t,n){const o=Array.isArray(t)&&t.length>0?t:go,s=Array.isArray(n)&&n.length>0?n:go,r=function(e,t){const n=Array.isArray(e)&&e.length>0?e:go,o=Array.isArray(t)&&t.length>0?t:go;let s=mo.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=po(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:yo,deleteIndexSet:new Set(i),addIndexSet:yo};let t=po(s);if(0===o.length){if(null===t){t=[];for(let n=0;n<s.length;n++){const o=uo(e,n);t.push(o)}}return a={oldIndexes:i,newIndexes:t,changeIndexSet:yo,deleteIndexSet:yo,addIndexSet:new Set(t)}}if(function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(o,s))return a={oldIndexes:i,newIndexes:i,changeIndexSet:yo,deleteIndexSet:yo,addIndexSet:yo};if(null!==t)return function(e,t){const n=new Set(t),o=new Set(e),s=new Set,r=n.difference(o),i=o.difference(n),a=new Map;for(let t=0;t<e.length;t++)a.set(e[t],t);for(let e=0;e<t.length;e++){const n=t[e];r.has(n)||a.get(n)!==e&&s.add(n)}return{oldIndexes:e,newIndexes:t,changeIndexSet:s,deleteIndexSet:i,addIndexSet:r}}(i,t);t=[];const n=new Map;for(let e=0;e<o.length;e++){const t=o[e];let s=n.get(t);s||(s=[],n.set(t,s)),s.push(e)}const r=new Set,l=new Set;for(let o=0;o<s.length;o++){const a=s[o],c=n.get(a),d=c&&c.length>0?c.shift():void 0;if(void 0===d){const n=uo(e,o);t.push(n),l.add(n)}else{const e=i[d];d!==o&&r.add(e),t.push(e)}}return a={oldIndexes:i,newIndexes:t,changeIndexSet:r,deleteIndexSet:new Set(i).difference(new Set(t)),addIndexSet:l}}finally{void 0!==a&&(!function(e,t,n){let o=mo.get(e);o||(o=new WeakMap,mo.set(e,o)),o.set(t,n)}(o,s,a),ho(s,a.newIndexes))}}(e,t,n);return function(e){for(let t=0;t<e.length;t++)e[t].index!==t&&(e[t].index=t)}(o.newIndexes),o}function wo(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=[],o=[];let s=-1,r=!0;for(const i of e.newIndexes){if(e.addIndexSet.has(i))continue;const a=t.get(i);if(void 0===a)return null;a<s&&(r=!1),s=a,n.push(i),o.push(a)}if(r)return null;const i=function(e){const t=e.length,n=[],o=new Array(t).fill(-1);for(let s=0;s<t;s++){const t=e[s];let r=0,i=n.length;for(;r<i;){const o=r+i>>1;e[n[o]]<t?r=o+1:i=o}r>0&&(o[s]=n[r-1]),n[r]=s}const s=[];let r=n.length>0?n[n.length-1]:-1;for(;r>=0;)s.push(r),r=o[r];return s.reverse(),s}(o),a=new Set;for(const e of i)a.add(n[e]);return a}const vo=new WeakMap;function No(e){return vo.get(e)??[]}function So(e,t){vo.set(e,t)}const xo=new WeakMap;function Io(e){return xo.get(e)??null}function Ao(e,t){xo.set(e,t)}const Po=new WeakMap;function _o(e){return Po.get(e)??[]}function $o(e,t){Po.set(e,t)}function To(e,t){const n=_o(e);for(const e of n)_e(e,t)}function ko(e,t,n){To(e,t);const o=No(e),s=Io(e);null!==s&&s.activate(o,n.rootNode);for(const e of o){if(null===s){st(et(e),e)}(null===s||s.shouldApplyState(e))&&ms(e,n)}}function Co(e){if(!e.mounted)return;const t=No(e),n=Io(e);for(const e of t)if(null!==n)n.disposeBinding(e);else{rt(et(e),e)}!function(e){const t=_o(e);for(const e of t)_e(e,null)}(e)}const Eo=new WeakMap,Mo=Object.freeze(new Set);function Oo(e,t){const n=Eo.get(e);n?n.add(t):Eo.set(e,new Set([t]))}function Do(e){const t=Eo.get(e);return void 0!==t?t:Mo}function Ro(e,t){const n=Eo.get(e);n&&(n.delete(t),0===n.size&&Eo.delete(e))}const Lo=new Set(["if","elseif","else","for"]);class Wo{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;_ranged=!1;constructor(e,t=!1){this._content=e,this._ranged=t,this._childNodeArray=Array.from(this._content.childNodes),this._firstNode=this._childNodeArray.length>0?this._childNodeArray[0]:null,this._lastNode=this._childNodeArray.length>0?this._childNodeArray[this._childNodeArray.length-1]:null}get firstNode(){return this._firstNode}get lastNode(){return this._lastNode}get mounted(){return this._mounted}appendTo(e){for(const t of this._childNodeArray)wn(t),e.appendChild(t);this._mounted=!0}_movableNodes(){if(!this._ranged||!this._mounted)return this._childNodeArray;const e=this._firstNode,t=this._lastNode;if(null===e||null===t||null===e.parentNode)return this._childNodeArray;const n=[];for(let o=e;null!==o;o=o.nextSibling)if(n.push(o),o===t)return n;return this._childNodeArray}mountAfter(e){const t=e.parentNode;if(t){let n=e;for(const e of this._movableNodes())n.nextSibling!==e&&(wn(e),t.insertBefore(e,n.nextSibling)),n=e}this._mounted=!0}tryDestroy(){const e=Io(this);if(null===e||!e.canWholesaleDestroy())return!1;e.destroyRecords();for(const e of this._childNodeArray)gn(e),null!==e.parentNode&&e.parentNode.removeChild(e);const t=No(this);for(const e of t)if(Lo.has(e.bindingType)){const t=Do(e.node);for(const e of t)e.tryDestroy()||e.unmount()}return this._mounted=!1,!0}unmount(){Io(this)?.dispose();for(const e of this._childNodeArray)gn(e),null!==e.parentNode&&e.parentNode.removeChild(e);const e=No(this);for(const t of e){if(Lo.has(t.bindingType)){const e=Do(t.node);for(const t of e)t.unmount()}ht(t),tt(t)}this._mounted=!1}}function Bo(e){let t=e.topLevelStructural;return void 0===t&&(t=e.topLevelStructural=function(e){const t=new RegExp(`^@@(?:${n.commentForPrefix}|${n.commentIfPrefix}|${n.commentElseIfPrefix}|${n.commentElsePrefix}):`);for(let n=e.firstChild;null!==n;n=n.nextSibling)if(n.nodeType===Node.COMMENT_NODE&&t.test(n.data))return!0;return!1}(e.fragment)),t}function jo(e){const t=document.createDocumentFragment(),n=new Wo(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 Fo(e,t,n){const o=document.importNode(t.fragment,!0),s=t.nodeInfos,r=new Array(s.length);for(let e=0;e<s.length;e++){const t=U(o,s[e].nodePath);null===t&&F(`Node not found by path [${s[e].nodePath.join(", ")}] in fragment.`),xe(t),l(t),r[e]=t}const i=n.slots,a=new Array(i.length),c=[];for(let e=0;e<i.length;e++){const t=i[e],n=r[t.nodeIndex],o={...t.template,node:n,replaceNode:n};a[e]=o,t.isIndexBinding&&c.push(o)}const d=function(e,t){const n=new Kn;return n.initializeRow(e,t),n}(n,a),u=new Wo(o);return Ao(u,d),So(u,a),ro(u,c),$o(u,r),Oo(e.node,u),u}function zo(t){void 0!==t.uuid&&null!==t.uuid||F("BindingInfo.uuid is null.");const o=ye(t.uuid);o||F(`Fragment with UUID "${t.uuid}" not found.`);const s=!e()&&Bo(o);let r=o.rowPlan;if((void 0===r||null!==r&&r.directional!==n.enableDirectionalInitialSync)&&(r=o.rowPlan=function(e){const t=n.enableDirectionalInitialSync,o=[],s=e.nodeInfos;for(let t=0;t<s.length;t++){const n=s[t],r=U(e.fragment,n.nodePath);if(null===r)return null;for(const e of n.parseBindTextResults){const n=e.bindingType;if("text"!==n&&"prop"!==n&&"event"!==n)return null;const s=e.propSegments[0];if("command"===s||"eventToken"===s)return null;if("text"===n){if(r.nodeType!==Node.TEXT_NODE)return null}else if(null!==M(r))return null;if("prop"===n&&Ut(r,e.propName))return null;let i;try{i=En({...e,node:r,replaceNode:r})}catch{return null}if(i.observable||"auto"===i.authority)return null;o.push({nodeIndex:t,template:e,isEvent:"event"===n,isIndexBinding:e.statePathName in h,policy:i,authority:i.authority})}}return{directional:t,slots:o}}(o)),null!==r)return Fo(t,o,r);const i=document.importNode(o.fragment,!0),a=function(e,t){const[n,o]=function(e,t){const n=[],o=[];for(const s of t){const t=U(e,s.nodePath);if(null===t&&F(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),ve.has(t))continue;const r=Ne(t,s.parseBindTextResults,{allowDeferred:!1});o.push(...r.bindings),n.push(t)}return[n,o]}(e,t),s=new Kn,r=s.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:r,bindingSession:s}}(i,o.nodeInfos);s&&function(e,t){e.appendChild(document.createComment(`wcs-row-end:${t}`))}(i,t.uuid);const l=new Wo(i,s);Ao(l,a.bindingSession),So(l,a.bindingInfos);const c=[];for(const e of a.bindingInfos)e.statePathName in h&&c.push(e);return ro(l,c),$o(l,a.nodes),Oo(t.node,l),l}const qo=new WeakMap,Uo=new WeakMap,Vo=new WeakMap,Ho=new WeakMap;function Go(e,t,n){!function(e,t,n){let o=Uo.get(e);if(void 0===o){if(null===n)return;o=new WeakMap,Uo.set(e,o)}null===n?o.delete(t):o.set(t,n)}(e,t,n)}function Jo(e,t){qo.set(e,t)}function Ko(e,t){let n=Vo.get(e.node);void 0===n&&(n=[],Vo.set(e.node,n)),n.length<1e3?n.push(t):Ro(e.node,t)}function Xo(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 Yo(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function Qo(t,o,s){const r=Boolean(s);let i;const a=Do(t.node);i=0===a.size?zo(t):a.values().next().value;const l=e(),c=t.uuid??"",d=t.bindingType;if(r||(n.debug&&console.log(`unmount if content : ${Yo(t)}`),Co(i),i.unmount()),r){if(n.debug&&console.log(`mount if content : ${Yo(t)}`),l){const e=document.createComment(`@@wcs-${d}-start:${c}:${t.statePathName}`);t.node.parentNode.insertBefore(e,t.node.nextSibling),i.mountAfter(e);const n=document.createComment(`@@wcs-${d}-end:${c}:${t.statePathName}`),o=i.lastNode??e;o.parentNode.insertBefore(n,o.nextSibling)}else i.mountAfter(t.node);ko(i,Pe(t.node),o)}}const Zo=new WeakMap;function es(e){return Zo.get(e)??[]}const ts=new Set;const ns={value(e,t){"TEXTAREA"===e.tagName?e.textContent=String(t??""):e.setAttribute("value",String(t??""))},checked(e,t){t?e.setAttribute("checked",""):e.removeAttribute("checked")},selected(e,t){t?e.setAttribute("selected",""):e.removeAttribute("selected")},disabled(e,t){t?e.setAttribute("disabled",""):e.removeAttribute("disabled")},selectedIndex(e,t){const n=e.querySelectorAll("option"),o=Number(t);for(let e=0;e<n.length;e++)e===o?n[e].setAttribute("selected",""):n[e].removeAttribute("selected")}};function os(t,o,s){if(void 0===s)return void(n.debug&&console.debug("Skipped property write: state value is undefined.",{element:t.node,propSegments:t.propSegments,statePathName:t.statePathName}));const r=t.node,i=t.propSegments;if(1===i.length){const l=i[0];if(r[l]!==s){const e=()=>{let e=!1;try{r[l]=s,e=!0}catch(e){n.debug&&console.warn(`Failed to set property '${l}' on element.`,{element:r,newValue:s,error:e})}if(e){const e=function(e,t){const n=M(e);if(null===n)return null;const o=O()?.get(n);if(void 0===o)return null;const s=R(e)?.declaredInputs.get(t);return"string"==typeof s?.attribute&&s.attribute.length>0?s.attribute:null}(r,l);if(null!==e)try{!function(e,t,n){if(null==n)return void e.removeAttribute(t);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);e.setAttribute(t,o)}(r,e,s)}catch(t){n.debug&&console.warn(`Failed to mirror attribute '${e}' on element.`,{element:r,newValue:s,error:t})}}};if(n.enablePropagationContext&&Ut(r,l)){const n=Kt(r,l,t.stateName,t.statePathName),i=Xt(n,"to-element"),a=o?.propagationContextByBinding?.get(t)??tn()??Qt(n);if(a.visitedEdges.has(i))null!==nt&&nt({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:i,node:r,member:l});else{const t=Zt(a,i);nn(t,()=>function(e,t,n,o,s,r){const i={bindingId:o,bindingGeneration:0,member:t,transactionId:s,synchronousScopeId:Gt++,writtenValue:n};on.push({receipt:i,node:e});try{return r()}finally{on.pop()}}(r,l,s,n,t.transactionId,e))}}else e()}if(e()){const e=ns[l];e?e(r,s):(!function(e,t,n){let o=Zo.get(e);o||(o=[],Zo.set(e,o));const s=o.find(e=>e.propName===t);s?s.value=n:o.push({propName:t,value:n})}(r,l,s),a=r,ts.add(a))}return}var a;const l=i[0];let c=r[l];for(let e=1;e<i.length-1;e++){const t=i[e];if(null==c)return;c=c[t]}const d=c[i[i.length-1]];if(d!==s){if(Object.isFrozen(c))return void(n.debug&&console.warn("Attempting to set property on frozen object.",{element:r,propSegments:i,oldValue:d,newValue:s}));try{c[i[i.length-1]]=s}catch(e){n.debug&&console.warn("Failed to set property on sub-object.",{element:r,propSegments:i,oldValue:d,newValue:s,error:e})}}}const ss=new WeakSet;function rs(e,t,n){const o=e.node,s=e.propSegments;s.length<=1&&F(`Invalid propSegments for web component binding: ${s.join(".")}`);const[r,...i]=s,a=o[r];void 0===a&&F(`Property "${r}" not found on web component.`),a[i.join(".")]=n}function is(e,t){const n=pt(t);if(n.pathInfo.path in h){const e=Pe(t.node);return null===e&&F(`ListIndex not found for binding: ${t.statePathName}`),function(e,t){null===e.listIndex&&F("ListIndex not found for loopContext:");const n=h[t];void 0===n&&F(`Invalid index name: ${t}`);const o=e.listIndex.at(n);return null===o&&F(`Index not found at position ${n} for loopContext:`),o.index}(e,n.pathInfo.path)}return e[Ee](n)}const as=new WeakSet;function ls(e,t){console.error(`[@wcstack/state] deferred apply failed for <${e}>.`,t)}const cs={class:function(e,t,n){const o=e.node,s=e.propSegments[1];"boolean"!=typeof n&&F("Invalid value for class application: expected boolean, got "+typeof n),o.classList.toggle(s,n)},attr:function(e,t,n){const o=e.node,s=e.propSegments[1];o.getAttribute(s)!==n&&o.setAttribute(s,n)},style:function(e,t,n){const o=e.propSegments[1],s=e.node.style;s[o]!==n&&(s[o]=n)},command:function(e,t,n){Ct(n)||F("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=no.get(e);if(s&&s.token===o)return;const r=e.node,i=e.propSegments[1];"string"==typeof i&&0!==i.length||F('command binding requires a method name (e.g., "command.fetch").');const a=function(e){const t=M(e);if(null===t)return null;const n=O()?.get(t);return void 0===n&&F(`Custom element <${t}> is not defined for command binding.`),R(e)}(r);null===a&&F(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(i)||F(`Command "${i}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.`),s&&(s.unsubscribe(),no.delete(e));const l=new WeakRef(r);let c=null;c=o.subscribe((...t)=>{const n=l.deref();if(!n||!n.isConnected)return c?.(),void no.delete(e);const o=n[i];return"function"!=typeof o&&F(`Method "${i}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,t)}),no.set(e,{token:o,unsubscribe:c,elementRef:l})}},ds={text:function(t,n,o){const s=null==o?"":String(o);if(t.replaceNode.nodeValue!==s&&(t.replaceNode.nodeValue=s),e()&&!ss.has(t.replaceNode)){ss.add(t.replaceNode);const e=t.replaceNode.parentNode;if(e){const n=t.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);e.insertBefore(o,t.replaceNode),e.insertBefore(s,t.replaceNode.nextSibling)}}},for:function(t,n,o){const s=t.statePathInfo,r=Ye(t),i=et(t),a=Te(i),l=bo(r,a,o);n.newListValueByAbsAddress.set(i,Array.isArray(o)?o:[]);const c=Array.isArray(a)&&a.length===l.deleteIndexSet.size&&l.deleteIndexSet.size>0;if(c&&null!==t.node.parentNode){let e=Ho.get(t.node);if(void 0===e){const n=qo.get(t.node)||t.node;e=function(e,t){let n=e.previousSibling,o=t.nextSibling,s=!0;for(;null!==n;){if(n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&""!==(n.textContent?.trim()??"")){s=!1;break}n=n.previousSibling}for(;null!==o;){if(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE&&""!==(o.textContent?.trim()??"")){s=!1;break}o=o.nextSibling}return s}(t.node,n),Ho.set(t.node,e)}if(e){const e=t.node.parentNode;e.textContent="",e.appendChild(t.node)}}let u=Uo.get(t.node),f=c?1e3-function(e){return Vo.get(e.node)||[]}(t).length:Number.POSITIVE_INFINITY;if(void 0!==u){for(const e of l.deleteIndexSet){const n=u.get(e);void 0!==n&&(f<=0&&n.tryDestroy()?Ro(t.node,n):(Co(n),n.unmount(),Ko(t,n),f-=1),c||u.delete(e))}c&&(Uo.delete(t.node),u=void 0)}let p=t.node;const h=k(s.path+"."+d),m=n.stateElement.loopContextStack,g=wo(l);let y=null;l.newIndexes.length==l.addIndexSet.size&&l.newIndexes.length>0&&p.isConnected&&(y=document.createDocumentFragment(),He(y,n.rootNode));const b=e(),w=t.uuid??"",v=Vo.get(t.node);for(const e of l.newIndexes){let o;if(l.addIndexSet.has(e)){const r=ut(h,e);m.createLoopContext(r,r=>{if(o=void 0!==v?v.pop():void 0,void 0===o&&(o=zo(t)),null!==y)b&&y.appendChild(document.createComment(`@@wcs-for-start:${w}:${s.path}:${e.index}`)),o.appendTo(y),b&&y.appendChild(document.createComment(`@@wcs-for-end:${w}:${s.path}:${e.index}`));else{if(p.nextSibling!==o.firstNode){if(b){const t=document.createComment(`@@wcs-for-start:${w}:${s.path}:${e.index}`);p.parentNode.insertBefore(t,p.nextSibling),p=t}o.mountAfter(p)}if(b){const t=document.createComment(`@@wcs-for-end:${w}:${s.path}:${e.index}`),n=o.lastNode??p;n.parentNode.insertBefore(t,n.nextSibling)}}ko(o,r,n)}),void 0===o&&F(`Content not found for ListIndex: ${e.index} at path "${s.path}"`)}else{if(o=void 0!==u?u.get(e)??null:null,l.changeIndexSet.has(e)){const e=so(o);for(const t of e)ms(t,n)}null===o&&F(`Content not found for ListIndex: ${e.index} at path "${s.path}"`);null!==g&&g.has(e)&&Xo(p,o.firstNode)||p.nextSibling===o.firstNode||o.mountAfter(p)}p=o.lastNode||p,void 0===u&&(u=new WeakMap,Uo.set(t.node,u)),u.set(e,o)}qo.set(t.node,p),null!==y&&(t.node.parentNode.insertBefore(y,t.node.nextSibling),He(y,null))},if:Qo,else:Qo,elseif:Qo,radio:function(e,t,n){const o=e.node,s=eo(o.value,e.inFilters);o.checked=n===s},checkbox:function(e,t,n){const o=e.node,s=eo(o.value,e.inFilters),r=Array.isArray(n)?n:to;o.checked=r.includes(s)}},us=new WeakMap,fs=new WeakMap,ps=new WeakMap;function hs(e,t){const n=eo(is(t.state,e),e.outFilters);if(!0===fs.get(e))return void t.deferredSelectBindings.push({binding:e,value:n});let o=us.get(e);if(void 0===o){if(us.has(e))return Zn(e.replaceNode,t.stateElement)?(o=rs,us.set(e,o)):o=os,void o(e,t,n);if(o=ds[e.bindingType],void 0===o){const n=e.propSegments[0];if(o=cs[n],us.set(e,o),void 0===o){M(e.replaceNode)?Zn(e.replaceNode,t.stateElement)?(o=rs,us.set(e,o)):o=os:(o=os,us.set(e,o))}}if(o===os){if("SELECT"===e.node.tagName){const o=e.propSegments[0];if("value"===o||"selectedIndex"===o)return t.deferredSelectBindings.push({binding:e,value:n}),void fs.set(e,!0)}}o(e,t,n)}else o(e,t,n)}function ms(e,t){if(t.appliedBindingSet.has(e))return;if(t.appliedBindingSet.add(e),!1!==t.stateElement.hasUpdatedCallback){const n=et(e);if(t.updatedAbsAddressSetByStateElement.has(t.stateElement)){t.updatedAbsAddressSetByStateElement.get(t.stateElement).add(n)}else t.updatedAbsAddressSetByStateElement.set(t.stateElement,new Set([n]))}const n=Yn(e);if(null!==n&&!n.shouldApplyState(e))return;if("event"===e.bindingType)return;if(!0!==ps.get(e)){const t=M(e.replaceNode);if(t&&void 0===O()?.get(t))return void function(e,t){if(as.has(e))return;as.add(e);const n=()=>{as.delete(e);const t=Yn(e);(null===t||t.shouldApplyState(e))&&gs([e])},o=n=>{as.delete(e),ls(t,n)},s=Yn(e);if(null!==s){const r=s.deferUntilDefined(e.replaceNode,t,n,o);return void(s.addTeardown(e,()=>{as.delete(e),r()})||(as.delete(e),r()))}const r=O();if(null===r)return as.delete(e),void ls(t,new Error("CustomElementRegistry is unavailable."));Pn(r).wait(t,()=>{e.replaceNode.isConnected?n():as.delete(e)},o)}(e,t);ps.set(e,!0)}if(!0===t.sameRootVerified&&e.stateName===t.stateName)return void hs(e,t);let o=e.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=Ge(o),null===o&&F("Root node for fragment not found for binding.")),e.stateName!==t.stateName||o!==t.rootNode){const n=nr(o,e.stateName);null===n&&F(`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};hs(e,r)})}else hs(e,t)}function gs(e,t){let o=0;const s=new Set,r=new Map,i=new Map,a=[];for(;o<e.length;){let l=e[o];const c=l.stateName;if(!1===l.replaceNode.isConnected){n.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${l.bindingType} ${l.statePathName} on ${l.node.nodeName}`,l),o++;continue}let d=l.replaceNode.getRootNode();d instanceof DocumentFragment&&!(d instanceof ShadowRoot)&&(d=Ge(d),null===d&&F("Root node for fragment not found for binding."));const u=nr(d,c);null===u&&F(`State element with name "${c}" not found for binding.`),u.createState("readonly",n=>{const f={rootNode:d,stateName:c,stateElement:u,state:n,appliedBindingSet:s,newListValueByAbsAddress:r,updatedAbsAddressSetByStateElement:i,deferredSelectBindings:a,sameRootVerified:!0,propagationContextByBinding:t};for(;;){ms(l,f),o++;const t=e[o];if(!t)break;const n=t.replaceNode.getRootNode();if(t.stateName!==c||n!==f.rootNode)break;l=t}})}for(const{binding:e,value:n}of a)os(e,{propagationContextByBinding:t},n);for(const[e,t]of r.entries())ke(e,t);for(const[e,t]of i.entries())e.createState("writable",e=>{e[Le](Array.from(t))})}function ys(e,t){const[n,o,s]=Se(e),r=Xn(e);for(const e of n)_e(e,t);gs(r.initialize(o)),function(e,t,n){for(const o of e)n.deferUntilDefined(o.node,o.tagName,()=>{const e=Ie(o);0!==e.length&&(_e(o.node,t),gs(n.initialize(e)))},e=>{console.error(`[@wcstack/state] deferred spread failed for <${o.tagName}>.`,e)})}(s,t,r)}const bs=/\{\{\s*(.+?)\s*\}\}/g,ws=new Set(["SCRIPT","STYLE"]);function vs(e){if(!n.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&&ws.has(e.parentElement.tagName)||Ns(e)}(e);const t=Array.from(e.querySelectorAll("template"));for(const e of t)if("http://www.w3.org/2000/svg"===e.namespaceURI){const t=document.createElement("template"),n=Array.from(e.childNodes);for(let e=0;e<n.length;e++){const o=n[e];t.content.appendChild(o)}for(const n of e.attributes)t.setAttribute(n.name,n.value);e.replaceWith(t),vs(t.content)}else vs(e.content)}function Ns(e){const t=e.data;if(bs.lastIndex=0,!bs.test(t))return;bs.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=bs.exec(t));){o.index>s&&n.appendChild(document.createTextNode(t.slice(s,o.index)));const e=o[1];n.appendChild(document.createComment(`@@: ${e}`)),s=o.index+o[0].length}s<t.length&&n.appendChild(document.createTextNode(t.slice(s))),e.parentNode.replaceChild(n,e)}let Ss;function xs(){if(Ss)return Ss;const e=[],t=oe("not",e)(te);return Ss={filterName:"not",args:e,filterFn:t},Ss}const Is=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function As(e,t){const n=t+c+d,o=e.indexOf("|"),s=e.indexOf("@");let r,i;if(-1!==o?(r=e.slice(0,o).trim(),i=e.slice(o)):-1!==s?(r=e.slice(0,s).trim(),i=e.slice(s)):(r=e.trim(),i=""),"."===r)r=n;else{if(!r.startsWith("."))return e;r=n+c+r.slice(1)}return i.length>0?r+i:r}function Ps(e,t){const n=Is.exec(e);if(null===n)return e;const o=n[1],s=n[2],r=n[3];return o+As(s,t)+r}function _s(e,t){const n=e.split(";");let o=!1;const s=n.map(e=>{const n=e.trim();if(0===n.length)return e;const s=n.indexOf(":");if(-1===s)return e;const r=n.slice(0,s).trim(),i=n.slice(s+1).trim(),a=As(i,t);return a!==i?(o=!0,`${r}: ${a}`):e});return o?s.join(";"):e}function $s(e,t){return _s(e,t)}function Ts(e,t){const o=n.bindAttributeName,s=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const e=s.currentNode;if(e.nodeType===Node.COMMENT_NODE){const n=e;n.data=Ps(n.data,t);continue}const n=e;if(n instanceof HTMLTemplateElement)continue;const r=n.getAttribute(o);if(null!==r){const e=_s(r,t);e!==r&&n.setAttribute(o,e)}}}function ks(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=we(e);for(const e of n){const n=be(e);let o=e;if(e.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==e.parentNode){const t=document.createTextNode("");e.parentNode.replaceChild(t,e),o=t}t.push({nodePath:ks(o),parseBindTextResults:n})}return t}function Es(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 Ms=new Map([["for",n.commentForPrefix],["if",n.commentIfPrefix],["elseif",n.commentElseIfPrefix],["else",n.commentElsePrefix]]),Os=xs();function Ds(e,t){const n=t.outFilters;return{...t,outFilters:[...n,Os],bindingType:e}}function Rs(e,t,n,o){Es(t),"string"==typeof o&&Ts(t,o),Ls(e,t,o);return{fragment:t,parseBindTextResult:n,nodeInfos:Cs(t)}}function Ls(e,t,o){const s=n.commentElsePrefix,r=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode(e){const t=e;if("template"===t.tagName.toLowerCase()){if((t.getAttribute(n.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let i=null;const a=[],l=[];for(;r.nextNode();){const e=r.currentNode;l.push(e)}for(const t of l){let r=t.getAttribute(n.bindAttributeName)||"";"string"==typeof o&&(r=$s(r,o));let l=de(r)[0];const c=Ms.get(l.bindingType);if(void 0===c)continue;const d=l.bindingType,u=t.content,f=ao();let p=null;const h="for"===d?l.statePathName:o;if("else"===d){null===i&&F("'else' binding found without preceding 'if' or 'elseif' binding."),l=Ds("else",i.parseBindTextResult),p=Rs(e,u,l,h),ge(f,e,p);const n=a.at(-1),o=document.createComment(`@@${c}:${f}`);void 0!==n?(t.remove(),n.fragment.appendChild(o),n.nodeInfos.push({nodePath:ks(o),parseBindTextResults:be(o)})):t.replaceWith(o)}else if("elseif"===d){null===i&&F("'elseif' binding found without preceding 'if' or 'elseif' binding."),p=Rs(e,u,l,h),ge(f,e,p);const n=document.createComment(`@@${c}:${f}`),o=ao(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Ds("else",i.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:ks(n),parseBindTextResults:be(n)}),ge(o,e,r);const d=a.at(-1);a.push(r);const m=document.createComment(`@@${s}:${o}`);void 0!==d?(t.remove(),d.fragment.appendChild(m),d.nodeInfos.push({nodePath:ks(m),parseBindTextResults:be(m)})):t.replaceWith(m)}else{p=Rs(e,u,l,h),ge(f,e,p);const n=document.createComment(`@@${c}:${f}`);t.replaceWith(n)}"if"===d?(a.length=0,i=p):"elseif"===d?i=p:"else"===d&&(i=null,a.length=0)}}async function Ws(e){const t=e.querySelectorAll(n.tagNames.state),o=[];await customElements.whenDefined(n.tagNames.state);for(const e of t){const t=e;o.push(t.initializePromise)}await Promise.all(o)}async function Bs(e){if(e===document)await Ws(document),vs(document),Ls(document,document),ys(document.body,null);else{const t=e;t.host.hasAttribute(n.bindAttributeName)&&await a(t.host),await Ws(t),vs(t),Ls(t,t),ys(t,null)}}const js="1.25.0",Fs="undefined"==typeof HTMLElement?class{}:HTMLElement,zs=/^@@wcs-(?:for|if|elseif|else):[^-]/,qs=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,Us=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,Vs=/^@@wcs-text-start:(.+)$/;function Hs(e){return e.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class Gs extends Fs{_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=js.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 o=n.tagNames.ssr,s=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!s)return null;return s.querySelector(`${o}[name="${t}"]`)}static extractStateData(e){const t=e.__state;if(!t||"object"!=typeof t)return{};const n={};for(const[e,o]of Object.entries(t))e.startsWith("$")||"function"==typeof o||(n[e]=o);return n}static buildContent(e,t){const o=document.createElement("script");o.setAttribute("type","application/json"),o.textContent=Hs(JSON.stringify(t)),e.appendChild(o);const s=Array.from(me.keys());for(const t of s){const o=ye(t);if(!o)continue;const s=document.createElement("template");s.setAttribute("id",t);const r=o.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;s.setAttribute(n.bindAttributeName,i);const a=o.fragment.cloneNode(!0);s.content.appendChild(a),e.appendChild(s)}const r=Array.from(ts);if(r.length>0){const t={};for(let e=0;e<r.length;e++){const n=r[e],o=es(n);if(0===o.length)continue;const s=`wcs-ssr-${e}`;n.setAttribute("data-wcs-ssr-id",s);const i={};for(const e of o)i[e.propName]=e.value;t[s]=i}if(Object.keys(t).length>0){const n=document.createElement("script");n.setAttribute("type","application/json"),n.setAttribute("data-wcs-ssr-props",""),n.textContent=Hs(JSON.stringify(t)),e.appendChild(n)}}ts.clear()}static removeBlockBoundaryComments(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),n=[];for(;t.nextNode();){const e=t.currentNode;(qs.test(e.data)||Us.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;zs.test(e.data)&&n.push(e)}for(const e of n)e.remove()}static restoreTextBindings(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),n=[];for(;t.nextNode();){const e=t.currentNode,o=Vs.exec(e.data);o&&n.push({comment:e,path:o[1]})}for(const{comment:e,path:t}of n){const n=document.createComment(`@@: ${t}`);e.parentNode.insertBefore(n,e);let o=e.nextSibling;e.remove();const s=`@@wcs-text-end:${t}`;for(;o;){const e=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===s){o.parentNode.removeChild(o);break}o.parentNode.removeChild(o),o=e}}}static cleanupDom(e){const t=document.body,o=e.querySelectorAll(n.tagNames.ssr),s=new Map;for(const e of o){const t=e.querySelectorAll("template[id]");for(const e of t){const t=e.getAttribute("id");t&&s.set(t,e)}}const r=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const e=r.currentNode;qs.test(e.data)&&i.push(e)}for(const e of i){const t=qs.exec(e.data),n=`@@wcs-${t[1]}-end:${t[2]}`;let o=e.nextSibling;for(;o;){const e=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===n){o.remove();break}o.remove(),o=e}e.remove()}Gs.restoreTextBindings(t);const a=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const e=a.currentNode;if(zs.test(e.data)){const t=e.data.split(":")[1];l.push({comment:e,uuid:t})}}for(const{comment:e,uuid:t}of l){const o=s.get(t);if(o){const t=document.createElement("template"),s=o.getAttribute(n.bindAttributeName);s&&t.setAttribute(n.bindAttributeName,s);const r=document.importNode(o.content,!0);if(r.childNodes.length>0)t.content.appendChild(r);else for(const e of Array.from(o.childNodes))t.content.appendChild(document.importNode(e,!0));e.parentNode.replaceChild(t,e)}}const c=e.querySelectorAll("[data-wcs-ssr-id]");for(const e of c)e.removeAttribute("data-wcs-ssr-id");for(const e of o)e.remove()}}const Js=new Set(["for","if","elseif","else"]);function Ks(e){const t=new Kn;if(0===e.length)return{bindingInfos:[],subscriberNodes:[],bindingSession:t};const n=e[0].parentNode,o=e[e.length-1].nextSibling,s=document.createElement("div");for(const t of e)s.appendChild(t);const[r,i]=Se(s),a=t.initialize(i,{registerAddress:!1,applyOnReconnect:!1});if(n)for(;s.firstChild;)n.insertBefore(s.firstChild,o);return{bindingInfos:a,subscriberNodes:r,bindingSession:t}}function Xs(e,t,o){const s={for:n.commentForPrefix,if:n.commentIfPrefix,elseif:n.commentElseIfPrefix,else:n.commentElsePrefix}[t];if(!s)return null;const r=`@@${s}:${o}`,i=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const e=i.currentNode;if(e.data===r)return e}return null}function Ys(e,t){const o=e;let s=null;for(const[e,r]of t.templates){let t=de(r.getAttribute(n.bindAttributeName)||"")[0];const i=t.bindingType;"else"===i&&s?t={...s,outFilters:[...s.outFilters,xs()],bindingType:"else"}:"elseif"===i&&s&&(t={...t,stateName:s.stateName}),"if"===i||"elseif"===i?s=t:"else"===i&&(s=null);const a=document.importNode(r.content,!0),l="for"===i?t.statePathName:void 0;Es(a),"string"==typeof l&&Ts(a,l),Ls(o,a,l);ge(e,o,{fragment:a,parseBindTextResult:t,nodeInfos:Cs(a)})}}async function Qs(e){await Ws(e);const t=e.querySelectorAll(n.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="${js}". Falling back to full render.`),Gs.cleanupDom(e),!1}for(const n of t)Ys(e,n);const o=function(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const e of o){const n=qs.exec(e.data);if(!n)continue;const o=n[1],s=n[2],r=s.split(":");let i,a,l=null;"for"===o?(i=r[0],a=r[1],l=parseInt(r[2],10)):(i=r[0],a=r.slice(1).join(":"));const c=[];let d=e.nextSibling;const u=`@@wcs-${o}-end:${s}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)c.push(d),d=d.nextSibling;t.push({type:o,uuid:i,path:a,index:l,nodes:c})}return t}(document.body);!function(e,t){const n=new Map;for(const o of t){if(0===o.nodes.length)continue;const t=jo(o.nodes),{bindingInfos:s,subscriberNodes:r,bindingSession:i}=Ks(o.nodes);Ao(t,i);for(const e of r)e.nodeType===Node.ELEMENT_NODE&&e.setAttribute("data-wcs-completed","");So(t,s),$o(t,r);const a=[];for(const e of s)e.statePathName in h&&a.push(e);if(ro(t,a),"for"===o.type&&null!==o.index){const r=Xs(e,"for",o.uuid);if(r){const e=uo(null,o.index);Go(r,e,t),Jo(r,o.nodes[o.nodes.length-1]),Oo(r,t),To(t,ut(k(o.path+"."+d),e)),i.initialize(s,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});let a=n.get(o.uuid);a||(a=[],n.set(o.uuid,a)),a.push(e)}}else{const n=Xs(e,o.type,o.uuid);n&&(Oo(n,t),i.initialize(s,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}))}}for(const[t,o]of n){const n=Xs(e,"for",t);if(!n)continue;const s=n.getRootNode(),r=ye(t);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=nr(s,i);l&&l.createState("readonly",e=>{const t=e[a];Array.isArray(t)&&ho(t,o)})}}(document.body,o),Gs.removeBlockBoundaryComments(document.body);const s=[];for(const e of t)e.parentNode&&(s.push({el:e,parent:e.parentNode,next:e.nextSibling}),e.remove());Gs.restoreTextBindings(document.body);const[r,i]=Se(document.body);for(const e of r)if(e.nodeType===Node.ELEMENT_NODE){const t=e;t.hasAttribute("data-wcs-completed")||(_e(e,null),t.setAttribute("data-wcs-completed",""))}else _e(e,null);const a=[],l=[],c=Xn(document.body).initialize(i);for(const e of c)if("event"!==e.bindingType)if(Js.has(e.bindingType))l.push(e);else{if(e.statePathName.includes(d))continue;a.push(e)}for(const e of l)if("for"===e.bindingType){const t=et(e),n=nr(e.replaceNode.getRootNode(),e.stateName);n&&n.createState("readonly",n=>{const o=n[e.statePathName];Array.isArray(o)&&ke(t,o)})}gs(a);for(const{el:e,parent:t,next:n}of s)t.insertBefore(e,n);const u=e.querySelectorAll(n.tagNames.ssr);for(const t of u){const n=t.hydrateProps;for(const[t,o]of Object.entries(n)){const n=e.querySelector(`[data-wcs-ssr-id="${t}"]`);if(n)for(const[e,t]of Object.entries(o))n[e]=t}}const f=e.querySelectorAll("[data-wcs-completed]");for(const e of f)e.removeAttribute("data-wcs-completed");return!0}const Zs=new WeakMap,er=new WeakMap,tr=new Set;function nr(e,t){let n=Zs.get(e);return n&&n.get(t)||null}function or(e){return er.get(e)??Promise.resolve()}function sr(t,o,s){let r=Zs.get(t);if(null===s){if(!r)return;const e=r.get(o);r.delete(o),0===r.size&&Zs.delete(t),void 0!==e&&(tr.delete(e),null!==nt&&nt({type:"state:element-unregistered",name:o,rootNode:t,element:e})),n.debug&&console.debug(`State element unregistered: name="${o}"`)}else{if(!r){r=new Map,Zs.set(t,r);const n=!e()&&s.hasAttribute?.("enable-ssr");if("HTMLDocument"===t.constructor.name||"Document"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{if(n){await Qs(t)||await Bs(t)}else await Bs(t);e()})});er.set(t,e)}else if("ShadowRoot"===t.constructor.name){const e=new Promise(e=>{queueMicrotask(async()=>{await Bs(t),e()})});er.set(t,e)}}r.has(o)&&F(`State element with name "${o}" is already registered.`),r.set(o,s),tr.add(s),null!==nt&&nt({type:"state:element-registered",name:o,rootNode:t,element:s}),n.debug&&console.debug(`State element registered: name="${o}"`,s)}}const rr=new Set;function ir(e){rr.add(e)}const ar=new class{_queueUpdateRecords=[];constructor(){}enqueueAbsoluteAddress(e,t=null){const n=0===this._queueUpdateRecords.length;this._queueUpdateRecords.push({absoluteAddress:e,context:t}),n&&queueMicrotask(()=>{const e=this._queueUpdateRecords;this._queueUpdateRecords=[],this._applyChange(e)})}testApplyChange(e,t){this._applyChange(e.map((e,n)=>({absoluteAddress:e,context:t?.[n]??null})))}_applyChange(e){const t=new Map;for(const n of e){const e=t.get(n.absoluteAddress);null!==nt&&null!=e&&null!==n.context&&e.transactionId!==n.context.transactionId&&nt({type:"propagation:coalesced",absoluteAddress:n.absoluteAddress,droppedTransactionId:e.transactionId,winnerTransactionId:n.context.transactionId}),t.set(n.absoluteAddress,n.context)}const n=[],o=new Map;for(const[e,s]of t){if(null!==s&&s.hop>=32){console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:e.absolutePathInfo.pathInfo.path,stateName:e.absolutePathInfo.stateName,transactionId:s.transactionId,hop:s.hop,maxHops:32}),null!==nt&&nt({type:"propagation:hop-limit",absoluteAddress:e,transactionId:s.transactionId,hop:s.hop});continue}const t=at(e);if(void 0!==t)if(t instanceof Set)for(const e of t)!1!==e.replaceNode.isConnected&&(n.push(e),null!==s&&o.set(e,s));else!1!==t.replaceNode.isConnected&&(n.push(t),null!==s&&o.set(t,s))}o.size>0?gs(n,o):gs(n),function(e){for(const t of rr)t(e)}(new Set(t.keys()))}};function lr(){return ar}const cr="__WCSTACK_DEVTOOLS_HOOK__";function dr(){const e=globalThis,t=e[cr];if(void 0!==t)return 1!==t.version&&console.warn(`[wcstack/state] devtools hook registry version mismatch: found ${t.version}, expected 1. Keeping the existing registry (first-wins).`),t;const n=function(){const e=new Map,t=new Set,n=e=>{if(0===t.size)return void e._setSink(null);const n=e.id;e._setSink(e=>{for(const o of t)o.onEvent?.(n,e)})};return{version:1,sources:e,register(o){if(!e.has(o.id)){e.set(o.id,o),n(o);for(const e of t)e.onSourceRegistered?.(o)}},unregister(n){const o=e.get(n);if(void 0!==o){o._setSink(null),e.delete(n);for(const e of t)e.onSourceUnregistered?.(n)}},addListener(o){t.add(o);for(const t of e.values())n(t),o.onSourceRegistered?.(t);return()=>{if(t.delete(o))for(const t of e.values())n(t)}}}}();return e[cr]=n,n}const ur=e=>{null!==nt&&nt({type:"state:update-batch",addresses:e})};function fr(e){const t=null!==nt;!function(e){nt=e}(e);const n=null!==e;var o;n&&!t?ir(ur):!n&&t&&(o=ur,rr.delete(o))}function pr(e){return{name:e.name,rootNode:e.rootNode,element:e,paths:{list:e.listPaths,element:e.elementPaths,getter:e.getterPaths,setter:e.setterPaths},commandTokenNames:e.commandTokenNames,eventTokenNames:e.eventTokenNames,staticDependency:e.staticDependency,dynamicDependency:e.dynamicDependency}}function hr(e,t){return nr(t,e)??F(`devtools: state element not found: name="${e}"`)}let mr=null;function gr(){if(e())return;if(null!==mr)return;const t={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:js,getStateElements(){const e=[];for(const t of tr)e.push(pr(t));return e},keys(e,t){const n=hr(e,t),o=[];return n.createState("readonly",e=>{for(const t of Object.keys(e))if(!t.includes("*")&&!t.startsWith("$")){try{if("function"==typeof e[t])continue}catch{}o.push(t)}}),o},read(e,t,n,o){let s;return hr(e,t).createState("readonly",e=>{s=e.$resolve(n,o??[])}),s},write(e,t,n,o,s){hr(e,t).createState("writable",e=>{void 0!==s&&s.length>0?e.$resolve(n,s,o):e[n]=o})},_setSink:fr};mr=t,dr().register(t)}async function yr(e,t){let n=null;const o=`\n//# sourceURL=${t}\n`;if("function"==typeof URL.createObjectURL){const t=new Blob([e.text+o],{type:"application/javascript"}),s=URL.createObjectURL(t);try{n=await import(s)}finally{URL.revokeObjectURL(s)}}else{const t=btoa(String.fromCodePoint(...(new TextEncoder).encode(e.text+o)));n=await import(`data:application/javascript;base64,${t}`)}return n&&"object"==typeof n.default?n.default:{}}async function br(e){try{return(await import(e)).default||{}}catch(e){F(`Failed to load script file: ${e}`)}}class wr{_loopContextStack=Array(u).fill(void 0);_length=0;createLoopContext(e,t){null===e.listIndex&&F("Cannot create loop context for a state address that does not have a list index.");const n=e;this._length>=u&&F("Exceeded maximum loop context stack depth of 128. Possible infinite loop.");const o=this._loopContextStack[this._length-1];if(void 0!==o){o.pathInfo.wildcardCount+1!==n.pathInfo.wildcardCount&&F("Cannot push loop context for a list whose wildcard count is not exactly one more than the current active loop context.");const e=n.pathInfo.wildcardPathInfos[n.pathInfo.wildcardPathInfos.length-2];o.pathInfo!==e&&F("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else n.listIndex.length!==n.pathInfo.wildcardCount&&F(`Cannot push loop context when there is no active loop context: the list index chain (length ${n.listIndex.length}) does not cover the wildcard path (wildcard count ${n.pathInfo.wildcardCount}).`);let s;this._loopContextStack[this._length]=n,this._length++;try{s=t(n)}finally{s instanceof Promise?s.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return s}}const vr=new WeakMap;function Nr(e,t){let n=vr.get(e);void 0===n&&(n=new Map,vr.set(e,n));let o=n.get(t);return void 0===o&&(o=new kt(t,e.name),n.set(t,o)),o}const Sr=new WeakMap;function xr(e){const t=Sr.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 Nr(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:Nr(e,n)}},set(){F("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){F("$command namespace is read-only; deleting from it is not allowed.")}});return Sr.set(e,n),n}const Ir=Symbol("wcs-stream-last-notified-uncertain"),Ar=new WeakMap;function Pr(e,t){const n=Ar.get(e);if(void 0!==n)for(const e of n.keys())t.has(e)||n.delete(e)}function _r(e,t){const n=Ar.get(e);if(void 0===n)return;const o=n.get(t);void 0!==o&&n.set(t,{status:"idle"===o.status?o.status:Ir,error:Object.is(o.error,null)?null:Ir})}const $r=new Set;function Tr(e){$r.delete(e)}function kr(){return $r}const Cr=new WeakMap;function Er(e){return Cr.get(e)??new Map}function Mr(e){Tr(e);const t=Cr.get(e);if(void 0!==t)for(const n of t.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,_r(e,n.name)}const Or=(e,t)=>t,Dr=new Set;function Rr(e,t){const n=t[I];if(void 0===n)return void Pr(e,Dr);"object"==typeof n&&null!==n||F(`${I} must be an object mapping stream names to stream definitions.`);const o=new Map;for(const[s,r]of Object.entries(n)){0===s.length&&F(`${I} entry name must be a non-empty string.`),s.includes(c)&&F(`${I} entry "${s}" must be a flat property name ("${c}" is not allowed).`),s.includes(d)&&F(`${I} entry "${s}" must be a flat property name ("${d}" is not allowed).`),s.startsWith("$")&&F(`${I} entry "${s}" must not start with "$" (reserved namespace).`),s in Object.prototype&&F(`${I} entry "${s}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),e.getterPaths.has(s)&&F(`${I} entry "${s}" conflicts with a getter declared on the state.`),e.setterPaths.has(s)&&F(`${I} entry "${s}" conflicts with a setter declared on the state.`),"object"==typeof r&&null!==r||F(`${I} entry "${s}" must be an object ({ args?, source, fold?, initial? }).`);const n=r;"function"!=typeof n.source&&F(`${I} entry "${s}" source must be a function.`);const i=void 0!==n.fold;i&&"function"!=typeof n.fold&&F(`${I} entry "${s}" fold must be a function.`),i&&!("initial"in n)&&F(`${I} entry "${s}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==n.args&&"function"!=typeof n.args&&F(`${I} entry "${s}" args must be a function.`);const a={name:s,definition:{args:n.args??null,source:n.source,fold:n.fold??Or,initial:n.initial},status:"idle",error:null,controller:null,depAddresses:new Set};s in t||(t[s]=a.definition.initial),o.set(s,a)}!function(e,t){Cr.set(e,t)}(e,o),Pr(e,new Set(o.keys()))}const Lr=new WeakMap,Wr=new WeakMap;function Br(e,t,n){return new Proxy(Object.create(null),{get(t,o){if("string"!=typeof o)return;const s=Er(e).get(o);return void 0!==s?n(s):void 0},has:(t,n)=>"string"==typeof n&&Er(e).has(n),ownKeys:()=>Array.from(Er(e).keys()),getOwnPropertyDescriptor(t,o){if("string"!=typeof o)return;const s=Er(e).get(o);return void 0!==s?{configurable:!0,enumerable:!0,value:n(s)}:void 0},set(){F(`${t} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){F(`${t} namespace is read-only; deleting from it is not allowed.`)}})}function jr(e){const t=Lr.get(e);if(void 0!==t)return t;const n=Br(e,A,e=>e.status);return Lr.set(e,n),n}function Fr(e){const t=Wr.get(e);if(void 0!==t)return t;const n=Br(e,P,e=>e.error);return Wr.set(e,n),n}function zr(e){Lr.delete(e),Wr.delete(e)}let qr=null;async function Ur(e,t,n,o){let s=null,r=null;const i=()=>{if(s&&s!==r){r=s;try{s.return?.()?.then?.(void 0,()=>{})}catch{}}};n.addEventListener("abort",i,{once:!0});try{const r=await e(t,n);if(s=function(e,t){if("function"==typeof e?.getReader)return async function*(e,t){const n=e.getReader(),o=()=>{n.cancel().catch(()=>{})};t.addEventListener("abort",o,{once:!0});try{for(;;){const{done:e,value:t}=await n.read();if(e)return;yield t}}finally{t.removeEventListener("abort",o),n.releaseLock()}}(e,t);if("function"==typeof e?.[Symbol.asyncIterator])return e;throw new TypeError("[@wcstack/state] $streams: source must return an AsyncIterable or a ReadableStream (got neither).")}(r,n)[Symbol.asyncIterator](),n.aborted)return void i();for(;;){const e=await s.next();if(e.done)break;if(n.aborted)return;o.fold(e.value)}if(n.aborted)return;o.done()}catch(e){if(n.aborted)return;o.fail(e)}finally{n.removeEventListener("abort",i)}}function Vr(e){const t=Er(e);if(0!==t.size){!function(e){$r.add(e)}(e);for(const n of t.values())Hr(e,n)}}function Hr(e,t){t.controller?.abort();const n=new AbortController;t.controller=n;const o=function(e,t){const n=t.definition.args;if(null===n)return void t.depAddresses.clear();const o=qr,s=new Set;let r;qr=s;try{e.createState("readonly",e=>{r=n(e)})}finally{qr=o}r instanceof Promise&&F(`${I} entry "${t.name}" args must be synchronous (it returned a Promise).`);const i=`${A}${c}${t.name}`,a=`${P}${c}${t.name}`;for(const n of s){const o=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==e||o.path!==t.name&&o.path!==i&&o.path!==a||F(`${I} entry "${t.name}" args must not read the stream itself ("${o.path}"): a self-dependency would restart the stream on its own writes (infinite loop).`),o.wildcardCount>0&&F(`${I} entry "${t.name}" args must not read wildcard paths ("${o.path}"): wildcard dependencies are out of scope.`)}return t.depAddresses=s,r}(e,t);e.createState("writable",e=>{e[t.name]=t.definition.initial}),Gr(e,t,"active",null);const s=t.definition,r={fold(n){e.createState("writable",e=>{e[t.name]=s.fold(e[t.name],n)})},done(){Gr(e,t,"done",null)},fail(o){Gr(e,t,"error",o),n.abort()}};Ur(s.source,o,n.signal,r)}function Gr(e,t,n,o){t.status=n,t.error=o;const s=function(e,t){return Ar.get(e)?.get(t)??{status:"idle",error:null}}(e,t.name),r=s.status!==n,i=!Object.is(s.error,o);(r||i)&&(!function(e,t,n,o){let s=Ar.get(e);void 0===s&&(s=new Map,Ar.set(e,s)),s.set(t,{status:n,error:o})}(e,t.name,n,o),e.createState("writable",e=>{r&&e.$postUpdate(`${A}${c}${t.name}`),i&&e.$postUpdate(`${P}${c}${t.name}`)}))}function Jr(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 Kr(e){return function(t){const n=this.stateElement;n&&n.initializePromise.then(()=>{n.createState("writable",n=>{n[e]=t})})}}function Xr(e,t){return t?function(...t){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[e](...t)}).then(()=>o)})}:function(...t){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[e](...t)}),o})}}function Yr(e){return e.startsWith("$")}ir(function(e){const t=kr();if(0===t.size)return;const n=[];for(const o of t)for(const t of Er(o).values())for(const s of t.depAddresses)if(e.has(s)){n.push({stateElement:o,entry:t});break}for(const{stateElement:e,entry:o}of n)if(t.has(e)&&Er(e).get(o.name)===o)try{Hr(e,o)}catch(n){o.controller?.abort(),t.has(e)&&Er(e).get(o.name)===o&&Gr(e,o,"error",n)}});const Qr=new Map;class Zr{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const t=e.split("."),n=t.slice();let o=0,s=0,r=0,i="none";const a=[];for(let e=0;e<t.length;e++){const i=t[e];if("*"===i)n[e]="*",a.push(null),o++,r++;else{const t=Number(i);Number.isNaN(t)||(n[e]="*",a.push(t),s++,r++)}}const l=k(n.join("."));(o>0||s>0)&&(i=o===r?"context":s===r?"all":"partial"),this.path=e,this.segments=t,this.wildcardCount=r,this.wildcardType=i,this.wildcardIndexes=a,this.pathInfo=l}}function ei(e){let t;return Qr.get(e)??(Qr.set(e,t=new Zr(e)),t)}const ti=new WeakMap;function ni(e,t){null===t?ti.delete(e):ti.set(e,t)}function oi(e){const t=ti.get(e);t&&(t.dirty=!0)}function si(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 ri(e,t,n,o,s){const r=t.pathInfo.segments[0];if(r===N)return si(xr(s),t.pathInfo.segments);if(r===A)return si(jr(s),t.pathInfo.segments);if(r===P)return si(Fr(s),t.pathInfo.segments);if(!(t.pathInfo.path in e)){const s=ai(e,t.parentAddress??F(`address.parentAddress is undefined path: ${t.pathInfo.path}`),n,o),r=t.pathInfo.segments[t.pathInfo.segments.length-1];if(r===d){const e=t.listIndex?.index??F(`address.listIndex?.index is undefined path: ${t.pathInfo.path}`);return Reflect.get(s,e)}return Reflect.get(s,r)}if(!s.getterPaths.has(t.pathInfo.path))return Reflect.get(e,t.pathInfo.path);o.pushAddress(t);try{return Reflect.get(e,t.pathInfo.path,n)}finally{o.popAddress()}}function ii(e,t,n,o,s){const r=Ue(Be(s,t.pathInfo),t.listIndex),i=function(e){return ti.get(e)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=ri(e,t,n,o,s);return ni(r,{value:a,dirty:!1}),a}function ai(e,t,n,o){!function(e,t){if(!e.untracking&&e.addressStackLength>0){const n=e.lastAddressStack,o=n?.pathInfo??null,s=e.stateElement;if(null!==o&&s.getterPaths.has(o.path)&&o.path!==t.pathInfo.path&&(s.addDynamicDependency(t.pathInfo.path,o.path),t.pathInfo.wildcardCount>0&&o.wildcardCount>0)){const e=Ke(t.pathInfo,o);if(e>0){let o=!1;for(let s=0;s<e;s++)if(t.listIndex?.at(s)!==n.listIndex?.at(s)){o=!0;break}if(o)for(let n=0;n<e;n++)s.addCrossRowListPath?.(t.pathInfo.wildcardParentPaths[n])}}}}(o,t),function(e,t){if(null===qr)return;const n=Be(e,t.pathInfo);qr.add(Ue(n,t.listIndex))}(o.stateElement,t);const s=o.stateElement;return t.pathInfo.wildcardCount>0||s.getterPaths.has(t.pathInfo.path)?ii(e,t,n,o,s):ri(e,t,n,o,s)}function li(e,t){if(0===e.addressStackLength)return null;const n=e.lastAddressStack;if(null===n)return null;const o=n.pathInfo.indexByWildcardPath[t];return void 0===o?null:n.listIndex?.at(o)??null}function ci(e,t,n,o){if(t.pathInfo.path in e)return!0;const s=t.parentAddress;if(null===s)return!1;const r=ai(e,s,n,o);if(null===r||"object"!=typeof r&&"function"!=typeof r)return!1;const i=t.pathInfo.lastSegment;if(i===d){const e=t.listIndex?.index;return"number"==typeof e&&e in r}return i in r}const di=new WeakMap;function ui(e,t){null===t?di.delete(e):di.set(e,t)}function fi(e,t,o){const s=k(e.wildcardParentPaths[t]),r=Be(e.stateElement,s),i=ut(s,o),a=Te(Ue(r,o)),l=e.stateProxy[Ee](i),c=function(e,t){switch(t){case"old":return e.oldIndexes;case"new":return e.newIndexes;case"add":return e.addIndexSet;case"change":return e.changeIndexSet;case"delete":return e.deleteIndexSet;default:return n.debug&&console.log(`Invalid search type: ${t}`),[]}}(bo(i.listIndex,a,l),e.searchType);if(t===e.wildcardPaths.length-1)e.targetListIndexes.push(...c);else for(const n of c)fi(e,t+1,n)}const pi=[];function hi(e,t,n,o,s){return"full"===e.listExpansion||e.stateElement.crossRowListPaths?.has(t)?{fullRows:s.newIndexes,movedRows:null}:0===s.addIndexSet.size&&0===s.changeIndexSet.size?0===s.deleteIndexSet.size?{fullRows:s.newIndexes,movedRows:null}:{fullRows:pi,movedRows:null}:{fullRows:s.addIndexSet,movedRows:s.changeIndexSet}}const mi=[];function gi(e,t,n){const o=e.stateElement.indexDependentGetterPaths;if(!o||0===o.size)return mi;let s=null;const r=[t],i=new Set(r);for(let t=0;t<r.length;t++){const a=r[t];if(o.has(a)){const e=k(a);if(e.wildcardCount!==n.wildcardCount)return null;(s??=[]).push(e)}const l=e.staticMap.get(a);if(l)for(const e of l)i.has(e)||(i.add(e),r.push(e))}return s??mi}function yi(e,t,n){const o=t.pathInfo.path,s=e.staticMap.get(o);if(s)for(const r of s){const s=k(r);if(e.listPathSet.has(o)&&s.lastSegment===d){const i=e.stateProxy[Ee](t),a=Te(Ue(Be(e.stateElement,t.pathInfo),t.listIndex)),l=hi(e,o,0,0,bo(t.listIndex,a,i));for(const t of l.fullRows){const o=ut(s,t);e.result.add(o),n.push(o)}if(null!==l.movedRows){const t=gi(e,r,s);if(null===t)for(const t of l.movedRows){const o=ut(s,t);e.result.add(o),n.push(o)}else if(t.length>0)for(const o of l.movedRows)for(const s of t){const t=ut(s,o);e.result.add(t),n.push(t)}}}else{const o=ut(s,t.listIndex);e.result.add(o),n.push(o)}}const r=e.dynamicMap.get(o);if(r)for(const o of r){const s=k(o),r=[];if(s.wildcardCount>0){const n=Ke(t.pathInfo,s);if(s.wildcardCount-n>=1){let o;n>0?(null===t.listIndex&&F(`Cannot expand dynamic dependency with wildcard for non-list address: ${t.pathInfo.path}`),o=t.listIndex.at(n-1)):o=null;const i={stateName:e.stateName,stateElement:e.stateElement,targetListIndexes:[],wildcardPaths:s.wildcardPaths,wildcardParentPaths:s.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};fi(i,n,o),r.push(...i.targetListIndexes)}else{null===t.listIndex&&F(`Cannot expand dynamic dependency with wildcard for non-list address: ${t.pathInfo.path}`);const e=t.listIndex.at(n-1);r.push(e)}}else r.push(null);for(const t of r){const o=ut(s,t);e.result.add(o),n.push(o)}}}function bi(e,t,n,o,s,r,i,a,l,c){const d=n.pathInfo.path;if(!o.has(d)&&!s.has(d))return l(n),[];const u=function(e,t,n,o){const s=new Map,r=new Map,i=[e];for(r.set(e,0);i.length>0;){const e=i.pop();if(s.has(e))continue;const o=t.get(e),a=n.get(e);let l;l=void 0===o?a??[]:void 0===a?o:o.concat(a),s.set(e,l);for(let e=0;e<l.length;e++){const t=l[e];r.set(t,(r.get(t)??0)+1),s.has(t)||i.push(t)}}const a=new Map,l=new Set,c=[];for(const[e,t]of r)0===t&&(a.set(e,0),l.add(e),c.push(e));for(let e=0;e<c.length;e++){const t=c[e],n=a.get(t)+1;n>o&&F(`Maximum dependency depth of ${o} exceeded. Possible circular dependency detected at path: ${t}`);const i=s.get(t);for(let e=0;e<i.length;e++){const t=i[e];n>(a.get(t)??-1)&&a.set(t,n);const o=r.get(t)-1;r.set(t,o),0===o&&(l.add(t),c.push(t))}}if(l.size!==s.size){let e=-1;for(const t of l){const n=a.get(t);n>e&&(e=n)}const t=e+1;for(const e of s.keys())l.has(e)||a.set(e,t)}return a}(d,o,s,1e3),f={ranks:u,stateName:e,stateElement:t,staticMap:o,dynamicMap:s,result:new Set,listPathSet:r,visited:new Set,stateProxy:i,searchType:a,listExpansion:c?.listExpansion??"full"};return function(e,t,n){const o=[],s=e.ranks,r=(e,t)=>{let n=s.get(e.pathInfo.path)??t;n<t&&(n=t),(o[n]??=[]).push(e)};r(t,0);const i=[];for(let t=0;t<o.length;t++){const s=o[t];if(void 0!==s)for(let o=0;o<s.length;o++){const a=s[o];if(!e.visited.has(a)){e.visited.add(a),n(a),i.length=0,yi(e,a,i);for(let e=0;e<i.length;e++)r(i[e],t+1)}}}}(f,n,l),Array.from(f.result)}function wi(e,t,o,s){const r=n.enablePropagationContext?tn()??Qt(-1):null,i=lr();i.enqueueAbsoluteAddress(t,r),bi(s.stateName,s.stateElement,e,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,o,"new",t=>{if(t===e)return;const n=Ue(Be(s.stateElement,t.pathInfo),t.listIndex);oi(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:"diff"})}function vi(e,t,n,o,s,r){try{if(!(t.pathInfo.path in e)){const n=t.parentAddress;if(null===n)return Reflect.set(e,t.pathInfo.path,o);const i=ai(e,n,s,r),a=t.pathInfo.segments[t.pathInfo.segments.length-1];if(a===d){const e=t.listIndex?.index??F(`address.listIndex?.index is undefined path: ${t.pathInfo.path}`);return Reflect.set(i,e,o)}return Reflect.set(i,a,o)}if(!r.stateElement.setterPaths.has(t.pathInfo.path))return Reflect.set(e,t.pathInfo.path,o);r.pushAddress(t),r.beginUntrack();try{return Reflect.set(e,t.pathInfo.path,o,s)}finally{r.endUntrack(),r.popAddress()}}finally{wi(t,n,s,r)}}function Ni(e,t,n,o,s,r){let i=t.parentAddress??F(`address.parentAddress is undefined path: ${t.pathInfo.path}`),a=function(e){return di.get(e)??null}(i);if(null===a){const t=ai(e,i,s,r)??[],n=po(t)??[];a={value:[...t],listIndexes:[...n]},ui(i,a)}try{return vi(e,t,n,o,s,r)}finally{const n=a.value.indexOf(o),l=ai(e,i,s,r)??[],c=Array.isArray(l)?po(l)??[]:[],d=t.listIndex.index,u=-1!==n?a.listIndexes[n]:uo(i.listIndex,-1);c[d]=u;if(new Set(l).size===a.value.length){for(let e=0;e<c.length;e++)c[e].index=e;ui(i,null)}}}function Si(e,t,o,s,r){const i=r.stateElement,a=t.pathInfo.path,l=!!sn&&(sn=!1,!0);if(!(a in e)&&null!==t.parentAddress&&!i.elementPaths.has(a)){const c=ai(e,t.parentAddress,s,r);if("object"==typeof c&&null!==c){const e=t.pathInfo.lastSegment,u=e===d?t.listIndex?.index:e;let f,p=!1;if(!l&&n.sameValueGuard&&(null===o||"object"!=typeof o)){const e=void 0!==u&&u in c,t=void 0!==u?c[u]:void 0;if(e&&Object.is(t,o))return!0;f=t,p=!0}const h=t.pathInfo.wildcardCount>0||i.getterPaths.has(a),m=Ue(Be(i,t.pathInfo),t.listIndex);null!==nt&&nt({type:"state:write",absoluteAddress:m,value:o,oldValue:f,hasOldValue:p});try{return void 0===u&&F(`address.listIndex?.index is undefined path: ${a}`),Reflect.set(c,u,o)}finally{wi(t,m,s,r),h&&ni(m,{value:o,dirty:!1});const e=i.bindableEventMap[a];if(e){const t=i.rootNode;t instanceof ShadowRoot&&t.host.dispatchEvent(new CustomEvent(e,{detail:o,bubbles:!0}))}}}}let c,u=!1;if(!l&&n.sameValueGuard&&(null===o||"object"!=typeof o)){const n=ai(e,t,s,r);if(ci(e,t,s,r)&&Object.is(n,o))return!0;c=n,u=!0}const f=i.elementPaths.has(t.pathInfo.path),p=t.pathInfo.wildcardCount>0||i.getterPaths.has(t.pathInfo.path),h=Ue(Be(i,t.pathInfo),t.listIndex);null!==nt&&nt({type:"state:write",absoluteAddress:h,value:o,oldValue:c,hasOldValue:u});try{return f?Ni(e,t,h,o,s,r):vi(e,t,h,o,s,r)}finally{p&&ni(h,{value:o,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:o,bubbles:!0}))}}}function xi(e,t,n,o){return(t,s,r)=>{const i=k(t);if(o.addressStackLength>0){const e=o.lastAddressStack?.pathInfo??null,t=o.stateElement;null!==e&&e.path!==i.path&&t.getterPaths.has(e.path)&&t.addDynamicDependency(i.path,e.path)}i.wildcardParentPathInfos.length>s.length&&F(`indexes length is insufficient: ${t}`);let a=null;for(let t=0;t<i.wildcardParentPathInfos.length;t++){const r=i.wildcardParentPathInfos[t],l=ut(r,a),c=po(ai(e,l,n,o));null==c&&F(`ListIndexes not found: ${r.path}`);a=c[s[t]]??F(`ListIndex not found: ${r.path}`)}const l=ut(i,a);if(!(void 0!==r))return ai(e,l,n,o);Si(e,l,r,n,o)}}const Ii=new WeakMap;function Ai(e,t,n,o){const s=t.pathInfo;switch(t.wildcardType){case"none":return null;case"context":return li(o,s.wildcardPaths.at(-1)??F(`lastWildcardPath is null: ${t.pathInfo.path}`))??F(`ListIndex not found: ${t.pathInfo.path}`);case"all":{let s=null;for(let r=0;r<t.pathInfo.wildcardCount;r++){const i=t.pathInfo.wildcardParentPathInfos[r]??F(`wildcardParentPathInfo is null: ${t.pathInfo.path}`);s=(po(ai(e,ut(i,s),n,o))??F(`ListIndex not found: ${i.path}`))[t.wildcardIndexes[r]??F(`wildcardIndex is null: ${t.pathInfo.path}`)]??F(`ListIndex not found: ${i.path}`)}return s}case"partial":F(`Partial wildcard type is not supported yet: ${t.pathInfo.path}`)}}const Pi=`${A}${c}`,_i=`${P}${c}`,$i=new WeakMap;function Ti(e,t,n,o){const s=h[t];if(void 0!==s){0===o.addressStackLength&&F(`No active state reference to get list index for "${t.toString()}".`);const e=o.lastAddressStack,n=e?.pathInfo;n&&!o.untracking&&o.stateElement?.getterPaths.has(n.path)&&o.stateElement.addIndexDependentGetterPath?.(n.path);const r=e?.listIndex;return r?.indexes[s]??F(`ListIndex not found: ${t.toString()}`)}if("string"==typeof t){if("$"===t[0]){switch(t){case"$stateElement":return o.stateElement;case"$getAll":return(t,s)=>function(e,t,n,o){const s=xi(e,0,n,o);return(t,r)=>{const i=new Map,a=k(t);if(o.addressStackLength>0){const e=o.lastAddressStack?.pathInfo??null,t=o.stateElement;null!==e&&e.path!==a.path&&t.getterPaths.has(e.path)&&t.addDynamicDependency(a.path,e.path)}if(void 0===r){for(let e=0;e<a.wildcardParentPathInfos.length;e++){const t=a.wildcardParentPathInfos[e],n=li(o,t.path);if(n){r=n.indexes;break}}void 0===r&&(r=[])}const l=(t,s,r,a,c,d,u)=>{const f=t[s]??null;if(null===f)return void u.push(d);const p=ut(f,r),h=Ii.get(p),m=ai(e,p,n,o),g=bo(r,h,m).newIndexes,y=a[c]??null;if(i.set(p,m),null===y)for(let e=0;e<g.length;e++){const n=g[e];l(t,s+1,n,a,c+1,d.concat(n.index),u)}else{const e=g[y]??F(`ListIndex not found: ${f.path}`);s+1<t.length?l(t,s+1,e,a,c+1,d.concat(e.index),u):u.push(d.concat(e.index))}},c=[];l(a.wildcardParentPathInfos,0,null,r,0,[],c);const d=[];for(let e=0;e<c.length;e++)d.push(s(a.path,c[e]));for(const[e,t]of i.entries())Ii.set(e,t);return d}}(e,0,n,o)(t,s);case"$postUpdate":return t=>function(e,t,n,o){const s=o.stateElement;return t=>{const r=ei(t),i=Ai(e,r,n,o),a=ut(r.pathInfo,i),l=Ue(Be(s,a.pathInfo),a.listIndex),c=lr();c.enqueueAbsoluteAddress(l),bi(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",e=>{const t=Ue(Be(s,e.pathInfo),e.listIndex);oi(t),c.enqueueAbsoluteAddress(t)})}}(e,0,n,o)(t);case"$resolve":return(t,s,r)=>xi(e,0,n,o)(t,s,r);case"$trackDependency":return e=>function(e,t,n,o){return e=>{0===o.addressStackLength&&F(`No active state reference to track dependency for path "${e}".`);const t=o.lastAddressStack?.pathInfo??F("Internal error: lastAddressStack is null"),n=o.stateElement;o.stateElement.getterPaths.has(t.path)&&t.path!==e&&n.addDynamicDependency(e,t.path)}}(0,0,0,o)(e);case"$untrackDependency":return e=>function(e,t,n,o){return e=>{o.beginUntrack();try{return e()}finally{o.endUntrack()}}}(0,0,0,o)(e);case N:return xr(o.stateElement);case A:return jr(o.stateElement);case P:return Fr(o.stateElement)}if(!t.startsWith(Pi)&&!t.startsWith(_i))return}const s=ei(t),r=Ai(e,s,n,o),i=ut(s.pathInfo,r);return ai(e,i,n,o)}if("symbol"==typeof t){const s=function(e){let t=$i.get(e);return void 0===t&&(t=new Map,$i.set(e,t)),t}(o),r=s.get(t);if(void 0!==r)return r;let i;switch(t){case Ce:i=(e,t=()=>{})=>function(e,t,n){void 0!==e.loopContext&&F("already in loop context"),e.setLoopContext(t);try{e.pushAddress(t);try{return n()}finally{e.popAddress()}}finally{e.clearLoopContext()}}(o,e,t);break;case Ee:i=t=>ai(e,t,n,o);break;case Me:i=t=>ci(e,t,n,o);break;case Oe:i=(t,s)=>Si(e,t,s,n,o);break;case De:i=()=>async function(e,t,n){const o=Reflect.get(e,m);"function"==typeof o&&await o.call(n)}(e,0,n);break;case Re:i=()=>function(e,t,n){const o=Reflect.get(e,g);"function"==typeof o&&o.call(n)}(e,0,n);break;case Le:i=t=>function(e,t,n,o){const s=Reflect.get(e,y);if("function"==typeof s){const e=new Set,r={};for(const n of t){const t=n.absolutePathInfo.pathInfo;let s;if(s=n.absolutePathInfo.stateName===o.stateName?t.path:t.path+"@"+n.absolutePathInfo.stateName,e.add(s),t.wildcardCount>0){const e=n.listIndex.indexes??[],t=r[s];void 0===t?r[s]=[e]:t.push(e)}}return s.call(n,Array.from(e),r)}}(e,t,n,o);break;default:return Reflect.get(e,t,n)}return s.set(t,i),i}}class ki{_stateElement;_stateName;_addressStack=Array(u).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;_untrackDepth=0;constructor(e,t,n){this._stateName=t;const o=nr(e,this._stateName);null===o&&F(`StateHandler: State element with name "${this._stateName}" not found.`),this._stateElement=o,this._mutability=n}get stateName(){return this._stateName}get stateElement(){return this._stateElement}get lastAddressStack(){let e;return this._addressStackIndex>=0&&(e=this._addressStack[this._addressStackIndex]),void 0===e&&F("Last address stack is undefined."),e}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(e){this._addressStackIndex++,this._addressStackIndex>=u&&F("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&&F(`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 untracking(){return this._untrackDepth>0}beginUntrack(){this._untrackDepth++}endUntrack(){this._untrackDepth--}get(e,t,n){return Ti(e,t,n,this)}set(e,t,n,o){return"readonly"===this._mutability&&F(`State "${this._stateName}" is readonly.`),function(e,t,n,o,s){if("string"==typeof t){const r=ei(t),i=Ai(e,r,o,s);return Si(e,ut(r.pathInfo,i),n,o,s)}return Reflect.set(e,t,n,o)}(e,t,n,o,this)}has(e,t){return Reflect.has(e,t)}}const Ci=new WeakMap;const Ei=new WeakMap;function Mi(e,t){const n=Ei.get(e);return n?n.get(t)??null:null}const Oi=new WeakMap,Di=new WeakMap,Ri=new WeakMap,Li=new WeakMap;function Wi(e,t){return{innerAbsPathInfo:Be(e,k(t.propSegments.slice(1).join(c))),outerAbsPathInfo:et(t).absolutePathInfo}}function Bi(e,t){let n=Oi.get(e);if(void 0===n&&(n=new Map,Oi.set(e,n)),n.has(t))return n.get(t);let o=Di.get(e);void 0===o&&(o=new Map,Di.set(e,o));const s=Ri.get(e);if(void 0===s)return null;let r=null;for(const e of s)if(t.pathInfo.cumulativePathInfoSet.has(e.innerAbsPathInfo.pathInfo)){e.innerAbsPathInfo.pathInfo.segments.length===t.pathInfo.segments.length&&F("Duplicate mapping rule for web component."),r=e;break}if(null===r)return null;const i=Li.get(r);void 0===i&&F("Binding not found for primary mapping rule on web component.");const a=t.pathInfo.segments.slice(r.innerAbsPathInfo.pathInfo.segments.length),l=k(r.outerAbsPathInfo.pathInfo.segments.concat(a).join(c)),d=nr(e.getRootNode(),i.stateName);null===d&&F(`State element with name "${i.stateName}" not found for web component.`);const u=Be(d,l);n.set(t,u),o.set(u,t);return function(e,t){const n=H(e);null===n?G(e,[t]):n.push(t)}(e,{...i,propName:t.pathInfo.path,propSegments:t.pathInfo.segments,statePathName:u.pathInfo.path,statePathInfo:u.pathInfo}),u}function ji(e){return function(e){const t=Object.getPrototypeOf(e),n=Object.create(t),o=Object.getOwnPropertyDescriptors(e);for(const e in o){const t=o[e];!1===t.writable&&(t.writable=!0)}return Object.defineProperties(n,o),n}(e)}class Fi{_webComponent;_innerStateElement;constructor(e,t){this._webComponent=e,this._innerStateElement=Mi(e,t)??F("State element not found for web component.")}get(e,t,n){if("string"!=typeof t)return Reflect.get(e,t,n);{if("then"===t)return;if("$"===t[0])return;if(this._innerStateElement.getterPaths.has(t)&&t in e)return Reflect.get(e,t,n);const o=k(t),s=Be(this._innerStateElement,o),r=Bi(this._webComponent,s);if(null!==r){const e=Pe(this._webComponent);let t;return r.stateElement.createState("readonly",n=>{n[Ce](e,()=>{t=n[r.pathInfo.path];let o=null;null!==e&&null!==e.listIndex&&r.pathInfo.wildcardCount>0&&(o=e.listIndex.at(r.pathInfo.wildcardCount-1));!function(e,t){Ci.set(e,t)}(Ue(r,o),t)})}),t}if(t in e)return Reflect.get(e,t,n);F(`Property "${t}" not found in inner state: no mapping rule and no local state property.`)}}set(e,t,n,o){if("string"!=typeof t)return Reflect.set(e,t,n,o);{if(this._innerStateElement.setterPaths.has(t)&&t in e)return Reflect.set(e,t,n,o);const s=k(t),r=Be(this._innerStateElement,s),i=Bi(this._webComponent,r);if(null!==i){const e=Pe(this._webComponent);return i.stateElement.createState("writable",t=>{t[Ce](e,()=>{t[i.pathInfo.path]=n})}),!0}if(t in e)return Reflect.set(e,t,n,o);F(`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=k(t),o=Be(this._innerStateElement,n);return null!==Bi(this._webComponent,o)||t in e}return Reflect.has(e,t)}}class zi{_innerStateElement;constructor(e,t){this._innerStateElement=Mi(e,t)??F("State element not found for web component.")}get(e,t,n){if("string"==typeof t){const e=k(t),n=Ue(Be(this._innerStateElement,e),null);return o=n,Ci.get(o)}return Reflect.get(e,t,n);var o}set(e,t,n,o){if("string"==typeof t){const e=k(t),n=Be(this._innerStateElement,e);return this._innerStateElement.createState("readonly",e=>{e.$postUpdate(n.pathInfo.path)}),!0}return Reflect.set(e,t,n,o)}}class qi{_innerStateElement;constructor(e,t){this._innerStateElement=Mi(e,t)??F("State element not found for web component.")}get(e,t,n){if("string"==typeof t){let e;return this._innerStateElement.createState("readonly",n=>{e=n[t]}),e}return Reflect.get(e,t,n)}set(e,t,n,o){return"string"==typeof t?(this._innerStateElement.createState("writable",e=>{e[t]=n}),!0):Reflect.set(e,t,n,o)}}const Ui=e=>()=>e;function Vi(e,t,o,s){if(function(e,t,n){let o=Ei.get(e);o||(o=new Map,Ei.set(e,o)),o.set(t,n)}(t,o,e),t.hasAttribute(n.bindAttributeName)){const n=(H(t)??[]).filter(e=>e.propSegments[0]===o);!function(e,t,n){if(0===n.length)return;const o=Mi(e,t);null===o&&F("State element not found for web component.");const s=new Map,r=new Map;for(const t of n){const n=Wi(o,t);let i=Ri.get(e);void 0===i?Ri.set(e,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;Li.set(n,t),s.set(a,l),r.set(l,a)}Oi.set(e,s),Di.set(e,r)}(t,o,n);const s=function(e,t){const n=new zi(e,t);return new Proxy({},n)}(t,o),r=function(e,t){const n=new Fi(e,t),o=Mi(e,t);null===o&&F("State element not found for web component."),null===o.boundComponentStateProp&&F("State element is not bound to any component state prop."),o.boundComponentStateProp in e||F(`State element is not bound to a valid component state prop: ${o.boundComponentStateProp}`);const s=e[o.boundComponentStateProp];return"object"==typeof s&&null!==s||F(`Invalid state object for component state prop: ${o.boundComponentStateProp}`),new Proxy(ji(s),n)}(t,o);e.setInitialState(r),Object.defineProperty(t,o,{get:Ui(s),enumerable:!0,configurable:!0})}else{e.setInitialState(ji(s));const n=function(e,t){const n=new qi(e,t);return new Proxy({},n)}(t,o);Object.defineProperty(t,o,{get:Ui(n),enumerable:!0,configurable:!0})}if(function(e,t){let n=Qn.get(e);n||(n=new WeakMap,Qn.set(e,n)),n.set(t,!0)}(t,e),b in t){const e=t[b];"function"==typeof e?e.call(t,o).catch(e=>{F(`Error in ${b}: ${e instanceof Error?e.message:String(e)}`)}):F(`${b} is not a function.`)}}function Hi(e){const t=new Set,n=new Set,o=function(e){let t={},n=e;for(;n&&n!==Object.prototype;)Object.assign(t,Object.getOwnPropertyDescriptors(n)),n=Object.getPrototypeOf(n);return t}(e);for(const[e,s]of Object.entries(o))"function"==typeof s.get&&t.add(e),"function"==typeof s.set&&n.add(e);return{getterPaths:t,setterPaths:n}}class Gi extends Fs{static hasConnectedCallbackPromise=!0;static getBindingsReady(e){return or(e)}__state;_hasUpdatedCallback=!1;_crossRowListPaths=new Set;_indexDependentGetterPaths=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 wr}();_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&&F(`${n.tagNames.state} _state is not initialized yet.`),this.__state}set _state(t){this._commandTokenNames=function(e){const t=new Set,n=e[v];if(void 0===n)return t;Array.isArray(n)||F(`${v} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||F(`${v} entries must be non-empty strings.`),e===N&&F(`${v} entry "${e}" conflicts with the reserved namespace name "${N}".`),t.has(e)&&F(`${v} entry "${e}" is duplicated.`),t.add(e);return t}(t),this._eventTokenNames=function(e){const t=new Set,n=e[S];if(void 0===n)return t;Array.isArray(n)||F(`${S} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||F(`${S} entries must be non-empty strings.`),t.has(e)&&F(`${S} entry "${e}" is duplicated.`),t.add(e);return t}(t),this.__state=t,this._hasUpdatedCallback=y in t,_t(this),function(e,t,n){const o=t[x];if(void 0!==o){"object"==typeof o&&null!==o||F(`${x} must be an object mapping event-token names to handler functions.`);for(const[t,s]of Object.entries(o))n.has(t)||F(`${x} entry "${t}" is not declared in $eventTokens.`),"function"!=typeof s&&F(`${x} entry "${t}" must be a function.`),Pt(e,t).subscribe(s)}}(this,t,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const n=Hi(t);for(const e of n.getterPaths)this._getterPaths.add(e);for(const e of n.setterPaths)this._setterPaths.add(e);var o;zr(this),Mr(o=this),Tr(o),Cr.delete(o),Rr(this,t),this._initialized&&null!==this._rootNode&&!e()&&(Vr(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=Gs.findByName(t,e);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null}async _initialize(){const t=e()?null:this._loadFromSsrElement();try{if(this.hasAttribute("state")){const 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){F("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||F(`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 br(e):F(`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 yr(e,`${this._name}`);else{const e=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${n.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(e)}}}catch(e){F(`Failed to initialize state: ${e}`)}if(null!==t&&this.__state)for(const[e,n]of Object.entries(t)){if(e in this.__state){const t=Object.getOwnPropertyDescriptor(this.__state,e);if(t&&(t.get||t.set))continue;if("function"==typeof this.__state[e])continue}this.__state[e]=n}await this._loadingPromise,this._name=this.getAttribute("name")||"default",sr(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,o=t?M(t):null;null!==t&&null!==o||F(`"bind-component" requires <${n.tagNames.state}> to be a direct child of a custom element.`),e instanceof ShadowRoot||this.hasAttribute("name")||F('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const s=this.getAttribute("bind-component");await customElements.whenDefined(o.toLowerCase()),t.hasAttribute(n.bindAttributeName)&&await a(t),s in t||F(`Component does not have property "${s}" for state binding.`);const r=t[s];"object"==typeof r&&null!==r||F(`Component property "${s}" is not an object for state binding.`),this._boundComponent=t,this._boundComponentStateProp=s,Vi(this,this._boundComponent,this._boundComponentStateProp,r)}}async _callStateConnectedCallback(){await this.createStateAsync("writable",async e=>{m in e&&await e[De]()})}async _initializeDCC(e,t){let o;try{if(this.hasAttribute("src")){const e=this.getAttribute("src");e.endsWith(".js")?o=await br(e):F(`DCC: Unsupported src type: ${e}`)}else{const t=this.querySelector('script[type="module"]');t?o=await yr(t,e.tagName.toLowerCase()):F(`DCC: No state source found for "${e.tagName.toLowerCase()}".`)}}catch(e){F(`DCC: Failed to load state: ${e}`)}!function(e,t,o){const s=e.tagName.toLowerCase();if(s.includes("-")||F(`DCC: "${s}" is not a valid custom element name (must contain a hyphen).`),customElements.get(s))return void console.warn(`[@wcstack/state] DCC: "${s}" is already registered. Skipping redefinition.`);const r=document.createElement("template");r.innerHTML=t.innerHTML;const i=t.mode,a=Array.isArray(o[w])?o[w]:[],l=a.length>0?function(e,t){return{protocol:"wc-bindable",version:1,properties:t.map(t=>({name:t,event:`${e}:${t}-changed`})),inputs:t.map(e=>({name:e}))}}(s,a):null,c=a.length>0?function(e,t){const n={};for(const o of t)n[o]=`${e}:${o}-changed`;return n}(s,a):{},d=`${n.tagNames.state}:not([name])`,u=class extends HTMLElement{static template=r;static shadowRootMode=i;static wcBindable=l;static bindableEventMap=c;_shadow=null;connectedCallback(){if(!this.hasAttribute(_)&&(this._shadow=this.attachShadow({mode:u.shadowRootMode}),this._shadow.appendChild(u.template.content.cloneNode(!0)),Object.keys(u.bindableEventMap).length>0)){const e=this._shadow.querySelector(d);e&&e.initializePromise.then(()=>{e.setBindableEventMap(u.bindableEventMap)})}}get stateElement(){return this._shadow?.querySelector(d)}},f=Object.getOwnPropertyDescriptors(o);for(const[e,t]of Object.entries(f)){if(Yr(e))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof t.value){const o="AsyncFunction"===t.value.constructor?.name;n.value=Xr(e,o)}else n.get=Jr(e),n.set=Kr(e);Object.defineProperty(u.prototype,e,n)}customElements.define(s,u)}(e,t,o),this._dcc=!0,this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",e=>{g in e&&e[Re]()})}async connectedCallback(){this._rootNode=this.getRootNode();const t=++this._connectGeneration;if(this._initialized)this._dcc||nr(this._rootNode,this._name)===this||sr(this._rootNode,this._name,this);else{const e=this.parentNode;if(e instanceof ShadowRoot&&e.host.hasAttribute(_))return void await this._initializeDCC(e.host,e);await this._initializeBindWebComponent(),await this._initialize(),this._initialized=!0,this._resolveInitialize?.()}if(this.hasAttribute("enable-ssr")&&!e()||await this._callStateConnectedCallback(),e()&&this.hasAttribute("enable-ssr")){await or(this.rootNode);const e=this.getAttribute("name")||"default",t=Gs.extractStateData(this),o=document.createElement(n.tagNames.ssr);o.setAttribute("name",e),o.setAttribute("version",js),Gs.buildContent(o,t),this.parentNode?.insertBefore(o,this)}e()||null===this._rootNode||t!==this._connectGeneration||this._streamsStartedGeneration===t||Vr(this),this._resolveConnectedCallback?.()}disconnectedCallback(){if(null!==this._rootNode)try{this._callStateDisconnectedCallback()}finally{sr(this.rootNode,this._name,null),e=this,vr.delete(e),function(e){Sr.delete(e)}(this),_t(this),Mr(this),zr(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&&F("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 o=e.get(t);return void 0===o?(e.set(t,[n]),!0):!o.includes(n)&&(o.push(n),!0)}addDynamicDependency(e,t){return this._addDependency(this._dynamicDependency,e,t)}addStaticDependency(e,t){return this._addDependency(this._staticDependency,e,t)}setPathInfo(e,t){if("for"===t&&(this._listPaths.add(e),this._elementPaths.add(e+"."+d)),!this._pathSet.has(e)){const t=k(e);if(this._pathSet.add(e),null!==t.parentPath){let e=t;for(;null!==e.parentPath&&this.addStaticDependency(e.parentPath,e.path);)e=k(e.parentPath)}}}_createState(e,t,n){try{const o=function(e,t,n,o){const s=new ki(e,n,o);return new Proxy(t,s)}(e,this._state,this._name,t);return n(o)}finally{}}async createStateAsync(e,t){return await this._createState(this.rootNode,e,t)}createState(e,t){this._createState(this.rootNode,e,t)}nextVersion(){return this._version++,this._version}get hasUpdatedCallback(){return this._hasUpdatedCallback}get crossRowListPaths(){return this._crossRowListPaths}addCrossRowListPath(e){this._crossRowListPaths.add(e)}get indexDependentGetterPaths(){return this._indexDependentGetterPaths}addIndexDependentGetterPath(e){this._indexDependentGetterPaths.add(e)}bindProperty(e,t){Object.defineProperty(this._state,e,t),e===y&&(this._hasUpdatedCallback=!0)}setInitialState(e){this._initialized?this._state=e:this._resolveSetState?.(e)}}function Ji(){customElements.get(n.tagNames.ssr)||customElements.define(n.tagNames.ssr,Gs),customElements.get(n.tagNames.state)||customElements.define(n.tagNames.state,Gi)}function Ki(e){var n;e&&((n=e).tagNames&&Object.assign(t.tagNames,n.tagNames),"string"==typeof n.bindAttributeName&&(t.bindAttributeName=n.bindAttributeName),"string"==typeof n.commentTextPrefix&&(t.commentTextPrefix=n.commentTextPrefix),"string"==typeof n.commentForPrefix&&(t.commentForPrefix=n.commentForPrefix),"string"==typeof n.commentIfPrefix&&(t.commentIfPrefix=n.commentIfPrefix),"string"==typeof n.commentElseIfPrefix&&(t.commentElseIfPrefix=n.commentElseIfPrefix),"string"==typeof n.commentElsePrefix&&(t.commentElsePrefix=n.commentElsePrefix),"string"==typeof n.locale&&(t.locale=n.locale),"boolean"==typeof n.debug&&(t.debug=n.debug),"boolean"==typeof n.enableMustache&&(t.enableMustache=n.enableMustache),"boolean"==typeof n.enableDirectionalInitialSync&&(t.enableDirectionalInitialSync=n.enableDirectionalInitialSync),"boolean"==typeof n.enablePropagationContext&&(t.enablePropagationContext=n.enablePropagationContext),"boolean"==typeof n.enableContractAnalyzer&&(t.enableContractAnalyzer=n.enableContractAnalyzer),"boolean"==typeof n.sameValueGuard&&(t.sameValueGuard=n.sameValueGuard)),Ji(),gr()}function Xi(e){return e}const Yi={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}},Qi=1;function Zi(){return{version:1,syntax:{bindAttribute:n.bindAttributeName,tagName:n.tagNames.state,pathDelimiter:c,wildcard:d,delimiters:{binding:";",propValue:":",modifier:"#",stateName:"@",filter:f},structuralDirectives:Array.from(J)},filters:Object.keys(te),filterMeta:Yi,reservedLifecycle:[m,g,y,b],reservedStateApi:[w,v,N,S,x,I,A,P]}}const ea=new Set(["wcstack.types","wcstack.async","wcstack.platformCapabilities","wcstack.application"]),ta=Object.freeze([]);function na(e){if(!n.enableContractAnalyzer)return ta;const t=[];return function(e,t,n){const o=e.manifestExtensions;if(null===o||"object"!=typeof o)return;for(const e of Object.keys(o))ea.has(e)||n({type:"contract:unsupported-extension",namespace:e});const s=o["wcstack.types"]?.components;if(null==s)return;for(const[e,o]of Object.entries(s)){const s=t(e);n({type:"contract:manifest-read",tag:e,loaded:null!==s}),null!==s?oa(e,o,s,n):n({type:"contract:drift",reason:"component-not-loaded",tag:e})}}(e,sa,e=>{t.push(e),null!==nt&&nt(e)}),t}function oa(e,t,n,o){const s=null!==t&&"object"==typeof t?t:{};for(const[t,r]of Object.entries(s.observables??{})){if(!n.propertyEvents.has(t)){o({type:"contract:drift",reason:"missing-member",tag:e,member:t});continue}const s=n.propertyEvents.get(t),i=r?.event;"string"==typeof i&&i!==s&&o({type:"contract:drift",reason:"event-mismatch",tag:e,member:t,sidecarEvent:i,liveEvent:s})}for(const t of Object.keys(s.inputs??{}))n.inputs.has(t)||o({type:"contract:drift",reason:"missing-member",tag:e,member:t});for(const t of Object.keys(s.commands??{}))n.commands.has(t)||o({type:"contract:drift",reason:"missing-member",tag:e,member:t})}function sa(e){const t=O(),n=t?.get(e);if(void 0===n)return null;const o=n.wcBindable;if(null===o||"object"!=typeof o||"wc-bindable"!==o.protocol)return null;const s=o,r=new Map;for(const e of Array.isArray(s.properties)?s.properties:[])"string"==typeof e?.name&&"string"==typeof e.event&&r.set(e.name,e.event);const i=new Set;for(const e of Array.isArray(s.inputs)?s.inputs:[])"string"==typeof e?.name&&i.add(e.name);const a=new Set;for(const e of Array.isArray(s.commands)?s.commands:[])"string"==typeof e?.name&&a.add(e.name);return{propertyEvents:r,inputs:i,commands:a}}export{Gs as Ssr,js as VERSION,Qi as WCS_MANIFEST_VERSION,na as analyzeContract,Ki as bootstrapState,Bs as buildBindings,Yi as builtinFilterMeta,Xi as defineState,or as getBindingsReady,o as getConfig,Zi as getWcsManifest};
|
|
2
2
|
//# sourceMappingURL=index.esm.min.js.map
|