@asyra/input-system 0.5.4 → 0.5.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,108 @@
1
+ # @asyra/input-system
2
+
3
+ ## 0.5.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 22883b1: Support owner-coordinated runtime replacement for applications such as Asyra Sim.
8
+ Quiesce feature work before retiring runtime-owned state, subscriptions, input
9
+ bindings, render resources, and registration graphs. Retain preset installation
10
+ cleanup and prevent callbacks from a retired runtime from affecting its successor.
11
+
12
+ Expose Core document-load preflight and validated renderer resizing through the
13
+ public facade. Applications can validate a replacement document before retiring
14
+ the active runtime, while ordinary document loading retains its existing history
15
+ ownership contract.
16
+
17
+ - Updated dependencies [22883b1]
18
+ - @asyra/utils@0.5.2
19
+ - @asyra/reactive-events@0.5.4
20
+
21
+ ## 0.5.4
22
+
23
+ ### Patch Changes
24
+
25
+ - Republish the affected Framework packages with publishable internal dependency
26
+ ranges instead of monorepo-only `workspace:*` metadata.
27
+ - Updated dependencies
28
+ - @asyra/reactive-events@0.5.3
29
+
30
+ ## 0.5.3
31
+
32
+ ### Patch Changes
33
+
34
+ - Exceptional synchronized patch release for the fixed 19-package Framework set.
35
+ - Updated dependencies
36
+ - @asyra/reactive-events@0.5.2
37
+ - @asyra/utils@0.5.1
38
+
39
+ ## 0.5.2
40
+
41
+ ### Patch Changes
42
+
43
+ - c714696: Make InputSystem import and construction DOM-neutral, add explicit browser host
44
+ and pointer-target lifecycle APIs, and provide symmetric listener cleanup.
45
+
46
+ ## 0.5.1
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [889f7b4]
51
+ - @asyra/reactive-events@0.5.1
52
+
53
+ ## 0.5.0
54
+
55
+ ### Minor Changes
56
+
57
+ - Exceptional synchronized minor release for the fixed 19-package Framework set.
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies
62
+ - @asyra/reactive-events@0.5.0
63
+ - @asyra/utils@0.5.0
64
+
65
+ ## 0.2.5
66
+
67
+ ### Patch Changes
68
+
69
+ - Auto-patch all packages.
70
+ - Updated dependencies
71
+ - @asyra/reactive-events@0.2.5
72
+ - @asyra/utils@0.2.5
73
+
74
+ ## 0.2.4
75
+
76
+ ### Patch Changes
77
+
78
+ - Auto-patch all packages.
79
+ - Updated dependencies
80
+ - @asyra/reactive-events@0.2.4
81
+ - @asyra/utils@0.2.4
82
+
83
+ ## 0.2.3
84
+
85
+ ### Patch Changes
86
+
87
+ - Auto-patch all packages.
88
+ - Updated dependencies
89
+ - @asyra/reactive-events@0.2.3
90
+ - @asyra/utils@0.2.3
91
+
92
+ ## 0.2.2
93
+
94
+ ### Patch Changes
95
+
96
+ - Auto-patch all packages.
97
+ - Updated dependencies
98
+ - @asyra/reactive-events@0.2.2
99
+ - @asyra/utils@0.2.2
100
+
101
+ ## 0.2.1
102
+
103
+ ### Patch Changes
104
+
105
+ - Auto-patch all packages.
106
+ - Updated dependencies
107
+ - @asyra/reactive-events@0.2.1
108
+ - @asyra/utils@0.2.1
package/README.md CHANGED
@@ -43,8 +43,12 @@ Attachment adds listeners to the selected host and target. Reattachment is idemp
43
43
 
44
44
  ## Support and policy
45
45
 
