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