@istmx/ui 0.1.11 → 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 -463
  3. package/bin/istmx.mjs +481 -314
  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 -0
  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,278 +1,269 @@
1
- 'use client'
2
-
3
- import { useEffect, useMemo, useRef, useState } from 'react'
4
- import type { ReactNode } from 'react'
5
- import { motion, useReducedMotion } from 'motion/react'
6
- import { cn } from '@/lib/utils'
7
-
8
- export type StreamingTextEffect = 'fade' | 'blur' | 'slide' | 'wave'
9
-
10
- export type StreamingTextProps = {
11
- /** The string to stream, as if the model is still writing it. */
12
- text: string
13
- /** Characters revealed per second. Defaults to 34. */
14
- speed?: number
15
- /** Delay in milliseconds before streaming starts. Defaults to 0. */
16
- startDelay?: number
17
- /** How each new character enters. Defaults to blur. */
18
- effect?: StreamingTextEffect
19
- /** Time in seconds for a single character to settle. Defaults to 0.34. */
20
- glyphDuration?: number
21
- /** Blur radius used by the blur effect. Defaults to 6. */
22
- blurAmount?: number
23
- /** Rise distance used by the slide, blur, and wave effects. Defaults to 6. */
24
- slideDistance?: number
25
- /** Show the blinking caret while streaming. Defaults to true. */
26
- cursor?: boolean
27
- /** Keep the caret blinking after the string finishes. Defaults to false. */
28
- cursorAfterComplete?: boolean
29
- /** Restart the stream after the string finishes. Defaults to false. */
30
- loop?: boolean
31
- /** Pause in milliseconds between loop cycles. Defaults to 1200. */
32
- loopDelay?: number
33
- /** Called once the full string has been revealed. */
34
- onComplete?: () => void
35
- className?: string
36
- textClassName?: string
37
- cursorClassName?: string
38
- }
39
-
40
- const WHITESPACE = /^\s$/u
41
-
42
- function splitGlyphs(value: string): string[] {
43
- if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {
44
- const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' })
45
- return Array.from(segmenter.segment(value), (part) => part.segment)
46
- }
47
-
48
- return Array.from(value)
49
- }
50
-
51
- type GlyphGroup = {
52
- start: number
53
- space: boolean
54
- glyphs: string[]
55
- }
56
-
57
- function groupGlyphs(glyphs: string[]): GlyphGroup[] {
58
- const groups: GlyphGroup[] = []
59
-
60
- glyphs.forEach((glyph, index) => {
61
- const space = WHITESPACE.test(glyph)
62
- const last = groups[groups.length - 1]
63
-
64
- if (last && last.space === space) {
65
- last.glyphs.push(glyph)
66
- return
67
- }
68
-
69
- groups.push({ start: index, space, glyphs: [glyph] })
70
- })
71
-
72
- return groups
73
- }
74
-
75
- function glyphStates(
76
- effect: StreamingTextEffect,
77
- blurAmount: number,
78
- slideDistance: number,
79
- ) {
80
- switch (effect) {
81
- case 'fade':
82
- return { initial: { opacity: 0 }, animate: { opacity: 1 } }
83
- case 'slide':
84
- return {
85
- initial: { opacity: 0, y: slideDistance },
86
- animate: { opacity: 1, y: 0 },
87
- }
88
- case 'wave':
89
- return {
90
- initial: { opacity: 0, y: slideDistance, scale: 0.94 },
91
- animate: { opacity: 1, y: 0, scale: 1 },
92
- }
93
- case 'blur':
94
- default:
95
- return {
96
- initial: {
97
- opacity: 0,
98
- y: slideDistance * 0.5,
99
- filter: `blur(${blurAmount}px)`,
100
- },
101
- animate: { opacity: 1, y: 0, filter: 'blur(0px)' },
102
- }
103
- }
104
- }
105
-
106
- export function StreamingText({
107
- text,
108
- speed = 34,
109
- startDelay = 0,
110
- effect = 'blur',
111
- glyphDuration = 0.34,
112
- blurAmount = 6,
113
- slideDistance = 6,
114
- cursor = true,
115
- cursorAfterComplete = false,
116
- loop = false,
117
- loopDelay = 1200,
118
- onComplete,
119
- className,
120
- textClassName,
121
- cursorClassName,
122
- }: StreamingTextProps) {
123
- const shouldReduceMotion = useReducedMotion()
124
- const glyphs = useMemo(() => splitGlyphs(text), [text])
125
- const [revealed, setRevealed] = useState(0)
126
- const [cycle, setCycle] = useState(0)
127
- const onCompleteRef = useRef(onComplete)
128
-
129
- useEffect(() => {
130
- onCompleteRef.current = onComplete
131
- })
132
-
133
- useEffect(() => {
134
- let frame = 0
135
- let timeout = 0
136
-
137
- const cancel = () => {
138
- window.cancelAnimationFrame(frame)
139
- window.clearTimeout(timeout)
140
- }
141
-
142
- if (shouldReduceMotion) {
143
- queueMicrotask(() => {
144
- setRevealed(glyphs.length)
145
- })
146
- return cancel
147
- }
148
-
149
- queueMicrotask(() => {
150
- setRevealed(0)
151
- })
152
-
153
- let startedAt: number | null = null
154
- const perGlyph = 1000 / Math.max(1, speed)
155
- const delay = Math.max(0, startDelay)
156
- const pause = Math.max(0, loopDelay)
157
-
158
- const step = (now: number) => {
159
- if (startedAt === null) startedAt = now
160
-
161
- const elapsed = now - startedAt - delay
162
-
163
- if (elapsed < 0) {
164
- frame = window.requestAnimationFrame(step)
165
- return
166
- }
167
-
168
- const count = Math.min(glyphs.length, Math.floor(elapsed / perGlyph) + 1)
169
- setRevealed(count)
170
-
171
- if (count < glyphs.length) {
172
- frame = window.requestAnimationFrame(step)
173
- return
174
- }
175
-
176
- onCompleteRef.current?.()
177
-
178
- if (loop) {
179
- timeout = window.setTimeout(() => {
180
- setCycle((value) => value + 1)
181
- }, pause)
182
- }
183
- }
184
-
185
- frame = window.requestAnimationFrame(step)
186
-
187
- return cancel
188
- }, [cycle, glyphs, loop, loopDelay, shouldReduceMotion, speed, startDelay])
189
-
190
- const visibleGlyphs = useMemo(
191
- () => glyphs.slice(0, Math.max(0, revealed)),
192
- [glyphs, revealed],
193
- )
194
- const groups = useMemo(() => groupGlyphs(visibleGlyphs), [visibleGlyphs])
195
- const streaming = revealed < glyphs.length
196
- const showCursor = cursor && (streaming || cursorAfterComplete)
197
- const states = glyphStates(effect, blurAmount, slideDistance)
198
-
199
- const content: ReactNode[] = groups.map((group) => {
200
- if (group.space) {
201
- return (
202
- <span key={`space-${group.start}`} className="whitespace-pre">
203
- {group.glyphs.join('')}
204
- </span>
205
- )
206
- }
207
-
208
- return (
209
- <span
210
- key={`word-${group.start}`}
211
- className="inline-block whitespace-nowrap"
212
- >
213
- {group.glyphs.map((glyph, offset) => {
214
- const index = group.start + offset
215
-
216
- return (
217
- <motion.span
218
- key={index}
219
- initial={shouldReduceMotion ? false : states.initial}
220
- animate={states.animate}
221
- transition={
222
- shouldReduceMotion
223
- ? { duration: 0 }
224
- : effect === 'wave'
225
- ? { type: 'spring', stiffness: 360, damping: 24, mass: 0.6 }
226
- : {
227
- duration: Math.max(0.05, glyphDuration),
228
- ease: 'easeOut',
229
- }
230
- }
231
- className="inline-block"
232
- >
233
- {glyph}
234
- </motion.span>
235
- )
236
- })}
237
- </span>
238
- )
239
- })
240
-
241
- return (
242
- <span
243
- role="status"
244
- aria-live="polite"
245
- aria-atomic="true"
246
- data-state={streaming ? 'streaming' : 'complete'}
247
- className={cn('relative inline', className)}
248
- >
249
- <span
250
- aria-hidden="true"
251
- className={cn('whitespace-pre-wrap', textClassName)}
252
- >
253
- {content}
254
- {showCursor ? (
255
- <motion.span
256
- aria-hidden="true"
257
- initial={{ opacity: 1 }}
258
- animate={
259
- shouldReduceMotion ? { opacity: 1 } : { opacity: [1, 0.15, 1] }
260
- }
261
- transition={
262
- shouldReduceMotion
263
- ? { duration: 0 }
264
- : { duration: 1, ease: 'easeInOut', repeat: Infinity }
265
- }
266
- className={cn(
267
- 'bg-foreground ml-0.5 inline-block h-[0.95em] w-[2px] translate-y-[0.1em] rounded-full align-middle',
268
- cursorClassName,
269
- )}
270
- />
271
- ) : null}
272
- </span>
273
- <span className="sr-only">{text}</span>
274
- </span>
275
- )
276
- }
277
-
278
- export default StreamingText
1
+ 'use client'
2
+
3
+ import { forwardRef, useEffect, useMemo, useRef, useState } from 'react'
4
+ import type { ReactNode } from 'react'
5
+ import { motion, useReducedMotion } from 'motion/react'
6
+ import { cn } from '@/lib/utils'
7
+
8
+ export type StreamingTextEffect = 'fade' | 'blur' | 'slide' | 'wave'
9
+
10
+ export type StreamingTextProps = {
11
+ text: string
12
+ speed?: number
13
+ startDelay?: number
14
+ effect?: StreamingTextEffect
15
+ glyphDuration?: number
16
+ blurAmount?: number
17
+ slideDistance?: number
18
+ cursor?: boolean
19
+ cursorAfterComplete?: boolean
20
+ loop?: boolean
21
+ loopDelay?: number
22
+ onComplete?: () => void
23
+ className?: string
24
+ textClassName?: string
25
+ cursorClassName?: string
26
+ }
27
+
28
+ const WHITESPACE = /^\s$/u
29
+
30
+ function splitGlyphs(value: string): string[] {
31
+ if (typeof Intl !== 'undefined' && 'Segmenter' in Intl) {
32
+ const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' })
33
+ return Array.from(segmenter.segment(value), (part) => part.segment)
34
+ }
35
+
36
+ return Array.from(value)
37
+ }
38
+
39
+ type GlyphGroup = {
40
+ start: number
41
+ space: boolean
42
+ glyphs: string[]
43
+ }
44
+
45
+ function groupGlyphs(glyphs: string[]): GlyphGroup[] {
46
+ const groups: GlyphGroup[] = []
47
+
48
+ glyphs.forEach((glyph, index) => {
49
+ const space = WHITESPACE.test(glyph)
50
+ const last = groups[groups.length - 1]
51
+
52
+ if (last && last.space === space) {
53
+ last.glyphs.push(glyph)
54
+ return
55
+ }
56
+
57
+ groups.push({ start: index, space, glyphs: [glyph] })
58
+ })
59
+
60
+ return groups
61
+ }
62
+
63
+ function glyphStates(
64
+ effect: StreamingTextEffect,
65
+ blurAmount: number,
66
+ slideDistance: number,
67
+ ) {
68
+ switch (effect) {
69
+ case 'fade':
70
+ return { initial: { opacity: 0 }, animate: { opacity: 1 } }
71
+ case 'slide':
72
+ return {
73
+ initial: { opacity: 0, y: slideDistance },
74
+ animate: { opacity: 1, y: 0 },
75
+ }
76
+ case 'wave':
77
+ return {
78
+ initial: { opacity: 0, y: slideDistance, scale: 0.94 },
79
+ animate: { opacity: 1, y: 0, scale: 1 },
80
+ }
81
+ case 'blur':
82
+ default:
83
+ return {
84
+ initial: {
85
+ opacity: 0,
86
+ y: slideDistance * 0.5,
87
+ filter: `blur(${blurAmount}px)`,
88
+ },
89
+ animate: { opacity: 1, y: 0, filter: 'blur(0px)' },
90
+ }
91
+ }
92
+ }
93
+
94
+ export const StreamingText = forwardRef<HTMLSpanElement, StreamingTextProps>(function StreamingText({
95
+ text,
96
+ speed = 34,
97
+ startDelay = 0,
98
+ effect = 'blur',
99
+ glyphDuration = 0.34,
100
+ blurAmount = 6,
101
+ slideDistance = 6,
102
+ cursor = true,
103
+ cursorAfterComplete = false,
104
+ loop = false,
105
+ loopDelay = 1200,
106
+ onComplete,
107
+ className,
108
+ textClassName,
109
+ cursorClassName,
110
+ }, ref) {
111
+ const shouldReduceMotion = useReducedMotion()
112
+ const glyphs = useMemo(() => splitGlyphs(text), [text])
113
+ const [revealed, setRevealed] = useState(0)
114
+ const [cycle, setCycle] = useState(0)
115
+ const onCompleteRef = useRef(onComplete)
116
+
117
+ useEffect(() => {
118
+ onCompleteRef.current = onComplete
119
+ })
120
+
121
+ useEffect(() => {
122
+ let frame = 0
123
+ let timeout = 0
124
+
125
+ const cancel = () => {
126
+ window.cancelAnimationFrame(frame)
127
+ window.clearTimeout(timeout)
128
+ }
129
+
130
+ if (shouldReduceMotion) {
131
+ queueMicrotask(() => {
132
+ setRevealed(glyphs.length)
133
+ })
134
+ return cancel
135
+ }
136
+
137
+ queueMicrotask(() => {
138
+ setRevealed(0)
139
+ })
140
+
141
+ let startedAt: number | null = null
142
+ const perGlyph = 1000 / Math.max(1, speed)
143
+ const delay = Math.max(0, startDelay)
144
+ const pause = Math.max(0, loopDelay)
145
+
146
+ const step = (now: number) => {
147
+ if (startedAt === null) startedAt = now
148
+
149
+ const elapsed = now - startedAt - delay
150
+
151
+ if (elapsed < 0) {
152
+ frame = window.requestAnimationFrame(step)
153
+ return
154
+ }
155
+
156
+ const count = Math.min(glyphs.length, Math.floor(elapsed / perGlyph) + 1)
157
+ setRevealed(count)
158
+
159
+ if (count < glyphs.length) {
160
+ frame = window.requestAnimationFrame(step)
161
+ return
162
+ }
163
+
164
+ onCompleteRef.current?.()
165
+
166
+ if (loop) {
167
+ timeout = window.setTimeout(() => {
168
+ setCycle((value) => value + 1)
169
+ }, pause)
170
+ }
171
+ }
172
+
173
+ frame = window.requestAnimationFrame(step)
174
+
175
+ return cancel
176
+ }, [cycle, glyphs, loop, loopDelay, shouldReduceMotion, speed, startDelay])
177
+
178
+ const visibleGlyphs = useMemo(
179
+ () => glyphs.slice(0, Math.max(0, revealed)),
180
+ [glyphs, revealed],
181
+ )
182
+ const groups = useMemo(() => groupGlyphs(visibleGlyphs), [visibleGlyphs])
183
+ const streaming = revealed < glyphs.length
184
+ const showCursor = cursor && (streaming || cursorAfterComplete)
185
+ const states = glyphStates(effect, blurAmount, slideDistance)
186
+
187
+ const content: ReactNode[] = groups.map((group) => {
188
+ if (group.space) {
189
+ return (
190
+ <span key={`space-${group.start}`} className="whitespace-pre">
191
+ {group.glyphs.join('')}
192
+ </span>
193
+ )
194
+ }
195
+
196
+ return (
197
+ <span
198
+ key={`word-${group.start}`}
199
+ className="inline-block whitespace-nowrap"
200
+ >
201
+ {group.glyphs.map((glyph, offset) => {
202
+ const index = group.start + offset
203
+
204
+ return (
205
+ <motion.span
206
+ key={index}
207
+ initial={shouldReduceMotion ? false : states.initial}
208
+ animate={states.animate}
209
+ transition={
210
+ shouldReduceMotion
211
+ ? { duration: 0 }
212
+ : effect === 'wave'
213
+ ? { type: 'spring', stiffness: 360, damping: 24, mass: 0.6 }
214
+ : {
215
+ duration: Math.max(0.05, glyphDuration),
216
+ ease: 'easeOut',
217
+ }
218
+ }
219
+ className="inline-block"
220
+ >
221
+ {glyph}
222
+ </motion.span>
223
+ )
224
+ })}
225
+ </span>
226
+ )
227
+ })
228
+
229
+ return (
230
+ <span
231
+ ref={ref}
232
+ role="status"
233
+ aria-live="polite"
234
+ aria-atomic="true"
235
+ data-state={streaming ? 'streaming' : 'complete'}
236
+ className={cn('relative inline', className)}
237
+ >
238
+ <span
239
+ aria-hidden="true"
240
+ className={cn('whitespace-pre-wrap', textClassName)}
241
+ >
242
+ {content}
243
+ {showCursor ? (
244
+ <motion.span
245
+ aria-hidden="true"
246
+ initial={{ opacity: 1 }}
247
+ animate={
248
+ shouldReduceMotion ? { opacity: 1 } : { opacity: [1, 0.15, 1] }
249
+ }
250
+ transition={
251
+ shouldReduceMotion
252
+ ? { duration: 0 }
253
+ : { duration: 1, ease: 'easeInOut', repeat: Infinity }
254
+ }
255
+ className={cn(
256
+ 'bg-foreground ml-0.5 inline-block h-[0.95em] w-[2px] translate-y-[0.1em] rounded-full align-middle',
257
+ cursorClassName,
258
+ )}
259
+ />
260
+ ) : null}
261
+ </span>
262
+ <span className="sr-only">{text}</span>
263
+ </span>
264
+ )
265
+ })
266
+
267
+ StreamingText.displayName = 'StreamingText'
268
+
269
+ export default StreamingText