@alivault/pico 0.10.1 → 0.10.3

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.
@@ -1,1036 +0,0 @@
1
- import { n as __exportAll } from "../_runtime.mjs";
2
- //#region node_modules/.pnpm/sugar-high@1.1.0/node_modules/sugar-high/lib/index.js
3
- var JSXBrackets = new Set([
4
- "<",
5
- ">",
6
- "{",
7
- "}",
8
- "[",
9
- "]"
10
- ]);
11
- var Keywords_Js = new Set([
12
- "for",
13
- "do",
14
- "while",
15
- "if",
16
- "else",
17
- "return",
18
- "function",
19
- "var",
20
- "let",
21
- "const",
22
- "true",
23
- "false",
24
- "undefined",
25
- "this",
26
- "new",
27
- "delete",
28
- "typeof",
29
- "in",
30
- "instanceof",
31
- "void",
32
- "break",
33
- "continue",
34
- "switch",
35
- "case",
36
- "default",
37
- "throw",
38
- "try",
39
- "catch",
40
- "finally",
41
- "debugger",
42
- "with",
43
- "yield",
44
- "async",
45
- "await",
46
- "class",
47
- "extends",
48
- "super",
49
- "import",
50
- "export",
51
- "from",
52
- "static"
53
- ]);
54
- var Keywords_Ts = new Set([
55
- ...Keywords_Js,
56
- "type",
57
- "interface",
58
- "enum",
59
- "implements",
60
- "readonly",
61
- "abstract",
62
- "declare",
63
- "namespace",
64
- "module",
65
- "private",
66
- "protected",
67
- "public",
68
- "override",
69
- "keyof",
70
- "infer",
71
- "is",
72
- "asserts",
73
- "satisfies",
74
- "as",
75
- "unknown",
76
- "never",
77
- "any",
78
- "number",
79
- "string",
80
- "boolean",
81
- "bigint",
82
- "symbol",
83
- "object"
84
- ]);
85
- var Signs = new Set([
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
- ...JSXBrackets
114
- ]);
115
- var DefaultOptions = {
116
- keywords: Keywords_Js,
117
- onCommentStart: isCommentStart_Js,
118
- onCommentEnd: isCommentEnd_Js
119
- };
120
- /**
121
- * Fast, heuristic TS detection. It intentionally prefers speed over full parsing.
122
- * @param {string} code
123
- * @returns {boolean}
124
- */
125
- function isLikelyTypeScript(code) {
126
- let tsScore = 0;
127
- if (/\binterface\s+[A-Za-z_$][\w$]*/.test(code)) tsScore += 2;
128
- if (/\btype\s+[A-Za-z_$][\w$]*\s*=/.test(code)) tsScore += 2;
129
- if (/\benum\s+[A-Za-z_$][\w$]*/.test(code)) tsScore += 2;
130
- if (/\b(?:implements|readonly|declare|namespace|satisfies|infer|keyof|asserts)\b/.test(code)) tsScore += 2;
131
- if (/:\s*[A-Za-z_$][\w$]*(?:<[^>\n]+>)?(?:\[\])?(?=\s*[,)=;{])/m.test(code)) tsScore += 1;
132
- if (/\b(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*:\s*/.test(code)) tsScore += 1;
133
- if (/\)\s*:\s*[A-Za-z_$][\w$]*(?:<[^>\n]+>)?(?:\[\])?\s*(?:=>|\{)/.test(code)) tsScore += 1;
134
- return tsScore >= 2;
135
- }
136
- /**
137
- * Detects `<T, U = ...>(` style generic parameter lists so they are not
138
- * treated as JSX tags.
139
- * @param {string} code
140
- * @param {number} startIndex
141
- * @returns {boolean}
142
- */
143
- function isTypeParameterListStart(code, startIndex) {
144
- if (code[startIndex] !== "<") return false;
145
- let depth = 0;
146
- let sawIdentifierStart = false;
147
- for (let i = startIndex; i < code.length; i++) {
148
- const ch = code[i];
149
- if (ch === "<") {
150
- depth++;
151
- continue;
152
- }
153
- if (ch === ">") {
154
- depth--;
155
- if (depth === 0) {
156
- let next = i + 1;
157
- while (next < code.length && /\s/.test(code[next])) next++;
158
- if (!(sawIdentifierStart && code[next] === "(")) return false;
159
- const tail = code.slice(next, next + 320);
160
- return /\)\s*(?::[\s\S]{0,120}?)?=>/.test(tail);
161
- }
162
- continue;
163
- }
164
- if (depth === 0) continue;
165
- if (/[$A-Za-z_]/.test(ch)) {
166
- sawIdentifierStart = true;
167
- continue;
168
- }
169
- if (/[\s,\.\=\?\:\|\&\[\]]/.test(ch)) continue;
170
- return false;
171
- }
172
- return false;
173
- }
174
- /**
175
- *
176
- * 0 - identifier
177
- * 1 - keyword
178
- * 2 - string
179
- * 3 - Class, number and null
180
- * 4 - property
181
- * 5 - entity
182
- * 6 - jsx literals
183
- * 7 - sign
184
- * 8 - comment
185
- * 9 - break
186
- * 10 - space
187
- *
188
- */
189
- var TokenTypes = [
190
- "identifier",
191
- "keyword",
192
- "string",
193
- "class",
194
- "property",
195
- "entity",
196
- "jsxliterals",
197
- "sign",
198
- "comment",
199
- "break",
200
- "space"
201
- ];
202
- var [T_IDENTIFIER, T_KEYWORD, T_STRING, T_CLS_NUMBER, T_PROPERTY, T_ENTITY, T_JSX_LITERALS, T_SIGN, T_COMMENT, T_BREAK, T_SPACE] = TokenTypes.map((_, i) => i);
203
- function isSpaces(str) {
204
- return /^[^\S\r\n]+$/g.test(str);
205
- }
206
- function isSign(ch) {
207
- return Signs.has(ch);
208
- }
209
- function encode(str) {
210
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
211
- }
212
- function isWord(chr) {
213
- return /^[\w_]+$/.test(chr) || hasUnicode(chr);
214
- }
215
- function isCls(str) {
216
- const chr0 = str[0];
217
- return isWord(chr0) && chr0 === chr0.toUpperCase() || str === "null";
218
- }
219
- function hasUnicode(s) {
220
- return /[^\u0000-\u007f]/.test(s);
221
- }
222
- function isAlpha(chr) {
223
- return /^[a-zA-Z]$/.test(chr);
224
- }
225
- function isIdentifierChar(chr) {
226
- return isAlpha(chr) || hasUnicode(chr);
227
- }
228
- function isIdentifier(str) {
229
- return isIdentifierChar(str[0]) && (str.length === 1 || isWord(str.slice(1)));
230
- }
231
- function isStrTemplateChr(chr) {
232
- return chr === "`";
233
- }
234
- function isSingleQuotes(chr) {
235
- return chr === "\"" || chr === "'";
236
- }
237
- function isStringQuotation(chr) {
238
- return isSingleQuotes(chr) || isStrTemplateChr(chr);
239
- }
240
- /** @returns {0|1|2} */
241
- function isCommentStart_Js(curr, next) {
242
- const str = curr + next;
243
- if (str === "/*") return 2;
244
- return str === "//" ? 1 : 0;
245
- }
246
- /** @returns {0|1|2} */
247
- function isCommentEnd_Js(prev, curr) {
248
- return prev + curr === "*/" ? 2 : curr === "\n" ? 1 : 0;
249
- }
250
- function isRegexStart(str) {
251
- return str[0] === "/" && !isCommentStart_Js(str[0], str[1]);
252
- }
253
- /**
254
- * @param {string} code
255
- * @param {{
256
- * keywords?: Set<string>
257
- * typeKeywords?: Set<string>
258
- * onCommentStart?: (curr: string, next: string) => number | boolean
259
- * onCommentEnd?: (prev: string, curr: string) => number | boolean
260
- * onQuote?: (curr: string, i: number, code: string) => number | null | undefined
261
- * } | undefined} options
262
- * Optional `onQuote(curr, i, code)` at `code[i] === "'"`: return length to consume from `i` (>= 1),
263
- * or null/undefined/below 1 for default JS single-quoted strings. No substring allocation.
264
- * @return {Array<[number, string]>}
265
- */
266
- function tokenize(code, options) {
267
- const mergedOptions = {
268
- ...DefaultOptions,
269
- ...options
270
- };
271
- const hasCustomKeywords = !!(options && options.keywords instanceof Set);
272
- const isTs = isLikelyTypeScript(code);
273
- const resolvedKeywords = hasCustomKeywords ? mergedOptions.keywords : isTs ? Keywords_Ts : Keywords_Js;
274
- const { onCommentStart, onCommentEnd } = mergedOptions;
275
- const resolvedTypeKeywords = mergedOptions.typeKeywords instanceof Set ? mergedOptions.typeKeywords : null;
276
- let current = "";
277
- let type = -1;
278
- /** @type {[number, string]} */
279
- let last = [-1, ""];
280
- /** @type {[number, string]} */
281
- let beforeLast = [-2, ""];
282
- /** @type {Array<[number, string]>} */
283
- const tokens = [];
284
- /**
285
- * TS generics (`Map<string>`) and JSX (`<div>`) share the same `<Name …>` lexical shape. We use
286
- * one tag-lexer mode (__jsxTag + __jsxStack) for both when we enter it; isTsTypeArgStart and
287
- * isTypeParameterListStart only decide when *not* to enter (e.g. `foo<T>`, `<T>(x)=>`).
288
- * __jsxEnter gates that mode so a latched __jsxTag (from `<` in `"a<b"`) does not run the tag
289
- * lexer until we are in real JSX/TSX surface (not inside strings).
290
- * @type {boolean}
291
- */
292
- let __jsxEnter = false;
293
- /** @type {0 | 1 | 2} 0 = none; 1 = inside `<open`; 2 = inside `</close` */
294
- let __jsxTag = 0;
295
- let __jsxExpr = false;
296
- /** Nested `<open>…</open>` depth (content between tags, including nested elements). */
297
- let __jsxStack = 0;
298
- const __jsxChild = () => __jsxEnter && !__jsxExpr && !__jsxTag;
299
- const inJsxTag = () => __jsxTag && !__jsxChild();
300
- const inJsxLiterals = () => !__jsxTag && __jsxChild() && !__jsxExpr && __jsxStack > 0;
301
- /** @type {string | null} */
302
- let __strQuote = null;
303
- let __regexQuoteStart = false;
304
- let __strTemplateExprStack = 0;
305
- let __strTemplateQuoteStack = 0;
306
- const inStringQuotes = () => __strQuote !== null;
307
- const inRegexQuotes = () => __regexQuoteStart;
308
- const inStrTemplateLiterals = () => __strTemplateQuoteStack > __strTemplateExprStack;
309
- const inStrTemplateExpr = () => __strTemplateQuoteStack > 0 && __strTemplateQuoteStack === __strTemplateExprStack;
310
- const inStringContent = () => inStringQuotes() || inStrTemplateLiterals();
311
- /**
312
- *
313
- * @param {string} token
314
- * @returns {number}
315
- */
316
- function classify(token) {
317
- const isLineBreak = token === "\n";
318
- if (inJsxTag()) {
319
- if (inStringQuotes()) return T_STRING;
320
- const [, lastToken] = last;
321
- if (isIdentifier(token)) {
322
- if (lastToken === "<" || lastToken === "</") return T_ENTITY;
323
- }
324
- }
325
- if (inJsxLiterals()) return T_JSX_LITERALS;
326
- if (inStringQuotes() || inStrTemplateLiterals()) return T_STRING;
327
- else if (resolvedTypeKeywords && resolvedTypeKeywords.has(token)) return last[1] === "." ? T_IDENTIFIER : T_CLS_NUMBER;
328
- else if (resolvedKeywords.has(token)) return last[1] === "." ? T_IDENTIFIER : T_KEYWORD;
329
- else if (isLineBreak) return T_BREAK;
330
- else if (isSpaces(token)) return T_SPACE;
331
- else if (token.split("").every(isSign)) return T_SIGN;
332
- else if (isCls(token)) return inJsxTag() ? T_IDENTIFIER : T_CLS_NUMBER;
333
- else {
334
- if (isIdentifier(token)) {
335
- const isLastPropDot = last[1] === "." && isIdentifier(beforeLast[1]);
336
- if (!inStringContent() && !isLastPropDot) return T_IDENTIFIER;
337
- if (isLastPropDot) return T_PROPERTY;
338
- }
339
- return T_STRING;
340
- }
341
- }
342
- /**
343
- *
344
- * @param {number | undefined} [type_]
345
- * @param {string | undefined} [token_]
346
- */
347
- const append = (type_, token_) => {
348
- if (token_) current = token_;
349
- if (current) {
350
- type = typeof type_ === "number" ? type_ : classify(current);
351
- /** @type [number, string] */
352
- const pair = [type, current];
353
- if (type !== T_SPACE && type !== T_BREAK) {
354
- beforeLast = last;
355
- last = pair;
356
- }
357
- tokens.push(pair);
358
- }
359
- current = "";
360
- };
361
- for (let i = 0; i < code.length; i++) {
362
- const curr = code[i];
363
- const prev = code[i - 1];
364
- const next = code[i + 1];
365
- const p_c = prev + curr;
366
- const c_n = curr + next;
367
- if (typeof mergedOptions.onQuote === "function" && curr === "'" && !inStringQuotes() && !inJsxLiterals() && !inStrTemplateLiterals()) {
368
- const rawLen = mergedOptions.onQuote(curr, i, code);
369
- if (typeof rawLen === "number" && rawLen >= 1 && !Number.isNaN(rawLen)) {
370
- const len = Math.min(rawLen, code.length - i);
371
- const end = i + len;
372
- append();
373
- current = code.slice(i, end);
374
- append(T_IDENTIFIER);
375
- i = end - 1;
376
- continue;
377
- }
378
- }
379
- if (isSingleQuotes(curr) && !inJsxLiterals() && !inStrTemplateLiterals()) {
380
- append();
381
- if (prev !== `\\`) {
382
- if (__strQuote && curr === __strQuote) __strQuote = null;
383
- else if (!__strQuote) __strQuote = curr;
384
- }
385
- append(T_STRING, curr);
386
- continue;
387
- }
388
- if (!inStrTemplateLiterals()) {
389
- if (prev !== "\\n" && isStrTemplateChr(curr)) {
390
- append();
391
- append(T_STRING, curr);
392
- __strTemplateQuoteStack++;
393
- continue;
394
- }
395
- }
396
- if (inStrTemplateLiterals()) {
397
- if (prev !== "\\n" && isStrTemplateChr(curr)) {
398
- if (__strTemplateQuoteStack > 0) {
399
- append();
400
- __strTemplateQuoteStack--;
401
- append(T_STRING, curr);
402
- continue;
403
- }
404
- }
405
- if (c_n === "${") {
406
- __strTemplateExprStack++;
407
- append(T_STRING);
408
- append(T_SIGN, c_n);
409
- i++;
410
- continue;
411
- }
412
- }
413
- if (inStrTemplateExpr() && curr === "}") {
414
- append();
415
- __strTemplateExprStack--;
416
- append(T_SIGN, curr);
417
- continue;
418
- }
419
- if (__jsxChild()) {
420
- if (curr === "{") {
421
- append();
422
- append(T_SIGN, curr);
423
- __jsxExpr = true;
424
- continue;
425
- }
426
- }
427
- if (__jsxEnter) {
428
- if (!__jsxTag && curr === "<") {
429
- append();
430
- if (next === "/") {
431
- __jsxTag = 2;
432
- current = c_n;
433
- i++;
434
- } else {
435
- __jsxTag = 1;
436
- current = curr;
437
- }
438
- append(T_SIGN);
439
- continue;
440
- }
441
- if (__jsxTag) {
442
- if (curr === ">" && !"/=".includes(prev)) {
443
- append();
444
- if (__jsxTag === 1) {
445
- __jsxTag = 0;
446
- __jsxStack++;
447
- } else {
448
- __jsxTag = 0;
449
- __jsxEnter = false;
450
- }
451
- append(T_SIGN, curr);
452
- continue;
453
- }
454
- if (c_n === "/>" || c_n === "</") {
455
- if (current !== "<" && current !== "/") append();
456
- if (c_n === "/>") __jsxTag = 0;
457
- else __jsxStack--;
458
- if (!__jsxStack) __jsxEnter = false;
459
- current = c_n;
460
- i++;
461
- append(T_SIGN);
462
- continue;
463
- }
464
- if (curr === "<") {
465
- append();
466
- current = curr;
467
- append(T_SIGN);
468
- continue;
469
- }
470
- if (next === "-" && !inStringContent() && !inJsxLiterals()) {
471
- if (current) {
472
- append(T_PROPERTY, current + curr + next);
473
- i++;
474
- continue;
475
- }
476
- }
477
- if (next === "=" && !inStringContent()) {
478
- if (!isSpaces(curr)) {
479
- if (isSpaces(current)) append();
480
- const prop = current + curr;
481
- if (isIdentifier(prop)) {
482
- append(T_PROPERTY, prop);
483
- continue;
484
- }
485
- }
486
- }
487
- }
488
- }
489
- if (!__jsxTag && (curr === "<" && isIdentifierChar(next) || c_n === "</")) {
490
- let prevNonSpace = i - 1;
491
- while (prevNonSpace >= 0 && /\s/.test(code[prevNonSpace])) prevNonSpace--;
492
- const prevChar = prevNonSpace >= 0 ? code[prevNonSpace] : "";
493
- const [lastType, lastTok] = last;
494
- let typeArgFromPending = false;
495
- let jsxFromPending = false;
496
- if (current && !isSpaces(current)) {
497
- const w = current;
498
- if (isCls(w) || w === "true" || w === "false") typeArgFromPending = true;
499
- else if (resolvedKeywords.has(w) && isIdentifier(w)) jsxFromPending = true;
500
- else if (isIdentifier(w)) typeArgFromPending = true;
501
- }
502
- const isTsTypeArgStart = curr === "<" && /[$\w\]\)]/.test(prevChar) && (typeArgFromPending || !jsxFromPending && (lastType === T_IDENTIFIER || lastType === T_CLS_NUMBER || lastType === T_SIGN && (lastTok === ")" || lastTok === "]")));
503
- const isTsGenericStart = curr === "<" && isTypeParameterListStart(code, i);
504
- if (!isTsTypeArgStart && !isTsGenericStart) __jsxTag = next === "/" ? 2 : 1;
505
- if (curr === "<" && (next === "/" || isAlpha(next))) {
506
- if (!isTsTypeArgStart && !isTsGenericStart && !inStringContent() && !inJsxLiterals() && !inRegexQuotes()) __jsxEnter = true;
507
- }
508
- }
509
- const isQuotationChar = isStringQuotation(curr);
510
- const isStringTemplateLiterals = inStrTemplateLiterals();
511
- const isRegexChar = !__jsxEnter && isRegexStart(c_n);
512
- const isJsxLiterals = inJsxLiterals();
513
- if (isQuotationChar || isStringTemplateLiterals || isSingleQuotes(__strQuote)) current += curr;
514
- else if (isRegexChar) {
515
- append();
516
- const [lastType, lastToken] = last;
517
- if (isRegexChar && lastType !== -1 && !(lastType === T_SIGN && ")" !== lastToken || lastType === T_COMMENT)) {
518
- current = curr;
519
- append();
520
- continue;
521
- }
522
- __regexQuoteStart = true;
523
- const start = i++;
524
- const isEof = () => i >= code.length;
525
- const isEol = () => isEof() || code[i] === "\n";
526
- let foundClose = false;
527
- for (; !isEol(); i++) if (code[i] === "/" && code[i - 1] !== "\\") {
528
- foundClose = true;
529
- while (start !== i && /^[a-z]$/.test(code[i + 1]) && !isEol()) i++;
530
- break;
531
- }
532
- __regexQuoteStart = false;
533
- if (start !== i && foundClose) {
534
- current = code.slice(start, i + 1);
535
- append(T_STRING);
536
- } else {
537
- current = curr;
538
- append();
539
- i = start;
540
- }
541
- } else if (onCommentStart(curr, next)) {
542
- append();
543
- const start = i;
544
- const startCommentType = onCommentStart(curr, next);
545
- if (startCommentType) {
546
- for (; i < code.length; i++) if (onCommentEnd(code[i - 1], code[i]) == startCommentType) break;
547
- }
548
- current = code.slice(start, i + 1);
549
- append(T_COMMENT);
550
- } else if (curr === " " || curr === "\n") if (curr === " " && (isSpaces(current) || !current || isJsxLiterals)) {
551
- current += curr;
552
- if (next === "<") append();
553
- } else {
554
- append();
555
- current = curr;
556
- append();
557
- }
558
- else if (__jsxExpr && curr === "}") {
559
- append();
560
- current = curr;
561
- append();
562
- __jsxExpr = false;
563
- } else if (isJsxLiterals && !JSXBrackets.has(curr) || inStrTemplateLiterals() || (isWord(curr) === isWord(current[current.length - 1]) || __jsxChild()) && !Signs.has(curr)) current += curr;
564
- else {
565
- if (p_c === "</") current = p_c;
566
- append();
567
- if (p_c !== "</") current = curr;
568
- if (c_n === "</" || c_n === "/>") {
569
- current = c_n;
570
- append();
571
- i++;
572
- } else if (JSXBrackets.has(curr)) append();
573
- }
574
- }
575
- append();
576
- return tokens;
577
- }
578
- /**
579
- * @param {Array<[number, string]>} tokens
580
- * @return {Array<{type: string, tagName: string, children: any[], properties: Record<string, string>}>}
581
- */
582
- function generate(tokens) {
583
- const lines = [];
584
- /**
585
- * @param {any} children
586
- * @return {{type: string, tagName: string, children: any[], properties: Record<string, string>}}
587
- */
588
- const createLine = (children) => ({
589
- type: "element",
590
- tagName: "span",
591
- children,
592
- properties: { className: "sh__line" }
593
- });
594
- /**
595
- * @param {Array<[number, string]>} tokens
596
- * @returns {void}
597
- */
598
- function flushLine(tokens) {
599
- /** @type {Array<any>} */
600
- const lineTokens = tokens.map(([type, value]) => {
601
- const tokenType = TokenTypes[type];
602
- return {
603
- type: "element",
604
- tagName: "span",
605
- children: [{
606
- type: "text",
607
- value
608
- }],
609
- properties: {
610
- className: `sh__token--${tokenType}`,
611
- style: { color: `var(--sh-${tokenType})` }
612
- }
613
- };
614
- });
615
- lines.push(createLine(lineTokens));
616
- }
617
- /** @type {Array<[number, string]>} */
618
- const lineTokens = [];
619
- let lastWasBreak = false;
620
- for (let i = 0; i < tokens.length; i++) {
621
- const token = tokens[i];
622
- const [type, value] = token;
623
- const isLastToken = i === tokens.length - 1;
624
- if (type !== T_BREAK) {
625
- if (value.includes("\n")) {
626
- const lines = value.split("\n");
627
- for (let j = 0; j < lines.length; j++) {
628
- lineTokens.push([type, lines[j]]);
629
- if (j < lines.length - 1) {
630
- flushLine(lineTokens);
631
- lineTokens.length = 0;
632
- }
633
- }
634
- } else lineTokens.push(token);
635
- lastWasBreak = false;
636
- } else {
637
- if (lastWasBreak) flushLine([]);
638
- else {
639
- flushLine(lineTokens);
640
- lineTokens.length = 0;
641
- }
642
- if (isLastToken) flushLine([]);
643
- lastWasBreak = true;
644
- }
645
- }
646
- if (lineTokens.length) flushLine(lineTokens);
647
- return lines;
648
- }
649
- /** @param {{ className: string, style?: Record<string, string> }} props */
650
- var propsToString = (props) => {
651
- let str = `class="${props.className}"`;
652
- if (props.style) {
653
- const style = Object.entries(props.style).map(([key, value]) => `${key}:${value}`).join(";");
654
- str += ` style="${style}"`;
655
- }
656
- return str;
657
- };
658
- function toHtml(lines) {
659
- return lines.map((line) => {
660
- const { tagName: lineTag } = line;
661
- const tokens = line.children.map((child) => {
662
- const { tagName, children, properties } = child;
663
- return `<${tagName} ${propsToString(properties)}>${encode(children[0].value)}</${tagName}>`;
664
- }).join("");
665
- return `<${lineTag} class="${line.properties.className}">${tokens}</${lineTag}>`;
666
- }).join("\n");
667
- }
668
- /**
669
- *
670
- * @param {string} code
671
- * @param {{
672
- * keywords?: Set<string>
673
- * typeKeywords?: Set<string>
674
- * onCommentStart?: (curr: string, next: string) => number | boolean
675
- * onCommentEnd?: (curr: string, prev: string) => number | boolean
676
- * onQuote?: (curr: string, i: number, code: string) => number | null | undefined
677
- * } | undefined} options
678
- * `onQuote` same as `tokenize`.
679
- * @returns {string}
680
- */
681
- function highlight(code, options) {
682
- return toHtml(generate(tokenize(code, options)));
683
- }
684
- /** @type {const} */ new Map(TokenTypes.map((type, i) => [type, i]));
685
- //#endregion
686
- //#region node_modules/.pnpm/sugar-high@1.1.0/node_modules/sugar-high/lib/presets/lang/css.js
687
- var css_exports = /* @__PURE__ */ __exportAll({
688
- keywords: () => keywords$5,
689
- onCommentEnd: () => onCommentEnd$2,
690
- onCommentStart: () => onCommentStart$2
691
- });
692
- var keywords$5 = new Set([
693
- "@media",
694
- "@import",
695
- "@keyframes",
696
- "@font-face",
697
- "@supports",
698
- "@page",
699
- "@counter-style",
700
- "@font-feature-values",
701
- "@viewport",
702
- "@counter-style",
703
- "@font-feature-values",
704
- "@document"
705
- ]);
706
- var onCommentStart$2 = (currentChar, nextChar) => {
707
- return "/*" === currentChar + nextChar ? 1 : 0;
708
- };
709
- var onCommentEnd$2 = (prevChar, currChar) => {
710
- return "*/" === prevChar + currChar ? 1 : 0;
711
- };
712
- //#endregion
713
- //#region node_modules/.pnpm/sugar-high@1.1.0/node_modules/sugar-high/lib/presets/lang/rust.js
714
- var rust_exports = /* @__PURE__ */ __exportAll({
715
- keywords: () => keywords$4,
716
- onQuote: () => onQuote
717
- });
718
- var keywords$4 = new Set([
719
- "as",
720
- "break",
721
- "const",
722
- "continue",
723
- "crate",
724
- "else",
725
- "enum",
726
- "extern",
727
- "false",
728
- "fn",
729
- "for",
730
- "if",
731
- "impl",
732
- "in",
733
- "let",
734
- "loop",
735
- "match",
736
- "mod",
737
- "move",
738
- "mut",
739
- "pub",
740
- "ref",
741
- "return",
742
- "self",
743
- "Self",
744
- "static",
745
- "struct",
746
- "super",
747
- "trait",
748
- "true",
749
- "type",
750
- "unsafe",
751
- "use",
752
- "where",
753
- "while",
754
- "async",
755
- "await",
756
- "dyn",
757
- "abstract",
758
- "become",
759
- "box",
760
- "do",
761
- "final",
762
- "macro",
763
- "override",
764
- "priv",
765
- "typeof",
766
- "unsized",
767
- "virtual",
768
- "yield",
769
- "try"
770
- ]);
771
- /**
772
- * @param {string} curr `code[i]` (apostrophe)
773
- * @param {number} i
774
- * @param {string} code
775
- * @returns {number} code units to consume from `i`
776
- */
777
- function onQuote(curr, i, code) {
778
- if (curr !== "'" || i + 1 >= code.length) return 1;
779
- const n1 = code[i + 1];
780
- if (n1 === "\\") {
781
- let j = i + 2;
782
- while (j < code.length) {
783
- if (code[j] === "\\") {
784
- j += 2;
785
- continue;
786
- }
787
- if (code[j] === "'") return j - i + 1;
788
- j++;
789
- }
790
- return code.length - i;
791
- }
792
- if (n1 === "_") return 2;
793
- if (/[a-zA-Z]/.test(n1)) {
794
- let j = i + 2;
795
- while (j < code.length && /[a-zA-Z0-9_]/.test(code[j])) j++;
796
- if (j < code.length && code[j] === "'") return j - i + 1;
797
- return j - i;
798
- }
799
- return 1;
800
- }
801
- //#endregion
802
- //#region node_modules/.pnpm/sugar-high@1.1.0/node_modules/sugar-high/lib/presets/lang/python.js
803
- var python_exports = /* @__PURE__ */ __exportAll({
804
- keywords: () => keywords$3,
805
- onCommentEnd: () => onCommentEnd$1,
806
- onCommentStart: () => onCommentStart$1
807
- });
808
- var keywords$3 = new Set([
809
- "and",
810
- "as",
811
- "assert",
812
- "async",
813
- "await",
814
- "break",
815
- "class",
816
- "continue",
817
- "def",
818
- "del",
819
- "elif",
820
- "else",
821
- "except",
822
- "finally",
823
- "for",
824
- "from",
825
- "global",
826
- "if",
827
- "import",
828
- "in",
829
- "is",
830
- "lambda",
831
- "nonlocal",
832
- "not",
833
- "or",
834
- "pass",
835
- "raise",
836
- "return",
837
- "try",
838
- "while",
839
- "with",
840
- "yield"
841
- ]);
842
- var onCommentStart$1 = (currentChar, _nextChar) => {
843
- return currentChar === "#" ? 1 : 0;
844
- };
845
- var onCommentEnd$1 = (_prevChar, currChar) => {
846
- return currChar === "\n" ? 1 : 0;
847
- };
848
- //#endregion
849
- //#region node_modules/.pnpm/sugar-high@1.1.0/node_modules/sugar-high/lib/presets/lang/clike-base.js
850
- var onCommentStart = (currentChar, nextChar) => {
851
- const pair = currentChar + nextChar;
852
- if (pair === "//") return 1;
853
- if (pair === "/*") return 1;
854
- return 0;
855
- };
856
- var onCommentEnd = (prevChar, currChar) => {
857
- if (currChar === "\n") return 1;
858
- return prevChar + currChar === "*/" ? 1 : 0;
859
- };
860
- //#endregion
861
- //#region node_modules/.pnpm/sugar-high@1.1.0/node_modules/sugar-high/lib/presets/lang/c.js
862
- var c_exports = /* @__PURE__ */ __exportAll({
863
- keywords: () => keywords$2,
864
- onCommentEnd: () => onCommentEnd,
865
- onCommentStart: () => onCommentStart,
866
- typeKeywords: () => typeKeywords$2
867
- });
868
- var typeKeywords$2 = new Set([
869
- "void",
870
- "char",
871
- "short",
872
- "int",
873
- "long",
874
- "float",
875
- "double",
876
- "signed",
877
- "unsigned",
878
- "_Bool",
879
- "_Complex",
880
- "_Imaginary"
881
- ]);
882
- var keywords$2 = new Set([
883
- "auto",
884
- "break",
885
- "case",
886
- "const",
887
- "continue",
888
- "default",
889
- "do",
890
- "else",
891
- "enum",
892
- "extern",
893
- "for",
894
- "goto",
895
- "if",
896
- "inline",
897
- "register",
898
- "restrict",
899
- "return",
900
- "sizeof",
901
- "static",
902
- "struct",
903
- "switch",
904
- "typedef",
905
- "union",
906
- "volatile",
907
- "while",
908
- "_Alignas",
909
- "_Alignof",
910
- "_Atomic",
911
- "_Generic",
912
- "_Noreturn",
913
- "_Static_assert",
914
- "_Thread_local"
915
- ]);
916
- //#endregion
917
- //#region node_modules/.pnpm/sugar-high@1.1.0/node_modules/sugar-high/lib/presets/lang/go.js
918
- var go_exports = /* @__PURE__ */ __exportAll({
919
- keywords: () => keywords$1,
920
- onCommentEnd: () => onCommentEnd,
921
- onCommentStart: () => onCommentStart,
922
- typeKeywords: () => typeKeywords$1
923
- });
924
- var typeKeywords$1 = new Set([
925
- "bool",
926
- "byte",
927
- "complex64",
928
- "complex128",
929
- "error",
930
- "float32",
931
- "float64",
932
- "int",
933
- "int8",
934
- "int16",
935
- "int32",
936
- "int64",
937
- "rune",
938
- "string",
939
- "uint",
940
- "uint8",
941
- "uint16",
942
- "uint32",
943
- "uint64",
944
- "uintptr"
945
- ]);
946
- var keywords$1 = new Set([
947
- "break",
948
- "case",
949
- "chan",
950
- "const",
951
- "continue",
952
- "default",
953
- "defer",
954
- "else",
955
- "fallthrough",
956
- "for",
957
- "func",
958
- "go",
959
- "goto",
960
- "if",
961
- "import",
962
- "interface",
963
- "map",
964
- "package",
965
- "range",
966
- "return",
967
- "select",
968
- "struct",
969
- "switch",
970
- "type",
971
- "var"
972
- ]);
973
- //#endregion
974
- //#region node_modules/.pnpm/sugar-high@1.1.0/node_modules/sugar-high/lib/presets/lang/java.js
975
- var java_exports = /* @__PURE__ */ __exportAll({
976
- keywords: () => keywords,
977
- onCommentEnd: () => onCommentEnd,
978
- onCommentStart: () => onCommentStart,
979
- typeKeywords: () => typeKeywords
980
- });
981
- var typeKeywords = new Set([
982
- "boolean",
983
- "byte",
984
- "char",
985
- "double",
986
- "float",
987
- "int",
988
- "long",
989
- "short",
990
- "void"
991
- ]);
992
- var keywords = new Set([
993
- "abstract",
994
- "assert",
995
- "break",
996
- "case",
997
- "catch",
998
- "class",
999
- "const",
1000
- "continue",
1001
- "default",
1002
- "do",
1003
- "else",
1004
- "enum",
1005
- "extends",
1006
- "final",
1007
- "finally",
1008
- "for",
1009
- "goto",
1010
- "if",
1011
- "implements",
1012
- "import",
1013
- "instanceof",
1014
- "interface",
1015
- "native",
1016
- "new",
1017
- "package",
1018
- "private",
1019
- "protected",
1020
- "public",
1021
- "return",
1022
- "static",
1023
- "strictfp",
1024
- "super",
1025
- "switch",
1026
- "synchronized",
1027
- "this",
1028
- "throw",
1029
- "throws",
1030
- "transient",
1031
- "try",
1032
- "volatile",
1033
- "while"
1034
- ]);
1035
- //#endregion
1036
- export { rust_exports as a, python_exports as i, go_exports as n, css_exports as o, c_exports as r, highlight as s, java_exports as t };