@hanzogui/animations-motion 2.0.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.
- package/LICENSE +21 -0
- package/README.md +72 -0
- package/dist/cjs/createAnimations.cjs +449 -0
- package/dist/cjs/createAnimations.native.js +548 -0
- package/dist/cjs/createAnimations.native.js.map +1 -0
- package/dist/cjs/index.cjs +19 -0
- package/dist/cjs/index.native.js +37 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/polyfill.cjs +1 -0
- package/dist/cjs/polyfill.native.js +4 -0
- package/dist/cjs/polyfill.native.js.map +1 -0
- package/dist/esm/createAnimations.mjs +414 -0
- package/dist/esm/createAnimations.mjs.map +1 -0
- package/dist/esm/createAnimations.native.js +510 -0
- package/dist/esm/createAnimations.native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +11 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/polyfill.mjs +2 -0
- package/dist/esm/polyfill.mjs.map +1 -0
- package/dist/esm/polyfill.native.js +2 -0
- package/dist/esm/polyfill.native.js.map +1 -0
- package/package.json +53 -0
- package/src/createAnimations.tsx +905 -0
- package/src/index.native.ts +28 -0
- package/src/index.ts +3 -0
- package/src/polyfill.ts +4 -0
- package/types/createAnimations.d.ts +8 -0
- package/types/createAnimations.d.ts.map +11 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +11 -0
- package/types/index.native.d.ts +4 -0
- package/types/index.native.d.ts.map +11 -0
- package/types/polyfill.d.ts +2 -0
- package/types/polyfill.d.ts.map +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @hanzogui/animations-motion
|
|
2
|
+
|
|
3
|
+
Motion animation driver for Hanzo GUI, powered by the [Motion](https://motion.dev) library and the Web Animations API (WAAPI).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Hybrid Engine**: Combines JavaScript animations with native WAAPI for GPU-accelerated performance
|
|
8
|
+
- **Spring Physics**: Natural, physics-based animations with intuitive `damping`, `stiffness`, and `mass` parameters
|
|
9
|
+
- **Independent Transforms**: Animate `x`, `y`, `scale`, `rotate` properties separately with different configurations
|
|
10
|
+
- **Compositor Thread**: Runs animations smoothly even when the main thread is busy
|
|
11
|
+
- **Web-Only**: Optimized for modern web browsers with WAAPI support
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @hanzogui/animations-motion motion
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Add to your Hanzo GUI configuration:
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { createAnimations } from '@hanzogui/animations-motion'
|
|
25
|
+
import { createGui } from '@hanzo/gui'
|
|
26
|
+
|
|
27
|
+
export default createGui({
|
|
28
|
+
animations: createAnimations({
|
|
29
|
+
bouncy: {
|
|
30
|
+
type: 'spring',
|
|
31
|
+
damping: 9,
|
|
32
|
+
mass: 0.9,
|
|
33
|
+
stiffness: 150,
|
|
34
|
+
},
|
|
35
|
+
quick: {
|
|
36
|
+
type: 'spring',
|
|
37
|
+
damping: 20,
|
|
38
|
+
mass: 1.2,
|
|
39
|
+
stiffness: 250,
|
|
40
|
+
},
|
|
41
|
+
'100ms': {
|
|
42
|
+
duration: 100,
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
// ...
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Animation Types
|
|
50
|
+
|
|
51
|
+
### Spring Animations
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
{
|
|
55
|
+
type: 'spring',
|
|
56
|
+
damping: 10, // Higher = less bouncy
|
|
57
|
+
stiffness: 100, // Higher = faster
|
|
58
|
+
mass: 1, // Higher = more inertia
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Tween Animations
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
{
|
|
66
|
+
duration: 200, // Duration in milliseconds
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
For complete documentation, see the [Gui Animations docs](https://gui.hanzo.ai/docs/core/animations).
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
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);
|
|
32
|
+
var createAnimations_exports = {};
|
|
33
|
+
__export(createAnimations_exports, {
|
|
34
|
+
createAnimations: () => createAnimations,
|
|
35
|
+
disableAnimationProps: () => disableAnimationProps
|
|
36
|
+
});
|
|
37
|
+
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";
|
|
45
|
+
function useAnimateSSRSafe() {
|
|
46
|
+
return isServer ? [(0, import_react2.useRef)(null), () => {}] : (0, import_react.useAnimate)();
|
|
47
|
+
}
|
|
48
|
+
const MotionValueStrategy = /* @__PURE__ */new WeakMap();
|
|
49
|
+
function createAnimations(animations) {
|
|
50
|
+
let isHydratingGlobal;
|
|
51
|
+
const hydratingComponents = /* @__PURE__ */new Set();
|
|
52
|
+
return {
|
|
53
|
+
View: MotionView,
|
|
54
|
+
Text: MotionText,
|
|
55
|
+
isReactNative: !1,
|
|
56
|
+
inputStyle: "css",
|
|
57
|
+
outputStyle: "inline",
|
|
58
|
+
avoidReRenders: !0,
|
|
59
|
+
animations,
|
|
60
|
+
usePresence: import_use_presence.usePresence,
|
|
61
|
+
ResetPresence: import_use_presence.ResetPresence,
|
|
62
|
+
onMount() {
|
|
63
|
+
isHydratingGlobal = !1, hydratingComponents.forEach(cb => cb());
|
|
64
|
+
},
|
|
65
|
+
useAnimations: animationProps => {
|
|
66
|
+
isHydratingGlobal === void 0 && !(0, import_web.getConfig)().settings.disableSSR && (isHydratingGlobal = !0);
|
|
67
|
+
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
|
+
});
|
|
97
|
+
const justFinishedEntering = refs.current.wasEntering && !isEntering;
|
|
98
|
+
(0, import_react2.useEffect)(() => {
|
|
99
|
+
refs.current.wasEntering = isEntering;
|
|
100
|
+
});
|
|
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)(() => {
|
|
108
|
+
refs.current.wasExiting = isExiting;
|
|
109
|
+
});
|
|
110
|
+
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);
|
|
117
|
+
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
|
+
}), []);
|
|
123
|
+
const flushAnimation = ({
|
|
124
|
+
doAnimate: doAnimateRaw = {},
|
|
125
|
+
animationOptions: passedOptions = {},
|
|
126
|
+
dontAnimate: dontAnimate2
|
|
127
|
+
}) => {
|
|
128
|
+
let startedControls = null;
|
|
129
|
+
const isCurrentlyExiting = refs.current.isExiting,
|
|
130
|
+
currentSendExitComplete = refs.current.sendExitComplete;
|
|
131
|
+
let doAnimate2 = doAnimateRaw;
|
|
132
|
+
isCurrentlyExiting && refs.current.frozenExitTarget && (doAnimate2 = refs.current.frozenExitTarget);
|
|
133
|
+
const animationOptions2 = isCurrentlyExiting && currentSendExitComplete ? getAnimationOptions(props.transition ?? null, "exit") : passedOptions;
|
|
134
|
+
try {
|
|
135
|
+
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;
|
|
153
|
+
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);
|
|
159
|
+
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]));
|
|
161
|
+
const lastAnimated = refs.current.lastDoAnimate;
|
|
162
|
+
lastAnimated && removeRemovedStyles(lastAnimated, doAnimate2, node, dontAnimate2);
|
|
163
|
+
const diff = getDiff(refs.current.lastDoAnimate, doAnimate2);
|
|
164
|
+
if (diff) {
|
|
165
|
+
isCurrentlyExiting && !refs.current.frozenExitTarget && (refs.current.frozenExitTarget = {
|
|
166
|
+
...doAnimate2
|
|
167
|
+
});
|
|
168
|
+
const isPopperPosition = node.hasAttribute("data-popper-animate-position");
|
|
169
|
+
let midFlightValues = null;
|
|
170
|
+
if (refs.current.controls) {
|
|
171
|
+
try {
|
|
172
|
+
const computed = getComputedStyle(node);
|
|
173
|
+
midFlightValues = {};
|
|
174
|
+
for (const key in diff) {
|
|
175
|
+
const val = computed[key];
|
|
176
|
+
val !== void 0 && val !== "" && (midFlightValues[key] = val);
|
|
177
|
+
}
|
|
178
|
+
} catch {}
|
|
179
|
+
if (isCurrentlyExiting && refs.current.controls.stop(), midFlightValues) for (const key in midFlightValues) node.style[key] = midFlightValues[key];
|
|
180
|
+
if (isPopperPosition) {
|
|
181
|
+
const anims = node.getAnimations();
|
|
182
|
+
for (const anim of anims) anim.cancel();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
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();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
refs.current.lastDontAnimate = dontAnimate2 ? {
|
|
190
|
+
...dontAnimate2
|
|
191
|
+
} : {}, refs.current.lastDoAnimate = doAnimate2 ? {
|
|
192
|
+
...doAnimate2
|
|
193
|
+
} : {};
|
|
194
|
+
} 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());
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
return useStyleEmitter?.((nextStyle, effectiveTransition) => {
|
|
203
|
+
const animationProps2 = getMotionAnimatedProps(props, nextStyle, disableAnimation, refs.current.animationState, effectiveTransition);
|
|
204
|
+
flushAnimation(animationProps2);
|
|
205
|
+
}), (0, import_web.useIsomorphicLayoutEffect)(() => {
|
|
206
|
+
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 ? {
|
|
213
|
+
...dontAnimate
|
|
214
|
+
} : {}, refs.current.lastAnimateAt = Date.now();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
refs.current.lastDontAnimate = dontAnimate ? {
|
|
218
|
+
...dontAnimate
|
|
219
|
+
} : {}, refs.current.lastDoAnimate = doAnimate ? {
|
|
220
|
+
...doAnimate
|
|
221
|
+
} : {};
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
flushAnimation({
|
|
225
|
+
doAnimate,
|
|
226
|
+
dontAnimate,
|
|
227
|
+
animationOptions
|
|
228
|
+
});
|
|
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()), {
|
|
239
|
+
style: firstRenderStyle,
|
|
240
|
+
ref: scope,
|
|
241
|
+
render: "div"
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
useAnimatedNumber(initial) {
|
|
245
|
+
const motionValue = (0, import_react.useMotionValue)(initial);
|
|
246
|
+
return import_react2.default.useMemo(() => ({
|
|
247
|
+
getInstance() {
|
|
248
|
+
return motionValue;
|
|
249
|
+
},
|
|
250
|
+
getValue() {
|
|
251
|
+
return motionValue.get();
|
|
252
|
+
},
|
|
253
|
+
setValue(next, config = {
|
|
254
|
+
type: "spring"
|
|
255
|
+
}, 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
|
+
}
|
|
264
|
+
motionValue.set(next);
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
stop() {
|
|
268
|
+
motionValue.stop();
|
|
269
|
+
}
|
|
270
|
+
}), [motionValue]);
|
|
271
|
+
},
|
|
272
|
+
useAnimatedNumberReaction({
|
|
273
|
+
value
|
|
274
|
+
}, onValue) {
|
|
275
|
+
const instance = value.getInstance();
|
|
276
|
+
(0, import_react.useMotionValueEvent)(instance, "change", onValue);
|
|
277
|
+
},
|
|
278
|
+
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
|
+
}), []);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
function getMotionAnimatedProps(props, style, disable, animationState = "default", transitionOverride) {
|
|
288
|
+
if (disable) return {
|
|
289
|
+
dontAnimate: style
|
|
290
|
+
};
|
|
291
|
+
const animationOptions = getAnimationOptions(transitionOverride ?? props.transition ?? null, animationState);
|
|
292
|
+
let dontAnimate, doAnimate;
|
|
293
|
+
const animateOnly = props.animateOnly;
|
|
294
|
+
for (const key in style) {
|
|
295
|
+
const value = style[key];
|
|
296
|
+
disableAnimationProps.has(key) || animateOnly && !animateOnly.includes(key) ? (dontAnimate ||= {}, dontAnimate[key] = value) : (doAnimate ||= {}, doAnimate[key] = value);
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
dontAnimate,
|
|
300
|
+
doAnimate,
|
|
301
|
+
animationOptions
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function getAnimationOptions(transitionProp, animationState = "default") {
|
|
305
|
+
const normalized = (0, import_animation_helpers.normalizeTransition)(transitionProp);
|
|
306
|
+
let effectiveKey = (0, import_animation_helpers.getEffectiveAnimation)(normalized, animationState);
|
|
307
|
+
!effectiveKey && animationState === "default" && (effectiveKey = normalized.enter || normalized.exit || null);
|
|
308
|
+
const globalConfigOverride = normalized.config ? {
|
|
309
|
+
...normalized.config
|
|
310
|
+
} : 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
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
convertMsToS(result), convertMsToS(result.default);
|
|
330
|
+
for (const key in result) key !== "default" && typeof result[key] == "object" && convertMsToS(result[key]);
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
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",
|
|
337
|
+
...config
|
|
338
|
+
} : {
|
|
339
|
+
type: "spring"
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
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));
|
|
344
|
+
}
|
|
345
|
+
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] = "";
|
|
349
|
+
}
|
|
350
|
+
}
|
|
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");
|
|
354
|
+
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 = {
|
|
369
|
+
get host() {
|
|
370
|
+
return hostRef.current;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
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) : {};
|
|
390
|
+
}
|
|
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;
|
|
405
|
+
if (webStyle && node instanceof HTMLElement) {
|
|
406
|
+
const motionAnimationConfig = animationConfig?.type === "timing" ? {
|
|
407
|
+
type: "tween",
|
|
408
|
+
duration: (animationConfig?.duration || 0) / 1e3
|
|
409
|
+
} : animationConfig?.type === "direct" ? {
|
|
410
|
+
type: "tween",
|
|
411
|
+
duration: 0
|
|
412
|
+
} : {
|
|
413
|
+
type: "spring",
|
|
414
|
+
...animationConfig
|
|
415
|
+
};
|
|
416
|
+
animate(node, webStyle, motionAnimationConfig);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
}, [animatedStyle]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(Element, {
|
|
420
|
+
...transformedProps,
|
|
421
|
+
ref: composedRefs
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
return Component.acceptRenderProp = !0, Component;
|
|
425
|
+
}
|
|
426
|
+
function getDiff(previous, next) {
|
|
427
|
+
if (!previous) return next;
|
|
428
|
+
let diff = null;
|
|
429
|
+
for (const key in next) next[key] !== previous[key] && (diff ||= {}, diff[key] = next[key]);
|
|
430
|
+
return diff;
|
|
431
|
+
}
|
|
432
|
+
function fixTransparentColors(diff, previous, next) {
|
|
433
|
+
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;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
result === diff && (result = {
|
|
445
|
+
...diff
|
|
446
|
+
}), result[key] = fixed;
|
|
447
|
+
}
|
|
448
|
+
return result;
|
|
449
|
+
}
|