@kyyinfinite/zapo-message 0.0.0-stage → 1.0.1

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 (191) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/LICENSE +20 -0
  3. package/README.md +1401 -2
  4. package/build.config.json +28 -0
  5. package/dist/airich/airich.d.ts +180 -0
  6. package/dist/airich/airich.js +548 -0
  7. package/dist/airich/context.d.ts +24 -0
  8. package/dist/airich/context.js +48 -0
  9. package/dist/airich/encode.d.ts +3 -0
  10. package/dist/airich/encode.js +16 -0
  11. package/dist/airich/index.d.ts +20 -0
  12. package/dist/airich/index.js +11 -0
  13. package/dist/airich/inline.d.ts +45 -0
  14. package/dist/airich/inline.js +152 -0
  15. package/dist/airich/nodes.d.ts +30 -0
  16. package/dist/airich/nodes.js +121 -0
  17. package/dist/airich/primitives.d.ts +144 -0
  18. package/dist/airich/primitives.js +230 -0
  19. package/dist/airich/protocol.d.ts +35 -0
  20. package/dist/airich/protocol.js +65 -0
  21. package/dist/airich/table.d.ts +22 -0
  22. package/dist/airich/table.js +35 -0
  23. package/dist/airich/tokenizer.d.ts +13 -0
  24. package/dist/airich/tokenizer.js +717 -0
  25. package/dist/airich/transport.d.ts +15 -0
  26. package/dist/airich/transport.js +56 -0
  27. package/dist/branding.d.ts +5 -0
  28. package/dist/branding.js +9 -0
  29. package/dist/btn/builders.d.ts +246 -0
  30. package/dist/btn/builders.js +710 -0
  31. package/dist/btn/media-slot.d.ts +28 -0
  32. package/dist/btn/media-slot.js +323 -0
  33. package/dist/btn/media-source.d.ts +36 -0
  34. package/dist/btn/media-source.js +116 -0
  35. package/dist/btn/sharp-loader.d.ts +5 -0
  36. package/dist/btn/sharp-loader.js +18 -0
  37. package/dist/btn/thumbnail.d.ts +21 -0
  38. package/dist/btn/thumbnail.js +124 -0
  39. package/dist/btn/validators.d.ts +40 -0
  40. package/dist/btn/validators.js +135 -0
  41. package/dist/btn.d.ts +1 -0
  42. package/dist/btn.js +1 -0
  43. package/dist/core/async-send.d.ts +20 -0
  44. package/dist/core/async-send.js +1 -0
  45. package/dist/core/base-builder.d.ts +20 -0
  46. package/dist/core/base-builder.js +67 -0
  47. package/dist/core/errors.d.ts +30 -0
  48. package/dist/core/errors.js +61 -0
  49. package/dist/download.d.ts +24 -0
  50. package/dist/download.js +123 -0
  51. package/dist/index.d.ts +38 -0
  52. package/dist/index.js +22 -0
  53. package/dist/integration/augment.d.ts +97 -0
  54. package/dist/integration/augment.js +1 -0
  55. package/dist/integration/auto.d.ts +8 -0
  56. package/dist/integration/auto.js +79 -0
  57. package/dist/integration/index.d.ts +4 -0
  58. package/dist/integration/index.js +2 -0
  59. package/dist/integration/methods.d.ts +25 -0
  60. package/dist/integration/methods.js +24 -0
  61. package/dist/interactive.d.ts +24 -0
  62. package/dist/interactive.js +121 -0
  63. package/dist/media-gate.d.ts +99 -0
  64. package/dist/media-gate.js +322 -0
  65. package/dist/message/album.d.ts +33 -0
  66. package/dist/message/album.js +107 -0
  67. package/dist/message/contact.d.ts +29 -0
  68. package/dist/message/contact.js +123 -0
  69. package/dist/message/forward.d.ts +23 -0
  70. package/dist/message/forward.js +77 -0
  71. package/dist/message/index.d.ts +26 -0
  72. package/dist/message/index.js +13 -0
  73. package/dist/message/link-preview.d.ts +28 -0
  74. package/dist/message/link-preview.js +98 -0
  75. package/dist/message/location.d.ts +24 -0
  76. package/dist/message/location.js +94 -0
  77. package/dist/message/media.d.ts +90 -0
  78. package/dist/message/media.js +123 -0
  79. package/dist/message/poll.d.ts +24 -0
  80. package/dist/message/poll.js +98 -0
  81. package/dist/message/reaction.d.ts +20 -0
  82. package/dist/message/reaction.js +71 -0
  83. package/dist/message/sticker.d.ts +29 -0
  84. package/dist/message/sticker.js +44 -0
  85. package/dist/message/target.d.ts +18 -0
  86. package/dist/message/target.js +24 -0
  87. package/dist/message/text.d.ts +17 -0
  88. package/dist/message/text.js +29 -0
  89. package/dist/message/vcard.d.ts +9 -0
  90. package/dist/message/vcard.js +23 -0
  91. package/dist/message/webp.d.ts +6 -0
  92. package/dist/message/webp.js +57 -0
  93. package/dist/payloads.d.ts +180 -0
  94. package/dist/payloads.js +1 -0
  95. package/dist/serialize.d.ts +41 -0
  96. package/dist/serialize.js +93 -0
  97. package/dist/status.d.ts +3 -0
  98. package/dist/status.js +21 -0
  99. package/dist/zapo-client.d.ts +44 -0
  100. package/dist/zapo-client.js +1 -0
  101. package/examples/airich.ts +59 -0
  102. package/examples/buttons.ts +48 -0
  103. package/examples/client-methods.ts +58 -0
  104. package/examples/hybrid.ts +133 -0
  105. package/examples/serialize.ts +61 -0
  106. package/package.json +271 -4
  107. package/scripts/check-no-comments.mjs +101 -0
  108. package/scripts/compare-golden.mjs +461 -0
  109. package/scripts/lib-config.mjs +9 -0
  110. package/scripts/smoke-auto.mjs +75 -0
  111. package/scripts/test-external-consumer.mjs +316 -0
  112. package/scripts/verify-package.mjs +78 -0
  113. package/src/airich/airich.ts +970 -0
  114. package/src/airich/context.ts +96 -0
  115. package/src/airich/encode.ts +25 -0
  116. package/src/airich/index.ts +98 -0
  117. package/src/airich/inline.ts +272 -0
  118. package/src/airich/nodes.ts +174 -0
  119. package/src/airich/primitives.ts +474 -0
  120. package/src/airich/protocol.ts +133 -0
  121. package/src/airich/table.ts +70 -0
  122. package/src/airich/tokenizer.ts +799 -0
  123. package/src/airich/transport.ts +106 -0
  124. package/src/branding.ts +23 -0
  125. package/src/btn/builders.ts +1073 -0
  126. package/src/btn/media-slot.ts +486 -0
  127. package/src/btn/media-source.ts +189 -0
  128. package/src/btn/sharp-loader.ts +23 -0
  129. package/src/btn/thumbnail.ts +182 -0
  130. package/src/btn/validators.ts +237 -0
  131. package/src/btn.ts +8 -0
  132. package/src/core/async-send.ts +28 -0
  133. package/src/core/base-builder.ts +104 -0
  134. package/src/core/errors.ts +82 -0
  135. package/src/download.ts +212 -0
  136. package/src/index.ts +229 -0
  137. package/src/integration/augment.ts +262 -0
  138. package/src/integration/auto.ts +103 -0
  139. package/src/integration/index.ts +8 -0
  140. package/src/integration/methods.ts +45 -0
  141. package/src/interactive.ts +188 -0
  142. package/src/media-gate.ts +499 -0
  143. package/src/message/album.ts +187 -0
  144. package/src/message/contact.ts +170 -0
  145. package/src/message/forward.ts +123 -0
  146. package/src/message/index.ts +83 -0
  147. package/src/message/link-preview.ts +148 -0
  148. package/src/message/location.ts +150 -0
  149. package/src/message/media.ts +323 -0
  150. package/src/message/poll.ts +158 -0
  151. package/src/message/reaction.ts +133 -0
  152. package/src/message/sticker.ts +100 -0
  153. package/src/message/target.ts +38 -0
  154. package/src/message/text.ts +61 -0
  155. package/src/message/vcard.ts +36 -0
  156. package/src/message/webp.ts +78 -0
  157. package/src/payloads.ts +204 -0
  158. package/src/serialize.ts +180 -0
  159. package/src/status.ts +29 -0
  160. package/src/zapo-client.ts +84 -0
  161. package/test/airich-inline.test.ts +200 -0
  162. package/test/airich-primitives.test.ts +226 -0
  163. package/test/airich-tokenizer.test.ts +145 -0
  164. package/test/airich.golden.test.ts +406 -0
  165. package/test/airich.test.ts +1006 -0
  166. package/test/btn-button.test.ts +416 -0
  167. package/test/btn-header.test.ts +646 -0
  168. package/test/btn-legacy.test.ts +342 -0
  169. package/test/btn-lifecycle.test.ts +295 -0
  170. package/test/btn-list.test.ts +261 -0
  171. package/test/btn-media-source.test.ts +150 -0
  172. package/test/btn-thumbnail.test.ts +160 -0
  173. package/test/builder-compat.test.ts +264 -0
  174. package/test/helpers.ts +27 -0
  175. package/test/hybrid-airich.test.ts +345 -0
  176. package/test/hybrid-client.test.ts +239 -0
  177. package/test/hybrid-errors.test.ts +557 -0
  178. package/test/hybrid-interactive.test.ts +455 -0
  179. package/test/hybrid.golden.test.ts +349 -0
  180. package/test/hybrid.test.ts +479 -0
  181. package/test/integration-auto.test.ts +159 -0
  182. package/test/integration.fakeserver.test.ts +440 -0
  183. package/test/media-gate.test.ts +215 -0
  184. package/test/message-album.test.ts +145 -0
  185. package/test/message-builders.test.ts +401 -0
  186. package/test/message-media.test.ts +303 -0
  187. package/test/message.fakeserver.test.ts +284 -0
  188. package/test/message.golden.test.ts +254 -0
  189. package/test/serializer.test.ts +448 -0
  190. package/tsconfig.json +26 -0
  191. package/tsconfig.test.json +10 -0
