interaction-system 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,75 +23,6 @@
23
23
  npm install interaction-system
24
24
  ```
25
25
 
26
- ### 本地使用
27
-
28
- 如果你想在本地项目中使用此包,有以下几种方式:
29
-
30
- #### 方法 1: npm link(推荐用于开发)
31
-
32
- 这种方式创建全局符号链接,适合频繁修改和测试:
33
-
34
- ```bash
35
- # 在 interaction-system 目录中
36
- cd interaction-system
37
- npm link
38
-
39
- # 在你的项目中
40
- cd your-project
41
- npm link interaction-system
42
- ```
43
-
44
- 之后可以像正常的 npm 包一样导入使用:
45
-
46
- ```typescript
47
- import { FeaturedInteractionHandler } from 'interaction-system';
48
- ```
49
-
50
- **取消链接:**
51
- ```bash
52
- # 在你的项目中
53
- npm unlink interaction-system
54
-
55
- # 在 interaction-system 目录中(可选)
56
- npm unlink
57
- ```
58
-
59
- #### 方法 2: 相对路径安装
60
-
61
- 直接从本地文件系统安装:
62
-
63
- ```bash
64
- cd your-project
65
- npm install ../path/to/ws-scrcpy/interaction-system
66
- ```
67
-
68
- #### 方法 3: file: 协议
69
-
70
- 在项目的 `package.json` 中添加依赖:
71
-
72
- ```json
73
- {
74
- "dependencies": {
75
- "interaction-system": "file:../ws-scrcpy/interaction-system"
76
- }
77
- }
78
- ```
79
-
80
- 然后运行 `npm install`。
81
-
82
- #### 方法 4: 直接引用源码
83
-
84
- 如果在同一个 monorepo 中,可以直接引用 TypeScript 源码:
85
-
86
- ```typescript
87
- import { FeaturedInteractionHandler } from '../../interaction-system/src';
88
- ```
89
-
90
- **注意事项:**
91
- - 使用 `npm link` 时,包的更新会立即反映到所有链接的项目中
92
- - 使用 `file:` 协议时,需要重新运行 `npm install` 才能获取更新
93
- - 直接引用源码需要项目的构建工具能够处理 TypeScript
94
-
95
26
  ## 基本使用
96
27
 
97
28
  ### 1. 实现 IPlayer 接口
@@ -311,67 +242,3 @@ interface IPlayer {
311
242
  - `ScreenInfo` - 屏幕信息
312
243
  - `MotionEvent` - 运动事件常量
313
244
 
314
- ## 高级用法
315
-
316
- ### 多点触控
317
-
318
- 使用 `FeaturedInteractionHandler` 时,按住 `Ctrl` 键可以激活多点触控模式:
319
-
320
- - `Ctrl + 鼠标移动` - 创建对称的两个触摸点
321
- - `Ctrl + Shift + 鼠标` - 以第一个点为中心创建镜像触摸点
322
-
323
- ### 自定义命令
324
-
325
- ```typescript
326
- import { CommandControlMessage, ControlMessage } from 'interaction-system';
327
-
328
- // 设置剪贴板
329
- const clipboardCmd = CommandControlMessage.createSetClipboardCommand('文本内容', false);
330
-
331
- // 设置屏幕电源模式
332
- const powerCmd = CommandControlMessage.createSetScreenPowerModeCommand(true);
333
-
334
- // 创建简单命令
335
- const expandNotifications = new CommandControlMessage(ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL);
336
- ```
337
-
338
- ## 架构说明
339
-
340
- ```
341
- interaction-system/
342
- ├── src/
343
- │ ├── interaction/ # 交互处理器
344
- │ ├── messages/ # 控制消息
345
- │ ├── input/ # 键盘输入处理
346
- │ ├── models/ # 数据模型
347
- │ ├── utils/ # 工具函数
348
- │ ├── types/ # TypeScript 接口
349
- │ └── assets/ # 静态资源(图片等)
350
- ```
351
-
352
- ## 注意事项
353
-
354
- 1. **ScreenInfo 是必需的**:大多数交互功能都需要正确的 `ScreenInfo`,确保在使用前设置。
355
-
356
- 2. **内存管理**:使用完交互处理器后调用 `release()` 方法释放资源。
357
-
358
- 3. **Buffer 依赖**:控制消息序列化依赖 Node.js 的 `Buffer` API(通过 buffer 包提供浏览器支持)。
359
-
360
- 4. **图片资源**:多点触控可视化需要加载图片资源,确保构建工具正确处理 PNG 导入。
361
-
362
- ## TypeScript 支持
363
-
364
- 本库完全使用 TypeScript 编写,提供完整的类型定义。无需额外安装 @types 包。
365
-
366
- ## 许可证
367
-
368
- 本项目采用 Apache-2.0 许可证。
369
-
370
- ## 贡献
371
-
372
- 欢迎提交 Issue 和 Pull Request!
373
-
374
- ## 相关项目
375
-
376
- - [ws-scrcpy](https://github.com/NetrisTV/ws-scrcpy) - 原始项目
377
-
@@ -0,0 +1,20 @@
1
+ export type EventMap = Record<string, any>;
2
+ export type EventKey<T extends EventMap> = string & keyof T;
3
+ export type EventReceiver<T> = (params: T) => void;
4
+ interface Emitter<T extends EventMap> {
5
+ on<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
6
+ off<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
7
+ emit<K extends EventKey<T>>(eventName: K, params: T[K]): void;
8
+ }
9
+ export declare class TypedEmitter<T extends EventMap> implements Emitter<T> {
10
+ private emitter;
11
+ addEventListener<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
12
+ removeEventListener<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
13
+ dispatchEvent(event: Event): boolean;
14
+ on<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
15
+ once<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
16
+ off<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): void;
17
+ emit<K extends EventKey<T>>(eventName: K, params: T[K]): boolean;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=TypedEmitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedEmitter.d.ts","sourceRoot":"","sources":["../../src/common/TypedEmitter.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC3C,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,QAAQ,IAAI,MAAM,GAAG,MAAM,CAAC,CAAC;AAC5D,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;AAEnD,UAAU,OAAO,CAAC,CAAC,SAAS,QA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G,IAAI;IAIxE,GAAG,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAIvE,IAAI,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO;CAGnE"}
package/dist/index.cjs.js CHANGED
@@ -56,6 +56,7 @@ const _TouchControlMessage = class _TouchControlMessage extends ControlMessage {
56
56
  toBuffer() {
57
57
  const buffer$1 = buffer.Buffer.alloc(_TouchControlMessage.PAYLOAD_LENGTH + 1);
58
58
  let offset = 0;
59
+ offset = buffer$1.writeUInt8(0, offset);
59
60
  offset = buffer$1.writeUInt8(this.type, offset);
60
61
  offset = buffer$1.writeUInt8(this.action, offset);
61
62
  offset = buffer$1.writeUInt32BE(0, offset);
@@ -65,6 +66,7 @@ const _TouchControlMessage = class _TouchControlMessage extends ControlMessage {
65
66
  offset = buffer$1.writeUInt16BE(this.position.screenSize.width, offset);
66
67
  offset = buffer$1.writeUInt16BE(this.position.screenSize.height, offset);
67
68
  offset = buffer$1.writeUInt16BE(this.pressure * _TouchControlMessage.MAX_PRESSURE_VALUE, offset);
69
+ offset = buffer$1.writeUInt32BE(0, offset);
68
70
  buffer$1.writeUInt32BE(this.buttons, offset);
69
71
  return buffer$1;
70
72
  }
@@ -82,7 +84,7 @@ const _TouchControlMessage = class _TouchControlMessage extends ControlMessage {
82
84
  };
83
85
  }
84
86
  };
85
- _TouchControlMessage.PAYLOAD_LENGTH = 28;
87
+ _TouchControlMessage.PAYLOAD_LENGTH = 28 + 4;
86
88
  _TouchControlMessage.MAX_PRESSURE_VALUE = 65535;
87
89
  let TouchControlMessage = _TouchControlMessage;
88
90
  class Size {
@@ -686,14 +688,6 @@ const _InteractionHandler = class _InteractionHandler {
686
688
  }
687
689
  }
688
690
  });
689
- if (this.multiTouchActive) {
690
- if (this.multiTouchCenter) {
691
- this.drawCenter(this.multiTouchCenter);
692
- }
693
- points.forEach((point) => {
694
- this.drawPointer(point);
695
- });
696
- }
697
691
  const hasActionUp = messages.find((message) => {
698
692
  return message.action === MotionEvent.ACTION_UP;
699
693
  });
@@ -749,6 +743,7 @@ _InteractionHandler.onKeyEvent = (event) => {
749
743
  };
750
744
  let InteractionHandler = _InteractionHandler;
751
745
  const _ScrollControlMessage = class _ScrollControlMessage extends ControlMessage {
746
+ // 1字节代表群控还是单控,后面4字节为底层需要填充
752
747
  constructor(position, hScroll, vScroll) {
753
748
  super(ControlMessage.TYPE_SCROLL);
754
749
  this.position = position;
@@ -761,13 +756,15 @@ const _ScrollControlMessage = class _ScrollControlMessage extends ControlMessage
761
756
  toBuffer() {
762
757
  const buffer$1 = buffer.Buffer.alloc(_ScrollControlMessage.PAYLOAD_LENGTH + 1);
763
758
  let offset = 0;
759
+ offset = buffer$1.writeUInt8(0, offset);
764
760
  offset = buffer$1.writeUInt8(this.type, offset);
765
761
  offset = buffer$1.writeUInt32BE(this.position.point.x, offset);
766
762
  offset = buffer$1.writeUInt32BE(this.position.point.y, offset);
767
763
  offset = buffer$1.writeUInt16BE(this.position.screenSize.width, offset);
768
764
  offset = buffer$1.writeUInt16BE(this.position.screenSize.height, offset);
769
- offset = buffer$1.writeInt32BE(this.hScroll, offset);
770
- buffer$1.writeInt32BE(this.vScroll, offset);
765
+ offset = buffer$1.writeInt16BE(this.hScroll, offset);
766
+ offset = buffer$1.writeInt16BE(this.vScroll, offset);
767
+ buffer$1.writeInt32BE(0, offset);
771
768
  return buffer$1;
772
769
  }
773
770
  toString() {
@@ -782,7 +779,7 @@ const _ScrollControlMessage = class _ScrollControlMessage extends ControlMessage
782
779
  };
783
780
  }
784
781
  };
785
- _ScrollControlMessage.PAYLOAD_LENGTH = 20;
782
+ _ScrollControlMessage.PAYLOAD_LENGTH = 21;
786
783
  let ScrollControlMessage = _ScrollControlMessage;
787
784
  const TAG$1 = "[FeaturedTouchHandler]";
788
785
  const _FeaturedInteractionHandler = class _FeaturedInteractionHandler extends InteractionHandler {
@@ -810,8 +807,8 @@ const _FeaturedInteractionHandler = class _FeaturedInteractionHandler extends In
810
807
  const messages = [];
811
808
  const touchOnClient = InteractionHandler.buildTouchOnClient(event, screenInfo);
812
809
  if (touchOnClient) {
813
- const hScroll = event.deltaX > 0 ? -1 : event.deltaX < -0 ? 1 : 0;
814
- const vScroll = event.deltaY > 0 ? -1 : event.deltaY < -0 ? 1 : 0;
810
+ const hScroll = event.deltaX > 0 ? -1e3 : event.deltaX < -0 ? 1e3 : 0;
811
+ const vScroll = event.deltaY > 0 ? -1e3 : event.deltaY < -0 ? 1e3 : 0;
815
812
  const time = Date.now();
816
813
  if (!this.lastScrollEvent || time - this.lastScrollEvent.time > _FeaturedInteractionHandler.SCROLL_EVENT_THROTTLING_TIME || this.lastScrollEvent.vScroll !== vScroll || this.lastScrollEvent.hScroll !== hScroll) {
817
814
  this.lastScrollEvent = { time, hScroll, vScroll };
@@ -978,6 +975,7 @@ const _KeyCodeControlMessage = class _KeyCodeControlMessage extends ControlMessa
978
975
  toBuffer() {
979
976
  const buffer$1 = buffer.Buffer.alloc(_KeyCodeControlMessage.PAYLOAD_LENGTH + 1);
980
977
  let offset = 0;
978
+ offset = buffer$1.writeInt8(0, offset);
981
979
  offset = buffer$1.writeInt8(this.type, offset);
982
980
  offset = buffer$1.writeInt8(this.action, offset);
983
981
  offset = buffer$1.writeInt32BE(this.keycode, offset);
@@ -998,7 +996,7 @@ const _KeyCodeControlMessage = class _KeyCodeControlMessage extends ControlMessa
998
996
  };
999
997
  }
1000
998
  };
1001
- _KeyCodeControlMessage.PAYLOAD_LENGTH = 13;
999
+ _KeyCodeControlMessage.PAYLOAD_LENGTH = 13 + 1;
1002
1000
  let KeyCodeControlMessage = _KeyCodeControlMessage;
1003
1001
  const _TextControlMessage = class _TextControlMessage extends ControlMessage {
1004
1002
  constructor(text) {
@@ -1843,6 +1841,10 @@ const _KeyInputHandler = class _KeyInputHandler {
1843
1841
  _KeyInputHandler.repeatCounter = /* @__PURE__ */ new Map();
1844
1842
  _KeyInputHandler.listeners = /* @__PURE__ */ new Set();
1845
1843
  _KeyInputHandler.handler = (event) => {
1844
+ const target = event.target;
1845
+ if (target instanceof HTMLElement && (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT" || target.isContentEditable)) {
1846
+ return;
1847
+ }
1846
1848
  const keyboardEvent = event;
1847
1849
  const keyCode = KeyToCodeMap.get(keyboardEvent.code);
1848
1850
  if (!keyCode) {