@shikijs/types 3.23.0 → 4.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.
package/dist/index.d.mts CHANGED
@@ -1,281 +1,282 @@
1
- import { Element, Root } from 'hast';
2
- import { OnigScanner, OnigString, IGrammar, IRawGrammar, IRawTheme, IRawThemeSetting, StateStack, FontStyle } from '@shikijs/vscode-textmate';
3
- export { IRawGrammar as RawGrammar, IRawTheme as RawTheme, IRawThemeSetting as RawThemeSetting } from '@shikijs/vscode-textmate';
1
+ import { Element, Root } from "hast";
2
+ import { FontStyle, IGrammar, IRawGrammar as RawGrammar, IRawTheme as RawTheme, IRawThemeSetting, IRawThemeSetting as RawThemeSetting, OnigScanner, OnigString, StateStack } from "@shikijs/vscode-textmate";
4
3
 
4
+ //#region src/utils.d.ts
5
5
  type Awaitable<T> = T | Promise<T>;
6
6
  type MaybeGetter<T> = Awaitable<MaybeModule<T>> | (() => Awaitable<MaybeModule<T>>);
7
7
  type MaybeModule<T> = T | {
8
- default: T;
8
+ default: T;
9
9
  };
10
10
  type MaybeArray<T> = T | T[];
11
11
  type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
12
- interface Nothing {
13
- }
12
+ interface Nothing {}
14
13
  /**
15
14
  * type StringLiteralUnion<'foo'> = 'foo' | string
16
15
  * This has auto completion whereas `'foo' | string` doesn't
17
16
  * Adapted from https://github.com/microsoft/TypeScript/issues/29729
18
17
  */
19
18
  type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
20
-
21
- interface PatternScanner extends OnigScanner {
22
- }
23
- interface RegexEngineString extends OnigString {
24
- }
19
+ //#endregion
20
+ //#region src/engines.d.ts
21
+ interface PatternScanner extends OnigScanner {}
22
+ interface RegexEngineString extends OnigString {}
25
23
  /**
26
24
  * Engine for RegExp matching and scanning.
27
25
  */
28
26
  interface RegexEngine {
29
- createScanner: (patterns: (string | RegExp)[]) => PatternScanner;
30
- createString: (s: string) => RegexEngineString;
27
+ createScanner: (patterns: (string | RegExp)[]) => PatternScanner;
28
+ createString: (s: string) => RegexEngineString;
31
29
  }
32
30
  interface WebAssemblyInstantiator {
33
- (importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined): Promise<WebAssemblyInstance>;
31
+ (importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined): Promise<WebAssemblyInstance>;
34
32
  }
35
33
  type WebAssemblyInstance = WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance | WebAssembly.Instance['exports'];
36
34
  type OnigurumaLoadOptions = {
37
- instantiator: WebAssemblyInstantiator;
35
+ instantiator: WebAssemblyInstantiator;
38
36
  } | {
39
- default: WebAssemblyInstantiator;
37
+ default: WebAssemblyInstantiator;
40
38
  } | {
41
- data: ArrayBufferView | ArrayBuffer | Response;
39
+ data: ArrayBufferView | ArrayBuffer | Response;
42
40
  };
43
41
  type LoadWasmOptionsPlain = OnigurumaLoadOptions | WebAssemblyInstantiator | ArrayBufferView | ArrayBuffer | Response;
44
42
  type LoadWasmOptions = Awaitable<LoadWasmOptionsPlain> | (() => Awaitable<LoadWasmOptionsPlain>);
45
-
43
+ //#endregion
44
+ //#region src/textmate.d.ts
46
45
  interface Grammar extends IGrammar {
47
- name: string;
46
+ name: string;
48
47
  }
49
-
48
+ //#endregion
49
+ //#region src/langs.d.ts
50
50
  type PlainTextLanguage = 'text' | 'plaintext' | 'txt' | 'plain';
51
51
  type AnsiLanguage = 'ansi';
52
52
  type SpecialLanguage = PlainTextLanguage | AnsiLanguage;
53
53
  type LanguageInput = MaybeGetter<MaybeArray<LanguageRegistration>>;
54
54
  type ResolveBundleKey<T extends string> = [T] extends [never] ? string : T;
