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