erosolar-cli 1.7.13 → 1.7.15

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 (65) hide show
  1. package/dist/core/responseVerifier.d.ts +79 -0
  2. package/dist/core/responseVerifier.d.ts.map +1 -0
  3. package/dist/core/responseVerifier.js +443 -0
  4. package/dist/core/responseVerifier.js.map +1 -0
  5. package/dist/shell/interactiveShell.d.ts +5 -0
  6. package/dist/shell/interactiveShell.d.ts.map +1 -1
  7. package/dist/shell/interactiveShell.js +45 -14
  8. package/dist/shell/interactiveShell.js.map +1 -1
  9. package/dist/ui/ShellUIAdapter.d.ts +3 -0
  10. package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
  11. package/dist/ui/ShellUIAdapter.js +4 -10
  12. package/dist/ui/ShellUIAdapter.js.map +1 -1
  13. package/dist/ui/display.d.ts +15 -0
  14. package/dist/ui/display.d.ts.map +1 -1
  15. package/dist/ui/display.js +57 -0
  16. package/dist/ui/display.js.map +1 -1
  17. package/dist/ui/persistentPrompt.d.ts +4 -0
  18. package/dist/ui/persistentPrompt.d.ts.map +1 -1
  19. package/dist/ui/persistentPrompt.js +10 -11
  20. package/dist/ui/persistentPrompt.js.map +1 -1
  21. package/package.json +1 -1
  22. package/dist/bin/core/agent.js +0 -362
  23. package/dist/bin/core/agentProfileManifest.js +0 -187
  24. package/dist/bin/core/agentProfiles.js +0 -34
  25. package/dist/bin/core/agentRulebook.js +0 -135
  26. package/dist/bin/core/agentSchemaLoader.js +0 -233
  27. package/dist/bin/core/contextManager.js +0 -412
  28. package/dist/bin/core/contextWindow.js +0 -122
  29. package/dist/bin/core/customCommands.js +0 -80
  30. package/dist/bin/core/errors/apiKeyErrors.js +0 -114
  31. package/dist/bin/core/errors/errorTypes.js +0 -340
  32. package/dist/bin/core/errors/safetyValidator.js +0 -304
  33. package/dist/bin/core/errors.js +0 -32
  34. package/dist/bin/core/modelDiscovery.js +0 -755
  35. package/dist/bin/core/preferences.js +0 -224
  36. package/dist/bin/core/schemaValidator.js +0 -92
  37. package/dist/bin/core/secretStore.js +0 -199
  38. package/dist/bin/core/sessionStore.js +0 -187
  39. package/dist/bin/core/toolRuntime.js +0 -290
  40. package/dist/bin/core/types.js +0 -1
  41. package/dist/bin/shell/bracketedPasteManager.js +0 -350
  42. package/dist/bin/shell/fileChangeTracker.js +0 -65
  43. package/dist/bin/shell/interactiveShell.js +0 -2908
  44. package/dist/bin/shell/liveStatus.js +0 -78
  45. package/dist/bin/shell/shellApp.js +0 -290
  46. package/dist/bin/shell/systemPrompt.js +0 -60
  47. package/dist/bin/shell/updateManager.js +0 -108
  48. package/dist/bin/ui/ShellUIAdapter.js +0 -459
  49. package/dist/bin/ui/UnifiedUIController.js +0 -183
  50. package/dist/bin/ui/animation/AnimationScheduler.js +0 -430
  51. package/dist/bin/ui/codeHighlighter.js +0 -854
  52. package/dist/bin/ui/designSystem.js +0 -121
  53. package/dist/bin/ui/display.js +0 -1222
  54. package/dist/bin/ui/interrupts/InterruptManager.js +0 -437
  55. package/dist/bin/ui/layout.js +0 -139
  56. package/dist/bin/ui/orchestration/StatusOrchestrator.js +0 -403
  57. package/dist/bin/ui/outputMode.js +0 -38
  58. package/dist/bin/ui/persistentPrompt.js +0 -183
  59. package/dist/bin/ui/richText.js +0 -338
  60. package/dist/bin/ui/shortcutsHelp.js +0 -87
  61. package/dist/bin/ui/telemetry/UITelemetry.js +0 -443
  62. package/dist/bin/ui/textHighlighter.js +0 -210
  63. package/dist/bin/ui/theme.js +0 -116
  64. package/dist/bin/ui/toolDisplay.js +0 -423
  65. package/dist/bin/ui/toolDisplayAdapter.js +0 -357
