motion-dom 14.10.0 → 14.11.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 (46) hide show
  1. package/dist/cjs/index.js +886 -126
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/GroupAnimation.mjs +21 -15
  4. package/dist/es/animation/GroupAnimation.mjs.map +1 -1
  5. package/dist/es/animation/animate/effects.mjs +15 -4
  6. package/dist/es/animation/animate/effects.mjs.map +1 -1
  7. package/dist/es/animation/animate/single-value.mjs +1 -1
  8. package/dist/es/animation/animate/single-value.mjs.map +1 -1
  9. package/dist/es/animation/generators/keyframes.mjs +44 -16
  10. package/dist/es/animation/generators/keyframes.mjs.map +1 -1
  11. package/dist/es/animation/interfaces/visual-element-target.mjs +1 -1
  12. package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
  13. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +8 -3
  14. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
  15. package/dist/es/animation/keyframes/get-final.mjs +18 -4
  16. package/dist/es/animation/keyframes/get-final.mjs.map +1 -1
  17. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +155 -42
  18. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
  19. package/dist/es/gestures/drag/VisualElementDragControls.mjs +4 -0
  20. package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
  21. package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
  22. package/dist/es/gestures/pinch/index.mjs +552 -0
  23. package/dist/es/gestures/pinch/index.mjs.map +1 -0
  24. package/dist/es/gestures/press/index.mjs +6 -2
  25. package/dist/es/gestures/press/index.mjs.map +1 -1
  26. package/dist/es/index.mjs +1 -0
  27. package/dist/es/index.mjs.map +1 -1
  28. package/dist/es/projection/styles/transform.mjs +39 -17
  29. package/dist/es/projection/styles/transform.mjs.map +1 -1
  30. package/dist/es/render/utils/get-variant-context.mjs.map +1 -1
  31. package/dist/es/render/utils/variant-props.mjs +1 -0
  32. package/dist/es/render/utils/variant-props.mjs.map +1 -1
  33. package/dist/es/value/index.mjs +24 -20
  34. package/dist/es/value/index.mjs.map +1 -1
  35. package/dist/es/value/types/utils/animatable-none.mjs +13 -1
  36. package/dist/es/value/types/utils/animatable-none.mjs.map +1 -1
  37. package/dist/index.d.ts +360 -105
  38. package/dist/motion-dom.dev.js +886 -126
  39. package/dist/motion-dom.js +1 -1
  40. package/dist/size-rollup-motion-value.js +1 -1
  41. package/dist/size-rollup-motion-value.js.map +1 -1
  42. package/dist/size-rollup-pinch.js +2 -0
  43. package/dist/size-rollup-pinch.js.map +1 -0
  44. package/dist/size-rollup-style-effect.js +1 -1
  45. package/dist/size-rollup-style-effect.js.map +1 -1
  46. package/package.json +6 -2
