@nice2dev/icons 1.3.15 → 1.3.17
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/CHANGELOG.md +26 -0
- package/README.md +1 -1
- package/dist/cjs/NiceDesktopIconExporter.js +688 -599
- package/dist/cjs/NiceFaviconGenerator.js +603 -417
- package/dist/cjs/NiceIconPicker.js +788 -508
- package/dist/cjs/NiceIconPreview.js +246 -188
- package/dist/cjs/NiceIconSetCreator.js +683 -552
- package/dist/cjs/NiceIconStacker.js +547 -171
- package/dist/cjs/NiceIconValue.js +27 -35
- package/dist/cjs/NtdIconBadge.js +384 -360
- package/dist/cjs/NtdIconMorph.js +419 -354
- package/dist/cjs/NtdStateMorph.js +150 -147
- package/dist/cjs/advancedIconSearch.js +373 -510
- package/dist/cjs/animationControls.js +518 -642
- package/dist/cjs/animationSpeed.js +69 -0
- package/dist/cjs/client.js +12 -15
- package/dist/cjs/createIcon.js +374 -252
- package/dist/cjs/design-tokens.js +324 -390
- package/dist/cjs/figmaExport.js +162 -257
- package/dist/cjs/figmaSync.js +234 -316
- package/dist/cjs/headless-ui.js +240 -368
- package/dist/cjs/iconAnalytics.js +337 -393
- package/dist/cjs/iconHtml.js +64 -86
- package/dist/cjs/iconMetadata.js +392 -472
- package/dist/cjs/iconParts.js +120 -90
- package/dist/cjs/iconStack.js +136 -155
- package/dist/cjs/iconStyles.js +1670 -509
- package/dist/cjs/iconValue.js +359 -430
- package/dist/cjs/icons/accessibility.js +1119 -134
- package/dist/cjs/icons/actions.js +1290 -330
- package/dist/cjs/icons/ai.js +1424 -144
- package/dist/cjs/icons/brand.js +613 -184
- package/dist/cjs/icons/business.js +938 -192
- package/dist/cjs/icons/devtech.js +1656 -227
- package/dist/cjs/icons/ecommerce.js +802 -111
- package/dist/cjs/icons/education.js +1345 -199
- package/dist/cjs/icons/files.js +1597 -328
- package/dist/cjs/icons/fintech.js +793 -104
- package/dist/cjs/icons/food.js +1028 -156
- package/dist/cjs/icons/fun.js +804 -109
- package/dist/cjs/icons/gaming.js +916 -170
- package/dist/cjs/icons/health.js +623 -112
- package/dist/cjs/icons/index.js +32 -42
- package/dist/cjs/icons/input.js +282 -83
- package/dist/cjs/icons/legal.js +1065 -122
- package/dist/cjs/icons/media.js +1061 -267
- package/dist/cjs/icons/navigation.js +407 -123
- package/dist/cjs/icons/omniverk.js +523 -93
- package/dist/cjs/icons/realestate.js +1520 -193
- package/dist/cjs/icons/saas.js +867 -98
- package/dist/cjs/icons/science.js +1344 -202
- package/dist/cjs/icons/shapes.js +1316 -308
- package/dist/cjs/icons/smarthome.js +786 -90
- package/dist/cjs/icons/social.js +591 -59
- package/dist/cjs/icons/sports.js +1133 -133
- package/dist/cjs/icons/sustainability.js +1211 -139
- package/dist/cjs/icons/travel.js +1470 -148
- package/dist/cjs/icons/ui.js +1508 -315
- package/dist/cjs/icons/weather.js +1160 -173
- package/dist/cjs/index.js +559 -568
- package/dist/cjs/lottieIntegration.js +261 -266
- package/dist/cjs/nicetodev-icons.css +1 -1
- package/dist/cjs/particleEffects.js +270 -251
- package/dist/cjs/resolver.js +229 -284
- package/dist/cjs/rsc.js +175 -193
- package/dist/cjs/sharpen.js +73 -130
- package/dist/cjs/smilAnimations.js +380 -165
- package/dist/cjs/stacking.js +87 -122
- package/dist/cjs/tailwind-plugin.js +280 -320
- package/dist/cjs/types.js +46 -72
- package/dist/cjs/utilities.js +163 -324
- package/dist/cjs/variantProps.js +12 -52
- package/dist/esm/NiceDesktopIconExporter.js +671 -598
- package/dist/esm/NiceFaviconGenerator.js +583 -416
- package/dist/esm/NiceIconPicker.js +789 -507
- package/dist/esm/NiceIconPreview.js +247 -187
- package/dist/esm/NiceIconSetCreator.js +685 -551
- package/dist/esm/NiceIconStacker.js +549 -170
- package/dist/esm/NiceIconValue.js +29 -34
- package/dist/esm/NtdIconBadge.js +388 -359
- package/dist/esm/NtdIconMorph.js +423 -353
- package/dist/esm/NtdStateMorph.js +152 -146
- package/dist/esm/advancedIconSearch.js +391 -509
- package/dist/esm/animationControls.js +527 -641
- package/dist/esm/animationSpeed.js +69 -0
- package/dist/esm/client.js +48 -10
- package/dist/esm/createIcon.js +375 -251
- package/dist/esm/design-tokens.js +334 -387
- package/dist/esm/figmaExport.js +170 -256
- package/dist/esm/figmaSync.js +237 -315
- package/dist/esm/headless-ui.js +254 -365
- package/dist/esm/iconAnalytics.js +342 -392
- package/dist/esm/iconHtml.js +67 -85
- package/dist/esm/iconMetadata.js +404 -471
- package/dist/esm/iconParts.js +125 -89
- package/dist/esm/iconStack.js +145 -154
- package/dist/esm/iconStyles.js +1681 -508
- package/dist/esm/iconValue.js +361 -429
- package/dist/esm/icons/accessibility.js +1133 -133
- package/dist/esm/icons/actions.js +1320 -329
- package/dist/esm/icons/ai.js +1441 -143
- package/dist/esm/icons/brand.js +616 -179
- package/dist/esm/icons/business.js +957 -191
- package/dist/esm/icons/devtech.js +1687 -226
- package/dist/esm/icons/ecommerce.js +816 -110
- package/dist/esm/icons/education.js +1364 -198
- package/dist/esm/icons/files.js +1628 -327
- package/dist/esm/icons/fintech.js +807 -103
- package/dist/esm/icons/food.js +1043 -153
- package/dist/esm/icons/fun.js +819 -108
- package/dist/esm/icons/gaming.js +933 -169
- package/dist/esm/icons/health.js +636 -111
- package/dist/esm/icons/index.js +589 -32
- package/dist/esm/icons/input.js +326 -82
- package/dist/esm/icons/legal.js +1079 -121
- package/dist/esm/icons/media.js +1086 -266
- package/dist/esm/icons/navigation.js +421 -122
- package/dist/esm/icons/omniverk.js +534 -91
- package/dist/esm/icons/realestate.js +1544 -198
- package/dist/esm/icons/saas.js +880 -97
- package/dist/esm/icons/science.js +1370 -208
- package/dist/esm/icons/shapes.js +1343 -307
- package/dist/esm/icons/smarthome.js +799 -89
- package/dist/esm/icons/social.js +599 -58
- package/dist/esm/icons/sports.js +1148 -132
- package/dist/esm/icons/sustainability.js +1226 -138
- package/dist/esm/icons/travel.js +1486 -147
- package/dist/esm/icons/ui.js +1540 -314
- package/dist/esm/icons/weather.js +1181 -172
- package/dist/esm/index.js +749 -58
- package/dist/esm/lottieIntegration.js +264 -265
- package/dist/esm/nicetodev-icons.css +1 -1
- package/dist/esm/particleEffects.js +271 -250
- package/dist/esm/resolver.js +231 -283
- package/dist/esm/rsc.js +182 -192
- package/dist/esm/sharpen.js +78 -129
- package/dist/esm/smilAnimations.js +385 -164
- package/dist/esm/stacking.js +99 -121
- package/dist/esm/tailwind-plugin.js +282 -319
- package/dist/esm/types.js +50 -71
- package/dist/esm/utilities.js +177 -321
- package/dist/esm/variantProps.js +23 -52
- package/dist/types/animationSpeed.d.ts +19 -0
- package/dist/types/createIcon.d.ts +6 -0
- package/dist/types/iconStyles.d.ts +6 -1
- package/dist/types/icons/brand.d.ts +0 -4
- package/dist/types/icons/food.d.ts +0 -3
- package/dist/types/icons/index.d.ts +3 -3
- package/dist/types/icons/omniverk.d.ts +0 -3
- package/dist/types/icons/science.d.ts +1 -1
- package/dist/types/smilAnimations.d.ts +4 -2
- package/dist/types/types.d.ts +7 -0
- package/package.json +15 -22
|
@@ -1,693 +1,569 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/* ────────────────────────────────────────────────────────────────────────────
|
|
7
|
-
2. HELPER FUNCTIONS
|
|
8
|
-
───────────────────────────────────────────────────────────────────────────── */
|
|
9
|
-
/**
|
|
10
|
-
* Build CSS class for animation
|
|
11
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
12
5
|
function getAnimationClass(animation) {
|
|
13
|
-
|
|
6
|
+
return `ntd-anim-${animation}`;
|
|
14
7
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
animationDelay: `${delay}ms`,
|
|
26
|
-
animationFillMode: 'forwards',
|
|
27
|
-
};
|
|
8
|
+
function getAnimationStyle(animation, duration = 1e3, easing = "ease-in-out", iterations = 1, delay = 0) {
|
|
9
|
+
const iterationValue = iterations < 0 ? "infinite" : iterations;
|
|
10
|
+
return {
|
|
11
|
+
animationName: `ntd-${animation}`,
|
|
12
|
+
animationDuration: `${duration}ms`,
|
|
13
|
+
animationTimingFunction: easing,
|
|
14
|
+
animationIterationCount: iterationValue,
|
|
15
|
+
animationDelay: `${delay}ms`,
|
|
16
|
+
animationFillMode: "forwards"
|
|
17
|
+
};
|
|
28
18
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Check if config is a sequence
|
|
31
|
-
*/
|
|
32
19
|
function isSequenceConfig(config) {
|
|
33
|
-
|
|
20
|
+
return typeof config === "object" && "steps" in config;
|
|
34
21
|
}
|
|
35
|
-
/* ────────────────────────────────────────────────────────────────────────────
|
|
36
|
-
3. ANIMATION SEQUENCE HOOK
|
|
37
|
-
───────────────────────────────────────────────────────────────────────────── */
|
|
38
|
-
/**
|
|
39
|
-
* Hook to manage animation sequences
|
|
40
|
-
*/
|
|
41
22
|
function useAnimationSequence(config) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
23
|
+
const [currentStepIndex, setCurrentStepIndex] = React.useState(0);
|
|
24
|
+
const [loopIteration, setLoopIteration] = React.useState(0);
|
|
25
|
+
const [state, setState] = React.useState("idle");
|
|
26
|
+
const [direction, setDirection] = React.useState("forward");
|
|
27
|
+
const timeoutRef = React.useRef(null);
|
|
28
|
+
const startTimeRef = React.useRef(0);
|
|
29
|
+
const elapsedRef = React.useRef(0);
|
|
30
|
+
const steps = React.useMemo(() => {
|
|
31
|
+
if (config.direction === "reverse") {
|
|
32
|
+
return [...config.steps].reverse();
|
|
33
|
+
}
|
|
34
|
+
return config.steps;
|
|
35
|
+
}, [config.steps, config.direction]);
|
|
36
|
+
const currentStep = steps[currentStepIndex];
|
|
37
|
+
const clearTimer = React.useCallback(() => {
|
|
38
|
+
if (timeoutRef.current) {
|
|
39
|
+
clearTimeout(timeoutRef.current);
|
|
40
|
+
timeoutRef.current = null;
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
43
|
+
const play = React.useCallback(() => {
|
|
44
|
+
if (state === "finished") {
|
|
45
|
+
setCurrentStepIndex(0);
|
|
46
|
+
setLoopIteration(0);
|
|
47
|
+
elapsedRef.current = 0;
|
|
48
|
+
}
|
|
49
|
+
setState("playing");
|
|
50
|
+
startTimeRef.current = Date.now();
|
|
51
|
+
}, [state]);
|
|
52
|
+
const pause = React.useCallback(() => {
|
|
53
|
+
if (state === "playing") {
|
|
54
|
+
clearTimer();
|
|
55
|
+
elapsedRef.current += Date.now() - startTimeRef.current;
|
|
56
|
+
setState("paused");
|
|
57
|
+
}
|
|
58
|
+
}, [state, clearTimer]);
|
|
59
|
+
const reset = React.useCallback(() => {
|
|
60
|
+
clearTimer();
|
|
61
|
+
setCurrentStepIndex(0);
|
|
62
|
+
setLoopIteration(0);
|
|
63
|
+
setDirection("forward");
|
|
64
|
+
elapsedRef.current = 0;
|
|
65
|
+
setState("idle");
|
|
66
|
+
}, [clearTimer]);
|
|
67
|
+
const goToStep = React.useCallback(
|
|
68
|
+
(index) => {
|
|
69
|
+
if (index >= 0 && index < steps.length) {
|
|
80
70
|
clearTimer();
|
|
81
|
-
setCurrentStepIndex(
|
|
82
|
-
setLoopIteration(0);
|
|
83
|
-
setDirection('forward');
|
|
71
|
+
setCurrentStepIndex(index);
|
|
84
72
|
elapsedRef.current = 0;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const goToStep = React.useCallback((index) => {
|
|
88
|
-
if (index >= 0 && index < steps.length) {
|
|
89
|
-
clearTimer();
|
|
90
|
-
setCurrentStepIndex(index);
|
|
91
|
-
elapsedRef.current = 0;
|
|
92
|
-
if (state === 'playing') {
|
|
93
|
-
startTimeRef.current = Date.now();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}, [steps.length, clearTimer, state]);
|
|
97
|
-
const getProgress = React.useCallback(() => {
|
|
98
|
-
if (state === 'idle') {
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
if (state === 'finished') {
|
|
102
|
-
return 1;
|
|
103
|
-
}
|
|
104
|
-
const stepProgress = currentStepIndex / steps.length;
|
|
105
|
-
return stepProgress;
|
|
106
|
-
}, [state, currentStepIndex, steps.length]);
|
|
107
|
-
// Handle step progression
|
|
108
|
-
React.useEffect(() => {
|
|
109
|
-
if (state !== 'playing' || !currentStep) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const stepDuration = (currentStep.duration || 1000) * (currentStep.iterations || 1);
|
|
113
|
-
const remainingTime = stepDuration - elapsedRef.current;
|
|
114
|
-
timeoutRef.current = setTimeout(() => {
|
|
115
|
-
elapsedRef.current = 0;
|
|
116
|
-
// Determine next step
|
|
117
|
-
let nextStepIndex;
|
|
118
|
-
if (config.direction === 'alternate') {
|
|
119
|
-
if (direction === 'forward') {
|
|
120
|
-
if (currentStepIndex >= steps.length - 1) {
|
|
121
|
-
setDirection('backward');
|
|
122
|
-
nextStepIndex = currentStepIndex - 1;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
nextStepIndex = currentStepIndex + 1;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
if (currentStepIndex <= 0) {
|
|
130
|
-
setDirection('forward');
|
|
131
|
-
nextStepIndex = currentStepIndex + 1;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
nextStepIndex = currentStepIndex - 1;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
nextStepIndex = currentStepIndex + 1;
|
|
140
|
-
}
|
|
141
|
-
// Check if sequence complete
|
|
142
|
-
if (nextStepIndex >= steps.length && config.direction !== 'alternate') {
|
|
143
|
-
if (config.loop) {
|
|
144
|
-
const newIteraton = loopIteration + 1;
|
|
145
|
-
if (config.loopCount && newIteraton >= config.loopCount) {
|
|
146
|
-
setState('finished');
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
setLoopIteration(newIteraton);
|
|
150
|
-
setCurrentStepIndex(0);
|
|
151
|
-
// Apply loop delay
|
|
152
|
-
if (config.loopDelay) {
|
|
153
|
-
setState('paused');
|
|
154
|
-
timeoutRef.current = setTimeout(() => {
|
|
155
|
-
setState('playing');
|
|
156
|
-
startTimeRef.current = Date.now();
|
|
157
|
-
}, config.loopDelay);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
startTimeRef.current = Date.now();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
setState('finished');
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
else if (nextStepIndex >= 0 && nextStepIndex < steps.length) {
|
|
169
|
-
setCurrentStepIndex(nextStepIndex);
|
|
170
|
-
startTimeRef.current = Date.now();
|
|
171
|
-
}
|
|
172
|
-
}, remainingTime + (currentStep.delay || 0));
|
|
173
|
-
return clearTimer;
|
|
174
|
-
}, [
|
|
175
|
-
state,
|
|
176
|
-
currentStep,
|
|
177
|
-
currentStepIndex,
|
|
178
|
-
steps.length,
|
|
179
|
-
direction,
|
|
180
|
-
config.loop,
|
|
181
|
-
config.loopCount,
|
|
182
|
-
config.loopDelay,
|
|
183
|
-
config.direction,
|
|
184
|
-
loopIteration,
|
|
185
|
-
clearTimer,
|
|
186
|
-
]);
|
|
187
|
-
return {
|
|
188
|
-
currentStep,
|
|
189
|
-
currentStepIndex,
|
|
190
|
-
state,
|
|
191
|
-
loopIteration,
|
|
192
|
-
play,
|
|
193
|
-
pause,
|
|
194
|
-
reset,
|
|
195
|
-
goToStep,
|
|
196
|
-
getProgress,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
/* ────────────────────────────────────────────────────────────────────────────
|
|
200
|
-
4. ANIMATION CONTROLLER COMPONENT
|
|
201
|
-
───────────────────────────────────────────────────────────────────────────── */
|
|
202
|
-
/**
|
|
203
|
-
* Animation Controller component
|
|
204
|
-
*
|
|
205
|
-
* Wraps an icon and provides play/pause/reset controls.
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```tsx
|
|
209
|
-
* const ref = useRef<AnimationControllerHandle>(null);
|
|
210
|
-
*
|
|
211
|
-
* <AnimationController
|
|
212
|
-
* ref={ref}
|
|
213
|
-
* animation="spin"
|
|
214
|
-
* autoPlay={false}
|
|
215
|
-
* >
|
|
216
|
-
* <NiceIcon name="loading" />
|
|
217
|
-
* </AnimationController>
|
|
218
|
-
*
|
|
219
|
-
* <button onClick={() => ref.current?.play()}>Play</button>
|
|
220
|
-
* <button onClick={() => ref.current?.pause()}>Pause</button>
|
|
221
|
-
* <button onClick={() => ref.current?.reset()}>Reset</button>
|
|
222
|
-
* ```
|
|
223
|
-
*
|
|
224
|
-
* @example Sequence
|
|
225
|
-
* ```tsx
|
|
226
|
-
* <AnimationController
|
|
227
|
-
* animation={{
|
|
228
|
-
* steps: [
|
|
229
|
-
* { animation: 'bounce', duration: 500 },
|
|
230
|
-
* { animation: 'spin', duration: 1000 },
|
|
231
|
-
* { animation: 'pulse', duration: 800 },
|
|
232
|
-
* ],
|
|
233
|
-
* loop: true,
|
|
234
|
-
* loopCount: 3
|
|
235
|
-
* }}
|
|
236
|
-
* autoPlay
|
|
237
|
-
* >
|
|
238
|
-
* <NiceIcon name="star" />
|
|
239
|
-
* </AnimationController>
|
|
240
|
-
* ```
|
|
241
|
-
*/
|
|
242
|
-
const AnimationController = /* @__PURE__ */ React.forwardRef(function AnimationController(props, ref) {
|
|
243
|
-
const { children, animation, autoPlay = false, playState: externalPlayState, onStart, onEnd, onStepChange, onPause, onResume, className, style, } = props;
|
|
244
|
-
// Determine if sequence or single animation
|
|
245
|
-
const isSequence = isSequenceConfig(animation);
|
|
246
|
-
// For single animations
|
|
247
|
-
const [singleState, setSingleState] = React.useState(autoPlay ? 'playing' : 'idle');
|
|
248
|
-
const singleIterationRef = React.useRef(0);
|
|
249
|
-
// For sequences
|
|
250
|
-
const sequenceConfig = isSequence ? animation : { steps: [{ animation, duration: 1000 }] };
|
|
251
|
-
const sequence = useAnimationSequence(sequenceConfig);
|
|
252
|
-
// Unified state
|
|
253
|
-
const state = isSequence ? sequence.state : singleState;
|
|
254
|
-
const currentStepIndex = isSequence ? sequence.currentStepIndex : 0;
|
|
255
|
-
// Handle external playState control
|
|
256
|
-
React.useEffect(() => {
|
|
257
|
-
if (externalPlayState !== undefined) {
|
|
258
|
-
if (isSequence) {
|
|
259
|
-
if (externalPlayState === 'playing') {
|
|
260
|
-
sequence.play();
|
|
261
|
-
}
|
|
262
|
-
else if (externalPlayState === 'paused') {
|
|
263
|
-
sequence.pause();
|
|
264
|
-
}
|
|
265
|
-
else if (externalPlayState === 'idle') {
|
|
266
|
-
sequence.reset();
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
setSingleState(externalPlayState);
|
|
271
|
-
}
|
|
73
|
+
if (state === "playing") {
|
|
74
|
+
startTimeRef.current = Date.now();
|
|
272
75
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
onPause === null || onPause === void 0 ? void 0 : onPause();
|
|
305
|
-
}
|
|
306
|
-
else if (state === 'finished') {
|
|
307
|
-
onEnd === null || onEnd === void 0 ? void 0 : onEnd();
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
[steps.length, clearTimer, state]
|
|
79
|
+
);
|
|
80
|
+
const getProgress = React.useCallback(() => {
|
|
81
|
+
if (state === "idle") {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
if (state === "finished") {
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
const stepProgress = currentStepIndex / steps.length;
|
|
88
|
+
return stepProgress;
|
|
89
|
+
}, [state, currentStepIndex, steps.length]);
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
if (state !== "playing" || !currentStep) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const stepDuration = (currentStep.duration || 1e3) * (currentStep.iterations || 1);
|
|
95
|
+
const remainingTime = stepDuration - elapsedRef.current;
|
|
96
|
+
timeoutRef.current = setTimeout(
|
|
97
|
+
() => {
|
|
98
|
+
elapsedRef.current = 0;
|
|
99
|
+
let nextStepIndex;
|
|
100
|
+
if (config.direction === "alternate") {
|
|
101
|
+
if (direction === "forward") {
|
|
102
|
+
if (currentStepIndex >= steps.length - 1) {
|
|
103
|
+
setDirection("backward");
|
|
104
|
+
nextStepIndex = currentStepIndex - 1;
|
|
105
|
+
} else {
|
|
106
|
+
nextStepIndex = currentStepIndex + 1;
|
|
308
107
|
}
|
|
309
|
-
|
|
310
|
-
|
|
108
|
+
} else {
|
|
109
|
+
if (currentStepIndex <= 0) {
|
|
110
|
+
setDirection("forward");
|
|
111
|
+
nextStepIndex = currentStepIndex + 1;
|
|
112
|
+
} else {
|
|
113
|
+
nextStepIndex = currentStepIndex - 1;
|
|
311
114
|
}
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
nextStepIndex = currentStepIndex + 1;
|
|
312
118
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
setSingleState('paused');
|
|
333
|
-
}
|
|
334
|
-
onPause === null || onPause === void 0 ? void 0 : onPause();
|
|
335
|
-
},
|
|
336
|
-
reset: () => {
|
|
337
|
-
if (isSequence) {
|
|
338
|
-
sequence.reset();
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
setSingleState('idle');
|
|
342
|
-
singleIterationRef.current++;
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
goToStep: (index) => {
|
|
346
|
-
if (isSequence) {
|
|
347
|
-
sequence.goToStep(index);
|
|
348
|
-
}
|
|
349
|
-
},
|
|
350
|
-
getState: () => state,
|
|
351
|
-
getCurrentStep: () => currentStepIndex,
|
|
352
|
-
getProgress: () => {
|
|
353
|
-
if (isSequence) {
|
|
354
|
-
return sequence.getProgress();
|
|
119
|
+
if (nextStepIndex >= steps.length && config.direction !== "alternate") {
|
|
120
|
+
if (config.loop) {
|
|
121
|
+
const newIteraton = loopIteration + 1;
|
|
122
|
+
if (config.loopCount && newIteraton >= config.loopCount) {
|
|
123
|
+
setState("finished");
|
|
124
|
+
} else {
|
|
125
|
+
setLoopIteration(newIteraton);
|
|
126
|
+
setCurrentStepIndex(0);
|
|
127
|
+
if (config.loopDelay) {
|
|
128
|
+
setState("paused");
|
|
129
|
+
timeoutRef.current = setTimeout(() => {
|
|
130
|
+
setState("playing");
|
|
131
|
+
startTimeRef.current = Date.now();
|
|
132
|
+
}, config.loopDelay);
|
|
133
|
+
} else {
|
|
134
|
+
startTimeRef.current = Date.now();
|
|
135
|
+
}
|
|
355
136
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return {};
|
|
137
|
+
} else {
|
|
138
|
+
setState("finished");
|
|
139
|
+
}
|
|
140
|
+
} else if (nextStepIndex >= 0 && nextStepIndex < steps.length) {
|
|
141
|
+
setCurrentStepIndex(nextStepIndex);
|
|
142
|
+
startTimeRef.current = Date.now();
|
|
363
143
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
144
|
+
},
|
|
145
|
+
remainingTime + (currentStep.delay || 0)
|
|
146
|
+
);
|
|
147
|
+
return clearTimer;
|
|
148
|
+
}, [
|
|
149
|
+
state,
|
|
150
|
+
currentStep,
|
|
151
|
+
currentStepIndex,
|
|
152
|
+
steps.length,
|
|
153
|
+
direction,
|
|
154
|
+
config.loop,
|
|
155
|
+
config.loopCount,
|
|
156
|
+
config.loopDelay,
|
|
157
|
+
config.direction,
|
|
158
|
+
loopIteration,
|
|
159
|
+
clearTimer
|
|
160
|
+
]);
|
|
161
|
+
return {
|
|
162
|
+
currentStep,
|
|
163
|
+
currentStepIndex,
|
|
164
|
+
state,
|
|
165
|
+
loopIteration,
|
|
166
|
+
play,
|
|
167
|
+
pause,
|
|
168
|
+
reset,
|
|
169
|
+
goToStep,
|
|
170
|
+
getProgress
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const AnimationController = /* @__PURE__ */ React.forwardRef(function AnimationController2(props, ref) {
|
|
174
|
+
const {
|
|
175
|
+
children,
|
|
176
|
+
animation,
|
|
177
|
+
autoPlay = false,
|
|
178
|
+
playState: externalPlayState,
|
|
179
|
+
onStart,
|
|
180
|
+
onEnd,
|
|
181
|
+
onStepChange,
|
|
182
|
+
onPause,
|
|
183
|
+
onResume,
|
|
184
|
+
className,
|
|
185
|
+
style
|
|
186
|
+
} = props;
|
|
187
|
+
const isSequence = isSequenceConfig(animation);
|
|
188
|
+
const [singleState, setSingleState] = React.useState(
|
|
189
|
+
autoPlay ? "playing" : "idle"
|
|
190
|
+
);
|
|
191
|
+
const singleIterationRef = React.useRef(0);
|
|
192
|
+
const sequenceConfig = isSequence ? animation : { steps: [{ animation, duration: 1e3 }] };
|
|
193
|
+
const sequence = useAnimationSequence(sequenceConfig);
|
|
194
|
+
const state = isSequence ? sequence.state : singleState;
|
|
195
|
+
const currentStepIndex = isSequence ? sequence.currentStepIndex : 0;
|
|
196
|
+
React.useEffect(() => {
|
|
197
|
+
if (externalPlayState !== void 0) {
|
|
198
|
+
if (isSequence) {
|
|
199
|
+
if (externalPlayState === "playing") {
|
|
200
|
+
sequence.play();
|
|
201
|
+
} else if (externalPlayState === "paused") {
|
|
202
|
+
sequence.pause();
|
|
203
|
+
} else if (externalPlayState === "idle") {
|
|
204
|
+
sequence.reset();
|
|
373
205
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
206
|
+
} else {
|
|
207
|
+
setSingleState(externalPlayState);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}, [externalPlayState, isSequence, sequence]);
|
|
211
|
+
React.useEffect(() => {
|
|
212
|
+
if (autoPlay) {
|
|
213
|
+
if (isSequence) {
|
|
214
|
+
sequence.play();
|
|
215
|
+
} else {
|
|
216
|
+
setSingleState("playing");
|
|
217
|
+
}
|
|
218
|
+
onStart?.();
|
|
219
|
+
}
|
|
220
|
+
}, []);
|
|
221
|
+
const prevStepRef = React.useRef(currentStepIndex);
|
|
222
|
+
React.useEffect(() => {
|
|
223
|
+
if (prevStepRef.current !== currentStepIndex && isSequence) {
|
|
224
|
+
const step = sequenceConfig.steps[currentStepIndex];
|
|
225
|
+
onStepChange?.(currentStepIndex, step);
|
|
226
|
+
}
|
|
227
|
+
prevStepRef.current = currentStepIndex;
|
|
228
|
+
}, [currentStepIndex, isSequence, sequenceConfig.steps, onStepChange]);
|
|
229
|
+
const prevStateRef = React.useRef(state);
|
|
230
|
+
React.useEffect(() => {
|
|
231
|
+
if (prevStateRef.current !== state) {
|
|
232
|
+
if (state === "playing" && prevStateRef.current === "paused") {
|
|
233
|
+
onResume?.();
|
|
234
|
+
} else if (state === "paused" && prevStateRef.current === "playing") {
|
|
235
|
+
onPause?.();
|
|
236
|
+
} else if (state === "finished") {
|
|
237
|
+
onEnd?.();
|
|
238
|
+
} else if (state === "playing" && prevStateRef.current === "idle") {
|
|
239
|
+
onStart?.();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
prevStateRef.current = state;
|
|
243
|
+
}, [state, onStart, onEnd, onPause, onResume]);
|
|
244
|
+
React.useImperativeHandle(ref, () => ({
|
|
245
|
+
play: () => {
|
|
246
|
+
if (isSequence) {
|
|
247
|
+
sequence.play();
|
|
248
|
+
} else {
|
|
249
|
+
setSingleState("playing");
|
|
250
|
+
singleIterationRef.current++;
|
|
251
|
+
}
|
|
252
|
+
onStart?.();
|
|
253
|
+
},
|
|
254
|
+
pause: () => {
|
|
255
|
+
if (isSequence) {
|
|
256
|
+
sequence.pause();
|
|
257
|
+
} else {
|
|
258
|
+
setSingleState("paused");
|
|
259
|
+
}
|
|
260
|
+
onPause?.();
|
|
261
|
+
},
|
|
262
|
+
reset: () => {
|
|
263
|
+
if (isSequence) {
|
|
264
|
+
sequence.reset();
|
|
265
|
+
} else {
|
|
266
|
+
setSingleState("idle");
|
|
267
|
+
singleIterationRef.current++;
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
goToStep: (index) => {
|
|
271
|
+
if (isSequence) {
|
|
272
|
+
sequence.goToStep(index);
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
getState: () => state,
|
|
276
|
+
getCurrentStep: () => currentStepIndex,
|
|
277
|
+
getProgress: () => {
|
|
278
|
+
if (isSequence) {
|
|
279
|
+
return sequence.getProgress();
|
|
280
|
+
}
|
|
281
|
+
return state === "playing" ? 0.5 : state === "finished" ? 1 : 0;
|
|
282
|
+
}
|
|
283
|
+
}));
|
|
284
|
+
const animationStyles = React.useMemo(() => {
|
|
285
|
+
if (state === "idle") {
|
|
286
|
+
return {};
|
|
287
|
+
}
|
|
288
|
+
if (state === "paused") {
|
|
289
|
+
return { animationPlayState: "paused" };
|
|
290
|
+
}
|
|
291
|
+
if (isSequence && sequence.currentStep) {
|
|
292
|
+
const step = sequence.currentStep;
|
|
293
|
+
return getAnimationStyle(
|
|
294
|
+
step.animation,
|
|
295
|
+
step.duration,
|
|
296
|
+
step.easing,
|
|
297
|
+
step.iterations,
|
|
298
|
+
step.delay
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
if (!isSequence) {
|
|
302
|
+
return getAnimationStyle(animation, 1e3, "ease-in-out", -1);
|
|
303
|
+
}
|
|
304
|
+
return {};
|
|
305
|
+
}, [state, isSequence, sequence.currentStep, animation]);
|
|
306
|
+
const animationClass = state === "playing" || state === "paused" ? isSequence && sequence.currentStep ? getAnimationClass(sequence.currentStep.animation) : getAnimationClass(animation) : "";
|
|
307
|
+
const animatedChild = React.cloneElement(children, {
|
|
308
|
+
className: `${children.props.className || ""} ${animationClass}`.trim(),
|
|
309
|
+
style: {
|
|
310
|
+
...children.props.style,
|
|
311
|
+
...animationStyles
|
|
312
|
+
},
|
|
313
|
+
key: isSequence ? `seq-${currentStepIndex}-${sequence.loopIteration}` : `single-${singleIterationRef.current}`
|
|
314
|
+
});
|
|
315
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
316
|
+
"span",
|
|
317
|
+
{
|
|
318
|
+
className: `ntd-animation-controller ntd-animation-${state} ${className || ""}`.trim(),
|
|
319
|
+
style,
|
|
320
|
+
children: animatedChild
|
|
321
|
+
}
|
|
322
|
+
);
|
|
394
323
|
});
|
|
395
|
-
/*
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
* enterAnimation: 'bounce',
|
|
407
|
-
* leaveAnimation: 'fadeOut',
|
|
408
|
-
* }}
|
|
409
|
-
* >
|
|
410
|
-
* <NiceIcon name="heart" />
|
|
411
|
-
* </InteractiveIcon>
|
|
412
|
-
* ```
|
|
413
|
-
*
|
|
414
|
-
* @example Click
|
|
415
|
-
* ```tsx
|
|
416
|
-
* <InteractiveIcon
|
|
417
|
-
* config={{
|
|
418
|
-
* trigger: 'click',
|
|
419
|
-
* enterAnimation: 'pulse',
|
|
420
|
-
* once: true,
|
|
421
|
-
* }}
|
|
422
|
-
* >
|
|
423
|
-
* <NiceIcon name="notification" />
|
|
424
|
-
* </InteractiveIcon>
|
|
425
|
-
* ```
|
|
426
|
-
*/
|
|
427
|
-
const InteractiveIcon = /* @__PURE__ */ React.forwardRef(function InteractiveIcon(props, ref) {
|
|
428
|
-
const { children, config, disabled = false, onInteractionStart, onInteractionEnd, className, style, } = props;
|
|
324
|
+
const InteractiveIcon = /* @__PURE__ */ React.forwardRef(
|
|
325
|
+
function InteractiveIcon2(props, ref) {
|
|
326
|
+
const {
|
|
327
|
+
children,
|
|
328
|
+
config,
|
|
329
|
+
disabled = false,
|
|
330
|
+
onInteractionStart,
|
|
331
|
+
onInteractionEnd,
|
|
332
|
+
className,
|
|
333
|
+
style
|
|
334
|
+
} = props;
|
|
429
335
|
const [isActive, setIsActive] = React.useState(false);
|
|
430
336
|
const [isLeaving, setIsLeaving] = React.useState(false);
|
|
431
337
|
const [hasPlayed, setHasPlayed] = React.useState(false);
|
|
432
338
|
const wrapperRef = React.useRef(null);
|
|
433
339
|
const timeoutRef = React.useRef(null);
|
|
434
|
-
|
|
435
|
-
|
|
340
|
+
const setRefs = React.useCallback(
|
|
341
|
+
(node) => {
|
|
436
342
|
wrapperRef.current = node;
|
|
437
|
-
if (typeof ref ===
|
|
438
|
-
|
|
343
|
+
if (typeof ref === "function") {
|
|
344
|
+
ref(node);
|
|
345
|
+
} else if (ref) {
|
|
346
|
+
ref.current = node;
|
|
439
347
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}, [ref]);
|
|
444
|
-
// Clear any pending timeouts
|
|
348
|
+
},
|
|
349
|
+
[ref]
|
|
350
|
+
);
|
|
445
351
|
const clearTimer = React.useCallback(() => {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
352
|
+
if (timeoutRef.current) {
|
|
353
|
+
clearTimeout(timeoutRef.current);
|
|
354
|
+
timeoutRef.current = null;
|
|
355
|
+
}
|
|
450
356
|
}, []);
|
|
451
357
|
React.useEffect(() => clearTimer, [clearTimer]);
|
|
452
|
-
// Handle activation
|
|
453
358
|
const activate = React.useCallback(() => {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
359
|
+
if (disabled) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (config.once && hasPlayed) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
clearTimer();
|
|
366
|
+
setIsLeaving(false);
|
|
367
|
+
if (config.delay) {
|
|
368
|
+
timeoutRef.current = setTimeout(() => {
|
|
369
|
+
setIsActive(true);
|
|
370
|
+
setHasPlayed(true);
|
|
371
|
+
onInteractionStart?.();
|
|
372
|
+
}, config.delay);
|
|
373
|
+
} else {
|
|
374
|
+
setIsActive(true);
|
|
375
|
+
setHasPlayed(true);
|
|
376
|
+
onInteractionStart?.();
|
|
377
|
+
}
|
|
474
378
|
}, [disabled, config.once, config.delay, hasPlayed, clearTimer, onInteractionStart]);
|
|
475
|
-
// Handle deactivation
|
|
476
379
|
const deactivate = React.useCallback(() => {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
380
|
+
if (!isActive) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
clearTimer();
|
|
384
|
+
if (config.leaveAnimation) {
|
|
385
|
+
setIsLeaving(true);
|
|
386
|
+
setIsActive(false);
|
|
387
|
+
timeoutRef.current = setTimeout(() => {
|
|
388
|
+
setIsLeaving(false);
|
|
389
|
+
onInteractionEnd?.();
|
|
390
|
+
}, config.leaveDuration || 300);
|
|
391
|
+
} else {
|
|
392
|
+
setIsActive(false);
|
|
393
|
+
onInteractionEnd?.();
|
|
394
|
+
}
|
|
493
395
|
}, [isActive, config.leaveAnimation, config.leaveDuration, clearTimer, onInteractionEnd]);
|
|
494
|
-
// Visibility observer
|
|
495
396
|
React.useEffect(() => {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
397
|
+
if (config.trigger !== "visible" || !wrapperRef.current) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const threshold = config.visibilityThreshold ?? 0.5;
|
|
401
|
+
const observer = new IntersectionObserver(
|
|
402
|
+
([entry]) => {
|
|
403
|
+
if (entry.isIntersecting) {
|
|
404
|
+
activate();
|
|
405
|
+
} else if (!config.once) {
|
|
406
|
+
deactivate();
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
{ threshold }
|
|
410
|
+
);
|
|
411
|
+
observer.observe(wrapperRef.current);
|
|
412
|
+
return () => observer.disconnect();
|
|
511
413
|
}, [config.trigger, config.visibilityThreshold, config.once, activate, deactivate]);
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
const
|
|
515
|
-
const
|
|
516
|
-
const
|
|
517
|
-
const
|
|
518
|
-
// Build animation props
|
|
519
|
-
const currentAnimation = isActive
|
|
520
|
-
? config.enterAnimation
|
|
521
|
-
: isLeaving
|
|
522
|
-
? config.leaveAnimation
|
|
523
|
-
: undefined;
|
|
414
|
+
const handleMouseEnter = config.trigger === "hover" ? activate : void 0;
|
|
415
|
+
const handleMouseLeave = config.trigger === "hover" ? deactivate : void 0;
|
|
416
|
+
const handleClick = config.trigger === "click" ? activate : void 0;
|
|
417
|
+
const handleFocus = config.trigger === "focus" ? activate : void 0;
|
|
418
|
+
const handleBlur = config.trigger === "focus" ? deactivate : void 0;
|
|
419
|
+
const currentAnimation = isActive ? config.enterAnimation : isLeaving ? config.leaveAnimation : void 0;
|
|
524
420
|
const animationDuration = isActive ? config.enterDuration : config.leaveDuration;
|
|
525
|
-
const animationStyles = currentAnimation
|
|
526
|
-
|
|
527
|
-
: {};
|
|
528
|
-
const animationClass = currentAnimation ? getAnimationClass(currentAnimation) : '';
|
|
529
|
-
// Clone with animation
|
|
421
|
+
const animationStyles = currentAnimation ? getAnimationStyle(currentAnimation, animationDuration || 300) : {};
|
|
422
|
+
const animationClass = currentAnimation ? getAnimationClass(currentAnimation) : "";
|
|
530
423
|
const animatedChild = React.cloneElement(children, {
|
|
531
|
-
|
|
424
|
+
className: `${children.props.className || ""} ${animationClass}`.trim(),
|
|
425
|
+
style: {
|
|
426
|
+
...children.props.style,
|
|
427
|
+
...animationStyles
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
431
|
+
"span",
|
|
432
|
+
{
|
|
433
|
+
ref: setRefs,
|
|
434
|
+
className: `ntd-interactive-icon ${isActive ? "ntd-active" : ""} ${isLeaving ? "ntd-leaving" : ""} ${disabled ? "ntd-disabled" : ""} ${className || ""}`.trim(),
|
|
532
435
|
style: {
|
|
533
|
-
|
|
534
|
-
|
|
436
|
+
display: "inline-flex",
|
|
437
|
+
cursor: disabled ? "default" : config.trigger === "click" ? "pointer" : void 0,
|
|
438
|
+
...style
|
|
535
439
|
},
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
* Create an animation sequence configuration
|
|
555
|
-
*
|
|
556
|
-
* @example
|
|
557
|
-
* ```tsx
|
|
558
|
-
* const seq = createAnimationSequence([
|
|
559
|
-
* { animation: 'shake', duration: 300 },
|
|
560
|
-
* { animation: 'pulse', duration: 500 },
|
|
561
|
-
* { animation: 'bounce', duration: 400 },
|
|
562
|
-
* ], { loop: true, loopCount: 2 });
|
|
563
|
-
* ```
|
|
564
|
-
*/
|
|
440
|
+
onMouseEnter: handleMouseEnter,
|
|
441
|
+
onMouseLeave: handleMouseLeave,
|
|
442
|
+
onClick: handleClick,
|
|
443
|
+
onKeyDown: handleClick ? (e) => {
|
|
444
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
445
|
+
e.preventDefault();
|
|
446
|
+
handleClick();
|
|
447
|
+
}
|
|
448
|
+
} : void 0,
|
|
449
|
+
onFocus: handleFocus,
|
|
450
|
+
onBlur: handleBlur,
|
|
451
|
+
tabIndex: config.trigger === "focus" || config.trigger === "click" ? 0 : void 0,
|
|
452
|
+
role: config.trigger === "click" ? "button" : void 0,
|
|
453
|
+
children: animatedChild
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
);
|
|
565
458
|
function createAnimationSequence(steps, options) {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
};
|
|
459
|
+
return {
|
|
460
|
+
steps,
|
|
461
|
+
loop: options?.loop ?? false,
|
|
462
|
+
loopCount: options?.loopCount,
|
|
463
|
+
loopDelay: options?.loopDelay,
|
|
464
|
+
direction: options?.direction ?? "normal"
|
|
465
|
+
};
|
|
574
466
|
}
|
|
575
|
-
/**
|
|
576
|
-
* Create an interactive config for hover effect
|
|
577
|
-
*/
|
|
578
467
|
function createHoverAnimation(enterAnimation, leaveAnimation, options) {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
};
|
|
468
|
+
return {
|
|
469
|
+
trigger: "hover",
|
|
470
|
+
enterAnimation,
|
|
471
|
+
leaveAnimation,
|
|
472
|
+
enterDuration: options?.enterDuration ?? 300,
|
|
473
|
+
leaveDuration: options?.leaveDuration ?? 200,
|
|
474
|
+
delay: options?.delay
|
|
475
|
+
};
|
|
588
476
|
}
|
|
589
|
-
/**
|
|
590
|
-
* Create an interactive config for click effect
|
|
591
|
-
*/
|
|
592
477
|
function createClickAnimation(animation, options) {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
};
|
|
478
|
+
return {
|
|
479
|
+
trigger: "click",
|
|
480
|
+
enterAnimation: animation,
|
|
481
|
+
enterDuration: options?.duration ?? 500,
|
|
482
|
+
once: options?.once ?? false,
|
|
483
|
+
delay: options?.delay
|
|
484
|
+
};
|
|
601
485
|
}
|
|
602
|
-
/**
|
|
603
|
-
* Create an interactive config for visibility trigger
|
|
604
|
-
*/
|
|
605
486
|
function createVisibilityAnimation(animation, options) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
};
|
|
487
|
+
return {
|
|
488
|
+
trigger: "visible",
|
|
489
|
+
enterAnimation: animation,
|
|
490
|
+
enterDuration: options?.duration ?? 600,
|
|
491
|
+
once: options?.once ?? true,
|
|
492
|
+
visibilityThreshold: options?.threshold ?? 0.5
|
|
493
|
+
};
|
|
614
494
|
}
|
|
615
|
-
/* ────────────────────────────────────────────────────────────────────────────
|
|
616
|
-
7. PRESET SEQUENCES
|
|
617
|
-
───────────────────────────────────────────────────────────────────────────── */
|
|
618
|
-
/**
|
|
619
|
-
* Preset animation sequences for common use cases
|
|
620
|
-
*/
|
|
621
495
|
const PRESET_SEQUENCES = {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
496
|
+
/** Attention grabber: bounce → shake → pulse */
|
|
497
|
+
attention: createAnimationSequence([
|
|
498
|
+
{ animation: "bounce", duration: 400 },
|
|
499
|
+
{ animation: "shake", duration: 300 },
|
|
500
|
+
{ animation: "pulse", duration: 500 }
|
|
501
|
+
]),
|
|
502
|
+
/** Success animation: pop → bounce */
|
|
503
|
+
success: createAnimationSequence([
|
|
504
|
+
{ animation: "pop", duration: 200 },
|
|
505
|
+
{ animation: "bounce", duration: 500 }
|
|
506
|
+
]),
|
|
507
|
+
/** Error animation: shake → pulse */
|
|
508
|
+
error: createAnimationSequence([
|
|
509
|
+
{ animation: "shake", duration: 500, iterations: 2 },
|
|
510
|
+
{ animation: "pulse", duration: 300 }
|
|
511
|
+
]),
|
|
512
|
+
/** Loading sequence: spin → pulse (looping) */
|
|
513
|
+
loading: createAnimationSequence(
|
|
514
|
+
[
|
|
515
|
+
{ animation: "spin", duration: 1e3 },
|
|
516
|
+
{ animation: "pulse", duration: 500 }
|
|
517
|
+
],
|
|
518
|
+
{ loop: true }
|
|
519
|
+
),
|
|
520
|
+
/** Celebration: bounce → tada → heartbeat */
|
|
521
|
+
celebrate: createAnimationSequence([
|
|
522
|
+
{ animation: "bounce", duration: 500 },
|
|
523
|
+
{ animation: "tada", duration: 800 },
|
|
524
|
+
{ animation: "heartbeat", duration: 600 }
|
|
525
|
+
]),
|
|
526
|
+
/** Notification: swing → bounce */
|
|
527
|
+
notification: createAnimationSequence([
|
|
528
|
+
{ animation: "swing", duration: 600 },
|
|
529
|
+
{ animation: "bounce", duration: 400 }
|
|
530
|
+
]),
|
|
531
|
+
/** Gentle: pulse → breathe */
|
|
532
|
+
gentle: createAnimationSequence(
|
|
533
|
+
[
|
|
534
|
+
{ animation: "pulse", duration: 800 },
|
|
535
|
+
{ animation: "breathe", duration: 1500 }
|
|
536
|
+
],
|
|
537
|
+
{ loop: true }
|
|
538
|
+
),
|
|
539
|
+
/** Reveal: fade-in → pop */
|
|
540
|
+
reveal: createAnimationSequence([
|
|
541
|
+
{ animation: "fade-in", duration: 300 },
|
|
542
|
+
{ animation: "pop", duration: 200 }
|
|
543
|
+
])
|
|
664
544
|
};
|
|
665
|
-
/**
|
|
666
|
-
* Preset interactive configs
|
|
667
|
-
*/
|
|
668
545
|
const PRESET_INTERACTIONS = {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
546
|
+
/** Bounce on hover */
|
|
547
|
+
hoverBounce: createHoverAnimation("bounce"),
|
|
548
|
+
/** Pulse on hover */
|
|
549
|
+
hoverPulse: createHoverAnimation("pulse"),
|
|
550
|
+
/** Spin on hover */
|
|
551
|
+
hoverSpin: createHoverAnimation("spin"),
|
|
552
|
+
/** Shake on hover */
|
|
553
|
+
hoverShake: createHoverAnimation("shake"),
|
|
554
|
+
/** Pop on click */
|
|
555
|
+
clickPop: createClickAnimation("pop", { once: true }),
|
|
556
|
+
/** Bounce on click */
|
|
557
|
+
clickBounce: createClickAnimation("bounce"),
|
|
558
|
+
/** Tada on click */
|
|
559
|
+
clickTada: createClickAnimation("tada"),
|
|
560
|
+
/** FadeIn on visible */
|
|
561
|
+
visibleFadeIn: createVisibilityAnimation("fade-in", { once: true }),
|
|
562
|
+
/** Bounce on visible */
|
|
563
|
+
visibleBounce: createVisibilityAnimation("bounce", { once: true }),
|
|
564
|
+
/** Scale in on visible */
|
|
565
|
+
visibleScaleIn: createVisibilityAnimation("scale-in", { once: true })
|
|
689
566
|
};
|
|
690
|
-
|
|
691
567
|
exports.AnimationController = AnimationController;
|
|
692
568
|
exports.InteractiveIcon = InteractiveIcon;
|
|
693
569
|
exports.PRESET_INTERACTIONS = PRESET_INTERACTIONS;
|