55
- interface LanguageRegistration extends IRawGrammar {
56
- name: string;
57
- scopeName: string;
58
- displayName?: string;
59
- aliases?: string[];
60
- /**
61
- * A list of languages the current language embeds.
62
- * If manually specifying languages to load, make sure to load the embedded
63
- * languages for each parent language.
64
- */
65
- embeddedLangs?: string[];
66
- embeddedLanguages?: string[];
67
- /**
68
- * A list of languages that embed the current language.
69
- * Unlike `embeddedLangs`, the embedded languages will not be loaded automatically.
70
- */
71
- embeddedLangsLazy?: string[];
72
- balancedBracketSelectors?: string[];
73
- unbalancedBracketSelectors?: string[];
74
- foldingStopMarker?: string;
75
- foldingStartMarker?: string;
76
- /**
77
- * Inject this language to other scopes.
78
- * Same as `injectTo` in VSCode's `contributes.grammars`.
79
- *
80
- * @see https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars
81
- */
82
- injectTo?: string[];
55
+ interface LanguageRegistration extends RawGrammar {
56
+ name: string;
57
+ scopeName: string;
58
+ displayName?: string;
59
+ aliases?: string[];
60
+ /**
61
+ * A list of languages the current language embeds.
62
+ * If manually specifying languages to load, make sure to load the embedded
63
+ * languages for each parent language.
64
+ */
65
+ embeddedLangs?: string[];
66
+ embeddedLanguages?: string[];
67
+ /**
68
+ * A list of languages that embed the current language.
69
+ * Unlike `embeddedLangs`, the embedded languages will not be loaded automatically.
70
+ */
71
+ embeddedLangsLazy?: string[];
72
+ balancedBracketSelectors?: string[];
73
+ unbalancedBracketSelectors?: string[];
74
+ foldingStopMarker?: string;
75
+ foldingStartMarker?: string;
76
+ /**
77
+ * Inject this language to other scopes.
78
+ * Same as `injectTo` in VSCode's `contributes.grammars`.
79
+ *
80
+ * @see https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars
81
+ */
82
+ injectTo?: string[];
83
83
  }
84
84
  interface BundledLanguageInfo {
85
- id: string;
86
- name: string;
87
- import: DynamicImportLanguageRegistration;
88
- aliases?: string[];
85
+ id: string;
86
+ name: string;
87
+ import: DynamicImportLanguageRegistration;
88
+ aliases?: string[];
89
89
  }
90
90
  type DynamicImportLanguageRegistration = () => Promise<{
91
- default: LanguageRegistration[];
91
+ default: LanguageRegistration[];
92
92
  }>;
93
-
93
+ //#endregion
94
+ //#region src/decorations.d.ts
94
95
  interface DecorationOptions {
95
- /**
96
- * Custom decorations to wrap highlighted tokens with.
97
- */
98
- decorations?: DecorationItem[];
96
+ /**
97
+ * Custom decorations to wrap highlighted tokens with.
98
+ */
99
+ decorations?: DecorationItem[];
99
100
  }
100
101
  interface DecorationItem {
101
- /**
102
- * Start offset or position of the decoration.
103
- */
104
- start: OffsetOrPosition;
105
- /**
106
- * End offset or position of the decoration.
107
- */
108
- end: OffsetOrPosition;
109
- /**
110
- * Tag name of the element to create.
111
- * @default 'span'
112
- */
113
- tagName?: string;
114
- /**
115
- * Properties of the element to create.
116
- */
117
- properties?: Element['properties'];
118
- /**
119
- * A custom function to transform the element after it has been created.
120
- */
121
- transform?: (element: Element, type: DecorationTransformType) => Element | void;
122
- /**
123
- * By default when the decoration contains only one token, the decoration will be applied to the token.
124
- *
125
- * Set to `true` to always wrap the token with a new element
126
- *
127
- * @default false
128
- */
129
- alwaysWrap?: boolean;
102
+ /**
103
+ * Start offset or position of the decoration.
104
+ */
105
+ start: OffsetOrPosition;
106
+ /**
107
+ * End offset or position of the decoration.
108
+ */
109
+ end: OffsetOrPosition;
110
+ /**
111
+ * Tag name of the element to create.
112
+ * @default 'span'
113
+ */
114
+ tagName?: string;
115
+ /**
116
+ * Properties of the element to create.
117
+ */
118
+ properties?: Element['properties'];
119
+ /**
120
+ * A custom function to transform the element after it has been created.
121
+ */
122
+ transform?: (element: Element, type: DecorationTransformType) => Element | void;
123
+ /**
124
+ * By default when the decoration contains only one token, the decoration will be applied to the token.
125
+ *
126
+ * Set to `true` to always wrap the token with a new element
127
+ *
128
+ * @default false
129
+ */
130
+ alwaysWrap?: boolean;
130
131
  }
131
132
  interface ResolvedDecorationItem extends Omit<DecorationItem, 'start' | 'end'> {
132
- start: ResolvedPosition;
133
- end: ResolvedPosition;
133
+ start: ResolvedPosition;
134
+ end: ResolvedPosition;
134
135
  }
135
136
  type DecorationTransformType = 'wrapper' | 'line' | 'token';
136
137
  interface Position {
137
- line: number;
138
- character: number;
138
+ line: number;
139
+ character: number;
139
140
  }
140
141
  type Offset = number;
141
142
  type OffsetOrPosition = Position | Offset;
142
143
  interface ResolvedPosition extends Position {
143
- offset: Offset;
144
+ offset: Offset;
144
145
  }
145
-
146
+ //#endregion
147
+ //#region src/themes.d.ts
146
148
  type SpecialTheme = 'none';
147
149
  type ThemeInput = MaybeGetter<ThemeRegistrationAny>;
148
- interface ThemeRegistrationRaw extends IRawTheme, Partial<Omit<ThemeRegistration, 'name' | 'settings'>> {
149
- }
150
- interface ThemeRegistration extends Partial<ThemeRegistrationResolved> {
151
- }
152
- interface ThemeRegistrationResolved extends IRawTheme {
153
- /**
154
- * Theme name
155
- */
156
- name: string;
157
- /**
158
- * Display name
159
- *
160
- * @field shiki custom property
161
- */
162
- displayName?: string;
163
- /**
164
- * Light/dark theme
165
- *
166
- * @field shiki custom property
167
- */
168
- type: 'light' | 'dark';
169
- /**
170
- * Token rules
171
- */
172
- settings: IRawThemeSetting[];
173
- /**
174
- * Same as `settings`, will use as fallback if `settings` is not present.
175
- */
176
- tokenColors?: IRawThemeSetting[];
177
- /**
178
- * Default foreground color
179
- *
180
- * @field shiki custom property
181
- */
182
- fg: string;
183
- /**
184
- * Background color
185
- *
186
- * @field shiki custom property
187
- */
188
- bg: string;
189
- /**
190
- * A map of color names to new color values.
191
- *
192
- * The color key starts with '#' and should be lowercased.
193
- *
194
- * @field shiki custom property
195
- */
196
- colorReplacements?: Record<string, string>;
197
- /**
198
- * Color map of VS Code options
199
- *
200
- * Will be used by shiki on `lang: 'ansi'` to find ANSI colors, and to find the default foreground/background colors.
201
- */
202
- colors?: Record<string, string>;
203
- /**
204
- * JSON schema path
205
- *
206
- * @field not used by shiki
207
- */
208
- $schema?: string;
209
- /**
210
- * Enable semantic highlighting
211
- *
212
- * @field not used by shiki
213
- */
214
- semanticHighlighting?: boolean;
215
- /**
216
- * Tokens for semantic highlighting
217
- *
218
- * @field not used by shiki
219
- */
220
- semanticTokenColors?: Record<string, string>;
150
+ interface ThemeRegistrationRaw extends RawTheme, Partial<Omit<ThemeRegistration, 'name' | 'settings'>> {}
151
+ interface ThemeRegistration extends Partial<ThemeRegistrationResolved> {}
152
+ interface ThemeRegistrationResolved extends RawTheme {
153
+ /**
154
+ * Theme name
155
+ */
156
+ name: string;
157
+ /**
158
+ * Display name
159
+ *
160
+ * @field shiki custom property
161
+ */
162
+ displayName?: string;
163
+ /**
164
+ * Light/dark theme
165
+ *
166
+ * @field shiki custom property
167
+ */
168
+ type: 'light' | 'dark';
169
+ /**
170
+ * Token rules
171
+ */
172
+ settings: RawThemeSetting[];
173
+ /**
174
+ * Same as `settings`, will use as fallback if `settings` is not present.
175
+ */
176
+ tokenColors?: RawThemeSetting[];
177
+ /**
178
+ * Default foreground color
179
+ *
180
+ * @field shiki custom property
181
+ */
182
+ fg: string;
183
+ /**
184
+ * Background color
185
+ *
186
+ * @field shiki custom property
187
+ */
188
+ bg: string;
189
+ /**
190
+ * A map of color names to new color values.
191
+ *
192
+ * The color key starts with '#' and should be lowercased.
193
+ *
194
+ * @field shiki custom property
195
+ */
196
+ colorReplacements?: Record<string, string>;
197
+ /**
198
+ * Color map of VS Code options
199
+ *
200
+ * Will be used by shiki on `lang: 'ansi'` to find ANSI colors, and to find the default foreground/background colors.
201
+ */
202
+ colors?: Record<string, string>;
203
+ /**
204
+ * JSON schema path
205
+ *
206
+ * @field not used by shiki
207
+ */
208
+ $schema?: string;
209
+ /**
210
+ * Enable semantic highlighting
211
+ *
212
+ * @field not used by shiki
213
+ */
214
+ semanticHighlighting?: boolean;
215
+ /**
216
+ * Tokens for semantic highlighting
217
+ *
218
+ * @field not used by shiki
219
+ */
220
+ semanticTokenColors?: Record<string, string>;
221
221
  }
222
222
  type ThemeRegistrationAny = ThemeRegistrationRaw | ThemeRegistration | ThemeRegistrationResolved;
223
223
  type DynamicImportThemeRegistration = () => Promise<{
224
- default: ThemeRegistration;
224
+ default: ThemeRegistration;
225
225
  }>;
226
226
  interface BundledThemeInfo {
227
- id: string;
228
- displayName: string;
229
- type: 'light' | 'dark';
230
- import: DynamicImportThemeRegistration;
227
+ id: string;
228
+ displayName: string;
229
+ type: 'light' | 'dark';
230
+ import: DynamicImportThemeRegistration;
231
231
  }
232
-
232
+ //#endregion
233
+ //#region src/tokens.d.ts
233
234
  /**
234
235
  * GrammarState is a special reference object that holds the state of a grammar.
235
236
  *
236
237
  * It's used to highlight code snippets that are part of the target language.
237
238
  */
238
239
  interface GrammarState {
239
- readonly lang: string;
240
- readonly theme: string;
241
- readonly themes: string[];
242
- /**
243
- * @internal
244
- */
245
- getInternalStack: (theme?: string) => StateStack | undefined;
246
- getScopes: (theme?: string) => string[] | undefined;
240
+ readonly lang: string;
241
+ readonly theme: string;
242
+ readonly themes: string[];
243
+ /**
244
+ * @internal
245
+ */
246
+ getInternalStack: (theme?: string) => StateStack | undefined;
247
+ getScopes: (theme?: string) => string[] | undefined;
247
248
  }
248
249
  interface CodeToTokensBaseOptions<Languages extends string = string, Themes extends string = string> extends TokenizeWithThemeOptions {
249
- lang?: Languages | SpecialLanguage;
250
- theme?: Themes | ThemeRegistrationAny | SpecialTheme;
250
+ lang?: Languages | SpecialLanguage;
251
+ theme?: Themes | ThemeRegistrationAny | SpecialTheme;
251
252
  }
252
253
  type CodeToTokensOptions<Languages extends string = string, Themes extends string = string> = Omit<CodeToTokensBaseOptions<Languages, Themes>, 'theme'> & CodeOptionsThemes<Themes>;
253
254
  interface CodeToTokensWithThemesOptions<Languages = string, Themes = string> extends TokenizeWithThemeOptions {
254
- lang?: Languages | SpecialLanguage;
255
- /**
256
- * A map of color names to themes.
257
- *
258
- * `light` and `dark` are required, and arbitrary color names can be added.
259
- *
260
- * @example
261
- * ```ts
262
- * themes: {
263
- * light: 'vitesse-light',
264
- * dark: 'vitesse-dark',
265
- * soft: 'nord',
266
- * // custom colors
267
- * }
268
- * ```
269
- */
270
- themes: Partial<Record<string, Themes | ThemeRegistrationAny | SpecialTheme>>;
255
+ lang?: Languages | SpecialLanguage;
256
+ /**
257
+ * A map of color names to themes.
258
+ *
259
+ * `light` and `dark` are required, and arbitrary color names can be added.
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * themes: {
264
+ * light: 'vitesse-light',
265
+ * dark: 'vitesse-dark',
266
+ * soft: 'nord',
267
+ * // custom colors
268
+ * }
269
+ * ```
270
+ */
271
+ themes: Partial<Record<string, Themes | ThemeRegistrationAny | SpecialTheme>>;
271
272
  }
272
273
  interface ThemedTokenScopeExplanation {
273
- scopeName: string;
274
- themeMatches?: IRawThemeSetting[];
274
+ scopeName: string;
275
+ themeMatches?: IRawThemeSetting[];
275
276
  }
276
277
  interface ThemedTokenExplanation {
277
- content: string;
278
- scopes: ThemedTokenScopeExplanation[];
278
+ content: string;
279
+ scopes: ThemedTokenScopeExplanation[];
279
280
  }
280
281
  /**
281
282
  * A single token with color, and optionally with explanation.
@@ -331,414 +332,415 @@ interface ThemedTokenExplanation {
331
332
  * }
332
333
  * ```
333
334
  */
334
- interface ThemedToken extends TokenStyles, TokenBase {
335
- }
335
+ interface ThemedToken extends TokenStyles, TokenBase {}
336
336
  interface TokenBase {
337
- /**
338
- * The content of the token
339
- */
340
- content: string;
341
- /**
342
- * The start offset of the token, relative to the input code. 0-indexed.
343
- */
344
- offset: number;
345
- /**
346
- * Explanation of
347
- *
348
- * - token text's matching scopes
349
- * - reason that token text is given a color (one matching scope matches a rule (scope -> color) in the theme)
350
- */
351
- explanation?: ThemedTokenExplanation[];
337
+ /**
338
+ * The content of the token
339
+ */
340
+ content: string;
341
+ /**
342
+ * The start offset of the token, relative to the input code. 0-indexed.
343
+ */
344
+ offset: number;
345
+ /**
346
+ * Explanation of
347
+ *
348
+ * - token text's matching scopes
349
+ * - reason that token text is given a color (one matching scope matches a rule (scope -> color) in the theme)
350
+ */
351
+ explanation?: ThemedTokenExplanation[];
352
352
  }
353
353
  interface TokenStyles {
354
- /**
355
- * 6 or 8 digit hex code representation of the token's color
356
- */
357
- color?: string;
358
- /**
359
- * 6 or 8 digit hex code representation of the token's background color
360
- */
361
- bgColor?: string;
362
- /**
363
- * Font style of token. Can be None/Italic/Bold/Underline
364
- */
365
- fontStyle?: FontStyle;
366
- /**
367
- * Override with custom inline style for HTML renderer.
368
- * When specified, `color` and `fontStyle` will be ignored.
369
- * Prefer use object style for merging with other styles.
370
- */
371
- htmlStyle?: Record<string, string>;
372
- /**
373
- * Extra HTML attributes for the token.
374
- */
375
- htmlAttrs?: Record<string, string>;
354
+ /**
355
+ * 6 or 8 digit hex code representation of the token's color
356
+ */
357
+ color?: string;
358
+ /**
359
+ * 6 or 8 digit hex code representation of the token's background color
360
+ */
361
+ bgColor?: string;
362
+ /**
363
+ * Font style of token. Can be None/Italic/Bold/Underline
364
+ */
365
+ fontStyle?: FontStyle;
366
+ /**
367
+ * Override with custom inline style for HTML renderer.
368
+ * When specified, `color` and `fontStyle` will be ignored.
369
+ * Prefer use object style for merging with other styles.
370
+ */
371
+ htmlStyle?: Record<string, string>;
372
+ /**
373
+ * Extra HTML attributes for the token.
374
+ */
375
+ htmlAttrs?: Record<string, string>;
376
376
  }
377
377
  interface ThemedTokenWithVariants extends TokenBase {
378
- /**
379
- * An object of color name to token styles
380
- */
381
- variants: Record<string, TokenStyles>;
378
+ /**
379
+ * An object of color name to token styles
380
+ */
381
+ variants: Record<string, TokenStyles>;
382
382
  }
383
383
  interface TokenizeWithThemeOptions {
384
- /**
385
- * Include explanation of why a token is given a color.
386
- *
387
- * You can optionally pass `scopeName` to only include explanation for scopes,
388
- * which is more performant than full explanation.
389
- *
390
- * @default false
391
- */
392
- includeExplanation?: boolean | 'scopeName';
393
- /**
394
- * A map of color names to new color values.
395
- *
396
- * The color key starts with '#' and should be lowercased.
397
- *
398
- * This will be merged with theme's `colorReplacements` if any.
399
- */
400
- colorReplacements?: Record<string, string | Record<string, string>>;
401
- /**
402
- * Lines above this length will not be tokenized for performance reasons.
403
- *
404
- * @default 0 (no limit)
405
- */
406
- tokenizeMaxLineLength?: number;
407
- /**
408
- * Time limit in milliseconds for tokenizing a single line.
409
- *
410
- * @default 500 (0.5s)
411
- */
412
- tokenizeTimeLimit?: number;
413
- /**
414
- * Represent the state of the grammar, allowing to continue tokenizing from a intermediate grammar state.
415
- *
416
- * You can get the grammar state from `getLastGrammarState`.
417
- */
418
- grammarState?: GrammarState;
419
- /**
420
- * The code context of the grammar.
421
- * Consider it a prepended code to the input code, that only participate the grammar inference but not presented in the final output.
422
- *
423
- * This will be ignored if `grammarState` is provided.
424
- */
425
- grammarContextCode?: string;
384
+ /**
385
+ * Include explanation of why a token is given a color.
386
+ *
387
+ * You can optionally pass `scopeName` to only include explanation for scopes,
388
+ * which is more performant than full explanation.
389
+ *
390
+ * @default false
391
+ */
392
+ includeExplanation?: boolean | 'scopeName';
393
+ /**
394
+ * A map of color names to new color values.
395
+ *
396
+ * The color key starts with '#' and should be lowercased.
397
+ *
398
+ * This will be merged with theme's `colorReplacements` if any.
399
+ */
400
+ colorReplacements?: Record<string, string | Record<string, string>>;
401
+ /**
402
+ * Lines above this length will not be tokenized for performance reasons.
403
+ *
404
+ * @default 0 (no limit)
405
+ */
406
+ tokenizeMaxLineLength?: number;
407
+ /**
408
+ * Time limit in milliseconds for tokenizing a single line.
409
+ *
410
+ * @default 500 (0.5s)
411
+ */
412
+ tokenizeTimeLimit?: number;
413
+ /**
414
+ * Represent the state of the grammar, allowing to continue tokenizing from a intermediate grammar state.
415
+ *
416
+ * You can get the grammar state from `getLastGrammarState`.
417
+ */
418
+ grammarState?: GrammarState;
419
+ /**
420
+ * The code context of the grammar.
421
+ * Consider it a prepended code to the input code, that only participate the grammar inference but not presented in the final output.
422
+ *
423
+ * This will be ignored if `grammarState` is provided.
424
+ */
425
+ grammarContextCode?: string;
426
426
  }
427
427
  /**
428
428
  * Result of `codeToTokens`, an object with 2D array of tokens and meta info like background and foreground color.
429
429
  */
430
430
  interface TokensResult {
431
- /**
432
- * 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
433
- */
434
- tokens: ThemedToken[][];
435
- /**
436
- * Foreground color of the code.
437
- */
438
- fg?: string;
439
- /**
440
- * Background color of the code.
441
- */
442
- bg?: string;
443
- /**
444
- * A string representation of themes applied to the token.
445
- */
446
- themeName?: string;
447
- /**
448
- * Custom style string to be applied to the root `<pre>` element.
449
- * When specified, `fg` and `bg` will be ignored.
450
- */
451
- rootStyle?: string | false;
452
- /**
453
- * The last grammar state of the code snippet.
454
- */
455
- grammarState?: GrammarState;
456
- }
457
-
431
+ /**
432
+ * 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
433
+ */
434
+ tokens: ThemedToken[][];
435
+ /**
436
+ * Foreground color of the code.
437
+ */
438
+ fg?: string;
439
+ /**
440
+ * Background color of the code.
441
+ */
442
+ bg?: string;
443
+ /**
444
+ * A string representation of themes applied to the token.
445
+ */
446
+ themeName?: string;
447
+ /**
448
+ * Custom style string to be applied to the root `<pre>` element.
449
+ * When specified, `fg` and `bg` will be ignored.
450
+ */
451
+ rootStyle?: string | false;
452
+ /**
453
+ * The last grammar state of the code snippet.
454
+ */
455
+ grammarState?: GrammarState;
456
+ }
457
+ //#endregion
458
+ //#region src/transformers.d.ts
458
459
  interface TransformerOptions {
459
- /**
460
- * Transformers for the Shiki pipeline.
461
- */
462
- transformers?: ShikiTransformer[];
463
- }
464
- interface ShikiTransformerContextMeta {
460
+ /**
461
+ * Transformers for the Shiki pipeline.
462
+ */
463
+ transformers?: ShikiTransformer[];
465
464
  }
465
+ interface ShikiTransformerContextMeta {}
466
466
  /**
467
467
  * Common transformer context for all transformers hooks
468
468
  */
469
469
  interface ShikiTransformerContextCommon {
470
- meta: ShikiTransformerContextMeta;
471
- options: CodeToHastOptions;
472
- codeToHast: (code: string, options: CodeToHastOptions) => Root;
473
- codeToTokens: (code: string, options: CodeToTokensOptions) => TokensResult;
470
+ meta: ShikiTransformerContextMeta;
471
+ options: CodeToHastOptions;
472
+ codeToHast: (code: string, options: CodeToHastOptions) => Root;
473
+ codeToTokens: (code: string, options: CodeToTokensOptions) => TokensResult;
474
474
  }
475
475
  interface ShikiTransformerContextSource extends ShikiTransformerContextCommon {
476
- readonly source: string;
476
+ readonly source: string;
477
477
  }
478
478
  /**
479
479
  * Transformer context for HAST related hooks
480
480
  */
481
481
  interface ShikiTransformerContext extends ShikiTransformerContextSource {
482
- readonly tokens: ThemedToken[][];
483
- readonly root: Root;
484
- readonly pre: Element;
485
- readonly code: Element;
486
- readonly lines: Element[];
487
- readonly structure: CodeToHastOptions['structure'];
488
- /**
489
- * Utility to append class to a hast node
490
- *
491
- * If the `property.class` is a string, it will be splitted by space and converted to an array.
492
- */
493
- addClassToHast: (hast: Element, className: string | string[]) => Element;
482
+ readonly tokens: ThemedToken[][];
483
+ readonly root: Root;
484
+ readonly pre: Element;
485
+ readonly code: Element;
486
+ readonly lines: Element[];
487
+ readonly structure: CodeToHastOptions['structure'];
488
+ /**
489
+ * Utility to append class to a hast node
490
+ *
491
+ * If the `property.class` is a string, it will be splitted by space and converted to an array.
492
+ */
493
+ addClassToHast: (hast: Element, className: string | string[]) => Element;
494
494
  }
495
495
  interface ShikiTransformer {
496
- /**
497
- * Name of the transformer
498
- */
499
- name?: string;
500
- /**
501
- * Enforce plugin invocation tier similar to webpack loaders. Hooks ordering
502
- * is still subject to the `order` property in the hook object.
503
- *
504
- * Plugin invocation order:
505
- * - `enforce: 'pre'` plugins
506
- * - normal plugins
507
- * - `enforce: 'post'` plugins
508
- * - shiki post plugins
509
- */
510
- enforce?: 'pre' | 'post';
511
- /**
512
- * Transform the raw input code before passing to the highlighter.
513
- */
514
- preprocess?: (this: ShikiTransformerContextCommon, code: string, options: CodeToHastOptions) => string | void;
515
- /**
516
- * Transform the full tokens list before converting to HAST.
517
- * Return a new tokens list will replace the original one.
518
- */
519
- tokens?: (this: ShikiTransformerContextSource, tokens: ThemedToken[][]) => ThemedToken[][] | void;
520
- /**
521
- * Transform the entire generated HAST tree. Return a new Node will replace the original one.
522
- */
523
- root?: (this: ShikiTransformerContext, hast: Root) => Root | void;
524
- /**
525
- * Transform the `<pre>` element. Return a new Node will replace the original one.
526
- */
527
- pre?: (this: ShikiTransformerContext, hast: Element) => Element | void;
528
- /**
529
- * Transform the `<code>` element. Return a new Node will replace the original one.
530
- */
531
- code?: (this: ShikiTransformerContext, hast: Element) => Element | void;
532
- /**
533
- * Transform each line `<span class="line">` element.
534
- *
535
- * @param hast
536
- * @param line 1-based line number
537
- */
538
- line?: (this: ShikiTransformerContext, hast: Element, line: number) => Element | void;
539
- /**
540
- * Transform each token `<span>` element.
541
- */
542
- span?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element, token: ThemedToken) => Element | void;
543
- /**
544
- * Transform the generated HTML string before returning.
545
- * This hook will only be called with `codeToHtml`.
546
- */
547
- postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void;
548
- }
549
-
496
+ /**
497
+ * Name of the transformer
498
+ */
499
+ name?: string;
500
+ /**
501
+ * Enforce plugin invocation tier similar to webpack loaders. Hooks ordering
502
+ * is still subject to the `order` property in the hook object.
503
+ *
504
+ * Plugin invocation order:
505
+ * - `enforce: 'pre'` plugins
506
+ * - normal plugins
507
+ * - `enforce: 'post'` plugins
508
+ * - shiki post plugins
509
+ */
510
+ enforce?: 'pre' | 'post';
511
+ /**
512
+ * Transform the raw input code before passing to the highlighter.
513
+ */
514
+ preprocess?: (this: ShikiTransformerContextCommon, code: string, options: CodeToHastOptions) => string | void;
515
+ /**
516
+ * Transform the full tokens list before converting to HAST.
517
+ * Return a new tokens list will replace the original one.
518
+ */
519
+ tokens?: (this: ShikiTransformerContextSource, tokens: ThemedToken[][]) => ThemedToken[][] | void;
520
+ /**
521
+ * Transform the entire generated HAST tree. Return a new Node will replace the original one.
522
+ */
523
+ root?: (this: ShikiTransformerContext, hast: Root) => Root | void;
524
+ /**
525
+ * Transform the `<pre>` element. Return a new Node will replace the original one.
526
+ */
527
+ pre?: (this: ShikiTransformerContext, hast: Element) => Element | void;
528
+ /**
529
+ * Transform the `<code>` element. Return a new Node will replace the original one.
530
+ */
531
+ code?: (this: ShikiTransformerContext, hast: Element) => Element | void;
532
+ /**
533
+ * Transform each line `<span class="line">` element.
534
+ *
535
+ * @param hast
536
+ * @param line 1-based line number
537
+ */
538
+ line?: (this: ShikiTransformerContext, hast: Element, line: number) => Element | void;
539
+ /**
540
+ * Transform each token `<span>` element.
541
+ */
542
+ span?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element, token: ThemedToken) => Element | void;
543
+ /**
544
+ * Transform the generated HTML string before returning.
545
+ * This hook will only be called with `codeToHtml`.
546
+ */
547
+ postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void;
548
+ }
549
+ //#endregion
550
+ //#region src/options.d.ts
550
551
  interface HighlighterCoreOptions<Sync extends boolean = false> {
551
- /**
552
- * Custom RegExp engine.
553
- */
554
- engine: Sync extends true ? RegexEngine : Awaitable<RegexEngine>;
555
- /**
556
- * Theme names, or theme registration objects to be loaded upfront.
557
- */
558
- themes?: Sync extends true ? MaybeArray<ThemeRegistrationAny>[] : ThemeInput[];
559
- /**
560
- * Language names, or language registration objects to be loaded upfront.
561
- */
562
- langs?: Sync extends true ? MaybeArray<LanguageRegistration>[] : LanguageInput[];
563
- /**
564
- * Alias of languages
565
- * @example { 'my-lang': 'javascript' }
566
- */
567
- langAlias?: Record<string, string>;
568
- /**
569
- * Emit console warnings to alert users of potential issues.
570
- * @default true
571
- */
572
- warnings?: boolean;
552
+ /**
553
+ * Custom RegExp engine.
554
+ */
555
+ engine: Sync extends true ? RegexEngine : Awaitable<RegexEngine>;
556
+ /**
557
+ * Theme names, or theme registration objects to be loaded upfront.
558
+ */
559
+ themes?: Sync extends true ? MaybeArray<ThemeRegistrationAny>[] : ThemeInput[];
560
+ /**
561
+ * Language names, or language registration objects to be loaded upfront.
562
+ */
563
+ langs?: Sync extends true ? MaybeArray<LanguageRegistration>[] : LanguageInput[];
564
+ /**
565
+ * Alias of languages
566
+ * @example { 'my-lang': 'javascript' }
567
+ */
568
+ langAlias?: Record<string, string>;
569
+ /**
570
+ * Emit console warnings to alert users of potential issues.
571
+ * @default true
572
+ */
573
+ warnings?: boolean;
573
574
  }
