@ac-kit/ui-gesture 0.0.0-stage → 0.1.1
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/CHANGELOG.md +151 -0
- package/LICENSE +28 -0
- package/README.md +310 -2
- package/dist/_validate.d.ts +4 -0
- package/dist/_validate.d.ts.map +1 -0
- package/dist/_validate.js +10 -0
- package/dist/_validate.js.map +1 -0
- package/dist/dom/_claim.d.ts +8 -0
- package/dist/dom/_claim.d.ts.map +1 -0
- package/dist/dom/_claim.js +14 -0
- package/dist/dom/_claim.js.map +1 -0
- package/dist/dom/_pointer-engine.d.ts +121 -0
- package/dist/dom/_pointer-engine.d.ts.map +1 -0
- package/dist/dom/_pointer-engine.js +559 -0
- package/dist/dom/_pointer-engine.js.map +1 -0
- package/dist/dom/_press-driver.d.ts +39 -0
- package/dist/dom/_press-driver.d.ts.map +1 -0
- package/dist/dom/_press-driver.js +121 -0
- package/dist/dom/_press-driver.js.map +1 -0
- package/dist/dom/index.d.ts +5 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +5 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/dom/pointer-binding.d.ts +111 -0
- package/dist/dom/pointer-binding.d.ts.map +1 -0
- package/dist/dom/pointer-binding.js +35 -0
- package/dist/dom/pointer-binding.js.map +1 -0
- package/dist/dom/press-binding.d.ts +29 -0
- package/dist/dom/press-binding.d.ts.map +1 -0
- package/dist/dom/press-binding.js +53 -0
- package/dist/dom/press-binding.js.map +1 -0
- package/dist/dom/transform-binding.d.ts +81 -0
- package/dist/dom/transform-binding.d.ts.map +1 -0
- package/dist/dom/transform-binding.js +349 -0
- package/dist/dom/transform-binding.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/inertia/inertia.d.ts +32 -0
- package/dist/inertia/inertia.d.ts.map +1 -0
- package/dist/inertia/inertia.js +62 -0
- package/dist/inertia/inertia.js.map +1 -0
- package/dist/keys/key-step.d.ts +25 -0
- package/dist/keys/key-step.d.ts.map +1 -0
- package/dist/keys/key-step.js +30 -0
- package/dist/keys/key-step.js.map +1 -0
- package/dist/pointer/_slop.d.ts +26 -0
- package/dist/pointer/_slop.d.ts.map +1 -0
- package/dist/pointer/_slop.js +74 -0
- package/dist/pointer/_slop.js.map +1 -0
- package/dist/pointer/pointer-input.d.ts +61 -0
- package/dist/pointer/pointer-input.d.ts.map +1 -0
- package/dist/pointer/pointer-input.js +6 -0
- package/dist/pointer/pointer-input.js.map +1 -0
- package/dist/press/press-gesture.d.ts +282 -0
- package/dist/press/press-gesture.d.ts.map +1 -0
- package/dist/press/press-gesture.js +579 -0
- package/dist/press/press-gesture.js.map +1 -0
- package/dist/transform/transform-gesture.d.ts +174 -0
- package/dist/transform/transform-gesture.d.ts.map +1 -0
- package/dist/transform/transform-gesture.js +415 -0
- package/dist/transform/transform-gesture.js.map +1 -0
- package/dist/velocity/velocity-tracker.d.ts +69 -0
- package/dist/velocity/velocity-tracker.d.ts.map +1 -0
- package/dist/velocity/velocity-tracker.js +152 -0
- package/dist/velocity/velocity-tracker.js.map +1 -0
- package/dist/wheel/wheel.d.ts +115 -0
- package/dist/wheel/wheel.d.ts.map +1 -0
- package/dist/wheel/wheel.js +164 -0
- package/dist/wheel/wheel.js.map +1 -0
- package/package.json +79 -3
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { PointerDown, PointerSample } from "../pointer/pointer-input.js";
|
|
2
|
+
import type { GestureBinding, GestureElement, HoverHandlers, PointerBindingOptions } from "./pointer-binding.js";
|
|
3
|
+
/** What a recogniser behind the engine does with the normalised pointers. */
|
|
4
|
+
export type EngineHooks_ = {
|
|
5
|
+
/**
|
|
6
|
+
* Updates the recogniser; whether it accepted the press. `provisional`: the
|
|
7
|
+
* binding keeps the pointer aside (a lone cooperative touch), so it is
|
|
8
|
+
* followed but not claimed, captured or counted as a gesture under way, until
|
|
9
|
+
* {@link PointerEngine_.promote}.
|
|
10
|
+
*/
|
|
11
|
+
down(down: PointerDown, event: PointerEvent): boolean | "provisional";
|
|
12
|
+
/** The press was accepted, claimed, captured and focused: tell the caller. */
|
|
13
|
+
accepted?(down: PointerDown, event: PointerEvent): void;
|
|
14
|
+
move(sample: PointerSample, event: PointerEvent): void;
|
|
15
|
+
up(sample: PointerSample, event: PointerEvent): void;
|
|
16
|
+
cancel(pointerId: number, event: PointerEvent | undefined): void;
|
|
17
|
+
/** Whether to capture this accepted pointer, on top of the `capture` option. */
|
|
18
|
+
captures?(down: PointerDown): boolean;
|
|
19
|
+
/** A `contextmenu` while a touch or pen pointer is down. */
|
|
20
|
+
contextMenu?(event: Event): void;
|
|
21
|
+
};
|
|
22
|
+
export type EngineConfiguration_ = {
|
|
23
|
+
/** Long press is on: touch and pen presses cancel `contextmenu`. */
|
|
24
|
+
readonly impliesContextMenuPrevention: boolean;
|
|
25
|
+
readonly suppressClickAfterDrag: boolean;
|
|
26
|
+
readonly hover: HoverHandlers | undefined;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The plumbing the three bindings share: listeners on one controller, a
|
|
30
|
+
* normalised sample per pointer event, capture, claims, a single end per
|
|
31
|
+
* pointer, hover, default actions, click suppression and disposal.
|
|
32
|
+
*/
|
|
33
|
+
export declare class PointerEngine_ implements GestureBinding {
|
|
34
|
+
readonly element: GestureElement;
|
|
35
|
+
private readonly hooks_;
|
|
36
|
+
private readonly options_;
|
|
37
|
+
private readonly configuration_;
|
|
38
|
+
/** Aborted when the binding is disposed. */
|
|
39
|
+
readonly signal: AbortSignal;
|
|
40
|
+
private readonly controller_;
|
|
41
|
+
private readonly tracked_;
|
|
42
|
+
private readonly hovering_;
|
|
43
|
+
private readonly cleanups_;
|
|
44
|
+
private box_;
|
|
45
|
+
private isDone_;
|
|
46
|
+
private isClickSuppressed_;
|
|
47
|
+
constructor(element: GestureElement, hooks_: EngineHooks_, options_: PointerBindingOptions, configuration_: EngineConfiguration_);
|
|
48
|
+
get isActive(): boolean;
|
|
49
|
+
get box(): DOMRectReadOnly | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the binding is disposed. A caller's aborted signal disposes it here
|
|
52
|
+
* too, at the first event or timer after, in case an earlier `abort` listener
|
|
53
|
+
* of that signal stopped propagation before ours ran.
|
|
54
|
+
*/
|
|
55
|
+
private get disposed_();
|
|
56
|
+
get isDisposed(): boolean;
|
|
57
|
+
/** Whether a touch pointer is down on the element. */
|
|
58
|
+
get isTouchDown(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The frame of `element` coordinates of the gesture under way (measured at
|
|
61
|
+
* its first press), or a fresh measure, kept as {@link box}, when no pointer
|
|
62
|
+
* is down.
|
|
63
|
+
*/
|
|
64
|
+
pointerFrame(): DOMRectReadOnly;
|
|
65
|
+
/**
|
|
66
|
+
* The element's frame now, for input that is no part of a pointer's gesture
|
|
67
|
+
* (hover, wheel, trackpad); it replaces {@link box} only while no pointer is
|
|
68
|
+
* down.
|
|
69
|
+
*/
|
|
70
|
+
liveFrame(): DOMRectReadOnly;
|
|
71
|
+
/** A client position in the binding's coordinates. */
|
|
72
|
+
point(clientX: number, clientY: number, frame: DOMRectReadOnly): {
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
};
|
|
76
|
+
/** Runs a caller's handler, or the recogniser, reporting what it throws. */
|
|
77
|
+
notify(action: () => void): void;
|
|
78
|
+
armClickSuppression(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Releases the pointers without telling anyone (the gesture ended as a
|
|
81
|
+
* whole).
|
|
82
|
+
*/
|
|
83
|
+
forget(pointerId?: number): void;
|
|
84
|
+
/** Adds a listener that goes with the binding. */
|
|
85
|
+
listen<EventType extends Event>(type: string, listener: (event: EventType) => void, options?: {
|
|
86
|
+
readonly passive?: boolean;
|
|
87
|
+
readonly capture?: boolean;
|
|
88
|
+
}): void;
|
|
89
|
+
/** Runs `cleanup` at disposal. */
|
|
90
|
+
onDispose(cleanup: () => void): void;
|
|
91
|
+
/** The pointer is part of the gesture now: claimed from here on. */
|
|
92
|
+
promote(pointerId: number): void;
|
|
93
|
+
/** The pointer goes back aside, its gesture over. */
|
|
94
|
+
demote(pointerId: number): void;
|
|
95
|
+
/** Sets a `touch-action` until disposal. */
|
|
96
|
+
setTouchAction(value: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* Links the caller's signal and sets the `touch-action`; `false`, the binding
|
|
99
|
+
* already disposed, when the signal is aborted: nothing is bound.
|
|
100
|
+
*/
|
|
101
|
+
begin(): boolean;
|
|
102
|
+
/** Adds the listeners; called once the bindings' own state is set up. */
|
|
103
|
+
start(): void;
|
|
104
|
+
/** A capture lost at the document: its owner left the page. */
|
|
105
|
+
private onDetachedCaptureLost_;
|
|
106
|
+
cancel(): void;
|
|
107
|
+
[Symbol.dispose](): void;
|
|
108
|
+
/** The ids now tracked, safe to walk while handlers add and remove some. */
|
|
109
|
+
private trackedIds_;
|
|
110
|
+
private end_;
|
|
111
|
+
private endHover_;
|
|
112
|
+
private sampleOf_;
|
|
113
|
+
private onPointerDown_;
|
|
114
|
+
private onPointerMove_;
|
|
115
|
+
private onHoverMove_;
|
|
116
|
+
private onPointerUp_;
|
|
117
|
+
private onPointerCancel_;
|
|
118
|
+
private onLostCapture_;
|
|
119
|
+
private onContextMenu_;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=_pointer-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_pointer-engine.d.ts","sourceRoot":"","sources":["../../src/dom/_pointer-engine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,WAAW,EAEX,aAAa,EACb,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EACX,cAAc,EACd,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,MAAM,sBAAsB,CAAC;AAE9B,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG;IAC1B;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AAG,IAAI,CAK/B;IAED,qDAAqD;IACrD,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAK9B;IAED,4CAA4C;IAC5C,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAOlC;IAED;;;OAGG;IACH,KAAK,IAAI,OAAO,CAsBf;IAED,yEAAyE;IACzE,KAAK,IAAI,IAAI,CAgFZ;IAED,+DAA+D;IAC/D,OAAO,CAAC,sBAAsB;IAe9B,MAAM,IAAI,IAAI,CASb;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAWvB;IAED,4EAA4E;IAC5E,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,IAAI;IAiBZ,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,SAAS;IAiCjB,OAAO,CAAC,cAAc;IAoFtB,OAAO,CAAC,cAAc;IA+DtB,OAAO,CAAC,YAAY;IAuBpB,OAAO,CAAC,YAAY;IA2BpB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,cAAc;IAwBtB,OAAO,CAAC,cAAc;CAoBtB"}
|
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
import { throwOutOfBand } from "@ac-kit/core";
|
|
2
|
+
import { claimPointerEvent, isPointerEventClaimed } from "./_claim.js";
|
|
3
|
+
function kindOf_(event) {
|
|
4
|
+
return event.pointerType === "mouse" || event.pointerType === "pen"
|
|
5
|
+
? event.pointerType
|
|
6
|
+
: "touch";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The plumbing the three bindings share: listeners on one controller, a
|
|
10
|
+
* normalised sample per pointer event, capture, claims, a single end per
|
|
11
|
+
* pointer, hover, default actions, click suppression and disposal.
|
|
12
|
+
*/
|
|
13
|
+
export class PointerEngine_ {
|
|
14
|
+
element;
|
|
15
|
+
hooks_;
|
|
16
|
+
options_;
|
|
17
|
+
configuration_;
|
|
18
|
+
/** Aborted when the binding is disposed. */
|
|
19
|
+
signal;
|
|
20
|
+
controller_ = new AbortController();
|
|
21
|
+
tracked_ = new Map();
|
|
22
|
+
hovering_ = new Set();
|
|
23
|
+
cleanups_ = new DisposableStack();
|
|
24
|
+
box_ = undefined;
|
|
25
|
+
isDone_ = false;
|
|
26
|
+
isClickSuppressed_ = false;
|
|
27
|
+
constructor(element, hooks_, options_, configuration_) {
|
|
28
|
+
this.element = element;
|
|
29
|
+
this.hooks_ = hooks_;
|
|
30
|
+
this.options_ = options_;
|
|
31
|
+
this.configuration_ = configuration_;
|
|
32
|
+
this.signal = this.controller_.signal;
|
|
33
|
+
}
|
|
34
|
+
get isActive() {
|
|
35
|
+
for (const tracked of this.tracked_.values()) {
|
|
36
|
+
if (!tracked.isProvisional) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
get box() {
|
|
43
|
+
return this.box_;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Whether the binding is disposed. A caller's aborted signal disposes it here
|
|
47
|
+
* too, at the first event or timer after, in case an earlier `abort` listener
|
|
48
|
+
* of that signal stopped propagation before ours ran.
|
|
49
|
+
*/
|
|
50
|
+
get disposed_() {
|
|
51
|
+
if (!this.isDone_ && this.options_.signal?.aborted === true) {
|
|
52
|
+
this[Symbol.dispose]();
|
|
53
|
+
}
|
|
54
|
+
return this.isDone_;
|
|
55
|
+
}
|
|
56
|
+
get isDisposed() {
|
|
57
|
+
return this.disposed_;
|
|
58
|
+
}
|
|
59
|
+
/** Whether a touch pointer is down on the element. */
|
|
60
|
+
get isTouchDown() {
|
|
61
|
+
for (const tracked of this.tracked_.values()) {
|
|
62
|
+
if (tracked.kind === "touch") {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The frame of `element` coordinates of the gesture under way (measured at
|
|
70
|
+
* its first press), or a fresh measure, kept as {@link box}, when no pointer
|
|
71
|
+
* is down.
|
|
72
|
+
*/
|
|
73
|
+
pointerFrame() {
|
|
74
|
+
if (this.tracked_.size > 0 && this.box_ !== undefined) {
|
|
75
|
+
return this.box_;
|
|
76
|
+
}
|
|
77
|
+
const rect = this.element.getBoundingClientRect();
|
|
78
|
+
this.box_ = rect;
|
|
79
|
+
return rect;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The element's frame now, for input that is no part of a pointer's gesture
|
|
83
|
+
* (hover, wheel, trackpad); it replaces {@link box} only while no pointer is
|
|
84
|
+
* down.
|
|
85
|
+
*/
|
|
86
|
+
liveFrame() {
|
|
87
|
+
const rect = this.element.getBoundingClientRect();
|
|
88
|
+
if (this.tracked_.size === 0) {
|
|
89
|
+
this.box_ = rect;
|
|
90
|
+
}
|
|
91
|
+
return rect;
|
|
92
|
+
}
|
|
93
|
+
/** A client position in the binding's coordinates. */
|
|
94
|
+
point(clientX, clientY, frame) {
|
|
95
|
+
return this.options_.coordinates === "client"
|
|
96
|
+
? { x: clientX, y: clientY }
|
|
97
|
+
: { x: clientX - frame.left, y: clientY - frame.top };
|
|
98
|
+
}
|
|
99
|
+
/** Runs a caller's handler, or the recogniser, reporting what it throws. */
|
|
100
|
+
notify(action) {
|
|
101
|
+
if (this.disposed_) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
action();
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
throwOutOfBand(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
armClickSuppression() {
|
|
112
|
+
if (this.configuration_.suppressClickAfterDrag) {
|
|
113
|
+
this.isClickSuppressed_ = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Releases the pointers without telling anyone (the gesture ended as a
|
|
118
|
+
* whole).
|
|
119
|
+
*/
|
|
120
|
+
forget(pointerId) {
|
|
121
|
+
if (pointerId !== undefined) {
|
|
122
|
+
this.end_(pointerId);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
for (const id of this.trackedIds_()) {
|
|
126
|
+
this.end_(id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** Adds a listener that goes with the binding. */
|
|
130
|
+
listen(type, listener, options) {
|
|
131
|
+
this.element.addEventListener(type, listener, {
|
|
132
|
+
...options,
|
|
133
|
+
signal: this.signal,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** Runs `cleanup` at disposal. */
|
|
137
|
+
onDispose(cleanup) {
|
|
138
|
+
this.cleanups_.defer(cleanup);
|
|
139
|
+
}
|
|
140
|
+
/** The pointer is part of the gesture now: claimed from here on. */
|
|
141
|
+
promote(pointerId) {
|
|
142
|
+
const tracked = this.tracked_.get(pointerId);
|
|
143
|
+
if (tracked !== undefined) {
|
|
144
|
+
tracked.isProvisional = false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** The pointer goes back aside, its gesture over. */
|
|
148
|
+
demote(pointerId) {
|
|
149
|
+
const tracked = this.tracked_.get(pointerId);
|
|
150
|
+
if (tracked !== undefined) {
|
|
151
|
+
tracked.isProvisional = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Sets a `touch-action` until disposal. */
|
|
155
|
+
setTouchAction(value) {
|
|
156
|
+
const style = this.element.style;
|
|
157
|
+
const previous = style.touchAction;
|
|
158
|
+
style.touchAction = value;
|
|
159
|
+
this.onDispose(() => {
|
|
160
|
+
style.touchAction = previous;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Links the caller's signal and sets the `touch-action`; `false`, the binding
|
|
165
|
+
* already disposed, when the signal is aborted: nothing is bound.
|
|
166
|
+
*/
|
|
167
|
+
begin() {
|
|
168
|
+
const signal = this.options_.signal;
|
|
169
|
+
if (signal?.aborted === true) {
|
|
170
|
+
this[Symbol.dispose]();
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
// A dependent signal is aborted by the platform, not by an `abort` event, so
|
|
174
|
+
// no earlier listener of the caller's signal can keep the binding alive.
|
|
175
|
+
const linked = signal === undefined ? undefined : AbortSignal.any([signal]);
|
|
176
|
+
linked?.addEventListener("abort", () => {
|
|
177
|
+
this[Symbol.dispose]();
|
|
178
|
+
}, { once: true, signal: this.signal });
|
|
179
|
+
if (this.options_.touchAction !== undefined) {
|
|
180
|
+
this.setTouchAction(this.options_.touchAction);
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
/** Adds the listeners; called once the bindings' own state is set up. */
|
|
185
|
+
start() {
|
|
186
|
+
this.listen("pointerdown", (event) => {
|
|
187
|
+
this.onPointerDown_(event);
|
|
188
|
+
});
|
|
189
|
+
this.listen("pointermove", (event) => {
|
|
190
|
+
this.onPointerMove_(event);
|
|
191
|
+
});
|
|
192
|
+
this.listen("pointerup", (event) => {
|
|
193
|
+
this.onPointerUp_(event);
|
|
194
|
+
});
|
|
195
|
+
this.listen("pointercancel", (event) => {
|
|
196
|
+
this.onPointerCancel_(event);
|
|
197
|
+
});
|
|
198
|
+
this.listen("lostpointercapture", (event) => {
|
|
199
|
+
this.onLostCapture_(event);
|
|
200
|
+
});
|
|
201
|
+
this.listen("gotpointercapture", (event) => {
|
|
202
|
+
const tracked = this.tracked_.get(event.pointerId);
|
|
203
|
+
if (tracked?.isShared === true) {
|
|
204
|
+
tracked.captureOwner = event.target;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
this.listen("pointerleave", (event) => {
|
|
208
|
+
this.endHover_(event.pointerId, event);
|
|
209
|
+
});
|
|
210
|
+
const cancelWhilePressed = (event) => {
|
|
211
|
+
if (!this.disposed_ &&
|
|
212
|
+
this.options_.preventDefaultActions !== false &&
|
|
213
|
+
this.isActive) {
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
this.listen("dragstart", cancelWhilePressed);
|
|
218
|
+
this.listen("selectstart", cancelWhilePressed);
|
|
219
|
+
this.listen("contextmenu", (event) => {
|
|
220
|
+
this.onContextMenu_(event);
|
|
221
|
+
});
|
|
222
|
+
this.listen("click", (event) => {
|
|
223
|
+
if (!this.disposed_ &&
|
|
224
|
+
this.isClickSuppressed_ &&
|
|
225
|
+
event.detail !== 0) {
|
|
226
|
+
// The click that follows a drag is one, not every later one.
|
|
227
|
+
this.isClickSuppressed_ = false;
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
event.stopImmediatePropagation();
|
|
230
|
+
}
|
|
231
|
+
}, { capture: true });
|
|
232
|
+
// A pointer's end can reach the document and not the element: an ancestor
|
|
233
|
+
// that captured the pointer gets the release, and a captured element
|
|
234
|
+
// removed from the page loses its capture at the document.
|
|
235
|
+
const document = this.element.ownerDocument;
|
|
236
|
+
const onDocument = (type, listener) => {
|
|
237
|
+
document.addEventListener(type, listener, {
|
|
238
|
+
capture: true,
|
|
239
|
+
signal: this.signal,
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
onDocument("pointerup", (event) => {
|
|
243
|
+
this.onPointerUp_(event);
|
|
244
|
+
});
|
|
245
|
+
onDocument("pointercancel", (event) => {
|
|
246
|
+
this.onPointerCancel_(event);
|
|
247
|
+
});
|
|
248
|
+
onDocument("lostpointercapture", (event) => {
|
|
249
|
+
if (event.target === document) {
|
|
250
|
+
this.onDetachedCaptureLost_(event);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/** A capture lost at the document: its owner left the page. */
|
|
255
|
+
onDetachedCaptureLost_(event) {
|
|
256
|
+
const tracked = this.tracked_.get(event.pointerId);
|
|
257
|
+
if (this.disposed_ ||
|
|
258
|
+
tracked === undefined ||
|
|
259
|
+
!(tracked.isCaptured || tracked.captureOwner !== null)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
this.end_(event.pointerId);
|
|
263
|
+
this.notify(() => {
|
|
264
|
+
this.hooks_.cancel(event.pointerId, event);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
cancel() {
|
|
268
|
+
for (const id of this.trackedIds_()) {
|
|
269
|
+
if (this.tracked_.has(id)) {
|
|
270
|
+
this.end_(id);
|
|
271
|
+
this.notify(() => {
|
|
272
|
+
this.hooks_.cancel(id, undefined);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
[Symbol.dispose]() {
|
|
278
|
+
if (this.isDone_) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this.isDone_ = true;
|
|
282
|
+
this.controller_.abort();
|
|
283
|
+
for (const id of this.trackedIds_()) {
|
|
284
|
+
this.end_(id);
|
|
285
|
+
}
|
|
286
|
+
this.hovering_.clear();
|
|
287
|
+
this.cleanups_.dispose();
|
|
288
|
+
}
|
|
289
|
+
/** The ids now tracked, safe to walk while handlers add and remove some. */
|
|
290
|
+
trackedIds_() {
|
|
291
|
+
return Array.from(this.tracked_.keys());
|
|
292
|
+
}
|
|
293
|
+
end_(pointerId) {
|
|
294
|
+
const tracked = this.tracked_.get(pointerId);
|
|
295
|
+
if (tracked === undefined) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
this.tracked_.delete(pointerId);
|
|
299
|
+
if (tracked.isCaptured) {
|
|
300
|
+
try {
|
|
301
|
+
this.element.releasePointerCapture(pointerId);
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
// The pointer is gone already.
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return tracked;
|
|
308
|
+
}
|
|
309
|
+
endHover_(pointerId, event) {
|
|
310
|
+
if (this.hovering_.delete(pointerId)) {
|
|
311
|
+
this.notify(() => {
|
|
312
|
+
this.configuration_.hover?.onHoverEnd?.(pointerId, event);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
sampleOf_(event, frame, floor) {
|
|
317
|
+
const { x, y } = this.point(event.clientX, event.clientY, frame);
|
|
318
|
+
const time = event.timeStamp;
|
|
319
|
+
if (!(Number.isFinite(x) &&
|
|
320
|
+
Number.isFinite(y) &&
|
|
321
|
+
Number.isFinite(time) &&
|
|
322
|
+
Number.isInteger(event.pointerId) &&
|
|
323
|
+
Number.isInteger(event.buttons))) {
|
|
324
|
+
return undefined;
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
pointerId: event.pointerId,
|
|
328
|
+
kind: kindOf_(event),
|
|
329
|
+
x,
|
|
330
|
+
y,
|
|
331
|
+
time: Math.max(time, floor),
|
|
332
|
+
buttons: event.buttons,
|
|
333
|
+
shiftKey: event.shiftKey,
|
|
334
|
+
altKey: event.altKey,
|
|
335
|
+
ctrlKey: event.ctrlKey,
|
|
336
|
+
metaKey: event.metaKey,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
onPointerDown_(event) {
|
|
340
|
+
if (this.disposed_) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const isShared = isPointerEventClaimed(event);
|
|
344
|
+
if (isShared && this.options_.claimed !== "share") {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (this.tracked_.has(event.pointerId)) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
let allowed = true;
|
|
351
|
+
const accept = this.options_.accept;
|
|
352
|
+
if (accept !== undefined) {
|
|
353
|
+
try {
|
|
354
|
+
allowed = accept(event);
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
throwOutOfBand(error);
|
|
358
|
+
allowed = false;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (!allowed || this.disposed_) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const sample = this.sampleOf_(event, this.pointerFrame(), Number.NEGATIVE_INFINITY);
|
|
365
|
+
if (sample === undefined || !Number.isInteger(event.button)) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const down = { ...sample, button: event.button };
|
|
369
|
+
let accepted = false;
|
|
370
|
+
try {
|
|
371
|
+
accepted = this.hooks_.down(down, event);
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
throwOutOfBand(error);
|
|
375
|
+
}
|
|
376
|
+
if (accepted === false || this.disposed_) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const tracked = {
|
|
380
|
+
kind: down.kind,
|
|
381
|
+
isShared,
|
|
382
|
+
isProvisional: accepted === "provisional",
|
|
383
|
+
isCaptured: false,
|
|
384
|
+
captureOwner: null,
|
|
385
|
+
x: down.x,
|
|
386
|
+
y: down.y,
|
|
387
|
+
time: down.time,
|
|
388
|
+
};
|
|
389
|
+
this.tracked_.set(down.pointerId, tracked);
|
|
390
|
+
this.isClickSuppressed_ = false;
|
|
391
|
+
if (tracked.isProvisional) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (!isShared) {
|
|
395
|
+
claimPointerEvent(event);
|
|
396
|
+
if (this.options_.capture !== false &&
|
|
397
|
+
this.hooks_.captures?.(down) !== false) {
|
|
398
|
+
try {
|
|
399
|
+
this.element.setPointerCapture(down.pointerId);
|
|
400
|
+
tracked.isCaptured = true;
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
// A synthetic pointer id has no active pointer behind it.
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (this.options_.focusOnPress === true) {
|
|
408
|
+
this.element.focus({ preventScroll: true });
|
|
409
|
+
}
|
|
410
|
+
this.isClickSuppressed_ = false;
|
|
411
|
+
this.endHover_(down.pointerId, event);
|
|
412
|
+
this.notify(() => {
|
|
413
|
+
this.hooks_.accepted?.(down, event);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
onPointerMove_(event) {
|
|
417
|
+
if (this.disposed_) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const tracked = this.tracked_.get(event.pointerId);
|
|
421
|
+
if (tracked === undefined) {
|
|
422
|
+
this.onHoverMove_(event);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const frame = this.pointerFrame();
|
|
426
|
+
if (tracked.kind !== "touch" && event.buttons === 0) {
|
|
427
|
+
// A release the page never saw.
|
|
428
|
+
this.end_(event.pointerId);
|
|
429
|
+
const sample = {
|
|
430
|
+
pointerId: event.pointerId,
|
|
431
|
+
kind: tracked.kind,
|
|
432
|
+
x: tracked.x,
|
|
433
|
+
y: tracked.y,
|
|
434
|
+
time: Math.max(Number.isFinite(event.timeStamp) ? event.timeStamp : 0, tracked.time),
|
|
435
|
+
buttons: 0,
|
|
436
|
+
shiftKey: event.shiftKey,
|
|
437
|
+
altKey: event.altKey,
|
|
438
|
+
ctrlKey: event.ctrlKey,
|
|
439
|
+
metaKey: event.metaKey,
|
|
440
|
+
};
|
|
441
|
+
this.notify(() => {
|
|
442
|
+
this.hooks_.up(sample, event);
|
|
443
|
+
});
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
let events = [event];
|
|
447
|
+
if (this.options_.coalesced === true &&
|
|
448
|
+
typeof event.getCoalescedEvents === "function") {
|
|
449
|
+
const coalesced = event.getCoalescedEvents();
|
|
450
|
+
if (coalesced.length > 0) {
|
|
451
|
+
events = coalesced;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
for (const part of events) {
|
|
455
|
+
if (this.disposed_ || !this.tracked_.has(event.pointerId)) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const sample = this.sampleOf_(part, frame, tracked.time);
|
|
459
|
+
if (sample === undefined) {
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
tracked.x = sample.x;
|
|
463
|
+
tracked.y = sample.y;
|
|
464
|
+
tracked.time = sample.time;
|
|
465
|
+
this.notify(() => {
|
|
466
|
+
this.hooks_.move(sample, event);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
onHoverMove_(event) {
|
|
471
|
+
const hover = this.configuration_.hover;
|
|
472
|
+
if (hover?.onHover === undefined ||
|
|
473
|
+
kindOf_(event) === "touch" ||
|
|
474
|
+
event.buttons !== 0) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const sample = this.sampleOf_(event, this.liveFrame(), Number.NEGATIVE_INFINITY);
|
|
478
|
+
if (sample === undefined) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
this.hovering_.add(event.pointerId);
|
|
482
|
+
this.notify(() => {
|
|
483
|
+
hover.onHover?.(sample, event);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
onPointerUp_(event) {
|
|
487
|
+
if (this.disposed_) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (!this.tracked_.has(event.pointerId)) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
const frame = this.pointerFrame();
|
|
494
|
+
const tracked = this.end_(event.pointerId);
|
|
495
|
+
// An end must happen even when the release itself carries nothing usable.
|
|
496
|
+
const sample = this.sampleOf_(event, frame, tracked.time) ?? {
|
|
497
|
+
pointerId: event.pointerId,
|
|
498
|
+
kind: tracked.kind,
|
|
499
|
+
x: tracked.x,
|
|
500
|
+
y: tracked.y,
|
|
501
|
+
time: tracked.time,
|
|
502
|
+
buttons: 0,
|
|
503
|
+
};
|
|
504
|
+
this.notify(() => {
|
|
505
|
+
this.hooks_.up(sample, event);
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
onPointerCancel_(event) {
|
|
509
|
+
if (this.disposed_) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
this.endHover_(event.pointerId, event);
|
|
513
|
+
if (this.end_(event.pointerId) !== undefined) {
|
|
514
|
+
this.notify(() => {
|
|
515
|
+
this.hooks_.cancel(event.pointerId, event);
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
onLostCapture_(event) {
|
|
520
|
+
if (this.disposed_) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const tracked = this.tracked_.get(event.pointerId);
|
|
524
|
+
if (tracked === undefined) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
// A capture another surface lost, bubbling up, is not ours; a sharing
|
|
528
|
+
// surface follows the one that owns the capture.
|
|
529
|
+
const owner = tracked.isShared ? tracked.captureOwner : this.element;
|
|
530
|
+
if ((!tracked.isShared && !tracked.isCaptured) ||
|
|
531
|
+
owner === null ||
|
|
532
|
+
event.target !== owner) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
this.end_(event.pointerId);
|
|
536
|
+
this.notify(() => {
|
|
537
|
+
this.hooks_.cancel(event.pointerId, event);
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
onContextMenu_(event) {
|
|
541
|
+
if (this.disposed_) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
let isTouchLike = false;
|
|
545
|
+
for (const tracked of this.tracked_.values()) {
|
|
546
|
+
isTouchLike ||= tracked.kind !== "mouse";
|
|
547
|
+
}
|
|
548
|
+
if (this.options_.preventContextMenu === true ||
|
|
549
|
+
(this.configuration_.impliesContextMenuPrevention && isTouchLike)) {
|
|
550
|
+
event.preventDefault();
|
|
551
|
+
}
|
|
552
|
+
if (isTouchLike) {
|
|
553
|
+
this.notify(() => {
|
|
554
|
+
this.hooks_.contextMenu?.(event);
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
//# sourceMappingURL=_pointer-engine.js.map
|