@tamagui/animations-motion 2.7.7 → 3.0.0-beta.1093.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.
@@ -1,954 +1,1085 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { getEffectiveAnimation, normalizeTransition } from "@tamagui/animation-helpers";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { easingToBezier, forAnimationState, getTransitionForKey, hasTransition, resolveTransition, styleKeysForProperty } from "@tamagui/animation-helpers";
3
3
  import { ResetPresence, usePresence } from "@tamagui/use-presence";
4
- import { fixStyles, getConfig, getSplitStyles, hooks, styleToCSS, Text, useComposedRefs, useIsomorphicLayoutEffect, useThemeWithState, View } from "@tamagui/web";
5
- import { animate as animateMotionValue, motionValue, useAnimate, useMotionValue, useMotionValueEvent } from "motion/react";
6
- import React, { forwardRef, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
7
- function _instanceof(left, right) {
8
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
9
- return !!right[Symbol.hasInstance](left);
10
- } else {
11
- return left instanceof right;
12
- }
13
- }
14
- function _type_of(obj) {
15
- "@swc/helpers - typeof";
4
+ import { Text, View, createRefComponent, getConfig, getSplitStyles, hooks, nonAnimatableStyleProps, useComposedRefs, useIsomorphicLayoutEffect } from "@tamagui/web";
5
+ import { fixStyles, normalizeValueWithProperty, styleToCSS, transformsToString, useThemeWithState } from "@tamagui/web/internal-runtime";
6
+ import { animate, motionValue, useAnimate, useMotionValue, useMotionValueEvent } from "motion/react";
7
+ import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
16
8
 
17
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
18
- }
19
9
  var isServer = typeof window === "undefined";
20
10
  function useAnimateSSRSafe() {
21
- if (isServer) {
22
- return [useRef(null), function () {}];
23
- }
24
- return useAnimate();
11
+ if (isServer) {
12
+ return [useRef(null), function() {}];
13
+ }
14
+ return useAnimate();
25
15
  }
26
- var MotionValueStrategy = /* @__PURE__ */new WeakMap();
27
- var PendingMotionOnFinish = /* @__PURE__ */new WeakMap();
16
+ var asStyleRecord = function(style) {
17
+ return style && typeof style === "object" && !Array.isArray(style) ? style : {};
18
+ };
19
+ function assignInlineStyles(node, styles) {
20
+ for (var key in styles) {
21
+ node.style[key] = normalizeValueWithProperty(styles[key], key);
22
+ }
23
+ }
24
+ var MotionValueStrategy = /* @__PURE__ */ new WeakMap();
25
+ var PendingMotionOnFinish = /* @__PURE__ */ new WeakMap();
28
26
  function settlePendingMotionOnFinish(mv, controls) {
29
- var onFinish = PendingMotionOnFinish.get(mv);
30
- if (!onFinish) return;
31
- PendingMotionOnFinish.delete(mv);
32
- controls.then(function () {
33
- return onFinish();
34
- }).catch(function () {
35
- return onFinish();
36
- });
27
+ var onFinish = PendingMotionOnFinish.get(mv);
28
+ if (!onFinish) return;
29
+ PendingMotionOnFinish.delete(mv);
30
+ controls.then(function() {
31
+ return onFinish();
32
+ }).catch(function() {
33
+ return onFinish();
34
+ });
37
35
  }
38
- var PopperPositionAnims = /* @__PURE__ */new WeakMap();
36
+ var PopperPositionAnims = /* @__PURE__ */ new WeakMap();
39
37
  function parseTranslate(transform) {
40
- if (!transform || transform === "none") return {
41
- x: 0,
42
- y: 0
43
- };
44
- try {
45
- var m = new DOMMatrixReadOnly(transform);
46
- if (!m.is2D || m.a !== 1 || m.b !== 0 || m.c !== 0 || m.d !== 1) return null;
47
- return {
48
- x: m.e,
49
- y: m.f
50
- };
51
- } catch (e) {
52
- return null;
53
- }
38
+ if (!transform || transform === "none") return {
39
+ x: 0,
40
+ y: 0
41
+ };
42
+ try {
43
+ var m = new DOMMatrixReadOnly(transform);
44
+ if (!m.is2D || m.a !== 1 || m.b !== 0 || m.c !== 0 || m.d !== 1) return null;
45
+ return {
46
+ x: m.e,
47
+ y: m.f
48
+ };
49
+ } catch (e) {
50
+ return null;
51
+ }
54
52
  }
