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