nmea-web-serial 1.1.2 → 1.1.4

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.
@@ -1,2388 +1,6 @@
1
- function yn() {
2
- if (typeof globalThis < "u")
3
- return globalThis;
4
- if (typeof self < "u")
5
- return self;
6
- if (typeof window < "u")
7
- return window;
8
- if (typeof global < "u")
9
- return global;
10
- }
11
- function Sn() {
12
- const e = yn();
13
- if (e.__xstate__)
14
- return e.__xstate__;
15
- }
16
- const _n = (e) => {
17
- if (typeof window > "u")
18
- return;
19
- const t = Sn();
20
- t && t.register(e);
21
- };
22
- class dt {
23
- constructor(t) {
24
- this._process = t, this._active = !1, this._current = null, this._last = null;
25
- }
26
- start() {
27
- this._active = !0, this.flush();
28
- }
29
- clear() {
30
- this._current && (this._current.next = null, this._last = this._current);
31
- }
32
- enqueue(t) {
33
- const n = {
34
- value: t,
35
- next: null
36
- };
37
- if (this._current) {
38
- this._last.next = n, this._last = n;
39
- return;
40
- }
41
- this._current = n, this._last = n, this._active && this.flush();
42
- }
43
- flush() {
44
- for (; this._current; ) {
45
- const t = this._current;
46
- this._process(t.value), this._current = t.next;
47
- }
48
- this._last = null;
49
- }
50
- }
51
- const zt = ".", bn = "", Jt = "", Tn = "#", In = "*", Zt = "xstate.init", wn = "xstate.error", we = "xstate.stop";
52
- function Pn(e, t) {
53
- return {
54
- type: `xstate.after.${e}.${t}`
55
- };
56
- }
57
- function Ke(e, t) {
58
- return {
59
- type: `xstate.done.state.${e}`,
60
- output: t
61
- };
62
- }
63
- function kn(e, t) {
64
- return {
65
- type: `xstate.done.actor.${e}`,
66
- output: t,
67
- actorId: e
68
- };
69
- }
70
- function Yt(e, t) {
71
- return {
72
- type: `xstate.error.actor.${e}`,
73
- error: t,
74
- actorId: e
75
- };
76
- }
77
- function Xt(e) {
78
- return {
79
- type: Zt,
80
- input: e
81
- };
82
- }
83
- function j(e) {
84
- setTimeout(() => {
85
- throw e;
86
- });
87
- }
88
- const Dn = typeof Symbol == "function" && Symbol.observable || "@@observable";
89
- function Qt(e, t) {
90
- const n = ft(e), r = ft(t);
91
- return typeof r == "string" ? typeof n == "string" ? r === n : !1 : typeof n == "string" ? n in r : Object.keys(n).every((i) => i in r ? Qt(n[i], r[i]) : !1);
92
- }
93
- function Qe(e) {
94
- if (en(e))
95
- return e;
96
- const t = [];
97
- let n = "";
98
- for (let r = 0; r < e.length; r++) {
99
- switch (e.charCodeAt(r)) {
100
- // \
101
- case 92:
102
- n += e[r + 1], r++;
103
- continue;
104
- // .
105
- case 46:
106
- t.push(n), n = "";
107
- continue;
108
- }
109
- n += e[r];
110
- }
111
- return t.push(n), t;
112
- }
113
- function ft(e) {
114
- if (ir(e))
115
- return e.value;
116
- if (typeof e != "string")
117
- return e;
118
- const t = Qe(e);
119
- return En(t);
120
- }
121
- function En(e) {
122
- if (e.length === 1)
123
- return e[0];
124
- const t = {};
125
- let n = t;
126
- for (let r = 0; r < e.length - 1; r++)
127
- if (r === e.length - 2)
128
- n[e[r]] = e[r + 1];
129
- else {
130
- const i = n;
131
- n = {}, i[e[r]] = n;
132
- }
133
- return t;
134
- }
135
- function lt(e, t) {
136
- const n = {}, r = Object.keys(e);
137
- for (let i = 0; i < r.length; i++) {
138
- const o = r[i];
139
- n[o] = t(e[o], o, e, i);
140
- }
141
- return n;
142
- }
143
- function $t(e) {
144
- return en(e) ? e : [e];
145
- }
146
- function x(e) {
147
- return e === void 0 ? [] : $t(e);
148
- }
149
- function ze(e, t, n, r) {
150
- return typeof e == "function" ? e({
151
- context: t,
152
- event: n,
153
- self: r
154
- }) : e;
155
- }
156
- function en(e) {
157
- return Array.isArray(e);
158
- }
159
- function An(e) {
160
- return e.type.startsWith("xstate.error.actor");
161
- }
162
- function Z(e) {
163
- return $t(e).map((t) => typeof t > "u" || typeof t == "string" ? {
164
- target: t
165
- } : t);
166
- }
167
- function tn(e) {
168
- if (!(e === void 0 || e === bn))
169
- return x(e);
170
- }
171
- function Je(e, t, n) {
172
- const r = typeof e == "object", i = r ? e : void 0;
173
- return {
174
- next: (r ? e.next : e)?.bind(i),
175
- error: (r ? e.error : t)?.bind(i),
176
- complete: (r ? e.complete : n)?.bind(i)
177
- };
178
- }
179
- function ht(e, t) {
180
- return `${t}.${e}`;
181
- }
182
- function $e(e, t) {
183
- const n = t.match(/^xstate\.invoke\.(\d+)\.(.*)/);
184
- if (!n)
185
- return e.implementations.actors[t];
186
- const [, r, i] = n, s = e.getStateNodeById(i).config.invoke;
187
- return (Array.isArray(s) ? s[r] : s).src;
188
- }
189
- function pt(e, t) {
190
- return `${e.sessionId}.${t}`;
191
- }
192
- let Mn = 0;
193
- function On(e, t) {
194
- const n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new Set(), s = {}, {
195
- clock: a,
196
- logger: c
197
- } = t, u = {
198
- schedule: (d, p, g, y, I = Math.random().toString(36).slice(2)) => {
199
- const C = {
200
- source: d,
201
- target: p,
202
- event: g,
203
- delay: y,
204
- id: I,
205
- startedAt: Date.now()
206
- }, R = pt(d, I);
207
- l._snapshot._scheduledEvents[R] = C;
208
- const V = a.setTimeout(() => {
209
- delete s[R], delete l._snapshot._scheduledEvents[R], l._relay(d, p, g);
210
- }, y);
211
- s[R] = V;
212
- },
213
- cancel: (d, p) => {
214
- const g = pt(d, p), y = s[g];
215
- delete s[g], delete l._snapshot._scheduledEvents[g], y !== void 0 && a.clearTimeout(y);
216
- },
217
- cancelAll: (d) => {
218
- for (const p in l._snapshot._scheduledEvents) {
219
- const g = l._snapshot._scheduledEvents[p];
220
- g.source === d && u.cancel(d, g.id);
221
- }
222
- }
223
- }, f = (d) => {
224
- if (!o.size)
225
- return;
226
- const p = {
227
- ...d,
228
- rootId: e.sessionId
229
- };
230
- o.forEach((g) => g.next?.(p));
231
- }, l = {
232
- _snapshot: {
233
- _scheduledEvents: (t?.snapshot && t.snapshot.scheduler) ?? {}
234
- },
235
- _bookId: () => `x:${Mn++}`,
236
- _register: (d, p) => (n.set(d, p), d),
237
- _unregister: (d) => {
238
- n.delete(d.sessionId);
239
- const p = i.get(d);
240
- p !== void 0 && (r.delete(p), i.delete(d));
241
- },
242
- get: (d) => r.get(d),
243
- getAll: () => Object.fromEntries(r.entries()),
244
- _set: (d, p) => {
245
- const g = r.get(d);
246
- if (g && g !== p)
247
- throw new Error(`Actor with system ID '${d}' already exists.`);
248
- r.set(d, p), i.set(p, d);
249
- },
250
- inspect: (d) => {
251
- const p = Je(d);
252
- return o.add(p), {
253
- unsubscribe() {
254
- o.delete(p);
255
- }
256
- };
257
- },
258
- _sendInspectionEvent: f,
259
- _relay: (d, p, g) => {
260
- l._sendInspectionEvent({
261
- type: "@xstate.event",
262
- sourceRef: d,
263
- actorRef: p,
264
- event: g
265
- }), p._send(g);
266
- },
267
- scheduler: u,
268
- getSnapshot: () => ({
269
- _scheduledEvents: {
270
- ...l._snapshot._scheduledEvents
271
- }
272
- }),
273
- start: () => {
274
- const d = l._snapshot._scheduledEvents;
275
- l._snapshot._scheduledEvents = {};
276
- for (const p in d) {
277
- const {
278
- source: g,
279
- target: y,
280
- event: I,
281
- delay: C,
282
- id: R
283
- } = d[p];
284
- u.schedule(g, y, I, C, R);
285
- }
286
- },
287
- _clock: a,
288
- _logger: c
289
- };
290
- return l;
291
- }
292
- let He = !1;
293
- const et = 1;
294
- let A = /* @__PURE__ */ (function(e) {
295
- return e[e.NotStarted = 0] = "NotStarted", e[e.Running = 1] = "Running", e[e.Stopped = 2] = "Stopped", e;
296
- })({});
297
- const Fn = {
298
- clock: {
299
- setTimeout: (e, t) => setTimeout(e, t),
300
- clearTimeout: (e) => clearTimeout(e)
301
- },
302
- logger: console.log.bind(console),
303
- devTools: !1
304
- };
305
- class Cn {
306
- /**
307
- * Creates a new actor instance for the given logic with the provided options,
308
- * if any.
309
- *
310
- * @param logic The logic to create an actor from
311
- * @param options Actor options
312
- */
313
- constructor(t, n) {
314
- this.logic = t, this._snapshot = void 0, this.clock = void 0, this.options = void 0, this.id = void 0, this.mailbox = new dt(this._process.bind(this)), this.observers = /* @__PURE__ */ new Set(), this.eventListeners = /* @__PURE__ */ new Map(), this.logger = void 0, this._processingStatus = A.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 = [];
315
- const r = {
316
- ...Fn,
317
- ...n
318
- }, {
319
- clock: i,
320
- logger: o,
321
- parent: s,
322
- syncSnapshot: a,
323
- id: c,
324
- systemId: u,
325
- inspect: f
326
- } = r;
327
- this.system = s ? s.system : On(this, {
328
- clock: i,
329
- logger: o
330
- }), f && !s && this.system.inspect(Je(f)), this.sessionId = this.system._bookId(), this.id = c ?? this.sessionId, this.logger = n?.logger ?? this.system._logger, this.clock = n?.clock ?? this.system._clock, this._parent = s, this._syncSnapshot = a, this.options = r, this.src = r.src ?? t, this.ref = this, this._actorScope = {
331
- self: this,
332
- id: this.id,
333
- sessionId: this.sessionId,
334
- logger: this.logger,
335
- defer: (l) => {
336
- this._deferred.push(l);
337
- },
338
- system: this.system,
339
- stopChild: (l) => {
340
- if (l._parent !== this)
341
- throw new Error(`Cannot stop child actor ${l.id} of ${this.id} because it is not a child`);
342
- l._stop();
343
- },
344
- emit: (l) => {
345
- const d = this.eventListeners.get(l.type), p = this.eventListeners.get("*");
346
- if (!d && !p)
347
- return;
348
- const g = [...d ? d.values() : [], ...p ? p.values() : []];
349
- for (const y of g)
350
- try {
351
- y(l);
352
- } catch (I) {
353
- j(I);
354
- }
355
- },
356
- actionExecutor: (l) => {
357
- const d = () => {
358
- if (this._actorScope.system._sendInspectionEvent({
359
- type: "@xstate.action",
360
- actorRef: this,
361
- action: {
362
- type: l.type,
363
- params: l.params
364
- }
365
- }), !l.exec)
366
- return;
367
- const p = He;
368
- try {
369
- He = !0, l.exec(l.info, l.params);
370
- } finally {
371
- He = p;
372
- }
373
- };
374
- this._processingStatus === A.Running ? d() : this._deferred.push(d);
375
- }
376
- }, this.send = this.send.bind(this), this.system._sendInspectionEvent({
377
- type: "@xstate.actor",
378
- actorRef: this
379
- }), u && (this.systemId = u, this.system._set(u, this)), this._initState(n?.snapshot ?? n?.state), u && this._snapshot.status !== "active" && this.system._unregister(this);
380
- }
381
- _initState(t) {
382
- try {
383
- this._snapshot = t ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(t, this._actorScope) : t : this.logic.getInitialSnapshot(this._actorScope, this.options?.input);
384
- } catch (n) {
385
- this._snapshot = {
386
- status: "error",
387
- output: void 0,
388
- error: n
389
- };
390
- }
391
- }
392
- update(t, n) {
393
- this._snapshot = t;
394
- let r;
395
- for (; r = this._deferred.shift(); )
396
- try {
397
- r();
398
- } catch (i) {
399
- this._deferred.length = 0, this._snapshot = {
400
- ...t,
401
- status: "error",
402
- error: i
403
- };
404
- }
405
- switch (this._snapshot.status) {
406
- case "active":
407
- for (const i of this.observers)
408
- try {
409
- i.next?.(t);
410
- } catch (o) {
411
- j(o);
412
- }
413
- break;
414
- case "done":
415
- for (const i of this.observers)
416
- try {
417
- i.next?.(t);
418
- } catch (o) {
419
- j(o);
420
- }
421
- this._stopProcedure(), this._complete(), this._doneEvent = kn(this.id, this._snapshot.output), this._parent && this.system._relay(this, this._parent, this._doneEvent);
422
- break;
423
- case "error":
424
- this._error(this._snapshot.error);
425
- break;
426
- }
427
- this.system._sendInspectionEvent({
428
- type: "@xstate.snapshot",
429
- actorRef: this,
430
- event: n,
431
- snapshot: t
432
- });
433
- }
434
- /**
435
- * Subscribe an observer to an actor’s snapshot values.
436
- *
437
- * @remarks
438
- * The observer will receive the actor’s snapshot value when it is emitted.
439
- * The observer can be:
440
- *
441
- * - A plain function that receives the latest snapshot, or
442
- * - An observer object whose `.next(snapshot)` method receives the latest
443
- * snapshot
444
- *
445
- * @example
446
- *
447
- * ```ts
448
- * // Observer as a plain function
449
- * const subscription = actor.subscribe((snapshot) => {
450
- * console.log(snapshot);
451
- * });
452
- * ```
453
- *
454
- * @example
455
- *
456
- * ```ts
457
- * // Observer as an object
458
- * const subscription = actor.subscribe({
459
- * next(snapshot) {
460
- * console.log(snapshot);
461
- * },
462
- * error(err) {
463
- * // ...
464
- * },
465
- * complete() {
466
- * // ...
467
- * }
468
- * });
469
- * ```
470
- *
471
- * The return value of `actor.subscribe(observer)` is a subscription object
472
- * that has an `.unsubscribe()` method. You can call
473
- * `subscription.unsubscribe()` to unsubscribe the observer:
474
- *
475
- * @example
476
- *
477
- * ```ts
478
- * const subscription = actor.subscribe((snapshot) => {
479
- * // ...
480
- * });
481
- *
482
- * // Unsubscribe the observer
483
- * subscription.unsubscribe();
484
- * ```
485
- *
486
- * When the actor is stopped, all of its observers will automatically be
487
- * unsubscribed.
488
- *
489
- * @param observer - Either a plain function that receives the latest
490
- * snapshot, or an observer object whose `.next(snapshot)` method receives
491
- * the latest snapshot
492
- */
493
- subscribe(t, n, r) {
494
- const i = Je(t, n, r);
495
- if (this._processingStatus !== A.Stopped)
496
- this.observers.add(i);
497
- else
498
- switch (this._snapshot.status) {
499
- case "done":
500
- try {
501
- i.complete?.();
502
- } catch (o) {
503
- j(o);
504
- }
505
- break;
506
- case "error": {
507
- const o = this._snapshot.error;
508
- if (!i.error)
509
- j(o);
510
- else
511
- try {
512
- i.error(o);
513
- } catch (s) {
514
- j(s);
515
- }
516
- break;
517
- }
518
- }
519
- return {
520
- unsubscribe: () => {
521
- this.observers.delete(i);
522
- }
523
- };
524
- }
525
- on(t, n) {
526
- let r = this.eventListeners.get(t);
527
- r || (r = /* @__PURE__ */ new Set(), this.eventListeners.set(t, r));
528
- const i = n.bind(void 0);
529
- return r.add(i), {
530
- unsubscribe: () => {
531
- r.delete(i);
532
- }
533
- };
534
- }
535
- /** Starts the Actor from the initial state */
536
- start() {
537
- if (this._processingStatus === A.Running)
538
- return this;
539
- this._syncSnapshot && this.subscribe({
540
- next: (r) => {
541
- r.status === "active" && this.system._relay(this, this._parent, {
542
- type: `xstate.snapshot.${this.id}`,
543
- snapshot: r
544
- });
545
- },
546
- error: () => {
547
- }
548
- }), this.system._register(this.sessionId, this), this.systemId && this.system._set(this.systemId, this), this._processingStatus = A.Running;
549
- const t = Xt(this.options.input);
550
- switch (this.system._sendInspectionEvent({
551
- type: "@xstate.event",
552
- sourceRef: this._parent,
553
- actorRef: this,
554
- event: t
555
- }), this._snapshot.status) {
556
- case "done":
557
- return this.update(this._snapshot, t), this;
558
- case "error":
559
- return this._error(this._snapshot.error), this;
560
- }
561
- if (this._parent || this.system.start(), this.logic.start)
562
- try {
563
- this.logic.start(this._snapshot, this._actorScope);
564
- } catch (r) {
565
- return this._snapshot = {
566
- ...this._snapshot,
567
- status: "error",
568
- error: r
569
- }, this._error(r), this;
570
- }
571
- return this.update(this._snapshot, t), this.options.devTools && this.attachDevTools(), this.mailbox.start(), this;
572
- }
573
- _process(t) {
574
- let n, r;
575
- try {
576
- n = this.logic.transition(this._snapshot, t, this._actorScope);
577
- } catch (i) {
578
- r = {
579
- err: i
580
- };
581
- }
582
- if (r) {
583
- const {
584
- err: i
585
- } = r;
586
- this._snapshot = {
587
- ...this._snapshot,
588
- status: "error",
589
- error: i
590
- }, this._error(i);
591
- return;
592
- }
593
- this.update(n, t), t.type === we && (this._stopProcedure(), this._complete());
594
- }
595
- _stop() {
596
- return this._processingStatus === A.Stopped ? this : (this.mailbox.clear(), this._processingStatus === A.NotStarted ? (this._processingStatus = A.Stopped, this) : (this.mailbox.enqueue({
597
- type: we
598
- }), this));
599
- }
600
- /** Stops the Actor and unsubscribe all listeners. */
601
- stop() {
602
- if (this._parent)
603
- throw new Error("A non-root actor cannot be stopped directly.");
604
- return this._stop();
605
- }
606
- _complete() {
607
- for (const t of this.observers)
608
- try {
609
- t.complete?.();
610
- } catch (n) {
611
- j(n);
612
- }
613
- this.observers.clear();
614
- }
615
- _reportError(t) {
616
- if (!this.observers.size) {
617
- this._parent || j(t);
618
- return;
619
- }
620
- let n = !1;
621
- for (const r of this.observers) {
622
- const i = r.error;
623
- n ||= !i;
624
- try {
625
- i?.(t);
626
- } catch (o) {
627
- j(o);
628
- }
629
- }
630
- this.observers.clear(), n && j(t);
631
- }
632
- _error(t) {
633
- this._stopProcedure(), this._reportError(t), this._parent && this.system._relay(this, this._parent, Yt(this.id, t));
634
- }
635
- // TODO: atm children don't belong entirely to the actor so
636
- // in a way - it's not even super aware of them
637
- // so we can't stop them from here but we really should!
638
- // right now, they are being stopped within the machine's transition
639
- // but that could throw and leave us with "orphaned" active actors
640
- _stopProcedure() {
641
- return this._processingStatus !== A.Running ? this : (this.system.scheduler.cancelAll(this), this.mailbox.clear(), this.mailbox = new dt(this._process.bind(this)), this._processingStatus = A.Stopped, this.system._unregister(this), this);
642
- }
643
- /** @internal */
644
- _send(t) {
645
- this._processingStatus !== A.Stopped && this.mailbox.enqueue(t);
646
- }
647
- /**
648
- * Sends an event to the running Actor to trigger a transition.
649
- *
650
- * @param event The event to send
651
- */
652
- send(t) {
653
- this.system._relay(void 0, this, t);
654
- }
655
- attachDevTools() {
656
- const {
657
- devTools: t
658
- } = this.options;
659
- t && (typeof t == "function" ? t : _n)(this);
660
- }
661
- toJSON() {
662
- return {
663
- xstate$$type: et,
664
- id: this.id
665
- };
666
- }
667
- /**
668
- * Obtain the internal state of the actor, which can be persisted.
669
- *
670
- * @remarks
671
- * The internal state can be persisted from any actor, not only machines.
672
- *
673
- * Note that the persisted state is not the same as the snapshot from
674
- * {@link Actor.getSnapshot}. Persisted state represents the internal state of
675
- * the actor, while snapshots represent the actor's last emitted value.
676
- *
677
- * Can be restored with {@link ActorOptions.state}
678
- * @see https://stately.ai/docs/persistence
679
- */
680
- getPersistedSnapshot(t) {
681
- return this.logic.getPersistedSnapshot(this._snapshot, t);
682
- }
683
- [Dn]() {
684
- return this;
685
- }
686
- /**
687
- * Read an actor’s snapshot synchronously.
688
- *
689
- * @remarks
690
- * The snapshot represent an actor's last emitted value.
691
- *
692
- * When an actor receives an event, its internal state may change. An actor
693
- * may emit a snapshot when a state transition occurs.
694
- *
695
- * Note that some actors, such as callback actors generated with
696
- * `fromCallback`, will not emit snapshots.
697
- * @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
698
- * @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
699
- */
700
- getSnapshot() {
701
- return this._snapshot;
702
- }
703
- }
704
- function Pe(e, ...[t]) {
705
- return new Cn(e, t);
706
- }
707
- function Rn(e, t, n, r, {
708
- sendId: i
709
- }) {
710
- const o = typeof i == "function" ? i(n, r) : i;
711
- return [t, {
712
- sendId: o
713
- }, void 0];
714
- }
715
- function Nn(e, t) {
716
- e.defer(() => {
717
- e.system.scheduler.cancel(e.self, t.sendId);
718
- });
719
- }
720
- function tt(e) {
721
- function t(n, r) {
722
- }
723
- return t.type = "xstate.cancel", t.sendId = e, t.resolve = Rn, t.execute = Nn, t;
724
- }
725
- function jn(e, t, n, r, {
726
- id: i,
727
- systemId: o,
728
- src: s,
729
- input: a,
730
- syncSnapshot: c
731
- }) {
732
- const u = typeof s == "string" ? $e(t.machine, s) : s, f = typeof i == "function" ? i(n) : i;
733
- let l, d;
734
- return u && (d = typeof a == "function" ? a({
735
- context: t.context,
736
- event: n.event,
737
- self: e.self
738
- }) : a, l = Pe(u, {
739
- id: f,
740
- src: s,
741
- parent: e.self,
742
- syncSnapshot: c,
743
- systemId: o,
744
- input: d
745
- })), [U(t, {
746
- children: {
747
- ...t.children,
748
- [f]: l
749
- }
750
- }), {
751
- id: i,
752
- systemId: o,
753
- actorRef: l,
754
- src: s,
755
- input: d
756
- }, void 0];
757
- }
758
- function Gn(e, {
759
- actorRef: t
760
- }) {
761
- t && e.defer(() => {
762
- t._processingStatus !== A.Stopped && t.start();
763
- });
764
- }
765
- function nt(...[e, {
766
- id: t,
767
- systemId: n,
768
- input: r,
769
- syncSnapshot: i = !1
770
- } = {}]) {
771
- function o(s, a) {
772
- }
773
- return o.type = "xstate.spawnChild", o.id = t, o.systemId = n, o.src = e, o.input = r, o.syncSnapshot = i, o.resolve = jn, o.execute = Gn, o;
774
- }
775
- function Ln(e, t, n, r, {
776
- actorRef: i
777
- }) {
778
- const o = typeof i == "function" ? i(n, r) : i, s = typeof o == "string" ? t.children[o] : o;
779
- let a = t.children;
780
- return s && (a = {
781
- ...a
782
- }, delete a[s.id]), [U(t, {
783
- children: a
784
- }), s, void 0];
785
- }
786
- function xn(e, t) {
787
- if (t) {
788
- if (e.system._unregister(t), t._processingStatus !== A.Running) {
789
- e.stopChild(t);
790
- return;
791
- }
792
- e.defer(() => {
793
- e.stopChild(t);
794
- });
795
- }
796
- }
797
- function Ce(e) {
798
- function t(n, r) {
799
- }
800
- return t.type = "xstate.stopChild", t.actorRef = e, t.resolve = Ln, t.execute = xn, t;
801
- }
802
- function Re(e, t, n, r) {
803
- const {
804
- machine: i
805
- } = r, o = typeof e == "function", s = o ? e : i.implementations.guards[typeof e == "string" ? e : e.type];
806
- if (!o && !s)
807
- throw new Error(`Guard '${typeof e == "string" ? e : e.type}' is not implemented.'.`);
808
- if (typeof s != "function")
809
- return Re(s, t, n, r);
810
- const a = {
811
- context: t,
812
- event: n
813
- }, c = o || typeof e == "string" ? void 0 : "params" in e ? typeof e.params == "function" ? e.params({
814
- context: t,
815
- event: n
816
- }) : e.params : void 0;
817
- return "check" in s ? s.check(
818
- r,
819
- a,
820
- s
821
- // this holds all params
822
- ) : s(a, c);
823
- }
824
- const rt = (e) => e.type === "atomic" || e.type === "final";
825
- function X(e) {
826
- return Object.values(e.states).filter((t) => t.type !== "history");
827
- }
828
- function ke(e, t) {
829
- const n = [];
830
- if (t === e)
831
- return n;
832
- let r = e.parent;
833
- for (; r && r !== t; )
834
- n.push(r), r = r.parent;
835
- return n;
836
- }
837
- function Ae(e) {
838
- const t = new Set(e), n = rn(t);
839
- for (const r of t)
840
- if (r.type === "compound" && (!n.get(r) || !n.get(r).length))
841
- gt(r).forEach((i) => t.add(i));
842
- else if (r.type === "parallel") {
843
- for (const i of X(r))
844
- if (i.type !== "history" && !t.has(i)) {
845
- const o = gt(i);
846
- for (const s of o)
847
- t.add(s);
848
- }
849
- }
850
- for (const r of t) {
851
- let i = r.parent;
852
- for (; i; )
853
- t.add(i), i = i.parent;
854
- }
855
- return t;
856
- }
857
- function nn(e, t) {
858
- const n = t.get(e);
859
- if (!n)
860
- return {};
861
- if (e.type === "compound") {
862
- const i = n[0];
863
- if (i) {
864
- if (rt(i))
865
- return i.key;
866
- } else
867
- return {};
868
- }
869
- const r = {};
870
- for (const i of n)
871
- r[i.key] = nn(i, t);
872
- return r;
873
- }
874
- function rn(e) {
875
- const t = /* @__PURE__ */ new Map();
876
- for (const n of e)
877
- t.has(n) || t.set(n, []), n.parent && (t.has(n.parent) || t.set(n.parent, []), t.get(n.parent).push(n));
878
- return t;
879
- }
880
- function sn(e, t) {
881
- const n = Ae(t);
882
- return nn(e, rn(n));
883
- }
884
- function st(e, t) {
885
- return t.type === "compound" ? X(t).some((n) => n.type === "final" && e.has(n)) : t.type === "parallel" ? X(t).every((n) => st(e, n)) : t.type === "final";
886
- }
887
- const Ne = (e) => e[0] === Tn;
888
- function qn(e, t) {
889
- return e.transitions.get(t) || [...e.transitions.keys()].filter((r) => {
890
- if (r === In)
891
- return !0;
892
- if (!r.endsWith(".*"))
893
- return !1;
894
- const i = r.split("."), o = t.split(".");
895
- for (let s = 0; s < i.length; s++) {
896
- const a = i[s], c = o[s];
897
- if (a === "*")
898
- return s === i.length - 1;
899
- if (a !== c)
900
- return !1;
901
- }
902
- return !0;
903
- }).sort((r, i) => i.length - r.length).flatMap((r) => e.transitions.get(r));
904
- }
905
- function Wn(e) {
906
- const t = e.config.after;
907
- if (!t)
908
- return [];
909
- const n = (i) => {
910
- const o = Pn(i, e.id), s = o.type;
911
- return e.entry.push(at(o, {
912
- id: s,
913
- delay: i
914
- })), e.exit.push(tt(s)), s;
915
- };
916
- return Object.keys(t).flatMap((i) => {
917
- const o = t[i], s = typeof o == "string" ? {
918
- target: o
919
- } : o, a = Number.isNaN(+i) ? i : +i, c = n(a);
920
- return x(s).map((u) => ({
921
- ...u,
922
- event: c,
923
- delay: a
924
- }));
925
- }).map((i) => {
926
- const {
927
- delay: o
928
- } = i;
929
- return {
930
- ...B(e, i.event, i),
931
- delay: o
932
- };
933
- });
934
- }
935
- function B(e, t, n) {
936
- const r = tn(n.target), i = n.reenter ?? !1, o = Un(e, r), s = {
937
- ...n,
938
- actions: x(n.actions),
939
- guard: n.guard,
940
- target: o,
941
- source: e,
942
- reenter: i,
943
- eventType: t,
944
- toJSON: () => ({
945
- ...s,
946
- source: `#${e.id}`,
947
- target: o ? o.map((a) => `#${a.id}`) : void 0
948
- })
949
- };
950
- return s;
951
- }
952
- function Bn(e) {
953
- const t = /* @__PURE__ */ new Map();
954
- if (e.config.on)
955
- for (const n of Object.keys(e.config.on)) {
956
- if (n === Jt)
957
- throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');
958
- const r = e.config.on[n];
959
- t.set(n, Z(r).map((i) => B(e, n, i)));
960
- }
961
- if (e.config.onDone) {
962
- const n = `xstate.done.state.${e.id}`;
963
- t.set(n, Z(e.config.onDone).map((r) => B(e, n, r)));
964
- }
965
- for (const n of e.invoke) {
966
- if (n.onDone) {
967
- const r = `xstate.done.actor.${n.id}`;
968
- t.set(r, Z(n.onDone).map((i) => B(e, r, i)));
969
- }
970
- if (n.onError) {
971
- const r = `xstate.error.actor.${n.id}`;
972
- t.set(r, Z(n.onError).map((i) => B(e, r, i)));
973
- }
974
- if (n.onSnapshot) {
975
- const r = `xstate.snapshot.${n.id}`;
976
- t.set(r, Z(n.onSnapshot).map((i) => B(e, r, i)));
977
- }
978
- }
979
- for (const n of e.after) {
980
- let r = t.get(n.eventType);
981
- r || (r = [], t.set(n.eventType, r)), r.push(n);
982
- }
983
- return t;
984
- }
985
- function Hn(e, t) {
986
- const n = typeof t == "string" ? e.states[t] : t ? e.states[t.target] : void 0;
987
- if (!n && t)
988
- throw new Error(
989
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
990
- `Initial state node "${t}" not found on parent state node #${e.id}`
991
- );
992
- const r = {
993
- source: e,
994
- actions: !t || typeof t == "string" ? [] : x(t.actions),
995
- eventType: null,
996
- reenter: !1,
997
- target: n ? [n] : [],
998
- toJSON: () => ({
999
- ...r,
1000
- source: `#${e.id}`,
1001
- target: n ? [`#${n.id}`] : []
1002
- })
1003
- };
1004
- return r;
1005
- }
1006
- function Un(e, t) {
1007
- if (t !== void 0)
1008
- return t.map((n) => {
1009
- if (typeof n != "string")
1010
- return n;
1011
- if (Ne(n))
1012
- return e.machine.getStateNodeById(n);
1013
- const r = n[0] === zt;
1014
- if (r && !e.parent)
1015
- return Me(e, n.slice(1));
1016
- const i = r ? e.key + n : n;
1017
- if (e.parent)
1018
- try {
1019
- return Me(e.parent, i);
1020
- } catch (o) {
1021
- throw new Error(`Invalid transition definition for state node '${e.id}':
1022
- ${o.message}`);
1023
- }
1024
- else
1025
- throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`);
1026
- });
1027
- }
1028
- function on(e) {
1029
- const t = tn(e.config.target);
1030
- return t ? {
1031
- target: t.map((n) => typeof n == "string" ? Me(e.parent, n) : n)
1032
- } : e.parent.initial;
1033
- }
1034
- function H(e) {
1035
- return e.type === "history";
1036
- }
1037
- function gt(e) {
1038
- const t = an(e);
1039
- for (const n of t)
1040
- for (const r of ke(n, e))
1041
- t.add(r);
1042
- return t;
1043
- }
1044
- function an(e) {
1045
- const t = /* @__PURE__ */ new Set();
1046
- function n(r) {
1047
- if (!t.has(r)) {
1048
- if (t.add(r), r.type === "compound")
1049
- n(r.initial.target[0]);
1050
- else if (r.type === "parallel")
1051
- for (const i of X(r))
1052
- n(i);
1053
- }
1054
- }
1055
- return n(e), t;
1056
- }
1057
- function Q(e, t) {
1058
- if (Ne(t))
1059
- return e.machine.getStateNodeById(t);
1060
- if (!e.states)
1061
- throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);
1062
- const n = e.states[t];
1063
- if (!n)
1064
- throw new Error(`Child state '${t}' does not exist on '${e.id}'`);
1065
- return n;
1066
- }
1067
- function Me(e, t) {
1068
- if (typeof t == "string" && Ne(t))
1069
- try {
1070
- return e.machine.getStateNodeById(t);
1071
- } catch {
1072
- }
1073
- const n = Qe(t).slice();
1074
- let r = e;
1075
- for (; n.length; ) {
1076
- const i = n.shift();
1077
- if (!i.length)
1078
- break;
1079
- r = Q(r, i);
1080
- }
1081
- return r;
1082
- }
1083
- function Oe(e, t) {
1084
- if (typeof t == "string") {
1085
- const i = e.states[t];
1086
- if (!i)
1087
- throw new Error(`State '${t}' does not exist on '${e.id}'`);
1088
- return [e, i];
1089
- }
1090
- const n = Object.keys(t), r = n.map((i) => Q(e, i)).filter(Boolean);
1091
- return [e.machine.root, e].concat(r, n.reduce((i, o) => {
1092
- const s = Q(e, o);
1093
- if (!s)
1094
- return i;
1095
- const a = Oe(s, t[o]);
1096
- return i.concat(a);
1097
- }, []));
1098
- }
1099
- function Vn(e, t, n, r) {
1100
- const o = Q(e, t).next(n, r);
1101
- return !o || !o.length ? e.next(n, r) : o;
1102
- }
1103
- function Kn(e, t, n, r) {
1104
- const i = Object.keys(t), o = Q(e, i[0]), s = it(o, t[i[0]], n, r);
1105
- return !s || !s.length ? e.next(n, r) : s;
1106
- }
1107
- function zn(e, t, n, r) {
1108
- const i = [];
1109
- for (const o of Object.keys(t)) {
1110
- const s = t[o];
1111
- if (!s)
1112
- continue;
1113
- const a = Q(e, o), c = it(a, s, n, r);
1114
- c && i.push(...c);
1115
- }
1116
- return i.length ? i : e.next(n, r);
1117
- }
1118
- function it(e, t, n, r) {
1119
- return typeof t == "string" ? Vn(e, t, n, r) : Object.keys(t).length === 1 ? Kn(e, t, n, r) : zn(e, t, n, r);
1120
- }
1121
- function Jn(e) {
1122
- return Object.keys(e.states).map((t) => e.states[t]).filter((t) => t.type === "history");
1123
- }
1124
- function q(e, t) {
1125
- let n = e;
1126
- for (; n.parent && n.parent !== t; )
1127
- n = n.parent;
1128
- return n.parent === t;
1129
- }
1130
- function Zn(e, t) {
1131
- const n = new Set(e), r = new Set(t);
1132
- for (const i of n)
1133
- if (r.has(i))
1134
- return !0;
1135
- for (const i of r)
1136
- if (n.has(i))
1137
- return !0;
1138
- return !1;
1139
- }
1140
- function cn(e, t, n) {
1141
- const r = /* @__PURE__ */ new Set();
1142
- for (const i of e) {
1143
- let o = !1;
1144
- const s = /* @__PURE__ */ new Set();
1145
- for (const a of r)
1146
- if (Zn(Ze([i], t, n), Ze([a], t, n)))
1147
- if (q(i.source, a.source))
1148
- s.add(a);
1149
- else {
1150
- o = !0;
1151
- break;
1152
- }
1153
- if (!o) {
1154
- for (const a of s)
1155
- r.delete(a);
1156
- r.add(i);
1157
- }
1158
- }
1159
- return Array.from(r);
1160
- }
1161
- function Yn(e) {
1162
- const [t, ...n] = e;
1163
- for (const r of ke(t, void 0))
1164
- if (n.every((i) => q(i, r)))
1165
- return r;
1166
- }
1167
- function ot(e, t) {
1168
- if (!e.target)
1169
- return [];
1170
- const n = /* @__PURE__ */ new Set();
1171
- for (const r of e.target)
1172
- if (H(r))
1173
- if (t[r.id])
1174
- for (const i of t[r.id])
1175
- n.add(i);
1176
- else
1177
- for (const i of ot(on(r), t))
1178
- n.add(i);
1179
- else
1180
- n.add(r);
1181
- return [...n];
1182
- }
1183
- function un(e, t) {
1184
- const n = ot(e, t);
1185
- if (!n)
1186
- return;
1187
- if (!e.reenter && n.every((i) => i === e.source || q(i, e.source)))
1188
- return e.source;
1189
- const r = Yn(n.concat(e.source));
1190
- if (r)
1191
- return r;
1192
- if (!e.reenter)
1193
- return e.source.machine.root;
1194
- }
1195
- function Ze(e, t, n) {
1196
- const r = /* @__PURE__ */ new Set();
1197
- for (const i of e)
1198
- if (i.target?.length) {
1199
- const o = un(i, n);
1200
- i.reenter && i.source === o && r.add(o);
1201
- for (const s of t)
1202
- q(s, o) && r.add(s);
1203
- }
1204
- return [...r];
1205
- }
1206
- function Xn(e, t) {
1207
- if (e.length !== t.size)
1208
- return !1;
1209
- for (const n of e)
1210
- if (!t.has(n))
1211
- return !1;
1212
- return !0;
1213
- }
1214
- function Ye(e, t, n, r, i, o) {
1215
- if (!e.length)
1216
- return t;
1217
- const s = new Set(t._nodes);
1218
- let a = t.historyValue;
1219
- const c = cn(e, s, a);
1220
- let u = t;
1221
- i || ([u, a] = tr(u, r, n, c, s, a, o, n.actionExecutor)), u = $(u, r, n, c.flatMap((l) => l.actions), o, void 0), u = $n(u, r, n, c, s, o, a, i);
1222
- const f = [...s];
1223
- u.status === "done" && (u = $(u, r, n, f.sort((l, d) => d.order - l.order).flatMap((l) => l.exit), o, void 0));
1224
- try {
1225
- return a === t.historyValue && Xn(t._nodes, s) ? u : U(u, {
1226
- _nodes: f,
1227
- historyValue: a
1228
- });
1229
- } catch (l) {
1230
- throw l;
1231
- }
1232
- }
1233
- function Qn(e, t, n, r, i) {
1234
- if (r.output === void 0)
1235
- return;
1236
- const o = Ke(i.id, i.output !== void 0 && i.parent ? ze(i.output, e.context, t, n.self) : void 0);
1237
- return ze(r.output, e.context, o, n.self);
1238
- }
1239
- function $n(e, t, n, r, i, o, s, a) {
1240
- let c = e;
1241
- const u = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
1242
- er(r, s, f, u), a && f.add(e.machine.root);
1243
- const l = /* @__PURE__ */ new Set();
1244
- for (const d of [...u].sort((p, g) => p.order - g.order)) {
1245
- i.add(d);
1246
- const p = [];
1247
- p.push(...d.entry);
1248
- for (const g of d.invoke)
1249
- p.push(nt(g.src, {
1250
- ...g,
1251
- syncSnapshot: !!g.onSnapshot
1252
- }));
1253
- if (f.has(d)) {
1254
- const g = d.initial.actions;
1255
- p.push(...g);
1256
- }
1257
- if (c = $(c, t, n, p, o, d.invoke.map((g) => g.id)), d.type === "final") {
1258
- const g = d.parent;
1259
- let y = g?.type === "parallel" ? g : g?.parent, I = y || d;
1260
- for (g?.type === "compound" && o.push(Ke(g.id, d.output !== void 0 ? ze(d.output, c.context, t, n.self) : void 0)); y?.type === "parallel" && !l.has(y) && st(i, y); )
1261
- l.add(y), o.push(Ke(y.id)), I = y, y = y.parent;
1262
- if (y)
1263
- continue;
1264
- c = U(c, {
1265
- status: "done",
1266
- output: Qn(c, t, n, c.machine.root, I)
1267
- });
1268
- }
1269
- }
1270
- return c;
1271
- }
1272
- function er(e, t, n, r) {
1273
- for (const i of e) {
1274
- const o = un(i, t);
1275
- for (const a of i.target || [])
1276
- !H(a) && // if the target is different than the source then it will *definitely* be entered
1277
- (i.source !== a || // we know that the domain can't lie within the source
1278
- // 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
1279
- i.source !== o || // reentering transitions always enter the target, even if it's the source itself
1280
- i.reenter) && (r.add(a), n.add(a)), Y(a, t, n, r);
1281
- const s = ot(i, t);
1282
- for (const a of s) {
1283
- const c = ke(a, o);
1284
- o?.type === "parallel" && c.push(o), dn(r, t, n, c, !i.source.parent && i.reenter ? void 0 : o);
1285
- }
1286
- }
1287
- }
1288
- function Y(e, t, n, r) {
1289
- if (H(e))
1290
- if (t[e.id]) {
1291
- const i = t[e.id];
1292
- for (const o of i)
1293
- r.add(o), Y(o, t, n, r);
1294
- for (const o of i)
1295
- Ue(o, e.parent, r, t, n);
1296
- } else {
1297
- const i = on(e);
1298
- for (const o of i.target)
1299
- r.add(o), i === e.parent?.initial && n.add(e.parent), Y(o, t, n, r);
1300
- for (const o of i.target)
1301
- Ue(o, e.parent, r, t, n);
1302
- }
1303
- else if (e.type === "compound") {
1304
- const [i] = e.initial.target;
1305
- H(i) || (r.add(i), n.add(i)), Y(i, t, n, r), Ue(i, e, r, t, n);
1306
- } else if (e.type === "parallel")
1307
- for (const i of X(e).filter((o) => !H(o)))
1308
- [...r].some((o) => q(o, i)) || (H(i) || (r.add(i), n.add(i)), Y(i, t, n, r));
1309
- }
1310
- function dn(e, t, n, r, i) {
1311
- for (const o of r)
1312
- if ((!i || q(o, i)) && e.add(o), o.type === "parallel")
1313
- for (const s of X(o).filter((a) => !H(a)))
1314
- [...e].some((a) => q(a, s)) || (e.add(s), Y(s, t, n, e));
1315
- }
1316
- function Ue(e, t, n, r, i) {
1317
- dn(n, r, i, ke(e, t));
1318
- }
1319
- function tr(e, t, n, r, i, o, s, a) {
1320
- let c = e;
1321
- const u = Ze(r, i, o);
1322
- u.sort((l, d) => d.order - l.order);
1323
- let f;
1324
- for (const l of u)
1325
- for (const d of Jn(l)) {
1326
- let p;
1327
- d.history === "deep" ? p = (g) => rt(g) && q(g, l) : p = (g) => g.parent === l, f ??= {
1328
- ...o
1329
- }, f[d.id] = Array.from(i).filter(p);
1330
- }
1331
- for (const l of u)
1332
- c = $(c, t, n, [...l.exit, ...l.invoke.map((d) => Ce(d.id))], s, void 0), i.delete(l);
1333
- return [c, f || o];
1334
- }
1335
- function nr(e, t) {
1336
- return e.implementations.actions[t];
1337
- }
1338
- function fn(e, t, n, r, i, o) {
1339
- const {
1340
- machine: s
1341
- } = e;
1342
- let a = e;
1343
- for (const c of r) {
1344
- const u = typeof c == "function", f = u ? c : (
1345
- // the existing type of `.actions` assumes non-nullable `TExpressionAction`
1346
- // it's fine to cast this here to get a common type and lack of errors in the rest of the code
1347
- // our logic below makes sure that we call those 2 "variants" correctly
1348
- nr(s, typeof c == "string" ? c : c.type)
1349
- ), l = {
1350
- context: a.context,
1351
- event: t,
1352
- self: n.self,
1353
- system: n.system
1354
- }, d = u || typeof c == "string" ? void 0 : "params" in c ? typeof c.params == "function" ? c.params({
1355
- context: a.context,
1356
- event: t
1357
- }) : c.params : void 0;
1358
- if (!f || !("resolve" in f)) {
1359
- n.actionExecutor({
1360
- type: typeof c == "string" ? c : typeof c == "object" ? c.type : c.name || "(anonymous)",
1361
- info: l,
1362
- params: d,
1363
- exec: f
1364
- });
1365
- continue;
1366
- }
1367
- const p = f, [g, y, I] = p.resolve(
1368
- n,
1369
- a,
1370
- l,
1371
- d,
1372
- f,
1373
- // this holds all params
1374
- i
1375
- );
1376
- a = g, "retryResolve" in p && o?.push([p, y]), "execute" in p && n.actionExecutor({
1377
- type: p.type,
1378
- info: l,
1379
- params: y,
1380
- exec: p.execute.bind(null, n, y)
1381
- }), I && (a = fn(a, t, n, I, i, o));
1382
- }
1383
- return a;
1384
- }
1385
- function $(e, t, n, r, i, o) {
1386
- const s = o ? [] : void 0, a = fn(e, t, n, r, {
1387
- internalQueue: i,
1388
- deferredActorIds: o
1389
- }, s);
1390
- return s?.forEach(([c, u]) => {
1391
- c.retryResolve(n, a, u);
1392
- }), a;
1393
- }
1394
- function Ve(e, t, n, r) {
1395
- let i = e;
1396
- const o = [];
1397
- function s(u, f, l) {
1398
- n.system._sendInspectionEvent({
1399
- type: "@xstate.microstep",
1400
- actorRef: n.self,
1401
- event: f,
1402
- snapshot: u,
1403
- _transitions: l
1404
- }), o.push(u);
1405
- }
1406
- if (t.type === we)
1407
- return i = U(vt(i, t, n), {
1408
- status: "stopped"
1409
- }), s(i, t, []), {
1410
- snapshot: i,
1411
- microstates: o
1412
- };
1413
- let a = t;
1414
- if (a.type !== Zt) {
1415
- const u = a, f = An(u), l = mt(u, i);
1416
- if (f && !l.length)
1417
- return i = U(e, {
1418
- status: "error",
1419
- error: u.error
1420
- }), s(i, u, []), {
1421
- snapshot: i,
1422
- microstates: o
1423
- };
1424
- i = Ye(
1425
- l,
1426
- e,
1427
- n,
1428
- a,
1429
- !1,
1430
- // isInitial
1431
- r
1432
- ), s(i, u, l);
1433
- }
1434
- let c = !0;
1435
- for (; i.status === "active"; ) {
1436
- let u = c ? rr(i, a) : [];
1437
- const f = u.length ? i : void 0;
1438
- if (!u.length) {
1439
- if (!r.length)
1440
- break;
1441
- a = r.shift(), u = mt(a, i);
1442
- }
1443
- i = Ye(u, i, n, a, !1, r), c = i !== f, s(i, a, u);
1444
- }
1445
- return i.status !== "active" && vt(i, a, n), {
1446
- snapshot: i,
1447
- microstates: o
1448
- };
1449
- }
1450
- function vt(e, t, n) {
1451
- return $(e, t, n, Object.values(e.children).map((r) => Ce(r)), [], void 0);
1452
- }
1453
- function mt(e, t) {
1454
- return t.machine.getTransitionData(t, e);
1455
- }
1456
- function rr(e, t) {
1457
- const n = /* @__PURE__ */ new Set(), r = e._nodes.filter(rt);
1458
- for (const i of r)
1459
- e: for (const o of [i].concat(ke(i, void 0)))
1460
- if (o.always) {
1461
- for (const s of o.always)
1462
- if (s.guard === void 0 || Re(s.guard, e.context, t, e)) {
1463
- n.add(s);
1464
- break e;
1465
- }
1466
- }
1467
- return cn(Array.from(n), new Set(e._nodes), e.historyValue);
1468
- }
1469
- function sr(e, t) {
1470
- const n = Ae(Oe(e, t));
1471
- return sn(e, [...n]);
1472
- }
1473
- function ir(e) {
1474
- return !!e && typeof e == "object" && "machine" in e && "value" in e;
1475
- }
1476
- const or = function(t) {
1477
- return Qt(t, this.value);
1478
- }, ar = function(t) {
1479
- return this.tags.has(t);
1480
- }, cr = function(t) {
1481
- const n = this.machine.getTransitionData(this, t);
1482
- return !!n?.length && // Check that at least one transition is not forbidden
1483
- n.some((r) => r.target !== void 0 || r.actions.length);
1484
- }, ur = function() {
1485
- const {
1486
- _nodes: t,
1487
- tags: n,
1488
- machine: r,
1489
- getMeta: i,
1490
- toJSON: o,
1491
- can: s,
1492
- hasTag: a,
1493
- matches: c,
1494
- ...u
1495
- } = this;
1496
- return {
1497
- ...u,
1498
- tags: Array.from(n)
1499
- };
1500
- }, dr = function() {
1501
- return this._nodes.reduce((t, n) => (n.meta !== void 0 && (t[n.id] = n.meta), t), {});
1502
- };
1503
- function Ee(e, t) {
1504
- return {
1505
- status: e.status,
1506
- output: e.output,
1507
- error: e.error,
1508
- machine: t,
1509
- context: e.context,
1510
- _nodes: e._nodes,
1511
- value: sn(t.root, e._nodes),
1512
- tags: new Set(e._nodes.flatMap((n) => n.tags)),
1513
- children: e.children,
1514
- historyValue: e.historyValue || {},
1515
- matches: or,
1516
- hasTag: ar,
1517
- can: cr,
1518
- getMeta: dr,
1519
- toJSON: ur
1520
- };
1521
- }
1522
- function U(e, t = {}) {
1523
- return Ee({
1524
- ...e,
1525
- ...t
1526
- }, e.machine);
1527
- }
1528
- function fr(e) {
1529
- if (typeof e != "object" || e === null)
1530
- return {};
1531
- const t = {};
1532
- for (const n in e) {
1533
- const r = e[n];
1534
- Array.isArray(r) && (t[n] = r.map((i) => ({
1535
- id: i.id
1536
- })));
1537
- }
1538
- return t;
1539
- }
1540
- function lr(e, t) {
1541
- const {
1542
- _nodes: n,
1543
- tags: r,
1544
- machine: i,
1545
- children: o,
1546
- context: s,
1547
- can: a,
1548
- hasTag: c,
1549
- matches: u,
1550
- getMeta: f,
1551
- toJSON: l,
1552
- ...d
1553
- } = e, p = {};
1554
- for (const y in o) {
1555
- const I = o[y];
1556
- p[y] = {
1557
- snapshot: I.getPersistedSnapshot(t),
1558
- src: I.src,
1559
- systemId: I.systemId,
1560
- syncSnapshot: I._syncSnapshot
1561
- };
1562
- }
1563
- return {
1564
- ...d,
1565
- context: ln(s),
1566
- children: p,
1567
- historyValue: fr(d.historyValue)
1568
- };
1569
- }
1570
- function ln(e) {
1571
- let t;
1572
- for (const n in e) {
1573
- const r = e[n];
1574
- if (r && typeof r == "object")
1575
- if ("sessionId" in r && "send" in r && "ref" in r)
1576
- t ??= Array.isArray(e) ? e.slice() : {
1577
- ...e
1578
- }, t[n] = {
1579
- xstate$$type: et,
1580
- id: r.id
1581
- };
1582
- else {
1583
- const i = ln(r);
1584
- i !== r && (t ??= Array.isArray(e) ? e.slice() : {
1585
- ...e
1586
- }, t[n] = i);
1587
- }
1588
- }
1589
- return t ?? e;
1590
- }
1591
- function hr(e, t, n, r, {
1592
- event: i,
1593
- id: o,
1594
- delay: s
1595
- }, {
1596
- internalQueue: a
1597
- }) {
1598
- const c = t.machine.implementations.delays;
1599
- if (typeof i == "string")
1600
- throw new Error(
1601
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1602
- `Only event objects may be used with raise; use raise({ type: "${i}" }) instead`
1603
- );
1604
- const u = typeof i == "function" ? i(n, r) : i;
1605
- let f;
1606
- if (typeof s == "string") {
1607
- const l = c && c[s];
1608
- f = typeof l == "function" ? l(n, r) : l;
1609
- } else
1610
- f = typeof s == "function" ? s(n, r) : s;
1611
- return typeof f != "number" && a.push(u), [t, {
1612
- event: u,
1613
- id: o,
1614
- delay: f
1615
- }, void 0];
1616
- }
1617
- function pr(e, t) {
1618
- const {
1619
- event: n,
1620
- delay: r,
1621
- id: i
1622
- } = t;
1623
- if (typeof r == "number") {
1624
- e.defer(() => {
1625
- const o = e.self;
1626
- e.system.scheduler.schedule(o, o, n, r, i);
1627
- });
1628
- return;
1629
- }
1630
- }
1631
- function at(e, t) {
1632
- function n(r, i) {
1633
- }
1634
- return n.type = "xstate.raise", n.event = e, n.id = t?.id, n.delay = t?.delay, n.resolve = hr, n.execute = pr, n;
1635
- }
1636
- const yt = /* @__PURE__ */ new WeakMap();
1637
- function gr(e) {
1638
- return {
1639
- config: e,
1640
- start: (n, r) => {
1641
- const {
1642
- self: i,
1643
- system: o,
1644
- emit: s
1645
- } = r, a = {
1646
- receivers: void 0,
1647
- dispose: void 0
1648
- };
1649
- yt.set(i, a), a.dispose = e({
1650
- input: n.input,
1651
- system: o,
1652
- self: i,
1653
- sendBack: (c) => {
1654
- i.getSnapshot().status !== "stopped" && i._parent && o._relay(i, i._parent, c);
1655
- },
1656
- receive: (c) => {
1657
- a.receivers ??= /* @__PURE__ */ new Set(), a.receivers.add(c);
1658
- },
1659
- emit: s
1660
- });
1661
- },
1662
- transition: (n, r, i) => {
1663
- const o = yt.get(i.self);
1664
- return r.type === we ? (n = {
1665
- ...n,
1666
- status: "stopped",
1667
- error: void 0
1668
- }, o.dispose?.(), n) : (o.receivers?.forEach((s) => s(r)), n);
1669
- },
1670
- getInitialSnapshot: (n, r) => ({
1671
- status: "active",
1672
- output: void 0,
1673
- error: void 0,
1674
- input: r
1675
- }),
1676
- getPersistedSnapshot: (n) => n,
1677
- restoreSnapshot: (n) => n
1678
- };
1679
- }
1680
- const St = "xstate.promise.resolve", _t = "xstate.promise.reject", De = /* @__PURE__ */ new WeakMap();
1681
- function hn(e) {
1682
- return {
1683
- config: e,
1684
- transition: (n, r, i) => {
1685
- if (n.status !== "active")
1686
- return n;
1687
- switch (r.type) {
1688
- case St: {
1689
- const o = r.data;
1690
- return {
1691
- ...n,
1692
- status: "done",
1693
- output: o,
1694
- input: void 0
1695
- };
1696
- }
1697
- case _t:
1698
- return {
1699
- ...n,
1700
- status: "error",
1701
- error: r.data,
1702
- input: void 0
1703
- };
1704
- case we:
1705
- return De.get(i.self)?.abort(), {
1706
- ...n,
1707
- status: "stopped",
1708
- input: void 0
1709
- };
1710
- default:
1711
- return n;
1712
- }
1713
- },
1714
- start: (n, {
1715
- self: r,
1716
- system: i,
1717
- emit: o
1718
- }) => {
1719
- if (n.status !== "active")
1720
- return;
1721
- const s = new AbortController();
1722
- De.set(r, s), Promise.resolve(e({
1723
- input: n.input,
1724
- system: i,
1725
- self: r,
1726
- signal: s.signal,
1727
- emit: o
1728
- })).then((c) => {
1729
- r.getSnapshot().status === "active" && (De.delete(r), i._relay(r, r, {
1730
- type: St,
1731
- data: c
1732
- }));
1733
- }, (c) => {
1734
- r.getSnapshot().status === "active" && (De.delete(r), i._relay(r, r, {
1735
- type: _t,
1736
- data: c
1737
- }));
1738
- });
1739
- },
1740
- getInitialSnapshot: (n, r) => ({
1741
- status: "active",
1742
- output: void 0,
1743
- error: void 0,
1744
- input: r
1745
- }),
1746
- getPersistedSnapshot: (n) => n,
1747
- restoreSnapshot: (n) => n
1748
- };
1749
- }
1750
- function vr(e, {
1751
- machine: t,
1752
- context: n
1753
- }, r, i) {
1754
- const o = (s, a) => {
1755
- if (typeof s == "string") {
1756
- const c = $e(t, s);
1757
- if (!c)
1758
- throw new Error(`Actor logic '${s}' not implemented in machine '${t.id}'`);
1759
- const u = Pe(c, {
1760
- id: a?.id,
1761
- parent: e.self,
1762
- syncSnapshot: a?.syncSnapshot,
1763
- input: typeof a?.input == "function" ? a.input({
1764
- context: n,
1765
- event: r,
1766
- self: e.self
1767
- }) : a?.input,
1768
- src: s,
1769
- systemId: a?.systemId
1770
- });
1771
- return i[u.id] = u, u;
1772
- } else
1773
- return Pe(s, {
1774
- id: a?.id,
1775
- parent: e.self,
1776
- syncSnapshot: a?.syncSnapshot,
1777
- input: a?.input,
1778
- src: s,
1779
- systemId: a?.systemId
1780
- });
1781
- };
1782
- return (s, a) => {
1783
- const c = o(s, a);
1784
- return i[c.id] = c, e.defer(() => {
1785
- c._processingStatus !== A.Stopped && c.start();
1786
- }), c;
1787
- };
1788
- }
1789
- function mr(e, t, n, r, {
1790
- assignment: i
1791
- }) {
1792
- if (!t.context)
1793
- throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");
1794
- const o = {}, s = {
1795
- context: t.context,
1796
- event: n.event,
1797
- spawn: vr(e, t, n.event, o),
1798
- self: e.self,
1799
- system: e.system
1800
- };
1801
- let a = {};
1802
- if (typeof i == "function")
1803
- a = i(s, r);
1804
- else
1805
- for (const u of Object.keys(i)) {
1806
- const f = i[u];
1807
- a[u] = typeof f == "function" ? f(s, r) : f;
1808
- }
1809
- const c = Object.assign({}, t.context, a);
1810
- return [U(t, {
1811
- context: c,
1812
- children: Object.keys(o).length ? {
1813
- ...t.children,
1814
- ...o
1815
- } : t.children
1816
- }), void 0, void 0];
1817
- }
1818
- function F(e) {
1819
- function t(n, r) {
1820
- }
1821
- return t.type = "xstate.assign", t.assignment = e, t.resolve = mr, t;
1822
- }
1823
- const bt = /* @__PURE__ */ new WeakMap();
1824
- function J(e, t, n) {
1825
- let r = bt.get(e);
1826
- return r ? t in r || (r[t] = n()) : (r = {
1827
- [t]: n()
1828
- }, bt.set(e, r)), r[t];
1829
- }
1830
- const yr = {}, te = (e) => typeof e == "string" ? {
1831
- type: e
1832
- } : typeof e == "function" ? "resolve" in e ? {
1833
- type: e.type
1834
- } : {
1835
- type: e.name
1836
- } : e;
1837
- class Fe {
1838
- constructor(t, n) {
1839
- 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(zt), 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 ? lt(this.config.states, (r, i) => new Fe(r, {
1840
- _parent: this,
1841
- _key: i,
1842
- _machine: this.machine
1843
- })) : yr, this.type === "compound" && !this.config.initial)
1844
- 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.`);
1845
- this.history = this.config.history === !0 ? "shallow" : this.config.history || !1, this.entry = x(this.config.entry).slice(), this.exit = x(this.config.exit).slice(), this.meta = this.config.meta, this.output = this.type === "final" || !this.parent ? this.config.output : void 0, this.tags = x(t.tags).slice();
1846
- }
1847
- /** @internal */
1848
- _initialize() {
1849
- this.transitions = Bn(this), this.config.always && (this.always = Z(this.config.always).map((t) => B(this, Jt, t))), Object.keys(this.states).forEach((t) => {
1850
- this.states[t]._initialize();
1851
- });
1852
- }
1853
- /** The well-structured state node definition. */
1854
- get definition() {
1855
- return {
1856
- id: this.id,
1857
- key: this.key,
1858
- version: this.machine.version,
1859
- type: this.type,
1860
- initial: this.initial ? {
1861
- target: this.initial.target,
1862
- source: this,
1863
- actions: this.initial.actions.map(te),
1864
- eventType: null,
1865
- reenter: !1,
1866
- toJSON: () => ({
1867
- target: this.initial.target.map((t) => `#${t.id}`),
1868
- source: `#${this.id}`,
1869
- actions: this.initial.actions.map(te),
1870
- eventType: null
1871
- })
1872
- } : void 0,
1873
- history: this.history,
1874
- states: lt(this.states, (t) => t.definition),
1875
- on: this.on,
1876
- transitions: [...this.transitions.values()].flat().map((t) => ({
1877
- ...t,
1878
- actions: t.actions.map(te)
1879
- })),
1880
- entry: this.entry.map(te),
1881
- exit: this.exit.map(te),
1882
- meta: this.meta,
1883
- order: this.order || -1,
1884
- output: this.output,
1885
- invoke: this.invoke,
1886
- description: this.description,
1887
- tags: this.tags
1888
- };
1889
- }
1890
- /** @internal */
1891
- toJSON() {
1892
- return this.definition;
1893
- }
1894
- /** The logic invoked as actors by this state node. */
1895
- get invoke() {
1896
- return J(this, "invoke", () => x(this.config.invoke).map((t, n) => {
1897
- const {
1898
- src: r,
1899
- systemId: i
1900
- } = t, o = t.id ?? ht(this.id, n), s = typeof r == "string" ? r : `xstate.invoke.${ht(this.id, n)}`;
1901
- return {
1902
- ...t,
1903
- src: s,
1904
- id: o,
1905
- systemId: i,
1906
- toJSON() {
1907
- const {
1908
- onDone: a,
1909
- onError: c,
1910
- ...u
1911
- } = t;
1912
- return {
1913
- ...u,
1914
- type: "xstate.invoke",
1915
- src: s,
1916
- id: o
1917
- };
1918
- }
1919
- };
1920
- }));
1921
- }
1922
- /** The mapping of events to transitions. */
1923
- get on() {
1924
- return J(this, "on", () => [...this.transitions].flatMap(([n, r]) => r.map((i) => [n, i])).reduce((n, [r, i]) => (n[r] = n[r] || [], n[r].push(i), n), {}));
1925
- }
1926
- get after() {
1927
- return J(this, "delayedTransitions", () => Wn(this));
1928
- }
1929
- get initial() {
1930
- return J(this, "initial", () => Hn(this, this.config.initial));
1931
- }
1932
- /** @internal */
1933
- next(t, n) {
1934
- const r = n.type, i = [];
1935
- let o;
1936
- const s = J(this, `candidates-${r}`, () => qn(this, r));
1937
- for (const a of s) {
1938
- const {
1939
- guard: c
1940
- } = a, u = t.context;
1941
- let f = !1;
1942
- try {
1943
- f = !c || Re(c, u, n, t);
1944
- } catch (l) {
1945
- const d = typeof c == "string" ? c : typeof c == "object" ? c.type : void 0;
1946
- throw new Error(`Unable to evaluate guard ${d ? `'${d}' ` : ""}in transition for event '${r}' in state node '${this.id}':
1947
- ${l.message}`);
1948
- }
1949
- if (f) {
1950
- i.push(...a.actions), o = a;
1951
- break;
1952
- }
1953
- }
1954
- return o ? [o] : void 0;
1955
- }
1956
- /** All the event types accepted by this state node and its descendants. */
1957
- get events() {
1958
- return J(this, "events", () => {
1959
- const {
1960
- states: t
1961
- } = this, n = new Set(this.ownEvents);
1962
- if (t)
1963
- for (const r of Object.keys(t)) {
1964
- const i = t[r];
1965
- if (i.states)
1966
- for (const o of i.events)
1967
- n.add(`${o}`);
1968
- }
1969
- return Array.from(n);
1970
- });
1971
- }
1972
- /**
1973
- * All the events that have transitions directly from this state node.
1974
- *
1975
- * Excludes any inert events.
1976
- */
1977
- get ownEvents() {
1978
- const t = new Set([...this.transitions.keys()].filter((n) => this.transitions.get(n).some((r) => !(!r.target && !r.actions.length && !r.reenter))));
1979
- return Array.from(t);
1980
- }
1981
- }
1982
- const Sr = "#";
1983
- class ct {
1984
- constructor(t, n) {
1985
- 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 = {
1986
- actors: n?.actors ?? {},
1987
- actions: n?.actions ?? {},
1988
- delays: n?.delays ?? {},
1989
- guards: n?.guards ?? {}
1990
- }, 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 Fe(t, {
1991
- _key: this.id,
1992
- _machine: this
1993
- }), this.root._initialize(), this.states = this.root.states, this.events = this.root.events;
1994
- }
1995
- /**
1996
- * Clones this state machine with the provided implementations.
1997
- *
1998
- * @param implementations Options (`actions`, `guards`, `actors`, `delays`) to
1999
- * recursively merge with the existing options.
2000
- * @returns A new `StateMachine` instance with the provided implementations.
2001
- */
2002
- provide(t) {
2003
- const {
2004
- actions: n,
2005
- guards: r,
2006
- actors: i,
2007
- delays: o
2008
- } = this.implementations;
2009
- return new ct(this.config, {
2010
- actions: {
2011
- ...n,
2012
- ...t.actions
2013
- },
2014
- guards: {
2015
- ...r,
2016
- ...t.guards
2017
- },
2018
- actors: {
2019
- ...i,
2020
- ...t.actors
2021
- },
2022
- delays: {
2023
- ...o,
2024
- ...t.delays
2025
- }
2026
- });
2027
- }
2028
- resolveState(t) {
2029
- const n = sr(this.root, t.value), r = Ae(Oe(this.root, n));
2030
- return Ee({
2031
- _nodes: [...r],
2032
- context: t.context || {},
2033
- children: {},
2034
- status: st(r, this.root) ? "done" : t.status || "active",
2035
- output: t.output,
2036
- error: t.error,
2037
- historyValue: t.historyValue
2038
- }, this);
2039
- }
2040
- /**
2041
- * Determines the next snapshot given the current `snapshot` and received
2042
- * `event`. Calculates a full macrostep from all microsteps.
2043
- *
2044
- * @param snapshot The current snapshot
2045
- * @param event The received event
2046
- */
2047
- transition(t, n, r) {
2048
- return Ve(t, n, r, []).snapshot;
2049
- }
2050
- /**
2051
- * Determines the next state given the current `state` and `event`. Calculates
2052
- * a microstep.
2053
- *
2054
- * @param state The current state
2055
- * @param event The received event
2056
- */
2057
- microstep(t, n, r) {
2058
- return Ve(t, n, r, []).microstates;
2059
- }
2060
- getTransitionData(t, n) {
2061
- return it(this.root, t.value, t, n) || [];
2062
- }
2063
- /**
2064
- * The initial state _before_ evaluating any microsteps. This "pre-initial"
2065
- * state is provided to initial actions executed in the initial state.
2066
- */
2067
- getPreInitialState(t, n, r) {
2068
- const {
2069
- context: i
2070
- } = this.config, o = Ee({
2071
- context: typeof i != "function" && i ? i : {},
2072
- _nodes: [this.root],
2073
- children: {},
2074
- status: "active"
2075
- }, this);
2076
- return typeof i == "function" ? $(o, n, t, [F(({
2077
- spawn: a,
2078
- event: c,
2079
- self: u
2080
- }) => i({
2081
- spawn: a,
2082
- input: c.input,
2083
- self: u
2084
- }))], r, void 0) : o;
2085
- }
2086
- /**
2087
- * Returns the initial `State` instance, with reference to `self` as an
2088
- * `ActorRef`.
2089
- */
2090
- getInitialSnapshot(t, n) {
2091
- const r = Xt(n), i = [], o = this.getPreInitialState(t, r, i), s = Ye([{
2092
- target: [...an(this.root)],
2093
- source: this.root,
2094
- reenter: !0,
2095
- actions: [],
2096
- eventType: null,
2097
- toJSON: null
2098
- // TODO: fix
2099
- }], o, t, r, !0, i), {
2100
- snapshot: a
2101
- } = Ve(s, r, t, i);
2102
- return a;
2103
- }
2104
- start(t) {
2105
- Object.values(t.children).forEach((n) => {
2106
- n.getSnapshot().status === "active" && n.start();
2107
- });
2108
- }
2109
- getStateNodeById(t) {
2110
- const n = Qe(t), r = n.slice(1), i = Ne(n[0]) ? n[0].slice(Sr.length) : n[0], o = this.idMap.get(i);
2111
- if (!o)
2112
- throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);
2113
- return Me(o, r);
2114
- }
2115
- get definition() {
2116
- return this.root.definition;
2117
- }
2118
- toJSON() {
2119
- return this.definition;
2120
- }
2121
- getPersistedSnapshot(t, n) {
2122
- return lr(t, n);
2123
- }
2124
- restoreSnapshot(t, n) {
2125
- const r = {}, i = t.children;
2126
- Object.keys(i).forEach((l) => {
2127
- const d = i[l], p = d.snapshot, g = d.src, y = typeof g == "string" ? $e(this, g) : g;
2128
- if (!y)
2129
- return;
2130
- const I = Pe(y, {
2131
- id: l,
2132
- parent: n.self,
2133
- syncSnapshot: d.syncSnapshot,
2134
- snapshot: p,
2135
- src: g,
2136
- systemId: d.systemId
2137
- });
2138
- r[l] = I;
2139
- });
2140
- function o(l, d) {
2141
- if (d instanceof Fe)
2142
- return d;
2143
- try {
2144
- return l.machine.getStateNodeById(d.id);
2145
- } catch {
2146
- }
2147
- }
2148
- function s(l, d) {
2149
- if (!d || typeof d != "object")
2150
- return {};
2151
- const p = {};
2152
- for (const g in d) {
2153
- const y = d[g];
2154
- for (const I of y) {
2155
- const C = o(l, I);
2156
- C && (p[g] ??= [], p[g].push(C));
2157
- }
2158
- }
2159
- return p;
2160
- }
2161
- const a = s(this.root, t.historyValue), c = Ee({
2162
- ...t,
2163
- children: r,
2164
- _nodes: Array.from(Ae(Oe(this.root, t.value))),
2165
- historyValue: a
2166
- }, this), u = /* @__PURE__ */ new Set();
2167
- function f(l, d) {
2168
- if (!u.has(l)) {
2169
- u.add(l);
2170
- for (const p in l) {
2171
- const g = l[p];
2172
- if (g && typeof g == "object") {
2173
- if ("xstate$$type" in g && g.xstate$$type === et) {
2174
- l[p] = d[g.id];
2175
- continue;
2176
- }
2177
- f(g, d);
2178
- }
2179
- }
2180
- }
2181
- }
2182
- return f(c.context, r), c;
2183
- }
2184
- }
2185
- function _r(e, t, n, r, {
2186
- event: i
2187
- }) {
2188
- const o = typeof i == "function" ? i(n, r) : i;
2189
- return [t, {
2190
- event: o
2191
- }, void 0];
2192
- }
2193
- function br(e, {
2194
- event: t
2195
- }) {
2196
- e.defer(() => e.emit(t));
2197
- }
2198
- function pn(e) {
2199
- function t(n, r) {
2200
- }
2201
- return t.type = "xstate.emit", t.event = e, t.resolve = _r, t.execute = br, t;
2202
- }
2203
- let Xe = /* @__PURE__ */ (function(e) {
2204
- return e.Parent = "#_parent", e.Internal = "#_internal", e;
2205
- })({});
2206
- function Tr(e, t, n, r, {
2207
- to: i,
2208
- event: o,
2209
- id: s,
2210
- delay: a
2211
- }, c) {
2212
- const u = t.machine.implementations.delays;
2213
- if (typeof o == "string")
2214
- throw new Error(
2215
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
2216
- `Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`
2217
- );
2218
- const f = typeof o == "function" ? o(n, r) : o;
2219
- let l;
2220
- if (typeof a == "string") {
2221
- const g = u && u[a];
2222
- l = typeof g == "function" ? g(n, r) : g;
2223
- } else
2224
- l = typeof a == "function" ? a(n, r) : a;
2225
- const d = typeof i == "function" ? i(n, r) : i;
2226
- let p;
2227
- if (typeof d == "string") {
2228
- if (d === Xe.Parent ? p = e.self._parent : d === Xe.Internal ? p = e.self : d.startsWith("#_") ? p = t.children[d.slice(2)] : p = c.deferredActorIds?.includes(d) ? d : t.children[d], !p)
2229
- throw new Error(`Unable to send event to actor '${d}' from machine '${t.machine.id}'.`);
2230
- } else
2231
- p = d || e.self;
2232
- return [t, {
2233
- to: p,
2234
- targetId: typeof d == "string" ? d : void 0,
2235
- event: f,
2236
- id: s,
2237
- delay: l
2238
- }, void 0];
2239
- }
2240
- function Ir(e, t, n) {
2241
- typeof n.to == "string" && (n.to = t.children[n.to]);
2242
- }
2243
- function wr(e, t) {
2244
- e.defer(() => {
2245
- const {
2246
- to: n,
2247
- event: r,
2248
- delay: i,
2249
- id: o
2250
- } = t;
2251
- if (typeof i == "number") {
2252
- e.system.scheduler.schedule(e.self, n, r, i, o);
2253
- return;
2254
- }
2255
- e.system._relay(
2256
- e.self,
2257
- // at this point, in a deferred task, it should already be mutated by retryResolveSendTo
2258
- // if it initially started as a string
2259
- n,
2260
- r.type === wn ? Yt(e.self.id, r.data) : r
2261
- );
2262
- });
2263
- }
2264
- function je(e, t, n) {
2265
- function r(i, o) {
2266
- }
2267
- return r.type = "xstate.sendTo", r.to = e, r.event = t, r.id = n?.id, r.delay = n?.delay, r.resolve = Tr, r.retryResolve = Ir, r.execute = wr, r;
2268
- }
2269
- function Pr(e, t) {
2270
- return je(Xe.Parent, e, t);
2271
- }
2272
- function kr(e, t, n, r, {
2273
- collect: i
2274
- }) {
2275
- const o = [], s = function(c) {
2276
- o.push(c);
2277
- };
2278
- return s.assign = (...a) => {
2279
- o.push(F(...a));
2280
- }, s.cancel = (...a) => {
2281
- o.push(tt(...a));
2282
- }, s.raise = (...a) => {
2283
- o.push(at(...a));
2284
- }, s.sendTo = (...a) => {
2285
- o.push(je(...a));
2286
- }, s.sendParent = (...a) => {
2287
- o.push(Pr(...a));
2288
- }, s.spawnChild = (...a) => {
2289
- o.push(nt(...a));
2290
- }, s.stopChild = (...a) => {
2291
- o.push(Ce(...a));
2292
- }, s.emit = (...a) => {
2293
- o.push(pn(...a));
2294
- }, i({
2295
- context: n.context,
2296
- event: n.event,
2297
- enqueue: s,
2298
- check: (a) => Re(a, t.context, n.event, t),
2299
- self: e.self,
2300
- system: e.system
2301
- }, r), [t, void 0, o];
2302
- }
2303
- function Dr(e) {
2304
- function t(n, r) {
2305
- }
2306
- return t.type = "xstate.enqueueActions", t.collect = e, t.resolve = kr, t;
2307
- }
2308
- function Er(e, t, n, r, {
2309
- value: i,
2310
- label: o
2311
- }) {
2312
- return [t, {
2313
- value: typeof i == "function" ? i(n, r) : i,
2314
- label: o
2315
- }, void 0];
2316
- }
2317
- function Ar({
2318
- logger: e
2319
- }, {
2320
- value: t,
2321
- label: n
2322
- }) {
2323
- n ? e(n, t) : e(t);
2324
- }
2325
- function Mr(e = ({
2326
- context: n,
2327
- event: r
2328
- }) => ({
2329
- context: n,
2330
- event: r
2331
- }), t) {
2332
- function n(r, i) {
2333
- }
2334
- return n.type = "xstate.log", n.value = e, n.label = t, n.resolve = Er, n.execute = Ar, n;
2335
- }
2336
- function Or(e, t) {
2337
- return new ct(e, t);
2338
- }
2339
- function gn({
2340
- schemas: e,
2341
- actors: t,
2342
- actions: n,
2343
- guards: r,
2344
- delays: i
2345
- }) {
2346
- return {
2347
- assign: F,
2348
- sendTo: je,
2349
- raise: at,
2350
- log: Mr,
2351
- cancel: tt,
2352
- stopChild: Ce,
2353
- enqueueActions: Dr,
2354
- emit: pn,
2355
- spawnChild: nt,
2356
- createStateConfig: (o) => o,
2357
- createAction: (o) => o,
2358
- createMachine: (o) => Or({
2359
- ...o,
2360
- schemas: e
2361
- }, {
2362
- actors: t,
2363
- actions: n,
2364
- guards: r,
2365
- delays: i
2366
- }),
2367
- extend: (o) => gn({
2368
- schemas: e,
2369
- actors: t,
2370
- actions: {
2371
- ...n,
2372
- ...o.actions
2373
- },
2374
- guards: {
2375
- ...r,
2376
- ...o.guards
2377
- },
2378
- delays: {
2379
- ...i,
2380
- ...o.delays
2381
- }
2382
- })
2383
- };
2384
- }
2385
- class Fr {
1
+ import { createActor as y, fromPromise as T, fromCallback as k, setup as A, assign as d, sendTo as C } from "xstate";
2
+ import { DefaultPacketFactory as E, parseGenericPacket as v } from "nmea-simple";
3
+ class I {
2386
4
  actor;
2387
5
  subscription = null;
2388
6
  options;
@@ -2392,16 +10,16 @@ class Fr {
2392
10
  * @param machine - The NMEA machine instance (created with createNmeaMachine).
2393
11
  * @param options - Optional configuration and callbacks.
2394
12
  */
2395
- constructor(t, n) {
2396
- this.options = n, this.actor = Pe(t), this.setupSubscriptions(), n?.enableLogging !== void 0 && this.setLogging(n.enableLogging), n?.baudRate !== void 0 && this.setBaudRate(n.baudRate), this.actor.start();
13
+ constructor(e, r) {
14
+ this.options = r, this.actor = y(e), this.setupSubscriptions(), r?.enableLogging !== void 0 && this.setLogging(r.enableLogging), r?.baudRate !== void 0 && this.setBaudRate(r.baudRate), this.actor.start();
2397
15
  }
2398
16
  setupSubscriptions() {
2399
- this.subscription = this.actor.subscribe((t) => {
2400
- if (this.options?.onData && t.context.data !== void 0 && this.options.onData(t.context.data), this.options?.onStateChange) {
2401
- const n = t.value === "connected";
2402
- this.options.onStateChange(n);
17
+ this.subscription = this.actor.subscribe((e) => {
18
+ if (this.options?.onData && e.context.data !== void 0 && this.options.onData(e.context.data), this.options?.onStateChange) {
19
+ const r = e.value === "connected";
20
+ this.options.onStateChange(r);
2403
21
  }
2404
- this.options?.onError && t.context.error && this.options.onError(t.context.error);
22
+ this.options?.onError && e.context.error && this.options.onError(e.context.error);
2405
23
  });
2406
24
  }
2407
25
  /**
@@ -2443,14 +61,14 @@ class Fr {
2443
61
  /**
2444
62
  * Sets logging enabled/disabled.
2445
63
  */
2446
- setLogging(t) {
2447
- this.actor.send({ type: "SET_LOGGING", enabled: t });
64
+ setLogging(e) {
65
+ this.actor.send({ type: "SET_LOGGING", enabled: e });
2448
66
  }
2449
67
  /**
2450
68
  * Sets the baud rate (requires reconnection to take effect).
2451
69
  */
2452
- setBaudRate(t) {
2453
- this.actor.send({ type: "SET_BAUD_RATE", baudRate: t });
70
+ setBaudRate(e) {
71
+ this.actor.send({ type: "SET_BAUD_RATE", baudRate: e });
2454
72
  }
2455
73
  /**
2456
74
  * Gets the underlying XState actor (for advanced users).
@@ -2466,882 +84,115 @@ class Fr {
2466
84
  this.subscription && (this.subscription.unsubscribe(), this.subscription = null), this.actor.stop();
2467
85
  }
2468
86
  }
2469
- var O = {}, ne = {}, T = {}, Tt;
87
+ var f = {}, g = {}, D;
2470
88
  function P() {
2471
- if (Tt) return T;
2472
- Tt = 1, Object.defineProperty(T, "__esModule", { value: !0 });
2473
- var e = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
2474
- function t(h) {
2475
- var v = h >> 4 & 15, m = h >> 0 & 15;
2476
- return e[v] + e[m];
2477
- }
2478
- T.toHexString = t;
2479
- function n(h, v, m) {
2480
- for (var S = typeof h == "string" ? h : h.toFixed(0); S.length < v; )
2481
- S = m + S;
2482
- return S;
2483
- }
2484
- T.padLeft = n;
2485
- function r(h) {
2486
- var v = h.split("*"), m = v[0], S = v[1], D = i(m), M = parseInt(S, 16);
2487
- return D === M;
2488
- }
2489
- T.validNmeaChecksum = r;
2490
- function i(h) {
2491
- for (var v = h.charCodeAt(1), m = 2; m < h.length; m += 1)
2492
- v = v ^ h.charCodeAt(m);
2493
- return v = v & 255, v;
2494
- }
2495
- T.computeNmeaChecksum = i;
2496
- function o(h) {
2497
- return "*" + t(i(h));
2498
- }
2499
- T.createNmeaChecksumFooter = o;
2500
- function s(h) {
2501
- return h + o(h);
2502
- }
2503
- T.appendChecksumFooter = s;
2504
- function a(h, v) {
2505
- return h === void 0 ? "" : h.toFixed(v);
2506
- }
2507
- T.encodeFixed = a;
2508
- function c(h) {
2509
- if (h === void 0)
2510
- return ",";
2511
- var v;
2512
- h < 0 ? (v = "S", h = -h) : v = "N";
2513
- var m = Math.floor(h), S = n(m, 2, "0"), D = h - m, M = D * 60, N = n(M.toFixed(6), 9, "0");
2514
- return S = S + N + "," + v, S;
2515
- }
2516
- T.encodeLatitude = c;
2517
- function u(h) {
2518
- if (h === void 0)
2519
- return ",";
2520
- var v;
2521
- h < 0 ? (v = "W", h = -h) : v = "E";
2522
- var m = Math.floor(h), S = n(m, 3, "0"), D = h - m, M = D * 60, N = n(M.toFixed(6), 9, "0");
2523
- return S = S + N + "," + v, S;
2524
- }
2525
- T.encodeLongitude = u;
2526
- function f(h) {
2527
- return h === void 0 ? "," : h.toFixed(1) + ",M";
2528
- }
2529
- T.encodeAltitude = f;
2530
- function l(h) {
2531
- return h === void 0 ? "" : h.toFixed(1);
2532
- }
2533
- T.encodeAltitudeNoUnits = l;
2534
- function d(h) {
2535
- return h === void 0 ? "," : h.toFixed(1) + ",M";
2536
- }
2537
- T.encodeGeoidalSeperation = d;
2538
- function p(h) {
2539
- return h === void 0 ? "" : h.toFixed(1);
2540
- }
2541
- T.encodeGeoidalSeperationNoUnits = p;
2542
- function g(h) {
2543
- return h === void 0 ? "" : n(h.toFixed(2), 6, "0");
2544
- }
2545
- T.encodeDegrees = g;
2546
- function y(h) {
2547
- if (h === void 0)
2548
- return "";
2549
- var v = h.getUTCFullYear(), m = h.getUTCMonth() + 1, S = h.getUTCDate();
2550
- return n(S, 2, "0") + n(m, 2, "0") + v.toFixed(0).substr(2);
2551
- }
2552
- T.encodeDate = y;
2553
- function I(h) {
2554
- if (h === void 0)
2555
- return "";
2556
- var v = h.getUTCHours(), m = h.getUTCMinutes(), S = h.getUTCSeconds();
2557
- return n(v, 2, "0") + n(m, 2, "0") + n(S, 2, "0");
2558
- }
2559
- T.encodeTime = I;
2560
- function C(h) {
2561
- return h === void 0 ? "" : h.toString();
2562
- }
2563
- T.encodeValue = C;
2564
- function R(h) {
2565
- return h === "" ? 0 : parseFloat(h);
2566
- }
2567
- T.parseFloatSafe = R;
2568
- function V(h) {
2569
- return h === "" ? 0 : parseInt(h, 10);
2570
- }
2571
- T.parseIntSafe = V;
2572
- function Le(h) {
2573
- if (h === void 0)
2574
- return "";
2575
- var v = parseFloat(h);
2576
- return v === NaN ? h : v;
2577
- }
2578
- T.parseNumberOrString = Le;
2579
- function ee(h) {
2580
- var v = h.indexOf(".");
2581
- if (v < 0)
2582
- return 0;
2583
- var m, S;
2584
- return v >= 3 ? (m = h.substring(0, v - 2), S = h.substring(v - 2)) : (m = "0", S = h), parseFloat(m) + parseFloat(S) / 60;
2585
- }
2586
- T.parseDmCoordinate = ee;
2587
- function xe(h, v) {
2588
- var m = v === "N" ? 1 : -1;
2589
- return ee(h) * m;
2590
- }
2591
- T.parseLatitude = xe;
2592
- function qe(h, v) {
2593
- var m = v === "E" ? 1 : -1;
2594
- return ee(h) * m;
2595
- }
2596
- T.parseLongitude = qe;
2597
- function We(h, v) {
2598
- if (h === "")
2599
- return /* @__PURE__ */ new Date(0);
2600
- var m = /* @__PURE__ */ new Date();
2601
- if (v) {
2602
- var S = v.slice(4), D = parseInt(v.slice(2, 4), 10) - 1, M = v.slice(0, 2);
2603
- S.length === 4 ? m.setUTCFullYear(Number(S), Number(D), Number(M)) : m.setUTCFullYear(+("20" + S), Number(D), Number(M));
2604
- }
2605
- m.setUTCHours(Number(h.slice(0, 2))), m.setUTCMinutes(Number(h.slice(2, 4))), m.setUTCSeconds(Number(h.slice(4, 6)));
2606
- var N = h.slice(7), K = N.length, W = 0;
2607
- return K !== 0 && (W = parseFloat(N) * Math.pow(10, 3 - K)), m.setUTCMilliseconds(Number(W)), m;
2608
- }
2609
- T.parseTime = We;
2610
- function Be(h, v) {
2611
- var m = parseInt(h.slice(0, 2), 10), S = parseInt(h.slice(2, 4), 10), D = parseInt(h.slice(4, 6), 10);
2612
- D < 73 ? D = D + 2e3 : D = D + 1900;
2613
- var M = parseInt(v.slice(0, 2), 10), N = parseInt(v.slice(2, 4), 10), K = parseInt(v.slice(4, 6), 10), W = 0;
2614
- return v.length === 9 && (W = parseInt(v.slice(7, 9), 10) * 10), new Date(Date.UTC(D, S - 1, m, M, N, K, W));
2615
- }
2616
- return T.parseDatetime = Be, T;
2617
- }
2618
- var re = {}, It;
2619
- function w() {
2620
- if (It) return re;
2621
- It = 1, Object.defineProperty(re, "__esModule", { value: !0 });
2622
- function e(n, r, i) {
89
+ if (D) return g;
90
+ D = 1, Object.defineProperty(g, "__esModule", { value: !0 });
91
+ function t(r, o, a) {
2623
92
  return {
2624
- sentenceId: r,
2625
- talkerId: n.talkerId,
2626
- chxOk: n.chxOk,
2627
- sentenceName: i
93
+ sentenceId: o,
94
+ talkerId: r.talkerId,
95
+ chxOk: r.chxOk,
96
+ sentenceName: a
2628
97
  };
2629
98
  }
2630
- re.initStubFields = e;
2631
- function t(n, r) {
2632
- var i, o;
2633
- return n.charAt(1) === "P" ? (i = "P", o = n.substr(2)) : (i = n.substr(1, 2), o = n.substr(3)), { talkerId: i, sentenceId: o, chxOk: r || void 0 };
99
+ g.initStubFields = t;
100
+ function e(r, o) {
101
+ var a, n;
102
+ return r.charAt(1) === "P" ? (a = "P", n = r.substr(2)) : (a = r.substr(1, 2), n = r.substr(3)), { talkerId: a, sentenceId: n, chxOk: o || void 0 };
2634
103
  }
2635
- return re.parseStub = t, re;
2636
- }
2637
- var wt;
2638
- function Cr() {
2639
- return wt || (wt = 1, (function(e) {
2640
- var t = ne && ne.__assign || function() {
2641
- return t = Object.assign || function(o) {
2642
- for (var s, a = 1, c = arguments.length; a < c; a++) {
2643
- s = arguments[a];
2644
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
2645
- }
2646
- return o;
2647
- }, t.apply(this, arguments);
2648
- };
2649
- Object.defineProperty(e, "__esModule", { value: !0 });
2650
- var n = P(), r = w();
2651
- e.sentenceId = "APB", e.sentenceName = 'Autopilot sentence "B"';
2652
- function i(o, s) {
2653
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { status1: s[1], status2: s[2], xteMagn: n.parseFloatSafe(s[3]), steerDir: s[4], xteUnit: s[5], arrivalCircleStatus: s[6], arrivalPerpendicularStatus: s[7], bearingOrig2Dest: n.parseFloatSafe(s[8]), bearingOrig2DestType: s[9], waypoint: s[10], bearing2Dest: n.parseFloatSafe(s[11]), bearingDestType: s[12], heading2steer: n.parseFloatSafe(s[13]), headingDestType: s[14] });
2654
- }
2655
- e.decodeSentence = i;
2656
- })(ne)), ne;
2657
- }
2658
- var se = {}, Pt;
2659
- function Rr() {
2660
- return Pt || (Pt = 1, (function(e) {
2661
- var t = se && se.__assign || function() {
2662
- return t = Object.assign || function(o) {
2663
- for (var s, a = 1, c = arguments.length; a < c; a++) {
2664
- s = arguments[a];
2665
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
2666
- }
2667
- return o;
2668
- }, t.apply(this, arguments);
2669
- };
2670
- Object.defineProperty(e, "__esModule", { value: !0 });
2671
- var n = P(), r = w();
2672
- e.sentenceId = "BWC", e.sentenceName = "Bearing and distance to waypoint - great circle";
2673
- function i(o, s) {
2674
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { time: n.parseTime(s[1]), bearingLatitude: n.parseLatitude(s[2], s[3]), bearingLongitude: n.parseLongitude(s[4], s[5]), bearingTrue: n.parseFloatSafe(s[6]), bearingMagnetic: n.parseFloatSafe(s[8]), distanceNm: n.parseFloatSafe(s[10]), waypointId: s[12], faaMode: s[13] });
2675
- }
2676
- e.decodeSentence = i;
2677
- })(se)), se;
2678
- }
2679
- var ie = {}, kt;
2680
- function Nr() {
2681
- return kt || (kt = 1, (function(e) {
2682
- var t = ie && ie.__assign || function() {
2683
- return t = Object.assign || function(s) {
2684
- for (var a, c = 1, u = arguments.length; c < u; c++) {
2685
- a = arguments[c];
2686
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
2687
- }
2688
- return s;
2689
- }, t.apply(this, arguments);
2690
- };
2691
- Object.defineProperty(e, "__esModule", { value: !0 });
2692
- var n = P(), r = w();
2693
- e.sentenceId = "DBT", e.sentenceName = "Depth below transducer";
2694
- function i(s, a) {
2695
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { depthFeet: n.parseFloatSafe(a[1]), depthMeters: n.parseFloatSafe(a[3]), depthFathoms: n.parseFloatSafe(a[5]) });
2696
- }
2697
- e.decodeSentence = i;
2698
- function o(s, a) {
2699
- var c = ["$" + a + e.sentenceId];
2700
- c.push(n.encodeFixed(s.depthFeet, 2)), c.push("f"), c.push(n.encodeFixed(s.depthMeters, 2)), c.push("M"), c.push(n.encodeFixed(s.depthFathoms, 2)), c.push("F");
2701
- var u = c.join(",");
2702
- return u + n.createNmeaChecksumFooter(u);
2703
- }
2704
- e.encodePacket = o;
2705
- })(ie)), ie;
104
+ return g.parseStub = e, g;
2706
105
  }
2707
- var oe = {}, Dt;
2708
- function jr() {
2709
- return Dt || (Dt = 1, (function(e) {
2710
- var t = oe && oe.__assign || function() {
2711
- return t = Object.assign || function(s) {
2712
- for (var a, c = 1, u = arguments.length; c < u; c++) {
2713
- a = arguments[c];
2714
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
2715
- }
2716
- return s;
2717
- }, t.apply(this, arguments);
2718
- };
2719
- Object.defineProperty(e, "__esModule", { value: !0 });
2720
- var n = P(), r = w();
2721
- e.sentenceId = "DTM", e.sentenceName = "Datum reference";
2722
- function i(s, a) {
2723
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { datumCode: o(a[1]), datumSubcode: a[2] || void 0, offsetLatitude: n.parseLatitude(a[3], a[4]), offsetLongitude: n.parseLongitude(a[5], a[6]), offsetAltitudeMeters: n.parseFloatSafe(a[7]), datumName: o(a[8]) });
2724
- }
2725
- e.decodeSentence = i;
2726
- function o(s) {
2727
- return s === "W84" ? "W84" : s === "W72" ? "W72" : s === "S85" ? "S85" : s === "P90" ? "P90" : s === "999" ? "999" : "";
2728
- }
2729
- })(oe)), oe;
2730
- }
2731
- var ae = {}, Et;
2732
- function Gr() {
2733
- return Et || (Et = 1, (function(e) {
2734
- var t = ae && ae.__assign || function() {
2735
- return t = Object.assign || function(a) {
2736
- for (var c, u = 1, f = arguments.length; u < f; u++) {
2737
- c = arguments[u];
2738
- for (var l in c) Object.prototype.hasOwnProperty.call(c, l) && (a[l] = c[l]);
106
+ var R;
107
+ function L() {
108
+ return R || (R = 1, (function(t) {
109
+ var e = f && f.__assign || function() {
110
+ return e = Object.assign || function(a) {
111
+ for (var n, s = 1, c = arguments.length; s < c; s++) {
112
+ n = arguments[s];
113
+ for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (a[i] = n[i]);
2739
114
  }
2740
115
  return a;
2741
- }, t.apply(this, arguments);
2742
- };
2743
- Object.defineProperty(e, "__esModule", { value: !0 });
2744
- var n = P(), r = w();
2745
- e.sentenceId = "GGA", e.sentenceName = "Global positioning system fix data";
2746
- var i = ["none", "fix", "delta", "pps", "rtk", "frtk", "estimated", "manual", "simulation"];
2747
- function o(a, c) {
2748
- return t(t({}, r.initStubFields(a, e.sentenceId, e.sentenceName)), { time: n.parseTime(c[1]), latitude: n.parseLatitude(c[2], c[3]), longitude: n.parseLongitude(c[4], c[5]), fixType: i[n.parseIntSafe(c[6])], satellitesInView: n.parseIntSafe(c[7]), horizontalDilution: n.parseFloatSafe(c[8]), altitudeMeters: n.parseFloatSafe(c[9]), geoidalSeperation: n.parseFloatSafe(c[11]), differentialAge: n.parseFloatSafe(c[13]), differentialRefStn: c[14] });
2749
- }
2750
- e.decodeSentence = o;
2751
- function s(a, c) {
2752
- var u = ["$" + c + e.sentenceId];
2753
- u.push(n.encodeTime(a.time)), u.push(n.encodeLatitude(a.latitude)), u.push(n.encodeLongitude(a.longitude)), u.push(n.encodeValue(i.indexOf(a.fixType))), u.push(n.encodeValue(a.satellitesInView)), u.push(n.encodeFixed(a.horizontalDilution, 1)), u.push(n.encodeAltitude(a.altitudeMeters)), u.push(n.encodeGeoidalSeperation(a.geoidalSeperation)), u.push(n.encodeFixed(a.differentialAge, 2)), u.push(n.encodeValue(a.differentialRefStn));
2754
- var f = u.join(",");
2755
- return f + n.createNmeaChecksumFooter(f);
2756
- }
2757
- e.encodePacket = s;
2758
- })(ae)), ae;
2759
- }
2760
- var ce = {}, At;
2761
- function Lr() {
2762
- return At || (At = 1, (function(e) {
2763
- var t = ce && ce.__assign || function() {
2764
- return t = Object.assign || function(s) {
2765
- for (var a, c = 1, u = arguments.length; c < u; c++) {
2766
- a = arguments[c];
2767
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
2768
- }
2769
- return s;
2770
- }, t.apply(this, arguments);
2771
- };
2772
- Object.defineProperty(e, "__esModule", { value: !0 });
2773
- var n = P(), r = w();
2774
- e.sentenceId = "GLL", e.sentenceName = "Geographic position - latitude and longitude";
2775
- function i(s, a) {
2776
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { latitude: n.parseLatitude(a[1], a[2]), longitude: n.parseLongitude(a[3], a[4]), time: n.parseTime(a[5]), status: a[6] === "A" ? "valid" : "invalid", faaMode: a[7] });
2777
- }
2778
- e.decodeSentence = i;
2779
- function o(s, a) {
2780
- var c = ["$" + a + e.sentenceId];
2781
- c.push(n.encodeLatitude(s.latitude)), c.push(n.encodeLongitude(s.longitude)), c.push(n.encodeTime(s.time)), c.push(s.status === "valid" ? "A" : "V"), s.faaMode && c.push(s.faaMode);
2782
- var u = c.join(",");
2783
- return u + n.createNmeaChecksumFooter(u);
2784
- }
2785
- e.encodePacket = o;
2786
- })(ce)), ce;
2787
- }
2788
- var ue = {}, Mt;
2789
- function xr() {
2790
- return Mt || (Mt = 1, (function(e) {
2791
- var t = ue && ue.__assign || function() {
2792
- return t = Object.assign || function(s) {
2793
- for (var a, c = 1, u = arguments.length; c < u; c++) {
2794
- a = arguments[c];
2795
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
2796
- }
2797
- return s;
2798
- }, t.apply(this, arguments);
2799
- };
2800
- Object.defineProperty(e, "__esModule", { value: !0 });
2801
- var n = P(), r = w();
2802
- e.sentenceId = "GNS", e.sentenceName = "GNSS fix data";
2803
- function i(s, a) {
2804
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { time: n.parseTime(a[1]), latitude: n.parseLatitude(a[2], a[3]), longitude: n.parseLongitude(a[4], a[5]), modeIndicator: a[6], satellitesInView: n.parseIntSafe(a[7]), horizontalDilution: n.parseFloatSafe(a[8]), altitudeMeters: n.parseFloatSafe(a[9]), geoidalSeperation: n.parseFloatSafe(a[10]), differentialAge: n.parseFloatSafe(a[11]), differentialRefStn: a[12] });
2805
- }
2806
- e.decodeSentence = i;
2807
- function o(s, a) {
2808
- var c = ["$" + a + e.sentenceId];
2809
- c.push(n.encodeTime(s.time)), c.push(n.encodeLatitude(s.latitude)), c.push(n.encodeLongitude(s.longitude)), c.push(s.modeIndicator), c.push(n.encodeValue(s.satellitesInView)), c.push(n.encodeFixed(s.horizontalDilution, 1)), c.push(n.encodeAltitudeNoUnits(s.altitudeMeters)), c.push(n.encodeGeoidalSeperationNoUnits(s.geoidalSeperation)), c.push(n.encodeFixed(s.differentialAge, 2)), c.push(n.encodeValue(s.differentialRefStn));
2810
- var u = c.join(",");
2811
- return u + n.createNmeaChecksumFooter(u);
2812
- }
2813
- e.encodePacket = o;
2814
- })(ue)), ue;
2815
- }
2816
- var de = {}, Ot;
2817
- function qr() {
2818
- return Ot || (Ot = 1, (function(e) {
2819
- var t = de && de.__assign || function() {
2820
- return t = Object.assign || function(s) {
2821
- for (var a, c = 1, u = arguments.length; c < u; c++) {
2822
- a = arguments[c];
2823
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
2824
- }
2825
- return s;
2826
- }, t.apply(this, arguments);
2827
- };
2828
- Object.defineProperty(e, "__esModule", { value: !0 });
2829
- var n = P(), r = w();
2830
- e.sentenceId = "GSA", e.sentenceName = "Active satellites and dilution of precision";
2831
- var i = ["unknown", "none", "2D", "3D"];
2832
- function o(s, a) {
2833
- for (var c = [], u = 3; u < 15; u++)
2834
- a[u] && c.push(+a[u]);
2835
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { selectionMode: a[1] === "A" ? "automatic" : "manual", fixMode: i[n.parseIntSafe(a[2])], satellites: c, PDOP: n.parseFloatSafe(a[15]), HDOP: n.parseFloatSafe(a[16]), VDOP: n.parseFloatSafe(a[17]) });
2836
- }
2837
- e.decodeSentence = o;
2838
- })(de)), de;
2839
- }
2840
- var fe = {}, Ft;
2841
- function Wr() {
2842
- return Ft || (Ft = 1, (function(e) {
2843
- var t = fe && fe.__assign || function() {
2844
- return t = Object.assign || function(o) {
2845
- for (var s, a = 1, c = arguments.length; a < c; a++) {
2846
- s = arguments[a];
2847
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
2848
- }
2849
- return o;
2850
- }, t.apply(this, arguments);
2851
- };
2852
- Object.defineProperty(e, "__esModule", { value: !0 });
2853
- var n = P(), r = w();
2854
- e.sentenceId = "GST", e.sentenceName = "GPS pseudorange noise statistics";
2855
- function i(o, s) {
2856
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { time: n.parseTime(s[1]), totalRms: n.parseFloatSafe(s[2]), semiMajorError: n.parseFloatSafe(s[3]), semiMinorError: n.parseFloatSafe(s[4]), orientationOfSemiMajorError: n.parseFloatSafe(s[5]), latitudeError: n.parseFloatSafe(s[6]), longitudeError: n.parseFloatSafe(s[7]), altitudeError: n.parseFloatSafe(s[8]) });
2857
- }
2858
- e.decodeSentence = i;
2859
- })(fe)), fe;
2860
- }
2861
- var le = {}, Ct;
2862
- function Br() {
2863
- return Ct || (Ct = 1, (function(e) {
2864
- var t = le && le.__assign || function() {
2865
- return t = Object.assign || function(o) {
2866
- for (var s, a = 1, c = arguments.length; a < c; a++) {
2867
- s = arguments[a];
2868
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
2869
- }
2870
- return o;
2871
- }, t.apply(this, arguments);
2872
- };
2873
- Object.defineProperty(e, "__esModule", { value: !0 });
2874
- var n = P(), r = w();
2875
- e.sentenceId = "GSV", e.sentenceName = "Satellites in view";
2876
- function i(o, s) {
2877
- for (var a = (s.length - 4) / 4, c = [], u = 0; u < a; u++) {
2878
- var f = u * 4 + 4;
2879
- c.push({
2880
- prnNumber: n.parseIntSafe(s[f]),
2881
- elevationDegrees: n.parseIntSafe(s[f + 1]),
2882
- azimuthTrue: n.parseIntSafe(s[f + 2]),
2883
- SNRdB: n.parseIntSafe(s[f + 3])
2884
- });
2885
- }
2886
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { numberOfMessages: n.parseIntSafe(s[1]), messageNumber: n.parseIntSafe(s[2]), satellitesInView: n.parseIntSafe(s[3]), satellites: c });
2887
- }
2888
- e.decodeSentence = i;
2889
- })(le)), le;
2890
- }
2891
- var he = {}, Rt;
2892
- function Hr() {
2893
- return Rt || (Rt = 1, (function(e) {
2894
- var t = he && he.__assign || function() {
2895
- return t = Object.assign || function(o) {
2896
- for (var s, a = 1, c = arguments.length; a < c; a++) {
2897
- s = arguments[a];
2898
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
2899
- }
2900
- return o;
2901
- }, t.apply(this, arguments);
2902
- };
2903
- Object.defineProperty(e, "__esModule", { value: !0 });
2904
- var n = P(), r = w();
2905
- e.sentenceId = "HDG", e.sentenceName = "Heading - deviation and variation";
2906
- function i(o, s) {
2907
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { heading: n.parseFloatSafe(s[1]), deviation: n.parseFloatSafe(s[2]), deviationDirection: s[3] === "E" ? "E" : s[3] === "W" ? "W" : "", variation: n.parseFloatSafe(s[4]), variationDirection: s[5] === "E" ? "E" : s[5] === "W" ? "W" : "" });
2908
- }
2909
- e.decodeSentence = i;
2910
- })(he)), he;
2911
- }
2912
- var pe = {}, Nt;
2913
- function Ur() {
2914
- return Nt || (Nt = 1, (function(e) {
2915
- var t = pe && pe.__assign || function() {
2916
- return t = Object.assign || function(s) {
2917
- for (var a, c = 1, u = arguments.length; c < u; c++) {
2918
- a = arguments[c];
2919
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
2920
- }
2921
- return s;
2922
- }, t.apply(this, arguments);
2923
- };
2924
- Object.defineProperty(e, "__esModule", { value: !0 });
2925
- var n = P(), r = w();
2926
- e.sentenceId = "HDM", e.sentenceName = "Heading - magnetic";
2927
- function i(s, a) {
2928
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { heading: n.parseFloatSafe(a[1]) });
2929
- }
2930
- e.decodeSentence = i;
2931
- function o(s, a) {
2932
- var c = ["$" + a + e.sentenceId];
2933
- c.push(n.encodeFixed(s.heading, 1)), c.push("M");
2934
- var u = c.join(",");
2935
- return u + n.createNmeaChecksumFooter(u);
2936
- }
2937
- e.encodePacket = o;
2938
- })(pe)), pe;
2939
- }
2940
- var ge = {}, jt;
2941
- function Vr() {
2942
- return jt || (jt = 1, (function(e) {
2943
- var t = ge && ge.__assign || function() {
2944
- return t = Object.assign || function(s) {
2945
- for (var a, c = 1, u = arguments.length; c < u; c++) {
2946
- a = arguments[c];
2947
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
2948
- }
2949
- return s;
2950
- }, t.apply(this, arguments);
2951
- };
2952
- Object.defineProperty(e, "__esModule", { value: !0 });
2953
- var n = P(), r = w();
2954
- e.sentenceId = "HDT", e.sentenceName = "Heading - true";
2955
- function i(s, a) {
2956
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { heading: n.parseFloatSafe(a[1]) });
2957
- }
2958
- e.decodeSentence = i;
2959
- function o(s, a) {
2960
- var c = ["$" + a + e.sentenceId];
2961
- c.push(n.encodeFixed(s.heading, 1)), c.push("T");
2962
- var u = c.join(",");
2963
- return u + n.createNmeaChecksumFooter(u);
2964
- }
2965
- e.encodePacket = o;
2966
- })(ge)), ge;
2967
- }
2968
- var ve = {}, Gt;
2969
- function Kr() {
2970
- return Gt || (Gt = 1, (function(e) {
2971
- var t = ve && ve.__assign || function() {
2972
- return t = Object.assign || function(s) {
2973
- for (var a, c = 1, u = arguments.length; c < u; c++) {
2974
- a = arguments[c];
2975
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
2976
- }
2977
- return s;
2978
- }, t.apply(this, arguments);
2979
- };
2980
- Object.defineProperty(e, "__esModule", { value: !0 });
2981
- var n = P(), r = w();
2982
- e.sentenceId = "MTK", e.sentenceName = "Configuration packet";
2983
- function i(s, a) {
2984
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { packetType: n.parseIntSafe(s.sentenceId.substr(3)), data: a.slice(1).map(n.parseNumberOrString) });
2985
- }
2986
- e.decodeSentence = i;
2987
- function o(s, a) {
2988
- var c = ["$" + a + e.sentenceId + n.padLeft(s.packetType, 3, "0")];
2989
- c = c.concat(s.data.toString());
2990
- var u = c.join(",");
2991
- return u + n.createNmeaChecksumFooter(u);
2992
- }
2993
- e.encodePacket = o;
2994
- })(ve)), ve;
2995
- }
2996
- var me = {}, Lt;
2997
- function zr() {
2998
- return Lt || (Lt = 1, (function(e) {
2999
- var t = me && me.__assign || function() {
3000
- return t = Object.assign || function(s) {
3001
- for (var a, c = 1, u = arguments.length; c < u; c++) {
3002
- a = arguments[c];
3003
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
3004
- }
3005
- return s;
3006
- }, t.apply(this, arguments);
3007
- };
3008
- Object.defineProperty(e, "__esModule", { value: !0 });
3009
- var n = P(), r = w();
3010
- e.sentenceId = "MWV", e.sentenceName = "Wind speed and angle";
3011
- function i(s, a) {
3012
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { windAngle: n.parseFloatSafe(a[1]), reference: a[2] === "R" ? "relative" : "true", speed: n.parseFloatSafe(a[3]), units: a[4] === "K" ? "K" : a[4] === "M" ? "M" : "N", status: a[5] === "A" ? "valid" : "invalid" });
3013
- }
3014
- e.decodeSentence = i;
3015
- function o(s, a) {
3016
- var c = ["$" + a + e.sentenceId];
3017
- c.push(n.encodeDegrees(s.windAngle)), c.push(s.reference === "relative" ? "R" : "T"), c.push(n.encodeFixed(s.speed, 2)), c.push(s.units === "K" ? "K" : s.units === "M" ? "M" : "N"), c.push(s.status === "valid" ? "A" : "V");
3018
- var u = c.join(",");
3019
- return u + n.createNmeaChecksumFooter(u);
3020
- }
3021
- e.encodePacket = o;
3022
- })(me)), me;
3023
- }
3024
- var ye = {}, xt;
3025
- function Jr() {
3026
- return xt || (xt = 1, (function(e) {
3027
- var t = ye && ye.__assign || function() {
3028
- return t = Object.assign || function(o) {
3029
- for (var s, a = 1, c = arguments.length; a < c; a++) {
3030
- s = arguments[a];
3031
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
3032
- }
3033
- return o;
3034
- }, t.apply(this, arguments);
3035
- };
3036
- Object.defineProperty(e, "__esModule", { value: !0 });
3037
- var n = P(), r = w();
3038
- e.sentenceId = "RDID", e.sentenceName = "RDI proprietary heading, pitch, and roll";
3039
- function i(o, s) {
3040
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { roll: n.parseFloatSafe(s[1]), pitch: n.parseFloatSafe(s[2]), heading: n.parseFloatSafe(s[3]) });
3041
- }
3042
- e.decodeSentence = i;
3043
- })(ye)), ye;
3044
- }
3045
- var Se = {}, qt;
3046
- function Zr() {
3047
- return qt || (qt = 1, (function(e) {
3048
- var t = Se && Se.__assign || function() {
3049
- return t = Object.assign || function(o) {
3050
- for (var s, a = 1, c = arguments.length; a < c; a++) {
3051
- s = arguments[a];
3052
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
3053
- }
3054
- return o;
3055
- }, t.apply(this, arguments);
3056
- };
3057
- Object.defineProperty(e, "__esModule", { value: !0 });
3058
- var n = P(), r = w();
3059
- e.sentenceId = "RMC", e.sentenceName = "Recommended minimum navigation information";
3060
- function i(o, s) {
3061
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { datetime: n.parseDatetime(s[9], s[1]), status: s[2] === "A" ? "valid" : "warning", latitude: n.parseLatitude(s[3], s[4]), longitude: n.parseLongitude(s[5], s[6]), speedKnots: n.parseFloatSafe(s[7]), trackTrue: n.parseFloatSafe(s[8]), variation: n.parseFloatSafe(s[10]), variationPole: s[11] === "E" ? "E" : s[11] === "W" ? "W" : "", faaMode: s[12] });
3062
- }
3063
- e.decodeSentence = i;
3064
- })(Se)), Se;
3065
- }
3066
- var _e = {}, Wt;
3067
- function Yr() {
3068
- return Wt || (Wt = 1, (function(e) {
3069
- var t = _e && _e.__assign || function() {
3070
- return t = Object.assign || function(o) {
3071
- for (var s, a = 1, c = arguments.length; a < c; a++) {
3072
- s = arguments[a];
3073
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
3074
- }
3075
- return o;
3076
- }, t.apply(this, arguments);
3077
- };
3078
- Object.defineProperty(e, "__esModule", { value: !0 });
3079
- var n = P(), r = w();
3080
- e.sentenceId = "VHW", e.sentenceName = "Water speed and heading";
3081
- function i(o, s) {
3082
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { degreesTrue: n.parseFloatSafe(s[1]), degreesMagnetic: n.parseFloatSafe(s[3]), speedKnots: n.parseFloatSafe(s[5]), speedKmph: n.parseFloatSafe(s[7]) });
3083
- }
3084
- e.decodeSentence = i;
3085
- })(_e)), _e;
3086
- }
3087
- var be = {}, Bt;
3088
- function Xr() {
3089
- return Bt || (Bt = 1, (function(e) {
3090
- var t = be && be.__assign || function() {
3091
- return t = Object.assign || function(s) {
3092
- for (var a, c = 1, u = arguments.length; c < u; c++) {
3093
- a = arguments[c];
3094
- for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
3095
- }
3096
- return s;
3097
- }, t.apply(this, arguments);
3098
- };
3099
- Object.defineProperty(e, "__esModule", { value: !0 });
3100
- var n = P(), r = w();
3101
- e.sentenceId = "VTG", e.sentenceName = "Track made good and ground speed";
3102
- function i(s, a) {
3103
- return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { trackTrue: n.parseFloatSafe(a[1]), trackMagnetic: n.parseFloatSafe(a[3]), speedKnots: n.parseFloatSafe(a[5]), speedKmph: n.parseFloatSafe(a[7]), faaMode: a[9] });
3104
- }
3105
- e.decodeSentence = i;
3106
- function o(s, a) {
3107
- var c = ["$" + a + e.sentenceId];
3108
- c.push(n.encodeDegrees(s.trackTrue)), c.push("T"), c.push(n.encodeDegrees(s.trackMagnetic)), c.push("M"), c.push(n.encodeFixed(s.speedKnots, 2)), c.push("N"), s.speedKmph ? (c.push(n.encodeFixed(s.speedKmph, 2)), c.push("K")) : (c.push(""), c.push("")), s.faaMode && c.push(s.faaMode);
3109
- var u = c.join(",");
3110
- return u + n.createNmeaChecksumFooter(u);
3111
- }
3112
- e.encodePacket = o;
3113
- })(be)), be;
3114
- }
3115
- var Te = {}, Ht;
3116
- function Qr() {
3117
- return Ht || (Ht = 1, (function(e) {
3118
- var t = Te && Te.__assign || function() {
3119
- return t = Object.assign || function(o) {
3120
- for (var s, a = 1, c = arguments.length; a < c; a++) {
3121
- s = arguments[a];
3122
- for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
3123
- }
3124
- return o;
3125
- }, t.apply(this, arguments);
3126
- };
3127
- Object.defineProperty(e, "__esModule", { value: !0 });
3128
- var n = P(), r = w();
3129
- e.sentenceId = "ZDA", e.sentenceName = "UTC, day, month, year, and local time zone";
3130
- function i(o, s) {
3131
- return t(t({}, r.initStubFields(o, e.sentenceId, e.sentenceName)), { datetime: n.parseTime(s[1], s.slice(2, 5).join("")), localZoneHours: n.parseIntSafe(s[5]), localZoneMinutes: n.parseIntSafe(s[6]) });
3132
- }
3133
- e.decodeSentence = i;
3134
- })(Te)), Te;
3135
- }
3136
- var Ie = {}, Ut;
3137
- function vn() {
3138
- return Ut || (Ut = 1, (function(e) {
3139
- var t = Ie && Ie.__assign || function() {
3140
- return t = Object.assign || function(i) {
3141
- for (var o, s = 1, a = arguments.length; s < a; s++) {
3142
- o = arguments[s];
3143
- for (var c in o) Object.prototype.hasOwnProperty.call(o, c) && (i[c] = o[c]);
3144
- }
3145
- return i;
3146
- }, t.apply(this, arguments);
3147
- };
3148
- Object.defineProperty(e, "__esModule", { value: !0 });
3149
- var n = w();
3150
- e.sentenceId = "?";
3151
- function r(i, o) {
3152
- return t(t({}, n.initStubFields(i, e.sentenceId)), { originalPacketId: i.sentenceId, dataFields: o.slice(1) });
3153
- }
3154
- e.decodeSentence = r;
3155
- })(Ie)), Ie;
3156
- }
3157
- var Vt;
3158
- function $r() {
3159
- if (Vt) return O;
3160
- Vt = 1;
3161
- var e = O && O.__extends || /* @__PURE__ */ (function() {
3162
- var _ = function(b, k) {
3163
- return _ = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(E, L) {
3164
- E.__proto__ = L;
3165
- } || function(E, L) {
3166
- for (var z in L) L.hasOwnProperty(z) && (E[z] = L[z]);
3167
- }, _(b, k);
3168
- };
3169
- return function(b, k) {
3170
- _(b, k);
3171
- function E() {
3172
- this.constructor = b;
3173
- }
3174
- b.prototype = k === null ? Object.create(k) : (E.prototype = k.prototype, new E());
116
+ }, e.apply(this, arguments);
3175
117
  };
3176
- })();
3177
- Object.defineProperty(O, "__esModule", { value: !0 });
3178
- var t = Cr(), n = Rr(), r = Nr(), i = jr(), o = Gr(), s = Lr(), a = xr(), c = qr(), u = Wr(), f = Br(), l = Hr(), d = Ur(), p = Vr(), g = Kr(), y = zr(), I = Jr(), C = Zr(), R = Yr(), V = Xr(), Le = Qr(), ee = w(), xe = vn(), qe = P(), We = {
3179
- APB: t.decodeSentence,
3180
- BWC: n.decodeSentence,
3181
- DBT: r.decodeSentence,
3182
- DTM: i.decodeSentence,
3183
- GGA: o.decodeSentence,
3184
- GLL: s.decodeSentence,
3185
- GNS: a.decodeSentence,
3186
- GSA: c.decodeSentence,
3187
- GST: u.decodeSentence,
3188
- GSV: f.decodeSentence,
3189
- HDG: l.decodeSentence,
3190
- HDM: d.decodeSentence,
3191
- HDT: p.decodeSentence,
3192
- MTK: g.decodeSentence,
3193
- MWV: y.decodeSentence,
3194
- RDID: I.decodeSentence,
3195
- RMC: C.decodeSentence,
3196
- VHW: R.decodeSentence,
3197
- VTG: V.decodeSentence,
3198
- ZDA: Le.decodeSentence
3199
- }, Be = {
3200
- DBT: r.encodePacket,
3201
- GGA: o.encodePacket,
3202
- GLL: s.encodePacket,
3203
- GNS: a.encodePacket,
3204
- HDM: d.encodePacket,
3205
- HDT: p.encodePacket,
3206
- MTK: g.encodePacket,
3207
- MWV: y.encodePacket,
3208
- VTG: V.encodePacket
3209
- }, h = (
3210
- /** @class */
3211
- (function() {
3212
- function _(b) {
3213
- b === void 0 && (b = !1), this.ableToParseBadChecksum = b;
3214
- }
3215
- return _.getParser = function(b) {
3216
- return b.sentenceId.substr(0, 3) === "MTK" ? g.decodeSentence : We[b.sentenceId];
3217
- }, _.prototype.assemble = function(b, k) {
3218
- var E = _.getParser(b);
3219
- return E ? E(b, k) : this.assembleCustomPacket(b, k);
3220
- }, _.prototype.assembleCustomPacket = function(b, k) {
3221
- return null;
3222
- }, _;
3223
- })()
3224
- );
3225
- O.DefaultPacketFactory = h;
3226
- var v = new h();
3227
- function m(_, b) {
3228
- var k = !0;
3229
- if (!qe.validNmeaChecksum(_)) {
3230
- if (!b.ableToParseBadChecksum)
3231
- throw Error('Invalid sentence: "' + _ + '".');
3232
- k = !1;
118
+ Object.defineProperty(t, "__esModule", { value: !0 });
119
+ var r = P();
120
+ t.sentenceId = "?";
121
+ function o(a, n) {
122
+ return e(e({}, r.initStubFields(a, t.sentenceId)), { originalPacketId: a.sentenceId, dataFields: n.slice(1) });
3233
123
  }
3234
- var E = _.split("*")[0].split(","), L = ee.parseStub(E[0], k), z = b.assemble(L, E);
3235
- if (!z)
3236
- throw Error('No known parser for sentence ID "' + L.sentenceId + '".');
3237
- return z;
3238
- }
3239
- O.parseGenericPacket = m;
3240
- function S(_) {
3241
- return m(_, v);
3242
- }
3243
- O.parseNmeaSentence = S;
3244
- function D(_, b) {
3245
- if (b === void 0 && (b = "P"), _ === void 0)
3246
- throw new Error("Packet must be given.");
3247
- var k = Be[_.sentenceId];
3248
- if (k)
3249
- return k(_, b);
3250
- throw Error('No known encoder for sentence ID "' + _.sentenceId + '"');
3251
- }
3252
- O.encodeNmeaPacket = D;
3253
- var M = (
3254
- /** @class */
3255
- (function(_) {
3256
- e(b, _);
3257
- function b() {
3258
- return _.call(this, !0) || this;
3259
- }
3260
- return b.prototype.assembleCustomPacket = function(k, E) {
3261
- return xe.decodeSentence(k, E);
3262
- }, b;
3263
- })(h)
3264
- );
3265
- O.UnsafePacketFactory = M;
3266
- var N = new M();
3267
- function K(_) {
3268
- return m(_, N);
3269
- }
3270
- O.parseUnsafeNmeaSentence = K;
3271
- function W(_) {
3272
- return _.sentenceId === "?" ? _.originalPacketId : _.sentenceId;
3273
- }
3274
- return O.getUnsafePacketId = W, O;
124
+ t.decodeSentence = o;
125
+ })(f)), f;
3275
126
  }
