@shikijs/core 1.2.2 → 1.2.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.
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +15 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -112,6 +112,7 @@ declare function splitToken<T extends Pick<ThemedToken, 'content' | 'offset'>>(t
|
|
|
112
112
|
*/
|
|
113
113
|
declare function splitTokens<T extends Pick<ThemedToken, 'content' | 'offset'>>(tokens: T[][], breakpoints: number[] | Set<number>): T[][];
|
|
114
114
|
declare function applyColorReplacements(color: string, replacements?: Record<string, string>): string;
|
|
115
|
+
declare function applyColorReplacements(color?: string | undefined, replacements?: Record<string, string>): string | undefined;
|
|
115
116
|
declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
|
|
116
117
|
declare function stringifyTokenStyle(token: Record<string, string>): string;
|
|
117
118
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -122,6 +122,8 @@ function splitTokens(tokens, breakpoints) {
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
function applyColorReplacements(color, replacements) {
|
|
125
|
+
if (!color)
|
|
126
|
+
return color;
|
|
125
127
|
return replacements?.[color?.toLowerCase()] || color;
|
|
126
128
|
}
|
|
127
129
|
function getTokenStyleObject(token) {
|
|
@@ -458,6 +460,7 @@ function tokenizeAnsiWithTheme(theme, fileContents, options) {
|
|
|
458
460
|
bgColor = token.background ? colorPalette.value(token.background) : undefined;
|
|
459
461
|
}
|
|
460
462
|
color = applyColorReplacements(color, colorReplacements);
|
|
463
|
+
bgColor = applyColorReplacements(bgColor, colorReplacements);
|
|
461
464
|
if (token.decorations.has('dim'))
|
|
462
465
|
color = dimColor(color);
|
|
463
466
|
let fontStyle = FontStyle.None;
|
|
@@ -563,13 +566,12 @@ function tokenizeWithTheme(code, grammar, theme, colorMap, options) {
|
|
|
563
566
|
if (startIndex === nextStartIndex)
|
|
564
567
|
continue;
|
|
565
568
|
const metadata = result.tokens[2 * j + 1];
|
|
566
|
-
const
|
|
567
|
-
const foregroundColor = applyColorReplacements(colorMap[foreground], colorReplacements);
|
|
569
|
+
const color = applyColorReplacements(colorMap[StackElementMetadata.getForeground(metadata)], colorReplacements);
|
|
568
570
|
const fontStyle = StackElementMetadata.getFontStyle(metadata);
|
|
569
571
|
const token = {
|
|
570
572
|
content: line.substring(startIndex, nextStartIndex),
|
|
571
573
|
offset: lineOffset + startIndex,
|
|
572
|
-
color
|
|
574
|
+
color,
|
|
573
575
|
fontStyle,
|
|
574
576
|
};
|
|
575
577
|
if (options.includeExplanation) {
|
|
@@ -748,7 +750,7 @@ function codeToTokens(internal, code, options) {
|
|
|
748
750
|
let themeName;
|
|
749
751
|
let rootStyle;
|
|
750
752
|
if ('themes' in options) {
|
|
751
|
-
const { defaultColor = 'light', cssVariablePrefix = '--shiki-', } = options;
|
|
753
|
+
const { defaultColor = 'light', cssVariablePrefix = '--shiki-', colorReplacements, } = options;
|
|
752
754
|
const themes = Object.entries(options.themes)
|
|
753
755
|
.filter(i => i[1])
|
|
754
756
|
.map(i => ({ color: i[0], theme: i[1] }))
|
|
@@ -762,16 +764,21 @@ function codeToTokens(internal, code, options) {
|
|
|
762
764
|
const themesOrder = themes.map(t => t.color);
|
|
763
765
|
tokens = themeTokens
|
|
764
766
|
.map(line => line.map(token => mergeToken(token, themesOrder, cssVariablePrefix, defaultColor)));
|
|
765
|
-
fg = themes.map((t, idx) => (idx === 0 && defaultColor
|
|
766
|
-
|
|
767
|
+
fg = themes.map((t, idx) => (idx === 0 && defaultColor
|
|
768
|
+
? ''
|
|
769
|
+
: `${cssVariablePrefix + t.color}:`) + (applyColorReplacements(themeRegs[idx].fg, colorReplacements) || 'inherit')).join(';');
|
|
770
|
+
bg = themes.map((t, idx) => (idx === 0 && defaultColor
|
|
771
|
+
? ''
|
|
772
|
+
: `${cssVariablePrefix + t.color}-bg:`) + (applyColorReplacements(themeRegs[idx].bg, colorReplacements) || 'inherit')).join(';');
|
|
767
773
|
themeName = `shiki-themes ${themeRegs.map(t => t.name).join(' ')}`;
|
|
768
774
|
rootStyle = defaultColor ? undefined : [fg, bg].join(';');
|
|
769
775
|
}
|
|
770
776
|
else if ('theme' in options) {
|
|
777
|
+
const { colorReplacements, } = options;
|
|
771
778
|
tokens = codeToTokensBase(internal, code, options);
|
|
772
779
|
const _theme = internal.getTheme(options.theme);
|
|
773
|
-
bg = _theme.bg;
|
|
774
|
-
fg = _theme.fg;
|
|
780
|
+
bg = applyColorReplacements(_theme.bg, colorReplacements);
|
|
781
|
+
fg = applyColorReplacements(_theme.fg, colorReplacements);
|
|
775
782
|
themeName = _theme.name;
|
|
776
783
|
}
|
|
777
784
|
else {
|