574
575
  interface BundledHighlighterOptions<L extends string, T extends string> extends Pick<HighlighterCoreOptions, 'warnings'> {
575
- /**
576
- * Custom RegExp engine.
577
- */
578
- engine?: Awaitable<RegexEngine>;
579
- /**
580
- * Theme registation
581
- *
582
- * @default []
583
- */
584
- themes: (ThemeInput | StringLiteralUnion<T> | SpecialTheme)[];
585
- /**
586
- * Language registation
587
- *
588
- * @default []
589
- */
590
- langs: (LanguageInput | StringLiteralUnion<L> | SpecialLanguage)[];
591
- /**
592
- * Alias of languages
593
- * @example { 'my-lang': 'javascript' }
594
- */
595
- langAlias?: Record<string, StringLiteralUnion<L>>;
576
+ /**
577
+ * Custom RegExp engine.
578
+ */
579
+ engine?: Awaitable<RegexEngine>;
580
+ /**
581
+ * Theme registation
582
+ *
583
+ * @default []
584
+ */
585
+ themes: (ThemeInput | StringLiteralUnion<T> | SpecialTheme)[];
586
+ /**
587
+ * Language registation
588
+ *
589
+ * @default []
590
+ */
591
+ langs: (LanguageInput | StringLiteralUnion<L> | SpecialLanguage)[];
592
+ /**
593
+ * Alias of languages
594
+ * @example { 'my-lang': 'javascript' }
595
+ */
596
+ langAlias?: Record<string, StringLiteralUnion<L>>;
596
597
  }
