@danidoble/webserial 4.4.4 → 4.4.6

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.
@@ -36,9 +36,9 @@ for (let n = 0; n < X.length; n++)
36
36
  const ye = (n) => {
37
37
  let e = n.length * 0.75, t = n.length, s, i = 0, r, o, l, c;
38
38
  n[n.length - 1] === "=" && (e--, n[n.length - 2] === "=" && e--);
39
- const f = new ArrayBuffer(e), u = new Uint8Array(f);
39
+ const f = new ArrayBuffer(e), _ = new Uint8Array(f);
40
40
  for (s = 0; s < t; s += 4)
41
- r = C[n.charCodeAt(s)], o = C[n.charCodeAt(s + 1)], l = C[n.charCodeAt(s + 2)], c = C[n.charCodeAt(s + 3)], u[i++] = r << 2 | o >> 4, u[i++] = (o & 15) << 4 | l >> 2, u[i++] = (l & 3) << 6 | c & 63;
41
+ r = C[n.charCodeAt(s)], o = C[n.charCodeAt(s + 1)], l = C[n.charCodeAt(s + 2)], c = C[n.charCodeAt(s + 3)], _[i++] = r << 2 | o >> 4, _[i++] = (o & 15) << 4 | l >> 2, _[i++] = (l & 3) << 6 | c & 63;
42
42
  return f;
43
43
  }, ge = typeof ArrayBuffer == "function", W = (n, e) => {
44
44
  if (typeof n != "string")
@@ -62,15 +62,7 @@ const ye = (n) => {
62
62
  return ie(t, e);
63
63
  } else
64
64
  return { base64: !0, data: n };
65
- }, ie = (n, e) => {
66
- switch (e) {
67
- case "blob":
68
- return n instanceof Blob ? n : new Blob([n]);
69
- case "arraybuffer":
70
- default:
71
- return n instanceof ArrayBuffer ? n : n.buffer;
72
- }
73
- }, re = "", we = (n, e) => {
65
+ }, ie = (n, e) => e === "blob" ? n instanceof Blob ? n : new Blob([n]) : n instanceof ArrayBuffer ? n : n.buffer, re = "", be = (n, e) => {
74
66
  const t = n.length, s = new Array(t);
75
67
  let i = 0;
76
68
  n.forEach((r, o) => {
@@ -78,7 +70,7 @@ const ye = (n) => {
78
70
  s[o] = l, ++i === t && e(s.join(re));
79
71
  });
80
72
  });
