@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.
- package/dist/cjs/createAnimations.cjs +490 -250
- package/dist/cjs/createAnimations.native.js +580 -319
- package/dist/cjs/createAnimations.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +21 -13
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/polyfill.cjs +3 -1
- package/dist/cjs/polyfill.native.js +3 -1
- package/dist/cjs/polyfill.native.js.map +1 -1
- package/dist/esm/createAnimations.mjs +460 -222
- package/dist/esm/createAnimations.mjs.map +1 -1
- package/dist/esm/createAnimations.native.js +550 -291
- package/dist/esm/createAnimations.native.js.map +1 -1
- package/dist/esm/index.native.js +9 -3
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/polyfill.mjs +3 -1
- package/dist/esm/polyfill.mjs.map +1 -1
- package/dist/esm/polyfill.native.js +3 -1
- package/dist/esm/polyfill.native.js.map +1 -1
- package/package.json +1 -1
- package/src/createAnimations.tsx +47 -3
- package/types/createAnimations.d.ts.map +2 -2
|
@@ -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
|
|
7
|
+
const isServer = typeof window === "undefined";
|
|
8
8
|
function useAnimateSSRSafe() {
|
|
9
|
-
|
|
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:
|
|
21
|
+
isReactNative: false,
|
|
19
22
|
inputStyle: "css",
|
|
20
23
|
outputStyle: "inline",
|
|
21
|
-
avoidReRenders:
|
|
24
|
+
avoidReRenders: true,
|
|
22
25
|
animations,
|
|
23
26
|
usePresence,
|
|
24
27
|
ResetPresence,
|
|
25
28
|
onMount() {
|
|
26
|
-
isHydratingGlobal =
|
|
29
|
+
isHydratingGlobal = false;
|
|
30
|
+
hydratingComponents.forEach(cb => cb());
|
|
27
31
|
},
|
|
28
32
|
useAnimations: animationProps => {
|
|
29
|
-
isHydratingGlobal === void 0 && !getConfig().settings.disableSSR
|
|
33
|
+
if (isHydratingGlobal === void 0 && !getConfig().settings.disableSSR) {
|
|
34
|
+
isHydratingGlobal = true;
|
|
35
|
+
}
|
|
30
36
|
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
refs.current.isExiting = isExiting
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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(() =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
113
|
+
const isCurrentlyExiting = refs.current.isExiting;
|
|
114
|
+
const currentSendExitComplete = refs.current.sendExitComplete;
|
|
94
115
|
let doAnimate2 = doAnimateRaw;
|
|
95
|
-
isCurrentlyExiting && 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
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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)
|
|
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
|
-
|
|
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
|
|
129
|
-
|
|
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 !== ""
|
|
197
|
+
if (val !== void 0 && val !== "") {
|
|
198
|
+
midFlightValues[key] = val;
|
|
199
|
+
}
|
|
140
200
|
}
|
|
141
201
|
} catch {}
|
|
142
|
-
if (isCurrentlyExiting
|
|
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)
|
|
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
|
|
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
|
-
} : {}
|
|
229
|
+
} : {};
|
|
230
|
+
refs.current.lastDoAnimate = doAnimate2 ? {
|
|
155
231
|
...doAnimate2
|
|
156
232
|
} : {};
|
|
157
233
|
} finally {
|
|
158
|
-
isCurrentlyExiting && currentSendExitComplete
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
252
|
+
useStyleEmitter?.((nextStyle, effectiveTransition) => {
|
|
166
253
|
const animationProps2 = getMotionAnimatedProps(props, nextStyle, disableAnimation, refs.current.animationState, effectiveTransition);
|
|
167
254
|
flushAnimation(animationProps2);
|
|
168
|
-
})
|
|
255
|
+
});
|
|
256
|
+
useIsomorphicLayoutEffect(() => {
|
|
169
257
|
if (refs.current.isFirstRender) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
} : {}
|
|
271
|
+
} : {};
|
|
272
|
+
refs.current.lastAnimateAt = Date.now();
|
|
178
273
|
return;
|
|
179
274
|
}
|
|
180
275
|
refs.current.lastDontAnimate = dontAnimate ? {
|
|
181
276
|
...dontAnimate
|
|
182
|
-
} : {}
|
|
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])
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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")
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
|
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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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)
|
|
252
|
-
|
|
253
|
-
|
|
379
|
+
if (disable) {
|
|
380
|
+
return {
|
|
381
|
+
dontAnimate: style
|
|
382
|
+
};
|
|
383
|
+
}
|
|
254
384
|
const animationOptions = getAnimationOptions(transitionOverride ?? props.transition ?? null, animationState);
|
|
255
|
-
let dontAnimate
|
|
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)
|
|
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"
|
|
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)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
293
|
-
|
|
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
|
-
|
|
299
|
-
|
|
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
|
-
|
|
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)
|
|
310
|
-
if (
|
|
311
|
-
|
|
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
|
-
|
|
316
|
-
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
337
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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
|
-
|
|
609
|
+
});
|
|
610
|
+
Component["acceptRenderProp"] = true;
|
|
611
|
+
return Component;
|
|
388
612
|
}
|
|
389
613
|
function getDiff(previous, next) {
|
|
390
|
-
if (!previous)
|
|
614
|
+
if (!previous) {
|
|
615
|
+
return next;
|
|
616
|
+
}
|
|
391
617
|
let diff = null;
|
|
392
|
-
for (const key in next)
|
|
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)
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
}
|