@xanui/core 1.2.71 → 1.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.
- package/Iframe/index.cjs +1 -2
- package/Iframe/index.cjs.map +1 -1
- package/Iframe/index.d.ts +2 -1
- package/Iframe/index.js +1 -2
- package/Iframe/index.js.map +1 -1
- package/Transition/index.cjs +40 -97
- package/Transition/index.cjs.map +1 -1
- package/Transition/index.d.ts +13 -18
- package/Transition/index.js +41 -98
- package/Transition/index.js.map +1 -1
- package/Transition/variants.cjs +92 -171
- package/Transition/variants.cjs.map +1 -1
- package/Transition/variants.d.ts +65 -83
- package/Transition/variants.js +93 -170
- package/Transition/variants.js.map +1 -1
- package/animate/easing.cjs +59 -0
- package/animate/easing.cjs.map +1 -0
- package/animate/easing.d.ts +13 -0
- package/animate/easing.js +57 -0
- package/animate/easing.js.map +1 -0
- package/animate/index.cjs +104 -0
- package/animate/index.cjs.map +1 -0
- package/animate/index.d.ts +19 -0
- package/animate/index.js +99 -0
- package/animate/index.js.map +1 -0
- package/hooks/useTransition.cjs +98 -0
- package/hooks/useTransition.cjs.map +1 -0
- package/hooks/useTransition.d.ts +23 -0
- package/hooks/useTransition.js +96 -0
- package/hooks/useTransition.js.map +1 -0
- package/hooks/useTransitionGroup.cjs +95 -0
- package/hooks/useTransitionGroup.cjs.map +1 -0
- package/hooks/useTransitionGroup.d.ts +32 -0
- package/hooks/useTransitionGroup.js +93 -0
- package/hooks/useTransitionGroup.js.map +1 -0
- package/index.cjs +16 -11
- package/index.cjs.map +1 -1
- package/index.d.ts +5 -2
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/hooks/useAnimation.cjs +0 -44
- package/hooks/useAnimation.cjs.map +0 -1
- package/hooks/useAnimation.d.ts +0 -20
- package/hooks/useAnimation.js +0 -39
- package/hooks/useAnimation.js.map +0 -1
package/Transition/variants.js
CHANGED
|
@@ -1,209 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
const getY = (el) => (el ? Math.min(el.getBoundingClientRect().height / 2, 40) : 20);
|
|
3
|
+
const getX = (el) => (el ? Math.min(el.getBoundingClientRect().width / 2, 40) : 20);
|
|
4
|
+
// ------------------ Variants ------------------
|
|
5
|
+
const slideDown = (el) => {
|
|
6
|
+
const y = getY(el);
|
|
5
7
|
return {
|
|
6
|
-
from: {
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
to: {
|
|
10
|
-
transform: `translateY(0)`,
|
|
11
|
-
}
|
|
8
|
+
from: { y: -y },
|
|
9
|
+
to: { y: 0 },
|
|
10
|
+
onUpdate: ({ y }) => (el.style.transform = `translateY(${y}px)`),
|
|
12
11
|
};
|
|
13
12
|
};
|
|
14
|
-
const slideUp = (
|
|
15
|
-
const y = getY(
|
|
13
|
+
const slideUp = (el) => {
|
|
14
|
+
const y = getY(el);
|
|
16
15
|
return {
|
|
17
|
-
from: {
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
to: {
|
|
21
|
-
transform: `translateY(0)`,
|
|
22
|
-
}
|
|
16
|
+
from: { y },
|
|
17
|
+
to: { y: 0 },
|
|
18
|
+
onUpdate: ({ y }) => (el.style.transform = `translateY(${y}px)`),
|
|
23
19
|
};
|
|
24
20
|
};
|
|
25
|
-
const slideRight = (
|
|
26
|
-
const x = getX(
|
|
21
|
+
const slideRight = (el) => {
|
|
22
|
+
const x = getX(el);
|
|
27
23
|
return {
|
|
28
|
-
from: {
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
to: {
|
|
32
|
-
transform: `translateX(0)`,
|
|
33
|
-
}
|
|
24
|
+
from: { x: -x },
|
|
25
|
+
to: { x: 0 },
|
|
26
|
+
onUpdate: ({ x }) => (el.style.transform = `translateX(${x}px)`),
|
|
34
27
|
};
|
|
35
28
|
};
|
|
36
|
-
const slideLeft = (
|
|
37
|
-
const x = getX(
|
|
29
|
+
const slideLeft = (el) => {
|
|
30
|
+
const x = getX(el);
|
|
38
31
|
return {
|
|
39
|
-
from: {
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
to: {
|
|
43
|
-
transform: `translateX(0)`,
|
|
44
|
-
}
|
|
32
|
+
from: { x },
|
|
33
|
+
to: { x: 0 },
|
|
34
|
+
onUpdate: ({ x }) => (el.style.transform = `translateX(${x}px)`),
|
|
45
35
|
};
|
|
46
36
|
};
|
|
47
|
-
const
|
|
48
|
-
from: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
pointerEvents: 'none',
|
|
52
|
-
transformOrigin: "top"
|
|
53
|
-
},
|
|
54
|
-
to: {
|
|
55
|
-
transform: "scaleY(1)",
|
|
56
|
-
opacity: 1,
|
|
57
|
-
transformOrigin: "top"
|
|
58
|
-
}
|
|
37
|
+
const fade = (el) => ({
|
|
38
|
+
from: { opacity: 0 },
|
|
39
|
+
to: { opacity: 1 },
|
|
40
|
+
onUpdate: ({ opacity }) => (el.style.opacity = opacity),
|
|
59
41
|
});
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
transform: "scaleY(0.8)",
|
|
63
|
-
transformOrigin: "bottom",
|
|
64
|
-
opacity: 0,
|
|
65
|
-
pointerEvents: 'none'
|
|
66
|
-
},
|
|
67
|
-
to: {
|
|
68
|
-
transform: "scaleY(1)",
|
|
69
|
-
transformOrigin: "bottom",
|
|
70
|
-
opacity: 1
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
const fade = () => {
|
|
42
|
+
const fadeDown = (el) => {
|
|
43
|
+
const y = getY(el);
|
|
74
44
|
return {
|
|
75
|
-
from: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
opacity: 1
|
|
45
|
+
from: { y: -y, scale: 0.98, opacity: 0 },
|
|
46
|
+
to: { y: 0, scale: 1, opacity: 1 },
|
|
47
|
+
onUpdate: ({ y, scale, opacity }) => {
|
|
48
|
+
el.style.transform = `translateY(${y}px) scale(${scale})`;
|
|
49
|
+
el.style.opacity = String(opacity);
|
|
81
50
|
}
|
|
82
51
|
};
|
|
83
52
|
};
|
|
84
|
-
const
|
|
85
|
-
const y = getY(
|
|
53
|
+
const fadeUp = (el) => {
|
|
54
|
+
const y = getY(el);
|
|
86
55
|
return {
|
|
87
|
-
from: {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
to: {
|
|
93
|
-
transform: `translateY(0) scale(1)`,
|
|
94
|
-
opacity: 1
|
|
56
|
+
from: { y, scale: 0.98, opacity: 0 },
|
|
57
|
+
to: { y: 0, scale: 1, opacity: 1 },
|
|
58
|
+
onUpdate: ({ y, scale, opacity }) => {
|
|
59
|
+
el.style.transform = `translateY(${y}px) scale(${scale})`;
|
|
60
|
+
el.style.opacity = String(opacity);
|
|
95
61
|
}
|
|
96
62
|
};
|
|
97
63
|
};
|
|
98
|
-
const
|
|
99
|
-
const
|
|
64
|
+
const fadeRight = (el) => {
|
|
65
|
+
const x = getX(el);
|
|
100
66
|
return {
|
|
101
|
-
from: {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
to: {
|
|
107
|
-
transform: `translateY(0) scale(1)`,
|
|
108
|
-
opacity: 1
|
|
67
|
+
from: { x: -x, scale: 0.98, opacity: 0 },
|
|
68
|
+
to: { x: 0, scale: 1, opacity: 1 },
|
|
69
|
+
onUpdate: ({ x, scale, opacity }) => {
|
|
70
|
+
el.style.transform = `translateX(${x}px) scale(${scale})`;
|
|
71
|
+
el.style.opacity = String(opacity);
|
|
109
72
|
}
|
|
110
73
|
};
|
|
111
74
|
};
|
|
112
|
-
const
|
|
113
|
-
const x = getX(
|
|
75
|
+
const fadeLeft = (el) => {
|
|
76
|
+
const x = getX(el);
|
|
114
77
|
return {
|
|
115
|
-
from: {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
to: {
|
|
121
|
-
transform: `translateX(0) scale(1)`,
|
|
122
|
-
opacity: 1
|
|
78
|
+
from: { x, scale: 0.98, opacity: 0 },
|
|
79
|
+
to: { x: 0, scale: 1, opacity: 1 },
|
|
80
|
+
onUpdate: ({ x, scale, opacity }) => {
|
|
81
|
+
el.style.transform = `translateX(${x}px) scale(${scale})`;
|
|
82
|
+
el.style.opacity = String(opacity);
|
|
123
83
|
}
|
|
124
84
|
};
|
|
125
85
|
};
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
153
|
-
const zoom = () => {
|
|
154
|
-
return {
|
|
155
|
-
from: {
|
|
156
|
-
transform: "scale(.8)",
|
|
157
|
-
transformOrigin: "center",
|
|
158
|
-
opacity: 0,
|
|
159
|
-
pointerEvents: 'none'
|
|
160
|
-
},
|
|
161
|
-
to: {
|
|
162
|
-
transform: "scale(1)",
|
|
163
|
-
transformOrigin: "center",
|
|
164
|
-
opacity: 1
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
};
|
|
168
|
-
const zoomOver = () => {
|
|
169
|
-
return {
|
|
170
|
-
from: {
|
|
171
|
-
transform: "scale(1.2)",
|
|
172
|
-
transformOrigin: "center",
|
|
173
|
-
opacity: 0,
|
|
174
|
-
pointerEvents: 'none'
|
|
175
|
-
},
|
|
176
|
-
to: {
|
|
177
|
-
transform: "scale(1)",
|
|
178
|
-
transformOrigin: "center",
|
|
179
|
-
opacity: 1
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
};
|
|
183
|
-
const collapseVertical = (rect) => {
|
|
86
|
+
const zoom = (el) => ({
|
|
87
|
+
from: { scale: 0.8, opacity: 0 },
|
|
88
|
+
to: { scale: 1, opacity: 1 },
|
|
89
|
+
onUpdate: ({ scale, opacity }) => {
|
|
90
|
+
el.style.transform = `scale(${scale})`;
|
|
91
|
+
el.style.opacity = String(opacity);
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
const zoomOver = (el) => ({
|
|
95
|
+
from: { scale: 1.2, opacity: 0 },
|
|
96
|
+
to: { scale: 1, opacity: 1 },
|
|
97
|
+
onUpdate: ({ scale, opacity }) => {
|
|
98
|
+
el.style.transform = `scale(${scale})`;
|
|
99
|
+
el.style.opacity = String(opacity);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const grow = (el) => ({
|
|
103
|
+
from: { scaleX: 0.8, scaleY: 0.6, opacity: 0 },
|
|
104
|
+
to: { scaleX: 1, scaleY: 1, opacity: 1 },
|
|
105
|
+
onUpdate: ({ scaleX, scaleY, opacity }) => {
|
|
106
|
+
el.style.transform = `scale(${scaleX}, ${scaleY})`;
|
|
107
|
+
el.style.opacity = String(opacity);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const collapseVertical = (el) => {
|
|
111
|
+
const height = el.getBoundingClientRect().height;
|
|
184
112
|
return {
|
|
185
|
-
from: {
|
|
186
|
-
|
|
187
|
-
|
|
113
|
+
from: { maxHeight: 0 },
|
|
114
|
+
to: { maxHeight: height },
|
|
115
|
+
onUpdate: ({ maxHeight }) => {
|
|
116
|
+
el.style.maxHeight = `${maxHeight}px`;
|
|
188
117
|
},
|
|
189
|
-
to: {
|
|
190
|
-
maxHeight: rect.height + "px",
|
|
191
|
-
overflow: "hidden"
|
|
192
|
-
}
|
|
193
118
|
};
|
|
194
119
|
};
|
|
195
|
-
const collapseHorizontal = (
|
|
120
|
+
const collapseHorizontal = (el) => {
|
|
121
|
+
const width = el.getBoundingClientRect().width;
|
|
196
122
|
return {
|
|
197
|
-
from: {
|
|
198
|
-
|
|
199
|
-
|
|
123
|
+
from: { width: 0 },
|
|
124
|
+
to: { width },
|
|
125
|
+
onUpdate: ({ width }) => {
|
|
126
|
+
el.style.width = `${width}px`;
|
|
200
127
|
},
|
|
201
|
-
to: {
|
|
202
|
-
width: rect.width + "px",
|
|
203
|
-
overflow: "hidden"
|
|
204
|
-
}
|
|
205
128
|
};
|
|
206
129
|
};
|
|
207
130
|
|
|
208
|
-
export { collapseHorizontal, collapseVertical, fade, fadeDown, fadeLeft, fadeRight, fadeUp, grow,
|
|
131
|
+
export { collapseHorizontal, collapseVertical, fade, fadeDown, fadeLeft, fadeRight, fadeUp, grow, slideDown, slideLeft, slideRight, slideUp, zoom, zoomOver };
|
|
209
132
|
//# sourceMappingURL=variants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.js","sources":["../../src/Transition/variants.ts"],"sourcesContent":["\nconst getY = (
|
|
1
|
+
{"version":3,"file":"variants.js","sources":["../../src/Transition/variants.ts"],"sourcesContent":["\"use client\"\nconst getY = (el?: HTMLElement) => (el ? Math.min(el.getBoundingClientRect().height / 2, 40) : 20)\nconst getX = (el?: HTMLElement) => (el ? Math.min(el.getBoundingClientRect().width / 2, 40) : 20)\n\n// ------------------ Variants ------------------\n\nexport const slideDown = (el: HTMLElement) => {\n const y = getY(el)\n return {\n from: { y: -y },\n to: { y: 0 },\n onUpdate: ({ y }: any) => (el.style.transform = `translateY(${y}px)`),\n }\n}\n\nexport const slideUp = (el: HTMLElement) => {\n const y = getY(el)\n return {\n from: { y },\n to: { y: 0 },\n onUpdate: ({ y }: any) => (el.style.transform = `translateY(${y}px)`),\n }\n}\n\nexport const slideRight = (el: HTMLElement) => {\n const x = getX(el)\n return {\n from: { x: -x },\n to: { x: 0 },\n onUpdate: ({ x }: any) => (el.style.transform = `translateX(${x}px)`),\n }\n}\n\nexport const slideLeft = (el: HTMLElement) => {\n const x = getX(el)\n return {\n from: { x },\n to: { x: 0 },\n onUpdate: ({ x }: any) => (el.style.transform = `translateX(${x}px)`),\n }\n}\n\nexport const fade = (el: HTMLElement) => ({\n from: { opacity: 0 },\n to: { opacity: 1 },\n onUpdate: ({ opacity }: any) => (el.style.opacity = opacity),\n})\n\nexport const fadeDown = (el: HTMLElement) => {\n const y = getY(el)\n return {\n from: { y: -y, scale: 0.98, opacity: 0 },\n to: { y: 0, scale: 1, opacity: 1 },\n onUpdate: ({ y, scale, opacity }: any) => {\n el.style.transform = `translateY(${y}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeUp = (el: HTMLElement) => {\n const y = getY(el)\n return {\n from: { y, scale: 0.98, opacity: 0 },\n to: { y: 0, scale: 1, opacity: 1 },\n onUpdate: ({ y, scale, opacity }: any) => {\n el.style.transform = `translateY(${y}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeRight = (el: HTMLElement) => {\n const x = getX(el)\n return {\n from: { x: -x, scale: 0.98, opacity: 0 },\n to: { x: 0, scale: 1, opacity: 1 },\n onUpdate: ({ x, scale, opacity }: any) => {\n el.style.transform = `translateX(${x}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const fadeLeft = (el: HTMLElement) => {\n const x = getX(el)\n return {\n from: { x, scale: 0.98, opacity: 0 },\n to: { x: 0, scale: 1, opacity: 1 },\n onUpdate: ({ x, scale, opacity }: any) => {\n el.style.transform = `translateX(${x}px) scale(${scale})`\n el.style.opacity = String(opacity)\n }\n }\n}\n\nexport const zoom = (el: HTMLElement) => ({\n from: { scale: 0.8, opacity: 0 },\n to: { scale: 1, opacity: 1 },\n onUpdate: ({ scale, opacity }: any) => {\n el.style.transform = `scale(${scale})`\n el.style.opacity = String(opacity)\n },\n})\n\nexport const zoomOver = (el: HTMLElement) => ({\n from: { scale: 1.2, opacity: 0 },\n to: { scale: 1, opacity: 1 },\n onUpdate: ({ scale, opacity }: any) => {\n el.style.transform = `scale(${scale})`\n el.style.opacity = String(opacity)\n },\n})\n\nexport const grow = (el: HTMLElement) => ({\n from: { scaleX: 0.8, scaleY: 0.6, opacity: 0 },\n to: { scaleX: 1, scaleY: 1, opacity: 1 },\n onUpdate: ({ scaleX, scaleY, opacity }: any) => {\n el.style.transform = `scale(${scaleX}, ${scaleY})`\n el.style.opacity = String(opacity)\n }\n})\n\nexport const collapseVertical = (el: HTMLElement) => {\n const height = el.getBoundingClientRect().height\n return {\n from: { maxHeight: 0 },\n to: { maxHeight: height },\n onUpdate: ({ maxHeight }: any) => {\n el.style.maxHeight = `${maxHeight}px`\n },\n }\n}\n\nexport const collapseHorizontal = (el: HTMLElement) => {\n const width = el.getBoundingClientRect().width\n return {\n from: { width: 0 },\n to: { width },\n onUpdate: ({ width }: any) => {\n el.style.width = `${width}px`\n },\n }\n}"],"names":[],"mappings":";AACA;AACA;AAEA;AAEO;AACH;;AAEI;AACA;AACA;;AAER;AAEO;AACH;;;AAGI;AACA;;AAER;AAEO;AACH;;AAEI;AACA;AACA;;AAER;AAEO;AACH;;;AAGI;AACA;;AAER;;AAGI;AACA;AACA;AACH;AAEM;AACH;;AAEI;AACA;;;;;;AAMR;AAEO;AACH;;;AAGI;;;;;;AAMR;AAEO;AACH;;AAEI;AACA;;;;;;AAMR;AAEO;AACH;;;AAGI;;;;;;AAMR;;;;;;;;AASC;;;;;;;;AASA;;AAGG;AACA;;;;;AAKH;AAEM;;;AAGC;AACA;AACA;;;;AAIR;AAEO;;;AAGC;;AAEA;;;;AAIR;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const cubicBezier = (p1x, p1y, p2x, p2y) => {
|
|
5
|
+
return (t) => {
|
|
6
|
+
const cx = 3 * p1x;
|
|
7
|
+
const bx = 3 * (p2x - p1x) - cx;
|
|
8
|
+
const ax = 1 - cx - bx;
|
|
9
|
+
const cy = 3 * p1y;
|
|
10
|
+
const by = 3 * (p2y - p1y) - cy;
|
|
11
|
+
const ay = 1 - cy - by;
|
|
12
|
+
const sampleCurveX = (t) => ((ax * t + bx) * t + cx) * t;
|
|
13
|
+
const sampleCurveY = (t) => ((ay * t + by) * t + cy) * t;
|
|
14
|
+
const sampleCurveDerivativeX = (t) => (3 * ax * t + 2 * bx) * t + cx;
|
|
15
|
+
// Newton-Raphson
|
|
16
|
+
let x = t;
|
|
17
|
+
for (let i = 0; i < 5; i++) {
|
|
18
|
+
const dx = sampleCurveX(x) - t;
|
|
19
|
+
const d = sampleCurveDerivativeX(x);
|
|
20
|
+
if (Math.abs(dx) < 1e-6)
|
|
21
|
+
break;
|
|
22
|
+
if (Math.abs(d) < 1e-6)
|
|
23
|
+
break;
|
|
24
|
+
x = x - dx / d;
|
|
25
|
+
}
|
|
26
|
+
return sampleCurveY(x);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const Easing = {
|
|
30
|
+
default: (t) => 1 - Math.pow(1 - t, 3),
|
|
31
|
+
// your cubic-bezier mappings
|
|
32
|
+
standard: cubicBezier(0.4, 0, 0.2, 1),
|
|
33
|
+
fast: cubicBezier(0.2, 0, 0, 1),
|
|
34
|
+
smooth: cubicBezier(0.25, 0.46, 0.45, 0.94),
|
|
35
|
+
linear: cubicBezier(0, 0, 1, 1),
|
|
36
|
+
bounceBezier: cubicBezier(0.34, 1.5, 0.64, 1),
|
|
37
|
+
// existing easings
|
|
38
|
+
cubicInOut: (t) => t < 0.5
|
|
39
|
+
? 4 * t * t * t
|
|
40
|
+
: 1 - Math.pow(-2 * t + 2, 3) / 2,
|
|
41
|
+
easeOutBounce: (t) => {
|
|
42
|
+
const n1 = 7.5625;
|
|
43
|
+
const d1 = 2.75;
|
|
44
|
+
if (t < 1 / d1)
|
|
45
|
+
return n1 * t * t;
|
|
46
|
+
else if (t < 2 / d1)
|
|
47
|
+
return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
48
|
+
else if (t < 2.5 / d1)
|
|
49
|
+
return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
50
|
+
else
|
|
51
|
+
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
52
|
+
},
|
|
53
|
+
spring: (t) => {
|
|
54
|
+
return 1 - Math.exp(-6 * t) * Math.cos(8 * t);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = Easing;
|
|
59
|
+
//# sourceMappingURL=easing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easing.cjs","sources":["../../src/animate/easing.ts"],"sourcesContent":["\"use client\"\nconst cubicBezier = (p1x: number, p1y: number, p2x: number, p2y: number) => {\n return (t: number) => {\n const cx = 3 * p1x;\n const bx = 3 * (p2x - p1x) - cx;\n const ax = 1 - cx - bx;\n\n const cy = 3 * p1y;\n const by = 3 * (p2y - p1y) - cy;\n const ay = 1 - cy - by;\n\n const sampleCurveX = (t: number) => ((ax * t + bx) * t + cx) * t;\n const sampleCurveY = (t: number) => ((ay * t + by) * t + cy) * t;\n const sampleCurveDerivativeX = (t: number) =>\n (3 * ax * t + 2 * bx) * t + cx;\n\n // Newton-Raphson\n let x = t;\n for (let i = 0; i < 5; i++) {\n const dx = sampleCurveX(x) - t;\n const d = sampleCurveDerivativeX(x);\n if (Math.abs(dx) < 1e-6) break;\n if (Math.abs(d) < 1e-6) break;\n x = x - dx / d;\n }\n\n return sampleCurveY(x);\n };\n};\n\nconst Easing = {\n default: (t: number) => 1 - Math.pow(1 - t, 3),\n // your cubic-bezier mappings\n standard: cubicBezier(0.4, 0, 0.2, 1),\n fast: cubicBezier(0.2, 0, 0, 1),\n smooth: cubicBezier(0.25, 0.46, 0.45, 0.94),\n linear: cubicBezier(0, 0, 1, 1),\n bounceBezier: cubicBezier(0.34, 1.5, 0.64, 1),\n\n // existing easings\n cubicInOut: (t: number) =>\n t < 0.5\n ? 4 * t * t * t\n : 1 - Math.pow(-2 * t + 2, 3) / 2,\n\n easeOutBounce: (t: number) => {\n const n1 = 7.5625;\n const d1 = 2.75;\n if (t < 1 / d1) return n1 * t * t;\n else if (t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;\n else if (t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;\n else return n1 * (t -= 2.625 / d1) * t + 0.984375;\n },\n\n spring: (t: number) => {\n return 1 - Math.exp(-6 * t) * Math.cos(8 * t);\n },\n};\n\nexport default Easing"],"names":[],"mappings":";;;AACA;;AAEM;;AAEA;AAEA;;AAEA;;;;;;AASA;;AAEG;AACA;;AACA;;AACA;;AAGH;AACH;AACH;AAEA;AACG;;;;;;;;;AAWM;AACA;AAEN;;;AAGG;AAAgB;AACX;AAAgB;AAChB;AAAkB;;AAClB;;AAGR;;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const Easing: {
|
|
2
|
+
default: (t: number) => number;
|
|
3
|
+
standard: (t: number) => number;
|
|
4
|
+
fast: (t: number) => number;
|
|
5
|
+
smooth: (t: number) => number;
|
|
6
|
+
linear: (t: number) => number;
|
|
7
|
+
bounceBezier: (t: number) => number;
|
|
8
|
+
cubicInOut: (t: number) => number;
|
|
9
|
+
easeOutBounce: (t: number) => number;
|
|
10
|
+
spring: (t: number) => number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { Easing as default };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const cubicBezier = (p1x, p1y, p2x, p2y) => {
|
|
3
|
+
return (t) => {
|
|
4
|
+
const cx = 3 * p1x;
|
|
5
|
+
const bx = 3 * (p2x - p1x) - cx;
|
|
6
|
+
const ax = 1 - cx - bx;
|
|
7
|
+
const cy = 3 * p1y;
|
|
8
|
+
const by = 3 * (p2y - p1y) - cy;
|
|
9
|
+
const ay = 1 - cy - by;
|
|
10
|
+
const sampleCurveX = (t) => ((ax * t + bx) * t + cx) * t;
|
|
11
|
+
const sampleCurveY = (t) => ((ay * t + by) * t + cy) * t;
|
|
12
|
+
const sampleCurveDerivativeX = (t) => (3 * ax * t + 2 * bx) * t + cx;
|
|
13
|
+
// Newton-Raphson
|
|
14
|
+
let x = t;
|
|
15
|
+
for (let i = 0; i < 5; i++) {
|
|
16
|
+
const dx = sampleCurveX(x) - t;
|
|
17
|
+
const d = sampleCurveDerivativeX(x);
|
|
18
|
+
if (Math.abs(dx) < 1e-6)
|
|
19
|
+
break;
|
|
20
|
+
if (Math.abs(d) < 1e-6)
|
|
21
|
+
break;
|
|
22
|
+
x = x - dx / d;
|
|
23
|
+
}
|
|
24
|
+
return sampleCurveY(x);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const Easing = {
|
|
28
|
+
default: (t) => 1 - Math.pow(1 - t, 3),
|
|
29
|
+
// your cubic-bezier mappings
|
|
30
|
+
standard: cubicBezier(0.4, 0, 0.2, 1),
|
|
31
|
+
fast: cubicBezier(0.2, 0, 0, 1),
|
|
32
|
+
smooth: cubicBezier(0.25, 0.46, 0.45, 0.94),
|
|
33
|
+
linear: cubicBezier(0, 0, 1, 1),
|
|
34
|
+
bounceBezier: cubicBezier(0.34, 1.5, 0.64, 1),
|
|
35
|
+
// existing easings
|
|
36
|
+
cubicInOut: (t) => t < 0.5
|
|
37
|
+
? 4 * t * t * t
|
|
38
|
+
: 1 - Math.pow(-2 * t + 2, 3) / 2,
|
|
39
|
+
easeOutBounce: (t) => {
|
|
40
|
+
const n1 = 7.5625;
|
|
41
|
+
const d1 = 2.75;
|
|
42
|
+
if (t < 1 / d1)
|
|
43
|
+
return n1 * t * t;
|
|
44
|
+
else if (t < 2 / d1)
|
|
45
|
+
return n1 * (t -= 1.5 / d1) * t + 0.75;
|
|
46
|
+
else if (t < 2.5 / d1)
|
|
47
|
+
return n1 * (t -= 2.25 / d1) * t + 0.9375;
|
|
48
|
+
else
|
|
49
|
+
return n1 * (t -= 2.625 / d1) * t + 0.984375;
|
|
50
|
+
},
|
|
51
|
+
spring: (t) => {
|
|
52
|
+
return 1 - Math.exp(-6 * t) * Math.cos(8 * t);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { Easing as default };
|
|
57
|
+
//# sourceMappingURL=easing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easing.js","sources":["../../src/animate/easing.ts"],"sourcesContent":["\"use client\"\nconst cubicBezier = (p1x: number, p1y: number, p2x: number, p2y: number) => {\n return (t: number) => {\n const cx = 3 * p1x;\n const bx = 3 * (p2x - p1x) - cx;\n const ax = 1 - cx - bx;\n\n const cy = 3 * p1y;\n const by = 3 * (p2y - p1y) - cy;\n const ay = 1 - cy - by;\n\n const sampleCurveX = (t: number) => ((ax * t + bx) * t + cx) * t;\n const sampleCurveY = (t: number) => ((ay * t + by) * t + cy) * t;\n const sampleCurveDerivativeX = (t: number) =>\n (3 * ax * t + 2 * bx) * t + cx;\n\n // Newton-Raphson\n let x = t;\n for (let i = 0; i < 5; i++) {\n const dx = sampleCurveX(x) - t;\n const d = sampleCurveDerivativeX(x);\n if (Math.abs(dx) < 1e-6) break;\n if (Math.abs(d) < 1e-6) break;\n x = x - dx / d;\n }\n\n return sampleCurveY(x);\n };\n};\n\nconst Easing = {\n default: (t: number) => 1 - Math.pow(1 - t, 3),\n // your cubic-bezier mappings\n standard: cubicBezier(0.4, 0, 0.2, 1),\n fast: cubicBezier(0.2, 0, 0, 1),\n smooth: cubicBezier(0.25, 0.46, 0.45, 0.94),\n linear: cubicBezier(0, 0, 1, 1),\n bounceBezier: cubicBezier(0.34, 1.5, 0.64, 1),\n\n // existing easings\n cubicInOut: (t: number) =>\n t < 0.5\n ? 4 * t * t * t\n : 1 - Math.pow(-2 * t + 2, 3) / 2,\n\n easeOutBounce: (t: number) => {\n const n1 = 7.5625;\n const d1 = 2.75;\n if (t < 1 / d1) return n1 * t * t;\n else if (t < 2 / d1) return n1 * (t -= 1.5 / d1) * t + 0.75;\n else if (t < 2.5 / d1) return n1 * (t -= 2.25 / d1) * t + 0.9375;\n else return n1 * (t -= 2.625 / d1) * t + 0.984375;\n },\n\n spring: (t: number) => {\n return 1 - Math.exp(-6 * t) * Math.cos(8 * t);\n },\n};\n\nexport default Easing"],"names":[],"mappings":";AACA;;AAEM;;AAEA;AAEA;;AAEA;;;;;;AASA;;AAEG;AACA;;AACA;;AACA;;AAGH;AACH;AACH;AAEA;AACG;;;;;;;;;AAWM;AACA;AAEN;;;AAGG;AAAgB;AACX;AAAgB;AAChB;AAAkB;;AAClB;;AAGR;;;;;"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var easing = require('./easing.cjs');
|
|
7
|
+
|
|
8
|
+
const animate = ({ from, to, duration = 400, delay = 0, easing: easing$1 = easing.default, onUpdate, onDone, breakpoints, repeat = 0, repeatBack = false, }) => {
|
|
9
|
+
let rafId;
|
|
10
|
+
let cycle = 0;
|
|
11
|
+
let forward = true;
|
|
12
|
+
// Track triggered breakpoints
|
|
13
|
+
const triggered = {};
|
|
14
|
+
const resolve = (val) => typeof val === "function" ? val() : val;
|
|
15
|
+
const getEased = (key, t) => {
|
|
16
|
+
if (typeof easing$1 === "function")
|
|
17
|
+
return easing$1(t);
|
|
18
|
+
if (easing$1[key])
|
|
19
|
+
return easing$1[key](t);
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
const startAnimation = () => {
|
|
23
|
+
const fromVal = resolve(from);
|
|
24
|
+
const toVal = resolve(to);
|
|
25
|
+
const keys = Object.keys(fromVal);
|
|
26
|
+
if (breakpoints) {
|
|
27
|
+
for (const key of keys)
|
|
28
|
+
triggered[key] = new Set();
|
|
29
|
+
}
|
|
30
|
+
const start = performance.now();
|
|
31
|
+
const frame = (now) => {
|
|
32
|
+
const progress = duration === 0 ? 1 : Math.min((now - start) / duration, 1);
|
|
33
|
+
const current = {};
|
|
34
|
+
for (const key of keys) {
|
|
35
|
+
const f = forward ? fromVal[key] : toVal[key];
|
|
36
|
+
const t = forward ? toVal[key] : fromVal[key];
|
|
37
|
+
const eased = getEased(key, progress);
|
|
38
|
+
const val = f + (t - f) * eased;
|
|
39
|
+
current[key] = val;
|
|
40
|
+
// breakpoints
|
|
41
|
+
const bps = breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints[key];
|
|
42
|
+
if (bps) {
|
|
43
|
+
for (let i = 0; i < bps.length; i++) {
|
|
44
|
+
const triggeredSet = triggered[key];
|
|
45
|
+
if (!triggeredSet.has(i) &&
|
|
46
|
+
((f < t && val >= bps[i].value) ||
|
|
47
|
+
(f > t && val <= bps[i].value))) {
|
|
48
|
+
triggeredSet.add(i);
|
|
49
|
+
bps[i].callback();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
onUpdate(current, progress);
|
|
55
|
+
if (progress < 1) {
|
|
56
|
+
rafId = requestAnimationFrame(frame);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const finalState = forward ? toVal : fromVal;
|
|
60
|
+
onUpdate(finalState, 1);
|
|
61
|
+
// fire remaining breakpoints
|
|
62
|
+
if (breakpoints) {
|
|
63
|
+
for (const key of keys) {
|
|
64
|
+
const bps = breakpoints[key];
|
|
65
|
+
if (!bps)
|
|
66
|
+
continue;
|
|
67
|
+
const triggeredSet = triggered[key];
|
|
68
|
+
for (let i = 0; i < bps.length; i++) {
|
|
69
|
+
if (!triggeredSet.has(i)) {
|
|
70
|
+
triggeredSet.add(i);
|
|
71
|
+
bps[i].callback();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
cycle++;
|
|
77
|
+
if (cycle <= repeat) {
|
|
78
|
+
if (repeatBack)
|
|
79
|
+
forward = !forward;
|
|
80
|
+
startAnimation(); // 🔁 re-run with fresh from/to if functions
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
onDone === null || onDone === void 0 ? void 0 : onDone();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
rafId = requestAnimationFrame(frame);
|
|
88
|
+
};
|
|
89
|
+
if (delay > 0) {
|
|
90
|
+
const timeout = setTimeout(startAnimation, delay);
|
|
91
|
+
return () => {
|
|
92
|
+
clearTimeout(timeout);
|
|
93
|
+
cancelAnimationFrame(rafId);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
startAnimation();
|
|
98
|
+
return () => cancelAnimationFrame(rafId);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.Easing = easing;
|
|
103
|
+
exports.default = animate;
|
|
104
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/animate/index.ts"],"sourcesContent":["\"use client\"\nimport Easing from \"./easing\";\n\nexport { Easing };\n\nexport type AnimateOptions<T extends Record<string, number>> = {\n from: T | (() => T);\n to: T | (() => T);\n duration?: number;\n delay?: number;\n easing?: ((t: number) => number) | Partial<Record<keyof T, (t: number) => number>>;\n onUpdate: (value: T, progress: number) => void;\n onDone?: () => void;\n breakpoints?: Partial<Record<keyof T, Array<{ value: number; callback: () => void }>>>;\n repeat?: number;\n repeatBack?: boolean;\n};\n\nconst animate = <T extends Record<string, number>>({\n from,\n to,\n duration = 400,\n delay = 0,\n easing = Easing.default,\n onUpdate,\n onDone,\n breakpoints,\n repeat = 0,\n repeatBack = false,\n}: AnimateOptions<T>) => {\n let rafId: number;\n let cycle = 0;\n let forward = true;\n\n // Track triggered breakpoints\n const triggered: Partial<Record<keyof T, Set<number>>> = {};\n\n const resolve = (val: T | (() => T)): T =>\n typeof val === \"function\" ? (val as () => T)() : val;\n\n const getEased = (key: keyof T, t: number) => {\n if (typeof easing === \"function\") return easing(t);\n if (easing[key]) return easing[key]!(t);\n return t;\n };\n\n const startAnimation = () => {\n const fromVal = resolve(from);\n const toVal = resolve(to);\n\n const keys = Object.keys(fromVal) as (keyof T)[];\n\n if (breakpoints) {\n for (const key of keys) triggered[key] = new Set();\n }\n\n const start = performance.now();\n\n const frame = (now: number) => {\n const progress =\n duration === 0 ? 1 : Math.min((now - start) / duration, 1);\n\n const current: any = {} as T;\n\n for (const key of keys) {\n const f = forward ? fromVal[key] : toVal[key];\n const t = forward ? toVal[key] : fromVal[key];\n\n const eased = getEased(key, progress);\n const val = f + (t - f) * eased;\n current[key] = val;\n\n // breakpoints\n const bps = breakpoints?.[key];\n if (bps) {\n for (let i = 0; i < bps.length; i++) {\n const triggeredSet = triggered[key]!;\n if (\n !triggeredSet.has(i) &&\n ((f < t && val >= bps[i].value) ||\n (f > t && val <= bps[i].value))\n ) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n onUpdate(current, progress);\n\n if (progress < 1) {\n rafId = requestAnimationFrame(frame);\n } else {\n const finalState = forward ? toVal : fromVal;\n onUpdate(finalState, 1);\n\n // fire remaining breakpoints\n if (breakpoints) {\n for (const key of keys) {\n const bps = breakpoints[key];\n if (!bps) continue;\n\n const triggeredSet = triggered[key]!;\n for (let i = 0; i < bps.length; i++) {\n if (!triggeredSet.has(i)) {\n triggeredSet.add(i);\n bps[i].callback();\n }\n }\n }\n }\n\n cycle++;\n\n if (cycle <= repeat) {\n if (repeatBack) forward = !forward;\n startAnimation(); // 🔁 re-run with fresh from/to if functions\n } else {\n onDone?.();\n }\n }\n };\n\n rafId = requestAnimationFrame(frame);\n };\n\n if (delay > 0) {\n const timeout = setTimeout(startAnimation, delay);\n return () => {\n clearTimeout(timeout);\n cancelAnimationFrame(rafId);\n };\n } else {\n startAnimation();\n return () => cancelAnimationFrame(rafId);\n }\n};\n\nexport default animate;"],"names":[],"mappings":";;;;;;;AAkBA;AAYG;;;;;;AAUA;;AACqC;;AACjB;AACjB;AACH;;AAGG;AACA;;;;AAK2B;;AAG3B;AAEA;;;AAMG;AACG;AACA;;;AAIA;;;;AAKG;AACG;AACA;AAEG;AACG;AAEH;AACA;;;;;AAMZ;AAEA;AACG;;;;AAGA;;;AAIG;AACG;AACA;;AAEA;AACA;;AAEM;AACA;;;;;AAMZ;AAEA;AACG;;;;;AAGA;;;AAGT;AAEA;AACH;AAEA;;AAEG;;;AAGA;;;AAEA;AACA;;AAEN;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type AnimateOptions<T extends Record<string, number>> = {
|
|
2
|
+
from: T | (() => T);
|
|
3
|
+
to: T | (() => T);
|
|
4
|
+
duration?: number;
|
|
5
|
+
delay?: number;
|
|
6
|
+
easing?: ((t: number) => number) | Partial<Record<keyof T, (t: number) => number>>;
|
|
7
|
+
onUpdate: (value: T, progress: number) => void;
|
|
8
|
+
onDone?: () => void;
|
|
9
|
+
breakpoints?: Partial<Record<keyof T, Array<{
|
|
10
|
+
value: number;
|
|
11
|
+
callback: () => void;
|
|
12
|
+
}>>>;
|
|
13
|
+
repeat?: number;
|
|
14
|
+
repeatBack?: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare const animate: <T extends Record<string, number>>({ from, to, duration, delay, easing, onUpdate, onDone, breakpoints, repeat, repeatBack, }: AnimateOptions<T>) => () => void;
|
|
17
|
+
|
|
18
|
+
export { animate as default };
|
|
19
|
+
export type { AnimateOptions };
|