597
598
  interface CodeOptionsSingleTheme<Themes extends string = string> {
598
- theme: ThemeRegistrationAny | StringLiteralUnion<Themes>;
599
+ theme: ThemeRegistrationAny | StringLiteralUnion<Themes>;
599
600
  }
600
601
  interface CodeOptionsMultipleThemes<Themes extends string = string> {
601
- /**
602
- * A map of color names to themes.
603
- * This allows you to specify multiple themes for the generated code.
604
- *
605
- * ```ts
606
- * highlighter.codeToHtml(code, {
607
- * lang: 'js',
608
- * themes: {
609
- * light: 'vitesse-light',
610
- * dark: 'vitesse-dark',
611
- * }
612
- * })
613
- * ```
614
- *
615
- * Will generate:
616
- *
617
- * ```html
618
- * <span style="color:#111;--shiki-dark:#fff;">code</span>
619
- * ```
620
- *
621
- * @see https://shiki.style/guide/dual-themes
622
- */
623
- themes: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<Themes>>>;
624
- /**
625
- * The default theme applied to the code (via inline `color` style).
626
- * The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
627
- *
628
- * For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
629
- * and the `dark` theme and other custom themes are applied via CSS variables:
630
- *
631
- * ```html
632
- * <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
633
- * ```
634
- *
635
- * When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
636
- *
637
- * ```html
638
- * <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
639
- * ```
640
- *
641
- * When set to `light-dark()`, the default color will be rendered as `light-dark(#{light}, #{dark})`.
642
- *
643
- * ```html
644
- * <span style="color:light-dark(#{light}, #{dark});--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
645
- * ```
646
- *
647
- * @default 'light'
648
- */
649
- defaultColor?: StringLiteralUnion<'light' | 'dark'> | 'light-dark()' | false;
650
- /**
651
- * The strategy to render multiple colors.
652
- *
653
- * - `css-vars`: Render the colors via CSS variables.
654
- * - `none`: Do not render the colors, only use the default color.
655
- *
656
- * @default 'css-vars'
657
- */
658
- colorsRendering?: 'css-vars' | 'none';
659
- /**
660
- * Prefix of CSS variables used to store the color of the other theme.
661
- *
662
- * @default '--shiki-'
663
- */
664
- cssVariablePrefix?: string;
602
+ /**
603
+ * A map of color names to themes.
604
+ * This allows you to specify multiple themes for the generated code.
605
+ *
606
+ * ```ts
607
+ * highlighter.codeToHtml(code, {
608
+ * lang: 'js',
609
+ * themes: {
610
+ * light: 'vitesse-light',
611
+ * dark: 'vitesse-dark',
612
+ * }
613
+ * })
614
+ * ```
615
+ *
616
+ * Will generate:
617
+ *
618
+ * ```html
619
+ * <span style="color:#111;--shiki-dark:#fff;">code</span>
620
+ * ```
621
+ *
622
+ * @see https://shiki.style/guide/dual-themes
623
+ */
624
+ themes: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<Themes>>>;
625
+ /**
626
+ * The default theme applied to the code (via inline `color` style).
627
+ * The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
628
+ *
629
+ * For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
630
+ * and the `dark` theme and other custom themes are applied via CSS variables:
631
+ *
632
+ * ```html
633
+ * <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
634
+ * ```
635
+ *
636
+ * When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
637
+ *
638
+ * ```html
639
+ * <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
640
+ * ```
641
+ *
642
+ * When set to `light-dark()`, the default color will be rendered as `light-dark(#{light}, #{dark})`.
643
+ *
644
+ * ```html
645
+ * <span style="color:light-dark(#{light}, #{dark});--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
646
+ * ```
647
+ *
648
+ * @default 'light'
649
+ */
650
+ defaultColor?: StringLiteralUnion<'light' | 'dark'> | 'light-dark()' | false;
651
+ /**
652
+ * The strategy to render multiple colors.
653
+ *
654
+ * - `css-vars`: Render the colors via CSS variables.
655
+ * - `none`: Do not render the colors, only use the default color.
656
+ *
657
+ * @default 'css-vars'
658
+ */
659
+ colorsRendering?: 'css-vars' | 'none';
660
+ /**
661
+ * Prefix of CSS variables used to store the color of the other theme.
662
+ *
663
+ * @default '--shiki-'
664
+ */
665
+ cssVariablePrefix?: string;
665
666
  }
