@istmx/ui 0.1.6 → 0.1.8
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 +29 -1
- package/bin/istmx.mjs +9 -1
- package/package.json +1 -1
- package/registry/button.tsx +262 -0
- package/registry/image-effects-card.tsx +197 -0
- package/registry/image-trail.tsx +121 -0
- package/registry/infinite-image-canvas.tsx +263 -0
- package/registry/mobile-menu-dock.tsx +211 -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,13 @@ 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
|
+
npx @istmx/ui add image-effects-card
|
|
21
|
+
```
|
|
22
|
+
|
|
16
23
|
Or use your preferred package manager:
|
|
17
24
|
|
|
18
25
|
```sh
|
|
@@ -27,12 +34,30 @@ Add the image stack component with:
|
|
|
27
34
|
npx @istmx/ui add image-accordion
|
|
28
35
|
```
|
|
29
36
|
|
|
37
|
+
Add the pointer-driven image trail with:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npx @istmx/ui add image-trail
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Add the pannable infinite image canvas with:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npx @istmx/ui add infinite-image-canvas
|
|
47
|
+
```
|
|
48
|
+
|
|
30
49
|
Add the magnifying dock navigation with:
|
|
31
50
|
|
|
32
51
|
```sh
|
|
33
52
|
npx @istmx/ui add dock-navigation
|
|
34
53
|
```
|
|
35
54
|
|
|
55
|
+
Add the searchable mobile menu dock with:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
npx @istmx/ui add mobile-menu-dock
|
|
59
|
+
```
|
|
60
|
+
|
|
36
61
|
Add the scroll-scrubbed image story with:
|
|
37
62
|
|
|
38
63
|
```sh
|
|
@@ -113,7 +138,10 @@ in your `components/ui/animated-text.tsx` file.
|
|
|
113
138
|
npx @istmx/ui add animated-text --no-install
|
|
114
139
|
npx @istmx/ui add animated-text --overwrite
|
|
115
140
|
npx @istmx/ui add image-accordion
|
|
141
|
+
npx @istmx/ui add image-trail
|
|
142
|
+
npx @istmx/ui add infinite-image-canvas
|
|
116
143
|
npx @istmx/ui add dock-navigation
|
|
144
|
+
npx @istmx/ui add mobile-menu-dock
|
|
117
145
|
```
|
|
118
146
|
|
|
119
147
|
- `--no-install` copies the source and prints the dependency command instead
|
package/bin/istmx.mjs
CHANGED
|
@@ -6,14 +6,22 @@ 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.8'
|
|
10
10
|
const COMPONENTS = {
|
|
11
|
+
button: { fileName: 'button.tsx' },
|
|
11
12
|
'animated-text': { fileName: 'animated-text.tsx' },
|
|
13
|
+
'infinite-image-canvas': { fileName: 'infinite-image-canvas.tsx' },
|
|
14
|
+
'image-trail': { fileName: 'image-trail.tsx' },
|
|
15
|
+
'image-effects-card': { fileName: 'image-effects-card.tsx' },
|
|
12
16
|
'image-accordion': { fileName: 'image-accordion.tsx' },
|
|
13
17
|
'dock-navigation': {
|
|
14
18
|
fileName: 'dock-navigation.tsx',
|
|
15
19
|
dependencies: ['@tabler/icons-react'],
|
|
16
20
|
},
|
|
21
|
+
'mobile-menu-dock': {
|
|
22
|
+
fileName: 'mobile-menu-dock.tsx',
|
|
23
|
+
dependencies: ['@tabler/icons-react'],
|
|
24
|
+
},
|
|
17
25
|
'scroll-story-cards': {
|
|
18
26
|
fileName: 'scroll-story-cards.tsx',
|
|
19
27
|
dependencies: ['@tabler/icons-react'],
|
package/package.json
CHANGED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react'
|
|
4
|
+
import type {
|
|
5
|
+
AnchorHTMLAttributes,
|
|
6
|
+
ButtonHTMLAttributes,
|
|
7
|
+
ReactNode,
|
|
8
|
+
} from 'react'
|
|
9
|
+
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
|
10
|
+
import { cn } from '@/lib/utils'
|
|
11
|
+
|
|
12
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'soft'
|
|
13
|
+
export type ButtonSize = 'sm' | 'md' | 'lg' | 'icon'
|
|
14
|
+
export type ButtonIntent = 'save' | 'share' | 'delete'
|
|
15
|
+
|
|
16
|
+
type SharedButtonProps = {
|
|
17
|
+
children?: ReactNode
|
|
18
|
+
className?: string
|
|
19
|
+
icon?: ReactNode
|
|
20
|
+
feedback?: {
|
|
21
|
+
label: string
|
|
22
|
+
icon?: ReactNode
|
|
23
|
+
duration?: number
|
|
24
|
+
}
|
|
25
|
+
intent?: ButtonIntent
|
|
26
|
+
variant?: ButtonVariant
|
|
27
|
+
size?: ButtonSize
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type NativeButtonProps = SharedButtonProps &
|
|
32
|
+
Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof SharedButtonProps> & {
|
|
33
|
+
href?: never
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ButtonAnchorProps = SharedButtonProps &
|
|
37
|
+
Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof SharedButtonProps | 'href'> & {
|
|
38
|
+
href: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ButtonProps = NativeButtonProps | ButtonAnchorProps
|
|
42
|
+
|
|
43
|
+
const VARIANT_CLASSES: Record<ButtonVariant, string> = {
|
|
44
|
+
primary:
|
|
45
|
+
'',
|
|
46
|
+
secondary:
|
|
47
|
+
'border border-border bg-surface text-foreground hover:border-foreground/25 hover:bg-surface/75',
|
|
48
|
+
outline:
|
|
49
|
+
'border border-border bg-transparent text-foreground hover:border-foreground/45 hover:bg-surface/70',
|
|
50
|
+
ghost:
|
|
51
|
+
'border border-transparent bg-transparent text-foreground hover:bg-surface/75',
|
|
52
|
+
soft:
|
|
53
|
+
'border border-transparent bg-surface text-foreground hover:border-border hover:bg-surface/80',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const INTENT_CLASSES: Record<ButtonIntent, string> = {
|
|
57
|
+
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',
|
|
58
|
+
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',
|
|
59
|
+
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',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const INTENT_FEEDBACK_CLASSES: Record<ButtonIntent, string> = {
|
|
63
|
+
save: 'border-emerald-100 ring-2 ring-emerald-200/70 drop-shadow-[0_0_10px_rgba(16,185,129,0.28)]',
|
|
64
|
+
share: 'border-sky-100 ring-2 ring-sky-200/70 drop-shadow-[0_0_10px_rgba(56,189,248,0.28)]',
|
|
65
|
+
delete: 'border-rose-100 ring-2 ring-rose-200/70 drop-shadow-[0_0_10px_rgba(244,63,94,0.28)]',
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const SIZE_CLASSES: Record<ButtonSize, string> = {
|
|
69
|
+
sm: 'min-h-8 gap-1.5 rounded-md px-3 text-xs',
|
|
70
|
+
md: 'min-h-10 gap-2 rounded-lg px-4 text-sm',
|
|
71
|
+
lg: 'min-h-12 gap-2.5 rounded-xl px-5 text-sm',
|
|
72
|
+
icon: 'size-10 rounded-lg p-0',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const MOTION_TRANSITION = {
|
|
76
|
+
type: 'spring' as const,
|
|
77
|
+
stiffness: 420,
|
|
78
|
+
damping: 26,
|
|
79
|
+
mass: 0.55,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function buttonClassName(
|
|
83
|
+
variant: ButtonVariant,
|
|
84
|
+
size: ButtonSize,
|
|
85
|
+
className?: string,
|
|
86
|
+
intent: ButtonIntent = 'save',
|
|
87
|
+
feedbackActive = false,
|
|
88
|
+
) {
|
|
89
|
+
return cn(
|
|
90
|
+
'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',
|
|
91
|
+
variant === 'primary' ? INTENT_CLASSES[intent] : VARIANT_CLASSES[variant],
|
|
92
|
+
SIZE_CLASSES[size],
|
|
93
|
+
feedbackActive && INTENT_FEEDBACK_CLASSES[intent],
|
|
94
|
+
className,
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function Button(props: NativeButtonProps): ReactNode
|
|
99
|
+
export function Button(props: ButtonAnchorProps): ReactNode
|
|
100
|
+
export function Button(props: ButtonProps) {
|
|
101
|
+
const reduceMotion = useReducedMotion()
|
|
102
|
+
const [feedbackActive, setFeedbackActive] = useState(false)
|
|
103
|
+
const feedbackTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
104
|
+
|
|
105
|
+
useEffect(
|
|
106
|
+
() => () => {
|
|
107
|
+
if (feedbackTimeout.current) clearTimeout(feedbackTimeout.current)
|
|
108
|
+
},
|
|
109
|
+
[],
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
function showFeedback(duration = 1800) {
|
|
113
|
+
setFeedbackActive(true)
|
|
114
|
+
if (feedbackTimeout.current) clearTimeout(feedbackTimeout.current)
|
|
115
|
+
feedbackTimeout.current = setTimeout(() => setFeedbackActive(false), duration)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function completeAction(result: unknown, duration?: number) {
|
|
119
|
+
if (result && typeof (result as PromiseLike<unknown>).then === 'function') {
|
|
120
|
+
void Promise.resolve(result).then(
|
|
121
|
+
() => showFeedback(duration),
|
|
122
|
+
() => undefined,
|
|
123
|
+
)
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
showFeedback(duration)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const motionProps = {
|
|
130
|
+
whileHover: reduceMotion ? undefined : { y: -2, scale: 1.025 },
|
|
131
|
+
whileTap: reduceMotion ? undefined : { y: 0, scale: 0.955, filter: 'brightness(0.9)' },
|
|
132
|
+
transition: MOTION_TRANSITION,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if ('href' in props && typeof props.href === 'string') {
|
|
136
|
+
const {
|
|
137
|
+
href,
|
|
138
|
+
variant = 'primary',
|
|
139
|
+
size = 'md',
|
|
140
|
+
className,
|
|
141
|
+
children,
|
|
142
|
+
icon,
|
|
143
|
+
feedback,
|
|
144
|
+
intent = 'save',
|
|
145
|
+
disabled,
|
|
146
|
+
onClick,
|
|
147
|
+
...anchorProps
|
|
148
|
+
} = props
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<motion.a
|
|
152
|
+
{...anchorProps}
|
|
153
|
+
href={href}
|
|
154
|
+
aria-disabled={disabled || undefined}
|
|
155
|
+
tabIndex={disabled ? -1 : anchorProps.tabIndex}
|
|
156
|
+
onClick={(event) => {
|
|
157
|
+
if (disabled) {
|
|
158
|
+
event.preventDefault()
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
const result = onClick?.(event)
|
|
162
|
+
if (feedback) completeAction(result, feedback.duration)
|
|
163
|
+
}}
|
|
164
|
+
data-state={feedbackActive ? 'success' : 'idle'}
|
|
165
|
+
className={buttonClassName(variant, size, className, intent, feedbackActive && !!feedback)}
|
|
166
|
+
{...motionProps}
|
|
167
|
+
>
|
|
168
|
+
<span
|
|
169
|
+
aria-live={feedback ? 'polite' : undefined}
|
|
170
|
+
className="relative inline-flex items-center justify-center gap-2"
|
|
171
|
+
>
|
|
172
|
+
{icon || feedback ? (
|
|
173
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
174
|
+
<motion.span
|
|
175
|
+
key={feedbackActive ? 'feedback-icon' : 'idle-icon'}
|
|
176
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.65, rotate: -12 }}
|
|
177
|
+
animate={{ opacity: 1, scale: 1, rotate: 0 }}
|
|
178
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.65, rotate: 12 }}
|
|
179
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
180
|
+
className="inline-flex"
|
|
181
|
+
aria-hidden="true"
|
|
182
|
+
>
|
|
183
|
+
{feedbackActive ? feedback?.icon ?? '✓' : icon}
|
|
184
|
+
</motion.span>
|
|
185
|
+
</AnimatePresence>
|
|
186
|
+
) : null}
|
|
187
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
188
|
+
<motion.span
|
|
189
|
+
key={feedbackActive ? 'feedback-label' : 'idle-label'}
|
|
190
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 5 }}
|
|
191
|
+
animate={{ opacity: 1, y: 0 }}
|
|
192
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -5 }}
|
|
193
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
194
|
+
>
|
|
195
|
+
{feedbackActive && feedback ? feedback.label : children}
|
|
196
|
+
</motion.span>
|
|
197
|
+
</AnimatePresence>
|
|
198
|
+
</span>
|
|
199
|
+
</motion.a>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const {
|
|
204
|
+
variant = 'primary',
|
|
205
|
+
size = 'md',
|
|
206
|
+
className,
|
|
207
|
+
children,
|
|
208
|
+
icon,
|
|
209
|
+
feedback,
|
|
210
|
+
intent = 'save',
|
|
211
|
+
disabled,
|
|
212
|
+
type = 'button',
|
|
213
|
+
...buttonProps
|
|
214
|
+
} = props
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<motion.button
|
|
218
|
+
{...buttonProps}
|
|
219
|
+
type={type}
|
|
220
|
+
disabled={disabled}
|
|
221
|
+
aria-live={feedback ? 'polite' : undefined}
|
|
222
|
+
data-state={feedbackActive ? 'success' : 'idle'}
|
|
223
|
+
onClick={(event) => {
|
|
224
|
+
const result = buttonProps.onClick?.(event)
|
|
225
|
+
if (!disabled && feedback) completeAction(result, feedback.duration)
|
|
226
|
+
}}
|
|
227
|
+
className={buttonClassName(variant, size, className, intent, feedbackActive && !!feedback)}
|
|
228
|
+
{...motionProps}
|
|
229
|
+
>
|
|
230
|
+
<span className="relative inline-flex items-center justify-center gap-2">
|
|
231
|
+
{icon || feedback ? (
|
|
232
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
233
|
+
<motion.span
|
|
234
|
+
key={feedbackActive ? 'feedback-icon' : 'idle-icon'}
|
|
235
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.65, rotate: -12 }}
|
|
236
|
+
animate={{ opacity: 1, scale: 1, rotate: 0 }}
|
|
237
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.65, rotate: 12 }}
|
|
238
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
239
|
+
className="inline-flex"
|
|
240
|
+
aria-hidden="true"
|
|
241
|
+
>
|
|
242
|
+
{feedbackActive ? feedback?.icon ?? '✓' : icon}
|
|
243
|
+
</motion.span>
|
|
244
|
+
</AnimatePresence>
|
|
245
|
+
) : null}
|
|
246
|
+
<AnimatePresence mode="wait" initial={false}>
|
|
247
|
+
<motion.span
|
|
248
|
+
key={feedbackActive ? 'feedback-label' : 'idle-label'}
|
|
249
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 5 }}
|
|
250
|
+
animate={{ opacity: 1, y: 0 }}
|
|
251
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -5 }}
|
|
252
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
253
|
+
>
|
|
254
|
+
{feedbackActive && feedback ? feedback.label : children}
|
|
255
|
+
</motion.span>
|
|
256
|
+
</AnimatePresence>
|
|
257
|
+
</span>
|
|
258
|
+
</motion.button>
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export default Button
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useId, useRef, useState } from 'react'
|
|
4
|
+
import type { CSSProperties, PointerEvent } from 'react'
|
|
5
|
+
import Image from 'next/image'
|
|
6
|
+
|
|
7
|
+
export type ImageEffect = 'pixelate' | 'rgb-split' | 'glitch' | 'ascii'
|
|
8
|
+
|
|
9
|
+
export type ImageEffectsCardProps = {
|
|
10
|
+
src: string
|
|
11
|
+
alt: string
|
|
12
|
+
effect: ImageEffect
|
|
13
|
+
title: string
|
|
14
|
+
detail?: string
|
|
15
|
+
className?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const LENS_MASK =
|
|
19
|
+
'radial-gradient(circle var(--lens-radius, 94px) at var(--pointer-x, 50%) var(--pointer-y, 50%), #000 0 52%, rgba(0,0,0,.92) 62%, rgba(0,0,0,.48) 78%, transparent 100%)'
|
|
20
|
+
const ASCII = ' .,:;irsXA253hMHGS#9B&@'
|
|
21
|
+
|
|
22
|
+
function drawEffectCanvas(
|
|
23
|
+
canvas: HTMLCanvasElement,
|
|
24
|
+
image: HTMLImageElement,
|
|
25
|
+
effect: 'pixelate' | 'ascii',
|
|
26
|
+
) {
|
|
27
|
+
const bounds = canvas.getBoundingClientRect()
|
|
28
|
+
const width = Math.max(1, Math.round(bounds.width))
|
|
29
|
+
const height = Math.max(1, Math.round(bounds.height))
|
|
30
|
+
const context = canvas.getContext('2d')
|
|
31
|
+
if (!context || !image.naturalWidth || !image.naturalHeight) return
|
|
32
|
+
canvas.width = width
|
|
33
|
+
canvas.height = height
|
|
34
|
+
|
|
35
|
+
const scale = Math.max(width / image.naturalWidth, height / image.naturalHeight)
|
|
36
|
+
const cropWidth = width / scale
|
|
37
|
+
const cropHeight = height / scale
|
|
38
|
+
const sx = (image.naturalWidth - cropWidth) / 2
|
|
39
|
+
const sy = (image.naturalHeight - cropHeight) / 2
|
|
40
|
+
|
|
41
|
+
if (effect === 'pixelate') {
|
|
42
|
+
const sample = document.createElement('canvas')
|
|
43
|
+
sample.width = Math.max(1, Math.ceil(width / 10))
|
|
44
|
+
sample.height = Math.max(1, Math.ceil(height / 10))
|
|
45
|
+
const small = sample.getContext('2d')
|
|
46
|
+
if (!small) return
|
|
47
|
+
small.drawImage(image, sx, sy, cropWidth, cropHeight, 0, 0, sample.width, sample.height)
|
|
48
|
+
context.imageSmoothingEnabled = false
|
|
49
|
+
context.drawImage(sample, 0, 0, width, height)
|
|
50
|
+
context.imageSmoothingEnabled = true
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const columns = Math.max(18, Math.round(width / 8))
|
|
55
|
+
const rows = Math.max(24, Math.round(height / 8))
|
|
56
|
+
const sample = document.createElement('canvas')
|
|
57
|
+
sample.width = columns
|
|
58
|
+
sample.height = rows
|
|
59
|
+
const small = sample.getContext('2d', { willReadFrequently: true })
|
|
60
|
+
if (!small) return
|
|
61
|
+
try {
|
|
62
|
+
small.drawImage(image, sx, sy, cropWidth, cropHeight, 0, 0, columns, rows)
|
|
63
|
+
const pixels = small.getImageData(0, 0, columns, rows).data
|
|
64
|
+
context.clearRect(0, 0, width, height)
|
|
65
|
+
context.font = `bold ${Math.max(6, width / columns)}px ui-monospace, monospace`
|
|
66
|
+
context.textAlign = 'center'
|
|
67
|
+
context.textBaseline = 'middle'
|
|
68
|
+
for (let y = 0; y < rows; y += 1) {
|
|
69
|
+
for (let x = 0; x < columns; x += 1) {
|
|
70
|
+
const offset = (y * columns + x) * 4
|
|
71
|
+
const red = pixels[offset]
|
|
72
|
+
const green = pixels[offset + 1]
|
|
73
|
+
const blue = pixels[offset + 2]
|
|
74
|
+
const lightness = (red * 0.3 + green * 0.59 + blue * 0.11) / 255
|
|
75
|
+
const character = ASCII[Math.min(ASCII.length - 1, Math.floor((1 - lightness) * (ASCII.length - 1)))]
|
|
76
|
+
context.fillStyle = `rgba(${Math.min(255, red + 48)}, ${Math.min(255, green + 48)}, ${Math.min(255, blue + 48)}, .98)`
|
|
77
|
+
context.fillText(character, (x + 0.5) * (width / columns), (y + 0.5) * (height / rows))
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
// Canvas text remains hidden if the remote image host blocks pixel access.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default function ImageEffectsCard({
|
|
86
|
+
src,
|
|
87
|
+
alt,
|
|
88
|
+
effect,
|
|
89
|
+
title,
|
|
90
|
+
detail,
|
|
91
|
+
className = '',
|
|
92
|
+
}: ImageEffectsCardProps) {
|
|
93
|
+
const canvasRef = useRef<HTMLCanvasElement>(null)
|
|
94
|
+
const [active, setActive] = useState(false)
|
|
95
|
+
const filterId = `glitch-${useId().replace(/:/g, '')}`
|
|
96
|
+
const localMaskStyle: CSSProperties = {
|
|
97
|
+
maskImage: LENS_MASK,
|
|
98
|
+
WebkitMaskImage: LENS_MASK,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if ((effect !== 'pixelate' && effect !== 'ascii') || !active) return
|
|
103
|
+
const canvas = canvasRef.current
|
|
104
|
+
if (!canvas) return
|
|
105
|
+
let cancelled = false
|
|
106
|
+
const image = new window.Image()
|
|
107
|
+
image.crossOrigin = 'anonymous'
|
|
108
|
+
image.src = src
|
|
109
|
+
const draw = () => {
|
|
110
|
+
if (!cancelled) drawEffectCanvas(canvas, image, effect)
|
|
111
|
+
}
|
|
112
|
+
image.decode().then(draw).catch(() => {})
|
|
113
|
+
const observer = new ResizeObserver(draw)
|
|
114
|
+
observer.observe(canvas)
|
|
115
|
+
return () => {
|
|
116
|
+
cancelled = true
|
|
117
|
+
observer.disconnect()
|
|
118
|
+
}
|
|
119
|
+
}, [active, effect, src])
|
|
120
|
+
|
|
121
|
+
function handlePointerEnter(event: PointerEvent<HTMLElement>) {
|
|
122
|
+
const radius = Math.round(76 + Math.random() * 52)
|
|
123
|
+
event.currentTarget.style.setProperty('--lens-radius', `${radius}px`)
|
|
124
|
+
setActive(true)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function handlePointerMove(event: PointerEvent<HTMLElement>) {
|
|
128
|
+
const bounds = event.currentTarget.getBoundingClientRect()
|
|
129
|
+
event.currentTarget.style.setProperty('--pointer-x', `${event.clientX - bounds.left}px`)
|
|
130
|
+
event.currentTarget.style.setProperty('--pointer-y', `${event.clientY - bounds.top}px`)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const layerTransition = `pointer-events-none absolute inset-0 transition-opacity duration-200 ease-out motion-reduce:transition-none ${active ? 'opacity-100' : 'opacity-0'}`
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<figure
|
|
137
|
+
onPointerEnter={handlePointerEnter}
|
|
138
|
+
onPointerMove={handlePointerMove}
|
|
139
|
+
onPointerLeave={() => setActive(false)}
|
|
140
|
+
className={`group relative isolate aspect-[4/5] overflow-hidden rounded-xl bg-neutral-950 ${className}`}
|
|
141
|
+
>
|
|
142
|
+
<Image
|
|
143
|
+
src={src}
|
|
144
|
+
alt={alt}
|
|
145
|
+
fill
|
|
146
|
+
unoptimized
|
|
147
|
+
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 25vw, 260px"
|
|
148
|
+
className="object-cover"
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
{(effect === 'pixelate' || effect === 'ascii') && (
|
|
152
|
+
<canvas
|
|
153
|
+
ref={canvasRef}
|
|
154
|
+
aria-hidden="true"
|
|
155
|
+
className={`${layerTransition} h-full w-full object-cover blur-[0.4px]`}
|
|
156
|
+
style={localMaskStyle}
|
|
157
|
+
/>
|
|
158
|
+
)}
|
|
159
|
+
|
|
160
|
+
{effect === 'rgb-split' && (
|
|
161
|
+
<div className={layerTransition} style={localMaskStyle} aria-hidden="true">
|
|
162
|
+
<div className="absolute inset-0 -translate-x-[3px] scale-[1.015] bg-cover bg-center mix-blend-screen blur-[0.6px]" style={{ backgroundImage: `url("${src}")`, filter: 'sepia(1) saturate(5) hue-rotate(292deg)' }} />
|
|
163
|
+
<div className="absolute inset-0 translate-x-[3px] scale-[1.015] bg-cover bg-center mix-blend-screen blur-[0.6px]" style={{ backgroundImage: `url("${src}")`, filter: 'sepia(1) saturate(5) hue-rotate(150deg)' }} />
|
|
164
|
+
</div>
|
|
165
|
+
)}
|
|
166
|
+
|
|
167
|
+
{effect === 'glitch' && (
|
|
168
|
+
<>
|
|
169
|
+
<svg className="absolute size-0" aria-hidden="true">
|
|
170
|
+
<filter id={filterId}>
|
|
171
|
+
<feTurbulence type="fractalNoise" baseFrequency="0.018 0.12" numOctaves="1" seed="3" result="noise" />
|
|
172
|
+
<feDisplacementMap in="SourceGraphic" in2="noise" scale="24" xChannelSelector="R" yChannelSelector="G" />
|
|
173
|
+
</filter>
|
|
174
|
+
</svg>
|
|
175
|
+
<div className={layerTransition} style={localMaskStyle} aria-hidden="true">
|
|
176
|
+
<div className="absolute inset-0 scale-[1.025] bg-cover bg-center blur-[0.55px]" style={{ backgroundImage: `url("${src}")`, filter: `url(#${filterId}) saturate(1.45) hue-rotate(8deg)` }} />
|
|
177
|
+
</div>
|
|
178
|
+
</>
|
|
179
|
+
)}
|
|
180
|
+
|
|
181
|
+
<div
|
|
182
|
+
aria-hidden="true"
|
|
183
|
+
className={`pointer-events-none absolute inset-0 transition-opacity duration-200 motion-reduce:transition-none ${active ? 'opacity-100' : 'opacity-0'}`}
|
|
184
|
+
style={{
|
|
185
|
+
...localMaskStyle,
|
|
186
|
+
background: 'radial-gradient(circle var(--lens-radius, 94px) at var(--pointer-x, 50%) var(--pointer-y, 50%), transparent 62%, rgba(255,255,255,.22) 76%, rgba(255,255,255,.05) 88%, transparent 100%)',
|
|
187
|
+
filter: 'blur(5px)',
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
|
|
191
|
+
<figcaption className="absolute inset-x-0 bottom-0 z-10 bg-gradient-to-t from-black/80 via-black/35 to-transparent px-3 pt-12 pb-3 text-white">
|
|
192
|
+
<p className="text-[10px] font-semibold tracking-[0.14em] uppercase">{title}</p>
|
|
193
|
+
{detail ? <p className="mt-1 text-[10px] text-white/70">{detail}</p> : null}
|
|
194
|
+
</figcaption>
|
|
195
|
+
</figure>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import Link from 'next/link'
|
|
4
|
+
import { useEffect, useState } from 'react'
|
|
5
|
+
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
|
6
|
+
import {
|
|
7
|
+
IconArrowRight,
|
|
8
|
+
IconArrowUpRight,
|
|
9
|
+
IconGridDots,
|
|
10
|
+
IconSearch,
|
|
11
|
+
IconX,
|
|
12
|
+
} from '@tabler/icons-react'
|
|
13
|
+
import { cn } from '@/lib/utils'
|
|
14
|
+
|
|
15
|
+
export type MobileMenuDockItem = {
|
|
16
|
+
label: string
|
|
17
|
+
href: string
|
|
18
|
+
active?: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type MobileMenuDockSearchItem = {
|
|
22
|
+
name: string
|
|
23
|
+
slug: string
|
|
24
|
+
href: string
|
|
25
|
+
category: string
|
|
26
|
+
description: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type MobileMenuDockProps = {
|
|
30
|
+
items: MobileMenuDockItem[]
|
|
31
|
+
searchItems: readonly MobileMenuDockSearchItem[]
|
|
32
|
+
label?: string
|
|
33
|
+
placement?: 'fixed' | 'inline'
|
|
34
|
+
className?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default function MobileMenuDock({
|
|
38
|
+
items,
|
|
39
|
+
searchItems,
|
|
40
|
+
label = 'Mobile navigation',
|
|
41
|
+
placement = 'fixed',
|
|
42
|
+
className,
|
|
43
|
+
}: MobileMenuDockProps) {
|
|
44
|
+
const [open, setOpen] = useState(false)
|
|
45
|
+
const [query, setQuery] = useState('')
|
|
46
|
+
const reduceMotion = useReducedMotion()
|
|
47
|
+
const filteredComponents = searchItems.filter((item) =>
|
|
48
|
+
`${item.name} ${item.category} ${item.description}`
|
|
49
|
+
.toLowerCase()
|
|
50
|
+
.includes(query.trim().toLowerCase()),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!open) return
|
|
55
|
+
|
|
56
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
57
|
+
if (event.key === 'Escape') {
|
|
58
|
+
setOpen(false)
|
|
59
|
+
setQuery('')
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
window.addEventListener('keydown', onKeyDown)
|
|
64
|
+
return () => window.removeEventListener('keydown', onKeyDown)
|
|
65
|
+
}, [open])
|
|
66
|
+
|
|
67
|
+
function toggleMenu() {
|
|
68
|
+
setOpen((current) => !current)
|
|
69
|
+
setQuery('')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div
|
|
74
|
+
className={cn(
|
|
75
|
+
placement === 'fixed'
|
|
76
|
+
? 'fixed inset-x-0 bottom-[calc(env(safe-area-inset-bottom)+0.75rem)] z-50 mx-auto w-[min(21rem,calc(100vw-2rem))] sm:hidden'
|
|
77
|
+
: 'relative z-10 mx-auto w-full',
|
|
78
|
+
className,
|
|
79
|
+
)}
|
|
80
|
+
>
|
|
81
|
+
<AnimatePresence initial={false}>
|
|
82
|
+
{open ? (
|
|
83
|
+
<motion.nav
|
|
84
|
+
id="mobile-menu-dock-panel"
|
|
85
|
+
aria-label={label}
|
|
86
|
+
className="border-border/80 bg-background/95 mb-2 overflow-hidden rounded-xl border p-1.5 shadow-[0_12px_40px_rgba(0,0,0,0.2)] backdrop-blur-xl"
|
|
87
|
+
initial={
|
|
88
|
+
reduceMotion ? { opacity: 0 } : { opacity: 0, y: 8, scale: 0.985 }
|
|
89
|
+
}
|
|
90
|
+
animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
91
|
+
exit={
|
|
92
|
+
reduceMotion ? { opacity: 0 } : { opacity: 0, y: 5, scale: 0.99 }
|
|
93
|
+
}
|
|
94
|
+
transition={{
|
|
95
|
+
duration: reduceMotion ? 0.12 : 0.2,
|
|
96
|
+
ease: 'easeOut',
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
<div className="border-border/60 text-muted border-b px-3.5 py-2 font-mono text-[9px] tracking-[0.12em] uppercase">
|
|
100
|
+
{query.trim() ? 'Components' : 'Navigate'}
|
|
101
|
+
</div>
|
|
102
|
+
<ul className="max-h-[min(55vh,24rem)] overflow-y-auto">
|
|
103
|
+
{query.trim() ? (
|
|
104
|
+
filteredComponents.length ? (
|
|
105
|
+
filteredComponents.map((item) => (
|
|
106
|
+
<li key={item.slug}>
|
|
107
|
+
<Link
|
|
108
|
+
href={item.href}
|
|
109
|
+
onClick={() => {
|
|
110
|
+
setOpen(false)
|
|
111
|
+
setQuery('')
|
|
112
|
+
}}
|
|
113
|
+
className="text-muted hover:bg-surface/70 hover:text-foreground flex min-h-12 items-center gap-3 rounded-lg px-3.5 transition-colors"
|
|
114
|
+
>
|
|
115
|
+
<span className="min-w-0 flex-1">
|
|
116
|
+
<span className="flex items-center justify-between gap-3">
|
|
117
|
+
<span className="font-display text-foreground text-sm font-medium">
|
|
118
|
+
{item.name}
|
|
119
|
+
</span>
|
|
120
|
+
<span className="font-mono text-[9px] tracking-wide uppercase">
|
|
121
|
+
{item.category}
|
|
122
|
+
</span>
|
|
123
|
+
</span>
|
|
124
|
+
<span className="mt-0.5 block truncate text-xs">
|
|
125
|
+
{item.description}
|
|
126
|
+
</span>
|
|
127
|
+
</span>
|
|
128
|
+
<IconArrowRight
|
|
129
|
+
aria-hidden="true"
|
|
130
|
+
className="shrink-0"
|
|
131
|
+
size={15}
|
|
132
|
+
stroke={1.6}
|
|
133
|
+
/>
|
|
134
|
+
</Link>
|
|
135
|
+
</li>
|
|
136
|
+
))
|
|
137
|
+
) : (
|
|
138
|
+
<li className="text-muted px-3.5 py-4 text-center text-sm">
|
|
139
|
+
No components match “{query}”.
|
|
140
|
+
</li>
|
|
141
|
+
)
|
|
142
|
+
) : (
|
|
143
|
+
items.map((item) => (
|
|
144
|
+
<li key={item.href}>
|
|
145
|
+
<Link
|
|
146
|
+
href={item.href}
|
|
147
|
+
aria-current={item.active ? 'page' : undefined}
|
|
148
|
+
onClick={() => {
|
|
149
|
+
setOpen(false)
|
|
150
|
+
setQuery('')
|
|
151
|
+
}}
|
|
152
|
+
className={cn(
|
|
153
|
+
'flex min-h-11 items-center justify-between rounded-lg px-3.5 text-sm transition-colors',
|
|
154
|
+
item.active
|
|
155
|
+
? 'bg-surface text-foreground'
|
|
156
|
+
: 'text-muted hover:bg-surface/70 hover:text-foreground',
|
|
157
|
+
)}
|
|
158
|
+
>
|
|
159
|
+
{item.label}
|
|
160
|
+
<IconArrowUpRight
|
|
161
|
+
aria-hidden="true"
|
|
162
|
+
className="text-muted/60"
|
|
163
|
+
size={15}
|
|
164
|
+
stroke={1.6}
|
|
165
|
+
/>
|
|
166
|
+
</Link>
|
|
167
|
+
</li>
|
|
168
|
+
))
|
|
169
|
+
)}
|
|
170
|
+
</ul>
|
|
171
|
+
</motion.nav>
|
|
172
|
+
) : null}
|
|
173
|
+
</AnimatePresence>
|
|
174
|
+
|
|
175
|
+
<div className="border-border/80 bg-background/95 flex h-12 items-center gap-2 rounded-xl border px-2.5 shadow-[0_8px_28px_rgba(0,0,0,0.16)] backdrop-blur-xl">
|
|
176
|
+
<IconSearch
|
|
177
|
+
aria-hidden="true"
|
|
178
|
+
className="text-muted shrink-0"
|
|
179
|
+
size={17}
|
|
180
|
+
stroke={1.7}
|
|
181
|
+
/>
|
|
182
|
+
<input
|
|
183
|
+
value={query}
|
|
184
|
+
onChange={(event) => {
|
|
185
|
+
setQuery(event.target.value)
|
|
186
|
+
setOpen(true)
|
|
187
|
+
}}
|
|
188
|
+
onFocus={() => setOpen(true)}
|
|
189
|
+
placeholder="Search components..."
|
|
190
|
+
aria-label="Search components by name, category, or description"
|
|
191
|
+
aria-controls="mobile-menu-dock-panel"
|
|
192
|
+
className="text-foreground placeholder:text-muted/70 min-w-0 flex-1 bg-transparent text-sm outline-none"
|
|
193
|
+
/>
|
|
194
|
+
<button
|
|
195
|
+
type="button"
|
|
196
|
+
onClick={toggleMenu}
|
|
197
|
+
aria-label={open ? 'Close navigation menu' : 'Open navigation menu'}
|
|
198
|
+
aria-expanded={open}
|
|
199
|
+
aria-controls="mobile-menu-dock-panel"
|
|
200
|
+
className="border-border/70 bg-surface/45 text-muted hover:border-foreground/40 hover:text-foreground focus-visible:outline-foreground inline-flex size-8 shrink-0 items-center justify-center rounded-lg border transition-colors focus-visible:outline-2 focus-visible:outline-offset-2"
|
|
201
|
+
>
|
|
202
|
+
{open ? (
|
|
203
|
+
<IconX aria-hidden="true" size={16} stroke={1.8} />
|
|
204
|
+
) : (
|
|
205
|
+
<IconGridDots aria-hidden="true" size={16} stroke={1.8} />
|
|
206
|
+
)}
|
|
207
|
+
</button>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
)
|
|
211
|
+
}
|