@shikijs/core 1.0.0-beta.0 → 1.0.0-beta.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.
@@ -1157,6 +1157,10 @@ interface TokenStyles {
1157
1157
  * 6 or 8 digit hex code representation of the token's color
1158
1158
  */
1159
1159
  color?: string;
1160
+ /**
1161
+ * 6 or 8 digit hex code representation of the token's background color
1162
+ */
1163
+ bgColor?: string;
1160
1164
  /**
1161
1165
  * Font style of token. Can be None/Italic/Bold/Underline
1162
1166
  */
@@ -1223,4 +1227,4 @@ interface ShikijiTransformerContext extends ShikiTransformerContext {
1223
1227
  interface ShikijiTransformerContextCommon extends ShikiTransformerContextCommon {
1224
1228
  }
1225
1229
 
1226
- export { type BundledLanguageInfo as $, type AnsiLanguage as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type ThemeRegistrationRaw as D, type Element as E, FontStyle as F, type ThemeRegistration as G, type HighlighterGeneric as H, type IGrammar as I, type ShikiTransformerContextMeta as J, type ShikiTransformerContext as K, type LanguageInput as L, type MaybeArray as M, type Nodes as N, type ShikiTransformer as O, type PlainTextLanguage as P, type HtmlRendererOptionsCommon as Q, type Root as R, type SpecialTheme as S, type ThemeInput as T, type HtmlRendererOptions as U, type ThemedTokenScopeExplanation as V, type ThemedTokenExplanation as W, type TokenBase as X, type TokenStyles as Y, type DynamicImportLanguageRegistration as Z, type DynamicImportThemeRegistration as _, type HighlighterCoreOptions as a, type BundledThemeInfo as a0, type ShikijiTransformer as a1, type ShikijiTransformerContext as a2, type ShikijiTransformerContextCommon as a3, Registry as a4, INITIAL as a5, type StateStack as a6, type IRawTheme as a7, type IGrammarConfiguration as a8, type IOnigLib as a9, type RegistryOptions as aa, type IRawThemeSetting as ab, type RequireKeys as b, type CodeToThemedTokensOptions as c, type ThemedToken as d, type CodeToTokensWithThemesOptions as e, type ThemedTokenWithVariants as f, type ShikiInternal as g, type ThemeRegistrationResolved as h, type TokenizeWithThemeOptions as i, type ShikiTransformerContextCommon as j, type RootContent as k, type ThemeRegistrationAny as l, type IRawGrammar as m, type SpecialLanguage as n, type Awaitable as o, type MaybeGetter as p, type MaybeModule as q, type StringLiteralUnion as r, type ResolveBundleKey as s, type LanguageRegistration as t, type CodeToHastOptionsCommon as u, type CodeOptionsSingleTheme as v, type CodeOptionsMultipleThemes as w, type CodeOptionsThemes as x, type CodeOptionsMeta as y, type TransformerOptions as z };
1230
+ export { type BundledLanguageInfo as $, type AnsiLanguage as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type TransformerOptions as D, type Element as E, FontStyle as F, type ThemeRegistrationRaw as G, type HighlighterGeneric as H, type IGrammar as I, type ThemeRegistration as J, type ShikiTransformerContextMeta as K, type LanguageInput as L, type MaybeArray as M, type Nodes as N, type ShikiTransformerContext as O, type PlainTextLanguage as P, type ShikiTransformer as Q, type Root as R, type SpecialTheme as S, type ThemeInput as T, type HtmlRendererOptionsCommon as U, type ThemedTokenScopeExplanation as V, type ThemedTokenExplanation as W, type TokenBase as X, type TokenStyles as Y, type DynamicImportLanguageRegistration as Z, type DynamicImportThemeRegistration as _, type HighlighterCoreOptions as a, type BundledThemeInfo as a0, type ShikijiTransformer as a1, type ShikijiTransformerContext as a2, type ShikijiTransformerContextCommon as a3, Registry as a4, INITIAL as a5, type StateStack as a6, type IRawTheme as a7, type IGrammarConfiguration as a8, type IOnigLib as a9, type RegistryOptions as aa, type IRawThemeSetting as ab, type RequireKeys as b, type CodeToThemedTokensOptions as c, type ThemedToken as d, type CodeToTokensWithThemesOptions as e, type ThemedTokenWithVariants as f, type ShikiInternal as g, type ThemeRegistrationResolved as h, type TokenizeWithThemeOptions as i, type ShikiTransformerContextCommon as j, type HtmlRendererOptions as k, type RootContent as l, type ThemeRegistrationAny as m, type IRawGrammar as n, type SpecialLanguage as o, type Awaitable as p, type MaybeGetter as q, type MaybeModule as r, type StringLiteralUnion as s, type ResolveBundleKey as t, type LanguageRegistration as u, type CodeToHastOptionsCommon as v, type CodeOptionsSingleTheme as w, type CodeOptionsMultipleThemes as x, type CodeOptionsThemes as y, type CodeOptionsMeta as z };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as HighlighterGeneric, a as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, T as ThemeInput, C as CodeToHastOptions, R as Root, b as RequireKeys, c as CodeToThemedTokensOptions, d as ThemedToken, e as CodeToTokensWithThemesOptions, f as ThemedTokenWithVariants, M as MaybeArray, S as SpecialTheme, E as Element, g as ShikiInternal, I as IGrammar, h as ThemeRegistrationResolved, i as TokenizeWithThemeOptions, j as ShikiTransformerContextCommon, N as Nodes$1, k as RootContent$1, l as ThemeRegistrationAny } from './chunk-types.mjs';
2
- export { A as AnsiLanguage, o as Awaitable, $ as BundledLanguageInfo, a0 as BundledThemeInfo, y as CodeOptionsMeta, w as CodeOptionsMultipleThemes, v as CodeOptionsSingleTheme, x as CodeOptionsThemes, u as CodeToHastOptionsCommon, Z as DynamicImportLanguageRegistration, _ as DynamicImportThemeRegistration, F as FontStyle, U as HtmlRendererOptions, Q as HtmlRendererOptionsCommon, m as IRawGrammar, t as LanguageRegistration, p as MaybeGetter, q as MaybeModule, P as PlainTextLanguage, m as RawGrammar, s as ResolveBundleKey, O as ShikiTransformer, K as ShikiTransformerContext, J as ShikiTransformerContextMeta, a1 as ShikijiTransformer, a2 as ShikijiTransformerContext, a3 as ShikijiTransformerContextCommon, n as SpecialLanguage, r as StringLiteralUnion, G as ThemeRegistration, D as ThemeRegistrationRaw, W as ThemedTokenExplanation, V as ThemedTokenScopeExplanation, X as TokenBase, Y as TokenStyles, z as TransformerOptions } from './chunk-types.mjs';
1
+ import { H as HighlighterGeneric, a as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, T as ThemeInput, C as CodeToHastOptions, R as Root, b as RequireKeys, c as CodeToThemedTokensOptions, d as ThemedToken, e as CodeToTokensWithThemesOptions, f as ThemedTokenWithVariants, M as MaybeArray, S as SpecialTheme, E as Element, g as ShikiInternal, I as IGrammar, h as ThemeRegistrationResolved, i as TokenizeWithThemeOptions, j as ShikiTransformerContextCommon, k as HtmlRendererOptions, N as Nodes$1, l as RootContent$1, m as ThemeRegistrationAny } from './chunk-types.mjs';
2
+ export { A as AnsiLanguage, p as Awaitable, $ as BundledLanguageInfo, a0 as BundledThemeInfo, z as CodeOptionsMeta, x as CodeOptionsMultipleThemes, w as CodeOptionsSingleTheme, y as CodeOptionsThemes, v as CodeToHastOptionsCommon, Z as DynamicImportLanguageRegistration, _ as DynamicImportThemeRegistration, F as FontStyle, U as HtmlRendererOptionsCommon, n as IRawGrammar, u as LanguageRegistration, q as MaybeGetter, r as MaybeModule, P as PlainTextLanguage, n as RawGrammar, t as ResolveBundleKey, Q as ShikiTransformer, O as ShikiTransformerContext, K as ShikiTransformerContextMeta, a1 as ShikijiTransformer, a2 as ShikijiTransformerContext, a3 as ShikijiTransformerContextCommon, o as SpecialLanguage, s as StringLiteralUnion, J as ThemeRegistration, G as ThemeRegistrationRaw, W as ThemedTokenExplanation, V as ThemedTokenScopeExplanation, X as TokenBase, Y as TokenStyles, D as TransformerOptions } from './chunk-types.mjs';
3
3
  import { L as LoadWasmOptions } from './chunk-index.mjs';
4
4
  export { l as loadWasm } from './chunk-index.mjs';
5
5
 
@@ -122,6 +122,7 @@ declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: Theme
122
122
  declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
123
123
 
124
124
  declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
125
+ declare function tokensToHast(tokens: ThemedToken[][], options: HtmlRendererOptions, transformerContext: ShikiTransformerContextCommon): Root;
125
126
 
126
127
  type FormatSmartOptions = {
127
128
  /**
@@ -360,4 +361,4 @@ declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, o
360
361
  */
361
362
  declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
362
363
 
363
- export { BundledHighlighterOptions, CodeToHastOptions, CodeToThemedTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar, type HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, IGrammar, LanguageInput, MaybeArray, RequireKeys, ShikiInternal, ShikiTransformerContextCommon, type ShorthandsBundle, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokenizeWithThemeOptions, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToThemedTokens, codeToTokensWithThemes, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, toHtml as hastToHtml, isNoneTheme, isPlainLang, isPlaintext, isSpecialLang, isSpecialTheme, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme };
364
+ export { BundledHighlighterOptions, CodeToHastOptions, CodeToThemedTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar, type HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, HtmlRendererOptions, IGrammar, LanguageInput, MaybeArray, RequireKeys, ShikiInternal, ShikiTransformerContextCommon, type ShorthandsBundle, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokenizeWithThemeOptions, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToThemedTokens, codeToTokensWithThemes, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, toHtml as hastToHtml, isNoneTheme, isPlainLang, isPlaintext, isSpecialLang, isSpecialTheme, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast };
package/dist/index.mjs CHANGED
@@ -372,10 +372,15 @@ function tokenizeAnsiWithTheme(theme, fileContents, options) {
372
372
  const parser = createAnsiSequenceParser();
373
373
  return lines.map(line => parser.parse(line[0]).map((token) => {
374
374
  let color;
375
- if (token.decorations.has('reverse'))
375
+ let bgColor;
376
+ if (token.decorations.has('reverse')) {
376
377
  color = token.background ? colorPalette.value(token.background) : theme.bg;
377
- else
378
+ bgColor = token.foreground ? colorPalette.value(token.foreground) : theme.fg;
379
+ }
380
+ else {
378
381
  color = token.foreground ? colorPalette.value(token.foreground) : theme.fg;
382
+ bgColor = token.background ? colorPalette.value(token.background) : undefined;
383
+ }
379
384
  color = applyColorReplacements(color, colorReplacements);
380
385
  if (token.decorations.has('dim'))
381
386
  color = dimColor(color);
@@ -390,6 +395,7 @@ function tokenizeAnsiWithTheme(theme, fileContents, options) {
390
395
  content: token.value,
391
396
  offset: line[1], // TODO: more accurate offset? might need to fork ansi-sequence-parser
392
397
  color,
398
+ bgColor,
393
399
  fontStyle,
394
400
  };
395
401
  }));
@@ -567,7 +573,6 @@ function codeToTokensWithThemes(internal, code, options) {
567
573
  const tokens = syncThemesTokenization(...themes.map(t => codeToThemedTokens(internal, code, {
568
574
  ...options,
569
575
  theme: t.theme,
570
- includeExplanation: false,
571
576
  })));
572
577
  const mergedTokens = tokens[0]
573
578
  .map((line, lineIdx) => line
@@ -667,10 +672,7 @@ function codeToHast(internal, code, options, transformerContext = {
667
672
  rootStyle = defaultColor ? undefined : [fg, bg].join(';');
668
673
  }
669
674
  else if ('theme' in options) {
670
- tokens = codeToThemedTokens(internal, input, {
671
- ...options,
672
- includeExplanation: false,
673
- });
675
+ tokens = codeToThemedTokens(internal, input, options);
674
676
  const _theme = internal.getTheme(options.theme);
675
677
  bg = _theme.bg;
676
678
  fg = _theme.fg;
@@ -710,7 +712,8 @@ function mergeToken(merged, variantsOrder, cssVariablePrefix, defaultColor) {
710
712
  acc[key] = value;
711
713
  }
712
714
  else {
713
- const varKey = cssVariablePrefix + variantsOrder[idx] + (key === 'color' ? '' : `-${key}`);
715
+ const keyName = key === 'color' ? '' : key === 'background-color' ? '-bg' : `-${key}`;
716
+ const varKey = cssVariablePrefix + variantsOrder[idx] + (key === 'color' ? '' : keyName);
714
717
  if (acc[key])
715
718
  acc[key] += `;${varKey}:${value}`;
716
719
  else
@@ -816,6 +819,8 @@ function getTokenStyleObject(token) {
816
819
  const styles = {};
817
820
  if (token.color)
818
821
  styles.color = token.color;
822
+ if (token.bgColor)
823
+ styles['background-color'] = token.bgColor;
819
824
  if (token.fontStyle) {
820
825
  if (token.fontStyle & FontStyle.Italic)
821
826
  styles['font-style'] = 'italic';
@@ -5184,4 +5189,4 @@ function createSingletonShorthands(getHighlighter) {
5184
5189
  };
5185
5190
  }
5186
5191
 
5187
- export { FontStyle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToThemedTokens, codeToTokensWithThemes, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, toHtml as hastToHtml, isNoneTheme, isPlainLang, isPlaintext, isSpecialLang, isSpecialTheme, loadWasm, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme };
5192
+ export { FontStyle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToThemedTokens, codeToTokensWithThemes, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, toHtml as hastToHtml, isNoneTheme, isPlainLang, isPlaintext, isSpecialLang, isSpecialTheme, loadWasm, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast };
@@ -1,5 +1,5 @@
1
1
  import { F as FontStyle } from './chunk-types.mjs';
2
- export { I as IGrammar, a8 as IGrammarConfiguration, a5 as INITIAL, a9 as IOnigLib, m as IRawGrammar, a7 as IRawTheme, ab as IRawThemeSetting, a4 as Registry, aa as RegistryOptions, a6 as StateStack } from './chunk-types.mjs';
2
+ export { I as IGrammar, a8 as IGrammarConfiguration, a5 as INITIAL, a9 as IOnigLib, n as IRawGrammar, a7 as IRawTheme, ab as IRawThemeSetting, a4 as Registry, aa as RegistryOptions, a6 as StateStack } from './chunk-types.mjs';
3
3
  import './chunk-index.mjs';
4
4
 
5
5
  declare const enum TemporaryStandardTokenType {
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as AnsiLanguage, o as Awaitable, B as BundledHighlighterOptions, $ as BundledLanguageInfo, a0 as BundledThemeInfo, y as CodeOptionsMeta, w as CodeOptionsMultipleThemes, v as CodeOptionsSingleTheme, x as CodeOptionsThemes, C as CodeToHastOptions, u as CodeToHastOptionsCommon, c as CodeToThemedTokensOptions, e as CodeToTokensWithThemesOptions, Z as DynamicImportLanguageRegistration, _ as DynamicImportThemeRegistration, F as FontStyle, I as Grammar, a as HighlighterCoreOptions, H as HighlighterGeneric, U as HtmlRendererOptions, Q as HtmlRendererOptionsCommon, I as IGrammar, m as IRawGrammar, L as LanguageInput, t as LanguageRegistration, M as MaybeArray, p as MaybeGetter, q as MaybeModule, P as PlainTextLanguage, m as RawGrammar, b as RequireKeys, s as ResolveBundleKey, g as ShikiInternal, O as ShikiTransformer, K as ShikiTransformerContext, j as ShikiTransformerContextCommon, J as ShikiTransformerContextMeta, a1 as ShikijiTransformer, a2 as ShikijiTransformerContext, a3 as ShikijiTransformerContextCommon, n as SpecialLanguage, S as SpecialTheme, r as StringLiteralUnion, T as ThemeInput, G as ThemeRegistration, l as ThemeRegistrationAny, D as ThemeRegistrationRaw, h as ThemeRegistrationResolved, d as ThemedToken, W as ThemedTokenExplanation, V as ThemedTokenScopeExplanation, f as ThemedTokenWithVariants, X as TokenBase, Y as TokenStyles, i as TokenizeWithThemeOptions, z as TransformerOptions } from './chunk-types.mjs';
1
+ export { A as AnsiLanguage, p as Awaitable, B as BundledHighlighterOptions, $ as BundledLanguageInfo, a0 as BundledThemeInfo, z as CodeOptionsMeta, x as CodeOptionsMultipleThemes, w as CodeOptionsSingleTheme, y as CodeOptionsThemes, C as CodeToHastOptions, v as CodeToHastOptionsCommon, c as CodeToThemedTokensOptions, e as CodeToTokensWithThemesOptions, Z as DynamicImportLanguageRegistration, _ as DynamicImportThemeRegistration, F as FontStyle, I as Grammar, a as HighlighterCoreOptions, H as HighlighterGeneric, k as HtmlRendererOptions, U as HtmlRendererOptionsCommon, I as IGrammar, n as IRawGrammar, L as LanguageInput, u as LanguageRegistration, M as MaybeArray, q as MaybeGetter, r as MaybeModule, P as PlainTextLanguage, n as RawGrammar, b as RequireKeys, t as ResolveBundleKey, g as ShikiInternal, Q as ShikiTransformer, O as ShikiTransformerContext, j as ShikiTransformerContextCommon, K as ShikiTransformerContextMeta, a1 as ShikijiTransformer, a2 as ShikijiTransformerContext, a3 as ShikijiTransformerContextCommon, o as SpecialLanguage, S as SpecialTheme, s as StringLiteralUnion, T as ThemeInput, J as ThemeRegistration, m as ThemeRegistrationAny, G as ThemeRegistrationRaw, h as ThemeRegistrationResolved, d as ThemedToken, W as ThemedTokenExplanation, V as ThemedTokenScopeExplanation, f as ThemedTokenWithVariants, X as TokenBase, Y as TokenStyles, i as TokenizeWithThemeOptions, D as TransformerOptions } from './chunk-types.mjs';
2
2
  import './chunk-index.mjs';
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.0",
4
+ "version": "1.0.0-beta.1",
5
5
  "description": "Core of Shiki",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -40,8 +40,8 @@
40
40
  "types": "./dist/index.d.mts",
41
41
  "typesVersions": {
42
42
  "*": {
43
- "wasm": [
44
- "./dist/wasm.d.mts"
43
+ "wasm-inlined": [
44
+ "./dist/wasm-inlined.d.mts"
45
45
  ],
46
46
  "types": [
47
47
  "./dist/types.d.mts"