@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,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
|
-
|
|
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
|
-
'
|
|
82
|
-
'
|
|
83
|
-
'
|
|
84
|
-
'
|
|
85
|
-
'
|
|
86
|
-
'
|
|
87
|
-
'
|
|
88
|
-
'
|
|
89
|
-
'
|
|
90
|
-
'
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
'
|
|
95
|
-
'
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
let
|
|
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
|
-
|
|
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
|
-
if (inTag &&
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
continue
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
continue
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
i
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
)) : <> </>}
|
|
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
|
+
)) : <> </>}
|
|
338
|
+
</span>
|
|
339
|
+
))}</code>
|
|
340
|
+
</pre>
|
|
341
|
+
)
|
|
342
|
+
}
|