@hanzogui/animations-motion 2.0.0-rc.41-hanzoai.5

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