46
- This repository does not accept external issues or contributions. You may use,
47
- inspect, and fork the package under the [MIT License](https://github.com/karote00/asyra/blob/main/LICENSE).
48
- Follow the [security policy](https://github.com/karote00/asyra/blob/main/SECURITY.md) for
49
- security-sensitive reports and the [root policy](https://github.com/karote00/asyra) for the
50
- current support boundary.
46
+ GitHub Discussions is the intended public channel for community conversation and
47
+ general help. Discussions is not enabled for this repository yet, so there is
48
+ currently no public community support destination. GitHub Issues are not a
49
+ general public support channel. External pull requests are not accepted by
50
+ default. Community participation creates no SLA or response deadline.
51
+
52
+ You may use, inspect, and fork the package under the [MIT License](https://github.com/karote00/asyra/blob/main/LICENSE).
53
+ Read the <a href="https://github.com/karote00/asyra/blob/main/SUPPORT.md" target="_blank" rel="noopener noreferrer">support policy</a>.
54
+ For suspected vulnerabilities, follow the <a href="https://github.com/karote00/asyra/blob/main/SECURITY.md" target="_blank" rel="noopener noreferrer">security policy</a> and report privately.
@@ -14,6 +14,8 @@ declare class InputSystem {
14
14
  private pointerInputBlocked;
15
15
  private pointerCaptureId;
16
16
  registry: InputSystemRegistry;
17
+ private runtimeGeneration;
18
+ private browserListeners;
17
19
  constructor();
18
20
  attachBrowserHost(host: Window, pointerTarget?: Window | HTMLElement): void;
19
21
  detachBrowserHost(): void;
@@ -21,6 +23,9 @@ declare class InputSystem {
21
23
  private removeKeyboardListeners;
22
24
  private addPointerListeners;
23
25
  private removePointerListeners;
26
+ private keyboardBindings;
27
+ private pointerBindings;
28
+ private browserListener;
24
29
  setCombinations(combinations: Combinations): void;
25
30
  on(action: string, callback: Callback): this;
26
31
  off(action: string, callback: Callback): boolean;
@@ -48,6 +53,7 @@ declare class InputSystem {
48
53
  private clearTransientState;
49
54
  dispose(): void;
50
55
  reset(): void;
56
+ resetRuntime(): void;
51
57
  }
52
58
  export { InputSystem };
53
59
  declare const inputSystem: InputSystem;
@@ -42,6 +42,8 @@ class InputSystem {
42
42
  pointerInputBlocked;
43
43
  pointerCaptureId;
44
44
  registry;
45
+ runtimeGeneration = 0;
46
+ browserListeners = new Map();
45
47
  constructor() {
46
48
  this.browserHost = null;
47
49
  this.pointerTarget = null;
@@ -86,26 +88,56 @@ class InputSystem {
86
88
  }
87
89
  }
88
90
  addKeyboardListeners(host) {
89
- host.addEventListener('keydown', this.handleKeyDown);
90
- host.addEventListener('keyup', this.handleKeyUp);
91
+ this.keyboardBindings().forEach(([name, listener]) => host.addEventListener(name, listener));
91
92
  }
92
- removeKeyboardListeners(host) {
93
- host.removeEventListener('keydown', this.handleKeyDown);
94
- host.removeEventListener('keyup', this.handleKeyUp);
93
+ removeKeyboardListeners(host, attempt = (cleanup) => cleanup()) {
94
+ this.keyboardBindings().forEach(([name, listener]) => attempt(() => host.removeEventListener(name, listener)));
95
95
  }
96
96
  addPointerListeners(target) {
97
- target.addEventListener('mousedown', this.handleMouseDown);
98
- target.addEventListener('mouseup', this.handleMouseUp);
99
- target.addEventListener('mousemove', this.handleMouseMove);
100
- target.addEventListener('dblclick', this.handleDoubleClick);
101
- target.addEventListener('wheel', this.handleWheel, WHEEL_EVENT_OPTIONS);
102
- }
103
- removePointerListeners(target) {
104
- target.removeEventListener('mousedown', this.handleMouseDown);
105
- target.removeEventListener('mouseup', this.handleMouseUp);
106
- target.removeEventListener('mousemove', this.handleMouseMove);
107
- target.removeEventListener('dblclick', this.handleDoubleClick);
108
- target.removeEventListener('wheel', this.handleWheel, WHEEL_EVENT_OPTIONS);
97
+ this.pointerBindings().forEach((binding) => target.addEventListener(...binding));
98
+ }
99
+ removePointerListeners(target, attempt = (cleanup) => cleanup()) {
100
+ this.pointerBindings().forEach((binding) => attempt(() => target.removeEventListener(...binding)));
101
+ }
102
+ keyboardBindings() {
103
+ return [
104
+ ['keydown', this.browserListener(this.handleKeyDown)],
105
+ ['keyup', this.browserListener(this.handleKeyUp)]
106
+ ];
107
+ }
108
+ pointerBindings() {
109
+ return [
110
+ [
111
+ 'mousedown',
112
+ this.browserListener(this.handleMouseDown)
113
+ ],
114
+ ['mouseup', this.browserListener(this.handleMouseUp)],
115
+ [
116
+ 'mousemove',
117
+ this.browserListener(this.handleMouseMove)
118
+ ],
119
+ [
120
+ 'dblclick',
121
+ this.browserListener(this.handleDoubleClick)
122
+ ],
123
+ [
124
+ 'wheel',
125
+ this.browserListener(this.handleWheel),
126
+ WHEEL_EVENT_OPTIONS
127
+ ]
128
+ ];
129
+ }
130
+ browserListener(listener) {
131
+ const existing = this.browserListeners.get(listener);
132
+ if (existing)
133
+ return existing;
134
+ const generation = this.runtimeGeneration;
135
+ const guarded = (event) => {
136
+ if (generation === this.runtimeGeneration)
137
+ listener(event);
138
+ };
139
+ this.browserListeners.set(listener, guarded);
140
+ return guarded;
109
141
  }
110
142
  setCombinations(combinations) {
111
143
  this.combinations = combinations;
@@ -146,7 +178,10 @@ class InputSystem {
146
178
  clearTimeout(currentTimer);
147
179
  }
148
180
  }
181
+ const generation = this.runtimeGeneration;
149
182
  const timer = setTimeout(() => {
183
+ if (generation !== this.runtimeGeneration)
184
+ return;
150
185
  this.activeKeys.delete(key);
151
186
  this.timers.delete(key);
152
187
  }, CLEAR_KEY_TIME);
@@ -436,6 +471,29 @@ class InputSystem {
436
471
  reset() {
437
472
  this.clearTransientState();
438
473
  }
474
+ resetRuntime() {
475
+ this.runtimeGeneration += 1;
476
+ const failures = [];
477
+ const attempt = (cleanup) => {
478
+ try {
479
+ cleanup();
480
+ }
481
+ catch (error) {
482
+ failures.push(error);
483
+ }
484
+ };
485
+ if (this.pointerTarget)
486
+ this.removePointerListeners(this.pointerTarget, attempt);
487
+ if (this.browserHost)
488
+ this.removeKeyboardListeners(this.browserHost, attempt);
489
+ this.pointerTarget = null;
490
+ this.browserHost = null;
491
+ this.browserListeners.clear();
492
+ this.clearTransientState();
493
+ this.registry.clear();
494
+ if (failures.length > 0)
495
+ throw failures[0];
496
+ }
439
497
  }
440
498
  export { InputSystem };
441
499
  const inputSystem = new InputSystem();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyra/input-system",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Keyboard and Mouse event listener plugin",
5
5
  "author": "Asa Tsai",
6
6
  "license": "MIT",
@@ -46,7 +46,7 @@
46
46
  "vitest": "^3.2.6"
47
47
  },
48
48
  "dependencies": {
49
- "@asyra/reactive-events": "0.5.3",
50
- "@asyra/utils": "0.5.1"
49
+ "@asyra/reactive-events": "0.5.4",
50
+ "@asyra/utils": "0.5.2"
51
51
  }
52
- }
52
+ }