@wcstack/state 3.0.0 → 3.2.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.
Files changed (44) hide show
  1. package/README.ja.md +47 -17
  2. package/README.md +47 -17
  3. package/dist/auto.min.js +1 -1
  4. package/dist/auto.min.js.map +1 -1
  5. package/dist/define.d.ts +11 -7
  6. package/dist/index.d.ts +15 -7
  7. package/dist/index.esm.js +1 -1
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/manifest.d.ts +14 -1
  10. package/dist/manifest.esm.js +91 -35
  11. package/dist/parser.esm.js +25 -0
  12. package/dist/split/chunks/binder.js +1 -1
  13. package/dist/split/chunks/binder.js.map +1 -1
  14. package/dist/split/chunks/checkDependency.js +1 -1
  15. package/dist/split/chunks/declarationAliases.js +2 -0
  16. package/dist/split/chunks/declarationAliases.js.map +1 -0
  17. package/dist/split/chunks/filterRegistry.js +1 -1
  18. package/dist/split/chunks/filterRegistry.js.map +1 -1
  19. package/dist/split/chunks/mount.js +1 -1
  20. package/dist/split/chunks/mount.js.map +1 -1
  21. package/dist/split/chunks/pathDiagnostics.js +1 -1
  22. package/dist/split/chunks/pathDiagnostics.js.map +1 -1
  23. package/dist/split/chunks/registerComponents.js +1 -1
  24. package/dist/split/chunks/registerComponents.js.map +1 -1
  25. package/dist/split/chunks/setAll.js +1 -1
  26. package/dist/split/chunks/version.js +1 -1
  27. package/dist/split/chunks/watchRuntime.js +1 -1
  28. package/dist/split/core.d.ts +11 -7
  29. package/dist/split/core.js +1 -1
  30. package/dist/split/core.js.map +1 -1
  31. package/dist/split/features/devtools.js +1 -1
  32. package/dist/split/features/devtools.js.map +1 -1
  33. package/dist/split/features/diagnostics.js +1 -1
  34. package/dist/split/features/formats.js +1 -1
  35. package/dist/split/features/formats.js.map +1 -1
  36. package/dist/split/features/recursion.js +1 -1
  37. package/dist/split/features/scopes.js +1 -1
  38. package/dist/split/features/scopes.js.map +1 -1
  39. package/dist/split/features/ssr.js +1 -1
  40. package/dist/split/features/ssr.js.map +1 -1
  41. package/dist/split/features/temporal.js +1 -1
  42. package/dist/split/features/temporal.js.map +1 -1
  43. package/dist/wcs-manifest.json +65 -25
  44. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- import{g as t,v as e,C as n,W as s,E as a,l as o,D as l,o as r,F as i,G as d,s as c,H as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aA as h,H as p,l as g,aB as y,N as I,K as w,k as m,M as x,L as P,aC as v,F as A,aD as b,G as $,af as k,aE as R,aF as E,aG as S,aH as M,aI as j,aJ as C,aK as L,a6 as O,c as D,aL as T,ab as V,X as B,aM as N,J as H,x as G}from"./binder.js";import{N as q}from"./getAllPropertyDescriptors.js";import{c as z}from"./checkDependency.js";import{c as W}from"./filterRegistry.js";const F=new WeakMap;function K(t,e){let n=F.get(t);void 0===n&&(n=new Map,F.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const J=new WeakMap;function U(t){const e=J.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return K(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:K(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return J.set(t,n),n}function X(t){J.delete(t)}function Q(t){"readonly"===t.mutability&&u("This state is readonly.")}const Y=new Map;class Z{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const n=e.split("."),s=n.slice();let a=0,o=0,l=0,r="none";const i=[];for(let t=0;t<n.length;t++){const e=n[t];if("*"===e)s[t]="*",i.push(null),a++,l++;else{const n=Number(e);Number.isNaN(n)||(s[t]="*",i.push(n),o++,l++)}}const d=s.join("."),c=t(d);(a>0||o>0)&&(r=a===l?"context":o===l?"all":"partial"),this.path=e,this.segments=n,this.wildcardCount=l,this.wildcardType=r,this.wildcardIndexes=i,this.pathInfo=c}}function _(t){let e;return Y.get(t)??(Y.set(t,e=new Z(t)),e)}function tt(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const s=n.pathInfo.indexByWildcardPath[e];return void 0===s||null===n.listIndex?null:p(n.listIndex,s,n.pathInfo.wildcardCount)}function et(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function nt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==q)return r}}return q}function st(t,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(U(i),o.pathInfo.segments);if(!(o.pathInfo.path in t)){if(null===o.parentAddress){const e=nt(i,o,null,l,r);if(e!==q)return e;u(n(o.pathInfo.path,t,i.getterPaths))}const e=at(t,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==s&&!(d in Object(e))){const t=nt(i,o,Object(e),l,r);if(t!==q)return t}if(d===s){const t=o.listIndex?.index??u(a(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(t,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(t,o.pathInfo.path,l)}finally{r.popAddress()}}function at(t,e,n,s){z(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==q)return l}}return et(a,e)?function(t,e,n,s,a){const o=g(a,e),l=y(o),r=a.stateGeneration;if(null!==l&&!1===l.dirty&&l.generation===r)return l.value;const i=st(t,e,n,s,a);return I(o,{value:i,dirty:!1,generation:r}),i}(t,e,n,s,a):st(t,e,n,s,a)}function ot(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const p=m(h,o),y=g(n.stateElement,p),I=x(y),w=at(t,p,e,n),v=P(o,I,w).newIndexes,A=i[d]??null;if(l.set(y,w),null===A)for(let t=0;t<v.length;t++){const e=v[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=v[A]??u(`ListIndex not found at index ${A} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())w(t,Array.isArray(e)?e:[]);return i}function lt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=at(t,m(r,o),e,n),d=v(i,o);null==d&&u(`ListIndexes not found: ${r.path}`);const c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function rt(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function it(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function dt(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];rt(i,n,s,r);const d=it(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function ct(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function ft(t,e,n,a){if(e.pathInfo.path in t)return!0;const o=e.parentAddress;if(null===o)return!1;const l=at(t,o,n,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=e.pathInfo.lastSegment;if(r===s){const t=e.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const ut=new WeakMap;function ht(t,e){null===e?ut.delete(t):ut.set(t,e)}function pt(e,n,s){const a=e.wildcardParentPaths[n],o=t(a),l=m(o,s),r=g(e.stateElement,l),i=x(r),d=e.stateProxy[A](l),c=P(l.listIndex,i,d);e.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return W.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,e.searchType);if(n===e.wildcardPaths.length-1)e.targetListIndexes.push(...f);else for(const t of f)pt(e,n+1,t)}const gt=[];function yt(t,e,n,s,a){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:a.newIndexes,movedRows:null}:0===a.addIndexSet.size&&0===a.changeIndexSet.size?0===a.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:gt,movedRows:null}:{fullRows:a.newIndexes,movedRows:null}:{fullRows:gt,movedRows:null}:{fullRows:a.addIndexSet,movedRows:a.changeIndexSet}}const It=[];function wt(e,n,s){const a=e.stateElement.indexDependentGetterPaths;if(!a||0===a.size)return It;let o=null;const r=n+l;for(const e of a){if(e!==n&&!e.startsWith(r))continue;const a=t(e);if(a.wildcardCount!==s.wildcardCount)return null;(o??=[]).push(a)}return o??It}function mt(e,n,a){const o=n.pathInfo.path,l=e.staticMap.get(o);if(l)for(const r of l){const l=t(r);if(e.listPathSet.has(o)&&l.lastSegment===s){const t=e.stateProxy[A](n),s=g(e.stateElement,n),i=x(s),d=P(n.listIndex,i,t);e.observedListValueByAbsAddress.set(s,Array.isArray(t)?t:[]);const c=yt(e,o,0,0,d);for(const t of c.fullRows){const n=m(l,t);e.result.add(n),a.push(n)}if(null!==c.movedRows){const t=wt(e,r,l);if(null===t)for(const t of c.movedRows){const n=m(l,t);e.result.add(n),a.push(n)}else if(t.length>0)for(const n of c.movedRows)for(const s of t){const t=m(s,n);e.result.add(t),a.push(t)}}}else{const t=m(l,n.listIndex);e.result.add(t),a.push(t)}}const r=e.dynamicMap.get(o);if(r)for(const s of r){const o=t(s),l=[];if(o.wildcardCount>0){const t=b(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=p(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};pt(a,t,s),l.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=p(n.listIndex,t-1,n.pathInfo.wildcardCount);l.push(e)}}else l.push(null);for(const t of l){const n=m(o,t);e.result.add(n),a.push(n)}}}function xt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null};!function(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),n(r),l.length=0,mt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}(f,e,r);for(const[t,e]of f.observedListValueByAbsAddress)w(t,e);return Array.from(f.result)}function Pt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function vt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function At(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function bt(t,e,n,s,a,o){const l=E(t,e),r=S(t,e);if(!l&&!r)return;const i=D(),d=W.enablePropagationContext?M()??null:null,c=t=>{k(t),i.enqueueAbsoluteAddress(t,d)};l&&j(t,e,n,s,a).forEach(c),r&&C(t,e,n?s:o(),a).forEach(c)}function $t(t,e,n,s,a,o,l="diff"){const r=W.enablePropagationContext?M()??L(-1):null,i=D();i.enqueueAbsoluteAddress(e,r),o&&k(e),xt(s.stateElement,t,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=g(s.stateElement,e);k(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:l,keyedMergePath:a})}function kt(t,e,n,s,a){a&&(t.getterPaths.has(e)?k(n):I(n,{value:s,dirty:!1,generation:t.stateGeneration}))}function Rt(t,e,n,o,l,r,i,d){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,o);const i=at(t,n,l,r),d=e.pathInfo.segments[e.pathInfo.segments.length-1];if(d===s){const t=e.listIndex?.index??u(a(`path "${e.pathInfo.path}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,o);r.pushAddress(e),r.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{$t(e,n,l,r,i,d)}}function Et(e,n,a,o,r,i,d,c){const f=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),h=at(e,f,r,i)??[];let p=(y=h,ut.get(y)??null);var y;if(null===p){const t=$(h)??[];p={value:[...h],listIndexes:[...t]},ht(h,p)}try{return Rt(e,n,a,o,r,i,d,c)}finally{const a=p.value.indexOf(o),d=at(e,f,r,i)??[],c=Array.isArray(d)?$(d)??[]:[],u=n.listIndex.index,y=-1!==a?p.listIndexes[a]:O(f.listIndex,-1);c[u]=y;if(new Set(d).size===p.value.length){for(let t=0;t<c.length;t++)c[t].index=t;ht(h,null),function(e,n,a,o,r,i){const d=i.stateElement,c=D(),f=g(d,e);T(f)===a&&(V(n.value,n.listIndexes),B(f,n.value),N(n.value));c.enqueueRenderOnlyAddress(f);const u=new Map;n.listIndexes.forEach((t,e)=>u.set(t,e));const h=t(e.pathInfo.path+l+s);for(let t=0;t<o.length;t++){const e=o[t],s=u.get(e);if(s===t)continue;const a=m(h,e),l=g(d,a);if(void 0===s){const e=H(d,h,n.listIndexes[t]??null);At(d,l,e),$t(a,l,r,i,null,et(d,a),"full");continue}xt(d,a,d.staticDependency,d.dynamicDependency,d.listPaths,r,"new",t=>{const e=g(d,t);k(e),c.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}}(f,p,d,c,r,i)}}}function St(e,n,a,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(a)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=at(e,n,o,r),c=function(t,e,n,s){const a=dt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=dt(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,a);if(null!==c)return function(e,n,a,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===$(o)&&P(c,null,o);const f=P(c,o,a.list),u=Mt(e,n,a.list,r,i,d),h=t(d+l+s);for(const n of a.matched){const s=ct(n.oldRow,n.newRow);if(0===s.length)continue;const a=f.newIndexes[n.position];for(const o of s){if(void 0===a){n.oldRow[o.field]=o.value;continue}const s=t(h.path+l+o.field);St(e,m(s,a),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return Mt(e,n,a,o,r,null)}function Mt(t,e,n,o,l,i){const d=l.stateElement,c=e.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let s=0;s<t.length;s++){const a=t[s](d,e,n,o,l);if(a!==q)return a}}const h=R();if(!(c in t)&&null!==e.parentAddress&&!d.elementPaths.has(c)){const p=at(t,e.parentAddress,o,l);if("object"==typeof p&&null!==p){const t=e.pathInfo.lastSegment,y=t===s?e.listIndex?.index:t;let I,w=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const t=void 0!==y&&y in p,e=void 0!==y?p[y]:void 0;if(t&&Object.is(e,n))return!0;I=e,w=!0}bt(d,c,w,I,n,()=>p[y]);const m=et(d,e),x=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:x,value:n,oldValue:I,hasOldValue:w}),Pt(d,c,x,I,w);let P=!1;try{if(void 0===y&&u(a(`path "${c}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0)),f&&0!==f.writeMissing.length&&t!==s&&!(y in p)){const t=f.writeMissing;for(let s=0;s<t.length;s++){P=!0;const a=t[s](d,e,p,y,n,o,l);if(a!==q)return a;P=!1}}return Reflect.set(p,y,n)}finally{$t(e,x,o,l,i,m),P?k(x):kt(d,c,x,n,m),vt(d,e.pathInfo,{value:n})}}}let p,y=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const s=at(t,e,o,l);if(ft(t,e,o,l)&&Object.is(s,n))return!0;p=s,y=!0}bt(d,c,y,p,n,()=>at(t,e,o,l));const I=d.elementPaths.has(e.pathInfo.path),w=et(d,e),m=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:m,value:n,oldValue:p,hasOldValue:y}),Pt(d,c,m,p,y);try{return I?Et(t,e,m,n,o,l,i,w):Rt(t,e,m,n,o,l,i,w)}finally{I||kt(d,c,m,n,w),vt(d,e.pathInfo,{value:n})}}function jt(e,n,s,a){return(n,o,...l)=>{const r=t(n);if(a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",n,r.wildcardParentPathInfos.length,o.length));const d=lt(e,s,a,r,o),c=m(r,d);if(0===l.length)return at(e,c,s,a);Q(a),St(e,c,l[0],s,a)}}function Ct(e,n,s,a){const o=jt(e,0,s,a);return(n,l)=>{const r=t(n);if(void 0===l||Array.isArray(l)||u(`$getAll("${n}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",n,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=tt(a,r.wildcardPaths[t]);if(e){l=G(e,e.length);break}}if(void 0===l){const t=a.addressStackLength>0?a.lastAddressStack:null,e=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==e&&e.length>0&&u(d(n,t.pathInfo.path)),l=[]}}const c=ot(e,s,a,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function Lt(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return tt(s,a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`))??u(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=at(t,m(l,a),n,s),i=v(r,a)??u(`ListIndex not found: ${l.path}`),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function Ot(e,n,s,a){return(n,o,l,r)=>{Q(a);const d=t(n);Array.isArray(o)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),o.length>d.wildcardParentPathInfos.length&&u(i("$setAll",n,d.wildcardParentPathInfos.length,o.length));const h=!0===r?.spread,p="function"==typeof l;h&&p&&u(c(n,"cannot combine { spread: true } with a mapper function.")),h&&!Array.isArray(l)&&u(c(n,"requires an array as the value when { spread: true } is set."));const g=ot(e,s,a,d,o,{commitDiffBaseline:!1});h&&l.length!==g.length&&u(f(n,g.length,l.length));const y=[];for(let t=0;t<g.length;t++){const n=lt(e,s,a,d,g[t]);y.push(m(d,n))}let I=0;for(let t=0;t<y.length;t++){const n=y[t];let o;if(p){o=l(at(e,n,s,a),...g[t])}else o=h?l[t]:l;void 0!==o&&(St(e,n,o,s,a),I++)}return I}}export{Q as a,Ct as b,Ot as c,_ as d,Lt as e,U as f,at as g,ft as h,X as i,jt as r,St as s,xt as w};
1
+ import{g as t,w as e,E as n,W as s,F as a,m as o,D as l,p as r,G as i,H as d,t as c,J as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aA as h,I as p,l as g,aB as y,O as I,L as w,k as m,N as x,M as P,aC as v,G as A,aD as b,H as $,af as k,aE as R,aF as E,aG as S,aH as M,aI as j,aJ as O,aK as L,a6 as C,c as D,aL as T,ab as V,Y as B,aM as N,K as H,x as G}from"./binder.js";import{N as q}from"./getAllPropertyDescriptors.js";import{c as z}from"./checkDependency.js";import{c as W}from"./filterRegistry.js";const K=new WeakMap;function F(t,e){let n=K.get(t);void 0===n&&(n=new Map,K.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const J=new WeakMap;function U(t){const e=J.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return F(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:F(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return J.set(t,n),n}function Y(t){J.delete(t)}function Q(t){"readonly"===t.mutability&&u("This state is readonly.")}const X=new Map;class Z{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const n=e.split("."),s=n.slice();let a=0,o=0,l=0,r="none";const i=[];for(let t=0;t<n.length;t++){const e=n[t];if("*"===e)s[t]="*",i.push(null),a++,l++;else{const n=Number(e);Number.isNaN(n)||(s[t]="*",i.push(n),o++,l++)}}const d=s.join("."),c=t(d);(a>0||o>0)&&(r=a===l?"context":o===l?"all":"partial"),this.path=e,this.segments=n,this.wildcardCount=l,this.wildcardType=r,this.wildcardIndexes=i,this.pathInfo=c}}function _(t){let e;return X.get(t)??(X.set(t,e=new Z(t)),e)}function tt(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const s=n.pathInfo.indexByWildcardPath[e];return void 0===s||null===n.listIndex?null:p(n.listIndex,s,n.pathInfo.wildcardCount)}function et(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function nt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==q)return r}}return q}function st(t,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(U(i),o.pathInfo.segments);if(!(o.pathInfo.path in t)){if(null===o.parentAddress){const e=nt(i,o,null,l,r);if(e!==q)return e;u(n(o.pathInfo.path,t,i.getterPaths))}const e=at(t,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==s&&!(d in Object(e))){const t=nt(i,o,Object(e),l,r);if(t!==q)return t}if(d===s){const t=o.listIndex?.index??u(a(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(t,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(t,o.pathInfo.path,l)}finally{r.popAddress()}}function at(t,e,n,s){z(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==q)return l}}return et(a,e)?function(t,e,n,s,a){const o=g(a,e),l=y(o),r=a.stateGeneration;if(null!==l&&!1===l.dirty&&l.generation===r)return l.value;const i=st(t,e,n,s,a);return I(o,{value:i,dirty:!1,generation:r}),i}(t,e,n,s,a):st(t,e,n,s,a)}function ot(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const p=m(h,o),y=g(n.stateElement,p),I=x(y),w=at(t,p,e,n),v=P(o,I,w).newIndexes,A=i[d]??null;if(l.set(y,w),null===A)for(let t=0;t<v.length;t++){const e=v[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=v[A]??u(`ListIndex not found at index ${A} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())w(t,Array.isArray(e)?e:[]);return i}function lt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=at(t,m(r,o),e,n),d=v(i,o);null==d&&u(`ListIndexes not found: ${r.path}`);const c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function rt(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function it(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function dt(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];rt(i,n,s,r);const d=it(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function ct(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function ft(t,e,n,a){if(e.pathInfo.path in t)return!0;const o=e.parentAddress;if(null===o)return!1;const l=at(t,o,n,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=e.pathInfo.lastSegment;if(r===s){const t=e.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const ut=new WeakMap;function ht(t,e){null===e?ut.delete(t):ut.set(t,e)}function pt(e,n,s){const a=e.wildcardParentPaths[n],o=t(a),l=m(o,s),r=g(e.stateElement,l),i=x(r),d=e.stateProxy[A](l),c=P(l.listIndex,i,d);e.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return W.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,e.searchType);if(n===e.wildcardPaths.length-1)e.targetListIndexes.push(...f);else for(const t of f)pt(e,n+1,t)}const gt=[];function yt(t,e,n,s,a){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:a.newIndexes,movedRows:null}:0===a.addIndexSet.size&&0===a.changeIndexSet.size?0===a.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:gt,movedRows:null}:{fullRows:a.newIndexes,movedRows:null}:{fullRows:gt,movedRows:null}:{fullRows:a.addIndexSet,movedRows:a.changeIndexSet}}const It=[];function wt(e,n,s){const a=e.stateElement.indexDependentGetterPaths;if(!a||0===a.size)return It;let o=null;const r=n+l;for(const e of a){if(e!==n&&!e.startsWith(r))continue;const a=t(e);if(a.wildcardCount!==s.wildcardCount)return null;(o??=[]).push(a)}return o??It}function mt(e,n,a){const o=n.pathInfo.path,l=e.staticMap.get(o);if(l)for(const r of l){const l=t(r);if(e.listPathSet.has(o)&&l.lastSegment===s){const t=e.stateProxy[A](n),s=g(e.stateElement,n),i=x(s),d=P(n.listIndex,i,t);e.observedListValueByAbsAddress.set(s,Array.isArray(t)?t:[]);const c=yt(e,o,0,0,d);for(const t of c.fullRows){const n=m(l,t);e.result.add(n),a.push(n)}if(null!==c.movedRows){const t=wt(e,r,l);if(null===t)for(const t of c.movedRows){const n=m(l,t);e.result.add(n),a.push(n)}else if(t.length>0)for(const n of c.movedRows)for(const s of t){const t=m(s,n);e.result.add(t),a.push(t)}}}else{const t=m(l,n.listIndex);e.result.add(t),a.push(t)}}const r=e.dynamicMap.get(o);if(r)for(const s of r){const o=t(s),l=[];if(o.wildcardCount>0){const t=b(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=p(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};pt(a,t,s),l.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=p(n.listIndex,t-1,n.pathInfo.wildcardCount);l.push(e)}}else l.push(null);for(const t of l){const n=m(o,t);e.result.add(n),a.push(n)}}}function xt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null};!function(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),n(r),l.length=0,mt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}(f,e,r);for(const[t,e]of f.observedListValueByAbsAddress)w(t,e);return Array.from(f.result)}function Pt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function vt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function At(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function bt(t,e,n,s,a,o){const l=E(t,e),r=S(t,e);if(!l&&!r)return;const i=D(),d=W.enablePropagationContext?M()??null:null,c=t=>{k(t),i.enqueueAbsoluteAddress(t,d)};l&&j(t,e,n,s,a).forEach(c),r&&O(t,e,n?s:o(),a).forEach(c)}function $t(t,e,n,s,a,o,l="diff"){const r=W.enablePropagationContext?M()??L(-1):null,i=D();i.enqueueAbsoluteAddress(e,r),o&&k(e),xt(s.stateElement,t,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=g(s.stateElement,e);k(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:l,keyedMergePath:a})}function kt(t,e,n,s,a){a&&(t.getterPaths.has(e)?k(n):I(n,{value:s,dirty:!1,generation:t.stateGeneration}))}function Rt(t,e,n,o,l,r,i,d){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,o);const i=at(t,n,l,r),d=e.pathInfo.segments[e.pathInfo.segments.length-1];if(d===s){const t=e.listIndex?.index??u(a(`path "${e.pathInfo.path}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,o);r.pushAddress(e),r.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{$t(e,n,l,r,i,d)}}function Et(e,n,a,o,r,i,d,c){const f=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),h=at(e,f,r,i)??[];let p=(y=h,ut.get(y)??null);var y;if(null===p){const t=$(h)??[];p={value:[...h],listIndexes:[...t]},ht(h,p)}try{return Rt(e,n,a,o,r,i,d,c)}finally{const a=p.value.indexOf(o),d=at(e,f,r,i)??[],c=Array.isArray(d)?$(d)??[]:[],u=n.listIndex.index,y=-1!==a?p.listIndexes[a]:C(f.listIndex,-1);c[u]=y;if(new Set(d).size===p.value.length){for(let t=0;t<c.length;t++)c[t].index=t;ht(h,null),function(e,n,a,o,r,i){const d=i.stateElement,c=D(),f=g(d,e);T(f)===a&&(V(n.value,n.listIndexes),B(f,n.value),N(n.value));c.enqueueRenderOnlyAddress(f);const u=new Map;n.listIndexes.forEach((t,e)=>u.set(t,e));const h=t(e.pathInfo.path+l+s);for(let t=0;t<o.length;t++){const e=o[t],s=u.get(e);if(s===t)continue;const a=m(h,e),l=g(d,a);if(void 0===s){const e=H(d,h,n.listIndexes[t]??null);At(d,l,e),$t(a,l,r,i,null,et(d,a),"full");continue}xt(d,a,d.staticDependency,d.dynamicDependency,d.listPaths,r,"new",t=>{const e=g(d,t);k(e),c.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}}(f,p,d,c,r,i)}}}function St(e,n,a,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(a)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=at(e,n,o,r),c=function(t,e,n,s){const a=dt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=dt(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,a);if(null!==c)return function(e,n,a,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===$(o)&&P(c,null,o);const f=P(c,o,a.list),u=Mt(e,n,a.list,r,i,d),h=t(d+l+s);for(const n of a.matched){const s=ct(n.oldRow,n.newRow);if(0===s.length)continue;const a=f.newIndexes[n.position];for(const o of s){if(void 0===a){n.oldRow[o.field]=o.value;continue}const s=t(h.path+l+o.field);St(e,m(s,a),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return Mt(e,n,a,o,r,null)}function Mt(t,e,n,o,l,i){const d=l.stateElement,c=e.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let s=0;s<t.length;s++){const a=t[s](d,e,n,o,l);if(a!==q)return a}}const h=R();if(!(c in t)&&null!==e.parentAddress&&!d.elementPaths.has(c)){const p=at(t,e.parentAddress,o,l);if("object"==typeof p&&null!==p){const t=e.pathInfo.lastSegment,y=t===s?e.listIndex?.index:t;let I,w=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const t=void 0!==y&&y in p,e=void 0!==y?p[y]:void 0;if(t&&Object.is(e,n))return!0;I=e,w=!0}bt(d,c,w,I,n,()=>p[y]);const m=et(d,e),x=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:x,value:n,oldValue:I,hasOldValue:w}),Pt(d,c,x,I,w);let P=!1;try{if(void 0===y&&u(a(`path "${c}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0)),f&&0!==f.writeMissing.length&&t!==s&&!(y in p)){const t=f.writeMissing;for(let s=0;s<t.length;s++){P=!0;const a=t[s](d,e,p,y,n,o,l);if(a!==q)return a;P=!1}}return Reflect.set(p,y,n)}finally{$t(e,x,o,l,i,m),P?k(x):kt(d,c,x,n,m),vt(d,e.pathInfo,{value:n})}}}let p,y=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const s=at(t,e,o,l);if(ft(t,e,o,l)&&Object.is(s,n))return!0;p=s,y=!0}bt(d,c,y,p,n,()=>at(t,e,o,l));const I=d.elementPaths.has(e.pathInfo.path),w=et(d,e),m=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:m,value:n,oldValue:p,hasOldValue:y}),Pt(d,c,m,p,y);try{return I?Et(t,e,m,n,o,l,i,w):Rt(t,e,m,n,o,l,i,w)}finally{I||kt(d,c,m,n,w),vt(d,e.pathInfo,{value:n})}}function jt(e,n,s,a){return(n,o,...l)=>{const r=t(n);if(a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",n,r.wildcardParentPathInfos.length,o.length));const d=lt(e,s,a,r,o),c=m(r,d);if(0===l.length)return at(e,c,s,a);Q(a),St(e,c,l[0],s,a)}}function Ot(e,n,s,a){const o=jt(e,0,s,a);return(n,l)=>{const r=t(n);if(void 0===l||Array.isArray(l)||u(`$getAll("${n}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",n,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=tt(a,r.wildcardPaths[t]);if(e){l=G(e,e.length);break}}if(void 0===l){const t=a.addressStackLength>0?a.lastAddressStack:null,e=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==e&&e.length>0&&u(d(n,t.pathInfo.path)),l=[]}}const c=ot(e,s,a,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function Lt(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return tt(s,a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`))??u(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=at(t,m(l,a),n,s),i=v(r,a)??u(`ListIndex not found: ${l.path}`),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function Ct(e,n,s,a){return(n,o,l,r)=>{Q(a);const d=t(n);Array.isArray(o)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),o.length>d.wildcardParentPathInfos.length&&u(i("$setAll",n,d.wildcardParentPathInfos.length,o.length));const h=!0===r?.spread,p="function"==typeof l;h&&p&&u(c(n,"cannot combine { spread: true } with a mapper function.")),h&&!Array.isArray(l)&&u(c(n,"requires an array as the value when { spread: true } is set."));const g=ot(e,s,a,d,o,{commitDiffBaseline:!1});h&&l.length!==g.length&&u(f(n,g.length,l.length));const y=[];for(let t=0;t<g.length;t++){const n=lt(e,s,a,d,g[t]);y.push(m(d,n))}let I=0;for(let t=0;t<y.length;t++){const n=y[t];let o;if(p){o=l(at(e,n,s,a),...g[t])}else o=h?l[t]:l;void 0!==o&&(St(e,n,o,s,a),I++)}return I}}export{Q as a,Ot as b,Ct as c,_ as d,Lt as e,U as f,at as g,ft as h,Y as i,jt as r,St as s,xt as w};
2
2
  //# sourceMappingURL=setAll.js.map
@@ -1,2 +1,2 @@
1
- const o="3.0.0";export{o as V};
1
+ const o="3.2.0";export{o as V};
2
2
  //# sourceMappingURL=version.js.map
@@ -1,2 +1,2 @@
1
- import{E as t,F as e,k as n,G as o,H as r,I as s,x as a,c as i,f as c,e as u,J as f}from"./binder.js";import{S as l,o as d,k as h,g as p,M as w,p as y,q as m}from"./pathDiagnostics.js";import{a as g,r as v}from"./getAllPropertyDescriptors.js";import{i as b}from"./filterRegistry.js";import{r as $,L as x}from"./errorGuidance.js";const I=new WeakMap,P=new Set,j=new Set;function k(t){return t.byFromPath.size>0||t.byResetPath.size>0}function O(t,e,n){const o=t.get(e);void 0===o?t.set(e,[n]):o.push(n)}function M(t,e){E(t);const n=new Map,o=new Map,r=new Map;for(const t of e){"path"===t.source.kind&&O(n,t.source.path,t);for(const e of t.resetOn)O(o,e,t),"event"===t.source.kind&&O(r,e,t)}const s={entries:new Set(e),byFromPath:n,byResetPath:o,eventResetByPath:r};return I.set(t,s),s}function A(t){return I.get(t)}function E(t){S(t),I.delete(t)}function S(t){P.delete(t),j.delete(t)}const z=new WeakSet;let C=0;function W(t){return A(t.absolutePathInfo.stateElement)?.eventResetByPath.get(t.absolutePathInfo.pathInfo.path)}function R(t){if(0===j.size)return;if(e=t.absolutePathInfo.stateElement,!j.has(e))return;var e;const n=W(t);if(void 0!==n)for(const t of n)F(t)}function F(t){z.has(t)||(z.add(t),C++)}function D(t){return z.has(t)}function _(t){return!!z.delete(t)&&(C--,!0)}const B=/^(?:0|[1-9]\d*)$/;function G(t,e){const n=Object.getOwnPropertyDescriptor(t,e);return!0===n.enumerable&&"value"in n}function T(t){if("object"!=typeof t||null===t||Object.isFrozen(t))return null;const e=Object.getPrototypeOf(t);if(Array.isArray(t)){return e===Array.prototype&&Reflect.ownKeys(t).every(e=>"length"===e||"string"==typeof e&&B.test(e)&&G(t,e))?"array":null}return(e===Object.prototype||null===e)&&Reflect.ownKeys(t).every(e=>"string"==typeof e&&G(t,e))?"object":null}function q(t,e){const n=T(t);if(null===n)return t;const o=t,r=e.get(o);if(void 0!==r)return r;let s;s="array"===n?new Array(t.length):null===Object.getPrototypeOf(t)?Object.create(null):{},e.set(o,s);for(const t of Object.keys(o))s[t]=q(o[t],e);return s}function H(t){return q(t,new Map)}function K(t,e,n){if(Object.is(t,e))return!0;const o=T(e);if(null===o||"object"!=typeof t||null===t)return!1;const r=t,s=e;if("array"===o){if(!Array.isArray(t)||t.length!==e.length)return!1}else if(Array.isArray(t)||Object.keys(r).length!==Object.keys(s).length)return!1;if(T(t)!==o)return!1;let a=n.get(r);if(void 0===a)a=new Set,n.set(r,a);else if(a.has(s))return!0;if(a.add(s),"array"===o){for(let e=0;e<t.length;e++)if(!K(r[e],s[e],n))return!1;return!0}return Object.keys(s).every(t=>Object.prototype.hasOwnProperty.call(r,t)&&K(r[t],s[t],n))}function L(t,e){return K(t,e,new Map)}const N=new WeakMap;function J(t,e){if("function"!=typeof e)return;const n=N.get(e);void 0===n?N.set(e,new Set([t])):n.add(t)}function Q(t,e){return"function"==typeof e&&!0===N.get(e)?.has(t)}const U={"read-source":t=>`${l} could not read a "from" value for "${t}". That landing was not folded; the other landings of the batch still were.`,"read-output":t=>`${l} could not read the output "${t}". Nothing was folded or written.`,threw:t=>`${l} fold for "${t}" threw. The output was not written.`,"returned-promise":t=>`${l} fold for "${t}" returned a Promise. fold must be synchronous and return the next value; the output was not written.`,write:t=>`${l} could not write the output "${t}".`},V={"read-source":"evaluate","read-output":"evaluate",threw:"fold","returned-promise":"fold",write:"write"};function X(t,e,n){null!==d&&d({type:"state:watch-error",phase:e,path:`${l}.${t}`,error:n})}function Y(t,e,n){console.error(`[@wcstack/state] ${U[n](t)}`,e),X(t,V[n],e)}function Z(t){return null!==t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function tt(t,e){e.then(void 0,()=>{}),Y(t,new TypeError(`${l} fold for "${t}" returned a Promise. fold must be synchronous and return the next value.`),"returned-promise")}const et=new WeakSet;const nt=Symbol("wcs-stream-last-notified-uncertain"),ot=new WeakMap;function rt(t,e){return ot.get(t)?.get(e)??{status:"idle",error:null}}function st(t,e,n,o){let r=ot.get(t);void 0===r&&(r=new Map,ot.set(t,r)),r.set(e,{status:n,error:o})}function at(t,e){const n=ot.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function it(t,e){const n=ot.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:nt,error:Object.is(o.error,null)?null:nt})}const ct=new Set;function ut(t){ct.add(t)}function ft(t){ct.delete(t)}function lt(){return ct}const dt=new WeakMap;function ht(t,e){dt.set(t,e)}function pt(t){return dt.get(t)??new Map}function wt(t){ft(t);const e=dt.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,it(t,n.name)}function yt(t){wt(t),ft(t),dt.delete(t)}let mt=0,gt=0;function vt(t){mt=t+1}function bt(){mt=0}function $t(){mt>gt&&(gt=mt)}const xt=new WeakMap;function It(t,e,n){let o=xt.get(t);void 0===o&&(o=new Map,xt.set(t,o)),o.set(e,n)}const Pt=new Map;function jt(t,e){Pt.has(t)||Pt.set(t,e)}function kt(t){return Pt.get(t)}const Ot=new WeakMap,Mt=new WeakMap,At=new Set,Et=new Map;function St(t){return Ot.get(t)??Et}function zt(t){At.add(t),function(t){const e=I.get(t);void 0!==e&&(k(e)&&P.add(t),function(t){return t.eventResetByPath.size>0}(e)&&j.add(t))}(t)}function Ct(){return At}function Wt(t,e){let n=Mt.get(t);void 0===n&&(n=new Map,Mt.set(t,n));for(const t of e){const e=n.get(t.path);void 0===e?n.set(t.path,[t]):e.push(t)}}const Rt=new Map;function Ft(t){return Mt.get(t)??Rt}function Dt(t){0===t.length&&$(`[wcs/watch-declaration-invalid] ${h} entry name must be a non-empty state path.`),t.startsWith("$")&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not start with "$" (reserved namespace).${x}`),t.includes("@")&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not contain "@" — the name selector was removed in v2; watch only paths of the state tree.${x}`),t in Object.prototype&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const e=p(t);for(const n of e.segments)0===n.length&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" has an empty path segment.${x}`);return e.wildcardCount>w&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" exceeds the maximum wildcard depth (${w}).`),e}function _t(t,e){const n=e[h];if(void 0===n)return null;"object"==typeof n&&null!==n||$(`[wcs/watch-declaration-invalid] ${h} must be an object mapping state paths to handler functions.${x}`);const o=new Map,r=new Set;let s=0;for(const[e,a]of Object.entries(n)){"function"!=typeof a&&$(`[wcs/watch-declaration-invalid] ${h} entry "${e}" must be a function.${x}`);const n=Dt(e);o.set(e,{path:e,pathInfo:n,handler:a,order:s++}),r.add(e),t.setPathInfo(e,"prop","watch")}return function(t,e){Ot.set(t,e)}(t,o),r.size>0?r:null}const Bt={writeObserve(t,e,n,o,r){if(!r)return;const s=t.watchPaths,a=t.scanPaths;!0!==s?.has(e)&&!0!==a?.has(e)||jt(n,o)},swapped(t,e,n){var o;o=n,Pt.has(o)&&jt(e,kt(n))}};function Gt(e){for(let n=e;null!==n;n=n.parentListIndex)if(t(n))return!0;return!1}function Tt(a,i,c){const u=c.absAddress.listIndex;let f="current",l=null;for(let d=0;d<i.wildcardCount;d++){const h=a[e](n(i.wildcardParentPathInfos[d],l)),p=o(h)?.[c.indexes[d]];if(void 0===p)return"gone";const w=r(u,d,i.wildcardCount);if(p!==w&&!s(p,w)){if(t(w))return"gone";f="replaced"}l=p}return f}function qt(t,e,n){const o=new Map;for(const r of n){const n=Tt(t,e,r);if("gone"===n)continue;const s="current"===n?1:0,a=r.indexes.join(","),i=o.get(a);(void 0===i||s>i.rank)&&o.set(a,{row:r,rank:s})}return Array.from(o.values(),t=>t.row)}const Ht=Object.freeze([]);function Kt(t,e,n){let o=t.get(n);return void 0===o&&(o={stateElement:e,entry:n,rows:[],reset:!1},t.set(n,o)),o}function Lt(t,e){let n=0;for(;n<t.indexes.length-1&&t.indexes[n]===e.indexes[n];)n++;return t.indexes[n]-e.indexes[n]}function Nt(t,e){return e.has(t.stateElement)&&!0===A(t.stateElement)?.entries.has(t.entry)}function Jt(t){const{entry:e,stateElement:n}=t;"event"!==e.source.kind||e.resetOn.some(t=>Qt(n,t))||_(e)}function Qt(t,e){return i().hasQueuedPath(t,e)}function Ut(t,e){!function(t,e,n){if(0!==C)for(const o of t){const t=o.absolutePathInfo.stateElement;if(!0===e?.has(t))continue;const r=W(o);if(void 0!==r)for(const e of r)e.resetOn.some(e=>n(t,e))||_(e)}}(t,e,Qt)}function Vt(t,e,n){return 0===e.pathInfo.wildcardCount?t[e.path]:t.$resolve(e.path,n.indexes)}function Xt(t,e,n){if(!Nt(t,n))return Jt(t),null;const{stateElement:o,entry:r}=t;if(t.reset)return{group:t,next:r.initial};const s=r.source;if(function(t,e){for(const n of e.pathInfo.cumulativePaths)if(t.getterPaths.has(n))return!0;return!1}(o,s))return function(t,e,n){if(et.has(t))return;et.add(t);const o=`[wcs/scan-source-computed] ${l} entry "${e}" from "${n}" is now backed by a getter (registered after the declaration, e.g. by a volume). A getter re-evaluates whenever its inputs change, so this scan stopped folding. Fold the plain value the getter reads instead.`;console.error(`[@wcstack/state] ${o}`),X(e,"fold",new Error(o))}(r,r.name,s.path),null;if(function(t,e,n){const o=pt(t).get(e);if(void 0===o)return!1;for(const t of o.depAddresses)if(n.has(t))return!0;return!1}(o,s.pathInfo.segments[0],e))return null;const a={plan:null,failure:"read-output"};try{o.createState("readonly",e=>{const n=e[r.name],o=0===s.pathInfo.wildcardCount?t.rows:qt(e,s.pathInfo,t.rows);a.failure="threw";const i=r.fold;let c=n;for(const t of o.sort(Lt)){let n;try{n=Vt(e,s,t)}catch(t){Y(r.name,t,"read-source");continue}const o=i(c,n,kt(t.absAddress),...t.indexes);if(Z(o))return void tt(r.name,o);c=o}Object.is(c,n)||(a.plan={group:t,next:c})})}catch(t){Y(r.name,t,a.failure)}return a.plan}function Yt(t,e){const{group:n}=t;if(!Nt(n,e))return void Jt(n);const{stateElement:o,entry:r}=n;if(!n.reset||"event"!==r.source.kind||_(r))try{o.createState("writable",e=>{const o=e[r.name];if(n.reset?!L(o,r.initial):!Object.is(o,t.next)){const o=n.reset?H(r.initial):t.next;e[r.name]=o,J(r.name,o)}})}catch(t){Y(r.name,t,"write")}}function Zt(t,e,n){if(Ut(t,e),0===P.size)return Ht;const o=new Map;for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=A(t);if(void 0===r)continue;const s=n.absolutePathInfo.pathInfo,i=r.byFromPath.get(s.path);if(void 0!==i){let e=[];if(s.wildcardCount>0){if(null===n.listIndex)continue;e=a(n.listIndex,s.wildcardCount)}for(const r of i)Kt(o,t,r).rows.push({absAddress:n,indexes:e})}const c=r.byResetPath.get(s.path);if(void 0!==c)for(const e of c)Kt(o,t,e).reset=!0}if(0===o.size)return Ht;const r=Array.from(o.values()).sort((t,e)=>t.entry.order-e.entry.order),s=[];vt(n);try{for(const n of r){const o=Xt(n,t,e);null!==o&&s.push(o)}}finally{bt()}return s}function te(t){ue(),(0!==St(t).size||0!==Ft(t).size||function(t){const e=I.get(t);return void 0!==e&&k(e)}(t))&&(zt(t),function(t){const e=[];for(const n of St(t).values())ee(t,n)&&e.push(n);for(const n of Ft(t).values())for(const o of n)ee(t,o)&&e.push(o);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{It(t,f(t,o.pathInfo,null),n[o.path])}catch(e){oe(t,o.path,"prime",e)}})}(t))}function ee(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const ne={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function oe(t,e,n,o){console.error(`[@wcstack/state] $watch ${ne[n]} "${e}" threw.`,o),null!==d&&d({type:"state:watch-error",phase:n,path:e,error:o})}function re(t){const e=Ct();try{if(0===e.size)return void Ut(t,e);const n=function(){const t=gt;return gt=0,t}();if(n>m){Ut(t,null);const e=Array.from(t,t=>t.absolutePathInfo.pathInfo.path);return console.error("[@wcstack/state] $watch chain depth limit exceeded; $scan folds and $watch handlers for this batch were skipped.",{maxDepth:m,paths:e}),void(null!==d&&d({type:"state:watch-chain-limit",maxDepth:m,paths:e}))}!function(t,e,n){if(0!==t.length){vt(n);try{for(const n of t)Yt(n,e)}finally{bt()}}}(Zt(t,e,n),e,n),function(t,e,n){const o=[];for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=n.absolutePathInfo.pathInfo.path,s=St(t).get(r),i=Ft(t).get(r);if(void 0===s&&void 0===i)continue;const c=void 0===s?[]:[s];void 0!==i&&c.push(...i);for(const e of c){let r=[];if(e.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=a(n.listIndex,e.pathInfo.wildcardCount)}o.push({stateElement:t,entry:e,absAddress:n,indexes:r})}}if(0===o.length)return;o.sort(ae);const r=function(t){let e=null;for(let n=0;n<t.length;n++){const o=t[n];if(0===o.entry.pathInfo.wildcardCount)continue;const r=t[n-1];(Gt(o.absAddress.listIndex)||r?.entry===o.entry&&se(r.indexes,o.indexes))&&(e??=new Set).add(o.entry)}if(null===e)return t;const n=new Set;for(const o of e){const e=t.filter(t=>t.entry===o),r=e[0].stateElement;try{r.createState("readonly",t=>{const r=new Set(qt(t,o.pathInfo,e));for(const t of e)r.has(t)||n.add(t)})}catch(t){oe(0,o.path,"evaluate",t);for(const t of e)n.add(t)}}return t.filter(t=>!n.has(t))}(o);vt(n);try{for(const t of r){if(!e.has(t.stateElement))continue;const n=St(t.stateElement).get(t.entry.path)===t.entry,o=!0===Ft(t.stateElement).get(t.entry.path)?.includes(t.entry);(n||o)&&ie(t)}}finally{bt()}}(t,e,n)}finally{Pt.clear()}}function se(t,e){for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function ae(t,e){if(t.entry.order!==e.entry.order)return t.entry.order-e.entry.order;const n=Math.min(t.indexes.length,e.indexes.length);for(let o=0;o<n;o++)if(t.indexes[o]!==e.indexes[o])return t.indexes[o]-e.indexes[o];return t.indexes.length-e.indexes.length}function ie(t){const{stateElement:e,entry:n,absAddress:o,indexes:r}=t,s=ee(e,n);try{e.createState("writable",t=>{let a;try{a=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,n,r)}catch(t){return void oe(0,n.path,"evaluate",t)}const i=s?function(t,e){return xt.get(t)?.get(e)}(e,o):kt(o);s&&It(e,o,a),null!==d&&d({type:"state:watch-fired",path:n.path,stateElement:e}),n.handler.call(t,a,i,...r)})}catch(t){oe(0,n.path,"handler",t)}}let ce=!1;function ue(){ce||(ce=!0,g("watch",Bt),v("watch",fe),c(re,y),u($t))}const fe={order:10,register(t,e){var n;n=t,At.delete(n),S(n),Ot.delete(n),function(t){xt.delete(t)}(t);const o=_t(t,e);t.setWatchPaths?.(o),null===o&&null==t.scanPaths||t.attachAddressHooks?.("watch",null!==o?h:l)},activate(t,e){b()||null==t.connectedRootNode||(null===e?!0===t.initialized:e===t.connectGeneration)&&te(t)},deactivate(t){var e;e=t,At.delete(e),S(e)}};export{te as A,E as a,H as b,_ as c,Z as d,tt as e,Y as f,A as g,D as h,L as i,ht as j,pt as k,wt as l,F as m,R as n,yt as o,at as p,ut as q,J as r,M as s,lt as t,rt as u,st as v,Q as w,ue as x,Dt as y,Wt as z};
1
+ import{F as t,G as e,k as n,H as o,I as r,J as s,x as a,c as i,f as c,e as u,K as f}from"./binder.js";import{S as l,p as d,l as h,g as p,M as w,q as y,r as m}from"./pathDiagnostics.js";import{a as g,r as v}from"./getAllPropertyDescriptors.js";import{i as b}from"./filterRegistry.js";import{r as $,L as x}from"./errorGuidance.js";const I=new WeakMap,P=new Set,j=new Set;function k(t){return t.byFromPath.size>0||t.byResetPath.size>0}function O(t,e,n){const o=t.get(e);void 0===o?t.set(e,[n]):o.push(n)}function M(t,e){E(t);const n=new Map,o=new Map,r=new Map;for(const t of e){"path"===t.source.kind&&O(n,t.source.path,t);for(const e of t.resetOn)O(o,e,t),"event"===t.source.kind&&O(r,e,t)}const s={entries:new Set(e),byFromPath:n,byResetPath:o,eventResetByPath:r};return I.set(t,s),s}function A(t){return I.get(t)}function E(t){S(t),I.delete(t)}function S(t){P.delete(t),j.delete(t)}const z=new WeakSet;let C=0;function W(t){return A(t.absolutePathInfo.stateElement)?.eventResetByPath.get(t.absolutePathInfo.pathInfo.path)}function R(t){if(0===j.size)return;if(e=t.absolutePathInfo.stateElement,!j.has(e))return;var e;const n=W(t);if(void 0!==n)for(const t of n)F(t)}function F(t){z.has(t)||(z.add(t),C++)}function D(t){return z.has(t)}function _(t){return!!z.delete(t)&&(C--,!0)}const B=/^(?:0|[1-9]\d*)$/;function G(t,e){const n=Object.getOwnPropertyDescriptor(t,e);return!0===n.enumerable&&"value"in n}function K(t){if("object"!=typeof t||null===t||Object.isFrozen(t))return null;const e=Object.getPrototypeOf(t);if(Array.isArray(t)){return e===Array.prototype&&Reflect.ownKeys(t).every(e=>"length"===e||"string"==typeof e&&B.test(e)&&G(t,e))?"array":null}return(e===Object.prototype||null===e)&&Reflect.ownKeys(t).every(e=>"string"==typeof e&&G(t,e))?"object":null}function T(t,e){const n=K(t);if(null===n)return t;const o=t,r=e.get(o);if(void 0!==r)return r;let s;s="array"===n?new Array(t.length):null===Object.getPrototypeOf(t)?Object.create(null):{},e.set(o,s);for(const t of Object.keys(o))s[t]=T(o[t],e);return s}function q(t){return T(t,new Map)}function H(t,e,n){if(Object.is(t,e))return!0;const o=K(e);if(null===o||"object"!=typeof t||null===t)return!1;const r=t,s=e;if("array"===o){if(!Array.isArray(t)||t.length!==e.length)return!1}else if(Array.isArray(t)||Object.keys(r).length!==Object.keys(s).length)return!1;if(K(t)!==o)return!1;let a=n.get(r);if(void 0===a)a=new Set,n.set(r,a);else if(a.has(s))return!0;if(a.add(s),"array"===o){for(let e=0;e<t.length;e++)if(!H(r[e],s[e],n))return!1;return!0}return Object.keys(s).every(t=>Object.prototype.hasOwnProperty.call(r,t)&&H(r[t],s[t],n))}function L(t,e){return H(t,e,new Map)}const N=new WeakMap;function J(t,e){if("function"!=typeof e)return;const n=N.get(e);void 0===n?N.set(e,new Set([t])):n.add(t)}function Q(t,e){return"function"==typeof e&&!0===N.get(e)?.has(t)}const U={"read-source":t=>`${l} could not read a "from" value for "${t}". That landing was not folded; the other landings of the batch still were.`,"read-output":t=>`${l} could not read the output "${t}". Nothing was folded or written.`,threw:t=>`${l} fold for "${t}" threw. The output was not written.`,"returned-promise":t=>`${l} fold for "${t}" returned a Promise. fold must be synchronous and return the next value; the output was not written.`,write:t=>`${l} could not write the output "${t}".`},V={"read-source":"evaluate","read-output":"evaluate",threw:"fold","returned-promise":"fold",write:"write"};function X(t,e,n){null!==d&&d({type:"state:watch-error",phase:e,path:`${l}.${t}`,error:n})}function Y(t,e,n){console.error(`[@wcstack/state] ${U[n](t)}`,e),X(t,V[n],e)}function Z(t){return null!==t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function tt(t,e){e.then(void 0,()=>{}),Y(t,new TypeError(`${l} fold for "${t}" returned a Promise. fold must be synchronous and return the next value.`),"returned-promise")}const et=new WeakSet;const nt=Symbol("wcs-stream-last-notified-uncertain"),ot=new WeakMap;function rt(t,e){return ot.get(t)?.get(e)??{status:"idle",error:null}}function st(t,e,n,o){let r=ot.get(t);void 0===r&&(r=new Map,ot.set(t,r)),r.set(e,{status:n,error:o})}function at(t,e){const n=ot.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function it(t,e){const n=ot.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:nt,error:Object.is(o.error,null)?null:nt})}const ct=new Set;function ut(t){ct.add(t)}function ft(t){ct.delete(t)}function lt(){return ct}const dt=new WeakMap;function ht(t,e){dt.set(t,e)}function pt(t){return dt.get(t)??new Map}function wt(t){ft(t);const e=dt.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,it(t,n.name)}function yt(t){wt(t),ft(t),dt.delete(t)}let mt=0,gt=0;function vt(t){mt=t+1}function bt(){mt=0}function $t(){mt>gt&&(gt=mt)}const xt=new WeakMap;function It(t,e,n){let o=xt.get(t);void 0===o&&(o=new Map,xt.set(t,o)),o.set(e,n)}const Pt=new Map;function jt(t,e){Pt.has(t)||Pt.set(t,e)}function kt(t){return Pt.get(t)}const Ot=new WeakMap,Mt=new WeakMap,At=new Set,Et=new Map;function St(t){return Ot.get(t)??Et}function zt(t){At.add(t),function(t){const e=I.get(t);void 0!==e&&(k(e)&&P.add(t),function(t){return t.eventResetByPath.size>0}(e)&&j.add(t))}(t)}function Ct(){return At}function Wt(t,e){let n=Mt.get(t);void 0===n&&(n=new Map,Mt.set(t,n));for(const t of e){const e=n.get(t.path);void 0===e?n.set(t.path,[t]):e.push(t)}}const Rt=new Map;function Ft(t){return Mt.get(t)??Rt}function Dt(t){0===t.length&&$(`[wcs/watch-declaration-invalid] ${h} entry name must be a non-empty state path.`),t.startsWith("$")&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not start with "$" (reserved namespace).${x}`),t.includes("@")&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not contain "@" — the name selector was removed in v2; watch only paths of the state tree.${x}`),t in Object.prototype&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const e=p(t);for(const n of e.segments)0===n.length&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" has an empty path segment.${x}`);return e.wildcardCount>w&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" exceeds the maximum wildcard depth (${w}).`),e}function _t(t,e){const n=e[h];if(void 0===n)return null;"object"==typeof n&&null!==n||$(`[wcs/watch-declaration-invalid] ${h} must be an object mapping state paths to handler functions.${x}`);const o=new Map,r=new Set;let s=0;for(const[e,a]of Object.entries(n)){"function"!=typeof a&&$(`[wcs/watch-declaration-invalid] ${h} entry "${e}" must be a function.${x}`);const n=Dt(e);o.set(e,{path:e,pathInfo:n,handler:a,order:s++}),r.add(e),t.setPathInfo(e,"prop","watch")}return function(t,e){Ot.set(t,e)}(t,o),r.size>0?r:null}const Bt={writeObserve(t,e,n,o,r){if(!r)return;const s=t.watchPaths,a=t.scanPaths;!0!==s?.has(e)&&!0!==a?.has(e)||jt(n,o)},swapped(t,e,n){var o;o=n,Pt.has(o)&&jt(e,kt(n))}};function Gt(e){for(let n=e;null!==n;n=n.parentListIndex)if(t(n))return!0;return!1}function Kt(a,i,c){const u=c.absAddress.listIndex;let f="current",l=null;for(let d=0;d<i.wildcardCount;d++){const h=a[e](n(i.wildcardParentPathInfos[d],l)),p=o(h)?.[c.indexes[d]];if(void 0===p)return"gone";const w=r(u,d,i.wildcardCount);if(p!==w&&!s(p,w)){if(t(w))return"gone";f="replaced"}l=p}return f}function Tt(t,e,n){const o=new Map;for(const r of n){const n=Kt(t,e,r);if("gone"===n)continue;const s="current"===n?1:0,a=r.indexes.join(","),i=o.get(a);(void 0===i||s>i.rank)&&o.set(a,{row:r,rank:s})}return Array.from(o.values(),t=>t.row)}const qt=Object.freeze([]);function Ht(t,e,n){let o=t.get(n);return void 0===o&&(o={stateElement:e,entry:n,rows:[],reset:!1},t.set(n,o)),o}function Lt(t,e){let n=0;for(;n<t.indexes.length-1&&t.indexes[n]===e.indexes[n];)n++;return t.indexes[n]-e.indexes[n]}function Nt(t,e){return e.has(t.stateElement)&&!0===A(t.stateElement)?.entries.has(t.entry)}function Jt(t){const{entry:e,stateElement:n}=t;"event"!==e.source.kind||e.resetOn.some(t=>Qt(n,t))||_(e)}function Qt(t,e){return i().hasQueuedPath(t,e)}function Ut(t,e){!function(t,e,n){if(0!==C)for(const o of t){const t=o.absolutePathInfo.stateElement;if(!0===e?.has(t))continue;const r=W(o);if(void 0!==r)for(const e of r)e.resetOn.some(e=>n(t,e))||_(e)}}(t,e,Qt)}function Vt(t,e,n){return 0===e.pathInfo.wildcardCount?t[e.path]:t.$resolve(e.path,n.indexes)}function Xt(t,e,n){if(!Nt(t,n))return Jt(t),null;const{stateElement:o,entry:r}=t;if(t.reset)return{group:t,next:r.initial};const s=r.source;if(function(t,e){for(const n of e.pathInfo.cumulativePaths)if(t.getterPaths.has(n))return!0;return!1}(o,s))return function(t,e,n){if(et.has(t))return;et.add(t);const o=`[wcs/scan-source-computed] ${l} entry "${e}" from "${n}" is now backed by a getter (registered after the declaration, e.g. by a volume). A getter re-evaluates whenever its inputs change, so this scan stopped folding. Fold the plain value the getter reads instead.`;console.error(`[@wcstack/state] ${o}`),X(e,"fold",new Error(o))}(r,r.name,s.path),null;if(function(t,e,n){const o=pt(t).get(e);if(void 0===o)return!1;for(const t of o.depAddresses)if(n.has(t))return!0;return!1}(o,s.pathInfo.segments[0],e))return null;const a={plan:null,failure:"read-output"};try{o.createState("readonly",e=>{const n=e[r.name],o=0===s.pathInfo.wildcardCount?t.rows:Tt(e,s.pathInfo,t.rows);a.failure="threw";const i=r.fold;let c=n;for(const t of o.sort(Lt)){let n;try{n=Vt(e,s,t)}catch(t){Y(r.name,t,"read-source");continue}const o=i(c,n,kt(t.absAddress),...t.indexes);if(Z(o))return void tt(r.name,o);c=o}Object.is(c,n)||(a.plan={group:t,next:c})})}catch(t){Y(r.name,t,a.failure)}return a.plan}function Yt(t,e){const{group:n}=t;if(!Nt(n,e))return void Jt(n);const{stateElement:o,entry:r}=n;if(!n.reset||"event"!==r.source.kind||_(r))try{o.createState("writable",e=>{const o=e[r.name];if(n.reset?!L(o,r.initial):!Object.is(o,t.next)){const o=n.reset?q(r.initial):t.next;e[r.name]=o,J(r.name,o)}})}catch(t){Y(r.name,t,"write")}}function Zt(t,e,n){if(Ut(t,e),0===P.size)return qt;const o=new Map;for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=A(t);if(void 0===r)continue;const s=n.absolutePathInfo.pathInfo,i=r.byFromPath.get(s.path);if(void 0!==i){let e=[];if(s.wildcardCount>0){if(null===n.listIndex)continue;e=a(n.listIndex,s.wildcardCount)}for(const r of i)Ht(o,t,r).rows.push({absAddress:n,indexes:e})}const c=r.byResetPath.get(s.path);if(void 0!==c)for(const e of c)Ht(o,t,e).reset=!0}if(0===o.size)return qt;const r=Array.from(o.values()).sort((t,e)=>t.entry.order-e.entry.order),s=[];vt(n);try{for(const n of r){const o=Xt(n,t,e);null!==o&&s.push(o)}}finally{bt()}return s}function te(t){ue(),(0!==St(t).size||0!==Ft(t).size||function(t){const e=I.get(t);return void 0!==e&&k(e)}(t))&&(zt(t),function(t){const e=[];for(const n of St(t).values())ee(t,n)&&e.push(n);for(const n of Ft(t).values())for(const o of n)ee(t,o)&&e.push(o);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{It(t,f(t,o.pathInfo,null),n[o.path])}catch(e){oe(t,o.path,"prime",e)}})}(t))}function ee(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const ne={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function oe(t,e,n,o){console.error(`[@wcstack/state] $watch ${ne[n]} "${e}" threw.`,o),null!==d&&d({type:"state:watch-error",phase:n,path:e,error:o})}function re(t){const e=Ct();try{if(0===e.size)return void Ut(t,e);const n=function(){const t=gt;return gt=0,t}();if(n>m){Ut(t,null);const e=Array.from(t,t=>t.absolutePathInfo.pathInfo.path);return console.error("[@wcstack/state] $watch chain depth limit exceeded; $scan folds and $watch handlers for this batch were skipped.",{maxDepth:m,paths:e}),void(null!==d&&d({type:"state:watch-chain-limit",maxDepth:m,paths:e}))}!function(t,e,n){if(0!==t.length){vt(n);try{for(const n of t)Yt(n,e)}finally{bt()}}}(Zt(t,e,n),e,n),function(t,e,n){const o=[];for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=n.absolutePathInfo.pathInfo.path,s=St(t).get(r),i=Ft(t).get(r);if(void 0===s&&void 0===i)continue;const c=void 0===s?[]:[s];void 0!==i&&c.push(...i);for(const e of c){let r=[];if(e.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=a(n.listIndex,e.pathInfo.wildcardCount)}o.push({stateElement:t,entry:e,absAddress:n,indexes:r})}}if(0===o.length)return;o.sort(ae);const r=function(t){let e=null;for(let n=0;n<t.length;n++){const o=t[n];if(0===o.entry.pathInfo.wildcardCount)continue;const r=t[n-1];(Gt(o.absAddress.listIndex)||r?.entry===o.entry&&se(r.indexes,o.indexes))&&(e??=new Set).add(o.entry)}if(null===e)return t;const n=new Set;for(const o of e){const e=t.filter(t=>t.entry===o),r=e[0].stateElement;try{r.createState("readonly",t=>{const r=new Set(Tt(t,o.pathInfo,e));for(const t of e)r.has(t)||n.add(t)})}catch(t){oe(0,o.path,"evaluate",t);for(const t of e)n.add(t)}}return t.filter(t=>!n.has(t))}(o);vt(n);try{for(const t of r){if(!e.has(t.stateElement))continue;const n=St(t.stateElement).get(t.entry.path)===t.entry,o=!0===Ft(t.stateElement).get(t.entry.path)?.includes(t.entry);(n||o)&&ie(t)}}finally{bt()}}(t,e,n)}finally{Pt.clear()}}function se(t,e){for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function ae(t,e){if(t.entry.order!==e.entry.order)return t.entry.order-e.entry.order;const n=Math.min(t.indexes.length,e.indexes.length);for(let o=0;o<n;o++)if(t.indexes[o]!==e.indexes[o])return t.indexes[o]-e.indexes[o];return t.indexes.length-e.indexes.length}function ie(t){const{stateElement:e,entry:n,absAddress:o,indexes:r}=t,s=ee(e,n);try{e.createState("writable",t=>{let a;try{a=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,n,r)}catch(t){return void oe(0,n.path,"evaluate",t)}const i=s?function(t,e){return xt.get(t)?.get(e)}(e,o):kt(o);s&&It(e,o,a),null!==d&&d({type:"state:watch-fired",path:n.path,stateElement:e}),n.handler.call(t,a,i,...r)})}catch(t){oe(0,n.path,"handler",t)}}let ce=!1;function ue(){ce||(ce=!0,g("watch",Bt),v("watch",fe),c(re,y),u($t))}const fe={order:10,register(t,e){var n;n=t,At.delete(n),S(n),Ot.delete(n),function(t){xt.delete(t)}(t);const o=_t(t,e);t.setWatchPaths?.(o),null===o&&null==t.scanPaths||t.attachAddressHooks?.("watch",null!==o?h:l)},activate(t,e){b()||null==t.connectedRootNode||(null===e?!0===t.initialized:e===t.connectGeneration)&&te(t)},deactivate(t){var e;e=t,At.delete(e),S(e)}};export{te as A,E as a,q as b,_ as c,Z as d,tt as e,Y as f,A as g,D as h,L as i,ht as j,pt as k,wt as l,F as m,R as n,yt as o,at as p,ut as q,J as r,M as s,lt as t,rt as u,st as v,Q as w,ue as x,Dt as y,Wt as z};
2
2
  //# sourceMappingURL=watchRuntime.js.map
@@ -917,19 +917,23 @@ interface WcsStateApi {
917
917
  * 指定パスへの依存関係を明示的に登録する。
918
918
  * computed getter 内で動的にパスを組み立てる場合に使用。
919
919
  */
920
- $trackDependency(path: string): void;
920
+ $dependOn(path: string): void;
921
921
  /**
922
922
  * コールバック実行中の依存追跡(動的依存・`$1` インデックス依存の登録)を
923
- * 抑止して fn を実行し、その戻り値を返す(`$trackDependency` と対称)。
923
+ * 抑止して fn を実行し、その戻り値を返す。
924
924
  * リスト行 getter が「行外の単一値」を読みたいが、その値の変更で全行を
925
925
  * 再評価させたくない場合に使う(該当行へ直接書き込む設計と組で用いる)。
926
926
  */
927
+ $untracked<T>(fn: () => T): T;
928
+ /** @deprecated `$dependOn` の旧名(3.x の間は動き、4.0 で外れる — 要件 B12) */
929
+ $trackDependency(path: string): void;
930
+ /** @deprecated `$untracked` の旧名(3.x の間は動き、4.0 で外れる — 要件 B12) */
927
931
  $untrackDependency<T>(fn: () => T): T;
928
932
  /**
929
933
  * 鍵付き購読: `path` の現在値が `key` に等しいかを返し、評価中のリスト行 getter を
930
934
  * その鍵で購読する。`path` への書き込みは旧値・新値の鍵の行だけを再評価する
931
935
  * (パターン依存なら全行)。`path` 自体は依存として追跡しない。
932
- * 例: `get "items.*.selected"() { return this.$eq("selectedId", this.$untrackDependency(() => this["items.*.id"])); }`
936
+ * 例: `get "items.*.selected"() { return this.$eq("selectedId", this.$untracked(() => this["items.*.id"])); }`
933
937
  */
934
938
  $eq(path: string, key: unknown): boolean;
935
939
  /**
@@ -954,9 +958,9 @@ interface WcsStateApi {
954
958
  readonly $command: Record<string, {
955
959
  emit(...args: any[]): any;
956
960
  }>;
957
- /** `$streams` 各エントリの状態("idle" | "active" | "done" | "error")を返す読み取り専用名前空間 */
961
+ /** `$stream` 各エントリの状態("idle" | "active" | "done" | "error")を返す読み取り専用名前空間 */
958
962
  readonly $streamStatus: Record<string, "idle" | "active" | "done" | "error">;
959
- /** `$streams` 各エントリの直近エラーを返す読み取り専用名前空間 */
963
+ /** `$stream` 各エントリの直近エラーを返す読み取り専用名前空間 */
960
964
  readonly $streamError: Record<string, unknown>;
961
965
  readonly [key: `$streamStatus.${string}`]: "idle" | "active" | "done" | "error";
962
966
  readonly [key: `$streamError.${string}`]: unknown;
@@ -1055,8 +1059,8 @@ type WcsThis<T> = T & WcsStateApi & WcsPathAccessor<T>;
1055
1059
  * $disconnectedCallback() {
1056
1060
  * // cleanup
1057
1061
  * },
1058
- * $updatedCallback() {
1059
- * // called after DOM update
1062
+ * $renderedCallback() {
1063
+ * // called after the bindings are applied (old name: $updatedCallback)
1060
1064
  * }
1061
1065
  * });
1062
1066
  * ```
@@ -1,2 +1,2 @@
1
- import{s as t}from"./chunks/filterRegistry.js";export{g as getConfig}from"./chunks/filterRegistry.js";import{r as n}from"./chunks/binder.js";export{T as TRUSTED_TYPES_POLICY_SLOT,b as buildBindings,g as getBindingsReady,a as getTrustedTypesPolicy,s as setTrustedTypesPolicy}from"./chunks/binder.js";import{r as o}from"./chunks/registerComponents.js";export{V as VERSION}from"./chunks/version.js";import"./chunks/errorGuidance.js";import"./chunks/pathDiagnostics.js";import"./chunks/lifecycleHooks.js";import"./chunks/setAll.js";import"./chunks/getAllPropertyDescriptors.js";import"./chunks/checkDependency.js";import"./chunks/diagnosticsHooks.js";function e(s){if("string"==typeof s?.locale)return s;const t=function(){const s=document.documentElement?.lang;if(s)try{return Intl.getCanonicalLocales(s),s}catch{return void console.warn(`[@wcstack/state] <html lang="${s}"> is not a valid BCP-47 language tag. Falling back to the default locale for filters.`)}}();return void 0===t?s:{...s,locale:t}}function r(s,r){const i=e(s);i&&t(i),o(r),n()}function i(s){for(let t=0;t<s.length;t++)s[t].install()}function c(s){return s}export{r as bootstrapState,c as defineState,i as installFeatures};
1
+ import{s as t}from"./chunks/filterRegistry.js";export{g as getConfig}from"./chunks/filterRegistry.js";import{r as n}from"./chunks/binder.js";export{T as TRUSTED_TYPES_POLICY_SLOT,b as buildBindings,g as getBindingsReady,a as getTrustedTypesPolicy,s as setTrustedTypesPolicy}from"./chunks/binder.js";import{r as o}from"./chunks/registerComponents.js";export{V as VERSION}from"./chunks/version.js";import"./chunks/errorGuidance.js";import"./chunks/pathDiagnostics.js";import"./chunks/lifecycleHooks.js";import"./chunks/declarationAliases.js";import"./chunks/setAll.js";import"./chunks/getAllPropertyDescriptors.js";import"./chunks/checkDependency.js";import"./chunks/diagnosticsHooks.js";function e(s){if("string"==typeof s?.locale)return s;const t=function(){const s=document.documentElement?.lang;if(s)try{return Intl.getCanonicalLocales(s),s}catch{return void console.warn(`[@wcstack/state] <html lang="${s}"> is not a valid BCP-47 language tag. Falling back to the default locale for filters.`)}}();return void 0===t?s:{...s,locale:t}}function r(s,r){const i=e(s);i&&t(i),o(r),n()}function i(s){for(let t=0;t<s.length;t++)s[t].install()}function c(s){return s}export{r as bootstrapState,c as defineState,i as installFeatures};
2
2
  //# sourceMappingURL=core.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sources":["../../../../src/core/bootstrapCore.ts","../../../../src/core/features.ts","../../../../src/defineState.ts"],"sourcesContent":["/**\n * core/bootstrapCore.ts — 機能を 1 つも入れない bootstrap(設計案 §4、`@wcstack/state/core`)。\n *\n * 設定の解決・タグの登録・binder プロトコルの提供だけを行う。機能の install は\n * `installFeatures([...])` の仕事で、full / auto の `bootstrapState()` が全部入れてから\n * これを呼ぶ(従来と同じ順序 — install は要素の定義より前)。\n */\nimport { setConfig } from \"../config\";\nimport { registerBinder } from \"../bindings/binder\";\nimport { registerComponents } from \"../registerComponents\";\nimport { IWritableConfig } from \"../types\";\n\n/**\n * `<html lang>` を既定ロケールとして採る。\n *\n * ロケール依存フィルタ(`locale` / `date` / `time` / `datetime`)は `config.locale`\n * を読むが、それを設定できる公開の入口は `bootstrapState({ locale })` しかない。\n * 一方 `auto` エントリは `bootstrapState()` を引数なしで呼ぶため、CDN 一発\n * (`<script src=\".../@wcstack/state/auto\">`)で読み込んだページには**ロケールを\n * 渡す口が無かった**。auto バンドルは SRI のため自己完結で、別途 `@wcstack/state`\n * を import して `bootstrapState` を呼んでも別インスタンスになり効かない。\n *\n * `<html lang>` はページのロケールを書く HTML 標準の場所であり、SSR ではサーバーが、\n * 静的ページでは head のスニペットが DOM 解析前に書く。そこを既定にすると\n * **ロケールの正本が 1 つになり**、「設定を早く呼ぶ」という守りにくい順序の約束が\n * 「`<html lang>` が state のロードより前にある」という構造的な保証に変わる。\n *\n * 明示指定(`bootstrapState({ locale })`)が常に優先する。\n */\nfunction localeFromDocument(): string | undefined {\n const lang = document.documentElement?.lang;\n if (!lang) {\n return undefined;\n }\n try {\n // 妥当な BCP-47 タグでなければ Intl が RangeError を投げる。不正な lang を\n // そのまま採ると、これまで既定 'en' で動いていたページのフィルタが実行時に\n // 落ちる。既定へ落として警告するほうが、黙って壊すより回復しやすい。\n Intl.getCanonicalLocales(lang);\n return lang;\n } catch {\n console.warn(\n `[@wcstack/state] <html lang=\"${lang}\"> is not a valid BCP-47 language tag. ` +\n `Falling back to the default locale for filters.`\n );\n return undefined;\n }\n}\n\nfunction resolveConfig(config?: IWritableConfig): IWritableConfig | undefined {\n if (typeof config?.locale === \"string\") {\n return config;\n }\n const locale = localeFromDocument();\n if (locale === undefined) {\n return config;\n }\n return { ...config, locale };\n}\n\nexport function bootstrapCore(config?: IWritableConfig, registry?: CustomElementRegistry): void {\n const resolved = resolveConfig(config);\n if (resolved) {\n setConfig(resolved);\n }\n registerComponents(registry);\n // binder プロトコルの提供(docs/binder-protocol-design.md)。router が後から\n // 差し込むノードをバインドできるようにする。登録は冪等。\n registerBinder();\n}\n","/**\n * core/features.ts — 分割エントリの install(設計案 §4、要件 D15)。\n *\n * 機能のエントリは「名前と install を持つ記述子」を export し、ページは要るものだけを入れる:\n *\n * ```js\n * import { bootstrapState, installFeatures } from \"@wcstack/state/core\";\n * import temporal from \"@wcstack/state/features/temporal\";\n * installFeatures([temporal]);\n * bootstrapState();\n * ```\n *\n * full(`@wcstack/state`)と `/auto` は `bootstrapState()` が全機能を入れるので、利用者から見た\n * 挙動は変わらない。\n *\n * **冪等は機能側の `install` が持つ**(どれも `installed` フラグで 2 回目を弾く)。ここで名前を\n * 覚えて重複を弾く手もあるが、同じことを 2 箇所で持つだけで、しかも「`bootstrapState()` を\n * 2 回呼ぶと 2 回目は機能の install に届かない」という観測できる差が増える。core は素直に並べた順に呼ぶ。\n */\nexport interface IStateFeature {\n /** 機能の名前(受け口のレジストリのキーと同じ。barrier の文言が使う) */\n readonly name: string;\n /** 受け口へこの機能の実装を置く。**冪等であること** — core は 2 回呼ぶことがある */\n install(): void;\n}\n\nexport function installFeatures(features: readonly IStateFeature[]): void {\n for (let i = 0; i < features.length; i++) {\n features[i].install();\n }\n}\n","/**\n * defineState.ts\n *\n * 状態オブジェクトに型付けを提供するためのユーティリティ。\n * defineState() はアイデンティティ関数で、ThisType<> を付与することで\n * メソッド・computed getter 内の this に型補完を提供する。\n *\n * テンプレートリテラル型によるドットパスの型解決:\n * - WcsPaths<T> : T から生成される全ドットパスの union\n * - WcsPathValue<T,P>: パス P に対応する値の型\n * - WcsPathAccessor<T>: ブラケットアクセス用マップ型\n */\n\n// ============================================================\n// Internal helper types\n// ============================================================\n\n/**\n * `any` 型を検出する。\n * `0 extends (1 & T)` は T が `any` の場合のみ true になる。\n */\ntype IsAny<T> = 0 extends (1 & T) ? true : false;\n\n/**\n * T がドットパス再帰の対象となる「プレーンなデータオブジェクト」かどうかを判定する。\n * プリミティブ、組み込みオブジェクト (Date, Map 等)、関数、配列、any は除外。\n */\ntype IsPlainObject<T> =\n IsAny<T> extends true ? false :\n T extends\n | string | number | boolean | null | undefined | symbol | bigint\n | ((...args: any[]) => any) | Date | RegExp | Error\n | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any>\n | Promise<any> | readonly any[]\n ? false\n : T extends Record<string, any>\n ? true\n : false;\n\n/**\n * T のキーのうち、関数でないもの(データプロパティ・computed getter)を抽出する。\n * メソッド(イベントハンドラ等)はドットパスの対象外。\n * `$` プレフィックスキー($streams / $commandTokens / $on 等の予約宣言)もドットパスにならない。\n * any 型のプロパティは除外せず保持する。\n */\ntype DataKeys<T> = {\n [K in keyof T & string]:\n K extends `$${string}` ? never :\n IsAny<T[K]> extends true ? K : T[K] extends (...args: any[]) => any ? never : K;\n}[keyof T & string];\n\n// ============================================================\n// WcsPaths — ドットパスの union 生成\n// ============================================================\n\n/**\n * 型 T から生成される全てのドットパスの union。\n * 配列プロパティはワイルドカード `*` を使用: `items.*.name`\n *\n * 再帰の深さは最大4レベルに制限(コンパイル性能の確保)。\n *\n * @example\n * ```ts\n * type S = {\n * count: number;\n * users: { name: string; age: number }[];\n * cart: { items: { price: number }[] };\n * };\n * type P = WcsPaths<S>;\n * // = \"count\" | \"users\" | \"users.*\" | \"users.*.name\" | \"users.*.age\"\n * // | \"cart\" | \"cart.items\" | \"cart.items.*\" | \"cart.items.*.price\"\n * ```\n */\nexport type WcsPaths<T, Depth extends readonly any[] = []> =\n Depth[\"length\"] extends 4 ? never :\n {\n [K in DataKeys<T>]:\n | K\n | (T[K] extends readonly (infer E)[]\n ? IsPlainObject<E> extends true\n ? `${K}.*` | WcsSubPaths<E, `${K}.*.`, [...Depth, 0]>\n : `${K}.*`\n : IsPlainObject<T[K]> extends true\n ? WcsSubPaths<T[K], `${K}.`, [...Depth, 0]>\n : never)\n }[DataKeys<T>];\n\n/** @internal プレフィックス付きサブパスの生成ヘルパー */\ntype WcsSubPaths<T, Prefix extends string, Depth extends readonly any[]> =\n WcsPaths<T, Depth> extends infer P extends string\n ? `${Prefix}${P}`\n : never;\n\n// ============================================================\n// WcsPathValue — パスから値の型を解決\n// ============================================================\n\n/**\n * ドットパス P に対応する値の型を T から解決する。\n *\n * 解決順序:\n * 1. T の直接キー(computed getter 含む)\n * 2. `K.*` → 配列要素型\n * 3. `K.rest` → オブジェクト/配列のネストを再帰的に辿る\n *\n * @example\n * ```ts\n * type S = { cart: { items: { price: number; qty: number }[] } };\n * type V1 = WcsPathValue<S, \"cart.items.*.price\">; // number\n * type V2 = WcsPathValue<S, \"cart.items.*\">; // { price: number; qty: number }\n * type V3 = WcsPathValue<S, \"cart\">; // { items: ... }\n * ```\n */\nexport type WcsPathValue<T, P extends string> =\n // 1. Direct key (includes computed getters like \"users.*.ageCategory\")\n P extends keyof T\n ? T[P]\n // 2. K.* → array element type\n : P extends `${infer K}.*`\n ? K extends keyof T\n ? T[K] extends readonly (infer E)[] ? E : never\n : never\n // 3. K.rest → recurse into nested structure\n : P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? T[K] extends readonly (infer E)[]\n // Array: expect *.subpath or *\n ? Rest extends `*.${infer SubRest}`\n ? WcsPathValue<E, SubRest>\n : Rest extends \"*\"\n ? E\n : never\n // Object: recurse\n : T[K] extends Record<string, any>\n ? WcsPathValue<T[K], Rest>\n : never\n : never\n : never;\n\n// ============================================================\n// WcsPathAccessor — ブラケットアクセス用マップ型\n// ============================================================\n\n/**\n * 全ドットパスに対する型付きブラケットアクセスを提供するマップ型。\n *\n * `this[\"users.*.name\"]` のようなアクセスに対して、\n * WcsPaths で生成されたパスに対応する値の型を返す。\n */\ntype WcsPathAccessor<T> = {\n [P in WcsPaths<T>]: WcsPathValue<T, P>;\n};\n\n// ============================================================\n// State Proxy API — this 経由でアクセスできるAPI\n// ============================================================\n\n/**\n * `<wcs-state>` の Proxy 経由で提供されるAPIメソッド。\n * state定義オブジェクト内のメソッド・getter で `this.` 経由で利用可能。\n */\nexport interface WcsStateApi {\n /**\n * ワイルドカードを含むパスにマッチする全要素を配列で取得する。\n *\n * @param path - ワイルドカードを含むパス\n * @param indexes - 各ワイルドカード階層のインデックス(前方一致の接頭辞。`[]` は全階層を展開)。\n * 省略時はループ文脈の添字(`[$1..$n]` 相当)のうち path と共有するワイルドカード連鎖の\n * 分が接頭辞として敷かれる(文脈が path より深い分は切り詰め)。共有が無いのに文脈が\n * 添字を持つ場合は throw する — 異なる文脈の添字は流用しない。\n *\n * @example\n * ```ts\n * get \"cart.totalPrice\"() {\n * return this.$getAll(\"cart.items.*.price\").reduce((sum, v) => sum + v, 0);\n * }\n * ```\n */\n $getAll<V = any>(path: string, indexes?: number[]): V[];\n\n /**\n * ワイルドカードを含むパスにマッチする**全アドレスへ一括で書き込む**(`$getAll` の対称形)。\n *\n * 配列を作り直さずに一括更新するための API。`this.users = this.users.map(...)` は\n * ListIndex・行 getter キャッシュ・差分描画をまとめて作り直すが、`$setAll` は\n * in-place な個別書き込みに分解するのでリストの同一性が保たれる。\n *\n * - `indexes` は `$getAll` と同じ**前方一致の接頭辞**(`[]` で全階層を展開)。省略は不可。\n * - 関数を渡すと **mapper**(`(current, ...indexes) => next`)として要素ごとに評価される。\n * - 配列は既定でブロードキャストされる。1 件ずつ配るには `{ spread: true }` を明示する。\n * - `undefined` を書こうとした要素はスキップされる(クリアは `null`)。\n *\n * @returns 実際に書き込んだ件数(`undefined` でスキップした分を含まない)\n *\n * @example\n * ```ts\n * toggleAll(e: Event) {\n * this.$setAll(\"users.*.selected\", [], (e.target as HTMLInputElement).checked);\n * }\n * invertAll() {\n * this.$setAll(\"users.*.selected\", [], cur => !cur);\n * }\n * ```\n */\n $setAll<V = any>(\n path: string,\n indexes: number[],\n value: V | ((current: V, ...indexes: number[]) => V | undefined),\n ): number;\n $setAll<V = any>(\n path: string,\n indexes: number[],\n values: readonly V[],\n options: { spread: true },\n ): number;\n\n /**\n * 指定パスの更新を手動でトリガーする。\n * Proxy の set トラップを経由せずに内部状態を変更した場合に使用。\n */\n $postUpdate(path: string): void;\n\n /**\n * パスとインデックス配列を指定して、ワイルドカードを解決した値を取得・設定する。\n *\n * @param path - ワイルドカードを含むパス\n * @param indexes - 各ワイルドカード階層のインデックス\n * @param value - 設定する値(省略時は取得)\n */\n $resolve(path: string, indexes: number[], value?: any): any;\n\n /**\n * 指定パスへの依存関係を明示的に登録する。\n * computed getter 内で動的にパスを組み立てる場合に使用。\n */\n $trackDependency(path: string): void;\n\n /**\n * コールバック実行中の依存追跡(動的依存・`$1` インデックス依存の登録)を\n * 抑止して fn を実行し、その戻り値を返す(`$trackDependency` と対称)。\n * リスト行 getter が「行外の単一値」を読みたいが、その値の変更で全行を\n * 再評価させたくない場合に使う(該当行へ直接書き込む設計と組で用いる)。\n */\n $untrackDependency<T>(fn: () => T): T;\n\n /**\n * 鍵付き購読: `path` の現在値が `key` に等しいかを返し、評価中のリスト行 getter を\n * その鍵で購読する。`path` への書き込みは旧値・新値の鍵の行だけを再評価する\n * (パターン依存なら全行)。`path` 自体は依存として追跡しない。\n * 例: `get \"items.*.selected\"() { return this.$eq(\"selectedId\", this.$untrackDependency(() => this[\"items.*.id\"])); }`\n */\n $eq(path: string, key: unknown): boolean;\n\n /**\n * `$eq` の鍵を `keyPath`(ワイルドカードは評価中の行で解決)から依存を張らずに読む形。\n * 例: `get \"items.*.selected\"() { return this.$eqPath(\"selectedId\", \"items.*.id\"); }`\n */\n $eqPath(path: string, keyPath: string): boolean;\n\n /**\n * `$eq` の鍵を評価中の行の index(`$1` 相当。`level` でワイルドカード段を選ぶ)にする形。\n * getter を index 依存には記録せず、行の移動時はリスト差分が鍵を付け替えるので、\n * 1 行削除で再評価されるのは高々 2 行。\n * 例: `get \"items.*.selected\"() { return this.$eqIndex(\"selectedIndex\"); }`\n */\n $eqIndex(path: string, level?: number): boolean;\n\n /** `<wcs-state>` 要素への参照 */\n readonly $stateElement: HTMLElement;\n\n /**\n * `$commandTokens` で宣言した command token の名前空間。\n * `this.$command.<name>` で token を解決できる(バインディングでは\n * `onclick: $command.<name>` / `command.<method>: $command.<name>`)。\n */\n readonly $command: Record<string, { emit(...args: any[]): any }>;\n\n /** `$streams` 各エントリの状態(\"idle\" | \"active\" | \"done\" | \"error\")を返す読み取り専用名前空間 */\n readonly $streamStatus: Record<string, \"idle\" | \"active\" | \"done\" | \"error\">;\n\n /** `$streams` 各エントリの直近エラーを返す読み取り専用名前空間 */\n readonly $streamError: Record<string, unknown>;\n\n // computed getter 内での依存追跡付き読み取りの正規形は dotted パス\n // (`this[\"$streamStatus.<name>\"]` — docs/state-streams-design.md §4-3)\n readonly [key: `$streamStatus.${string}`]: \"idle\" | \"active\" | \"done\" | \"error\";\n readonly [key: `$streamError.${string}`]: unknown;\n\n // ループインデックス変数 ($1〜$9)\n // for テンプレート内のイベントハンドラで、ネストされたループの\n // 各階層のインデックスにアクセスするために使用。\n // (ランタイムは $1〜$128 まで解決するが、型宣言は実用域の $9 までとする)\n readonly $1: number;\n readonly $2: number;\n readonly $3: number;\n readonly $4: number;\n readonly $5: number;\n readonly $6: number;\n readonly $7: number;\n readonly $8: number;\n readonly $9: number;\n\n // `$recursion` 宣言済みの再帰パス(`this[\"nodes.**.total\"]`)。深さの族なので\n // `WcsPaths<T>` の有限展開には現れず、getter のキーに書いた 1 本しか T に現れない。\n // パターン索引で「`**` を含むキーは読める」とだけ言う(型は any — 深さを型で表せない\n // 以上、値の型も辿れない)。パターンは `**` を必ず含むので、通常のドットパスの型付けは\n // 損なわない。VS Code 拡張の preamble(vscode-wcs src/language/preamble.ts)と同じ形 —\n // 公開型面とエディタの型面は対で保つ。\n // 素の `nodes.**`(再帰 getter の中でノード自身に束縛される読み)は `.**.` を含まないので、\n // 末尾が `.**` のキーにも同じ索引を置く。\n readonly [key: `${string}.**.${string}`]: any;\n readonly [key: `${string}.**`]: any;\n}\n\n// ============================================================\n// WcsThis — state メソッド/getter 内の this の型\n// ============================================================\n\n/**\n * state定義オブジェクト内の `this` の型。\n *\n * - `T` のプロパティに型付きでアクセス可能(直接キー)\n * - `WcsPathAccessor<T>` によるネストされたドットパスの型付きアクセス\n * - `WcsStateApi` のメソッド ($getAll, $postUpdate 等) にアクセス可能\n * - 動的パス (`this[\\`items.${i}.name\\`]`) は型チェック対象外(キャストが必要)\n *\n * @example\n * ```ts\n * defineState({\n * count: 0,\n * users: [] as { name: string; age: number }[],\n * increment() {\n * this.count++; // number\n * this[\"users.*.name\"]; // string (パス型解決)\n * this.$getAll(\"users.*.age\"); // API\n * }\n * });\n * ```\n */\nexport type WcsThis<T> = T & WcsStateApi & WcsPathAccessor<T>;\n\n// ============================================================\n// defineState — 型付き状態定義関数\n// ============================================================\n\n/**\n * `<wcs-state>` 用の型付き状態オブジェクトを定義する。\n *\n * ランタイムではアイデンティティ関数(引数をそのまま返す)として動作し、\n * コストはゼロ。TypeScript の `ThisType<>` を利用して、メソッド・getter 内の\n * `this` に型補完を提供する。\n *\n * ### 基本的な使い方 (TypeScript)\n * ```ts\n * import { defineState } from '@wcstack/state';\n *\n * export default defineState({\n * count: 0,\n * users: [] as { name: string; age: number }[],\n *\n * increment() {\n * this.count++; // ✅ number\n * this[\"users.*.name\"]; // ✅ string (ドットパス型解決)\n * },\n *\n * get \"users.*.ageCategory\"() {\n * return this[\"users.*.age\"] < 25 ? \"Young\" : \"Adult\";\n * }\n * });\n * ```\n *\n * ### JavaScript (JSDoc)\n * ```js\n * import { defineState } from '@wcstack/state';\n *\n * export default defineState({\n * count: 0,\n * increment() {\n * this.count++; // ✅ JSDoc + tsconfig checkJs で型補完\n * }\n * });\n * ```\n *\n * ### HTML インラインスクリプト\n * ```html\n * <wcs-state>\n * <script type=\"module\">\n * import { defineState } from '@wcstack/state';\n * export default defineState({\n * count: 0,\n * increment() { this.count++; }\n * });\n * </script>\n * </wcs-state>\n * ```\n *\n * ### ライフサイクルコールバック\n * ```ts\n * export default defineState({\n * data: null,\n * async $connectedCallback() {\n * this.data = await fetch('/api/data').then(r => r.json());\n * },\n * $disconnectedCallback() {\n * // cleanup\n * },\n * $updatedCallback() {\n * // called after DOM update\n * }\n * });\n * ```\n */\nexport function defineState<T extends Record<string, any>>(\n definition: T & ThisType<WcsThis<T>>\n): T {\n return definition;\n}\n"],"names":["resolveConfig","config","locale","lang","document","documentElement","Intl","getCanonicalLocales","console","warn","localeFromDocument","undefined","bootstrapCore","registry","resolved","setConfig","registerComponents","registerBinder","installFeatures","features","i","length","install","defineState","definition"],"mappings":"uoBAiDA,SAASA,EAAcC,GACrB,GAA8B,iBAAnBA,GAAQC,OACjB,OAAOD,EAET,MAAMC,EAxBR,WACE,MAAMC,EAAOC,SAASC,iBAAiBF,KACvC,GAAKA,EAGL,IAKE,OADAG,KAAKC,oBAAoBJ,GAClBA,CACT,CAAE,MAKA,YAJAK,QAAQC,KACN,gCAAgCN,0FAIpC,CACF,CAMiBO,GACf,YAAeC,IAAXT,EACKD,EAEF,IAAKA,EAAQC,SACtB,CAEM,SAAUU,EAAcX,EAA0BY,GACtD,MAAMC,EAAWd,EAAcC,GAC3Ba,GACFC,EAAUD,GAEZE,EAAmBH,GAGnBI,GACF,CC3CM,SAAUC,EAAgBC,GAC9B,IAAK,IAAIC,EAAI,EAAGA,EAAID,EAASE,OAAQD,IACnCD,EAASC,GAAGE,SAEhB,CC8XM,SAAUC,EACdC,GAEA,OAAOA,CACT"}
