motion 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.
@@ -9921,6 +9921,7 @@
9921
9921
  "whileHover",
9922
9922
  "whileTap",
9923
9923
  "whileDrag",
9924
+ "whilePinch",
9924
9925
  "exit",
9925
9926
  ];
9926
9927
  const variantProps = /* @__PURE__ */ ["initial"].concat(variantPriorityOrder);
@@ -11720,6 +11721,10 @@
11720
11721
  this.openDragLock = null;
11721
11722
  this.isDragging = false;
11722
11723
  this.currentDirection = null;
11724
+ /**
11725
+ * Where the drag started, which pointer offsets are added to. Public
11726
+ * so pinch() can restart a drag from where it leaves the element.
11727
+ */
11723
11728
  this.originPoint = { x: 0, y: 0 };
11724
11729
  /**
11725
11730
  * The permitted boundaries of travel, in pixels.
@@ -12490,6 +12495,587 @@
12490
12495
  return cancel;
12491
12496
  }
12492
12497
 
12498
+ /**
12499
+ * A trackpad pinch arrives as a stream of `wheel` events with no end
12500
+ * event, so it ends once none have arrived for this long.
12501
+ */
12502
+ const wheelTimeout = 150;
12503
+ /**
12504
+ * Convert an `x`/`y` set in other units (e.g. `"-50%"` to centre an
12505
+ * element) to pixels, so the gesture can add to it.
12506
+ */
12507
+ const toPixels = (value, size) => {
12508
+ const latest = value.get();
12509
+ if (typeof latest === "string") {
12510
+ value.set(parseFloat(latest) * (latest.endsWith("%") ? size / 100 : 1));
12511
+ }
12512
+ };
12513
+ const limitsOf = (option) => typeof option === "object" ? option : {};
12514
+ /**
12515
+ * Resolve `elastic` to a resistance for each side, as for `dragElastic`.
12516
+ */
12517
+ const resolveElastic = (elastic = defaultElastic) => {
12518
+ const side = (value) => value === true ? defaultElastic : +(value || 0);
12519
+ return typeof elastic === "object"
12520
+ ? { min: side(elastic.min), max: side(elastic.max) }
12521
+ : { min: side(elastic), max: side(elastic) };
12522
+ };
12523
+ /**
12524
+ * Whether the gesture writes `x`/`y`: to follow the focal point, or to
12525
+ * keep an `origin` on the element in place.
12526
+ */
12527
+ const writesXY = ({ pan, origin }) => pan !== false || !!origin;
12528
+ const clampTo = (value, { min = -Infinity, max = Infinity }) => clamp(min, max, value);
12529
+ /**
12530
+ * The raw gesture value that elastic shows as `value`. A pinch that starts
12531
+ * while a value is still past its limit (like during a spring back) carries
12532
+ * on from it, rather than jumping.
12533
+ */
12534
+ const unconstrain = (value, option, resistance) => {
12535
+ const limit = clampTo(value, limitsOf(option));
12536
+ const elastic = resistance[value < limit ? "min" : "max"];
12537
+ return elastic ? limit + (value - limit) / elastic : value;
12538
+ };
12539
+ /**
12540
+ * Listen for pinch gestures on `element`: two touches (or pens), a trackpad
12541
+ * pinch (`wheel` with `ctrlKey`, as Chrome, Edge and Firefox report it),
12542
+ * and Safari's `gesture*` events.
12543
+ *
12544
+ * `getValues` is called each time a gesture starts, in the frame's read
12545
+ * step, for the scale/rotate/x/y values to write to. It runs alongside the
12546
+ * element measurement so neither forces a layout.
12547
+ *
12548
+ * `getOptions` is read whenever it's needed, so options can change while
12549
+ * listening. Return `false` to disable the gesture, which also ends one in
12550
+ * progress.
12551
+ *
12552
+ * `onPinchStart` is called once as each gesture starts, with the gesture's
12553
+ * info as a third argument. It can return the gesture's handlers, as for
12554
+ * `pinch()`.
12555
+ */
12556
+ function addPinchListeners(element, getValues, getEnabledOptions, onPinchStart) {
12557
+ const pointers = new Map();
12558
+ /**
12559
+ * The gesture as last reported: focal point, log of a distance and an
12560
+ * angle. Only changes in distance and angle matter, so trackpad and
12561
+ * Safari input write a virtual distance (the scale) here. Logs keep
12562
+ * a long trackpad pinch from overflowing.
12563
+ */
12564
+ const current = { x: 0, y: 0, l: 0, a: 0 };
12565
+ const start = { ...current };
12566
+ const prev = { ...current };
12567
+ let source;
12568
+ let lastEvent;
12569
+ let values;
12570
+ let originX = 0;
12571
+ let originY = 0;
12572
+ let width = 0;
12573
+ let height = 0;
12574
+ let lastX = 0;
12575
+ let lastY = 0;
12576
+ let hasMoved = false;
12577
+ let wheelTime = 0;
12578
+ let handlers = {};
12579
+ let unlock;
12580
+ /**
12581
+ * The gesture's scale and rotation before limits and elastic apply.
12582
+ */
12583
+ let rawScale = 1;
12584
+ let rawRotate = 0;
12585
+ let stopSnap = () => { };
12586
+ /**
12587
+ * The latest enabled options, so a gesture disabled mid-way can still
12588
+ * report its end.
12589
+ */
12590
+ let options = {};
12591
+ const getOptions = () => (options = getEnabledOptions() || options);
12592
+ const info = () => ({
12593
+ point: { x: current.x, y: current.y },
12594
+ offset: { x: current.x - start.x, y: current.y - start.y },
12595
+ scale: Math.exp(current.l - start.l),
12596
+ rotate: current.a - start.a,
12597
+ });
12598
+ /**
12599
+ * Read the element's box and values, and find its layout origin: its
12600
+ * centre without `x`/`y`. Scale and rotate are applied around the
12601
+ * centre (the default transform origin), so they don't move it.
12602
+ */
12603
+ const measure = () => {
12604
+ const box = element.getBoundingClientRect();
12605
+ const { left, top } = box;
12606
+ const { scale, rotate, elastic } = getOptions();
12607
+ const [s, r, x, y] = (values = getValues());
12608
+ const resistance = resolveElastic(elastic);
12609
+ /**
12610
+ * Stop animations on values this gesture writes, and leave the
12611
+ * rest running.
12612
+ */
12613
+ scale !== false && s.stop();
12614
+ rotate !== false && r.stop();
12615
+ rawScale = unconstrain(s.get(), scale, resistance);
12616
+ rawRotate = unconstrain(r.get(), rotate, resistance);
12617
+ width = element.offsetWidth ?? box.width;
12618
+ height = element.offsetHeight ?? box.height;
12619
+ if (writesXY(options)) {
12620
+ x.stop();
12621
+ y.stop();
12622
+ toPixels(x, width);
12623
+ toPixels(y, height);
12624
+ }
12625
+ lastX = x.get();
12626
+ lastY = y.get();
12627
+ originX = left + box.width / 2 - lastX;
12628
+ originY = top + box.height / 2 - lastY;
12629
+ };
12630
+ /**
12631
+ * The point scale and rotation pivot around, in client coordinates:
12632
+ * the focal point, or `origin` on the element at scale `s`, rotation
12633
+ * `r` and offset `x`/`y`.
12634
+ */
12635
+ const pivot = (focal, s, r, x, y) => {
12636
+ const { origin } = options;
12637
+ if (typeof origin !== "object")
12638
+ return focal;
12639
+ const a = (r * Math.PI) / 180;
12640
+ const u = (origin.x - 0.5) * width * s;
12641
+ const v = (origin.y - 0.5) * height * s;
12642
+ return {
12643
+ x: originX + x + Math.cos(a) * u - Math.sin(a) * v,
12644
+ y: originY + y + Math.sin(a) * u + Math.cos(a) * v,
12645
+ };
12646
+ };
12647
+ const dragControls = () => elementDragControls.get(visualElementStore.get(element));
12648
+ /**
12649
+ * On release, spring scale and rotation back inside their limits (or
12650
+ * to a `snap` angle), keeping the focal point in place, or everything
12651
+ * back to its origin with `snapToOrigin`.
12652
+ */
12653
+ const snap = () => {
12654
+ const { scale: scaleOption, rotate: rotateOption, snapToOrigin, transition, } = options;
12655
+ const [scale, rotate, x, y] = values;
12656
+ const s0 = scale.get();
12657
+ const r0 = rotate.get();
12658
+ const x0 = x.get();
12659
+ const y0 = y.get();
12660
+ const { snap: step } = limitsOf(rotateOption);
12661
+ let s1 = clampTo(s0, limitsOf(scaleOption));
12662
+ /**
12663
+ * Snap to the step nearest where the release velocity would carry
12664
+ * the rotation, found as inertia finds its target (with a lower power
12665
+ * than inertia's 0.8).
12666
+ */
12667
+ let r1 = clampTo(step
12668
+ ? Math.round((r0 + 0.2 * rotate.getVelocity()) / step) * step
12669
+ : r0, limitsOf(rotateOption));
12670
+ if (snapToOrigin) {
12671
+ s1 = 1;
12672
+ // The nearest upright angle, so it turns the shortest way
12673
+ r1 = Math.round(r0 / 360) * 360;
12674
+ }
12675
+ /**
12676
+ * Keep the focal point in place, unless the element doesn't move
12677
+ * with it, or a drag carries on and owns x/y.
12678
+ */
12679
+ const moves = writesXY(options) && !dragControls()?.isDragging;
12680
+ const p0 = pivot(current, s0, r0, x0, y0);
12681
+ const vx = originX + x0 - p0.x;
12682
+ const vy = originY + y0 - p0.y;
12683
+ /**
12684
+ * Scale, rotation and x/y at progress `p` of the snap, keeping the
12685
+ * focal point in place.
12686
+ */
12687
+ const at = (p) => {
12688
+ const k = mixNumber$1(s0, s1, p);
12689
+ const r = mixNumber$1(r0, r1, p);
12690
+ const angle = ((r - r0) * Math.PI) / 180;
12691
+ const cos = (Math.cos(angle) * k) / s0;
12692
+ const sin = (Math.sin(angle) * k) / s0;
12693
+ return [
12694
+ k,
12695
+ r,
12696
+ x0 + cos * vx - sin * vy - vx,
12697
+ y0 + sin * vx + cos * vy - vy,
12698
+ ];
12699
+ };
12700
+ if (!s0 ||
12701
+ (s1 === s0 && r1 === r0 && !(snapToOrigin && moves && (x0 || y0)))) {
12702
+ return;
12703
+ }
12704
+ const generator = spring({
12705
+ keyframes: [0, 1],
12706
+ stiffness: 200,
12707
+ damping: 40,
12708
+ ...transition,
12709
+ });
12710
+ const startTime = time.now();
12711
+ /**
12712
+ * Drive the values from one spring, from 0 to 1, so they stay in
12713
+ * step and the focal point stays in place.
12714
+ */
12715
+ const tick = () => {
12716
+ if (dragControls()?.isDragging)
12717
+ return stopSnap();
12718
+ const { value: p, done } = generator.next(time.now() - startTime);
12719
+ if (done)
12720
+ stopSnap();
12721
+ const [k, r, fx, fy] = at(p);
12722
+ scaleOption !== false && scale.set(k);
12723
+ rotateOption !== false && rotate.set(r);
12724
+ if (moves) {
12725
+ x.set(snapToOrigin ? mixNumber$1(x0, 0, p) : fx);
12726
+ y.set(snapToOrigin ? mixNumber$1(y0, 0, p) : fy);
12727
+ }
12728
+ };
12729
+ stopSnap = () => cancelFrame(tick);
12730
+ frame.update(tick, true);
12731
+ };
12732
+ /**
12733
+ * Apply the change in the gesture since the last frame as an
12734
+ * incremental scale and rotation around the previous focal point,
12735
+ * plus the focal point's movement.
12736
+ */
12737
+ const apply = () => {
12738
+ if (!values || !hasMoved)
12739
+ return;
12740
+ hasMoved = false;
12741
+ const { rotate: rotateOption, scale: scaleOption, pan, elastic, } = getOptions();
12742
+ const [scale, rotate, x, y] = values;
12743
+ const resistance = resolveElastic(elastic);
12744
+ const latest = scale.get();
12745
+ const drag = dragControls();
12746
+ const isDragging = drag?.isDragging;
12747
+ if (!isDragging) {
12748
+ lastX = x.get();
12749
+ lastY = y.get();
12750
+ }
12751
+ const p = pivot(prev, latest, rotate.get(), lastX, lastY);
12752
+ let theta = 0;
12753
+ let k = 1;
12754
+ /**
12755
+ * Apply limits and elastic to the gesture's raw scale and rotation.
12756
+ * At a hard limit, the raw value stops too, so moving back responds
12757
+ * straight away.
12758
+ */
12759
+ const constrain = (raw, option) => {
12760
+ const limits = limitsOf(option);
12761
+ const limit = clampTo(raw, limits);
12762
+ return resistance[raw < limit ? "min" : "max"]
12763
+ ? [applyConstraints(raw, limits, resistance), raw]
12764
+ : [limit, limit];
12765
+ };
12766
+ if (scaleOption !== false && latest) {
12767
+ const [next, raw] = constrain(clamp(1e-9, 1e9, rawScale * Math.exp(current.l - prev.l)), scaleOption);
12768
+ rawScale = raw;
12769
+ k = next / latest;
12770
+ scale.set(next);
12771
+ }
12772
+ if (rotateOption !== false) {
12773
+ const [next, raw] = constrain(rawRotate + current.a - prev.a, rotateOption);
12774
+ rawRotate = raw;
12775
+ theta = next - rotate.get();
12776
+ if (theta)
12777
+ rotate.set(next);
12778
+ }
12779
+ if (writesXY(options)) {
12780
+ /**
12781
+ * Pinch owns x/y while it runs, so stop any animation started
12782
+ * on them since (like a drag's snap back) taking over after.
12783
+ */
12784
+ x.stop();
12785
+ y.stop();
12786
+ /**
12787
+ * If drag() or the drag prop is dragging this element with one
12788
+ * of the touches, it has set x/y this frame to where it started
12789
+ * plus the touch's offset. Carry on from our own values instead,
12790
+ * and restart the drag from them and the touch's latest point.
12791
+ * That way it continues from wherever the pinch leaves the
12792
+ * element, and its release velocity only counts movement after
12793
+ * the pinch, so a zoom doesn't end in a fling.
12794
+ */
12795
+ const angle = (theta * Math.PI) / 180;
12796
+ const cos = Math.cos(angle) * k;
12797
+ const sin = Math.sin(angle) * k;
12798
+ const dx = p.x - originX - lastX;
12799
+ const dy = p.y - originY - lastY;
12800
+ const panX = pan !== false ? current.x - prev.x : 0;
12801
+ const panY = pan !== false ? current.y - prev.y : 0;
12802
+ /**
12803
+ * Move the centre so the pivot, scaled and rotated around the
12804
+ * centre, stays in place, plus the focal point's movement.
12805
+ */
12806
+ lastX += dx + panX - (cos * dx - sin * dy);
12807
+ lastY += dy + panY - (sin * dx + cos * dy);
12808
+ if (isDragging) {
12809
+ const history = drag.panSession.history;
12810
+ history.splice(0, history.length - 1);
12811
+ /**
12812
+ * Date the point long ago, so drag only measures release
12813
+ * velocity from moves after the pinch. A move that drag
12814
+ * processes as the touch lifts is part of the pinch.
12815
+ */
12816
+ history[0].timestamp = -Infinity;
12817
+ drag.originPoint.x = lastX;
12818
+ drag.originPoint.y = lastY;
12819
+ }
12820
+ x.set(lastX);
12821
+ y.set(lastY);
12822
+ }
12823
+ Object.assign(prev, current);
12824
+ handlers.onPinch?.(lastEvent, info());
12825
+ };
12826
+ /**
12827
+ * Runs after the update step, where drag sets x/y, so it has the final
12828
+ * say on them each frame.
12829
+ */
12830
+ const update = () => {
12831
+ if (!getEnabledOptions())
12832
+ return end(lastEvent);
12833
+ apply();
12834
+ if (source === "wheel" && time.now() - wheelTime > wheelTimeout) {
12835
+ end(lastEvent);
12836
+ }
12837
+ };
12838
+ const begin = (event, from) => {
12839
+ if (!getEnabledOptions())
12840
+ return;
12841
+ stopSnap();
12842
+ source = from;
12843
+ lastEvent = event;
12844
+ hasMoved = false;
12845
+ values = undefined;
12846
+ handlers = {};
12847
+ Object.assign(start, current);
12848
+ Object.assign(prev, current);
12849
+ frame.read(measure);
12850
+ frame.preRender(update, true);
12851
+ const result = onPinchStart(element, event, info());
12852
+ handlers =
12853
+ typeof result === "function" ? { onComplete: result } : result || {};
12854
+ };
12855
+ const end = (event) => {
12856
+ if (!source)
12857
+ return;
12858
+ cancelFrame(measure);
12859
+ cancelFrame(update);
12860
+ if (getEnabledOptions()) {
12861
+ apply();
12862
+ values && snap();
12863
+ }
12864
+ source = undefined;
12865
+ handlers.onComplete?.(event, info());
12866
+ };
12867
+ const moved = (event) => {
12868
+ lastEvent = event;
12869
+ hasMoved = true;
12870
+ };
12871
+ const readPointers = () => {
12872
+ const [a, b] = pointers.values();
12873
+ const angle = (Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI;
12874
+ const delta = angle - current.a;
12875
+ current.x = (a.x + b.x) / 2;
12876
+ current.y = (a.y + b.y) / 2;
12877
+ current.l = Math.log(Math.hypot(b.x - a.x, b.y - a.y) || 1);
12878
+ /**
12879
+ * Take the shortest way round, so rotation keeps counting past
12880
+ * 180deg rather than flipping to -180deg.
12881
+ */
12882
+ current.a += delta - 360 * Math.round(delta / 360);
12883
+ };
12884
+ const setPointer = (event) => pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
12885
+ const onPointerMove = (event) => {
12886
+ if (!pointers.has(event.pointerId))
12887
+ return;
12888
+ setPointer(event);
12889
+ if (source === "pointer") {
12890
+ readPointers();
12891
+ moved(event);
12892
+ }
12893
+ };
12894
+ const onPointerUp = (event) => {
12895
+ if (!pointers.delete(event.pointerId))
12896
+ return;
12897
+ if (source === "pointer")
12898
+ end(event);
12899
+ if (!pointers.size) {
12900
+ toggleWindowListeners();
12901
+ release();
12902
+ }
12903
+ };
12904
+ /**
12905
+ * Once a touch is down on the element, listen on the window too, so
12906
+ * the second touch can land beside it (for instance on a small image).
12907
+ */
12908
+ const onPointerDown = (event) => {
12909
+ if (source ||
12910
+ pointers.size > 1 ||
12911
+ pointers.has(event.pointerId) ||
12912
+ event.pointerType === "mouse") {
12913
+ return;
12914
+ }
12915
+ if (!pointers.size)
12916
+ toggleWindowListeners(true);
12917
+ setPointer(event);
12918
+ if (pointers.size === 2) {
12919
+ readPointers();
12920
+ begin(event, "pointer");
12921
+ /**
12922
+ * Unless this element drags, hold the drag lock until every
12923
+ * touch lifts. A press on it then ends as a cancel, rather than
12924
+ * a tap, and a draggable parent doesn't drag.
12925
+ */
12926
+ if (source &&
12927
+ !unlock &&
12928
+ !elementDragControls.get(visualElementStore.get(element))) {
12929
+ unlock = setDragLock(true);
12930
+ }
12931
+ }
12932
+ };
12933
+ /**
12934
+ * Release the drag lock a frame later, so a press ending on this same
12935
+ * pointerup still sees it.
12936
+ */
12937
+ const release = () => {
12938
+ const done = unlock;
12939
+ unlock = undefined;
12940
+ done && frame.postRender(done);
12941
+ };
12942
+ const toggleWindowListeners = (add) => {
12943
+ const method = add ? "addEventListener" : "removeEventListener";
12944
+ window[method]("pointerdown", onPointerDown);
12945
+ window[method]("pointermove", onPointerMove);
12946
+ window[method]("pointerup", onPointerUp);
12947
+ window[method]("pointercancel", onPointerUp);
12948
+ };
12949
+ const onWheel = (event) => {
12950
+ if (!event.ctrlKey || (source && source !== "wheel"))
12951
+ return;
12952
+ current.x = event.clientX;
12953
+ current.y = event.clientY;
12954
+ if (!source) {
12955
+ current.l = 0;
12956
+ begin(event, "wheel");
12957
+ if (!source)
12958
+ return;
12959
+ }
12960
+ event.preventDefault();
12961
+ /**
12962
+ * Lines (Firefox's mouse wheel) to pixels, and cap each event so a
12963
+ * mouse wheel notch with ctrl held (about 100px) zooms a step.
12964
+ */
12965
+ current.l -=
12966
+ clamp(-50, 50, event.deltaY * (event.deltaMode ? 16 : 1)) / 100;
12967
+ wheelTime = time.now();
12968
+ moved(event);
12969
+ };
12970
+ /**
12971
+ * Safari reports trackpad pinches as `gesture*` events. iOS Safari
12972
+ * fires them for touches too, alongside the pointer events we track.
12973
+ */
12974
+ const onGesture = (event) => {
12975
+ if (!pointers.size && (!source || source === "gesture")) {
12976
+ const { scale, rotation, clientX, clientY } = event;
12977
+ current.x = clientX;
12978
+ current.y = clientY;
12979
+ current.l = Math.log(scale);
12980
+ current.a = rotation;
12981
+ if (source) {
12982
+ moved(event);
12983
+ if (event.type === "gestureend")
12984
+ end(event);
12985
+ }
12986
+ else if (event.type === "gesturestart") {
12987
+ begin(event, "gesture");
12988
+ }
12989
+ }
12990
+ if (source)
12991
+ event.preventDefault();
12992
+ };
12993
+ const listeners = {
12994
+ pointerdown: onPointerDown,
12995
+ wheel: onWheel,
12996
+ gesturestart: onGesture,
12997
+ gesturechange: onGesture,
12998
+ gestureend: onGesture,
12999
+ };
13000
+ for (const name in listeners) {
13001
+ element.addEventListener(name, listeners[name], { passive: false });
13002
+ }
13003
+ return () => {
13004
+ for (const name in listeners) {
13005
+ element.removeEventListener(name, listeners[name]);
13006
+ }
13007
+ toggleWindowListeners();
13008
+ end(lastEvent);
13009
+ stopSnap();
13010
+ pointers.clear();
13011
+ release();
13012
+ };
13013
+ }
13014
+ const valueKeys = ["scale", "rotate", "x", "y"];
13015
+ /**
13016
+ * The element's scale/rotate/x/y motion values: those of its
13017
+ * VisualElement if it has one (it's a <motion.*> component, or drag() or
13018
+ * animateLayout() own it), otherwise those animate() binds to it, created
13019
+ * from its current style if this is the first time.
13020
+ */
13021
+ const getElementValues = (element) => {
13022
+ const visualElement = visualElementStore.get(element);
13023
+ const effect = isSVGElement(element) ? svgSubjectEffect : styleSubjectEffect;
13024
+ return valueKeys.map((key) => {
13025
+ if (visualElement) {
13026
+ return visualElement.getValue(key, key === "scale" ? 1 : 0);
13027
+ }
13028
+ let value = effect.get(element, key);
13029
+ if (!value) {
13030
+ value = motionValue(readStyleValue(element, key));
13031
+ effect(element, { [key]: value });
13032
+ }
13033
+ return value;
13034
+ });
13035
+ };
13036
+ function pinch(elementOrSelector, startOrOptions, options = {}) {
13037
+ let onPinchStart = () => { };
13038
+ if (typeof startOrOptions === "function") {
13039
+ onPinchStart = startOrOptions;
13040
+ }
13041
+ else if (startOrOptions) {
13042
+ options = startOrOptions;
13043
+ }
13044
+ const scope = activeScope.current;
13045
+ /**
13046
+ * Run the start callback and the handlers it returns in the active
13047
+ * scope, so work they start is collected. A returned function is
13048
+ * bound by `scope.bind` itself.
13049
+ */
13050
+ if (scope) {
13051
+ const start = scope.bind(onPinchStart);
13052
+ onPinchStart = (element, event) => {
13053
+ const result = start(element, event);
13054
+ if (typeof result !== "object")
13055
+ return result;
13056
+ const handlers = {};
13057
+ for (const key in result) {
13058
+ const name = key;
13059
+ const handler = result[name];
13060
+ handlers[name] = handler && scope.bind(handler);
13061
+ }
13062
+ return handlers;
13063
+ };
13064
+ }
13065
+ const cleanups = resolveElements(elementOrSelector).map((element) => {
13066
+ scope?.track(element);
13067
+ const { style } = element;
13068
+ const touchAction = style.touchAction;
13069
+ style.touchAction = "none";
13070
+ const remove = addPinchListeners(element, () => getElementValues(element), () => options, onPinchStart);
13071
+ return () => {
13072
+ remove();
13073
+ style.touchAction = touchAction;
13074
+ };
13075
+ });
13076
+ return addToScope(() => cleanups.forEach((cleanup) => cleanup()));
13077
+ }
13078
+
12493
13079
  /**
12494
13080
  * Recursively traverse up the tree to check whether the provided child node
12495
13081
  * is the parent or a descendant of it.
@@ -12705,14 +13291,18 @@
12705
13291
  */
12706
13292
  const endEventOptions = { ...eventOptions, capture: true };
12707
13293
  const onPointerEnd = (endEvent, success) => {
13294
+ /**
13295
+ * Another touch lifting (for instance after a pinch) doesn't
13296
+ * end the press.
13297
+ */
13298
+ if (!isPrimaryPointer(endEvent))
13299
+ return;
12708
13300
  window.removeEventListener("pointerup", onPointerUp, endEventOptions);
12709
13301
  window.removeEventListener("pointercancel", onPointerCancel, endEventOptions);
12710
13302
  window.removeEventListener("pointermove", onPointerMove, endEventOptions);
12711
13303
  target.removeEventListener("contextmenu", preventDefault);
12712
13304
  cancelFrame(tick);
12713
13305
  isPressing.delete(target);
12714
- if (!isPrimaryPointer(endEvent))
12715
- return;
12716
13306
  /**
12717
13307
  * A press that ends while a drag is active is a cancel.
12718
13308
  */
@@ -17217,6 +17807,7 @@
17217
17807
  exports.addBuilderToScope = addBuilderToScope;
17218
17808
  exports.addDomEvent = addDomEvent;
17219
17809
  exports.addEffect = addEffect;
17810
+ exports.addPinchListeners = addPinchListeners;
17220
17811
  exports.addPointerEvent = addPointerEvent;
17221
17812
  exports.addPointerInfo = addPointerInfo;
17222
17813
  exports.addSVGValue = addSVGValue;
@@ -17442,6 +18033,7 @@
17442
18033
  exports.parseCSSVariable = parseCSSVariable;
17443
18034
  exports.parseValueFromTransform = parseValueFromTransform;
17444
18035
  exports.percent = percent;
18036
+ exports.pinch = pinch;
17445
18037
  exports.pipe = pipe;
17446
18038
  exports.pixelsToPercent = pixelsToPercent;
17447
18039
  exports.positionalKeys = positionalKeys;