@shikijs/core 1.0.0-beta.6 → 1.0.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.
@@ -848,25 +848,6 @@ interface ShikiTransformer {
848
848
  * This hook will only be called with `codeToHtml`.
849
849
  */
850
850
  postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void;
851
- /**
852
- * @deprecated Use `span` instead
853
- */
854
- token?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element) => Element | void;
855
- }
856
- /**
857
- * @deprecated Rnamed to `ShikiTransformer`
858
- */
859
- interface ShikijiTransformer extends ShikiTransformer {
860
- }
861
- /**
862
- * @deprecated Rnamed to `ShikiTransformerContext`
863
- */
864
- interface ShikijiTransformerContext extends ShikiTransformerContext {
865
- }
866
- /**
867
- * @deprecated Rnamed to `ShikiTransformerContextCommon`
868
- */
869
- interface ShikijiTransformerContextCommon extends ShikiTransformerContextCommon {
870
851
  }
871
852
 
872
853
  interface DecorationOptions {
@@ -1235,4 +1216,4 @@ declare enum FontStyle {
1235
1216
  Underline = 4
1236
1217
  }
1237
1218
 
1238
- export { type DynamicImportThemeRegistration as $, type ShikiTransformer as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type AnsiLanguage as D, type Element as E, FontStyle as F, type ResolveBundleKey as G, type HighlighterCoreOptions as H, INITIAL as I, type LanguageRegistration as J, type BundledLanguageInfo as K, type LanguageInput as L, type MaybeArray as M, type Nodes as N, type DynamicImportLanguageRegistration as O, type PlainTextLanguage as P, type CodeOptionsSingleTheme as Q, Registry as R, type StateStack as S, type ThemeInput as T, type CodeOptionsMultipleThemes as U, type CodeOptionsThemes as V, type CodeToHastOptionsCommon as W, type CodeOptionsMeta as X, type CodeToHastRenderOptionsCommon as Y, type ThemeRegistrationRaw as Z, type ThemeRegistration as _, type IRawTheme as a, type BundledThemeInfo as a0, type ThemedTokenScopeExplanation as a1, type ThemedTokenExplanation as a2, type TokenBase as a3, type TransformerOptions as a4, type ShikiTransformerContextMeta as a5, type ShikiTransformerContext as a6, type ShikijiTransformer as a7, type ShikijiTransformerContext as a8, type ShikijiTransformerContextCommon as a9, type Awaitable as aa, type MaybeGetter as ab, type MaybeModule as ac, type StringLiteralUnion as ad, type DecorationOptions as ae, type DecorationItem as af, type ResolvedDecorationItem as ag, type DecorationTransformType as ah, type Offset as ai, type OffsetOrPosition as aj, type ResolvedPosition as ak, 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 Root 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 TokenStyles as r, type Position as s, type ThemeRegistrationResolved as t, type TokenizeWithThemeOptions as u, type ShikiTransformerContextCommon as v, type CodeToHastRenderOptions as w, type ShikiTransformerContextSource as x, type RootContent as y, type ThemeRegistrationAny as z };
1219
+ export { type DynamicImportThemeRegistration as $, type ShikiTransformer as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type AnsiLanguage as D, type Element as E, FontStyle as F, type ResolveBundleKey as G, type HighlighterCoreOptions as H, INITIAL as I, type LanguageRegistration as J, type BundledLanguageInfo as K, type LanguageInput as L, type MaybeArray as M, type Nodes as N, type DynamicImportLanguageRegistration as O, type PlainTextLanguage as P, type CodeOptionsSingleTheme as Q, Registry as R, type StateStack as S, type ThemeInput as T, type CodeOptionsMultipleThemes as U, type CodeOptionsThemes as V, type CodeToHastOptionsCommon as W, type CodeOptionsMeta as X, type CodeToHastRenderOptionsCommon as Y, type ThemeRegistrationRaw as Z, type ThemeRegistration as _, type IRawTheme as a, type BundledThemeInfo as a0, type ThemedTokenScopeExplanation as a1, type ThemedTokenExplanation as a2, type TokenBase as a3, type TransformerOptions as a4, type ShikiTransformerContextMeta as a5, type ShikiTransformerContext as a6, type Awaitable as a7, type MaybeGetter as a8, type MaybeModule as a9, type StringLiteralUnion as aa, type DecorationOptions as ab, type DecorationItem as ac, type ResolvedDecorationItem as ad, type DecorationTransformType as ae, type Offset as af, type OffsetOrPosition as ag, type ResolvedPosition as ah, 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 Root 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 TokenStyles as r, type Position as s, type ThemeRegistrationResolved as t, type TokenizeWithThemeOptions as u, type ShikiTransformerContextCommon as v, type CodeToHastRenderOptions as w, type ShikiTransformerContextSource as x, type RootContent as y, type ThemeRegistrationAny as z };
package/dist/index.d.mts CHANGED
@@ -1,10 +1,9 @@
1
- import { HighlighterGeneric, ShikiInternal } from './types.mjs';
1
+ import { HighlighterCore, HighlighterGeneric, ShikiInternal } from './types.mjs';
2
2
  import { H as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, T as ThemeInput, C as CodeToHastOptions, h as Root, i as CodeToTokensOptions, j as TokensResult, k as RequireKeys, l as CodeToTokensBaseOptions, m as ThemedToken, n as CodeToTokensWithThemesOptions, o as ThemedTokenWithVariants, M as MaybeArray, P as PlainTextLanguage, p as SpecialLanguage, q as SpecialTheme, E as Element, r as TokenStyles, s as Position, c as IGrammar, t as ThemeRegistrationResolved, u as TokenizeWithThemeOptions, v as ShikiTransformerContextCommon, w as CodeToHastRenderOptions, x as ShikiTransformerContextSource, N as Nodes$1, y as RootContent$1, z as ThemeRegistrationAny, A as ShikiTransformer } from './chunk-tokens.mjs';
3
- export { D as AnsiLanguage, aa as Awaitable, K as BundledLanguageInfo, a0 as BundledThemeInfo, X as CodeOptionsMeta, U as CodeOptionsMultipleThemes, Q as CodeOptionsSingleTheme, V as CodeOptionsThemes, W as CodeToHastOptionsCommon, Y as CodeToHastRenderOptionsCommon, af as DecorationItem, ae as DecorationOptions, ah as DecorationTransformType, O as DynamicImportLanguageRegistration, $ as DynamicImportThemeRegistration, F as FontStyle, b as IRawGrammar, J as LanguageRegistration, ab as MaybeGetter, ac as MaybeModule, ai as Offset, aj as OffsetOrPosition, b as RawGrammar, a as RawTheme, g as RawThemeSetting, G as ResolveBundleKey, ag as ResolvedDecorationItem, ak as ResolvedPosition, a6 as ShikiTransformerContext, a5 as ShikiTransformerContextMeta, a7 as ShikijiTransformer, a8 as ShikijiTransformerContext, a9 as ShikijiTransformerContextCommon, ad as StringLiteralUnion, _ as ThemeRegistration, Z as ThemeRegistrationRaw, a2 as ThemedTokenExplanation, a1 as ThemedTokenScopeExplanation, a3 as TokenBase, a4 as TransformerOptions } from './chunk-tokens.mjs';
3
+ export { D as AnsiLanguage, a7 as Awaitable, K as BundledLanguageInfo, a0 as BundledThemeInfo, X as CodeOptionsMeta, U as CodeOptionsMultipleThemes, Q as CodeOptionsSingleTheme, V as CodeOptionsThemes, W as CodeToHastOptionsCommon, Y as CodeToHastRenderOptionsCommon, ac as DecorationItem, ab as DecorationOptions, ae as DecorationTransformType, O as DynamicImportLanguageRegistration, $ as DynamicImportThemeRegistration, F as FontStyle, J as LanguageRegistration, a8 as MaybeGetter, a9 as MaybeModule, af as Offset, ag as OffsetOrPosition, b as RawGrammar, a as RawTheme, g as RawThemeSetting, G as ResolveBundleKey, ad as ResolvedDecorationItem, ah as ResolvedPosition, a6 as ShikiTransformerContext, a5 as ShikiTransformerContextMeta, aa as StringLiteralUnion, _ as ThemeRegistration, Z as ThemeRegistrationRaw, a2 as ThemedTokenExplanation, a1 as ThemedTokenScopeExplanation, a3 as TokenBase, a4 as TransformerOptions } from './chunk-tokens.mjs';
4
4
  import { L as LoadWasmOptions } from './chunk-index.mjs';
5
5
  export { l as loadWasm } from './chunk-index.mjs';
6
6
 
7
- type HighlighterCore = HighlighterGeneric<never, never>;
8
7
  /**
9
8
  * Create a Shiki core highlighter instance, with no languages or themes bundled.
10
9
  * Wasm and each language and theme must be loaded manually.
@@ -64,10 +63,6 @@ interface ShorthandsBundle<L extends string, T extends string> {
64
63
  * @internal
65
64
  */
66
65
  getSingletonHighlighter: () => Promise<HighlighterGeneric<L, T>>;
67
- /**
68
- * @deprecated Use `codeToTokensBase` instead.
69
- */
70
- codeToThemedTokens: (code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>) => Promise<ThemedToken[][]>;
71
66
  }
