@hanzogui/animations-motion 3.0.6 → 4.4.0

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.
@@ -5,211 +5,323 @@ import { fixStyles, getConfig, getSplitStyles, hooks, styleToCSS, Text, useCompo
5
5
  import { useAnimate, useMotionValue, useMotionValueEvent } from "motion/react";
6
6
  import React, { forwardRef, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
7
7
  function _instanceof(left, right) {
8
- return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof 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
+ }
9
13
  }
10
14
  function _type_of(obj) {
11
15
  "@swc/helpers - typeof";
12
16
 
13
- return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
17
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
14
18
  }
15
- var isServer = typeof window > "u";
19
+ var isServer = typeof window === "undefined";
16
20
  function useAnimateSSRSafe() {
17
- return isServer ? [useRef(null), function () {}] : useAnimate();
21
+ if (isServer) {
22
+ return [useRef(null), function () {}];
23
+ }
24
+ return useAnimate();
18
25
  }
19
26
  var MotionValueStrategy = /* @__PURE__ */new WeakMap();
27
+ var PendingMotionOnFinish = /* @__PURE__ */new WeakMap();
28
+ 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
+ });
37
+ }
20
38
  function createAnimations(animations) {
21
- var isHydratingGlobal,
22
- hydratingComponents = /* @__PURE__ */new Set();
39
+ var isHydratingGlobal;
40
+ var hydratingComponents = /* @__PURE__ */new Set();
23
41
  return {
24
42
  View: MotionView,
25
43
  Text: MotionText,
26
- isReactNative: !1,
44
+ isReactNative: false,
27
45
  inputStyle: "css",
28
46
  outputStyle: "inline",
29
- avoidReRenders: !0,
47
+ avoidReRenders: true,
30
48
  animations,
31
49
  usePresence,
32
50
  ResetPresence,
33
51
  onMount() {
34
- isHydratingGlobal = !1, hydratingComponents.forEach(function (cb) {
52
+ isHydratingGlobal = false;
53
+ hydratingComponents.forEach(function (cb) {
35
54
  return cb();
36
55
  });
37
56
  },
38
57
  useAnimations: function (animationProps) {
39
- isHydratingGlobal === void 0 && !getConfig().settings.disableSSR && (isHydratingGlobal = !0);
58
+ if (isHydratingGlobal === void 0 && !getConfig().settings.disableSSR) {
59
+ isHydratingGlobal = true;
60
+ }
40
61
  var {
41
- props,
42
- style,
43
- componentState,
44
- stateRef,
45
- useStyleEmitter,
46
- presence
47
- } = animationProps,
48
- animationKey = Array.isArray(props.transition) ? props.transition[0] : props.transition,
49
- isComponentHydrating = componentState.unmounted === !0,
50
- isMounting = componentState.unmounted === "should-enter",
51
- isEntering = !!componentState.unmounted,
52
- isExiting = presence?.[0] === !1,
53
- sendExitComplete = presence?.[1],
54
- refs = useRef(null);
55
- refs.current || (refs.current = {
56
- isFirstRender: !0,
57
- lastDoAnimate: null,
58
- lastDontAnimate: null,
59
- controls: null,
60
- lastAnimateAt: 0,
61
- disposed: !1,
62
- wasExiting: !1,
63
- isExiting: !1,
64
- sendExitComplete: void 0,
65
- animationState: "default",
66
- frozenExitTarget: null,
67
- exitCompleteScheduled: !1,
68
- wasEntering: !1
69
- });
62
+ props,
63
+ style,
64
+ componentState,
65
+ stateRef,
66
+ useStyleEmitter,
67
+ presence
68
+ } = animationProps;
69
+ var animationKey = Array.isArray(props.transition) ? props.transition[0] : props.transition;
70
+ var isComponentHydrating = componentState.unmounted === true;
71
+ var isMounting = componentState.unmounted === "should-enter";
72
+ var isEntering = !!componentState.unmounted;
73
+ var isExiting = (presence === null || presence === void 0 ? void 0 : presence[0]) === false;
74
+ var sendExitComplete = presence === null || presence === void 0 ? void 0 : presence[1];
75
+ var refs = useRef(null);
76
+ if (!refs.current) {
77
+ refs.current = {
78
+ isFirstRender: true,
79
+ lastDoAnimate: null,
80
+ lastDontAnimate: null,
81
+ controls: null,
82
+ lastAnimateAt: 0,
83
+ disposed: false,
84
+ wasExiting: false,
85
+ isExiting: false,
86
+ sendExitComplete: void 0,
87
+ animationState: "default",
88
+ frozenExitTarget: null,
89
+ exitCompleteScheduled: false,
90
+ wasEntering: false
91
+ };
92
+ }
70
93
  var justFinishedEntering = refs.current.wasEntering && !isEntering;
71
94
  useEffect(function () {
72
95
  refs.current.wasEntering = isEntering;
73
96
  });
74
- var animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default",
75
- disableAnimation = isComponentHydrating || isMounting || !animationKey,
76
- [scope, animate] = useAnimateSSRSafe();
77
- refs.current.isExiting = isExiting, refs.current.sendExitComplete = sendExitComplete, refs.current.animationState = animationState;
78
- var justStartedExiting = isExiting && !refs.current.wasExiting,
79
- justStoppedExiting = !isExiting && refs.current.wasExiting;
80
- (justStartedExiting || justStoppedExiting) && (refs.current.frozenExitTarget = null, refs.current.exitCompleteScheduled = !1), useEffect(function () {
97
+ var animationState = isExiting ? "exit" : isMounting || justFinishedEntering ? "enter" : "default";
98
+ var disableAnimation = isComponentHydrating || isMounting || !animationKey;
99
+ var [scope, animate] = useAnimateSSRSafe();
100
+ refs.current.isExiting = isExiting;
101
+ refs.current.sendExitComplete = sendExitComplete;
102
+ refs.current.animationState = animationState;
103
+ var justStartedExiting = isExiting && !refs.current.wasExiting;
104
+ var justStoppedExiting = !isExiting && refs.current.wasExiting;
105
+ if (justStartedExiting || justStoppedExiting) {
106
+ refs.current.frozenExitTarget = null;
107
+ refs.current.exitCompleteScheduled = false;
108
+ }
109
+ useEffect(function () {
81
110
  refs.current.wasExiting = isExiting;
82
111
  });
83
112
  var {
84
- dontAnimate = {},
85
- doAnimate,
86
- animationOptions
87
- } = getMotionAnimatedProps(props, style, disableAnimation, animationState),
88
- [firstRenderStyle] = useState(style);
89
- refs.current.isFirstRender && (refs.current.lastDontAnimate = firstRenderStyle);
113
+ dontAnimate = {},
114
+ doAnimate,
115
+ animationOptions
116
+ } = getMotionAnimatedProps(props, style, disableAnimation, animationState);
117
+ var [firstRenderStyle] = useState(style);
118
+ if (refs.current.isFirstRender) {
119
+ refs.current.lastDontAnimate = firstRenderStyle;
120
+ }
90
121
  var [isHydrating, setIsHydrating] = useState(isHydratingGlobal);
91
122
  useLayoutEffect(function () {
92
- return isHydratingGlobal && hydratingComponents.add(function () {
93
- setIsHydrating(!1);
94
- }), function () {
95
- refs.current.disposed = !0;
123
+ if (isHydratingGlobal) {
124
+ hydratingComponents.add(function () {
125
+ setIsHydrating(false);
126
+ });
127
+ }
128
+ return function () {
129
+ refs.current.disposed = true;
96
130
  };
97
131
  }, []);
98
132
  var flushAnimation = function (param) {
99
133
  var {
100
- doAnimate: doAnimateRaw = {},
101
- animationOptions: passedOptions = {},
102
- dontAnimate: dontAnimate2
103
- } = param,
104
- startedControls = null,
105
- isCurrentlyExiting = refs.current.isExiting,
106
- currentSendExitComplete = refs.current.sendExitComplete,
107
- doAnimate2 = doAnimateRaw;
108
- isCurrentlyExiting && refs.current.frozenExitTarget && (doAnimate2 = refs.current.frozenExitTarget);
109
- var _props_transition,
110
- animationOptions2 = isCurrentlyExiting && currentSendExitComplete ? getAnimationOptions((_props_transition = props.transition) !== null && _props_transition !== void 0 ? _props_transition : null, "exit") : passedOptions;
134
+ doAnimate: doAnimateRaw = {},
135
+ animationOptions: passedOptions = {},
136
+ dontAnimate: dontAnimate2
137
+ } = param;
138
+ var startedControls = null;
139
+ var isCurrentlyExiting = refs.current.isExiting;
140
+ var currentSendExitComplete = refs.current.sendExitComplete;
141
+ var doAnimate2 = doAnimateRaw;
142
+ if (isCurrentlyExiting && refs.current.frozenExitTarget) {
143
+ doAnimate2 = refs.current.frozenExitTarget;
144
+ }
145
+ var _props_transition;
146
+ var animationOptions2 = isCurrentlyExiting && currentSendExitComplete ? getAnimationOptions((_props_transition = props.transition) !== null && _props_transition !== void 0 ? _props_transition : null, "exit") : passedOptions;
111
147
  try {
112
148
  var node = stateRef.current.host;
113
- if (refs.current.isFirstRender && (refs.current.lastDontAnimate = null, refs.current.lastDoAnimate = null), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && (console.groupCollapsed(`[motion] animate (${JSON.stringify(getDiff(refs.current.lastDoAnimate, doAnimate2), null, 2)})`), console.info({
114
- props,
115
- componentState,
116
- doAnimate: doAnimate2,
117
- dontAnimate: dontAnimate2,
118
- animationOptions: animationOptions2,
119
- animationProps,
120
- lastDoAnimate: {
121
- ...refs.current.lastDoAnimate
122
- },
123
- lastDontAnimate: {
124
- ...refs.current.lastDontAnimate
125
- },
126
- isExiting,
127
- style,
128
- node
129
- }), console.groupCollapsed("trace >"), console.trace(), console.groupEnd(), console.groupEnd()), !_instanceof(node, HTMLElement)) return;
149
+ if (refs.current.isFirstRender) {
150
+ refs.current.lastDontAnimate = null;
151
+ refs.current.lastDoAnimate = null;
152
+ }
153
+ if (process.env.NODE_ENV === "development") {
154
+ if (props["debug"] && props["debug"] !== "profile") {
155
+ console.groupCollapsed(`[motion] animate (${JSON.stringify(getDiff(refs.current.lastDoAnimate, doAnimate2), null, 2)})`);
156
+ console.info({
157
+ props,
158
+ componentState,
159
+ doAnimate: doAnimate2,
160
+ dontAnimate: dontAnimate2,
161
+ animationOptions: animationOptions2,
162
+ animationProps,
163
+ lastDoAnimate: {
164
+ ...refs.current.lastDoAnimate
165
+ },
166
+ lastDontAnimate: {
167
+ ...refs.current.lastDontAnimate
168
+ },
169
+ isExiting,
170
+ style,
171
+ node
172
+ });
173
+ console.groupCollapsed(`trace >`);
174
+ console.trace();
175
+ console.groupEnd();
176
+ console.groupEnd();
177
+ }
178
+ }
179
+ if (!_instanceof(node, HTMLElement)) {
180
+ return;
181
+ }
130
182
  var prevDont = refs.current.lastDontAnimate;
131
- if (dontAnimate2) if (prevDont) {
132
- removeRemovedStyles(prevDont, dontAnimate2, node, doAnimate2);
133
- var changed = getDiff(prevDont, dontAnimate2);
134
- changed && Object.assign(node.style, changed);
135
- } else Object.assign(node.style, dontAnimate2);
183
+ if (dontAnimate2) {
184
+ if (prevDont) {
185
+ removeRemovedStyles(prevDont, dontAnimate2, node, doAnimate2);
186
+ var changed = getDiff(prevDont, dontAnimate2);
187
+ if (changed) {
188
+ Object.assign(node.style, changed);
189
+ }
190
+ } else {
191
+ Object.assign(node.style, dontAnimate2);
192
+ }
193
+ }
136
194
  if (doAnimate2) {
137
- if (prevDont) for (var key in prevDont) key in doAnimate2 && (node.style[key] = prevDont[key], refs.current.lastDoAnimate && (refs.current.lastDoAnimate[key] = prevDont[key]));
195
+ if (prevDont) {
196
+ for (var key in prevDont) {
197
+ if (key in doAnimate2) {
198
+ node.style[key] = prevDont[key];
199
+ if (refs.current.lastDoAnimate) {
200
+ refs.current.lastDoAnimate[key] = prevDont[key];
201
+ }
202
+ }
203
+ }
204
+ }
138
205
  var lastAnimated = refs.current.lastDoAnimate;
139
- lastAnimated && removeRemovedStyles(lastAnimated, doAnimate2, node, dontAnimate2);
206
+ if (lastAnimated) {
207
+ removeRemovedStyles(lastAnimated, doAnimate2, node, dontAnimate2);
208
+ }
140
209
  var diff = getDiff(refs.current.lastDoAnimate, doAnimate2);
141
210
  if (diff) {
142
- isCurrentlyExiting && !refs.current.frozenExitTarget && (refs.current.frozenExitTarget = {
143
- ...doAnimate2
144
- });
145
- var isPopperPosition = node.hasAttribute("data-popper-animate-position"),
146
- midFlightValues = null;
211
+ if (isCurrentlyExiting && !refs.current.frozenExitTarget) {
212
+ refs.current.frozenExitTarget = {
213
+ ...doAnimate2
214
+ };
215
+ }
216
+ var isPopperPosition = node.hasAttribute("data-popper-animate-position");
217
+ var midFlightValues = null;
147
218
  if (refs.current.controls) {
148
219
  try {
149
220
  var computed = getComputedStyle(node);
150
221
  midFlightValues = {};
151
222
  for (var key1 in diff) {
152
223
  var val = computed[key1];
153
- val !== void 0 && val !== "" && (midFlightValues[key1] = val);
224
+ if (val !== void 0 && val !== "") {
225
+ midFlightValues[key1] = val;
226
+ }
227
+ }
228
+ } catch (e) {}
229
+ if (isCurrentlyExiting) {
230
+ refs.current.controls.stop();
231
+ }
232
+ if (midFlightValues) {
233
+ for (var key2 in midFlightValues) {
234
+ ;
235
+ node.style[key2] = midFlightValues[key2];
154
236
  }
155
- } catch {}
156
- if (isCurrentlyExiting && refs.current.controls.stop(), midFlightValues) for (var key2 in midFlightValues) node.style[key2] = midFlightValues[key2];
237
+ }
157
238
  if (isPopperPosition) {
158
- var anims = node.getAnimations(),
159
- _iteratorNormalCompletion = !0,
160
- _didIteratorError = !1,
239
+ var anims = node.getAnimations();
240
+ var _iteratorNormalCompletion = true,
241
+ _didIteratorError = false,
161
242
  _iteratorError = void 0;
162
243
  try {
163
- for (var _iterator = anims[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
244
+ for (var _iterator = anims[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
164
245
  var anim = _step.value;
165
246
  anim.cancel();
166
247
  }
167
248
  } catch (err) {
168
- _didIteratorError = !0, _iteratorError = err;
249
+ _didIteratorError = true;
250
+ _iteratorError = err;
169
251
  } finally {
170
252
  try {
171
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
253
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
254
+ _iterator.return();
255
+ }
172
256
  } finally {
173
- if (_didIteratorError) throw _iteratorError;
257
+ if (_didIteratorError) {
258
+ throw _iteratorError;
259
+ }
174
260
  }
175
261
  }
176
262
  }
177
263
  }
178
264
  var fixedDiff = fixTransparentColors(diff, refs.current.lastDoAnimate, doAnimate2);
179
- midFlightValues?.transform && fixedDiff.transform && (fixedDiff.transform = [midFlightValues.transform, fixedDiff.transform]), startedControls = animate(scope.current, fixedDiff, animationOptions2), refs.current.controls = startedControls, refs.current.lastAnimateAt = Date.now();
265
+ if ((midFlightValues === null || midFlightValues === void 0 ? void 0 : midFlightValues.transform) && fixedDiff.transform) {
266
+ fixedDiff.transform = [midFlightValues.transform, fixedDiff.transform];
267
+ }
268
+ startedControls = animate(scope.current, fixedDiff, animationOptions2);
269
+ refs.current.controls = startedControls;
270
+ refs.current.lastAnimateAt = Date.now();
180
271
  }
181
272
  }
182
273
  refs.current.lastDontAnimate = dontAnimate2 ? {
183
274
  ...dontAnimate2
184
- } : {}, refs.current.lastDoAnimate = doAnimate2 ? {
275
+ } : {};
276
+ refs.current.lastDoAnimate = doAnimate2 ? {
185
277
  ...doAnimate2
186
278
  } : {};
187
279
  } finally {
188
- isCurrentlyExiting && currentSendExitComplete && (startedControls ? (refs.current.exitCompleteScheduled = !0, startedControls.finished.then(function () {
189
- refs.current.isExiting && currentSendExitComplete();
190
- }).catch(function () {
191
- refs.current.isExiting && currentSendExitComplete();
192
- })) : refs.current.exitCompleteScheduled || currentSendExitComplete());
280
+ if (isCurrentlyExiting && currentSendExitComplete) {
281
+ if (startedControls) {
282
+ refs.current.exitCompleteScheduled = true;
283
+ startedControls.finished.then(function () {
284
+ if (refs.current.isExiting) {
285
+ currentSendExitComplete();
286
+ }
287
+ }).catch(function () {
288
+ if (refs.current.isExiting) {
289
+ currentSendExitComplete();
290
+ }
291
+ });
292
+ } else if (!refs.current.exitCompleteScheduled) {
293
+ currentSendExitComplete();
294
+ }
295
+ }
193
296
  }
194
297
  };
195
- return useStyleEmitter?.(function (nextStyle, effectiveTransition) {
298
+ useStyleEmitter === null || useStyleEmitter === void 0 ? void 0 : useStyleEmitter(function (nextStyle, effectiveTransition) {
196
299
  var _$animationProps = getMotionAnimatedProps(props, nextStyle, disableAnimation, refs.current.animationState, effectiveTransition);
197
300
  flushAnimation(_$animationProps);
198
- }), useIsomorphicLayoutEffect(function () {
301
+ });
302
+ useIsomorphicLayoutEffect(function () {
199
303
  if (refs.current.isFirstRender) {
200
- if (refs.current.isFirstRender = !1, isHydrating) {
201
- doAnimate && Object.keys(doAnimate).length > 0 ? refs.current.lastDoAnimate = {
202
- ...doAnimate
203
- } : refs.current.lastDoAnimate = dontAnimate ? {
204
- ...dontAnimate
205
- } : {}, refs.current.lastDontAnimate = dontAnimate ? {
304
+ refs.current.isFirstRender = false;
305
+ if (isHydrating) {
306
+ if (doAnimate && Object.keys(doAnimate).length > 0) {
307
+ refs.current.lastDoAnimate = {
308
+ ...doAnimate
309
+ };
310
+ } else {
311
+ refs.current.lastDoAnimate = dontAnimate ? {
312
+ ...dontAnimate
313
+ } : {};
314
+ }
315
+ refs.current.lastDontAnimate = dontAnimate ? {
206
316
  ...dontAnimate
207
- } : {}, refs.current.lastAnimateAt = Date.now();
317
+ } : {};
318
+ refs.current.lastAnimateAt = Date.now();
208
319
  return;
209
320
  }
210
321
  refs.current.lastDontAnimate = dontAnimate ? {
211
322
  ...dontAnimate
212
- } : {}, refs.current.lastDoAnimate = doAnimate ? {
323
+ } : {};
324
+ refs.current.lastDoAnimate = doAnimate ? {
213
325
  ...doAnimate
214
326
  } : {};
215
327
  return;
@@ -219,16 +331,24 @@ function createAnimations(animations) {
219
331
  dontAnimate,
220
332
  animationOptions
221
333
  });
222
- }, [style, isExiting, disableAnimation]), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && (console.groupCollapsed("[motion] render"), console.info({
223
- style,
224
- doAnimate,
225
- dontAnimate,
226
- scope,
227
- animationOptions,
228
- isExiting,
229
- isFirstRender: refs.current.isFirstRender,
230
- animationProps
231
- }), console.groupEnd()), {
334
+ }, [style, isExiting, disableAnimation]);
335
+ if (process.env.NODE_ENV === "development") {
336
+ if (props["debug"] && props["debug"] !== "profile") {
337
+ console.groupCollapsed(`[motion] render`);
338
+ console.info({
339
+ style,
340
+ doAnimate,
341
+ dontAnimate,
342
+ scope,
343
+ animationOptions,
344
+ isExiting,
345
+ isFirstRender: refs.current.isFirstRender,
346
+ animationProps
347
+ });
348
+ console.groupEnd();
349
+ }
350
+ }
351
+ return {
232
352
  style: firstRenderStyle,
233
353
  ref: scope,
234
354
  render: "div"
@@ -249,14 +369,24 @@ function createAnimations(animations) {
249
369
  type: "spring"
250
370
  },
251
371
  onFinish = arguments.length > 2 ? arguments[2] : void 0;
252
- if (config.type === "direct") MotionValueStrategy.set(motionValue, {
253
- type: "direct"
254
- }), motionValue.set(next), onFinish?.();else {
255
- if (MotionValueStrategy.set(motionValue, config), onFinish) var unsubscribe = motionValue.on("change", function (value) {
256
- Math.abs(value - next) < 0.01 && (unsubscribe(), onFinish());
372
+ if (config.type === "direct") {
373
+ MotionValueStrategy.set(motionValue, {
374
+ type: "direct"
257
375
  });
258
376
  motionValue.set(next);
377
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish();
378
+ return;
259
379
  }
380
+ MotionValueStrategy.set(motionValue, config);
381
+ if (onFinish) {
382
+ var prior = PendingMotionOnFinish.get(motionValue);
383
+ if (prior) {
384
+ PendingMotionOnFinish.delete(motionValue);
385
+ prior();
386
+ }
387
+ PendingMotionOnFinish.set(motionValue, onFinish);
388
+ }
389
+ motionValue.set(next);
260
390
  },
261
391
  stop() {
262
392
  motionValue.stop();
@@ -266,15 +396,16 @@ function createAnimations(animations) {
266
396
  },
267
397
  useAnimatedNumberReaction(param, onValue) {
268
398
  var {
269
- value
270
- } = param,
271
- instance = value.getInstance();
399
+ value
400
+ } = param;
401
+ var instance = value.getInstance();
272
402
  useMotionValueEvent(instance, "change", onValue);
273
403
  },
274
404
  useAnimatedNumberStyle(val, getStyleProp) {
275
- var motionValue = val.getInstance(),
276
- getStyleRef = useRef(getStyleProp);
277
- return getStyleRef.current = getStyleProp, useMemo(function () {
405
+ var motionValue = val.getInstance();
406
+ var getStyleRef = useRef(getStyleProp);
407
+ getStyleRef.current = getStyleProp;
408
+ return useMemo(function () {
278
409
  return {
279
410
  getStyle: function (cur) {
280
411
  return getStyleRef.current(cur);
@@ -282,22 +413,48 @@ function createAnimations(animations) {
282
413
  motionValue
283
414
  };
284
415
  }, []);
416
+ },
417
+ useAnimatedNumbersStyle(vals, getStyleProp) {
418
+ var motionValues = vals.map(function (v) {
419
+ return v.getInstance();
420
+ });
421
+ var getStyleRef = useRef(getStyleProp);
422
+ getStyleRef.current = getStyleProp;
423
+ return useMemo(function () {
424
+ return {
425
+ getStyle: function () {
426
+ for (var _len = arguments.length, currentValues = new Array(_len), _key = 0; _key < _len; _key++) {
427
+ currentValues[_key] = arguments[_key];
428
+ }
429
+ return getStyleRef.current(...currentValues);
430
+ },
431
+ motionValues
432
+ };
433
+ }, []);
285
434
  }
286
435
  };
287
436
  function getMotionAnimatedProps(props, style, disable) {
288
437
  var animationState = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "default",
289
438
  transitionOverride = arguments.length > 4 ? arguments[4] : void 0;
290
- if (disable) return {
291
- dontAnimate: style
292
- };
293
- var _ref,
294
- animationOptions = getAnimationOptions((_ref = transitionOverride ?? props.transition) !== null && _ref !== void 0 ? _ref : null, animationState),
295
- dontAnimate,
296
- doAnimate,
297
- animateOnly = props.animateOnly;
439
+ if (disable) {
440
+ return {
441
+ dontAnimate: style
442
+ };
443
+ }
444
+ var _ref;
445
+ var animationOptions = getAnimationOptions((_ref = transitionOverride !== null && transitionOverride !== void 0 ? transitionOverride : props.transition) !== null && _ref !== void 0 ? _ref : null, animationState);
446
+ var dontAnimate;
447
+ var doAnimate;
448
+ var animateOnly = props.animateOnly;
298
449
  for (var key in style) {
299
450
  var value = style[key];
300
- disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key) ? (dontAnimate || (dontAnimate = {}), dontAnimate[key] = value) : (doAnimate || (doAnimate = {}), doAnimate[key] = value);
451
+ if (disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key)) {
452
+ dontAnimate || (dontAnimate = {});
453
+ dontAnimate[key] = value;
454
+ } else {
455
+ doAnimate || (doAnimate = {});
456
+ doAnimate[key] = value;
457
+ }
301
458
  }
302
459
  return {
303
460
  dontAnimate,
@@ -306,31 +463,51 @@ function createAnimations(animations) {
306
463
  };
307
464
  }
308
465
  function getAnimationOptions(transitionProp) {
309
- var animationState = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "default",
310
- normalized = normalizeTransition(transitionProp),
311
- effectiveKey = getEffectiveAnimation(normalized, animationState);
312
- !effectiveKey && animationState === "default" && (effectiveKey = normalized.enter || normalized.exit || null);
466
+ var animationState = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "default";
467
+ var normalized = normalizeTransition(transitionProp);
468
+ var effectiveKey = getEffectiveAnimation(normalized, animationState);
469
+ if (!effectiveKey && animationState === "default") {
470
+ effectiveKey = normalized.enter || normalized.exit || null;
471
+ }
313
472
  var globalConfigOverride = normalized.config ? {
314
473
  ...normalized.config
315
474
  } : void 0;
316
- if (!effectiveKey && Object.keys(normalized.properties).length === 0 && !globalConfigOverride) return {};
317
- var defaultConfig = effectiveKey ? withInferredType(animations[effectiveKey]) : null,
318
- delay = normalized.delay,
319
- result = {};
320
- defaultConfig && Object.assign(result, defaultConfig), globalConfigOverride && (Object.assign(result, globalConfigOverride), result.type === void 0 && result.duration !== void 0 && result.damping === void 0 && result.stiffness === void 0 && result.mass === void 0 && (result.type = "tween")), delay && (result.delay = delay), (defaultConfig || globalConfigOverride || delay) && (result.default = {
321
- ...defaultConfig,
322
- ...globalConfigOverride,
323
- ...(delay ? {
324
- delay
325
- } : null)
326
- });
327
- var _iteratorNormalCompletion = !0,
328
- _didIteratorError = !1,
475
+ if (!effectiveKey && Object.keys(normalized.properties).length === 0 && !globalConfigOverride) {
476
+ return {};
477
+ }
478
+ var defaultConfig = effectiveKey ? withInferredType(animations[effectiveKey]) : null;
479
+ var delay = normalized.delay;
480
+ var result = {};
481
+ if (defaultConfig) {
482
+ Object.assign(result, defaultConfig);
483
+ }
484
+ if (globalConfigOverride) {
485
+ Object.assign(result, globalConfigOverride);
486
+ if (result.type === void 0 && result.duration !== void 0 && result.damping === void 0 && result.stiffness === void 0 && result.mass === void 0) {
487
+ result.type = "tween";
488
+ }
489
+ }
490
+ if (delay) {
491
+ result.delay = delay;
492
+ }
493
+ if (defaultConfig || globalConfigOverride || delay) {
494
+ result.default = {
495
+ ...defaultConfig,
496
+ ...globalConfigOverride,
497
+ ...(delay ? {
498
+ delay
499
+ } : null)
500
+ };
501
+ }
502
+ var _iteratorNormalCompletion = true,
503
+ _didIteratorError = false,
329
504
  _iteratorError = void 0;
330
505
  try {
331
- for (var _iterator = Object.entries(normalized.properties)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
506
+ for (var _iterator = Object.entries(normalized.properties)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
332
507
  var [propName, animationNameOrConfig] = _step.value;
333
- if (typeof animationNameOrConfig == "string") result[propName] = withInferredType(animations[animationNameOrConfig]);else if (animationNameOrConfig && (typeof animationNameOrConfig > "u" ? "undefined" : _type_of(animationNameOrConfig)) === "object") {
508
+ if (typeof animationNameOrConfig === "string") {
509
+ result[propName] = withInferredType(animations[animationNameOrConfig]);
510
+ } else if (animationNameOrConfig && (typeof animationNameOrConfig === "undefined" ? "undefined" : _type_of(animationNameOrConfig)) === "object") {
334
511
  var baseConfig = animationNameOrConfig.type ? withInferredType(animations[animationNameOrConfig.type]) : defaultConfig;
335
512
  result[propName] = {
336
513
  ...baseConfig,
@@ -339,23 +516,35 @@ function createAnimations(animations) {
339
516
  }
340
517
  }
341
518
  } catch (err) {
342
- _didIteratorError = !0, _iteratorError = err;
519
+ _didIteratorError = true;
520
+ _iteratorError = err;
343
521
  } finally {
344
522
  try {
345
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
523
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
524
+ _iterator.return();
525
+ }
346
526
  } finally {
347
- if (_didIteratorError) throw _iteratorError;
527
+ if (_didIteratorError) {
528
+ throw _iteratorError;
529
+ }
530
+ }
531
+ }
532
+ convertMsToS(result);
533
+ convertMsToS(result.default);
534
+ for (var key in result) {
535
+ if (key !== "default" && _type_of(result[key]) === "object") {
536
+ convertMsToS(result[key]);
348
537
  }
349
538
  }
350
- convertMsToS(result), convertMsToS(result.default);
351
- for (var key in result) key !== "default" && _type_of(result[key]) === "object" && convertMsToS(result[key]);
352
539
  return result;
353
540
  }
354
541
  }
355
542
  function withInferredType(config) {
356
- if (!config) return {
357
- type: "spring"
358
- };
543
+ if (!config) {
544
+ return {
545
+ type: "spring"
546
+ };
547
+ }
359
548
  var isTimingBased = config.duration !== void 0 && config.damping === void 0 && config.stiffness === void 0 && config.mass === void 0;
360
549
  return {
361
550
  type: isTimingBased ? "tween" : "spring",
@@ -363,146 +552,229 @@ function withInferredType(config) {
363
552
  };
364
553
  }
365
554
  function convertMsToS(config) {
366
- if (config && (typeof config.delay == "number" && (config.delay = config.delay / 1e3), typeof config.duration == "number")) {
555
+ if (!config) return;
556
+ if (typeof config.delay === "number") config.delay = config.delay / 1e3;
557
+ if (typeof config.duration === "number") {
367
558
  var isTimingBased = config.type === "tween" || config.type === void 0 && config.damping === void 0 && config.stiffness === void 0 && config.mass === void 0;
368
- isTimingBased && (config.duration = config.duration / 1e3);
559
+ if (isTimingBased) {
560
+ config.duration = config.duration / 1e3;
561
+ }
369
562
  }
370
563
  }
371
564
  function removeRemovedStyles(prev, next, node, dontClearIfIn) {
372
- for (var key in prev) if (!(key in next)) {
373
- if (dontClearIfIn && key in dontClearIfIn) continue;
374
- node.style[key] = "";
565
+ for (var key in prev) {
566
+ if (!(key in next)) {
567
+ if (dontClearIfIn && key in dontClearIfIn) {
568
+ continue;
569
+ }
570
+ node.style[key] = "";
571
+ }
375
572
  }
376
573
  }
377
- var disableAnimationProps = /* @__PURE__ */new Set(["alignContent", "alignItems", "boxSizing", "contain", "containerType", "display", "flexBasis", "flexDirection", "fontFamily", "justifyContent", "overflow", "overflowX", "overflowY", "pointerEvents", "position", "textWrap", "userSelect"]),
378
- MotionView = createMotionView("div"),
379
- MotionText = createMotionView("span");
574
+ var disableAnimationProps = /* @__PURE__ */new Set(["alignContent", "alignItems", "boxSizing", "contain", "containerType", "display", "flexBasis", "flexDirection", "fontFamily", "justifyContent", "overflow", "overflowX", "overflowY", "pointerEvents", "position", "textWrap", "userSelect"]);
575
+ var MotionView = createMotionView("div");
576
+ var MotionText = createMotionView("span");
380
577
  function createMotionView(defaultTag) {
381
- var isText = defaultTag === "span",
382
- Component = /* @__PURE__ */forwardRef(function (propsIn, ref) {
383
- var _hooks_usePropsTransform,
384
- {
385
- forwardedRef,
386
- animation,
387
- render = defaultTag,
388
- style,
389
- ...propsRest
390
- } = propsIn,
391
- [scope, animate] = useAnimateSSRSafe(),
392
- hostRef = useRef(null),
393
- composedRefs = useComposedRefs(forwardedRef, ref, hostRef, scope),
394
- stateRef = useRef(null);
395
- stateRef.current || (stateRef.current = {
578
+ var isText = defaultTag === "span";
579
+ var Component = /* @__PURE__ */forwardRef(function (propsIn, ref) {
580
+ var _hooks_usePropsTransform;
581
+ var {
582
+ forwardedRef,
583
+ animation,
584
+ render = defaultTag,
585
+ style,
586
+ ...propsRest
587
+ } = propsIn;
588
+ var [scope, animate] = useAnimateSSRSafe();
589
+ var hostRef = useRef(null);
590
+ var composedRefs = useComposedRefs(forwardedRef, ref, hostRef, scope);
591
+ var stateRef = useRef(null);
592
+ if (!stateRef.current) {
593
+ stateRef.current = {
396
594
  get host() {
397
595
  return hostRef.current;
398
596
  }
399
- });
400
- var [_, state] = useThemeWithState({}),
401
- styles = Array.isArray(style) ? style : [style],
402
- [animatedStyle, nonAnimatedStyles] = function () {
403
- var animatedStyle2,
404
- nonAnimatedStyles2 = [],
405
- _iteratorNormalCompletion = !0,
406
- _didIteratorError = !1,
407
- _iteratorError = void 0;
408
- try {
409
- for (var _iterator = styles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
410
- var style2 = _step.value;
411
- style2.getStyle ? animatedStyle2 = style2 : nonAnimatedStyles2.push(style2);
412
- }
413
- } catch (err) {
414
- _didIteratorError = !0, _iteratorError = err;
415
- } finally {
416
- try {
417
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
418
- } finally {
419
- if (_didIteratorError) throw _iteratorError;
420
- }
597
+ };
598
+ }
599
+ var [_, state] = useThemeWithState({});
600
+ var styles = Array.isArray(style) ? style : [style];
601
+ var [animatedStyle, nonAnimatedStyles] = function () {
602
+ var animatedStyle2;
603
+ var nonAnimatedStyles2 = [];
604
+ var _iteratorNormalCompletion = true,
605
+ _didIteratorError = false,
606
+ _iteratorError = void 0;
607
+ try {
608
+ for (var _iterator = styles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
609
+ var style2 = _step.value;
610
+ if (style2.getStyle) {
611
+ animatedStyle2 = style2;
612
+ } else {
613
+ nonAnimatedStyles2.push(style2);
421
614
  }
422
- return [animatedStyle2, nonAnimatedStyles2];
423
- }();
424
- function getProps(props2) {
425
- var out = getSplitStyles(props2, isText ? Text.staticConfig : View.staticConfig, state?.theme, state?.name, {
426
- unmounted: !1
427
- }, {
428
- isAnimated: !1,
429
- noClass: !0,
430
- resolveValues: "auto"
431
- });
432
- return out ? (out.viewProps.style && (fixStyles(out.viewProps.style), styleToCSS(out.viewProps.style)), out.viewProps) : {};
615
+ }
616
+ } catch (err) {
617
+ _didIteratorError = true;
618
+ _iteratorError = err;
619
+ } finally {
620
+ try {
621
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
622
+ _iterator.return();
623
+ }
624
+ } finally {
625
+ if (_didIteratorError) {
626
+ throw _iteratorError;
627
+ }
628
+ }
433
629
  }
434
- var props = getProps({
435
- ...propsRest,
436
- style: nonAnimatedStyles
437
- }),
438
- Element = render || "div",
439
- transformedProps = (_hooks_usePropsTransform = hooks.usePropsTransform) === null || _hooks_usePropsTransform === void 0 ? void 0 : _hooks_usePropsTransform.call(hooks, render, props, stateRef, !1);
440
- return useEffect(function () {
441
- if (animatedStyle) return animatedStyle.motionValue.on("change", function (value) {
442
- var nextStyle = animatedStyle.getStyle(value),
443
- animationConfig = MotionValueStrategy.get(animatedStyle.motionValue),
444
- node = hostRef.current,
445
- webStyle = getProps({
630
+ return [animatedStyle2, nonAnimatedStyles2];
631
+ }();
632
+ function getProps(props2) {
633
+ 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, {
634
+ unmounted: false
635
+ }, {
636
+ isAnimated: false,
637
+ noClass: true,
638
+ resolveValues: "auto"
639
+ });
640
+ if (!out) {
641
+ return {};
642
+ }
643
+ if (out.viewProps.style) {
644
+ fixStyles(out.viewProps.style);
645
+ styleToCSS(out.viewProps.style);
646
+ }
647
+ return out.viewProps;
648
+ }
649
+ var props = getProps({
650
+ ...propsRest,
651
+ style: nonAnimatedStyles
652
+ });
653
+ var Element = render || "div";
654
+ var transformedProps = (_hooks_usePropsTransform = hooks.usePropsTransform) === null || _hooks_usePropsTransform === void 0 ? void 0 : _hooks_usePropsTransform.call(hooks, render, props, stateRef, false);
655
+ useEffect(function () {
656
+ if (!animatedStyle) return;
657
+ if (animatedStyle.motionValues) {
658
+ var mvs = animatedStyle.motionValues;
659
+ var unsubs = mvs.map(function (mv) {
660
+ return mv.on("change", function () {
661
+ var currentValues = mvs.map(function (v) {
662
+ return v.get();
663
+ });
664
+ var nextStyle = animatedStyle.getStyle(...currentValues);
665
+ var animationConfig = MotionValueStrategy.get(mv);
666
+ var node = hostRef.current;
667
+ var webStyle = getProps({
446
668
  style: nextStyle
447
669
  }).style;
448
- if (webStyle && _instanceof(node, HTMLElement)) {
449
- var motionAnimationConfig = animationConfig?.type === "timing" ? {
450
- type: "tween",
451
- duration: (animationConfig?.duration || 0) / 1e3
452
- } : animationConfig?.type === "direct" ? {
453
- type: "tween",
454
- duration: 0
455
- } : {
456
- type: "spring",
457
- ...animationConfig
458
- };
459
- animate(node, webStyle, motionAnimationConfig);
460
- }
670
+ if (webStyle && _instanceof(node, HTMLElement)) {
671
+ var motionAnimationConfig = (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "timing" ? {
672
+ type: "tween",
673
+ duration: ((animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.duration) || 0) / 1e3
674
+ } : (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "direct" ? {
675
+ type: "tween",
676
+ duration: 0
677
+ } : {
678
+ type: "spring",
679
+ ...animationConfig
680
+ };
681
+ var controls = animate(node, webStyle, motionAnimationConfig);
682
+ settlePendingMotionOnFinish(mv, controls);
683
+ }
684
+ });
461
685
  });
462
- }, [animatedStyle]), /* @__PURE__ */_jsx(Element, {
463
- ...transformedProps,
464
- ref: composedRefs
686
+ return function () {
687
+ return unsubs.forEach(function (fn) {
688
+ return fn();
689
+ });
690
+ };
691
+ }
692
+ if (!animatedStyle.motionValue) return;
693
+ return animatedStyle.motionValue.on("change", function (value) {
694
+ var nextStyle = animatedStyle.getStyle(value);
695
+ var animationConfig = MotionValueStrategy.get(animatedStyle.motionValue);
696
+ var node = hostRef.current;
697
+ var webStyle = getProps({
698
+ style: nextStyle
699
+ }).style;
700
+ if (webStyle && _instanceof(node, HTMLElement)) {
701
+ var motionAnimationConfig = (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "timing" ? {
702
+ type: "tween",
703
+ duration: ((animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.duration) || 0) / 1e3
704
+ } : (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.type) === "direct" ? {
705
+ type: "tween",
706
+ duration: 0
707
+ } : {
708
+ type: "spring",
709
+ ...animationConfig
710
+ };
711
+ var controls = animate(node, webStyle, motionAnimationConfig);
712
+ settlePendingMotionOnFinish(animatedStyle.motionValue, controls);
713
+ }
465
714
  });
715
+ }, [animatedStyle]);
716
+ return /* @__PURE__ */_jsx(Element, {
717
+ ...transformedProps,
718
+ ref: composedRefs
466
719
  });
467
- return Component.acceptRenderProp = !0, Component;
720
+ });
721
+ Component["acceptRenderProp"] = true;
722
+ return Component;
468
723
  }
469
724
  function getDiff(previous, next) {
470
- if (!previous) return next;
725
+ if (!previous) {
726
+ return next;
727
+ }
471
728
  var diff = null;
472
- for (var key in next) next[key] !== previous[key] && (diff || (diff = {}), diff[key] = next[key]);
729
+ for (var key in next) {
730
+ if (next[key] !== previous[key]) {
731
+ diff || (diff = {});
732
+ diff[key] = next[key];
733
+ }
734
+ }
473
735
  return diff;
474
736
  }
475
737
  function fixTransparentColors(diff, previous, next) {
476
738
  var result = diff;
477
- for (var key in diff) if (diff[key] === "transparent") {
478
- var fixed = "rgba(0, 0, 0, 0)",
479
- candidates = [previous?.[key], next?.[key]],
480
- _iteratorNormalCompletion = !0,
481
- _didIteratorError = !1,
482
- _iteratorError = void 0;
483
- try {
484
- for (var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
485
- var candidate = _step.value;
486
- if (typeof candidate == "string" && candidate !== "transparent") {
487
- var rgbaMatch = candidate.match(/^rgba?\(([^,]+),\s*([^,]+),\s*([^,)]+)/);
488
- if (rgbaMatch) {
489
- fixed = `rgba(${rgbaMatch[1]}, ${rgbaMatch[2]}, ${rgbaMatch[3]}, 0)`;
490
- break;
739
+ for (var key in diff) {
740
+ if (diff[key] === "transparent") {
741
+ var fixed = "rgba(0, 0, 0, 0)";
742
+ var candidates = [previous === null || previous === void 0 ? void 0 : previous[key], next === null || next === void 0 ? void 0 : next[key]];
743
+ var _iteratorNormalCompletion = true,
744
+ _didIteratorError = false,
745
+ _iteratorError = void 0;
746
+ try {
747
+ for (var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
748
+ var candidate = _step.value;
749
+ if (typeof candidate === "string" && candidate !== "transparent") {
750
+ var rgbaMatch = candidate.match(/^rgba?\(([^,]+),\s*([^,]+),\s*([^,)]+)/);
751
+ if (rgbaMatch) {
752
+ fixed = `rgba(${rgbaMatch[1]}, ${rgbaMatch[2]}, ${rgbaMatch[3]}, 0)`;
753
+ break;
754
+ }
491
755
  }
492
756
  }
493
- }
494
- } catch (err) {
495
- _didIteratorError = !0, _iteratorError = err;
496
- } finally {
497
- try {
498
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
757
+ } catch (err) {
758
+ _didIteratorError = true;
759
+ _iteratorError = err;
499
760
  } finally {
500
- if (_didIteratorError) throw _iteratorError;
761
+ try {
762
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
763
+ _iterator.return();
764
+ }
765
+ } finally {
766
+ if (_didIteratorError) {
767
+ throw _iteratorError;
768
+ }
769
+ }
770
+ }
771
+ if (result === diff) {
772
+ result = {
773
+ ...diff
774
+ };
501
775
  }
776
+ result[key] = fixed;
502
777
  }
503
- result === diff && (result = {
504
- ...diff
505
- }), result[key] = fixed;
506
778
  }
507
779
  return result;
508
780
  }