@shikijs/core 1.16.2 → 1.16.3

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.
@@ -57,4 +57,4 @@ interface JavaScriptRegexEngineOptions {
57
57
  regexConstructor?: (pattern: string) => RegExp;
58
58
  }
59
59
 
60
- export type { Awaitable as A, JavaScriptRegexEngineOptions as J, LoadWasmOptions as L, MaybeArray as M, OnigurumaLoadOptions as O, PatternScanner as P, RequireKeys as R, StringLiteralUnion as S, WebAssemblyInstantiator as W, RegexEngine as a, MaybeGetter as b, MaybeModule as c, RegexEngineString as d, WebAssemblyInstance as e, LoadWasmOptionsPlain as f };
60
+ export type { Awaitable as A, JavaScriptRegexEngineOptions as J, LoadWasmOptions as L, MaybeArray as M, OnigurumaLoadOptions as O, PatternScanner as P, RequireKeys as R, StringLiteralUnion as S, WebAssemblyInstantiator as W, RegexEngine as a, MaybeGetter as b, RegexEngineString as c, WebAssemblyInstance as d, LoadWasmOptionsPlain as e, MaybeModule as f };
package/dist/index.d.mts CHANGED
@@ -1,34 +1,11 @@
1
- import { HighlighterCoreOptions, HighlighterCore, BundledHighlighterOptions, HighlighterGeneric, CreatedBundledHighlighterOptions, LanguageInput, ThemeInput, CodeToHastOptions, CodeToTokensOptions, TokensResult, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, GrammarState, ShikiInternal, ThemeRegistrationAny, ThemeRegistrationResolved, TokenizeWithThemeOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, PlainTextLanguage, SpecialLanguage, SpecialTheme, TokenStyles, Position, ShikiTransformer } from './types.mjs';
2
- export { AnsiLanguage, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptionsCommon, CodeToHastRenderOptionsCommon, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, FontStyle, Grammar, LanguageRegistration, Offset, OffsetOrPosition, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiTransformerContext, ShikiTransformerContextMeta, ThemeRegistration, ThemeRegistrationRaw, ThemedTokenExplanation, ThemedTokenScopeExplanation, TokenBase, TransformerOptions } from './types.mjs';
3
- import { R as RequireKeys, L as LoadWasmOptions, a as RegexEngine, J as JavaScriptRegexEngineOptions, M as MaybeArray, b as MaybeGetter } from './chunk-engines.mjs';
4
- export { A as Awaitable, f as LoadWasmOptionsPlain, c as MaybeModule, O as OnigurumaLoadOptions, P as PatternScanner, d as RegexEngineString, S as StringLiteralUnion, e as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
5
1
  import { Root, RootContent, Nodes, Element } from 'hast';
2
+ import { R as RequireKeys, L as LoadWasmOptions, J as JavaScriptRegexEngineOptions, a as RegexEngine, M as MaybeArray, b as MaybeGetter } from './chunk-engines.mjs';
3
+ export { A as Awaitable, e as LoadWasmOptionsPlain, f as MaybeModule, O as OnigurumaLoadOptions, P as PatternScanner, c as RegexEngineString, S as StringLiteralUnion, d as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
4
+ import { BundledHighlighterOptions, HighlighterGeneric, CreatedBundledHighlighterOptions, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, GrammarState, HighlighterCore, ShikiInternal, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, ThemeRegistrationAny, ShikiTransformer, PlainTextLanguage, SpecialLanguage, SpecialTheme, TokenStyles, Position } from './types.mjs';
5
+ export { AnsiLanguage, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptionsCommon, CodeToHastRenderOptionsCommon, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, FontStyle, Grammar, LanguageRegistration, Offset, OffsetOrPosition, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiTransformerContext, ShikiTransformerContextMeta, ThemeRegistration, ThemeRegistrationRaw, ThemedTokenExplanation, ThemedTokenScopeExplanation, TokenBase, TransformerOptions } from './types.mjs';
6
6
  import { IGrammar } from '@shikijs/vscode-textmate';
7
7
  export { IRawGrammar as RawGrammar, IRawTheme as RawTheme, IRawThemeSetting as RawThemeSetting, EncodedTokenMetadata as StackElementMetadata } from '@shikijs/vscode-textmate';
8
8
 
9
- /**
10
- * Create a Shiki core highlighter instance, with no languages or themes bundled.
11
- * Wasm and each language and theme must be loaded manually.
12
- *
13
- * @see http://shiki.style/guide/bundles#fine-grained-bundle
14
- */
15
- declare function createHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
16
- /**
17
- * Create a Shiki core highlighter instance, with no languages or themes bundled.
18
- * Wasm and each language and theme must be loaded manually.
19
- *
20
- * Synchronous version of `createHighlighterCore`, which requires to provide the engine and all themes and languages upfront.
21
- *
22
- * @see http://shiki.style/guide/bundles#fine-grained-bundle
23
- */
24
- declare function createHighlighterCoreSync(options?: HighlighterCoreOptions<true>): HighlighterCore;
25
- declare function makeSingletonHighlighterCore(createHighlighter: typeof createHighlighterCore): (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
26
- declare const getSingletonHighlighterCore: (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
27
- /**
28
- * @deprecated Use `createHighlighterCore` or `getSingletonHighlighterCore` instead.
29
- */
30
- declare function getHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
31
-
32
9
  type CreateHighlighterFactory<L extends string, T extends string> = (options: BundledHighlighterOptions<L, T>) => Promise<HighlighterGeneric<L, T>>;
33
10
  /**
34
11
  * Create a `createHighlighter` function with bundled themes, languages, and engine.
@@ -107,11 +84,27 @@ declare function makeSingletonHighlighter<L extends string, T extends string>(cr
107
84
  declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
108
85
 
109
86
  /**
110
- * Get the minimal shiki context for rendering.
87
+ * Create a Shiki core highlighter instance, with no languages or themes bundled.
88
+ * Wasm and each language and theme must be loaded manually.
111
89
  *
112
- * Synchronous version of `createShikiInternal`, which requires to provide the engine and all themes and languages upfront.
90
+ * @see http://shiki.style/guide/bundles#fine-grained-bundle
113
91
  */
114
- declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
92
+ declare function createHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
93
+ /**
94
+ * Create a Shiki core highlighter instance, with no languages or themes bundled.
95
+ * Wasm and each language and theme must be loaded manually.
96
+ *
97
+ * Synchronous version of `createHighlighterCore`, which requires to provide the engine and all themes and languages upfront.
98
+ *
99
+ * @see http://shiki.style/guide/bundles#fine-grained-bundle
100
+ */
101
+ declare function createHighlighterCoreSync(options?: HighlighterCoreOptions<true>): HighlighterCore;
102
+ declare function makeSingletonHighlighterCore(createHighlighter: typeof createHighlighterCore): (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
103
+ declare const getSingletonHighlighterCore: (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
104
+ /**
105
+ * @deprecated Use `createHighlighterCore` or `getSingletonHighlighterCore` instead.
106
+ */
107
+ declare function getHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
115
108
 
116
109
  /**
117
110
  * Set the default wasm loader for `loadWasm`.
@@ -127,9 +120,12 @@ declare function createShikiInternal(options?: HighlighterCoreOptions): Promise<
127
120
  */
128
121
  declare function getShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
129
122
 
130
- declare function loadWasm(options: LoadWasmOptions): Promise<void>;
131
-
132
- declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
123
+ /**
124
+ * Get the minimal shiki context for rendering.
125
+ *
126
+ * Synchronous version of `createShikiInternal`, which requires to provide the engine and all themes and languages upfront.
127
+ */
128
+ declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
133
129
 
134
130
  /**
135
131
  * The default RegExp constructor for JavaScript regex engine.
@@ -146,25 +142,13 @@ declare function defaultJavaScriptRegexConstructor(pattern: string): RegExp;
146
142
  */
147
143
  declare function createJavaScriptRegexEngine(options?: JavaScriptRegexEngineOptions): RegexEngine;
148
144
 
149
- /**
150
- * Normalize a textmate theme to shiki theme
151
- */
152
- declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
153
-
154
- /**
155
- * Code to tokens, with a simple theme.
156
- */
157
- declare function codeToTokensBase(internal: ShikiInternal, code: string, options?: CodeToTokensBaseOptions): ThemedToken[][];
158
- declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
145
+ declare function loadWasm(options: LoadWasmOptions): Promise<void>;
159
146
 
160
- /**
161
- * High-level code-to-tokens API.
162
- *
163
- * It will use `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
164
- */
165
- declare function codeToTokens(internal: ShikiInternal, code: string, options: CodeToTokensOptions): TokensResult;
147
+ declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
166
148
 
167
- declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
149
+ declare class ShikiError extends Error {
150
+ constructor(message: string);
151
+ }
168
152
 
169
153
  declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
170
154
  declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource): Root;
@@ -393,11 +377,36 @@ type Space = "html" | "svg";
393
377
  */
394
378
  declare function codeToHtml(internal: ShikiInternal, code: string, options: CodeToHastOptions): string;
395
379
 
380
+ /**
381
+ * High-level code-to-tokens API.
382
+ *
383
+ * It will use `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
384
+ */
385
+ declare function codeToTokens(internal: ShikiInternal, code: string, options: CodeToTokensOptions): TokensResult;
386
+
387
+ declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
388
+
389
+ /**
390
+ * Code to tokens, with a simple theme.
391
+ */
392
+ declare function codeToTokensBase(internal: ShikiInternal, code: string, options?: CodeToTokensBaseOptions): ThemedToken[][];
393
+ declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
394
+
396
395
  /**
397
396
  * Get tokens with multiple themes
398
397
  */
399
398
  declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, options: CodeToTokensWithThemesOptions): ThemedTokenWithVariants[][];
400
399
 
400
+ /**
401
+ * Normalize a textmate theme to shiki theme
402
+ */
403
+ declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
404
+
405
+ /**
406
+ * A built-in transformer to add decorations to the highlighted code.
407
+ */
408
+ declare function transformerDecorations(): ShikiTransformer;
409
+
401
410
  declare function toArray<T>(x: MaybeArray<T>): T[];
402
411
  /**
403
412
  * Split a string into lines, each line preserves the line ending.
@@ -465,13 +474,4 @@ declare function createPositionConverter(code: string): {
465
474
  posToIndex: (line: number, character: number) => number;
466
475
  };
467
476
 
468
- /**
469
- * A built-in transformer to add decorations to the highlighted code.
470
- */
471
- declare function transformerDecorations(): ShikiTransformer;
472
-
473
- declare class ShikiError extends Error {
474
- constructor(message: string);
475
- }
476
-
477
477
  export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type CreateHighlighterFactory, CreatedBundledHighlighterOptions, GrammarState, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, JavaScriptRegexEngineOptions, LanguageInput, LoadWasmOptions, MaybeArray, MaybeGetter, PlainTextLanguage, Position, RegexEngine, 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, createHighlighterCoreSync, createJavaScriptRegexEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };