@wcstack/state 3.1.0 → 3.3.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/README.ja.md +128 -90
- package/README.md +129 -91
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/define.d.ts +11 -7
- package/dist/index.d.ts +58 -15
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/manifest.d.ts +39 -5
- package/dist/manifest.esm.js +315 -253
- package/dist/parser.d.ts +16 -2
- package/dist/parser.esm.js +223 -50
- package/dist/split/chunks/binder.js +1 -1
- package/dist/split/chunks/binder.js.map +1 -1
- package/dist/split/chunks/checkDependency.js +1 -1
- package/dist/split/chunks/declarationAliases.js +2 -0
- package/dist/split/chunks/declarationAliases.js.map +1 -0
- package/dist/split/chunks/declarationHooks.js +2 -0
- package/dist/split/chunks/declarationHooks.js.map +1 -0
- package/dist/split/chunks/featureBridge.js +2 -0
- package/dist/split/chunks/featureBridge.js.map +1 -0
- package/dist/split/chunks/filterRegistry.js +1 -1
- package/dist/split/chunks/filterRegistry.js.map +1 -1
- package/dist/split/chunks/getAllPropertyDescriptors.js +1 -1
- package/dist/split/chunks/getAllPropertyDescriptors.js.map +1 -1
- package/dist/split/chunks/lifecycleHooks.js +1 -1
- package/dist/split/chunks/pathDiagnostics.js +1 -1
- package/dist/split/chunks/pathDiagnostics.js.map +1 -1
- package/dist/split/chunks/registerComponents.js +1 -1
- package/dist/split/chunks/registerComponents.js.map +1 -1
- package/dist/split/chunks/setAll.js +1 -1
- package/dist/split/chunks/setAll.js.map +1 -1
- package/dist/split/chunks/version.js +1 -1
- package/dist/split/core.d.ts +21 -9
- package/dist/split/core.js +1 -1
- package/dist/split/core.js.map +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/devtools.js.map +1 -1
- package/dist/split/features/diagnostics.js +1 -1
- package/dist/split/features/diagnostics.js.map +1 -1
- package/dist/split/features/formats.js +1 -1
- package/dist/split/features/formats.js.map +1 -1
- package/dist/split/features/recursion.js +1 -1
- package/dist/split/features/recursion.js.map +1 -1
- package/dist/split/features/scopes.js +1 -1
- package/dist/split/features/scopes.js.map +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/dist/split/features/ssr.js.map +1 -1
- package/dist/split/features/temporal.js +1 -1
- package/dist/split/features/temporal.js.map +1 -1
- package/dist/wcs-manifest.json +98 -44
- package/package.json +1 -1
- package/dist/split/chunks/mount.js +0 -2
- package/dist/split/chunks/mount.js.map +0 -1
- package/dist/split/chunks/watchRuntime.js +0 -2
- package/dist/split/chunks/watchRuntime.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as t,l as e,a as n,C as o}from"../chunks/lifecycleHooks.js";import{f as r,h as s,a,i,D as c,V as l,j as u,g as d,k as f,W as h,l as m,m as p,n as g,R as y,o as b}from"../chunks/pathDiagnostics.js";import{r as $,d as w}from"../chunks/errorGuidance.js";import{a as v,g as k,N as S}from"../chunks/getAllPropertyDescriptors.js";import{c as P}from"../chunks/filterRegistry.js";import{h as j,u as C,i as I,j as A,k as x,m as N,n as R,o as M,p as O,q as E,t as D,v as W,w as z,x as L,y as V,z as B,A as F,B as _,C as q,D as T,E as U}from"../chunks/binder.js";import{f as H,t as K,a as G,b as X,c as J,s as Q,g as Y,d as Z,e as tt,r as et,h as nt,i as ot,j as rt,k as st,l as at,m as it,n as ct,w as lt}from"../chunks/mount.js";import{p as ut}from"../chunks/diagnosticsHooks.js";import{c as dt}from"../chunks/checkDependency.js";import{y as ft,z as ht,A as mt}from"../chunks/watchRuntime.js";const pt={written:function(t,e,n){const o=t.bindableEventMap,r=o[e.path],s="string"==typeof r,a=s?r:e.segments.length>1?o[e.segments[0]]:void 0;if("string"!=typeof a)return;const i=t.rootNode;i instanceof ShadowRoot&&i.host.dispatchEvent(new CustomEvent(a,{detail:s&&void 0!==n?n.value:void 0,bubbles:!0}))}};let gt=!1;function yt(t){return function(){const e=this.stateElement;if(!e)return;if(!0!==e.initialized)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function bt(t){return function(e){const n=this.stateElement;n&&(!0!==n.initialized?n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})}):n.createState("writable",n=>{n[t]=e}))}}function $t(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function wt(t){return t.startsWith("$")}function vt(t,e){return Object.keys(t).filter(n=>{if(n.startsWith("$")||"constructor"===n)return!1;const o="function"==typeof t[n].value;return"method"===e?o:!o})}function kt(t,e){const n=t[e];if(void 0===n)return null;Array.isArray(n)||$(`${e} must be an array of strings.`);const o=[],r=new Set;for(const t of n)"string"==typeof t&&0!==t.length||$(`${e} entries must be non-empty strings.`),t.startsWith("$")&&$(`${e} entry "${t}" must not start with "$" (internal properties are not exposed on the component).`),r.has(t)&&$(`${e} entry "${t}" is duplicated.`),r.add(t),o.push(t);return o}function St(t){const e=kt(t,r)??[],n=kt(t,s)??[],o=k(t),i=function(t){const e=t[a];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),c=[];for(const t of e){const e=o[t];if(void 0===e){if(i.has(t)){c.push(t);continue}$(`${r} entry "${t}" is not declared on the state.${w(t,vt(o,"value"))}`)}"function"==typeof e.value&&$(`${r} entry "${t}" is a method. Declare it in ${s} instead.`)}for(const t of n){const e=o[t];void 0===e&&$(`${s} entry "${t}" is not declared on the state.${w(t,vt(o,"method"))}`),"function"!=typeof e.value&&$(`${s} entry "${t}" is not a method. Declare it in ${r} instead.`)}return{bindables:e,commands:n,streamBackedBindables:c}}function Pt(t,e,n){const o=t.tagName.toLowerCase();o.includes("-")||$(`DCC: "${o}" is not a valid custom element name (must contain a hyphen).`);const s=j(t);null!==s&&"function"==typeof s.define||$(`DCC: CustomElementRegistry is unavailable for "${o}".`),s.get(o)&&$(`DCC: "${o}" is already registered. A custom element name can only be defined once.`);const a=document.createElement("template"),c=a.content.ownerDocument;for(const t of Array.from(e.childNodes))a.content.appendChild(c.importNode(t,!0));const l=e.mode,{bindables:u,commands:d,streamBackedBindables:f}=St(n),h=u.length>0||d.length>0?function(t,e,n=[]){const o={protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`,getter:t=>t.target[e]})),inputs:e.map(t=>({name:t}))};if(0===n.length)return o;const r=n.map(t=>({name:t,async:!0}));return{...o,commands:r}}(o,u,d):null,m=u.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(o,u):{},p=P.tagNames.state,g=class extends HTMLElement{static template=a;static shadowRootMode=l;static wcBindable=h;static bindableEventMap=m;_shadow=null;_ensureShadow(){if(null!==this._shadow)return this._shadow;if(this.hasAttribute(i))return null;this._shadow=this.attachShadow({mode:g.shadowRootMode}),this._shadow.appendChild(g.template.content.cloneNode(!0));const t=j(this._shadow);return null!==t&&C(t,this._shadow),this._shadow}connectedCallback(){const t=this._ensureShadow();if(null!==t&&Object.keys(g.bindableEventMap).length>0){const e=t.querySelector(p);e?(gt||(gt=!0,v("dcc",pt)),e.setBindableEventMap(g.bindableEventMap)):console.warn(`[@wcstack/state] DCC: "${o}" declares ${r} but its template has no <${P.tagNames.state}>. Change events will not be dispatched.`)}}get stateElement(){return this._ensureShadow()?.querySelector(p)??null}},y=k(n);for(const[t,e]of Object.entries(y)){if(wt(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=$t(t,o)}else n.get=yt(t),n.set=bt(t);Object.defineProperty(g.prototype,t,n)}for(const t of f)Object.defineProperty(g.prototype,t,{configurable:!0,enumerable:!0,get:yt(t),set:bt(t)});s.define(o,g)}async function jt(t,o,r){const s=t;try{s.hasAttribute("bind-component")&&$(`"bind-component" cannot be used inside a [${i}] host. DCC state comes from the template, not from a component property.`);const a=await async function(t,o){try{if(t.hasAttribute("src")){const n=t.getAttribute("src");if(n.endsWith(".js"))return await e(n);$(`DCC: Unsupported src type: ${n}`)}const r=t.querySelector('script[type="module"]');if(r)return await n(r,o.tagName.toLowerCase());$(`DCC: No state source found for "${o.tagName.toLowerCase()}".`)}catch(t){$(`DCC: Failed to load state: ${t}`)}}(s,o);Pt(o,r,a),t.markTreeless(),t.markInitialized(),t.clearConnectedRootNode(),t.settleInitialization()}catch(e){t.failInitializeLoudly(e)}}const Ct={order:10,connecting(t){const e=t.parentNode;return e instanceof ShadowRoot&&e.host.hasAttribute(i)?jt(t,e.host,e):null}};let It=!1;const At=new WeakMap;function xt(t,e,n){let o=At.get(t);void 0===o&&(o=new Map,At.set(t,o));const r=o.get(e);null!=r&&$(`Volume slot "${e}" is already mounted on this tree.`),o.set(e,n)}function Nt(t,e){if(null===t)return!1;const n=At.get(t);if(void 0===n||0===n.size)return!1;for(const t of n.keys())if(e===t||e.startsWith(t+c)||t.startsWith(e+c))return!0;return!1}const Rt=new WeakMap;const Mt=[];function Ot(t,e,n,o){if(e.length>0){const r=n.split(c),s=H(e,r);if(null!==s)return o&&s.readonly&&$(`[wcs/mount-readonly] volume "${t}" cannot write "${n}": it is injected read-only ("${l}.${s.innerSegments.join(c)}#${u}: ${s.outerPathInfo.path}"). Write "${s.outerPathInfo.path}" on the root, or drop #${u} from the injection.`),K(s,r)}return t+c+n}function Et(t,e,n){for(const t of e){const e=t.outerPathInfo.path;if(n===e)return t.innerSegments.join(c);if(n.startsWith(e+c))return t.innerSegments.join(c)+n.slice(e.length)}return n===t?"":n.startsWith(t+c)?n.slice(t.length+1):null}function Dt(t,e,n=Mt){return new Proxy({},{get(o,r){if("string"==typeof r&&"then"!==r){if("$"===r[0]){if("$postUpdate"===r||"$getAll"===r){const o=r;return(r,...s)=>e[o](Ot(t,n,r,!1),...s)}return"$setAll"===r?(o,...r)=>e.$setAll(Ot(t,n,o,!0),...r):"$resolve"===r?(o,...r)=>e.$resolve(Ot(t,n,o,r.length>1),...r):e[r]}return e[Ot(t,n,r,!1)]}},set:(o,r,s)=>("string"!=typeof r||(e[Ot(t,n,r,!0)]=s),!0),has:(t,e)=>"string"==typeof e&&"$"!==e[0]&&"#"!==e[0]})}const Wt=new WeakMap,zt=[];const Lt=new WeakMap,Vt=new WeakSet;function Bt(t){console.error(`[@wcstack/state] volume "${t.mountPath}" was not grafted — the root state element on this root node failed to initialize (its own diagnostic is reported separately). The volume is not at fault: fix the root <wcs-state>.`),t.onGrafted(null)}let Ft=null;const _t=new WeakMap,qt=new Set;function Tt(t,e,n,o){let r=_t.get(t);if(void 0===r){if(!o)return null;r=new Map,_t.set(t,r)}let s=r.get(e);if(void 0===s){if(!o)return null;s=new Map,r.set(e,s)}let a=s.get(n);if(void 0===a){if(!o)return null;a={holders:new Set,byListIndex:new WeakMap,noIndex:null},s.set(n,a)}return a}function Ut(t,e){if(!t.component.isConnected)return!1;const n=I(t.component)?.listIndex??null;if(null===e)return null===n;let o=n;for(;null!==o;){if(o===e)return!0;o=o.parentListIndex}return!1}function Ht(t,e,n,o){const r=Tt(t,e,n,!1);if(null===r)return null;const s=null===o?r.noIndex:r.byListIndex.get(o)??null;if(null!==s){const t=function(t,e){const n=t.ref.deref();return void 0!==n&&Ut(n,e)?n:null}(s,o);if(null!==t)return{record:t,entry:s.entry}}let a=null,i=null;for(const t of r.holders){const s=t.ref.deref();void 0!==s?Ut(s,o)&&(null!==i&&$(`[wcs/mount-export-ambiguous] "${e}${c}${n}" is exported by two mounted components on the same instance: <${i.component.tagName.toLowerCase()}> and <${s.component.tagName.toLowerCase()}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),a=t,i=s):r.holders.delete(t)}return null===a||null===i?null:(null===o?r.noIndex=a:r.byListIndex.set(o,a),{record:i,entry:a.entry})}function Kt(t){const e=t.parentStateElement,n=I(t.component);if(!(!1===e.isConnected||t.delta>0&&null===n))for(const o of t.exports.values())e.createState("readonly",t=>{t[A](n,()=>{t.$postUpdate(o.exportedPath)})})}const Gt=new WeakMap;class Xt{record;markerParentPath;listIndex;isBase;receiver;handler;constructor(t,e,n,o,r,s){this.record=t,this.markerParentPath=e,this.listIndex=n,this.isBase=o,this.receiver=r,this.handler=s}accessorNameFor(t){return this.record.accessorBySuffixByMarkerParent.get(this.markerParentPath)?.get(t)?.accessorName}accessorAddress(t){return x(d(this.markerParentPath+c+t),this.listIndex)}get(t,e,n){if("string"!=typeof e)return Reflect.get(t,e);if("then"===e)return;if("$"===e[0]){if("$postUpdate"===e)return t=>{this.receiver.$postUpdate(G(this.record,t))};if("$getAll"===e||"$setAll"===e||"$resolve"===e){const t=this.record,n=this.listIndex?.indexes??[],o=this.receiver;if("$resolve"===e)return(e,r,...s)=>{const a=s.length>0?X(t,e):G(t,e),i=J(t,e,a,r??[],n);return o.$resolve(a,i,...s)};const r=e;return(e,s,...a)=>{const i="$setAll"===r?X(t,e):G(t,e),c=J(t,e,i,s,n);return o[r](i,c,...a)}}return this.receiver[e]}const o=this.accessorNameFor(e);if(void 0!==o){this.handler.pushAddress(this.accessorAddress(e));try{return Reflect.get(this.record.stateObject,o,n)}finally{this.handler.popAddress()}}if(this.isBase){if(Object.prototype.hasOwnProperty.call(t,e))return dt(this.handler,this.accessorAddress(e)),t[e];const o=this.record.stateObject[e];if("function"==typeof o)return o.bind(n)}return this.receiver[G(this.record,e)]}set(t,e,n,o){if("string"!=typeof e)return Reflect.set(t,e,n);const r=this.accessorNameFor(e);if(void 0!==r){this.record.setterKeys.has(r)||$(`Cannot write to "${r}" on mounted <${this.record.component.tagName.toLowerCase()}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),this.handler.pushAddress(this.accessorAddress(e)),this.handler.beginUntrack();try{return Reflect.set(this.record.stateObject,r,n,o)}finally{this.handler.endUntrack(),this.handler.popAddress()}}return this.isBase&&Object.prototype.hasOwnProperty.call(t,e)?(t[e]=n,!0):(this.receiver[X(this.record,e)]=n,!0)}has(t,e){if("string"!=typeof e)return Reflect.has(t,e);if("$"===e[0]||"#"===e[0])return!1;if(void 0!==this.accessorNameFor(e))return!0;if(this.isBase){if(Object.prototype.hasOwnProperty.call(t,e))return!0;if("function"==typeof this.record.stateObject[e])return!0}try{return G(this.record,e),!0}catch{return!1}}}function Jt(t,e,n,o){const r=e.pathInfo.path,s=r===t.markerBasePath,a=s?function(t,e){let n=Gt.get(t);if(void 0===n&&(n={byListIndex:new WeakMap,noIndex:null},Gt.set(t,n)),null===e)return n.noIndex??={...t.privateSnapshot};let o=n.byListIndex.get(e);return void 0===o&&(o={...t.privateSnapshot},n.byListIndex.set(e,o)),o}(t,e.listIndex):{};return new Proxy(a,new Xt(t,r,e.listIndex,s,n,o))}function Qt(t){const e=t.parentStateElement,n=(e,n)=>{const o=I(t.component);let r;return e[A](o,()=>{r=n()}),r};return new Proxy({},{get(o,r){if("string"!=typeof r||"then"===r)return;if("$getAll"===r||"$setAll"===r||"$resolve"===r||"$postUpdate"===r)return function(t,e,n){const o=t.parentStateElement,r=(t,e)=>{let r;return o.createState(t,t=>{r=n(t,()=>e(t))}),r};return"$postUpdate"===e?e=>r("readonly",n=>n.$postUpdate(G(t,e))):(n,o,...s)=>{const a="$setAll"===e||"$resolve"===e&&s.length>0,i=a?X(t,n):G(t,n),c=I(t.component)?.listIndex.indexes??[],l=J(t,n,i,"$resolve"===e?o??[]:o,c);return r(a?"writable":"readonly",t=>t[e](i,l,...s))}}(t,r,n);let s;return e.createState("readonly",e=>{s=n(e,()=>e["$"===r[0]?r:G(t,r)])}),s},set:(o,r,s)=>("string"!=typeof r||e.createState("writable",e=>{n(e,()=>{e["$"===r[0]?r:X(t,r)]=s})}),!0),has(e,n){if("string"!=typeof n||"$"===n[0]||"#"===n[0])return!1;if(Object.prototype.hasOwnProperty.call(t.stateObject,n))return!0;try{return G(t,n),!0}catch{return!1}}})}function Yt(t,e){const n=tt(e);null!==n&&n.stateProp!==t.stateProp&&$(`A mount scope is already initialized on this component for "${n.stateProp}" — one <wcs-state bind-component> per component (v2). Merge the "${t.stateProp}" wiring into "${n.stateProp}" or split the component.`),null!==n&&N(e).dispose(),et(e,t),e instanceof ShadowRoot&&O(e,t.parentStateElement),function(t,e){const n=(e,n)=>nt(t,e,n);D(e);const o=I(t.component),r=e instanceof ShadowRoot?e:e.getRootNode();W(r,e,void 0,n),z(e,o,n)}(t,e),function(t){if(t.exports.size>0||null===t.rootEntry)return;const e=new Set([...t.getterKeys,...t.setterKeys]);for(const n of e){let e;try{e=G(t,n)}catch{continue}const o=e.indexOf(c+t.marker);if(-1===o)continue;const r=e.slice(0,o+1+t.marker.length),s=e.slice(r.length+1),a=e.slice(0,o)+c+s,i=d(a);if(i.wildcardCount!==t.delta)continue;const l={markerTerminalPath:r,suffix:s,markerPath:e,exportedPath:a};t.exports.set(a,l),Tt(t.parentStateElement,i.parentPath,i.lastSegment,!0).holders.add({ref:new WeakRef(t),entry:l}),t.parentStateElement.addDynamicDependency(e,a),ut?.markExported(t.parentStateElement,a)}t.parentStateElement.markHasMounts?.()}(t),function(t){const e=I(t.component);if(t.delta>0&&null===e)return;const n=t.component.tagName.toLowerCase();for(const o of t.exports.values()){const r=`${n}|${o.exportedPath}`;if(qt.has(r))continue;const s=d(o.exportedPath);let a;t.parentStateElement.createState("readonly",t=>{t[A](e,()=>{a=t[s.parentPath]})}),null!=a&&s.lastSegment in Object(a)&&(qt.add(r),console.warn(`[@wcstack/state] [wcs/mount-export-shadowed] <${n}>.${t.stateProp}.${o.suffix} is exported at "${o.exportedPath}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`))}}(t),Kt(t),E(e,Promise.resolve())}function Zt(t,e){const n=N(e),o=I(t.component);n.forEachActiveBindingNode(t=>R(t,o));const r=n.rebindAddresses();M(r),Kt(t)}function te(t,e){for(let n=e.firstNode;null!==n;n=n.nextSibling){if(n===t||n.contains(t))return!0;if(n===e.lastNode)break}return!1}const ee={read(t,e,n,o){if(!0===t.hasMounts&&35===e.pathInfo.lastSegment.charCodeAt(0)){const r=rt(t,e.pathInfo.path);if(null!==r)return Jt(r,e,n,o)}return S},readMissing(t,e,n,o,r){if(null===n){if(Nt(t.rootNode??null,e.pathInfo.path))return;return S}if(!0===t.hasMounts){const n=Ht(t,e.parentAddress.pathInfo.path,e.pathInfo.lastSegment,e.listIndex);if(null!==n)return function(t,e,n,o,r){const s=Jt(t,x(d(e.markerTerminalPath),n),o,r);return Reflect.get(s,e.suffix)}(n.record,n.entry,e.listIndex,o,r)}return S},write(t,e){if(!0===t.hasGraftedVolumes){const n=e.pathInfo.path,o=function(t,e){const n=Rt.get(t);if(void 0===n||0===n.size)return null;const o=e+c;for(const t of n)if(t.startsWith(o))return t;return null}(t,n);null!==o&&$(`Cannot replace "${n}" wholesale: a volume is mounted at "${o}" under it (D22). Replacing an ancestor of a mount point silently discards the grafted data while its accessors remain. Write "${o}" itself, or individual fields inside "${n}", instead.`)}return S},writeMissing(t,e,n,o,r,s,a){if(!0===t.hasMounts){const n=Ht(t,e.parentAddress.pathInfo.path,e.pathInfo.lastSegment,e.listIndex);if(null!==n)return function(t,e,n,o,r,s){const a=Jt(t,x(d(e.markerTerminalPath),n),r,s);return Reflect.set(a,e.suffix,o)}(n.record,n.entry,e.listIndex,r,s,a)}return S},indexShift(t,e){const n=t.stateElement,o=e.pathInfo.path;if(!0===n.hasMounts&&-1!==o.indexOf("#")){const t=rt(n,o);if(null!==t)return st(t,o)}return 0},handlerScope(t,e,n,o,r){if(!0!==t.hasMounts)return r;const s=ot(e,n);if(null===s)return r;const a=s.indexShiftByLoopElementPath.get(o.pathInfo.path);return void 0!==a?r-a:0},updated(t,e,n){const o=function(t){return Wt.get(t)??zt}(t);for(const r of o){const o=new Set,s={};for(const n of e){if(n.absolutePathInfo.stateElement!==t)continue;const e=n.absolutePathInfo.pathInfo.path;if(-1!==e.indexOf("#"))continue;const a=Et(r.mountPath,r.injections,e);if(null===a||""===a)continue;o.add(a);const i=n.absolutePathInfo.pathInfo.wildcardCount;if(i>0&&null!==n.listIndex){const t=L(n.listIndex,i);(s[a]??=[]).push(t)}}if(o.size>0)try{r.callback.call(Dt(r.mountPath,n,r.injections),Array.from(o),s)}catch(t){console.error(`[@wcstack/state] volume "${r.mountPath}" $updatedCallback threw.`,t)}}},suppressPathDiagnostic:(t,e)=>Nt(!1===t.isConnected?null:t.rootNode??null,e),rowReused(t,e){!function(t,e){if(Q(e))for(const n of Y(e)){if(!te(n.component,t))continue;const e=Z(n);null!==e&&Zt(n,e)}}(e,t)}};let ne=!1;const oe=new WeakMap;function re(t){let e=oe.get(t);return void 0===e&&(e={graftInfo:null,initializing:!1,mountPath:null,slotRootNode:null,detachedFrom:null},oe.set(t,e)),e}function se(t,e){null!==e.slotRootNode&&(!function(t,e,n){const o=At.get(t);o?.get(e)===n&&o.set(e,null)}(e.slotRootNode,e.mountPath,t),e.slotRootNode=null)}function ae(t,e,n){if(e.slotRootNode===n)return!0;const o=e.mountPath;try{xt(n,o,t)}catch{return console.error(`[@wcstack/state] <${P.tagNames.state} mount="${o}"> will not graft: another volume already holds the "${o}" slot on this root. Keep one volume per mount path.`),!1}return V(n)?.markHasVolume?.(),e.slotRootNode=n,!0}async function ie(t,e){const n=t,o=t.connectedRootNode,r=n.getAttribute("mount");let s;try{!function(t){0===t.length&&$('"mount" requires a non-empty tree path.');const e=d(t);for(const n of e.segments)0===n.length&&$(`"mount" path "${t}" has an empty segment.`),n===h&&$(`"mount" path "${t}" must be static (wildcards are not allowed).`),(n.includes("$")||n.includes("#")||n.includes("@"))&&$(`"mount" path "${t}" must not use reserved characters ($, #, @).`)}(r),s=function(t,e){const n=[],o=new Set;for(const r of T(t)){if(r.propSegments[0]!==l)continue;const t=r.propSegments.slice(1),s=r.statePathInfo,a=t=>$(`[wcs/mount-path-invalid] <${P.tagNames.state} mount="${e}"> "${r.propName}: ${r.statePathName}": ${t}`);1===t.length&&t[0]&&t[0]!==h&&"$"!==t[0][0]&&"#"!==t[0][0]||a(`inject one key at a time ("${l}.<key>: path"); change "mount" to move the whole volume.`),(s.wildcardCount>0||"$"===s.path[0]||"#"===s.path[0])&&a("the injected path must be a static path on the root tree (a volume has no loop context)."),(r.inFilters.length>0||r.outFilters.length>0)&&a("an injection takes no filters."),r.propModifiers.some(t=>t!==u)&&a(`an injection accepts only #${u}.`),o.has(t[0])&&a(`"${t[0]}" is injected twice.`),o.add(t[0]),n.push({innerSegments:t,outerPathInfo:s,readonly:r.propModifiers.includes(u)})}return n}(n.getAttribute(P.bindAttributeName)??"",r),n.hasAttribute("bind-component")&&$('"mount" cannot be combined with "bind-component".'),n.hasAttribute("enable-ssr")&&console.warn(`[@wcstack/state] <${P.tagNames.state} mount="${r}"> ignores "enable-ssr" — snapshots are per root tree (the root state element aggregates volume data).`),xt(o,r,t),V(o)?.markHasVolume?.(),e.mountPath=r,e.slotRootNode=o}catch(e){throw t.settleInitialization(),e}e.initializing=!0,null===V(o)&&function(t,e){const n=()=>{if(null!==V(t))return;const n=t.querySelectorAll(P.tagNames.state);for(const t of n)if(!t.hasAttribute("mount")&&!t.hasAttribute("bind-component"))return;console.error(`[@wcstack/state] <${P.tagNames.state} mount="${e}"> has no root state tree to graft onto (D11). A volume mounts onto the root tree — add a root <${P.tagNames.state}> to this root node (an empty <${P.tagNames.state}></${P.tagNames.state}> is enough). If the root is added dynamically later, the graft will still complete and this report can be ignored.`)},o=t.ownerDocument??t;"loading"===o.readyState?o.addEventListener("DOMContentLoaded",()=>queueMicrotask(n),{once:!0}):setTimeout(n,0)}(o,r);const a=n=>{e.graftInfo=n,t.markInitialized(),null===n&&se(t,e),t.settleInitialization()};let i;try{i=await t.loadStateFromSource()}catch(t){return console.error(`[@wcstack/state] volume "${r}" failed to load.`,t),void a(null)}const c=t.connectedRootNode??null;null!==c&&ae(t,e,c)?function(t,e,n,o,r,s,a=[]){const i={mountPath:n,volumeState:o,injections:a,onGrafted:r,acquireSlot:s};if(null!==e)return void Ee(e,i);We(),function(t,e){if(Vt.has(t))return void Bt(e);let n=Lt.get(t);void 0===n&&(n=[],Lt.set(t,n)),n.push(e)}(t,i)}(c,V(c),r,i,a,()=>ae(t,e,c),s):a(null)}const ce={order:20,connecting(t){if(!t.hasAttribute("mount"))return null;const e=re(t);if(e.initializing){const n=t.connectedRootNode;if(null!=n&&e.detachedFrom===n)try{xt(n,e.mountPath,t),V(n)?.markHasVolume?.(),e.slotRootNode=n}catch{}return e.detachedFrom=null,o}return ie(t,e)},reconnecting(t){if(!t.hasAttribute("mount"))return!1;const e=re(t),n=t.connectedRootNode??null;return null!==e.graftInfo&&null!==n&&V(n)===e.graftInfo.rootStateElement&&Re(e.graftInfo,"$connectedCallback"),!0},replacingState(t){if(!0!==oe.get(t)?.initializing)return;const e=t.getAttribute("mount");$(`Cannot replace the state of <${P.tagNames.state} mount="${e}"> after it has loaded: a volume's data is copied into the root tree when it grafts, so a new state would never reach the page. Write the paths under "${e}" on the root state instead.`)},initializeFailed(t,e){!function(t){Vt.add(t);const e=Lt.get(t);if(void 0!==e){Lt.delete(t);for(const t of e)Bt(t)}}(e)},initializeFailureCleared(t,e){!function(t){Vt.delete(t)}(e)},disconnecting(t){if(!t.hasAttribute("mount"))return!1;const e=re(t);return null!==e.graftInfo&&Re(e.graftInfo,"$disconnectedCallback"),!0!==t.initialized&&(e.detachedFrom=e.slotRootNode,se(t,e)),t.clearConnectedRootNode(),!0}};let le=!1;const ue=new WeakMap;function de(t,e){let n=ue.get(t);n||(n=new Set,ue.set(t,n)),n.add(e)}const fe=new WeakMap;const he=new WeakMap,me=new WeakMap;const pe=new WeakMap;const ge={isComplete:function(t,e){return!0===ue.get(t)?.has(e)},isDeclared:function(t,e){return!0===fe.get(t)?.has(e)},rememberOverwrittenObject:function(t,e,n){let o=he.get(t);o||(o=new Map,he.set(t,o)),o.has(e)||o.set(e,n)},recordInjectedKey:function(t,e,n){let o=me.get(t);o||(o=new Map,me.set(t,o));let r=o.get(e);r||(r=new Set,o.set(e,r)),r.add(n)},rememberOverwrittenValue:function(t,e,n,o){let r=pe.get(t);r||(r=new Map,pe.set(t,r));let s=r.get(e);s||(s=new Map,r.set(e,s)),s.has(n)||s.set(n,o)}};function ye(t){return function(t){const e=Object.getPrototypeOf(t),n=Object.create(e),o=Object.getOwnPropertyDescriptors(t);for(const t in o){const e=o[t];!1===e.writable&&(e.writable=!0)}return Object.defineProperties(n,o),n}(t)}const be=new WeakMap;class $e{_innerStateElement;constructor(t,e){this._innerStateElement=function(t,e){const n=be.get(t);return n?n.get(e)??null:null}(t,e)??$("State element not found for web component.")}get(t,e,n){if("string"==typeof e){let t;return this._innerStateElement.createState("readonly",n=>{t=n[e]}),t}return Reflect.get(t,e,n)}set(t,e,n,o){return"string"==typeof e?(this._innerStateElement.createState("writable",t=>{t[e]=n}),!0):Reflect.set(t,e,n,o)}}const we=t=>()=>t;function ve(t,e,n,o){!function(t,e,n){let o=be.get(t);o||(o=new Map,be.set(t,o)),o.set(e,n)}(e,n,t),t.setInitialState(ye(o));const r=function(t,e){const n=new $e(t,e);return new Proxy({},n)}(e,n);Object.defineProperty(e,n,{get:we(r),enumerable:!0,configurable:!0}),de(e,n),ke(e,n)}function ke(t,e){if(f in t){const n=t[f];"function"==typeof n?n.call(t,e).catch(t=>{$(`Error in ${f}: ${t instanceof Error?t.message:String(t)}`)}):$(`${f} is not a function.`)}}const Se=new Set;function Pe(t,e){Se.has(t)||(Se.add(t),console.warn(`[@wcstack/state] [wcs/mount-own-key-shadow] ${e} See docs/state-mount-design.md §4-3.`))}function je(t){const e=t.rootEntry,n=I(t.component);if(e.outerPathInfo.wildcardCount>0&&null===n)return;let o;return t.parentStateElement.createState("readonly",t=>{t[A](n,()=>{o=t[e.outerPathInfo.path]})}),o}const Ce=new WeakMap;function Ie(t,e){t.landInitialization(),$(e)}async function Ae(t,e){const n=t;if(n.hasAttribute("bind-component")){const o=n.parentNode,r=o instanceof ShadowRoot?o.host:o instanceof Element?o:null,s=r?_(r):null;null!==r&&null!==s||$(`"bind-component" requires <${P.tagNames.state}> to be a direct child of a custom element.`),o instanceof ShadowRoot||r.hasAttribute(P.bindAttributeName)||Ie(t,`A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${s}>, or mount it from the host (data-wcs="${n.getAttribute("bind-component")}: path").`);const a=["state","src","json"].filter(t=>n.hasAttribute(t));null!==n.querySelector('script[type="module"]')&&a.push('<script type="module">'),a.length>0&&$(`"bind-component" cannot be combined with ${a.join(", ")}. The component's "${n.getAttribute("bind-component")}" property is the only state source.`);const i=n.getAttribute("bind-component");!function(t,e){let n=fe.get(t);n||(n=new Set,fe.set(t,n)),n.add(e)}(r,i);const c=j(r);null===c&&$(`CustomElementRegistry is unavailable for <${s}>.`),await c.whenDefined(s.toLowerCase()),r.hasAttribute(P.bindAttributeName)&&await q(r),i in r||$(`Component does not have property "${i}" for state binding.`);let l=r[i];"object"==typeof l&&null!==l||$(`Component property "${i}" is not an object for state binding.`);const u=function(t,e){const n=he.get(t);if(!n)return;const o=n.get(e);return n.delete(e),o}(r,i);if(void 0!==u&&function(t,e){if(!t.hasAttribute(P.bindAttributeName))return!1;const n=B(t);if(null===n)return!1;for(const t of n)if(1===t.propSegments.length&&t.propSegments[0]===e)return!0;return!1}(r,i)&&(r[i]=u,l=u),e.boundComponent=r,e.boundComponentStateProp=i,t.setBoundComponent(r,i),o instanceof ShadowRoot||(B(r)??[]).some(t=>t.propSegments[0]===i)||Ie(t,`A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${s}>, or mount it from the host (data-wcs="${i}: path").`),r.hasAttribute(P.bindAttributeName)){const a=(B(r)??[]).filter(t=>t.propSegments[0]===i);if(a.length>0){const c=V(r.getRootNode())??Ie(t,`No state tree found on this root for mount host <${s}>.`);let u=it(r,i);const d=null!==u;if(null===u&&(function(t,e,n){const o=pe.get(t)?.get(e);if(void 0!==o){for(const[t,e]of o)n[t]=e;pe.get(t).delete(e)}}(r,i,l),u=ct(r,i,a,c,l,function(t,e){return me.get(t)?.get(e)}(r,i)),function(t){const e=Object.keys(t.privateSnapshot);if(0===e.length)return;const n=t.component.tagName.toLowerCase(),o=t.stateProp;let r,s=!1;for(const a of e){if(null===t.rootEntry)continue;if(s||(r=je(t),s=!0),"object"!=typeof r||null===r||!(a in r))continue;const e=t.rootEntry.outerPathInfo.path;Pe(`${n}|${o}|${a}|root`,`<${n}>.${o}.${a} is private and hides the mounted tree key "${e}.${a}" (${o}: ${e}). Remove the default to read the tree, or rename it to keep it private.`)}}(u)),e.mountRecord=u,n.parentNode!==o)return;try{Yt(u,o instanceof ShadowRoot?o:r)}catch(e){throw t.landInitialization(),e}if(!d){const t=Qt(u);Object.defineProperty(r,i,{get:()=>t,enumerable:!0,configurable:!0}),de(r,i)}return ke(r,i),lt(u),void at(u,"$connectedCallback")}}ve(t,e.boundComponent,e.boundComponentStateProp,l)}}const xe={order:30,preparing(t){if(!t.hasAttribute("bind-component"))return null;const e=function(t){let e=Ce.get(t);return void 0===e&&(e={boundComponent:null,boundComponentStateProp:null,mountRecord:null},Ce.set(t,e)),e}(t);return Ae(t,e).then(()=>null!==e.mountRecord&&(t.markInitialized(),t.settleInitialization(),!0))},reconnecting(t){const e=Ce.get(t);if(void 0===e||null===e.mountRecord)return!1;const n=e.mountRecord,o=t.parentNode;return queueMicrotask(()=>{null!=t.connectedRootNode&&Zt(n,o)}),at(n,"$connectedCallback"),!0},disconnecting(t){const e=Ce.get(t);return void 0!==e&&null!==e.mountRecord&&(at(e.mountRecord,"$disconnectedCallback"),Kt(e.mountRecord),t.clearConnectedRootNode(),!0)}};let Ne=!1;function Re(t,e){const n=t.volumeState[e];"function"==typeof n&&t.rootStateElement.createState("writable",o=>{const r=n.call(Dt(t.mountPath,o,t.injections));r instanceof Promise&&r.catch(n=>{console.error(`[@wcstack/state] volume "${t.mountPath}" ${e} failed.`,n)})})}function Me(t,e,n,o){const r=n[m];if(void 0!==r){const n=[],s=new Set;let a=0;for(const[i,c]of Object.entries(r)){const r=Ot(e,o,i,!1),l=function(t,n,...r){c.call(Dt(e,this,o),t,n,...r)};n.push({path:r,pathInfo:d(r),handler:l,order:1e6+a++}),s.add(r),t.setPathInfo(r,"prop","watch")}n.length>0&&(ht(t,n),t.addVolumeWatchPaths?.(s),mt(t))}const s=n[p];if(void 0!==s){const n=new Map;for(const[t,r]of Object.entries(s))n.set(Ot(e,o,t,!1),r);t.mergeVolumeListKeys?.(n)}const a=n[b];"function"==typeof a&&(!function(t,e){let n=Wt.get(t);void 0===n&&(n=[],Wt.set(t,n)),n.push(e),t.markHasVolume?.()}(t,{mountPath:e,injections:o,callback:a}),t.enableUpdatedCallback?.());for(const t of["$commandTokens","$eventTokens","$on","$errorCallback"])void 0!==n[t]&&console.warn(`[@wcstack/state] volume "${e}" declares ${t}, which volumes do not support. Declare it on the root state instead.`)}function Oe(t,e,n,o=[]){!function(t,e,n,o){for(const t of o){const o=t.innerSegments[0],r=Object.getOwnPropertyDescriptor(n,o);void 0===r||"function"!=typeof r.get&&"function"!=typeof r.set&&"function"!=typeof r.value||$(`Volume "${e}" declares "${o}" as an accessor or a method and also injects it ("${l}.${o}: ${t.outerPathInfo.path}"). Rename one of them.`)}const r=n[m];if(void 0!==r){"object"==typeof r&&null!==r||$(`${m} must be an object mapping state paths to handler functions.`);for(const[t,e]of Object.entries(r))"function"!=typeof e&&$(`${m} entry "${t}" must be a function.`),ft(t)}const s=n[p];if(void 0!==s){"object"==typeof s&&null!==s||$(`${p} must be an object mapping list paths to key specs.`);for(const[n,r]of Object.entries(s)){(0===n.length||"string"!=typeof r&&"function"!=typeof r)&&$(`${p} entry "${n}" must map a list path to a field name or a key function.`);const s=Ot(e,o,n,!1);t.listKeys?.has(s)&&$(`${p} entry "${s}" is declared by both the root and a volume (or two volumes). Keep exactly one.`)}}void 0!==n.$streams&&$(`Volume "${e}" declares $streams, which volumes do not support yet. Declare the stream on the root state.`),void 0!==n.$scan&&$(`Volume "${e}" declares $scan, which volumes do not support yet. Declare the scan on the root state.`),void 0!==n[g]&&$(`Volume "${e}" declares ${g}, which volumes do not support yet. Declare the recursion anchor on the root state — the anchor path is resolved against the root tree.`);for(const t of Object.keys(k(n)))-1!==t.indexOf(y)&&$(`Volume "${e}" declares "${t}", which uses "${y}". Volumes do not support recursive getters yet — declare them on the root state.`)}(t,e,n,o);const{data:r,accessors:s}=function(t,e){const n={},o=new Map;for(const[r,s]of Object.entries(Object.getOwnPropertyDescriptors(t)))r.startsWith("$")||e.has(r)||("function"!=typeof s.get&&"function"!=typeof s.set?"function"!=typeof s.value&&(n[r]=s.value):o.set(r,s));return{data:n,accessors:o}}(n,new Set(o.map(t=>t.innerSegments[0]))),a=d(e),i=!0===t.hydratedFromSsr;t.createState("writable",t=>{if(1===a.segments.length&&e in t){if(i)return;$(`Volume mount "${e}" collides with an existing key on the root tree. Remove the root key or mount the volume elsewhere.`)}let n="";for(let e=0;e<a.segments.length-1;e++){const o=a.segments[e],r=""===n?o in t:void 0!==t[n+c+o];n=""===n?o:n+c+o,r||(t[n]={})}if(a.segments.length>1&&void 0!==t[e]){if(i)return;$(`Volume mount "${e}" collides with an existing key on the root tree. Remove the root key or mount the volume elsewhere.`)}t[e]=r}),function(t,e){let n=Rt.get(t);void 0===n&&(n=new Set,Rt.set(t,n)),n.add(e)}(t,e),t.markHasGraftedVolumes?.();for(const[n,r]of s){const s=e+c+n,a=r.get,i=r.set,l={enumerable:!1,configurable:!0};"function"==typeof a&&(l.get=function(){return a.call(Dt(e,this,o))}),"function"==typeof i&&(l.set=function(t){i.call(Dt(e,this,o),t)}),t.defineTreeAccessor(s,l)}Me(t,e,n,o);const u=n.$connectedCallback;return"function"==typeof u&&t.createState("writable",t=>{let n;try{n=u.call(Dt(e,t,o))}catch(t){return void console.error(`[@wcstack/state] volume "${e}" $connectedCallback failed.`,t)}n instanceof Promise&&n.catch(t=>{console.error(`[@wcstack/state] volume "${e}" $connectedCallback failed.`,t)})}),{rootStateElement:t,mountPath:e,volumeState:n,injections:o}}function Ee(t,e){if(!e.acquireSlot())return void e.onGrafted(null);let n=null;try{n=Oe(t,e.mountPath,e.volumeState,e.injections)}catch(t){console.error(`[@wcstack/state] volume "${e.mountPath}" failed to graft.`,t)}finally{e.onGrafted(n)}}let De=!1;function We(){De||(De=!0,ne||(ne=!0,v("scopes",ee)),le||(le=!0,t("scopes",ce)),Ne||(Ne=!0,t("bindComponent",xe),F(ge)),Ft=Ee,U(ze))}function ze(t,e){(function(t){const e=At.get(t);return void 0!==e&&e.size>0})(t)&&e.markHasVolume?.(),function(t,e){Vt.delete(t);const n=Lt.get(t);if(void 0===n||0===n.length||null===Ft)return;Lt.delete(t);const o=Ft;queueMicrotask(()=>{for(const t of n)o(e,t)})}(t,e)}const Le={name:"scopes",install(){We(),It||(It=!0,t("dcc",Ct))}};export{Le as default,Le as scopes};
|
|
1
|
+
import{r as t,l as e,a as n,C as o}from"../chunks/lifecycleHooks.js";import{k as r,l as s,a,m as i,D as c,V as l,n as u,g as d,W as f,o as h,R as m,p,h as g,q as y,r as $}from"../chunks/pathDiagnostics.js";import{r as w,d as b}from"../chunks/errorGuidance.js";import{r as v,g as k,N as S}from"../chunks/getAllPropertyDescriptors.js";import{c as P}from"../chunks/filterRegistry.js";import{n as j}from"../chunks/declarationAliases.js";import{q as C,u as x,t as I,v as N,w as M,j as A,x as O,y as R,z as E,A as K,B as W,C as D,D as L,E as B,o as z,F as V,G as F,H as q,I as T,J as _,K as G,L as H}from"../chunks/binder.js";import{a as U,r as X}from"../chunks/featureBridge.js";import{p as J}from"../chunks/diagnosticsHooks.js";import{c as Q}from"../chunks/checkDependency.js";const Y={written:function(t,e,n){const o=t.bindableEventMap,r=o[e.path],s="string"==typeof r,a=s?r:e.segments.length>1?o[e.segments[0]]:void 0;if("string"!=typeof a)return;const i=t.rootNode;i instanceof ShadowRoot&&i.host.dispatchEvent(new CustomEvent(a,{detail:s&&void 0!==n?n.value:void 0,bubbles:!0}))}};let Z=!1;function tt(t){return function(){const e=this.stateElement;if(!e)return;if(!0!==e.initialized)return;let n;try{e.createState("readonly",e=>{n=e[t]})}catch(e){return void console.warn(`[@wcstack/state] DCC getter "${t}" failed:`,e)}return n}}function et(t){return function(e){const n=this.stateElement;n&&(!0!==n.initialized?n.initializePromise.then(()=>{n.createState("writable",n=>{n[t]=e})}):n.createState("writable",n=>{n[t]=e}))}}function nt(t,e){return e?function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createStateAsync("writable",async n=>{o=await n[t](...e)}).then(()=>o)})}:function(...e){const n=this.stateElement;if(n)return n.initializePromise.then(()=>{let o;return n.createState("writable",n=>{o=n[t](...e)}),o})}}function ot(t){return t.startsWith("$")}function rt(t,e){return Object.keys(t).filter(n=>{if(n.startsWith("$")||"constructor"===n)return!1;const o="function"==typeof t[n].value;return"method"===e?o:!o})}function st(t,e){const n=t[e];if(void 0===n)return null;Array.isArray(n)||w(`${e} must be an array of strings.`);const o=[],r=new Set;for(const t of n)"string"==typeof t&&0!==t.length||w(`${e} entries must be non-empty strings.`),t.startsWith("$")&&w(`${e} entry "${t}" must not start with "$" (internal properties are not exposed on the component).`),r.has(t)&&w(`${e} entry "${t}" is duplicated.`),r.add(t),o.push(t);return o}function at(t){j(t);const e=st(t,r)??[],n=st(t,s)??[],o=k(t),i=function(t){const e=t[a];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),c=[];for(const t of e){const e=o[t];if(void 0===e){if(i.has(t)){c.push(t);continue}w(`${r} entry "${t}" is not declared on the state.${b(t,rt(o,"value"))}`)}"function"==typeof e.value&&w(`${r} entry "${t}" is a method. Declare it in ${s} instead.`)}for(const t of n){const e=o[t];void 0===e&&w(`${s} entry "${t}" is not declared on the state.${b(t,rt(o,"method"))}`),"function"!=typeof e.value&&w(`${s} entry "${t}" is not a method. Declare it in ${r} instead.`)}return{bindables:e,commands:n,streamBackedBindables:c}}function it(t,e,n){const o=t.tagName.toLowerCase();o.includes("-")||w(`DCC: "${o}" is not a valid custom element name (must contain a hyphen).`);const s=C(t);null!==s&&"function"==typeof s.define||w(`DCC: CustomElementRegistry is unavailable for "${o}".`),s.get(o)&&w(`DCC: "${o}" is already registered. A custom element name can only be defined once.`);const a=document.createElement("template"),c=a.content.ownerDocument;for(const t of Array.from(e.childNodes))a.content.appendChild(c.importNode(t,!0));const l=e.mode,{bindables:u,commands:d,streamBackedBindables:f}=at(n),h=u.length>0||d.length>0?function(t,e,n=[]){const o={protocol:"wc-bindable",version:1,properties:e.map(e=>({name:e,event:`${t}:${e}-changed`,getter:t=>t.target[e]})),inputs:e.map(t=>({name:t}))};if(0===n.length)return o;const r=n.map(t=>({name:t,async:!0}));return{...o,commands:r}}(o,u,d):null,m=u.length>0?function(t,e){const n={};for(const o of e)n[o]=`${t}:${o}-changed`;return n}(o,u):{},p=P.tagNames.state,g=class extends HTMLElement{static template=a;static shadowRootMode=l;static wcBindable=h;static bindableEventMap=m;_shadow=null;_ensureShadow(){if(null!==this._shadow)return this._shadow;if(this.hasAttribute(i))return null;this._shadow=this.attachShadow({mode:g.shadowRootMode}),this._shadow.appendChild(g.template.content.cloneNode(!0));const t=C(this._shadow);return null!==t&&x(t,this._shadow),this._shadow}connectedCallback(){const t=this._ensureShadow();if(null!==t&&Object.keys(g.bindableEventMap).length>0){const e=t.querySelector(p);e?(Z||(Z=!0,v("dcc",Y)),e.setBindableEventMap(g.bindableEventMap)):console.warn(`[@wcstack/state] DCC: "${o}" declares ${r} but its template has no <${P.tagNames.state}>. Change events will not be dispatched.`)}}get stateElement(){return this._ensureShadow()?.querySelector(p)??null}},y=k(n);for(const[t,e]of Object.entries(y)){if(ot(t))continue;const n={configurable:!0,enumerable:!0};if("function"==typeof e.value){const o="AsyncFunction"===e.value.constructor?.name;n.value=nt(t,o)}else n.get=tt(t),n.set=et(t);Object.defineProperty(g.prototype,t,n)}for(const t of f)Object.defineProperty(g.prototype,t,{configurable:!0,enumerable:!0,get:tt(t),set:et(t)});s.define(o,g)}async function ct(t,o,r){const s=t;try{s.hasAttribute("bind-component")&&w(`"bind-component" cannot be used inside a [${i}] host. DCC state comes from the template, not from a component property.`);const a=await async function(t,o){try{if(t.hasAttribute("src")){const n=t.getAttribute("src");if(n.endsWith(".js"))return await e(n);w(`DCC: Unsupported src type: ${n}`)}const r=t.querySelector('script[type="module"]');if(r)return await n(r,o.tagName.toLowerCase());w(`DCC: No state source found for "${o.tagName.toLowerCase()}".`)}catch(t){w(`DCC: Failed to load state: ${t}`)}}(s,o);it(o,r,a),t.markTreeless(),t.markInitialized(),t.clearConnectedRootNode(),t.settleInitialization()}catch(e){t.failInitializeLoudly(e)}}const lt={order:10,connecting(t){const e=t.parentNode;return e instanceof ShadowRoot&&e.host.hasAttribute(i)?ct(t,e.host,e):null}};let ut=!1;function dt(t,e){if(e.length>t.length)return!1;for(let n=0;n<e.length;n++)if(t[n]!==e[n])return!1;return!0}function ft(t,e){for(const n of t)if(dt(e,n.innerSegments))return n;return null}function ht(t,e){const n=e.slice(t.innerSegments.length);return 0===n.length?t.outerPathInfo.path:t.outerPathInfo.path+c+n.join(c)}const mt=new Map([["$eq",[0]],["$eqPath",[0,1]],["$eqIndex",[0]],["$dependOn",[0]],["$trackDependency",[0]]]);function pt(t,e,n){const o=mt.get(t);return void 0===o?null:(...t)=>{const r=t.slice();for(let t=0;t<o.length;t++){const n=o[t];"string"==typeof r[n]&&(r[n]=e(r[n]))}return n(r)}}const gt=new WeakMap;function yt(t,e,n){let o=gt.get(t);void 0===o&&(o=new Map,gt.set(t,o));const r=o.get(e);null!=r&&w(`Volume slot "${e}" is already mounted on this tree.`),o.set(e,n)}function $t(t,e){if(null===t)return!1;const n=gt.get(t);if(void 0===n||0===n.size)return!1;for(const t of n.keys())if(e===t||e.startsWith(t+c)||t.startsWith(e+c))return!0;return!1}const wt=new WeakMap;const bt=[];function vt(t,e,n,o){if(e.length>0){const r=n.split(c),s=ft(e,r);if(null!==s)return o&&s.readonly&&w(`[wcs/mount-readonly] volume "${t}" cannot write "${n}": it is injected read-only ("${l}.${s.innerSegments.join(c)}#${u}: ${s.outerPathInfo.path}"). Write "${s.outerPathInfo.path}" on the root, or drop #${u} from the injection.`),ht(s,r)}return t+c+n}function kt(t,e,n){let o=-1,r=null;for(const t of e){const e=t.outerPathInfo.path;e.length<=o||(n===e?(o=e.length,r=t.innerSegments.join(c)):n.startsWith(e+c)&&(o=e.length,r=t.innerSegments.join(c)+n.slice(e.length)))}if(t.length>o){if(n===t)return"";if(n.startsWith(t+c))return n.slice(t.length+1)}return r}function St(t,e,n=bt){return new Proxy({},{get(o,r){if("string"==typeof r&&"then"!==r){if("$"===r[0]){if("$postUpdate"===r||"$getAll"===r){const o=r;return(r,...s)=>e[o](vt(t,n,r,!1),...s)}if("$setAll"===r)return(o,...r)=>e.$setAll(vt(t,n,o,!0),...r);if("$resolve"===r)return(o,...r)=>e.$resolve(vt(t,n,o,r.length>1),...r);const o=pt(r,e=>vt(t,n,e,!1),t=>e[r](...t));return null!==o?o:e[r]}return e[vt(t,n,r,!1)]}},set:(o,r,s)=>"string"!=typeof r||("$"===r[0]?(e[r]=s,!0):(e[vt(t,n,r,!0)]=s,!0)),has:(t,e)=>"string"==typeof e&&"$"!==e[0]&&"#"!==e[0]})}const Pt=new WeakMap,jt=[];const Ct=new WeakMap,xt=new WeakSet;function It(t){console.error(`[@wcstack/state] volume "${t.mountPath}" was not grafted — the root state element on this root node failed to initialize (its own diagnostic is reported separately). The volume is not at fault: fix the root <wcs-state>.`),t.onGrafted(null)}let Nt=null;let Mt=0;const At=["$watch",a,"$scan","$listKeys",h,"$commandTokens","$eventTokens","$on","$recursion","$errorCallback"],Ot=new Set;function Rt(t,e){const n=t.stateObject[e];if("function"==typeof n)try{const o=t.component[t.stateProp],r=n.call(o);r instanceof Promise&&r.catch(n=>{console.error(`[@wcstack/state] mounted <${t.component.tagName.toLowerCase()}> ${e} failed.`,n)})}catch(n){console.error(`[@wcstack/state] mounted <${t.component.tagName.toLowerCase()}> ${e} failed.`,n)}}function Et(t,e,n,o,r,s=new Set){0===n.length&&w(`Cannot build a mount record without host bindings for "${e}".`),j(r);const a=[],i=new Set;let l=null;for(const t of n){const e=t.propSegments.slice(1),n=e.join(c);i.has(n)&&w("Duplicate mapping rule for web component."),i.add(n);const o={innerSegments:e,outerPathInfo:t.statePathInfo,readonly:!0===t.propModifiers?.includes(u)};a.push(o),0===e.length&&(l=o)}a.sort((t,e)=>e.innerSegments.length-t.innerSegments.length);const d=++Mt,f=`#m${d}`,{getterKeys:h,setterKeys:m}=function(t){const e=new Set,n=new Set,o=k(t);for(const[t,r]of Object.entries(o))"function"==typeof r.get&&e.add(t),"function"==typeof r.set&&n.add(t);return{getterKeys:e,setterKeys:n}}(r),p=new Set;for(const t of a)1===t.innerSegments.length&&p.add(t.innerSegments[0]);const g={};for(const t of Object.keys(r))t.startsWith("$")||h.has(t)||m.has(t)||"function"!=typeof r[t]&&(s.has(t)||p.has(t)||(g[t]=r[t]));return{id:d,marker:f,component:t,stateProp:e,parentStateElement:o,entries:a,rootEntry:l,delta:null===l?0:l.outerPathInfo.wildcardCount,markerBasePath:null===l?f:l.outerPathInfo.path+c+f,stateObject:r,getterKeys:h,setterKeys:m,injectedKeys:s,mappedKeys:p,hasReadonlyEntries:a.some(t=>t.readonly),privateSnapshot:g,accessorBySuffixByMarkerParent:new Map,indexShiftByLoopElementPath:new Map,addedGetterPaths:new Set,exports:new Map}}function Kt(t){const e=t.indexOf(c);return-1===e?t:t.slice(0,e)}function Wt(t,e){const n=ft(t.entries,e);return null===n?null:ht(n,e)}function Dt(t,e){return t.markerBasePath+c+e}function Lt(t,e,n,o){let r=t.accessorBySuffixByMarkerParent.get(e);void 0===r&&(r=new Map,t.accessorBySuffixByMarkerParent.set(e,r));const s=e+c+n;r.set(n,{accessorName:o,indexShift:d(s).wildcardCount-d(o).wildcardCount}),t.getterKeys.has(o)&&(t.parentStateElement.getterPaths?.add(s),t.addedGetterPaths.add(s))}function Bt(t,e){return!t.injectedKeys.has(e)&&(!t.getterKeys.has(e)&&"function"==typeof t.stateObject[e]||!t.mappedKeys.has(e)&&(Object.prototype.hasOwnProperty.call(t.stateObject,e)&&!t.getterKeys.has(e)&&!t.setterKeys.has(e)))}function zt(t,e){return`Path "${e}" in <${t.component.tagName.toLowerCase()}> does not resolve: it is not an own key of the component state and no mount entry covers it (mounted prefixes: ${t.entries.filter(t=>t.innerSegments.length>0).map(t=>t.innerSegments.join(c)).join(", ")}). Mount it from the host ("${t.stateProp}: path" / "${t.stateProp}.${Kt(e)}: path") or declare the key on the component state.`}const Vt=/^\$(\d+)$/;function Ft(t,e){if(!t.hasReadonlyEntries)return null;const n=e[0];if("$"===n||"#"===n)return null;if(t.getterKeys.has(e)||t.setterKeys.has(e))return null;const o=Kt(e);if(t.getterKeys.has(o)||t.setterKeys.has(o)||Bt(t,o))return null;const r=function(t,e){return ft(t.entries,e)}(t,e.split(c));return null!==r&&r.readonly?r:null}function qt(t,e){const n=Ft(t,e);if(null!==n){const o=0===n.innerSegments.length?"":c+n.innerSegments.join(c);w(`[wcs/mount-readonly] <${t.component.tagName.toLowerCase()}> cannot write "${e}": it is mounted read-only ("${t.stateProp}${o}#${u}: ${n.outerPathInfo.path}"). Write it on the host, or drop #${u} from the mount.`)}return Tt(t,e)}function Tt(t,e){const n=e[0];if("$"===n||"#"===n)return e;if(t.getterKeys.has(e)||t.setterKeys.has(e))return function(t,e){const n=e.split(c);let o=-1;for(let t=n.length-1;t>=0;t--)if(n[t]===f){o=t;break}if(-1===o)return Lt(t,t.markerBasePath,e,e),Dt(t,e);if(Bt(t,n[0]))return Lt(t,t.markerBasePath,e,e),Dt(t,e);const r=n.slice(0,o+1),s=n.slice(o+1),a=Wt(t,r);null===a&&w(zt(t,e)),0===s.length&&w(`Wildcard-terminal accessor "${e}" on mounted <${t.component.tagName.toLowerCase()}> is not supported: it translates to a marker-terminal path where the mount overlay would shadow the accessor. Declare the row value as a getter on the host tree, or back it with a component-own array (a private key makes the whole path private).`);const i=a+c+t.marker;return Lt(t,i,s.join(c),e),i+c+s.join(c)}(t,e);const o=Kt(e);if(t.getterKeys.has(o)||t.setterKeys.has(o))return Dt(t,e);if(Bt(t,o))return Dt(t,e);const r=Wt(t,e.split(c));if(null!==r)return r;w(zt(t,e))}const _t=new Set(["prop","radio","checkbox"]);function Gt(t,e,n){let o;const r=Vt.exec(e.statePathName);if(null!==r){const s=function(t,e){if(void 0===e)return t.delta;const n=Tt(t,e);return d(n).wildcardCount-d(e).wildcardCount}(t,n);o=0===s?e.statePathName:`$${Number(r[1])+s}`}else if(o=Tt(t,e.statePathName),"for"===e.bindingType){const n=d(o).wildcardCount-e.statePathInfo.wildcardCount;t.indexShiftByLoopElementPath.set(o+c+f,n)}const s=e.propModifiers,a=null===r&&Array.isArray(s)&&_t.has(e.bindingType??"")&&!s.includes(u)&&null!==Ft(t,e.statePathName);return o!==e.statePathName||a?{...e,statePathName:o,statePathInfo:d(o),...a?{propModifiers:[...s,u]}:{}}:e}function Ht(t,e,n,o,r){if(void 0===o)return;const s=d(n).wildcardCount-d(e).wildcardCount;return 0===s?o:(r.length<s&&w(`Cannot resolve "${e}" from this mount: the mounted prefix has ${s} wildcard(s) but the host context provides only ${r.length} index(es).`),[...r.slice(0,s),...o])}const Ut=new WeakMap,Xt=new WeakMap;const Jt=new WeakMap;const Qt=new FinalizationRegistry(function(t){const e=t.byMarker.get(t.marker);if(void 0!==e&&void 0===e.deref()&&t.byMarker.delete(t.marker),void 0!==t.getterPaths)for(const e of t.addedGetterPaths)t.getterPaths.delete(e)}),Yt=new WeakMap;function Zt(t){return Yt.get(t)??null}let te=!1;function ee(t,e){te||(te=!0,I(t=>Ut.has(t)?t.host:null)),Ut.set(t,e),Yt.set(e,t);let n=Jt.get(e.parentStateElement);void 0===n&&(n=new Map,Jt.set(e.parentStateElement,n)),n.set(e.marker,new WeakRef(e));let o=Xt.get(e.component);void 0===o&&(o=new Map,Xt.set(e.component,o));const r=o.get(e.stateProp)!==e;o.set(e.stateProp,e),r&&Qt.register(e,{byMarker:n,marker:e.marker,getterPaths:e.parentStateElement.getterPaths,addedGetterPaths:e.addedGetterPaths}),e.parentStateElement.markHasMounts?.()}function ne(t){return oe(t).map(t=>({marker:t.marker,componentTag:t.component.tagName.toLowerCase(),stateProp:t.stateProp,mountTable:t.entries.map(t=>({inner:t.innerSegments.join(c),outer:t.outerPathInfo.path})),delta:t.delta,privateKeys:Object.keys(t.privateSnapshot),getterKeys:[...t.getterKeys],exports:[...t.exports.keys()]}))}function oe(t){const e=Jt.get(t);if(void 0===e)return[];const n=[];for(const t of e.values()){const e=t.deref();void 0!==e&&n.push(e)}return n}function re(t,e){const n=e.lastIndexOf("#");if(-1===n)return null;const o=Jt.get(t);if(void 0===o)return null;const r=e.indexOf(c,n),s=-1===r?e.slice(n):e.slice(n,r),a=o.get(s);if(void 0===a)return null;const i=a.deref();return void 0===i?(o.delete(s),null):i}const se=new WeakMap,ae=new Set;function ie(t,e,n,o){let r=se.get(t);if(void 0===r){if(!o)return null;r=new Map,se.set(t,r)}let s=r.get(e);if(void 0===s){if(!o)return null;s=new Map,r.set(e,s)}let a=s.get(n);if(void 0===a){if(!o)return null;a={holders:new Set,byListIndex:new WeakMap,noIndex:null},s.set(n,a)}return a}function ce(t,e){if(!t.component.isConnected)return!1;const n=N(t.component)?.listIndex??null;if(null===e)return null===n;let o=n;for(;null!==o;){if(o===e)return!0;o=o.parentListIndex}return!1}function le(t,e,n,o){const r=ie(t,e,n,!1);if(null===r)return null;const s=null===o?r.noIndex:r.byListIndex.get(o)??null;if(null!==s){const t=function(t,e){const n=t.ref.deref();return void 0!==n&&ce(n,e)?n:null}(s,o);if(null!==t)return{record:t,entry:s.entry}}let a=null,i=null;for(const t of r.holders){const s=t.ref.deref();void 0!==s?ce(s,o)&&(null!==i&&w(`[wcs/mount-export-ambiguous] "${e}${c}${n}" is exported by two mounted components on the same instance: <${i.component.tagName.toLowerCase()}> and <${s.component.tagName.toLowerCase()}>. Mount only one of them there, or rename one accessor. See docs/state-overlay-export-design.md X4.`),a=t,i=s):r.holders.delete(t)}return null===a||null===i?null:(null===o?r.noIndex=a:r.byListIndex.set(o,a),{record:i,entry:a.entry})}function ue(t){const e=t.parentStateElement,n=N(t.component);if(!(!1===e.isConnected||t.delta>0&&null===n))for(const o of t.exports.values())e.createState("readonly",t=>{t[M](n,()=>{t.$postUpdate(o.exportedPath)})})}const de=new WeakMap;class fe{record;markerParentPath;listIndex;isBase;receiver;handler;constructor(t,e,n,o,r,s){this.record=t,this.markerParentPath=e,this.listIndex=n,this.isBase=o,this.receiver=r,this.handler=s}accessorNameFor(t){return this.record.accessorBySuffixByMarkerParent.get(this.markerParentPath)?.get(t)?.accessorName}accessorAddress(t){return A(d(this.markerParentPath+c+t),this.listIndex)}get(t,e,n){if("string"!=typeof e)return Reflect.get(t,e);if("then"===e)return;if("$"===e[0]){if("$postUpdate"===e)return t=>{this.receiver.$postUpdate(Tt(this.record,t))};if("$getAll"===e||"$setAll"===e||"$resolve"===e){const t=this.record,n=this.listIndex?.indexes??[],o=this.receiver;if("$resolve"===e)return(e,r,...s)=>{const a=s.length>0?qt(t,e):Tt(t,e),i=Ht(0,e,a,r??[],n);return o.$resolve(a,i,...s)};const r=e;return(e,s,...a)=>{const i="$setAll"===r?qt(t,e):Tt(t,e),c=Ht(0,e,i,s,n);return o[r](i,c,...a)}}const t=this.record,n=this.receiver,o=pt(e,e=>Tt(t,e),t=>n[e](...t));return null!==o?o:this.receiver[e]}const o=this.accessorNameFor(e);if(void 0!==o){this.handler.pushAddress(this.accessorAddress(e));try{return Reflect.get(this.record.stateObject,o,n)}finally{this.handler.popAddress()}}if(this.isBase){if(Object.prototype.hasOwnProperty.call(t,e))return Q(this.handler,this.accessorAddress(e)),t[e];const o=this.record.stateObject[e];if("function"==typeof o)return o.bind(n)}return this.receiver[Tt(this.record,e)]}set(t,e,n,o){if("string"!=typeof e)return Reflect.set(t,e,n);const r=this.accessorNameFor(e);if(void 0!==r){this.record.setterKeys.has(r)||w(`Cannot write to "${r}" on mounted <${this.record.component.tagName.toLowerCase()}>: the accessor has no setter. Add a setter or write to the underlying state paths instead.`),this.handler.pushAddress(this.accessorAddress(e)),this.handler.beginUntrack();try{return Reflect.set(this.record.stateObject,r,n,o)}finally{this.handler.endUntrack(),this.handler.popAddress()}}return this.isBase&&Object.prototype.hasOwnProperty.call(t,e)?(t[e]=n,!0):(this.receiver[qt(this.record,e)]=n,!0)}has(t,e){if("string"!=typeof e)return Reflect.has(t,e);if("$"===e[0]||"#"===e[0])return!1;if(void 0!==this.accessorNameFor(e))return!0;if(this.isBase){if(Object.prototype.hasOwnProperty.call(t,e))return!0;if("function"==typeof this.record.stateObject[e])return!0}try{return Tt(this.record,e),!0}catch{return!1}}}function he(t,e,n,o){const r=e.pathInfo.path,s=r===t.markerBasePath,a=s?function(t,e){let n=de.get(t);if(void 0===n&&(n={byListIndex:new WeakMap,noIndex:null},de.set(t,n)),null===e)return n.noIndex??={...t.privateSnapshot};let o=n.byListIndex.get(e);return void 0===o&&(o={...t.privateSnapshot},n.byListIndex.set(e,o)),o}(t,e.listIndex):{};return new Proxy(a,new fe(t,r,e.listIndex,s,n,o))}function me(t){const e=t.parentStateElement,n=(e,n)=>{const o=N(t.component);let r;return e[M](o,()=>{r=n()}),r};return new Proxy({},{get(o,r){if("string"!=typeof r||"then"===r)return;if("$getAll"===r||"$setAll"===r||"$resolve"===r||"$postUpdate"===r)return function(t,e,n){const o=t.parentStateElement,r=(t,e)=>{let r;return o.createState(t,t=>{r=n(t,()=>e(t))}),r};return"$postUpdate"===e?e=>r("readonly",n=>n.$postUpdate(Tt(t,e))):(n,o,...s)=>{const a="$setAll"===e||"$resolve"===e&&s.length>0,i=a?qt(t,n):Tt(t,n),c=N(t.component)?.listIndex.indexes??[],l=Ht(0,n,i,"$resolve"===e?o??[]:o,c);return r(a?"writable":"readonly",t=>t[e](i,l,...s))}}(t,r,n);const s=pt(r,e=>Tt(t,e),t=>{let o;return e.createState("readonly",e=>{o=n(e,()=>e[r](...t))}),o});if(null!==s)return s;let a;return e.createState("readonly",e=>{a=n(e,()=>e["$"===r[0]?r:Tt(t,r)])}),a},set:(o,r,s)=>("string"!=typeof r||e.createState("writable",e=>{n(e,()=>{e["$"===r[0]?r:qt(t,r)]=s})}),!0),has(e,n){if("string"!=typeof n||"$"===n[0]||"#"===n[0])return!1;if(Object.prototype.hasOwnProperty.call(t.stateObject,n))return!0;try{return Tt(t,n),!0}catch{return!1}}})}function pe(t,e){const n=function(t){return Ut.get(t)??null}(e);null!==n&&n.stateProp!==t.stateProp&&w(`A mount scope is already initialized on this component for "${n.stateProp}" — one <wcs-state bind-component> per component (v2). Merge the "${t.stateProp}" wiring into "${n.stateProp}" or split the component.`),null!==n&&O(e).dispose(),ee(e,t),e instanceof ShadowRoot&&K(e,t.parentStateElement),function(t,e){const n=(e,n)=>Gt(t,e,n);D(e);const o=N(t.component),r=e instanceof ShadowRoot?e:e.getRootNode();L(r,e,void 0,n),B(e,o,n)}(t,e),function(t){if(t.exports.size>0||null===t.rootEntry)return;const e=new Set([...t.getterKeys,...t.setterKeys]);for(const n of e){let e;try{e=Tt(t,n)}catch{continue}const o=e.indexOf(c+t.marker);if(-1===o)continue;const r=e.slice(0,o+1+t.marker.length),s=e.slice(r.length+1),a=e.slice(0,o)+c+s,i=d(a);if(i.wildcardCount!==t.delta)continue;const l={markerTerminalPath:r,suffix:s,markerPath:e,exportedPath:a};t.exports.set(a,l),ie(t.parentStateElement,i.parentPath,i.lastSegment,!0).holders.add({ref:new WeakRef(t),entry:l}),t.parentStateElement.addDynamicDependency(e,a),J?.markExported(t.parentStateElement,a)}t.parentStateElement.markHasMounts?.()}(t),function(t){const e=N(t.component);if(t.delta>0&&null===e)return;const n=t.component.tagName.toLowerCase();for(const o of t.exports.values()){const r=`${n}|${o.exportedPath}`;if(ae.has(r))continue;const s=d(o.exportedPath);let a;t.parentStateElement.createState("readonly",t=>{t[M](e,()=>{a=t[s.parentPath]})}),null!=a&&s.lastSegment in Object(a)&&(ae.add(r),console.warn(`[@wcstack/state] [wcs/mount-export-shadowed] <${n}>.${t.stateProp}.${o.suffix} is exported at "${o.exportedPath}" but the tree already has that key, so readers outside the component get the tree value. Remove the tree key or rename the accessor. See docs/state-overlay-export-design.md X1.`))}}(t),ue(t),W(e,Promise.resolve())}function ge(t,e){const n=O(e),o=N(t.component);n.forEachActiveBindingNode(t=>R(t,o));const r=n.rebindAddresses();E(r),ue(t)}function ye(t,e){if(function(t){const e=Jt.get(t);return void 0!==e&&e.size>0}(e))for(const n of oe(e)){if(!$e(n.component,t))continue;const e=Zt(n);null!==e&&ge(n,e)}}function $e(t,e){for(let n=e.firstNode;null!==n;n=n.nextSibling){if(n===t||n.contains(t))return!0;if(n===e.lastNode)break}return!1}const we={read(t,e,n,o){if(!0===t.hasMounts&&35===e.pathInfo.lastSegment.charCodeAt(0)){const r=re(t,e.pathInfo.path);if(null!==r)return he(r,e,n,o)}return S},readMissing(t,e,n,o,r){if(null===n){if($t(t.rootNode??null,e.pathInfo.path))return;return S}if(!0===t.hasMounts){const n=le(t,e.parentAddress.pathInfo.path,e.pathInfo.lastSegment,e.listIndex);if(null!==n)return function(t,e,n,o,r){const s=he(t,A(d(e.markerTerminalPath),n),o,r);return Reflect.get(s,e.suffix)}(n.record,n.entry,e.listIndex,o,r)}return S},write(t,e){if(!0===t.hasGraftedVolumes){const n=e.pathInfo.path,o=function(t,e){const n=wt.get(t);if(void 0===n||0===n.size)return null;const o=e+c;for(const t of n)if(t.startsWith(o))return t;return null}(t,n);null!==o&&w(`Cannot replace "${n}" wholesale: a volume is mounted at "${o}" under it (D22). Replacing an ancestor of a mount point silently discards the grafted data while its accessors remain. Write "${o}" itself, or individual fields inside "${n}", instead.`)}return S},writeMissing(t,e,n,o,r,s,a){if(!0===t.hasMounts){const n=le(t,e.parentAddress.pathInfo.path,e.pathInfo.lastSegment,e.listIndex);if(null!==n)return function(t,e,n,o,r,s){const a=he(t,A(d(e.markerTerminalPath),n),r,s);return Reflect.set(a,e.suffix,o)}(n.record,n.entry,e.listIndex,r,s,a)}return S},indexShift(t,e){const n=t.stateElement,o=e.pathInfo.path;if(!0===n.hasMounts&&-1!==o.indexOf("#")){const t=re(n,o);if(null!==t)return function(t,e){const n=e.lastIndexOf("#");if(-1===n)return t.delta;const o=e.indexOf(c,n);if((-1===o?e.slice(n):e.slice(n,o))!==t.marker)return t.delta;const r=-1===o?e:e.slice(0,o),s=-1===o?"":e.slice(o+1),a=t.accessorBySuffixByMarkerParent.get(r)?.get(s);return void 0!==a?a.indexShift:t.delta}(t,o)}return 0},handlerScope(t,e,n,o,r){if(!0!==t.hasMounts)return r;const s=function(t,e){let n=t;for(;null!==n&&n!==e;){const t=Ut.get(n);if(void 0!==t)return t;n=n.parentNode}return Ut.get(e)??null}(e,n);if(null===s)return r;const a=s.indexShiftByLoopElementPath.get(o.pathInfo.path);return void 0!==a?r-a:0},updated(t,e,n){const o=function(t){return Pt.get(t)??jt}(t);for(const r of o){const o=new Set,s={};for(const n of e){if(n.absolutePathInfo.stateElement!==t)continue;const e=n.absolutePathInfo.pathInfo.path;if(-1!==e.indexOf("#"))continue;const a=kt(r.mountPath,r.injections,e);if(null===a||""===a)continue;o.add(a);const i=n.absolutePathInfo.pathInfo.wildcardCount;if(i>0&&null!==n.listIndex){const t=z(n.listIndex,i);(s[a]??=[]).push(t)}}if(o.size>0)try{r.callback.call(St(r.mountPath,n,r.injections),Array.from(o),s)}catch(t){console.error(`[@wcstack/state] volume "${r.mountPath}" $updatedCallback threw.`,t)}}},suppressPathDiagnostic:(t,e)=>$t(!1===t.isConnected?null:t.rootNode??null,e),rowReused(t,e){ye(e,t)}};let be=!1;const ve=new WeakMap;function ke(t){let e=ve.get(t);return void 0===e&&(e={graftInfo:null,initializing:!1,mountPath:null,slotRootNode:null,detachedFrom:null},ve.set(t,e)),e}function Se(t,e){null!==e.slotRootNode&&(!function(t,e,n){const o=gt.get(t);o?.get(e)===n&&o.set(e,null)}(e.slotRootNode,e.mountPath,t),e.slotRootNode=null)}function Pe(t,e,n){if(e.slotRootNode===n)return!0;const o=e.mountPath;try{yt(n,o,t)}catch{return console.error(`[@wcstack/state] <${P.tagNames.state} mount="${o}"> will not graft: another volume already holds the "${o}" slot on this root. Keep one volume per mount path.`),!1}return V(n)?.markHasVolume?.(),e.slotRootNode=n,!0}async function je(t,e){const n=t,o=t.connectedRootNode,r=n.getAttribute("mount");let s;try{!function(t){0===t.length&&w('"mount" requires a non-empty tree path.');const e=d(t);for(const n of e.segments)0===n.length&&w(`"mount" path "${t}" has an empty segment.`),n===f&&w(`"mount" path "${t}" must be static (wildcards are not allowed).`),(n.includes("$")||n.includes("#")||n.includes("@"))&&w(`"mount" path "${t}" must not use reserved characters ($, #, @).`)}(r),s=function(t,e){const n=[],o=new Set;let r;try{r=G(t)}catch(t){w(`[wcs/mount-path-invalid] <${P.tagNames.state} mount="${e}"> has an invalid ${P.bindAttributeName}: ${t instanceof Error?t.message:String(t)}`)}for(const t of r){if(t.propSegments[0]!==l)continue;const r=t.propSegments.slice(1),s=t.statePathInfo,a=n=>w(`[wcs/mount-path-invalid] <${P.tagNames.state} mount="${e}"> "${t.propName}: ${t.statePathName}": ${n}`);1===r.length&&r[0]&&r[0]!==f&&"$"!==r[0][0]&&"#"!==r[0][0]||a(`inject one key at a time ("${l}.<key>: path"); change "mount" to move the whole volume.`),(s.wildcardCount>0||"$"===s.path[0]||"#"===s.path[0])&&a("the injected path must be a static path on the root tree (a volume has no loop context)."),(t.inFilters.length>0||t.outFilters.length>0)&&a("an injection takes no filters."),t.propModifiers.some(t=>t!==u)&&a(`an injection accepts only #${u}.`),o.has(r[0])&&a(`"${r[0]}" is injected twice.`),o.add(r[0]),n.push({innerSegments:r,outerPathInfo:s,readonly:t.propModifiers.includes(u)})}return n.sort((t,e)=>e.innerSegments.length-t.innerSegments.length),n}(n.getAttribute(P.bindAttributeName)??"",r),n.hasAttribute("bind-component")&&w('"mount" cannot be combined with "bind-component".'),n.hasAttribute("enable-ssr")&&console.warn(`[@wcstack/state] <${P.tagNames.state} mount="${r}"> ignores "enable-ssr" — snapshots are per root tree (the root state element aggregates volume data).`),yt(o,r,t),V(o)?.markHasVolume?.(),e.mountPath=r,e.slotRootNode=o}catch(e){throw t.settleInitialization(),e}e.initializing=!0,null===V(o)&&function(t,e){const n=()=>{if(null!==V(t))return;const n=t.querySelectorAll(P.tagNames.state);for(const t of n)if(!t.hasAttribute("mount")&&!t.hasAttribute("bind-component"))return;console.error(`[@wcstack/state] <${P.tagNames.state} mount="${e}"> has no root state tree to graft onto (D11). A volume mounts onto the root tree — add a root <${P.tagNames.state}> to this root node (an empty <${P.tagNames.state}></${P.tagNames.state}> is enough). If the root is added dynamically later, the graft will still complete and this report can be ignored.`)},o=t.ownerDocument??t;"loading"===o.readyState?o.addEventListener("DOMContentLoaded",()=>queueMicrotask(n),{once:!0}):setTimeout(n,0)}(o,r);const a=n=>{e.graftInfo=n,t.markInitialized(),null===n&&Se(t,e),t.settleInitialization()};let i;try{await Promise.resolve(),i=await t.loadStateFromSource()}catch(t){return console.error(`[@wcstack/state] volume "${r}" failed to load.`,t),void a(null)}const c=t.connectedRootNode??null;null!==c&&Pe(t,e,c)?function(t,e,n,o,r,s,a=[]){const i={mountPath:n,volumeState:o,injections:a,onGrafted:r,acquireSlot:s};if(null!==e)return void Ze(e,i);en(),function(t,e){if(xt.has(t))return void It(e);let n=Ct.get(t);void 0===n&&(n=[],Ct.set(t,n)),n.push(e)}(t,i)}(c,V(c),r,i,a,()=>Pe(t,e,c),s):a(null)}const Ce={order:20,connecting(t){if(!t.hasAttribute("mount"))return null;const e=ke(t);if(e.initializing){const n=t.connectedRootNode;if(null!=n&&e.detachedFrom===n)try{yt(n,e.mountPath,t),V(n)?.markHasVolume?.(),e.slotRootNode=n}catch{}return e.detachedFrom=null,o}return je(t,e)},reconnecting(t){if(!t.hasAttribute("mount"))return!1;const e=ke(t),n=t.connectedRootNode??null;return null!==e.graftInfo&&null!==n&&V(n)===e.graftInfo.rootStateElement&&Je(e.graftInfo,"$connectedCallback"),!0},replacingState(t){if(!0!==ve.get(t)?.initializing)return;const e=t.getAttribute("mount");w(`Cannot replace the state of <${P.tagNames.state} mount="${e}"> after it has loaded: a volume's data is copied into the root tree when it grafts, so a new state would never reach the page. Write the paths under "${e}" on the root state instead.`)},initializeFailed(t,e){!function(t){xt.add(t);const e=Ct.get(t);if(void 0!==e){Ct.delete(t);for(const t of e)It(t)}}(e)},initializeFailureCleared(t,e){!function(t){xt.delete(t)}(e)},disconnecting(t){if(!t.hasAttribute("mount"))return!1;const e=ke(t);return null!==e.graftInfo&&Je(e.graftInfo,"$disconnectedCallback"),!0!==t.initialized&&(e.detachedFrom=e.slotRootNode,Se(t,e)),t.clearConnectedRootNode(),!0}};let xe=!1;const Ie=new WeakMap;function Ne(t,e){let n=Ie.get(t);n||(n=new Set,Ie.set(t,n)),n.add(e)}const Me=new WeakMap;const Ae=new WeakMap,Oe=new WeakMap;const Re=new WeakMap;const Ee={isComplete:function(t,e){return!0===Ie.get(t)?.has(e)},isDeclared:function(t,e){return!0===Me.get(t)?.has(e)},rememberOverwrittenObject:function(t,e,n){let o=Ae.get(t);o||(o=new Map,Ae.set(t,o)),o.has(e)||o.set(e,n)},recordInjectedKey:function(t,e,n){let o=Oe.get(t);o||(o=new Map,Oe.set(t,o));let r=o.get(e);r||(r=new Set,o.set(e,r)),r.add(n)},rememberOverwrittenValue:function(t,e,n,o){let r=Re.get(t);r||(r=new Map,Re.set(t,r));let s=r.get(e);s||(s=new Map,r.set(e,s)),s.has(n)||s.set(n,o)}};function Ke(t){return function(t){const e=Object.getPrototypeOf(t),n=Object.create(e),o=Object.getOwnPropertyDescriptors(t);for(const t in o){const e=o[t];!1===e.writable&&(e.writable=!0)}return Object.defineProperties(n,o),n}(t)}const We=new WeakMap;class De{_innerStateElement;constructor(t,e){this._innerStateElement=function(t,e){const n=We.get(t);return n?n.get(e)??null:null}(t,e)??w("State element not found for web component.")}get(t,e,n){if("string"==typeof e){let t;return this._innerStateElement.createState("readonly",n=>{t=n[e]}),t}return Reflect.get(t,e,n)}set(t,e,n,o){return"string"==typeof e?(this._innerStateElement.createState("writable",t=>{t[e]=n}),!0):Reflect.set(t,e,n,o)}}const Le=t=>()=>t;function Be(t,e,n,o){!function(t,e,n){let o=We.get(t);o||(o=new Map,We.set(t,o)),o.set(e,n)}(e,n,t),t.setInitialState(Ke(o));const r=function(t,e){const n=new De(t,e);return new Proxy({},n)}(e,n);Object.defineProperty(e,n,{get:Le(r),enumerable:!0,configurable:!0}),Ne(e,n),ze(e,n)}function ze(t,e){if(p in t){const n=t[p];"function"==typeof n?n.call(t,e).catch(t=>{w(`Error in ${p}: ${t instanceof Error?t.message:String(t)}`)}):w(`${p} is not a function.`)}}const Ve=new Set;function Fe(t,e){Ve.has(t)||(Ve.add(t),console.warn(`[@wcstack/state] [wcs/mount-own-key-shadow] ${e} See docs/state-mount-design.md §4-3.`))}function qe(t){!function(t){const e=t.component.tagName.toLowerCase(),n=t.stateProp;let o=null;for(const r of t.entries){if(0===r.innerSegments.length)continue;const s=r.innerSegments[0];o??=k(t.stateObject);const a=o[s];let i;if(t.getterKeys.has(s)||t.setterKeys.has(s)||"function"==typeof a?.get||"function"==typeof a?.set)i="an accessor";else if("function"==typeof a?.value)i="a method";else{if(t.mappedKeys.has(s)||t.injectedKeys.has(s)||!Object.prototype.hasOwnProperty.call(t.stateObject,s))continue;i="an own data key"}const l=r.innerSegments.join(c);Fe(`${e}|${n}|${l}|entry`,`<${e}>.${n} declares "${s}" as ${i}, which hides the mounted entry "${n}.${l}: ${r.outerPathInfo.path}" (the host value never reaches it). Rename one of them.`)}}(t);const e=Object.keys(t.privateSnapshot);if(0===e.length)return;const n=t.component.tagName.toLowerCase(),o=t.stateProp;let r,s=!1;for(const a of e){if(null===t.rootEntry)continue;if(s||(r=Te(t),s=!0),"object"!=typeof r||null===r||!(a in r))continue;const e=t.rootEntry.outerPathInfo.path;Fe(`${n}|${o}|${a}|root`,`<${n}>.${o}.${a} is private and hides the mounted tree key "${e}.${a}" (${o}: ${e}). Remove the default to read the tree, or rename it to keep it private.`)}}function Te(t){const e=t.rootEntry,n=N(t.component);if(e.outerPathInfo.wildcardCount>0&&null===n)return;let o;return t.parentStateElement.createState("readonly",t=>{t[M](n,()=>{o=t[e.outerPathInfo.path]})}),o}const _e=new WeakMap;function Ge(t,e){t.landInitialization(),w(e)}async function He(t,e){const n=t;if(n.hasAttribute("bind-component")){const s=n.parentNode,a=s instanceof ShadowRoot?s.host:s instanceof Element?s:null,i=a?T(a):null;null!==a&&null!==i||w(`"bind-component" requires <${P.tagNames.state}> to be a direct child of a custom element.`),s instanceof ShadowRoot||a.hasAttribute(P.bindAttributeName)||Ge(t,`A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${i}>, or mount it from the host (data-wcs="${n.getAttribute("bind-component")}: path").`);const c=["state","src","json"].filter(t=>n.hasAttribute(t));null!==n.querySelector('script[type="module"]')&&c.push('<script type="module">'),c.length>0&&w(`"bind-component" cannot be combined with ${c.join(", ")}. The component's "${n.getAttribute("bind-component")}" property is the only state source.`);const l=n.getAttribute("bind-component");!function(t,e){let n=Me.get(t);n||(n=new Set,Me.set(t,n)),n.add(e)}(a,l);const u=C(a);null===u&&w(`CustomElementRegistry is unavailable for <${i}>.`),await u.whenDefined(i.toLowerCase()),a.hasAttribute(P.bindAttributeName)&&await _(a),l in a||w(`Component does not have property "${l}" for state binding.`);let d=a[l];"object"==typeof d&&null!==d||w(`Component property "${l}" is not an object for state binding.`);const f=function(t,e){const n=Ae.get(t);if(!n)return;const o=n.get(e);return n.delete(e),o}(a,l);if(void 0!==f&&function(t,e){if(!t.hasAttribute(P.bindAttributeName))return!1;const n=F(t);if(null===n)return!1;for(const t of n)if(1===t.propSegments.length&&t.propSegments[0]===e)return!0;return!1}(a,l)&&(a[l]=f,d=f),e.boundComponent=a,e.boundComponentStateProp=l,t.setBoundComponent(a,l),s instanceof ShadowRoot||(F(a)??[]).some(t=>t.propSegments[0]===l)||Ge(t,`A plain (unwired) Light DOM "bind-component" is not supported. Attach a shadow root to <${i}>, or mount it from the host (data-wcs="${l}: path").`),a.hasAttribute(P.bindAttributeName)){const c=(F(a)??[]).filter(t=>t.propSegments[0]===l);if(c.length>0){const u=V(a.getRootNode())??Ge(t,`No state tree found on this root for mount host <${i}>.`);let f=(o=a,r=l,Xt.get(o)?.get(r)??null);const h=null!==f;if(null===f&&(!function(t,e,n){const o=Re.get(t)?.get(e);if(void 0!==o){for(const[t,e]of o)n[t]=e;Re.get(t).delete(e)}}(a,l,d),f=Et(a,l,c,u,d,function(t,e){return Oe.get(t)?.get(e)}(a,l)),qe(f)),e.mountRecord=f,n.parentNode!==s)return;try{pe(f,s instanceof ShadowRoot?s:a)}catch(e){throw t.landInitialization(),e}if(!h){const t=me(f);Object.defineProperty(a,l,{get:()=>t,enumerable:!0,configurable:!0}),Ne(a,l)}return ze(a,l),function(t){const e=At.filter(e=>void 0!==t.stateObject[e]);for(const n of t.getterKeys)-1!==n.indexOf(m)&&e.push(`"${n}"`);if(0===e.length)return;const n=`${t.component.tagName.toLowerCase()}|${t.stateProp}`;Ot.has(n)||(Ot.add(n),console.warn(`[@wcstack/state] [wcs/mount-dollar-declaration] <${n.split("|")[0]}>.${t.stateProp} declares ${e.join(", ")}, which mounted components do not run. Declare them on the root state instead (a volume <wcs-state mount="..."> can host $watch / $listKeys / $updatedCallback; $recursion and "**" getters expand against the root tree). See docs/state-mount-design.md §4-6.`))}(f),void Rt(f,"$connectedCallback")}}Be(t,e.boundComponent,e.boundComponentStateProp,d)}var o,r}const Ue={order:30,preparing(t){if(!t.hasAttribute("bind-component"))return null;const e=function(t){let e=_e.get(t);return void 0===e&&(e={boundComponent:null,boundComponentStateProp:null,mountRecord:null},_e.set(t,e)),e}(t);return He(t,e).then(()=>null!==e.mountRecord&&(t.markInitialized(),t.settleInitialization(),!0))},reconnecting(t){const e=_e.get(t);if(void 0===e||null===e.mountRecord)return!1;const n=e.mountRecord,o=t.parentNode;return queueMicrotask(()=>{null!=t.connectedRootNode&&ge(n,o)}),Rt(n,"$connectedCallback"),!0},disconnecting(t){const e=_e.get(t);return void 0!==e&&null!==e.mountRecord&&(Rt(e.mountRecord,"$disconnectedCallback"),ue(e.mountRecord),t.clearConnectedRootNode(),!0)}};let Xe=!1;function Je(t,e){const n=t.volumeState[e];"function"==typeof n&&t.rootStateElement.createState("writable",o=>{const r=n.call(St(t.mountPath,o,t.injections));r instanceof Promise&&r.catch(n=>{console.error(`[@wcstack/state] volume "${t.mountPath}" ${e} failed.`,n)})})}function Qe(t,e,n,o){const r=n[g];if(void 0!==r){const n=X(e),s=[],a=new Set;let i=0;for(const[n,c]of Object.entries(r)){const r=vt(e,o,n,!1),l=function(t,n,...r){c.call(St(e,this,o),t,n,...r)};s.push({path:r,pathInfo:d(r),handler:l,order:1e6+i++}),a.add(r),t.setPathInfo(r,"prop","watch")}s.length>0&&(n.addEntries(t,s),t.addVolumeWatchPaths?.(a),n.start(t))}const s=n[y];if(void 0!==s){const n=new Map;for(const[t,r]of Object.entries(s))n.set(vt(e,o,t,!1),r);t.mergeVolumeListKeys?.(n)}const a=n[h];"function"==typeof a&&(!function(t,e){let n=Pt.get(t);void 0===n&&(n=[],Pt.set(t,n)),n.push(e),t.markHasVolume?.()}(t,{mountPath:e,injections:o,callback:a}),t.enableUpdatedCallback?.());for(const t of["$commandTokens","$eventTokens","$on","$errorCallback"])void 0!==n[t]&&console.warn(`[@wcstack/state] volume "${e}" declares ${t}, which volumes do not support. Declare it on the root state instead.`)}function Ye(t,e,n,o=[]){j(n),function(t,e,n,o){const r=0===o.length?null:k(n);for(const t of o){const n=t.innerSegments[0],o=r[n];void 0===o||"function"!=typeof o.get&&"function"!=typeof o.set&&"function"!=typeof o.value||w(`[wcs/mount-path-invalid] Volume "${e}" declares "${n}" as an accessor or a method and also injects it ("${l}.${n}: ${t.outerPathInfo.path}"). Rename one of them.`)}const s=n[g];if(void 0!==s){"object"==typeof s&&null!==s||w(`${g} must be an object mapping state paths to handler functions.`);const t=X(e);for(const[e,n]of Object.entries(s))"function"!=typeof n&&w(`${g} entry "${e}" must be a function.`),t.assertValidPath(e)}const i=n[y];if(void 0!==i){"object"==typeof i&&null!==i||w(`${y} must be an object mapping list paths to key specs.`);for(const[n,r]of Object.entries(i)){(0===n.length||"string"!=typeof r&&"function"!=typeof r)&&w(`${y} entry "${n}" must map a list path to a field name or a key function.`);const s=vt(e,o,n,!1);t.listKeys?.has(s)&&w(`${y} entry "${s}" is declared by both the root and a volume (or two volumes). Keep exactly one.`)}}void 0!==n[a]&&w(`Volume "${e}" declares ${a}, which volumes do not support yet. Declare the stream on the root state.`),void 0!==n.$scan&&w(`Volume "${e}" declares $scan, which volumes do not support yet. Declare the scan on the root state.`),void 0!==n[$]&&w(`Volume "${e}" declares ${$}, which volumes do not support yet. Declare the recursion anchor on the root state — the anchor path is resolved against the root tree.`);for(const t of Object.keys(k(n)))-1!==t.indexOf(m)&&w(`Volume "${e}" declares "${t}", which uses "${m}". Volumes do not support recursive getters yet — declare them on the root state.`)}(t,e,n,o);const{data:r,accessors:s}=function(t,e){const n={},o=new Map;for(const[r,s]of Object.entries(k(t)))r.startsWith("$")||e.has(r)||("function"!=typeof s.get&&"function"!=typeof s.set?"function"!=typeof s.value&&(n[r]=s.value):o.set(r,s));return{data:n,accessors:o}}(n,new Set(o.map(t=>t.innerSegments[0]))),i=d(e),u=!0===t.hydratedFromSsr;t.createState("writable",t=>{if(1===i.segments.length&&e in t){if(u)return;w(`Volume mount "${e}" collides with an existing key on the root tree. Remove the root key or mount the volume elsewhere.`)}let n="";for(let e=0;e<i.segments.length-1;e++){const o=i.segments[e],r=""===n?o in t:void 0!==t[n+c+o];n=""===n?o:n+c+o,r||(t[n]={})}if(i.segments.length>1&&void 0!==t[e]){if(u)return;w(`Volume mount "${e}" collides with an existing key on the root tree. Remove the root key or mount the volume elsewhere.`)}t[e]=r}),function(t,e){let n=wt.get(t);void 0===n&&(n=new Set,wt.set(t,n)),n.add(e)}(t,e),t.markHasGraftedVolumes?.();for(const[n,r]of s){const s=e+c+n,a=r.get,i=r.set,l={enumerable:!1,configurable:!0};"function"==typeof a&&(l.get=function(){return a.call(St(e,this,o))}),"function"==typeof i&&(l.set=function(t){i.call(St(e,this,o),t)}),t.defineTreeAccessor(s,l)}Qe(t,e,n,o);const f=n.$connectedCallback;return"function"==typeof f&&t.createState("writable",t=>{let n;try{n=f.call(St(e,t,o))}catch(t){return void console.error(`[@wcstack/state] volume "${e}" $connectedCallback failed.`,t)}n instanceof Promise&&n.catch(t=>{console.error(`[@wcstack/state] volume "${e}" $connectedCallback failed.`,t)})}),{rootStateElement:t,mountPath:e,volumeState:n,injections:o}}function Ze(t,e){if(!e.acquireSlot())return void e.onGrafted(null);let n=null;try{n=Ye(t,e.mountPath,e.volumeState,e.injections)}catch(t){console.error(`[@wcstack/state] volume "${e.mountPath}" failed to graft.`,t)}finally{e.onGrafted(n)}}let tn=!1;function en(){tn||(tn=!0,be||(be=!0,v("scopes",we),U(ne)),xe||(xe=!0,t("scopes",Ce)),Xe||(Xe=!0,t("bindComponent",Ue),q(Ee)),Nt=Ze,H(nn))}function nn(t,e){(function(t){const e=gt.get(t);return void 0!==e&&e.size>0})(t)&&e.markHasVolume?.(),function(t,e){xt.delete(t);const n=Ct.get(t);if(void 0===n||0===n.length||null===Nt)return;Ct.delete(t);const o=Nt;queueMicrotask(()=>{for(const t of n)o(e,t)})}(t,e)}const on={name:"scopes",install(){en(),ut||(ut=!0,t("dcc",lt))}};export{on as default,on as scopes};
|
|
2
2
|
//# sourceMappingURL=scopes.js.map
|