webserial-core 1.0.11 → 1.0.12

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/Core.d.ts CHANGED
@@ -44,6 +44,7 @@ type SerialData = {
44
44
  filters: SerialPortFilter[];
45
45
  config_port: SerialOptions;
46
46
  queue: QueueData[];
47
+ running_queue: boolean;
47
48
  auto_response: any;
48
49
  free_timeout_ms: number;
49
50
  useRTSCTS: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"Core.d.ts","sourceRoot":"","sources":["../lib/Core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAI7C,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC;IAC1E,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,KAAK,gBAAgB,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,aAAa,CAAC;AAEnE,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC;IACnB,EAAE,EAAE,gBAAgB,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,OAAO,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;IAChC,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,SAAS;IACjB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GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI;IAgBxG,gBAAgB,IAAI,IAAI;IAIxB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM;IAQ7B,QAAQ,IAAI,MAAM;IAUlB,UAAU,IAAI,IAAI;IAKZ,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,cAAc,CAAC,EAAE,IAAS,EAAE,GAAE,UAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7E,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAI1C,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAE,MAAa,GAAG,eAAe;IAIxE,wBAAwB,CAAC,MAAM,GAAE,MAAW,EAAE,GAAG,GAAE,MAAa,GAAG,UAAU;IAM7E,kBAAkB,CAAC,MAAM,GAAE,MAAW,EAAE,GAAG,GAAE,MAAa,GAAG,MAAM,EAAE;IAKrE,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE;IAI5C,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU;IAI5C,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU;IAatD,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,MAAM;IAgB7D,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IASxC,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IASvC,2BAA2B,IAAI,OAAO;CAG9C"}
@@ -1,39 +1,29 @@
1
- var J = Object.defineProperty;
2
- var k = (l) => {
3
- throw TypeError(l);
4
- };
5
- var K = (l, i, e) => i in l ? J(l, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[i] = e;
6
- var y = (l, i, e) => K(l, typeof i != "symbol" ? i + "" : i, e), T = (l, i, e) => i.has(l) || k("Cannot " + e);
7
- var v = (l, i, e) => (T(l, i, "read from private field"), e ? e.call(l) : i.get(l)), S = (l, i, e) => i.has(l) ? k("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(l) : i.set(l, e), P = (l, i, e, t) => (T(l, i, "write to private field"), t ? t.call(l, e) : i.set(l, e), e), o = (l, i, e) => (T(l, i, "access private method"), e);
8
- class B extends CustomEvent {
9
- constructor(i, e) {
10
- super(i, e);
1
+ class p extends CustomEvent {
2
+ constructor(e, t) {
3
+ super(e, t);
11
4
  }
12
5
  }
13
- class U extends EventTarget {
14
- constructor() {
15
- super(...arguments);
16
- y(this, "__listeners__", {
17
- debug: !1
18
- });
19
- y(this, "__debug__", !1);
20
- y(this, "__listenersCallbacks__", []);
21
- }
6
+ class y extends EventTarget {
7
+ __listeners__ = {
8
+ debug: !1
9
+ };
10
+ __debug__ = !1;
11
+ __listenersCallbacks__ = [];
22
12
  dispatch(e, t = null) {
23
- const n = new B(e, { detail: t });
24
- this.dispatchEvent(n), this.__debug__ && this.dispatchEvent(new B("debug", { detail: { type: e, data: t } }));
13
+ const i = new p(e, { detail: t });
14
+ this.dispatchEvent(i), this.__debug__ && this.dispatchEvent(new p("debug", { detail: { type: e, data: t } }));
25
15
  }
26
- dispatchAsync(e, t = null, n = 100) {
27
- const r = this;
16
+ dispatchAsync(e, t = null, i = 100) {
17
+ const n = this;
28
18
  setTimeout(() => {
29
- r.dispatch(e, t);
30
- }, n);
19
+ n.dispatch(e, t);
20
+ }, i);
31
21
  }
32
22
  on(e, t) {
33
23
  typeof this.__listeners__[e] < "u" && !this.__listeners__[e] && (this.__listeners__[e] = !0), this.__listenersCallbacks__.push({ key: e, callback: t }), this.addEventListener(e, t);
34
24
  }
35
25
  off(e, t) {
36
- this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((n) => !(n.key === e && n.callback === t)), this.removeEventListener(e, t);
26
+ this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((i) => !(i.key === e && i.callback === t)), this.removeEventListener(e, t);
37
27
  }
38
28
  serialRegisterAvailableListener(e) {
39
29
  this.__listeners__[e] || (this.__listeners__[e] = !1);
@@ -51,90 +41,90 @@ class U extends EventTarget {
51
41
  this.__listeners__[e] = !1;
52
42
  }
53
43
  }
54
- const a = class a extends U {
44
+ class s extends y {
45
+ static instance;
46
+ static devices = {};
55
47
  constructor() {
56
- super(), ["change"].forEach((e) => {
57
- this.serialRegisterAvailableListener(e);
48
+ super(), ["change"].forEach((t) => {
49
+ this.serialRegisterAvailableListener(t);
58
50
  });
59
51
  }
60
- static $dispatchChange(i = null) {
61
- i && i.$checkAndDispatchConnection(), a.instance.dispatch("change", { devices: a.devices, dispatcher: i });
52
+ static $dispatchChange(e = null) {
53
+ e && e.$checkAndDispatchConnection(), s.instance.dispatch("change", { devices: s.devices, dispatcher: e });
62
54
  }
63
- static typeError(i) {
64
- const e = new Error();
65
- throw e.message = `Type ${i} is not supported`, e.name = "DeviceTypeError", e;
55
+ static typeError(e) {
56
+ const t = new Error();
57
+ throw t.message = `Type ${e} is not supported`, t.name = "DeviceTypeError", t;
66
58
  }
67
- static registerType(i) {
68
- typeof a.devices[i] > "u" && (a.devices = { ...a.devices, [i]: {} });
59
+ static registerType(e) {
60
+ typeof s.devices[e] > "u" && (s.devices = { ...s.devices, [e]: {} });
69
61
  }
70
- static add(i) {
71
- const e = i.typeDevice;
72
- typeof a.devices[e] > "u" && a.registerType(e);
73
- const t = i.uuid;
74
- if (typeof a.devices[e] > "u" && a.typeError(e), a.devices[e][t])
75
- throw new Error(`Device with id ${t} already exists`);
76
- return a.devices[e][t] = i, a.$dispatchChange(i), Object.keys(a.devices[e]).indexOf(t);
62
+ static add(e) {
63
+ const t = e.typeDevice;
64
+ typeof s.devices[t] > "u" && s.registerType(t);
65
+ const i = e.uuid;
66
+ if (typeof s.devices[t] > "u" && s.typeError(t), s.devices[t][i])
67
+ throw new Error(`Device with id ${i} already exists`);
68
+ return s.devices[t][i] = e, s.$dispatchChange(e), Object.keys(s.devices[t]).indexOf(i);
77
69
  }
78
- static get(i, e) {
79
- return typeof a.devices[i] > "u" && a.registerType(i), typeof a.devices[i] > "u" && a.typeError(i), a.devices[i][e];
70
+ static get(e, t) {
71
+ return typeof s.devices[e] > "u" && s.registerType(e), typeof s.devices[e] > "u" && s.typeError(e), s.devices[e][t];
80
72
  }
81
- static getAll(i = null) {
82
- return i === null ? a.devices : (typeof a.devices[i] > "u" && a.typeError(i), a.devices[i]);
73
+ static getAll(e = null) {
74
+ return e === null ? s.devices : (typeof s.devices[e] > "u" && s.typeError(e), s.devices[e]);
83
75
  }
84
76
  static getList() {
85
- return Object.values(a.devices).map((e) => Object.values(e)).flat();
77
+ return Object.values(s.devices).map((t) => Object.values(t)).flat();
86
78
  }
87
- static getByNumber(i, e) {
88
- return typeof a.devices[i] > "u" && a.typeError(i), Object.values(a.devices[i]).find((n) => n.deviceNumber === e) ?? null;
79
+ static getByNumber(e, t) {
80
+ return typeof s.devices[e] > "u" && s.typeError(e), Object.values(s.devices[e]).find((n) => n.deviceNumber === t) ?? null;
89
81
  }
90
- static getCustom(i, e = 1) {
91
- return typeof a.devices[i] > "u" && a.typeError(i), Object.values(a.devices[i]).find((n) => n.deviceNumber === e) ?? null;
82
+ static getCustom(e, t = 1) {
83
+ return typeof s.devices[e] > "u" && s.typeError(e), Object.values(s.devices[e]).find((n) => n.deviceNumber === t) ?? null;
92
84
  }
93
85
  static async connectToAll() {
94
- const i = a.getList();
95
- for (const e of i)
96
- e.isConnected || await e.connect().catch(console.warn);
97
- return Promise.resolve(a.areAllConnected());
86
+ const e = s.getList();
87
+ for (const t of e)
88
+ t.isConnected || await t.connect().catch(console.warn);
89
+ return Promise.resolve(s.areAllConnected());
98
90
  }
99
91
  static async disconnectAll() {
100
- const i = a.getList();
101
- for (const e of i)
102
- e.isDisconnected || await e.disconnect().catch(console.warn);
103
- return Promise.resolve(a.areAllDisconnected());
92
+ const e = s.getList();
93
+ for (const t of e)
94
+ t.isDisconnected || await t.disconnect().catch(console.warn);
95
+ return Promise.resolve(s.areAllDisconnected());
104
96
  }
105
97
  static async areAllConnected() {
106
- const i = a.getList();
107
- for (const e of i)
108
- if (!e.isConnected) return Promise.resolve(!1);
98
+ const e = s.getList();
99
+ for (const t of e)
100
+ if (!t.isConnected) return Promise.resolve(!1);
109
101
  return Promise.resolve(!0);
110
102
  }
111
103
  static async areAllDisconnected() {
112
- const i = a.getList();
113
- for (const e of i)
114
- if (!e.isDisconnected) return Promise.resolve(!1);
104
+ const e = s.getList();
105
+ for (const t of e)
106
+ if (!t.isDisconnected) return Promise.resolve(!1);
115
107
  return Promise.resolve(!0);
116
108
  }
117
109
  static async getAllConnected() {
118
- const i = a.getList();
119
- return Promise.resolve(i.filter((e) => e.isConnected));
110
+ const e = s.getList();
111
+ return Promise.resolve(e.filter((t) => t.isConnected));
120
112
  }
121
113
  static async getAllDisconnected() {
122
- const i = a.getList();
123
- return Promise.resolve(i.filter((e) => e.isDisconnected));
114
+ const e = s.getList();
115
+ return Promise.resolve(e.filter((t) => t.isDisconnected));
124
116
  }
125
- };
126
- y(a, "instance"), y(a, "devices", {});
127
- let h = a;
128
- h.instance || (h.instance = new h());
129
- function D(l = 100) {
117
+ }
118
+ s.instance || (s.instance = new s());
119
+ function g(h = 100) {
130
120
  return new Promise(
131
- (i) => setTimeout(() => i(), l)
121
+ (e) => setTimeout(() => e(), h)
132
122
  );
133
123
  }
134
- function X() {
124
+ function m() {
135
125
  return "serial" in navigator;
136
126
  }
137
- const E = {
127
+ const d = {
138
128
  baudRate: 9600,
139
129
  dataBits: 8,
140
130
  stopBits: 1,
@@ -142,88 +132,86 @@ const E = {
142
132
  bufferSize: 32768,
143
133
  flowControl: "none"
144
134
  };
145
- var p, s, m, C, I, A, $, f, R, M, q, N, O, F, b, H, j, W, Q, V, z, G;
146
- class Z extends U {
135
+ class b extends y {
136
+ __internal__ = {
137
+ bypassSerialBytesConnection: !1,
138
+ auto_response: !1,
139
+ device_number: 1,
140
+ aux_port_connector: 0,
141
+ last_error: {
142
+ message: null,
143
+ action: null,
144
+ code: null,
145
+ no_code: 0
146
+ },
147
+ serial: {
148
+ aux_connecting: "idle",
149
+ connecting: !1,
150
+ connected: !1,
151
+ port: null,
152
+ last_action: null,
153
+ response: {
154
+ length: null,
155
+ buffer: new Uint8Array([]),
156
+ as: "uint8",
157
+ replacer: /[\n\r]+/g,
158
+ limiter: null,
159
+ prefixLimiter: !1,
160
+ sufixLimiter: !0,
161
+ delimited: !1
162
+ },
163
+ reader: null,
164
+ input_done: null,
165
+ output_done: null,
166
+ input_stream: null,
167
+ output_stream: null,
168
+ keep_reading: !0,
169
+ time_until_send_bytes: void 0,
170
+ delay_first_connection: 200,
171
+ bytes_connection: null,
172
+ filters: [],
173
+ config_port: d,
174
+ queue: [],
175
+ running_queue: !1,
176
+ auto_response: ["DD", "DD"],
177
+ free_timeout_ms: 50,
178
+ // In previous versions 400 was used
179
+ useRTSCTS: !1
180
+ // Use RTS/CTS flow control
181
+ },
182
+ device: {
183
+ type: "unknown",
184
+ id: window.crypto.randomUUID(),
185
+ listen_on_port: null
186
+ },
187
+ time: {
188
+ response_connection: 500,
189
+ response_general: 2e3
190
+ },
191
+ timeout: {
192
+ until_response: 0
193
+ },
194
+ interval: {
195
+ reconnection: 0
196
+ }
197
+ };
198
+ #t = null;
147
199
  constructor({
148
200
  filters: e = null,
149
- config_port: t = E,
150
- no_device: n = 1,
151
- device_listen_on_channel: r = 1,
152
- bypassSerialBytesConnection: _ = !1
201
+ config_port: t = d,
202
+ no_device: i = 1,
203
+ device_listen_on_channel: n = 1,
204
+ bypassSerialBytesConnection: a = !1
153
205
  } = {
154
206
  filters: null,
155
- config_port: E,
207
+ config_port: d,
156
208
  no_device: 1,
157
209
  device_listen_on_channel: 1,
158
210
  bypassSerialBytesConnection: !1
159
211
  }) {
160
- super();
161
- S(this, s);
162
- y(this, "__internal__", {
163
- bypassSerialBytesConnection: !1,
164
- auto_response: !1,
165
- device_number: 1,
166
- aux_port_connector: 0,
167
- last_error: {
168
- message: null,
169
- action: null,
170
- code: null,
171
- no_code: 0
172
- },
173
- serial: {
174
- aux_connecting: "idle",
175
- connecting: !1,
176
- connected: !1,
177
- port: null,
178
- last_action: null,
179
- response: {
180
- length: null,
181
- buffer: new Uint8Array([]),
182
- as: "uint8",
183
- replacer: /[\n\r]+/g,
184
- limiter: null,
185
- prefixLimiter: !1,
186
- sufixLimiter: !0,
187
- delimited: !1
188
- },
189
- reader: null,
190
- input_done: null,
191
- output_done: null,
192
- input_stream: null,
193
- output_stream: null,
194
- keep_reading: !0,
195
- time_until_send_bytes: void 0,
196
- delay_first_connection: 200,
197
- bytes_connection: null,
198
- filters: [],
199
- config_port: E,
200
- queue: [],
201
- auto_response: ["DD", "DD"],
202
- free_timeout_ms: 50,
203
- // In previous versions 400 was used
204
- useRTSCTS: !1
205
- // Use RTS/CTS flow control
206
- },
207
- device: {
208
- type: "unknown",
209
- id: window.crypto.randomUUID(),
210
- listen_on_port: null
211
- },
212
- time: {
213
- response_connection: 500,
214
- response_general: 2e3
215
- },
216
- timeout: {
217
- until_response: 0
218
- },
219
- interval: {
220
- reconnection: 0
221
- }
222
- });
223
- S(this, p, null);
224
- if (!("serial" in navigator))
212
+ if (super(), !("serial" in navigator))
225
213
  throw new Error("Web Serial not supported");
226
- e && (this.serialFilters = e), t && (this.serialConfigPort = t), _ && (this.__internal__.bypassSerialBytesConnection = _), n && o(this, s, z).call(this, n), r && ["number", "string"].includes(typeof r) && (this.listenOnChannel = r), o(this, s, j).call(this), o(this, s, W).call(this);
214
+ e && (this.serialFilters = e), t && (this.serialConfigPort = t), a && (this.__internal__.bypassSerialBytesConnection = a), i && this.#b(i), n && ["number", "string"].includes(typeof n) && (this.listenOnChannel = n), this.#p(), this.#g();
227
215
  }
228
216
  set listenOnChannel(e) {
229
217
  if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
@@ -257,15 +245,15 @@ class Z extends U {
257
245
  this.__internal__.serial.useRTSCTS = e;
258
246
  }
259
247
  get isConnected() {
260
- const e = this.__internal__.serial.connected, t = o(this, s, m).call(this, this.__internal__.serial.port);
261
- return e && !t && o(this, s, C).call(this, { error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
248
+ const e = this.__internal__.serial.connected, t = this.#i(this.__internal__.serial.port);
249
+ return e && !t && this.#s({ error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
262
250
  }
263
251
  get isConnecting() {
264
252
  return this.__internal__.serial.connecting;
265
253
  }
266
254
  get isDisconnected() {
267
- const e = this.__internal__.serial.connected, t = o(this, s, m).call(this, this.__internal__.serial.port);
268
- return !e && t && (this.dispatch("serial:connected"), o(this, s, b).call(this, !1), h.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
255
+ const e = this.__internal__.serial.connected, t = this.#i(this.__internal__.serial.port);
256
+ return !e && t && (this.dispatch("serial:connected"), this.#n(!1), s.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
269
257
  }
270
258
  get deviceNumber() {
271
259
  return this.__internal__.device_number;
@@ -335,21 +323,30 @@ class Z extends U {
335
323
  throw new Error("bypassSerialBytesConnection must be a boolean");
336
324
  this.__internal__.bypassSerialBytesConnection = e;
337
325
  }
326
+ #i(e) {
327
+ return !!(e && e.readable && e.writable);
328
+ }
338
329
  async timeout(e, t) {
339
- 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", {}), h.$dispatchChange(this)) : t === "connection:start" && (await this.serialDisconnect(), this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector += 1, h.$dispatchChange(this), await this.serialConnect()), this.dispatch("serial:timeout", {
330
+ 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", {}), s.$dispatchChange(this)) : t === "connection:start" && (await this.serialDisconnect(), this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector += 1, s.$dispatchChange(this), await this.serialConnect()), this.__internal__.serial.queue.length > 0 && this.dispatch("internal:queue", {}), this.dispatch("serial:timeout", {
340
331
  ...this.__internal__.last_error,
341
332
  bytes: e,
342
333
  action: t
343
334
  });
344
335
  }
345
336
  async disconnect(e = null) {
346
- await this.serialDisconnect(), o(this, s, C).call(this, e);
337
+ await this.serialDisconnect(), this.#s(e);
338
+ }
339
+ #s(e = null) {
340
+ this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), s.$dispatchChange(this);
341
+ }
342
+ #a(e) {
343
+ this.__internal__.serial.aux_connecting = e.detail.active ? "connecting" : "finished";
347
344
  }
348
345
  async connect() {
349
346
  return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
350
- X() || t("Web Serial not supported"), v(this, p) || P(this, p, o(this, s, I).bind(this)), this.on("internal:connecting", v(this, p));
351
- const n = setInterval(() => {
352
- this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(n), this.__internal__.serial.aux_connecting = "idle", v(this, p) !== null && this.off("internal:connecting", v(this, p)), 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 }));
347
+ m() || t("Web Serial not supported"), this.#t || (this.#t = this.#a.bind(this)), this.on("internal:connecting", this.#t);
348
+ const i = setInterval(() => {
349
+ this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(i), this.__internal__.serial.aux_connecting = "idle", this.#t !== null && this.off("internal:connecting", this.#t), 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 }));
353
350
  }, 100);
354
351
  this.serialConnect();
355
352
  }));
@@ -357,12 +354,57 @@ class Z extends U {
357
354
  async serialDisconnect() {
358
355
  try {
359
356
  const e = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
360
- e && (await e.cancel().catch((r) => this.serialErrors(r)), 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();
357
+ 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();
361
358
  } catch (e) {
362
359
  this.serialErrors(e);
363
360
  } finally {
364
- 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, h.$dispatchChange(this);
361
+ 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, s.$dispatchChange(this);
362
+ }
363
+ }
364
+ async #r(e) {
365
+ const t = this.__internal__.serial.port;
366
+ if (!t || t && (!t.readable || !t.writable))
367
+ throw this.#s({ error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
368
+ const i = this.validateBytes(e);
369
+ if (this.useRTSCTS && await this.#l(t, 5e3), t.writable === null) return;
370
+ const n = t.writable.getWriter();
371
+ await n.write(i), n.releaseLock();
372
+ }
373
+ async #l(e, t = 5e3) {
374
+ const i = Date.now();
375
+ for (; ; ) {
376
+ if (Date.now() - i > t)
377
+ throw new Error("Timeout waiting for clearToSend signal");
378
+ const { clearToSend: n } = await e.getSignals();
379
+ if (n) return;
380
+ await g(100);
381
+ }
382
+ }
383
+ #e(e = new Uint8Array([]), t = !1) {
384
+ if (e && e.length > 0) {
385
+ const i = this.__internal__.serial.connected;
386
+ if (this.__internal__.serial.connected = this.#i(this.__internal__.serial.port), s.$dispatchChange(this), !i && this.__internal__.serial.connected && (this.dispatch("serial:connected"), this.#n(!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")
387
+ t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
388
+ else if (this.__internal__.serial.response.as === "uint8")
389
+ t ? this.serialCorruptMessage(e) : this.serialMessage(e);
390
+ else if (this.__internal__.serial.response.as === "string") {
391
+ const n = this.parseUint8ArrayToString(e);
392
+ if (this.__internal__.serial.response.limiter !== null) {
393
+ const a = n.split(this.__internal__.serial.response.limiter);
394
+ for (const r in a)
395
+ a[r] && (t ? this.serialCorruptMessage(a[r]) : this.serialMessage(a[r]));
396
+ } else
397
+ t ? this.serialCorruptMessage(n) : this.serialMessage(n);
398
+ } else {
399
+ const n = this.stringToArrayBuffer(this.parseUint8ArrayToString(e));
400
+ t ? this.serialCorruptMessage(n) : this.serialMessage(n);
401
+ }
402
+ }
403
+ if (this.__internal__.serial.queue.length === 0) {
404
+ this.__internal__.serial.running_queue = !1;
405
+ return;
365
406
  }
407
+ this.dispatch("internal:queue", {});
366
408
  }
367
409
  getResponseAsArrayBuffer() {
368
410
  this.__internal__.serial.response.as = "arraybuffer";
@@ -376,11 +418,18 @@ class Z extends U {
376
418
  getResponseAsString() {
377
419
  this.__internal__.serial.response.as = "string";
378
420
  }
421
+ async #o() {
422
+ const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
423
+ return e.length === 0 ? t : t.filter((n) => {
424
+ const a = n.getInfo();
425
+ return e.some((r) => a.usbProductId === r.usbProductId && a.usbVendorId === r.usbVendorId);
426
+ }).filter((n) => !this.#i(n));
427
+ }
379
428
  async serialPortsSaved(e) {
380
429
  const t = this.serialFilters;
381
430
  if (this.__internal__.aux_port_connector < e.length) {
382
- const n = this.__internal__.aux_port_connector;
383
- this.__internal__.serial.port = e[n];
431
+ const i = this.__internal__.aux_port_connector;
432
+ this.__internal__.serial.port = e[i];
384
433
  } else
385
434
  this.__internal__.aux_port_connector = 0, this.__internal__.serial.port = await navigator.serial.requestPort({
386
435
  filters: t
@@ -401,7 +450,7 @@ class Z extends U {
401
450
  case t.includes(
402
451
  "this readable stream reader has been released and cannot be used to cancel its previous owner stream"
403
452
  ):
404
- this.dispatch("serial:need-permission", {}), h.$dispatchChange(this);
453
+ this.dispatch("serial:need-permission", {}), s.$dispatchChange(this);
405
454
  break;
406
455
  case t.includes("the port is already open."):
407
456
  case t.includes("failed to open serial port"):
@@ -424,7 +473,7 @@ class Z extends U {
424
473
  case t.includes("the port is already closed."):
425
474
  break;
426
475
  case t.includes("the device has been lost"):
427
- this.dispatch("serial:lost", {}), h.$dispatchChange(this);
476
+ this.dispatch("serial:lost", {}), s.$dispatchChange(this);
428
477
  break;
429
478
  case t.includes("navigator.serial is undefined"):
430
479
  this.dispatch("serial:unsupported", {});
@@ -435,40 +484,140 @@ class Z extends U {
435
484
  }
436
485
  this.dispatch("serial:error", e);
437
486
  }
487
+ #_(e) {
488
+ if (e) {
489
+ const t = this.__internal__.serial.response.buffer, i = new Uint8Array(t.length + e.byteLength);
490
+ i.set(t, 0), i.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = i;
491
+ }
492
+ }
493
+ async #c() {
494
+ 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(() => {
495
+ this.__internal__.serial.response.buffer && this.#e(this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
496
+ }, this.__internal__.serial.free_timeout_ms || 50);
497
+ }
498
+ async #h() {
499
+ const e = this.__internal__.serial.response.length;
500
+ let t = this.__internal__.serial.response.buffer;
501
+ 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)) {
502
+ for (; t.length >= e; ) {
503
+ const i = t.slice(0, e);
504
+ this.#e(i), t = t.slice(e);
505
+ }
506
+ this.__internal__.serial.response.buffer = t, t.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
507
+ this.#e(this.__internal__.serial.response.buffer, !0);
508
+ }, this.__internal__.serial.free_timeout_ms || 50));
509
+ }
510
+ }
511
+ async #u() {
512
+ const {
513
+ limiter: e,
514
+ prefixLimiter: t = !1,
515
+ sufixLimiter: i = !0
516
+ } = this.__internal__.serial.response;
517
+ if (!e)
518
+ throw new Error("No limiter defined for delimited serial response");
519
+ const n = this.__internal__.serial.response.buffer;
520
+ if (!e || !n || n.length === 0) return;
521
+ this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
522
+ let r = new TextDecoder().decode(n);
523
+ const c = [];
524
+ if (typeof e == "string") {
525
+ let l;
526
+ if (t && i)
527
+ l = new RegExp(`${e}([^${e}]+)${e}`, "g");
528
+ else if (t)
529
+ l = new RegExp(`${e}([^${e}]*)`, "g");
530
+ else if (i)
531
+ l = new RegExp(`([^${e}]+)${e}`, "g");
532
+ else
533
+ return;
534
+ let _, o = 0;
535
+ for (; (_ = l.exec(r)) !== null; )
536
+ c.push(new TextEncoder().encode(_[1])), o = l.lastIndex;
537
+ r = r.slice(o);
538
+ } else if (e instanceof RegExp) {
539
+ let l, _ = 0;
540
+ if (t && i) {
541
+ const o = new RegExp(`${e.source}(.*?)${e.source}`, "g");
542
+ for (; (l = o.exec(r)) !== null; )
543
+ c.push(new TextEncoder().encode(l[1])), _ = o.lastIndex;
544
+ } else if (i)
545
+ for (; (l = e.exec(r)) !== null; ) {
546
+ const o = l.index, u = r.slice(_, o);
547
+ c.push(new TextEncoder().encode(u)), _ = e.lastIndex;
548
+ }
549
+ else if (t) {
550
+ const o = r.split(e);
551
+ o.shift();
552
+ for (const u of o)
553
+ c.push(new TextEncoder().encode(u));
554
+ r = "";
555
+ }
556
+ r = r.slice(_);
557
+ }
558
+ for (const l of c)
559
+ this.#e(l);
560
+ const f = new TextEncoder().encode(r);
561
+ this.__internal__.serial.response.buffer = f, f.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
562
+ this.#e(this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
563
+ }, this.__internal__.serial.free_timeout_ms ?? 50));
564
+ }
565
+ async #d() {
566
+ const e = this.__internal__.serial.port;
567
+ if (!e || !e.readable) throw new Error("Port is not readable");
568
+ const t = e.readable.getReader();
569
+ this.__internal__.serial.reader = t;
570
+ try {
571
+ for (; this.__internal__.serial.keep_reading; ) {
572
+ const { value: i, done: n } = await t.read();
573
+ if (n) break;
574
+ this.#_(i), this.__internal__.serial.response.delimited ? await this.#u() : this.__internal__.serial.response.length === null ? await this.#c() : await this.#h();
575
+ }
576
+ } catch (i) {
577
+ this.serialErrors(i);
578
+ } finally {
579
+ t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
580
+ }
581
+ }
582
+ #n(e) {
583
+ e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, this.dispatch("serial:connecting", { active: e }), this.dispatch("internal:connecting", { active: e }));
584
+ }
438
585
  async serialConnect() {
439
586
  try {
440
- o(this, s, b).call(this, !0);
441
- const e = await o(this, s, R).call(this);
587
+ this.#n(!0);
588
+ const e = await this.#o();
442
589
  if (e.length > 0)
443
590
  await this.serialPortsSaved(e);
444
591
  else {
445
- const r = this.serialFilters;
592
+ const n = this.serialFilters;
446
593
  this.__internal__.serial.port = await navigator.serial.requestPort({
447
- filters: r
594
+ filters: n
448
595
  });
449
596
  }
450
597
  const t = this.__internal__.serial.port;
451
598
  if (!t)
452
599
  throw new Error("No port selected by the user");
453
600
  await t.open(this.serialConfigPort);
454
- const n = this;
455
- t.onconnect = (r) => {
456
- var _;
457
- n.dispatch("serial:connected", r), o(_ = n, s, b).call(_, !1), h.$dispatchChange(this), n.__internal__.serial.queue.length > 0 && n.dispatch("internal:queue", {});
601
+ const i = this;
602
+ t.onconnect = (n) => {
603
+ i.dispatch("serial:connected", n), i.#n(!1), s.$dispatchChange(this), i.__internal__.serial.queue.length > 0 ? i.dispatch("internal:queue", {}) : i.__internal__.serial.running_queue = !1;
458
604
  }, t.ondisconnect = async () => {
459
- await n.disconnect();
460
- }, await D(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
461
- await n.timeout(n.__internal__.serial.bytes_connection ?? [], "connection:start");
462
- }, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await o(this, s, A).call(this, this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
605
+ await i.disconnect();
606
+ }, await g(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
607
+ await i.timeout(i.__internal__.serial.bytes_connection ?? [], "connection:start");
608
+ }, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await this.#r(this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
463
609
  action: "connect",
464
610
  bytes: this.__internal__.serial.bytes_connection
465
- }), this.__internal__.auto_response && o(this, s, f).call(this, this.__internal__.serial.auto_response), await o(this, s, F).call(this);
611
+ }), this.__internal__.auto_response && this.#e(this.__internal__.serial.auto_response), await this.#d();
466
612
  } catch (e) {
467
- o(this, s, b).call(this, !1), this.serialErrors(e);
613
+ this.#n(!1), this.serialErrors(e);
468
614
  }
469
615
  }
616
+ async #f() {
617
+ return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
618
+ }
470
619
  async serialForget() {
471
- return await o(this, s, H).call(this);
620
+ return await this.#f();
472
621
  }
473
622
  decToHex(e) {
474
623
  return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
@@ -481,13 +630,77 @@ class Z extends U {
481
630
  }
482
631
  add0x(e) {
483
632
  const t = [];
484
- return e.forEach((n, r) => {
485
- t[r] = "0x" + n;
633
+ return e.forEach((i, n) => {
634
+ t[n] = "0x" + i;
486
635
  }), t;
487
636
  }
488
637
  bytesToHex(e) {
489
638
  return this.add0x(Array.from(e, (t) => this.hexMaker(t)));
490
639
  }
640
+ #p() {
641
+ [
642
+ "serial:connected",
643
+ "serial:connecting",
644
+ "serial:reconnect",
645
+ "serial:timeout",
646
+ "serial:disconnected",
647
+ "serial:sent",
648
+ "serial:soft-reload",
649
+ "serial:message",
650
+ "serial:corrupt-message",
651
+ "unknown",
652
+ "serial:need-permission",
653
+ "serial:lost",
654
+ "serial:unsupported",
655
+ "serial:error",
656
+ "debug"
657
+ ].forEach((t) => {
658
+ this.serialRegisterAvailableListener(t);
659
+ });
660
+ }
661
+ #g() {
662
+ const e = this;
663
+ this.on("internal:queue", async () => {
664
+ await e.#m();
665
+ }), this.#y();
666
+ }
667
+ #y() {
668
+ const e = this;
669
+ navigator.serial.addEventListener("connect", async () => {
670
+ e.isDisconnected && await e.serialConnect().catch(() => {
671
+ });
672
+ });
673
+ }
674
+ async #m() {
675
+ if (!this.#i(this.__internal__.serial.port)) {
676
+ this.#s({ error: "Port is closed, not readable or writable." }), await this.serialConnect();
677
+ return;
678
+ }
679
+ if (this.__internal__.timeout.until_response) return;
680
+ if (this.__internal__.serial.queue.length === 0) {
681
+ this.__internal__.serial.running_queue = !1;
682
+ return;
683
+ }
684
+ this.__internal__.serial.running_queue = !0;
685
+ const e = this.__internal__.serial.queue[0];
686
+ let t = this.__internal__.time.response_general;
687
+ if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
688
+ await this.timeout(e.bytes, e.action);
689
+ }, t), this.__internal__.serial.last_action = e.action ?? "unknown", await this.#r(e.bytes), this.dispatch("serial:sent", {
690
+ action: e.action,
691
+ bytes: e.bytes
692
+ }), this.__internal__.auto_response) {
693
+ let n = new Uint8Array(0);
694
+ try {
695
+ n = this.validateBytes(this.__internal__.serial.auto_response);
696
+ } catch (a) {
697
+ this.serialErrors(a);
698
+ }
699
+ this.#e(n);
700
+ }
701
+ const i = [...this.__internal__.serial.queue];
702
+ this.__internal__.serial.queue = i.splice(1), this.__internal__.serial.queue.length > 0 && (this.__internal__.serial.running_queue = !0);
703
+ }
491
704
  validateBytes(e) {
492
705
  let t = new Uint8Array(0);
493
706
  if (e instanceof Uint8Array)
@@ -503,13 +716,16 @@ class Z extends U {
503
716
  return t;
504
717
  }
505
718
  async appendToQueue(e, t) {
506
- const n = this.validateBytes(e);
719
+ const i = this.validateBytes(e);
507
720
  if (["connect", "connection:start"].includes(t)) {
508
721
  if (this.__internal__.serial.connected) return;
509
722
  await this.serialConnect();
510
723
  return;
511
724
  }
512
- this.__internal__.serial.queue.push({ bytes: n, action: t }), this.dispatch("internal:queue", {});
725
+ this.__internal__.serial.queue.push({ bytes: i, action: t }), this.dispatch("internal:queue", {});
726
+ }
727
+ #b(e = 1) {
728
+ this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
513
729
  }
514
730
  serialSetConnectionConstant(e = 1) {
515
731
  if (this.__internal__.bypassSerialBytesConnection) return this.__internal__.serial.bytes_connection;
@@ -521,13 +737,21 @@ class Z extends U {
521
737
  serialCorruptMessage(e) {
522
738
  throw console.log(e), this.dispatch("serial:corrupt-message", { code: e }), new Error("Method not implemented 'serialCorruptMessage'");
523
739
  }
740
+ #w() {
741
+ this.__internal__.last_error = {
742
+ message: null,
743
+ action: null,
744
+ code: null,
745
+ no_code: 0
746
+ };
747
+ }
524
748
  clearSerialQueue() {
525
749
  this.__internal__.serial.queue = [];
526
750
  }
527
751
  sumHex(e) {
528
752
  let t = 0;
529
- return e.forEach((n) => {
530
- t += parseInt(n, 16);
753
+ return e.forEach((i) => {
754
+ t += parseInt(i, 16);
531
755
  }), t.toString(16);
532
756
  }
533
757
  toString() {
@@ -540,7 +764,7 @@ class Z extends U {
540
764
  });
541
765
  }
542
766
  softReload() {
543
- o(this, s, G).call(this), this.dispatch("serial:soft-reload", {});
767
+ this.#w(), this.dispatch("serial:soft-reload", {});
544
768
  }
545
769
  async sendConnect() {
546
770
  if (!this.__internal__.serial.bytes_connection)
@@ -561,13 +785,13 @@ class Z extends U {
561
785
  }
562
786
  parseStringToTextEncoder(e = "", t = `
563
787
  `) {
564
- const n = new TextEncoder();
565
- return e += t, n.encode(e);
788
+ const i = new TextEncoder();
789
+ return e += t, i.encode(e);
566
790
  }
567
791
  parseStringToBytes(e = "", t = `
568
792
  `) {
569
- const n = this.parseStringToTextEncoder(e, t);
570
- return Array.from(n).map((r) => r.toString(16));
793
+ const i = this.parseStringToTextEncoder(e, t);
794
+ return Array.from(i).map((n) => n.toString(16));
571
795
  }
572
796
  parseUint8ToHex(e) {
573
797
  return Array.from(e).map((t) => t.toString(16));
@@ -577,29 +801,29 @@ class Z extends U {
577
801
  }
578
802
  stringArrayToUint8Array(e) {
579
803
  const t = [];
580
- return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((n) => {
581
- const r = n.replace("0x", "");
582
- t.push(parseInt(r, 16));
804
+ return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((i) => {
805
+ const n = i.replace("0x", "");
806
+ t.push(parseInt(n, 16));
583
807
  }), new Uint8Array(t));
584
808
  }
585
809
  parseUint8ArrayToString(e) {
586
810
  let t = new Uint8Array(0);
587
811
  e instanceof Uint8Array ? t = e : t = this.stringArrayToUint8Array(e), e = this.parseUint8ToHex(t);
588
- const n = e.map((r) => parseInt(r, 16));
589
- return this.__internal__.serial.response.replacer ? String.fromCharCode(...n).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...n);
812
+ const i = e.map((n) => parseInt(n, 16));
813
+ return this.__internal__.serial.response.replacer ? String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...i);
590
814
  }
591
815
  hexToAscii(e) {
592
816
  const t = e.toString();
593
- let n = "";
594
- for (let r = 0; r < t.length; r += 2)
595
- n += String.fromCharCode(parseInt(t.substring(r, 2), 16));
596
- return n;
817
+ let i = "";
818
+ for (let n = 0; n < t.length; n += 2)
819
+ i += String.fromCharCode(parseInt(t.substring(n, 2), 16));
820
+ return i;
597
821
  }
598
822
  asciiToHex(e) {
599
823
  const t = [];
600
- for (let n = 0, r = e.length; n < r; n++) {
601
- const _ = Number(e.charCodeAt(n)).toString(16);
602
- t.push(_);
824
+ for (let i = 0, n = e.length; i < n; i++) {
825
+ const a = Number(e.charCodeAt(i)).toString(16);
826
+ t.push(a);
603
827
  }
604
828
  return t.join("");
605
829
  }
@@ -607,218 +831,8 @@ class Z extends U {
607
831
  return this.isConnected;
608
832
  }
609
833
  }
610
- p = new WeakMap(), s = new WeakSet(), m = function(e) {
611
- return !!(e && e.readable && e.writable);
612
- }, C = function(e = null) {
613
- this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", e), h.$dispatchChange(this);
614
- }, I = function(e) {
615
- this.__internal__.serial.aux_connecting = e.detail.active ? "connecting" : "finished";
616
- }, A = async function(e) {
617
- const t = this.__internal__.serial.port;
618
- if (!t || t && (!t.readable || !t.writable))
619
- throw o(this, s, C).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
620
- const n = this.validateBytes(e);
621
- if (this.useRTSCTS && await o(this, s, $).call(this, t, 5e3), t.writable === null) return;
622
- const r = t.writable.getWriter();
623
- await r.write(n), r.releaseLock();
624
- }, $ = async function(e, t = 5e3) {
625
- const n = Date.now();
626
- for (; ; ) {
627
- if (Date.now() - n > t)
628
- throw new Error("Timeout waiting for clearToSend signal");
629
- const { clearToSend: r } = await e.getSignals();
630
- if (r) return;
631
- await D(100);
632
- }
633
- }, f = function(e = new Uint8Array([]), t = !1) {
634
- if (e && e.length > 0) {
635
- const n = this.__internal__.serial.connected;
636
- if (this.__internal__.serial.connected = o(this, s, m).call(this, this.__internal__.serial.port), h.$dispatchChange(this), !n && this.__internal__.serial.connected && (this.dispatch("serial:connected"), o(this, s, b).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")
637
- t ? this.serialCorruptMessage(this.parseUint8ToHex(e)) : this.serialMessage(this.parseUint8ToHex(e));
638
- else if (this.__internal__.serial.response.as === "uint8")
639
- t ? this.serialCorruptMessage(e) : this.serialMessage(e);
640
- else if (this.__internal__.serial.response.as === "string") {
641
- const r = this.parseUint8ArrayToString(e);
642
- if (this.__internal__.serial.response.limiter !== null) {
643
- const _ = r.split(this.__internal__.serial.response.limiter);
644
- for (const c in _)
645
- _[c] && (t ? this.serialCorruptMessage(_[c]) : this.serialMessage(_[c]));
646
- } else
647
- t ? this.serialCorruptMessage(r) : this.serialMessage(r);
648
- } else {
649
- const r = this.stringToArrayBuffer(this.parseUint8ArrayToString(e));
650
- t ? this.serialCorruptMessage(r) : this.serialMessage(r);
651
- }
652
- }
653
- this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
654
- }, R = async function() {
655
- const e = this.serialFilters, t = await navigator.serial.getPorts({ filters: e });
656
- return e.length === 0 ? t : t.filter((r) => {
657
- const _ = r.getInfo();
658
- return e.some((c) => _.usbProductId === c.usbProductId && _.usbVendorId === c.usbVendorId);
659
- }).filter((r) => !o(this, s, m).call(this, r));
660
- }, M = function(e) {
661
- if (e) {
662
- const t = this.__internal__.serial.response.buffer, n = new Uint8Array(t.length + e.byteLength);
663
- n.set(t, 0), n.set(new Uint8Array(e), t.length), this.__internal__.serial.response.buffer = n;
664
- }
665
- }, q = async function() {
666
- 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(() => {
667
- this.__internal__.serial.response.buffer && o(this, s, f).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
668
- }, this.__internal__.serial.free_timeout_ms || 50);
669
- }, N = async function() {
670
- const e = this.__internal__.serial.response.length;
671
- let t = this.__internal__.serial.response.buffer;
672
- 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)) {
673
- for (; t.length >= e; ) {
674
- const n = t.slice(0, e);
675
- o(this, s, f).call(this, n), t = t.slice(e);
676
- }
677
- this.__internal__.serial.response.buffer = t, t.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
678
- o(this, s, f).call(this, this.__internal__.serial.response.buffer, !0);
679
- }, this.__internal__.serial.free_timeout_ms || 50));
680
- }
681
- }, O = async function() {
682
- const {
683
- limiter: e,
684
- prefixLimiter: t = !1,
685
- sufixLimiter: n = !0
686
- } = this.__internal__.serial.response;
687
- if (!e)
688
- throw new Error("No limiter defined for delimited serial response");
689
- const r = this.__internal__.serial.response.buffer;
690
- if (!e || !r || r.length === 0) return;
691
- this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
692
- let c = new TextDecoder().decode(r);
693
- const w = [];
694
- if (typeof e == "string") {
695
- let u;
696
- if (t && n)
697
- u = new RegExp(`${e}([^${e}]+)${e}`, "g");
698
- else if (t)
699
- u = new RegExp(`${e}([^${e}]*)`, "g");
700
- else if (n)
701
- u = new RegExp(`([^${e}]+)${e}`, "g");
702
- else
703
- return;
704
- let g, d = 0;
705
- for (; (g = u.exec(c)) !== null; )
706
- w.push(new TextEncoder().encode(g[1])), d = u.lastIndex;
707
- c = c.slice(d);
708
- } else if (e instanceof RegExp) {
709
- let u, g = 0;
710
- if (t && n) {
711
- const d = new RegExp(`${e.source}(.*?)${e.source}`, "g");
712
- for (; (u = d.exec(c)) !== null; )
713
- w.push(new TextEncoder().encode(u[1])), g = d.lastIndex;
714
- } else if (n)
715
- for (; (u = e.exec(c)) !== null; ) {
716
- const d = u.index, x = c.slice(g, d);
717
- w.push(new TextEncoder().encode(x)), g = e.lastIndex;
718
- }
719
- else if (t) {
720
- const d = c.split(e);
721
- d.shift();
722
- for (const x of d)
723
- w.push(new TextEncoder().encode(x));
724
- c = "";
725
- }
726
- c = c.slice(g);
727
- }
728
- for (const u of w)
729
- o(this, s, f).call(this, u);
730
- const L = new TextEncoder().encode(c);
731
- this.__internal__.serial.response.buffer = L, L.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
732
- o(this, s, f).call(this, this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
733
- }, this.__internal__.serial.free_timeout_ms ?? 50));
734
- }, F = async function() {
735
- const e = this.__internal__.serial.port;
736
- if (!e || !e.readable) throw new Error("Port is not readable");
737
- const t = e.readable.getReader();
738
- this.__internal__.serial.reader = t;
739
- try {
740
- for (; this.__internal__.serial.keep_reading; ) {
741
- const { value: n, done: r } = await t.read();
742
- if (r) break;
743
- o(this, s, M).call(this, n), this.__internal__.serial.response.delimited ? await o(this, s, O).call(this) : this.__internal__.serial.response.length === null ? await o(this, s, q).call(this) : await o(this, s, N).call(this);
744
- }
745
- } catch (n) {
746
- this.serialErrors(n);
747
- } finally {
748
- t.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
749
- }
750
- }, b = function(e) {
751
- e !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = e, this.dispatch("serial:connecting", { active: e }), this.dispatch("internal:connecting", { active: e }));
752
- }, H = async function() {
753
- return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
754
- }, j = function() {
755
- [
756
- "serial:connected",
757
- "serial:connecting",
758
- "serial:reconnect",
759
- "serial:timeout",
760
- "serial:disconnected",
761
- "serial:sent",
762
- "serial:soft-reload",
763
- "serial:message",
764
- "serial:corrupt-message",
765
- "unknown",
766
- "serial:need-permission",
767
- "serial:lost",
768
- "serial:unsupported",
769
- "serial:error",
770
- "debug"
771
- ].forEach((t) => {
772
- this.serialRegisterAvailableListener(t);
773
- });
774
- }, W = function() {
775
- const e = this;
776
- this.on("internal:queue", async () => {
777
- var t;
778
- await o(t = e, s, V).call(t);
779
- }), o(this, s, Q).call(this);
780
- }, Q = function() {
781
- const e = this;
782
- navigator.serial.addEventListener("connect", async () => {
783
- e.isDisconnected && await e.serialConnect().catch(() => {
784
- });
785
- });
786
- }, V = async function() {
787
- if (!o(this, s, m).call(this, this.__internal__.serial.port)) {
788
- o(this, s, C).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
789
- return;
790
- }
791
- if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
792
- const e = this.__internal__.serial.queue[0];
793
- let t = this.__internal__.time.response_general;
794
- if (e.action === "connect" && (t = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
795
- await this.timeout(e.bytes, e.action);
796
- }, t), this.__internal__.serial.last_action = e.action ?? "unknown", await o(this, s, A).call(this, e.bytes), this.dispatch("serial:sent", {
797
- action: e.action,
798
- bytes: e.bytes
799
- }), this.__internal__.auto_response) {
800
- let r = new Uint8Array(0);
801
- try {
802
- r = this.validateBytes(this.__internal__.serial.auto_response);
803
- } catch (_) {
804
- this.serialErrors(_);
805
- }
806
- o(this, s, f).call(this, r);
807
- }
808
- const n = [...this.__internal__.serial.queue];
809
- this.__internal__.serial.queue = n.splice(1);
810
- }, z = function(e = 1) {
811
- this.__internal__.device_number = e, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(e));
812
- }, G = function() {
813
- this.__internal__.last_error = {
814
- message: null,
815
- action: null,
816
- code: null,
817
- no_code: 0
818
- };
819
- };
820
834
  export {
821
- Z as Core,
822
- h as Devices,
823
- U as Dispatcher
835
+ b as Core,
836
+ s as Devices,
837
+ y as Dispatcher
824
838
  };
