@shikijs/core 1.16.3 → 1.17.0

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