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