666
667
  type CodeOptionsThemes<Themes extends string = string> = CodeOptionsSingleTheme<Themes> | CodeOptionsMultipleThemes<Themes>;
667
668
  type CodeToHastOptions<Languages extends string = string, Themes extends string = string> = CodeToHastOptionsCommon<Languages> & CodeOptionsThemes<Themes> & CodeOptionsMeta;
668
669
  interface CodeToHastOptionsCommon<Languages extends string = string> extends TransformerOptions, DecorationOptions, Pick<TokenizeWithThemeOptions, 'colorReplacements' | 'tokenizeMaxLineLength' | 'tokenizeTimeLimit' | 'grammarState' | 'grammarContextCode' | 'includeExplanation'> {
669
- /**
670
- * Data to be added to the root `<pre>` element.
671
- */
672
- data?: Record<string, unknown>;
673
- /**
674
- * The grammar name for the code.
675
- */
676
- lang: StringLiteralUnion<Languages | SpecialLanguage>;
677
- /**
678
- * Custom style string to be applied to the root `<pre>` element.
679
- *
680
- * When set to `false`, no style will be applied.
681
- */
682
- rootStyle?: string | false;
683
- /**
684
- * Merge whitespace tokens to saving extra `<span>`.
685
- *
686
- * When set to true, it will merge whitespace tokens with the next token.
687
- * When set to false, it keep the output as-is.
688
- * When set to `never`, it will force to separate leading and trailing spaces from tokens.
689
- *
690
- * @default true
691
- */
692
- mergeWhitespaces?: boolean | 'never';
693
- /**
694
- * Merge consecutive tokens with the same style to reduce the number of DOM nodes.
695
- * This can improve rendering performance but may affect the structure of the output.
696
- *
697
- * @default false
698
- */
699
- mergeSameStyleTokens?: boolean;
700
- /**
701
- * The structure of the generated HAST and HTML.
702
- *
703
- * - `classic`: The classic structure with `<pre>` and `<code>` elements, each line wrapped with a `<span class="line">` element.
704
- * - `inline`: All tokens are rendered as `<span>`, line breaks are rendered as `<br>`. No `<pre>` or `<code>` elements. Default forground and background colors are not applied.
705
- *
706
- * @default 'classic'
707
- */
708
- structure?: 'classic' | 'inline';
709
- /**
710
- * Tab index of the root `<pre>` element.
711
- *
712
- * Set to `false` to disable tab index.
713
- *
714
- * @default 0
715
- */
716
- tabindex?: number | string | false;
670
+ /**
671
+ * Data to be added to the root `<pre>` element.
672
+ */
673
+ data?: Record<string, unknown>;
674
+ /**
675
+ * The grammar name for the code.
676
+ */
677
+ lang: StringLiteralUnion<Languages | SpecialLanguage>;
678
+ /**
679
+ * Custom style string to be applied to the root `<pre>` element.
680
+ *
681
+ * When set to `false`, no style will be applied.
682
+ */
683
+ rootStyle?: string | false;
684
+ /**
685
+ * Merge whitespace tokens to saving extra `<span>`.
686
+ *
687
+ * When set to true, it will merge whitespace tokens with the next token.
688
+ * When set to false, it keep the output as-is.
689
+ * When set to `never`, it will force to separate leading and trailing spaces from tokens.
690
+ *
691
+ * @default true
692
+ */
693
+ mergeWhitespaces?: boolean | 'never';
694
+ /**
695
+ * Merge consecutive tokens with the same style to reduce the number of DOM nodes.
696
+ * This can improve rendering performance but may affect the structure of the output.
697
+ *
698
+ * @default false
699
+ */
700
+ mergeSameStyleTokens?: boolean;
701
+ /**
702
+ * The structure of the generated HAST and HTML.
703
+ *
704
+ * - `classic`: The classic structure with `<pre>` and `<code>` elements, each line wrapped with a `<span class="line">` element.
705
+ * - `inline`: All tokens are rendered as `<span>`, line breaks are rendered as `<br>`. No `<pre>` or `<code>` elements. Default forground and background colors are not applied.
706
+ *
707
+ * @default 'classic'
708
+ */
709
+ structure?: 'classic' | 'inline';
710
+ /**
711
+ * Tab index of the root `<pre>` element.
712
+ *
713
+ * Set to `false` to disable tab index.
714
+ *
715
+ * @default 0
716
+ */
717
+ tabindex?: number | string | false;
717
718
  }
