@tamagui/animations-react-native 1.0.1-beta.99 → 1.0.1-rc.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.
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -17,77 +18,286 @@ var __copyProps = (to, from, except, desc) => {
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
  var createAnimations_exports = {};
19
20
  __export(createAnimations_exports, {
20
- createAnimations: () => createAnimations
21
+ AnimatedText: () => AnimatedText,
22
+ AnimatedView: () => AnimatedView,
23
+ createAnimations: () => createAnimations,
24
+ useAnimatedNumber: () => useAnimatedNumber,
25
+ useAnimatedNumberReaction: () => useAnimatedNumberReaction,
26
+ useAnimatedNumberStyle: () => useAnimatedNumberStyle
21
27
  });
22
28
  module.exports = __toCommonJS(createAnimations_exports);
23
- var import_animate_presence = require("@tamagui/animate-presence");
29
+ var import_core = require("@tamagui/core");
30
+ var import_use_presence = require("@tamagui/use-presence");
24
31
  var import_react = require("react");
25
32
  var import_react_native = require("react-native");
33
+ const animatedStyleKey = {
34
+ transform: true,
35
+ opacity: true
36
+ };
37
+ const AnimatedView = import_react_native.Animated.View;
38
+ const AnimatedText = import_react_native.Animated.Text;
39
+ function useAnimatedNumber(initial) {
40
+ const state = (0, import_core.useSafeRef)(
41
+ null
42
+ );
43
+ if (!state.current) {
44
+ state.current = {
45
+ composite: null,
46
+ val: new import_react_native.Animated.Value(initial),
47
+ strategy: { type: "spring" }
48
+ };
49
+ }
50
+ return {
51
+ getInstance() {
52
+ return state.current.val;
53
+ },
54
+ getValue() {
55
+ return state.current.val["_value"];
56
+ },
57
+ stop() {
58
+ var _a;
59
+ (_a = state.current.composite) == null ? void 0 : _a.stop();
60
+ state.current.composite = null;
61
+ },
62
+ setValue(next, { type, ...config } = { type: "spring" }) {
63
+ var _a, _b;
64
+ const val = state.current.val;
65
+ if (type === "direct") {
66
+ val.setValue(next);
67
+ } else if (type === "spring") {
68
+ (_a = state.current.composite) == null ? void 0 : _a.stop();
69
+ const composite = import_react_native.Animated.spring(val, {
70
+ ...config,
71
+ toValue: next,
72
+ useNativeDriver: !import_core.isWeb
73
+ });
74
+ composite.start();
75
+ state.current.composite = composite;
76
+ } else {
77
+ (_b = state.current.composite) == null ? void 0 : _b.stop();
78
+ const composite = import_react_native.Animated.timing(val, {
79
+ ...config,
80
+ toValue: next,
81
+ useNativeDriver: !import_core.isWeb
82
+ });
83
+ composite.start();
84
+ state.current.composite = composite;
85
+ }
86
+ }
87
+ };
88
+ }
89
+ function useAnimatedNumberReaction(value, cb) {
90
+ const onChange = (0, import_core.useEvent)((current) => {
91
+ cb(current.value);
92
+ });
93
+ (0, import_react.useEffect)(() => {
94
+ const id = value.getInstance().addListener(onChange);
95
+ return () => {
96
+ value.getInstance().removeListener(id);
97
+ };
98
+ }, [value, onChange]);
99
+ }
100
+ function useAnimatedNumberStyle(value, getStyle) {
101
+ return getStyle(value.getInstance());
102
+ }
26
103
  function createAnimations(animations) {
27
- const AnimatedView = import_react_native.Animated.View;
28
- const AnimatedText = import_react_native.Animated.Text;
29
104
  AnimatedView["displayName"] = "AnimatedView";
30
105
  AnimatedText["displayName"] = "AnimatedText";
31
106
  return {
32
- avoidClasses: true,
107
+ isReactNative: true,
33
108
  animations,
34
109
  View: AnimatedView,
35
110
  Text: AnimatedText,
36
- useAnimations: (props, helpers) => {
37
- var _a, _b;
38
- const { pseudos, onDidAnimate, delay, getStyle, state, staticConfig } = helpers;
39
- const [isPresent, sendExitComplete] = (0, import_animate_presence.usePresence)();
40
- const presence = (0, import_react.useContext)(import_animate_presence.PresenceContext);
41
- const exitStyle = (presence == null ? void 0 : presence.exitVariant) ? ((_b = (_a = staticConfig.variantsParsed) == null ? void 0 : _a[presence.exitVariant]) == null ? void 0 : _b.true) || pseudos.exitStyle : pseudos.exitStyle;
42
- const onDidAnimateCb = (0, import_react.useCallback)((...args2) => {
43
- onDidAnimate == null ? void 0 : onDidAnimate(...args2);
44
- }, [onDidAnimate]);
45
- const isExiting = isPresent === false;
46
- const isEntering = !state.mounted;
47
- const all = getStyle({
48
- isExiting,
49
- isEntering,
50
- exitVariant: presence == null ? void 0 : presence.exitVariant,
51
- enterVariant: presence == null ? void 0 : presence.enterVariant
52
- });
53
- const animatedValues = (0, import_react.useRef)({});
54
- const [animatedStyles, nonAnimatedStyle] = [{}, {}];
55
- const animatedStyleKey = {
56
- transform: true,
57
- opacity: true
58
- };
59
- for (const key of Object.keys(all)) {
60
- if (animatedStyleKey[key]) {
61
- animatedStyles[key] = all[key];
62
- } else {
63
- nonAnimatedStyle[key] = all[key];
64
- }
111
+ useAnimatedNumber,
112
+ useAnimatedNumberReaction,
113
+ useAnimatedNumberStyle,
114
+ usePresence: import_use_presence.usePresence,
115
+ useAnimations: ({ props, onDidAnimate, style, state, presence }) => {
116
+ const isExiting = (presence == null ? void 0 : presence[0]) === false;
117
+ const sendExitComplete = presence == null ? void 0 : presence[1];
118
+ const mergedStyles = style;
119
+ const animateStyles = (0, import_core.useSafeRef)({});
120
+ const animatedTranforms = (0, import_core.useSafeRef)([]);
121
+ const animationsState = (0, import_core.useSafeRef)(null);
122
+ if (!animationsState.current) {
123
+ animationsState.current = /* @__PURE__ */ new WeakMap();
65
124
  }
66
- const animatedStyle = animatedStyleKey;
67
- const args = [
68
- JSON.stringify(all),
69
- state.mounted,
70
- state.hover,
71
- state.press,
72
- state.pressIn,
73
- state.focus,
74
- delay,
75
- isPresent,
76
- onDidAnimate,
77
- onDidAnimateCb,
78
- presence == null ? void 0 : presence.exitVariant,
79
- presence == null ? void 0 : presence.enterVariant
80
- ];
81
- return (0, import_react.useMemo)(() => {
125
+ const runners = [];
126
+ const completions = [];
127
+ const args = [JSON.stringify(mergedStyles), JSON.stringify(state), isExiting, !!onDidAnimate];
128
+ const res = (0, import_react.useMemo)(() => {
129
+ var _a;
130
+ const nonAnimatedStyle = {};
131
+ for (const key in mergedStyles) {
132
+ const val = mergedStyles[key];
133
+ if (!animatedStyleKey[key]) {
134
+ nonAnimatedStyle[key] = val;
135
+ continue;
136
+ }
137
+ if (key !== "transform") {
138
+ animateStyles.current[key] = update(key, animateStyles.current[key], val);
139
+ continue;
140
+ }
141
+ if (!val)
142
+ continue;
143
+ for (const [index, transform] of val.entries()) {
144
+ if (!transform)
145
+ continue;
146
+ const tkey = Object.keys(transform)[0];
147
+ const currentTransform = (_a = animatedTranforms.current[index]) == null ? void 0 : _a[tkey];
148
+ animatedTranforms.current[index] = {
149
+ [tkey]: update(tkey, currentTransform, transform[tkey])
150
+ };
151
+ animatedTranforms.current = [...animatedTranforms.current];
152
+ }
153
+ }
154
+ const animatedStyle = {
155
+ ...Object.fromEntries(
156
+ Object.entries({
157
+ ...animateStyles.current
158
+ }).map(([k, v]) => {
159
+ var _a2;
160
+ return [k, ((_a2 = animationsState.current.get(v)) == null ? void 0 : _a2.interopolation) || v];
161
+ })
162
+ ),
163
+ transform: animatedTranforms.current.map((r) => {
164
+ var _a2;
165
+ const key = Object.keys(r)[0];
166
+ const val = ((_a2 = animationsState.current.get(r[key])) == null ? void 0 : _a2.interopolation) || r[key];
167
+ return { [key]: val };
168
+ })
169
+ };
82
170
  return {
83
171
  style: [nonAnimatedStyle, animatedStyle]
84
172
  };
173
+ function update(key, animated, valIn) {
174
+ const [val, type] = getValue(valIn);
175
+ const value = animated || new import_react_native.Animated.Value(val);
176
+ let interpolateArgs;
177
+ if (type) {
178
+ const curInterpolation = animationsState.current.get(value);
179
+ interpolateArgs = getInterpolated(
180
+ (curInterpolation == null ? void 0 : curInterpolation.current) ?? value["_value"],
181
+ val,
182
+ type
183
+ );
184
+ animationsState.current.set(value, {
185
+ interopolation: value.interpolate(interpolateArgs),
186
+ current: val
187
+ });
188
+ }
189
+ if (value) {
190
+ const animationConfig = getAnimationConfig(key, animations, props.animation);
191
+ let resolve;
192
+ const promise = new Promise((res2) => {
193
+ resolve = res2;
194
+ });
195
+ completions.push(promise);
196
+ runners.push(() => {
197
+ value.stopAnimation();
198
+ import_react_native.Animated.spring(value, {
199
+ toValue: val,
200
+ useNativeDriver: !import_core.isWeb,
201
+ ...animationConfig
202
+ }).start(({ finished }) => {
203
+ if (finished) {
204
+ resolve();
205
+ }
206
+ });
207
+ });
208
+ }
209
+ if (process.env.NODE_ENV === "development") {
210
+ if (props["debug"]) {
211
+ console.log(" \u{1F4A0} animate", key, `from ${value["_value"]} to`, valIn, `(${val})`, "type", type, "interpolate", interpolateArgs);
212
+ }
213
+ }
214
+ return value;
215
+ }
216
+ }, args);
217
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
218
+ runners.forEach((r) => r());
219
+ let cancel = false;
220
+ Promise.all(completions).then(() => {
221
+ if (cancel)
222
+ return;
223
+ onDidAnimate == null ? void 0 : onDidAnimate();
224
+ if (isExiting) {
225
+ sendExitComplete == null ? void 0 : sendExitComplete();
226
+ }
227
+ });
228
+ return () => {
229
+ cancel = true;
230
+ };
85
231
  }, args);
232
+ if (process.env.NODE_ENV === "development") {
233
+ if (props["debug"]) {
234
+ console.log(`Returning animated`, res);
235
+ }
236
+ }
237
+ return res;
86
238
  }
87
239
  };
88
240
  }
241
+ function getInterpolated(current, next, postfix = "deg") {
242
+ if (next === current) {
243
+ current = next - 1e-9;
244
+ }
245
+ const inputRange = [current, next];
246
+ const outputRange = [`${current}${postfix}`, `${next}${postfix}`];
247
+ if (next < current) {
248
+ inputRange.reverse();
249
+ outputRange.reverse();
250
+ }
251
+ return {
252
+ inputRange,
253
+ outputRange
254
+ };
255
+ }
256
+ function getAnimationConfig(key, animations, animation) {
257
+ if (typeof animation === "string") {
258
+ return animations[animation];
259
+ }
260
+ let type = "";
261
+ let extraConf;
262
+ if (Array.isArray(animation)) {
263
+ type = animation[0];
264
+ const conf = animation[1] && animation[1][key];
265
+ if (conf) {
266
+ if (typeof conf === "string") {
267
+ type = conf;
268
+ } else {
269
+ type = conf.type || type;
270
+ extraConf = conf;
271
+ }
272
+ }
273
+ } else {
274
+ const val = animation == null ? void 0 : animation[key];
275
+ type = val == null ? void 0 : val.type;
276
+ extraConf = val;
277
+ }
278
+ const found = animations[type];
279
+ if (!found) {
280
+ throw new Error(`No animation of type "${type}" for key "${key}"`);
281
+ }
282
+ return {
283
+ ...found,
284
+ ...extraConf
285
+ };
286
+ }
287
+ function getValue(input) {
288
+ if (typeof input !== "string") {
289
+ return [input];
290
+ }
291
+ const [_, number, after] = input.match(/([-0-9]+)(deg|%|px)/) ?? [];
292
+ return [+number, after];
293
+ }
89
294
  // Annotate the CommonJS export names for ESM import in node:
90
295
  0 && (module.exports = {
91
- createAnimations
296
+ AnimatedText,
297
+ AnimatedView,
298
+ createAnimations,
299
+ useAnimatedNumber,
300
+ useAnimatedNumberReaction,
301
+ useAnimatedNumberStyle
92
302
  });
93
303
  //# sourceMappingURL=createAnimations.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/createAnimations.tsx"],
4
- "sourcesContent": ["import { PresenceContext, usePresence } from '@tamagui/animate-presence'\nimport { AnimationDriver, AnimationProp } from '@tamagui/core'\nimport { useCallback, useContext, useMemo, useRef, useState } from 'react'\nimport { Animated } from 'react-native'\n\ntype AnimationsConfig<A extends Object = any> = {\n [Key in keyof A]: AnimationConfig\n}\n\ntype AnimationConfig = {}\n// | ({ type: 'timing'; loop?: number; repeat?: number; repeatReverse?: boolean } & WithTimingConfig)\n// | ({ type: 'spring'; loop?: number; repeat?: number; repeatReverse?: boolean } & WithSpringConfig)\n// | ({ type: 'decay'; loop?: number; repeat?: number; repeatReverse?: boolean } & WithDecayConfig)\n\nexport function createAnimations<A extends AnimationsConfig>(animations: A): AnimationDriver<A> {\n const AnimatedView = Animated.View\n const AnimatedText = Animated.Text\n\n AnimatedView['displayName'] = 'AnimatedView'\n AnimatedText['displayName'] = 'AnimatedText'\n\n return {\n avoidClasses: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimations: (props, helpers) => {\n const { pseudos, onDidAnimate, delay, getStyle, state, staticConfig } = helpers\n const [isPresent, sendExitComplete] = usePresence()\n const presence = useContext(PresenceContext)\n\n const exitStyle = presence?.exitVariant\n ? staticConfig.variantsParsed?.[presence.exitVariant]?.true || pseudos.exitStyle\n : pseudos.exitStyle\n\n const onDidAnimateCb = useCallback<NonNullable<typeof onDidAnimate>>(\n (...args) => {\n onDidAnimate?.(...args)\n },\n [onDidAnimate]\n )\n\n const isExiting = isPresent === false\n const isEntering = !state.mounted\n\n const all = getStyle({\n isExiting,\n isEntering,\n exitVariant: presence?.exitVariant,\n enterVariant: presence?.enterVariant,\n })\n\n const animatedValues = useRef<Record<string, Animated.Value>>({})\n\n // TODO loop and create values, run them if they change\n\n const [animatedStyles, nonAnimatedStyle] = [{}, {}]\n const animatedStyleKey = {\n transform: true,\n opacity: true,\n }\n for (const key of Object.keys(all)) {\n if (animatedStyleKey[key]) {\n animatedStyles[key] = all[key]\n } else {\n nonAnimatedStyle[key] = all[key]\n }\n }\n\n const animatedStyle = animatedStyleKey\n\n const args = [\n JSON.stringify(all),\n state.mounted,\n state.hover,\n state.press,\n state.pressIn,\n state.focus,\n delay,\n isPresent,\n onDidAnimate,\n onDidAnimateCb,\n presence?.exitVariant,\n presence?.enterVariant,\n ]\n\n // const callback = (\n // isExiting: boolean,\n // exitingStyleProps: Record<string, boolean>,\n // key: string,\n // value: any\n // ) => {\n // return (completed, current) => {\n // onDidAnimateCb(key, completed, current, {\n // attemptedValue: value,\n // })\n // if (isExiting) {\n // exitingStyleProps[key] = false\n // const areStylesExiting = Object.values(exitingStyleProps).some(Boolean)\n // // if this is true, then we've finished our exit animations\n // if (!areStylesExiting) {\n // sendExitComplete?.()\n // }\n // }\n // }\n // }\n\n return useMemo(() => {\n return {\n style: [nonAnimatedStyle, animatedStyle],\n }\n }, args)\n },\n }\n}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,KAAK,UAAU,GAAG;AAAA,QAClB,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,qCAAU;AAAA,QACV,qCAAU;AAAA,MACZ;AAuBA,aAAO,0BAAQ,MAAM;AACnB,eAAO;AAAA,UACL,OAAO,CAAC,kBAAkB,aAAa;AAAA,QACzC;AAAA,MACF,GAAG,IAAI;AAAA,IACT;AAAA,EACF;AACF;",
6
- "names": []
4
+ "sourcesContent": ["import {\n AnimatedNumberStrategy,\n AnimationDriver,\n AnimationProp,\n UniversalAnimatedNumber,\n isWeb,\n useEvent,\n useIsomorphicLayoutEffect,\n useSafeRef,\n} from '@tamagui/core'\nimport { usePresence } from '@tamagui/use-presence'\nimport { useEffect, useMemo } from 'react'\nimport { Animated } from 'react-native'\n\ntype AnimationsConfig<A extends Object = any> = {\n [Key in keyof A]: AnimationConfig\n}\n\ntype AnimationConfig = Partial<\n Pick<\n Animated.SpringAnimationConfig,\n | 'delay'\n | 'bounciness'\n | 'damping'\n | 'friction'\n | 'mass'\n | 'overshootClamping'\n | 'speed'\n | 'stiffness'\n | 'tension'\n | 'velocity'\n >\n>\n\nconst animatedStyleKey = {\n transform: true,\n opacity: true,\n}\n\nexport const AnimatedView = Animated.View\nexport const AnimatedText = Animated.Text\n\nexport function useAnimatedNumber(initial: number): UniversalAnimatedNumber<Animated.Value> {\n const state = useSafeRef(\n null as any as {\n val: Animated.Value\n composite: Animated.CompositeAnimation | null\n strategy: AnimatedNumberStrategy\n }\n )\n if (!state.current) {\n state.current = {\n composite: null,\n val: new Animated.Value(initial),\n strategy: { type: 'spring' },\n }\n }\n\n return {\n getInstance() {\n return state.current.val\n },\n getValue() {\n return state.current.val['_value']\n },\n stop() {\n state.current.composite?.stop()\n state.current.composite = null\n },\n setValue(next: number, { type, ...config } = { type: 'spring' }) {\n const val = state.current.val\n if (type === 'direct') {\n val.setValue(next)\n } else if (type === 'spring') {\n state.current.composite?.stop()\n const composite = Animated.spring(val, {\n ...config,\n toValue: next,\n useNativeDriver: !isWeb,\n })\n composite.start()\n state.current.composite = composite\n } else {\n state.current.composite?.stop()\n const composite = Animated.timing(val, {\n ...config,\n toValue: next,\n useNativeDriver: !isWeb,\n })\n composite.start()\n state.current.composite = composite\n }\n },\n }\n}\n\nexport function useAnimatedNumberReaction(\n value: UniversalAnimatedNumber<Animated.Value>,\n cb: (current: number) => void\n) {\n const onChange = useEvent((current) => {\n cb(current.value)\n })\n\n useEffect(() => {\n const id = value.getInstance().addListener(onChange)\n return () => {\n value.getInstance().removeListener(id)\n }\n }, [value, onChange])\n}\n\nexport function useAnimatedNumberStyle<V extends UniversalAnimatedNumber<Animated.Value>>(\n value: V,\n getStyle: (value: any) => any\n) {\n return getStyle(value.getInstance())\n}\n\nexport function createAnimations<A extends AnimationsConfig>(animations: A): AnimationDriver<A> {\n AnimatedView['displayName'] = 'AnimatedView'\n AnimatedText['displayName'] = 'AnimatedText'\n\n return {\n isReactNative: true,\n animations,\n View: AnimatedView,\n Text: AnimatedText,\n useAnimatedNumber,\n useAnimatedNumberReaction,\n useAnimatedNumberStyle,\n usePresence,\n useAnimations: ({ props, onDidAnimate, style, state, presence }) => {\n const isExiting = presence?.[0] === false\n const sendExitComplete = presence?.[1]\n const mergedStyles = style\n const animateStyles = useSafeRef<Record<string, Animated.Value>>({})\n const animatedTranforms = useSafeRef<{ [key: string]: Animated.Value }[]>([])\n const animationsState = useSafeRef<\n WeakMap<\n Animated.Value,\n {\n interopolation: Animated.AnimatedInterpolation\n current?: number | undefined\n }\n >\n >(null as any)\n if (!animationsState.current) {\n animationsState.current = new WeakMap()\n }\n\n const runners: Function[] = []\n const completions: Promise<void>[] = []\n\n // const args = [JSON.stringify(mergedStyles)]\n const args = [JSON.stringify(mergedStyles), JSON.stringify(state), isExiting, !!onDidAnimate]\n\n const res = useMemo(() => {\n const nonAnimatedStyle = {}\n for (const key in mergedStyles) {\n const val = mergedStyles[key]\n if (!animatedStyleKey[key]) {\n nonAnimatedStyle[key] = val\n continue\n }\n if (key !== 'transform') {\n animateStyles.current[key] = update(key, animateStyles.current[key], val)\n continue\n }\n // key: 'transform'\n // for now just support one transform key\n if (!val) continue\n for (const [index, transform] of val.entries()) {\n if (!transform) continue\n const tkey = Object.keys(transform)[0]\n const currentTransform = animatedTranforms.current[index]?.[tkey]\n animatedTranforms.current[index] = {\n [tkey]: update(tkey, currentTransform, transform[tkey]),\n }\n animatedTranforms.current = [...animatedTranforms.current]\n }\n }\n\n const animatedStyle = {\n ...Object.fromEntries(\n Object.entries({\n ...animateStyles.current,\n }).map(([k, v]) => [k, animationsState.current!.get(v)?.interopolation || v])\n ),\n transform: animatedTranforms.current.map((r) => {\n const key = Object.keys(r)[0]\n const val = animationsState.current!.get(r[key])?.interopolation || r[key]\n return { [key]: val }\n }),\n }\n\n return {\n style: [nonAnimatedStyle, animatedStyle],\n }\n\n function update(key: string, animated: Animated.Value | undefined, valIn: string | number) {\n const [val, type] = getValue(valIn)\n const value = animated || new Animated.Value(val)\n let interpolateArgs: any\n if (type) {\n const curInterpolation = animationsState.current.get(value)\n interpolateArgs = getInterpolated(\n curInterpolation?.current ?? value['_value'],\n val,\n type\n )\n animationsState.current!.set(value, {\n interopolation: value.interpolate(interpolateArgs),\n current: val,\n })\n }\n if (value) {\n const animationConfig = getAnimationConfig(key, animations, props.animation)\n\n let resolve\n const promise = new Promise<void>((res) => {\n resolve = res\n })\n completions.push(promise)\n\n runners.push(() => {\n value.stopAnimation()\n Animated.spring(value, {\n toValue: val,\n useNativeDriver: !isWeb,\n ...animationConfig,\n }).start(({ finished }) => {\n if (finished) {\n resolve()\n }\n })\n })\n }\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // prettier-ignore\n // eslint-disable-next-line no-console\n console.log(' \uD83D\uDCA0 animate', key, `from ${value['_value']} to`, valIn, `(${val})`, 'type', type, 'interpolate', interpolateArgs)\n }\n }\n return value\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, args)\n\n useIsomorphicLayoutEffect(() => {\n runners.forEach((r) => r())\n let cancel = false\n Promise.all(completions).then(() => {\n if (cancel) return\n onDidAnimate?.()\n if (isExiting) {\n sendExitComplete?.()\n }\n })\n return () => {\n cancel = true\n }\n }, args)\n\n if (process.env.NODE_ENV === 'development') {\n if (props['debug']) {\n // eslint-disable-next-line no-console\n console.log(`Returning animated`, res)\n }\n }\n\n return res\n },\n }\n}\n\nfunction getInterpolated(current: number, next: number, postfix = 'deg') {\n if (next === current) {\n current = next - 0.000000001\n }\n const inputRange = [current, next]\n const outputRange = [`${current}${postfix}`, `${next}${postfix}`]\n if (next < current) {\n inputRange.reverse()\n outputRange.reverse()\n }\n return {\n inputRange,\n outputRange,\n }\n}\n\nfunction getAnimationConfig(key: string, animations: AnimationsConfig, animation?: AnimationProp) {\n if (typeof animation === 'string') {\n return animations[animation]\n }\n let type = ''\n let extraConf: any\n if (Array.isArray(animation)) {\n type = animation[0] as string\n const conf = animation[1] && animation[1][key]\n if (conf) {\n if (typeof conf === 'string') {\n type = conf\n } else {\n type = (conf as any).type || type\n extraConf = conf\n }\n }\n } else {\n const val = animation?.[key]\n type = val?.type\n extraConf = val\n }\n const found = animations[type]\n if (!found) {\n throw new Error(`No animation of type \"${type}\" for key \"${key}\"`)\n }\n return {\n ...found,\n ...extraConf,\n }\n}\n\nfunction getValue(input: number | string) {\n if (typeof input !== 'string') {\n return [input] as const\n }\n const [_, number, after] = input.match(/([-0-9]+)(deg|%|px)/) ?? []\n return [+number, after] as const\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBASO;AACP,0BAA4B;AAC5B,mBAAmC;AACnC,0BAAyB;AAsBzB,MAAM,mBAAmB;AAAA,EACvB,WAAW;AAAA,EACX,SAAS;AACX;AAEO,MAAM,eAAe,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a", "res"]
7
7
  }
package/dist/cjs/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -14,5 +15,6 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
14
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
16
  var src_exports = {};
16
17
  module.exports = __toCommonJS(src_exports);
18
+ var import_polyfill = require("./polyfill");
17
19
  __reExport(src_exports, require("./createAnimations"), module.exports);
18
20
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["export * from './createAnimations'\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,+BAAd;",
4
+ "sourcesContent": ["import './polyfill'\n\nexport * from './createAnimations'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,sBAAO;AAEP,wBAAc,+BAFd;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ if (typeof requestAnimationFrame === "undefined") {
3
+ globalThis["requestAnimationFrame"] = setImmediate;
4
+ }
5
+ //# sourceMappingURL=polyfill.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/polyfill.ts"],
4
+ "sourcesContent": ["// for SSR\nif (typeof requestAnimationFrame === 'undefined') {\n globalThis['requestAnimationFrame'] = setImmediate\n}\n"],
5
+ "mappings": ";AACA,IAAI,OAAO,0BAA0B,aAAa;AAChD,aAAW,2BAA2B;AACxC;",
6
+ "names": []
7
+ }