81
- }, be = (n, e) => {
73
+ }, we = (n, e) => {
82
74
  const t = n.split(re), s = [];
83
75
  for (let i = 0; i < t.length; i++) {
84
76
  const r = W(t[i], e);
@@ -142,12 +134,12 @@ function Ee(n, e) {
142
134
  } else if (s === 2) {
143
135
  if (T(t) < 8)
144
136
  break;
145
- const c = A(t, 8), f = new DataView(c.buffer, c.byteOffset, c.length), u = f.getUint32(0);
146
- if (u > Math.pow(2, 21) - 1) {
137
+ const c = A(t, 8), f = new DataView(c.buffer, c.byteOffset, c.length), _ = f.getUint32(0);
138
+ if (_ > Math.pow(2, 21) - 1) {
147
139
  l.enqueue(q);
148
140
  break;
149
141
  }
150
- i = u * Math.pow(2, 32) + f.getUint32(4), s = 3;
142
+ i = _ * Math.pow(2, 32) + f.getUint32(4), s = 3;
151
143
  } else {
152
144
  if (T(t) < i)
153
145
  break;
@@ -163,24 +155,24 @@ function Ee(n, e) {
163
155
  });
164
156
  }
165
157
  const oe = 4;
166
- function _(n) {
158
+ function u(n) {
167
159
  if (n) return ke(n);
168
160
  }
169
161
  function ke(n) {
170
- for (var e in _.prototype)
171
- n[e] = _.prototype[e];
162
+ for (var e in u.prototype)
163
+ n[e] = u.prototype[e];
172
164
  return n;
173
165
  }
174
- _.prototype.on = _.prototype.addEventListener = function(n, e) {
166
+ u.prototype.on = u.prototype.addEventListener = function(n, e) {
175
167
  return this._callbacks = this._callbacks || {}, (this._callbacks["$" + n] = this._callbacks["$" + n] || []).push(e), this;
176
168
  };
177
- _.prototype.once = function(n, e) {
169
+ u.prototype.once = function(n, e) {
178
170
  function t() {
179
171
  this.off(n, t), e.apply(this, arguments);
180
172
  }
181
173
  return t.fn = e, this.on(n, t), this;
182
174
  };
183
- _.prototype.off = _.prototype.removeListener = _.prototype.removeAllListeners = _.prototype.removeEventListener = function(n, e) {
175
+ u.prototype.off = u.prototype.removeListener = u.prototype.removeAllListeners = u.prototype.removeEventListener = function(n, e) {
184
176
  if (this._callbacks = this._callbacks || {}, arguments.length == 0)
185
177
  return this._callbacks = {}, this;
186
178
  var t = this._callbacks["$" + n];
@@ -194,7 +186,7 @@ _.prototype.off = _.prototype.removeListener = _.prototype.removeAllListeners =
194
186
  }
195
187
  return t.length === 0 && delete this._callbacks["$" + n], this;
196
188
  };
197
- _.prototype.emit = function(n) {
189
+ u.prototype.emit = function(n) {
198
190
  this._callbacks = this._callbacks || {};
199
191
  for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + n], s = 1; s < arguments.length; s++)
200
192
  e[s - 1] = arguments[s];
@@ -205,11 +197,11 @@ _.prototype.emit = function(n) {
205
197
  }
206
198
  return this;
207
199
  };
208
- _.prototype.emitReserved = _.prototype.emit;
209
- _.prototype.listeners = function(n) {
200
+ u.prototype.emitReserved = u.prototype.emit;
201
+ u.prototype.listeners = function(n) {
210
202
  return this._callbacks = this._callbacks || {}, this._callbacks["$" + n] || [];
211
203
  };
212
- _.prototype.hasListeners = function(n) {
204
+ u.prototype.hasListeners = function(n) {
213
205
  return !!this.listeners(n).length;
214
206
  };
215
207
  const O = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), p = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Ce = "arraybuffer";
@@ -252,7 +244,7 @@ class Le extends Error {
252
244
  super(e), this.description = t, this.context = s, this.type = "TransportError";
253
245
  }
254
246
  }
255
- class K extends _ {
247
+ class K extends u {
256
248
  /**
257
249
  * Transport abstract constructor.
258
250
  *
@@ -406,7 +398,7 @@ class Pe extends K {
406
398
  return this.onClose({ description: "transport closed by the server" }), !1;
407
399
  this.onPacket(s);
408
400
  };
409
- be(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
401
+ we(e, this.socket.binaryType).forEach(t), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
410
402
  }
411
403
  /**
412
404
  * For polling, send a close packet.
@@ -426,7 +418,7 @@ class Pe extends K {
426
418
  * @protected
427
419
  */
428
420
  write(e) {
429
- this.writable = !1, we(e, (t) => {
421
+ this.writable = !1, be(e, (t) => {
430
422
  this.doWrite(t, () => {
431
423
  this.writable = !0, this.emitReserved("drain");
432
424
  });
@@ -492,7 +484,7 @@ class De extends Pe {
492
484
  }), this.pollXhr = e;
493
485
  }
494
486
  }
495
- class g extends _ {
487
+ class g extends u {
496
488
  /**
497
489
  * Request constructor
498
490
  *
@@ -632,13 +624,13 @@ function he(n) {
632
624
  } catch {
633
625
  }
634
626
  }
635
- const ue = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
627
+ const _e = typeof navigator < "u" && typeof navigator.product == "string" && navigator.product.toLowerCase() === "reactnative";
636
628
  class Me extends K {
637
629
  get name() {
638
630
  return "websocket";
639
631
  }
640
632
  doOpen() {
641
- const e = this.uri(), t = this.opts.protocols, s = ue ? {} : ae(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
633
+ const e = this.uri(), t = this.opts.protocols, s = _e ? {} : ae(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
642
634
  this.opts.extraHeaders && (s.headers = this.opts.extraHeaders);
643
635
  try {
644
636
  this.ws = this.createSocket(e, t, s);
@@ -692,7 +684,7 @@ class Me extends K {
692
684
  const I = p.WebSocket || p.MozWebSocket;
693
685
  class Fe extends Me {
694
686
  createSocket(e, t, s) {
695
- return ue ? new I(e, t, s) : t ? new I(e, t) : new I(e);
687
+ return _e ? new I(e, t, s) : t ? new I(e, t) : new I(e);
696
688
  }
697
689
  doWrite(e, t) {
698
690
  this.ws.send(t);
@@ -788,7 +780,7 @@ const M = typeof addEventListener == "function" && typeof removeEventListener ==
788
780
  M && addEventListener("offline", () => {
789
781
  x.forEach((n) => n());
790
782
  }, !1);
791
- class b extends _ {
783
+ class w extends u {
792
784
  /**
793
785
  * Socket constructor.
794
786
  *
@@ -856,7 +848,7 @@ class b extends _ {
856
848
  }, 0);
857
849
  return;
858
850
  }
859
- const e = this.opts.rememberUpgrade && b.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
851
+ const e = this.opts.rememberUpgrade && w.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
860
852
  this.readyState = "opening";
861
853
  const t = this.createTransport(e);
862
854
  t.open(), this.setTransport(t);
@@ -875,7 +867,7 @@ class b extends _ {
875
867
  * @private
876
868
  */
877
869
  onOpen() {
878
- this.readyState = "open", b.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
870
+ this.readyState = "open", w.priorWebsocketSuccess = this.transport.name === "websocket", this.emitReserved("open"), this.flush();
879
871
  }
880
872
  /**
881
873
  * Handles a packet.
@@ -1039,7 +1031,7 @@ class b extends _ {
1039
1031
  * @private
1040
1032
  */
1041
1033
  _onError(e) {
1042
- if (b.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening")
1034
+ if (w.priorWebsocketSuccess = !1, this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening")
1043
1035
  return this.transports.shift(), this._open();
1044
1036
  this.emitReserved("error", e), this._onClose("transport error", e);
1045
1037
  }
@@ -1058,8 +1050,8 @@ class b extends _ {
1058
1050
  }
1059
1051
  }
1060
1052
  }
1061
- b.protocol = oe;
1062
- class Ye extends b {
1053
+ w.protocol = oe;
1054
+ class Ye extends w {
1063
1055
  constructor() {
1064
1056
  super(...arguments), this._upgrades = [];
1065
1057
  }
@@ -1076,15 +1068,15 @@ class Ye extends b {
1076
1068
  */
1077
1069
  _probe(e) {
1078
1070
  let t = this.createTransport(e), s = !1;
1079
- b.priorWebsocketSuccess = !1;
1071
+ w.priorWebsocketSuccess = !1;
1080
1072
  const i = () => {
1081
1073
  s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (d) => {
1082
1074
  if (!s)
1083
1075
  if (d.type === "pong" && d.data === "probe") {
1084
1076
  if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
1085
1077
  return;
1086
- b.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1087
- s || this.readyState !== "closed" && (u(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
1078
+ w.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1079
+ s || this.readyState !== "closed" && (_(), this.setTransport(t), t.send([{ type: "upgrade" }]), this.emitReserved("upgrade", t), t = null, this.upgrading = !1, this.flush());
1088
1080
  });
1089
1081
  } else {
1090
1082
  const E = new Error("probe error");
@@ -1093,7 +1085,7 @@ class Ye extends b {
1093
1085
  }));
1094
1086
  };
1095
1087
  function r() {
1096
- s || (s = !0, u(), t.close(), t = null);
1088
+ s || (s = !0, _(), t.close(), t = null);
1097
1089
  }
1098
1090
  const o = (d) => {
1099
1091
  const E = new Error("probe error: " + d);
@@ -1108,7 +1100,7 @@ class Ye extends b {
1108
1100
  function f(d) {
1109
1101
  t && d.name !== t.name && r();
1110
1102
  }
1111
- const u = () => {
1103
+ const _ = () => {
1112
1104
  t.removeListener("open", i), t.removeListener("error", o), t.removeListener("close", l), this.off("close", c), this.off("upgrading", f);
1113
1105
  };
1114
1106
  t.once("open", i), t.once("error", o), t.once("close", l), this.once("close", c), this.once("upgrading", f), this._upgrades.indexOf("webtransport") !== -1 && e !== "webtransport" ? this.setTimeoutFn(() => {
@@ -1143,7 +1135,7 @@ function Qe(n, e = "", t) {
1143
1135
  const r = s.host.indexOf(":") !== -1 ? "[" + s.host + "]" : s.host;
1144
1136
  return s.id = s.protocol + "://" + r + ":" + s.port + e, s.href = s.protocol + "://" + r + (t && t.port === s.port ? "" : ":" + s.port), s;
1145
1137
  }
1146
- const Xe = typeof ArrayBuffer == "function", je = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n.buffer instanceof ArrayBuffer, _e = Object.prototype.toString, Ge = typeof Blob == "function" || typeof Blob < "u" && _e.call(Blob) === "[object BlobConstructor]", Ze = typeof File == "function" || typeof File < "u" && _e.call(File) === "[object FileConstructor]";
1138
+ const Xe = typeof ArrayBuffer == "function", je = (n) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(n) : n.buffer instanceof ArrayBuffer, ue = Object.prototype.toString, Ge = typeof Blob == "function" || typeof Blob < "u" && ue.call(Blob) === "[object BlobConstructor]", Ze = typeof File == "function" || typeof File < "u" && ue.call(File) === "[object FileConstructor]";
1147
1139
  function z(n) {
1148
1140
  return Xe && (n instanceof ArrayBuffer || je(n)) || Ge && n instanceof Blob || Ze && n instanceof File;
1149
1141
  }
@@ -1262,7 +1254,7 @@ class it {
1262
1254
  function G(n) {
1263
1255
  return Object.prototype.toString.call(n) === "[object Object]";
1264
1256
  }
1265
- class Y extends _ {
1257
+ class Y extends u {
1266
1258
  /**
1267
1259
  * Decoder constructor
1268
1260
  *
@@ -1423,7 +1415,7 @@ const at = Object.freeze({
1423
1415
  newListener: 1,
1424
1416
  removeListener: 1
1425
1417
  });
1426
- class fe extends _ {
1418
+ class fe extends u {
1427
1419
  /**
1428
1420
  * `Socket` constructor.
1429
1421
  */
@@ -1548,8 +1540,8 @@ class fe extends _ {
1548
1540
  data: t
1549
1541
  };
1550
1542
  if (o.options = {}, o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
1551
- const u = this.ids++, d = t.pop();
1552
- this._registerAckCallback(u, d), o.id = u;
1543
+ const _ = this.ids++, d = t.pop();
1544
+ this._registerAckCallback(_, d), o.id = _;
1553
1545
  }
1554
1546
  const l = (i = (s = this.io.engine) === null || s === void 0 ? void 0 : s.transport) === null || i === void 0 ? void 0 : i.writable, c = this.connected && !(!((r = this.io.engine) === null || r === void 0) && r._hasPingExpired());
1555
1547
  return this.flags.volatile && !l || (c ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
@@ -2038,7 +2030,7 @@ v.prototype.setMax = function(n) {
2038
2030
  v.prototype.setJitter = function(n) {
2039
2031
  this.jitter = n;
2040
2032
  };
2041
- class V extends _ {
2033
+ class V extends u {
2042
2034
  constructor(e, t) {
2043
2035
  var s;
2044
2036
  super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t = t || {}, t.path = t.path || "/socket.io", this.opts = t, L(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || 1 / 0), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor((s = t.randomizationFactor) !== null && s !== void 0 ? s : 0.5), this.backoff = new v({
@@ -2503,16 +2495,16 @@ function ee(n = 100) {
2503
2495
  );
2504
2496
  }
2505
2497
  class ct {
2506
- #s = "http://localhost:3000";
2507
- #n = {
2498
+ #n = "http://localhost:3001";
2499
+ #t = {
2508
2500
  transports: ["websocket"]
2509
2501
  };
2510
2502
  #e = null;
2511
2503
  #i = !1;
2512
- #a = !1;
2513
- #t;
2514
- constructor() {
2515
- this.#t = {
2504
+ #o = !1;
2505
+ #s;
2506
+ constructor(e, t) {
2507
+ e && (this.#n = e), t && (this.#t = { ...this.#t, ...t }), this.#s = {
2516
2508
  onResponse: this.onResponse.bind(this),
2517
2509
  onDisconnect: () => {
2518
2510
  this.#i = !1, window.dispatchEvent(new Event("serial:socket:disconnected"));
@@ -2520,8 +2512,8 @@ class ct {
2520
2512
  onConnect: () => {
2521
2513
  this.#i = !0, window.dispatchEvent(new Event("serial:socket:connected"));
2522
2514
  },
2523
- onConnectError: (e) => {
2524
- console.debug("Socket connection error", e), this.#i = !1, window.dispatchEvent(new Event("serial:socket:disconnected"));
2515
+ onConnectError: (s) => {
2516
+ console.debug("Socket connection error", s), this.#i = !1, window.dispatchEvent(new Event("serial:socket:disconnected"));
2525
2517
  }
2526
2518
  };
2527
2519
  }
@@ -2529,27 +2521,32 @@ class ct {
2529
2521
  const t = new URL(e);
2530
2522
  if (!["http:", "https:", "ws:", "wss:"].includes(t.protocol))
2531
2523
  throw new Error("URI must start with http://, https://, ws://, or wss://");
2532
- this.#s = e;
2524
+ this.#n = e;
2533
2525
  }
2534
2526
  get uri() {
2535
- return this.#s;
2527
+ return this.#n;
2536
2528
  }
2537
2529
  set options(e) {
2538
2530
  if (typeof e != "object")
2539
2531
  throw new Error("Options must be an object");
2540
- this.#n = e;
2532
+ this.#t = e;
2541
2533
  }
2542
2534
  get options() {
2543
- return this.#n;
2535
+ return this.#t;
2544
2536
  }
2545
2537
  get socketId() {
2546
2538
  return this.#e && this.#e.id ? this.#e.id : null;
2547
2539
  }
2540
+ configure(e, t) {
2541
+ if (this.#o)
2542
+ throw new Error("Cannot configure socket after it has been initialized. Call configure() before prepare().");
2543
+ e && (this.uri = e), t && (this.#t = { ...this.#t, ...t });
2544
+ }
2548
2545
  disconnect() {
2549
- this.#e && (this.#e.off("response", this.#t.onResponse), this.#e.off("disconnect", this.#t.onDisconnect), this.#e.off("connect", this.#t.onConnect), this.#e.off("connect_error", this.#t.onConnectError), this.#e.disconnect(), this.#e = null, this.#a = !1), this.#i = !1;
2546
+ this.#e && (this.#e.off("response", this.#s.onResponse), this.#e.off("disconnect", this.#s.onDisconnect), this.#e.off("connect", this.#s.onConnect), this.#e.off("connect_error", this.#s.onConnectError), this.#e.disconnect(), this.#e = null, this.#o = !1), this.#i = !1;
2550
2547
  }
2551
2548
  prepare() {
2552
- this.#i || this.#a || (this.#e = B(this.#s, this.#n), this.#a = !0, this.#e.on("disconnect", this.#t.onDisconnect), this.#e.on("response", this.#t.onResponse), this.#e.on("connect", this.#t.onConnect), this.#e.on("connect_error", this.#t.onConnectError));
2549
+ this.#i || this.#o || (this.#e = B(this.#n, this.#t), this.#o = !0, this.#e.on("disconnect", this.#s.onDisconnect), this.#e.on("response", this.#s.onResponse), this.#e.on("connect", this.#s.onConnect), this.#e.on("connect_error", this.#s.onConnectError));
2553
2550
  }
2554
2551
  connectDevice(e) {
2555
2552
  if (!this.#e)
@@ -2582,7 +2579,7 @@ class ct {
2582
2579
  return !this.#i;
2583
2580
  }
2584
2581
  }
2585
- const w = new ct(), D = {
2582
+ const b = new ct(), D = {
2586
2583
  baudRate: 9600,
2587
2584
  dataBits: 8,
2588
2585
  stopBits: 1,
@@ -2603,6 +2600,7 @@ class ht extends de {
2603
2600
  no_code: 0
2604
2601
  },
2605
2602
  serial: {
2603
+ transformStream: !1,
2606
2604
  socket: !1,
2607
2605
  portInfo: {
2608
2606
  path: null,
@@ -2664,25 +2662,27 @@ class ht extends de {
2664
2662
  reconnection: 0
2665
2663
  }
2666
2664
  };
2667
- #s = null;
2665
+ #n = null;
2668
2666
  constructor({
2669
2667
  filters: e = null,
2670
2668
  config_port: t = D,
2671
2669
  no_device: s = 1,
2672
2670
  device_listen_on_channel: i = 1,
2673
2671
  bypassSerialBytesConnection: r = !1,
2674
- socket: o = !1
2672
+ socket: o = !1,
2673
+ transformStream: l = !1
2675
2674
  } = {
2676
2675
  filters: null,
2677
2676
  config_port: D,
2678
2677
  no_device: 1,
2679
2678
  device_listen_on_channel: 1,
2680
2679
  bypassSerialBytesConnection: !1,
2681
- socket: !1
2680
+ socket: !1,
2681
+ transformStream: !1
2682
2682
  }) {
2683
2683
  if (super(), !("serial" in navigator))
2684
2684
  throw new Error("Web Serial not supported");
2685
- e && (this.serialFilters = e), t && (this.serialConfigPort = t), r && (this.__internal__.bypassSerialBytesConnection = r), s && this.#b(s), i && ["number", "string"].includes(typeof i) && (this.listenOnChannel = i), this.__internal__.serial.socket = o, this.#y(), this.#g();
2685
+ e && (this.serialFilters = e), t && (this.serialConfigPort = t), r && (this.__internal__.bypassSerialBytesConnection = r), s && this.#v(s), i && ["number", "string"].includes(typeof i) && (this.listenOnChannel = i), this.__internal__.serial.socket = o, this.__internal__.serial.transformStream = l, this.#g(), this.#m();
2686
2686
  }
2687
2687
  set listenOnChannel(e) {
2688
2688
  if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
@@ -2716,15 +2716,15 @@ class ht extends de {
2716
2716
  this.__internal__.serial.useRTSCTS = e;
2717
2717
  }
2718
2718
  get isConnected() {
2719
- const e = this.__internal__.serial.connected, t = this.#n(this.__internal__.serial.port);
2719
+ const e = this.__internal__.serial.connected, t = this.#t(this.__internal__.serial.port);
2720
2720
  return e && !t && this.#e({ error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
2721
2721
  }
2722
2722
  get isConnecting() {
2723
2723
  return this.__internal__.serial.connecting;
2724
2724
  }
2725
2725
  get isDisconnected() {
2726
- const e = this.__internal__.serial.connected, t = this.#n(this.__internal__.serial.port);
2727
- return !e && t && (this.dispatch("serial:connected"), this.#o(!1), a.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
2726
+ const e = this.__internal__.serial.connected, t = this.#t(this.__internal__.serial.port);
2727
+ return !e && t && (this.dispatch("serial:connected"), this.#a(!1), a.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
2728
2728
  }
2729
2729
  get deviceNumber() {
2730
2730
  return this.__internal__.device_number;
@@ -2897,8 +2897,8 @@ class ht extends de {
2897
2897
  }
2898
2898
  };
2899
2899
  }
2900
- #n(e) {
2901
- return this.useSocket ? this.__internal__.serial.connected && w.isConnected() : !!(e && e.readable && e.writable);
2900
+ #t(e) {
2901
+ return this.useSocket ? this.__internal__.serial.connected && b.isConnected() : !!(e && e.readable && e.writable);
2902
2902
  }
2903
2903
  async timeout(e, t) {
2904
2904
  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", {}), a.$dispatchChange(this)) : t === "connection:start" && (await this.serialDisconnect(), this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector += 1, a.$dispatchChange(this), await this.serialConnect()), this.__internal__.serial.queue.length > 0 && this.dispatch("internal:queue", {}), this.dispatch("serial:timeout", {
@@ -2918,7 +2918,7 @@ class ht extends de {
2918
2918
  }
2919
2919
  socketResponse(e) {
2920
2920
  const t = this.__internal__.serial.connected;
2921
- if (e.type === "disconnect" || e.type === "error" && e.data === "DISCONNECTED" ? this.__internal__.serial.connected = !1 : e.type === "success" && (this.__internal__.serial.connected = !0), a.$dispatchChange(this), !t && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#o(!1)), e.type === "success")
2921
+ if (e.type === "disconnect" || e.type === "error" && e.data === "DISCONNECTED" ? this.__internal__.serial.connected = !1 : e.type === "success" && (this.__internal__.serial.connected = !0), a.$dispatchChange(this), !t && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#a(!1)), e.type === "success")
2922
2922
  this.#r(new Uint8Array(e.data));
2923
2923
  else if (e.type === "error") {
2924
2924
  const s = new Error("The port is closed or is not readable/writable");
@@ -2928,9 +2928,9 @@ class ht extends de {
2928
2928
  }
2929
2929
  async connect() {
2930
2930
  return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
2931
- this.#s || (this.#s = this.#i.bind(this)), this.on("internal:connecting", this.#s);
2931
+ this.#n || (this.#n = this.#i.bind(this)), this.on("internal:connecting", this.#n);
2932
2932
  const s = setInterval(() => {
2933
- this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(s), this.__internal__.serial.aux_connecting = "idle", this.#s !== null && this.off("internal:connecting", this.#s), 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("internal:connecting", { active: !0 }), this.dispatch("serial:connecting", { active: !0 }));
2933
+ this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(s), this.__internal__.serial.aux_connecting = "idle", this.#n !== null && this.off("internal:connecting", this.#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("internal:connecting", { active: !0 }), this.dispatch("serial:connecting", { active: !0 }));
2934
2934
  }, 100);
2935
2935
  this.serialConnect();
2936
2936
  }));
@@ -2938,10 +2938,15 @@ class ht extends de {
2938
2938
  async serialDisconnect() {
2939
2939
  try {
2940
2940
  if (this.useSocket)
2941
- w.isConnected() && w.disconnectDevice(this.configDeviceSocket);
2941
+ b.isConnected() && b.disconnectDevice(this.configDeviceSocket);
2942
2942
  else {
2943
+ this.__internal__.serial.keep_reading = !1;
2943
2944
  const e = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
2944
- e && (await e.cancel().catch((s) => this.serialErrors(s)), 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();
2945
+ if (e && (await e.cancel().catch((s) => this.serialErrors(s)), this.__internal__.serial.input_done && await this.__internal__.serial.input_done), t) {
2946
+ const s = t.getWriter();
2947
+ await s.close(), s.releaseLock(), this.__internal__.serial.output_done && await this.__internal__.serial.output_done;
2948
+ }
2949
+ this.__internal__.serial && this.__internal__.serial.connected && this.__internal__.serial.port && await this.__internal__.serial.port.close();
2945
2950
  }
2946
2951
  } catch (e) {
2947
2952
  this.serialErrors(e);
@@ -2949,17 +2954,17 @@ class ht extends de {
2949
2954
  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, a.$dispatchChange(this);
2950
2955
  }
2951
2956
  }
2952
- async #a(e) {
2953
- if (w.isDisconnected())
2957
+ async #o(e) {
2958
+ if (b.isDisconnected())
2954
2959
  throw this.#e({ error: "Socket is disconnected." }), new Error("The socket is disconnected");
2955
2960
  if (this.isDisconnected)
2956
2961
  throw this.#e({ error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
2957
2962
  const t = this.validateBytes(e);
2958
- w.write({ config: this.configDeviceSocket, bytes: Array.from(t) });
2963
+ b.write({ config: this.configDeviceSocket, bytes: Array.from(t) });
2959
2964
  }
2960
- async #t(e) {
2965
+ async #s(e) {
2961
2966
  if (this.useSocket) {
2962
- await this.#a(e);
2967
+ await this.#o(e);
2963
2968
  return;
2964
2969
  }
2965
2970
  const t = this.__internal__.serial.port;
@@ -2983,7 +2988,7 @@ class ht extends de {
2983
2988
  #r(e = new Uint8Array([]), t = !1) {
2984
2989
  if (e && e.length > 0) {
2985
2990
  const s = this.__internal__.serial.connected;
2986
- if (this.__internal__.serial.connected = this.#n(this.__internal__.serial.port), a.$dispatchChange(this), !s && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#o(!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")
2991
+ if (this.__internal__.serial.connected = this.#t(this.__internal__.serial.port), a.$dispatchChange(this), !s && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#a(!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")
2987
2992
  t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
2988
2993
  else if (this.__internal__.serial.response.as === "uint8")
2989
2994
  t ? this.serialCorruptMessage(e) : this.serialMessage(e);
@@ -3023,7 +3028,7 @@ class ht extends de {
3023
3028
  return e.length === 0 ? t : t.filter((s) => {
3024
3029
  const i = s.getInfo();
3025
3030
  return e.some((r) => i.usbProductId === r.usbProductId && i.usbVendorId === r.usbVendorId);
3026
- }).filter((s) => !this.#n(s));
3031
+ }).filter((s) => !this.#t(s));
3027
3032
  }
3028
3033
  async serialPortsSaved(e) {
3029
3034
  const t = this.serialFilters;
@@ -3090,12 +3095,15 @@ class ht extends de {
3090
3095
  s.set(t, 0), s.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = s;
3091
3096
  }
3092
3097
  }
3098
+ async #_() {
3099
+ 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.response.buffer && this.#r(this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
3100
+ }
3093
3101
  async #u() {
3094
3102
  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(() => {
3095
3103
  this.__internal__.serial.response.buffer && this.#r(this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
3096
3104
  }, this.__internal__.serial.free_timeout_ms || 50);
3097
3105
  }
3098
- async #_() {
3106
+ async #f() {
3099
3107
  const e = this.__internal__.serial.response.length;
3100
3108
  let t = this.__internal__.serial.response.buffer;
3101
3109
  if (this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0), !(e === null || !t || t.length === 0)) {
@@ -3108,7 +3116,7 @@ class ht extends de {
3108
3116
  }, this.__internal__.serial.free_timeout_ms || 50));
3109
3117
  }
3110
3118
  }
3111
- async #f() {
3119
+ async #d() {
3112
3120
  const {
3113
3121
  limiter: e,
3114
3122
  prefixLimiter: t = !1,
@@ -3131,25 +3139,25 @@ class ht extends de {
3131
3139
  c = new RegExp(`([^${e}]+)${e}`, "g");
3132
3140
  else
3133
3141
  return;
3134
- let f, u = 0;
3142
+ let f, _ = 0;
3135
3143
  for (; (f = c.exec(r)) !== null; )
3136
- o.push(new TextEncoder().encode(f[1])), u = c.lastIndex;
3137
- r = r.slice(u);
3144
+ o.push(new TextEncoder().encode(f[1])), _ = c.lastIndex;
3145
+ r = r.slice(_);
3138
3146
  } else if (e instanceof RegExp) {
3139
3147
  let c, f = 0;
3140
3148
  if (t && s) {
3141
- const u = new RegExp(`${e.source}(.*?)${e.source}`, "g");
3142
- for (; (c = u.exec(r)) !== null; )
3143
- o.push(new TextEncoder().encode(c[1])), f = u.lastIndex;
3149
+ const _ = new RegExp(`${e.source}(.*?)${e.source}`, "g");
3150
+ for (; (c = _.exec(r)) !== null; )
3151
+ o.push(new TextEncoder().encode(c[1])), f = _.lastIndex;
3144
3152
  } else if (s)
3145
3153
  for (; (c = e.exec(r)) !== null; ) {
3146
- const u = c.index, d = r.slice(f, u);
3154
+ const _ = c.index, d = r.slice(f, _);
3147
3155
  o.push(new TextEncoder().encode(d)), f = e.lastIndex;
3148
3156
  }
3149
3157
  else if (t) {
3150
- const u = r.split(e);
3151
- u.shift();
3152
- for (const d of u)
3158
+ const _ = r.split(e);
3159
+ _.shift();
3160
+ for (const d of _)
3153
3161
  o.push(new TextEncoder().encode(d));
3154
3162
  r = "";
3155
3163
  }
@@ -3162,34 +3170,34 @@ class ht extends de {
3162
3170
  this.#r(this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
3163
3171
  }, this.__internal__.serial.free_timeout_ms ?? 50));
3164
3172
  }
3165
- async #d() {
3173
+ async #p() {
3166
3174
  const e = this.__internal__.serial.port;
3167
3175
  if (!e || !e.readable) throw new Error("Port is not readable");
3168
- const t = e.readable.getReader();
3169
- this.__internal__.serial.reader = t;
3176
+ const t = this.__internal__.serial.transformStream ? this.__internal__.serial.transformStream : null, s = t ? e.readable.pipeThrough(t).getReader() : e.readable.getReader();
3177
+ this.__internal__.serial.reader = s;
3170
3178
  try {
3171
3179
  for (; this.__internal__.serial.keep_reading; ) {
3172
- const { value: s, done: i } = await t.read();
3173
- if (i) break;
3174
- this.#h(s), this.__internal__.serial.response.delimited ? await this.#f() : this.__internal__.serial.response.length === null ? await this.#u() : await this.#_();
3180
+ const { value: i, done: r } = await s.read();
3181
+ if (r) break;
3182
+ this.#h(i), this.__internal__.serial.transformStream ? await this.#_() : this.__internal__.serial.response.delimited ? await this.#d() : this.__internal__.serial.response.length === null ? await this.#u() : await this.#f();
3175
3183
  }
3176
- } catch (s) {
3177
- this.serialErrors(s);
3184
+ } catch (i) {
3185
+ this.serialErrors(i);
3178
3186
  } finally {
3179
- t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
3187
+ s.releaseLock(), this.__internal__.serial.reader = null, this.__internal__.serial.keep_reading = !0;
3180
3188
  }
3181
3189
  }
3182
- #o(e) {
3190
+ #a(e) {
3183
3191
  e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, this.dispatch("serial:connecting", { active: e }), this.dispatch("internal:connecting", { active: e }));
3184
3192
  }
3185
3193
  async serialConnect() {
3186
3194
  try {
3187
- if (this.#o(!0), this.useSocket) {
3188
- if (w.prepare(), this.__internal__.serial.last_action = "connect", this.__internal__.timeout.until_response = setTimeout(async () => {
3195
+ if (this.#a(!0), this.useSocket) {
3196
+ if (b.prepare(), this.__internal__.serial.last_action = "connect", this.__internal__.timeout.until_response = setTimeout(async () => {
3189
3197
  await this.timeout(this.__internal__.serial.bytes_connection ?? [], "connection:start");
3190
- }, this.__internal__.time.response_connection), w.isDisconnected())
3198
+ }, this.__internal__.time.response_connection), b.isDisconnected())
3191
3199
  return;
3192
- w.connectDevice(this.configDeviceSocket), this.dispatch("serial:sent", {
3200
+ b.connectDevice(this.configDeviceSocket), this.dispatch("serial:sent", {
3193
3201
  action: "connect",
3194
3202
  bytes: this.__internal__.serial.bytes_connection
3195
3203
  });
@@ -3209,25 +3217,25 @@ class ht extends de {
3209
3217
  await t.open(this.serialConfigPort);
3210
3218
  const s = this;
3211
3219
  t.onconnect = (i) => {
3212
- s.dispatch("serial:connected", i), s.#o(!1), a.$dispatchChange(this), s.__internal__.serial.queue.length > 0 ? s.dispatch("internal:queue", {}) : s.__internal__.serial.running_queue = !1;
3220
+ s.dispatch("serial:connected", i), s.#a(!1), a.$dispatchChange(this), s.__internal__.serial.queue.length > 0 ? s.dispatch("internal:queue", {}) : s.__internal__.serial.running_queue = !1;
3213
3221
  }, t.ondisconnect = async () => {
3214
3222
  await s.disconnect();
3215
3223
  }, await ee(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
3216
3224
  await s.timeout(s.__internal__.serial.bytes_connection ?? [], "connection:start");
3217
- }, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await this.#t(this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
3225
+ }, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await this.#s(this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
3218
3226
  action: "connect",
3219
3227
  bytes: this.__internal__.serial.bytes_connection
3220
- }), this.__internal__.auto_response && this.#r(this.__internal__.serial.auto_response), await this.#d();
3228
+ }), this.__internal__.auto_response && this.#r(this.__internal__.serial.auto_response), await this.#p();
3221
3229
  }
3222
3230
  } catch (e) {
3223
- this.#o(!1), this.serialErrors(e);
3231
+ this.#a(!1), this.serialErrors(e);
3224
3232
  }
3225
3233
  }
3226
- async #p() {
3234
+ async #y() {
3227
3235
  return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
3228
3236
  }
3229
3237
  async serialForget() {
3230
- return await this.#p();
3238
+ return await this.#y();
3231
3239
  }
3232
3240
  decToHex(e) {
3233
3241
  return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
@@ -3247,7 +3255,7 @@ class ht extends de {
3247
3255
  bytesToHex(e) {
3248
3256
  return this.add0x(Array.from(e, (t) => this.hexMaker(t)));
3249
3257
  }
3250
- #y() {
3258
+ #g() {
3251
3259
  [
3252
3260
  "serial:connected",
3253
3261
  "serial:connecting",
@@ -3268,7 +3276,7 @@ class ht extends de {
3268
3276
  this.serialRegisterAvailableListener(e);
3269
3277
  });
3270
3278
  }
3271
- #g() {
3279
+ #m() {
3272
3280
  const e = this;
3273
3281
  this.on("internal:queue", async () => {
3274
3282
  await e.#w();
@@ -3279,9 +3287,9 @@ class ht extends de {
3279
3287
  e.isDisconnected && !e.isConnecting && e.serialConnect().catch(() => {
3280
3288
  });
3281
3289
  };
3282
- this.useSocket && (window.addEventListener("serial:socket:disconnected", t), window.addEventListener("serial:socket:connected", s)), this.#m();
3290
+ this.useSocket && (window.addEventListener("serial:socket:disconnected", t), window.addEventListener("serial:socket:connected", s)), this.#b();
3283
3291
  }
3284
- #m() {
3292
+ #b() {
3285
3293
  const e = this;
3286
3294
  navigator.serial.addEventListener("connect", async () => {
3287
3295
  e.isDisconnected && await e.serialConnect().catch(() => {
@@ -3289,9 +3297,9 @@ class ht extends de {
3289
3297
  });
3290
3298
  }
3291
3299
  async #w() {
3292
- if (this.useSocket && w.isDisconnected())
3300
+ if (this.useSocket && b.isDisconnected())
3293
3301
  return;
3294
- if (!this.#n(this.__internal__.serial.port)) {
3302
+ if (!this.#t(this.__internal__.serial.port)) {
3295
3303
  this.#e({ error: "Port is closed, not readable or writable." }), await this.serialConnect();
3296
3304
  return;
3297
3305
  }
@@ -3305,7 +3313,7 @@ class ht extends de {
3305
3313
  let t = this.__internal__.time.response_general;
3306
3314
  if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
3307
3315
  await this.timeout(e.bytes, e.action);
3308
- }, t), this.__internal__.serial.last_action = e.action ?? "unknown", await this.#t(e.bytes), this.dispatch("serial:sent", {
3316
+ }, t), this.__internal__.serial.last_action = e.action ?? "unknown", await this.#s(e.bytes), this.dispatch("serial:sent", {
3309
3317
  action: e.action,
3310
3318
  bytes: e.bytes
3311
3319
  }), this.__internal__.auto_response) {
@@ -3343,7 +3351,7 @@ class ht extends de {
3343
3351
  }
3344
3352
  this.__internal__.serial.queue.push({ bytes: s, action: t }), this.dispatch("internal:queue", {});
3345
3353
  }
3346
- #b(e = 1) {
3354
+ #v(e = 1) {
3347
3355
  this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
3348
3356
  }
3349
3357
  serialSetConnectionConstant(e = 1) {
@@ -3356,7 +3364,7 @@ class ht extends de {
3356
3364
  serialCorruptMessage(e) {
3357
3365
  throw console.log(e), this.dispatch("serial:corrupt-message", { code: e }), new Error("Method not implemented 'serialCorruptMessage'");
3358
3366
  }
3359
- #v() {
3367
+ #E() {
3360
3368
  this.__internal__.last_error = {
3361
3369
  message: null,
3362
3370
  action: null,
@@ -3383,7 +3391,7 @@ class ht extends de {
3383
3391
  });
3384
3392
  }
3385
3393
  softReload() {
3386
- this.#v(), this.dispatch("serial:soft-reload", {});
3394
+ this.#E(), this.dispatch("serial:soft-reload", {});
3387
3395
  }
3388
3396
  async sendConnect() {
3389
3397
  if (!this.__internal__.serial.bytes_connection)
@@ -3451,7 +3459,7 @@ class ht extends de {
3451
3459
  }
3452
3460
  }
3453
3461
  export {
3454
- ht as S,
3455
- w as c,
3462
+ ht as T,
3463
+ b as c,
3456
3464
  a as s
3457
3465
  };