@@ -1,854 +0,0 @@
1
- import { theme } from './theme.js';
2
- const identity = (value) => value;
3
- const LANGUAGE_ALIASES = {
4
- js: 'javascript',
5
- javascript: 'javascript',
6
- mjs: 'javascript',
7
- cjs: 'javascript',
8
- jsx: 'typescript',
9
- ts: 'typescript',
10
- tsx: 'typescript',
11
- typescript: 'typescript',
12
- py: 'python',
13
- python: 'python',
14
- bash: 'shell',
15
- sh: 'shell',
16
- shell: 'shell',
17
- zsh: 'shell',
18
- powershell: 'shell',
19
- go: 'go',
20
- rust: 'rust',
21
- rs: 'rust',
22
- rb: 'ruby',
23
- ruby: 'ruby',
24
- php: 'php',
25
- java: 'java',
26
- cs: 'csharp',
27
- csharp: 'csharp',
28
- dotnet: 'csharp',
29
- cpp: 'cpp',
30
- cxx: 'cpp',
31
- hpp: 'cpp',
32
- cc: 'cpp',
33
- c: 'c',
34
- swift: 'swift',
35
- kt: 'kotlin',
36
- kotlin: 'kotlin',
37
- sql: 'sql',
38
- postgres: 'sql',
39
- mysql: 'sql',
40
- sqlite: 'sql',
41
- json: 'json',
42
- jsonc: 'json',
43
- };
44
- const LANGUAGE_LABELS = {
45
- js: 'JS',
46
- javascript: 'JS',
47
- mjs: 'JS',
48
- cjs: 'JS',
49
- jsx: 'JSX',
50
- ts: 'TS',
51
- tsx: 'TSX',
52
- typescript: 'TS',
53
- py: 'PY',
54
- python: 'PY',
55
- bash: 'BASH',
56
- sh: 'SH',
57
- shell: 'BASH',
58
- zsh: 'ZSH',
59
- powershell: 'PS',
60
- go: 'GO',
61
- rust: 'RUST',
62
- rs: 'RUST',
63
- ruby: 'RUBY',
64
- rb: 'RB',
65
- php: 'PHP',
66
- java: 'JAVA',
67
- cs: 'C#',
68
- csharp: 'C#',
69
- dotnet: '.NET',
70
- cpp: 'C++',
71
- cxx: 'C++',
72
- hpp: 'C++',
73
- cc: 'C++',
74
- c: 'C',
75
- swift: 'SWIFT',
76
- kt: 'KOTLIN',
77
- kotlin: 'KOTLIN',
78
- sql: 'SQL',
79
- postgres: 'SQL',
80
- mysql: 'SQL',
81
- sqlite: 'SQL',
82
- json: 'JSON',
83
- jsonc: 'JSON',
84
- };
85
- const IDENTIFIER_START_C = /[A-Za-z_$]/;
86
- const IDENTIFIER_PART_C = /[A-Za-z0-9_$]/;
87
- const IDENTIFIER_START_ALPHA = /[A-Za-z_]/;
88
- const IDENTIFIER_PART_ALPHA = /[A-Za-z0-9_]/;
89
- const IDENTIFIER_PART_SHELL = /[A-Za-z0-9_\-]/;
90
- const COMMON_C_KEYWORDS = [
91
- 'const',
92
- 'let',
93
- 'var',
94
- 'function',
95
- 'return',
96
- 'if',
97
- 'else',
98
- 'switch',
99
- 'case',
100
- 'default',
101
- 'for',
102
- 'while',
103
- 'do',
104
- 'break',
105
- 'continue',
106
- 'class',
107
- 'extends',
108
- 'implements',
109
- 'new',
110
- 'this',
111
- 'super',
112
- 'try',
113
- 'catch',
114
- 'finally',
115
- 'throw',
116
- 'import',
117
- 'from',
118
- 'export',
119
- 'await',
120
- 'async',
121
- 'yield',
122
- 'static',
123
- 'public',
124
- 'private',
125
- 'protected',
126
- 'continue',
127
- 'break',
128
- 'typeof',
129
- 'instanceof',
130
- 'delete',
131
- 'in',
132
- 'of',
133
- ];
134
- const TYPESCRIPT_KEYWORDS = ['namespace', 'abstract', 'readonly', 'declare', 'keyof', 'infer', 'satisfies'];
135
- const JAVA_KEYWORDS = ['package', 'synchronized', 'volatile', 'transient', 'implements', 'extends', 'throws'];
136
- const CSHARP_KEYWORDS = [
137
- 'namespace',
138
- 'async',
139
- 'await',
140
- 'var',
141
- 'dynamic',
142
- 'lock',
143
- 'unsafe',
144
- 'checked',
145
- 'unchecked',
146
- 'partial',
147
- 'record',
148
- 'ref',
149
- 'when',
150
- 'where',
151
- ];
152
- const CPP_KEYWORDS = ['constexpr', 'typename', 'template', 'namespace', 'using', 'virtual', 'override', 'mutable', 'explicit', 'friend'];
153
- const GO_KEYWORDS = [
154
- 'package',
155
- 'import',
156
- 'var',
157
- 'const',
158
- 'func',
159
- 'struct',
160
- 'interface',
161
- 'map',
162
- 'chan',
163
- 'go',
164
- 'defer',
165
- 'select',
166
- 'range',
167
- 'fallthrough',
168
- 'type',
169
- ];
170
- const RUST_KEYWORDS = [
171
- 'fn',
172
- 'let',
173
- 'mut',
174
- 'impl',
175
- 'trait',
176
- 'struct',
177
- 'enum',
178
- 'pub',
179
- 'crate',
180
- 'super',
181
- 'use',
182
- 'move',
183
- 'match',
184
- 'ref',
185
- 'self',
186
- 'where',
187
- 'dyn',
188
- 'async',
189
- 'await',
190
- 'unsafe',
191
- 'extern',
192
- 'type',
193
- 'const',
194
- 'static',
195
- ];
196
- const PYTHON_KEYWORDS = [
197
- 'def',
198
- 'class',
199
- 'return',
200
- 'if',
201
- 'elif',
202
- 'else',
203
- 'for',
204
- 'while',
205
- 'break',
206
- 'continue',
207
- 'pass',
208
- 'import',
209
- 'from',
210
- 'as',
211
- 'try',
212
- 'except',
213
- 'finally',
214
- 'raise',
215
- 'with',
216
- 'lambda',
217
- 'yield',
218
- 'global',
219
- 'nonlocal',
220
- 'assert',
221
- 'del',
222
- 'and',
223
- 'or',
224
- 'not',
225
- 'is',
226
- 'in',
227
- ];
228
- const SHELL_KEYWORDS = ['if', 'then', 'fi', 'elif', 'else', 'for', 'while', 'in', 'do', 'done', 'case', 'esac', 'function', 'select', 'until', 'time'];
229
- const RUBY_KEYWORDS = [
230
- 'def',
231
- 'class',
232
- 'module',
233
- 'if',
234
- 'elsif',
235
- 'else',
236
- 'end',
237
- 'do',
238
- 'while',
239
- 'until',
240
- 'begin',
241
- 'rescue',
242
- 'ensure',
243
- 'case',
244
- 'when',
245
- 'yield',
246
- 'return',
247
- 'self',
248
- 'super',
249
- 'alias',
250
- 'undef',
251
- ];
252
- const PHP_KEYWORDS = [
253
- 'function',
254
- 'class',
255
- 'interface',
256
- 'trait',
257
- 'if',
258
- 'else',
259
- 'elseif',
260
- 'endif',
261
- 'foreach',
262
- 'endforeach',
263
- 'while',
264
- 'endwhile',
265
- 'do',
266
- 'switch',
267
- 'endswitch',
268
- 'case',
269
- 'break',
270
- 'continue',
271
- 'public',
272
- 'private',
273
- 'protected',
274
- 'static',
275
- 'abstract',
276
- 'final',
277
- 'namespace',
278
- 'use',
279
- 'as',
280
- 'return',
281
- 'throw',
282
- 'try',
283
- 'catch',
284
- 'finally',
285
- 'yield',
286
- ];
287
- const SQL_KEYWORDS = [
288
- 'select',
289
- 'from',
290
- 'where',
291
- 'insert',
292
- 'into',
293
- 'values',
294
- 'update',
295
- 'set',
296
- 'delete',
297
- 'create',
298
- 'table',
299
- 'drop',
300
- 'alter',
301
- 'join',
302
- 'left',
303
- 'right',
304
- 'inner',
305
- 'outer',
306
- 'group',
307
- 'by',
308
- 'order',
309
- 'limit',
310
- 'offset',
311
- 'having',
312
- 'union',
313
- 'on',
314
- 'as',
315
- 'and',
316
- 'or',
317
- 'not',
318
- 'null',
319
- 'is',
320
- 'like',
321
- 'in',
322
- 'case',
323
- 'when',
324
- 'then',
325
- 'end',
326
- 'distinct',
327
- 'exists',
328
- 'between',
329
- ];
330
- const COMMON_C_TYPES = ['string', 'number', 'boolean', 'any', 'never', 'void', 'null', 'undefined', 'Promise', 'Array', 'Record', 'Map', 'Set'];
331
- const GO_TYPES = ['string', 'int', 'int64', 'int32', 'bool', 'error', 'byte', 'rune', 'float64', 'float32', 'map', 'chan', 'interface', 'struct'];
332
- const RUST_TYPES = ['String', 'str', 'Vec', 'u8', 'u16', 'u32', 'u64', 'usize', 'i32', 'i64', 'Result', 'Option', 'Box'];
333
- const PYTHON_TYPES = ['int', 'float', 'str', 'list', 'dict', 'set', 'tuple', 'bool', 'Any'];
334
- const RUBY_TYPES = ['String', 'Array', 'Hash', 'Symbol', 'Integer', 'Float'];
335
- const PHP_TYPES = ['string', 'int', 'float', 'bool', 'array', 'callable', 'iterable', 'object', 'mixed', 'void', 'never'];
336
- const SQL_TYPES = ['int', 'integer', 'text', 'varchar', 'timestamp', 'date', 'json', 'boolean', 'serial', 'uuid'];
337
- const JS_BUILTINS = ['console', 'process', 'Math', 'Date', 'Promise', 'JSON', 'setTimeout', 'setInterval'];
338
- const PY_BUILTINS = ['print', 'len', 'range', 'list', 'dict', 'set', 'tuple', 'enumerate', 'zip', 'map', 'filter', 'sum'];
339
- const SHELL_BUILTINS = ['echo', 'cd', 'alias', 'export', 'local', 'readonly', 'return', 'function', 'trap', 'printf', 'test'];
340
- const GO_BUILTINS = ['make', 'len', 'cap', 'append', 'copy', 'panic', 'recover', 'new', 'print', 'println'];
341
- const RUST_BUILTINS = ['println', 'format', 'vec', 'dbg'];
342
- const RUBY_BUILTINS = ['puts', 'print', 'gets', 'attr_reader', 'attr_accessor', 'attr_writer'];
343
- const PHP_BUILTINS = ['echo', 'print', 'isset', 'empty', 'array_merge', 'count'];
344
- const JS_CONSTANTS = ['true', 'false', 'null', 'undefined', 'NaN', 'Infinity'];
345
- const PY_CONSTANTS = ['true', 'false', 'none'];
346
- const SHELL_CONSTANTS = ['true', 'false'];
347
- const GO_CONSTANTS = ['true', 'false', 'nil', 'iota'];
348
- const RUST_CONSTANTS = ['true', 'false', 'none', 'some', 'ok', 'err'];
349
- const RUBY_CONSTANTS = ['true', 'false', 'nil'];
350
- const PHP_CONSTANTS = ['true', 'false', 'null'];
351
- const SQL_CONSTANTS = ['true', 'false', 'null'];
352
- const LANGUAGE_PROFILES = {
353
- javascript: createProfile({
354
- keywords: [...COMMON_C_KEYWORDS],
355
- types: COMMON_C_TYPES,
356
- builtins: JS_BUILTINS,
357
- constants: JS_CONSTANTS,
358
- commentIndicators: ['//', '/*'],
359
- stringDelimiters: ['"', "'", '`'],
360
- identifierStart: IDENTIFIER_START_C,
361
- identifierPart: IDENTIFIER_PART_C,
362
- }),
363
- typescript: createProfile({
364
- keywords: [...COMMON_C_KEYWORDS, ...TYPESCRIPT_KEYWORDS],
365
- types: [...COMMON_C_TYPES, 'readonly', 'Pick', 'Partial'],
366
- builtins: JS_BUILTINS,
367
- constants: JS_CONSTANTS,
368
- commentIndicators: ['//', '/*'],
369
- stringDelimiters: ['"', "'", '`'],
370
- identifierStart: IDENTIFIER_START_C,
371
- identifierPart: IDENTIFIER_PART_C,
372
- decoratorPrefix: true,
373
- }),
374
- python: createProfile({
375
- keywords: PYTHON_KEYWORDS,
376
- types: PYTHON_TYPES,
377
- builtins: PY_BUILTINS,
378
- constants: PY_CONSTANTS,
379
- commentIndicators: ['#'],
380
- stringDelimiters: ['"', "'"],
381
- identifierStart: IDENTIFIER_START_ALPHA,
382
- identifierPart: IDENTIFIER_PART_ALPHA,
383
- decoratorPrefix: true,
384
- }),
385
- shell: createProfile({
386
- keywords: SHELL_KEYWORDS,
387
- builtins: SHELL_BUILTINS,
388
- constants: SHELL_CONSTANTS,
389
- commentIndicators: ['#'],
390
- stringDelimiters: ['"', "'"],
391
- identifierStart: IDENTIFIER_START_ALPHA,
392
- identifierPart: IDENTIFIER_PART_SHELL,
393
- highlightVariables: true,
394
- }),
395
- go: createProfile({
396
- keywords: GO_KEYWORDS,
397
- types: GO_TYPES,
398
- builtins: GO_BUILTINS,
399
- constants: GO_CONSTANTS,
400
- commentIndicators: ['//', '/*'],
401
- stringDelimiters: ['"', "'", '`'],
402
- identifierStart: IDENTIFIER_START_ALPHA,
403
- identifierPart: IDENTIFIER_PART_ALPHA,
404
- }),
405
- rust: createProfile({
406
- keywords: RUST_KEYWORDS,
407
- types: RUST_TYPES,
408
- builtins: RUST_BUILTINS,
409
- constants: RUST_CONSTANTS,
410
- commentIndicators: ['//'],
411
- stringDelimiters: ['"', "'"],
412
- identifierStart: IDENTIFIER_START_C,
413
- identifierPart: IDENTIFIER_PART_C,
414
- }),
415
- ruby: createProfile({
416
- keywords: RUBY_KEYWORDS,
417
- types: RUBY_TYPES,
418
- builtins: RUBY_BUILTINS,
419
- constants: RUBY_CONSTANTS,
420
- commentIndicators: ['#'],
421
- stringDelimiters: ['"', "'"],
422
- identifierStart: IDENTIFIER_START_ALPHA,
423
- identifierPart: IDENTIFIER_PART_ALPHA,
424
- }),
425
- php: createProfile({
426
- keywords: PHP_KEYWORDS,
427
- types: PHP_TYPES,
428
- builtins: PHP_BUILTINS,
429
- constants: PHP_CONSTANTS,
430
- commentIndicators: ['//', '#'],
431
- stringDelimiters: ['"', "'"],
432
- identifierStart: IDENTIFIER_START_ALPHA,
433
- identifierPart: IDENTIFIER_PART_ALPHA,
434
- highlightVariables: true,
435
- }),
436
- java: createProfile({
437
- keywords: [...COMMON_C_KEYWORDS, ...JAVA_KEYWORDS],
438
- types: [...COMMON_C_TYPES, 'int', 'long', 'float', 'double', 'boolean', 'char', 'String'],
439
- builtins: ['System', 'String', 'List', 'Map', 'Set'],
440
- constants: JS_CONSTANTS,
441
- commentIndicators: ['//', '/*'],
442
- stringDelimiters: ['"', "'"],
443
- identifierStart: IDENTIFIER_START_C,
444
- identifierPart: IDENTIFIER_PART_C,
445
- }),
446
- csharp: createProfile({
447
- keywords: [...COMMON_C_KEYWORDS, ...CSHARP_KEYWORDS],
448
- types: [...COMMON_C_TYPES, 'int', 'long', 'float', 'double', 'bool', 'string', 'Task'],
449
- builtins: ['Console', 'IEnumerable', 'List', 'Dictionary'],
450
- constants: JS_CONSTANTS,
451
- commentIndicators: ['//', '/*'],
452
- stringDelimiters: ['"', "'"],
453
- identifierStart: IDENTIFIER_START_C,
454
- identifierPart: IDENTIFIER_PART_C,
455
- decoratorPrefix: true,
456
- }),
457
- cpp: createProfile({
458
- keywords: [...COMMON_C_KEYWORDS, ...CPP_KEYWORDS],
459
- types: [...COMMON_C_TYPES, 'int', 'long', 'float', 'double', 'bool', 'char', 'std'],
460
- builtins: ['std', 'cout', 'cin'],
461
- constants: JS_CONSTANTS,
462
- commentIndicators: ['//', '/*'],
463
- stringDelimiters: ['"', "'"],
464
- identifierStart: IDENTIFIER_START_C,
465
- identifierPart: IDENTIFIER_PART_C,
466
- }),
467
- c: createProfile({
468
- keywords: [...COMMON_C_KEYWORDS],
469
- types: ['int', 'long', 'float', 'double', 'bool', 'char', 'size_t', 'uint32_t', 'uint64_t'],
470
- builtins: ['printf', 'scanf'],
471
- constants: JS_CONSTANTS,
472
- commentIndicators: ['//', '/*'],
473
- stringDelimiters: ['"', "'"],
474
- identifierStart: IDENTIFIER_START_C,
475
- identifierPart: IDENTIFIER_PART_C,
476
- }),
477
- swift: createProfile({
478
- keywords: [...COMMON_C_KEYWORDS, 'struct', 'protocol', 'extension', 'guard', 'defer'],
479
- types: [...COMMON_C_TYPES, 'Int', 'Float', 'Double', 'String', 'Bool'],
480
- builtins: ['print'],
481
- constants: JS_CONSTANTS,
482
- commentIndicators: ['//', '/*'],
483
- stringDelimiters: ['"'],
484
- identifierStart: IDENTIFIER_START_C,
485
- identifierPart: IDENTIFIER_PART_C,
486
- }),
487
- kotlin: createProfile({
488
- keywords: [...COMMON_C_KEYWORDS, 'fun', 'val', 'var', 'object', 'sealed', 'data', 'companion'],
489
- types: [...COMMON_C_TYPES, 'Int', 'Long', 'Float', 'Double', 'String', 'Boolean'],
490
- builtins: ['println', 'print'],
491
- constants: JS_CONSTANTS,
492
- commentIndicators: ['//', '/*'],
493
- stringDelimiters: ['"'],
494
- identifierStart: IDENTIFIER_START_C,
495
- identifierPart: IDENTIFIER_PART_C,
496
- }),
497
- sql: createProfile({
498
- keywords: SQL_KEYWORDS,
499
- types: SQL_TYPES,
500
- constants: SQL_CONSTANTS,
501
- commentIndicators: ['--', '#'],
502
- stringDelimiters: ['"', "'"],
503
- identifierStart: IDENTIFIER_START_ALPHA,
504
- identifierPart: IDENTIFIER_PART_ALPHA,
505
- }),
506
- };
507
- export function highlightAndWrapCode(code, language, width) {
508
- const normalized = normalizeLanguage(language);
509
- const profile = normalized?.id ? LANGUAGE_PROFILES[normalized.id] ?? null : null;
510
- const tokenizer = selectTokenizer(normalized?.id ?? null, profile);
511
- const available = Math.max(1, Number.isFinite(width) ? Math.floor(width) : 80);
512
- const sanitized = code.replace(/\t/g, ' ');
513
- const lines = [];
514
- for (const raw of sanitized.split('\n')) {
515
- const tokens = tokenizer(raw);
516
- const wrapped = wrapTokens(tokens, available);
517
- if (wrapped.length) {
518
- lines.push(...wrapped);
519
- }
520
- else {
521
- lines.push('');
522
- }
523
- }
524
- if (!lines.length) {
525
- lines.push('');
526
- }
527
- return {
528
- lines,
529
- languageLabel: normalized?.label ?? null,
530
- };
531
- }
532
- function normalizeLanguage(value) {
533
- if (!value) {
534
- return null;
535
- }
536
- const trimmed = value.trim();
537
- if (!trimmed) {
538
- return null;
539
- }
540
- const key = trimmed.toLowerCase();
541
- const id = LANGUAGE_ALIASES[key] ?? null;
542
- const label = LANGUAGE_LABELS[key] ?? (id ? LANGUAGE_LABELS[id] : undefined) ?? trimmed.toUpperCase();
543
- return { id, label };
544
- }
545
- function selectTokenizer(language, profile) {
546
- if (language === 'json') {
547
- return tokenizeJsonLine;
548
- }
549
- if (profile) {
550
- return tokenizeGenericLine(profile);
551
- }
552
- return (line) => (line.length ? [{ text: line }] : [{ text: '' }]);
553
- }
554
- function createProfile(config) {
555
- const profile = {
556
- keywords: toWordSet(config.keywords),
557
- commentIndicators: config.commentIndicators,
558
- stringDelimiters: config.stringDelimiters,
559
- identifierStart: config.identifierStart,
560
- identifierPart: config.identifierPart,
561
- };
562
- if (config.types) {
563
- profile.types = toWordSet(config.types);
564
- }
565
- if (config.builtins) {
566
- profile.builtins = toWordSet(config.builtins);
567
- }
568
- if (config.constants) {
569
- profile.constants = toWordSet(config.constants);
570
- }
571
- if (typeof config.decoratorPrefix === 'boolean') {
572
- profile.decoratorPrefix = config.decoratorPrefix;
573
- }
574
- if (typeof config.highlightVariables === 'boolean') {
575
- profile.highlightVariables = config.highlightVariables;
576
- }
577
- return profile;
578
- }
579
- function toWordSet(values) {
580
- return new Set(values.map((value) => value.toLowerCase()));
581
- }
582
- function tokenizeGenericLine(profile) {
583
- const commentIndicators = [...profile.commentIndicators].sort((a, b) => b.length - a.length);
584
- return (line) => {
585
- if (!line.length) {
586
- return [{ text: '' }];
587
- }
588
- const tokens = [];
589
- let index = 0;
590
- const push = (text, formatter) => {
591
- if (!text) {
592
- return;
593
- }
594
- tokens.push(formatter ? { text, formatter } : { text });
595
- };
596
- while (index < line.length) {
597
- const rest = line.slice(index);
598
- const comment = commentIndicators.find((indicator) => rest.startsWith(indicator));
599
- if (comment) {
600
- push(line.slice(index), theme.ui.muted);
601
- break;
602
- }
603
- const char = line.charAt(index);
604
- if (/\s/.test(char)) {
605
- const start = index;
606
- while (index < line.length && /\s/.test(line.charAt(index))) {
607
- index += 1;
608
- }
609
- push(line.slice(start, index));
610
- continue;
611
- }
612
- if (profile.highlightVariables && char === '$') {
613
- const span = readVariable(line, index, profile);
614
- push(span.text, theme.accent);
615
- index = span.next;
616
- continue;
617
- }
618
- if (profile.decoratorPrefix && char === '@') {
619
- const decorator = readIdentifier(line, index + 1, profile);
620
- push(`@${decorator.text}`, theme.accent);
621
- index = decorator.next;
622
- continue;
623
- }
624
- if (profile.stringDelimiters.includes(char)) {
625
- const literal = readString(line, index, char);
626
- push(literal.text, theme.secondary);
627
- index = literal.next;
628
- continue;
629
- }
630
- if (isNumberStart(line, index)) {
631
- const numberToken = readNumber(line, index);
632
- push(numberToken.text, theme.accent);
633
- index = numberToken.next;
634
- continue;
635
- }
636
- if (profile.identifierStart.test(char)) {
637
- const identifier = readIdentifier(line, index, profile);
638
- const formatter = pickIdentifierFormatter(identifier.text, profile);
639
- push(identifier.text, formatter);
640
- index = identifier.next;
641
- continue;
642
- }
643
- push(char);
644
- index += 1;
645
- }
646
- return tokens.length ? tokens : [{ text: '' }];
647
- };
648
- }
649
- function tokenizeJsonLine(line) {
650
- if (!line.length) {
651
- return [{ text: '' }];
652
- }
653
- const tokens = [];
654
- let index = 0;
655
- const push = (text, formatter) => {
656
- if (!text) {
657
- return;
658
- }
659
- tokens.push(formatter ? { text, formatter } : { text });
660
- };
661
- while (index < line.length) {
662
- const char = line.charAt(index);
663
- if (/\s/.test(char)) {
664
- const start = index;
665
- while (index < line.length && /\s/.test(line.charAt(index))) {
666
- index += 1;
667
- }
668
- push(line.slice(start, index));
669
- continue;
670
- }
671
- if (char === '"') {
672
- const literal = readString(line, index, '"');
673
- const isKey = isJsonKey(line, literal.next);
674
- push(literal.text, isKey ? theme.primary : theme.secondary);
675
- index = literal.next;
676
- continue;
677
- }
678
- if (char === '-' || /\d/.test(char)) {
679
- const numberToken = readNumber(line, index);
680
- push(numberToken.text, theme.accent);
681
- index = numberToken.next;
682
- continue;
683
- }
684
- const remaining = line.slice(index).toLowerCase();
685
- if (remaining.startsWith('true') || remaining.startsWith('false')) {
686
- const literal = remaining.startsWith('true') ? 'true' : 'false';
687
- push(line.slice(index, index + literal.length), theme.warning);
688
- index += literal.length;
689
- continue;
690
- }
691
- if (remaining.startsWith('null')) {
692
- push('null', theme.warning);
693
- index += 4;
694
- continue;
695
- }
696
- push(char);
697
- index += 1;
698
- }
699
- return tokens.length ? tokens : [{ text: '' }];
700
- }
701
- function isJsonKey(line, index) {
702
- for (let cursor = index; cursor < line.length; cursor += 1) {
703
- const char = line.charAt(cursor);
704
- if (char === ':') {
705
- return true;
706
- }
707
- if (!/\s/.test(char)) {
708
- return false;
709
- }
710
- }
711
- return false;
712
- }
713
- function wrapTokens(tokens, width) {
714
- const lines = [];
715
- let current = '';
716
- let used = 0;
717
- const flush = () => {
718
- lines.push(current);
719
- current = '';
720
- used = 0;
721
- };
722
- for (const token of tokens) {
723
- const formatter = token.formatter ?? identity;
724
- let remaining = token.text;
725
- if (!remaining) {
726
- continue;
727
- }
728
- while (remaining.length) {
729
- const available = Math.max(1, width - used);
730
- if (available <= 0) {
731
- flush();
732
- continue;
733
- }
734
- if (remaining.length <= available) {
735
- current += formatter(remaining);
736
- used += remaining.length;
737
- remaining = '';
738
- }
739
- else {
740
- const slice = remaining.slice(0, available);
741
- current += formatter(slice);
742
- used += slice.length;
743
- remaining = remaining.slice(available);
744
- flush();
745
- }
746
- }
747
- }
748
- if (current) {
749
- flush();
750
- }
751
- if (!lines.length) {
752
- lines.push('');
753
- }
754
- return lines;
755
- }
756
- function pickIdentifierFormatter(value, profile) {
757
- const lower = value.toLowerCase();
758
- if (profile.keywords.has(lower)) {
759
- return theme.primary;
760
- }
761
- if (profile.constants?.has(lower)) {
762
- return theme.warning;
763
- }
764
- if (profile.types?.has(lower)) {
765
- return theme.accent;
766
- }
767
- if (profile.builtins?.has(lower)) {
768
- return theme.secondary;
769
- }
770
- return undefined;
771
- }
772
- function readString(line, start, delimiter) {
773
- let index = start + 1;
774
- while (index < line.length) {
775
- const char = line.charAt(index);
776
- if (char === '\\') {
777
- index += 2;
778
- continue;
779
- }
780
- if (char === delimiter) {
781
- index += 1;
782
- break;
783
- }
784
- index += 1;
785
- }
786
- return { text: line.slice(start, index), next: index };
787
- }
788
- function readNumber(line, start) {
789
- let index = start;
790
- if (line.charAt(index) === '-' || line.charAt(index) === '+') {
791
- index += 1;
792
- }
793
- if (line.slice(index, index + 2).toLowerCase() === '0x') {
794
- index += 2;
795
- while (/[0-9a-fA-F_]/.test(line.charAt(index))) {
796
- index += 1;
797
- }
798
- return { text: line.slice(start, index), next: index };
799
- }
800
- while (/[0-9_]/.test(line.charAt(index))) {
801
- index += 1;
802
- }
803
- if (line.charAt(index) === '.' && /[0-9]/.test(line.charAt(index + 1))) {
804
- index += 1;
805
- while (/[0-9_]/.test(line.charAt(index))) {
806
- index += 1;
807
- }
808
- }
809
- if ((line.charAt(index) === 'e' || line.charAt(index) === 'E') && /[+\-0-9]/.test(line.charAt(index + 1))) {
810
- index += 1;
811
- if (line.charAt(index) === '+' || line.charAt(index) === '-') {
812
- index += 1;
813
- }
814
- while (/[0-9]/.test(line.charAt(index))) {
815
- index += 1;
816
- }
817
- }
818
- return { text: line.slice(start, index), next: index };
819
- }
820
- function isNumberStart(line, index) {
821
- const char = line.charAt(index);
822
- if (char === '-' || char === '+') {
823
- return /[0-9]/.test(line.charAt(index + 1));
824
- }
825
- return /[0-9]/.test(char);
826
- }
827
- function readIdentifier(line, start, profile) {
828
- let index = start;
829
- if (!profile.identifierStart.test(line.charAt(index))) {
830
- return { text: line.charAt(start), next: start + 1 };
831
- }
832
- index += 1;
833
- while (index < line.length && profile.identifierPart.test(line.charAt(index))) {
834
- index += 1;
835
- }
836
- return { text: line.slice(start, index), next: index };
837
- }
838
- function readVariable(line, start, profile) {
839
- if (line.charAt(start + 1) === '{') {
840
- let index = start + 2;
841
- while (index < line.length && line.charAt(index) !== '}') {
842
- index += 1;
843
- }
844
- if (line.charAt(index) === '}') {
845
- index += 1;
846
- }
847
- return { text: line.slice(start, index), next: index };
848
- }
849
- let index = start + 1;
850
- while (index < line.length && profile.identifierPart.test(line.charAt(index))) {
851
- index += 1;
852
- }
853
- return { text: line.slice(start, index), next: index };
854
- }