swf2js 0.1.0 → 0.1.2
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/README.md +9 -9
- package/package.json +3 -2
- package/src/cli.js +15 -6
- package/src/emitter/bundle-emitter.js +56 -16
- package/src/runtime/avm1-runtime.js +329 -84
- package/src/runtime/avm2-runtime.js +56 -6
- package/src/runtime/embedded-movie-runtime.js +6 -1
- package/src/runtime/index.js +2 -6
- package/src/runtime/movie-runtime.js +2 -1
- package/src/runtime/swflib/assemble.js +34 -0
- package/src/runtime/swflib/bitmap-image.js +4 -0
- package/src/runtime/swflib/bitmap.js +1004 -0
- package/src/runtime/swflib/builtins.js +156 -0
- package/src/runtime/swflib/bytearray.js +949 -0
- package/src/runtime/swflib/compiled-swf.js +3 -0
- package/src/runtime/swflib/context-menu.js +245 -0
- package/src/runtime/swflib/cursor-flag.js +12 -0
- package/src/runtime/swflib/dictionary.js +121 -0
- package/src/runtime/swflib/display.js +823 -0
- package/src/runtime/swflib/events.js +754 -0
- package/src/runtime/swflib/filters.js +298 -0
- package/src/runtime/swflib/flash.js +130 -0
- package/src/runtime/swflib/geom.js +759 -0
- package/src/runtime/swflib/glyph-metrics.js +14 -0
- package/src/runtime/swflib/graphics.js +735 -0
- package/src/runtime/swflib/host.js +2 -0
- package/src/runtime/swflib/inherit.js +22 -0
- package/src/runtime/swflib/input.js +1085 -0
- package/src/runtime/swflib/loader.js +687 -0
- package/src/runtime/swflib/marks.js +16 -0
- package/src/runtime/swflib/matrix3d.js +144 -0
- package/src/runtime/swflib/pointer-bridge.js +8 -0
- package/src/runtime/swflib/projection.js +158 -0
- package/src/runtime/swflib/render.js +1240 -0
- package/src/runtime/swflib/sound.js +1166 -0
- package/src/runtime/swflib/sprite-drag.js +116 -0
- package/src/runtime/swflib/stage-ref.js +9 -0
- package/src/runtime/swflib/stage.js +484 -0
- package/src/runtime/swflib/system.js +987 -0
- package/src/runtime/swflib/text-field.js +519 -0
- package/src/runtime/swflib/text-paint.js +797 -0
- package/src/runtime/swflib/text.js +1387 -0
- package/src/runtime/swflib/transform.js +133 -0
- package/src/runtime/swflib/xml.js +268 -0
- package/src/transpiler/avm1/avm1-ir.js +2 -1
- package/src/transpiler/avm1/avm1-rewrite.js +23 -2
- package/src/transpiler/avm1/avm1-transpiler.js +4 -1
- package/src/transpiler/avm2/avm2-transpiler.js +38 -7
- package/src/transpiler/timeline/timeline-codegen.js +366 -123
- package/src/runtime/swflib.js +0 -14050
|
@@ -0,0 +1,1085 @@
|
|
|
1
|
+
import { ContextMenu, openContextMenu } from './context-menu.js';
|
|
2
|
+
import { DisplayObject, InteractiveObject, authoredMaskSources, detachedAuthoredMaskBases, displayMaskOwners, displayMasks, hitAreaOwners, isStageDescendant, pointPassesScrollRect, pointPassesScrollRects } from './display.js';
|
|
3
|
+
import { GestureEvent, GesturePhase, MouseEvent, PressAndTapGestureEvent, TextEvent, TextFieldType, TouchEvent, TouchEventIntent, TransformGestureEvent } from './events.js';
|
|
4
|
+
import { MultitouchInputMode, cancelActiveTouches, mapsPointerToMouse, normalizeFlashWheelDelta, setCancelActiveTouches, touchInputMode } from './filters.js';
|
|
5
|
+
import { Point } from './geom.js';
|
|
6
|
+
import { global } from './host.js';
|
|
7
|
+
import { isSprite } from './marks.js';
|
|
8
|
+
import { pointerBridge } from './pointer-bridge.js';
|
|
9
|
+
import { SimpleButton } from './loader.js';
|
|
10
|
+
import {
|
|
11
|
+
activeCanvasTouches, activeMouseDrag, activeTouchDrag, advanceSpriteDrag, advanceTouchDrag,
|
|
12
|
+
setActiveMouseDrag, setActiveTouchDrag,
|
|
13
|
+
} from './sprite-drag.js';
|
|
14
|
+
import { Mouse, focusCanvasPointerTarget, installStage, mouseCursorTarget, setMouseCursorCanvas, setMouseCursorStageWrap, setMouseCursorTarget, setMovieClipButtonState, stageSingleton, updateMouseCursor } from './stage.js';
|
|
15
|
+
import { URLRequest, navigateToURL } from './system.js';
|
|
16
|
+
import { TextField } from './text-field.js';
|
|
17
|
+
import { scrollCanvasText, scrollCanvasTextHorizontal } from './text-paint.js';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
activeCanvasTouches, activeMouseDrag, activeTouchDrag,
|
|
21
|
+
advanceSpriteDrag, advanceTouchDrag,
|
|
22
|
+
setActiveMouseDrag, setActiveTouchDrag,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export var _buttonCapture = null;
|
|
26
|
+
export var _textLinkCapture = null;
|
|
27
|
+
export var _keyboardButtonCapture = null;
|
|
28
|
+
export var _buttonPointerId = null;
|
|
29
|
+
export var _hoveredButton = null;
|
|
30
|
+
export var canvasAuthoredTarget = null;
|
|
31
|
+
export var stagePrimaryDispatches = new WeakSet();
|
|
32
|
+
export var lastPrimaryClick = null;
|
|
33
|
+
export var canvasAuthoredTouchPick = null;
|
|
34
|
+
export var canvasTimelineOrder = null;
|
|
35
|
+
export var cancelLoadedPointerInput = null;
|
|
36
|
+
export function setKeyboardButtonCapture(value) { _keyboardButtonCapture = value; }
|
|
37
|
+
export function setHoveredButton(value) { _hoveredButton = value; }
|
|
38
|
+
export function setCanvasAuthoredTarget(value) { canvasAuthoredTarget = value; }
|
|
39
|
+
export function setLastPrimaryClick(value) { lastPrimaryClick = value; }
|
|
40
|
+
export function setCanvasAuthoredTouchPick(value) { canvasAuthoredTouchPick = value; }
|
|
41
|
+
export function setCanvasTimelineOrder(value) { canvasTimelineOrder = value; }
|
|
42
|
+
export function hasStagePrimaryDispatch(event) { return stagePrimaryDispatches.has(event); }
|
|
43
|
+
export function cancelPrimaryClickSequence(target) {
|
|
44
|
+
if (lastPrimaryClick?.button === target) setLastPrimaryClick(null);
|
|
45
|
+
}
|
|
46
|
+
export function setCanvasHoveredButton(button, cursorTarget, legacyControl) {
|
|
47
|
+
setHoveredButton(button);
|
|
48
|
+
setMouseCursorTarget(cursorTarget === undefined ? button : cursorTarget, legacyControl);
|
|
49
|
+
}
|
|
50
|
+
export function primaryClickType(button, e) {
|
|
51
|
+
var previous = lastPrimaryClick;
|
|
52
|
+
lastPrimaryClick = null;
|
|
53
|
+
if (e.pointerType === 'touch') return MouseEvent.CLICK;
|
|
54
|
+
var now = Number.isFinite(e.timeStamp) ? e.timeStamp : Date.now();
|
|
55
|
+
// Pointer Events usually have detail=0. Use native MouseEvent counts
|
|
56
|
+
// when provided, and a time and distance threshold for Pointer Events.
|
|
57
|
+
var inSequence = previous && previous.button === button &&
|
|
58
|
+
(e.detail > 0 ? e.detail % 2 === 0 : (
|
|
59
|
+
now >= previous.time && now - previous.time <= 500 &&
|
|
60
|
+
Math.abs(e.clientX - previous.x) <= 4 && Math.abs(e.clientY - previous.y) <= 4
|
|
61
|
+
));
|
|
62
|
+
if (inSequence && button.doubleClickEnabled) return MouseEvent.DOUBLE_CLICK;
|
|
63
|
+
if (!inSequence) lastPrimaryClick = { button: button, time: now, x: e.clientX, y: e.clientY };
|
|
64
|
+
return MouseEvent.CLICK;
|
|
65
|
+
}
|
|
66
|
+
export function buttonHitTest(button, x, y) {
|
|
67
|
+
if (!button || !button.enabled || button.visible === false) return false;
|
|
68
|
+
var target = button.hitTestState || button.upState;
|
|
69
|
+
var local = button.globalToLocal(new Point(x, y));
|
|
70
|
+
var bounds = target && target.graphics && target.graphics.getBounds ? target.graphics.getBounds() : null;
|
|
71
|
+
if (bounds) {
|
|
72
|
+
if (!(local.x >= bounds.x && local.y >= bounds.y && local.x <= bounds.x + bounds.width && local.y <= bounds.y + bounds.height)) return false;
|
|
73
|
+
if (target.graphics.containsPoint && typeof document !== 'undefined' && typeof Path2D !== 'undefined') {
|
|
74
|
+
return target.graphics.containsPoint(local.x, local.y);
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
var w = +button.width || (target && +target.width) || 0;
|
|
79
|
+
var h = +button.height || (target && +target.height) || 0;
|
|
80
|
+
return local.x >= 0 && local.y >= 0 && local.x < w && local.y < h;
|
|
81
|
+
}
|
|
82
|
+
export var bitmapMaskBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
83
|
+
export function bitmapStencilHasPixel(image, x, y, width) {
|
|
84
|
+
var coverage = image._swoofMaskCoverage;
|
|
85
|
+
if (coverage == null) return true;
|
|
86
|
+
if (!coverage) return false;
|
|
87
|
+
var index = Math.floor(y) * width + Math.floor(x);
|
|
88
|
+
var byteIndex = Math.floor(index / 8);
|
|
89
|
+
var byteInGroup = byteIndex % 3;
|
|
90
|
+
var charIndex = Math.floor(byteIndex / 3) * 4 + byteInGroup;
|
|
91
|
+
// Resolve only the bit being queried, with no decoded raster allocation.
|
|
92
|
+
var first = bitmapMaskBase64.indexOf(coverage[charIndex]);
|
|
93
|
+
var second = bitmapMaskBase64.indexOf(coverage[charIndex + 1]);
|
|
94
|
+
if (first < 0 || second < 0) return false;
|
|
95
|
+
var byte = (first << (2 + 2 * byteInGroup)) | (second >> (4 - 2 * byteInGroup));
|
|
96
|
+
return !!(byte & (1 << (index % 8)));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function pointerMaskContains(mask, x, y) {
|
|
100
|
+
if (!mask || mask.visible === false || typeof mask.globalToLocal !== 'function') return false;
|
|
101
|
+
var detached = !mask.parent && detachedAuthoredMaskBases.get(mask);
|
|
102
|
+
if (detached) {
|
|
103
|
+
var parentPoint = detached.inverse.transformPoint(new Point(x, y));
|
|
104
|
+
x = parentPoint.x;
|
|
105
|
+
y = parentPoint.y;
|
|
106
|
+
}
|
|
107
|
+
if (!pointPassesScrollRects(mask, x, y)) return false;
|
|
108
|
+
var authored = authoredMaskSources.get(mask);
|
|
109
|
+
if (authored && authored.contains(mask, x, y)) return true;
|
|
110
|
+
var graphics = mask.graphics, commands = graphics && graphics._cmds;
|
|
111
|
+
if (commands && commands.length) {
|
|
112
|
+
if (commands.some(function (command) { return command.op === 'fill'; })) {
|
|
113
|
+
if (typeof document !== 'undefined' && typeof Path2D !== 'undefined') {
|
|
114
|
+
var local = mask.globalToLocal(new Point(x, y));
|
|
115
|
+
if (graphics.containsPoint(local.x, local.y, null, true)) return true;
|
|
116
|
+
} else if (DisplayObject.prototype.hitTestPoint.call(mask, x, y, false)) return true;
|
|
117
|
+
}
|
|
118
|
+
} else if (!authored?.isBitmap?.(mask) && DisplayObject.prototype.hitTestPoint.call(mask, x, y, true)) return true;
|
|
119
|
+
var children = mask._children || [];
|
|
120
|
+
for (var i = children.length - 1; i >= 0; i--) {
|
|
121
|
+
if (pointerMaskContains(children[i], x, y)) return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
export function pointerPassesOwnMask(node, x, y) {
|
|
126
|
+
var mask = displayMasks.get(node);
|
|
127
|
+
return !displayMaskOwners.has(node) && pointPassesScrollRect(node, x, y) &&
|
|
128
|
+
(!mask || pointerMaskContains(mask, x, y));
|
|
129
|
+
}
|
|
130
|
+
export function pointerPassesDisplayMasks(clip, x, y) {
|
|
131
|
+
for (var node = clip; node; node = node.parent) {
|
|
132
|
+
if (!pointerPassesOwnMask(node, x, y)) return false;
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
export function pointerHitsLinkedChildArtwork(control, x, y) {
|
|
137
|
+
if (!isSprite(control) || control.mouseEnabled === false || control.visible === false) return false;
|
|
138
|
+
for (var parent = control.parent; parent; parent = parent.parent) {
|
|
139
|
+
if (parent.mouseChildren === false || parent.visible === false) return false;
|
|
140
|
+
}
|
|
141
|
+
return control._children.some(function (child) {
|
|
142
|
+
return child.parent === control && child._swoofStandaloneArtworkId && !child._swoofAs3TimelineAttached &&
|
|
143
|
+
child.visible !== false && pointerPassesOwnMask(child, x, y) &&
|
|
144
|
+
(child._swoofTimelinePaintParent !== control || child._swoofTimelinePointerAllowed?.(x, y) !== false) &&
|
|
145
|
+
authoredMaskSources.get(child)?.hitArtwork?.(child, x, y);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
export function timelineAuthoredAbove(authored, candidate, timeline) {
|
|
149
|
+
if (!authored || !candidate) return false;
|
|
150
|
+
for (var branch = candidate; branch?.parent; branch = branch.parent) {
|
|
151
|
+
var parent = branch.parent;
|
|
152
|
+
if (branch._swoofTimelinePaintOwner !== timeline || branch._swoofTimelinePaintParent !== parent) continue;
|
|
153
|
+
for (var other = authored; other?.parent; other = other.parent) {
|
|
154
|
+
if (other.parent !== parent) continue;
|
|
155
|
+
return parent._children.indexOf(other) > parent._children.indexOf(branch);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
var stage = stageSingleton;
|
|
159
|
+
var authoredBranch = authored, candidateBranch = candidate;
|
|
160
|
+
while (authoredBranch?.parent && authoredBranch.parent !== stage) authoredBranch = authoredBranch.parent;
|
|
161
|
+
while (candidateBranch?.parent && candidateBranch.parent !== stage) candidateBranch = candidateBranch.parent;
|
|
162
|
+
var kids = stage?._children;
|
|
163
|
+
if (!kids || authoredBranch?.parent !== stage || candidateBranch?.parent !== stage || authoredBranch === candidateBranch) return false;
|
|
164
|
+
return kids.indexOf(authoredBranch) > kids.indexOf(candidateBranch);
|
|
165
|
+
}
|
|
166
|
+
export function canvasProgrammaticPointerAt(x, y, touch, secondary) {
|
|
167
|
+
var target = topmostPointerTarget(stageSingleton, x, y, false, touch, null, secondary);
|
|
168
|
+
return target && canvasTimelineOrder?.(x, y, touch, target, secondary) ? null : target;
|
|
169
|
+
}
|
|
170
|
+
export function canvasWheelTextAt(x, y, authoredTextContains) {
|
|
171
|
+
var wheelHit = { textContains: authoredTextContains, authoredButton: canvasAuthoredTouchPick?.(x, y, false, 'wheel')?.target };
|
|
172
|
+
var target = topmostPointerTarget(stageSingleton, x, y, false, false, wheelHit, 'wheel');
|
|
173
|
+
return target instanceof TextField ? target : null;
|
|
174
|
+
}
|
|
175
|
+
var embeddedAvm1KeyOwner = null;
|
|
176
|
+
/** Pointer capture for Loader-hosted AVM1 so move/up/wheel continue off the child canvas. */
|
|
177
|
+
var embeddedAvm1PointerCapture = null;
|
|
178
|
+
function embeddedAvm1Hit(node, x, y) {
|
|
179
|
+
if (!node || node.visible === false) return null;
|
|
180
|
+
var kids = node._children;
|
|
181
|
+
if (kids && node.mouseChildren !== false) {
|
|
182
|
+
for (var i = kids.length - 1; i >= 0; i--) {
|
|
183
|
+
var found = embeddedAvm1Hit(kids[i], x, y);
|
|
184
|
+
if (found) return found;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
var embed = node._swoofTimelineCanvas && node._swoofTimelineCanvas._swoofAvm1Embed;
|
|
188
|
+
if (!embed || node.mouseEnabled === false) return null;
|
|
189
|
+
var local = node.globalToLocal(new Point(x, y));
|
|
190
|
+
var canvas = node._swoofTimelineCanvas;
|
|
191
|
+
if (local.x < 0 || local.y < 0 || local.x >= canvas.width || local.y >= canvas.height) return null;
|
|
192
|
+
return { embed: embed, node: node, x: local.x, y: local.y };
|
|
193
|
+
}
|
|
194
|
+
function collectEmbeddedAvm1Embeds(node, out) {
|
|
195
|
+
if (!node || node.visible === false) return out;
|
|
196
|
+
var kids = node._children;
|
|
197
|
+
if (kids) {
|
|
198
|
+
for (var i = 0; i < kids.length; i++) collectEmbeddedAvm1Embeds(kids[i], out);
|
|
199
|
+
}
|
|
200
|
+
var embed = node._swoofTimelineCanvas && node._swoofTimelineCanvas._swoofAvm1Embed;
|
|
201
|
+
if (embed && node.mouseEnabled !== false) out.push(embed);
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
/** Last clicked embed, else the sole visible AVM1 embed on stage (title Space before click). */
|
|
205
|
+
export function resolveEmbeddedAvm1KeyOwner() {
|
|
206
|
+
if (embeddedAvm1KeyOwner) return embeddedAvm1KeyOwner;
|
|
207
|
+
var embeds = collectEmbeddedAvm1Embeds(stageSingleton, []);
|
|
208
|
+
return embeds.length === 1 ? embeds[0] : null;
|
|
209
|
+
}
|
|
210
|
+
function localPointOnEmbedNode(node, x, y) {
|
|
211
|
+
var local = node.globalToLocal(new Point(x, y));
|
|
212
|
+
return { x: local.x, y: local.y };
|
|
213
|
+
}
|
|
214
|
+
function dispatchEmbeddedAvm1(type, x, y, event, extra) {
|
|
215
|
+
var hit = embeddedAvm1Hit(stageSingleton, x, y);
|
|
216
|
+
if (type === 'down') {
|
|
217
|
+
embeddedAvm1KeyOwner = hit ? hit.embed : null;
|
|
218
|
+
embeddedAvm1PointerCapture = hit ? { embed: hit.embed, node: hit.node } : null;
|
|
219
|
+
} else if (type === 'move' && hit) {
|
|
220
|
+
embeddedAvm1KeyOwner = hit.embed;
|
|
221
|
+
}
|
|
222
|
+
if (!hit && embeddedAvm1PointerCapture && (type === 'move' || type === 'up')) {
|
|
223
|
+
var captured = embeddedAvm1PointerCapture;
|
|
224
|
+
var local = localPointOnEmbedNode(captured.node, x, y);
|
|
225
|
+
captured.embed[type](local.x, local.y, event, extra);
|
|
226
|
+
if (type === 'up') embeddedAvm1PointerCapture = null;
|
|
227
|
+
return { embed: captured.embed, node: captured.node, x: local.x, y: local.y };
|
|
228
|
+
}
|
|
229
|
+
if (type === 'up' || (type === 'down' && !hit)) {
|
|
230
|
+
if (type === 'up') embeddedAvm1PointerCapture = null;
|
|
231
|
+
}
|
|
232
|
+
if (!hit) return null;
|
|
233
|
+
hit.embed[type](hit.x, hit.y, event, extra);
|
|
234
|
+
return hit;
|
|
235
|
+
}
|
|
236
|
+
export function dispatchEmbeddedAvm1Key(type, event) {
|
|
237
|
+
var embed = resolveEmbeddedAvm1KeyOwner();
|
|
238
|
+
if (embed && embed[type]) embed[type](event);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Flash InteractiveObject.hitArea: geometry hits even when the Sprite is invisible
|
|
242
|
+
* or off the display list; hitTestPoint alone rejects visible === false.
|
|
243
|
+
*/
|
|
244
|
+
export function pointerHitsAssignedHitArea(area, x, y) {
|
|
245
|
+
if (!area || !isSprite(area)) return false;
|
|
246
|
+
var stack = [area], saved = [];
|
|
247
|
+
while (stack.length) {
|
|
248
|
+
var node = stack.pop();
|
|
249
|
+
if (!node) continue;
|
|
250
|
+
saved.push(node, node.visible);
|
|
251
|
+
node.visible = true;
|
|
252
|
+
var kids = node._children;
|
|
253
|
+
if (kids) for (var i = 0; i < kids.length; i++) stack.push(kids[i]);
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
return !!area.hitTestPoint(x, y, true);
|
|
257
|
+
} catch (_) {
|
|
258
|
+
return false;
|
|
259
|
+
} finally {
|
|
260
|
+
for (var j = 0; j < saved.length; j += 2) saved[j].visible = saved[j + 1];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
export function topmostPointerTarget(node, x, y, contextMenu, touch, wheelHit, secondary) {
|
|
264
|
+
if (!node || node.visible === false || !pointerPassesOwnMask(node, x, y)) return null;
|
|
265
|
+
// Flash: a Sprite used as another object's hitArea does not receive mouse events.
|
|
266
|
+
if (hitAreaOwners.has(node)) return null;
|
|
267
|
+
if (node._swoofTimelinePaintParent === node.parent && node._swoofTimelinePointerAllowed?.(x, y) === false) return null;
|
|
268
|
+
var kids = node._children;
|
|
269
|
+
var embedded = !contextMenu && node.mouseChildren !== false && node._swoofTimelineCanvas;
|
|
270
|
+
var found = null;
|
|
271
|
+
if (kids && node.mouseChildren !== false) {
|
|
272
|
+
for (var i = kids.length - 1; i >= 0; i--) {
|
|
273
|
+
found = topmostPointerTarget(kids[i], x, y, contextMenu, touch, wheelHit, secondary);
|
|
274
|
+
if (found) break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (embedded) {
|
|
278
|
+
var stagePoint = new Point(x, y);
|
|
279
|
+
var local = node.globalToLocal(stagePoint);
|
|
280
|
+
var authored = node._swoofTimeline?.pickAuthoredPointer?.(local.x, local.y, touch, stagePoint, secondary);
|
|
281
|
+
if (authored && isStageDescendant(node, authored) &&
|
|
282
|
+
(!found || timelineAuthoredAbove(authored, found, node._swoofTimeline))) return authored;
|
|
283
|
+
}
|
|
284
|
+
if (!contextMenu && node._swoofStandaloneArtworkId) {
|
|
285
|
+
var linked = authoredMaskSources.get(node)?.pickStandalonePointer?.(node, x, y, touch, secondary);
|
|
286
|
+
if (linked && (!found || timelineAuthoredAbove(linked.target, found, linked.timeline))) return linked.target;
|
|
287
|
+
}
|
|
288
|
+
if (found) return found;
|
|
289
|
+
if (!node.mouseEnabled) return null;
|
|
290
|
+
if (node._hitArea && isSprite(node._hitArea)) {
|
|
291
|
+
return pointerHitsAssignedHitArea(node._hitArea, x, y) ? node : null;
|
|
292
|
+
}
|
|
293
|
+
if (!contextMenu && canvasAuthoredTarget?.(node)) return wheelHit?.authoredButton === node ? node : null;
|
|
294
|
+
if (wheelHit && node instanceof TextField && node.type === TextFieldType.DYNAMIC &&
|
|
295
|
+
node.selectable !== false && (node.multiline || !node.wordWrap) &&
|
|
296
|
+
((typeof wheelHit.textContains === 'function' ? wheelHit.textContains(node, x, y) : null)
|
|
297
|
+
?? node.hitTestPoint(x, y, false))) return node;
|
|
298
|
+
if (contextMenu) {
|
|
299
|
+
var source = authoredMaskSources.get(node);
|
|
300
|
+
if (source && source.contains(node, x, y)) return node;
|
|
301
|
+
if (node instanceof TextField && node.selectable !== false && node.hitTestPoint(x, y, false)) return node;
|
|
302
|
+
}
|
|
303
|
+
if (node instanceof SimpleButton) return buttonHitTest(node, x, y) ? node : null;
|
|
304
|
+
if (isSprite(node) && !node._swoofHostTimeline) {
|
|
305
|
+
if (node.graphics && node.graphics._cmds.length &&
|
|
306
|
+
DisplayObject.prototype.hitTestPoint.call(node, x, y, true)) return node;
|
|
307
|
+
// Linked SymbolClass skins reuse the authored overlay helper.
|
|
308
|
+
if (pointerHitsLinkedChildArtwork(node, x, y)) return node;
|
|
309
|
+
// Shape skins and mouseEnabled=false children never win the InteractiveObject walk,
|
|
310
|
+
// but their geometry still belongs to this Sprite's hit area.
|
|
311
|
+
if (kids) {
|
|
312
|
+
for (var si = kids.length - 1; si >= 0; si--) {
|
|
313
|
+
var skin = kids[si];
|
|
314
|
+
if (!skin || skin.visible === false || displayMaskOwners.has(skin)) continue;
|
|
315
|
+
if (skin instanceof InteractiveObject && skin.mouseEnabled !== false) continue;
|
|
316
|
+
if (skin.hitTestPoint(x, y, true)) return node;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
export function dispatchButtonEvent(button, type, x, y, nativeEvent, relatedObject, delta) {
|
|
323
|
+
if (!button) return;
|
|
324
|
+
var point = button.globalToLocal(new Point(x, y));
|
|
325
|
+
var source = nativeEvent || {};
|
|
326
|
+
var bubbles = type !== MouseEvent.ROLL_OVER && type !== MouseEvent.ROLL_OUT;
|
|
327
|
+
var buttonDown = type === MouseEvent.MOUSE_DOWN || type === MouseEvent.MIDDLE_MOUSE_DOWN || type === MouseEvent.RIGHT_MOUSE_DOWN;
|
|
328
|
+
if (type === MouseEvent.MOUSE_MOVE || type === MouseEvent.MOUSE_OVER || type === MouseEvent.MOUSE_OUT ||
|
|
329
|
+
type === MouseEvent.ROLL_OVER || type === MouseEvent.ROLL_OUT ||
|
|
330
|
+
type === MouseEvent.MOUSE_WHEEL || type === MouseEvent.MOUSE_WHEEL_HORIZONTAL) {
|
|
331
|
+
buttonDown = !!(source.buttons & 1);
|
|
332
|
+
}
|
|
333
|
+
var event = new MouseEvent(type, bubbles, false, point.x, point.y, relatedObject,
|
|
334
|
+
source.ctrlKey || source.metaKey, source.altKey, source.shiftKey, buttonDown, delta || 0,
|
|
335
|
+
source.metaKey, source.ctrlKey, source.detail);
|
|
336
|
+
event.stageX = x; event.stageY = y;
|
|
337
|
+
try { button.dispatchEvent(event); } catch (_) {}
|
|
338
|
+
}
|
|
339
|
+
export function topmostTextLinkAt(node, x, y) {
|
|
340
|
+
if (!node || node.visible === false || !pointerPassesOwnMask(node, x, y)) return null;
|
|
341
|
+
var kids = node._children;
|
|
342
|
+
if (kids && node.mouseChildren !== false) {
|
|
343
|
+
for (var i = kids.length - 1; i >= 0; i--) {
|
|
344
|
+
var found = topmostTextLinkAt(kids[i], x, y);
|
|
345
|
+
if (found) return found;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (!(node instanceof TextField) || node.mouseEnabled === false || !node._swoofLinkRegions || !node._swoofLinkRegions.length) return null;
|
|
349
|
+
var local = node.globalToLocal(new Point(x, y));
|
|
350
|
+
for (var ri = node._swoofLinkRegions.length - 1; ri >= 0; ri--) {
|
|
351
|
+
var region = node._swoofLinkRegions[ri];
|
|
352
|
+
if (local.x >= region.x && local.y >= region.y && local.x < region.x + region.width && local.y < region.y + region.height) {
|
|
353
|
+
return { field: node, region: region };
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
export function activateTextLink(hit) {
|
|
359
|
+
if (!hit || !hit.field || !hit.region) return false;
|
|
360
|
+
var href = String(hit.region.href || '');
|
|
361
|
+
if (!href) return false;
|
|
362
|
+
if (/^event:/i.test(href)) {
|
|
363
|
+
var event = new TextEvent(TextEvent.LINK, true, false, href.slice(href.indexOf(':') + 1));
|
|
364
|
+
try { hit.field.dispatchEvent(event); } catch (_) {}
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
try { navigateToURL(new URLRequest(href), hit.region.target || '_blank'); } catch (_) {}
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
export function dispatchButtonRoll(target, type, x, y, nativeEvent, relatedObject) {
|
|
371
|
+
var relatedAncestors = new Set();
|
|
372
|
+
for (var node = relatedObject; node; node = node.parent) relatedAncestors.add(node);
|
|
373
|
+
var chain = [];
|
|
374
|
+
for (var current = target; current && current !== stageSingleton && !relatedAncestors.has(current); current = current.parent) {
|
|
375
|
+
chain.push(current);
|
|
376
|
+
}
|
|
377
|
+
// Enter from the outside in. Leave from the target back out.
|
|
378
|
+
if (type === MouseEvent.ROLL_OVER) chain.reverse();
|
|
379
|
+
for (var i = 0; i < chain.length; i++) dispatchButtonEvent(chain[i], type, x, y, nativeEvent, relatedObject);
|
|
380
|
+
}
|
|
381
|
+
export function updateButtonHover(next, x, y, nativeEvent, reportMove) {
|
|
382
|
+
if (canvasAuthoredTarget) { _hoveredButton = next; return next; }
|
|
383
|
+
setMouseCursorTarget(nativeEvent?.pointerType === 'touch' ? null : next);
|
|
384
|
+
if (next === _hoveredButton) {
|
|
385
|
+
if (reportMove) dispatchButtonEvent(next, MouseEvent.MOUSE_MOVE, x, y, nativeEvent);
|
|
386
|
+
return next;
|
|
387
|
+
}
|
|
388
|
+
var previous = _hoveredButton;
|
|
389
|
+
_hoveredButton = next;
|
|
390
|
+
dispatchButtonEvent(previous, MouseEvent.MOUSE_OUT, x, y, nativeEvent, next);
|
|
391
|
+
dispatchButtonRoll(previous, MouseEvent.ROLL_OUT, x, y, nativeEvent, next);
|
|
392
|
+
dispatchButtonRoll(next, MouseEvent.ROLL_OVER, x, y, nativeEvent, previous);
|
|
393
|
+
dispatchButtonEvent(next, MouseEvent.MOUSE_OVER, x, y, nativeEvent, previous);
|
|
394
|
+
return next;
|
|
395
|
+
}
|
|
396
|
+
export function bindStagePointer() {
|
|
397
|
+
if (typeof document === 'undefined' || bindStagePointer.bound) return;
|
|
398
|
+
bindStagePointer.bound = true;
|
|
399
|
+
var _bindMouse = function () {
|
|
400
|
+
installStage();
|
|
401
|
+
var canvas = document.getElementById('stage');
|
|
402
|
+
if (!canvas) return;
|
|
403
|
+
setMouseCursorCanvas(canvas);
|
|
404
|
+
setMouseCursorStageWrap(document.getElementById('stage-wrap'));
|
|
405
|
+
updateMouseCursor();
|
|
406
|
+
if (canvas.tabIndex == null || canvas.tabIndex < 0) canvas.tabIndex = 0;
|
|
407
|
+
if (canvas.style) canvas.style.touchAction = 'none';
|
|
408
|
+
var secondaryCaptures = [];
|
|
409
|
+
var secondaryEvents = [
|
|
410
|
+
null,
|
|
411
|
+
[MouseEvent.MIDDLE_MOUSE_DOWN, MouseEvent.MIDDLE_MOUSE_UP, MouseEvent.MIDDLE_CLICK],
|
|
412
|
+
[MouseEvent.RIGHT_MOUSE_DOWN, MouseEvent.RIGHT_MOUSE_UP, MouseEvent.RIGHT_CLICK],
|
|
413
|
+
];
|
|
414
|
+
var stagePrimaryPressed = false;
|
|
415
|
+
function sampleStageMousePosition(e) {
|
|
416
|
+
var rect = canvas.getBoundingClientRect();
|
|
417
|
+
var sx = canvas.width / Math.max(1, rect.width);
|
|
418
|
+
var sy = canvas.height / Math.max(1, rect.height);
|
|
419
|
+
stageSingleton._mouseX = (e.clientX - rect.left) * sx;
|
|
420
|
+
stageSingleton._mouseY = (e.clientY - rect.top) * sy;
|
|
421
|
+
}
|
|
422
|
+
canvas._swoofStageTextPointerPosition = function (e, field) {
|
|
423
|
+
if (e.isPrimary === false || !mapsPointerToMouse(e)) return;
|
|
424
|
+
sampleStageMousePosition(e);
|
|
425
|
+
if ((e.type === 'pointermove' || e.type === 'mousemove') && field?.mouseEnabled !== false &&
|
|
426
|
+
isStageDescendant(stageSingleton, field) && field.willTrigger?.(MouseEvent.MOUSE_MOVE)) {
|
|
427
|
+
dispatchButtonEvent(field, MouseEvent.MOUSE_MOVE, stageSingleton.mouseX, stageSingleton.mouseY, e);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
var update = function (e) {
|
|
431
|
+
sampleStageMousePosition(e);
|
|
432
|
+
Mouse._isDown = !!(e.buttons & 1);
|
|
433
|
+
};
|
|
434
|
+
var containsCanvasPoint = function (x, y) {
|
|
435
|
+
return x >= 0 && x < canvas.width && y >= 0 && y < canvas.height;
|
|
436
|
+
};
|
|
437
|
+
var hitButton = function (x, y, touch, secondary) {
|
|
438
|
+
return containsCanvasPoint(x, y) ? canvasProgrammaticPointerAt(x, y, touch, secondary) : null;
|
|
439
|
+
};
|
|
440
|
+
function isBlankPrimaryPoint(x, y) {
|
|
441
|
+
return !canvas._swoofAvm1Pointer && containsCanvasPoint(x, y) && !canvasAuthoredTouchPick?.(x, y, false);
|
|
442
|
+
}
|
|
443
|
+
function dispatchBlankPrimary(type, x, y, e) {
|
|
444
|
+
stagePrimaryDispatches.add(e);
|
|
445
|
+
if (stageSingleton.hasEventListener(type)) dispatchButtonEvent(stageSingleton, type, x, y, e);
|
|
446
|
+
}
|
|
447
|
+
function secondaryPointerTarget(x, y, secondary) {
|
|
448
|
+
var hit = hitButton(x, y, false, secondary);
|
|
449
|
+
if (hit || canvas._swoofAvm1Pointer || !containsCanvasPoint(x, y)) return hit;
|
|
450
|
+
var authored = canvasAuthoredTouchPick?.(x, y, false, secondary)?.target;
|
|
451
|
+
return isStageDescendant(stageSingleton, authored) ? authored : stageSingleton;
|
|
452
|
+
}
|
|
453
|
+
var touches = activeCanvasTouches;
|
|
454
|
+
var gesture = null;
|
|
455
|
+
var pendingGestureTap = null;
|
|
456
|
+
function pickTouch(x, y, fixed) {
|
|
457
|
+
var target = fixed || hitButton(x, y, true);
|
|
458
|
+
var authored = target ? null : canvasAuthoredTouchPick?.(x, y);
|
|
459
|
+
target = target || authored?.target || stageSingleton;
|
|
460
|
+
return { target: target, local: authored?.local || target.globalToLocal(new Point(x, y)) };
|
|
461
|
+
}
|
|
462
|
+
function gestureSample(first, second) {
|
|
463
|
+
return { x: (first.x + second.x) / 2, y: (first.y + second.y) / 2,
|
|
464
|
+
distance: Math.hypot(second.x - first.x, second.y - first.y),
|
|
465
|
+
angle: Math.atan2(second.y - first.y, second.x - first.x) };
|
|
466
|
+
}
|
|
467
|
+
function dispatchGesture(active, type, phase, sample, scale, rotation, dx, dy, source) {
|
|
468
|
+
var local = active.target.globalToLocal(new Point(sample.x, sample.y));
|
|
469
|
+
var event = new TransformGestureEvent(type, true, false, phase, local.x, local.y, scale, scale, rotation, dx, dy,
|
|
470
|
+
source.ctrlKey || source.metaKey, source.altKey, source.shiftKey, source.metaKey, source.ctrlKey);
|
|
471
|
+
event._stagePoint = new Point(sample.x, sample.y);
|
|
472
|
+
try { active.target.dispatchEvent(event); } catch (_) {}
|
|
473
|
+
}
|
|
474
|
+
function endGesture() {
|
|
475
|
+
var active = gesture;
|
|
476
|
+
if (!active) return;
|
|
477
|
+
gesture = null;
|
|
478
|
+
for (var type of active.types) {
|
|
479
|
+
dispatchGesture(active, type, GesturePhase.END, active.sample, 1, 0, 0, 0, active.source);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function gestureEventTime(event) {
|
|
483
|
+
return Number.isFinite(event.timeStamp) ? event.timeStamp : Date.now();
|
|
484
|
+
}
|
|
485
|
+
function gestureTapMoved(contact) {
|
|
486
|
+
return Math.hypot(contact.event.clientX - contact.gestureStart.clientX,
|
|
487
|
+
contact.event.clientY - contact.gestureStart.clientY) > 3;
|
|
488
|
+
}
|
|
489
|
+
function dispatchGestureSwipe(contact) {
|
|
490
|
+
if (contact.swipeBlocked || !isStageDescendant(stageSingleton, contact.origin)) return;
|
|
491
|
+
var start = contact.gestureStart, source = contact.event;
|
|
492
|
+
var elapsed = gestureEventTime(source) - gestureEventTime(start);
|
|
493
|
+
if (elapsed <= 0 || elapsed > 500) return;
|
|
494
|
+
var dx = source.clientX - start.clientX, dy = source.clientY - start.clientY;
|
|
495
|
+
var horizontal = Math.abs(dx) >= 40 && Math.abs(dx) >= Math.abs(dy) * 1.5;
|
|
496
|
+
var vertical = Math.abs(dy) >= 40 && Math.abs(dy) >= Math.abs(dx) * 1.5;
|
|
497
|
+
if (!horizontal && !vertical) return;
|
|
498
|
+
var point = new Point(contact.x, contact.y);
|
|
499
|
+
var local = contact.origin.globalToLocal(point);
|
|
500
|
+
var speed = Math.hypot(dx * contact.scaleX, dy * contact.scaleY) * 1000 / elapsed;
|
|
501
|
+
var event = new TransformGestureEvent(TransformGestureEvent.GESTURE_SWIPE, true, false, GesturePhase.ALL,
|
|
502
|
+
local.x, local.y, 1, 1, 0, horizontal ? Math.sign(dx) : 0, vertical ? Math.sign(dy) : 0,
|
|
503
|
+
source.ctrlKey || source.metaKey, source.altKey, source.shiftKey, source.metaKey, source.ctrlKey, speed);
|
|
504
|
+
event._stagePoint = point;
|
|
505
|
+
try { contact.origin.dispatchEvent(event); } catch (_) {}
|
|
506
|
+
}
|
|
507
|
+
function updateGestureTap(type, contact, canceled) {
|
|
508
|
+
var tap = pendingGestureTap;
|
|
509
|
+
if (!tap || !tap.pair.includes(contact)) return false;
|
|
510
|
+
var elapsed = gestureEventTime(contact.event) - tap.startTime;
|
|
511
|
+
if (canceled || elapsed < 0 || elapsed > (tap.press ? 350 : 500) || gestureTapMoved(contact) ||
|
|
512
|
+
!isStageDescendant(stageSingleton, tap.target)) {
|
|
513
|
+
pendingGestureTap = null;
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
if (type !== TouchEvent.TOUCH_END) return true;
|
|
517
|
+
if (!tap.press && ++tap.released < 2) return false;
|
|
518
|
+
pendingGestureTap = null;
|
|
519
|
+
if (tap.press && contact === tap.pair[0]) return false;
|
|
520
|
+
var sample = tap.press ? tap.pair[0] : gestureSample(tap.pair[0], tap.pair[1]);
|
|
521
|
+
var local = tap.target.globalToLocal(new Point(sample.x, sample.y));
|
|
522
|
+
var source = contact.event;
|
|
523
|
+
var event;
|
|
524
|
+
if (tap.press) {
|
|
525
|
+
var tapPoint = new Point(contact.x, contact.y);
|
|
526
|
+
var tapLocal = tap.target.globalToLocal(tapPoint);
|
|
527
|
+
event = new PressAndTapGestureEvent(PressAndTapGestureEvent.GESTURE_PRESS_AND_TAP, true, false,
|
|
528
|
+
GesturePhase.ALL, local.x, local.y, tapLocal.x, tapLocal.y,
|
|
529
|
+
source.ctrlKey || source.metaKey, source.altKey, source.shiftKey, source.metaKey, source.ctrlKey);
|
|
530
|
+
event._tapStagePoint = tapPoint;
|
|
531
|
+
} else {
|
|
532
|
+
event = new GestureEvent(GestureEvent.GESTURE_TWO_FINGER_TAP, true, false, GesturePhase.ALL, local.x, local.y,
|
|
533
|
+
source.ctrlKey || source.metaKey, source.altKey, source.shiftKey, source.metaKey, source.ctrlKey);
|
|
534
|
+
}
|
|
535
|
+
event._stagePoint = new Point(sample.x, sample.y);
|
|
536
|
+
try { tap.target.dispatchEvent(event); } catch (_) {}
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
function routeGesture(type, contact, canceled) {
|
|
540
|
+
if (type === TouchEvent.TOUCH_BEGIN) {
|
|
541
|
+
contact.origin = pickTouch(contact.x, contact.y).target;
|
|
542
|
+
contact.gestureStart = contact.event;
|
|
543
|
+
pendingGestureTap = null;
|
|
544
|
+
if (touches.size > 1) {
|
|
545
|
+
for (var activeContact of touches.values()) activeContact.swipeBlocked = true;
|
|
546
|
+
}
|
|
547
|
+
if (gesture || touches.size < 2) return;
|
|
548
|
+
var pair = Array.from(touches.values()).slice(0, 2);
|
|
549
|
+
var target = pair[0].origin;
|
|
550
|
+
while (target && !isStageDescendant(target, pair[1].origin)) target = target.parent;
|
|
551
|
+
gesture = { pair: pair, target: target || stageSingleton, sample: gestureSample(pair[0], pair[1]),
|
|
552
|
+
source: contact.event, types: new Set() };
|
|
553
|
+
var startTime = gestureEventTime(pair[0].gestureStart);
|
|
554
|
+
var secondStart = gestureEventTime(contact.gestureStart);
|
|
555
|
+
var separation = secondStart - startTime;
|
|
556
|
+
var press = separation >= 300;
|
|
557
|
+
if (touches.size === 2 && (press || separation >= 0 && separation <= 150) &&
|
|
558
|
+
!pair.some(function (point) { return point.gestureMoved || gestureTapMoved(point); })) {
|
|
559
|
+
pendingGestureTap = { pair: pair, startTime: press ? secondStart : startTime,
|
|
560
|
+
target: gesture.target, released: 0, press: press };
|
|
561
|
+
}
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
if (type === TouchEvent.TOUCH_MOVE && gestureTapMoved(contact)) contact.gestureMoved = true;
|
|
565
|
+
if (type === TouchEvent.TOUCH_END && !canceled) dispatchGestureSwipe(contact);
|
|
566
|
+
if (updateGestureTap(type, contact, canceled)) return;
|
|
567
|
+
var active = gesture;
|
|
568
|
+
if (!active?.pair.includes(contact)) return;
|
|
569
|
+
if (type === TouchEvent.TOUCH_END || !isStageDescendant(stageSingleton, active.target)) {
|
|
570
|
+
endGesture();
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
var next = gestureSample(active.pair[0], active.pair[1]);
|
|
574
|
+
var previous = active.sample;
|
|
575
|
+
var scale = previous.distance && next.distance ? next.distance / previous.distance : 1;
|
|
576
|
+
var angle = next.angle - previous.angle;
|
|
577
|
+
var rotation = previous.distance && next.distance ? Math.atan2(Math.sin(angle), Math.cos(angle)) * 180 / Math.PI : 0;
|
|
578
|
+
var dx = next.x - previous.x, dy = next.y - previous.y;
|
|
579
|
+
active.sample = next;
|
|
580
|
+
active.source = contact.event;
|
|
581
|
+
function emit(type, changed, scale, rotation, dx, dy) {
|
|
582
|
+
if (!changed || gesture !== active) return;
|
|
583
|
+
var phase = active.types.has(type) ? GesturePhase.UPDATE : GesturePhase.BEGIN;
|
|
584
|
+
active.types.add(type);
|
|
585
|
+
dispatchGesture(active, type, phase, next, scale, rotation, dx, dy, contact.event);
|
|
586
|
+
}
|
|
587
|
+
emit(TransformGestureEvent.GESTURE_PAN, !!(dx || dy), 1, 0, dx, dy);
|
|
588
|
+
emit(TransformGestureEvent.GESTURE_ZOOM, Math.abs(scale - 1) > 1e-9, scale, 0, 0, 0);
|
|
589
|
+
emit(TransformGestureEvent.GESTURE_ROTATE, Math.abs(rotation) > 1e-9, 1, rotation, 0, 0);
|
|
590
|
+
}
|
|
591
|
+
function touchPressure(source) {
|
|
592
|
+
return Number.isFinite(source.pressure) ? Math.max(0, Math.min(1, source.pressure)) : 1;
|
|
593
|
+
}
|
|
594
|
+
function collectTouchSamples(contact, touch) {
|
|
595
|
+
var e = contact.event, events = [];
|
|
596
|
+
try { events = e.getCoalescedEvents?.() || []; } catch (_) {}
|
|
597
|
+
var values = [];
|
|
598
|
+
for (var sample of events) {
|
|
599
|
+
if ((sample.pointerId != null && sample.pointerId !== e.pointerId) ||
|
|
600
|
+
!Number.isFinite(sample.clientX) || !Number.isFinite(sample.clientY)) continue;
|
|
601
|
+
values.push((sample.clientX - contact.left) * contact.scaleX,
|
|
602
|
+
(sample.clientY - contact.top) * contact.scaleY, touchPressure(sample));
|
|
603
|
+
}
|
|
604
|
+
var final = values.length - 3;
|
|
605
|
+
if (final < 0 || values[final] !== contact.x || values[final + 1] !== contact.y || values[final + 2] !== touch.pressure) {
|
|
606
|
+
values.push(contact.x, contact.y, touch.pressure);
|
|
607
|
+
}
|
|
608
|
+
return new Float32Array(values);
|
|
609
|
+
}
|
|
610
|
+
function touchBubbles(type) {
|
|
611
|
+
return type !== TouchEvent.TOUCH_ROLL_OVER && type !== TouchEvent.TOUCH_ROLL_OUT &&
|
|
612
|
+
type !== TouchEvent.PROXIMITY_OVER && type !== TouchEvent.PROXIMITY_OUT;
|
|
613
|
+
}
|
|
614
|
+
var proximities = new Map();
|
|
615
|
+
function emitTouch(type, contact, picked, related, canceled) {
|
|
616
|
+
var e = contact.event;
|
|
617
|
+
var target = picked.target, local = picked.local;
|
|
618
|
+
var touch = new TouchEvent(type, touchBubbles(type), false, e.pointerId, contact.primary,
|
|
619
|
+
local.x, local.y, e.width * contact.scaleX, e.height * contact.scaleY, touchPressure(e), related,
|
|
620
|
+
e.ctrlKey || e.metaKey, e.altKey, e.shiftKey, e.metaKey, e.ctrlKey, e.timeStamp, contact.intent, null, canceled);
|
|
621
|
+
touch._stagePoint = new Point(contact.x, contact.y);
|
|
622
|
+
if (type === TouchEvent.TOUCH_MOVE || type === TouchEvent.PROXIMITY_MOVE) {
|
|
623
|
+
touch._touchSamples = collectTouchSamples(contact, touch);
|
|
624
|
+
}
|
|
625
|
+
try { target.dispatchEvent(touch); } catch (_) {}
|
|
626
|
+
}
|
|
627
|
+
function emitTouchRoll(type, contact, start, related, expected) {
|
|
628
|
+
var blocked = new Set();
|
|
629
|
+
for (var node = related; node; node = node.parent) blocked.add(node);
|
|
630
|
+
var chain = [];
|
|
631
|
+
for (var current = start; current && current !== stageSingleton && !blocked.has(current); current = current.parent) {
|
|
632
|
+
chain.push(current);
|
|
633
|
+
}
|
|
634
|
+
if (type === TouchEvent.TOUCH_ROLL_OVER) chain.reverse();
|
|
635
|
+
for (var i = 0; i < chain.length; i++) {
|
|
636
|
+
if (contact.target !== expected) return;
|
|
637
|
+
var current = chain[i];
|
|
638
|
+
var local = current.globalToLocal ? current.globalToLocal(new Point(contact.x, contact.y)) : { x: contact.x, y: contact.y };
|
|
639
|
+
emitTouch(type, contact, { target: current, local: local }, related);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function transitionTouch(contact, next) {
|
|
643
|
+
var previous = contact.target;
|
|
644
|
+
var target = next?.target || null;
|
|
645
|
+
if (previous === target) return;
|
|
646
|
+
contact.target = target;
|
|
647
|
+
if (previous) {
|
|
648
|
+
var leaving = pickTouch(contact.x, contact.y, previous);
|
|
649
|
+
emitTouch(TouchEvent.TOUCH_OUT, contact, leaving, target);
|
|
650
|
+
if (contact.target !== target) return;
|
|
651
|
+
emitTouchRoll(TouchEvent.TOUCH_ROLL_OUT, contact, previous, target, target);
|
|
652
|
+
}
|
|
653
|
+
if (next && contact.target === target) {
|
|
654
|
+
emitTouchRoll(TouchEvent.TOUCH_ROLL_OVER, contact, target, previous, target);
|
|
655
|
+
if (contact.target === target) emitTouch(TouchEvent.TOUCH_OVER, contact, next, previous);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
function dispatchTouch(type, contact, canceled, cancelTarget) {
|
|
659
|
+
var picked = pickTouch(contact.x, contact.y, cancelTarget);
|
|
660
|
+
var e = contact.event;
|
|
661
|
+
if (type === TouchEvent.TOUCH_BEGIN) {
|
|
662
|
+
contact.origin = picked.target;
|
|
663
|
+
contact.startX = e.clientX;
|
|
664
|
+
contact.startY = e.clientY;
|
|
665
|
+
contact.startTime = Number.isFinite(e.timeStamp) ? e.timeStamp : Date.now();
|
|
666
|
+
}
|
|
667
|
+
if (!canceled && (picked.target !== contact.origin ||
|
|
668
|
+
Math.hypot(e.clientX - contact.startX, e.clientY - contact.startY) > 10)) contact.moved = true;
|
|
669
|
+
if (!canceled) transitionTouch(contact, picked);
|
|
670
|
+
if (type !== TouchEvent.TOUCH_END && !touches.has(e.pointerId)) return;
|
|
671
|
+
emitTouch(type, contact, picked, null, canceled);
|
|
672
|
+
if (type !== TouchEvent.TOUCH_END) return;
|
|
673
|
+
var released = Number.isFinite(e.timeStamp) ? e.timeStamp : Date.now();
|
|
674
|
+
if (!canceled && !contact.moved && touchInputMode === MultitouchInputMode.TOUCH_POINT &&
|
|
675
|
+
released >= contact.startTime && released - contact.startTime <= 500 &&
|
|
676
|
+
isStageDescendant(stageSingleton, picked.target)) {
|
|
677
|
+
emitTouch(TouchEvent.TOUCH_TAP, contact, picked, null);
|
|
678
|
+
}
|
|
679
|
+
transitionTouch(contact, null);
|
|
680
|
+
}
|
|
681
|
+
function transitionProximity(contact, next) {
|
|
682
|
+
var previous = contact.target;
|
|
683
|
+
var target = next?.target || null;
|
|
684
|
+
if (previous === target) return;
|
|
685
|
+
contact.target = target;
|
|
686
|
+
if (previous) {
|
|
687
|
+
var leaving = pickTouch(contact.x, contact.y, previous);
|
|
688
|
+
emitTouch(TouchEvent.PROXIMITY_OUT, contact, leaving, target);
|
|
689
|
+
}
|
|
690
|
+
if (next && contact.target === target) {
|
|
691
|
+
emitTouch(TouchEvent.PROXIMITY_OVER, contact, next, previous);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
function endProximity(id, canceled) {
|
|
695
|
+
var contact = proximities.get(id);
|
|
696
|
+
if (!contact) return;
|
|
697
|
+
proximities.delete(id);
|
|
698
|
+
var picked = pickTouch(contact.x, contact.y, canceled ? contact.target : null);
|
|
699
|
+
if (!canceled) transitionProximity(contact, picked);
|
|
700
|
+
emitTouch(TouchEvent.PROXIMITY_END, contact, picked, null, canceled);
|
|
701
|
+
transitionProximity(contact, null);
|
|
702
|
+
}
|
|
703
|
+
function routeProximity(e) {
|
|
704
|
+
if (e.pointerType !== 'pen' || !Number.isInteger(e.pointerId)) return false;
|
|
705
|
+
if (touchInputMode !== MultitouchInputMode.TOUCH_POINT) return false;
|
|
706
|
+
// Tip (1) or eraser (32) contact is a real touch point, not hover proximity.
|
|
707
|
+
if (e.buttons & 33) {
|
|
708
|
+
endProximity(e.pointerId, false);
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
if (touches.has(e.pointerId)) return false;
|
|
712
|
+
var rect = canvas.getBoundingClientRect();
|
|
713
|
+
var contact = proximities.get(e.pointerId);
|
|
714
|
+
var began = !contact;
|
|
715
|
+
if (!contact) {
|
|
716
|
+
contact = {
|
|
717
|
+
primary: e.isPrimary !== false, mode: touchInputMode, intent: TouchEventIntent.PEN,
|
|
718
|
+
event: e, target: null,
|
|
719
|
+
};
|
|
720
|
+
proximities.set(e.pointerId, contact);
|
|
721
|
+
}
|
|
722
|
+
contact.left = rect.left;
|
|
723
|
+
contact.top = rect.top;
|
|
724
|
+
contact.scaleX = canvas.width / Math.max(1, rect.width);
|
|
725
|
+
contact.scaleY = canvas.height / Math.max(1, rect.height);
|
|
726
|
+
contact.x = (e.clientX - rect.left) * contact.scaleX;
|
|
727
|
+
contact.y = (e.clientY - rect.top) * contact.scaleY;
|
|
728
|
+
contact.event = e;
|
|
729
|
+
var picked = pickTouch(contact.x, contact.y);
|
|
730
|
+
if (began) {
|
|
731
|
+
contact.origin = picked.target;
|
|
732
|
+
transitionProximity(contact, picked);
|
|
733
|
+
emitTouch(TouchEvent.PROXIMITY_BEGIN, contact, picked, null);
|
|
734
|
+
} else {
|
|
735
|
+
transitionProximity(contact, picked);
|
|
736
|
+
emitTouch(TouchEvent.PROXIMITY_MOVE, contact, picked, null);
|
|
737
|
+
}
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
function routeTouch(e, type, canceled) {
|
|
741
|
+
var pen = e.pointerType === 'pen';
|
|
742
|
+
if ((!pen && e.pointerType !== 'touch') || !Number.isInteger(e.pointerId)) return;
|
|
743
|
+
var contact = touches.get(e.pointerId);
|
|
744
|
+
if (type === TouchEvent.TOUCH_BEGIN) {
|
|
745
|
+
if (touchInputMode === MultitouchInputMode.NONE || contact) return;
|
|
746
|
+
// The W3C button mask distinguishes pen tip (1), barrel (2), and eraser (32).
|
|
747
|
+
if (pen && (touchInputMode !== MultitouchInputMode.TOUCH_POINT || !(e.buttons & 33))) return;
|
|
748
|
+
endProximity(e.pointerId, false);
|
|
749
|
+
var intent = pen ? (e.buttons & 32 ? TouchEventIntent.ERASER : TouchEventIntent.PEN) : TouchEventIntent.UNKNOWN;
|
|
750
|
+
contact = { primary: e.isPrimary !== false, mode: touchInputMode, intent: intent };
|
|
751
|
+
touches.set(e.pointerId, contact);
|
|
752
|
+
if (touchInputMode === MultitouchInputMode.TOUCH_POINT) {
|
|
753
|
+
try { canvas.setPointerCapture?.(e.pointerId); } catch (_) {}
|
|
754
|
+
e.preventDefault?.();
|
|
755
|
+
}
|
|
756
|
+
} else if (!contact) return;
|
|
757
|
+
if (!canceled) {
|
|
758
|
+
var rect = canvas.getBoundingClientRect();
|
|
759
|
+
contact.left = rect.left;
|
|
760
|
+
contact.top = rect.top;
|
|
761
|
+
contact.scaleX = canvas.width / Math.max(1, rect.width);
|
|
762
|
+
contact.scaleY = canvas.height / Math.max(1, rect.height);
|
|
763
|
+
contact.x = (e.clientX - rect.left) * contact.scaleX;
|
|
764
|
+
contact.y = (e.clientY - rect.top) * contact.scaleY;
|
|
765
|
+
contact.event = e;
|
|
766
|
+
}
|
|
767
|
+
if (!canceled && type !== TouchEvent.TOUCH_BEGIN) advanceTouchDrag(contact);
|
|
768
|
+
if (type === TouchEvent.TOUCH_END) {
|
|
769
|
+
if (activeTouchDrag?.contact === contact) setActiveTouchDrag(null);
|
|
770
|
+
touches.delete(e.pointerId);
|
|
771
|
+
}
|
|
772
|
+
if (contact.mode === MultitouchInputMode.GESTURE) routeGesture(type, contact, canceled);
|
|
773
|
+
else dispatchTouch(type, contact, canceled);
|
|
774
|
+
}
|
|
775
|
+
setCancelActiveTouches(function () {
|
|
776
|
+
var canceled = Array.from(touches.values());
|
|
777
|
+
touches.clear();
|
|
778
|
+
for (var id of Array.from(proximities.keys())) endProximity(id, true);
|
|
779
|
+
setActiveTouchDrag(null);
|
|
780
|
+
pendingGestureTap = null;
|
|
781
|
+
endGesture();
|
|
782
|
+
for (var contact of canceled) {
|
|
783
|
+
if (contact.mode === MultitouchInputMode.TOUCH_POINT) dispatchTouch(TouchEvent.TOUCH_END, contact, true);
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
cancelLoadedPointerInput = function (root) {
|
|
787
|
+
var pointerId = _buttonPointerId;
|
|
788
|
+
var pressed = _buttonCapture;
|
|
789
|
+
var x = stageSingleton.mouseX, y = stageSingleton.mouseY;
|
|
790
|
+
if (isStageDescendant(root, pressed) || isStageDescendant(root, _textLinkCapture?.field)) {
|
|
791
|
+
_buttonCapture = _textLinkCapture = null;
|
|
792
|
+
_buttonPointerId = null;
|
|
793
|
+
Mouse._isDown = false;
|
|
794
|
+
dispatchButtonEvent(pressed, MouseEvent.MOUSE_UP, x, y);
|
|
795
|
+
try { if (pointerId != null) canvas.releasePointerCapture?.(pointerId); } catch (_) {}
|
|
796
|
+
}
|
|
797
|
+
for (var i = 0; i < secondaryCaptures.length; i++) {
|
|
798
|
+
if (isStageDescendant(root, secondaryCaptures[i])) secondaryCaptures[i] = null;
|
|
799
|
+
}
|
|
800
|
+
if (isStageDescendant(root, lastPrimaryClick?.button)) lastPrimaryClick = null;
|
|
801
|
+
if (isStageDescendant(root, _hoveredButton)) updateButtonHover(null, x, y);
|
|
802
|
+
if (isStageDescendant(root, mouseCursorTarget)) setMouseCursorTarget(null);
|
|
803
|
+
if (isStageDescendant(root, stageSingleton.focus)) stageSingleton.focus = null;
|
|
804
|
+
for (var [id, contact] of touches) {
|
|
805
|
+
if (!isStageDescendant(root, contact.origin) && !isStageDescendant(root, contact.target)) continue;
|
|
806
|
+
touches.delete(id);
|
|
807
|
+
if (activeTouchDrag?.contact === contact) setActiveTouchDrag(null);
|
|
808
|
+
if (contact.mode === MultitouchInputMode.GESTURE) {
|
|
809
|
+
routeGesture(TouchEvent.TOUCH_END, contact, true);
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
var target = isStageDescendant(stageSingleton, contact.target) ? contact.target : contact.origin;
|
|
813
|
+
dispatchTouch(TouchEvent.TOUCH_END, contact, true, target);
|
|
814
|
+
try { canvas.releasePointerCapture?.(id); } catch (_) {}
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
function secondaryButton(e, isDown) {
|
|
818
|
+
var types = secondaryEvents[e.button];
|
|
819
|
+
if (!types || e.sourceCapabilities && e.sourceCapabilities.firesTouchEvents) return;
|
|
820
|
+
if (isDown) lastPrimaryClick = null;
|
|
821
|
+
update(e);
|
|
822
|
+
var x = stageSingleton.mouseX, y = stageSingleton.mouseY;
|
|
823
|
+
var secondary = e.button === 1 ? 'middle' : 'right';
|
|
824
|
+
var hit = secondaryPointerTarget(x, y, secondary);
|
|
825
|
+
if (isDown) {
|
|
826
|
+
secondaryCaptures[e.button] = hit;
|
|
827
|
+
dispatchButtonEvent(hit, types[0], x, y, e);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
var pressed = secondaryCaptures[e.button];
|
|
831
|
+
secondaryCaptures[e.button] = null;
|
|
832
|
+
dispatchButtonEvent(hit, types[1], x, y, e);
|
|
833
|
+
if (pressed && pressed === hit && secondaryPointerTarget(x, y, secondary) === pressed) dispatchButtonEvent(pressed, types[2], x, y, e);
|
|
834
|
+
}
|
|
835
|
+
var unrelatedPointer = function (e) {
|
|
836
|
+
return e.isPrimary === false || (_buttonPointerId != null && e.pointerId != null && e.pointerId !== _buttonPointerId);
|
|
837
|
+
};
|
|
838
|
+
var onMove = function (e) {
|
|
839
|
+
if (routeProximity(e)) {
|
|
840
|
+
// Pen hover consumed as proximity; tip/eraser contact still routes below.
|
|
841
|
+
} else routeTouch(e, TouchEvent.TOUCH_MOVE, false);
|
|
842
|
+
if (!mapsPointerToMouse(e)) return;
|
|
843
|
+
if (unrelatedPointer(e)) return;
|
|
844
|
+
update(e);
|
|
845
|
+
var x = stageSingleton.mouseX, y = stageSingleton.mouseY;
|
|
846
|
+
dispatchEmbeddedAvm1('move', x, y, e);
|
|
847
|
+
if (activeMouseDrag && !advanceSpriteDrag(activeMouseDrag, x, y)) setActiveMouseDrag(null);
|
|
848
|
+
var hit = hitButton(x, y);
|
|
849
|
+
updateButtonHover(hit, x, y, e, true);
|
|
850
|
+
if (!hit && stageSingleton.hasEventListener(MouseEvent.MOUSE_MOVE) && isBlankPrimaryPoint(x, y)) {
|
|
851
|
+
dispatchBlankPrimary(MouseEvent.MOUSE_MOVE, x, y, e);
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
var onDown = function (e) {
|
|
855
|
+
routeTouch(e, TouchEvent.TOUCH_BEGIN, false);
|
|
856
|
+
if (!mapsPointerToMouse(e)) return;
|
|
857
|
+
if (unrelatedPointer(e) || e.button !== 0 || _buttonCapture || _textLinkCapture || stagePrimaryPressed) return;
|
|
858
|
+
update(e);
|
|
859
|
+
// Keyboard Tab/Enter/Space activation needs the stage canvas focused.
|
|
860
|
+
if (typeof canvas.focus === 'function') {
|
|
861
|
+
try {
|
|
862
|
+
if (typeof document === 'undefined' || document.activeElement !== canvas) canvas.focus({ preventScroll: true });
|
|
863
|
+
} catch (_) {
|
|
864
|
+
try { canvas.focus(); } catch (_) {}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
var x = stageSingleton.mouseX, y = stageSingleton.mouseY;
|
|
868
|
+
dispatchEmbeddedAvm1('down', x, y, e);
|
|
869
|
+
var textLink = topmostTextLinkAt(stageSingleton, x, y);
|
|
870
|
+
if (textLink) {
|
|
871
|
+
lastPrimaryClick = null;
|
|
872
|
+
_textLinkCapture = textLink;
|
|
873
|
+
stageSingleton.focus = textLink.field;
|
|
874
|
+
if (e.pointerId != null) _buttonPointerId = e.pointerId;
|
|
875
|
+
if (e.pointerType === 'touch' && e.preventDefault) e.preventDefault();
|
|
876
|
+
try { if (canvas.setPointerCapture && e.pointerId != null) canvas.setPointerCapture(e.pointerId); } catch (_) {}
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
var button = updateButtonHover(hitButton(x, y), x, y, e);
|
|
880
|
+
var authoredTarget = !button && canvasAuthoredTouchPick?.(x, y, false)?.target;
|
|
881
|
+
if (lastPrimaryClick && lastPrimaryClick.button !== (button || authoredTarget || stageSingleton)) lastPrimaryClick = null;
|
|
882
|
+
// The timeline listener handles its own authored hit after this listener.
|
|
883
|
+
if (!button && !authoredTarget) focusCanvasPointerTarget(null);
|
|
884
|
+
if (button) {
|
|
885
|
+
_buttonCapture = button;
|
|
886
|
+
if (e.pointerId != null) _buttonPointerId = e.pointerId;
|
|
887
|
+
focusCanvasPointerTarget(button);
|
|
888
|
+
if (_buttonCapture !== button) return;
|
|
889
|
+
setMovieClipButtonState(button, '_down');
|
|
890
|
+
dispatchButtonEvent(button, MouseEvent.MOUSE_DOWN, x, y, e);
|
|
891
|
+
if (e.pointerType === 'touch' && e.preventDefault) e.preventDefault();
|
|
892
|
+
try { if (_buttonCapture === button && e.pointerId != null) canvas.setPointerCapture?.(e.pointerId); } catch (_) {}
|
|
893
|
+
} else if (isBlankPrimaryPoint(x, y)) {
|
|
894
|
+
stagePrimaryPressed = true;
|
|
895
|
+
if (e.pointerId != null) _buttonPointerId = e.pointerId;
|
|
896
|
+
dispatchBlankPrimary(MouseEvent.MOUSE_DOWN, x, y, e);
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
var onUp = function (e, cancelled) {
|
|
900
|
+
routeTouch(e, TouchEvent.TOUCH_END, cancelled);
|
|
901
|
+
if (!cancelled) routeProximity(e);
|
|
902
|
+
if (!mapsPointerToMouse(e)) {
|
|
903
|
+
if (_buttonPointerId == null || e.pointerId !== _buttonPointerId) return;
|
|
904
|
+
cancelled = true;
|
|
905
|
+
}
|
|
906
|
+
if (unrelatedPointer(e) || (!cancelled && e.button !== 0)) return;
|
|
907
|
+
if (Number.isFinite(e.clientX) && Number.isFinite(e.clientY)) update(e);
|
|
908
|
+
var x = stageSingleton.mouseX, y = stageSingleton.mouseY;
|
|
909
|
+
dispatchEmbeddedAvm1('up', x, y, e, cancelled);
|
|
910
|
+
var pressedLink = _textLinkCapture;
|
|
911
|
+
var pressed = _buttonCapture;
|
|
912
|
+
var pressedStage = stagePrimaryPressed;
|
|
913
|
+
stagePrimaryPressed = false;
|
|
914
|
+
_textLinkCapture = null;
|
|
915
|
+
_buttonCapture = null;
|
|
916
|
+
_buttonPointerId = null;
|
|
917
|
+
Mouse._isDown = false;
|
|
918
|
+
if (cancelled) {
|
|
919
|
+
secondaryCaptures.length = 0;
|
|
920
|
+
lastPrimaryClick = null;
|
|
921
|
+
updateButtonHover(null, x, y, e);
|
|
922
|
+
setMovieClipButtonState(pressed, '_up');
|
|
923
|
+
dispatchButtonEvent(pressed, MouseEvent.MOUSE_UP, x, y, e);
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
if (pressedLink) {
|
|
927
|
+
var linkHit = topmostTextLinkAt(stageSingleton, x, y);
|
|
928
|
+
if (linkHit && linkHit.field === pressedLink.field && linkHit.region.href === pressedLink.region.href && linkHit.region.target === pressedLink.region.target) activateTextLink(linkHit);
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
var hit = updateButtonHover(hitButton(x, y), x, y, e);
|
|
932
|
+
var canvasRelease = !e.target || e.target === canvas;
|
|
933
|
+
var blankRelease = !hit && (pressed || canvasRelease) && isBlankPrimaryPoint(x, y);
|
|
934
|
+
setMovieClipButtonState(pressed, pressed === hit ? '_over' : '_up');
|
|
935
|
+
if (hit) dispatchButtonEvent(hit, MouseEvent.MOUSE_UP, x, y, e);
|
|
936
|
+
else if (blankRelease) dispatchBlankPrimary(MouseEvent.MOUSE_UP, x, y, e);
|
|
937
|
+
if (pressedStage && blankRelease && !hitButton(x, y) &&
|
|
938
|
+
isBlankPrimaryPoint(x, y) && !topmostTextLinkAt(stageSingleton, x, y)) {
|
|
939
|
+
dispatchBlankPrimary(primaryClickType(stageSingleton, e), x, y, e);
|
|
940
|
+
} else if (pressedStage) lastPrimaryClick = null;
|
|
941
|
+
if (pressed && pressed !== hit) dispatchButtonEvent(pressed, MouseEvent.RELEASE_OUTSIDE, x, y, e);
|
|
942
|
+
if (pressed && pressed === hit && hitButton(x, y) === pressed) {
|
|
943
|
+
dispatchButtonEvent(pressed, primaryClickType(pressed, e), x, y, e);
|
|
944
|
+
} else if (pressed || hit) lastPrimaryClick = null;
|
|
945
|
+
if (e.pointerType === 'touch') updateButtonHover(null, x, y, e);
|
|
946
|
+
};
|
|
947
|
+
var onLeave = function (e) {
|
|
948
|
+
if (e.pointerType === 'pen' && Number.isInteger(e.pointerId)) endProximity(e.pointerId, false);
|
|
949
|
+
if (!mapsPointerToMouse(e)) return;
|
|
950
|
+
if (unrelatedPointer(e)) return;
|
|
951
|
+
update(e);
|
|
952
|
+
updateButtonHover(null, stageSingleton.mouseX, stageSingleton.mouseY, e);
|
|
953
|
+
};
|
|
954
|
+
var pointerEvents = typeof window !== 'undefined' && typeof window.PointerEvent === 'function';
|
|
955
|
+
var releaseTarget = typeof window !== 'undefined' && window.addEventListener ? window : canvas;
|
|
956
|
+
// Keep Sprite.startDrag / touch-drag / embedded AVM1 drag updates when the
|
|
957
|
+
// pointer leaves the canvas without Pointer Event capture (or after a scripted startDrag).
|
|
958
|
+
var embeddedAvm1Dragging = function () {
|
|
959
|
+
if (embeddedAvm1PointerCapture?.embed?.isDragging?.()) return true;
|
|
960
|
+
var stack = stageSingleton ? [stageSingleton] : [];
|
|
961
|
+
while (stack.length) {
|
|
962
|
+
var node = stack.pop();
|
|
963
|
+
var embed = node?._swoofTimelineCanvas?._swoofAvm1Embed;
|
|
964
|
+
if (embed?.isDragging?.()) return true;
|
|
965
|
+
var kids = node?._children;
|
|
966
|
+
if (kids) for (var i = 0; i < kids.length; i++) stack.push(kids[i]);
|
|
967
|
+
}
|
|
968
|
+
return false;
|
|
969
|
+
};
|
|
970
|
+
var onWindowDragMove = function (e) {
|
|
971
|
+
if (!activeMouseDrag && !activeTouchDrag && !embeddedAvm1PointerCapture && !embeddedAvm1Dragging()) return;
|
|
972
|
+
if (e.target === canvas) return;
|
|
973
|
+
onMove(e);
|
|
974
|
+
};
|
|
975
|
+
if (pointerEvents) {
|
|
976
|
+
if (canvas.style) canvas.style.touchAction = 'none';
|
|
977
|
+
canvas.addEventListener('pointermove', onMove, true);
|
|
978
|
+
canvas.addEventListener('pointerdown', onDown, true);
|
|
979
|
+
canvas.addEventListener('pointerleave', onLeave, true);
|
|
980
|
+
canvas.addEventListener('lostpointercapture', function (e) {
|
|
981
|
+
if (_buttonPointerId != null || touches.has(e.pointerId)) onUp(e, true);
|
|
982
|
+
}, true);
|
|
983
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
984
|
+
window.addEventListener('pointermove', onWindowDragMove, true);
|
|
985
|
+
window.addEventListener('pointerup', function (e) { onUp(e, false); }, true);
|
|
986
|
+
window.addEventListener('pointercancel', function (e) { onUp(e, true); }, true);
|
|
987
|
+
} else {
|
|
988
|
+
canvas.addEventListener('pointerup', function (e) { onUp(e, false); }, true);
|
|
989
|
+
canvas.addEventListener('pointercancel', function (e) { onUp(e, true); }, true);
|
|
990
|
+
}
|
|
991
|
+
} else {
|
|
992
|
+
canvas.addEventListener('mousemove', onMove, true);
|
|
993
|
+
canvas.addEventListener('mouseleave', onLeave, true);
|
|
994
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
995
|
+
window.addEventListener('mousemove', onWindowDragMove, true);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
// Compatibility mouse events report each button during a chord.
|
|
999
|
+
// Pointer Events report pointerdown/up only at the first/last button.
|
|
1000
|
+
canvas.addEventListener('mousedown', function (e) {
|
|
1001
|
+
if (e.button !== 0) secondaryButton(e, true);
|
|
1002
|
+
else if (!pointerEvents || (e.buttons & 6)) onDown(e);
|
|
1003
|
+
}, true);
|
|
1004
|
+
releaseTarget.addEventListener('mouseup', function (e) {
|
|
1005
|
+
if (e.button !== 0) secondaryButton(e, false);
|
|
1006
|
+
else if (!pointerEvents || (e.buttons & 6)) onUp(e, false);
|
|
1007
|
+
}, true);
|
|
1008
|
+
canvas.addEventListener('contextmenu', function (e) {
|
|
1009
|
+
if (canvas._swoofAvm1Pointer || !e.preventDefault) return;
|
|
1010
|
+
update(e);
|
|
1011
|
+
var mouseTarget = e.button === 2 ? topmostPointerTarget(stageSingleton, stageSingleton.mouseX, stageSingleton.mouseY, true) : stageSingleton.focus;
|
|
1012
|
+
var target = mouseTarget || global.__swoof?.main || stageSingleton;
|
|
1013
|
+
for (var owner = target; owner; owner = owner.parent) {
|
|
1014
|
+
if (owner.contextMenu instanceof ContextMenu && openContextMenu(canvas, e, owner.contextMenu, owner, target, false)) return;
|
|
1015
|
+
}
|
|
1016
|
+
if (e.button !== 2) return;
|
|
1017
|
+
var hit = secondaryPointerTarget(stageSingleton.mouseX, stageSingleton.mouseY, 'right');
|
|
1018
|
+
if (hit && (hit.willTrigger(MouseEvent.RIGHT_CLICK) || hit.willTrigger(MouseEvent.RIGHT_MOUSE_DOWN) ||
|
|
1019
|
+
hit.willTrigger(MouseEvent.RIGHT_MOUSE_UP))) e.preventDefault();
|
|
1020
|
+
}, true);
|
|
1021
|
+
canvas.addEventListener('wheel', function (e) {
|
|
1022
|
+
var page = e.deltaMode === 2 ? canvas.getBoundingClientRect() : null;
|
|
1023
|
+
var vertical = normalizeFlashWheelDelta(e, page?.height || 0, 'y');
|
|
1024
|
+
var horizontal = normalizeFlashWheelDelta(e, page?.width || 0, 'x');
|
|
1025
|
+
if (!vertical && !horizontal) return;
|
|
1026
|
+
update(e);
|
|
1027
|
+
var x = stageSingleton.mouseX, y = stageSingleton.mouseY;
|
|
1028
|
+
var target = secondaryPointerTarget(x, y, 'wheel');
|
|
1029
|
+
if (vertical) {
|
|
1030
|
+
dispatchButtonEvent(target, MouseEvent.MOUSE_WHEEL, x, y, e, null, vertical);
|
|
1031
|
+
if (canvas._swoofAs3CanvasWheel) canvas._swoofAs3CanvasWheel(e, vertical, x, y);
|
|
1032
|
+
else {
|
|
1033
|
+
var verticalText = canvasWheelTextAt(x, y);
|
|
1034
|
+
if (verticalText && scrollCanvasText(verticalText, vertical)) e.preventDefault?.();
|
|
1035
|
+
}
|
|
1036
|
+
canvas._swoofAvm1Wheel?.(e, vertical);
|
|
1037
|
+
var embeddedWheel = embeddedAvm1Hit(stageSingleton, x, y);
|
|
1038
|
+
if (!embeddedWheel && embeddedAvm1PointerCapture) {
|
|
1039
|
+
var wheelLocal = localPointOnEmbedNode(embeddedAvm1PointerCapture.node, x, y);
|
|
1040
|
+
embeddedWheel = {
|
|
1041
|
+
embed: embeddedAvm1PointerCapture.embed,
|
|
1042
|
+
x: wheelLocal.x,
|
|
1043
|
+
y: wheelLocal.y,
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
if (embeddedWheel) embeddedWheel.embed.wheel(embeddedWheel.x, embeddedWheel.y, vertical, e);
|
|
1047
|
+
}
|
|
1048
|
+
if (horizontal) {
|
|
1049
|
+
dispatchButtonEvent(target, MouseEvent.MOUSE_WHEEL_HORIZONTAL, x, y, e, null, horizontal);
|
|
1050
|
+
if (canvas._swoofAs3CanvasWheelHorizontal) canvas._swoofAs3CanvasWheelHorizontal(e, horizontal, x, y);
|
|
1051
|
+
else {
|
|
1052
|
+
var horizontalText = canvasWheelTextAt(x, y);
|
|
1053
|
+
if (horizontalText && scrollCanvasTextHorizontal(horizontalText, horizontal)) e.preventDefault?.();
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}, true);
|
|
1057
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
1058
|
+
window.addEventListener('blur', function (e) {
|
|
1059
|
+
cancelActiveTouches();
|
|
1060
|
+
onUp(e || {}, true);
|
|
1061
|
+
}, true);
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
if (document.readyState === 'loading') {
|
|
1065
|
+
document.addEventListener('DOMContentLoaded', _bindMouse);
|
|
1066
|
+
} else {
|
|
1067
|
+
_bindMouse();
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
pointerBridge.childRemoved = function (child) {
|
|
1071
|
+
if (isStageDescendant(child, activeTouchDrag?.sprite)) setActiveTouchDrag(null);
|
|
1072
|
+
if (isStageDescendant(child, activeMouseDrag?.sprite)) setActiveMouseDrag(null);
|
|
1073
|
+
if (embeddedAvm1PointerCapture && isStageDescendant(child, embeddedAvm1PointerCapture.node)) {
|
|
1074
|
+
embeddedAvm1PointerCapture = null;
|
|
1075
|
+
}
|
|
1076
|
+
if (child._swoofTimelineCanvas) {
|
|
1077
|
+
if (embeddedAvm1KeyOwner && child._swoofTimelineCanvas._swoofAvm1Embed === embeddedAvm1KeyOwner) {
|
|
1078
|
+
embeddedAvm1KeyOwner = null;
|
|
1079
|
+
}
|
|
1080
|
+
cancelLoadedPointerInput?.(child);
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
pointerBridge.maskContains = function (mask, x, y) {
|
|
1084
|
+
return pointerMaskContains(mask, x, y);
|
|
1085
|
+
};
|