modern-monaco 0.1.4 → 0.1.6
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/README.md +131 -118
- package/dist/cache.js +43 -35
- package/dist/core.js +7 -2
- package/dist/editor-core.js +5 -0
- package/dist/lsp/typescript/worker.js +183 -182
- package/dist/shiki.js +27 -8
- package/dist/ssr/index.js +2 -2
- package/dist/ssr/workerd.js +2 -2
- package/package.json +1 -1
package/dist/shiki.js
CHANGED
|
@@ -7751,8 +7751,8 @@ var MINIMUM_LINE_HEIGHT = 8;
|
|
|
7751
7751
|
var MINIMUM_MAX_DIGIT_WIDTH = 5;
|
|
7752
7752
|
function render(highlighter, input, options = {}) {
|
|
7753
7753
|
const isBrowser = typeof globalThis.document?.querySelector === "function";
|
|
7754
|
-
if (!options.userAgent && !isBrowser) {
|
|
7755
|
-
throw new Error("`userAgent` option is required in non-browser environment");
|
|
7754
|
+
if (!options.userAgent && !options.fontFamily && !isBrowser) {
|
|
7755
|
+
throw new Error("`userAgent` or `fontFamily` option is required in non-browser environment");
|
|
7756
7756
|
}
|
|
7757
7757
|
const code = typeof input === "string" ? input : input.code;
|
|
7758
7758
|
const filename = typeof input === "string" ? void 0 : input.filename;
|
|
@@ -8097,30 +8097,41 @@ async function initShiki({
|
|
|
8097
8097
|
return highlighterCore;
|
|
8098
8098
|
}
|
|
8099
8099
|
function loadTMTheme(src, cdn = "https://esm.sh") {
|
|
8100
|
+
if (typeof src === "string" && /^[a-zA-Z]/.test(src)) {
|
|
8101
|
+
src = src.replace(/\s+/g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
8102
|
+
}
|
|
8100
8103
|
if (typeof src === "string" && tmThemes.has(src)) {
|
|
8101
8104
|
const theme = tmThemes.get(src);
|
|
8102
8105
|
if (theme) {
|
|
8103
8106
|
return theme;
|
|
8104
8107
|
}
|
|
8105
|
-
const
|
|
8106
|
-
return cache.fetch(
|
|
8108
|
+
const url2 = new URL(`/tm-themes@${version2}/themes/${src}.json`, cdn);
|
|
8109
|
+
return cache.fetch(url2).then(
|
|
8107
8110
|
(res) => res.json().then((theme2) => {
|
|
8108
8111
|
tmThemes.set(src, theme2);
|
|
8109
8112
|
return theme2;
|
|
8110
8113
|
})
|
|
8111
8114
|
);
|
|
8112
8115
|
}
|
|
8113
|
-
|
|
8116
|
+
const url = typeof src === "string" ? new URL(src) : src;
|
|
8117
|
+
if (url.protocol === "http" || url.protocol === "https") {
|
|
8118
|
+
return cache.fetch(url).then((res) => res.json());
|
|
8119
|
+
}
|
|
8120
|
+
throw new Error(`Unsupported theme source: ${src}`);
|
|
8114
8121
|
}
|
|
8115
8122
|
function loadTMGrammar(src, cdn = "https://esm.sh") {
|
|
8116
8123
|
if (typeof src === "string") {
|
|
8117
8124
|
const g = tmGrammars.find((g2) => g2.name === src);
|
|
8118
8125
|
if (g) {
|
|
8119
|
-
const
|
|
8120
|
-
return cache.fetch(
|
|
8126
|
+
const url2 = new URL(`/tm-grammars@${version}/grammars/${g.name}.json`, cdn);
|
|
8127
|
+
return cache.fetch(url2).then((res) => res.json());
|
|
8121
8128
|
}
|
|
8122
8129
|
}
|
|
8123
|
-
|
|
8130
|
+
const url = typeof src === "string" ? new URL(src) : src;
|
|
8131
|
+
if (url.protocol === "http" || url.protocol === "https") {
|
|
8132
|
+
return cache.fetch(url).then((res) => res.json());
|
|
8133
|
+
}
|
|
8134
|
+
throw new Error(`Unsupported grammar source: ${src}`);
|
|
8124
8135
|
}
|
|
8125
8136
|
function getGarmmarInfoFromPath(path) {
|
|
8126
8137
|
const idx = path.lastIndexOf(".");
|
|
@@ -8132,7 +8143,15 @@ function getGarmmarInfoFromPath(path) {
|
|
|
8132
8143
|
function getLanguageIdFromPath(path) {
|
|
8133
8144
|
return getGarmmarInfoFromPath(path)?.name;
|
|
8134
8145
|
}
|
|
8146
|
+
function getExtnameFromLanguageId(language) {
|
|
8147
|
+
const g = tmGrammars.find((g2) => g2.name === language);
|
|
8148
|
+
if (g) {
|
|
8149
|
+
return g.aliases?.[0] ?? g.name;
|
|
8150
|
+
}
|
|
8151
|
+
return void 0;
|
|
8152
|
+
}
|
|
8135
8153
|
export {
|
|
8154
|
+
getExtnameFromLanguageId,
|
|
8136
8155
|
getGarmmarInfoFromPath,
|
|
8137
8156
|
getLanguageIdFromPath,
|
|
8138
8157
|
initShiki,
|
package/dist/ssr/index.js
CHANGED
|
@@ -12,14 +12,14 @@ async function renderToString(input, options) {
|
|
|
12
12
|
const highlighter = await (ssrHighlighter ?? (ssrHighlighter = initShiki(shiki)));
|
|
13
13
|
const promises = [];
|
|
14
14
|
if (theme && !highlighter.getLoadedThemes().includes(theme)) {
|
|
15
|
-
console.info(`[modern-monaco] Loading theme '${theme}' from
|
|
15
|
+
console.info(`[modern-monaco] Loading theme '${theme}' from CDN...`);
|
|
16
16
|
promises.push(highlighter.loadThemeFromCDN(theme));
|
|
17
17
|
}
|
|
18
18
|
if (language || filename) {
|
|
19
19
|
const languageId = language ?? getLanguageIdFromPath(filename);
|
|
20
20
|
if (languageId && !highlighter.getLoadedLanguages().includes(languageId)) {
|
|
21
21
|
console.info(
|
|
22
|
-
`[modern-monaco] Loading garmmar '${languageId}' from
|
|
22
|
+
`[modern-monaco] Loading garmmar '${languageId}' from CDN...`
|
|
23
23
|
);
|
|
24
24
|
promises.push(highlighter.loadGrammarFromCDN(languageId));
|
|
25
25
|
}
|
package/dist/ssr/workerd.js
CHANGED
|
@@ -11,14 +11,14 @@ async function renderToString(input, options) {
|
|
|
11
11
|
const highlighter = await (ssrHighlighter ?? (ssrHighlighter = initShiki(shiki)));
|
|
12
12
|
const promises = [];
|
|
13
13
|
if (theme && !highlighter.getLoadedThemes().includes(theme)) {
|
|
14
|
-
console.info(`[modern-monaco] Loading theme '${theme}' from
|
|
14
|
+
console.info(`[modern-monaco] Loading theme '${theme}' from CDN...`);
|
|
15
15
|
promises.push(highlighter.loadThemeFromCDN(theme));
|
|
16
16
|
}
|
|
17
17
|
if (language || filename) {
|
|
18
18
|
const languageId = language ?? getLanguageIdFromPath(filename);
|
|
19
19
|
if (languageId && !highlighter.getLoadedLanguages().includes(languageId)) {
|
|
20
20
|
console.info(
|
|
21
|
-
`[modern-monaco] Loading garmmar '${languageId}' from
|
|
21
|
+
`[modern-monaco] Loading garmmar '${languageId}' from CDN...`
|
|
22
22
|
);
|
|
23
23
|
promises.push(highlighter.loadGrammarFromCDN(languageId));
|
|
24
24
|
}
|