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