@hanzogui/animations-motion 3.0.6 → 4.3.1

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