@@ -0,0 +1,552 @@
1
+ import { clamp } from 'motion-utils';
2
+ import { spring } from '../../animation/generators/spring.mjs';
3
+ import { styleSubjectEffect, readStyleValue } from '../../effects/style/index.mjs';
4
+ import { svgSubjectEffect } from '../../effects/svg/index.mjs';
5
+ import { time } from '../../frameloop/sync-time.mjs';
6
+ import { visualElementStore } from '../../render/store.mjs';
7
+ import { activeScope, addToScope } from '../../scope/active.mjs';
8
+ import { isSVGElement } from '../../utils/is-svg-element.mjs';
9
+ import { mixNumber } from '../../utils/mix/number.mjs';
10
+ import { resolveElements } from '../../utils/resolve-elements.mjs';
11
+ import { motionValue } from '../../value/index.mjs';
12
+ import { setDragLock } from '../drag/state/set-active.mjs';
13
+ import { defaultElastic, applyConstraints } from '../drag/utils/constraints.mjs';
14
+ import { elementDragControls } from '../drag/VisualElementDragControls.mjs';
15
+ import { frame, cancelFrame } from '../../frameloop/frame.mjs';
16
+
17
+ /**
18
+ * A trackpad pinch arrives as a stream of `wheel` events with no end
19
+ * event, so it ends once none have arrived for this long.
20
+ */
21
+ const wheelTimeout = 150;
22
+ /**
23
+ * Convert an `x`/`y` set in other units (e.g. `"-50%"` to centre an
24
+ * element) to pixels, so the gesture can add to it.
25
+ */
26
+ const toPixels = (value, size) => {
27
+ const latest = value.get();
28
+ if (typeof latest === "string") {
29
+ value.set(parseFloat(latest) * (latest.endsWith("%") ? size / 100 : 1));
30
+ }
31
+ };
32
+ const limitsOf = (option) => typeof option === "object" ? option : {};
33
+ /**
34
+ * Resolve `elastic` to a resistance for each side, as for `dragElastic`.
35
+ */
36
+ const resolveElastic = (elastic = defaultElastic) => {
37
+ const side = (value) => value === true ? defaultElastic : +(value || 0);
38
+ return typeof elastic === "object"
39
+ ? { min: side(elastic.min), max: side(elastic.max) }
40
+ : { min: side(elastic), max: side(elastic) };
41
+ };
42
+ const clampTo = (value, { min = -Infinity, max = Infinity }) => clamp(min, max, value);
43
+ /**
44
+ * The raw gesture value that elastic shows as `value`. A pinch that starts
45
+ * while a value is still past its limit (like during a spring back) carries
46
+ * on from it, rather than jumping.
47
+ */
48
+ const unconstrain = (value, option, resistance) => {
49
+ const limit = clampTo(value, limitsOf(option));
50
+ const elastic = resistance[value < limit ? "min" : "max"];
51
+ return elastic ? limit + (value - limit) / elastic : value;
52
+ };
53
+ /**
54
+ * Listen for pinch gestures on `element`: two touches (or pens), a trackpad
55
+ * pinch (`wheel` with `ctrlKey`, as Chrome, Edge and Firefox report it),
56
+ * and Safari's `gesture*` events.
57
+ *
58
+ * `getValues` is called each time a gesture starts, in the frame's read
59
+ * step, for the scale/rotate/x/y values to write to. It runs alongside the
60
+ * element measurement so neither forces a layout.
61
+ *
62
+ * `getOptions` is read whenever it's needed, so options can change while
63
+ * listening. Return `false` to disable the gesture, which also ends one in
64
+ * progress.
65
+ *
66
+ * `onPinchStart` is called once as each gesture starts, with the gesture's
67
+ * info as a third argument. It can return the gesture's handlers, as for
68
+ * `pinch()`.
69
+ */
70
+ function addPinchListeners(element, getValues, getEnabledOptions, onPinchStart) {
71
+ const pointers = new Map();
72
+ /**
73
+ * The gesture as last reported: focal point, log of a distance and an
74
+ * angle. Only changes in distance and angle matter, so trackpad and
75
+ * Safari input write a virtual distance (the scale) here. Logs keep
76
+ * a long trackpad pinch from overflowing.
77
+ */
78
+ const current = { x: 0, y: 0, l: 0, a: 0 };
79
+ const start = { ...current };
80
+ const prev = { ...current };
81
+ let source;
82
+ let lastEvent;
83
+ let values;
84
+ let originX = 0;
85
+ let originY = 0;
86
+ let lastX = 0;
87
+ let lastY = 0;
88
+ let hasMoved = false;
89
+ let wheelTime = 0;
90
+ let handlers = {};
91
+ let unlock;
92
+ /**
93
+ * The gesture's scale and rotation before limits and elastic apply.
94
+ */
95
+ let rawScale = 1;
96
+ let rawRotate = 0;
97
+ let stopSnap = () => { };
98
+ /**
99
+ * The latest enabled options, so a gesture disabled mid-way can still
100
+ * report its end.
101
+ */
102
+ let options = {};
103
+ const getOptions = () => (options = getEnabledOptions() || options);
104
+ const info = () => ({
105
+ point: { x: current.x, y: current.y },
106
+ offset: { x: current.x - start.x, y: current.y - start.y },
107
+ scale: Math.exp(current.l - start.l),
108
+ rotate: current.a - start.a,
109
+ });
110
+ /**
111
+ * Read the element's box and values, and find its layout origin: its
112
+ * centre without `x`/`y`. Scale and rotate are applied around the
113
+ * centre (the default transform origin), so they don't move it.
114
+ */
115
+ const measure = () => {
116
+ const { left, top, width, height } = element.getBoundingClientRect();
117
+ const { scale, rotate, pan, elastic } = getOptions();
118
+ const [s, r, x, y] = (values = getValues());
119
+ const resistance = resolveElastic(elastic);
120
+ /**
121
+ * Stop animations on values this gesture writes, and leave the
122
+ * rest running.
123
+ */
124
+ scale !== false && s.stop();
125
+ rotate !== false && r.stop();
126
+ rawScale = unconstrain(s.get(), scale, resistance);
127
+ rawRotate = unconstrain(r.get(), rotate, resistance);
128
+ if (pan !== false) {
129
+ x.stop();
130
+ y.stop();
131
+ toPixels(x, element.offsetWidth ?? width);
132
+ toPixels(y, element.offsetHeight ?? height);
133
+ }
134
+ lastX = x.get();
135
+ lastY = y.get();
136
+ originX = left + width / 2 - lastX;
137
+ originY = top + height / 2 - lastY;
138
+ };
139
+ const dragControls = () => elementDragControls.get(visualElementStore.get(element));
140
+ /**
141
+ * On release, spring scale and rotation back inside their limits (or
142
+ * to a `snap` angle), keeping the focal point in place, or everything
143
+ * back to its origin with `snapToOrigin`.
144
+ */
145
+ const snap = () => {
146
+ const { scale: scaleOption, rotate: rotateOption, pan, snapToOrigin, transition, } = options;
147
+ const [scale, rotate, x, y] = values;
148
+ const s0 = scale.get();
149
+ const r0 = rotate.get();
150
+ const x0 = x.get();
151
+ const y0 = y.get();
152
+ const { snap: step } = limitsOf(rotateOption);
153
+ let s1 = clampTo(s0, limitsOf(scaleOption));
154
+ let r1 = clampTo(step ? Math.round(r0 / step) * step : r0, limitsOf(rotateOption));
155
+ if (snapToOrigin) {
156
+ s1 = 1;
157
+ // The nearest upright angle, so it turns the shortest way
158
+ r1 = Math.round(r0 / 360) * 360;
159
+ }
160
+ /**
161
+ * Keep the focal point in place, unless the element doesn't move
162
+ * with it, or a drag carries on and owns x/y.
163
+ */
164
+ const moves = pan !== false && !dragControls()?.isDragging;
165
+ const vx = originX + x0 - current.x;
166
+ const vy = originY + y0 - current.y;
167
+ if (!s0 ||
168
+ (s1 === s0 && r1 === r0 && !(snapToOrigin && moves && (x0 || y0)))) {
169
+ return;
170
+ }
171
+ const generator = spring({
172
+ keyframes: [0, 1],
173
+ stiffness: 200,
174
+ damping: 40,
175
+ ...transition,
176
+ });
177
+ const startTime = time.now();
178
+ /**
179
+ * Drive the values from one spring, from 0 to 1, so they stay in
180
+ * step and the focal point stays in place.
181
+ */
182
+ const tick = () => {
183
+ if (dragControls()?.isDragging)
184
+ return stopSnap();
185
+ const { value: p, done } = generator.next(time.now() - startTime);
186
+ if (done)
187
+ stopSnap();
188
+ const k = mixNumber(s0, s1, p);
189
+ const r = mixNumber(r0, r1, p);
190
+ const angle = ((r - r0) * Math.PI) / 180;
191
+ const cos = (Math.cos(angle) * k) / s0;
192
+ const sin = (Math.sin(angle) * k) / s0;
193
+ scaleOption !== false && scale.set(k);
194
+ rotateOption !== false && rotate.set(r);
195
+ if (moves) {
196
+ x.set(snapToOrigin
197
+ ? mixNumber(x0, 0, p)
198
+ : x0 + cos * vx - sin * vy - vx);
199
+ y.set(snapToOrigin
200
+ ? mixNumber(y0, 0, p)
201
+ : y0 + sin * vx + cos * vy - vy);
202
+ }
203
+ };
204
+ stopSnap = () => cancelFrame(tick);
205
+ frame.update(tick, true);
206
+ };
207
+ /**
208
+ * Apply the change in the gesture since the last frame as an
209
+ * incremental scale and rotation around the previous focal point,
210
+ * plus the focal point's movement.
211
+ */
212
+ const apply = () => {
213
+ if (!values || !hasMoved)
214
+ return;
215
+ hasMoved = false;
216
+ const { rotate: rotateOption, scale: scaleOption, pan, elastic, } = getOptions();
217
+ const [scale, rotate, x, y] = values;
218
+ const resistance = resolveElastic(elastic);
219
+ const latest = scale.get();
220
+ let theta = 0;
221
+ let k = 1;
222
+ /**
223
+ * Apply limits and elastic to the gesture's raw scale and rotation.
224
+ * At a hard limit, the raw value stops too, so moving back responds
225
+ * straight away.
226
+ */
227
+ const constrain = (raw, option) => {
228
+ const limits = limitsOf(option);
229
+ const limit = clampTo(raw, limits);
230
+ return resistance[raw < limit ? "min" : "max"]
231
+ ? [applyConstraints(raw, limits, resistance), raw]
232
+ : [limit, limit];
233
+ };
234
+ if (scaleOption !== false && latest) {
235
+ const [next, raw] = constrain(clamp(1e-9, 1e9, rawScale * Math.exp(current.l - prev.l)), scaleOption);
236
+ rawScale = raw;
237
+ k = next / latest;
238
+ scale.set(next);
239
+ }
240
+ if (rotateOption !== false) {
241
+ const [next, raw] = constrain(rawRotate + current.a - prev.a, rotateOption);
242
+ rawRotate = raw;
243
+ theta = next - rotate.get();
244
+ if (theta)
245
+ rotate.set(next);
246
+ }
247
+ if (pan !== false) {
248
+ /**
249
+ * Pinch owns x/y while it runs, so stop any animation started
250
+ * on them since (like a drag's snap back) taking over after.
251
+ */
252
+ x.stop();
253
+ y.stop();
254
+ /**
255
+ * If drag() or the drag prop is dragging this element with one
256
+ * of the touches, it has set x/y this frame to where it started
257
+ * plus the touch's offset. Carry on from our own values instead,
258
+ * and restart the drag from them and the touch's latest point.
259
+ * That way it continues from wherever the pinch leaves the
260
+ * element, and its release velocity only counts movement after
261
+ * the pinch, so a zoom doesn't end in a fling.
262
+ */
263
+ const drag = dragControls();
264
+ const isDragging = drag?.isDragging;
265
+ if (!isDragging) {
266
+ lastX = x.get();
267
+ lastY = y.get();
268
+ }
269
+ const angle = (theta * Math.PI) / 180;
270
+ const cos = Math.cos(angle) * k;
271
+ const sin = Math.sin(angle) * k;
272
+ const dx = prev.x - originX - lastX;
273
+ const dy = prev.y - originY - lastY;
274
+ /**
275
+ * Move the centre so the previous focal point, scaled and
276
+ * rotated around the centre, lands on the current focal point.
277
+ */
278
+ lastX += dx + current.x - prev.x - (cos * dx - sin * dy);
279
+ lastY += dy + current.y - prev.y - (sin * dx + cos * dy);
280
+ if (isDragging) {
281
+ const history = drag.panSession.history;
282
+ history.splice(0, history.length - 1);
283
+ /**
284
+ * Date the point long ago, so drag only measures release
285
+ * velocity from moves after the pinch. A move that drag
286
+ * processes as the touch lifts is part of the pinch.
287
+ */
288
+ history[0].timestamp = -Infinity;
289
+ drag.originPoint.x = lastX;
290
+ drag.originPoint.y = lastY;
291
+ }
292
+ x.set(lastX);
293
+ y.set(lastY);
294
+ }
295
+ Object.assign(prev, current);
296
+ handlers.onPinch?.(lastEvent, info());
297
+ };
298
+ /**
299
+ * Runs after the update step, where drag sets x/y, so it has the final
300
+ * say on them each frame.
301
+ */
302
+ const update = () => {
303
+ if (!getEnabledOptions())
304
+ return end(lastEvent);
305
+ apply();
306
+ if (source === "wheel" && time.now() - wheelTime > wheelTimeout) {
307
+ end(lastEvent);
308
+ }
309
+ };
310
+ const begin = (event, from) => {
311
+ if (!getEnabledOptions())
312
+ return;
313
+ stopSnap();
314
+ source = from;
315
+ lastEvent = event;
316
+ hasMoved = false;
317
+ values = undefined;
318
+ handlers = {};
319
+ Object.assign(start, current);
320
+ Object.assign(prev, current);
321
+ frame.read(measure);
322
+ frame.preRender(update, true);
323
+ const result = onPinchStart(element, event, info());
324
+ handlers =
325
+ typeof result === "function" ? { onComplete: result } : result || {};
326
+ };
327
+ const end = (event) => {
328
+ if (!source)
329
+ return;
330
+ cancelFrame(measure);
331
+ cancelFrame(update);
332
+ if (getEnabledOptions()) {
333
+ apply();
334
+ values && snap();
335
+ }
336
+ source = undefined;
337
+ handlers.onComplete?.(event, info());
338
+ };
339
+ const moved = (event) => {
340
+ lastEvent = event;
341
+ hasMoved = true;
342
+ };
343
+ const readPointers = () => {
344
+ const [a, b] = pointers.values();
345
+ const angle = (Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI;
346
+ const delta = angle - current.a;
347
+ current.x = (a.x + b.x) / 2;
348
+ current.y = (a.y + b.y) / 2;
349
+ current.l = Math.log(Math.hypot(b.x - a.x, b.y - a.y) || 1);
350
+ /**
351
+ * Take the shortest way round, so rotation keeps counting past
352
+ * 180deg rather than flipping to -180deg.
353
+ */
354
+ current.a += delta - 360 * Math.round(delta / 360);
355
+ };
356
+ const setPointer = (event) => pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
357
+ const onPointerMove = (event) => {
358
+ if (!pointers.has(event.pointerId))
359
+ return;
360
+ setPointer(event);
361
+ if (source === "pointer") {
362
+ readPointers();
363
+ moved(event);
364
+ }
365
+ };
366
+ const onPointerUp = (event) => {
367
+ if (!pointers.delete(event.pointerId))
368
+ return;
369
+ if (source === "pointer")
370
+ end(event);
371
+ if (!pointers.size) {
372
+ toggleWindowListeners();
373
+ release();
374
+ }
375
+ };
376
+ /**
377
+ * Once a touch is down on the element, listen on the window too, so
378
+ * the second touch can land beside it (for instance on a small image).
379
+ */
380
+ const onPointerDown = (event) => {
381
+ if (source ||
382
+ pointers.size > 1 ||
383
+ pointers.has(event.pointerId) ||
384
+ event.pointerType === "mouse") {
385
+ return;
386
+ }
387
+ if (!pointers.size)
388
+ toggleWindowListeners(true);
389
+ setPointer(event);
390
+ if (pointers.size === 2) {
391
+ readPointers();
392
+ begin(event, "pointer");
393
+ /**
394
+ * Unless this element drags, hold the drag lock until every
395
+ * touch lifts. A press on it then ends as a cancel, rather than
396
+ * a tap, and a draggable parent doesn't drag.
397
+ */
398
+ if (source &&
399
+ !unlock &&
400
+ !elementDragControls.get(visualElementStore.get(element))) {
401
+ unlock = setDragLock(true);
402
+ }
403
+ }
404
+ };
405
+ /**
406
+ * Release the drag lock a frame later, so a press ending on this same
407
+ * pointerup still sees it.
408
+ */
409
+ const release = () => {
410
+ const done = unlock;
411
+ unlock = undefined;
412
+ done && frame.postRender(done);
413
+ };
414
+ const toggleWindowListeners = (add) => {
415
+ const method = add ? "addEventListener" : "removeEventListener";
416
+ window[method]("pointerdown", onPointerDown);
417
+ window[method]("pointermove", onPointerMove);
418
+ window[method]("pointerup", onPointerUp);
419
+ window[method]("pointercancel", onPointerUp);
420
+ };
421
+ const onWheel = (event) => {
422
+ if (!event.ctrlKey || (source && source !== "wheel"))
423
+ return;
424
+ current.x = event.clientX;
425
+ current.y = event.clientY;
426
+ if (!source) {
427
+ current.l = 0;
428
+ begin(event, "wheel");
429
+ if (!source)
430
+ return;
431
+ }
432
+ event.preventDefault();
433
+ /**
434
+ * Lines (Firefox's mouse wheel) to pixels, and cap each event so a
435
+ * mouse wheel notch with ctrl held (about 100px) zooms a step.
436
+ */
437
+ current.l -=
438
+ clamp(-50, 50, event.deltaY * (event.deltaMode ? 16 : 1)) / 100;
439
+ wheelTime = time.now();
440
+ moved(event);
441
+ };
442
+ /**
443
+ * Safari reports trackpad pinches as `gesture*` events. iOS Safari
444
+ * fires them for touches too, alongside the pointer events we track.
445
+ */
446
+ const onGesture = (event) => {
447
+ if (!pointers.size && (!source || source === "gesture")) {
448
+ const { scale, rotation, clientX, clientY } = event;
449
+ current.x = clientX;
450
+ current.y = clientY;
451
+ current.l = Math.log(scale);
452
+ current.a = rotation;
453
+ if (source) {
454
+ moved(event);
455
+ if (event.type === "gestureend")
456
+ end(event);
457
+ }
458
+ else if (event.type === "gesturestart") {
459
+ begin(event, "gesture");
460
+ }
461
+ }
462
+ if (source)
463
+ event.preventDefault();
464
+ };
465
+ const listeners = {
466
+ pointerdown: onPointerDown,
467
+ wheel: onWheel,
468
+ gesturestart: onGesture,
469
+ gesturechange: onGesture,
470
+ gestureend: onGesture,
471
+ };
472
+ for (const name in listeners) {
473
+ element.addEventListener(name, listeners[name], { passive: false });
474
+ }
475
+ return () => {
476
+ for (const name in listeners) {
477
+ element.removeEventListener(name, listeners[name]);
478
+ }
479
+ toggleWindowListeners();
480
+ end(lastEvent);
481
+ stopSnap();
482
+ pointers.clear();
483
+ release();
484
+ };
485
+ }
486
+ const valueKeys = ["scale", "rotate", "x", "y"];
487
+ /**
488
+ * The element's scale/rotate/x/y motion values: those of its
489
+ * VisualElement if it has one (it's a <motion.*> component, or drag() or
490
+ * animateLayout() own it), otherwise those animate() binds to it, created
491
+ * from its current style if this is the first time.
492
+ */
493
+ const getElementValues = (element) => {
494
+ const visualElement = visualElementStore.get(element);
495
+ const effect = isSVGElement(element) ? svgSubjectEffect : styleSubjectEffect;
496
+ return valueKeys.map((key) => {
497
+ if (visualElement) {
498
+ return visualElement.getValue(key, key === "scale" ? 1 : 0);
499
+ }
500
+ let value = effect.get(element, key);
501
+ if (!value) {
502
+ value = motionValue(readStyleValue(element, key));
503
+ effect(element, { [key]: value });
504
+ }
505
+ return value;
506
+ });
507
+ };
508
+ function pinch(elementOrSelector, startOrOptions, options = {}) {
509
+ let onPinchStart = () => { };
510
+ if (typeof startOrOptions === "function") {
511
+ onPinchStart = startOrOptions;
512
+ }
513
+ else if (startOrOptions) {
514
+ options = startOrOptions;
515
+ }
516
+ const scope = activeScope.current;
517
+ /**
518
+ * Run the start callback and the handlers it returns in the active
519
+ * scope, so work they start is collected. A returned function is
520
+ * bound by `scope.bind` itself.
521
+ */
522
+ if (scope) {
523
+ const start = scope.bind(onPinchStart);
524
+ onPinchStart = (element, event) => {
525
+ const result = start(element, event);
526
+ if (typeof result !== "object")
527
+ return result;
528
+ const handlers = {};
529
+ for (const key in result) {
530
+ const name = key;
531
+ const handler = result[name];
532
+ handlers[name] = handler && scope.bind(handler);
533
+ }
534
+ return handlers;
535
+ };
536
+ }
537
+ const cleanups = resolveElements(elementOrSelector).map((element) => {
538
+ scope?.track(element);
539
+ const { style } = element;
540
+ const touchAction = style.touchAction;
541
+ style.touchAction = "none";
542
+ const remove = addPinchListeners(element, () => getElementValues(element), () => options, onPinchStart);
543
+ return () => {
544
+ remove();
545
+ style.touchAction = touchAction;
546
+ };
547
+ });
548
+ return addToScope(() => cleanups.forEach((cleanup) => cleanup()));
549
+ }
550
+
551
+ export { addPinchListeners, pinch };
552
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/gestures/pinch/index.ts"],"sourcesContent":["import { clamp, type Point } from \"motion-utils\"\nimport { spring } from \"../../animation/generators/spring\"\nimport type { SpringOptions } from \"../../animation/types\"\nimport { readStyleValue, styleSubjectEffect } from \"../../effects/style\"\nimport { svgSubjectEffect } from \"../../effects/svg\"\nimport { cancelFrame, frame } from \"../../frameloop\"\nimport { time } from \"../../frameloop/sync-time\"\nimport { visualElementStore } from \"../../render/store\"\nimport { activeScope, addToScope } from \"../../scope/active\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { mixNumber } from \"../../utils/mix/number\"\nimport {\n resolveElements,\n type ElementOrSelector,\n} from \"../../utils/resolve-elements\"\nimport { motionValue, type MotionValue } from \"../../value\"\nimport { setDragLock } from \"../drag/state/set-active\"\nimport { applyConstraints, defaultElastic } from \"../drag/utils/constraints\"\nimport { elementDragControls } from \"../drag/VisualElementDragControls\"\n\n/**\n * @public\n */\nexport interface PinchInfo {\n /**\n * The gesture's focal point in client coordinates: the midpoint\n * between two touches, or the cursor for a trackpad pinch.\n */\n point: Point\n\n /**\n * How far the focal point has moved since the gesture started.\n */\n offset: Point\n\n /**\n * The gesture's scale relative to its start.\n */\n scale: number\n\n /**\n * The gesture's rotation since its start, in degrees.\n */\n rotate: number\n}\n\n/**\n * Called with the latest event and the gesture's info.\n *\n * @public\n */\nexport type OnPinchEvent = (event: Event, info: PinchInfo) => void\n\n/**\n * Handlers for a single pinch gesture, returned from the pinch start\n * callback.\n *\n * @public\n */\nexport interface PinchHandlers {\n /**\n * Called each frame the gesture changes, after the element's values\n * are updated.\n */\n onPinch?: OnPinchEvent\n\n /**\n * Called once when the gesture ends: a touch lifts or is cancelled, a\n * trackpad pinch stops, or the gesture is disabled or removed.\n *\n * Returning this function directly from the pinch start callback is\n * equivalent.\n */\n onComplete?: OnPinchEvent\n}\n\n/**\n * Called once when a pinch gesture starts: when a second touch lands, on\n * the first trackpad pinch event, or on Safari's `gesturestart`. Can\n * return a function to call when the pinch ends, or an object of\n * `PinchHandlers`.\n *\n * @public\n */\nexport type OnPinchStartEvent = (\n element: Element,\n event: Event\n) => OnPinchEvent | PinchHandlers | void\n\n/**\n * The limits of a pinch's scale or rotation.\n *\n * @public\n */\nexport interface PinchLimits {\n /**\n * The minimum. Past it, the gesture resists by `elastic`, and the\n * value springs back to it on release.\n */\n min?: number\n\n /**\n * The maximum. Past it, the gesture resists by `elastic`, and the\n * value springs back to it on release.\n */\n max?: number\n}\n\n/**\n * @public\n */\nexport interface PinchRotateOptions extends PinchLimits {\n /**\n * On release, rotate to the nearest multiple of this many degrees.\n */\n snap?: number\n}\n\n/**\n * @public\n */\nexport interface PinchOptions {\n /**\n * Scale the element. Defaults to `true`. Pass `{ min, max }` to limit\n * the scale.\n */\n scale?: boolean | PinchLimits\n\n /**\n * Rotate the element with the touches. Defaults to `true`. Pass\n * `{ min, max }` (in degrees) to limit the rotation, and `snap` to\n * rotate to the nearest multiple of `snap` degrees on release.\n */\n rotate?: boolean | PinchRotateOptions\n\n /**\n * Move the element with the focal point, and keep the point under the\n * fingers (or cursor) in place while scaling and rotating. Defaults to\n * `true`. Composes with drag: a drag that one of the touches started\n * carries on from wherever the pinch leaves the element (its offset\n * restarts there). Drag constraints aren't applied while pinching.\n *\n * Assumes the default `transform-origin` (the element's centre).\n */\n pan?: boolean\n\n /**\n * How far scale and rotation can go past their limits, as for\n * `dragElastic`: `0` stops at the limit, `1` doesn't resist. Pass\n * `{ min, max }` to set each side. Defaults to `0.35`.\n */\n elastic?: boolean | number | PinchLimits\n\n /**\n * On release, animate scale back to `1`, and rotation and `x`/`y`\n * back to `0`.\n */\n snapToOrigin?: boolean\n\n /**\n * The spring values use to animate back inside their limits, to a\n * `snap` angle or to their origin.\n */\n transition?: SpringOptions\n}\n\n/**\n * Options for the `pinch` prop.\n *\n * @public\n */\nexport interface PinchProps extends PinchOptions {\n /**\n * Called when the pinch starts.\n */\n onStart?: OnPinchEvent\n\n /**\n * Called each frame the pinch changes.\n */\n onMove?: OnPinchEvent\n\n /**\n * Called when the pinch ends.\n */\n onEnd?: OnPinchEvent\n}\n\nexport type PinchValues = [\n scale: MotionValue<number>,\n rotate: MotionValue<number>,\n x: MotionValue<number>,\n y: MotionValue<number>\n]\n\n/**\n * A trackpad pinch arrives as a stream of `wheel` events with no end\n * event, so it ends once none have arrived for this long.\n */\nconst wheelTimeout = 150\n\n/**\n * Convert an `x`/`y` set in other units (e.g. `\"-50%\"` to centre an\n * element) to pixels, so the gesture can add to it.\n */\nconst toPixels = (value: MotionValue<number>, size: number) => {\n const latest = value.get() as number | string\n\n if (typeof latest === \"string\") {\n value.set(parseFloat(latest) * (latest.endsWith(\"%\") ? size / 100 : 1))\n }\n}\n\nconst limitsOf = (option?: boolean | PinchRotateOptions): PinchRotateOptions =>\n typeof option === \"object\" ? option : {}\n\n/**\n * Resolve `elastic` to a resistance for each side, as for `dragElastic`.\n */\nconst resolveElastic = (\n elastic: PinchOptions[\"elastic\"] = defaultElastic\n): { min: number; max: number } => {\n const side = (value?: number | boolean) =>\n value === true ? defaultElastic : +(value || 0)\n\n return typeof elastic === \"object\"\n ? { min: side(elastic.min), max: side(elastic.max) }\n : { min: side(elastic), max: side(elastic) }\n}\n\nconst clampTo = (value: number, { min = -Infinity, max = Infinity }) =>\n clamp(min, max, value)\n\n/**\n * The raw gesture value that elastic shows as `value`. A pinch that starts\n * while a value is still past its limit (like during a spring back) carries\n * on from it, rather than jumping.\n */\nconst unconstrain = (\n value: number,\n option: boolean | PinchRotateOptions | undefined,\n resistance: { min: number; max: number }\n) => {\n const limit = clampTo(value, limitsOf(option))\n const elastic = resistance[value < limit ? \"min\" : \"max\"]\n\n return elastic ? limit + (value - limit) / elastic : value\n}\n\n/**\n * Listen for pinch gestures on `element`: two touches (or pens), a trackpad\n * pinch (`wheel` with `ctrlKey`, as Chrome, Edge and Firefox report it),\n * and Safari's `gesture*` events.\n *\n * `getValues` is called each time a gesture starts, in the frame's read\n * step, for the scale/rotate/x/y values to write to. It runs alongside the\n * element measurement so neither forces a layout.\n *\n * `getOptions` is read whenever it's needed, so options can change while\n * listening. Return `false` to disable the gesture, which also ends one in\n * progress.\n *\n * `onPinchStart` is called once as each gesture starts, with the gesture's\n * info as a third argument. It can return the gesture's handlers, as for\n * `pinch()`.\n */\nexport function addPinchListeners(\n element: Element,\n getValues: () => PinchValues,\n getEnabledOptions: () => PinchOptions | false | undefined,\n onPinchStart: (\n element: Element,\n event: Event,\n info: PinchInfo\n ) => ReturnType<OnPinchStartEvent>\n): VoidFunction {\n const pointers = new Map<number, Point>()\n\n /**\n * The gesture as last reported: focal point, log of a distance and an\n * angle. Only changes in distance and angle matter, so trackpad and\n * Safari input write a virtual distance (the scale) here. Logs keep\n * a long trackpad pinch from overflowing.\n */\n const current = { x: 0, y: 0, l: 0, a: 0 }\n const start = { ...current }\n const prev = { ...current }\n\n let source: \"pointer\" | \"wheel\" | \"gesture\" | undefined\n let lastEvent: Event\n let values: PinchValues | undefined\n let originX = 0\n let originY = 0\n let lastX = 0\n let lastY = 0\n let hasMoved = false\n let wheelTime = 0\n let handlers: PinchHandlers = {}\n let unlock: VoidFunction | null | undefined\n\n /**\n * The gesture's scale and rotation before limits and elastic apply.\n */\n let rawScale = 1\n let rawRotate = 0\n let stopSnap = () => {}\n\n /**\n * The latest enabled options, so a gesture disabled mid-way can still\n * report its end.\n */\n let options: PinchOptions = {}\n const getOptions = () => (options = getEnabledOptions() || options)\n\n const info = (): PinchInfo => ({\n point: { x: current.x, y: current.y },\n offset: { x: current.x - start.x, y: current.y - start.y },\n scale: Math.exp(current.l - start.l),\n rotate: current.a - start.a,\n })\n\n /**\n * Read the element's box and values, and find its layout origin: its\n * centre without `x`/`y`. Scale and rotate are applied around the\n * centre (the default transform origin), so they don't move it.\n */\n const measure = () => {\n const { left, top, width, height } = element.getBoundingClientRect()\n const { scale, rotate, pan, elastic } = getOptions()\n const [s, r, x, y] = (values = getValues())\n const resistance = resolveElastic(elastic)\n\n /**\n * Stop animations on values this gesture writes, and leave the\n * rest running.\n */\n scale !== false && s.stop()\n rotate !== false && r.stop()\n rawScale = unconstrain(s.get(), scale, resistance)\n rawRotate = unconstrain(r.get(), rotate, resistance)\n\n if (pan !== false) {\n x.stop()\n y.stop()\n toPixels(x, (element as HTMLElement).offsetWidth ?? width)\n toPixels(y, (element as HTMLElement).offsetHeight ?? height)\n }\n\n lastX = x.get()\n lastY = y.get()\n originX = left + width / 2 - lastX\n originY = top + height / 2 - lastY\n }\n\n const dragControls = () =>\n elementDragControls.get(visualElementStore.get(element)!)\n\n /**\n * On release, spring scale and rotation back inside their limits (or\n * to a `snap` angle), keeping the focal point in place, or everything\n * back to its origin with `snapToOrigin`.\n */\n const snap = () => {\n const {\n scale: scaleOption,\n rotate: rotateOption,\n pan,\n snapToOrigin,\n transition,\n } = options\n const [scale, rotate, x, y] = values!\n const s0 = scale.get()\n const r0 = rotate.get()\n const x0 = x.get()\n const y0 = y.get()\n const { snap: step } = limitsOf(rotateOption)\n let s1 = clampTo(s0, limitsOf(scaleOption))\n let r1 = clampTo(\n step ? Math.round(r0 / step) * step : r0,\n limitsOf(rotateOption)\n )\n\n if (snapToOrigin) {\n s1 = 1\n // The nearest upright angle, so it turns the shortest way\n r1 = Math.round(r0 / 360) * 360\n }\n\n /**\n * Keep the focal point in place, unless the element doesn't move\n * with it, or a drag carries on and owns x/y.\n */\n const moves = pan !== false && !dragControls()?.isDragging\n const vx = originX + x0 - current.x\n const vy = originY + y0 - current.y\n\n if (\n !s0 ||\n (s1 === s0 && r1 === r0 && !(snapToOrigin && moves && (x0 || y0)))\n ) {\n return\n }\n\n const generator = spring({\n keyframes: [0, 1],\n stiffness: 200,\n damping: 40,\n ...transition,\n })\n const startTime = time.now()\n\n /**\n * Drive the values from one spring, from 0 to 1, so they stay in\n * step and the focal point stays in place.\n */\n const tick = () => {\n if (dragControls()?.isDragging) return stopSnap()\n\n const { value: p, done } = generator.next(time.now() - startTime)\n if (done) stopSnap()\n\n const k = mixNumber(s0, s1, p)\n const r = mixNumber(r0, r1, p)\n const angle = ((r - r0) * Math.PI) / 180\n const cos = (Math.cos(angle) * k) / s0\n const sin = (Math.sin(angle) * k) / s0\n\n scaleOption !== false && scale.set(k)\n rotateOption !== false && rotate.set(r)\n\n if (moves) {\n x.set(\n snapToOrigin\n ? mixNumber(x0, 0, p)\n : x0 + cos * vx - sin * vy - vx\n )\n y.set(\n snapToOrigin\n ? mixNumber(y0, 0, p)\n : y0 + sin * vx + cos * vy - vy\n )\n }\n }\n\n stopSnap = () => cancelFrame(tick)\n frame.update(tick, true)\n }\n\n /**\n * Apply the change in the gesture since the last frame as an\n * incremental scale and rotation around the previous focal point,\n * plus the focal point's movement.\n */\n const apply = () => {\n if (!values || !hasMoved) return\n hasMoved = false\n\n const {\n rotate: rotateOption,\n scale: scaleOption,\n pan,\n elastic,\n } = getOptions()\n const [scale, rotate, x, y] = values\n const resistance = resolveElastic(elastic)\n const latest = scale.get()\n let theta = 0\n let k = 1\n\n /**\n * Apply limits and elastic to the gesture's raw scale and rotation.\n * At a hard limit, the raw value stops too, so moving back responds\n * straight away.\n */\n const constrain = (raw: number, option?: boolean | PinchLimits) => {\n const limits = limitsOf(option)\n const limit = clampTo(raw, limits)\n\n return resistance[raw < limit ? \"min\" : \"max\"]\n ? [applyConstraints(raw, limits, resistance), raw]\n : [limit, limit]\n }\n\n if (scaleOption !== false && latest) {\n const [next, raw] = constrain(\n clamp(1e-9, 1e9, rawScale * Math.exp(current.l - prev.l)),\n scaleOption\n )\n rawScale = raw\n k = next / latest\n scale.set(next)\n }\n\n if (rotateOption !== false) {\n const [next, raw] = constrain(\n rawRotate + current.a - prev.a,\n rotateOption\n )\n rawRotate = raw\n theta = next - rotate.get()\n if (theta) rotate.set(next)\n }\n\n if (pan !== false) {\n /**\n * Pinch owns x/y while it runs, so stop any animation started\n * on them since (like a drag's snap back) taking over after.\n */\n x.stop()\n y.stop()\n\n /**\n * If drag() or the drag prop is dragging this element with one\n * of the touches, it has set x/y this frame to where it started\n * plus the touch's offset. Carry on from our own values instead,\n * and restart the drag from them and the touch's latest point.\n * That way it continues from wherever the pinch leaves the\n * element, and its release velocity only counts movement after\n * the pinch, so a zoom doesn't end in a fling.\n */\n const drag = dragControls()\n const isDragging = drag?.isDragging\n\n if (!isDragging) {\n lastX = x.get()\n lastY = y.get()\n }\n\n const angle = (theta * Math.PI) / 180\n const cos = Math.cos(angle) * k\n const sin = Math.sin(angle) * k\n const dx = prev.x - originX - lastX\n const dy = prev.y - originY - lastY\n\n /**\n * Move the centre so the previous focal point, scaled and\n * rotated around the centre, lands on the current focal point.\n */\n lastX += dx + current.x - prev.x - (cos * dx - sin * dy)\n lastY += dy + current.y - prev.y - (sin * dx + cos * dy)\n\n if (isDragging) {\n const history = drag!.panSession!.history\n history.splice(0, history.length - 1)\n\n /**\n * Date the point long ago, so drag only measures release\n * velocity from moves after the pinch. A move that drag\n * processes as the touch lifts is part of the pinch.\n */\n history[0].timestamp = -Infinity\n drag!.originPoint.x = lastX\n drag!.originPoint.y = lastY\n }\n\n x.set(lastX)\n y.set(lastY)\n }\n\n Object.assign(prev, current)\n handlers.onPinch?.(lastEvent, info())\n }\n\n /**\n * Runs after the update step, where drag sets x/y, so it has the final\n * say on them each frame.\n */\n const update = () => {\n if (!getEnabledOptions()) return end(lastEvent)\n\n apply()\n\n if (source === \"wheel\" && time.now() - wheelTime > wheelTimeout) {\n end(lastEvent)\n }\n }\n\n const begin = (event: Event, from: typeof source) => {\n if (!getEnabledOptions()) return\n\n stopSnap()\n source = from\n lastEvent = event\n hasMoved = false\n values = undefined\n handlers = {}\n Object.assign(start, current)\n Object.assign(prev, current)\n frame.read(measure)\n frame.preRender(update, true)\n\n const result = onPinchStart(element, event, info())\n handlers =\n typeof result === \"function\" ? { onComplete: result } : result || {}\n }\n\n const end = (event: Event) => {\n if (!source) return\n cancelFrame(measure)\n cancelFrame(update)\n\n if (getEnabledOptions()) {\n apply()\n values && snap()\n }\n\n source = undefined\n handlers.onComplete?.(event, info())\n }\n\n const moved = (event: Event) => {\n lastEvent = event\n hasMoved = true\n }\n\n const readPointers = () => {\n const [a, b] = pointers.values()\n const angle = (Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI\n const delta = angle - current.a\n\n current.x = (a.x + b.x) / 2\n current.y = (a.y + b.y) / 2\n current.l = Math.log(Math.hypot(b.x - a.x, b.y - a.y) || 1)\n\n /**\n * Take the shortest way round, so rotation keeps counting past\n * 180deg rather than flipping to -180deg.\n */\n current.a += delta - 360 * Math.round(delta / 360)\n }\n\n const setPointer = (event: PointerEvent) =>\n pointers.set(event.pointerId, { x: event.clientX, y: event.clientY })\n\n const onPointerMove = (event: PointerEvent) => {\n if (!pointers.has(event.pointerId)) return\n setPointer(event)\n\n if (source === \"pointer\") {\n readPointers()\n moved(event)\n }\n }\n\n const onPointerUp = (event: PointerEvent) => {\n if (!pointers.delete(event.pointerId)) return\n\n if (source === \"pointer\") end(event)\n\n if (!pointers.size) {\n toggleWindowListeners()\n release()\n }\n }\n\n /**\n * Once a touch is down on the element, listen on the window too, so\n * the second touch can land beside it (for instance on a small image).\n */\n const onPointerDown = (event: PointerEvent) => {\n if (\n source ||\n pointers.size > 1 ||\n pointers.has(event.pointerId) ||\n event.pointerType === \"mouse\"\n ) {\n return\n }\n\n if (!pointers.size) toggleWindowListeners(true)\n setPointer(event)\n\n if (pointers.size === 2) {\n readPointers()\n begin(event, \"pointer\")\n\n /**\n * Unless this element drags, hold the drag lock until every\n * touch lifts. A press on it then ends as a cancel, rather than\n * a tap, and a draggable parent doesn't drag.\n */\n if (\n source &&\n !unlock &&\n !elementDragControls.get(visualElementStore.get(element)!)\n ) {\n unlock = setDragLock(true)\n }\n }\n }\n\n /**\n * Release the drag lock a frame later, so a press ending on this same\n * pointerup still sees it.\n */\n const release = () => {\n const done = unlock\n unlock = undefined\n done && frame.postRender(done)\n }\n\n const toggleWindowListeners = (add?: boolean) => {\n const method = add ? \"addEventListener\" : \"removeEventListener\"\n window[method](\"pointerdown\", onPointerDown as EventListener)\n window[method](\"pointermove\", onPointerMove as EventListener)\n window[method](\"pointerup\", onPointerUp as EventListener)\n window[method](\"pointercancel\", onPointerUp as EventListener)\n }\n\n const onWheel = (event: WheelEvent) => {\n if (!event.ctrlKey || (source && source !== \"wheel\")) return\n\n current.x = event.clientX\n current.y = event.clientY\n\n if (!source) {\n current.l = 0\n begin(event, \"wheel\")\n if (!source) return\n }\n\n event.preventDefault()\n\n /**\n * Lines (Firefox's mouse wheel) to pixels, and cap each event so a\n * mouse wheel notch with ctrl held (about 100px) zooms a step.\n */\n current.l -=\n clamp(-50, 50, event.deltaY * (event.deltaMode ? 16 : 1)) / 100\n wheelTime = time.now()\n moved(event)\n }\n\n /**\n * Safari reports trackpad pinches as `gesture*` events. iOS Safari\n * fires them for touches too, alongside the pointer events we track.\n */\n const onGesture = (event: Event) => {\n if (!pointers.size && (!source || source === \"gesture\")) {\n const { scale, rotation, clientX, clientY } = event as any\n current.x = clientX\n current.y = clientY\n current.l = Math.log(scale)\n current.a = rotation\n\n if (source) {\n moved(event)\n if (event.type === \"gestureend\") end(event)\n } else if (event.type === \"gesturestart\") {\n begin(event, \"gesture\")\n }\n }\n\n if (source) event.preventDefault()\n }\n\n const listeners = {\n pointerdown: onPointerDown,\n wheel: onWheel,\n gesturestart: onGesture,\n gesturechange: onGesture,\n gestureend: onGesture,\n }\n\n for (const name in listeners) {\n element.addEventListener(\n name,\n listeners[name as keyof typeof listeners] as EventListener,\n { passive: false }\n )\n }\n\n return () => {\n for (const name in listeners) {\n element.removeEventListener(\n name,\n listeners[name as keyof typeof listeners] as EventListener\n )\n }\n toggleWindowListeners()\n end(lastEvent)\n stopSnap()\n pointers.clear()\n release()\n }\n}\n\nconst valueKeys = [\"scale\", \"rotate\", \"x\", \"y\"]\n\n/**\n * The element's scale/rotate/x/y motion values: those of its\n * VisualElement if it has one (it's a <motion.*> component, or drag() or\n * animateLayout() own it), otherwise those animate() binds to it, created\n * from its current style if this is the first time.\n */\nconst getElementValues = (element: HTMLElement | SVGElement) => {\n const visualElement = visualElementStore.get(element)\n const effect = isSVGElement(element) ? svgSubjectEffect : styleSubjectEffect\n\n return valueKeys.map((key) => {\n if (visualElement) {\n return visualElement.getValue(key, key === \"scale\" ? 1 : 0)\n }\n\n let value = effect.get(element as any, key)\n\n if (!value) {\n value = motionValue(readStyleValue(element, key))\n effect(element as any, { [key]: value })\n }\n\n return value\n }) as PinchValues\n}\n\n/**\n * Make elements pinchable. Returns a function that removes the gesture.\n * The start callback is optional:\n *\n * ```javascript\n * pinch(\"img\")\n * pinch(\"img\", { scale: { min: 1, max: 4 } })\n * ```\n *\n * ```javascript\n * const stop = pinch(\"#photo\", (element, startEvent) => {\n * return (endEvent, info) => {}\n * }, { scale: { min: 1, max: 4 } })\n * ```\n *\n * `onPinchStart` is called once as each pinch starts. It can return a\n * function to call when the pinch ends, or an object of handlers:\n *\n * ```javascript\n * pinch(\"#photo\", () => ({\n * onPinch: (event, { scale }) => {},\n * onComplete: (event, info) => {},\n * }))\n * ```\n *\n * Touches, trackpad pinches and Safari's gesture events scale the element\n * around the focal point and move it with the touches. Its `scale`,\n * `rotate`, `x` and `y` are motion values shared with `animate()`, so an\n * `onComplete` handler can animate the element after a pinch.\n *\n * @public\n */\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n options?: PinchOptions\n): VoidFunction\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n onPinchStart?: OnPinchStartEvent,\n options?: PinchOptions\n): VoidFunction\nexport function pinch(\n elementOrSelector: ElementOrSelector,\n startOrOptions?: OnPinchStartEvent | PinchOptions,\n options: PinchOptions = {}\n): VoidFunction {\n let onPinchStart: OnPinchStartEvent = () => {}\n\n if (typeof startOrOptions === \"function\") {\n onPinchStart = startOrOptions\n } else if (startOrOptions) {\n options = startOrOptions\n }\n\n const scope = activeScope.current\n\n /**\n * Run the start callback and the handlers it returns in the active\n * scope, so work they start is collected. A returned function is\n * bound by `scope.bind` itself.\n */\n if (scope) {\n const start = scope.bind(onPinchStart)\n onPinchStart = (element, event) => {\n const result = start(element, event)\n if (typeof result !== \"object\") return result\n\n const handlers: PinchHandlers = {}\n for (const key in result) {\n const name = key as keyof PinchHandlers\n const handler = result[name]\n handlers[name] = handler && scope.bind(handler)\n }\n return handlers\n }\n }\n\n const cleanups = resolveElements(elementOrSelector).map((element) => {\n scope?.track(element)\n\n const { style } = element as HTMLElement\n const touchAction = style.touchAction\n style.touchAction = \"none\"\n\n const remove = addPinchListeners(\n element,\n () => getElementValues(element as HTMLElement),\n () => options,\n onPinchStart\n )\n\n return () => {\n remove()\n style.touchAction = touchAction\n }\n })\n\n return addToScope(() => cleanups.forEach((cleanup) => cleanup()))\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAmMA;;;AAGG;AACH,MAAM,YAAY,GAAG,GAAG;AAExB;;;AAGG;AACH,MAAM,QAAQ,GAAG,CAAC,KAA0B,EAAE,IAAY,KAAI;AAC1D,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAqB;AAE7C,IAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC5B,KAAK,CAAC,GAA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AA,KAAK,CAAC,WAAW,GAAG,MAAM;QAE1B,MAAM,MAAM,GAAG,iBAAiB,CAC5B,OAAO,EACP,MAAM,gBAAgB,CAAC,OAAsB,CAAC,EAC9C,MAAM,OAAO,EACb,YAAY,CACf;AAED,QAAA,OAAO,MAAK;AACR,YAAA,MAAM,EAAE;AACR,YAAA,KAAK,CAAC,WAAW,GAAG,WAAW;AACnC,QAAA,CAAC;AACL,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,UAAU,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC,CAAC;AACrE;;;;"}
@@ -160,14 +160,18 @@ function press(targetOrSelector, onPressStart, options = {}) {
160
160
  */
161
161
  const endEventOptions = { ...eventOptions, capture: true };
162
162
  const onPointerEnd = (endEvent, success) => {
163
+ /**
164
+ * Another touch lifting (for instance after a pinch) doesn't
165
+ * end the press.
166
+ */
167
+ if (!isPrimaryPointer(endEvent))
168
+ return;
163
169
  window.removeEventListener("pointerup", onPointerUp, endEventOptions);
164
170
  window.removeEventListener("pointercancel", onPointerCancel, endEventOptions);
165
171
  window.removeEventListener("pointermove", onPointerMove, endEventOptions);
166
172
  target.removeEventListener("contextmenu", preventDefault);
167
173
  cancelFrame(tick);
168
174
  isPressing.delete(target);
169
- if (!isPrimaryPointer(endEvent))
170
- return;
171
175
  /**
172
176
  * A press that ends while a drag is active is a cancel.
173
177
  */