@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.
Files changed (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +533 -469
  3. package/bin/istmx.mjs +481 -318
  4. package/package.json +27 -27
  5. package/registry/accordion.tsx +186 -0
  6. package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
  7. package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
  8. package/registry/ai-chat-block/attachment.tsx +466 -466
  9. package/registry/ai-chat-block/chat-code-block.tsx +50 -50
  10. package/registry/ai-chat-block/chat-composer.tsx +51 -51
  11. package/registry/ai-chat-block/chat-logo.tsx +18 -18
  12. package/registry/ai-chat-block/chat-message.tsx +161 -161
  13. package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
  14. package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
  15. package/registry/ai-chat-block/code-highlighter.tsx +342 -357
  16. package/registry/ai-chat-block/default-attachments.tsx +42 -42
  17. package/registry/ai-chat-block/index.ts +30 -30
  18. package/registry/ai-chat-block/message-content.tsx +287 -287
  19. package/registry/ai-chat-block/message-list.tsx +93 -93
  20. package/registry/ai-chat-block/send-button.tsx +102 -102
  21. package/registry/ai-chat-block/types.ts +70 -71
  22. package/registry/ai-chat-block/utils.ts +6 -6
  23. package/registry/ai-chat-block/voice-button.tsx +66 -66
  24. package/registry/alert-dialog.tsx +229 -0
  25. package/registry/alert.tsx +188 -0
  26. package/registry/animated-text.tsx +228 -225
  27. package/registry/aspect-ratio.tsx +32 -0
  28. package/registry/avatar-group.tsx +66 -0
  29. package/registry/avatar.tsx +121 -0
  30. package/registry/badge.tsx +52 -0
  31. package/registry/bento-grid.tsx +438 -433
  32. package/registry/button.tsx +156 -237
  33. package/registry/carousel.tsx +184 -0
  34. package/registry/dock-navigation.tsx +200 -198
  35. package/registry/drift-canvas.tsx +383 -0
  36. package/registry/drift-wall.tsx +361 -0
  37. package/registry/flex-carousel.tsx +1430 -0
  38. package/registry/guided-gallery.tsx +1506 -0
  39. package/registry/image-accordion.tsx +306 -302
  40. package/registry/image-trail.tsx +126 -121
  41. package/registry/infinite-image-canvas.tsx +268 -263
  42. package/registry/input-otp.tsx +332 -0
  43. package/registry/list-card.tsx +130 -0
  44. package/registry/mobile-menu-dock.tsx +216 -211
  45. package/registry/morph-slider.tsx +756 -0
  46. package/registry/pixel-cat.tsx +972 -1020
  47. package/registry/scroll-canvas-cards.tsx +643 -640
  48. package/registry/scroll-parallax-hero.tsx +566 -565
  49. package/registry/scroll-story-cards.tsx +443 -438
  50. package/registry/slider.tsx +163 -0
  51. package/registry/spotlight-grid.tsx +226 -0
  52. package/registry/streaming-text.tsx +269 -278
  53. package/registry/text-reveal.tsx +311 -307
  54. package/registry/user-avatar.tsx +99 -0
  55. package/registry/utils.ts +6 -6
@@ -0,0 +1,361 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { cn } from '@/lib/utils'
5
+
6
+ export interface DriftWallItem {
7
+ image: string
8
+ title?: string
9
+ href?: string
10
+ }
11
+
12
+ export interface DriftWallProps {
13
+ items?: DriftWallItem[]
14
+ columns?: number
15
+ tileWidth?: number
16
+ tileHeight?: number
17
+ gap?: number
18
+ radius?: number
19
+ tilt?: number
20
+ turn?: number
21
+ roll?: number
22
+ perspective?: number
23
+ depth?: number
24
+ speed?: number
25
+ direction?: 'up' | 'down'
26
+ variance?: number
27
+ parallax?: number
28
+ pauseOnHover?: boolean
29
+ lift?: number
30
+ fade?: number
31
+ dim?: number
32
+ grayscale?: boolean
33
+ overlayColor?: string
34
+ className?: string
35
+ style?: React.CSSProperties
36
+ }
37
+
38
+ const DEFAULT_ITEMS: DriftWallItem[] = Array.from({ length: 15 }, (_, i) => {
39
+ const ids = [1015, 1025, 1039, 1043, 1044, 1050, 1062, 1069, 1074, 1080, 1084, 106, 110, 133, 164]
40
+ return {
41
+ image: `https://picsum.photos/id/${ids[i % ids.length]}/600/400`,
42
+ title: `Tile ${i + 1}`,
43
+ }
44
+ })
45
+
46
+ const columnFactor = (index: number, variance: number) => {
47
+ const pseudo = ((index * 0.6180339887 + 0.35) % 1) * 2 - 1
48
+ return 1 + variance * pseudo
49
+ }
50
+
51
+ export function DriftWall({
52
+ items = DEFAULT_ITEMS,
53
+ columns = 5,
54
+ tileWidth = 200,
55
+ tileHeight = 132,
56
+ gap = 18,
57
+ radius = 14,
58
+ tilt = 16,
59
+ turn = -14,
60
+ roll = 0,
61
+ perspective = 1200,
62
+ depth = 120,
63
+ speed = 42,
64
+ direction = 'up',
65
+ variance = 0.45,
66
+ parallax = 0.6,
67
+ pauseOnHover = false,
68
+ lift = 64,
69
+ fade = 0.6,
70
+ dim = 0.55,
71
+ grayscale = false,
72
+ overlayColor = '#060010',
73
+ className = '',
74
+ style,
75
+ }: DriftWallProps) {
76
+ const containerRef = React.useRef<HTMLDivElement | null>(null)
77
+ const planeRef = React.useRef<HTMLDivElement | null>(null)
78
+ const trackRefs = React.useRef<(HTMLDivElement | null)[]>([])
79
+ const rafRef = React.useRef<number | null>(null)
80
+
81
+ const offsetsRef = React.useRef<number[]>([])
82
+ const velocitiesRef = React.useRef<number[]>([])
83
+ const hoveredColRef = React.useRef(-1)
84
+ const wallHoveredRef = React.useRef(false)
85
+ const pointerRef = React.useRef({ x: 0, y: 0 })
86
+ const pointerDampedRef = React.useRef({ x: 0, y: 0 })
87
+ const lastTsRef = React.useRef<number | null>(null)
88
+
89
+ const [containerHeight, setContainerHeight] = React.useState(600)
90
+ const [activeId, setActiveId] = React.useState<string | null>(null)
91
+ const activeIdRef = React.useRef<string | null>(null)
92
+ const [reduced, setReduced] = React.useState(false)
93
+
94
+ React.useEffect(() => {
95
+ const mq = window.matchMedia('(prefers-reduced-motion: reduce)')
96
+ setReduced(mq.matches)
97
+ const onChange = (e: MediaQueryListEvent) => setReduced(e.matches)
98
+ mq.addEventListener('change', onChange)
99
+ return () => mq.removeEventListener('change', onChange)
100
+ }, [])
101
+
102
+ const columnItems = React.useMemo(() => {
103
+ const cols: DriftWallItem[][] = Array.from({ length: columns }, () => [])
104
+ items.forEach((item, i) => cols[i % columns].push(item))
105
+ return cols.map((col) => (col.length ? col : items.slice(0, 1)))
106
+ }, [items, columns])
107
+
108
+ const columnMeta = React.useMemo(() => {
109
+ const unit = tileHeight + gap
110
+ return columnItems.map((col) => {
111
+ const copyHeight = Math.max(unit, col.length * unit)
112
+ const copies = Math.max(2, Math.ceil((containerHeight * 1.6) / copyHeight) + 1)
113
+ return { copyHeight, copies }
114
+ })
115
+ }, [columnItems, tileHeight, gap, containerHeight])
116
+
117
+ React.useLayoutEffect(() => {
118
+ if (!containerRef.current) return
119
+ const ro = new ResizeObserver(([entry]) => {
120
+ setContainerHeight(entry.contentRect.height || 600)
121
+ })
122
+ ro.observe(containerRef.current)
123
+ return () => ro.disconnect()
124
+ }, [])
125
+
126
+ const baseVelocities = React.useMemo(() => {
127
+ const dirSign = direction === 'up' ? 1 : -1
128
+ return columnItems.map((_, c) => {
129
+ const altSign = c % 2 === 0 ? 1 : -1
130
+ return speed * columnFactor(c, variance) * dirSign * altSign
131
+ })
132
+ }, [columnItems, speed, direction, variance])
133
+
134
+ React.useEffect(() => {
135
+ offsetsRef.current = columnMeta.map((meta, c) => meta.copyHeight * ((c * 0.37) % 1))
136
+ velocitiesRef.current = columnItems.map(() => 0)
137
+ }, [columnMeta, columnItems])
138
+
139
+ const applyPlaneTransform = React.useCallback(
140
+ (px: number, py: number) => {
141
+ const plane = planeRef.current
142
+ if (!plane) return
143
+ plane.style.transform =
144
+ `translate(-50%, -50%) scale(1.18) ` +
145
+ `rotateX(${tilt + py}deg) rotateY(${turn + px}deg) rotateZ(${roll}deg) ` +
146
+ `translateZ(${-depth}px)`
147
+ },
148
+ [tilt, turn, roll, depth],
149
+ )
150
+
151
+ React.useEffect(() => {
152
+ const animate = (ts: number) => {
153
+ if (lastTsRef.current === null) lastTsRef.current = ts
154
+ const dt = Math.min(0.05, Math.max(0, ts - lastTsRef.current) / 1000)
155
+ lastTsRef.current = ts
156
+
157
+ const maxTilt = parallax * 8
158
+ const targetX = pointerRef.current.x * maxTilt
159
+ const targetY = -pointerRef.current.y * maxTilt
160
+ const damp = 1 - Math.exp(-dt / 0.12)
161
+ pointerDampedRef.current.x += (targetX - pointerDampedRef.current.x) * damp
162
+ pointerDampedRef.current.y += (targetY - pointerDampedRef.current.y) * damp
163
+ applyPlaneTransform(pointerDampedRef.current.x, pointerDampedRef.current.y)
164
+
165
+ if (!reduced) {
166
+ for (let c = 0; c < trackRefs.current.length; c++) {
167
+ const meta = columnMeta[c]
168
+ if (!meta) continue
169
+ const paused = wallHoveredRef.current && pauseOnHover
170
+ const factor = paused || hoveredColRef.current === c ? 0 : 1
171
+ const target = baseVelocities[c] * factor
172
+
173
+ const ease = 1 - Math.exp(-dt / (target === 0 ? 0.16 : 0.28))
174
+ velocitiesRef.current[c] += (target - velocitiesRef.current[c]) * ease
175
+ let next = (offsetsRef.current[c] ?? 0) + velocitiesRef.current[c] * dt
176
+ next = ((next % meta.copyHeight) + meta.copyHeight) % meta.copyHeight
177
+ offsetsRef.current[c] = next
178
+
179
+ const el = trackRefs.current[c]
180
+ if (el) el.style.transform = `translate3d(0, ${-next}px, 0)`
181
+ }
182
+ } else {
183
+ for (let c = 0; c < trackRefs.current.length; c++) {
184
+ const el = trackRefs.current[c]
185
+ const meta = columnMeta[c]
186
+ if (el && meta) el.style.transform = `translate3d(0, ${-(offsetsRef.current[c] ?? 0)}px, 0)`
187
+ }
188
+ }
189
+
190
+ rafRef.current = requestAnimationFrame(animate)
191
+ }
192
+
193
+ rafRef.current = requestAnimationFrame(animate)
194
+ return () => {
195
+ if (rafRef.current) cancelAnimationFrame(rafRef.current)
196
+ rafRef.current = null
197
+ lastTsRef.current = null
198
+ }
199
+ }, [baseVelocities, columnMeta, pauseOnHover, parallax, reduced, applyPlaneTransform])
200
+
201
+ const activate = React.useCallback((id: string, index: number) => {
202
+ activeIdRef.current = id
203
+ hoveredColRef.current = index
204
+ setActiveId(id)
205
+ }, [])
206
+
207
+ const release = React.useCallback(() => {
208
+ activeIdRef.current = null
209
+ hoveredColRef.current = -1
210
+ setActiveId(null)
211
+ }, [])
212
+
213
+ const handlePointerMove = React.useCallback(
214
+ (e: React.PointerEvent) => {
215
+ const rect = containerRef.current?.getBoundingClientRect()
216
+ if (!rect) return
217
+ if (parallax > 0 && !reduced) {
218
+ pointerRef.current = {
219
+ x: (e.clientX - rect.left) / rect.width - 0.5,
220
+ y: (e.clientY - rect.top) / rect.height - 0.5,
221
+ }
222
+ }
223
+ const hit = document.elementFromPoint(e.clientX, e.clientY) as HTMLElement | null
224
+ const tile = hit && hit.closest ? (hit.closest('[data-tile-id]') as HTMLElement | null) : null
225
+ if (!tile) return
226
+ const id = tile.dataset.tileId
227
+ if (!id || id === activeIdRef.current) return
228
+ activeIdRef.current = id
229
+ hoveredColRef.current = Number(tile.dataset.col)
230
+ setActiveId(id)
231
+ },
232
+ [parallax, reduced],
233
+ )
234
+
235
+ const handlePointerLeaveWall = React.useCallback(() => {
236
+ wallHoveredRef.current = false
237
+ pointerRef.current = { x: 0, y: 0 }
238
+ release()
239
+ }, [release])
240
+
241
+ const edgePercentage = Math.max(0, (1 - fade) * 100)
242
+
243
+ const renderTile = (item: DriftWallItem, id: string, colIndex: number) => {
244
+ const isActive = activeId === id
245
+ const inner = (
246
+ <span
247
+ style={{
248
+ borderRadius: `${radius}px`,
249
+ opacity: isActive ? 1 : dim,
250
+ transform: isActive ? `translateZ(${lift}px)` : 'translateZ(0)',
251
+ boxShadow: isActive
252
+ ? '0 24px 48px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.2)'
253
+ : '0 4px 12px rgba(0, 0, 0, 0.15)',
254
+ }}
255
+ className="absolute inset-[9px] block overflow-hidden bg-neutral-900 pointer-events-none transition-all duration-[420ms] ease-[cubic-bezier(0.22,1,0.36,1)]"
256
+ >
257
+ <img
258
+ src={item.image}
259
+ alt={item.title ?? ''}
260
+ loading="lazy"
261
+ decoding="async"
262
+ draggable={false}
263
+ style={{
264
+ filter: grayscale ? (isActive ? 'grayscale(0)' : 'grayscale(1)') : 'none',
265
+ }}
266
+ className="w-full h-full object-cover block select-none pointer-events-none transition-[filter] duration-[420ms] ease-[cubic-bezier(0.22,1,0.36,1)]"
267
+ />
268
+ <span
269
+ style={{
270
+ backgroundColor: overlayColor,
271
+ opacity: isActive ? 0.1 : 0.42,
272
+ }}
273
+ className="absolute inset-0 pointer-events-none transition-opacity duration-[420ms] ease-[cubic-bezier(0.22,1,0.36,1)]"
274
+ aria-hidden="true"
275
+ />
276
+ </span>
277
+ )
278
+
279
+ const commonProps = {
280
+ className: 'relative block flex-none outline-none select-none [transform-style:preserve-3d]',
281
+ style: {
282
+ width: `${tileWidth + gap}px`,
283
+ height: `${tileHeight + gap}px`,
284
+ },
285
+ 'data-tile-id': id,
286
+ 'data-col': colIndex,
287
+ onFocus: () => activate(id, colIndex),
288
+ onBlur: release,
289
+ }
290
+
291
+ if (item.href) {
292
+ return (
293
+ <a key={id} href={item.href} target="_blank" rel="noreferrer noopener" {...commonProps}>
294
+ {inner}
295
+ </a>
296
+ )
297
+ }
298
+
299
+ return (
300
+ <div key={id} tabIndex={0} role="button" aria-label={item.title ?? 'tile'} {...commonProps}>
301
+ {inner}
302
+ </div>
303
+ )
304
+ }
305
+
306
+ return (
307
+ <div
308
+ ref={containerRef}
309
+ style={{
310
+ perspective: `${perspective}px`,
311
+ perspectiveOrigin: '50% 50%',
312
+ maskImage: `radial-gradient(ellipse 78% 82% at 50% 46%, #000 ${edgePercentage}%, transparent 100%), linear-gradient(to top, #000 ${edgePercentage}%, transparent 100%)`,
313
+ WebkitMaskImage: `radial-gradient(ellipse 78% 82% at 50% 46%, #000 ${edgePercentage}%, transparent 100%), linear-gradient(to top, #000 ${edgePercentage}%, transparent 100%)`,
314
+ maskComposite: 'intersect',
315
+ WebkitMaskComposite: 'source-in',
316
+ ...style,
317
+ }}
318
+ className={cn(
319
+ 'relative w-full h-full overflow-hidden select-none',
320
+ className,
321
+ )}
322
+ onPointerMove={handlePointerMove}
323
+ onPointerEnter={() => {
324
+ wallHoveredRef.current = true
325
+ }}
326
+ onPointerLeave={handlePointerLeaveWall}
327
+ role="group"
328
+ aria-label="Drifting wall of tiles"
329
+ >
330
+ <div
331
+ ref={planeRef}
332
+ className="absolute top-1/2 left-1/2 flex flex-row [transform-style:preserve-3d] cursor-pointer origin-center will-change-transform"
333
+ >
334
+ {columnItems.map((col, c) => {
335
+ const meta = columnMeta[c]
336
+ const copies = Array.from({ length: meta.copies })
337
+ return (
338
+ <div
339
+ key={`col-${c}`}
340
+ style={{ width: `${tileWidth + gap}px` }}
341
+ className="relative [transform-style:preserve-3d]"
342
+ >
343
+ <div
344
+ ref={(el) => {
345
+ trackRefs.current[c] = el
346
+ }}
347
+ className="flex flex-col will-change-transform [transform-style:preserve-3d]"
348
+ >
349
+ {copies.map((_, copyIndex) =>
350
+ col.map((item, itemIndex) =>
351
+ renderTile(item, `${c}-${copyIndex}-${itemIndex}`, c),
352
+ ),
353
+ )}
354
+ </div>
355
+ </div>
356
+ )
357
+ })}
358
+ </div>
359
+ </div>
360
+ )
361
+ }