55
53
  function createAnimations(animations) {
56
- var isHydratingGlobal;
57
- var hydratingComponents = /* @__PURE__ */new Set();
58
- return {
59
- View: MotionView,
60
- Text: MotionText,
61
- isReactNative: false,
62
- inputStyle: "css",
63
- outputStyle: "inline",
64
- avoidReRenders: true,
65
- animations,
66
- usePresence,
67
- ResetPresence,
68
- onMount() {
69
- isHydratingGlobal = false;
70
- hydratingComponents.forEach(function (cb) {
71
- return cb();
72
- });
73
- },
74
- useAnimations: function (animationProps) {
75
- if (isHydratingGlobal === void 0 && !getConfig().settings.disableSSR) {
76
- isHydratingGlobal = true;
77
- }
78
- var {
79
- props,
80
- style,
81
- componentState,
82
- stateRef,
83
- useStyleEmitter,
84
- presence,
85
- styleProps
86
- } = animationProps;
87
- var animationKey = Array.isArray(props.transition) ? props.transition[0] : props.transition;
88
- var isComponentHydrating = componentState.unmounted === true;
89
- var isMounting = componentState.unmounted === "should-enter";
90
- var isEntering = !!componentState.unmounted;
91
- var isExiting = (presence === null || presence === void 0 ? void 0 : presence[0]) === false;
92
- var sendExitComplete = presence === null || presence === void 0 ? void 0 : presence[1];
93
- var refs = useRef(null);
94
- if (!refs.current) {
95
- refs.current = {
96
- isFirstRender: true,
97
- lastDoAnimate: null,
98
- lastDontAnimate: null,
99
- controls: null,
100
- lastAnimateAt: 0,
101
- disposed: false,
102
- wasExiting: false,
103
- isExiting: false,
104
- sendExitComplete: void 0,
105
- animationState: "default",
106
- frozenExitTarget: null,
107
- exitCompleteScheduled: false,
108
- wasEntering: false,
109
- wasDisabled: false,
110
- wasNoClass: !!styleProps.noClass
111
- };
112
- }
113
- var justFinishedEntering = refs.current.wasEntering && !isEntering;
114
- useEffect(function () {
115
- refs.current.wasEntering = isEntering;
116
- });
117
- var animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default";
118
- var disableAnimation = isComponentHydrating || isMounting || !animationKey;
119
- var [scope, animate] = useAnimateSSRSafe();
120
- refs.current.isExiting = isExiting;
121
- refs.current.sendExitComplete = sendExitComplete;
122
- refs.current.animationState = animationState;
123
- var justStartedExiting = isExiting && !refs.current.wasExiting;
124
- var justStoppedExiting = !isExiting && refs.current.wasExiting;
125
- if (justStartedExiting || justStoppedExiting) {
126
- refs.current.frozenExitTarget = null;
127
- refs.current.exitCompleteScheduled = false;
128
- }
129
- useEffect(function () {
130
- refs.current.wasExiting = isExiting;
131
- });
132
- var {
133
- dontAnimate = {},
134
- doAnimate,
135
- animationOptions
136
- } = getMotionAnimatedProps(props, style, disableAnimation, animationState);
137
- var [firstRenderStyle] = useState(style);
138
- if (refs.current.isFirstRender) {
139
- refs.current.lastDontAnimate = firstRenderStyle;
140
- }
141
- var [isHydrating, setIsHydrating] = useState(isHydratingGlobal);
142
- useLayoutEffect(function () {
143
- if (isHydratingGlobal) {
144
- hydratingComponents.add(function () {
145
- setIsHydrating(false);
146
- });
147
- }
148
- return function () {
149
- refs.current.disposed = true;
150
- };
151
- }, []);
152
- var flushAnimation = function (param) {
153
- var {
154
- doAnimate: doAnimateRaw = {},
155
- animationOptions: passedOptions = {},
156
- dontAnimate: dontAnimate2
157
- } = param;
158
- var startedControls = null;
159
- var isCurrentlyExiting = refs.current.isExiting;
160
- var currentSendExitComplete = refs.current.sendExitComplete;
161
- var doAnimate2 = doAnimateRaw;
162
- if (isCurrentlyExiting && refs.current.frozenExitTarget) {
163
- doAnimate2 = refs.current.frozenExitTarget;
164
- }
165
- var _props_transition;
166
- var animationOptions2 = isCurrentlyExiting && currentSendExitComplete ? getAnimationOptions((_props_transition = props.transition) !== null && _props_transition !== void 0 ? _props_transition : null, "exit") : passedOptions;
167
- try {
168
- var node = stateRef.current.host;
169
- if (refs.current.isFirstRender) {
170
- refs.current.lastDontAnimate = null;
171
- refs.current.lastDoAnimate = null;
172
- }
173
- if (process.env.NODE_ENV === "development") {
174
- if (props["debug"] && props["debug"] !== "profile") {
175
- console.groupCollapsed(`[motion] animate (${JSON.stringify(getDiff(refs.current.lastDoAnimate, doAnimate2), null, 2)})`);
176
- console.info({
177
- props,
178
- componentState,
179
- doAnimate: doAnimate2,
180
- dontAnimate: dontAnimate2,
181
- animationOptions: animationOptions2,
182
- animationProps,
183
- lastDoAnimate: {
184
- ...refs.current.lastDoAnimate
185
- },
186
- lastDontAnimate: {
187
- ...refs.current.lastDontAnimate
188
- },
189
- isExiting,
190
- style,
191
- node
192
- });
193
- console.groupCollapsed(`trace >`);
194
- console.trace();
195
- console.groupEnd();
196
- console.groupEnd();
197
- }
198
- }
199
- if (!_instanceof(node, HTMLElement)) {
200
- return;
201
- }
202
- var prevDont = refs.current.lastDontAnimate;
203
- if (dontAnimate2) {
204
- if (prevDont) {
205
- removeRemovedStyles(prevDont, dontAnimate2, node, doAnimate2);
206
- var changed = getDiff(prevDont, dontAnimate2);
207
- if (changed) {
208
- Object.assign(node.style, changed);
209
- }
210
- } else {
211
- Object.assign(node.style, dontAnimate2);
212
- }
213
- }
214
- if (doAnimate2) {
215
- if (prevDont) {
216
- for (var key in prevDont) {
217
- if (key in doAnimate2) {
218
- node.style[key] = prevDont[key];
219
- if (refs.current.lastDoAnimate) {
220
- refs.current.lastDoAnimate[key] = prevDont[key];
221
- }
222
- }
223
- }
224
- }
225
- var lastAnimated = refs.current.lastDoAnimate;
226
- if (lastAnimated) {
227
- removeRemovedStyles(lastAnimated, doAnimate2, node, dontAnimate2);
228
- }
229
- var diff = getDiff(refs.current.lastDoAnimate, doAnimate2);
230
- if (diff) {
231
- if (isCurrentlyExiting && !refs.current.frozenExitTarget) {
232
- refs.current.frozenExitTarget = {
233
- ...doAnimate2
234
- };
235
- }
236
- var isPopperPosition = node.hasAttribute("data-popper-animate-position");
237
- var popperHandledTransform = false;
238
- if (isPopperPosition && !isCurrentlyExiting && typeof diff.transform === "string") {
239
- var target = parseTranslate(diff.transform);
240
- if (target) {
241
- var entry = PopperPositionAnims.get(node);
242
- if (!entry) {
243
- var seed = target;
244
- try {
245
- var _parseTranslate;
246
- seed = (_parseTranslate = parseTranslate(getComputedStyle(node).transform)) !== null && _parseTranslate !== void 0 ? _parseTranslate : target;
247
- } catch (e) {}
248
- var x = motionValue(seed.x);
249
- var y = motionValue(seed.y);
250
- var write = function () {
251
- node.style.transform = `translate3d(${x.get()}px, ${y.get()}px, 0)`;
252
- };
253
- x.on("change", write);
254
- y.on("change", write);
255
- entry = {
256
- x,
257
- y,
258
- stop: null
259
- };
260
- PopperPositionAnims.set(node, entry);
261
- }
262
- if (!entry.stop) {
263
- try {
264
- var live = parseTranslate(getComputedStyle(node).transform);
265
- if (live) {
266
- entry.x.jump(live.x);
267
- entry.y.jump(live.y);
268
- }
269
- } catch (e) {}
270
- }
271
- var _iteratorNormalCompletion = true,
272
- _didIteratorError = false,
273
- _iteratorError = void 0;
274
- try {
275
- for (var _iterator = node.getAnimations()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
276
- var anim = _step.value;
277
- try {
278
- var _anim_effect_getKeyframes, _anim_effect;
279
- 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);
280
- if (kf === null || kf === void 0 ? void 0 : kf.some(function (k) {
281
- return "transform" in k;
282
- })) {
283
- anim.cancel();
284
- }
285
- } catch (e) {}
286
- }
287
- } catch (err) {
288
- _didIteratorError = true;
289
- _iteratorError = err;
290
- } finally {
291
- try {
292
- if (!_iteratorNormalCompletion && _iterator.return != null) {
293
- _iterator.return();
294
- }
295
- } finally {
296
- if (_didIteratorError) {
297
- throw _iteratorError;
298
- }
299
- }
300
- }
301
- var opts = animationOptions2;
302
- var _opts_transform, _ref;
303
- var positionTransition = (_ref = (_opts_transform = opts.transform) !== null && _opts_transform !== void 0 ? _opts_transform : opts.default) !== null && _ref !== void 0 ? _ref : animationOptions2;
304
- var cx = animateMotionValue(entry.x, target.x, positionTransition);
305
- var cy = animateMotionValue(entry.y, target.y, positionTransition);
306
- entry.stop = function () {
307
- cx.stop();
308
- cy.stop();
309
- };
310
- popperHandledTransform = true;
311
- }
312
- }
313
- if (isCurrentlyExiting) {
314
- var entry1 = PopperPositionAnims.get(node);
315
- if (entry1 === null || entry1 === void 0 ? void 0 : entry1.stop) {
316
- entry1.stop();
317
- entry1.stop = null;
318
- }
319
- }
320
- var midFlightValues = null;
321
- if (refs.current.controls) {
322
- try {
323
- var computed = getComputedStyle(node);
324
- midFlightValues = {};
325
- for (var key1 in diff) {
326
- var val = computed[key1];
327
- if (val !== void 0 && val !== "") {
328
- midFlightValues[key1] = val;
329
- }
330
- }
331
- } catch (e) {}
332
- if (isCurrentlyExiting) {
333
- refs.current.controls.stop();
334
- }
335
- if (midFlightValues) {
336
- for (var key2 in midFlightValues) {
337
- if (key2 === "transform" && popperHandledTransform) continue;
338
- node.style[key2] = midFlightValues[key2];
339
- }
340
- }
341
- if (isPopperPosition && !popperHandledTransform) {
342
- var anims = node.getAnimations();
343
- var _iteratorNormalCompletion1 = true,
344
- _didIteratorError1 = false,
345
- _iteratorError1 = void 0;
346
- try {
347
- for (var _iterator1 = anims[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
348
- var anim1 = _step1.value;
349
- anim1.cancel();
350
- }
351
- } catch (err) {
352
- _didIteratorError1 = true;
353
- _iteratorError1 = err;
354
- } finally {
355
- try {
356
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
357
- _iterator1.return();
358
- }
359
- } finally {
360
- if (_didIteratorError1) {
361
- throw _iteratorError1;
362
- }
363
- }
364
- }
365
- }
366
- }
367
- var fixedDiff = fixTransparentColors(diff, refs.current.lastDoAnimate, doAnimate2);
368
- var waapiDiff = fixedDiff;
369
- if (popperHandledTransform && "transform" in waapiDiff) {
370
- waapiDiff = {
371
- ...waapiDiff
372
- };
373
- delete waapiDiff.transform;
374
- }
375
- if ((isPopperPosition || isCurrentlyExiting) && (midFlightValues === null || midFlightValues === void 0 ? void 0 : midFlightValues.transform) && waapiDiff.transform) {
376
- waapiDiff.transform = [midFlightValues.transform, waapiDiff.transform];
377
- }
378
- if (Object.keys(waapiDiff).length > 0) {
379
- startedControls = animate(scope.current, waapiDiff, animationOptions2);
380
- refs.current.controls = startedControls;
381
- }
382
- refs.current.lastAnimateAt = Date.now();
383
- }
384
- }
385
- refs.current.lastDontAnimate = dontAnimate2 ? {
386
- ...dontAnimate2
387
- } : {};
388
- refs.current.lastDoAnimate = doAnimate2 ? {
389
- ...doAnimate2
390
- } : {};
391
- } finally {
392
- if (isCurrentlyExiting && currentSendExitComplete) {
393
- if (startedControls) {
394
- refs.current.exitCompleteScheduled = true;
395
- startedControls.finished.then(function () {
396
- if (refs.current.isExiting) {
397
- currentSendExitComplete();
398
- }
399
- }).catch(function () {
400
- if (refs.current.isExiting) {
401
- currentSendExitComplete();
402
- }
403
- });
404
- } else if (!refs.current.exitCompleteScheduled) {
405
- currentSendExitComplete();
406
- }
407
- }
408
- }
409
- };
410
- useStyleEmitter === null || useStyleEmitter === void 0 ? void 0 : useStyleEmitter(function (nextStyle, effectiveTransition) {
411
- var _$animationProps = getMotionAnimatedProps(props, nextStyle, disableAnimation, refs.current.animationState, effectiveTransition);
412
- flushAnimation(_$animationProps);
413
- });
414
- useIsomorphicLayoutEffect(function () {
415
- if (refs.current.isFirstRender) {
416
- refs.current.isFirstRender = false;
417
- refs.current.wasDisabled = disableAnimation;
418
- if (isHydrating) {
419
- if (doAnimate && Object.keys(doAnimate).length > 0) {
420
- refs.current.lastDoAnimate = {
421
- ...doAnimate
422
- };
423
- } else {
424
- refs.current.lastDoAnimate = dontAnimate ? {
425
- ...dontAnimate
426
- } : {};
427
- }
428
- refs.current.lastDontAnimate = dontAnimate ? {
429
- ...dontAnimate
430
- } : {};
431
- refs.current.lastAnimateAt = Date.now();
432
- return;
433
- }
434
- refs.current.lastDontAnimate = dontAnimate ? {
435
- ...dontAnimate
436
- } : {};
437
- refs.current.lastDoAnimate = doAnimate ? {
438
- ...doAnimate
439
- } : {};
440
- return;
441
- }
442
- var justEnabled = refs.current.wasDisabled && !disableAnimation;
443
- refs.current.wasDisabled = disableAnimation;
444
- var justStrippedClasses = !refs.current.wasNoClass && !!styleProps.noClass;
445
- refs.current.wasNoClass = !!styleProps.noClass;
446
- if ((justEnabled || justStrippedClasses) && animationState !== "enter") {
447
- var node = stateRef.current.host;
448
- if (_instanceof(node, HTMLElement)) {
449
- if (dontAnimate) Object.assign(node.style, dontAnimate);
450
- if (doAnimate) Object.assign(node.style, doAnimate);
451
- var entry = PopperPositionAnims.get(node);
452
- if (entry) {
453
- var _doAnimate_transform;
454
- 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);
455
- if (target) {
456
- var _entry_stop;
457
- (_entry_stop = entry.stop) === null || _entry_stop === void 0 ? void 0 : _entry_stop.call(entry);
458
- entry.stop = null;
459
- entry.x.jump(target.x);
460
- entry.y.jump(target.y);
461
- }
462
- }
463
- }
464
- refs.current.lastDontAnimate = dontAnimate ? {
465
- ...dontAnimate
466
- } : {};
467
- refs.current.lastDoAnimate = doAnimate ? {
468
- ...doAnimate
469
- } : {};
470
- return;
471
- }
472
- flushAnimation({
473
- doAnimate,
474
- dontAnimate,
475
- animationOptions
476
- });
477
- }, [style, isExiting, disableAnimation, styleProps.noClass]);
478
- if (process.env.NODE_ENV === "development") {
479
- if (props["debug"] && props["debug"] !== "profile") {
480
- console.groupCollapsed(`[motion] render`);
481
- console.info({
482
- style,
483
- doAnimate,
484
- dontAnimate,
485
- scope,
486
- animationOptions,
487
- isExiting,
488
- isFirstRender: refs.current.isFirstRender,
489
- animationProps
490
- });
491
- console.groupEnd();
492
- }
493
- }
494
- return {
495
- style: firstRenderStyle,
496
- ref: scope,
497
- render: "div"
498
- };
499
- },
500
- useAnimatedNumber(initial) {
501
- var motionValue2 = useMotionValue(initial);
502
- return React.useMemo(function () {
503
- return {
504
- getInstance() {
505
- return motionValue2;
506
- },
507
- getValue() {
508
- return motionValue2.get();
509
- },
510
- setValue(next) {
511
- var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
512
- type: "spring"
513
- },
514
- onFinish = arguments.length > 2 ? arguments[2] : void 0;
515
- if (config.type === "direct") {
516
- MotionValueStrategy.set(motionValue2, {
517
- type: "direct"
518
- });
519
- motionValue2.set(next);
520
- onFinish === null || onFinish === void 0 ? void 0 : onFinish();
521
- return;
522
- }
523
- MotionValueStrategy.set(motionValue2, config);
524
- if (onFinish) {
525
- var prior = PendingMotionOnFinish.get(motionValue2);
526
- if (prior) {
527
- PendingMotionOnFinish.delete(motionValue2);
528
- prior();
529
- }
530
- PendingMotionOnFinish.set(motionValue2, onFinish);
531
- }
532
- motionValue2.set(next);
533
- },
534
- stop() {
535
- motionValue2.stop();
536
- }
537
- };
538
- }, [motionValue2]);
539
- },
540
- useAnimatedNumberReaction(param, onValue) {
541
- var {
542
- value
543
- } = param;
544
- var instance = value.getInstance();
545
- useMotionValueEvent(instance, "change", onValue);
546
- },
547
- useAnimatedNumberStyle(val, getStyleProp) {
548
- var motionValue2 = val.getInstance();
549
- var getStyleRef = useRef(getStyleProp);
550
- getStyleRef.current = getStyleProp;
551
- return useMemo(function () {
552
- return {
553
- getStyle: function (cur) {
554
- return getStyleRef.current(cur);
555
- },
556
- motionValue: motionValue2
557
- };
558
- }, []);
559
- },
560
- useAnimatedNumbersStyle(vals, getStyleProp) {
561
- var motionValues = vals.map(function (v) {
562
- return v.getInstance();
563
- });
564
- var getStyleRef = useRef(getStyleProp);
565
- getStyleRef.current = getStyleProp;
566
- return useMemo(function () {
567
- return {
568
- getStyle: function () {
569
- for (var _len = arguments.length, currentValues = new Array(_len), _key = 0; _key < _len; _key++) {
570
- currentValues[_key] = arguments[_key];
571
- }
572
- return getStyleRef.current(...currentValues);
573
- },
574
- motionValues
575
- };
576
- }, []);
577
- }
578
- };
579
- function getMotionAnimatedProps(props, style, disable) {
580
- var animationState = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "default",
581
- transitionOverride = arguments.length > 4 ? arguments[4] : void 0;
582
- if (disable) {
583
- return {
584
- dontAnimate: style
585
- };
586
- }
587
- var _ref;
588
- var animationOptions = getAnimationOptions((_ref = transitionOverride !== null && transitionOverride !== void 0 ? transitionOverride : props.transition) !== null && _ref !== void 0 ? _ref : null, animationState);
589
- var dontAnimate;
590
- var doAnimate;
591
- var animateOnly = props.animateOnly;
592
- for (var key in style) {
593
- var value = style[key];
594
- if (disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key)) {
595
- dontAnimate || (dontAnimate = {});
596
- dontAnimate[key] = value;
597
- } else {
598
- doAnimate || (doAnimate = {});
599
- doAnimate[key] = value;
600
- }
601
- }
602
- return {
603
- dontAnimate,
604
- doAnimate,
605
- animationOptions
606
- };
607
- }
608
- function getAnimationOptions(transitionProp) {
609
- var animationState = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "default";
610
- var normalized = normalizeTransition(transitionProp);
611
- var effectiveKey = getEffectiveAnimation(normalized, animationState);
612
- if (!effectiveKey && animationState === "default") {
613
- effectiveKey = normalized.enter || normalized.exit || null;
614
- }
615
- var globalConfigOverride = normalized.config ? {
616
- ...normalized.config
617
- } : void 0;
618
- if (!effectiveKey && Object.keys(normalized.properties).length === 0 && !globalConfigOverride) {
619
- return {};
620
- }
621
- var defaultConfig = effectiveKey ? withInferredType(animations[effectiveKey]) : null;
622
- var delay = normalized.delay;
623
- var result = {};
624
- if (defaultConfig) {
625
- Object.assign(result, defaultConfig);
626
- }
627
- if (globalConfigOverride) {
628
- Object.assign(result, globalConfigOverride);
629
- if (result.type === void 0 && result.duration !== void 0 && result.damping === void 0 && result.stiffness === void 0 && result.mass === void 0) {
630
- result.type = "tween";
631
- }
632
- }
633
- if (delay) {
634
- result.delay = delay;
635
- }
636
- if (defaultConfig || globalConfigOverride || delay) {
637
- result.default = {
638
- ...defaultConfig,
639
- ...globalConfigOverride,
640
- ...(delay ? {
641
- delay
642
- } : null)
643
- };
644
- }
645
- var _iteratorNormalCompletion = true,
646
- _didIteratorError = false,
647
- _iteratorError = void 0;
648
- try {
649
- for (var _iterator = Object.entries(normalized.properties)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
650
- var [propName, animationNameOrConfig] = _step.value;
651
- if (typeof animationNameOrConfig === "string") {
652
- result[propName] = withInferredType(animations[animationNameOrConfig]);
653
- } else if (animationNameOrConfig && (typeof animationNameOrConfig === "undefined" ? "undefined" : _type_of(animationNameOrConfig)) === "object") {
654
- var baseConfig = animationNameOrConfig.type ? withInferredType(animations[animationNameOrConfig.type]) : defaultConfig;
655
- result[propName] = {
656
- ...baseConfig,
657
- ...animationNameOrConfig
658
- };
659
- }
660
- }
661
- } catch (err) {
662
- _didIteratorError = true;
663
- _iteratorError = err;
664
- } finally {
665
- try {
666
- if (!_iteratorNormalCompletion && _iterator.return != null) {
667
- _iterator.return();
668
- }
669
- } finally {
670
- if (_didIteratorError) {
671
- throw _iteratorError;
672
- }
673
- }
674
- }
675
- convertMsToS(result);
676
- convertMsToS(result.default);
677
- for (var key in result) {
678
- if (key !== "default" && _type_of(result[key]) === "object") {
679
- convertMsToS(result[key]);
680
- }
681
- }
682
- return result;
683
- }
684
- }
685
- function withInferredType(config) {
686
- if (!config) {
687
- return {
688
- type: "spring"
689
- };
690
- }
691
- var isTimingBased = config.duration !== void 0 && config.damping === void 0 && config.stiffness === void 0 && config.mass === void 0;
692
- return {
693
- type: isTimingBased ? "tween" : "spring",
694
- ...config
695
- };
54
+ var isHydratingGlobal;
55
+ var hydratingComponents = /* @__PURE__ */ new Set();
56
+ return {
57
+ View: MotionView,
58
+ Text: MotionText,
59
+ inputStyle: "css",
60
+ outputStyle: "inline",
61
+ avoidReRenders: true,
62
+ animations,
63
+ usePresence,
64
+ ResetPresence,
65
+ onMount() {
66
+ isHydratingGlobal = false;
67
+ hydratingComponents.forEach(function(cb) {
68
+ return cb();
69
+ });
70
+ },
71
+ useAnimations: function(animationProps) {
72
+ if (isHydratingGlobal === void 0 && !getConfig().settings.disableSSR) {
73
+ isHydratingGlobal = true;
74
+ }
75
+ var { props, style, componentState, stateRef, useStyleEmitter, presence, onTransition, styleProps, styleState } = animationProps;
76
+ var _styleState_effectiveTransition;
77
+ var effectiveTransition = (_styleState_effectiveTransition = styleState === null || styleState === void 0 ? void 0 : styleState.effectiveTransition) !== null && _styleState_effectiveTransition !== void 0 ? _styleState_effectiveTransition : props.transition;
78
+ var isComponentHydrating = componentState.unmounted === true;
79
+ var isMounting = componentState.unmounted === "should-enter";
80
+ var isEntering = !!componentState.unmounted;
81
+ var isExiting = (presence === null || presence === void 0 ? void 0 : presence[0]) === false;
82
+ var sendExitComplete = presence === null || presence === void 0 ? void 0 : presence[1];
83
+ var refs = useRef(null);
84
+ if (!refs.current) {
85
+ refs.current = {
86
+ isFirstRender: true,
87
+ lastDoAnimate: null,
88
+ lastDontAnimate: null,
89
+ controls: null,
90
+ lastAnimateAt: 0,
91
+ disposed: false,
92
+ wasExiting: false,
93
+ isExiting: false,
94
+ sendExitComplete: void 0,
95
+ animationState: "default",
96
+ frozenExitTarget: null,
97
+ exitCompleteScheduled: false,
98
+ enterCompleteScheduled: false,
99
+ disableAnimation: true,
100
+ wasEntering: false,
101
+ wasDisabled: false,
102
+ onTransition: void 0,
103
+ enterStarted: false,
104
+ exitStarted: false,
105
+ updateInFlight: false,
106
+ updateControls: null,
107
+ wasNoClass: !!styleProps.noClass
108
+ };
109
+ }
110
+ var emit = function(phase, cause, finished) {
111
+ var _refs_current_onTransition, _refs_current;
112
+ (_refs_current_onTransition = (_refs_current = refs.current).onTransition) === null || _refs_current_onTransition === void 0 ? void 0 : _refs_current_onTransition.call(_refs_current, phase === "end" ? {
113
+ phase,
114
+ cause,
115
+ finished
116
+ } : {
117
+ phase,
118
+ cause
119
+ });
120
+ };
121
+ var justFinishedEntering = refs.current.wasEntering && !isEntering;
122
+ useEffect(function() {
123
+ refs.current.wasEntering = isEntering;
124
+ });
125
+ var animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default";
126
+ var disableAnimation = isComponentHydrating || isMounting || !effectiveTransition;
127
+ var [scope] = useAnimateSSRSafe();
128
+ refs.current.isExiting = isExiting;
129
+ refs.current.sendExitComplete = sendExitComplete;
130
+ refs.current.animationState = animationState;
131
+ refs.current.disableAnimation = disableAnimation;
132
+ refs.current.onTransition = onTransition;
133
+ var justStartedExiting = isExiting && !refs.current.wasExiting;
134
+ var justStoppedExiting = !isExiting && refs.current.wasExiting;
135
+ if (justStartedExiting || justStoppedExiting) {
136
+ refs.current.frozenExitTarget = null;
137
+ refs.current.exitCompleteScheduled = false;
138
+ refs.current.enterCompleteScheduled = false;
139
+ }
140
+ useEffect(function() {
141
+ refs.current.wasExiting = isExiting;
142
+ });
143
+ useIsomorphicLayoutEffect(function() {
144
+ if (justStoppedExiting && refs.current.exitStarted) {
145
+ refs.current.exitStarted = false;
146
+ emit("end", "exit", false);
147
+ }
148
+ }, [justStoppedExiting]);
149
+ var { dontAnimate = {}, doAnimate, animationOptions } = getMotionAnimatedProps(props, style, disableAnimation, animationState, effectiveTransition);
150
+ var [firstRenderStyle] = useState(style);
151
+ if (refs.current.isFirstRender) {
152
+ refs.current.lastDontAnimate = firstRenderStyle;
153
+ }
154
+ var [isHydrating, setIsHydrating] = useState(isHydratingGlobal);
155
+ useLayoutEffect(function() {
156
+ if (isHydratingGlobal) {
157
+ hydratingComponents.add(function() {
158
+ setIsHydrating(false);
159
+ });
160
+ }
161
+ return function() {
162
+ refs.current.disposed = true;
163
+ };
164
+ }, []);
165
+ var flushAnimation = function(param) {
166
+ var { doAnimate: doAnimateRaw = {}, animationOptions: passedOptions = {}, dontAnimate: dontAnimate2 } = param;
167
+ var startedControls = null;
168
+ var isCurrentlyExiting = refs.current.isExiting;
169
+ var currentSendExitComplete = refs.current.sendExitComplete;
170
+ var currentAnimationState = refs.current.animationState;
171
+ var doAnimate2 = doAnimateRaw;
172
+ if (isCurrentlyExiting && refs.current.frozenExitTarget) {
173
+ doAnimate2 = refs.current.frozenExitTarget;
174
+ }
175
+ var animationOptions2 = isCurrentlyExiting && currentSendExitComplete ? getAnimationOptions(forAnimationState(resolveTransition(effectiveTransition !== null && effectiveTransition !== void 0 ? effectiveTransition : null, { animations }), "exit")) : passedOptions;
176
+ try {
177
+ var node = stateRef.current.host;
178
+ if (refs.current.isFirstRender) {
179
+ refs.current.lastDontAnimate = null;
180
+ refs.current.lastDoAnimate = null;
181
+ }
182
+ if (process.env.NODE_ENV === "development") {
183
+ if (props["debug"] && props["debug"] !== "profile") {
184
+ console.groupCollapsed(`[motion] animate (${JSON.stringify(getDiff(refs.current.lastDoAnimate, doAnimate2), null, 2)})`);
185
+ console.info({
186
+ props,
187
+ componentState,
188
+ doAnimate: doAnimate2,
189
+ dontAnimate: dontAnimate2,
190
+ animationOptions: animationOptions2,
191
+ animationProps,
192
+ lastDoAnimate: { ...refs.current.lastDoAnimate },
193
+ lastDontAnimate: { ...refs.current.lastDontAnimate },
194
+ isExiting,
195
+ style,
196
+ node
197
+ });
198
+ console.groupCollapsed(`trace >`);
199
+ console.trace();
200
+ console.groupEnd();
201
+ console.groupEnd();
202
+ }
203
+ }
204
+ if (!(node instanceof HTMLElement)) {
205
+ return;
206
+ }
207
+ var prevDont = refs.current.lastDontAnimate;
208
+ if (dontAnimate2) {
209
+ if (prevDont) {
210
+ removeRemovedStyles(prevDont, dontAnimate2, node, doAnimate2);
211
+ var changed = getDiff(prevDont, dontAnimate2);
212
+ if (changed) {
213
+ assignInlineStyles(node, changed);
214
+ }
215
+ } else {
216
+ assignInlineStyles(node, dontAnimate2);
217
+ }
218
+ } else if (prevDont) {
219
+ removeRemovedStyles(prevDont, {}, node, doAnimate2);
220
+ }
221
+ if (doAnimate2) {
222
+ if (prevDont) {
223
+ for (var key in prevDont) {
224
+ if (key in doAnimate2) {
225
+ node.style[key] = normalizeValueWithProperty(prevDont[key], key);
226
+ if (refs.current.lastDoAnimate) {
227
+ refs.current.lastDoAnimate[key] = prevDont[key];
228
+ }
229
+ }
230
+ }
231
+ }
232
+ var lastAnimated = refs.current.lastDoAnimate;
233
+ if (lastAnimated) {
234
+ removeRemovedStyles(lastAnimated, doAnimate2, node, dontAnimate2);
235
+ }
236
+ var diff = getDiff(refs.current.lastDoAnimate, doAnimate2);
237
+ if (diff) {
238
+ if (isCurrentlyExiting && !refs.current.frozenExitTarget) {
239
+ refs.current.frozenExitTarget = { ...doAnimate2 };
240
+ }
241
+ var isPopperPosition = node.hasAttribute("data-popper-animate-position");
242
+ var popperHandledTransform = false;
243
+ if (isPopperPosition && !isCurrentlyExiting && typeof diff.transform === "string") {
244
+ var target = parseTranslate(diff.transform);
245
+ if (target) {
246
+ var entry = PopperPositionAnims.get(node);
247
+ if (!entry) {
248
+ var seed = target;
249
+ try {
250
+ var _parseTranslate;
251
+ seed = (_parseTranslate = parseTranslate(getComputedStyle(node).transform)) !== null && _parseTranslate !== void 0 ? _parseTranslate : target;
252
+ } catch (e) {}
253
+ var x = motionValue(seed.x);
254
+ var y = motionValue(seed.y);
255
+ var write = function() {
256
+ node.style.transform = `translate3d(${x.get()}px, ${y.get()}px, 0)`;
257
+ };
258
+ x.on("change", write);
259
+ y.on("change", write);
260
+ entry = {
261
+ x,
262
+ y,
263
+ stop: null
264
+ };
265
+ PopperPositionAnims.set(node, entry);
266
+ }
267
+ if (!entry.stop) {
268
+ try {
269
+ var live = parseTranslate(getComputedStyle(node).transform);
270
+ if (live) {
271
+ entry.x.jump(live.x);
272
+ entry.y.jump(live.y);
273
+ }
274
+ } catch (e) {}
275
+ }
276
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
277
+ try {
278
+ for (var _iterator = node.getAnimations()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
279
+ var anim = _step.value;
280
+ try {
281
+ var _anim_effect_getKeyframes, _anim_effect;
282
+ 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);
283
+ if (kf === null || kf === void 0 ? void 0 : kf.some(function(k) {
284
+ return "transform" in k;
285
+ })) {
286
+ anim.cancel();
287
+ }
288
+ } catch (e) {}
289
+ }
290
+ } catch (err) {
291
+ _didIteratorError = true;
292
+ _iteratorError = err;
293
+ } finally {
294
+ try {
295
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
296
+ _iterator.return();
297
+ }
298
+ } finally {
299
+ if (_didIteratorError) {
300
+ throw _iteratorError;
301
+ }
302
+ }
303
+ }
304
+ var opts = animationOptions2;
305
+ var _opts_x, _ref, _ref1;
306
+ var positionTransition = (_ref1 = (_ref = (_opts_x = opts.x) !== null && _opts_x !== void 0 ? _opts_x : opts.transform) !== null && _ref !== void 0 ? _ref : opts.default) !== null && _ref1 !== void 0 ? _ref1 : animationOptions2;
307
+ var cx = animate(entry.x, target.x, positionTransition);
308
+ var cy = animate(entry.y, target.y, positionTransition);
309
+ entry.stop = function() {
310
+ cx.stop();
311
+ cy.stop();
312
+ };
313
+ popperHandledTransform = true;
314
+ }
315
+ }
316
+ if (isCurrentlyExiting) {
317
+ var entry1 = PopperPositionAnims.get(node);
318
+ if (entry1 === null || entry1 === void 0 ? void 0 : entry1.stop) {
319
+ entry1.stop();
320
+ entry1.stop = null;
321
+ }
322
+ }
323
+ var midFlightValues = null;
324
+ if (refs.current.controls) {
325
+ try {
326
+ var computed = getComputedStyle(node);
327
+ midFlightValues = {};
328
+ for (var key1 in diff) {
329
+ var val = computed[key1];
330
+ if (val !== void 0 && val !== "") {
331
+ midFlightValues[key1] = val;
332
+ }
333
+ }
334
+ } catch (e) {}
335
+ if (isCurrentlyExiting) {
336
+ refs.current.controls.stop();
337
+ }
338
+ if (midFlightValues) {
339
+ for (var key2 in midFlightValues) {
340
+ if (key2 === "transform" && popperHandledTransform) continue;
341
+ node.style[key2] = midFlightValues[key2];
342
+ }
343
+ }
344
+ if (isPopperPosition && !popperHandledTransform) {
345
+ var anims = node.getAnimations();
346
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
347
+ try {
348
+ for (var _iterator1 = anims[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
349
+ var anim1 = _step1.value;
350
+ anim1.cancel();
351
+ }
352
+ } catch (err) {
353
+ _didIteratorError1 = true;
354
+ _iteratorError1 = err;
355
+ } finally {
356
+ try {
357
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
358
+ _iterator1.return();
359
+ }
360
+ } finally {
361
+ if (_didIteratorError1) {
362
+ throw _iteratorError1;
363
+ }
364
+ }
365
+ }
366
+ }
367
+ }
368
+ var fixedDiff = fixTransparentColors(diff, refs.current.lastDoAnimate, doAnimate2);
369
+ var waapiDiff = Object.fromEntries(Object.entries(fixedDiff).map(function(param2) {
370
+ var [key3, value] = param2;
371
+ return [key3, Array.isArray(value) ? value.map(function(item) {
372
+ return normalizeValueWithProperty(item, key3);
373
+ }) : normalizeValueWithProperty(value, key3)];
374
+ }));
375
+ if (popperHandledTransform && "transform" in waapiDiff) {
376
+ waapiDiff = { ...waapiDiff };
377
+ delete waapiDiff.transform;
378
+ }
379
+ if ((isPopperPosition || isCurrentlyExiting) && (midFlightValues === null || midFlightValues === void 0 ? void 0 : midFlightValues.transform) && waapiDiff.transform) {
380
+ waapiDiff.transform = [midFlightValues.transform, waapiDiff.transform];
381
+ }
382
+ if (Object.keys(waapiDiff).length > 0) {
383
+ startedControls = animate(node, waapiDiff, animationOptions2);
384
+ refs.current.controls = startedControls;
385
+ }
386
+ refs.current.lastAnimateAt = Date.now();
387
+ }
388
+ }
389
+ refs.current.lastDontAnimate = dontAnimate2 ? { ...dontAnimate2 } : {};
390
+ refs.current.lastDoAnimate = doAnimate2 ? { ...doAnimate2 } : {};
391
+ } finally {
392
+ if (isCurrentlyExiting && currentSendExitComplete) {
393
+ if (refs.current.enterStarted) {
394
+ refs.current.enterStarted = false;
395
+ emit("end", "enter", false);
396
+ }
397
+ if (startedControls) {
398
+ if (!refs.current.exitStarted) {
399
+ refs.current.exitStarted = true;
400
+ emit("start", "exit");
401
+ }
402
+ refs.current.exitCompleteScheduled = true;
403
+ var complete = function(finished) {
404
+ if (!refs.current.isExiting) return;
405
+ if (refs.current.exitStarted) {
406
+ refs.current.exitStarted = false;
407
+ emit("end", "exit", finished);
408
+ }
409
+ currentSendExitComplete();
410
+ };
411
+ startedControls.finished.then(function() {
412
+ return complete(true);
413
+ }).catch(function() {
414
+ return complete(false);
415
+ });
416
+ } else if (!refs.current.exitCompleteScheduled) {
417
+ emit("start", "exit");
418
+ emit("end", "exit", true);
419
+ currentSendExitComplete();
420
+ }
421
+ } else if (currentAnimationState === "enter") {
422
+ if (startedControls) {
423
+ if (!refs.current.enterStarted) {
424
+ refs.current.enterStarted = true;
425
+ emit("start", "enter");
426
+ }
427
+ refs.current.enterCompleteScheduled = true;
428
+ var complete1 = function(finished) {
429
+ if (refs.current.disposed || refs.current.animationState !== "enter") return;
430
+ if (refs.current.enterStarted) {
431
+ refs.current.enterStarted = false;
432
+ emit("end", "enter", finished);
433
+ }
434
+ };
435
+ startedControls.finished.then(function() {
436
+ return complete1(true);
437
+ }).catch(function() {
438
+ return complete1(false);
439
+ });
440
+ } else if (!refs.current.enterCompleteScheduled && !refs.current.disableAnimation) {
441
+ emit("start", "enter");
442
+ emit("end", "enter", true);
443
+ }
444
+ } else if (startedControls) {
445
+ var controls = startedControls;
446
+ if (refs.current.updateInFlight) {
447
+ emit("end", "update", false);
448
+ }
449
+ refs.current.updateInFlight = true;
450
+ refs.current.updateControls = controls;
451
+ emit("start", "update");
452
+ var settle = function(finished) {
453
+ if (refs.current.updateControls !== controls) return;
454
+ refs.current.updateInFlight = false;
455
+ refs.current.updateControls = null;
456
+ emit("end", "update", finished);
457
+ };
458
+ controls.finished.then(function() {
459
+ return settle(true);
460
+ }).catch(function() {
461
+ return settle(false);
462
+ });
463
+ }
464
+ }
465
+ };
466
+ useStyleEmitter === null || useStyleEmitter === void 0 ? void 0 : useStyleEmitter(function(nextStyle, emittedTransition) {
467
+ var _$animationProps = getMotionAnimatedProps(props, nextStyle, disableAnimation, refs.current.animationState, emittedTransition !== null && emittedTransition !== void 0 ? emittedTransition : effectiveTransition);
468
+ flushAnimation(_$animationProps);
469
+ });
470
+ useIsomorphicLayoutEffect(function() {
471
+ if (refs.current.isFirstRender) {
472
+ refs.current.isFirstRender = false;
473
+ refs.current.wasDisabled = disableAnimation;
474
+ if (isHydrating) {
475
+ if (doAnimate && Object.keys(doAnimate).length > 0) {
476
+ refs.current.lastDoAnimate = { ...doAnimate };
477
+ } else {
478
+ refs.current.lastDoAnimate = dontAnimate ? { ...dontAnimate } : {};
479
+ }
480
+ refs.current.lastDontAnimate = dontAnimate ? { ...dontAnimate } : {};
481
+ refs.current.lastAnimateAt = Date.now();
482
+ return;
483
+ }
484
+ refs.current.lastDontAnimate = dontAnimate ? { ...dontAnimate } : {};
485
+ refs.current.lastDoAnimate = doAnimate ? { ...doAnimate } : {};
486
+ return;
487
+ }
488
+ var justEnabled = refs.current.wasDisabled && !disableAnimation;
489
+ refs.current.wasDisabled = disableAnimation;
490
+ var justStrippedClasses = !refs.current.wasNoClass && !!styleProps.noClass;
491
+ refs.current.wasNoClass = !!styleProps.noClass;
492
+ if ((justEnabled || justStrippedClasses) && animationState !== "enter") {
493
+ var node = stateRef.current.host;
494
+ if (node instanceof HTMLElement) {
495
+ if (dontAnimate) assignInlineStyles(node, dontAnimate);
496
+ if (doAnimate) assignInlineStyles(node, doAnimate);
497
+ var entry = PopperPositionAnims.get(node);
498
+ if (entry) {
499
+ var _doAnimate_transform;
500
+ 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);
501
+ if (target) {
502
+ var _entry_stop;
503
+ (_entry_stop = entry.stop) === null || _entry_stop === void 0 ? void 0 : _entry_stop.call(entry);
504
+ entry.stop = null;
505
+ entry.x.jump(target.x);
506
+ entry.y.jump(target.y);
507
+ }
508
+ }
509
+ }
510
+ refs.current.lastDontAnimate = dontAnimate ? { ...dontAnimate } : {};
511
+ refs.current.lastDoAnimate = doAnimate ? { ...doAnimate } : {};
512
+ return;
513
+ }
514
+ flushAnimation({
515
+ doAnimate,
516
+ dontAnimate,
517
+ animationOptions
518
+ });
519
+ }, [
520
+ style,
521
+ isExiting,
522
+ disableAnimation,
523
+ styleProps.noClass
524
+ ]);
525
+ if (process.env.NODE_ENV === "development") {
526
+ if (props["debug"] && props["debug"] !== "profile") {
527
+ console.groupCollapsed(`[motion] render`);
528
+ console.info({
529
+ style,
530
+ doAnimate,
531
+ dontAnimate,
532
+ scope,
533
+ animationOptions,
534
+ isExiting,
535
+ isFirstRender: refs.current.isFirstRender,
536
+ animationProps
537
+ });
538
+ console.groupEnd();
539
+ }
540
+ }
541
+ return {
542
+ style: firstRenderStyle,
543
+ ref: scope,
544
+ render: "div"
545
+ };
546
+ },
547
+ useAnimatedNumber(initial) {
548
+ var motionValue2 = useMotionValue(initial);
549
+ return React.useMemo(function() {
550
+ return {
551
+ getInstance() {
552
+ return motionValue2;
553
+ },
554
+ getValue() {
555
+ return motionValue2.get();
556
+ },
557
+ setValue(next) {
558
+ var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : { type: "spring" }, onFinish = arguments.length > 2 ? arguments[2] : void 0;
559
+ if (config.type === "direct") {
560
+ MotionValueStrategy.set(motionValue2, { type: "direct" });
561
+ motionValue2.set(next);
562
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish();
563
+ return;
564
+ }
565
+ MotionValueStrategy.set(motionValue2, config);
566
+ if (onFinish) {
567
+ var prior = PendingMotionOnFinish.get(motionValue2);
568
+ if (prior) {
569
+ PendingMotionOnFinish.delete(motionValue2);
570
+ prior();
571
+ }
572
+ PendingMotionOnFinish.set(motionValue2, onFinish);
573
+ }
574
+ motionValue2.set(next);
575
+ },
576
+ stop() {
577
+ motionValue2.stop();
578
+ }
579
+ };
580
+ }, [motionValue2]);
581
+ },
582
+ useAnimatedNumberReaction(param, onValue) {
583
+ var { value } = param;
584
+ var instance = value.getInstance();
585
+ useMotionValueEvent(instance, "change", onValue);
586
+ },
587
+ useAnimatedNumberStyle(val, getStyleProp) {
588
+ var motionValue2 = val.getInstance();
589
+ var getStyleRef = useRef(getStyleProp);
590
+ getStyleRef.current = getStyleProp;
591
+ return useMemo(function() {
592
+ return {
593
+ getStyle: function(cur) {
594
+ return getStyleRef.current(cur);
595
+ },
596
+ motionValue: motionValue2
597
+ };
598
+ }, []);
599
+ },
600
+ useAnimatedNumbersStyle(vals, getStyleProp) {
601
+ var motionValues = vals.map(function(v) {
602
+ return v.getInstance();
603
+ });
604
+ var getStyleRef = useRef(getStyleProp);
605
+ getStyleRef.current = getStyleProp;
606
+ return useMemo(function() {
607
+ return {
608
+ getStyle: function() {
609
+ for (var _len = arguments.length, currentValues = new Array(_len), _key = 0; _key < _len; _key++) {
610
+ currentValues[_key] = arguments[_key];
611
+ }
612
+ return getStyleRef.current(...currentValues);
613
+ },
614
+ motionValues
615
+ };
616
+ }, []);
617
+ }
618
+ };
619
+ function getMotionAnimatedProps(props, style, disable) {
620
+ var animationState = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "default", transitionOverride = arguments.length > 4 ? arguments[4] : void 0;
621
+ if (disable) {
622
+ return { dontAnimate: style };
623
+ }
624
+ var _ref;
625
+ var resolved = forAnimationState(resolveTransition((_ref = transitionOverride !== null && transitionOverride !== void 0 ? transitionOverride : props.transition) !== null && _ref !== void 0 ? _ref : null, { animations }), animationState);
626
+ var animationOptions = getAnimationOptions(resolved);
627
+ var dontAnimate;
628
+ var doAnimate;
629
+ for (var key in style) {
630
+ var value = style[key];
631
+ if (disableAnimationProps.has(key) || !getTransitionForKey(resolved, key)) {
632
+ dontAnimate || (dontAnimate = {});
633
+ dontAnimate[key] = value;
634
+ } else {
635
+ doAnimate || (doAnimate = {});
636
+ doAnimate[key] = value;
637
+ }
638
+ }
639
+ return {
640
+ dontAnimate,
641
+ doAnimate,
642
+ animationOptions
643
+ };
644
+ }
645
+ function getAnimationOptions(resolved) {
646
+ if (!hasTransition(resolved)) return {};
647
+ var result = {};
648
+ if (resolved.all) {
649
+ var base = entryToMotion(resolved.all);
650
+ Object.assign(result, base);
651
+ result.default = { ...base };
652
+ }
653
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
654
+ try {
655
+ for (var _iterator = resolved.entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
656
+ var entry = _step.value;
657
+ if (entry.property === "all") continue;
658
+ var config = entryToMotion(entry);
659
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
660
+ try {
661
+ for (var _iterator1 = styleKeysForProperty(entry.property)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
662
+ var key = _step1.value;
663
+ result[key] = { ...config };
664
+ }
665
+ } catch (err) {
666
+ _didIteratorError1 = true;
667
+ _iteratorError1 = err;
668
+ } finally {
669
+ try {
670
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
671
+ _iterator1.return();
672
+ }
673
+ } finally {
674
+ if (_didIteratorError1) {
675
+ throw _iteratorError1;
676
+ }
677
+ }
678
+ }
679
+ }
680
+ } catch (err) {
681
+ _didIteratorError = true;
682
+ _iteratorError = err;
683
+ } finally {
684
+ try {
685
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
686
+ _iterator.return();
687
+ }
688
+ } finally {
689
+ if (_didIteratorError) {
690
+ throw _iteratorError;
691
+ }
692
+ }
693
+ }
694
+ return result;
695
+ }
696
696
  }
