@istmx/ui 0.1.8 → 0.1.10

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 (32) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +115 -1
  3. package/bin/istmx.mjs +53 -12
  4. package/package.json +2 -2
  5. package/registry/ai-chat-block/ai-chat-block.tsx +460 -0
  6. package/registry/ai-chat-block/ai-chat-input.tsx +690 -0
  7. package/registry/ai-chat-block/attachment.tsx +605 -0
  8. package/registry/ai-chat-block/chat-code-block.tsx +50 -0
  9. package/registry/ai-chat-block/chat-composer.tsx +51 -0
  10. package/registry/ai-chat-block/chat-logo.tsx +18 -0
  11. package/registry/ai-chat-block/chat-message.tsx +161 -0
  12. package/registry/ai-chat-block/chat-sidebar.tsx +273 -0
  13. package/registry/ai-chat-block/chat-user-avatar.tsx +9 -0
  14. package/registry/ai-chat-block/code-highlighter.tsx +357 -0
  15. package/registry/ai-chat-block/default-attachments.tsx +42 -0
  16. package/registry/ai-chat-block/index.ts +16 -0
  17. package/registry/ai-chat-block/message-content.tsx +287 -0
  18. package/registry/ai-chat-block/message-list.tsx +93 -0
  19. package/registry/ai-chat-block/send-button.tsx +102 -0
  20. package/registry/ai-chat-block/types.ts +71 -0
  21. package/registry/ai-chat-block/utils.ts +6 -0
  22. package/registry/ai-chat-block/voice-button.tsx +66 -0
  23. package/registry/ai-chat-input/ai-chat-input.tsx +690 -0
  24. package/registry/ai-chat-input/attachment.tsx +605 -0
  25. package/registry/ai-chat-input/send-button.tsx +102 -0
  26. package/registry/ai-chat-input/types.ts +71 -0
  27. package/registry/ai-chat-input/utils.ts +6 -0
  28. package/registry/ai-chat-input/voice-button.tsx +66 -0
  29. package/registry/button.tsx +4 -7
  30. package/registry/streaming-text.tsx +278 -0
  31. package/registry/text-reveal.tsx +307 -0
  32. package/registry/image-effects-card.tsx +0 -197
