nsd-ble 0.3.3 → 0.4.1
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/README.md +887 -0
- package/dist/Objects-Zntmn07s.cjs +1 -0
- package/dist/Objects-ulh5Kfet.js +1043 -0
- package/dist/main.cjs +1 -1
- package/dist/main.js +641 -287
- package/dist/objects.cjs +1 -1
- package/dist/objects.js +1 -1
- package/dist/types/Types.d.ts +99 -0
- package/dist/types/ble/BluetoothProvider.d.ts +9 -0
- package/dist/types/ble/Mesh.d.ts +14 -9
- package/dist/types/ble/MeshWriter.d.ts +8 -0
- package/dist/types/ble/MockBluetooth.d.ts +25 -0
- package/dist/types/ble/Settings.d.ts +4 -0
- package/dist/types/composable/Debug.d.ts +26 -0
- package/dist/types/main.d.ts +3 -1
- package/dist/types/standee/Loader.d.ts +5 -0
- package/package.json +1 -1
- package/dist/Objects-C2BH61j-.js +0 -941
- package/dist/Objects-WdcC281c.cjs +0 -1
- package/readme.md +0 -30
package/dist/main.js
CHANGED
|
@@ -1,192 +1,234 @@
|
|
|
1
|
-
import { l as
|
|
2
|
-
import { Data as
|
|
3
|
-
import { Image as
|
|
4
|
-
class
|
|
1
|
+
import { l as I, u as x, a as O, b as Z, c as Q, d as tt, B, S as mt, s as et } from "./Objects-ulh5Kfet.js";
|
|
2
|
+
import { Data as i, DataType as f, ActionType as A, ActionDataType as U, FloodTypes as v, Button as G } from "./enums.js";
|
|
3
|
+
import { Image as yt, Rectangle as Et, Text as Tt } from "./elements.js";
|
|
4
|
+
class Dt {
|
|
5
5
|
data = [];
|
|
6
6
|
size = 0;
|
|
7
7
|
total = 0;
|
|
8
8
|
}
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
return
|
|
9
|
+
const j = 7, _ = /* @__PURE__ */ new Map();
|
|
10
|
+
function It(t) {
|
|
11
|
+
return _.get(t);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
13
|
+
function Ut(t) {
|
|
14
|
+
_.delete(t);
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
const e = t.getUint8(
|
|
18
|
-
if (!
|
|
19
|
-
const
|
|
20
|
-
|
|
16
|
+
function Ct(t) {
|
|
17
|
+
const e = t.getUint8(i.CACHE), o = t.getUint16(i.DATA_SIZE, !0), n = t.getUint16(i.POSITION, !0), r = t.byteLength - j;
|
|
18
|
+
if (!_.has(e)) {
|
|
19
|
+
const a = new Dt();
|
|
20
|
+
a.size = o, _.set(e, a);
|
|
21
21
|
}
|
|
22
|
-
const s =
|
|
23
|
-
for (let
|
|
24
|
-
s.data[
|
|
25
|
-
s.total +=
|
|
22
|
+
const s = _.get(e);
|
|
23
|
+
for (let a = 0; a < r; a++)
|
|
24
|
+
s.data[a + n] = t.getUint8(j + a);
|
|
25
|
+
s.total += r;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const e =
|
|
27
|
+
function St(t) {
|
|
28
|
+
const e = _.get(t);
|
|
29
29
|
return e.total == e.size || e.size == 0;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
return { add:
|
|
31
|
+
function bt() {
|
|
32
|
+
return { add: Ct, get: It, remove: Ut, isDone: St };
|
|
33
33
|
}
|
|
34
|
-
const { serviceUuid:
|
|
35
|
-
function
|
|
34
|
+
const { serviceUuid: _t, handshakeCharUuid: Nt } = O(), nt = new I.SyncEvent(), { add: Rt, get: xt, remove: Bt, isDone: Pt } = bt();
|
|
35
|
+
function Lt() {
|
|
36
36
|
return new Promise((t, e) => {
|
|
37
|
-
|
|
37
|
+
x().subscribe(_t, Nt, Mt).then(() => t()).catch((o) => e(o));
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function Mt(t) {
|
|
41
41
|
console.log(t, t.buffer.byteLength);
|
|
42
|
-
const e = t.getUint8(
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
function
|
|
46
|
-
const e =
|
|
47
|
-
let
|
|
48
|
-
for (;
|
|
49
|
-
const
|
|
50
|
-
for (let
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
const e = t.getUint8(i.CACHE);
|
|
43
|
+
Rt(t), Pt(e) && (nt.post(Ot(e)), Bt(e));
|
|
44
|
+
}
|
|
45
|
+
function Ot(t) {
|
|
46
|
+
const e = xt(t), o = /* @__PURE__ */ new Map();
|
|
47
|
+
let n = 1;
|
|
48
|
+
for (; n < e.size; ) {
|
|
49
|
+
const r = e.data[n++], s = e.data[n++], a = [];
|
|
50
|
+
for (let c = 0; c < s; c++)
|
|
51
|
+
a.push(e.data[n++]);
|
|
52
|
+
o.set(r, a);
|
|
53
53
|
}
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
function S() {
|
|
57
|
-
return { subscribe: Q, onNodes: C };
|
|
54
|
+
return o;
|
|
58
55
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
function ot() {
|
|
57
|
+
return { subscribe: Lt, onNodes: nt };
|
|
58
|
+
}
|
|
59
|
+
const { onNodes: vt } = ot(), { onMessageDone: kt, onNode: $t, onNodeLost: zt } = Z(), { onPlusButton: Ht, onMinButton: Ft, onEitherButton: Gt } = Q(), {
|
|
60
|
+
connect: Wt,
|
|
61
|
+
reconnect: rt,
|
|
62
|
+
onConnect: Vt,
|
|
63
|
+
onDisconnect: st
|
|
64
|
+
} = x(), it = new I.SyncEvent(), at = new I.SyncEvent();
|
|
65
|
+
let k = !1, b = !1, N = !1;
|
|
66
|
+
st.attach(() => {
|
|
67
|
+
k && !b && (tt().abortAll(new Error("BLE disconnected")), Kt());
|
|
68
|
+
});
|
|
69
|
+
async function Zt() {
|
|
70
|
+
N = !0, await Wt(O().options), await Y(), k = !0;
|
|
71
|
+
}
|
|
72
|
+
async function Yt() {
|
|
73
|
+
N = !0, await rt(), await Y(), k = !0;
|
|
74
|
+
}
|
|
75
|
+
function Y() {
|
|
76
|
+
return Promise.all([
|
|
77
|
+
ot().subscribe(),
|
|
78
|
+
Q().subscribe(),
|
|
79
|
+
Z().subscribe()
|
|
80
|
+
]).then(() => {
|
|
68
81
|
});
|
|
69
82
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
async function Kt() {
|
|
84
|
+
const { RECONNECT_DELAY: t, RECONNECT_MAX_RETRIES: e } = O();
|
|
85
|
+
b = !0, N = !1;
|
|
86
|
+
for (let o = 1; o <= e; o++) {
|
|
87
|
+
const n = Math.min(
|
|
88
|
+
t * Math.pow(2, o - 1),
|
|
89
|
+
3e4
|
|
90
|
+
);
|
|
91
|
+
if (it.post({ attempt: o, maxRetries: e, delay: n }), await qt(n), N) {
|
|
92
|
+
b = !1, N = !1;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
await rt(), await Y(), b = !1;
|
|
97
|
+
return;
|
|
98
|
+
} catch (r) {
|
|
99
|
+
console.warn(
|
|
100
|
+
`Auto-reconnect attempt ${o}/${e} failed:`,
|
|
101
|
+
r
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
b = !1, at.post();
|
|
106
|
+
}
|
|
107
|
+
function qt(t) {
|
|
108
|
+
return new Promise((e) => setTimeout(e, t));
|
|
74
109
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
S().subscribe(),
|
|
78
|
-
B().subscribe(),
|
|
79
|
-
D().subscribe()
|
|
80
|
-
]).then(t);
|
|
110
|
+
function Xt() {
|
|
111
|
+
k = !1, b = !1, N = !1;
|
|
81
112
|
}
|
|
82
|
-
function
|
|
113
|
+
function jt() {
|
|
83
114
|
return {
|
|
84
|
-
connect:
|
|
85
|
-
onConnect:
|
|
86
|
-
onDisconnect:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
115
|
+
connect: Zt,
|
|
116
|
+
onConnect: Vt,
|
|
117
|
+
onDisconnect: st,
|
|
118
|
+
onReconnecting: it,
|
|
119
|
+
onReconnectFailed: at,
|
|
120
|
+
reconnect: Yt,
|
|
121
|
+
onNodes: vt,
|
|
122
|
+
onNode: $t,
|
|
123
|
+
onNodeLost: zt,
|
|
124
|
+
onPlusButton: Ht,
|
|
125
|
+
onMinButton: Ft,
|
|
126
|
+
onEitherButton: Gt,
|
|
127
|
+
onMessageDone: kt,
|
|
128
|
+
_resetForTesting: Xt
|
|
95
129
|
};
|
|
96
130
|
}
|
|
97
|
-
function
|
|
131
|
+
function hn(t) {
|
|
98
132
|
return {
|
|
99
|
-
upload: (e,
|
|
100
|
-
const
|
|
101
|
-
return
|
|
133
|
+
upload: (e, o) => {
|
|
134
|
+
const n = new Uint8Array(o.length + 1);
|
|
135
|
+
return n.set([e], 0), n.set(o, 1), new B(f.UPLOAD, t.id, n);
|
|
102
136
|
},
|
|
103
|
-
clear: () => new
|
|
137
|
+
clear: () => new B(f.CLEAR_GRAPHICS, t.id)
|
|
104
138
|
};
|
|
105
139
|
}
|
|
106
|
-
class
|
|
140
|
+
class Jt {
|
|
107
141
|
id;
|
|
108
142
|
buffers;
|
|
109
143
|
totalPackets = 0;
|
|
110
|
-
onProgress = new
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
144
|
+
onProgress = new I.SyncEvent();
|
|
145
|
+
onError = new I.SyncEvent();
|
|
146
|
+
constructor(e, o) {
|
|
147
|
+
this.id = o, this.buffers = e, this.buffers.forEach((n) => {
|
|
148
|
+
this.totalPackets += n.packets.length;
|
|
114
149
|
});
|
|
115
150
|
}
|
|
116
151
|
async send() {
|
|
117
|
-
const e = this.totalPackets & 255,
|
|
118
|
-
let
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
152
|
+
const e = this.totalPackets & 255, o = this.totalPackets >> 8 & 255, n = new Uint8Array([e, o]), r = new B(f.LOADER, this.id, n), s = this.buffers.length;
|
|
153
|
+
let a = 0;
|
|
154
|
+
try {
|
|
155
|
+
await r.send();
|
|
156
|
+
for (const c of this.buffers)
|
|
157
|
+
await c.send(), a++, this.onProgress.post({
|
|
158
|
+
current: a,
|
|
159
|
+
total: s,
|
|
160
|
+
percentage: a / s
|
|
161
|
+
});
|
|
162
|
+
} catch (c) {
|
|
163
|
+
throw this.onError.post({
|
|
164
|
+
buffer: a,
|
|
165
|
+
error: c
|
|
166
|
+
}), c;
|
|
167
|
+
}
|
|
126
168
|
}
|
|
127
169
|
}
|
|
128
|
-
function
|
|
170
|
+
function gn(t) {
|
|
129
171
|
return {
|
|
130
|
-
load: (e) => new
|
|
172
|
+
load: (e) => new Jt(e, t.id)
|
|
131
173
|
};
|
|
132
174
|
}
|
|
133
|
-
const { onNodes:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
function
|
|
175
|
+
const { onNodes: Qt, onNode: te, onNodeLost: ee } = jt();
|
|
176
|
+
Qt.attach(ne);
|
|
177
|
+
te.attach(oe);
|
|
178
|
+
ee.attach(re);
|
|
179
|
+
const w = [], $ = new I.SyncEvent();
|
|
180
|
+
function ne(t) {
|
|
139
181
|
console.log("standees", t);
|
|
140
|
-
for (const [e,
|
|
141
|
-
|
|
142
|
-
|
|
182
|
+
for (const [e, o] of t)
|
|
183
|
+
ct(e), w.find((n) => n.id === e).neighbors = o;
|
|
184
|
+
$.post(w);
|
|
143
185
|
}
|
|
144
|
-
function
|
|
186
|
+
function oe(t) {
|
|
145
187
|
console.log("nodes", t);
|
|
146
|
-
const e = t.keys().next().value,
|
|
147
|
-
|
|
188
|
+
const e = t.keys().next().value, o = t.get(e);
|
|
189
|
+
ct(e), w.find((n) => n.id === e).neighbors = o, $.post(w);
|
|
148
190
|
}
|
|
149
|
-
function
|
|
150
|
-
|
|
191
|
+
function re(t) {
|
|
192
|
+
se(t), $.post(w);
|
|
151
193
|
}
|
|
152
|
-
function
|
|
153
|
-
|
|
194
|
+
function ct(t) {
|
|
195
|
+
w.some((e) => e.id === t) || w.push(new mt(t));
|
|
154
196
|
}
|
|
155
|
-
function
|
|
156
|
-
const e =
|
|
157
|
-
e !== -1 &&
|
|
197
|
+
function se(t) {
|
|
198
|
+
const e = w.findIndex((o) => o.id === t);
|
|
199
|
+
e !== -1 && w.splice(e, 1);
|
|
158
200
|
}
|
|
159
|
-
function
|
|
160
|
-
return { standees:
|
|
201
|
+
function An() {
|
|
202
|
+
return { standees: w, onChange: $ };
|
|
161
203
|
}
|
|
162
|
-
function
|
|
204
|
+
function ie(t) {
|
|
163
205
|
const e = () => {
|
|
164
|
-
let
|
|
165
|
-
return n
|
|
166
|
-
},
|
|
206
|
+
let n = Math.floor(Math.random() * 256);
|
|
207
|
+
return o(n) ? e() : n;
|
|
208
|
+
}, o = (n) => t.some((r) => r.id === n);
|
|
167
209
|
return { generate: e };
|
|
168
210
|
}
|
|
169
|
-
function
|
|
170
|
-
return { add: (
|
|
211
|
+
function wn(t) {
|
|
212
|
+
return { add: (n) => (n.id = ie(t.elements).generate(), t.elements.push(n), n), remove: (n) => {
|
|
171
213
|
t.elements = t.elements.filter(
|
|
172
|
-
(
|
|
214
|
+
(r) => r.id !== n
|
|
173
215
|
);
|
|
174
216
|
} };
|
|
175
217
|
}
|
|
176
|
-
function
|
|
177
|
-
return new
|
|
218
|
+
function ae(t) {
|
|
219
|
+
return new B(f.CLEAR_SCREEN, t.id);
|
|
178
220
|
}
|
|
179
|
-
function
|
|
221
|
+
function ce(t) {
|
|
180
222
|
let e = new Uint8Array();
|
|
181
|
-
for (const
|
|
182
|
-
|
|
183
|
-
return new
|
|
223
|
+
for (const o of t.elements)
|
|
224
|
+
o.dirty !== !1 && (o instanceof yt && (e = W(e, ue(o))), o instanceof Et && (e = W(e, fe(o))), o instanceof Tt && (e = W(e, le(o))), o.dirty = !1);
|
|
225
|
+
return new B(f.ALL, t.id, e);
|
|
184
226
|
}
|
|
185
|
-
function
|
|
186
|
-
const
|
|
187
|
-
return
|
|
227
|
+
function W(t, e) {
|
|
228
|
+
const o = new Uint8Array(t.length + e.length);
|
|
229
|
+
return o.set(t, 0), o.set(e, t.length), o;
|
|
188
230
|
}
|
|
189
|
-
function
|
|
231
|
+
function ue(t) {
|
|
190
232
|
return new Uint8Array([
|
|
191
233
|
f.DRAW_IMAGE,
|
|
192
234
|
7,
|
|
@@ -199,7 +241,7 @@ function Nt(t) {
|
|
|
199
241
|
t.data
|
|
200
242
|
]);
|
|
201
243
|
}
|
|
202
|
-
function
|
|
244
|
+
function fe(t) {
|
|
203
245
|
return new Uint8Array([
|
|
204
246
|
f.DRAW_RECTANGLE,
|
|
205
247
|
9,
|
|
@@ -214,9 +256,9 @@ function Dt(t) {
|
|
|
214
256
|
t.colorBlack ? 0 : 1
|
|
215
257
|
]);
|
|
216
258
|
}
|
|
217
|
-
function
|
|
218
|
-
const e = new TextEncoder().encode(t.text),
|
|
219
|
-
return
|
|
259
|
+
function le(t) {
|
|
260
|
+
const e = new TextEncoder().encode(t.text), o = new Uint8Array(9 + e.length);
|
|
261
|
+
return o.set(
|
|
220
262
|
[
|
|
221
263
|
f.DRAW_TEXT,
|
|
222
264
|
7 + e.length,
|
|
@@ -229,50 +271,50 @@ function Bt(t) {
|
|
|
229
271
|
t.center ? 1 : 0
|
|
230
272
|
],
|
|
231
273
|
0
|
|
232
|
-
),
|
|
233
|
-
}
|
|
234
|
-
function
|
|
235
|
-
return { clear:
|
|
236
|
-
}
|
|
237
|
-
function
|
|
238
|
-
const
|
|
239
|
-
for (let s = 0; s <
|
|
240
|
-
for (let
|
|
241
|
-
let
|
|
242
|
-
for (let
|
|
243
|
-
const
|
|
244
|
-
|
|
274
|
+
), o.set(e, 9), o;
|
|
275
|
+
}
|
|
276
|
+
function pn() {
|
|
277
|
+
return { clear: ae, draw: ce };
|
|
278
|
+
}
|
|
279
|
+
function de(t, e) {
|
|
280
|
+
const o = Math.ceil(t.length / e), n = Math.ceil(e / 8), r = new Uint8Array(n * o);
|
|
281
|
+
for (let s = 0; s < o; s++)
|
|
282
|
+
for (let a = 0; a < n; a++) {
|
|
283
|
+
let c = 0;
|
|
284
|
+
for (let u = 0; u < 8; u++) {
|
|
285
|
+
const l = a * 8 + u, E = s * e + l;
|
|
286
|
+
l < e && E < t.length && t[E] && (c |= 1 << 7 - u);
|
|
245
287
|
}
|
|
246
|
-
|
|
288
|
+
r[s * n + a] = ut(c);
|
|
247
289
|
}
|
|
248
|
-
return
|
|
290
|
+
return r;
|
|
249
291
|
}
|
|
250
|
-
function
|
|
292
|
+
function ut(t) {
|
|
251
293
|
return t = (t & 240) >> 4 | (t & 15) << 4, t = (t & 204) >> 2 | (t & 51) << 2, t = (t & 170) >> 1 | (t & 85) << 1, t;
|
|
252
294
|
}
|
|
253
|
-
function
|
|
254
|
-
const e = t.reduce((
|
|
255
|
-
let
|
|
256
|
-
for (const
|
|
257
|
-
|
|
258
|
-
return
|
|
295
|
+
function he(t) {
|
|
296
|
+
const e = t.reduce((r, s) => r + s.length, 0), o = new Uint8Array(e);
|
|
297
|
+
let n = 0;
|
|
298
|
+
for (const r of t)
|
|
299
|
+
o.set(r, n), n += r.length;
|
|
300
|
+
return o;
|
|
259
301
|
}
|
|
260
|
-
function
|
|
302
|
+
function K() {
|
|
261
303
|
return {
|
|
262
|
-
pixelsToBytes:
|
|
263
|
-
bitswap:
|
|
264
|
-
flattenUint8Arrays:
|
|
304
|
+
pixelsToBytes: de,
|
|
305
|
+
bitswap: ut,
|
|
306
|
+
flattenUint8Arrays: he
|
|
265
307
|
};
|
|
266
308
|
}
|
|
267
|
-
const { flattenUint8Arrays:
|
|
268
|
-
class
|
|
309
|
+
const { flattenUint8Arrays: ft } = K();
|
|
310
|
+
class T {
|
|
269
311
|
element_id;
|
|
270
312
|
property;
|
|
271
|
-
constructor(e,
|
|
272
|
-
this.element_id = e, this.property =
|
|
313
|
+
constructor(e, o) {
|
|
314
|
+
this.element_id = e, this.property = o;
|
|
273
315
|
}
|
|
274
316
|
}
|
|
275
|
-
class
|
|
317
|
+
class p {
|
|
276
318
|
target;
|
|
277
319
|
constructor(e) {
|
|
278
320
|
this.target = e;
|
|
@@ -281,85 +323,85 @@ class h {
|
|
|
281
323
|
return new Uint8Array();
|
|
282
324
|
}
|
|
283
325
|
}
|
|
284
|
-
class
|
|
326
|
+
class ge extends p {
|
|
285
327
|
format() {
|
|
286
328
|
return new Uint8Array([
|
|
287
|
-
|
|
329
|
+
A.INCREMENT,
|
|
288
330
|
2,
|
|
289
331
|
this.target.element_id,
|
|
290
332
|
this.target.property
|
|
291
333
|
]);
|
|
292
334
|
}
|
|
293
335
|
}
|
|
294
|
-
class
|
|
336
|
+
class Ae extends p {
|
|
295
337
|
format() {
|
|
296
338
|
return new Uint8Array([
|
|
297
|
-
|
|
339
|
+
A.DECREMENT,
|
|
298
340
|
2,
|
|
299
341
|
this.target.element_id,
|
|
300
342
|
this.target.property
|
|
301
343
|
]);
|
|
302
344
|
}
|
|
303
345
|
}
|
|
304
|
-
class
|
|
346
|
+
class we extends p {
|
|
305
347
|
format() {
|
|
306
|
-
return new Uint8Array([
|
|
348
|
+
return new Uint8Array([A.SHOW, 1, this.target.element_id]);
|
|
307
349
|
}
|
|
308
350
|
}
|
|
309
|
-
class
|
|
351
|
+
class pe extends p {
|
|
310
352
|
format() {
|
|
311
|
-
return new Uint8Array([
|
|
353
|
+
return new Uint8Array([A.HIDE, 1, this.target.element_id]);
|
|
312
354
|
}
|
|
313
355
|
}
|
|
314
|
-
class
|
|
356
|
+
let me = class extends p {
|
|
315
357
|
value;
|
|
316
|
-
constructor(e,
|
|
317
|
-
super(e), this.value =
|
|
358
|
+
constructor(e, o) {
|
|
359
|
+
super(e), this.value = o;
|
|
318
360
|
}
|
|
319
361
|
format() {
|
|
320
|
-
const e = this.dataType(),
|
|
321
|
-
|
|
322
|
-
|
|
362
|
+
const e = this.dataType(), o = this.convertValue(e), n = new Uint8Array(5 + o.length), r = [
|
|
363
|
+
A.SET,
|
|
364
|
+
o.length + 3,
|
|
323
365
|
e,
|
|
324
366
|
this.target.element_id,
|
|
325
367
|
this.target.property
|
|
326
368
|
];
|
|
327
|
-
return
|
|
369
|
+
return n.set(r, 0), n.set(o, 5), n;
|
|
328
370
|
}
|
|
329
371
|
dataType() {
|
|
330
|
-
return typeof this.value === "string" ?
|
|
372
|
+
return typeof this.value === "string" ? U.STRING : U.NUMBER;
|
|
331
373
|
}
|
|
332
374
|
convertValue(e) {
|
|
333
|
-
return e ===
|
|
375
|
+
return e === U.STRING ? new TextEncoder().encode(this.value) : e === U.NUMBER ? new Uint8Array([this.value]) : new Uint8Array();
|
|
334
376
|
}
|
|
335
|
-
}
|
|
336
|
-
class
|
|
377
|
+
};
|
|
378
|
+
class ye extends p {
|
|
337
379
|
format() {
|
|
338
380
|
return this.target.element_id !== 0 && this.target.property !== 0 ? new Uint8Array([
|
|
339
|
-
|
|
381
|
+
A.BROADCAST,
|
|
340
382
|
2,
|
|
341
383
|
this.target.element_id,
|
|
342
384
|
this.target.property
|
|
343
|
-
]) : new Uint8Array([
|
|
385
|
+
]) : new Uint8Array([A.BROADCAST, 0]);
|
|
344
386
|
}
|
|
345
387
|
}
|
|
346
|
-
class
|
|
388
|
+
class Ee extends p {
|
|
347
389
|
format() {
|
|
348
|
-
return new Uint8Array([
|
|
390
|
+
return new Uint8Array([A.BREAK, 0]);
|
|
349
391
|
}
|
|
350
392
|
}
|
|
351
|
-
let
|
|
393
|
+
let Te = class extends p {
|
|
352
394
|
fromLow;
|
|
353
395
|
fromHigh;
|
|
354
396
|
toLow;
|
|
355
397
|
toHigh;
|
|
356
398
|
value;
|
|
357
|
-
constructor(e, n, r,
|
|
358
|
-
super(
|
|
399
|
+
constructor(e, o, n, r, s, a) {
|
|
400
|
+
super(a), this.value = e, this.fromLow = o, this.fromHigh = n, this.toLow = r, this.toHigh = s;
|
|
359
401
|
}
|
|
360
402
|
format() {
|
|
361
403
|
return new Uint8Array([
|
|
362
|
-
|
|
404
|
+
A.MAP,
|
|
363
405
|
8,
|
|
364
406
|
this.value.element_id,
|
|
365
407
|
this.value.property,
|
|
@@ -372,174 +414,486 @@ let kt = class extends h {
|
|
|
372
414
|
]);
|
|
373
415
|
}
|
|
374
416
|
};
|
|
375
|
-
class
|
|
417
|
+
class De extends p {
|
|
376
418
|
deciseconds;
|
|
377
419
|
resetable;
|
|
378
420
|
onComplete;
|
|
379
|
-
constructor(e,
|
|
380
|
-
super(new
|
|
421
|
+
constructor(e, o, n) {
|
|
422
|
+
super(new T(0, 0)), this.deciseconds = e, this.resetable = o, this.onComplete = n;
|
|
381
423
|
}
|
|
382
424
|
format() {
|
|
383
|
-
const e =
|
|
384
|
-
this.onComplete.map((
|
|
385
|
-
),
|
|
386
|
-
|
|
425
|
+
const e = ft(
|
|
426
|
+
this.onComplete.map((r) => r.format())
|
|
427
|
+
), o = new Uint8Array(4 + e.length), n = [
|
|
428
|
+
A.TIMER,
|
|
387
429
|
e.length + 2,
|
|
388
430
|
this.resetable ? 1 : 0,
|
|
389
431
|
this.deciseconds
|
|
390
432
|
];
|
|
391
|
-
return
|
|
392
|
-
(
|
|
393
|
-
),
|
|
433
|
+
return o.set(n, 0), e.forEach(
|
|
434
|
+
(r, s) => o.set([r], s + 4)
|
|
435
|
+
), o;
|
|
394
436
|
}
|
|
395
437
|
}
|
|
396
|
-
class
|
|
438
|
+
class Ie extends p {
|
|
397
439
|
left;
|
|
398
440
|
operator;
|
|
399
441
|
right;
|
|
400
442
|
actions;
|
|
401
|
-
constructor(e, n, r
|
|
402
|
-
super(new
|
|
443
|
+
constructor(e, o, n, r) {
|
|
444
|
+
super(new T(0, 0)), this.actions = r, this.left = e, this.operator = o, this.right = n;
|
|
403
445
|
}
|
|
404
446
|
convertValue(e) {
|
|
405
447
|
if (typeof e == "number")
|
|
406
|
-
return new Uint8Array([
|
|
448
|
+
return new Uint8Array([U.NUMBER, 1, e]);
|
|
407
449
|
if (typeof e == "string") {
|
|
408
|
-
const
|
|
450
|
+
const o = new TextEncoder().encode(e);
|
|
409
451
|
return new Uint8Array([
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
...
|
|
452
|
+
U.STRING,
|
|
453
|
+
o.length,
|
|
454
|
+
...o
|
|
413
455
|
]);
|
|
414
456
|
}
|
|
415
|
-
return e instanceof
|
|
416
|
-
|
|
457
|
+
return e instanceof T ? new Uint8Array([
|
|
458
|
+
U.ELEMENT,
|
|
417
459
|
2,
|
|
418
460
|
e.element_id,
|
|
419
461
|
e.property
|
|
420
462
|
]) : new Uint8Array();
|
|
421
463
|
}
|
|
422
464
|
format() {
|
|
423
|
-
const e =
|
|
424
|
-
this.actions.map((
|
|
425
|
-
),
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
465
|
+
const e = ft(
|
|
466
|
+
this.actions.map((c) => c.format())
|
|
467
|
+
), o = this.convertValue(this.left), n = this.convertValue(this.right), r = 4 + o.length + n.length + e.length, s = new Uint8Array(r), a = [
|
|
468
|
+
A.CONDITION,
|
|
469
|
+
r - 2,
|
|
470
|
+
o.length + n.length + 1
|
|
429
471
|
];
|
|
430
|
-
return s.set(
|
|
472
|
+
return s.set(a, 0), s.set([this.operator], 3), s.set(o, 4), s.set(n, 4 + o.length), s.set(e, 4 + o.length + n.length), s;
|
|
431
473
|
}
|
|
432
474
|
}
|
|
433
|
-
function
|
|
475
|
+
function En() {
|
|
434
476
|
return {
|
|
435
477
|
target(t, e) {
|
|
436
|
-
return new
|
|
478
|
+
return new T(t, e);
|
|
437
479
|
},
|
|
438
480
|
increment(t) {
|
|
439
|
-
return new
|
|
481
|
+
return new ge(t);
|
|
440
482
|
},
|
|
441
483
|
decrement(t) {
|
|
442
|
-
return new
|
|
484
|
+
return new Ae(t);
|
|
443
485
|
},
|
|
444
486
|
show(t) {
|
|
445
|
-
return new
|
|
487
|
+
return new we(new T(t, 0));
|
|
446
488
|
},
|
|
447
489
|
hide(t) {
|
|
448
|
-
return new
|
|
490
|
+
return new pe(new T(t, 0));
|
|
449
491
|
},
|
|
450
492
|
set(t, e) {
|
|
451
|
-
return new
|
|
493
|
+
return new me(t, e);
|
|
452
494
|
},
|
|
453
495
|
broadcast(t) {
|
|
454
|
-
return new
|
|
496
|
+
return new ye(t || new T(0, 0));
|
|
455
497
|
},
|
|
456
|
-
timer(t, e,
|
|
457
|
-
return new
|
|
498
|
+
timer(t, e, o) {
|
|
499
|
+
return new De(t, e, o);
|
|
458
500
|
},
|
|
459
501
|
stop() {
|
|
460
|
-
return new
|
|
502
|
+
return new Ee(new T(0, 0));
|
|
461
503
|
},
|
|
462
|
-
condition(t, e,
|
|
463
|
-
return new
|
|
504
|
+
condition(t, e, o, n) {
|
|
505
|
+
return new Ie(t, e, o, n);
|
|
464
506
|
},
|
|
465
|
-
map(t, e, n, r,
|
|
466
|
-
return new
|
|
507
|
+
map(t, e, o, n, r, s) {
|
|
508
|
+
return new Te(t, e, o, n, r, s);
|
|
467
509
|
}
|
|
468
510
|
};
|
|
469
511
|
}
|
|
470
|
-
const { flattenUint8Arrays:
|
|
471
|
-
function
|
|
512
|
+
const { flattenUint8Arrays: Ue } = K();
|
|
513
|
+
function Tn(t) {
|
|
472
514
|
return {
|
|
473
|
-
setButton(e,
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
),
|
|
477
|
-
return
|
|
478
|
-
(s,
|
|
479
|
-
), new
|
|
515
|
+
setButton(e, o) {
|
|
516
|
+
const n = Ue(
|
|
517
|
+
o.map((s) => s.format())
|
|
518
|
+
), r = new Uint8Array(1 + n.length);
|
|
519
|
+
return r.set([e], 0), n.forEach(
|
|
520
|
+
(s, a) => r.set([s], a + 1)
|
|
521
|
+
), new B(f.ACTIONS, t.id, r);
|
|
480
522
|
}
|
|
481
523
|
};
|
|
482
524
|
}
|
|
483
|
-
function
|
|
484
|
-
return new Promise((e,
|
|
485
|
-
const
|
|
486
|
-
|
|
525
|
+
function Ce(t) {
|
|
526
|
+
return new Promise((e, o) => {
|
|
527
|
+
const n = new Image();
|
|
528
|
+
n.onload = () => e(n), n.onerror = o, n.src = t;
|
|
487
529
|
});
|
|
488
530
|
}
|
|
489
|
-
function
|
|
490
|
-
const e = document.createElement("canvas"),
|
|
491
|
-
if (e.width = t.width, e.height = t.height, !
|
|
531
|
+
function Se(t) {
|
|
532
|
+
const e = document.createElement("canvas"), o = e.getContext("2d");
|
|
533
|
+
if (e.width = t.width, e.height = t.height, !o)
|
|
492
534
|
throw new Error("Failed to get 2D context for image data.");
|
|
493
|
-
return
|
|
494
|
-
}
|
|
495
|
-
function
|
|
496
|
-
const e = [],
|
|
497
|
-
for (let s = 0; s <
|
|
498
|
-
for (let
|
|
499
|
-
const
|
|
500
|
-
e.push(
|
|
535
|
+
return o.drawImage(t, 0, 0), o.getImageData(0, 0, t.width, t.height);
|
|
536
|
+
}
|
|
537
|
+
function be(t) {
|
|
538
|
+
const e = [], o = t.data, n = t.width, r = t.height;
|
|
539
|
+
for (let s = 0; s < r; s++)
|
|
540
|
+
for (let a = 0; a < n; a++) {
|
|
541
|
+
const c = (s * n + a) * 4, u = o[c], l = o[c + 1], E = o[c + 2], F = 0.2126 * u + 0.7152 * l + 0.0722 * E;
|
|
542
|
+
e.push(F < 128 ? 0 : 1);
|
|
501
543
|
}
|
|
502
544
|
return {
|
|
503
|
-
width:
|
|
504
|
-
height:
|
|
545
|
+
width: n,
|
|
546
|
+
height: r,
|
|
505
547
|
pixels: e
|
|
506
548
|
};
|
|
507
549
|
}
|
|
508
|
-
function
|
|
550
|
+
function _e() {
|
|
509
551
|
return {
|
|
510
|
-
createImage:
|
|
511
|
-
getImageData:
|
|
512
|
-
imageDataToPixels:
|
|
552
|
+
createImage: Ce,
|
|
553
|
+
getImageData: Se,
|
|
554
|
+
imageDataToPixels: be
|
|
513
555
|
};
|
|
514
556
|
}
|
|
515
|
-
const { createImage:
|
|
516
|
-
function
|
|
517
|
-
return new Promise((e,
|
|
518
|
-
|
|
557
|
+
const { createImage: Ne, getImageData: Re, imageDataToPixels: xe } = _e(), { pixelsToBytes: Be } = K();
|
|
558
|
+
function Pe(t) {
|
|
559
|
+
return new Promise((e, o) => {
|
|
560
|
+
Ne(t).then((n) => Re(n)).then((n) => xe(n)).then((n) => Be(n.pixels, n.width)).then((n) => e(n)).catch((n) => o(n));
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
function Dn() {
|
|
564
|
+
return {
|
|
565
|
+
imageToBytes: Pe
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
function Le(t, e, o, n, r) {
|
|
569
|
+
return (t - e) / (o - e) * (r - n) + n;
|
|
570
|
+
}
|
|
571
|
+
function In() {
|
|
572
|
+
return { map: Le };
|
|
573
|
+
}
|
|
574
|
+
let d = !1;
|
|
575
|
+
const C = [], y = /* @__PURE__ */ new Map();
|
|
576
|
+
let P = 500, V = !1;
|
|
577
|
+
const lt = new I.SyncEvent(), L = new I.SyncEvent(), dt = /* @__PURE__ */ new Map([
|
|
578
|
+
[f.UPLOAD, "UPLOAD"],
|
|
579
|
+
[f.DRAW_IMAGE, "DRAW_IMAGE"],
|
|
580
|
+
[f.DRAW_RECTANGLE, "DRAW_RECTANGLE"],
|
|
581
|
+
[f.BUTTON_PRESS, "BUTTON_PRESS"],
|
|
582
|
+
[f.DRAW_TEXT, "DRAW_TEXT"],
|
|
583
|
+
[f.ALL, "ALL"],
|
|
584
|
+
[f.CLEAR_GRAPHICS, "CLEAR_GRAPHICS"],
|
|
585
|
+
[f.ACTIONS, "ACTIONS"],
|
|
586
|
+
[f.CLEAR_SCREEN, "CLEAR_SCREEN"],
|
|
587
|
+
[f.LOADER, "LOADER"]
|
|
588
|
+
]);
|
|
589
|
+
function Me() {
|
|
590
|
+
d = !0, V || (Ve(), V = !0);
|
|
591
|
+
}
|
|
592
|
+
function Oe() {
|
|
593
|
+
d = !1;
|
|
594
|
+
}
|
|
595
|
+
function ve() {
|
|
596
|
+
return d;
|
|
597
|
+
}
|
|
598
|
+
function ke(t) {
|
|
599
|
+
P = t, ht();
|
|
600
|
+
}
|
|
601
|
+
function $e() {
|
|
602
|
+
return C;
|
|
603
|
+
}
|
|
604
|
+
function ze() {
|
|
605
|
+
return Array.from(y.values());
|
|
606
|
+
}
|
|
607
|
+
function He(t) {
|
|
608
|
+
return y.get(t);
|
|
609
|
+
}
|
|
610
|
+
function Fe() {
|
|
611
|
+
C.length = 0, y.clear();
|
|
612
|
+
}
|
|
613
|
+
function Ge(t) {
|
|
614
|
+
const e = t.length > i.TYPE ? t[i.TYPE] : 0;
|
|
615
|
+
return {
|
|
616
|
+
cacheId: t[i.CACHE],
|
|
617
|
+
targetId: t[i.ID],
|
|
618
|
+
ttl: t[i.TTL],
|
|
619
|
+
position: t.length > 4 ? t[i.POSITION] | t[i.POSITION + 1] << 8 : 0,
|
|
620
|
+
dataSize: t.length > 6 ? t[i.DATA_SIZE] | t[i.DATA_SIZE + 1] << 8 : 0,
|
|
621
|
+
typeName: dt.get(e) ?? `UNKNOWN(${e})`,
|
|
622
|
+
typeValue: e,
|
|
623
|
+
payloadBytes: Math.max(0, t.length - i.DATA),
|
|
624
|
+
raw: Array.from(t)
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
function g(t, e) {
|
|
628
|
+
if (!d) return;
|
|
629
|
+
const o = {
|
|
630
|
+
type: t,
|
|
631
|
+
timestamp: Date.now(),
|
|
632
|
+
data: e
|
|
633
|
+
};
|
|
634
|
+
C.push(o), ht(), lt.post(o);
|
|
635
|
+
}
|
|
636
|
+
function ht() {
|
|
637
|
+
C.length > P && C.splice(0, C.length - P);
|
|
638
|
+
}
|
|
639
|
+
function We(t, e) {
|
|
640
|
+
if (!d) return;
|
|
641
|
+
const o = y.get(t);
|
|
642
|
+
o && (Object.assign(o, e), o.completedAt && o.queuedAt && (o.latencyMs = o.completedAt - o.queuedAt), L.post(o));
|
|
643
|
+
}
|
|
644
|
+
function Ve() {
|
|
645
|
+
const t = tt(), e = Z(), o = x();
|
|
646
|
+
t.onMessageQueued.attach((n) => {
|
|
647
|
+
d && (y.set(n.cacheId, {
|
|
648
|
+
cacheId: n.cacheId,
|
|
649
|
+
queuedAt: n.timestamp,
|
|
650
|
+
firstPacketAt: null,
|
|
651
|
+
completedAt: null,
|
|
652
|
+
latencyMs: null,
|
|
653
|
+
retransmitCount: 0,
|
|
654
|
+
timeoutCount: 0,
|
|
655
|
+
packetsSent: 0,
|
|
656
|
+
totalPackets: n.packetCount
|
|
657
|
+
}), g("message_queued", {
|
|
658
|
+
cacheId: n.cacheId,
|
|
659
|
+
typeName: dt.get(n.type) ?? `UNKNOWN(${n.type})`,
|
|
660
|
+
targetId: n.targetId,
|
|
661
|
+
packetCount: n.packetCount,
|
|
662
|
+
totalBytes: n.totalBytes
|
|
663
|
+
}));
|
|
664
|
+
}), t.onPacketSent.attach((n) => {
|
|
665
|
+
if (!d) return;
|
|
666
|
+
const r = y.get(n.cacheId);
|
|
667
|
+
r && (r.packetsSent++, r.firstPacketAt === null && (r.firstPacketAt = n.timestamp)), g("packet_sent", {
|
|
668
|
+
cacheId: n.cacheId,
|
|
669
|
+
position: n.position,
|
|
670
|
+
dataSize: n.dataSize,
|
|
671
|
+
batchIndex: n.batchIndex
|
|
672
|
+
});
|
|
673
|
+
}), t.onRetransmit.attach((n) => {
|
|
674
|
+
if (!d) return;
|
|
675
|
+
const r = y.get(n.cacheId);
|
|
676
|
+
r && (r.retransmitCount++, L.post(r)), g("retransmit", {
|
|
677
|
+
cacheId: n.cacheId,
|
|
678
|
+
packetCount: n.packetCount,
|
|
679
|
+
reason: n.reason
|
|
680
|
+
});
|
|
681
|
+
}), t.onTimeout.attach((n) => {
|
|
682
|
+
if (!d) return;
|
|
683
|
+
const r = y.get(n.cacheId);
|
|
684
|
+
r && (r.timeoutCount++, L.post(r)), g("timeout", {
|
|
685
|
+
cacheId: n.cacheId,
|
|
686
|
+
retryCount: n.retryCount,
|
|
687
|
+
maxRetries: n.maxRetries,
|
|
688
|
+
willRetry: n.willRetry
|
|
689
|
+
});
|
|
690
|
+
}), t.onMessageComplete.attach((n) => {
|
|
691
|
+
d && (We(n.cacheId, {
|
|
692
|
+
completedAt: n.timestamp
|
|
693
|
+
}), g("message_complete", {
|
|
694
|
+
cacheId: n.cacheId
|
|
695
|
+
}));
|
|
696
|
+
}), e.onMessageDone.attach((n) => {
|
|
697
|
+
d && g("message_done", { cacheId: n });
|
|
698
|
+
}), e.onReceivedPackets.attach((n) => {
|
|
699
|
+
d && g("received_packets", {
|
|
700
|
+
incompleteCaches: n.filter((r) => r !== 0)
|
|
701
|
+
});
|
|
702
|
+
}), e.onNode.attach((n) => {
|
|
703
|
+
if (d)
|
|
704
|
+
for (const [r, s] of n)
|
|
705
|
+
g("node_discovered", { nodeId: r, neighbors: s });
|
|
706
|
+
}), e.onNodeLost.attach((n) => {
|
|
707
|
+
d && g("node_lost", { nodeId: n });
|
|
708
|
+
}), o.onConnect.attach(() => {
|
|
709
|
+
d && g("connected", {});
|
|
710
|
+
}), o.onDisconnect.attach(() => {
|
|
711
|
+
d && g("disconnected", {});
|
|
519
712
|
});
|
|
520
713
|
}
|
|
521
|
-
function
|
|
714
|
+
function Ze() {
|
|
715
|
+
d = !1, C.length = 0, y.clear(), V = !1, P = 500;
|
|
716
|
+
}
|
|
717
|
+
function Un() {
|
|
522
718
|
return {
|
|
523
|
-
|
|
719
|
+
enable: Me,
|
|
720
|
+
disable: Oe,
|
|
721
|
+
isEnabled: ve,
|
|
722
|
+
clear: Fe,
|
|
723
|
+
getLog: $e,
|
|
724
|
+
getTimings: ze,
|
|
725
|
+
getTimingForCache: He,
|
|
726
|
+
setMaxLogSize: ke,
|
|
727
|
+
decodePacket: Ge,
|
|
728
|
+
onDebugEvent: lt,
|
|
729
|
+
onTimingUpdate: L,
|
|
730
|
+
_resetForTesting: Ze
|
|
524
731
|
};
|
|
525
732
|
}
|
|
526
|
-
|
|
527
|
-
|
|
733
|
+
const { messageCharUuid: gt, messageFloodCharUuid: z, handshakeCharUuid: At, BATCH_SIZE: Ye, PACKET_SIZE: M } = O();
|
|
734
|
+
let q = !1, R = !1, H = !0, h = { standees: [] };
|
|
735
|
+
const m = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map();
|
|
736
|
+
let S = 0;
|
|
737
|
+
const J = 7;
|
|
738
|
+
function Ke(t) {
|
|
739
|
+
h = {
|
|
740
|
+
responseDelay: 10,
|
|
741
|
+
dropRate: 0,
|
|
742
|
+
partialDelivery: !1,
|
|
743
|
+
...t
|
|
744
|
+
}, q = !0, R = !1, H = !0, m.clear(), D.clear(), S = 0, et(rn);
|
|
745
|
+
}
|
|
746
|
+
function wt() {
|
|
747
|
+
q = !1, R = !1, H = !0, m.clear(), D.clear(), S = 0, et(null);
|
|
748
|
+
}
|
|
749
|
+
function qe() {
|
|
750
|
+
return q;
|
|
751
|
+
}
|
|
752
|
+
function Xe() {
|
|
753
|
+
return h;
|
|
754
|
+
}
|
|
755
|
+
function je(t) {
|
|
756
|
+
h = { ...h, ...t };
|
|
757
|
+
}
|
|
758
|
+
function Je(t, e, o) {
|
|
759
|
+
const n = m.get(gt);
|
|
760
|
+
if (!n) return;
|
|
761
|
+
const r = e === "plus" ? G.PLUS : e === "minus" ? G.MINUS : G.EITHER, s = o ? new TextEncoder().encode(o) : new Uint8Array(0), a = i.DATA + 1 + s.length, c = new ArrayBuffer(a), u = new DataView(c);
|
|
762
|
+
u.setUint8(i.ID, t), u.setUint8(i.TYPE, f.BUTTON_PRESS), u.setUint8(i.DATA, r);
|
|
763
|
+
for (let l = 0; l < s.length; l++)
|
|
764
|
+
u.setUint8(i.DATA + 1 + l, s[l]);
|
|
765
|
+
n(u);
|
|
766
|
+
}
|
|
767
|
+
function Qe(t) {
|
|
768
|
+
const e = m.get(z);
|
|
769
|
+
if (!e) return;
|
|
770
|
+
const o = new ArrayBuffer(i.DATA + 1), n = new DataView(o);
|
|
771
|
+
n.setUint8(i.ID, t), n.setUint8(i.TYPE, v.LOST_NODE), n.setUint8(i.DATA, t), e(n);
|
|
772
|
+
}
|
|
773
|
+
function tn(t) {
|
|
774
|
+
const e = m.get(z);
|
|
775
|
+
e && e(cn(t));
|
|
776
|
+
}
|
|
777
|
+
function en() {
|
|
778
|
+
R = !1, m.clear(), D.clear(), S = 0, x().onDisconnect.post();
|
|
779
|
+
}
|
|
780
|
+
function nn(t) {
|
|
781
|
+
H = t;
|
|
782
|
+
}
|
|
783
|
+
function on() {
|
|
784
|
+
wt();
|
|
785
|
+
}
|
|
786
|
+
const rn = {
|
|
787
|
+
async connect(t) {
|
|
788
|
+
R = !0, x().onConnect.post();
|
|
789
|
+
},
|
|
790
|
+
async reconnect() {
|
|
791
|
+
if (!H)
|
|
792
|
+
throw new Error("No devices found");
|
|
793
|
+
R = !0, x().onConnect.post();
|
|
794
|
+
},
|
|
795
|
+
async readCharacteristic(t, e) {
|
|
796
|
+
},
|
|
797
|
+
async writeCharacteristic(t, e, o) {
|
|
798
|
+
if (!R || e !== gt || h.dropRate !== void 0 && h.dropRate > 0 && Math.random() < h.dropRate)
|
|
799
|
+
return;
|
|
800
|
+
const n = o[i.CACHE], r = o[i.POSITION] | o[i.POSITION + 1] << 8, s = o[i.DATA_SIZE] | o[i.DATA_SIZE + 1] << 8;
|
|
801
|
+
D.has(n) || D.set(n, {
|
|
802
|
+
received: /* @__PURE__ */ new Set(),
|
|
803
|
+
dataSize: s
|
|
804
|
+
});
|
|
805
|
+
const a = D.get(n);
|
|
806
|
+
a.received.add(r), S++;
|
|
807
|
+
const c = Math.ceil(s / M);
|
|
808
|
+
if (a.received.size >= c) {
|
|
809
|
+
const l = h.responseDelay ?? 10;
|
|
810
|
+
setTimeout(() => {
|
|
811
|
+
sn(n);
|
|
812
|
+
}, l);
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
if (h.partialDelivery && S >= Ye) {
|
|
816
|
+
S = 0;
|
|
817
|
+
const l = h.responseDelay ?? 10;
|
|
818
|
+
setTimeout(() => {
|
|
819
|
+
const E = [];
|
|
820
|
+
for (const [F, X] of D) {
|
|
821
|
+
const pt = Math.ceil(X.dataSize / M);
|
|
822
|
+
X.received.size < pt && E.push(F);
|
|
823
|
+
}
|
|
824
|
+
E.length > 0 && an(E);
|
|
825
|
+
}, l);
|
|
826
|
+
}
|
|
827
|
+
},
|
|
828
|
+
async subscribe(t, e, o) {
|
|
829
|
+
m.set(e, o), e === At && un();
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
function sn(t) {
|
|
833
|
+
const e = m.get(z);
|
|
834
|
+
if (!e) return;
|
|
835
|
+
const o = new ArrayBuffer(i.DATA + 1), n = new DataView(o);
|
|
836
|
+
n.setUint8(i.TYPE, v.MESSAGE_DONE), n.setUint8(i.DATA, t), D.delete(t), S = 0, e(n);
|
|
837
|
+
}
|
|
838
|
+
function an(t) {
|
|
839
|
+
const e = m.get(z);
|
|
840
|
+
if (!e) return;
|
|
841
|
+
const o = new ArrayBuffer(i.DATA + t.length), n = new DataView(o);
|
|
842
|
+
n.setUint8(i.TYPE, v.DATA_FEEDBACK);
|
|
843
|
+
for (let r = 0; r < t.length; r++)
|
|
844
|
+
n.setUint8(i.DATA + r, t[r]);
|
|
845
|
+
e(n);
|
|
846
|
+
}
|
|
847
|
+
function cn(t) {
|
|
848
|
+
const e = i.DATA + 1 + t.neighbors.length, o = new ArrayBuffer(e), n = new DataView(o);
|
|
849
|
+
n.setUint8(i.TYPE, v.NODES), n.setUint8(i.DATA, t.id);
|
|
850
|
+
for (let r = 0; r < t.neighbors.length; r++)
|
|
851
|
+
n.setUint8(i.DATA + 1 + r, t.neighbors[r]);
|
|
852
|
+
return n;
|
|
528
853
|
}
|
|
529
|
-
function
|
|
530
|
-
|
|
854
|
+
function un() {
|
|
855
|
+
const t = m.get(At);
|
|
856
|
+
if (!t || h.standees.length === 0) return;
|
|
857
|
+
const e = [h.standees.length];
|
|
858
|
+
for (const r of h.standees)
|
|
859
|
+
e.push(r.id, r.neighbors.length, ...r.neighbors);
|
|
860
|
+
const o = 200, n = e.length;
|
|
861
|
+
for (let r = 0; r < n; r += M) {
|
|
862
|
+
const s = Math.min(M, n - r), a = J + s, c = new ArrayBuffer(a), u = new DataView(c);
|
|
863
|
+
u.setUint8(i.ID, 0), u.setUint8(i.CACHE, o), u.setUint8(i.TTL, 10), u.setUint16(i.POSITION, r, !0), u.setUint16(i.DATA_SIZE, n, !0);
|
|
864
|
+
for (let l = 0; l < s; l++)
|
|
865
|
+
u.setUint8(J + l, e[r + l]);
|
|
866
|
+
t(u);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
function Cn() {
|
|
870
|
+
return {
|
|
871
|
+
activate: Ke,
|
|
872
|
+
deactivate: wt,
|
|
873
|
+
isActive: qe,
|
|
874
|
+
getConfig: Xe,
|
|
875
|
+
updateConfig: je,
|
|
876
|
+
pressButton: Je,
|
|
877
|
+
simulateNodeLost: Qe,
|
|
878
|
+
simulateNodeJoin: tn,
|
|
879
|
+
disconnect: en,
|
|
880
|
+
reconnectable: nn,
|
|
881
|
+
_resetForTesting: on
|
|
882
|
+
};
|
|
531
883
|
}
|
|
532
884
|
export {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
885
|
+
En as useActions,
|
|
886
|
+
K as useBinary,
|
|
887
|
+
Tn as useButtons,
|
|
888
|
+
Dn as useConverter,
|
|
889
|
+
Un as useDebug,
|
|
890
|
+
pn as useDisplay,
|
|
891
|
+
hn as useGraphics,
|
|
892
|
+
_e as useImage,
|
|
893
|
+
gn as useLoader,
|
|
894
|
+
jt as useMesh,
|
|
895
|
+
Cn as useMockBluetooth,
|
|
896
|
+
wn as useStandeeElements,
|
|
897
|
+
An as useStandees,
|
|
898
|
+
In as useUtils
|
|
545
899
|
};
|