@@ -0,0 +1,717 @@
1
+ const KEYWORDS_MAP = {
2
+ javascript: new Set([
3
+ "break",
4
+ "case",
5
+ "catch",
6
+ "continue",
7
+ "debugger",
8
+ "delete",
9
+ "do",
10
+ "else",
11
+ "finally",
12
+ "for",
13
+ "function",
14
+ "if",
15
+ "in",
16
+ "instanceof",
17
+ "new",
18
+ "return",
19
+ "switch",
20
+ "this",
21
+ "throw",
22
+ "try",
23
+ "typeof",
24
+ "var",
25
+ "void",
26
+ "while",
27
+ "with",
28
+ "true",
29
+ "false",
30
+ "null",
31
+ "undefined",
32
+ "class",
33
+ "const",
34
+ "let",
35
+ "super",
36
+ "extends",
37
+ "export",
38
+ "import",
39
+ "yield",
40
+ "static",
41
+ "constructor",
42
+ "async",
43
+ "await",
44
+ "get",
45
+ "set",
46
+ ]),
47
+ typescript: new Set([
48
+ "abstract",
49
+ "any",
50
+ "as",
51
+ "asserts",
52
+ "bigint",
53
+ "boolean",
54
+ "declare",
55
+ "enum",
56
+ "implements",
57
+ "infer",
58
+ "interface",
59
+ "is",
60
+ "keyof",
61
+ "module",
62
+ "namespace",
63
+ "never",
64
+ "readonly",
65
+ "require",
66
+ "number",
67
+ "object",
68
+ "override",
69
+ "private",
70
+ "protected",
71
+ "public",
72
+ "satisfies",
73
+ "string",
74
+ "symbol",
75
+ "type",
76
+ "unknown",
77
+ "using",
78
+ "from",
79
+ "break",
80
+ "case",
81
+ "catch",
82
+ "continue",
83
+ "do",
84
+ "else",
85
+ "finally",
86
+ "for",
87
+ "function",
88
+ "if",
89
+ "new",
90
+ "return",
91
+ "switch",
92
+ "this",
93
+ "throw",
94
+ "try",
95
+ "var",
96
+ "void",
97
+ "while",
98
+ "class",
99
+ "const",
100
+ "let",
101
+ "extends",
102
+ "import",
103
+ "export",
104
+ "async",
105
+ "await",
106
+ ]),
107
+ python: new Set([
108
+ "False",
109
+ "None",
110
+ "True",
111
+ "and",
112
+ "as",
113
+ "assert",
114
+ "async",
115
+ "await",
116
+ "break",
117
+ "class",
118
+ "continue",
119
+ "def",
120
+ "del",
121
+ "elif",
122
+ "else",
123
+ "except",
124
+ "finally",
125
+ "for",
126
+ "from",
127
+ "global",
128
+ "if",
129
+ "import",
130
+ "in",
131
+ "is",
132
+ "lambda",
133
+ "nonlocal",
134
+ "not",
135
+ "or",
136
+ "pass",
137
+ "raise",
138
+ "return",
139
+ "try",
140
+ "while",
141
+ "with",
142
+ "yield",
143
+ ]),
144
+ java: new Set([
145
+ "abstract",
146
+ "assert",
147
+ "boolean",
148
+ "break",
149
+ "byte",
150
+ "case",
151
+ "catch",
152
+ "char",
153
+ "class",
154
+ "const",
155
+ "continue",
156
+ "default",
157
+ "do",
158
+ "double",
159
+ "else",
160
+ "enum",
161
+ "extends",
162
+ "final",
163
+ "finally",
164
+ "float",
165
+ "for",
166
+ "goto",
167
+ "if",
168
+ "implements",
169
+ "import",
170
+ "instanceof",
171
+ "int",
172
+ "interface",
173
+ "long",
174
+ "native",
175
+ "new",
176
+ "package",
177
+ "private",
178
+ "protected",
179
+ "public",
180
+ "return",
181
+ "short",
182
+ "static",
183
+ "strictfp",
184
+ "super",
185
+ "switch",
186
+ "synchronized",
187
+ "this",
188
+ "throw",
189
+ "throws",
190
+ "transient",
191
+ "try",
192
+ "void",
193
+ "volatile",
194
+ "while",
195
+ ]),
196
+ golang: new Set([
197
+ "break",
198
+ "case",
199
+ "chan",
200
+ "const",
201
+ "continue",
202
+ "default",
203
+ "defer",
204
+ "else",
205
+ "fallthrough",
206
+ "for",
207
+ "func",
208
+ "go",
209
+ "goto",
210
+ "if",
211
+ "import",
212
+ "interface",
213
+ "map",
214
+ "package",
215
+ "range",
216
+ "return",
217
+ "select",
218
+ "struct",
219
+ "switch",
220
+ "type",
221
+ "var",
222
+ ]),
223
+ c: new Set([
224
+ "auto",
225
+ "break",
226
+ "case",
227
+ "char",
228
+ "const",
229
+ "continue",
230
+ "default",
231
+ "do",
232
+ "double",
233
+ "else",
234
+ "enum",
235
+ "extern",
236
+ "float",
237
+ "for",
238
+ "goto",
239
+ "if",
240
+ "int",
241
+ "long",
242
+ "register",
243
+ "return",
244
+ "short",
245
+ "signed",
246
+ "sizeof",
247
+ "static",
248
+ "struct",
249
+ "switch",
250
+ "typedef",
251
+ "union",
252
+ "unsigned",
253
+ "void",
254
+ "volatile",
255
+ "while",
256
+ ]),
257
+ cpp: new Set([
258
+ "alignas",
259
+ "alignof",
260
+ "and",
261
+ "auto",
262
+ "bool",
263
+ "break",
264
+ "case",
265
+ "catch",
266
+ "class",
267
+ "const",
268
+ "constexpr",
269
+ "continue",
270
+ "delete",
271
+ "do",
272
+ "double",
273
+ "else",
274
+ "enum",
275
+ "explicit",
276
+ "export",
277
+ "extern",
278
+ "false",
279
+ "float",
280
+ "for",
281
+ "friend",
282
+ "if",
283
+ "inline",
284
+ "int",
285
+ "long",
286
+ "mutable",
287
+ "namespace",
288
+ "new",
289
+ "noexcept",
290
+ "nullptr",
291
+ "operator",
292
+ "private",
293
+ "protected",
294
+ "public",
295
+ "return",
296
+ "short",
297
+ "signed",
298
+ "sizeof",
299
+ "static",
300
+ "struct",
301
+ "switch",
302
+ "template",
303
+ "this",
304
+ "throw",
305
+ "true",
306
+ "try",
307
+ "typedef",
308
+ "typename",
309
+ "union",
310
+ "unsigned",
311
+ "using",
312
+ "virtual",
313
+ "void",
314
+ "while",
315
+ ]),
316
+ php: new Set([
317
+ "abstract",
318
+ "and",
319
+ "array",
320
+ "as",
321
+ "break",
322
+ "callable",
323
+ "case",
324
+ "catch",
325
+ "class",
326
+ "clone",
327
+ "const",
328
+ "continue",
329
+ "declare",
330
+ "default",
331
+ "do",
332
+ "echo",
333
+ "else",
334
+ "elseif",
335
+ "empty",
336
+ "enddeclare",
337
+ "endfor",
338
+ "endforeach",
339
+ "endif",
340
+ "endswitch",
341
+ "endwhile",
342
+ "extends",
343
+ "final",
344
+ "finally",
345
+ "fn",
346
+ "for",
347
+ "foreach",
348
+ "function",
349
+ "global",
350
+ "goto",
351
+ "if",
352
+ "implements",
353
+ "include",
354
+ "include_once",
355
+ "instanceof",
356
+ "interface",
357
+ "match",
358
+ "namespace",
359
+ "new",
360
+ "null",
361
+ "or",
362
+ "private",
363
+ "protected",
364
+ "public",
365
+ "require",
366
+ "require_once",
367
+ "return",
368
+ "static",
369
+ "switch",
370
+ "throw",
371
+ "trait",
372
+ "try",
373
+ "use",
374
+ "var",
375
+ "while",
376
+ "yield",
377
+ ]),
378
+ rust: new Set([
379
+ "as",
380
+ "break",
381
+ "const",
382
+ "continue",
383
+ "crate",
384
+ "else",
385
+ "enum",
386
+ "extern",
387
+ "false",
388
+ "fn",
389
+ "for",
390
+ "if",
391
+ "impl",
392
+ "in",
393
+ "let",
394
+ "loop",
395
+ "match",
396
+ "mod",
397
+ "move",
398
+ "mut",
399
+ "pub",
400
+ "ref",
401
+ "return",
402
+ "self",
403
+ "Self",
404
+ "static",
405
+ "struct",
406
+ "super",
407
+ "trait",
408
+ "true",
409
+ "type",
410
+ "unsafe",
411
+ "use",
412
+ "where",
413
+ "while",
414
+ ]),
415
+ html: new Set([
416
+ "html",
417
+ "head",
418
+ "body",
419
+ "div",
420
+ "span",
421
+ "p",
422
+ "a",
423
+ "img",
424
+ "video",
425
+ "audio",
426
+ "script",
427
+ "style",
428
+ "link",
429
+ "meta",
430
+ "form",
431
+ "input",
432
+ "button",
433
+ "table",
434
+ "tr",
435
+ "td",
436
+ "th",
437
+ "ul",
438
+ "ol",
439
+ "li",
440
+ "section",
441
+ "article",
442
+ "header",
443
+ "footer",
444
+ "nav",
445
+ "main",
446
+ ]),
447
+ bash: new Set([
448
+ "if",
449
+ "then",
450
+ "else",
451
+ "elif",
452
+ "fi",
453
+ "for",
454
+ "while",
455
+ "do",
456
+ "done",
457
+ "case",
458
+ "esac",
459
+ "function",
460
+ "in",
461
+ "select",
462
+ "until",
463
+ "break",
464
+ "continue",
465
+ "return",
466
+ "export",
467
+ "readonly",
468
+ "local",
469
+ "declare",
470
+ ]),
471
+ markdown: new Set(["#", "##", "###", "####", "#####", "######"]),
472
+ };
473
+ const LANGUAGE_ALIASES = {
474
+ js: "javascript",
475
+ mjs: "javascript",
476
+ cjs: "javascript",
477
+ ts: "typescript",
478
+ py: "python",
479
+ python3: "python",
480
+ sh: "bash",
481
+ shell: "bash",
482
+ zsh: "bash",
483
+ go: "golang",
484
+ "c++": "cpp",
485
+ cc: "cpp",
486
+ cxx: "cpp",
487
+ htm: "html",
488
+ md: "markdown",
489
+ };
490
+ const BLOCK_COMMENT_OPEN = {
491
+ javascript: "/*",
492
+ typescript: "/*",
493
+ java: "/*",
494
+ c: "/*",
495
+ cpp: "/*",
496
+ php: "/*",
497
+ rust: "/*",
498
+ golang: "/*",
499
+ css: "/*",
500
+ };
501
+ const HASH_COMMENT_LANGS = new Set(["python", "bash"]);
502
+ const TYPE_MAP = {
503
+ 0: "DEFAULT",
504
+ 1: "KEYWORD",
505
+ 2: "METHOD",
506
+ 3: "STR",
507
+ 4: "NUMBER",
508
+ 5: "COMMENT",
509
+ };
510
+ const isWhitespace = (char) => /\s/.test(char);
511
+ export function tokenizeCode(code, lang = "javascript") {
512
+ const lower = String(lang ?? "").toLowerCase();
513
+ const norm = LANGUAGE_ALIASES[lower] ?? lower;
514
+ if (!norm || norm === "txt" || norm === "text" || norm === "plaintext") {
515
+ return {
516
+ codeBlock: [
517
+ {
518
+ codeContent: code,
519
+ highlightType: 0,
520
+ },
521
+ ],
522
+ unified_codeBlock: [
523
+ {
524
+ content: code,
525
+ type: "DEFAULT",
526
+ },
527
+ ],
528
+ };
529
+ }
530
+ const keywords = KEYWORDS_MAP[norm] ?? new Set();
531
+ const blockCommentOpen = BLOCK_COMMENT_OPEN[norm] ?? null;
532
+ const blockCommentClose = blockCommentOpen ? "*/" : null;
533
+ const tripleQuote = norm === "python" ? ['"""', "'''"] : null;
534
+ const tokens = [];
535
+ let i = 0;
536
+ const push = (content, type) => {
537
+ if (!content)
538
+ return;
539
+ const last = tokens[tokens.length - 1];
540
+ if (last && last.highlightType === type) {
541
+ last.codeContent += content;
542
+ }
543
+ else {
544
+ tokens.push({
545
+ codeContent: content,
546
+ highlightType: type,
547
+ });
548
+ }
549
+ };
550
+ const isIdentifier = (char) => {
551
+ switch (norm) {
552
+ case "css":
553
+ return /[a-zA-Z0-9_$-]/.test(char);
554
+ case "html":
555
+ return /[a-zA-Z0-9_$:-]/.test(char);
556
+ default:
557
+ return /[a-zA-Z0-9_$]/.test(char);
558
+ }
559
+ };
560
+ const startsWithAt = (needle, pos) => {
561
+ if (pos + needle.length > code.length)
562
+ return false;
563
+ return code.startsWith(needle, pos);
564
+ };
565
+ const scanUntil = (terminator, from) => {
566
+ let j = from;
567
+ while (j < code.length) {
568
+ if ((code[j] ?? "") === "\\" && j + 1 < code.length) {
569
+ j += 2;
570
+ continue;
571
+ }
572
+ if (startsWithAt(terminator, j))
573
+ return j + terminator.length;
574
+ j++;
575
+ }
576
+ return code.length;
577
+ };
578
+ while (i < code.length) {
579
+ const c = code[i] ?? "";
580
+ if (isWhitespace(c)) {
581
+ let s = i;
582
+ while (i < code.length && isWhitespace(code[i] ?? "")) {
583
+ i++;
584
+ }
585
+ push(code.slice(s, i), 0);
586
+ continue;
587
+ }
588
+ if (blockCommentOpen && startsWithAt(blockCommentOpen, i)) {
589
+ const end = code.indexOf(blockCommentClose, i + blockCommentOpen.length);
590
+ const stop = end === -1 ? code.length : end + blockCommentClose.length;
591
+ push(code.slice(i, stop), 5);
592
+ i = stop;
593
+ continue;
594
+ }
595
+ if (norm === "html" && startsWithAt("<!--", i)) {
596
+ const end = code.indexOf("-->", i + 4);
597
+ const stop = end === -1 ? code.length : end + 3;
598
+ push(code.slice(i, stop), 5);
599
+ i = stop;
600
+ continue;
601
+ }
602
+ if ((c === "/" && code[i + 1] === "/") ||
603
+ (c === "#" && HASH_COMMENT_LANGS.has(norm))) {
604
+ let s = i;
605
+ while (i < code.length && (code[i] ?? "") !== "\n") {
606
+ i++;
607
+ }
608
+ push(code.slice(s, i), 5);
609
+ continue;
610
+ }
611
+ if (tripleQuote &&
612
+ (startsWithAt(tripleQuote[0], i) || startsWithAt(tripleQuote[1], i))) {
613
+ const open = startsWithAt(tripleQuote[0], i)
614
+ ? tripleQuote[0]
615
+ : tripleQuote[1];
616
+ const stop = scanUntil(open, i + 3);
617
+ push(code.slice(i, stop), 3);
618
+ i = stop;
619
+ continue;
620
+ }
621
+ if (c === '"' || c === "'" || c === "`") {
622
+ let s = i;
623
+ const q = c;
624
+ i++;
625
+ while (i < code.length) {
626
+ if ((code[i] ?? "") === "\\" && i + 1 < code.length) {
627
+ i += 2;
628
+ }
629
+ else if ((code[i] ?? "") === q) {
630
+ i++;
631
+ break;
632
+ }
633
+ else {
634
+ i++;
635
+ }
636
+ }
637
+ push(code.slice(s, i), 3);
638
+ continue;
639
+ }
640
+ if (/[0-9]/.test(c)) {
641
+ let s = i;
642
+ if (c === "0" && /[xXbBoO]/.test(code[i + 1] ?? "")) {
643
+ const kind = (code[i + 1] ?? "").toLowerCase();
644
+ const digitRe = kind === "x" ? /[0-9a-fA-F]/ : kind === "b" ? /[01]/ : /[0-7]/;
645
+ i += 2;
646
+ while (i < code.length && digitRe.test(code[i] ?? "")) {
647
+ i++;
648
+ }
649
+ push(code.slice(s, i), 4);
650
+ continue;
651
+ }
652
+ while (i < code.length && /[0-9._]/.test(code[i] ?? "")) {
653
+ i++;
654
+ }
655
+ if (((code[i] ?? "") === "e" || (code[i] ?? "") === "E") &&
656
+ /[0-9]/.test(code[i + 1] ?? "")) {
657
+ i++;
658
+ while (i < code.length && /[0-9._]/.test(code[i] ?? "")) {
659
+ i++;
660
+ }
661
+ }
662
+ push(code.slice(s, i), 4);
663
+ continue;
664
+ }
665
+ if (/[a-zA-Z_$]/.test(c)) {
666
+ let s = i;
667
+ while (i < code.length && isIdentifier(code[i] ?? "")) {
668
+ i++;
669
+ }
670
+ const word = code.slice(s, i);
671
+ let type = 0;
672
+ if (keywords.has(word) ||
673
+ (norm === "html" && keywords.has(word.toLowerCase()))) {
674
+ type = 1;
675
+ }
676
+ else if (norm === "css") {
677
+ let j = i;
678
+ while (j < code.length && isWhitespace(code[j] ?? "")) {
679
+ j++;
680
+ }
681
+ if ((code[j] ?? "") === ":") {
682
+ type = 1;
683
+ }
684
+ }
685
+ else if (norm === "html") {
686
+ let p = s - 1;
687
+ while (p >= 0 && isWhitespace(code[p] ?? "")) {
688
+ p--;
689
+ }
690
+ if ((code[p] ?? "") === "<" ||
691
+ ((code[p] ?? "") === "/" && (code[p - 1] ?? "") === "<")) {
692
+ type = 1;
693
+ }
694
+ }
695
+ if (type === 0) {
696
+ let j = i;
697
+ while (j < code.length && isWhitespace(code[j] ?? "")) {
698
+ j++;
699
+ }
700
+ if ((code[j] ?? "") === "(") {
701
+ type = 2;
702
+ }
703
+ }
704
+ push(word, type);
705
+ continue;
706
+ }
707
+ push(c, 0);
708
+ i++;
709
+ }
710
+ return {
711
+ codeBlock: tokens,
712
+ unified_codeBlock: tokens.map((t) => ({
713
+ content: t.codeContent,
714
+ type: TYPE_MAP[t.highlightType] ?? "DEFAULT",
715
+ })),
716
+ };
717
+ }