likec4 1.59.4 → 1.61.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 (186) hide show
  1. package/README.md +2 -0
  2. package/__app__/codegen/react.mjs +4 -10
  3. package/__app__/codegen/webcomponent.mjs +6 -131
  4. package/__app__/index.html +15 -15
  5. package/__app__/src/aichat/index.mjs +11 -7
  6. package/__app__/src/chunks/AIChat.mjs +1355 -739
  7. package/__app__/src/chunks/ErrorComponent.mjs +444 -0
  8. package/__app__/src/chunks/Header.mjs +269 -0
  9. package/__app__/src/chunks/ViewReact.mjs +438 -0
  10. package/__app__/src/chunks/find.mjs +38 -0
  11. package/__app__/src/chunks/hooks.mjs +158 -472
  12. package/__app__/src/chunks/libs/@tabler/icons-react.mjs +340 -0
  13. package/__app__/src/chunks/libs/@tanstack-ai.mjs +11841 -1417
  14. package/__app__/src/chunks/libs/@tanstack.mjs +5110 -2404
  15. package/__app__/src/chunks/libs/fast-equals.mjs +507 -214
  16. package/__app__/src/chunks/libs/html-to-image.mjs +613 -0
  17. package/__app__/src/chunks/libs/nanostores.mjs +170 -0
  18. package/__app__/src/chunks/libs/react-resizable-panels.mjs +2792 -0
  19. package/__app__/src/chunks/react.mjs +22 -0
  20. package/__app__/src/chunks/rolldown-runtime.mjs +16 -29
  21. package/__app__/src/chunks/router.mjs +106 -0
  22. package/__app__/src/chunks/scope.mjs +106 -0
  23. package/__app__/src/chunks/searchParams.mjs +29 -0
  24. package/__app__/src/chunks/single-index.mjs +465 -0
  25. package/__app__/src/chunks/styled-system.mjs +1826 -2528
  26. package/__app__/src/chunks/useAsync.mjs +69 -0
  27. package/__app__/src/chunks/useSyncedRef.mjs +16 -0
  28. package/__app__/src/components/ColorSchemeToggle.mjs +124 -0
  29. package/__app__/src/components/CopyToClipboard.mjs +53 -0
  30. package/__app__/src/components/ErrorComponent.mjs +1 -0
  31. package/__app__/src/components/NavigationPanel.mjs +63 -0
  32. package/__app__/src/components/NotFound.mjs +155 -0
  33. package/__app__/src/components/ViewOutlet.mjs +9 -0
  34. package/__app__/src/components/model-diff/CompareModelProvider.mjs +44 -0
  35. package/__app__/src/components/model-diff/ModelDiffPanel.mjs +179 -0
  36. package/__app__/src/components/model-diff/compare-model.mjs +76 -0
  37. package/__app__/src/components/model-diff/state.mjs +45 -0
  38. package/__app__/src/components/search/OverviewSearch.mjs +92 -0
  39. package/__app__/src/components/search/OverviewSearchAdapter.mjs +94 -0
  40. package/__app__/src/components/sidebar/DiagramTree.css.mjs +48 -0
  41. package/__app__/src/components/sidebar/DiagramsTree.mjs +304 -0
  42. package/__app__/src/components/sidebar/Drawer.mjs +178 -0
  43. package/__app__/src/components/sidebar/SidebarBurger.mjs +28 -0
  44. package/__app__/src/components/sidebar/data.mjs +94 -0
  45. package/__app__/src/components/sidebar/state.mjs +16 -0
  46. package/__app__/src/components/view-page/Header.mjs +1 -0
  47. package/__app__/src/components/view-page/SelectProject.mjs +258 -0
  48. package/__app__/src/components/view-page/ShareModal.mjs +111 -0
  49. package/__app__/src/components/view-page/share-modal/AlertLocalhost.mjs +31 -0
  50. package/__app__/src/components/view-page/share-modal/CopyButtonChild.mjs +36 -0
  51. package/__app__/src/components/view-page/share-modal/EmbedPanel.mjs +100 -0
  52. package/__app__/src/components/view-page/share-modal/WebcomponentsPanel.mjs +264 -0
  53. package/__app__/src/components/view-page/state.mjs +17 -0
  54. package/__app__/src/context/LikeC4CustomizationContext.mjs +26 -0
  55. package/__app__/src/context/LikeC4IconRendererContext.mjs +29 -0
  56. package/__app__/src/context/LikeC4ModelContext.mjs +34 -0
  57. package/__app__/src/context/LikeC4ProjectsContext.mjs +40 -0
  58. package/__app__/src/context/ModelDiffsContext.mjs +33 -0
  59. package/__app__/src/context/safeCtx.mjs +14 -0
  60. package/__app__/src/fonts.css +112 -1
  61. package/__app__/src/hooks.mjs +1 -0
  62. package/__app__/src/main.mjs +6 -29151
  63. package/__app__/src/pages/EmbedPage.mjs +93 -0
  64. package/__app__/src/pages/ExportPage.mjs +691 -0
  65. package/__app__/src/pages/ProjectsOverview.mjs +23 -0
  66. package/__app__/src/pages/ViewAsD2.mjs +105 -0
  67. package/__app__/src/pages/ViewAsDot.mjs +65 -0
  68. package/__app__/src/pages/ViewAsMmd.mjs +109 -0
  69. package/__app__/src/pages/ViewAsPuml.mjs +105 -0
  70. package/__app__/src/pages/ViewEditor.mjs +220 -0
  71. package/__app__/src/pages/ViewReact.mjs +1 -0
  72. package/__app__/src/pages/export-layout.mjs +95 -0
  73. package/__app__/src/pages/export-page-params.mjs +9 -0
  74. package/__app__/src/pages/styles.css.mjs +23 -0
  75. package/__app__/src/routeTree.gen.mjs +105 -0
  76. package/__app__/src/router.mjs +1 -0
  77. package/__app__/src/routes/__root.mjs +65 -0
  78. package/__app__/src/routes/index.css.mjs +29 -0
  79. package/__app__/src/routes/index.mjs +32 -0
  80. package/__app__/src/routes/project._projectId/-components.mjs +100 -0
  81. package/__app__/src/routes/project._projectId/embed._viewId.mjs +5 -0
  82. package/__app__/src/routes/project._projectId/export._viewId.mjs +24 -0
  83. package/__app__/src/routes/project._projectId/index.mjs +14 -0
  84. package/__app__/src/routes/project._projectId/route.mjs +93 -0
  85. package/__app__/src/routes/project._projectId/view._viewId.d2.mjs +34 -0
  86. package/__app__/src/routes/project._projectId/view._viewId.dot.mjs +41 -0
  87. package/__app__/src/routes/project._projectId/view._viewId.index.mjs +7 -0
  88. package/__app__/src/routes/project._projectId/view._viewId.mjs +23 -0
  89. package/__app__/src/routes/project._projectId/view._viewId.mmd.mjs +39 -0
  90. package/__app__/src/routes/project._projectId/view._viewId.puml.mjs +34 -0
  91. package/__app__/src/routes/projects.mjs +36 -0
  92. package/__app__/src/routes/single-index.mjs +1 -0
  93. package/__app__/src/routes/webcomponent._.mjs +94 -0
  94. package/__app__/src/style.css +18497 -1
  95. package/config/schema.json +146 -97
  96. package/dist/app/render-view-client.css +1 -1
  97. package/dist/app/render-view-client.js +394 -238
  98. package/dist/chunks/enableServer.mjs +1 -1
  99. package/dist/chunks/filenames.mjs +25 -17
  100. package/dist/chunks/generate-likec4.mjs +5 -0
  101. package/dist/chunks/index.d.mts +255 -194
  102. package/dist/chunks/index2.d.mts +8246 -3610
  103. package/dist/chunks/libs/@chenglou/pretext.mjs +9 -0
  104. package/dist/chunks/libs/@chevrotain/gast.mjs +27 -1
  105. package/dist/chunks/libs/@chevrotain/regexp-to-ast.mjs +81 -9
  106. package/dist/chunks/libs/@logtape/logtape.mjs +5 -4
  107. package/dist/chunks/libs/@lume/kiwi.mjs +1 -1
  108. package/dist/chunks/libs/@ts-graphviz/common.d.mts +2 -4
  109. package/dist/chunks/libs/@ts-graphviz/core.mjs +1 -1
  110. package/dist/chunks/libs/birpc.mjs +1 -1
  111. package/dist/chunks/libs/chevrotain-allstar.mjs +2 -2
  112. package/dist/chunks/libs/chevrotain.mjs +88 -36
  113. package/dist/chunks/libs/clone.mjs +1 -0
  114. package/dist/chunks/libs/eventemitter3.mjs +1 -1
  115. package/dist/chunks/libs/fast-equals.mjs +1 -0
  116. package/dist/chunks/libs/fontkit.mjs +1 -0
  117. package/dist/chunks/libs/json5.mjs +4 -4
  118. package/dist/chunks/libs/langium.d.mts +6707 -6715
  119. package/dist/chunks/libs/langium.mjs +16 -24
  120. package/dist/chunks/libs/merge-error-cause.mjs +1 -1
  121. package/dist/chunks/libs/p-limit.mjs +1 -0
  122. package/dist/chunks/libs/p-queue.mjs +1 -1
  123. package/dist/chunks/libs/package-manager-detector.mjs +1 -1
  124. package/dist/chunks/libs/pako.mjs +1 -1
  125. package/dist/chunks/libs/pathe.mjs +1 -1
  126. package/dist/chunks/libs/pretty-ms.mjs +1 -1
  127. package/dist/chunks/libs/remeda.mjs +1 -1
  128. package/dist/chunks/libs/ufo.mjs +1 -1
  129. package/dist/chunks/libs/unstorage.mjs +1 -1
  130. package/dist/chunks/libs/which.mjs +1 -1
  131. package/dist/chunks/node.mjs +111 -77
  132. package/dist/chunks/rolldown-runtime.mjs +1 -1
  133. package/dist/chunks/sequence-view.mjs +1 -1
  134. package/dist/chunks/vite-plugin.mjs +185 -166
  135. package/dist/cli/index.mjs +254 -1306
  136. package/dist/config/index.d.mts +66 -5
  137. package/dist/config/index.mjs +1 -1
  138. package/dist/generators/likec4.d.mts +6530 -0
  139. package/dist/generators/likec4.mjs +1 -0
  140. package/dist/index.d.mts +2 -4
  141. package/dist/model/index.d.mts +0 -7
  142. package/dist/vite-plugin/index.d.mts +83 -58
  143. package/dist/vite-plugin/index.mjs +1 -1
  144. package/dist/vite-plugin/internal/chunks/rolldown-runtime.mjs +8 -0
  145. package/dist/vite-plugin/internal/index.d.mts +92 -17
  146. package/dist/vite-plugin/internal/index.mjs +225 -126
  147. package/generators/likec4/package.json +4 -0
  148. package/package.json +134 -122
  149. package/react/index.d.mts +7496 -26659
  150. package/react/index.mjs +533 -63936
  151. package/react/rolldown-runtime-CfRud99p.js +1 -0
  152. package/skills/likec4-dsl/SKILL.md +474 -0
  153. package/skills/likec4-dsl/evals/evals-public.json +207 -0
  154. package/skills/likec4-dsl/evals/grading-spec.json +603 -0
  155. package/skills/likec4-dsl/references/bridge-leanix-drawio.md +42 -0
  156. package/skills/likec4-dsl/references/cli.md +168 -0
  157. package/skills/likec4-dsl/references/configuration.md +266 -0
  158. package/skills/likec4-dsl/references/deployment.md +160 -0
  159. package/skills/likec4-dsl/references/diffs.md +52 -0
  160. package/skills/likec4-dsl/references/dynamic-views.md +455 -0
  161. package/skills/likec4-dsl/references/examples.md +370 -0
  162. package/skills/likec4-dsl/references/identifier-validity.md +90 -0
  163. package/skills/likec4-dsl/references/include-predicates-wildcards.md +180 -0
  164. package/skills/likec4-dsl/references/model.md +182 -0
  165. package/skills/likec4-dsl/references/predicates.md +123 -0
  166. package/skills/likec4-dsl/references/relationships-bidirectional.md +176 -0
  167. package/skills/likec4-dsl/references/specification.md +79 -0
  168. package/skills/likec4-dsl/references/style-tokens-colors.md +150 -0
  169. package/skills/likec4-dsl/references/troubleshooting.md +101 -0
  170. package/skills/likec4-dsl/references/views.md +329 -0
  171. package/vite-plugin-modules.d.ts +126 -51
  172. package/__app__/src/chunks/LikeC4Styles.mjs +0 -2306
  173. package/__app__/src/chunks/ProjectsOverview.mjs +0 -537
  174. package/__app__/src/chunks/es.mjs +0 -439
  175. package/__app__/src/chunks/libs/@floating-ui.mjs +0 -2532
  176. package/__app__/src/chunks/libs/@mantine.mjs +0 -13868
  177. package/__app__/src/chunks/libs/@xstate/react.mjs +0 -2015
  178. package/__app__/src/chunks/libs/@xyflow/react.mjs +0 -5367
  179. package/__app__/src/chunks/libs/bezier-js.mjs +0 -1007
  180. package/__app__/src/chunks/libs/d3.mjs +0 -2817
  181. package/__app__/src/chunks/libs/framer.mjs +0 -5926
  182. package/__app__/src/chunks/libs/zod.mjs +0 -3176
  183. package/dist/chunks/libs/@chevrotain/types.d.mts +0 -108
  184. package/dist/chunks/libs/picomatch.mjs +0 -1
  185. package/dist/chunks/libs/zod.d.mts +0 -3840
  186. package/dist/chunks/libs/zod.mjs +0 -65
