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