@wcstack/state 3.3.0 → 3.5.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 (43) hide show
  1. package/README.ja.md +94 -27
  2. package/README.md +94 -27
  3. package/dist/auto.min.js +1 -1
  4. package/dist/auto.min.js.map +1 -1
  5. package/dist/index.d.ts +52 -1
  6. package/dist/index.esm.js +1 -1
  7. package/dist/index.esm.js.map +1 -1
  8. package/dist/split/chunks/binder.js +1 -1
  9. package/dist/split/chunks/binder.js.map +1 -1
  10. package/dist/split/chunks/checkDependency.js +1 -1
  11. package/dist/split/chunks/checkDependency.js.map +1 -1
  12. package/dist/split/chunks/declarationAliases.js.map +1 -1
  13. package/dist/split/chunks/diagnosticsHooks.js.map +1 -1
  14. package/dist/split/chunks/featureBridge.js +1 -1
  15. package/dist/split/chunks/filterRegistry.js +1 -1
  16. package/dist/split/chunks/filterRegistry.js.map +1 -1
  17. package/dist/split/chunks/getAllPropertyDescriptors.js +1 -1
  18. package/dist/split/chunks/lifecycleHooks.js +1 -1
  19. package/dist/split/chunks/lifecycleHooks.js.map +1 -1
  20. package/dist/split/chunks/pathDiagnostics.js +1 -1
  21. package/dist/split/chunks/pathDiagnostics.js.map +1 -1
  22. package/dist/split/chunks/registerComponents.js +1 -1
  23. package/dist/split/chunks/registerComponents.js.map +1 -1
  24. package/dist/split/chunks/setAll.js +1 -1
  25. package/dist/split/chunks/setAll.js.map +1 -1
  26. package/dist/split/chunks/version.js +1 -1
  27. package/dist/split/core.d.ts +77 -1
  28. package/dist/split/core.js +1 -1
  29. package/dist/split/features/devtools.js +1 -1
  30. package/dist/split/features/devtools.js.map +1 -1
  31. package/dist/split/features/diagnostics.js +1 -1
  32. package/dist/split/features/diagnostics.js.map +1 -1
  33. package/dist/split/features/formats.js +1 -1
  34. package/dist/split/features/formats.js.map +1 -1
  35. package/dist/split/features/recursion.js +1 -1
  36. package/dist/split/features/recursion.js.map +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/package.json +1 -1