@@ -1,4 +1,4 @@
1
- (function(l,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(l=typeof globalThis<"u"?globalThis:l||self,_(l.WebSerialCore={}))})(this,function(l){"use strict";var Y=Object.defineProperty;var U=l=>{throw TypeError(l)};var Z=(l,_,c)=>_ in l?Y(l,_,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[_]=c;var b=(l,_,c)=>Z(l,typeof _!="symbol"?_+"":_,c),L=(l,_,c)=>_.has(l)||U("Cannot "+c);var x=(l,_,c)=>(L(l,_,"read from private field"),c?c.call(l):_.get(l)),k=(l,_,c)=>_.has(l)?U("Cannot add the same private member more than once"):_ instanceof WeakSet?_.add(l):_.set(l,c),I=(l,_,c,h)=>(L(l,_,"write to private field"),h?h.call(l,c):_.set(l,c),c),o=(l,_,c)=>(L(l,_,"access private method"),c);var g,n,w,T,$,P,R,y,M,q,O,N,F,H,v,j,W,Q,V,z,G,J;class _ extends CustomEvent{constructor(s,e){super(s,e)}}class c extends EventTarget{constructor(){super(...arguments);b(this,"__listeners__",{debug:!1});b(this,"__debug__",!1);b(this,"__listenersCallbacks__",[])}dispatch(e,t=null){const i=new _(e,{detail:t});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new _("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,i=100){const r=this;setTimeout(()=>{r.dispatch(e,t)},i)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.__listenersCallbacks__.push({key:e,callback:t}),this.addEventListener(e,t)}off(e,t){this.__listenersCallbacks__=this.__listenersCallbacks__.filter(i=>!(i.key===e&&i.callback===t)),this.removeEventListener(e,t)}serialRegisterAvailableListener(e){this.__listeners__[e]||(this.__listeners__[e]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(t=>({type:t,listening:this.__listeners__[t]}))}removeAllListeners(){for(const e of this.__listenersCallbacks__)["internal:queue"].includes(e.key)||(this.__listenersCallbacks__=this.__listenersCallbacks__.filter(t=>!(t.key===e.key&&t.callback===e.callback)),this.removeEventListener(e.key,e.callback));for(const e of Object.keys(this.__listeners__))this.__listeners__[e]=!1}}const a=class a extends c{constructor(){super(),["change"].forEach(e=>{this.serialRegisterAvailableListener(e)})}static $dispatchChange(s=null){s&&s.$checkAndDispatchConnection(),a.instance.dispatch("change",{devices:a.devices,dispatcher:s})}static typeError(s){const e=new Error;throw e.message=`Type ${s} is not supported`,e.name="DeviceTypeError",e}static registerType(s){typeof a.devices[s]>"u"&&(a.devices={...a.devices,[s]:{}})}static add(s){const e=s.typeDevice;typeof a.devices[e]>"u"&&a.registerType(e);const t=s.uuid;if(typeof a.devices[e]>"u"&&a.typeError(e),a.devices[e][t])throw new Error(`Device with id ${t} already exists`);return a.devices[e][t]=s,a.$dispatchChange(s),Object.keys(a.devices[e]).indexOf(t)}static get(s,e){return typeof a.devices[s]>"u"&&a.registerType(s),typeof a.devices[s]>"u"&&a.typeError(s),a.devices[s][e]}static getAll(s=null){return s===null?a.devices:(typeof a.devices[s]>"u"&&a.typeError(s),a.devices[s])}static getList(){return Object.values(a.devices).map(e=>Object.values(e)).flat()}static getByNumber(s,e){return typeof a.devices[s]>"u"&&a.typeError(s),Object.values(a.devices[s]).find(i=>i.deviceNumber===e)??null}static getCustom(s,e=1){return typeof a.devices[s]>"u"&&a.typeError(s),Object.values(a.devices[s]).find(i=>i.deviceNumber===e)??null}static async connectToAll(){const s=a.getList();for(const e of s)e.isConnected||await e.connect().catch(console.warn);return Promise.resolve(a.areAllConnected())}static async disconnectAll(){const s=a.getList();for(const e of s)e.isDisconnected||await e.disconnect().catch(console.warn);return Promise.resolve(a.areAllDisconnected())}static async areAllConnected(){const s=a.getList();for(const e of s)if(!e.isConnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async areAllDisconnected(){const s=a.getList();for(const e of s)if(!e.isDisconnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async getAllConnected(){const s=a.getList();return Promise.resolve(s.filter(e=>e.isConnected))}static async getAllDisconnected(){const s=a.getList();return Promise.resolve(s.filter(e=>e.isDisconnected))}};b(a,"instance"),b(a,"devices",{});let h=a;h.instance||(h.instance=new h);function D(S=100){return new Promise(s=>setTimeout(()=>s(),S))}function K(){return"serial"in navigator}const E={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class X extends c{constructor({filters:e=null,config_port:t=E,no_device:i=1,device_listen_on_channel:r=1,bypassSerialBytesConnection:u=!1}={filters:null,config_port:E,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){super();k(this,n);b(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:E,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}});k(this,g,null);if(!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),u&&(this.__internal__.bypassSerialBytesConnection=u),i&&o(this,n,G).call(this,i),r&&["number","string"].includes(typeof r)&&(this.listenOnChannel=r),o(this,n,W).call(this),o(this,n,Q).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=o(this,n,w).call(this,this.__internal__.serial.port);return e&&!t&&o(this,n,T).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=o(this,n,w).call(this,this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),o(this,n,v).call(this,!1),h.$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",{}),h.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,h.$dispatchChange(this),await this.serialConnect()),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),o(this,n,T).call(this,e)}async connect(){return this.isConnected?!0:(this.__internal__.serial.aux_connecting="idle",new Promise((e,t)=>{K()||t("Web Serial not supported"),x(this,g)||I(this,g,o(this,n,$).bind(this)),this.on("internal:connecting",x(this,g));const i=setInterval(()=>{this.__internal__.serial.aux_connecting==="finished"?(clearInterval(i),this.__internal__.serial.aux_connecting="idle",x(this,g)!==null&&this.off("internal:connecting",x(this,g)),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}))},100);this.serialConnect()}))}async serialDisconnect(){try{const e=this.__internal__.serial.reader,t=this.__internal__.serial.output_stream;e&&(await e.cancel().catch(r=>this.serialErrors(r)),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,h.$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 i=this.__internal__.aux_port_connector;this.__internal__.serial.port=e[i]}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",{}),h.$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",{}),h.$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{o(this,n,v).call(this,!0);const e=await o(this,n,M).call(this);if(e.length>0)await this.serialPortsSaved(e);else{const r=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:r})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const i=this;t.onconnect=r=>{var u;i.dispatch("serial:connected",r),o(u=i,n,v).call(u,!1),h.$dispatchChange(this),i.__internal__.serial.queue.length>0&&i.dispatch("internal:queue",{})},t.ondisconnect=async()=>{await i.disconnect()},await D(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await i.timeout(i.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await o(this,n,P).call(this,this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&o(this,n,y).call(this,this.__internal__.serial.auto_response),await o(this,n,H).call(this)}catch(e){o(this,n,v).call(this,!1),this.serialErrors(e)}}async serialForget(){return await o(this,n,j).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((i,r)=>{t[r]="0x"+i}),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 i=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:i,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(i=>{t+=parseInt(i,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(){o(this,n,J).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=`
1
+ (function(_,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(_=typeof globalThis<"u"?globalThis:_||self,h(_.WebSerialCore={}))})(this,function(_){"use strict";class h extends CustomEvent{constructor(e,t){super(e,t)}}class f extends EventTarget{__listeners__={debug:!1};__debug__=!1;__listenersCallbacks__=[];dispatch(e,t=null){const i=new h(e,{detail:t});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new h("debug",{detail:{type:e,data:t}}))}dispatchAsync(e,t=null,i=100){const n=this;setTimeout(()=>{n.dispatch(e,t)},i)}on(e,t){typeof this.__listeners__[e]<"u"&&!this.__listeners__[e]&&(this.__listeners__[e]=!0),this.__listenersCallbacks__.push({key:e,callback:t}),this.addEventListener(e,t)}off(e,t){this.__listenersCallbacks__=this.__listenersCallbacks__.filter(i=>!(i.key===e&&i.callback===t)),this.removeEventListener(e,t)}serialRegisterAvailableListener(e){this.__listeners__[e]||(this.__listeners__[e]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(t=>({type:t,listening:this.__listeners__[t]}))}removeAllListeners(){for(const e of this.__listenersCallbacks__)["internal:queue"].includes(e.key)||(this.__listenersCallbacks__=this.__listenersCallbacks__.filter(t=>!(t.key===e.key&&t.callback===e.callback)),this.removeEventListener(e.key,e.callback));for(const e of Object.keys(this.__listeners__))this.__listeners__[e]=!1}}class s extends f{static instance;static devices={};constructor(){super(),["change"].forEach(t=>{this.serialRegisterAvailableListener(t)})}static $dispatchChange(e=null){e&&e.$checkAndDispatchConnection(),s.instance.dispatch("change",{devices:s.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 s.devices[e]>"u"&&(s.devices={...s.devices,[e]:{}})}static add(e){const t=e.typeDevice;typeof s.devices[t]>"u"&&s.registerType(t);const i=e.uuid;if(typeof s.devices[t]>"u"&&s.typeError(t),s.devices[t][i])throw new Error(`Device with id ${i} already exists`);return s.devices[t][i]=e,s.$dispatchChange(e),Object.keys(s.devices[t]).indexOf(i)}static get(e,t){return typeof s.devices[e]>"u"&&s.registerType(e),typeof s.devices[e]>"u"&&s.typeError(e),s.devices[e][t]}static getAll(e=null){return e===null?s.devices:(typeof s.devices[e]>"u"&&s.typeError(e),s.devices[e])}static getList(){return Object.values(s.devices).map(t=>Object.values(t)).flat()}static getByNumber(e,t){return typeof s.devices[e]>"u"&&s.typeError(e),Object.values(s.devices[e]).find(n=>n.deviceNumber===t)??null}static getCustom(e,t=1){return typeof s.devices[e]>"u"&&s.typeError(e),Object.values(s.devices[e]).find(n=>n.deviceNumber===t)??null}static async connectToAll(){const e=s.getList();for(const t of e)t.isConnected||await t.connect().catch(console.warn);return Promise.resolve(s.areAllConnected())}static async disconnectAll(){const e=s.getList();for(const t of e)t.isDisconnected||await t.disconnect().catch(console.warn);return Promise.resolve(s.areAllDisconnected())}static async areAllConnected(){const e=s.getList();for(const t of e)if(!t.isConnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async areAllDisconnected(){const e=s.getList();for(const t of e)if(!t.isDisconnected)return Promise.resolve(!1);return Promise.resolve(!0)}static async getAllConnected(){const e=s.getList();return Promise.resolve(e.filter(t=>t.isConnected))}static async getAllDisconnected(){const e=s.getList();return Promise.resolve(e.filter(t=>t.isDisconnected))}}s.instance||(s.instance=new s);function y(d=100){return new Promise(e=>setTimeout(()=>e(),d))}function b(){return"serial"in navigator}const p={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};class w extends f{__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:p,queue:[],running_queue:!1,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}};#t=null;constructor({filters:e=null,config_port:t=p,no_device:i=1,device_listen_on_channel:n=1,bypassSerialBytesConnection:a=!1}={filters:null,config_port:p,no_device:1,device_listen_on_channel:1,bypassSerialBytesConnection:!1}){if(super(),!("serial"in navigator))throw new Error("Web Serial not supported");e&&(this.serialFilters=e),t&&(this.serialConfigPort=t),a&&(this.__internal__.bypassSerialBytesConnection=a),i&&this.#b(i),n&&["number","string"].includes(typeof n)&&(this.listenOnChannel=n),this.#p(),this.#g()}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=this.#i(this.__internal__.serial.port);return e&&!t&&this.#s({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=this.#i(this.__internal__.serial.port);return!e&&t&&(this.dispatch("serial:connected"),this.#n(!1),s.$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}#i(e){return!!(e&&e.readable&&e.writable)}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",{}),s.$dispatchChange(this)):t==="connection:start"&&(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,s.$dispatchChange(this),await this.serialConnect()),this.__internal__.serial.queue.length>0&&this.dispatch("internal:queue",{}),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:e,action:t})}async disconnect(e=null){await this.serialDisconnect(),this.#s(e)}#s(e=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",e),s.$dispatchChange(this)}#a(e){this.__internal__.serial.aux_connecting=e.detail.active?"connecting":"finished"}async connect(){return this.isConnected?!0:(this.__internal__.serial.aux_connecting="idle",new Promise((e,t)=>{b()||t("Web Serial not supported"),this.#t||(this.#t=this.#a.bind(this)),this.on("internal:connecting",this.#t);const i=setInterval(()=>{this.__internal__.serial.aux_connecting==="finished"?(clearInterval(i),this.__internal__.serial.aux_connecting="idle",this.#t!==null&&this.off("internal:connecting",this.#t),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}))},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,s.$dispatchChange(this)}}async#r(e){const t=this.__internal__.serial.port;if(!t||t&&(!t.readable||!t.writable))throw this.#s({error:"Port is closed, not readable or writable."}),new Error("The port is closed or is not readable/writable");const i=this.validateBytes(e);if(this.useRTSCTS&&await this.#l(t,5e3),t.writable===null)return;const n=t.writable.getWriter();await n.write(i),n.releaseLock()}async#l(e,t=5e3){const i=Date.now();for(;;){if(Date.now()-i>t)throw new Error("Timeout waiting for clearToSend signal");const{clearToSend:n}=await e.getSignals();if(n)return;await y(100)}}#e(e=new Uint8Array([]),t=!1){if(e&&e.length>0){const i=this.__internal__.serial.connected;if(this.__internal__.serial.connected=this.#i(this.__internal__.serial.port),s.$dispatchChange(this),!i&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),this.#n(!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")t?this.serialCorruptMessage(this.parseUint8ToHex(e)):this.serialMessage(this.parseUint8ToHex(e));else if(this.__internal__.serial.response.as==="uint8")t?this.serialCorruptMessage(e):this.serialMessage(e);else if(this.__internal__.serial.response.as==="string"){const n=this.parseUint8ArrayToString(e);if(this.__internal__.serial.response.limiter!==null){const a=n.split(this.__internal__.serial.response.limiter);for(const r in a)a[r]&&(t?this.serialCorruptMessage(a[r]):this.serialMessage(a[r]))}else t?this.serialCorruptMessage(n):this.serialMessage(n)}else{const n=this.stringToArrayBuffer(this.parseUint8ArrayToString(e));t?this.serialCorruptMessage(n):this.serialMessage(n)}}if(this.__internal__.serial.queue.length===0){this.__internal__.serial.running_queue=!1;return}this.dispatch("internal:queue",{})}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#o(){const e=this.serialFilters,t=await navigator.serial.getPorts({filters:e});return e.length===0?t:t.filter(n=>{const a=n.getInfo();return e.some(r=>a.usbProductId===r.usbProductId&&a.usbVendorId===r.usbVendorId)}).filter(n=>!this.#i(n))}async serialPortsSaved(e){const t=this.serialFilters;if(this.__internal__.aux_port_connector<e.length){const i=this.__internal__.aux_port_connector;this.__internal__.serial.port=e[i]}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",{}),s.$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",{}),s.$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)}#_(e){if(e){const t=this.__internal__.serial.response.buffer,i=new Uint8Array(t.length+e.byteLength);i.set(t,0),i.set(new Uint8Array(e),t.length),this.__internal__.serial.response.buffer=i}}async#c(){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&&this.#e(this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)}async#h(){const e=this.__internal__.serial.response.length;let t=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),!(e===null||!t||t.length===0)){for(;t.length>=e;){const i=t.slice(0,e);this.#e(i),t=t.slice(e)}this.__internal__.serial.response.buffer=t,t.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.#e(this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}}async#u(){const{limiter:e,prefixLimiter:t=!1,sufixLimiter:i=!0}=this.__internal__.serial.response;if(!e)throw new Error("No limiter defined for delimited serial response");const n=this.__internal__.serial.response.buffer;if(!e||!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 r=new TextDecoder().decode(n);const u=[];if(typeof e=="string"){let l;if(t&&i)l=new RegExp(`${e}([^${e}]+)${e}`,"g");else if(t)l=new RegExp(`${e}([^${e}]*)`,"g");else if(i)l=new RegExp(`([^${e}]+)${e}`,"g");else return;let c,o=0;for(;(c=l.exec(r))!==null;)u.push(new TextEncoder().encode(c[1])),o=l.lastIndex;r=r.slice(o)}else if(e instanceof RegExp){let l,c=0;if(t&&i){const o=new RegExp(`${e.source}(.*?)${e.source}`,"g");for(;(l=o.exec(r))!==null;)u.push(new TextEncoder().encode(l[1])),c=o.lastIndex}else if(i)for(;(l=e.exec(r))!==null;){const o=l.index,g=r.slice(c,o);u.push(new TextEncoder().encode(g)),c=e.lastIndex}else if(t){const o=r.split(e);o.shift();for(const g of o)u.push(new TextEncoder().encode(g));r=""}r=r.slice(c)}for(const l of u)this.#e(l);const m=new TextEncoder().encode(r);this.__internal__.serial.response.buffer=m,m.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{this.#e(this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))}async#d(){const e=this.__internal__.serial.port;if(!e||!e.readable)throw new Error("Port is not readable");const t=e.readable.getReader();this.__internal__.serial.reader=t;try{for(;this.__internal__.serial.keep_reading;){const{value:i,done:n}=await t.read();if(n)break;this.#_(i),this.__internal__.serial.response.delimited?await this.#u():this.__internal__.serial.response.length===null?await this.#c():await this.#h()}}catch(i){this.serialErrors(i)}finally{t.releaseLock(),this.__internal__.serial.keep_reading=!0,this.__internal__.serial.port&&await this.__internal__.serial.port.close()}}#n(e){e!==this.__internal__.serial.connecting&&(this.__internal__.serial.connecting=e,this.dispatch("serial:connecting",{active:e}),this.dispatch("internal:connecting",{active:e}))}async serialConnect(){try{this.#n(!0);const e=await this.#o();if(e.length>0)await this.serialPortsSaved(e);else{const n=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:n})}const t=this.__internal__.serial.port;if(!t)throw new Error("No port selected by the user");await t.open(this.serialConfigPort);const i=this;t.onconnect=n=>{i.dispatch("serial:connected",n),i.#n(!1),s.$dispatchChange(this),i.__internal__.serial.queue.length>0?i.dispatch("internal:queue",{}):i.__internal__.serial.running_queue=!1},t.ondisconnect=async()=>{await i.disconnect()},await y(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await i.timeout(i.__internal__.serial.bytes_connection??[],"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await this.#r(this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&this.#e(this.__internal__.serial.auto_response),await this.#d()}catch(e){this.#n(!1),this.serialErrors(e)}}async#f(){return typeof window>"u"?!1:"serial"in navigator&&"forget"in SerialPort.prototype&&this.__internal__.serial.port?(await this.__internal__.serial.port.forget(),!0):!1}async serialForget(){return await this.#f()}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((i,n)=>{t[n]="0x"+i}),t}bytesToHex(e){return this.add0x(Array.from(e,t=>this.hexMaker(t)))}#p(){["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(t=>{this.serialRegisterAvailableListener(t)})}#g(){const e=this;this.on("internal:queue",async()=>{await e.#m()}),this.#y()}#y(){const e=this;navigator.serial.addEventListener("connect",async()=>{e.isDisconnected&&await e.serialConnect().catch(()=>{})})}async#m(){if(!this.#i(this.__internal__.serial.port)){this.#s({error:"Port is closed, not readable or writable."}),await this.serialConnect();return}if(this.__internal__.timeout.until_response)return;if(this.__internal__.serial.queue.length===0){this.__internal__.serial.running_queue=!1;return}this.__internal__.serial.running_queue=!0;const e=this.__internal__.serial.queue[0];let t=this.__internal__.time.response_general;if(e.action==="connect"&&(t=this.__internal__.time.response_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(e.bytes,e.action)},t),this.__internal__.serial.last_action=e.action??"unknown",await this.#r(e.bytes),this.dispatch("serial:sent",{action:e.action,bytes:e.bytes}),this.__internal__.auto_response){let n=new Uint8Array(0);try{n=this.validateBytes(this.__internal__.serial.auto_response)}catch(a){this.serialErrors(a)}this.#e(n)}const i=[...this.__internal__.serial.queue];this.__internal__.serial.queue=i.splice(1),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.running_queue=!0)}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 i=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:i,action:t}),this.dispatch("internal:queue",{})}#b(e=1){this.__internal__.device_number=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))}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'")}#w(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(e){let t=0;return e.forEach(i=>{t+=parseInt(i,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(){this.#w(),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
2
  `){return this.parseStringToTextEncoder(e,t).buffer}parseStringToTextEncoder(e="",t=`
3
3
  `){const i=new TextEncoder;return e+=t,i.encode(e)}parseStringToBytes(e="",t=`
4
- `){const i=this.parseStringToTextEncoder(e,t);return Array.from(i).map(r=>r.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(i=>{const r=i.replace("0x","");t.push(parseInt(r,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 i=e.map(r=>parseInt(r,16));return this.__internal__.serial.response.replacer?String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer,""):String.fromCharCode(...i)}hexToAscii(e){const t=e.toString();let i="";for(let r=0;r<t.length;r+=2)i+=String.fromCharCode(parseInt(t.substring(r,2),16));return i}asciiToHex(e){const t=[];for(let i=0,r=e.length;i<r;i++){const u=Number(e.charCodeAt(i)).toString(16);t.push(u)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}g=new WeakMap,n=new WeakSet,w=function(e){return!!(e&&e.readable&&e.writable)},T=function(e=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",e),h.$dispatchChange(this)},$=function(e){this.__internal__.serial.aux_connecting=e.detail.active?"connecting":"finished"},P=async function(e){const t=this.__internal__.serial.port;if(!t||t&&(!t.readable||!t.writable))throw o(this,n,T).call(this,{error:"Port is closed, not readable or writable."}),new Error("The port is closed or is not readable/writable");const i=this.validateBytes(e);if(this.useRTSCTS&&await o(this,n,R).call(this,t,5e3),t.writable===null)return;const r=t.writable.getWriter();await r.write(i),r.releaseLock()},R=async function(e,t=5e3){const i=Date.now();for(;;){if(Date.now()-i>t)throw new Error("Timeout waiting for clearToSend signal");const{clearToSend:r}=await e.getSignals();if(r)return;await D(100)}},y=function(e=new Uint8Array([]),t=!1){if(e&&e.length>0){const i=this.__internal__.serial.connected;if(this.__internal__.serial.connected=o(this,n,w).call(this,this.__internal__.serial.port),h.$dispatchChange(this),!i&&this.__internal__.serial.connected&&(this.dispatch("serial:connected"),o(this,n,v).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")t?this.serialCorruptMessage(this.parseUint8ToHex(e)):this.serialMessage(this.parseUint8ToHex(e));else if(this.__internal__.serial.response.as==="uint8")t?this.serialCorruptMessage(e):this.serialMessage(e);else if(this.__internal__.serial.response.as==="string"){const r=this.parseUint8ArrayToString(e);if(this.__internal__.serial.response.limiter!==null){const u=r.split(this.__internal__.serial.response.limiter);for(const d in u)u[d]&&(t?this.serialCorruptMessage(u[d]):this.serialMessage(u[d]))}else t?this.serialCorruptMessage(r):this.serialMessage(r)}else{const r=this.stringToArrayBuffer(this.parseUint8ArrayToString(e));t?this.serialCorruptMessage(r):this.serialMessage(r)}}this.__internal__.serial.queue.length!==0&&this.dispatch("internal:queue",{})},M=async function(){const e=this.serialFilters,t=await navigator.serial.getPorts({filters:e});return e.length===0?t:t.filter(r=>{const u=r.getInfo();return e.some(d=>u.usbProductId===d.usbProductId&&u.usbVendorId===d.usbVendorId)}).filter(r=>!o(this,n,w).call(this,r))},q=function(e){if(e){const t=this.__internal__.serial.response.buffer,i=new Uint8Array(t.length+e.byteLength);i.set(t,0),i.set(new Uint8Array(e),t.length),this.__internal__.serial.response.buffer=i}},O=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&&o(this,n,y).call(this,this.__internal__.serial.response.buffer),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms||50)},N=async function(){const e=this.__internal__.serial.response.length;let t=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),!(e===null||!t||t.length===0)){for(;t.length>=e;){const i=t.slice(0,e);o(this,n,y).call(this,i),t=t.slice(e)}this.__internal__.serial.response.buffer=t,t.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{o(this,n,y).call(this,this.__internal__.serial.response.buffer,!0)},this.__internal__.serial.free_timeout_ms||50))}},F=async function(){const{limiter:e,prefixLimiter:t=!1,sufixLimiter:i=!0}=this.__internal__.serial.response;if(!e)throw new Error("No limiter defined for delimited serial response");const r=this.__internal__.serial.response.buffer;if(!e||!r||r.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 d=new TextDecoder().decode(r);const C=[];if(typeof e=="string"){let f;if(t&&i)f=new RegExp(`${e}([^${e}]+)${e}`,"g");else if(t)f=new RegExp(`${e}([^${e}]*)`,"g");else if(i)f=new RegExp(`([^${e}]+)${e}`,"g");else return;let m,p=0;for(;(m=f.exec(d))!==null;)C.push(new TextEncoder().encode(m[1])),p=f.lastIndex;d=d.slice(p)}else if(e instanceof RegExp){let f,m=0;if(t&&i){const p=new RegExp(`${e.source}(.*?)${e.source}`,"g");for(;(f=p.exec(d))!==null;)C.push(new TextEncoder().encode(f[1])),m=p.lastIndex}else if(i)for(;(f=e.exec(d))!==null;){const p=f.index,A=d.slice(m,p);C.push(new TextEncoder().encode(A)),m=e.lastIndex}else if(t){const p=d.split(e);p.shift();for(const A of p)C.push(new TextEncoder().encode(A));d=""}d=d.slice(m)}for(const f of C)o(this,n,y).call(this,f);const B=new TextEncoder().encode(d);this.__internal__.serial.response.buffer=B,B.length>0&&(this.__internal__.serial.time_until_send_bytes=setTimeout(()=>{o(this,n,y).call(this,this.__internal__.serial.response.buffer,!0),this.__internal__.serial.response.buffer=new Uint8Array(0)},this.__internal__.serial.free_timeout_ms??50))},H=async function(){const e=this.__internal__.serial.port;if(!e||!e.readable)throw new Error("Port is not readable");const t=e.readable.getReader();this.__internal__.serial.reader=t;try{for(;this.__internal__.serial.keep_reading;){const{value:i,done:r}=await t.read();if(r)break;o(this,n,q).call(this,i),this.__internal__.serial.response.delimited?await o(this,n,F).call(this):this.__internal__.serial.response.length===null?await o(this,n,O).call(this):await o(this,n,N).call(this)}}catch(i){this.serialErrors(i)}finally{t.releaseLock(),this.__internal__.serial.keep_reading=!0,this.__internal__.serial.port&&await this.__internal__.serial.port.close()}},v=function(e){e!==this.__internal__.serial.connecting&&(this.__internal__.serial.connecting=e,this.dispatch("serial:connecting",{active:e}),this.dispatch("internal:connecting",{active:e}))},j=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},W=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(t=>{this.serialRegisterAvailableListener(t)})},Q=function(){const e=this;this.on("internal:queue",async()=>{var t;await o(t=e,n,z).call(t)}),o(this,n,V).call(this)},V=function(){const e=this;navigator.serial.addEventListener("connect",async()=>{e.isDisconnected&&await e.serialConnect().catch(()=>{})})},z=async function(){if(!o(this,n,w).call(this,this.__internal__.serial.port)){o(this,n,T).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 e=this.__internal__.serial.queue[0];let t=this.__internal__.time.response_general;if(e.action==="connect"&&(t=this.__internal__.time.response_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(e.bytes,e.action)},t),this.__internal__.serial.last_action=e.action??"unknown",await o(this,n,P).call(this,e.bytes),this.dispatch("serial:sent",{action:e.action,bytes:e.bytes}),this.__internal__.auto_response){let r=new Uint8Array(0);try{r=this.validateBytes(this.__internal__.serial.auto_response)}catch(u){this.serialErrors(u)}o(this,n,y).call(this,r)}const i=[...this.__internal__.serial.queue];this.__internal__.serial.queue=i.splice(1)},G=function(e=1){this.__internal__.device_number=e,!this.__internal__.bypassSerialBytesConnection&&(this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e))},J=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}},l.Core=X,l.Devices=h,l.Dispatcher=c,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
4
+ `){const i=this.parseStringToTextEncoder(e,t);return Array.from(i).map(n=>n.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(i=>{const n=i.replace("0x","");t.push(parseInt(n,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 i=e.map(n=>parseInt(n,16));return this.__internal__.serial.response.replacer?String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer,""):String.fromCharCode(...i)}hexToAscii(e){const t=e.toString();let i="";for(let n=0;n<t.length;n+=2)i+=String.fromCharCode(parseInt(t.substring(n,2),16));return i}asciiToHex(e){const t=[];for(let i=0,n=e.length;i<n;i++){const a=Number(e.charCodeAt(i)).toString(16);t.push(a)}return t.join("")}$checkAndDispatchConnection(){return this.isConnected}}_.Core=w,_.Devices=s,_.Dispatcher=f,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "webserial-core",
3
3
  "description": "Webserial Core to easy connections with serial devices",
4
- "version": "1.0.11",
4
+ "version": "1.0.12",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "danidoble",
@@ -45,14 +45,14 @@
45
45
  "format": "prettier --write ./lib/**/*.ts"
46
46
  },
47
47
  "devDependencies": {
48
- "@eslint/js": "^9.30.0",
48
+ "@eslint/js": "^9.34.0",
49
49
  "@types/w3c-web-serial": "^1.0.8",
50
- "eslint": "^9.30.0",
50
+ "eslint": "^9.34.0",
51
51
  "globals": "^15.15.0",
52
52
  "prettier": "3.4.2",
53
53
  "typescript": "~5.7.3",
54
- "typescript-eslint": "^8.35.0",
55
- "vite": "^6.3.5"
54
+ "typescript-eslint": "^8.41.0",
55
+ "vite": "^7.1.3"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"