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