@hanzogui/animations-motion 3.0.6 → 4.4.0

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