1
+ {"version":3,"file":"core.js","sources":["../../../../src/core/bootstrapCore.ts","../../../../src/core/features.ts","../../../../src/defineState.ts"],"sourcesContent":["/**\n * core/bootstrapCore.ts — 機能を 1 つも入れない bootstrap(設計案 §4、`@wcstack/state/core`)。\n *\n * 設定の解決・タグの登録・binder プロトコルの提供だけを行う。機能の install は\n * `installFeatures([...])` の仕事で、full / auto の `bootstrapState()` が全部入れてから\n * これを呼ぶ(従来と同じ順序 — install は要素の定義より前)。\n */\nimport { setConfig } from \"../config\";\nimport { registerBinder } from \"../bindings/binder\";\nimport { registerComponents } from \"../registerComponents\";\nimport { IWritableConfig } from \"../types\";\n\n/**\n * `<html lang>` を既定ロケールとして採る。\n *\n * ロケール依存フィルタ(`locale` / `date` / `time` / `datetime`)は `config.locale`\n * を読むが、それを設定できる公開の入口は `bootstrapState({ locale })` しかない。\n * 一方 `auto` エントリは `bootstrapState()` を引数なしで呼ぶため、CDN 一発\n * (`<script src=\".../@wcstack/state/auto\">`)で読み込んだページには**ロケールを\n * 渡す口が無かった**。auto バンドルは SRI のため自己完結で、別途 `@wcstack/state`\n * を import して `bootstrapState` を呼んでも別インスタンスになり効かない。\n *\n * `<html lang>` はページのロケールを書く HTML 標準の場所であり、SSR ではサーバーが、\n * 静的ページでは head のスニペットが DOM 解析前に書く。そこを既定にすると\n * **ロケールの正本が 1 つになり**、「設定を早く呼ぶ」という守りにくい順序の約束が\n * 「`<html lang>` が state のロードより前にある」という構造的な保証に変わる。\n *\n * 明示指定(`bootstrapState({ locale })`)が常に優先する。\n */\nfunction localeFromDocument(): string | undefined {\n const lang = document.documentElement?.lang;\n if (!lang) {\n return undefined;\n }\n try {\n // 妥当な BCP-47 タグでなければ Intl が RangeError を投げる。不正な lang を\n // そのまま採ると、これまで既定 'en' で動いていたページのフィルタが実行時に\n // 落ちる。既定へ落として警告するほうが、黙って壊すより回復しやすい。\n Intl.getCanonicalLocales(lang);\n return lang;\n } catch {\n console.warn(\n `[@wcstack/state] <html lang=\"${lang}\"> is not a valid BCP-47 language tag. ` +\n `Falling back to the default locale for filters.`\n );\n return undefined;\n }\n}\n\nfunction resolveConfig(config?: IWritableConfig): IWritableConfig | undefined {\n if (typeof config?.locale === \"string\") {\n return config;\n }\n const locale = localeFromDocument();\n if (locale === undefined) {\n return config;\n }\n return { ...config, locale };\n}\n\nexport function bootstrapCore(config?: IWritableConfig, registry?: CustomElementRegistry): void {\n const resolved = resolveConfig(config);\n if (resolved) {\n setConfig(resolved);\n }\n registerComponents(registry);\n // binder プロトコルの提供(docs/binder-protocol-design.md)。router が後から\n // 差し込むノードをバインドできるようにする。登録は冪等。\n registerBinder();\n}\n","/**\n * core/features.ts — 分割エントリの install(設計案 §4、要件 D15)。\n *\n * 機能のエントリは「名前と install を持つ記述子」を export し、ページは要るものだけを入れる:\n *\n * ```js\n * import { bootstrapState, installFeatures } from \"@wcstack/state/core\";\n * import temporal from \"@wcstack/state/features/temporal\";\n * installFeatures([temporal]);\n * bootstrapState();\n * ```\n *\n * full(`@wcstack/state`)と `/auto` は `bootstrapState()` が全機能を入れるので、利用者から見た\n * 挙動は変わらない。\n *\n * **冪等は機能側の `install` が持つ**(どれも `installed` フラグで 2 回目を弾く)。ここで名前を\n * 覚えて重複を弾く手もあるが、同じことを 2 箇所で持つだけで、しかも「`bootstrapState()` を\n * 2 回呼ぶと 2 回目は機能の install に届かない」という観測できる差が増える。core は素直に並べた順に呼ぶ。\n */\nexport interface IStateFeature {\n /** 機能の名前(受け口のレジストリのキーと同じ。barrier の文言が使う) */\n readonly name: string;\n /** 受け口へこの機能の実装を置く。**冪等であること** — core は 2 回呼ぶことがある */\n install(): void;\n}\n\nexport function installFeatures(features: readonly IStateFeature[]): void {\n for (let i = 0; i < features.length; i++) {\n features[i].install();\n }\n}\n","/**\n * defineState.ts\n *\n * 状態オブジェクトに型付けを提供するためのユーティリティ。\n * defineState() はアイデンティティ関数で、ThisType<> を付与することで\n * メソッド・computed getter 内の this に型補完を提供する。\n *\n * テンプレートリテラル型によるドットパスの型解決:\n * - WcsPaths<T> : T から生成される全ドットパスの union\n * - WcsPathValue<T,P>: パス P に対応する値の型\n * - WcsPathAccessor<T>: ブラケットアクセス用マップ型\n */\n\n// ============================================================\n// Internal helper types\n// ============================================================\n\n/**\n * `any` 型を検出する。\n * `0 extends (1 & T)` は T が `any` の場合のみ true になる。\n */\ntype IsAny<T> = 0 extends (1 & T) ? true : false;\n\n/**\n * T がドットパス再帰の対象となる「プレーンなデータオブジェクト」かどうかを判定する。\n * プリミティブ、組み込みオブジェクト (Date, Map 等)、関数、配列、any は除外。\n */\ntype IsPlainObject<T> =\n IsAny<T> extends true ? false :\n T extends\n | string | number | boolean | null | undefined | symbol | bigint\n | ((...args: any[]) => any) | Date | RegExp | Error\n | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any>\n | Promise<any> | readonly any[]\n ? false\n : T extends Record<string, any>\n ? true\n : false;\n\n/**\n * T のキーのうち、関数でないもの(データプロパティ・computed getter)を抽出する。\n * メソッド(イベントハンドラ等)はドットパスの対象外。\n * `$` プレフィックスキー($streams / $commandTokens / $on 等の予約宣言)もドットパスにならない。\n * any 型のプロパティは除外せず保持する。\n */\ntype DataKeys<T> = {\n [K in keyof T & string]:\n K extends `$${string}` ? never :\n IsAny<T[K]> extends true ? K : T[K] extends (...args: any[]) => any ? never : K;\n}[keyof T & string];\n\n// ============================================================\n// WcsPaths — ドットパスの union 生成\n// ============================================================\n\n/**\n * 型 T から生成される全てのドットパスの union。\n * 配列プロパティはワイルドカード `*` を使用: `items.*.name`\n *\n * 再帰の深さは最大4レベルに制限(コンパイル性能の確保)。\n *\n * @example\n * ```ts\n * type S = {\n * count: number;\n * users: { name: string; age: number }[];\n * cart: { items: { price: number }[] };\n * };\n * type P = WcsPaths<S>;\n * // = \"count\" | \"users\" | \"users.*\" | \"users.*.name\" | \"users.*.age\"\n * // | \"cart\" | \"cart.items\" | \"cart.items.*\" | \"cart.items.*.price\"\n * ```\n */\nexport type WcsPaths<T, Depth extends readonly any[] = []> =\n Depth[\"length\"] extends 4 ? never :\n {\n [K in DataKeys<T>]:\n | K\n | (T[K] extends readonly (infer E)[]\n ? IsPlainObject<E> extends true\n ? `${K}.*` | WcsSubPaths<E, `${K}.*.`, [...Depth, 0]>\n : `${K}.*`\n : IsPlainObject<T[K]> extends true\n ? WcsSubPaths<T[K], `${K}.`, [...Depth, 0]>\n : never)\n }[DataKeys<T>];\n\n/** @internal プレフィックス付きサブパスの生成ヘルパー */\ntype WcsSubPaths<T, Prefix extends string, Depth extends readonly any[]> =\n WcsPaths<T, Depth> extends infer P extends string\n ? `${Prefix}${P}`\n : never;\n\n// ============================================================\n// WcsPathValue — パスから値の型を解決\n// ============================================================\n\n/**\n * ドットパス P に対応する値の型を T から解決する。\n *\n * 解決順序:\n * 1. T の直接キー(computed getter 含む)\n * 2. `K.*` → 配列要素型\n * 3. `K.rest` → オブジェクト/配列のネストを再帰的に辿る\n *\n * @example\n * ```ts\n * type S = { cart: { items: { price: number; qty: number }[] } };\n * type V1 = WcsPathValue<S, \"cart.items.*.price\">; // number\n * type V2 = WcsPathValue<S, \"cart.items.*\">; // { price: number; qty: number }\n * type V3 = WcsPathValue<S, \"cart\">; // { items: ... }\n * ```\n */\nexport type WcsPathValue<T, P extends string> =\n // 1. Direct key (includes computed getters like \"users.*.ageCategory\")\n P extends keyof T\n ? T[P]\n // 2. K.* → array element type\n : P extends `${infer K}.*`\n ? K extends keyof T\n ? T[K] extends readonly (infer E)[] ? E : never\n : never\n // 3. K.rest → recurse into nested structure\n : P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? T[K] extends readonly (infer E)[]\n // Array: expect *.subpath or *\n ? Rest extends `*.${infer SubRest}`\n ? WcsPathValue<E, SubRest>\n : Rest extends \"*\"\n ? E\n : never\n // Object: recurse\n : T[K] extends Record<string, any>\n ? WcsPathValue<T[K], Rest>\n : never\n : never\n : never;\n\n// ============================================================\n// WcsPathAccessor — ブラケットアクセス用マップ型\n// ============================================================\n\n/**\n * 全ドットパスに対する型付きブラケットアクセスを提供するマップ型。\n *\n * `this[\"users.*.name\"]` のようなアクセスに対して、\n * WcsPaths で生成されたパスに対応する値の型を返す。\n */\ntype WcsPathAccessor<T> = {\n [P in WcsPaths<T>]: WcsPathValue<T, P>;\n};\n\n// ============================================================\n// State Proxy API — this 経由でアクセスできるAPI\n// ============================================================\n\n/**\n * `<wcs-state>` の Proxy 経由で提供されるAPIメソッド。\n * state定義オブジェクト内のメソッド・getter で `this.` 経由で利用可能。\n */\nexport interface WcsStateApi {\n /**\n * ワイルドカードを含むパスにマッチする全要素を配列で取得する。\n *\n * @param path - ワイルドカードを含むパス\n * @param indexes - 各ワイルドカード階層のインデックス(前方一致の接頭辞。`[]` は全階層を展開)。\n * 省略時はループ文脈の添字(`[$1..$n]` 相当)のうち path と共有するワイルドカード連鎖の\n * 分が接頭辞として敷かれる(文脈が path より深い分は切り詰め)。共有が無いのに文脈が\n * 添字を持つ場合は throw する — 異なる文脈の添字は流用しない。\n *\n * @example\n * ```ts\n * get \"cart.totalPrice\"() {\n * return this.$getAll(\"cart.items.*.price\").reduce((sum, v) => sum + v, 0);\n * }\n * ```\n */\n $getAll<V = any>(path: string, indexes?: number[]): V[];\n\n /**\n * ワイルドカードを含むパスにマッチする**全アドレスへ一括で書き込む**(`$getAll` の対称形)。\n *\n * 配列を作り直さずに一括更新するための API。`this.users = this.users.map(...)` は\n * ListIndex・行 getter キャッシュ・差分描画をまとめて作り直すが、`$setAll` は\n * in-place な個別書き込みに分解するのでリストの同一性が保たれる。\n *\n * - `indexes` は `$getAll` と同じ**前方一致の接頭辞**(`[]` で全階層を展開)。省略は不可。\n * - 関数を渡すと **mapper**(`(current, ...indexes) => next`)として要素ごとに評価される。\n * - 配列は既定でブロードキャストされる。1 件ずつ配るには `{ spread: true }` を明示する。\n * - `undefined` を書こうとした要素はスキップされる(クリアは `null`)。\n *\n * @returns 実際に書き込んだ件数(`undefined` でスキップした分を含まない)\n *\n * @example\n * ```ts\n * toggleAll(e: Event) {\n * this.$setAll(\"users.*.selected\", [], (e.target as HTMLInputElement).checked);\n * }\n * invertAll() {\n * this.$setAll(\"users.*.selected\", [], cur => !cur);\n * }\n * ```\n */\n $setAll<V = any>(\n path: string,\n indexes: number[],\n value: V | ((current: V, ...indexes: number[]) => V | undefined),\n ): number;\n $setAll<V = any>(\n path: string,\n indexes: number[],\n values: readonly V[],\n options: { spread: true },\n ): number;\n\n /**\n * 指定パスの更新を手動でトリガーする。\n * Proxy の set トラップを経由せずに内部状態を変更した場合に使用。\n */\n $postUpdate(path: string): void;\n\n /**\n * パスとインデックス配列を指定して、ワイルドカードを解決した値を取得・設定する。\n *\n * @param path - ワイルドカードを含むパス\n * @param indexes - 各ワイルドカード階層のインデックス\n * @param value - 設定する値(省略時は取得)\n */\n $resolve(path: string, indexes: number[], value?: any): any;\n\n /**\n * 指定パスへの依存関係を明示的に登録する。\n * computed getter 内で動的にパスを組み立てる場合に使用。\n */\n $dependOn(path: string): void;\n\n /**\n * コールバック実行中の依存追跡(動的依存・`$1` インデックス依存の登録)を\n * 抑止して fn を実行し、その戻り値を返す。\n * リスト行 getter が「行外の単一値」を読みたいが、その値の変更で全行を\n * 再評価させたくない場合に使う(該当行へ直接書き込む設計と組で用いる)。\n */\n $untracked<T>(fn: () => T): T;\n\n /** @deprecated `$dependOn` の旧名(3.x の間は動き、4.0 で外れる — 要件 B12) */\n $trackDependency(path: string): void;\n\n /** @deprecated `$untracked` の旧名(3.x の間は動き、4.0 で外れる — 要件 B12) */\n $untrackDependency<T>(fn: () => T): T;\n\n /**\n * 鍵付き購読: `path` の現在値が `key` に等しいかを返し、評価中のリスト行 getter を\n * その鍵で購読する。`path` への書き込みは旧値・新値の鍵の行だけを再評価する\n * (パターン依存なら全行)。`path` 自体は依存として追跡しない。\n * 例: `get \"items.*.selected\"() { return this.$eq(\"selectedId\", this.$untracked(() => this[\"items.*.id\"])); }`\n */\n $eq(path: string, key: unknown): boolean;\n\n /**\n * `$eq` の鍵を `keyPath`(ワイルドカードは評価中の行で解決)から依存を張らずに読む形。\n * 例: `get \"items.*.selected\"() { return this.$eqPath(\"selectedId\", \"items.*.id\"); }`\n */\n $eqPath(path: string, keyPath: string): boolean;\n\n /**\n * `$eq` の鍵を評価中の行の index(`$1` 相当。`level` でワイルドカード段を選ぶ)にする形。\n * getter を index 依存には記録せず、行の移動時はリスト差分が鍵を付け替えるので、\n * 1 行削除で再評価されるのは高々 2 行。\n * 例: `get \"items.*.selected\"() { return this.$eqIndex(\"selectedIndex\"); }`\n */\n $eqIndex(path: string, level?: number): boolean;\n\n /** `<wcs-state>` 要素への参照 */\n readonly $stateElement: HTMLElement;\n\n /**\n * `$commandTokens` で宣言した command token の名前空間。\n * `this.$command.<name>` で token を解決できる(バインディングでは\n * `onclick: $command.<name>` / `command.<method>: $command.<name>`)。\n */\n readonly $command: Record<string, { emit(...args: any[]): any }>;\n\n /** `$stream` 各エントリの状態(\"idle\" | \"active\" | \"done\" | \"error\")を返す読み取り専用名前空間 */\n readonly $streamStatus: Record<string, \"idle\" | \"active\" | \"done\" | \"error\">;\n\n /** `$stream` 各エントリの直近エラーを返す読み取り専用名前空間 */\n readonly $streamError: Record<string, unknown>;\n\n // computed getter 内での依存追跡付き読み取りの正規形は dotted パス\n // (`this[\"$streamStatus.<name>\"]` — docs/state-streams-design.md §4-3)\n readonly [key: `$streamStatus.${string}`]: \"idle\" | \"active\" | \"done\" | \"error\";\n readonly [key: `$streamError.${string}`]: unknown;\n\n // ループインデックス変数 ($1〜$9)\n // for テンプレート内のイベントハンドラで、ネストされたループの\n // 各階層のインデックスにアクセスするために使用。\n // (ランタイムは $1〜$128 まで解決するが、型宣言は実用域の $9 までとする)\n readonly $1: number;\n readonly $2: number;\n readonly $3: number;\n readonly $4: number;\n readonly $5: number;\n readonly $6: number;\n readonly $7: number;\n readonly $8: number;\n readonly $9: number;\n\n // `$recursion` 宣言済みの再帰パス(`this[\"nodes.**.total\"]`)。深さの族なので\n // `WcsPaths<T>` の有限展開には現れず、getter のキーに書いた 1 本しか T に現れない。\n // パターン索引で「`**` を含むキーは読める」とだけ言う(型は any — 深さを型で表せない\n // 以上、値の型も辿れない)。パターンは `**` を必ず含むので、通常のドットパスの型付けは\n // 損なわない。VS Code 拡張の preamble(vscode-wcs src/language/preamble.ts)と同じ形 —\n // 公開型面とエディタの型面は対で保つ。\n // 素の `nodes.**`(再帰 getter の中でノード自身に束縛される読み)は `.**.` を含まないので、\n // 末尾が `.**` のキーにも同じ索引を置く。\n readonly [key: `${string}.**.${string}`]: any;\n readonly [key: `${string}.**`]: any;\n}\n\n// ============================================================\n// WcsThis — state メソッド/getter 内の this の型\n// ============================================================\n\n/**\n * state定義オブジェクト内の `this` の型。\n *\n * - `T` のプロパティに型付きでアクセス可能(直接キー)\n * - `WcsPathAccessor<T>` によるネストされたドットパスの型付きアクセス\n * - `WcsStateApi` のメソッド ($getAll, $postUpdate 等) にアクセス可能\n * - 動的パス (`this[\\`items.${i}.name\\`]`) は型チェック対象外(キャストが必要)\n *\n * @example\n * ```ts\n * defineState({\n * count: 0,\n * users: [] as { name: string; age: number }[],\n * increment() {\n * this.count++; // number\n * this[\"users.*.name\"]; // string (パス型解決)\n * this.$getAll(\"users.*.age\"); // API\n * }\n * });\n * ```\n */\nexport type WcsThis<T> = T & WcsStateApi & WcsPathAccessor<T>;\n\n// ============================================================\n// defineState — 型付き状態定義関数\n// ============================================================\n\n/**\n * `<wcs-state>` 用の型付き状態オブジェクトを定義する。\n *\n * ランタイムではアイデンティティ関数(引数をそのまま返す)として動作し、\n * コストはゼロ。TypeScript の `ThisType<>` を利用して、メソッド・getter 内の\n * `this` に型補完を提供する。\n *\n * ### 基本的な使い方 (TypeScript)\n * ```ts\n * import { defineState } from '@wcstack/state';\n *\n * export default defineState({\n * count: 0,\n * users: [] as { name: string; age: number }[],\n *\n * increment() {\n * this.count++; // ✅ number\n * this[\"users.*.name\"]; // ✅ string (ドットパス型解決)\n * },\n *\n * get \"users.*.ageCategory\"() {\n * return this[\"users.*.age\"] < 25 ? \"Young\" : \"Adult\";\n * }\n * });\n * ```\n *\n * ### JavaScript (JSDoc)\n * ```js\n * import { defineState } from '@wcstack/state';\n *\n * export default defineState({\n * count: 0,\n * increment() {\n * this.count++; // ✅ JSDoc + tsconfig checkJs で型補完\n * }\n * });\n * ```\n *\n * ### HTML インラインスクリプト\n * ```html\n * <wcs-state>\n * <script type=\"module\">\n * import { defineState } from '@wcstack/state';\n * export default defineState({\n * count: 0,\n * increment() { this.count++; }\n * });\n * </script>\n * </wcs-state>\n * ```\n *\n * ### ライフサイクルコールバック\n * ```ts\n * export default defineState({\n * data: null,\n * async $connectedCallback() {\n * this.data = await fetch('/api/data').then(r => r.json());\n * },\n * $disconnectedCallback() {\n * // cleanup\n * },\n * $renderedCallback() {\n * // called after the bindings are applied (old name: $updatedCallback)\n * }\n * });\n * ```\n */\nexport function defineState<T extends Record<string, any>>(\n definition: T & ThisType<WcsThis<T>>\n): T {\n return definition;\n}\n"],"names":["resolveConfig","config","locale","lang","document","documentElement","Intl","getCanonicalLocales","console","warn","localeFromDocument","undefined","bootstrapCore","registry","resolved","setConfig","registerComponents","registerBinder","installFeatures","features","i","length","install","defineState","definition"],"mappings":"8qBAiDA,SAASA,EAAcC,GACrB,GAA8B,iBAAnBA,GAAQC,OACjB,OAAOD,EAET,MAAMC,EAxBR,WACE,MAAMC,EAAOC,SAASC,iBAAiBF,KACvC,GAAKA,EAGL,IAKE,OADAG,KAAKC,oBAAoBJ,GAClBA,CACT,CAAE,MAKA,YAJAK,QAAQC,KACN,gCAAgCN,0FAIpC,CACF,CAMiBO,GACf,YAAeC,IAAXT,EACKD,EAEF,IAAKA,EAAQC,SACtB,CAEM,SAAUU,EAAcX,EAA0BY,GACtD,MAAMC,EAAWd,EAAcC,GAC3Ba,GACFC,EAAUD,GAEZE,EAAmBH,GAGnBI,GACF,CC3CM,SAAUC,EAAgBC,GAC9B,IAAK,IAAIC,EAAI,EAAGA,EAAID,EAASE,OAAQD,IACnCD,EAASC,GAAGE,SAEhB,CCoYM,SAAUC,EACdC,GAEA,OAAOA,CACT"}
@@ -1,2 +1,2 @@
1
- import{c as e,i as t}from"../chunks/filterRegistry.js";import{J as n,o as s,K as o}from"../chunks/pathDiagnostics.js";import{aN as r,Y as i,P as a,aO as c,aP as l,aQ as u,f as d,aR as f,y as m}from"../chunks/binder.js";import{g as p}from"../chunks/mount.js";import{r as h}from"../chunks/errorGuidance.js";import{V as y}from"../chunks/version.js";const g=/^\s*@@\s*(.*?)\s*:\s*(.+?)\s*$/;function k(e,t,n,s){return{node:e,propName:t.propName,statePathName:t.statePathName,bindingType:t.bindingType,inFilters:t.inFilters,outFilters:t.outFilters,origin:n,raw:s}}const v="__WCSTACK_DEVTOOLS_HOOK__";function N(){const e=globalThis,t=e[v];if(void 0!==t)return 2!==t.version&&console.warn(`[wcstack/state] devtools hook registry version mismatch: found ${t.version}, expected 2. 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:2,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[v]=n,n}const S=e=>{null!==s&&s({type:"state:update-batch",addresses:e})};function T(e){const t=null!==s;o(e);const r=null!==e;r&&!t?d(S,n):!r&&t&&f(S)}function w(e){return{rootNode:e.rootNode,element:e,paths:{list:e.listPaths,element:e.elementPaths,getter:e.getterPaths,setter:e.setterPaths},commandTokenNames:e.commandTokenNames,eventTokenNames:e.eventTokenNames,staticDependency:e.staticDependency,dynamicDependency:e.dynamicDependency,watchPaths:e.watchPaths??null,keyedListPaths:void 0===e.listKeys||null===e.listKeys?null:new Set(e.listKeys.keys())}}function P(e){return m(e)??h("devtools: no state tree on this root")}let b=null;function x(){if(t())return;if(null!==b)return;const n={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:y,getStateElements(){const e=[];for(const t of u())e.push(w(t));return e},overlays(e){const t=P(e);return p(t).map(e=>({marker:e.marker,componentTag:e.component.tagName.toLowerCase(),stateProp:e.stateProp,mountTable:e.entries.map(e=>({inner:e.innerSegments.join("."),outer:e.outerPathInfo.path})),delta:e.delta,privateKeys:Object.keys(e.privateSnapshot),getterKeys:[...e.getterKeys],exports:[...e.exports.keys()]}))},keyedSubscriptions:e=>function(e){const t=l(e);if(null===t)return[];const n=new Set([...t.byPath.keys(),...t.tracked]);if(void 0!==t.watchers)for(const e of t.watchers.keys())n.add(e);const s=[];for(const e of[...n].sort()){const n=t.byPath.get(e);let o=0;if(void 0!==n)for(const e of n.values())o+=e.size;s.push({path:e,tracked:t.tracked.has(e),rows:o,keys:n?.size??0,lists:t.watchers?.get(e)?.size??0,lastValue:t.lastValue.get(e)})}return s}(P(e)),keys(e){const t=P(e),n=[];return t.createState("readonly",e=>{for(const t of Object.keys(e))if(!t.includes("*")&&!t.startsWith("$")){try{if("function"==typeof e[t])continue}catch{}n.push(t)}}),n},read(e,t,n){let s;return P(e).createState("readonly",e=>{s=e.$resolve(t,n??[])}),s},write(e,t,n,s){P(e).createState("writable",e=>{void 0!==s&&s.length>0?e.$resolve(t,s,n):e[t]=n})},getDeclaredBindings:t=>function(t){const n=[],s=new Set,o=new Set,l=e=>{const t=function(e){const t=[...e.inFilters,...e.outFilters].map(e=>`${e.filterName}(${e.args.join(",")})`).join("|");return[e.statePathName,e.propName,e.bindingType,t].join("\0")}(e);s.has(t)||(s.add(t),n.push(e))},u=e=>{if(o.has(e))return;o.add(e);const t=a(e);if(null!==t)for(const e of t.nodeInfos)for(const t of e.parseBindTextResults)l(k(null,t,"fragment","")),null!=t.uuid&&u(t.uuid)},d=(t.ownerDocument??t).createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT);for(let t=d.nextNode();null!==t;t=d.nextNode()){if(t.nodeType===Node.ELEMENT_NODE){const n=t,s=n.getAttribute(e.bindAttributeName);if(null===s||0===s.length)continue;try{const e=r(n,i(s));for(const t of e)l(k(n,t,"attribute",s))}catch{}continue}const n=g.exec(t.data.trim());if(null===n)continue;const s=n[1]||e.commentTextPrefix,o=n[2],d=a(o);if(null===d){if(s===e.commentTextPrefix)try{l(k(t,c(o),"comment",o))}catch{}}else l(k(t,d.parseBindTextResult,"comment",o)),u(o)}return n}(t),_setSink:T};b=n,N().register(n)}const _={name:"devtools",install(){x()}};export{_ as default,_ as devtools};
1
+ import{c as e,i as t}from"../chunks/filterRegistry.js";import{K as n,p as s,L as o}from"../chunks/pathDiagnostics.js";import{aN as r,D as i,Q as a,aO as c,aP as l,aQ as u,f as d,aR as f,y as m}from"../chunks/binder.js";import{g as p}from"../chunks/mount.js";import{r as h}from"../chunks/errorGuidance.js";import{V as y}from"../chunks/version.js";import"../chunks/declarationAliases.js";const g=/^\s*@@\s*(.*?)\s*:\s*(.+?)\s*$/;function k(e,t,n,s){return{node:e,propName:t.propName,statePathName:t.statePathName,bindingType:t.bindingType,inFilters:t.inFilters,outFilters:t.outFilters,origin:n,raw:s}}const v="__WCSTACK_DEVTOOLS_HOOK__";function N(){const e=globalThis,t=e[v];if(void 0!==t)return 2!==t.version&&console.warn(`[wcstack/state] devtools hook registry version mismatch: found ${t.version}, expected 2. 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:2,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[v]=n,n}const S=e=>{null!==s&&s({type:"state:update-batch",addresses:e})};function T(e){const t=null!==s;o(e);const r=null!==e;r&&!t?d(S,n):!r&&t&&f(S)}function w(e){return{rootNode:e.rootNode,element:e,paths:{list:e.listPaths,element:e.elementPaths,getter:e.getterPaths,setter:e.setterPaths},commandTokenNames:e.commandTokenNames,eventTokenNames:e.eventTokenNames,staticDependency:e.staticDependency,dynamicDependency:e.dynamicDependency,watchPaths:e.watchPaths??null,keyedListPaths:void 0===e.listKeys||null===e.listKeys?null:new Set(e.listKeys.keys())}}function P(e){return m(e)??h("devtools: no state tree on this root")}let b=null;function x(){if(t())return;if(null!==b)return;const n={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:y,getStateElements(){const e=[];for(const t of u())e.push(w(t));return e},overlays(e){const t=P(e);return p(t).map(e=>({marker:e.marker,componentTag:e.component.tagName.toLowerCase(),stateProp:e.stateProp,mountTable:e.entries.map(e=>({inner:e.innerSegments.join("."),outer:e.outerPathInfo.path})),delta:e.delta,privateKeys:Object.keys(e.privateSnapshot),getterKeys:[...e.getterKeys],exports:[...e.exports.keys()]}))},keyedSubscriptions:e=>function(e){const t=l(e);if(null===t)return[];const n=new Set([...t.byPath.keys(),...t.tracked]);if(void 0!==t.watchers)for(const e of t.watchers.keys())n.add(e);const s=[];for(const e of[...n].sort()){const n=t.byPath.get(e);let o=0;if(void 0!==n)for(const e of n.values())o+=e.size;s.push({path:e,tracked:t.tracked.has(e),rows:o,keys:n?.size??0,lists:t.watchers?.get(e)?.size??0,lastValue:t.lastValue.get(e)})}return s}(P(e)),keys(e){const t=P(e),n=[];return t.createState("readonly",e=>{for(const t of Object.keys(e))if(!t.includes("*")&&!t.startsWith("$")){try{if("function"==typeof e[t])continue}catch{}n.push(t)}}),n},read(e,t,n){let s;return P(e).createState("readonly",e=>{s=e.$resolve(t,n??[])}),s},write(e,t,n,s){P(e).createState("writable",e=>{void 0!==s&&s.length>0?e.$resolve(t,s,n):e[t]=n})},getDeclaredBindings:t=>function(t){const n=[],s=new Set,o=new Set,l=e=>{const t=function(e){const t=[...e.inFilters,...e.outFilters].map(e=>`${e.filterName}(${e.args.join(",")})`).join("|");return[e.statePathName,e.propName,e.bindingType,t].join("\0")}(e);s.has(t)||(s.add(t),n.push(e))},u=e=>{if(o.has(e))return;o.add(e);const t=a(e);if(null!==t)for(const e of t.nodeInfos)for(const t of e.parseBindTextResults)l(k(null,t,"fragment","")),null!=t.uuid&&u(t.uuid)},d=(t.ownerDocument??t).createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT);for(let t=d.nextNode();null!==t;t=d.nextNode()){if(t.nodeType===Node.ELEMENT_NODE){const n=t,s=n.getAttribute(e.bindAttributeName);if(null===s||0===s.length)continue;try{const e=r(n,i(s));for(const t of e)l(k(n,t,"attribute",s))}catch{}continue}const n=g.exec(t.data.trim());if(null===n)continue;const s=n[1]||e.commentTextPrefix,o=n[2],d=a(o);if(null===d){if(s===e.commentTextPrefix)try{l(k(t,c(o),"comment",o))}catch{}}else l(k(t,d.parseBindTextResult,"comment",o)),u(o)}return n}(t),_setSink:T};b=n,N().register(n)}const j={name:"devtools",install(){x()}};export{j as default,j as devtools};
2
2
  //# sourceMappingURL=devtools.js.map