@danidoble/webserial 4.4.5 → 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,7 +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) => e === "blob" ? n instanceof Blob ? n : new Blob([n]) : n instanceof ArrayBuffer ? n : n.buffer, 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) => {
66
66
  const t = n.length, s = new Array(t);
67
67
  let i = 0;
68
68
  n.forEach((r, o) => {
@@ -70,7 +70,7 @@ const ye = (n) => {
70
70
  s[o] = l, ++i === t && e(s.join(re));
71
71
  });
72
72
  });
73
- }, be = (n, e) => {
73
+ }, we = (n, e) => {
74
74
  const t = n.split(re), s = [];
75
75
  for (let i = 0; i < t.length; i++) {
76
76
  const r = W(t[i], e);
@@ -134,12 +134,12 @@ function Ee(n, e) {
134
134
  } else if (s === 2) {
135
135
  if (T(t) < 8)
136
136
  break;
137
- const c = A(t, 8), f = new DataView(c.buffer, c.byteOffset, c.length), u = f.getUint32(0);
138
- 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) {
139
139
  l.enqueue(q);
140
140
  break;
141
141
  }
142
- i = u * Math.pow(2, 32) + f.getUint32(4), s = 3;
142
+ i = _ * Math.pow(2, 32) + f.getUint32(4), s = 3;
143
143
  } else {
144
144
  if (T(t) < i)
145
145
  break;
@@ -155,24 +155,24 @@ function Ee(n, e) {
155
155
  });
156
156
  }
157
157
  const oe = 4;
