sanity 3.94.1-next.5.ec6157041e → 3.94.1

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 (113) hide show
  1. package/dist/BehaviorSubject-CU-WJrzA.mjs +30 -0
  2. package/dist/BehaviorSubject-CU-WJrzA.mjs.map +1 -0
  3. package/dist/BroadcastDisplayedDocument-BSV9T3BU.mjs +20 -0
  4. package/dist/BroadcastDisplayedDocument-BSV9T3BU.mjs.map +1 -0
  5. package/dist/DisplayedDocumentBroadcaster-DZ65n35Q.mjs +62 -0
  6. package/dist/DisplayedDocumentBroadcaster-DZ65n35Q.mjs.map +1 -0
  7. package/dist/LiveQueries-Crz53eU5.mjs +407 -0
  8. package/dist/LiveQueries-Crz53eU5.mjs.map +1 -0
  9. package/dist/Observable-CCQtH8Gg.mjs +546 -0
  10. package/dist/Observable-CCQtH8Gg.mjs.map +1 -0
  11. package/dist/PostMessageDocuments-BjgsJxz4.mjs +72 -0
  12. package/dist/PostMessageDocuments-BjgsJxz4.mjs.map +1 -0
  13. package/dist/PostMessagePerspective-pucY-E6a.mjs +22 -0
  14. package/dist/PostMessagePerspective-pucY-E6a.mjs.map +1 -0
  15. package/dist/PostMessagePreviewSnapshots-CRQgRg4_.mjs +71 -0
  16. package/dist/PostMessagePreviewSnapshots-CRQgRg4_.mjs.map +1 -0
  17. package/dist/PostMessageRefreshMutations-D944RbO3.mjs +66 -0
  18. package/dist/PostMessageRefreshMutations-D944RbO3.mjs.map +1 -0
  19. package/dist/PostMessageSchema-3eOtr1bs.mjs +516 -0
  20. package/dist/PostMessageSchema-3eOtr1bs.mjs.map +1 -0
  21. package/dist/PostMessageTelemetry-DMTQDJeN.mjs +20 -0
  22. package/dist/PostMessageTelemetry-DMTQDJeN.mjs.map +1 -0
  23. package/dist/PresentationToolGrantsCheck-B0q4AQ3b.mjs +3999 -0
  24. package/dist/PresentationToolGrantsCheck-B0q4AQ3b.mjs.map +1 -0
  25. package/dist/QRCodeSVG-hyTW2xeN.mjs +648 -0
  26. package/dist/QRCodeSVG-hyTW2xeN.mjs.map +1 -0
  27. package/dist/Refractor-Zss2QEe8.mjs +2568 -0
  28. package/dist/Refractor-Zss2QEe8.mjs.map +1 -0
  29. package/dist/SourceContext-QxJD1Wrm.mjs +111 -0
  30. package/dist/SourceContext-QxJD1Wrm.mjs.map +1 -0
  31. package/dist/StructureToolProvider-B-7cwz7l.mjs +2287 -0
  32. package/dist/StructureToolProvider-B-7cwz7l.mjs.map +1 -0
  33. package/dist/ViteDevServerStopped-CgIEqy9p.mjs +57 -0
  34. package/dist/ViteDevServerStopped-CgIEqy9p.mjs.map +1 -0
  35. package/dist/_createContext.mjs +38 -0
  36. package/dist/_createContext.mjs.map +1 -0
  37. package/dist/_singletons.mjs +216 -0
  38. package/dist/_singletons.mjs.map +1 -0
  39. package/dist/browser-B0Q9qZJS.mjs +478 -0
  40. package/dist/browser-B0Q9qZJS.mjs.map +1 -0
  41. package/dist/browser-DmX5VEcE.mjs +324 -0
  42. package/dist/browser-DmX5VEcE.mjs.map +1 -0
  43. package/dist/desk.mjs +53 -0
  44. package/dist/desk.mjs.map +1 -0
  45. package/dist/first-Cz545eV-.mjs +42 -0
  46. package/dist/first-Cz545eV-.mjs.map +1 -0
  47. package/dist/index-B2GCDfau.mjs +96 -0
  48. package/dist/index-B2GCDfau.mjs.map +1 -0
  49. package/dist/index-BRIelBPK.mjs +6946 -0
  50. package/dist/index-BRIelBPK.mjs.map +1 -0
  51. package/dist/index-BUB137yJ.mjs +144 -0
  52. package/dist/index-BUB137yJ.mjs.map +1 -0
  53. package/dist/index-C3PGPrdL.mjs +1192 -0
  54. package/dist/index-C3PGPrdL.mjs.map +1 -0
  55. package/dist/index-C9NvTy6s.mjs +319 -0
  56. package/dist/index-C9NvTy6s.mjs.map +1 -0
  57. package/dist/index-DCkQlgdi.mjs +4001 -0
  58. package/dist/index-DCkQlgdi.mjs.map +1 -0
  59. package/dist/index-DG-3plB0.mjs +71 -0
  60. package/dist/index-DG-3plB0.mjs.map +1 -0
  61. package/dist/index-RoxwhtVB.mjs +5600 -0
  62. package/dist/index-RoxwhtVB.mjs.map +1 -0
  63. package/dist/index-iMZR29eF.mjs +756 -0
  64. package/dist/index-iMZR29eF.mjs.map +1 -0
  65. package/dist/index-wVXq9rWS.mjs +244 -0
  66. package/dist/index-wVXq9rWS.mjs.map +1 -0
  67. package/dist/index.mjs +137385 -0
  68. package/dist/index.mjs.map +1 -0
  69. package/dist/lodash-Vz5dH_Dm.mjs +3679 -0
  70. package/dist/lodash-Vz5dH_Dm.mjs.map +1 -0
  71. package/dist/pane-Bm_57XKB.mjs +5 -0
  72. package/dist/pane-Bm_57XKB.mjs.map +1 -0
  73. package/dist/pane-Dopl4BjD.mjs +5 -0
  74. package/dist/pane-Dopl4BjD.mjs.map +1 -0
  75. package/dist/presentation-DsIky7Cj.mjs +556 -0
  76. package/dist/presentation-DsIky7Cj.mjs.map +1 -0
  77. package/dist/presentation.mjs +10 -0
  78. package/dist/presentation.mjs.map +1 -0
  79. package/dist/publishReplay-PuJoYJpp.mjs +92 -0
  80. package/dist/publishReplay-PuJoYJpp.mjs.map +1 -0
  81. package/dist/refractor-Bg1S3YDK.mjs +26 -0
  82. package/dist/refractor-Bg1S3YDK.mjs.map +1 -0
  83. package/dist/resources-BQsCEzu1.mjs +60 -0
  84. package/dist/resources-BQsCEzu1.mjs.map +1 -0
  85. package/dist/resources-BahMtJuO.mjs +177 -0
  86. package/dist/resources-BahMtJuO.mjs.map +1 -0
  87. package/dist/resources-CjkBN4z6.mjs +126 -0
  88. package/dist/resources-CjkBN4z6.mjs.map +1 -0
  89. package/dist/resources-Dc-6ZcPg.mjs +157 -0
  90. package/dist/resources-Dc-6ZcPg.mjs.map +1 -0
  91. package/dist/resources-DqxSuDsr.mjs +37 -0
  92. package/dist/resources-DqxSuDsr.mjs.map +1 -0
  93. package/dist/resources-_gTjFWLH.mjs +517 -0
  94. package/dist/resources-_gTjFWLH.mjs.map +1 -0
  95. package/dist/resources-kA1bao30.mjs +358 -0
  96. package/dist/resources-kA1bao30.mjs.map +1 -0
  97. package/dist/router.mjs +721 -0
  98. package/dist/router.mjs.map +1 -0
  99. package/dist/stegaEncodeSourceMap-DCG9Ba1H.mjs +358 -0
  100. package/dist/stegaEncodeSourceMap-DCG9Ba1H.mjs.map +1 -0
  101. package/dist/structure.mjs +57 -0
  102. package/dist/structure.mjs.map +1 -0
  103. package/dist/structureTool-Bth1vd8r.mjs +13150 -0
  104. package/dist/structureTool-Bth1vd8r.mjs.map +1 -0
  105. package/dist/switchMap-DHVUskpL.mjs +54 -0
  106. package/dist/switchMap-DHVUskpL.mjs.map +1 -0
  107. package/dist/v4-zH-CAum7.mjs +24798 -0
  108. package/dist/v4-zH-CAum7.mjs.map +1 -0
  109. package/dist/version-DoE_JnhG.mjs +5 -0
  110. package/dist/version-DoE_JnhG.mjs.map +1 -0
  111. package/lib/_chunks-cjs/version.js +1 -1
  112. package/lib/_chunks-es/version.mjs +1 -1
  113. package/package.json +23 -23
