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