@satoriui/blur-reveal 0.0.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/blur-reveal.tsx +122 -0
- package/package.json +16 -0
package/blur-reveal.tsx
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { AnimatePresence, motion } from "motion/react";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
|
|
5
|
+
export interface BlurRevealProps {
|
|
6
|
+
children: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
delay?: number;
|
|
9
|
+
speedReveal?: number;
|
|
10
|
+
speedSegment?: number;
|
|
11
|
+
trigger?: boolean;
|
|
12
|
+
onAnimationComplete?: () => void;
|
|
13
|
+
onAnimationStart?: () => void;
|
|
14
|
+
as?: keyof React.JSX.IntrinsicElements;
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
inView?: boolean;
|
|
17
|
+
once?: boolean;
|
|
18
|
+
letterSpacing?: string | number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const BlurReveal = ({
|
|
22
|
+
children,
|
|
23
|
+
className,
|
|
24
|
+
delay = 0,
|
|
25
|
+
speedReveal = 1.5,
|
|
26
|
+
speedSegment = 0.5,
|
|
27
|
+
trigger = true,
|
|
28
|
+
onAnimationComplete,
|
|
29
|
+
onAnimationStart,
|
|
30
|
+
as = "p",
|
|
31
|
+
style,
|
|
32
|
+
inView = false,
|
|
33
|
+
once = true,
|
|
34
|
+
letterSpacing,
|
|
35
|
+
}: BlurRevealProps) => {
|
|
36
|
+
const MotionTag = motion[as as keyof typeof motion] as typeof motion.div;
|
|
37
|
+
|
|
38
|
+
const stagger = 0.03 / speedReveal;
|
|
39
|
+
const baseDuration = 0.3 / speedSegment;
|
|
40
|
+
|
|
41
|
+
const containerVariants = {
|
|
42
|
+
hidden: { opacity: 0 },
|
|
43
|
+
visible: {
|
|
44
|
+
opacity: 1,
|
|
45
|
+
transition: {
|
|
46
|
+
staggerChildren: stagger,
|
|
47
|
+
delayChildren: delay,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
exit: {
|
|
51
|
+
transition: {
|
|
52
|
+
staggerChildren: stagger,
|
|
53
|
+
staggerDirection: -1,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const itemVariants = {
|
|
59
|
+
hidden: { opacity: 0, filter: "blur(12px)", y: 10 },
|
|
60
|
+
visible: {
|
|
61
|
+
opacity: 1,
|
|
62
|
+
filter: "blur(0px)",
|
|
63
|
+
y: 0,
|
|
64
|
+
transition: {
|
|
65
|
+
duration: baseDuration,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
exit: { opacity: 0, filter: "blur(12px)", y: 10 },
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<AnimatePresence mode="popLayout">
|
|
73
|
+
{trigger && (
|
|
74
|
+
<MotionTag
|
|
75
|
+
initial="hidden"
|
|
76
|
+
whileInView={inView ? "visible" : undefined}
|
|
77
|
+
animate={inView ? undefined : "visible"}
|
|
78
|
+
exit="exit"
|
|
79
|
+
variants={containerVariants}
|
|
80
|
+
viewport={{ once }}
|
|
81
|
+
className={className}
|
|
82
|
+
onAnimationComplete={onAnimationComplete}
|
|
83
|
+
onAnimationStart={onAnimationStart}
|
|
84
|
+
style={style}
|
|
85
|
+
>
|
|
86
|
+
<span className="sr-only">{children}</span>
|
|
87
|
+
{children &&
|
|
88
|
+
children.split(" ").map((word, wordIndex, wordsArray) => (
|
|
89
|
+
<span
|
|
90
|
+
key={`word-${wordIndex}`}
|
|
91
|
+
className="inline-block whitespace-nowrap"
|
|
92
|
+
aria-hidden="true"
|
|
93
|
+
>
|
|
94
|
+
{word.split("").map((char, charIndex) => (
|
|
95
|
+
<motion.span
|
|
96
|
+
key={`char-${wordIndex}-${charIndex}`}
|
|
97
|
+
variants={itemVariants}
|
|
98
|
+
className="inline-block"
|
|
99
|
+
style={
|
|
100
|
+
letterSpacing ? { marginRight: letterSpacing } : undefined
|
|
101
|
+
}
|
|
102
|
+
>
|
|
103
|
+
{char}
|
|
104
|
+
</motion.span>
|
|
105
|
+
))}
|
|
106
|
+
{wordIndex < wordsArray.length - 1 && (
|
|
107
|
+
<motion.span
|
|
108
|
+
key={`space-${wordIndex}`}
|
|
109
|
+
variants={itemVariants}
|
|
110
|
+
className="inline-block"
|
|
111
|
+
>
|
|
112
|
+
|
|
113
|
+
</motion.span>
|
|
114
|
+
)}
|
|
115
|
+
</span>
|
|
116
|
+
))}
|
|
117
|
+
</MotionTag>
|
|
118
|
+
)}
|
|
119
|
+
</AnimatePresence>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
export default BlurReveal;
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@satoriui/blur-reveal",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"registry.json",
|
|
10
|
+
"blur-reveal.tsx"
|
|
11
|
+
],
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"react": ">=18",
|
|
14
|
+
"react-dom": ">=18"
|
|
15
|
+
}
|
|
16
|
+
}
|