modern-monaco 0.4.1 → 0.4.2
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/core.mjs +1 -1
- package/dist/shiki.mjs +45 -42
- package/package.json +4 -4
package/dist/core.mjs
CHANGED
package/dist/shiki.mjs
CHANGED
|
@@ -3240,9 +3240,10 @@ function isNoneTheme(theme) {
|
|
|
3240
3240
|
function isSpecialTheme(theme) {
|
|
3241
3241
|
return isNoneTheme(theme);
|
|
3242
3242
|
}
|
|
3243
|
+
var RE_NEWLINE = /(\r?\n)/g;
|
|
3243
3244
|
function splitLines(code, preserveEnding = false) {
|
|
3244
3245
|
if (code.length === 0) return [["", 0]];
|
|
3245
|
-
const parts = code.split(
|
|
3246
|
+
const parts = code.split(RE_NEWLINE);
|
|
3246
3247
|
let index = 0;
|
|
3247
3248
|
const lines = [];
|
|
3248
3249
|
for (let i = 0; i < parts.length; i += 2) {
|
|
@@ -3333,7 +3334,7 @@ function normalizeTheme(rawTheme) {
|
|
|
3333
3334
|
return theme;
|
|
3334
3335
|
}
|
|
3335
3336
|
async function resolveLangs(langs) {
|
|
3336
|
-
return
|
|
3337
|
+
return [...new Set((await Promise.all(langs.filter((l) => !isSpecialLang(l)).map(async (lang) => await normalizeGetter(lang).then((r) => Array.isArray(r) ? r : [r])))).flat())];
|
|
3337
3338
|
}
|
|
3338
3339
|
async function resolveThemes(themes2) {
|
|
3339
3340
|
return (await Promise.all(themes2.map(async (theme) => isSpecialTheme(theme) ? null : normalizeTheme(await normalizeGetter(theme))))).filter((i) => !!i);
|
|
@@ -3344,13 +3345,17 @@ function resolveLangAlias(name, alias) {
|
|
|
3344
3345
|
const resolved = /* @__PURE__ */ new Set([name]);
|
|
3345
3346
|
while (alias[name]) {
|
|
3346
3347
|
name = alias[name];
|
|
3347
|
-
if (resolved.has(name)) throw new ShikiError(`Circular alias \`${
|
|
3348
|
+
if (resolved.has(name)) throw new ShikiError(`Circular alias \`${[...resolved].join(" -> ")} -> ${name}\``);
|
|
3348
3349
|
resolved.add(name);
|
|
3349
3350
|
}
|
|
3350
3351
|
}
|
|
3351
3352
|
return name;
|
|
3352
3353
|
}
|
|
3353
3354
|
var Registry2 = class extends Registry {
|
|
3355
|
+
_resolver;
|
|
3356
|
+
_themes;
|
|
3357
|
+
_langs;
|
|
3358
|
+
_alias;
|
|
3354
3359
|
_resolvedThemes = /* @__PURE__ */ new Map();
|
|
3355
3360
|
_resolvedGrammars = /* @__PURE__ */ new Map();
|
|
3356
3361
|
_langMap = /* @__PURE__ */ new Map();
|
|
@@ -3429,7 +3434,7 @@ var Registry2 = class extends Registry {
|
|
|
3429
3434
|
}
|
|
3430
3435
|
loadLanguages(langs) {
|
|
3431
3436
|
for (const lang of langs) this.resolveEmbeddedLanguages(lang);
|
|
3432
|
-
const langsGraphArray =
|
|
3437
|
+
const langsGraphArray = [...this._langGraph.entries()];
|
|
3433
3438
|
const missingLangs = langsGraphArray.filter(([_, lang]) => !lang);
|
|
3434
3439
|
if (missingLangs.length) {
|
|
3435
3440
|
const dependents = langsGraphArray.filter(([_, lang]) => {
|
|
@@ -3674,6 +3679,8 @@ function getGrammarStack(state, theme) {
|
|
|
3674
3679
|
if (!(state instanceof GrammarState)) throw new ShikiError("Invalid grammar state");
|
|
3675
3680
|
return state.getInternalStack(theme);
|
|
3676
3681
|
}
|
|
3682
|
+
var RE_COMMA = /,/;
|
|
3683
|
+
var RE_SPACE = / /;
|
|
3677
3684
|
function codeToTokensBase(primitive, code, options = {}) {
|
|
3678
3685
|
const { theme: themeName = primitive.getLoadedThemes()[0] } = options;
|
|
3679
3686
|
if (isPlainLang(primitive.resolveLangAlias(options.lang || "text")) || isNoneTheme(themeName)) return splitLines(code).map((line) => [{
|
|
@@ -3761,7 +3768,7 @@ function _tokenizeWithTheme(code, grammar, theme, colorMap2, options) {
|
|
|
3761
3768
|
let selectors;
|
|
3762
3769
|
switch (typeof setting.scope) {
|
|
3763
3770
|
case "string":
|
|
3764
|
-
selectors = setting.scope.split(
|
|
3771
|
+
selectors = setting.scope.split(RE_COMMA).map((scope) => scope.trim());
|
|
3765
3772
|
break;
|
|
3766
3773
|
case "object":
|
|
3767
3774
|
selectors = setting.scope;
|
|
@@ -3771,7 +3778,7 @@ function _tokenizeWithTheme(code, grammar, theme, colorMap2, options) {
|
|
|
3771
3778
|
}
|
|
3772
3779
|
themeSettingsSelectors.push({
|
|
3773
3780
|
settings: setting,
|
|
3774
|
-
selectors: selectors.map((selector) => selector.split(
|
|
3781
|
+
selectors: selectors.map((selector) => selector.split(RE_SPACE))
|
|
3775
3782
|
});
|
|
3776
3783
|
}
|
|
3777
3784
|
token.explanation = [];
|
|
@@ -3816,7 +3823,7 @@ function matchesOne(selector, scope) {
|
|
|
3816
3823
|
return selector === scope || scope.substring(0, selector.length) === selector && scope[selector.length] === ".";
|
|
3817
3824
|
}
|
|
3818
3825
|
function matches(selectors, scope, parentScopes) {
|
|
3819
|
-
if (!matchesOne(selectors
|
|
3826
|
+
if (!matchesOne(selectors.at(-1), scope)) return false;
|
|
3820
3827
|
let selectorParentIndex = selectors.length - 2;
|
|
3821
3828
|
let parentIndex = parentScopes.length - 1;
|
|
3822
3829
|
while (selectorParentIndex >= 0 && parentIndex >= 0) {
|
|
@@ -6102,13 +6109,14 @@ function all(parent) {
|
|
|
6102
6109
|
}
|
|
6103
6110
|
|
|
6104
6111
|
// node_modules/@shikijs/core/dist/index.mjs
|
|
6112
|
+
var RE_WHITESPACE = /\s+/g;
|
|
6105
6113
|
function addClassToHast(node, className) {
|
|
6106
6114
|
if (!className) return node;
|
|
6107
6115
|
node.properties ||= {};
|
|
6108
6116
|
node.properties.class ||= [];
|
|
6109
|
-
if (typeof node.properties.class === "string") node.properties.class = node.properties.class.split(
|
|
6117
|
+
if (typeof node.properties.class === "string") node.properties.class = node.properties.class.split(RE_WHITESPACE);
|
|
6110
6118
|
if (!Array.isArray(node.properties.class)) node.properties.class = [];
|
|
6111
|
-
const targets = Array.isArray(className) ? className : className.split(
|
|
6119
|
+
const targets = Array.isArray(className) ? className : className.split(RE_WHITESPACE);
|
|
6112
6120
|
for (const c of targets) if (c && !node.properties.class.includes(c)) node.properties.class.push(c);
|
|
6113
6121
|
return node;
|
|
6114
6122
|
}
|
|
@@ -6117,7 +6125,7 @@ function createPositionConverter(code) {
|
|
|
6117
6125
|
function indexToPos(index) {
|
|
6118
6126
|
if (index === code.length) return {
|
|
6119
6127
|
line: lines.length - 1,
|
|
6120
|
-
character: lines
|
|
6128
|
+
character: lines.at(-1).length
|
|
6121
6129
|
};
|
|
6122
6130
|
let character = index;
|
|
6123
6131
|
let line = 0;
|
|
@@ -6143,7 +6151,6 @@ function createPositionConverter(code) {
|
|
|
6143
6151
|
posToIndex
|
|
6144
6152
|
};
|
|
6145
6153
|
}
|
|
6146
|
-
var DEFAULT_COLOR_LIGHT_DARK = "light-dark()";
|
|
6147
6154
|
var COLOR_KEYS = ["color", "background-color"];
|
|
6148
6155
|
function splitToken(token, offsets) {
|
|
6149
6156
|
let lastOffset = 0;
|
|
@@ -6164,7 +6171,7 @@ function splitToken(token, offsets) {
|
|
|
6164
6171
|
return tokens;
|
|
6165
6172
|
}
|
|
6166
6173
|
function splitTokens(tokens, breakpoints) {
|
|
6167
|
-
const sorted =
|
|
6174
|
+
const sorted = [...breakpoints instanceof Set ? breakpoints : new Set(breakpoints)].sort((a, b) => a - b);
|
|
6168
6175
|
if (!sorted.length) return tokens;
|
|
6169
6176
|
return tokens.map((line) => {
|
|
6170
6177
|
return line.flatMap((token) => {
|
|
@@ -6190,7 +6197,7 @@ function flatTokenVariants(merged, variantsOrder, cssVariablePrefix, defaultColo
|
|
|
6190
6197
|
styles.forEach((cur, idx) => {
|
|
6191
6198
|
for (const key2 of styleKeys) {
|
|
6192
6199
|
const value = cur[key2] || "inherit";
|
|
6193
|
-
if (idx === 0 && defaultColor && COLOR_KEYS.includes(key2)) if (defaultColor ===
|
|
6200
|
+
if (idx === 0 && defaultColor && COLOR_KEYS.includes(key2)) if (defaultColor === "light-dark()" && styles.length > 1) {
|
|
6194
6201
|
const lightIndex = variantsOrder.findIndex((t) => t === "light");
|
|
6195
6202
|
const darkIndex = variantsOrder.findIndex((t) => t === "dark");
|
|
6196
6203
|
if (lightIndex === -1 || darkIndex === -1) throw new ShikiError('When using `defaultColor: "light-dark()"`, you must provide both `light` and `dark` themes');
|
|
@@ -6269,7 +6276,7 @@ function transformerDecorations() {
|
|
|
6269
6276
|
code(codeEl) {
|
|
6270
6277
|
if (!this.options.decorations?.length) return;
|
|
6271
6278
|
const ctx = getContext(this);
|
|
6272
|
-
const lines =
|
|
6279
|
+
const lines = [...codeEl.children].filter((i) => i.type === "element" && i.tagName === "span");
|
|
6273
6280
|
if (lines.length !== ctx.converter.lines.length) throw new ShikiError(`Number of lines in code element (${lines.length}) does not match the number of lines in the source (${ctx.converter.lines.length}). Failed to apply decorations.`);
|
|
6274
6281
|
function applyLineSection(line, start, end, decoration) {
|
|
6275
6282
|
const lineEl = lines[line];
|
|
@@ -6622,6 +6629,8 @@ function createColorPalette(namedColorsMap = defaultNamedColorsMap) {
|
|
|
6622
6629
|
}
|
|
6623
6630
|
return { value };
|
|
6624
6631
|
}
|
|
6632
|
+
var RE_HEX_COLOR = /#([0-9a-f]{3,8})/i;
|
|
6633
|
+
var RE_CSS_VAR_ANSI = /var\((--[\w-]+-ansi-[\w-]+)\)/;
|
|
6625
6634
|
var defaultAnsiColors = {
|
|
6626
6635
|
black: "#000000",
|
|
6627
6636
|
red: "#cd3131",
|
|
@@ -6676,7 +6685,7 @@ function tokenizeAnsiWithTheme(theme, fileContents, options) {
|
|
|
6676
6685
|
}));
|
|
6677
6686
|
}
|
|
6678
6687
|
function dimColor(color) {
|
|
6679
|
-
const hexMatch = color.match(
|
|
6688
|
+
const hexMatch = color.match(RE_HEX_COLOR);
|
|
6680
6689
|
if (hexMatch) {
|
|
6681
6690
|
const hex = hexMatch[1];
|
|
6682
6691
|
if (hex.length === 8) {
|
|
@@ -6696,7 +6705,7 @@ function dimColor(color) {
|
|
|
6696
6705
|
return `#${r}${r}${g}${g}${b}${b}80`;
|
|
6697
6706
|
}
|
|
6698
6707
|
}
|
|
6699
|
-
const cssVarMatch = color.match(
|
|
6708
|
+
const cssVarMatch = color.match(RE_CSS_VAR_ANSI);
|
|
6700
6709
|
if (cssVarMatch) return `var(${cssVarMatch[1]}-dim)`;
|
|
6701
6710
|
return color;
|
|
6702
6711
|
}
|
|
@@ -6725,7 +6734,7 @@ function codeToTokens(primitive, code, options) {
|
|
|
6725
6734
|
if (themes2.length === 0) throw new ShikiError("`themes` option must not be empty");
|
|
6726
6735
|
const themeTokens = codeToTokensWithThemes(primitive, code, options, codeToTokensBase2);
|
|
6727
6736
|
grammarState = getLastGrammarStateFromMap(themeTokens);
|
|
6728
|
-
if (defaultColor &&
|
|
6737
|
+
if (defaultColor && "light-dark()" !== defaultColor && !themes2.some((t) => t.color === defaultColor)) throw new ShikiError(`\`themes\` option must contain the defaultColor key \`${defaultColor}\``);
|
|
6729
6738
|
const themeRegs = themes2.map((t) => primitive.getTheme(t.theme));
|
|
6730
6739
|
const themesOrder = themes2.map((t) => t.color);
|
|
6731
6740
|
tokens = themeTokens.map((line) => line.map((token) => flatTokenVariants(token, themesOrder, cssVariablePrefix, defaultColor, colorsRendering)));
|
|
@@ -6758,7 +6767,7 @@ function mapThemeColors(themes2, themeRegs, themeColorReplacements, cssVariableP
|
|
|
6758
6767
|
const value = applyColorReplacements(themeRegs[idx][property], themeColorReplacements[idx]) || "inherit";
|
|
6759
6768
|
const cssVar = `${cssVariablePrefix + t.color}${property === "bg" ? "-bg" : ""}:${value}`;
|
|
6760
6769
|
if (idx === 0 && defaultColor) {
|
|
6761
|
-
if (defaultColor ===
|
|
6770
|
+
if (defaultColor === "light-dark()" && themes2.length > 1) {
|
|
6762
6771
|
const lightIndex = themes2.findIndex((t2) => t2.color === "light");
|
|
6763
6772
|
const darkIndex = themes2.findIndex((t2) => t2.color === "dark");
|
|
6764
6773
|
if (lightIndex === -1 || darkIndex === -1) throw new ShikiError('When using `defaultColor: "light-dark()"`, you must provide both `light` and `dark` themes');
|
|
@@ -6770,6 +6779,8 @@ function mapThemeColors(themes2, themeRegs, themeColorReplacements, cssVariableP
|
|
|
6770
6779
|
return null;
|
|
6771
6780
|
}).filter((i) => !!i).join(";");
|
|
6772
6781
|
}
|
|
6782
|
+
var RE_WHITESPACE_ONLY = /^\s+$/;
|
|
6783
|
+
var RE_LEADING_TRAILING_WHITESPACE = /^(\s*)(.*?)(\s*)$/;
|
|
6773
6784
|
function codeToHast(primitive, code, options, transformerContext = {
|
|
6774
6785
|
meta: {},
|
|
6775
6786
|
options,
|
|
@@ -6948,7 +6959,7 @@ function mergeWhitespaceTokens(tokens) {
|
|
|
6948
6959
|
let firstOffset;
|
|
6949
6960
|
line.forEach((token, idx) => {
|
|
6950
6961
|
const couldMerge = !(token.fontStyle && (token.fontStyle & FontStyle.Underline || token.fontStyle & FontStyle.Strikethrough));
|
|
6951
|
-
if (couldMerge && token.content
|
|
6962
|
+
if (couldMerge && RE_WHITESPACE_ONLY.test(token.content) && line[idx + 1]) {
|
|
6952
6963
|
if (firstOffset === void 0) firstOffset = token.offset;
|
|
6953
6964
|
carryOnContent += token.content;
|
|
6954
6965
|
} else if (carryOnContent) {
|
|
@@ -6971,8 +6982,8 @@ function mergeWhitespaceTokens(tokens) {
|
|
|
6971
6982
|
function splitWhitespaceTokens(tokens) {
|
|
6972
6983
|
return tokens.map((line) => {
|
|
6973
6984
|
return line.flatMap((token) => {
|
|
6974
|
-
if (token.content
|
|
6975
|
-
const match = token.content.match(
|
|
6985
|
+
if (RE_WHITESPACE_ONLY.test(token.content)) return token;
|
|
6986
|
+
const match = token.content.match(RE_LEADING_TRAILING_WHITESPACE);
|
|
6976
6987
|
if (!match) return token;
|
|
6977
6988
|
const [, leading, content, trailing] = match;
|
|
6978
6989
|
if (!leading && !trailing) return token;
|
|
@@ -7001,7 +7012,7 @@ function mergeAdjacentStyledTokens(tokens) {
|
|
|
7001
7012
|
newLine.push({ ...token });
|
|
7002
7013
|
continue;
|
|
7003
7014
|
}
|
|
7004
|
-
const prevToken = newLine
|
|
7015
|
+
const prevToken = newLine.at(-1);
|
|
7005
7016
|
const prevStyle = stringifyTokenStyle(prevToken.htmlStyle || getTokenStyleObject(prevToken));
|
|
7006
7017
|
const currentStyle = stringifyTokenStyle(token.htmlStyle || getTokenStyleObject(token));
|
|
7007
7018
|
const isPrevDecorated = prevToken.fontStyle && (prevToken.fontStyle & FontStyle.Underline || prevToken.fontStyle & FontStyle.Strikethrough);
|
|
@@ -7139,10 +7150,10 @@ async function main(init) {
|
|
|
7139
7150
|
env: asmLibraryArg,
|
|
7140
7151
|
wasi_snapshot_preview1: asmLibraryArg
|
|
7141
7152
|
};
|
|
7142
|
-
const exports
|
|
7143
|
-
wasmMemory = exports
|
|
7153
|
+
const exports = await init(info);
|
|
7154
|
+
wasmMemory = exports.memory;
|
|
7144
7155
|
updateGlobalBufferAndViews(wasmMemory.buffer);
|
|
7145
|
-
Object.assign(binding, exports
|
|
7156
|
+
Object.assign(binding, exports);
|
|
7146
7157
|
binding.UTF8ToString = UTF8ToString;
|
|
7147
7158
|
}
|
|
7148
7159
|
await createWasm();
|
|
@@ -7681,7 +7692,7 @@ function textmateThemeToMonacoTheme(theme) {
|
|
|
7681
7692
|
if (s && settings?.foreground) {
|
|
7682
7693
|
rules.push({
|
|
7683
7694
|
token: s,
|
|
7684
|
-
foreground: normalizeColor(
|
|
7695
|
+
foreground: normalizeColor(settings.foreground),
|
|
7685
7696
|
fontStyle: settings?.fontStyle
|
|
7686
7697
|
});
|
|
7687
7698
|
}
|
|
@@ -7689,7 +7700,7 @@ function textmateThemeToMonacoTheme(theme) {
|
|
|
7689
7700
|
}
|
|
7690
7701
|
return {
|
|
7691
7702
|
base: theme.type === "dark" ? "vs-dark" : "vs",
|
|
7692
|
-
colors: Object.fromEntries(Object.entries(theme.colors ?? {}).map(([key2, value]) => [key2, normalizeColor(
|
|
7703
|
+
colors: Object.fromEntries(Object.entries(theme.colors ?? {}).map(([key2, value]) => [key2, normalizeColor(value)])),
|
|
7693
7704
|
inherit: false,
|
|
7694
7705
|
rules
|
|
7695
7706
|
};
|
|
@@ -7717,7 +7728,7 @@ function initShikiMonacoTokenizer(monaco, highlighter) {
|
|
|
7717
7728
|
const ret = highlighter.setTheme(themeId);
|
|
7718
7729
|
colorMap.length = ret.colorMap.length;
|
|
7719
7730
|
ret.colorMap.forEach((color, i) => {
|
|
7720
|
-
colorMap[i] = normalizeColor(
|
|
7731
|
+
colorMap[i] = normalizeColor(color);
|
|
7721
7732
|
});
|
|
7722
7733
|
colorToScopeMap.clear();
|
|
7723
7734
|
theme.rules.forEach((rule) => {
|
|
@@ -7788,27 +7799,19 @@ function toRGBA(hex) {
|
|
|
7788
7799
|
rgba[i] = parseInt(hex.slice(j, j + step).repeat(3 - step), 16);
|
|
7789
7800
|
}
|
|
7790
7801
|
if (Number.isNaN(rgba[3])) {
|
|
7791
|
-
rgba[3] =
|
|
7792
|
-
} else {
|
|
7793
|
-
rgba[3] /= 255;
|
|
7802
|
+
rgba[3] = 255;
|
|
7794
7803
|
}
|
|
7795
7804
|
return rgba;
|
|
7796
7805
|
}
|
|
7797
7806
|
function toHexColor(rgb) {
|
|
7798
7807
|
return "#" + rgb.map((c) => c.toString(16).padStart(2, "0")).join("");
|
|
7799
7808
|
}
|
|
7800
|
-
function
|
|
7801
|
-
const
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
}
|
|
7805
|
-
function normalizeColor(bg, fg) {
|
|
7806
|
-
const fgRgba = toRGBA(Array.isArray(fg) ? fg[0] : fg);
|
|
7807
|
-
if (fgRgba[3] === 1) {
|
|
7808
|
-
return toHexColor(fgRgba.slice(0, 3));
|
|
7809
|
+
function normalizeColor(color) {
|
|
7810
|
+
const rgba = toRGBA(Array.isArray(color) ? color[0] : color);
|
|
7811
|
+
if (rgba[3] === 255) {
|
|
7812
|
+
return toHexColor(rgba.slice(0, 3));
|
|
7809
7813
|
}
|
|
7810
|
-
|
|
7811
|
-
return toHexColor([0, 1, 2].map((i) => channelMixer(bgRgba[i], fgRgba[i], fgRgba[3])));
|
|
7814
|
+
return toHexColor(rgba);
|
|
7812
7815
|
}
|
|
7813
7816
|
|
|
7814
7817
|
// src/shiki.ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-monaco",
|
|
3
3
|
"description": "A modern version of Monaco Editor",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
"sideEffects": ["dist/index.mjs"],
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@esm.sh/import-map": "0.4.0",
|
|
74
|
-
"@shikijs/core": "4.0
|
|
75
|
-
"@shikijs/engine-oniguruma": "4.0
|
|
76
|
-
"@types/bun": "1.3.
|
|
74
|
+
"@shikijs/core": "4.1.0",
|
|
75
|
+
"@shikijs/engine-oniguruma": "4.1.0",
|
|
76
|
+
"@types/bun": "1.3.14",
|
|
77
77
|
"esbuild": "0.28.0",
|
|
78
78
|
"monaco-editor-core": "0.55.1",
|
|
79
79
|
"tm-grammars": "1.31.15",
|