@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
@@ -1,259 +1,178 @@
1
1
  'use client'
2
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'
3
+ import * as React from 'react'
4
+ import { AnimatePresence, motion, type HTMLMotionProps } from 'motion/react'
7
5
  import { cn } from '@/lib/utils'
8
6
 
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> = {
7
+ const buttonVariants = {
41
8
  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
- }
9
+ 'text-white border-[color:color-mix(in_oklab,var(--brand)_78%,black)] ' +
10
+ 'bg-[linear-gradient(to_bottom,color-mix(in_oklab,var(--brand)_86%,white),var(--brand))] ' +
11
+ 'shadow-[inset_0_0_0_1.5px_var(--effect-white-24),inset_0_3px_0_var(--effect-white-10)] ' +
12
+ 'hover:brightness-105',
64
13
 
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
- }
14
+ secondary:
15
+ 'text-foreground light:text-neutral-950 dark:text-neutral-50 border-[var(--button-border)] ' +
16
+ 'bg-[linear-gradient(to_bottom,var(--button-surface-top),var(--button-surface-bottom))] ' +
17
+ 'shadow-[inset_0_0_0_1px_var(--effect-white-full)] ' +
18
+ 'hover:bg-surface hover:border-[var(--button-border-hover)]',
71
19
 
72
- const MOTION_TRANSITION = {
73
- type: 'spring' as const,
74
- stiffness: 420,
75
- damping: 26,
76
- mass: 0.55,
77
- }
20
+ outline:
21
+ 'bg-transparent text-[color:var(--brand)] border-[color:var(--brand)] ' +
22
+ 'shadow-[inset_0_-2px_0_color-mix(in_srgb,var(--brand)_25%,transparent)] ' +
23
+ 'hover:bg-[color-mix(in_srgb,var(--brand)_10%,transparent)]',
78
24
 
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
- )
25
+ ghost:
26
+ 'bg-transparent text-[color:var(--brand)] border-transparent ' +
27
+ 'hover:bg-[color-mix(in_srgb,var(--brand)_12%,transparent)]',
28
+
29
+ destructive:
30
+ 'text-white border-[color:color-mix(in_oklab,var(--status-error)_78%,black)] ' +
31
+ 'bg-[linear-gradient(to_bottom,color-mix(in_oklab,var(--status-error)_86%,white),var(--status-error))] ' +
32
+ 'shadow-[inset_0_0_0_1.5px_var(--effect-white-24),inset_0_3px_0_var(--effect-white-10)] ' +
33
+ 'hover:brightness-105',
34
+
35
+ link:
36
+ 'bg-transparent text-[color:var(--brand)] border-transparent underline-offset-4 ' +
37
+ 'hover:underline',
38
+ } as const
39
+
40
+ const buttonSizes = {
41
+ sm: 'h-9 px-4 text-sm rounded-xl border-2',
42
+ md: 'h-12 px-6 text-lg rounded-2xl border-[3px]',
43
+ lg: 'h-[72px] px-10 text-3xl rounded-[24px] border-[3px]',
44
+ icon: 'h-10 w-10 rounded-xl border-2',
45
+ } as const
46
+
47
+ type ButtonVariant = keyof typeof buttonVariants
48
+ type ButtonSize = keyof typeof buttonSizes
49
+
50
+ type ButtonProps = Omit<HTMLMotionProps<'button'>, 'children'> & {
51
+ children?: React.ReactNode
52
+ color?: string
53
+ variant?: ButtonVariant
54
+ size?: ButtonSize
55
+ width?: number | string | 'full'
56
+ loading?: boolean
57
+ loadingText?: React.ReactNode
58
+ feedback?: 'success' | 'error' | null
59
+ feedbackText?: React.ReactNode
60
+ loadingIcon?: React.ReactNode
61
+ successIcon?: React.ReactNode
62
+ errorIcon?: React.ReactNode
63
+ asChild?: boolean
93
64
  }
