motion-dom 14.10.1 → 14.11.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/dist/cjs/index.js CHANGED
@@ -9625,6 +9625,7 @@ const variantPriorityOrder = [
9625
9625
  "whileHover",
9626
9626
  "whileTap",
9627
9627
  "whileDrag",
9628
+ "whilePinch",
9628
9629
  "exit",
9629
9630
  ];
9630
9631
  const variantProps = /* @__PURE__ */ ["initial"].concat(variantPriorityOrder);
@@ -11418,6 +11419,10 @@ class VisualElementDragControls {
11418
11419
  this.openDragLock = null;
11419
11420
  this.isDragging = false;
11420
11421
  this.currentDirection = null;
11422
+ /**
11423
+ * Where the drag started, which pointer offsets are added to. Public
11424
+ * so pinch() can restart a drag from where it leaves the element.
11425
+ */
11421
11426
  this.originPoint = { x: 0, y: 0 };
11422
11427
  /**
11423
11428
  * The permitted boundaries of travel, in pixels.
@@ -12189,6 +12194,587 @@ function hover(elementOrSelector, onHoverStart, options = {}) {
12189
12194
  return cancel;
12190
12195
  }
12191
12196
 
12197
+ /**
12198
+ * A trackpad pinch arrives as a stream of `wheel` events with no end
12199
+ * event, so it ends once none have arrived for this long.
12200
+ */
12201
+ const wheelTimeout = 150;
12202
+ /**
12203
+ * Convert an `x`/`y` set in other units (e.g. `"-50%"` to centre an
12204
+ * element) to pixels, so the gesture can add to it.
12205
+ */
12206
+ const toPixels = (value, size) => {
12207
+ const latest = value.get();
12208
+ if (typeof latest === "string") {
12209
+ value.set(parseFloat(latest) * (latest.endsWith("%") ? size / 100 : 1));
12210
+ }
12211
+ };
12212
+ const limitsOf = (option) => typeof option === "object" ? option : {};
12213
+ /**
12214
+ * Resolve `elastic` to a resistance for each side, as for `dragElastic`.
12215
+ */
12216
+ const resolveElastic = (elastic = defaultElastic) => {
12217
+ const side = (value) => value === true ? defaultElastic : +(value || 0);
12218
+ return typeof elastic === "object"
12219
+ ? { min: side(elastic.min), max: side(elastic.max) }
12220
+ : { min: side(elastic), max: side(elastic) };
12221
+ };
12222
+ /**
12223
+ * Whether the gesture writes `x`/`y`: to follow the focal point, or to
12224
+ * keep an `origin` on the element in place.
12225
+ */
12226
+ const writesXY = ({ pan, origin }) => pan !== false || !!origin;
12227
+ const clampTo = (value, { min = -Infinity, max = Infinity }) => motionUtils.clamp(min, max, value);
12228
+ /**
12229
+ * The raw gesture value that elastic shows as `value`. A pinch that starts
12230
+ * while a value is still past its limit (like during a spring back) carries
12231
+ * on from it, rather than jumping.
12232
+ */
12233
+ const unconstrain = (value, option, resistance) => {
12234
+ const limit = clampTo(value, limitsOf(option));
12235
+ const elastic = resistance[value < limit ? "min" : "max"];
12236
+ return elastic ? limit + (value - limit) / elastic : value;
12237
+ };
12238
+ /**
12239
+ * Listen for pinch gestures on `element`: two touches (or pens), a trackpad
12240
+ * pinch (`wheel` with `ctrlKey`, as Chrome, Edge and Firefox report it),
12241
+ * and Safari's `gesture*` events.
12242
+ *
12243
+ * `getValues` is called each time a gesture starts, in the frame's read
12244
+ * step, for the scale/rotate/x/y values to write to. It runs alongside the
12245
+ * element measurement so neither forces a layout.
12246
+ *
12247
+ * `getOptions` is read whenever it's needed, so options can change while
12248
+ * listening. Return `false` to disable the gesture, which also ends one in
12249
+ * progress.
12250
+ *
12251
+ * `onPinchStart` is called once as each gesture starts, with the gesture's
12252
+ * info as a third argument. It can return the gesture's handlers, as for
12253
+ * `pinch()`.
12254
+ */
12255
+ function addPinchListeners(element, getValues, getEnabledOptions, onPinchStart) {
12256
+ const pointers = new Map();
12257
+ /**
12258
+ * The gesture as last reported: focal point, log of a distance and an
12259
+ * angle. Only changes in distance and angle matter, so trackpad and
12260
+ * Safari input write a virtual distance (the scale) here. Logs keep
12261
+ * a long trackpad pinch from overflowing.
12262
+ */
12263
+ const current = { x: 0, y: 0, l: 0, a: 0 };
12264
+ const start = { ...current };
12265
+ const prev = { ...current };
12266
+ let source;
12267
+ let lastEvent;
12268
+ let values;
12269
+ let originX = 0;
12270
+ let originY = 0;
12271
+ let width = 0;
12272
+ let height = 0;
12273
+ let lastX = 0;
12274
+ let lastY = 0;
12275
+ let hasMoved = false;
12276
+ let wheelTime = 0;
12277
+ let handlers = {};
12278
+ let unlock;
12279
+ /**
12280
+ * The gesture's scale and rotation before limits and elastic apply.
12281
+ */
12282
+ let rawScale = 1;
12283
+ let rawRotate = 0;
12284
+ let stopSnap = () => { };
12285
+ /**
12286
+ * The latest enabled options, so a gesture disabled mid-way can still
12287
+ * report its end.
12288
+ */
12289
+ let options = {};
12290
+ const getOptions = () => (options = getEnabledOptions() || options);
12291
+ const info = () => ({
12292
+ point: { x: current.x, y: current.y },
12293
+ offset: { x: current.x - start.x, y: current.y - start.y },
12294
+ scale: Math.exp(current.l - start.l),
12295
+ rotate: current.a - start.a,
12296
+ });
12297
+ /**
12298
+ * Read the element's box and values, and find its layout origin: its
12299
+ * centre without `x`/`y`. Scale and rotate are applied around the
12300
+ * centre (the default transform origin), so they don't move it.
12301
+ */
12302
+ const measure = () => {
12303
+ const box = element.getBoundingClientRect();
12304
+ const { left, top } = box;
12305
+ const { scale, rotate, elastic } = getOptions();
12306
+ const [s, r, x, y] = (values = getValues());
12307
+ const resistance = resolveElastic(elastic);
12308
+ /**
12309
+ * Stop animations on values this gesture writes, and leave the
12310
+ * rest running.
12311
+ */
12312
+ scale !== false && s.stop();
12313
+ rotate !== false && r.stop();
12314
+ rawScale = unconstrain(s.get(), scale, resistance);
12315
+ rawRotate = unconstrain(r.get(), rotate, resistance);
12316
+ width = element.offsetWidth ?? box.width;
12317
+ height = element.offsetHeight ?? box.height;
12318
+ if (writesXY(options)) {
12319
+ x.stop();
12320
+ y.stop();
12321
+ toPixels(x, width);
12322
+ toPixels(y, height);
12323
+ }
12324
+ lastX = x.get();
12325
+ lastY = y.get();
12326
+ originX = left + box.width / 2 - lastX;
12327
+ originY = top + box.height / 2 - lastY;
12328
+ };
12329
+ /**
12330
+ * The point scale and rotation pivot around, in client coordinates:
12331
+ * the focal point, or `origin` on the element at scale `s`, rotation
12332
+ * `r` and offset `x`/`y`.
12333
+ */
12334
+ const pivot = (focal, s, r, x, y) => {
12335
+ const { origin } = options;
12336
+ if (typeof origin !== "object")
12337
+ return focal;
12338
+ const a = (r * Math.PI) / 180;
12339
+ const u = (origin.x - 0.5) * width * s;
12340
+ const v = (origin.y - 0.5) * height * s;
12341
+ return {
12342
+ x: originX + x + Math.cos(a) * u - Math.sin(a) * v,
12343
+ y: originY + y + Math.sin(a) * u + Math.cos(a) * v,
12344
+ };
12345
+ };
12346
+ const dragControls = () => elementDragControls.get(visualElementStore.get(element));
12347
+ /**
12348
+ * On release, spring scale and rotation back inside their limits (or
12349
+ * to a `snap` angle), keeping the focal point in place, or everything
12350
+ * back to its origin with `snapToOrigin`.
12351
+ */
12352
+ const snap = () => {
12353
+ const { scale: scaleOption, rotate: rotateOption, snapToOrigin, transition, } = options;
12354
+ const [scale, rotate, x, y] = values;
12355
+ const s0 = scale.get();
12356
+ const r0 = rotate.get();
12357
+ const x0 = x.get();
12358
+ const y0 = y.get();
12359
+ const { snap: step } = limitsOf(rotateOption);
12360
+ let s1 = clampTo(s0, limitsOf(scaleOption));
12361
+ /**
12362
+ * Snap to the step nearest where the release velocity would carry
12363
+ * the rotation, found as inertia finds its target (with a lower power
12364
+ * than inertia's 0.8).
12365
+ */
12366
+ let r1 = clampTo(step
12367
+ ? Math.round((r0 + 0.2 * rotate.getVelocity()) / step) * step
12368
+ : r0, limitsOf(rotateOption));
12369
+ if (snapToOrigin) {
12370
+ s1 = 1;
12371
+ // The nearest upright angle, so it turns the shortest way
12372
+ r1 = Math.round(r0 / 360) * 360;
12373
+ }
12374
+ /**
12375
+ * Keep the focal point in place, unless the element doesn't move
12376
+ * with it, or a drag carries on and owns x/y.
12377
+ */
12378
+ const moves = writesXY(options) && !dragControls()?.isDragging;
12379
+ const p0 = pivot(current, s0, r0, x0, y0);
12380
+ const vx = originX + x0 - p0.x;
12381
+ const vy = originY + y0 - p0.y;
12382
+ /**
12383
+ * Scale, rotation and x/y at progress `p` of the snap, keeping the
12384
+ * focal point in place.
12385
+ */
12386
+ const at = (p) => {
12387
+ const k = mixNumber$1(s0, s1, p);
12388
+ const r = mixNumber$1(r0, r1, p);
12389
+ const angle = ((r - r0) * Math.PI) / 180;
12390
+ const cos = (Math.cos(angle) * k) / s0;
12391
+ const sin = (Math.sin(angle) * k) / s0;
12392
+ return [
12393
+ k,
12394
+ r,
12395
+ x0 + cos * vx - sin * vy - vx,
12396
+ y0 + sin * vx + cos * vy - vy,
12397
+ ];
12398
+ };
12399
+ if (!s0 ||
12400
+ (s1 === s0 && r1 === r0 && !(snapToOrigin && moves && (x0 || y0)))) {
12401
+ return;
12402
+ }
12403
+ const generator = spring({
12404
+ keyframes: [0, 1],
12405
+ stiffness: 200,
12406
+ damping: 40,
12407
+ ...transition,
12408
+ });
12409
+ const startTime = time.now();
12410
+ /**
12411
+ * Drive the values from one spring, from 0 to 1, so they stay in
12412
+ * step and the focal point stays in place.
12413
+ */
12414
+ const tick = () => {
12415
+ if (dragControls()?.isDragging)
12416
+ return stopSnap();
12417
+ const { value: p, done } = generator.next(time.now() - startTime);
12418
+ if (done)
12419
+ stopSnap();
12420
+ const [k, r, fx, fy] = at(p);
12421
+ scaleOption !== false && scale.set(k);
12422
+ rotateOption !== false && rotate.set(r);
12423
+ if (moves) {
12424
+ x.set(snapToOrigin ? mixNumber$1(x0, 0, p) : fx);
12425
+ y.set(snapToOrigin ? mixNumber$1(y0, 0, p) : fy);
12426
+ }
12427
+ };
12428
+ stopSnap = () => cancelFrame(tick);
12429
+ frame.update(tick, true);
12430
+ };
12431
+ /**
12432
+ * Apply the change in the gesture since the last frame as an
12433
+ * incremental scale and rotation around the previous focal point,
12434
+ * plus the focal point's movement.
12435
+ */
12436
+ const apply = () => {
12437
+ if (!values || !hasMoved)
12438
+ return;
12439
+ hasMoved = false;
12440
+ const { rotate: rotateOption, scale: scaleOption, pan, elastic, } = getOptions();
12441
+ const [scale, rotate, x, y] = values;
12442
+ const resistance = resolveElastic(elastic);
12443
+ const latest = scale.get();
12444
+ const drag = dragControls();
12445
+ const isDragging = drag?.isDragging;
12446
+ if (!isDragging) {
12447
+ lastX = x.get();
12448
+ lastY = y.get();
12449
+ }
12450
+ const p = pivot(prev, latest, rotate.get(), lastX, lastY);
12451
+ let theta = 0;
12452
+ let k = 1;
12453
+ /**
12454
+ * Apply limits and elastic to the gesture's raw scale and rotation.
12455
+ * At a hard limit, the raw value stops too, so moving back responds
12456
+ * straight away.
12457
+ */
12458
+ const constrain = (raw, option) => {
12459
+ const limits = limitsOf(option);
12460
+ const limit = clampTo(raw, limits);
12461
+ return resistance[raw < limit ? "min" : "max"]
12462
+ ? [applyConstraints(raw, limits, resistance), raw]
12463
+ : [limit, limit];
12464
+ };
12465
+ if (scaleOption !== false && latest) {
12466
+ const [next, raw] = constrain(motionUtils.clamp(1e-9, 1e9, rawScale * Math.exp(current.l - prev.l)), scaleOption);
12467
+ rawScale = raw;
12468
+ k = next / latest;
12469
+ scale.set(next);
12470
+ }
12471
+ if (rotateOption !== false) {
12472
+ const [next, raw] = constrain(rawRotate + current.a - prev.a, rotateOption);
12473
+ rawRotate = raw;
12474
+ theta = next - rotate.get();
12475
+ if (theta)
12476
+ rotate.set(next);
12477
+ }
12478
+ if (writesXY(options)) {
12479
+ /**
12480
+ * Pinch owns x/y while it runs, so stop any animation started
12481
+ * on them since (like a drag's snap back) taking over after.
12482
+ */
12483
+ x.stop();
12484
+ y.stop();
12485
+ /**
12486
+ * If drag() or the drag prop is dragging this element with one
12487
+ * of the touches, it has set x/y this frame to where it started
12488
+ * plus the touch's offset. Carry on from our own values instead,
12489
+ * and restart the drag from them and the touch's latest point.
12490
+ * That way it continues from wherever the pinch leaves the
12491
+ * element, and its release velocity only counts movement after
12492
+ * the pinch, so a zoom doesn't end in a fling.
12493
+ */
12494
+ const angle = (theta * Math.PI) / 180;
12495
+ const cos = Math.cos(angle) * k;
12496
+ const sin = Math.sin(angle) * k;
12497
+ const dx = p.x - originX - lastX;
12498
+ const dy = p.y - originY - lastY;
12499
+ const panX = pan !== false ? current.x - prev.x : 0;
12500
+ const panY = pan !== false ? current.y - prev.y : 0;
12501
+ /**
12502
+ * Move the centre so the pivot, scaled and rotated around the
12503
+ * centre, stays in place, plus the focal point's movement.
12504
+ */
12505
+ lastX += dx + panX - (cos * dx - sin * dy);
12506
+ lastY += dy + panY - (sin * dx + cos * dy);
12507
+ if (isDragging) {
12508
+ const history = drag.panSession.history;
12509
+ history.splice(0, history.length - 1);
12510
+ /**
12511
+ * Date the point long ago, so drag only measures release
12512
+ * velocity from moves after the pinch. A move that drag
12513
+ * processes as the touch lifts is part of the pinch.
12514
+ */
12515
+ history[0].timestamp = -Infinity;
12516
+ drag.originPoint.x = lastX;
12517
+ drag.originPoint.y = lastY;
12518
+ }
12519
+ x.set(lastX);
12520
+ y.set(lastY);
12521
+ }
12522
+ Object.assign(prev, current);
12523
+ handlers.onPinch?.(lastEvent, info());
12524
+ };
12525
+ /**
12526
+ * Runs after the update step, where drag sets x/y, so it has the final
12527
+ * say on them each frame.
12528
+ */
12529
+ const update = () => {
12530
+ if (!getEnabledOptions())
12531
+ return end(lastEvent);
12532
+ apply();
12533
+ if (source === "wheel" && time.now() - wheelTime > wheelTimeout) {
12534
+ end(lastEvent);
12535
+ }
12536
+ };
12537
+ const begin = (event, from) => {
12538
+ if (!getEnabledOptions())
12539
+ return;
12540
+ stopSnap();
12541
+ source = from;
12542
+ lastEvent = event;
12543
+ hasMoved = false;
12544
+ values = undefined;
12545
+ handlers = {};
12546
+ Object.assign(start, current);
12547
+ Object.assign(prev, current);
12548
+ frame.read(measure);
12549
+ frame.preRender(update, true);
12550
+ const result = onPinchStart(element, event, info());
12551
+ handlers =
12552
+ typeof result === "function" ? { onComplete: result } : result || {};
12553
+ };
12554
+ const end = (event) => {
12555
+ if (!source)
12556
+ return;
12557
+ cancelFrame(measure);
12558
+ cancelFrame(update);
12559
+ if (getEnabledOptions()) {
12560
+ apply();
12561
+ values && snap();
12562
+ }
12563
+ source = undefined;
12564
+ handlers.onComplete?.(event, info());
12565
+ };
12566
+ const moved = (event) => {
12567
+ lastEvent = event;
12568
+ hasMoved = true;
12569
+ };
12570
+ const readPointers = () => {
12571
+ const [a, b] = pointers.values();
12572
+ const angle = (Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI;
12573
+ const delta = angle - current.a;
12574
+ current.x = (a.x + b.x) / 2;
12575
+ current.y = (a.y + b.y) / 2;
12576
+ current.l = Math.log(Math.hypot(b.x - a.x, b.y - a.y) || 1);
12577
+ /**
12578
+ * Take the shortest way round, so rotation keeps counting past
12579
+ * 180deg rather than flipping to -180deg.
12580
+ */
12581
+ current.a += delta - 360 * Math.round(delta / 360);
12582
+ };
12583
+ const setPointer = (event) => pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
12584
+ const onPointerMove = (event) => {
12585
+ if (!pointers.has(event.pointerId))
12586
+ return;
12587
+ setPointer(event);
12588
+ if (source === "pointer") {
12589
+ readPointers();
12590
+ moved(event);
12591
+ }
12592
+ };
12593
+ const onPointerUp = (event) => {
12594
+ if (!pointers.delete(event.pointerId))
12595
+ return;
12596
+ if (source === "pointer")
12597
+ end(event);
12598
+ if (!pointers.size) {
12599
+ toggleWindowListeners();
12600
+ release();
12601
+ }
12602
+ };
12603
+ /**
12604
+ * Once a touch is down on the element, listen on the window too, so
12605
+ * the second touch can land beside it (for instance on a small image).
12606
+ */
12607
+ const onPointerDown = (event) => {
12608
+ if (source ||
12609
+ pointers.size > 1 ||
12610
+ pointers.has(event.pointerId) ||
12611
+ event.pointerType === "mouse") {
12612
+ return;
12613
+ }
12614
+ if (!pointers.size)
12615
+ toggleWindowListeners(true);
12616
+ setPointer(event);
12617
+ if (pointers.size === 2) {
12618
+ readPointers();
12619
+ begin(event, "pointer");
12620
+ /**
12621
+ * Unless this element drags, hold the drag lock until every
12622
+ * touch lifts. A press on it then ends as a cancel, rather than
12623
+ * a tap, and a draggable parent doesn't drag.
12624
+ */
12625
+ if (source &&
12626
+ !unlock &&
12627
+ !elementDragControls.get(visualElementStore.get(element))) {
12628
+ unlock = setDragLock(true);
12629
+ }
12630
+ }
12631
+ };
12632
+ /**
12633
+ * Release the drag lock a frame later, so a press ending on this same
12634
+ * pointerup still sees it.
12635
+ */
12636
+ const release = () => {
12637
+ const done = unlock;
12638
+ unlock = undefined;
12639
+ done && frame.postRender(done);
12640
+ };
12641
+ const toggleWindowListeners = (add) => {
12642
+ const method = add ? "addEventListener" : "removeEventListener";
12643
+ window[method]("pointerdown", onPointerDown);
12644
+ window[method]("pointermove", onPointerMove);
12645
+ window[method]("pointerup", onPointerUp);
12646
+ window[method]("pointercancel", onPointerUp);
12647
+ };
12648
+ const onWheel = (event) => {
12649
+ if (!event.ctrlKey || (source && source !== "wheel"))
12650
+ return;
12651
+ current.x = event.clientX;
12652
+ current.y = event.clientY;
12653
+ if (!source) {
12654
+ current.l = 0;
12655
+ begin(event, "wheel");
12656
+ if (!source)
12657
+ return;
12658
+ }
12659
+ event.preventDefault();
12660
+ /**
12661
+ * Lines (Firefox's mouse wheel) to pixels, and cap each event so a
12662
+ * mouse wheel notch with ctrl held (about 100px) zooms a step.
12663
+ */
12664
+ current.l -=
12665
+ motionUtils.clamp(-50, 50, event.deltaY * (event.deltaMode ? 16 : 1)) / 100;
12666
+ wheelTime = time.now();
12667
+ moved(event);
12668
+ };
12669
+ /**
12670
+ * Safari reports trackpad pinches as `gesture*` events. iOS Safari
12671
+ * fires them for touches too, alongside the pointer events we track.
12672
+ */
12673
+ const onGesture = (event) => {
12674
+ if (!pointers.size && (!source || source === "gesture")) {
12675
+ const { scale, rotation, clientX, clientY } = event;
12676
+ current.x = clientX;
12677
+ current.y = clientY;
12678
+ current.l = Math.log(scale);
12679
+ current.a = rotation;
12680
+ if (source) {
12681
+ moved(event);
12682
+ if (event.type === "gestureend")
12683
+ end(event);
12684
+ }
12685
+ else if (event.type === "gesturestart") {
12686
+ begin(event, "gesture");
12687
+ }
12688
+ }
12689
+ if (source)
12690
+ event.preventDefault();
12691
+ };
12692
+ const listeners = {
12693
+ pointerdown: onPointerDown,
12694
+ wheel: onWheel,
12695
+ gesturestart: onGesture,
12696
+ gesturechange: onGesture,
12697
+ gestureend: onGesture,
12698
+ };
12699
+ for (const name in listeners) {
12700
+ element.addEventListener(name, listeners[name], { passive: false });
12701
+ }
12702
+ return () => {
12703
+ for (const name in listeners) {
12704
+ element.removeEventListener(name, listeners[name]);
12705
+ }
12706
+ toggleWindowListeners();
12707
+ end(lastEvent);
12708
+ stopSnap();
12709
+ pointers.clear();
12710
+ release();
12711
+ };
12712
+ }
12713
+ const valueKeys = ["scale", "rotate", "x", "y"];
12714
+ /**
12715
+ * The element's scale/rotate/x/y motion values: those of its
12716
+ * VisualElement if it has one (it's a <motion.*> component, or drag() or
12717
+ * animateLayout() own it), otherwise those animate() binds to it, created
12718
+ * from its current style if this is the first time.
12719
+ */
12720
+ const getElementValues = (element) => {
12721
+ const visualElement = visualElementStore.get(element);
12722
+ const effect = isSVGElement(element) ? svgSubjectEffect : styleSubjectEffect;
12723
+ return valueKeys.map((key) => {
12724
+ if (visualElement) {
12725
+ return visualElement.getValue(key, key === "scale" ? 1 : 0);
12726
+ }
12727
+ let value = effect.get(element, key);
12728
+ if (!value) {
12729
+ value = motionValue(readStyleValue(element, key));
12730
+ effect(element, { [key]: value });
12731
+ }
12732
+ return value;
12733
+ });
12734
+ };
12735
+ function pinch(elementOrSelector, startOrOptions, options = {}) {
12736
+ let onPinchStart = () => { };
12737
+ if (typeof startOrOptions === "function") {
12738
+ onPinchStart = startOrOptions;
12739
+ }
12740
+ else if (startOrOptions) {
12741
+ options = startOrOptions;
12742
+ }
12743
+ const scope = activeScope.current;
12744
+ /**
12745
+ * Run the start callback and the handlers it returns in the active
12746
+ * scope, so work they start is collected. A returned function is
12747
+ * bound by `scope.bind` itself.
12748
+ */
12749
+ if (scope) {
12750
+ const start = scope.bind(onPinchStart);
12751
+ onPinchStart = (element, event) => {
12752
+ const result = start(element, event);
12753
+ if (typeof result !== "object")
12754
+ return result;
12755
+ const handlers = {};
12756
+ for (const key in result) {
12757
+ const name = key;
12758
+ const handler = result[name];
12759
+ handlers[name] = handler && scope.bind(handler);
12760
+ }
12761
+ return handlers;
12762
+ };
12763
+ }
12764
+ const cleanups = resolveElements(elementOrSelector).map((element) => {
12765
+ scope?.track(element);
12766
+ const { style } = element;
12767
+ const touchAction = style.touchAction;
12768
+ style.touchAction = "none";
12769
+ const remove = addPinchListeners(element, () => getElementValues(element), () => options, onPinchStart);
12770
+ return () => {
12771
+ remove();
12772
+ style.touchAction = touchAction;
12773
+ };
12774
+ });
12775
+ return addToScope(() => cleanups.forEach((cleanup) => cleanup()));
12776
+ }
12777
+
12192
12778
  /**
12193
12779
  * Recursively traverse up the tree to check whether the provided child node
12194
12780
  * is the parent or a descendant of it.
@@ -12404,14 +12990,18 @@ function press(targetOrSelector, onPressStart, options = {}) {
12404
12990
  */
12405
12991
  const endEventOptions = { ...eventOptions, capture: true };
12406
12992
  const onPointerEnd = (endEvent, success) => {
12993
+ /**
12994
+ * Another touch lifting (for instance after a pinch) doesn't
12995
+ * end the press.
12996
+ */
12997
+ if (!isPrimaryPointer(endEvent))
12998
+ return;
12407
12999
  window.removeEventListener("pointerup", onPointerUp, endEventOptions);
12408
13000
  window.removeEventListener("pointercancel", onPointerCancel, endEventOptions);
12409
13001
  window.removeEventListener("pointermove", onPointerMove, endEventOptions);
12410
13002
  target.removeEventListener("contextmenu", preventDefault);
12411
13003
  cancelFrame(tick);
12412
13004
  isPressing.delete(target);
12413
- if (!isPrimaryPointer(endEvent))
12414
- return;
12415
13005
  /**
12416
13006
  * A press that ends while a drag is active is a cancel.
12417
13007
  */
@@ -14929,6 +15519,7 @@ exports.addAttrValue = addAttrValue;
14929
15519
  exports.addBuilderToScope = addBuilderToScope;
14930
15520
  exports.addDomEvent = addDomEvent;
14931
15521
  exports.addEffect = addEffect;
15522
+ exports.addPinchListeners = addPinchListeners;
14932
15523
  exports.addPointerEvent = addPointerEvent;
14933
15524
  exports.addPointerInfo = addPointerInfo;
14934
15525
  exports.addSVGValue = addSVGValue;
@@ -15124,6 +15715,7 @@ exports.parseAnimateLayoutArgs = parseAnimateLayoutArgs;
15124
15715
  exports.parseCSSVariable = parseCSSVariable;
15125
15716
  exports.parseValueFromTransform = parseValueFromTransform;
15126
15717
  exports.percent = percent;
15718
+ exports.pinch = pinch;
15127
15719
  exports.pixelsToPercent = pixelsToPercent;
15128
15720
  exports.positionalKeys = positionalKeys;
15129
15721
  exports.prefersReducedMotion = prefersReducedMotion;