@shikijs/core 3.14.0 → 3.15.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.
Files changed (2) hide show
  1. package/dist/index.mjs +34 -11
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -778,17 +778,35 @@ function createColorPalette(namedColorsMap = defaultNamedColorsMap) {
778
778
  };
779
779
  }
780
780
 
781
+ const defaultAnsiColors = {
782
+ black: "#000000",
783
+ red: "#cd3131",
784
+ green: "#0DBC79",
785
+ yellow: "#E5E510",
786
+ blue: "#2472C8",
787
+ magenta: "#BC3FBC",
788
+ cyan: "#11A8CD",
789
+ white: "#E5E5E5",
790
+ brightBlack: "#666666",
791
+ brightRed: "#F14C4C",
792
+ brightGreen: "#23D18B",
793
+ brightYellow: "#F5F543",
794
+ brightBlue: "#3B8EEA",
795
+ brightMagenta: "#D670D6",
796
+ brightCyan: "#29B8DB",
797
+ brightWhite: "#FFFFFF"
798
+ };
781
799
  function tokenizeAnsiWithTheme(theme, fileContents, options) {
782
800
  const colorReplacements = resolveColorReplacements(theme, options);
783
801
  const lines = splitLines(fileContents);
784
- const colorPalette = createColorPalette(
785
- Object.fromEntries(
786
- namedColors.map((name) => [
787
- name,
788
- theme.colors?.[`terminal.ansi${name[0].toUpperCase()}${name.substring(1)}`]
789
- ])
790
- )
802
+ const ansiPalette = Object.fromEntries(
803
+ namedColors.map((name) => {
804
+ const key = `terminal.ansi${name[0].toUpperCase()}${name.substring(1)}`;
805
+ const themeColor = theme.colors?.[key];
806
+ return [name, themeColor || defaultAnsiColors[name]];
807
+ })
791
808
  );
809
+ const colorPalette = createColorPalette(ansiPalette);
792
810
  const parser = createAnsiSequenceParser();
793
811
  return lines.map(
794
812
  (line) => parser.parse(line[0]).map((token) => {
@@ -826,7 +844,7 @@ function tokenizeAnsiWithTheme(theme, fileContents, options) {
826
844
  );
827
845
  }
828
846
  function dimColor(color) {
829
- const hexMatch = color.match(/#([0-9a-f]{3})([0-9a-f]{3})?([0-9a-f]{2})?/);
847
+ const hexMatch = color.match(/#([0-9a-f]{3})([0-9a-f]{3})?([0-9a-f]{2})?/i);
830
848
  if (hexMatch) {
831
849
  if (hexMatch[3]) {
832
850
  const alpha = Math.round(Number.parseInt(hexMatch[3], 16) / 2).toString(16).padStart(2, "0");
@@ -2033,10 +2051,15 @@ function makeSingletonHighlighter(createHighlighter) {
2033
2051
  if (!_shiki) {
2034
2052
  _shiki = createHighlighter({
2035
2053
  ...options,
2036
- themes: options.themes || [],
2037
- langs: options.langs || []
2054
+ themes: [],
2055
+ langs: []
2038
2056
  });
2039
- return _shiki;
2057
+ const s = await _shiki;
2058
+ await Promise.all([
2059
+ s.loadTheme(...options.themes || []),
2060
+ s.loadLanguage(...options.langs || [])
2061
+ ]);
2062
+ return s;
2040
2063
  } else {
2041
2064
  const s = await _shiki;
2042
2065
  await Promise.all([
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/core",
3
3
  "type": "module",
4
- "version": "3.14.0",
4
+ "version": "3.15.0",
5
5
  "description": "Core of Shiki",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "@shikijs/vscode-textmate": "^10.0.2",
40
40
  "@types/hast": "^3.0.4",
41
41
  "hast-util-to-html": "^9.0.5",
42
- "@shikijs/types": "3.14.0"
42
+ "@shikijs/types": "3.15.0"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "unbuild",