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