interaction-system 1.0.0

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.
Files changed (51) hide show
  1. package/README.md +377 -0
  2. package/USAGE.md +490 -0
  3. package/dist/index.cjs.js +1983 -0
  4. package/dist/index.cjs.js.map +1 -0
  5. package/dist/index.d.ts +34 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.es.js +1983 -0
  8. package/dist/index.es.js.map +1 -0
  9. package/dist/input/KeyEvent.d.ts +315 -0
  10. package/dist/input/KeyEvent.d.ts.map +1 -0
  11. package/dist/input/KeyInputHandler.d.ts +15 -0
  12. package/dist/input/KeyInputHandler.d.ts.map +1 -0
  13. package/dist/input/KeyToCodeMap.d.ts +2 -0
  14. package/dist/input/KeyToCodeMap.d.ts.map +1 -0
  15. package/dist/input/UIEventsCode.d.ts +175 -0
  16. package/dist/input/UIEventsCode.d.ts.map +1 -0
  17. package/dist/interaction/FeaturedInteractionHandler.d.ts +26 -0
  18. package/dist/interaction/FeaturedInteractionHandler.d.ts.map +1 -0
  19. package/dist/interaction/InteractionHandler.d.ts +86 -0
  20. package/dist/interaction/InteractionHandler.d.ts.map +1 -0
  21. package/dist/interaction/SimpleInteractionHandler.d.ts +19 -0
  22. package/dist/interaction/SimpleInteractionHandler.d.ts.map +1 -0
  23. package/dist/messages/CommandControlMessage.d.ts +49 -0
  24. package/dist/messages/CommandControlMessage.d.ts.map +1 -0
  25. package/dist/messages/ControlMessage.d.ts +25 -0
  26. package/dist/messages/ControlMessage.d.ts.map +1 -0
  27. package/dist/messages/KeyCodeControlMessage.d.ts +24 -0
  28. package/dist/messages/KeyCodeControlMessage.d.ts.map +1 -0
  29. package/dist/messages/ScrollControlMessage.d.ts +23 -0
  30. package/dist/messages/ScrollControlMessage.d.ts.map +1 -0
  31. package/dist/messages/TextControlMessage.d.ts +19 -0
  32. package/dist/messages/TextControlMessage.d.ts.map +1 -0
  33. package/dist/messages/TouchControlMessage.d.ts +44 -0
  34. package/dist/messages/TouchControlMessage.d.ts.map +1 -0
  35. package/dist/models/MotionEvent.d.ts +18 -0
  36. package/dist/models/MotionEvent.d.ts.map +1 -0
  37. package/dist/models/Point.d.ts +14 -0
  38. package/dist/models/Point.d.ts.map +1 -0
  39. package/dist/models/Position.d.ts +17 -0
  40. package/dist/models/Position.d.ts.map +1 -0
  41. package/dist/models/Rect.d.ts +22 -0
  42. package/dist/models/Rect.d.ts.map +1 -0
  43. package/dist/models/ScreenInfo.d.ts +14 -0
  44. package/dist/models/ScreenInfo.d.ts.map +1 -0
  45. package/dist/models/Size.d.ts +21 -0
  46. package/dist/models/Size.d.ts.map +1 -0
  47. package/dist/types/PlayerInterface.d.ts +20 -0
  48. package/dist/types/PlayerInterface.d.ts.map +1 -0
  49. package/dist/utils/Util.d.ts +26 -0
  50. package/dist/utils/Util.d.ts.map +1 -0
  51. package/package.json +56 -0