94
65
 
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',
66
+ const DefaultSpinner = () => (
67
+ <svg aria-hidden="true" viewBox="0 0 24 24" className="h-4 w-4 animate-spin motion-reduce:animate-none">
68
+ <circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" strokeOpacity="0.25" strokeWidth="3" />
69
+ <path d="M21 12a9 9 0 0 0-9-9" fill="none" stroke="currentColor" strokeLinecap="round" strokeWidth="3" />
70
+ </svg>
71
+ )
72
+
73
+ const DefaultCheckIcon = () => (
74
+ <svg aria-hidden="true" viewBox="0 0 24 24" className="h-4 w-4" fill="none">
75
+ <path d="m5 12 4.5 4.5L19 7" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2.5" />
76
+ </svg>
77
+ )
78
+
79
+ const DefaultXIcon = () => (
80
+ <svg aria-hidden="true" viewBox="0 0 24 24" className="h-4 w-4" fill="none">
81
+ <path d="m7 7 10 10M17 7 7 17" stroke="currentColor" strokeLinecap="round" strokeWidth="2.5" />
82
+ </svg>
83
+ )
84
+
85
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
86
+ (
87
+ {
137
88
  className,
89
+ style,
138
90
  children,
139
- icon,
140
- feedback,
141
- intent = 'save',
91
+ color,
92
+ variant = 'primary',
93
+ size = 'md',
94
+ width,
95
+ loading = false,
96
+ loadingText,
97
+ feedback = null,
98
+ feedbackText,
99
+ loadingIcon,
100
+ successIcon,
101
+ errorIcon,
102
+ type = 'button',
142
103
  disabled,
143
- onClick,
144
- ...anchorProps
145
- } = props
104
+ ...props
105
+ },
106
+ ref,
107
+ ) => {
108
+ const resolvedWidth = width === 'full' ? '100%' : width
109
+ const isDisabled = disabled || loading
110
+ const status = loading ? 'loading' : feedback
111
+
112
+ const LoadingIcon = loadingIcon ?? <DefaultSpinner />
113
+ const SuccessIcon = successIcon ?? <DefaultCheckIcon />
114
+ const ErrorIcon = errorIcon ?? <DefaultXIcon />
146
115
 
147
116
  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}
117
+ <motion.button
118
+ ref={ref}
119
+ type={type}
120
+ disabled={isDisabled}
121
+ aria-busy={loading || undefined}
122
+ whileHover={isDisabled ? undefined : { y: -1 }}
123
+ whileTap={isDisabled ? undefined : { y: 2, scale: 0.985 }}
124
+ transition={{ type: 'spring', stiffness: 500, damping: 30 }}
125
+ style={
126
+ {
127
+ ...(color ? { '--brand': color } : {}),
128
+ ...(resolvedWidth ? { width: resolvedWidth } : {}),
129
+ ...style,
130
+ ...(feedback === 'error'
131
+ ? {
132
+ background: 'linear-gradient(to bottom, var(--status-error-soft), var(--status-error-soft-strong))',
133
+ borderColor: 'var(--status-error-deep)',
134
+ color: 'var(--status-error-strong)',
135
+ }
136
+ : {}),
137
+ } as React.CSSProperties
138
+ }
139
+ className={cn(
140
+ 'inline-flex select-none items-center justify-center whitespace-nowrap font-medium tracking-tight cursor-pointer',
141
+ 'outline-none transition-[background-color,border-color,filter] duration-150',
142
+ 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[color:var(--brand)]',
143
+ 'disabled:pointer-events-none disabled:opacity-50 motion-reduce:transition-none',
144
+ buttonVariants[variant],
145
+ buttonSizes[size],
146
+ className,
147
+ )}
148
+ {...props}
164
149
  >
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}>
150
+ <AnimatePresence mode="wait" initial={false}>
151
+ {status && (
171
152
  <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"
153
+ key={status}
154
+ role={feedback === 'error' ? 'alert' : 'status'}
155
+ aria-live="polite"
156
+ className="inline-flex items-center gap-2"
157
+ initial={{ opacity: 0, scale: 0.85, y: 3 }}
158
+ animate={{ opacity: 1, scale: 1, y: 0 }}
159
+ exit={{ opacity: 0, scale: 0.85, y: -3 }}
160
+ transition={{ duration: 0.16, ease: 'easeOut' }}
179
161
  >
180
- {feedbackActive ? feedback?.icon ?? '✓' : icon}
162
+ {loading ? LoadingIcon : feedback === 'success' ? SuccessIcon : ErrorIcon}
163
+ {loading
164
+ ? (loadingText ?? children)
165
+ : (feedbackText ?? children)}
181
166
  </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>
167
+ )}
168
+ </AnimatePresence>
169
+ {!status && children}
170
+ </motion.button>
197
171
  )
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
172
+ },
173
+ )
212
174
 
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
- }
175
+ Button.displayName = 'Button'
258
176
 