@@ -0,0 +1,4001 @@
1
+ import lt, { useLayoutEffect as Jt, useCallback as Je, useEffect as Ne, useState as Nt, forwardRef as pt } from "react";
2
+ import { v as Xt, f as yt, b as Oe, x as Yt, y as Ie, z as Kt, t as Zt } from "./index-RoxwhtVB.mjs";
3
+ import { o as Ft, c as Qt, m as Ae, y as Ce } from "./v4-zH-CAum7.mjs";
4
+ import { b as ye, a as en, p as ge } from "./Observable-CCQtH8Gg.mjs";
5
+ import { jsxs as gt, jsx as R } from "react/jsx-runtime";
6
+ function tn(e, t) {
7
+ return t === void 0 && (t = null), t = t ?? e, Ft(function(n, s) {
8
+ var r = [], i = 0;
9
+ n.subscribe(Qt(s, function(o) {
10
+ var a, d, h, y, u = null;
11
+ i++ % t === 0 && r.push([]);
12
+ try {
13
+ for (var c = ye(r), l = c.next(); !l.done; l = c.next()) {
14
+ var f = l.value;
15
+ f.push(o), e <= f.length && (u = u ?? [], u.push(f));
16
+ }
17
+ } catch (m) {
18
+ a = { error: m };
19
+ } finally {
20
+ try {
21
+ l && !l.done && (d = c.return) && d.call(c);
22
+ } finally {
23
+ if (a) throw a.error;
24
+ }
25
+ }
26
+ if (u)
27
+ try {
28
+ for (var p = ye(u), g = p.next(); !g.done; g = p.next()) {
29
+ var f = g.value;
30
+ en(r, f), s.next(f);
31
+ }
32
+ } catch (m) {
33
+ h = { error: m };
34
+ } finally {
35
+ try {
36
+ g && !g.done && (y = p.return) && y.call(p);
37
+ } finally {
38
+ if (h) throw h.error;
39
+ }
40
+ }
41
+ }, function() {
42
+ var o, a;
43
+ try {
44
+ for (var d = ye(r), h = d.next(); !h.done; h = d.next()) {
45
+ var y = h.value;
46
+ s.next(y);
47
+ }
48
+ } catch (u) {
49
+ o = { error: u };
50
+ } finally {
51
+ try {
52
+ h && !h.done && (a = d.return) && a.call(d);
53
+ } finally {
54
+ if (o) throw o.error;
55
+ }
56
+ }
57
+ s.complete();
58
+ }, void 0, function() {
59
+ r = null;
60
+ }));
61
+ });
62
+ }
63
+ var nn = Jt;
64
+ function sn() {
65
+ if (typeof globalThis < "u")
66
+ return globalThis;
67
+ if (typeof self < "u")
68
+ return self;
69
+ if (typeof window < "u")
70
+ return window;
71
+ if (typeof global < "u")
72
+ return global;
73
+ }
74
+ function rn() {
75
+ const e = sn();
76
+ if (e.__xstate__)
77
+ return e.__xstate__;
78
+ }
79
+ const on = (e) => {
80
+ if (typeof window > "u")
81
+ return;
82
+ const t = rn();
83
+ t && t.register(e);
84
+ };
85
+ class Xe {
86
+ constructor(t) {
87
+ this._process = t, this._active = !1, this._current = null, this._last = null;
88
+ }
89
+ start() {
90
+ this._active = !0, this.flush();
91
+ }
92
+ clear() {
93
+ this._current && (this._current.next = null, this._last = this._current);
94
+ }
95
+ enqueue(t) {
96
+ const n = {
97
+ value: t,
98
+ next: null
99
+ };
100
+ if (this._current) {
101
+ this._last.next = n, this._last = n;
102
+ return;
103
+ }
104
+ this._current = n, this._last = n, this._active && this.flush();
105
+ }
106
+ flush() {
107
+ for (; this._current; ) {
108
+ const t = this._current;
109
+ this._process(t.value), this._current = t.next;
110
+ }
111
+ this._last = null;
112
+ }
113
+ }
114
+ const mt = ".", an = "", vt = "", cn = "#", un = "*", _t = "xstate.init", dn = "xstate.error", j = "xstate.stop";
115
+ function fn(e, t) {
116
+ return {
117
+ type: `xstate.after.${e}.${t}`
118
+ };
119
+ }
120
+ function Re(e, t) {
121
+ return {
122
+ type: `xstate.done.state.${e}`,
123
+ output: t
124
+ };
125
+ }
126
+ function hn(e, t) {
127
+ return {
128
+ type: `xstate.done.actor.${e}`,
129
+ output: t,
130
+ actorId: e
131
+ };
132
+ }
133
+ function St(e, t) {
134
+ return {
135
+ type: `xstate.error.actor.${e}`,
136
+ error: t,
137
+ actorId: e
138
+ };
139
+ }
140
+ function bt(e) {
141
+ return {
142
+ type: _t,
143
+ input: e
144
+ };
145
+ }
146
+ function k(e) {
147
+ setTimeout(() => {
148
+ throw e;
149
+ });
150
+ }
151
+ const ln = typeof Symbol == "function" && Symbol.observable || "@@observable";
152
+ function wt(e, t) {
153
+ const n = Ye(e), s = Ye(t);
154
+ return typeof s == "string" ? typeof n == "string" ? s === n : !1 : typeof n == "string" ? n in s : Object.keys(n).every((r) => r in s ? wt(n[r], s[r]) : !1);
155
+ }
156
+ function je(e) {
157
+ if (Tt(e))
158
+ return e;
159
+ const t = [];
160
+ let n = "";
161
+ for (let s = 0; s < e.length; s++) {
162
+ switch (e.charCodeAt(s)) {
163
+ // \
164
+ case 92:
165
+ n += e[s + 1], s++;
166
+ continue;
167
+ // .
168
+ case 46:
169
+ t.push(n), n = "";
170
+ continue;
171
+ }
172
+ n += e[s];
173
+ }
174
+ return t.push(n), t;
175
+ }
176
+ function Ye(e) {
177
+ if (Xn(e))
178
+ return e.value;
179
+ if (typeof e != "string")
180
+ return e;
181
+ const t = je(e);
182
+ return pn(t);
183
+ }
184
+ function pn(e) {
185
+ if (e.length === 1)
186
+ return e[0];
187
+ const t = {};
188
+ let n = t;
189
+ for (let s = 0; s < e.length - 1; s++)
190
+ if (s === e.length - 2)
191
+ n[e[s]] = e[s + 1];
192
+ else {
193
+ const r = n;
194
+ n = {}, r[e[s]] = n;
195
+ }
196
+ return t;
197
+ }
198
+ function Ke(e, t) {
199
+ const n = {}, s = Object.keys(e);
200
+ for (let r = 0; r < s.length; r++) {
201
+ const i = s[r];
202
+ n[i] = t(e[i], i, e, r);
203
+ }
204
+ return n;
205
+ }
206
+ function Et(e) {
207
+ return Tt(e) ? e : [e];
208
+ }
209
+ function C(e) {
210
+ return e === void 0 ? [] : Et(e);
211
+ }
212
+ function Me(e, t, n, s) {
213
+ return typeof e == "function" ? e({
214
+ context: t,
215
+ event: n,
216
+ self: s
217
+ }) : e;
218
+ }
219
+ function Tt(e) {
220
+ return Array.isArray(e);
221
+ }
222
+ function yn(e) {
223
+ return e.type.startsWith("xstate.error.actor");
224
+ }
225
+ function U(e) {
226
+ return Et(e).map((t) => typeof t > "u" || typeof t == "string" ? {
227
+ target: t
228
+ } : t);
229
+ }
230
+ function xt(e) {
231
+ if (!(e === void 0 || e === an))
232
+ return C(e);
233
+ }
234
+ function ae(e, t, n) {
235
+ var i, o, a;
236
+ const s = typeof e == "object", r = s ? e : void 0;
237
+ return {
238
+ next: (i = s ? e.next : e) == null ? void 0 : i.bind(r),
239
+ error: (o = s ? e.error : t) == null ? void 0 : o.bind(r),
240
+ complete: (a = s ? e.complete : n) == null ? void 0 : a.bind(r)
241
+ };
242
+ }
243
+ function Ze(e, t) {
244
+ return `${t}.${e}`;
245
+ }
246
+ function De(e, t) {
247
+ const n = t.match(/^xstate\.invoke\.(\d+)\.(.*)/);
248
+ if (!n)
249
+ return e.implementations.actors[t];
250
+ const [, s, r] = n, o = e.getStateNodeById(r).config.invoke;
251
+ return (Array.isArray(o) ? o[s] : o).src;
252
+ }
253
+ function Fe(e, t) {
254
+ return `${e.sessionId}.${t}`;
255
+ }
256
+ let gn = 0;
257
+ function mn(e, t) {
258
+ const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new Set(), o = {}, {
259
+ clock: a,
260
+ logger: d
261
+ } = t, h = {
262
+ schedule: (c, l, f, p, g = Math.random().toString(36).slice(2)) => {
263
+ const m = {
264
+ source: c,
265
+ target: l,
266
+ event: f,
267
+ delay: p,
268
+ id: g,
269
+ startedAt: Date.now()
270
+ }, v = Fe(c, g);
271
+ u._snapshot._scheduledEvents[v] = m;
272
+ const _ = a.setTimeout(() => {
273
+ delete o[v], delete u._snapshot._scheduledEvents[v], u._relay(c, l, f);
274
+ }, p);
275
+ o[v] = _;
276
+ },
277
+ cancel: (c, l) => {
278
+ const f = Fe(c, l), p = o[f];
279
+ delete o[f], delete u._snapshot._scheduledEvents[f], p !== void 0 && a.clearTimeout(p);
280
+ },
281
+ cancelAll: (c) => {
282
+ for (const l in u._snapshot._scheduledEvents) {
283
+ const f = u._snapshot._scheduledEvents[l];
284
+ f.source === c && h.cancel(c, f.id);
285
+ }
286
+ }
287
+ }, y = (c) => {
288
+ if (!i.size)
289
+ return;
290
+ const l = {
291
+ ...c,
292
+ rootId: e.sessionId
293
+ };
294
+ i.forEach((f) => {
295
+ var p;
296
+ return (p = f.next) == null ? void 0 : p.call(f, l);
297
+ });
298
+ }, u = {
299
+ _snapshot: {
300
+ _scheduledEvents: ((t == null ? void 0 : t.snapshot) && t.snapshot.scheduler) ?? {}
301
+ },
302
+ _bookId: () => `x:${gn++}`,
303
+ _register: (c, l) => (n.set(c, l), c),
304
+ _unregister: (c) => {
305
+ n.delete(c.sessionId);
306
+ const l = r.get(c);
307
+ l !== void 0 && (s.delete(l), r.delete(c));
308
+ },
309
+ get: (c) => s.get(c),
310
+ _set: (c, l) => {
311
+ const f = s.get(c);
312
+ if (f && f !== l)
313
+ throw new Error(`Actor with system ID '${c}' already exists.`);
314
+ s.set(c, l), r.set(l, c);
315
+ },
316
+ inspect: (c) => {
317
+ const l = ae(c);
318
+ return i.add(l), {
319
+ unsubscribe() {
320
+ i.delete(l);
321
+ }
322
+ };
323
+ },
324
+ _sendInspectionEvent: y,
325
+ _relay: (c, l, f) => {
326
+ u._sendInspectionEvent({
327
+ type: "@xstate.event",
328
+ sourceRef: c,
329
+ actorRef: l,
330
+ event: f
331
+ }), l._send(f);
332
+ },
333
+ scheduler: h,
334
+ getSnapshot: () => ({
335
+ _scheduledEvents: {
336
+ ...u._snapshot._scheduledEvents
337
+ }
338
+ }),
339
+ start: () => {
340
+ const c = u._snapshot._scheduledEvents;
341
+ u._snapshot._scheduledEvents = {};
342
+ for (const l in c) {
343
+ const {
344
+ source: f,
345
+ target: p,
346
+ event: g,
347
+ delay: m,
348
+ id: v
349
+ } = c[l];
350
+ h.schedule(f, p, g, m, v);
351
+ }
352
+ },
353
+ _clock: a,
354
+ _logger: d
355
+ };
356
+ return u;
357
+ }
358
+ let me = !1;
359
+ const Ve = 1;
360
+ let E = /* @__PURE__ */ function(e) {
361
+ return e[e.NotStarted = 0] = "NotStarted", e[e.Running = 1] = "Running", e[e.Stopped = 2] = "Stopped", e;
362
+ }({});
363
+ const vn = {
364
+ clock: {
365
+ setTimeout: (e, t) => setTimeout(e, t),
366
+ clearTimeout: (e) => clearTimeout(e)
367
+ },
368
+ logger: console.log.bind(console),
369
+ devTools: !1
370
+ };
371
+ class _n {
372
+ /**
373
+ * Creates a new actor instance for the given logic with the provided options,
374
+ * if any.
375
+ *
376
+ * @param logic The logic to create an actor from
377
+ * @param options Actor options
378
+ */
379
+ constructor(t, n) {
380
+ this.logic = t, this._snapshot = void 0, this.clock = void 0, this.options = void 0, this.id = void 0, this.mailbox = new Xe(this._process.bind(this)), this.observers = /* @__PURE__ */ new Set(), this.eventListeners = /* @__PURE__ */ new Map(), this.logger = void 0, this._processingStatus = E.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 = [];
381
+ const s = {
382
+ ...vn,
383
+ ...n
384
+ }, {
385
+ clock: r,
386
+ logger: i,
387
+ parent: o,
388
+ syncSnapshot: a,
389
+ id: d,
390
+ systemId: h,
391
+ inspect: y
392
+ } = s;
393
+ this.system = o ? o.system : mn(this, {
394
+ clock: r,
395
+ logger: i
396
+ }), y && !o && this.system.inspect(ae(y)), this.sessionId = this.system._bookId(), this.id = d ?? this.sessionId, this.logger = (n == null ? void 0 : n.logger) ?? this.system._logger, this.clock = (n == null ? void 0 : n.clock) ?? this.system._clock, this._parent = o, this._syncSnapshot = a, this.options = s, this.src = s.src ?? t, this.ref = this, this._actorScope = {
397
+ self: this,
398
+ id: this.id,
399
+ sessionId: this.sessionId,
400
+ logger: this.logger,
401
+ defer: (u) => {
402
+ this._deferred.push(u);
403
+ },
404
+ system: this.system,
405
+ stopChild: (u) => {
406
+ if (u._parent !== this)
407
+ throw new Error(`Cannot stop child actor ${u.id} of ${this.id} because it is not a child`);
408
+ u._stop();
409
+ },
410
+ emit: (u) => {
411
+ const c = this.eventListeners.get(u.type), l = this.eventListeners.get("*");
412
+ if (!c && !l)
413
+ return;
414
+ const f = [...c ? c.values() : [], ...l ? l.values() : []];
415
+ for (const p of f)
416
+ p(u);
417
+ },
418
+ actionExecutor: (u) => {
419
+ const c = () => {
420
+ if (this._actorScope.system._sendInspectionEvent({
421
+ type: "@xstate.action",
422
+ actorRef: this,
423
+ action: {
424
+ type: u.type,
425
+ params: u.params
426
+ }
427
+ }), !u.exec)
428
+ return;
429
+ const l = me;
430
+ try {
431
+ me = !0, u.exec(u.info, u.params);
432
+ } finally {
433
+ me = l;
434
+ }
435
+ };
436
+ this._processingStatus === E.Running ? c() : this._deferred.push(c);
437
+ }
438
+ }, this.send = this.send.bind(this), this.system._sendInspectionEvent({
439
+ type: "@xstate.actor",
440
+ actorRef: this
441
+ }), h && (this._systemId = h, this.system._set(h, this)), this._initState((n == null ? void 0 : n.snapshot) ?? (n == null ? void 0 : n.state)), h && this._snapshot.status !== "active" && this.system._unregister(this);
442
+ }
443
+ _initState(t) {
444
+ var n;
445
+ try {
446
+ this._snapshot = t ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(t, this._actorScope) : t : this.logic.getInitialSnapshot(this._actorScope, (n = this.options) == null ? void 0 : n.input);
447
+ } catch (s) {
448
+ this._snapshot = {
449
+ status: "error",
450
+ output: void 0,
451
+ error: s
452
+ };
453
+ }
454
+ }
455
+ update(t, n) {
456
+ var r, i;
457
+ this._snapshot = t;
458
+ let s;
459
+ for (; s = this._deferred.shift(); )
460
+ try {
461
+ s();
462
+ } catch (o) {
463
+ this._deferred.length = 0, this._snapshot = {
464
+ ...t,
465
+ status: "error",
466
+ error: o
467
+ };
468
+ }
469
+ switch (this._snapshot.status) {
470
+ case "active":
471
+ for (const o of this.observers)
472
+ try {
473
+ (r = o.next) == null || r.call(o, t);
474
+ } catch (a) {
475
+ k(a);
476
+ }
477
+ break;
478
+ case "done":
479
+ for (const o of this.observers)
480
+ try {
481
+ (i = o.next) == null || i.call(o, t);
482
+ } catch (a) {
483
+ k(a);
484
+ }
485
+ this._stopProcedure(), this._complete(), this._doneEvent = hn(this.id, this._snapshot.output), this._parent && this.system._relay(this, this._parent, this._doneEvent);
486
+ break;
487
+ case "error":
488
+ this._error(this._snapshot.error);
489
+ break;
490
+ }
491
+ this.system._sendInspectionEvent({
492
+ type: "@xstate.snapshot",
493
+ actorRef: this,
494
+ event: n,
495
+ snapshot: t
496
+ });
497
+ }
498
+ /**
499
+ * Subscribe an observer to an actor’s snapshot values.
500
+ *
501
+ * @remarks
502
+ * The observer will receive the actor’s snapshot value when it is emitted.
503
+ * The observer can be:
504
+ *
505
+ * - A plain function that receives the latest snapshot, or
506
+ * - An observer object whose `.next(snapshot)` method receives the latest
507
+ * snapshot
508
+ *
509
+ * @example
510
+ *
511
+ * ```ts
512
+ * // Observer as a plain function
513
+ * const subscription = actor.subscribe((snapshot) => {
514
+ * console.log(snapshot);
515
+ * });
516
+ * ```
517
+ *
518
+ * @example
519
+ *
520
+ * ```ts
521
+ * // Observer as an object
522
+ * const subscription = actor.subscribe({
523
+ * next(snapshot) {
524
+ * console.log(snapshot);
525
+ * },
526
+ * error(err) {
527
+ * // ...
528
+ * },
529
+ * complete() {
530
+ * // ...
531
+ * }
532
+ * });
533
+ * ```
534
+ *
535
+ * The return value of `actor.subscribe(observer)` is a subscription object
536
+ * that has an `.unsubscribe()` method. You can call
537
+ * `subscription.unsubscribe()` to unsubscribe the observer:
538
+ *
539
+ * @example
540
+ *
541
+ * ```ts
542
+ * const subscription = actor.subscribe((snapshot) => {
543
+ * // ...
544
+ * });
545
+ *
546
+ * // Unsubscribe the observer
547
+ * subscription.unsubscribe();
548
+ * ```
549
+ *
550
+ * When the actor is stopped, all of its observers will automatically be
551
+ * unsubscribed.
552
+ *
553
+ * @param observer - Either a plain function that receives the latest
554
+ * snapshot, or an observer object whose `.next(snapshot)` method receives
555
+ * the latest snapshot
556
+ */
557
+ subscribe(t, n, s) {
558
+ var i;
559
+ const r = ae(t, n, s);
560
+ if (this._processingStatus !== E.Stopped)
561
+ this.observers.add(r);
562
+ else
563
+ switch (this._snapshot.status) {
564
+ case "done":
565
+ try {
566
+ (i = r.complete) == null || i.call(r);
567
+ } catch (o) {
568
+ k(o);
569
+ }
570
+ break;
571
+ case "error": {
572
+ const o = this._snapshot.error;
573
+ if (!r.error)
574
+ k(o);
575
+ else
576
+ try {
577
+ r.error(o);
578
+ } catch (a) {
579
+ k(a);
580
+ }
581
+ break;
582
+ }
583
+ }
584
+ return {
585
+ unsubscribe: () => {
586
+ this.observers.delete(r);
587
+ }
588
+ };
589
+ }
590
+ on(t, n) {
591
+ let s = this.eventListeners.get(t);
592
+ s || (s = /* @__PURE__ */ new Set(), this.eventListeners.set(t, s));
593
+ const r = n.bind(void 0);
594
+ return s.add(r), {
595
+ unsubscribe: () => {
596
+ s.delete(r);
597
+ }
598
+ };
599
+ }
600
+ /** Starts the Actor from the initial state */
601
+ start() {
602
+ if (this._processingStatus === E.Running)
603
+ return this;
604
+ this._syncSnapshot && this.subscribe({
605
+ next: (s) => {
606
+ s.status === "active" && this.system._relay(this, this._parent, {
607
+ type: `xstate.snapshot.${this.id}`,
608
+ snapshot: s
609
+ });
610
+ },
611
+ error: () => {
612
+ }
613
+ }), this.system._register(this.sessionId, this), this._systemId && this.system._set(this._systemId, this), this._processingStatus = E.Running;
614
+ const t = bt(this.options.input);
615
+ switch (this.system._sendInspectionEvent({
616
+ type: "@xstate.event",
617
+ sourceRef: this._parent,
618
+ actorRef: this,
619
+ event: t
620
+ }), this._snapshot.status) {
621
+ case "done":
622
+ return this.update(this._snapshot, t), this;
623
+ case "error":
624
+ return this._error(this._snapshot.error), this;
625
+ }
626
+ if (this._parent || this.system.start(), this.logic.start)
627
+ try {
628
+ this.logic.start(this._snapshot, this._actorScope);
629
+ } catch (s) {
630
+ return this._snapshot = {
631
+ ...this._snapshot,
632
+ status: "error",
633
+ error: s
634
+ }, this._error(s), this;
635
+ }
636
+ return this.update(this._snapshot, t), this.options.devTools && this.attachDevTools(), this.mailbox.start(), this;
637
+ }
638
+ _process(t) {
639
+ let n, s;
640
+ try {
641
+ n = this.logic.transition(this._snapshot, t, this._actorScope);
642
+ } catch (r) {
643
+ s = {
644
+ err: r
645
+ };
646
+ }
647
+ if (s) {
648
+ const {
649
+ err: r
650
+ } = s;
651
+ this._snapshot = {
652
+ ...this._snapshot,
653
+ status: "error",
654
+ error: r
655
+ }, this._error(r);
656
+ return;
657
+ }
658
+ this.update(n, t), t.type === j && (this._stopProcedure(), this._complete());
659
+ }
660
+ _stop() {
661
+ return this._processingStatus === E.Stopped ? this : (this.mailbox.clear(), this._processingStatus === E.NotStarted ? (this._processingStatus = E.Stopped, this) : (this.mailbox.enqueue({
662
+ type: j
663
+ }), this));
664
+ }
665
+ /** Stops the Actor and unsubscribe all listeners. */
666
+ stop() {
667
+ if (this._parent)
668
+ throw new Error("A non-root actor cannot be stopped directly.");
669
+ return this._stop();
670
+ }
671
+ _complete() {
672
+ var t;
673
+ for (const n of this.observers)
674
+ try {
675
+ (t = n.complete) == null || t.call(n);
676
+ } catch (s) {
677
+ k(s);
678
+ }
679
+ this.observers.clear();
680
+ }
681
+ _reportError(t) {
682
+ if (!this.observers.size) {
683
+ this._parent || k(t);
684
+ return;
685
+ }
686
+ let n = !1;
687
+ for (const s of this.observers) {
688
+ const r = s.error;
689
+ n || (n = !r);
690
+ try {
691
+ r == null || r(t);
692
+ } catch (i) {
693
+ k(i);
694
+ }
695
+ }
696
+ this.observers.clear(), n && k(t);
697
+ }
698
+ _error(t) {
699
+ this._stopProcedure(), this._reportError(t), this._parent && this.system._relay(this, this._parent, St(this.id, t));
700
+ }
701
+ // TODO: atm children don't belong entirely to the actor so
702
+ // in a way - it's not even super aware of them
703
+ // so we can't stop them from here but we really should!
704
+ // right now, they are being stopped within the machine's transition
705
+ // but that could throw and leave us with "orphaned" active actors
706
+ _stopProcedure() {
707
+ return this._processingStatus !== E.Running ? this : (this.system.scheduler.cancelAll(this), this.mailbox.clear(), this.mailbox = new Xe(this._process.bind(this)), this._processingStatus = E.Stopped, this.system._unregister(this), this);
708
+ }
709
+ /** @internal */
710
+ _send(t) {
711
+ this._processingStatus !== E.Stopped && this.mailbox.enqueue(t);
712
+ }
713
+ /**
714
+ * Sends an event to the running Actor to trigger a transition.
715
+ *
716
+ * @param event The event to send
717
+ */
718
+ send(t) {
719
+ this.system._relay(void 0, this, t);
720
+ }
721
+ attachDevTools() {
722
+ const {
723
+ devTools: t
724
+ } = this.options;
725
+ t && (typeof t == "function" ? t : on)(this);
726
+ }
727
+ toJSON() {
728
+ return {
729
+ xstate$$type: Ve,
730
+ id: this.id
731
+ };
732
+ }
733
+ /**
734
+ * Obtain the internal state of the actor, which can be persisted.
735
+ *
736
+ * @remarks
737
+ * The internal state can be persisted from any actor, not only machines.
738
+ *
739
+ * Note that the persisted state is not the same as the snapshot from
740
+ * {@link Actor.getSnapshot}. Persisted state represents the internal state of
741
+ * the actor, while snapshots represent the actor's last emitted value.
742
+ *
743
+ * Can be restored with {@link ActorOptions.state}
744
+ * @see https://stately.ai/docs/persistence
745
+ */
746
+ getPersistedSnapshot(t) {
747
+ return this.logic.getPersistedSnapshot(this._snapshot, t);
748
+ }
749
+ [ln]() {
750
+ return this;
751
+ }
752
+ /**
753
+ * Read an actor’s snapshot synchronously.
754
+ *
755
+ * @remarks
756
+ * The snapshot represent an actor's last emitted value.
757
+ *
758
+ * When an actor receives an event, its internal state may change. An actor
759
+ * may emit a snapshot when a state transition occurs.
760
+ *
761
+ * Note that some actors, such as callback actors generated with
762
+ * `fromCallback`, will not emit snapshots.
763
+ * @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
764
+ * @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
765
+ */
766
+ getSnapshot() {
767
+ return this._snapshot;
768
+ }
769
+ }
770
+ function $(e, ...[t]) {
771
+ return new _n(e, t);
772
+ }
773
+ function Sn(e, t, n, s, {
774
+ sendId: r
775
+ }) {
776
+ const i = typeof r == "function" ? r(n, s) : r;
777
+ return [t, {
778
+ sendId: i
779
+ }, void 0];
780
+ }
781
+ function bn(e, t) {
782
+ e.defer(() => {
783
+ e.system.scheduler.cancel(e.self, t.sendId);
784
+ });
785
+ }
786
+ function kt(e) {
787
+ function t(n, s) {
788
+ }
789
+ return t.type = "xstate.cancel", t.sendId = e, t.resolve = Sn, t.execute = bn, t;
790
+ }
791
+ function wn(e, t, n, s, {
792
+ id: r,
793
+ systemId: i,
794
+ src: o,
795
+ input: a,
796
+ syncSnapshot: d
797
+ }) {
798
+ const h = typeof o == "string" ? De(t.machine, o) : o, y = typeof r == "function" ? r(n) : r;
799
+ let u, c;
800
+ return h && (c = typeof a == "function" ? a({
801
+ context: t.context,
802
+ event: n.event,
803
+ self: e.self
804
+ }) : a, u = $(h, {
805
+ id: y,
806
+ src: o,
807
+ parent: e.self,
808
+ syncSnapshot: d,
809
+ systemId: i,
810
+ input: c
811
+ })), [D(t, {
812
+ children: {
813
+ ...t.children,
814
+ [y]: u
815
+ }
816
+ }), {
817
+ id: r,
818
+ systemId: i,
819
+ actorRef: u,
820
+ src: o,
821
+ input: c
822
+ }, void 0];
823
+ }
824
+ function En(e, {
825
+ actorRef: t
826
+ }) {
827
+ t && e.defer(() => {
828
+ t._processingStatus !== E.Stopped && t.start();
829
+ });
830
+ }
831
+ function It(...[e, {
832
+ id: t,
833
+ systemId: n,
834
+ input: s,
835
+ syncSnapshot: r = !1
836
+ } = {}]) {
837
+ function i(o, a) {
838
+ }
839
+ return i.type = "xstate.spawnChild", i.id = t, i.systemId = n, i.src = e, i.input = s, i.syncSnapshot = r, i.resolve = wn, i.execute = En, i;
840
+ }
841
+ function Tn(e, t, n, s, {
842
+ actorRef: r
843
+ }) {
844
+ const i = typeof r == "function" ? r(n, s) : r, o = typeof i == "string" ? t.children[i] : i;
845
+ let a = t.children;
846
+ return o && (a = {
847
+ ...a
848
+ }, delete a[o.id]), [D(t, {
849
+ children: a
850
+ }), o, void 0];
851
+ }
852
+ function xn(e, t) {
853
+ if (t) {
854
+ if (e.system._unregister(t), t._processingStatus !== E.Running) {
855
+ e.stopChild(t);
856
+ return;
857
+ }
858
+ e.defer(() => {
859
+ e.stopChild(t);
860
+ });
861
+ }
862
+ }
863
+ function F(e) {
864
+ function t(n, s) {
865
+ }
866
+ return t.type = "xstate.stopChild", t.actorRef = e, t.resolve = Tn, t.execute = xn, t;
867
+ }
868
+ function kn(e, t, {
869
+ stateValue: n
870
+ }) {
871
+ if (typeof n == "string" && ee(n)) {
872
+ const s = e.machine.getStateNodeById(n);
873
+ return e._nodes.some((r) => r === s);
874
+ }
875
+ return e.matches(n);
876
+ }
877
+ function Ns(e) {
878
+ function t() {
879
+ return !1;
880
+ }
881
+ return t.check = kn, t.stateValue = e, t;
882
+ }
883
+ function In(e, {
884
+ context: t,
885
+ event: n
886
+ }, {
887
+ guards: s
888
+ }) {
889
+ return !N(s[0], t, n, e);
890
+ }
891
+ function Xs(e) {
892
+ function t(n, s) {
893
+ return !1;
894
+ }
895
+ return t.check = In, t.guards = [e], t;
896
+ }
897
+ function An(e, {
898
+ context: t,
899
+ event: n
900
+ }, {
901
+ guards: s
902
+ }) {
903
+ return s.every((r) => N(r, t, n, e));
904
+ }
905
+ function Ys(e) {
906
+ function t(n, s) {
907
+ return !1;
908
+ }
909
+ return t.check = An, t.guards = e, t;
910
+ }
911
+ function N(e, t, n, s) {
912
+ const {
913
+ machine: r
914
+ } = s, i = typeof e == "function", o = i ? e : r.implementations.guards[typeof e == "string" ? e : e.type];
915
+ if (!i && !o)
916
+ throw new Error(`Guard '${typeof e == "string" ? e : e.type}' is not implemented.'.`);
917
+ if (typeof o != "function")
918
+ return N(o, t, n, s);
919
+ const a = {
920
+ context: t,
921
+ event: n
922
+ }, d = i || typeof e == "string" ? void 0 : "params" in e ? typeof e.params == "function" ? e.params({
923
+ context: t,
924
+ event: n
925
+ }) : e.params : void 0;
926
+ return "check" in o ? o.check(
927
+ s,
928
+ a,
929
+ o
930
+ // this holds all params
931
+ ) : o(a, d);
932
+ }
933
+ const He = (e) => e.type === "atomic" || e.type === "final";
934
+ function z(e) {
935
+ return Object.values(e.states).filter((t) => t.type !== "history");
936
+ }
937
+ function Q(e, t) {
938
+ const n = [];
939
+ if (t === e)
940
+ return n;
941
+ let s = e.parent;
942
+ for (; s && s !== t; )
943
+ n.push(s), s = s.parent;
944
+ return n;
945
+ }
946
+ function ce(e) {
947
+ const t = new Set(e), n = Ct(t);
948
+ for (const s of t)
949
+ if (s.type === "compound" && (!n.get(s) || !n.get(s).length))
950
+ Qe(s).forEach((r) => t.add(r));
951
+ else if (s.type === "parallel") {
952
+ for (const r of z(s))
953
+ if (r.type !== "history" && !t.has(r)) {
954
+ const i = Qe(r);
955
+ for (const o of i)
956
+ t.add(o);
957
+ }
958
+ }
959
+ for (const s of t) {
960
+ let r = s.parent;
961
+ for (; r; )
962
+ t.add(r), r = r.parent;
963
+ }
964
+ return t;
965
+ }
966
+ function At(e, t) {
967
+ const n = t.get(e);
968
+ if (!n)
969
+ return {};
970
+ if (e.type === "compound") {
971
+ const r = n[0];
972
+ if (r) {
973
+ if (He(r))
974
+ return r.key;
975
+ } else
976
+ return {};
977
+ }
978
+ const s = {};
979
+ for (const r of n)
980
+ s[r.key] = At(r, t);
981
+ return s;
982
+ }
983
+ function Ct(e) {
984
+ const t = /* @__PURE__ */ new Map();
985
+ for (const n of e)
986
+ t.has(n) || t.set(n, []), n.parent && (t.has(n.parent) || t.set(n.parent, []), t.get(n.parent).push(n));
987
+ return t;
988
+ }
989
+ function Rt(e, t) {
990
+ const n = ce(t);
991
+ return At(e, Ct(n));
992
+ }
993
+ function Ue(e, t) {
994
+ return t.type === "compound" ? z(t).some((n) => n.type === "final" && e.has(n)) : t.type === "parallel" ? z(t).every((n) => Ue(e, n)) : t.type === "final";
995
+ }
996
+ const ee = (e) => e[0] === cn;
997
+ function Cn(e, t) {
998
+ return e.transitions.get(t) || [...e.transitions.keys()].filter((s) => {
999
+ if (s === un)
1000
+ return !0;
1001
+ if (!s.endsWith(".*"))
1002
+ return !1;
1003
+ const r = s.split("."), i = t.split(".");
1004
+ for (let o = 0; o < r.length; o++) {
1005
+ const a = r[o], d = i[o];
1006
+ if (a === "*")
1007
+ return o === r.length - 1;
1008
+ if (a !== d)
1009
+ return !1;
1010
+ }
1011
+ return !0;
1012
+ }).sort((s, r) => r.length - s.length).flatMap((s) => e.transitions.get(s));
1013
+ }
1014
+ function Rn(e) {
1015
+ const t = e.config.after;
1016
+ if (!t)
1017
+ return [];
1018
+ const n = (r) => {
1019
+ const i = fn(r, e.id), o = i.type;
1020
+ return e.entry.push(x(i, {
1021
+ id: o,
1022
+ delay: r
1023
+ })), e.exit.push(kt(o)), o;
1024
+ };
1025
+ return Object.keys(t).flatMap((r) => {
1026
+ const i = t[r], o = typeof i == "string" ? {
1027
+ target: i
1028
+ } : i, a = Number.isNaN(+r) ? r : +r, d = n(a);
1029
+ return C(o).map((h) => ({
1030
+ ...h,
1031
+ event: d,
1032
+ delay: a
1033
+ }));
1034
+ }).map((r) => {
1035
+ const {
1036
+ delay: i
1037
+ } = r;
1038
+ return {
1039
+ ...q(e, r.event, r),
1040
+ delay: i
1041
+ };
1042
+ });
1043
+ }
1044
+ function q(e, t, n) {
1045
+ const s = xt(n.target), r = n.reenter ?? !1, i = Ln(e, s), o = {
1046
+ ...n,
1047
+ actions: C(n.actions),
1048
+ guard: n.guard,
1049
+ target: i,
1050
+ source: e,
1051
+ reenter: r,
1052
+ eventType: t,
1053
+ toJSON: () => ({
1054
+ ...o,
1055
+ source: `#${e.id}`,
1056
+ target: i ? i.map((a) => `#${a.id}`) : void 0
1057
+ })
1058
+ };
1059
+ return o;
1060
+ }
1061
+ function Mn(e) {
1062
+ const t = /* @__PURE__ */ new Map();
1063
+ if (e.config.on)
1064
+ for (const n of Object.keys(e.config.on)) {
1065
+ if (n === vt)
1066
+ throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');
1067
+ const s = e.config.on[n];
1068
+ t.set(n, U(s).map((r) => q(e, n, r)));
1069
+ }
1070
+ if (e.config.onDone) {
1071
+ const n = `xstate.done.state.${e.id}`;
1072
+ t.set(n, U(e.config.onDone).map((s) => q(e, n, s)));
1073
+ }
1074
+ for (const n of e.invoke) {
1075
+ if (n.onDone) {
1076
+ const s = `xstate.done.actor.${n.id}`;
1077
+ t.set(s, U(n.onDone).map((r) => q(e, s, r)));
1078
+ }
1079
+ if (n.onError) {
1080
+ const s = `xstate.error.actor.${n.id}`;
1081
+ t.set(s, U(n.onError).map((r) => q(e, s, r)));
1082
+ }
1083
+ if (n.onSnapshot) {
1084
+ const s = `xstate.snapshot.${n.id}`;
1085
+ t.set(s, U(n.onSnapshot).map((r) => q(e, s, r)));
1086
+ }
1087
+ }
1088
+ for (const n of e.after) {
1089
+ let s = t.get(n.eventType);
1090
+ s || (s = [], t.set(n.eventType, s)), s.push(n);
1091
+ }
1092
+ return t;
1093
+ }
1094
+ function $n(e, t) {
1095
+ const n = typeof t == "string" ? e.states[t] : t ? e.states[t.target] : void 0;
1096
+ if (!n && t)
1097
+ throw new Error(
1098
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
1099
+ `Initial state node "${t}" not found on parent state node #${e.id}`
1100
+ );
1101
+ const s = {
1102
+ source: e,
1103
+ actions: !t || typeof t == "string" ? [] : C(t.actions),
1104
+ eventType: null,
1105
+ reenter: !1,
1106
+ target: n ? [n] : [],
1107
+ toJSON: () => ({
1108
+ ...s,
1109
+ source: `#${e.id}`,
1110
+ target: n ? [`#${n.id}`] : []
1111
+ })
1112
+ };
1113
+ return s;
1114
+ }
1115
+ function Ln(e, t) {
1116
+ if (t !== void 0)
1117
+ return t.map((n) => {
1118
+ if (typeof n != "string")
1119
+ return n;
1120
+ if (ee(n))
1121
+ return e.machine.getStateNodeById(n);
1122
+ const s = n[0] === mt;
1123
+ if (s && !e.parent)
1124
+ return ue(e, n.slice(1));
1125
+ const r = s ? e.key + n : n;
1126
+ if (e.parent)
1127
+ try {
1128
+ return ue(e.parent, r);
1129
+ } catch (i) {
1130
+ throw new Error(`Invalid transition definition for state node '${e.id}':
1131
+ ${i.message}`);
1132
+ }
1133
+ else
1134
+ throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`);
1135
+ });
1136
+ }
1137
+ function Mt(e) {
1138
+ const t = xt(e.config.target);
1139
+ return t ? {
1140
+ target: t.map((n) => typeof n == "string" ? ue(e.parent, n) : n)
1141
+ } : e.parent.initial;
1142
+ }
1143
+ function O(e) {
1144
+ return e.type === "history";
1145
+ }
1146
+ function Qe(e) {
1147
+ const t = $t(e);
1148
+ for (const n of t)
1149
+ for (const s of Q(n, e))
1150
+ t.add(s);
1151
+ return t;
1152
+ }
1153
+ function $t(e) {
1154
+ const t = /* @__PURE__ */ new Set();
1155
+ function n(s) {
1156
+ if (!t.has(s)) {
1157
+ if (t.add(s), s.type === "compound")
1158
+ n(s.initial.target[0]);
1159
+ else if (s.type === "parallel")
1160
+ for (const r of z(s))
1161
+ n(r);
1162
+ }
1163
+ }
1164
+ return n(e), t;
1165
+ }
1166
+ function G(e, t) {
1167
+ if (ee(t))
1168
+ return e.machine.getStateNodeById(t);
1169
+ if (!e.states)
1170
+ throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);
1171
+ const n = e.states[t];
1172
+ if (!n)
1173
+ throw new Error(`Child state '${t}' does not exist on '${e.id}'`);
1174
+ return n;
1175
+ }
1176
+ function ue(e, t) {
1177
+ if (typeof t == "string" && ee(t))
1178
+ try {
1179
+ return e.machine.getStateNodeById(t);
1180
+ } catch {
1181
+ }
1182
+ const n = je(t).slice();
1183
+ let s = e;
1184
+ for (; n.length; ) {
1185
+ const r = n.shift();
1186
+ if (!r.length)
1187
+ break;
1188
+ s = G(s, r);
1189
+ }
1190
+ return s;
1191
+ }
1192
+ function de(e, t) {
1193
+ if (typeof t == "string") {
1194
+ const r = e.states[t];
1195
+ if (!r)
1196
+ throw new Error(`State '${t}' does not exist on '${e.id}'`);
1197
+ return [e, r];
1198
+ }
1199
+ const n = Object.keys(t), s = n.map((r) => G(e, r)).filter(Boolean);
1200
+ return [e.machine.root, e].concat(s, n.reduce((r, i) => {
1201
+ const o = G(e, i);
1202
+ if (!o)
1203
+ return r;
1204
+ const a = de(o, t[i]);
1205
+ return r.concat(a);
1206
+ }, []));
1207
+ }
1208
+ function qn(e, t, n, s) {
1209
+ const i = G(e, t).next(n, s);
1210
+ return !i || !i.length ? e.next(n, s) : i;
1211
+ }
1212
+ function On(e, t, n, s) {
1213
+ const r = Object.keys(t), i = G(e, r[0]), o = We(i, t[r[0]], n, s);
1214
+ return !o || !o.length ? e.next(n, s) : o;
1215
+ }
1216
+ function jn(e, t, n, s) {
1217
+ const r = [];
1218
+ for (const i of Object.keys(t)) {
1219
+ const o = t[i];
1220
+ if (!o)
1221
+ continue;
1222
+ const a = G(e, i), d = We(a, o, n, s);
1223
+ d && r.push(...d);
1224
+ }
1225
+ return r.length ? r : e.next(n, s);
1226
+ }
1227
+ function We(e, t, n, s) {
1228
+ return typeof t == "string" ? qn(e, t, n, s) : Object.keys(t).length === 1 ? On(e, t, n, s) : jn(e, t, n, s);
1229
+ }
1230
+ function Dn(e) {
1231
+ return Object.keys(e.states).map((t) => e.states[t]).filter((t) => t.type === "history");
1232
+ }
1233
+ function L(e, t) {
1234
+ let n = e;
1235
+ for (; n.parent && n.parent !== t; )
1236
+ n = n.parent;
1237
+ return n.parent === t;
1238
+ }
1239
+ function Vn(e, t) {
1240
+ const n = new Set(e), s = new Set(t);
1241
+ for (const r of n)
1242
+ if (s.has(r))
1243
+ return !0;
1244
+ for (const r of s)
1245
+ if (n.has(r))
1246
+ return !0;
1247
+ return !1;
1248
+ }
1249
+ function Lt(e, t, n) {
1250
+ const s = /* @__PURE__ */ new Set();
1251
+ for (const r of e) {
1252
+ let i = !1;
1253
+ const o = /* @__PURE__ */ new Set();
1254
+ for (const a of s)
1255
+ if (Vn($e([r], t, n), $e([a], t, n)))
1256
+ if (L(r.source, a.source))
1257
+ o.add(a);
1258
+ else {
1259
+ i = !0;
1260
+ break;
1261
+ }
1262
+ if (!i) {
1263
+ for (const a of o)
1264
+ s.delete(a);
1265
+ s.add(r);
1266
+ }
1267
+ }
1268
+ return Array.from(s);
1269
+ }
1270
+ function Hn(e) {
1271
+ const [t, ...n] = e;
1272
+ for (const s of Q(t, void 0))
1273
+ if (n.every((r) => L(r, s)))
1274
+ return s;
1275
+ }
1276
+ function Be(e, t) {
1277
+ if (!e.target)
1278
+ return [];
1279
+ const n = /* @__PURE__ */ new Set();
1280
+ for (const s of e.target)
1281
+ if (O(s))
1282
+ if (t[s.id])
1283
+ for (const r of t[s.id])
1284
+ n.add(r);
1285
+ else
1286
+ for (const r of Be(Mt(s), t))
1287
+ n.add(r);
1288
+ else
1289
+ n.add(s);
1290
+ return [...n];
1291
+ }
1292
+ function qt(e, t) {
1293
+ const n = Be(e, t);
1294
+ if (!n)
1295
+ return;
1296
+ if (!e.reenter && n.every((r) => r === e.source || L(r, e.source)))
1297
+ return e.source;
1298
+ const s = Hn(n.concat(e.source));
1299
+ if (s)
1300
+ return s;
1301
+ if (!e.reenter)
1302
+ return e.source.machine.root;
1303
+ }
1304
+ function $e(e, t, n) {
1305
+ var r;
1306
+ const s = /* @__PURE__ */ new Set();
1307
+ for (const i of e)
1308
+ if ((r = i.target) != null && r.length) {
1309
+ const o = qt(i, n);
1310
+ i.reenter && i.source === o && s.add(o);
1311
+ for (const a of t)
1312
+ L(a, o) && s.add(a);
1313
+ }
1314
+ return [...s];
1315
+ }
1316
+ function Un(e, t) {
1317
+ if (e.length !== t.size)
1318
+ return !1;
1319
+ for (const n of e)
1320
+ if (!t.has(n))
1321
+ return !1;
1322
+ return !0;
1323
+ }
1324
+ function Le(e, t, n, s, r, i) {
1325
+ if (!e.length)
1326
+ return t;
1327
+ const o = new Set(t._nodes);
1328
+ let a = t.historyValue;
1329
+ const d = Lt(e, o, a);
1330
+ let h = t;
1331
+ r || ([h, a] = zn(h, s, n, d, o, a, i, n.actionExecutor)), h = J(h, s, n, d.flatMap((u) => u.actions), i, void 0), h = Bn(h, s, n, d, o, i, a, r);
1332
+ const y = [...o];
1333
+ h.status === "done" && (h = J(h, s, n, y.sort((u, c) => c.order - u.order).flatMap((u) => u.exit), i, void 0));
1334
+ try {
1335
+ return a === t.historyValue && Un(t._nodes, o) ? h : D(h, {
1336
+ _nodes: y,
1337
+ historyValue: a
1338
+ });
1339
+ } catch (u) {
1340
+ throw u;
1341
+ }
1342
+ }
1343
+ function Wn(e, t, n, s, r) {
1344
+ if (s.output === void 0)
1345
+ return;
1346
+ const i = Re(r.id, r.output !== void 0 && r.parent ? Me(r.output, e.context, t, n.self) : void 0);
1347
+ return Me(s.output, e.context, i, n.self);
1348
+ }
1349
+ function Bn(e, t, n, s, r, i, o, a) {
1350
+ let d = e;
1351
+ const h = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Set();
1352
+ Pn(s, o, y, h), a && y.add(e.machine.root);
1353
+ const u = /* @__PURE__ */ new Set();
1354
+ for (const c of [...h].sort((l, f) => l.order - f.order)) {
1355
+ r.add(c);
1356
+ const l = [];
1357
+ l.push(...c.entry);
1358
+ for (const f of c.invoke)
1359
+ l.push(It(f.src, {
1360
+ ...f,
1361
+ syncSnapshot: !!f.onSnapshot
1362
+ }));
1363
+ if (y.has(c)) {
1364
+ const f = c.initial.actions;
1365
+ l.push(...f);
1366
+ }
1367
+ if (d = J(d, t, n, l, i, c.invoke.map((f) => f.id)), c.type === "final") {
1368
+ const f = c.parent;
1369
+ let p = (f == null ? void 0 : f.type) === "parallel" ? f : f == null ? void 0 : f.parent, g = p || c;
1370
+ for ((f == null ? void 0 : f.type) === "compound" && i.push(Re(f.id, c.output !== void 0 ? Me(c.output, d.context, t, n.self) : void 0)); (p == null ? void 0 : p.type) === "parallel" && !u.has(p) && Ue(r, p); )
1371
+ u.add(p), i.push(Re(p.id)), g = p, p = p.parent;
1372
+ if (p)
1373
+ continue;
1374
+ d = D(d, {
1375
+ status: "done",
1376
+ output: Wn(d, t, n, d.machine.root, g)
1377
+ });
1378
+ }
1379
+ }
1380
+ return d;
1381
+ }
1382
+ function Pn(e, t, n, s) {
1383
+ for (const r of e) {
1384
+ const i = qt(r, t);
1385
+ for (const a of r.target || [])
1386
+ !O(a) && // if the target is different than the source then it will *definitely* be entered
1387
+ (r.source !== a || // we know that the domain can't lie within the source
1388
+ // if it's different than the source then it's outside of it and it means that the target has to be entered as well
1389
+ r.source !== i || // reentering transitions always enter the target, even if it's the source itself
1390
+ r.reenter) && (s.add(a), n.add(a)), W(a, t, n, s);
1391
+ const o = Be(r, t);
1392
+ for (const a of o) {
1393
+ const d = Q(a, i);
1394
+ (i == null ? void 0 : i.type) === "parallel" && d.push(i), Ot(s, t, n, d, !r.source.parent && r.reenter ? void 0 : i);
1395
+ }
1396
+ }
1397
+ }
1398
+ function W(e, t, n, s) {
1399
+ var r;
1400
+ if (O(e))
1401
+ if (t[e.id]) {
1402
+ const i = t[e.id];
1403
+ for (const o of i)
1404
+ s.add(o), W(o, t, n, s);
1405
+ for (const o of i)
1406
+ ve(o, e.parent, s, t, n);
1407
+ } else {
1408
+ const i = Mt(e);
1409
+ for (const o of i.target)
1410
+ s.add(o), i === ((r = e.parent) == null ? void 0 : r.initial) && n.add(e.parent), W(o, t, n, s);
1411
+ for (const o of i.target)
1412
+ ve(o, e.parent, s, t, n);
1413
+ }
1414
+ else if (e.type === "compound") {
1415
+ const [i] = e.initial.target;
1416
+ O(i) || (s.add(i), n.add(i)), W(i, t, n, s), ve(i, e, s, t, n);
1417
+ } else if (e.type === "parallel")
1418
+ for (const i of z(e).filter((o) => !O(o)))
1419
+ [...s].some((o) => L(o, i)) || (O(i) || (s.add(i), n.add(i)), W(i, t, n, s));
1420
+ }
1421
+ function Ot(e, t, n, s, r) {
1422
+ for (const i of s)
1423
+ if ((!r || L(i, r)) && e.add(i), i.type === "parallel")
1424
+ for (const o of z(i).filter((a) => !O(a)))
1425
+ [...e].some((a) => L(a, o)) || (e.add(o), W(o, t, n, e));
1426
+ }
1427
+ function ve(e, t, n, s, r) {
1428
+ Ot(n, s, r, Q(e, t));
1429
+ }
1430
+ function zn(e, t, n, s, r, i, o, a) {
1431
+ let d = e;
1432
+ const h = $e(s, r, i);
1433
+ h.sort((u, c) => c.order - u.order);
1434
+ let y;
1435
+ for (const u of h)
1436
+ for (const c of Dn(u)) {
1437
+ let l;
1438
+ c.history === "deep" ? l = (f) => He(f) && L(f, u) : l = (f) => f.parent === u, y ?? (y = {
1439
+ ...i
1440
+ }), y[c.id] = Array.from(r).filter(l);
1441
+ }
1442
+ for (const u of h)
1443
+ d = J(d, t, n, [...u.exit, ...u.invoke.map((c) => F(c.id))], o, void 0), r.delete(u);
1444
+ return [d, y || i];
1445
+ }
1446
+ function Gn(e, t) {
1447
+ return e.implementations.actions[t];
1448
+ }
1449
+ function jt(e, t, n, s, r, i) {
1450
+ const {
1451
+ machine: o
1452
+ } = e;
1453
+ let a = e;
1454
+ for (const d of s) {
1455
+ const h = typeof d == "function", y = h ? d : (
1456
+ // the existing type of `.actions` assumes non-nullable `TExpressionAction`
1457
+ // it's fine to cast this here to get a common type and lack of errors in the rest of the code
1458
+ // our logic below makes sure that we call those 2 "variants" correctly
1459
+ Gn(o, typeof d == "string" ? d : d.type)
1460
+ ), u = {
1461
+ context: a.context,
1462
+ event: t,
1463
+ self: n.self,
1464
+ system: n.system
1465
+ }, c = h || typeof d == "string" ? void 0 : "params" in d ? typeof d.params == "function" ? d.params({
1466
+ context: a.context,
1467
+ event: t
1468
+ }) : d.params : void 0;
1469
+ if (!y || !("resolve" in y)) {
1470
+ n.actionExecutor({
1471
+ type: typeof d == "string" ? d : typeof d == "object" ? d.type : d.name || "(anonymous)",
1472
+ info: u,
1473
+ params: c,
1474
+ exec: y
1475
+ });
1476
+ continue;
1477
+ }
1478
+ const l = y, [f, p, g] = l.resolve(
1479
+ n,
1480
+ a,
1481
+ u,
1482
+ c,
1483
+ y,
1484
+ // this holds all params
1485
+ r
1486
+ );
1487
+ a = f, "retryResolve" in l && (i == null || i.push([l, p])), "execute" in l && n.actionExecutor({
1488
+ type: l.type,
1489
+ info: u,
1490
+ params: p,
1491
+ exec: l.execute.bind(null, n, p)
1492
+ }), g && (a = jt(a, t, n, g, r, i));
1493
+ }
1494
+ return a;
1495
+ }
1496
+ function J(e, t, n, s, r, i) {
1497
+ const o = i ? [] : void 0, a = jt(e, t, n, s, {
1498
+ internalQueue: r,
1499
+ deferredActorIds: i
1500
+ }, o);
1501
+ return o == null || o.forEach(([d, h]) => {
1502
+ d.retryResolve(n, a, h);
1503
+ }), a;
1504
+ }
1505
+ function _e(e, t, n, s) {
1506
+ let r = e;
1507
+ const i = [];
1508
+ function o(h, y, u) {
1509
+ n.system._sendInspectionEvent({
1510
+ type: "@xstate.microstep",
1511
+ actorRef: n.self,
1512
+ event: y,
1513
+ snapshot: h,
1514
+ _transitions: u
1515
+ }), i.push(h);
1516
+ }
1517
+ if (t.type === j)
1518
+ return r = D(et(r, t, n), {
1519
+ status: "stopped"
1520
+ }), o(r, t, []), {
1521
+ snapshot: r,
1522
+ microstates: i
1523
+ };
1524
+ let a = t;
1525
+ if (a.type !== _t) {
1526
+ const h = a, y = yn(h), u = tt(h, r);
1527
+ if (y && !u.length)
1528
+ return r = D(e, {
1529
+ status: "error",
1530
+ error: h.error
1531
+ }), o(r, h, []), {
1532
+ snapshot: r,
1533
+ microstates: i
1534
+ };
1535
+ r = Le(
1536
+ u,
1537
+ e,
1538
+ n,
1539
+ a,
1540
+ !1,
1541
+ // isInitial
1542
+ s
1543
+ ), o(r, h, u);
1544
+ }
1545
+ let d = !0;
1546
+ for (; r.status === "active"; ) {
1547
+ let h = d ? Jn(r, a) : [];
1548
+ const y = h.length ? r : void 0;
1549
+ if (!h.length) {
1550
+ if (!s.length)
1551
+ break;
1552
+ a = s.shift(), h = tt(a, r);
1553
+ }
1554
+ r = Le(h, r, n, a, !1, s), d = r !== y, o(r, a, h);
1555
+ }
1556
+ return r.status !== "active" && et(r, a, n), {
1557
+ snapshot: r,
1558
+ microstates: i
1559
+ };
1560
+ }
1561
+ function et(e, t, n) {
1562
+ return J(e, t, n, Object.values(e.children).map((s) => F(s)), [], void 0);
1563
+ }
1564
+ function tt(e, t) {
1565
+ return t.machine.getTransitionData(t, e);
1566
+ }
1567
+ function Jn(e, t) {
1568
+ const n = /* @__PURE__ */ new Set(), s = e._nodes.filter(He);
1569
+ for (const r of s)
1570
+ e: for (const i of [r].concat(Q(r, void 0)))
1571
+ if (i.always) {
1572
+ for (const o of i.always)
1573
+ if (o.guard === void 0 || N(o.guard, e.context, t, e)) {
1574
+ n.add(o);
1575
+ break e;
1576
+ }
1577
+ }
1578
+ return Lt(Array.from(n), new Set(e._nodes), e.historyValue);
1579
+ }
1580
+ function Nn(e, t) {
1581
+ const n = ce(de(e, t));
1582
+ return Rt(e, [...n]);
1583
+ }
1584
+ function Xn(e) {
1585
+ return !!e && typeof e == "object" && "machine" in e && "value" in e;
1586
+ }
1587
+ const Yn = function(t) {
1588
+ return wt(t, this.value);
1589
+ }, Kn = function(t) {
1590
+ return this.tags.has(t);
1591
+ }, Zn = function(t) {
1592
+ const n = this.machine.getTransitionData(this, t);
1593
+ return !!(n != null && n.length) && // Check that at least one transition is not forbidden
1594
+ n.some((s) => s.target !== void 0 || s.actions.length);
1595
+ }, Fn = function() {
1596
+ const {
1597
+ _nodes: t,
1598
+ tags: n,
1599
+ machine: s,
1600
+ getMeta: r,
1601
+ toJSON: i,
1602
+ can: o,
1603
+ hasTag: a,
1604
+ matches: d,
1605
+ ...h
1606
+ } = this;
1607
+ return {
1608
+ ...h,
1609
+ tags: Array.from(n)
1610
+ };
1611
+ }, Qn = function() {
1612
+ return this._nodes.reduce((t, n) => (n.meta !== void 0 && (t[n.id] = n.meta), t), {});
1613
+ };
1614
+ function se(e, t) {
1615
+ return {
1616
+ status: e.status,
1617
+ output: e.output,
1618
+ error: e.error,
1619
+ machine: t,
1620
+ context: e.context,
1621
+ _nodes: e._nodes,
1622
+ value: Rt(t.root, e._nodes),
1623
+ tags: new Set(e._nodes.flatMap((n) => n.tags)),
1624
+ children: e.children,
1625
+ historyValue: e.historyValue || {},
1626
+ matches: Yn,
1627
+ hasTag: Kn,
1628
+ can: Zn,
1629
+ getMeta: Qn,
1630
+ toJSON: Fn
1631
+ };
1632
+ }
1633
+ function D(e, t = {}) {
1634
+ return se({
1635
+ ...e,
1636
+ ...t
1637
+ }, e.machine);
1638
+ }
1639
+ function es(e) {
1640
+ if (typeof e != "object" || e === null)
1641
+ return {};
1642
+ const t = {};
1643
+ for (const n in e) {
1644
+ const s = e[n];
1645
+ Array.isArray(s) && (t[n] = s.map((r) => ({
1646
+ id: r.id
1647
+ })));
1648
+ }
1649
+ return t;
1650
+ }
1651
+ function ts(e, t) {
1652
+ const {
1653
+ _nodes: n,
1654
+ tags: s,
1655
+ machine: r,
1656
+ children: i,
1657
+ context: o,
1658
+ can: a,
1659
+ hasTag: d,
1660
+ matches: h,
1661
+ getMeta: y,
1662
+ toJSON: u,
1663
+ ...c
1664
+ } = e, l = {};
1665
+ for (const p in i) {
1666
+ const g = i[p];
1667
+ l[p] = {
1668
+ snapshot: g.getPersistedSnapshot(t),
1669
+ src: g.src,
1670
+ systemId: g._systemId,
1671
+ syncSnapshot: g._syncSnapshot
1672
+ };
1673
+ }
1674
+ return {
1675
+ ...c,
1676
+ context: Dt(o),
1677
+ children: l,
1678
+ historyValue: es(c.historyValue)
1679
+ };
1680
+ }
1681
+ function Dt(e) {
1682
+ let t;
1683
+ for (const n in e) {
1684
+ const s = e[n];
1685
+ if (s && typeof s == "object")
1686
+ if ("sessionId" in s && "send" in s && "ref" in s)
1687
+ t ?? (t = Array.isArray(e) ? e.slice() : {
1688
+ ...e
1689
+ }), t[n] = {
1690
+ xstate$$type: Ve,
1691
+ id: s.id
1692
+ };
1693
+ else {
1694
+ const r = Dt(s);
1695
+ r !== s && (t ?? (t = Array.isArray(e) ? e.slice() : {
1696
+ ...e
1697
+ }), t[n] = r);
1698
+ }
1699
+ }
1700
+ return t ?? e;
1701
+ }
1702
+ function ns(e, t, n, s, {
1703
+ event: r,
1704
+ id: i,
1705
+ delay: o
1706
+ }, {
1707
+ internalQueue: a
1708
+ }) {
1709
+ const d = t.machine.implementations.delays;
1710
+ if (typeof r == "string")
1711
+ throw new Error(
1712
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1713
+ `Only event objects may be used with raise; use raise({ type: "${r}" }) instead`
1714
+ );
1715
+ const h = typeof r == "function" ? r(n, s) : r;
1716
+ let y;
1717
+ if (typeof o == "string") {
1718
+ const u = d && d[o];
1719
+ y = typeof u == "function" ? u(n, s) : u;
1720
+ } else
1721
+ y = typeof o == "function" ? o(n, s) : o;
1722
+ return typeof y != "number" && a.push(h), [t, {
1723
+ event: h,
1724
+ id: i,
1725
+ delay: y
1726
+ }, void 0];
1727
+ }
1728
+ function ss(e, t) {
1729
+ const {
1730
+ event: n,
1731
+ delay: s,
1732
+ id: r
1733
+ } = t;
1734
+ if (typeof s == "number") {
1735
+ e.defer(() => {
1736
+ const i = e.self;
1737
+ e.system.scheduler.schedule(i, i, n, s, r);
1738
+ });
1739
+ return;
1740
+ }
1741
+ }
1742
+ function x(e, t) {
1743
+ function n(s, r) {
1744
+ }
1745
+ return n.type = "xstate.raise", n.event = e, n.id = t == null ? void 0 : t.id, n.delay = t == null ? void 0 : t.delay, n.resolve = ns, n.execute = ss, n;
1746
+ }
1747
+ const nt = /* @__PURE__ */ new WeakMap();
1748
+ function rs(e) {
1749
+ return {
1750
+ config: e,
1751
+ start: (n, s) => {
1752
+ const {
1753
+ self: r,
1754
+ system: i,
1755
+ emit: o
1756
+ } = s, a = {
1757
+ receivers: void 0,
1758
+ dispose: void 0
1759
+ };
1760
+ nt.set(r, a), a.dispose = e({
1761
+ input: n.input,
1762
+ system: i,
1763
+ self: r,
1764
+ sendBack: (d) => {
1765
+ r.getSnapshot().status !== "stopped" && r._parent && i._relay(r, r._parent, d);
1766
+ },
1767
+ receive: (d) => {
1768
+ a.receivers ?? (a.receivers = /* @__PURE__ */ new Set()), a.receivers.add(d);
1769
+ },
1770
+ emit: o
1771
+ });
1772
+ },
1773
+ transition: (n, s, r) => {
1774
+ var o, a;
1775
+ const i = nt.get(r.self);
1776
+ return s.type === j ? (n = {
1777
+ ...n,
1778
+ status: "stopped",
1779
+ error: void 0
1780
+ }, (o = i.dispose) == null || o.call(i), n) : ((a = i.receivers) == null || a.forEach((d) => d(s)), n);
1781
+ },
1782
+ getInitialSnapshot: (n, s) => ({
1783
+ status: "active",
1784
+ output: void 0,
1785
+ error: void 0,
1786
+ input: s
1787
+ }),
1788
+ getPersistedSnapshot: (n) => n,
1789
+ restoreSnapshot: (n) => n
1790
+ };
1791
+ }
1792
+ const st = "xstate.observable.next", fe = "xstate.observable.error", he = "xstate.observable.complete";
1793
+ function Ks(e) {
1794
+ return {
1795
+ config: e,
1796
+ transition: (n, s) => {
1797
+ if (n.status !== "active")
1798
+ return n;
1799
+ switch (s.type) {
1800
+ case st:
1801
+ return {
1802
+ ...n,
1803
+ context: s.data
1804
+ };
1805
+ case fe:
1806
+ return {
1807
+ ...n,
1808
+ status: "error",
1809
+ error: s.data,
1810
+ input: void 0,
1811
+ _subscription: void 0
1812
+ };
1813
+ case he:
1814
+ return {
1815
+ ...n,
1816
+ status: "done",
1817
+ input: void 0,
1818
+ _subscription: void 0
1819
+ };
1820
+ case j:
1821
+ return n._subscription.unsubscribe(), {
1822
+ ...n,
1823
+ status: "stopped",
1824
+ input: void 0,
1825
+ _subscription: void 0
1826
+ };
1827
+ default:
1828
+ return n;
1829
+ }
1830
+ },
1831
+ getInitialSnapshot: (n, s) => ({
1832
+ status: "active",
1833
+ output: void 0,
1834
+ error: void 0,
1835
+ context: void 0,
1836
+ input: s,
1837
+ _subscription: void 0
1838
+ }),
1839
+ start: (n, {
1840
+ self: s,
1841
+ system: r,
1842
+ emit: i
1843
+ }) => {
1844
+ n.status !== "done" && (n._subscription = e({
1845
+ input: n.input,
1846
+ system: r,
1847
+ self: s,
1848
+ emit: i
1849
+ }).subscribe({
1850
+ next: (o) => {
1851
+ r._relay(s, s, {
1852
+ type: st,
1853
+ data: o
1854
+ });
1855
+ },
1856
+ error: (o) => {
1857
+ r._relay(s, s, {
1858
+ type: fe,
1859
+ data: o
1860
+ });
1861
+ },
1862
+ complete: () => {
1863
+ r._relay(s, s, {
1864
+ type: he
1865
+ });
1866
+ }
1867
+ }));
1868
+ },
1869
+ getPersistedSnapshot: ({
1870
+ _subscription: n,
1871
+ ...s
1872
+ }) => s,
1873
+ restoreSnapshot: (n) => ({
1874
+ ...n,
1875
+ _subscription: void 0
1876
+ })
1877
+ };
1878
+ }
1879
+ function Vt(e) {
1880
+ return {
1881
+ config: e,
1882
+ transition: (n, s) => {
1883
+ if (n.status !== "active")
1884
+ return n;
1885
+ switch (s.type) {
1886
+ case fe:
1887
+ return {
1888
+ ...n,
1889
+ status: "error",
1890
+ error: s.data,
1891
+ input: void 0,
1892
+ _subscription: void 0
1893
+ };
1894
+ case he:
1895
+ return {
1896
+ ...n,
1897
+ status: "done",
1898
+ input: void 0,
1899
+ _subscription: void 0
1900
+ };
1901
+ case j:
1902
+ return n._subscription.unsubscribe(), {
1903
+ ...n,
1904
+ status: "stopped",
1905
+ input: void 0,
1906
+ _subscription: void 0
1907
+ };
1908
+ default:
1909
+ return n;
1910
+ }
1911
+ },
1912
+ getInitialSnapshot: (n, s) => ({
1913
+ status: "active",
1914
+ output: void 0,
1915
+ error: void 0,
1916
+ context: void 0,
1917
+ input: s,
1918
+ _subscription: void 0
1919
+ }),
1920
+ start: (n, {
1921
+ self: s,
1922
+ system: r,
1923
+ emit: i
1924
+ }) => {
1925
+ n.status !== "done" && (n._subscription = e({
1926
+ input: n.input,
1927
+ system: r,
1928
+ self: s,
1929
+ emit: i
1930
+ }).subscribe({
1931
+ next: (o) => {
1932
+ s._parent && r._relay(s, s._parent, o);
1933
+ },
1934
+ error: (o) => {
1935
+ r._relay(s, s, {
1936
+ type: fe,
1937
+ data: o
1938
+ });
1939
+ },
1940
+ complete: () => {
1941
+ r._relay(s, s, {
1942
+ type: he
1943
+ });
1944
+ }
1945
+ }));
1946
+ },
1947
+ getPersistedSnapshot: ({
1948
+ _subscription: n,
1949
+ ...s
1950
+ }) => s,
1951
+ restoreSnapshot: (n) => ({
1952
+ ...n,
1953
+ _subscription: void 0
1954
+ })
1955
+ };
1956
+ }
1957
+ const rt = "xstate.promise.resolve", it = "xstate.promise.reject", ne = /* @__PURE__ */ new WeakMap();
1958
+ function Zs(e) {
1959
+ return {
1960
+ config: e,
1961
+ transition: (n, s, r) => {
1962
+ var i;
1963
+ if (n.status !== "active")
1964
+ return n;
1965
+ switch (s.type) {
1966
+ case rt: {
1967
+ const o = s.data;
1968
+ return {
1969
+ ...n,
1970
+ status: "done",
1971
+ output: o,
1972
+ input: void 0
1973
+ };
1974
+ }
1975
+ case it:
1976
+ return {
1977
+ ...n,
1978
+ status: "error",
1979
+ error: s.data,
1980
+ input: void 0
1981
+ };
1982
+ case j:
1983
+ return (i = ne.get(r.self)) == null || i.abort(), {
1984
+ ...n,
1985
+ status: "stopped",
1986
+ input: void 0
1987
+ };
1988
+ default:
1989
+ return n;
1990
+ }
1991
+ },
1992
+ start: (n, {
1993
+ self: s,
1994
+ system: r,
1995
+ emit: i
1996
+ }) => {
1997
+ if (n.status !== "active")
1998
+ return;
1999
+ const o = new AbortController();
2000
+ ne.set(s, o), Promise.resolve(e({
2001
+ input: n.input,
2002
+ system: r,
2003
+ self: s,
2004
+ signal: o.signal,
2005
+ emit: i
2006
+ })).then((d) => {
2007
+ s.getSnapshot().status === "active" && (ne.delete(s), r._relay(s, s, {
2008
+ type: rt,
2009
+ data: d
2010
+ }));
2011
+ }, (d) => {
2012
+ s.getSnapshot().status === "active" && (ne.delete(s), r._relay(s, s, {
2013
+ type: it,
2014
+ data: d
2015
+ }));
2016
+ });
2017
+ },
2018
+ getInitialSnapshot: (n, s) => ({
2019
+ status: "active",
2020
+ output: void 0,
2021
+ error: void 0,
2022
+ input: s
2023
+ }),
2024
+ getPersistedSnapshot: (n) => n,
2025
+ restoreSnapshot: (n) => n
2026
+ };
2027
+ }
2028
+ function is(e, {
2029
+ machine: t,
2030
+ context: n
2031
+ }, s, r) {
2032
+ const i = (o, a) => {
2033
+ if (typeof o == "string") {
2034
+ const d = De(t, o);
2035
+ if (!d)
2036
+ throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);
2037
+ const h = $(d, {
2038
+ id: a == null ? void 0 : a.id,
2039
+ parent: e.self,
2040
+ syncSnapshot: a == null ? void 0 : a.syncSnapshot,
2041
+ input: typeof (a == null ? void 0 : a.input) == "function" ? a.input({
2042
+ context: n,
2043
+ event: s,
2044
+ self: e.self
2045
+ }) : a == null ? void 0 : a.input,
2046
+ src: o,
2047
+ systemId: a == null ? void 0 : a.systemId
2048
+ });
2049
+ return r[h.id] = h, h;
2050
+ } else
2051
+ return $(o, {
2052
+ id: a == null ? void 0 : a.id,
2053
+ parent: e.self,
2054
+ syncSnapshot: a == null ? void 0 : a.syncSnapshot,
2055
+ input: a == null ? void 0 : a.input,
2056
+ src: o,
2057
+ systemId: a == null ? void 0 : a.systemId
2058
+ });
2059
+ };
2060
+ return (o, a) => {
2061
+ const d = i(o, a);
2062
+ return r[d.id] = d, e.defer(() => {
2063
+ d._processingStatus !== E.Stopped && d.start();
2064
+ }), d;
2065
+ };
2066
+ }
2067
+ function os(e, t, n, s, {
2068
+ assignment: r
2069
+ }) {
2070
+ if (!t.context)
2071
+ throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");
2072
+ const i = {}, o = {
2073
+ context: t.context,
2074
+ event: n.event,
2075
+ spawn: is(e, t, n.event, i),
2076
+ self: e.self,
2077
+ system: e.system
2078
+ };
2079
+ let a = {};
2080
+ if (typeof r == "function")
2081
+ a = r(o, s);
2082
+ else
2083
+ for (const h of Object.keys(r)) {
2084
+ const y = r[h];
2085
+ a[h] = typeof y == "function" ? y(o, s) : y;
2086
+ }
2087
+ const d = Object.assign({}, t.context, a);
2088
+ return [D(t, {
2089
+ context: d,
2090
+ children: Object.keys(i).length ? {
2091
+ ...t.children,
2092
+ ...i
2093
+ } : t.children
2094
+ }), void 0, void 0];
2095
+ }
2096
+ function M(e) {
2097
+ function t(n, s) {
2098
+ }
2099
+ return t.type = "xstate.assign", t.assignment = e, t.resolve = os, t;
2100
+ }
2101
+ const ot = /* @__PURE__ */ new WeakMap();
2102
+ function H(e, t, n) {
2103
+ let s = ot.get(e);
2104
+ return s ? t in s || (s[t] = n()) : (s = {
2105
+ [t]: n()
2106
+ }, ot.set(e, s)), s[t];
2107
+ }
2108
+ const as = {}, X = (e) => typeof e == "string" ? {
2109
+ type: e
2110
+ } : typeof e == "function" ? "resolve" in e ? {
2111
+ type: e.type
2112
+ } : {
2113
+ type: e.name
2114
+ } : e;
2115
+ class le {
2116
+ constructor(t, n) {
2117
+ if (this.config = t, 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 = n._parent, this.key = n._key, this.machine = n._machine, this.path = this.parent ? this.parent.path.concat(this.key) : [], this.id = this.config.id || [this.machine.id, ...this.path].join(mt), 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 ? Ke(this.config.states, (s, r) => new le(s, {
2118
+ _parent: this,
2119
+ _key: r,
2120
+ _machine: this.machine
2121
+ })) : as, this.type === "compound" && !this.config.initial)
2122
+ throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);
2123
+ this.history = this.config.history === !0 ? "shallow" : this.config.history || !1, this.entry = C(this.config.entry).slice(), this.exit = C(this.config.exit).slice(), this.meta = this.config.meta, this.output = this.type === "final" || !this.parent ? this.config.output : void 0, this.tags = C(t.tags).slice();
2124
+ }
2125
+ /** @internal */
2126
+ _initialize() {
2127
+ this.transitions = Mn(this), this.config.always && (this.always = U(this.config.always).map((t) => q(this, vt, t))), Object.keys(this.states).forEach((t) => {
2128
+ this.states[t]._initialize();
2129
+ });
2130
+ }
2131
+ /** The well-structured state node definition. */
2132
+ get definition() {
2133
+ return {
2134
+ id: this.id,
2135
+ key: this.key,
2136
+ version: this.machine.version,
2137
+ type: this.type,
2138
+ initial: this.initial ? {
2139
+ target: this.initial.target,
2140
+ source: this,
2141
+ actions: this.initial.actions.map(X),
2142
+ eventType: null,
2143
+ reenter: !1,
2144
+ toJSON: () => ({
2145
+ target: this.initial.target.map((t) => `#${t.id}`),
2146
+ source: `#${this.id}`,
2147
+ actions: this.initial.actions.map(X),
2148
+ eventType: null
2149
+ })
2150
+ } : void 0,
2151
+ history: this.history,
2152
+ states: Ke(this.states, (t) => t.definition),
2153
+ on: this.on,
2154
+ transitions: [...this.transitions.values()].flat().map((t) => ({
2155
+ ...t,
2156
+ actions: t.actions.map(X)
2157
+ })),
2158
+ entry: this.entry.map(X),
2159
+ exit: this.exit.map(X),
2160
+ meta: this.meta,
2161
+ order: this.order || -1,
2162
+ output: this.output,
2163
+ invoke: this.invoke,
2164
+ description: this.description,
2165
+ tags: this.tags
2166
+ };
2167
+ }
2168
+ /** @internal */
2169
+ toJSON() {
2170
+ return this.definition;
2171
+ }
2172
+ /** The logic invoked as actors by this state node. */
2173
+ get invoke() {
2174
+ return H(this, "invoke", () => C(this.config.invoke).map((t, n) => {
2175
+ const {
2176
+ src: s,
2177
+ systemId: r
2178
+ } = t, i = t.id ?? Ze(this.id, n), o = typeof s == "string" ? s : `xstate.invoke.${Ze(this.id, n)}`;
2179
+ return {
2180
+ ...t,
2181
+ src: o,
2182
+ id: i,
2183
+ systemId: r,
2184
+ toJSON() {
2185
+ const {
2186
+ onDone: a,
2187
+ onError: d,
2188
+ ...h
2189
+ } = t;
2190
+ return {
2191
+ ...h,
2192
+ type: "xstate.invoke",
2193
+ src: o,
2194
+ id: i
2195
+ };
2196
+ }
2197
+ };
2198
+ }));
2199
+ }
2200
+ /** The mapping of events to transitions. */
2201
+ get on() {
2202
+ return H(this, "on", () => [...this.transitions].flatMap(([n, s]) => s.map((r) => [n, r])).reduce((n, [s, r]) => (n[s] = n[s] || [], n[s].push(r), n), {}));
2203
+ }
2204
+ get after() {
2205
+ return H(this, "delayedTransitions", () => Rn(this));
2206
+ }
2207
+ get initial() {
2208
+ return H(this, "initial", () => $n(this, this.config.initial));
2209
+ }
2210
+ /** @internal */
2211
+ next(t, n) {
2212
+ const s = n.type, r = [];
2213
+ let i;
2214
+ const o = H(this, `candidates-${s}`, () => Cn(this, s));
2215
+ for (const a of o) {
2216
+ const {
2217
+ guard: d
2218
+ } = a, h = t.context;
2219
+ let y = !1;
2220
+ try {
2221
+ y = !d || N(d, h, n, t);
2222
+ } catch (u) {
2223
+ const c = typeof d == "string" ? d : typeof d == "object" ? d.type : void 0;
2224
+ throw new Error(`Unable to evaluate guard ${c ? `'${c}' ` : ""}in transition for event '${s}' in state node '${this.id}':
2225
+ ${u.message}`);
2226
+ }
2227
+ if (y) {
2228
+ r.push(...a.actions), i = a;
2229
+ break;
2230
+ }
2231
+ }
2232
+ return i ? [i] : void 0;
2233
+ }
2234
+ /** All the event types accepted by this state node and its descendants. */
2235
+ get events() {
2236
+ return H(this, "events", () => {
2237
+ const {
2238
+ states: t
2239
+ } = this, n = new Set(this.ownEvents);
2240
+ if (t)
2241
+ for (const s of Object.keys(t)) {
2242
+ const r = t[s];
2243
+ if (r.states)
2244
+ for (const i of r.events)
2245
+ n.add(`${i}`);
2246
+ }
2247
+ return Array.from(n);
2248
+ });
2249
+ }
2250
+ /**
2251
+ * All the events that have transitions directly from this state node.
2252
+ *
2253
+ * Excludes any inert events.
2254
+ */
2255
+ get ownEvents() {
2256
+ const t = new Set([...this.transitions.keys()].filter((n) => this.transitions.get(n).some((s) => !(!s.target && !s.actions.length && !s.reenter))));
2257
+ return Array.from(t);
2258
+ }
2259
+ }
2260
+ const cs = "#";
2261
+ class Pe {
2262
+ constructor(t, n) {
2263
+ this.config = t, this.version = void 0, this.schemas = void 0, this.implementations = 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 = t.id || "(machine)", this.implementations = {
2264
+ actors: (n == null ? void 0 : n.actors) ?? {},
2265
+ actions: (n == null ? void 0 : n.actions) ?? {},
2266
+ delays: (n == null ? void 0 : n.delays) ?? {},
2267
+ guards: (n == null ? void 0 : n.guards) ?? {}
2268
+ }, this.version = this.config.version, this.schemas = this.config.schemas, 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 le(t, {
2269
+ _key: this.id,
2270
+ _machine: this
2271
+ }), this.root._initialize(), this.states = this.root.states, this.events = this.root.events;
2272
+ }
2273
+ /**
2274
+ * Clones this state machine with the provided implementations.
2275
+ *
2276
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`) to
2277
+ * recursively merge with the existing options.
2278
+ * @returns A new `StateMachine` instance with the provided implementations.
2279
+ */
2280
+ provide(t) {
2281
+ const {
2282
+ actions: n,
2283
+ guards: s,
2284
+ actors: r,
2285
+ delays: i
2286
+ } = this.implementations;
2287
+ return new Pe(this.config, {
2288
+ actions: {
2289
+ ...n,
2290
+ ...t.actions
2291
+ },
2292
+ guards: {
2293
+ ...s,
2294
+ ...t.guards
2295
+ },
2296
+ actors: {
2297
+ ...r,
2298
+ ...t.actors
2299
+ },
2300
+ delays: {
2301
+ ...i,
2302
+ ...t.delays
2303
+ }
2304
+ });
2305
+ }
2306
+ resolveState(t) {
2307
+ const n = Nn(this.root, t.value), s = ce(de(this.root, n));
2308
+ return se({
2309
+ _nodes: [...s],
2310
+ context: t.context || {},
2311
+ children: {},
2312
+ status: Ue(s, this.root) ? "done" : t.status || "active",
2313
+ output: t.output,
2314
+ error: t.error,
2315
+ historyValue: t.historyValue
2316
+ }, this);
2317
+ }
2318
+ /**
2319
+ * Determines the next snapshot given the current `snapshot` and received
2320
+ * `event`. Calculates a full macrostep from all microsteps.
2321
+ *
2322
+ * @param snapshot The current snapshot
2323
+ * @param event The received event
2324
+ */
2325
+ transition(t, n, s) {
2326
+ return _e(t, n, s, []).snapshot;
2327
+ }
2328
+ /**
2329
+ * Determines the next state given the current `state` and `event`. Calculates
2330
+ * a microstep.
2331
+ *
2332
+ * @param state The current state
2333
+ * @param event The received event
2334
+ */
2335
+ microstep(t, n, s) {
2336
+ return _e(t, n, s, []).microstates;
2337
+ }
2338
+ getTransitionData(t, n) {
2339
+ return We(this.root, t.value, t, n) || [];
2340
+ }
2341
+ /**
2342
+ * The initial state _before_ evaluating any microsteps. This "pre-initial"
2343
+ * state is provided to initial actions executed in the initial state.
2344
+ */
2345
+ getPreInitialState(t, n, s) {
2346
+ const {
2347
+ context: r
2348
+ } = this.config, i = se({
2349
+ context: typeof r != "function" && r ? r : {},
2350
+ _nodes: [this.root],
2351
+ children: {},
2352
+ status: "active"
2353
+ }, this);
2354
+ return typeof r == "function" ? J(i, n, t, [M(({
2355
+ spawn: a,
2356
+ event: d,
2357
+ self: h
2358
+ }) => r({
2359
+ spawn: a,
2360
+ input: d.input,
2361
+ self: h
2362
+ }))], s, void 0) : i;
2363
+ }
2364
+ /**
2365
+ * Returns the initial `State` instance, with reference to `self` as an
2366
+ * `ActorRef`.
2367
+ */
2368
+ getInitialSnapshot(t, n) {
2369
+ const s = bt(n), r = [], i = this.getPreInitialState(t, s, r), o = Le([{
2370
+ target: [...$t(this.root)],
2371
+ source: this.root,
2372
+ reenter: !0,
2373
+ actions: [],
2374
+ eventType: null,
2375
+ toJSON: null
2376
+ // TODO: fix
2377
+ }], i, t, s, !0, r), {
2378
+ snapshot: a
2379
+ } = _e(o, s, t, r);
2380
+ return a;
2381
+ }
2382
+ start(t) {
2383
+ Object.values(t.children).forEach((n) => {
2384
+ n.getSnapshot().status === "active" && n.start();
2385
+ });
2386
+ }
2387
+ getStateNodeById(t) {
2388
+ const n = je(t), s = n.slice(1), r = ee(n[0]) ? n[0].slice(cs.length) : n[0], i = this.idMap.get(r);
2389
+ if (!i)
2390
+ throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);
2391
+ return ue(i, s);
2392
+ }
2393
+ get definition() {
2394
+ return this.root.definition;
2395
+ }
2396
+ toJSON() {
2397
+ return this.definition;
2398
+ }
2399
+ getPersistedSnapshot(t, n) {
2400
+ return ts(t, n);
2401
+ }
2402
+ restoreSnapshot(t, n) {
2403
+ const s = {}, r = t.children;
2404
+ Object.keys(r).forEach((u) => {
2405
+ const c = r[u], l = c.snapshot, f = c.src, p = typeof f == "string" ? De(this, f) : f;
2406
+ if (!p)
2407
+ return;
2408
+ const g = $(p, {
2409
+ id: u,
2410
+ parent: n.self,
2411
+ syncSnapshot: c.syncSnapshot,
2412
+ snapshot: l,
2413
+ src: f,
2414
+ systemId: c.systemId
2415
+ });
2416
+ s[u] = g;
2417
+ });
2418
+ function i(u, c) {
2419
+ if (c instanceof le)
2420
+ return c;
2421
+ try {
2422
+ return u.machine.getStateNodeById(c.id);
2423
+ } catch {
2424
+ }
2425
+ }
2426
+ function o(u, c) {
2427
+ if (!c || typeof c != "object")
2428
+ return {};
2429
+ const l = {};
2430
+ for (const f in c) {
2431
+ const p = c[f];
2432
+ for (const g of p) {
2433
+ const m = i(u, g);
2434
+ m && (l[f] ?? (l[f] = []), l[f].push(m));
2435
+ }
2436
+ }
2437
+ return l;
2438
+ }
2439
+ const a = o(this.root, t.historyValue), d = se({
2440
+ ...t,
2441
+ children: s,
2442
+ _nodes: Array.from(ce(de(this.root, t.value))),
2443
+ historyValue: a
2444
+ }, this), h = /* @__PURE__ */ new Set();
2445
+ function y(u, c) {
2446
+ if (!h.has(u)) {
2447
+ h.add(u);
2448
+ for (const l in u) {
2449
+ const f = u[l];
2450
+ if (f && typeof f == "object") {
2451
+ if ("xstate$$type" in f && f.xstate$$type === Ve) {
2452
+ u[l] = c[f.id];
2453
+ continue;
2454
+ }
2455
+ y(f, c);
2456
+ }
2457
+ }
2458
+ }
2459
+ }
2460
+ return y(d.context, s), d;
2461
+ }
2462
+ }
2463
+ function us(e, t, n, s, {
2464
+ event: r
2465
+ }) {
2466
+ const i = typeof r == "function" ? r(n, s) : r;
2467
+ return [t, {
2468
+ event: i
2469
+ }, void 0];
2470
+ }
2471
+ function ds(e, {
2472
+ event: t
2473
+ }) {
2474
+ e.defer(() => e.emit(t));
2475
+ }
2476
+ function pe(e) {
2477
+ function t(n, s) {
2478
+ }
2479
+ return t.type = "xstate.emit", t.event = e, t.resolve = us, t.execute = ds, t;
2480
+ }
2481
+ let qe = /* @__PURE__ */ function(e) {
2482
+ return e.Parent = "#_parent", e.Internal = "#_internal", e;
2483
+ }({});
2484
+ function fs(e, t, n, s, {
2485
+ to: r,
2486
+ event: i,
2487
+ id: o,
2488
+ delay: a
2489
+ }, d) {
2490
+ var f;
2491
+ const h = t.machine.implementations.delays;
2492
+ if (typeof i == "string")
2493
+ throw new Error(
2494
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
2495
+ `Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`
2496
+ );
2497
+ const y = typeof i == "function" ? i(n, s) : i;
2498
+ let u;
2499
+ if (typeof a == "string") {
2500
+ const p = h && h[a];
2501
+ u = typeof p == "function" ? p(n, s) : p;
2502
+ } else
2503
+ u = typeof a == "function" ? a(n, s) : a;
2504
+ const c = typeof r == "function" ? r(n, s) : r;
2505
+ let l;
2506
+ if (typeof c == "string") {
2507
+ if (c === qe.Parent ? l = e.self._parent : c === qe.Internal ? l = e.self : c.startsWith("#_") ? l = t.children[c.slice(2)] : l = (f = d.deferredActorIds) != null && f.includes(c) ? c : t.children[c], !l)
2508
+ throw new Error(`Unable to send event to actor '${c}' from machine '${t.machine.id}'.`);
2509
+ } else
2510
+ l = c || e.self;
2511
+ return [t, {
2512
+ to: l,
2513
+ targetId: typeof c == "string" ? c : void 0,
2514
+ event: y,
2515
+ id: o,
2516
+ delay: u
2517
+ }, void 0];
2518
+ }
2519
+ function hs(e, t, n) {
2520
+ typeof n.to == "string" && (n.to = t.children[n.to]);
2521
+ }
2522
+ function ls(e, t) {
2523
+ e.defer(() => {
2524
+ const {
2525
+ to: n,
2526
+ event: s,
2527
+ delay: r,
2528
+ id: i
2529
+ } = t;
2530
+ if (typeof r == "number") {
2531
+ e.system.scheduler.schedule(e.self, n, s, r, i);
2532
+ return;
2533
+ }
2534
+ e.system._relay(
2535
+ e.self,
2536
+ // at this point, in a deferred task, it should already be mutated by retryResolveSendTo
2537
+ // if it initially started as a string
2538
+ n,
2539
+ s.type === dn ? St(e.self.id, s.data) : s
2540
+ );
2541
+ });
2542
+ }
2543
+ function K(e, t, n) {
2544
+ function s(r, i) {
2545
+ }
2546
+ return s.type = "xstate.sendTo", s.to = e, s.event = t, s.id = n == null ? void 0 : n.id, s.delay = n == null ? void 0 : n.delay, s.resolve = fs, s.retryResolve = hs, s.execute = ls, s;
2547
+ }
2548
+ function ps(e, t) {
2549
+ return K(qe.Parent, e, t);
2550
+ }
2551
+ function ys(e, t, n, s, {
2552
+ collect: r
2553
+ }) {
2554
+ const i = [], o = function(d) {
2555
+ i.push(d);
2556
+ };
2557
+ return o.assign = (...a) => {
2558
+ i.push(M(...a));
2559
+ }, o.cancel = (...a) => {
2560
+ i.push(kt(...a));
2561
+ }, o.raise = (...a) => {
2562
+ i.push(x(...a));
2563
+ }, o.sendTo = (...a) => {
2564
+ i.push(K(...a));
2565
+ }, o.sendParent = (...a) => {
2566
+ i.push(ps(...a));
2567
+ }, o.spawnChild = (...a) => {
2568
+ i.push(It(...a));
2569
+ }, o.stopChild = (...a) => {
2570
+ i.push(F(...a));
2571
+ }, o.emit = (...a) => {
2572
+ i.push(pe(...a));
2573
+ }, r({
2574
+ context: n.context,
2575
+ event: n.event,
2576
+ enqueue: o,
2577
+ check: (a) => N(a, t.context, n.event, t),
2578
+ self: e.self,
2579
+ system: e.system
2580
+ }, s), [t, void 0, i];
2581
+ }
2582
+ function A(e) {
2583
+ function t(n, s) {
2584
+ }
2585
+ return t.type = "xstate.enqueueActions", t.collect = e, t.resolve = ys, t;
2586
+ }
2587
+ function gs(e, t, n, s, {
2588
+ value: r,
2589
+ label: i
2590
+ }) {
2591
+ return [t, {
2592
+ value: typeof r == "function" ? r(n, s) : r,
2593
+ label: i
2594
+ }, void 0];
2595
+ }
2596
+ function ms({
2597
+ logger: e
2598
+ }, {
2599
+ value: t,
2600
+ label: n
2601
+ }) {
2602
+ n ? e(n, t) : e(t);
2603
+ }
2604
+ function Fs(e = ({
2605
+ context: n,
2606
+ event: s
2607
+ }) => ({
2608
+ context: n,
2609
+ event: s
2610
+ }), t) {
2611
+ function n(s, r) {
2612
+ }
2613
+ return n.type = "xstate.log", n.value = e, n.label = t, n.resolve = gs, n.execute = ms, n;
2614
+ }
2615
+ function S(e, t) {
2616
+ const n = C(t);
2617
+ if (!n.includes(e.type)) {
2618
+ const s = n.length === 1 ? `type "${n[0]}"` : `one of types "${n.join('", "')}"`;
2619
+ throw new Error(`Expected event ${JSON.stringify(e)} to have ${s}`);
2620
+ }
2621
+ }
2622
+ function vs(e, t) {
2623
+ return new Pe(e, t);
2624
+ }
2625
+ function ze({
2626
+ schemas: e,
2627
+ actors: t,
2628
+ actions: n,
2629
+ guards: s,
2630
+ delays: r
2631
+ }) {
2632
+ return {
2633
+ createMachine: (i) => vs({
2634
+ ...i,
2635
+ schemas: e
2636
+ }, {
2637
+ actors: t,
2638
+ actions: n,
2639
+ guards: s,
2640
+ delays: r
2641
+ })
2642
+ };
2643
+ }
2644
+ var Se = { exports: {} }, be = {}, we = { exports: {} }, Ee = {};
2645
+ /**
2646
+ * @license React
2647
+ * use-sync-external-store-shim.production.js
2648
+ *
2649
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2650
+ *
2651
+ * This source code is licensed under the MIT license found in the
2652
+ * LICENSE file in the root directory of this source tree.
2653
+ */
2654
+ var at;
2655
+ function _s() {
2656
+ if (at) return Ee;
2657
+ at = 1;
2658
+ var e = lt;
2659
+ function t(u, c) {
2660
+ return u === c && (u !== 0 || 1 / u === 1 / c) || u !== u && c !== c;
2661
+ }
2662
+ var n = typeof Object.is == "function" ? Object.is : t, s = e.useState, r = e.useEffect, i = e.useLayoutEffect, o = e.useDebugValue;
2663
+ function a(u, c) {
2664
+ var l = c(), f = s({ inst: { value: l, getSnapshot: c } }), p = f[0].inst, g = f[1];
2665
+ return i(
2666
+ function() {
2667
+ p.value = l, p.getSnapshot = c, d(p) && g({ inst: p });
2668
+ },
2669
+ [u, l, c]
2670
+ ), r(
2671
+ function() {
2672
+ return d(p) && g({ inst: p }), u(function() {
2673
+ d(p) && g({ inst: p });
2674
+ });
2675
+ },
2676
+ [u]
2677
+ ), o(l), l;
2678
+ }
2679
+ function d(u) {
2680
+ var c = u.getSnapshot;
2681
+ u = u.value;
2682
+ try {
2683
+ var l = c();
2684
+ return !n(u, l);
2685
+ } catch {
2686
+ return !0;
2687
+ }
2688
+ }
2689
+ function h(u, c) {
2690
+ return c();
2691
+ }
2692
+ var y = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? h : a;
2693
+ return Ee.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : y, Ee;
2694
+ }
2695
+ var ct;
2696
+ function Ht() {
2697
+ return ct || (ct = 1, we.exports = _s()), we.exports;
2698
+ }
2699
+ /**
2700
+ * @license React
2701
+ * use-sync-external-store-shim/with-selector.production.js
2702
+ *
2703
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2704
+ *
2705
+ * This source code is licensed under the MIT license found in the
2706
+ * LICENSE file in the root directory of this source tree.
2707
+ */
2708
+ var ut;
2709
+ function Ss() {
2710
+ if (ut) return be;
2711
+ ut = 1;
2712
+ var e = lt, t = Ht();
2713
+ function n(h, y) {
2714
+ return h === y && (h !== 0 || 1 / h === 1 / y) || h !== h && y !== y;
2715
+ }
2716
+ var s = typeof Object.is == "function" ? Object.is : n, r = t.useSyncExternalStore, i = e.useRef, o = e.useEffect, a = e.useMemo, d = e.useDebugValue;
2717
+ return be.useSyncExternalStoreWithSelector = function(h, y, u, c, l) {
2718
+ var f = i(null);
2719
+ if (f.current === null) {
2720
+ var p = { hasValue: !1, value: null };
2721
+ f.current = p;
2722
+ } else p = f.current;
2723
+ f = a(
2724
+ function() {
2725
+ function m(T) {
2726
+ if (!v) {
2727
+ if (v = !0, _ = T, T = c(T), l !== void 0 && p.hasValue) {
2728
+ var V = p.value;
2729
+ if (l(V, T))
2730
+ return w = V;
2731
+ }
2732
+ return w = T;
2733
+ }
2734
+ if (V = w, s(_, T)) return V;
2735
+ var Ge = c(T);
2736
+ return l !== void 0 && l(V, Ge) ? (_ = T, V) : (_ = T, w = Ge);
2737
+ }
2738
+ var v = !1, _, w, te = u === void 0 ? null : u;
2739
+ return [
2740
+ function() {
2741
+ return m(y());
2742
+ },
2743
+ te === null ? void 0 : function() {
2744
+ return m(te());
2745
+ }
2746
+ ];
2747
+ },
2748
+ [y, u, c, l]
2749
+ );
2750
+ var g = r(h, f[0], f[1]);
2751
+ return o(
2752
+ function() {
2753
+ p.hasValue = !0, p.value = g;
2754
+ },
2755
+ [g]
2756
+ ), d(g), g;
2757
+ }, be;
2758
+ }
2759
+ var dt;
2760
+ function bs() {
2761
+ return dt || (dt = 1, Se.exports = Ss()), Se.exports;
2762
+ }
2763
+ var ws = bs(), Qs = Ht();
2764
+ const Ut = (e, t) => {
2765
+ t(e);
2766
+ const n = e.getSnapshot().children;
2767
+ n && Object.values(n).forEach((s) => {
2768
+ Ut(s, t);
2769
+ });
2770
+ };
2771
+ function Es(e) {
2772
+ var s, r;
2773
+ const t = [];
2774
+ Ut(e, (i) => {
2775
+ t.push([i, i.getSnapshot()]), i.observers = /* @__PURE__ */ new Set();
2776
+ });
2777
+ const n = (r = (s = e.system).getSnapshot) == null ? void 0 : r.call(s);
2778
+ e.stop(), e.system._snapshot = n, t.forEach(([i, o]) => {
2779
+ i._processingStatus = 0, i._snapshot = o;
2780
+ });
2781
+ }
2782
+ function Ts(e, ...[t]) {
2783
+ let [[n, s], r] = Nt(() => {
2784
+ const i = $(e, t);
2785
+ return [e.config, i];
2786
+ });
2787
+ if (e.config !== n) {
2788
+ const i = $(e, {
2789
+ ...t,
2790
+ snapshot: s.getPersistedSnapshot({
2791
+ __unsafeAllowInlineActors: !0
2792
+ })
2793
+ });
2794
+ r([e.config, i]), s = i;
2795
+ }
2796
+ return nn(() => {
2797
+ s.logic.implementations = e.implementations;
2798
+ }), s;
2799
+ }
2800
+ function er(e, ...[t, n]) {
2801
+ const s = Ts(e, t);
2802
+ return Ne(() => {
2803
+ if (!n)
2804
+ return;
2805
+ const r = s.subscribe(ae(n));
2806
+ return () => {
2807
+ r.unsubscribe();
2808
+ };
2809
+ }, [n]), Ne(() => (s.start(), () => {
2810
+ Es(s);
2811
+ }), [s]), s;
2812
+ }
2813
+ function xs(e, t) {
2814
+ return e === t;
2815
+ }
2816
+ function tr(e, t, n = xs) {
2817
+ const s = Je((o) => {
2818
+ if (!e)
2819
+ return () => {
2820
+ };
2821
+ const {
2822
+ unsubscribe: a
2823
+ } = e.subscribe(o);
2824
+ return a;
2825
+ }, [e]), r = Je(() => e == null ? void 0 : e.getSnapshot(), [e]);
2826
+ return ws.useSyncExternalStoreWithSelector(s, r, r, t, n);
2827
+ }
2828
+ const b = [];
2829
+ for (let e = 0; e < 256; ++e)
2830
+ b.push((e + 256).toString(16).slice(1));
2831
+ function ks(e, t = 0) {
2832
+ return (b[e[t + 0]] + b[e[t + 1]] + b[e[t + 2]] + b[e[t + 3]] + "-" + b[e[t + 4]] + b[e[t + 5]] + "-" + b[e[t + 6]] + b[e[t + 7]] + "-" + b[e[t + 8]] + b[e[t + 9]] + "-" + b[e[t + 10]] + b[e[t + 11]] + b[e[t + 12]] + b[e[t + 13]] + b[e[t + 14]] + b[e[t + 15]]).toLowerCase();
2833
+ }
2834
+ let Te;
2835
+ const Is = new Uint8Array(16);
2836
+ function As() {
2837
+ if (!Te) {
2838
+ if (typeof crypto > "u" || !crypto.getRandomValues)
2839
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
2840
+ Te = crypto.getRandomValues.bind(crypto);
2841
+ }
2842
+ return Te(Is);
2843
+ }
2844
+ const Cs = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ft = { randomUUID: Cs };
2845
+ function B(e, t, n) {
2846
+ var r;
2847
+ if (ft.randomUUID && !e)
2848
+ return ft.randomUUID();
2849
+ e = e || {};
2850
+ const s = e.random ?? ((r = e.rng) == null ? void 0 : r.call(e)) ?? As();
2851
+ if (s.length < 16)
2852
+ throw new Error("Random bytes length must be >= 16");
2853
+ return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, ks(s);
2854
+ }
2855
+ const I = (e) => ({
2856
+ context: t
2857
+ }) => {
2858
+ const { count: n, include: s, exclude: r, responseType: i = "message.received" } = e;
2859
+ return {
2860
+ count: n,
2861
+ domain: t.domain,
2862
+ from: t.connectTo,
2863
+ include: s ? Array.isArray(s) ? s : [s] : [],
2864
+ exclude: r ? Array.isArray(r) ? r : [r] : [],
2865
+ responseType: i,
2866
+ target: t.target,
2867
+ to: t.name
2868
+ };
2869
+ }, Rs = (e) => (t) => {
2870
+ const { data: n } = t;
2871
+ return (e.include.length ? e.include.includes(n.type) : !0) && (e.exclude.length ? !e.exclude.includes(n.type) : !0) && n.domain === e.domain && n.from === e.from && n.to === e.to && (!e.target || t.source === e.target);
2872
+ }, Ms = (e) => (t) => ({
2873
+ type: e,
2874
+ message: t
2875
+ }), $s = Xt(
2876
+ () => Ie(window, "message")
2877
+ ), Wt = (e) => Vt(({ input: t }) => $s.pipe(
2878
+ e ? Ae(e) : ge(),
2879
+ yt(Rs(t)),
2880
+ Ae(Ms(t.responseType)),
2881
+ t.count ? ge(
2882
+ tn(t.count),
2883
+ Yt((n) => n),
2884
+ Oe(t.count)
2885
+ ) : ge()
2886
+ )), Bt = "sanity/comlink", Ls = 3e3, qs = 1e4, Os = 500, P = "comlink/response", Z = "comlink/heartbeat", Y = "comlink/disconnect", re = "comlink/handshake/syn", Pt = "comlink/handshake/syn-ack", ie = "comlink/handshake/ack", js = (e) => (t) => t.pipe(
2887
+ Oe(1),
2888
+ Ae(() => {
2889
+ throw new Error(e);
2890
+ })
2891
+ ), zt = () => ze({
2892
+ actors: {
2893
+ listen: Vt(
2894
+ ({
2895
+ input: e
2896
+ }) => {
2897
+ const t = e.signal ? Ie(e.signal, "abort").pipe(
2898
+ js(`Request ${e.requestId} aborted`)
2899
+ ) : Kt, n = (s) => {
2900
+ var r, i;
2901
+ return ((r = s.data) == null ? void 0 : r.type) === P && ((i = s.data) == null ? void 0 : i.responseTo) === e.requestId && !!s.source && e.sources.has(s.source);
2902
+ };
2903
+ return Ie(window, "message").pipe(
2904
+ yt(n),
2905
+ Oe(e.sources.size),
2906
+ Zt(t)
2907
+ );
2908
+ }
2909
+ )
2910
+ },
2911
+ actions: {
2912
+ "send message": ({ context: e }, t) => {
2913
+ const { sources: n, targetOrigin: s } = e, { message: r } = t;
2914
+ n.forEach((i) => {
2915
+ i.postMessage(r, { targetOrigin: s });
2916
+ });
2917
+ },
2918
+ "on success": K(
2919
+ ({ context: e }) => e.parentRef,
2920
+ ({ context: e, self: t }) => {
2921
+ var n;
2922
+ return e.response && ((n = e.resolvable) == null || n.resolve(e.response)), {
2923
+ type: "request.success",
2924
+ requestId: t.id,
2925
+ response: e.response,
2926
+ responseTo: e.responseTo
2927
+ };
2928
+ }
2929
+ ),
2930
+ "on fail": K(
2931
+ ({ context: e }) => e.parentRef,
2932
+ ({ context: e, self: t }) => {
2933
+ var n;
2934
+ return e.suppressWarnings || console.warn(
2935
+ `[@sanity/comlink] Received no response to message '${e.type}' on client '${e.from}' (ID: '${e.id}').`
2936
+ ), (n = e.resolvable) == null || n.reject(new Error("No response received")), { type: "request.failed", requestId: t.id };
2937
+ }
2938
+ ),
2939
+ "on abort": K(
2940
+ ({ context: e }) => e.parentRef,
2941
+ ({ context: e, self: t }) => {
2942
+ var n;
2943
+ return (n = e.resolvable) == null || n.reject(new Error("Request aborted")), { type: "request.aborted", requestId: t.id };
2944
+ }
2945
+ )
2946
+ },
2947
+ guards: {
2948
+ expectsResponse: ({ context: e }) => e.expectResponse
2949
+ },
2950
+ delays: {
2951
+ initialTimeout: 0,
2952
+ responseTimeout: ({ context: e }) => e.responseTimeout ?? Ls
2953
+ }
2954
+ }).createMachine({
2955
+ /** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAOlwgBswBiAD1gBd0GwT0AzFgJ2QNwdzoKAFVyowAewCuDItTRY8hUuSoBtAAwBdRKAAOE2P1wT8ukLUQBGAEwBWEgBYAnK+eOAzB7sB2DzY8rABoQAE9rDQc3V0cNTw8fAA4NHwBfVJCFHAJiElgwfAgCKGpNHSQQAyMBU3NLBDsrDxI7DTaAjQA2OOcNDxDwhHsNJx9Ou0TOq2cJxP9HdMyMbOU8gqL8ErUrcv1DY1qK+sbm1vaPLp6+gcRnGydo9wDGycWQLKVc9AB3dGNN6jiWCwdAwMrmKoHMxHRCJRKOEiJHwuZKBZwXKzBMKIGyYkhtAkXOweTqOHw2RJvD45Ug-P4CAH0JgsNicMA8LhwAz4fKicTSWTyZafWm-f5QcEVSE1aGgepwhFIlF9aYYrGDC4+JzEppjGzOUkeGbpDIgfASCBwczU5QQ-YyuqIAC0nRuCBd+IJXu9KSpwppZEoYDt1RMsosiEcNjdVjiJEeGisiSTHkcVgWpptuXyhWKIahjqGzi1BqRJINnVcdkcbuTLS9VYC8ISfsUAbp4vzDphCHJIyjBvJNlxNmRNexQ3sJGH43GPj8jWJrZWuXYfyoEC7YcLsbrgRsjkcvkmdgNbopVhIPhVfnsh8ClMz-tWsCkmEwcHgUvt257u8v+6Hse4xnhOdZnImVidPqCRNB4JqpEAA */
2956
+ context: ({ input: e }) => ({
2957
+ channelId: e.channelId,
2958
+ data: e.data,
2959
+ domain: e.domain,
2960
+ expectResponse: e.expectResponse ?? !1,
2961
+ from: e.from,
2962
+ id: `msg-${B()}`,
2963
+ parentRef: e.parentRef,
2964
+ resolvable: e.resolvable,
2965
+ response: null,
2966
+ responseTimeout: e.responseTimeout,
2967
+ responseTo: e.responseTo,
2968
+ signal: e.signal,
2969
+ sources: e.sources instanceof Set ? e.sources : /* @__PURE__ */ new Set([e.sources]),
2970
+ suppressWarnings: e.suppressWarnings,
2971
+ targetOrigin: e.targetOrigin,
2972
+ to: e.to,
2973
+ type: e.type
2974
+ }),
2975
+ initial: "idle",
2976
+ on: {
2977
+ abort: ".aborted"
2978
+ },
2979
+ states: {
2980
+ idle: {
2981
+ after: {
2982
+ initialTimeout: [
2983
+ {
2984
+ target: "sending"
2985
+ }
2986
+ ]
2987
+ }
2988
+ },
2989
+ sending: {
2990
+ entry: {
2991
+ type: "send message",
2992
+ params: ({ context: e }) => {
2993
+ const { channelId: t, data: n, domain: s, from: r, id: i, responseTo: o, to: a, type: d } = e;
2994
+ return { message: {
2995
+ channelId: t,
2996
+ data: n,
2997
+ domain: s,
2998
+ from: r,
2999
+ id: i,
3000
+ to: a,
3001
+ type: d,
3002
+ responseTo: o
3003
+ } };
3004
+ }
3005
+ },
3006
+ always: [
3007
+ {
3008
+ guard: "expectsResponse",
3009
+ target: "awaiting"
3010
+ },
3011
+ "success"
3012
+ ]
3013
+ },
3014
+ awaiting: {
3015
+ invoke: {
3016
+ id: "listen for response",
3017
+ src: "listen",
3018
+ input: ({ context: e }) => ({
3019
+ requestId: e.id,
3020
+ sources: e.sources,
3021
+ signal: e.signal
3022
+ }),
3023
+ onError: "aborted"
3024
+ },
3025
+ after: {
3026
+ responseTimeout: "failed"
3027
+ },
3028
+ on: {
3029
+ message: {
3030
+ actions: M({
3031
+ response: ({ event: e }) => e.data.data,
3032
+ responseTo: ({ event: e }) => e.data.responseTo
3033
+ }),
3034
+ target: "success"
3035
+ }
3036
+ }
3037
+ },
3038
+ failed: {
3039
+ type: "final",
3040
+ entry: "on fail"
3041
+ },
3042
+ success: {
3043
+ type: "final",
3044
+ entry: "on success"
3045
+ },
3046
+ aborted: {
3047
+ type: "final",
3048
+ entry: "on abort"
3049
+ }
3050
+ },
3051
+ output: ({ context: e, self: t }) => ({
3052
+ requestId: t.id,
3053
+ response: e.response,
3054
+ responseTo: e.responseTo
3055
+ })
3056
+ }), Ds = rs(({ sendBack: e, input: t }) => {
3057
+ const n = () => {
3058
+ e(t.event);
3059
+ };
3060
+ t.immediate && n();
3061
+ const s = setInterval(n, t.interval);
3062
+ return () => {
3063
+ clearInterval(s);
3064
+ };
3065
+ }), Gt = () => ze({
3066
+ actors: {
3067
+ requestMachine: zt(),
3068
+ listen: Wt(),
3069
+ sendBackAtInterval: Ds
3070
+ },
3071
+ actions: {
3072
+ "buffer message": A(({ enqueue: e }) => {
3073
+ e.assign({
3074
+ buffer: ({ event: t, context: n }) => (S(t, "post"), [...n.buffer, t.data])
3075
+ }), e.emit(({ event: t }) => (S(t, "post"), {
3076
+ type: "buffer.added",
3077
+ message: t.data
3078
+ }));
3079
+ }),
3080
+ "create request": M({
3081
+ requests: ({ context: e, event: t, self: n, spawn: s }) => {
3082
+ S(t, "request");
3083
+ const r = (Array.isArray(t.data) ? t.data : [t.data]).map((i) => {
3084
+ const o = `req-${B()}`;
3085
+ return s("requestMachine", {
3086
+ id: o,
3087
+ input: {
3088
+ channelId: e.channelId,
3089
+ data: i.data,
3090
+ domain: e.domain,
3091
+ expectResponse: i.expectResponse,
3092
+ from: e.name,
3093
+ parentRef: n,
3094
+ responseTo: i.responseTo,
3095
+ sources: e.target,
3096
+ targetOrigin: e.targetOrigin,
3097
+ to: e.connectTo,
3098
+ type: i.type
3099
+ }
3100
+ });
3101
+ });
3102
+ return [...e.requests, ...r];
3103
+ }
3104
+ }),
3105
+ "emit received message": A(({ enqueue: e }) => {
3106
+ e.emit(({ event: t }) => (S(t, "message.received"), {
3107
+ type: "message",
3108
+ message: t.message.data
3109
+ }));
3110
+ }),
3111
+ "emit status": pe((e, t) => ({
3112
+ type: "status",
3113
+ status: t.status
3114
+ })),
3115
+ "post message": x(({ event: e }) => (S(e, "post"), {
3116
+ type: "request",
3117
+ data: {
3118
+ data: e.data.data,
3119
+ expectResponse: !0,
3120
+ type: e.data.type
3121
+ }
3122
+ })),
3123
+ "remove request": A(({ context: e, enqueue: t, event: n }) => {
3124
+ S(n, ["request.success", "request.failed", "request.aborted"]), F(n.requestId), t.assign({ requests: e.requests.filter(({ id: s }) => s !== n.requestId) });
3125
+ }),
3126
+ respond: x(({ event: e }) => (S(e, "response"), {
3127
+ type: "request",
3128
+ data: {
3129
+ data: e.data,
3130
+ type: P,
3131
+ responseTo: e.respondTo
3132
+ }
3133
+ })),
3134
+ "send handshake ack": x({
3135
+ type: "request",
3136
+ data: { type: ie }
3137
+ }),
3138
+ "send disconnect": x(() => ({
3139
+ type: "request",
3140
+ data: { type: Y }
3141
+ })),
3142
+ "send handshake syn": x({
3143
+ type: "request",
3144
+ data: { type: re }
3145
+ }),
3146
+ "send pending messages": A(({ enqueue: e }) => {
3147
+ e.raise(({ context: t }) => ({
3148
+ type: "request",
3149
+ data: t.buffer.map(({ data: n, type: s }) => ({ data: n, type: s }))
3150
+ })), e.emit(({ context: t }) => ({
3151
+ type: "buffer.flushed",
3152
+ messages: t.buffer
3153
+ })), e.assign({
3154
+ buffer: []
3155
+ });
3156
+ }),
3157
+ "set target": M({
3158
+ target: ({ event: e }) => (S(e, "target.set"), e.target)
3159
+ })
3160
+ },
3161
+ guards: {
3162
+ "has target": ({ context: e }) => !!e.target,
3163
+ "should send heartbeats": ({ context: e }) => e.heartbeat
3164
+ }
3165
+ }).createMachine({
3166
+ /** @xstate-layout N4IgpgJg5mDOIC5QGMAWBDAdpsAbAxAC7oBOMhAdLGIQNoAMAuoqAA4D2sAloV+5ixAAPRAHZRAJgoAWABz0ArHICMy2QGZZCgJwAaEAE9EE+tIrb6ANgkLl46fTuj1AXxf60WHARJgAjgCucJSwAcjIcLAMzEggHNy8-IIiCKLS2hQS6qb2yurisrL6RgjK9LIyCuqq0g7WstZuHhjYePi+gcEUAGboXLiQ0YLxPHwCsSmiCgoykpayDtqS6trqxYjKEk0gnq24FFwQA-jI-DjIdEzDnKNJExuOZpZ12eq29OrSCuupypYUojUaTKCnm5Wk2123gORzA+HilxibBuiXGoBSGnUAIU4gU9FWamUtR+lmUM1EllBEkslMUEnpkJa0JaEFgGAA1lxMFB8LADJghrERqjkhtshk3mTtNo5OpqpYfqCKhTptoqpY1WUtu4dky8BQWWz0Jzue1-EFYIjrgkxqLSupqRRPpoPqJtLI0hIioZENJJE7NnJ8ZYHVk1YyvPrDRyuTyEYLkTa7uixVlMh81KGFhS1j6EPkZlpVjTphr8mkI3sDVhWTHTQBbSLoGAUXwRLgAN0GVyFKNt91KimUFEKXvKC2s9R+6X+jipnzJeSqEJ1UKjNaNJp5EC4sFOrQuCbifeTwg2cgoym0RPxDtqkj0eaB9Ao8zSolMEivZVcq71+33c5CEgeFOCtXskzRM8EDxKRpmkSw3QJbQsmpH5tHmV8JHSbJpDsakV2aSMALOMALhAjoLXAxNbiglI-SxWw1Vw0QNDw0Qfg9KQ7EJSxHHxApK2hQCyOAiAzVgDhMGoI9hX7FMEHSF8cWkelpHURCbBsb481xAEgT9BQJCmWQsiE-URPI8TG1gWBmzAVsyLATtuyRY9ILtWoKmlL82Kqd0tAVJ91LMHFZDKIkVlkNVZHMkiDzE-Adz3UjDx7GiRQHCKnheD53k+HSSkDDIwpBVTqQwuKKEssSDTAUhCAAI3qyg0DIrd8Fkk86MQUMnVM+RynoegTDJH48hGp0vR-FDRqqKqasgOqGua9AQjATAd1NSiul6fpXOtWi7Wy19cslD4vnG7IX3oVjVDUVYEJQqrksW8SdstLqPKy0wKgG1RhtMWogqKhoMjkWp6XxUyFBe3c3tAz70vco6fq+V8PTkGUFzdQqNnELEM2yClrwwzQ4ZShKQJqr7UYU98AS0W9pT4z5pHG0yXwMkNNTyGk3B1TB2AgOBBDXXBDsyhSFG9EovQqN5i1JeRcKqw4Bkl+ToMx8x0j+EaqQ9XMSkBURMgMkEwQWKro2NWNNdPFJAzN0lJGM4slDxhBEJfXyplBd03wW1KxIdnrBxBh4JAyW75C8rJpmDqmIGWkgmpasPjqUcaHooMLHA0uU1UkJOgKW1B6rT1bWor5At0zgcTAkK7hrz1irB0D8cW0UvRPLyv07WqgNq2qAG+l9SnXUz0UOXD5xuMs3Y4+DVJBX7UiKrV6Q8gcfoJO54rFefLLqfJYX1WKYNLxL4NO1NwgA */
3167
+ id: "connection",
3168
+ context: ({ input: e }) => ({
3169
+ id: e.id || `${e.name}-${B()}`,
3170
+ buffer: [],
3171
+ channelId: `chn-${B()}`,
3172
+ connectTo: e.connectTo,
3173
+ domain: e.domain ?? Bt,
3174
+ heartbeat: e.heartbeat ?? !1,
3175
+ name: e.name,
3176
+ requests: [],
3177
+ target: e.target,
3178
+ targetOrigin: e.targetOrigin
3179
+ }),
3180
+ on: {
3181
+ "target.set": {
3182
+ actions: "set target"
3183
+ },
3184
+ "request.success": {
3185
+ actions: "remove request"
3186
+ },
3187
+ "request.failed": {
3188
+ actions: "remove request"
3189
+ }
3190
+ },
3191
+ initial: "idle",
3192
+ states: {
3193
+ idle: {
3194
+ entry: [{ type: "emit status", params: { status: "idle" } }],
3195
+ on: {
3196
+ connect: {
3197
+ target: "handshaking",
3198
+ guard: "has target"
3199
+ },
3200
+ post: {
3201
+ actions: "buffer message"
3202
+ }
3203
+ }
3204
+ },
3205
+ handshaking: {
3206
+ id: "handshaking",
3207
+ entry: [{ type: "emit status", params: { status: "handshaking" } }],
3208
+ invoke: [
3209
+ {
3210
+ id: "send syn",
3211
+ src: "sendBackAtInterval",
3212
+ input: () => ({
3213
+ event: { type: "syn" },
3214
+ interval: Os,
3215
+ immediate: !0
3216
+ })
3217
+ },
3218
+ {
3219
+ id: "listen for handshake",
3220
+ src: "listen",
3221
+ input: (e) => I({
3222
+ include: Pt,
3223
+ count: 1
3224
+ })(e)
3225
+ /* Below would maybe be more readable than transitioning to
3226
+ 'connected' on 'message', and 'ack' on exit but having onDone when
3227
+ using passing invocations currently breaks XState Editor */
3228
+ // onDone: {
3229
+ // target: 'connected',
3230
+ // actions: 'ack',
3231
+ // },
3232
+ }
3233
+ ],
3234
+ on: {
3235
+ syn: {
3236
+ actions: "send handshake syn"
3237
+ },
3238
+ request: {
3239
+ actions: "create request"
3240
+ },
3241
+ post: {
3242
+ actions: "buffer message"
3243
+ },
3244
+ "message.received": {
3245
+ target: "connected"
3246
+ },
3247
+ disconnect: {
3248
+ target: "disconnected"
3249
+ }
3250
+ },
3251
+ exit: "send handshake ack"
3252
+ },
3253
+ connected: {
3254
+ entry: ["send pending messages", { type: "emit status", params: { status: "connected" } }],
3255
+ invoke: {
3256
+ id: "listen for messages",
3257
+ src: "listen",
3258
+ input: I({
3259
+ exclude: [P, Z]
3260
+ })
3261
+ },
3262
+ on: {
3263
+ post: {
3264
+ actions: "post message"
3265
+ },
3266
+ request: {
3267
+ actions: "create request"
3268
+ },
3269
+ response: {
3270
+ actions: "respond"
3271
+ },
3272
+ "message.received": {
3273
+ actions: "emit received message"
3274
+ },
3275
+ disconnect: {
3276
+ target: "disconnected"
3277
+ }
3278
+ },
3279
+ initial: "heartbeat",
3280
+ states: {
3281
+ heartbeat: {
3282
+ initial: "checking",
3283
+ states: {
3284
+ checking: {
3285
+ always: {
3286
+ guard: "should send heartbeats",
3287
+ target: "sending"
3288
+ }
3289
+ },
3290
+ sending: {
3291
+ on: {
3292
+ "request.failed": {
3293
+ target: "#handshaking"
3294
+ }
3295
+ },
3296
+ invoke: {
3297
+ id: "send heartbeat",
3298
+ src: "sendBackAtInterval",
3299
+ input: () => ({
3300
+ event: { type: "post", data: { type: Z, data: void 0 } },
3301
+ interval: 2e3,
3302
+ immediate: !1
3303
+ })
3304
+ }
3305
+ }
3306
+ }
3307
+ }
3308
+ }
3309
+ },
3310
+ disconnected: {
3311
+ id: "disconnected",
3312
+ entry: ["send disconnect", { type: "emit status", params: { status: "disconnected" } }],
3313
+ on: {
3314
+ request: {
3315
+ actions: "create request"
3316
+ },
3317
+ post: {
3318
+ actions: "buffer message"
3319
+ },
3320
+ connect: {
3321
+ target: "handshaking",
3322
+ guard: "has target"
3323
+ }
3324
+ }
3325
+ }
3326
+ }
3327
+ }), xe = (e, t = Gt()) => {
3328
+ const n = e.id || `${e.name}-${B()}`, s = $(t, {
3329
+ input: { ...e, id: n }
3330
+ }), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), o = (f, p, g) => {
3331
+ const m = r.get(f) || /* @__PURE__ */ new Set();
3332
+ r.has(f) || r.set(f, m), m.add(p);
3333
+ const v = i.get(f);
3334
+ if (v) {
3335
+ const _ = (g == null ? void 0 : g.replay) ?? 1;
3336
+ Array.from(v).slice(-_).forEach(async ({ data: w, id: te }) => {
3337
+ const T = await p(w);
3338
+ T && s.send({
3339
+ type: "response",
3340
+ respondTo: te,
3341
+ data: T
3342
+ });
3343
+ }), i.delete(f);
3344
+ }
3345
+ return () => {
3346
+ m.delete(p);
3347
+ };
3348
+ }, a = () => {
3349
+ s.send({ type: "connect" });
3350
+ }, d = () => {
3351
+ s.send({ type: "disconnect" });
3352
+ }, h = (f, p) => {
3353
+ const { unsubscribe: g } = s.on("status", (m) => {
3354
+ p && m.status !== p || f(m.status);
3355
+ });
3356
+ return g;
3357
+ }, y = (f) => {
3358
+ s.send({ type: "target.set", target: f });
3359
+ }, u = (f, p) => {
3360
+ const g = { type: f, data: p };
3361
+ s.send({ type: "post", data: g });
3362
+ };
3363
+ s.on("message", async ({ message: f }) => {
3364
+ const p = r.get(f.type);
3365
+ if (p) {
3366
+ p.forEach(async (m) => {
3367
+ const v = await m(f.data);
3368
+ v && s.send({ type: "response", respondTo: f.id, data: v });
3369
+ });
3370
+ return;
3371
+ }
3372
+ const g = i.get(f.type);
3373
+ g ? g.add(f) : i.set(f.type, /* @__PURE__ */ new Set([f]));
3374
+ });
3375
+ const c = () => {
3376
+ s.stop();
3377
+ }, l = () => (s.start(), c);
3378
+ return {
3379
+ actor: s,
3380
+ connect: a,
3381
+ disconnect: d,
3382
+ id: n,
3383
+ name: e.name,
3384
+ machine: t,
3385
+ on: o,
3386
+ onStatus: h,
3387
+ post: u,
3388
+ setTarget: y,
3389
+ start: l,
3390
+ stop: c,
3391
+ get target() {
3392
+ return s.getSnapshot().context.target;
3393
+ }
3394
+ };
3395
+ }, ke = (e) => {
3396
+ e.disconnect(), setTimeout(() => {
3397
+ e.stop();
3398
+ }, 0);
3399
+ }, Vs = () => {
3400
+ }, nr = (e) => {
3401
+ const { targetOrigin: t } = e, n = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
3402
+ return {
3403
+ addTarget: (r) => {
3404
+ if (n.has(r))
3405
+ return Vs;
3406
+ if (!n.size || !s.size)
3407
+ return n.add(r), s.forEach((o) => {
3408
+ o.connections.forEach((a) => {
3409
+ a.setTarget(r), a.connect();
3410
+ });
3411
+ }), () => {
3412
+ n.delete(r), s.forEach((o) => {
3413
+ o.connections.forEach((a) => {
3414
+ a.target === r && a.disconnect();
3415
+ });
3416
+ });
3417
+ };
3418
+ n.add(r);
3419
+ const i = /* @__PURE__ */ new Set();
3420
+ return s.forEach((o) => {
3421
+ const a = xe(
3422
+ {
3423
+ ...o.input,
3424
+ target: r,
3425
+ targetOrigin: t
3426
+ },
3427
+ o.machine
3428
+ );
3429
+ i.add(a), o.connections.add(a), o.subscribers.forEach(({ type: d, handler: h, unsubscribers: y }) => {
3430
+ y.push(a.on(d, h));
3431
+ }), o.internalEventSubscribers.forEach(({ type: d, handler: h, unsubscribers: y }) => {
3432
+ y.push(a.actor.on(d, h).unsubscribe);
3433
+ }), o.statusSubscribers.forEach(({ handler: d, unsubscribers: h }) => {
3434
+ h.push(
3435
+ a.onStatus((y) => d({ connection: a.id, status: y }))
3436
+ );
3437
+ }), a.start(), a.connect();
3438
+ }), () => {
3439
+ n.delete(r), i.forEach((o) => {
3440
+ ke(o), s.forEach((a) => {
3441
+ a.connections.delete(o);
3442
+ });
3443
+ });
3444
+ };
3445
+ },
3446
+ createChannel: (r, i = Gt()) => {
3447
+ const o = {
3448
+ connections: /* @__PURE__ */ new Set(),
3449
+ input: r,
3450
+ internalEventSubscribers: /* @__PURE__ */ new Set(),
3451
+ machine: i,
3452
+ statusSubscribers: /* @__PURE__ */ new Set(),
3453
+ subscribers: /* @__PURE__ */ new Set()
3454
+ };
3455
+ s.add(o);
3456
+ const { connections: a, internalEventSubscribers: d, statusSubscribers: h, subscribers: y } = o;
3457
+ if (n.size)
3458
+ n.forEach((g) => {
3459
+ const m = xe(
3460
+ {
3461
+ ...r,
3462
+ target: g,
3463
+ targetOrigin: t
3464
+ },
3465
+ i
3466
+ );
3467
+ a.add(m);
3468
+ });
3469
+ else {
3470
+ const g = xe({ ...r, targetOrigin: t }, i);
3471
+ a.add(g);
3472
+ }
3473
+ const u = (...g) => {
3474
+ const [m, v] = g;
3475
+ a.forEach((_) => {
3476
+ _.post(m, v);
3477
+ });
3478
+ }, c = (g, m) => {
3479
+ const v = [];
3480
+ a.forEach((w) => {
3481
+ v.push(w.on(g, m));
3482
+ });
3483
+ const _ = { type: g, handler: m, unsubscribers: v };
3484
+ return y.add(_), () => {
3485
+ v.forEach((w) => w()), y.delete(_);
3486
+ };
3487
+ }, l = (g, m) => {
3488
+ const v = [];
3489
+ a.forEach((w) => {
3490
+ v.push(w.actor.on(g, m).unsubscribe);
3491
+ });
3492
+ const _ = { type: g, handler: m, unsubscribers: v };
3493
+ return d.add(_), () => {
3494
+ v.forEach((w) => w()), d.delete(_);
3495
+ };
3496
+ }, f = (g) => {
3497
+ const m = [];
3498
+ a.forEach((_) => {
3499
+ m.push(
3500
+ _.onStatus((w) => g({ connection: _.id, status: w }))
3501
+ );
3502
+ });
3503
+ const v = { handler: g, unsubscribers: m };
3504
+ return h.add(v), () => {
3505
+ m.forEach((_) => _()), h.delete(v);
3506
+ };
3507
+ }, p = () => {
3508
+ const g = o.connections;
3509
+ g.forEach(ke), g.clear(), s.delete(o);
3510
+ };
3511
+ return {
3512
+ on: c,
3513
+ onInternalEvent: l,
3514
+ onStatus: f,
3515
+ post: u,
3516
+ start: () => (a.forEach((g) => {
3517
+ g.start(), g.connect();
3518
+ }), p),
3519
+ stop: p
3520
+ };
3521
+ },
3522
+ destroy: () => {
3523
+ s.forEach(({ connections: r }) => {
3524
+ r.forEach(ke), r.clear();
3525
+ }), s.clear(), n.clear();
3526
+ }
3527
+ };
3528
+ };
3529
+ function Hs() {
3530
+ if (typeof Promise.withResolvers == "function")
3531
+ return Promise.withResolvers();
3532
+ let e, t;
3533
+ return { promise: new Promise((n, s) => {
3534
+ e = n, t = s;
3535
+ }), resolve: e, reject: t };
3536
+ }
3537
+ const Us = () => ze({
3538
+ actors: {
3539
+ requestMachine: zt(),
3540
+ listen: Wt()
3541
+ },
3542
+ actions: {
3543
+ "buffer handshake": M({
3544
+ handshakeBuffer: ({ event: e, context: t }) => (S(e, "message.received"), [...t.handshakeBuffer, e])
3545
+ }),
3546
+ "buffer message": A(({ enqueue: e }) => {
3547
+ e.assign({
3548
+ buffer: ({ event: t, context: n }) => (S(t, "post"), [
3549
+ ...n.buffer,
3550
+ {
3551
+ data: t.data,
3552
+ resolvable: t.resolvable,
3553
+ options: t.options
3554
+ }
3555
+ ])
3556
+ }), e.emit(({ event: t }) => (S(t, "post"), {
3557
+ type: "buffer.added",
3558
+ message: t.data
3559
+ }));
3560
+ }),
3561
+ "create request": M({
3562
+ requests: ({ context: e, event: t, self: n, spawn: s }) => {
3563
+ S(t, "request");
3564
+ const r = (Array.isArray(t.data) ? t.data : [t.data]).map((i) => {
3565
+ var a, d, h;
3566
+ const o = `req-${B()}`;
3567
+ return s("requestMachine", {
3568
+ id: o,
3569
+ input: {
3570
+ channelId: e.channelId,
3571
+ data: i.data,
3572
+ domain: e.domain,
3573
+ expectResponse: i.expectResponse,
3574
+ from: e.name,
3575
+ parentRef: n,
3576
+ resolvable: i.resolvable,
3577
+ responseTimeout: (a = i.options) == null ? void 0 : a.responseTimeout,
3578
+ responseTo: i.responseTo,
3579
+ signal: (d = i.options) == null ? void 0 : d.signal,
3580
+ sources: e.target,
3581
+ suppressWarnings: (h = i.options) == null ? void 0 : h.suppressWarnings,
3582
+ targetOrigin: e.targetOrigin,
3583
+ to: e.connectTo,
3584
+ type: i.type
3585
+ }
3586
+ });
3587
+ });
3588
+ return [...e.requests, ...r];
3589
+ }
3590
+ }),
3591
+ "emit heartbeat": pe(() => ({
3592
+ type: "heartbeat"
3593
+ })),
3594
+ "emit received message": A(({ enqueue: e }) => {
3595
+ e.emit(({ event: t }) => (S(t, "message.received"), {
3596
+ type: "message",
3597
+ message: t.message.data
3598
+ }));
3599
+ }),
3600
+ "emit status": pe((e, t) => ({
3601
+ type: "status",
3602
+ status: t.status
3603
+ })),
3604
+ "post message": x(({ event: e }) => (S(e, "post"), {
3605
+ type: "request",
3606
+ data: {
3607
+ data: e.data.data,
3608
+ expectResponse: !!e.resolvable,
3609
+ type: e.data.type,
3610
+ resolvable: e.resolvable,
3611
+ options: e.options
3612
+ }
3613
+ })),
3614
+ "process pending handshakes": A(({ context: e, enqueue: t }) => {
3615
+ e.handshakeBuffer.forEach((n) => t.raise(n)), t.assign({
3616
+ handshakeBuffer: []
3617
+ });
3618
+ }),
3619
+ "remove request": A(({ context: e, enqueue: t, event: n }) => {
3620
+ S(n, ["request.success", "request.failed", "request.aborted"]), F(n.requestId), t.assign({ requests: e.requests.filter(({ id: s }) => s !== n.requestId) });
3621
+ }),
3622
+ "send response": x(({ event: e }) => (S(e, ["message.received", "heartbeat.received"]), {
3623
+ type: "request",
3624
+ data: {
3625
+ type: P,
3626
+ responseTo: e.message.data.id,
3627
+ data: void 0
3628
+ }
3629
+ })),
3630
+ "send handshake syn ack": x({
3631
+ type: "request",
3632
+ data: { type: Pt }
3633
+ }),
3634
+ "send pending messages": A(({ enqueue: e }) => {
3635
+ e.raise(({ context: t }) => ({
3636
+ type: "request",
3637
+ data: t.buffer.map(({ data: n, resolvable: s, options: r }) => ({
3638
+ data: n.data,
3639
+ type: n.type,
3640
+ expectResponse: !!s,
3641
+ resolvable: s,
3642
+ options: r
3643
+ }))
3644
+ })), e.emit(({ context: t }) => ({
3645
+ type: "buffer.flushed",
3646
+ messages: t.buffer.map(({ data: n }) => n)
3647
+ })), e.assign({
3648
+ buffer: []
3649
+ });
3650
+ }),
3651
+ "set connection config": M({
3652
+ channelId: ({ event: e }) => (S(e, "handshake.syn"), e.message.data.channelId),
3653
+ target: ({ event: e }) => (S(e, "handshake.syn"), e.message.source || void 0),
3654
+ targetOrigin: ({ event: e }) => (S(e, "handshake.syn"), e.message.origin)
3655
+ })
3656
+ },
3657
+ guards: {
3658
+ hasSource: ({ context: e }) => e.target !== null
3659
+ }
3660
+ }).createMachine({
3661
+ /** @xstate-layout N4IgpgJg5mDOIC5QDsD2EwGIBOYCOArnAC4B0sBAxpXLANoAMAuoqAA6qwCWxXqyrEAA9EAVgYAWUgEYJDUQA4JAZmUSJC0coDsAGhABPRNIYLSErdOkBOAGzbx227YUBfV-rQYc+IrDIAZgCGXAA2kIwsSCAc3Lz8giIIoiakqgBMDKbp2tYS0srp+kYI0ununuhgpFwQ4ZgQ-NVcyABuqADW1V7NdWAILe2UQfHIkZGCsTx8AtFJ6aKipAzWOtrpC7Z5BUWGiNoK6aS26RLW2tLaqkqqFSA9NX2YALa0QTCkuDRcrRHMk5xpgk5ogJLZSNZIVDoVCFLZiohbIVSLkXLZRHZDgxbHcHrV6rFiBNolNRolEVJbCsdGUzsoyhiEcllOC1DowelVmVrOUPPcqqQABZBZAQWDCjotKANJo1NqdboC4Wi8VBSXIKADeXDUbjf4kwFkkEILbg8RZMHKOzWKzKJkHJa086Xa4qZS4pUisUSqU+QgkYnsQ0zcnJaRLDbpZwKNQSBYspm2MEyC5KTnaDSSd18h7K71q32EwMxYPA0BJFLKY5yZxIrKSURM0RnFHSBTrQqQ9babQejBCr2q9XSiBcWCUfjIMCUIn6oNxEPGtTWFFR0RUy7iGzt+3Ip0XURXVZKPvVCfIKczyB+vyzqLzoGzcuIG0MGTyCztjRtjaJjbHVMNAUTdu1PUhz0vYhryLOcSwXMthBfK0ZGsLQGBZekCi0Jso1IdI23WG04zOE4wIg6coIgBox3Imdi1JRdnxNOxSHNSQkWtW0mTjMxMQ7fDzgcbNKn7WjKJeN4Pi+MAfj+e84MfUMFHbZZwxOHZNDyO09gQOQjmAhZJCM9IMjIycKOvQUwCCbBiAAI2sshpNkiB6NLJ9EIQBQbWOdJlMhYCUjbJkchXGsFmsJQMVsWl3BzKp4GiHoAXgjykgAWmkZZ6xy3LZF2EobCy6xsQWJQ42kE4FjA-EwBSxTjSRUhDgqkzgO2BxdykU4AvXFQ-KjMC8yHKV6qNJi6WOdcypcZsXGxe0JG0XySKjM5lKsMyLwsiAxsYzylDfONznUEqrmi+1ThkHqXDONbULi1wgA */
3662
+ id: "node",
3663
+ context: ({ input: e }) => ({
3664
+ buffer: [],
3665
+ channelId: null,
3666
+ connectTo: e.connectTo,
3667
+ domain: e.domain ?? Bt,
3668
+ handshakeBuffer: [],
3669
+ name: e.name,
3670
+ requests: [],
3671
+ target: void 0,
3672
+ targetOrigin: null
3673
+ }),
3674
+ // Always listen for handshake syn messages. The channel could have
3675
+ // disconnected without being able to notify the node, and so need to
3676
+ // re-establish the connection.
3677
+ invoke: {
3678
+ id: "listen for handshake syn",
3679
+ src: "listen",
3680
+ input: I({
3681
+ include: re,
3682
+ responseType: "handshake.syn"
3683
+ })
3684
+ },
3685
+ on: {
3686
+ "request.success": {
3687
+ actions: "remove request"
3688
+ },
3689
+ "request.failed": {
3690
+ actions: "remove request"
3691
+ },
3692
+ "request.aborted": {
3693
+ actions: "remove request"
3694
+ },
3695
+ "handshake.syn": {
3696
+ actions: "set connection config",
3697
+ target: ".handshaking"
3698
+ }
3699
+ },
3700
+ initial: "idle",
3701
+ states: {
3702
+ idle: {
3703
+ entry: [{ type: "emit status", params: { status: "idle" } }],
3704
+ on: {
3705
+ post: {
3706
+ actions: "buffer message"
3707
+ }
3708
+ }
3709
+ },
3710
+ handshaking: {
3711
+ guard: "hasSource",
3712
+ entry: ["send handshake syn ack", { type: "emit status", params: { status: "handshaking" } }],
3713
+ invoke: [
3714
+ {
3715
+ id: "listen for handshake ack",
3716
+ src: "listen",
3717
+ input: I({
3718
+ include: ie,
3719
+ count: 1,
3720
+ // Override the default `message.received` responseType to prevent
3721
+ // buffering the ack message. We transition to the connected state
3722
+ // using onDone instead of listening to this event using `on`
3723
+ responseType: "handshake.complete"
3724
+ }),
3725
+ onDone: "connected"
3726
+ },
3727
+ {
3728
+ id: "listen for disconnect",
3729
+ src: "listen",
3730
+ input: I({
3731
+ include: Y,
3732
+ count: 1,
3733
+ responseType: "disconnect"
3734
+ })
3735
+ },
3736
+ {
3737
+ id: "listen for messages",
3738
+ src: "listen",
3739
+ input: I({
3740
+ exclude: [
3741
+ Y,
3742
+ re,
3743
+ ie,
3744
+ Z,
3745
+ P
3746
+ ]
3747
+ })
3748
+ }
3749
+ ],
3750
+ on: {
3751
+ request: {
3752
+ actions: "create request"
3753
+ },
3754
+ post: {
3755
+ actions: "buffer message"
3756
+ },
3757
+ "message.received": {
3758
+ actions: "buffer handshake"
3759
+ },
3760
+ disconnect: {
3761
+ target: "idle"
3762
+ }
3763
+ }
3764
+ },
3765
+ connected: {
3766
+ entry: [
3767
+ "process pending handshakes",
3768
+ "send pending messages",
3769
+ { type: "emit status", params: { status: "connected" } }
3770
+ ],
3771
+ invoke: [
3772
+ {
3773
+ id: "listen for messages",
3774
+ src: "listen",
3775
+ input: I({
3776
+ exclude: [
3777
+ Y,
3778
+ re,
3779
+ ie,
3780
+ Z,
3781
+ P
3782
+ ]
3783
+ })
3784
+ },
3785
+ {
3786
+ id: "listen for heartbeat",
3787
+ src: "listen",
3788
+ input: I({
3789
+ include: Z,
3790
+ responseType: "heartbeat.received"
3791
+ })
3792
+ },
3793
+ {
3794
+ id: "listen for disconnect",
3795
+ src: "listen",
3796
+ input: I({
3797
+ include: Y,
3798
+ count: 1,
3799
+ responseType: "disconnect"
3800
+ })
3801
+ }
3802
+ ],
3803
+ on: {
3804
+ request: {
3805
+ actions: "create request"
3806
+ },
3807
+ post: {
3808
+ actions: "post message"
3809
+ },
3810
+ disconnect: {
3811
+ target: "idle"
3812
+ },
3813
+ "message.received": {
3814
+ actions: ["send response", "emit received message"]
3815
+ },
3816
+ "heartbeat.received": {
3817
+ actions: ["send response", "emit heartbeat"]
3818
+ }
3819
+ }
3820
+ }
3821
+ }
3822
+ }), sr = (e, t = Us()) => {
3823
+ const n = $(t, {
3824
+ input: e
3825
+ }), s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (u, c, l) => {
3826
+ const f = s.get(u) || /* @__PURE__ */ new Set();
3827
+ s.has(u) || s.set(u, f), f.add(c);
3828
+ const p = r.get(u);
3829
+ if (p) {
3830
+ const g = (l == null ? void 0 : l.replay) ?? 1;
3831
+ Array.from(p).slice(-g).forEach(({ data: m }) => c(m)), r.delete(u);
3832
+ }
3833
+ return () => {
3834
+ f.delete(c);
3835
+ };
3836
+ };
3837
+ let o;
3838
+ const a = (u, c) => {
3839
+ const { unsubscribe: l } = n.on(
3840
+ "status",
3841
+ (f) => {
3842
+ o = f.status, !(c && f.status !== c) && u(f.status);
3843
+ }
3844
+ );
3845
+ return o && u(o), l;
3846
+ }, d = (u, c) => {
3847
+ const l = { type: u, data: c };
3848
+ n.send({ type: "post", data: l });
3849
+ }, h = (u, c, l) => {
3850
+ const { responseTimeout: f = qs, signal: p, suppressWarnings: g } = l || {}, m = Hs(), v = { type: u, data: c };
3851
+ return n.send({
3852
+ type: "post",
3853
+ data: v,
3854
+ resolvable: m,
3855
+ options: { responseTimeout: f, signal: p, suppressWarnings: g }
3856
+ }), m.promise;
3857
+ };
3858
+ n.on("message", ({ message: u }) => {
3859
+ const c = s.get(u.type);
3860
+ if (c) {
3861
+ c.forEach((f) => f(u.data));
3862
+ return;
3863
+ }
3864
+ const l = r.get(u.type);
3865
+ l ? l.add(u) : r.set(u.type, /* @__PURE__ */ new Set([u]));
3866
+ });
3867
+ const y = () => {
3868
+ n.stop();
3869
+ };
3870
+ return {
3871
+ actor: n,
3872
+ fetch: h,
3873
+ machine: t,
3874
+ on: i,
3875
+ onStatus: a,
3876
+ post: d,
3877
+ start: () => (n.start(), y),
3878
+ stop: y
3879
+ };
3880
+ }, Ws = "#FF5500", oe = "#0D0E12", rr = /* @__PURE__ */ pt(function(e, t) {
3881
+ const { dark: n, ...s } = e, r = n ? Ce.hex : oe;
3882
+ return /* @__PURE__ */ gt(
3883
+ "svg",
3884
+ {
3885
+ "data-sanity-icon": "sanity-logo",
3886
+ height: "1em",
3887
+ viewBox: "0 0 435 154",
3888
+ fill: "none",
3889
+ xmlns: "http://www.w3.org/2000/svg",
3890
+ ...s,
3891
+ ref: t,
3892
+ children: [
3893
+ /* @__PURE__ */ R(
3894
+ "path",
3895
+ {
3896
+ d: "M44.883 52.4463C33.4181 43.7972 21.8121 37.1021 21.8121 27.3381C21.8121 21.482 26.9827 15.4851 34.1181 15.4851C46.983 15.4851 54.5302 28.8754 61.942 45.6103H66.5538V7.11182H34.3946C7.82952 7.11182 0 23.1543 0 35.7055C0 52.1647 13.5649 61.9287 28.9416 73.365C39.7064 81.3158 48.7948 88.7092 48.7948 97.2175C48.7948 106.424 42.5006 111.723 34.5299 111.723C26.0004 111.723 13.4178 100.562 4.60595 77.4137H0V120.096H36.777C59.4302 120.096 70.7539 102.24 71.1716 87.876C71.7304 71.1411 57.3302 61.7937 44.883 52.4463Z",
3897
+ fill: r
3898
+ }
3899
+ ),
3900
+ /* @__PURE__ */ R(
3901
+ "path",
3902
+ {
3903
+ d: "M145.002 106.841V61.7878C145.002 42.2598 132.837 37.1021 115.219 37.1021H83.8952L84.0364 68.9054H89.2071C94.6601 55.3743 102.49 45.4754 110.878 45.4754C118.149 45.4754 121.366 51.7539 121.366 58.3082V64.4459C109.619 71.4227 78.301 77.2788 78.301 98.4791C78.301 110.754 86.8306 120.935 99.2778 120.935C110.043 120.935 117.454 113.958 121.231 105.732C121.931 112.568 126.402 120.096 136.614 120.096H152.696V113.958C147.525 113.958 145.008 110.473 145.008 106.847L145.002 106.841ZM120.949 99.8639C118.713 103.074 115.213 106.7 111.019 106.7C105.148 106.7 101.372 102.234 101.372 93.3096C101.372 83.129 115.072 76.5746 120.949 71.6926V99.8697V99.8639Z",
3904
+ fill: r
3905
+ }
3906
+ ),
3907
+ /* @__PURE__ */ R(
3908
+ "path",
3909
+ {
3910
+ d: "M270.145 28.4529C279.092 28.4529 284.686 22.1744 284.686 14.0885C284.686 6.00274 279.092 0 270.145 0C261.198 0 255.462 5.99688 255.462 14.0885C255.462 22.1802 261.474 28.4529 270.145 28.4529Z",
3911
+ fill: r
3912
+ }
3913
+ ),
3914
+ /* @__PURE__ */ R(
3915
+ "path",
3916
+ {
3917
+ d: "M409.135 37.102V43.2397C417.947 43.2397 420.459 47.84 416.129 60.2563L405.641 88.5683L392.217 54.1186C389.141 47.4234 390.817 43.2397 397.252 43.2397V37.102H330.557V9.20654H324.263C322.446 18.6889 312.516 37.102 295.598 37.102V43.2397H306.504V100.568C306.504 110.191 309.722 121.07 328.457 121.07H357.54V89.5482H352.37C350.269 96.9417 345.94 111.723 336.569 111.723C331.399 111.723 330.557 106.002 330.557 101.401V45.8861H357.264C360.481 45.8861 363.834 46.3027 365.511 50.2106L393.894 120.231C388.441 132.647 379.07 134.595 362.293 129.437V153.988C366.629 153.988 377.811 154.129 379.77 153.572C390.817 150.362 398.364 128.745 401.441 120.378L425.488 55.521C428.147 48.4092 430.382 43.2456 434.994 43.2456V37.1079H409.129L409.135 37.102Z",
3918
+ fill: r
3919
+ }
3920
+ ),
3921
+ /* @__PURE__ */ R(
3922
+ "path",
3923
+ {
3924
+ d: "M237.703 106.841V59.2764C237.703 44.3546 230.574 35.4238 216.45 35.4238C204.009 35.4238 196.803 44.0319 191.279 52.0414V37.0961H159.396V43.2338C164.849 43.2338 167.226 46.5785 167.226 50.4864V106.835C167.226 110.602 164.432 113.947 159.396 113.947V120.084H199.109V113.947C194.073 113.947 191.279 110.602 191.279 106.835V59.646C194.503 55.3743 198.214 50.7681 204.42 50.7681C210.291 50.7681 213.65 55.5093 213.65 61.2303V106.841C213.65 110.608 210.856 113.952 205.82 113.952V120.09H245.533V113.952C240.497 113.952 237.703 110.608 237.703 106.841Z",
3925
+ fill: r
3926
+ }
3927
+ ),
3928
+ /* @__PURE__ */ R(
3929
+ "path",
3930
+ {
3931
+ d: "M284.127 106.841V37.1021H252.245V43.2398C257.698 43.2398 260.074 46.5844 260.074 50.4923V106.841C260.074 110.608 257.28 113.952 252.245 113.952V120.09H291.957V113.952C286.922 113.952 284.127 110.608 284.127 106.841Z",
3932
+ fill: r
3933
+ }
3934
+ )
3935
+ ]
3936
+ }
3937
+ );
3938
+ }), ht = {
3939
+ light: { bg: Ce.hex, fg: oe },
3940
+ dark: { bg: oe, fg: Ce.hex },
3941
+ default: { bg: Ws, fg: oe }
3942
+ }, ir = /* @__PURE__ */ pt(function(e, t) {
3943
+ const { scheme: n = "default", color: s, ...r } = e, i = (s == null ? void 0 : s.bg1) || ht[n].bg, o = (s == null ? void 0 : s.fg) || ht[n].fg;
3944
+ return /* @__PURE__ */ gt(
3945
+ "svg",
3946
+ {
3947
+ "data-sanity-icon": "sanity-monogram",
3948
+ height: "1em",
3949
+ viewBox: "0 0 192 192",
3950
+ fill: "none",
3951
+ xmlns: "http://www.w3.org/2000/svg",
3952
+ ...r,
3953
+ ref: t,
3954
+ children: [
3955
+ /* @__PURE__ */ R("rect", { width: "192", height: "192", fill: i }),
3956
+ /* @__PURE__ */ R(
3957
+ "path",
3958
+ {
3959
+ d: "M160.077 112.697L154.865 103.629L129.659 118.981L157.655 83.3368L161.888 80.8533L160.841 79.2802L162.764 76.8232L153.929 69.4699L149.886 74.6225L68.2657 122.375L98.4429 86.0855L154.651 55.2759L149.311 44.953L118.696 61.7277L133.771 43.6096L125.134 36L91.2055 76.7966L57.5083 95.2771L83.307 61.1709L99.4731 52.757L94.3391 42.3192L47.2403 66.8361L60.0839 49.8405L51.1123 42.6551L24 78.5378L24.4207 78.8736L29.486 89.1877L59.543 73.5354L32.1474 109.745L36.6375 113.342L39.3075 118.504L70.9528 101.154L36.1052 143.065L44.742 150.674L46.4762 148.588L130.543 99.2454L102.632 134.792L103.088 135.172L103.045 135.199L108.831 145.265L145.954 122.649L131.659 145.716L141.24 152L164 115.278L160.077 112.697Z",
3960
+ fill: o
3961
+ }
3962
+ )
3963
+ ]
3964
+ }
3965
+ );
3966
+ });
3967
+ export {
3968
+ sr as A,
3969
+ Qs as B,
3970
+ rr as C,
3971
+ Bt as D,
3972
+ Y as M,
3973
+ ir as S,
3974
+ zt as a,
3975
+ Wt as b,
3976
+ Gt as c,
3977
+ Z as d,
3978
+ P as e,
3979
+ ie as f,
3980
+ Pt as g,
3981
+ re as h,
3982
+ M as i,
3983
+ nr as j,
3984
+ er as k,
3985
+ Zs as l,
3986
+ Fs as m,
3987
+ Ks as n,
3988
+ $ as o,
3989
+ pe as p,
3990
+ Ns as q,
3991
+ A as r,
3992
+ ze as s,
3993
+ S as t,
3994
+ tr as u,
3995
+ B as v,
3996
+ Ys as w,
3997
+ Xs as x,
3998
+ x as y,
3999
+ rs as z
4000
+ };
4001
+ //# sourceMappingURL=index-DCkQlgdi.mjs.map