@@ -0,0 +1,1983 @@
1
+ import { Buffer } from "buffer";
2
+ const _MotionEvent = class _MotionEvent {
3
+ };
4
+ _MotionEvent.ACTION_DOWN = 0;
5
+ _MotionEvent.ACTION_UP = 1;
6
+ _MotionEvent.ACTION_MOVE = 2;
7
+ _MotionEvent.BUTTON_PRIMARY = 1 << 0;
8
+ _MotionEvent.BUTTON_SECONDARY = 1 << 1;
9
+ _MotionEvent.BUTTON_TERTIARY = 1 << 2;
10
+ let MotionEvent = _MotionEvent;
11
+ const _ControlMessage = class _ControlMessage {
12
+ constructor(type) {
13
+ this.type = type;
14
+ }
15
+ toBuffer() {
16
+ throw Error("Not implemented");
17
+ }
18
+ toString() {
19
+ return "ControlMessage";
20
+ }
21
+ toJSON() {
22
+ return {
23
+ type: this.type
24
+ };
25
+ }
26
+ };
27
+ _ControlMessage.TYPE_KEYCODE = 0;
28
+ _ControlMessage.TYPE_TEXT = 1;
29
+ _ControlMessage.TYPE_TOUCH = 2;
30
+ _ControlMessage.TYPE_SCROLL = 3;
31
+ _ControlMessage.TYPE_BACK_OR_SCREEN_ON = 4;
32
+ _ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL = 5;
33
+ _ControlMessage.TYPE_EXPAND_SETTINGS_PANEL = 6;
34
+ _ControlMessage.TYPE_COLLAPSE_PANELS = 7;
35
+ _ControlMessage.TYPE_GET_CLIPBOARD = 8;
36
+ _ControlMessage.TYPE_SET_CLIPBOARD = 9;
37
+ _ControlMessage.TYPE_SET_SCREEN_POWER_MODE = 10;
38
+ _ControlMessage.TYPE_ROTATE_DEVICE = 11;
39
+ _ControlMessage.TYPE_CHANGE_STREAM_PARAMETERS = 101;
40
+ _ControlMessage.TYPE_PUSH_FILE = 102;
41
+ let ControlMessage = _ControlMessage;
42
+ const _TouchControlMessage = class _TouchControlMessage extends ControlMessage {
43
+ constructor(action, pointerId, position, pressure, buttons) {
44
+ super(ControlMessage.TYPE_TOUCH);
45
+ this.action = action;
46
+ this.pointerId = pointerId;
47
+ this.position = position;
48
+ this.pressure = pressure;
49
+ this.buttons = buttons;
50
+ }
51
+ /**
52
+ * @override
53
+ */
54
+ toBuffer() {
55
+ const buffer = Buffer.alloc(_TouchControlMessage.PAYLOAD_LENGTH + 1);
56
+ let offset = 0;
57
+ offset = buffer.writeUInt8(this.type, offset);
58
+ offset = buffer.writeUInt8(this.action, offset);
59
+ offset = buffer.writeUInt32BE(0, offset);
60
+ offset = buffer.writeUInt32BE(this.pointerId, offset);
61
+ offset = buffer.writeUInt32BE(this.position.point.x, offset);
62
+ offset = buffer.writeUInt32BE(this.position.point.y, offset);
63
+ offset = buffer.writeUInt16BE(this.position.screenSize.width, offset);
64
+ offset = buffer.writeUInt16BE(this.position.screenSize.height, offset);
65
+ offset = buffer.writeUInt16BE(this.pressure * _TouchControlMessage.MAX_PRESSURE_VALUE, offset);
66
+ buffer.writeUInt32BE(this.buttons, offset);
67
+ return buffer;
68
+ }
69
+ toString() {
70
+ return `TouchControlMessage{action=${this.action}, pointerId=${this.pointerId}, position=${this.position}, pressure=${this.pressure}, buttons=${this.buttons}}`;
71
+ }
72
+ toJSON() {
73
+ return {
74
+ type: this.type,
75
+ action: this.action,
76
+ pointerId: this.pointerId,
77
+ position: this.position.toJSON(),
78
+ pressure: this.pressure,
79
+ buttons: this.buttons
80
+ };
81
+ }
82
+ };
83
+ _TouchControlMessage.PAYLOAD_LENGTH = 28;
84
+ _TouchControlMessage.MAX_PRESSURE_VALUE = 65535;
85
+ let TouchControlMessage = _TouchControlMessage;
86
+ class Size {
87
+ constructor(width, height) {
88
+ this.width = width;
89
+ this.height = height;
90
+ this.w = width;
91
+ this.h = height;
92
+ }
93
+ static equals(a, b) {
94
+ if (!a && !b) {
95
+ return true;
96
+ }
97
+ return !!a && !!b && a.equals(b);
98
+ }
99
+ static copy(a) {
100
+ if (!a) {
101
+ return null;
102
+ }
103
+ return new Size(a.width, a.height);
104
+ }
105
+ length() {
106
+ return this.w * this.h;
107
+ }
108
+ rotate() {
109
+ return new Size(this.height, this.width);
110
+ }
111
+ equals(o) {
112
+ if (this === o) {
113
+ return true;
114
+ }
115
+ if (!o) {
116
+ return false;
117
+ }
118
+ return this.width === o.width && this.height === o.height;
119
+ }
120
+ intersect(o) {
121
+ if (!o) {
122
+ return this;
123
+ }
124
+ const minH = Math.min(this.height, o.height);
125
+ const minW = Math.min(this.width, o.width);
126
+ return new Size(minW, minH);
127
+ }
128
+ getHalfSize() {
129
+ return new Size(this.width >>> 1, this.height >>> 1);
130
+ }
131
+ toString() {
132
+ return `Size{width=${this.width}, height=${this.height}}`;
133
+ }
134
+ toJSON() {
135
+ return {
136
+ width: this.width,
137
+ height: this.height
138
+ };
139
+ }
140
+ }
141
+ class Point {
142
+ constructor(x, y) {
143
+ this.x = Math.round(x);
144
+ this.y = Math.round(y);
145
+ }
146
+ equals(o) {
147
+ if (this === o) {
148
+ return true;
149
+ }
150
+ if (o === null) {
151
+ return false;
152
+ }
153
+ return this.x === o.x && this.y === o.y;
154
+ }
155
+ distance(to) {
156
+ const x = this.x - to.x;
157
+ const y = this.y - to.y;
158
+ return Math.sqrt(x * x + y * y);
159
+ }
160
+ toString() {
161
+ return `Point{x=${this.x}, y=${this.y}}`;
162
+ }
163
+ toJSON() {
164
+ return {
165
+ x: this.x,
166
+ y: this.y
167
+ };
168
+ }
169
+ }
170
+ class Position {
171
+ constructor(point, screenSize) {
172
+ this.point = point;
173
+ this.screenSize = screenSize;
174
+ }
175
+ equals(o) {
176
+ if (this === o) {
177
+ return true;
178
+ }
179
+ if (o === null) {
180
+ return false;
181
+ }
182
+ return this.point.equals(o.point) && this.screenSize.equals(o.screenSize);
183
+ }
184
+ rotate(rotation) {
185
+ switch (rotation) {
186
+ case 1:
187
+ return new Position(
188
+ new Point(this.screenSize.height - this.point.y, this.point.x),
189
+ this.screenSize.rotate()
190
+ );
191
+ case 2:
192
+ return new Position(
193
+ new Point(this.screenSize.width - this.point.x, this.screenSize.height - this.point.y),
194
+ this.screenSize
195
+ );
196
+ case 3:
197
+ return new Position(
198
+ new Point(this.point.y, this.screenSize.width - this.point.x),
199
+ this.screenSize.rotate()
200
+ );
201
+ default:
202
+ return this;
203
+ }
204
+ }
205
+ toString() {
206
+ return `Position{point=${this.point}, screenSize=${this.screenSize}}`;
207
+ }
208
+ toJSON() {
209
+ return {
210
+ point: this.point.toJSON(),
211
+ screenSize: this.screenSize.toJSON()
212
+ };
213
+ }
214
+ }
215
+ const _Util = class _Util {
216
+ /**
217
+ * 将 UTF-8 字节数组转换为 JavaScript 字符串
218
+ * @param bytes UTF-8 字节数组
219
+ * @returns 16位 Unicode 字符串
220
+ */
221
+ static utf8ByteArrayToString(bytes) {
222
+ var out = [], pos = 0, c = 0;
223
+ while (pos < bytes.length) {
224
+ var c1 = bytes[pos++];
225
+ if (c1 < 128) {
226
+ out[c++] = String.fromCharCode(c1);
227
+ } else if (c1 > 191 && c1 < 224) {
228
+ var c2 = bytes[pos++];
229
+ out[c++] = String.fromCharCode((c1 & 31) << 6 | c2 & 63);
230
+ } else if (c1 > 239 && c1 < 365) {
231
+ var c2 = bytes[pos++];
232
+ var c3 = bytes[pos++];
233
+ var c4 = bytes[pos++];
234
+ var u = ((c1 & 7) << 18 | (c2 & 63) << 12 | (c3 & 63) << 6 | c4 & 63) - 65536;
235
+ out[c++] = String.fromCharCode(55296 + (u >> 10));
236
+ out[c++] = String.fromCharCode(56320 + (u & 1023));
237
+ } else {
238
+ var c2 = bytes[pos++];
239
+ var c3 = bytes[pos++];
240
+ out[c++] = String.fromCharCode((c1 & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
241
+ }
242
+ }
243
+ return out.join("");
244
+ }
245
+ /**
246
+ * 检测浏览器是否支持 passive 事件监听器
247
+ * 参考: https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
248
+ * @returns 是否支持 passive 选项
249
+ */
250
+ static supportsPassive() {
251
+ if (typeof _Util.supportsPassiveValue === "boolean") {
252
+ return _Util.supportsPassiveValue;
253
+ }
254
+ let supportsPassive = false;
255
+ try {
256
+ const opts = Object.defineProperty({}, "passive", {
257
+ get: function() {
258
+ supportsPassive = true;
259
+ }
260
+ });
261
+ window.addEventListener("testPassive", null, opts);
262
+ window.removeEventListener("testPassive", null, opts);
263
+ } catch (error) {
264
+ }
265
+ return _Util.supportsPassiveValue = supportsPassive;
266
+ }
267
+ };
268
+ _Util.stringToUtf8ByteArray = function(str) {
269
+ var out = [], p = 0;
270
+ for (var i = 0; i < str.length; i++) {
271
+ var c = str.charCodeAt(i);
272
+ if (c < 128) {
273
+ out[p++] = c;
274
+ } else if (c < 2048) {
275
+ out[p++] = c >> 6 | 192;
276
+ out[p++] = c & 63 | 128;
277
+ } else if ((c & 64512) == 55296 && i + 1 < str.length && (str.charCodeAt(i + 1) & 64512) == 56320) {
278
+ c = 65536 + ((c & 1023) << 10) + (str.charCodeAt(++i) & 1023);
279
+ out[p++] = c >> 18 | 240;
280
+ out[p++] = c >> 12 & 63 | 128;
281
+ out[p++] = c >> 6 & 63 | 128;
282
+ out[p++] = c & 63 | 128;
283
+ } else {
284
+ out[p++] = c >> 12 | 224;
285
+ out[p++] = c >> 6 & 63 | 128;
286
+ out[p++] = c & 63 | 128;
287
+ }
288
+ }
289
+ return Uint8Array.from(out);
290
+ };
291
+ let Util = _Util;
292
+ const TouchPointPNG = "../assets/images/touch_point.png";
293
+ const CenterPointPNG = "../assets/images/center_point.png";
294
+ const TAG$2 = "[TouchHandler]";
295
+ const _InteractionHandler = class _InteractionHandler {
296
+ constructor(player, touchEventsNames, keyEventsNames) {
297
+ this.player = player;
298
+ this.touchEventsNames = touchEventsNames;
299
+ this.keyEventsNames = keyEventsNames;
300
+ this.multiTouchActive = false;
301
+ this.multiTouchShift = false;
302
+ this.dirtyPlace = [];
303
+ this.over = false;
304
+ this.tag = player.getTouchableElement();
305
+ this.ctx = this.tag.getContext("2d");
306
+ _InteractionHandler.loadImages();
307
+ _InteractionHandler.bindGlobalListeners(this);
308
+ }
309
+ static bindGlobalListeners(interactionHandler) {
310
+ interactionHandler.touchEventsNames.forEach((eventName) => {
311
+ let set = _InteractionHandler.eventListeners.get(eventName);
312
+ if (!set) {
313
+ set = /* @__PURE__ */ new Set();
314
+ document.body.addEventListener(eventName, this.onInteractionEvent, _InteractionHandler.options);
315
+ this.eventListeners.set(eventName, set);
316
+ }
317
+ set.add(interactionHandler);
318
+ });
319
+ interactionHandler.keyEventsNames.forEach((eventName) => {
320
+ let set = _InteractionHandler.eventListeners.get(eventName);
321
+ if (!set) {
322
+ set = /* @__PURE__ */ new Set();
323
+ document.body.addEventListener(eventName, this.onKeyEvent);
324
+ this.eventListeners.set(eventName, set);
325
+ }
326
+ set.add(interactionHandler);
327
+ });
328
+ }
329
+ static unbindListeners(touchHandler) {
330
+ touchHandler.touchEventsNames.forEach((eventName) => {
331
+ const set = _InteractionHandler.eventListeners.get(eventName);
332
+ if (!set) {
333
+ return;
334
+ }
335
+ set.delete(touchHandler);
336
+ if (set.size <= 0) {
337
+ this.eventListeners.delete(eventName);
338
+ document.body.removeEventListener(eventName, this.onInteractionEvent);
339
+ }
340
+ });
341
+ touchHandler.keyEventsNames.forEach((eventName) => {
342
+ const set = _InteractionHandler.eventListeners.get(eventName);
343
+ if (!set) {
344
+ return;
345
+ }
346
+ set.delete(touchHandler);
347
+ if (set.size <= 0) {
348
+ this.eventListeners.delete(eventName);
349
+ document.body.removeEventListener(eventName, this.onKeyEvent);
350
+ }
351
+ });
352
+ }
353
+ static loadImages() {
354
+ if (this.pointImagesLoaded) {
355
+ return;
356
+ }
357
+ const total = 2;
358
+ let current = 0;
359
+ const onload = (event) => {
360
+ if (++current === total) {
361
+ this.pointImagesLoaded = true;
362
+ }
363
+ if (event.target === this.touchPointImage) {
364
+ this.touchPointRadius = this.touchPointImage.width / 2;
365
+ } else if (event.target === this.centerPointImage) {
366
+ this.centerPointRadius = this.centerPointImage.width / 2;
367
+ }
368
+ };
369
+ const touch = this.touchPointImage = new Image();
370
+ touch.src = TouchPointPNG;
371
+ touch.onload = onload;
372
+ const center = this.centerPointImage = new Image();
373
+ center.src = CenterPointPNG;
374
+ center.onload = onload;
375
+ }
376
+ static getPointerId(type, identifier) {
377
+ if (this.idToPointerMap.has(identifier)) {
378
+ const pointerId2 = this.idToPointerMap.get(identifier);
379
+ if (type === "touchend" || type === "touchcancel") {
380
+ this.idToPointerMap.delete(identifier);
381
+ this.pointerToIdMap.delete(pointerId2);
382
+ }
383
+ return pointerId2;
384
+ }
385
+ let pointerId = 0;
386
+ while (this.pointerToIdMap.has(pointerId)) {
387
+ pointerId++;
388
+ }
389
+ this.idToPointerMap.set(identifier, pointerId);
390
+ this.pointerToIdMap.set(pointerId, identifier);
391
+ return pointerId;
392
+ }
393
+ static buildTouchOnClient(event, screenInfo) {
394
+ const action = this.mapTypeToAction(event.type);
395
+ const { width, height } = screenInfo.videoSize;
396
+ const target = event.target;
397
+ const rect = target.getBoundingClientRect();
398
+ let { clientWidth, clientHeight } = target;
399
+ let touchX = event.clientX - rect.left;
400
+ let touchY = event.clientY - rect.top;
401
+ let invalid = false;
402
+ if (touchX < 0 || touchX > clientWidth || touchY < 0 || touchY > clientHeight) {
403
+ invalid = true;
404
+ }
405
+ const eps = 1e5;
406
+ const ratio = width / height;
407
+ const shouldBe = Math.round(eps * ratio);
408
+ const haveNow = Math.round(eps * clientWidth / clientHeight);
409
+ if (shouldBe > haveNow) {
410
+ const realHeight = Math.ceil(clientWidth / ratio);
411
+ const top = (clientHeight - realHeight) / 2;
412
+ if (touchY < top || touchY > top + realHeight) {
413
+ invalid = true;
414
+ }
415
+ touchY -= top;
416
+ clientHeight = realHeight;
417
+ } else if (shouldBe < haveNow) {
418
+ const realWidth = Math.ceil(clientHeight * ratio);
419
+ const left = (clientWidth - realWidth) / 2;
420
+ if (touchX < left || touchX > left + realWidth) {
421
+ invalid = true;
422
+ }
423
+ touchX -= left;
424
+ clientWidth = realWidth;
425
+ }
426
+ const x = touchX * width / clientWidth;
427
+ const y = touchY * height / clientHeight;
428
+ const size = new Size(width, height);
429
+ const point = new Point(x, y);
430
+ const position = new Position(point, size);
431
+ if (x < 0 || y < 0 || x > width || y > height) {
432
+ invalid = true;
433
+ }
434
+ return {
435
+ client: {
436
+ width: clientWidth,
437
+ height: clientHeight
438
+ },
439
+ touch: {
440
+ invalid,
441
+ action,
442
+ position,
443
+ buttons: event.buttons
444
+ }
445
+ };
446
+ }
447
+ static validateMessage(originalEvent, message, storage, logPrefix) {
448
+ const messages = [];
449
+ const { action, pointerId } = message;
450
+ const previous = storage.get(pointerId);
451
+ if (action === MotionEvent.ACTION_UP) {
452
+ if (!previous) {
453
+ console.warn(logPrefix, "Received ACTION_UP while there are no DOWN stored");
454
+ } else {
455
+ storage.delete(pointerId);
456
+ messages.push(message);
457
+ }
458
+ } else if (action === MotionEvent.ACTION_DOWN) {
459
+ if (previous) {
460
+ console.warn(logPrefix, "Received ACTION_DOWN while already has one stored");
461
+ } else {
462
+ storage.set(pointerId, message);
463
+ messages.push(message);
464
+ }
465
+ } else if (action === MotionEvent.ACTION_MOVE) {
466
+ if (!previous) {
467
+ if (originalEvent instanceof MouseEvent && originalEvent.buttons || window["TouchEvent"] && originalEvent instanceof TouchEvent) {
468
+ console.warn(logPrefix, "Received ACTION_MOVE while there are no DOWN stored");
469
+ const emulated = _InteractionHandler.createEmulatedMessage(MotionEvent.ACTION_DOWN, message);
470
+ messages.push(emulated);
471
+ storage.set(pointerId, emulated);
472
+ }
473
+ } else {
474
+ messages.push(message);
475
+ storage.set(pointerId, message);
476
+ }
477
+ }
478
+ return messages;
479
+ }
480
+ static createEmulatedMessage(action, event) {
481
+ const { pointerId, position, buttons } = event;
482
+ let pressure = event.pressure;
483
+ if (action === MotionEvent.ACTION_UP) {
484
+ pressure = 0;
485
+ }
486
+ return new TouchControlMessage(action, pointerId, position, pressure, buttons);
487
+ }
488
+ static mapTypeToAction(type) {
489
+ return this.EVENT_ACTION_MAP[type];
490
+ }
491
+ getTouch(e, screenInfo, ctrlKey, shiftKey) {
492
+ const touchOnClient = _InteractionHandler.buildTouchOnClient(e, screenInfo);
493
+ if (!touchOnClient) {
494
+ return null;
495
+ }
496
+ const { client, touch } = touchOnClient;
497
+ const result = [touch];
498
+ if (!ctrlKey) {
499
+ this.multiTouchActive = false;
500
+ this.multiTouchCenter = void 0;
501
+ this.multiTouchShift = false;
502
+ this.clearCanvas();
503
+ return result;
504
+ }
505
+ const { position, action, buttons } = touch;
506
+ const { point, screenSize } = position;
507
+ const { width, height } = screenSize;
508
+ const { x, y } = point;
509
+ if (!this.multiTouchActive) {
510
+ if (shiftKey) {
511
+ this.multiTouchCenter = point;
512
+ this.multiTouchShift = true;
513
+ } else {
514
+ this.multiTouchCenter = new Point(client.width / 2, client.height / 2);
515
+ }
516
+ }
517
+ this.multiTouchActive = true;
518
+ let opposite;
519
+ let invalid = false;
520
+ if (this.multiTouchShift && this.multiTouchCenter) {
521
+ const oppoX = 2 * this.multiTouchCenter.x - x;
522
+ const oppoY = 2 * this.multiTouchCenter.y - y;
523
+ opposite = new Point(oppoX, oppoY);
524
+ if (!(oppoX <= width && oppoX >= 0 && oppoY <= height && oppoY >= 0)) {
525
+ invalid = true;
526
+ }
527
+ } else {
528
+ opposite = new Point(client.width - x, client.height - y);
529
+ invalid = touch.invalid;
530
+ }
531
+ if (opposite) {
532
+ result.push({
533
+ invalid,
534
+ action,
535
+ buttons,
536
+ position: new Position(opposite, screenSize)
537
+ });
538
+ }
539
+ return result;
540
+ }
541
+ drawCircle(ctx, point, radius) {
542
+ ctx.beginPath();
543
+ ctx.arc(point.x, point.y, radius, 0, Math.PI * 2, true);
544
+ ctx.stroke();
545
+ }
546
+ drawLine(point1, point2) {
547
+ if (!this.ctx) {
548
+ return;
549
+ }
550
+ this.ctx.save();
551
+ this.ctx.strokeStyle = _InteractionHandler.STROKE_STYLE;
552
+ this.ctx.beginPath();
553
+ this.ctx.moveTo(point1.x, point1.y);
554
+ this.ctx.lineTo(point2.x, point2.y);
555
+ this.ctx.stroke();
556
+ this.ctx.restore();
557
+ }
558
+ drawPoint(point, radius, image) {
559
+ if (!this.ctx) {
560
+ return;
561
+ }
562
+ let { lineWidth } = this.ctx;
563
+ if (_InteractionHandler.pointImagesLoaded && image) {
564
+ radius = image.width / 2;
565
+ lineWidth = 0;
566
+ this.ctx.drawImage(image, point.x - radius, point.y - radius);
567
+ } else {
568
+ this.drawCircle(this.ctx, point, radius);
569
+ }
570
+ const topLeft = new Point(point.x - radius - lineWidth, point.y - radius - lineWidth);
571
+ const bottomRight = new Point(point.x + radius + lineWidth, point.y + radius + lineWidth);
572
+ this.updateDirty(topLeft, bottomRight);
573
+ }
574
+ drawPointer(point) {
575
+ this.drawPoint(point, _InteractionHandler.touchPointRadius, _InteractionHandler.touchPointImage);
576
+ if (this.multiTouchCenter) {
577
+ this.drawLine(this.multiTouchCenter, point);
578
+ }
579
+ }
580
+ drawCenter(point) {
581
+ this.drawPoint(point, _InteractionHandler.centerPointRadius, _InteractionHandler.centerPointImage);
582
+ }
583
+ updateDirty(topLeft, bottomRight) {
584
+ if (!this.dirtyPlace.length) {
585
+ this.dirtyPlace.push(topLeft, bottomRight);
586
+ return;
587
+ }
588
+ const currentTopLeft = this.dirtyPlace[0];
589
+ const currentBottomRight = this.dirtyPlace[1];
590
+ const newTopLeft = new Point(Math.min(currentTopLeft.x, topLeft.x), Math.min(currentTopLeft.y, topLeft.y));
591
+ const newBottomRight = new Point(
592
+ Math.max(currentBottomRight.x, bottomRight.x),
593
+ Math.max(currentBottomRight.y, bottomRight.y)
594
+ );
595
+ this.dirtyPlace.length = 0;
596
+ this.dirtyPlace.push(newTopLeft, newBottomRight);
597
+ }
598
+ clearCanvas() {
599
+ const { clientWidth, clientHeight } = this.tag;
600
+ const ctx = this.ctx;
601
+ if (ctx && this.dirtyPlace.length) {
602
+ const topLeft = this.dirtyPlace[0];
603
+ const bottomRight = this.dirtyPlace[1];
604
+ this.dirtyPlace.length = 0;
605
+ const x = Math.max(topLeft.x, 0);
606
+ const y = Math.max(topLeft.y, 0);
607
+ const w = Math.min(clientWidth, bottomRight.x - x);
608
+ const h = Math.min(clientHeight, bottomRight.y - y);
609
+ ctx.clearRect(x, y, w, h);
610
+ ctx.strokeStyle = _InteractionHandler.STROKE_STYLE;
611
+ }
612
+ }
613
+ formatTouchEvent(e, screenInfo, storage) {
614
+ const logPrefix = `${TAG$2}[formatTouchEvent]`;
615
+ const messages = [];
616
+ const touches = e.changedTouches;
617
+ if (touches && touches.length) {
618
+ for (let i = 0, l = touches.length; i < l; i++) {
619
+ const touch = touches[i];
620
+ const pointerId = _InteractionHandler.getPointerId(e.type, touch.identifier);
621
+ if (touch.target !== this.tag) {
622
+ continue;
623
+ }
624
+ const previous = storage.get(pointerId);
625
+ const item = {
626
+ clientX: touch.clientX,
627
+ clientY: touch.clientY,
628
+ type: e.type,
629
+ buttons: MotionEvent.BUTTON_PRIMARY,
630
+ target: e.target
631
+ };
632
+ const event = _InteractionHandler.buildTouchOnClient(item, screenInfo);
633
+ if (event) {
634
+ const { action, buttons, position, invalid } = event.touch;
635
+ let pressure = 1;
636
+ if (action === MotionEvent.ACTION_UP) {
637
+ pressure = 0;
638
+ } else if (typeof touch.force === "number") {
639
+ pressure = touch.force;
640
+ }
641
+ if (!invalid) {
642
+ const message = new TouchControlMessage(action, pointerId, position, pressure, buttons);
643
+ messages.push(
644
+ ..._InteractionHandler.validateMessage(e, message, storage, `${logPrefix}[validate]`)
645
+ );
646
+ } else {
647
+ if (previous) {
648
+ messages.push(_InteractionHandler.createEmulatedMessage(MotionEvent.ACTION_UP, previous));
649
+ storage.delete(pointerId);
650
+ }
651
+ }
652
+ } else {
653
+ console.error(logPrefix, `Failed to format touch`, touch);
654
+ }
655
+ }
656
+ } else {
657
+ console.error(logPrefix, 'No "touches"', e);
658
+ }
659
+ return messages;
660
+ }
661
+ buildTouchEvent(e, screenInfo, storage) {
662
+ const logPrefix = `${TAG$2}[buildTouchEvent]`;
663
+ const touches = this.getTouch(e, screenInfo, e.ctrlKey, e.shiftKey);
664
+ if (!touches) {
665
+ return [];
666
+ }
667
+ const messages = [];
668
+ const points = [];
669
+ this.clearCanvas();
670
+ touches.forEach((touch, pointerId) => {
671
+ const { action, buttons, position } = touch;
672
+ const previous = storage.get(pointerId);
673
+ if (!touch.invalid) {
674
+ let pressure = 1;
675
+ if (action === MotionEvent.ACTION_UP) {
676
+ pressure = 0;
677
+ }
678
+ const message = new TouchControlMessage(action, pointerId, position, pressure, buttons);
679
+ messages.push(..._InteractionHandler.validateMessage(e, message, storage, `${logPrefix}[validate]`));
680
+ points.push(touch.position.point);
681
+ } else {
682
+ if (previous) {
683
+ points.push(previous.position.point);
684
+ }
685
+ }
686
+ });
687
+ if (this.multiTouchActive) {
688
+ if (this.multiTouchCenter) {
689
+ this.drawCenter(this.multiTouchCenter);
690
+ }
691
+ points.forEach((point) => {
692
+ this.drawPointer(point);
693
+ });
694
+ }
695
+ const hasActionUp = messages.find((message) => {
696
+ return message.action === MotionEvent.ACTION_UP;
697
+ });
698
+ if (hasActionUp && storage.size) {
699
+ console.warn(logPrefix, "Looks like one of Multi-touch pointers was not raised up");
700
+ storage.forEach((message) => {
701
+ messages.push(_InteractionHandler.createEmulatedMessage(MotionEvent.ACTION_UP, message));
702
+ });
703
+ storage.clear();
704
+ }
705
+ return messages;
706
+ }
707
+ release() {
708
+ _InteractionHandler.unbindListeners(this);
709
+ }
710
+ };
711
+ _InteractionHandler.SIMULATE_MULTI_TOUCH = "SIMULATE_MULTI_TOUCH";
712
+ _InteractionHandler.STROKE_STYLE = "#00BEA4";
713
+ _InteractionHandler.EVENT_ACTION_MAP = {
714
+ touchstart: MotionEvent.ACTION_DOWN,
715
+ touchend: MotionEvent.ACTION_UP,
716
+ touchmove: MotionEvent.ACTION_MOVE,
717
+ touchcancel: MotionEvent.ACTION_UP,
718
+ mousedown: MotionEvent.ACTION_DOWN,
719
+ mousemove: MotionEvent.ACTION_MOVE,
720
+ mouseup: MotionEvent.ACTION_UP,
721
+ [_InteractionHandler.SIMULATE_MULTI_TOUCH]: -1
722
+ };
723
+ _InteractionHandler.options = Util.supportsPassive() ? { passive: false } : false;
724
+ _InteractionHandler.idToPointerMap = /* @__PURE__ */ new Map();
725
+ _InteractionHandler.pointerToIdMap = /* @__PURE__ */ new Map();
726
+ _InteractionHandler.touchPointRadius = 10;
727
+ _InteractionHandler.centerPointRadius = 5;
728
+ _InteractionHandler.pointImagesLoaded = false;
729
+ _InteractionHandler.eventListeners = /* @__PURE__ */ new Map();
730
+ _InteractionHandler.onInteractionEvent = (event) => {
731
+ const set = _InteractionHandler.eventListeners.get(event.type);
732
+ if (!set) {
733
+ return;
734
+ }
735
+ set.forEach((instance) => {
736
+ instance.onInteraction(event);
737
+ });
738
+ };
739
+ _InteractionHandler.onKeyEvent = (event) => {
740
+ const set = _InteractionHandler.eventListeners.get(event.type);
741
+ if (!set) {
742
+ return;
743
+ }
744
+ set.forEach((instance) => {
745
+ instance.onKey(event);
746
+ });
747
+ };
748
+ let InteractionHandler = _InteractionHandler;
749
+ const _ScrollControlMessage = class _ScrollControlMessage extends ControlMessage {
750
+ constructor(position, hScroll, vScroll) {
751
+ super(ControlMessage.TYPE_SCROLL);
752
+ this.position = position;
753
+ this.hScroll = hScroll;
754
+ this.vScroll = vScroll;
755
+ }
756
+ /**
757
+ * @override
758
+ */
759
+ toBuffer() {
760
+ const buffer = Buffer.alloc(_ScrollControlMessage.PAYLOAD_LENGTH + 1);
761
+ let offset = 0;
762
+ offset = buffer.writeUInt8(this.type, offset);
763
+ offset = buffer.writeUInt32BE(this.position.point.x, offset);
764
+ offset = buffer.writeUInt32BE(this.position.point.y, offset);
765
+ offset = buffer.writeUInt16BE(this.position.screenSize.width, offset);
766
+ offset = buffer.writeUInt16BE(this.position.screenSize.height, offset);
767
+ offset = buffer.writeInt32BE(this.hScroll, offset);
768
+ buffer.writeInt32BE(this.vScroll, offset);
769
+ return buffer;
770
+ }
771
+ toString() {
772
+ return `ScrollControlMessage{hScroll=${this.hScroll}, vScroll=${this.vScroll}, position=${this.position}}`;
773
+ }
774
+ toJSON() {
775
+ return {
776
+ type: this.type,
777
+ position: this.position.toJSON(),
778
+ hScroll: this.hScroll,
779
+ vScroll: this.vScroll
780
+ };
781
+ }
782
+ };
783
+ _ScrollControlMessage.PAYLOAD_LENGTH = 20;
784
+ let ScrollControlMessage = _ScrollControlMessage;
785
+ const TAG$1 = "[FeaturedTouchHandler]";
786
+ const _FeaturedInteractionHandler = class _FeaturedInteractionHandler extends InteractionHandler {
787
+ constructor(player, listener) {
788
+ super(player, _FeaturedInteractionHandler.touchEventsNames, _FeaturedInteractionHandler.keyEventsNames);
789
+ this.listener = listener;
790
+ this.storedFromMouseEvent = /* @__PURE__ */ new Map();
791
+ this.storedFromTouchEvent = /* @__PURE__ */ new Map();
792
+ this.onMouseEnter = () => {
793
+ this.over = true;
794
+ };
795
+ this.onMouseLeave = () => {
796
+ this.lastPosition = void 0;
797
+ this.over = false;
798
+ this.storedFromMouseEvent.forEach((message) => {
799
+ this.listener.sendMessage(InteractionHandler.createEmulatedMessage(MotionEvent.ACTION_UP, message));
800
+ });
801
+ this.storedFromMouseEvent.clear();
802
+ this.clearCanvas();
803
+ };
804
+ this.tag.addEventListener("mouseleave", this.onMouseLeave);
805
+ this.tag.addEventListener("mouseenter", this.onMouseEnter);
806
+ }
807
+ buildScrollEvent(event, screenInfo) {
808
+ const messages = [];
809
+ const touchOnClient = InteractionHandler.buildTouchOnClient(event, screenInfo);
810
+ if (touchOnClient) {
811
+ const hScroll = event.deltaX > 0 ? -1 : event.deltaX < -0 ? 1 : 0;
812
+ const vScroll = event.deltaY > 0 ? -1 : event.deltaY < -0 ? 1 : 0;
813
+ const time = Date.now();
814
+ if (!this.lastScrollEvent || time - this.lastScrollEvent.time > _FeaturedInteractionHandler.SCROLL_EVENT_THROTTLING_TIME || this.lastScrollEvent.vScroll !== vScroll || this.lastScrollEvent.hScroll !== hScroll) {
815
+ this.lastScrollEvent = { time, hScroll, vScroll };
816
+ messages.push(new ScrollControlMessage(touchOnClient.touch.position, hScroll, vScroll));
817
+ }
818
+ }
819
+ return messages;
820
+ }
821
+ onInteraction(event) {
822
+ const screenInfo = this.player.getScreenInfo();
823
+ if (!screenInfo) {
824
+ return;
825
+ }
826
+ let messages;
827
+ let storage;
828
+ if (event instanceof MouseEvent) {
829
+ if (event.target !== this.tag) {
830
+ return;
831
+ }
832
+ if (window["WheelEvent"] && event instanceof WheelEvent) {
833
+ messages = this.buildScrollEvent(event, screenInfo);
834
+ } else {
835
+ storage = this.storedFromMouseEvent;
836
+ messages = this.buildTouchEvent(event, screenInfo, storage);
837
+ }
838
+ if (this.over) {
839
+ this.lastPosition = event;
840
+ }
841
+ } else if (window["TouchEvent"] && event instanceof TouchEvent) {
842
+ if (event.target !== this.tag) {
843
+ return;
844
+ }
845
+ storage = this.storedFromTouchEvent;
846
+ messages = this.formatTouchEvent(event, screenInfo, storage);
847
+ } else {
848
+ console.error(TAG$1, "Unsupported event", event);
849
+ return;
850
+ }
851
+ if (event.cancelable) {
852
+ event.preventDefault();
853
+ }
854
+ event.stopPropagation();
855
+ messages.forEach((message) => {
856
+ this.listener.sendMessage(message);
857
+ });
858
+ }
859
+ onKey(event) {
860
+ if (!this.lastPosition) {
861
+ return;
862
+ }
863
+ const screenInfo = this.player.getScreenInfo();
864
+ if (!screenInfo) {
865
+ return;
866
+ }
867
+ const { ctrlKey, shiftKey } = event;
868
+ const { target, button, buttons, clientY, clientX } = this.lastPosition;
869
+ const type = InteractionHandler.SIMULATE_MULTI_TOUCH;
870
+ const props = { ctrlKey, shiftKey, type, target, button, buttons, clientX, clientY };
871
+ this.buildTouchEvent(props, screenInfo, /* @__PURE__ */ new Map());
872
+ }
873
+ release() {
874
+ super.release();
875
+ this.tag.removeEventListener("mouseleave", this.onMouseLeave);
876
+ this.tag.removeEventListener("mouseenter", this.onMouseEnter);
877
+ this.storedFromMouseEvent.clear();
878
+ }
879
+ };
880
+ _FeaturedInteractionHandler.touchEventsNames = [
881
+ "touchstart",
882
+ "touchend",
883
+ "touchmove",
884
+ "touchcancel",
885
+ "mousedown",
886
+ "mouseup",
887
+ "mousemove",
888
+ "wheel"
889
+ ];
890
+ _FeaturedInteractionHandler.keyEventsNames = ["keydown", "keyup"];
891
+ _FeaturedInteractionHandler.SCROLL_EVENT_THROTTLING_TIME = 30;
892
+ let FeaturedInteractionHandler = _FeaturedInteractionHandler;
893
+ const TAG = "[SimpleTouchHandler]";
894
+ const _SimpleInteractionHandler = class _SimpleInteractionHandler extends InteractionHandler {
895
+ constructor(player, listener) {
896
+ super(player, _SimpleInteractionHandler.touchEventsNames, []);
897
+ this.listener = listener;
898
+ this.storage = /* @__PURE__ */ new Map();
899
+ }
900
+ onInteraction(event) {
901
+ let handled = false;
902
+ if (!(event instanceof MouseEvent)) {
903
+ return;
904
+ }
905
+ if (event.target === this.tag) {
906
+ const screenInfo = this.player.getScreenInfo();
907
+ if (!screenInfo) {
908
+ return;
909
+ }
910
+ const events = this.buildTouchEvent(event, screenInfo, this.storage);
911
+ if (events.length > 1) {
912
+ console.warn(TAG, "Too many events", events);
913
+ return;
914
+ }
915
+ const downEventName = "mousedown";
916
+ if (events.length === 1) {
917
+ handled = true;
918
+ if (event.type === downEventName) {
919
+ this.startPosition = events[0].position;
920
+ } else {
921
+ if (this.startPosition) {
922
+ this.endPosition = events[0].position;
923
+ } else {
924
+ console.warn(TAG, `Received "${event.type}" before "${downEventName}"`);
925
+ }
926
+ }
927
+ if (this.startPosition) {
928
+ this.drawPointer(this.startPosition.point);
929
+ }
930
+ if (this.endPosition) {
931
+ this.drawPointer(this.endPosition.point);
932
+ if (this.startPosition) {
933
+ this.drawLine(this.startPosition.point, this.endPosition.point);
934
+ }
935
+ }
936
+ if (event.type === "mouseup") {
937
+ if (this.startPosition && this.endPosition) {
938
+ this.clearCanvas();
939
+ if (this.startPosition.point.distance(this.endPosition.point) < 10) {
940
+ this.listener.performClick(this.endPosition);
941
+ } else {
942
+ this.listener.performScroll(this.startPosition, this.endPosition);
943
+ }
944
+ }
945
+ }
946
+ }
947
+ if (handled) {
948
+ if (event.cancelable) {
949
+ event.preventDefault();
950
+ }
951
+ event.stopPropagation();
952
+ }
953
+ }
954
+ if (event.type === "mouseup") {
955
+ this.startPosition = void 0;
956
+ this.endPosition = void 0;
957
+ }
958
+ }
959
+ onKey() {
960
+ throw Error(`${TAG} Unsupported`);
961
+ }
962
+ };
963
+ _SimpleInteractionHandler.touchEventsNames = ["mousedown", "mouseup", "mousemove"];
964
+ let SimpleInteractionHandler = _SimpleInteractionHandler;
965
+ const _KeyCodeControlMessage = class _KeyCodeControlMessage extends ControlMessage {
966
+ constructor(action, keycode, repeat, metaState) {
967
+ super(ControlMessage.TYPE_KEYCODE);
968
+ this.action = action;
969
+ this.keycode = keycode;
970
+ this.repeat = repeat;
971
+ this.metaState = metaState;
972
+ }
973
+ /**
974
+ * @override
975
+ */
976
+ toBuffer() {
977
+ const buffer = Buffer.alloc(_KeyCodeControlMessage.PAYLOAD_LENGTH + 1);
978
+ let offset = 0;
979
+ offset = buffer.writeInt8(this.type, offset);
980
+ offset = buffer.writeInt8(this.action, offset);
981
+ offset = buffer.writeInt32BE(this.keycode, offset);
982
+ offset = buffer.writeInt32BE(this.repeat, offset);
983
+ buffer.writeInt32BE(this.metaState, offset);
984
+ return buffer;
985
+ }
986
+ toString() {
987
+ return `KeyCodeControlMessage{action=${this.action}, keycode=${this.keycode}, metaState=${this.metaState}}`;
988
+ }
989
+ toJSON() {
990
+ return {
991
+ type: this.type,
992
+ action: this.action,
993
+ keycode: this.keycode,
994
+ metaState: this.metaState,
995
+ repeat: this.repeat
996
+ };
997
+ }
998
+ };
999
+ _KeyCodeControlMessage.PAYLOAD_LENGTH = 13;
1000
+ let KeyCodeControlMessage = _KeyCodeControlMessage;
1001
+ const _TextControlMessage = class _TextControlMessage extends ControlMessage {
1002
+ constructor(text) {
1003
+ super(ControlMessage.TYPE_TEXT);
1004
+ this.text = text;
1005
+ }
1006
+ getText() {
1007
+ return this.text;
1008
+ }
1009
+ /**
1010
+ * @override
1011
+ */
1012
+ toBuffer() {
1013
+ const length = this.text.length;
1014
+ const buffer = Buffer.alloc(length + 1 + _TextControlMessage.TEXT_SIZE_FIELD_LENGTH);
1015
+ let offset = 0;
1016
+ offset = buffer.writeUInt8(this.type, offset);
1017
+ offset = buffer.writeUInt32BE(length, offset);
1018
+ buffer.write(this.text, offset);
1019
+ return buffer;
1020
+ }
1021
+ toString() {
1022
+ return `TextControlMessage{text=${this.text}}`;
1023
+ }
1024
+ toJSON() {
1025
+ return {
1026
+ type: this.type,
1027
+ text: this.text
1028
+ };
1029
+ }
1030
+ };
1031
+ _TextControlMessage.TEXT_SIZE_FIELD_LENGTH = 4;
1032
+ let TextControlMessage = _TextControlMessage;
1033
+ var FilePushState = /* @__PURE__ */ ((FilePushState2) => {
1034
+ FilePushState2[FilePushState2["NEW"] = 0] = "NEW";
1035
+ FilePushState2[FilePushState2["START"] = 1] = "START";
1036
+ FilePushState2[FilePushState2["APPEND"] = 2] = "APPEND";
1037
+ FilePushState2[FilePushState2["FINISH"] = 3] = "FINISH";
1038
+ FilePushState2[FilePushState2["CANCEL"] = 4] = "CANCEL";
1039
+ return FilePushState2;
1040
+ })(FilePushState || {});
1041
+ const _CommandControlMessage = class _CommandControlMessage extends ControlMessage {
1042
+ constructor(type) {
1043
+ super(type);
1044
+ this.type = type;
1045
+ }
1046
+ /**
1047
+ * 注意: createSetVideoSettingsCommand 方法依赖 VideoSettings 类
1048
+ * 该方法未包含在此独立模块中
1049
+ * 如需使用,请在应用中自行实现或从原项目导入
1050
+ */
1051
+ // public static createSetVideoSettingsCommand(videoSettings: VideoSettings): CommandControlMessage {
1052
+ // ...
1053
+ // }
1054
+ static createSetClipboardCommand(text, paste = false) {
1055
+ const event = new _CommandControlMessage(ControlMessage.TYPE_SET_CLIPBOARD);
1056
+ const textBytes = text ? Util.stringToUtf8ByteArray(text) : null;
1057
+ const textLength = textBytes ? textBytes.length : 0;
1058
+ let offset = 0;
1059
+ const buffer = Buffer.alloc(1 + 1 + 4 + textLength);
1060
+ offset = buffer.writeInt8(event.type, offset);
1061
+ offset = buffer.writeInt8(paste ? 1 : 0, offset);
1062
+ offset = buffer.writeInt32BE(textLength, offset);
1063
+ if (textBytes) {
1064
+ textBytes.forEach((byte, index) => {
1065
+ buffer.writeUInt8(byte, index + offset);
1066
+ });
1067
+ }
1068
+ event.buffer = buffer;
1069
+ return event;
1070
+ }
1071
+ static createSetScreenPowerModeCommand(mode) {
1072
+ const event = new _CommandControlMessage(ControlMessage.TYPE_SET_SCREEN_POWER_MODE);
1073
+ let offset = 0;
1074
+ const buffer = Buffer.alloc(1 + 1);
1075
+ offset = buffer.writeInt8(event.type, offset);
1076
+ buffer.writeUInt8(mode ? 1 : 0, offset);
1077
+ event.buffer = buffer;
1078
+ return event;
1079
+ }
1080
+ static createPushFileCommand(params) {
1081
+ const { id, fileName, fileSize, chunk, state } = params;
1082
+ if (state === 1) {
1083
+ return this.createPushFileStartCommand(id, fileName, fileSize);
1084
+ }
1085
+ if (state === 2) {
1086
+ if (!chunk) {
1087
+ throw TypeError("Invalid type");
1088
+ }
1089
+ return this.createPushFileChunkCommand(id, chunk);
1090
+ }
1091
+ if (state === 4 || state === 3 || state === 0) {
1092
+ return this.createPushFileOtherCommand(id, state);
1093
+ }
1094
+ throw TypeError(`Unsupported state: "${state}"`);
1095
+ }
1096
+ static createPushFileStartCommand(id, fileName, fileSize) {
1097
+ const event = new _CommandControlMessage(ControlMessage.TYPE_PUSH_FILE);
1098
+ const text = Util.stringToUtf8ByteArray(fileName);
1099
+ const typeField = 1;
1100
+ const idField = 2;
1101
+ const stateField = 1;
1102
+ const sizeField = 4;
1103
+ const textLengthField = 2;
1104
+ const textLength = text.length;
1105
+ let offset = _CommandControlMessage.PAYLOAD_LENGTH;
1106
+ const buffer = Buffer.alloc(
1107
+ offset + typeField + idField + stateField + sizeField + textLengthField + textLength
1108
+ );
1109
+ buffer.writeUInt8(event.type, offset);
1110
+ offset += typeField;
1111
+ buffer.writeInt16BE(id, offset);
1112
+ offset += idField;
1113
+ buffer.writeInt8(1, offset);
1114
+ offset += stateField;
1115
+ buffer.writeUInt32BE(fileSize, offset);
1116
+ offset += sizeField;
1117
+ buffer.writeUInt16BE(textLength, offset);
1118
+ offset += textLengthField;
1119
+ text.forEach((byte, index) => {
1120
+ buffer.writeUInt8(byte, index + offset);
1121
+ });
1122
+ event.buffer = buffer;
1123
+ return event;
1124
+ }
1125
+ static createPushFileChunkCommand(id, chunk) {
1126
+ const event = new _CommandControlMessage(ControlMessage.TYPE_PUSH_FILE);
1127
+ const typeField = 1;
1128
+ const idField = 2;
1129
+ const stateField = 1;
1130
+ const chunkLengthField = 4;
1131
+ const chunkLength = chunk.byteLength;
1132
+ let offset = _CommandControlMessage.PAYLOAD_LENGTH;
1133
+ const buffer = Buffer.alloc(offset + typeField + idField + stateField + chunkLengthField + chunkLength);
1134
+ buffer.writeUInt8(event.type, offset);
1135
+ offset += typeField;
1136
+ buffer.writeInt16BE(id, offset);
1137
+ offset += idField;
1138
+ buffer.writeInt8(2, offset);
1139
+ offset += stateField;
1140
+ buffer.writeUInt32BE(chunkLength, offset);
1141
+ offset += chunkLengthField;
1142
+ Array.from(chunk).forEach((byte, index) => {
1143
+ buffer.writeUInt8(byte, index + offset);
1144
+ });
1145
+ event.buffer = buffer;
1146
+ return event;
1147
+ }
1148
+ static createPushFileOtherCommand(id, state) {
1149
+ const event = new _CommandControlMessage(ControlMessage.TYPE_PUSH_FILE);
1150
+ const typeField = 1;
1151
+ const idField = 2;
1152
+ const stateField = 1;
1153
+ let offset = _CommandControlMessage.PAYLOAD_LENGTH;
1154
+ const buffer = Buffer.alloc(offset + typeField + idField + stateField);
1155
+ buffer.writeUInt8(event.type, offset);
1156
+ offset += typeField;
1157
+ buffer.writeInt16BE(id, offset);
1158
+ offset += idField;
1159
+ buffer.writeInt8(state, offset);
1160
+ event.buffer = buffer;
1161
+ return event;
1162
+ }
1163
+ static pushFileCommandFromBuffer(buffer) {
1164
+ let offset = 0;
1165
+ const type = buffer.readUInt8(offset);
1166
+ offset += 1;
1167
+ if (type !== _CommandControlMessage.TYPE_PUSH_FILE) {
1168
+ throw TypeError(`Incorrect type: "${type}"`);
1169
+ }
1170
+ const id = buffer.readInt16BE(offset);
1171
+ offset += 2;
1172
+ const state = buffer.readInt8(offset);
1173
+ offset += 1;
1174
+ let chunk;
1175
+ let fileSize;
1176
+ let fileName;
1177
+ if (state === 2) {
1178
+ const chunkLength = buffer.readUInt32BE(offset);
1179
+ offset += 4;
1180
+ chunk = buffer.slice(offset, offset + chunkLength);
1181
+ } else if (state === 1) {
1182
+ fileSize = buffer.readUInt32BE(offset);
1183
+ offset += 4;
1184
+ const textLength = buffer.readUInt16BE(offset);
1185
+ offset += 2;
1186
+ fileName = Util.utf8ByteArrayToString(buffer.slice(offset, offset + textLength));
1187
+ }
1188
+ return { id, state, chunk, fileName, fileSize };
1189
+ }
1190
+ /**
1191
+ * @override
1192
+ */
1193
+ toBuffer() {
1194
+ if (!this.buffer) {
1195
+ const buffer = Buffer.alloc(_CommandControlMessage.PAYLOAD_LENGTH + 1);
1196
+ buffer.writeUInt8(this.type, 0);
1197
+ this.buffer = buffer;
1198
+ }
1199
+ return this.buffer;
1200
+ }
1201
+ toString() {
1202
+ const buffer = this.buffer ? `, buffer=[${this.buffer.join(",")}]` : "";
1203
+ return `CommandControlMessage{action=${this.type}${buffer}}`;
1204
+ }
1205
+ };
1206
+ _CommandControlMessage.PAYLOAD_LENGTH = 0;
1207
+ _CommandControlMessage.Commands = /* @__PURE__ */ new Map([
1208
+ [ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL, "Expand notifications"],
1209
+ [ControlMessage.TYPE_EXPAND_SETTINGS_PANEL, "Expand settings"],
1210
+ [ControlMessage.TYPE_COLLAPSE_PANELS, "Collapse panels"],
1211
+ [ControlMessage.TYPE_GET_CLIPBOARD, "Get clipboard"],
1212
+ [ControlMessage.TYPE_SET_CLIPBOARD, "Set clipboard"],
1213
+ [ControlMessage.TYPE_ROTATE_DEVICE, "Rotate device"],
1214
+ [ControlMessage.TYPE_CHANGE_STREAM_PARAMETERS, "Change video settings"]
1215
+ ]);
1216
+ let CommandControlMessage = _CommandControlMessage;
1217
+ const _KeyEvent = class _KeyEvent {
1218
+ };
1219
+ _KeyEvent.ACTION_DOWN = 0;
1220
+ _KeyEvent.ACTION_UP = 1;
1221
+ _KeyEvent.KEYCODE_0 = 7;
1222
+ _KeyEvent.KEYCODE_1 = 8;
1223
+ _KeyEvent.KEYCODE_11 = 227;
1224
+ _KeyEvent.KEYCODE_12 = 228;
1225
+ _KeyEvent.KEYCODE_2 = 9;
1226
+ _KeyEvent.KEYCODE_3 = 10;
1227
+ _KeyEvent.KEYCODE_3D_MODE = 206;
1228
+ _KeyEvent.KEYCODE_4 = 11;
1229
+ _KeyEvent.KEYCODE_5 = 12;
1230
+ _KeyEvent.KEYCODE_6 = 13;
1231
+ _KeyEvent.KEYCODE_7 = 14;
1232
+ _KeyEvent.KEYCODE_8 = 15;
1233
+ _KeyEvent.KEYCODE_9 = 16;
1234
+ _KeyEvent.KEYCODE_A = 29;
1235
+ _KeyEvent.KEYCODE_ALL_APPS = 284;
1236
+ _KeyEvent.KEYCODE_ALT_LEFT = 57;
1237
+ _KeyEvent.KEYCODE_ALT_RIGHT = 58;
1238
+ _KeyEvent.KEYCODE_APOSTROPHE = 75;
1239
+ _KeyEvent.KEYCODE_APP_SWITCH = 187;
1240
+ _KeyEvent.KEYCODE_ASSIST = 219;
1241
+ _KeyEvent.KEYCODE_AT = 77;
1242
+ _KeyEvent.KEYCODE_AVR_INPUT = 182;
1243
+ _KeyEvent.KEYCODE_AVR_POWER = 181;
1244
+ _KeyEvent.KEYCODE_B = 30;
1245
+ _KeyEvent.KEYCODE_BACK = 4;
1246
+ _KeyEvent.KEYCODE_BACKSLASH = 73;
1247
+ _KeyEvent.KEYCODE_BOOKMARK = 174;
1248
+ _KeyEvent.KEYCODE_BREAK = 121;
1249
+ _KeyEvent.KEYCODE_BRIGHTNESS_DOWN = 220;
1250
+ _KeyEvent.KEYCODE_BRIGHTNESS_UP = 221;
1251
+ _KeyEvent.KEYCODE_BUTTON_1 = 188;
1252
+ _KeyEvent.KEYCODE_BUTTON_10 = 197;
1253
+ _KeyEvent.KEYCODE_BUTTON_11 = 198;
1254
+ _KeyEvent.KEYCODE_BUTTON_12 = 199;
1255
+ _KeyEvent.KEYCODE_BUTTON_13 = 200;
1256
+ _KeyEvent.KEYCODE_BUTTON_14 = 201;
1257
+ _KeyEvent.KEYCODE_BUTTON_15 = 202;
1258
+ _KeyEvent.KEYCODE_BUTTON_16 = 203;
1259
+ _KeyEvent.KEYCODE_BUTTON_2 = 189;
1260
+ _KeyEvent.KEYCODE_BUTTON_3 = 190;
1261
+ _KeyEvent.KEYCODE_BUTTON_4 = 191;
1262
+ _KeyEvent.KEYCODE_BUTTON_5 = 192;
1263
+ _KeyEvent.KEYCODE_BUTTON_6 = 193;
1264
+ _KeyEvent.KEYCODE_BUTTON_7 = 194;
1265
+ _KeyEvent.KEYCODE_BUTTON_8 = 195;
1266
+ _KeyEvent.KEYCODE_BUTTON_9 = 196;
1267
+ _KeyEvent.KEYCODE_BUTTON_A = 96;
1268
+ _KeyEvent.KEYCODE_BUTTON_B = 97;
1269
+ _KeyEvent.KEYCODE_BUTTON_C = 98;
1270
+ _KeyEvent.KEYCODE_BUTTON_L1 = 102;
1271
+ _KeyEvent.KEYCODE_BUTTON_L2 = 104;
1272
+ _KeyEvent.KEYCODE_BUTTON_MODE = 110;
1273
+ _KeyEvent.KEYCODE_BUTTON_R1 = 103;
1274
+ _KeyEvent.KEYCODE_BUTTON_R2 = 105;
1275
+ _KeyEvent.KEYCODE_BUTTON_SELECT = 109;
1276
+ _KeyEvent.KEYCODE_BUTTON_START = 108;
1277
+ _KeyEvent.KEYCODE_BUTTON_THUMBL = 106;
1278
+ _KeyEvent.KEYCODE_BUTTON_THUMBR = 107;
1279
+ _KeyEvent.KEYCODE_BUTTON_X = 99;
1280
+ _KeyEvent.KEYCODE_BUTTON_Y = 100;
1281
+ _KeyEvent.KEYCODE_BUTTON_Z = 101;
1282
+ _KeyEvent.KEYCODE_C = 31;
1283
+ _KeyEvent.KEYCODE_CALCULATOR = 210;
1284
+ _KeyEvent.KEYCODE_CALENDAR = 208;
1285
+ _KeyEvent.KEYCODE_CALL = 5;
1286
+ _KeyEvent.KEYCODE_CAMERA = 27;
1287
+ _KeyEvent.KEYCODE_CAPS_LOCK = 115;
1288
+ _KeyEvent.KEYCODE_CAPTIONS = 175;
1289
+ _KeyEvent.KEYCODE_CHANNEL_DOWN = 167;
1290
+ _KeyEvent.KEYCODE_CHANNEL_UP = 166;
1291
+ _KeyEvent.KEYCODE_CLEAR = 28;
1292
+ _KeyEvent.KEYCODE_COMMA = 55;
1293
+ _KeyEvent.KEYCODE_CONTACTS = 207;
1294
+ _KeyEvent.KEYCODE_COPY = 278;
1295
+ _KeyEvent.KEYCODE_CTRL_LEFT = 113;
1296
+ _KeyEvent.KEYCODE_CTRL_RIGHT = 114;
1297
+ _KeyEvent.KEYCODE_CUT = 277;
1298
+ _KeyEvent.KEYCODE_D = 32;
1299
+ _KeyEvent.KEYCODE_DEL = 67;
1300
+ _KeyEvent.KEYCODE_DPAD_CENTER = 23;
1301
+ _KeyEvent.KEYCODE_DPAD_DOWN = 20;
1302
+ _KeyEvent.KEYCODE_DPAD_DOWN_LEFT = 269;
1303
+ _KeyEvent.KEYCODE_DPAD_DOWN_RIGHT = 271;
1304
+ _KeyEvent.KEYCODE_DPAD_LEFT = 21;
1305
+ _KeyEvent.KEYCODE_DPAD_RIGHT = 22;
1306
+ _KeyEvent.KEYCODE_DPAD_UP = 19;
1307
+ _KeyEvent.KEYCODE_DPAD_UP_LEFT = 268;
1308
+ _KeyEvent.KEYCODE_DPAD_UP_RIGHT = 270;
1309
+ _KeyEvent.KEYCODE_DVR = 173;
1310
+ _KeyEvent.KEYCODE_E = 33;
1311
+ _KeyEvent.KEYCODE_EISU = 212;
1312
+ _KeyEvent.KEYCODE_ENDCALL = 6;
1313
+ _KeyEvent.KEYCODE_ENTER = 66;
1314
+ _KeyEvent.KEYCODE_ENVELOPE = 65;
1315
+ _KeyEvent.KEYCODE_EQUALS = 70;
1316
+ _KeyEvent.KEYCODE_ESCAPE = 111;
1317
+ _KeyEvent.KEYCODE_EXPLORER = 64;
1318
+ _KeyEvent.KEYCODE_F = 34;
1319
+ _KeyEvent.KEYCODE_F1 = 131;
1320
+ _KeyEvent.KEYCODE_F10 = 140;
1321
+ _KeyEvent.KEYCODE_F11 = 141;
1322
+ _KeyEvent.KEYCODE_F12 = 142;
1323
+ _KeyEvent.KEYCODE_F2 = 132;
1324
+ _KeyEvent.KEYCODE_F3 = 133;
1325
+ _KeyEvent.KEYCODE_F4 = 134;
1326
+ _KeyEvent.KEYCODE_F5 = 135;
1327
+ _KeyEvent.KEYCODE_F6 = 136;
1328
+ _KeyEvent.KEYCODE_F7 = 137;
1329
+ _KeyEvent.KEYCODE_F8 = 138;
1330
+ _KeyEvent.KEYCODE_F9 = 139;
1331
+ _KeyEvent.KEYCODE_FOCUS = 80;
1332
+ _KeyEvent.KEYCODE_FORWARD = 125;
1333
+ _KeyEvent.KEYCODE_FORWARD_DEL = 112;
1334
+ _KeyEvent.KEYCODE_FUNCTION = 119;
1335
+ _KeyEvent.KEYCODE_G = 35;
1336
+ _KeyEvent.KEYCODE_GRAVE = 68;
1337
+ _KeyEvent.KEYCODE_GUIDE = 172;
1338
+ _KeyEvent.KEYCODE_H = 36;
1339
+ _KeyEvent.KEYCODE_HEADSETHOOK = 79;
1340
+ _KeyEvent.KEYCODE_HELP = 259;
1341
+ _KeyEvent.KEYCODE_HENKAN = 214;
1342
+ _KeyEvent.KEYCODE_HOME = 3;
1343
+ _KeyEvent.KEYCODE_I = 37;
1344
+ _KeyEvent.KEYCODE_INFO = 165;
1345
+ _KeyEvent.KEYCODE_INSERT = 124;
1346
+ _KeyEvent.KEYCODE_J = 38;
1347
+ _KeyEvent.KEYCODE_K = 39;
1348
+ _KeyEvent.KEYCODE_KANA = 218;
1349
+ _KeyEvent.KEYCODE_KATAKANA_HIRAGANA = 215;
1350
+ _KeyEvent.KEYCODE_L = 40;
1351
+ _KeyEvent.KEYCODE_LANGUAGE_SWITCH = 204;
1352
+ _KeyEvent.KEYCODE_LAST_CHANNEL = 229;
1353
+ _KeyEvent.KEYCODE_LEFT_BRACKET = 71;
1354
+ _KeyEvent.KEYCODE_M = 41;
1355
+ _KeyEvent.KEYCODE_MANNER_MODE = 205;
1356
+ _KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK = 222;
1357
+ _KeyEvent.KEYCODE_MEDIA_CLOSE = 128;
1358
+ _KeyEvent.KEYCODE_MEDIA_EJECT = 129;
1359
+ _KeyEvent.KEYCODE_MEDIA_FAST_FORWARD = 90;
1360
+ _KeyEvent.KEYCODE_MEDIA_NEXT = 87;
1361
+ _KeyEvent.KEYCODE_MEDIA_PAUSE = 127;
1362
+ _KeyEvent.KEYCODE_MEDIA_PLAY = 126;
1363
+ _KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE = 85;
1364
+ _KeyEvent.KEYCODE_MEDIA_PREVIOUS = 88;
1365
+ _KeyEvent.KEYCODE_MEDIA_RECORD = 130;
1366
+ _KeyEvent.KEYCODE_MEDIA_REWIND = 89;
1367
+ _KeyEvent.KEYCODE_MEDIA_SKIP_BACKWARD = 273;
1368
+ _KeyEvent.KEYCODE_MEDIA_SKIP_FORWARD = 272;
1369
+ _KeyEvent.KEYCODE_MEDIA_STEP_BACKWARD = 275;
1370
+ _KeyEvent.KEYCODE_MEDIA_STEP_FORWARD = 274;
1371
+ _KeyEvent.KEYCODE_MEDIA_STOP = 86;
1372
+ _KeyEvent.KEYCODE_MEDIA_TOP_MENU = 226;
1373
+ _KeyEvent.KEYCODE_MENU = 82;
1374
+ _KeyEvent.KEYCODE_META_LEFT = 117;
1375
+ _KeyEvent.KEYCODE_META_RIGHT = 118;
1376
+ _KeyEvent.KEYCODE_MINUS = 69;
1377
+ _KeyEvent.KEYCODE_MOVE_END = 123;
1378
+ _KeyEvent.KEYCODE_MOVE_HOME = 122;
1379
+ _KeyEvent.KEYCODE_MUHENKAN = 213;
1380
+ _KeyEvent.KEYCODE_MUSIC = 209;
1381
+ _KeyEvent.KEYCODE_MUTE = 91;
1382
+ _KeyEvent.KEYCODE_N = 42;
1383
+ _KeyEvent.KEYCODE_NAVIGATE_IN = 262;
1384
+ _KeyEvent.KEYCODE_NAVIGATE_NEXT = 261;
1385
+ _KeyEvent.KEYCODE_NAVIGATE_OUT = 263;
1386
+ _KeyEvent.KEYCODE_NAVIGATE_PREVIOUS = 260;
1387
+ _KeyEvent.KEYCODE_NOTIFICATION = 83;
1388
+ _KeyEvent.KEYCODE_NUM = 78;
1389
+ _KeyEvent.KEYCODE_NUMPAD_0 = 144;
1390
+ _KeyEvent.KEYCODE_NUMPAD_1 = 145;
1391
+ _KeyEvent.KEYCODE_NUMPAD_2 = 146;
1392
+ _KeyEvent.KEYCODE_NUMPAD_3 = 147;
1393
+ _KeyEvent.KEYCODE_NUMPAD_4 = 148;
1394
+ _KeyEvent.KEYCODE_NUMPAD_5 = 149;
1395
+ _KeyEvent.KEYCODE_NUMPAD_6 = 150;
1396
+ _KeyEvent.KEYCODE_NUMPAD_7 = 151;
1397
+ _KeyEvent.KEYCODE_NUMPAD_8 = 152;
1398
+ _KeyEvent.KEYCODE_NUMPAD_9 = 153;
1399
+ _KeyEvent.KEYCODE_NUMPAD_ADD = 157;
1400
+ _KeyEvent.KEYCODE_NUMPAD_COMMA = 159;
1401
+ _KeyEvent.KEYCODE_NUMPAD_DIVIDE = 154;
1402
+ _KeyEvent.KEYCODE_NUMPAD_DOT = 158;
1403
+ _KeyEvent.KEYCODE_NUMPAD_ENTER = 160;
1404
+ _KeyEvent.KEYCODE_NUMPAD_EQUALS = 161;
1405
+ _KeyEvent.KEYCODE_NUMPAD_LEFT_PAREN = 162;
1406
+ _KeyEvent.KEYCODE_NUMPAD_MULTIPLY = 155;
1407
+ _KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN = 163;
1408
+ _KeyEvent.KEYCODE_NUMPAD_SUBTRACT = 156;
1409
+ _KeyEvent.KEYCODE_NUM_LOCK = 143;
1410
+ _KeyEvent.KEYCODE_O = 43;
1411
+ _KeyEvent.KEYCODE_P = 44;
1412
+ _KeyEvent.KEYCODE_PAGE_DOWN = 93;
1413
+ _KeyEvent.KEYCODE_PAGE_UP = 92;
1414
+ _KeyEvent.KEYCODE_PAIRING = 225;
1415
+ _KeyEvent.KEYCODE_PASTE = 279;
1416
+ _KeyEvent.KEYCODE_PERIOD = 56;
1417
+ _KeyEvent.KEYCODE_PICTSYMBOLS = 94;
1418
+ _KeyEvent.KEYCODE_PLUS = 81;
1419
+ _KeyEvent.KEYCODE_POUND = 18;
1420
+ _KeyEvent.KEYCODE_POWER = 26;
1421
+ _KeyEvent.KEYCODE_PROFILE_SWITCH = 288;
1422
+ _KeyEvent.KEYCODE_PROG_BLUE = 186;
1423
+ _KeyEvent.KEYCODE_PROG_GREEN = 184;
1424
+ _KeyEvent.KEYCODE_PROG_RED = 183;
1425
+ _KeyEvent.KEYCODE_PROG_YELLOW = 185;
1426
+ _KeyEvent.KEYCODE_Q = 45;
1427
+ _KeyEvent.KEYCODE_R = 46;
1428
+ _KeyEvent.KEYCODE_REFRESH = 285;
1429
+ _KeyEvent.KEYCODE_RIGHT_BRACKET = 72;
1430
+ _KeyEvent.KEYCODE_RO = 217;
1431
+ _KeyEvent.KEYCODE_S = 47;
1432
+ _KeyEvent.KEYCODE_SCROLL_LOCK = 116;
1433
+ _KeyEvent.KEYCODE_SEARCH = 84;
1434
+ _KeyEvent.KEYCODE_SEMICOLON = 74;
1435
+ _KeyEvent.KEYCODE_SETTINGS = 176;
1436
+ _KeyEvent.KEYCODE_SHIFT_LEFT = 59;
1437
+ _KeyEvent.KEYCODE_SHIFT_RIGHT = 60;
1438
+ _KeyEvent.KEYCODE_SLASH = 76;
1439
+ _KeyEvent.KEYCODE_SLEEP = 223;
1440
+ _KeyEvent.KEYCODE_SOFT_LEFT = 1;
1441
+ _KeyEvent.KEYCODE_SOFT_RIGHT = 2;
1442
+ _KeyEvent.KEYCODE_SOFT_SLEEP = 276;
1443
+ _KeyEvent.KEYCODE_SPACE = 62;
1444
+ _KeyEvent.KEYCODE_STAR = 17;
1445
+ _KeyEvent.KEYCODE_STB_INPUT = 180;
1446
+ _KeyEvent.KEYCODE_STB_POWER = 179;
1447
+ _KeyEvent.KEYCODE_STEM_1 = 265;
1448
+ _KeyEvent.KEYCODE_STEM_2 = 266;
1449
+ _KeyEvent.KEYCODE_STEM_3 = 267;
1450
+ _KeyEvent.KEYCODE_STEM_PRIMARY = 264;
1451
+ _KeyEvent.KEYCODE_SWITCH_CHARSET = 95;
1452
+ _KeyEvent.KEYCODE_SYM = 63;
1453
+ _KeyEvent.KEYCODE_SYSRQ = 120;
1454
+ _KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN = 281;
1455
+ _KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT = 282;
1456
+ _KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT = 283;
1457
+ _KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP = 280;
1458
+ _KeyEvent.KEYCODE_T = 48;
1459
+ _KeyEvent.KEYCODE_TAB = 61;
1460
+ _KeyEvent.KEYCODE_THUMBS_DOWN = 287;
1461
+ _KeyEvent.KEYCODE_THUMBS_UP = 286;
1462
+ _KeyEvent.KEYCODE_TV = 170;
1463
+ _KeyEvent.KEYCODE_TV_ANTENNA_CABLE = 242;
1464
+ _KeyEvent.KEYCODE_TV_AUDIO_DESCRIPTION = 252;
1465
+ _KeyEvent.KEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN = 254;
1466
+ _KeyEvent.KEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP = 253;
1467
+ _KeyEvent.KEYCODE_TV_CONTENTS_MENU = 256;
1468
+ _KeyEvent.KEYCODE_TV_DATA_SERVICE = 230;
1469
+ _KeyEvent.KEYCODE_TV_INPUT = 178;
1470
+ _KeyEvent.KEYCODE_TV_INPUT_COMPONENT_1 = 249;
1471
+ _KeyEvent.KEYCODE_TV_INPUT_COMPONENT_2 = 250;
1472
+ _KeyEvent.KEYCODE_TV_INPUT_COMPOSITE_1 = 247;
1473
+ _KeyEvent.KEYCODE_TV_INPUT_COMPOSITE_2 = 248;
1474
+ _KeyEvent.KEYCODE_TV_INPUT_HDMI_1 = 243;
1475
+ _KeyEvent.KEYCODE_TV_INPUT_HDMI_2 = 244;
1476
+ _KeyEvent.KEYCODE_TV_INPUT_HDMI_3 = 245;
1477
+ _KeyEvent.KEYCODE_TV_INPUT_HDMI_4 = 246;
1478
+ _KeyEvent.KEYCODE_TV_INPUT_VGA_1 = 251;
1479
+ _KeyEvent.KEYCODE_TV_MEDIA_CONTEXT_MENU = 257;
1480
+ _KeyEvent.KEYCODE_TV_NETWORK = 241;
1481
+ _KeyEvent.KEYCODE_TV_NUMBER_ENTRY = 234;
1482
+ _KeyEvent.KEYCODE_TV_POWER = 177;
1483
+ _KeyEvent.KEYCODE_TV_RADIO_SERVICE = 232;
1484
+ _KeyEvent.KEYCODE_TV_SATELLITE = 237;
1485
+ _KeyEvent.KEYCODE_TV_SATELLITE_BS = 238;
1486
+ _KeyEvent.KEYCODE_TV_SATELLITE_CS = 239;
1487
+ _KeyEvent.KEYCODE_TV_SATELLITE_SERVICE = 240;
1488
+ _KeyEvent.KEYCODE_TV_TELETEXT = 233;
1489
+ _KeyEvent.KEYCODE_TV_TERRESTRIAL_ANALOG = 235;
1490
+ _KeyEvent.KEYCODE_TV_TERRESTRIAL_DIGITAL = 236;
1491
+ _KeyEvent.KEYCODE_TV_TIMER_PROGRAMMING = 258;
1492
+ _KeyEvent.KEYCODE_TV_ZOOM_MODE = 255;
1493
+ _KeyEvent.KEYCODE_U = 49;
1494
+ _KeyEvent.KEYCODE_UNKNOWN = 0;
1495
+ _KeyEvent.KEYCODE_V = 50;
1496
+ _KeyEvent.KEYCODE_VOICE_ASSIST = 231;
1497
+ _KeyEvent.KEYCODE_VOLUME_DOWN = 25;
1498
+ _KeyEvent.KEYCODE_VOLUME_MUTE = 164;
1499
+ _KeyEvent.KEYCODE_VOLUME_UP = 24;
1500
+ _KeyEvent.KEYCODE_W = 51;
1501
+ _KeyEvent.KEYCODE_WAKEUP = 224;
1502
+ _KeyEvent.KEYCODE_WINDOW = 171;
1503
+ _KeyEvent.KEYCODE_X = 52;
1504
+ _KeyEvent.KEYCODE_Y = 53;
1505
+ _KeyEvent.KEYCODE_YEN = 216;
1506
+ _KeyEvent.KEYCODE_Z = 54;
1507
+ _KeyEvent.KEYCODE_ZENKAKU_HANKAKU = 211;
1508
+ _KeyEvent.KEYCODE_ZOOM_IN = 168;
1509
+ _KeyEvent.KEYCODE_ZOOM_OUT = 169;
1510
+ _KeyEvent.META_ALT_LEFT_ON = 16;
1511
+ _KeyEvent.META_ALT_MASK = 50;
1512
+ _KeyEvent.META_ALT_ON = 2;
1513
+ _KeyEvent.META_ALT_RIGHT_ON = 32;
1514
+ _KeyEvent.META_CAPS_LOCK_ON = 1048576;
1515
+ _KeyEvent.META_CTRL_LEFT_ON = 8192;
1516
+ _KeyEvent.META_CTRL_MASK = 28672;
1517
+ _KeyEvent.META_CTRL_ON = 4096;
1518
+ _KeyEvent.META_CTRL_RIGHT_ON = 16384;
1519
+ _KeyEvent.META_FUNCTION_ON = 8;
1520
+ _KeyEvent.META_META_LEFT_ON = 131072;
1521
+ _KeyEvent.META_META_MASK = 458752;
1522
+ _KeyEvent.META_META_ON = 65536;
1523
+ _KeyEvent.META_META_RIGHT_ON = 262144;
1524
+ _KeyEvent.META_NUM_LOCK_ON = 2097152;
1525
+ _KeyEvent.META_SCROLL_LOCK_ON = 4194304;
1526
+ _KeyEvent.META_SHIFT_LEFT_ON = 64;
1527
+ _KeyEvent.META_SHIFT_MASK = 193;
1528
+ _KeyEvent.META_SHIFT_ON = 1;
1529
+ _KeyEvent.META_SHIFT_RIGHT_ON = 128;
1530
+ _KeyEvent.META_SYM_ON = 4;
1531
+ let KeyEvent = _KeyEvent;
1532
+ const _UIEventsCode = class _UIEventsCode {
1533
+ };
1534
+ _UIEventsCode.Backquote = "Backquote";
1535
+ _UIEventsCode.Backslash = "Backslash";
1536
+ _UIEventsCode.BracketLeft = "BracketLeft";
1537
+ _UIEventsCode.BracketRight = "BracketRight";
1538
+ _UIEventsCode.Comma = "Comma";
1539
+ _UIEventsCode.Digit0 = "Digit0";
1540
+ _UIEventsCode.Digit1 = "Digit1";
1541
+ _UIEventsCode.Digit2 = "Digit2";
1542
+ _UIEventsCode.Digit3 = "Digit3";
1543
+ _UIEventsCode.Digit4 = "Digit4";
1544
+ _UIEventsCode.Digit5 = "Digit5";
1545
+ _UIEventsCode.Digit6 = "Digit6";
1546
+ _UIEventsCode.Digit7 = "Digit7";
1547
+ _UIEventsCode.Digit8 = "Digit8";
1548
+ _UIEventsCode.Digit9 = "Digit9";
1549
+ _UIEventsCode.Equal = "Equal";
1550
+ _UIEventsCode.IntlBackslash = "IntlBackslash";
1551
+ _UIEventsCode.IntlRo = "IntlRo";
1552
+ _UIEventsCode.IntlYen = "IntlYen";
1553
+ _UIEventsCode.KeyA = "KeyA";
1554
+ _UIEventsCode.KeyB = "KeyB";
1555
+ _UIEventsCode.KeyC = "KeyC";
1556
+ _UIEventsCode.KeyD = "KeyD";
1557
+ _UIEventsCode.KeyE = "KeyE";
1558
+ _UIEventsCode.KeyF = "KeyF";
1559
+ _UIEventsCode.KeyG = "KeyG";
1560
+ _UIEventsCode.KeyH = "KeyH";
1561
+ _UIEventsCode.KeyI = "KeyI";
1562
+ _UIEventsCode.KeyJ = "KeyJ";
1563
+ _UIEventsCode.KeyK = "KeyK";
1564
+ _UIEventsCode.KeyL = "KeyL";
1565
+ _UIEventsCode.KeyM = "KeyM";
1566
+ _UIEventsCode.KeyN = "KeyN";
1567
+ _UIEventsCode.KeyO = "KeyO";
1568
+ _UIEventsCode.KeyP = "KeyP";
1569
+ _UIEventsCode.KeyQ = "KeyQ";
1570
+ _UIEventsCode.KeyR = "KeyR";
1571
+ _UIEventsCode.KeyS = "KeyS";
1572
+ _UIEventsCode.KeyT = "KeyT";
1573
+ _UIEventsCode.KeyU = "KeyU";
1574
+ _UIEventsCode.KeyV = "KeyV";
1575
+ _UIEventsCode.KeyW = "KeyW";
1576
+ _UIEventsCode.KeyX = "KeyX";
1577
+ _UIEventsCode.KeyY = "KeyY";
1578
+ _UIEventsCode.KeyZ = "KeyZ";
1579
+ _UIEventsCode.Minus = "Minus";
1580
+ _UIEventsCode.Period = "Period";
1581
+ _UIEventsCode.Quote = "Quote";
1582
+ _UIEventsCode.Semicolon = "Semicolon";
1583
+ _UIEventsCode.Slash = "Slash";
1584
+ _UIEventsCode.AltLeft = "AltLeft";
1585
+ _UIEventsCode.AltRight = "AltRight";
1586
+ _UIEventsCode.Backspace = "Backspace";
1587
+ _UIEventsCode.CapsLock = "CapsLock";
1588
+ _UIEventsCode.ContextMenu = "ContextMenu";
1589
+ _UIEventsCode.ControlLeft = "ControlLeft";
1590
+ _UIEventsCode.ControlRight = "ControlRight";
1591
+ _UIEventsCode.Enter = "Enter";
1592
+ _UIEventsCode.MetaLeft = "MetaLeft";
1593
+ _UIEventsCode.MetaRight = "MetaRight";
1594
+ _UIEventsCode.ShiftLeft = "ShiftLeft";
1595
+ _UIEventsCode.ShiftRight = "ShiftRight";
1596
+ _UIEventsCode.Space = "Space";
1597
+ _UIEventsCode.Tab = "Tab";
1598
+ _UIEventsCode.Convert = "Convert";
1599
+ _UIEventsCode.KanaMode = "KanaMode";
1600
+ _UIEventsCode.Lang1 = "Lang1";
1601
+ _UIEventsCode.Lang2 = "Lang2";
1602
+ _UIEventsCode.Lang3 = "Lang3";
1603
+ _UIEventsCode.Lang4 = "Lang4";
1604
+ _UIEventsCode.Lang5 = "Lang5";
1605
+ _UIEventsCode.NonConvert = "NonConvert";
1606
+ _UIEventsCode.Delete = "Delete";
1607
+ _UIEventsCode.End = "End";
1608
+ _UIEventsCode.Help = "Help";
1609
+ _UIEventsCode.Home = "Home";
1610
+ _UIEventsCode.Insert = "Insert";
1611
+ _UIEventsCode.PageDown = "PageDown";
1612
+ _UIEventsCode.PageUp = "PageUp";
1613
+ _UIEventsCode.ArrowDown = "ArrowDown";
1614
+ _UIEventsCode.ArrowLeft = "ArrowLeft";
1615
+ _UIEventsCode.ArrowRight = "ArrowRight";
1616
+ _UIEventsCode.ArrowUp = "ArrowUp";
1617
+ _UIEventsCode.NumLock = "NumLock";
1618
+ _UIEventsCode.Numpad0 = "Numpad0";
1619
+ _UIEventsCode.Numpad1 = "Numpad1";
1620
+ _UIEventsCode.Numpad2 = "Numpad2";
1621
+ _UIEventsCode.Numpad3 = "Numpad3";
1622
+ _UIEventsCode.Numpad4 = "Numpad4";
1623
+ _UIEventsCode.Numpad5 = "Numpad5";
1624
+ _UIEventsCode.Numpad6 = "Numpad6";
1625
+ _UIEventsCode.Numpad7 = "Numpad7";
1626
+ _UIEventsCode.Numpad8 = "Numpad8";
1627
+ _UIEventsCode.Numpad9 = "Numpad9";
1628
+ _UIEventsCode.NumpadAdd = "NumpadAdd";
1629
+ _UIEventsCode.NumpadBackspace = "NumpadBackspace";
1630
+ _UIEventsCode.NumpadClear = "NumpadClear";
1631
+ _UIEventsCode.NumpadClearEntry = "NumpadClearEntry";
1632
+ _UIEventsCode.NumpadComma = "NumpadComma";
1633
+ _UIEventsCode.NumpadDecimal = "NumpadDecimal";
1634
+ _UIEventsCode.NumpadDivide = "NumpadDivide";
1635
+ _UIEventsCode.NumpadEnter = "NumpadEnter";
1636
+ _UIEventsCode.NumpadEqual = "NumpadEqual";
1637
+ _UIEventsCode.NumpadHash = "NumpadHash";
1638
+ _UIEventsCode.NumpadMemoryAdd = "NumpadMemoryAdd";
1639
+ _UIEventsCode.NumpadMemoryClear = "NumpadMemoryClear";
1640
+ _UIEventsCode.NumpadMemoryRecall = "NumpadMemoryRecall";
1641
+ _UIEventsCode.NumpadMemoryStore = "NumpadMemoryStore";
1642
+ _UIEventsCode.NumpadMemorySubtract = "NumpadMemorySubtract";
1643
+ _UIEventsCode.NumpadMultiply = "NumpadMultiply";
1644
+ _UIEventsCode.NumpadParenLeft = "NumpadParenLeft";
1645
+ _UIEventsCode.NumpadParenRight = "NumpadParenRight";
1646
+ _UIEventsCode.NumpadStar = "NumpadStar";
1647
+ _UIEventsCode.NumpadSubtract = "NumpadSubtract";
1648
+ _UIEventsCode.Escape = "Escape";
1649
+ _UIEventsCode.F1 = "F1";
1650
+ _UIEventsCode.F2 = "F2";
1651
+ _UIEventsCode.F3 = "F3";
1652
+ _UIEventsCode.F4 = "F4";
1653
+ _UIEventsCode.F5 = "F5";
1654
+ _UIEventsCode.F6 = "F6";
1655
+ _UIEventsCode.F7 = "F7";
1656
+ _UIEventsCode.F8 = "F8";
1657
+ _UIEventsCode.F9 = "F9";
1658
+ _UIEventsCode.F10 = "F10";
1659
+ _UIEventsCode.F11 = "F11";
1660
+ _UIEventsCode.F12 = "F12";
1661
+ _UIEventsCode.Fn = "Fn";
1662
+ _UIEventsCode.FnLock = "FnLock";
1663
+ _UIEventsCode.PrintScreen = "PrintScreen";
1664
+ _UIEventsCode.ScrollLock = "ScrollLock";
1665
+ _UIEventsCode.Pause = "Pause";
1666
+ _UIEventsCode.BrowserBack = "BrowserBack";
1667
+ _UIEventsCode.BrowserFavorites = "BrowserFavorites";
1668
+ _UIEventsCode.BrowserForward = "BrowserForward";
1669
+ _UIEventsCode.BrowserHome = "BrowserHome";
1670
+ _UIEventsCode.BrowserRefresh = "BrowserRefresh";
1671
+ _UIEventsCode.BrowserSearch = "BrowserSearch";
1672
+ _UIEventsCode.BrowserStop = "BrowserStop";
1673
+ _UIEventsCode.Eject = "Eject";
1674
+ _UIEventsCode.LaunchApp1 = "LaunchApp1";
1675
+ _UIEventsCode.LaunchApp2 = "LaunchApp2";
1676
+ _UIEventsCode.LaunchMail = "LaunchMail";
1677
+ _UIEventsCode.MediaPlayPause = "MediaPlayPause";
1678
+ _UIEventsCode.MediaSelect = "MediaSelect";
1679
+ _UIEventsCode.MediaStop = "MediaStop";
1680
+ _UIEventsCode.MediaTrackNext = "MediaTrackNext";
1681
+ _UIEventsCode.MediaTrackPrevious = "MediaTrackPrevious";
1682
+ _UIEventsCode.Power = "Power";
1683
+ _UIEventsCode.Sleep = "Sleep";
1684
+ _UIEventsCode.AudioVolumeDown = "AudioVolumeDown";
1685
+ _UIEventsCode.AudioVolumeMute = "AudioVolumeMute";
1686
+ _UIEventsCode.AudioVolumeUp = "AudioVolumeUp";
1687
+ _UIEventsCode.WakeUp = "WakeUp";
1688
+ _UIEventsCode.Hyper = "Hyper";
1689
+ _UIEventsCode.Super = "Super";
1690
+ _UIEventsCode.Turbo = "Turbo";
1691
+ _UIEventsCode.Abort = "Abort";
1692
+ _UIEventsCode.Resume = "Resume";
1693
+ _UIEventsCode.Suspend = "Suspend";
1694
+ _UIEventsCode.Again = "Again";
1695
+ _UIEventsCode.Copy = "Copy";
1696
+ _UIEventsCode.Cut = "Cut";
1697
+ _UIEventsCode.Find = "Find";
1698
+ _UIEventsCode.Open = "Open";
1699
+ _UIEventsCode.Paste = "Paste";
1700
+ _UIEventsCode.Props = "Props";
1701
+ _UIEventsCode.Select = "Select";
1702
+ _UIEventsCode.Undo = "Undo";
1703
+ _UIEventsCode.Hiragana = "Hiragana";
1704
+ _UIEventsCode.Katakana = "Katakana";
1705
+ _UIEventsCode.Unidentified = "Unidentified";
1706
+ let UIEventsCode = _UIEventsCode;
1707
+ const KeyToCodeMap = /* @__PURE__ */ new Map([
1708
+ [UIEventsCode.Backquote, KeyEvent.KEYCODE_GRAVE],
1709
+ [UIEventsCode.Backslash, KeyEvent.KEYCODE_BACKSLASH],
1710
+ [UIEventsCode.BracketLeft, KeyEvent.KEYCODE_LEFT_BRACKET],
1711
+ [UIEventsCode.BracketRight, KeyEvent.KEYCODE_RIGHT_BRACKET],
1712
+ [UIEventsCode.Comma, KeyEvent.KEYCODE_COMMA],
1713
+ [UIEventsCode.Digit0, KeyEvent.KEYCODE_0],
1714
+ [UIEventsCode.Digit1, KeyEvent.KEYCODE_1],
1715
+ [UIEventsCode.Digit2, KeyEvent.KEYCODE_2],
1716
+ [UIEventsCode.Digit3, KeyEvent.KEYCODE_3],
1717
+ [UIEventsCode.Digit4, KeyEvent.KEYCODE_4],
1718
+ [UIEventsCode.Digit5, KeyEvent.KEYCODE_5],
1719
+ [UIEventsCode.Digit6, KeyEvent.KEYCODE_6],
1720
+ [UIEventsCode.Digit7, KeyEvent.KEYCODE_7],
1721
+ [UIEventsCode.Digit8, KeyEvent.KEYCODE_8],
1722
+ [UIEventsCode.Digit9, KeyEvent.KEYCODE_9],
1723
+ [UIEventsCode.Equal, KeyEvent.KEYCODE_EQUALS],
1724
+ [UIEventsCode.IntlRo, KeyEvent.KEYCODE_RO],
1725
+ [UIEventsCode.IntlYen, KeyEvent.KEYCODE_YEN],
1726
+ [UIEventsCode.KeyA, KeyEvent.KEYCODE_A],
1727
+ [UIEventsCode.KeyB, KeyEvent.KEYCODE_B],
1728
+ [UIEventsCode.KeyC, KeyEvent.KEYCODE_C],
1729
+ [UIEventsCode.KeyD, KeyEvent.KEYCODE_D],
1730
+ [UIEventsCode.KeyE, KeyEvent.KEYCODE_E],
1731
+ [UIEventsCode.KeyF, KeyEvent.KEYCODE_F],
1732
+ [UIEventsCode.KeyG, KeyEvent.KEYCODE_G],
1733
+ [UIEventsCode.KeyH, KeyEvent.KEYCODE_H],
1734
+ [UIEventsCode.KeyI, KeyEvent.KEYCODE_I],
1735
+ [UIEventsCode.KeyJ, KeyEvent.KEYCODE_J],
1736
+ [UIEventsCode.KeyK, KeyEvent.KEYCODE_K],
1737
+ [UIEventsCode.KeyL, KeyEvent.KEYCODE_L],
1738
+ [UIEventsCode.KeyM, KeyEvent.KEYCODE_M],
1739
+ [UIEventsCode.KeyN, KeyEvent.KEYCODE_N],
1740
+ [UIEventsCode.KeyO, KeyEvent.KEYCODE_O],
1741
+ [UIEventsCode.KeyP, KeyEvent.KEYCODE_P],
1742
+ [UIEventsCode.KeyQ, KeyEvent.KEYCODE_Q],
1743
+ [UIEventsCode.KeyR, KeyEvent.KEYCODE_R],
1744
+ [UIEventsCode.KeyS, KeyEvent.KEYCODE_S],
1745
+ [UIEventsCode.KeyT, KeyEvent.KEYCODE_T],
1746
+ [UIEventsCode.KeyU, KeyEvent.KEYCODE_U],
1747
+ [UIEventsCode.KeyV, KeyEvent.KEYCODE_V],
1748
+ [UIEventsCode.KeyW, KeyEvent.KEYCODE_W],
1749
+ [UIEventsCode.KeyX, KeyEvent.KEYCODE_X],
1750
+ [UIEventsCode.KeyY, KeyEvent.KEYCODE_Y],
1751
+ [UIEventsCode.KeyZ, KeyEvent.KEYCODE_Z],
1752
+ [UIEventsCode.Minus, KeyEvent.KEYCODE_MINUS],
1753
+ [UIEventsCode.Period, KeyEvent.KEYCODE_PERIOD],
1754
+ [UIEventsCode.Quote, KeyEvent.KEYCODE_APOSTROPHE],
1755
+ [UIEventsCode.Semicolon, KeyEvent.KEYCODE_SEMICOLON],
1756
+ [UIEventsCode.Slash, KeyEvent.KEYCODE_SLASH],
1757
+ [UIEventsCode.KanaMode, KeyEvent.KEYCODE_KANA],
1758
+ [UIEventsCode.Delete, KeyEvent.KEYCODE_FORWARD_DEL],
1759
+ [UIEventsCode.End, KeyEvent.KEYCODE_MOVE_END],
1760
+ [UIEventsCode.Help, KeyEvent.KEYCODE_HELP],
1761
+ [UIEventsCode.Home, KeyEvent.KEYCODE_MOVE_HOME],
1762
+ [UIEventsCode.Insert, KeyEvent.KEYCODE_INSERT],
1763
+ [UIEventsCode.PageDown, KeyEvent.KEYCODE_PAGE_DOWN],
1764
+ [UIEventsCode.PageUp, KeyEvent.KEYCODE_PAGE_UP],
1765
+ [UIEventsCode.AltLeft, KeyEvent.KEYCODE_ALT_LEFT],
1766
+ [UIEventsCode.AltRight, KeyEvent.KEYCODE_ALT_RIGHT],
1767
+ [UIEventsCode.Backspace, KeyEvent.KEYCODE_DEL],
1768
+ [UIEventsCode.CapsLock, KeyEvent.KEYCODE_CAPS_LOCK],
1769
+ [UIEventsCode.ControlLeft, KeyEvent.KEYCODE_CTRL_LEFT],
1770
+ [UIEventsCode.ControlRight, KeyEvent.KEYCODE_CTRL_RIGHT],
1771
+ [UIEventsCode.Enter, KeyEvent.KEYCODE_ENTER],
1772
+ [UIEventsCode.MetaLeft, KeyEvent.KEYCODE_META_LEFT],
1773
+ [UIEventsCode.MetaRight, KeyEvent.KEYCODE_META_RIGHT],
1774
+ [UIEventsCode.ShiftLeft, KeyEvent.KEYCODE_SHIFT_LEFT],
1775
+ [UIEventsCode.ShiftRight, KeyEvent.KEYCODE_SHIFT_RIGHT],
1776
+ [UIEventsCode.Space, KeyEvent.KEYCODE_SPACE],
1777
+ [UIEventsCode.Tab, KeyEvent.KEYCODE_TAB],
1778
+ [UIEventsCode.ArrowLeft, KeyEvent.KEYCODE_DPAD_LEFT],
1779
+ [UIEventsCode.ArrowUp, KeyEvent.KEYCODE_DPAD_UP],
1780
+ [UIEventsCode.ArrowRight, KeyEvent.KEYCODE_DPAD_RIGHT],
1781
+ [UIEventsCode.ArrowDown, KeyEvent.KEYCODE_DPAD_DOWN],
1782
+ [UIEventsCode.NumLock, KeyEvent.KEYCODE_NUM_LOCK],
1783
+ [UIEventsCode.Numpad0, KeyEvent.KEYCODE_NUMPAD_0],
1784
+ [UIEventsCode.Numpad1, KeyEvent.KEYCODE_NUMPAD_1],
1785
+ [UIEventsCode.Numpad2, KeyEvent.KEYCODE_NUMPAD_2],
1786
+ [UIEventsCode.Numpad3, KeyEvent.KEYCODE_NUMPAD_3],
1787
+ [UIEventsCode.Numpad4, KeyEvent.KEYCODE_NUMPAD_4],
1788
+ [UIEventsCode.Numpad5, KeyEvent.KEYCODE_NUMPAD_5],
1789
+ [UIEventsCode.Numpad6, KeyEvent.KEYCODE_NUMPAD_7],
1790
+ [UIEventsCode.Numpad8, KeyEvent.KEYCODE_NUMPAD_8],
1791
+ [UIEventsCode.Numpad9, KeyEvent.KEYCODE_NUMPAD_9],
1792
+ [UIEventsCode.NumpadAdd, KeyEvent.KEYCODE_NUMPAD_ADD],
1793
+ [UIEventsCode.NumpadComma, KeyEvent.KEYCODE_NUMPAD_COMMA],
1794
+ [UIEventsCode.NumpadDecimal, KeyEvent.KEYCODE_NUMPAD_DOT],
1795
+ [UIEventsCode.NumpadDivide, KeyEvent.KEYCODE_NUMPAD_DIVIDE],
1796
+ [UIEventsCode.NumpadEnter, KeyEvent.KEYCODE_NUMPAD_ENTER],
1797
+ [UIEventsCode.NumpadEqual, KeyEvent.KEYCODE_NUMPAD_EQUALS],
1798
+ [UIEventsCode.NumpadMultiply, KeyEvent.KEYCODE_NUMPAD_MULTIPLY],
1799
+ [UIEventsCode.NumpadParenLeft, KeyEvent.KEYCODE_NUMPAD_LEFT_PAREN],
1800
+ [UIEventsCode.NumpadParenRight, KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN],
1801
+ [UIEventsCode.NumpadSubtract, KeyEvent.KEYCODE_NUMPAD_SUBTRACT],
1802
+ [UIEventsCode.Escape, KeyEvent.KEYCODE_ESCAPE],
1803
+ [UIEventsCode.F1, KeyEvent.KEYCODE_F1],
1804
+ [UIEventsCode.F2, KeyEvent.KEYCODE_F2],
1805
+ [UIEventsCode.F3, KeyEvent.KEYCODE_F3],
1806
+ [UIEventsCode.F4, KeyEvent.KEYCODE_F4],
1807
+ [UIEventsCode.F5, KeyEvent.KEYCODE_F5],
1808
+ [UIEventsCode.F6, KeyEvent.KEYCODE_F6],
1809
+ [UIEventsCode.F7, KeyEvent.KEYCODE_F7],
1810
+ [UIEventsCode.F8, KeyEvent.KEYCODE_F8],
1811
+ [UIEventsCode.F9, KeyEvent.KEYCODE_F9],
1812
+ [UIEventsCode.F10, KeyEvent.KEYCODE_F10],
1813
+ [UIEventsCode.F11, KeyEvent.KEYCODE_F11],
1814
+ [UIEventsCode.F12, KeyEvent.KEYCODE_F12],
1815
+ [UIEventsCode.Fn, KeyEvent.KEYCODE_FUNCTION],
1816
+ [UIEventsCode.PrintScreen, KeyEvent.KEYCODE_SYSRQ],
1817
+ [UIEventsCode.Pause, KeyEvent.KEYCODE_BREAK]
1818
+ ]);
1819
+ const _KeyInputHandler = class _KeyInputHandler {
1820
+ static attachListeners() {
1821
+ document.body.addEventListener("keydown", this.handler);
1822
+ document.body.addEventListener("keyup", this.handler);
1823
+ }
1824
+ static detachListeners() {
1825
+ document.body.removeEventListener("keydown", this.handler);
1826
+ document.body.removeEventListener("keyup", this.handler);
1827
+ }
1828
+ static addEventListener(listener) {
1829
+ if (!this.listeners.size) {
1830
+ this.attachListeners();
1831
+ }
1832
+ this.listeners.add(listener);
1833
+ }
1834
+ static removeEventListener(listener) {
1835
+ this.listeners.delete(listener);
1836
+ if (!this.listeners.size) {
1837
+ this.detachListeners();
1838
+ }
1839
+ }
1840
+ };
1841
+ _KeyInputHandler.repeatCounter = /* @__PURE__ */ new Map();
1842
+ _KeyInputHandler.listeners = /* @__PURE__ */ new Set();
1843
+ _KeyInputHandler.handler = (event) => {
1844
+ const keyboardEvent = event;
1845
+ const keyCode = KeyToCodeMap.get(keyboardEvent.code);
1846
+ if (!keyCode) {
1847
+ return;
1848
+ }
1849
+ let action;
1850
+ let repeatCount = 0;
1851
+ if (keyboardEvent.type === "keydown") {
1852
+ action = KeyEvent.ACTION_DOWN;
1853
+ if (keyboardEvent.repeat) {
1854
+ let count = _KeyInputHandler.repeatCounter.get(keyCode);
1855
+ if (typeof count !== "number") {
1856
+ count = 1;
1857
+ } else {
1858
+ count++;
1859
+ }
1860
+ repeatCount = count;
1861
+ _KeyInputHandler.repeatCounter.set(keyCode, count);
1862
+ }
1863
+ } else if (keyboardEvent.type === "keyup") {
1864
+ action = KeyEvent.ACTION_UP;
1865
+ _KeyInputHandler.repeatCounter.delete(keyCode);
1866
+ } else {
1867
+ return;
1868
+ }
1869
+ const metaState = (keyboardEvent.getModifierState("Alt") ? KeyEvent.META_ALT_ON : 0) | (keyboardEvent.getModifierState("Shift") ? KeyEvent.META_SHIFT_ON : 0) | (keyboardEvent.getModifierState("Control") ? KeyEvent.META_CTRL_ON : 0) | (keyboardEvent.getModifierState("Meta") ? KeyEvent.META_META_ON : 0) | (keyboardEvent.getModifierState("CapsLock") ? KeyEvent.META_CAPS_LOCK_ON : 0) | (keyboardEvent.getModifierState("ScrollLock") ? KeyEvent.META_SCROLL_LOCK_ON : 0) | (keyboardEvent.getModifierState("NumLock") ? KeyEvent.META_NUM_LOCK_ON : 0);
1870
+ const controlMessage = new KeyCodeControlMessage(
1871
+ action,
1872
+ keyCode,
1873
+ repeatCount,
1874
+ metaState
1875
+ );
1876
+ _KeyInputHandler.listeners.forEach((listener) => {
1877
+ listener.onKeyEvent(controlMessage);
1878
+ });
1879
+ event.preventDefault();
1880
+ };
1881
+ let KeyInputHandler = _KeyInputHandler;
1882
+ class Rect {
1883
+ constructor(left, top, right, bottom) {
1884
+ this.left = left;
1885
+ this.top = top;
1886
+ this.right = right;
1887
+ this.bottom = bottom;
1888
+ this.left = left;
1889
+ this.top = top;
1890
+ this.right = right;
1891
+ this.bottom = bottom;
1892
+ }
1893
+ static equals(a, b) {
1894
+ if (!a && !b) {
1895
+ return true;
1896
+ }
1897
+ return !!a && !!b && a.equals(b);
1898
+ }
1899
+ static copy(a) {
1900
+ if (!a) {
1901
+ return null;
1902
+ }
1903
+ return new Rect(a.left, a.top, a.right, a.bottom);
1904
+ }
1905
+ equals(o) {
1906
+ if (this === o) {
1907
+ return true;
1908
+ }
1909
+ if (!o) {
1910
+ return false;
1911
+ }
1912
+ return this.left === o.left && this.top === o.top && this.right === o.right && this.bottom === o.bottom;
1913
+ }
1914
+ getWidth() {
1915
+ return this.right - this.left;
1916
+ }
1917
+ getHeight() {
1918
+ return this.bottom - this.top;
1919
+ }
1920
+ toString() {
1921
+ return `Rect{left=${this.left}, top=${this.top}, right=${this.right}, bottom=${this.bottom}}`;
1922
+ }
1923
+ toJSON() {
1924
+ return {
1925
+ left: this.left,
1926
+ right: this.right,
1927
+ top: this.top,
1928
+ bottom: this.bottom
1929
+ };
1930
+ }
1931
+ }
1932
+ const _ScreenInfo = class _ScreenInfo {
1933
+ constructor(contentRect, videoSize, deviceRotation) {
1934
+ this.contentRect = contentRect;
1935
+ this.videoSize = videoSize;
1936
+ this.deviceRotation = deviceRotation;
1937
+ }
1938
+ static fromBuffer(buffer) {
1939
+ const left = buffer.readInt32BE(0);
1940
+ const top = buffer.readInt32BE(4);
1941
+ const right = buffer.readInt32BE(8);
1942
+ const bottom = buffer.readInt32BE(12);
1943
+ const width = buffer.readInt32BE(16);
1944
+ const height = buffer.readInt32BE(20);
1945
+ const deviceRotation = buffer.readUInt8(24);
1946
+ return new _ScreenInfo(new Rect(left, top, right, bottom), new Size(width, height), deviceRotation);
1947
+ }
1948
+ equals(o) {
1949
+ if (!o) {
1950
+ return false;
1951
+ }
1952
+ return this.contentRect.equals(o.contentRect) && this.videoSize.equals(o.videoSize) && this.deviceRotation === o.deviceRotation;
1953
+ }
1954
+ toString() {
1955
+ return `ScreenInfo{contentRect=${this.contentRect}, videoSize=${this.videoSize}, deviceRotation=${this.deviceRotation}}`;
1956
+ }
1957
+ };
1958
+ _ScreenInfo.BUFFER_LENGTH = 25;
1959
+ let ScreenInfo = _ScreenInfo;
1960
+ export {
1961
+ CommandControlMessage,
1962
+ ControlMessage,
1963
+ FeaturedInteractionHandler,
1964
+ FilePushState,
1965
+ InteractionHandler,
1966
+ KeyCodeControlMessage,
1967
+ KeyEvent,
1968
+ KeyInputHandler,
1969
+ KeyToCodeMap,
1970
+ MotionEvent,
1971
+ Point,
1972
+ Position,
1973
+ Rect,
1974
+ ScreenInfo,
1975
+ ScrollControlMessage,
1976
+ SimpleInteractionHandler,
1977
+ Size,
1978
+ TextControlMessage,
1979
+ TouchControlMessage,
1980
+ UIEventsCode,
1981
+ Util
1982
+ };
1983
+ //# sourceMappingURL=index.es.js.map