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