@mks2508/mks-ui 0.2.1 → 0.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/dist/react-ui/hooks/Animation/UseAutoHeight.js +7 -7
- package/dist/react-ui/hooks/DOM/UseIsInView.js +3 -3
- package/dist/react-ui/hooks/Formatting/UseListFormat.d.ts +49 -0
- package/dist/react-ui/hooks/Formatting/UseListFormat.d.ts.map +1 -0
- package/dist/react-ui/hooks/Formatting/UseListFormat.js +105 -0
- package/dist/react-ui/hooks/State/UseControlledState.js +4 -4
- package/dist/react-ui/hooks/State/UseDataState.js +5 -5
- package/dist/react-ui/hooks/index.d.ts +2 -0
- package/dist/react-ui/hooks/index.d.ts.map +1 -1
- package/dist/react-ui/hooks/index.js +1 -0
- package/dist/react-ui/index.js +22 -2
- package/dist/react-ui/lib/get-strict-context.js +3 -3
- package/dist/react-ui/primitives/CountingNumber/index.js +3 -3
- package/dist/react-ui/primitives/Highlight/index.js +26 -26
- package/dist/react-ui/primitives/Slot/index.js +3 -3
- package/dist/react-ui/primitives/index.d.ts +1 -0
- package/dist/react-ui/primitives/index.d.ts.map +1 -1
- package/dist/react-ui/primitives/index.js +18 -0
- package/dist/react-ui/primitives/waapi/Morph/Morph.types.d.ts +76 -0
- package/dist/react-ui/primitives/waapi/Morph/Morph.types.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Morph/MorphContext.d.ts +11 -0
- package/dist/react-ui/primitives/waapi/Morph/MorphContext.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Morph/MorphContext.js +19 -0
- package/dist/react-ui/primitives/waapi/Morph/index.d.ts +23 -0
- package/dist/react-ui/primitives/waapi/Morph/index.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Morph/index.js +45 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/index.d.ts +12 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/index.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useCSSGridMorph.d.ts +38 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useCSSGridMorph.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useCSSGridMorph.js +78 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useFLIPClipPath.d.ts +23 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useFLIPClipPath.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useFLIPClipPath.js +140 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useViewTransitions.d.ts +28 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useViewTransitions.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Morph/techniques/useViewTransitions.js +77 -0
- package/dist/react-ui/primitives/waapi/Morph/useMorph.d.ts +27 -0
- package/dist/react-ui/primitives/waapi/Morph/useMorph.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Morph/useMorph.js +86 -0
- package/dist/react-ui/primitives/waapi/Reorder/Reorder.types.d.ts +168 -0
- package/dist/react-ui/primitives/waapi/Reorder/Reorder.types.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Reorder/index.d.ts +25 -0
- package/dist/react-ui/primitives/waapi/Reorder/index.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Reorder/index.js +186 -0
- package/dist/react-ui/primitives/waapi/Reorder/useReorder.d.ts +26 -0
- package/dist/react-ui/primitives/waapi/Reorder/useReorder.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Reorder/useReorder.js +48 -0
- package/dist/react-ui/primitives/waapi/Reorder/useReorderPresence.d.ts +33 -0
- package/dist/react-ui/primitives/waapi/Reorder/useReorderPresence.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Reorder/useReorderPresence.js +137 -0
- package/dist/react-ui/primitives/waapi/Reorder/utils/separatorCoordination.d.ts +47 -0
- package/dist/react-ui/primitives/waapi/Reorder/utils/separatorCoordination.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/Reorder/utils/separatorCoordination.js +72 -0
- package/dist/react-ui/primitives/waapi/SlidingNumber/SlidingNumber.styles.d.ts +10 -0
- package/dist/react-ui/primitives/waapi/SlidingNumber/SlidingNumber.styles.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/SlidingNumber/SlidingNumber.types.d.ts +74 -0
- package/dist/react-ui/primitives/waapi/SlidingNumber/SlidingNumber.types.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/SlidingNumber/index.d.ts +33 -0
- package/dist/react-ui/primitives/waapi/SlidingNumber/index.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/SlidingNumber/index.js +354 -0
- package/dist/react-ui/primitives/waapi/SlidingText/SlidingText.styles.d.ts +25 -0
- package/dist/react-ui/primitives/waapi/SlidingText/SlidingText.styles.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/SlidingText/SlidingText.types.d.ts +57 -0
- package/dist/react-ui/primitives/waapi/SlidingText/SlidingText.types.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/SlidingText/index.d.ts +26 -0
- package/dist/react-ui/primitives/waapi/SlidingText/index.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/SlidingText/index.js +105 -0
- package/dist/react-ui/primitives/waapi/core/animationConstants.d.ts +156 -0
- package/dist/react-ui/primitives/waapi/core/animationConstants.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/core/animationConstants.js +180 -0
- package/dist/react-ui/primitives/waapi/core/index.d.ts +16 -0
- package/dist/react-ui/primitives/waapi/core/index.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/core/index.js +5 -0
- package/dist/react-ui/primitives/waapi/core/types.d.ts +143 -0
- package/dist/react-ui/primitives/waapi/core/types.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/core/useAnimationOrchestrator.d.ts +32 -0
- package/dist/react-ui/primitives/waapi/core/useAnimationOrchestrator.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/core/useAnimationOrchestrator.js +322 -0
- package/dist/react-ui/primitives/waapi/core/useElementRegistry.d.ts +21 -0
- package/dist/react-ui/primitives/waapi/core/useElementRegistry.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/core/useElementRegistry.js +65 -0
- package/dist/react-ui/primitives/waapi/core/useFLIPAnimation.d.ts +20 -0
- package/dist/react-ui/primitives/waapi/core/useFLIPAnimation.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/core/useFLIPAnimation.js +99 -0
- package/dist/react-ui/primitives/waapi/core/usePositionCapture.d.ts +24 -0
- package/dist/react-ui/primitives/waapi/core/usePositionCapture.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/core/usePositionCapture.js +75 -0
- package/dist/react-ui/primitives/waapi/index.d.ts +33 -0
- package/dist/react-ui/primitives/waapi/index.d.ts.map +1 -0
- package/dist/react-ui/primitives/waapi/index.js +18 -0
- package/dist/react-ui/ui/Accordion/index.js +3 -3
- package/dist/react-ui/ui/Button/index.js +8 -8
- package/dist/react-ui/ui/Combobox/index.js +2 -2
- package/dist/react-ui/ui/DataCard/DataCard.styles.d.ts +35 -0
- package/dist/react-ui/ui/DataCard/DataCard.styles.d.ts.map +1 -0
- package/dist/react-ui/ui/DataCard/DataCard.styles.js +114 -0
- package/dist/react-ui/ui/DataCard/DataCard.types.d.ts +135 -0
- package/dist/react-ui/ui/DataCard/DataCard.types.d.ts.map +1 -0
- package/dist/react-ui/ui/DataCard/index.d.ts +129 -0
- package/dist/react-ui/ui/DataCard/index.d.ts.map +1 -0
- package/dist/react-ui/ui/DataCard/index.js +276 -0
- package/dist/react-ui/ui/Menu/index.js +2 -2
- package/dist/react-ui/ui/Switch/index.js +3 -3
- package/dist/react-ui/ui/Tabs/index.js +3 -3
- package/dist/react-ui/ui/TextFlow/TextFlow.styles.d.ts +16 -0
- package/dist/react-ui/ui/TextFlow/TextFlow.styles.d.ts.map +1 -0
- package/dist/react-ui/ui/TextFlow/TextFlow.types.d.ts +101 -0
- package/dist/react-ui/ui/TextFlow/TextFlow.types.d.ts.map +1 -0
- package/dist/react-ui/ui/TextFlow/index.d.ts +26 -0
- package/dist/react-ui/ui/TextFlow/index.d.ts.map +1 -0
- package/dist/react-ui/ui/TextFlow/index.js +187 -0
- package/dist/react-ui/ui/index.d.ts +2 -1
- package/dist/react-ui/ui/index.d.ts.map +1 -1
- package/dist/react-ui/ui/index.js +3 -1
- package/package.json +6 -2
- package/src/react-ui/hooks/Formatting/UseListFormat.ts +134 -0
- package/src/react-ui/hooks/index.ts +3 -0
- package/src/react-ui/primitives/index.ts +3 -0
- package/src/react-ui/primitives/waapi/Morph/Morph.types.ts +106 -0
- package/src/react-ui/primitives/waapi/Morph/MorphContext.tsx +21 -0
- package/src/react-ui/primitives/waapi/Morph/index.tsx +56 -0
- package/src/react-ui/primitives/waapi/Morph/techniques/index.ts +12 -0
- package/src/react-ui/primitives/waapi/Morph/techniques/useCSSGridMorph.ts +88 -0
- package/src/react-ui/primitives/waapi/Morph/techniques/useFLIPClipPath.ts +175 -0
- package/src/react-ui/primitives/waapi/Morph/techniques/useViewTransitions.ts +86 -0
- package/src/react-ui/primitives/waapi/Morph/useMorph.ts +100 -0
- package/src/react-ui/primitives/waapi/Reorder/Reorder.types.ts +177 -0
- package/src/react-ui/primitives/waapi/Reorder/index.tsx +260 -0
- package/src/react-ui/primitives/waapi/Reorder/useReorder.ts +46 -0
- package/src/react-ui/primitives/waapi/Reorder/useReorderPresence.ts +208 -0
- package/src/react-ui/primitives/waapi/Reorder/utils/separatorCoordination.ts +104 -0
- package/src/react-ui/primitives/waapi/SlidingNumber/SlidingNumber.styles.ts +14 -0
- package/src/react-ui/primitives/waapi/SlidingNumber/SlidingNumber.types.ts +84 -0
- package/src/react-ui/primitives/waapi/SlidingNumber/index.tsx +474 -0
- package/src/react-ui/primitives/waapi/SlidingText/SlidingText.styles.ts +32 -0
- package/src/react-ui/primitives/waapi/SlidingText/SlidingText.types.ts +69 -0
- package/src/react-ui/primitives/waapi/SlidingText/index.tsx +140 -0
- package/src/react-ui/primitives/waapi/core/animationConstants.ts +215 -0
- package/src/react-ui/primitives/waapi/core/index.ts +53 -0
- package/src/react-ui/primitives/waapi/core/types.ts +200 -0
- package/src/react-ui/primitives/waapi/core/useAnimationOrchestrator.ts +429 -0
- package/src/react-ui/primitives/waapi/core/useElementRegistry.ts +80 -0
- package/src/react-ui/primitives/waapi/core/useFLIPAnimation.ts +137 -0
- package/src/react-ui/primitives/waapi/core/usePositionCapture.ts +105 -0
- package/src/react-ui/primitives/waapi/index.ts +116 -0
- package/src/react-ui/styles/animations.css +369 -0
- package/src/react-ui/ui/DataCard/DataCard.styles.ts +150 -0
- package/src/react-ui/ui/DataCard/DataCard.types.ts +146 -0
- package/src/react-ui/ui/DataCard/index.tsx +406 -0
- package/src/react-ui/ui/TextFlow/TextFlow.styles.ts +36 -0
- package/src/react-ui/ui/TextFlow/TextFlow.types.ts +118 -0
- package/src/react-ui/ui/TextFlow/index.tsx +276 -0
- package/src/react-ui/ui/index.ts +4 -1
- /package/dist/react-ui/components/MorphingPopover/{morphing-popover.module-CgbYV_HS.css → morphing-popover.module-BycNI8nU.css} +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format options for number display using Intl.NumberFormat
|
|
3
|
+
*/
|
|
4
|
+
export interface IFormatOptions {
|
|
5
|
+
/** Number formatting style */
|
|
6
|
+
style?: 'decimal' | 'currency' | 'percent';
|
|
7
|
+
/** Currency code (required when style is 'currency') */
|
|
8
|
+
currency?: string;
|
|
9
|
+
/** Locale for formatting (e.g., 'en-US', 'es-ES') */
|
|
10
|
+
locale?: string;
|
|
11
|
+
/** Minimum fraction digits */
|
|
12
|
+
minimumFractionDigits?: number;
|
|
13
|
+
/** Maximum fraction digits */
|
|
14
|
+
maximumFractionDigits?: number;
|
|
15
|
+
/** Whether to use grouping separators */
|
|
16
|
+
useGrouping?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Props for SlidingNumber component
|
|
21
|
+
*
|
|
22
|
+
* Animated number transitions with format preservation using WAAPI slot-machine-style animation.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* // Basic counter
|
|
27
|
+
* <SlidingNumber value={1234} duration={700} />
|
|
28
|
+
*
|
|
29
|
+
* // Currency
|
|
30
|
+
* <SlidingNumber
|
|
31
|
+
* value={99.99}
|
|
32
|
+
* format={{ style: 'currency', currency: 'USD' }}
|
|
33
|
+
* />
|
|
34
|
+
*
|
|
35
|
+
* // With motion blur
|
|
36
|
+
* <SlidingNumber value={500} motionBlur={true} digitHeight={60} />
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface ISlidingNumberProps {
|
|
40
|
+
/** The numeric value to display */
|
|
41
|
+
value: number;
|
|
42
|
+
|
|
43
|
+
/** Animation duration in milliseconds */
|
|
44
|
+
duration?: number;
|
|
45
|
+
|
|
46
|
+
/** Font size for the number display */
|
|
47
|
+
fontSize?: string;
|
|
48
|
+
|
|
49
|
+
/** Font weight for the number display */
|
|
50
|
+
fontWeight?: string;
|
|
51
|
+
|
|
52
|
+
/** Text color */
|
|
53
|
+
color?: string;
|
|
54
|
+
|
|
55
|
+
/** Height of each digit row in pixels */
|
|
56
|
+
digitHeight?: number;
|
|
57
|
+
|
|
58
|
+
/** Delay between digit animations in milliseconds */
|
|
59
|
+
stagger?: number;
|
|
60
|
+
|
|
61
|
+
/** Enable motion blur effect during animation */
|
|
62
|
+
motionBlur?: boolean;
|
|
63
|
+
|
|
64
|
+
/** Number formatting options */
|
|
65
|
+
format?: IFormatOptions;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Animation direction trend
|
|
69
|
+
* - 1: Always animate upward (increasing)
|
|
70
|
+
* - -1: Always animate downward (decreasing)
|
|
71
|
+
* - 0: Auto (shorter path)
|
|
72
|
+
*/
|
|
73
|
+
trend?: -1 | 0 | 1;
|
|
74
|
+
|
|
75
|
+
/** Physics-based animation configuration */
|
|
76
|
+
animationConfig?: {
|
|
77
|
+
/** Overshoot amount (higher = more bounce) */
|
|
78
|
+
overshoot?: number;
|
|
79
|
+
/** Mass of the animated object */
|
|
80
|
+
mass?: number;
|
|
81
|
+
/** Spring stiffness */
|
|
82
|
+
stiffness?: number;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useEffect, useRef, useMemo, useLayoutEffect } from 'react';
|
|
4
|
+
import type { ISlidingNumberProps, IFormatOptions } from './SlidingNumber.types';
|
|
5
|
+
import { cn } from '@/react-ui/lib/utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* SlidingNumber - Animated number transitions with format preservation
|
|
9
|
+
*
|
|
10
|
+
* Uses WAAPI slot-machine-style animation with optional motion blur.
|
|
11
|
+
* Supports Intl.NumberFormat for currency, percentage, and decimal formatting.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // Basic counter
|
|
16
|
+
* <SlidingNumber value={1234} />
|
|
17
|
+
*
|
|
18
|
+
* // Currency with animation
|
|
19
|
+
* <SlidingNumber
|
|
20
|
+
* value={99.99}
|
|
21
|
+
* format={{ style: 'currency', currency: 'USD' }}
|
|
22
|
+
* duration={700}
|
|
23
|
+
* />
|
|
24
|
+
*
|
|
25
|
+
* // Percentage
|
|
26
|
+
* <SlidingNumber
|
|
27
|
+
* value={75.5}
|
|
28
|
+
* format={{ style: 'percent' }}
|
|
29
|
+
* />
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const SlidingNumber = ({
|
|
33
|
+
value,
|
|
34
|
+
duration = 700,
|
|
35
|
+
fontSize = '3rem',
|
|
36
|
+
fontWeight = '700',
|
|
37
|
+
color = '#000',
|
|
38
|
+
digitHeight = 60,
|
|
39
|
+
stagger = 30,
|
|
40
|
+
motionBlur = true,
|
|
41
|
+
format,
|
|
42
|
+
trend = 0,
|
|
43
|
+
animationConfig,
|
|
44
|
+
}: ISlidingNumberProps): React.ReactElement => {
|
|
45
|
+
const computedEasing = useMemo(() => {
|
|
46
|
+
if (animationConfig) {
|
|
47
|
+
const { overshoot = 1, stiffness = 1, mass = 1 } = animationConfig;
|
|
48
|
+
const p1 = 0.34 * stiffness;
|
|
49
|
+
const p2 = 1 + 0.56 * overshoot;
|
|
50
|
+
const p3 = 0.64 / mass;
|
|
51
|
+
return `cubic-bezier(${Math.min(p1, 1).toFixed(2)}, ${Math.min(p2, 2).toFixed(2)}, ${Math.min(p3, 1).toFixed(2)}, 1)`;
|
|
52
|
+
}
|
|
53
|
+
return 'cubic-bezier(0.34, 1.56, 0.64, 1)';
|
|
54
|
+
}, [animationConfig]);
|
|
55
|
+
|
|
56
|
+
const currentChars = useMemo(() => parseNumberToChars(value, format), [value, format]);
|
|
57
|
+
const prevKeysRef = useRef<Set<string>>(new Set());
|
|
58
|
+
const isFirstRenderRef = useRef(true);
|
|
59
|
+
|
|
60
|
+
const enteringKeys = useMemo(() => {
|
|
61
|
+
if (isFirstRenderRef.current) return new Set<string>();
|
|
62
|
+
const entering = new Set<string>();
|
|
63
|
+
currentChars.forEach((c) => {
|
|
64
|
+
if (!prevKeysRef.current.has(c.key)) {
|
|
65
|
+
entering.add(c.key);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return entering;
|
|
69
|
+
}, [currentChars]);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
isFirstRenderRef.current = false;
|
|
73
|
+
prevKeysRef.current = new Set(currentChars.map((c) => c.key));
|
|
74
|
+
}, [currentChars]);
|
|
75
|
+
|
|
76
|
+
const getDelay = (position: number) => {
|
|
77
|
+
const absPos = Math.abs(position);
|
|
78
|
+
return (absPos - 1) * stagger;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div
|
|
83
|
+
className={cn('waapi-sliding-number')}
|
|
84
|
+
style={{
|
|
85
|
+
display: 'inline-flex',
|
|
86
|
+
alignItems: 'center',
|
|
87
|
+
fontSize,
|
|
88
|
+
fontWeight,
|
|
89
|
+
color,
|
|
90
|
+
fontVariantNumeric: 'tabular-nums',
|
|
91
|
+
fontFamily: 'system-ui, -apple-system, sans-serif',
|
|
92
|
+
overflow: 'hidden',
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
{currentChars.map((item) => {
|
|
96
|
+
const isEntering = enteringKeys.has(item.key);
|
|
97
|
+
|
|
98
|
+
if (item.isDigit) {
|
|
99
|
+
return (
|
|
100
|
+
<Digit
|
|
101
|
+
key={item.key}
|
|
102
|
+
digit={Number.parseInt(item.char)}
|
|
103
|
+
duration={duration}
|
|
104
|
+
digitHeight={digitHeight}
|
|
105
|
+
delay={getDelay(item.position)}
|
|
106
|
+
motionBlur={motionBlur}
|
|
107
|
+
easing={computedEasing}
|
|
108
|
+
isEntering={isEntering}
|
|
109
|
+
trend={trend}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<Symbol key={item.key} char={item.char} isEntering={isEntering} duration={duration} easing={computedEasing} />
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
SlidingNumber.displayName = 'SlidingNumber';
|
|
123
|
+
|
|
124
|
+
// ============================================================================
|
|
125
|
+
// Types
|
|
126
|
+
// ============================================================================
|
|
127
|
+
|
|
128
|
+
interface ICharItem {
|
|
129
|
+
char: string;
|
|
130
|
+
key: string;
|
|
131
|
+
isDigit: boolean;
|
|
132
|
+
position: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface IDigitProps {
|
|
136
|
+
digit: number;
|
|
137
|
+
duration: number;
|
|
138
|
+
digitHeight: number;
|
|
139
|
+
delay: number;
|
|
140
|
+
motionBlur: boolean;
|
|
141
|
+
easing: string;
|
|
142
|
+
isEntering: boolean;
|
|
143
|
+
trend: -1 | 0 | 1;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
interface ISymbolProps {
|
|
147
|
+
char: string;
|
|
148
|
+
isEntering: boolean;
|
|
149
|
+
duration: number;
|
|
150
|
+
easing: string;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ============================================================================
|
|
154
|
+
// Utilities
|
|
155
|
+
// ============================================================================
|
|
156
|
+
|
|
157
|
+
function parseNumberToChars(value: number, format?: IFormatOptions): ICharItem[] {
|
|
158
|
+
const locale = format?.locale || 'en-US';
|
|
159
|
+
const options: Intl.NumberFormatOptions = {
|
|
160
|
+
style: format?.style || 'decimal',
|
|
161
|
+
minimumFractionDigits: format?.minimumFractionDigits,
|
|
162
|
+
maximumFractionDigits: format?.maximumFractionDigits,
|
|
163
|
+
useGrouping: format?.useGrouping ?? true,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
if (format?.style === 'currency' && format?.currency) {
|
|
167
|
+
options.currency = format.currency;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
171
|
+
const parts = formatter.formatToParts(value);
|
|
172
|
+
|
|
173
|
+
const result: ICharItem[] = [];
|
|
174
|
+
|
|
175
|
+
let integerDigitCount = 0;
|
|
176
|
+
parts.forEach((part) => {
|
|
177
|
+
if (part.type === 'integer') {
|
|
178
|
+
integerDigitCount += part.value.length;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
let integerIndex = integerDigitCount;
|
|
183
|
+
let fractionIndex = 0;
|
|
184
|
+
let groupCount = 0;
|
|
185
|
+
|
|
186
|
+
parts.forEach((part, partIdx) => {
|
|
187
|
+
if (part.type === 'integer') {
|
|
188
|
+
for (const char of part.value) {
|
|
189
|
+
result.push({
|
|
190
|
+
char,
|
|
191
|
+
key: `int-${integerIndex}`,
|
|
192
|
+
isDigit: true,
|
|
193
|
+
position: integerIndex,
|
|
194
|
+
});
|
|
195
|
+
integerIndex--;
|
|
196
|
+
}
|
|
197
|
+
} else if (part.type === 'fraction') {
|
|
198
|
+
for (const char of part.value) {
|
|
199
|
+
fractionIndex++;
|
|
200
|
+
result.push({
|
|
201
|
+
char,
|
|
202
|
+
key: `frac-${fractionIndex}`,
|
|
203
|
+
isDigit: true,
|
|
204
|
+
position: -fractionIndex,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
} else if (part.type === 'decimal') {
|
|
208
|
+
result.push({ char: part.value, key: 'decimal', isDigit: false, position: 0 });
|
|
209
|
+
} else if (part.type === 'group') {
|
|
210
|
+
groupCount++;
|
|
211
|
+
result.push({ char: part.value, key: `group-${groupCount}`, isDigit: false, position: 0 });
|
|
212
|
+
} else if (part.type === 'currency') {
|
|
213
|
+
result.push({ char: part.value, key: `currency-${partIdx}`, isDigit: false, position: 0 });
|
|
214
|
+
} else if (part.type === 'percentSign') {
|
|
215
|
+
result.push({ char: part.value, key: 'percent', isDigit: false, position: 0 });
|
|
216
|
+
} else {
|
|
217
|
+
result.push({ char: part.value, key: `symbol-${partIdx}`, isDigit: false, position: 0 });
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ============================================================================
|
|
225
|
+
// Symbol Component (non-digit characters)
|
|
226
|
+
// ============================================================================
|
|
227
|
+
|
|
228
|
+
function Symbol({ char, isEntering, duration, easing }: ISymbolProps) {
|
|
229
|
+
const ref = useRef<HTMLSpanElement>(null);
|
|
230
|
+
const hasAnimatedRef = useRef(false);
|
|
231
|
+
|
|
232
|
+
useLayoutEffect(() => {
|
|
233
|
+
if (!ref.current || !isEntering || hasAnimatedRef.current) return;
|
|
234
|
+
hasAnimatedRef.current = true;
|
|
235
|
+
|
|
236
|
+
ref.current.animate(
|
|
237
|
+
[
|
|
238
|
+
{ opacity: 0, transform: 'scale(0.8)' },
|
|
239
|
+
{ opacity: 1, transform: 'scale(1)' },
|
|
240
|
+
],
|
|
241
|
+
{
|
|
242
|
+
duration: duration * 0.3,
|
|
243
|
+
easing,
|
|
244
|
+
fill: 'forwards',
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
}, [isEntering, duration, easing]);
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<span
|
|
251
|
+
ref={ref}
|
|
252
|
+
style={{
|
|
253
|
+
display: 'inline-block',
|
|
254
|
+
whiteSpace: 'pre',
|
|
255
|
+
opacity: isEntering ? 0 : 1,
|
|
256
|
+
}}
|
|
257
|
+
>
|
|
258
|
+
{char}
|
|
259
|
+
</span>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ============================================================================
|
|
264
|
+
// Digit Component (animated numbers)
|
|
265
|
+
// ============================================================================
|
|
266
|
+
|
|
267
|
+
function Digit({ digit, duration, digitHeight, delay, motionBlur, easing, isEntering, trend }: IDigitProps) {
|
|
268
|
+
const columnRef = useRef<HTMLDivElement>(null);
|
|
269
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
270
|
+
const animationRef = useRef<Animation | null>(null);
|
|
271
|
+
const filterId = useRef(`blur-${Math.random().toString(36).slice(2, 9)}`).current;
|
|
272
|
+
|
|
273
|
+
const currentOffsetRef = useRef<number | null>(null);
|
|
274
|
+
const targetDigitRef = useRef(digit);
|
|
275
|
+
const hasInitializedRef = useRef(false);
|
|
276
|
+
|
|
277
|
+
const sequence = useMemo(() => {
|
|
278
|
+
const seq: number[] = [];
|
|
279
|
+
for (let cycle = -1; cycle <= 1; cycle++) {
|
|
280
|
+
for (let d = 0; d <= 9; d++) {
|
|
281
|
+
seq.push(d);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return seq;
|
|
285
|
+
}, []);
|
|
286
|
+
|
|
287
|
+
useLayoutEffect(() => {
|
|
288
|
+
if (!hasInitializedRef.current) {
|
|
289
|
+
hasInitializedRef.current = true;
|
|
290
|
+
const offset = -(digit + 10) * digitHeight;
|
|
291
|
+
currentOffsetRef.current = offset;
|
|
292
|
+
targetDigitRef.current = digit;
|
|
293
|
+
|
|
294
|
+
if (columnRef.current) {
|
|
295
|
+
columnRef.current.style.transform = `translateY(${offset}px)`;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}, [digit, digitHeight]);
|
|
299
|
+
|
|
300
|
+
useLayoutEffect(() => {
|
|
301
|
+
if (!containerRef.current || !isEntering) return;
|
|
302
|
+
|
|
303
|
+
containerRef.current.animate(
|
|
304
|
+
[
|
|
305
|
+
{ opacity: 0, transform: 'scale(0.5) translateY(-20px)' },
|
|
306
|
+
{ opacity: 1, transform: 'scale(1) translateY(0)' },
|
|
307
|
+
],
|
|
308
|
+
{
|
|
309
|
+
duration: duration * 0.4,
|
|
310
|
+
easing,
|
|
311
|
+
fill: 'forwards',
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
}, [isEntering, duration, easing]);
|
|
315
|
+
|
|
316
|
+
useEffect(() => {
|
|
317
|
+
targetDigitRef.current = digit;
|
|
318
|
+
|
|
319
|
+
if (!hasInitializedRef.current) return;
|
|
320
|
+
|
|
321
|
+
const currentDigit =
|
|
322
|
+
currentOffsetRef.current !== null
|
|
323
|
+
? (((Math.round(-currentOffsetRef.current / digitHeight) - 10) % 10) + 10) % 10
|
|
324
|
+
: digit;
|
|
325
|
+
|
|
326
|
+
if (digit === currentDigit && currentOffsetRef.current !== null) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
animateToDigit(digit);
|
|
331
|
+
}, [digit, digitHeight]);
|
|
332
|
+
|
|
333
|
+
const animateToDigit = (target: number) => {
|
|
334
|
+
if (!columnRef.current || !containerRef.current) return;
|
|
335
|
+
|
|
336
|
+
if (animationRef.current) {
|
|
337
|
+
const computedStyle = getComputedStyle(columnRef.current);
|
|
338
|
+
const matrix = new DOMMatrix(computedStyle.transform);
|
|
339
|
+
currentOffsetRef.current = matrix.m42;
|
|
340
|
+
animationRef.current.cancel();
|
|
341
|
+
animationRef.current = null;
|
|
342
|
+
columnRef.current.style.transform = `translateY(${currentOffsetRef.current}px)`;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const rawIndex = currentOffsetRef.current !== null ? -currentOffsetRef.current / digitHeight : target + 10;
|
|
346
|
+
|
|
347
|
+
const currentDigitFromOffset = (((Math.round(rawIndex) - 10) % 10) + 10) % 10;
|
|
348
|
+
const from = currentDigitFromOffset;
|
|
349
|
+
|
|
350
|
+
if (target === from && currentOffsetRef.current !== null) {
|
|
351
|
+
const normalizedOffset = -(target + 10) * digitHeight;
|
|
352
|
+
if (columnRef.current) {
|
|
353
|
+
const currentAnim = animationRef.current as Animation | null;
|
|
354
|
+
if (currentAnim) {
|
|
355
|
+
currentAnim.cancel();
|
|
356
|
+
}
|
|
357
|
+
columnRef.current.style.transform = `translateY(${normalizedOffset}px)`;
|
|
358
|
+
}
|
|
359
|
+
currentOffsetRef.current = normalizedOffset;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
let diff: number;
|
|
364
|
+
if (trend === 1) {
|
|
365
|
+
diff = target >= from ? target - from : 10 - from + target;
|
|
366
|
+
} else if (trend === -1) {
|
|
367
|
+
diff = target <= from ? target - from : target - from - 10;
|
|
368
|
+
} else {
|
|
369
|
+
diff = target - from;
|
|
370
|
+
if (diff > 5) diff -= 10;
|
|
371
|
+
else if (diff < -5) diff += 10;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const startOffset = currentOffsetRef.current ?? -(from + 10) * digitHeight;
|
|
375
|
+
const endOffset = startOffset - diff * digitHeight;
|
|
376
|
+
|
|
377
|
+
const blurEl = document.getElementById(filterId)?.querySelector('feGaussianBlur');
|
|
378
|
+
if (motionBlur && blurEl) {
|
|
379
|
+
const intensity = Math.min(Math.abs(diff) * 1.2, 6);
|
|
380
|
+
blurEl.setAttribute('stdDeviation', `0,${intensity}`);
|
|
381
|
+
containerRef.current.style.filter = `url(#${filterId})`;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const anim = columnRef.current.animate(
|
|
385
|
+
[{ transform: `translateY(${startOffset}px)` }, { transform: `translateY(${endOffset}px)` }],
|
|
386
|
+
{
|
|
387
|
+
duration,
|
|
388
|
+
delay,
|
|
389
|
+
easing,
|
|
390
|
+
fill: 'forwards',
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
animationRef.current = anim;
|
|
395
|
+
|
|
396
|
+
anim.onfinish = () => {
|
|
397
|
+
const normalizedOffset = -(target + 10) * digitHeight;
|
|
398
|
+
if (columnRef.current) {
|
|
399
|
+
anim.cancel();
|
|
400
|
+
columnRef.current.style.transform = `translateY(${normalizedOffset}px)`;
|
|
401
|
+
}
|
|
402
|
+
currentOffsetRef.current = normalizedOffset;
|
|
403
|
+
|
|
404
|
+
if (containerRef.current) {
|
|
405
|
+
containerRef.current.style.filter = 'none';
|
|
406
|
+
}
|
|
407
|
+
if (blurEl) {
|
|
408
|
+
blurEl.setAttribute('stdDeviation', '0,0');
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
animationRef.current = null;
|
|
412
|
+
|
|
413
|
+
if (targetDigitRef.current !== target) {
|
|
414
|
+
requestAnimationFrame(() => {
|
|
415
|
+
animateToDigit(targetDigitRef.current);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
anim.oncancel = () => {
|
|
421
|
+
animationRef.current = null;
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
return (
|
|
426
|
+
<>
|
|
427
|
+
<svg style={{ position: 'absolute', width: 0, height: 0 }} aria-hidden="true">
|
|
428
|
+
<defs>
|
|
429
|
+
<filter id={filterId}>
|
|
430
|
+
<feGaussianBlur in="SourceGraphic" stdDeviation="0,0" />
|
|
431
|
+
</filter>
|
|
432
|
+
</defs>
|
|
433
|
+
</svg>
|
|
434
|
+
|
|
435
|
+
<div
|
|
436
|
+
ref={containerRef}
|
|
437
|
+
style={{
|
|
438
|
+
position: 'relative',
|
|
439
|
+
height: `${digitHeight}px`,
|
|
440
|
+
overflow: 'hidden',
|
|
441
|
+
width: '0.65em',
|
|
442
|
+
textAlign: 'center',
|
|
443
|
+
opacity: isEntering ? 0 : 1,
|
|
444
|
+
}}
|
|
445
|
+
>
|
|
446
|
+
<div
|
|
447
|
+
ref={columnRef}
|
|
448
|
+
style={{
|
|
449
|
+
position: 'absolute',
|
|
450
|
+
left: 0,
|
|
451
|
+
right: 0,
|
|
452
|
+
willChange: 'transform',
|
|
453
|
+
}}
|
|
454
|
+
>
|
|
455
|
+
{sequence.map((d, i) => (
|
|
456
|
+
<div
|
|
457
|
+
key={i}
|
|
458
|
+
style={{
|
|
459
|
+
height: `${digitHeight}px`,
|
|
460
|
+
display: 'flex',
|
|
461
|
+
alignItems: 'center',
|
|
462
|
+
justifyContent: 'center',
|
|
463
|
+
}}
|
|
464
|
+
>
|
|
465
|
+
{d}
|
|
466
|
+
</div>
|
|
467
|
+
))}
|
|
468
|
+
</div>
|
|
469
|
+
</div>
|
|
470
|
+
</>
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export type { ISlidingNumberProps, IFormatOptions };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { StyleSlots } from '@/core/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Style slots for SlidingText component
|
|
5
|
+
*/
|
|
6
|
+
export type SlidingTextSlot = 'root' | 'content' | 'token';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base styles for SlidingText component
|
|
10
|
+
*/
|
|
11
|
+
export const slidingTextBaseStyles: StyleSlots<SlidingTextSlot> = {
|
|
12
|
+
root: 'waapi-sliding-text-container',
|
|
13
|
+
content: 'waapi-sliding-text-content',
|
|
14
|
+
token: 'waapi-sliding-text-token',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* CSS classes for animation states
|
|
19
|
+
*/
|
|
20
|
+
export const slidingTextAnimationClasses = {
|
|
21
|
+
enterFrom: 'enter-from',
|
|
22
|
+
enterTo: 'enter-to',
|
|
23
|
+
exitActive: 'exit-active',
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* CSS classes for direction variants
|
|
28
|
+
*/
|
|
29
|
+
export const slidingTextDirectionClasses = {
|
|
30
|
+
vertical: 'waapi-direction-vertical',
|
|
31
|
+
horizontal: 'waapi-direction-horizontal',
|
|
32
|
+
} as const;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props for SlidingText component
|
|
3
|
+
*
|
|
4
|
+
* Character or word-by-word text animations with entrance/exit transitions and blur effects.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* // Character animation (default)
|
|
9
|
+
* <SlidingText text="Hello World" mode="character" />
|
|
10
|
+
*
|
|
11
|
+
* // Word animation
|
|
12
|
+
* <SlidingText text="React Components" mode="word" />
|
|
13
|
+
*
|
|
14
|
+
* // Horizontal direction
|
|
15
|
+
* <SlidingText
|
|
16
|
+
* text="Slide In"
|
|
17
|
+
* direction="horizontal"
|
|
18
|
+
* blur={false}
|
|
19
|
+
* />
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface ISlidingTextProps {
|
|
23
|
+
/** The text content to animate */
|
|
24
|
+
text: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Animation mode
|
|
28
|
+
* - 'character': Each character animates individually
|
|
29
|
+
* - 'word': The text animates as a unit
|
|
30
|
+
* - 'none': No animation
|
|
31
|
+
*/
|
|
32
|
+
mode?: 'word' | 'character' | 'none';
|
|
33
|
+
|
|
34
|
+
/** Animation direction */
|
|
35
|
+
direction?: 'vertical' | 'horizontal';
|
|
36
|
+
|
|
37
|
+
/** Delay between each character/word in milliseconds */
|
|
38
|
+
staggerDelay?: number;
|
|
39
|
+
|
|
40
|
+
/** Animation duration in milliseconds */
|
|
41
|
+
duration?: number;
|
|
42
|
+
|
|
43
|
+
/** CSS easing function */
|
|
44
|
+
easing?: string;
|
|
45
|
+
|
|
46
|
+
/** Enable blur effect during animation */
|
|
47
|
+
blur?: boolean;
|
|
48
|
+
|
|
49
|
+
/** Animate width changes during animation */
|
|
50
|
+
widthAnimation?: boolean;
|
|
51
|
+
|
|
52
|
+
/** Initial animation state */
|
|
53
|
+
initial?: 'initial' | false;
|
|
54
|
+
|
|
55
|
+
/** Trigger animation state */
|
|
56
|
+
animate?: 'animate';
|
|
57
|
+
|
|
58
|
+
/** Exit animation state */
|
|
59
|
+
exit?: 'exit';
|
|
60
|
+
|
|
61
|
+
/** Callback when animation completes */
|
|
62
|
+
onAnimationComplete?: () => void;
|
|
63
|
+
|
|
64
|
+
/** Additional CSS class name */
|
|
65
|
+
className?: string;
|
|
66
|
+
|
|
67
|
+
/** Additional inline styles */
|
|
68
|
+
style?: React.CSSProperties;
|
|
69
|
+
}
|