nsd-ble 0.3.0 → 0.3.2

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.
@@ -1,43 +1,53 @@
1
- import { Data as L, DataType as J, Button as k } from "./enums.js";
2
- let H = !1, B = [], M, ce, U = /* @__PURE__ */ new Map();
3
- async function we(t) {
1
+ import { Data as j, DataType as x, Button as $ } from "./enums.js";
2
+ let M = !1, V = [], A, G, B = /* @__PURE__ */ new Map();
3
+ async function Ce(t) {
4
4
  try {
5
- if (M = await navigator.bluetooth.requestDevice(t), M.gatt === void 0)
5
+ if (A = await navigator.bluetooth.requestDevice(t), A.gatt === void 0)
6
6
  throw new Error("Device does not support GATT");
7
- ce = await M.gatt.connect(), M.addEventListener("gattserverdisconnected", me), H = !0;
7
+ G = await A.gatt.connect(), A.addEventListener("gattserverdisconnected", he), M = !0;
8
8
  } catch (c) {
9
9
  throw c;
10
10
  }
11
11
  }
12
- function me() {
13
- U.clear(), H = !1, B.forEach((t) => t());
12
+ async function Ae() {
13
+ if (M)
14
+ return;
15
+ const t = await navigator.bluetooth.getDevices();
16
+ if (t.length === 0)
17
+ throw new Error("No devices found");
18
+ if (A = t[0], A.gatt === void 0)
19
+ throw new Error("Device does not support GATT");
20
+ G = await A.gatt.connect(), A.addEventListener("gattserverdisconnected", he), M = !0;
21
+ }
22
+ function he() {
23
+ B.clear(), M = !1, V.forEach((t) => t());
14
24
  }
15
- function Ce(t) {
16
- B.push(t);
25
+ function be(t) {
26
+ V.push(t);
17
27
  }
18
- function Ae(t) {
19
- B = B.filter((c) => c !== t);
28
+ function Se(t) {
29
+ V = V.filter((c) => c !== t);
20
30
  }
21
31
  async function X(t, c) {
22
- if (U.has(c)) {
23
- const d = U.get(c);
32
+ if (B.has(c)) {
33
+ const d = B.get(c);
24
34
  if (d === void 0)
25
35
  throw new Error("Characteristic not found");
26
36
  return d;
27
37
  }
28
- const h = await (await ce.getPrimaryService(t)).getCharacteristic(c);
29
- return U.set(c, h), h;
38
+ const h = await (await G.getPrimaryService(t)).getCharacteristic(c);
39
+ return B.set(c, h), h;
30
40
  }
31
- async function be(t, c) {
41
+ async function qe(t, c) {
32
42
  return await (await X(t, c)).readValue();
33
43
  }
34
- async function Se(t, c, r) {
44
+ async function Oe(t, c, r) {
35
45
  const h = new DataView(new ArrayBuffer(r.length));
36
46
  for (let l = 0; l < r.length; l++)
37
47
  h.setUint8(l, r[l]);
38
48
  await (await X(t, c)).writeValue(h);
39
49
  }
40
- async function qe(t, c, r) {
50
+ async function De(t, c, r) {
41
51
  const h = await X(t, c);
42
52
  h.addEventListener(
43
53
  "characteristicvaluechanged",
@@ -47,33 +57,34 @@ async function qe(t, c, r) {
47
57
  }
48
58
  ), await h.startNotifications();
49
59
  }
50
- function he() {
60
+ function le() {
51
61
  return {
52
- connected: H,
53
- connect: we,
54
- readCharacteristic: be,
55
- writeCharacteristic: Se,
56
- subscribe: qe,
57
- setDisconnectCallback: Ce,
58
- removeDisconnectCallback: Ae
62
+ connected: M,
63
+ reconnect: Ae,
64
+ connect: Ce,
65
+ readCharacteristic: qe,
66
+ writeCharacteristic: Oe,
67
+ subscribe: De,
68
+ setDisconnectCallback: be,
69
+ removeDisconnectCallback: Se
59
70
  };
60
71
  }
61
- const le = "19b10000-e8f2-537e-4f6c-d104768a1214", Oe = "6b061bdc-9bc1-4952-a96f-c6ed551b2c3e", Pe = "998ff920-81af-42a9-a915-f88025f9647d", De = {
72
+ const fe = "19b10000-e8f2-537e-4f6c-d104768a1214", Pe = "6b061bdc-9bc1-4952-a96f-c6ed551b2c3e", Le = "998ff920-81af-42a9-a915-f88025f9647d", je = {
62
73
  filters: [{ namePrefix: "BLE-STANDEE" }],
63
- optionalServices: [le]
74
+ optionalServices: [fe]
64
75
  };
65
- function fe() {
76
+ function ve() {
66
77
  return {
67
- serviceUuid: le,
68
- messageCharUuid: Oe,
69
- handshakeCharUuid: Pe,
70
- options: De
78
+ serviceUuid: fe,
79
+ messageCharUuid: Pe,
80
+ handshakeCharUuid: Le,
81
+ options: je
71
82
  };
72
83
  }
73
- var A = {}, q = {}, x;
74
- function V() {
75
- if (x) return q;
76
- x = 1, Object.defineProperty(q, "__esModule", { value: !0 }), q.BaseEvent = void 0;
84
+ var b = {}, O = {}, ee;
85
+ function R() {
86
+ if (ee) return O;
87
+ ee = 1, Object.defineProperty(O, "__esModule", { value: !0 }), O.BaseEvent = void 0;
77
88
  var t = (
78
89
  /** @class */
79
90
  (function() {
@@ -133,12 +144,12 @@ function V() {
133
144
  }, c;
134
145
  })()
135
146
  );
136
- return q.BaseEvent = t, q;
147
+ return O.BaseEvent = t, O;
137
148
  }
138
- var E = {}, ee;
139
- function Q() {
140
- if (ee) return E;
141
- ee = 1;
149
+ var E = {}, te;
150
+ function T() {
151
+ if (te) return E;
152
+ te = 1;
142
153
  var t = E && E.__extends || /* @__PURE__ */ (function() {
143
154
  var l = function(u, o) {
144
155
  return l = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(i, a) {
@@ -156,7 +167,7 @@ function Q() {
156
167
  };
157
168
  })();
158
169
  Object.defineProperty(E, "__esModule", { value: !0 }), E.ErrorSyncEvent = E.VoidSyncEvent = E.SyncEvent = void 0;
159
- var c = V(), r = (
170
+ var c = R(), r = (
160
171
  /** @class */
161
172
  (function(l) {
162
173
  t(u, l);
@@ -186,8 +197,8 @@ function Q() {
186
197
  this._recursion--;
187
198
  }
188
199
  }, u.prototype._attach = function(o, i, a) {
189
- var n, e, s, f, v = (e = (n = this._listeners) === null || n === void 0 ? void 0 : n.length) !== null && e !== void 0 ? e : 0, y = l.prototype._attach.call(this, o, i, a);
190
- return this.evtListenersChanged && v !== ((f = (s = this._listeners) === null || s === void 0 ? void 0 : s.length) !== null && f !== void 0 ? f : 0) && this.evtListenersChanged.post(), y;
200
+ var n, e, s, f, v = (e = (n = this._listeners) === null || n === void 0 ? void 0 : n.length) !== null && e !== void 0 ? e : 0, p = l.prototype._attach.call(this, o, i, a);
201
+ return this.evtListenersChanged && v !== ((f = (s = this._listeners) === null || s === void 0 ? void 0 : s.length) !== null && f !== void 0 ? f : 0) && this.evtListenersChanged.post(), p;
191
202
  }, u.prototype._detach = function() {
192
203
  for (var o, i, a, n, e = [], s = 0; s < arguments.length; s++)
193
204
  e[s] = arguments[s];
@@ -226,11 +237,11 @@ function Q() {
226
237
  );
227
238
  return E.ErrorSyncEvent = d, E;
228
239
  }
229
- var w = {}, T = {}, te;
230
- function $() {
231
- if (te) return T;
232
- te = 1, Object.defineProperty(T, "__esModule", { value: !0 });
233
- var t = Q(), c = (
240
+ var w = {}, U = {}, ne;
241
+ function F() {
242
+ if (ne) return U;
243
+ ne = 1, Object.defineProperty(U, "__esModule", { value: !0 });
244
+ var t = T(), c = (
234
245
  /** @class */
235
246
  (function() {
236
247
  function r() {
@@ -271,12 +282,12 @@ function $() {
271
282
  }, r;
272
283
  })()
273
284
  );
274
- return T.default = c, T;
285
+ return U.default = c, U;
275
286
  }
276
- var ne;
277
- function ve() {
278
- if (ne) return w;
279
- ne = 1;
287
+ var re;
288
+ function de() {
289
+ if (re) return w;
290
+ re = 1;
280
291
  var t = w && w.__extends || /* @__PURE__ */ (function() {
281
292
  var o = function(i, a) {
282
293
  return o = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, e) {
@@ -294,7 +305,7 @@ function ve() {
294
305
  };
295
306
  })();
296
307
  Object.defineProperty(w, "__esModule", { value: !0 }), w.ErrorQueuedEvent = w.VoidQueuedEvent = w.QueuedEvent = void 0;
297
- var c = V(), r = $(), h = Q(), d = (
308
+ var c = R(), r = F(), h = T(), d = (
298
309
  /** @class */
299
310
  (function(o) {
300
311
  t(i, o);
@@ -322,8 +333,8 @@ function ve() {
322
333
  return;
323
334
  this._queued = !0, s.add(function() {
324
335
  a._queued = !1;
325
- for (var v = a._queuedData, y = a._queuedListeners, p = 0; p < y.length; ++p) {
326
- var g = y[p];
336
+ for (var v = a._queuedData, p = a._queuedListeners, y = 0; y < p.length; ++y) {
337
+ var g = p[y];
327
338
  a._call(g, v);
328
339
  }
329
340
  });
@@ -331,20 +342,20 @@ function ve() {
331
342
  var f = this._listeners;
332
343
  s.add(function() {
333
344
  for (var v = 0; v < f.length; ++v) {
334
- var y = f[v];
335
- a._call(y, n);
345
+ var p = f[v];
346
+ a._call(p, n);
336
347
  }
337
348
  });
338
349
  }
339
350
  }
340
351
  }, i.prototype._attach = function(a, n, e) {
341
- var s, f, v, y, p = (f = (s = this._listeners) === null || s === void 0 ? void 0 : s.length) !== null && f !== void 0 ? f : 0, g = o.prototype._attach.call(this, a, n, e);
342
- return this.evtListenersChanged && p !== ((y = (v = this._listeners) === null || v === void 0 ? void 0 : v.length) !== null && y !== void 0 ? y : 0) && this.evtListenersChanged.post(), g;
352
+ var s, f, v, p, y = (f = (s = this._listeners) === null || s === void 0 ? void 0 : s.length) !== null && f !== void 0 ? f : 0, g = o.prototype._attach.call(this, a, n, e);
353
+ return this.evtListenersChanged && y !== ((p = (v = this._listeners) === null || v === void 0 ? void 0 : v.length) !== null && p !== void 0 ? p : 0) && this.evtListenersChanged.post(), g;
343
354
  }, i.prototype._detach = function() {
344
355
  for (var a, n, e, s, f = [], v = 0; v < arguments.length; v++)
345
356
  f[v] = arguments[v];
346
- var y = (n = (a = this._listeners) === null || a === void 0 ? void 0 : a.length) !== null && n !== void 0 ? n : 0, p = o.prototype._detach.apply(this, f);
347
- return this.evtListenersChanged && y !== ((s = (e = this._listeners) === null || e === void 0 ? void 0 : e.length) !== null && s !== void 0 ? s : 0) && this.evtListenersChanged.post(), p;
357
+ var p = (n = (a = this._listeners) === null || a === void 0 ? void 0 : a.length) !== null && n !== void 0 ? n : 0, y = o.prototype._detach.apply(this, f);
358
+ return this.evtListenersChanged && p !== ((s = (e = this._listeners) === null || e === void 0 ? void 0 : e.length) !== null && s !== void 0 ? s : 0) && this.evtListenersChanged.post(), y;
348
359
  }, i;
349
360
  })(c.BaseEvent)
350
361
  );
@@ -378,10 +389,10 @@ function ve() {
378
389
  );
379
390
  return w.ErrorQueuedEvent = u, w;
380
391
  }
381
- var m = {}, re;
382
- function de() {
383
- if (re) return m;
384
- re = 1;
392
+ var m = {}, se;
393
+ function pe() {
394
+ if (se) return m;
395
+ se = 1;
385
396
  var t = m && m.__extends || /* @__PURE__ */ (function() {
386
397
  var u = function(o, i) {
387
398
  return u = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(a, n) {
@@ -399,7 +410,7 @@ function de() {
399
410
  };
400
411
  })();
401
412
  Object.defineProperty(m, "__esModule", { value: !0 }), m.ErrorAsyncEvent = m.VoidAsyncEvent = m.AsyncEvent = void 0;
402
- var c = V(), r = Q(), h = (
413
+ var c = R(), r = T(), h = (
403
414
  /** @class */
404
415
  (function(u) {
405
416
  t(o, u);
@@ -431,8 +442,8 @@ function de() {
431
442
  this._queued = !0, o._scheduler(function() {
432
443
  i._queued = !1;
433
444
  for (var s = i._queuedData, f = i._queuedListeners, v = 0; v < f.length; ++v) {
434
- var y = f[v];
435
- i._call(y, s);
445
+ var p = f[v];
446
+ i._call(p, s);
436
447
  }
437
448
  });
438
449
  } else {
@@ -453,13 +464,13 @@ function de() {
453
464
  this._call(e, i);
454
465
  }
455
466
  }, o.prototype._attach = function(i, a, n) {
456
- var e, s, f, v, y = (s = (e = this._listeners) === null || e === void 0 ? void 0 : e.length) !== null && s !== void 0 ? s : 0, p = u.prototype._attach.call(this, i, a, n);
457
- return this.evtListenersChanged && y !== ((v = (f = this._listeners) === null || f === void 0 ? void 0 : f.length) !== null && v !== void 0 ? v : 0) && this.evtListenersChanged.post(), p;
467
+ var e, s, f, v, p = (s = (e = this._listeners) === null || e === void 0 ? void 0 : e.length) !== null && s !== void 0 ? s : 0, y = u.prototype._attach.call(this, i, a, n);
468
+ return this.evtListenersChanged && p !== ((v = (f = this._listeners) === null || f === void 0 ? void 0 : f.length) !== null && v !== void 0 ? v : 0) && this.evtListenersChanged.post(), y;
458
469
  }, o.prototype._detach = function() {
459
470
  for (var i, a, n, e, s = [], f = 0; f < arguments.length; f++)
460
471
  s[f] = arguments[f];
461
- var v = (a = (i = this._listeners) === null || i === void 0 ? void 0 : i.length) !== null && a !== void 0 ? a : 0, y = u.prototype._detach.apply(this, s);
462
- return this.evtListenersChanged && v !== ((e = (n = this._listeners) === null || n === void 0 ? void 0 : n.length) !== null && e !== void 0 ? e : 0) && this.evtListenersChanged.post(), y;
472
+ var v = (a = (i = this._listeners) === null || i === void 0 ? void 0 : i.length) !== null && a !== void 0 ? a : 0, p = u.prototype._detach.apply(this, s);
473
+ return this.evtListenersChanged && v !== ((e = (n = this._listeners) === null || n === void 0 ? void 0 : n.length) !== null && e !== void 0 ? e : 0) && this.evtListenersChanged.post(), p;
463
474
  }, o._scheduler = o.defaultScheduler, o;
464
475
  })(c.BaseEvent)
465
476
  );
@@ -493,10 +504,10 @@ function de() {
493
504
  );
494
505
  return m.ErrorAsyncEvent = l, m;
495
506
  }
496
- var O = {}, P = {}, se;
497
- function Le() {
498
- if (se) return P;
499
- se = 1, Object.defineProperty(P, "__esModule", { value: !0 }), P.shallowEquals = void 0;
507
+ var D = {}, P = {}, ie;
508
+ function Qe() {
509
+ if (ie) return P;
510
+ ie = 1, Object.defineProperty(P, "__esModule", { value: !0 }), P.shallowEquals = void 0;
500
511
  function t(c, r) {
501
512
  if (c === r)
502
513
  return !0;
@@ -538,15 +549,15 @@ function Le() {
538
549
  }
539
550
  return P.shallowEquals = t, P;
540
551
  }
541
- var ie;
542
- function je() {
543
- return ie || (ie = 1, (function(t) {
544
- var c = O && O.__extends || /* @__PURE__ */ (function() {
552
+ var oe;
553
+ function Me() {
554
+ return oe || (oe = 1, (function(t) {
555
+ var c = D && D.__extends || /* @__PURE__ */ (function() {
545
556
  var n = function(e, s) {
546
557
  return n = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(f, v) {
547
558
  f.__proto__ = v;
548
559
  } || function(f, v) {
549
- for (var y in v) v.hasOwnProperty(y) && (f[y] = v[y]);
560
+ for (var p in v) v.hasOwnProperty(p) && (f[p] = v[p]);
550
561
  }, n(e, s);
551
562
  };
552
563
  return function(e, s) {
@@ -558,7 +569,7 @@ function je() {
558
569
  };
559
570
  })();
560
571
  Object.defineProperty(t, "__esModule", { value: !0 }), t.ErrorAnyEvent = t.VoidAnyEvent = t.AnyEvent = t.EventType = void 0;
561
- var r = Le(), h = Q(), d = de(), l = ve(), u;
572
+ var r = Qe(), h = T(), d = pe(), l = de(), u;
562
573
  (function(n) {
563
574
  n[n.Sync = 0] = "Sync", n[n.Async = 1] = "Async", n[n.Queued = 2] = "Queued";
564
575
  })(u = t.EventType || (t.EventType = {}));
@@ -582,22 +593,22 @@ function je() {
582
593
  e[s] = arguments[s];
583
594
  var f = u.Sync;
584
595
  e.length > 0 && typeof e[0] == "number" && (f = e.shift());
585
- var v = this, y, p, g;
586
- return typeof e[0] == "function" || e[0] && typeof e[0] == "object" && typeof e[0].post == "function" ? (typeof e[0] == "function" ? y = e[0] : g = e[0], p = e[1]) : (v = e[0], y = e[1], p = e[2]), this._attach(f, v, y, g, p, !1);
596
+ var v = this, p, y, g;
597
+ return typeof e[0] == "function" || e[0] && typeof e[0] == "object" && typeof e[0].post == "function" ? (typeof e[0] == "function" ? p = e[0] : g = e[0], y = e[1]) : (v = e[0], p = e[1], y = e[2]), this._attach(f, v, p, g, y, !1);
587
598
  }, n.prototype.once = function() {
588
599
  for (var e = [], s = 0; s < arguments.length; s++)
589
600
  e[s] = arguments[s];
590
601
  var f = u.Sync;
591
602
  e.length > 0 && typeof e[0] == "number" && (f = e.shift());
592
- var v = this, y, p, g;
593
- return typeof e[0] == "function" || e[0] && typeof e[0] == "object" && typeof e[0].post == "function" ? (typeof e[0] == "function" ? y = e[0] : g = e[0], p = e[1]) : (v = e[0], y = e[1], p = e[2]), this._attach(f, v, y, g, p, !0);
594
- }, n.prototype._attach = function(e, s, f, v, y, p) {
595
- var g = this, Y = this.evtFirstAttached ? this.listenerCount() : 0, _;
603
+ var v = this, p, y, g;
604
+ return typeof e[0] == "function" || e[0] && typeof e[0] == "object" && typeof e[0].post == "function" ? (typeof e[0] == "function" ? p = e[0] : g = e[0], y = e[1]) : (v = e[0], p = e[1], y = e[2]), this._attach(f, v, p, g, y, !0);
605
+ }, n.prototype._attach = function(e, s, f, v, p, y) {
606
+ var g = this, z = this.evtFirstAttached ? this.listenerCount() : 0, _;
596
607
  switch (e) {
597
608
  case u.Sync:
598
609
  {
599
- for (var R = 0, z = this._events; R < z.length; R++) {
600
- var C = z[R];
610
+ for (var I = 0, K = this._events; I < K.length; I++) {
611
+ var C = K[I];
601
612
  C instanceof h.SyncEvent && (_ = C);
602
613
  }
603
614
  _ || (_ = new h.SyncEvent(), this._events.push(_));
@@ -605,29 +616,29 @@ function je() {
605
616
  break;
606
617
  case u.Async:
607
618
  {
608
- for (var I = 0, K = this._events; I < K.length; I++) {
609
- var C = K[I];
610
- C instanceof d.AsyncEvent && r.shallowEquals(C.options, y) && (_ = C);
619
+ for (var N = 0, W = this._events; N < W.length; N++) {
620
+ var C = W[N];
621
+ C instanceof d.AsyncEvent && r.shallowEquals(C.options, p) && (_ = C);
611
622
  }
612
- _ || (_ = new d.AsyncEvent(y), this._events.push(_));
623
+ _ || (_ = new d.AsyncEvent(p), this._events.push(_));
613
624
  }
614
625
  break;
615
626
  case u.Queued:
616
627
  {
617
- for (var N = 0, W = this._events; N < W.length; N++) {
618
- var C = W[N];
619
- C instanceof l.QueuedEvent && r.shallowEquals(C.options, y) && (_ = C);
628
+ for (var k = 0, Z = this._events; k < Z.length; k++) {
629
+ var C = Z[k];
630
+ C instanceof l.QueuedEvent && r.shallowEquals(C.options, p) && (_ = C);
620
631
  }
621
- _ || (_ = new l.QueuedEvent(y), this._events.push(_));
632
+ _ || (_ = new l.QueuedEvent(p), this._events.push(_));
622
633
  }
623
634
  break;
624
635
  default:
625
636
  throw new Error("unknown EventType");
626
637
  }
627
- var S;
628
- return p ? v ? S = _.once(v) : S = _.once(s, f) : v ? S = _.attach(v) : S = _.attach(s, f), this.evtFirstAttached && Y === 0 && this.evtFirstAttached.post(), this.evtListenersChanged && Y !== this.listenerCount() && this.evtListenersChanged.post(), function() {
629
- var Z = g.evtLastDetached ? g.listenerCount() : 0;
630
- S(), g.evtLastDetached && Z > 0 && g.listenerCount() === 0 && g.evtLastDetached.post(), g.evtListenersChanged && Z !== g.listenerCount() && g.evtListenersChanged.post();
638
+ var q;
639
+ return y ? v ? q = _.once(v) : q = _.once(s, f) : v ? q = _.attach(v) : q = _.attach(s, f), this.evtFirstAttached && z === 0 && this.evtFirstAttached.post(), this.evtListenersChanged && z !== this.listenerCount() && this.evtListenersChanged.post(), function() {
640
+ var J = g.evtLastDetached ? g.listenerCount() : 0;
641
+ q(), g.evtLastDetached && J > 0 && g.listenerCount() === 0 && g.evtLastDetached.post(), g.evtListenersChanged && J !== g.listenerCount() && g.evtListenersChanged.post();
631
642
  };
632
643
  }, n.prototype.attachSync = function() {
633
644
  for (var e = [], s = 0; s < arguments.length; s++)
@@ -700,22 +711,22 @@ function je() {
700
711
  })(o)
701
712
  );
702
713
  t.ErrorAnyEvent = a;
703
- })(O)), O;
714
+ })(D)), D;
704
715
  }
705
- var oe;
706
- function Qe() {
707
- return oe || (oe = 1, (function(t) {
708
- var c = A && A.__createBinding || (Object.create ? (function(i, a, n, e) {
716
+ var ae;
717
+ function Te() {
718
+ return ae || (ae = 1, (function(t) {
719
+ var c = b && b.__createBinding || (Object.create ? (function(i, a, n, e) {
709
720
  e === void 0 && (e = n), Object.defineProperty(i, e, { enumerable: !0, get: function() {
710
721
  return a[n];
711
722
  } });
712
723
  }) : (function(i, a, n, e) {
713
724
  e === void 0 && (e = n), i[e] = a[n];
714
- })), r = A && A.__exportStar || function(i, a) {
725
+ })), r = b && b.__exportStar || function(i, a) {
715
726
  for (var n in i) n !== "default" && !a.hasOwnProperty(n) && c(a, i, n);
716
727
  };
717
- Object.defineProperty(t, "__esModule", { value: !0 }), t.flush = t.flushOnce = t.queue = void 0, r(V(), t), r(Q(), t), r(ve(), t), r(de(), t), r(je(), t);
718
- var h = $(), d = $();
728
+ Object.defineProperty(t, "__esModule", { value: !0 }), t.flush = t.flushOnce = t.queue = void 0, r(R(), t), r(T(), t), r(de(), t), r(pe(), t), r(Me(), t);
729
+ var h = F(), d = F();
719
730
  Object.defineProperty(t, "EventQueue", { enumerable: !0, get: function() {
720
731
  return d.default;
721
732
  } });
@@ -731,130 +742,130 @@ function Qe() {
731
742
  i === void 0 && (i = 10), h.default.global().flush(i);
732
743
  }
733
744
  t.flush = o;
734
- })(A)), A;
745
+ })(b)), b;
735
746
  }
736
- var b = Qe();
737
- class Me {
747
+ var S = Te();
748
+ class Ue {
738
749
  id;
739
750
  data;
740
751
  constructor(c, r) {
741
752
  this.id = c, this.data = r;
742
753
  }
743
754
  }
744
- const { serviceUuid: Te, messageCharUuid: Ue } = fe(), ye = new b.SyncEvent(), pe = new b.SyncEvent(), ge = new b.SyncEvent(), _e = new b.SyncEvent();
745
- function Be() {
755
+ const { serviceUuid: Be, messageCharUuid: Ve } = ve(), ye = new S.SyncEvent(), ge = new S.SyncEvent(), _e = new S.SyncEvent(), Ee = new S.SyncEvent();
756
+ function Re() {
746
757
  return new Promise((t, c) => {
747
- he().subscribe(Te, Ue, Ve).then(() => t()).catch((r) => c(r));
758
+ le().subscribe(Be, Ve, Ie).then(() => t()).catch((r) => c(r));
748
759
  });
749
760
  }
750
- function Ve(t) {
751
- t !== void 0 && (t.getUint8(L.TYPE) === J.BUTTON_PRESS && Re(t), t.getUint8(L.TYPE) === J.MESSAGE_DONE && _e.post(t.getUint8(L.DATA)));
761
+ function Ie(t) {
762
+ t !== void 0 && (t.getUint8(j.TYPE) === x.BUTTON_PRESS && Ne(t), t.getUint8(j.TYPE) === x.MESSAGE_DONE && Ee.post(t.getUint8(j.DATA)));
752
763
  }
753
- function Re(t) {
754
- const c = t.getUint8(L.DATA), r = new Me(
755
- t.getUint8(L.ID),
756
- Ie(t)
764
+ function Ne(t) {
765
+ const c = t.getUint8(j.DATA), r = new Ue(
766
+ t.getUint8(j.ID),
767
+ ke(t)
757
768
  );
758
- c === k.MINUS && pe.post(r), c === k.PLUS && ye.post(r), c === k.EITHER && ge.post(r);
769
+ c === $.MINUS && ge.post(r), c === $.PLUS && ye.post(r), c === $.EITHER && _e.post(r);
759
770
  }
760
- function Ie(t) {
771
+ function ke(t) {
761
772
  const c = t.buffer, r = 7, h = t.byteLength - 7;
762
773
  return Array.from(new Uint8Array(c, r, h)).map((d) => String.fromCharCode(d)).join("").replace(/\0/g, "").trim();
763
774
  }
764
- function Ne() {
775
+ function $e() {
765
776
  return {
766
- subscribe: Be,
777
+ subscribe: Re,
767
778
  onPlusButton: ye,
768
- onMinButton: pe,
769
- onEitherButton: ge,
770
- onMessageDone: _e
779
+ onMinButton: ge,
780
+ onEitherButton: _e,
781
+ onMessageDone: Ee
771
782
  };
772
783
  }
773
- const j = [];
774
- function ke() {
784
+ const Q = [];
785
+ function Fe() {
775
786
  let t = Math.floor(Math.random() * 256);
776
- for (; j.includes(t); ) t = Math.floor(Math.random() * 256);
787
+ for (; Q.includes(t); ) t = Math.floor(Math.random() * 256);
777
788
  return t;
778
789
  }
779
- function $e(t) {
780
- j.push(t), Fe();
781
- }
782
- function Fe() {
783
- j.length <= 20 || j.splice(0, j.length - 20);
790
+ function He(t) {
791
+ Q.push(t), Ge();
784
792
  }
785
- function He() {
786
- const t = ke();
787
- return $e(t), t;
793
+ function Ge() {
794
+ Q.length <= 20 || Q.splice(0, Q.length - 20);
788
795
  }
789
796
  function Xe() {
797
+ const t = Fe();
798
+ return He(t), t;
799
+ }
800
+ function Ye() {
790
801
  return {
791
- create: He
802
+ create: Xe
792
803
  };
793
804
  }
794
- const { serviceUuid: Ge, messageCharUuid: Ye } = fe(), { onMessageDone: ze } = Ne(), Ke = he(), Ee = [], F = /* @__PURE__ */ new Map();
795
- let D = !1;
796
- ze.attach(Ze);
797
- function We(t) {
798
- return t.packets.forEach((c) => Ee.push(c)), new Promise((c) => {
799
- F.set(t.cache, () => {
805
+ const { serviceUuid: ze, messageCharUuid: Ke } = ve(), { onMessageDone: We } = $e(), Ze = le(), we = [], H = /* @__PURE__ */ new Map(), me = /* @__PURE__ */ new Map();
806
+ let L = !1;
807
+ We.attach(xe);
808
+ function Je(t) {
809
+ return t.packets.forEach((c) => we.push(c)), me.set(t.cache, t.packets), new Promise((c) => {
810
+ H.set(t.cache, () => {
800
811
  t.resolve?.(), c();
801
- }), D || G();
812
+ }), L || Y();
802
813
  });
803
814
  }
804
- function G() {
805
- if (D)
815
+ function Y() {
816
+ if (L)
806
817
  return;
807
- const t = Ee.shift();
818
+ const t = we.shift();
808
819
  if (t == null) {
809
- D = !1;
820
+ L = !1;
810
821
  return;
811
822
  }
812
- D = !0, Ke.writeCharacteristic(Ge, Ye, t).catch((c) => console.log(c)).finally(() => {
813
- D = !1, G();
823
+ L = !0, Ze.writeCharacteristic(ze, Ke, t).catch((c) => console.log(c)).finally(() => {
824
+ L = !1, Y();
814
825
  });
815
826
  }
816
- function Ze(t) {
817
- F.get(t)?.(), F.delete(t), G();
827
+ function xe(t) {
828
+ H.get(t)?.(), H.delete(t), me.delete(t), Y();
818
829
  }
819
- function Je() {
820
- return { write: We };
830
+ function et() {
831
+ return { write: Je };
821
832
  }
822
- const ae = 10, ue = 15;
823
- function xe(t) {
833
+ const ue = 10, ce = 15;
834
+ function tt(t) {
824
835
  if (t.data == null) {
825
- let d = [t.id, t.cache, ae, 0, 2, t.type, 0];
836
+ let d = [t.id, t.cache, ue, 0, 2, t.type, 0];
826
837
  return [new Uint8Array(d)];
827
838
  }
828
839
  const c = new Uint8Array(2 + t.data.length), r = t.data.length + 2, h = [];
829
840
  c.set([t.type, r], 0), c.set(t.data, 2);
830
- for (let d = 0; d < r; d += ue) {
831
- const l = Math.min(ue, r - d), u = new Uint8Array(l), o = [t.id, t.cache, ae, d, r];
841
+ for (let d = 0; d < r; d += ce) {
842
+ const l = Math.min(ce, r - d), u = new Uint8Array(l), o = [t.id, t.cache, ue, d, r];
832
843
  u.set(c.subarray(d, d + l), 0), h.push(new Uint8Array([...o, ...u]));
833
844
  }
834
845
  return h;
835
846
  }
836
- class tt {
837
- cache = Xe().create();
847
+ class rt {
848
+ cache = Ye().create();
838
849
  type;
839
850
  id;
840
851
  data;
841
852
  packets = [];
842
853
  resolve;
843
854
  constructor(c, r, h) {
844
- this.type = c, this.id = r, this.data = h, this.packets = xe(this);
855
+ this.type = c, this.id = r, this.data = h, this.packets = tt(this);
845
856
  }
846
857
  send() {
847
- return Je().write(this);
858
+ return et().write(this);
848
859
  }
849
860
  then(c) {
850
861
  return this.resolve = c, this;
851
862
  }
852
863
  }
853
- class nt {
864
+ class st {
854
865
  id;
855
866
  elements = [];
856
- onPlus = new b.SyncEvent();
857
- onMin = new b.SyncEvent();
867
+ onPlus = new S.SyncEvent();
868
+ onMin = new S.SyncEvent();
858
869
  constructor(c) {
859
870
  this.id = c;
860
871
  }
@@ -863,11 +874,11 @@ class nt {
863
874
  }
864
875
  }
865
876
  export {
866
- tt as B,
867
- nt as S,
868
- fe as a,
869
- Ne as b,
870
- Me as c,
871
- b as l,
872
- he as u
877
+ rt as B,
878
+ st as S,
879
+ ve as a,
880
+ $e as b,
881
+ Ue as c,
882
+ S as l,
883
+ le as u
873
884
  };