3276
- var Ge = $r(), es = vn(), ut = w();
3277
- function G(e) {
3278
- return e === "" ? 0 : Number.parseFloat(e);
127
+ var M = L(), S = P();
128
+ function l(t) {
129
+ return t === "" ? 0 : Number.parseFloat(t);
3279
130
  }
3280
- const ts = "DBK", ns = "Depth Below Keel";
3281
- function rs(e, t) {
131
+ const w = "DBK", G = "Depth Below Keel";
132
+ function _(t, e) {
3282
133
  return {
3283
- ...ut.initStubFields(e, ts, ns),
3284
- depthFeet: G(t[1]),
3285
- depthMeters: G(t[3]),
3286
- depthFathoms: G(t[5])
134
+ ...S.initStubFields(t, w, G),
135
+ depthFeet: l(e[1]),
136
+ depthMeters: l(e[3]),
137
+ depthFathoms: l(e[5])
3287
138
  };
3288
139
  }
3289
- const ss = "DBS", is = "Depth Below Surface";
3290
- function os(e, t) {
140
+ const O = "DBS", F = "Depth Below Surface";
141
+ function x(t, e) {
3291
142
  return {
3292
- ...ut.initStubFields(e, ss, is),
3293
- depthFeet: G(t[1]),
3294
- depthMeters: G(t[3]),
3295
- depthFathoms: G(t[5])
143
+ ...S.initStubFields(t, O, F),
144
+ depthFeet: l(e[1]),
145
+ depthMeters: l(e[3]),
146
+ depthFathoms: l(e[5])
3296
147
  };
3297
148
  }
3298
- const as = "DPT", cs = "Depth of Water";
3299
- function us(e, t) {
149
+ const B = "DPT", K = "Depth of Water";
150
+ function V(t, e) {
3300
151
  return {
3301
- ...ut.initStubFields(e, as, cs),
3302
- depthMeters: G(t[1]),
3303
- offsetMeters: G(t[2]),
3304
- maximumRangeScale: G(t[3])
152
+ ...S.initStubFields(t, B, K),
153
+ depthMeters: l(e[1]),
154
+ offsetMeters: l(e[2]),
155
+ maximumRangeScale: l(e[3])
3305
156
  };
3306
157
  }
3307
- function mn(e, t) {
3308
- switch (e.talkerId) {
158
+ function N(t, e) {
159
+ switch (t.talkerId) {
3309
160
  case "DBS":
3310
- return os(e, t);
161
+ return x(t, e);
3311
162
  case "DBK":
3312
- return rs(e, t);
163
+ return _(t, e);
3313
164
  case "DPT":
3314
- return us(e, t);
165
+ return V(t, e);
3315
166
  default:
3316
167
  return null;
3317
168
  }
3318
169
  }
3319
- class ds extends Ge.DefaultPacketFactory {
3320
- assembleCustomPacket(t, n) {
3321
- return mn(t, n);
170
+ class U extends E {
171
+ assembleCustomPacket(e, r) {
172
+ return N(e, r);
3322
173
  }
3323
174
  }
3324
- const fs = new ds();
3325
- function Cs(e) {
3326
- return Ge.parseGenericPacket(e, fs);
175
+ const H = new U();
176
+ function fe(t) {
177
+ return v(t, H);
3327
178
  }
3328
- class ls extends Ge.DefaultPacketFactory {
179
+ class q extends E {
3329
180
  constructor() {
3330
181
  super(!0);
3331
182
  }
3332
- assembleCustomPacket(t, n) {
3333
- const r = mn(t, n);
3334
- return r || es.decodeSentence(t, n);
183
+ assembleCustomPacket(e, r) {
184
+ const o = N(e, r);
185
+ return o || M.decodeSentence(e, r);
3335
186
  }
3336
187
  }
3337
- const hs = new ls();
3338
- function ps(e) {
3339
- return Ge.parseGenericPacket(e, hs);
188
+ const $ = new q();
189
+ function Z(t) {
190
+ return v(t, $);
3340
191
  }
3341
- function Kt(e, t) {
3342
- return !t || t.length === 0 ? !0 : e !== void 0 && t.includes(e);
192
+ function b(t, e) {
193
+ return !e || e.length === 0 ? !0 : t !== void 0 && e.includes(t);
3343
194
  }
3344
- class gs {
195
+ class j {
3345
196
  /** Buffer for incomplete lines that span multiple chunks. */
3346
197
  container;
3347
198
  constructor() {
@@ -3354,12 +205,12 @@ class gs {
3354
205
  * @param chunk - The text chunk to process.
3355
206
  * @param controller - The transform stream controller to enqueue complete lines.
3356
207
  */
3357
- transform(t, n) {
3358
- this.container += t;
3359
- const r = this.container.split(`\r
3360
- `), i = r.pop();
3361
- this.container = i ?? "", r.forEach((o) => {
3362
- o.length > 0 && n.enqueue(o);
208
+ transform(e, r) {
209
+ this.container += e;
210
+ const o = this.container.split(`\r
211
+ `), a = o.pop();
212
+ this.container = a ?? "", o.forEach((n) => {
213
+ n.length > 0 && r.enqueue(n);
3363
214
  });
3364
215
  }
3365
216
  /**
@@ -3368,171 +219,172 @@ class gs {
3368
219
  *
3369
220
  * @param controller - The transform stream controller (required by interface but unused).
3370
221
  */
3371
- flush(t) {
222
+ flush(e) {
3372
223
  this.container = "";
3373
224
  }
3374
225
  }
3375
- const vs = hn(async ({ input: e }) => {
226
+ const W = T(async ({ input: t }) => {
3376
227
  if (!navigator.serial)
3377
228
  throw new Error("Web Serial API is not supported in this browser.");
3378
229
  console.log("Requesting serial port...");
3379
- const t = await navigator.serial.requestPort();
3380
- if (console.log(`Opening port at ${e.baudRate} baud...`), t.readable || t.writable) {
230
+ const e = await navigator.serial.requestPort();
231
+ if (console.log(`Opening port at ${t.baudRate} baud...`), e.readable || e.writable) {
3381
232
  console.log("Port is already open, closing first...");
3382
233
  try {
3383
- await t.close();
3384
- } catch (n) {
3385
- console.warn("Error closing already-open port:", n);
234
+ await e.close();
235
+ } catch (r) {
236
+ console.warn("Error closing already-open port:", r);
3386
237
  }
3387
238
  }
3388
- return await t.open({ baudRate: e.baudRate }), console.log("Port open."), t;
3389
- }), ms = hn(async ({ input: e }) => {
3390
- if (e.port)
239
+ return await e.open({ baudRate: t.baudRate }), console.log("Port open."), e;
240
+ }), Y = T(async ({ input: t }) => {
241
+ if (t.port)
3391
242
  try {
3392
- (e.port.readable || e.port.writable) && (await e.port.close(), console.log("Port closed successfully."));
3393
- } catch (t) {
3394
- console.warn("Error closing port:", t);
3395
- }
3396
- }), ys = gr(
3397
- ({ input: e, sendBack: t, receive: n }) => {
3398
- const { port: r } = e;
3399
- if (!r || !r.readable) {
3400
- t({ type: "SERIAL.ERROR", error: "Invalid port context." });
243
+ (t.port.readable || t.port.writable) && (await t.port.close(), console.log("Port closed successfully."));
244
+ } catch (e) {
245
+ console.warn("Error closing port:", e);
246
+ }
247
+ }), J = k(
248
+ ({ input: t, sendBack: e, receive: r }) => {
249
+ const { port: o } = t;
250
+ if (!o || !o.readable) {
251
+ e({ type: "SERIAL.ERROR", error: "Invalid port context." });
3401
252
  return;
3402
253
  }
3403
- const i = new gs(), s = r.readable.pipeThrough(new TextDecoderStream()).pipeThrough(
254
+ const a = new j(), s = o.readable.pipeThrough(new TextDecoderStream()).pipeThrough(
3404
255
  new TransformStream({
3405
- transform: i.transform.bind(i),
3406
- flush: i.flush.bind(i)
256
+ transform: a.transform.bind(a),
257
+ flush: a.flush.bind(a)
3407
258
  })
3408
259
  ).getReader();
3409
- let a = !0;
3410
- async function c() {
260
+ let c = !0;
261
+ async function i() {
3411
262
  try {
3412
- for (; a; ) {
3413
- const { value: u, done: f } = await s.read();
3414
- if (f)
263
+ for (; c; ) {
264
+ const { value: u, done: h } = await s.read();
265
+ if (h)
3415
266
  break;
3416
267
  if (u && u.length > 0)
3417
268
  try {
3418
- const l = ps(u);
3419
- if (l.sentenceId === "?")
269
+ const p = Z(u);
270
+ if (p.sentenceId === "?")
3420
271
  continue;
3421
- t({ type: "SERIAL.DATA", data: l });
3422
- } catch (l) {
3423
- const d = l instanceof Error ? l.message : String(l);
3424
- console.warn("Failed to parse NMEA sentence:", u, d), t({
272
+ e({ type: "SERIAL.DATA", data: p });
273
+ } catch (p) {
274
+ const m = p instanceof Error ? p.message : String(p);
275
+ console.warn("Failed to parse NMEA sentence:", u, m), e({
3425
276
  type: "SERIAL.ERROR",
3426
- error: `Parser Error: ${d}`
277
+ error: `Parser Error: ${m}`
3427
278
  });
3428
279
  }
3429
280
  }
3430
281
  } catch (u) {
3431
- if (console.error("Read loop error:", u), a) {
3432
- const f = u instanceof Error ? u.message : String(u);
3433
- t({ type: "FATAL_ERROR", error: f });
282
+ if (console.error("Read loop error:", u), c) {
283
+ const h = u instanceof Error ? u.message : String(u);
284
+ e({ type: "FATAL_ERROR", error: h });
3434
285
  }
3435
286
  } finally {
3436
- console.log("Read loop finished."), t({ type: "SERIAL.DISCONNECTED" });
287
+ console.log("Read loop finished."), e({ type: "SERIAL.DISCONNECTED" });
3437
288
  }
3438
289
  }
3439
- return c(), n((u) => {
3440
- u.type === "STOP" && (console.log("Received STOP, cancelling reader..."), a = !1, s.cancel().catch(() => {
290
+ return i(), r((u) => {
291
+ u.type === "STOP" && (console.log("Received STOP, cancelling reader..."), c = !1, s.cancel().catch(() => {
3441
292
  }));
3442
293
  }), () => {
3443
- console.log("Cleaning up stream reader actor..."), a = !1, s && s.cancel().catch(() => {
294
+ console.log("Cleaning up stream reader actor..."), c = !1, s && s.cancel().catch(() => {
3444
295
  });
3445
296
  };
3446
297
  }
3447
298
  );
3448
- function Ss(e) {
3449
- const { adapter: t, allowedSentenceIds: n, initialData: r, initialPackets: i } = e;
3450
- return gn({
299
+ function Q(t) {
300
+ const { adapter: e, allowedSentenceIds: r, initialData: o, initialPackets: a } = t;
301
+ return A({
302
+ types: {},
3451
303
  actors: {
3452
- connectToSerial: vs,
3453
- readNmeaStream: ys,
3454
- closePort: ms
304
+ connectToSerial: W,
305
+ readNmeaStream: J,
306
+ closePort: Y
3455
307
  },
3456
308
  actions: {
3457
309
  /**
3458
310
  * Sets the serial port in context and clears any error.
3459
311
  */
3460
- setPort: F((o, s) => ({
312
+ setPort: d((n, s) => ({
3461
313
  port: s.port,
3462
314
  error: null
3463
315
  })),
3464
316
  /**
3465
317
  * Sets an error message in context from a connection error.
3466
318
  */
3467
- setError: F((o, s) => {
3468
- const a = s.error;
3469
- let c;
3470
- return typeof a == "string" ? c = a : a instanceof Error ? c = a.message || "Failed to connect." : c = String(a) || "Failed to connect.", { error: c };
319
+ setError: d((n, s) => {
320
+ const c = s.error;
321
+ let i;
322
+ return typeof c == "string" ? i = c : c instanceof Error ? i = c.message || "Failed to connect." : i = String(c) || "Failed to connect.", { error: i };
3471
323
  }),
3472
324
  /**
3473
325
  * Logs parsed NMEA packet data to the console.
3474
326
  * Only logs packets with allowed sentence IDs if logging is enabled.
3475
327
  */
3476
- logParsedData: ({ context: o }, s) => {
3477
- if (!o.enableLogging)
328
+ logParsedData: ({ context: n }, s) => {
329
+ if (!n.enableLogging)
3478
330
  return;
3479
- const c = s.packet.sentenceId;
3480
- Kt(c, n) && console.log(`${c} Packet:`, s.packet);
331
+ const i = s.packet.sentenceId;
332
+ b(i, r) && console.log(`${i} Packet:`, s.packet);
3481
333
  },
3482
334
  /**
3483
335
  * Stores a parsed NMEA packet in context and recomputes data via the adapter.
3484
336
  * Only stores packets with allowed sentence IDs (if filtering is configured).
3485
337
  */
3486
- storePacket: F(({ context: o }, s) => {
3487
- const c = s.packet.sentenceId;
3488
- if (c && Kt(c, n)) {
338
+ storePacket: d(({ context: n }, s) => {
339
+ const i = s.packet.sentenceId;
340
+ if (i && b(i, r)) {
3489
341
  const u = {
3490
- ...o.packets,
3491
- [c]: s.packet
342
+ ...n.packets,
343
+ [i]: s.packet
3492
344
  };
3493
345
  return {
3494
346
  packets: u,
3495
- data: t(u),
347
+ data: e(u),
3496
348
  error: null
3497
349
  };
3498
350
  }
3499
351
  return {
3500
- packets: o.packets,
3501
- data: t(o.packets),
352
+ packets: n.packets,
353
+ data: e(n.packets),
3502
354
  error: null
3503
355
  };
3504
356
  }),
3505
357
  /**
3506
358
  * Sets a serial error message in context.
3507
359
  */
3508
- clearError: F((o, s) => ({
360
+ clearError: d((n, s) => ({
3509
361
  error: s.error
3510
362
  })),
3511
363
  /**
3512
364
  * Sets a fatal error message in context.
3513
365
  */
3514
- setFatalError: F((o, s) => ({
366
+ setFatalError: d((n, s) => ({
3515
367
  error: s.error
3516
368
  })),
3517
369
  /**
3518
370
  * Resets the machine context to disconnected state.
3519
371
  */
3520
- disconnect: F({
372
+ disconnect: d({
3521
373
  port: null,
3522
374
  error: null,
3523
- packets: i,
3524
- data: r
375
+ packets: a,
376
+ data: o
3525
377
  }),
3526
378
  /**
3527
379
  * Sets the logging enabled state.
3528
380
  */
3529
- setLogging: F((o, s) => ({
381
+ setLogging: d((n, s) => ({
3530
382
  enableLogging: s.enabled
3531
383
  })),
3532
384
  /**
3533
385
  * Sets the baud rate for serial communication.
3534
386
  */
3535
- setBaudRate: F((o, s) => ({
387
+ setBaudRate: d((n, s) => ({
3536
388
  baudRate: s.baudRate
3537
389
  }))
3538
390
  }
@@ -3542,8 +394,8 @@ function Ss(e) {
3542
394
  context: {
3543
395
  port: null,
3544
396
  error: null,
3545
- packets: i,
3546
- data: r,
397
+ packets: a,
398
+ data: o,
3547
399
  enableLogging: !1,
3548
400
  baudRate: 4800
3549
401
  },
@@ -3551,7 +403,7 @@ function Ss(e) {
3551
403
  SET_LOGGING: {
3552
404
  actions: {
3553
405
  type: "setLogging",
3554
- params: ({ event: o }) => ({ enabled: o.enabled })
406
+ params: ({ event: n }) => ({ enabled: n.enabled })
3555
407
  }
3556
408
  }
3557
409
  },
@@ -3562,7 +414,7 @@ function Ss(e) {
3562
414
  SET_BAUD_RATE: {
3563
415
  actions: {
3564
416
  type: "setBaudRate",
3565
- params: ({ event: o }) => ({ baudRate: o.baudRate })
417
+ params: ({ event: n }) => ({ baudRate: n.baudRate })
3566
418
  }
3567
419
  }
3568
420
  }
@@ -3571,19 +423,19 @@ function Ss(e) {
3571
423
  invoke: {
3572
424
  id: "connectToSerial",
3573
425
  src: "connectToSerial",
3574
- input: ({ context: o }) => ({ baudRate: o.baudRate }),
426
+ input: ({ context: n }) => ({ baudRate: n.baudRate }),
3575
427
  onDone: {
3576
428
  target: "connected",
3577
429
  actions: {
3578
430
  type: "setPort",
3579
- params: ({ event: o }) => ({ port: o.output })
431
+ params: ({ event: n }) => ({ port: n.output })
3580
432
  }
3581
433
  },
3582
434
  onError: {
3583
435
  target: "error",
3584
436
  actions: {
3585
437
  type: "setError",
3586
- params: ({ event: o }) => ({ error: o.error })
438
+ params: ({ event: n }) => ({ error: n.error })
3587
439
  }
3588
440
  }
3589
441
  }
@@ -3594,45 +446,45 @@ function Ss(e) {
3594
446
  actions: [
3595
447
  {
3596
448
  type: "logParsedData",
3597
- params: ({ event: o }) => ({ packet: o.data })
449
+ params: ({ event: n }) => ({ packet: n.data })
3598
450
  },
3599
451
  {
3600
452
  type: "storePacket",
3601
- params: ({ event: o }) => ({ packet: o.data })
453
+ params: ({ event: n }) => ({ packet: n.data })
3602
454
  }
3603
455
  ]
3604
456
  },
3605
457
  "SERIAL.ERROR": {
3606
458
  actions: {
3607
459
  type: "clearError",
3608
- params: ({ event: o }) => ({ error: o.error })
460
+ params: ({ event: n }) => ({ error: n.error })
3609
461
  }
3610
462
  },
3611
463
  FATAL_ERROR: {
3612
464
  target: "error",
3613
465
  actions: {
3614
466
  type: "setFatalError",
3615
- params: ({ event: o }) => ({ error: o.error })
467
+ params: ({ event: n }) => ({ error: n.error })
3616
468
  }
3617
469
  },
3618
470
  "SERIAL.DISCONNECTED": {
3619
471
  target: "disconnecting"
3620
472
  },
3621
473
  DISCONNECT: {
3622
- actions: je("streamReader", { type: "STOP" })
474
+ actions: C("streamReader", { type: "STOP" })
3623
475
  }
3624
476
  },
3625
477
  invoke: {
3626
478
  id: "streamReader",
3627
479
  src: "readNmeaStream",
3628
- input: ({ context: o }) => ({ port: o.port })
480
+ input: ({ context: n }) => ({ port: n.port })
3629
481
  }
3630
482
  },
3631
483
  disconnecting: {
3632
484
  invoke: {
3633
485
  id: "closePort",
3634
486
  src: "closePort",
3635
- input: ({ context: o }) => ({ port: o.port }),
487
+ input: ({ context: n }) => ({ port: n.port }),
3636
488
  onDone: {
3637
489
  target: "disconnected",
3638
490
  actions: "disconnect"
@@ -3651,78 +503,78 @@ function Ss(e) {
3651
503
  }
3652
504
  });
3653
505
  }
3654
- function _s(e, t, n) {
3655
- return e && e.fixType !== "none" ? {
3656
- latitude: e.latitude,
3657
- longitude: e.longitude,
3658
- source: "GGA",
3659
- fixType: e.fixType,
3660
- altitudeMeters: e.altitudeMeters,
3661
- satellitesInView: e.satellitesInView,
3662
- horizontalDilution: e.horizontalDilution
3663
- } : t && t.status === "valid" ? {
506
+ function X(t, e, r) {
507
+ return t && t.fixType !== "none" ? {
3664
508
  latitude: t.latitude,
3665
509
  longitude: t.longitude,
510
+ source: "GGA",
511
+ fixType: t.fixType,
512
+ altitudeMeters: t.altitudeMeters,
513
+ satellitesInView: t.satellitesInView,
514
+ horizontalDilution: t.horizontalDilution
515
+ } : e && e.status === "valid" ? {
516
+ latitude: e.latitude,
517
+ longitude: e.longitude,
3666
518
  source: "RMC",
3667
- status: t.status
3668
- } : n && n.status === "valid" ? {
3669
- latitude: n.latitude,
3670
- longitude: n.longitude,
519
+ status: e.status
520
+ } : r && r.status === "valid" ? {
521
+ latitude: r.latitude,
522
+ longitude: r.longitude,
3671
523
  source: "GLL",
3672
524
  status: "valid"
3673
525
  } : null;
3674
526
  }
3675
- function bs(e, t, n, r) {
3676
- if (e) {
3677
- const i = new Date(e.datetime), o = e.localZoneHours * 60 + e.localZoneMinutes;
3678
- return i.setMinutes(i.getMinutes() + o), {
3679
- utc: e.datetime,
3680
- local: i,
527
+ function z(t, e, r, o) {
528
+ if (t) {
529
+ const a = new Date(t.datetime), n = t.localZoneHours * 60 + t.localZoneMinutes;
530
+ return a.setMinutes(a.getMinutes() + n), {
531
+ utc: t.datetime,
532
+ local: a,
3681
533
  source: "ZDA"
3682
534
  };
3683
535
  }
3684
- return t && t.fixType !== "none" ? {
3685
- utc: t.time,
536
+ return e && e.fixType !== "none" ? {
537
+ utc: e.time,
3686
538
  local: null,
3687
539
  source: "GGA"
3688
- } : n && n.status === "valid" ? {
3689
- utc: n.datetime,
540
+ } : r && r.status === "valid" ? {
541
+ utc: r.datetime,
3690
542
  local: null,
3691
543
  source: "RMC"
3692
- } : r && r.status === "valid" ? {
3693
- utc: r.time,
544
+ } : o && o.status === "valid" ? {
545
+ utc: o.time,
3694
546
  local: null,
3695
547
  source: "GLL"
3696
548
  } : null;
3697
549
  }
3698
- function Ts(e, t) {
3699
- return e ? { knots: e.speedKnots, source: "VTG" } : t && t.status === "valid" ? { knots: t.speedKnots, source: "RMC" } : null;
550
+ function ee(t, e) {
551
+ return t ? { knots: t.speedKnots, source: "VTG" } : e && e.status === "valid" ? { knots: e.speedKnots, source: "RMC" } : null;
3700
552
  }
3701
- function Is(e) {
3702
- return e.variationDirection === "W" ? -e.variation : (e.variationDirection === "E", e.variation);
553
+ function te(t) {
554
+ return t.variationDirection === "W" ? -t.variation : (t.variationDirection === "E", t.variation);
3703
555
  }
3704
- function ws(e, t, n, r) {
3705
- if (e && e.heading !== void 0)
3706
- return { degreesTrue: e.heading, source: "HDT", isDerived: !1 };
3707
- if (t && t.heading !== void 0) {
3708
- const o = Is(t);
556
+ function ne(t, e, r, o) {
557
+ if (t && t.heading !== void 0)
558
+ return { degreesTrue: t.heading, source: "HDT", isDerived: !1 };
559
+ if (e && e.heading !== void 0) {
560
+ const n = te(e);
3709
561
  return {
3710
- degreesTrue: t.heading + o,
562
+ degreesTrue: e.heading + n,
3711
563
  source: "HDG",
3712
564
  isDerived: !1
3713
565
  };
3714
566
  }
3715
- const i = n?.trackTrue ?? r?.trackTrue;
3716
- return i !== void 0 ? { degreesTrue: i, source: "COG", isDerived: !0 } : null;
567
+ const a = r?.trackTrue ?? o?.trackTrue;
568
+ return a !== void 0 ? { degreesTrue: a, source: "COG", isDerived: !0 } : null;
3717
569
  }
3718
- function Ps(e, t, n, r) {
3719
- return e && e.depthMeters !== void 0 ? { meters: e.depthMeters, source: "DPT" } : t ? { meters: t.depthMeters, source: "DBT" } : n && n.depthMeters !== void 0 ? { meters: n.depthMeters, source: "DBS" } : r && r.depthMeters !== void 0 ? { meters: r.depthMeters, source: "DBK" } : null;
570
+ function re(t, e, r, o) {
571
+ return t && t.depthMeters !== void 0 ? { meters: t.depthMeters, source: "DPT" } : e ? { meters: e.depthMeters, source: "DBT" } : r && r.depthMeters !== void 0 ? { meters: r.depthMeters, source: "DBS" } : o && o.depthMeters !== void 0 ? { meters: o.depthMeters, source: "DBK" } : null;
3720
572
  }
3721
- function ks(e) {
3722
- const t = bs(e.ZDA, e.GGA, e.RMC, e.GLL), n = _s(e.GGA, e.RMC, e.GLL), r = Ts(e.VTG, e.RMC), i = ws(e.HDT, e.HDG, e.RMC, e.VTG), o = Ps(e.DPT, e.DBT, e.DBS, e.DBK);
3723
- return { time: t, position: n, speed: r, heading: i, depth: o };
573
+ function oe(t) {
574
+ const e = z(t.ZDA, t.GGA, t.RMC, t.GLL), r = X(t.GGA, t.RMC, t.GLL), o = ee(t.VTG, t.RMC), a = ne(t.HDT, t.HDG, t.RMC, t.VTG), n = re(t.DPT, t.DBT, t.DBS, t.DBK);
575
+ return { time: e, position: r, speed: o, heading: a, depth: n };
3724
576
  }
3725
- const Ds = [
577
+ const ae = [
3726
578
  "GGA",
3727
579
  "RMC",
3728
580
  "GLL",
@@ -3735,42 +587,49 @@ const Ds = [
3735
587
  "DBK",
3736
588
  "ZDA"
3737
589
  ];
3738
- function Es() {
3739
- return (e) => ks(e);
590
+ function se() {
591
+ return (t) => oe(t);
3740
592
  }
3741
- const As = {
593
+ const ie = {
3742
594
  time: null,
3743
595
  position: null,
3744
596
  speed: null,
3745
597
  heading: null,
3746
598
  depth: null
3747
- }, Ms = {};
3748
- function Os() {
599
+ }, ce = {};
600
+ function ue() {
3749
601
  return {
3750
- adapter: Es(),
3751
- allowedSentenceIds: Ds,
3752
- initialData: As,
3753
- initialPackets: Ms
602
+ adapter: se(),
603
+ allowedSentenceIds: ae,
604
+ initialData: ie,
605
+ initialPackets: ce
3754
606
  };
3755
607
  }
3756
- function Fs() {
3757
- return Ss(Os());
608
+ function le() {
609
+ return Q(ue());
3758
610
  }
3759
- function Rs(e) {
3760
- const t = Fs();
3761
- return new Fr(t, {
3762
- enableLogging: e?.enableLogging,
3763
- baudRate: e?.baudRate,
3764
- onData: e?.onData,
3765
- onStateChange: e?.onStateChange,
3766
- onError: e?.onError
3767
- });
611
+ class ge extends I {
612
+ /**
613
+ * Creates a new navigation NMEA client.
614
+ *
615
+ * @param options - Optional configuration and callbacks.
616
+ */
617
+ constructor(e) {
618
+ const r = le();
619
+ super(r, {
620
+ enableLogging: e?.enableLogging,
621
+ baudRate: e?.baudRate,
622
+ onData: e?.onData,
623
+ onStateChange: e?.onStateChange,
624
+ onError: e?.onError
625
+ });
626
+ }
3768
627
  }
3769
628
  export {
3770
- Fr as NmeaClient,
3771
- Rs as createNavigationNmeaClient,
3772
- Fs as createNavigationNmeaMachine,
3773
- Ss as createNmeaMachine,
3774
- Cs as parseNmeaSentence,
3775
- ps as parseUnsafeNmeaSentence
629
+ ge as NavigationNmeaClient,
630
+ I as NmeaClient,
631
+ le as createNavigationNmeaMachine,
632
+ Q as createNmeaMachine,
633
+ fe as parseNmeaSentence,
634
+ Z as parseUnsafeNmeaSentence
3776
635
  };