697
- function convertMsToS(config) {
698
- if (!config) return;
699
- if (typeof config.delay === "number") config.delay = config.delay / 1e3;
700
- if (typeof config.duration === "number") {
701
- var isTimingBased = config.type === "tween" || config.type === void 0 && config.damping === void 0 && config.stiffness === void 0 && config.mass === void 0;
702
- if (isTimingBased) {
703
- config.duration = config.duration / 1e3;
704
- }
705
- }
697
+ function entryToMotion(entry) {
698
+ var delay = entry.delayMs ? { delay: entry.delayMs / 1e3 } : null;
699
+ if (entry.timing.kind === "spring") {
700
+ return {
701
+ type: "spring",
702
+ stiffness: entry.timing.stiffness,
703
+ damping: entry.timing.damping,
704
+ mass: entry.timing.mass,
705
+ ...delay
706
+ };
707
+ }
708
+ var bezier = easingToBezier(entry.timing.easing);
709
+ return {
710
+ type: "tween",
711
+ duration: entry.timing.durationMs / 1e3,
712
+ ...bezier ? { ease: [
713
+ bezier[0],
714
+ bezier[1],
715
+ bezier[2],
716
+ bezier[3]
717
+ ] } : null,
718
+ ...delay
719
+ };
706
720
  }
707
721
  function removeRemovedStyles(prev, next, node, dontClearIfIn) {
708
- for (var key in prev) {
709
- if (!(key in next)) {
710
- if (dontClearIfIn && key in dontClearIfIn) {
711
- continue;
712
- }
713
- node.style[key] = "";
714
- }
715
- }
722
+ for (var key in prev) {
723
+ if (!(key in next)) {
724
+ if (dontClearIfIn && key in dontClearIfIn) {
725
+ continue;
726
+ }
727
+ node.style[key] = "";
728
+ }
729
+ }
730
+ }
731
+ var disableAnimationProps = /* @__PURE__ */ new Set([...Object.keys(nonAnimatableStyleProps), "flexBasis"]);
732
+ function motionPropsEqual(a, b) {
733
+ for (var key in a) {
734
+ if (!(key in b)) return false;
735
+ }
736
+ for (var key1 in b) {
737
+ if (key1 === "children") continue;
738
+ var av = a[key1];
739
+ var bv = b[key1];
740
+ if (typeof bv === "function" && typeof av === "function") continue;
741
+ if (!Object.is(av, bv)) return false;
742
+ }
743
+ return true;
744
+ }
745
+ function motionStylesEqual(a, b) {
746
+ if (a.length !== b.length) return false;
747
+ for (var i = 0; i < a.length; i++) {
748
+ var sa = a[i];
749
+ var sb = b[i];
750
+ if (sa === sb) continue;
751
+ if (!sa || !sb) return false;
752
+ var aCount = 0;
753
+ for (var key in sa) {
754
+ aCount++;
755
+ if (!Object.is(sa[key], sb[key])) return false;
756
+ }
757
+ var bCount = 0;
758
+ for (var _key in sb) {
759
+ bCount++;
760
+ }
761
+ if (aCount !== bCount) return false;
762
+ }
763
+ return true;
716
764
  }
717
- var disableAnimationProps = /* @__PURE__ */new Set(["alignContent", "alignItems", "boxSizing", "contain", "containerType", "display", "flexBasis", "flexDirection", "fontFamily", "justifyContent", "overflow", "overflowX", "overflowY", "pointerEvents", "position", "textWrap", "userSelect"]);
718
765
  var MotionView = createMotionView("div");
719
766
  var MotionText = createMotionView("span");
767
+ var transformAliases = {
768
+ x: "translateX",
769
+ y: "translateY",
770
+ scale: "scale",
771
+ scaleX: "scaleX",
772
+ scaleY: "scaleY",
773
+ rotate: "rotate",
774
+ rotateX: "rotateX",
775
+ rotateY: "rotateY",
776
+ rotateZ: "rotateZ",
777
+ skewX: "skewX",
778
+ skewY: "skewY"
779
+ };
780
+ function compileAnimatedStyle(initialSource, initialResolved) {
781
+ var shorthands = getConfig().shorthands;
782
+ var entries = Object.keys(initialSource).map(function(source) {
783
+ var _shorthands_source, _shorthands_source1, _shorthands_source2;
784
+ return {
785
+ source,
786
+ target: (_shorthands_source = shorthands === null || shorthands === void 0 ? void 0 : shorthands[source]) !== null && _shorthands_source !== void 0 ? _shorthands_source : source,
787
+ tokenValue: typeof initialSource[source] === "string" && initialResolved[(_shorthands_source1 = shorthands === null || shorthands === void 0 ? void 0 : shorthands[source]) !== null && _shorthands_source1 !== void 0 ? _shorthands_source1 : source] !== initialSource[source] ? initialResolved[(_shorthands_source2 = shorthands === null || shorthands === void 0 ? void 0 : shorthands[source]) !== null && _shorthands_source2 !== void 0 ? _shorthands_source2 : source] : void 0
788
+ };
789
+ });
790
+ return function(sourceStyle) {
791
+ var resolved = {};
792
+ var transforms = [];
793
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
794
+ try {
795
+ for (var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
796
+ var entry = _step.value;
797
+ var value = sourceStyle[entry.source];
798
+ if (value === void 0) continue;
799
+ if (entry.source === "transform" && Array.isArray(value)) {
800
+ resolved.transform = transformsToString(value);
801
+ } else if (entry.source in transformAliases) {
802
+ transforms.push({ [transformAliases[entry.source]]: value });
803
+ } else {
804
+ var _entry_tokenValue;
805
+ resolved[entry.target] = (_entry_tokenValue = entry.tokenValue) !== null && _entry_tokenValue !== void 0 ? _entry_tokenValue : normalizeValueWithProperty(value, entry.target);
806
+ }
807
+ }
808
+ } catch (err) {
809
+ _didIteratorError = true;
810
+ _iteratorError = err;
811
+ } finally {
812
+ try {
813
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
814
+ _iterator.return();
815
+ }
816
+ } finally {
817
+ if (_didIteratorError) {
818
+ throw _iteratorError;
819
+ }
820
+ }
821
+ }
822
+ if (transforms.length) resolved.transform = transformsToString(transforms);
823
+ return resolved;
824
+ };
825
+ }
720
826
  function createMotionView(defaultTag) {
721
- var isText = defaultTag === "span";
722
- var Component = /* @__PURE__ */forwardRef(function (propsIn, ref) {
723
- var _hooks_usePropsTransform;
724
- var {
725
- forwardedRef,
726
- animation,
727
- render = defaultTag,
728
- style,
729
- ...propsRest
730
- } = propsIn;
731
- var [scope, animate] = useAnimateSSRSafe();
732
- var hostRef = useRef(null);
733
- var seededNode = useRef(null);
734
- var seededInCurrentFrame = useRef(false);
735
- var queuedAnimationFrames = useRef(/* @__PURE__ */new WeakMap());
736
- var composedRefs = useComposedRefs(forwardedRef, ref, hostRef, scope);
737
- var stateRef = useRef(null);
738
- if (!stateRef.current) {
739
- stateRef.current = {
740
- get host() {
741
- return hostRef.current;
742
- }
743
- };
744
- }
745
- var [_, state] = useThemeWithState({});
746
- var styles = Array.isArray(style) ? style : [style];
747
- var [animatedStyle, nonAnimatedStyles] = function () {
748
- var animatedStyle2;
749
- var nonAnimatedStyles2 = [];
750
- var _iteratorNormalCompletion = true,
751
- _didIteratorError = false,
752
- _iteratorError = void 0;
753
- try {
754
- for (var _iterator = styles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
755
- var style2 = _step.value;
756
- if (style2.getStyle) {
757
- animatedStyle2 = style2;
758
- } else {
759
- nonAnimatedStyles2.push(style2);
760
- }
761
- }
762
- } catch (err) {
763
- _didIteratorError = true;
764
- _iteratorError = err;
765
- } finally {
766
- try {
767
- if (!_iteratorNormalCompletion && _iterator.return != null) {
768
- _iterator.return();
769
- }
770
- } finally {
771
- if (_didIteratorError) {
772
- throw _iteratorError;
773
- }
774
- }
775
- }
776
- return [animatedStyle2, nonAnimatedStyles2];
777
- }();
778
- function getProps(props2) {
779
- var out = getSplitStyles(props2, isText ? Text.staticConfig : View.staticConfig, state === null || state === void 0 ? void 0 : state.theme, state === null || state === void 0 ? void 0 : state.name, {
780
- unmounted: false
781
- }, {
782
- isAnimated: false,
783
- noClass: true,
784
- resolveValues: "auto"
785
- });
786
- if (!out) {
787
- return {};
788
- }
789
- if (out.viewProps.style) {
790
- fixStyles(out.viewProps.style);
791
- styleToCSS(out.viewProps.style);
792
- }
793
- return out.viewProps;
794
- }
795
- var props = getProps({
796
- ...propsRest,
797
- style: nonAnimatedStyles
798
- });
799
- var Element = render || "div";
800
- var transformedProps = (_hooks_usePropsTransform = hooks.usePropsTransform) === null || _hooks_usePropsTransform === void 0 ? void 0 : _hooks_usePropsTransform.call(hooks, render, props, stateRef, false);
801
- useIsomorphicLayoutEffect(function () {
802
- if (!animatedStyle) return;
803
- var node = hostRef.current;
804
- if (_instanceof(node, HTMLElement) && seededNode.current !== node) {
805
- var currentStyle = animatedStyle.motionValues ? animatedStyle.getStyle(...animatedStyle.motionValues.map(function (value) {
806
- return value.get();
807
- })) : animatedStyle.motionValue ? animatedStyle.getStyle(animatedStyle.motionValue.get()) : null;
808
- var webStyle = currentStyle && getProps({
809
- style: currentStyle
810
- }).style;
811
- if (webStyle) {
812
- Object.assign(node.style, webStyle);
813
- seededNode.current = node;
814
- seededInCurrentFrame.current = true;
815
- requestAnimationFrame(function () {
816
- if (seededNode.current === node) {
817
- seededInCurrentFrame.current = false;
818
- }
819
- });
820
- }
821
- }
822
- var toTransition = function (animationConfig) {
823
- return (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "timing" ? {
824
- type: "tween",
825
- duration: ((animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.duration) || 0) / 1e3
826
- } : (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "direct" ? {
827
- type: "tween",
828
- duration: 0
829
- } : {
830
- type: "spring",
831
- ...animationConfig
832
- };
833
- };
834
- var animateNodeTo = function (nextStyle, transition, mv) {
835
- if (!_instanceof(node, HTMLElement) || hostRef.current !== node) return;
836
- var webStyle2 = getProps({
837
- style: nextStyle
838
- }).style;
839
- if (!webStyle2) return;
840
- settlePendingMotionOnFinish(mv, animate(node, webStyle2, transition));
841
- };
842
- var animateChangedValue = function (nextStyle, transition, mv) {
843
- if (seededInCurrentFrame.current && seededNode.current === node) {
844
- var queuedFrame = queuedAnimationFrames.current.get(mv);
845
- if (queuedFrame !== void 0) {
846
- cancelAnimationFrame(queuedFrame);
847
- }
848
- var frame = requestAnimationFrame(function () {
849
- if (queuedAnimationFrames.current.get(mv) !== frame) return;
850
- queuedAnimationFrames.current.delete(mv);
851
- if (hostRef.current === node) {
852
- animateNodeTo(nextStyle, transition, mv);
853
- } else {
854
- var onFinish = PendingMotionOnFinish.get(mv);
855
- PendingMotionOnFinish.delete(mv);
856
- onFinish === null || onFinish === void 0 ? void 0 : onFinish();
857
- }
858
- });
859
- queuedAnimationFrames.current.set(mv, frame);
860
- return;
861
- }
862
- animateNodeTo(nextStyle, transition, mv);
863
- };
864
- if (animatedStyle.motionValues) {
865
- var mvs = animatedStyle.motionValues;
866
- var styleForAll = function () {
867
- return animatedStyle.getStyle(...mvs.map(function (v) {
868
- return v.get();
869
- }));
870
- };
871
- var unsubs = mvs.map(function (mv) {
872
- return mv.on("change", function () {
873
- return animateChangedValue(styleForAll(), toTransition(MotionValueStrategy.get(mv)), mv);
874
- });
875
- });
876
- return function () {
877
- return unsubs.forEach(function (fn) {
878
- return fn();
879
- });
880
- };
881
- }
882
- var motionValue2 = animatedStyle.motionValue;
883
- if (!motionValue2) return;
884
- return motionValue2.on("change", function (value) {
885
- return animateChangedValue(animatedStyle.getStyle(value), toTransition(MotionValueStrategy.get(motionValue2)), motionValue2);
886
- });
887
- }, [animatedStyle]);
888
- return /* @__PURE__ */_jsx(Element, {
889
- ...transformedProps,
890
- ref: composedRefs
891
- });
892
- });
893
- Component["acceptRenderProp"] = true;
894
- return Component;
827
+ var isText = defaultTag === "span";
828
+ var Component = createRefComponent(function(propsIn, ref) {
829
+ var _hooks_usePropsTransform;
830
+ var { forwardedRef, animation, render = defaultTag, style, ...propsRest } = propsIn;
831
+ var [scope, animate] = useAnimateSSRSafe();
832
+ var hostRef = useRef(null);
833
+ var seededNode = useRef(null);
834
+ var seededInCurrentFrame = useRef(false);
835
+ var queuedAnimationFrames = useRef(/* @__PURE__ */ new WeakMap());
836
+ var composedRefs = useComposedRefs(forwardedRef, ref, hostRef, scope);
837
+ var stateRef = useRef(null);
838
+ if (!stateRef.current) {
839
+ stateRef.current = { get host() {
840
+ return hostRef.current;
841
+ } };
842
+ }
843
+ var [_, state] = useThemeWithState({});
844
+ var styles = Array.isArray(style) ? style : [style];
845
+ var [animatedStyle, nonAnimatedStyles] = (function() {
846
+ var animatedStyle2;
847
+ var nonAnimatedStyles2 = [];
848
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
849
+ try {
850
+ for (var _iterator = styles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
851
+ var style2 = _step.value;
852
+ if (style2.getStyle) {
853
+ animatedStyle2 = style2;
854
+ } else {
855
+ nonAnimatedStyles2.push(style2);
856
+ }
857
+ }
858
+ } catch (err) {
859
+ _didIteratorError = true;
860
+ _iteratorError = err;
861
+ } finally {
862
+ try {
863
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
864
+ _iterator.return();
865
+ }
866
+ } finally {
867
+ if (_didIteratorError) {
868
+ throw _iteratorError;
869
+ }
870
+ }
871
+ }
872
+ return [animatedStyle2, nonAnimatedStyles2];
873
+ })();
874
+ function getProps(props2) {
875
+ if (process.env.NODE_ENV === "development" && propsIn.debug === "profile" && typeof performance !== "undefined") {
876
+ performance.mark("tamagui-motion-style-split");
877
+ }
878
+ var out = getSplitStyles(props2, isText ? Text.staticConfig : View.staticConfig, state === null || state === void 0 ? void 0 : state.theme, state === null || state === void 0 ? void 0 : state.name, { unmounted: false }, {
879
+ isAnimated: false,
880
+ noClass: true,
881
+ resolveValues: "auto"
882
+ });
883
+ if (!out) {
884
+ return {};
885
+ }
886
+ if (out.viewProps.style) {
887
+ fixStyles(out.viewProps.style);
888
+ styleToCSS(out.viewProps.style);
889
+ }
890
+ return out.viewProps;
891
+ }
892
+ var resolvedAnimatedStyle = useMemo(function() {
893
+ if (!animatedStyle) return null;
894
+ var currentValues = animatedStyle.motionValues ? animatedStyle.motionValues.map(function(value) {
895
+ return value.get();
896
+ }) : animatedStyle.motionValue ? [animatedStyle.motionValue.get()] : [];
897
+ var initialSource = animatedStyle.getStyle(...currentValues);
898
+ var initialResolved = asStyleRecord(getProps({ style: initialSource }).style);
899
+ return {
900
+ initial: initialResolved,
901
+ resolve: compileAnimatedStyle(initialSource, initialResolved)
902
+ };
903
+ }, [
904
+ animatedStyle,
905
+ state === null || state === void 0 ? void 0 : state.theme,
906
+ state === null || state === void 0 ? void 0 : state.name
907
+ ]);
908
+ var memoRef = useRef(null);
909
+ var props;
910
+ var cached = memoRef.current;
911
+ if (cached && cached.theme === (state === null || state === void 0 ? void 0 : state.theme) && cached.themeName === (state === null || state === void 0 ? void 0 : state.name) && motionStylesEqual(cached.styles, nonAnimatedStyles) && motionPropsEqual(cached.propsRest, propsRest)) {
912
+ props = { ...cached.result };
913
+ for (var key in propsRest) {
914
+ var val = propsRest[key];
915
+ if (key === "children" || typeof val === "function") {
916
+ props[key] = val;
917
+ }
918
+ }
919
+ } else {
920
+ props = getProps({
921
+ ...propsRest,
922
+ style: nonAnimatedStyles
923
+ });
924
+ memoRef.current = {
925
+ propsRest,
926
+ styles: nonAnimatedStyles,
927
+ theme: state === null || state === void 0 ? void 0 : state.theme,
928
+ themeName: state === null || state === void 0 ? void 0 : state.name,
929
+ result: props
930
+ };
931
+ }
932
+ if (resolvedAnimatedStyle) {
933
+ props = {
934
+ ...props,
935
+ style: {
936
+ ...asStyleRecord(props.style),
937
+ ...resolvedAnimatedStyle.initial
938
+ }
939
+ };
940
+ }
941
+ var Element = render || "div";
942
+ var transformedProps = (_hooks_usePropsTransform = hooks.usePropsTransform) === null || _hooks_usePropsTransform === void 0 ? void 0 : _hooks_usePropsTransform.call(hooks, render, props, stateRef, false);
943
+ useIsomorphicLayoutEffect(function() {
944
+ if (!animatedStyle) return;
945
+ var node = hostRef.current;
946
+ if (node instanceof HTMLElement && seededNode.current !== node) {
947
+ var currentStyle = animatedStyle.motionValues ? animatedStyle.getStyle(...animatedStyle.motionValues.map(function(value) {
948
+ return value.get();
949
+ })) : animatedStyle.motionValue ? animatedStyle.getStyle(animatedStyle.motionValue.get()) : null;
950
+ var webStyle = currentStyle && (resolvedAnimatedStyle === null || resolvedAnimatedStyle === void 0 ? void 0 : resolvedAnimatedStyle.resolve(currentStyle));
951
+ if (webStyle) {
952
+ assignInlineStyles(node, webStyle);
953
+ seededNode.current = node;
954
+ seededInCurrentFrame.current = true;
955
+ requestAnimationFrame(function() {
956
+ if (seededNode.current === node) seededInCurrentFrame.current = false;
957
+ });
958
+ }
959
+ }
960
+ var toTransition = function(animationConfig) {
961
+ return (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "timing" ? {
962
+ type: "tween",
963
+ duration: (animationConfig.duration || 0) / 1e3
964
+ } : (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "direct" ? {
965
+ type: "tween",
966
+ duration: 0
967
+ } : {
968
+ type: "spring",
969
+ ...animationConfig
970
+ };
971
+ };
972
+ var animateNodeTo = function(nextStyle, transition, motionValue3) {
973
+ if (!(node instanceof HTMLElement) || hostRef.current !== node) return;
974
+ var webStyle2 = resolvedAnimatedStyle === null || resolvedAnimatedStyle === void 0 ? void 0 : resolvedAnimatedStyle.resolve(nextStyle);
975
+ if (!webStyle2) return;
976
+ settlePendingMotionOnFinish(motionValue3, animate(node, webStyle2, transition));
977
+ };
978
+ var animateChangedValue = function(nextStyle, transition, motionValue3) {
979
+ if (seededInCurrentFrame.current && seededNode.current === node) {
980
+ var queuedFrame = queuedAnimationFrames.current.get(motionValue3);
981
+ if (queuedFrame !== void 0) cancelAnimationFrame(queuedFrame);
982
+ var frame = requestAnimationFrame(function() {
983
+ if (queuedAnimationFrames.current.get(motionValue3) !== frame) return;
984
+ queuedAnimationFrames.current.delete(motionValue3);
985
+ if (hostRef.current === node) {
986
+ animateNodeTo(nextStyle, transition, motionValue3);
987
+ } else {
988
+ var onFinish = PendingMotionOnFinish.get(motionValue3);
989
+ PendingMotionOnFinish.delete(motionValue3);
990
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish();
991
+ }
992
+ });
993
+ queuedAnimationFrames.current.set(motionValue3, frame);
994
+ return;
995
+ }
996
+ animateNodeTo(nextStyle, transition, motionValue3);
997
+ };
998
+ if (animatedStyle.motionValues) {
999
+ var mvs = animatedStyle.motionValues;
1000
+ var styleForAll = function() {
1001
+ return animatedStyle.getStyle(...mvs.map(function(value) {
1002
+ return value.get();
1003
+ }));
1004
+ };
1005
+ var unsubs = mvs.map(function(mv) {
1006
+ return mv.on("change", function() {
1007
+ return animateChangedValue(styleForAll(), toTransition(MotionValueStrategy.get(mv)), mv);
1008
+ });
1009
+ });
1010
+ return function() {
1011
+ return unsubs.forEach(function(fn) {
1012
+ return fn();
1013
+ });
1014
+ };
1015
+ }
1016
+ var motionValue2 = animatedStyle.motionValue;
1017
+ if (!motionValue2) return;
1018
+ return motionValue2.on("change", function(value) {
1019
+ return animateChangedValue(animatedStyle.getStyle(value), toTransition(MotionValueStrategy.get(motionValue2)), motionValue2);
1020
+ });
1021
+ }, [animatedStyle, resolvedAnimatedStyle]);
1022
+ return /* @__PURE__ */ jsx(Element, {
1023
+ ...transformedProps,
1024
+ ref: composedRefs
1025
+ });
1026
+ });
1027
+ Component["acceptRenderProp"] = true;
1028
+ return Component;
895
1029
  }
896
1030
  function getDiff(previous, next) {
897
- if (!previous) {
898
- return next;
899
- }
900
- var diff = null;
901
- for (var key in next) {
902
- if (next[key] !== previous[key]) {
903
- diff || (diff = {});
904
- diff[key] = next[key];
905
- }
906
- }
907
- return diff;
1031
+ if (!previous) {
1032
+ return next;
1033
+ }
1034
+ var diff = null;
1035
+ for (var key in next) {
1036
+ if (next[key] !== previous[key]) {
1037
+ diff || (diff = {});
1038
+ diff[key] = next[key];
1039
+ }
1040
+ }
1041
+ return diff;
908
1042
  }
909
1043
  function fixTransparentColors(diff, previous, next) {
910
- var result = diff;
911
- for (var key in diff) {
912
- if (diff[key] === "transparent") {
913
- var fixed = "rgba(0, 0, 0, 0)";
914
- var candidates = [previous === null || previous === void 0 ? void 0 : previous[key], next === null || next === void 0 ? void 0 : next[key]];
915
- var _iteratorNormalCompletion = true,
916
- _didIteratorError = false,
917
- _iteratorError = void 0;
918
- try {
919
- for (var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
920
- var candidate = _step.value;
921
- if (typeof candidate === "string" && candidate !== "transparent") {
922
- var rgbaMatch = candidate.match(/^rgba?\(([^,]+),\s*([^,]+),\s*([^,)]+)/);
923
- if (rgbaMatch) {
924
- fixed = `rgba(${rgbaMatch[1]}, ${rgbaMatch[2]}, ${rgbaMatch[3]}, 0)`;
925
- break;
926
- }
927
- }
928
- }
929
- } catch (err) {
930
- _didIteratorError = true;
931
- _iteratorError = err;
932
- } finally {
933
- try {
934
- if (!_iteratorNormalCompletion && _iterator.return != null) {
935
- _iterator.return();
936
- }
937
- } finally {
938
- if (_didIteratorError) {
939
- throw _iteratorError;
940
- }
941
- }
942
- }
943
- if (result === diff) {
944
- result = {
945
- ...diff
946
- };
947
- }
948
- result[key] = fixed;
949
- }
950
- }
951
- return result;
1044
+ var result = diff;
1045
+ for (var key in diff) {
1046
+ if (diff[key] === "transparent") {
1047
+ var fixed = "rgba(0, 0, 0, 0)";
1048
+ var candidates = [previous === null || previous === void 0 ? void 0 : previous[key], next === null || next === void 0 ? void 0 : next[key]];
1049
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1050
+ try {
1051
+ for (var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
1052
+ var candidate = _step.value;
1053
+ if (typeof candidate === "string" && candidate !== "transparent") {
1054
+ var rgbaMatch = candidate.match(/^rgba?\(([^,]+),\s*([^,]+),\s*([^,)]+)/);
1055
+ if (rgbaMatch) {
1056
+ fixed = `rgba(${rgbaMatch[1]}, ${rgbaMatch[2]}, ${rgbaMatch[3]}, 0)`;
1057
+ break;
1058
+ }
1059
+ }
1060
+ }
1061
+ } catch (err) {
1062
+ _didIteratorError = true;
1063
+ _iteratorError = err;
1064
+ } finally {
1065
+ try {
1066
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1067
+ _iterator.return();
1068
+ }
1069
+ } finally {
1070
+ if (_didIteratorError) {
1071
+ throw _iteratorError;
1072
+ }
1073
+ }
1074
+ }
1075
+ if (result === diff) {
1076
+ result = { ...diff };
1077
+ }
1078
+ result[key] = fixed;
1079
+ }
1080
+ }
1081
+ return result;
952
1082
  }
1083
+
953
1084
  export { createAnimations, disableAnimationProps };
954
1085
  //# sourceMappingURL=createAnimations.native.js.map