@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,74 @@
|
|
|
1
|
+
import { assertNonNegative } from "@ac-kit/core";
|
|
2
|
+
import { vec2Create, vec2LengthScaled, vec2Set } from "@ac-kit/math-linear";
|
|
3
|
+
import { POINTER_SLOP, } from "./pointer-input.js";
|
|
4
|
+
const scratch_ = vec2Create();
|
|
5
|
+
/** Checks a slop option and returns it with the default filled in. */
|
|
6
|
+
export function checkedSlop_(slop) {
|
|
7
|
+
if (slop === undefined) {
|
|
8
|
+
return POINTER_SLOP;
|
|
9
|
+
}
|
|
10
|
+
if (typeof slop === "number") {
|
|
11
|
+
assertNonNegative(slop, "slop");
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
assertNonNegative(slop.mouse, "slop.mouse");
|
|
15
|
+
assertNonNegative(slop.pen, "slop.pen");
|
|
16
|
+
assertNonNegative(slop.touch, "slop.touch");
|
|
17
|
+
}
|
|
18
|
+
return slop;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The slop of a kind; a kind the type does not name reads as touch, as the
|
|
22
|
+
* bindings do.
|
|
23
|
+
*/
|
|
24
|
+
export function slopOf_(slop, kind) {
|
|
25
|
+
if (typeof slop === "number") {
|
|
26
|
+
return slop;
|
|
27
|
+
}
|
|
28
|
+
return slop[kind] ?? slop.touch;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether a movement of `(dx, dy)` is still within `slop`: none at all always
|
|
32
|
+
* is.
|
|
33
|
+
*/
|
|
34
|
+
export function isWithinSlop_(dx, dy, slop) {
|
|
35
|
+
return (dx === 0 && dy === 0) || compareLength_(dx, dy, slop) < 0;
|
|
36
|
+
}
|
|
37
|
+
// Squares and their sums stay exact and finite between these.
|
|
38
|
+
const SQUARE_MIN_ = 1e-200;
|
|
39
|
+
const SQUARE_MAX_ = 1e200;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the vector `(dx, dy)` is shorter than (−1), as long as (0) or longer
|
|
42
|
+
* than (1) `limit`, at any scale: a distance is compared as squares only where
|
|
43
|
+
* a square neither overflows nor underflows, else through its larger component.
|
|
44
|
+
* `Math.hypot` is not an option on a per-event path (several times slower).
|
|
45
|
+
*/
|
|
46
|
+
export function compareLength_(dx, dy, limit) {
|
|
47
|
+
const squared = dx * dx + dy * dy;
|
|
48
|
+
const limitSquared = limit * limit;
|
|
49
|
+
if (squared > SQUARE_MIN_ &&
|
|
50
|
+
squared < SQUARE_MAX_ &&
|
|
51
|
+
limitSquared > SQUARE_MIN_ &&
|
|
52
|
+
limitSquared < SQUARE_MAX_) {
|
|
53
|
+
return squared < limitSquared ? -1 : squared > limitSquared ? 1 : 0;
|
|
54
|
+
}
|
|
55
|
+
const length = scaledLength_(dx, dy);
|
|
56
|
+
if (length === 0) {
|
|
57
|
+
return limit === 0 ? 0 : -1;
|
|
58
|
+
}
|
|
59
|
+
return length < limit ? -1 : length > limit ? 1 : 0;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The length of `(dx, dy)`, finite whenever the result is representable, with
|
|
63
|
+
* no `Math.hypot`: `Infinity` only for a length beyond the double range.
|
|
64
|
+
*/
|
|
65
|
+
export function lengthOf_(dx, dy) {
|
|
66
|
+
const squared = dx * dx + dy * dy;
|
|
67
|
+
return squared > SQUARE_MIN_ && squared < SQUARE_MAX_
|
|
68
|
+
? Math.sqrt(squared)
|
|
69
|
+
: scaledLength_(dx, dy);
|
|
70
|
+
}
|
|
71
|
+
function scaledLength_(dx, dy) {
|
|
72
|
+
return vec2LengthScaled(vec2Set(scratch_, dx, dy));
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=_slop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_slop.js","sourceRoot":"","sources":["../../src/pointer/_slop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EACN,YAAY,GAGZ,MAAM,oBAAoB,CAAC;AAE5B,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAC;AAE9B,sEAAsE;AACtE,MAAM,UAAU,YAAY,CAAC,IAA6B;IACzD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,YAAY,CAAC;IACrB,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACjC,CAAC;SAAM,CAAC;QACP,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,CAAC;IACD,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,EAAU,EAAE,EAAU;IAC/C,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAElC,OAAO,OAAO,GAAG,WAAW,IAAI,OAAO,GAAG,WAAW;QACpD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;QACpB,CAAC,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,aAAa,CAAC,EAAU,EAAE,EAAU;IAC5C,OAAO,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The device behind a pointer, as `PointerEvent.pointerType` names it; the
|
|
3
|
+
* bindings read any other value as `touch`.
|
|
4
|
+
*/
|
|
5
|
+
export type PointerKind = "mouse" | "pen" | "touch";
|
|
6
|
+
/** Modifier keys held during an input; an absent key is not held. */
|
|
7
|
+
export type ModifierKeys = {
|
|
8
|
+
readonly shiftKey?: boolean;
|
|
9
|
+
readonly altKey?: boolean;
|
|
10
|
+
readonly ctrlKey?: boolean;
|
|
11
|
+
readonly metaKey?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** One position of one pointer. */
|
|
14
|
+
export type PointerSample = ModifierKeys & {
|
|
15
|
+
readonly pointerId: number;
|
|
16
|
+
readonly kind: PointerKind;
|
|
17
|
+
/** Right positive. */
|
|
18
|
+
readonly x: number;
|
|
19
|
+
/** Down positive, as client coordinates run. */
|
|
20
|
+
readonly y: number;
|
|
21
|
+
/** Milliseconds on a monotonic clock. */
|
|
22
|
+
readonly time: number;
|
|
23
|
+
/**
|
|
24
|
+
* `PointerEvent.buttons`: 1 primary (and touch or pen contact), 2 secondary
|
|
25
|
+
* (pen barrel), 4 auxiliary.
|
|
26
|
+
*/
|
|
27
|
+
readonly buttons: number;
|
|
28
|
+
};
|
|
29
|
+
/** A pointer going down. */
|
|
30
|
+
export type PointerDown = PointerSample & {
|
|
31
|
+
/**
|
|
32
|
+
* `PointerEvent.button`: 0 primary (touch and pen contact too), 1 auxiliary,
|
|
33
|
+
* 2 secondary.
|
|
34
|
+
*/
|
|
35
|
+
readonly button: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* How far a pointer may move and still count as still: one distance, or one per
|
|
39
|
+
* kind.
|
|
40
|
+
*/
|
|
41
|
+
export type PointerSlop = number | Readonly<Record<PointerKind, number>>;
|
|
42
|
+
/**
|
|
43
|
+
* Default slop, a distance: 4 px for a mouse (Windows' default drag threshold),
|
|
44
|
+
* 8 px for touch and pen (Android's touch slop, in dp).
|
|
45
|
+
*/
|
|
46
|
+
export declare const POINTER_SLOP: Readonly<Record<PointerKind, number>>;
|
|
47
|
+
/**
|
|
48
|
+
* Where a gesture is: begun past the slop, moving, ended by a release, or
|
|
49
|
+
* abandoned.
|
|
50
|
+
*/
|
|
51
|
+
export type GesturePhase = "start" | "move" | "end" | "cancel";
|
|
52
|
+
/** A tap, double tap or long press: where and when, and by what. */
|
|
53
|
+
export type TapEvent = {
|
|
54
|
+
readonly pointerId: number;
|
|
55
|
+
readonly kind: PointerKind;
|
|
56
|
+
readonly button: number;
|
|
57
|
+
readonly x: number;
|
|
58
|
+
readonly y: number;
|
|
59
|
+
readonly time: number;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=pointer-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointer-input.d.ts","sourceRoot":"","sources":["../../src/pointer/pointer-input.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;AAEpD,qEAAqE;AACrE,MAAM,MAAM,YAAY,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,sBAAsB;IACtB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,4BAA4B;AAC5B,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG;IACzC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CACjB,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE/D,oEAAoE;AACpE,MAAM,MAAM,QAAQ,GAAG;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointer-input.js","sourceRoot":"","sources":["../../src/pointer/pointer-input.ts"],"names":[],"mappings":"AA8CA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GACxB,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import type { GesturePhase, PointerDown, PointerKind, PointerSample, PointerSlop, TapEvent } from "../pointer/pointer-input.js";
|
|
2
|
+
export type DragAxis = "x" | "y";
|
|
3
|
+
/** Options of a double tap. */
|
|
4
|
+
export type DoubleTapOptions = {
|
|
5
|
+
/** Longest time from the first release to the second press, in ms. Default 300. */
|
|
6
|
+
readonly interval?: number;
|
|
7
|
+
/** Shortest such time; faster is a bounce, in ms. Default 40. */
|
|
8
|
+
readonly minInterval?: number;
|
|
9
|
+
/** Farthest the second press may land from the first. Default 100. */
|
|
10
|
+
readonly slop?: number;
|
|
11
|
+
};
|
|
12
|
+
/** Options of a long press. */
|
|
13
|
+
export type LongPressOptions = {
|
|
14
|
+
/** How long a still press lasts before it is a long press, in ms. Default 500. */
|
|
15
|
+
readonly delay?: number;
|
|
16
|
+
};
|
|
17
|
+
/** When a drag's end is a swipe along an axis. */
|
|
18
|
+
export type SwipeOptions = {
|
|
19
|
+
/** Least movement from the press along the axis. Default 50. */
|
|
20
|
+
readonly minDistance?: number;
|
|
21
|
+
/** Least release speed along the axis, per ms. Default 0.5. */
|
|
22
|
+
readonly minVelocity?: number;
|
|
23
|
+
};
|
|
24
|
+
/** Options of {@link PressGesture}. */
|
|
25
|
+
export type PressGestureOptions = {
|
|
26
|
+
/** Default {@link POINTER_SLOP}. */
|
|
27
|
+
readonly slop?: PointerSlop;
|
|
28
|
+
/** `PointerEvent.button` values that start a press. Default `[0]`. */
|
|
29
|
+
readonly buttons?: readonly number[];
|
|
30
|
+
/**
|
|
31
|
+
* A fixed axis, where a press whose first movement past the slop runs along
|
|
32
|
+
* the other axis is abandoned; or `lock`, where that first movement chooses
|
|
33
|
+
* the axis. Default: both axes, unlocked.
|
|
34
|
+
*/
|
|
35
|
+
readonly axis?: DragAxis | "lock";
|
|
36
|
+
/**
|
|
37
|
+
* Whether the first drag delta counts from the press or from where the slop
|
|
38
|
+
* was crossed. Default `slop`.
|
|
39
|
+
*/
|
|
40
|
+
readonly dragFrom?: "press" | "slop";
|
|
41
|
+
/**
|
|
42
|
+
* Whether, and how, a second tap makes a double tap. Default `false`: every
|
|
43
|
+
* tap is single at once.
|
|
44
|
+
*/
|
|
45
|
+
readonly doubleTap?: boolean | DoubleTapOptions;
|
|
46
|
+
/** Whether, and how, a still press becomes a long press. Default `false`. */
|
|
47
|
+
readonly longPress?: boolean | LongPressOptions;
|
|
48
|
+
/** A press held longer than this is not a tap, in ms. Default `Infinity`. */
|
|
49
|
+
readonly tapMaxDuration?: number;
|
|
50
|
+
readonly swipe?: SwipeOptions;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A drag of one pointer. One shape for every phase; end-only fields are 0
|
|
54
|
+
* otherwise.
|
|
55
|
+
*/
|
|
56
|
+
export type DragUpdate = {
|
|
57
|
+
readonly phase: GesturePhase;
|
|
58
|
+
readonly pointerId: number;
|
|
59
|
+
readonly kind: PointerKind;
|
|
60
|
+
readonly button: number;
|
|
61
|
+
/** The locked or fixed axis; `undefined` when both axes move. */
|
|
62
|
+
readonly axis: DragAxis | undefined;
|
|
63
|
+
readonly x: number;
|
|
64
|
+
readonly y: number;
|
|
65
|
+
/** Since the press, slop included. */
|
|
66
|
+
readonly movementX: number;
|
|
67
|
+
readonly movementY: number;
|
|
68
|
+
/** Since the previous update; 0 at `start` unless `dragFrom` is `press`. */
|
|
69
|
+
readonly deltaX: number;
|
|
70
|
+
readonly deltaY: number;
|
|
71
|
+
/** At `end`: the release velocity, per ms. */
|
|
72
|
+
readonly velocityX: number;
|
|
73
|
+
readonly velocityY: number;
|
|
74
|
+
/** At `end`: −1 or 1 when the drag was a swipe along that axis. */
|
|
75
|
+
readonly swipeX: -1 | 0 | 1;
|
|
76
|
+
readonly swipeY: -1 | 0 | 1;
|
|
77
|
+
readonly time: number;
|
|
78
|
+
readonly shiftKey: boolean;
|
|
79
|
+
readonly altKey: boolean;
|
|
80
|
+
readonly ctrlKey: boolean;
|
|
81
|
+
readonly metaKey: boolean;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* What a release ended:
|
|
85
|
+
*
|
|
86
|
+
* - `drag` — the end update of a drag. A release past the slop that no `move`
|
|
87
|
+
* reported is a drag that starts and ends at once: its `end` update is the
|
|
88
|
+
* only one, with the deltas the `start` would have had.
|
|
89
|
+
* - `tap` — a tap that may still become a double tap; ask
|
|
90
|
+
* {@link PressGesture.resolve} at `deadline`.
|
|
91
|
+
* - `single-tap` — a tap, settled (double tap off).
|
|
92
|
+
* - `double-tap` — the second tap of a double tap; the first's pending tap is
|
|
93
|
+
* withdrawn.
|
|
94
|
+
* - `long-press-end` — the release of a long press (not a tap).
|
|
95
|
+
* - `none` — a press that is none of these: abandoned on the wrong axis, joined
|
|
96
|
+
* by a second pointer, or held past `tapMaxDuration`.
|
|
97
|
+
* - `ignored` — not the pointer followed, or no press.
|
|
98
|
+
*/
|
|
99
|
+
export type PressRelease = {
|
|
100
|
+
readonly kind: "drag";
|
|
101
|
+
readonly update: DragUpdate;
|
|
102
|
+
} | {
|
|
103
|
+
readonly kind: "tap";
|
|
104
|
+
readonly tap: TapEvent;
|
|
105
|
+
readonly deadline: number;
|
|
106
|
+
} | {
|
|
107
|
+
readonly kind: "single-tap";
|
|
108
|
+
readonly tap: TapEvent;
|
|
109
|
+
} | {
|
|
110
|
+
readonly kind: "double-tap";
|
|
111
|
+
readonly tap: TapEvent;
|
|
112
|
+
} | {
|
|
113
|
+
readonly kind: "long-press-end";
|
|
114
|
+
readonly tap: TapEvent;
|
|
115
|
+
} | {
|
|
116
|
+
readonly kind: "none";
|
|
117
|
+
} | {
|
|
118
|
+
readonly kind: "ignored";
|
|
119
|
+
};
|
|
120
|
+
/** What became due at a time: see {@link PressGesture.resolve}. */
|
|
121
|
+
export type PressResolution = {
|
|
122
|
+
readonly kind: "single-tap";
|
|
123
|
+
readonly tap: TapEvent;
|
|
124
|
+
} | {
|
|
125
|
+
readonly kind: "long-press";
|
|
126
|
+
readonly tap: TapEvent;
|
|
127
|
+
} | {
|
|
128
|
+
readonly kind: "none";
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Everything one press of one pointer can mean — a tap, a double tap, a long
|
|
132
|
+
* press, a drag — arbitrated in one place, as Android's `GestureDetector` does:
|
|
133
|
+
* a drag past the slop withdraws the tap and the long press; a fired long press
|
|
134
|
+
* withdraws the tap (a later move past the slop still drags); a second pointer
|
|
135
|
+
* withdraws both. Times are passed in; timers are the caller's: schedule a call
|
|
136
|
+
* to {@link PressGesture.resolve} at {@link PressGesture.deadline}, and read
|
|
137
|
+
* `deadline` again after every call, since any of them can change it.
|
|
138
|
+
*
|
|
139
|
+
* A tap is held back for a second tap only while a second tap is possible: a
|
|
140
|
+
* press that lands in time and place for one keeps the first tap from settling,
|
|
141
|
+
* and the first tap settles at once, as a single tap for `resolve` to report,
|
|
142
|
+
* when that press turns out to be anything but a tap (or any other press lands
|
|
143
|
+
* out of time or place), or can no longer be one (held past `tapMaxDuration`).
|
|
144
|
+
*
|
|
145
|
+
* What a press is follows from the times of the events, never from when the
|
|
146
|
+
* caller asked `resolve`. An event at time `T` first settles whatever fell due
|
|
147
|
+
* before `T`: a long press whose delay has passed fires, a tap whose interval
|
|
148
|
+
* has passed settles. Those resolutions wait for the next `resolve`, which
|
|
149
|
+
* reports each once (`long-press` carries the time it fell due), so an event
|
|
150
|
+
* can come back before the resolution that explains it: call `resolve` with the
|
|
151
|
+
* event's time before passing the event, as the DOM bindings do, to keep them
|
|
152
|
+
* in order. At exactly the time something falls due, the call order decides: an
|
|
153
|
+
* event passed before `resolve(T)` is processed first (a second press exactly
|
|
154
|
+
* `interval` ms after the first release is a double tap, a release exactly at
|
|
155
|
+
* the long-press delay is a tap, one exactly at `tapMaxDuration` is a tap), and
|
|
156
|
+
* `resolve(T)` first settles it. Taps settle at the time their cause happened
|
|
157
|
+
* and are reported by a `resolve` at or after it, never before, and never lost:
|
|
158
|
+
* a caller that never resolves accumulates one small record per settled tap.
|
|
159
|
+
*
|
|
160
|
+
* The press has a clock: the latest time one of its events or a resolution it
|
|
161
|
+
* settled carried. `move`, `release`, `resolve` and `signalLongPress` take a
|
|
162
|
+
* time on the press's own time line, so a time before the clock is a
|
|
163
|
+
* `RangeError` and changes nothing; another pointer's time, which ends no
|
|
164
|
+
* press, need not interleave. A caller that polls with a time earlier than an
|
|
165
|
+
* event it has not yet delivered passes `Math.max` of the two.
|
|
166
|
+
*
|
|
167
|
+
* Every method is O(1), except the end of a drag, O(capacity) for the velocity.
|
|
168
|
+
*/
|
|
169
|
+
export declare class PressGesture {
|
|
170
|
+
private readonly slop_;
|
|
171
|
+
private readonly buttons_;
|
|
172
|
+
private readonly axisOption_;
|
|
173
|
+
private readonly dragFrom_;
|
|
174
|
+
private readonly doubleTap_;
|
|
175
|
+
private readonly longPressDelay_;
|
|
176
|
+
private readonly tapMaxDuration_;
|
|
177
|
+
private readonly swipe_;
|
|
178
|
+
private readonly tracker_;
|
|
179
|
+
private press_;
|
|
180
|
+
private pending_;
|
|
181
|
+
private readonly queue_;
|
|
182
|
+
private lastQueuedAt_;
|
|
183
|
+
constructor(options?: PressGestureOptions);
|
|
184
|
+
/** Whether a pointer is down. */
|
|
185
|
+
get isPressed(): boolean;
|
|
186
|
+
/** Whether the pointer down has started a drag. */
|
|
187
|
+
get isDragging(): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* The earliest time {@link PressGesture.resolve} has something to report, or
|
|
190
|
+
* `undefined`: a settled resolution's time, a long press's delay, the end of
|
|
191
|
+
* a tap's interval, or the first instant a press held for a second tap can no
|
|
192
|
+
* longer be a tap.
|
|
193
|
+
*/
|
|
194
|
+
get deadline(): number | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Starts following `down`; `false` when ignored: another pointer is down
|
|
197
|
+
* (which withdraws the tap of the one followed, unless it is that very
|
|
198
|
+
* pointer, which changes nothing), or a button not accepted.
|
|
199
|
+
*
|
|
200
|
+
* @throws {RangeError} For a non-finite field.
|
|
201
|
+
*/
|
|
202
|
+
press(down: PointerDown): boolean;
|
|
203
|
+
/**
|
|
204
|
+
* A drag update once past the slop; `undefined` before, after an abandon, and
|
|
205
|
+
* for another pointer. The first update is the `start`, counted from where
|
|
206
|
+
* the slop was crossed unless `dragFrom` is `press`.
|
|
207
|
+
*
|
|
208
|
+
* @throws {RangeError} For a non-finite field, or a time before the pointer's
|
|
209
|
+
* last one.
|
|
210
|
+
*/
|
|
211
|
+
move(sample: PointerSample): DragUpdate | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* Ends the press of the pointer and says what it was. The release is a
|
|
214
|
+
* movement like any other: one past the slop that no `move` reported is a
|
|
215
|
+
* drag that starts and ends at once, its `end` update the only one (carrying
|
|
216
|
+
* what the `start` would have: no delta, or the whole movement for `dragFrom:
|
|
217
|
+
* "press"`), and along the other axis of a fixed one it abandons the press.
|
|
218
|
+
*
|
|
219
|
+
* @throws {RangeError} For a non-finite field, or a time before the pointer's
|
|
220
|
+
* last one.
|
|
221
|
+
*/
|
|
222
|
+
release(sample: PointerSample): PressRelease;
|
|
223
|
+
/**
|
|
224
|
+
* Abandons the press, as on `pointercancel`; a `cancel` update when a drag
|
|
225
|
+
* was under way. Without `pointerId`, whichever is down.
|
|
226
|
+
*/
|
|
227
|
+
cancel(pointerId?: number): DragUpdate | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* A single tap whose interval has passed, or a long press whose delay has;
|
|
230
|
+
* each reported once, once `time` has reached the moment it fell due (a
|
|
231
|
+
* `long-press` carries that moment as its time). Call it again until it
|
|
232
|
+
* reports `none`: several things can be due at once.
|
|
233
|
+
*
|
|
234
|
+
* @throws {RangeError} For a non-finite `time`, or one before the clock of
|
|
235
|
+
* the press that is down; nothing changes then.
|
|
236
|
+
*/
|
|
237
|
+
resolve(time: number): PressResolution;
|
|
238
|
+
/**
|
|
239
|
+
* The platform signalled a long press (a `contextmenu` during a still touch
|
|
240
|
+
* or pen press): a `long-press` now if the press is still a candidate (long
|
|
241
|
+
* press on, within the slop, not yet fired); `none` otherwise.
|
|
242
|
+
*
|
|
243
|
+
* @throws {RangeError} For a non-finite `time`, or one before the clock of
|
|
244
|
+
* the press that is down; nothing changes then.
|
|
245
|
+
*/
|
|
246
|
+
signalLongPress(time: number): PressResolution;
|
|
247
|
+
private checkTime_;
|
|
248
|
+
/**
|
|
249
|
+
* Settles, in the order they fell due, what fell due before `time` (at it,
|
|
250
|
+
* too, when `inclusive`): a tap whose interval ended, a long press whose
|
|
251
|
+
* delay passed, a press held for a second tap that can no longer be a tap.
|
|
252
|
+
* Each moves the press's clock to the moment it fell due.
|
|
253
|
+
*/
|
|
254
|
+
private drain_;
|
|
255
|
+
/**
|
|
256
|
+
* The first instant a press can no longer be a tap: a release exactly at
|
|
257
|
+
* `tapMaxDuration` still is one.
|
|
258
|
+
*/
|
|
259
|
+
private holdExpiry_;
|
|
260
|
+
private tapOf_;
|
|
261
|
+
private follow_;
|
|
262
|
+
/**
|
|
263
|
+
* The drag the followed pointer's position starts, if it is past the slop:
|
|
264
|
+
* its `start` update; `undefined` within the slop, and when the press is
|
|
265
|
+
* abandoned for running along the other axis of a fixed one.
|
|
266
|
+
*/
|
|
267
|
+
private startDrag_;
|
|
268
|
+
/** Whether `down` lands in time and place to be the second tap of `pending`. */
|
|
269
|
+
private isSecondTap_;
|
|
270
|
+
/** `undefined` for no axis, `null` for a press abandoned on the wrong axis. */
|
|
271
|
+
private axisOfFirstMovement_;
|
|
272
|
+
/** The press is no longer a tap: nor a long press, nor a second tap. */
|
|
273
|
+
private withdrawTap_;
|
|
274
|
+
/** The first tap this press held back can no longer become a double tap. */
|
|
275
|
+
private releaseHold_;
|
|
276
|
+
private settlePending_;
|
|
277
|
+
private enqueue_;
|
|
278
|
+
/** The press has become a long press: no longer a tap, at `at`. */
|
|
279
|
+
private markLongPress_;
|
|
280
|
+
private update_;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=press-gesture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"press-gesture.d.ts","sourceRoot":"","sources":["../../src/press/press-gesture.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACX,QAAQ,EACR,MAAM,6BAA6B,CAAC;AAMrC,MAAM,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,CAAC;AAEjC,+BAA+B;AAC/B,MAAM,MAAM,gBAAgB,GAAG;IAC9B,mFAAmF;IACnF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,iEAAiE;IACjE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,CAAC,EAAE,M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