@istmx/ui 0.1.7 → 0.1.9
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/README.md +62 -1
- package/bin/istmx.mjs +5 -1
- package/package.json +1 -1
- package/registry/button.tsx +259 -0
- package/registry/image-trail.tsx +121 -0
- package/registry/infinite-image-canvas.tsx +263 -0
- package/registry/mobile-menu-dock.tsx +2 -1
- package/registry/text-reveal.tsx +307 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Editable UI components for your codebase. ISTMX adds the component source to
|
|
4
4
|
your project so you can read it, change it, and make it yours.
|
|
5
5
|
|
|
6
|
-
**Website:** [aryanonai.vercel.app](
|
|
6
|
+
**Website:** [aryanonai.vercel.app](https://aryanonai.vercel.app/)
|
|
7
7
|
|
|
8
8
|
## Add a component
|
|
9
9
|
|
|
@@ -13,6 +13,12 @@ Run the command from your project root:
|
|
|
13
13
|
npx @istmx/ui add animated-text
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
Add the practical controls:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npx @istmx/ui add button
|
|
20
|
+
```
|
|
21
|
+
|
|
16
22
|
Or use your preferred package manager:
|
|
17
23
|
|
|
18
24
|
```sh
|
|
@@ -27,6 +33,18 @@ Add the image stack component with:
|
|
|
27
33
|
npx @istmx/ui add image-accordion
|
|
28
34
|
```
|
|
29
35
|
|
|
36
|
+
Add the pointer-driven image trail with:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npx @istmx/ui add image-trail
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Add the pannable infinite image canvas with:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npx @istmx/ui add infinite-image-canvas
|
|
46
|
+
```
|
|
47
|
+
|
|
30
48
|
Add the magnifying dock navigation with:
|
|
31
49
|
|
|
32
50
|
```sh
|
|
@@ -113,12 +131,55 @@ Other options include `direction`, `interval`, `speed`, `scale`, and effect
|
|
|
113
131
|
settings for blur, fade, slide, and wave. The full component implementation is
|
|
114
132
|
in your `components/ui/animated-text.tsx` file.
|
|
115
133
|
|
|
134
|
+
## Text Reveal
|
|
135
|
+
|
|
136
|
+
Install the editable source with:
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
npx @istmx/ui add text-reveal
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`TextReveal` reveals plain text line by line and character by character. It
|
|
143
|
+
supports a viewport-triggered entrance by default, or reversible scroll-linked
|
|
144
|
+
animation by passing a Motion value from `useScroll`.
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
import TextReveal from '@/components/ui/text-reveal'
|
|
148
|
+
|
|
149
|
+
export function Quote() {
|
|
150
|
+
return (
|
|
151
|
+
<TextReveal
|
|
152
|
+
text={'Every word arrives softly,\none character at a time.'}
|
|
153
|
+
characterStagger={0.028}
|
|
154
|
+
lineStagger={0.2}
|
|
155
|
+
duration={0.65}
|
|
156
|
+
waveDistance={8}
|
|
157
|
+
waveOvershoot={6}
|
|
158
|
+
sidewaysDistance={1.5}
|
|
159
|
+
blurAmount={6}
|
|
160
|
+
opacityFrom={0.08}
|
|
161
|
+
opacityPeak={0.72}
|
|
162
|
+
scaleFrom={0.96}
|
|
163
|
+
scalePeak={1.025}
|
|
164
|
+
/>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Tune `characterStagger`, `lineStagger`, `duration`, `waveDistance`,
|
|
170
|
+
`waveOvershoot`, `sidewaysDistance`, `blurAmount`, opacity, and scale props to
|
|
171
|
+
shape the reveal. The component keeps words together across natural line wraps
|
|
172
|
+
and provides a single screen-reader text string.
|
|
173
|
+
|
|
116
174
|
## CLI options
|
|
117
175
|
|
|
118
176
|
```sh
|
|
119
177
|
npx @istmx/ui add animated-text --no-install
|
|
120
178
|
npx @istmx/ui add animated-text --overwrite
|
|
179
|
+
npx @istmx/ui add text-reveal
|
|
121
180
|
npx @istmx/ui add image-accordion
|
|
181
|
+
npx @istmx/ui add image-trail
|
|
182
|
+
npx @istmx/ui add infinite-image-canvas
|
|
122
183
|
npx @istmx/ui add dock-navigation
|
|
123
184
|
npx @istmx/ui add mobile-menu-dock
|
|
124
185
|
```
|
package/bin/istmx.mjs
CHANGED
|
@@ -6,9 +6,13 @@ import { access, mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
|
6
6
|
import path from 'node:path'
|
|
7
7
|
import { fileURLToPath } from 'node:url'
|
|
8
8
|
|
|
9
|
-
const VERSION = '0.1.
|
|
9
|
+
const VERSION = '0.1.9'
|
|
10
10
|
const COMPONENTS = {
|
|
11
|
+
button: { fileName: 'button.tsx' },
|
|
11
12
|
'animated-text': { fileName: 'animated-text.tsx' },
|
|
13
|
+
'text-reveal': { fileName: 'text-reveal.tsx' },
|
|
14
|
+
'infinite-image-canvas': { fileName: 'infinite-image-canvas.tsx' },
|
|
15
|
+
'image-trail': { fileName: 'image-trail.tsx' },
|
|
12
16
|
'image-accordion': { fileName: 'image-accordion.tsx' },
|
|
13
17
|
'dock-navigation': {
|
|
14
18
|
fileName: 'dock-navigation.tsx',
|
package/package.json
CHANGED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react'
|
|
4
|
+
import type { ReactNode } from 'react'
|
|
5
|
+
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
|
6
|
+
import type { HTMLMotionProps } from 'motion/react'
|
|
7
|
+
import { cn } from '@/lib/utils'
|
|
8
|
+
|
|
9
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'soft'
|
|
10
|
+
export type ButtonSize = 'sm' | 'md' | 'lg' | 'icon'
|
|
11
|
+
export type ButtonIntent = 'save' | 'share' | 'delete'
|
|
12
|
+
|
|
13
|
+
type SharedButtonProps = {
|
|
14
|
+
children?: ReactNode
|
|
15
|
+
className?: string
|
|
16
|
+
icon?: ReactNode
|
|
17
|
+
feedback?: {
|
|
18
|
+
label: string
|
|
19
|
+
icon?: ReactNode
|
|
20
|
+
duration?: number
|
|
21
|
+
}
|
|
22
|
+
intent?: ButtonIntent
|
|
23
|
+
variant?: ButtonVariant
|
|
24
|
+
size?: ButtonSize
|
|
25
|
+
disabled?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type NativeButtonProps = SharedButtonProps &
|
|
29
|
+
Omit<HTMLMotionProps<'button'>, keyof SharedButtonProps> & {
|
|
30
|
+
href?: never
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type ButtonAnchorProps = SharedButtonProps &
|
|
34
|
+
Omit<HTMLMotionProps<'a'>, keyof SharedButtonProps | 'href'> & {
|
|
35
|
+
href: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type ButtonProps = NativeButtonProps | ButtonAnchorProps
|
|
39
|
+
|
|
40
|
+
const VARIANT_CLASSES: Record<ButtonVariant, string> = {
|
|
41
|
+
primary:
|
|
42
|
+
'',
|
|
43
|
+
secondary:
|
|
44
|
+
'border border-border bg-surface text-foreground hover:border-foreground/25 hover:bg-surface/75',
|
|
45
|
+
outline:
|
|
46
|
+
'border border-border bg-transparent text-foreground hover:border-foreground/45 hover:bg-surface/70',
|
|
47
|
+
ghost:
|
|
48
|
+
'border border-transparent bg-transparent text-foreground hover:bg-surface/75',
|
|
49
|
+
soft:
|
|
50
|
+
'border border-transparent bg-surface text-foreground hover:border-border hover:bg-surface/80',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const INTENT_CLASSES: Record<ButtonIntent, string> = {
|
|
54
|
+
save: 'border-emerald-400 bg-emerald-400 text-emerald-950 hover:border-emerald-300 hover:bg-emerald-300 hover:drop-shadow-[0_7px_12px_rgba(16,185,129,0.2)] active:drop-shadow-[0_2px_5px_rgba(16,185,129,0.2)] focus-visible:ring-emerald-300/60',
|
|
55
|
+
share: 'border-sky-400 bg-sky-400 text-sky-950 hover:border-sky-300 hover:bg-sky-300 hover:drop-shadow-[0_7px_12px_rgba(14,165,233,0.2)] active:drop-shadow-[0_2px_5px_rgba(14,165,233,0.2)] focus-visible:ring-sky-300/60',
|
|
56
|
+
delete: 'border-rose-400 bg-rose-400 text-rose-950 hover:border-rose-300 hover:bg-rose-300 hover:drop-shadow-[0_7px_12px_rgba(244,63,94,0.2)] active:drop-shadow-[0_2px_5px_rgba(244,63,94,0.2)] focus-visible:ring-rose-300/60',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const INTENT_FEEDBACK_CLASSES: Record<ButtonIntent, string> = {
|
|
60
|
+
save: 'border-emerald-100 ring-2 ring-emerald-200/70 drop-shadow-[0_0_10px_rgba(16,185,129,0.28)]',
|
|
61
|
+
share: 'border-sky-100 ring-2 ring-sky-200/70 drop-shadow-[0_0_10px_rgba(56,189,248,0.28)]',
|
|
62
|
+
delete: 'border-rose-100 ring-2 ring-rose-200/70 drop-shadow-[0_0_10px_rgba(244,63,94,0.28)]',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const SIZE_CLASSES: Record<ButtonSize, string> = {
|
|
66
|
+
sm: 'min-h-8 gap-1.5 rounded-md px-3 text-xs',
|
|
67
|
+
md: 'min-h-10 gap-2 rounded-lg px-4 text-sm',
|
|
68
|
+
lg: 'min-h-12 gap-2.5 rounded-xl px-5 text-sm',
|
|
69
|
+
icon: 'size-10 rounded-lg p-0',
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const MOTION_TRANSITION = {
|
|
73
|
+
type: 'spring' as const,
|
|
74
|
+
stiffness: 420,
|
|
75
|
+
damping: 26,
|
|
76
|
+
mass: 0.55,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function buttonClassName(
|
|
80
|
+
variant: ButtonVariant,
|
|
81
|
+
size: ButtonSize,
|
|
82
|
+
className?: string,
|
|
83
|
+
intent: ButtonIntent = 'save',
|
|
84
|
+
feedbackActive = false,
|
|
85
|
+
) {
|
|
86
|
+
return cn(
|
|
87
|
+
'group relative inline-flex shrink-0 cursor-pointer items-center justify-center overflow-hidden font-medium whitespace-nowrap transition-[color,background-color,border-color,filter] duration-200 focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-foreground/35 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
|
|
88
|
+
variant === 'primary' ? INTENT_CLASSES[intent] : VARIANT_CLASSES[variant],
|
|
89
|
+
SIZE_CLASSES[size],
|
|
90
|
+
feedbackActive && INTENT_FEEDBACK_CLASSES[intent],
|
|
91
|
+
className,
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function Button(props: NativeButtonProps): ReactNode
|
|
96
|
+
export function Button(props: ButtonAnchorProps): ReactNode
|
|
97
|
+
export function Button(props: ButtonProps) {
|
|
98
|
+
const reduceMotion = useReducedMotion()
|
|
99
|
+
const [feedbackActive, setFeedbackActive] = useState(false)
|
|
100
|
+
const feedbackTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
101
|
+
|
|
102
|
+
useEffect(
|
|
103
|
+
() => () => {
|
|
104
|
+
if (feedbackTimeout.current) clearTimeout(feedbackTimeout.current)
|
|
105
|
+
},
|
|
106
|
+
[],
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
function showFeedback(duration = 1800) {
|
|
110
|
+
setFeedbackActive(true)
|
|
111
|
+
if (feedbackTimeout.current) clearTimeout(feedbackTimeout.current)
|
|
112
|
+
feedbackTimeout.current = setTimeout(() => setFeedbackActive(false), duration)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function completeAction(result: unknown, duration?: number) {
|
|
116
|
+
if (result && typeof (result as PromiseLike<unknown>).then === 'function') {
|
|
117
|
+
void Promise.resolve(result).then(
|
|
118
|
+
() => showFeedback(duration),
|
|
119
|
+
() => undefined,
|
|
120
|
+
)
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
showFeedback(duration)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const motionProps = {
|
|
127
|
+
whileHover: reduceMotion ? undefined : { y: -2, scale: 1.025 },
|
|
128
|
+
whileTap: reduceMotion ? undefined : { y: 0, scale: 0.955, filter: 'brightness(0.9)' },
|
|
129
|
+
transition: MOTION_TRANSITION,
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if ('href' in props && typeof props.href === 'string') {
|
|
133
|
+
const {
|
|
134
|
+
href,
|
|
135
|
+
variant = 'primary',
|
|
136
|
+
size = 'md',
|
|
137
|
+
className,
|
|
138
|
+
children,
|
|
139
|
+
icon,
|
|
140
|
+
feedback,
|
|
141
|
+
intent = 'save',
|
|
142
|
+
disabled,
|
|
143
|
+
onClick,
|
|
144
|
+
...anchorProps
|
|
145
|
+
} = props
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<motion.a
|
|
149
|
+
{...anchorProps}
|
|
150
|
+
href={href}
|
|
151
|
+
aria-disabled={disabled || undefined}
|
|
152
|
+
tabIndex={disabled ? -1 : anchorProps.tabIndex}
|
|
153
|
+
onClick={(event) => {
|
|
154
|
+
if (disabled) {
|
|
155
|
+
event.preventDefault()
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
const result = onClick?.(event)
|
|
159
|
+
if (feedback) completeAction(result, feedback.duration)
|
|
160
|
+
}}
|
|
161
|
+
data-state={feedbackActive ? 'success' : 'idle'}
|
|
162
|
+
className={buttonClassName(variant, size, className, intent, feedbackActive && !!feedback)}
|
|
163
|
+
{...motionProps}
|
|
164
|
+
>
|
|
165
|
+
<span
|
|
166
|
+
aria-live={feedback ? 'polite' : undefined}
|
|
167
|
+
className="relative inline-flex items-center justify-center gap-2"
|
|
168
|
+
>
|
|
169
|
+
{icon || feedback ? (
|
|
170
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
171
|
+
<motion.span
|
|
172
|
+
key={feedbackActive ? 'feedback-icon' : 'idle-icon'}
|
|
173
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.65, rotate: -12 }}
|
|
174
|
+
animate={{ opacity: 1, scale: 1, rotate: 0 }}
|
|
175
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.65, rotate: 12 }}
|
|
176
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
177
|
+
className="inline-flex"
|
|
178
|
+
aria-hidden="true"
|
|
179
|
+
>
|
|
180
|
+
{feedbackActive ? feedback?.icon ?? '✓' : icon}
|
|
181
|
+
</motion.span>
|
|
182
|
+
</AnimatePresence>
|
|
183
|
+
) : null}
|
|
184
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
185
|
+
<motion.span
|
|
186
|
+
key={feedbackActive ? 'feedback-label' : 'idle-label'}
|
|
187
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 5 }}
|
|
188
|
+
animate={{ opacity: 1, y: 0 }}
|
|
189
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -5 }}
|
|
190
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
191
|
+
>
|
|
192
|
+
{feedbackActive && feedback ? feedback.label : children}
|
|
193
|
+
</motion.span>
|
|
194
|
+
</AnimatePresence>
|
|
195
|
+
</span>
|
|
196
|
+
</motion.a>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const {
|
|
201
|
+
variant = 'primary',
|
|
202
|
+
size = 'md',
|
|
203
|
+
className,
|
|
204
|
+
children,
|
|
205
|
+
icon,
|
|
206
|
+
feedback,
|
|
207
|
+
intent = 'save',
|
|
208
|
+
disabled,
|
|
209
|
+
type = 'button',
|
|
210
|
+
...buttonProps
|
|
211
|
+
} = props
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<motion.button
|
|
215
|
+
{...buttonProps}
|
|
216
|
+
type={type}
|
|
217
|
+
disabled={disabled}
|
|
218
|
+
aria-live={feedback ? 'polite' : undefined}
|
|
219
|
+
data-state={feedbackActive ? 'success' : 'idle'}
|
|
220
|
+
onClick={(event) => {
|
|
221
|
+
const result = buttonProps.onClick?.(event)
|
|
222
|
+
if (!disabled && feedback) completeAction(result, feedback.duration)
|
|
223
|
+
}}
|
|
224
|
+
className={buttonClassName(variant, size, className, intent, feedbackActive && !!feedback)}
|
|
225
|
+
{...motionProps}
|
|
226
|
+
>
|
|
227
|
+
<span className="relative inline-flex items-center justify-center gap-2">
|
|
228
|
+
{icon || feedback ? (
|
|
229
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
230
|
+
<motion.span
|
|
231
|
+
key={feedbackActive ? 'feedback-icon' : 'idle-icon'}
|
|
232
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.65, rotate: -12 }}
|
|
233
|
+
animate={{ opacity: 1, scale: 1, rotate: 0 }}
|
|
234
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.65, rotate: 12 }}
|
|
235
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
236
|
+
className="inline-flex"
|
|
237
|
+
aria-hidden="true"
|
|
238
|
+
>
|
|
239
|
+
{feedbackActive ? feedback?.icon ?? '✓' : icon}
|
|
240
|
+
</motion.span>
|
|
241
|
+
</AnimatePresence>
|
|
242
|
+
) : null}
|
|
243
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
244
|
+
<motion.span
|
|
245
|
+
key={feedbackActive ? 'feedback-label' : 'idle-label'}
|
|
246
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 5 }}
|
|
247
|
+
animate={{ opacity: 1, y: 0 }}
|
|
248
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -5 }}
|
|
249
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
250
|
+
>
|
|
251
|
+
{feedbackActive && feedback ? feedback.label : children}
|
|
252
|
+
</motion.span>
|
|
253
|
+
</AnimatePresence>
|
|
254
|
+
</span>
|
|
255
|
+
</motion.button>
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export default Button
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useRef, useState } from 'react'
|
|
4
|
+
import type { PointerEvent } from 'react'
|
|
5
|
+
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
|
6
|
+
import { cn } from '@/lib/utils'
|
|
7
|
+
|
|
8
|
+
export type ImageTrailItem = {
|
|
9
|
+
src: string
|
|
10
|
+
alt: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ImageTrailProps = {
|
|
14
|
+
images: ImageTrailItem[]
|
|
15
|
+
className?: string
|
|
16
|
+
imageClassName?: string
|
|
17
|
+
throttle?: number
|
|
18
|
+
maxTrailItems?: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type TrailImage = ImageTrailItem & {
|
|
22
|
+
id: number
|
|
23
|
+
x: number
|
|
24
|
+
y: number
|
|
25
|
+
rotate: number
|
|
26
|
+
driftX: number
|
|
27
|
+
driftY: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function ImageTrail({
|
|
31
|
+
images,
|
|
32
|
+
className,
|
|
33
|
+
imageClassName,
|
|
34
|
+
throttle = 160,
|
|
35
|
+
maxTrailItems = 5,
|
|
36
|
+
}: ImageTrailProps) {
|
|
37
|
+
const [trail, setTrail] = useState<TrailImage[]>([])
|
|
38
|
+
const lastSpawn = useRef(0)
|
|
39
|
+
const nextId = useRef(0)
|
|
40
|
+
const reduceMotion = useReducedMotion()
|
|
41
|
+
|
|
42
|
+
function handlePointerMove(event: PointerEvent<HTMLDivElement>) {
|
|
43
|
+
if (reduceMotion || images.length === 0) return
|
|
44
|
+
|
|
45
|
+
const now = performance.now()
|
|
46
|
+
if (now - lastSpawn.current < Math.max(0, throttle)) return
|
|
47
|
+
lastSpawn.current = now
|
|
48
|
+
|
|
49
|
+
const bounds = event.currentTarget.getBoundingClientRect()
|
|
50
|
+
const id = nextId.current++
|
|
51
|
+
const image = images[id % images.length]
|
|
52
|
+
const x = event.clientX - bounds.left
|
|
53
|
+
const y = event.clientY - bounds.top
|
|
54
|
+
|
|
55
|
+
setTrail((current) => [
|
|
56
|
+
...current,
|
|
57
|
+
{
|
|
58
|
+
...image,
|
|
59
|
+
id,
|
|
60
|
+
x,
|
|
61
|
+
y,
|
|
62
|
+
rotate: (id % 2 === 0 ? -1 : 1) * (4 + (id % 4) * 2),
|
|
63
|
+
driftX: (id % 2 === 0 ? -1 : 1) * (12 + (id % 3) * 5),
|
|
64
|
+
driftY: -18 - (id % 3) * 7,
|
|
65
|
+
},
|
|
66
|
+
].slice(-Math.max(1, maxTrailItems)))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
role="group"
|
|
72
|
+
aria-label="Move or tap over the canvas to create an image trail"
|
|
73
|
+
onPointerMove={handlePointerMove}
|
|
74
|
+
onPointerDown={handlePointerMove}
|
|
75
|
+
className={cn(
|
|
76
|
+
'border-border bg-surface relative isolate h-[24rem] w-full touch-pan-y overflow-hidden rounded-2xl border bg-[radial-gradient(ellipse_at_50%_40%,color-mix(in_srgb,var(--foreground)_9%,transparent),transparent_55%),linear-gradient(145deg,color-mix(in_srgb,var(--foreground)_3%,var(--background)),var(--background))] sm:h-[32rem]',
|
|
77
|
+
className,
|
|
78
|
+
)}
|
|
79
|
+
>
|
|
80
|
+
<div
|
|
81
|
+
aria-hidden="true"
|
|
82
|
+
className="pointer-events-none absolute inset-0 bg-[linear-gradient(to_right,color-mix(in_srgb,var(--foreground)_3%,transparent)_1px,transparent_1px),linear-gradient(to_bottom,color-mix(in_srgb,var(--foreground)_3%,transparent)_1px,transparent_1px)] bg-size-[48px_48px] opacity-30"
|
|
83
|
+
/>
|
|
84
|
+
<div className="pointer-events-none absolute inset-x-0 top-5 z-10 flex justify-center px-4">
|
|
85
|
+
<span className="border-border/70 bg-background/75 text-muted rounded-full border px-4 py-2 text-xs shadow-sm backdrop-blur-md">
|
|
86
|
+
Move or tap to explore
|
|
87
|
+
</span>
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
<AnimatePresence initial={false}>
|
|
91
|
+
{trail.map((item) => (
|
|
92
|
+
<motion.img
|
|
93
|
+
key={item.id}
|
|
94
|
+
src={item.src}
|
|
95
|
+
alt=""
|
|
96
|
+
aria-hidden="true"
|
|
97
|
+
draggable={false}
|
|
98
|
+
initial={{ opacity: 0, scale: 0.72, rotate: item.rotate + 8 }}
|
|
99
|
+
animate={{
|
|
100
|
+
opacity: [0, 1, 0.88, 0],
|
|
101
|
+
scale: [0.72, 1, 1, 0.86],
|
|
102
|
+
rotate: item.rotate,
|
|
103
|
+
x: item.driftX,
|
|
104
|
+
y: item.driftY,
|
|
105
|
+
}}
|
|
106
|
+
exit={{ opacity: 0, scale: 0.8 }}
|
|
107
|
+
transition={{ duration: 1.15, times: [0, 0.16, 0.58, 1], ease: 'easeOut' }}
|
|
108
|
+
onAnimationComplete={() =>
|
|
109
|
+
setTrail((current) => current.filter((image) => image.id !== item.id))
|
|
110
|
+
}
|
|
111
|
+
style={{ left: item.x, top: item.y }}
|
|
112
|
+
className={cn(
|
|
113
|
+
'pointer-events-none absolute -ml-[5.25rem] -mt-[7rem] h-56 w-40 rounded-xl border border-white/70 object-cover shadow-[0_18px_50px_-18px_rgba(0,0,0,0.65)] sm:-ml-[6rem] sm:-mt-[8rem] sm:h-64 sm:w-48',
|
|
114
|
+
imageClassName,
|
|
115
|
+
)}
|
|
116
|
+
/>
|
|
117
|
+
))}
|
|
118
|
+
</AnimatePresence>
|
|
119
|
+
</div>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react'
|
|
4
|
+
import type { KeyboardEvent, PointerEvent } from 'react'
|
|
5
|
+
import {
|
|
6
|
+
AnimatePresence,
|
|
7
|
+
motion,
|
|
8
|
+
useInView,
|
|
9
|
+
useReducedMotion,
|
|
10
|
+
} from 'motion/react'
|
|
11
|
+
import { cn } from '@/lib/utils'
|
|
12
|
+
|
|
13
|
+
export type InfiniteImageCanvasItem = {
|
|
14
|
+
src: string
|
|
15
|
+
alt: string
|
|
16
|
+
name: string
|
|
17
|
+
color: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type InfiniteImageCanvasProps = {
|
|
21
|
+
images: InfiniteImageCanvasItem[]
|
|
22
|
+
heading?: string
|
|
23
|
+
description?: string
|
|
24
|
+
className?: string
|
|
25
|
+
tileWidth?: number
|
|
26
|
+
tileHeight?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Camera = { x: number; y: number }
|
|
30
|
+
type CanvasSize = { width: number; height: number }
|
|
31
|
+
|
|
32
|
+
function CanvasTile({
|
|
33
|
+
image,
|
|
34
|
+
left,
|
|
35
|
+
top,
|
|
36
|
+
width,
|
|
37
|
+
height,
|
|
38
|
+
reduceMotion,
|
|
39
|
+
}: {
|
|
40
|
+
image: InfiniteImageCanvasItem
|
|
41
|
+
left: number
|
|
42
|
+
top: number
|
|
43
|
+
width: number
|
|
44
|
+
height: number
|
|
45
|
+
reduceMotion: boolean
|
|
46
|
+
}) {
|
|
47
|
+
const tileRef = useRef<HTMLDivElement>(null)
|
|
48
|
+
const isInView = useInView(tileRef, { once: false, amount: 0.12 })
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<motion.div
|
|
52
|
+
ref={tileRef}
|
|
53
|
+
initial={
|
|
54
|
+
reduceMotion
|
|
55
|
+
? { opacity: 1 }
|
|
56
|
+
: { opacity: 0, scale: 0.96, filter: 'blur(8px)' }
|
|
57
|
+
}
|
|
58
|
+
animate={{
|
|
59
|
+
x: left,
|
|
60
|
+
y: top,
|
|
61
|
+
opacity: reduceMotion ? 1 : isInView ? 1 : 0,
|
|
62
|
+
scale: reduceMotion || isInView ? 1 : 0.94,
|
|
63
|
+
filter: reduceMotion || isInView ? 'blur(0px)' : 'blur(7px)',
|
|
64
|
+
}}
|
|
65
|
+
exit={
|
|
66
|
+
reduceMotion
|
|
67
|
+
? { opacity: 0 }
|
|
68
|
+
: { opacity: 0, scale: 0.94, filter: 'blur(7px)' }
|
|
69
|
+
}
|
|
70
|
+
transition={
|
|
71
|
+
reduceMotion
|
|
72
|
+
? { duration: 0 }
|
|
73
|
+
: {
|
|
74
|
+
x: { type: 'spring', stiffness: 150, damping: 28, mass: 0.7 },
|
|
75
|
+
y: { type: 'spring', stiffness: 150, damping: 28, mass: 0.7 },
|
|
76
|
+
opacity: { duration: 0.35 },
|
|
77
|
+
scale: { duration: 0.4, ease: 'easeOut' },
|
|
78
|
+
filter: { duration: 0.4, ease: 'easeOut' },
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
aria-hidden="true"
|
|
82
|
+
className="absolute flex flex-col gap-2 rounded-lg"
|
|
83
|
+
style={{ left: 0, top: 0, width, height }}
|
|
84
|
+
>
|
|
85
|
+
<div className="min-h-0 flex-1 overflow-hidden rounded-lg border border-white/15 bg-zinc-900 shadow-[0_12px_30px_-18px_rgba(0,0,0,0.85)]">
|
|
86
|
+
<img
|
|
87
|
+
src={image.src}
|
|
88
|
+
alt=""
|
|
89
|
+
draggable={false}
|
|
90
|
+
loading="lazy"
|
|
91
|
+
className="size-full object-cover"
|
|
92
|
+
/>
|
|
93
|
+
</div>
|
|
94
|
+
<div
|
|
95
|
+
className="flex h-8 shrink-0 items-center rounded-md px-3 text-xs font-medium tracking-wide text-zinc-900"
|
|
96
|
+
style={{ backgroundColor: image.color }}
|
|
97
|
+
>
|
|
98
|
+
<span className="truncate">{image.name}</span>
|
|
99
|
+
</div>
|
|
100
|
+
</motion.div>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default function InfiniteImageCanvas({
|
|
105
|
+
images,
|
|
106
|
+
heading = 'Somewhere, Everywhere',
|
|
107
|
+
description = 'An endless field of images, waiting to be explored.',
|
|
108
|
+
className,
|
|
109
|
+
tileWidth = 210,
|
|
110
|
+
tileHeight = 270,
|
|
111
|
+
}: InfiniteImageCanvasProps) {
|
|
112
|
+
const canvasRef = useRef<HTMLDivElement>(null)
|
|
113
|
+
const dragRef = useRef<{ pointerId: number; x: number; y: number } | null>(
|
|
114
|
+
null,
|
|
115
|
+
)
|
|
116
|
+
const [camera, setCamera] = useState<Camera>({ x: 0, y: 0 })
|
|
117
|
+
const [size, setSize] = useState<CanvasSize>({ width: 0, height: 0 })
|
|
118
|
+
const reduceMotion = useReducedMotion() ?? false
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const element = canvasRef.current
|
|
122
|
+
if (!element) return
|
|
123
|
+
|
|
124
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
125
|
+
if (!entry) return
|
|
126
|
+
setSize({
|
|
127
|
+
width: entry.contentRect.width,
|
|
128
|
+
height: entry.contentRect.height,
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
observer.observe(element)
|
|
133
|
+
return () => observer.disconnect()
|
|
134
|
+
}, [])
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
const element = canvasRef.current
|
|
138
|
+
if (!element) return
|
|
139
|
+
|
|
140
|
+
function handleWheel(event: globalThis.WheelEvent) {
|
|
141
|
+
event.preventDefault()
|
|
142
|
+
const horizontalDelta = event.shiftKey && event.deltaX === 0
|
|
143
|
+
? event.deltaY
|
|
144
|
+
: event.deltaX
|
|
145
|
+
const verticalDelta = event.shiftKey && event.deltaX === 0 ? 0 : event.deltaY
|
|
146
|
+
|
|
147
|
+
setCamera((current) => ({
|
|
148
|
+
x: current.x + horizontalDelta * 0.72,
|
|
149
|
+
y: current.y + verticalDelta * 0.72,
|
|
150
|
+
}))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
element.addEventListener('wheel', handleWheel, { passive: false })
|
|
154
|
+
return () => element.removeEventListener('wheel', handleWheel)
|
|
155
|
+
}, [])
|
|
156
|
+
|
|
157
|
+
const columns = Math.max(8, Math.ceil(size.width / tileWidth) + 4)
|
|
158
|
+
const rows = Math.max(8, Math.ceil(size.height / tileHeight) + 4)
|
|
159
|
+
const firstColumn = Math.floor(camera.x / tileWidth) - 2
|
|
160
|
+
const firstRow = Math.floor(camera.y / tileHeight) - 2
|
|
161
|
+
const cells = []
|
|
162
|
+
|
|
163
|
+
for (let rowOffset = 0; rowOffset < rows; rowOffset += 1) {
|
|
164
|
+
for (let columnOffset = 0; columnOffset < columns; columnOffset += 1) {
|
|
165
|
+
const row = firstRow + rowOffset
|
|
166
|
+
const column = firstColumn + columnOffset
|
|
167
|
+
const imageIndex = Math.abs(row * 11 + column * 7) % images.length
|
|
168
|
+
const image = images[imageIndex]
|
|
169
|
+
if (image) cells.push({ row, column, image })
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function handlePointerDown(event: PointerEvent<HTMLDivElement>) {
|
|
174
|
+
if (event.button !== 0) return
|
|
175
|
+
dragRef.current = {
|
|
176
|
+
pointerId: event.pointerId,
|
|
177
|
+
x: event.clientX,
|
|
178
|
+
y: event.clientY,
|
|
179
|
+
}
|
|
180
|
+
event.currentTarget.setPointerCapture(event.pointerId)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function handlePointerMove(event: PointerEvent<HTMLDivElement>) {
|
|
184
|
+
const drag = dragRef.current
|
|
185
|
+
if (!drag || drag.pointerId !== event.pointerId) return
|
|
186
|
+
|
|
187
|
+
const deltaX = event.clientX - drag.x
|
|
188
|
+
const deltaY = event.clientY - drag.y
|
|
189
|
+
dragRef.current = { ...drag, x: event.clientX, y: event.clientY }
|
|
190
|
+
setCamera((current) => ({
|
|
191
|
+
x: current.x - deltaX,
|
|
192
|
+
y: current.y - deltaY,
|
|
193
|
+
}))
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function stopDragging(event: PointerEvent<HTMLDivElement>) {
|
|
197
|
+
if (dragRef.current?.pointerId === event.pointerId) dragRef.current = null
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function handleKeyDown(event: KeyboardEvent<HTMLDivElement>) {
|
|
201
|
+
const directions: Record<string, Camera> = {
|
|
202
|
+
ArrowLeft: { x: -tileWidth / 2, y: 0 },
|
|
203
|
+
ArrowRight: { x: tileWidth / 2, y: 0 },
|
|
204
|
+
ArrowUp: { x: 0, y: -tileHeight / 2 },
|
|
205
|
+
ArrowDown: { x: 0, y: tileHeight / 2 },
|
|
206
|
+
}
|
|
207
|
+
const direction = directions[event.key]
|
|
208
|
+
if (!direction) return
|
|
209
|
+
event.preventDefault()
|
|
210
|
+
setCamera((current) => ({
|
|
211
|
+
x: current.x + direction.x,
|
|
212
|
+
y: current.y + direction.y,
|
|
213
|
+
}))
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<section
|
|
218
|
+
aria-label="Infinite image canvas"
|
|
219
|
+
className={cn(
|
|
220
|
+
'border-border relative isolate h-[34rem] w-full overflow-hidden rounded-2xl border bg-zinc-950 sm:h-[42rem]',
|
|
221
|
+
className,
|
|
222
|
+
)}
|
|
223
|
+
>
|
|
224
|
+
<div
|
|
225
|
+
ref={canvasRef}
|
|
226
|
+
role="region"
|
|
227
|
+
aria-label="Image canvas. Use the scroll wheel, drag, or arrow keys to explore. Scroll outside the canvas to move the page."
|
|
228
|
+
tabIndex={0}
|
|
229
|
+
onPointerDown={handlePointerDown}
|
|
230
|
+
onPointerMove={handlePointerMove}
|
|
231
|
+
onPointerUp={stopDragging}
|
|
232
|
+
onPointerCancel={stopDragging}
|
|
233
|
+
onKeyDown={handleKeyDown}
|
|
234
|
+
className="absolute inset-0 cursor-grab touch-none overflow-hidden outline-none active:cursor-grabbing focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-white/70"
|
|
235
|
+
>
|
|
236
|
+
<div className="pointer-events-none absolute inset-0 z-10 bg-[radial-gradient(ellipse_at_center,rgba(0,0,0,0.42),transparent_62%),linear-gradient(90deg,rgba(0,0,0,0.45),transparent_75%),linear-gradient(0deg,rgba(0,0,0,0.16),transparent_55%)]" />
|
|
237
|
+
|
|
238
|
+
<AnimatePresence initial={false}>
|
|
239
|
+
{cells.map(({ row, column, image }) => (
|
|
240
|
+
<CanvasTile
|
|
241
|
+
key={row + ':' + column}
|
|
242
|
+
image={image}
|
|
243
|
+
left={column * tileWidth - camera.x}
|
|
244
|
+
top={row * tileHeight - camera.y}
|
|
245
|
+
width={tileWidth - 18}
|
|
246
|
+
height={tileHeight - 18}
|
|
247
|
+
reduceMotion={reduceMotion}
|
|
248
|
+
/>
|
|
249
|
+
))}
|
|
250
|
+
</AnimatePresence>
|
|
251
|
+
</div>
|
|
252
|
+
|
|
253
|
+
<div className="pointer-events-none absolute inset-0 z-20 flex flex-col items-center justify-center px-6 text-center text-white">
|
|
254
|
+
<h2 className="font-display mt-3 max-w-xl text-5xl leading-[0.95] font-semibold tracking-[-0.045em] sm:text-7xl">
|
|
255
|
+
{heading}
|
|
256
|
+
</h2>
|
|
257
|
+
<p className="mt-3 max-w-sm text-sm leading-6 text-white/70">
|
|
258
|
+
{description}
|
|
259
|
+
</p>
|
|
260
|
+
</div>
|
|
261
|
+
</section>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
@@ -21,6 +21,7 @@ export type MobileMenuDockItem = {
|
|
|
21
21
|
export type MobileMenuDockSearchItem = {
|
|
22
22
|
name: string
|
|
23
23
|
slug: string
|
|
24
|
+
href: string
|
|
24
25
|
category: string
|
|
25
26
|
description: string
|
|
26
27
|
}
|
|
@@ -104,7 +105,7 @@ export default function MobileMenuDock({
|
|
|
104
105
|
filteredComponents.map((item) => (
|
|
105
106
|
<li key={item.slug}>
|
|
106
107
|
<Link
|
|
107
|
-
href={
|
|
108
|
+
href={item.href}
|
|
108
109
|
onClick={() => {
|
|
109
110
|
setOpen(false)
|
|
110
111
|
setQuery('')
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { motion, useReducedMotion, useTransform } from 'motion/react'
|
|
4
|
+
import type { MotionValue } from 'motion/react'
|
|
5
|
+
import { cn } from '@/lib/utils'
|
|
6
|
+
|
|
7
|
+
export type TextRevealProps = {
|
|
8
|
+
text: string
|
|
9
|
+
className?: string
|
|
10
|
+
characterStagger?: number
|
|
11
|
+
lineStagger?: number
|
|
12
|
+
duration?: number
|
|
13
|
+
waveDistance?: number
|
|
14
|
+
waveOvershoot?: number
|
|
15
|
+
sidewaysDistance?: number
|
|
16
|
+
blurAmount?: number
|
|
17
|
+
opacityFrom?: number
|
|
18
|
+
opacityPeak?: number
|
|
19
|
+
scaleFrom?: number
|
|
20
|
+
scalePeak?: number
|
|
21
|
+
scrollProgress?: MotionValue<number>
|
|
22
|
+
once?: boolean
|
|
23
|
+
viewportAmount?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function ScrollRevealCharacter({
|
|
27
|
+
character,
|
|
28
|
+
progress,
|
|
29
|
+
start,
|
|
30
|
+
end,
|
|
31
|
+
waveDistance,
|
|
32
|
+
waveOvershoot,
|
|
33
|
+
sidewaysDistance,
|
|
34
|
+
blurAmount,
|
|
35
|
+
opacityFrom,
|
|
36
|
+
opacityPeak,
|
|
37
|
+
scaleFrom,
|
|
38
|
+
scalePeak,
|
|
39
|
+
}: {
|
|
40
|
+
character: string
|
|
41
|
+
progress: MotionValue<number>
|
|
42
|
+
start: number
|
|
43
|
+
end: number
|
|
44
|
+
waveDistance: number
|
|
45
|
+
waveOvershoot: number
|
|
46
|
+
sidewaysDistance: number
|
|
47
|
+
blurAmount: number
|
|
48
|
+
opacityFrom: number
|
|
49
|
+
opacityPeak: number
|
|
50
|
+
scaleFrom: number
|
|
51
|
+
scalePeak: number
|
|
52
|
+
}) {
|
|
53
|
+
const characterProgress = useTransform(progress, [start, end], [0, 1])
|
|
54
|
+
const opacity = useTransform(
|
|
55
|
+
characterProgress,
|
|
56
|
+
[0, 0.55, 1],
|
|
57
|
+
[opacityFrom, opacityPeak, 1],
|
|
58
|
+
)
|
|
59
|
+
const y = useTransform(
|
|
60
|
+
characterProgress,
|
|
61
|
+
[0, 0.55, 1],
|
|
62
|
+
[waveDistance, -waveOvershoot, 0],
|
|
63
|
+
)
|
|
64
|
+
const x = useTransform(
|
|
65
|
+
characterProgress,
|
|
66
|
+
[0, 0.55, 1],
|
|
67
|
+
[-sidewaysDistance, sidewaysDistance * 0.5, 0],
|
|
68
|
+
)
|
|
69
|
+
const scale = useTransform(
|
|
70
|
+
characterProgress,
|
|
71
|
+
[0, 0.55, 1],
|
|
72
|
+
[scaleFrom, scalePeak, 1],
|
|
73
|
+
)
|
|
74
|
+
const filter = useTransform(
|
|
75
|
+
characterProgress,
|
|
76
|
+
[0, 0.55, 1],
|
|
77
|
+
[`blur(${blurAmount}px)`, `blur(${blurAmount * 0.35}px)`, 'blur(0px)'],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<motion.span
|
|
82
|
+
style={{ opacity, x, y, scale, filter }}
|
|
83
|
+
className="inline-block whitespace-pre"
|
|
84
|
+
>
|
|
85
|
+
{character}
|
|
86
|
+
</motion.span>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function TextReveal({
|
|
91
|
+
text,
|
|
92
|
+
className,
|
|
93
|
+
characterStagger = 0.024,
|
|
94
|
+
lineStagger = 0.24,
|
|
95
|
+
duration = 0.7,
|
|
96
|
+
waveDistance = 5,
|
|
97
|
+
waveOvershoot = waveDistance * 0.75,
|
|
98
|
+
sidewaysDistance = waveDistance * 0.12,
|
|
99
|
+
blurAmount = 7,
|
|
100
|
+
opacityFrom = 0.08,
|
|
101
|
+
opacityPeak = 0.72,
|
|
102
|
+
scaleFrom = 0.96,
|
|
103
|
+
scalePeak = 1.025,
|
|
104
|
+
scrollProgress,
|
|
105
|
+
once = true,
|
|
106
|
+
viewportAmount = 0.4,
|
|
107
|
+
}: TextRevealProps) {
|
|
108
|
+
const shouldReduceMotion = useReducedMotion()
|
|
109
|
+
const lines = text.split('\n')
|
|
110
|
+
const stagger = Math.max(0, characterStagger)
|
|
111
|
+
const lineDelay = Math.max(0, lineStagger)
|
|
112
|
+
const animationDuration = Math.max(0, duration)
|
|
113
|
+
const wave = Math.max(0, waveDistance)
|
|
114
|
+
const wavePeak = Math.max(0, waveOvershoot)
|
|
115
|
+
const sideways = Math.max(0, sidewaysDistance)
|
|
116
|
+
const blur = Math.max(0, blurAmount)
|
|
117
|
+
const startOpacity = Math.min(1, Math.max(0, opacityFrom))
|
|
118
|
+
const middleOpacity = Math.min(1, Math.max(startOpacity, opacityPeak))
|
|
119
|
+
const startScale = Math.max(0.01, scaleFrom)
|
|
120
|
+
const middleScale = Math.max(0.01, scalePeak)
|
|
121
|
+
const lineStartDelays: number[] = []
|
|
122
|
+
let nextLineDelay = 0
|
|
123
|
+
|
|
124
|
+
for (const line of lines) {
|
|
125
|
+
lineStartDelays.push(nextLineDelay)
|
|
126
|
+
nextLineDelay +=
|
|
127
|
+
Math.max(0, Array.from(line).length - 1) * stagger +
|
|
128
|
+
animationDuration +
|
|
129
|
+
lineDelay
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const characterCount = lines.reduce(
|
|
133
|
+
(total, line) => total + Array.from(line).length,
|
|
134
|
+
0,
|
|
135
|
+
)
|
|
136
|
+
const scrollCharacterWeight = Math.max(stagger, 0.001)
|
|
137
|
+
const scrollLineWeight = Math.max(0, lineDelay)
|
|
138
|
+
const totalScrollWeight =
|
|
139
|
+
characterCount * scrollCharacterWeight +
|
|
140
|
+
Math.max(0, lines.length - 1) * scrollLineWeight
|
|
141
|
+
let scrollWeight = 0
|
|
142
|
+
|
|
143
|
+
if (scrollProgress && !shouldReduceMotion) {
|
|
144
|
+
return (
|
|
145
|
+
<p className={cn('text-foreground', className)}>
|
|
146
|
+
<span className="sr-only">{text.replace(/\n/g, ' ')}</span>
|
|
147
|
+
{lines.map((line, lineIndex) => {
|
|
148
|
+
const words = line.match(/\s+|\S+/gu) ?? []
|
|
149
|
+
const content = words.map((word, wordIndex) => {
|
|
150
|
+
if (/^\s+$/u.test(word)) {
|
|
151
|
+
scrollWeight += Array.from(word).length * scrollCharacterWeight
|
|
152
|
+
return (
|
|
153
|
+
<span
|
|
154
|
+
key={`${wordIndex}-${word}`}
|
|
155
|
+
className="whitespace-pre-wrap"
|
|
156
|
+
>
|
|
157
|
+
{word}
|
|
158
|
+
</span>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const characters = Array.from(word).map((character) => {
|
|
163
|
+
const start = scrollWeight / totalScrollWeight
|
|
164
|
+
scrollWeight += scrollCharacterWeight
|
|
165
|
+
const end = scrollWeight / totalScrollWeight
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<ScrollRevealCharacter
|
|
169
|
+
key={`${start}-${character}`}
|
|
170
|
+
character={character}
|
|
171
|
+
progress={scrollProgress}
|
|
172
|
+
start={start}
|
|
173
|
+
end={end}
|
|
174
|
+
waveDistance={wave}
|
|
175
|
+
waveOvershoot={wavePeak}
|
|
176
|
+
sidewaysDistance={sideways}
|
|
177
|
+
blurAmount={blur}
|
|
178
|
+
opacityFrom={startOpacity}
|
|
179
|
+
opacityPeak={middleOpacity}
|
|
180
|
+
scaleFrom={startScale}
|
|
181
|
+
scalePeak={middleScale}
|
|
182
|
+
/>
|
|
183
|
+
)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<span
|
|
188
|
+
key={`${wordIndex}-${word}`}
|
|
189
|
+
className="inline-block whitespace-nowrap"
|
|
190
|
+
>
|
|
191
|
+
{characters}
|
|
192
|
+
</span>
|
|
193
|
+
)
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
if (lineIndex < lines.length - 1) {
|
|
197
|
+
scrollWeight += scrollLineWeight
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<span
|
|
202
|
+
key={`${lineIndex}-${line}`}
|
|
203
|
+
aria-hidden="true"
|
|
204
|
+
className="block"
|
|
205
|
+
>
|
|
206
|
+
{content}
|
|
207
|
+
</span>
|
|
208
|
+
)
|
|
209
|
+
})}
|
|
210
|
+
</p>
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<motion.p
|
|
216
|
+
initial={shouldReduceMotion ? false : 'hidden'}
|
|
217
|
+
whileInView="visible"
|
|
218
|
+
viewport={{ once, amount: Math.min(1, Math.max(0, viewportAmount)) }}
|
|
219
|
+
className={cn('text-foreground', className)}
|
|
220
|
+
>
|
|
221
|
+
<span className="sr-only">{text.replace(/\n/g, ' ')}</span>
|
|
222
|
+
{lines.map((line, lineIndex) => {
|
|
223
|
+
let characterIndex = 0
|
|
224
|
+
const words = line.match(/\s+|\S+/gu) ?? []
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<span
|
|
228
|
+
key={`${lineIndex}-${line}`}
|
|
229
|
+
aria-hidden="true"
|
|
230
|
+
className="block"
|
|
231
|
+
>
|
|
232
|
+
{words.map((word, wordIndex) => {
|
|
233
|
+
if (/^\s+$/u.test(word)) {
|
|
234
|
+
characterIndex += Array.from(word).length
|
|
235
|
+
return (
|
|
236
|
+
<span
|
|
237
|
+
key={`${wordIndex}-${word}`}
|
|
238
|
+
className="whitespace-pre-wrap"
|
|
239
|
+
>
|
|
240
|
+
{word}
|
|
241
|
+
</span>
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const characters = Array.from(word).map((character) => {
|
|
246
|
+
const delay =
|
|
247
|
+
lineStartDelays[lineIndex] + characterIndex * stagger
|
|
248
|
+
characterIndex += 1
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<motion.span
|
|
252
|
+
key={`${characterIndex}-${character}`}
|
|
253
|
+
custom={delay}
|
|
254
|
+
variants={{
|
|
255
|
+
hidden: {
|
|
256
|
+
opacity: startOpacity,
|
|
257
|
+
y: wave,
|
|
258
|
+
x: -sideways,
|
|
259
|
+
scale: startScale,
|
|
260
|
+
filter: `blur(${blur}px)`,
|
|
261
|
+
},
|
|
262
|
+
visible: shouldReduceMotion
|
|
263
|
+
? {
|
|
264
|
+
opacity: 1,
|
|
265
|
+
y: 0,
|
|
266
|
+
x: 0,
|
|
267
|
+
scale: 1,
|
|
268
|
+
filter: 'blur(0px)',
|
|
269
|
+
transition: { duration: 0 },
|
|
270
|
+
}
|
|
271
|
+
: (staggerDelay: number) => ({
|
|
272
|
+
opacity: 1,
|
|
273
|
+
y: [wave, -wavePeak, 0],
|
|
274
|
+
x: [-sideways, sideways * 0.5, 0],
|
|
275
|
+
scale: [startScale, middleScale, 1],
|
|
276
|
+
filter: ['blur(' + blur + 'px)', 'blur(0px)'],
|
|
277
|
+
transition: {
|
|
278
|
+
duration: animationDuration,
|
|
279
|
+
delay: staggerDelay,
|
|
280
|
+
ease: 'easeOut',
|
|
281
|
+
},
|
|
282
|
+
}),
|
|
283
|
+
}}
|
|
284
|
+
className="inline-block whitespace-pre"
|
|
285
|
+
>
|
|
286
|
+
{character}
|
|
287
|
+
</motion.span>
|
|
288
|
+
)
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<span
|
|
293
|
+
key={`${wordIndex}-${word}`}
|
|
294
|
+
className="inline-block whitespace-nowrap"
|
|
295
|
+
>
|
|
296
|
+
{characters}
|
|
297
|
+
</span>
|
|
298
|
+
)
|
|
299
|
+
})}
|
|
300
|
+
</span>
|
|
301
|
+
)
|
|
302
|
+
})}
|
|
303
|
+
</motion.p>
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export default TextReveal
|