@@ -1,2015 +0,0 @@
1
- import { i as e } from "../../rolldown-runtime.mjs";
2
- import { useCallback as t, useEffect as n, useLayoutEffect as r, useState as i } from "react";
3
- import { useSyncExternalStoreWithSelector as a } from "use-sync-external-store/shim/with-selector";
4
- //#region ../../node_modules/.pnpm/use-isomorphic-layout-effect@1.2.1_@types+react@19.2.18_react@19.2.8/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js
5
- var o = r;
6
- //#endregion
7
- //#region ../../node_modules/.pnpm/xstate@5.32.6/node_modules/xstate/dist/xstate-dev.esm.js
8
- function getGlobal() {
9
- if (typeof globalThis < "u") return globalThis;
10
- if (typeof self < "u") return self;
11
- if (typeof window < "u") return window;
12
- if (typeof global < "u") return global;
13
- }
14
- function getDevTools() {
15
- let e = getGlobal();
16
- if (e.__xstate__) return e.__xstate__;
17
- }
18
- var devToolsAdapter = (e) => {
19
- if (typeof window > "u") return;
20
- let t = getDevTools();
21
- t && t.register(e);
22
- }, Mailbox = class {
23
- constructor(e) {
24
- this._process = e, this._active = !1, this._current = null, this._last = null;
25
- }
26
- start() {
27
- this._active = !0, this.flush();
28
- }
29
- clear() {
30
- this._current && (this._current.next = null, this._last = this._current);
31
- }
32
- enqueue(e) {
33
- let t = {
34
- value: e,
35
- next: null
36
- };
37
- if (this._current) {
38
- this._last.next = t, this._last = t;
39
- return;
40
- }
41
- this._current = t, this._last = t, this._active && this.flush();
42
- }
43
- flush() {
44
- for (; this._current;) {
45
- let e = this._current;
46
- this._process(e.value), this._current = e.next;
47
- }
48
- this._last = null;
49
- }
50
- }, s = "", c = "#", l = "*", u = "xstate.init", d = "xstate.stop";
51
- function createAfterEvent(e, t) {
52
- return { type: `xstate.after.${e}.${t}` };
53
- }
54
- function createDoneStateEvent(e, t) {
55
- return {
56
- type: `xstate.done.state.${e}`,
57
- output: t
58
- };
59
- }
60
- function createDoneActorEvent(e, t) {
61
- return {
62
- type: `xstate.done.actor.${e}`,
63
- output: t,
64
- actorId: e
65
- };
66
- }
67
- function createErrorActorEvent(e, t) {
68
- return {
69
- type: `xstate.error.actor.${e}`,
70
- error: t,
71
- actorId: e
72
- };
73
- }
74
- function createInitEvent(e) {
75
- return {
76
- type: u,
77
- input: e
78
- };
79
- }
80
- function reportUnhandledError(e) {
81
- setTimeout(() => {
82
- throw e;
83
- });
84
- }
85
- var f = typeof Symbol == "function" && Symbol.observable || "@@observable";
86
- function matchesState(e, t) {
87
- let n = toStateValue(e), r = toStateValue(t);
88
- return typeof r == "string" ? typeof n == "string" && r === n : typeof n == "string" ? n in r : Object.keys(n).every((e) => e in r && matchesState(n[e], r[e]));
89
- }
90
- function toStatePath(e) {
91
- if (isArray(e)) return e;
92
- let t = [], n = "";
93
- for (let r = 0; r < e.length; r++) {
94
- switch (e.charCodeAt(r)) {
95
- case 92:
96
- n += e[r + 1], r++;
97
- continue;
98
- case 46:
99
- t.push(n), n = "";
100
- continue;
101
- }
102
- n += e[r];
103
- }
104
- return t.push(n), t;
105
- }
106
- function toStateValue(e) {
107
- return isMachineSnapshot(e) ? e.value : typeof e == "string" ? pathToStateValue(toStatePath(e)) : e;
108
- }
109
- function pathToStateValue(e) {
110
- if (e.length === 1) return e[0];
111
- let t = {}, n = t;
112
- for (let t = 0; t < e.length - 1; t++) if (t === e.length - 2) n[e[t]] = e[t + 1];
113
- else {
114
- let r = n;
115
- n = {}, r[e[t]] = n;
116
- }
117
- return t;
118
- }
119
- function mapValues(e, t) {
120
- let n = {}, r = Object.keys(e);
121
- for (let i = 0; i < r.length; i++) {
122
- let a = r[i];
123
- n[a] = t(e[a], a, e, i);
124
- }
125
- return n;
126
- }
127
- function toArrayStrict(e) {
128
- return isArray(e) ? e : [e];
129
- }
130
- function toArray(e) {
131
- return e === void 0 ? [] : toArrayStrict(e);
132
- }
133
- function resolveOutput(e, t, n, r) {
134
- return typeof e == "function" ? e({
135
- context: t,
136
- event: n,
137
- self: r
138
- }) : e;
139
- }
140
- function isArray(e) {
141
- return Array.isArray(e);
142
- }
143
- function isErrorActorEvent(e) {
144
- return e.type.startsWith("xstate.error.actor");
145
- }
146
- function toTransitionConfigArray(e) {
147
- return toArrayStrict(e).map((e) => e === void 0 || typeof e == "string" ? { target: e } : e);
148
- }
149
- function normalizeTarget(e) {
150
- if (e !== void 0 && e !== s) return toArray(e);
151
- }
152
- function toObserver(e, t, n) {
153
- let r = typeof e == "object", i = r ? e : void 0;
154
- return {
155
- next: (r ? e.next : e)?.bind(i),
156
- error: (r ? e.error : t)?.bind(i),
157
- complete: (r ? e.complete : n)?.bind(i)
158
- };
159
- }
160
- function createInvokeId(e, t) {
161
- return `${t}.${e}`;
162
- }
163
- function resolveReferencedActor(e, t) {
164
- let n = t.match(/^xstate\.invoke\.(\d+)\.(.*)/);
165
- if (!n) return e.implementations.actors[t];
166
- let [, r, i] = n, a = e.getStateNodeById(i).config.invoke;
167
- return (Array.isArray(a) ? a[r] : a).src;
168
- }
169
- function matchesEventDescriptor(e, t) {
170
- if (t === e || t === l) return !0;
171
- if (!t.endsWith(".*")) return !1;
172
- let n = t.split("."), r = e.split(".");
173
- for (let e = 0; e < n.length; e++) {
174
- let t = n[e], i = r[e];
175
- if (t === "*") return e === n.length - 1;
176
- if (t !== i) return !1;
177
- }
178
- return !0;
179
- }
180
- function createScheduledEventId(e, t) {
181
- return `${e.sessionId}.${t}`;
182
- }
183
- var p = 0;
184
- function createSystem(e, t) {
185
- let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new Set(), o = {}, { clock: s, logger: c } = t, l = {
186
- schedule: (e, t, n, r, i = Math.random().toString(36).slice(2)) => {
187
- let a = {
188
- source: e,
189
- target: t,
190
- event: n,
191
- delay: r,
192
- id: i,
193
- startedAt: Date.now()
194
- }, c = createScheduledEventId(e, i);
195
- u._snapshot._scheduledEvents[c] = a;
196
- let l = s.setTimeout(() => {
197
- delete o[c], delete u._snapshot._scheduledEvents[c], u._relay(e, t, n);
198
- }, r);
199
- o[c] = l;
200
- },
201
- cancel: (e, t) => {
202
- let n = createScheduledEventId(e, t), r = o[n];
203
- delete o[n], delete u._snapshot._scheduledEvents[n], r !== void 0 && s.clearTimeout(r);
204
- },
205
- cancelAll: (e) => {
206
- for (let t in u._snapshot._scheduledEvents) {
207
- let n = u._snapshot._scheduledEvents[t];
208
- n.source === e && l.cancel(e, n.id);
209
- }
210
- }
211
- }, sendInspectionEvent = (t) => {
212
- if (!a.size) return;
213
- let n = {
214
- ...t,
215
- rootId: e.sessionId
216
- };
217
- a.forEach((e) => e.next?.(n));
218
- }, u = {
219
- _snapshot: { _scheduledEvents: (t?.snapshot && t.snapshot.scheduler) ?? {} },
220
- _bookId: () => `x:${p++}`,
221
- _register: (e, t) => (n.set(e, t), e),
222
- _unregister: (e) => {
223
- n.delete(e.sessionId);
224
- let t = i.get(e);
225
- t !== void 0 && (r.delete(t), i.delete(e));
226
- },
227
- get: (e) => r.get(e),
228
- getAll: () => Object.fromEntries(r.entries()),
229
- _set: (e, t) => {
230
- let n = r.get(e);
231
- if (n && n !== t) throw Error(`Actor with system ID '${e}' already exists.`);
232
- r.set(e, t), i.set(t, e);
233
- },
234
- inspect: (e) => {
235
- let t = toObserver(e);
236
- return a.add(t), { unsubscribe() {
237
- a.delete(t);
238
- } };
239
- },
240
- _sendInspectionEvent: sendInspectionEvent,
241
- _relay: (e, t, n) => {
242
- u._sendInspectionEvent({
243
- type: "@xstate.event",
244
- sourceRef: e,
245
- actorRef: t,
246
- event: n
247
- }), t._send(n);
248
- },
249
- scheduler: l,
250
- getSnapshot: () => ({ _scheduledEvents: { ...u._snapshot._scheduledEvents } }),
251
- start: () => {
252
- let e = u._snapshot._scheduledEvents;
253
- u._snapshot._scheduledEvents = {};
254
- for (let t in e) {
255
- let { source: n, target: r, event: i, delay: a, id: o } = e[t];
256
- l.schedule(n, r, i, a, o);
257
- }
258
- },
259
- _clock: s,
260
- _logger: c
261
- };
262
- return u;
263
- }
264
- var m = !1, h = /*#__PURE__*/ function(e) {
265
- return e[e.NotStarted = 0] = "NotStarted", e[e.Running = 1] = "Running", e[e.Stopped = 2] = "Stopped", e;
266
- }({}), g = {
267
- clock: {
268
- setTimeout: (e, t) => setTimeout(e, t),
269
- clearTimeout: (e) => clearTimeout(e)
270
- },
271
- logger: console.log.bind(console),
272
- devTools: !1
273
- }, Actor = class {
274
- constructor(e, t) {
275
- this.logic = e, this._snapshot = void 0, this.clock = void 0, this.options = void 0, this.id = void 0, this.mailbox = new Mailbox(this._process.bind(this)), this.observers = /* @__PURE__ */ new Set(), this.eventListeners = /* @__PURE__ */ new Map(), this.logger = void 0, this._processingStatus = h.NotStarted, this._parent = void 0, this._syncSnapshot = void 0, this.ref = void 0, this._actorScope = void 0, this.systemId = void 0, this.sessionId = void 0, this.system = void 0, this._doneEvent = void 0, this.src = void 0, this._deferred = [];
276
- let n = {
277
- ...g,
278
- ...t
279
- }, { clock: r, logger: i, parent: a, syncSnapshot: o, id: s, systemId: c, inspect: l } = n;
280
- this.system = a ? a.system : createSystem(this, {
281
- clock: r,
282
- logger: i
283
- }), l && !a && this.system.inspect(toObserver(l)), this.sessionId = this.system._bookId(), this.id = s ?? this.sessionId, this.logger = t?.logger ?? this.system._logger, this.clock = t?.clock ?? this.system._clock, this._parent = a, this._syncSnapshot = o, this.options = n, this.src = n.src ?? e, this.ref = this, this._actorScope = {
284
- self: this,
285
- id: this.id,
286
- sessionId: this.sessionId,
287
- logger: this.logger,
288
- defer: (e) => {
289
- this._deferred.push(e);
290
- },
291
- system: this.system,
292
- stopChild: (e) => {
293
- if (e._parent !== this) throw Error(`Cannot stop child actor ${e.id} of ${this.id} because it is not a child`);
294
- e._stop();
295
- },
296
- emit: (e) => {
297
- let t = this.eventListeners.get(e.type), n = this.eventListeners.get("*");
298
- if (!t && !n) return;
299
- let r = [...t ? t.values() : [], ...n ? n.values() : []];
300
- for (let t of r) try {
301
- t(e);
302
- } catch (e) {
303
- reportUnhandledError(e);
304
- }
305
- },
306
- actionExecutor: (e) => {
307
- let exec = () => {
308
- if (this._actorScope.system._sendInspectionEvent({
309
- type: "@xstate.action",
310
- actorRef: this,
311
- action: {
312
- type: e.type,
313
- params: e.params
314
- }
315
- }), !e.exec) return;
316
- let t = m;
317
- try {
318
- m = !0, e.exec(e.info, e.params);
319
- } finally {
320
- m = t;
321
- }
322
- };
323
- this._processingStatus === h.Running ? exec() : this._deferred.push(exec);
324
- }
325
- }, this.send = this.send.bind(this), this.system._sendInspectionEvent({
326
- type: "@xstate.actor",
327
- actorRef: this
328
- }), c && (this.systemId = c, this.system._set(c, this)), this._initState(t?.snapshot ?? t?.state), c && this._snapshot.status !== "active" && this.system._unregister(this);
329
- }
330
- _initState(e) {
331
- try {
332
- this._snapshot = e ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(e, this._actorScope) : e : this.logic.getInitialSnapshot(this._actorScope, this.options?.input);
333
- } catch (e) {
334
- this._snapshot = {
335
- status: "error",
336
- output: void 0,
337
- error: e
338
- };
339
- }
340
- }
341
- update(e, t) {
342
- this._snapshot = e;
343
- let n;
344
- for (; n = this._deferred.shift();) try {
345
- n();
346
- } catch (t) {
347
- this._deferred.length = 0, this._snapshot = {
348
- ...e,
349
- status: "error",
350
- error: t
351
- };
352
- }
353
- switch (this._snapshot.status) {
354
- case "active":
355
- for (let t of this.observers) try {
356
- t.next?.(e);
357
- } catch (e) {
358
- reportUnhandledError(e);
359
- }
360
- break;
361
- case "done":
362
- for (let t of this.observers) try {
363
- t.next?.(e);
364
- } catch (e) {
365
- reportUnhandledError(e);
366
- }
367
- this._stopProcedure(), this._complete(), this._doneEvent = createDoneActorEvent(this.id, this._snapshot.output), this._parent && this.system._relay(this, this._parent, this._doneEvent);
368
- break;
369
- case "error": this._error(this._snapshot.error);
370
- }
371
- this.system._sendInspectionEvent({
372
- type: "@xstate.snapshot",
373
- actorRef: this,
374
- event: t,
375
- snapshot: e
376
- });
377
- }
378
- subscribe(e, t, n) {
379
- let r = toObserver(e, t, n);
380
- if (this._processingStatus !== h.Stopped) this.observers.add(r);
381
- else switch (this._snapshot.status) {
382
- case "done":
383
- try {
384
- r.complete?.();
385
- } catch (e) {
386
- reportUnhandledError(e);
387
- }
388
- break;
389
- case "error": {
390
- let e = this._snapshot.error;
391
- if (!r.error) reportUnhandledError(e);
392
- else try {
393
- r.error(e);
394
- } catch (e) {
395
- reportUnhandledError(e);
396
- }
397
- break;
398
- }
399
- }
400
- return { unsubscribe: () => {
401
- this.observers.delete(r);
402
- } };
403
- }
404
- on(e, t) {
405
- let n = this.eventListeners.get(e);
406
- n || (n = /* @__PURE__ */ new Set(), this.eventListeners.set(e, n));
407
- let r = t.bind(void 0);
408
- return n.add(r), { unsubscribe: () => {
409
- n.delete(r);
410
- } };
411
- }
412
- select(e, t = Object.is) {
413
- return {
414
- subscribe: (n) => {
415
- let r = toObserver(n), i = e(this.getSnapshot());
416
- return this.subscribe((n) => {
417
- let a = e(n);
418
- t(i, a) || (i = a, r.next?.(a));
419
- });
420
- },
421
- get: () => e(this.getSnapshot())
422
- };
423
- }
424
- start() {
425
- if (this._processingStatus === h.Running) return this;
426
- this._syncSnapshot && this.subscribe({
427
- next: (e) => {
428
- e.status === "active" && this.system._relay(this, this._parent, {
429
- type: `xstate.snapshot.${this.id}`,
430
- snapshot: e
431
- });
432
- },
433
- error: () => {}
434
- }), this.system._register(this.sessionId, this), this.systemId && this.system._set(this.systemId, this), this._processingStatus = h.Running;
435
- let e = createInitEvent(this.options.input);
436
- switch (this.system._sendInspectionEvent({
437
- type: "@xstate.event",
438
- sourceRef: this._parent,
439
- actorRef: this,
440
- event: e
441
- }), this._snapshot.status) {
442
- case "done": return this.update(this._snapshot, e), this;
443
- case "error": return this._error(this._snapshot.error), this;
444
- }
445
- if (this._parent || this.system.start(), this.logic.start) try {
446
- this.logic.start(this._snapshot, this._actorScope);
447
- } catch (e) {
448
- return this._snapshot = {
449
- ...this._snapshot,
450
- status: "error",
451
- error: e
452
- }, this._error(e), this;
453
- }
454
- return this.update(this._snapshot, e), this.options.devTools && this.attachDevTools(), this.mailbox.start(), this;
455
- }
456
- _process(e) {
457
- let t, n;
458
- try {
459
- t = this.logic.transition(this._snapshot, e, this._actorScope);
460
- } catch (e) {
461
- n = { err: e };
462
- }
463
- if (n) {
464
- let { err: e } = n;
465
- this._snapshot = {
466
- ...this._snapshot,
467
- status: "error",
468
- error: e
469
- }, this._error(e);
470
- return;
471
- }
472
- this.update(t, e), e.type === "xstate.stop" && (this._stopProcedure(), this._complete());
473
- }
474
- _stop() {
475
- return this._processingStatus === h.Stopped ? this : (this.mailbox.clear(), this._processingStatus === h.NotStarted ? (this._processingStatus = h.Stopped, this) : (this.mailbox.enqueue({ type: d }), this));
476
- }
477
- stop() {
478
- if (this._parent) throw Error("A non-root actor cannot be stopped directly.");
479
- return this._stop();
480
- }
481
- _complete() {
482
- for (let e of this.observers) try {
483
- e.complete?.();
484
- } catch (e) {
485
- reportUnhandledError(e);
486
- }
487
- this.observers.clear(), this.eventListeners.clear();
488
- }
489
- _reportError(e) {
490
- if (!this.observers.size) {
491
- this._parent || reportUnhandledError(e), this.eventListeners.clear();
492
- return;
493
- }
494
- let t = !1;
495
- for (let n of this.observers) {
496
- let r = n.error;
497
- t ||= !r;
498
- try {
499
- r?.(e);
500
- } catch (e) {
501
- reportUnhandledError(e);
502
- }
503
- }
504
- this.observers.clear(), this.eventListeners.clear(), t && reportUnhandledError(e);
505
- }
506
- _error(e) {
507
- this._stopProcedure(), this._reportError(e), this._parent && this.system._relay(this, this._parent, createErrorActorEvent(this.id, e));
508
- }
509
- _stopProcedure() {
510
- return this._processingStatus === h.Running ? (this.system.scheduler.cancelAll(this), this.mailbox.clear(), this.mailbox = new Mailbox(this._process.bind(this)), this._processingStatus = h.Stopped, this.system._unregister(this), this) : this;
511
- }
512
- _send(e) {
513
- this._processingStatus !== h.Stopped && this.mailbox.enqueue(e);
514
- }
515
- send(e) {
516
- this.system._relay(void 0, this, e);
517
- }
518
- attachDevTools() {
519
- let { devTools: e } = this.options;
520
- e && (typeof e == "function" ? e : devToolsAdapter)(this);
521
- }
522
- toJSON() {
523
- return {
524
- xstate$$type: 1,
525
- id: this.id
526
- };
527
- }
528
- getPersistedSnapshot(e) {
529
- return this.logic.getPersistedSnapshot(this._snapshot, e);
530
- }
531
- [f]() {
532
- return this;
533
- }
534
- getSnapshot() {
535
- return this._snapshot;
536
- }
537
- };
538
- function createActor(e, ...[t]) {
539
- return new Actor(e, t);
540
- }
541
- function resolveCancel(e, t, n, r, { sendId: i }) {
542
- return [
543
- t,
544
- { sendId: typeof i == "function" ? i(n, r) : i },
545
- void 0
546
- ];
547
- }
548
- function executeCancel(e, t) {
549
- e.defer(() => {
550
- e.system.scheduler.cancel(e.self, t.sendId);
551
- });
552
- }
553
- function cancel(e) {
554
- function cancel(e, t) {}
555
- return cancel.type = "xstate.cancel", cancel.sendId = e, cancel.resolve = resolveCancel, cancel.execute = executeCancel, cancel;
556
- }
557
- function resolveSpawn(e, t, n, r, { id: i, systemId: a, src: o, input: s, syncSnapshot: c }) {
558
- let l = typeof o == "string" ? resolveReferencedActor(t.machine, o) : o, u = typeof i == "function" ? i(n) : i, d, f;
559
- return l && (f = typeof s == "function" ? s({
560
- context: t.context,
561
- event: n.event,
562
- self: e.self
563
- }) : s, d = createActor(l, {
564
- id: u,
565
- src: o,
566
- parent: e.self,
567
- syncSnapshot: c,
568
- systemId: a,
569
- input: f
570
- })), [
571
- cloneMachineSnapshot(t, { children: {
572
- ...t.children,
573
- [u]: d
574
- } }),
575
- {
576
- id: i,
577
- systemId: a,
578
- actorRef: d,
579
- src: o,
580
- input: f
581
- },
582
- void 0
583
- ];
584
- }
585
- function executeSpawn(e, { actorRef: t }) {
586
- t && e.defer(() => {
587
- t._processingStatus !== h.Stopped && t.start();
588
- });
589
- }
590
- function spawnChild(...[e, { id: t, systemId: n, input: r, syncSnapshot: i = !1 } = {}]) {
591
- function spawnChild(e, t) {}
592
- return spawnChild.type = "xstate.spawnChild", spawnChild.id = t, spawnChild.systemId = n, spawnChild.src = e, spawnChild.input = r, spawnChild.syncSnapshot = i, spawnChild.resolve = resolveSpawn, spawnChild.execute = executeSpawn, spawnChild;
593
- }
594
- function resolveStop(e, t, n, r, { actorRef: i }) {
595
- let a = typeof i == "function" ? i(n, r) : i, o = typeof a == "string" ? t.children[a] : a, s = t.children;
596
- return o && (s = { ...s }, delete s[o.id]), [
597
- cloneMachineSnapshot(t, { children: s }),
598
- o,
599
- void 0
600
- ];
601
- }
602
- function unregisterRecursively(e, t) {
603
- let n = t.getSnapshot();
604
- if (n && "children" in n) for (let t of Object.values(n.children)) unregisterRecursively(e, t);
605
- e.system._unregister(t);
606
- }
607
- function executeStop(e, t) {
608
- if (t) {
609
- if (unregisterRecursively(e, t), t._processingStatus !== h.Running) {
610
- e.stopChild(t);
611
- return;
612
- }
613
- e.defer(() => {
614
- e.stopChild(t);
615
- });
616
- }
617
- }
618
- function stopChild(e) {
619
- function stop(e, t) {}
620
- return stop.type = "xstate.stopChild", stop.actorRef = e, stop.resolve = resolveStop, stop.execute = executeStop, stop;
621
- }
622
- function checkNot(e, { context: t, event: n }, { guards: r }) {
623
- return !evaluateGuard(r[0], t, n, e);
624
- }
625
- function not(e) {
626
- function not(e, t) {
627
- return !1;
628
- }
629
- return not.check = checkNot, not.guards = [e], not;
630
- }
631
- function checkAnd(e, { context: t, event: n }, { guards: r }) {
632
- return r.every((r) => evaluateGuard(r, t, n, e));
633
- }
634
- function and(e) {
635
- function and(e, t) {
636
- return !1;
637
- }
638
- return and.check = checkAnd, and.guards = e, and;
639
- }
640
- function checkOr(e, { context: t, event: n }, { guards: r }) {
641
- return r.some((r) => evaluateGuard(r, t, n, e));
642
- }
643
- function or(e) {
644
- function or(e, t) {
645
- return !1;
646
- }
647
- return or.check = checkOr, or.guards = e, or;
648
- }
649
- function evaluateGuard(e, t, n, r) {
650
- let { machine: i } = r, a = typeof e == "function", o = a ? e : i.implementations.guards[typeof e == "string" ? e : e.type];
651
- if (!a && !o) throw Error(`Guard '${typeof e == "string" ? e : e.type}' is not implemented.'.`);
652
- if (typeof o != "function") return evaluateGuard(o, t, n, r);
653
- let s = {
654
- context: t,
655
- event: n
656
- }, c = a || typeof e == "string" ? void 0 : "params" in e ? typeof e.params == "function" ? e.params({
657
- context: t,
658
- event: n
659
- }) : e.params : void 0;
660
- return "check" in o ? o.check(r, s, o) : o(s, c);
661
- }
662
- function isAtomicStateNode(e) {
663
- return e.type === "atomic" || e.type === "final";
664
- }
665
- function getChildren(e) {
666
- return Object.values(e.states).filter((e) => e.type !== "history");
667
- }
668
- function getProperAncestors(e, t) {
669
- let n = [];
670
- if (t === e) return n;
671
- let r = e.parent;
672
- for (; r && r !== t;) n.push(r), r = r.parent;
673
- return n;
674
- }
675
- function getAllStateNodes(e) {
676
- let t = new Set(e), n = getAdjList(t);
677
- for (let e of t) if (e.type === "compound" && (!n.get(e) || !n.get(e).length)) getInitialStateNodesWithTheirAncestors(e).forEach((e) => t.add(e));
678
- else if (e.type === "parallel") {
679
- for (let n of getChildren(e)) if (n.type !== "history" && !t.has(n)) {
680
- let e = getInitialStateNodesWithTheirAncestors(n);
681
- for (let n of e) t.add(n);
682
- }
683
- }
684
- for (let e of t) {
685
- let n = e.parent;
686
- for (; n;) t.add(n), n = n.parent;
687
- }
688
- return t;
689
- }
690
- function getValueFromAdj(e, t) {
691
- let n = t.get(e);
692
- if (!n) return {};
693
- if (e.type === "compound") {
694
- let e = n[0];
695
- if (e) {
696
- if (isAtomicStateNode(e)) return e.key;
697
- } else return {};
698
- }
699
- let r = {};
700
- for (let e of n) r[e.key] = getValueFromAdj(e, t);
701
- return r;
702
- }
703
- function getAdjList(e) {
704
- let t = /* @__PURE__ */ new Map();
705
- for (let n of e) t.has(n) || t.set(n, []), n.parent && (t.has(n.parent) || t.set(n.parent, []), t.get(n.parent).push(n));
706
- return t;
707
- }
708
- function getStateValue(e, t) {
709
- return getValueFromAdj(e, getAdjList(getAllStateNodes(t)));
710
- }
711
- function isInFinalState(e, t) {
712
- return t.type === "compound" ? getChildren(t).some((t) => t.type === "final" && e.has(t)) : t.type === "parallel" ? getChildren(t).every((t) => isInFinalState(e, t)) : t.type === "final";
713
- }
714
- var isStateId = (e) => e[0] === c;
715
- function getCandidates(e, t) {
716
- let n = e.transitions.get(t), r = [...e.transitions.keys()].filter((e) => e !== t && matchesEventDescriptor(t, e)).sort((e, t) => t.length - e.length).flatMap((t) => e.transitions.get(t));
717
- return n ? [...n, ...r] : r;
718
- }
719
- function getDelayedTransitions(e) {
720
- let t = e.config.after;
721
- if (!t) return [];
722
- let mutateEntryExit = (t) => {
723
- let n = createAfterEvent(t, e.id), r = n.type;
724
- return e.entry.push(raise(n, {
725
- id: r,
726
- delay: t
727
- })), e.exit.push(cancel(r)), r;
728
- };
729
- return Object.keys(t).flatMap((e) => {
730
- let n = t[e], r = typeof n == "string" ? { target: n } : n, i = Number.isNaN(+e) ? e : +e, a = mutateEntryExit(i);
731
- return toArray(r).map((e) => ({
732
- ...e,
733
- event: a,
734
- delay: i
735
- }));
736
- }).map((t) => {
737
- let { delay: n } = t;
738
- return {
739
- ...formatTransition(e, t.event, t),
740
- delay: n
741
- };
742
- });
743
- }
744
- function formatTransition(e, t, n) {
745
- let r = normalizeTarget(n.target), i = n.reenter ?? !1, a = resolveTarget(e, r), o = {
746
- ...n,
747
- actions: toArray(n.actions),
748
- guard: n.guard,
749
- target: a,
750
- source: e,
751
- reenter: i,
752
- eventType: t,
753
- toJSON: () => ({
754
- ...o,
755
- source: `#${e.id}`,
756
- target: a ? a.map((e) => `#${e.id}`) : void 0
757
- })
758
- };
759
- return o;
760
- }
761
- function formatTransitions(e) {
762
- let t = /* @__PURE__ */ new Map();
763
- if (e.config.on) for (let n of Object.keys(e.config.on)) {
764
- if (n === "") throw Error("Null events (\"\") cannot be specified as a transition key. Use `always: { ... }` instead.");
765
- let r = e.config.on[n];
766
- t.set(n, toTransitionConfigArray(r).map((t) => formatTransition(e, n, t)));
767
- }
768
- if (e.config.onDone) {
769
- let n = `xstate.done.state.${e.id}`;
770
- t.set(n, toTransitionConfigArray(e.config.onDone).map((t) => formatTransition(e, n, t)));
771
- }
772
- for (let n of e.invoke) {
773
- if (n.onDone) {
774
- let r = `xstate.done.actor.${n.id}`;
775
- t.set(r, toTransitionConfigArray(n.onDone).map((t) => formatTransition(e, r, t)));
776
- }
777
- if (n.onError) {
778
- let r = `xstate.error.actor.${n.id}`;
779
- t.set(r, toTransitionConfigArray(n.onError).map((t) => formatTransition(e, r, t)));
780
- }
781
- if (n.onSnapshot) {
782
- let r = `xstate.snapshot.${n.id}`;
783
- t.set(r, toTransitionConfigArray(n.onSnapshot).map((t) => formatTransition(e, r, t)));
784
- }
785
- }
786
- for (let n of e.after) {
787
- let e = t.get(n.eventType);
788
- e || (e = [], t.set(n.eventType, e)), e.push(n);
789
- }
790
- return t;
791
- }
792
- function formatRouteTransitions(e) {
793
- let t = [], collectRoutes = (n) => {
794
- Object.values(n).forEach((n) => {
795
- if (n.config.route && n.config.id) {
796
- let r = n.config.id, i = n.config.route.guard, routeMatches = ({ event: e }) => e.to === `#${r}`, a = {
797
- ...n.config.route,
798
- guard: i ? and([routeMatches, i]) : routeMatches,
799
- target: `#${r}`
800
- };
801
- t.push(formatTransition(e, "xstate.route", a));
802
- }
803
- n.states && collectRoutes(n.states);
804
- });
805
- };
806
- collectRoutes(e.states), t.length > 0 && e.transitions.set("xstate.route", t);
807
- }
808
- function formatInitialTransition(e, t) {
809
- let n = typeof t == "string" ? e.states[t] : t ? e.states[t.target] : void 0;
810
- if (!n && t) throw Error(`Initial state node "${t}" not found on parent state node #${e.id}`);
811
- let r = {
812
- source: e,
813
- actions: !t || typeof t == "string" ? [] : toArray(t.actions),
814
- eventType: null,
815
- reenter: !1,
816
- target: n ? [n] : [],
817
- toJSON: () => ({
818
- ...r,
819
- source: `#${e.id}`,
820
- target: n ? [`#${n.id}`] : []
821
- })
822
- };
823
- return r;
824
- }
825
- function resolveTarget(e, t) {
826
- if (t !== void 0) return t.map((t) => {
827
- if (typeof t != "string") return t;
828
- if (isStateId(t)) return e.machine.getStateNodeById(t);
829
- let n = t[0] === ".";
830
- if (n && !e.parent) return getStateNodeByPath(e, t.slice(1));
831
- let r = n ? e.key + t : t;
832
- if (e.parent) try {
833
- return getStateNodeByPath(e.parent, r);
834
- } catch (t) {
835
- throw Error(`Invalid transition definition for state node '${e.id}':\n${t.message}`);
836
- }
837
- throw Error(`Invalid target: "${t}" is not a valid target from the root node. Did you mean ".${t}"?`);
838
- });
839
- }
840
- function resolveHistoryDefaultTransition(e) {
841
- let t = normalizeTarget(e.config.target);
842
- return t ? { target: t.map((t) => typeof t == "string" ? getStateNodeByPath(e.parent, t) : t) } : e.parent.type === "parallel" ? { target: [e.parent] } : e.parent.initial;
843
- }
844
- function isHistoryNode(e) {
845
- return e.type === "history";
846
- }
847
- function getInitialStateNodesWithTheirAncestors(e) {
848
- let t = getInitialStateNodes(e);
849
- for (let n of t) for (let r of getProperAncestors(n, e)) t.add(r);
850
- return t;
851
- }
852
- function getInitialStateNodes(e) {
853
- let t = /* @__PURE__ */ new Set();
854
- function iter(e) {
855
- if (!t.has(e)) {
856
- if (t.add(e), e.type === "compound") iter(e.initial.target[0]);
857
- else if (e.type === "parallel") for (let t of getChildren(e)) iter(t);
858
- }
859
- }
860
- return iter(e), t;
861
- }
862
- function getStateNode(e, t) {
863
- if (isStateId(t)) return e.machine.getStateNodeById(t);
864
- if (!e.states) throw Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);
865
- let n = e.states[t];
866
- if (!n) throw Error(`Child state '${t}' does not exist on '${e.id}'`);
867
- return n;
868
- }
869
- function getStateNodeByPath(e, t) {
870
- if (typeof t == "string" && isStateId(t)) try {
871
- return e.machine.getStateNodeById(t);
872
- } catch {}
873
- let n = toStatePath(t).slice(), r = e;
874
- for (; n.length;) {
875
- let e = n.shift();
876
- if (!e.length) break;
877
- r = getStateNode(r, e);
878
- }
879
- return r;
880
- }
881
- function getStateNodes(e, t) {
882
- if (typeof t == "string") {
883
- let n = e.states[t];
884
- if (!n) throw Error(`State '${t}' does not exist on '${e.id}'`);
885
- return [e, n];
886
- }
887
- let n = Object.keys(t), r = n.map((t) => getStateNode(e, t)).filter(Boolean);
888
- return [e.machine.root, e].concat(r, n.reduce((n, r) => {
889
- let i = getStateNode(e, r);
890
- if (!i) return n;
891
- let a = getStateNodes(i, t[r]);
892
- return n.concat(a);
893
- }, []));
894
- }
895
- function transitionAtomicNode(e, t, n, r) {
896
- let i = getStateNode(e, t).next(n, r);
897
- return !i || !i.length ? e.next(n, r) : i;
898
- }
899
- function transitionCompoundNode(e, t, n, r) {
900
- let i = Object.keys(t), a = transitionNode(getStateNode(e, i[0]), t[i[0]], n, r);
901
- return !a || !a.length ? e.next(n, r) : a;
902
- }
903
- function transitionParallelNode(e, t, n, r) {
904
- let i = [];
905
- for (let a of Object.keys(t)) {
906
- let o = t[a];
907
- if (!o) continue;
908
- let s = transitionNode(getStateNode(e, a), o, n, r);
909
- s && i.push(...s);
910
- }
911
- return i.length ? i : e.next(n, r);
912
- }
913
- function transitionNode(e, t, n, r) {
914
- return typeof t == "string" ? transitionAtomicNode(e, t, n, r) : Object.keys(t).length === 1 ? transitionCompoundNode(e, t, n, r) : transitionParallelNode(e, t, n, r);
915
- }
916
- function getHistoryNodes(e) {
917
- return Object.keys(e.states).map((t) => e.states[t]).filter((e) => e.type === "history");
918
- }
919
- function isDescendant(e, t) {
920
- let n = e;
921
- for (; n.parent && n.parent !== t;) n = n.parent;
922
- return n.parent === t;
923
- }
924
- function hasIntersection(e, t) {
925
- let n = new Set(e), r = new Set(t);
926
- for (let e of n) if (r.has(e)) return !0;
927
- for (let e of r) if (n.has(e)) return !0;
928
- return !1;
929
- }
930
- function removeConflictingTransitions(e, t, n) {
931
- let r = /* @__PURE__ */ new Set();
932
- for (let i of e) {
933
- let e = !1, a = /* @__PURE__ */ new Set();
934
- for (let o of r) if (hasIntersection(computeExitSet([i], t, n), computeExitSet([o], t, n))) {
935
- if (isDescendant(i.source, o.source)) a.add(o);
936
- else {
937
- e = !0;
938
- break;
939
- }
940
- }
941
- if (!e) {
942
- for (let e of a) r.delete(e);
943
- r.add(i);
944
- }
945
- }
946
- return Array.from(r);
947
- }
948
- function findLeastCommonAncestor(e) {
949
- let [t, ...n] = e;
950
- for (let e of getProperAncestors(t, void 0)) if (n.every((t) => isDescendant(t, e))) return e;
951
- }
952
- function getEffectiveTargetStates(e, t) {
953
- if (!e.target) return [];
954
- let n = /* @__PURE__ */ new Set();
955
- for (let r of e.target) if (isHistoryNode(r)) {
956
- if (t[r.id]) for (let e of t[r.id]) n.add(e);
957
- else for (let e of getEffectiveTargetStates(resolveHistoryDefaultTransition(r), t)) n.add(e);
958
- } else n.add(r);
959
- return [...n];
960
- }
961
- function getTransitionDomain(e, t) {
962
- let n = getEffectiveTargetStates(e, t);
963
- if (!n) return;
964
- if (!e.reenter && n.every((t) => t === e.source || isDescendant(t, e.source))) return e.source;
965
- let r = findLeastCommonAncestor(n.concat(e.source));
966
- if (r) return r;
967
- if (!e.reenter) return e.source.machine.root;
968
- }
969
- function computeExitSet(e, t, n) {
970
- let r = /* @__PURE__ */ new Set();
971
- for (let i of e) if (i.target?.length) {
972
- let e = getTransitionDomain(i, n);
973
- i.reenter && i.source === e && r.add(e);
974
- for (let n of t) isDescendant(n, e) && r.add(n);
975
- }
976
- return [...r];
977
- }
978
- function areStateNodeCollectionsEqual(e, t) {
979
- if (e.length !== t.size) return !1;
980
- for (let n of e) if (!t.has(n)) return !1;
981
- return !0;
982
- }
983
- function initialMicrostep(e, t, n, r, i) {
984
- return microstep([{
985
- target: [...getInitialStateNodes(e)],
986
- source: e,
987
- reenter: !0,
988
- actions: [],
989
- eventType: null,
990
- toJSON: null
991
- }], t, n, r, !0, i);
992
- }
993
- function microstep(e, t, n, r, i, a) {
994
- let o = [];
995
- if (!e.length) return [t, o];
996
- let s = n.actionExecutor;
997
- n.actionExecutor = (e) => {
998
- o.push(e), s(e);
999
- };
1000
- try {
1001
- let s = new Set(t._nodes), c = t.historyValue, l = removeConflictingTransitions(e, s, c), u = t;
1002
- i || ([u, c] = exitStates(u, r, n, l, s, c, a, n.actionExecutor)), u = resolveActionsAndContext(u, r, n, l.flatMap((e) => e.actions), a, void 0), u = enterStates(u, r, n, l, s, a, c, i);
1003
- let d = [...s];
1004
- u.status === "done" && (u = resolveActionsAndContext(u, r, n, d.sort((e, t) => t.order - e.order).flatMap((e) => e.exit), a, void 0));
1005
- try {
1006
- return c === t.historyValue && areStateNodeCollectionsEqual(t._nodes, s) ? [u, o] : [cloneMachineSnapshot(u, {
1007
- _nodes: d,
1008
- historyValue: c
1009
- }), o];
1010
- } catch (e) {
1011
- throw e;
1012
- }
1013
- } finally {
1014
- n.actionExecutor = s;
1015
- }
1016
- }
1017
- function getMachineOutput(e, t, n, r, i) {
1018
- if (r.output === void 0) return;
1019
- let a = createDoneStateEvent(i.id, i.output !== void 0 && i.parent ? resolveOutput(i.output, e.context, t, n.self) : void 0);
1020
- return resolveOutput(r.output, e.context, a, n.self);
1021
- }
1022
- function enterStates(e, t, n, r, i, a, o, s) {
1023
- let c = e, l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
1024
- computeEntrySet(r, o, u, l), s && u.add(e.machine.root);
1025
- let d = /* @__PURE__ */ new Set();
1026
- for (let e of [...l].sort((e, t) => e.order - t.order)) {
1027
- i.add(e);
1028
- let r = [];
1029
- r.push(...e.entry);
1030
- for (let t of e.invoke) r.push(spawnChild(t.src, {
1031
- ...t,
1032
- syncSnapshot: !!t.onSnapshot
1033
- }));
1034
- if (u.has(e)) {
1035
- let t = e.initial.actions;
1036
- r.push(...t);
1037
- }
1038
- if (c = resolveActionsAndContext(c, t, n, r, a, e.invoke.map((e) => e.id)), e.type === "final") {
1039
- let r = e.parent, o = r?.type === "parallel" ? r : r?.parent, s = o || e;
1040
- for (r?.type === "compound" && a.push(createDoneStateEvent(r.id, e.output === void 0 ? void 0 : resolveOutput(e.output, c.context, t, n.self))); o?.type === "parallel" && !d.has(o) && isInFinalState(i, o);) d.add(o), a.push(createDoneStateEvent(o.id)), s = o, o = o.parent;
1041
- if (o) continue;
1042
- c = cloneMachineSnapshot(c, {
1043
- status: "done",
1044
- output: getMachineOutput(c, t, n, c.machine.root, s)
1045
- });
1046
- }
1047
- }
1048
- return c;
1049
- }
1050
- function computeEntrySet(e, t, n, r) {
1051
- for (let i of e) {
1052
- let e = getTransitionDomain(i, t);
1053
- for (let a of i.target || []) !isHistoryNode(a) && (i.source !== a || i.source !== e || i.reenter) && (r.add(a), n.add(a)), addDescendantStatesToEnter(a, t, n, r);
1054
- let a = getEffectiveTargetStates(i, t);
1055
- for (let o of a) {
1056
- let a = getProperAncestors(o, e);
1057
- e?.type === "parallel" && a.push(e), addAncestorStatesToEnter(r, t, n, a, !i.source.parent && i.reenter ? void 0 : e);
1058
- }
1059
- }
1060
- }
1061
- function addDescendantStatesToEnter(e, t, n, r) {
1062
- if (isHistoryNode(e)) {
1063
- if (t[e.id]) {
1064
- let i = t[e.id];
1065
- for (let e of i) r.add(e), addDescendantStatesToEnter(e, t, n, r);
1066
- for (let a of i) addProperAncestorStatesToEnter(a, e.parent, r, t, n);
1067
- } else {
1068
- let i = resolveHistoryDefaultTransition(e);
1069
- for (let a of i.target) r.add(a), i === e.parent?.initial && n.add(e.parent), addDescendantStatesToEnter(a, t, n, r);
1070
- for (let a of i.target) addProperAncestorStatesToEnter(a, e.parent, r, t, n);
1071
- }
1072
- } else if (e.type === "compound") {
1073
- let [i] = e.initial.target;
1074
- isHistoryNode(i) || (r.add(i), n.add(i)), addDescendantStatesToEnter(i, t, n, r), addProperAncestorStatesToEnter(i, e, r, t, n);
1075
- } else if (e.type === "parallel") for (let i of getChildren(e).filter((e) => !isHistoryNode(e))) [...r].some((e) => isDescendant(e, i)) || (isHistoryNode(i) || (r.add(i), n.add(i)), addDescendantStatesToEnter(i, t, n, r));
1076
- }
1077
- function addAncestorStatesToEnter(e, t, n, r, i) {
1078
- for (let a of r) if ((!i || isDescendant(a, i)) && e.add(a), a.type === "parallel") for (let r of getChildren(a).filter((e) => !isHistoryNode(e))) [...e].some((e) => isDescendant(e, r)) || (e.add(r), addDescendantStatesToEnter(r, t, n, e));
1079
- }
1080
- function addProperAncestorStatesToEnter(e, t, n, r, i) {
1081
- addAncestorStatesToEnter(n, r, i, getProperAncestors(e, t));
1082
- }
1083
- function exitStates(e, t, n, r, i, a, o, s) {
1084
- let c = e, l = computeExitSet(r, i, a);
1085
- l.sort((e, t) => t.order - e.order);
1086
- let u;
1087
- for (let e of l) for (let t of getHistoryNodes(e)) {
1088
- let n;
1089
- n = t.history === "deep" ? (t) => isAtomicStateNode(t) && isDescendant(t, e) : (t) => t.parent === e, u ??= { ...a }, u[t.id] = Array.from(i).filter(n);
1090
- }
1091
- for (let e of l) c = resolveActionsAndContext(c, t, n, [...e.exit, ...e.invoke.map((e) => stopChild(e.id))], o, void 0), i.delete(e);
1092
- return [c, u || a];
1093
- }
1094
- function getAction(e, t) {
1095
- return e.implementations.actions[t];
1096
- }
1097
- function resolveAndExecuteActionsWithContext(e, t, n, r, i, a) {
1098
- let { machine: o } = e, s = e;
1099
- for (let e of r) {
1100
- let r = typeof e == "function", c = r ? e : getAction(o, typeof e == "string" ? e : e.type), l = {
1101
- context: s.context,
1102
- event: t,
1103
- self: n.self,
1104
- system: n.system
1105
- }, u = r || typeof e == "string" ? void 0 : "params" in e ? typeof e.params == "function" ? e.params({
1106
- context: s.context,
1107
- event: t
1108
- }) : e.params : void 0;
1109
- if (!c || !("resolve" in c)) {
1110
- n.actionExecutor({
1111
- type: typeof e == "string" ? e : typeof e == "object" ? e.type : e.name || "(anonymous)",
1112
- info: l,
1113
- params: u,
1114
- exec: c
1115
- });
1116
- continue;
1117
- }
1118
- let d = c, [f, p, m] = d.resolve(n, s, l, u, c, i);
1119
- s = f, "retryResolve" in d && a?.push([d, p]), "execute" in d && n.actionExecutor({
1120
- type: d.type,
1121
- info: l,
1122
- params: p,
1123
- exec: d.execute.bind(null, n, p)
1124
- }), m && (s = resolveAndExecuteActionsWithContext(s, t, n, m, i, a));
1125
- }
1126
- return s;
1127
- }
1128
- function resolveActionsAndContext(e, t, n, r, i, a) {
1129
- let o = a ? [] : void 0, s = resolveAndExecuteActionsWithContext(e, t, n, r, {
1130
- internalQueue: i,
1131
- deferredActorIds: a
1132
- }, o);
1133
- return o?.forEach(([e, t]) => {
1134
- e.retryResolve(n, s, t);
1135
- }), s;
1136
- }
1137
- function macrostep(e, t, n, r) {
1138
- let i = e, a = [];
1139
- function addMicrostep(e, t, r) {
1140
- n.system._sendInspectionEvent({
1141
- type: "@xstate.microstep",
1142
- actorRef: n.self,
1143
- event: t,
1144
- snapshot: e[0],
1145
- _transitions: r
1146
- }), a.push(e);
1147
- }
1148
- if (t.type === "xstate.stop") return i = cloneMachineSnapshot(stopChildren(i, t, n), { status: "stopped" }), addMicrostep([i, []], t, []), {
1149
- snapshot: i,
1150
- microsteps: a
1151
- };
1152
- let o = t;
1153
- if (o.type !== u) {
1154
- let t = o, s = isErrorActorEvent(t), c = selectTransitions(t, i);
1155
- if (s && !c.length) return i = cloneMachineSnapshot(e, {
1156
- status: "error",
1157
- error: t.error
1158
- }), addMicrostep([i, []], t, []), {
1159
- snapshot: i,
1160
- microsteps: a
1161
- };
1162
- let l = microstep(c, e, n, o, !1, r);
1163
- i = l[0], addMicrostep(l, t, c);
1164
- }
1165
- let s = !0, c = e.machine.options?.maxIterations ?? Infinity, l = 0;
1166
- for (; i.status === "active";) {
1167
- if (l++, l > c) throw Error(`Infinite loop detected: the machine has processed more than ${c} microsteps without reaching a stable state. This usually happens when there's a cycle of transitions (e.g., eventless transitions or raised events causing state A -> B -> C -> A).`);
1168
- let e = s ? selectEventlessTransitions(i, o) : [], t = e.length ? i : void 0;
1169
- if (!e.length) {
1170
- if (!r.length) break;
1171
- o = r.shift(), e = selectTransitions(o, i);
1172
- }
1173
- let a = microstep(e, i, n, o, !1, r);
1174
- i = a[0], s = i !== t, addMicrostep(a, o, e);
1175
- }
1176
- return i.status !== "active" && stopChildren(i, o, n), {
1177
- snapshot: i,
1178
- microsteps: a
1179
- };
1180
- }
1181
- function stopChildren(e, t, n) {
1182
- return resolveActionsAndContext(e, t, n, Object.values(e.children).map((e) => stopChild(e)), [], void 0);
1183
- }
1184
- function selectTransitions(e, t) {
1185
- return t.machine.getTransitionData(t, e);
1186
- }
1187
- function selectEventlessTransitions(e, t) {
1188
- let n = /* @__PURE__ */ new Set(), r = e._nodes.filter(isAtomicStateNode);
1189
- for (let i of r) loop: for (let r of [i].concat(getProperAncestors(i, void 0))) if (r.always) {
1190
- for (let i of r.always) if (i.guard === void 0 || evaluateGuard(i.guard, e.context, t, e)) {
1191
- n.add(i);
1192
- break loop;
1193
- }
1194
- }
1195
- return removeConflictingTransitions(Array.from(n), new Set(e._nodes), e.historyValue);
1196
- }
1197
- function resolveStateValue(e, t) {
1198
- return getStateValue(e, [...getAllStateNodes(getStateNodes(e, t))]);
1199
- }
1200
- function isMachineSnapshot(e) {
1201
- return !!e && typeof e == "object" && "machine" in e && "value" in e;
1202
- }
1203
- var _ = function matches(e) {
1204
- return matchesState(e, this.value);
1205
- }, v = function hasTag(e) {
1206
- return this.tags.has(e);
1207
- }, y = function can(e) {
1208
- let t = this.machine.getTransitionData(this, e);
1209
- return !!t?.length && t.some((e) => e.target !== void 0 || e.actions.length);
1210
- }, b = function toJSON() {
1211
- let { _nodes: e, tags: t, machine: n, getMeta: r, toJSON: i, can: a, hasTag: o, matches: s, ...c } = this;
1212
- return {
1213
- ...c,
1214
- tags: Array.from(t)
1215
- };
1216
- }, x = function getMeta() {
1217
- return this._nodes.reduce((e, t) => (t.meta !== void 0 && (e[t.id] = t.meta), e), {});
1218
- };
1219
- function createMachineSnapshot(e, t) {
1220
- return {
1221
- status: e.status,
1222
- output: e.output,
1223
- error: e.error,
1224
- machine: t,
1225
- context: e.context,
1226
- _nodes: e._nodes,
1227
- value: getStateValue(t.root, e._nodes),
1228
- tags: new Set(e._nodes.flatMap((e) => e.tags)),
1229
- children: e.children,
1230
- historyValue: e.historyValue || {},
1231
- matches: _,
1232
- hasTag: v,
1233
- can: y,
1234
- getMeta: x,
1235
- toJSON: b
1236
- };
1237
- }
1238
- function cloneMachineSnapshot(e, t = {}) {
1239
- return createMachineSnapshot({
1240
- ...e,
1241
- ...t
1242
- }, e.machine);
1243
- }
1244
- function serializeHistoryValue(e) {
1245
- if (typeof e != "object" || !e) return {};
1246
- let t = {};
1247
- for (let n in e) {
1248
- let r = e[n];
1249
- Array.isArray(r) && (t[n] = r.map((e) => ({ id: e.id })));
1250
- }
1251
- return t;
1252
- }
1253
- function getPersistedSnapshot(e, t) {
1254
- let { _nodes: n, tags: r, machine: i, children: a, context: o, can: s, hasTag: c, matches: l, getMeta: u, toJSON: d, ...f } = e, p = {};
1255
- for (let e in a) {
1256
- let n = a[e];
1257
- p[e] = {
1258
- snapshot: n.getPersistedSnapshot(t),
1259
- src: n.src,
1260
- systemId: n.systemId,
1261
- syncSnapshot: n._syncSnapshot
1262
- };
1263
- }
1264
- return {
1265
- ...f,
1266
- context: persistContext(o),
1267
- children: p,
1268
- historyValue: serializeHistoryValue(f.historyValue)
1269
- };
1270
- }
1271
- function persistContext(e) {
1272
- let t;
1273
- for (let n in e) {
1274
- let r = e[n];
1275
- if (r && typeof r == "object") {
1276
- if ("sessionId" in r && "send" in r && "ref" in r) t ??= Array.isArray(e) ? e.slice() : { ...e }, t[n] = {
1277
- xstate$$type: 1,
1278
- id: r.id
1279
- };
1280
- else {
1281
- let i = persistContext(r);
1282
- i !== r && (t ??= Array.isArray(e) ? e.slice() : { ...e }, t[n] = i);
1283
- }
1284
- }
1285
- }
1286
- return t ?? e;
1287
- }
1288
- function resolveRaise(e, t, n, r, { event: i, id: a, delay: o }, { internalQueue: s }) {
1289
- let c = t.machine.implementations.delays;
1290
- if (typeof i == "string") throw Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);
1291
- let l = typeof i == "function" ? i(n, r) : i, u;
1292
- if (typeof o == "string") {
1293
- let e = c && c[o];
1294
- u = typeof e == "function" ? e(n, r) : e;
1295
- } else u = typeof o == "function" ? o(n, r) : o;
1296
- return typeof u != "number" && s.push(l), [
1297
- t,
1298
- {
1299
- event: l,
1300
- id: a,
1301
- delay: u
1302
- },
1303
- void 0
1304
- ];
1305
- }
1306
- function executeRaise(e, t) {
1307
- let { event: n, delay: r, id: i } = t;
1308
- if (typeof r == "number") {
1309
- e.defer(() => {
1310
- let t = e.self;
1311
- e.system.scheduler.schedule(t, t, n, r, i);
1312
- });
1313
- return;
1314
- }
1315
- }
1316
- function raise(e, t) {
1317
- function raise(e, t) {}
1318
- return raise.type = "xstate.raise", raise.event = e, raise.id = t?.id, raise.delay = t?.delay, raise.resolve = resolveRaise, raise.execute = executeRaise, raise;
1319
- }
1320
- var S = /* #__PURE__ */ new WeakMap();
1321
- function fromCallback(e) {
1322
- return {
1323
- config: e,
1324
- start: (t, n) => {
1325
- let { self: r, system: i, emit: a } = n, o = {
1326
- receivers: void 0,
1327
- dispose: void 0
1328
- };
1329
- S.set(r, o), o.dispose = e({
1330
- input: t.input,
1331
- system: i,
1332
- self: r,
1333
- sendBack: (e) => {
1334
- r.getSnapshot().status !== "stopped" && r._parent && i._relay(r, r._parent, e);
1335
- },
1336
- receive: (e) => {
1337
- o.receivers ??= /* @__PURE__ */ new Set(), o.receivers.add(e);
1338
- },
1339
- emit: a
1340
- });
1341
- },
1342
- transition: (e, t, n) => {
1343
- let r = S.get(n.self);
1344
- return t.type === "xstate.stop" ? (e = {
1345
- ...e,
1346
- status: "stopped",
1347
- error: void 0
1348
- }, S.delete(n.self), r.receivers?.clear(), r.dispose?.(), e) : (r.receivers?.forEach((e) => e(t)), e);
1349
- },
1350
- getInitialSnapshot: (e, t) => ({
1351
- status: "active",
1352
- output: void 0,
1353
- error: void 0,
1354
- input: t
1355
- }),
1356
- getPersistedSnapshot: (e) => e,
1357
- restoreSnapshot: (e) => e
1358
- };
1359
- }
1360
- var C = "xstate.promise.resolve", w = "xstate.promise.reject", T = /* @__PURE__ */ new WeakMap();
1361
- function fromPromise(e) {
1362
- return {
1363
- config: e,
1364
- transition: (e, t, n) => {
1365
- if (e.status !== "active") return e;
1366
- switch (t.type) {
1367
- case C: {
1368
- let n = t.data;
1369
- return {
1370
- ...e,
1371
- status: "done",
1372
- output: n,
1373
- input: void 0
1374
- };
1375
- }
1376
- case w: return {
1377
- ...e,
1378
- status: "error",
1379
- error: t.data,
1380
- input: void 0
1381
- };
1382
- case d: return T.get(n.self)?.abort(), T.delete(n.self), {
1383
- ...e,
1384
- status: "stopped",
1385
- input: void 0
1386
- };
1387
- default: return e;
1388
- }
1389
- },
1390
- start: (t, { self: n, system: r, emit: i }) => {
1391
- if (t.status !== "active") return;
1392
- let a = new AbortController();
1393
- T.set(n, a), Promise.resolve(e({
1394
- input: t.input,
1395
- system: r,
1396
- self: n,
1397
- signal: a.signal,
1398
- emit: i
1399
- })).then((e) => {
1400
- n.getSnapshot().status === "active" && (T.delete(n), r._relay(n, n, {
1401
- type: C,
1402
- data: e
1403
- }));
1404
- }, (e) => {
1405
- n.getSnapshot().status === "active" && (T.delete(n), r._relay(n, n, {
1406
- type: w,
1407
- data: e
1408
- }));
1409
- });
1410
- },
1411
- getInitialSnapshot: (e, t) => ({
1412
- status: "active",
1413
- output: void 0,
1414
- error: void 0,
1415
- input: t
1416
- }),
1417
- getPersistedSnapshot: (e) => e,
1418
- restoreSnapshot: (e) => e
1419
- };
1420
- }
1421
- //#endregion
1422
- //#region ../../node_modules/.pnpm/xstate@5.32.6/node_modules/xstate/dist/assign-54f9e2d3.esm.js
1423
- function createSpawner(e, { machine: t, context: n }, r, i) {
1424
- let spawn = (a, o) => {
1425
- if (typeof a == "string") {
1426
- let s = resolveReferencedActor(t, a);
1427
- if (!s) throw Error(`Actor logic '${a}' not implemented in machine '${t.id}'`);
1428
- let c = createActor(s, {
1429
- id: o?.id,
1430
- parent: e.self,
1431
- syncSnapshot: o?.syncSnapshot,
1432
- input: typeof o?.input == "function" ? o.input({
1433
- context: n,
1434
- event: r,
1435
- self: e.self
1436
- }) : o?.input,
1437
- src: a,
1438
- systemId: o?.systemId
1439
- });
1440
- return i[c.id] = c, c;
1441
- }
1442
- return createActor(a, {
1443
- id: o?.id,
1444
- parent: e.self,
1445
- syncSnapshot: o?.syncSnapshot,
1446
- input: o?.input,
1447
- src: a,
1448
- systemId: o?.systemId
1449
- });
1450
- };
1451
- return (t, n) => {
1452
- let r = spawn(t, n);
1453
- return i[r.id] = r, e.defer(() => {
1454
- r._processingStatus !== h.Stopped && r.start();
1455
- }), r;
1456
- };
1457
- }
1458
- function resolveAssign(e, t, n, r, { assignment: i }) {
1459
- if (!t.context) throw Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");
1460
- let a = {}, o = {
1461
- context: t.context,
1462
- event: n.event,
1463
- spawn: createSpawner(e, t, n.event, a),
1464
- self: e.self,
1465
- system: e.system
1466
- }, s = {};
1467
- if (typeof i == "function") s = i(o, r);
1468
- else for (let e of Object.keys(i)) {
1469
- let t = i[e];
1470
- s[e] = typeof t == "function" ? t(o, r) : t;
1471
- }
1472
- return [
1473
- cloneMachineSnapshot(t, {
1474
- context: Object.assign({}, t.context, s),
1475
- children: Object.keys(a).length ? {
1476
- ...t.children,
1477
- ...a
1478
- } : t.children
1479
- }),
1480
- void 0,
1481
- void 0
1482
- ];
1483
- }
1484
- function assign(e) {
1485
- function assign(e, t) {}
1486
- return assign.type = "xstate.assign", assign.assignment = e, assign.resolve = resolveAssign, assign;
1487
- }
1488
- //#endregion
1489
- //#region ../../node_modules/.pnpm/xstate@5.32.6/node_modules/xstate/dist/StateMachine-28a9f50e.esm.js
1490
- var E = /* @__PURE__ */ new WeakMap();
1491
- function memo$1(e, t, n) {
1492
- let r = E.get(e);
1493
- return r ? t in r || (r[t] = n()) : (r = { [t]: n() }, E.set(e, r)), r[t];
1494
- }
1495
- e(memo$1, "memo");
1496
- var D = {}, toSerializableAction = (e) => typeof e == "string" ? { type: e } : typeof e == "function" ? "resolve" in e ? { type: e.type } : { type: e.name } : e, O = class StateNode {
1497
- constructor(e, t) {
1498
- if (this.config = e, this.key = void 0, this.id = void 0, this.type = void 0, this.path = void 0, this.states = void 0, this.history = void 0, this.entry = void 0, this.exit = void 0, this.parent = void 0, this.machine = void 0, this.meta = void 0, this.output = void 0, this.order = -1, this.description = void 0, this.tags = [], this.transitions = void 0, this.always = void 0, this.parent = t._parent, this.key = t._key, this.machine = t._machine, this.path = this.parent ? this.parent.path.concat(this.key) : [], this.id = this.config.id || [this.machine.id, ...this.path].join("."), this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? "compound" : this.config.history ? "history" : "atomic"), this.description = this.config.description, this.order = this.machine.idMap.size, this.machine.idMap.set(this.id, this), this.states = this.config.states ? mapValues(this.config.states, (e, t) => new StateNode(e, {
1499
- _parent: this,
1500
- _key: t,
1501
- _machine: this.machine
1502
- })) : D, this.type === "compound" && !this.config.initial) throw Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);
1503
- this.history = this.config.history === !0 ? "shallow" : this.config.history || !1, this.entry = toArray(this.config.entry).slice(), this.exit = toArray(this.config.exit).slice(), this.meta = this.config.meta, this.output = this.type === "final" || !this.parent ? this.config.output : void 0, this.tags = toArray(e.tags).slice();
1504
- }
1505
- _initialize() {
1506
- this.transitions = formatTransitions(this), this.config.always && (this.always = toTransitionConfigArray(this.config.always).map((e) => formatTransition(this, "", e))), Object.keys(this.states).forEach((e) => {
1507
- this.states[e]._initialize();
1508
- });
1509
- }
1510
- get definition() {
1511
- return {
1512
- id: this.id,
1513
- key: this.key,
1514
- version: this.machine.version,
1515
- type: this.type,
1516
- initial: this.initial ? {
1517
- target: this.initial.target,
1518
- source: this,
1519
- actions: this.initial.actions.map(toSerializableAction),
1520
- eventType: null,
1521
- reenter: !1,
1522
- toJSON: () => ({
1523
- target: this.initial.target.map((e) => `#${e.id}`),
1524
- source: `#${this.id}`,
1525
- actions: this.initial.actions.map(toSerializableAction),
1526
- eventType: null
1527
- })
1528
- } : void 0,
1529
- history: this.history,
1530
- states: mapValues(this.states, (e) => e.definition),
1531
- on: this.on,
1532
- transitions: [...this.transitions.values()].flat().map((e) => ({
1533
- ...e,
1534
- actions: e.actions.map(toSerializableAction)
1535
- })),
1536
- entry: this.entry.map(toSerializableAction),
1537
- exit: this.exit.map(toSerializableAction),
1538
- meta: this.meta,
1539
- order: this.order || -1,
1540
- output: this.output,
1541
- invoke: this.invoke,
1542
- description: this.description,
1543
- tags: this.tags
1544
- };
1545
- }
1546
- toJSON() {
1547
- return this.definition;
1548
- }
1549
- get invoke() {
1550
- return memo$1(this, "invoke", () => toArray(this.config.invoke).map((e, t) => {
1551
- let { src: n, systemId: r } = e, i = e.id ?? createInvokeId(this.id, t), a = typeof n == "string" ? n : `xstate.invoke.${createInvokeId(this.id, t)}`;
1552
- return {
1553
- ...e,
1554
- src: a,
1555
- id: i,
1556
- systemId: r,
1557
- toJSON() {
1558
- let { onDone: t, onError: n, ...r } = e;
1559
- return {
1560
- ...r,
1561
- type: "xstate.invoke",
1562
- src: a,
1563
- id: i
1564
- };
1565
- }
1566
- };
1567
- }));
1568
- }
1569
- get on() {
1570
- return memo$1(this, "on", () => [...this.transitions].flatMap(([e, t]) => t.map((t) => [e, t])).reduce((e, [t, n]) => (e[t] = e[t] || [], e[t].push(n), e), {}));
1571
- }
1572
- get after() {
1573
- return memo$1(this, "delayedTransitions", () => getDelayedTransitions(this));
1574
- }
1575
- get initial() {
1576
- return memo$1(this, "initial", () => formatInitialTransition(this, this.config.initial));
1577
- }
1578
- next(e, t) {
1579
- let n = t.type, r = [], i, a = memo$1(this, `candidates-${n}`, () => getCandidates(this, n));
1580
- for (let o of a) {
1581
- let { guard: a } = o, s = e.context, c = !1;
1582
- try {
1583
- c = !a || evaluateGuard(a, s, t, e);
1584
- } catch (e) {
1585
- let t = typeof a == "string" ? a : typeof a == "object" ? a.type : void 0;
1586
- throw Error(`Unable to evaluate guard ${t ? `'${t}' ` : ""}in transition for event '${n}' in state node '${this.id}':\n${e.message}`);
1587
- }
1588
- if (c) {
1589
- r.push(...o.actions), i = o;
1590
- break;
1591
- }
1592
- }
1593
- return i ? [i] : void 0;
1594
- }
1595
- get events() {
1596
- return memo$1(this, "events", () => {
1597
- let { states: e } = this, t = new Set(this.ownEvents);
1598
- if (e) for (let n of Object.keys(e)) {
1599
- let r = e[n];
1600
- if (r.states) for (let e of r.events) t.add(`${e}`);
1601
- }
1602
- return Array.from(t);
1603
- });
1604
- }
1605
- get ownEvents() {
1606
- let e = Object.keys(Object.fromEntries(this.transitions)), t = new Set(e.filter((e) => this.transitions.get(e).some((e) => !(!e.target && !e.actions.length && !e.reenter))));
1607
- return Array.from(t);
1608
- }
1609
- }, k = class StateMachine {
1610
- constructor(e, t) {
1611
- this.config = e, this.version = void 0, this.schemas = void 0, this.implementations = void 0, this.options = void 0, this.__xstatenode = !0, this.idMap = /* @__PURE__ */ new Map(), this.root = void 0, this.id = void 0, this.states = void 0, this.events = void 0, this.id = e.id || "(machine)", this.implementations = {
1612
- actors: t?.actors ?? {},
1613
- actions: t?.actions ?? {},
1614
- delays: t?.delays ?? {},
1615
- guards: t?.guards ?? {}
1616
- }, this.version = this.config.version, this.schemas = this.config.schemas, this.options = {
1617
- maxIterations: Infinity,
1618
- ...this.config.options
1619
- }, this.transition = this.transition.bind(this), this.getInitialSnapshot = this.getInitialSnapshot.bind(this), this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this), this.restoreSnapshot = this.restoreSnapshot.bind(this), this.start = this.start.bind(this), this.root = new O(e, {
1620
- _key: this.id,
1621
- _machine: this
1622
- }), this.root._initialize(), formatRouteTransitions(this.root), this.states = this.root.states, this.events = this.root.events;
1623
- }
1624
- provide(e) {
1625
- let { actions: t, guards: n, actors: r, delays: i } = this.implementations;
1626
- return new StateMachine(this.config, {
1627
- actions: {
1628
- ...t,
1629
- ...e.actions
1630
- },
1631
- guards: {
1632
- ...n,
1633
- ...e.guards
1634
- },
1635
- actors: {
1636
- ...r,
1637
- ...e.actors
1638
- },
1639
- delays: {
1640
- ...i,
1641
- ...e.delays
1642
- }
1643
- });
1644
- }
1645
- resolveState(e) {
1646
- let t = resolveStateValue(this.root, e.value), n = getAllStateNodes(getStateNodes(this.root, t));
1647
- return createMachineSnapshot({
1648
- _nodes: [...n],
1649
- context: e.context || {},
1650
- children: {},
1651
- status: isInFinalState(n, this.root) ? "done" : e.status || "active",
1652
- output: e.output,
1653
- error: e.error,
1654
- historyValue: e.historyValue
1655
- }, this);
1656
- }
1657
- transition(e, t, n) {
1658
- return macrostep(e, t, n, []).snapshot;
1659
- }
1660
- microstep(e, t, n) {
1661
- return macrostep(e, t, n, []).microsteps.map(([e]) => e);
1662
- }
1663
- getTransitionData(e, t) {
1664
- return transitionNode(this.root, e.value, e, t) || [];
1665
- }
1666
- _getPreInitialState(e, t, n) {
1667
- let { context: r } = this.config, i = createMachineSnapshot({
1668
- context: typeof r != "function" && r ? r : {},
1669
- _nodes: [this.root],
1670
- children: {},
1671
- status: "active"
1672
- }, this);
1673
- if (typeof r == "function") {
1674
- let assignment = ({ spawn: e, event: t, self: n }) => r({
1675
- spawn: e,
1676
- input: t.input,
1677
- self: n
1678
- });
1679
- return resolveActionsAndContext(i, t, e, [assign(assignment)], n, void 0);
1680
- }
1681
- return i;
1682
- }
1683
- getInitialSnapshot(e, t) {
1684
- let n = createInitEvent(t), r = [], i = createMachineSnapshot({
1685
- context: typeof this.config.context != "function" && this.config.context ? this.config.context : {},
1686
- _nodes: [this.root],
1687
- children: {},
1688
- status: "active"
1689
- }, this);
1690
- try {
1691
- i = this._getPreInitialState(e, n, r);
1692
- let [t] = initialMicrostep(this.root, i, e, n, r), { snapshot: a } = macrostep(t, n, e, r);
1693
- return a;
1694
- } catch (e) {
1695
- return cloneMachineSnapshot(i, {
1696
- status: "error",
1697
- error: e
1698
- });
1699
- }
1700
- }
1701
- start(e) {
1702
- Object.values(e.children).forEach((e) => {
1703
- e.getSnapshot().status === "active" && e.start();
1704
- });
1705
- }
1706
- getStateNodeById(e) {
1707
- let t = toStatePath(e), n = t.slice(1), r = isStateId(t[0]) ? t[0].slice(1) : t[0], i = this.idMap.get(r);
1708
- if (!i) throw Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);
1709
- return getStateNodeByPath(i, n);
1710
- }
1711
- get definition() {
1712
- return this.root.definition;
1713
- }
1714
- toJSON() {
1715
- return this.definition;
1716
- }
1717
- getPersistedSnapshot(e, t) {
1718
- return getPersistedSnapshot(e, t);
1719
- }
1720
- restoreSnapshot(e, t) {
1721
- let n = {}, r = e.children;
1722
- Object.keys(r).forEach((e) => {
1723
- let i = r[e], a = i.snapshot, o = i.src, s = typeof o == "string" ? resolveReferencedActor(this, o) : o;
1724
- if (!s) return;
1725
- let c = createActor(s, {
1726
- id: e,
1727
- parent: t.self,
1728
- syncSnapshot: i.syncSnapshot,
1729
- snapshot: a,
1730
- src: o,
1731
- systemId: i.systemId
1732
- });
1733
- n[e] = c;
1734
- });
1735
- function resolveHistoryReferencedState(e, t) {
1736
- if (t instanceof O) return t;
1737
- try {
1738
- return e.machine.getStateNodeById(t.id);
1739
- } catch {}
1740
- }
1741
- function reviveHistoryValue(e, t) {
1742
- if (!t || typeof t != "object") return {};
1743
- let n = {};
1744
- for (let r in t) {
1745
- let i = t[r];
1746
- for (let t of i) {
1747
- let i = resolveHistoryReferencedState(e, t);
1748
- i && (n[r] ??= [], n[r].push(i));
1749
- }
1750
- }
1751
- return n;
1752
- }
1753
- let i = reviveHistoryValue(this.root, e.historyValue), a = createMachineSnapshot({
1754
- ...e,
1755
- children: n,
1756
- _nodes: Array.from(getAllStateNodes(getStateNodes(this.root, e.value))),
1757
- historyValue: i
1758
- }, this), o = /* @__PURE__ */ new Set();
1759
- function reviveContext(e, t) {
1760
- if (!o.has(e)) {
1761
- o.add(e);
1762
- for (let n in e) {
1763
- let r = e[n];
1764
- if (r && typeof r == "object") {
1765
- if ("xstate$$type" in r && r.xstate$$type === 1) {
1766
- e[n] = t[r.id];
1767
- continue;
1768
- }
1769
- reviveContext(r, t);
1770
- }
1771
- }
1772
- }
1773
- }
1774
- return reviveContext(a.context, n), a;
1775
- }
1776
- };
1777
- //#endregion
1778
- //#region ../../node_modules/.pnpm/xstate@5.32.6/node_modules/xstate/dist/log-66075555.esm.js
1779
- function resolveEmit(e, t, n, r, { event: i }) {
1780
- return [
1781
- t,
1782
- { event: typeof i == "function" ? i(n, r) : i },
1783
- void 0
1784
- ];
1785
- }
1786
- function executeEmit(e, { event: t }) {
1787
- e.defer(() => e.emit(t));
1788
- }
1789
- function emit(e) {
1790
- function emit(e, t) {}
1791
- return emit.type = "xstate.emit", emit.event = e, emit.resolve = resolveEmit, emit.execute = executeEmit, emit;
1792
- }
1793
- var A = /*#__PURE__*/ function(e) {
1794
- return e.Parent = "#_parent", e.Internal = "#_internal", e;
1795
- }({});
1796
- function resolveSendTo(e, t, n, r, { to: i, event: a, id: o, delay: s }, c) {
1797
- let l = t.machine.implementations.delays;
1798
- if (typeof a == "string") throw Error(`Only event objects may be used with sendTo; use sendTo({ type: "${a}" }) instead`);
1799
- let u = typeof a == "function" ? a(n, r) : a, d;
1800
- if (typeof s == "string") {
1801
- let e = l && l[s];
1802
- d = typeof e == "function" ? e(n, r) : e;
1803
- } else d = typeof s == "function" ? s(n, r) : s;
1804
- let f = typeof i == "function" ? i(n, r) : i, p;
1805
- if (typeof f == "string") {
1806
- if (p = f === A.Parent ? e.self._parent : f === A.Internal ? e.self : f.startsWith("#_") ? t.children[f.slice(2)] : c.deferredActorIds?.includes(f) ? f : t.children[f], !p) throw Error(`Unable to send event to actor '${f}' from machine '${t.machine.id}'.`);
1807
- } else p = f || e.self;
1808
- return [
1809
- t,
1810
- {
1811
- to: p,
1812
- targetId: typeof f == "string" ? f : void 0,
1813
- event: u,
1814
- id: o,
1815
- delay: d
1816
- },
1817
- void 0
1818
- ];
1819
- }
1820
- function retryResolveSendTo(e, t, n) {
1821
- typeof n.to == "string" && (n.to = t.children[n.to]);
1822
- }
1823
- function executeSendTo(e, t) {
1824
- e.defer(() => {
1825
- let { to: n, event: r, delay: i, id: a } = t;
1826
- if (typeof i == "number") {
1827
- e.system.scheduler.schedule(e.self, n, r, i, a);
1828
- return;
1829
- }
1830
- e.system._relay(e.self, n, r.type === "xstate.error" ? createErrorActorEvent(e.self.id, r.data) : r);
1831
- });
1832
- }
1833
- function sendTo(e, t, n) {
1834
- function sendTo(e, t) {}
1835
- return sendTo.type = "xstate.sendTo", sendTo.to = e, sendTo.event = t, sendTo.id = n?.id, sendTo.delay = n?.delay, sendTo.resolve = resolveSendTo, sendTo.retryResolve = retryResolveSendTo, sendTo.execute = executeSendTo, sendTo;
1836
- }
1837
- function sendParent(e, t) {
1838
- return sendTo(A.Parent, e, t);
1839
- }
1840
- function resolveEnqueueActions(e, t, n, r, { collect: i }) {
1841
- let a = [], o = function enqueue(e) {
1842
- a.push(e);
1843
- };
1844
- return o.assign = (...e) => {
1845
- a.push(assign(...e));
1846
- }, o.cancel = (...e) => {
1847
- a.push(cancel(...e));
1848
- }, o.raise = (...e) => {
1849
- a.push(raise(...e));
1850
- }, o.sendTo = (...e) => {
1851
- a.push(sendTo(...e));
1852
- }, o.sendParent = (...e) => {
1853
- a.push(sendParent(...e));
1854
- }, o.spawnChild = (...e) => {
1855
- a.push(spawnChild(...e));
1856
- }, o.stopChild = (...e) => {
1857
- a.push(stopChild(...e));
1858
- }, o.emit = (...e) => {
1859
- a.push(emit(...e));
1860
- }, i({
1861
- context: n.context,
1862
- event: n.event,
1863
- enqueue: o,
1864
- check: (e) => evaluateGuard(e, t.context, n.event, t),
1865
- self: e.self,
1866
- system: e.system
1867
- }, r), [
1868
- t,
1869
- void 0,
1870
- a
1871
- ];
1872
- }
1873
- function enqueueActions(e) {
1874
- function enqueueActions(e, t) {}
1875
- return enqueueActions.type = "xstate.enqueueActions", enqueueActions.collect = e, enqueueActions.resolve = resolveEnqueueActions, enqueueActions;
1876
- }
1877
- function resolveLog(e, t, n, r, { value: i, label: a }) {
1878
- return [
1879
- t,
1880
- {
1881
- value: typeof i == "function" ? i(n, r) : i,
1882
- label: a
1883
- },
1884
- void 0
1885
- ];
1886
- }
1887
- function executeLog({ logger: e }, { value: t, label: n }) {
1888
- n ? e(n, t) : e(t);
1889
- }
1890
- function log(e = ({ context: e, event: t }) => ({
1891
- context: e,
1892
- event: t
1893
- }), t) {
1894
- function log(e, t) {}
1895
- return log.type = "xstate.log", log.value = e, log.label = t, log.resolve = resolveLog, log.execute = executeLog, log;
1896
- }
1897
- //#endregion
1898
- //#region ../../node_modules/.pnpm/xstate@5.32.6/node_modules/xstate/dist/xstate.esm.js
1899
- function assertEvent(e, t) {
1900
- let n = toArray(t);
1901
- if (!n.some((t) => matchesEventDescriptor(e.type, t))) {
1902
- let t = n.length === 1 ? `type matching "${n[0]}"` : `one of types matching "${n.join("\", \"")}"`;
1903
- throw Error(`Expected event ${JSON.stringify(e)} to have ${t}`);
1904
- }
1905
- }
1906
- function createMachine(e, t) {
1907
- return new k(e, t);
1908
- }
1909
- function setup({ schemas: e, actors: t, actions: n, guards: r, delays: i }) {
1910
- return {
1911
- assign,
1912
- sendTo,
1913
- raise,
1914
- log,
1915
- cancel,
1916
- stopChild,
1917
- enqueueActions,
1918
- emit,
1919
- spawnChild,
1920
- createStateConfig: (e) => e,
1921
- createAction: (e) => e,
1922
- createMachine: (a) => createMachine({
1923
- ...a,
1924
- schemas: e
1925
- }, {
1926
- actors: t,
1927
- actions: n,
1928
- guards: r,
1929
- delays: i
1930
- }),
1931
- extend: (a) => setup({
1932
- schemas: e,
1933
- actors: t,
1934
- actions: {
1935
- ...n,
1936
- ...a.actions
1937
- },
1938
- guards: {
1939
- ...r,
1940
- ...a.guards
1941
- },
1942
- delays: {
1943
- ...i,
1944
- ...a.delays
1945
- }
1946
- })
1947
- };
1948
- }
1949
- //#endregion
1950
- //#region ../../node_modules/.pnpm/@xstate+react@6.1.0_@types+react@19.2.18_react@19.2.8_xstate@5.32.6/node_modules/@xstate/react/dist/xstate-react.esm.js
1951
- var forEachActor = (e, t) => {
1952
- t(e);
1953
- let n = e.getSnapshot().children;
1954
- n && Object.values(n).forEach((e) => {
1955
- forEachActor(e, t);
1956
- });
1957
- };
1958
- function stopRootWithRehydration(e) {
1959
- let t = [];
1960
- forEachActor(e, (e) => {
1961
- t.push([e, e.getSnapshot()]), e.observers = /* @__PURE__ */ new Set();
1962
- });
1963
- let n = e.system.getSnapshot?.();
1964
- e.stop(), e.system._snapshot = n, t.forEach(([e, t]) => {
1965
- e._processingStatus = 0, e._snapshot = t;
1966
- });
1967
- }
1968
- function useIdleActorRef(e, ...[t]) {
1969
- let [[n, r], a] = i(() => {
1970
- let n = createActor(e, t);
1971
- return [e.config, n];
1972
- });
1973
- if (e.config !== n) {
1974
- let n = createActor(e, {
1975
- ...t,
1976
- snapshot: r.getPersistedSnapshot({ __unsafeAllowInlineActors: !0 })
1977
- });
1978
- a([e.config, n]), r = n;
1979
- }
1980
- return o(() => {
1981
- r.logic.implementations = e.implementations;
1982
- }), r;
1983
- }
1984
- function useActorRef(e, ...[t, r]) {
1985
- let i = useIdleActorRef(e, t);
1986
- return n(() => {
1987
- if (!r) return;
1988
- let e = i.subscribe(toObserver(r));
1989
- return () => {
1990
- e.unsubscribe();
1991
- };
1992
- }, [r]), n(() => (i.start(), () => {
1993
- stopRootWithRehydration(i);
1994
- }), [i]), i;
1995
- }
1996
- function defaultCompare(e, t) {
1997
- return e === t;
1998
- }
1999
- function useSelector(e, n, r = defaultCompare) {
2000
- let i = t((t) => {
2001
- if (!e) return () => {};
2002
- let { unsubscribe: n } = e.subscribe({
2003
- next: t,
2004
- error: t
2005
- });
2006
- return n;
2007
- }, [e]), o = t(() => {
2008
- let t = e?.getSnapshot();
2009
- if (t && "status" in t && t.status === "error") throw t.error;
2010
- return t;
2011
- }, [e]);
2012
- return a(i, o, o, n, r);
2013
- }
2014
- //#endregion
2015
- export { spawnChild as _, emit as a, sendTo as c, fromPromise as d, and as f, raise as g, or as h, setup as i, assign as l, not as m, useSelector as n, enqueueActions as o, cancel as p, assertEvent as r, log as s, useActorRef as t, fromCallback as u, stopChild as v };