@shikijs/core 1.14.1 → 1.15.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.
@@ -1,3 +1,4 @@
1
+ type Awaitable<T> = T | Promise<T>;
1
2
  interface WebAssemblyInstantiator {
2
3
  (importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined): Promise<WebAssemblyInstance>;
3
4
  }
@@ -9,9 +10,17 @@ type OnigurumaLoadOptions = {
9
10
  } | {
10
11
  data: ArrayBufferView | ArrayBuffer | Response;
11
12
  };
12
- type Awaitable<T> = T | Promise<T>;
13
13
  type LoadWasmOptionsPlain = OnigurumaLoadOptions | WebAssemblyInstantiator | ArrayBufferView | ArrayBuffer | Response;
14
14
  type LoadWasmOptions = Awaitable<LoadWasmOptionsPlain> | (() => Awaitable<LoadWasmOptionsPlain>);
15
- declare function loadWasm(options: LoadWasmOptions): Promise<void>;
15
+ interface JavaScriptRegexEngineOptions {
16
+ /**
17
+ * Whether to allow invalid regex patterns.
18
+ */
19
+ forgiving?: boolean;
20
+ /**
21
+ * Cache for regex patterns.
22
+ */
23
+ cache?: Map<string, RegExp | Error>;
24
+ }
16
25
 
17
- export { type LoadWasmOptions as L, type WebAssemblyInstantiator as W, loadWasm as l };
26
+ export type { JavaScriptRegexEngineOptions as J, LoadWasmOptions as L, WebAssemblyInstantiator as W, WebAssemblyInstance as a };
@@ -1,5 +1,5 @@
1
- import { L as LoadWasmOptions } from './chunk-index.mjs';
2
1
  import { Root, Element } from 'hast';
2
+ import { L as LoadWasmOptions } from './chunk-engines.mjs';
3
3
 
4
4
  /**
5
5
  * A union of given const enum values.
@@ -222,7 +222,7 @@ interface ILocatable {
222
222
  readonly $vscodeTextmateLocation?: ILocation;
223
223
  }
224
224
 
225
- declare const enum StandardTokenType {
225
+ declare const enum StandardTokenType$1 {
226
226
  Other = 0,
227
227
  Comment = 1,
228
228
  String = 2,
@@ -249,7 +249,7 @@ interface IEmbeddedLanguagesMap {
249
249
  * A map from selectors to token types.
250
250
  */
251
251
  interface ITokenTypeMap {
252
- [selector: string]: StandardTokenType;
252
+ [selector: string]: StandardTokenType$1;
253
253
  }
