@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,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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case '
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|