@danidoble/webserial 4.3.1 → 4.3.3
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/dist/boardroid.cjs +1 -1
- package/dist/boardroid.js +3 -3
- package/dist/hopper.cjs +2 -2
- package/dist/hopper.js +35 -35
- package/dist/jofemar.cjs +1 -1
- package/dist/jofemar.js +3 -3
- package/dist/{kernel-lcvN8cY0.js → kernel-BblykfpT.js} +257 -259
- package/dist/{kernel-BTqvt4pt.cjs → kernel-CzkmE_OW.cjs} +1 -1
- package/dist/kernel.cjs +2 -2
- package/dist/kernel.js +3 -3
- package/dist/locker.cjs +1 -1
- package/dist/locker.js +3 -3
- package/dist/pinpad.cjs +1 -1
- package/dist/pinpad.js +2 -2
- package/dist/pinpax.cjs +1 -1
- package/dist/pinpax.js +3 -3
- package/dist/{relay-Dop4mFk-.js → relay-CsdB0FSa.js} +0 -1
- package/dist/{relay-BsUsBpOv.cjs → relay-DGFymXOw.cjs} +3 -3
- package/dist/relay.cjs +1 -1
- package/dist/relay.js +3 -3
- package/dist/webserial-core-5B5nYtyR.cjs +4 -0
- package/dist/{webserial-core-DGKQCs5a.js → webserial-core-ByrJ7tlu.js} +103 -64
- package/dist/webserial.cjs +2 -2
- package/dist/webserial.js +11 -13
- package/package.json +2 -6
- package/dist/arduino.cjs +0 -1
- package/dist/arduino.js +0 -72
- package/dist/webserial-core-DlH0cFSH.cjs +0 -4
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var j = Object.defineProperty,
|
|
1
|
+
var j = Object.defineProperty, B = (i) => {
|
|
2
2
|
throw TypeError(i);
|
|
3
|
-
}, F = (i, e, t) => e in i ? j(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t,
|
|
3
|
+
}, F = (i, e, t) => e in i ? j(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, g = (i, e, t) => F(i, typeof e != "symbol" ? e + "" : e, t), W = (i, e, t) => e.has(i) || B("Cannot " + t), Q = (i, e, t) => e.has(i) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), l = (i, e, t) => (W(i, e, "access private method"), t);
|
|
4
4
|
class x extends CustomEvent {
|
|
5
5
|
constructor(e, t) {
|
|
6
6
|
super(e, t);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
class
|
|
9
|
+
class P extends EventTarget {
|
|
10
10
|
constructor() {
|
|
11
|
-
super(...arguments),
|
|
11
|
+
super(...arguments), g(this, "__listeners__", {
|
|
12
12
|
debug: !1
|
|
13
|
-
}),
|
|
13
|
+
}), g(this, "__debug__", !1), g(this, "__listenersCallbacks__", []);
|
|
14
14
|
}
|
|
15
15
|
dispatch(e, t = null) {
|
|
16
16
|
const n = new x(e, { detail: t });
|
|
@@ -23,10 +23,10 @@ class $ extends EventTarget {
|
|
|
23
23
|
}, n);
|
|
24
24
|
}
|
|
25
25
|
on(e, t) {
|
|
26
|
-
typeof this.__listeners__[e] < "u" && !this.__listeners__[e] && (this.__listeners__[e] = !0), this.addEventListener(e, t);
|
|
26
|
+
typeof this.__listeners__[e] < "u" && !this.__listeners__[e] && (this.__listeners__[e] = !0), this.__listenersCallbacks__.push({ key: e, callback: t }), this.addEventListener(e, t);
|
|
27
27
|
}
|
|
28
28
|
off(e, t) {
|
|
29
|
-
this.removeEventListener(e, t);
|
|
29
|
+
this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((n) => !(n.key === e && n.callback === t)), this.removeEventListener(e, t);
|
|
30
30
|
}
|
|
31
31
|
serialRegisterAvailableListener(e) {
|
|
32
32
|
this.__listeners__[e] || (this.__listeners__[e] = !1);
|
|
@@ -37,51 +37,90 @@ class $ extends EventTarget {
|
|
|
37
37
|
listening: this.__listeners__[e]
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
|
+
removeAllListeners() {
|
|
41
|
+
for (const e of this.__listenersCallbacks__)
|
|
42
|
+
this.removeEventListener(e.key, e.callback);
|
|
43
|
+
this.__listenersCallbacks__ = [], this.__listeners__ = {
|
|
44
|
+
debug: !1
|
|
45
|
+
};
|
|
46
|
+
}
|
|
40
47
|
}
|
|
41
|
-
const w = class
|
|
48
|
+
const w = class a extends P {
|
|
42
49
|
constructor() {
|
|
43
50
|
super(), ["change"].forEach((e) => {
|
|
44
51
|
this.serialRegisterAvailableListener(e);
|
|
45
52
|
});
|
|
46
53
|
}
|
|
47
54
|
static $dispatchChange(e = null) {
|
|
48
|
-
e && e.$checkAndDispatchConnection(),
|
|
55
|
+
e && e.$checkAndDispatchConnection(), a.instance.dispatch("change", { devices: a.devices, dispatcher: e });
|
|
49
56
|
}
|
|
50
57
|
static typeError(e) {
|
|
51
58
|
const t = new Error();
|
|
52
59
|
throw t.message = `Type ${e} is not supported`, t.name = "DeviceTypeError", t;
|
|
53
60
|
}
|
|
54
61
|
static registerType(e) {
|
|
55
|
-
typeof
|
|
62
|
+
typeof a.devices[e] > "u" && (a.devices = { ...a.devices, [e]: {} });
|
|
56
63
|
}
|
|
57
64
|
static add(e) {
|
|
58
65
|
const t = e.typeDevice;
|
|
59
|
-
typeof
|
|
66
|
+
typeof a.devices[t] > "u" && a.registerType(t);
|
|
60
67
|
const n = e.uuid;
|
|
61
|
-
if (typeof
|
|
68
|
+
if (typeof a.devices[t] > "u" && a.typeError(t), a.devices[t][n])
|
|
62
69
|
throw new Error(`Device with id ${n} already exists`);
|
|
63
|
-
return
|
|
70
|
+
return a.devices[t][n] = e, a.$dispatchChange(e), Object.keys(a.devices[t]).indexOf(n);
|
|
64
71
|
}
|
|
65
72
|
static get(e, t) {
|
|
66
|
-
return typeof
|
|
73
|
+
return typeof a.devices[e] > "u" && a.registerType(e), typeof a.devices[e] > "u" && a.typeError(e), a.devices[e][t];
|
|
67
74
|
}
|
|
68
75
|
static getAll(e = null) {
|
|
69
|
-
return e === null ?
|
|
76
|
+
return e === null ? a.devices : (typeof a.devices[e] > "u" && a.typeError(e), a.devices[e]);
|
|
70
77
|
}
|
|
71
78
|
static getList() {
|
|
72
|
-
return Object.values(
|
|
79
|
+
return Object.values(a.devices).map((e) => Object.values(e)).flat();
|
|
73
80
|
}
|
|
74
81
|
static getByNumber(e, t) {
|
|
75
|
-
return typeof
|
|
82
|
+
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((n) => n.deviceNumber === t) ?? null;
|
|
76
83
|
}
|
|
77
84
|
static getCustom(e, t = 1) {
|
|
78
|
-
return typeof
|
|
85
|
+
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((n) => n.deviceNumber === t) ?? null;
|
|
86
|
+
}
|
|
87
|
+
static async connectToAll() {
|
|
88
|
+
const e = a.getList();
|
|
89
|
+
for (const t of e)
|
|
90
|
+
t.isConnected || await t.connect().catch(console.warn);
|
|
91
|
+
return Promise.resolve(a.areAllConnected());
|
|
92
|
+
}
|
|
93
|
+
static async disconnectAll() {
|
|
94
|
+
const e = a.getList();
|
|
95
|
+
for (const t of e)
|
|
96
|
+
t.isDisconnected || await t.disconnect().catch(console.warn);
|
|
97
|
+
return Promise.resolve(a.areAllDisconnected());
|
|
98
|
+
}
|
|
99
|
+
static async areAllConnected() {
|
|
100
|
+
const e = a.getList();
|
|
101
|
+
for (const t of e)
|
|
102
|
+
if (!t.isConnected) return Promise.resolve(!1);
|
|
103
|
+
return Promise.resolve(!0);
|
|
104
|
+
}
|
|
105
|
+
static async areAllDisconnected() {
|
|
106
|
+
const e = a.getList();
|
|
107
|
+
for (const t of e)
|
|
108
|
+
if (!t.isDisconnected) return Promise.resolve(!1);
|
|
109
|
+
return Promise.resolve(!0);
|
|
110
|
+
}
|
|
111
|
+
static async getAllConnected() {
|
|
112
|
+
const e = a.getList();
|
|
113
|
+
return Promise.resolve(e.filter((t) => t.isConnected));
|
|
114
|
+
}
|
|
115
|
+
static async getAllDisconnected() {
|
|
116
|
+
const e = a.getList();
|
|
117
|
+
return Promise.resolve(e.filter((t) => t.isDisconnected));
|
|
79
118
|
}
|
|
80
119
|
};
|
|
81
|
-
|
|
120
|
+
g(w, "instance"), g(w, "devices", {});
|
|
82
121
|
let c = w;
|
|
83
122
|
c.instance || (c.instance = new c());
|
|
84
|
-
function
|
|
123
|
+
function U(i = 100) {
|
|
85
124
|
return new Promise(
|
|
86
125
|
(e) => setTimeout(() => e(), i)
|
|
87
126
|
);
|
|
@@ -97,8 +136,8 @@ const b = {
|
|
|
97
136
|
bufferSize: 32768,
|
|
98
137
|
flowControl: "none"
|
|
99
138
|
};
|
|
100
|
-
var r, p,
|
|
101
|
-
class z extends
|
|
139
|
+
var r, p, y, $, v, T, u, R, E, S, A, k, I, f, M, q, N, L, D, O, H;
|
|
140
|
+
class z extends P {
|
|
102
141
|
constructor({
|
|
103
142
|
filters: e = null,
|
|
104
143
|
config_port: t = b,
|
|
@@ -112,7 +151,7 @@ class z extends $ {
|
|
|
112
151
|
device_listen_on_channel: 1,
|
|
113
152
|
bypassSerialBytesConnection: !1
|
|
114
153
|
}) {
|
|
115
|
-
if (super(), Q(this, r),
|
|
154
|
+
if (super(), Q(this, r), g(this, "__internal__", {
|
|
116
155
|
bypassSerialBytesConnection: !1,
|
|
117
156
|
auto_response: !1,
|
|
118
157
|
device_number: 1,
|
|
@@ -174,7 +213,7 @@ class z extends $ {
|
|
|
174
213
|
}
|
|
175
214
|
}), !("serial" in navigator))
|
|
176
215
|
throw new Error("Web Serial not supported");
|
|
177
|
-
e && (this.serialFilters = e), t && (this.serialConfigPort = t), o && (this.__internal__.bypassSerialBytesConnection = o), n &&
|
|
216
|
+
e && (this.serialFilters = e), t && (this.serialConfigPort = t), o && (this.__internal__.bypassSerialBytesConnection = o), n && l(this, r, O).call(this, n), s && ["number", "string"].includes(typeof s) && (this.listenOnChannel = s), l(this, r, q).call(this), l(this, r, N).call(this);
|
|
178
217
|
}
|
|
179
218
|
set listenOnChannel(e) {
|
|
180
219
|
if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
|
|
@@ -208,15 +247,15 @@ class z extends $ {
|
|
|
208
247
|
this.__internal__.serial.useRTSCTS = e;
|
|
209
248
|
}
|
|
210
249
|
get isConnected() {
|
|
211
|
-
const e = this.__internal__.serial.connected, t =
|
|
212
|
-
return e && !t &&
|
|
250
|
+
const e = this.__internal__.serial.connected, t = l(this, r, p).call(this, this.__internal__.serial.port);
|
|
251
|
+
return e && !t && l(this, r, y).call(this, { error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
|
|
213
252
|
}
|
|
214
253
|
get isConnecting() {
|
|
215
254
|
return this.__internal__.serial.connecting;
|
|
216
255
|
}
|
|
217
256
|
get isDisconnected() {
|
|
218
|
-
const e = this.__internal__.serial.connected, t =
|
|
219
|
-
return !e && t && (this.dispatch("serial:connected"),
|
|
257
|
+
const e = this.__internal__.serial.connected, t = l(this, r, p).call(this, this.__internal__.serial.port);
|
|
258
|
+
return !e && t && (this.dispatch("serial:connected"), l(this, r, f).call(this, !1), c.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
|
|
220
259
|
}
|
|
221
260
|
get deviceNumber() {
|
|
222
261
|
return this.__internal__.device_number;
|
|
@@ -294,12 +333,12 @@ class z extends $ {
|
|
|
294
333
|
});
|
|
295
334
|
}
|
|
296
335
|
async disconnect(e = null) {
|
|
297
|
-
await this.serialDisconnect(),
|
|
336
|
+
await this.serialDisconnect(), l(this, r, y).call(this, e);
|
|
298
337
|
}
|
|
299
338
|
async connect() {
|
|
300
339
|
return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
|
|
301
340
|
V() || t("Web Serial not supported");
|
|
302
|
-
const n =
|
|
341
|
+
const n = l(this, r, $).bind(this);
|
|
303
342
|
this.on("serial:connecting", n);
|
|
304
343
|
const s = setInterval(() => {
|
|
305
344
|
this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(s), this.__internal__.serial.aux_connecting = "idle", this.off("serial:connecting", n), this.isConnected ? e(!0) : t(`${this.typeDevice} device ${this.deviceNumber} not connected`)) : this.__internal__.serial.aux_connecting === "connecting" && (this.__internal__.serial.aux_connecting = "idle", this.dispatch("serial:connecting", { active: !0 }));
|
|
@@ -390,8 +429,8 @@ class z extends $ {
|
|
|
390
429
|
}
|
|
391
430
|
async serialConnect() {
|
|
392
431
|
try {
|
|
393
|
-
|
|
394
|
-
const e = await
|
|
432
|
+
l(this, r, f).call(this, !0);
|
|
433
|
+
const e = await l(this, r, R).call(this);
|
|
395
434
|
if (e.length > 0)
|
|
396
435
|
await this.serialPortsSaved(e);
|
|
397
436
|
else {
|
|
@@ -407,21 +446,21 @@ class z extends $ {
|
|
|
407
446
|
const n = this;
|
|
408
447
|
t.onconnect = (s) => {
|
|
409
448
|
var o;
|
|
410
|
-
n.dispatch("serial:connected", s),
|
|
449
|
+
n.dispatch("serial:connected", s), l(o = n, r, f).call(o, !1), c.$dispatchChange(this), n.__internal__.serial.queue.length > 0 && n.dispatch("internal:queue", {});
|
|
411
450
|
}, t.ondisconnect = async () => {
|
|
412
451
|
await n.disconnect();
|
|
413
|
-
}, await
|
|
452
|
+
}, await U(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
414
453
|
await n.timeout(n.__internal__.serial.bytes_connection ?? [], "connection:start");
|
|
415
|
-
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await
|
|
454
|
+
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await l(this, r, v).call(this, this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
|
|
416
455
|
action: "connect",
|
|
417
456
|
bytes: this.__internal__.serial.bytes_connection
|
|
418
|
-
}), this.__internal__.auto_response &&
|
|
457
|
+
}), this.__internal__.auto_response && l(this, r, u).call(this, this.__internal__.serial.auto_response), await l(this, r, I).call(this);
|
|
419
458
|
} catch (e) {
|
|
420
|
-
|
|
459
|
+
l(this, r, f).call(this, !1), this.serialErrors(e);
|
|
421
460
|
}
|
|
422
461
|
}
|
|
423
462
|
async serialForget() {
|
|
424
|
-
return await
|
|
463
|
+
return await l(this, r, M).call(this);
|
|
425
464
|
}
|
|
426
465
|
decToHex(e) {
|
|
427
466
|
return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
|
|
@@ -493,7 +532,7 @@ class z extends $ {
|
|
|
493
532
|
});
|
|
494
533
|
}
|
|
495
534
|
softReload() {
|
|
496
|
-
|
|
535
|
+
l(this, r, H).call(this), this.dispatch("serial:soft-reload", {});
|
|
497
536
|
}
|
|
498
537
|
async sendConnect() {
|
|
499
538
|
if (!this.__internal__.serial.bytes_connection)
|
|
@@ -562,16 +601,16 @@ class z extends $ {
|
|
|
562
601
|
}
|
|
563
602
|
r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
564
603
|
return !!(i && i.readable && i.writable);
|
|
565
|
-
},
|
|
604
|
+
}, y = function(i = null) {
|
|
566
605
|
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", i), c.$dispatchChange(this);
|
|
567
|
-
},
|
|
606
|
+
}, $ = function(i) {
|
|
568
607
|
this.__internal__.serial.aux_connecting = i.detail.active ? "connecting" : "finished";
|
|
569
608
|
}, v = async function(i) {
|
|
570
609
|
const e = this.__internal__.serial.port;
|
|
571
610
|
if (!e || e && (!e.readable || !e.writable))
|
|
572
|
-
throw
|
|
611
|
+
throw l(this, r, y).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
|
|
573
612
|
const t = this.validateBytes(i);
|
|
574
|
-
if (this.useRTSCTS && await
|
|
613
|
+
if (this.useRTSCTS && await l(this, r, T).call(this, e, 5e3), e.writable === null) return;
|
|
575
614
|
const n = e.writable.getWriter();
|
|
576
615
|
await n.write(t), n.releaseLock();
|
|
577
616
|
}, T = async function(i, e = 5e3) {
|
|
@@ -581,12 +620,12 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
581
620
|
throw new Error("Timeout waiting for clearToSend signal");
|
|
582
621
|
const { clearToSend: n } = await i.getSignals();
|
|
583
622
|
if (n) return;
|
|
584
|
-
await
|
|
623
|
+
await U(100);
|
|
585
624
|
}
|
|
586
625
|
}, u = function(i = new Uint8Array([]), e = !1) {
|
|
587
626
|
if (i && i.length > 0) {
|
|
588
627
|
const t = this.__internal__.serial.connected;
|
|
589
|
-
if (this.__internal__.serial.connected =
|
|
628
|
+
if (this.__internal__.serial.connected = l(this, r, p).call(this, this.__internal__.serial.port), c.$dispatchChange(this), !t && this.__internal__.serial.connected && (this.dispatch("serial:connected"), l(this, r, f).call(this, !1)), this.__internal__.interval.reconnection && (clearInterval(this.__internal__.interval.reconnection), this.__internal__.interval.reconnection = 0), this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), this.__internal__.serial.response.as === "hex")
|
|
590
629
|
e ? this.serialCorruptMessage(this.parseUint8ToHex(i)) : this.serialMessage(this.parseUint8ToHex(i));
|
|
591
630
|
else if (this.__internal__.serial.response.as === "uint8")
|
|
592
631
|
e ? this.serialCorruptMessage(i) : this.serialMessage(i);
|
|
@@ -604,20 +643,20 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
604
643
|
}
|
|
605
644
|
}
|
|
606
645
|
this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
|
|
607
|
-
},
|
|
646
|
+
}, R = async function() {
|
|
608
647
|
const i = this.serialFilters, e = await navigator.serial.getPorts({ filters: i });
|
|
609
648
|
return i.length === 0 ? e : e.filter((t) => {
|
|
610
649
|
const n = t.getInfo();
|
|
611
650
|
return i.some((s) => n.usbProductId === s.usbProductId && n.usbVendorId === s.usbVendorId);
|
|
612
|
-
}).filter((t) => !
|
|
613
|
-
},
|
|
651
|
+
}).filter((t) => !l(this, r, p).call(this, t));
|
|
652
|
+
}, E = function(i) {
|
|
614
653
|
if (i) {
|
|
615
654
|
const e = this.__internal__.serial.response.buffer, t = new Uint8Array(e.length + i.byteLength);
|
|
616
655
|
t.set(e, 0), t.set(new Uint8Array(i), e.length), this.__internal__.serial.response.buffer = t;
|
|
617
656
|
}
|
|
618
|
-
},
|
|
657
|
+
}, S = async function() {
|
|
619
658
|
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0), this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
620
|
-
this.__internal__.serial.response.buffer &&
|
|
659
|
+
this.__internal__.serial.response.buffer && l(this, r, u).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
621
660
|
}, this.__internal__.serial.free_timeout_ms || 50);
|
|
622
661
|
}, A = async function() {
|
|
623
662
|
const i = this.__internal__.serial.response.length;
|
|
@@ -625,13 +664,13 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
625
664
|
if (this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0), !(i === null || !e || e.length === 0)) {
|
|
626
665
|
for (; e.length >= i; ) {
|
|
627
666
|
const t = e.slice(0, i);
|
|
628
|
-
|
|
667
|
+
l(this, r, u).call(this, t), e = e.slice(i);
|
|
629
668
|
}
|
|
630
669
|
this.__internal__.serial.response.buffer = e, e.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
631
|
-
|
|
670
|
+
l(this, r, u).call(this, this.__internal__.serial.response.buffer, !0);
|
|
632
671
|
}, this.__internal__.serial.free_timeout_ms || 50));
|
|
633
672
|
}
|
|
634
|
-
},
|
|
673
|
+
}, k = async function() {
|
|
635
674
|
const {
|
|
636
675
|
limiter: i,
|
|
637
676
|
prefixLimiter: e = !1,
|
|
@@ -679,12 +718,12 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
679
718
|
s = s.slice(d);
|
|
680
719
|
}
|
|
681
720
|
for (const _ of o)
|
|
682
|
-
|
|
721
|
+
l(this, r, u).call(this, _);
|
|
683
722
|
const C = new TextEncoder().encode(s);
|
|
684
723
|
this.__internal__.serial.response.buffer = C, C.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
685
|
-
|
|
724
|
+
l(this, r, u).call(this, this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
686
725
|
}, this.__internal__.serial.free_timeout_ms ?? 50));
|
|
687
|
-
},
|
|
726
|
+
}, I = async function() {
|
|
688
727
|
const i = this.__internal__.serial.port;
|
|
689
728
|
if (!i || !i.readable) throw new Error("Port is not readable");
|
|
690
729
|
const e = i.readable.getReader();
|
|
@@ -693,7 +732,7 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
693
732
|
for (; this.__internal__.serial.keep_reading; ) {
|
|
694
733
|
const { value: t, done: n } = await e.read();
|
|
695
734
|
if (n) break;
|
|
696
|
-
|
|
735
|
+
l(this, r, E).call(this, t), this.__internal__.serial.response.delimited ? await l(this, r, k).call(this) : this.__internal__.serial.response.length === null ? await l(this, r, S).call(this) : await l(this, r, A).call(this);
|
|
697
736
|
}
|
|
698
737
|
} catch (t) {
|
|
699
738
|
this.serialErrors(t);
|
|
@@ -728,17 +767,17 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
728
767
|
const i = this;
|
|
729
768
|
this.on("internal:queue", async () => {
|
|
730
769
|
var e;
|
|
731
|
-
await
|
|
732
|
-
}),
|
|
770
|
+
await l(e = i, r, D).call(e);
|
|
771
|
+
}), l(this, r, L).call(this);
|
|
733
772
|
}, L = function() {
|
|
734
773
|
const i = this;
|
|
735
774
|
navigator.serial.addEventListener("connect", async () => {
|
|
736
775
|
i.isDisconnected && await i.serialConnect().catch(() => {
|
|
737
776
|
});
|
|
738
777
|
});
|
|
739
|
-
},
|
|
740
|
-
if (!
|
|
741
|
-
|
|
778
|
+
}, D = async function() {
|
|
779
|
+
if (!l(this, r, p).call(this, this.__internal__.serial.port)) {
|
|
780
|
+
l(this, r, y).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
|
|
742
781
|
return;
|
|
743
782
|
}
|
|
744
783
|
if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
|
|
@@ -746,7 +785,7 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
746
785
|
let e = this.__internal__.time.response_general;
|
|
747
786
|
if (i.action === "connect" && (e = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
748
787
|
await this.timeout(i.bytes, i.action);
|
|
749
|
-
}, e), this.__internal__.serial.last_action = i.action ?? "unknown", await
|
|
788
|
+
}, e), this.__internal__.serial.last_action = i.action ?? "unknown", await l(this, r, v).call(this, i.bytes), this.dispatch("serial:sent", {
|
|
750
789
|
action: i.action,
|
|
751
790
|
bytes: i.bytes
|
|
752
791
|
}), this.__internal__.auto_response) {
|
|
@@ -756,7 +795,7 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
756
795
|
} catch (s) {
|
|
757
796
|
this.serialErrors(s);
|
|
758
797
|
}
|
|
759
|
-
|
|
798
|
+
l(this, r, u).call(this, n);
|
|
760
799
|
}
|
|
761
800
|
const t = [...this.__internal__.serial.queue];
|
|
762
801
|
this.__internal__.serial.queue = t.splice(1);
|
package/dist/webserial.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-CzkmE_OW.cjs"),r=require("./relay.cjs"),o=require("./locker.cjs"),i=require("./pinpad.cjs"),t=require("./pinpax.cjs"),n=require("./jofemar.cjs"),a=require("./boardroid.cjs"),s=require("./hopper.cjs"),c=require("./webserial-core-5B5nYtyR.cjs");/**
|
|
2
2
|
* @license Webserial
|
|
3
3
|
* webserial
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/const
|
|
9
|
+
*/const u={wait:e.wait,getSeconds:e.getSeconds,supportWebSerial:e.supportWebSerial},l="4.1.8";exports.Emulator=e.Emulator;exports.Kernel=e.Kernel;exports.Relay=r.Relay;exports.Locker=o.Locker;exports.PinPad=i.PinPad;exports.PinPax=t.PinPax;exports.Jofemar=n.Jofemar;exports.Boardroid=a.Boardroid;exports.Hopper=s.Hopper;exports.Devices=c.h;exports.utils=u;exports.version=l;
|
package/dist/webserial.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { s as o, g as r, w as e } from "./kernel-
|
|
2
|
-
import { E as f, K as x } from "./kernel-
|
|
1
|
+
import { s as o, g as r, w as e } from "./kernel-BblykfpT.js";
|
|
2
|
+
import { E as f, K as x } from "./kernel-BblykfpT.js";
|
|
3
3
|
import { Relay as n } from "./relay.js";
|
|
4
|
-
import { Locker as
|
|
5
|
-
import { PinPad as
|
|
4
|
+
import { Locker as l } from "./locker.js";
|
|
5
|
+
import { PinPad as P } from "./pinpad.js";
|
|
6
6
|
import { PinPax as g } from "./pinpax.js";
|
|
7
7
|
import { Jofemar as w } from "./jofemar.js";
|
|
8
8
|
import { Boardroid as K } from "./boardroid.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { h as A } from "./webserial-core-DGKQCs5a.js";
|
|
9
|
+
import { Hopper as b } from "./hopper.js";
|
|
10
|
+
import { h as k } from "./webserial-core-ByrJ7tlu.js";
|
|
12
11
|
/**
|
|
13
12
|
* @license Webserial
|
|
14
13
|
* webserial
|
|
@@ -22,17 +21,16 @@ const p = {
|
|
|
22
21
|
wait: e,
|
|
23
22
|
getSeconds: r,
|
|
24
23
|
supportWebSerial: o
|
|
25
|
-
}, a = "4.1.
|
|
24
|
+
}, a = "4.1.8";
|
|
26
25
|
export {
|
|
27
|
-
b as Arduino,
|
|
28
26
|
K as Boardroid,
|
|
29
|
-
|
|
27
|
+
k as Devices,
|
|
30
28
|
f as Emulator,
|
|
31
|
-
|
|
29
|
+
b as Hopper,
|
|
32
30
|
w as Jofemar,
|
|
33
31
|
x as Kernel,
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
l as Locker,
|
|
33
|
+
P as PinPad,
|
|
36
34
|
g as PinPax,
|
|
37
35
|
n as Relay,
|
|
38
36
|
p as utils,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danidoble/webserial",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.3",
|
|
4
4
|
"author": "danidoble",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"prettier": "^3.6.2",
|
|
22
22
|
"uuid": "^11.1.0",
|
|
23
23
|
"vite": "^6.3.5",
|
|
24
|
-
"webserial-core": "^1.0.
|
|
24
|
+
"webserial-core": "^1.0.10"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
"import": "./dist/kernel.js",
|
|
33
33
|
"require": "./dist/kernel.cjs"
|
|
34
34
|
},
|
|
35
|
-
"./arduino": {
|
|
36
|
-
"import": "./dist/arduino.js",
|
|
37
|
-
"require": "./dist/arduino.cjs"
|
|
38
|
-
},
|
|
39
35
|
"./boardroid": {
|
|
40
36
|
"import": "./dist/boardroid.js",
|
|
41
37
|
"require": "./dist/boardroid.cjs"
|
package/dist/arduino.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var c=t=>{throw TypeError(t)};var _=(t,s,n)=>s.has(t)||c("Cannot "+n);var d=(t,s,n)=>s.has(t)?c("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,n);var l=(t,s,n)=>(_(t,s,"access private method"),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./kernel-BTqvt4pt.cjs"),a=require("./relay-BsUsBpOv.cjs"),u=require("./webserial-core-DlH0cFSH.cjs");var r,h;class y extends p.Kernel{constructor({filters:n=null,config_port:o=null,no_device:i=1}={}){super({filters:n,config_port:o,no_device:i});d(this,r);if(this.__internal__.device.type="arduino",u.h.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.time.response_connection=2e3,this.__internal__.time.response_general=2e3,this.__internal__.serial.delay_first_connection=1e3,l(this,r,h).call(this),u.h.add(this),this.getResponseAsString()}serialMessage(n){const o=this.stringToArrayHex(n),i=this.stringToArrayBuffer(n),e={original_code:o,arrayBuffer:i,code:null,name:null,description:null,request:null,no_code:0};switch(e.code=n,n){case"connected":e.name="connected",e.description="Connection established",e.request="connect",e.no_code=100;break;case"created by danidoble":e.name="thanks",e.description="thanks for using this software",e.request="credits",e.no_code=101;break;case"hello there":e.name="hello there",e.description="hi human",e.request="hi",e.no_code=102;break;case"ara ara":e.name="ara ara",e.description="troll",e.request="ara ara",e.no_code=404;break;default:e.name="unknown",e.description="Unknown command",e.request="unknown",e.no_code=400;break}this.dispatch("serial:message",e)}serialSetConnectionConstant(n=1){return a.i.connection(n)}async sayCredits(){await this.appendToQueue(a.i.credits(),"credits")}async sayHi(){await this.appendToQueue(a.i.hi(),"hi")}async sayAra(){await this.appendToQueue(a.i.ara(),"ara")}async sendCustomCode({code:n=""}={}){if(typeof n!="string")throw new Error("Invalid string");await this.appendToQueue(this.parseStringToTextEncoder(n),"custom")}async doSomething(){await this.sayCredits(),await this.sayAra(),await this.sayHi()}}r=new WeakSet,h=function(){};exports.Arduino=y;
|
package/dist/arduino.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
var c = (n) => {
|
|
2
|
-
throw TypeError(n);
|
|
3
|
-
};
|
|
4
|
-
var p = (n, s, t) => s.has(n) || c("Cannot " + t);
|
|
5
|
-
var d = (n, s, t) => s.has(n) ? c("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(n) : s.set(n, t);
|
|
6
|
-
var h = (n, s, t) => (p(n, s, "access private method"), t);
|
|
7
|
-
import { K as _ } from "./kernel-lcvN8cY0.js";
|
|
8
|
-
import { i } from "./relay-Dop4mFk-.js";
|
|
9
|
-
import { h as l } from "./webserial-core-DGKQCs5a.js";
|
|
10
|
-
var r, u;
|
|
11
|
-
class f extends _ {
|
|
12
|
-
constructor({ filters: t = null, config_port: o = null, no_device: a = 1 } = {}) {
|
|
13
|
-
super({ filters: t, config_port: o, no_device: a });
|
|
14
|
-
d(this, r);
|
|
15
|
-
if (this.__internal__.device.type = "arduino", l.getCustom(this.typeDevice, a))
|
|
16
|
-
throw new Error(`Device ${this.typeDevice} ${a} already exists`);
|
|
17
|
-
this.__internal__.time.response_connection = 2e3, this.__internal__.time.response_general = 2e3, this.__internal__.serial.delay_first_connection = 1e3, h(this, r, u).call(this), l.add(this), this.getResponseAsString();
|
|
18
|
-
}
|
|
19
|
-
serialMessage(t) {
|
|
20
|
-
const o = this.stringToArrayHex(t), a = this.stringToArrayBuffer(t), e = {
|
|
21
|
-
original_code: o,
|
|
22
|
-
arrayBuffer: a,
|
|
23
|
-
code: null,
|
|
24
|
-
name: null,
|
|
25
|
-
description: null,
|
|
26
|
-
request: null,
|
|
27
|
-
no_code: 0
|
|
28
|
-
};
|
|
29
|
-
switch (e.code = t, t) {
|
|
30
|
-
case "connected":
|
|
31
|
-
e.name = "connected", e.description = "Connection established", e.request = "connect", e.no_code = 100;
|
|
32
|
-
break;
|
|
33
|
-
case "created by danidoble":
|
|
34
|
-
e.name = "thanks", e.description = "thanks for using this software", e.request = "credits", e.no_code = 101;
|
|
35
|
-
break;
|
|
36
|
-
case "hello there":
|
|
37
|
-
e.name = "hello there", e.description = "hi human", e.request = "hi", e.no_code = 102;
|
|
38
|
-
break;
|
|
39
|
-
case "ara ara":
|
|
40
|
-
e.name = "ara ara", e.description = "troll", e.request = "ara ara", e.no_code = 404;
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
e.name = "unknown", e.description = "Unknown command", e.request = "unknown", e.no_code = 400;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
this.dispatch("serial:message", e);
|
|
47
|
-
}
|
|
48
|
-
serialSetConnectionConstant(t = 1) {
|
|
49
|
-
return i.connection(t);
|
|
50
|
-
}
|
|
51
|
-
async sayCredits() {
|
|
52
|
-
await this.appendToQueue(i.credits(), "credits");
|
|
53
|
-
}
|
|
54
|
-
async sayHi() {
|
|
55
|
-
await this.appendToQueue(i.hi(), "hi");
|
|
56
|
-
}
|
|
57
|
-
async sayAra() {
|
|
58
|
-
await this.appendToQueue(i.ara(), "ara");
|
|
59
|
-
}
|
|
60
|
-
async sendCustomCode({ code: t = "" } = {}) {
|
|
61
|
-
if (typeof t != "string") throw new Error("Invalid string");
|
|
62
|
-
await this.appendToQueue(this.parseStringToTextEncoder(t), "custom");
|
|
63
|
-
}
|
|
64
|
-
async doSomething() {
|
|
65
|
-
await this.sayCredits(), await this.sayAra(), await this.sayHi();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
r = new WeakSet(), u = function() {
|
|
69
|
-
};
|
|
70
|
-
export {
|
|
71
|
-
f as Arduino
|
|
72
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";var j=Object.defineProperty,D=i=>{throw TypeError(i)},F=(i,e,t)=>e in i?j(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,y=(i,e,t)=>F(i,typeof e!="symbol"?e+"":e,t),W=(i,e,t)=>e.has(i)||D("Cannot "+t),Q=(i,e,t)=>e.has(i)?D("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),a=(i,e,t)=>(W(i,e,"access private method"),t);class x extends CustomEvent{constructor(e,t){super(e,t)}}class $ extends EventTarget{constructor(){super(...arguments),y(this,"__listeners__",{debug:!1}),y(this,"__debug__",!1)}dispatch(e,t=null){const n=new x(e,{detail:t});this.dispatchEvent(n),this.__debug__&&this.dispatchEvent(new x("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,n=100){const s=this;setTimeout(()=>{s.dispatch(e,t)},n)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.addEventListener(e,t)}off(e,t){this.removeEventListener(e,t)}serialRegisterAvailableListener(e){this.__listeners__[e]||(this.__listeners__[e]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(e=>({type:e,listening:this.__listeners__[e]}))}}const w=class l extends ${constructor(){super(),["change"].forEach(e=>{this.serialRegisterAvailableListener(e)})}static $dispatchChange(e=null){e&&e.$checkAndDispatchConnection(),l.instance.dispatch("change",{devices:l.devices,dispatcher:e})}static typeError(e){const t=new Error;throw t.message=`Type ${e} is not supported`,t.name="DeviceTypeError",t}static registerType(e){typeof l.devices[e]>"u"&&(l.devices[e]={})}static add(e){const t=e.typeDevice;typeof l.devices[t]>"u"&&(l.devices[t]={});const n=e.uuid;if(typeof l.devices[t]>"u"&&l.typeError(t),l.devices[t][n])throw new Error(`Device with id ${n} already exists`);return l.devices[t][n]=e,l.$dispatchChange(e),Object.keys(l.devices[t]).indexOf(n)}static get(e,t){return typeof l.devices[e]>"u"&&(l.devices[e]={}),typeof l.devices[e]>"u"&&l.typeError(e),l.devices[e][t]}static getAll(e=null){return e===null?l.devices:(typeof l.devices[e]>"u"&&l.typeError(e),l.devices[e])}static getList(){return Object.values(l.devices).map(e=>Object.values(e)).flat()}static getByNumber(e,t){return typeof l.devices[e]>"u"&&l.typeError(e),Object.values(l.devices[e]).find(n=>n.deviceNumber===t)??null}static getCustom(e,t=1){return typeof l.devices[e]>"u"&&l.typeError(e),Object.values(l.devices[e]).find(n=>n.deviceNumber===t)??null}};y(w,"instance"),y(w,"devices",{});let _=w;_.instance||(_.instance=new _);function k(i=100){return new Promise(e=>setTimeout(()=>e(),i))}function V(){return"serial"in navigator}const b={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};var r,p,g,R,v,T,u,I,S,E,A,B,P,f,M,q,N,L,U,O,H;class z extends ${constructor({filters:e=null,config_port:t=b,no_device:n=1,device_listen_on_channel:s=1,bypassSerialBytesConnection:o=!1}={filters:null,config_port:b,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){if(super(),Q(this,r),y(this,"__internal__",{bypassSerialBytesConnection:!1,auto_response:!1,device_number:1,aux_port_connector:0,last_error:{message:null,action:null,code:null,no_code:0},serial:{aux_connecting:"idle",connecting:!1,connected:!1,port:null,last_action:null,response:{length:null,buffer:new Uint8Array([]),as:"uint8",replacer:/[\n\r]+/g,limiter:null,prefixLimiter:!1,sufixLimiter:!0,delimited:!1},reader:null,input_done:null,output_done:null,input_stream:null,output_stream:null,keep_reading:!0,time_until_send_bytes:void 0,delay_first_connection:200,bytes_connection:null,filters:[],config_port:b,queue:[],auto_response:["DD","DD"],free_timeout_ms:50,useRTSCTS:!1},device:{type:"unknown",id:window.crypto.randomUUID(),listen_on_port:null},time:{response_connection:500,response_general:2e3},timeout:{until_response:0},interval:{reconnection:0}}),!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),o&&(this.__internal__.bypassSerialBytesConnection=o),n&&a(this,r,O).call(this,n),s&&["number","string"].includes(typeof s)&&(this.listenOnChannel=s),a(this,r,q).call(this),a(this,r,N).call(this)}set listenOnChannel(e){if(typeof e=="string"&&(e=parseInt(e)),isNaN(e)||e<1||e>255)throw new Error("Invalid port number");this.__internal__.device.listen_on_port=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))}get lastAction(){return this.__internal__.serial.last_action}get listenOnChannel(){return this.__internal__.device.listen_on_port??1}set serialFilters(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.filters=e}get serialFilters(){return this.__internal__.serial.filters}set serialConfigPort(e){if(this.isConnected)throw new Error("Cannot change serial filters while connected");this.__internal__.serial.config_port=e}get serialConfigPort(){return this.__internal__.serial.config_port}get useRTSCTS(){return this.__internal__.serial.useRTSCTS}set useRTSCTS(e){this.__internal__.serial.useRTSCTS=e}get isConnected(){const e=this.__internal__.serial.connected,t=a(this,r,p).call(this,this.__internal__.serial.port);return e&&!t&&a(this,r,g).call(this,{error:"Port is closed, not readable or writable."}),this.__internal__.serial.connected=t,this.__internal__.serial.connected}get isConnecting(){return this.__internal__.serial.connecting}get isDisconnected(){const e=this.__internal__.serial.connected,t=a(this,r,p).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),a(this,r,f).call(this,!1),_.$dispatchChange(this)),this.__internal__.serial.connected=t,!this.__internal__.serial.connected}get deviceNumber(){return this.__internal__.device_number}get uuid(){return this.__internal__.device.id}get typeDevice(){return this.__internal__.device.type}get queue(){return this.__internal__.serial.queue}get responseDelimited(){return this.__internal__.serial.response.delimited}set responseDelimited(e){if(typeof e!="boolean")throw new Error("responseDelimited must be a boolean");this.__internal__.serial.response.delimited=e}get responsePrefixLimited(){return this.__internal__.serial.response.prefixLimiter}set responsePrefixLimited(e){if(typeof e!="boolean")throw new Error("responsePrefixLimited must be a boolean");this.__internal__.serial.response.prefixLimiter=e}get responseSufixLimited(){return this.__internal__.serial.response.sufixLimiter}set responseSufixLimited(e){if(typeof e!="boolean")throw new Error("responseSufixLimited must be a boolean");this.__internal__.serial.response.sufixLimiter=e}get responseLimiter(){return this.__internal__.serial.response.limiter}set responseLimiter(e){if(typeof e!="string"&&!(e instanceof RegExp))throw new Error("responseLimiter must be a string or a RegExp");this.__internal__.serial.response.limiter=e}get fixedBytesMessage(){return this.__internal__.serial.response.length}set fixedBytesMessage(e){if(e!==null&&(typeof e!="number"||e<1))throw new Error("Invalid length for fixed bytes message");this.__internal__.serial.response.length=e}get timeoutBeforeResponseBytes(){return this.__internal__.serial.free_timeout_ms||50}set timeoutBeforeResponseBytes(e){if(e!==void 0&&(typeof e!="number"||e<1))throw new Error("Invalid timeout for response bytes");this.__internal__.serial.free_timeout_ms=e??50}get bypassSerialBytesConnection(){return this.__internal__.bypassSerialBytesConnection}set bypassSerialBytesConnection(e){if(typeof e!="boolean")throw new Error("bypassSerialBytesConnection must be a boolean");this.__internal__.bypassSerialBytesConnection=e}async timeout(e,t){this.__internal__.last_error.message="Operation response timed out.",this.__internal__.last_error.action=t,this.__internal__.last_error.code=e,this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),t==="connect"?(this.__internal__.serial.connected=!1,this.dispatch("serial:reconnect",{}),_.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,_.$dispatchChange(this),await this.serialConnect()),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),a(this,r,g).call(this,e)}async connect(){return this.isConnected?!0:(this.__internal__.serial.aux_connecting="idle",new Promise((e,t)=>{V()||t("Web Serial not supported");const n=a(this,r,R).bind(this);this.on("serial:connecting",n);const s=setInterval(()=>{this.__internal__.serial.aux_connecting==="finished"?(clearInterval(s),this.__internal__.serial.aux_connecting="idle",this.off("serial:connecting",n),this.isConnected?e(!0):t(`${this.typeDevice} device ${this.deviceNumber} not connected`)):this.__internal__.serial.aux_connecting==="connecting"&&(this.__internal__.serial.aux_connecting="idle",this.dispatch("serial:connecting",{active:!0}))},100);this.serialConnect()}))}async serialDisconnect(){try{const e=this.__internal__.serial.reader,t=this.__internal__.serial.output_stream;e&&(await e.cancel().catch(n=>this.serialErrors(n)),await this.__internal__.serial.input_done),t&&(await t.getWriter().close(),await this.__internal__.serial.output_done),this.__internal__.serial.connected&&this.__internal__.serial&&this.__internal__.serial.port&&await this.__internal__.serial.port.close()}catch(e){this.serialErrors(e)}finally{this.__internal__.serial.reader=null,this.__internal__.serial.input_done=null,this.__internal__.serial.output_stream=null,this.__internal__.serial.output_done=null,this.__internal__.serial.connected=!1,this.__internal__.serial.port=null,_.$dispatchChange(this)}}getResponseAsArrayBuffer(){this.__internal__.serial.response.as="arraybuffer"}getResponseAsArrayHex(){this.__internal__.serial.response.as="hex"}getResponseAsUint8Array(){this.__internal__.serial.response.as="uint8"}getResponseAsString(){this.__internal__.serial.response.as="string"}async serialPortsSaved(e){const t=this.serialFilters;if(this.__internal__.aux_port_connector<e.length){const n=this.__internal__.aux_port_connector;this.__internal__.serial.port=e[n]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:t});if(!this.__internal__.serial.port)throw new Error("Select another port please")}serialErrors(e){const t=e.toString().toLowerCase();switch(!0){case t.includes("must be handling a user gesture to show a permission request"):case t.includes("the port is closed."):case t.includes("the port is closed or is not writable"):case t.includes("the port is closed or is not readable"):case t.includes("the port is closed or is not readable/writable"):case t.includes("select another port please"):case t.includes("no port selected by the user"):case t.includes("this readable stream reader has been released and cannot be used to cancel its previous owner stream"):this.dispatch("serial:need-permission",{}),_.$dispatchChange(this);break;case t.includes("the port is already open."):case t.includes("failed to open serial port"):this.serialDisconnect().then(async()=>{this.__internal__.aux_port_connector+=1,await this.serialConnect()});break;case t.includes("cannot read properties of undefined (reading 'writable')"):case t.includes("cannot read properties of null (reading 'writable')"):case t.includes("cannot read property 'writable' of null"):case t.includes("cannot read property 'writable' of undefined"):this.serialDisconnect().then(async()=>{await this.serialConnect()});break;case t.includes("'close' on 'serialport': a call to close() is already in progress."):break;case t.includes("failed to execute 'open' on 'serialport': a call to open() is already in progress."):break;case t.includes("the port is already closed."):break;case t.includes("the device has been lost"):this.dispatch("serial:lost",{}),_.$dispatchChange(this);break;case t.includes("navigator.serial is undefined"):this.dispatch("serial:unsupported",{});break;default:console.error(e);break}this.dispatch("serial:error",e)}async serialConnect(){try{a(this,r,f).call(this,!0);const e=await a(this,r,I).call(this);if(e.length>0)await this.serialPortsSaved(e);else{const s=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:s})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const n=this;t.onconnect=s=>{var o;n.dispatch("serial:connected",s),a(o=n,r,f).call(o,!1),_.$dispatchChange(this),n.__internal__.serial.queue.length>0&&n.dispatch("internal:queue",{})},t.ondisconnect=async()=>{await n.disconnect()},await k(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await n.timeout(n.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await a(this,r,v).call(this,this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&a(this,r,u).call(this,this.__internal__.serial.auto_response),await a(this,r,P).call(this)}catch(e){a(this,r,f).call(this,!1),this.serialErrors(e)}}async serialForget(){return await a(this,r,M).call(this)}decToHex(e){return typeof e=="string"&&(e=parseInt(e,10)),e.toString(16)}hexToDec(e){return parseInt(e,16)}hexMaker(e="00",t=2){return e.toString().padStart(t,"0").toLowerCase()}add0x(e){const t=[];return e.forEach((n,s)=>{t[s]="0x"+n}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}validateBytes(e){let t=new Uint8Array(0);if(e instanceof Uint8Array)t=e;else if(typeof e=="string")t=this.parseStringToTextEncoder(e);else if(Array.isArray(e)&&typeof e[0]=="string")t=this.stringArrayToUint8Array(e);else if(Array.isArray(e)&&typeof e[0]=="number")t=new Uint8Array(e);else throw new Error("Invalid data type");return t}async appendToQueue(e,t){const n=this.validateBytes(e);if(["connect","connection:start"].includes(t)){if(this.__internal__.serial.connected)return;await this.serialConnect();return}this.__internal__.serial.queue.push({bytes:n,action:t}),this.dispatch("internal:queue",{})}serialSetConnectionConstant(e=1){if(this.__internal__.bypassSerialBytesConnection)return this.__internal__.serial.bytes_connection;throw new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${e}`)}serialMessage(e){throw console.log(e),this.dispatch("serial:message",{code:e}),new Error("Method not implemented 'serialMessage'")}serialCorruptMessage(e){throw console.log(e),this.dispatch("serial:corrupt-message",{code:e}),new Error("Method not implemented 'serialCorruptMessage'")}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(e){let t=0;return e.forEach(n=>{t+=parseInt(n,16)}),t.toString(16)}toString(){return JSON.stringify({__class:this.typeDevice,device_number:this.deviceNumber,uuid:this.uuid,connected:this.isConnected,connection:this.__internal__.serial.bytes_connection})}softReload(){a(this,r,H).call(this),this.dispatch("serial:soft-reload",{})}async sendConnect(){if(!this.__internal__.serial.bytes_connection)throw new Error("No connection bytes defined");await this.appendToQueue(this.__internal__.serial.bytes_connection,"connect")}async sendCustomCode({code:e=[]}={code:[]}){if(!e)throw new Error("No data to send");this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.validateBytes(e)),await this.appendToQueue(e,"custom")}stringToArrayHex(e){return Array.from(e).map(t=>t.charCodeAt(0).toString(16))}stringToArrayBuffer(e,t=`
|
|
2
|
-
`){return this.parseStringToTextEncoder(e,t).buffer}parseStringToTextEncoder(e="",t=`
|
|
3
|
-
`){const n=new TextEncoder;return e+=t,n.encode(e)}parseStringToBytes(e="",t=`
|
|
4
|
-
`){const n=this.parseStringToTextEncoder(e,t);return Array.from(n).map(s=>s.toString(16))}parseUint8ToHex(e){return Array.from(e).map(t=>t.toString(16))}parseHexToUint8(e){return new Uint8Array(e.map(t=>parseInt(t,16)))}stringArrayToUint8Array(e){const t=[];return typeof e=="string"?this.parseStringToTextEncoder(e).buffer:(e.forEach(n=>{const s=n.replace("0x","");t.push(parseInt(s,16))}),new Uint8Array(t))}parseUint8ArrayToString(e){let t=new Uint8Array(0);e instanceof Uint8Array?t=e:t=this.stringArrayToUint8Array(e),e=this.parseUint8ToHex(t);const n=e.map(s=>parseInt(s,16));return this.__internal__.serial.response.replacer?String.fromCharCode(...n).replace(this.__internal__.serial.response.replacer,""):String.fromCharCode(...n)}hexToAscii(e){const t=e.toString();let n="";for(let s=0;s<t.length;s+=2)n+=String.fromCharCode(parseInt(t.substring(s,2),16));return n}asciiToHex(e){const t=[];for(let n=0,s=e.length;n<s;n++){const o=Number(e.charCodeAt(n)).toString(16);t.push(o)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}r=new WeakSet,p=function(i){return!!(i&&i.readable&&i.writable)},g=function(i=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",i),_.$dispatchChange(this)},R=function(i){this.__internal__.serial.aux_connecting=i.detail.active?"connecting":"finished"},v=async function(i){const e=this.__internal__.serial.port;if(!e||e&&(!e.readable||!e.writable))throw a(this,r,g).call(this,{error:"Port is closed, not readable or writable."}),new Error("The port is closed or is not readable/writable");const t=this.validateBytes(i);if(this.useRTSCTS&&await a(this,r,T).call(this,e,5e3),e.writable===null)return;const n=e.writable.getWriter();await n.write(t),n.releaseLock()},T=async function(i,e=5e3){const t=Date.now();for(;;){if(Date.now()-t>e)throw new Error("Timeout waiting for clearToSend signal");const{clearToSend:n}=await i.getSignals();if(n)return;await k(100)}},u=function(i=new Uint8Array([]),e=!1){if(i&&i.length>0){const t=this.__internal__.serial.connected;if(this.__internal__.serial.connected=a(this,r,p).call(this,this.__internal__.serial.port),_.$dispatchChange(this),!t&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),a(this,r,f).call(this,!1)),this.__internal__.interval.reconnection&&(clearInterval(this.__internal__.interval.reconnection),this.__internal__.interval.reconnection=0),this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),this.__internal__.serial.response.as==="hex")e?this.serialCorruptMessage(this.parseUint8ToHex(i)):this.serialMessage(this.parseUint8ToHex(i));else if(this.__internal__.serial.response.as==="uint8")e?this.serialCorruptMessage(i):this.serialMessage(i);else if(this.__internal__.serial.response.as==="string"){const n=this.parseUint8ArrayToString(i);if(this.__internal__.serial.response.limiter!==null){const s=n.split(this.__internal__.serial.response.limiter);for(const o in s)s[o]&&(e?this.serialCorruptMessage(s[o]):this.serialMessage(s[o]))}else e?this.serialCorruptMessage(n):this.serialMessage(n)}else{const n=this.stringToArrayBuffer(this.parseUint8ArrayToString(i));e?this.serialCorruptMessage(n):this.serialMessage(n)}}this.__internal__.serial.queue.length!==0&&this.dispatch("internal:queue",{})},I=async function(){const i=this.serialFilters,e=await navigator.serial.getPorts({filters:i});return i.length===0?e:e.filter(t=>{const n=t.getInfo();return i.some(s=>n.usbProductId===s.usbProductId&&n.usbVendorId===s.usbVendorId)}).filter(t=>!a(this,r,p).call(this,t))},S=function(i){if(i){const e=this.__internal__.serial.response.buffer,t=new Uint8Array(e.length+i.byteLength);t.set(e,0),t.set(new Uint8Array(i),e.length),this.__internal__.serial.response.buffer=t}},E=async function(){this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0),this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.__internal__.serial.response.buffer&&a(this,r,u).call(this,this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)},A=async function(){const i=this.__internal__.serial.response.length;let e=this.__internal__.serial.response.buffer;if(this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0),!(i===null||!e||e.length===0)){for(;e.length>=i;){const t=e.slice(0,i);a(this,r,u).call(this,t),e=e.slice(i)}this.__internal__.serial.response.buffer=e,e.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{a(this,r,u).call(this,this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}},B=async function(){const{limiter:i,prefixLimiter:e=!1,sufixLimiter:t=!0}=this.__internal__.serial.response;if(!i)throw new Error("No limiter defined for delimited serial response");const n=this.__internal__.serial.response.buffer;if(!i||!n||n.length===0)return;this.__internal__.serial.time_until_send_bytes&&(clearTimeout(this.__internal__.serial.time_until_send_bytes),this.__internal__.serial.time_until_send_bytes=0);let s=new TextDecoder().decode(n);const o=[];if(typeof i=="string"){let c;if(e&&t)c=new RegExp(`${i}([^${i}]+)${i}`,"g");else if(e)c=new RegExp(`${i}([^${i}]*)`,"g");else if(t)c=new RegExp(`([^${i}]+)${i}`,"g");else return;let d,h=0;for(;(d=c.exec(s))!==null;)o.push(new TextEncoder().encode(d[1])),h=c.lastIndex;s=s.slice(h)}else if(i instanceof RegExp){let c,d=0;if(e&&t){const h=new RegExp(`${i.source}(.*?)${i.source}`,"g");for(;(c=h.exec(s))!==null;)o.push(new TextEncoder().encode(c[1])),d=h.lastIndex}else if(t)for(;(c=i.exec(s))!==null;){const h=c.index,m=s.slice(d,h);o.push(new TextEncoder().encode(m)),d=i.lastIndex}else if(e){const h=s.split(i);h.shift();for(const m of h)o.push(new TextEncoder().encode(m));s=""}s=s.slice(d)}for(const c of o)a(this,r,u).call(this,c);const C=new TextEncoder().encode(s);this.__internal__.serial.response.buffer=C,C.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{a(this,r,u).call(this,this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))},P=async function(){const i=this.__internal__.serial.port;if(!i||!i.readable)throw new Error("Port is not readable");const e=i.readable.getReader();this.__internal__.serial.reader=e;try{for(;this.__internal__.serial.keep_reading;){const{value:t,done:n}=await e.read();if(n)break;a(this,r,S).call(this,t),this.__internal__.serial.response.delimited?await a(this,r,B).call(this):this.__internal__.serial.response.length===null?await a(this,r,E).call(this):await a(this,r,A).call(this)}}catch(t){this.serialErrors(t)}finally{e.releaseLock(),this.__internal__.serial.keep_reading=!0,this.__internal__.serial.port&&await this.__internal__.serial.port.close()}},f=function(i){i!==this.__internal__.serial.connecting&&(this.__internal__.serial.connecting=i,i?this.dispatch("serial:connecting",{active:!0}):this.dispatch("serial:connecting",{active:!1}))},M=async function(){return typeof window>"u"?!1:"serial"in navigator&&"forget"in SerialPort.prototype&&this.__internal__.serial.port?(await this.__internal__.serial.port.forget(),!0):!1},q=function(){["serial:connected","serial:connecting","serial:reconnect","serial:timeout","serial:disconnected","serial:sent","serial:soft-reload","serial:message","serial:corrupt-message","unknown","serial:need-permission","serial:lost","serial:unsupported","serial:error","debug"].forEach(i=>{this.serialRegisterAvailableListener(i)})},N=function(){const i=this;this.on("internal:queue",async()=>{var e;await a(e=i,r,U).call(e)}),a(this,r,L).call(this)},L=function(){const i=this;navigator.serial.addEventListener("connect",async()=>{i.isDisconnected&&await i.serialConnect().catch(()=>{})})},U=async function(){if(!a(this,r,p).call(this,this.__internal__.serial.port)){a(this,r,g).call(this,{error:"Port is closed, not readable or writable."}),await this.serialConnect();return}if(this.__internal__.timeout.until_response||this.__internal__.serial.queue.length===0)return;const i=this.__internal__.serial.queue[0];let e=this.__internal__.time.response_general;if(i.action==="connect"&&(e=this.__internal__.time.response_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(i.bytes,i.action)},e),this.__internal__.serial.last_action=i.action??"unknown",await a(this,r,v).call(this,i.bytes),this.dispatch("serial:sent",{action:i.action,bytes:i.bytes}),this.__internal__.auto_response){let n=new Uint8Array(0);try{n=this.validateBytes(this.__internal__.serial.auto_response)}catch(s){this.serialErrors(s)}a(this,r,u).call(this,n)}const t=[...this.__internal__.serial.queue];this.__internal__.serial.queue=t.splice(1)},O=function(i=1){this.__internal__.device_number=i,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(i))},H=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}};exports.K=z;exports.h=_;
|