254
254
  interface IGrammarConfiguration {
255
255
  embeddedLanguages?: IEmbeddedLanguagesMap;
@@ -364,6 +364,42 @@ interface StateStack {
364
364
  }
365
365
  declare const INITIAL: StateStack;
366
366
 
367
+ declare const enum TemporaryStandardTokenType {
368
+ Other = 0,
369
+ Comment = 1,
370
+ String = 2,
371
+ RegEx = 4,
372
+ MetaEmbedded = 8
373
+ }
374
+ declare const enum StandardTokenType {
375
+ Other = 0,
376
+ Comment = 1,
377
+ String = 2,
378
+ RegEx = 4
379
+ }
380
+ declare class StackElementMetadata {
381
+ static toBinaryStr(metadata: number): string;
382
+ static getLanguageId(metadata: number): number;
383
+ static getTokenType(metadata: number): number;
384
+ static getFontStyle(metadata: number): number;
385
+ static getForeground(metadata: number): number;
386
+ static getBackground(metadata: number): number;
387
+ static containsBalancedBrackets(metadata: number): boolean;
388
+ static set(metadata: number, languageId: number, tokenType: TemporaryStandardTokenType, fontStyle: FontStyle, foreground: number, background: number): number;
389
+ }
390
+
391
+ interface PatternScanner extends OnigScanner {
392
+ }
393
+ interface RegexEngineString extends OnigString {
394
+ }
395
+ /**
396
+ * Engine for RegExp matching and scanning.
397
+ */
398
+ interface RegexEngine {
399
+ createScanner: (patterns: string[]) => PatternScanner;
400
+ createString: (s: string) => RegexEngineString;
401
+ }
402
+
367
403
  type Awaitable<T> = T | Promise<T>;
368
404
  type MaybeGetter<T> = Awaitable<MaybeModule<T>> | (() => Awaitable<MaybeModule<T>>);
369
405
  type MaybeModule<T> = T | {
@@ -688,8 +724,12 @@ interface HighlighterCoreOptions {
688
724
  * @default true
689
725
  */
690
726
  warnings?: boolean;
727
+ /**
728
+ * Custom RegExp engine.
729
+ */
730
+ engine?: RegexEngine | Promise<RegexEngine>;
691
731
  }
692
- interface BundledHighlighterOptions<L extends string, T extends string> {
732
+ interface BundledHighlighterOptions<L extends string, T extends string> extends Pick<HighlighterCoreOptions, 'warnings' | 'engine'> {
693
733
  /**
694
734
  * Theme registation
695
735
  *
@@ -1019,4 +1059,4 @@ declare enum FontStyle {
1019
1059
  Underline = 4
1020
1060
  }
1021
1061
 
1022
- export { type ThemedTokenScopeExplanation as $, type AnsiLanguage as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type ResolveBundleKey as D, type LanguageRegistration as E, FontStyle as F, GrammarState as G, type HighlighterCoreOptions as H, INITIAL as I, type BundledLanguageInfo as J, type DynamicImportLanguageRegistration as K, type LanguageInput as L, type MaybeArray as M, type CodeOptionsSingleTheme as N, type CodeOptionsMultipleThemes as O, type PlainTextLanguage as P, type CodeOptionsThemes as Q, Registry as R, type StateStack as S, Theme as T, type CodeToHastOptionsCommon as U, type CodeOptionsMeta as V, type CodeToHastRenderOptionsCommon as W, type ThemeRegistrationRaw as X, type ThemeRegistration as Y, type DynamicImportThemeRegistration as Z, type BundledThemeInfo as _, type IRawTheme as a, type ThemedTokenExplanation as a0, type TokenBase as a1, type TransformerOptions as a2, type ShikiTransformerContextMeta as a3, type ShikiTransformerContext as a4, type Awaitable as a5, type MaybeGetter as a6, type MaybeModule as a7, type StringLiteralUnion as a8, type DecorationOptions as a9, type DecorationItem as aa, type ResolvedDecorationItem as ab, type DecorationTransformType as ac, type Offset as ad, type OffsetOrPosition as ae, type ResolvedPosition as af, type IRawGrammar as b, type IGrammar as c, type IGrammarConfiguration as d, type IOnigLib as e, type RegistryOptions as f, type IRawThemeSetting as g, type ThemeInput as h, type CodeToTokensOptions as i, type TokensResult as j, type RequireKeys as k, type CodeToTokensBaseOptions as l, type ThemedToken as m, type CodeToTokensWithThemesOptions as n, type ThemedTokenWithVariants as o, type SpecialLanguage as p, type SpecialTheme as q, type ThemeRegistrationAny as r, type TokenizeWithThemeOptions as s, type TokenStyles as t, type Position as u, type ThemeRegistrationResolved as v, type ShikiTransformerContextCommon as w, type CodeToHastRenderOptions as x, type ShikiTransformerContextSource as y, type ShikiTransformer as z };
1062
+ export { type Awaitable as $, type AnsiLanguage as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type DynamicImportLanguageRegistration as D, type IRawGrammar as E, type IRawTheme as F, GrammarState as G, type HighlighterCoreOptions as H, type IGrammar as I, type IRawThemeSetting as J, type ThemeRegistrationRaw as K, type LanguageInput as L, type MaybeArray as M, type ThemeRegistration as N, type DynamicImportThemeRegistration as O, type PlainTextLanguage as P, type BundledThemeInfo as Q, type RequireKeys as R, type SpecialLanguage as S, type ThemeInput as T, type ThemedTokenScopeExplanation as U, type ThemedTokenExplanation as V, type TokenBase as W, FontStyle as X, type TransformerOptions as Y, type ShikiTransformerContextMeta as Z, type ShikiTransformerContext as _, type CodeToTokensOptions as a, type MaybeGetter as a0, type MaybeModule as a1, type StringLiteralUnion as a2, type DecorationOptions as a3, type DecorationItem as a4, type ResolvedDecorationItem as a5, type DecorationTransformType as a6, type Offset as a7, type OffsetOrPosition as a8, type ResolvedPosition as a9, type PatternScanner as aa, type RegexEngineString as ab, Registry as ac, INITIAL as ad, type StateStack as ae, Theme as af, type IGrammarConfiguration as ag, type RegistryOptions as ah, TemporaryStandardTokenType as ai, StandardTokenType as aj, StackElementMetadata as ak, type TokensResult as b, type CodeToTokensBaseOptions as c, type ThemedToken as d, type CodeToTokensWithThemesOptions as e, type ThemedTokenWithVariants as f, type SpecialTheme as g, type ThemeRegistrationAny as h, type TokenizeWithThemeOptions as i, type TokenStyles as j, type Position as k, type RegexEngine as l, type ThemeRegistrationResolved as m, type ShikiTransformerContextCommon as n, type CodeToHastRenderOptions as o, type ShikiTransformerContextSource as p, type ShikiTransformer as q, type ResolveBundleKey as r, type LanguageRegistration as s, type BundledLanguageInfo as t, type CodeOptionsSingleTheme as u, type CodeOptionsMultipleThemes as v, type CodeOptionsThemes as w, type CodeToHastOptionsCommon as x, type CodeOptionsMeta as y, type CodeToHastRenderOptionsCommon as z };
package/dist/index.d.mts CHANGED
@@ -1,11 +1,10 @@
1
1
  import { HighlighterCore, HighlighterGeneric, ShikiInternal } from './types.mjs';
2
2
  export { Grammar } from './types.mjs';
3
- import { H as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, h as ThemeInput, C as CodeToHastOptions, i as CodeToTokensOptions, j as TokensResult, k as RequireKeys, l as CodeToTokensBaseOptions, m as ThemedToken, n as CodeToTokensWithThemesOptions, o as ThemedTokenWithVariants, G as GrammarState, M as MaybeArray, P as PlainTextLanguage, p as SpecialLanguage, q as SpecialTheme, r as ThemeRegistrationAny, s as TokenizeWithThemeOptions, t as TokenStyles, u as Position, c as IGrammar, v as ThemeRegistrationResolved, w as ShikiTransformerContextCommon, x as CodeToHastRenderOptions, y as ShikiTransformerContextSource, z as ShikiTransformer } from './chunk-tokens.mjs';
4
- export { A as AnsiLanguage, a5 as Awaitable, J as BundledLanguageInfo, _ as BundledThemeInfo, V as CodeOptionsMeta, O as CodeOptionsMultipleThemes, N as CodeOptionsSingleTheme, Q as CodeOptionsThemes, U as CodeToHastOptionsCommon, W as CodeToHastRenderOptionsCommon, aa as DecorationItem, a9 as DecorationOptions, ac as DecorationTransformType, K as DynamicImportLanguageRegistration, Z as DynamicImportThemeRegistration, F as FontStyle, E as LanguageRegistration, a6 as MaybeGetter, a7 as MaybeModule, ad as Offset, ae as OffsetOrPosition, b as RawGrammar, a as RawTheme, g as RawThemeSetting, D as ResolveBundleKey, ab as ResolvedDecorationItem, af as ResolvedPosition, a4 as ShikiTransformerContext, a3 as ShikiTransformerContextMeta, a8 as StringLiteralUnion, Y as ThemeRegistration, X as ThemeRegistrationRaw, a0 as ThemedTokenExplanation, $ as ThemedTokenScopeExplanation, a1 as TokenBase, a2 as TransformerOptions } from './chunk-tokens.mjs';
5
- import * as hast from 'hast';
6
- import { Root, Element } from 'hast';
7
- import { L as LoadWasmOptions } from './chunk-index.mjs';
8
- export { W as WebAssemblyInstantiator, l as loadWasm } from './chunk-index.mjs';
3
+ import { H as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, T as ThemeInput, C as CodeToHastOptions, a as CodeToTokensOptions, b as TokensResult, R as RequireKeys, c as CodeToTokensBaseOptions, d as ThemedToken, e as CodeToTokensWithThemesOptions, f as ThemedTokenWithVariants, G as GrammarState, M as MaybeArray, P as PlainTextLanguage, S as SpecialLanguage, g as SpecialTheme, h as ThemeRegistrationAny, i as TokenizeWithThemeOptions, j as TokenStyles, k as Position, l as RegexEngine, I as IGrammar, m as ThemeRegistrationResolved, n as ShikiTransformerContextCommon, o as CodeToHastRenderOptions, p as ShikiTransformerContextSource, q as ShikiTransformer } from './chunk-tokens.mjs';
4
+ export { A as AnsiLanguage, $ as Awaitable, t as BundledLanguageInfo, Q as BundledThemeInfo, y as CodeOptionsMeta, v as CodeOptionsMultipleThemes, u as CodeOptionsSingleTheme, w as CodeOptionsThemes, x as CodeToHastOptionsCommon, z as CodeToHastRenderOptionsCommon, a4 as DecorationItem, a3 as DecorationOptions, a6 as DecorationTransformType, D as DynamicImportLanguageRegistration, O as DynamicImportThemeRegistration, X as FontStyle, s as LanguageRegistration, a0 as MaybeGetter, a1 as MaybeModule, a7 as Offset, a8 as OffsetOrPosition, E as RawGrammar, F as RawTheme, J as RawThemeSetting, r as ResolveBundleKey, a5 as ResolvedDecorationItem, a9 as ResolvedPosition, _ as ShikiTransformerContext, Z as ShikiTransformerContextMeta, a2 as StringLiteralUnion, N as ThemeRegistration, K as ThemeRegistrationRaw, V as ThemedTokenExplanation, U as ThemedTokenScopeExplanation, W as TokenBase, Y as TransformerOptions } from './chunk-tokens.mjs';
5
+ import { Root, Element, RootContent, Nodes } from 'hast';
6
+ import { L as LoadWasmOptions, J as JavaScriptRegexEngineOptions } from './chunk-engines.mjs';
7
+ export { a as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
9
8
 
10
9
  /**
11
10
  * Create a Shiki core highlighter instance, with no languages or themes bundled.
@@ -142,6 +141,21 @@ declare function createPositionConverter(code: string): {
142
141
  posToIndex: (line: number, character: number) => number;
143
142
  };
144
143
 
144
+ declare function loadWasm(options: LoadWasmOptions): Promise<void>;
145
+
146
+ declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
147
+
148
+ /**
149
+ * Use the modern JavaScript RegExp engine to implement the OnigScanner.
150
+ *
151
+ * As Oniguruma regex is more powerful than JavaScript regex, some patterns may not be supported.
152
+ * Errors will be thrown when parsing TextMate grammars with unsupported patterns.
153
+ * Set `forgiving` to `true` to ignore these errors and skip the unsupported patterns.
154
+ *
155
+ * @experimental
156
+ */
157
+ declare function createJavaScriptRegexEngine(options?: JavaScriptRegexEngineOptions): RegexEngine;
158
+
145
159
  /**
146
160
  * Set the default wasm loader for `loadWasm`.
147
161
  * @internal
@@ -226,10 +240,7 @@ type Options$1 = Options$2
226
240
  * Serialized HTML.
227
241
  */
228
242
  declare function toHtml(tree: Array<RootContent> | Nodes, options?: Options | null | undefined): string;
229
- type Nodes = hast.Nodes;
230
- type RootContent = hast.RootContent;
231
- type StringifyEntitiesOptions = Options$1;
232
- type CharacterReferences = Omit<StringifyEntitiesOptions, 'attribute' | 'escapeOnly' | 'subset'>;
243
+ type CharacterReferences = Omit<Options$1, "attribute" | "escapeOnly" | "subset">;
233
244
  /**
234
245
  * Configuration.
235
246
  */
@@ -318,14 +329,14 @@ type Options = {
318
329
  * Not used in the SVG space.
319
330
  */
320
331
  preferUnquoted?: boolean | null | undefined;
321
- /**
322
- * Preferred quote to use (default: `'"'`).
323
- */
324
- quote?: Quote | null | undefined;
325
332
  /**
326
333
  * Use the other quote if that results in less bytes (default: `false`).
327
334
  */
328
335
  quoteSmart?: boolean | null | undefined;
336
+ /**
337
+ * Preferred quote to use (default: `'"'`).
338
+ */
339
+ quote?: Quote | null | undefined;
329
340
  /**
330
341
  * When an `<svg>` element is found in the HTML space, this package already
331
342
  * automatically switches to and from the SVG space when entering and exiting
@@ -390,11 +401,11 @@ type Options = {
390
401
  /**
391
402
  * HTML quotes for attribute values.
392
403
  */
393
- type Quote = '"' | "'";
404
+ type Quote = "\"" | "'";
394
405
  /**
395
406
  * Namespace.
396
407
  */
397
- type Space = 'html' | 'svg';
408
+ type Space = "html" | "svg";
398
409
 
399
410
  /**
400
411
  * Get highlighted code in HTML.
@@ -420,4 +431,4 @@ declare class ShikiError extends Error {
420
431
  constructor(message: string);
421
432
  }
422
433
 
423
- export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type CreateHighlighterFactory, GrammarState, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, MaybeArray, PlainTextLanguage, Position, RequireKeys, ShikiError, ShikiInternal, ShikiTransformer, ShikiTransformerContextCommon, ShikiTransformerContextSource, type ShorthandsBundle, SpecialLanguage, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokenStyles, TokenizeWithThemeOptions, TokensResult, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighterCore, createPositionConverter, createShikiInternal, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeTheme, resolveColorReplacements, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
434
+ export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type CreateHighlighterFactory, GrammarState, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, LoadWasmOptions, MaybeArray, PlainTextLanguage, Position, RequireKeys, ShikiError, ShikiInternal, ShikiTransformer, ShikiTransformerContextCommon, ShikiTransformerContextSource, type ShorthandsBundle, SpecialLanguage, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokenStyles, TokenizeWithThemeOptions, TokensResult, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighterCore, createJavaScriptRegexEngine, createPositionConverter, createShikiInternal, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeTheme, resolveColorReplacements, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };