@istmx/ui 0.1.12 → 0.1.13
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/LICENSE +21 -21
- package/README.md +533 -469
- package/bin/istmx.mjs +481 -318
- package/package.json +27 -27
- package/registry/accordion.tsx +186 -0
- package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
- package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
- package/registry/ai-chat-block/attachment.tsx +466 -466
- package/registry/ai-chat-block/chat-code-block.tsx +50 -50
- package/registry/ai-chat-block/chat-composer.tsx +51 -51
- package/registry/ai-chat-block/chat-logo.tsx +18 -18
- package/registry/ai-chat-block/chat-message.tsx +161 -161
- package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
- package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
- package/registry/ai-chat-block/code-highlighter.tsx +342 -357
- package/registry/ai-chat-block/default-attachments.tsx +42 -42
- package/registry/ai-chat-block/index.ts +30 -30
- package/registry/ai-chat-block/message-content.tsx +287 -287
- package/registry/ai-chat-block/message-list.tsx +93 -93
- package/registry/ai-chat-block/send-button.tsx +102 -102
- package/registry/ai-chat-block/types.ts +70 -71
- package/registry/ai-chat-block/utils.ts +6 -6
- package/registry/ai-chat-block/voice-button.tsx +66 -66
- package/registry/alert-dialog.tsx +229 -0
- package/registry/alert.tsx +188 -0
- package/registry/animated-text.tsx +228 -225
- package/registry/aspect-ratio.tsx +32 -0
- package/registry/avatar-group.tsx +66 -0
- package/registry/avatar.tsx +121 -0
- package/registry/badge.tsx +52 -0
- package/registry/bento-grid.tsx +438 -433
- package/registry/button.tsx +156 -237
- package/registry/carousel.tsx +184 -0
- package/registry/dock-navigation.tsx +200 -198
- package/registry/drift-canvas.tsx +383 -0
- package/registry/drift-wall.tsx +361 -0
- package/registry/flex-carousel.tsx +1430 -0
- package/registry/guided-gallery.tsx +1506 -0
- package/registry/image-accordion.tsx +306 -302
- package/registry/image-trail.tsx +126 -121
- package/registry/infinite-image-canvas.tsx +268 -263
- package/registry/input-otp.tsx +332 -0
- package/registry/list-card.tsx +130 -0
- package/registry/mobile-menu-dock.tsx +216 -211
- package/registry/morph-slider.tsx +756 -0
- package/registry/pixel-cat.tsx +972 -1020
- package/registry/scroll-canvas-cards.tsx +643 -640
- package/registry/scroll-parallax-hero.tsx +566 -565
- package/registry/scroll-story-cards.tsx +443 -438
- package/registry/slider.tsx +163 -0
- package/registry/spotlight-grid.tsx +226 -0
- package/registry/streaming-text.tsx +269 -278
- package/registry/text-reveal.tsx +311 -307
- package/registry/user-avatar.tsx +99 -0
- package/registry/utils.ts +6 -6
|
@@ -1,263 +1,268 @@
|
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { forwardRef, 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
|
+
const InfiniteImageCanvas = forwardRef<HTMLElement, InfiniteImageCanvasProps>(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
|
+
}, ref) {
|
|
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
|
+
ref={ref}
|
|
219
|
+
aria-label="Infinite image canvas"
|
|
220
|
+
className={cn(
|
|
221
|
+
'border-border relative isolate h-[34rem] w-full overflow-hidden rounded-2xl border bg-zinc-950 sm:h-[42rem]',
|
|
222
|
+
className,
|
|
223
|
+
)}
|
|
224
|
+
>
|
|
225
|
+
<div
|
|
226
|
+
ref={canvasRef}
|
|
227
|
+
role="region"
|
|
228
|
+
aria-label="Image canvas. Use the scroll wheel, drag, or arrow keys to explore. Scroll outside the canvas to move the page."
|
|
229
|
+
tabIndex={0}
|
|
230
|
+
onPointerDown={handlePointerDown}
|
|
231
|
+
onPointerMove={handlePointerMove}
|
|
232
|
+
onPointerUp={stopDragging}
|
|
233
|
+
onPointerCancel={stopDragging}
|
|
234
|
+
onKeyDown={handleKeyDown}
|
|
235
|
+
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"
|
|
236
|
+
>
|
|
237
|
+
<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%)]" />
|
|
238
|
+
|
|
239
|
+
<AnimatePresence initial={false}>
|
|
240
|
+
{cells.map(({ row, column, image }) => (
|
|
241
|
+
<CanvasTile
|
|
242
|
+
key={row + ':' + column}
|
|
243
|
+
image={image}
|
|
244
|
+
left={column * tileWidth - camera.x}
|
|
245
|
+
top={row * tileHeight - camera.y}
|
|
246
|
+
width={tileWidth - 18}
|
|
247
|
+
height={tileHeight - 18}
|
|
248
|
+
reduceMotion={reduceMotion}
|
|
249
|
+
/>
|
|
250
|
+
))}
|
|
251
|
+
</AnimatePresence>
|
|
252
|
+
</div>
|
|
253
|
+
|
|
254
|
+
<div className="pointer-events-none absolute inset-0 z-20 flex flex-col items-center justify-center px-6 text-center text-white">
|
|
255
|
+
<h2 className="font-display mt-3 max-w-xl text-5xl leading-[0.95] font-semibold tracking-[-0.045em] sm:text-7xl">
|
|
256
|
+
{heading}
|
|
257
|
+
</h2>
|
|
258
|
+
<p className="mt-3 max-w-sm text-sm leading-6 text-white/70">
|
|
259
|
+
{description}
|
|
260
|
+
</p>
|
|
261
|
+
</div>
|
|
262
|
+
</section>
|
|
263
|
+
)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
InfiniteImageCanvas.displayName = 'InfiniteImageCanvas'
|
|
267
|
+
|
|
268
|
+
export default InfiniteImageCanvas
|