@@ -1,2 +1,2 @@
1
- import{r as t}from"../chunks/declarationHooks.js";import{S as e,d as n,a as o,D as r,W as s,b as a,g as i,M as c,c as u,e as l,f,h as d,i as h,j as p}from"../chunks/pathDiagnostics.js";import{n as m}from"../chunks/declarationAliases.js";import{r as $,L as y,d as w}from"../chunks/errorGuidance.js";import{c as g,d as v,e as b,l as k,f as j,i as O,h as P,j as I,k as x,m as S,n as A,o as E,p as M}from"../chunks/binder.js";import{g as z,N as W,r as R}from"../chunks/getAllPropertyDescriptors.js";import{i as C}from"../chunks/filterRegistry.js";import{s as _}from"../chunks/featureBridge.js";const D=new WeakMap,F=new Set,N=new Set;function T(t){return t.byFromPath.size>0||t.byResetPath.size>0}function L(t,e,n){const o=t.get(e);void 0===o?t.set(e,[n]):o.push(n)}function G(t){return D.get(t)}function B(t){H(t),D.delete(t)}function H(t){F.delete(t),N.delete(t)}const K=new WeakSet;let q=0;function Q(t){return G(t.absolutePathInfo.stateElement)?.eventResetByPath.get(t.absolutePathInfo.pathInfo.path)}function U(t){if(0===N.size)return;if(e=t.absolutePathInfo.stateElement,!N.has(e))return;var e;const n=Q(t);if(void 0!==n)for(const t of n)V(t)}function V(t){K.has(t)||(K.add(t),q++)}function J(t){return!!K.delete(t)&&(q--,!0)}const X=/^(?:0|[1-9]\d*)$/;function Y(t,e){const n=Object.getOwnPropertyDescriptor(t,e);return!0===n.enumerable&&"value"in n}function Z(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&&X.test(e)&&Y(t,e))?"array":null}return(e===Object.prototype||null===e)&&Reflect.ownKeys(t).every(e=>"string"==typeof e&&Y(t,e))?"object":null}function tt(t,e){const n=Z(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]=tt(o[t],e);return s}function et(t){return tt(t,new Map)}function nt(t,e,n){if(Object.is(t,e))return!0;const o=Z(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(Z(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(!nt(r[e],s[e],n))return!1;return!0}return Object.keys(s).every(t=>Object.prototype.hasOwnProperty.call(r,t)&&nt(r[t],s[t],n))}function ot(t,e){return nt(t,e,new Map)}const rt=new WeakMap;function st(t,e){if("function"!=typeof e)return;const n=rt.get(e);void 0===n?rt.set(e,new Set([t])):n.add(t)}function at(t,e){return"function"==typeof e&&!0===rt.get(e)?.has(t)}const it={"read-source":t=>`${e} could not read a "from" value for "${t}". That landing was not folded; the other landings of the batch still were.`,"read-rows":t=>`${e} could not read the rows of "from" for "${t}". Nothing was folded or written.`,"read-output":t=>`${e} could not read the output "${t}". Nothing was folded or written.`,threw:t=>`${e} fold for "${t}" threw. The output was not written.`,"returned-promise":t=>`${e} fold for "${t}" returned a Promise. fold must be synchronous and return the next value; the output was not written.`,write:t=>`${e} could not write the output "${t}".`},ct={"read-source":"evaluate","read-rows":"evaluate","read-output":"evaluate",threw:"fold","returned-promise":"fold",write:"write"};function ut(t,o,r){null!==n&&n({type:"state:watch-error",phase:o,path:`${e}.${t}`,error:r})}function lt(t,e,n){console.error(`[@wcstack/state] ${it[n](t)}`,e),ut(t,ct[n],e)}function ft(t){return null!==t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function dt(t,n){n.then(void 0,()=>{}),lt(t,new TypeError(`${e} fold for "${t}" returned a Promise. fold must be synchronous and return the next value.`),"returned-promise")}const ht=new WeakSet;const pt="[wcs/scan-declaration-invalid]",mt=Object.freeze([]);function $t(t){return`${e} entry "${t}"`}function yt(t,e){for(const n of t.cumulativePaths)if(e.has(n))return n;return null}function wt(t,e,n,o){return`[wcs/scan-source-computed] ${t} ${e} "${n}" ${o===n?"is a getter":o.includes(`${s}${s}`)?`is computed by the recursive getter "${o}"`:`is under the getter "${o}"`}. A getter re-evaluates whenever its inputs change, so folding it would count re-evaluations, not events. Fold the plain value the getter reads, or use "on" with an event token.${y}`}function gt(t,e,n){0===n.length&&$(`${pt} ${t} "${e}" must be a non-empty state path.${y}`),n.startsWith("$")&&$(`${pt} ${t} ${e} "${n}" must not start with "$" (reserved namespace).${y}`),n.includes("@")&&$(`${pt} ${t} ${e} "${n}" must not contain "@" — there is a single state tree per root.${y}`),n in Object.prototype&&$(`${pt} ${t} ${e} "${n}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").${y}`);const o=i(n);for(const r of o.segments)0===r.length&&$(`${pt} ${t} ${e} "${n}" has an empty path segment.${y}`);return o.wildcardCount>c&&$(`${pt} ${t} ${e} "${n}" exceeds the maximum wildcard depth (${c}).`),o}function vt(t,n,a,i){const c=$t(t);0===t.length&&$(`${pt} ${e} entry name must be a non-empty string.${y}`),(t.includes(r)||t.includes(s))&&$(`${pt} ${c} must be a flat property name ("${r}" and "${s}" are not allowed). The output is a property the runtime owns.${y}`),t.startsWith("$")&&$(`${pt} ${c} must not start with "$" (reserved namespace).${y}`),t in Object.prototype&&$(`${pt} ${c} must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").${y}`),n.has(t)&&$(`${pt} ${c} conflicts with a getter declared on the state.${y}`),a.has(t)&&$(`${pt} ${c} conflicts with a setter declared on the state.${y}`),i.has(t)&&$(`${pt} ${c} conflicts with the ${o} entry of the same name — each output has exactly one owner.${y}`)}function bt(t,e,n){const o=e.get(t);e.has(t)&&o!==n.initial&&!at(t,o)&&$(`${pt} ${$t(t)} conflicts with a method (a function-valued property) declared on the state. The output is a property the runtime owns.${y}`)}function kt(t,e,n,o,s,i){const c=$t(t),u=void 0!==e.from,l=void 0!==e.on;if(u===l&&$(`${pt} ${c} must declare exactly one of "from" (a state path) or "on" (an event-token name).${y}`),l){const t=e.on;return"string"==typeof t&&0!==t.length||$(`${pt} ${c} "on" must be a non-empty event-token name.${y}`),n.has(t)||$(`${pt} ${c} on "${t}" is not declared in ${a}.${w(t,n)}${y}`),{kind:"event",tokenName:t}}const f=e.from;"string"!=typeof f&&$(`${pt} ${c} "from" must be a state path string.${y}`);const d=gt(c,"from",f),h=yt(d,o)??i?.recursiveGetterOwning(f)??null;null!==h&&$(wt(c,"from",f,h));const p=yt(d,s);return null!==p&&$(function(t,e,n){return`${pt} ${t} from "${e}" ${n===e?"is a setter without a getter":`is under the setter without a getter "${n}"`}, so it always reads undefined and every fold would receive undefined. Fold the plain value the setter writes, or use "on" with an event token.${y}`}(c,f,p)),(f===t||f.startsWith(t+r))&&$(`${pt} ${c} from "${f}" reads the entry's own output — the scan would fold its own writes forever.${y}`),{kind:"path",path:f,pathInfo:d}}function jt(t,e,n,o){if(void 0===e)return mt;const a=$t(t);Array.isArray(e)||$(`${pt} ${a} "resetOn" must be an array of state paths.${y}`);const i=[];for(const t of e){"string"!=typeof t&&$(`${pt} ${a} "resetOn" must contain only state path strings.${y}`);const e=gt(a,"resetOn",t);e.wildcardCount>0&&$(`${pt} ${a} resetOn "${t}" must not contain "${s}" — a reset returns the whole output to "initial".${y}`);const c=yt(e,o);null!==c&&$(wt(a,"resetOn",t,c)),"path"===n.kind&&t===n.path&&$(`${pt} ${a} resetOn "${t}" is the entry's own "from" — every change would reset instead of fold.${y}`),"path"===n.kind&&t.startsWith(n.path+r)&&$(`${pt} ${a} resetOn "${t}" sits under the entry's own "from" "${n.path}" — every write of "from" also lands it, so the reset would win every time and nothing would fold.${y}`),i.push(t)}return i}function Ot(t,n,r=null){const s=t[e];if(void 0===s)return null;("object"!=typeof s||null===s||Array.isArray(s))&&$(`${pt} ${e} must be an object mapping output names to scan definitions ({ from | on, initial, fold, resetOn? }).${y}`);const a=new Set,c=new Set,u=new Set,l=new Map;for(const[e,n]of Object.entries(z(t)))"function"==typeof n.get?a.add(e):"function"==typeof n.set&&u.add(e),"function"==typeof n.set&&c.add(e),"function"==typeof n.value&&l.set(e,n.value);const f=function(t){m(t);const e=t[o];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),d=[];let h=0;for(const[t,e]of Object.entries(s)){vt(t,a,c,f),("object"!=typeof e||null===e||Array.isArray(e))&&$(`${pt} ${$t(t)} must be an object ({ from | on, initial, fold, resetOn? }).${y}`);const o=e;bt(t,l,o);const s=kt(t,o,n,a,u,r);"initial"in o||$(`${pt} ${$t(t)} requires "initial" — the seed of the accumulator and the value "resetOn" returns to.${y}`),"function"!=typeof o.fold&&$(`${pt} ${$t(t)} fold must be a function.${y}`);const i=jt(t,o.resetOn,s,a);d.push({name:t,source:s,fold:o.fold,initial:o.initial,resetOn:i,order:h++})}return function(t){const n=new Set(t.map(t=>t.name)),o=new Map;for(const r of t){for(const t of r.resetOn){const o=i(t).segments[0];n.has(o)&&$(`${pt} ${$t(r.name)} resetOn "${t}" reads the ${e} output "${o}" — a reset driven by an accumulator is a feedback loop. Reset on the plain inputs instead.${y}`)}if("path"===r.source.kind){const t=r.source.pathInfo.segments[0];n.has(t)&&o.set(r.name,t)}}for(const t of o.keys()){const r=[t];let s=o.get(t);for(;void 0!==s&&r.length<=n.size;)s===t&&$(`${pt} ${e} entries ${[...r,t].map(t=>`"${t}"`).join(" → ")} feed each other through "from" — each fold would re-trigger the next forever.${y}`),r.push(s),s=o.get(s)}}(d),d.length>0?d:null}function Pt(t){const e=t.fold;return(n,o,...r)=>{const s=n;let a="read-output";try{const n=s[t.name];a="threw";const i=function(t){return K.has(t)}(t),c=i&&!ot(n,t.initial)?et(t.initial):n,u=e(c,o,...r);if(ft(u))return void dt(t.name,u);Object.is(u,n)||(a="write",s[t.name]=u,st(t.name,u)),i&&J(t)}catch(e){lt(t.name,e,a)}}}function It(t,e,n){const o=function(t,e){B(t);const n=new Map,o=new Map,r=new Map;for(const t of e){"path"===t.source.kind&&L(n,t.source.path,t);for(const e of t.resetOn)L(o,e,t),"event"===t.source.kind&&L(r,e,t)}const s={entries:new Set(e),byFromPath:n,byResetPath:o,eventResetByPath:r};return D.set(t,s),s}(t,e);for(const o of e){const e=n.get(o.name);"event"===o.source.kind&&void 0!==e&&(o.resetOn.some(n=>e.includes(n)&&g().hasQueuedPath(t,n))&&V(o))}const r=new Set;for(const e of o.byFromPath.keys())r.add(e),t.setPathInfo(e,"prop","scan");for(const e of o.byResetPath.keys())t.setPathInfo(e,"prop","scan");return r.size>0?r:null}const xt="scanEntries",St={order:8,validate(t,e,n){const o=Ot(e,n.get("eventTokenNames")??new Set,n.get("recursionRegistry")??null);n.set(xt,o)},applyEarly(t,e,n){const o=n.get(xt)??null;null!==o&&(function(t,e){for(const n of e)if(!(n.name in t)){const e=et(n.initial);t[n.name]=e,st(n.name,e)}}(e,o),function(t,e){for(const n of e)"event"===n.source.kind&&v(t,n.source.tokenName).subscribe(Pt(n))}(t,o))},register(t,e,n){const o=n.get(xt)??null,r=function(t){const e=new Map,n=G(t);if(void 0!==n)for(const t of n.entries)J(t)&&e.set(t.name,t.resetOn);return B(t),e}(t);t.setScanPaths?.(null===o?null:It(t,o,r))}};let At=!1;const Et=Object.freeze([]),Mt=Object.freeze([]);function zt(t,e,n){const o=new Set([n]),r=[n];for(;r.length>0;){const n=r.pop(),s=t.staticDependency.get(n)??Et,a=t.dynamicDependency.get(n)??Et,i=e.byFromPath.get(n)??Mt;for(const t of[...s,...a,...i.map(t=>t.name)])o.has(t)||(o.add(t),r.push(t))}return o}const Wt=Symbol("wcs-stream-last-notified-uncertain"),Rt=new WeakMap;function Ct(t,e){const n=Rt.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function _t(t,e){const n=Rt.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:Wt,error:Object.is(o.error,null)?null:Wt})}const Dt=new Set;function Ft(t){Dt.delete(t)}const Nt=new WeakMap;function Tt(t){return Nt.get(t)??new Map}function Lt(t){Ft(t);const e=Nt.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,_t(t,n.name)}const Gt=(t,e)=>e,Bt=new Set;function Ht(t,e){m(e);const n=e[o];if(void 0===n)return void Ct(t,Bt);"object"==typeof n&&null!==n||$(`${o} must be an object mapping stream names to stream definitions.`);const a=new Map,i=z(e);for(const[c,u]of Object.entries(n)){0===c.length&&$(`${o} entry name must be a non-empty string.`),c.includes(r)&&$(`${o} entry "${c}" must be a flat property name ("${r}" is not allowed).`),c.includes(s)&&$(`${o} entry "${c}" must be a flat property name ("${s}" is not allowed).`),c.startsWith("$")&&$(`${o} entry "${c}" must not start with "$" (reserved namespace).`),c in Object.prototype&&$(`${o} entry "${c}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),t.getterPaths.has(c)&&$(`${o} entry "${c}" conflicts with a getter declared on the state.`),t.setterPaths.has(c)&&$(`${o} entry "${c}" conflicts with a setter declared on the state.`),"object"==typeof u&&null!==u||$(`${o} entry "${c}" must be an object ({ args?, source, fold?, initial? }).`);const n=u,l=i[c]?.value;"function"!=typeof l||l===n.initial||at(c,l)||$(`${o} entry "${c}" conflicts with a method (a function-valued property) declared on the state. The value is a property the runtime owns.`),"function"!=typeof n.source&&$(`${o} entry "${c}" source must be a function.`);const f=void 0!==n.fold;f&&"function"!=typeof n.fold&&$(`${o} entry "${c}" fold must be a function.`),f&&!("initial"in n)&&$(`${o} entry "${c}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==n.args&&"function"!=typeof n.args&&$(`${o} entry "${c}" args must be a function.`);const d={name:c,definition:{args:n.args??null,source:n.source,fold:n.fold??Gt,initial:n.initial},status:"idle",error:null,controller:null,depAddresses:new Set};c in e||(e[c]=d.definition.initial,st(c,d.definition.initial)),a.set(c,d)}!function(t,e){Nt.set(t,e)}(t,a),Ct(t,new Set(a.keys()))}const Kt=new WeakMap,qt=new WeakMap;function Qt(t,e,n){return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;const r=Tt(t).get(o);return void 0!==r?n(r):void 0},has:(e,n)=>"string"==typeof n&&Tt(t).has(n),ownKeys:()=>Array.from(Tt(t).keys()),getOwnPropertyDescriptor(e,o){if("string"!=typeof o)return;const r=Tt(t).get(o);return void 0!==r?{configurable:!0,enumerable:!0,value:n(r)}:void 0},set(){$(`${e} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){$(`${e} namespace is read-only; deleting from it is not allowed.`)}})}function Ut(t){const e=Kt.get(t);if(void 0!==e)return e;const n=Qt(t,u,t=>t.status);return Kt.set(t,n),n}function Vt(t){const e=qt.get(t);if(void 0!==e)return e;const n=Qt(t,l,t=>t.error);return qt.set(t,n),n}function Jt(t){Kt.delete(t),qt.delete(t)}let Xt=null;function Yt(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}const Zt={read(t,e){!function(t,e){null!==Xt&&Xt.add(k(t,e))}(t,e);const n=e.pathInfo.segments[0];return n===u?Yt(Ut(t),e.pathInfo.segments):n===l?Yt(Vt(t),e.pathInfo.segments):W},get:(t,e)=>e===u?Ut(t.stateElement):e===l?Vt(t.stateElement):W};async function te(t,e,n,r){let s=null;const a=()=>{if(null!==s)try{s.return?.()?.then?.(void 0,()=>{})}catch{}};n.addEventListener("abort",a,{once:!0});try{const i=await t(e,n);if(s=function(t,e){if("function"==typeof t?.getReader)return async function*(t,e){const n=t.getReader(),o=()=>{n.cancel().catch(()=>{})};e.addEventListener("abort",o,{once:!0});try{for(;;){const{done:t,value:e}=await n.read();if(t)return;yield e}}finally{e.removeEventListener("abort",o),n.releaseLock()}}(t,e);if("function"==typeof t?.[Symbol.asyncIterator])return t;throw new TypeError(`[@wcstack/state] ${o}: source must return an AsyncIterable or a ReadableStream (got neither).`)}(i,n)[Symbol.asyncIterator](),n.aborted)return void a();for(;;){const t=await s.next();if(t.done)break;if(n.aborted)return;r.fold(t.value)}if(n.aborted)return;r.done()}catch(t){if(n.aborted)return;r.fail(t)}finally{n.removeEventListener("abort",a)}}function ee(t){ce();const e=Tt(t);if(0!==e.size){!function(t){Dt.add(t)}(t);for(const n of e.values())ne(t,n)}}function ne(t,n){n.controller?.abort();const s=new AbortController;n.controller=s;const a=function(t,e){const n=e.definition.args;if(null===n)return void e.depAddresses.clear();const s=Xt,a=new Set;let i;Xt=a;try{t.createState("readonly",t=>{i=n(t)})}finally{Xt=s}i instanceof Promise&&$(`${o} entry "${e.name}" args must be synchronous (it returned a Promise).`);const c=`${u}${r}${e.name}`,f=`${l}${r}${e.name}`;for(const n of a){const r=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==t||r.path!==e.name&&r.path!==c&&r.path!==f||$(`${o} entry "${e.name}" args must not read the stream itself ("${r.path}"): a self-dependency would restart the stream on its own writes (infinite loop).`),r.wildcardCount>0&&$(`${o} entry "${e.name}" args must not read wildcard paths ("${r.path}"): wildcard dependencies are out of scope.`)}return e.depAddresses=a,i}(t,n);!function(t,n){const r=G(t);if(void 0!==r&&0!==n.depAddresses.size)for(const s of r.entries){if("path"!==s.source.kind||s.source.pathInfo.segments[0]!==n.name)continue;const a=zt(t,r,s.name);for(const t of n.depAddresses){const r=t.absolutePathInfo.pathInfo.path;a.has(r)&&$(`[wcs/scan-feedback-loop] ${o} entry "${n.name}" args read "${r}", which is derived from the ${e} output "${s.name}" that this stream feeds. Every landing would restart the stream on its own result. Advance the cursor from an event ($on) and keep it a plain property instead of deriving it from the accumulator.`)}}}(t,n),t.createState("writable",t=>{t[n.name]=n.definition.initial}),st(n.name,n.definition.initial),oe(t,n,"active",null);const i=n.definition,c={fold(e){t.createState("writable",t=>{const o=i.fold(t[n.name],e);t[n.name]=o,st(n.name,o)})},done(){oe(t,n,"done",null)},fail(e){oe(t,n,"error",e),s.abort()}};te(i.source,a,s.signal,c)}function oe(t,e,n,o){e.status=n,e.error=o;const s=function(t,e){return Rt.get(t)?.get(e)??{status:"idle",error:null}}(t,e.name),a=s.status!==n,i=!Object.is(s.error,o);(a||i)&&(!function(t,e,n,o){let r=Rt.get(t);void 0===r&&(r=new Map,Rt.set(t,r)),r.set(e,{status:n,error:o})}(t,e.name,n,o),t.createState("writable",t=>{a&&t.$postUpdate(`${u}${r}${e.name}`),i&&t.$postUpdate(`${l}${r}${e.name}`)}))}function re(t){const e=Dt;if(0===e.size)return;const n=[];for(const o of e)for(const e of Tt(o).values())for(const r of e.depAddresses)if(t.has(r)){n.push({stateElement:o,entry:e});break}for(const{stateElement:t,entry:o}of n)if(e.has(t)&&Tt(t).get(o.name)===o)try{ne(t,o)}catch(n){o.controller?.abort(),e.has(t)&&Tt(t).get(o.name)===o&&oe(t,o,"error",n)}}let se=!1;const ae=new WeakMap,ie={order:20,apply(t,e){var n;Jt(t),Lt(n=t),Ft(n),Nt.delete(n),Ht(t,e),void 0!==e[o]&&t.attachAddressHooks?.("streams",o)},activate(t,e){if(!C()&&null!=t.connectedRootNode){if(null===e){if(!0!==t.initialized)return;return ee(t),void ae.set(t,t.connectGeneration??0)}e===t.connectGeneration&&ae.get(t)!==e&&ee(t)}},deactivate(t){Lt(t),Jt(t)}};function ce(){se||(se=!0,R("streams",Zt),t("streams",ie),j(re,f))}let ue=0,le=0;function fe(t){ue=t+1}function de(){ue=0}function he(){ue>le&&(le=ue)}const pe=new WeakMap;function me(t,e,n){let o=pe.get(t);void 0===o&&(o=new Map,pe.set(t,o)),o.set(e,n)}const $e=new Map;function ye(t,e){$e.has(t)||$e.set(t,e)}function we(t){return $e.get(t)}const ge=new WeakMap,ve=new WeakMap,be=new Set,ke=new Map;function je(t){return ge.get(t)??ke}function Oe(t){be.add(t),function(t){const e=D.get(t);void 0!==e&&(T(e)&&F.add(t),function(t){return t.eventResetByPath.size>0}(e)&&N.add(t))}(t)}function Pe(){return be}function Ie(t,e){let n=ve.get(t);void 0===n&&(n=new Map,ve.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 xe=new Map;function Se(t){return ve.get(t)??xe}function Ae(t){0===t.length&&$(`[wcs/watch-declaration-invalid] ${d} entry name must be a non-empty state path.`),t.startsWith("$")&&$(`[wcs/watch-declaration-invalid] ${d} entry "${t}" must not start with "$" (reserved namespace).${y}`),t.includes("@")&&$(`[wcs/watch-declaration-invalid] ${d} entry "${t}" must not contain "@" — the name selector was removed in v2; watch only paths of the state tree.${y}`),t in Object.prototype&&$(`[wcs/watch-declaration-invalid] ${d} entry "${t}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const e=i(t);for(const n of e.segments)0===n.length&&$(`[wcs/watch-declaration-invalid] ${d} entry "${t}" has an empty path segment.${y}`);return e.wildcardCount>c&&$(`[wcs/watch-declaration-invalid] ${d} entry "${t}" exceeds the maximum wildcard depth (${c}).`),e}function Ee(t,e){const n=e[d];if(void 0===n)return null;"object"==typeof n&&null!==n||$(`[wcs/watch-declaration-invalid] ${d} must be an object mapping state paths to handler functions.${y}`);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] ${d} entry "${e}" must be a function.${y}`);const n=Ae(e);o.set(e,{path:e,pathInfo:n,handler:a,order:s++}),r.add(e),t.setPathInfo(e,"prop","watch")}return function(t,e){ge.set(t,e)}(t,o),r.size>0?r:null}const Me={writeObserve(t,e,n,o,r){if(!r)return;const s=t.watchPaths,a=t.scanPaths;!0!==s?.has(e)&&!0!==a?.has(e)||ye(n,o)},swapped(t,e,n){var o;o=n,$e.has(o)&&ye(e,we(n))}};function ze(t){for(let e=t;null!==e;e=e.parentListIndex)if(O(e))return!0;return!1}function We(t,e,n){const o=n.absAddress.listIndex;let r="current",s=null;for(let a=0;a<e.wildcardCount;a++){const i=t[P](I(e.wildcardParentPathInfos[a],s)),c=x(i)?.[n.indexes[a]];if(void 0===c)return"gone";const u=S(o,a,e.wildcardCount);if(c!==u&&!A(c,u)){if(O(u))return"gone";r="replaced"}s=c}return r}function Re(t,e,n){const o=new Map;for(const r of n){const n=We(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 Ce=Object.freeze([]);function _e(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 De(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 Fe(t,e){return e.has(t.stateElement)&&!0===G(t.stateElement)?.entries.has(t.entry)}function Ne(t){const{entry:e,stateElement:n}=t;"event"!==e.source.kind||e.resetOn.some(t=>Te(n,t))||J(e)}function Te(t,e){return g().hasQueuedPath(t,e)}function Le(t,e){!function(t,e,n){if(0!==q)for(const o of t){const t=o.absolutePathInfo.stateElement;if(!0===e?.has(t))continue;const r=Q(o);if(void 0!==r)for(const e of r)e.resetOn.some(e=>n(t,e))||J(e)}}(t,e,Te)}function Ge(t,e,n){return 0===e.pathInfo.wildcardCount?t[e.path]:t.$resolve(e.path,n.indexes)}function Be(t,n,o){if(!Fe(t,o))return Ne(t),null;const{stateElement:r,entry:s}=t;if(t.reset)return{group:t,next:s.initial};const a=s.source;if(function(t,e){for(const n of e.pathInfo.cumulativePaths)if(t.getterPaths.has(n))return!0;return!1}(r,a))return function(t,n,o){if(ht.has(t))return;ht.add(t);const r=`[wcs/scan-source-computed] ${e} entry "${n}" from "${o}" 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] ${r}`),ut(n,"fold",new Error(r))}(s,s.name,a.path),null;if(function(t,e,n){const o=Tt(t).get(e);if(void 0===o)return!1;for(const t of o.depAddresses)if(n.has(t))return!0;return!1}(r,a.pathInfo.segments[0],n))return null;const i={plan:null,failure:"read-output"};try{r.createState("readonly",e=>{const n=e[s.name];i.failure="read-rows";const o=0===a.pathInfo.wildcardCount?t.rows:Re(e,a.pathInfo,t.rows);i.failure="threw";const r=s.fold;let c=n;for(const t of o.sort(De)){let n;try{n=Ge(e,a,t)}catch(t){lt(s.name,t,"read-source");continue}const o=r(c,n,we(t.absAddress),...t.indexes);if(ft(o))return void dt(s.name,o);c=o}Object.is(c,n)||(i.plan={group:t,next:c})})}catch(t){lt(s.name,t,i.failure)}return i.plan}function He(t,e){const{group:n}=t;if(!Fe(n,e))return void Ne(n);const{stateElement:o,entry:r}=n;if(!n.reset||"event"!==r.source.kind||J(r))try{o.createState("writable",e=>{const o=e[r.name];if(n.reset?!ot(o,r.initial):!Object.is(o,t.next)){const o=n.reset?et(r.initial):t.next;e[r.name]=o,st(r.name,o)}})}catch(t){lt(r.name,t,"write")}}function Ke(t,e,n){if(Le(t,e),0===F.size)return Ce;const o=new Map;for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=G(t);if(void 0===r)continue;const s=n.absolutePathInfo.pathInfo,a=r.byFromPath.get(s.path);if(void 0!==a){let e=[];if(s.wildcardCount>0){if(null===n.listIndex)continue;e=E(n.listIndex,s.wildcardCount)}for(const r of a)_e(o,t,r).rows.push({absAddress:n,indexes:e})}const i=r.byResetPath.get(s.path);if(void 0!==i)for(const e of i)_e(o,t,e).reset=!0}if(0===o.size)return Ce;const r=Array.from(o.values()).sort((t,e)=>t.entry.order-e.entry.order),s=[];fe(n);try{for(const n of r){const o=Be(n,t,e);null!==o&&s.push(o)}}finally{de()}return s}function qe(t){en(),(0!==je(t).size||0!==Se(t).size||function(t){const e=D.get(t);return void 0!==e&&T(e)}(t))&&(Oe(t),function(t){const e=[];for(const n of je(t).values())Qe(t,n)&&e.push(n);for(const n of Se(t).values())for(const o of n)Qe(t,o)&&e.push(o);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{me(t,M(t,o.pathInfo,null),n[o.path])}catch(e){Ve(t,o.path,"prime",e)}})}(t))}function Qe(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const Ue={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function Ve(t,e,o,r){console.error(`[@wcstack/state] $watch ${Ue[o]} "${e}" threw.`,r),null!==n&&n({type:"state:watch-error",phase:o,path:e,error:r})}function Je(t){const e=Pe();try{if(0===e.size)return void Le(t,e);const o=function(){const t=le;return le=0,t}();if(o>p){Le(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:p,paths:e}),void(null!==n&&n({type:"state:watch-chain-limit",maxDepth:p,paths:e}))}!function(t,e,n){if(0!==t.length){fe(n);try{for(const n of t)He(n,e)}finally{de()}}}(Ke(t,e,o),e,o),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=je(t).get(r),a=Se(t).get(r);if(void 0===s&&void 0===a)continue;const i=void 0===s?[]:[s];void 0!==a&&i.push(...a);for(const e of i){let r=[];if(e.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=E(n.listIndex,e.pathInfo.wildcardCount)}o.push({stateElement:t,entry:e,absAddress:n,indexes:r})}}if(0===o.length)return;o.sort(Ye);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];(ze(o.absAddress.listIndex)||r?.entry===o.entry&&Xe(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(Re(t,o.pathInfo,e));for(const t of e)r.has(t)||n.add(t)})}catch(t){Ve(0,o.path,"evaluate",t);for(const t of e)n.add(t)}}return t.filter(t=>!n.has(t))}(o);fe(n);try{for(const t of r){if(!e.has(t.stateElement))continue;const n=je(t.stateElement).get(t.entry.path)===t.entry,o=!0===Se(t.stateElement).get(t.entry.path)?.includes(t.entry);(n||o)&&Ze(t)}}finally{de()}}(t,e,o)}finally{$e.clear()}}function Xe(t,e){for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function Ye(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 Ze(t){const{stateElement:e,entry:o,absAddress:r,indexes:s}=t,a=Qe(e,o);try{e.createState("writable",t=>{let i;try{i=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,o,s)}catch(t){return void Ve(0,o.path,"evaluate",t)}const c=a?function(t,e){return pe.get(t)?.get(e)}(e,r):we(r);a&&me(e,r,i),null!==n&&n({type:"state:watch-fired",path:o.path,stateElement:e}),o.handler.call(t,i,c,...s)})}catch(t){Ve(0,o.path,"handler",t)}}let tn=!1;function en(){tn||(tn=!0,R("watch",Me),t("watch",nn),j(Je,h),b(he),_({assertValidPath:Ae,addEntries:Ie,start:qe}))}const nn={order:10,register(t,n){var o;o=t,be.delete(o),H(o),ge.delete(o),function(t){pe.delete(t)}(t);const r=Ee(t,n);t.setWatchPaths?.(r),null===r&&null==t.scanPaths||t.attachAddressHooks?.("watch",null!==r?d:e)},activate(t,e){C()||null==t.connectedRootNode||(null===e?!0===t.initialized:e===t.connectGeneration)&&qe(t)},deactivate(t){var e;e=t,be.delete(e),H(e)}},on={name:"temporal",install(){en(),At||(At=!0,t("scan",St),b(U)),ce()}};export{on as default,on as temporal};
1
+ import{r as t}from"../chunks/declarationHooks.js";import{S as e,d as n,a as o,D as r,W as s,b as a,g as i,M as c,c as u,e as l,f,h as d,i as h,j as p}from"../chunks/pathDiagnostics.js";import{n as m}from"../chunks/declarationAliases.js";import{r as y,L as $,d as w}from"../chunks/errorGuidance.js";import{c as g,d as v,e as b,l as k,f as j,i as O,h as P,j as I,k as x,m as S,n as A,o as M,p as E}from"../chunks/binder.js";import{g as z,N as W,r as R}from"../chunks/getAllPropertyDescriptors.js";import{i as C}from"../chunks/filterRegistry.js";import{s as _}from"../chunks/featureBridge.js";const D=new WeakMap,F=new Set,N=new Set;function T(t){return t.byFromPath.size>0||t.byResetPath.size>0}function L(t,e,n){const o=t.get(e);void 0===o?t.set(e,[n]):o.push(n)}function G(t){return D.get(t)}function B(t){H(t),D.delete(t)}function H(t){F.delete(t),N.delete(t)}const K=new WeakSet;let q=0;function Q(t){return G(t.absolutePathInfo.stateElement)?.eventResetByPath.get(t.absolutePathInfo.pathInfo.path)}function U(t){if(0===N.size)return;if(e=t.absolutePathInfo.stateElement,!N.has(e))return;var e;const n=Q(t);if(void 0!==n)for(const t of n)V(t)}function V(t){K.has(t)||(K.add(t),q++)}function J(t){return!!K.delete(t)&&(q--,!0)}const X=/^(?:0|[1-9]\d*)$/;function Y(t,e){const n=Object.getOwnPropertyDescriptor(t,e);return!0===n.enumerable&&"value"in n}function Z(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&&X.test(e)&&Y(t,e))?"array":null}return(e===Object.prototype||null===e)&&Reflect.ownKeys(t).every(e=>"string"==typeof e&&Y(t,e))?"object":null}function tt(t,e){const n=Z(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]=tt(o[t],e);return s}function et(t){return tt(t,new Map)}function nt(t,e,n){if(Object.is(t,e))return!0;const o=Z(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(Z(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(!nt(r[e],s[e],n))return!1;return!0}return Object.keys(s).every(t=>Object.prototype.hasOwnProperty.call(r,t)&&nt(r[t],s[t],n))}function ot(t,e){return nt(t,e,new Map)}const rt=new WeakMap;function st(t,e){if("function"!=typeof e)return;const n=rt.get(e);void 0===n?rt.set(e,new Set([t])):n.add(t)}function at(t,e){return"function"==typeof e&&!0===rt.get(e)?.has(t)}const it={"read-source":t=>`${e} could not read a "from" value for "${t}". That landing was not folded; the other landings of the batch still were.`,"read-rows":t=>`${e} could not read the rows of "from" for "${t}". Nothing was folded or written.`,"read-output":t=>`${e} could not read the output "${t}". Nothing was folded or written.`,threw:t=>`${e} fold for "${t}" threw. The output was not written.`,"returned-promise":t=>`${e} fold for "${t}" returned a Promise. fold must be synchronous and return the next value; the output was not written.`,write:t=>`${e} could not write the output "${t}".`},ct={"read-source":"evaluate","read-rows":"evaluate","read-output":"evaluate",threw:"fold","returned-promise":"fold",write:"write"};function ut(t,o,r){null!==n&&n({type:"state:watch-error",phase:o,path:`${e}.${t}`,error:r})}function lt(t,e,n){console.error(`[@wcstack/state] ${it[n](t)}`,e),ut(t,ct[n],e)}function ft(t){return null!==t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function dt(t,n){n.then(void 0,()=>{}),lt(t,new TypeError(`${e} fold for "${t}" returned a Promise. fold must be synchronous and return the next value.`),"returned-promise")}const ht=new WeakSet;const pt="[wcs/scan-declaration-invalid]",mt=Object.freeze([]);function yt(t){return`${e} entry "${t}"`}function $t(t,e){for(const n of t.cumulativePaths)if(e.has(n))return n;return null}function wt(t,e,n,o){return`[wcs/scan-source-computed] ${t} ${e} "${n}" ${o===n?"is a getter":o.includes(`${s}${s}`)?`is computed by the recursive getter "${o}"`:`is under the getter "${o}"`}. A getter re-evaluates whenever its inputs change, so folding it would count re-evaluations, not events. Fold the plain value the getter reads, or use "on" with an event token.${$}`}function gt(t,e,n){0===n.length&&y(`${pt} ${t} "${e}" must be a non-empty state path.${$}`),n.startsWith("$")&&y(`${pt} ${t} ${e} "${n}" must not start with "$" (reserved namespace).${$}`),n.includes("@")&&y(`${pt} ${t} ${e} "${n}" must not contain "@" — there is a single state tree per root.${$}`),n in Object.prototype&&y(`${pt} ${t} ${e} "${n}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").${$}`);const o=i(n);for(const r of o.segments)0===r.length&&y(`${pt} ${t} ${e} "${n}" has an empty path segment.${$}`);return o.wildcardCount>c&&y(`${pt} ${t} ${e} "${n}" exceeds the maximum wildcard depth (${c}).`),o}function vt(t,n,a,i){const c=yt(t);0===t.length&&y(`${pt} ${e} entry name must be a non-empty string.${$}`),(t.includes(r)||t.includes(s))&&y(`${pt} ${c} must be a flat property name ("${r}" and "${s}" are not allowed). The output is a property the runtime owns.${$}`),t.startsWith("$")&&y(`${pt} ${c} must not start with "$" (reserved namespace).${$}`),t in Object.prototype&&y(`${pt} ${c} must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").${$}`),n.has(t)&&y(`${pt} ${c} conflicts with a getter declared on the state.${$}`),a.has(t)&&y(`${pt} ${c} conflicts with a setter declared on the state.${$}`),i.has(t)&&y(`${pt} ${c} conflicts with the ${o} entry of the same name — each output has exactly one owner.${$}`)}function bt(t,e,n){const o=e.get(t);e.has(t)&&o!==n.initial&&!at(t,o)&&y(`${pt} ${yt(t)} conflicts with a method (a function-valued property) declared on the state. The output is a property the runtime owns.${$}`)}function kt(t,e,n,o,s,i){const c=yt(t),u=void 0!==e.from,l=void 0!==e.on;if(u===l&&y(`${pt} ${c} must declare exactly one of "from" (a state path) or "on" (an event-token name).${$}`),l){const t=e.on;return"string"==typeof t&&0!==t.length||y(`${pt} ${c} "on" must be a non-empty event-token name.${$}`),n.has(t)||y(`${pt} ${c} on "${t}" is not declared in ${a}.${w(t,n)}${$}`),{kind:"event",tokenName:t}}const f=e.from;"string"!=typeof f&&y(`${pt} ${c} "from" must be a state path string.${$}`);const d=gt(c,"from",f),h=$t(d,o)??i?.recursiveGetterOwning(f)??null;null!==h&&y(wt(c,"from",f,h));const p=$t(d,s);return null!==p&&y(function(t,e,n){return`${pt} ${t} from "${e}" ${n===e?"is a setter without a getter":`is under the setter without a getter "${n}"`}, so it always reads undefined and every fold would receive undefined. Fold the plain value the setter writes, or use "on" with an event token.${$}`}(c,f,p)),(f===t||f.startsWith(t+r))&&y(`${pt} ${c} from "${f}" reads the entry's own output — the scan would fold its own writes forever.${$}`),{kind:"path",path:f,pathInfo:d}}function jt(t,e,n,o){if(void 0===e)return mt;const a=yt(t);Array.isArray(e)||y(`${pt} ${a} "resetOn" must be an array of state paths.${$}`);const i=[];for(const t of e){"string"!=typeof t&&y(`${pt} ${a} "resetOn" must contain only state path strings.${$}`);const e=gt(a,"resetOn",t);e.wildcardCount>0&&y(`${pt} ${a} resetOn "${t}" must not contain "${s}" — a reset returns the whole output to "initial".${$}`);const c=$t(e,o);null!==c&&y(wt(a,"resetOn",t,c)),"path"===n.kind&&t===n.path&&y(`${pt} ${a} resetOn "${t}" is the entry's own "from" — every change would reset instead of fold.${$}`),"path"===n.kind&&t.startsWith(n.path+r)&&y(`${pt} ${a} resetOn "${t}" sits under the entry's own "from" "${n.path}" — every write of "from" also lands it, so the reset would win every time and nothing would fold.${$}`),i.push(t)}return i}function Ot(t,n,r=null){const s=t[e];if(void 0===s)return null;("object"!=typeof s||null===s||Array.isArray(s))&&y(`${pt} ${e} must be an object mapping output names to scan definitions ({ from | on, initial, fold, resetOn? }).${$}`);const a=new Set,c=new Set,u=new Set,l=new Map;for(const[e,n]of Object.entries(z(t)))"function"==typeof n.get?a.add(e):"function"==typeof n.set&&u.add(e),"function"==typeof n.set&&c.add(e),"function"==typeof n.value&&l.set(e,n.value);const f=function(t){m(t);const e=t[o];return"object"!=typeof e||null===e?new Set:new Set(Object.keys(e))}(t),d=[];let h=0;for(const[t,e]of Object.entries(s)){vt(t,a,c,f),("object"!=typeof e||null===e||Array.isArray(e))&&y(`${pt} ${yt(t)} must be an object ({ from | on, initial, fold, resetOn? }).${$}`);const o=e;bt(t,l,o);const s=kt(t,o,n,a,u,r);"initial"in o||y(`${pt} ${yt(t)} requires "initial" — the seed of the accumulator and the value "resetOn" returns to.${$}`),"function"!=typeof o.fold&&y(`${pt} ${yt(t)} fold must be a function.${$}`);const i=jt(t,o.resetOn,s,a);d.push({name:t,source:s,fold:o.fold,initial:o.initial,resetOn:i,order:h++})}return function(t){const n=new Set(t.map(t=>t.name)),o=new Map;for(const r of t){for(const t of r.resetOn){const o=i(t).segments[0];n.has(o)&&y(`${pt} ${yt(r.name)} resetOn "${t}" reads the ${e} output "${o}" — a reset driven by an accumulator is a feedback loop. Reset on the plain inputs instead.${$}`)}if("path"===r.source.kind){const t=r.source.pathInfo.segments[0];n.has(t)&&o.set(r.name,t)}}for(const t of o.keys()){const r=[t];let s=o.get(t);for(;void 0!==s&&r.length<=n.size;)s===t&&y(`${pt} ${e} entries ${[...r,t].map(t=>`"${t}"`).join(" → ")} feed each other through "from" — each fold would re-trigger the next forever.${$}`),r.push(s),s=o.get(s)}}(d),d.length>0?d:null}function Pt(t){const e=t.fold;return(n,o,...r)=>{const s=n;let a="read-output";try{const n=s[t.name];a="threw";const i=function(t){return K.has(t)}(t),c=i&&!ot(n,t.initial)?et(t.initial):n,u=e(c,o,...r);if(ft(u))return void dt(t.name,u);Object.is(u,n)||(a="write",s[t.name]=u,st(t.name,u)),i&&J(t)}catch(e){lt(t.name,e,a)}}}function It(t,e,n){const o=function(t,e){B(t);const n=new Map,o=new Map,r=new Map;for(const t of e){"path"===t.source.kind&&L(n,t.source.path,t);for(const e of t.resetOn)L(o,e,t),"event"===t.source.kind&&L(r,e,t)}const s={entries:new Set(e),byFromPath:n,byResetPath:o,eventResetByPath:r};return D.set(t,s),s}(t,e);for(const o of e){const e=n.get(o.name);"event"===o.source.kind&&void 0!==e&&(o.resetOn.some(n=>e.includes(n)&&g().hasQueuedPath(t,n))&&V(o))}const r=new Set;for(const e of o.byFromPath.keys())r.add(e),t.setPathInfo(e,"prop","scan");for(const e of o.byResetPath.keys())t.setPathInfo(e,"prop","scan");return r.size>0?r:null}const xt="scanEntries",St={order:8,validate(t,e,n){const o=Ot(e,n.get("eventTokenNames")??new Set,n.get("recursionRegistry")??null);n.set(xt,o)},applyEarly(t,e,n){const o=n.get(xt)??null;null!==o&&(function(t,e){for(const n of e)if(!(n.name in t)){const e=et(n.initial);t[n.name]=e,st(n.name,e)}}(e,o),function(t,e){for(const n of e)"event"===n.source.kind&&v(t,n.source.tokenName).subscribe(Pt(n))}(t,o))},register(t,e,n){const o=n.get(xt)??null,r=function(t){const e=new Map,n=G(t);if(void 0!==n)for(const t of n.entries)J(t)&&e.set(t.name,t.resetOn);return B(t),e}(t);t.setScanPaths?.(null===o?null:It(t,o,r))}};let At=!1;const Mt=Object.freeze([]),Et=Object.freeze([]);function zt(t,e,n){const o=new Set([n]),r=[n];for(;r.length>0;){const n=r.pop(),s=t.staticDependency.get(n)??Mt,a=t.dynamicDependency.get(n)??Mt,i=e.byFromPath.get(n)??Et;for(const t of[...s,...a,...i.map(t=>t.name)])o.has(t)||(o.add(t),r.push(t))}return o}const Wt=Symbol("wcs-stream-last-notified-uncertain"),Rt=new WeakMap;function Ct(t,e){const n=Rt.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function _t(t,e){const n=Rt.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:Wt,error:Object.is(o.error,null)?null:Wt})}const Dt=new Set;function Ft(t){Dt.delete(t)}const Nt=new WeakMap;function Tt(t){return Nt.get(t)??new Map}function Lt(t){Ft(t);const e=Nt.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,_t(t,n.name)}const Gt=(t,e)=>e,Bt=new Set;function Ht(t,e){m(e);const n=e[o];if(void 0===n)return void Ct(t,Bt);"object"==typeof n&&null!==n||y(`${o} must be an object mapping stream names to stream definitions.`);const a=new Map,i=z(e);for(const[c,u]of Object.entries(n)){0===c.length&&y(`${o} entry name must be a non-empty string.`),c.includes(r)&&y(`${o} entry "${c}" must be a flat property name ("${r}" is not allowed).`),c.includes(s)&&y(`${o} entry "${c}" must be a flat property name ("${s}" is not allowed).`),c.startsWith("$")&&y(`${o} entry "${c}" must not start with "$" (reserved namespace).`),c in Object.prototype&&y(`${o} entry "${c}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),t.getterPaths.has(c)&&y(`${o} entry "${c}" conflicts with a getter declared on the state.`),t.setterPaths.has(c)&&y(`${o} entry "${c}" conflicts with a setter declared on the state.`),"object"==typeof u&&null!==u||y(`${o} entry "${c}" must be an object ({ args?, source, fold?, initial? }).`);const n=u,l=i[c]?.value;"function"!=typeof l||l===n.initial||at(c,l)||y(`${o} entry "${c}" conflicts with a method (a function-valued property) declared on the state. The value is a property the runtime owns.`),"function"!=typeof n.source&&y(`${o} entry "${c}" source must be a function.`);const f=void 0!==n.fold;f&&"function"!=typeof n.fold&&y(`${o} entry "${c}" fold must be a function.`),f&&!("initial"in n)&&y(`${o} entry "${c}" requires "initial" when fold is specified (reduce needs a seed value).`);void 0!==n.args&&"function"!=typeof n.args&&y(`${o} entry "${c}" args must be a function.`);const d={name:c,definition:{args:n.args??null,source:n.source,fold:n.fold??Gt,initial:n.initial},status:"idle",error:null,controller:null,depAddresses:new Set};c in e||(e[c]=d.definition.initial,st(c,d.definition.initial)),a.set(c,d)}!function(t,e){Nt.set(t,e)}(t,a),Ct(t,new Set(a.keys()))}const Kt=new WeakMap,qt=new WeakMap;function Qt(t,e,n){return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;const r=Tt(t).get(o);return void 0!==r?n(r):void 0},has:(e,n)=>"string"==typeof n&&Tt(t).has(n),ownKeys:()=>Array.from(Tt(t).keys()),getOwnPropertyDescriptor(e,o){if("string"!=typeof o)return;const r=Tt(t).get(o);return void 0!==r?{configurable:!0,enumerable:!0,value:n(r)}:void 0},set(){y(`${e} namespace is read-only; assigning to it is not allowed.`)},deleteProperty(){y(`${e} namespace is read-only; deleting from it is not allowed.`)}})}function Ut(t){const e=Kt.get(t);if(void 0!==e)return e;const n=Qt(t,u,t=>t.status);return Kt.set(t,n),n}function Vt(t){const e=qt.get(t);if(void 0!==e)return e;const n=Qt(t,l,t=>t.error);return qt.set(t,n),n}function Jt(t){Kt.delete(t),qt.delete(t)}let Xt=null;function Yt(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}const Zt={read(t,e){!function(t,e){null!==Xt&&Xt.add(k(t,e))}(t,e);const n=e.pathInfo.segments[0];return n===u?Yt(Ut(t),e.pathInfo.segments):n===l?Yt(Vt(t),e.pathInfo.segments):W},get:(t,e)=>e===u?Ut(t.stateElement):e===l?Vt(t.stateElement):W};let te=0,ee=null,ne=0;const oe=new WeakMap;function re(t){te=t+1}function se(){te=0}function ae(t){if(te>0){const e=ee??=new Map;te>(e.get(t)??0)&&e.set(t,te),ne=Math.max(ne,te)}}function ie(t,e){return oe.get(t)?.get(e)??0}async function ce(t,e,n,r){let s=null;const a=()=>{if(null!==s)try{s.return?.()?.then?.(void 0,()=>{})}catch{}};n.addEventListener("abort",a,{once:!0});try{const i=await t(e,n);if(s=function(t,e){if("function"==typeof t?.getReader)return async function*(t,e){const n=t.getReader(),o=()=>{n.cancel().catch(()=>{})};e.addEventListener("abort",o,{once:!0});try{for(;;){const{done:t,value:e}=await n.read();if(t)return;yield e}}finally{e.removeEventListener("abort",o),n.releaseLock()}}(t,e);if("function"==typeof t?.[Symbol.asyncIterator])return t;throw new TypeError(`[@wcstack/state] ${o}: source must return an AsyncIterable or a ReadableStream (got neither).`)}(i,n)[Symbol.asyncIterator](),n.aborted)return void a();for(;;){const t=await s.next();if(t.done)break;if(n.aborted)return;r.fold(t.value)}if(n.aborted)return;r.done()}catch(t){if(n.aborted)return;r.fail(t)}finally{n.removeEventListener("abort",a)}}function ue(t){ye();const e=Tt(t);if(0!==e.size){!function(t){Dt.add(t)}(t);for(const n of e.values())le(t,n)}}function le(t,n){n.controller?.abort();const s=new AbortController;n.controller=s;const a=function(t,e){const n=e.definition.args;if(null===n)return void e.depAddresses.clear();const s=Xt,a=new Set;let i;Xt=a;try{t.createState("readonly",t=>{i=n(t)})}finally{Xt=s}i instanceof Promise&&y(`${o} entry "${e.name}" args must be synchronous (it returned a Promise).`);const c=`${u}${r}${e.name}`,f=`${l}${r}${e.name}`;for(const n of a){const r=n.absolutePathInfo.pathInfo;n.absolutePathInfo.stateElement!==t||r.path!==e.name&&r.path!==c&&r.path!==f||y(`${o} entry "${e.name}" args must not read the stream itself ("${r.path}"): a self-dependency would restart the stream on its own writes (infinite loop).`),r.wildcardCount>0&&y(`${o} entry "${e.name}" args must not read wildcard paths ("${r.path}"): wildcard dependencies are out of scope.`)}return e.depAddresses=a,i}(t,n);!function(t,n){const r=G(t);if(void 0!==r&&0!==n.depAddresses.size)for(const s of r.entries){if("path"!==s.source.kind||s.source.pathInfo.segments[0]!==n.name)continue;const a=zt(t,r,s.name);for(const t of n.depAddresses){const r=t.absolutePathInfo.pathInfo.path;a.has(r)&&y(`[wcs/scan-feedback-loop] ${o} entry "${n.name}" args read "${r}", which is derived from the ${e} output "${s.name}" that this stream feeds. Every landing would restart the stream on its own result. Advance the cursor from an event ($on) and keep it a plain property instead of deriving it from the accumulator.`)}}}(t,n),t.createState("writable",t=>{t[n.name]=n.definition.initial}),st(n.name,n.definition.initial),fe(t,n,"active",null);const i=n.definition,c={fold(e){t.createState("writable",t=>{const o=i.fold(t[n.name],e);t[n.name]=o,st(n.name,o)})},done(){fe(t,n,"done",null)},fail(e){fe(t,n,"error",e),s.abort()}};ce(i.source,a,s.signal,c)}function fe(t,e,n,o){e.status=n,e.error=o;const s=function(t,e){return Rt.get(t)?.get(e)??{status:"idle",error:null}}(t,e.name),a=s.status!==n,i=!Object.is(s.error,o);(a||i)&&(!function(t,e,n,o){let r=Rt.get(t);void 0===r&&(r=new Map,Rt.set(t,r)),r.set(e,{status:n,error:o})}(t,e.name,n,o),t.createState("writable",t=>{a&&t.$postUpdate(`${u}${r}${e.name}`),i&&t.$postUpdate(`${l}${r}${e.name}`)}))}function de(t){const e=Dt;if(0===e.size)return;const n=[];for(const o of e)for(const e of Tt(o).values()){let r=-1;for(const n of e.depAddresses)t.has(n)&&(r=Math.max(r,ie(t,n)));r>=0&&r<=d&&n.push({stateElement:o,entry:e,depth:r})}try{for(const{stateElement:t,entry:o,depth:r}of n)if(e.has(t)&&Tt(t).get(o.name)===o){re(r);try{le(t,o)}catch(n){o.controller?.abort(),e.has(t)&&Tt(t).get(o.name)===o&&fe(t,o,"error",n)}}}finally{se()}}let he=!1;const pe=new WeakMap,me={order:20,apply(t,e){var n;Jt(t),Lt(n=t),Ft(n),Nt.delete(n),Ht(t,e),void 0!==e[o]&&t.attachAddressHooks?.("streams",o)},activate(t,e){if(!C()&&null!=t.connectedRootNode){if(null===e){if(!0!==t.initialized)return;return ue(t),void pe.set(t,t.connectGeneration??0)}e===t.connectGeneration&&pe.get(t)!==e&&ue(t)}},deactivate(t){Lt(t),Jt(t)}};function ye(){he||(he=!0,R("streams",Zt),t("streams",me),j(de,f))}const $e=new WeakMap;function we(t,e,n){let o=$e.get(t);void 0===o&&(o=new Map,$e.set(t,o)),o.set(e,n)}const ge=new Map;function ve(t,e){ge.has(t)||ge.set(t,e)}function be(t){return ge.get(t)}const ke=new WeakMap,je=new WeakMap,Oe=new Set,Pe=new Map;function Ie(t){return ke.get(t)??Pe}function xe(t){Oe.add(t),function(t){const e=D.get(t);void 0!==e&&(T(e)&&F.add(t),function(t){return t.eventResetByPath.size>0}(e)&&N.add(t))}(t)}function Se(){return Oe}function Ae(t,e){let n=je.get(t);void 0===n&&(n=new Map,je.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 Me=new Map;function Ee(t){return je.get(t)??Me}function ze(t){0===t.length&&y(`[wcs/watch-declaration-invalid] ${h} entry name must be a non-empty state path.`),t.startsWith("$")&&y(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not start with "$" (reserved namespace).${$}`),t.includes("@")&&y(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not contain "@" — the name selector was removed in v2; watch only paths of the state tree.${$}`),t in Object.prototype&&y(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const e=i(t);for(const n of e.segments)0===n.length&&y(`[wcs/watch-declaration-invalid] ${h} entry "${t}" has an empty path segment.${$}`);return e.wildcardCount>c&&y(`[wcs/watch-declaration-invalid] ${h} entry "${t}" exceeds the maximum wildcard depth (${c}).`),e}function We(t,e){const n=e[h];if(void 0===n)return null;"object"==typeof n&&null!==n||y(`[wcs/watch-declaration-invalid] ${h} must be an object mapping state paths to handler functions.${$}`);const o=new Map,r=new Set;let s=0;for(const[e,a]of Object.entries(n)){"function"!=typeof a&&y(`[wcs/watch-declaration-invalid] ${h} entry "${e}" must be a function.${$}`);const n=ze(e);o.set(e,{path:e,pathInfo:n,handler:a,order:s++}),r.add(e),t.setPathInfo(e,"prop","watch")}return function(t,e){ke.set(t,e)}(t,o),r.size>0?r:null}const Re={writeObserve(t,e,n,o,r){if(!r)return;const s=t.watchPaths,a=t.scanPaths;!0!==s?.has(e)&&!0!==a?.has(e)||ve(n,o)},swapped(t,e,n){var o;o=n,ge.has(o)&&ve(e,be(n))}};function Ce(t){for(let e=t;null!==e;e=e.parentListIndex)if(O(e))return!0;return!1}function _e(t,e,n){const o=n.absAddress.listIndex;let r="current",s=null;for(let a=0;a<e.wildcardCount;a++){const i=t[P](I(e.wildcardParentPathInfos[a],s)),c=x(i)?.[n.indexes[a]];if(void 0===c)return"gone";const u=S(o,a,e.wildcardCount);if(c!==u&&!A(c,u)){if(O(u))return"gone";r="replaced"}s=c}return r}function De(t,e,n){const o=new Map;for(const r of n){const n=_e(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 Fe=Object.freeze([]);function Ne(t,e,n,o){let r=t.get(n);return void 0===r&&(r={stateElement:e,entry:n,rows:[],reset:!1,depth:o},t.set(n,r)),r.depth=Math.max(r.depth,o),r}function Te(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 Le(t,e){return e.has(t.stateElement)&&!0===G(t.stateElement)?.entries.has(t.entry)}function Ge(t){const{entry:e,stateElement:n}=t;"event"!==e.source.kind||e.resetOn.some(t=>Be(n,t))||J(e)}function Be(t,e){return g().hasQueuedPath(t,e)}function He(t,e){!function(t,e,n){if(0!==q)for(const o of t){const t=o.absolutePathInfo.stateElement;if(!0===e?.has(t))continue;const r=Q(o);if(void 0!==r)for(const e of r)e.resetOn.some(e=>n(t,e))||J(e)}}(t,e,Be)}function Ke(t,e,n){return 0===e.pathInfo.wildcardCount?t[e.path]:t.$resolve(e.path,n.indexes)}function qe(t,n,o){if(!Le(t,o))return Ge(t),null;const{stateElement:r,entry:s}=t;if(t.reset)return{group:t,next:s.initial};const a=s.source;if(function(t,e){for(const n of e.pathInfo.cumulativePaths)if(t.getterPaths.has(n))return!0;return!1}(r,a))return function(t,n,o){if(ht.has(t))return;ht.add(t);const r=`[wcs/scan-source-computed] ${e} entry "${n}" from "${o}" 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] ${r}`),ut(n,"fold",new Error(r))}(s,s.name,a.path),null;if(function(t,e,n){const o=Tt(t).get(e);if(void 0===o)return!1;for(const t of o.depAddresses)if(n.has(t))return!0;return!1}(r,a.pathInfo.segments[0],n))return null;const i={plan:null,failure:"read-output"};try{r.createState("readonly",e=>{const n=e[s.name];i.failure="read-rows";const o=0===a.pathInfo.wildcardCount?t.rows:De(e,a.pathInfo,t.rows);i.failure="threw";const r=s.fold;let c=n;for(const t of o.sort(Te)){let n;try{n=Ke(e,a,t)}catch(t){lt(s.name,t,"read-source");continue}const o=r(c,n,be(t.absAddress),...t.indexes);if(ft(o))return void dt(s.name,o);c=o}Object.is(c,n)||(i.plan={group:t,next:c})})}catch(t){lt(s.name,t,i.failure)}return i.plan}function Qe(t,e){const{group:n}=t;if(!Le(n,e))return void Ge(n);const{stateElement:o,entry:r}=n;if(!n.reset||"event"!==r.source.kind||J(r))try{o.createState("writable",e=>{const o=e[r.name];if(n.reset?!ot(o,r.initial):!Object.is(o,t.next)){const o=n.reset?et(r.initial):t.next;e[r.name]=o,st(r.name,o)}})}catch(t){lt(r.name,t,"write")}}function Ue(t,e){if(He(t,e),0===F.size)return Fe;const n=new Map;for(const o of t){const r=o.absolutePathInfo.stateElement;if(!e.has(r))continue;const s=G(r);if(void 0===s)continue;const a=o.absolutePathInfo.pathInfo,i=ie(t,o),c=s.byFromPath.get(a.path);if(void 0!==c){let t=[];if(a.wildcardCount>0){if(null===o.listIndex)continue;t=M(o.listIndex,a.wildcardCount)}for(const e of c)Ne(n,r,e,i).rows.push({absAddress:o,indexes:t})}const u=s.byResetPath.get(a.path);if(void 0!==u)for(const t of u)Ne(n,r,t,i).reset=!0}if(0===n.size)return Fe;const o=Array.from(n.values()).sort((t,e)=>t.entry.order-e.entry.order),r=[];try{for(const n of o){re(n.depth);const o=qe(n,t,e);null!==o&&r.push(o)}}finally{se()}return r}function Ve(t){rn(),(0!==Ie(t).size||0!==Ee(t).size||function(t){const e=D.get(t);return void 0!==e&&T(e)}(t))&&(xe(t),function(t){const e=[];for(const n of Ie(t).values())Je(t,n)&&e.push(n);for(const n of Ee(t).values())for(const o of n)Je(t,o)&&e.push(o);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{we(t,E(t,o.pathInfo,null),n[o.path])}catch(e){Ye(t,o.path,"prime",e)}})}(t))}function Je(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const Xe={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function Ye(t,e,o,r){console.error(`[@wcstack/state] $watch ${Xe[o]} "${e}" threw.`,r),null!==n&&n({type:"state:watch-error",phase:o,path:e,error:r})}function Ze(t){const e=Se(),o=function(t){const e=ne;return e>0&&(oe.set(t,ee),ee=null,ne=0),e}(t);try{if(o>d){He(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:d,paths:e}),void(null!==n&&n({type:"state:watch-chain-limit",maxDepth:d,paths:e}))}if(0===e.size)return void He(t,e);!function(t,e){if(0!==t.length)try{for(const n of t)re(n.group.depth),Qe(n,e)}finally{se()}}(Ue(t,e),e),function(t,e){const n=[],o=new Set;for(const r of t){const t=r.absolutePathInfo.stateElement;if(!e.has(t))continue;const s=r.absolutePathInfo.pathInfo.path;o.add(s);const a=Ie(t).get(s),i=Ee(t).get(s);if(void 0===a&&void 0===i)continue;const c=void 0===a?[]:[a];void 0!==i&&c.push(...i);for(const e of c){let o=[];if(e.pathInfo.wildcardCount>0){if(null===r.listIndex)continue;o=M(r.listIndex,e.pathInfo.wildcardCount)}n.push({stateElement:t,entry:e,absAddress:r,indexes:o})}}if(0===n.length)return;n.sort(en);const r=function(t,e){let n=null;for(let o=0;o<t.length;o++){const r=t[o];if(0===r.entry.pathInfo.wildcardCount)continue;const s=t[o-1];(Ce(r.absAddress.listIndex)||s?.entry===r.entry&&tn(s.indexes,r.indexes)||r.entry.pathInfo.wildcardParentPaths.some(t=>e.has(t)))&&(n??=new Set).add(r.entry)}if(null===n)return t;const o=new Set;for(const e of n){const n=t.filter(t=>t.entry===e),r=n[0].stateElement;try{r.createState("readonly",t=>{const r=new Set(De(t,e.pathInfo,n));for(const t of n)r.has(t)||o.add(t)})}catch(t){Ye(0,e.path,"evaluate",t);for(const t of n)o.add(t)}}return t.filter(t=>!o.has(t))}(n,o);try{for(const n of r){if(!e.has(n.stateElement))continue;const o=Ie(n.stateElement).get(n.entry.path)===n.entry,r=!0===Ee(n.stateElement).get(n.entry.path)?.includes(n.entry);(o||r)&&(re(ie(t,n.absAddress)),nn(n))}}finally{se()}}(t,e)}finally{ge.clear()}}function tn(t,e){for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function en(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 nn(t){const{stateElement:e,entry:o,absAddress:r,indexes:s}=t,a=Je(e,o);try{e.createState("writable",t=>{let i;try{i=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,o,s)}catch(t){return void Ye(0,o.path,"evaluate",t)}const c=a?function(t,e){return $e.get(t)?.get(e)}(e,r):be(r);a&&we(e,r,i),null!==n&&n({type:"state:watch-fired",path:o.path,stateElement:e}),o.handler.call(t,i,c,...s)})}catch(t){Ye(0,o.path,"handler",t)}}let on=!1;function rn(){on||(on=!0,R("watch",Re),t("watch",sn),j(Ze,p),b(ae),_({assertValidPath:ze,addEntries:Ae,start:Ve}))}const sn={order:10,register(t,n){var o;o=t,Oe.delete(o),H(o),ke.delete(o),function(t){$e.delete(t)}(t);const r=We(t,n);t.setWatchPaths?.(r),null===r&&null==t.scanPaths||t.attachAddressHooks?.("watch",null!==r?h:e)},activate(t,e){C()||null==t.connectedRootNode||(null===e?!0===t.initialized:e===t.connectGeneration)&&Ve(t)},deactivate(t){var e;e=t,Oe.delete(e),H(e)}},an={name:"temporal",install(){rn(),At||(At=!0,t("scan",St),b(U)),ye()}};export{an as default,an as temporal};
2
2
  //# sourceMappingURL=temporal.js.map