@ac-kit/ui-gesture 0.0.0-stage → 0.1.0

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/LICENSE +28 -0
  3. package/README.md +310 -2
  4. package/dist/_validate.d.ts +4 -0
  5. package/dist/_validate.d.ts.map +1 -0
  6. package/dist/_validate.js +10 -0
  7. package/dist/_validate.js.map +1 -0
  8. package/dist/dom/_claim.d.ts +8 -0
  9. package/dist/dom/_claim.d.ts.map +1 -0
  10. package/dist/dom/_claim.js +14 -0
  11. package/dist/dom/_claim.js.map +1 -0
  12. package/dist/dom/_pointer-engine.d.ts +121 -0
  13. package/dist/dom/_pointer-engine.d.ts.map +1 -0
  14. package/dist/dom/_pointer-engine.js +559 -0
  15. package/dist/dom/_pointer-engine.js.map +1 -0
  16. package/dist/dom/_press-driver.d.ts +39 -0
  17. package/dist/dom/_press-driver.d.ts.map +1 -0
  18. package/dist/dom/_press-driver.js +121 -0
  19. package/dist/dom/_press-driver.js.map +1 -0
  20. package/dist/dom/index.d.ts +5 -0
  21. package/dist/dom/index.d.ts.map +1 -0
  22. package/dist/dom/index.js +5 -0
  23. package/dist/dom/index.js.map +1 -0
  24. package/dist/dom/pointer-binding.d.ts +111 -0
  25. package/dist/dom/pointer-binding.d.ts.map +1 -0
  26. package/dist/dom/pointer-binding.js +35 -0
  27. package/dist/dom/pointer-binding.js.map +1 -0
  28. package/dist/dom/press-binding.d.ts +29 -0
  29. package/dist/dom/press-binding.d.ts.map +1 -0
  30. package/dist/dom/press-binding.js +53 -0
  31. package/dist/dom/press-binding.js.map +1 -0
  32. package/dist/dom/transform-binding.d.ts +81 -0
  33. package/dist/dom/transform-binding.d.ts.map +1 -0
  34. package/dist/dom/transform-binding.js +349 -0
  35. package/dist/dom/transform-binding.js.map +1 -0
  36. package/dist/index.d.ts +8 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +8 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/inertia/inertia.d.ts +32 -0
  41. package/dist/inertia/inertia.d.ts.map +1 -0
  42. package/dist/inertia/inertia.js +62 -0
  43. package/dist/inertia/inertia.js.map +1 -0
  44. package/dist/keys/key-step.d.ts +25 -0
  45. package/dist/keys/key-step.d.ts.map +1 -0
  46. package/dist/keys/key-step.js +30 -0
  47. package/dist/keys/key-step.js.map +1 -0
  48. package/dist/pointer/_slop.d.ts +26 -0
  49. package/dist/pointer/_slop.d.ts.map +1 -0
  50. package/dist/pointer/_slop.js +74 -0
  51. package/dist/pointer/_slop.js.map +1 -0
  52. package/dist/pointer/pointer-input.d.ts +61 -0
  53. package/dist/pointer/pointer-input.d.ts.map +1 -0
  54. package/dist/pointer/pointer-input.js +6 -0
  55. package/dist/pointer/pointer-input.js.map +1 -0
  56. package/dist/press/press-gesture.d.ts +282 -0
  57. package/dist/press/press-gesture.d.ts.map +1 -0
  58. package/dist/press/press-gesture.js +579 -0
  59. package/dist/press/press-gesture.js.map +1 -0
  60. package/dist/transform/transform-gesture.d.ts +174 -0
  61. package/dist/transform/transform-gesture.d.ts.map +1 -0
  62. package/dist/transform/transform-gesture.js +415 -0
  63. package/dist/transform/transform-gesture.js.map +1 -0
  64. package/dist/velocity/velocity-tracker.d.ts +69 -0
  65. package/dist/velocity/velocity-tracker.d.ts.map +1 -0
  66. package/dist/velocity/velocity-tracker.js +152 -0
  67. package/dist/velocity/velocity-tracker.js.map +1 -0
  68. package/dist/wheel/wheel.d.ts +115 -0
  69. package/dist/wheel/wheel.d.ts.map +1 -0
  70. package/dist/wheel/wheel.js +162 -0
  71. package/dist/wheel/wheel.js.map +1 -0
  72. package/package.json +79 -3