158
- function _(n) {
158
+ function u(n) {
159
159
  if (n) return ke(n);
160
160
  }
161
161
  function ke(n) {
162
- for (var e in _.prototype)
163
- n[e] = _.prototype[e];
162
+ for (var e in u.prototype)
163
+ n[e] = u.prototype[e];
164
164
  return n;
165
165
  }
166
- _.prototype.on = _.prototype.addEventListener = function(n, e) {
166
+ u.prototype.on = u.prototype.addEventListener = function(n, e) {
167
167
  return this._callbacks = this._callbacks || {}, (this._callbacks["$" + n] = this._callbacks["$" + n] || []).push(e), this;
168
168
  };
169
- _.prototype.once = function(n, e) {
169
+ u.prototype.once = function(n, e) {
170
170
  function t() {
171
171
  this.off(n, t), e.apply(this, arguments);
172
172
  }
173
173
  return t.fn = e, this.on(n, t), this;
174
174
  };
175
- _.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) {
176
176
  if (this._callbacks = this._callbacks || {}, arguments.length == 0)
177
177
  return this._callbacks = {}, this;
178
178
  var t = this._callbacks["$" + n];
@@ -186,7 +186,7 @@ _.prototype.off = _.prototype.removeListener = _.prototype.removeAllListeners =
186
186
  }
187
187
  return t.length === 0 && delete this._callbacks["$" + n], this;
188
188
  };
189
- _.prototype.emit = function(n) {
189
+ u.prototype.emit = function(n) {
190
190
  this._callbacks = this._callbacks || {};
191
191
  for (var e = new Array(arguments.length - 1), t = this._callbacks["$" + n], s = 1; s < arguments.length; s++)
192
192
  e[s - 1] = arguments[s];
@@ -197,11 +197,11 @@ _.prototype.emit = function(n) {
197
197
  }
198
198
  return this;
199
199
  };
200
- _.prototype.emitReserved = _.prototype.emit;
201
- _.prototype.listeners = function(n) {
200
+ u.prototype.emitReserved = u.prototype.emit;
201
+ u.prototype.listeners = function(n) {
202
202
  return this._callbacks = this._callbacks || {}, this._callbacks["$" + n] || [];
203
203
  };
204
- _.prototype.hasListeners = function(n) {
204
+ u.prototype.hasListeners = function(n) {
205
205
  return !!this.listeners(n).length;
206
206
  };
207
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";
@@ -244,7 +244,7 @@ class Le extends Error {
244
244
  super(e), this.description = t, this.context = s, this.type = "TransportError";
245
245
  }
246
246
  }
247
- class K extends _ {
247
+ class K extends u {
248
248
  /**
249
249
  * Transport abstract constructor.
250
250
  *
@@ -398,7 +398,7 @@ class Pe extends K {
398
398
  return this.onClose({ description: "transport closed by the server" }), !1;
399
399
  this.onPacket(s);
400
400
  };
401
- 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());
402
402
  }
403
403
  /**
404
404
  * For polling, send a close packet.
@@ -418,7 +418,7 @@ class Pe extends K {
418
418
  * @protected
419
419
  */
420
420
  write(e) {
421
- this.writable = !1, we(e, (t) => {
421
+ this.writable = !1, be(e, (t) => {
422
422
  this.doWrite(t, () => {
423
423
  this.writable = !0, this.emitReserved("drain");
424
424
  });
@@ -484,7 +484,7 @@ class De extends Pe {
484
484
  }), this.pollXhr = e;
485
485
  }
486
486
  }
487
- class g extends _ {
487
+ class g extends u {
488
488
  /**
489
489
  * Request constructor
490
490
  *
@@ -624,13 +624,13 @@ function he(n) {
624
624
  } catch {
625
625
  }
626
626
  }
627
- 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";
628
628
  class Me extends K {
629
629
  get name() {
630
630
  return "websocket";
631
631
  }
632
632
  doOpen() {
633
- 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");
634
634
  this.opts.extraHeaders && (s.headers = this.opts.extraHeaders);
635
635
  try {
636
636
  this.ws = this.createSocket(e, t, s);
@@ -684,7 +684,7 @@ class Me extends K {
684
684
  const I = p.WebSocket || p.MozWebSocket;
685
685
  class Fe extends Me {
686
686
  createSocket(e, t, s) {
687
- 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);
688
688
  }
689
689
  doWrite(e, t) {
690
690
  this.ws.send(t);
@@ -780,7 +780,7 @@ const M = typeof addEventListener == "function" && typeof removeEventListener ==
780
780
  M && addEventListener("offline", () => {
781
781
  x.forEach((n) => n());
782
782
  }, !1);
783
- class b extends _ {
783
+ class w extends u {
784
784
  /**
785
785
  * Socket constructor.
786
786
  *
@@ -848,7 +848,7 @@ class b extends _ {
848
848
  }, 0);
849
849
  return;
850
850
  }
851
- 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];
852
852
  this.readyState = "opening";
853
853
  const t = this.createTransport(e);
854
854
  t.open(), this.setTransport(t);
@@ -867,7 +867,7 @@ class b extends _ {
867
867
  * @private
868
868
  */
869
869
  onOpen() {
870
- 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();
871
871
  }
872
872
  /**
873
873
  * Handles a packet.
@@ -1031,7 +1031,7 @@ class b extends _ {
1031
1031
  * @private
1032
1032
  */
1033
1033
  _onError(e) {
1034
- 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")
1035
1035
  return this.transports.shift(), this._open();
1036
1036
  this.emitReserved("error", e), this._onClose("transport error", e);
1037
1037
  }
@@ -1050,8 +1050,8 @@ class b extends _ {
1050
1050
  }
1051
1051
  }
1052
1052
  }
1053
- b.protocol = oe;
1054
- class Ye extends b {
1053
+ w.protocol = oe;
1054
+ class Ye extends w {
1055
1055
  constructor() {
1056
1056
  super(...arguments), this._upgrades = [];
1057
1057
  }
@@ -1068,15 +1068,15 @@ class Ye extends b {
1068
1068
  */
1069
1069
  _probe(e) {
1070
1070
  let t = this.createTransport(e), s = !1;
1071
- b.priorWebsocketSuccess = !1;
1071
+ w.priorWebsocketSuccess = !1;
1072
1072
  const i = () => {
1073
1073
  s || (t.send([{ type: "ping", data: "probe" }]), t.once("packet", (d) => {
1074
1074
  if (!s)
1075
1075
  if (d.type === "pong" && d.data === "probe") {
1076
1076
  if (this.upgrading = !0, this.emitReserved("upgrading", t), !t)
1077
1077
  return;
1078
- b.priorWebsocketSuccess = t.name === "websocket", this.transport.pause(() => {
1079
- 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());
1080
1080
  });
1081
1081
  } else {
1082
1082
  const E = new Error("probe error");
@@ -1085,7 +1085,7 @@ class Ye extends b {
1085
1085
  }));
1086
1086
  };
1087
1087
  function r() {
1088
- s || (s = !0, u(), t.close(), t = null);
1088
+ s || (s = !0, _(), t.close(), t = null);
1089
1089
  }
1090
1090
  const o = (d) => {
1091
1091
  const E = new Error("probe error: " + d);
@@ -1100,7 +1100,7 @@ class Ye extends b {
1100
1100
  function f(d) {
1101
1101
  t && d.name !== t.name && r();
1102
1102
  }
1103
- const u = () => {
1103
+ const _ = () => {
1104
1104
  t.removeListener("open", i), t.removeListener("error", o), t.removeListener("close", l), this.off("close", c), this.off("upgrading", f);
1105
1105
  };
1106
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(() => {
@@ -1135,7 +1135,7 @@ function Qe(n, e = "", t) {
1135
1135
  const r = s.host.indexOf(":") !== -1 ? "[" + s.host + "]" : s.host;
1136
1136
  return s.id = s.protocol + "://" + r + ":" + s.port + e, s.href = s.protocol + "://" + r + (t && t.port === s.port ? "" : ":" + s.port), s;
1137
1137
  }
1138
- 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]";
1139
1139
  function z(n) {
1140
1140
  return Xe && (n instanceof ArrayBuffer || je(n)) || Ge && n instanceof Blob || Ze && n instanceof File;
1141
1141
  }
@@ -1254,7 +1254,7 @@ class it {
1254
1254
  function G(n) {
1255
1255
  return Object.prototype.toString.call(n) === "[object Object]";
1256
1256
  }
1257
- class Y extends _ {
1257
+ class Y extends u {
1258
1258
  /**
1259
1259
  * Decoder constructor
1260
1260
  *
@@ -1415,7 +1415,7 @@ const at = Object.freeze({
1415
1415
  newListener: 1,
1416
1416
  removeListener: 1
1417
1417
  });
1418
- class fe extends _ {
1418
+ class fe extends u {
1419
1419
  /**
1420
1420
  * `Socket` constructor.
1421
1421
  */
@@ -1540,8 +1540,8 @@ class fe extends _ {
1540
1540
  data: t
1541
1541
  };
1542
1542
  if (o.options = {}, o.options.compress = this.flags.compress !== !1, typeof t[t.length - 1] == "function") {
1543
- const u = this.ids++, d = t.pop();
1544
- this._registerAckCallback(u, d), o.id = u;
1543
+ const _ = this.ids++, d = t.pop();
1544
+ this._registerAckCallback(_, d), o.id = _;
1545
1545
  }
1546
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());
1547
1547
  return this.flags.volatile && !l || (c ? (this.notifyOutgoingListeners(o), this.packet(o)) : this.sendBuffer.push(o)), this.flags = {}, this;
@@ -2030,7 +2030,7 @@ v.prototype.setMax = function(n) {
2030
2030
  v.prototype.setJitter = function(n) {
2031
2031
  this.jitter = n;
2032
2032
  };
2033
- class V extends _ {
2033
+ class V extends u {
2034
2034
  constructor(e, t) {
2035
2035
  var s;
2036
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({
@@ -2495,16 +2495,16 @@ function ee(n = 100) {
2495
2495
  );
2496
2496
  }
2497
2497
  class ct {
2498
- #s = "http://localhost:3000";
2499
- #n = {
2498
+ #n = "http://localhost:3001";
2499
+ #t = {
2500
2500
  transports: ["websocket"]
2501
2501
  };
2502
2502
  #e = null;
2503
2503
  #i = !1;
2504
- #a = !1;
2505
- #t;
2506
- constructor() {
2507
- this.#t = {
2504
+ #o = !1;
2505
+ #s;
2506
+ constructor(e, t) {
2507
+ e && (this.#n = e), t && (this.#t = { ...this.#t, ...t }), this.#s = {
2508
2508
  onResponse: this.onResponse.bind(this),
2509
2509
  onDisconnect: () => {
2510
2510
  this.#i = !1, window.dispatchEvent(new Event("serial:socket:disconnected"));
@@ -2512,8 +2512,8 @@ class ct {
2512
2512
  onConnect: () => {
2513
2513
  this.#i = !0, window.dispatchEvent(new Event("serial:socket:connected"));
2514
2514
  },
2515
- onConnectError: (e) => {
2516
- 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"));
2517
2517
  }
2518
2518
  };
2519
2519
  }
@@ -2521,27 +2521,32 @@ class ct {
2521
2521
  const t = new URL(e);
2522
2522
  if (!["http:", "https:", "ws:", "wss:"].includes(t.protocol))
2523
2523
  throw new Error("URI must start with http://, https://, ws://, or wss://");
2524
- this.#s = e;
2524
+ this.#n = e;
2525
2525
  }
2526
2526
  get uri() {
2527
- return this.#s;
2527
+ return this.#n;
2528
2528
  }
2529
2529
  set options(e) {
2530
2530
  if (typeof e != "object")
2531
2531
  throw new Error("Options must be an object");
2532
- this.#n = e;
2532
+ this.#t = e;
2533
2533
  }
2534
2534
  get options() {
2535
- return this.#n;
2535
+ return this.#t;
2536
2536
  }
2537
2537
  get socketId() {
2538
2538
  return this.#e && this.#e.id ? this.#e.id : null;
2539
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
+ }
2540
2545
  disconnect() {
2541
- 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;
2542
2547
  }
2543
2548
  prepare() {
2544
- 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));
2545
2550
  }
2546
2551
  connectDevice(e) {
2547
2552
  if (!this.#e)
@@ -2574,7 +2579,7 @@ class ct {
2574
2579
  return !this.#i;
2575
2580
  }
2576
2581
  }
2577
- const w = new ct(), D = {
2582
+ const b = new ct(), D = {
2578
2583
  baudRate: 9600,
2579
2584
  dataBits: 8,
2580
2585
  stopBits: 1,
@@ -2595,6 +2600,7 @@ class ht extends de {
2595
2600
  no_code: 0
2596
2601
  },
2597
2602
  serial: {
2603
+ transformStream: !1,
2598
2604
  socket: !1,
2599
2605
  portInfo: {
2600
2606
  path: null,
@@ -2656,25 +2662,27 @@ class ht extends de {
2656
2662
  reconnection: 0
2657
2663
  }
2658
2664
  };
2659
- #s = null;
2665
+ #n = null;
2660
2666
  constructor({
2661
2667
  filters: e = null,
2662
2668
  config_port: t = D,
2663
2669
  no_device: s = 1,
2664
2670
  device_listen_on_channel: i = 1,
2665
2671
  bypassSerialBytesConnection: r = !1,
2666
- socket: o = !1
2672
+ socket: o = !1,
2673
+ transformStream: l = !1
2667
2674
  } = {
2668
2675
  filters: null,
2669
2676
  config_port: D,
2670
2677
  no_device: 1,
2671
2678
  device_listen_on_channel: 1,
2672
2679
  bypassSerialBytesConnection: !1,
2673
- socket: !1
2680
+ socket: !1,
2681
+ transformStream: !1
2674
2682
  }) {
2675
2683
  if (super(), !("serial" in navigator))
2676
2684
  throw new Error("Web Serial not supported");
2677
- 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();
2678
2686
  }
2679
2687
  set listenOnChannel(e) {
2680
2688
  if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
@@ -2708,15 +2716,15 @@ class ht extends de {
2708
2716
  this.__internal__.serial.useRTSCTS = e;
2709
2717
  }
2710
2718
  get isConnected() {
2711
- 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);
2712
2720
  return e && !t && this.#e({ error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
2713
2721
  }
2714
2722
  get isConnecting() {
2715
2723
  return this.__internal__.serial.connecting;
2716
2724
  }
2717
2725
  get isDisconnected() {
2718
- const e = this.__internal__.serial.connected, t = this.#n(this.__internal__.serial.port);
2719
- 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;
2720
2728
  }
2721
2729
  get deviceNumber() {
2722
2730
  return this.__internal__.device_number;
@@ -2889,8 +2897,8 @@ class ht extends de {
2889
2897
  }
2890
2898
  };
2891
2899
  }
2892
- #n(e) {
2893
- 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);
2894
2902
  }
2895
2903
  async timeout(e, t) {
2896
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", {
@@ -2910,7 +2918,7 @@ class ht extends de {
2910
2918
  }
2911
2919
  socketResponse(e) {
2912
2920
  const t = this.__internal__.serial.connected;
2913
- 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")
2914
2922
  this.#r(new Uint8Array(e.data));
2915
2923
  else if (e.type === "error") {
2916
2924
  const s = new Error("The port is closed or is not readable/writable");
@@ -2920,9 +2928,9 @@ class ht extends de {
2920
2928
  }
2921
2929
  async connect() {
2922
2930
  return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
2923
- 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);
2924
2932
  const s = setInterval(() => {
2925
- 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 }));
2926
2934
  }, 100);
2927
2935
  this.serialConnect();
2928
2936
  }));
@@ -2930,10 +2938,15 @@ class ht extends de {
2930
2938
  async serialDisconnect() {
2931
2939
  try {
2932
2940
  if (this.useSocket)
2933
- w.isConnected() && w.disconnectDevice(this.configDeviceSocket);
2941
+ b.isConnected() && b.disconnectDevice(this.configDeviceSocket);
2934
2942
  else {
2943
+ this.__internal__.serial.keep_reading = !1;
2935
2944
  const e = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
2936
- 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();
2937
2950
  }
2938
2951
  } catch (e) {
2939
2952
  this.serialErrors(e);
@@ -2941,17 +2954,17 @@ class ht extends de {
2941
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);
2942
2955
  }
2943
2956
  }
2944
- async #a(e) {
2945
- if (w.isDisconnected())
2957
+ async #o(e) {
2958
+ if (b.isDisconnected())
2946
2959
  throw this.#e({ error: "Socket is disconnected." }), new Error("The socket is disconnected");
2947
2960
  if (this.isDisconnected)
2948
2961
  throw this.#e({ error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
2949
2962
  const t = this.validateBytes(e);
2950
- w.write({ config: this.configDeviceSocket, bytes: Array.from(t) });
2963
+ b.write({ config: this.configDeviceSocket, bytes: Array.from(t) });
2951
2964
  }
2952
- async #t(e) {
2965
+ async #s(e) {
2953
2966
  if (this.useSocket) {
2954
- await this.#a(e);
2967
+ await this.#o(e);
2955
2968
  return;
2956
2969
  }
2957
2970
  const t = this.__internal__.serial.port;
@@ -2975,7 +2988,7 @@ class ht extends de {
2975
2988
  #r(e = new Uint8Array([]), t = !1) {
2976
2989
  if (e && e.length > 0) {
2977
2990
  const s = this.__internal__.serial.connected;
2978
- 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")
2979
2992
  t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
2980
2993
  else if (this.__internal__.serial.response.as === "uint8")
2981
2994
  t ? this.serialCorruptMessage(e) : this.serialMessage(e);
@@ -3015,7 +3028,7 @@ class ht extends de {
3015
3028
  return e.length === 0 ? t : t.filter((s) => {
3016
3029
  const i = s.getInfo();
3017
3030
  return e.some((r) => i.usbProductId === r.usbProductId && i.usbVendorId === r.usbVendorId);
3018
- }).filter((s) => !this.#n(s));
3031
+ }).filter((s) => !this.#t(s));
3019
3032
  }
3020
3033
  async serialPortsSaved(e) {
3021
3034
  const t = this.serialFilters;
@@ -3082,12 +3095,15 @@ class ht extends de {
3082
3095
  s.set(t, 0), s.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = s;
3083
3096
  }
3084
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
+ }
3085
3101
  async #u() {
3086
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(() => {
3087
3103
  this.__internal__.serial.response.buffer && this.#r(this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
3088
3104
  }, this.__internal__.serial.free_timeout_ms || 50);
3089
3105
  }
3090
- async #_() {
3106
+ async #f() {
3091
3107
  const e = this.__internal__.serial.response.length;
3092
3108
  let t = this.__internal__.serial.response.buffer;
3093
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)) {
@@ -3100,7 +3116,7 @@ class ht extends de {
3100
3116
  }, this.__internal__.serial.free_timeout_ms || 50));
3101
3117
  }
3102
3118
  }
3103
- async #f() {
3119
+ async #d() {
3104
3120
  const {
3105
3121
  limiter: e,
3106
3122
  prefixLimiter: t = !1,
@@ -3123,25 +3139,25 @@ class ht extends de {
3123
3139
  c = new RegExp(`([^${e}]+)${e}`, "g");
3124
3140
  else
3125
3141
  return;
3126
- let f, u = 0;
3142
+ let f, _ = 0;
3127
3143
  for (; (f = c.exec(r)) !== null; )
3128
- o.push(new TextEncoder().encode(f[1])), u = c.lastIndex;
3129
- r = r.slice(u);
3144
+ o.push(new TextEncoder().encode(f[1])), _ = c.lastIndex;
3145
+ r = r.slice(_);
3130
3146
  } else if (e instanceof RegExp) {
3131
3147
  let c, f = 0;
3132
3148
  if (t && s) {
3133
- const u = new RegExp(`${e.source}(.*?)${e.source}`, "g");
3134
- for (; (c = u.exec(r)) !== null; )
3135
- 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;
3136
3152
  } else if (s)
3137
3153
  for (; (c = e.exec(r)) !== null; ) {
3138
- const u = c.index, d = r.slice(f, u);
3154
+ const _ = c.index, d = r.slice(f, _);
3139
3155
  o.push(new TextEncoder().encode(d)), f = e.lastIndex;
3140
3156
  }
3141
3157
  else if (t) {
3142
- const u = r.split(e);
3143
- u.shift();
3144
- for (const d of u)
3158
+ const _ = r.split(e);
3159
+ _.shift();
3160
+ for (const d of _)
3145
3161
  o.push(new TextEncoder().encode(d));
3146
3162
  r = "";
3147
3163
  }
@@ -3154,34 +3170,34 @@ class ht extends de {
3154
3170
  this.#r(this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
3155
3171
  }, this.__internal__.serial.free_timeout_ms ?? 50));
3156
3172
  }
3157
- async #d() {
3173
+ async #p() {
3158
3174
  const e = this.__internal__.serial.port;
3159
3175
  if (!e || !e.readable) throw new Error("Port is not readable");
3160
- const t = e.readable.getReader();
3161
- 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;
3162
3178
  try {
3163
3179
  for (; this.__internal__.serial.keep_reading; ) {
3164
- const { value: s, done: i } = await t.read();
3165
- if (i) break;
3166
- 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();
3167
3183
  }
3168
- } catch (s) {
3169
- this.serialErrors(s);
3184
+ } catch (i) {
3185
+ this.serialErrors(i);
3170
3186
  } finally {
3171
- 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;
3172
3188
  }
3173
3189
  }
3174
- #o(e) {
3190
+ #a(e) {
3175
3191
  e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, this.dispatch("serial:connecting", { active: e }), this.dispatch("internal:connecting", { active: e }));
3176
3192
  }
3177
3193
  async serialConnect() {
3178
3194
  try {
3179
- if (this.#o(!0), this.useSocket) {
3180
- 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 () => {
3181
3197
  await this.timeout(this.__internal__.serial.bytes_connection ?? [], "connection:start");
3182
- }, this.__internal__.time.response_connection), w.isDisconnected())
3198
+ }, this.__internal__.time.response_connection), b.isDisconnected())
3183
3199
  return;
3184
- w.connectDevice(this.configDeviceSocket), this.dispatch("serial:sent", {
3200
+ b.connectDevice(this.configDeviceSocket), this.dispatch("serial:sent", {
3185
3201
  action: "connect",
3186
3202
  bytes: this.__internal__.serial.bytes_connection
3187
3203
  });
@@ -3201,25 +3217,25 @@ class ht extends de {
3201
3217
  await t.open(this.serialConfigPort);
3202
3218
  const s = this;
3203
3219
  t.onconnect = (i) => {
3204
- 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;
3205
3221
  }, t.ondisconnect = async () => {
3206
3222
  await s.disconnect();
3207
3223
  }, await ee(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
3208
3224
  await s.timeout(s.__internal__.serial.bytes_connection ?? [], "connection:start");
3209
- }, 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", {
3210
3226
  action: "connect",
3211
3227
  bytes: this.__internal__.serial.bytes_connection
3212
- }), 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();
3213
3229
  }
3214
3230
  } catch (e) {
3215
- this.#o(!1), this.serialErrors(e);
3231
+ this.#a(!1), this.serialErrors(e);
3216
3232
  }
3217
3233
  }
3218
- async #p() {
3234
+ async #y() {
3219
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;
3220
3236
  }
3221
3237
  async serialForget() {
3222
- return await this.#p();
3238
+ return await this.#y();
3223
3239
  }
3224
3240
  decToHex(e) {
3225
3241
  return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
@@ -3239,7 +3255,7 @@ class ht extends de {
3239
3255
  bytesToHex(e) {
3240
3256
  return this.add0x(Array.from(e, (t) => this.hexMaker(t)));
3241
3257
  }
3242
- #y() {
3258
+ #g() {
3243
3259
  [
3244
3260
  "serial:connected",
3245
3261
  "serial:connecting",
@@ -3260,7 +3276,7 @@ class ht extends de {
3260
3276
  this.serialRegisterAvailableListener(e);
3261
3277
  });
3262
3278
  }
3263
- #g() {
3279
+ #m() {
3264
3280
  const e = this;
3265
3281
  this.on("internal:queue", async () => {
3266
3282
  await e.#w();
@@ -3271,9 +3287,9 @@ class ht extends de {
3271
3287
  e.isDisconnected && !e.isConnecting && e.serialConnect().catch(() => {
3272
3288
  });
3273
3289
  };
3274
- 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();
3275
3291
  }
3276
- #m() {
3292
+ #b() {
3277
3293
  const e = this;
3278
3294
  navigator.serial.addEventListener("connect", async () => {
3279
3295
  e.isDisconnected && await e.serialConnect().catch(() => {
@@ -3281,9 +3297,9 @@ class ht extends de {
3281
3297
  });
3282
3298
  }
3283
3299
  async #w() {
3284
- if (this.useSocket && w.isDisconnected())
3300
+ if (this.useSocket && b.isDisconnected())
3285
3301
  return;
3286
- if (!this.#n(this.__internal__.serial.port)) {
3302
+ if (!this.#t(this.__internal__.serial.port)) {
3287
3303
  this.#e({ error: "Port is closed, not readable or writable." }), await this.serialConnect();
3288
3304
  return;
3289
3305
  }
@@ -3297,7 +3313,7 @@ class ht extends de {
3297
3313
  let t = this.__internal__.time.response_general;
3298
3314
  if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
3299
3315
  await this.timeout(e.bytes, e.action);
3300
- }, 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", {
3301
3317
  action: e.action,
3302
3318
  bytes: e.bytes
3303
3319
  }), this.__internal__.auto_response) {
@@ -3335,7 +3351,7 @@ class ht extends de {
3335
3351
  }
3336
3352
  this.__internal__.serial.queue.push({ bytes: s, action: t }), this.dispatch("internal:queue", {});
3337
3353
  }
3338
- #b(e = 1) {
3354
+ #v(e = 1) {
3339
3355
  this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
3340
3356
  }
3341
3357
  serialSetConnectionConstant(e = 1) {
@@ -3348,7 +3364,7 @@ class ht extends de {
3348
3364
  serialCorruptMessage(e) {
3349
3365
  throw console.log(e), this.dispatch("serial:corrupt-message", { code: e }), new Error("Method not implemented 'serialCorruptMessage'");
3350
3366
  }
3351
- #v() {
3367
+ #E() {
3352
3368
  this.__internal__.last_error = {
3353
3369
  message: null,
3354
3370
  action: null,
@@ -3375,7 +3391,7 @@ class ht extends de {
3375
3391
  });
3376
3392
  }
3377
3393
  softReload() {
3378
- this.#v(), this.dispatch("serial:soft-reload", {});
3394
+ this.#E(), this.dispatch("serial:soft-reload", {});
3379
3395
  }
3380
3396
  async sendConnect() {
3381
3397
  if (!this.__internal__.serial.bytes_connection)
@@ -3443,7 +3459,7 @@ class ht extends de {
3443
3459
  }
3444
3460
  }
3445
3461
  export {
3446
- ht as S,
3447
- w as c,
3462
+ ht as T,
3463
+ b as c,
3448
3464
  a as s
3449
3465
  };