Skip to content

Commit 1966d53

Browse files
feat: update code
1 parent eaa2cf9 commit 1966d53

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

packages/core/src/input/InputManager.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ export class InputManager {
156156
// @ts-ignore
157157
const canvas = engine._canvas._webCanvas;
158158
if (typeof OffscreenCanvas === "undefined" || !(canvas instanceof OffscreenCanvas)) {
159-
this._wheelManager = new WheelManager(engine, inputOptions?.wheelTarget);
160-
this._pointerManager = new PointerManager(engine, inputOptions?.pointerTarget);
161-
this._keyboardManager = new KeyboardManager(engine, inputOptions?.keyboardTarget);
159+
this._wheelManager = new WheelManager(engine, inputOptions?.wheelTarget ?? canvas);
160+
this._pointerManager = new PointerManager(engine, inputOptions?.pointerTarget ?? canvas);
161+
this._keyboardManager = new KeyboardManager(engine, inputOptions?.keyboardTarget ?? window);
162162
this._initialized = true;
163163
}
164164
}

packages/core/src/input/keyboard/KeyboardManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class KeyboardManager implements IInput {
3232
/**
3333
* @internal
3434
*/
35-
constructor(engine: Engine, target: EventTarget = window) {
35+
constructor(engine: Engine, target: EventTarget) {
3636
this._engine = engine;
3737
this._onBlur = this._onBlur.bind(this);
3838
this._onKeyEvent = this._onKeyEvent.bind(this);

packages/core/src/input/pointer/PointerManager.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ export class PointerManager implements IInput {
4545
/**
4646
* @internal
4747
*/
48-
constructor(engine: Engine, target?: EventTarget) {
48+
constructor(engine: Engine, target: EventTarget) {
49+
if (target instanceof Window) {
50+
throw "Do not set window as target because window cannot listen to pointer leave event.";
51+
}
4952
this._engine = engine;
53+
this._target = target;
5054
this._canvas = engine.canvas;
51-
this._onPointerEvent = this._onPointerEvent.bind(this);
55+
// @ts-ignore
56+
this._htmlCanvas = engine._canvas._webCanvas;
5257
// If there are no compatibility issues, navigator.maxTouchPoints should be used here
5358
this._pointerPool = new Array<Pointer>(11);
54-
// @ts-ignore
55-
const htmlCanvas = (this._htmlCanvas = engine._canvas._webCanvas);
56-
this._target = target ?? htmlCanvas;
59+
this._onPointerEvent = this._onPointerEvent.bind(this);
5760
this._addEventListener();
5861
}
5962

packages/core/src/input/wheel/WheelManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class WheelManager implements IInput {
1717
/**
1818
* @internal
1919
*/
20-
constructor(engine: Engine, target: EventTarget = window) {
20+
constructor(engine: Engine, target: EventTarget) {
2121
this._onWheelEvent = this._onWheelEvent.bind(this);
2222
this._target = target;
2323
this._addEventListener();

packages/design/src/input/IInputOptions.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
export interface IInputOptions {
55
/**
66
* The target element of the pointer event, defaults is the current canvas.
7+
* @remarks
78
* @remarks: When setting the pointer target you need to specify:
8-
* 1. Do not set window as target because window cannot listen to pointer leave event.
9-
* 2. On mobile, pointer move may trigger the default slide event, thereby removing the point from the screen,
10-
* so in most cases you need to set HtmlElement.style.touchAction = "none";
9+
* - Do not set window as target because window cannot listen to pointer leave event.
10+
* - On mobile, pointer move may trigger the default slide event, thereby removing the point from the screen, so in most cases you need to set HtmlElement.style.touchAction = "none".
1111
*/
12-
pointerTarget?: EventTarget;
12+
pointerTarget?: Exclude<EventTarget, Window & typeof globalThis>;
13+
1314
/**
1415
* The target element of the keyboard event, defaults is the window.
15-
* @remarks: When setting the keyboard target you need to specify:
16-
* If the type of listening source is HtmlElement, you need to set tabIndex to make the element focus.
16+
* @remarks
17+
* If the type of listening target is `HtmlElement`, you need to set tabIndex to make the element focus.
1718
*/
1819
keyboardTarget?: EventTarget;
19-
/**
20-
* The target element of the wheel event, defaults is the window.
21-
*/
20+
21+
/** The target element of the wheel event, defaults is the current canvas. */
2222
wheelTarget?: EventTarget;
2323
}

0 commit comments

Comments
 (0)