259
- export default Button
177
+ export { Button, buttonVariants, buttonSizes }
178
+ export type { ButtonProps, ButtonVariant, ButtonSize }
@@ -0,0 +1,184 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { motion, useReducedMotion, type PanInfo } from 'motion/react'
5
+ import { cn } from '@/lib/utils'
6
+
7
+ export interface CarouselItem {
8
+ id: string
9
+ image: string
10
+ alt: string
11
+ title: string
12
+ description?: string
13
+ }
14
+
15
+ export type CarouselVariant = 'arc' | 'horizontal' | 'stack' | 'fade'
16
+
17
+ export interface CarouselProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
18
+ items: CarouselItem[]
19
+ variant?: CarouselVariant
20
+ index?: number
21
+ defaultIndex?: number
22
+ onIndexChange?: (index: number, item: CarouselItem) => void
23
+ visibleCount?: number
24
+ cardWidth?: number
25
+ cardGap?: number
26
+ draggable?: boolean
27
+ loop?: boolean
28
+ showControls?: boolean
29
+ }
30
+
31
+ const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(
32
+ ({
33
+ className,
34
+ items,
35
+ variant = 'arc',
36
+ index,
37
+ defaultIndex = 0,
38
+ onIndexChange,
39
+ visibleCount = 3,
40
+ cardWidth = 320,
41
+ cardGap = 24,
42
+ draggable = true,
43
+ loop = true,
44
+ showControls = true,
45
+ onKeyDown,
46
+ ...props
47
+ }, ref) => {
48
+ const [uncontrolledIndex, setUncontrolledIndex] = React.useState(defaultIndex)
49
+ const [stageWidth, setStageWidth] = React.useState(0)
50
+ const stageRef = React.useRef<HTMLDivElement>(null)
51
+ const reduceMotion = useReducedMotion()
52
+ const activeIndex = items.length ? Math.min(items.length - 1, Math.max(0, index ?? uncontrolledIndex)) : 0
53
+ const safeVisibleCount = Math.max(1, Math.floor(visibleCount))
54
+ const sideCount = Math.floor(safeVisibleCount / 2)
55
+ const effectiveCardWidth = Math.min(cardWidth, stageWidth ? Math.max(180, (stageWidth - 32) / 3.15) : cardWidth)
56
+ const safeCardGap = Math.max(0, cardGap)
57
+ const cardHeight = Math.round(effectiveCardWidth * 1.34)
58
+
59
+ React.useEffect(() => {
60
+ const stage = stageRef.current
61
+ if (!stage) return
62
+ const observer = new ResizeObserver(([entry]) => setStageWidth(entry.contentRect.width))
63
+ observer.observe(stage)
64
+ return () => observer.disconnect()
65
+ }, [])
66
+
67
+ const goTo = React.useCallback((requestedIndex: number) => {
68
+ if (!items.length) return
69
+ const nextIndex = loop
70
+ ? (requestedIndex % items.length + items.length) % items.length
71
+ : Math.min(items.length - 1, Math.max(0, requestedIndex))
72
+ if (index === undefined) setUncontrolledIndex(nextIndex)
73
+ onIndexChange?.(nextIndex, items[nextIndex])
74
+ }, [index, items, loop, onIndexChange])
75
+
76
+ const getOffset = (itemIndex: number) => {
77
+ let offset = itemIndex - activeIndex
78
+ if (loop && items.length > 1) {
79
+ if (offset > items.length / 2) offset -= items.length
80
+ if (offset < -items.length / 2) offset += items.length
81
+ }
82
+ return offset
83
+ }
84
+
85
+ const handleDragEnd = (_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
86
+ if (Math.abs(info.offset.x) > Math.min(90, effectiveCardWidth * 0.3) || Math.abs(info.velocity.x) > 550) {
87
+ goTo(activeIndex + (info.offset.x < 0 ? 1 : -1))
88
+ }
89
+ }
90
+
91
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
92
+ onKeyDown?.(event)
93
+ if (event.defaultPrevented) return
94
+ if (event.key === 'ArrowRight') {
95
+ event.preventDefault()
96
+ goTo(activeIndex + 1)
97
+ } else if (event.key === 'ArrowLeft') {
98
+ event.preventDefault()
99
+ goTo(activeIndex - 1)
100
+ }
101
+ }
102
+
103
+ return (
104
+ <section
105
+ {...props}
106
+ ref={ref}
107
+ role="region"
108
+ aria-roledescription="carousel"
109
+ aria-label={props['aria-label'] ?? 'Image carousel'}
110
+ data-slot="carousel"
111
+ data-variant={variant}
112
+ onKeyDown={handleKeyDown}
113
+ tabIndex={props.tabIndex ?? 0}
114
+ className={cn('relative isolate w-full select-none outline-none focus-visible:ring-2 focus-visible:ring-foreground/70 focus-visible:ring-offset-4 focus-visible:ring-offset-background', className)}
115
+ >
116
+ <div ref={stageRef} style={{ height: cardHeight + (variant === 'arc' ? 220 : 70) }} className="relative mx-auto w-full max-w-6xl overflow-hidden">
117
+ {items.map((item, itemIndex) => {
118
+ const offset = getOffset(itemIndex)
119
+ const distance = Math.abs(offset)
120
+ const isVisible = variant === 'arc' ? distance <= 1 : distance <= sideCount
121
+ const linearX = offset * (effectiveCardWidth + safeCardGap)
122
+ const stackScale = Math.max(0.78, 1 - distance * 0.075)
123
+ const cardOuterHeight = cardHeight + (variant === 'arc' ? 64 : 0)
124
+
125
+ return (
126
+ <motion.article
127
+ key={item.id}
128
+ aria-hidden={!isVisible}
129
+ aria-label={`${item.title}, ${itemIndex + 1} of ${items.length}`}
130
+ drag={variant === 'stack' && draggable && isVisible ? 'x' : false}
131
+ dragConstraints={{ left: -effectiveCardWidth, right: effectiveCardWidth }}
132
+ dragElastic={0.18}
133
+ dragMomentum={false}
134
+ onDragEnd={handleDragEnd}
135
+ onClick={() => offset !== 0 && goTo(itemIndex)}
136
+ animate={variant === 'arc'
137
+ ? { x: offset * (effectiveCardWidth + safeCardGap), y: 65 + distance * 21, rotate: offset * 13, scale: 1 - distance * 0.06, opacity: isVisible ? 1 : 0, zIndex: items.length - distance }
138
+ : variant === 'horizontal'
139
+ ? { x: linearX, y: 0, rotate: 0, scale: 1, opacity: isVisible ? 1 : 0, zIndex: items.length - distance }
140
+ : variant === 'stack'
141
+ ? { x: offset * 18, y: distance * 13, rotate: offset * 3, scale: stackScale, opacity: isVisible ? 1 - distance * 0.12 : 0, zIndex: items.length - distance }
142
+ : { x: offset === 0 ? 0 : offset * 34, y: 0, rotate: 0, scale: offset === 0 ? 1 : 0.94, opacity: offset === 0 ? 1 : 0, zIndex: items.length - distance }}
143
+ transition={reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 190, damping: 24, mass: 0.85 }}
144
+ style={{ width: effectiveCardWidth, height: cardOuterHeight, left: '50%', top: '50%', marginLeft: -effectiveCardWidth / 2, marginTop: -cardOuterHeight / 2, pointerEvents: isVisible ? 'auto' : 'none', transformOrigin: '50% 88%' }}
145
+ className={cn('absolute cursor-grab active:cursor-grabbing', variant === 'arc' ? 'overflow-visible' : 'overflow-hidden rounded-[1.6rem] border border-foreground/15 bg-muted shadow-[0_24px_64px_-24px_rgb(0_0_0/0.8)]')}
146
+ >
147
+ {variant === 'arc' ? <>
148
+ <div role="img" aria-label={item.alt} className="absolute inset-x-0 top-0 overflow-hidden rounded-[1.25rem] border border-foreground/15 bg-muted shadow-[0_24px_64px_-24px_rgb(0_0_0/0.8)]" style={{ height: cardHeight, backgroundImage: `linear-gradient(to top, rgb(0 0 0 / 0.38), transparent 42%), url(${JSON.stringify(item.image)})`, backgroundSize: 'cover', backgroundPosition: 'center' }} />
149
+ <div className="absolute inset-x-0 bottom-0 flex h-14 flex-col items-center justify-center text-center text-foreground">
150
+ <h3 className="font-grotesk text-xl font-semibold tracking-tight sm:text-2xl">{item.title}</h3>
151
+ {item.description && <p className="max-w-full truncate text-[10px] text-muted-foreground sm:text-xs">{item.description}</p>}
152
+ </div>
153
+ </> : <>
154
+ <div role="img" aria-label={item.alt} className="absolute inset-0 bg-cover bg-center" style={{ backgroundImage: `linear-gradient(to top, rgb(0 0 0 / 0.78), transparent 58%), url(${JSON.stringify(item.image)})` }} />
155
+ <div className="pointer-events-none absolute inset-0 bg-[linear-gradient(145deg,transparent_30%,rgb(255_255_255/0.12))]" />
156
+ <div className="absolute inset-x-0 bottom-0 p-5 text-left text-white sm:p-6">
157
+ <p className="mb-2 text-[10px] font-medium uppercase tracking-[0.2em] text-white/70">{item.description ?? 'A scene from the dream'}</p>
158
+ <h3 className="font-grotesk text-2xl font-semibold tracking-tight sm:text-3xl">{item.title}</h3>
159
+ </div>
160
+ </>}
161
+ </motion.article>
162
+ )
163
+ })}
164
+ <div aria-hidden="true" className="pointer-events-none absolute inset-y-0 left-0 z-10 w-12 bg-gradient-to-r from-background/75 via-background/25 to-transparent sm:w-20" />
165
+ <div aria-hidden="true" className="pointer-events-none absolute inset-y-0 right-0 z-10 w-12 bg-gradient-to-l from-background/75 via-background/25 to-transparent sm:w-20" />
166
+ </div>
167
+
168
+ {items.length > 0 && (
169
+ <div className="relative z-20 mx-auto mt-3 flex max-w-4xl items-center justify-between gap-4 px-2">
170
+ <p className="min-w-0 truncate text-xs text-muted-foreground" aria-live="polite">{items[activeIndex]?.title} <span className="tabular-nums">· {activeIndex + 1} / {items.length}</span></p>
171
+ {showControls && <div className="flex shrink-0 items-center gap-2">
172
+ <button type="button" aria-label="Previous slide" onClick={() => goTo(activeIndex - 1)} className="grid size-10 cursor-pointer place-items-center rounded-full border border-border bg-surface text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground/70"><svg aria-hidden="true" viewBox="0 0 20 20" className="size-4" fill="none"><path d="m12.5 4.5-7 5.5 7 5.5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg></button>
173
+ <button type="button" aria-label="Next slide" onClick={() => goTo(activeIndex + 1)} className="grid size-10 cursor-pointer place-items-center rounded-full border border-border bg-surface text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground/70"><svg aria-hidden="true" viewBox="0 0 20 20" className="size-4" fill="none"><path d="m7.5 4.5 7 5.5-7 5.5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg></button>
174
+ </div>}
175
+ </div>
176
+ )}
177
+ </section>
178
+ )
179
+ },
180
+ )
181
+
182
+ Carousel.displayName = 'Carousel'
183
+
184
+ export { Carousel }