stage-js 0.9.5 → 1.0.0-alpha.11
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/.eslintrc.json +36 -0
- package/.gitattributes +1 -0
- package/.prettierignore +2 -0
- package/.prettierrc.json +3 -0
- package/CHANGELOG.md +173 -0
- package/LICENSE.md +4 -2
- package/README.md +12 -631
- package/dist/stage.d.ts +558 -0
- package/dist/stage.js +3620 -0
- package/dist/stage.js.map +1 -0
- package/dist/stage.umd.cjs +3624 -0
- package/dist/stage.umd.cjs.map +1 -0
- package/docs/package-lock.json +12922 -0
- package/docs/package.json +18 -0
- package/docs/pages/anim.md +34 -0
- package/docs/pages/api/classes/Anim.md +1357 -0
- package/docs/pages/api/classes/Atlas.md +281 -0
- package/docs/pages/api/classes/CanvasTexture.md +317 -0
- package/docs/pages/api/classes/ImageTexture.md +256 -0
- package/docs/pages/api/classes/Matrix.md +283 -0
- package/docs/pages/api/classes/Monotype.md +1291 -0
- package/docs/pages/api/classes/Node.md +1030 -0
- package/docs/pages/api/classes/Pin.md +41 -0
- package/docs/pages/api/classes/PipeTexture.md +231 -0
- package/docs/pages/api/classes/ResizableTexture.md +219 -0
- package/docs/pages/api/classes/Root.md +1400 -0
- package/docs/pages/api/classes/Sprite.md +1285 -0
- package/docs/pages/api/classes/Texture.md +175 -0
- package/docs/pages/api/classes/TextureSelection.md +61 -0
- package/docs/pages/api/classes/Transition.md +417 -0
- package/docs/pages/api/functions/anim.md +13 -0
- package/docs/pages/api/functions/atlas.md +11 -0
- package/docs/pages/api/functions/canvas.md +9 -0
- package/docs/pages/api/functions/column.md +11 -0
- package/docs/pages/api/functions/component.md +7 -0
- package/docs/pages/api/functions/maximize.md +7 -0
- package/docs/pages/api/functions/minimize.md +7 -0
- package/docs/pages/api/functions/monotype.md +11 -0
- package/docs/pages/api/functions/mount.md +11 -0
- package/docs/pages/api/functions/pause.md +7 -0
- package/docs/pages/api/functions/resume.md +7 -0
- package/docs/pages/api/functions/row.md +11 -0
- package/docs/pages/api/functions/sprite.md +11 -0
- package/docs/pages/api/functions/texture.md +15 -0
- package/docs/pages/api/index.md +68 -0
- package/docs/pages/api/interfaces/AtlasDefinition.md +109 -0
- package/docs/pages/api/interfaces/AtlasTextureDefinition.md +49 -0
- package/docs/pages/api/interfaces/MatrixValue.md +37 -0
- package/docs/pages/api/interfaces/Vec2Value.md +13 -0
- package/docs/pages/api/type-aliases/FitMode.md +7 -0
- package/docs/pages/api/type-aliases/NodeEventListener.md +17 -0
- package/docs/pages/api/type-aliases/NodeTickListener.md +21 -0
- package/docs/pages/api/type-aliases/ResizableTextureMode.md +3 -0
- package/docs/pages/api/type-aliases/TextureSelectionInput.md +11 -0
- package/docs/pages/api/type-aliases/TextureSelectionInputArray.md +3 -0
- package/docs/pages/api/type-aliases/TextureSelectionInputFactory.md +11 -0
- package/docs/pages/api/type-aliases/TextureSelectionInputMap.md +3 -0
- package/docs/pages/api/type-aliases/TextureSelectionInputOne.md +3 -0
- package/docs/pages/api/type-aliases/TransitionEndListener.md +11 -0
- package/docs/pages/api/type-aliases/TransitionOptions.md +17 -0
- package/docs/pages/api/type-aliases/Viewbox.md +27 -0
- package/docs/pages/api/type-aliases/Viewport.md +19 -0
- package/docs/pages/api/variables/POINTER_CANCEL.md +3 -0
- package/docs/pages/api/variables/POINTER_CLICK.md +3 -0
- package/docs/pages/api/variables/POINTER_DOWN.md +3 -0
- package/docs/pages/api/variables/POINTER_MOVE.md +3 -0
- package/docs/pages/api/variables/POINTER_UP.md +3 -0
- package/docs/pages/api/variables/math.md +3 -0
- package/docs/pages/atlas.md +42 -0
- package/docs/pages/events.md +47 -0
- package/docs/pages/hello-world.md +60 -0
- package/docs/pages/index.md +15 -0
- package/docs/pages/install.md +24 -0
- package/docs/pages/layout.md +40 -0
- package/docs/pages/loop.md +25 -0
- package/docs/pages/monotype.md +32 -0
- package/docs/pages/news/v1-0.md +37 -0
- package/docs/pages/pin.md +128 -0
- package/docs/pages/setup.md +46 -0
- package/docs/pages/sprite.md +17 -0
- package/docs/pages/texture.md +4 -0
- package/docs/pages/transition.md +46 -0
- package/docs/pages/tree.md +77 -0
- package/docs/styles.css +0 -0
- package/docs/tsconfig.json +24 -0
- package/docs/vercel.json +8 -0
- package/docs/vocs.config.ts +113 -0
- package/example/basic-anim/app.js +22 -0
- package/example/basic-anim/index.html +14 -0
- package/example/basic-drawing/app.js +53 -0
- package/example/basic-drawing/index.html +19 -0
- package/example/basic-example/app.js +33 -0
- package/example/basic-example/index.html +19 -0
- package/example/basic-example/sample.png +0 -0
- package/example/basic-grid/app.js +38 -0
- package/example/basic-grid/index.html +19 -0
- package/example/basic-layout/app.js +72 -0
- package/example/basic-layout/index.html +19 -0
- package/example/basic-matrix/app.js +35 -0
- package/example/basic-matrix/box.png +0 -0
- package/example/basic-matrix/index.html +19 -0
- package/example/basic-mouse/app.js +76 -0
- package/example/basic-mouse/index.html +19 -0
- package/example/basic-package/app.js +22 -0
- package/example/basic-package/index.html +19 -0
- package/example/basic-package/main.png +0 -0
- package/example/basic-package/main.svg +6 -0
- package/example/basic-pinwheel/app.js +24 -0
- package/example/basic-pinwheel/index.html +19 -0
- package/example/basic-pinwheel/pinwheel.png +0 -0
- package/example/basic-row/app.js +27 -0
- package/example/basic-row/index.html +19 -0
- package/example/basic-row-fix/app.js +33 -0
- package/example/basic-row-fix/index.html +19 -0
- package/example/basic-stretch/app.js +24 -0
- package/example/basic-stretch/index.html +19 -0
- package/example/basic-string/app.js +22 -0
- package/example/basic-string/index.html +19 -0
- package/example/basic-tile/app.js +24 -0
- package/example/basic-tile/index.html +19 -0
- package/example/basic-tween/app.js +49 -0
- package/example/basic-tween/index.html +19 -0
- package/example/basic-window/app.js +42 -0
- package/example/basic-window/index.html +19 -0
- package/example/common/bezier.js +62 -0
- package/example/common/example.css +58 -0
- package/example/common/example.png +0 -0
- package/example/common/example.svg +23 -0
- package/example/common/p2.js +10343 -0
- package/example/common/pool.js +92 -0
- package/example/common/randomize.js +100 -0
- package/{ext → example/common}/stage-p2.js +182 -202
- package/example/common/texture.js +45 -0
- package/example/common/timeout.js +47 -0
- package/example/example.svg +23 -0
- package/example/game-aero/app.js +284 -0
- package/example/game-aero/index.html +21 -0
- package/example/game-aero/main.png +0 -0
- package/example/game-aero/main.svg +29 -0
- package/example/game-asteroids/app.js +444 -0
- package/example/game-asteroids/index.html +28 -0
- package/example/game-asteroids/main.svg +9 -0
- package/example/game-breakout/app.js +627 -0
- package/example/game-breakout/bg.png +0 -0
- package/example/game-breakout/bg.svg +11 -0
- package/example/game-breakout/index.html +19 -0
- package/example/game-breakout/logo.svg +31 -0
- package/example/game-breakout/main.png +0 -0
- package/example/game-breakout/main.svg +45 -0
- package/example/game-breakout/texture.js +51 -0
- package/example/game-o/app.js +1496 -0
- package/example/game-o/index.html +14 -0
- package/example/game-o/main.png +0 -0
- package/example/game-o/textures.js +203 -0
- package/example/game-orbit/app.js +497 -0
- package/example/game-orbit/art/android.json +13 -0
- package/example/game-orbit/art/bg.svg +62 -0
- package/example/game-orbit/art/digit.svg +140 -0
- package/example/game-orbit/art/game.json +14 -0
- package/example/game-orbit/art/icon.svg +128 -0
- package/example/game-orbit/art/ios.json +34 -0
- package/example/game-orbit/art/main.svg +56 -0
- package/example/game-orbit/art/misc.json +10 -0
- package/example/game-orbit/art/splash.svg +77 -0
- package/example/game-orbit/index.html +19 -0
- package/example/game-orbit/media/bg.png +0 -0
- package/example/game-orbit/media/digit.png +0 -0
- package/example/game-orbit/media/main.png +0 -0
- package/example/game-orbit/textures.js +40 -0
- package/example/game-samegame/app.js +244 -0
- package/example/game-samegame/index.html +19 -0
- package/example/game-samegame/main.png +0 -0
- package/example/game-samegame/main.svg +29 -0
- package/example/game-samegame/textures.js +15 -0
- package/example/game-tictactoe/app.js +183 -0
- package/example/game-tictactoe/index.html +19 -0
- package/example/game-traffic/app.js +383 -0
- package/example/game-traffic/base.svg +4 -0
- package/example/game-traffic/bg.png +0 -0
- package/example/game-traffic/bg.svg +10 -0
- package/example/game-traffic/index.html +19 -0
- package/example/game-traffic/main.png +0 -0
- package/example/game-traffic/map-1.png +0 -0
- package/example/game-traffic/map-1.svg +5 -0
- package/example/game-traffic/textures.js +24 -0
- package/example/index.html +30 -0
- package/index.html +6 -0
- package/package.json +46 -22
- package/src/common/browser.ts +5 -0
- package/src/common/is.ts +18 -0
- package/src/common/math.ts +60 -0
- package/src/common/matrix.ts +241 -0
- package/src/common/stats.ts +8 -0
- package/src/common/uid.ts +4 -0
- package/src/core/anim.ts +144 -0
- package/src/core/core.ts +1191 -0
- package/src/core/easing.ts +235 -0
- package/src/core/monotype.ts +94 -0
- package/src/core/pin.ts +664 -0
- package/src/core/pointer.ts +317 -0
- package/src/core/root.ts +451 -0
- package/src/core/sprite.ts +105 -0
- package/src/core/transition.ts +271 -0
- package/src/index.ts +3 -0
- package/src/main.ts +16 -0
- package/src/texture/atlas.ts +218 -0
- package/src/texture/canvas.ts +176 -0
- package/src/texture/image.ts +103 -0
- package/src/texture/index.ts +7 -0
- package/src/texture/pipe.ts +47 -0
- package/src/texture/resizable.ts +159 -0
- package/src/texture/selection.ts +203 -0
- package/src/texture/texture.ts +157 -0
- package/test/atlas-test.js +112 -97
- package/test/event-test.js +48 -50
- package/test/main-test.js +12 -15
- package/test/mouse-test.js +81 -67
- package/test/node-test.js +117 -80
- package/test/pin-test.js +57 -59
- package/test/transition-test.js +40 -0
- package/test/util/expect.js +24 -20
- package/test/util/memo.js +5 -5
- package/tsconfig.json +18 -0
- package/typedoc.json +24 -0
- package/vite.config.ts +52 -0
- package/dist/stage.cordova.js +0 -4035
- package/dist/stage.cordova.js.map +0 -1
- package/dist/stage.cordova.min.js +0 -36
- package/dist/stage.cordova.min.js.map +0 -1
- package/dist/stage.web.js +0 -3984
- package/dist/stage.web.js.map +0 -1
- package/dist/stage.web.min.js +0 -36
- package/dist/stage.web.min.js.map +0 -1
- package/ext/stage-matter.js +0 -201
- package/ext/stage-physics.js +0 -167
- package/ext/stage-planck.js +0 -355
- package/ext/stage-sat.js +0 -197
- package/lib/addon/easing.js +0 -185
- package/lib/addon/mouse.js +0 -206
- package/lib/addon/tween.js +0 -189
- package/lib/anim.js +0 -135
- package/lib/atlas.js +0 -240
- package/lib/canvas.js +0 -51
- package/lib/core.js +0 -221
- package/lib/event.js +0 -3
- package/lib/image.js +0 -72
- package/lib/index.js +0 -10
- package/lib/layout.js +0 -143
- package/lib/loader/cordova.js +0 -186
- package/lib/loader/web.js +0 -151
- package/lib/loop.js +0 -136
- package/lib/matrix.js +0 -169
- package/lib/pin.js +0 -620
- package/lib/root.js +0 -136
- package/lib/str.js +0 -81
- package/lib/texture.js +0 -103
- package/lib/tree.js +0 -410
- package/lib/util/await.js +0 -28
- package/lib/util/create.js +0 -16
- package/lib/util/event.js +0 -71
- package/lib/util/extend.js +0 -11
- package/lib/util/insert.js +0 -16
- package/lib/util/is.js +0 -167
- package/lib/util/math.js +0 -42
- package/lib/util/memo.js +0 -13
- package/lib/util/now.js +0 -13
- package/lib/util/once.js +0 -9
- package/lib/util/repeat.js +0 -74
- package/lib/util/stats.js +0 -1
- package/lib/util/string.js +0 -4
- package/platform/cordova.js +0 -16
- package/platform/web.js +0 -16
- package/test/tween-test.js +0 -41
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Vec2Value } from "../common/matrix";
|
|
2
|
+
|
|
3
|
+
import { Root, Viewport } from "./root";
|
|
4
|
+
import { Node } from "./core";
|
|
5
|
+
|
|
6
|
+
// todo: capture mouse
|
|
7
|
+
// todo: implement unmount
|
|
8
|
+
|
|
9
|
+
// todo: replace this with single synthetic event names
|
|
10
|
+
export const POINTER_CLICK = "click";
|
|
11
|
+
export const POINTER_DOWN = "touchstart mousedown";
|
|
12
|
+
export const POINTER_MOVE = "touchmove mousemove";
|
|
13
|
+
export const POINTER_UP = "touchend mouseup";
|
|
14
|
+
export const POINTER_CANCEL = "touchcancel mousecancel";
|
|
15
|
+
|
|
16
|
+
/** @hidden @deprecated */
|
|
17
|
+
export const POINTER_START = "touchstart mousedown";
|
|
18
|
+
/** @hidden @deprecated */
|
|
19
|
+
export const POINTER_END = "touchend mouseup";
|
|
20
|
+
|
|
21
|
+
class EventPoint {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
|
|
25
|
+
clone(obj?: Vec2Value) {
|
|
26
|
+
if (obj) {
|
|
27
|
+
obj.x = this.x;
|
|
28
|
+
obj.y = this.y;
|
|
29
|
+
} else {
|
|
30
|
+
obj = {
|
|
31
|
+
x: this.x,
|
|
32
|
+
y: this.y,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
toString() {
|
|
39
|
+
return (this.x | 0) + "x" + (this.y | 0);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// todo: make object readonly for users, to make it safe for reuse
|
|
44
|
+
class PointerSyntheticEvent {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
readonly abs = new EventPoint();
|
|
48
|
+
|
|
49
|
+
raw: UIEvent;
|
|
50
|
+
type: string;
|
|
51
|
+
timeStamp: number;
|
|
52
|
+
|
|
53
|
+
clone(obj?: Vec2Value) {
|
|
54
|
+
if (obj) {
|
|
55
|
+
obj.x = this.x;
|
|
56
|
+
obj.y = this.y;
|
|
57
|
+
} else {
|
|
58
|
+
obj = {
|
|
59
|
+
x: this.x,
|
|
60
|
+
y: this.y,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return obj;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
toString() {
|
|
67
|
+
return this.type + ": " + (this.x | 0) + "x" + (this.y | 0);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
class VisitPayload {
|
|
73
|
+
type: string = "";
|
|
74
|
+
x: number = 0;
|
|
75
|
+
y: number = 0;
|
|
76
|
+
timeStamp: number = -1;
|
|
77
|
+
event: UIEvent = null;
|
|
78
|
+
root: Root = null;
|
|
79
|
+
collected: Node[] | null = null;
|
|
80
|
+
toString() {
|
|
81
|
+
return this.type + ": " + (this.x | 0) + "x" + (this.y | 0);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// todo: define per pointer object? so that don't need to update root
|
|
86
|
+
/** @internal */ const syntheticEvent = new PointerSyntheticEvent();
|
|
87
|
+
|
|
88
|
+
/** @internal */ const PAYLOAD = new VisitPayload();
|
|
89
|
+
|
|
90
|
+
/** @internal */
|
|
91
|
+
export class Pointer {
|
|
92
|
+
static DEBUG = false;
|
|
93
|
+
ratio = 1;
|
|
94
|
+
|
|
95
|
+
stage: Root;
|
|
96
|
+
elem: HTMLElement;
|
|
97
|
+
|
|
98
|
+
mount(stage: Root, elem: HTMLElement) {
|
|
99
|
+
this.stage = stage;
|
|
100
|
+
this.elem = elem;
|
|
101
|
+
|
|
102
|
+
this.ratio = stage.viewport().ratio || 1;
|
|
103
|
+
stage.on("viewport", (viewport: Viewport) => {
|
|
104
|
+
this.ratio = viewport.ratio ?? this.ratio;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// `click` events are synthesized from start/end events on same nodes
|
|
108
|
+
// `mousecancel` events are synthesized on blur or mouseup outside element
|
|
109
|
+
|
|
110
|
+
elem.addEventListener("touchstart", this.handleStart);
|
|
111
|
+
elem.addEventListener("touchend", this.handleEnd);
|
|
112
|
+
elem.addEventListener("touchmove", this.handleMove);
|
|
113
|
+
elem.addEventListener("touchcancel", this.handleCancel);
|
|
114
|
+
|
|
115
|
+
elem.addEventListener("mousedown", this.handleStart);
|
|
116
|
+
elem.addEventListener("mouseup", this.handleEnd);
|
|
117
|
+
elem.addEventListener("mousemove", this.handleMove);
|
|
118
|
+
|
|
119
|
+
document.addEventListener("mouseup", this.handleCancel);
|
|
120
|
+
window.addEventListener("blur", this.handleCancel);
|
|
121
|
+
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
unmount() {
|
|
126
|
+
const elem = this.elem;
|
|
127
|
+
|
|
128
|
+
elem.removeEventListener("touchstart", this.handleStart);
|
|
129
|
+
elem.removeEventListener("touchend", this.handleEnd);
|
|
130
|
+
elem.removeEventListener("touchmove", this.handleMove);
|
|
131
|
+
elem.removeEventListener("touchcancel", this.handleCancel);
|
|
132
|
+
|
|
133
|
+
elem.removeEventListener("mousedown", this.handleStart);
|
|
134
|
+
elem.removeEventListener("mouseup", this.handleEnd);
|
|
135
|
+
elem.removeEventListener("mousemove", this.handleMove);
|
|
136
|
+
|
|
137
|
+
document.removeEventListener("mouseup", this.handleCancel);
|
|
138
|
+
window.removeEventListener("blur", this.handleCancel);
|
|
139
|
+
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
clickList: Node[] = [];
|
|
144
|
+
cancelList: Node[] = [];
|
|
145
|
+
|
|
146
|
+
handleStart = (event: TouchEvent | MouseEvent) => {
|
|
147
|
+
Pointer.DEBUG && console.debug && console.debug("pointer-start", event.type);
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
this.localPoint(event);
|
|
150
|
+
this.dispatchEvent(event.type, event);
|
|
151
|
+
|
|
152
|
+
this.findTargets("click", this.clickList);
|
|
153
|
+
this.findTargets("mousecancel", this.cancelList);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
handleMove = (event: TouchEvent | MouseEvent) => {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
this.localPoint(event);
|
|
159
|
+
this.dispatchEvent(event.type, event);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
handleEnd = (event: TouchEvent | MouseEvent) => {
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
// up/end location is not available, last one is used instead
|
|
165
|
+
Pointer.DEBUG && console.debug && console.debug("pointer-end", event.type);
|
|
166
|
+
this.dispatchEvent(event.type, event);
|
|
167
|
+
|
|
168
|
+
if (this.clickList.length) {
|
|
169
|
+
Pointer.DEBUG && console.debug && console.debug("pointer-click: ", event.type, this.clickList?.length);
|
|
170
|
+
this.dispatchEvent("click", event, this.clickList);
|
|
171
|
+
}
|
|
172
|
+
this.cancelList.length = 0;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
handleCancel = (event: TouchEvent | MouseEvent | FocusEvent) => {
|
|
176
|
+
if (this.cancelList.length) {
|
|
177
|
+
Pointer.DEBUG && console.debug && console.debug("pointer-cancel", event.type, this.clickList?.length);
|
|
178
|
+
this.dispatchEvent("mousecancel", event, this.cancelList);
|
|
179
|
+
}
|
|
180
|
+
this.clickList.length = 0;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Computer the location of the pointer event in the canvas coordination
|
|
185
|
+
*/
|
|
186
|
+
localPoint(event: TouchEvent | MouseEvent) {
|
|
187
|
+
const elem = this.elem;
|
|
188
|
+
let x: number;
|
|
189
|
+
let y: number;
|
|
190
|
+
// pageX/Y if available?
|
|
191
|
+
|
|
192
|
+
if ((event as TouchEvent).touches?.length) {
|
|
193
|
+
x = (event as TouchEvent).touches[0].clientX;
|
|
194
|
+
y = (event as TouchEvent).touches[0].clientY;
|
|
195
|
+
} else {
|
|
196
|
+
x = (event as MouseEvent).clientX;
|
|
197
|
+
y = (event as MouseEvent).clientY;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const rect = elem.getBoundingClientRect();
|
|
201
|
+
x -= rect.left;
|
|
202
|
+
y -= rect.top;
|
|
203
|
+
x -= elem.clientLeft | 0;
|
|
204
|
+
y -= elem.clientTop | 0;
|
|
205
|
+
|
|
206
|
+
PAYLOAD.x = x * this.ratio;
|
|
207
|
+
PAYLOAD.y = y * this.ratio;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Find eligible target for and event type, used to keep trace nodes to dispatch click event
|
|
212
|
+
*/
|
|
213
|
+
findTargets(type: string, result: Node[]) {
|
|
214
|
+
const payload = PAYLOAD;
|
|
215
|
+
|
|
216
|
+
payload.type = type;
|
|
217
|
+
payload.root = this.stage;
|
|
218
|
+
payload.event = null;
|
|
219
|
+
payload.collected = result;
|
|
220
|
+
payload.collected.length = 0;
|
|
221
|
+
|
|
222
|
+
this.stage.visit(
|
|
223
|
+
{
|
|
224
|
+
reverse: true,
|
|
225
|
+
visible: true,
|
|
226
|
+
start: this.visitStart,
|
|
227
|
+
end: this.visitEnd,
|
|
228
|
+
},
|
|
229
|
+
payload,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
dispatchEvent(type: string, event: UIEvent, targets?: Node[]) {
|
|
234
|
+
const payload = PAYLOAD;
|
|
235
|
+
|
|
236
|
+
payload.type = type;
|
|
237
|
+
payload.root = this.stage;
|
|
238
|
+
payload.event = event;
|
|
239
|
+
payload.timeStamp = Date.now();
|
|
240
|
+
payload.collected = null;
|
|
241
|
+
|
|
242
|
+
if (type !== "mousemove" && type !== "touchmove") {
|
|
243
|
+
Pointer.DEBUG && console.debug && console.debug("pointer:dispatchEvent", payload, targets?.length);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (targets) {
|
|
247
|
+
while (targets.length) {
|
|
248
|
+
const node = targets.shift();
|
|
249
|
+
if (this.visitEnd(node, payload)) {
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
targets.length = 0;
|
|
254
|
+
} else {
|
|
255
|
+
this.stage.visit(
|
|
256
|
+
{
|
|
257
|
+
reverse: true,
|
|
258
|
+
visible: true,
|
|
259
|
+
start: this.visitStart,
|
|
260
|
+
end: this.visitEnd,
|
|
261
|
+
},
|
|
262
|
+
payload,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
visitStart = (node: Node, payload: VisitPayload) => {
|
|
268
|
+
return !node._flag(payload.type);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
visitEnd = (node: Node, payload: VisitPayload) => {
|
|
272
|
+
// mouse: event/collect, type, root
|
|
273
|
+
syntheticEvent.raw = payload.event;
|
|
274
|
+
syntheticEvent.type = payload.type;
|
|
275
|
+
syntheticEvent.timeStamp = payload.timeStamp;
|
|
276
|
+
syntheticEvent.abs.x = payload.x;
|
|
277
|
+
syntheticEvent.abs.y = payload.y;
|
|
278
|
+
|
|
279
|
+
const listeners = node.listeners(payload.type);
|
|
280
|
+
if (!listeners) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
node.matrix().inverse().map(payload, syntheticEvent);
|
|
285
|
+
|
|
286
|
+
// deep flags are used to decide to pass down event, and spy is not used for that
|
|
287
|
+
// we use spy to decide if an event should be delivered to elements that do not have hitTest
|
|
288
|
+
// todo: collect and pass hitTest result upward instead, probably use visit payload
|
|
289
|
+
const isEventTarget = node === payload.root || node.attr("spy") || node.hitTest(syntheticEvent);
|
|
290
|
+
if (!isEventTarget) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (payload.collected) {
|
|
295
|
+
payload.collected.push(node);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// todo: when this condition is false?
|
|
299
|
+
if (payload.event) {
|
|
300
|
+
// todo: use a function call to cancel processing events, like dom
|
|
301
|
+
let stop = false;
|
|
302
|
+
for (let l = 0; l < listeners.length; l++) {
|
|
303
|
+
stop = listeners[l].call(node, syntheticEvent) ? true : stop;
|
|
304
|
+
}
|
|
305
|
+
return stop;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** @hidden @deprecated @internal */
|
|
311
|
+
export const Mouse = {
|
|
312
|
+
CLICK: "click",
|
|
313
|
+
START: "touchstart mousedown",
|
|
314
|
+
MOVE: "touchmove mousemove",
|
|
315
|
+
END: "touchend mouseup",
|
|
316
|
+
CANCEL: "touchcancel mousecancel",
|
|
317
|
+
};
|