@@ -0,0 +1,174 @@
1
+ import type { GesturePhase, PointerDown, PointerKind, PointerSample, PointerSlop } from "../pointer/pointer-input.js";
2
+ /** Options of {@link TransformGesture}. */
3
+ export type TransformGestureOptions = {
4
+ /**
5
+ * Default {@link POINTER_SLOP}; any pointer moving past it starts the
6
+ * gesture.
7
+ */
8
+ readonly slop?: PointerSlop;
9
+ /** `PointerEvent.button` values a first pointer may press with. Default `[0]`. */
10
+ readonly buttons?: readonly number[];
11
+ /** Pointers followed at once; later ones wait until one lifts. Default 2. */
12
+ readonly maxPointers?: number;
13
+ /** Device kinds accepted. Default all. */
14
+ readonly kinds?: readonly PointerKind[];
15
+ };
16
+ /**
17
+ * A pan, pinch and twist of up to `maxPointers` pointers, as one change of the
18
+ * view: the centroid's movement, the ratio of the spread (mean distance to the
19
+ * centroid) and the turn of the line through the first two pointers. With one
20
+ * pointer, a pan: `scaleFactor` 1, `rotationDelta` 0.
21
+ */
22
+ export type TransformUpdate = {
23
+ readonly phase: GesturePhase;
24
+ readonly pointerCount: number;
25
+ /**
26
+ * The first pointer's kind and button, which every pointer of the gesture
27
+ * shares.
28
+ */
29
+ readonly kind: PointerKind;
30
+ readonly button: number;
31
+ /** The centroid now: the point a pinch zooms about. */
32
+ readonly originX: number;
33
+ readonly originY: number;
34
+ /** Since the previous update. */
35
+ readonly deltaX: number;
36
+ readonly deltaY: number;
37
+ readonly scaleFactor: number;
38
+ /** Radians, positive clockwise on screen, in (−π, π]. */
39
+ readonly rotationDelta: number;
40
+ /** Since `start`. */
41
+ readonly movementX: number;
42
+ readonly movementY: number;
43
+ readonly scale: number;
44
+ readonly rotation: number;
45
+ /** At `end`: the centroid's release velocity, per ms. */
46
+ readonly velocityX: number;
47
+ readonly velocityY: number;
48
+ readonly time: number;
49
+ readonly shiftKey: boolean;
50
+ readonly altKey: boolean;
51
+ readonly ctrlKey: boolean;
52
+ readonly metaKey: boolean;
53
+ };
54
+ /**
55
+ * What produced a {@link TransformStep}: a plain wheel, a trackpad pinch (small
56
+ * `ctrlKey` wheel deltas), Ctrl or ⌘ held with a wheel, or Safari's trackpad
57
+ * gesture events.
58
+ */
59
+ export type TransformStepSource = "wheel" | "pinch-wheel" | "modified-wheel" | "trackpad-gesture";
60
+ /** A discrete change of the view, from the wheel or a trackpad gesture. */
61
+ export type TransformStep = {
62
+ readonly source: TransformStepSource;
63
+ readonly originX: number;
64
+ readonly originY: number;
65
+ readonly deltaX: number;
66
+ readonly deltaY: number;
67
+ readonly scaleFactor: number;
68
+ readonly rotationDelta: number;
69
+ readonly time: number;
70
+ };
71
+ /**
72
+ * Follows several pointers as one transform. Adding or lifting a pointer
73
+ * rebases the centroid, spread and angle, so no update jumps. A zero spread
74
+ * (two pointers on one spot) gives a scale factor and a rotation of 1 and 0.
75
+ * Cancelling any pointer abandons the whole gesture. Each pointer has its own
76
+ * velocity tracker on its own time line, so one pointer's samples may be older
77
+ * than another's; the end velocity is the last pointer's. Each move is
78
+ * O(pointers) and allocates only its update.
79
+ *
80
+ * Pointers of one gesture share a device kind and a button: the first one's. A
81
+ * pointer ignored at its press is never followed, even after another lifts.
82
+ *
83
+ * A release is a movement like any other. A pointer that lifts at a position
84
+ * other than its last one hands that movement over: as a `move` update when
85
+ * others stay (or the `start`, when it is the first past the slop), and within
86
+ * the `end` update when it is the last. The last pointer's release past the
87
+ * slop, before any `move` reported it, is a gesture that starts and ends at
88
+ * once: its `end` update is the only one, with no delta.
89
+ */
90
+ export declare class TransformGesture {
91
+ private readonly slop_;
92
+ private readonly buttons_;
93
+ private readonly maxPointers_;
94
+ private readonly kinds_;
95
+ private readonly pointers_;
96
+ private readonly spareTrackers_;
97
+ private kind_;
98
+ private button_;
99
+ private started_;
100
+ private readonly measures_;
101
+ private movementX_;
102
+ private movementY_;
103
+ private scale_;
104
+ private rotation_;
105
+ private lastTime_;
106
+ private shiftKey_;
107
+ private altKey_;
108
+ private ctrlKey_;
109
+ private metaKey_;
110
+ constructor(options?: TransformGestureOptions);
111
+ /** How many pointers are followed. */
112
+ get pointerCount(): number;
113
+ /** Whether the gesture has started (moved past the slop). */
114
+ get isActive(): boolean;
115
+ /**
116
+ * Starts following `down`. `false` when ignored: its kind or button is not
117
+ * accepted, its kind or button differs from the gesture's (the first
118
+ * pointer's), `maxPointers` is reached, or the pointer id is already
119
+ * followed.
120
+ *
121
+ * @throws {RangeError} For a non-finite field.
122
+ */
123
+ press(down: PointerDown): boolean;
124
+ /**
125
+ * The update this movement makes: the `start` once a pointer has moved past
126
+ * the slop (from where the pointers are then, so the slop is not part of the
127
+ * movement), a `move` after. `undefined` before, and for a pointer not
128
+ * followed.
129
+ *
130
+ * @throws {RangeError} For a non-finite field, or a time before this
131
+ * pointer's last one (another pointer's older time is accepted).
132
+ */
133
+ move(sample: PointerSample): TransformUpdate | undefined;
134
+ /**
135
+ * Stops following the pointer, which first makes the movement to its release
136
+ * position, as a `move` would. The `end` update when the last pointer of a
137
+ * started gesture lifts (the gesture starts and ends at once when that
138
+ * release is the first movement past the slop); otherwise `undefined`, the
139
+ * remaining pointers carrying on from where they are, except that a pointer
140
+ * lifting at a position other than its last one hands over that movement as a
141
+ * `move` update (a `start` when it is the one that crosses the slop).
142
+ *
143
+ * @throws {RangeError} For a non-finite field, or a time before this
144
+ * pointer's last one.
145
+ */
146
+ release(sample: PointerSample): TransformUpdate | undefined;
147
+ /**
148
+ * Abandons the whole gesture, as on `pointercancel` of any of its pointers; a
149
+ * `cancel` update, carrying the totals so far to revert, when it had started.
150
+ * Without `pointerId`, whatever is followed; with one, only when that pointer
151
+ * is followed.
152
+ */
153
+ cancel(pointerId?: number): TransformUpdate | undefined;
154
+ private find_;
155
+ private checkTime_;
156
+ /** Takes `sample` as the pointer's latest position, on its own time line. */
157
+ private track_;
158
+ private isPastSlop_;
159
+ /**
160
+ * The update a pointer's new position makes: the `start` when it is the first
161
+ * past the slop (from where the pointers are then, so the slop is not part of
162
+ * the movement), a `move` after, `undefined` before.
163
+ */
164
+ private advance_;
165
+ private noteSample_;
166
+ /** Stops following `pointer`, and the gesture with the last one. */
167
+ private drop_;
168
+ /** Centroid, spread and angle of the pointers followed now. */
169
+ private measure_;
170
+ /** Makes what was last measured the baseline of the next update. */
171
+ private rebase_;
172
+ private update_;
173
+ }
174
+ //# sourceMappingURL=transform-g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}
@@ -0,0 +1,415 @@
1
+ import { assertInteger, clamp, describeValue } from "@ac-kit/core";
2
+ import { vec2ArrayMean, vec2Create } from "@ac-kit/math-linear";
3
+ import { angleNormalizeRad } from "@ac-kit/math-scalar";
4
+ import { assertSample_ } from "../_validate.js";
5
+ import { checkedSlop_, isWithinSlop_, lengthOf_, slopOf_, } from "../pointer/_slop.js";
6
+ import { VelocityTracker } from "../velocity/velocity-tracker.js";
7
+ const DEFAULT_BUTTONS_ = [0];
8
+ const DEFAULT_MAX_POINTERS_ = 2;
9
+ // Scratch for measure_: one positions buffer per pointer count, made on first
10
+ // use, and one 2D value.
11
+ const positionBuffers_ = [];
12
+ const centroid_ = vec2Create();
13
+ const BASE_X_ = 0;
14
+ const BASE_Y_ = 1;
15
+ const BASE_SPREAD_ = 2;
16
+ const BASE_ANGLE_ = 3;
17
+ const CURRENT_X_ = 4;
18
+ const CURRENT_Y_ = 5;
19
+ const CURRENT_SPREAD_ = 6;
20
+ const CURRENT_ANGLE_ = 7;
21
+ const MEASURE_COUNT_ = 8;
22
+ const MAX_FINITE_ = Number.MAX_VALUE;
23
+ /** The smallest power of two that is at least `count`. */
24
+ function normaliser_(count) {
25
+ return 2 ** Math.ceil(Math.log2(count));
26
+ }
27
+ /**
28
+ * Follows several pointers as one transform. Adding or lifting a pointer
29
+ * rebases the centroid, spread and angle, so no update jumps. A zero spread
30
+ * (two pointers on one spot) gives a scale factor and a rotation of 1 and 0.
31
+ * Cancelling any pointer abandons the whole gesture. Each pointer has its own
32
+ * velocity tracker on its own time line, so one pointer's samples may be older
33
+ * than another's; the end velocity is the last pointer's. Each move is
34
+ * O(pointers) and allocates only its update.
35
+ *
36
+ * Pointers of one gesture share a device kind and a button: the first one's. A
37
+ * pointer ignored at its press is never followed, even after another lifts.
38
+ *
39
+ * A release is a movement like any other. A pointer that lifts at a position
40
+ * other than its last one hands that movement over: as a `move` update when
41
+ * others stay (or the `start`, when it is the first past the slop), and within
42
+ * the `end` update when it is the last. The last pointer's release past the
43
+ * slop, before any `move` reported it, is a gesture that starts and ends at
44
+ * once: its `end` update is the only one, with no delta.
45
+ */
46
+ export class TransformGesture {
47
+ slop_;
48
+ buttons_;
49
+ maxPointers_;
50
+ kinds_;
51
+ pointers_ = [];
52
+ spareTrackers_ = [];
53
+ kind_ = "touch";
54
+ button_ = 0;
55
+ started_ = false;
56
+ // What the previous update measured (the next one is relative to it) and what
57
+ // the pointers measure now (refreshed by `measure_`), as unboxed numbers: an
58
+ // angle that does not exist is NaN, which `atan2` never gives.
59
+ measures_ = new Float64Array(MEASURE_COUNT_);
60
+ movementX_ = 0;
61
+ movementY_ = 0;
62
+ scale_ = 1;
63
+ rotation_ = 0;
64
+ lastTime_ = 0;
65
+ shiftKey_ = false;
66
+ altKey_ = false;
67
+ ctrlKey_ = false;
68
+ metaKey_ = false;
69
+ constructor(options) {
70
+ this.slop_ = checkedSlop_(options?.slop);
71
+ this.buttons_ = options?.buttons ?? DEFAULT_BUTTONS_;
72
+ for (const button of this.buttons_) {
73
+ assertInteger(button, "button");
74
+ }
75
+ const maxPointers = options?.maxPointers ?? DEFAULT_MAX_POINTERS_;
76
+ if (!Number.isInteger(maxPointers) || maxPointers < 1) {
77
+ throw new RangeError(`maxPointers must be a positive integer, got ${describeValue(maxPointers)}`);
78
+ }
79
+ this.maxPointers_ = maxPointers;
80
+ this.kinds_ = options?.kinds;
81
+ this.measures_[BASE_ANGLE_] = Number.NaN;
82
+ this.measures_[CURRENT_ANGLE_] = Number.NaN;
83
+ }
84
+ /** How many pointers are followed. */
85
+ get pointerCount() {
86
+ return this.pointers_.length;
87
+ }
88
+ /** Whether the gesture has started (moved past the slop). */
89
+ get isActive() {
90
+ return this.started_;
91
+ }
92
+ /**
93
+ * Starts following `down`. `false` when ignored: its kind or button is not
94
+ * accepted, its kind or button differs from the gesture's (the first
95
+ * pointer's), `maxPointers` is reached, or the pointer id is already
96
+ * followed.
97
+ *
98
+ * @throws {RangeError} For a non-finite field.
99
+ */
100
+ press(down) {
101
+ assertSample_(down);
102
+ assertInteger(down.button, "button");
103
+ if (this.kinds_ !== undefined && !this.kinds_.includes(down.kind)) {
104
+ return false;
105
+ }
106
+ if (this.pointers_.length === 0) {
107
+ if (!this.buttons_.includes(down.button)) {
108
+ return false;
109
+ }
110
+ }
111
+ else if (down.kind !== this.kind_ ||
112
+ down.button !== this.button_ ||
113
+ this.pointers_.length >= this.maxPointers_) {
114
+ return false;
115
+ }
116
+ if (this.pointers_.some((pointer) => pointer.pointerId === down.pointerId)) {
117
+ return false;
118
+ }
119
+ if (this.pointers_.length === 0) {
120
+ this.kind_ = down.kind;
121
+ this.button_ = down.button;
122
+ this.started_ = false;
123
+ this.movementX_ = 0;
124
+ this.movementY_ = 0;
125
+ this.scale_ = 1;
126
+ this.rotation_ = 0;
127
+ this.lastTime_ = down.time;
128
+ }
129
+ const tracker = this.spareTrackers_.pop() ?? new VelocityTracker();
130
+ tracker.add(down.time, down.x, down.y);
131
+ this.pointers_.push({
132
+ pointerId: down.pointerId,
133
+ downX: down.x,
134
+ downY: down.y,
135
+ x: down.x,
136
+ y: down.y,
137
+ time: down.time,
138
+ tracker,
139
+ });
140
+ this.noteSample_(down);
141
+ this.measure_();
142
+ this.rebase_();
143
+ return true;
144
+ }
145
+ /**
146
+ * The update this movement makes: the `start` once a pointer has moved past
147
+ * the slop (from where the pointers are then, so the slop is not part of the
148
+ * movement), a `move` after. `undefined` before, and for a pointer not
149
+ * followed.
150
+ *
151
+ * @throws {RangeError} For a non-finite field, or a time before this
152
+ * pointer's last one (another pointer's older time is accepted).
153
+ */
154
+ move(sample) {
155
+ assertSample_(sample);
156
+ const pointer = this.find_(sample.pointerId);
157
+ if (pointer === undefined) {
158
+ return undefined;
159
+ }
160
+ this.checkTime_(pointer, sample.time);
161
+ this.track_(pointer, sample);
162
+ return this.advance_(pointer, sample);
163
+ }
164
+ /**
165
+ * Stops following the pointer, which first makes the movement to its release
166
+ * position, as a `move` would. The `end` update when the last pointer of a
167
+ * started gesture lifts (the gesture starts and ends at once when that
168
+ * release is the first movement past the slop); otherwise `undefined`, the
169
+ * remaining pointers carrying on from where they are, except that a pointer
170
+ * lifting at a position other than its last one hands over that movement as a
171
+ * `move` update (a `start` when it is the one that crosses the slop).
172
+ *
173
+ * @throws {RangeError} For a non-finite field, or a time before this
174
+ * pointer's last one.
175
+ */
176
+ release(sample) {
177
+ assertSample_(sample);
178
+ const pointer = this.find_(sample.pointerId);
179
+ if (pointer === undefined) {
180
+ return undefined;
181
+ }
182
+ this.checkTime_(pointer, sample.time);
183
+ const moved = sample.x !== pointer.x || sample.y !== pointer.y;
184
+ this.track_(pointer, sample);
185
+ if (this.pointers_.length > 1) {
186
+ const handedOver = moved ? this.advance_(pointer, sample) : undefined;
187
+ this.drop_(pointer);
188
+ this.measure_();
189
+ this.rebase_();
190
+ return handedOver;
191
+ }
192
+ if (!this.started_) {
193
+ if (!this.isPastSlop_(pointer, sample)) {
194
+ this.drop_(pointer);
195
+ return undefined;
196
+ }
197
+ this.started_ = true;
198
+ this.measure_();
199
+ this.rebase_();
200
+ }
201
+ const velocity = pointer.tracker.velocity(sample.time);
202
+ const deltaX = sample.x - this.measures_[BASE_X_];
203
+ const deltaY = sample.y - this.measures_[BASE_Y_];
204
+ this.movementX_ += deltaX;
205
+ this.movementY_ += deltaY;
206
+ this.measures_[CURRENT_X_] = sample.x;
207
+ this.measures_[CURRENT_Y_] = sample.y;
208
+ const update = this.update_("end", sample.time, deltaX, deltaY, 1, 0, velocity.x, velocity.y);
209
+ this.drop_(pointer);
210
+ return update;
211
+ }
212
+ /**
213
+ * Abandons the whole gesture, as on `pointercancel` of any of its pointers; a
214
+ * `cancel` update, carrying the totals so far to revert, when it had started.
215
+ * Without `pointerId`, whatever is followed; with one, only when that pointer
216
+ * is followed.
217
+ */
218
+ cancel(pointerId) {
219
+ if (this.pointers_.length === 0) {
220
+ return undefined;
221
+ }
222
+ if (pointerId !== undefined) {
223
+ assertInteger(pointerId, "pointerId");
224
+ if (this.find_(pointerId) === undefined) {
225
+ return undefined;
226
+ }
227
+ }
228
+ let update;
229
+ if (this.started_) {
230
+ this.measure_();
231
+ update = this.update_("cancel", this.lastTime_, 0, 0, 1, 0, 0, 0);
232
+ }
233
+ while (this.pointers_.length > 0) {
234
+ this.drop_(this.pointers_[this.pointers_.length - 1]);
235
+ }
236
+ return update;
237
+ }
238
+ find_(pointerId) {
239
+ const pointers = this.pointers_;
240
+ for (let index = 0; index < pointers.length; index++) {
241
+ if (pointers[index].pointerId === pointerId) {
242
+ return pointers[index];
243
+ }
244
+ }
245
+ return undefined;
246
+ }
247
+ checkTime_(pointer, time) {
248
+ if (time < pointer.time) {
249
+ throw new RangeError(`time must not go backwards for a pointer, got ${time} after ${pointer.time}`);
250
+ }
251
+ }
252
+ /** Takes `sample` as the pointer's latest position, on its own time line. */
253
+ track_(pointer, sample) {
254
+ pointer.tracker.add(sample.time, sample.x, sample.y);
255
+ pointer.x = sample.x;
256
+ pointer.y = sample.y;
257
+ pointer.time = sample.time;
258
+ this.noteSample_(sample);
259
+ }
260
+ isPastSlop_(pointer, sample) {
261
+ return !isWithinSlop_(sample.x - pointer.downX, sample.y - pointer.downY, slopOf_(this.slop_, this.kind_));
262
+ }
263
+ /**
264
+ * The update a pointer's new position makes: the `start` when it is the first
265
+ * past the slop (from where the pointers are then, so the slop is not part of
266
+ * the movement), a `move` after, `undefined` before.
267
+ */
268
+ advance_(pointer, sample) {
269
+ if (!this.started_) {
270
+ if (!this.isPastSlop_(pointer, sample)) {
271
+ return undefined;
272
+ }
273
+ this.started_ = true;
274
+ this.measure_();
275
+ this.rebase_();
276
+ return this.update_("start", sample.time, 0, 0, 1, 0, 0, 0);
277
+ }
278
+ this.measure_();
279
+ const measures = this.measures_;
280
+ const deltaX = measures[CURRENT_X_] - measures[BASE_X_];
281
+ const deltaY = measures[CURRENT_Y_] - measures[BASE_Y_];
282
+ const baseSpread = measures[BASE_SPREAD_];
283
+ const currentSpread = measures[CURRENT_SPREAD_];
284
+ const scaleFactor = baseSpread > 0 &&
285
+ currentSpread > 0 &&
286
+ Number.isFinite(baseSpread) &&
287
+ Number.isFinite(currentSpread)
288
+ ? currentSpread / baseSpread
289
+ : 1;
290
+ const baseAngle = measures[BASE_ANGLE_];
291
+ const currentAngle = measures[CURRENT_ANGLE_];
292
+ const rotationDelta = Number.isNaN(baseAngle) || Number.isNaN(currentAngle)
293
+ ? 0
294
+ : angleNormalizeRad(currentAngle - baseAngle);
295
+ this.movementX_ += deltaX;
296
+ this.movementY_ += deltaY;
297
+ this.scale_ *= scaleFactor;
298
+ this.rotation_ += rotationDelta;
299
+ this.rebase_();
300
+ return this.update_("move", sample.time, deltaX, deltaY, scaleFactor, rotationDelta, 0, 0);
301
+ }
302
+ noteSample_(sample) {
303
+ this.lastTime_ = Math.max(this.lastTime_, sample.time);
304
+ this.shiftKey_ = sample.shiftKey === true;
305
+ this.altKey_ = sample.altKey === true;
306
+ this.ctrlKey_ = sample.ctrlKey === true;
307
+ this.metaKey_ = sample.metaKey === true;
308
+ }
309
+ /** Stops following `pointer`, and the gesture with the last one. */
310
+ drop_(pointer) {
311
+ this.pointers_.splice(this.pointers_.indexOf(pointer), 1);
312
+ pointer.tracker.reset();
313
+ this.spareTrackers_.push(pointer.tracker);
314
+ if (this.pointers_.length === 0) {
315
+ this.started_ = false;
316
+ }
317
+ }
318
+ /** Centroid, spread and angle of the pointers followed now. */
319
+ measure_() {
320
+ const pointers = this.pointers_;
321
+ const count = pointers.length;
322
+ let positions = positionBuffers_[count];
323
+ if (positions === undefined) {
324
+ positions = new Float64Array(count * 2);
325
+ positionBuffers_[count] = positions;
326
+ }
327
+ for (let index = 0; index < count; index++) {
328
+ positions[index * 2] = pointers[index].x;
329
+ positions[index * 2 + 1] = pointers[index].y;
330
+ }
331
+ vec2ArrayMean(centroid_, positions);
332
+ let centroidX = centroid_[0];
333
+ let centroidY = centroid_[1];
334
+ if (!(Number.isFinite(centroidX) && Number.isFinite(centroidY))) {
335
+ // Finite positions whose sum overflows: average them divided by a
336
+ // power of two (exact) no smaller than the count, so no partial sum
337
+ // can overflow either.
338
+ const unit = normaliser_(count);
339
+ centroidX = 0;
340
+ centroidY = 0;
341
+ for (let index = 0; index < count; index++) {
342
+ centroidX += pointers[index].x / unit;
343
+ centroidY += pointers[index].y / unit;
344
+ }
345
+ centroidX = clamp(centroidX * (unit / count), -MAX_FINITE_, MAX_FINITE_);
346
+ centroidY = clamp(centroidY * (unit / count), -MAX_FINITE_, MAX_FINITE_);
347
+ }
348
+ let spread = 0;
349
+ if (count > 1) {
350
+ for (let index = 0; index < count; index++) {
351
+ spread += lengthOf_(pointers[index].x - centroidX, pointers[index].y - centroidY);
352
+ }
353
+ spread /= count;
354
+ if (!Number.isFinite(spread)) {
355
+ const unit = normaliser_(count);
356
+ spread = 0;
357
+ for (let index = 0; index < count; index++) {
358
+ spread +=
359
+ lengthOf_(pointers[index].x - centroidX, pointers[index].y - centroidY) / unit;
360
+ }
361
+ spread *= unit / count;
362
+ // A length beyond the double range stays infinite: no scale then.
363
+ if (Number.isFinite(spread)) {
364
+ spread = Math.min(spread, MAX_FINITE_);
365
+ }
366
+ }
367
+ }
368
+ const measures = this.measures_;
369
+ measures[CURRENT_X_] = centroidX;
370
+ measures[CURRENT_Y_] = centroidY;
371
+ measures[CURRENT_SPREAD_] = spread;
372
+ measures[CURRENT_ANGLE_] = Number.NaN;
373
+ if (count > 1) {
374
+ const dx = pointers[1].x - pointers[0].x;
375
+ const dy = pointers[1].y - pointers[0].y;
376
+ if (dx !== 0 || dy !== 0) {
377
+ measures[CURRENT_ANGLE_] = Math.atan2(dy, dx);
378
+ }
379
+ }
380
+ }
381
+ /** Makes what was last measured the baseline of the next update. */
382
+ rebase_() {
383
+ const measures = this.measures_;
384
+ measures[BASE_X_] = measures[CURRENT_X_];
385
+ measures[BASE_Y_] = measures[CURRENT_Y_];
386
+ measures[BASE_SPREAD_] = measures[CURRENT_SPREAD_];
387
+ measures[BASE_ANGLE_] = measures[CURRENT_ANGLE_];
388
+ }
389
+ update_(phase, time, deltaX, deltaY, scaleFactor, rotationDelta, velocityX, velocityY) {
390
+ return {
391
+ phase,
392
+ pointerCount: this.pointers_.length,
393
+ kind: this.kind_,
394
+ button: this.button_,
395
+ originX: this.measures_[CURRENT_X_],
396
+ originY: this.measures_[CURRENT_Y_],
397
+ deltaX,
398
+ deltaY,
399
+ scaleFactor,
400
+ rotationDelta,
401
+ movementX: this.movementX_,
402
+ movementY: this.movementY_,
403
+ scale: this.scale_,
404
+ rotation: this.rotation_,
405
+ velocityX,
406
+ velocityY,
407
+ time,
408
+ shiftKey: this.shiftKey_,
409
+ altKey: this.altKey_,
410
+ ctrlKey: this.ctrlKey_,
411
+ metaKey: this.metaKey_,
412
+ };
413
+ }
414
+ }
415
+ //# sourceMappingURL=transform-gesture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-gesture.js","sourceRoot":"","sources":["../../src/transform/transform-gesture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACN,YAAY,EACZ,aAAa,EACb,SAAS,EACT,OAAO,GACP,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAyFlE,MAAM,gBAAgB,GAAsB,CAAC,CAAC,CAAC,CAAC;AAChD,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC,8EAA8E;AAC9E,yBAAyB;AACzB,MAAM,gBAAgB,GAAmB,EAAE,CAAC;AAC5C,MAAM,SAAS,GAAG,UAAU,EAAE,CAAC;AAE/B,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,M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