@@ -0,0 +1,307 @@
1
+ 'use client'
2
+
3
+ import { motion, useReducedMotion, useTransform } from 'motion/react'
4
+ import type { MotionValue } from 'motion/react'
5
+ import { cn } from '@/lib/utils'
6
+
7
+ export type TextRevealProps = {
8
+ text: string
9
+ className?: string
10
+ characterStagger?: number
11
+ lineStagger?: number
12
+ duration?: number
13
+ waveDistance?: number
14
+ waveOvershoot?: number
15
+ sidewaysDistance?: number
16
+ blurAmount?: number
17
+ opacityFrom?: number
18
+ opacityPeak?: number
19
+ scaleFrom?: number
20
+ scalePeak?: number
21
+ scrollProgress?: MotionValue<number>
22
+ once?: boolean
23
+ viewportAmount?: number
24
+ }
25
+
26
+ function ScrollRevealCharacter({
27
+ character,
28
+ progress,
29
+ start,
30
+ end,
31
+ waveDistance,
32
+ waveOvershoot,
33
+ sidewaysDistance,
34
+ blurAmount,
35
+ opacityFrom,
36
+ opacityPeak,
37
+ scaleFrom,
38
+ scalePeak,
39
+ }: {
40
+ character: string
41
+ progress: MotionValue<number>
42
+ start: number
43
+ end: number
44
+ waveDistance: number
45
+ waveOvershoot: number
46
+ sidewaysDistance: number
47
+ blurAmount: number
48
+ opacityFrom: number
49
+ opacityPeak: number
50
+ scaleFrom: number
51
+ scalePeak: number
52
+ }) {
53
+ const characterProgress = useTransform(progress, [start, end], [0, 1])
54
+ const opacity = useTransform(
55
+ characterProgress,
56
+ [0, 0.55, 1],
57
+ [opacityFrom, opacityPeak, 1],
58
+ )
59
+ const y = useTransform(
60
+ characterProgress,
61
+ [0, 0.55, 1],
62
+ [waveDistance, -waveOvershoot, 0],
63
+ )
64
+ const x = useTransform(
65
+ characterProgress,
66
+ [0, 0.55, 1],
67
+ [-sidewaysDistance, sidewaysDistance * 0.5, 0],
68
+ )
69
+ const scale = useTransform(
70
+ characterProgress,
71
+ [0, 0.55, 1],
72
+ [scaleFrom, scalePeak, 1],
73
+ )
74
+ const filter = useTransform(
75
+ characterProgress,
76
+ [0, 0.55, 1],
77
+ [`blur(${blurAmount}px)`, `blur(${blurAmount * 0.35}px)`, 'blur(0px)'],
78
+ )
79
+
80
+ return (
81
+ <motion.span
82
+ style={{ opacity, x, y, scale, filter }}
83
+ className="inline-block whitespace-pre"
84
+ >
85
+ {character}
86
+ </motion.span>
87
+ )
88
+ }
89
+
90
+ export function TextReveal({
91
+ text,
92
+ className,
93
+ characterStagger = 0.024,
94
+ lineStagger = 0.24,
95
+ duration = 0.7,
96
+ waveDistance = 5,
97
+ waveOvershoot = waveDistance * 0.75,
98
+ sidewaysDistance = waveDistance * 0.12,
99
+ blurAmount = 7,
100
+ opacityFrom = 0.08,
101
+ opacityPeak = 0.72,
102
+ scaleFrom = 0.96,
103
+ scalePeak = 1.025,
104
+ scrollProgress,
105
+ once = true,
106
+ viewportAmount = 0.4,
107
+ }: TextRevealProps) {
108
+ const shouldReduceMotion = useReducedMotion()
109
+ const lines = text.split('\n')
110
+ const stagger = Math.max(0, characterStagger)
111
+ const lineDelay = Math.max(0, lineStagger)
112
+ const animationDuration = Math.max(0, duration)
113
+ const wave = Math.max(0, waveDistance)
114
+ const wavePeak = Math.max(0, waveOvershoot)
115
+ const sideways = Math.max(0, sidewaysDistance)
116
+ const blur = Math.max(0, blurAmount)
117
+ const startOpacity = Math.min(1, Math.max(0, opacityFrom))
118
+ const middleOpacity = Math.min(1, Math.max(startOpacity, opacityPeak))
119
+ const startScale = Math.max(0.01, scaleFrom)
120
+ const middleScale = Math.max(0.01, scalePeak)
121
+ const lineStartDelays: number[] = []
122
+ let nextLineDelay = 0
123
+
124
+ for (const line of lines) {
125
+ lineStartDelays.push(nextLineDelay)
126
+ nextLineDelay +=
127
+ Math.max(0, Array.from(line).length - 1) * stagger +
128
+ animationDuration +
129
+ lineDelay
130
+ }
131
+
132
+ const characterCount = lines.reduce(
133
+ (total, line) => total + Array.from(line).length,
134
+ 0,
135
+ )
136
+ const scrollCharacterWeight = Math.max(stagger, 0.001)
137
+ const scrollLineWeight = Math.max(0, lineDelay)
138
+ const totalScrollWeight =
139
+ characterCount * scrollCharacterWeight +
140
+ Math.max(0, lines.length - 1) * scrollLineWeight
141
+ let scrollWeight = 0
142
+
143
+ if (scrollProgress && !shouldReduceMotion) {
144
+ return (
145
+ <p className={cn('text-foreground', className)}>
146
+ <span className="sr-only">{text.replace(/\n/g, ' ')}</span>
147
+ {lines.map((line, lineIndex) => {
148
+ const words = line.match(/\s+|\S+/gu) ?? []
149
+ const content = words.map((word, wordIndex) => {
150
+ if (/^\s+$/u.test(word)) {
151
+ scrollWeight += Array.from(word).length * scrollCharacterWeight
152
+ return (
153
+ <span
154
+ key={`${wordIndex}-${word}`}
155
+ className="whitespace-pre-wrap"
156
+ >
157
+ {word}
158
+ </span>
159
+ )
160
+ }
161
+
162
+ const characters = Array.from(word).map((character) => {
163
+ const start = scrollWeight / totalScrollWeight
164
+ scrollWeight += scrollCharacterWeight
165
+ const end = scrollWeight / totalScrollWeight
166
+
167
+ return (
168
+ <ScrollRevealCharacter
169
+ key={`${start}-${character}`}
170
+ character={character}
171
+ progress={scrollProgress}
172
+ start={start}
173
+ end={end}
174
+ waveDistance={wave}
175
+ waveOvershoot={wavePeak}
176
+ sidewaysDistance={sideways}
177
+ blurAmount={blur}
178
+ opacityFrom={startOpacity}
179
+ opacityPeak={middleOpacity}
180
+ scaleFrom={startScale}
181
+ scalePeak={middleScale}
182
+ />
183
+ )
184
+ })
185
+
186
+ return (
187
+ <span
188
+ key={`${wordIndex}-${word}`}
189
+ className="inline-block whitespace-nowrap"
190
+ >
191
+ {characters}
192
+ </span>
193
+ )
194
+ })
195
+
196
+ if (lineIndex < lines.length - 1) {
197
+ scrollWeight += scrollLineWeight
198
+ }
199
+
200
+ return (
201
+ <span
202
+ key={`${lineIndex}-${line}`}
203
+ aria-hidden="true"
204
+ className="block"
205
+ >
206
+ {content}
207
+ </span>
208
+ )
209
+ })}
210
+ </p>
211
+ )
212
+ }
213
+
214
+ return (
215
+ <motion.p
216
+ initial={shouldReduceMotion ? false : 'hidden'}
217
+ whileInView="visible"
218
+ viewport={{ once, amount: Math.min(1, Math.max(0, viewportAmount)) }}
219
+ className={cn('text-foreground', className)}
220
+ >
221
+ <span className="sr-only">{text.replace(/\n/g, ' ')}</span>
222
+ {lines.map((line, lineIndex) => {
223
+ let characterIndex = 0
224
+ const words = line.match(/\s+|\S+/gu) ?? []
225
+
226
+ return (
227
+ <span
228
+ key={`${lineIndex}-${line}`}
229
+ aria-hidden="true"
230
+ className="block"
231
+ >
232
+ {words.map((word, wordIndex) => {
233
+ if (/^\s+$/u.test(word)) {
234
+ characterIndex += Array.from(word).length
235
+ return (
236
+ <span
237
+ key={`${wordIndex}-${word}`}
238
+ className="whitespace-pre-wrap"
239
+ >
240
+ {word}
241
+ </span>
242
+ )
243
+ }
244
+
245
+ const characters = Array.from(word).map((character) => {
246
+ const delay =
247
+ lineStartDelays[lineIndex] + characterIndex * stagger
248
+ characterIndex += 1
249
+
250
+ return (
251
+ <motion.span
252
+ key={`${characterIndex}-${character}`}
253
+ custom={delay}
254
+ variants={{
255
+ hidden: {
256
+ opacity: startOpacity,
257
+ y: wave,
258
+ x: -sideways,
259
+ scale: startScale,
260
+ filter: `blur(${blur}px)`,
261
+ },
262
+ visible: shouldReduceMotion
263
+ ? {
264
+ opacity: 1,
265
+ y: 0,
266
+ x: 0,
267
+ scale: 1,
268
+ filter: 'blur(0px)',
269
+ transition: { duration: 0 },
270
+ }
271
+ : (staggerDelay: number) => ({
272
+ opacity: 1,
273
+ y: [wave, -wavePeak, 0],
274
+ x: [-sideways, sideways * 0.5, 0],
275
+ scale: [startScale, middleScale, 1],
276
+ filter: ['blur(' + blur + 'px)', 'blur(0px)'],
277
+ transition: {
278
+ duration: animationDuration,
279
+ delay: staggerDelay,
280
+ ease: 'easeOut',
281
+ },
282
+ }),
283
+ }}
284
+ className="inline-block whitespace-pre"
285
+ >
286
+ {character}
287
+ </motion.span>
288
+ )
289
+ })
290
+
291
+ return (
292
+ <span
293
+ key={`${wordIndex}-${word}`}
294
+ className="inline-block whitespace-nowrap"
295
+ >
296
+ {characters}
297
+ </span>
298
+ )
299
+ })}
300
+ </span>
301
+ )
302
+ })}
303
+ </motion.p>
304
+ )
305
+ }
306
+
307
+ export default TextReveal
@@ -1,197 +0,0 @@
1
- 'use client'
2
-
3
- import { useEffect, useId, useRef, useState } from 'react'
4
- import type { CSSProperties, PointerEvent } from 'react'
5
- import Image from 'next/image'
6
-
7
- export type ImageEffect = 'pixelate' | 'rgb-split' | 'glitch' | 'ascii'
8
-
9
- export type ImageEffectsCardProps = {
10
- src: string
11
- alt: string
12
- effect: ImageEffect
13
- title: string
14
- detail?: string
15
- className?: string
16
- }
17
-
18
- const LENS_MASK =
19
- 'radial-gradient(circle var(--lens-radius, 94px) at var(--pointer-x, 50%) var(--pointer-y, 50%), #000 0 52%, rgba(0,0,0,.92) 62%, rgba(0,0,0,.48) 78%, transparent 100%)'
20
- const ASCII = ' .,:;irsXA253hMHGS#9B&@'
21
-
22
- function drawEffectCanvas(
23
- canvas: HTMLCanvasElement,
24
- image: HTMLImageElement,
25
- effect: 'pixelate' | 'ascii',
26
- ) {
27
- const bounds = canvas.getBoundingClientRect()
28
- const width = Math.max(1, Math.round(bounds.width))
29
- const height = Math.max(1, Math.round(bounds.height))
30
- const context = canvas.getContext('2d')
31
- if (!context || !image.naturalWidth || !image.naturalHeight) return
32
- canvas.width = width
33
- canvas.height = height
34
-
35
- const scale = Math.max(width / image.naturalWidth, height / image.naturalHeight)
36
- const cropWidth = width / scale
37
- const cropHeight = height / scale
38
- const sx = (image.naturalWidth - cropWidth) / 2
39
- const sy = (image.naturalHeight - cropHeight) / 2
40
-
41
- if (effect === 'pixelate') {
42
- const sample = document.createElement('canvas')
43
- sample.width = Math.max(1, Math.ceil(width / 10))
44
- sample.height = Math.max(1, Math.ceil(height / 10))
45
- const small = sample.getContext('2d')
46
- if (!small) return
47
- small.drawImage(image, sx, sy, cropWidth, cropHeight, 0, 0, sample.width, sample.height)
48
- context.imageSmoothingEnabled = false
49
- context.drawImage(sample, 0, 0, width, height)
50
- context.imageSmoothingEnabled = true
51
- return
52
- }
53
-
54
- const columns = Math.max(18, Math.round(width / 8))
55
- const rows = Math.max(24, Math.round(height / 8))
56
- const sample = document.createElement('canvas')
57
- sample.width = columns
58
- sample.height = rows
59
- const small = sample.getContext('2d', { willReadFrequently: true })
60
- if (!small) return
61
- try {
62
- small.drawImage(image, sx, sy, cropWidth, cropHeight, 0, 0, columns, rows)
63
- const pixels = small.getImageData(0, 0, columns, rows).data
64
- context.clearRect(0, 0, width, height)
65
- context.font = `bold ${Math.max(6, width / columns)}px ui-monospace, monospace`
66
- context.textAlign = 'center'
67
- context.textBaseline = 'middle'
68
- for (let y = 0; y < rows; y += 1) {
69
- for (let x = 0; x < columns; x += 1) {
70
- const offset = (y * columns + x) * 4
71
- const red = pixels[offset]
72
- const green = pixels[offset + 1]
73
- const blue = pixels[offset + 2]
74
- const lightness = (red * 0.3 + green * 0.59 + blue * 0.11) / 255
75
- const character = ASCII[Math.min(ASCII.length - 1, Math.floor((1 - lightness) * (ASCII.length - 1)))]
76
- context.fillStyle = `rgba(${Math.min(255, red + 48)}, ${Math.min(255, green + 48)}, ${Math.min(255, blue + 48)}, .98)`
77
- context.fillText(character, (x + 0.5) * (width / columns), (y + 0.5) * (height / rows))
78
- }
79
- }
80
- } catch {
81
- // Canvas text remains hidden if the remote image host blocks pixel access.
82
- }
83
- }
84
-
85
- export default function ImageEffectsCard({
86
- src,
87
- alt,
88
- effect,
89
- title,
90
- detail,
91
- className = '',
92
- }: ImageEffectsCardProps) {
93
- const canvasRef = useRef<HTMLCanvasElement>(null)
94
- const [active, setActive] = useState(false)
95
- const filterId = `glitch-${useId().replace(/:/g, '')}`
96
- const localMaskStyle: CSSProperties = {
97
- maskImage: LENS_MASK,
98
- WebkitMaskImage: LENS_MASK,
99
- }
100
-
101
- useEffect(() => {
102
- if ((effect !== 'pixelate' && effect !== 'ascii') || !active) return
103
- const canvas = canvasRef.current
104
- if (!canvas) return
105
- let cancelled = false
106
- const image = new window.Image()
107
- image.crossOrigin = 'anonymous'
108
- image.src = src
109
- const draw = () => {
110
- if (!cancelled) drawEffectCanvas(canvas, image, effect)
111
- }
112
- image.decode().then(draw).catch(() => {})
113
- const observer = new ResizeObserver(draw)
114
- observer.observe(canvas)
115
- return () => {
116
- cancelled = true
117
- observer.disconnect()
118
- }
119
- }, [active, effect, src])
120
-
121
- function handlePointerEnter(event: PointerEvent<HTMLElement>) {
122
- const radius = Math.round(76 + Math.random() * 52)
123
- event.currentTarget.style.setProperty('--lens-radius', `${radius}px`)
124
- setActive(true)
125
- }
126
-
127
- function handlePointerMove(event: PointerEvent<HTMLElement>) {
128
- const bounds = event.currentTarget.getBoundingClientRect()
129
- event.currentTarget.style.setProperty('--pointer-x', `${event.clientX - bounds.left}px`)
130
- event.currentTarget.style.setProperty('--pointer-y', `${event.clientY - bounds.top}px`)
131
- }
132
-
133
- const layerTransition = `pointer-events-none absolute inset-0 transition-opacity duration-200 ease-out motion-reduce:transition-none ${active ? 'opacity-100' : 'opacity-0'}`
134
-
135
- return (
136
- <figure
137
- onPointerEnter={handlePointerEnter}
138
- onPointerMove={handlePointerMove}
139
- onPointerLeave={() => setActive(false)}
140
- className={`group relative isolate aspect-[4/5] overflow-hidden rounded-xl bg-neutral-950 ${className}`}
141
- >
142
- <Image
143
- src={src}
144
- alt={alt}
145
- fill
146
- unoptimized
147
- sizes="(max-width: 640px) 50vw, (max-width: 1024px) 25vw, 260px"
148
- className="object-cover"
149
- />
150
-
151
- {(effect === 'pixelate' || effect === 'ascii') && (
152
- <canvas
153
- ref={canvasRef}
154
- aria-hidden="true"
155
- className={`${layerTransition} h-full w-full object-cover blur-[0.4px]`}
156
- style={localMaskStyle}
157
- />
158
- )}
159
-
160
- {effect === 'rgb-split' && (
161
- <div className={layerTransition} style={localMaskStyle} aria-hidden="true">
162
- <div className="absolute inset-0 -translate-x-[3px] scale-[1.015] bg-cover bg-center mix-blend-screen blur-[0.6px]" style={{ backgroundImage: `url("${src}")`, filter: 'sepia(1) saturate(5) hue-rotate(292deg)' }} />
163
- <div className="absolute inset-0 translate-x-[3px] scale-[1.015] bg-cover bg-center mix-blend-screen blur-[0.6px]" style={{ backgroundImage: `url("${src}")`, filter: 'sepia(1) saturate(5) hue-rotate(150deg)' }} />
164
- </div>
165
- )}
166
-
167
- {effect === 'glitch' && (
168
- <>
169
- <svg className="absolute size-0" aria-hidden="true">
170
- <filter id={filterId}>
171
- <feTurbulence type="fractalNoise" baseFrequency="0.018 0.12" numOctaves="1" seed="3" result="noise" />
172
- <feDisplacementMap in="SourceGraphic" in2="noise" scale="24" xChannelSelector="R" yChannelSelector="G" />
173
- </filter>
174
- </svg>
175
- <div className={layerTransition} style={localMaskStyle} aria-hidden="true">
176
- <div className="absolute inset-0 scale-[1.025] bg-cover bg-center blur-[0.55px]" style={{ backgroundImage: `url("${src}")`, filter: `url(#${filterId}) saturate(1.45) hue-rotate(8deg)` }} />
177
- </div>
178
- </>
179
- )}
180
-
181
- <div
182
- aria-hidden="true"
183
- className={`pointer-events-none absolute inset-0 transition-opacity duration-200 motion-reduce:transition-none ${active ? 'opacity-100' : 'opacity-0'}`}
184
- style={{
185
- ...localMaskStyle,
186
- background: 'radial-gradient(circle var(--lens-radius, 94px) at var(--pointer-x, 50%) var(--pointer-y, 50%), transparent 62%, rgba(255,255,255,.22) 76%, rgba(255,255,255,.05) 88%, transparent 100%)',
187
- filter: 'blur(5px)',
188
- }}
189
- />
190
-
191
- <figcaption className="absolute inset-x-0 bottom-0 z-10 bg-gradient-to-t from-black/80 via-black/35 to-transparent px-3 pt-12 pb-3 text-white">
192
- <p className="text-[10px] font-semibold tracking-[0.14em] uppercase">{title}</p>
193
- {detail ? <p className="mt-1 text-[10px] text-white/70">{detail}</p> : null}
194
- </figcaption>
195
- </figure>
196
- )
197
- }