@wcstack/state 1.30.0 → 1.32.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/auto.min.js CHANGED
@@ -1,2 +1,2 @@
1
- function t(){const t=document.documentElement;return!!t&&t.hasAttribute("data-wcs-server")}const e={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=".",o="*",s=128,r="|",i="prevent",a="stop",l="ro",c="init",d="sync",u="else",f="...",h="on",p="eventToken",m="command",g="class",y="attr",b="style",w={};for(let t=0;t<128;t++)w[`$${t+1}`]=t;const v=Object.freeze(w),N="$connectedCallback",S="$disconnectedCallback",I="$updatedCallback",x="$stateReadyCallback",$="$bindables",P="$commands",_="$commandTokens",A="$command",k="$eventTokens",C="$on",E="$streams",M="$watch",T="$listKeys",O="$streamStatus",R="$streamError",D="data-wc-definition",L=new WeakMap,W=new WeakSet;let j=0;async function B(t){const e=function(t){let e,n=L.get(t)||null;if(null!==n)return n;const o=new Promise(t=>{e=t});return n={id:++j,promise:o,resolve:e},L.set(t,n),W.has(t)&&n.resolve(),n}(t);await e.promise}function F(t){const e=L.get(t);void 0===e?W.add(t):e.resolve()}const z=new Map;let q=0;function U(t){let e=z.get(t);return void 0!==e||(e=Object.freeze(new H(t)),z.set(t,e)),e}class H{id=++q;path;segments;lastSegment;cumulativePaths;cumulativePathSet;cumulativePathInfos;cumulativePathInfoSet;parentPath;wildcardPaths;wildcardPathSet;indexByWildcardPath;wildcardPathInfos;wildcardPathInfoSet;wildcardParentPaths;wildcardParentPathSet;wildcardParentPathInfos;wildcardParentPathInfoSet;wildcardPositions;lastWildcardPath;lastWildcardInfo;wildcardCount;parentPathInfo;constructor(t){const e=e=>t===e?this:U(e),n=t.split("."),s=[],r=[],i=[],a={},l=[],c=[],d=[],u=[];let f="",h="",p=0;for(let t=0;t<n.length;t++)f+=n[t],n[t]===o&&(i.push(f),a[f]=p,l.push(e(f)),c.push(h),d.push(e(h)),u.push(t),p++),s.push(f),r.push(e(f)),h=f,f+=".";const m=i.length>0?i[i.length-1]:null,g=s.length>1?s[s.length-2]:null;this.path=t,this.segments=n,this.lastSegment=n[n.length-1],this.cumulativePaths=s,this.cumulativePathSet=new Set(s),this.cumulativePathInfos=r,this.cumulativePathInfoSet=new Set(r),this.wildcardPaths=i,this.wildcardPathSet=new Set(i),this.indexByWildcardPath=a,this.wildcardPathInfos=l,this.wildcardPathInfoSet=new Set(l),this.wildcardParentPaths=c,this.wildcardParentPathSet=new Set(c),this.wildcardParentPathInfos=d,this.wildcardParentPathInfoSet=new Set(d),this.wildcardPositions=u,this.lastWildcardPath=m,this.lastWildcardInfo=m?e(m):null,this.parentPath=g,this.parentPathInfo=g?e(g):null,this.wildcardCount=p}}const V=new WeakMap;function G(t){const e=V.get(t);if(void 0!==e)return e;let n=null;try{if(t.nodeType!==Node.ELEMENT_NODE)return n;const e=t,o=e.tagName.toLowerCase();if(o.includes("-"))return n=o;if(e.hasAttribute("is")){const t=e.getAttribute("is");if(t.includes("-"))return n=t}return n}finally{V.set(t,n)}}function K(t=null){const e=globalThis.customElements,n=t?.customElements??e;if("object"!=typeof n||null===n)return null;const o=n;return"function"!=typeof o.get||"function"!=typeof o.whenDefined?null:o}function J(t,e){t.upgrade?.(e)}function X(t){try{if(null===t||"object"!=typeof t&&"function"!=typeof t)return null;const e=t,n=e.addEventListener,o=e.removeEventListener,s=e.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=tt(s.properties,Y);if(null===r)return null;const i=void 0===s.inputs?new Map:tt(s.inputs,Q);if(null===i)return null;const a=void 0===s.commands?new Map:tt(s.commands,Z);return null===a?null:{target:t,liveDeclaration:s,knownProperties:r,declaredInputs:i,declaredCommands:a}}catch{return null}}function Y(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&("string"==typeof e.event&&0!==e.event.length&&(void 0===e.getter||"function"==typeof e.getter))}function Q(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&(void 0===e.attribute||"string"==typeof e.attribute)}function Z(t){if("object"!=typeof t||null===t)return!1;const e=t;return"string"==typeof e.name&&0!==e.name.length&&(void 0===e.async||"boolean"==typeof e.async)}function tt(t,e){if(!Array.isArray(t))return null;const n=new Map;for(const o of t){if(!e(o)||n.has(o.name))return null;n.set(o.name,o)}return n}function et(t){throw new Error(`[@wcstack/state] ${t}`)}function nt(t,e,n){const o="."===e?`.${t}`:`${e}.${t}`;return{propName:t,propSegments:[t],propModifiers:[],statePathName:o,statePathInfo:U(o),stateName:n,inFilters:[],outFilters:[],bindingType:"prop"}}function ot(t){switch(t.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${t.bindingType}::${t.propName}`;default:return null}}function st(t,e,n={}){const o=n.allowDeferred??!0;if(!e.some(t=>"spread"===t.bindingType))return e;const s=[],r=new WeakSet;for(const n of e){if("spread"!==n.bindingType){s.push(n);continue}t.nodeType!==Node.ELEMENT_NODE&&et("Spread binding requires an element node.");const e=t,i=G(e);null===i&&et(`Spread binding "${n.statePathName}" requires a custom element with wcBindable, but <${e.tagName.toLowerCase()}> is not a custom element.`);const a=K();null===a&&et(`CustomElementRegistry is unavailable for <${i}>.`);if(void 0===a.get(i)){o||et(`Spread binding "${n.statePathName}" requires <${i}> to be registered. Define the custom element before initializing this binding.`),s.push(n);continue}J(a,e);const l=X(e);null===l&&et(`Spread binding "${n.statePathName}" requires <${i}> to expose a valid wcBindable declaration.`);const c=n.statePathName,d=n.stateName,u=new Set;for(const t of l.knownProperties.keys()){if(u.has(t))continue;u.add(t);const e=nt(t,c,d);r.add(e),s.push(e)}for(const t of l.declaredInputs.keys()){if(u.has(t))continue;u.add(t);const e=nt(t,c,d);r.add(e),s.push(e)}}const i=new Map;for(let t=0;t<s.length;t++){const e=ot(s[t]);null!==e&&i.set(e,t)}const a=[];for(let t=0;t<s.length;t++){const e=ot(s[t]);null!==e?i.get(e)===t&&a.push(s[t]):a.push(s[t])}return a}function rt(t,e){let n=t;if(0===e.length)return n;for(let t=0;t<e.length&&(n=n?.childNodes[e[t]]??null,null!==n);t++);return n}const it=new WeakMap;function at(t,e,n){if(Math.abs(t.length-e.length)>n)return n+1;const o=new Array(e.length+1),s=new Array(e.length+1);for(let t=0;t<=e.length;t++)o[t]=t;for(let n=1;n<=t.length;n++){s[0]=n;for(let r=1;r<=e.length;r++){const i=t[n-1]===e[r-1]?0:1;s[r]=Math.min(o[r]+1,s[r-1]+1,o[r-1]+i)}for(let t=0;t<=e.length;t++)o[t]=s[t]}return o[e.length]}function lt(t,e){if(0===t.length)return"";const n=t.toLowerCase();let o=null,s=3;for(const t of e){const e=at(n,t.toLowerCase(),2);e<s&&(o=t,s=e)}return null!==o?` Did you mean "${o}"?`:""}const ct=" Validate statically: npx @wcstack/lint <file>.",dt=new Set(["if","elseif","else","for"]);function ut(t){et(`filter ${t} requires at least one option`)}function ft(t){et(`filter ${t} requires a number as option`)}function ht(t){et(`filter ${t} requires a number value`)}function pt(t){et(`filter ${t} requires a date value`)}function mt(t){return!(!t||isNaN(Number(t)))}const gt={eq:t=>{const e=t?.[0]??ut("eq");return t=>"number"==typeof t?(mt(e)||ft("eq"),t===Number(e)):t===e},ne:t=>{const e=t?.[0]??ut("ne");return t=>"number"==typeof t?(mt(e)||ft("ne"),t!==Number(e)):t!==e},not:t=>t=>("boolean"!=typeof t&&et(`filter ${"not"} requires a boolean value`),!t),lt:t=>{const e=t?.[0]??ut("lt");return mt(e)||ft("lt"),t=>("number"!=typeof t&&ht("lt"),t<Number(e))},le:t=>{const e=t?.[0]??ut("le");return mt(e)||ft("le"),t=>("number"!=typeof t&&ht("le"),t<=Number(e))},gt:t=>{const e=t?.[0]??ut("gt");return mt(e)||ft("gt"),t=>("number"!=typeof t&&ht("gt"),t>Number(e))},ge:t=>{const e=t?.[0]??ut("ge");return mt(e)||ft("ge"),t=>("number"!=typeof t&&ht("ge"),t>=Number(e))},inc:t=>{const e=t?.[0]??ut("inc");return mt(e)||ft("inc"),t=>("number"!=typeof t&&ht("inc"),t+Number(e))},dec:t=>{const e=t?.[0]??ut("dec");return mt(e)||ft("dec"),t=>("number"!=typeof t&&ht("dec"),t-Number(e))},mul:t=>{const e=t?.[0]??ut("mul");return mt(e)||ft("mul"),t=>("number"!=typeof t&&ht("mul"),t*Number(e))},div:t=>{const e=t?.[0]??ut("div");return mt(e)||ft("div"),t=>("number"!=typeof t&&ht("div"),t/Number(e))},mod:t=>{const e=t?.[0]??ut("mod");return mt(e)||ft("mod"),t=>("number"!=typeof t&&ht("mod"),t%Number(e))},abs:t=>t=>("number"!=typeof t&&ht("abs"),Math.abs(t)),clamp:t=>{const e=t?.[0]??ut("clamp");mt(e)||ft("clamp");const n=t?.[1]??ut("clamp");mt(n)||ft("clamp");const o=Number(e),s=Number(n);return t=>("number"!=typeof t&&ht("clamp"),Math.min(Math.max(t,o),s))},fix:t=>{const e=t?.[0]??"0";return mt(e)||ft("fix"),t=>("number"!=typeof t&&ht("fix"),t.toFixed(Number(e)))},locale:t=>{const n=t?.[0]??e.locale;return t=>("number"!=typeof t&&ht("locale"),t.toLocaleString(n))},uc:t=>t=>String(t).toUpperCase(),lc:t=>t=>String(t).toLowerCase(),cap:t=>t=>{const e=String(t);return 0===e.length?e:1===e.length?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)},trim:t=>t=>String(t).trim(),slice:t=>{const e=[],n=t?.[0]??ut("slice");mt(n)||ft("slice"),e.push(Number(n));const o=t?.[1];return void 0!==o&&(mt(o)||ft("slice"),e.push(Number(o))),t=>String(t).slice(...e)},substr:t=>{const e=t?.[0]??ut("substr");mt(e)||ft("substr");const n=t?.[1]??ut("substr");return mt(n)||ft("substr"),t=>String(t).substr(Number(e),Number(n))},pad:t=>{const e=t?.[0]??ut("pad");mt(e)||ft("pad");const n=t?.[1]??"0";return t=>String(t).padStart(Number(e),n)},rep:t=>{const e=t?.[0]??ut("rep");return mt(e)||ft("rep"),t=>String(t).repeat(Number(e))},rev:t=>t=>String(t).split("").reverse().join(""),truncate:t=>{const e=t?.[0]??ut("truncate");mt(e)||ft("truncate");const n=Number(e),o=t?.[1]??"…";return t=>{const e=String(t);return e.length<=n?e:e.slice(0,n)+o}},join:t=>{const e=t?.[0]??", ";return t=>(Array.isArray(t)||et(`filter ${"join"} requires an array value`),t.join(e))},int:t=>t=>parseInt(String(t),10),float:t=>t=>parseFloat(String(t)),round:t=>{const e=t?.[0]??"0";return mt(e)||ft("round"),t=>{"number"!=typeof t&&ht("round");const n=Math.pow(10,Number(e));return Math.round(t*n)/n}},floor:t=>{const e=t?.[0]??"0";return mt(e)||ft("floor"),t=>{"number"!=typeof t&&ht("floor");const n=Math.pow(10,Number(e));return Math.floor(t*n)/n}},ceil:t=>{const e=t?.[0]??"0";return mt(e)||ft("ceil"),t=>{"number"!=typeof t&&ht("ceil");const n=Math.pow(10,Number(e));return Math.ceil(t*n)/n}},percent:t=>{const e=t?.[0]??"0";return mt(e)||ft("percent"),t=>("number"!=typeof t&&ht("percent"),`${(100*t).toFixed(Number(e))}%`)},unit:t=>{const e=t?.[0]??ut("unit");return t=>null==t?t:String(t)+e},date:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||pt("date"),t.toLocaleDateString(n))},time:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||pt("time"),t.toLocaleTimeString(n))},datetime:t=>{const n=t?.[0]??e.locale;return t=>(t instanceof Date||pt("datetime"),t.toLocaleString(n))},ymd:t=>{const e=t?.[0]??"-";return t=>{t instanceof Date||pt("ymd");const n=t.getFullYear().toString(),o=(t.getMonth()+1).toString().padStart(2,"0"),s=t.getDate().toString().padStart(2,"0");return`${n}${e}${o}${e}${s}`}},hms:t=>{const e=t?.[0]??":";return t=>{t instanceof Date||pt("hms");const n=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0"),s=t.getSeconds().toString().padStart(2,"0");return`${n}${e}${o}${e}${s}`}},falsy:t=>t=>!1===t||null==t||0===t||""===t||Number.isNaN(t),truthy:t=>t=>!1!==t&&null!=t&&0!==t&&""!==t&&!Number.isNaN(t),defaults:t=>{const e=t?.[0]??ut("defaults");return t=>!1===t||null==t||0===t||""===t||Number.isNaN(t)?e:t},boolean:t=>t=>Boolean(t),number:t=>t=>Number(t),string:t=>t=>String(t),null:t=>t=>""===t?null:t},yt=gt,bt={input:gt,output:yt},wt=(t,e)=>n=>{const o=n[t];return o||et(`[wcs/filter-unknown] filter not found: ${t}.${lt(t,Object.keys(n))}${ct}`),o(e)};function vt(t,e,n){const o=-1===e?t.length:e;let s=0;for(;s<o&&/\s/.test(t[s]);)s++;const r=-1===n?0:n;let i=t.length;for(;i>r&&/\s/.test(t[i-1]);)i--;return t.slice(s,i)}const Nt=new Map;function St(t,e){const n=bt[e];return t.map(t=>{const o=t.indexOf("("),s=t.lastIndexOf(")");if(-1!==o&&-1===s&&et(`Invalid filter format: missing closing parenthesis in "${t}"`),-1!==s&&-1===o&&et(`Invalid filter format: missing opening parenthesis in "${t}"`),-1===o){const o=t.trim(),s=`${o}():${e}`;let r=Nt.get(s);return void 0===r&&(r=wt(o,[])(n),Nt.set(s,r)),{filterName:o,args:[],filterFn:r}}{const r=t.substring(o+1,s),i=t.substring(0,o).trim(),a=function(t){const e=[];let n="",o=null,s=!1,r=-1,i=-1;const a=()=>{e.push(vt(n,r,i)),n="",s=!1,r=-1,i=-1};for(let e=0;e<t.length;e++){const l=t[e];o?l===o?o=null:(-1===r&&(r=n.length),n+=l,i=n.length):'"'===l||"'"===l?(o=l,s=!0):","===l?a():n+=l}const l=vt(n,r,i);return(l||s)&&e.push(l),e}(r),l=`${i}(${a.join(",")}):${e}`;let c=Nt.get(l);return void 0===c&&(c=wt(i,a)(n),Nt.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const It=t=>t.trim(),xt=new Map;const $t=new Map;function Pt(t){const e=t.indexOf(r);let n="",o=[],s="",i=[];-1!==e?(n=t.slice(0,e).trim(),s=t.slice(e+1).trim(),$t.has(s)?i=$t.get(s):(o=s.split(r).map(It),i=St(o,"output"),$t.set(s,i))):n=t.trim();const[a,l="default"]=n.split("@").map(It);return{stateName:l,statePathName:a,statePathInfo:U(a),outFilters:i}}function _t(t){const[...e]=t.split(";").map(It).filter(t=>t.length>0),o=e.map(t=>{const e=t.indexOf(":");-1===e&&et(`Invalid bindText: "${t}". Missing ':' separator between propPart and statePart.`);const o=t.slice(0,e).trim(),s=t.slice(e+1).trim();if(o===u){const t=U("#else");return{propName:u,propSegments:[u],propModifiers:[],statePathName:"#else",statePathInfo:t,stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if(o===f){const e=Pt(s);return e.outFilters.length>0&&et(`Invalid spread binding "${t}": filters are not allowed on spread targets.`),0===e.statePathName.length&&et(`Invalid spread binding "${t}": spread target path is required.`),{propName:f,propSegments:[f],propModifiers:[],inFilters:[],...e,bindingType:"spread"}}if("if"===o||"elseif"===o||"for"===o||"radio"===o||"checkbox"===o){return{propName:o,propSegments:[o],propModifiers:[],inFilters:[],...Pt(s),bindingType:o}}{const t=Pt(s),e=function(t){const e=t.indexOf(r);let o="",s=[],i="",a=[];-1!==e?(o=t.slice(0,e).trim(),i=t.slice(e+1).trim(),xt.has(i)?a=xt.get(i):(s=i.split(r).map(It),a=St(s,"input"),xt.set(i,a))):o=t.trim();const[l,c]=o.split("#").map(It),d=l.split(n).map(It);return{propName:l,propSegments:d,propModifiers:c?c.split(",").map(It):[],inFilters:a}}(o);return e.propSegments[0]===p||e.propSegments[0].startsWith(h)?{...e,...t,bindingType:"event"}:{...e,...t,bindingType:"prop"}}});if(o.length>1){o.some(t=>dt.has(t.bindingType))&&et(`[wcs/template-syntax] Invalid bindText: "${t}". 'if', 'elseif', 'else', and 'for' bindings must be single binding. Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).${ct}`)}return o}const At=new WeakMap,kt=new Set([e.commentTextPrefix,e.commentForPrefix,e.commentIfPrefix,e.commentElseIfPrefix,e.commentElsePrefix]),Ct=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function Et(t){const n=At.get(t);if("string"==typeof n)return n;if(t.nodeType!==Node.COMMENT_NODE)return null;const o=t.data.trim(),s=Ct.exec(o);if(null===s)return null;const r=s[1]||e.commentTextPrefix;return kt.has(r)?(At.set(t,s[2]),s[2]):null}function Mt(t){return{propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...Pt(t),bindingType:"text"}}const Tt=new Map;function Ot(t,e,n){if(null===n)Tt.delete(t);else{Tt.set(t,n);const o=n.parseBindTextResult,s=zr(e,o.stateName);null===s&&et(`State element with name "${o.stateName}" not found for fragment info.`),s.setPathInfo(o.statePathName,o.bindingType);for(const t of n.nodeInfos)for(const n of t.parseBindTextResults){const t=zr(e,n.stateName);null===t&&et(`State element with name "${n.stateName}" not found for fragment info node.`),t.setPathInfo(n.statePathName,n.bindingType)}}}function Rt(t){return Tt.get(t)||null}function Dt(t){if(t.nodeType===Node.ELEMENT_NODE){return _t(t.getAttribute(e.bindAttributeName)||"")}if(t.nodeType===Node.COMMENT_NODE){const e=Et(t);null===e&&et("Comment node binding text not found.");const n=Rt(e);let o=n?.parseBindTextResult??null,s=null;return null===o?(o=Mt(e),s=null):s=e,[{...o,uuid:s}]}return[]}function Lt(t){if(!t.hasAttribute("bind-component"))return!1;const n=t.parentNode;return n instanceof Element&&n.hasAttribute(e.bindAttributeName)}function Wt(t){const n=[],o=t.querySelectorAll(`${e.tagNames.state}[bind-component]`);for(const e of o){if(!Lt(e))continue;const o=e.parentNode;o!==t&&n.push(o)}return n}function jt(t,e){for(let n=0;n<e.length;n++){const o=e[n];if(o!==t&&o.contains(t))return!0}return!1}function Bt(t){const n=[],o=Wt(t),s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(t){if(t.nodeType===Node.ELEMENT_NODE){return t.hasAttribute(e.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==Et(t)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();){const t=s.currentNode;o.length>0&&jt(t,o)||n.push(t)}return n}const Ft=new WeakSet;function zt(t,e,n){const o=st(t,e,{allowDeferred:n.allowDeferred});if(o.some(t=>"spread"===t.bindingType)){const n=t.nodeType===Node.ELEMENT_NODE?G(t):null;return null===n&&et("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:t,tagName:n,parseResults:e}}}Ft.add(t);const s=function(t,e){const n=[];for(const o of e)if("text"!==o.bindingType)n.push({...o,node:t,replaceNode:t});else{const e=t.nodeType===Node.TEXT_NODE?t:document.createTextNode("");n.push({...o,node:t,replaceNode:e})}return n}(t,o);return function(t,e){it.set(t,e)}(t,s),F(t),{bindings:s,deferred:null}}function qt(t){const e=Bt(t),n=[],o=[];for(const t of e){if(Ft.has(t))continue;const e=zt(t,Dt(t),{allowDeferred:!0});null===e.deferred?n.push(...e.bindings):o.push(e.deferred)}return[e,n,o]}function Ut(t){Ft.add(t)}function Ht(t){const{node:e,parseResults:n}=t;!function(t){Ft.delete(t)}(e);return zt(e,n,{allowDeferred:!1}).bindings}const Vt=new WeakMap;function Gt(t){let e=t;for(;e;){const t=Vt.get(e);if(t)return t;e=e.parentNode}return null}function Kt(t,e){null!==e?Vt.set(t,e):Vt.delete(t)}const Jt=new WeakMap;function Xt(t){return Jt.get(t)??[]}function Yt(t,e){Jt.set(t,e)}const Qt=Symbol("$$setLoopContext"),Zt=Symbol("$$getByAddress"),te=Symbol("$$hasByAddress"),ee=Symbol("$$setByAddress"),ne=Symbol("$$connectedCallback"),oe=Symbol("$$disconnectedCallback"),se=Symbol("$$updatedCallback"),re=new WeakMap;function ie(t,e){if(re.has(t)){const n=re.get(t);if(n.has(e))return n.get(e)}else re.set(t,new WeakMap);const n=Object.freeze(new ae(t,e));return re.get(t).set(e,n),n}class ae{pathInfo;stateName;stateElement;parentAbsolutePathInfo;constructor(t,e){this.pathInfo=e,this.stateName=t.name,this.stateElement=t,null===e.parentPathInfo?this.parentAbsolutePathInfo=null:this.parentAbsolutePathInfo=ie(t,e.parentPathInfo)}}const le=new WeakMap,ce=new WeakMap;class de{absolutePathInfo;listIndex;_parentAbsoluteAddress;constructor(t,e){this.absolutePathInfo=t,this.listIndex=e}get parentAbsoluteAddress(){if(void 0!==this._parentAbsoluteAddress)return this._parentAbsoluteAddress;const t=this.absolutePathInfo.parentAbsolutePathInfo;if(null===t)return null;let e=null;return e=this.absolutePathInfo.pathInfo.segments[this.absolutePathInfo.pathInfo.segments.length-1]===o?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAbsoluteAddress=ue(t,e)}}function ue(t,e){if(null===e){let e=ce.get(t);return void 0!==e||(e=new de(t,null),ce.set(t,e)),e}{let n=le.get(e);void 0===n&&(n=new WeakMap,le.set(e,n));let o=n.get(t);return void 0!==o||(o=new de(t,e),n.set(t,o)),o}}const fe=new WeakMap;function he(t,e){null===e?fe.delete(t):fe.set(t,e)}function pe(t){return fe.get(t)||null}const me=new Map;function ge(t,e){let n,o;if(0===t.wildcardCount||0===e.wildcardCount)return 0;if(1===t.wildcardCount&&e.wildcardCount>0&&e.wildcardPathSet.has(t.path))return 1;t.id<e.id?(n=t,o=e):(n=e,o=t);const s=`${n.path}\t${o.path}`;let r=me.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,me.set(s,r),r}function ye(t,e,n){return e<0||e>=n?null:t.at(e-n)}function be(t,e){const n=t.indexes??[];return n.length===e?n:n.slice(n.length-e)}const we=new WeakMap;function ve(t){const e=Gt(t.node);if(null===e)return null;let n=we.get(e);if(void 0===n)n=new WeakMap,we.set(e,n);else{const e=n.get(t);if(void 0!==e)return e}let o=null;try{const n=ge(e.pathInfo,t.statePathInfo);return n>0&&(o=ye(e.listIndex,n-1,e.pathInfo.wildcardCount)),o}finally{n.set(t,o)}}const Ne=new WeakMap;function Se(t,e){if(null!=e)return e;let n=t.replaceNode.getRootNode();if(!1===t.replaceNode.isConnected){const e=pe(n);null===e?et(`Cannot get absolute state address for disconnected binding: ${t.bindingType} ${t.statePathName} on ${t.node.nodeName}`):n=e}return n}function Ie(t,e){let n=null;if(n=Ne.get(t)||null,null!==n)return n;const o=Se(t,e),s=ve(t),r=zr(o,t.stateName);null===r&&et(`State element with name "${t.stateName}" not found for binding.`);return n=ue(ie(r,t.statePathInfo),s),Ne.set(t,n),n}function xe(t){Ne.delete(t)}let $e=null;const Pe=new WeakMap;function _e(t,e){const n=Pe.get(t);void 0===n?Pe.set(t,e):n instanceof Set?n.add(e):n!==e&&Pe.set(t,new Set([n,e])),null!==$e&&$e({type:"state:binding-added",absoluteAddress:t,binding:e})}function Ae(t,e){const n=Pe.get(t);void 0!==n&&(n instanceof Set?n.delete(e):n===e&&Pe.delete(t),null!==$e&&$e({type:"state:binding-removed",absoluteAddress:t,binding:e}))}const ke=new WeakMap;function Ce(t,e,n){let o=ke.get(t);void 0===o&&(o=new WeakMap,ke.set(t,o));const s=o.get(e);void 0===s?o.set(e,n):s instanceof Set?s.add(n):s!==n&&o.set(e,new Set([s,n])),null!==$e&&$e({type:"state:binding-added",absoluteAddress:ue(t,e),binding:n})}function Ee(t,e,n){const o=ke.get(t);if(void 0===o)return;const s=o.get(e);void 0!==s&&(s instanceof Set?s.delete(n):s===n&&o.delete(e),null!==$e&&$e({type:"state:binding-removed",absoluteAddress:ue(t,e),binding:n}))}function Me(t){const e=Pe.get(t);return void 0!==e?e:null!==t.listIndex?ke.get(t.absolutePathInfo)?.get(t.listIndex):void 0}const Te=new WeakMap,Oe=new WeakMap;class Re{pathInfo;listIndex;_parentAddress;constructor(t,e){this.pathInfo=t,this.listIndex=e}get parentAddress(){if(void 0!==this._parentAddress)return this._parentAddress;const t=this.pathInfo.parentPathInfo;if(null===t)return null;let e=null;return e=this.pathInfo.segments[this.pathInfo.segments.length-1]===o?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=De(t,e)}}function De(t,e){if(null===e){let e=Oe.get(t);return void 0!==e||(e=new Re(t,null),Oe.set(t,e)),e}{let n=Te.get(e);void 0===n&&(n=new WeakMap,Te.set(e,n));let o=n.get(t);return void 0!==o||(o=new Re(t,e),n.set(t,o)),o}}const Le=new WeakMap;function We(t){let e=null;if(e=Le.get(t)||null,null!==e)return e;if(t.statePathInfo.wildcardCount>0){const n=ve(t);null===n&&et(`Cannot resolve state address for binding with wildcard statePathName "${t.statePathName}" because list index is null.`),e=De(t.statePathInfo,n)}else e=De(t.statePathInfo,null);return Le.set(t,e),e}function je(t){Le.delete(t)}function Be(){const t=new Map,e=new Map;return{add(n,o){let s=t.get(n);return void 0===s&&(s=new WeakSet,t.set(n,s)),!s.has(o)&&(s.add(o),e.set(n,(e.get(n)??0)+1),!0)},remove(n,o){const s=t.get(n);if(void 0===s||!s.has(o))return!1;s.delete(o);const r=(e.get(n)??1)-1;return r<=0?(t.delete(n),e.delete(n),!0):(e.set(n,r),!1)},has:(e,n)=>t.get(e)?.has(n)??!1,countOf:t=>e.get(t)??0,get keyCount(){return e.size},clear(){t.clear(),e.clear()}}}const Fe=new Map,ze=Be();function qe(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}function Ue(t){let e="input";for(const n of t.propModifiers)n.startsWith(h)&&(e=n.slice(2));return e}function He(t){if("checkbox"===t.bindingType&&-1===t.propModifiers.indexOf(l)){const s=Ue(t),r=qe(t,s);let i=Fe.get(r);return void 0===i&&(e=t.stateName,n=t.statePathName,o=t.inFilters,i=t=>{const s=t.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 t of o)i=t.filterFn(i);const a=zr(s.getRootNode(),e);null===a&&et(`State element with name "${e}" not found for two-way binding.`);const l=Gt(s);a.createState("writable",t=>{t[Qt](l,()=>{let e=t[n];if(Array.isArray(e))if(r)-1===e.indexOf(i)&&(t[n]=e.concat(i));else{const o=e.indexOf(i);-1!==o&&(t[n]=e.toSpliced(o,1))}else t[n]=r?[i]:[]})})},Fe.set(r,i)),t.node.addEventListener(s,i),ze.add(r,t),!0}var e,n,o;return!1}function Ve(t){return("object"==typeof t||"function"==typeof t)&&null!==t&&"function"==typeof t.then}function Ge(t,e){const n=Array.isArray(t)?t:[t];for(const t of n)Ve(t)&&Promise.resolve(t).catch(t=>{console.error(`[wcstack/state] ${e} rejected.`,t)})}class Ke{_name;_subscribers=new Set;constructor(t){this._name=t}get name(){return this._name}get size(){return this._subscribers.size}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}unsubscribe(t){return this._subscribers.delete(t)}emit(...t){const e=[];for(const n of this._subscribers)e.push(n(...t));return e}}class Je extends Ke{_ownerStateName;constructor(t,e){super(t),this._ownerStateName=e??null}emit(...t){return null!==$e&&$e({type:"state:token-emit",kind:"event",stateName:this._ownerStateName,tokenName:this.name,args:t,subscriberCount:this.size}),super.emit(...t)}}const Xe=new WeakMap;function Ye(t,e){let n=Xe.get(t);void 0===n&&(n=new Map,Xe.set(t,n));let o=n.get(e);return void 0===o&&(o=new Je(e,t.name),n.set(e,o)),o}function Qe(t){Xe.delete(t)}const Ze=new WeakMap;function tn(t){if(t.propSegments[0]!==p)return!1;const e=t.node,n=G(e),o=K();if(null!==n&&void 0===o?.get(n))return null===o&&et(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(Ze.has(t))return!0;const s=t.propSegments[1];"string"==typeof s&&0!==s.length||et('eventToken binding requires a property name (e.g., "eventToken.error").');const r=function(t){return null===G(t)?null:X(t)}(e);null===r&&et(`eventToken binding requires a wc-bindable custom element. <${e.tagName.toLowerCase()}> is not wc-bindable.`);const l=r.knownProperties.get(s);void 0===l&&et(`Property "${s}" is not declared in wcBindable.properties of <${e.tagName.toLowerCase()}>.${lt(s,r.knownProperties.keys())}`);const c=l.event,d=t.statePathName,u=t.stateName,f=t.propModifiers,h=t=>{f.includes(i)&&t.preventDefault(),f.includes(a)&&t.stopPropagation();const n=zr(e.getRootNode(),u);null===n&&et(`State element with name "${u}" not found for eventToken handler.`),n.eventTokenNames.has(d)||et(`[wcs/token-undeclared] eventToken "${d}" is not declared in $eventTokens of state "${u}".${lt(d,n.eventTokenNames)}${ct}`);const o=Gt(e);n.createStateAsync("writable",async e=>{Ge(e[Qt](o,()=>{const s=null!==o?be(o.listIndex,o.pathInfo.wildcardCount):[];return Ye(n,d).emit(e,t,...s)}),`$on."${d}" of state "${u}"`)})};return e.addEventListener(c,h),Ze.set(t,{eventName:c,handler:h}),!0}class en extends Ke{_ownerStateName;constructor(t,e){super(t),this._ownerStateName=e??null}emit(...t){return null!==$e&&$e({type:"state:token-emit",kind:"command",stateName:this._ownerStateName,tokenName:this.name,args:t,subscriberCount:this.size}),super.emit(...t)}}function nn(t){return t instanceof en}const on=new Map,sn=Be();function rn(t){const e=t.propModifiers.filter(t=>t===i||t===a).sort().join(",");return`${t.stateName}::${t.statePathName}::${e}`}const an=(t,e,n,o)=>s=>{n.includes(i)&&s.preventDefault(),n.includes(a)&&s.stopPropagation();const r=s.target,l=zr(r.getRootNode(),t);null===l&&et(`State element with name "${t}" not found for event handler.`);const c=Gt(r),d=e.startsWith(A+".");l.createStateAsync("writable",async n=>{Ge(n[Qt](c,()=>{const r=null!==c?be(c.listIndex,c.pathInfo.wildcardCount):[];if(d){const t=n[Zt](De(o,null));return nn(t)||et(`Event binding "${e}" did not resolve to a CommandToken. Declare the name in $commandTokens and reference it as $command.<name>.`),t.emit(s,...r)}const i=n[e];return"function"!=typeof i&&et(`Handler "${e}" is not a function on state "${t}".`),Reflect.apply(i,n,[s,...r])}),`"${e}" of state "${t}"`)})};function ln(t){if(!t.propName.startsWith(h))return!1;const e=rn(t);let n=on.get(e);void 0===n&&(n=an(t.stateName,t.statePathName,t.propModifiers,t.statePathInfo),on.set(e,n));const o=t.propName.slice(2);return t.node.addEventListener(o,n),sn.add(e,t),!0}const cn=new Map,dn=Be();function un(t,e){const n=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.statePathName}::${e}::${n}`}function fn(t){let e="input";for(const n of t.propModifiers)n.startsWith(h)&&(e=n.slice(2));return e}function hn(t){if("radio"===t.bindingType&&-1===t.propModifiers.indexOf(l)){const s=fn(t),r=un(t,s);let i=cn.get(r);return void 0===i&&(e=t.stateName,n=t.statePathName,o=t.inFilters,i=t=>{const s=t.target;if(null===s)return void console.warn("[@wcstack/state] event.target is null.");if("radio"!==s.type)return void console.warn("[@wcstack/state] event.target is not a radio input element.");if(!1===s.checked)return;let r=s.value;for(const t of o)r=t.filterFn(r);const i=zr(s.getRootNode(),e);null===i&&et(`State element with name "${e}" not found for two-way binding.`);const a=Gt(s);i.createState("writable",t=>{t[Qt](a,()=>{t[n]=r})})},cn.set(r,i)),t.node.addEventListener(s,i),dn.add(r,t),!0}var e,n,o;return!1}const pn=new Set(["radio","checkbox"]),mn=new Set(["value","valueAsNumber","valueAsDate"]);function gn(t,e){if(t.nodeType!==Node.ELEMENT_NODE)return!1;const n=t,o=n.tagName.toLowerCase();if("input"===o){const t=(n.getAttribute("type")||"text").toLowerCase();if("button"===t)return!1;if(pn.has(t)&&"checked"===e)return!0;if(mn.has(e))return!0}if("select"===o&&"value"===e)return!0;if("textarea"===o&&"value"===e)return!0;const s=G(n);if(null!==s){const t=K()?.get(s);void 0===t&&et(`Custom element <${s}> is not defined. Cannot determine if property "${e}" is suitable for two-way binding.`);const o=X(n);if(o?.knownProperties.has(e))return!0}return!1}let yn=1,bn=1,wn=1;const vn=new WeakMap;function Nn(t,e,n,o){let s=vn.get(t);void 0===s&&(s=new Map,vn.set(t,s));const r=function(t,e,n){return`${e}::${n}::${t}`}(e,n,o);let i=s.get(r);return void 0===i&&(i=yn++,s.set(r,i)),i}function Sn(t,e){return"to-element"===e?2*t:2*t+1}const In=new Set;function xn(t){return{transactionId:bn++,originBindingId:t,visitedEdges:In,hop:0}}function $n(t,e){const n=new Set(t.visitedEdges);return n.add(e),{transactionId:t.transactionId,originBindingId:t.originBindingId,visitedEdges:n,hop:t.hop+1}}let Pn=null;function _n(){return Pn}function An(t,e){const n=Pn;Pn=t;try{return e()}finally{Pn=n}}const kn=[];let Cn=!1;const En=new Map,Mn=Be(),Tn=new WeakMap,On=t=>t.detail;function Rn(t,e,n,o){const s=t.inFilters.map(t=>t.filterName+"("+t.args.join(",")+")").join("|");return`${t.stateName}::${t.propName}::${t.statePathName}::${e}::${s}::${n?"g":"n"}::${o?"o":"s"}`}function Dn(t){let e="select"===t.node.tagName.toLowerCase()?"change":"input";const n=G(t.node);if(null!==n){const o=K()?.get(n);void 0===o&&et(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=X(t.node)?.knownProperties.get(t.propName);s&&(e=s.event)}for(const n of t.propModifiers)n.startsWith(h)&&(e=n.slice(2));return e}function Ln(t){if(null!==G(t.node)){const e=X(t.node)?.knownProperties.get(t.propName);if(e)return e.getter??On}return null}function Wn(t){if(null===G(t.node))return!1;const e=X(t.node)?.knownProperties.get(t.propName);return"event"===e?.semantics}const jn=(t,e,n,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!==s)l=s(i);else{if(!(e in a))return void console.warn(`[@wcstack/state] Property "${e}" does not exist on target element.`);l=a[e]}let c=l;for(const t of o)c=t.filterFn(c);const d=Tn.get(a)?.get(e);if(void 0!==d)for(const t of d)t(c);let u=null;{const o=Nn(a,e,t,n),s=function(t,e){for(let n=kn.length-1;n>=0;n--){const o=kn[n];if(o.node===t&&o.receipt.member===e)return o.receipt}return null}(a,e);if(null!==s&&Object.is(s.writtenValue,l))return void(null!==$e&&$e({type:"propagation:suppressed",reason:"confirmation",transactionId:s.transactionId,edgeId:Sn(o,"to-state"),node:a,member:e}));const r=Sn(o,"to-state"),i=_n();if(null!==i&&i.visitedEdges.has(r))return void(null!==$e&&$e({type:"propagation:suppressed",reason:"visited-edge",transactionId:i.transactionId,edgeId:r,node:a,member:e}));u=$n(i??xn(o),r)}const f=zr(a.getRootNode(),t);null===f&&et(`State element with name "${t}" not found for two-way binding.`);const h=Gt(a),p=()=>{r&&(Cn=!0);try{f.createState("writable",t=>{t[Qt](h,()=>{t[n]=c})})}finally{r&&(Cn=!1)}};null!==u?An(u,p):p()};const Bn=new WeakMap;function Fn(t,e){const n=Bn.get(t);return n?n.get(e)??null:null}const zn=new WeakMap;function qn(t,e){zn.set(t,e)}function Un(t){return zn.get(t)??null}function Hn(t){let e=t;for(;;){if(null==e||!0!==e.hasMappedComponentState)return null;const t=e.boundComponent;if(null==t)return null;const n=Gt(t)?.listIndex;if(null!=n)return n;e=Un(t)}}function Vn(t){return Hn(t)?.length??0}function Gn(t,e){return e.wildcardCount+Vn(t)}function Kn(t,e){return e??Hn(t)}const Jn=new WeakMap,Xn=new WeakMap,Yn=new WeakMap,Qn=new WeakMap;function Zn(t,e){return{innerAbsPathInfo:ie(t,U(e.propSegments.slice(1).join(n))),outerAbsPathInfo:Ie(e).absolutePathInfo}}function to(t,e,o=!0){let s=Jn.get(t);if(void 0===s&&(s=new Map,Jn.set(t,s)),s.has(e))return s.get(e);let r=Xn.get(t);void 0===r&&(r=new Map,Xn.set(t,r));const i=Yn.get(t);if(void 0===i)return null;let a=null;for(const t of i)if(e.pathInfo.cumulativePathInfoSet.has(t.innerAbsPathInfo.pathInfo)){t.innerAbsPathInfo.pathInfo.segments.length===e.pathInfo.segments.length&&et("Duplicate mapping rule for web component."),a=t;break}if(null===a)return null;const l=Qn.get(a);void 0===l&&et("Binding not found for primary mapping rule on web component.");const c=e.pathInfo.segments.slice(a.innerAbsPathInfo.pathInfo.segments.length),d=U(a.outerAbsPathInfo.pathInfo.segments.concat(c).join(n)),u=zr(t.getRootNode(),l.stateName);null===u&&et(`State element with name "${l.stateName}" not found for web component.`);const f=ie(u,d);if(!o)return f;s.set(e,f),r.set(f,e);const h=[l.propSegments[0],...e.pathInfo.segments],p={...l,propName:h.join(n),propSegments:h,statePathName:f.pathInfo.path,statePathInfo:f.pathInfo},m=jo(l);return null===m||f.pathInfo.wildcardCount>0&&null===ve(p)||m.initialize([p],{registerAddress:!0}),f}function eo(t,e){const n=no(t,e);if(null===n||n.stateElement===t)return null;return Gn(t,e)!==Gn(n.stateElement,n.pathInfo)?null:n}function no(t,e){if(!0!==t.hasMappedComponentState)return null;const n=t.boundComponent;if(null==n)return null;return to(n,ie(t,e),!1)}const oo=new WeakSet;function so(t){oo.add(t)}function ro(t){return!!oo.has(t)&&(oo.delete(t),!0)}const io=new WeakSet;function ao(t){io.add(t)}function lo(t){return!!io.has(t)&&(io.delete(t),!0)}let co=0;function uo(){co--}function fo(){return co>0}class ho{registry;entries=new Map;constructor(t){this.registry=t}wait(t,e,n=()=>{}){const o=t.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),t=>this.settle(o,t)));const r={active:!0,resolve:e,reject:n};return s.waiters.add(r),()=>{r.active&&(r.active=!1,s?.waiters.delete(r))}}pendingCount(t){return this.entries.get(t.toLowerCase())?.waiters.size??0}settle(t,e){const n=this.entries.get(t);if(void 0===n)return;this.entries.delete(t);const o=Array.from(n.waiters);n.waiters.clear();for(const t of o)t.active&&(t.active=!1,null===e?t.resolve():t.reject(e))}}const po=new WeakMap;function mo(t){let e=po.get(t);return void 0===e&&(e=new ho(t),po.set(t,e)),e}function go(t,e){let n=null;for(const o of t.propModifiers){const t=o.indexOf("=");if(t<0)continue;const s=o.slice(0,t).trim(),r=o.slice(t+1).trim();s!==c&&s!==d&&et(`Unknown binding modifier "${s}" in "${o}".`),s===e&&(null!==n&&et(`Binding modifier "${e}" may only be specified once.`),n=r)}return n}const yo=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),bo=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function wo(t,e){return"state"===t&&"call"===e?yo:{authority:t,syncOn:e,observable:!1,outputOnly:!1}}function vo(t){const e=null===(n=go(t,c))?null:"state"===n||"element"===n||"auto"===n||"none"===n?n:et(`Invalid init modifier value "${n}".`);var n;const o=function(t){return null===t||"call"===t?"call":"connect"===t?"connect":et(`Invalid sync modifier value "${t}".`)}(go(t,d));if("event"===t.bindingType)return null!==e&&"none"!==e&&et("Event bindings only allow init=none."),"call"===o?bo:{authority:"none",syncOn:o,observable:!1,outputOnly:!1};if(t.propSegments[0]===m)return wo("state",o);if("prop"!==t.bindingType)return null!==e&&"state"!==e&&"none"!==e&&et(`Binding type "${t.bindingType}" does not support init=${e}.`),wo(e??"state",o);const s=X(t.node);if(null===s)return wo(e??"state",o);const r=s.knownProperties.has(t.propName),i=s.declaredInputs.has(t.propName);r||i||et(`Property "${t.propName}" is not declared by wcBindable.`);const a=e??(r&&!i?"element":"state");return(r&&i?new Set(["state","element","auto","none"]):r?new Set(["element","none"]):new Set(["state","none"])).has(a)||et(`init=${a} is incompatible with wcBindable member "${t.propName}".`),"connect"!==o||r||et(`sync=connect requires observable property "${t.propName}".`),{authority:a,syncOn:o,observable:r,outputOnly:r&&!i}}function No(t,e){return"auto"!==e?e:function(t){const e=zr(t.replaceNode.getRootNode(),t.stateName);null===e&&et(`State element with name "${t.stateName}" not found for binding.`);const n=We(t);let o=!1;return e.createState("readonly",t=>{o=t[te](n)}),o}(t)?"state":"element"}let So=0,Io=0;const xo=new WeakMap,$o=new WeakMap,Po=new WeakMap,_o=new WeakMap;function Ao(t,e){const n=_o.get(t);void 0!==n?n!==e&&(n instanceof Set?n.add(e):_o.set(t,new Set([n,e]))):_o.set(t,e)}function ko(t,e){const n=_o.get(t);if(void 0!==n)if(n instanceof Set)for(const t of Array.from(n))e(t);else e(n)}function Co(t,e){if(e(t),null!==t.firstChild)for(const n of Array.from(t.childNodes))Co(n,e)}function Eo(t){if("object"!=typeof t||null===t)return!1;const e=t;return 9===e.nodeType||11===e.nodeType&&"host"in e}class Mo{root;observer;constructor(t){this.root=t;const e=globalThis.MutationObserver;this.observer="function"==typeof e?new e(t=>this.handleMutations(t)):null,this.observer?.observe(t,{childList:!0,subtree:!0})}handleMutations(t){const e=[],n=[];for(const o of t)e.push(...Array.from(o.removedNodes)),n.push(...Array.from(o.addedNodes));const o=[];for(const t of e)ro(t)||Co(t,t=>{ko(t,e=>{this.root.contains(t)||e.handleRemovedNode(t)})});for(const t of n)lo(t)&&!fo()||Co(t,t=>{ko(t,e=>{this.root.contains(t)&&e.handleAddedNode(t,o)})});o.length>0&&nr(o)}}const To=new WeakMap;function Oo(t){let e=To.get(t);return void 0===e&&(e=new Mo(t),To.set(t,e)),e}function Ro(t){const e=t.inFilters.map(t=>`${t.filterName}(${t.args.join(",")})`).join("|"),n=t.outFilters.map(t=>`${t.filterName}(${t.args.join(",")})`).join("|");return[t.bindingType,t.propName,t.propModifiers.join(","),t.stateName,t.statePathName,e,n,t.uuid??""].join("\0")}function Do(t,e){null===t.teardowns&&(t.teardowns=new Set),t.teardowns.add(e)}class Lo{records=new Set;rowPlan=null;knownBindingsByNode=new WeakMap;optionsByBinding=new WeakMap;deferredByNode=new WeakMap;deferred=new Set;constructor(t=null){null!==t&&this.observe(t)}initialize(t,e={},n){const o=e.registerAddress??!0,s={registerAddress:o,registerPathInfo:e.registerPathInfo??o,applyOnReconnect:e.applyOnReconnect??!0},r=[];for(const e of t){const t=this.remember(e,s),o=xo.get(t);void 0===o||"disposed"===o.phase||"failed"===o.phase?(this.start(t,s,n),r.push(t)):(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(t=>this.shouldApplyState(t))}activate(t,e){if(Eo(e)&&Oo(e),null===this.rowPlan)for(const n of t){const t=xo.get(n);if(void 0!==t&&t.session===this&&"disposed"!==t.phase&&"failed"!==t.phase){null===t.address&&null===t.patternListIndex&&(t.options.registerAddress=!0,this.registerAddress(t,e)),"active"===t.phase&&this.settleInitialRecord(t),this.settleConnectedSnapshot(t);continue}const o=this.optionsByBinding.get(n);void 0!==o?(o.registerAddress=!0,this.start(n,o,e)):this.initialize([n],{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1})}else this.activatePlanRows(this.rowPlan,t,e)}shouldApplyState(t){const e=xo.get(t);return void 0===e||e.session!==this||(!e.options.registerAddress||"waiting-definition"===e.phase||"failed"!==e.phase&&("active"===e.phase&&this.settleInitialRecord(e),e.initialApplyDone?"state"===e.resolvedAuthority||!e.outputOnlyMember&&!e.observationPending:(e.initialApplyDone=!0,"state"===e.resolvedAuthority)))}getRecord(t){const e=xo.get(t);return e?.session===this?e:null}addTeardown(t,e){const n=xo.get(t);return!(void 0===n||!this.isAlive(n,n.generation))&&(Do(n,e),!0)}deferUntilDefined(t,e,n,o=()=>{}){const s=K();null===s&&et(`CustomElementRegistry is unavailable for <${e}>.`),this.observe(t),Ao(t,this);const r={node:t,active:!0,cancel:null};let i=this.deferredByNode.get(t);void 0===i&&(i=new Set,this.deferredByNode.set(t,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=mo(s).wait(e,()=>{if(a())try{J(s,t),n()}catch(t){o(t)}},t=>{a()&&o(t)}),()=>{a()&&r.cancel?.()}}disposeBinding(t){const e=xo.get(t);void 0!==e&&e.session===this&&this.disposeRecord(e)}dispose(){for(const t of Array.from(this.records))this.disposeRecord(t);for(const t of Array.from(this.deferred))t.active=!1,t.cancel?.(),this.deferred.delete(t),this.deferredByNode.get(t.node)?.delete(t)}canWholesaleDestroy(){if(this.deferred.size>0)return!1;for(const t of this.records)if(t.pendingDefinitions>0||t.observationPending)return!1;return!0}destroyRecords(){for(const t of this.records)null!==t.address&&(Ae(t.address,t.info),t.address=null),t.phase="disposed",t.teardowns=null;this.records.clear()}observe(t){const e=function(t){const e=t.getRootNode();return Eo(e)?e:null}(t);null!==e&&Oo(e)}handleMutations(t,e,n){for(const n of e)Co(n,e=>{t.contains(e)||this.handleRemovedNode(e)});const o=[];for(const e of n)Co(e,e=>{t.contains(e)&&this.handleAddedNode(e,o)});o.length>0&&nr(o)}handleRemovedNode(t){const e=this.knownBindingsByNode.get(t);if(void 0!==e)if(e instanceof Map)for(const t of e.values())this.disposeBinding(t);else this.disposeBinding(e);const n=this.deferredByNode.get(t);if(void 0!==n)for(const t of Array.from(n))t.active=!1,t.cancel?.(),n.delete(t),this.deferred.delete(t)}handleAddedNode(t,e){const n=this.knownBindingsByNode.get(t);if(void 0===n)return;const o=n instanceof Map?n.values():[n];for(const t of o){const n=xo.get(t);if("active"===n?.phase){this.settleConnectedSnapshot(n);continue}if("disposed"!==n?.phase)continue;const o=this.optionsByBinding.get(t);if(void 0!==o)try{this.start(t,o),o.applyOnReconnect&&this.shouldApplyState(t)&&e.push(t)}catch{}}}knownMapFor(t){const e=this.knownBindingsByNode.get(t);if(e instanceof Map)return e;const n=new Map;if(void 0!==e){let t=Po.get(e);void 0===t&&(t=Ro(e),Po.set(e,t)),n.set(t,e)}return this.knownBindingsByNode.set(t,n),n}remember(t,e){const n=t.replaceNode;Ao(n,this);const o=this.knownMapFor(n);let s=Po.get(t);void 0===s&&(s=Ro(t),Po.set(t,s));const r=o.get(s);if(void 0!==r){const t=this.optionsByBinding.get(r);return void 0!==t&&(t.registerAddress||=e.registerAddress,t.registerPathInfo||=e.registerPathInfo,t.applyOnReconnect||=e.applyOnReconnect),r}return o.set(s,t),this.optionsByBinding.set(t,{...e}),t}initializeRow(t,e){this.rowPlan=t;const n={registerAddress:!1,registerPathInfo:!1,applyOnReconnect:!1},o=t.slots;for(let t=0;t<e.length;t++){const s=e[t],r=o[t],i=s.replaceNode;Ao(i,this),this.addKnownRowBinding(i,s,t),this.optionsByBinding.set(s,n);const a={id:++So,info:s,generation:++Io,phase:"active",teardowns:null,session:this,anchor:i,options:n,address:null,patternPathInfo:null,patternListIndex:null,outerPatternPathInfo:null,outerPatternPathInfosRest: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(xo.set(s,a),this.records.add(a),r.isEvent){try{ln(s)}catch(t){throw a.phase="failed",this.runTeardowns(a),this.records.delete(a),t}a.eventAttached=!0}}}activatePlanRows(t,e,n){const o=t.slots;for(let t=0;t<e.length;t++){const s=e[t],r=xo.get(s);if(void 0!==r&&r.session===this){if(r.options.registerAddress=!0,"disposed"===r.phase||"failed"===r.phase){const e=o[t];if(r.generation=++Io,r.phase="active",r.initialPolicy=e.policy,r.resolvedAuthority=e.authority,r.initialSettled=!0,r.initialApplyDone=!1,r.outputOnlyMember=e.policy.outputOnly,this.records.add(r),e.isEvent){try{ln(s)}catch(t){throw r.phase="failed",this.runTeardowns(r),this.records.delete(r),t}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(t,e,n){const o=this.knownBindingsByNode.get(t);if(void 0===o)return void this.knownBindingsByNode.set(t,e);if(o instanceof Map)return void o.set("@plan:"+n,e);const s=new Map;s.set("@plan:first",o),s.set("@plan:"+n,e),this.knownBindingsByNode.set(t,s)}start(t,e,n){!function(t){const e=t.node,n=t.replaceNode;e!==n&&null!==e.parentNode&&e.parentNode.replaceChild(n,e)}(t);const o=this.optionsByBinding.get(t)??{...e},s={id:++So,info:t,generation:++Io,phase:"discovered",teardowns:null,session:this,anchor:t.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,outerPatternPathInfo:null,outerPatternPathInfosRest: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};xo.set(t,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(t){throw s.phase="failed",this.runTeardowns(s),this.records.delete(s),t}}attachListeners(t){const e=t.info;ln(e)?t.eventAttached=!0:e.propSegments[0]!==p?(hn(e)&&Do(t,()=>function(t){if("radio"===t.bindingType&&-1===t.propModifiers.indexOf(l)){const e=fn(t),n=un(t,e),o=cn.get(n);return void 0!==o&&(t.node.removeEventListener(e,o),0!==dn.countOf(n)&&(dn.remove(n,t)&&cn.delete(n),!0))}return!1}(e)),He(e)&&Do(t,()=>function(t){if("checkbox"===t.bindingType&&-1===t.propModifiers.indexOf(l)){const e=Ue(t),n=qe(t,e),o=Fe.get(n);return void 0!==o&&(t.node.removeEventListener(e,o),0!==ze.countOf(n)&&(ze.remove(n,t)&&Fe.delete(n),!0))}return!1}(e)),this.attachAfterDefinition(t,()=>{if(gn(e.node,e.propName)&&-1===e.propModifiers.indexOf(l)){const n=function(t,e,n){let o=Tn.get(t);void 0===o&&(o=new Map,Tn.set(t,o));let s=o.get(e);return void 0===s&&(s=new Set,o.set(e,s)),s.add(n),()=>{s?.delete(n),0===s?.size&&o?.delete(e),0===o?.size&&Tn.delete(t)}}(e.node,e.propName,e=>{this.isAlive(t,t.generation)&&(t.eventSequence+=1,t.hasProducerValue=!0,t.producerValue=e)});Do(t,n)}!function(t){const e=G(t.node);if(null!==e){const t=K(),n=t?.get(e);if(void 0===n)return void(null===t&&et(`CustomElementRegistry is unavailable for <${e}>.`))}if(gn(t.node,t.propName)&&-1===t.propModifiers.indexOf(l)){const e=Dn(t),n=Ln(t),o=Wn(t),s=Rn(t,e,null!==n,o);let r=En.get(s);void 0===r&&(r=jn(t.stateName,t.propName,t.statePathName,t.inFilters,n,o),En.set(s,r)),t.node.addEventListener(e,r),Mn.add(s,t)}}(e),t.twowayAttached=!0})):this.attachAfterDefinition(t,()=>{tn(e)&&Do(t,()=>function(t){if(t.propSegments[0]!==p)return!1;const e=Ze.get(t);return void 0!==e&&(t.node.removeEventListener(e.eventName,e.handler),Ze.delete(t),!0)}(e))})}attachAfterDefinition(t,e){const n=G(t.info.node);if(null===n)return void e();const o=K();if(null===o&&et(`CustomElementRegistry is unavailable for <${n}>.`),void 0!==o.get(n))return void e();t.phase="waiting-definition",t.pendingDefinitions+=1;const s=t.generation,r=mo(o).wait(n,()=>{if(this.isAlive(t,s))try{J(o,t.info.node),e(),t.pendingDefinitions-=1,0===t.pendingDefinitions&&(t.phase="active",this.settleInitialRecord(t))}catch{t.phase="failed",this.runTeardowns(t),this.records.delete(t)}},()=>{this.isAlive(t,s)&&(t.phase="failed",this.runTeardowns(t),this.records.delete(t))});Do(t,r)}settleInitialRecord(t){if(!t.initialSettled&&t.options.registerAddress){t.phase="synchronizing";try{const e=vo(t.info),n=No(t.info,e.authority);if(t.initialPolicy=e,t.resolvedAuthority=n,t.initialSettled=!0,t.outputOnlyMember=e.outputOnly,t.phase="active",!e.observable)return;if("connect"===e.syncOn&&t.info.node instanceof HTMLElement&&!t.info.node.isConnected)return t.observationPending=!0,void co++;this.readProducerSnapshot(t,"call"===e.syncOn)}catch(e){throw t.phase="failed",this.runTeardowns(t),this.records.delete(t),e}}}readProducerSnapshot(t,e){if(!this.isAlive(t,t.generation))return;const n=t.info.node,o=t.info.propName;if(!(o in n))return;const s=t.eventSequence,r=n[o];t.observationPending&&(t.observationPending=!1,uo()),e&&t.eventSequence!==s||(t.hasProducerValue=!0,t.producerValue=r,"element"===t.resolvedAuthority&&function(t,e){let n=e;for(const e of t.inFilters)n=e.filterFn(n);const o=zr(t.node.getRootNode(),t.stateName);null===o&&et(`State element with name "${t.stateName}" not found for initial binding sync.`);const s=Gt(t.node);o.createState("writable",e=>{e[Qt](s,()=>{e[t.statePathName]=n})})}(t.info,r))}settleConnectedSnapshot(t){if(t.observationPending&&t.info.node instanceof HTMLElement&&t.info.node.isConnected)try{this.readProducerSnapshot(t,!1)}catch{t.phase="failed",this.runTeardowns(t),this.records.delete(t)}}registerAddress(t,e){if(null!==t.address||null!==t.patternListIndex)return;const n=t.info,o=ve(n);if(null!==o){const i=zr(Se(n,e),n.stateName);null===i&&et(`State element with name "${n.stateName}" not found for binding.`);const a=ie(i,n.statePathInfo);Ce(a,o,n),t.patternPathInfo=a,t.patternListIndex=o;const l=(s=i,0===(r=n.statePathInfo).wildcardCount?null:eo(s,r));if(null!==l){Ce(l,o,n),t.outerPatternPathInfo=l;const e=function(t){let e=null,n=t.stateElement,o=t.pathInfo;for(;;){const t=eo(n,o);if(null===t)return e;(e??=[]).push(t),n=t.stateElement,o=t.pathInfo}}(l);if(null!==e){for(let t=0;t<e.length;t++)Ce(e[t],o,n);t.outerPatternPathInfosRest=e}}}else{const o=Ie(n,e);_e(o,n),t.address=o}var s,r;if(!t.options.registerPathInfo)return;const i=zr(n.replaceNode.getRootNode(),n.stateName);null===i&&et(`State element with name "${n.stateName}" not found for binding.`),"event"!==n.bindingType&&i.setPathInfo(n.statePathName,n.bindingType)}isAlive(t,e){return t.generation===e&&xo.get(t.info)===t&&"disposed"!==t.phase&&"failed"!==t.phase}disposeRecord(t){"disposed"!==t.phase&&(t.phase="disposed",this.runTeardowns(t),this.records.delete(t))}runTeardowns(t){t.observationPending&&(t.observationPending=!1,uo());const e=t.info;if(null!==t.address)try{Ae(t.address,e),t.address=null,je(e),xe(e)}catch{}else if(null!==t.patternListIndex){if(null!==t.outerPatternPathInfo){try{Ee(t.outerPatternPathInfo,t.patternListIndex,e)}catch{}t.outerPatternPathInfo=null}if(null!==t.outerPatternPathInfosRest){const n=t.outerPatternPathInfosRest;for(let o=0;o<n.length;o++)try{Ee(n[o],t.patternListIndex,e)}catch{}t.outerPatternPathInfosRest=null}try{Ee(t.patternPathInfo,t.patternListIndex,e),t.patternPathInfo=null,t.patternListIndex=null,je(e),xe(e)}catch{}}if(t.twowayAttached){t.twowayAttached=!1;try{!function(t){const e=G(t.node);if(null!==e){const t=K(),n=t?.get(e);if(void 0===n)return}if(gn(t.node,t.propName)&&-1===t.propModifiers.indexOf(l)){const e=Dn(t),n=Rn(t,e,null!==Ln(t),Wn(t)),o=En.get(n);if(void 0===o)return;t.node.removeEventListener(e,o),Mn.remove(n,t)&&En.delete(n)}}(e)}catch{}}if(null!==t.teardowns){const e=Array.from(t.teardowns).reverse();t.teardowns=null;for(const t of e)try{t()}catch{}}if(t.eventAttached){t.eventAttached=!1;try{!function(t){if(!t.propName.startsWith(h))return!1;const e=rn(t),n=on.get(e);if(void 0===n)return!1;const o=t.propName.slice(2);t.node.removeEventListener(o,n),0!==sn.countOf(e)&&(sn.remove(e,t)&&on.delete(e))}(e)}catch{}}}}function Wo(t){let e=$o.get(t);return void 0===e&&(e=new Lo(t),$o.set(t,e)),e}function jo(t){return xo.get(t)?.session??null}const Bo=new WeakMap;function Fo(t,e){let n=t;for(const t of e)n=t.filterFn(n);return n}const zo=Object.freeze([]);const qo=new WeakMap;const Uo=new WeakMap;function Ho(t){return Uo.get(t)??[]}function Vo(t,e){Uo.set(t,e)}Set.prototype.difference||(Set.prototype.difference=function(t){const e=new Set(this);for(const n of t)e.delete(n);return e}),Set.prototype.intersection||(Set.prototype.intersection=function(t){const e=new Set;for(const n of t)this.has(n)&&e.add(n);return e});let Go=0;function Ko(){return`u${(Go++).toString(36)}`}let Jo=0;class Xo{uuid=Ko();parentListIndex;position;length;_index;_version;_indexes;_listIndexes;constructor(t,e){this.parentListIndex=t,this.position=t?t.position+1:0,this.length=this.position+1,this._index=e,this._version=Jo}get index(){return this._index}set index(t){this._index=t,this._version=++Jo,this.indexes[this.position]=t}get version(){return this._version}get dirty(){return null!==this.parentListIndex&&(this.parentListIndex.dirty||this.parentListIndex.version>this._version)}get indexes(){return null===this.parentListIndex?void 0===this._indexes&&(this._indexes=[this._index]):(void 0===this._indexes||this.dirty)&&(this._indexes=[...this.parentListIndex.indexes,this._index],this._version=Jo),this._indexes}get listIndexes(){return null===this.parentListIndex?void 0===this._listIndexes&&(this._listIndexes=[new WeakRef(this)]):void 0===this._listIndexes&&(this._listIndexes=[...this.parentListIndex.listIndexes,new WeakRef(this)]),this._listIndexes}get varName(){return`$${this.position+1}`}at(t){return t>=0?this.listIndexes[t]?.deref()||null:this.listIndexes[this.listIndexes.length+t]?.deref()||null}}function Yo(t,e){return new Xo(t,e)}const Qo=new WeakMap;function Zo(t){return Qo.get(t)||null}function ts(t,e){null!==e?Qo.set(t,e):Qo.delete(t)}const es=new WeakMap,ns=Object.freeze([]),os=new Set;function ss(t,e,n){const o=function(t,e,n){const o=Array.isArray(e)&&e.length>0?e:ns,s=Array.isArray(n)&&n.length>0?n:ns,r=function(t,e){const n=Array.isArray(t)&&t.length>0?t:ns,o=Array.isArray(e)&&e.length>0?e:ns;let s=es.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=Zo(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:os,deleteIndexSet:new Set(i),addIndexSet:os};let e=Zo(s);if(0===o.length){if(null===e){e=[];for(let n=0;n<s.length;n++){const o=Yo(t,n);e.push(o)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:os,deleteIndexSet:os,addIndexSet:new Set(e)}}if(function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}(o,s))return a={oldIndexes:i,newIndexes:i,changeIndexSet:os,deleteIndexSet:os,addIndexSet:os};if(null!==e)return function(t,e){const n=new Set(e),o=new Set(t),s=new Set,r=n.difference(o),i=o.difference(n),a=new Map;for(let e=0;e<t.length;e++)a.set(t[e],e);for(let t=0;t<e.length;t++){const n=e[t];r.has(n)||a.get(n)!==t&&s.add(n)}return{oldIndexes:t,newIndexes:e,changeIndexSet:s,deleteIndexSet:i,addIndexSet:r}}(i,e);e=[];const n=new Map;for(let t=0;t<o.length;t++){const e=o[t];let s=n.get(e);s||(s=[],n.set(e,s)),s.push(t)}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=Yo(t,o);e.push(n),l.add(n)}else{const t=i[d];d!==o&&r.add(t),e.push(t)}}return a={oldIndexes:i,newIndexes:e,changeIndexSet:r,deleteIndexSet:new Set(i).difference(new Set(e)),addIndexSet:l}}finally{void 0!==a&&(!function(t,e,n){let o=es.get(t);o||(o=new WeakMap,es.set(t,o)),o.set(e,n)}(o,s,a),ts(s,a.newIndexes))}}(t,e,n);return function(t){for(let e=0;e<t.length;e++)t[e].index!==e&&(t[e].index=e)}(o.newIndexes),o}function rs(t){if(0===t.changeIndexSet.size||t.addIndexSet.size===t.newIndexes.length)return null;const e=new Map;for(let n=0;n<t.oldIndexes.length;n++)e.set(t.oldIndexes[n],n);const n=[],o=[];let s=-1,r=!0;for(const i of t.newIndexes){if(t.addIndexSet.has(i))continue;const a=e.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(t){const e=t.length,n=[],o=new Array(e).fill(-1);for(let s=0;s<e;s++){const e=t[s];let r=0,i=n.length;for(;r<i;){const o=r+i>>1;t[n[o]]<e?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 t of i)a.add(n[t]);return a}const is=new WeakMap;function as(t){return is.get(t)??[]}function ls(t,e){is.set(t,e)}const cs=new WeakMap;function ds(t){return cs.get(t)??null}function us(t,e){cs.set(t,e)}const fs=new WeakMap;function hs(t){return fs.get(t)??[]}function ps(t,e){fs.set(t,e)}function ms(t,e){const n=hs(t);for(const t of n)Kt(t,e)}function gs(t,e,n){ms(t,e);const o=as(t),s=ds(t);null!==s&&s.activate(o,n.rootNode);for(const t of o){if(null===s){_e(Ie(t),t)}(null===s||s.shouldApplyState(t))&&er(t,n)}}function ys(t){if(!t.mounted)return;const e=as(t),n=ds(t);for(const t of e)if(null!==n)n.disposeBinding(t);else{Ae(Ie(t),t)}!function(t){const e=hs(t);for(const t of e)Kt(t,null)}(t)}const bs=new WeakMap,ws=Object.freeze(new Set);function vs(t,e){const n=bs.get(t);n?n.add(e):bs.set(t,new Set([e]))}function Ns(t){const e=bs.get(t);return void 0!==e?e:ws}function Ss(t,e){const n=bs.get(t);n&&(n.delete(e),0===n.size&&bs.delete(t))}const Is=new Set(["if","elseif","else","for"]);class xs{_content;_childNodeArray=[];_firstNode=null;_lastNode=null;_mounted=!1;_ranged=!1;constructor(t,e=!1){this._content=t,this._ranged=e,this._childNodeArray=Array.from(this._content.childNodes),this._firstNode=this._childNodeArray.length>0?this._childNodeArray[0]:null,this._lastNode=this._childNodeArray.length>0?this._childNodeArray[this._childNodeArray.length-1]:null}get firstNode(){return this._firstNode}get lastNode(){return this._lastNode}get mounted(){return this._mounted}appendTo(t){for(const e of this._childNodeArray)ao(e),t.appendChild(e);this._mounted=!0}_movableNodes(){if(!this._ranged||!this._mounted)return this._childNodeArray;const t=this._firstNode,e=this._lastNode;if(null===t||null===e||null===t.parentNode)return this._childNodeArray;const n=[];for(let o=t;null!==o;o=o.nextSibling)if(n.push(o),o===e)return n;return this._childNodeArray}mountAfter(t){const e=t.parentNode;if(e){let n=t;for(const t of this._movableNodes())n.nextSibling!==t&&(ao(t),e.insertBefore(t,n.nextSibling)),n=t}this._mounted=!0}tryDestroy(){const t=ds(this);if(null===t||!t.canWholesaleDestroy())return!1;t.destroyRecords();for(const t of this._childNodeArray)so(t),null!==t.parentNode&&t.parentNode.removeChild(t);const e=as(this);for(const t of e)if(Is.has(t.bindingType)){const e=Ns(t.node);for(const t of e)t.tryDestroy()||t.unmount()}return this._mounted=!1,!0}unmount(){ds(this)?.dispose();for(const t of this._childNodeArray)so(t),null!==t.parentNode&&t.parentNode.removeChild(t);const t=as(this);for(const e of t){if(Is.has(e.bindingType)){const t=Ns(e.node);for(const e of t)e.unmount()}je(e),xe(e)}this._mounted=!1}}function $s(t){let n=t.topLevelStructural;return void 0===n&&(n=t.topLevelStructural=function(t){const n=new RegExp(`^@@(?:${e.commentForPrefix}|${e.commentIfPrefix}|${e.commentElseIfPrefix}|${e.commentElsePrefix}):`);for(let e=t.firstChild;null!==e;e=e.nextSibling)if(e.nodeType===Node.COMMENT_NODE&&n.test(e.data))return!0;return!1}(t.fragment)),n}function Ps(t){const e=document.createDocumentFragment(),n=new xs(e);return n._childNodeArray=t,n._firstNode=t.length>0?t[0]:null,n._lastNode=t.length>0?t[t.length-1]:null,n._mounted=!0,n}function _s(t,e,n){const o=document.importNode(e.fragment,!0),s=e.nodeInfos,r=new Array(s.length);for(let t=0;t<s.length;t++){const e=rt(o,s[t].nodePath);null===e&&et(`Node not found by path [${s[t].nodePath.join(", ")}] in fragment.`),Ut(e),F(e),r[t]=e}const i=n.slots,a=new Array(i.length),l=[];for(let t=0;t<i.length;t++){const e=i[t],n=r[e.nodeIndex],o={...e.template,node:n,replaceNode:n};a[t]=o,e.isIndexBinding&&l.push(o)}const c=function(t,e){const n=new Lo;return n.initializeRow(t,e),n}(n,a),d=new xs(o);return us(d,c),ls(d,a),Vo(d,l),ps(d,r),vs(t.node,d),d}function As(n){void 0!==n.uuid&&null!==n.uuid||et("BindingInfo.uuid is null.");const o=Rt(n.uuid);o||et(`Fragment with UUID "${n.uuid}" not found.`);const s=!t()&&$s(o);let r=o.rowPlan;if((void 0===r||null!==r&&r.directional!==e.enableDirectionalInitialSync)&&(r=o.rowPlan=function(t){const n=e.enableDirectionalInitialSync,o=[],s=t.nodeInfos;for(let e=0;e<s.length;e++){const n=s[e],r=rt(t.fragment,n.nodePath);if(null===r)return null;for(const t of n.parseBindTextResults){const n=t.bindingType;if("text"!==n&&"prop"!==n&&"event"!==n)return null;const s=t.propSegments[0];if(s===m||s===p)return null;if("text"===n){if(r.nodeType!==Node.TEXT_NODE)return null}else if(null!==G(r))return null;if("prop"===n&&gn(r,t.propName))return null;let i;try{i=vo({...t,node:r,replaceNode:r})}catch{return null}if(i.observable||"auto"===i.authority)return null;o.push({nodeIndex:e,template:t,isEvent:"event"===n,isIndexBinding:t.statePathName in v,policy:i,authority:i.authority})}}return{directional:n,slots:o}}(o)),null!==r)return _s(n,o,r);const i=document.importNode(o.fragment,!0),a=function(t,e){const[n,o]=function(t,e){const n=[],o=[];for(const s of e){const e=rt(t,s.nodePath);if(null===e&&et(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),Ft.has(e))continue;const r=zt(e,s.parseBindTextResults,{allowDeferred:!1});o.push(...r.bindings),n.push(e)}return[n,o]}(t,e),s=new Lo,r=s.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:r,bindingSession:s}}(i,o.nodeInfos);s&&function(t,e){t.appendChild(document.createComment(`wcs-row-end:${e}`))}(i,n.uuid);const l=new xs(i,s);us(l,a.bindingSession),ls(l,a.bindingInfos);const c=[];for(const t of a.bindingInfos)t.statePathName in v&&c.push(t);return Vo(l,c),ps(l,a.nodes),vs(n.node,l),l}const ks=new WeakMap,Cs=new WeakMap,Es=new WeakMap,Ms=new WeakMap;function Ts(t,e,n){!function(t,e,n){let o=Cs.get(t);if(void 0===o){if(null===n)return;o=new WeakMap,Cs.set(t,o)}null===n?o.delete(e):o.set(e,n)}(t,e,n)}function Os(t,e){ks.set(t,e)}function Rs(t,e){let n=Es.get(t.node);void 0===n&&(n=[],Es.set(t.node,n)),n.length<1e3?n.push(e):Ss(t.node,e)}function Ds(t,e){if(null===e)return!1;if(t.nextSibling===e)return!0;const n=t.compareDocumentPosition(e);return 0!==(n&Node.DOCUMENT_POSITION_FOLLOWING)&&0===(n&Node.DOCUMENT_POSITION_DISCONNECTED)}function Ls(e,n,o){const s=Boolean(o);let r;const i=Ns(e.node);r=0===i.size?As(e):i.values().next().value;const a=t(),l=e.uuid??"",c=e.bindingType;if(s||(ys(r),r.unmount()),s){if(a){const t=document.createComment(`@@wcs-${c}-start:${l}:${e.statePathName}`);e.node.parentNode.insertBefore(t,e.node.nextSibling),r.mountAfter(t);const n=document.createComment(`@@wcs-${c}-end:${l}:${e.statePathName}`),o=r.lastNode??t;o.parentNode.insertBefore(n,o.nextSibling)}else r.mountAfter(e.node);gs(r,Gt(e.node),n)}}const Ws=new WeakMap;function js(t){return Ws.get(t)??[]}const Bs=new Set;const Fs={value(t,e){"TEXTAREA"===t.tagName?t.textContent=String(e??""):t.setAttribute("value",String(e??""))},checked(t,e){e?t.setAttribute("checked",""):t.removeAttribute("checked")},selected(t,e){e?t.setAttribute("selected",""):t.removeAttribute("selected")},disabled(t,e){e?t.setAttribute("disabled",""):t.removeAttribute("disabled")},selectedIndex(t,e){const n=t.querySelectorAll("option"),o=Number(e);for(let t=0;t<n.length;t++)t===o?n[t].setAttribute("selected",""):n[t].removeAttribute("selected")}};function zs(e,n,o){if(void 0===o)return;const s=e.node,r=e.propSegments;if(1===r.length){const a=r[0];if(s[a]!==o){const t=()=>{let t=!1;try{s[a]=o,t=!0}catch(t){}if(t){const t=function(t,e){const n=G(t);if(null===n)return null;const o=K()?.get(n);if(void 0===o)return null;const s=X(t)?.declaredInputs.get(e);return"string"==typeof s?.attribute&&s.attribute.length>0?s.attribute:null}(s,a);if(null!==t)try{!function(t,e,n){if(null==n)return void t.removeAttribute(e);let o;if("object"==typeof n)try{o=JSON.stringify(n)}catch{o=String(n)}else o=String(n);t.setAttribute(e,o)}(s,t,o)}catch(t){}}};if(gn(s,a)){const r=Nn(s,a,e.stateName,e.statePathName),i=Sn(r,"to-element"),l=n?.propagationContextByBinding?.get(e)??_n()??xn(r);if(l.visitedEdges.has(i))null!==$e&&$e({type:"propagation:suppressed",reason:"visited-edge",transactionId:l.transactionId,edgeId:i,node:s,member:a});else{const e=$n(l,i);An(e,()=>function(t,e,n,o,s,r){const i={bindingId:o,bindingGeneration:0,member:e,transactionId:s,synchronousScopeId:wn++,writtenValue:n};kn.push({receipt:i,node:t});try{return r()}finally{kn.pop()}}(s,a,o,r,e.transactionId,t))}}else t()}if(t()){const t=Fs[a];t?t(s,o):(!function(t,e,n){let o=Ws.get(t);o||(o=[],Ws.set(t,o));const s=o.find(t=>t.propName===e);s?s.value=n:o.push({propName:e,value:n})}(s,a,o),i=s,Bs.add(i))}return}var i;const a=r[0];let l=s[a];for(let t=1;t<r.length-1;t++){const e=r[t];if(null==l)return;l=l[e]}if(l[r[r.length-1]]!==o){if(Object.isFrozen(l))return;try{l[r[r.length-1]]=o}catch(t){}}}const qs=new WeakSet;function Us(t,e,o){const s=t.node,r=t.propSegments;r.length<=1&&et(`Invalid propSegments for web component binding: ${r.join(n)}`);const[i,...a]=r,l=Fn(s,i);null===l&&et(`State element not bound to "${i}" on web component.`),!1!==l.hasRootNode&&l.createState("readonly",t=>{t.$postUpdate(a.join(n))})}function Hs(t,e){const n=We(e);if(n.pathInfo.path in v){const t=Gt(e.node);return null===t&&et(`ListIndex not found for binding: ${e.statePathName}`),function(t,e){null===t.listIndex&&et("ListIndex not found for loopContext:");const n=v[e];void 0===n&&et(`Invalid index name: ${e}`);const o=ye(t.listIndex,n,t.pathInfo.wildcardCount);return null===o&&et(`Index not found at position ${n} for loopContext:`),o.index}(t,n.pathInfo.path)}return t[Zt](n)}const Vs=new WeakSet;function Gs(t,e){console.error(`[@wcstack/state] deferred apply failed for <${t}>.`,e)}const Ks=Object.freeze({[g]:function(t,e,n){const o=t.node,s=t.propSegments[1];"boolean"!=typeof n&&et("Invalid value for class application: expected boolean, got "+typeof n),o.classList.toggle(s,n)},[y]:function(t,e,n){const o=t.node,s=t.propSegments[1];o.getAttribute(s)!==n&&o.setAttribute(s,n)},[b]:function(t,e,n){const o=t.propSegments[1],s=t.node.style;s[o]!==n&&(s[o]=n)},[m]:function(t,e,n){nn(n)||et("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=qo.get(t);if(s&&s.token===o)return;const r=t.node,i=t.propSegments[1];"string"==typeof i&&0!==i.length||et('command binding requires a method name (e.g., "command.fetch").');const a=function(t){const e=G(t);if(null===e)return null;const n=K()?.get(e);return void 0===n&&et(`Custom element <${e}> is not defined for command binding.`),X(t)}(r);null===a&&et(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(i)||et(`Command "${i}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.${lt(i,a.declaredCommands.keys())}`),s&&(s.unsubscribe(),qo.delete(t));const l=new WeakRef(r);let c=null;c=o.subscribe((...e)=>{const n=l.deref();if(!n||!n.isConnected)return c?.(),void qo.delete(t);const o=n[i];return"function"!=typeof o&&et(`Method "${i}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,e)}),qo.set(t,{token:o,unsubscribe:c,elementRef:l})}}),Js={text:function(e,n,o){const s=null==o?"":String(o);if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),t()&&!qs.has(e.replaceNode)){qs.add(e.replaceNode);const t=e.replaceNode.parentNode;if(t){const n=e.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);t.insertBefore(o,e.replaceNode),t.insertBefore(s,e.replaceNode.nextSibling)}}},for:function(e,n,s){const r=e.statePathInfo,i=ve(e),a=Ie(e),l=Xt(a),c=ss(Kn(n.stateElement,i),l,s);n.newListValueByAbsAddress.set(a,Array.isArray(s)?s:[]);const d=Array.isArray(l)&&l.length===c.deleteIndexSet.size&&c.deleteIndexSet.size>0;if(d&&null!==e.node.parentNode){let t=Ms.get(e.node);if(void 0===t){const n=ks.get(e.node)||e.node;t=function(t,e){let n=t.previousSibling,o=e.nextSibling,s=!0;for(;null!==n;){if(n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&""!==(n.textContent?.trim()??"")){s=!1;break}n=n.previousSibling}for(;null!==o;){if(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE&&""!==(o.textContent?.trim()??"")){s=!1;break}o=o.nextSibling}return s}(e.node,n),Ms.set(e.node,t)}if(t){const t=e.node.parentNode;t.textContent="",t.appendChild(e.node)}}let u=Cs.get(e.node),f=d?1e3-function(t){return Es.get(t.node)||[]}(e).length:Number.POSITIVE_INFINITY;if(void 0!==u){for(const t of c.deleteIndexSet){const n=u.get(t);void 0!==n&&(f<=0&&n.tryDestroy()?Ss(e.node,n):(ys(n),n.unmount(),Rs(e,n),f-=1),d||u.delete(t))}d&&(Cs.delete(e.node),u=void 0)}let h=e.node;const p=U(r.path+"."+o),m=n.stateElement.loopContextStack,g=rs(c);let y=null;c.newIndexes.length==c.addIndexSet.size&&c.newIndexes.length>0&&h.isConnected&&(y=document.createDocumentFragment(),he(y,n.rootNode));const b=t(),w=e.uuid??"",v=Es.get(e.node);for(const t of c.newIndexes){let o;if(c.addIndexSet.has(t)){const s=De(p,t);m.createLoopContext(s,s=>{if(o=void 0!==v?v.pop():void 0,void 0===o&&(o=As(e)),null!==y)b&&y.appendChild(document.createComment(`@@wcs-for-start:${w}:${r.path}:${t.index}`)),o.appendTo(y),b&&y.appendChild(document.createComment(`@@wcs-for-end:${w}:${r.path}:${t.index}`));else{if(h.nextSibling!==o.firstNode){if(b){const e=document.createComment(`@@wcs-for-start:${w}:${r.path}:${t.index}`);h.parentNode.insertBefore(e,h.nextSibling),h=e}o.mountAfter(h)}if(b){const e=document.createComment(`@@wcs-for-end:${w}:${r.path}:${t.index}`),n=o.lastNode??h;n.parentNode.insertBefore(e,n.nextSibling)}}gs(o,s,n)}),void 0===o&&et(`Content not found for ListIndex: ${t.index} at path "${r.path}"`)}else{if(o=void 0!==u?u.get(t)??null:null,c.changeIndexSet.has(t)){const t=Ho(o);for(const e of t)er(e,n)}null===o&&et(`Content not found for ListIndex: ${t.index} at path "${r.path}"`);const e=!o.mounted;if(null!==g&&g.has(t)&&Ds(h,o.firstNode)||h.nextSibling===o.firstNode||o.mountAfter(h),e){const e=o,s=De(p,t);m.createLoopContext(s,t=>{gs(e,t,n)})}}h=o.lastNode||h,void 0===u&&(u=new WeakMap,Cs.set(e.node,u)),u.set(t,o)}ks.set(e.node,h),null!==y&&(e.node.parentNode.insertBefore(y,e.node.nextSibling),he(y,null))},if:Ls,else:Ls,elseif:Ls,radio:function(t,e,n){const o=t.node,s=Fo(o.value,t.inFilters);o.checked=n===s},checkbox:function(t,e,n){const o=t.node,s=Fo(o.value,t.inFilters),r=Array.isArray(n)?n:zo;o.checked=r.includes(s)}},Xs=new WeakMap,Ys=new WeakMap,Qs=new WeakMap;function Zs(t){return t.propSegments.length>1&&(e=t.replaceNode,n=t.propSegments[0],!0===Bo.get(e)?.has(n));var e,n}function tr(t,e){const n=Fo(Hs(e.state,t),t.outFilters);if(!0===Ys.get(t))return void e.deferredSelectBindings.push({binding:t,value:n});let o=Xs.get(t);if(void 0===o){if(Xs.has(t))return Zs(t)?(o=Us,Xs.set(t,o)):o=zs,void o(t,e,n);if(o=Js[t.bindingType],void 0===o){const e=t.propSegments[0];if(o=Ks[e],Xs.set(t,o),void 0===o){G(t.replaceNode)?Zs(t)?(o=Us,Xs.set(t,o)):o=zs:(o=zs,Xs.set(t,o))}}if(o===zs){if("SELECT"===t.node.tagName){const o=t.propSegments[0];if("value"===o||"selectedIndex"===o)return e.deferredSelectBindings.push({binding:t,value:n}),void Ys.set(t,!0)}}o(t,e,n)}else o(t,e,n)}function er(t,e){if(e.appliedBindingSet.has(t))return;if(e.appliedBindingSet.add(t),!1!==e.stateElement.hasUpdatedCallback){const n=Ie(t);if(e.updatedAbsAddressSetByStateElement.has(e.stateElement)){e.updatedAbsAddressSetByStateElement.get(e.stateElement).add(n)}else e.updatedAbsAddressSetByStateElement.set(e.stateElement,new Set([n]))}const n=jo(t);if(null!==n&&!n.shouldApplyState(t))return;if("event"===t.bindingType)return;if(!0!==Qs.get(t)){const e=G(t.replaceNode);if(e&&void 0===K()?.get(e))return void function(t,e){if(Vs.has(t))return;Vs.add(t);const n=()=>{Vs.delete(t);const e=jo(t);(null===e||e.shouldApplyState(t))&&nr([t])},o=n=>{Vs.delete(t),Gs(e,n)},s=jo(t);if(null!==s){const r=s.deferUntilDefined(t.replaceNode,e,n,o);return void(s.addTeardown(t,()=>{Vs.delete(t),r()})||(Vs.delete(t),r()))}const r=K();if(null===r)return Vs.delete(t),void Gs(e,new Error("CustomElementRegistry is unavailable."));mo(r).wait(e,()=>{t.replaceNode.isConnected?n():Vs.delete(t)},o)}(t,e);Qs.set(t,!0)}if(!0===e.sameRootVerified&&t.stateName===e.stateName)return void tr(t,e);let o=t.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=pe(o),null===o&&et("Root node for fragment not found for binding.")),t.stateName!==e.stateName||o!==e.rootNode){const n=zr(o,t.stateName);null===n&&et(`State element with name "${t.stateName}" not found for binding.`),n.createState("readonly",s=>{const r={stateName:t.stateName,rootNode:o,stateElement:n,state:s,appliedBindingSet:e.appliedBindingSet,newListValueByAbsAddress:e.newListValueByAbsAddress,updatedAbsAddressSetByStateElement:e.updatedAbsAddressSetByStateElement,deferredSelectBindings:e.deferredSelectBindings};tr(t,r)})}else tr(t,e)}function nr(t,e){let n=0;const o=new Set,s=new Map,r=new Map,i=[];for(;n<t.length;){let a=t[n];const l=a.stateName;if(!1===a.replaceNode.isConnected){n++;continue}let c=a.replaceNode.getRootNode();c instanceof DocumentFragment&&!(c instanceof ShadowRoot)&&(c=pe(c),null===c&&et("Root node for fragment not found for binding."));const d=zr(c,l);null===d&&et(`State element with name "${l}" not found for binding.`),d.createState("readonly",u=>{const f={rootNode:c,stateName:l,stateElement:d,state:u,appliedBindingSet:o,newListValueByAbsAddress:s,updatedAbsAddressSetByStateElement:r,deferredSelectBindings:i,sameRootVerified:!0,propagationContextByBinding:e};for(;;){er(a,f),n++;const e=t[n];if(!e)break;const o=e.replaceNode.getRootNode();if(e.stateName!==l||o!==f.rootNode)break;a=e}})}for(const{binding:t,value:n}of i)zs(t,{propagationContextByBinding:e},n);for(const[t,e]of s.entries())Yt(t,e);for(const[t,e]of r.entries())t.createState("writable",t=>{t[se](Array.from(e))})}function or(t,e){const[n,o,s]=qt(t),r=Wo(t);for(const t of n)Kt(t,e);nr(r.initialize(o)),function(t,e,n){for(const o of t)n.deferUntilDefined(o.node,o.tagName,()=>{const t=Ht(o);0!==t.length&&(Kt(o.node,e),nr(n.initialize(t)))},t=>{console.error(`[@wcstack/state] deferred spread failed for <${o.tagName}>.`,t)})}(s,e,r)}const sr=/\{\{\s*(.+?)\s*\}\}/g,rr=new Set(["SCRIPT","STYLE"]);function ir(t){!function(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),n=[];for(;e.nextNode();)n.push(e.currentNode);for(const t of n)t.parentElement&&rr.has(t.parentElement.tagName)||ar(t)}(t);const e=Array.from(t.querySelectorAll("template"));for(const t of e)if("http://www.w3.org/2000/svg"===t.namespaceURI){const e=document.createElement("template"),n=Array.from(t.childNodes);for(let t=0;t<n.length;t++){const o=n[t];e.content.appendChild(o)}for(const n of t.attributes)e.setAttribute(n.name,n.value);t.replaceWith(e),ir(e.content)}else ir(t.content)}function ar(t){const e=t.data;if(sr.lastIndex=0,!sr.test(e))return;sr.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=sr.exec(e));){o.index>s&&n.appendChild(document.createTextNode(e.slice(s,o.index)));const t=o[1];n.appendChild(document.createComment(`@@: ${t}`)),s=o.index+o[0].length}s<e.length&&n.appendChild(document.createTextNode(e.slice(s))),t.parentNode.replaceChild(n,t)}let lr;function cr(){if(lr)return lr;const t=[],e=wt("not",t)(yt);return lr={filterName:"not",args:t,filterFn:e},lr}const dr=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function ur(t,e){const s=e+n+o,r=t.indexOf("|"),i=t.indexOf("@");let a,l;if(-1!==r?(a=t.slice(0,r).trim(),l=t.slice(r)):-1!==i?(a=t.slice(0,i).trim(),l=t.slice(i)):(a=t.trim(),l=""),"."===a)a=s;else{if(!a.startsWith("."))return t;a=s+n+a.slice(1)}return l.length>0?a+l:a}function fr(t,e){const n=dr.exec(t);if(null===n)return t;const o=n[1],s=n[2],r=n[3];return o+ur(s,e)+r}function hr(t,e){const n=t.split(";");let o=!1;const s=n.map(t=>{const n=t.trim();if(0===n.length)return t;const s=n.indexOf(":");if(-1===s)return t;const r=n.slice(0,s).trim(),i=n.slice(s+1).trim(),a=ur(i,e);return a!==i?(o=!0,`${r}: ${a}`):t});return o?s.join(";"):t}function pr(t,e){return hr(t,e)}function mr(t,n){const o=e.bindAttributeName,s=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const t=s.currentNode;if(t.nodeType===Node.COMMENT_NODE){const e=t;e.data=fr(e.data,n);continue}const e=t;if(e instanceof HTMLTemplateElement)continue;const r=e.getAttribute(o);if(null!==r){const t=hr(r,n);t!==r&&e.setAttribute(o,t)}}}function gr(t){let e=t;const n=[];for(;null!==e.parentNode;){const t=Array.from(e.parentNode.childNodes).indexOf(e);n.unshift(t),e=e.parentNode}return n}function yr(t){const e=[],n=Bt(t);for(const t of n){const n=Dt(t);let o=t;if(t.nodeType===Node.COMMENT_NODE&&1===n.length&&"text"===n[0].bindingType&&null!==t.parentNode){const e=document.createTextNode("");t.parentNode.replaceChild(e,t),o=e}e.push({nodePath:gr(o),parseBindTextResults:n})}return e}function br(t){const e=Array.from(t.childNodes);for(const n of e)if(n.nodeType===Node.TEXT_NODE){""===(n.textContent||"").trim()&&t.removeChild(n)}}const wr=new Map([["for",e.commentForPrefix],["if",e.commentIfPrefix],["elseif",e.commentElseIfPrefix],["else",e.commentElsePrefix]]),vr=cr();function Nr(t,e){const n=e.outFilters;return{...e,outFilters:[...n,vr],bindingType:t}}function Sr(t,e,n,o){br(e),"string"==typeof o&&mr(e,o),Ir(t,e,o);return{fragment:e,parseBindTextResult:n,nodeInfos:yr(e)}}function Ir(t,n,o){const s=e.commentElsePrefix,r=Wt(n),i=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode(t){const n=t;if(r.length>0&&-1!==r.indexOf(n))return NodeFilter.FILTER_REJECT;if("template"===n.tagName.toLowerCase()){if((n.getAttribute(e.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let a=null;const l=[],c=[];for(;i.nextNode();){const t=i.currentNode;c.push(t)}for(const n of c){let r=n.getAttribute(e.bindAttributeName)||"";"string"==typeof o&&(r=pr(r,o));let i=_t(r)[0];const c=wr.get(i.bindingType);if(void 0===c)continue;const d=i.bindingType,u=n.content,f=Ko();let h=null;const p="for"===d?i.statePathName:o;if("else"===d){null===a&&et("'else' binding found without preceding 'if' or 'elseif' binding."),i=Nr("else",a.parseBindTextResult),h=Sr(t,u,i,p),Ot(f,t,h);const e=l.at(-1),o=document.createComment(`@@${c}:${f}`);void 0!==e?(n.remove(),e.fragment.appendChild(o),e.nodeInfos.push({nodePath:gr(o),parseBindTextResults:Dt(o)})):n.replaceWith(o)}else if("elseif"===d){null===a&&et("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=Sr(t,u,i,p),Ot(f,t,h);const e=document.createComment(`@@${c}:${f}`),o=Ko(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Nr("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(e),r.nodeInfos.push({nodePath:gr(e),parseBindTextResults:Dt(e)}),Ot(o,t,r);const d=l.at(-1);l.push(r);const m=document.createComment(`@@${s}:${o}`);void 0!==d?(n.remove(),d.fragment.appendChild(m),d.nodeInfos.push({nodePath:gr(m),parseBindTextResults:Dt(m)})):n.replaceWith(m)}else{h=Sr(t,u,i,p),Ot(f,t,h);const e=document.createComment(`@@${c}:${f}`);n.replaceWith(e)}"if"===d?(l.length=0,a=h):"elseif"===d?a=h:"else"===d&&(a=null,l.length=0)}}async function xr(t){const n=t.querySelectorAll(e.tagNames.state),o=[];await customElements.whenDefined(e.tagNames.state);for(const t of n){if(Lt(t))continue;const e=t;o.push(e.initializePromise)}await Promise.all(o)}async function $r(t){if(t===document)await xr(document),ir(document),Ir(document,document),or(document.body,null);else{const n=t;n.host.hasAttribute(e.bindAttributeName)&&await B(n.host),await xr(n),ir(n),Ir(n,n),or(n,null)}}const Pr="1.30.0",_r="undefined"==typeof HTMLElement?class{}:HTMLElement,Ar=/^@@wcs-(?:for|if|elseif|else):[^-]/,kr=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,Cr=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,Er=/^@@wcs-text-start:(.+)$/;function Mr(t){return t.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class Tr extends _r{_stateData=null;_templates=null;_hydrateProps=null;get name(){return this.getAttribute("name")||"default"}get version(){return this.getAttribute("version")||""}get stateData(){return null===this._stateData&&(this._stateData=this._loadStateData()),this._stateData}get templates(){return null===this._templates&&(this._templates=this._loadTemplates()),this._templates}get hydrateProps(){return null===this._hydrateProps&&(this._hydrateProps=this._loadHydrateProps()),this._hydrateProps}getTemplate(t){return this.templates.get(t)??null}verifyVersion(){const t=this.version;if(!t)return!0;const e=t.split("."),n=Pr.split(".");return e[0]===n[0]&&e[1]===n[1]}setStateData(t){this._stateData=t}setHydrateProps(t){this._hydrateProps=t}_loadStateData(){const t=this.querySelector('script[type="application/json"]:not([data-wcs-ssr-props])');if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}_loadTemplates(){const t=new Map,e=this.querySelectorAll("template[id]");for(const n of e){const e=n.getAttribute("id");e&&t.set(e,n)}return t}_loadHydrateProps(){const t=this.querySelector("script[data-wcs-ssr-props]");if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}static findByName(t,n){const o=e.tagNames.ssr,s=t instanceof Element?t:t instanceof Document?t.documentElement:null;if(!s)return null;return s.querySelector(`${o}[name="${n}"]`)}static extractStateData(t){const e=t.__state;if(!e||"object"!=typeof e)return{};const n={};for(const[t,o]of Object.entries(e))t.startsWith("$")||"function"==typeof o||(n[t]=o);return n}static buildContent(t,n){const o=document.createElement("script");o.setAttribute("type","application/json"),o.textContent=Mr(JSON.stringify(n)),t.appendChild(o);const s=Array.from(Tt.keys());for(const n of s){const o=Rt(n);if(!o)continue;const s=document.createElement("template");s.setAttribute("id",n);const r=o.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;s.setAttribute(e.bindAttributeName,i);const a=o.fragment.cloneNode(!0);s.content.appendChild(a),t.appendChild(s)}const r=Array.from(Bs);if(r.length>0){const e={};for(let t=0;t<r.length;t++){const n=r[t],o=js(n);if(0===o.length)continue;const s=`wcs-ssr-${t}`;n.setAttribute("data-wcs-ssr-id",s);const i={};for(const t of o)i[t.propName]=t.value;e[s]=i}if(Object.keys(e).length>0){const n=document.createElement("script");n.setAttribute("type","application/json"),n.setAttribute("data-wcs-ssr-props",""),n.textContent=Mr(JSON.stringify(e)),t.appendChild(n)}}Bs.clear()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(kr.test(t.data)||Cr.test(t.data))&&n.push(t)}for(const t of n)t.remove()}static removeStructuralComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;Ar.test(t.data)&&n.push(t)}for(const t of n)t.remove()}static restoreTextBindings(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode,o=Er.exec(t.data);o&&n.push({comment:t,path:o[1]})}for(const{comment:t,path:e}of n){const n=document.createComment(`@@: ${e}`);t.parentNode.insertBefore(n,t);let o=t.nextSibling;t.remove();const s=`@@wcs-text-end:${e}`;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===s){o.parentNode.removeChild(o);break}o.parentNode.removeChild(o),o=t}}}static cleanupDom(t){const n=document.body,o=t.querySelectorAll(e.tagNames.ssr),s=new Map;for(const t of o){const e=t.querySelectorAll("template[id]");for(const t of e){const e=t.getAttribute("id");e&&s.set(e,t)}}const r=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const t=r.currentNode;kr.test(t.data)&&i.push(t)}for(const t of i){const e=kr.exec(t.data),n=`@@wcs-${e[1]}-end:${e[2]}`;let o=t.nextSibling;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===n){o.remove();break}o.remove(),o=t}t.remove()}Tr.restoreTextBindings(n);const a=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const t=a.currentNode;if(Ar.test(t.data)){const e=t.data.split(":")[1];l.push({comment:t,uuid:e})}}for(const{comment:t,uuid:n}of l){const o=s.get(n);if(o){const n=document.createElement("template"),s=o.getAttribute(e.bindAttributeName);s&&n.setAttribute(e.bindAttributeName,s);const r=document.importNode(o.content,!0);if(r.childNodes.length>0)n.content.appendChild(r);else for(const t of Array.from(o.childNodes))n.content.appendChild(document.importNode(t,!0));t.parentNode.replaceChild(n,t)}}const c=t.querySelectorAll("[data-wcs-ssr-id]");for(const t of c)t.removeAttribute("data-wcs-ssr-id");for(const t of o)t.remove()}}const Or=new Set(["for","if","elseif","else"]);function Rr(t){const e=new Lo;if(0===t.length)return{bindingInfos:[],subscriberNodes:[],bindingSession:e};const n=t[0].parentNode,o=t[t.length-1].nextSibling,s=document.createElement("div");for(const e of t)s.appendChild(e);const[r,i]=qt(s),a=e.initialize(i,{registerAddress:!1,applyOnReconnect:!1});if(n)for(;s.firstChild;)n.insertBefore(s.firstChild,o);return{bindingInfos:a,subscriberNodes:r,bindingSession:e}}function Dr(t,n,o){const s={for:e.commentForPrefix,if:e.commentIfPrefix,elseif:e.commentElseIfPrefix,else:e.commentElsePrefix}[n];if(!s)return null;const r=`@@${s}:${o}`,i=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const t=i.currentNode;if(t.data===r)return t}return null}function Lr(t,n){const o=t;let s=null;for(const[t,r]of n.templates){let n=_t(r.getAttribute(e.bindAttributeName)||"")[0];const i=n.bindingType;"else"===i&&s?n={...s,outFilters:[...s.outFilters,cr()],bindingType:"else"}:"elseif"===i&&s&&(n={...n,stateName:s.stateName}),"if"===i||"elseif"===i?s=n:"else"===i&&(s=null);const a=document.importNode(r.content,!0),l="for"===i?n.statePathName:void 0;br(a),"string"==typeof l&&mr(a,l),Ir(o,a,l);Ot(t,o,{fragment:a,parseBindTextResult:n,nodeInfos:yr(a)})}}async function Wr(t){await xr(t);const n=t.querySelectorAll(e.tagNames.ssr);for(const e of n){const n=e;if(!n.verifyVersion())return console.warn(`[@wcstack/state] SSR version mismatch: server="${n.version}", client="${Pr}". Falling back to full render.`),Tr.cleanupDom(t),!1}for(const e of n)Lr(t,e);const s=function(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const t of o){const n=kr.exec(t.data);if(!n)continue;const o=n[1],s=n[2],r=s.split(":");let i,a,l=null;"for"===o?(i=r[0],a=r[1],l=parseInt(r[2],10)):(i=r[0],a=r.slice(1).join(":"));const c=[];let d=t.nextSibling;const u=`@@wcs-${o}-end:${s}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)c.push(d),d=d.nextSibling;e.push({type:o,uuid:i,path:a,index:l,nodes:c})}return e}(document.body);!function(t,e){const n=new Map;for(const s of e){if(0===s.nodes.length)continue;const e=Ps(s.nodes),{bindingInfos:r,subscriberNodes:i,bindingSession:a}=Rr(s.nodes);us(e,a);for(const t of i)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");ls(e,r),ps(e,i);const l=[];for(const t of r)t.statePathName in v&&l.push(t);if(Vo(e,l),"for"===s.type&&null!==s.index){const i=Dr(t,"for",s.uuid);if(i){const t=Yo(null,s.index);Ts(i,t,e),Os(i,s.nodes[s.nodes.length-1]),vs(i,e),ms(e,De(U(s.path+"."+o),t)),a.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});let l=n.get(s.uuid);l||(l=[],n.set(s.uuid,l)),l.push(t)}}else{const n=Dr(t,s.type,s.uuid);n&&(vs(n,e),a.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}))}}for(const[e,o]of n){const n=Dr(t,"for",e);if(!n)continue;const s=n.getRootNode(),r=Rt(e);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=zr(s,i);l&&l.createState("readonly",t=>{const e=t[a];Array.isArray(e)&&ts(e,o)})}}(document.body,s),Tr.removeBlockBoundaryComments(document.body);const r=[];for(const t of n)t.parentNode&&(r.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());Tr.restoreTextBindings(document.body);const[i,a]=qt(document.body);for(const t of i)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(Kt(t,null),e.setAttribute("data-wcs-completed",""))}else Kt(t,null);const l=[],c=[],d=Wo(document.body).initialize(a);for(const t of d)if("event"!==t.bindingType)if(Or.has(t.bindingType))c.push(t);else{if(t.statePathName.includes(o))continue;l.push(t)}for(const t of c)if("for"===t.bindingType){const e=Ie(t),n=zr(t.replaceNode.getRootNode(),t.stateName);n&&n.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&Yt(e,o)})}nr(l);for(const{el:t,parent:e,next:n}of r)e.insertBefore(t,n);const u=t.querySelectorAll(e.tagNames.ssr);for(const e of u){const n=e.hydrateProps;for(const[e,o]of Object.entries(n)){const n=t.querySelector(`[data-wcs-ssr-id="${e}"]`);if(n)for(const[t,e]of Object.entries(o))n[t]=e}}const f=t.querySelectorAll("[data-wcs-completed]");for(const t of f)t.removeAttribute("data-wcs-completed");return!0}const jr=new WeakMap,Br=new WeakMap,Fr=new Set;function zr(t,e){let n=jr.get(t);return n&&n.get(e)||null}function qr(t){return Br.get(t)??Promise.resolve()}function Ur(e,n,o){let s=jr.get(e);if(null===o){if(!s)return;const t=s.get(n);s.delete(n),0===s.size&&jr.delete(e),void 0!==t&&(Fr.delete(t),null!==$e&&$e({type:"state:element-unregistered",name:n,rootNode:e,element:t}))}else{if(!s){s=new Map,jr.set(e,s);const n=!t()&&o.hasAttribute?.("enable-ssr");if("HTMLDocument"===e.constructor.name||"Document"===e.constructor.name){const t=new Promise((t,o)=>{queueMicrotask(async()=>{try{if(n){await Wr(e)||await $r(e)}else await $r(e);t()}catch(t){o(t)}})});Br.set(e,t)}else if("ShadowRoot"===e.constructor.name){const t=new Promise((t,n)=>{queueMicrotask(async()=>{try{await $r(e),t()}catch(t){n(t)}})});Br.set(e,t)}}s.has(n)&&et(`State element with name "${n}" is already registered.`),s.set(n,o),Fr.add(o),null!==$e&&$e({type:"state:element-registered",name:n,rootNode:e,element:o})}}let Hr=0,Vr=0;const Gr=[];function Kr(t,e=0){const n=Gr.findIndex(t=>t.priority>e),o={listener:t,priority:e};-1===n?Gr.push(o):Gr.splice(n,0,o)}const Jr=new class{_queueUpdateRecords=[];constructor(){}enqueueAbsoluteAddress(t,e=null){Hr>Vr&&(Vr=Hr);const n=0===this._queueUpdateRecords.length;this._queueUpdateRecords.push({absoluteAddress:t,context:e}),n&&queueMicrotask(()=>{const t=this._queueUpdateRecords;this._queueUpdateRecords=[],this._applyChange(t)})}testApplyChange(t,e){this._applyChange(t.map((t,n)=>({absoluteAddress:t,context:e?.[n]??null})))}_applyChange(t){const e=new Map;for(const n of t){const t=e.get(n.absoluteAddress);null!==$e&&null!=t&&null!==n.context&&t.transactionId!==n.context.transactionId&&$e({type:"propagation:coalesced",absoluteAddress:n.absoluteAddress,droppedTransactionId:t.transactionId,winnerTransactionId:n.context.transactionId}),e.set(n.absoluteAddress,n.context)}const n=[],o=new Map;for(const[t,s]of e){if(null!==s&&s.hop>=32){console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:t.absolutePathInfo.pathInfo.path,stateName:t.absolutePathInfo.stateName,transactionId:s.transactionId,hop:s.hop,maxHops:32}),null!==$e&&$e({type:"propagation:hop-limit",absoluteAddress:t,transactionId:s.transactionId,hop:s.hop});continue}const e=Me(t);if(void 0!==e)if(e instanceof Set)for(const t of e)!1!==t.replaceNode.isConnected&&(n.push(t),null!==s&&o.set(t,s));else!1!==e.replaceNode.isConnected&&(n.push(e),null!==s&&o.set(e,s))}o.size>0?nr(n,o):nr(n),function(t){for(const e of Gr.slice())e.listener(t)}(new Set(e.keys()))}};function Xr(){return Jr}const Yr=/^\s*@@\s*(.*?)\s*:\s*(.+?)\s*$/;function Qr(t,e,n,o){return{node:t,propName:e.propName,statePathName:e.statePathName,stateName:e.stateName,bindingType:e.bindingType,inFilters:e.inFilters,outFilters:e.outFilters,origin:n,raw:o}}const Zr="__WCSTACK_DEVTOOLS_HOOK__";function ti(){const t=globalThis,e=t[Zr];if(void 0!==e)return 1!==e.version&&console.warn(`[wcstack/state] devtools hook registry version mismatch: found ${e.version}, expected 1. Keeping the existing registry (first-wins).`),e;const n=function(){const t=new Map,e=new Set,n=t=>{if(0===e.size)return void t._setSink(null);const n=t.id;t._setSink(t=>{for(const o of e)o.onEvent?.(n,t)})};return{version:1,sources:t,register(o){if(!t.has(o.id)){t.set(o.id,o),n(o);for(const t of e)t.onSourceRegistered?.(o)}},unregister(n){const o=t.get(n);if(void 0!==o){o._setSink(null),t.delete(n);for(const t of e)t.onSourceUnregistered?.(n)}},addListener(o){e.add(o);for(const e of t.values())n(e),o.onSourceRegistered?.(e);return()=>{if(e.delete(o))for(const e of t.values())n(e)}}}}();return t[Zr]=n,n}const ei=t=>{null!==$e&&$e({type:"state:update-batch",addresses:t})};function ni(t){const e=null!==$e;!function(t){$e=t}(t);const n=null!==t;n&&!e?Kr(ei,0):!n&&e&&function(t){const e=Gr.findIndex(e=>e.listener===t);-1!==e&&Gr.splice(e,1)}(ei)}function oi(t){return{name:t.name,rootNode:t.rootNode,element:t,paths:{list:t.listPaths,element:t.elementPaths,getter:t.getterPaths,setter:t.setterPaths},commandTokenNames:t.commandTokenNames,eventTokenNames:t.eventTokenNames,staticDependency:t.staticDependency,dynamicDependency:t.dynamicDependency,watchPaths:t.watchPaths??null,keyedListPaths:void 0===t.listKeys||null===t.listKeys?null:new Set(t.listKeys.keys())}}function si(t,e){return zr(e,t)??et(`devtools: state element not found: name="${t}"`)}let ri=null;function ii(){if(t())return;if(null!==ri)return;const n={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:Pr,getStateElements(){const t=[];for(const e of Fr)t.push(oi(e));return t},keys(t,e){const n=si(t,e),o=[];return n.createState("readonly",t=>{for(const e of Object.keys(t))if(!e.includes("*")&&!e.startsWith("$")){try{if("function"==typeof t[e])continue}catch{}o.push(e)}}),o},read(t,e,n,o){let s;return si(t,e).createState("readonly",t=>{s=t.$resolve(n,o??[])}),s},write(t,e,n,o,s){si(t,e).createState("writable",t=>{void 0!==s&&s.length>0?t.$resolve(n,s,o):t[n]=o})},getDeclaredBindings:t=>function(t){const n=[],o=new Set,s=new Set,r=t=>{const e=function(t){const e=[...t.inFilters,...t.outFilters].map(t=>`${t.filterName}(${t.args.join(",")})`).join("|");return[t.stateName,t.statePathName,t.propName,t.bindingType,e].join("\0")}(t);o.has(e)||(o.add(e),n.push(t))},i=t=>{if(s.has(t))return;s.add(t);const e=Rt(t);if(null!==e)for(const t of e.nodeInfos)for(const e of t.parseBindTextResults)r(Qr(null,e,"fragment","")),null!=e.uuid&&i(e.uuid)},a=(t.ownerDocument??t).createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT);for(let t=a.nextNode();null!==t;t=a.nextNode()){if(t.nodeType===Node.ELEMENT_NODE){const n=t,o=n.getAttribute(e.bindAttributeName);if(null===o||0===o.length)continue;try{const t=st(n,_t(o));for(const e of t)r(Qr(n,e,"attribute",o))}catch{}continue}const n=Yr.exec(t.data.trim());if(null===n)continue;const o=n[1]||e.commentTextPrefix,s=n[2],a=Rt(s);if(null===a){if(o===e.commentTextPrefix)try{r(Qr(t,Mt(s),"comment",s))}catch{}}else r(Qr(t,a.parseBindTextResult,"comment",s)),i(s)}return n}(t),_setSink:ni};ri=n,ti().register(n)}const ai="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";async function li(t,e){let n=null;const o=`\n//# sourceURL=${e}\n`;let s=!1;const r=t=>{t.effectiveDirective.startsWith("script-src")&&(s=!0)};document.addEventListener("securitypolicyviolation",r);try{if("function"==typeof URL.createObjectURL){const e=new Blob([t.text+o],{type:"application/javascript"}),s=URL.createObjectURL(e);try{n=await import(s)}finally{URL.revokeObjectURL(s)}}else{const e=btoa(String.fromCodePoint(...(new TextEncoder).encode(t.text+o)));n=await import(`data:application/javascript;base64,${e}`)}}catch(t){throw new Error(function(t,e,n){const o=e?.message??String(e);return n?`The inline <script> of state "${t}" was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL, so script-src must allow blob:. Prefer moving the state into an external file and loading it with src="./state.js", which requires no extra CSP directive. See ${ai}`:`Failed to evaluate the inline <script> of state "${t}": ${o}. If this page sets a Content-Security-Policy, see ${ai}`}(e,t,s),{cause:t})}finally{document.removeEventListener("securitypolicyviolation",r)}return n&&"object"==typeof n.default?n.default:{}}async function ci(t){try{return(await import(t)).default||{}}catch(t){et(`Failed to load script file: ${t}`)}}class di{_loopContextStack=Array(s).fill(void 0);_length=0;_getBaseDepth;constructor(t){this._getBaseDepth=t}createLoopContext(t,e){null===t.listIndex&&et("Cannot create loop context for a state address that does not have a list index.");const n=t;this._length>=s&&et("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&&et("Cannot push loop context for a list whose wildcard count is not exactly one more than the current active loop context.");const t=n.pathInfo.wildcardPathInfos[n.pathInfo.wildcardPathInfos.length-2];o.pathInfo!==t&&et("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else if(n.listIndex.length!==n.pathInfo.wildcardCount){const t=this._getBaseDepth();n.listIndex.length!==n.pathInfo.wildcardCount+t&&et(`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}, base depth ${t}).`)}let r;this._loopContextStack[this._length]=n,this._length++;try{r=e(n)}finally{r instanceof Promise?r.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return r}}const ui=new WeakMap;function fi(t,e){let n=ui.get(t);void 0===n&&(n=new Map,ui.set(t,n));let o=n.get(e);return void 0===o&&(o=new en(e,t.name),n.set(e,o)),o}const hi=new WeakMap;function pi(t){const e=hi.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return fi(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:fi(t,n)}},set(){et("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){et("$command namespace is read-only; deleting from it is not allowed.")}});return hi.set(t,n),n}const mi=Symbol("wcs-stream-last-notified-uncertain"),gi=new WeakMap;function yi(t,e){const n=gi.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function bi(t,e){const n=gi.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:mi,error:Object.is(o.error,null)?null:mi})}const wi=new Set;function vi(t){wi.delete(t)}const Ni=new WeakMap;function Si(t){return Ni.get(t)??new Map}function Ii(t){vi(t);const e=Ni.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,bi(t,n.name)}const xi=(t,e)=>e,$i=new Set;function Pi(t,e){const s=e[E];if(void 0===s)return void yi(t,$i);"object"==typeof s&&null!==s||et(`${E} must be an object mapping stream names to stream definitions.`);const r=new Map;for(const[i,a]of Object.entries(s)){0===i.length&&et(`${E} entry name must be a non-empty string.`),i.includes(n)&&et(`${E} entry "${i}" must be a flat property name ("${n}" is not allowed).`),i.includes(o)&&et(`${E} entry "${i}" must be a flat property name ("${o}" is not allowed).`),i.startsWith("$")&&et(`${E} entry "${i}" must not start with "$" (reserved namespace).`),i in Object.prototype&&et(`${E} entry "${i}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),t.getterPaths.has(i)&&et(`${E} entry "${i}" conflicts with a getter declared on the state.`),t.setterPaths.has(i)&&et(`${E} entry "${i}" conflicts with a setter declared on the state.`),"object"==typeof a&&null!==a||et(`${E} entry "${i}" must be an object ({ args?, source, fold?, initial? }).`);const s=a;"function"!=typeof s.source&&et(`${E} entry "${i}" source must be a function.`);const l=void 0!==s.fold;l&&"function"!=typeof s.fold&&et(`${E} entry "${i}" fold must be a function.`),l&&!("initial"in s)&&et(`${E} entry "${i}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==s.args&&"function"!=typeof s.args&&et(`${E} entry "${i}" args must be a function.`);const c={name:i,definition:{args:s.args??null,source:s.source,fold:s.fold??xi,initial:s.initial},status:"idle",error:null,controller:null,depAddresses:new Set};i in e||(e[i]=c.definition.initial),r.set(i,c)}!function(t,e){Ni.set(t,e)}(t,r),yi(t,new Set(r.keys()))}const _i=new WeakMap,Ai=new WeakMap;function ki(t,e,n){return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;const s=Si(t).get(o);return void 0!==s?n(s):void 0},has:(e,n)=>"string"==typeof n&&Si(t).has(n),ownKeys:()=>Array.from(Si(t).keys()),getOwnPropertyDescriptor(e,o){if("string"!=typeof o)return;const s=Si(t).get(o);return void 0!==s?{configurable:!0,enumerable:!0,value:n(s)}:void 0},set(){et(`${e} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){et(`${e} namespace is read-only; deleting from it is not allowed.`)}})}function Ci(t){const e=_i.get(t);if(void 0!==e)return e;const n=ki(t,O,t=>t.status);return _i.set(t,n),n}function Ei(t){const e=Ai.get(t);if(void 0!==e)return e;const n=ki(t,R,t=>t.error);return Ai.set(t,n),n}function Mi(t){_i.delete(t),Ai.delete(t)}let Ti=null;async function Oi(t,e,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 t(e,n);if(s=function(t,e){if("function"==typeof t?.getReader)return async function*(t,e){const n=t.getReader(),o=()=>{n.cancel().catch(()=>{})};e.addEventListener("abort",o,{once:!0});try{for(;;){const{done:t,value:e}=await n.read();if(t)return;yield e}}finally{e.removeEventListener("abort",o),n.releaseLock()}}(t,e);if("function"==typeof t?.[Symbol.asyncIterator])return t;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 t=await s.next();if(t.done)break;if(n.aborted)return;o.fold(t.value)}if(n.aborted)return;o.done()}catch(t){if(n.aborted)return;o.fail(t)}finally{n.removeEventListener("abort",i)}}function Ri(t){const e=Si(t);if(0!==e.size){!function(t){wi.add(t)}(t);for(const n of e.values())Di(t,n)}}function Di(t,e){e.controller?.abort();const o=new AbortController;e.controller=o;const s=function(t,e){const o=e.definition.args;if(null===o)return void e.depAddresses.clear();const s=Ti,r=new Set;let i;Ti=r;try{t.createState("readonly",t=>{i=o(t)})}finally{Ti=s}i instanceof Promise&&et(`${E} entry "${e.name}" args must be synchronous (it returned a Promise).`);const a=`${O}${n}${e.name}`,l=`${R}${n}${e.name}`;for(const n of r){const o=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==t||o.path!==e.name&&o.path!==a&&o.path!==l||et(`${E} entry "${e.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&&et(`${E} entry "${e.name}" args must not read wildcard paths ("${o.path}"): wildcard dependencies are out of scope.`)}return e.depAddresses=r,i}(t,e);t.createState("writable",t=>{t[e.name]=e.definition.initial}),Li(t,e,"active",null);const r=e.definition,i={fold(n){t.createState("writable",t=>{t[e.name]=r.fold(t[e.name],n)})},done(){Li(t,e,"done",null)},fail(n){Li(t,e,"error",n),o.abort()}};Oi(r.source,s,o.signal,i)}function Li(t,e,o,s){e.status=o,e.error=s;const r=function(t,e){return gi.get(t)?.get(e)??{status:"idle",error:null}}(t,e.name),i=r.status!==o,a=!Object.is(r.error,s);(i||a)&&(!function(t,e,n,o){let s=gi.get(t);void 0===s&&(s=new Map,gi.set(t,s)),s.set(e,{status:n,error:o})}(t,e.name,o,s),t.createState("writable",t=>{i&&t.$postUpdate(`${O}${n}${e.name}`),a&&t.$postUpdate(`${R}${n}${e.name}`)}))}Kr(function(t){const e=wi;if(0===e.size)return;const n=[];for(const o of e)for(const e of Si(o).values())for(const s of e.depAddresses)if(t.has(s)){n.push({stateElement:o,entry:e});break}for(const{stateElement:t,entry:o}of n)if(e.has(t)&&Si(t).get(o.name)===o)try{Di(t,o)}catch(n){o.controller?.abort(),e.has(t)&&Si(t).get(o.name)===o&&Li(t,o,"error",n)}},20);const Wi=new WeakMap,ji=new Set,Bi=new Map;function Fi(t){return Wi.get(t)??Bi}function zi(){return ji}function qi(t,e){const n=e[M];if(void 0===n)return null;"object"==typeof n&&null!==n||et(`[wcs/watch-declaration-invalid] ${M} must be an object mapping state paths to handler functions.${ct}`);const o=new Map,s=new Set;let r=0;for(const[e,i]of Object.entries(n)){"function"!=typeof i&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" must be a function.${ct}`),0===e.length&&et(`[wcs/watch-declaration-invalid] ${M} entry name must be a non-empty state path.`),e.startsWith("$")&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" must not start with "$" (reserved namespace).${ct}`),e.includes("@")&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" must not target another state ("@" is not allowed); watch only paths of its own state.${ct}`),e in Object.prototype&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const n=U(e);for(const t of n.segments)0===t.length&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" has an empty path segment.${ct}`);n.wildcardCount>128&&et(`[wcs/watch-declaration-invalid] ${M} entry "${e}" exceeds the maximum wildcard depth (128).`),o.set(e,{path:e,pathInfo:n,handler:i,order:r++}),s.add(e),t.setPathInfo(e,"prop")}return function(t,e){Wi.set(t,e)}(t,o),s.size>0?s:null}const Ui=new WeakMap;function Hi(t,e,n){let o=Ui.get(t);void 0===o&&(o=new Map,Ui.set(t,o)),o.set(e,n)}const Vi=new Map;function Gi(t){0!==Fi(t).size&&(function(t){ji.add(t)}(t),function(t){const e=[];for(const n of Fi(t).values())Ji(t,n)&&e.push(n);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{Hi(t,Ki(t,o),n[o.path])}catch(e){Yi(t,o.path,"prime",e)}})}(t))}function Ki(t,e){return ue(ie(t,e.pathInfo),null)}function Ji(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const Xi={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function Yi(t,e,n,o){console.error(`[@wcstack/state] $watch ${Xi[n]} "${e}" threw.`,o),null!==$e&&$e({type:"state:watch-error",phase:n,stateName:t.name,path:e,error:o})}function Qi(t,e){if(t.entry.order!==e.entry.order)return t.entry.order-e.entry.order;const n=Math.min(t.indexes.length,e.indexes.length);for(let o=0;o<n;o++)if(t.indexes[o]!==e.indexes[o])return t.indexes[o]-e.indexes[o];return t.indexes.length-e.indexes.length}function Zi(t){const{stateElement:e,entry:n,absAddress:o,indexes:s}=t,r=Ji(e,n);try{e.createState("writable",t=>{let i;try{i=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,n,s)}catch(t){return void Yi(e,n.path,"evaluate",t)}const a=r?function(t,e){return Ui.get(t)?.get(e)}(e,o):function(t){return Vi.get(t)}(o);r&&Hi(e,o,i),null!==$e&&$e({type:"state:watch-fired",stateName:e.name,path:n.path}),n.handler.call(t,i,a,...s)})}catch(t){Yi(e,n.path,"handler",t)}}function ta(t){return function(){const e=this.stateElement;if(!e)return;if(!0!==e.initialized)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function ea(t){return function(e){const n=this.stateElement;n&&(!0!==n.initialized?n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})}):n.createState("writable",n=>{n[t]=e}))}}function na(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function oa(t){return t.startsWith("$")}function sa(t){const e=[];let n=t;for(;n&&n!==Object.prototype;)e.push(n),n=Object.getPrototypeOf(n);const o={};for(let t=e.length-1;t>=0;t--)Object.assign(o,Object.getOwnPropertyDescriptors(e[t]));return o}function ra(t,e){return Object.keys(t).filter(n=>{if(n.startsWith("$")||"constructor"===n)return!1;const o="function"==typeof t[n].value;return"method"===e?o:!o})}function ia(t,e){const n=t[e];if(void 0===n)return null;Array.isArray(n)||et(`${e} must be an array of strings.`);const o=[],s=new Set;for(const t of n)"string"==typeof t&&0!==t.length||et(`${e} entries must be non-empty strings.`),t.startsWith("$")&&et(`${e} entry "${t}" must not start with "$" (internal properties are not exposed on the component).`),s.has(t)&&et(`${e} entry "${t}" is duplicated.`),s.add(t),o.push(t);return o}function aa(t){const e=ia(t,$)??[],n=ia(t,P)??[],o=sa(t),s=function(t){const e=t[E];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),r=[];for(const t of e){const e=o[t];if(void 0===e){if(s.has(t)){r.push(t);continue}et(`${$} entry "${t}" is not declared on the state.${lt(t,ra(o,"value"))}`)}"function"==typeof e.value&&et(`${$} entry "${t}" is a method. Declare it in ${P} instead.`)}for(const t of n){const e=o[t];void 0===e&&et(`${P} entry "${t}" is not declared on the state.${lt(t,ra(o,"method"))}`),"function"!=typeof e.value&&et(`${P} entry "${t}" is not a method. Declare it in ${$} instead.`)}return{bindables:e,commands:n,streamBackedBindables:r}}Kr(function(t){const e=zi();try{if(0===e.size)return;const n=function(){const t=Vr;return Vr=0,t}();if(n>32){const e=Array.from(t,t=>t.absolutePathInfo.pathInfo.path);return console.error("[@wcstack/state] $watch chain depth limit exceeded; watch handlers for this batch were skipped.",{maxDepth:32,paths:e}),void(null!==$e&&$e({type:"state:watch-chain-limit",maxDepth:32,paths:e}))}const o=[];for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const s=Fi(t).get(n.absolutePathInfo.pathInfo.path);if(void 0===s)continue;let r=[];if(s.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=be(n.listIndex,s.pathInfo.wildcardCount)}o.push({stateElement:t,entry:s,absAddress:n,indexes:r})}if(0===o.length)return;o.sort(Qi),function(t){Hr=t+1}(n);try{for(const t of o)e.has(t.stateElement)&&Fi(t.stateElement).get(t.entry.path)===t.entry&&Zi(t)}finally{Hr=0}}finally{Vi.clear()}},10);const la=new Map;class ca{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(t){const e=t.split("."),n=e.slice();let o=0,s=0,r=0,i="none";const a=[];for(let t=0;t<e.length;t++){const i=e[t];if("*"===i)n[t]="*",a.push(null),o++,r++;else{const e=Number(i);Number.isNaN(e)||(n[t]="*",a.push(e),s++,r++)}}const l=U(n.join("."));(o>0||s>0)&&(i=o===r?"context":s===r?"all":"partial"),this.path=t,this.segments=e,this.wildcardCount=r,this.wildcardType=i,this.wildcardIndexes=a,this.pathInfo=l}}function da(t){let e;return la.get(t)??(la.set(t,e=new ca(t)),e)}const ua=new WeakMap;function fa(t,e){null===e?ua.delete(t):ua.set(t,e)}function ha(t){const e=ua.get(t);e&&(e.dirty=!0)}const pa=[],ma=[];let ga=0;function ya(t,e){pa[ga]=t,ma[ga]=e,ga++}function ba(){ga--,pa[ga]=void 0,ma[ga]=void 0}function wa(t,e){return!0!==t.hasMappedComponentState&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function va(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}function Na(t,e,n,s,r){const i=e.pathInfo.segments[0];if(i===A)return va(pi(r),e.pathInfo.segments);if(i===O)return va(Ci(r),e.pathInfo.segments);if(i===R)return va(Ei(r),e.pathInfo.segments);if(!(e.pathInfo.path in t)){const r=Ia(t,e.parentAddress??et(`address.parentAddress is undefined path: ${e.pathInfo.path}`),n,s);if(null==r)return;const i=e.pathInfo.segments[e.pathInfo.segments.length-1];if(i===o){const t=e.listIndex?.index??et(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.get(r,t)}return Reflect.get(r,i)}if(r.getterPaths.has(e.pathInfo.path)){s.pushAddress(e);try{return Reflect.get(t,e.pathInfo.path,n)}finally{s.popAddress()}}else{if(!0!==r.hasMappedComponentState)return Reflect.get(t,e.pathInfo.path);ya(r,e);try{return Reflect.get(t,e.pathInfo.path)}finally{ba()}}}function Sa(t,e,n,o,s){const r=ue(ie(s,e.pathInfo),e.listIndex),i=function(t){return ua.get(t)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=Na(t,e,n,o,s);return fa(r,{value:a,dirty:!1}),a}function Ia(t,e,n,o){!function(t,e){if(!t.untracking&&t.addressStackLength>0){const n=t.lastAddressStack,o=n?.pathInfo??null,s=t.stateElement;if(null!==o&&s.getterPaths.has(o.path)&&o.path!==e.pathInfo.path&&(s.addDynamicDependency(e.pathInfo.path,o.path),e.pathInfo.wildcardCount>0&&o.wildcardCount>0)){const t=ge(e.pathInfo,o);if(t>0){let r=!1;const i=e.listIndex??null,a=n.listIndex??null;for(let n=0;n<t;n++)if((null!==i?ye(i,n,e.pathInfo.wildcardCount):null)!==(null!==a?ye(a,n,o.wildcardCount):null)){r=!0;break}if(r)for(let n=0;n<t;n++)s.addCrossRowListPath?.(e.pathInfo.wildcardParentPaths[n])}}}}(o,e),function(t,e){if(null===Ti)return;const n=ie(t,e.pathInfo);Ti.add(ue(n,e.listIndex))}(o.stateElement,e);const s=o.stateElement;return wa(s,e)?Sa(t,e,n,o,s):Na(t,e,n,o,s)}function xa(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const o=n.pathInfo.indexByWildcardPath[e];return void 0===o||null===n.listIndex?null:ye(n.listIndex,o,n.pathInfo.wildcardCount)}function $a(t,e,n){const o=t.bindableEventMap,s=o[e.path],r="string"==typeof s,i=r?s:e.segments.length>1?o[e.segments[0]]:void 0;if("string"!=typeof i)return;const a=t.rootNode;a instanceof ShadowRoot&&a.host.dispatchEvent(new CustomEvent(i,{detail:r&&void 0!==n?n.value:void 0,bubbles:!0}))}function Pa(t,e,n,o){"object"==typeof t&&null!==t||et(`${T} list "${e}": ${n} row at index ${o} must be a plain object (got ${null===t?"null":typeof t}).`);const s=Object.getPrototypeOf(t);s!==Object.prototype&&null!==s&&et(`${T} list "${e}": ${n} row at index ${o} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function _a(t,e,n,o,s){const r="function"==typeof e?e(t):t[e];return null==r&&et(`${T} list "${n}": ${o} row at index ${s} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(r)}).`),r}function Aa(t,e,n,o){const s=new Array(t.length),r=new Set;for(let i=0;i<t.length;i++){const a=t[i];Pa(a,n,o,i);const l=_a(a,e,n,o,i);r.has(l)&&et(`${T} list "${n}": duplicate key ${JSON.stringify(l)} in ${o} list.`),r.add(l),s[i]=l}return s}function ka(t,e){const n=[];for(const o of Object.keys(e))Object.is(t[o],e[o])||n.push({field:o,value:e[o]});for(const o of Object.keys(t))Object.hasOwn(e,o)||null==t[o]||n.push({field:o,value:null});return n}function Ca(t,e,n,s){if(e.pathInfo.path in t)return!0;const r=e.parentAddress;if(null===r)return!1;const i=Ia(t,r,n,s);if(null===i||"object"!=typeof i&&"function"!=typeof i)return!1;const a=e.pathInfo.lastSegment;if(a===o){const t=e.listIndex?.index;return"number"==typeof t&&t in i}return a in i}const Ea=new WeakMap;function Ma(t,e){null===e?Ea.delete(t):Ea.set(t,e)}function Ta(t,e,n){const o=U(t.wildcardParentPaths[e]),s=ie(t.stateElement,o),r=De(o,n),i=Xt(ue(s,n)),a=t.stateProxy[Zt](r),l=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return[]}}(ss(Kn(t.stateElement,r.listIndex),i,a),t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...l);else for(const n of l)Ta(t,e+1,n)}const Oa=[];function Ra(t,e,n,o,s){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:s.newIndexes,movedRows:null}:0===s.addIndexSet.size&&0===s.changeIndexSet.size?0===s.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:Oa,movedRows:null}:{fullRows:s.newIndexes,movedRows:null}:{fullRows:Oa,movedRows:null}:{fullRows:s.addIndexSet,movedRows:s.changeIndexSet}}const Da=[];function La(t,e,o){const s=t.stateElement.indexDependentGetterPaths;if(!s||0===s.size)return Da;let r=null;const i=e+n;for(const t of s){if(t!==e&&!t.startsWith(i))continue;const n=U(t);if(n.wildcardCount!==o.wildcardCount)return null;(r??=[]).push(n)}return r??Da}function Wa(t,e,n){const s=e.pathInfo.path,r=t.staticMap.get(s);if(r)for(const i of r){const r=U(i);if(t.listPathSet.has(s)&&r.lastSegment===o){const o=t.stateProxy[Zt](e),a=Xt(ue(ie(t.stateElement,e.pathInfo),e.listIndex)),l=Ra(t,s,0,0,ss(Kn(t.stateElement,e.listIndex),a,o));for(const e of l.fullRows){const o=De(r,e);t.result.add(o),n.push(o)}if(null!==l.movedRows){const e=La(t,i,r);if(null===e)for(const e of l.movedRows){const o=De(r,e);t.result.add(o),n.push(o)}else if(e.length>0)for(const o of l.movedRows)for(const s of e){const e=De(s,o);t.result.add(e),n.push(e)}}}else{const o=De(r,e.listIndex);t.result.add(o),n.push(o)}}const i=t.dynamicMap.get(s);if(i)for(const o of i){const s=U(o),r=[];if(s.wildcardCount>0){const n=ge(e.pathInfo,s);if(s.wildcardCount-n>=1){let o;n>0?(null===e.listIndex&&et(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`),o=ye(e.listIndex,n-1,e.pathInfo.wildcardCount)):o=null;const i={stateName:t.stateName,stateElement:t.stateElement,targetListIndexes:[],wildcardPaths:s.wildcardPaths,wildcardParentPaths:s.wildcardParentPaths,stateProxy:t.stateProxy,searchType:t.searchType};Ta(i,n,o),r.push(...i.targetListIndexes)}else{null===e.listIndex&&et(`Cannot expand dynamic dependency with wildcard for non-list address: ${e.pathInfo.path}`);const t=ye(e.listIndex,n-1,e.pathInfo.wildcardCount);r.push(t)}}else r.push(null);for(const e of r){const o=De(s,e);t.result.add(o),n.push(o)}}}function ja(t,e,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(t,e,n,o){const s=new Map,r=new Map,i=[t];for(r.set(t,0);i.length>0;){const t=i.pop();if(s.has(t))continue;const o=e.get(t),a=n.get(t);let l;l=void 0===o?a??[]:void 0===a?o:o.concat(a),s.set(t,l);for(let t=0;t<l.length;t++){const e=l[t];r.set(e,(r.get(e)??0)+1),s.has(e)||i.push(e)}}const a=new Map,l=new Set,c=[];for(const[t,e]of r)0===e&&(a.set(t,0),l.add(t),c.push(t));for(let t=0;t<c.length;t++){const e=c[t],n=a.get(e)+1;n>o&&et(`Maximum dependency depth of ${o} exceeded. Possible circular dependency detected at path: ${e}`);const i=s.get(e);for(let t=0;t<i.length;t++){const e=i[t];n>(a.get(e)??-1)&&a.set(e,n);const o=r.get(e)-1;r.set(e,o),0===o&&(l.add(e),c.push(e))}}if(l.size!==s.size){let t=-1;for(const e of l){const n=a.get(e);n>t&&(t=n)}const e=t+1;for(const t of s.keys())l.has(t)||a.set(t,e)}return a}(d,o,s,1e3),f={ranks:u,stateName:t,stateElement:e,staticMap:o,dynamicMap:s,result:new Set,listPathSet:r,visited:new Set,stateProxy:i,searchType:a,listExpansion:c?.listExpansion??"full",keyedMergePath:c?.keyedMergePath??null};return function(t,e,n){const o=[],s=t.ranks,r=(t,e)=>{let n=s.get(t.pathInfo.path)??e;n<e&&(n=e),(o[n]??=[]).push(t)};r(e,0);const i=[];for(let e=0;e<o.length;e++){const s=o[e];if(void 0!==s)for(let o=0;o<s.length;o++){const a=s[o];if(!t.visited.has(a)){t.visited.add(a),n(a),i.length=0,Wa(t,a,i);for(let t=0;t<i.length;t++)r(i[t],e+1)}}}}(f,n,l),Array.from(f.result)}function Ba(t,e,n,o,s){const r=t.watchPaths;null!=r&&s&&r.has(e)&&function(t,e){Vi.has(t)||Vi.set(t,e)}(n,o)}function Fa(t,e,n,o,s){const r=_n()??xn(-1),i=Xr();i.enqueueAbsoluteAddress(e,r),ja(o.stateName,o.stateElement,t,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=ue(ie(o.stateElement,e.pathInfo),e.listIndex);ha(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:"diff",keyedMergePath:s})}function za(t,e,n,s,r,i,a){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,s);const a=Ia(t,n,r,i),l=e.pathInfo.segments[e.pathInfo.segments.length-1];if(l===o){const t=e.listIndex?.index??et(`address.listIndex?.index is undefined path: ${e.pathInfo.path}`);return Reflect.set(a,t,s)}return Reflect.set(a,l,s)}if(i.stateElement.setterPaths.has(e.pathInfo.path)){i.pushAddress(e),i.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,s,r)}finally{i.endUntrack(),i.popAddress()}}else{if(!0!==i.stateElement.hasMappedComponentState)return Reflect.set(t,e.pathInfo.path,s);ya(i.stateElement,e);try{return Reflect.set(t,e.pathInfo.path,s)}finally{ba()}}}finally{Fa(e,n,r,i,a)}}function qa(t,e,n,o,s,r,i){let a=e.parentAddress??et(`address.parentAddress is undefined path: ${e.pathInfo.path}`),l=function(t){return Ea.get(t)??null}(a);if(null===l){const e=Ia(t,a,s,r)??[],n=Zo(e)??[];l={value:[...e],listIndexes:[...n]},Ma(a,l)}try{return za(t,e,n,o,s,r,i)}finally{const n=l.value.indexOf(o),i=Ia(t,a,s,r)??[],c=Array.isArray(i)?Zo(i)??[]:[],d=e.listIndex.index,u=-1!==n?l.listIndexes[n]:Yo(a.listIndex,-1);c[d]=u;if(new Set(i).size===l.value.length){for(let t=0;t<c.length;t++)c[t].index=t;Ma(a,null)}}}function Ua(t,e,s,r,i){const a=i.stateElement.listKeys;if(null!=a&&Array.isArray(s)){const l=a.get(e.pathInfo.path);if(void 0!==l){const a=Ia(t,e,r,i),c=function(t,e,n,o){const s=Aa(o,e,t,"new");if(!Array.isArray(n)||0===n.length||0===o.length)return null;const r=n,i=Aa(r,e,t,"current"),a=new Map;for(let t=0;t<r.length;t++)a.set(i[t],r[t]);const l=new Array(o.length),c=[];for(let t=0;t<o.length;t++){const e=o[t],n=a.get(s[t]);void 0!==n&&n!==e?(l[t]=n,c.push({position:t,oldRow:n,newRow:e})):l[t]=e}return c.length>0?{list:l,matched:c}:null}(e.pathInfo.path,l,a,s);if(null!==c)return function(t,e,s,r,i,a){const l=e.pathInfo.path,c=Kn(a.stateElement,e.listIndex);null===Zo(r)&&ss(c,null,r);const d=ss(c,r,s.list),u=Ha(t,e,s.list,i,a,l),f=U(l+n+o);for(const e of s.matched){const o=ka(e.oldRow,e.newRow);if(0===o.length)continue;const s=d.newIndexes[e.position];for(const r of o)void 0!==s?Ua(t,De(U(f.path+n+r.field),s),r.value,i,a):e.oldRow[r.field]=r.value}return u}(t,e,c,a,r,i)}}return Ha(t,e,s,r,i,null)}function Ha(t,n,s,r,i,a){const l=i.stateElement,c=n.pathInfo.path,d=!!Cn&&(Cn=!1,!0);if(!(c in t)&&null!==n.parentAddress&&!l.elementPaths.has(c)){const u=Ia(t,n.parentAddress,r,i);if("object"==typeof u&&null!==u){const t=n.pathInfo.lastSegment,f=t===o?n.listIndex?.index:t;let h,p=!1;if(!d&&e.sameValueGuard&&(null===s||"object"!=typeof s)){const t=void 0!==f&&f in u,e=void 0!==f?u[f]:void 0;if(t&&Object.is(e,s))return!0;h=e,p=!0}const m=wa(l,n),g=ue(ie(l,n.pathInfo),n.listIndex);null!==$e&&$e({type:"state:write",absoluteAddress:g,value:s,oldValue:h,hasOldValue:p}),Ba(l,c,g,h,p);try{return void 0===f&&et(`address.listIndex?.index is undefined path: ${c}`),Reflect.set(u,f,s)}finally{Fa(n,g,r,i,a),m&&fa(g,{value:s,dirty:!1}),$a(l,n.pathInfo,{value:s})}}}let u,f=!1;if(!d&&e.sameValueGuard&&(null===s||"object"!=typeof s)){const e=Ia(t,n,r,i);if(Ca(t,n,r,i)&&Object.is(e,s))return!0;u=e,f=!0}const h=l.elementPaths.has(n.pathInfo.path),p=wa(l,n),m=ue(ie(l,n.pathInfo),n.listIndex);null!==$e&&$e({type:"state:write",absoluteAddress:m,value:s,oldValue:u,hasOldValue:f}),Ba(l,c,m,u,f);try{return h?qa(t,n,m,s,r,i,a):za(t,n,m,s,r,i,a)}finally{p&&fa(m,{value:s,dirty:!1}),$a(l,n.pathInfo,{value:s})}}function Va(t,e,n,o){return(e,s,r)=>{const i=U(e);if(o.addressStackLength>0){const t=o.lastAddressStack?.pathInfo??null,e=o.stateElement;null!==t&&t.path!==i.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(i.path,t.path)}i.wildcardParentPathInfos.length>s.length&&et(`indexes length is insufficient: ${e}`);let a=null;for(let e=0;e<i.wildcardParentPathInfos.length;e++){const r=i.wildcardParentPathInfos[e],l=De(r,a),c=Zo(Ia(t,l,n,o));null==c&&et(`ListIndexes not found: ${r.path}`);const d=s[e];a=c[d]??et(`ListIndex not found at index ${d} of ${r.path}`)}const l=De(i,a);if(!(void 0!==r))return Ia(t,l,n,o);Ua(t,l,r,n,o)}}const Ga=new WeakMap;function Ka(t,e,n,o){const s=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return xa(o,s.wildcardPaths.at(-1)??et(`lastWildcardPath is null: ${e.pathInfo.path}`))??et(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let s=null;for(let r=0;r<e.pathInfo.wildcardCount;r++){const i=e.pathInfo.wildcardParentPathInfos[r]??et(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),a=Zo(Ia(t,De(i,s),n,o))??et(`ListIndex not found: ${i.path}`),l=e.wildcardIndexes[r]??et(`wildcardIndex is null: ${e.pathInfo.path}`);s=a[l]??et(`ListIndex not found at index ${l} of ${i.path}`)}return s}case"partial":et(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}const Ja=`${O}${n}`,Xa=`${R}${n}`,Ya=new WeakMap;function Qa(t,e,n,o){const s=v[e];if(void 0!==s){0===o.addressStackLength&&et(`No active state reference to get list index for "${e.toString()}".`);const t=o.lastAddressStack,n=t?.pathInfo;n&&!o.untracking&&o.stateElement?.getterPaths.has(n.path)&&o.stateElement.addIndexDependentGetterPath?.(n.path);const r=t?.listIndex;null==r&&et(`ListIndex not found: ${e.toString()}`);const i=ye(r,s,t.pathInfo.wildcardCount);return i?.index??et(`ListIndex not found: ${e.toString()}`)}if("string"==typeof e){if("$"===e[0]){switch(e){case"$stateElement":return o.stateElement;case"$getAll":return(e,s)=>function(t,e,n,o){const s=Va(t,0,n,o);return(e,r)=>{const i=new Map,a=U(e);if(o.addressStackLength>0){const t=o.lastAddressStack?.pathInfo??null,e=o.stateElement;null!==t&&t.path!==a.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(a.path,t.path)}if(void 0===r){for(let t=0;t<a.wildcardParentPathInfos.length;t++){const e=a.wildcardParentPathInfos[t],n=xa(o,e.path);if(n){r=be(n,n.length-Vn(o.stateElement));break}}void 0===r&&(r=[])}const l=(e,s,r,a,c,d,u)=>{const f=e[s]??null;if(null===f)return void u.push(d);const h=De(f,r),p=Ga.get(h),m=Ia(t,h,n,o),g=ss(Kn(o.stateElement,r),p,m).newIndexes,y=a[c]??null;if(i.set(h,m),null===y)for(let t=0;t<g.length;t++){const n=g[t];l(e,s+1,n,a,c+1,d.concat(n.index),u)}else{const t=g[y]??et(`ListIndex not found at index ${y} of ${f.path}`);s+1<e.length?l(e,s+1,t,a,c+1,d.concat(t.index),u):u.push(d.concat(t.index))}},c=[];l(a.wildcardParentPathInfos,0,null,r,0,[],c);const d=[];for(let t=0;t<c.length;t++)d.push(s(a.path,c[t]));for(const[t,e]of i.entries())Ga.set(t,e);return d}}(t,0,n,o)(e,s);case"$postUpdate":return e=>function(t,e,n,o){const s=o.stateElement;return e=>{const r=da(e),i=Ka(t,r,n,o),a=De(r.pathInfo,i),l=ue(ie(s,a.pathInfo),a.listIndex),c=Xr();c.enqueueAbsoluteAddress(l),ja(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",t=>{const e=ue(ie(s,t.pathInfo),t.listIndex);ha(e),c.enqueueAbsoluteAddress(e)}),$a(s,a.pathInfo)}}(t,0,n,o)(e);case"$resolve":return(e,s,r)=>Va(t,0,n,o)(e,s,r);case"$trackDependency":return t=>function(t,e,n,o){return t=>{0===o.addressStackLength&&et(`No active state reference to track dependency for path "${t}".`);const e=o.lastAddressStack?.pathInfo??et("Internal error: lastAddressStack is null"),n=o.stateElement;o.stateElement.getterPaths.has(e.path)&&e.path!==t&&n.addDynamicDependency(t,e.path)}}(0,0,0,o)(t);case"$untrackDependency":return t=>function(t,e,n,o){return t=>{o.beginUntrack();try{return t()}finally{o.endUntrack()}}}(0,0,0,o)(t);case A:return pi(o.stateElement);case O:return Ci(o.stateElement);case R:return Ei(o.stateElement)}if(!e.startsWith(Ja)&&!e.startsWith(Xa))return}const s=da(e),r=Ka(t,s,n,o),i=De(s.pathInfo,r);return Ia(t,i,n,o)}if("symbol"==typeof e){const s=function(t){let e=Ya.get(t);return void 0===e&&(e=new Map,Ya.set(t,e)),e}(o),r=s.get(e);if(void 0!==r)return r;let i;switch(e){case Qt:i=(t,e=()=>{})=>function(t,e,n){void 0!==t.loopContext&&et("already in loop context"),t.setLoopContext(e);try{t.pushAddress(e);try{return n()}finally{t.popAddress()}}finally{t.clearLoopContext()}}(o,t,e);break;case Zt:i=e=>Ia(t,e,n,o);break;case te:i=e=>Ca(t,e,n,o);break;case ee:i=(e,s)=>Ua(t,e,s,n,o);break;case ne:i=()=>async function(t,e,n){const o=Reflect.get(t,N);"function"==typeof o&&await o.call(n)}(t,0,n);break;case oe:i=()=>function(t,e,n){const o=Reflect.get(t,S);"function"==typeof o&&o.call(n)}(t,0,n);break;case se:i=e=>function(t,e,n,o){const s=Reflect.get(t,I);if("function"==typeof s){const t=new Set,r={};for(const n of e){const e=n.absolutePathInfo.pathInfo;let s;if(s=n.absolutePathInfo.stateName===o.stateName?e.path:e.path+"@"+n.absolutePathInfo.stateName,t.add(s),e.wildcardCount>0){const t=be(n.listIndex,e.wildcardCount),o=r[s];void 0===o?r[s]=[t]:o.push(t)}}return s.call(n,Array.from(t),r)}}(t,e,n,o);break;default:return Reflect.get(t,e,n)}return s.set(e,i),i}}class Za{_stateElement;_stateName;_addressStack=Array(s).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;_untrackDepth=0;constructor(t,e,n){this._stateName=e;const o=zr(t,this._stateName);null===o&&et(`StateHandler: State element with name "${this._stateName}" not found.`),this._stateElement=o,this._mutability=n}get stateName(){return this._stateName}get stateElement(){return this._stateElement}get lastAddressStack(){let t;return this._addressStackIndex>=0&&(t=this._addressStack[this._addressStackIndex]),void 0===t&&et("Last address stack is undefined."),t}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(t){this._addressStackIndex++,this._addressStackIndex>=s&&et("Exceeded maximum address stack depth of 128. Possible infinite loop."),this._addressStack[this._addressStackIndex]=t}popAddress(){if(this._addressStackIndex<0)return null;const t=this._addressStack[this._addressStackIndex];return void 0===t&&et(`Address stack at index ${this._addressStackIndex} is undefined.`),this._addressStack[this._addressStackIndex]=void 0,this._addressStackIndex--,t}setLoopContext(t){this._loopContext=t}clearLoopContext(){this._loopContext=void 0}get untracking(){return this._untrackDepth>0}beginUntrack(){this._untrackDepth++}endUntrack(){this._untrackDepth--}get(t,e,n){return Qa(t,e,n,this)}set(t,e,n,o){return"readonly"===this._mutability&&et(`State "${this._stateName}" is readonly.`),function(t,e,n,o,s){if("string"==typeof e){const r=da(e),i=Ka(t,r,o,s);return Ua(t,De(r.pathInfo,i),n,o,s)}return Reflect.set(t,e,n,o)}(t,e,n,o,this)}has(t,e){return Reflect.has(t,e)}}function tl(t){return function(t){const e=Object.getPrototypeOf(t),n=Object.create(e),o=Object.getOwnPropertyDescriptors(t);for(const t in o){const e=o[t];!1===e.writable&&(e.writable=!0)}return Object.defineProperties(n,o),n}(t)}class el{_webComponent;_innerStateElement;constructor(t,e){this._webComponent=t,this._innerStateElement=Fn(t,e)??et("State element not found for web component.")}_outerLoopContext(t,e){const n=e.pathInfo.wildcardCount,o=Gn(e.stateElement,e.pathInfo),s=Gt(this._webComponent);if(null!==s&&s.listIndex.length===o)return s;if(n>0){const s=function(t,e){if(0===ga)return null;const n=ga-1,o=ma[n];return pa[n]!==t||o?.pathInfo.path!==e?null:o}(this._innerStateElement,t.path),r=s?.listIndex??null;if(null!==r&&r.length===o){return De(U(e.pathInfo.wildcardPaths[n-1]),r)}}return s}get(t,e,n){if("string"!=typeof e)return Reflect.get(t,e,n);{if("then"===e)return;if("$"===e[0])return;if(this._innerStateElement.getterPaths.has(e)&&e in t)return Reflect.get(t,e,n);const o=U(e),s=ie(this._innerStateElement,o),r=to(this._webComponent,s);if(null!==r){const t=this._outerLoopContext(o,r);let e;return r.stateElement.createState("readonly",n=>{n[Qt](t,()=>{e=n[r.pathInfo.path]})}),e}if(e in t)return Reflect.get(t,e,n);et(`Property "${e}" not found in inner state: no mapping rule and no local state property.`)}}set(t,e,n,o){if("string"!=typeof e)return Reflect.set(t,e,n,o);{if(this._innerStateElement.setterPaths.has(e)&&e in t)return Reflect.set(t,e,n,o);const s=U(e),r=ie(this._innerStateElement,s),i=to(this._webComponent,r);if(null!==i){const t=this._outerLoopContext(s,i);return i.stateElement.createState("writable",e=>{e[Qt](t,()=>{e[i.pathInfo.path]=n})}),!0}if(e in t)return Reflect.set(t,e,n,o);et(`Property "${e}" not found in inner state: no mapping rule and no local state property.`)}}has(t,e){if("string"==typeof e){if("$"===e[0])return!1;if((this._innerStateElement.getterPaths.has(e)||this._innerStateElement.setterPaths.has(e))&&e in t)return!0;const n=U(e),o=ie(this._innerStateElement,n);return null!==to(this._webComponent,o)||e in t}return Reflect.has(t,e)}}class nl{_innerStateElement;constructor(t,e){this._innerStateElement=Fn(t,e)??et("State element not found for web component.")}get(t,e,n){if("string"==typeof e){let t;return this._innerStateElement.createState("readonly",n=>{t=n[e]}),t}return Reflect.get(t,e,n)}set(t,e,n,o){return"string"==typeof e?(this._innerStateElement.createState("writable",t=>{t[e]=n}),!0):Reflect.set(t,e,n,o)}}const ol=t=>()=>t;function sl(t,n,o,s){!function(t,e,n){let o=Bn.get(t);o||(o=new Map,Bn.set(t,o)),o.set(e,n)}(n,o,t);const r=n.hasAttribute(e.bindAttributeName)?(i=n,(it.get(i)||null)??[]).filter(t=>t.propSegments[0]===o):[];var i;r.length>0?(!function(t,e,n){if(0===n.length)return;const o=Fn(t,e);null===o&&et("State element not found for web component.");const s=new Map,r=new Map;for(const e of n){const n=Zn(o,e);let i=Yn.get(t);void 0===i?Yn.set(t,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;Qn.set(n,e),s.set(a,l),r.set(l,a),qn(t,l.stateElement)}Jn.set(t,s),Xn.set(t,r)}(n,o,r),t.markComponentStateMapped?.(),t.setInitialState(function(t,e){const n=new el(t,e),o=Fn(t,e);null===o&&et("State element not found for web component."),null===o.boundComponentStateProp&&et("State element is not bound to any component state prop."),o.boundComponentStateProp in t||et(`State element is not bound to a valid component state prop: ${o.boundComponentStateProp}`);const s=t[o.boundComponentStateProp];return"object"==typeof s&&null!==s||et(`Invalid state object for component state prop: ${o.boundComponentStateProp}`),new Proxy(tl(s),n)}(n,o))):t.setInitialState(tl(s));const a=function(t,e){const n=new nl(t,e);return new Proxy({},n)}(n,o);if(Object.defineProperty(n,o,{get:ol(a),enumerable:!0,configurable:!0}),function(t,e){let n=Bo.get(t);n||(n=new Set,Bo.set(t,n)),n.add(e)}(n,o),x in n){const t=n[x];"function"==typeof t?t.call(n,o).catch(t=>{et(`Error in ${x}: ${t instanceof Error?t.message:String(t)}`)}):et(`${x} is not a function.`)}}class rl extends _r{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return qr(t)}__state;_hasUpdatedCallback=!1;_crossRowListPaths=new Set;_indexDependentGetterPaths=new Set;_name="default";_initialized=!1;_initializePromise;_resolveInitialize=null;_connectedCallbackPromise;_resolveConnectedCallback=null;_rejectConnectedCallback=null;_loadingPromise;_resolveLoading=null;_setStatePromise=null;_resolveSetState=null;_listPaths=new Set;_listKeys=null;_elementPaths=new Set;_getterPaths=new Set;_setterPaths=new Set;_loopContextStack=function(t=()=>0){return new di(t)}(()=>Vn(this));_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_watchPaths=null;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_hasMappedComponentState=!1;_bindableEventMap={};_commandTokenNames=new Set;_eventTokenNames=new Set;_dcc=!1;_connectGeneration=0;_streamsStartedGeneration=0;constructor(){super(),this._initializePromise=new Promise(t=>{this._resolveInitialize=t}),this._connectedCallbackPromise=new Promise((t,e)=>{this._resolveConnectedCallback=t,this._rejectConnectedCallback=e}),this._loadingPromise=new Promise(t=>{this._resolveLoading=t}),this._setStatePromise=new Promise(t=>{this._resolveSetState=t})}get _state(){return void 0===this.__state&&et(`${e.tagNames.state} _state is not initialized yet.`),this.__state}set _state(e){this._commandTokenNames=function(t){const e=new Set,n=t[_];if(void 0===n)return e;Array.isArray(n)||et(`${_} must be an array of strings.`);for(const t of n)"string"==typeof t&&0!==t.length||et(`${_} entries must be non-empty strings.`),t===A&&et(`${_} entry "${t}" conflicts with the reserved namespace name "${A}".`),e.has(t)&&et(`${_} entry "${t}" is duplicated.`),e.add(t);return e}(e),this._eventTokenNames=function(t){const e=new Set,n=t[k];if(void 0===n)return e;Array.isArray(n)||et(`${k} must be an array of strings.`);for(const t of n)"string"==typeof t&&0!==t.length||et(`${k} entries must be non-empty strings.`),e.has(t)&&et(`${k} entry "${t}" is duplicated.`),e.add(t);return e}(e),this.__state=e,this._hasUpdatedCallback=I in e,Qe(this),function(t,e,n){const o=e[C];if(void 0!==o){"object"==typeof o&&null!==o||et(`${C} must be an object mapping event-token names to handler functions.`);for(const[e,s]of Object.entries(o))n.has(e)||et(`${C} entry "${e}" is not declared in $eventTokens.${lt(e,n)}`),"function"!=typeof s&&et(`${C} entry "${e}" must be a function.`),Ye(t,e).subscribe(s)}}(this,e,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const s=function(t){const e=new Set,n=new Set,o=sa(t);for(const[t,s]of Object.entries(o))"function"==typeof s.get&&e.add(t),"function"==typeof s.set&&n.add(t);return{getterPaths:e,setterPaths:n}}(e);for(const t of s.getterPaths)this._getterPaths.add(t);for(const t of s.setterPaths)this._setterPaths.add(t);var r;Mi(this),Ii(r=this),vi(r),Ni.delete(r),Pi(this,e),this._listKeys=function(t){const e=t[T];if(void 0===e)return null;"object"==typeof e&&null!==e||et(`${T} must be an object mapping list paths to key specs.`);const s=new Map;for(const[t,r]of Object.entries(e)){0===t.length&&et(`${T} entry path must be a non-empty string.`);const e=t.split(n);e.some(t=>0===t.length)&&et(`${T} entry "${t}" must not contain empty path segments.`),e[e.length-1]===o&&et(`${T} entry "${t}" must be the list path itself, not the element path (drop the trailing "${n}${o}").`),"function"!=typeof r?("string"!=typeof r&&et(`${T} entry "${t}" key spec must be a field name (string) or a function.`),0===r.length&&et(`${T} entry "${t}" key field name must be a non-empty string.`),(r.includes(n)||r.includes(o))&&et(`${T} entry "${t}" key field name "${r}" must be a flat property name ("${n}" / "${o}" are not allowed).`),r in Object.prototype&&et(`${T} entry "${t}" key field name "${r}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),s.set(t,r)):s.set(t,r)}return s.size>0?s:null}(e),function(t){ji.delete(t),Wi.delete(t)}(this),function(t){Ui.delete(t)}(this),this._watchPaths=qi(this,e),this._initialized&&null!==this._rootNode&&!t()&&(Gi(this),Ri(this),this._streamsStartedGeneration=this._connectGeneration),this._resolveLoading?.()}get name(){return this._name}_loadFromSsrElement(){if(!this.hasAttribute("enable-ssr"))return null;const t=this.getAttribute("name")||"default",e=this.parentNode;if(!e)return null;const n=Tr.findByName(e,t);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null}async _initialize(){const n=t()?null:this._loadFromSsrElement();try{if(this.hasAttribute("state")){const t=this.getAttribute("state");this._state=function(t){const e=document.getElementById(t);if(e&&"application/json"===e.type)try{return JSON.parse(e.textContent||"{}")}catch(t){et("Failed to parse JSON from script element:"+t)}return{}}(t)}else if(this.hasAttribute("src")){const t=this.getAttribute("src");t&&t.endsWith(".json")?this._state=await async function(t){try{const e=await fetch(t);return e.ok||et(`Failed to fetch JSON file: ${e.statusText}`),await e.json()}catch(t){return console.error("Failed to load JSON file:",t),{}}}(t):t&&t.endsWith(".js")?this._state=await ci(t):et(`Unsupported src file type: ${t}`)}else if(this.hasAttribute("json")){const t=this.getAttribute("json");this._state=JSON.parse(t)}else{const t=this.querySelector('script[type="module"]');if(t)this._state=await li(t,`${this._name}`);else{const t=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${e.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(t)}}}catch(t){et(`Failed to initialize state: ${t}`)}if(null!==n&&this.__state)for(const[t,e]of Object.entries(n)){if(t in this.__state){const e=Object.getOwnPropertyDescriptor(this.__state,t);if(e&&(e.get||e.set))continue;if("function"==typeof this.__state[t])continue}this.__state[t]=e}await this._loadingPromise,this._name=this.getAttribute("name")||"default",Ur(this.rootNode,this._name,this)}async _initializeBindWebComponent(){if(this.hasAttribute("bind-component")){const t=this.parentNode,n=t instanceof ShadowRoot?t.host:t instanceof Element?t:null,o=n?G(n):null;null!==n&&null!==o||et(`"bind-component" requires <${e.tagNames.state}> to be a direct child of a custom element.`),t instanceof ShadowRoot||this.hasAttribute("name")||et('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const s=["state","src","json"].filter(t=>this.hasAttribute(t));null!==this.querySelector('script[type="module"]')&&s.push('<script type="module">'),s.length>0&&et(`"bind-component" cannot be combined with ${s.join(", ")}. The component's "${this.getAttribute("bind-component")}" property is the only state source.`);const r=this.getAttribute("bind-component");await customElements.whenDefined(o.toLowerCase()),n.hasAttribute(e.bindAttributeName)&&await B(n),r in n||et(`Component does not have property "${r}" for state binding.`);const i=n[r];"object"==typeof i&&null!==i||et(`Component property "${r}" is not an object for state binding.`),this._boundComponent=n,this._boundComponentStateProp=r,sl(this,this._boundComponent,this._boundComponentStateProp,i)}}_initializeLightDomComponentScope(){const t=this._boundComponent;null!==t&&this.parentNode===t&&t.hasAttribute(e.bindAttributeName)&&(Ir(this._rootNode,t),or(t,null))}_reloadMappedPathsAfterReconnect(){if(!this._hasMappedComponentState||null===this._boundComponent)return;const t=function(t){const e=Yn.get(t);if(void 0===e)return[];const n=[];for(const t of e)n.push(t.innerAbsPathInfo.pathInfo.path);return n}(this._boundComponent);!function(t){const e=Yn.get(t);if(void 0===e)return;const n=new Map,o=new Map;for(const t of e)n.set(t.innerAbsPathInfo,t.outerAbsPathInfo),o.set(t.outerAbsPathInfo,t.innerAbsPathInfo);Jn.set(t,n),Xn.set(t,o)}(this._boundComponent),this.createState("readonly",e=>{for(const n of t)e.$postUpdate(n)})}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{N in t&&await t[ne]()})}async _initializeDCC(t,n){let o;try{if(this.hasAttribute("src")){const t=this.getAttribute("src");t.endsWith(".js")?o=await ci(t):et(`DCC: Unsupported src type: ${t}`)}else{const e=this.querySelector('script[type="module"]');e?o=await li(e,t.tagName.toLowerCase()):et(`DCC: No state source found for "${t.tagName.toLowerCase()}".`)}}catch(t){et(`DCC: Failed to load state: ${t}`)}!function(t,n,o){const s=t.tagName.toLowerCase();s.includes("-")||et(`DCC: "${s}" is not a valid custom element name (must contain a hyphen).`),customElements.get(s)&&et(`DCC: "${s}" is already registered. A custom element name can only be defined once.`);const r=document.createElement("template");r.innerHTML=n.innerHTML;const i=n.mode,{bindables:a,commands:l,streamBackedBindables:c}=aa(o),d=a.length>0||l.length>0?function(t,e,n=[]){const o={protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`,getter:t=>t.target[e]})),inputs:e.map(t=>({name:t}))};if(0===n.length)return o;const s=n.map(t=>({name:t,async:!0}));return{...o,commands:s}}(s,a,l):null,u=a.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(s,a):{},f=`${e.tagNames.state}:not([name])`,h=class extends HTMLElement{static template=r;static shadowRootMode=i;static wcBindable=d;static bindableEventMap=u;_shadow=null;_ensureShadow(){if(null!==this._shadow)return this._shadow;if(this.hasAttribute(D))return null;this._shadow=this.attachShadow({mode:h.shadowRootMode}),this._shadow.appendChild(h.template.content.cloneNode(!0));const t=K();return null!==t&&J(t,this._shadow),this._shadow}connectedCallback(){const t=this._ensureShadow();if(null!==t&&Object.keys(h.bindableEventMap).length>0){const n=t.querySelector(f);n?n.setBindableEventMap(h.bindableEventMap):console.warn(`[@wcstack/state] DCC: "${s}" declares ${$} but its template has no <${e.tagNames.state}> without a "name" attribute. Change events will not be dispatched.`)}}get stateElement(){return this._ensureShadow()?.querySelector(f)??null}},p=sa(o);for(const[t,e]of Object.entries(p)){if(oa(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=na(t,o)}else n.get=ta(t),n.set=ea(t);Object.defineProperty(h.prototype,t,n)}for(const t of c)Object.defineProperty(h.prototype,t,{configurable:!0,enumerable:!0,get:ta(t),set:ea(t)});customElements.define(s,h)}(t,n,o),this._dcc=!0,this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",t=>{S in t&&t[oe]()})}async connectedCallback(){this._rootNode=this.getRootNode();const n=++this._connectGeneration;if(this._initialized)this._dcc||zr(this._rootNode,this._name)===this||(Ur(this._rootNode,this._name,this),this._reloadMappedPathsAfterReconnect());else{const t=this.parentNode;if(t instanceof ShadowRoot&&t.host.hasAttribute(D))return this.hasAttribute("bind-component")&&et(`"bind-component" cannot be used inside a [${D}] host. DCC state comes from the template, not from a component property.`),void await this._initializeDCC(t.host,t);await this._initializeBindWebComponent(),await this._initialize(),this._initialized=!0,this._initializeLightDomComponentScope(),this._resolveInitialize?.()}if(this.hasAttribute("enable-ssr")&&!t()||await this._callStateConnectedCallback(),t()&&this.hasAttribute("enable-ssr"))try{await qr(this.rootNode);const t=this.getAttribute("name")||"default",n=Tr.extractStateData(this),o=document.createElement(e.tagNames.ssr);o.setAttribute("name",t),o.setAttribute("version",Pr),Tr.buildContent(o,n),this.parentNode?.insertBefore(o,this)}catch(t){throw this._rejectConnectedCallback?.(t),t}t()||null===this._rootNode||n!==this._connectGeneration||Gi(this),t()||null===this._rootNode||n!==this._connectGeneration||this._streamsStartedGeneration===n||Ri(this),this._resolveConnectedCallback?.()}disconnectedCallback(){if(null!==this._rootNode)try{this._callStateDisconnectedCallback()}finally{Ur(this.rootNode,this._name,null),t=this,ui.delete(t),function(t){hi.delete(t)}(this),Qe(this),Ii(this),Mi(this),function(t){ji.delete(t)}(this),this._rootNode=null}var t}get initialized(){return this._initialized}get initializePromise(){return this._initializePromise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get listPaths(){return this._listPaths}get listKeys(){return this._listKeys}get watchPaths(){return this._watchPaths}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&&et("State rootNode is not available."),this._rootNode}get hasRootNode(){return null!==this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get boundComponent(){return this._boundComponent}get hasMappedComponentState(){return this._hasMappedComponentState}markComponentStateMapped(){this._hasMappedComponentState=!0}get bindableEventMap(){return this._bindableEventMap}get commandTokenNames(){return this._commandTokenNames}get eventTokenNames(){return this._eventTokenNames}setBindableEventMap(t){this._bindableEventMap=t}_addDependency(t,e,n){const o=t.get(e);return void 0===o?(t.set(e,[n]),!0):!o.includes(n)&&(o.push(n),!0)}addDynamicDependency(t,e){return this._addDependency(this._dynamicDependency,t,e)}addStaticDependency(t,e){return this._addDependency(this._staticDependency,t,e)}setPathInfo(t,e){if("for"===e){const e=!this._listPaths.has(t);this._listPaths.add(t),this._elementPaths.add(t+"."+o),e&&this._hasMappedComponentState&&function(t,e){const n=no(t,U(e));null!==n&&n.stateElement!==t&&n.stateElement.setPathInfo(n.pathInfo.path,"for")}(this,t)}if(!this._pathSet.has(t)){const e=U(t);if(this._pathSet.add(t),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=U(t.parentPath)}}}_createState(t,e,n){try{const o=function(t,e,n,o){const s=new Za(t,n,o);return new Proxy(e,s)}(t,this._state,this._name,e);return n(o)}finally{}}async createStateAsync(t,e){return await this._createState(this.rootNode,t,e)}createState(t,e){this._createState(this.rootNode,t,e)}nextVersion(){return this._version++,this._version}get hasUpdatedCallback(){return this._hasUpdatedCallback}get crossRowListPaths(){return this._crossRowListPaths}addCrossRowListPath(t){this._crossRowListPaths.add(t)}get indexDependentGetterPaths(){return this._indexDependentGetterPaths}addIndexDependentGetterPath(t){this._indexDependentGetterPaths.add(t)}bindProperty(t,e){Object.defineProperty(this._state,t,e),t===I&&(this._hasUpdatedCallback=!0)}setInitialState(t){this._initialized?this._state=t:this._resolveSetState?.(t)}}function il(){customElements.get(e.tagNames.ssr)||customElements.define(e.tagNames.ssr,Tr),customElements.get(e.tagNames.state)||customElements.define(e.tagNames.state,rl)}await(il(),void ii());
1
+ const e=Symbol.for("wcstack.ssr.snapshotBuilder");function t(){const e=document.documentElement;return!!e&&e.hasAttribute("data-wcs-server")}const n={bindAttributeName:"data-wcs",commentTextPrefix:"wcs-text",commentForPrefix:"wcs-for",commentIfPrefix:"wcs-if",commentElseIfPrefix:"wcs-elseif",commentElsePrefix:"wcs-else",tagNames:{state:"wcs-state",ssr:"wcs-ssr"},locale:"en",debug:!1,enableMustache:!0,enableDirectionalInitialSync:!0,enablePropagationContext:!0,enableContractAnalyzer:!1,sameValueGuard:!0},o=n;const s=".",r="*",i=128,a="|",l="prevent",c="stop",d="ro",u="init",f="sync",h="else",p="...",m="on",g="eventToken",b="command",y="class",w="attr",v="style",N={};for(let e=0;e<128;e++)N[`$${e+1}`]=e;const S=Object.freeze(N),I="$connectedCallback",x="$disconnectedCallback",$="$updatedCallback",P="$stateReadyCallback",_="$bindables",A="$commands",k="$commandTokens",C="$command",E="$eventTokens",M="$on",T="$streams",O="$watch",R="$listKeys",D="$streamStatus",L="$streamError",j="data-wc-definition",W=new WeakMap,B=new WeakSet;let F=0;async function z(e){const t=function(e){let t,n=W.get(e)||null;if(null!==n)return n;const o=new Promise(e=>{t=e});return n={id:++F,promise:o,resolve:t},W.set(e,n),B.has(e)&&n.resolve(),n}(e);await t.promise}function q(e){const t=W.get(e);void 0===t?B.add(e):t.resolve()}const U=new Map;let V=0;function H(e){let t=U.get(e);return void 0!==t||(t=Object.freeze(new G(e)),U.set(e,t)),t}class G{id=++V;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:H(t),n=e.split("."),o=[],s=[],i=[],a={},l=[],c=[],d=[],u=[];let f="",h="",p=0;for(let e=0;e<n.length;e++)f+=n[e],n[e]===r&&(i.push(f),a[f]=p,l.push(t(f)),c.push(h),d.push(t(h)),u.push(e),p++),o.push(f),s.push(t(f)),h=f,f+=".";const m=i.length>0?i[i.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=i,this.wildcardPathSet=new Set(i),this.indexByWildcardPath=a,this.wildcardPathInfos=l,this.wildcardPathInfoSet=new Set(l),this.wildcardParentPaths=c,this.wildcardParentPathSet=new Set(c),this.wildcardParentPathInfos=d,this.wildcardParentPathInfoSet=new Set(d),this.wildcardPositions=u,this.lastWildcardPath=m,this.lastWildcardInfo=m?t(m):null,this.parentPath=g,this.parentPathInfo=g?t(g):null,this.wildcardCount=p}}const K=new WeakMap;function J(e){const t=K.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{K.set(e,n)}}function X(e){if("object"!=typeof e||null===e)return null;const t=e;return"function"!=typeof t.get||"function"!=typeof t.whenDefined?null:t}function Y(e=null){if(null!=e){const{customElementRegistry:t,customElements:n}=e;if(null===t)return null;if(void 0!==t)return X(t);if(void 0!==n)return X(n)}return X(globalThis.customElements)}function Q(e,t){e.upgrade?.(t)}function Z(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=oe(s.properties,ee);if(null===r)return null;const i=void 0===s.inputs?new Map:oe(s.inputs,te);if(null===i)return null;const a=void 0===s.commands?new Map:oe(s.commands,ne);return null===a?null:{target:e,liveDeclaration:s,knownProperties:r,declaredInputs:i,declaredCommands:a}}catch{return null}}function ee(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 te(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 ne(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 oe(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 se(e){throw new Error(`[@wcstack/state] ${e}`)}function re(e,t,n){const o="."===t?`.${e}`:`${t}.${e}`;return{propName:e,propSegments:[e],propModifiers:[],statePathName:o,statePathInfo:H(o),stateName:n,inFilters:[],outFilters:[],bindingType:"prop"}}function ie(e){switch(e.bindingType){case"prop":case"event":case"radio":case"checkbox":return`${e.bindingType}::${e.propName}`;default:return null}}function ae(e,t,n={}){const s=n.allowDeferred??!0;if(!t.some(e=>"spread"===e.bindingType))return t;const r=[],i=new WeakSet;for(const n of t){if("spread"!==n.bindingType){r.push(n);continue}e.nodeType!==Node.ELEMENT_NODE&&se("Spread binding requires an element node.");const t=e,o=J(t);null===o&&se(`Spread binding "${n.statePathName}" requires a custom element with wcBindable, but <${t.tagName.toLowerCase()}> is not a custom element.`);const a=Y(t);null===a&&se(`CustomElementRegistry is unavailable for <${o}>.`);if(void 0===a.get(o)){s||se(`Spread binding "${n.statePathName}" requires <${o}> to be registered. Define the custom element before initializing this binding.`),r.push(n);continue}Q(a,t);const l=Z(t);null===l&&se(`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=re(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=re(e,c,d);i.add(t),r.push(t)}}const a=new Map;for(let e=0;e<r.length;e++){const t=ie(r[e]);null!==t&&a.set(t,e)}const l=[];for(let t=0;t<r.length;t++){const n=ie(r[t]);if(null!==n){if(a.get(n)===t)l.push(r[t]);else if(o.debug&&i.has(r[t])){const o=r[a.get(n)],s=e.nodeType===Node.ELEMENT_NODE?`<${e.tagName.toLowerCase()}>`:"node";console.debug(`[@wcstack/state] spread: prop "${r[t].propName}" of ${s} overridden by explicit binding (statePath: "${o.statePathName}").`)}}else l.push(r[t])}return l}function le(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 ce=new WeakMap;function de(e,t,n){if(Math.abs(e.length-t.length)>n)return n+1;const o=new Array(t.length+1),s=new Array(t.length+1);for(let e=0;e<=t.length;e++)o[e]=e;for(let n=1;n<=e.length;n++){s[0]=n;for(let r=1;r<=t.length;r++){const i=e[n-1]===t[r-1]?0:1;s[r]=Math.min(o[r]+1,s[r-1]+1,o[r-1]+i)}for(let e=0;e<=t.length;e++)o[e]=s[e]}return o[t.length]}function ue(e,t){if(0===e.length)return"";const n=e.toLowerCase();let o=null,s=3;for(const e of t){const t=de(n,e.toLowerCase(),2);t<s&&(o=e,s=t)}return null!==o?` Did you mean "${o}"?`:""}const fe=" Validate statically: npx @wcstack/lint <file>.",he=new Set(["if","elseif","else","for"]);function pe(e){se(`filter ${e} requires at least one option`)}function me(e){se(`filter ${e} requires a number as option`)}function ge(e){se(`filter ${e} requires a number value`)}function be(e){se(`filter ${e} requires a date value`)}function ye(e){return!(!e||isNaN(Number(e)))}const we={eq:e=>{const t=e?.[0]??pe("eq");return e=>"number"==typeof e?(ye(t)||me("eq"),e===Number(t)):e===t},ne:e=>{const t=e?.[0]??pe("ne");return e=>"number"==typeof e?(ye(t)||me("ne"),e!==Number(t)):e!==t},not:e=>e=>("boolean"!=typeof e&&se(`filter ${"not"} requires a boolean value`),!e),lt:e=>{const t=e?.[0]??pe("lt");return ye(t)||me("lt"),e=>("number"!=typeof e&&ge("lt"),e<Number(t))},le:e=>{const t=e?.[0]??pe("le");return ye(t)||me("le"),e=>("number"!=typeof e&&ge("le"),e<=Number(t))},gt:e=>{const t=e?.[0]??pe("gt");return ye(t)||me("gt"),e=>("number"!=typeof e&&ge("gt"),e>Number(t))},ge:e=>{const t=e?.[0]??pe("ge");return ye(t)||me("ge"),e=>("number"!=typeof e&&ge("ge"),e>=Number(t))},inc:e=>{const t=e?.[0]??pe("inc");return ye(t)||me("inc"),e=>("number"!=typeof e&&ge("inc"),e+Number(t))},dec:e=>{const t=e?.[0]??pe("dec");return ye(t)||me("dec"),e=>("number"!=typeof e&&ge("dec"),e-Number(t))},mul:e=>{const t=e?.[0]??pe("mul");return ye(t)||me("mul"),e=>("number"!=typeof e&&ge("mul"),e*Number(t))},div:e=>{const t=e?.[0]??pe("div");return ye(t)||me("div"),e=>("number"!=typeof e&&ge("div"),e/Number(t))},mod:e=>{const t=e?.[0]??pe("mod");return ye(t)||me("mod"),e=>("number"!=typeof e&&ge("mod"),e%Number(t))},abs:e=>e=>("number"!=typeof e&&ge("abs"),Math.abs(e)),clamp:e=>{const t=e?.[0]??pe("clamp");ye(t)||me("clamp");const n=e?.[1]??pe("clamp");ye(n)||me("clamp");const o=Number(t),s=Number(n);return e=>("number"!=typeof e&&ge("clamp"),Math.min(Math.max(e,o),s))},fix:e=>{const t=e?.[0]??"0";return ye(t)||me("fix"),e=>("number"!=typeof e&&ge("fix"),e.toFixed(Number(t)))},locale:e=>{const t=e?.[0];return e=>("number"!=typeof e&&ge("locale"),e.toLocaleString(t??o.locale))},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]??pe("slice");ye(n)||me("slice"),t.push(Number(n));const o=e?.[1];return void 0!==o&&(ye(o)||me("slice"),t.push(Number(o))),e=>String(e).slice(...t)},substr:e=>{const t=e?.[0]??pe("substr");ye(t)||me("substr");const n=e?.[1]??pe("substr");return ye(n)||me("substr"),e=>String(e).substr(Number(t),Number(n))},pad:e=>{const t=e?.[0]??pe("pad");ye(t)||me("pad");const n=e?.[1]??"0";return e=>String(e).padStart(Number(t),n)},rep:e=>{const t=e?.[0]??pe("rep");return ye(t)||me("rep"),e=>String(e).repeat(Number(t))},rev:e=>e=>String(e).split("").reverse().join(""),truncate:e=>{const t=e?.[0]??pe("truncate");ye(t)||me("truncate");const n=Number(t),o=e?.[1]??"…";return e=>{const t=String(e);return t.length<=n?t:t.slice(0,n)+o}},join:e=>{const t=e?.[0]??", ";return e=>(Array.isArray(e)||se(`filter ${"join"} requires an array value`),e.join(t))},int:e=>e=>parseInt(String(e),10),float:e=>e=>parseFloat(String(e)),round:e=>{const t=e?.[0]??"0";return ye(t)||me("round"),e=>{"number"!=typeof e&&ge("round");const n=Math.pow(10,Number(t));return Math.round(e*n)/n}},floor:e=>{const t=e?.[0]??"0";return ye(t)||me("floor"),e=>{"number"!=typeof e&&ge("floor");const n=Math.pow(10,Number(t));return Math.floor(e*n)/n}},ceil:e=>{const t=e?.[0]??"0";return ye(t)||me("ceil"),e=>{"number"!=typeof e&&ge("ceil");const n=Math.pow(10,Number(t));return Math.ceil(e*n)/n}},percent:e=>{const t=e?.[0]??"0";return ye(t)||me("percent"),e=>("number"!=typeof e&&ge("percent"),`${(100*e).toFixed(Number(t))}%`)},unit:e=>{const t=e?.[0]??pe("unit");return e=>null==e?e:String(e)+t},date:e=>{const t=e?.[0];return e=>(e instanceof Date||be("date"),e.toLocaleDateString(t??o.locale))},time:e=>{const t=e?.[0];return e=>(e instanceof Date||be("time"),e.toLocaleTimeString(t??o.locale))},datetime:e=>{const t=e?.[0];return e=>(e instanceof Date||be("datetime"),e.toLocaleString(t??o.locale))},ymd:e=>{const t=e?.[0]??"-";return e=>{e instanceof Date||be("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}`}},hms:e=>{const t=e?.[0]??":";return e=>{e instanceof Date||be("hms");const n=e.getHours().toString().padStart(2,"0"),o=e.getMinutes().toString().padStart(2,"0"),s=e.getSeconds().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]??pe("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},ve=we,Ne={input:we,output:ve},Se=(e,t)=>n=>{const o=n[e];return o||se(`[wcs/filter-unknown] filter not found: ${e}.${ue(e,Object.keys(n))}${fe}`),o(t)};function Ie(e,t,n){const o=-1===t?e.length:t;let s=0;for(;s<o&&/\s/.test(e[s]);)s++;const r=-1===n?0:n;let i=e.length;for(;i>r&&/\s/.test(e[i-1]);)i--;return e.slice(s,i)}const xe=new Map;function $e(e,t){const n=Ne[t];return e.map(e=>{const o=e.indexOf("("),s=e.lastIndexOf(")");if(-1!==o&&-1===s&&se(`Invalid filter format: missing closing parenthesis in "${e}"`),-1!==s&&-1===o&&se(`Invalid filter format: missing opening parenthesis in "${e}"`),-1===o){const o=e.trim(),s=`${o}():${t}`;let r=xe.get(s);return void 0===r&&(r=Se(o,[])(n),xe.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,r=-1,i=-1;const a=()=>{t.push(Ie(n,r,i)),n="",s=!1,r=-1,i=-1};for(let t=0;t<e.length;t++){const l=e[t];o?l===o?o=null:(-1===r&&(r=n.length),n+=l,i=n.length):'"'===l||"'"===l?(o=l,s=!0):","===l?a():n+=l}const l=Ie(n,r,i);return(l||s)&&t.push(l),t}(r),l=`${i}(${a.join(",")}):${t}`;let c=xe.get(l);return void 0===c&&(c=Se(i,a)(n),xe.set(l,c)),{filterName:i,args:a,filterFn:c}}})}const Pe=e=>e.trim(),_e=new Map;const Ae=new Map;function ke(e){const t=e.indexOf(a);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(a).map(Pe),r=$e(o,"output"),Ae.set(s,r))):n=e.trim();const[i,l="default"]=n.split("@").map(Pe);return{stateName:l,statePathName:i,statePathInfo:H(i),outFilters:r}}function Ce(e){const[...t]=e.split(";").map(Pe).filter(e=>e.length>0),n=t.map(e=>{const t=e.indexOf(":");-1===t&&se(`Invalid bindText: "${e}". Missing ':' separator between propPart and statePart.`);const n=e.slice(0,t).trim(),o=e.slice(t+1).trim();if(n===h){const e=H("#else");return{propName:h,propSegments:[h],propModifiers:[],statePathName:"#else",statePathInfo:e,stateName:"",inFilters:[],outFilters:[],bindingType:"else"}}if(n===p){const t=ke(o);return t.outFilters.length>0&&se(`Invalid spread binding "${e}": filters are not allowed on spread targets.`),0===t.statePathName.length&&se(`Invalid spread binding "${e}": spread target path is required.`),{propName:p,propSegments:[p],propModifiers:[],inFilters:[],...t,bindingType:"spread"}}if("if"===n||"elseif"===n||"for"===n||"radio"===n||"checkbox"===n){return{propName:n,propSegments:[n],propModifiers:[],inFilters:[],...ke(o),bindingType:n}}{const e=ke(o),t=function(e){const t=e.indexOf(a);let n="",o=[],r="",i=[];-1!==t?(n=e.slice(0,t).trim(),r=e.slice(t+1).trim(),_e.has(r)?i=_e.get(r):(o=r.split(a).map(Pe),i=$e(o,"input"),_e.set(r,i))):n=e.trim();const[l,c]=n.split("#").map(Pe),d=l.split(s).map(Pe);return{propName:l,propSegments:d,propModifiers:c?c.split(",").map(Pe):[],inFilters:i}}(n);return t.propSegments[0]===g||t.propSegments[0].startsWith(m)?{...t,...e,bindingType:"event"}:{...t,...e,bindingType:"prop"}}});if(n.length>1){n.some(e=>he.has(e.bindingType))&&se(`[wcs/template-syntax] Invalid bindText: "${e}". 'if', 'elseif', 'else', and 'for' bindings must be single binding. Put the structural binding alone in its own data-wcs (e.g. <template data-wcs="for: items">).${fe}`)}return n}const Ee=new WeakMap,Me=new Set([o.commentTextPrefix,o.commentForPrefix,o.commentIfPrefix,o.commentElseIfPrefix,o.commentElsePrefix]),Te=new RegExp("^\\s*@@\\s*(.*?)\\s*:\\s*(.+?)\\s*$");function Oe(e){const t=Ee.get(e);if("string"==typeof t)return t;if(e.nodeType!==Node.COMMENT_NODE)return null;const n=e.data.trim(),s=Te.exec(n);if(null===s)return null;const r=s[1]||o.commentTextPrefix;return Me.has(r)?(Ee.set(e,s[2]),s[2]):null}function Re(e){return{propName:"textContent",propSegments:["textContent"],propModifiers:[],inFilters:[],...ke(e),bindingType:"text"}}const De=new Map;function Le(e,t,n){if(null===n)De.delete(e);else{De.set(e,n);const o=n.parseBindTextResult,s=Si(t,o.stateName);null===s&&se(`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=Si(t,n.stateName);null===e&&se(`State element with name "${n.stateName}" not found for fragment info node.`),e.setPathInfo(n.statePathName,n.bindingType)}}}function je(e){return De.get(e)||null}function We(e){if(e.nodeType===Node.ELEMENT_NODE){return Ce(e.getAttribute(o.bindAttributeName)||"")}if(e.nodeType===Node.COMMENT_NODE){const t=Oe(e);null===t&&se("Comment node binding text not found.");const n=je(t);let o=n?.parseBindTextResult??null,s=null;return null===o?(o=Re(t),s=null):s=t,[{...o,uuid:s}]}return[]}function Be(e){if(!e.hasAttribute("bind-component"))return!1;const t=e.parentNode;return t instanceof Element&&t.hasAttribute(o.bindAttributeName)}function Fe(e){const t=[],n=e.querySelectorAll(`${o.tagNames.state}[bind-component]`);for(const o of n){if(!Be(o))continue;const n=o.parentNode;n!==e&&t.push(n)}return t}function ze(e,t){for(let n=0;n<t.length;n++){const o=t[n];if(o!==e&&o.contains(e))return!0}return!1}function qe(e){const t=[],n=Fe(e),s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,{acceptNode(e){if(e.nodeType===Node.ELEMENT_NODE){return e.hasAttribute(o.bindAttributeName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}return null!==Oe(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;s.nextNode();){const e=s.currentNode;n.length>0&&ze(e,n)||t.push(e)}return t}const Ue=new WeakSet;function Ve(e,t,n){const o=ae(e,t,{allowDeferred:n.allowDeferred});if(o.some(e=>"spread"===e.bindingType)){const n=e.nodeType===Node.ELEMENT_NODE?J(e):null;return null===n&&se("Spread binding deferred but element is not a custom element."),{bindings:[],deferred:{node:e,tagName:n,parseResults:t}}}Ue.add(e);const s=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,o);return function(e,t){ce.set(e,t)}(e,s),q(e),{bindings:s,deferred:null}}function He(e){const t=qe(e),n=[],o=[];for(const e of t){if(Ue.has(e))continue;const t=Ve(e,We(e),{allowDeferred:!0});null===t.deferred?n.push(...t.bindings):o.push(t.deferred)}return[t,n,o]}function Ge(e){Ue.add(e)}function Ke(e){const{node:t,parseResults:n}=e;!function(e){Ue.delete(e)}(t);return Ve(t,n,{allowDeferred:!1}).bindings}const Je=new WeakMap;function Xe(e){let t=e;for(;t;){const e=Je.get(t);if(e)return e;t=t.parentNode}return null}function Ye(e,t){null!==t?Je.set(e,t):Je.delete(e)}let Qe=null;const Ze=new WeakMap;function et(e){return Ze.get(e)??[]}function tt(e,t){Ze.set(e,t)}const nt=Symbol("$$setLoopContext"),ot=Symbol("$$getByAddress"),st=Symbol("$$hasByAddress"),rt=Symbol("$$setByAddress"),it=Symbol("$$connectedCallback"),at=Symbol("$$disconnectedCallback"),lt=Symbol("$$updatedCallback"),ct=new WeakMap;function dt(e,t){if(ct.has(e)){const n=ct.get(e);if(n.has(t))return n.get(t)}else ct.set(e,new WeakMap);const n=Object.freeze(new ut(e,t));return ct.get(e).set(t,n),n}class ut{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=dt(e,t.parentPathInfo)}}const ft=new WeakMap,ht=new WeakMap;class pt{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]===r?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAbsoluteAddress=mt(e,t)}}function mt(e,t){if(null===t){let t=ht.get(e);return void 0!==t||(t=new pt(e,null),ht.set(e,t)),t}{let n=ft.get(t);void 0===n&&(n=new WeakMap,ft.set(t,n));let o=n.get(e);return void 0!==o||(o=new pt(e,t),n.set(e,o)),o}}const gt=new WeakMap;function bt(e,t){null===t?gt.delete(e):gt.set(e,t)}function yt(e){return gt.get(e)||null}const wt=new Map;function vt(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=wt.get(s);if(void 0!==r)return r;return r=n.wildcardPathSet.intersection(o.wildcardPathSet).size,wt.set(s,r),r}function Nt(e,t,n){return t<0||t>=n?null:e.at(t-n)}function St(e,t){const n=e.indexes??[];return n.length===t?n:n.slice(n.length-t)}const It=new WeakMap;function xt(e){const t=Xe(e.node);if(null===t)return null;let n=It.get(t);if(void 0===n)n=new WeakMap,It.set(t,n);else{const t=n.get(e);if(void 0!==t)return t}let o=null;try{const n=vt(t.pathInfo,e.statePathInfo);return n>0&&(o=Nt(t.listIndex,n-1,t.pathInfo.wildcardCount)),o}finally{n.set(e,o)}}const $t=new WeakMap;function Pt(e,t){if(null!=t)return t;let n=e.replaceNode.getRootNode();if(!1===e.replaceNode.isConnected){const t=yt(n);null===t?se(`Cannot get absolute state address for disconnected binding: ${e.bindingType} ${e.statePathName} on ${e.node.nodeName}`):n=t}return n}function _t(e,t){let n=null;if(n=$t.get(e)||null,null!==n)return n;const o=Pt(e,t),s=xt(e),r=Si(o,e.stateName);null===r&&se(`State element with name "${e.stateName}" not found for binding.`);return n=mt(dt(r,e.statePathInfo),s),$t.set(e,n),n}function At(e){$t.delete(e)}const kt=new WeakMap;function Ct(e,t){const n=kt.get(e);void 0===n?kt.set(e,t):n instanceof Set?n.add(t):n!==t&&kt.set(e,new Set([n,t])),null!==Qe&&Qe({type:"state:binding-added",absoluteAddress:e,binding:t})}function Et(e,t){const n=kt.get(e);void 0!==n&&(n instanceof Set?n.delete(t):n===t&&kt.delete(e),null!==Qe&&Qe({type:"state:binding-removed",absoluteAddress:e,binding:t}))}const Mt=new WeakMap;function Tt(e,t,n){let o=Mt.get(e);void 0===o&&(o=new WeakMap,Mt.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!==Qe&&Qe({type:"state:binding-added",absoluteAddress:mt(e,t),binding:n})}function Ot(e,t,n){const o=Mt.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!==Qe&&Qe({type:"state:binding-removed",absoluteAddress:mt(e,t),binding:n}))}function Rt(e){const t=kt.get(e);return void 0!==t?t:null!==e.listIndex?Mt.get(e.absolutePathInfo)?.get(e.listIndex):void 0}const Dt=new WeakMap,Lt=new WeakMap;class jt{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]===r?this.listIndex?.parentListIndex??null:this.listIndex,this._parentAddress=Wt(e,t)}}function Wt(e,t){if(null===t){let t=Lt.get(e);return void 0!==t||(t=new jt(e,null),Lt.set(e,t)),t}{let n=Dt.get(t);void 0===n&&(n=new WeakMap,Dt.set(t,n));let o=n.get(e);return void 0!==o||(o=new jt(e,t),n.set(e,o)),o}}const Bt=new WeakMap;function Ft(e){let t=null;if(t=Bt.get(e)||null,null!==t)return t;if(e.statePathInfo.wildcardCount>0){const n=xt(e);null===n&&se(`Cannot resolve state address for binding with wildcard statePathName "${e.statePathName}" because list index is null.`),t=Wt(e.statePathInfo,n)}else t=Wt(e.statePathInfo,null);return Bt.set(e,t),t}function zt(e){Bt.delete(e)}function qt(){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 Ut=new Map,Vt=qt();function Ht(e,t){const n=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.statePathName}::${t}::${n}`}function Gt(e){let t="input";for(const n of e.propModifiers)n.startsWith(m)&&(t=n.slice(2));return t}function Kt(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(d)){const s=Gt(e),r=Ht(e,s);let i=Ut.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=Si(s.getRootNode(),t);null===a&&se(`State element with name "${t}" not found for two-way binding.`);const l=Xe(s);a.createState("writable",e=>{e[nt](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]:[]})})},Ut.set(r,i)),e.node.addEventListener(s,i),Vt.add(r,e),!0}var t,n,o;return!1}function Jt(e){return("object"==typeof e||"function"==typeof e)&&null!==e&&"function"==typeof e.then}function Xt(e,t){const n=Array.isArray(e)?e:[e];for(const e of n)Jt(e)&&Promise.resolve(e).catch(e=>{console.error(`[wcstack/state] ${t} rejected.`,e)})}class Yt{_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 Qt extends Yt{_ownerStateName;constructor(e,t){super(e),this._ownerStateName=t??null}emit(...e){return null!==Qe&&Qe({type:"state:token-emit",kind:"event",stateName:this._ownerStateName,tokenName:this.name,args:e,subscriberCount:this.size}),super.emit(...e)}}const Zt=new WeakMap;function en(e,t){let n=Zt.get(e);void 0===n&&(n=new Map,Zt.set(e,n));let o=n.get(t);return void 0===o&&(o=new Qt(t,e.name),n.set(t,o)),o}function tn(e){Zt.delete(e)}const nn=new WeakMap;function on(e){if(e.propSegments[0]!==g)return!1;const t=e.node,n=J(t),o=Y(t);if(null!==n&&void 0===o?.get(n))return null===o&&se(`CustomElementRegistry is unavailable for <${n}>.`),!0;if(nn.has(e))return!0;const s=e.propSegments[1];"string"==typeof s&&0!==s.length||se('eventToken binding requires a property name (e.g., "eventToken.error").');const r=function(e){return null===J(e)?null:Z(e)}(t);null===r&&se(`eventToken binding requires a wc-bindable custom element. <${t.tagName.toLowerCase()}> is not wc-bindable.`);const i=r.knownProperties.get(s);void 0===i&&se(`Property "${s}" is not declared in wcBindable.properties of <${t.tagName.toLowerCase()}>.${ue(s,r.knownProperties.keys())}`);const a=i.event,d=e.statePathName,u=e.stateName,f=e.propModifiers,h=e=>{f.includes(l)&&e.preventDefault(),f.includes(c)&&e.stopPropagation();const n=Si(t.getRootNode(),u);null===n&&se(`State element with name "${u}" not found for eventToken handler.`),n.eventTokenNames.has(d)||se(`[wcs/token-undeclared] eventToken "${d}" is not declared in $eventTokens of state "${u}".${ue(d,n.eventTokenNames)}${fe}`);const o=Xe(t);n.createStateAsync("writable",async t=>{Xt(t[nt](o,()=>{const s=null!==o?St(o.listIndex,o.pathInfo.wildcardCount):[];return en(n,d).emit(t,e,...s)}),`$on."${d}" of state "${u}"`)})};return t.addEventListener(a,h),nn.set(e,{eventName:a,handler:h}),!0}class sn extends Yt{_ownerStateName;constructor(e,t){super(e),this._ownerStateName=t??null}emit(...e){return null!==Qe&&Qe({type:"state:token-emit",kind:"command",stateName:this._ownerStateName,tokenName:this.name,args:e,subscriberCount:this.size}),super.emit(...e)}}function rn(e){return e instanceof sn}const an=new Map,ln=qt();function cn(e){const t=e.propModifiers.filter(e=>e===l||e===c).sort().join(",");return`${e.stateName}::${e.statePathName}::${t}`}const dn=(e,t,n,o)=>s=>{n.includes(l)&&s.preventDefault(),n.includes(c)&&s.stopPropagation();const r=s.target,i=Si(r.getRootNode(),e);null===i&&se(`State element with name "${e}" not found for event handler.`);const a=Xe(r),d=t.startsWith(C+".");i.createStateAsync("writable",async n=>{Xt(n[nt](a,()=>{const r=null!==a?St(a.listIndex,a.pathInfo.wildcardCount):[];if(d){const e=n[ot](Wt(o,null));return rn(e)||se(`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&&se(`Handler "${t}" is not a function on state "${e}".`),Reflect.apply(i,n,[s,...r])}),`"${t}" of state "${e}"`)})};function un(e){if(!e.propName.startsWith(m))return!1;const t=cn(e);let n=an.get(t);void 0===n&&(n=dn(e.stateName,e.statePathName,e.propModifiers,e.statePathInfo),an.set(t,n));const o=e.propName.slice(2);return e.node.addEventListener(o,n),ln.add(t,e),!0}const fn=new Map,hn=qt();function pn(e,t){const n=e.inFilters.map(e=>e.filterName+"("+e.args.join(",")+")").join("|");return`${e.stateName}::${e.statePathName}::${t}::${n}`}function mn(e){let t="input";for(const n of e.propModifiers)n.startsWith(m)&&(t=n.slice(2));return t}function gn(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(d)){const s=mn(e),r=pn(e,s);let i=fn.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=Si(s.getRootNode(),t);null===i&&se(`State element with name "${t}" not found for two-way binding.`);const a=Xe(s);i.createState("writable",e=>{e[nt](a,()=>{e[n]=r})})},fn.set(r,i)),e.node.addEventListener(s,i),hn.add(r,e),!0}var t,n,o;return!1}const bn=new Set(["radio","checkbox"]),yn=new Set(["value","valueAsNumber","valueAsDate"]);function wn(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(bn.has(e)&&"checked"===t)return!0;if(yn.has(t))return!0}if("select"===o&&"value"===t)return!0;if("textarea"===o&&"value"===t)return!0;const s=J(n);if(null!==s){const e=Y(n)?.get(s);void 0===e&&se(`Custom element <${s}> is not defined. Cannot determine if property "${t}" is suitable for two-way binding.`);const o=Z(n);if(o?.knownProperties.has(t))return!0}return!1}let vn=1,Nn=1,Sn=1;const In=new WeakMap;function xn(e,t,n,o){let s=In.get(e);void 0===s&&(s=new Map,In.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=vn++,s.set(r,i)),i}function $n(e,t){return"to-element"===t?2*e:2*e+1}const Pn=new Set;function _n(e){return{transactionId:Nn++,originBindingId:e,visitedEdges:Pn,hop:0}}function An(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 kn=null;function Cn(){return kn}function En(e,t){const n=kn;kn=e;try{return t()}finally{kn=n}}const Mn=[];let Tn=!1;const On=new Map,Rn=qt(),Dn=new WeakMap,Ln=e=>e.detail;function jn(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 Wn(e){let t="select"===e.node.tagName.toLowerCase()?"change":"input";const n=J(e.node);if(null!==n){const o=Y(e.node)?.get(n);void 0===o&&se(`Custom element <${n}> is not defined. Cannot determine event name for two-way binding.`);const s=Z(e.node)?.knownProperties.get(e.propName);s&&(t=s.event)}for(const n of e.propModifiers)n.startsWith(m)&&(t=n.slice(2));return t}function Bn(e){if(null!==J(e.node)){const t=Z(e.node)?.knownProperties.get(e.propName);if(t)return t.getter??Ln}return null}function Fn(e){if(null===J(e.node))return!1;const t=Z(e.node)?.knownProperties.get(e.propName);return"event"===t?.semantics}const zn=(e,t,n,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=Dn.get(l)?.get(t);if(void 0!==u)for(const e of u)e(d);let f=null;if(o.enablePropagationContext){const s=xn(l,t,e,n),r=function(e,t){for(let n=Mn.length-1;n>=0;n--){const o=Mn[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 o.debug&&console.debug("[@wcstack/state] propagation: write confirmation suppressed echo.",{node:l,propName:t,statePathName:n,transactionId:r.transactionId,coveredBySameValueGuard:o.sameValueGuard&&(null===d||"object"!=typeof d)}),void(null!==Qe&&Qe({type:"propagation:suppressed",reason:"confirmation",transactionId:r.transactionId,edgeId:$n(s,"to-state"),node:l,member:t}));const i=$n(s,"to-state"),a=Cn();if(null!==a&&a.visitedEdges.has(i))return void(null!==Qe&&Qe({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:i,node:l,member:t}));f=An(a??_n(s),i)}const h=Si(l.getRootNode(),e);null===h&&se(`State element with name "${e}" not found for two-way binding.`);const p=Xe(l),m=()=>{i&&(Tn=!0);try{h.createState("writable",e=>{e[nt](p,()=>{e[n]=d})})}finally{i&&(Tn=!1)}};null!==f?En(f,m):m()};const qn=new WeakMap;function Un(e,t){const n=qn.get(e);return n?n.get(t)??null:null}const Vn=new WeakMap;function Hn(e,t){Vn.set(e,t)}function Gn(e){return Vn.get(e)??null}function Kn(e){let t=e;for(;;){if(null==t||!0!==t.hasMappedComponentState)return null;const e=t.boundComponent;if(null==e)return null;const n=Xe(e)?.listIndex;if(null!=n)return n;t=Gn(e)}}function Jn(e){return Kn(e)?.length??0}function Xn(e,t){return t.wildcardCount+Jn(e)}function Yn(e,t){return t??Kn(e)}const Qn=new WeakMap,Zn=new WeakMap,eo=new WeakMap,to=new WeakMap;function no(e,t){return{innerAbsPathInfo:dt(e,H(t.propSegments.slice(1).join(s))),outerAbsPathInfo:_t(t).absolutePathInfo}}function oo(e,t,n=!0){let r=Qn.get(e);if(void 0===r&&(r=new Map,Qn.set(e,r)),r.has(t))return r.get(t);let i=Zn.get(e);void 0===i&&(i=new Map,Zn.set(e,i));const a=eo.get(e);if(void 0===a)return null;let l=null;for(const e of a)if(t.pathInfo.cumulativePathInfoSet.has(e.innerAbsPathInfo.pathInfo)){e.innerAbsPathInfo.pathInfo.segments.length===t.pathInfo.segments.length&&se("Duplicate mapping rule for web component."),l=e;break}if(null===l)return null;const c=to.get(l);void 0===c&&se("Binding not found for primary mapping rule on web component.");const d=t.pathInfo.segments.slice(l.innerAbsPathInfo.pathInfo.segments.length),u=H(l.outerAbsPathInfo.pathInfo.segments.concat(d).join(s)),f=Si(e.getRootNode(),c.stateName);null===f&&se(`State element with name "${c.stateName}" not found for web component.`);const h=dt(f,u);if(!n)return h;r.set(t,h),i.set(h,t);const p=[c.propSegments[0],...t.pathInfo.segments],m={...c,propName:p.join(s),propSegments:p,statePathName:h.pathInfo.path,statePathInfo:h.pathInfo},g=t=>{o.debug&&console.warn(`parent→child notification for "${h.pathInfo.path}" is not registered: ${t}.`,{webComponent:e,primaryBinding:c})},b=Uo(c);return null===b?(g("no binding session for the primary mapping rule"),h):h.pathInfo.wildcardCount>0&&null===xt(m)?(g("the derived outer path is a wildcard path but no list index resolves from the component"),h):(b.initialize([m],{registerAddress:!0}),h)}function so(e,t){const n=ro(e,t);if(null===n||n.stateElement===e)return null;return Xn(e,t)!==Xn(n.stateElement,n.pathInfo)?null:n}function ro(e,t){if(!0!==e.hasMappedComponentState)return null;const n=e.boundComponent;if(null==n)return null;return oo(n,dt(e,t),!1)}const io=new WeakSet;function ao(e){io.add(e)}function lo(e){return!!io.has(e)&&(io.delete(e),!0)}const co=new WeakSet;function uo(e){co.add(e)}function fo(e){return!!co.has(e)&&(co.delete(e),!0)}let ho=0;function po(){ho--}function mo(){return ho>0}class go{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 bo=new WeakMap;function yo(e){let t=bo.get(e);return void 0===t&&(t=new go(e),bo.set(e,t)),t}function wo(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();s!==u&&s!==f&&se(`Unknown binding modifier "${s}" in "${o}".`),s===t&&(null!==n&&se(`Binding modifier "${t}" may only be specified once.`),n=r)}return n}function vo(e){return e.propModifiers.some(e=>e.includes("="))}const No=Object.freeze({authority:"state",syncOn:"call",observable:!1,outputOnly:!1}),So=Object.freeze({authority:"none",syncOn:"call",observable:!1,outputOnly:!1});function Io(e,t){return"state"===e&&"call"===t?No:{authority:e,syncOn:t,observable:!1,outputOnly:!1}}function xo(e){if(!o.enableDirectionalInitialSync)return vo(e)&&se("init=/sync= modifiers require enableDirectionalInitialSync."),No;const t=null===(n=wo(e,u))?null:"state"===n||"element"===n||"auto"===n||"none"===n?n:se(`Invalid init modifier value "${n}".`);var n;const s=function(e){return null===e||"call"===e?"call":"connect"===e?"connect":se(`Invalid sync modifier value "${e}".`)}(wo(e,f));if("event"===e.bindingType)return null!==t&&"none"!==t&&se("Event bindings only allow init=none."),"call"===s?So:{authority:"none",syncOn:s,observable:!1,outputOnly:!1};if(e.propSegments[0]===b)return Io("state",s);if("prop"!==e.bindingType)return null!==t&&"state"!==t&&"none"!==t&&se(`Binding type "${e.bindingType}" does not support init=${t}.`),Io(t??"state",s);const r=Z(e.node);if(null===r)return Io(t??"state",s);const i=r.knownProperties.has(e.propName),a=r.declaredInputs.has(e.propName);i||a||se(`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)||se(`init=${l} is incompatible with wcBindable member "${e.propName}".`),"connect"!==s||i||se(`sync=connect requires observable property "${e.propName}".`),{authority:l,syncOn:s,observable:i,outputOnly:i&&!a}}function $o(e,t){return"auto"!==t?t:function(e){const t=Si(e.replaceNode.getRootNode(),e.stateName);null===t&&se(`State element with name "${e.stateName}" not found for binding.`);const n=Ft(e);let o=!1;return t.createState("readonly",e=>{o=e[st](n)}),o}(e)?"state":"element"}let Po=0,_o=0;const Ao=new WeakMap,ko=new WeakMap,Co=new WeakMap,Eo=new WeakMap;function Mo(e,t){const n=Eo.get(e);void 0!==n?n!==t&&(n instanceof Set?n.add(t):Eo.set(e,new Set([n,t]))):Eo.set(e,t)}function To(e){return Eo.has(e)}function Oo(e,t){const n=Eo.get(e);if(void 0!==n)if(n instanceof Set)for(const e of Array.from(n))t(e);else t(n)}function Ro(e,t){if(t(e),null!==e.firstChild)for(const n of Array.from(e.childNodes))Ro(n,t)}function Do(e){if("object"!=typeof e||null===e)return!1;const t=e;return 9===t.nodeType||11===t.nodeType&&"host"in t}class Lo{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)lo(e)||Ro(e,e=>{Oo(e,t=>{this.root.contains(e)||t.handleRemovedNode(e)})});for(const e of n)fo(e)&&!mo()||Ro(e,e=>{Oo(e,t=>{this.root.contains(e)&&t.handleAddedNode(e,o)})});o.length>0&&Pr(o)}}const jo=new WeakMap;function Wo(e){let t=jo.get(e);return void 0===t&&(t=new Lo(e),jo.set(e,t)),t}function Bo(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 Fo(e,t){null===e.teardowns&&(e.teardowns=new Set),e.teardowns.add(t)}class zo{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=Ao.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(Do(t)&&Wo(t),null===this.rowPlan)for(const n of e){const e=Ao.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(!o.enableDirectionalInitialSync)return vo(e)&&xo(e),!0;const t=Ao.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=Ao.get(e);return t?.session===this?t:null}addTeardown(e,t){const n=Ao.get(e);return!(void 0===n||!this.isAlive(n,n.generation))&&(Fo(n,t),!0)}deferUntilDefined(e,t,n,o=()=>{}){const s=Y(e);null===s&&se(`CustomElementRegistry is unavailable for <${t}>.`),this.observe(e),Mo(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=yo(s).wait(t,()=>{if(a())try{Q(s,e),n()}catch(e){o(e)}},e=>{a()&&o(e)}),()=>{a()&&r.cancel?.()}}disposeBinding(e){const t=Ao.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&&(Et(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 Do(t)?t:null}(e);null!==t&&Wo(t)}handleMutations(e,t,n){for(const n of t)Ro(n,t=>{e.contains(t)||this.handleRemovedNode(t)});const o=[];for(const t of n)Ro(t,t=>{e.contains(t)&&this.handleAddedNode(t,o)});o.length>0&&Pr(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=Ao.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=Co.get(t);void 0===e&&(e=Bo(t),Co.set(t,e)),n.set(e,t)}return this.knownBindingsByNode.set(e,n),n}remember(e,t){const n=e.replaceNode;Mo(n,this);const o=this.knownMapFor(n);let s=Co.get(e);void 0===s&&(s=Bo(e),Co.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;Mo(i,this),this.addKnownRowBinding(i,s,e),this.optionsByBinding.set(s,n);const a={id:++Po,info:s,generation:++_o,phase:"active",teardowns:null,session:this,anchor:i,options:n,address:null,patternPathInfo:null,patternListIndex:null,outerPatternPathInfo:null,outerPatternPathInfosRest: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(Ao.set(s,a),this.records.add(a),r.isEvent){try{un(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=Ao.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=++_o,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{un(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:++Po,info:e,generation:++_o,phase:"discovered",teardowns:null,session:this,anchor:e.replaceNode,options:o,address:null,patternPathInfo:null,patternListIndex:null,outerPatternPathInfo:null,outerPatternPathInfosRest: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};Ao.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;un(t)?e.eventAttached=!0:t.propSegments[0]!==g?(gn(t)&&Fo(e,()=>function(e){if("radio"===e.bindingType&&-1===e.propModifiers.indexOf(d)){const t=mn(e),n=pn(e,t),o=fn.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==hn.countOf(n)&&(hn.remove(n,e)&&fn.delete(n),!0))}return!1}(t)),Kt(t)&&Fo(e,()=>function(e){if("checkbox"===e.bindingType&&-1===e.propModifiers.indexOf(d)){const t=Gt(e),n=Ht(e,t),o=Ut.get(n);return void 0!==o&&(e.node.removeEventListener(t,o),0!==Vt.countOf(n)&&(Vt.remove(n,e)&&Ut.delete(n),!0))}return!1}(t)),this.attachAfterDefinition(e,()=>{if(o.enableDirectionalInitialSync&&wn(t.node,t.propName)&&-1===t.propModifiers.indexOf(d)){const n=function(e,t,n){let o=Dn.get(e);void 0===o&&(o=new Map,Dn.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&&Dn.delete(e)}}(t.node,t.propName,t=>{this.isAlive(e,e.generation)&&(e.eventSequence+=1,e.hasProducerValue=!0,e.producerValue=t)});Fo(e,n)}!function(e){const t=J(e.node);if(null!==t){const n=Y(e.node),o=n?.get(t);if(void 0===o)return void(null===n&&se(`CustomElementRegistry is unavailable for <${t}>.`))}if(wn(e.node,e.propName)&&-1===e.propModifiers.indexOf(d)){const t=Wn(e),n=Bn(e),o=Fn(e),s=jn(e,t,null!==n,o);let r=On.get(s);void 0===r&&(r=zn(e.stateName,e.propName,e.statePathName,e.inFilters,n,o),On.set(s,r)),e.node.addEventListener(t,r),Rn.add(s,e)}}(t),e.twowayAttached=!0})):this.attachAfterDefinition(e,()=>{on(t)&&Fo(e,()=>function(e){if(e.propSegments[0]!==g)return!1;const t=nn.get(e);return void 0!==t&&(e.node.removeEventListener(t.eventName,t.handler),nn.delete(e),!0)}(t))})}attachAfterDefinition(e,t){const n=J(e.info.node);if(null===n)return void t();const o=Y(e.info.node);if(null===o&&se(`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=yo(o).wait(n,()=>{if(this.isAlive(e,s))try{Q(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))});Fo(e,r)}settleInitialRecord(e){if(o.enableDirectionalInitialSync&&!e.initialSettled&&e.options.registerAddress){e.phase="synchronizing";try{const t=xo(e.info),n=$o(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 ho++;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,po()),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=Si(e.node.getRootNode(),e.stateName);null===o&&se(`State element with name "${e.stateName}" not found for initial binding sync.`);const s=Xe(e.node);o.createState("writable",t=>{t[nt](s,()=>{t[e.statePathName]=n})})}(e.info,r))}settleConnectedSnapshot(e){if(o.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=xt(n);if(null!==o){const i=Si(Pt(n,t),n.stateName);null===i&&se(`State element with name "${n.stateName}" not found for binding.`);const a=dt(i,n.statePathInfo);Tt(a,o,n),e.patternPathInfo=a,e.patternListIndex=o;const l=(s=i,0===(r=n.statePathInfo).wildcardCount?null:so(s,r));if(null!==l){Tt(l,o,n),e.outerPatternPathInfo=l;const t=function(e){let t=null,n=e.stateElement,o=e.pathInfo;for(;;){const e=so(n,o);if(null===e)return t;(t??=[]).push(e),n=e.stateElement,o=e.pathInfo}}(l);if(null!==t){for(let e=0;e<t.length;e++)Tt(t[e],o,n);e.outerPatternPathInfosRest=t}}}else{const o=_t(n,t);Ct(o,n),e.address=o}var s,r;if(!e.options.registerPathInfo)return;const i=Si(n.replaceNode.getRootNode(),n.stateName);null===i&&se(`State element with name "${n.stateName}" not found for binding.`),"event"!==n.bindingType&&i.setPathInfo(n.statePathName,n.bindingType)}isAlive(e,t){return e.generation===t&&Ao.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,po());const t=e.info;if(null!==e.address)try{Et(e.address,t),e.address=null,zt(t),At(t)}catch{}else if(null!==e.patternListIndex){if(null!==e.outerPatternPathInfo){try{Ot(e.outerPatternPathInfo,e.patternListIndex,t)}catch{}e.outerPatternPathInfo=null}if(null!==e.outerPatternPathInfosRest){const n=e.outerPatternPathInfosRest;for(let o=0;o<n.length;o++)try{Ot(n[o],e.patternListIndex,t)}catch{}e.outerPatternPathInfosRest=null}try{Ot(e.patternPathInfo,e.patternListIndex,t),e.patternPathInfo=null,e.patternListIndex=null,zt(t),At(t)}catch{}}if(e.twowayAttached){e.twowayAttached=!1;try{!function(e){const t=J(e.node);if(null!==t){const n=Y(e.node),o=n?.get(t);if(void 0===o)return}if(wn(e.node,e.propName)&&-1===e.propModifiers.indexOf(d)){const t=Wn(e),n=jn(e,t,null!==Bn(e),Fn(e)),o=On.get(n);if(void 0===o)return;e.node.removeEventListener(t,o),Rn.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(m))return!1;const t=cn(e),n=an.get(t);if(void 0===n)return!1;const o=e.propName.slice(2);e.node.removeEventListener(o,n),0!==ln.countOf(t)&&(ln.remove(t,e)&&an.delete(t))}(t)}catch{}}}}function qo(e){let t=ko.get(e);return void 0===t&&(t=new zo(e),ko.set(e,t)),t}function Uo(e){return Ao.get(e)?.session??null}const Vo=new WeakMap;function Ho(e,t){let n=e;for(const e of t)n=e.filterFn(n);return n}const Go=Object.freeze([]);const Ko=new WeakMap;const Jo=new WeakMap;function Xo(e){return Jo.get(e)??[]}function Yo(e,t){Jo.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 Qo=0;function Zo(){return`u${(Qo++).toString(36)}`}let es=0;class ts{uuid=Zo();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=es}get index(){return this._index}set index(e){this._index=e,this._version=++es,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=es),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 ns(e,t){return new ts(e,t)}const os=new WeakMap;function ss(e){return os.get(e)||null}function rs(e,t){null!==t?os.set(e,t):os.delete(e)}const is=new WeakMap,as=Object.freeze([]),ls=new Set;function cs(e,t,n){const o=function(e,t,n){const o=Array.isArray(t)&&t.length>0?t:as,s=Array.isArray(n)&&n.length>0?n:as,r=function(e,t){const n=Array.isArray(e)&&e.length>0?e:as,o=Array.isArray(t)&&t.length>0?t:as;let s=is.get(n);return s&&s.get(o)||null}(o,s);if(r)return r;const i=ss(o)||[];let a;try{if(0===s.length)return a={oldIndexes:i,newIndexes:[],changeIndexSet:ls,deleteIndexSet:new Set(i),addIndexSet:ls};let t=ss(s);if(0===o.length){if(null===t){t=[];for(let n=0;n<s.length;n++){const o=ns(e,n);t.push(o)}}return a={oldIndexes:i,newIndexes:t,changeIndexSet:ls,deleteIndexSet:ls,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:ls,deleteIndexSet:ls,addIndexSet:ls};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=ns(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=is.get(e);o||(o=new WeakMap,is.set(e,o)),o.set(t,n)}(o,s,a),rs(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 ds(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 us=new WeakMap;function fs(e){return us.get(e)??[]}function hs(e,t){us.set(e,t)}const ps=new WeakMap;function ms(e){return ps.get(e)??null}function gs(e,t){ps.set(e,t)}const bs=new WeakMap;function ys(e){return bs.get(e)??[]}function ws(e,t){bs.set(e,t)}function vs(e,t){const n=ys(e);for(const e of n)Ye(e,t)}function Ns(e,t,n){vs(e,t);const o=fs(e),s=ms(e);null!==s&&s.activate(o,n.rootNode);for(const e of o){if(null===s){Ct(_t(e),e)}(null===s||s.shouldApplyState(e))&&xr(e,n)}}function Ss(e){if(!e.mounted)return;const t=fs(e),n=ms(e);for(const e of t)if(null!==n)n.disposeBinding(e);else{Et(_t(e),e)}!function(e){const t=ys(e);for(const e of t)Ye(e,null)}(e)}const Is=new WeakMap,xs=Object.freeze(new Set);function $s(e,t){const n=Is.get(e);n?n.add(t):Is.set(e,new Set([t]))}function Ps(e){const t=Is.get(e);return void 0!==t?t:xs}function _s(e,t){const n=Is.get(e);n&&(n.delete(t),0===n.size&&Is.delete(e))}const As=new Set(["if","elseif","else","for"]);class ks{_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)uo(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()){if(n.nextSibling!==e){uo(e);const o=t;e.parentNode===t&&"function"==typeof o.moveBefore?o.moveBefore(e,n.nextSibling):t.insertBefore(e,n.nextSibling)}n=e}}this._mounted=!0}tryDestroy(){const e=ms(this);if(null===e||!e.canWholesaleDestroy())return!1;e.destroyRecords();for(const e of this._childNodeArray)ao(e),null!==e.parentNode&&e.parentNode.removeChild(e);const t=fs(this);for(const e of t)if(As.has(e.bindingType)){const t=Ps(e.node);for(const e of t)e.tryDestroy()||e.unmount()}return this._mounted=!1,!0}unmount(){ms(this)?.dispose();for(const e of this._childNodeArray)ao(e),null!==e.parentNode&&e.parentNode.removeChild(e);const e=fs(this);for(const t of e){if(As.has(t.bindingType)){const e=Ps(t.node);for(const t of e)t.unmount()}zt(t),At(t)}this._mounted=!1}}function Cs(e){let t=e.topLevelStructural;return void 0===t&&(t=e.topLevelStructural=function(e){const t=new RegExp(`^@@(?:${o.commentForPrefix}|${o.commentIfPrefix}|${o.commentElseIfPrefix}|${o.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 Es(e){const t=document.createDocumentFragment(),n=new ks(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 Ms(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=le(o,s[e].nodePath);null===t&&se(`Node not found by path [${s[e].nodePath.join(", ")}] in fragment.`),Ge(t),q(t),r[e]=t}const i=n.slots,a=new Array(i.length),l=[];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&&l.push(o)}const c=function(e,t){const n=new zo;return n.initializeRow(e,t),n}(n,a),d=new ks(o);return gs(d,c),hs(d,a),Yo(d,l),ws(d,r),$s(e.node,d),d}function Ts(e){void 0!==e.uuid&&null!==e.uuid||se("BindingInfo.uuid is null.");const n=je(e.uuid);n||se(`Fragment with UUID "${e.uuid}" not found.`);const s=!t()&&Cs(n);let r=n.rowPlan;if((void 0===r||null!==r&&r.directional!==o.enableDirectionalInitialSync)&&(r=n.rowPlan=function(e){const t=o.enableDirectionalInitialSync,n=[],s=e.nodeInfos;for(let t=0;t<s.length;t++){const o=s[t],r=le(e.fragment,o.nodePath);if(null===r)return null;for(const e of o.parseBindTextResults){const o=e.bindingType;if("text"!==o&&"prop"!==o&&"event"!==o)return null;const s=e.propSegments[0];if(s===b||s===g)return null;if("text"===o){if(r.nodeType!==Node.TEXT_NODE)return null}else if(null!==J(r))return null;if("prop"===o&&wn(r,e.propName))return null;let i;try{i=xo({...e,node:r,replaceNode:r})}catch{return null}if(i.observable||"auto"===i.authority)return null;n.push({nodeIndex:t,template:e,isEvent:"event"===o,isIndexBinding:e.statePathName in S,policy:i,authority:i.authority})}}return{directional:t,slots:n}}(n)),null!==r)return Ms(e,n,r);const i=document.importNode(n.fragment,!0),a=function(e,t){const[n,o]=function(e,t){const n=[],o=[];for(const s of t){const t=le(e,s.nodePath);if(null===t&&se(`Node not found by path [${s.nodePath.join(", ")}] in fragment.`),Ue.has(t))continue;const r=Ve(t,s.parseBindTextResults,{allowDeferred:!1});o.push(...r.bindings),n.push(t)}return[n,o]}(e,t),s=new zo,r=s.initialize(o,{registerAddress:!1,applyOnReconnect:!1},null);return{nodes:n,bindingInfos:r,bindingSession:s}}(i,n.nodeInfos);s&&function(e,t){e.appendChild(document.createComment(`wcs-row-end:${t}`))}(i,e.uuid);const l=new ks(i,s);gs(l,a.bindingSession),hs(l,a.bindingInfos);const c=[];for(const e of a.bindingInfos)e.statePathName in S&&c.push(e);return Yo(l,c),ws(l,a.nodes),$s(e.node,l),l}const Os=Symbol.for("wcstack.transition-runner");function Rs(e){const t=globalThis[Os];return null==t||"wcs-transition-runner"!==t.protocol||"number"!=typeof t.version||t.version<1||"function"!=typeof t.run?null:"function"==typeof t.accepts&&t.accepts(e)?t:null}const Ds=new WeakSet,Ls=Symbol.for("wcstack.state.view-transition-naming");function js(){const e=Rs("state");return null===e||"auto"!==e.naming?null:{limit:e.namingLimit}}function Ws(e,t,n){const o=function(e){const t=e.firstNode;if(null===t)return null;const n=e.lastNode;for(let e=t;null!==e;e=e.nextSibling){if(e.nodeType===Node.ELEMENT_NODE)return e;if(e===n)break}return null}(e);if(null===o||Ds.has(o))return;const s=o.style;if(void 0===s)return;const r=function(){const e=globalThis;return e[Ls]??={counter:0,assigned:0,warned:!1}}();r.assigned>=n.limit?r.warned||(r.warned=!0,console.warn(`[@wcstack/state] auto view-transition-name limit (${n.limit}) reached; further elements are left unnamed. Raise naming-limit on <wcs-view-transition>, or switch to naming="manual" and name only what should morph.`)):(Ds.add(o),r.assigned+=1,r.counter+=1,s.setProperty("view-transition-name",`wcs-${t}-${r.counter}`),s.setProperty("view-transition-class",`wcs-${t}`))}const Bs=new WeakMap,Fs=new WeakMap,zs=new WeakMap,qs=new WeakMap;function Us(e,t,n){!function(e,t,n){let o=Fs.get(e);if(void 0===o){if(null===n)return;o=new WeakMap,Fs.set(e,o)}null===n?o.delete(t):o.set(t,n)}(e,t,n)}function Vs(e,t){Bs.set(e,t)}function Hs(e,t){let n=zs.get(e.node);void 0===n&&(n=[],zs.set(e.node,n)),n.length<1e3?n.push(t):_s(e.node,t)}function Gs(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 Ks(e){return`${e.bindingType} ${e.statePathName} ${e.outFilters.map(e=>e.filterName).join("|")} ${e.node.isConnected?"(connected)":"(disconnected)"}`}function Js(e,n,s){const r=Boolean(s);let i;const a=Ps(e.node);i=0===a.size?Ts(e):a.values().next().value;const l=t(),c=e.uuid??"",d=e.bindingType;if(r||(o.debug&&console.log(`unmount if content : ${Ks(e)}`),Ss(i),i.unmount()),r){if(o.debug&&console.log(`mount if content : ${Ks(e)}`),l){const t=document.createComment(`@@wcs-${d}-start:${c}:${e.statePathName}`);e.node.parentNode.insertBefore(t,e.node.nextSibling),i.mountAfter(t);const n=document.createComment(`@@wcs-${d}-end:${c}:${e.statePathName}`),o=i.lastNode??t;o.parentNode.insertBefore(n,o.nextSibling)}else i.mountAfter(e.node);Ns(i,Xe(e.node),n);const t=js();null!==t&&Ws(i,"branch",t)}}const Xs=new WeakMap;function Ys(e){return Xs.get(e)??[]}const Qs=new Set;const Zs={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 er(e,n,s){if(void 0===s)return void(o.debug&&console.debug("Skipped property write: state value is undefined.",{element:e.node,propSegments:e.propSegments,statePathName:e.statePathName}));const r=e.node,i=e.propSegments;if(1===i.length){const l=i[0];if(r[l]!==s){const t=()=>{let e=!1;try{r[l]=s,e=!0}catch(e){o.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=J(e);if(null===n)return null;const o=Y(e)?.get(n);if(void 0===o)return null;const s=Z(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){o.debug&&console.warn(`Failed to mirror attribute '${e}' on element.`,{element:r,newValue:s,error:t})}}};if(o.enablePropagationContext&&wn(r,l)){const o=xn(r,l,e.stateName,e.statePathName),i=$n(o,"to-element"),a=n?.propagationContextByBinding?.get(e)??Cn()??_n(o);if(a.visitedEdges.has(i))null!==Qe&&Qe({type:"propagation:suppressed",reason:"visited-edge",transactionId:a.transactionId,edgeId:i,node:r,member:l});else{const e=An(a,i);En(e,()=>function(e,t,n,o,s,r){const i={bindingId:o,bindingGeneration:0,member:t,transactionId:s,synchronousScopeId:Sn++,writtenValue:n};Mn.push({receipt:i,node:e});try{return r()}finally{Mn.pop()}}(r,l,s,o,e.transactionId,t))}}else t()}if(t()){const e=Zs[l];e?e(r,s):(!function(e,t,n){let o=Xs.get(e);o||(o=[],Xs.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,Qs.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(o.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){o.debug&&console.warn("Failed to set property on sub-object.",{element:r,propSegments:i,oldValue:d,newValue:s,error:e})}}}const tr=new WeakSet;function nr(e,t,n){const r=e.node,i=e.propSegments;i.length<=1&&se(`Invalid propSegments for web component binding: ${i.join(s)}`);const[a,...l]=i,c=Un(r,a);null===c&&se(`State element not bound to "${a}" on web component.`),!1!==c.hasRootNode?c.createState("readonly",e=>{e.$postUpdate(l.join(s))}):o.debug&&console.debug(`[@wcstack/state] skipped parent→child notification for a disconnected state element on <${r.tagName.toLowerCase()}>.`,{element:r,stateProp:a,path:l.join(s)})}const or=Object.freeze({existence:"unknown",missingSegment:"",candidates:Object.freeze([])}),sr=Object.freeze({existence:"exists",missingSegment:"",candidates:Object.freeze([])});function rr(e,t){let n=e;for(;null!==n&&n!==Object.prototype;){const e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return e;n=Object.getPrototypeOf(n)}}function ir(e,t,n){const o=function(e){const t=[];let n=e;for(;null!==n&&n!==Object.prototype;){for(const e of Object.getOwnPropertyNames(n))t.push(e);n=Object.getPrototypeOf(n)}return t}(e),r=t.length>0?t+s:"";for(const e of n){if(r.length>0&&!e.startsWith(r))continue;const t=e.slice(r.length);t.length>0&&-1===t.indexOf(s)&&o.push(t)}return o}const ar={binding:"wcs/binding-path-missing",watch:"wcs/watch-path-missing"},lr={binding:"Bound path",watch:"$watch path"};function cr(e,t,n,o){return`[wcs/index-arity] ${e}("${t}") requires ${"$resolve"===e?`exactly ${n}`:`at most ${n}`} index(es) ("*" appears ${n} time(s) in the path) but got ${o}.${fe}`}function dr(e,t){return`$setAll("${e}") ${t}`}function ur(e,t,n){return`[wcs/wildcard-rank] ${e} needs ${t} enclosing loop level(s) but the current scope provides ${n}. Wrap it in that many "for" templates, or use $resolve(path, indexes) to name the row explicitly.${fe}`}const fr=new WeakMap;function hr(e,t,n,o){if("internal"===o||void 0===t)return;if(n.startsWith("$"))return;if(!0===e.hasMappedComponentState)return;const i=H(n).segments;if("binding"===o&&i.length<2)return;if(function(e,t){let n=fr.get(e);return void 0===n&&(n=new Set,fr.set(e,n)),!!n.has(t)||(n.add(t),!1)}(e,n))return;const a=function(e,t,n){if(void 0!==rr(e,t))return sr;const o=H(t).segments;let i=e,a="";for(let t=0;t<o.length;t++){const l=o[t],c=a;if(a=0===t?l:a+s+l,t>0&&t<o.length-1&&void 0!==rr(e,a))return or;if(Object(i)!==i)return or;if(l===r){if(!Array.isArray(i)||0===i.length)return or;i=i[0];continue}const d=rr(i,l);if(void 0===d)return{existence:"missing",missingSegment:l,candidates:ir(i,c,n)};if("function"==typeof d.get)return t===o.length-1?sr:or;i=d.value}return sr}(t,n,e.getterPaths);"missing"===a.existence&&(console.warn(`[@wcstack/state] [${ar[o]}] ${lr[o]} "${n}" does not resolve on state "${e.name}": "${a.missingSegment}" is not declared.${ue(a.missingSegment,a.candidates)} Updates to this path will be silently dropped.${fe}`),null!==Qe&&Qe({type:"state:path-unresolved",source:o,stateName:e.name,path:n,missingSegment:a.missingSegment}))}function pr(e,t){const n=Ft(t);if(n.pathInfo.path in S){const e=Xe(t.node);return null===e&&se(`ListIndex not found for binding: ${t.statePathName}`),function(e,t){null===e.listIndex&&se("ListIndex not found for loopContext:");const n=S[t];void 0===n&&se(`Invalid index name: ${t}`);const o=Nt(e.listIndex,n,e.pathInfo.wildcardCount);return null===o&&se(ur(`"${t}"`,n+1,e.pathInfo.wildcardCount)),o.index}(e,n.pathInfo.path)}return e[ot](n)}const mr=new WeakSet;function gr(e,t){console.error(`[@wcstack/state] deferred apply failed for <${e}>.`,t)}const br=Object.freeze({[y]:function(e,t,n){const o=e.node,s=e.propSegments[1];"boolean"!=typeof n&&se("Invalid value for class application: expected boolean, got "+typeof n),o.classList.toggle(s,n)},[w]:function(e,t,n){const o=e.node,s=e.propSegments[1];o.getAttribute(s)!==n&&o.setAttribute(s,n)},[v]:function(e,t,n){const o=e.propSegments[1],s=e.node.style;s[o]!==n&&(s[o]=n)},[b]:function(e,t,n){rn(n)||se("command binding requires a CommandToken value (use $command.<tokenName> with a name declared in $commandTokens).");const o=n,s=Ko.get(e);if(s&&s.token===o)return;const r=e.node,i=e.propSegments[1];"string"==typeof i&&0!==i.length||se('command binding requires a method name (e.g., "command.fetch").');const a=function(e){const t=J(e);if(null===t)return null;const n=Y(e)?.get(t);return void 0===n&&se(`Custom element <${t}> is not defined for command binding.`),Z(e)}(r);null===a&&se(`command binding requires a wc-bindable custom element. <${r.tagName.toLowerCase()}> is not wc-bindable.`),a.declaredCommands.has(i)||se(`Command "${i}" is not declared in wcBindable.commands of <${r.tagName.toLowerCase()}>.${ue(i,a.declaredCommands.keys())}`),s&&(s.unsubscribe(),Ko.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 Ko.delete(e);const o=n[i];return"function"!=typeof o&&se(`Method "${i}" is not a function on <${n.tagName.toLowerCase()}>.`),Reflect.apply(o,n,t)}),Ko.set(e,{token:o,unsubscribe:c,elementRef:l})}}),yr={text:function(e,n,o){const s=null==o?"":String(o);if(e.replaceNode.nodeValue!==s&&(e.replaceNode.nodeValue=s),t()&&!tr.has(e.replaceNode)){tr.add(e.replaceNode);const t=e.replaceNode.parentNode;if(t){const n=e.statePathName,o=document.createComment(`@@wcs-text-start:${n}`),s=document.createComment(`@@wcs-text-end:${n}`);t.insertBefore(o,e.replaceNode),t.insertBefore(s,e.replaceNode.nextSibling)}}},for:function(e,n,o){const s=e.statePathInfo,i=xt(e),a=_t(e),l=et(a),c=cs(Yn(n.stateElement,i),l,o);n.newListValueByAbsAddress.set(a,Array.isArray(o)?o:[]);const d=Array.isArray(l)&&l.length===c.deleteIndexSet.size&&c.deleteIndexSet.size>0;if(d&&null!==e.node.parentNode){let t=qs.get(e.node);if(void 0===t){const n=Bs.get(e.node)||e.node;t=function(e,t){let n=e.previousSibling,o=t.nextSibling,s=!0;for(;null!==n;){if(n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&""!==(n.textContent?.trim()??"")){s=!1;break}n=n.previousSibling}for(;null!==o;){if(o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE&&""!==(o.textContent?.trim()??"")){s=!1;break}o=o.nextSibling}return s}(e.node,n),qs.set(e.node,t)}if(t){const t=e.node.parentNode;t.textContent="",t.appendChild(e.node)}}let u=Fs.get(e.node),f=d?1e3-function(e){return zs.get(e.node)||[]}(e).length:Number.POSITIVE_INFINITY;if(void 0!==u){for(const t of c.deleteIndexSet){const n=u.get(t);void 0!==n&&(f<=0&&n.tryDestroy()?_s(e.node,n):(Ss(n),n.unmount(),Hs(e,n),f-=1),d||u.delete(t))}d&&(Fs.delete(e.node),u=void 0)}let h=e.node;const p=H(s.path+"."+r),m=n.stateElement.loopContextStack,g=ds(c);let b=null;c.newIndexes.length==c.addIndexSet.size&&c.newIndexes.length>0&&h.isConnected&&(b=document.createDocumentFragment(),bt(b,n.rootNode));const y=t(),w=js(),v=e.uuid??"",N=zs.get(e.node);for(const t of c.newIndexes){let o;if(c.addIndexSet.has(t)){const r=Wt(p,t);m.createLoopContext(r,r=>{if(o=void 0!==N?N.pop():void 0,void 0===o&&(o=Ts(e)),null!==b)y&&b.appendChild(document.createComment(`@@wcs-for-start:${v}:${s.path}:${t.index}`)),o.appendTo(b),y&&b.appendChild(document.createComment(`@@wcs-for-end:${v}:${s.path}:${t.index}`));else{if(h.nextSibling!==o.firstNode){if(y){const e=document.createComment(`@@wcs-for-start:${v}:${s.path}:${t.index}`);h.parentNode.insertBefore(e,h.nextSibling),h=e}o.mountAfter(h)}if(y){const e=document.createComment(`@@wcs-for-end:${v}:${s.path}:${t.index}`),n=o.lastNode??h;n.parentNode.insertBefore(e,n.nextSibling)}}Ns(o,r,n),null!==w&&Ws(o,"row",w)}),void 0===o&&se(`Content not found for ListIndex: ${t.index} at path "${s.path}"`)}else{if(o=void 0!==u?u.get(t)??null:null,c.changeIndexSet.has(t)){const e=Xo(o);for(const t of e)xr(t,n)}null===o&&se(`Content not found for ListIndex: ${t.index} at path "${s.path}"`);const e=!o.mounted;if(null!==g&&g.has(t)&&Gs(h,o.firstNode)||h.nextSibling===o.firstNode||o.mountAfter(h),e){const e=o,s=Wt(p,t);m.createLoopContext(s,t=>{Ns(e,t,n)})}}h=o.lastNode||h,void 0===u&&(u=new WeakMap,Fs.set(e.node,u)),u.set(t,o)}Bs.set(e.node,h),null!==b&&(e.node.parentNode.insertBefore(b,e.node.nextSibling),bt(b,null))},if:Js,else:Js,elseif:Js,radio:function(e,t,n){const o=e.node,s=Ho(o.value,e.inFilters);o.checked=n===s},checkbox:function(e,t,n){const o=e.node,s=Ho(o.value,e.inFilters),r=Array.isArray(n)?n:Go;o.checked=r.includes(s)}},wr=new WeakMap,vr=new WeakMap,Nr=new WeakMap;function Sr(e){return e.propSegments.length>1&&(t=e.replaceNode,n=e.propSegments[0],!0===Vo.get(t)?.has(n));var t,n}function Ir(e,t){const n=Ho(pr(t.state,e),e.outFilters);if(!0===vr.get(e))return void t.deferredSelectBindings.push({binding:e,value:n});let o=wr.get(e);if(void 0===o){if(wr.has(e))return Sr(e)?(o=nr,wr.set(e,o)):o=er,void o(e,t,n);if(o=yr[e.bindingType],void 0===o){const t=e.propSegments[0];if(o=br[t],wr.set(e,o),void 0===o){J(e.replaceNode)?Sr(e)?(o=nr,wr.set(e,o)):o=er:(o=er,wr.set(e,o))}}if(o===er){if("SELECT"===e.node.tagName){const o=e.propSegments[0];if("value"===o||"selectedIndex"===o)return t.deferredSelectBindings.push({binding:e,value:n}),void vr.set(e,!0)}}o(e,t,n)}else o(e,t,n)}function xr(e,t){if(t.appliedBindingSet.has(e))return;if(t.appliedBindingSet.add(e),!1!==t.stateElement.hasUpdatedCallback){const n=_t(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=Uo(e);if(null!==n&&!n.shouldApplyState(e))return;if("event"===e.bindingType)return;if(!0!==Nr.get(e)){const t=J(e.replaceNode);if(t&&void 0===Y(e.replaceNode)?.get(t))return void function(e,t){if(mr.has(e))return;mr.add(e);const n=()=>{mr.delete(e);const t=Uo(e);(null===t||t.shouldApplyState(e))&&Pr([e])},o=n=>{mr.delete(e),gr(t,n)},s=Uo(e);if(null!==s){const r=s.deferUntilDefined(e.replaceNode,t,n,o);return void(s.addTeardown(e,()=>{mr.delete(e),r()})||(mr.delete(e),r()))}const r=Y(e.replaceNode);if(null===r)return mr.delete(e),void gr(t,new Error("CustomElementRegistry is unavailable."));yo(r).wait(t,()=>{e.replaceNode.isConnected?n():mr.delete(e)},o)}(e,t);Nr.set(e,!0)}if(!0===t.sameRootVerified&&e.stateName===t.stateName)return void Ir(e,t);let o=e.replaceNode.getRootNode();if(o instanceof DocumentFragment&&!(o instanceof ShadowRoot)&&(o=yt(o),null===o&&se("Root node for fragment not found for binding.")),e.stateName!==t.stateName||o!==t.rootNode){const n=Si(o,e.stateName);null===n&&se(`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};Ir(e,r)})}else Ir(e,t)}function $r(e,t){console.error(`[@wcstack/state] binding "${e.bindingType}: ${e.statePathName}" failed to apply; the rest of this batch continues.`,{node:e.node,error:t}),null!==Qe&&Qe({type:"state:binding-apply-error",stateName:e.stateName,path:e.statePathName,bindingType:e.bindingType,error:t})}function Pr(e,t){let n=0;const s=new Set,r=new Map,i=new Map,a=[];for(;n<e.length;){let l=e[n];const c=l.stateName;if(!1===l.replaceNode.isConnected){o.debug&&console.log(`applyChangeFromBindings: skip disconnected binding: ${l.bindingType} ${l.statePathName} on ${l.node.nodeName}`,l),n++;continue}let d=l.replaceNode.getRootNode();d instanceof DocumentFragment&&!(d instanceof ShadowRoot)&&(d=yt(d),null===d&&se("Root node for fragment not found for binding."));const u=Si(d,c);null===u&&se(`State element with name "${c}" not found for binding.`),u.createState("readonly",o=>{const f={rootNode:d,stateName:c,stateElement:u,state:o,appliedBindingSet:s,newListValueByAbsAddress:r,updatedAbsAddressSetByStateElement:i,deferredSelectBindings:a,sameRootVerified:!0,propagationContextByBinding:t};for(;;){try{xr(l,f)}catch(e){$r(l,e)}n++;const t=e[n];if(!t)break;const o=t.replaceNode.getRootNode();if(t.stateName!==c||o!==f.rootNode)break;l=t}})}for(const{binding:e,value:n}of a)try{er(e,{propagationContextByBinding:t},n)}catch(t){$r(e,t)}for(const[e,t]of r.entries())tt(e,t);for(const[e,t]of i.entries())e.createState("writable",e=>{e[lt](Array.from(t))})}function _r(e,t){const[n,o,s]=He(e),r=qo(e);for(const e of n)Ye(e,t);Pr(r.initialize(o)),function(e,t,n){for(const o of e)n.deferUntilDefined(o.node,o.tagName,()=>{const e=Ke(o);0!==e.length&&(Ye(o.node,t),Pr(n.initialize(e)))},e=>{console.error(`[@wcstack/state] deferred spread failed for <${o.tagName}>.`,e)})}(s,t,r)}const Ar=/\{\{\s*(.+?)\s*\}\}/g,kr=new Set(["SCRIPT","STYLE"]);function Cr(e){if(!o.enableMustache)return;!function(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[];for(;t.nextNode();)n.push(t.currentNode);for(const e of n)e.parentElement&&kr.has(e.parentElement.tagName)||Er(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),Cr(t.content)}else Cr(e.content)}function Er(e){const t=e.data;if(Ar.lastIndex=0,!Ar.test(t))return;Ar.lastIndex=0;const n=document.createDocumentFragment();let o,s=0;for(;null!==(o=Ar.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 Mr;function Tr(){if(Mr)return Mr;const e=[],t=Se("not",e)(ve);return Mr={filterName:"not",args:e,filterFn:t},Mr}const Or=/^(\s*@@\s*(?:.*?)\s*:\s*)(.+?)(\s*)$/;function Rr(e,t){const n=t+s+r,o=e.indexOf("|"),i=e.indexOf("@");let a,l;if(-1!==o?(a=e.slice(0,o).trim(),l=e.slice(o)):-1!==i?(a=e.slice(0,i).trim(),l=e.slice(i)):(a=e.trim(),l=""),"."===a)a=n;else{if(!a.startsWith("."))return e;a=n+s+a.slice(1)}return l.length>0?a+l:a}function Dr(e,t){const n=Or.exec(e);if(null===n)return e;const o=n[1],s=n[2],r=n[3];return o+Rr(s,t)+r}function Lr(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=Rr(i,t);return a!==i?(o=!0,`${r}: ${a}`):e});return o?s.join(";"):e}function jr(e,t){return Lr(e,t)}function Wr(e,t){const n=o.bindAttributeName,s=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT);for(;s.nextNode();){const e=s.currentNode;if(e.nodeType===Node.COMMENT_NODE){const n=e;n.data=Dr(n.data,t);continue}const o=e;if(o instanceof HTMLTemplateElement)continue;const r=o.getAttribute(n);if(null!==r){const e=Lr(r,t);e!==r&&o.setAttribute(n,e)}}}function Br(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 Fr(e){const t=[],n=qe(e);for(const e of n){const n=We(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:Br(o),parseBindTextResults:n})}return t}function zr(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 qr=new Map([["for",o.commentForPrefix],["if",o.commentIfPrefix],["elseif",o.commentElseIfPrefix],["else",o.commentElsePrefix]]),Ur=Tr();function Vr(e,t){const n=t.outFilters;return{...t,outFilters:[...n,Ur],bindingType:e}}function Hr(e,t,n,o){zr(t),"string"==typeof o&&Wr(t,o),Gr(e,t,o);return{fragment:t,parseBindTextResult:n,nodeInfos:Fr(t)}}function Gr(e,t,n){const s=o.commentElsePrefix,r=Fe(t),i=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode(e){const t=e;if(r.length>0&&-1!==r.indexOf(t))return NodeFilter.FILTER_REJECT;if("template"===t.tagName.toLowerCase()){if((t.getAttribute(o.bindAttributeName)||"").length>0)return NodeFilter.FILTER_ACCEPT}return NodeFilter.FILTER_SKIP}});let a=null;const l=[],c=[];for(;i.nextNode();){const e=i.currentNode;c.push(e)}for(const t of c){let r=t.getAttribute(o.bindAttributeName)||"";"string"==typeof n&&(r=jr(r,n));let i=Ce(r)[0];const c=qr.get(i.bindingType);if(void 0===c)continue;const d=i.bindingType,u=t.content,f=Zo();let h=null;const p="for"===d?i.statePathName:n;if("else"===d){null===a&&se("'else' binding found without preceding 'if' or 'elseif' binding."),i=Vr("else",a.parseBindTextResult),h=Hr(e,u,i,p),Le(f,e,h);const n=l.at(-1),o=document.createComment(`@@${c}:${f}`);void 0!==n?(t.remove(),n.fragment.appendChild(o),n.nodeInfos.push({nodePath:Br(o),parseBindTextResults:We(o)})):t.replaceWith(o)}else if("elseif"===d){null===a&&se("'elseif' binding found without preceding 'if' or 'elseif' binding."),h=Hr(e,u,i,p),Le(f,e,h);const n=document.createComment(`@@${c}:${f}`),o=Zo(),r={fragment:document.createDocumentFragment(),parseBindTextResult:Vr("else",a.parseBindTextResult),nodeInfos:[]};r.fragment.appendChild(n),r.nodeInfos.push({nodePath:Br(n),parseBindTextResults:We(n)}),Le(o,e,r);const d=l.at(-1);l.push(r);const m=document.createComment(`@@${s}:${o}`);void 0!==d?(t.remove(),d.fragment.appendChild(m),d.nodeInfos.push({nodePath:Br(m),parseBindTextResults:We(m)})):t.replaceWith(m)}else{h=Hr(e,u,i,p),Le(f,e,h);const n=document.createComment(`@@${c}:${f}`);t.replaceWith(n)}"if"===d?(l.length=0,a=h):"elseif"===d?a=h:"else"===d&&(a=null,l.length=0)}}async function Kr(e){const t=e.querySelectorAll(o.tagNames.state),n=[],s=Y(e);null===s&&se(`CustomElementRegistry is unavailable for <${o.tagNames.state}>.`),await s.whenDefined(o.tagNames.state);for(const e of t){if(Be(e))continue;const t=e;n.push(t.initializePromise)}await Promise.all(n)}async function Jr(e){if(e===document)await Kr(document),Cr(document),Gr(document,document),_r(document.body,null);else{const t=e;t.host.hasAttribute(o.bindAttributeName)&&await z(t.host),await Kr(t),Cr(t),Gr(t,t),_r(t,null)}}const Xr="1.32.0",Yr="undefined"==typeof HTMLElement?class{}:HTMLElement,Qr=/^@@wcs-(?:for|if|elseif|else):[^-]/,Zr=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,ei=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,ti=/^@@wcs-text-start:(.+)$/;function ni(e){return e.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class oi extends Yr{_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=Xr.split(".");return t[0]===n[0]&&t[1]===n[1]}setStateData(e){this._stateData=e}setHydrateProps(e){this._hydrateProps=e}_loadStateData(){const e=this.querySelector('script[type="application/json"]:not([data-wcs-ssr-props])');if(!e)return{};try{return JSON.parse(e.textContent||"{}")}catch{return{}}}_loadTemplates(){const e=new Map,t=this.querySelectorAll("template[id]");for(const n of t){const t=n.getAttribute("id");t&&e.set(t,n)}return e}_loadHydrateProps(){const e=this.querySelector("script[data-wcs-ssr-props]");if(!e)return{};try{return JSON.parse(e.textContent||"{}")}catch{return{}}}static findByName(e,t){const n=o.tagNames.ssr,s=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!s)return null;return s.querySelector(`${n}[name="${t}"]`)}static extractStateData(e){const t=e.__state;if(!t||"object"!=typeof t)return{};const n={};for(const[e,o]of Object.entries(t))e.startsWith("$")||"function"==typeof o||(n[e]=o);return n}static buildContent(e,t){const n=document.createElement("script");n.setAttribute("type","application/json"),n.textContent=ni(JSON.stringify(t)),e.appendChild(n);const s=Array.from(De.keys());for(const t of s){const n=je(t);if(!n)continue;const s=document.createElement("template");s.setAttribute("id",t);const r=n.parseBindTextResult,i="else"===r.bindingType?"else:":`${r.bindingType}: ${r.statePathName}`;s.setAttribute(o.bindAttributeName,i);const a=n.fragment.cloneNode(!0);s.content.appendChild(a),e.appendChild(s)}const r=Array.from(Qs);if(r.length>0){const t={};for(let e=0;e<r.length;e++){const n=r[e],o=Ys(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=ni(JSON.stringify(t)),e.appendChild(n)}}Qs.clear()}static removeBlockBoundaryComments(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),n=[];for(;t.nextNode();){const e=t.currentNode;(Zr.test(e.data)||ei.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;Qr.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=ti.exec(e.data);o&&n.push({comment:e,path:o[1]})}for(const{comment:e,path:t}of n){const n=document.createComment(`@@: ${t}`);e.parentNode.insertBefore(n,e);let o=e.nextSibling;e.remove();const s=`@@wcs-text-end:${t}`;for(;o;){const e=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===s){o.parentNode.removeChild(o);break}o.parentNode.removeChild(o),o=e}}}static cleanupDom(e){const t=document.body,n=e.querySelectorAll(o.tagNames.ssr),s=new Map;for(const e of n){const t=e.querySelectorAll("template[id]");for(const e of t){const t=e.getAttribute("id");t&&s.set(t,e)}}const r=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),i=[];for(;r.nextNode();){const e=r.currentNode;Zr.test(e.data)&&i.push(e)}for(const e of i){const t=Zr.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()}oi.restoreTextBindings(t);const a=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),l=[];for(;a.nextNode();){const e=a.currentNode;if(Qr.test(e.data)){const t=e.data.split(":")[1];l.push({comment:e,uuid:t})}}for(const{comment:e,uuid:t}of l){const n=s.get(t);if(n){const t=document.createElement("template"),s=n.getAttribute(o.bindAttributeName);s&&t.setAttribute(o.bindAttributeName,s);const r=document.importNode(n.content,!0);if(r.childNodes.length>0)t.content.appendChild(r);else for(const e of Array.from(n.childNodes))t.content.appendChild(document.importNode(e,!0));e.parentNode.replaceChild(t,e)}}const c=e.querySelectorAll("[data-wcs-ssr-id]");for(const e of c)e.removeAttribute("data-wcs-ssr-id");for(const e of n)e.remove()}}const si=new Set(["for","if","elseif","else"]);function ri(e){const t=new zo;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]=He(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 ii(e,t,n){const s={for:o.commentForPrefix,if:o.commentIfPrefix,elseif:o.commentElseIfPrefix,else:o.commentElsePrefix}[t];if(!s)return null;const r=`@@${s}:${n}`,i=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;i.nextNode();){const e=i.currentNode;if(e.data===r)return e}return null}function ai(e,t){const n=e;let s=null;for(const[e,r]of t.templates){let t=Ce(r.getAttribute(o.bindAttributeName)||"")[0];const i=t.bindingType;"else"===i&&s?t={...s,outFilters:[...s.outFilters,Tr()],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;zr(a),"string"==typeof l&&Wr(a,l),Gr(n,a,l);Le(e,n,{fragment:a,parseBindTextResult:t,nodeInfos:Fr(a)})}}async function li(e){await Kr(e);const t=e.querySelectorAll(o.tagNames.ssr);for(const n of t){const t=n;if(!t.verifyVersion())return console.warn(`[@wcstack/state] SSR version mismatch: server="${t.version}", client="${Xr}". Falling back to full render.`),oi.cleanupDom(e),!1}for(const n of t)ai(e,n);const n=function(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const e of o){const n=Zr.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=Es(o.nodes),{bindingInfos:s,subscriberNodes:i,bindingSession:a}=ri(o.nodes);gs(t,a);for(const e of i)e.nodeType===Node.ELEMENT_NODE&&e.setAttribute("data-wcs-completed","");hs(t,s),ws(t,i);const l=[];for(const e of s)e.statePathName in S&&l.push(e);if(Yo(t,l),"for"===o.type&&null!==o.index){const i=ii(e,"for",o.uuid);if(i){const e=ns(null,o.index);Us(i,e,t),Vs(i,o.nodes[o.nodes.length-1]),$s(i,t),vs(t,Wt(H(o.path+"."+r),e)),a.initialize(s,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1});let l=n.get(o.uuid);l||(l=[],n.set(o.uuid,l)),l.push(e)}}else{const n=ii(e,o.type,o.uuid);n&&($s(n,t),a.initialize(s,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}))}}for(const[t,o]of n){const n=ii(e,"for",t);if(!n)continue;const s=n.getRootNode(),r=je(t);if(!r)continue;const i=r.parseBindTextResult.stateName,a=r.parseBindTextResult.statePathName,l=Si(s,i);l&&l.createState("readonly",e=>{const t=e[a];Array.isArray(t)&&rs(t,o)})}}(document.body,n),oi.removeBlockBoundaryComments(document.body);const s=[];for(const e of t)e.parentNode&&(s.push({el:e,parent:e.parentNode,next:e.nextSibling}),e.remove());oi.restoreTextBindings(document.body);const[i,a]=He(document.body);for(const e of i)if(e.nodeType===Node.ELEMENT_NODE){const t=e;t.hasAttribute("data-wcs-completed")||(Ye(e,null),t.setAttribute("data-wcs-completed",""))}else Ye(e,null);const l=[],c=[],d=qo(document.body).initialize(a);for(const e of d)if("event"!==e.bindingType)if(si.has(e.bindingType))c.push(e);else{if(e.statePathName.includes(r))continue;l.push(e)}for(const e of c)if("for"===e.bindingType){const t=_t(e),n=Si(e.replaceNode.getRootNode(),e.stateName);n&&n.createState("readonly",n=>{const o=n[e.statePathName];Array.isArray(o)&&tt(t,o)})}Pr(l);for(const{el:e,parent:t,next:n}of s)t.insertBefore(e,n);const u=e.querySelectorAll(o.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 ci=Symbol.for("wcstack.binder");const di=Symbol.for("wcstack.binder.pending"),ui=Symbol.for("wcstack.binder.taken");function fi(){const e=function(){const e=globalThis[ci];return null==e||"wcs-binder"!==e.protocol||"number"!=typeof e.version||e.version<1||"function"!=typeof e.bind?null:e}();if(null===e)return;const t=function(){const e=globalThis;let t=e[di];return void 0===t&&(t=[],e[di]=t),t}();if(0===t.length)return;const n=t.splice(0,t.length),o=function(){const e=globalThis;let t=e[ui];return void 0===t&&(t=new WeakSet,e[ui]=t),t}();for(const t of n)o.add(t),e.bind(t)}function hi(e){if(To(e))return!0;if(!pi(e))return!1;if(e.hasAttribute(o.bindAttributeName))return!1;const t=e.querySelector(`[${o.bindAttributeName}]`);return null!==t&&To(t)}function pi(e){return 1===e.nodeType}function mi(e){if(hi(e))return;Cr(e),Gr(e.getRootNode(),e);const t=e.hasAttribute(o.bindAttributeName),n=e.parentNode,s=null!==n&&(1===n.nodeType||9===n.nodeType||11===n.nodeType);_r(t&&s?n:e,null)}const gi=[];function bi(){const e=gi.splice(0,gi.length);for(const t of e)mi(t);fi()}const yi={protocol:"wcs-binder",version:1,bind:function(e){var t;pi(e)&&!hi(e)&&(t=e.getRootNode(),xi.has(t)?mi(e):gi.push(e))}};const wi=new WeakMap,vi=new WeakMap,Ni=new Set;function Si(e,t){let n=wi.get(e);return n&&n.get(t)||null}function Ii(e){return vi.get(e)??Promise.resolve()}const xi=new WeakSet;function $i(e){xi.add(e)}function Pi(e,n,s){let r=wi.get(e);if(null===s){if(!r)return;const t=r.get(n);r.delete(n),0===r.size&&wi.delete(e),void 0!==t&&(Ni.delete(t),null!==Qe&&Qe({type:"state:element-unregistered",name:n,rootNode:e,element:t})),o.debug&&console.debug(`State element unregistered: name="${n}"`)}else{if(!r){r=new Map,wi.set(e,r);const n=!t()&&s.hasAttribute?.("enable-ssr");if("HTMLDocument"===e.constructor.name||"Document"===e.constructor.name){const t=new Promise((t,o)=>{queueMicrotask(async()=>{try{if(n){await li(e)||await Jr(e)}else await Jr(e);$i(e),bi(),t()}catch(e){o(e)}})});vi.set(e,t)}else if("ShadowRoot"===e.constructor.name){const t=new Promise((t,n)=>{queueMicrotask(async()=>{try{await Jr(e),$i(e),bi(),t()}catch(e){n(e)}})});vi.set(e,t)}}r.has(n)&&se(`State element with name "${n}" is already registered.`),r.set(n,s),Ni.add(s),null!==Qe&&Qe({type:"state:element-registered",name:n,rootNode:e,element:s}),o.debug&&console.debug(`State element registered: name="${n}"`,s)}}let _i=0,Ai=0;const ki=[];function Ci(e,t=0){const n=ki.findIndex(e=>e.priority>t),o={listener:e,priority:t};-1===n?ki.push(o):ki.splice(n,0,o)}function Ei(e){queueMicrotask(()=>{throw e})}const Mi=new class{_queueUpdateRecords=[];constructor(){}enqueueAbsoluteAddress(e,t=null){_i>Ai&&(Ai=_i);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 n=new Map;for(const t of e){const e=n.get(t.absoluteAddress);null!==Qe&&null!=e&&null!==t.context&&e.transactionId!==t.context.transactionId&&Qe({type:"propagation:coalesced",absoluteAddress:t.absoluteAddress,droppedTransactionId:e.transactionId,winnerTransactionId:t.context.transactionId}),n.set(t.absoluteAddress,t.context)}const o=[],s=new Map;for(const[e,t]of n){if(null!==t&&t.hop>=32){console.error("[@wcstack/state] propagation hop limit exceeded; update record quarantined.",{path:e.absolutePathInfo.pathInfo.path,stateName:e.absolutePathInfo.stateName,transactionId:t.transactionId,hop:t.hop,maxHops:32}),null!==Qe&&Qe({type:"propagation:hop-limit",absoluteAddress:e,transactionId:t.transactionId,hop:t.hop});continue}const n=Rt(e);if(void 0!==n)if(n instanceof Set)for(const e of n)!1!==e.replaceNode.isConnected&&(o.push(e),null!==t&&s.set(e,t));else!1!==n.replaceNode.isConnected&&(o.push(n),null!==t&&s.set(n,t))}try{const e=()=>{s.size>0?Pr(o,s):Pr(o)};if(t()||0===o.length)e();else{const t=function(e,t,n){const o=Rs(e);if(null!==o)return o.run(t,{source:e,types:n});t()}("state",e);void 0!==t&&t.catch(Ei)}}finally{!function(e){for(const t of ki.slice())t.listener(e)}(new Set(n.keys()))}}};function Ti(){return Mi}const Oi=/^\s*@@\s*(.*?)\s*:\s*(.+?)\s*$/;function Ri(e,t,n,o){return{node:e,propName:t.propName,statePathName:t.statePathName,stateName:t.stateName,bindingType:t.bindingType,inFilters:t.inFilters,outFilters:t.outFilters,origin:n,raw:o}}const Di="__WCSTACK_DEVTOOLS_HOOK__";function Li(){const e=globalThis,t=e[Di];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[Di]=n,n}const ji=e=>{null!==Qe&&Qe({type:"state:update-batch",addresses:e})};function Wi(e){const t=null!==Qe;!function(e){Qe=e}(e);const n=null!==e;n&&!t?Ci(ji,0):!n&&t&&function(e){const t=ki.findIndex(t=>t.listener===e);-1!==t&&ki.splice(t,1)}(ji)}function Bi(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,watchPaths:e.watchPaths??null,keyedListPaths:void 0===e.listKeys||null===e.listKeys?null:new Set(e.listKeys.keys())}}function Fi(e,t){return Si(t,e)??se(`devtools: state element not found: name="${e}"`)}let zi=null;function qi(){if(t())return;if(null!==zi)return;const e={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:Xr,getStateElements(){const e=[];for(const t of Ni)e.push(Bi(t));return e},keys(e,t){const n=Fi(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 Fi(e,t).createState("readonly",e=>{s=e.$resolve(n,o??[])}),s},write(e,t,n,o,s){Fi(e,t).createState("writable",e=>{void 0!==s&&s.length>0?e.$resolve(n,s,o):e[n]=o})},getDeclaredBindings:e=>function(e){const t=[],n=new Set,s=new Set,r=e=>{const o=function(e){const t=[...e.inFilters,...e.outFilters].map(e=>`${e.filterName}(${e.args.join(",")})`).join("|");return[e.stateName,e.statePathName,e.propName,e.bindingType,t].join("\0")}(e);n.has(o)||(n.add(o),t.push(e))},i=e=>{if(s.has(e))return;s.add(e);const t=je(e);if(null!==t)for(const e of t.nodeInfos)for(const t of e.parseBindTextResults)r(Ri(null,t,"fragment","")),null!=t.uuid&&i(t.uuid)},a=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT);for(let e=a.nextNode();null!==e;e=a.nextNode()){if(e.nodeType===Node.ELEMENT_NODE){const t=e,n=t.getAttribute(o.bindAttributeName);if(null===n||0===n.length)continue;try{const e=ae(t,Ce(n));for(const o of e)r(Ri(t,o,"attribute",n))}catch{}continue}const t=Oi.exec(e.data.trim());if(null===t)continue;const n=t[1]||o.commentTextPrefix,s=t[2],a=je(s);if(null===a){if(n===o.commentTextPrefix)try{r(Ri(e,Re(s),"comment",s))}catch{}}else r(Ri(e,a.parseBindTextResult,"comment",s)),i(s)}return t}(e),_setSink:Wi};zi=e,Li().register(e)}const Ui={protocol:"wcs-ssr-snapshot",version:1,build:function(e){const t=o.tagNames.state,n=o.tagNames.ssr,s=e.querySelectorAll(`${t}[enable-ssr]`);for(const e of s){const t=e.getAttribute("name")||"default",o=e.previousElementSibling;if(null!==o&&o.tagName.toLowerCase()===n&&(o.getAttribute("name")||"default")===t)continue;const s=document.createElement(n);s.setAttribute("name",t),s.setAttribute("version",Xr),oi.buildContent(s,oi.extractStateData(e)),e.parentNode?.insertBefore(s,e)}}};const Vi="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";async function Hi(e,t){let n=null;const o=`\n//# sourceURL=${t}\n`;let s=!1;const r=e=>{e.effectiveDirective.startsWith("script-src")&&(s=!0)};document.addEventListener("securitypolicyviolation",r);try{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}`)}}catch(e){throw new Error(function(e,t,n){const o=t?.message??String(t);return n?`The inline <script> of state "${e}" was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL, so script-src must allow blob:. Prefer moving the state into an external file and loading it with src="./state.js", which requires no extra CSP directive. See ${Vi}`:`Failed to evaluate the inline <script> of state "${e}": ${o}. If this page sets a Content-Security-Policy, see ${Vi}`}(t,e,s),{cause:e})}finally{document.removeEventListener("securitypolicyviolation",r)}return n&&"object"==typeof n.default?n.default:{}}async function Gi(e){try{const t=await import(function(e){return new URL(e,document.baseURI).href}(e));return t.default||{}}catch(e){se(`Failed to load script file: ${e}`)}}class Ki{_loopContextStack=Array(i).fill(void 0);_length=0;_getBaseDepth;constructor(e){this._getBaseDepth=e}createLoopContext(e,t){null===e.listIndex&&se("Cannot create loop context for a state address that does not have a list index.");const n=e;this._length>=i&&se("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&&se("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&&se("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else if(n.listIndex.length!==n.pathInfo.wildcardCount){const e=this._getBaseDepth();n.listIndex.length!==n.pathInfo.wildcardCount+e&&se(`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}, base depth ${e}).`)}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 Ji=new WeakMap;function Xi(e,t){let n=Ji.get(e);void 0===n&&(n=new Map,Ji.set(e,n));let o=n.get(t);return void 0===o&&(o=new sn(t,e.name),n.set(t,o)),o}const Yi=new WeakMap;function Qi(e){const t=Yi.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 Xi(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:Xi(e,n)}},set(){se("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){se("$command namespace is read-only; deleting from it is not allowed.")}});return Yi.set(e,n),n}const Zi=Symbol("wcs-stream-last-notified-uncertain"),ea=new WeakMap;function ta(e,t){const n=ea.get(e);if(void 0!==n)for(const e of n.keys())t.has(e)||n.delete(e)}function na(e,t){const n=ea.get(e);if(void 0===n)return;const o=n.get(t);void 0!==o&&n.set(t,{status:"idle"===o.status?o.status:Zi,error:Object.is(o.error,null)?null:Zi})}const oa=new Set;function sa(e){oa.delete(e)}const ra=new WeakMap;function ia(e){return ra.get(e)??new Map}function aa(e){sa(e);const t=ra.get(e);if(void 0!==t)for(const n of t.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,na(e,n.name)}const la=(e,t)=>t,ca=new Set;function da(e,t){const n=t[T];if(void 0===n)return void ta(e,ca);"object"==typeof n&&null!==n||se(`${T} must be an object mapping stream names to stream definitions.`);const o=new Map;for(const[i,a]of Object.entries(n)){0===i.length&&se(`${T} entry name must be a non-empty string.`),i.includes(s)&&se(`${T} entry "${i}" must be a flat property name ("${s}" is not allowed).`),i.includes(r)&&se(`${T} entry "${i}" must be a flat property name ("${r}" is not allowed).`),i.startsWith("$")&&se(`${T} entry "${i}" must not start with "$" (reserved namespace).`),i in Object.prototype&&se(`${T} entry "${i}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),e.getterPaths.has(i)&&se(`${T} entry "${i}" conflicts with a getter declared on the state.`),e.setterPaths.has(i)&&se(`${T} entry "${i}" conflicts with a setter declared on the state.`),"object"==typeof a&&null!==a||se(`${T} entry "${i}" must be an object ({ args?, source, fold?, initial? }).`);const n=a;"function"!=typeof n.source&&se(`${T} entry "${i}" source must be a function.`);const l=void 0!==n.fold;l&&"function"!=typeof n.fold&&se(`${T} entry "${i}" fold must be a function.`),l&&!("initial"in n)&&se(`${T} entry "${i}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==n.args&&"function"!=typeof n.args&&se(`${T} entry "${i}" args must be a function.`);const c={name:i,definition:{args:n.args??null,source:n.source,fold:n.fold??la,initial:n.initial},status:"idle",error:null,controller:null,depAddresses:new Set};i in t||(t[i]=c.definition.initial),o.set(i,c)}!function(e,t){ra.set(e,t)}(e,o),ta(e,new Set(o.keys()))}const ua=new WeakMap,fa=new WeakMap;function ha(e,t,n){return new Proxy(Object.create(null),{get(t,o){if("string"!=typeof o)return;const s=ia(e).get(o);return void 0!==s?n(s):void 0},has:(t,n)=>"string"==typeof n&&ia(e).has(n),ownKeys:()=>Array.from(ia(e).keys()),getOwnPropertyDescriptor(t,o){if("string"!=typeof o)return;const s=ia(e).get(o);return void 0!==s?{configurable:!0,enumerable:!0,value:n(s)}:void 0},set(){se(`${t} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){se(`${t} namespace is read-only; deleting from it is not allowed.`)}})}function pa(e){const t=ua.get(e);if(void 0!==t)return t;const n=ha(e,D,e=>e.status);return ua.set(e,n),n}function ma(e){const t=fa.get(e);if(void 0!==t)return t;const n=ha(e,L,e=>e.error);return fa.set(e,n),n}function ga(e){ua.delete(e),fa.delete(e)}let ba=null;async function ya(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 wa(e){const t=ia(e);if(0!==t.size){!function(e){oa.add(e)}(e);for(const n of t.values())va(e,n)}}function va(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=ba,r=new Set;let i;ba=r;try{e.createState("readonly",e=>{i=n(e)})}finally{ba=o}i instanceof Promise&&se(`${T} entry "${t.name}" args must be synchronous (it returned a Promise).`);const a=`${D}${s}${t.name}`,l=`${L}${s}${t.name}`;for(const n of r){const o=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==e||o.path!==t.name&&o.path!==a&&o.path!==l||se(`${T} 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&&se(`${T} entry "${t.name}" args must not read wildcard paths ("${o.path}"): wildcard dependencies are out of scope.`)}return t.depAddresses=r,i}(e,t);e.createState("writable",e=>{e[t.name]=t.definition.initial}),Na(e,t,"active",null);const r=t.definition,i={fold(n){e.createState("writable",e=>{e[t.name]=r.fold(e[t.name],n)})},done(){Na(e,t,"done",null)},fail(o){Na(e,t,"error",o),n.abort()}};ya(r.source,o,n.signal,i)}function Na(e,t,n,o){t.status=n,t.error=o;const r=function(e,t){return ea.get(e)?.get(t)??{status:"idle",error:null}}(e,t.name),i=r.status!==n,a=!Object.is(r.error,o);(i||a)&&(!function(e,t,n,o){let s=ea.get(e);void 0===s&&(s=new Map,ea.set(e,s)),s.set(t,{status:n,error:o})}(e,t.name,n,o),e.createState("writable",e=>{i&&e.$postUpdate(`${D}${s}${t.name}`),a&&e.$postUpdate(`${L}${s}${t.name}`)}))}Ci(function(e){const t=oa;if(0===t.size)return;const n=[];for(const o of t)for(const t of ia(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)&&ia(e).get(o.name)===o)try{va(e,o)}catch(n){o.controller?.abort(),t.has(e)&&ia(e).get(o.name)===o&&Na(e,o,"error",n)}},20);const Sa=new WeakMap,Ia=new Set,xa=new Map;function $a(e){return Sa.get(e)??xa}function Pa(){return Ia}function _a(e,t){const n=t[O];if(void 0===n)return null;"object"==typeof n&&null!==n||se(`[wcs/watch-declaration-invalid] ${O} must be an object mapping state paths to handler functions.${fe}`);const o=new Map,s=new Set;let r=0;for(const[t,i]of Object.entries(n)){"function"!=typeof i&&se(`[wcs/watch-declaration-invalid] ${O} entry "${t}" must be a function.${fe}`),0===t.length&&se(`[wcs/watch-declaration-invalid] ${O} entry name must be a non-empty state path.`),t.startsWith("$")&&se(`[wcs/watch-declaration-invalid] ${O} entry "${t}" must not start with "$" (reserved namespace).${fe}`),t.includes("@")&&se(`[wcs/watch-declaration-invalid] ${O} entry "${t}" must not target another state ("@" is not allowed); watch only paths of its own state.${fe}`),t in Object.prototype&&se(`[wcs/watch-declaration-invalid] ${O} entry "${t}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const n=H(t);for(const e of n.segments)0===e.length&&se(`[wcs/watch-declaration-invalid] ${O} entry "${t}" has an empty path segment.${fe}`);n.wildcardCount>128&&se(`[wcs/watch-declaration-invalid] ${O} entry "${t}" exceeds the maximum wildcard depth (128).`),o.set(t,{path:t,pathInfo:n,handler:i,order:r++}),s.add(t),e.setPathInfo(t,"prop","watch")}return function(e,t){Sa.set(e,t)}(e,o),s.size>0?s:null}const Aa=new WeakMap;function ka(e,t,n){let o=Aa.get(e);void 0===o&&(o=new Map,Aa.set(e,o)),o.set(t,n)}const Ca=new Map;function Ea(e){0!==$a(e).size&&(function(e){Ia.add(e)}(e),function(e){const t=[];for(const n of $a(e).values())Ta(e,n)&&t.push(n);if(0===t.length)return;e.createState("readonly",n=>{for(const o of t)try{ka(e,Ma(e,o),n[o.path])}catch(t){Ra(e,o.path,"prime",t)}})}(e))}function Ma(e,t){return mt(dt(e,t.pathInfo),null)}function Ta(e,t){return 0===t.pathInfo.wildcardCount&&e.getterPaths.has(t.path)}const Oa={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function Ra(e,t,n,o){console.error(`[@wcstack/state] $watch ${Oa[n]} "${t}" threw.`,o),null!==Qe&&Qe({type:"state:watch-error",phase:n,stateName:e.name,path:t,error:o})}function Da(e,t){if(e.entry.order!==t.entry.order)return e.entry.order-t.entry.order;const n=Math.min(e.indexes.length,t.indexes.length);for(let o=0;o<n;o++)if(e.indexes[o]!==t.indexes[o])return e.indexes[o]-t.indexes[o];return e.indexes.length-t.indexes.length}function La(e){const{stateElement:t,entry:n,absAddress:o,indexes:s}=e,r=Ta(t,n);try{t.createState("writable",e=>{let i;try{i=function(e,t,n){if(0===t.pathInfo.wildcardCount)return e[t.path];return e.$resolve(t.path,n)}(e,n,s)}catch(e){return void Ra(t,n.path,"evaluate",e)}const a=r?function(e,t){return Aa.get(e)?.get(t)}(t,o):function(e){return Ca.get(e)}(o);r&&ka(t,o,i),null!==Qe&&Qe({type:"state:watch-fired",stateName:t.name,path:n.path}),n.handler.call(e,i,a,...s)})}catch(e){Ra(t,n.path,"handler",e)}}function ja(e){return function(){const t=this.stateElement;if(!t)return;if(!0!==t.initialized)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 Wa(e){return function(t){const n=this.stateElement;n&&(!0!==n.initialized?n.initializePromise.then(()=>{n.createState("writable",n=>{n[e]=t})}):n.createState("writable",n=>{n[e]=t}))}}function Ba(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 Fa(e){return e.startsWith("$")}function za(e){const t=[];let n=e;for(;n&&n!==Object.prototype;)t.push(n),n=Object.getPrototypeOf(n);const o={};for(let e=t.length-1;e>=0;e--)Object.assign(o,Object.getOwnPropertyDescriptors(t[e]));return o}function qa(e,t){return Object.keys(e).filter(n=>{if(n.startsWith("$")||"constructor"===n)return!1;const o="function"==typeof e[n].value;return"method"===t?o:!o})}function Ua(e,t){const n=e[t];if(void 0===n)return null;Array.isArray(n)||se(`${t} must be an array of strings.`);const o=[],s=new Set;for(const e of n)"string"==typeof e&&0!==e.length||se(`${t} entries must be non-empty strings.`),e.startsWith("$")&&se(`${t} entry "${e}" must not start with "$" (internal properties are not exposed on the component).`),s.has(e)&&se(`${t} entry "${e}" is duplicated.`),s.add(e),o.push(e);return o}function Va(e){const t=Ua(e,_)??[],n=Ua(e,A)??[],o=za(e),s=function(e){const t=e[T];return"object"!=typeof t||null===t?new Set:new Set(Object.keys(t))}(e),r=[];for(const e of t){const t=o[e];if(void 0===t){if(s.has(e)){r.push(e);continue}se(`${_} entry "${e}" is not declared on the state.${ue(e,qa(o,"value"))}`)}"function"==typeof t.value&&se(`${_} entry "${e}" is a method. Declare it in ${A} instead.`)}for(const e of n){const t=o[e];void 0===t&&se(`${A} entry "${e}" is not declared on the state.${ue(e,qa(o,"method"))}`),"function"!=typeof t.value&&se(`${A} entry "${e}" is not a method. Declare it in ${_} instead.`)}return{bindables:t,commands:n,streamBackedBindables:r}}Ci(function(e){const t=Pa();try{if(0===t.size)return;const n=function(){const e=Ai;return Ai=0,e}();if(n>32){const t=Array.from(e,e=>e.absolutePathInfo.pathInfo.path);return console.error("[@wcstack/state] $watch chain depth limit exceeded; watch handlers for this batch were skipped.",{maxDepth:32,paths:t}),void(null!==Qe&&Qe({type:"state:watch-chain-limit",maxDepth:32,paths:t}))}const o=[];for(const n of e){const e=n.absolutePathInfo.stateElement;if(!t.has(e))continue;const s=$a(e).get(n.absolutePathInfo.pathInfo.path);if(void 0===s)continue;let r=[];if(s.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=St(n.listIndex,s.pathInfo.wildcardCount)}o.push({stateElement:e,entry:s,absAddress:n,indexes:r})}if(0===o.length)return;o.sort(Da),function(e){_i=e+1}(n);try{for(const e of o)t.has(e.stateElement)&&$a(e.stateElement).get(e.entry.path)===e.entry&&La(e)}finally{_i=0}}finally{Ca.clear()}},10);const Ha=new Map;class Ga{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=H(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 Ka(e){let t;return Ha.get(e)??(Ha.set(e,t=new Ga(e)),t)}function Ja(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?null:Nt(n.listIndex,o,n.pathInfo.wildcardCount)}const Xa=new WeakMap;function Ya(e,t){null===t?Xa.delete(e):Xa.set(e,t)}function Qa(e){const t=Xa.get(e);t&&(t.dirty=!0)}const Za=[],el=[];let tl=0;function nl(e,t){Za[tl]=e,el[tl]=t,tl++}function ol(){tl--,Za[tl]=void 0,el[tl]=void 0}function sl(e,t){return!0!==e.hasMappedComponentState&&(t.pathInfo.wildcardCount>0||e.getterPaths.has(t.pathInfo.path))}function rl(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 il(e,t,n,o,s){const i=t.pathInfo.segments[0];if(i===C)return rl(Qi(s),t.pathInfo.segments);if(i===D)return rl(pa(s),t.pathInfo.segments);if(i===L)return rl(ma(s),t.pathInfo.segments);if(!(t.pathInfo.path in e)){const i=t.parentAddress??se(function(e,t,n,o){return`[${ar.binding}] Path "${t}" does not exist on state "${e}".${ue(t,ir(n,"",o))}${fe}`}(s.name,t.pathInfo.path,e,s.getterPaths)),a=ll(e,i,n,o);if(null==a)return;const l=t.pathInfo.segments[t.pathInfo.segments.length-1];if(l===r){const e=t.listIndex?.index??se(ur(`path "${t.pathInfo.path}"`,t.pathInfo.wildcardCount,t.listIndex?.length??0));return Reflect.get(a,e)}return Reflect.get(a,l)}if(s.getterPaths.has(t.pathInfo.path)){o.pushAddress(t);try{return Reflect.get(e,t.pathInfo.path,n)}finally{o.popAddress()}}else{if(!0!==s.hasMappedComponentState)return Reflect.get(e,t.pathInfo.path);nl(s,t);try{return Reflect.get(e,t.pathInfo.path)}finally{ol()}}}function al(e,t,n,o,s){const r=mt(dt(s,t.pathInfo),t.listIndex),i=function(e){return Xa.get(e)??null}(r);if(null!==i&&!1===i.dirty)return i.value;const a=il(e,t,n,o,s);return Ya(r,{value:a,dirty:!1}),a}function ll(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=vt(t.pathInfo,o);if(e>0){let r=!1;const i=t.listIndex??null,a=n.listIndex??null;for(let n=0;n<e;n++)if((null!==i?Nt(i,n,t.pathInfo.wildcardCount):null)!==(null!==a?Nt(a,n,o.wildcardCount):null)){r=!0;break}if(r)for(let n=0;n<e;n++)s.addCrossRowListPath?.(t.pathInfo.wildcardParentPaths[n])}}}}(o,t),function(e,t){if(null===ba)return;const n=dt(e,t.pathInfo);ba.add(mt(n,t.listIndex))}(o.stateElement,t);const s=o.stateElement;return sl(s,t)?al(e,t,n,o,s):il(e,t,n,o,s)}const cl=new WeakMap;function dl(e,t,n,o,s,r){const i=new Map,a=(o,s,r,l,c,d,u)=>{const f=o[s]??null;if(null===f)return void u.push(d);const h=Wt(f,r),p=cl.get(h),m=ll(e,h,t,n),g=cs(Yn(n.stateElement,r),p,m).newIndexes,b=l[c]??null;if(i.set(h,m),null===b)for(let e=0;e<g.length;e++){const t=g[e];a(o,s+1,t,l,c+1,d.concat(t.index),u)}else{const e=g[b]??se(`ListIndex not found at index ${b} of ${f.path}`);s+1<o.length?a(o,s+1,e,l,c+1,d.concat(e.index),u):u.push(d.concat(e.index))}},l=[];if(a(o.wildcardParentPathInfos,0,null,s,0,[],l),r.commitDiffBaseline)for(const[e,t]of i.entries())cl.set(e,t);return l}function ul(e,t,n,o,s){let r=null;for(let i=0;i<o.wildcardParentPathInfos.length;i++){const a=o.wildcardParentPathInfos[i],l=ss(ll(e,Wt(a,r),t,n));null==l&&se(`ListIndexes not found: ${a.path}`);const c=s[i];r=l[c]??se(`ListIndex not found at index ${c} of ${a.path}`)}return r}function fl(e,t,n){const o=e.bindableEventMap,s=o[t.path],r="string"==typeof s,i=r?s:t.segments.length>1?o[t.segments[0]]:void 0;if("string"!=typeof i)return;const a=e.rootNode;a instanceof ShadowRoot&&a.host.dispatchEvent(new CustomEvent(i,{detail:r&&void 0!==n?n.value:void 0,bubbles:!0}))}function hl(e,t,n,o){"object"==typeof e&&null!==e||se(`${R} list "${t}": ${n} row at index ${o} must be a plain object (got ${null===e?"null":typeof e}).`);const s=Object.getPrototypeOf(e);s!==Object.prototype&&null!==s&&se(`${R} list "${t}": ${n} row at index ${o} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function pl(e,t,n,o,s){const r="function"==typeof t?t(e):e[t];return null==r&&se(`${R} list "${n}": ${o} row at index ${s} has no key (${"function"==typeof t?"key function":`field "${t}"`} returned ${String(r)}).`),r}function ml(e,t,n,o){const s=new Array(e.length),r=new Set;for(let i=0;i<e.length;i++){const a=e[i];hl(a,n,o,i);const l=pl(a,t,n,o,i);r.has(l)&&se(`${R} list "${n}": duplicate key ${JSON.stringify(l)} in ${o} list.`),r.add(l),s[i]=l}return s}function gl(e,t){const n=[];for(const o of Object.keys(t))Object.is(e[o],t[o])||n.push({field:o,value:t[o]});for(const o of Object.keys(e))Object.hasOwn(t,o)||null==e[o]||n.push({field:o,value:null});return n}function bl(e,t,n,o){if(t.pathInfo.path in e)return!0;const s=t.parentAddress;if(null===s)return!1;const i=ll(e,s,n,o);if(null===i||"object"!=typeof i&&"function"!=typeof i)return!1;const a=t.pathInfo.lastSegment;if(a===r){const e=t.listIndex?.index;return"number"==typeof e&&e in i}return a in i}const yl=new WeakMap;function wl(e,t){null===t?yl.delete(e):yl.set(e,t)}function vl(e,t,n){const s=H(e.wildcardParentPaths[t]),r=dt(e.stateElement,s),i=Wt(s,n),a=et(mt(r,n)),l=e.stateProxy[ot](i),c=function(e,t){switch(t){case"old":return e.oldIndexes;case"new":return e.newIndexes;case"add":return e.addIndexSet;case"change":return e.changeIndexSet;case"delete":return e.deleteIndexSet;default:return o.debug&&console.log(`Invalid search type: ${t}`),[]}}(cs(Yn(e.stateElement,i.listIndex),a,l),e.searchType);if(t===e.wildcardPaths.length-1)e.targetListIndexes.push(...c);else for(const n of c)vl(e,t+1,n)}const Nl=[];function Sl(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?e.keyedMergePath===t?{fullRows:Nl,movedRows:null}:{fullRows:s.newIndexes,movedRows:null}:{fullRows:Nl,movedRows:null}:{fullRows:s.addIndexSet,movedRows:s.changeIndexSet}}const Il=[];function xl(e,t,n){const o=e.stateElement.indexDependentGetterPaths;if(!o||0===o.size)return Il;let r=null;const i=t+s;for(const e of o){if(e!==t&&!e.startsWith(i))continue;const o=H(e);if(o.wildcardCount!==n.wildcardCount)return null;(r??=[]).push(o)}return r??Il}function $l(e,t,n){const o=t.pathInfo.path,s=e.staticMap.get(o);if(s)for(const i of s){const s=H(i);if(e.listPathSet.has(o)&&s.lastSegment===r){const r=e.stateProxy[ot](t),a=et(mt(dt(e.stateElement,t.pathInfo),t.listIndex)),l=Sl(e,o,0,0,cs(Yn(e.stateElement,t.listIndex),a,r));for(const t of l.fullRows){const o=Wt(s,t);e.result.add(o),n.push(o)}if(null!==l.movedRows){const t=xl(e,i,s);if(null===t)for(const t of l.movedRows){const o=Wt(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=Wt(s,o);e.result.add(t),n.push(t)}}}else{const o=Wt(s,t.listIndex);e.result.add(o),n.push(o)}}const i=e.dynamicMap.get(o);if(i)for(const o of i){const s=H(o),r=[];if(s.wildcardCount>0){const n=vt(t.pathInfo,s);if(s.wildcardCount-n>=1){let o;n>0?(null===t.listIndex&&se(`Cannot expand dynamic dependency with wildcard for non-list address: ${t.pathInfo.path}`),o=Nt(t.listIndex,n-1,t.pathInfo.wildcardCount)):o=null;const i={stateName:e.stateName,stateElement:e.stateElement,targetListIndexes:[],wildcardPaths:s.wildcardPaths,wildcardParentPaths:s.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};vl(i,n,o),r.push(...i.targetListIndexes)}else{null===t.listIndex&&se(`Cannot expand dynamic dependency with wildcard for non-list address: ${t.pathInfo.path}`);const e=Nt(t.listIndex,n-1,t.pathInfo.wildcardCount);r.push(e)}}else r.push(null);for(const t of r){const o=Wt(s,t);e.result.add(o),n.push(o)}}}function Pl(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&&se(`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",keyedMergePath:c?.keyedMergePath??null};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,$l(e,a,i);for(let e=0;e<i.length;e++)r(i[e],t+1)}}}}(f,n,l),Array.from(f.result)}function _l(e,t,n,o,s){const r=e.watchPaths;null!=r&&s&&r.has(t)&&function(e,t){Ca.has(e)||Ca.set(e,t)}(n,o)}function Al(e,t,n,s,r){const i=o.enablePropagationContext?Cn()??_n(-1):null,a=Ti();a.enqueueAbsoluteAddress(t,i),Pl(s.stateName,s.stateElement,e,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",t=>{if(t===e)return;const n=mt(dt(s.stateElement,t.pathInfo),t.listIndex);Qa(n),a.enqueueAbsoluteAddress(n,i)},{listExpansion:"diff",keyedMergePath:r})}function kl(e,t,n,o,s,i,a){try{if(!(t.pathInfo.path in e)){const n=t.parentAddress;if(null===n)return Reflect.set(e,t.pathInfo.path,o);const a=ll(e,n,s,i),l=t.pathInfo.segments[t.pathInfo.segments.length-1];if(l===r){const e=t.listIndex?.index??se(ur(`path "${t.pathInfo.path}"`,t.pathInfo.wildcardCount,t.listIndex?.length??0));return Reflect.set(a,e,o)}return Reflect.set(a,l,o)}if(i.stateElement.setterPaths.has(t.pathInfo.path)){i.pushAddress(t),i.beginUntrack();try{return Reflect.set(e,t.pathInfo.path,o,s)}finally{i.endUntrack(),i.popAddress()}}else{if(!0!==i.stateElement.hasMappedComponentState)return Reflect.set(e,t.pathInfo.path,o);nl(i.stateElement,t);try{return Reflect.set(e,t.pathInfo.path,o)}finally{ol()}}}finally{Al(t,n,s,i,a)}}function Cl(e,t,n,o,s,r,i){let a=t.parentAddress??se(`address.parentAddress is undefined path: ${t.pathInfo.path}`),l=function(e){return yl.get(e)??null}(a);if(null===l){const t=ll(e,a,s,r)??[],n=ss(t)??[];l={value:[...t],listIndexes:[...n]},wl(a,l)}try{return kl(e,t,n,o,s,r,i)}finally{const n=l.value.indexOf(o),i=ll(e,a,s,r)??[],c=Array.isArray(i)?ss(i)??[]:[],d=t.listIndex.index,u=-1!==n?l.listIndexes[n]:ns(a.listIndex,-1);c[d]=u;if(new Set(i).size===l.value.length){for(let e=0;e<c.length;e++)c[e].index=e;wl(a,null)}}}function El(e,t,n,o,i){const a=i.stateElement.listKeys;if(null!=a&&Array.isArray(n)){const l=a.get(t.pathInfo.path);if(void 0!==l){const a=ll(e,t,o,i),c=function(e,t,n,o){const s=ml(o,t,e,"new");if(!Array.isArray(n)||0===n.length||0===o.length)return null;const r=n,i=ml(r,t,e,"current"),a=new Map;for(let e=0;e<r.length;e++)a.set(i[e],r[e]);const l=new Array(o.length),c=[];for(let e=0;e<o.length;e++){const t=o[e],n=a.get(s[e]);void 0!==n&&n!==t?(l[e]=n,c.push({position:e,oldRow:n,newRow:t})):l[e]=t}return c.length>0?{list:l,matched:c}:null}(t.pathInfo.path,l,a,n);if(null!==c)return function(e,t,n,o,i,a){const l=t.pathInfo.path,c=Yn(a.stateElement,t.listIndex);null===ss(o)&&cs(c,null,o);const d=cs(c,o,n.list),u=Ml(e,t,n.list,i,a,l),f=H(l+s+r);for(const t of n.matched){const n=gl(t.oldRow,t.newRow);if(0===n.length)continue;const o=d.newIndexes[t.position];for(const r of n)void 0!==o?El(e,Wt(H(f.path+s+r.field),o),r.value,i,a):t.oldRow[r.field]=r.value}return u}(e,t,c,a,o,i)}}return Ml(e,t,n,o,i,null)}function Ml(e,t,n,s,i,a){const l=i.stateElement,c=t.pathInfo.path,d=!!Tn&&(Tn=!1,!0);if(!(c in e)&&null!==t.parentAddress&&!l.elementPaths.has(c)){const u=ll(e,t.parentAddress,s,i);if("object"==typeof u&&null!==u){const e=t.pathInfo.lastSegment,f=e===r?t.listIndex?.index:e;let h,p=!1;if(!d&&o.sameValueGuard&&(null===n||"object"!=typeof n)){const e=void 0!==f&&f in u,t=void 0!==f?u[f]:void 0;if(e&&Object.is(t,n))return!0;h=t,p=!0}const m=sl(l,t),g=mt(dt(l,t.pathInfo),t.listIndex);null!==Qe&&Qe({type:"state:write",absoluteAddress:g,value:n,oldValue:h,hasOldValue:p}),_l(l,c,g,h,p);try{return void 0===f&&se(ur(`path "${c}"`,t.pathInfo.wildcardCount,t.listIndex?.length??0)),Reflect.set(u,f,n)}finally{Al(t,g,s,i,a),m&&Ya(g,{value:n,dirty:!1}),fl(l,t.pathInfo,{value:n})}}}let u,f=!1;if(!d&&o.sameValueGuard&&(null===n||"object"!=typeof n)){const o=ll(e,t,s,i);if(bl(e,t,s,i)&&Object.is(o,n))return!0;u=o,f=!0}const h=l.elementPaths.has(t.pathInfo.path),p=sl(l,t),m=mt(dt(l,t.pathInfo),t.listIndex);null!==Qe&&Qe({type:"state:write",absoluteAddress:m,value:n,oldValue:u,hasOldValue:f}),_l(l,c,m,u,f);try{return h?Cl(e,t,m,n,s,i,a):kl(e,t,m,n,s,i,a)}finally{p&&Ya(m,{value:n,dirty:!1}),fl(l,t.pathInfo,{value:n})}}function Tl(e,t,n,o){return(t,s,r)=>{const i=H(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)}s.length!==i.wildcardParentPathInfos.length&&se(cr("$resolve",t,i.wildcardParentPathInfos.length,s.length));const a=Wt(i,ul(e,n,o,i,s));if(!(void 0!==r))return ll(e,a,n,o);El(e,a,r,n,o)}}function Ol(e,t,n,o){const s=t.pathInfo;switch(t.wildcardType){case"none":return null;case"context":return Ja(o,s.wildcardPaths.at(-1)??se(`lastWildcardPath is null: ${t.pathInfo.path}`))??se(`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]??se(`wildcardParentPathInfo is null: ${t.pathInfo.path}`),a=ss(ll(e,Wt(i,s),n,o))??se(`ListIndex not found: ${i.path}`),l=t.wildcardIndexes[r]??se(`wildcardIndex is null: ${t.pathInfo.path}`);s=a[l]??se(`ListIndex not found at index ${l} of ${i.path}`)}return s}case"partial":se(`Partial wildcard type is not supported yet: ${t.pathInfo.path}`)}}const Rl=`${D}${s}`,Dl=`${L}${s}`,Ll=new WeakMap;function jl(e,t,n,o){const s=S[t];if(void 0!==s){0===o.addressStackLength&&se(`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;null==r&&se(`ListIndex not found: ${t.toString()}`);const i=Nt(r,s,e.pathInfo.wildcardCount);return i?.index??se(`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=Tl(e,0,n,o);return(t,r)=>{const i=H(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)}if(void 0!==r&&r.length>i.wildcardParentPathInfos.length&&se(cr("$getAll",t,i.wildcardParentPathInfos.length,r.length)),void 0===r){for(let e=i.wildcardPaths.length-1;e>=0;e--){const t=Ja(o,i.wildcardPaths[e]);if(t){r=St(t,t.length-Jn(o.stateElement));break}}if(void 0===r){const e=o.addressStackLength>0?o.lastAddressStack:null,n=e?.listIndex??null;i.wildcardCount>0&&null!==e&&null!==n&&n.length-Jn(o.stateElement)>0&&se(function(e,t){return`$getAll("${e}") was called without indexes inside the loop context of "${t}", but the path shares no wildcard level with that context, so the context indexes ($1..$n) do not apply. Pass indexes explicitly ([] expands every level).`}(t,e.pathInfo.path)),r=[]}}const a=dl(e,n,o,i,r,{commitDiffBaseline:!0}),l=[];for(let e=0;e<a.length;e++)l.push(s(i.path,a[e]));return l}}(e,0,n,o)(t,s);case"$setAll":return(t,s,r,i)=>function(e,t,n,o){return(t,s,r,i)=>{const a=H(t);Array.isArray(s)||se(dr(t,"requires an explicit indexes array (pass [] to expand every level).")),s.length>a.wildcardParentPathInfos.length&&se(cr("$setAll",t,a.wildcardParentPathInfos.length,s.length));const l=!0===i?.spread,c="function"==typeof r;l&&c&&se(dr(t,"cannot combine { spread: true } with a mapper function.")),l&&!Array.isArray(r)&&se(dr(t,"requires an array as the value when { spread: true } is set."));const d=dl(e,n,o,a,s,{commitDiffBaseline:!1});l&&r.length!==d.length&&se(function(e,t,n){return`$setAll("${e}", …, { spread: true }) requires the values array to have exactly one entry per matched address (matched ${t}) but got ${n}. Did the list change between $getAll and $setAll?`}(t,d.length,r.length));const u=[];for(let t=0;t<d.length;t++){const s=ul(e,n,o,a,d[t]);u.push(Wt(a,s))}let f=0;for(let t=0;t<u.length;t++){const s=u[t];let i;i=c?r(ll(e,s,n,o),...d[t]):l?r[t]:r,void 0!==i&&(El(e,s,i,n,o),f++)}return f}}(e,0,n,o)(t,s,r,i);case"$postUpdate":return t=>function(e,t,n,o){const s=o.stateElement;return t=>{const r=Ka(t),i=Ol(e,r,n,o),a=Wt(r.pathInfo,i),l=mt(dt(s,a.pathInfo),a.listIndex),c=Ti();c.enqueueAbsoluteAddress(l),Pl(o.stateName,o.stateElement,a,o.stateElement.staticDependency,o.stateElement.dynamicDependency,o.stateElement.listPaths,n,"new",e=>{const t=mt(dt(s,e.pathInfo),e.listIndex);Qa(t),c.enqueueAbsoluteAddress(t)}),fl(s,a.pathInfo)}}(e,0,n,o)(t);case"$resolve":return(t,s,r)=>Tl(e,0,n,o)(t,s,r);case"$trackDependency":return e=>function(e,t,n,o){return e=>{0===o.addressStackLength&&se(`No active state reference to track dependency for path "${e}".`);const t=o.lastAddressStack?.pathInfo??se("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 C:return Qi(o.stateElement);case D:return pa(o.stateElement);case L:return ma(o.stateElement)}if(!t.startsWith(Rl)&&!t.startsWith(Dl))return}const s=Ka(t),r=Ol(e,s,n,o),i=Wt(s.pathInfo,r);return ll(e,i,n,o)}if("symbol"==typeof t){const s=function(e){let t=Ll.get(e);return void 0===t&&(t=new Map,Ll.set(e,t)),t}(o),r=s.get(t);if(void 0!==r)return r;let i;switch(t){case nt:i=(e,t=()=>{})=>function(e,t,n){void 0!==e.loopContext&&se("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 ot:i=t=>ll(e,t,n,o);break;case st:i=t=>bl(e,t,n,o);break;case rt:i=(t,s)=>El(e,t,s,n,o);break;case it:i=()=>async function(e,t,n){const o=Reflect.get(e,I);"function"==typeof o&&await o.call(n)}(e,0,n);break;case at:i=()=>function(e,t,n){const o=Reflect.get(e,x);"function"==typeof o&&o.call(n)}(e,0,n);break;case lt:i=t=>function(e,t,n,o){const s=Reflect.get(e,$);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=St(n.listIndex,t.wildcardCount),o=r[s];void 0===o?r[s]=[e]:o.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 Wl{_stateElement;_stateName;_addressStack=Array(i).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;_untrackDepth=0;constructor(e,t,n){this._stateName=t;const o=Si(e,this._stateName);null===o&&se(`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&&se("Last address stack is undefined."),e}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(e){this._addressStackIndex+1>=i&&se(`Exceeded maximum address stack depth of 128. Possible circular dependency between path getters: ${this._describeAddressCycle()}`),this._addressStackIndex++,this._addressStack[this._addressStackIndex]=e}_describeAddressCycle(){const e=[];for(let t=this._addressStackIndex;t>=0&&e.length<8;t--){const n=this._addressStack[t];n&&e.push(n.pathInfo.path)}return`${Array.from(new Set(e)).reverse().join(" -> ")} -> ...`}popAddress(){if(this._addressStackIndex<0)return null;const e=this._addressStack[this._addressStackIndex];return void 0===e&&se(`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 jl(e,t,n,this)}set(e,t,n,o){return"readonly"===this._mutability&&se(`State "${this._stateName}" is readonly.`),function(e,t,n,o,s){if("string"==typeof t){const r=Ka(t),i=Ol(e,r,o,s);return El(e,Wt(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)}}function Bl(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 Fl{_webComponent;_innerStateElement;constructor(e,t){this._webComponent=e,this._innerStateElement=Un(e,t)??se("State element not found for web component.")}_outerLoopContext(e,t){const n=t.pathInfo.wildcardCount,o=Xn(t.stateElement,t.pathInfo),s=Xe(this._webComponent);if(null!==s&&s.listIndex.length===o)return s;if(n>0){const s=function(e,t){if(0===tl)return null;const n=tl-1,o=el[n];return Za[n]!==e||o?.pathInfo.path!==t?null:o}(this._innerStateElement,e.path),r=s?.listIndex??null;if(null!==r&&r.length===o){return Wt(H(t.pathInfo.wildcardPaths[n-1]),r)}}return s}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=H(t),s=dt(this._innerStateElement,o),r=oo(this._webComponent,s);if(null!==r){const e=this._outerLoopContext(o,r);let t;return r.stateElement.createState("readonly",n=>{n[nt](e,()=>{t=n[r.pathInfo.path]})}),t}if(t in e)return Reflect.get(e,t,n);se(`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=H(t),r=dt(this._innerStateElement,s),i=oo(this._webComponent,r);if(null!==i){const e=this._outerLoopContext(s,i);return i.stateElement.createState("writable",t=>{t[nt](e,()=>{t[i.pathInfo.path]=n})}),!0}if(t in e)return Reflect.set(e,t,n,o);se(`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=H(t),o=dt(this._innerStateElement,n);return null!==oo(this._webComponent,o)||t in e}return Reflect.has(e,t)}}class zl{_innerStateElement;constructor(e,t){this._innerStateElement=Un(e,t)??se("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 ql=e=>()=>e;function Ul(e,t,n,s){!function(e,t,n){let o=qn.get(e);o||(o=new Map,qn.set(e,o)),o.set(t,n)}(t,n,e);const r=t.hasAttribute(o.bindAttributeName)?(i=t,(ce.get(i)||null)??[]).filter(e=>e.propSegments[0]===n):[];var i;r.length>0?(!function(e,t,n){if(0===n.length)return;const o=Un(e,t);null===o&&se("State element not found for web component.");const s=new Map,r=new Map;for(const t of n){const n=no(o,t);let i=eo.get(e);void 0===i?eo.set(e,new Set([n])):i.add(n);const a=n.innerAbsPathInfo,l=n.outerAbsPathInfo;to.set(n,t),s.set(a,l),r.set(l,a),Hn(e,l.stateElement)}Qn.set(e,s),Zn.set(e,r)}(t,n,r),e.markComponentStateMapped?.(),e.setInitialState(function(e,t){const n=new Fl(e,t),o=Un(e,t);null===o&&se("State element not found for web component."),null===o.boundComponentStateProp&&se("State element is not bound to any component state prop."),o.boundComponentStateProp in e||se(`State element is not bound to a valid component state prop: ${o.boundComponentStateProp}`);const s=e[o.boundComponentStateProp];return"object"==typeof s&&null!==s||se(`Invalid state object for component state prop: ${o.boundComponentStateProp}`),new Proxy(Bl(s),n)}(t,n))):e.setInitialState(Bl(s));const a=function(e,t){const n=new zl(e,t);return new Proxy({},n)}(t,n);if(Object.defineProperty(t,n,{get:ql(a),enumerable:!0,configurable:!0}),function(e,t){let n=Vo.get(e);n||(n=new Set,Vo.set(e,n)),n.add(t)}(t,n),P in t){const e=t[P];"function"==typeof e?e.call(t,n).catch(e=>{se(`Error in ${P}: ${e instanceof Error?e.message:String(e)}`)}):se(`${P} is not a function.`)}}class Vl extends Yr{static hasConnectedCallbackPromise=!0;static getBindingsReady(e){return Ii(e)}__state;_hasUpdatedCallback=!1;_crossRowListPaths=new Set;_indexDependentGetterPaths=new Set;_name="default";_initialized=!1;_initializePromise;_resolveInitialize=null;_connectedCallbackPromise;_resolveConnectedCallback=null;_rejectConnectedCallback=null;_loadingPromise;_resolveLoading=null;_setStatePromise=null;_resolveSetState=null;_listPaths=new Set;_listKeys=null;_elementPaths=new Set;_getterPaths=new Set;_setterPaths=new Set;_loopContextStack=function(e=()=>0){return new Ki(e)}(()=>Jn(this));_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_watchPaths=null;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_hasMappedComponentState=!1;_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,t)=>{this._resolveConnectedCallback=e,this._rejectConnectedCallback=t}),this._loadingPromise=new Promise(e=>{this._resolveLoading=e}),this._setStatePromise=new Promise(e=>{this._resolveSetState=e})}get _state(){return void 0===this.__state&&se(`${o.tagNames.state} _state is not initialized yet.`),this.__state}set _state(e){this._commandTokenNames=function(e){const t=new Set,n=e[k];if(void 0===n)return t;Array.isArray(n)||se(`${k} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||se(`${k} entries must be non-empty strings.`),e===C&&se(`${k} entry "${e}" conflicts with the reserved namespace name "${C}".`),t.has(e)&&se(`${k} entry "${e}" is duplicated.`),t.add(e);return t}(e),this._eventTokenNames=function(e){const t=new Set,n=e[E];if(void 0===n)return t;Array.isArray(n)||se(`${E} must be an array of strings.`);for(const e of n)"string"==typeof e&&0!==e.length||se(`${E} entries must be non-empty strings.`),t.has(e)&&se(`${E} entry "${e}" is duplicated.`),t.add(e);return t}(e),this.__state=e,this._hasUpdatedCallback=$ in e,tn(this),function(e,t,n){const o=t[M];if(void 0!==o){"object"==typeof o&&null!==o||se(`${M} must be an object mapping event-token names to handler functions.`);for(const[t,s]of Object.entries(o))n.has(t)||se(`${M} entry "${t}" is not declared in $eventTokens.${ue(t,n)}`),"function"!=typeof s&&se(`${M} entry "${t}" must be a function.`),en(e,t).subscribe(s)}}(this,e,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const n=function(e){const t=new Set,n=new Set,o=za(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}}(e);for(const e of n.getterPaths)this._getterPaths.add(e);for(const e of n.setterPaths)this._setterPaths.add(e);var o;ga(this),aa(o=this),sa(o),ra.delete(o),da(this,e),this._listKeys=function(e){const t=e[R];if(void 0===t)return null;"object"==typeof t&&null!==t||se(`${R} must be an object mapping list paths to key specs.`);const n=new Map;for(const[e,o]of Object.entries(t)){0===e.length&&se(`${R} entry path must be a non-empty string.`);const t=e.split(s);t.some(e=>0===e.length)&&se(`${R} entry "${e}" must not contain empty path segments.`),t[t.length-1]===r&&se(`${R} entry "${e}" must be the list path itself, not the element path (drop the trailing "${s}${r}").`),"function"!=typeof o?("string"!=typeof o&&se(`${R} entry "${e}" key spec must be a field name (string) or a function.`),0===o.length&&se(`${R} entry "${e}" key field name must be a non-empty string.`),(o.includes(s)||o.includes(r))&&se(`${R} entry "${e}" key field name "${o}" must be a flat property name ("${s}" / "${r}" are not allowed).`),o in Object.prototype&&se(`${R} entry "${e}" key field name "${o}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),n.set(e,o)):n.set(e,o)}return n.size>0?n:null}(e),function(e){Ia.delete(e),Sa.delete(e)}(this),function(e){Aa.delete(e)}(this),this._watchPaths=_a(this,e),this._initialized&&null!==this._rootNode&&!t()&&(Ea(this),wa(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=oi.findByName(t,e);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null}async _initialize(){const e=t()?null:this._loadFromSsrElement();try{if(this.hasAttribute("state")){const e=this.getAttribute("state");this._state=function(e){const t=document.getElementById(e);if(t&&"application/json"===t.type)try{return JSON.parse(t.textContent||"{}")}catch(e){se("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||se(`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 Gi(e):se(`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 Hi(e,`${this._name}`);else{const e=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${o.tagNames.state}> element with name="${this._name}".`)},6e4);this._state=await this._setStatePromise,clearTimeout(e)}}}catch(e){se(`Failed to initialize state: ${e}`)}if(null!==e&&this.__state)for(const[t,n]of Object.entries(e)){if(t in this.__state){const e=Object.getOwnPropertyDescriptor(this.__state,t);if(e&&(e.get||e.set))continue;if("function"==typeof this.__state[t])continue}this.__state[t]=n}await this._loadingPromise,this._name=this.getAttribute("name")||"default",Pi(this.rootNode,this._name,this)}async _initializeBindWebComponent(){if(this.hasAttribute("bind-component")){const e=this.parentNode,t=e instanceof ShadowRoot?e.host:e instanceof Element?e:null,n=t?J(t):null;null!==t&&null!==n||se(`"bind-component" requires <${o.tagNames.state}> to be a direct child of a custom element.`),e instanceof ShadowRoot||this.hasAttribute("name")||se('"bind-component" in Light DOM requires a "name" attribute to avoid namespace conflicts with the parent scope.');const s=["state","src","json"].filter(e=>this.hasAttribute(e));null!==this.querySelector('script[type="module"]')&&s.push('<script type="module">'),s.length>0&&se(`"bind-component" cannot be combined with ${s.join(", ")}. The component's "${this.getAttribute("bind-component")}" property is the only state source.`);const r=this.getAttribute("bind-component"),i=Y(t);null===i&&se(`CustomElementRegistry is unavailable for <${n}>.`),await i.whenDefined(n.toLowerCase()),t.hasAttribute(o.bindAttributeName)&&await z(t),r in t||se(`Component does not have property "${r}" for state binding.`);const a=t[r];"object"==typeof a&&null!==a||se(`Component property "${r}" is not an object for state binding.`),this._boundComponent=t,this._boundComponentStateProp=r,Ul(this,this._boundComponent,this._boundComponentStateProp,a)}}_initializeLightDomComponentScope(){const e=this._boundComponent;null!==e&&this.parentNode===e&&e.hasAttribute(o.bindAttributeName)&&(Gr(this._rootNode,e),_r(e,null))}_reloadMappedPathsAfterReconnect(){if(!this._hasMappedComponentState||null===this._boundComponent)return;const e=function(e){const t=eo.get(e);if(void 0===t)return[];const n=[];for(const e of t)n.push(e.innerAbsPathInfo.pathInfo.path);return n}(this._boundComponent);!function(e){const t=eo.get(e);if(void 0===t)return;const n=new Map,o=new Map;for(const e of t)n.set(e.innerAbsPathInfo,e.outerAbsPathInfo),o.set(e.outerAbsPathInfo,e.innerAbsPathInfo);Qn.set(e,n),Zn.set(e,o)}(this._boundComponent),this.createState("readonly",t=>{for(const n of e)t.$postUpdate(n)})}async _callStateConnectedCallback(){await this.createStateAsync("writable",async e=>{I in e&&await e[it]()})}async _initializeDCC(e,t){let n;try{if(this.hasAttribute("src")){const e=this.getAttribute("src");e.endsWith(".js")?n=await Gi(e):se(`DCC: Unsupported src type: ${e}`)}else{const t=this.querySelector('script[type="module"]');t?n=await Hi(t,e.tagName.toLowerCase()):se(`DCC: No state source found for "${e.tagName.toLowerCase()}".`)}}catch(e){se(`DCC: Failed to load state: ${e}`)}!function(e,t,n){const s=e.tagName.toLowerCase();s.includes("-")||se(`DCC: "${s}" is not a valid custom element name (must contain a hyphen).`);const r=Y(e);null!==r&&"function"==typeof r.define||se(`DCC: CustomElementRegistry is unavailable for "${s}".`),r.get(s)&&se(`DCC: "${s}" is already registered. A custom element name can only be defined once.`);const i=document.createElement("template");i.innerHTML=t.innerHTML;const a=t.mode,{bindables:l,commands:c,streamBackedBindables:d}=Va(n),u=l.length>0||c.length>0?function(e,t,n=[]){const o={protocol:"wc-bindable",version:1,properties:t.map(t=>({name:t,event:`${e}:${t}-changed`,getter:e=>e.target[t]})),inputs:t.map(e=>({name:e}))};if(0===n.length)return o;const s=n.map(e=>({name:e,async:!0}));return{...o,commands:s}}(s,l,c):null,f=l.length>0?function(e,t){const n={};for(const o of t)n[o]=`${e}:${o}-changed`;return n}(s,l):{},h=`${o.tagNames.state}:not([name])`,p=class extends HTMLElement{static template=i;static shadowRootMode=a;static wcBindable=u;static bindableEventMap=f;_shadow=null;_ensureShadow(){if(null!==this._shadow)return this._shadow;if(this.hasAttribute(j))return null;this._shadow=this.attachShadow({mode:p.shadowRootMode}),this._shadow.appendChild(p.template.content.cloneNode(!0));const e=Y(this._shadow);return null!==e&&Q(e,this._shadow),this._shadow}connectedCallback(){const e=this._ensureShadow();if(null!==e&&Object.keys(p.bindableEventMap).length>0){const t=e.querySelector(h);t?t.setBindableEventMap(p.bindableEventMap):console.warn(`[@wcstack/state] DCC: "${s}" declares ${_} but its template has no <${o.tagNames.state}> without a "name" attribute. Change events will not be dispatched.`)}}get stateElement(){return this._ensureShadow()?.querySelector(h)??null}},m=za(n);for(const[e,t]of Object.entries(m)){if(Fa(e))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof t.value){const o="AsyncFunction"===t.value.constructor?.name;n.value=Ba(e,o)}else n.get=ja(e),n.set=Wa(e);Object.defineProperty(p.prototype,e,n)}for(const e of d)Object.defineProperty(p.prototype,e,{configurable:!0,enumerable:!0,get:ja(e),set:Wa(e)});r.define(s,p)}(e,t,n),this._dcc=!0,this._initialized=!0,this._rootNode=null,this._resolveInitialize?.(),this._resolveConnectedCallback?.()}_callStateDisconnectedCallback(){this.createState("writable",e=>{x in e&&e[at]()})}async connectedCallback(){this._rootNode=this.getRootNode();const e=++this._connectGeneration;if(this._initialized)this._dcc||Si(this._rootNode,this._name)===this||(Pi(this._rootNode,this._name,this),this._reloadMappedPathsAfterReconnect());else{const e=this.parentNode;if(e instanceof ShadowRoot&&e.host.hasAttribute(j))return this.hasAttribute("bind-component")&&se(`"bind-component" cannot be used inside a [${j}] host. DCC state comes from the template, not from a component property.`),void await this._initializeDCC(e.host,e);await this._initializeBindWebComponent(),await this._initialize(),this._initialized=!0,this._initializeLightDomComponentScope(),this._resolveInitialize?.()}if(this.hasAttribute("enable-ssr")&&!t()||await this._callStateConnectedCallback(),t()&&this.hasAttribute("enable-ssr")&&!function(){const e=document.documentElement;return!!e&&"orchestrated"===e.getAttribute("data-wcs-server")}())try{await Ii(this.rootNode);const e=this.getAttribute("name")||"default",t=oi.extractStateData(this),n=document.createElement(o.tagNames.ssr);n.setAttribute("name",e),n.setAttribute("version",Xr),oi.buildContent(n,t),this.parentNode?.insertBefore(n,this)}catch(e){throw this._rejectConnectedCallback?.(e),e}t()||null===this._rootNode||e!==this._connectGeneration||Ea(this),t()||null===this._rootNode||e!==this._connectGeneration||this._streamsStartedGeneration===e||wa(this),this._resolveConnectedCallback?.()}disconnectedCallback(){if(null!==this._rootNode)try{this._callStateDisconnectedCallback()}finally{Pi(this.rootNode,this._name,null),e=this,Ji.delete(e),function(e){Yi.delete(e)}(this),tn(this),aa(this),ga(this),function(e){Ia.delete(e)}(this),this._rootNode=null}var e}get initialized(){return this._initialized}get initializePromise(){return this._initializePromise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get listPaths(){return this._listPaths}get listKeys(){return this._listKeys}get watchPaths(){return this._watchPaths}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&&se("State rootNode is not available."),this._rootNode}get hasRootNode(){return null!==this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get boundComponent(){return this._boundComponent}get hasMappedComponentState(){return this._hasMappedComponentState}markComponentStateMapped(){this._hasMappedComponentState=!0}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,n="binding"){if("for"===t){const t=!this._listPaths.has(e);this._listPaths.add(e),this._elementPaths.add(e+"."+r),t&&this._hasMappedComponentState&&function(e,t){const n=ro(e,H(t));null!==n&&n.stateElement!==e&&n.stateElement.setPathInfo(n.pathInfo.path,"for","internal")}(this,e)}if(!this._pathSet.has(e)){const t=H(e);if(this._pathSet.add(e),hr(this,this.__state,e,n),null!==t.parentPath){let e=t;for(;null!==e.parentPath&&this.addStaticDependency(e.parentPath,e.path);)e=H(e.parentPath)}}}_createState(e,t,n){try{const o=function(e,t,n,o){const s=new Wl(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===$&&(this._hasUpdatedCallback=!0)}setInitialState(e){this._initialized?this._state=e:this._resolveSetState?.(e)}}function Hl(e=customElements){e.get(o.tagNames.ssr)||e.define(o.tagNames.ssr,oi),e.get(o.tagNames.state)||e.define(o.tagNames.state,Vl)}function Gl(e){const t=function(){const e=document.documentElement?.lang;if(e)try{return Intl.getCanonicalLocales(e),e}catch{return void console.warn(`[@wcstack/state] <html lang="${e}"> is not a valid BCP-47 language tag. Falling back to the default locale for filters.`)}}();return void 0===t?e:{...e,locale:t}}await function(t,o){const s=Gl(t);var r;s&&((r=s).tagNames&&Object.assign(n.tagNames,r.tagNames),"string"==typeof r.bindAttributeName&&(n.bindAttributeName=r.bindAttributeName),"string"==typeof r.commentTextPrefix&&(n.commentTextPrefix=r.commentTextPrefix),"string"==typeof r.commentForPrefix&&(n.commentForPrefix=r.commentForPrefix),"string"==typeof r.commentIfPrefix&&(n.commentIfPrefix=r.commentIfPrefix),"string"==typeof r.commentElseIfPrefix&&(n.commentElseIfPrefix=r.commentElseIfPrefix),"string"==typeof r.commentElsePrefix&&(n.commentElsePrefix=r.commentElsePrefix),"string"==typeof r.locale&&(n.locale=r.locale),"boolean"==typeof r.debug&&(n.debug=r.debug),"boolean"==typeof r.enableMustache&&(n.enableMustache=r.enableMustache),"boolean"==typeof r.enableDirectionalInitialSync&&(n.enableDirectionalInitialSync=r.enableDirectionalInitialSync),"boolean"==typeof r.enablePropagationContext&&(n.enablePropagationContext=r.enablePropagationContext),"boolean"==typeof r.enableContractAnalyzer&&(n.enableContractAnalyzer=r.enableContractAnalyzer),"boolean"==typeof r.sameValueGuard&&(n.sameValueGuard=r.sameValueGuard)),Hl(o),function(){const e=globalThis;void 0===e[ci]&&(e[ci]=yi)}(),function(){const t=globalThis;void 0===t[e]&&(t[e]=Ui)}(),qi()}();
2
2
  //# sourceMappingURL=auto.min.js.map