@tamagui/animations-motion 2.6.1 → 2.6.2

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.
@@ -58,6 +58,23 @@ function settlePendingMotionOnFinish(mv, controls) {
58
58
  PendingMotionOnFinish.delete(mv);
59
59
  controls.then(() => onFinish()).catch(() => onFinish());
60
60
  }
61
+ const PopperPositionAnims = /* @__PURE__ */new WeakMap();
62
+ function parseTranslate(transform) {
63
+ if (!transform || transform === "none") return {
64
+ x: 0,
65
+ y: 0
66
+ };
67
+ try {
68
+ const m = new DOMMatrixReadOnly(transform);
69
+ if (!m.is2D || m.a !== 1 || m.b !== 0 || m.c !== 0 || m.d !== 1) return null;
70
+ return {
71
+ x: m.e,
72
+ y: m.f
73
+ };
74
+ } catch {
75
+ return null;
76
+ }
77
+ }
61
78
  function createAnimations(animations) {
62
79
  let isHydratingGlobal;
63
80
  const hydratingComponents = /* @__PURE__ */new Set();
@@ -236,6 +253,65 @@ function createAnimations(animations) {
236
253
  };
237
254
  }
238
255
  const isPopperPosition = node.hasAttribute("data-popper-animate-position");
256
+ let popperHandledTransform = false;
257
+ if (isPopperPosition && !isCurrentlyExiting && typeof diff.transform === "string") {
258
+ const target = parseTranslate(diff.transform);
259
+ if (target) {
260
+ let entry = PopperPositionAnims.get(node);
261
+ if (!entry) {
262
+ let seed = target;
263
+ try {
264
+ seed = parseTranslate(getComputedStyle(node).transform) ?? target;
265
+ } catch {}
266
+ const x = (0, import_react.motionValue)(seed.x);
267
+ const y = (0, import_react.motionValue)(seed.y);
268
+ const write = () => {
269
+ node.style.transform = `translate3d(${x.get()}px, ${y.get()}px, 0)`;
270
+ };
271
+ x.on("change", write);
272
+ y.on("change", write);
273
+ entry = {
274
+ x,
275
+ y,
276
+ stop: null
277
+ };
278
+ PopperPositionAnims.set(node, entry);
279
+ }
280
+ if (!entry.stop) {
281
+ try {
282
+ const live = parseTranslate(getComputedStyle(node).transform);
283
+ if (live) {
284
+ entry.x.jump(live.x);
285
+ entry.y.jump(live.y);
286
+ }
287
+ } catch {}
288
+ }
289
+ for (const anim of node.getAnimations()) {
290
+ try {
291
+ const kf = anim.effect?.getKeyframes?.();
292
+ if (kf?.some(k => "transform" in k)) {
293
+ anim.cancel();
294
+ }
295
+ } catch {}
296
+ }
297
+ const opts = animationOptions2;
298
+ const positionTransition = opts.transform ?? opts.default ?? animationOptions2;
299
+ const cx = (0, import_react.animate)(entry.x, target.x, positionTransition);
300
+ const cy = (0, import_react.animate)(entry.y, target.y, positionTransition);
301
+ entry.stop = () => {
302
+ cx.stop();
303
+ cy.stop();
304
+ };
305
+ popperHandledTransform = true;
306
+ }
307
+ }
308
+ if (isCurrentlyExiting) {
309
+ const entry = PopperPositionAnims.get(node);
310
+ if (entry?.stop) {
311
+ entry.stop();
312
+ entry.stop = null;
313
+ }
314
+ }
239
315
  let midFlightValues = null;
