nmea-web-serial 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +0 -0
- package/dist/nmea-web-serial.cjs +4 -0
- package/dist/nmea-web-serial.d.ts +1421 -0
- package/dist/nmea-web-serial.iife.js +4 -0
- package/dist/nmea-web-serial.js +3858 -0
- package/dist/nmea-web-serial.umd.cjs +4 -0
- package/package.json +72 -0
|
@@ -0,0 +1,3858 @@
|
|
|
1
|
+
function Tn() {
|
|
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 In() {
|
|
12
|
+
const e = Tn();
|
|
13
|
+
if (e.__xstate__)
|
|
14
|
+
return e.__xstate__;
|
|
15
|
+
}
|
|
16
|
+
const wn = (e) => {
|
|
17
|
+
if (typeof window > "u")
|
|
18
|
+
return;
|
|
19
|
+
const t = In();
|
|
20
|
+
t && t.register(e);
|
|
21
|
+
};
|
|
22
|
+
class ft {
|
|
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 Yt = ".", kn = "", Zt = "", Pn = "#", Dn = "*", Xt = "xstate.init", Mn = "xstate.error", ke = "xstate.stop";
|
|
52
|
+
function An(e, t) {
|
|
53
|
+
return {
|
|
54
|
+
type: `xstate.after.${e}.${t}`
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function ze(e, t) {
|
|
58
|
+
return {
|
|
59
|
+
type: `xstate.done.state.${e}`,
|
|
60
|
+
output: t
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function En(e, t) {
|
|
64
|
+
return {
|
|
65
|
+
type: `xstate.done.actor.${e}`,
|
|
66
|
+
output: t,
|
|
67
|
+
actorId: e
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function Qt(e, t) {
|
|
71
|
+
return {
|
|
72
|
+
type: `xstate.error.actor.${e}`,
|
|
73
|
+
error: t,
|
|
74
|
+
actorId: e
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function $t(e) {
|
|
78
|
+
return {
|
|
79
|
+
type: Xt,
|
|
80
|
+
input: e
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function j(e) {
|
|
84
|
+
setTimeout(() => {
|
|
85
|
+
throw e;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const Fn = typeof Symbol == "function" && Symbol.observable || "@@observable";
|
|
89
|
+
function en(e, t) {
|
|
90
|
+
const n = lt(e), r = lt(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 ? en(n[i], r[i]) : !1);
|
|
92
|
+
}
|
|
93
|
+
function $e(e) {
|
|
94
|
+
if (nn(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 lt(e) {
|
|
114
|
+
if (ur(e))
|
|
115
|
+
return e.value;
|
|
116
|
+
if (typeof e != "string")
|
|
117
|
+
return e;
|
|
118
|
+
const t = $e(e);
|
|
119
|
+
return On(t);
|
|
120
|
+
}
|
|
121
|
+
function On(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 ht(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 tn(e) {
|
|
144
|
+
return nn(e) ? e : [e];
|
|
145
|
+
}
|
|
146
|
+
function q(e) {
|
|
147
|
+
return e === void 0 ? [] : tn(e);
|
|
148
|
+
}
|
|
149
|
+
function Je(e, t, n, r) {
|
|
150
|
+
return typeof e == "function" ? e({
|
|
151
|
+
context: t,
|
|
152
|
+
event: n,
|
|
153
|
+
self: r
|
|
154
|
+
}) : e;
|
|
155
|
+
}
|
|
156
|
+
function nn(e) {
|
|
157
|
+
return Array.isArray(e);
|
|
158
|
+
}
|
|
159
|
+
function Nn(e) {
|
|
160
|
+
return e.type.startsWith("xstate.error.actor");
|
|
161
|
+
}
|
|
162
|
+
function Z(e) {
|
|
163
|
+
return tn(e).map((t) => typeof t > "u" || typeof t == "string" ? {
|
|
164
|
+
target: t
|
|
165
|
+
} : t);
|
|
166
|
+
}
|
|
167
|
+
function rn(e) {
|
|
168
|
+
if (!(e === void 0 || e === kn))
|
|
169
|
+
return q(e);
|
|
170
|
+
}
|
|
171
|
+
function Ye(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 pt(e, t) {
|
|
180
|
+
return `${t}.${e}`;
|
|
181
|
+
}
|
|
182
|
+
function et(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 vt(e, t) {
|
|
190
|
+
return `${e.sessionId}.${t}`;
|
|
191
|
+
}
|
|
192
|
+
let Cn = 0;
|
|
193
|
+
function Rn(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, v, y, I = Math.random().toString(36).slice(2)) => {
|
|
199
|
+
const N = {
|
|
200
|
+
source: d,
|
|
201
|
+
target: p,
|
|
202
|
+
event: v,
|
|
203
|
+
delay: y,
|
|
204
|
+
id: I,
|
|
205
|
+
startedAt: Date.now()
|
|
206
|
+
}, C = vt(d, I);
|
|
207
|
+
l._snapshot._scheduledEvents[C] = N;
|
|
208
|
+
const K = a.setTimeout(() => {
|
|
209
|
+
delete s[C], delete l._snapshot._scheduledEvents[C], l._relay(d, p, v);
|
|
210
|
+
}, y);
|
|
211
|
+
s[C] = K;
|
|
212
|
+
},
|
|
213
|
+
cancel: (d, p) => {
|
|
214
|
+
const v = vt(d, p), y = s[v];
|
|
215
|
+
delete s[v], delete l._snapshot._scheduledEvents[v], y !== void 0 && a.clearTimeout(y);
|
|
216
|
+
},
|
|
217
|
+
cancelAll: (d) => {
|
|
218
|
+
for (const p in l._snapshot._scheduledEvents) {
|
|
219
|
+
const v = l._snapshot._scheduledEvents[p];
|
|
220
|
+
v.source === d && u.cancel(d, v.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((v) => v.next?.(p));
|
|
231
|
+
}, l = {
|
|
232
|
+
_snapshot: {
|
|
233
|
+
_scheduledEvents: (t?.snapshot && t.snapshot.scheduler) ?? {}
|
|
234
|
+
},
|
|
235
|
+
_bookId: () => `x:${Cn++}`,
|
|
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 v = r.get(d);
|
|
246
|
+
if (v && v !== 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 = Ye(d);
|
|
252
|
+
return o.add(p), {
|
|
253
|
+
unsubscribe() {
|
|
254
|
+
o.delete(p);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
},
|
|
258
|
+
_sendInspectionEvent: f,
|
|
259
|
+
_relay: (d, p, v) => {
|
|
260
|
+
l._sendInspectionEvent({
|
|
261
|
+
type: "@xstate.event",
|
|
262
|
+
sourceRef: d,
|
|
263
|
+
actorRef: p,
|
|
264
|
+
event: v
|
|
265
|
+
}), p._send(v);
|
|
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: v,
|
|
279
|
+
target: y,
|
|
280
|
+
event: I,
|
|
281
|
+
delay: N,
|
|
282
|
+
id: C
|
|
283
|
+
} = d[p];
|
|
284
|
+
u.schedule(v, y, I, N, C);
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
_clock: a,
|
|
288
|
+
_logger: c
|
|
289
|
+
};
|
|
290
|
+
return l;
|
|
291
|
+
}
|
|
292
|
+
let Be = !1;
|
|
293
|
+
const tt = 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 jn = {
|
|
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 Gn {
|
|
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 ft(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
|
+
...jn,
|
|
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 : Rn(this, {
|
|
328
|
+
clock: i,
|
|
329
|
+
logger: o
|
|
330
|
+
}), f && !s && this.system.inspect(Ye(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 v = [...d ? d.values() : [], ...p ? p.values() : []];
|
|
349
|
+
for (const y of v)
|
|
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 = Be;
|
|
368
|
+
try {
|
|
369
|
+
Be = !0, l.exec(l.info, l.params);
|
|
370
|
+
} finally {
|
|
371
|
+
Be = 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 = En(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 = Ye(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 = $t(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 === ke && (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: ke
|
|
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, Qt(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 ft(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 : wn)(this);
|
|
660
|
+
}
|
|
661
|
+
toJSON() {
|
|
662
|
+
return {
|
|
663
|
+
xstate$$type: tt,
|
|
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
|
+
[Fn]() {
|
|
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 Ae(e, ...[t]) {
|
|
705
|
+
return new Gn(e, t);
|
|
706
|
+
}
|
|
707
|
+
function Ln(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 xn(e, t) {
|
|
716
|
+
e.defer(() => {
|
|
717
|
+
e.system.scheduler.cancel(e.self, t.sendId);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
function nt(e) {
|
|
721
|
+
function t(n, r) {
|
|
722
|
+
}
|
|
723
|
+
return t.type = "xstate.cancel", t.sendId = e, t.resolve = Ln, t.execute = xn, t;
|
|
724
|
+
}
|
|
725
|
+
function qn(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" ? et(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 = Ae(u, {
|
|
739
|
+
id: f,
|
|
740
|
+
src: s,
|
|
741
|
+
parent: e.self,
|
|
742
|
+
syncSnapshot: c,
|
|
743
|
+
systemId: o,
|
|
744
|
+
input: d
|
|
745
|
+
})), [V(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 Un(e, {
|
|
759
|
+
actorRef: t
|
|
760
|
+
}) {
|
|
761
|
+
t && e.defer(() => {
|
|
762
|
+
t._processingStatus !== A.Stopped && t.start();
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
function rt(...[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 = qn, o.execute = Un, o;
|
|
774
|
+
}
|
|
775
|
+
function Hn(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]), [V(t, {
|
|
783
|
+
children: a
|
|
784
|
+
}), s, void 0];
|
|
785
|
+
}
|
|
786
|
+
function Wn(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 = Hn, t.execute = Wn, 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 st = (e) => e.type === "atomic" || e.type === "final";
|
|
825
|
+
function Q(e) {
|
|
826
|
+
return Object.values(e.states).filter((t) => t.type !== "history");
|
|
827
|
+
}
|
|
828
|
+
function Pe(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 Ee(e) {
|
|
838
|
+
const t = new Set(e), n = on(t);
|
|
839
|
+
for (const r of t)
|
|
840
|
+
if (r.type === "compound" && (!n.get(r) || !n.get(r).length))
|
|
841
|
+
mt(r).forEach((i) => t.add(i));
|
|
842
|
+
else if (r.type === "parallel") {
|
|
843
|
+
for (const i of Q(r))
|
|
844
|
+
if (i.type !== "history" && !t.has(i)) {
|
|
845
|
+
const o = mt(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 sn(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 (st(i))
|
|
865
|
+
return i.key;
|
|
866
|
+
} else
|
|
867
|
+
return {};
|
|
868
|
+
}
|
|
869
|
+
const r = {};
|
|
870
|
+
for (const i of n)
|
|
871
|
+
r[i.key] = sn(i, t);
|
|
872
|
+
return r;
|
|
873
|
+
}
|
|
874
|
+
function on(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 an(e, t) {
|
|
881
|
+
const n = Ee(t);
|
|
882
|
+
return sn(e, on(n));
|
|
883
|
+
}
|
|
884
|
+
function it(e, t) {
|
|
885
|
+
return t.type === "compound" ? Q(t).some((n) => n.type === "final" && e.has(n)) : t.type === "parallel" ? Q(t).every((n) => it(e, n)) : t.type === "final";
|
|
886
|
+
}
|
|
887
|
+
const je = (e) => e[0] === Pn;
|
|
888
|
+
function Bn(e, t) {
|
|
889
|
+
return e.transitions.get(t) || [...e.transitions.keys()].filter((r) => {
|
|
890
|
+
if (r === Dn)
|
|
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 Vn(e) {
|
|
906
|
+
const t = e.config.after;
|
|
907
|
+
if (!t)
|
|
908
|
+
return [];
|
|
909
|
+
const n = (i) => {
|
|
910
|
+
const o = An(i, e.id), s = o.type;
|
|
911
|
+
return e.entry.push(ct(o, {
|
|
912
|
+
id: s,
|
|
913
|
+
delay: i
|
|
914
|
+
})), e.exit.push(nt(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 q(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
|
+
...W(e, i.event, i),
|
|
931
|
+
delay: o
|
|
932
|
+
};
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
function W(e, t, n) {
|
|
936
|
+
const r = rn(n.target), i = n.reenter ?? !1, o = Jn(e, r), s = {
|
|
937
|
+
...n,
|
|
938
|
+
actions: q(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 Kn(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 === Zt)
|
|
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) => W(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) => W(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) => W(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) => W(e, r, i)));
|
|
973
|
+
}
|
|
974
|
+
if (n.onSnapshot) {
|
|
975
|
+
const r = `xstate.snapshot.${n.id}`;
|
|
976
|
+
t.set(r, Z(n.onSnapshot).map((i) => W(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 zn(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" ? [] : q(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 Jn(e, t) {
|
|
1007
|
+
if (t !== void 0)
|
|
1008
|
+
return t.map((n) => {
|
|
1009
|
+
if (typeof n != "string")
|
|
1010
|
+
return n;
|
|
1011
|
+
if (je(n))
|
|
1012
|
+
return e.machine.getStateNodeById(n);
|
|
1013
|
+
const r = n[0] === Yt;
|
|
1014
|
+
if (r && !e.parent)
|
|
1015
|
+
return Fe(e, n.slice(1));
|
|
1016
|
+
const i = r ? e.key + n : n;
|
|
1017
|
+
if (e.parent)
|
|
1018
|
+
try {
|
|
1019
|
+
return Fe(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 cn(e) {
|
|
1029
|
+
const t = rn(e.config.target);
|
|
1030
|
+
return t ? {
|
|
1031
|
+
target: t.map((n) => typeof n == "string" ? Fe(e.parent, n) : n)
|
|
1032
|
+
} : e.parent.initial;
|
|
1033
|
+
}
|
|
1034
|
+
function B(e) {
|
|
1035
|
+
return e.type === "history";
|
|
1036
|
+
}
|
|
1037
|
+
function mt(e) {
|
|
1038
|
+
const t = un(e);
|
|
1039
|
+
for (const n of t)
|
|
1040
|
+
for (const r of Pe(n, e))
|
|
1041
|
+
t.add(r);
|
|
1042
|
+
return t;
|
|
1043
|
+
}
|
|
1044
|
+
function un(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 Q(r))
|
|
1052
|
+
n(i);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
return n(e), t;
|
|
1056
|
+
}
|
|
1057
|
+
function $(e, t) {
|
|
1058
|
+
if (je(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 Fe(e, t) {
|
|
1068
|
+
if (typeof t == "string" && je(t))
|
|
1069
|
+
try {
|
|
1070
|
+
return e.machine.getStateNodeById(t);
|
|
1071
|
+
} catch {
|
|
1072
|
+
}
|
|
1073
|
+
const n = $e(t).slice();
|
|
1074
|
+
let r = e;
|
|
1075
|
+
for (; n.length; ) {
|
|
1076
|
+
const i = n.shift();
|
|
1077
|
+
if (!i.length)
|
|
1078
|
+
break;
|
|
1079
|
+
r = $(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) => $(e, i)).filter(Boolean);
|
|
1091
|
+
return [e.machine.root, e].concat(r, n.reduce((i, o) => {
|
|
1092
|
+
const s = $(e, o);
|
|
1093
|
+
if (!s)
|
|
1094
|
+
return i;
|
|
1095
|
+
const a = Oe(s, t[o]);
|
|
1096
|
+
return i.concat(a);
|
|
1097
|
+
}, []));
|
|
1098
|
+
}
|
|
1099
|
+
function Yn(e, t, n, r) {
|
|
1100
|
+
const o = $(e, t).next(n, r);
|
|
1101
|
+
return !o || !o.length ? e.next(n, r) : o;
|
|
1102
|
+
}
|
|
1103
|
+
function Zn(e, t, n, r) {
|
|
1104
|
+
const i = Object.keys(t), o = $(e, i[0]), s = ot(o, t[i[0]], n, r);
|
|
1105
|
+
return !s || !s.length ? e.next(n, r) : s;
|
|
1106
|
+
}
|
|
1107
|
+
function Xn(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 = $(e, o), c = ot(a, s, n, r);
|
|
1114
|
+
c && i.push(...c);
|
|
1115
|
+
}
|
|
1116
|
+
return i.length ? i : e.next(n, r);
|
|
1117
|
+
}
|
|
1118
|
+
function ot(e, t, n, r) {
|
|
1119
|
+
return typeof t == "string" ? Yn(e, t, n, r) : Object.keys(t).length === 1 ? Zn(e, t, n, r) : Xn(e, t, n, r);
|
|
1120
|
+
}
|
|
1121
|
+
function Qn(e) {
|
|
1122
|
+
return Object.keys(e.states).map((t) => e.states[t]).filter((t) => t.type === "history");
|
|
1123
|
+
}
|
|
1124
|
+
function U(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 $n(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 dn(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 ($n(Ze([i], t, n), Ze([a], t, n)))
|
|
1147
|
+
if (U(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 er(e) {
|
|
1162
|
+
const [t, ...n] = e;
|
|
1163
|
+
for (const r of Pe(t, void 0))
|
|
1164
|
+
if (n.every((i) => U(i, r)))
|
|
1165
|
+
return r;
|
|
1166
|
+
}
|
|
1167
|
+
function at(e, t) {
|
|
1168
|
+
if (!e.target)
|
|
1169
|
+
return [];
|
|
1170
|
+
const n = /* @__PURE__ */ new Set();
|
|
1171
|
+
for (const r of e.target)
|
|
1172
|
+
if (B(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 at(cn(r), t))
|
|
1178
|
+
n.add(i);
|
|
1179
|
+
else
|
|
1180
|
+
n.add(r);
|
|
1181
|
+
return [...n];
|
|
1182
|
+
}
|
|
1183
|
+
function fn(e, t) {
|
|
1184
|
+
const n = at(e, t);
|
|
1185
|
+
if (!n)
|
|
1186
|
+
return;
|
|
1187
|
+
if (!e.reenter && n.every((i) => i === e.source || U(i, e.source)))
|
|
1188
|
+
return e.source;
|
|
1189
|
+
const r = er(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 = fn(i, n);
|
|
1200
|
+
i.reenter && i.source === o && r.add(o);
|
|
1201
|
+
for (const s of t)
|
|
1202
|
+
U(s, o) && r.add(s);
|
|
1203
|
+
}
|
|
1204
|
+
return [...r];
|
|
1205
|
+
}
|
|
1206
|
+
function tr(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 Xe(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 = dn(e, s, a);
|
|
1220
|
+
let u = t;
|
|
1221
|
+
i || ([u, a] = ir(u, r, n, c, s, a, o, n.actionExecutor)), u = ee(u, r, n, c.flatMap((l) => l.actions), o, void 0), u = rr(u, r, n, c, s, o, a, i);
|
|
1222
|
+
const f = [...s];
|
|
1223
|
+
u.status === "done" && (u = ee(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 && tr(t._nodes, s) ? u : V(u, {
|
|
1226
|
+
_nodes: f,
|
|
1227
|
+
historyValue: a
|
|
1228
|
+
});
|
|
1229
|
+
} catch (l) {
|
|
1230
|
+
throw l;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
function nr(e, t, n, r, i) {
|
|
1234
|
+
if (r.output === void 0)
|
|
1235
|
+
return;
|
|
1236
|
+
const o = ze(i.id, i.output !== void 0 && i.parent ? Je(i.output, e.context, t, n.self) : void 0);
|
|
1237
|
+
return Je(r.output, e.context, o, n.self);
|
|
1238
|
+
}
|
|
1239
|
+
function rr(e, t, n, r, i, o, s, a) {
|
|
1240
|
+
let c = e;
|
|
1241
|
+
const u = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
|
|
1242
|
+
sr(r, s, f, u), a && f.add(e.machine.root);
|
|
1243
|
+
const l = /* @__PURE__ */ new Set();
|
|
1244
|
+
for (const d of [...u].sort((p, v) => p.order - v.order)) {
|
|
1245
|
+
i.add(d);
|
|
1246
|
+
const p = [];
|
|
1247
|
+
p.push(...d.entry);
|
|
1248
|
+
for (const v of d.invoke)
|
|
1249
|
+
p.push(rt(v.src, {
|
|
1250
|
+
...v,
|
|
1251
|
+
syncSnapshot: !!v.onSnapshot
|
|
1252
|
+
}));
|
|
1253
|
+
if (f.has(d)) {
|
|
1254
|
+
const v = d.initial.actions;
|
|
1255
|
+
p.push(...v);
|
|
1256
|
+
}
|
|
1257
|
+
if (c = ee(c, t, n, p, o, d.invoke.map((v) => v.id)), d.type === "final") {
|
|
1258
|
+
const v = d.parent;
|
|
1259
|
+
let y = v?.type === "parallel" ? v : v?.parent, I = y || d;
|
|
1260
|
+
for (v?.type === "compound" && o.push(ze(v.id, d.output !== void 0 ? Je(d.output, c.context, t, n.self) : void 0)); y?.type === "parallel" && !l.has(y) && it(i, y); )
|
|
1261
|
+
l.add(y), o.push(ze(y.id)), I = y, y = y.parent;
|
|
1262
|
+
if (y)
|
|
1263
|
+
continue;
|
|
1264
|
+
c = V(c, {
|
|
1265
|
+
status: "done",
|
|
1266
|
+
output: nr(c, t, n, c.machine.root, I)
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
return c;
|
|
1271
|
+
}
|
|
1272
|
+
function sr(e, t, n, r) {
|
|
1273
|
+
for (const i of e) {
|
|
1274
|
+
const o = fn(i, t);
|
|
1275
|
+
for (const a of i.target || [])
|
|
1276
|
+
!B(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)), X(a, t, n, r);
|
|
1281
|
+
const s = at(i, t);
|
|
1282
|
+
for (const a of s) {
|
|
1283
|
+
const c = Pe(a, o);
|
|
1284
|
+
o?.type === "parallel" && c.push(o), ln(r, t, n, c, !i.source.parent && i.reenter ? void 0 : o);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
function X(e, t, n, r) {
|
|
1289
|
+
if (B(e))
|
|
1290
|
+
if (t[e.id]) {
|
|
1291
|
+
const i = t[e.id];
|
|
1292
|
+
for (const o of i)
|
|
1293
|
+
r.add(o), X(o, t, n, r);
|
|
1294
|
+
for (const o of i)
|
|
1295
|
+
Ve(o, e.parent, r, t, n);
|
|
1296
|
+
} else {
|
|
1297
|
+
const i = cn(e);
|
|
1298
|
+
for (const o of i.target)
|
|
1299
|
+
r.add(o), i === e.parent?.initial && n.add(e.parent), X(o, t, n, r);
|
|
1300
|
+
for (const o of i.target)
|
|
1301
|
+
Ve(o, e.parent, r, t, n);
|
|
1302
|
+
}
|
|
1303
|
+
else if (e.type === "compound") {
|
|
1304
|
+
const [i] = e.initial.target;
|
|
1305
|
+
B(i) || (r.add(i), n.add(i)), X(i, t, n, r), Ve(i, e, r, t, n);
|
|
1306
|
+
} else if (e.type === "parallel")
|
|
1307
|
+
for (const i of Q(e).filter((o) => !B(o)))
|
|
1308
|
+
[...r].some((o) => U(o, i)) || (B(i) || (r.add(i), n.add(i)), X(i, t, n, r));
|
|
1309
|
+
}
|
|
1310
|
+
function ln(e, t, n, r, i) {
|
|
1311
|
+
for (const o of r)
|
|
1312
|
+
if ((!i || U(o, i)) && e.add(o), o.type === "parallel")
|
|
1313
|
+
for (const s of Q(o).filter((a) => !B(a)))
|
|
1314
|
+
[...e].some((a) => U(a, s)) || (e.add(s), X(s, t, n, e));
|
|
1315
|
+
}
|
|
1316
|
+
function Ve(e, t, n, r, i) {
|
|
1317
|
+
ln(n, r, i, Pe(e, t));
|
|
1318
|
+
}
|
|
1319
|
+
function ir(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 Qn(l)) {
|
|
1326
|
+
let p;
|
|
1327
|
+
d.history === "deep" ? p = (v) => st(v) && U(v, l) : p = (v) => v.parent === l, f ??= {
|
|
1328
|
+
...o
|
|
1329
|
+
}, f[d.id] = Array.from(i).filter(p);
|
|
1330
|
+
}
|
|
1331
|
+
for (const l of u)
|
|
1332
|
+
c = ee(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 or(e, t) {
|
|
1336
|
+
return e.implementations.actions[t];
|
|
1337
|
+
}
|
|
1338
|
+
function hn(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
|
+
or(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, [v, y, I] = p.resolve(
|
|
1368
|
+
n,
|
|
1369
|
+
a,
|
|
1370
|
+
l,
|
|
1371
|
+
d,
|
|
1372
|
+
f,
|
|
1373
|
+
// this holds all params
|
|
1374
|
+
i
|
|
1375
|
+
);
|
|
1376
|
+
a = v, "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 = hn(a, t, n, I, i, o));
|
|
1382
|
+
}
|
|
1383
|
+
return a;
|
|
1384
|
+
}
|
|
1385
|
+
function ee(e, t, n, r, i, o) {
|
|
1386
|
+
const s = o ? [] : void 0, a = hn(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 Ke(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 === ke)
|
|
1407
|
+
return i = V(gt(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 !== Xt) {
|
|
1415
|
+
const u = a, f = Nn(u), l = yt(u, i);
|
|
1416
|
+
if (f && !l.length)
|
|
1417
|
+
return i = V(e, {
|
|
1418
|
+
status: "error",
|
|
1419
|
+
error: u.error
|
|
1420
|
+
}), s(i, u, []), {
|
|
1421
|
+
snapshot: i,
|
|
1422
|
+
microstates: o
|
|
1423
|
+
};
|
|
1424
|
+
i = Xe(
|
|
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 ? ar(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 = yt(a, i);
|
|
1442
|
+
}
|
|
1443
|
+
i = Xe(u, i, n, a, !1, r), c = i !== f, s(i, a, u);
|
|
1444
|
+
}
|
|
1445
|
+
return i.status !== "active" && gt(i, a, n), {
|
|
1446
|
+
snapshot: i,
|
|
1447
|
+
microstates: o
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
function gt(e, t, n) {
|
|
1451
|
+
return ee(e, t, n, Object.values(e.children).map((r) => Ce(r)), [], void 0);
|
|
1452
|
+
}
|
|
1453
|
+
function yt(e, t) {
|
|
1454
|
+
return t.machine.getTransitionData(t, e);
|
|
1455
|
+
}
|
|
1456
|
+
function ar(e, t) {
|
|
1457
|
+
const n = /* @__PURE__ */ new Set(), r = e._nodes.filter(st);
|
|
1458
|
+
for (const i of r)
|
|
1459
|
+
e: for (const o of [i].concat(Pe(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 dn(Array.from(n), new Set(e._nodes), e.historyValue);
|
|
1468
|
+
}
|
|
1469
|
+
function cr(e, t) {
|
|
1470
|
+
const n = Ee(Oe(e, t));
|
|
1471
|
+
return an(e, [...n]);
|
|
1472
|
+
}
|
|
1473
|
+
function ur(e) {
|
|
1474
|
+
return !!e && typeof e == "object" && "machine" in e && "value" in e;
|
|
1475
|
+
}
|
|
1476
|
+
const dr = function(t) {
|
|
1477
|
+
return en(t, this.value);
|
|
1478
|
+
}, fr = function(t) {
|
|
1479
|
+
return this.tags.has(t);
|
|
1480
|
+
}, lr = 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
|
+
}, hr = 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
|
+
}, pr = function() {
|
|
1501
|
+
return this._nodes.reduce((t, n) => (n.meta !== void 0 && (t[n.id] = n.meta), t), {});
|
|
1502
|
+
};
|
|
1503
|
+
function Me(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: an(t.root, e._nodes),
|
|
1512
|
+
tags: new Set(e._nodes.flatMap((n) => n.tags)),
|
|
1513
|
+
children: e.children,
|
|
1514
|
+
historyValue: e.historyValue || {},
|
|
1515
|
+
matches: dr,
|
|
1516
|
+
hasTag: fr,
|
|
1517
|
+
can: lr,
|
|
1518
|
+
getMeta: pr,
|
|
1519
|
+
toJSON: hr
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
function V(e, t = {}) {
|
|
1523
|
+
return Me({
|
|
1524
|
+
...e,
|
|
1525
|
+
...t
|
|
1526
|
+
}, e.machine);
|
|
1527
|
+
}
|
|
1528
|
+
function vr(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 mr(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: pn(s),
|
|
1566
|
+
children: p,
|
|
1567
|
+
historyValue: vr(d.historyValue)
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
function pn(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: tt,
|
|
1580
|
+
id: r.id
|
|
1581
|
+
};
|
|
1582
|
+
else {
|
|
1583
|
+
const i = pn(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 gr(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 yr(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 ct(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 = gr, n.execute = yr, n;
|
|
1635
|
+
}
|
|
1636
|
+
const St = /* @__PURE__ */ new WeakMap();
|
|
1637
|
+
function Sr(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
|
+
St.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 = St.get(i.self);
|
|
1664
|
+
return r.type === ke ? (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 _t = "xstate.promise.resolve", bt = "xstate.promise.reject", De = /* @__PURE__ */ new WeakMap();
|
|
1681
|
+
function vn(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 _t: {
|
|
1689
|
+
const o = r.data;
|
|
1690
|
+
return {
|
|
1691
|
+
...n,
|
|
1692
|
+
status: "done",
|
|
1693
|
+
output: o,
|
|
1694
|
+
input: void 0
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
case bt:
|
|
1698
|
+
return {
|
|
1699
|
+
...n,
|
|
1700
|
+
status: "error",
|
|
1701
|
+
error: r.data,
|
|
1702
|
+
input: void 0
|
|
1703
|
+
};
|
|
1704
|
+
case ke:
|
|
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: _t,
|
|
1731
|
+
data: c
|
|
1732
|
+
}));
|
|
1733
|
+
}, (c) => {
|
|
1734
|
+
r.getSnapshot().status === "active" && (De.delete(r), i._relay(r, r, {
|
|
1735
|
+
type: bt,
|
|
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 _r(e, {
|
|
1751
|
+
machine: t,
|
|
1752
|
+
context: n
|
|
1753
|
+
}, r, i) {
|
|
1754
|
+
const o = (s, a) => {
|
|
1755
|
+
if (typeof s == "string") {
|
|
1756
|
+
const c = et(t, s);
|
|
1757
|
+
if (!c)
|
|
1758
|
+
throw new Error(`Actor logic '${s}' not implemented in machine '${t.id}'`);
|
|
1759
|
+
const u = Ae(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 Ae(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 br(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: _r(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 [V(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 O(e) {
|
|
1819
|
+
function t(n, r) {
|
|
1820
|
+
}
|
|
1821
|
+
return t.type = "xstate.assign", t.assignment = e, t.resolve = br, t;
|
|
1822
|
+
}
|
|
1823
|
+
const Tt = /* @__PURE__ */ new WeakMap();
|
|
1824
|
+
function Y(e, t, n) {
|
|
1825
|
+
let r = Tt.get(e);
|
|
1826
|
+
return r ? t in r || (r[t] = n()) : (r = {
|
|
1827
|
+
[t]: n()
|
|
1828
|
+
}, Tt.set(e, r)), r[t];
|
|
1829
|
+
}
|
|
1830
|
+
const Tr = {}, ne = (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 Ne {
|
|
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(Yt), 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 ? ht(this.config.states, (r, i) => new Ne(r, {
|
|
1840
|
+
_parent: this,
|
|
1841
|
+
_key: i,
|
|
1842
|
+
_machine: this.machine
|
|
1843
|
+
})) : Tr, 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 = q(this.config.entry).slice(), this.exit = q(this.config.exit).slice(), this.meta = this.config.meta, this.output = this.type === "final" || !this.parent ? this.config.output : void 0, this.tags = q(t.tags).slice();
|
|
1846
|
+
}
|
|
1847
|
+
/** @internal */
|
|
1848
|
+
_initialize() {
|
|
1849
|
+
this.transitions = Kn(this), this.config.always && (this.always = Z(this.config.always).map((t) => W(this, Zt, 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(ne),
|
|
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(ne),
|
|
1870
|
+
eventType: null
|
|
1871
|
+
})
|
|
1872
|
+
} : void 0,
|
|
1873
|
+
history: this.history,
|
|
1874
|
+
states: ht(this.states, (t) => t.definition),
|
|
1875
|
+
on: this.on,
|
|
1876
|
+
transitions: [...this.transitions.values()].flat().map((t) => ({
|
|
1877
|
+
...t,
|
|
1878
|
+
actions: t.actions.map(ne)
|
|
1879
|
+
})),
|
|
1880
|
+
entry: this.entry.map(ne),
|
|
1881
|
+
exit: this.exit.map(ne),
|
|
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 Y(this, "invoke", () => q(this.config.invoke).map((t, n) => {
|
|
1897
|
+
const {
|
|
1898
|
+
src: r,
|
|
1899
|
+
systemId: i
|
|
1900
|
+
} = t, o = t.id ?? pt(this.id, n), s = typeof r == "string" ? r : `xstate.invoke.${pt(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 Y(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 Y(this, "delayedTransitions", () => Vn(this));
|
|
1928
|
+
}
|
|
1929
|
+
get initial() {
|
|
1930
|
+
return Y(this, "initial", () => zn(this, this.config.initial));
|
|
1931
|
+
}
|
|
1932
|
+
/** @internal */
|
|
1933
|
+
next(t, n) {
|
|
1934
|
+
const r = n.type, i = [];
|
|
1935
|
+
let o;
|
|
1936
|
+
const s = Y(this, `candidates-${r}`, () => Bn(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 Y(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 Ir = "#";
|
|
1983
|
+
class ut {
|
|
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 Ne(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 ut(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 = cr(this.root, t.value), r = Ee(Oe(this.root, n));
|
|
2030
|
+
return Me({
|
|
2031
|
+
_nodes: [...r],
|
|
2032
|
+
context: t.context || {},
|
|
2033
|
+
children: {},
|
|
2034
|
+
status: it(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 Ke(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 Ke(t, n, r, []).microstates;
|
|
2059
|
+
}
|
|
2060
|
+
getTransitionData(t, n) {
|
|
2061
|
+
return ot(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 = Me({
|
|
2071
|
+
context: typeof i != "function" && i ? i : {},
|
|
2072
|
+
_nodes: [this.root],
|
|
2073
|
+
children: {},
|
|
2074
|
+
status: "active"
|
|
2075
|
+
}, this);
|
|
2076
|
+
return typeof i == "function" ? ee(o, n, t, [O(({
|
|
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 = $t(n), i = [], o = this.getPreInitialState(t, r, i), s = Xe([{
|
|
2092
|
+
target: [...un(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
|
+
} = Ke(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 = $e(t), r = n.slice(1), i = je(n[0]) ? n[0].slice(Ir.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 Fe(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 mr(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, v = d.src, y = typeof v == "string" ? et(this, v) : v;
|
|
2128
|
+
if (!y)
|
|
2129
|
+
return;
|
|
2130
|
+
const I = Ae(y, {
|
|
2131
|
+
id: l,
|
|
2132
|
+
parent: n.self,
|
|
2133
|
+
syncSnapshot: d.syncSnapshot,
|
|
2134
|
+
snapshot: p,
|
|
2135
|
+
src: v,
|
|
2136
|
+
systemId: d.systemId
|
|
2137
|
+
});
|
|
2138
|
+
r[l] = I;
|
|
2139
|
+
});
|
|
2140
|
+
function o(l, d) {
|
|
2141
|
+
if (d instanceof Ne)
|
|
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 v in d) {
|
|
2153
|
+
const y = d[v];
|
|
2154
|
+
for (const I of y) {
|
|
2155
|
+
const N = o(l, I);
|
|
2156
|
+
N && (p[v] ??= [], p[v].push(N));
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
return p;
|
|
2160
|
+
}
|
|
2161
|
+
const a = s(this.root, t.historyValue), c = Me({
|
|
2162
|
+
...t,
|
|
2163
|
+
children: r,
|
|
2164
|
+
_nodes: Array.from(Ee(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 v = l[p];
|
|
2172
|
+
if (v && typeof v == "object") {
|
|
2173
|
+
if ("xstate$$type" in v && v.xstate$$type === tt) {
|
|
2174
|
+
l[p] = d[v.id];
|
|
2175
|
+
continue;
|
|
2176
|
+
}
|
|
2177
|
+
f(v, d);
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
return f(c.context, r), c;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
function wr(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 kr(e, {
|
|
2194
|
+
event: t
|
|
2195
|
+
}) {
|
|
2196
|
+
e.defer(() => e.emit(t));
|
|
2197
|
+
}
|
|
2198
|
+
function mn(e) {
|
|
2199
|
+
function t(n, r) {
|
|
2200
|
+
}
|
|
2201
|
+
return t.type = "xstate.emit", t.event = e, t.resolve = wr, t.execute = kr, t;
|
|
2202
|
+
}
|
|
2203
|
+
let Qe = /* @__PURE__ */ (function(e) {
|
|
2204
|
+
return e.Parent = "#_parent", e.Internal = "#_internal", e;
|
|
2205
|
+
})({});
|
|
2206
|
+
function Pr(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 v = u && u[a];
|
|
2222
|
+
l = typeof v == "function" ? v(n, r) : v;
|
|
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 === Qe.Parent ? p = e.self._parent : d === Qe.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 Dr(e, t, n) {
|
|
2241
|
+
typeof n.to == "string" && (n.to = t.children[n.to]);
|
|
2242
|
+
}
|
|
2243
|
+
function Mr(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 === Mn ? Qt(e.self.id, r.data) : r
|
|
2261
|
+
);
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
function Ge(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 = Pr, r.retryResolve = Dr, r.execute = Mr, r;
|
|
2268
|
+
}
|
|
2269
|
+
function Ar(e, t) {
|
|
2270
|
+
return Ge(Qe.Parent, e, t);
|
|
2271
|
+
}
|
|
2272
|
+
function Er(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(O(...a));
|
|
2280
|
+
}, s.cancel = (...a) => {
|
|
2281
|
+
o.push(nt(...a));
|
|
2282
|
+
}, s.raise = (...a) => {
|
|
2283
|
+
o.push(ct(...a));
|
|
2284
|
+
}, s.sendTo = (...a) => {
|
|
2285
|
+
o.push(Ge(...a));
|
|
2286
|
+
}, s.sendParent = (...a) => {
|
|
2287
|
+
o.push(Ar(...a));
|
|
2288
|
+
}, s.spawnChild = (...a) => {
|
|
2289
|
+
o.push(rt(...a));
|
|
2290
|
+
}, s.stopChild = (...a) => {
|
|
2291
|
+
o.push(Ce(...a));
|
|
2292
|
+
}, s.emit = (...a) => {
|
|
2293
|
+
o.push(mn(...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 Fr(e) {
|
|
2304
|
+
function t(n, r) {
|
|
2305
|
+
}
|
|
2306
|
+
return t.type = "xstate.enqueueActions", t.collect = e, t.resolve = Er, t;
|
|
2307
|
+
}
|
|
2308
|
+
function Or(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 Nr({
|
|
2318
|
+
logger: e
|
|
2319
|
+
}, {
|
|
2320
|
+
value: t,
|
|
2321
|
+
label: n
|
|
2322
|
+
}) {
|
|
2323
|
+
n ? e(n, t) : e(t);
|
|
2324
|
+
}
|
|
2325
|
+
function Cr(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 = Or, n.execute = Nr, n;
|
|
2335
|
+
}
|
|
2336
|
+
function Rr(e, t) {
|
|
2337
|
+
return new ut(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: O,
|
|
2348
|
+
sendTo: Ge,
|
|
2349
|
+
raise: ct,
|
|
2350
|
+
log: Cr,
|
|
2351
|
+
cancel: nt,
|
|
2352
|
+
stopChild: Ce,
|
|
2353
|
+
enqueueActions: Fr,
|
|
2354
|
+
emit: mn,
|
|
2355
|
+
spawnChild: rt,
|
|
2356
|
+
createStateConfig: (o) => o,
|
|
2357
|
+
createAction: (o) => o,
|
|
2358
|
+
createMachine: (o) => Rr({
|
|
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
|
+
var F = {}, re = {}, T = {}, It;
|
|
2386
|
+
function k() {
|
|
2387
|
+
if (It) return T;
|
|
2388
|
+
It = 1, Object.defineProperty(T, "__esModule", { value: !0 });
|
|
2389
|
+
var e = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
|
|
2390
|
+
function t(h) {
|
|
2391
|
+
var m = h >> 4 & 15, g = h >> 0 & 15;
|
|
2392
|
+
return e[m] + e[g];
|
|
2393
|
+
}
|
|
2394
|
+
T.toHexString = t;
|
|
2395
|
+
function n(h, m, g) {
|
|
2396
|
+
for (var S = typeof h == "string" ? h : h.toFixed(0); S.length < m; )
|
|
2397
|
+
S = g + S;
|
|
2398
|
+
return S;
|
|
2399
|
+
}
|
|
2400
|
+
T.padLeft = n;
|
|
2401
|
+
function r(h) {
|
|
2402
|
+
var m = h.split("*"), g = m[0], S = m[1], D = i(g), E = parseInt(S, 16);
|
|
2403
|
+
return D === E;
|
|
2404
|
+
}
|
|
2405
|
+
T.validNmeaChecksum = r;
|
|
2406
|
+
function i(h) {
|
|
2407
|
+
for (var m = h.charCodeAt(1), g = 2; g < h.length; g += 1)
|
|
2408
|
+
m = m ^ h.charCodeAt(g);
|
|
2409
|
+
return m = m & 255, m;
|
|
2410
|
+
}
|
|
2411
|
+
T.computeNmeaChecksum = i;
|
|
2412
|
+
function o(h) {
|
|
2413
|
+
return "*" + t(i(h));
|
|
2414
|
+
}
|
|
2415
|
+
T.createNmeaChecksumFooter = o;
|
|
2416
|
+
function s(h) {
|
|
2417
|
+
return h + o(h);
|
|
2418
|
+
}
|
|
2419
|
+
T.appendChecksumFooter = s;
|
|
2420
|
+
function a(h, m) {
|
|
2421
|
+
return h === void 0 ? "" : h.toFixed(m);
|
|
2422
|
+
}
|
|
2423
|
+
T.encodeFixed = a;
|
|
2424
|
+
function c(h) {
|
|
2425
|
+
if (h === void 0)
|
|
2426
|
+
return ",";
|
|
2427
|
+
var m;
|
|
2428
|
+
h < 0 ? (m = "S", h = -h) : m = "N";
|
|
2429
|
+
var g = Math.floor(h), S = n(g, 2, "0"), D = h - g, E = D * 60, R = n(E.toFixed(6), 9, "0");
|
|
2430
|
+
return S = S + R + "," + m, S;
|
|
2431
|
+
}
|
|
2432
|
+
T.encodeLatitude = c;
|
|
2433
|
+
function u(h) {
|
|
2434
|
+
if (h === void 0)
|
|
2435
|
+
return ",";
|
|
2436
|
+
var m;
|
|
2437
|
+
h < 0 ? (m = "W", h = -h) : m = "E";
|
|
2438
|
+
var g = Math.floor(h), S = n(g, 3, "0"), D = h - g, E = D * 60, R = n(E.toFixed(6), 9, "0");
|
|
2439
|
+
return S = S + R + "," + m, S;
|
|
2440
|
+
}
|
|
2441
|
+
T.encodeLongitude = u;
|
|
2442
|
+
function f(h) {
|
|
2443
|
+
return h === void 0 ? "," : h.toFixed(1) + ",M";
|
|
2444
|
+
}
|
|
2445
|
+
T.encodeAltitude = f;
|
|
2446
|
+
function l(h) {
|
|
2447
|
+
return h === void 0 ? "" : h.toFixed(1);
|
|
2448
|
+
}
|
|
2449
|
+
T.encodeAltitudeNoUnits = l;
|
|
2450
|
+
function d(h) {
|
|
2451
|
+
return h === void 0 ? "," : h.toFixed(1) + ",M";
|
|
2452
|
+
}
|
|
2453
|
+
T.encodeGeoidalSeperation = d;
|
|
2454
|
+
function p(h) {
|
|
2455
|
+
return h === void 0 ? "" : h.toFixed(1);
|
|
2456
|
+
}
|
|
2457
|
+
T.encodeGeoidalSeperationNoUnits = p;
|
|
2458
|
+
function v(h) {
|
|
2459
|
+
return h === void 0 ? "" : n(h.toFixed(2), 6, "0");
|
|
2460
|
+
}
|
|
2461
|
+
T.encodeDegrees = v;
|
|
2462
|
+
function y(h) {
|
|
2463
|
+
if (h === void 0)
|
|
2464
|
+
return "";
|
|
2465
|
+
var m = h.getUTCFullYear(), g = h.getUTCMonth() + 1, S = h.getUTCDate();
|
|
2466
|
+
return n(S, 2, "0") + n(g, 2, "0") + m.toFixed(0).substr(2);
|
|
2467
|
+
}
|
|
2468
|
+
T.encodeDate = y;
|
|
2469
|
+
function I(h) {
|
|
2470
|
+
if (h === void 0)
|
|
2471
|
+
return "";
|
|
2472
|
+
var m = h.getUTCHours(), g = h.getUTCMinutes(), S = h.getUTCSeconds();
|
|
2473
|
+
return n(m, 2, "0") + n(g, 2, "0") + n(S, 2, "0");
|
|
2474
|
+
}
|
|
2475
|
+
T.encodeTime = I;
|
|
2476
|
+
function N(h) {
|
|
2477
|
+
return h === void 0 ? "" : h.toString();
|
|
2478
|
+
}
|
|
2479
|
+
T.encodeValue = N;
|
|
2480
|
+
function C(h) {
|
|
2481
|
+
return h === "" ? 0 : parseFloat(h);
|
|
2482
|
+
}
|
|
2483
|
+
T.parseFloatSafe = C;
|
|
2484
|
+
function K(h) {
|
|
2485
|
+
return h === "" ? 0 : parseInt(h, 10);
|
|
2486
|
+
}
|
|
2487
|
+
T.parseIntSafe = K;
|
|
2488
|
+
function xe(h) {
|
|
2489
|
+
if (h === void 0)
|
|
2490
|
+
return "";
|
|
2491
|
+
var m = parseFloat(h);
|
|
2492
|
+
return m === NaN ? h : m;
|
|
2493
|
+
}
|
|
2494
|
+
T.parseNumberOrString = xe;
|
|
2495
|
+
function te(h) {
|
|
2496
|
+
var m = h.indexOf(".");
|
|
2497
|
+
if (m < 0)
|
|
2498
|
+
return 0;
|
|
2499
|
+
var g, S;
|
|
2500
|
+
return m >= 3 ? (g = h.substring(0, m - 2), S = h.substring(m - 2)) : (g = "0", S = h), parseFloat(g) + parseFloat(S) / 60;
|
|
2501
|
+
}
|
|
2502
|
+
T.parseDmCoordinate = te;
|
|
2503
|
+
function qe(h, m) {
|
|
2504
|
+
var g = m === "N" ? 1 : -1;
|
|
2505
|
+
return te(h) * g;
|
|
2506
|
+
}
|
|
2507
|
+
T.parseLatitude = qe;
|
|
2508
|
+
function Ue(h, m) {
|
|
2509
|
+
var g = m === "E" ? 1 : -1;
|
|
2510
|
+
return te(h) * g;
|
|
2511
|
+
}
|
|
2512
|
+
T.parseLongitude = Ue;
|
|
2513
|
+
function He(h, m) {
|
|
2514
|
+
if (h === "")
|
|
2515
|
+
return /* @__PURE__ */ new Date(0);
|
|
2516
|
+
var g = /* @__PURE__ */ new Date();
|
|
2517
|
+
if (m) {
|
|
2518
|
+
var S = m.slice(4), D = parseInt(m.slice(2, 4), 10) - 1, E = m.slice(0, 2);
|
|
2519
|
+
S.length === 4 ? g.setUTCFullYear(Number(S), Number(D), Number(E)) : g.setUTCFullYear(+("20" + S), Number(D), Number(E));
|
|
2520
|
+
}
|
|
2521
|
+
g.setUTCHours(Number(h.slice(0, 2))), g.setUTCMinutes(Number(h.slice(2, 4))), g.setUTCSeconds(Number(h.slice(4, 6)));
|
|
2522
|
+
var R = h.slice(7), z = R.length, H = 0;
|
|
2523
|
+
return z !== 0 && (H = parseFloat(R) * Math.pow(10, 3 - z)), g.setUTCMilliseconds(Number(H)), g;
|
|
2524
|
+
}
|
|
2525
|
+
T.parseTime = He;
|
|
2526
|
+
function We(h, m) {
|
|
2527
|
+
var g = parseInt(h.slice(0, 2), 10), S = parseInt(h.slice(2, 4), 10), D = parseInt(h.slice(4, 6), 10);
|
|
2528
|
+
D < 73 ? D = D + 2e3 : D = D + 1900;
|
|
2529
|
+
var E = parseInt(m.slice(0, 2), 10), R = parseInt(m.slice(2, 4), 10), z = parseInt(m.slice(4, 6), 10), H = 0;
|
|
2530
|
+
return m.length === 9 && (H = parseInt(m.slice(7, 9), 10) * 10), new Date(Date.UTC(D, S - 1, g, E, R, z, H));
|
|
2531
|
+
}
|
|
2532
|
+
return T.parseDatetime = We, T;
|
|
2533
|
+
}
|
|
2534
|
+
var se = {}, wt;
|
|
2535
|
+
function w() {
|
|
2536
|
+
if (wt) return se;
|
|
2537
|
+
wt = 1, Object.defineProperty(se, "__esModule", { value: !0 });
|
|
2538
|
+
function e(n, r, i) {
|
|
2539
|
+
return {
|
|
2540
|
+
sentenceId: r,
|
|
2541
|
+
talkerId: n.talkerId,
|
|
2542
|
+
chxOk: n.chxOk,
|
|
2543
|
+
sentenceName: i
|
|
2544
|
+
};
|
|
2545
|
+
}
|
|
2546
|
+
se.initStubFields = e;
|
|
2547
|
+
function t(n, r) {
|
|
2548
|
+
var i, o;
|
|
2549
|
+
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 };
|
|
2550
|
+
}
|
|
2551
|
+
return se.parseStub = t, se;
|
|
2552
|
+
}
|
|
2553
|
+
var kt;
|
|
2554
|
+
function jr() {
|
|
2555
|
+
return kt || (kt = 1, (function(e) {
|
|
2556
|
+
var t = re && re.__assign || function() {
|
|
2557
|
+
return t = Object.assign || function(o) {
|
|
2558
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
2559
|
+
s = arguments[a];
|
|
2560
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
2561
|
+
}
|
|
2562
|
+
return o;
|
|
2563
|
+
}, t.apply(this, arguments);
|
|
2564
|
+
};
|
|
2565
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2566
|
+
var n = k(), r = w();
|
|
2567
|
+
e.sentenceId = "APB", e.sentenceName = 'Autopilot sentence "B"';
|
|
2568
|
+
function i(o, s) {
|
|
2569
|
+
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] });
|
|
2570
|
+
}
|
|
2571
|
+
e.decodeSentence = i;
|
|
2572
|
+
})(re)), re;
|
|
2573
|
+
}
|
|
2574
|
+
var ie = {}, Pt;
|
|
2575
|
+
function Gr() {
|
|
2576
|
+
return Pt || (Pt = 1, (function(e) {
|
|
2577
|
+
var t = ie && ie.__assign || function() {
|
|
2578
|
+
return t = Object.assign || function(o) {
|
|
2579
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
2580
|
+
s = arguments[a];
|
|
2581
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
2582
|
+
}
|
|
2583
|
+
return o;
|
|
2584
|
+
}, t.apply(this, arguments);
|
|
2585
|
+
};
|
|
2586
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2587
|
+
var n = k(), r = w();
|
|
2588
|
+
e.sentenceId = "BWC", e.sentenceName = "Bearing and distance to waypoint - great circle";
|
|
2589
|
+
function i(o, s) {
|
|
2590
|
+
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] });
|
|
2591
|
+
}
|
|
2592
|
+
e.decodeSentence = i;
|
|
2593
|
+
})(ie)), ie;
|
|
2594
|
+
}
|
|
2595
|
+
var oe = {}, Dt;
|
|
2596
|
+
function Lr() {
|
|
2597
|
+
return Dt || (Dt = 1, (function(e) {
|
|
2598
|
+
var t = oe && oe.__assign || function() {
|
|
2599
|
+
return t = Object.assign || function(s) {
|
|
2600
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
2601
|
+
a = arguments[c];
|
|
2602
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
2603
|
+
}
|
|
2604
|
+
return s;
|
|
2605
|
+
}, t.apply(this, arguments);
|
|
2606
|
+
};
|
|
2607
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2608
|
+
var n = k(), r = w();
|
|
2609
|
+
e.sentenceId = "DBT", e.sentenceName = "Depth below transducer";
|
|
2610
|
+
function i(s, a) {
|
|
2611
|
+
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]) });
|
|
2612
|
+
}
|
|
2613
|
+
e.decodeSentence = i;
|
|
2614
|
+
function o(s, a) {
|
|
2615
|
+
var c = ["$" + a + e.sentenceId];
|
|
2616
|
+
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");
|
|
2617
|
+
var u = c.join(",");
|
|
2618
|
+
return u + n.createNmeaChecksumFooter(u);
|
|
2619
|
+
}
|
|
2620
|
+
e.encodePacket = o;
|
|
2621
|
+
})(oe)), oe;
|
|
2622
|
+
}
|
|
2623
|
+
var ae = {}, Mt;
|
|
2624
|
+
function xr() {
|
|
2625
|
+
return Mt || (Mt = 1, (function(e) {
|
|
2626
|
+
var t = ae && ae.__assign || function() {
|
|
2627
|
+
return t = Object.assign || function(s) {
|
|
2628
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
2629
|
+
a = arguments[c];
|
|
2630
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
2631
|
+
}
|
|
2632
|
+
return s;
|
|
2633
|
+
}, t.apply(this, arguments);
|
|
2634
|
+
};
|
|
2635
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2636
|
+
var n = k(), r = w();
|
|
2637
|
+
e.sentenceId = "DTM", e.sentenceName = "Datum reference";
|
|
2638
|
+
function i(s, a) {
|
|
2639
|
+
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]) });
|
|
2640
|
+
}
|
|
2641
|
+
e.decodeSentence = i;
|
|
2642
|
+
function o(s) {
|
|
2643
|
+
return s === "W84" ? "W84" : s === "W72" ? "W72" : s === "S85" ? "S85" : s === "P90" ? "P90" : s === "999" ? "999" : "";
|
|
2644
|
+
}
|
|
2645
|
+
})(ae)), ae;
|
|
2646
|
+
}
|
|
2647
|
+
var ce = {}, At;
|
|
2648
|
+
function qr() {
|
|
2649
|
+
return At || (At = 1, (function(e) {
|
|
2650
|
+
var t = ce && ce.__assign || function() {
|
|
2651
|
+
return t = Object.assign || function(a) {
|
|
2652
|
+
for (var c, u = 1, f = arguments.length; u < f; u++) {
|
|
2653
|
+
c = arguments[u];
|
|
2654
|
+
for (var l in c) Object.prototype.hasOwnProperty.call(c, l) && (a[l] = c[l]);
|
|
2655
|
+
}
|
|
2656
|
+
return a;
|
|
2657
|
+
}, t.apply(this, arguments);
|
|
2658
|
+
};
|
|
2659
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2660
|
+
var n = k(), r = w();
|
|
2661
|
+
e.sentenceId = "GGA", e.sentenceName = "Global positioning system fix data";
|
|
2662
|
+
var i = ["none", "fix", "delta", "pps", "rtk", "frtk", "estimated", "manual", "simulation"];
|
|
2663
|
+
function o(a, c) {
|
|
2664
|
+
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] });
|
|
2665
|
+
}
|
|
2666
|
+
e.decodeSentence = o;
|
|
2667
|
+
function s(a, c) {
|
|
2668
|
+
var u = ["$" + c + e.sentenceId];
|
|
2669
|
+
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));
|
|
2670
|
+
var f = u.join(",");
|
|
2671
|
+
return f + n.createNmeaChecksumFooter(f);
|
|
2672
|
+
}
|
|
2673
|
+
e.encodePacket = s;
|
|
2674
|
+
})(ce)), ce;
|
|
2675
|
+
}
|
|
2676
|
+
var ue = {}, Et;
|
|
2677
|
+
function Ur() {
|
|
2678
|
+
return Et || (Et = 1, (function(e) {
|
|
2679
|
+
var t = ue && ue.__assign || function() {
|
|
2680
|
+
return t = Object.assign || function(s) {
|
|
2681
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
2682
|
+
a = arguments[c];
|
|
2683
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
2684
|
+
}
|
|
2685
|
+
return s;
|
|
2686
|
+
}, t.apply(this, arguments);
|
|
2687
|
+
};
|
|
2688
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2689
|
+
var n = k(), r = w();
|
|
2690
|
+
e.sentenceId = "GLL", e.sentenceName = "Geographic position - latitude and longitude";
|
|
2691
|
+
function i(s, a) {
|
|
2692
|
+
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] });
|
|
2693
|
+
}
|
|
2694
|
+
e.decodeSentence = i;
|
|
2695
|
+
function o(s, a) {
|
|
2696
|
+
var c = ["$" + a + e.sentenceId];
|
|
2697
|
+
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);
|
|
2698
|
+
var u = c.join(",");
|
|
2699
|
+
return u + n.createNmeaChecksumFooter(u);
|
|
2700
|
+
}
|
|
2701
|
+
e.encodePacket = o;
|
|
2702
|
+
})(ue)), ue;
|
|
2703
|
+
}
|
|
2704
|
+
var de = {}, Ft;
|
|
2705
|
+
function Hr() {
|
|
2706
|
+
return Ft || (Ft = 1, (function(e) {
|
|
2707
|
+
var t = de && de.__assign || function() {
|
|
2708
|
+
return t = Object.assign || function(s) {
|
|
2709
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
2710
|
+
a = arguments[c];
|
|
2711
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
2712
|
+
}
|
|
2713
|
+
return s;
|
|
2714
|
+
}, t.apply(this, arguments);
|
|
2715
|
+
};
|
|
2716
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2717
|
+
var n = k(), r = w();
|
|
2718
|
+
e.sentenceId = "GNS", e.sentenceName = "GNSS fix data";
|
|
2719
|
+
function i(s, a) {
|
|
2720
|
+
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] });
|
|
2721
|
+
}
|
|
2722
|
+
e.decodeSentence = i;
|
|
2723
|
+
function o(s, a) {
|
|
2724
|
+
var c = ["$" + a + e.sentenceId];
|
|
2725
|
+
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));
|
|
2726
|
+
var u = c.join(",");
|
|
2727
|
+
return u + n.createNmeaChecksumFooter(u);
|
|
2728
|
+
}
|
|
2729
|
+
e.encodePacket = o;
|
|
2730
|
+
})(de)), de;
|
|
2731
|
+
}
|
|
2732
|
+
var fe = {}, Ot;
|
|
2733
|
+
function Wr() {
|
|
2734
|
+
return Ot || (Ot = 1, (function(e) {
|
|
2735
|
+
var t = fe && fe.__assign || function() {
|
|
2736
|
+
return t = Object.assign || function(s) {
|
|
2737
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
2738
|
+
a = arguments[c];
|
|
2739
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
2740
|
+
}
|
|
2741
|
+
return s;
|
|
2742
|
+
}, t.apply(this, arguments);
|
|
2743
|
+
};
|
|
2744
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2745
|
+
var n = k(), r = w();
|
|
2746
|
+
e.sentenceId = "GSA", e.sentenceName = "Active satellites and dilution of precision";
|
|
2747
|
+
var i = ["unknown", "none", "2D", "3D"];
|
|
2748
|
+
function o(s, a) {
|
|
2749
|
+
for (var c = [], u = 3; u < 15; u++)
|
|
2750
|
+
a[u] && c.push(+a[u]);
|
|
2751
|
+
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]) });
|
|
2752
|
+
}
|
|
2753
|
+
e.decodeSentence = o;
|
|
2754
|
+
})(fe)), fe;
|
|
2755
|
+
}
|
|
2756
|
+
var le = {}, Nt;
|
|
2757
|
+
function Br() {
|
|
2758
|
+
return Nt || (Nt = 1, (function(e) {
|
|
2759
|
+
var t = le && le.__assign || function() {
|
|
2760
|
+
return t = Object.assign || function(o) {
|
|
2761
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
2762
|
+
s = arguments[a];
|
|
2763
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
2764
|
+
}
|
|
2765
|
+
return o;
|
|
2766
|
+
}, t.apply(this, arguments);
|
|
2767
|
+
};
|
|
2768
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2769
|
+
var n = k(), r = w();
|
|
2770
|
+
e.sentenceId = "GST", e.sentenceName = "GPS pseudorange noise statistics";
|
|
2771
|
+
function i(o, s) {
|
|
2772
|
+
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]) });
|
|
2773
|
+
}
|
|
2774
|
+
e.decodeSentence = i;
|
|
2775
|
+
})(le)), le;
|
|
2776
|
+
}
|
|
2777
|
+
var he = {}, Ct;
|
|
2778
|
+
function Vr() {
|
|
2779
|
+
return Ct || (Ct = 1, (function(e) {
|
|
2780
|
+
var t = he && he.__assign || function() {
|
|
2781
|
+
return t = Object.assign || function(o) {
|
|
2782
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
2783
|
+
s = arguments[a];
|
|
2784
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
2785
|
+
}
|
|
2786
|
+
return o;
|
|
2787
|
+
}, t.apply(this, arguments);
|
|
2788
|
+
};
|
|
2789
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2790
|
+
var n = k(), r = w();
|
|
2791
|
+
e.sentenceId = "GSV", e.sentenceName = "Satellites in view";
|
|
2792
|
+
function i(o, s) {
|
|
2793
|
+
for (var a = (s.length - 4) / 4, c = [], u = 0; u < a; u++) {
|
|
2794
|
+
var f = u * 4 + 4;
|
|
2795
|
+
c.push({
|
|
2796
|
+
prnNumber: n.parseIntSafe(s[f]),
|
|
2797
|
+
elevationDegrees: n.parseIntSafe(s[f + 1]),
|
|
2798
|
+
azimuthTrue: n.parseIntSafe(s[f + 2]),
|
|
2799
|
+
SNRdB: n.parseIntSafe(s[f + 3])
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2802
|
+
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 });
|
|
2803
|
+
}
|
|
2804
|
+
e.decodeSentence = i;
|
|
2805
|
+
})(he)), he;
|
|
2806
|
+
}
|
|
2807
|
+
var pe = {}, Rt;
|
|
2808
|
+
function Kr() {
|
|
2809
|
+
return Rt || (Rt = 1, (function(e) {
|
|
2810
|
+
var t = pe && pe.__assign || function() {
|
|
2811
|
+
return t = Object.assign || function(o) {
|
|
2812
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
2813
|
+
s = arguments[a];
|
|
2814
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
2815
|
+
}
|
|
2816
|
+
return o;
|
|
2817
|
+
}, t.apply(this, arguments);
|
|
2818
|
+
};
|
|
2819
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2820
|
+
var n = k(), r = w();
|
|
2821
|
+
e.sentenceId = "HDG", e.sentenceName = "Heading - deviation and variation";
|
|
2822
|
+
function i(o, s) {
|
|
2823
|
+
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" : "" });
|
|
2824
|
+
}
|
|
2825
|
+
e.decodeSentence = i;
|
|
2826
|
+
})(pe)), pe;
|
|
2827
|
+
}
|
|
2828
|
+
var ve = {}, jt;
|
|
2829
|
+
function zr() {
|
|
2830
|
+
return jt || (jt = 1, (function(e) {
|
|
2831
|
+
var t = ve && ve.__assign || function() {
|
|
2832
|
+
return t = Object.assign || function(s) {
|
|
2833
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
2834
|
+
a = arguments[c];
|
|
2835
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
2836
|
+
}
|
|
2837
|
+
return s;
|
|
2838
|
+
}, t.apply(this, arguments);
|
|
2839
|
+
};
|
|
2840
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2841
|
+
var n = k(), r = w();
|
|
2842
|
+
e.sentenceId = "HDM", e.sentenceName = "Heading - magnetic";
|
|
2843
|
+
function i(s, a) {
|
|
2844
|
+
return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { heading: n.parseFloatSafe(a[1]) });
|
|
2845
|
+
}
|
|
2846
|
+
e.decodeSentence = i;
|
|
2847
|
+
function o(s, a) {
|
|
2848
|
+
var c = ["$" + a + e.sentenceId];
|
|
2849
|
+
c.push(n.encodeFixed(s.heading, 1)), c.push("M");
|
|
2850
|
+
var u = c.join(",");
|
|
2851
|
+
return u + n.createNmeaChecksumFooter(u);
|
|
2852
|
+
}
|
|
2853
|
+
e.encodePacket = o;
|
|
2854
|
+
})(ve)), ve;
|
|
2855
|
+
}
|
|
2856
|
+
var me = {}, Gt;
|
|
2857
|
+
function Jr() {
|
|
2858
|
+
return Gt || (Gt = 1, (function(e) {
|
|
2859
|
+
var t = me && me.__assign || function() {
|
|
2860
|
+
return t = Object.assign || function(s) {
|
|
2861
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
2862
|
+
a = arguments[c];
|
|
2863
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
2864
|
+
}
|
|
2865
|
+
return s;
|
|
2866
|
+
}, t.apply(this, arguments);
|
|
2867
|
+
};
|
|
2868
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2869
|
+
var n = k(), r = w();
|
|
2870
|
+
e.sentenceId = "HDT", e.sentenceName = "Heading - true";
|
|
2871
|
+
function i(s, a) {
|
|
2872
|
+
return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { heading: n.parseFloatSafe(a[1]) });
|
|
2873
|
+
}
|
|
2874
|
+
e.decodeSentence = i;
|
|
2875
|
+
function o(s, a) {
|
|
2876
|
+
var c = ["$" + a + e.sentenceId];
|
|
2877
|
+
c.push(n.encodeFixed(s.heading, 1)), c.push("T");
|
|
2878
|
+
var u = c.join(",");
|
|
2879
|
+
return u + n.createNmeaChecksumFooter(u);
|
|
2880
|
+
}
|
|
2881
|
+
e.encodePacket = o;
|
|
2882
|
+
})(me)), me;
|
|
2883
|
+
}
|
|
2884
|
+
var ge = {}, Lt;
|
|
2885
|
+
function Yr() {
|
|
2886
|
+
return Lt || (Lt = 1, (function(e) {
|
|
2887
|
+
var t = ge && ge.__assign || function() {
|
|
2888
|
+
return t = Object.assign || function(s) {
|
|
2889
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
2890
|
+
a = arguments[c];
|
|
2891
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
2892
|
+
}
|
|
2893
|
+
return s;
|
|
2894
|
+
}, t.apply(this, arguments);
|
|
2895
|
+
};
|
|
2896
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2897
|
+
var n = k(), r = w();
|
|
2898
|
+
e.sentenceId = "MTK", e.sentenceName = "Configuration packet";
|
|
2899
|
+
function i(s, a) {
|
|
2900
|
+
return t(t({}, r.initStubFields(s, e.sentenceId, e.sentenceName)), { packetType: n.parseIntSafe(s.sentenceId.substr(3)), data: a.slice(1).map(n.parseNumberOrString) });
|
|
2901
|
+
}
|
|
2902
|
+
e.decodeSentence = i;
|
|
2903
|
+
function o(s, a) {
|
|
2904
|
+
var c = ["$" + a + e.sentenceId + n.padLeft(s.packetType, 3, "0")];
|
|
2905
|
+
c = c.concat(s.data.toString());
|
|
2906
|
+
var u = c.join(",");
|
|
2907
|
+
return u + n.createNmeaChecksumFooter(u);
|
|
2908
|
+
}
|
|
2909
|
+
e.encodePacket = o;
|
|
2910
|
+
})(ge)), ge;
|
|
2911
|
+
}
|
|
2912
|
+
var ye = {}, xt;
|
|
2913
|
+
function Zr() {
|
|
2914
|
+
return xt || (xt = 1, (function(e) {
|
|
2915
|
+
var t = ye && ye.__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 = k(), r = w();
|
|
2926
|
+
e.sentenceId = "MWV", e.sentenceName = "Wind speed and angle";
|
|
2927
|
+
function i(s, a) {
|
|
2928
|
+
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" });
|
|
2929
|
+
}
|
|
2930
|
+
e.decodeSentence = i;
|
|
2931
|
+
function o(s, a) {
|
|
2932
|
+
var c = ["$" + a + e.sentenceId];
|
|
2933
|
+
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");
|
|
2934
|
+
var u = c.join(",");
|
|
2935
|
+
return u + n.createNmeaChecksumFooter(u);
|
|
2936
|
+
}
|
|
2937
|
+
e.encodePacket = o;
|
|
2938
|
+
})(ye)), ye;
|
|
2939
|
+
}
|
|
2940
|
+
var Se = {}, qt;
|
|
2941
|
+
function Xr() {
|
|
2942
|
+
return qt || (qt = 1, (function(e) {
|
|
2943
|
+
var t = Se && Se.__assign || function() {
|
|
2944
|
+
return t = Object.assign || function(o) {
|
|
2945
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
2946
|
+
s = arguments[a];
|
|
2947
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
2948
|
+
}
|
|
2949
|
+
return o;
|
|
2950
|
+
}, t.apply(this, arguments);
|
|
2951
|
+
};
|
|
2952
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2953
|
+
var n = k(), r = w();
|
|
2954
|
+
e.sentenceId = "RDID", e.sentenceName = "RDI proprietary heading, pitch, and roll";
|
|
2955
|
+
function i(o, s) {
|
|
2956
|
+
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]) });
|
|
2957
|
+
}
|
|
2958
|
+
e.decodeSentence = i;
|
|
2959
|
+
})(Se)), Se;
|
|
2960
|
+
}
|
|
2961
|
+
var _e = {}, Ut;
|
|
2962
|
+
function Qr() {
|
|
2963
|
+
return Ut || (Ut = 1, (function(e) {
|
|
2964
|
+
var t = _e && _e.__assign || function() {
|
|
2965
|
+
return t = Object.assign || function(o) {
|
|
2966
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
2967
|
+
s = arguments[a];
|
|
2968
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
2969
|
+
}
|
|
2970
|
+
return o;
|
|
2971
|
+
}, t.apply(this, arguments);
|
|
2972
|
+
};
|
|
2973
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2974
|
+
var n = k(), r = w();
|
|
2975
|
+
e.sentenceId = "RMC", e.sentenceName = "Recommended minimum navigation information";
|
|
2976
|
+
function i(o, s) {
|
|
2977
|
+
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] });
|
|
2978
|
+
}
|
|
2979
|
+
e.decodeSentence = i;
|
|
2980
|
+
})(_e)), _e;
|
|
2981
|
+
}
|
|
2982
|
+
var be = {}, Ht;
|
|
2983
|
+
function $r() {
|
|
2984
|
+
return Ht || (Ht = 1, (function(e) {
|
|
2985
|
+
var t = be && be.__assign || function() {
|
|
2986
|
+
return t = Object.assign || function(o) {
|
|
2987
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
2988
|
+
s = arguments[a];
|
|
2989
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
2990
|
+
}
|
|
2991
|
+
return o;
|
|
2992
|
+
}, t.apply(this, arguments);
|
|
2993
|
+
};
|
|
2994
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
2995
|
+
var n = k(), r = w();
|
|
2996
|
+
e.sentenceId = "VHW", e.sentenceName = "Water speed and heading";
|
|
2997
|
+
function i(o, s) {
|
|
2998
|
+
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]) });
|
|
2999
|
+
}
|
|
3000
|
+
e.decodeSentence = i;
|
|
3001
|
+
})(be)), be;
|
|
3002
|
+
}
|
|
3003
|
+
var Te = {}, Wt;
|
|
3004
|
+
function es() {
|
|
3005
|
+
return Wt || (Wt = 1, (function(e) {
|
|
3006
|
+
var t = Te && Te.__assign || function() {
|
|
3007
|
+
return t = Object.assign || function(s) {
|
|
3008
|
+
for (var a, c = 1, u = arguments.length; c < u; c++) {
|
|
3009
|
+
a = arguments[c];
|
|
3010
|
+
for (var f in a) Object.prototype.hasOwnProperty.call(a, f) && (s[f] = a[f]);
|
|
3011
|
+
}
|
|
3012
|
+
return s;
|
|
3013
|
+
}, t.apply(this, arguments);
|
|
3014
|
+
};
|
|
3015
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
3016
|
+
var n = k(), r = w();
|
|
3017
|
+
e.sentenceId = "VTG", e.sentenceName = "Track made good and ground speed";
|
|
3018
|
+
function i(s, a) {
|
|
3019
|
+
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] });
|
|
3020
|
+
}
|
|
3021
|
+
e.decodeSentence = i;
|
|
3022
|
+
function o(s, a) {
|
|
3023
|
+
var c = ["$" + a + e.sentenceId];
|
|
3024
|
+
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);
|
|
3025
|
+
var u = c.join(",");
|
|
3026
|
+
return u + n.createNmeaChecksumFooter(u);
|
|
3027
|
+
}
|
|
3028
|
+
e.encodePacket = o;
|
|
3029
|
+
})(Te)), Te;
|
|
3030
|
+
}
|
|
3031
|
+
var Ie = {}, Bt;
|
|
3032
|
+
function ts() {
|
|
3033
|
+
return Bt || (Bt = 1, (function(e) {
|
|
3034
|
+
var t = Ie && Ie.__assign || function() {
|
|
3035
|
+
return t = Object.assign || function(o) {
|
|
3036
|
+
for (var s, a = 1, c = arguments.length; a < c; a++) {
|
|
3037
|
+
s = arguments[a];
|
|
3038
|
+
for (var u in s) Object.prototype.hasOwnProperty.call(s, u) && (o[u] = s[u]);
|
|
3039
|
+
}
|
|
3040
|
+
return o;
|
|
3041
|
+
}, t.apply(this, arguments);
|
|
3042
|
+
};
|
|
3043
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
3044
|
+
var n = k(), r = w();
|
|
3045
|
+
e.sentenceId = "ZDA", e.sentenceName = "UTC, day, month, year, and local time zone";
|
|
3046
|
+
function i(o, s) {
|
|
3047
|
+
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]) });
|
|
3048
|
+
}
|
|
3049
|
+
e.decodeSentence = i;
|
|
3050
|
+
})(Ie)), Ie;
|
|
3051
|
+
}
|
|
3052
|
+
var we = {}, Vt;
|
|
3053
|
+
function yn() {
|
|
3054
|
+
return Vt || (Vt = 1, (function(e) {
|
|
3055
|
+
var t = we && we.__assign || function() {
|
|
3056
|
+
return t = Object.assign || function(i) {
|
|
3057
|
+
for (var o, s = 1, a = arguments.length; s < a; s++) {
|
|
3058
|
+
o = arguments[s];
|
|
3059
|
+
for (var c in o) Object.prototype.hasOwnProperty.call(o, c) && (i[c] = o[c]);
|
|
3060
|
+
}
|
|
3061
|
+
return i;
|
|
3062
|
+
}, t.apply(this, arguments);
|
|
3063
|
+
};
|
|
3064
|
+
Object.defineProperty(e, "__esModule", { value: !0 });
|
|
3065
|
+
var n = w();
|
|
3066
|
+
e.sentenceId = "?";
|
|
3067
|
+
function r(i, o) {
|
|
3068
|
+
return t(t({}, n.initStubFields(i, e.sentenceId)), { originalPacketId: i.sentenceId, dataFields: o.slice(1) });
|
|
3069
|
+
}
|
|
3070
|
+
e.decodeSentence = r;
|
|
3071
|
+
})(we)), we;
|
|
3072
|
+
}
|
|
3073
|
+
var Kt;
|
|
3074
|
+
function ns() {
|
|
3075
|
+
if (Kt) return F;
|
|
3076
|
+
Kt = 1;
|
|
3077
|
+
var e = F && F.__extends || /* @__PURE__ */ (function() {
|
|
3078
|
+
var _ = function(b, P) {
|
|
3079
|
+
return _ = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(M, x) {
|
|
3080
|
+
M.__proto__ = x;
|
|
3081
|
+
} || function(M, x) {
|
|
3082
|
+
for (var J in x) x.hasOwnProperty(J) && (M[J] = x[J]);
|
|
3083
|
+
}, _(b, P);
|
|
3084
|
+
};
|
|
3085
|
+
return function(b, P) {
|
|
3086
|
+
_(b, P);
|
|
3087
|
+
function M() {
|
|
3088
|
+
this.constructor = b;
|
|
3089
|
+
}
|
|
3090
|
+
b.prototype = P === null ? Object.create(P) : (M.prototype = P.prototype, new M());
|
|
3091
|
+
};
|
|
3092
|
+
})();
|
|
3093
|
+
Object.defineProperty(F, "__esModule", { value: !0 });
|
|
3094
|
+
var t = jr(), n = Gr(), r = Lr(), i = xr(), o = qr(), s = Ur(), a = Hr(), c = Wr(), u = Br(), f = Vr(), l = Kr(), d = zr(), p = Jr(), v = Yr(), y = Zr(), I = Xr(), N = Qr(), C = $r(), K = es(), xe = ts(), te = w(), qe = yn(), Ue = k(), He = {
|
|
3095
|
+
APB: t.decodeSentence,
|
|
3096
|
+
BWC: n.decodeSentence,
|
|
3097
|
+
DBT: r.decodeSentence,
|
|
3098
|
+
DTM: i.decodeSentence,
|
|
3099
|
+
GGA: o.decodeSentence,
|
|
3100
|
+
GLL: s.decodeSentence,
|
|
3101
|
+
GNS: a.decodeSentence,
|
|
3102
|
+
GSA: c.decodeSentence,
|
|
3103
|
+
GST: u.decodeSentence,
|
|
3104
|
+
GSV: f.decodeSentence,
|
|
3105
|
+
HDG: l.decodeSentence,
|
|
3106
|
+
HDM: d.decodeSentence,
|
|
3107
|
+
HDT: p.decodeSentence,
|
|
3108
|
+
MTK: v.decodeSentence,
|
|
3109
|
+
MWV: y.decodeSentence,
|
|
3110
|
+
RDID: I.decodeSentence,
|
|
3111
|
+
RMC: N.decodeSentence,
|
|
3112
|
+
VHW: C.decodeSentence,
|
|
3113
|
+
VTG: K.decodeSentence,
|
|
3114
|
+
ZDA: xe.decodeSentence
|
|
3115
|
+
}, We = {
|
|
3116
|
+
DBT: r.encodePacket,
|
|
3117
|
+
GGA: o.encodePacket,
|
|
3118
|
+
GLL: s.encodePacket,
|
|
3119
|
+
GNS: a.encodePacket,
|
|
3120
|
+
HDM: d.encodePacket,
|
|
3121
|
+
HDT: p.encodePacket,
|
|
3122
|
+
MTK: v.encodePacket,
|
|
3123
|
+
MWV: y.encodePacket,
|
|
3124
|
+
VTG: K.encodePacket
|
|
3125
|
+
}, h = (
|
|
3126
|
+
/** @class */
|
|
3127
|
+
(function() {
|
|
3128
|
+
function _(b) {
|
|
3129
|
+
b === void 0 && (b = !1), this.ableToParseBadChecksum = b;
|
|
3130
|
+
}
|
|
3131
|
+
return _.getParser = function(b) {
|
|
3132
|
+
return b.sentenceId.substr(0, 3) === "MTK" ? v.decodeSentence : He[b.sentenceId];
|
|
3133
|
+
}, _.prototype.assemble = function(b, P) {
|
|
3134
|
+
var M = _.getParser(b);
|
|
3135
|
+
return M ? M(b, P) : this.assembleCustomPacket(b, P);
|
|
3136
|
+
}, _.prototype.assembleCustomPacket = function(b, P) {
|
|
3137
|
+
return null;
|
|
3138
|
+
}, _;
|
|
3139
|
+
})()
|
|
3140
|
+
);
|
|
3141
|
+
F.DefaultPacketFactory = h;
|
|
3142
|
+
var m = new h();
|
|
3143
|
+
function g(_, b) {
|
|
3144
|
+
var P = !0;
|
|
3145
|
+
if (!Ue.validNmeaChecksum(_)) {
|
|
3146
|
+
if (!b.ableToParseBadChecksum)
|
|
3147
|
+
throw Error('Invalid sentence: "' + _ + '".');
|
|
3148
|
+
P = !1;
|
|
3149
|
+
}
|
|
3150
|
+
var M = _.split("*")[0].split(","), x = te.parseStub(M[0], P), J = b.assemble(x, M);
|
|
3151
|
+
if (!J)
|
|
3152
|
+
throw Error('No known parser for sentence ID "' + x.sentenceId + '".');
|
|
3153
|
+
return J;
|
|
3154
|
+
}
|
|
3155
|
+
F.parseGenericPacket = g;
|
|
3156
|
+
function S(_) {
|
|
3157
|
+
return g(_, m);
|
|
3158
|
+
}
|
|
3159
|
+
F.parseNmeaSentence = S;
|
|
3160
|
+
function D(_, b) {
|
|
3161
|
+
if (b === void 0 && (b = "P"), _ === void 0)
|
|
3162
|
+
throw new Error("Packet must be given.");
|
|
3163
|
+
var P = We[_.sentenceId];
|
|
3164
|
+
if (P)
|
|
3165
|
+
return P(_, b);
|
|
3166
|
+
throw Error('No known encoder for sentence ID "' + _.sentenceId + '"');
|
|
3167
|
+
}
|
|
3168
|
+
F.encodeNmeaPacket = D;
|
|
3169
|
+
var E = (
|
|
3170
|
+
/** @class */
|
|
3171
|
+
(function(_) {
|
|
3172
|
+
e(b, _);
|
|
3173
|
+
function b() {
|
|
3174
|
+
return _.call(this, !0) || this;
|
|
3175
|
+
}
|
|
3176
|
+
return b.prototype.assembleCustomPacket = function(P, M) {
|
|
3177
|
+
return qe.decodeSentence(P, M);
|
|
3178
|
+
}, b;
|
|
3179
|
+
})(h)
|
|
3180
|
+
);
|
|
3181
|
+
F.UnsafePacketFactory = E;
|
|
3182
|
+
var R = new E();
|
|
3183
|
+
function z(_) {
|
|
3184
|
+
return g(_, R);
|
|
3185
|
+
}
|
|
3186
|
+
F.parseUnsafeNmeaSentence = z;
|
|
3187
|
+
function H(_) {
|
|
3188
|
+
return _.sentenceId === "?" ? _.originalPacketId : _.sentenceId;
|
|
3189
|
+
}
|
|
3190
|
+
return F.getUnsafePacketId = H, F;
|
|
3191
|
+
}
|
|
3192
|
+
var Le = ns(), rs = yn(), dt = w();
|
|
3193
|
+
const zt = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
|
|
3194
|
+
function ss(e) {
|
|
3195
|
+
const t = e >> 4 & 15, n = e >> 0 & 15;
|
|
3196
|
+
return zt[t] + zt[n];
|
|
3197
|
+
}
|
|
3198
|
+
function G(e, t, n) {
|
|
3199
|
+
let r = typeof e == "string" ? e : e.toFixed(0);
|
|
3200
|
+
for (; r.length < t; )
|
|
3201
|
+
r = n + r;
|
|
3202
|
+
return r;
|
|
3203
|
+
}
|
|
3204
|
+
function Ls(e) {
|
|
3205
|
+
const [t, n] = e.split("*"), r = Sn(t), i = Number.parseInt(n, 16);
|
|
3206
|
+
return r === i;
|
|
3207
|
+
}
|
|
3208
|
+
function Sn(e) {
|
|
3209
|
+
let t = e.charCodeAt(1);
|
|
3210
|
+
for (let n = 2; n < e.length; n += 1)
|
|
3211
|
+
t = t ^ e.charCodeAt(n);
|
|
3212
|
+
return t = t & 255, t;
|
|
3213
|
+
}
|
|
3214
|
+
function is(e) {
|
|
3215
|
+
return `*${ss(Sn(e))}`;
|
|
3216
|
+
}
|
|
3217
|
+
function xs(e) {
|
|
3218
|
+
return e + is(e);
|
|
3219
|
+
}
|
|
3220
|
+
function qs(e, t) {
|
|
3221
|
+
return e === void 0 ? "" : e.toFixed(t);
|
|
3222
|
+
}
|
|
3223
|
+
function Us(e) {
|
|
3224
|
+
if (e === void 0)
|
|
3225
|
+
return ",";
|
|
3226
|
+
let t;
|
|
3227
|
+
e < 0 ? (t = "S", e = -e) : t = "N";
|
|
3228
|
+
const n = Math.floor(e);
|
|
3229
|
+
let r = G(n, 2, "0");
|
|
3230
|
+
const o = (e - n) * 60, s = G(o.toFixed(6), 9, "0");
|
|
3231
|
+
return r = `${r + s},${t}`, r;
|
|
3232
|
+
}
|
|
3233
|
+
function Hs(e) {
|
|
3234
|
+
if (e === void 0)
|
|
3235
|
+
return ",";
|
|
3236
|
+
let t;
|
|
3237
|
+
e < 0 ? (t = "W", e = -e) : t = "E";
|
|
3238
|
+
const n = Math.floor(e);
|
|
3239
|
+
let r = G(n, 3, "0");
|
|
3240
|
+
const o = (e - n) * 60, s = G(o.toFixed(6), 9, "0");
|
|
3241
|
+
return r = `${r + s},${t}`, r;
|
|
3242
|
+
}
|
|
3243
|
+
function Ws(e) {
|
|
3244
|
+
return e === void 0 ? "," : `${e.toFixed(1)},M`;
|
|
3245
|
+
}
|
|
3246
|
+
function Bs(e) {
|
|
3247
|
+
return e === void 0 ? "" : e.toFixed(1);
|
|
3248
|
+
}
|
|
3249
|
+
function Vs(e) {
|
|
3250
|
+
return e === void 0 ? "," : `${e.toFixed(1)},M`;
|
|
3251
|
+
}
|
|
3252
|
+
function Ks(e) {
|
|
3253
|
+
return e === void 0 ? "" : e.toFixed(1);
|
|
3254
|
+
}
|
|
3255
|
+
function zs(e) {
|
|
3256
|
+
return e === void 0 ? "" : G(e.toFixed(2), 6, "0");
|
|
3257
|
+
}
|
|
3258
|
+
function Js(e) {
|
|
3259
|
+
if (e === void 0)
|
|
3260
|
+
return "";
|
|
3261
|
+
const t = e.getUTCFullYear(), n = e.getUTCMonth() + 1, r = e.getUTCDate();
|
|
3262
|
+
return G(r, 2, "0") + G(n, 2, "0") + t.toFixed(0).substr(2);
|
|
3263
|
+
}
|
|
3264
|
+
function Ys(e) {
|
|
3265
|
+
if (e === void 0)
|
|
3266
|
+
return "";
|
|
3267
|
+
const t = e.getUTCHours(), n = e.getUTCMinutes(), r = e.getUTCSeconds();
|
|
3268
|
+
return G(t, 2, "0") + G(n, 2, "0") + G(r, 2, "0");
|
|
3269
|
+
}
|
|
3270
|
+
function Zs(e) {
|
|
3271
|
+
return e === void 0 ? "" : String(e);
|
|
3272
|
+
}
|
|
3273
|
+
function L(e) {
|
|
3274
|
+
return e === "" ? 0 : Number.parseFloat(e);
|
|
3275
|
+
}
|
|
3276
|
+
function Xs(e) {
|
|
3277
|
+
return e === "" ? 0 : Number.parseInt(e, 10);
|
|
3278
|
+
}
|
|
3279
|
+
function Qs(e) {
|
|
3280
|
+
if (e === void 0)
|
|
3281
|
+
return "";
|
|
3282
|
+
const t = Number.parseFloat(e);
|
|
3283
|
+
return Number.isNaN(t) ? e : t;
|
|
3284
|
+
}
|
|
3285
|
+
function _n(e) {
|
|
3286
|
+
const t = e.indexOf(".");
|
|
3287
|
+
if (t < 0)
|
|
3288
|
+
return 0;
|
|
3289
|
+
let n, r;
|
|
3290
|
+
return t >= 3 ? (n = e.substring(0, t - 2), r = e.substring(t - 2)) : (n = "0", r = e), Number.parseFloat(n) + Number.parseFloat(r) / 60;
|
|
3291
|
+
}
|
|
3292
|
+
function $s(e, t) {
|
|
3293
|
+
const n = t === "N" ? 1 : -1;
|
|
3294
|
+
return _n(e) * n;
|
|
3295
|
+
}
|
|
3296
|
+
function ei(e, t) {
|
|
3297
|
+
const n = t === "E" ? 1 : -1;
|
|
3298
|
+
return _n(e) * n;
|
|
3299
|
+
}
|
|
3300
|
+
function os(e, t) {
|
|
3301
|
+
if (e.length === 4)
|
|
3302
|
+
return Number(e);
|
|
3303
|
+
if (e.length === 2)
|
|
3304
|
+
if (t) {
|
|
3305
|
+
let n = Number(e);
|
|
3306
|
+
return n < 73 ? n = 2e3 + n : n = 1900 + n, n;
|
|
3307
|
+
} else
|
|
3308
|
+
return +`20${e}`;
|
|
3309
|
+
else
|
|
3310
|
+
throw new Error(`Unexpected year string: ${e}`);
|
|
3311
|
+
}
|
|
3312
|
+
function ti(e, t, n = !1) {
|
|
3313
|
+
if (e === "")
|
|
3314
|
+
return /* @__PURE__ */ new Date(0);
|
|
3315
|
+
const r = /* @__PURE__ */ new Date();
|
|
3316
|
+
if (t) {
|
|
3317
|
+
const a = t.slice(4), c = Number.parseInt(t.slice(2, 4), 10) - 1, u = t.slice(0, 2);
|
|
3318
|
+
r.setUTCFullYear(os(a, n), Number(c), Number(u));
|
|
3319
|
+
}
|
|
3320
|
+
r.setUTCHours(Number(e.slice(0, 2))), r.setUTCMinutes(Number(e.slice(2, 4))), r.setUTCSeconds(Number(e.slice(4, 6)));
|
|
3321
|
+
const i = e.slice(7), o = i.length;
|
|
3322
|
+
let s = 0;
|
|
3323
|
+
return o !== 0 && (s = Number.parseFloat(i) * 10 ** (3 - o)), r.setUTCMilliseconds(Number(s)), r;
|
|
3324
|
+
}
|
|
3325
|
+
const as = "DBK", cs = "Depth Below Keel";
|
|
3326
|
+
function us(e, t) {
|
|
3327
|
+
return {
|
|
3328
|
+
...dt.initStubFields(e, as, cs),
|
|
3329
|
+
depthFeet: L(t[1]),
|
|
3330
|
+
depthMeters: L(t[3]),
|
|
3331
|
+
depthFathoms: L(t[5])
|
|
3332
|
+
};
|
|
3333
|
+
}
|
|
3334
|
+
const ds = "DBS", fs = "Depth Below Surface";
|
|
3335
|
+
function ls(e, t) {
|
|
3336
|
+
return {
|
|
3337
|
+
...dt.initStubFields(e, ds, fs),
|
|
3338
|
+
depthFeet: L(t[1]),
|
|
3339
|
+
depthMeters: L(t[3]),
|
|
3340
|
+
depthFathoms: L(t[5])
|
|
3341
|
+
};
|
|
3342
|
+
}
|
|
3343
|
+
const hs = "DPT", ps = "Depth of Water";
|
|
3344
|
+
function vs(e, t) {
|
|
3345
|
+
return {
|
|
3346
|
+
...dt.initStubFields(e, hs, ps),
|
|
3347
|
+
depthMeters: L(t[1]),
|
|
3348
|
+
offsetMeters: L(t[2]),
|
|
3349
|
+
maximumRangeScale: L(t[3])
|
|
3350
|
+
};
|
|
3351
|
+
}
|
|
3352
|
+
function bn(e, t) {
|
|
3353
|
+
switch (e.talkerId) {
|
|
3354
|
+
case "DBS":
|
|
3355
|
+
return ls(e, t);
|
|
3356
|
+
case "DBK":
|
|
3357
|
+
return us(e, t);
|
|
3358
|
+
case "DPT":
|
|
3359
|
+
return vs(e, t);
|
|
3360
|
+
default:
|
|
3361
|
+
return null;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
class ms extends Le.DefaultPacketFactory {
|
|
3365
|
+
assembleCustomPacket(t, n) {
|
|
3366
|
+
return bn(t, n);
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
const gs = new ms();
|
|
3370
|
+
function ni(e) {
|
|
3371
|
+
return Le.parseGenericPacket(e, gs);
|
|
3372
|
+
}
|
|
3373
|
+
class ys extends Le.DefaultPacketFactory {
|
|
3374
|
+
constructor() {
|
|
3375
|
+
super(!0);
|
|
3376
|
+
}
|
|
3377
|
+
assembleCustomPacket(t, n) {
|
|
3378
|
+
const r = bn(t, n);
|
|
3379
|
+
return r || rs.decodeSentence(t, n);
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
const Ss = new ys();
|
|
3383
|
+
function _s(e) {
|
|
3384
|
+
return Le.parseGenericPacket(e, Ss);
|
|
3385
|
+
}
|
|
3386
|
+
function Jt(e, t) {
|
|
3387
|
+
return !t || t.length === 0 ? !0 : e !== void 0 && t.includes(e);
|
|
3388
|
+
}
|
|
3389
|
+
class bs {
|
|
3390
|
+
/** Buffer for incomplete lines that span multiple chunks. */
|
|
3391
|
+
container;
|
|
3392
|
+
constructor() {
|
|
3393
|
+
this.container = "";
|
|
3394
|
+
}
|
|
3395
|
+
/**
|
|
3396
|
+
* Transforms incoming text chunks by splitting on \r\n and emitting complete lines.
|
|
3397
|
+
* Incomplete lines are buffered until the next chunk arrives.
|
|
3398
|
+
*
|
|
3399
|
+
* @param chunk - The text chunk to process.
|
|
3400
|
+
* @param controller - The transform stream controller to enqueue complete lines.
|
|
3401
|
+
*/
|
|
3402
|
+
transform(t, n) {
|
|
3403
|
+
this.container += t;
|
|
3404
|
+
const r = this.container.split(`\r
|
|
3405
|
+
`), i = r.pop();
|
|
3406
|
+
this.container = i ?? "", r.forEach((o) => {
|
|
3407
|
+
o.length > 0 && n.enqueue(o);
|
|
3408
|
+
});
|
|
3409
|
+
}
|
|
3410
|
+
/**
|
|
3411
|
+
* Flushes any remaining buffered data when the stream closes.
|
|
3412
|
+
* Incomplete NMEA sentences are discarded as they cannot be reliably parsed.
|
|
3413
|
+
*
|
|
3414
|
+
* @param controller - The transform stream controller (required by interface but unused).
|
|
3415
|
+
*/
|
|
3416
|
+
flush(t) {
|
|
3417
|
+
this.container = "";
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
const Ts = vn(async ({ input: e }) => {
|
|
3421
|
+
if (!navigator.serial)
|
|
3422
|
+
throw new Error("Web Serial API is not supported in this browser.");
|
|
3423
|
+
console.log("Requesting serial port...");
|
|
3424
|
+
const t = await navigator.serial.requestPort();
|
|
3425
|
+
if (console.log(`Opening port at ${e.baudRate} baud...`), t.readable || t.writable) {
|
|
3426
|
+
console.log("Port is already open, closing first...");
|
|
3427
|
+
try {
|
|
3428
|
+
await t.close();
|
|
3429
|
+
} catch (n) {
|
|
3430
|
+
console.warn("Error closing already-open port:", n);
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
return await t.open({ baudRate: e.baudRate }), console.log("Port open."), t;
|
|
3434
|
+
}), Is = vn(async ({ input: e }) => {
|
|
3435
|
+
if (e.port)
|
|
3436
|
+
try {
|
|
3437
|
+
(e.port.readable || e.port.writable) && (await e.port.close(), console.log("Port closed successfully."));
|
|
3438
|
+
} catch (t) {
|
|
3439
|
+
console.warn("Error closing port:", t);
|
|
3440
|
+
}
|
|
3441
|
+
}), ws = Sr(
|
|
3442
|
+
({ input: e, sendBack: t, receive: n }) => {
|
|
3443
|
+
const { port: r } = e;
|
|
3444
|
+
if (!r || !r.readable) {
|
|
3445
|
+
t({ type: "SERIAL.ERROR", error: "Invalid port context." });
|
|
3446
|
+
return;
|
|
3447
|
+
}
|
|
3448
|
+
const i = new bs(), s = r.readable.pipeThrough(new TextDecoderStream()).pipeThrough(
|
|
3449
|
+
new TransformStream({
|
|
3450
|
+
transform: i.transform.bind(i),
|
|
3451
|
+
flush: i.flush.bind(i)
|
|
3452
|
+
})
|
|
3453
|
+
).getReader();
|
|
3454
|
+
let a = !0;
|
|
3455
|
+
async function c() {
|
|
3456
|
+
try {
|
|
3457
|
+
for (; a; ) {
|
|
3458
|
+
const { value: u, done: f } = await s.read();
|
|
3459
|
+
if (f)
|
|
3460
|
+
break;
|
|
3461
|
+
if (u && u.length > 0)
|
|
3462
|
+
try {
|
|
3463
|
+
const l = _s(u);
|
|
3464
|
+
if (l.sentenceId === "?")
|
|
3465
|
+
continue;
|
|
3466
|
+
t({ type: "SERIAL.DATA", data: l });
|
|
3467
|
+
} catch (l) {
|
|
3468
|
+
const d = l instanceof Error ? l.message : String(l);
|
|
3469
|
+
console.warn("Failed to parse NMEA sentence:", u, d), t({
|
|
3470
|
+
type: "SERIAL.ERROR",
|
|
3471
|
+
error: `Parser Error: ${d}`
|
|
3472
|
+
});
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
} catch (u) {
|
|
3476
|
+
if (console.error("Read loop error:", u), a) {
|
|
3477
|
+
const f = u instanceof Error ? u.message : String(u);
|
|
3478
|
+
t({ type: "FATAL_ERROR", error: f });
|
|
3479
|
+
}
|
|
3480
|
+
} finally {
|
|
3481
|
+
console.log("Read loop finished."), t({ type: "SERIAL.DISCONNECTED" });
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
return c(), n((u) => {
|
|
3485
|
+
u.type === "STOP" && (console.log("Received STOP, cancelling reader..."), a = !1, s.cancel().catch(() => {
|
|
3486
|
+
}));
|
|
3487
|
+
}), () => {
|
|
3488
|
+
console.log("Cleaning up stream reader actor..."), a = !1, s && s.cancel().catch(() => {
|
|
3489
|
+
});
|
|
3490
|
+
};
|
|
3491
|
+
}
|
|
3492
|
+
);
|
|
3493
|
+
function ks(e) {
|
|
3494
|
+
const { adapter: t, allowedSentenceIds: n, initialData: r, initialPackets: i } = e;
|
|
3495
|
+
return gn({
|
|
3496
|
+
actors: {
|
|
3497
|
+
connectToSerial: Ts,
|
|
3498
|
+
readNmeaStream: ws,
|
|
3499
|
+
closePort: Is
|
|
3500
|
+
},
|
|
3501
|
+
actions: {
|
|
3502
|
+
/**
|
|
3503
|
+
* Sets the serial port in context and clears any error.
|
|
3504
|
+
*/
|
|
3505
|
+
setPort: O((o, s) => ({
|
|
3506
|
+
port: s.port,
|
|
3507
|
+
error: null
|
|
3508
|
+
})),
|
|
3509
|
+
/**
|
|
3510
|
+
* Sets an error message in context from a connection error.
|
|
3511
|
+
*/
|
|
3512
|
+
setError: O((o, s) => {
|
|
3513
|
+
const a = s.error;
|
|
3514
|
+
let c;
|
|
3515
|
+
return typeof a == "string" ? c = a : a instanceof Error ? c = a.message || "Failed to connect." : c = String(a) || "Failed to connect.", { error: c };
|
|
3516
|
+
}),
|
|
3517
|
+
/**
|
|
3518
|
+
* Logs parsed NMEA packet data to the console.
|
|
3519
|
+
* Only logs packets with allowed sentence IDs if logging is enabled.
|
|
3520
|
+
*/
|
|
3521
|
+
logParsedData: ({ context: o }, s) => {
|
|
3522
|
+
if (!o.enableLogging)
|
|
3523
|
+
return;
|
|
3524
|
+
const c = s.packet.sentenceId;
|
|
3525
|
+
Jt(c, n) && console.log(`${c} Packet:`, s.packet);
|
|
3526
|
+
},
|
|
3527
|
+
/**
|
|
3528
|
+
* Stores a parsed NMEA packet in context and recomputes data via the adapter.
|
|
3529
|
+
* Only stores packets with allowed sentence IDs (if filtering is configured).
|
|
3530
|
+
*/
|
|
3531
|
+
storePacket: O(({ context: o }, s) => {
|
|
3532
|
+
const c = s.packet.sentenceId;
|
|
3533
|
+
if (c && Jt(c, n)) {
|
|
3534
|
+
const u = {
|
|
3535
|
+
...o.packets,
|
|
3536
|
+
[c]: s.packet
|
|
3537
|
+
};
|
|
3538
|
+
return {
|
|
3539
|
+
packets: u,
|
|
3540
|
+
data: t(u),
|
|
3541
|
+
error: null
|
|
3542
|
+
};
|
|
3543
|
+
}
|
|
3544
|
+
return {
|
|
3545
|
+
packets: o.packets,
|
|
3546
|
+
data: t(o.packets),
|
|
3547
|
+
error: null
|
|
3548
|
+
};
|
|
3549
|
+
}),
|
|
3550
|
+
/**
|
|
3551
|
+
* Sets a serial error message in context.
|
|
3552
|
+
*/
|
|
3553
|
+
clearError: O((o, s) => ({
|
|
3554
|
+
error: s.error
|
|
3555
|
+
})),
|
|
3556
|
+
/**
|
|
3557
|
+
* Sets a fatal error message in context.
|
|
3558
|
+
*/
|
|
3559
|
+
setFatalError: O((o, s) => ({
|
|
3560
|
+
error: s.error
|
|
3561
|
+
})),
|
|
3562
|
+
/**
|
|
3563
|
+
* Resets the machine context to disconnected state.
|
|
3564
|
+
*/
|
|
3565
|
+
disconnect: O({
|
|
3566
|
+
port: null,
|
|
3567
|
+
error: null,
|
|
3568
|
+
packets: i,
|
|
3569
|
+
data: r
|
|
3570
|
+
}),
|
|
3571
|
+
/**
|
|
3572
|
+
* Sets the logging enabled state.
|
|
3573
|
+
*/
|
|
3574
|
+
setLogging: O((o, s) => ({
|
|
3575
|
+
enableLogging: s.enabled
|
|
3576
|
+
})),
|
|
3577
|
+
/**
|
|
3578
|
+
* Sets the baud rate for serial communication.
|
|
3579
|
+
*/
|
|
3580
|
+
setBaudRate: O((o, s) => ({
|
|
3581
|
+
baudRate: s.baudRate
|
|
3582
|
+
}))
|
|
3583
|
+
}
|
|
3584
|
+
}).createMachine({
|
|
3585
|
+
id: "nmea",
|
|
3586
|
+
initial: "disconnected",
|
|
3587
|
+
context: {
|
|
3588
|
+
port: null,
|
|
3589
|
+
error: null,
|
|
3590
|
+
packets: i,
|
|
3591
|
+
data: r,
|
|
3592
|
+
enableLogging: !1,
|
|
3593
|
+
baudRate: 4800
|
|
3594
|
+
},
|
|
3595
|
+
on: {
|
|
3596
|
+
SET_LOGGING: {
|
|
3597
|
+
actions: {
|
|
3598
|
+
type: "setLogging",
|
|
3599
|
+
params: ({ event: o }) => ({ enabled: o.enabled })
|
|
3600
|
+
}
|
|
3601
|
+
}
|
|
3602
|
+
},
|
|
3603
|
+
states: {
|
|
3604
|
+
disconnected: {
|
|
3605
|
+
on: {
|
|
3606
|
+
CONNECT: "connecting",
|
|
3607
|
+
SET_BAUD_RATE: {
|
|
3608
|
+
actions: {
|
|
3609
|
+
type: "setBaudRate",
|
|
3610
|
+
params: ({ event: o }) => ({ baudRate: o.baudRate })
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
},
|
|
3615
|
+
connecting: {
|
|
3616
|
+
invoke: {
|
|
3617
|
+
id: "connectToSerial",
|
|
3618
|
+
src: "connectToSerial",
|
|
3619
|
+
input: ({ context: o }) => ({ baudRate: o.baudRate }),
|
|
3620
|
+
onDone: {
|
|
3621
|
+
target: "connected",
|
|
3622
|
+
actions: {
|
|
3623
|
+
type: "setPort",
|
|
3624
|
+
params: ({ event: o }) => ({ port: o.output })
|
|
3625
|
+
}
|
|
3626
|
+
},
|
|
3627
|
+
onError: {
|
|
3628
|
+
target: "error",
|
|
3629
|
+
actions: {
|
|
3630
|
+
type: "setError",
|
|
3631
|
+
params: ({ event: o }) => ({ error: o.error })
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
},
|
|
3636
|
+
connected: {
|
|
3637
|
+
on: {
|
|
3638
|
+
"SERIAL.DATA": {
|
|
3639
|
+
actions: [
|
|
3640
|
+
{
|
|
3641
|
+
type: "logParsedData",
|
|
3642
|
+
params: ({ event: o }) => ({ packet: o.data })
|
|
3643
|
+
},
|
|
3644
|
+
{
|
|
3645
|
+
type: "storePacket",
|
|
3646
|
+
params: ({ event: o }) => ({ packet: o.data })
|
|
3647
|
+
}
|
|
3648
|
+
]
|
|
3649
|
+
},
|
|
3650
|
+
"SERIAL.ERROR": {
|
|
3651
|
+
actions: {
|
|
3652
|
+
type: "clearError",
|
|
3653
|
+
params: ({ event: o }) => ({ error: o.error })
|
|
3654
|
+
}
|
|
3655
|
+
},
|
|
3656
|
+
FATAL_ERROR: {
|
|
3657
|
+
target: "error",
|
|
3658
|
+
actions: {
|
|
3659
|
+
type: "setFatalError",
|
|
3660
|
+
params: ({ event: o }) => ({ error: o.error })
|
|
3661
|
+
}
|
|
3662
|
+
},
|
|
3663
|
+
"SERIAL.DISCONNECTED": {
|
|
3664
|
+
target: "disconnecting"
|
|
3665
|
+
},
|
|
3666
|
+
DISCONNECT: {
|
|
3667
|
+
actions: Ge("streamReader", { type: "STOP" })
|
|
3668
|
+
}
|
|
3669
|
+
},
|
|
3670
|
+
invoke: {
|
|
3671
|
+
id: "streamReader",
|
|
3672
|
+
src: "readNmeaStream",
|
|
3673
|
+
input: ({ context: o }) => ({ port: o.port })
|
|
3674
|
+
}
|
|
3675
|
+
},
|
|
3676
|
+
disconnecting: {
|
|
3677
|
+
invoke: {
|
|
3678
|
+
id: "closePort",
|
|
3679
|
+
src: "closePort",
|
|
3680
|
+
input: ({ context: o }) => ({ port: o.port }),
|
|
3681
|
+
onDone: {
|
|
3682
|
+
target: "disconnected",
|
|
3683
|
+
actions: "disconnect"
|
|
3684
|
+
},
|
|
3685
|
+
onError: {
|
|
3686
|
+
target: "disconnected",
|
|
3687
|
+
actions: "disconnect"
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
},
|
|
3691
|
+
error: {
|
|
3692
|
+
on: {
|
|
3693
|
+
CONNECT: "connecting"
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
function Ps(e, t, n) {
|
|
3700
|
+
return e && e.fixType !== "none" ? {
|
|
3701
|
+
latitude: e.latitude,
|
|
3702
|
+
longitude: e.longitude,
|
|
3703
|
+
source: "GGA",
|
|
3704
|
+
fixType: e.fixType,
|
|
3705
|
+
altitudeMeters: e.altitudeMeters,
|
|
3706
|
+
satellitesInView: e.satellitesInView,
|
|
3707
|
+
horizontalDilution: e.horizontalDilution
|
|
3708
|
+
} : t && t.status === "valid" ? {
|
|
3709
|
+
latitude: t.latitude,
|
|
3710
|
+
longitude: t.longitude,
|
|
3711
|
+
source: "RMC",
|
|
3712
|
+
status: t.status
|
|
3713
|
+
} : n && n.status === "valid" ? {
|
|
3714
|
+
latitude: n.latitude,
|
|
3715
|
+
longitude: n.longitude,
|
|
3716
|
+
source: "GLL",
|
|
3717
|
+
status: "valid"
|
|
3718
|
+
} : null;
|
|
3719
|
+
}
|
|
3720
|
+
function Ds(e, t, n, r) {
|
|
3721
|
+
if (e) {
|
|
3722
|
+
const i = new Date(e.datetime), o = e.localZoneHours * 60 + e.localZoneMinutes;
|
|
3723
|
+
return i.setMinutes(i.getMinutes() + o), {
|
|
3724
|
+
utc: e.datetime,
|
|
3725
|
+
local: i,
|
|
3726
|
+
source: "ZDA"
|
|
3727
|
+
};
|
|
3728
|
+
}
|
|
3729
|
+
return t && t.fixType !== "none" ? {
|
|
3730
|
+
utc: t.time,
|
|
3731
|
+
local: null,
|
|
3732
|
+
source: "GGA"
|
|
3733
|
+
} : n && n.status === "valid" ? {
|
|
3734
|
+
utc: n.datetime,
|
|
3735
|
+
local: null,
|
|
3736
|
+
source: "RMC"
|
|
3737
|
+
} : r && r.status === "valid" ? {
|
|
3738
|
+
utc: r.time,
|
|
3739
|
+
local: null,
|
|
3740
|
+
source: "GLL"
|
|
3741
|
+
} : null;
|
|
3742
|
+
}
|
|
3743
|
+
function Ms(e, t) {
|
|
3744
|
+
return e ? { knots: e.speedKnots, source: "VTG" } : t && t.status === "valid" ? { knots: t.speedKnots, source: "RMC" } : null;
|
|
3745
|
+
}
|
|
3746
|
+
function As(e) {
|
|
3747
|
+
return e.variationDirection === "W" ? -e.variation : (e.variationDirection === "E", e.variation);
|
|
3748
|
+
}
|
|
3749
|
+
function Es(e, t, n, r, i, o) {
|
|
3750
|
+
if (e && e.heading !== void 0)
|
|
3751
|
+
return { degreesTrue: e.heading, source: "HDT", isDerived: !1 };
|
|
3752
|
+
if (t && t.heading !== void 0) {
|
|
3753
|
+
const a = As(t);
|
|
3754
|
+
return {
|
|
3755
|
+
degreesTrue: t.heading + a,
|
|
3756
|
+
source: "HDG",
|
|
3757
|
+
isDerived: !1
|
|
3758
|
+
};
|
|
3759
|
+
}
|
|
3760
|
+
if (n && n.heading !== void 0 && o !== void 0)
|
|
3761
|
+
return {
|
|
3762
|
+
degreesTrue: n.heading + o,
|
|
3763
|
+
source: "HDM",
|
|
3764
|
+
isDerived: !1
|
|
3765
|
+
};
|
|
3766
|
+
const s = r?.trackTrue ?? i?.trackTrue;
|
|
3767
|
+
return s !== void 0 ? { degreesTrue: s, source: "COG", isDerived: !0 } : null;
|
|
3768
|
+
}
|
|
3769
|
+
function Fs(e, t, n, r) {
|
|
3770
|
+
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;
|
|
3771
|
+
}
|
|
3772
|
+
function Os(e, t) {
|
|
3773
|
+
const n = Ds(e.ZDA, e.GGA, e.RMC, e.GLL), r = Ps(e.GGA, e.RMC, e.GLL), i = Ms(e.VTG, e.RMC), o = Es(
|
|
3774
|
+
e.HDT,
|
|
3775
|
+
e.HDG,
|
|
3776
|
+
e.HDM,
|
|
3777
|
+
e.RMC,
|
|
3778
|
+
e.VTG,
|
|
3779
|
+
t
|
|
3780
|
+
), s = Fs(
|
|
3781
|
+
e.DPT,
|
|
3782
|
+
e.DBT,
|
|
3783
|
+
e.DBS,
|
|
3784
|
+
e.DBK
|
|
3785
|
+
);
|
|
3786
|
+
return { time: n, position: r, speed: i, heading: o, depth: s };
|
|
3787
|
+
}
|
|
3788
|
+
const Ns = [
|
|
3789
|
+
"GGA",
|
|
3790
|
+
"RMC",
|
|
3791
|
+
"GLL",
|
|
3792
|
+
"VTG",
|
|
3793
|
+
"HDT",
|
|
3794
|
+
"HDG",
|
|
3795
|
+
"HDM",
|
|
3796
|
+
"DPT",
|
|
3797
|
+
"DBT",
|
|
3798
|
+
"DBS",
|
|
3799
|
+
"DBK",
|
|
3800
|
+
"ZDA"
|
|
3801
|
+
];
|
|
3802
|
+
function Cs(e) {
|
|
3803
|
+
return (t) => Os(t, e);
|
|
3804
|
+
}
|
|
3805
|
+
const Rs = {
|
|
3806
|
+
time: null,
|
|
3807
|
+
position: null,
|
|
3808
|
+
speed: null,
|
|
3809
|
+
heading: null,
|
|
3810
|
+
depth: null
|
|
3811
|
+
}, js = {};
|
|
3812
|
+
function Gs(e) {
|
|
3813
|
+
return {
|
|
3814
|
+
adapter: Cs(e?.externalVariation),
|
|
3815
|
+
allowedSentenceIds: e?.allowedSentenceIds ?? Ns,
|
|
3816
|
+
initialData: Rs,
|
|
3817
|
+
initialPackets: js
|
|
3818
|
+
};
|
|
3819
|
+
}
|
|
3820
|
+
function ri(e) {
|
|
3821
|
+
return ks(Gs(e));
|
|
3822
|
+
}
|
|
3823
|
+
export {
|
|
3824
|
+
Ns as NAVIGATION_SENTENCE_IDS,
|
|
3825
|
+
xs as appendChecksumFooter,
|
|
3826
|
+
Os as computeNavigationData,
|
|
3827
|
+
Sn as computeNmeaChecksum,
|
|
3828
|
+
Cs as createNavigationAdapter,
|
|
3829
|
+
Gs as createNavigationNmeaConfig,
|
|
3830
|
+
ri as createNavigationNmeaMachine,
|
|
3831
|
+
is as createNmeaChecksumFooter,
|
|
3832
|
+
ks as createNmeaMachine,
|
|
3833
|
+
Ws as encodeAltitude,
|
|
3834
|
+
Bs as encodeAltitudeNoUnits,
|
|
3835
|
+
Js as encodeDate,
|
|
3836
|
+
zs as encodeDegrees,
|
|
3837
|
+
qs as encodeFixed,
|
|
3838
|
+
Vs as encodeGeoidalSeperation,
|
|
3839
|
+
Ks as encodeGeoidalSeperationNoUnits,
|
|
3840
|
+
Us as encodeLatitude,
|
|
3841
|
+
Hs as encodeLongitude,
|
|
3842
|
+
Ys as encodeTime,
|
|
3843
|
+
Zs as encodeValue,
|
|
3844
|
+
Rs as initialNavigationData,
|
|
3845
|
+
js as initialNavigationPackets,
|
|
3846
|
+
G as padLeft,
|
|
3847
|
+
_n as parseDmCoordinate,
|
|
3848
|
+
L as parseFloatSafe,
|
|
3849
|
+
Xs as parseIntSafe,
|
|
3850
|
+
$s as parseLatitude,
|
|
3851
|
+
ei as parseLongitude,
|
|
3852
|
+
ni as parseNmeaSentence,
|
|
3853
|
+
Qs as parseNumberOrString,
|
|
3854
|
+
ti as parseTime,
|
|
3855
|
+
_s as parseUnsafeNmeaSentence,
|
|
3856
|
+
ss as toHexString,
|
|
3857
|
+
Ls as validNmeaChecksum
|
|
3858
|
+
};
|