@visactor/vrender-core 1.1.12 → 1.1.13
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/cjs/canvas/conical-gradient.js +1 -1
- package/cjs/canvas/constants.js +1 -1
- package/cjs/canvas/empty-context.js +1 -1
- package/cjs/canvas/index.js +1 -1
- package/cjs/canvas/util.js +1 -1
- package/cjs/common/bezier-utils.js +1 -2
- package/cjs/common/contribution-store-state.js +2 -1
- package/cjs/common/path-svg.js +1 -2
- package/cjs/common/render-command-list.js +2 -1
- package/cjs/common/seg-context.js +1 -1
- package/cjs/common/simplify.js +1 -1
- package/cjs/common/sort.js +1 -1
- package/cjs/common/split-path.js +1 -1
- package/cjs/common/text.js +1 -1
- package/cjs/core/contributions/layerHandler/modules.js +4 -2
- package/cjs/core/contributions/layerHandler/modules.js.map +1 -1
- package/cjs/core/stage.d.ts +10 -3
- package/cjs/core/stage.js +39 -20
- package/cjs/core/stage.js.map +1 -1
- package/cjs/event/event-manager.d.ts +29 -1
- package/cjs/event/event-manager.js +161 -42
- package/cjs/event/event-manager.js.map +1 -1
- package/cjs/event/event-system.d.ts +19 -3
- package/cjs/event/event-system.js +110 -62
- package/cjs/event/event-system.js.map +1 -1
- package/cjs/event/federated-event/base-event.js +3 -1
- package/cjs/event/federated-event/base-event.js.map +1 -1
- package/cjs/event/input-source.d.ts +7 -0
- package/cjs/event/input-source.js +37 -0
- package/cjs/event/input-source.js.map +1 -0
- package/cjs/interface/event.d.ts +9 -0
- package/cjs/interface/event.js.map +1 -1
- package/cjs/interface/stage.d.ts +10 -2
- package/cjs/interface/stage.js.map +1 -1
- package/cjs/render/contributions/render/draw-interceptor.js +13 -3
- package/cjs/render/contributions/render/draw-interceptor.js.map +1 -1
- package/dist/index.es.js +622 -145
- package/es/canvas/conical-gradient.js +1 -1
- package/es/canvas/constants.js +1 -1
- package/es/canvas/empty-context.js +1 -1
- package/es/canvas/index.js +1 -1
- package/es/canvas/util.js +1 -1
- package/es/common/bezier-utils.js +1 -2
- package/es/common/contribution-store-state.js +2 -1
- package/es/common/path-svg.js +1 -2
- package/es/common/render-command-list.js +2 -1
- package/es/common/seg-context.js +1 -1
- package/es/common/simplify.js +1 -1
- package/es/common/sort.js +1 -1
- package/es/common/split-path.js +1 -1
- package/es/common/text.js +1 -1
- package/es/core/contributions/layerHandler/modules.js +6 -2
- package/es/core/contributions/layerHandler/modules.js.map +1 -1
- package/es/core/stage.d.ts +10 -3
- package/es/core/stage.js +40 -21
- package/es/core/stage.js.map +1 -1
- package/es/event/event-manager.d.ts +29 -1
- package/es/event/event-manager.js +162 -41
- package/es/event/event-manager.js.map +1 -1
- package/es/event/event-system.d.ts +19 -3
- package/es/event/event-system.js +110 -62
- package/es/event/event-system.js.map +1 -1
- package/es/event/federated-event/base-event.js +2 -1
- package/es/event/federated-event/base-event.js.map +1 -1
- package/es/event/input-source.d.ts +7 -0
- package/es/event/input-source.js +29 -0
- package/es/event/input-source.js.map +1 -0
- package/es/interface/event.d.ts +9 -0
- package/es/interface/event.js.map +1 -1
- package/es/interface/stage.d.ts +10 -2
- package/es/interface/stage.js.map +1 -1
- package/es/render/contributions/render/draw-interceptor.js +12 -3
- package/es/render/contributions/render/draw-interceptor.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { InputSource } from "./input-source";
|
|
2
|
+
|
|
1
3
|
import { EventEmitter, Logger } from "@visactor/vutils";
|
|
2
4
|
|
|
3
5
|
import { FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent } from "./federated-event";
|
|
@@ -12,21 +14,36 @@ function isMouseLike(pointerType) {
|
|
|
12
14
|
return "mouse" === pointerType || "pen" === pointerType;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
const DEFAULT_CLICK_INTERVAL = 200
|
|
17
|
+
const DEFAULT_CLICK_INTERVAL = 200, TOUCH_INPUT_TYPES = {
|
|
18
|
+
pointerdown: "touchstart",
|
|
19
|
+
pointermove: "touchmove",
|
|
20
|
+
pointerup: "touchend"
|
|
21
|
+
}, MOUSE_INPUT_TYPES = {
|
|
22
|
+
pointerdown: "mousedown",
|
|
23
|
+
pointermove: "mousemove",
|
|
24
|
+
pointerup: "mouseup"
|
|
25
|
+
};
|
|
16
26
|
|
|
17
27
|
export class EventManager {
|
|
18
28
|
constructor(root, config) {
|
|
19
29
|
this.dispatch = new EventEmitter, this.cursorTarget = null, this.pauseNotify = !1,
|
|
20
30
|
this.mappingState = {
|
|
21
31
|
trackingData: {}
|
|
22
|
-
}, this.eventPool = new Map, this.
|
|
32
|
+
}, this.eventPool = new Map, this.canvasInput = new InputSource, this.windowInput = new InputSource,
|
|
33
|
+
this.input = {
|
|
34
|
+
canvas: this.canvasInput.source,
|
|
35
|
+
window: this.windowInput.source
|
|
36
|
+
}, this.currentGeneration = 0, this.terminalDepth = 0, this.inputValid = () => !!this.rootTarget && (this.terminalDepth > 0 || !this.currentTracking || this.currentTracking.generation === this.currentGeneration),
|
|
37
|
+
this.onPointerCancel = from => {
|
|
38
|
+
from instanceof FederatedPointerEvent && this.cancelPointer(from.pointerId);
|
|
39
|
+
}, this.onPointerDown = (from, target) => {
|
|
23
40
|
if (!(from instanceof FederatedPointerEvent)) return void Logger.getInstance().warn("EventManager cannot map a non-pointer event as a pointer event");
|
|
24
41
|
const e = this.createPointerEvent(from, from.type, target);
|
|
25
|
-
if (this.
|
|
42
|
+
if (this.trackingData(from.pointerId).pressTargetsByButton[from.button] = e.composedPath(),
|
|
43
|
+
this.dispatchEvent(e, "pointerdown"), "touch" === e.pointerType) this.dispatchEvent(e, "touchstart"); else if (isMouseLike(e.pointerType)) {
|
|
26
44
|
const isRightButton = 2 === e.button;
|
|
27
45
|
this.dispatchEvent(e, isRightButton ? "rightdown" : "mousedown");
|
|
28
46
|
}
|
|
29
|
-
this.trackingData(from.pointerId).pressTargetsByButton[from.button] = e.composedPath(),
|
|
30
47
|
this.freeEvent(e);
|
|
31
48
|
}, this.onPointerMove = (from, target) => {
|
|
32
49
|
var _a, _b;
|
|
@@ -48,8 +65,8 @@ export class EventManager {
|
|
|
48
65
|
const overType = "mousemove" === from.type ? "mouseover" : "pointerover", overEvent = this.clonePointerEvent(e, overType);
|
|
49
66
|
this.dispatchEvent(overEvent, "pointerover"), isMouse && this.dispatchEvent(overEvent, "mouseover");
|
|
50
67
|
let overTargetAncestor = null == outTarget ? void 0 : outTarget.parent;
|
|
51
|
-
for (;overTargetAncestor && overTargetAncestor !== this.rootTarget.parent && overTargetAncestor !== e.target; ) overTargetAncestor = overTargetAncestor.parent;
|
|
52
|
-
if (!overTargetAncestor || overTargetAncestor === this.rootTarget.parent) {
|
|
68
|
+
for (;this.inputValid() && overTargetAncestor && overTargetAncestor !== this.rootTarget.parent && overTargetAncestor !== e.target; ) overTargetAncestor = overTargetAncestor.parent;
|
|
69
|
+
if (this.inputValid() && (!overTargetAncestor || overTargetAncestor === this.rootTarget.parent)) {
|
|
53
70
|
const enterEvent = this.clonePointerEvent(e, "pointerenter");
|
|
54
71
|
enterEvent.eventPhase = enterEvent.AT_TARGET;
|
|
55
72
|
let currentTarget = enterEvent.target;
|
|
@@ -57,7 +74,7 @@ export class EventManager {
|
|
|
57
74
|
let ancestor = outTarget;
|
|
58
75
|
for (;ancestor && ancestor !== this.rootTarget; ) outTargetAncestors.add(ancestor),
|
|
59
76
|
ancestor = ancestor.parent;
|
|
60
|
-
for (;currentTarget && currentTarget !== outTarget && currentTarget !== this.rootTarget.parent; ) outTargetAncestors.has(currentTarget) || (enterEvent.currentTarget = currentTarget,
|
|
77
|
+
for (;this.inputValid() && currentTarget && currentTarget !== outTarget && currentTarget !== this.rootTarget.parent; ) outTargetAncestors.has(currentTarget) || (enterEvent.currentTarget = currentTarget,
|
|
61
78
|
this.notifyTarget(enterEvent), isMouse && this.notifyTarget(enterEvent, "mouseenter")),
|
|
62
79
|
currentTarget = currentTarget.parent;
|
|
63
80
|
this.freeEvent(enterEvent);
|
|
@@ -65,19 +82,22 @@ export class EventManager {
|
|
|
65
82
|
this.freeEvent(overEvent);
|
|
66
83
|
}
|
|
67
84
|
this.dispatchEvent(e, "pointermove"), "touch" === e.pointerType && this.dispatchEvent(e, "touchmove"),
|
|
68
|
-
isMouse && (this.dispatchEvent(e, "mousemove"), this.cursorTarget = e.target,
|
|
69
|
-
|
|
85
|
+
isMouse && this.inputValid() && (this.dispatchEvent(e, "mousemove"), this.cursorTarget = e.target,
|
|
86
|
+
this.cursor = (null === (_b = null === (_a = e.target) || void 0 === _a ? void 0 : _a.attribute) || void 0 === _b ? void 0 : _b.cursor) || this.rootTarget.getCursor()),
|
|
87
|
+
this.inputValid() && (trackingData.overTargets = e.composedPath()), this.freeEvent(e);
|
|
70
88
|
}, this.onPointerOver = (from, target) => {
|
|
71
89
|
var _a, _b;
|
|
72
90
|
if (!(from instanceof FederatedPointerEvent)) return void Logger.getInstance().warn("EventManager cannot map a non-pointer event as a pointer event");
|
|
73
91
|
const trackingData = this.trackingData(from.pointerId), e = this.createPointerEvent(from, from.type, target), isMouse = isMouseLike(e.pointerType);
|
|
74
92
|
this.dispatchEvent(e, "pointerover"), isMouse && this.dispatchEvent(e, "mouseover"),
|
|
75
|
-
"mouse" === e.pointerType &&
|
|
93
|
+
"mouse" === e.pointerType && this.inputValid() && (this.cursorTarget = e.target,
|
|
94
|
+
this.cursor = (null === (_b = null === (_a = e.target) || void 0 === _a ? void 0 : _a.attribute) || void 0 === _b ? void 0 : _b.cursor) || this.rootTarget.getCursor());
|
|
76
95
|
const enterEvent = this.clonePointerEvent(e, "pointerenter");
|
|
77
|
-
for (enterEvent.eventPhase = enterEvent.AT_TARGET; enterEvent.target && enterEvent.target !== this.rootTarget.parent; ) enterEvent.currentTarget = enterEvent.target,
|
|
96
|
+
for (enterEvent.eventPhase = enterEvent.AT_TARGET; this.inputValid() && enterEvent.target && enterEvent.target !== this.rootTarget.parent; ) enterEvent.currentTarget = enterEvent.target,
|
|
78
97
|
this.notifyTarget(enterEvent), isMouse && this.notifyTarget(enterEvent, "mouseenter"),
|
|
79
98
|
enterEvent.target = enterEvent.target.parent;
|
|
80
|
-
trackingData.overTargets = e.composedPath(), this.freeEvent(e),
|
|
99
|
+
this.inputValid() && (trackingData.overTargets = e.composedPath()), this.freeEvent(e),
|
|
100
|
+
this.freeEvent(enterEvent);
|
|
81
101
|
}, this.onPointerOut = (from, target) => {
|
|
82
102
|
if (!(from instanceof FederatedPointerEvent)) return void Logger.getInstance().warn("EventManager cannot map a non-pointer event as a pointer event");
|
|
83
103
|
const trackingData = this.trackingData(from.pointerId);
|
|
@@ -85,7 +105,7 @@ export class EventManager {
|
|
|
85
105
|
const isMouse = isMouseLike(from.pointerType), outTarget = this.findMountedTarget(trackingData.overTargets), outEvent = this.createPointerEvent(from, "pointerout", outTarget || void 0);
|
|
86
106
|
this.dispatchEvent(outEvent), isMouse && this.dispatchEvent(outEvent, "mouseout");
|
|
87
107
|
const leaveEvent = this.createPointerEvent(from, "pointerleave", outTarget || void 0);
|
|
88
|
-
for (leaveEvent.eventPhase = leaveEvent.AT_TARGET; leaveEvent.target && leaveEvent.target !== this.rootTarget.parent; ) leaveEvent.currentTarget = leaveEvent.target,
|
|
108
|
+
for (leaveEvent.eventPhase = leaveEvent.AT_TARGET; this.inputValid() && leaveEvent.target && leaveEvent.target !== this.rootTarget.parent; ) leaveEvent.currentTarget = leaveEvent.target,
|
|
89
109
|
this.notifyTarget(leaveEvent), isMouse && this.notifyTarget(leaveEvent, "mouseleave"),
|
|
90
110
|
leaveEvent.target = leaveEvent.target.parent;
|
|
91
111
|
trackingData.overTargets = [], this.freeEvent(outEvent), this.freeEvent(leaveEvent);
|
|
@@ -94,12 +114,13 @@ export class EventManager {
|
|
|
94
114
|
}, this.onPointerUp = (from, target) => {
|
|
95
115
|
var _a;
|
|
96
116
|
if (!(from instanceof FederatedPointerEvent)) return void Logger.getInstance().warn("EventManager cannot map a non-pointer event as a pointer event");
|
|
97
|
-
const now = clock.now(), e = this.createPointerEvent(from, from.type, target);
|
|
98
|
-
if (
|
|
117
|
+
const now = clock.now(), e = this.createPointerEvent(from, from.type, target), trackingData = this.trackingData(from.pointerId);
|
|
118
|
+
if (trackingData.ending = trackingData.pressTargetsByButton[from.button], delete trackingData.pressTargetsByButton[from.button],
|
|
119
|
+
this.dispatchEvent(e, "pointerup"), "touch" === e.pointerType) this.dispatchEvent(e, "touchend"); else if (isMouseLike(e.pointerType)) {
|
|
99
120
|
const isRightButton = 2 === e.button;
|
|
100
121
|
this.dispatchEvent(e, isRightButton ? "rightup" : "mouseup");
|
|
101
122
|
}
|
|
102
|
-
const
|
|
123
|
+
const pressTarget = this.findMountedTarget(trackingData.ending);
|
|
103
124
|
let clickTarget = pressTarget;
|
|
104
125
|
if (pressTarget && !e.composedPath().includes(pressTarget)) {
|
|
105
126
|
let currentTarget = pressTarget;
|
|
@@ -112,7 +133,7 @@ export class EventManager {
|
|
|
112
133
|
}
|
|
113
134
|
delete trackingData.pressTargetsByButton[from.button], clickTarget = currentTarget;
|
|
114
135
|
}
|
|
115
|
-
if (clickTarget) {
|
|
136
|
+
if (this.emitPointerInput(e, "pointerup"), clickTarget && this.inputValid()) {
|
|
116
137
|
const clickEvent = this.clonePointerEvent(e, "click");
|
|
117
138
|
clickEvent.target = clickTarget, clickEvent.path = [], clickEvent.detailPath = [],
|
|
118
139
|
trackingData.clicksByButton[from.button] || (trackingData.clicksByButton[from.button] = {
|
|
@@ -124,14 +145,18 @@ export class EventManager {
|
|
|
124
145
|
clickHistory.target === clickEvent.target && now - clickHistory.timeStamp < (null !== (_a = this._config.clickInterval) && void 0 !== _a ? _a : 200) ? ++clickHistory.clickCount : clickHistory.clickCount = 1,
|
|
125
146
|
clickHistory.target = clickEvent.target, clickHistory.timeStamp = now, clickEvent.detail = clickHistory.clickCount,
|
|
126
147
|
isMouseLike(clickEvent.pointerType) ? (this.dispatchEvent(clickEvent, "click"),
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.
|
|
148
|
+
this.emitInput(clickEvent, "click"), 2 === clickHistory.clickCount && (this.dispatchEvent(clickEvent, "dblclick"),
|
|
149
|
+
this.emitInput(clickEvent, "dblclick"))) : "touch" === clickEvent.pointerType && this._config.supportsTouchEvents && (this.dispatchEvent(clickEvent, "tap"),
|
|
150
|
+
this.emitInput(clickEvent, "tap"), 2 === clickHistory.clickCount && (this.dispatchEvent(clickEvent, "dbltap"),
|
|
151
|
+
this.emitInput(clickEvent, "dbltap"))), this.dispatchEvent(clickEvent, "pointertap"),
|
|
152
|
+
this.emitInput(clickEvent, "pointertap"), this.freeEvent(clickEvent);
|
|
130
153
|
}
|
|
131
154
|
this.freeEvent(e);
|
|
132
155
|
}, this.onPointerUpOutside = (from, target) => {
|
|
133
156
|
if (!(from instanceof FederatedPointerEvent)) return void Logger.getInstance().warn("EventManager cannot map a non-pointer event as a pointer event");
|
|
134
|
-
const trackingData = this.trackingData(from.pointerId)
|
|
157
|
+
const trackingData = this.trackingData(from.pointerId);
|
|
158
|
+
trackingData.ending = trackingData.pressTargetsByButton[from.button], delete trackingData.pressTargetsByButton[from.button];
|
|
159
|
+
const pressTarget = this.findMountedTarget(trackingData.ending), e = this.createPointerEvent(from, from.type, target);
|
|
135
160
|
if (pressTarget) {
|
|
136
161
|
let currentTarget = pressTarget;
|
|
137
162
|
for (;currentTarget; ) e.currentTarget = currentTarget, this.notifyTarget(e, "pointerupoutside"),
|
|
@@ -139,7 +164,7 @@ export class EventManager {
|
|
|
139
164
|
currentTarget = currentTarget.parent;
|
|
140
165
|
delete trackingData.pressTargetsByButton[from.button];
|
|
141
166
|
}
|
|
142
|
-
this.freeEvent(e);
|
|
167
|
+
this.emitPointerInput(e, "pointerup"), this.freeEvent(e);
|
|
143
168
|
}, this.onWheel = (from, target) => {
|
|
144
169
|
if (!(from instanceof FederatedWheelEvent)) return void Logger.getInstance().warn("EventManager cannot map a non-wheel event as a wheel event");
|
|
145
170
|
const wheelEvent = this.createWheelEvent(from, target);
|
|
@@ -149,7 +174,76 @@ export class EventManager {
|
|
|
149
174
|
}, config), this.addEventMapping("pointerdown", this.onPointerDown), this.addEventMapping("pointermove", this.onPointerMove),
|
|
150
175
|
this.addEventMapping("pointerout", this.onPointerOut), this.addEventMapping("pointerleave", this.onPointerOut),
|
|
151
176
|
this.addEventMapping("pointerover", this.onPointerOver), this.addEventMapping("pointerup", this.onPointerUp),
|
|
152
|
-
this.addEventMapping("pointerupoutside", this.onPointerUpOutside), this.addEventMapping("
|
|
177
|
+
this.addEventMapping("pointerupoutside", this.onPointerUpOutside), this.addEventMapping("pointercancel", this.onPointerCancel),
|
|
178
|
+
this.addEventMapping("wheel", this.onWheel);
|
|
179
|
+
}
|
|
180
|
+
hasPointer(id) {
|
|
181
|
+
const data = this.mappingState.trackingData[id];
|
|
182
|
+
if (!data) return !1;
|
|
183
|
+
if (data.inside || data.ending) return !0;
|
|
184
|
+
for (const button in data.pressTargetsByButton) if (data.pressTargetsByButton[button]) return !0;
|
|
185
|
+
return !1;
|
|
186
|
+
}
|
|
187
|
+
cancelAllPointers() {
|
|
188
|
+
for (const id in this.mappingState.trackingData) this.cancelPointer(Number(id));
|
|
189
|
+
}
|
|
190
|
+
cancelPointer(id) {
|
|
191
|
+
var _a;
|
|
192
|
+
if (!this.rootTarget || !this.hasPointer(id)) return;
|
|
193
|
+
const data = this.trackingData(id);
|
|
194
|
+
let press = data.ending;
|
|
195
|
+
for (const button in data.pressTargetsByButton) {
|
|
196
|
+
press = data.pressTargetsByButton[button];
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
const over = data.overTargets, inside = data.inside;
|
|
200
|
+
data.generation++, data.pressTargetsByButton = {}, data.clicksByButton = {}, data.ending = void 0,
|
|
201
|
+
data.inside = !1, data.overTargets = [], this.dispatchingEvent instanceof FederatedPointerEvent && this.dispatchingEvent.pointerId === id && this.dispatchingEvent.stopImmediatePropagation();
|
|
202
|
+
const event = this.allocateEvent(FederatedPointerEvent);
|
|
203
|
+
event.type = "pointercancel", event.pointerId = id, event.pointerType = data.pointerType,
|
|
204
|
+
event.button = data.button, event.nativeEvent = null, event.canvas.x = data.canvasX,
|
|
205
|
+
event.canvas.y = data.canvasY, event.viewport.x = data.viewX, event.viewport.y = data.viewY,
|
|
206
|
+
event.target = null !== (_a = this.findMountedTarget(press)) && void 0 !== _a ? _a : this.findMountedTarget(over),
|
|
207
|
+
this.terminalDepth++;
|
|
208
|
+
try {
|
|
209
|
+
if (this.dispatchEvent(event), "touch" === event.pointerType && this.dispatchEvent(event, "touchcancel"),
|
|
210
|
+
this.windowInput.emit("pointercancel", event, this.inputValid), "touch" === event.pointerType && this.windowInput.emit("touchcancel", event, this.inputValid),
|
|
211
|
+
inside && (this.canvasInput.emit("pointercancel", event, this.inputValid), "touch" === event.pointerType && this.canvasInput.emit("touchcancel", event, this.inputValid),
|
|
212
|
+
this.emitBoundary(event, !1)), (null == over ? void 0 : over.length) && this.rootTarget) for (event.target = this.findMountedTarget(over),
|
|
213
|
+
event.path = [], this.dispatchEvent(event, "pointerout"), isMouseLike(event.pointerType) && this.dispatchEvent(event, "mouseout"),
|
|
214
|
+
event.eventPhase = event.AT_TARGET; event.target && this.rootTarget; ) event.currentTarget = event.target,
|
|
215
|
+
this.notifyTarget(event, "pointerleave"), isMouseLike(event.pointerType) && this.notifyTarget(event, "mouseleave"),
|
|
216
|
+
event.target = event.target.parent;
|
|
217
|
+
} finally {
|
|
218
|
+
this.terminalDepth--, this.freeEvent(event), this.cursorTarget = null, this.cursor = "";
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
emitBoundary(event, inside) {
|
|
222
|
+
this.canvasInput.emit(inside ? "pointerover" : "pointerout", event, this.inputValid),
|
|
223
|
+
this.canvasInput.emit(inside ? "pointerenter" : "pointerleave", event, this.inputValid),
|
|
224
|
+
isMouseLike(event.pointerType) && (this.canvasInput.emit(inside ? "mouseover" : "mouseout", event, this.inputValid),
|
|
225
|
+
this.canvasInput.emit(inside ? "mouseenter" : "mouseleave", event, this.inputValid));
|
|
226
|
+
}
|
|
227
|
+
emitInput(event, type = event.type) {
|
|
228
|
+
if (!this.inputValid()) return;
|
|
229
|
+
if (this.windowInput.emit(type, event, this.inputValid), !this.inputValid()) return;
|
|
230
|
+
const data = event instanceof FederatedPointerEvent ? this.trackingData(event.pointerId) : void 0;
|
|
231
|
+
data && data.previousInside !== data.inside && (data.previousInside = data.inside,
|
|
232
|
+
this.emitBoundary(event, data.inside)), data && !data.inside || this.canvasInput.emit(type, event, this.inputValid);
|
|
233
|
+
}
|
|
234
|
+
emitPointerInput(event, type = event.type) {
|
|
235
|
+
if (this.inputValid()) if ("pointerover" !== type && "pointerout" !== type && "pointerleave" !== type) {
|
|
236
|
+
if (this.emitInput(event, type), "touch" === event.pointerType) {
|
|
237
|
+
const alias = TOUCH_INPUT_TYPES[type];
|
|
238
|
+
alias && this.emitInput(event, alias);
|
|
239
|
+
} else if (isMouseLike(event.pointerType)) {
|
|
240
|
+
const alias = 2 === event.button && "pointerdown" === type ? "rightdown" : 2 === event.button && "pointerup" === type ? "rightup" : MOUSE_INPUT_TYPES[type];
|
|
241
|
+
alias && this.emitInput(event, alias);
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
const data = this.trackingData(event.pointerId);
|
|
245
|
+
data.previousInside !== data.inside && (data.previousInside = data.inside, this.emitBoundary(event, data.inside));
|
|
246
|
+
}
|
|
153
247
|
}
|
|
154
248
|
addEventMapping(type, fn) {
|
|
155
249
|
this.mappingTable[type] || (this.mappingTable[type] = []), this.mappingTable[type].push({
|
|
@@ -158,20 +252,36 @@ export class EventManager {
|
|
|
158
252
|
}), this.mappingTable[type].sort(((a, b) => a.priority - b.priority));
|
|
159
253
|
}
|
|
160
254
|
dispatchEvent(e, type) {
|
|
161
|
-
|
|
162
|
-
|
|
255
|
+
if (!this.inputValid()) return;
|
|
256
|
+
const previous = this.dispatchingEvent;
|
|
257
|
+
this.dispatchingEvent = e, e.propagationStopped = !1, e.propagationImmediatelyStopped = !1;
|
|
258
|
+
try {
|
|
259
|
+
this.propagate(e, type), this.inputValid() && this.dispatch.emit(type || e.type, e);
|
|
260
|
+
} finally {
|
|
261
|
+
this.dispatchingEvent = previous;
|
|
262
|
+
}
|
|
163
263
|
}
|
|
164
|
-
mapEvent(e) {
|
|
165
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
264
|
+
mapEvent(e, inViewport = !0) {
|
|
265
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
166
266
|
if (!this.rootTarget) return;
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
e.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
267
|
+
const previous = this.currentTracking, generation = this.currentGeneration, tracking = e instanceof FederatedPointerEvent ? this.trackingData(e.pointerId) : void 0;
|
|
268
|
+
this.currentTracking = tracking, this.currentGeneration = null !== (_a = null == tracking ? void 0 : tracking.generation) && void 0 !== _a ? _a : 0,
|
|
269
|
+
tracking && (tracking.previousInside = tracking.inside, tracking.inside = inViewport,
|
|
270
|
+
tracking.pointerType = e.pointerType, tracking.button = e.button, tracking.canvasX = e.canvasX,
|
|
271
|
+
tracking.canvasY = e.canvasY, tracking.viewX = e.viewX, tracking.viewY = e.viewY);
|
|
272
|
+
const type = "pointerup" !== e.type || inViewport ? e.type : "pointerupoutside", mappers = this.mappingTable[type];
|
|
273
|
+
try {
|
|
274
|
+
let target;
|
|
275
|
+
const cacheKey = `${e.canvasX}-${e.canvasY}`;
|
|
276
|
+
if (inViewport ? (null === (_b = this._prePointTargetCache) || void 0 === _b ? void 0 : _b[cacheKey]) && (null === (_d = null === (_c = this._prePointTargetCache) || void 0 === _c ? void 0 : _c[cacheKey]) || void 0 === _d ? void 0 : _d.stage) && (null === (_f = null === (_e = this._prePointTargetCache) || void 0 === _e ? void 0 : _e[cacheKey]) || void 0 === _f ? void 0 : _f.stage.renderCount) === (null === (_g = this._prePointTargetCache) || void 0 === _g ? void 0 : _g.stageRenderCount) ? target = this._prePointTargetCache[cacheKey] : (target = this.pickTarget(e.viewX, e.viewY, e),
|
|
277
|
+
e.pickParams || (this._prePointTargetCache = {
|
|
278
|
+
[cacheKey]: target,
|
|
279
|
+
stageRenderCount: null !== (_h = null == target ? void 0 : target.stage.renderCount) && void 0 !== _h ? _h : -1
|
|
280
|
+
})) : target = null, mappers) for (let i = 0, j = mappers.length; i < j && this.inputValid(); i++) mappers[i].fn(e, target); else Logger.getInstance().warn(`[EventManager]: Event mapping not defined for ${e.type}`);
|
|
281
|
+
e instanceof FederatedPointerEvent && "pointerup" !== type && "pointerupoutside" !== type && "pointercancel" !== type ? this.emitPointerInput(e) : e instanceof FederatedWheelEvent && this.emitInput(e);
|
|
282
|
+
} finally {
|
|
283
|
+
tracking && (tracking.ending = void 0), this.currentTracking = previous, this.currentGeneration = generation;
|
|
284
|
+
}
|
|
175
285
|
}
|
|
176
286
|
propagate(e, type) {
|
|
177
287
|
if (!e.target) return;
|
|
@@ -195,10 +305,11 @@ export class EventManager {
|
|
|
195
305
|
return propagationPath.reverse(), propagationPath;
|
|
196
306
|
}
|
|
197
307
|
notifyTarget(e, type) {
|
|
308
|
+
if (!this.inputValid()) return void e.stopImmediatePropagation();
|
|
198
309
|
if (this.pauseNotify) return;
|
|
199
310
|
type = null != type ? type : e.type;
|
|
200
311
|
const key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? `${type}capture` : type;
|
|
201
|
-
this.notifyListeners(e, key), e.eventPhase === e.AT_TARGET && this.notifyListeners(e, type);
|
|
312
|
+
this.notifyListeners(e, key), e.eventPhase === e.AT_TARGET && this.inputValid() && !e.propagationImmediatelyStopped && this.notifyListeners(e, type);
|
|
202
313
|
}
|
|
203
314
|
findMountedTarget(propagationPath) {
|
|
204
315
|
if (!propagationPath) return null;
|
|
@@ -210,7 +321,7 @@ export class EventManager {
|
|
|
210
321
|
var _a, _b;
|
|
211
322
|
const event = this.allocateEvent(FederatedPointerEvent);
|
|
212
323
|
return this.copyPointerData(from, event), this.copyMouseData(from, event), this.copyData(from, event),
|
|
213
|
-
event.nativeEvent = from.nativeEvent, event.originalEvent = from, event.target = target
|
|
324
|
+
event.nativeEvent = from.nativeEvent, event.originalEvent = from, event.target = void 0 !== target ? target : this.pickTarget(null !== (_a = event.viewX) && void 0 !== _a ? _a : event.global.x, null !== (_b = event.viewY) && void 0 !== _b ? _b : event.global.y, event),
|
|
214
325
|
"string" == typeof type && (event.type = type), event;
|
|
215
326
|
}
|
|
216
327
|
createWheelEvent(from, target) {
|
|
@@ -254,6 +365,9 @@ export class EventManager {
|
|
|
254
365
|
}
|
|
255
366
|
trackingData(id) {
|
|
256
367
|
return this.mappingState.trackingData[id] || (this.mappingState.trackingData[id] = {
|
|
368
|
+
generation: 0,
|
|
369
|
+
inside: !1,
|
|
370
|
+
previousInside: !1,
|
|
257
371
|
pressTargetsByButton: {},
|
|
258
372
|
clicksByButton: {},
|
|
259
373
|
overTarget: null
|
|
@@ -268,6 +382,7 @@ export class EventManager {
|
|
|
268
382
|
}
|
|
269
383
|
freeEvent(event) {
|
|
270
384
|
var _a;
|
|
385
|
+
if (event.nativeEvent = null, event.originalEvent = null, !this.rootTarget) return;
|
|
271
386
|
if (event.manager !== this) throw new Error("It is illegal to free an event not managed by this EventManager!");
|
|
272
387
|
const constructor = event.constructor;
|
|
273
388
|
this.eventPool.has(constructor) || (this.eventPool.get(constructor).forEach((e => {
|
|
@@ -276,17 +391,19 @@ export class EventManager {
|
|
|
276
391
|
})), this.eventPool.set(constructor, [])), null === (_a = this.eventPool.get(constructor)) || void 0 === _a || _a.push(event);
|
|
277
392
|
}
|
|
278
393
|
notifyListeners(e, type) {
|
|
394
|
+
if (!this.inputValid() || !e.currentTarget) return;
|
|
279
395
|
const listeners = e.currentTarget._events[type];
|
|
280
396
|
if (listeners) if ("fn" in listeners) listeners.once && e.currentTarget.removeEventListener(type, listeners.fn, {
|
|
281
397
|
once: !0
|
|
282
|
-
}), listeners.fn.call(listeners.context, e); else for (let i = 0, j = listeners.length; i < j && !e.propagationImmediatelyStopped; i++) listeners[i].once && e.currentTarget.removeEventListener(type, listeners[i].fn, {
|
|
398
|
+
}), listeners.fn.call(listeners.context, e); else for (let i = 0, j = listeners.length; i < j && this.inputValid() && !e.propagationImmediatelyStopped; i++) listeners[i].once && e.currentTarget.removeEventListener(type, listeners[i].fn, {
|
|
283
399
|
once: !0
|
|
284
400
|
}), listeners[i].fn.call(listeners[i].context, e);
|
|
285
|
-
this.emitDelegation(e, type);
|
|
401
|
+
this.inputValid() && this.emitDelegation(e, type);
|
|
286
402
|
}
|
|
287
403
|
emitDelegation(e, type) {
|
|
404
|
+
if (!this.inputValid() || !e.currentTarget) return;
|
|
288
405
|
const listeners = e.currentTarget._events[WILDCARD];
|
|
289
|
-
if (listeners) if ("fn" in listeners) listeners.fn.call(listeners.context, e, type); else for (let i = 0, j = listeners.length; i < j && !e.propagationImmediatelyStopped; i++) listeners[i].fn.call(listeners[i].context, e, type);
|
|
406
|
+
if (listeners) if ("fn" in listeners) listeners.fn.call(listeners.context, e, type); else for (let i = 0, j = listeners.length; i < j && this.inputValid() && !e.propagationImmediatelyStopped; i++) listeners[i].fn.call(listeners[i].context, e, type);
|
|
290
407
|
}
|
|
291
408
|
pickTarget(x, y, e) {
|
|
292
409
|
let target;
|
|
@@ -295,8 +412,12 @@ export class EventManager {
|
|
|
295
412
|
e && (e.pickParams = pickResult.params), target;
|
|
296
413
|
}
|
|
297
414
|
release() {
|
|
415
|
+
var _a;
|
|
298
416
|
this.dispatch.removeAllListeners(), this.eventPool.clear(), this.rootTarget = null,
|
|
299
|
-
this.mappingTable = null, this.mappingState =
|
|
417
|
+
this.mappingTable = null, this.mappingState = {
|
|
418
|
+
trackingData: {}
|
|
419
|
+
}, this.canvasInput.clear(), this.windowInput.clear(), null === (_a = this.dispatchingEvent) || void 0 === _a || _a.stopImmediatePropagation(),
|
|
420
|
+
this.cursorTarget = null;
|
|
300
421
|
}
|
|
301
422
|
}
|
|
302
423
|
//# sourceMappingURL=event-manager.js.map
|