72
67
  declare function createSingletonShorthands<L extends string, T extends string>(getHighlighter: GetHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
73
68
 
@@ -117,10 +112,6 @@ declare function splitToken<T extends Pick<ThemedToken, 'content' | 'offset'>>(t
117
112
  */
118
113
  declare function splitTokens<T extends Pick<ThemedToken, 'content' | 'offset'>>(tokens: T[][], breakpoints: number[] | Set<number>): T[][];
119
114
  declare function applyColorReplacements(color: string, replacements?: Record<string, string>): string;
120
- /**
121
- * @deprecated Use `isPlainLang` instead.
122
- */
123
- declare const isPlaintext: typeof isPlainLang;
124
115
  declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
125
116
  declare function stringifyTokenStyle(token: Record<string, string>): string;
126
117
  /**
@@ -406,4 +397,4 @@ declare class ShikiError extends Error {
406
397
  constructor(message: string);
407
398
  }
408
399
 
409
- export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar, type HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, IGrammar, 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, createPositionConverter, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isPlaintext, isSpecialLang, isSpecialTheme, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
400
+ export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar, 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, createPositionConverter, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
package/dist/index.mjs CHANGED
@@ -124,10 +124,6 @@ function splitTokens(tokens, breakpoints) {
124
124
  function applyColorReplacements(color, replacements) {
125
125
  return replacements?.[color.toLowerCase()] || color;
126
126
  }
127
- /**
128
- * @deprecated Use `isPlainLang` instead.
129
- */
130
- const isPlaintext = isPlainLang;
131
127
  function getTokenStyleObject(token) {
132
128
  const styles = {};
133
129
  if (token.color)
@@ -520,7 +516,7 @@ function codeToTokensBase(internal, code, options = {}) {
520
516
  const { theme, colorMap } = internal.setTheme(themeName);
521
517
  if (lang === 'ansi')
522
518
  return tokenizeAnsiWithTheme(theme, code, options);
523
- const _grammar = internal.getLangGrammar(lang);
519
+ const _grammar = internal.getLanguage(lang);
524
520
  return tokenizeWithTheme(code, _grammar, theme, colorMap, options);
525
521
  }
526
522
  function tokenizeWithTheme(code, grammar, theme, colorMap, options) {
@@ -1086,7 +1082,7 @@ function tokensToHast(tokens, options, transformerContext) {
1086
1082
  if (style)
1087
1083
  tokenNode.properties.style = style;
1088
1084
  for (const transformer of transformers)
1089
- tokenNode = (transformer?.span || transformer?.token)?.call(context, tokenNode, idx + 1, col, lineNode) || tokenNode;
1085
+ tokenNode = transformer?.span?.call(context, tokenNode, idx + 1, col, lineNode) || tokenNode;
1090
1086
  lineNode.children.push(tokenNode);
1091
1087
  col += token.content.length;
1092
1088
  }
@@ -5282,7 +5278,7 @@ async function getShikiInternal(options = {}) {
5282
5278
  Object.assign(_registry.alias, options.langAlias);
5283
5279
  await _registry.init();
5284
5280
  let _lastTheme;
5285
- function getLangGrammar(name) {
5281
+ function getLanguage(name) {
5286
5282
  const _lang = _registry.getGrammar(typeof name === 'string' ? name : name.name);
5287
5283
  if (!_lang)
5288
5284
  throw new ShikiError(`Language \`${name}\` not found, you may need to load it first`);
@@ -5322,20 +5318,12 @@ async function getShikiInternal(options = {}) {
5322
5318
  ? null
5323
5319
  : _registry.loadTheme(await normalizeGetter(theme))));
5324
5320
  }
5325
- function updateAlias(alias) {
5326
- Object.assign(_registry.alias, alias);
5327
- }
5328
- function getAlias() {
5329
- return _registry.alias;
5330
- }
5331
5321
  return {
5332
5322
  setTheme,
5333
5323
  getTheme,
5334
- getLangGrammar,
5324
+ getLanguage,
5335
5325
  getLoadedThemes,
5336
5326
  getLoadedLanguages,
5337
- getAlias,
5338
- updateAlias,
5339
5327
  loadLanguage,
5340
5328
  loadTheme,
5341
5329
  };
@@ -5355,16 +5343,8 @@ async function getHighlighterCore(options = {}) {
5355
5343
  codeToTokens: (code, options) => codeToTokens(internal, code, options),
5356
5344
  codeToHast: (code, options) => codeToHast(internal, code, options),
5357
5345
  codeToHtml: (code, options) => codeToHtml(internal, code, options),
5358
- loadLanguage: internal.loadLanguage,
5359
- loadTheme: internal.loadTheme,
5360
- getTheme: internal.getTheme,
5361
- getLangGrammar: internal.getLangGrammar,
5362
- setTheme: internal.setTheme,
5363
- getLoadedThemes: internal.getLoadedThemes,
5364
- getLoadedLanguages: internal.getLoadedLanguages,
5346
+ ...internal,
5365
5347
  getInternalContext: () => internal,
5366
- /** @deprecated */
5367
- codeToThemedTokens: (code, options) => codeToTokensBase(internal, code, options),
5368
5348
  };
5369
5349
  }
5370
5350
 
@@ -5466,13 +5446,6 @@ function createSingletonShorthands(getHighlighter) {
5466
5446
  const shiki = await _getHighlighter(options);
5467
5447
  return shiki.codeToTokensBase(code, options);
5468
5448
  },
5469
- /**
5470
- * @deprecated Use `codeToTokensBase` instead.
5471
- */
5472
- async codeToThemedTokens(code, options) {
5473
- const shiki = await _getHighlighter(options);
5474
- return shiki.codeToThemedTokens(code, options);
5475
- },
5476
5449
  async codeToTokensWithThemes(code, options) {
5477
5450
  const shiki = await _getHighlighter({
5478
5451
  lang: options.lang,
@@ -5483,4 +5456,4 @@ function createSingletonShorthands(getHighlighter) {
5483
5456
  };
5484
5457
  }
5485
5458
 
5486
- export { FontStyle, ShikiError, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createPositionConverter, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isPlaintext, isSpecialLang, isSpecialTheme, loadWasm, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
5459
+ export { FontStyle, ShikiError, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createPositionConverter, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
package/dist/types.d.mts CHANGED
@@ -1,25 +1,52 @@
1
- import { z as ThemeRegistrationAny, t as ThemeRegistrationResolved, J as LanguageRegistration, c as IGrammar, L as LanguageInput, p as SpecialLanguage, T as ThemeInput, q as SpecialTheme, C as CodeToHastOptions, G as ResolveBundleKey, h as Root, i as CodeToTokensOptions, j as TokensResult, l as CodeToTokensBaseOptions, m as ThemedToken, n as CodeToTokensWithThemesOptions, o as ThemedTokenWithVariants } from './chunk-tokens.mjs';
2
- export { D as AnsiLanguage, aa as Awaitable, B as BundledHighlighterOptions, K as BundledLanguageInfo, a0 as BundledThemeInfo, X as CodeOptionsMeta, U as CodeOptionsMultipleThemes, Q as CodeOptionsSingleTheme, V as CodeOptionsThemes, W as CodeToHastOptionsCommon, w as CodeToHastRenderOptions, Y as CodeToHastRenderOptionsCommon, af as DecorationItem, ae as DecorationOptions, ah as DecorationTransformType, O as DynamicImportLanguageRegistration, $ as DynamicImportThemeRegistration, F as FontStyle, H as HighlighterCoreOptions, b as IRawGrammar, M as MaybeArray, ab as MaybeGetter, ac as MaybeModule, ai as Offset, aj as OffsetOrPosition, P as PlainTextLanguage, s as Position, b as RawGrammar, a as RawTheme, g as RawThemeSetting, k as RequireKeys, ag as ResolvedDecorationItem, ak as ResolvedPosition, A as ShikiTransformer, a6 as ShikiTransformerContext, v as ShikiTransformerContextCommon, a5 as ShikiTransformerContextMeta, x as ShikiTransformerContextSource, a7 as ShikijiTransformer, a8 as ShikijiTransformerContext, a9 as ShikijiTransformerContextCommon, ad as StringLiteralUnion, _ as ThemeRegistration, Z as ThemeRegistrationRaw, a2 as ThemedTokenExplanation, a1 as ThemedTokenScopeExplanation, a3 as TokenBase, r as TokenStyles, u as TokenizeWithThemeOptions, a4 as TransformerOptions } from './chunk-tokens.mjs';
1
+ import { T as ThemeInput, q as SpecialTheme, L as LanguageInput, p as SpecialLanguage, z as ThemeRegistrationAny, t as ThemeRegistrationResolved, J as LanguageRegistration, c as IGrammar, C as CodeToHastOptions, G as ResolveBundleKey, h as Root, i as CodeToTokensOptions, j as TokensResult, l as CodeToTokensBaseOptions, m as ThemedToken, n as CodeToTokensWithThemesOptions, o as ThemedTokenWithVariants } from './chunk-tokens.mjs';
2
+ export { D as AnsiLanguage, a7 as Awaitable, B as BundledHighlighterOptions, K as BundledLanguageInfo, a0 as BundledThemeInfo, X as CodeOptionsMeta, U as CodeOptionsMultipleThemes, Q as CodeOptionsSingleTheme, V as CodeOptionsThemes, W as CodeToHastOptionsCommon, w as CodeToHastRenderOptions, Y as CodeToHastRenderOptionsCommon, ac as DecorationItem, ab as DecorationOptions, ae as DecorationTransformType, O as DynamicImportLanguageRegistration, $ as DynamicImportThemeRegistration, F as FontStyle, H as HighlighterCoreOptions, M as MaybeArray, a8 as MaybeGetter, a9 as MaybeModule, af as Offset, ag as OffsetOrPosition, P as PlainTextLanguage, s as Position, b as RawGrammar, a as RawTheme, g as RawThemeSetting, k as RequireKeys, ad as ResolvedDecorationItem, ah as ResolvedPosition, A as ShikiTransformer, a6 as ShikiTransformerContext, v as ShikiTransformerContextCommon, a5 as ShikiTransformerContextMeta, x as ShikiTransformerContextSource, aa as StringLiteralUnion, _ as ThemeRegistration, Z as ThemeRegistrationRaw, a2 as ThemedTokenExplanation, a1 as ThemedTokenScopeExplanation, a3 as TokenBase, r as TokenStyles, u as TokenizeWithThemeOptions, a4 as TransformerOptions } from './chunk-tokens.mjs';
3
3
  import './chunk-index.mjs';
4
4
 
5
- interface ShikiInternal {
6
- setTheme: (name: string | ThemeRegistrationAny) => {
5
+ /**
6
+ * Internal context of Shiki, core textmate logic
7
+ */
8
+ interface ShikiInternal<BundledLangKeys extends string = never, BundledThemeKeys extends string = never> {
9
+ /**
10
+ * Load a theme to the highlighter, so later it can be used synchronously.
11
+ */
12
+ loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
13
+ /**
14
+ * Load a language to the highlighter, so later it can be used synchronously.
15
+ */
16
+ loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
17
+ /**
18
+ * Get the registered theme object
19
+ */
20
+ getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
21
+ /**
22
+ * Get the registered language object
23
+ */
24
+ getLanguage: (name: string | LanguageRegistration) => IGrammar;
25
+ /**
26
+ * Set the current theme and get the resolved theme object and color map.
27
+ * @internal
28
+ */
29
+ setTheme: (themeName: string | ThemeRegistrationAny) => {
7
30
  theme: ThemeRegistrationResolved;
8
31
  colorMap: string[];
9
32
  };
10
- getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
11
- getLangGrammar: (name: string | LanguageRegistration) => IGrammar;
12
- getLoadedThemes: () => string[];
33
+ /**
34
+ * Get the names of loaded languages
35
+ *
36
+ * Special-handled languages like `text`, `plain` and `ansi` are not included.
37
+ */
13
38
  getLoadedLanguages: () => string[];
14
- loadLanguage: (...langs: (LanguageInput | SpecialLanguage)[]) => Promise<void>;
15
- loadTheme: (...themes: (ThemeInput | SpecialTheme)[]) => Promise<void>;
16
- getAlias: () => Record<string, string>;
17
- updateAlias: (alias: Record<string, string>) => void;
39
+ /**
40
+ * Get the names of loaded themes
41
+ *
42
+ * Special-handled themes like `none` are not included.
43
+ */
44
+ getLoadedThemes: () => string[];
18
45
  }
19
46
  /**
20
47
  * Generic instance interface of Shiki
21
48
  */
22
- interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> {
49
+ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> extends ShikiInternal<BundledLangKeys, BundledThemeKeys> {
23
50
  /**
24
51
  * Get highlighted code in HTML string
25
52
  */
@@ -46,43 +73,6 @@ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys ex
46
73
  * @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
47
74
  */
48
75
  codeToTokensWithThemes: (code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedTokenWithVariants[][];
49
- /**
50
- * @deprecated Renamed to `codeToTokensBase`, or use high-level `codeToTokens` directly.
51
- */
52
- codeToThemedTokens: (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedToken[][];
53
- /**
54
- * Load a theme to the highlighter, so later it can be used synchronously.
55
- */
56
- loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
57
- /**
58
- * Load a language to the highlighter, so later it can be used synchronously.
59
- */
60
- loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
61
- /**
62
- * Get the registered theme object
63
- */
64
- getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
65
- /**
66
- * Get the registered language object
67
- */
68
- getLangGrammar: (name: string | LanguageRegistration) => IGrammar;
69
- /**
70
- * Set the current theme and get the resolved theme object and color map.
71
- * @internal
72
- */
73
- setTheme: ShikiInternal['setTheme'];
74
- /**
75
- * Get the names of loaded languages
76
- *
77
- * Special-handled languages like `text`, `plain` and `ansi` are not included.
78
- */
79
- getLoadedLanguages: () => string[];
80
- /**
81
- * Get the names of loaded themes
82
- *
83
- * Special-handled themes like `none` are not included.
84
- */
85
- getLoadedThemes: () => string[];
86
76
  /**
87
77
  * Get internal context object
88
78
  * @internal
@@ -90,5 +80,9 @@ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys ex
90
80
  */
91
81
  getInternalContext: () => ShikiInternal;
92
82
  }
83
+ /**
84
+ * The fine-grained core Shiki highlighter instance.
85
+ */
86
+ type HighlighterCore = HighlighterGeneric<never, never>;
93
87
 
94
- export { CodeToHastOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, IGrammar as Grammar, type HighlighterGeneric, IGrammar, LanguageInput, LanguageRegistration, ResolveBundleKey, type ShikiInternal, SpecialLanguage, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokensResult };
88
+ export { CodeToHastOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, IGrammar as Grammar, type HighlighterCore, type HighlighterGeneric, LanguageInput, LanguageRegistration, ResolveBundleKey, type ShikiInternal, SpecialLanguage, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokensResult };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/core",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.6",
4
+ "version": "1.0.0",
5
5
  "description": "Core of Shiki",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",