240
316
  if (refs.current.controls) {
241
317
  try {
@@ -253,11 +329,11 @@ function createAnimations(animations) {
253
329
  }
254
330
  if (midFlightValues) {
255
331
  for (const key in midFlightValues) {
256
- ;
332
+ if (key === "transform" && popperHandledTransform) continue;
257
333
  node.style[key] = midFlightValues[key];
258
334
  }
259
335
  }
260
- if (isPopperPosition) {
336
+ if (isPopperPosition && !popperHandledTransform) {
261
337
  const anims = node.getAnimations();
262
338
  for (const anim of anims) {
263
339
  anim.cancel();
@@ -265,11 +341,20 @@ function createAnimations(animations) {
265
341
  }
266
342
  }
267
343
  const fixedDiff = fixTransparentColors(diff, refs.current.lastDoAnimate, doAnimate2);
268
- if ((isPopperPosition || isCurrentlyExiting) && midFlightValues?.transform && fixedDiff.transform) {
269
- fixedDiff.transform = [midFlightValues.transform, fixedDiff.transform];
344
+ let waapiDiff = fixedDiff;
345
+ if (popperHandledTransform && "transform" in waapiDiff) {
346
+ waapiDiff = {
347
+ ...waapiDiff
348
+ };
349
+ delete waapiDiff.transform;
350
+ }
351
+ if ((isPopperPosition || isCurrentlyExiting) && midFlightValues?.transform && waapiDiff.transform) {
352
+ waapiDiff.transform = [midFlightValues.transform, waapiDiff.transform];
353
+ }
354
+ if (Object.keys(waapiDiff).length > 0) {
355
+ startedControls = animate(scope.current, waapiDiff, animationOptions2);
356
+ refs.current.controls = startedControls;
270
357
  }
271
- startedControls = animate(scope.current, fixedDiff, animationOptions2);
272
- refs.current.controls = startedControls;
273
358
  refs.current.lastAnimateAt = Date.now();
274
359
  }
275
360
  }
@@ -339,6 +424,16 @@ function createAnimations(animations) {
339
424
  if (node instanceof HTMLElement) {
340
425
  if (dontAnimate) Object.assign(node.style, dontAnimate);
341
426
  if (doAnimate) Object.assign(node.style, doAnimate);
427
+ const entry = PopperPositionAnims.get(node);
428
+ if (entry) {
429
+ const target = parseTranslate(doAnimate?.transform ?? dontAnimate?.transform);
430
+ if (target) {
431
+ entry.stop?.();
432
+ entry.stop = null;
433
+ entry.x.jump(target.x);
434
+ entry.y.jump(target.y);
435
+ }
436
+ }
342
437
  }
343
438
  refs.current.lastDontAnimate = dontAnimate ? {
344
439
  ...dontAnimate
@@ -377,40 +472,40 @@ function createAnimations(animations) {
377
472
  };
378
473
  },
379
474
  useAnimatedNumber(initial) {
380
- const motionValue = (0, import_react.useMotionValue)(initial);
475
+ const motionValue2 = (0, import_react.useMotionValue)(initial);
381
476
  return import_react2.default.useMemo(() => ({
382
477
  getInstance() {
383
- return motionValue;
478
+ return motionValue2;
384
479
  },
385
480
  getValue() {
386
- return motionValue.get();
481
+ return motionValue2.get();
387
482
  },
388
483
  setValue(next, config = {
389
484
  type: "spring"
390
485
  }, onFinish) {
391
486
  if (config.type === "direct") {
392
- MotionValueStrategy.set(motionValue, {
487
+ MotionValueStrategy.set(motionValue2, {
393
488
  type: "direct"
394
489
  });
395
- motionValue.set(next);
490
+ motionValue2.set(next);
396
491
  onFinish?.();
397
492
  return;
398
493
  }
399
- MotionValueStrategy.set(motionValue, config);
494
+ MotionValueStrategy.set(motionValue2, config);
400
495
  if (onFinish) {
401
- const prior = PendingMotionOnFinish.get(motionValue);
496
+ const prior = PendingMotionOnFinish.get(motionValue2);
402
497
  if (prior) {
403
- PendingMotionOnFinish.delete(motionValue);
498
+ PendingMotionOnFinish.delete(motionValue2);
404
499
  prior();
405
500
  }
406
- PendingMotionOnFinish.set(motionValue, onFinish);
501
+ PendingMotionOnFinish.set(motionValue2, onFinish);
407
502
  }
408
- motionValue.set(next);
503
+ motionValue2.set(next);
409
504
  },
410
505
  stop() {
411
- motionValue.stop();
506
+ motionValue2.stop();
412
507
  }
413
- }), [motionValue]);
508
+ }), [motionValue2]);
414
509
  },
415
510
  useAnimatedNumberReaction({
416
511
  value
@@ -419,7 +514,7 @@ function createAnimations(animations) {
419
514
  (0, import_react.useMotionValueEvent)(instance, "change", onValue);
420
515
  },
421
516
  useAnimatedNumberStyle(val, getStyleProp) {
422
- const motionValue = val.getInstance();
517
+ const motionValue2 = val.getInstance();
423
518
  const getStyleRef = (0, import_react2.useRef)(getStyleProp);
424
519
  getStyleRef.current = getStyleProp;
425
520
  return (0, import_react2.useMemo)(() => {
@@ -427,7 +522,7 @@ function createAnimations(animations) {
427
522
  getStyle: cur => {
428
523
  return getStyleRef.current(cur);
429
524
  },
430
- motionValue
525
+ motionValue: motionValue2
431
526
  };
432
527
  }, []);
433
528
  },
@@ -76,6 +76,23 @@ function settlePendingMotionOnFinish(mv, controls) {
76
76
  return onFinish();
77
77
  });
78
78
  }
79
+ var PopperPositionAnims = /* @__PURE__ */new WeakMap();
80
+ function parseTranslate(transform) {
81
+ if (!transform || transform === "none") return {
82
+ x: 0,
83
+ y: 0
84
+ };
85
+ try {
86
+ var m = new DOMMatrixReadOnly(transform);
87
+ if (!m.is2D || m.a !== 1 || m.b !== 0 || m.c !== 0 || m.d !== 1) return null;
88
+ return {
89
+ x: m.e,
90
+ y: m.f
91
+ };
92
+ } catch (e) {
93
+ return null;
94
+ }
95
+ }
79
96
  function createAnimations(animations) {
80
97
  var isHydratingGlobal;
81
98
  var hydratingComponents = /* @__PURE__ */new Set();
@@ -258,6 +275,89 @@ function createAnimations(animations) {
258
275
  };
259
276
  }
260
277
  var isPopperPosition = node.hasAttribute("data-popper-animate-position");
278
+ var popperHandledTransform = false;
279
+ if (isPopperPosition && !isCurrentlyExiting && typeof diff.transform === "string") {
280
+ var target = parseTranslate(diff.transform);
281
+ if (target) {
282
+ var entry = PopperPositionAnims.get(node);
283
+ if (!entry) {
284
+ var seed = target;
285
+ try {
286
+ var _parseTranslate;
287
+ seed = (_parseTranslate = parseTranslate(getComputedStyle(node).transform)) !== null && _parseTranslate !== void 0 ? _parseTranslate : target;
288
+ } catch (e) {}
289
+ var x = (0, import_react.motionValue)(seed.x);
290
+ var y = (0, import_react.motionValue)(seed.y);
291
+ var write = function () {
292
+ node.style.transform = `translate3d(${x.get()}px, ${y.get()}px, 0)`;
293
+ };
294
+ x.on("change", write);
295
+ y.on("change", write);
296
+ entry = {
297
+ x,
298
+ y,
299
+ stop: null
300
+ };
301
+ PopperPositionAnims.set(node, entry);
302
+ }
303
+ if (!entry.stop) {
304
+ try {
305
+ var live = parseTranslate(getComputedStyle(node).transform);
306
+ if (live) {
307
+ entry.x.jump(live.x);
308
+ entry.y.jump(live.y);
309
+ }
310
+ } catch (e) {}
311
+ }
312
+ var _iteratorNormalCompletion = true,
313
+ _didIteratorError = false,
314
+ _iteratorError = void 0;
315
+ try {
316
+ for (var _iterator = node.getAnimations()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
317
+ var anim = _step.value;
318
+ try {
319
+ var _anim_effect_getKeyframes, _anim_effect;
320
+ var kf = (_anim_effect = anim.effect) === null || _anim_effect === void 0 ? void 0 : (_anim_effect_getKeyframes = _anim_effect.getKeyframes) === null || _anim_effect_getKeyframes === void 0 ? void 0 : _anim_effect_getKeyframes.call(_anim_effect);
321
+ if (kf === null || kf === void 0 ? void 0 : kf.some(function (k) {
322
+ return "transform" in k;
323
+ })) {
324
+ anim.cancel();
325
+ }
326
+ } catch (e) {}
327
+ }
328
+ } catch (err) {
329
+ _didIteratorError = true;
330
+ _iteratorError = err;
331
+ } finally {
332
+ try {
333
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
334
+ _iterator.return();
335
+ }
336
+ } finally {
337
+ if (_didIteratorError) {
338
+ throw _iteratorError;
339
+ }
340
+ }
341
+ }
342
+ var opts = animationOptions2;
343
+ var _opts_transform, _ref;
344
+ var positionTransition = (_ref = (_opts_transform = opts.transform) !== null && _opts_transform !== void 0 ? _opts_transform : opts.default) !== null && _ref !== void 0 ? _ref : animationOptions2;
345
+ var cx = (0, import_react.animate)(entry.x, target.x, positionTransition);
346
+ var cy = (0, import_react.animate)(entry.y, target.y, positionTransition);
347
+ entry.stop = function () {
348
+ cx.stop();
349
+ cy.stop();
350
+ };
351
+ popperHandledTransform = true;
352
+ }
353
+ }
354
+ if (isCurrentlyExiting) {
355
+ var entry1 = PopperPositionAnims.get(node);
356
+ if (entry1 === null || entry1 === void 0 ? void 0 : entry1.stop) {
357
+ entry1.stop();
358
+ entry1.stop = null;
359
+ }
360
+ }
261
361
  var midFlightValues = null;
262
362
  if (refs.current.controls) {
263
363
  try {
@@ -275,42 +375,51 @@ function createAnimations(animations) {
275
375
  }
276
376
  if (midFlightValues) {
277
377
  for (var key2 in midFlightValues) {
278
- ;
378
+ if (key2 === "transform" && popperHandledTransform) continue;
279
379
  node.style[key2] = midFlightValues[key2];
280
380
  }
281
381
  }
282
- if (isPopperPosition) {
382
+ if (isPopperPosition && !popperHandledTransform) {
283
383
  var anims = node.getAnimations();
284
- var _iteratorNormalCompletion = true,
285
- _didIteratorError = false,
286
- _iteratorError = void 0;
384
+ var _iteratorNormalCompletion1 = true,
385
+ _didIteratorError1 = false,
386
+ _iteratorError1 = void 0;
287
387
  try {
288
- for (var _iterator = anims[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
289
- var anim = _step.value;
290
- anim.cancel();
388
+ for (var _iterator1 = anims[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
389
+ var anim1 = _step1.value;
390
+ anim1.cancel();
291
391
  }
292
392
  } catch (err) {
293
- _didIteratorError = true;
294
- _iteratorError = err;
393
+ _didIteratorError1 = true;
394
+ _iteratorError1 = err;
295
395
  } finally {
296
396
  try {
297
- if (!_iteratorNormalCompletion && _iterator.return != null) {
298
- _iterator.return();
397
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
398
+ _iterator1.return();
299
399
  }
300
400
  } finally {
301
- if (_didIteratorError) {
302
- throw _iteratorError;
401
+ if (_didIteratorError1) {
402
+ throw _iteratorError1;
303
403
  }
304
404
  }
305
405
  }
306
406
  }
307
407
  }
308
408
  var fixedDiff = fixTransparentColors(diff, refs.current.lastDoAnimate, doAnimate2);
309
- if ((isPopperPosition || isCurrentlyExiting) && (midFlightValues === null || midFlightValues === void 0 ? void 0 : midFlightValues.transform) && fixedDiff.transform) {
310
- fixedDiff.transform = [midFlightValues.transform, fixedDiff.transform];
409
+ var waapiDiff = fixedDiff;
410
+ if (popperHandledTransform && "transform" in waapiDiff) {
411
+ waapiDiff = {
412
+ ...waapiDiff
413
+ };
414
+ delete waapiDiff.transform;
415
+ }
416
+ if ((isPopperPosition || isCurrentlyExiting) && (midFlightValues === null || midFlightValues === void 0 ? void 0 : midFlightValues.transform) && waapiDiff.transform) {
417
+ waapiDiff.transform = [midFlightValues.transform, waapiDiff.transform];
418
+ }
419
+ if (Object.keys(waapiDiff).length > 0) {
420
+ startedControls = animate(scope.current, waapiDiff, animationOptions2);
421
+ refs.current.controls = startedControls;
311
422
  }
312
- startedControls = animate(scope.current, fixedDiff, animationOptions2);
313
- refs.current.controls = startedControls;
314
423
  refs.current.lastAnimateAt = Date.now();
315
424
  }
316
425
  }
@@ -380,6 +489,18 @@ function createAnimations(animations) {
380
489
  if (_instanceof(node, HTMLElement)) {
381
490
  if (dontAnimate) Object.assign(node.style, dontAnimate);
382
491
  if (doAnimate) Object.assign(node.style, doAnimate);
492
+ var entry = PopperPositionAnims.get(node);
493
+ if (entry) {
494
+ var _doAnimate_transform;
495
+ var target = parseTranslate((_doAnimate_transform = doAnimate === null || doAnimate === void 0 ? void 0 : doAnimate.transform) !== null && _doAnimate_transform !== void 0 ? _doAnimate_transform : dontAnimate === null || dontAnimate === void 0 ? void 0 : dontAnimate.transform);
496
+ if (target) {
497
+ var _entry_stop;
498
+ (_entry_stop = entry.stop) === null || _entry_stop === void 0 ? void 0 : _entry_stop.call(entry);
499
+ entry.stop = null;
500
+ entry.x.jump(target.x);
501
+ entry.y.jump(target.y);
502
+ }
503
+ }
383
504
  }
384
505
  refs.current.lastDontAnimate = dontAnimate ? {
385
506
  ...dontAnimate
@@ -418,14 +539,14 @@ function createAnimations(animations) {
418
539
  };
419
540
  },
420
541
  useAnimatedNumber(initial) {
421
- var motionValue = (0, import_react.useMotionValue)(initial);
542
+ var motionValue2 = (0, import_react.useMotionValue)(initial);
422
543
  return import_react2.default.useMemo(function () {
423
544
  return {
424
545
  getInstance() {
425
- return motionValue;
546
+ return motionValue2;
426
547
  },
427
548
  getValue() {
428
- return motionValue.get();
549
+ return motionValue2.get();
429
550
  },
430
551
  setValue(next) {
431
552
  var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
@@ -433,29 +554,29 @@ function createAnimations(animations) {
433
554
  },
434
555
  onFinish = arguments.length > 2 ? arguments[2] : void 0;
435
556
  if (config.type === "direct") {
436
- MotionValueStrategy.set(motionValue, {
557
+ MotionValueStrategy.set(motionValue2, {
437
558
  type: "direct"
438
559
  });
439
- motionValue.set(next);
560
+ motionValue2.set(next);
440
561
  onFinish === null || onFinish === void 0 ? void 0 : onFinish();
441
562
  return;
442
563
  }
443
- MotionValueStrategy.set(motionValue, config);
564
+ MotionValueStrategy.set(motionValue2, config);
444
565
  if (onFinish) {
445
- var prior = PendingMotionOnFinish.get(motionValue);
566
+ var prior = PendingMotionOnFinish.get(motionValue2);
446
567
  if (prior) {
447
- PendingMotionOnFinish.delete(motionValue);
568
+ PendingMotionOnFinish.delete(motionValue2);
448
569
  prior();
449
570
  }
450
- PendingMotionOnFinish.set(motionValue, onFinish);
571
+ PendingMotionOnFinish.set(motionValue2, onFinish);
451
572
  }
452
- motionValue.set(next);
573
+ motionValue2.set(next);
453
574
  },
454
575
  stop() {
455
- motionValue.stop();
576
+ motionValue2.stop();
456
577
  }
457
578
  };
458
- }, [motionValue]);
579
+ }, [motionValue2]);
459
580
  },
460
581
  useAnimatedNumberReaction(param, onValue) {
461
582
  var {
@@ -465,7 +586,7 @@ function createAnimations(animations) {
465
586
  (0, import_react.useMotionValueEvent)(instance, "change", onValue);
466
587
  },
467
588
  useAnimatedNumberStyle(val, getStyleProp) {
468
- var motionValue = val.getInstance();
589
+ var motionValue2 = val.getInstance();
469
590
  var getStyleRef = (0, import_react2.useRef)(getStyleProp);
470
591
  getStyleRef.current = getStyleProp;
471
592
  return (0, import_react2.useMemo)(function () {
@@ -473,7 +594,7 @@ function createAnimations(animations) {
473
594
  getStyle: function (cur) {
474
595
  return getStyleRef.current(cur);
475
596
  },
476
- motionValue
597
+ motionValue: motionValue2
477
598
  };
478
599
  }, []);
479
600
  },