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