@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.25

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 (246) hide show
  1. package/README.md +1096 -0
  2. package/dist/api/Raph.d.ts +59 -190
  3. package/dist/api/RaphFacadeSession.d.ts +90 -0
  4. package/dist/api/RaphReactivityInstance.d.ts +72 -0
  5. package/dist/api/errors.d.ts +9 -4
  6. package/dist/api/types.d.ts +162 -17
  7. package/dist/core-CClhT8WR.js +1044 -0
  8. package/dist/core-cPQWYD4K.cjs +1 -0
  9. package/dist/debug/api/Raph.cjs +1 -1
  10. package/dist/debug/api/Raph.js +368 -367
  11. package/dist/debug/api/RaphFacadeSession.cjs +1 -0
  12. package/dist/debug/api/RaphFacadeSession.js +302 -0
  13. package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
  14. package/dist/debug/api/RaphReactivityInstance.js +146 -0
  15. package/dist/debug/api/errors.cjs +1 -1
  16. package/dist/debug/api/errors.js +10 -7
  17. package/dist/debug/path/DataPath.cjs +1 -0
  18. package/dist/debug/path/DataPath.js +390 -0
  19. package/dist/debug/path/PathRouter.cjs +1 -0
  20. package/dist/debug/path/PathRouter.js +80 -0
  21. package/dist/debug/path/RaphKernel.cjs +1 -1
  22. package/dist/debug/path/RaphKernel.js +316 -236
  23. package/dist/debug/path/data-path.utils.cjs +1 -0
  24. package/dist/debug/path/data-path.utils.js +56 -0
  25. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
  26. package/dist/debug/path/derived/DerivedRegistry.js +143 -0
  27. package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
  28. package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +19 -22
  29. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
  30. package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +71 -71
  31. package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
  32. package/dist/debug/path/derived/derived-strategy.types.js +1 -0
  33. package/dist/debug/path/meta/MetaController.cjs +1 -0
  34. package/dist/debug/path/{MetaController.js → meta/MetaController.js} +58 -66
  35. package/dist/debug/path/meta/RaphMeta.cjs +1 -0
  36. package/dist/debug/path/meta/RaphMeta.js +62 -0
  37. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
  38. package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +24 -30
  39. package/dist/debug/path/meta/meta.types.cjs +1 -0
  40. package/dist/debug/path/meta/meta.types.js +1 -0
  41. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
  42. package/dist/debug/path/storage/AdapterPathStore.js +128 -0
  43. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
  44. package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +47 -57
  45. package/dist/debug/path/storage/PathEventHub.cjs +1 -0
  46. package/dist/debug/path/storage/PathEventHub.js +161 -0
  47. package/dist/debug/path/storage/PathStore.cjs +1 -0
  48. package/dist/debug/path/{PathStore.js → storage/PathStore.js} +88 -98
  49. package/dist/debug/path/storage/createDataDraft.cjs +1 -0
  50. package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +24 -28
  51. package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
  52. package/dist/debug/path/storage/data-adapter.types.js +1 -0
  53. package/dist/debug/reactivity/disposal.cjs +1 -0
  54. package/dist/debug/reactivity/disposal.js +32 -0
  55. package/dist/debug/reactivity/engine.cjs +1 -1
  56. package/dist/debug/reactivity/engine.js +888 -321
  57. package/dist/debug/reactivity/reactive-object.cjs +1 -0
  58. package/dist/debug/reactivity/reactive-object.js +265 -0
  59. package/dist/debug/reactivity/scope.cjs +1 -1
  60. package/dist/debug/reactivity/scope.js +221 -117
  61. package/dist/debug/reactivity/watch.cjs +1 -1
  62. package/dist/debug/reactivity/watch.js +1 -1
  63. package/dist/debug/runtime/RaphRuntime.cjs +1 -1
  64. package/dist/debug/runtime/RaphRuntime.js +1134 -502
  65. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
  66. package/dist/debug/runtime/diagnostics/RaphDebug.js +287 -0
  67. package/dist/debug/runtime/errors.cjs +1 -1
  68. package/dist/debug/runtime/errors.js +6 -3
  69. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
  70. package/dist/debug/runtime/ownership/RaphEffectScope.js +304 -0
  71. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
  72. package/dist/debug/runtime/ownership/RaphNode.js +665 -0
  73. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
  74. package/dist/debug/runtime/ownership/RaphScope.js +236 -0
  75. package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
  76. package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
  77. package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -0
  78. package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +13 -17
  79. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
  80. package/dist/debug/runtime/phases/RaphPhasePipeline.js +848 -0
  81. package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -0
  82. package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +176 -0
  83. package/dist/debug/runtime/phases/RaphPhaseWatch.cjs +1 -0
  84. package/dist/debug/runtime/phases/RaphPhaseWatch.js +20 -0
  85. package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
  86. package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
  87. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
  88. package/dist/debug/runtime/reactivity/PathHandle.js +165 -0
  89. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
  90. package/dist/debug/runtime/reactivity/RaphMetaSource.js +108 -0
  91. package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -0
  92. package/dist/debug/runtime/reactivity/RaphSelector.js +503 -0
  93. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
  94. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +1157 -0
  95. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
  96. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +550 -0
  97. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
  98. package/dist/debug/runtime/reactivity/RuntimeWatch.js +77 -0
  99. package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
  100. package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -0
  101. package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
  102. package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
  103. package/dist/entrypoints/machine-testing.d.ts +2 -0
  104. package/dist/entrypoints/machine.d.ts +5 -0
  105. package/dist/entrypoints/path.d.ts +14 -0
  106. package/dist/entrypoints/reactivity.d.ts +1 -0
  107. package/dist/entrypoints/runtime.d.ts +18 -0
  108. package/dist/index.cjs +1 -1
  109. package/dist/index.js +46 -38
  110. package/dist/machine/compiler.d.ts +71 -0
  111. package/dist/machine/core.d.ts +50 -0
  112. package/dist/machine/persistence.d.ts +5 -0
  113. package/dist/machine/runtime.d.ts +4 -0
  114. package/dist/machine/testing.d.ts +43 -0
  115. package/dist/machine/types.d.ts +155 -0
  116. package/dist/machine-testing.cjs +1 -0
  117. package/dist/machine-testing.js +188 -0
  118. package/dist/machine.cjs +1 -0
  119. package/dist/machine.js +822 -0
  120. package/dist/main.d.ts +20 -0
  121. package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
  122. package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
  123. package/dist/path/RaphKernel.d.ts +37 -10
  124. package/dist/path/data-path.types.d.ts +34 -0
  125. package/dist/path/data-path.utils.d.ts +9 -0
  126. package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
  127. package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
  128. package/dist/path/derived/derived-collection.types.d.ts +12 -0
  129. package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
  130. package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
  131. package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
  132. package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
  133. package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
  134. package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
  135. package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
  136. package/dist/path/path.types.d.ts +3 -2
  137. package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
  138. package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
  139. package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
  140. package/dist/path/storage/PathEventHub.d.ts +62 -0
  141. package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +7 -7
  142. package/dist/path/storage/data-adapter.types.d.ts +17 -0
  143. package/dist/path.cjs +1 -1
  144. package/dist/path.js +16 -16
  145. package/dist/raph.cjs +1 -1
  146. package/dist/raph.js +46 -38
  147. package/dist/reactivity/disposal.d.ts +14 -0
  148. package/dist/reactivity/engine.d.ts +193 -6
  149. package/dist/reactivity/reactive-object.d.ts +36 -0
  150. package/dist/reactivity/scope.d.ts +108 -30
  151. package/dist/reactivity/types.d.ts +25 -0
  152. package/dist/reactivity.cjs +1 -1
  153. package/dist/reactivity.js +12 -12
  154. package/dist/runtime/RaphRuntime.d.ts +319 -160
  155. package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
  156. package/dist/runtime/errors.d.ts +5 -0
  157. package/dist/runtime/ownership/RaphEffectScope.d.ts +98 -0
  158. package/dist/runtime/ownership/RaphNode.d.ts +310 -0
  159. package/dist/runtime/ownership/RaphScope.d.ts +168 -0
  160. package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
  161. package/dist/runtime/ownership/parentGraph.d.ts +3 -0
  162. package/dist/runtime/phases/RaphPhasePipeline.d.ts +253 -0
  163. package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
  164. package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
  165. package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
  166. package/dist/runtime/phases/phase.types.d.ts +171 -0
  167. package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
  168. package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
  169. package/dist/runtime/reactivity/RaphSelector.d.ts +338 -0
  170. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +309 -0
  171. package/dist/runtime/reactivity/RuntimeReactivity.d.ts +293 -0
  172. package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +12 -6
  173. package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
  174. package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +56 -0
  175. package/dist/runtime.cjs +1 -1
  176. package/dist/runtime.js +21 -16
  177. package/package.json +76 -35
  178. package/ReadMe.md +0 -153
  179. package/dist/api/public.d.ts +0 -22
  180. package/dist/debug/api/public.cjs +0 -1
  181. package/dist/debug/api/public.js +0 -40
  182. package/dist/debug/path/AdapterPathStore.cjs +0 -1
  183. package/dist/debug/path/AdapterPathStore.js +0 -133
  184. package/dist/debug/path/DerivedRegistry.cjs +0 -1
  185. package/dist/debug/path/DerivedRegistry.js +0 -157
  186. package/dist/debug/path/MetaController.cjs +0 -1
  187. package/dist/debug/path/PathEventHub.cjs +0 -1
  188. package/dist/debug/path/PathEventHub.js +0 -148
  189. package/dist/debug/path/PathStore.cjs +0 -1
  190. package/dist/debug/path/RaphDerivedHandle.cjs +0 -1
  191. package/dist/debug/path/RaphMeta.cjs +0 -1
  192. package/dist/debug/path/RaphMeta.js +0 -68
  193. package/dist/debug/path/RaphMetaStore.cjs +0 -1
  194. package/dist/debug/path/data-adapter.cjs +0 -1
  195. package/dist/debug/path/data-draft.cjs +0 -1
  196. package/dist/debug/path/data-path.cjs +0 -1
  197. package/dist/debug/path/data-path.js +0 -423
  198. package/dist/debug/path/derived-collection.cjs +0 -1
  199. package/dist/debug/path/path-router.cjs +0 -1
  200. package/dist/debug/path/path-router.js +0 -86
  201. package/dist/debug/path/public.cjs +0 -1
  202. package/dist/debug/path/public.js +0 -18
  203. package/dist/debug/runtime/PathHandle.cjs +0 -1
  204. package/dist/debug/runtime/PathHandle.js +0 -139
  205. package/dist/debug/runtime/RaphDebug.cjs +0 -1
  206. package/dist/debug/runtime/RaphDebug.js +0 -15
  207. package/dist/debug/runtime/RaphFrameLoop.cjs +0 -1
  208. package/dist/debug/runtime/RaphNode.cjs +0 -1
  209. package/dist/debug/runtime/RaphNode.js +0 -143
  210. package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
  211. package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
  212. package/dist/debug/runtime/RaphScope.cjs +0 -1
  213. package/dist/debug/runtime/RaphScope.js +0 -64
  214. package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
  215. package/dist/debug/runtime/RuntimeReactivity.js +0 -154
  216. package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
  217. package/dist/debug/runtime/RuntimeWatch.js +0 -71
  218. package/dist/debug/runtime/public.cjs +0 -1
  219. package/dist/debug/runtime/public.js +0 -18
  220. package/dist/path/PathEventHub.d.ts +0 -48
  221. package/dist/path/public.d.ts +0 -14
  222. package/dist/runtime/RaphDebug.d.ts +0 -32
  223. package/dist/runtime/RaphNode.d.ts +0 -68
  224. package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
  225. package/dist/runtime/RaphScope.d.ts +0 -50
  226. package/dist/runtime/RuntimeReactivity.d.ts +0 -40
  227. package/dist/runtime/phase.types.d.ts +0 -49
  228. package/dist/runtime/public.d.ts +0 -13
  229. package/dist/runtime/runtime-reactivity.types.d.ts +0 -9
  230. /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
  231. /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
  232. /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
  233. /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
  234. /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
  235. /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
  236. /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
  237. /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
  238. /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
  239. /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
  240. /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
  241. /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
  242. /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
  243. /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
  244. /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
  245. /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
  246. /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ "use strict";const Z=new WeakMap,gt=16384;function St(t){if(Pt(t.id,t.version),typeof t.states!="object"||t.states===null||Array.isArray(t.states))throw new TypeError("[Raph machine] states must be an object.");const e=t,n=[],r=new Map,o=[];for(const[f,w]of Object.entries(e.states))o.push(ct(f,w,void 0,0,n,r));const i=r.get(t.initial);if(i===void 0||n[i]?.parent!==void 0)throw new Error(`[Raph machine] Initial state "${t.initial}" must be a root state key.`);const s=new Set,a=n.map(f=>{const w=f.initialKey===void 0?void 0:f.children.find(g=>n[g]?.key===f.initialKey);if(f.kind==="compound"&&w===void 0)throw new Error(`[Raph machine] Compound state "${f.path}" requires a valid direct initial child.`);if(w!==void 0&&n[w].kind==="history")throw new Error(`[Raph machine] Compound state "${f.path}" cannot use history as its initial child.`);const b=f.historyFallbackPath===void 0?void 0:r.get(f.historyFallbackPath);if(f.historyFallbackPath!==void 0&&b===void 0)throw new Error(`[Raph machine] History state "${f.path}" has unknown fallback "${f.historyFallbackPath}".`);for(const g of f.on.keys())s.add(g);return{after:f.after,always:f.always,children:Object.freeze([...f.children]),depth:f.depth,entry:f.entry,exit:f.exit,history:f.history,...b===void 0?{}:{historyFallback:b},id:f.id,...w===void 0?{}:{initial:w},invokes:f.invokes,key:f.key,kind:f.kind,...f.meta===void 0?{}:{meta:f.meta},on:f.on,onDone:f.onDone,...f.output===void 0?{}:{output:f.output},...f.parent===void 0?{}:{parent:f.parent},path:f.path,resources:f.resources,tags:f.tags}});for(const f of a)Tt(f,r,a);const u=t.version??1;It(a);const h=Object.freeze([...s]),c=new Map(h.map((f,w)=>[f,w])),d=Object.freeze(a.map(f=>Object.freeze(zt(a,f.id)))),l=Rt(a),y=l&&h.length<=Math.floor(gt/a.length)?xt(a,c,h.length):void 0,v=Object.freeze({ancestry:d,context:_t(e.context),eventIndexes:c,eventTypes:h,flat:l,...y===void 0?{}:{flatDispatch:y},id:t.id,initial:i,migrations:Dt(t.migrations,u),...e.output===void 0?{}:{output:e.output},pathToState:r,rootChildren:Object.freeze(o),states:Object.freeze(a),version:u}),m=Object.freeze({id:t.id,version:u});return Z.set(m,v),m}function xt(t,e,n){const r=Array.from({length:t.length*n}).fill(void 0);for(const o of t){const i=o.id*n;for(const[s,a]of o.on)r[i+e.get(s)]=a}return Object.freeze(r)}function zt(t,e){const n=[];for(let r=e;r!==void 0;r=t[r].parent)n.push(r);return n}function Rt(t){return t.every(e=>{if(e.parent!==void 0||e.kind!=="atomic"&&e.kind!=="final"||e.always.length!==0||e.onDone.length!==0||e.after.size!==0||e.entry.length!==0||e.exit.length!==0||e.resources.length!==0||e.invokes.length!==0)return!1;for(const n of e.on.values())if(n.some(r=>r.raise!==void 0))return!1;return!0})}function A(t){const e=Z.get(t);if(e===void 0)throw new TypeError("[Raph machine] Model was not created by defineMachine().");return e}function ct(t,e,n,r,o,i){if(typeof e!="object"||e===null||Array.isArray(e))throw new TypeError(`[Raph machine] State "${t}" must be an object.`);At(e,t),Ct(t);const s=n===void 0?"":o[n].path,a=s?`${s}.${t}`:t,u=o.length;if(i.has(a))throw new Error(`[Raph machine] Duplicate state path "${a}".`);const h=$t(e),c={after:new Map,always:Object.freeze([]),children:[],depth:r,entry:I(e.entry),exit:I(e.exit),history:e.history??"shallow",...e.target===void 0?{}:{historyFallbackPath:e.target},id:u,...e.initial===void 0?{}:{initialKey:e.initial},invokes:Object.freeze([]),key:t,kind:h,...e.meta===void 0?{}:{meta:Object.freeze({...e.meta})},on:new Map,onDone:Object.freeze([]),...e.output===void 0?{}:{output:e.output},...n===void 0?{}:{parent:n},path:a,resources:ot(e.resources),tags:ot(e.tags)};o.push(c),i.set(a,u);for(const[y,v]of Object.entries(e.states??{}))c.children.push(ct(y,v,u,r+1,o,i));let d=0;for(const[y,v]of Object.entries(e.on??{})){if(!y.trim())throw new Error(`[Raph machine] State "${a}" has an empty event type.`);c.on.set(y,P(v,u,()=>d++))}c.always=P(e.always,u,()=>d++),c.onDone=P(e.onDone,u,()=>d++);for(const[y,v]of Object.entries(e.after??{})){if(!y.trim())throw new Error(`[Raph machine] State "${a}" has an empty delay key.`);c.after.set(y,P(v,u,()=>d++))}const l=Ft(e.invoke);return c.invokes=Object.freeze(l.map((y,v)=>kt(y,c,v,()=>d++))),Mt(c,o),u}function kt(t,e,n,r){if(typeof t!="object"||t===null||Array.isArray(t))throw new TypeError(`[Raph machine] Invoke in "${e.path}" must be an object.`);const o=typeof t.src=="string"?"task":"machine",i=t.type??o,s=t.id??`${e.path}:invoke#${n+1}`;if(!s.trim())throw new Error(`[Raph machine] Invoke id in "${e.path}" must not be empty.`);if(i!=="machine"&&i!=="task")throw new Error(`[Raph machine] Invoke "${s}" has unsupported type "${String(i)}".`);if(typeof t.src=="string"){if(!t.src.trim())throw new Error(`[Raph machine] Invoke "${s}" source must not be empty.`)}else if(!Z.has(t.src))throw new TypeError(`[Raph machine] Invoke "${s}" actor source must come from defineMachine().`);if(i==="task"&&typeof t.src!="string")throw new TypeError(`[Raph machine] Task invoke "${s}" requires a string source.`);return Object.freeze({id:s,...t.input===void 0?{}:{input:t.input},onDone:P(t.onDone,e.id,r),onError:P(t.onError,e.id,r),src:t.src,type:i})}function P(t,e,n){if(t===void 0)return Object.freeze([]);const r=Array.isArray(t)?t:[t];return Object.freeze(r.map(o=>{const i=typeof o=="string"?{target:o}:o;if(i===null||typeof i!="object")throw new TypeError("[Raph machine] Transition must be a target string or object.");if(i.reenter===!0&&i.target===void 0)throw new Error("[Raph machine] A targetless transition cannot declare reenter: true.");if(i.reason!==void 0&&(typeof i.reason!="string"||!i.reason.trim()))throw new Error("[Raph machine] Transition reason must be a non-empty string.");return W(i.guard===void 0?[]:[i.guard],"guard"),W(I(i.reduce),"reducer"),W(I(i.emit),"output"),{emit:I(i.emit),...i.guard===void 0?{}:{guard:i.guard},index:n(),...i.raise===void 0?{}:{raise:i.raise},...i.reason===void 0?{}:{reason:i.reason},reduce:I(i.reduce),reenter:i.reenter===!0,source:e,...i.target===void 0?{}:{target:i.target}}}))}function Tt(t,e,n){const r=[t.always,t.onDone,...t.on.values(),...t.after.values()];for(const o of t.invokes)r.push(o.onDone,o.onError);for(const o of r)for(const i of o){if(i.target!==void 0){const s=i.target,a=e.get(s);if(a===void 0)throw new Error(`[Raph machine] Transition from "${t.path}" targets unknown state "${s}".`);i.target=a}Object.freeze(i)}if(t.kind==="history"&&t.historyFallback!==void 0){const o=[...e].find(([,s])=>s===t.historyFallback)?.[0],i=t.path.slice(0,t.path.lastIndexOf("."));if(o===void 0||o===t.path||t.historyFallback===void 0||!o.startsWith(`${i}.`))throw new Error(`[Raph machine] History fallback for "${t.path}" must stay inside its parent state.`);if(n[t.historyFallback].kind==="history")throw new Error(`[Raph machine] History fallback for "${t.path}" cannot target another history state.`)}}function $t(t){if(t.type!==void 0){if(t.type!=="atomic"&&t.type!=="compound"&&t.type!=="final"&&t.type!=="history"&&t.type!=="parallel")throw new TypeError(`[Raph machine] Unsupported state type "${String(t.type)}".`);return t.type}return t.states===void 0?"atomic":"compound"}function Mt(t,e){if((t.kind==="atomic"||t.kind==="final"||t.kind==="history")&&t.children.length!==0)throw new Error(`[Raph machine] ${t.kind} state "${t.path}" cannot have children.`);if(t.kind==="parallel"&&t.initialKey!==void 0)throw new Error(`[Raph machine] Parallel state "${t.path}" cannot declare initial.`);if(t.kind==="parallel"&&!t.children.some(n=>e[n].kind!=="history"))throw new Error(`[Raph machine] Parallel state "${t.path}" requires at least one region.`);if(t.kind==="history"&&t.parent===void 0)throw new Error(`[Raph machine] History state "${t.path}" must have a parent.`);if(t.kind!=="history"&&t.historyFallbackPath!==void 0)throw new Error("[Raph machine] Only a history state may declare target as fallback.");if((t.kind==="atomic"||t.kind==="final"||t.kind==="history")&&t.initialKey!==void 0)throw new Error(`[Raph machine] ${t.kind} state "${t.path}" cannot declare initial.`);if((t.kind==="final"||t.kind==="history")&&(t.on.size!==0||t.always.length!==0||t.after.size!==0||t.onDone.length!==0||t.invokes.length!==0))throw new Error(`[Raph machine] ${t.kind} state "${t.path}" cannot declare transitions or invokes.`)}function At(t,e){if(U(t.states,`State "${e}" states`),U(t.on,`State "${e}" on`),U(t.after,`State "${e}" after`),t.history!==void 0&&t.history!=="deep"&&t.history!=="shallow")throw new TypeError(`[Raph machine] State "${e}" has unsupported history mode.`)}function U(t,e){if(t!==void 0&&(typeof t!="object"||t===null||Array.isArray(t)))throw new TypeError(`[Raph machine] ${e} must be an object.`)}function Pt(t,e){if(typeof t!="string"||!t.trim())throw new TypeError("[Raph machine] Model id must be a non-empty string.");const n=e??1;if(!Number.isSafeInteger(n)||n<1)throw new TypeError("[Raph machine] Model version must be a positive safe integer.")}function It(t){const e=new Set;for(const n of t)for(const r of n.invokes){if(e.has(r.id))throw new Error(`[Raph machine] Invoke id "${r.id}" is duplicated.`);e.add(r.id)}}function Dt(t,e){const n=new Map;for(const[r,o]of Object.entries(t??{})){const i=Number(r);if(!Number.isSafeInteger(i)||i<1||i>=e)throw new Error(`[Raph machine] Migration version "${r}" must be a positive integer below ${e}.`);if(typeof o!="function")throw new TypeError(`[Raph machine] Migration from version ${i} must be a function.`);n.set(i,o)}return n}function W(t,e){for(const n of t)if(typeof n!="function"&&(typeof n!="string"||!n.trim()))throw new TypeError(`[Raph machine] ${e} reference must be a function or non-empty string.`)}function Ct(t){if(!t||t.includes("."))throw new Error("[Raph machine] State keys must be non-empty and cannot contain dots.")}function I(t){return Object.freeze(t===void 0?[]:Array.isArray(t)?[...t]:[t])}function ot(t){if(t===void 0)return Object.freeze([]);const e=typeof t=="string"?[t]:[...t];for(const n of e)if(typeof n!="string"||!n.trim())throw new TypeError("[Raph machine] Tags and resource names must be non-empty strings.");return Object.freeze(e)}function Ft(t){return t===void 0?[]:Array.isArray(t)?t:[t]}function _t(t){return Array.isArray(t)?Object.freeze([...t]):typeof t=="object"&&t!==null&&Object.getPrototypeOf(t)===Object.prototype?Object.freeze({...t}):t}const T=Symbol("RaphMachineSnapshot"),it=new WeakMap;function ut(t){const e=Object.getPrototypeOf(t);return e!==null&&Object.hasOwn(e,T)?e:void 0}function ft(t){return t[T]}function L(t,e,n){const r=n??Object.freeze({[T]:e}),o=Object.create(r);return o.active=t.active,o.context=t.context,o.history=t.history,t.output!==void 0&&(o.output=t.output),o.revision=t.revision,o.status=t.status,Object.freeze(o)}function J(t,e,n,r,o){let i=t?.flatPrototypes;i===void 0&&(n===void 0?(i=it.get(r),i===void 0&&(i=[],it.set(r,i))):i=[]);const s=i[e];if(s!==void 0)return s;const a=Object.freeze({[T]:Object.freeze({active:Object.freeze([e]),flatPrototypes:i,input:n,model:r,publicActive:Object.freeze([o])})});return i[e]=a,a}const Nt=100,G=Object.freeze({type:"@@init"}),ht=Object.freeze([]),q=Object.freeze({}),K=Object.freeze([]),C=Object.freeze([]),Ht=Object.freeze([]),Q=Object.freeze({entered:K,entryOutputs:C,event:G,exited:K,exitOutputs:C,transitionOutputs:C});function qt(t,e){return pt(t,e,void 0).snapshot}function Kt(t,e,n,r,o){const i=ft(e);if(i!==void 0&&i.model!==t)throw new TypeError("[Raph machine] Snapshot belongs to another model.");const s=A(t);return tt(t,e,n,r,i?.input,o,s).snapshot}function dt(t,e){if(ut(e)?.[T].model!==t)throw new TypeError("[Raph machine] Snapshot belongs to another model or was not created by Raph.")}function Lt(t,e){if(dt(t,e),e.status==="stopped")return e;const n=ut(e);return L({active:e.active,context:e.context,history:e.history,...e.output===void 0?{}:{output:e.output},revision:e.revision+1,status:"stopped"},n[T],n)}function pt(t,e,n,r){const o=A(t),i=o.context,s=typeof i=="function"?i(e):i;if(o.flat){const h=o.states[o.initial],c=h.kind==="final"?"done":"active",d=c==="done"?h.output??o.output:void 0,l=typeof d=="function"?d({context:s,event:G,input:e}):d,y=J(void 0,o.initial,e,t,h.path),v=y[T],m=L({active:v.publicActive,context:rt(s),history:q,...l===void 0?{}:{output:l},revision:0,status:c},v,y);return{changed:!1,plan:Q,snapshot:m}}const a=$(o,o.initial,q),u=F(t,e,{active:a,context:s,history:q},0,"active",void 0,o);return tt(t,u,G,n,e,r,o,!0)}function tt(t,e,n,r,o,i,s,a=!1,u=ht){return Et(n),lt(t,e,n,r,o,i,s,void 0,a,u)}function lt(t,e,n,r,o,i,s,a,u=!1,h=ht){const c=s??A(t);if(e.status!=="active")return D(e);if(!u&&c.flat){const E=a??c.eventIndexes.get(n.type);return E===void 0?D(e):Yt(t,c,e,n,E,r,o,i)}if(!u&&!ee(c,e.active,n.type))return D(e);const d={active:e.active.map(E=>N(c,E)),context:e.context,history:{...e.history}},l=r,y=new Set,v=new Set,m=[],f=[],w=[],b=[...h];let g=!1;if(!u){const E=st(c,d,n,l,o,i);at(E,y,v,m,f,w),g=E.changed,b.push(...E.raised)}const p=new Set;let O=0;for(;;){const E=b.shift();let S;if(E!==void 0?S=st(c,d,E,l,o,i):(S=Wt(c,d,n,l,o,i),S.changed||(S=Gt(c,d,n,l,o,p,i))),!S.changed){if(b.length!==0)continue;break}if(++O>Nt)throw new Error("[Raph machine] Macrostep exceeded 100 stabilization microsteps.");for(const B of S.exited)p.delete(B);for(const B of S.entered)p.delete(B);g=!0,at(S,y,v,m,f,w),b.push(...S.raised)}const R=nt(c,d.active)?"done":"active";if(!g&&R===e.status)return D(e);const z=R==="done"?wt(c,d,n,o):void 0,k=F(t,o,d,e.revision+1,R,z,c),j=new Set(_(c,d.active));return Object.freeze({changed:!0,plan:Object.freeze({entered:Object.freeze([...v].filter(E=>j.has(E)).sort((E,S)=>c.states[E].depth-c.states[S].depth)),entryOutputs:Object.freeze(w),event:n,exited:Object.freeze([...y].sort((E,S)=>c.states[S].depth-c.states[E].depth)),exitOutputs:Object.freeze(m),transitionOutputs:Object.freeze(f)}),snapshot:k})}function Yt(t,e,n,r,o,i,s,a){const u=ft(n),h=u?.active[0]??N(e,n.active[0]),c=e.flatDispatch===void 0?e.states[h].on.get(r.type):e.flatDispatch[h*e.eventTypes.length+o],d=H(c??Ht,n.context,r,i,s,a);if(d===void 0)return D(n);yt(e,d,a);let l=n.context;for(const p of d.reduce)l=Ot(p,i)({context:l,event:r,input:s});const y=d.target??h,v=e.states[y],m=v.kind==="final"?"done":"active",f=m==="done"?v.output??e.output:void 0,w=typeof f=="function"?f({context:l,event:r,input:s}):f,b=J(u,y,s,t,v.path),g=L({active:y===h?n.active:b[T].publicActive,context:l===n.context?n.context:rt(l),history:n.history,...w===void 0?{}:{output:w},revision:n.revision+1,status:m},b[T],b);return{changed:!0,plan:d.emit.length===0?Q:{entered:K,entryOutputs:C,event:r,exited:K,exitOutputs:C,transitionOutputRefs:d.emit,transitionOutputs:C},snapshot:g}}function Vt(t,e,n,r,o,i,s){const a=A(t),u=H(r,e.context,n,o,i,s);if(u===void 0)return D(e);const h={active:e.active.map(b=>N(a,b)),context:e.context,history:{...e.history}},c=Y(a,h,[u],n,o,i,s),d=F(t,i,h,e.revision,"active",void 0,a),l=tt(t,d,n,o,i,s,a,!0,c.raised),y=l.changed?{active:l.snapshot.active.map(b=>N(a,b)),context:l.snapshot.context,history:{...l.snapshot.history}}:h,v=l.changed?l.snapshot.status:nt(a,y.active)?"done":"active",m=v==="done"?l.snapshot.output??wt(a,y,n,i):void 0,f=F(t,i,y,e.revision+1,v,m,a),w=new Set(_(a,y.active));return Object.freeze({changed:!0,plan:Object.freeze({entered:Object.freeze(M([...c.entered,...l.plan.entered]).filter(b=>w.has(b)).sort((b,g)=>a.states[b].depth-a.states[g].depth)),entryOutputs:Object.freeze([...c.entryOutputs,...l.plan.entryOutputs]),event:n,exited:Object.freeze(M([...c.exited,...l.plan.exited]).sort((b,g)=>a.states[g].depth-a.states[b].depth)),exitOutputs:Object.freeze([...c.exitOutputs,...l.plan.exitOutputs]),transitionOutputs:Object.freeze([...c.transitionOutputs,...l.plan.transitionOutputs])}),snapshot:f})}function Bt(t,e,n){const r=A(t);if(e.status!=="active"&&e.status!=="done"&&e.status!=="stopped")throw new Error(`[Raph machine] Unknown persisted status "${String(e.status)}".`);if(!Number.isSafeInteger(e.revision)||e.revision<0)throw new Error("[Raph machine] Persisted revision must be a non-negative safe integer.");const o=e.active.map(i=>N(r,i));return Ut(r,o,e.history,e.status),F(t,n,{active:M(o),context:e.context,history:{...e.history}},e.revision,e.status,e.output,r)}function Ut(t,e,n,r){if(e.length===0||new Set(e).size!==e.length)throw new Error("[Raph machine] Persisted active configuration must contain unique leaf states.");for(const s of e){const a=t.states[s].kind;if(a!=="atomic"&&a!=="final")throw new Error(`[Raph machine] Persisted active state "${t.states[s].path}" is not a leaf.`)}if(new Set(e.map(s=>V(t,s))).size!==1)throw new Error("[Raph machine] Persisted configuration spans multiple root states.");for(const s of t.states){if(s.kind!=="compound"&&s.kind!=="parallel")continue;const a=s.children.filter(h=>t.states[h].kind!=="history"&&e.some(c=>c===h||x(t,h,c)));if(e.some(h=>x(t,s.id,h))){if(s.kind==="compound"&&a.length!==1)throw new Error(`[Raph machine] Compound state "${s.path}" requires one active child.`);if(s.kind==="parallel"&&a.length!==s.children.filter(h=>t.states[h].kind!=="history").length)throw new Error(`[Raph machine] Parallel state "${s.path}" requires every region.`)}}const i=nt(t,e);if(r==="done"&&!i)throw new Error("[Raph machine] Done persisted snapshot is not in a final configuration.");if(r==="active"&&i)throw new Error("[Raph machine] Active persisted snapshot is already final.");for(const[s,a]of Object.entries(n)){const u=t.pathToState.get(s);if(u===void 0)throw new Error(`[Raph machine] Persisted history has unknown owner "${s}".`);const h=t.states[u];if(h.kind!=="compound"&&h.kind!=="parallel")throw new Error(`[Raph machine] Persisted history owner "${s}" cannot own history.`);if(!Array.isArray(a))throw new TypeError(`[Raph machine] Persisted history for "${s}" must be an array.`);for(const c of a){const d=t.pathToState.get(c);if(d===void 0||!x(t,u,d))throw new Error(`[Raph machine] Persisted history path "${c}" is invalid for "${s}".`)}}}function st(t,e,n,r,o,i){const s=[],a=new Set,u=[...e.active].sort((h,c)=>t.states[c].depth-t.states[h].depth||h-c);for(const h of u)for(let c=h;c!==void 0&&!a.has(c);c=t.states[c].parent){const d=t.states[c].on.get(n.type);if(d===void 0)continue;const l=H(d,e.context,n,r,o,i);if(l!==void 0){a.add(c),s.push(l);break}}return Y(t,e,vt(t,s),n,r,o,i)}function Wt(t,e,n,r,o,i){const s=[],a=new Set;for(const u of e.active)for(let h=u;h!==void 0;h=t.states[h].parent){if(a.has(h))continue;a.add(h);const c=H(t.states[h].always,e.context,n,r,o,i);c!==void 0&&s.push(c)}return Y(t,e,vt(t,s),n,r,o,i)}function Gt(t,e,n,r,o,i,s){const a=_(t,e.active).filter(u=>!i.has(u)&&et(t,u,e.active)).sort((u,h)=>t.states[h].depth-t.states[u].depth);for(const u of a){i.add(u);const h=H(t.states[u].onDone,e.context,n,r,o,s);if(h!==void 0)return Y(t,e,[h],n,r,o,s)}return mt()}function Y(t,e,n,r,o,i,s){if(n.length===0)return mt();const a=[...e.active],u=new Set(_(t,a)),h=new Set,c=new Set,d=new Set,l=[],y=[];let v=!1;for(const p of n){yt(t,p,s);for(const j of p.reduce)e.context=Ot(j,o)({context:e.context,event:r,input:i}),v=!0;for(const j of p.emit)l.push({event:r,ref:j});if(p.emit.length!==0&&(v=!0),p.raise!==void 0){const j=typeof p.raise=="function"?p.raise({context:e.context,event:r,input:i}):p.raise;Et(j),y.push(j),v=!0}if(p.target===void 0){v=!0;continue}const O=p.source,R=p.target;if(O===R&&!p.reenter){v=!0;continue}const z=X(t,O,R);if(p.reenter){d.add(z);for(const j of u)(j===z||x(t,z,j))&&h.add(j)}e.active=e.active.filter(j=>j!==z&&!x(t,z,j));const k=bt(t,R,e.history);e.active.push(...k),v=!0}e.active=Zt(t,M(e.active),e.history);const m=new Set(_(t,e.active));for(const p of d)for(const O of m)(O===p||x(t,p,O))&&c.add(O);const f=[...u].filter(p=>!m.has(p)||h.has(p)).sort((p,O)=>t.states[O].depth-t.states[p].depth),w=[...m].filter(p=>!u.has(p)||c.has(p)).sort((p,O)=>t.states[p].depth-t.states[O].depth);for(const p of f){const O=t.states[p];if(O.kind==="compound"||O.kind==="parallel"){const R=a.filter(z=>x(t,p,z));if(R.length!==0){const z=O.children.map(k=>t.states[k]).find(k=>k.kind==="history")?.history??O.history;e.history[O.path]=Object.freeze(R.map(k=>{if(z==="deep")return t.states[k].path;const j=jt(t,p,k);return t.states[j].path}))}}}const b=f.flatMap(p=>t.states[p].exit.map(O=>({event:r,ref:O}))),g=w.flatMap(p=>t.states[p].entry.map(O=>({event:r,ref:O})));return Object.freeze({changed:v||f.length!==0||w.length!==0,entered:Object.freeze(w),entryOutputs:Object.freeze(g),exited:Object.freeze(f),exitOutputs:Object.freeze(b),raised:Object.freeze(y),transitionOutputs:Object.freeze(l)})}function yt(t,e,n){n?.transition!==void 0&&n.transition({...e.reason===void 0?{}:{reason:e.reason},source:t.states[e.source].path,...e.target===void 0?{}:{target:t.states[e.target].path}})}function H(t,e,n,r,o,i){for(const s of t){if(s.guard===void 0)return s;const a=Jt(s.guard,r),u=a({context:e,event:n,input:o});if(i?.guard?.(typeof s.guard=="string"?s.guard:a.name||"inline",u,re(e)?e:void 0),u)return s}}function vt(t,e){const n=[...e].sort((o,i)=>t.states[i.source].depth-t.states[o.source].depth||o.source-i.source||o.index-i.index),r=[];for(const o of n)r.some(s=>Xt(t,o,s))||r.push(o);return r}function Xt(t,e,n){const r=X(t,e.source,e.target??e.source),o=X(t,n.source,n.target??n.source);return e.source===n.source||x(t,e.source,n.source)||x(t,n.source,e.source)||r===o||x(t,r,o)||x(t,o,r)}function X(t,e,n){if(e===n||x(t,e,n))return e;const r=Qt(t,e,n);return r!==void 0&&t.states[r].kind==="parallel"?r:r===void 0?V(t,e):jt(t,r,e)}function bt(t,e,n){const r=t.states[e];if(r.kind!=="history")return $(t,e,n);const o=r.parent,i=n[t.states[o].path];if(i!==void 0&&i.length!==0){const s=[];for(const a of i){const u=t.pathToState.get(a);u!==void 0&&s.push(...r.history==="deep"?$(t,u,n):$(t,u,{}))}if(s.length!==0)return M(s)}return r.historyFallback!==void 0?$(t,r.historyFallback,n):$(t,o,{})}function Zt(t,e,n){const r=[...e];for(let o=0;o<r.length;o++)for(const i of t.ancestry[r[o]].slice(1)){const s=t.states[i];if(s.kind==="parallel")for(const a of s.children)t.states[a].kind!=="history"&&(r.some(u=>u===a||x(t,a,u))||r.push(...$(t,a,n)))}return M(r)}function $(t,e,n){const r=t.states[e];if(r.kind==="history")return bt(t,e,n);if(r.kind==="atomic"||r.kind==="final")return[e];if(r.kind==="compound")return $(t,r.initial,n);const o=[];for(const i of r.children)t.states[i].kind!=="history"&&o.push(...$(t,i,n));return M(o)}function et(t,e,n){const r=t.states[e];return r.kind==="final"?n.includes(e):r.kind==="compound"?r.children.some(o=>t.states[o].kind==="final"&&n.includes(o)):r.kind==="parallel"?r.children.filter(o=>t.states[o].kind!=="history").every(o=>et(t,o,n)):!1}function nt(t,e){const n=te(t,e[0]);return n===void 0?!1:et(t,n,e)}function wt(t,e,n,r){const o=V(t,e.active[0]),i=t.states[o],s=i.kind==="compound"?e.active.find(u=>t.states[u].parent===o&&t.states[u].kind==="final"):i.kind==="final"?o:void 0,a=s===void 0?t.output:t.states[s].output??t.output;return typeof a=="function"?a({context:e.context,event:n,input:r}):a}function Jt(t,e){if(typeof t=="function")return t;const n=e?.guards?.[t];if(n===void 0)throw new Error(`[Raph machine] Guard binding "${t}" is not defined.`);return n}function Ot(t,e){if(typeof t=="function")return t;const n=e?.reducers?.[t];if(n===void 0)throw new Error(`[Raph machine] Reducer binding "${t}" is not defined.`);return n}function F(t,e,n,r,o,i,s){const a=s??A(t),u=a.flat&&n.active.length===1?n.active[0]:void 0,h=u===void 0?void 0:J(void 0,u,e,t,a.states[u].path),c=h===void 0?Object.freeze([...n.active]):void 0,d=h?.[T]??Object.freeze({active:c,input:e,model:t});return L({active:d.publicActive??Object.freeze(c.map(l=>a.states[l].path)),context:rt(n.context),history:a.flat?q:ne(n.history),...i===void 0?{}:{output:i},revision:r,status:o},d,h)}function D(t,e){return{changed:!1,plan:Q,snapshot:t}}function mt(){return Object.freeze({changed:!1,entered:Object.freeze([]),entryOutputs:Object.freeze([]),exited:Object.freeze([]),exitOutputs:Object.freeze([]),raised:Object.freeze([]),transitionOutputs:Object.freeze([])})}function at(t,e,n,r,o,i){for(const s of t.exited)e.add(s);for(const s of t.entered)n.add(s);r.push(...t.exitOutputs),o.push(...t.transitionOutputs),i.push(...t.entryOutputs)}function _(t,e){const n=new Set;for(const r of e)for(const o of t.ancestry[r])n.add(o);return[...n]}function Qt(t,e,n){const r=new Set(t.ancestry[e]);for(const o of t.ancestry[n])if(r.has(o))return o}function x(t,e,n){const r=t.ancestry[n];return r.length>1&&r.includes(e,1)}function jt(t,e,n){let r=n;for(;t.states[r].parent!==e;){const o=t.states[r].parent;if(o===void 0)return r;r=o}return r}function V(t,e){return t.ancestry[e].at(-1)}function te(t,e){return e===void 0?void 0:V(t,e)}function N(t,e){const n=t.pathToState.get(e);if(n===void 0)throw new Error(`[Raph machine] Snapshot contains unknown state "${e}".`);return n}function ee(t,e,n){if(!t.eventIndexes.has(n))return!1;for(const r of e){const o=t.pathToState.get(r);if(o!==void 0){for(const i of t.ancestry[o])if(t.states[i].on.has(n))return!0}}return!1}function M(t){return[...new Set(t)].sort((e,n)=>e-n)}function rt(t){return typeof t=="object"&&t!==null?Object.freeze(t):t}function ne(t){const e={};for(const[n,r]of Object.entries(t))e[n]=Object.freeze([...r]);return Object.freeze(e)}function Et(t){if(typeof t!="object"||t===null||typeof t.type!="string"||!t.type)throw new TypeError("[Raph machine] Event must contain a non-empty string type.")}function re(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}exports.assertMachineSnapshot=dt;exports.createInitialSnapshot=pt;exports.defineMachine=St;exports.getCompiledMachine=A;exports.getInitialSnapshot=qt;exports.hydrateSnapshot=Bt;exports.runExplicitTransitions=Vt;exports.runValidatedMacrostep=lt;exports.stopMachineSnapshot=Lt;exports.transition=Kt;
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var g=(u,e,t)=>e in u?m(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t;var s=(u,e,t)=>g(u,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../path/data-adapter.cjs");require("../path/data-path.cjs");const o=require("../path/derived-strategies.cjs");require("../path/RaphDerivedHandle.cjs");const d=require("../path/RaphKernel.cjs");require("../path/RaphMeta.cjs");require("../runtime/errors.cjs");require("../runtime/parent-graph.cjs");require("../runtime/PathHandle.cjs");const h=require("../runtime/phase.types.cjs");require("../runtime/RaphNode.cjs");const f=require("../runtime/RaphRuntime.cjs");require("../runtime/RaphScope.cjs");const r=require("./errors.cjs"),R=require("../reactivity/engine.cjs");function n(){throw new r.RaphConfigurationError("[Raph] Facade is not configured. Call Raph.configure({ mode }) first.")}class a{static get configured(){return this._state==="configured"}static get mode(){return this._mode}static configure(e){if(this._state!=="unconfigured")throw new r.RaphConfigurationError(`[Raph] Cannot configure facade while it is ${this._state}.`);this._state="configuring";try{if(this._validateConfigureOptions(e),e.mode==="reactivity")this._configureReactivity(new R.RaphReactivity);else if(e.mode==="runtime")this._configureRuntime(e);else throw new r.RaphConfigurationError("[Raph] Unsupported facade mode.");this._mode=e.mode,this._state="configured"}catch(t){const i=[t],c=[...this._runtimeOrder].reverse();this._clearSession();for(const l of c)try{l.dispose()}catch(_){i.push(_)}throw i.length===1?t:new AggregateError(i,"[Raph] Facade configuration and cleanup failed.")}}static reset(){if(this._state==="unconfigured")return;if(this._state!=="configured")throw new r.RaphConfigurationError(`[Raph] Cannot reset facade while it is ${this._state}.`);this._state="resetting";const e=[...this._runtimeOrder].reverse();this._clearBindings(),this._runtimes=new Map,this._runtimeOrder=[],this._defaultRuntime=void 0;const t=[];for(const i of e)try{i.dispose()}catch(c){t.push(c)}if(this._clearSession(),t.length===1)throw t[0];if(t.length>1)throw new AggregateError(t,"[Raph] Facade reset failed.")}static get runtime(){return this._requireDefault()}static get meta(){return this._requireDefault().meta}static get debug(){return this._requireDefault().debug}static get root(){return this._requireDefault().root}static getDerivedSnapshot(){return this._requireDefault().getDerivedSnapshot()}static createKernel(e={}){return this._requireMode("runtime"),new d.RaphKernel(e)}static createRuntime(e={}){this._requireMode("runtime");const t=this._resolveRuntimeId(e.id);if(this._runtimes.has(t))throw new r.RaphConfigurationError(`[Raph] Runtime id "${t}" is already registered.`);const i=new f.RaphRuntime({...this._runtimeDefaults,...e,id:t});return this._registerRuntime(i),i}static getRuntime(e){return this._requireMode("runtime"),this._validateRuntimeId(e),this._runtimes.get(e)}static requireRuntime(e){const t=this.getRuntime(e);if(t===void 0)throw new r.RaphConfigurationError(`[Raph] Runtime "${e}" is not registered.`);return t}static hasRuntime(e){return this.getRuntime(e)!==void 0}static disposeRuntime(e){const t=this.getRuntime(e);return t===void 0?!1:(t.dispose(),!0)}static definePhases(e){this._requireDefault().definePhases(e)}static addPhase(e){this._requireDefault().addPhase(e)}static clearPhases(){this._requireDefault().clearPhases()}static flush(){this._requireDefault().flush()}static acquireLoop(e){return this._requireDefault().acquireLoop(e)}static startLoop(){this._requireDefault().startLoop()}static stopLoop(){this._requireDefault().stopLoop()}static node(e,t){return this._requireDefault().node(e,t)}static derive(e){return this._requireDefault().derive(e)}static path(e,t={}){return this._requireDefault().path(e,t)}static get(e,t){const i=this._requireDefault();return e===void 0?i.get():i.get(e,t)}static peek(e,t){const i=this._requireDefault();return e===void 0?i.peek():i.peek(e,t)}static has(e,t){return this._requireDefault().has(e,t)}static set(e,t,i){this._requireDefault().set(e,t,i)}static merge(e,t,i){this._requireDefault().merge(e,t,i)}static delete(e,t){this._requireDefault().delete(e,t)}static transaction(e){return this._requireDefault().transaction(e)}static action(e,t){return this._requireDefault().action(e,t)}static runInAction(e,t){return this._requireDefault().runInAction(e,t)}static _configureReactivity(e){this._reactivity=e,this.signal=e.signal,this.computed=e.computed,this.effect=(t=>{if(typeof t!="function")throw new r.RaphModeError("[Raph] Phase effects require runtime mode.");return e.effect(t)}),this.watch=e.watch,this.batch=e.batch,this.untracked=e.untracked,this.scope=e.scope}static _configureRuntime(e){if(this._runtimeDefaults={...e.scheduler===void 0?{}:{scheduler:e.scheduler},...e.enforceActions===void 0?{}:{enforceActions:e.enforceActions}},e.createDefaultRuntime===!1){this._installMissingDefaultBindings();return}const t=e.defaultRuntimeId??"default";this._validateRuntimeId(t);const i=new f.RaphRuntime({...this._runtimeDefaults,...e.kernel===void 0?{}:{kernel:e.kernel},id:t});this._registerRuntime(i),e.phases!==void 0&&i.definePhases(e.phases),this._defaultRuntime=i,this._bindRuntime(i)}static _bindRuntime(e){this.signal=e.signal.bind(e),this.computed=e.computed.bind(e),this.effect=e.effect.bind(e),this.watch=e.watch.bind(e),this.batch=e.transaction.bind(e),this.untracked=e.untracked.bind(e),this.scope=e.scope.bind(e)}static _registerRuntime(e){this._runtimes.set(e.id,e),this._runtimeOrder.push(e),e._onDisposed(()=>{this._runtimes.get(e.id)===e&&this._runtimes.delete(e.id);const t=this._runtimeOrder.indexOf(e);t>=0&&this._runtimeOrder.splice(t,1),this._defaultRuntime===e&&(this._defaultRuntime=void 0,this._state==="configured"&&this._installMissingDefaultBindings())})}static _requireDefault(){this._requireMode("runtime");const e=this._defaultRuntime;if(e===void 0)throw new r.RaphDefaultRuntimeError("[Raph] Runtime mode has no default Runtime.");return e}static _requireMode(e){if(this._state!=="configured"&&n(),this._mode!==e)throw new r.RaphModeError(`[Raph] Operation requires ${e} mode.`)}static _resolveRuntimeId(e){if(e!==void 0)return this._validateRuntimeId(e),e;let t;do t=`runtime-${this._runtimeCounter++}`;while(this._runtimes.has(t));return t}static _validateRuntimeId(e){if(typeof e!="string"||e.length===0||e.trim()!==e)throw new r.RaphConfigurationError("[Raph] Runtime id must be a non-empty string without surrounding whitespace.")}static _validateConfigureOptions(e){if(typeof e!="object"||e===null)throw new r.RaphConfigurationError("[Raph] Configure options must be an object.");if(e.mode==="reactivity"){this._assertKnownOptions(e,new Set(["mode"]));return}if(e.mode!=="runtime")throw new r.RaphConfigurationError("[Raph] Unsupported facade mode.");if(this._assertKnownOptions(e,new Set(["mode","createDefaultRuntime","defaultRuntimeId","kernel","phases","scheduler","enforceActions"])),e.createDefaultRuntime!==void 0&&e.createDefaultRuntime!==!0&&e.createDefaultRuntime!==!1)throw new r.RaphConfigurationError("[Raph] createDefaultRuntime must be boolean.");if(e.scheduler!==void 0&&!p(e.scheduler))throw new r.RaphConfigurationError(`[Raph] Unsupported scheduler "${String(e.scheduler)}".`);if(e.enforceActions!==void 0&&typeof e.enforceActions!="boolean")throw new r.RaphConfigurationError("[Raph] enforceActions must be boolean.");if(e.createDefaultRuntime===!1){if(e.defaultRuntimeId!==void 0||e.kernel!==void 0||e.phases!==void 0)throw new r.RaphConfigurationError("[Raph] Registry-only mode cannot receive defaultRuntimeId, kernel or phases.");return}if(e.defaultRuntimeId!==void 0&&this._validateRuntimeId(e.defaultRuntimeId),e.kernel!==void 0&&!(e.kernel instanceof d.RaphKernel))throw new r.RaphConfigurationError("[Raph] kernel must be a RaphKernel instance.");if(e.phases!==void 0&&!Array.isArray(e.phases))throw new r.RaphConfigurationError("[Raph] phases must be an array.")}static _assertKnownOptions(e,t){for(const i of Object.keys(e))if(!t.has(i))throw new r.RaphConfigurationError(`[Raph] Unsupported configure option "${i}".`)}static _installMissingDefaultBindings(){const e=()=>{throw new r.RaphDefaultRuntimeError("[Raph] Runtime mode has no default Runtime.")};this.signal=e,this.computed=e,this.effect=e,this.watch=e,this.batch=e,this.untracked=e,this.scope=e}static _clearBindings(){this.signal=n,this.computed=n,this.effect=n,this.watch=n,this.batch=n,this.untracked=n,this.scope=n}static _clearSession(){this._clearBindings(),this._state="unconfigured",this._mode=void 0,this._defaultRuntime=void 0,this._reactivity=void 0,this._runtimes=new Map,this._runtimeOrder=[],this._runtimeDefaults={}}constructor(){}}s(a,"_state","unconfigured"),s(a,"_mode"),s(a,"_defaultRuntime"),s(a,"_reactivity"),s(a,"_runtimes",new Map),s(a,"_runtimeOrder",[]),s(a,"_runtimeCounter",0),s(a,"_runtimeDefaults",{}),s(a,"signal",n),s(a,"computed",n),s(a,"effect",n),s(a,"watch",n),s(a,"batch",n),s(a,"untracked",n),s(a,"scope",n),s(a,"Scheduler",h.RaphSchedulerType),s(a,"DerivedStrategy",Object.freeze({full:o.full,collectionByKey:o.collectionByKey,filterByKey:o.filterByKey}));function p(u){return u===h.RaphSchedulerType.Sync||u===h.RaphSchedulerType.Microtask||u===h.RaphSchedulerType.AnimationFrame}exports.Raph=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../path/derived/derived-strategy.utils.cjs"),h=require("../runtime/phases/phase.types.cjs"),_=require("../runtime/RaphRuntime.cjs"),n=require("./errors.cjs"),d=require("./RaphFacadeSession.cjs"),c=require("./RaphReactivityInstance.cjs");class p{constructor(e){this._session=e}get configured(){return!0}get defaultInstanceId(){return this._session.defaultInstanceId}get kernel(){return this._runtime().kernel}get meta(){return this._runtime().meta}get debug(){return this._runtime().debug}get root(){return this._runtime().root}get rootScope(){return this._runtime().rootScope}get frameTick(){return this._runtime().frameTick}get frame(){return this._runtime().frame}get phases(){return this._runtime().phases}get loopEnabled(){return this._runtime().loopEnabled}instance(e){return this._session.instance(e)}getInstance(e){return this._session.getInstance(e)}hasInstance(e){return this._session.hasInstance(e)}disposeInstance(e){return this._session.disposeInstance(e)}runtime(e){return this._session.runtime(e)}reactivity(e){return this._session.reactivity(e)}createRuntime(e={}){return this._session.createRuntime(e)}createReactivity(e={}){return this._session.createReactivity(e)}createKernel(e={}){return this._session.createKernel(e)}signal(e){return this._reactive().signal(e)}reactive(e){return this._reactive().reactive(e)}computed(e){const t=this._reactive();return t instanceof _.RaphRuntime,t.computed(e)}effect(e,t,r){const i=this._session.instance();if(i instanceof c.RaphReactivityInstance){if(typeof e!="function"||t!==void 0)throw o("phase effect",i);return i.effect(e)}if(typeof e!="string"||t===void 0)throw new n.RaphCapabilityError("[Raph] Runtime effects require an explicit phase.");return i.effect(i.rootScope,e,t,r)}watch(e,t,r,i){const s=this._session.instance();if(s instanceof c.RaphReactivityInstance){if(typeof t!="function")throw o("phase watch",s);return s.watch(e,t,r)}if(typeof t!="string"||typeof r!="function")throw new n.RaphCapabilityError("[Raph] Runtime watches require an explicit phase.");return s.watch(s.rootScope,e,t,r,i)}batch(e){return this._reactive().batch(e)}untracked(e){return this._reactive().untracked(e)}scope(e){const t=this._session.instance();if(t instanceof c.RaphReactivityInstance){if(e!==void 0)throw o("named Runtime scope",t);return t.scope()}if(e===void 0)throw new n.RaphCapabilityError("[Raph] Runtime scopes require an explicit id.");return t.scope(e)}action(e,t){return typeof e=="function"?this._runtime().action(e):this._runtime().action(e,t)}definePhases(e){this._runtime().definePhases(e)}addPhase(e){this._runtime().addPhase(e)}clearPhases(){this._runtime().clearPhases()}requestExecution(){this._runtime().requestExecution()}flush(){this._runtime().flush()}afterFlush(){return this._runtime().afterFlush()}acquireLoop(e){return this._runtime().acquireLoop(e)}startLoop(){this._runtime().startLoop()}stopLoop(){this._runtime().stopLoop()}aggregate(e){const t=this._runtime();return t.aggregate(t.rootScope,e)}node(e,t){return this._runtime().node(e,t)}getNode(e){return this._runtime().getNode(e)}derive(e){return this._runtime().derive(e)}getDerivedSnapshot(){return this._runtime().getDerivedSnapshot()}path(e,t={}){return this._runtime().path(e,t)}get(e,t){return e===void 0?this._runtime().get():this._runtime().get(e,t)}peek(e,t){return e===void 0?this._runtime().peek():this._runtime().peek(e,t)}has(e,t){return this._runtime().has(e,t)}set(e,t,r){this._runtime().set(e,t,r)}merge(e,t,r){this._runtime().merge(e,t,r)}delete(e,t){this._runtime().delete(e,t)}_dispose(){this._session.dispose()}_runtime(){return this._session.runtime()}_reactive(){return this._session.instance()}}class f{static _handle;constructor(){}static get configured(){return this._handle!==void 0}static get defaultInstanceId(){return this._require().defaultInstanceId}static get kernel(){return this._require().kernel}static get meta(){return this._require().meta}static get debug(){return this._require().debug}static get root(){return this._require().root}static get rootScope(){return this._require().rootScope}static get frameTick(){return this._require().frameTick}static get frame(){return this._require().frame}static get phases(){return this._require().phases}static get loopEnabled(){return this._require().loopEnabled}static configure(e){if(this._handle!==void 0)throw new n.RaphConfigurationError("[Raph] Facade is already configured.");const t=new p(d.RaphFacadeSession.create(e));return this._handle=t,t}static reset(){const e=this._handle;e!==void 0&&(this._handle=void 0,e._dispose())}static instance(e){return this._require().instance(e)}static getInstance(e){return this._require().getInstance(e)}static hasInstance(e){return this._require().hasInstance(e)}static disposeInstance(e){return this._require().disposeInstance(e)}static runtime(e){return this._require().runtime(e)}static reactivity(e){return this._require().reactivity(e)}static createRuntime(e={}){return this._require().createRuntime(e)}static createReactivity(e={}){return this._require().createReactivity(e)}static createKernel(e={}){return this._require().createKernel(e)}static signal(e){return this._require().signal(e)}static reactive(e){return this._require().reactive(e)}static computed(e){return typeof e=="function"?this._require().computed(e):this._require().computed(e)}static effect(e,t,r){return typeof e=="function"?this._require().effect(e):this._require().effect(e,t,r)}static watch(e,t,r,i){const s=this._require();return typeof t=="string"?s.watch(e,t,r,i):s.watch(e,t,r)}static batch(e){return this._require().batch(e)}static untracked(e){return this._require().untracked(e)}static scope(e){return e===void 0?this._require().scope():this._require().scope(e)}static action(e,t){return typeof e=="function"?this._require().action(e):this._require().action(e,t)}static definePhases(e){this._require().definePhases(e)}static addPhase(e){this._require().addPhase(e)}static clearPhases(){this._require().clearPhases()}static requestExecution(){this._require().requestExecution()}static flush(){this._require().flush()}static afterFlush(){return this._require().afterFlush()}static acquireLoop(e){return this._require().acquireLoop(e)}static startLoop(){this._require().startLoop()}static stopLoop(){this._require().stopLoop()}static aggregate(e){return this._require().aggregate(e)}static node(e,t){return this._require().node(e,t)}static getNode(e){return this._require().getNode(e)}static derive(e){return this._require().derive(e)}static getDerivedSnapshot(){return this._require().getDerivedSnapshot()}static path(e,t={}){return this._require().path(e,t)}static get(e,t){return e===void 0?this._require().get():this._require().get(e,t)}static peek(e,t){return e===void 0?this._require().peek():this._require().peek(e,t)}static has(e,t){return this._require().has(e,t)}static set(e,t,r){this._require().set(e,t,r)}static merge(e,t,r){this._require().merge(e,t,r)}static delete(e,t){this._require().delete(e,t)}static Scheduler=h.RaphSchedulerType;static DerivedStrategy=Object.freeze({full:a.full,collectionByKey:a.collectionByKey,filterByKey:a.filterByKey});static _require(){const e=this._handle;if(e===void 0)throw new n.RaphConfigurationError("[Raph] Facade is not configured. Call Raph.configure(...) first.");return e}}function o(u,e){return new n.RaphCapabilityError(`[Raph] ${u} is unavailable for reactivity instance "${e.id}".`)}exports.Raph=f;