718
719
  interface CodeOptionsMeta {
719
- /**
720
- * Meta data passed to Shiki, usually used by plugin integrations to pass the code block header.
721
- *
722
- * Key values in meta will be serialized to the attributes of the root `<pre>` element.
723
- *
724
- * Keys starting with `_` will be ignored.
725
- *
726
- * A special key `__raw` key will be used to pass the raw code block header (if the integration supports it).
727
- */
728
- meta?: {
729
- /**
730
- * Raw string of the code block header.
731
- */
732
- __raw?: string;
733
- [key: string]: any;
734
- };
720
+ /**
721
+ * Meta data passed to Shiki, usually used by plugin integrations to pass the code block header.
722
+ *
723
+ * Key values in meta will be serialized to the attributes of the root `<pre>` element.
724
+ *
725
+ * Keys starting with `_` will be ignored.
726
+ *
727
+ * A special key `__raw` key will be used to pass the raw code block header (if the integration supports it).
728
+ */
729
+ meta?: {
730
+ /**
731
+ * Raw string of the code block header.
732
+ */
733
+ __raw?: string;
734
+ [key: string]: any;
735
+ };
735
736
  }
736
737
  interface CodeToHastRenderOptionsCommon extends TransformerOptions, Omit<TokensResult, 'tokens'> {
737
- lang?: string;
738
- langId?: string;
738
+ lang?: string;
739
+ langId?: string;
739
740
  }
