@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,357 +1,342 @@
1
- import { cn } from './utils'
2
-
3
- export type TokenType =
4
- | 'tag'
5
- | 'attribute'
6
- | 'string'
7
- | 'keyword'
8
- | 'component'
9
- | 'type'
10
- | 'function'
11
- | 'literal'
12
- | 'number'
13
- | 'comment'
14
- | 'punctuation'
15
- | 'identifier'
16
- | 'space'
17
-
18
- export type Token = {
19
- type: TokenType
20
- value: string
21
- }
22
-
23
- // Visual color palette matching the target editor reference
24
- export const TOKEN_COLORS: Record<TokenType, string> = {
25
- tag: '#fb923c', // Warm orange for JSX / HTML tags (<AppleCarouselRoot>, <AnimatedText>, </MotionLink>)
26
- attribute: '#fde047', // Light / warm yellow for JSX attributes (aria-label, prefix, href, initial, animate)
27
- string: '#4ade80', // Emerald green for string values ("Featured", "blur", "@/components/...")
28
- keyword: '#f472b6', // Pink / magenta for language keywords (import, from, const, return, export)
29
- function: '#38bdf8', // Sky blue for function calls and methods (motion.create, useState)
30
- component: '#2dd4bf', // Teal / cyan for capitalized components & types in expressions
31
- type: '#2dd4bf', // Teal / cyan for TypeScript types
32
- literal: '#fdba74', // Warm peach for booleans & null (false, true, null)
33
- number: '#fdba74', // Warm peach for numbers
34
- comment: '#71717a', // Muted slate gray for comments
35
- punctuation: '#94a3b8', // Subtle neutral gray for punctuation (<, >, =, ;, {}, ())
36
- identifier: '#e2e8f0', // Warm off-white for plain variables & identifiers
37
- space: 'inherit',
38
- }
39
-
40
- const KEYWORDS = new Set([
41
- 'import',
42
- 'from',
43
- 'export',
44
- 'default',
45
- 'const',
46
- 'let',
47
- 'var',
48
- 'function',
49
- 'return',
50
- 'if',
51
- 'else',
52
- 'switch',
53
- 'case',
54
- 'break',
55
- 'continue',
56
- 'for',
57
- 'while',
58
- 'do',
59
- 'try',
60
- 'catch',
61
- 'finally',
62
- 'throw',
63
- 'new',
64
- 'delete',
65
- 'typeof',
66
- 'instanceof',
67
- 'void',
68
- 'in',
69
- 'of',
70
- 'yield',
71
- 'await',
72
- 'async',
73
- 'as',
74
- ])
75
-
76
- const TYPES = new Set([
77
- 'type',
78
- 'interface',
79
- 'extends',
80
- 'implements',
81
- 'class',
82
- 'enum',
83
- 'string',
84
- 'number',
85
- 'boolean',
86
- 'any',
87
- 'unknown',
88
- 'never',
89
- 'symbol',
90
- 'bigint',
91
- 'void',
92
- 'Record',
93
- 'ReactNode',
94
- 'React',
95
- 'keyof',
96
- 'readonly',
97
- ])
98
-
99
- const LITERALS = new Set(['true', 'false', 'null', 'undefined'])
100
-
101
- export function tokenizeCode(code: string): Token[][] {
102
- const lines = code.replace(/\r\n/g, '\n').split('\n')
103
- const result: Token[][] = []
104
- let inTag = false
105
- let braceDepth = 0
106
-
107
- for (const line of lines) {
108
- const tokens: Token[] = []
109
- let i = 0
110
- const len = line.length
111
-
112
- while (i < len) {
113
- // 1. Whitespace
114
- if (/\s/.test(line[i])) {
115
- let space = ''
116
- while (i < len && /\s/.test(line[i])) {
117
- space += line[i++]
118
- }
119
- tokens.push({ type: 'space', value: space })
120
- continue
121
- }
122
-
123
- // 2. Comments
124
- if (line.startsWith('{/*', i)) {
125
- const end = line.indexOf('*/}', i)
126
- const val = end === -1 ? line.slice(i) : line.slice(i, end + 3)
127
- tokens.push({ type: 'comment', value: val })
128
- i += val.length
129
- continue
130
- }
131
- if (line.startsWith('//', i)) {
132
- const val = line.slice(i)
133
- tokens.push({ type: 'comment', value: val })
134
- break
135
- }
136
- if (line.startsWith('/*', i)) {
137
- const end = line.indexOf('*/', i)
138
- const val = end === -1 ? line.slice(i) : line.slice(i, end + 2)
139
- tokens.push({ type: 'comment', value: val })
140
- i += val.length
141
- continue
142
- }
143
-
144
- // 3. Strings
145
- if (line[i] === '"' || line[i] === "'" || line[i] === '`') {
146
- const quote = line[i]
147
- let str = quote
148
- i++
149
- while (i < len) {
150
- if (line[i] === '\\') {
151
- str += line[i++]
152
- if (i < len) str += line[i++]
153
- } else if (line[i] === quote) {
154
- str += line[i++]
155
- break
156
- } else {
157
- str += line[i++]
158
- }
159
- }
160
- tokens.push({ type: 'string', value: str })
161
- continue
162
- }
163
-
164
- // 4. Closing JSX Tag: </Tag
165
- if (line.startsWith('</', i)) {
166
- const m = line.slice(i + 2).match(/^[a-zA-Z_$][a-zA-Z0-9_$.-]*/)
167
- if (m) {
168
- tokens.push({ type: 'punctuation', value: '</' })
169
- tokens.push({ type: 'tag', value: m[0] })
170
- i += 2 + m[0].length
171
- inTag = true
172
- braceDepth = 0
173
- continue
174
- }
175
- }
176
-
177
- // 5. Opening JSX Tag: <Tag
178
- if (line[i] === '<') {
179
- const m = line.slice(i + 1).match(/^[a-zA-Z_$][a-zA-Z0-9_$.-]*/)
180
- if (m && !line.startsWith('<=', i) && !line.startsWith('<<', i)) {
181
- tokens.push({ type: 'punctuation', value: '<' })
182
- tokens.push({ type: 'tag', value: m[0] })
183
- i += 1 + m[0].length
184
- inTag = true
185
- braceDepth = 0
186
- continue
187
- }
188
- }
189
-
190
- // Track braces inside JSX attributes
191
- if (inTag && line[i] === '{') {
192
- braceDepth++
193
- tokens.push({ type: 'punctuation', value: '{' })
194
- i++
195
- continue
196
- }
197
- if (inTag && line[i] === '}') {
198
- if (braceDepth > 0) braceDepth--
199
- tokens.push({ type: 'punctuation', value: '}' })
200
- i++
201
- continue
202
- }
203
-
204
- // Tag closers: /> or > (when outside attribute expressions)
205
- if (inTag && braceDepth === 0 && line.startsWith('/>', i)) {
206
- tokens.push({ type: 'punctuation', value: '/>' })
207
- i += 2
208
- inTag = false
209
- continue
210
- }
211
- if (inTag && braceDepth === 0 && line[i] === '>') {
212
- tokens.push({ type: 'punctuation', value: '>' })
213
- i += 1
214
- inTag = false
215
- continue
216
- }
217
-
218
- // 6. Multi-character operators
219
- const two = line.slice(i, i + 2)
220
- const three = line.slice(i, i + 3)
221
- if (three === '===' || three === '!==') {
222
- tokens.push({ type: 'punctuation', value: three })
223
- i += 3
224
- continue
225
- }
226
- if (
227
- two === '=>' ||
228
- two === '==' ||
229
- two === '!=' ||
230
- two === '<=' ||
231
- two === '>=' ||
232
- two === '&&' ||
233
- two === '||' ||
234
- two === '??' ||
235
- two === '?.'
236
- ) {
237
- tokens.push({ type: 'punctuation', value: two })
238
- i += 2
239
- continue
240
- }
241
-
242
- // Check preceding non-space token in this line
243
- const prevToken = [...tokens].reverse().find((t) => t.type !== 'space')
244
- const isAfterDeclaration =
245
- prevToken && ['const', 'let', 'var', 'export'].includes(prevToken.value)
246
-
247
- // 7. JSX Attribute: word before = (inTag or in multiline JSX)
248
- const attrMatch = line
249
- .slice(i)
250
- .match(/^[a-zA-Z_$][a-zA-Z0-9_$-]*(?=\s*=)/)
251
- if (attrMatch && (inTag || !isAfterDeclaration)) {
252
- tokens.push({ type: 'attribute', value: attrMatch[0] })
253
- i += attrMatch[0].length
254
- continue
255
- }
256
-
257
- // 8. Boolean attribute inside tag when braceDepth === 0
258
- if (inTag && braceDepth === 0) {
259
- const boolAttrMatch = line.slice(i).match(/^[a-zA-Z_$][a-zA-Z0-9_$-]*/)
260
- if (boolAttrMatch) {
261
- const val = boolAttrMatch[0]
262
- let nextIdx = i + val.length
263
- while (nextIdx < len && /\s/.test(line[nextIdx])) nextIdx++
264
- if (
265
- nextIdx >= len ||
266
- line[nextIdx] === '>' ||
267
- line.startsWith('/>', nextIdx) ||
268
- /^[a-zA-Z]/.test(line[nextIdx])
269
- ) {
270
- tokens.push({ type: 'attribute', value: val })
271
- i += val.length
272
- continue
273
- }
274
- }
275
- }
276
-
277
- // 9. Numbers
278
- const numMatch = line.slice(i).match(/^\d+(?:\.\d+)?\b/)
279
- if (numMatch) {
280
- tokens.push({ type: 'number', value: numMatch[0] })
281
- i += numMatch[0].length
282
- continue
283
- }
284
-
285
- // 10. Word / identifier
286
- const idMatch = line.slice(i).match(/^[a-zA-Z_$][a-zA-Z0-9_$]*/)
287
- if (idMatch) {
288
- const val = idMatch[0]
289
- i += val.length
290
-
291
- let j = i
292
- while (j < len && /\s/.test(line[j])) j++
293
- const isCall = line[j] === '('
294
-
295
- if (KEYWORDS.has(val)) {
296
- tokens.push({ type: 'keyword', value: val })
297
- } else if (LITERALS.has(val)) {
298
- tokens.push({ type: 'literal', value: val })
299
- } else if (TYPES.has(val)) {
300
- tokens.push({ type: 'type', value: val })
301
- } else if (isCall) {
302
- tokens.push({ type: 'function', value: val })
303
- } else if (/^[A-Z]/.test(val)) {
304
- tokens.push({ type: 'component', value: val })
305
- } else {
306
- tokens.push({ type: 'identifier', value: val })
307
- }
308
- continue
309
- }
310
-
311
- // 11. Single-char punctuation
312
- tokens.push({ type: 'punctuation', value: line[i] })
313
- i++
314
- }
315
-
316
- result.push(tokens)
317
- }
318
-
319
- return result
320
- }
321
-
322
- export function TokenSpan({ token }: { token: Token }) {
323
- if (token.type === 'space') {
324
- return <>{token.value}</>
325
- }
326
-
327
- const color = TOKEN_COLORS[token.type] ?? '#e2e8f0'
328
- const isItalic = token.type === 'comment'
329
-
330
- return (
331
- <span style={{ color }} className={isItalic ? 'italic' : undefined}>
332
- {token.value}
333
- </span>
334
- )
335
- }
336
-
337
-
338
- export function CodeHighlighter({
339
- code,
340
- className,
341
- }: {
342
- code: string
343
- className?: string
344
- }) {
345
- const lines = tokenizeCode(code)
346
- return (
347
- <pre className={cn('w-full max-w-full overflow-x-auto p-4 font-mono text-[13.5px] leading-[1.7] antialiased select-text sm:p-5 sm:text-[14.5px] sm:leading-[1.72]', className)} style={{ fontFamily: 'var(--font-geist-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace' }}>
348
- <code>{lines.map((line, lineIndex) => (
349
- <span key={`highlight-line-${lineIndex}`} className="block min-h-[1.7em] whitespace-pre">
350
- {line.length ? line.map((token, tokenIndex) => (
351
- <TokenSpan key={`highlight-${lineIndex}-${tokenIndex}`} token={token} />
352
- )) : <>&nbsp;</>}
353
- </span>
354
- ))}</code>
355
- </pre>
356
- )
357
- }
1
+ import { cn } from './utils'
2
+
3
+ export type TokenType =
4
+ | 'tag'
5
+ | 'attribute'
6
+ | 'string'
7
+ | 'keyword'
8
+ | 'component'
9
+ | 'type'
10
+ | 'function'
11
+ | 'literal'
12
+ | 'number'
13
+ | 'comment'
14
+ | 'punctuation'
15
+ | 'identifier'
16
+ | 'space'
17
+
18
+ export type Token = {
19
+ type: TokenType
20
+ value: string
21
+ }
22
+
23
+ export const TOKEN_COLORS: Record<TokenType, string> = {
24
+ tag: '#fb923c',
25
+ attribute: '#fde047',
26
+ string: '#4ade80',
27
+ keyword: '#f472b6',
28
+ function: '#38bdf8',
29
+ component: '#2dd4bf',
30
+ type: '#2dd4bf',
31
+ literal: '#fdba74',
32
+ number: '#fdba74',
33
+ comment: '#71717a',
34
+ punctuation: '#94a3b8',
35
+ identifier: '#e2e8f0',
36
+ space: 'inherit',
37
+ }
38
+
39
+ const KEYWORDS = new Set([
40
+ 'import',
41
+ 'from',
42
+ 'export',
43
+ 'default',
44
+ 'const',
45
+ 'let',
46
+ 'var',
47
+ 'function',
48
+ 'return',
49
+ 'if',
50
+ 'else',
51
+ 'switch',
52
+ 'case',
53
+ 'break',
54
+ 'continue',
55
+ 'for',
56
+ 'while',
57
+ 'do',
58
+ 'try',
59
+ 'catch',
60
+ 'finally',
61
+ 'throw',
62
+ 'new',
63
+ 'delete',
64
+ 'typeof',
65
+ 'instanceof',
66
+ 'void',
67
+ 'in',
68
+ 'of',
69
+ 'yield',
70
+ 'await',
71
+ 'async',
72
+ 'as',
73
+ ])
74
+
75
+ const TYPES = new Set([
76
+ 'type',
77
+ 'interface',
78
+ 'extends',
79
+ 'implements',
80
+ 'class',
81
+ 'enum',
82
+ 'string',
83
+ 'number',
84
+ 'boolean',
85
+ 'any',
86
+ 'unknown',
87
+ 'never',
88
+ 'symbol',
89
+ 'bigint',
90
+ 'void',
91
+ 'Record',
92
+ 'ReactNode',
93
+ 'React',
94
+ 'keyof',
95
+ 'readonly',
96
+ ])
97
+
98
+ const LITERALS = new Set(['true', 'false', 'null', 'undefined'])
99
+
100
+ export function tokenizeCode(code: string): Token[][] {
101
+ const lines = code.replace(/\r\n/g, '\n').split('\n')
102
+ const result: Token[][] = []
103
+ let inTag = false
104
+ let braceDepth = 0
105
+
106
+ for (const line of lines) {
107
+ const tokens: Token[] = []
108
+ let i = 0
109
+ const len = line.length
110
+
111
+ while (i < len) {
112
+ if (/\s/.test(line[i])) {
113
+ let space = ''
114
+ while (i < len && /\s/.test(line[i])) {
115
+ space += line[i++]
116
+ }
117
+ tokens.push({ type: 'space', value: space })
118
+ continue
119
+ }
120
+
121
+ if (line.startsWith('{/*', i)) {
122
+ const end = line.indexOf('*/}', i)
123
+ const val = end === -1 ? line.slice(i) : line.slice(i, end + 3)
124
+ tokens.push({ type: 'comment', value: val })
125
+ i += val.length
126
+ continue
127
+ }
128
+ if (line.startsWith('//', i)) {
129
+ const val = line.slice(i)
130
+ tokens.push({ type: 'comment', value: val })
131
+ break
132
+ }
133
+ if (line.startsWith('/*', i)) {
134
+ const end = line.indexOf('*/', i)
135
+ const val = end === -1 ? line.slice(i) : line.slice(i, end + 2)
136
+ tokens.push({ type: 'comment', value: val })
137
+ i += val.length
138
+ continue
139
+ }
140
+
141
+ if (line[i] === '"' || line[i] === "'" || line[i] === '`') {
142
+ const quote = line[i]
143
+ let str = quote
144
+ i++
145
+ while (i < len) {
146
+ if (line[i] === '\\') {
147
+ str += line[i++]
148
+ if (i < len) str += line[i++]
149
+ } else if (line[i] === quote) {
150
+ str += line[i++]
151
+ break
152
+ } else {
153
+ str += line[i++]
154
+ }
155
+ }
156
+ tokens.push({ type: 'string', value: str })
157
+ continue
158
+ }
159
+
160
+ if (line.startsWith('</', i)) {
161
+ const m = line.slice(i + 2).match(/^[a-zA-Z_$][a-zA-Z0-9_$.-]*/)
162
+ if (m) {
163
+ tokens.push({ type: 'punctuation', value: '</' })
164
+ tokens.push({ type: 'tag', value: m[0] })
165
+ i += 2 + m[0].length
166
+ inTag = true
167
+ braceDepth = 0
168
+ continue
169
+ }
170
+ }
171
+
172
+ if (line[i] === '<') {
173
+ const m = line.slice(i + 1).match(/^[a-zA-Z_$][a-zA-Z0-9_$.-]*/)
174
+ if (m && !line.startsWith('<=', i) && !line.startsWith('<<', i)) {
175
+ tokens.push({ type: 'punctuation', value: '<' })
176
+ tokens.push({ type: 'tag', value: m[0] })
177
+ i += 1 + m[0].length
178
+ inTag = true
179
+ braceDepth = 0
180
+ continue
181
+ }
182
+ }
183
+
184
+ if (inTag && line[i] === '{') {
185
+ braceDepth++
186
+ tokens.push({ type: 'punctuation', value: '{' })
187
+ i++
188
+ continue
189
+ }
190
+ if (inTag && line[i] === '}') {
191
+ if (braceDepth > 0) braceDepth--
192
+ tokens.push({ type: 'punctuation', value: '}' })
193
+ i++
194
+ continue
195
+ }
196
+
197
+ if (inTag && braceDepth === 0 && line.startsWith('/>', i)) {
198
+ tokens.push({ type: 'punctuation', value: '/>' })
199
+ i += 2
200
+ inTag = false
201
+ continue
202
+ }
203
+ if (inTag && braceDepth === 0 && line[i] === '>') {
204
+ tokens.push({ type: 'punctuation', value: '>' })
205
+ i += 1
206
+ inTag = false
207
+ continue
208
+ }
209
+
210
+ const two = line.slice(i, i + 2)
211
+ const three = line.slice(i, i + 3)
212
+ if (three === '===' || three === '!==') {
213
+ tokens.push({ type: 'punctuation', value: three })
214
+ i += 3
215
+ continue
216
+ }
217
+ if (
218
+ two === '=>' ||
219
+ two === '==' ||
220
+ two === '!=' ||
221
+ two === '<=' ||
222
+ two === '>=' ||
223
+ two === '&&' ||
224
+ two === '||' ||
225
+ two === '??' ||
226
+ two === '?.'
227
+ ) {
228
+ tokens.push({ type: 'punctuation', value: two })
229
+ i += 2
230
+ continue
231
+ }
232
+
233
+ const prevToken = [...tokens].reverse().find((t) => t.type !== 'space')
234
+ const isAfterDeclaration =
235
+ prevToken && ['const', 'let', 'var', 'export'].includes(prevToken.value)
236
+
237
+ const attrMatch = line
238
+ .slice(i)
239
+ .match(/^[a-zA-Z_$][a-zA-Z0-9_$-]*(?=\s*=)/)
240
+ if (attrMatch && (inTag || !isAfterDeclaration)) {
241
+ tokens.push({ type: 'attribute', value: attrMatch[0] })
242
+ i += attrMatch[0].length
243
+ continue
244
+ }
245
+
246
+ if (inTag && braceDepth === 0) {
247
+ const boolAttrMatch = line.slice(i).match(/^[a-zA-Z_$][a-zA-Z0-9_$-]*/)
248
+ if (boolAttrMatch) {
249
+ const val = boolAttrMatch[0]
250
+ let nextIdx = i + val.length
251
+ while (nextIdx < len && /\s/.test(line[nextIdx])) nextIdx++
252
+ if (
253
+ nextIdx >= len ||
254
+ line[nextIdx] === '>' ||
255
+ line.startsWith('/>', nextIdx) ||
256
+ /^[a-zA-Z]/.test(line[nextIdx])
257
+ ) {
258
+ tokens.push({ type: 'attribute', value: val })
259
+ i += val.length
260
+ continue
261
+ }
262
+ }
263
+ }
264
+
265
+ const numMatch = line.slice(i).match(/^\d+(?:\.\d+)?\b/)
266
+ if (numMatch) {
267
+ tokens.push({ type: 'number', value: numMatch[0] })
268
+ i += numMatch[0].length
269
+ continue
270
+ }
271
+
272
+ const idMatch = line.slice(i).match(/^[a-zA-Z_$][a-zA-Z0-9_$]*/)
273
+ if (idMatch) {
274
+ const val = idMatch[0]
275
+ i += val.length
276
+
277
+ let j = i
278
+ while (j < len && /\s/.test(line[j])) j++
279
+ const isCall = line[j] === '('
280
+
281
+ if (KEYWORDS.has(val)) {
282
+ tokens.push({ type: 'keyword', value: val })
283
+ } else if (LITERALS.has(val)) {
284
+ tokens.push({ type: 'literal', value: val })
285
+ } else if (TYPES.has(val)) {
286
+ tokens.push({ type: 'type', value: val })
287
+ } else if (isCall) {
288
+ tokens.push({ type: 'function', value: val })
289
+ } else if (/^[A-Z]/.test(val)) {
290
+ tokens.push({ type: 'component', value: val })
291
+ } else {
292
+ tokens.push({ type: 'identifier', value: val })
293
+ }
294
+ continue
295
+ }
296
+
297
+ tokens.push({ type: 'punctuation', value: line[i] })
298
+ i++
299
+ }
300
+
301
+ result.push(tokens)
302
+ }
303
+
304
+ return result
305
+ }
306
+
307
+ export function TokenSpan({ token }: { token: Token }) {
308
+ if (token.type === 'space') {
309
+ return <>{token.value}</>
310
+ }
311
+
312
+ const color = TOKEN_COLORS[token.type] ?? '#e2e8f0'
313
+ const isItalic = token.type === 'comment'
314
+
315
+ return (
316
+ <span style={{ color }} className={isItalic ? 'italic' : undefined}>
317
+ {token.value}
318
+ </span>
319
+ )
320
+ }
321
+
322
+
323
+ export function CodeHighlighter({
324
+ code,
325
+ className,
326
+ }: {
327
+ code: string
328
+ className?: string
329
+ }) {
330
+ const lines = tokenizeCode(code)
331
+ return (
332
+ <pre className={cn('w-full max-w-full overflow-x-auto p-4 font-mono text-[13.5px] leading-[1.7] antialiased select-text sm:p-5 sm:text-[14.5px] sm:leading-[1.72]', className)} style={{ fontFamily: 'var(--font-geist-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace' }}>
333
+ <code>{lines.map((line, lineIndex) => (
334
+ <span key={`highlight-line-${lineIndex}`} className="block min-h-[1.7em] whitespace-pre">
335
+ {line.length ? line.map((token, tokenIndex) => (
336
+ <TokenSpan key={`highlight-${lineIndex}-${tokenIndex}`} token={token} />
337
+ )) : <>&nbsp;</>}
338
+ </span>
339
+ ))}</code>
340
+ </pre>
341
+ )
342
+ }