740
741
  type CodeToHastRenderOptions = CodeToHastRenderOptionsCommon & CodeToHastOptions;
741
-
742
+ //#endregion
743
+ //#region src/highlighter.d.ts
742
744
  /**
743
745
  * Type of object that can be bound to a grammar state
744
746
  */
@@ -746,116 +748,116 @@ type GrammarStateMapKey = Root | ThemedToken[][];
746
748
  /**
747
749
  * Internal context of Shiki, core textmate logic
748
750
  */
749
- interface ShikiInternal<BundledLangKeys extends string = never, BundledThemeKeys extends string = never> {
750
- /**
751
- * Load a theme to the highlighter, so later it can be used synchronously.
752
- */
753
- loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
754
- /**
755
- * Load a theme registration synchronously.
756
- */
757
- loadThemeSync: (...themes: MaybeArray<ThemeRegistrationAny>[]) => void;
758
- /**
759
- * Load a language to the highlighter, so later it can be used synchronously.
760
- */
761
- loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
762
- /**
763
- * Load a language registration synchronously.
764
- */
765
- loadLanguageSync: (...langs: MaybeArray<LanguageRegistration>[]) => void;
766
- /**
767
- * Get the registered theme object
768
- */
769
- getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
770
- /**
771
- * Get the registered language object
772
- */
773
- getLanguage: (name: string | LanguageRegistration) => Grammar;
774
- /**
775
- * Set the current theme and get the resolved theme object and color map.
776
- * @internal
777
- */
778
- setTheme: (themeName: string | ThemeRegistrationAny) => {
779
- theme: ThemeRegistrationResolved;
780
- colorMap: string[];
781
- };
782
- /**
783
- * Resolve a language alias
784
- */
785
- resolveLangAlias: (lang: string) => string;
786
- /**
787
- * Get the names of loaded languages
788
- *
789
- * Special-handled languages like `text`, `plain` and `ansi` are not included.
790
- */
791
- getLoadedLanguages: () => string[];
792
- /**
793
- * Get the names of loaded themes
794
- *
795
- * Special-handled themes like `none` are not included.
796
- */
797
- getLoadedThemes: () => string[];
798
- /**
799
- * Dispose the internal registry and release resources
800
- */
801
- dispose: () => void;
802
- /**
803
- * Dispose the internal registry and release resources
804
- */
805
- [Symbol.dispose]: () => void;
751
+ interface ShikiPrimitive<BundledLangKeys extends string = never, BundledThemeKeys extends string = never> {
752
+ /**
753
+ * Load a theme to the highlighter, so later it can be used synchronously.
754
+ */
755
+ loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
756
+ /**
757
+ * Load a theme registration synchronously.
758
+ */
759
+ loadThemeSync: (...themes: MaybeArray<ThemeRegistrationAny>[]) => void;
760
+ /**
761
+ * Load a language to the highlighter, so later it can be used synchronously.
762
+ */
763
+ loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
764
+ /**
765
+ * Load a language registration synchronously.
766
+ */
767
+ loadLanguageSync: (...langs: MaybeArray<LanguageRegistration>[]) => void;
768
+ /**
769
+ * Get the registered theme object
770
+ */
771
+ getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
772
+ /**
773
+ * Get the registered language object
774
+ */
775
+ getLanguage: (name: string | LanguageRegistration) => Grammar;
776
+ /**
777
+ * Set the current theme and get the resolved theme object and color map.
778
+ * @internal
779
+ */
780
+ setTheme: (themeName: string | ThemeRegistrationAny) => {
781
+ theme: ThemeRegistrationResolved;
782
+ colorMap: string[];
783
+ };
784
+ /**
785
+ * Resolve a language alias
786
+ */
787
+ resolveLangAlias: (lang: string) => string;
788
+ /**
789
+ * Get the names of loaded languages
790
+ *
791
+ * Special-handled languages like `text`, `plain` and `ansi` are not included.
792
+ */
793
+ getLoadedLanguages: () => string[];
794
+ /**
795
+ * Get the names of loaded themes
796
+ *
797
+ * Special-handled themes like `none` are not included.
798
+ */
799
+ getLoadedThemes: () => string[];
800
+ /**
801
+ * Dispose the internal registry and release resources
802
+ */
803
+ dispose: () => void;
804
+ /**
805
+ * Dispose the internal registry and release resources
806
+ */
807
+ [Symbol.dispose]: () => void;
806
808
  }
807
809
  /**
808
810
  * Generic instance interface of Shiki
809
811
  */
810
- interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> extends ShikiInternal<BundledLangKeys, BundledThemeKeys> {
811
- /**
812
- * Get highlighted code in HTML string
813
- */
814
- codeToHtml: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => string;
815
- /**
816
- * Get highlighted code in HAST.
817
- * @see https://github.com/syntax-tree/hast
818
- */
819
- codeToHast: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => Root;
820
- /**
821
- * Get highlighted code in tokens. Uses `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
822
- */
823
- codeToTokens: (code: string, options: CodeToTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => TokensResult;
824
- /**
825
- * Get highlighted code in tokens with a single theme.
826
- * @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
827
- */
828
- codeToTokensBase: (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedToken[][];
829
- /**
830
- * Get highlighted code in tokens with multiple themes.
831
- *
832
- * Different from `codeToTokensBase`, each token will have a `variants` property consisting of an object of color name to token styles.
833
- *
834
- * @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
835
- */
836
- codeToTokensWithThemes: (code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedTokenWithVariants[][];
837
- /**
838
- * Get the last grammar state of a code snippet.
839
- * You can pass the grammar state to `codeToTokens` as `grammarState` to continue tokenizing from an intermediate state.
840
- */
841
- getLastGrammarState: {
842
- (element: GrammarStateMapKey, options?: never): GrammarState | undefined;
843
- (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): GrammarState;
844
- };
845
- /**
846
- * Get internal context object
847
- * @internal
848
- * @deprecated
849
- */
850
- getInternalContext: () => ShikiInternal;
851
- /**
852
- * Get bundled languages object
853
- */
854
- getBundledLanguages: () => Record<BundledLangKeys, LanguageInput>;
855
- /**
856
- * Get bundled themes object
857
- */
858
- getBundledThemes: () => Record<BundledThemeKeys, ThemeInput>;
812
+ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> extends ShikiPrimitive<BundledLangKeys, BundledThemeKeys> {
813
+ /**
814
+ * Get highlighted code in HTML string
815
+ */
816
+ codeToHtml: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => string;
817
+ /**
818
+ * Get highlighted code in HAST.
819
+ * @see https://github.com/syntax-tree/hast
820
+ */
821
+ codeToHast: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => Root;
822
+ /**
823
+ * Get highlighted code in tokens. Uses `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
824
+ */
825
+ codeToTokens: (code: string, options: CodeToTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => TokensResult;
826
+ /**
827
+ * Get highlighted code in tokens with a single theme.
828
+ * @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
829
+ */
830
+ codeToTokensBase: (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedToken[][];
831
+ /**
832
+ * Get highlighted code in tokens with multiple themes.
833
+ *
834
+ * Different from `codeToTokensBase`, each token will have a `variants` property consisting of an object of color name to token styles.
835
+ *
836
+ * @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
837
+ */
838
+ codeToTokensWithThemes: (code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedTokenWithVariants[][];
839
+ /**
840
+ * Get the last grammar state of a code snippet.
841
+ * You can pass the grammar state to `codeToTokens` as `grammarState` to continue tokenizing from an intermediate state.
842
+ */
843
+ getLastGrammarState: {
844
+ (element: GrammarStateMapKey, options?: never): GrammarState | undefined;
845
+ (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): GrammarState;
846
+ };
847
+ /**
848
+ * Get internal context object
849
+ * @internal
850
+ * @deprecated
851
+ */
852
+ getInternalContext: () => ShikiPrimitive;
853
+ /**
854
+ * Get bundled languages object
855
+ */
856
+ getBundledLanguages: () => Record<BundledLangKeys, LanguageInput>;
857
+ /**
858
+ * Get bundled themes object
859
+ */
860
+ getBundledThemes: () => Record<BundledThemeKeys, ThemeInput>;
859
861
  }
860
862
  /**
861
863
  * The fine-grained core Shiki highlighter instance.
@@ -865,21 +867,21 @@ type HighlighterCore = HighlighterGeneric<never, never>;
865
867
  * Options for creating a bundled highlighter.
866
868
  */
867
869
  interface CreateBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> {
868
- langs: Record<BundledLangs, LanguageInput>;
869
- themes: Record<BundledThemes, ThemeInput>;
870
- engine: () => Awaitable<RegexEngine>;
870
+ langs: Record<BundledLangs, LanguageInput>;
871
+ themes: Record<BundledThemes, ThemeInput>;
872
+ engine: () => Awaitable<RegexEngine>;
871
873
  }
872
874
  /**
873
875
  * @deprecated Use `CreateBundledHighlighterOptions` instead.
874
876
  */
875
- interface CreatedBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> extends CreateBundledHighlighterOptions<BundledLangs, BundledThemes> {
876
- }
877
-
877
+ interface CreatedBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> extends CreateBundledHighlighterOptions<BundledLangs, BundledThemes> {}
878
+ //#endregion
879
+ //#region src/bundle-factory.d.ts
878
880
  type CreateHighlighterFactory<L extends string, T extends string> = (options: BundledHighlighterOptions<L, T>) => Promise<HighlighterGeneric<L, T>>;
879
-
881
+ //#endregion
882
+ //#region src/error.d.ts
880
883
  declare class ShikiError extends Error {
881
- constructor(message: string);
884
+ constructor(message: string);
882
885
  }
883
-
884
- export { ShikiError };
885
- export type { AnsiLanguage, Awaitable, BundledHighlighterOptions, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptions, CodeToHastOptionsCommon, CodeToHastRenderOptions, CodeToHastRenderOptionsCommon, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, CreateBundledHighlighterOptions, CreateHighlighterFactory, CreatedBundledHighlighterOptions, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, Grammar, GrammarState, GrammarStateMapKey, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, LanguageRegistration, LoadWasmOptions, LoadWasmOptionsPlain, MaybeArray, MaybeGetter, MaybeModule, Offset, OffsetOrPosition, OnigurumaLoadOptions, PatternScanner, PlainTextLanguage, Position, RegexEngine, RegexEngineString, RequireKeys, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiInternal, ShikiTransformer, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformerContextMeta, ShikiTransformerContextSource, SpecialLanguage, SpecialTheme, StringLiteralUnion, ThemeInput, ThemeRegistration, ThemeRegistrationAny, ThemeRegistrationRaw, ThemeRegistrationResolved, ThemedToken, ThemedTokenExplanation, ThemedTokenScopeExplanation, ThemedTokenWithVariants, TokenBase, TokenStyles, TokenizeWithThemeOptions, TokensResult, TransformerOptions, WebAssemblyInstance, WebAssemblyInstantiator };
886
+ //#endregion
887
+ export { AnsiLanguage, Awaitable, BundledHighlighterOptions, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptions, CodeToHastOptionsCommon, CodeToHastRenderOptions, CodeToHastRenderOptionsCommon, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, CreateBundledHighlighterOptions, CreateHighlighterFactory, CreatedBundledHighlighterOptions, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, Grammar, GrammarState, GrammarStateMapKey, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, LanguageRegistration, LoadWasmOptions, LoadWasmOptionsPlain, MaybeArray, MaybeGetter, MaybeModule, Offset, OffsetOrPosition, OnigurumaLoadOptions, PatternScanner, PlainTextLanguage, Position, type RawGrammar, type RawTheme, type RawThemeSetting, RegexEngine, RegexEngineString, RequireKeys, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiError, ShikiPrimitive, ShikiTransformer, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformerContextMeta, ShikiTransformerContextSource, SpecialLanguage, SpecialTheme, StringLiteralUnion, ThemeInput, ThemeRegistration, ThemeRegistrationAny, ThemeRegistrationRaw, ThemeRegistrationResolved, ThemedToken, ThemedTokenExplanation, ThemedTokenScopeExplanation, ThemedTokenWithVariants, TokenBase, TokenStyles, TokenizeWithThemeOptions, TokensResult, TransformerOptions, WebAssemblyInstance, WebAssemblyInstantiator };