modern-monaco 0.0.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +359 -0
- package/dist/cache.js +94 -0
- package/dist/editor-core.js +177856 -0
- package/dist/editor-worker.js +13528 -0
- package/dist/index.js +635 -0
- package/dist/lsp/css/setup.js +43 -0
- package/dist/lsp/css/worker.js +40804 -0
- package/dist/lsp/html/setup.js +90 -0
- package/dist/lsp/html/worker.js +16632 -0
- package/dist/lsp/json/setup.js +258 -0
- package/dist/lsp/json/worker.js +7964 -0
- package/dist/lsp/language-service.js +2244 -0
- package/dist/lsp/typescript/libs.js +100 -0
- package/dist/lsp/typescript/setup.js +425 -0
- package/dist/lsp/typescript/worker.js +2858 -0
- package/dist/onig.wasm +0 -0
- package/dist/shiki-wasm.js +9 -0
- package/dist/shiki.js +8744 -0
- package/dist/ssr/index.js +47 -0
- package/dist/ssr/workerd.js +46 -0
- package/dist/util.js +192 -0
- package/dist/workspace.js +611 -0
- package/package.json +67 -0
- package/types/cache.d.ts +7 -0
- package/types/index.d.ts +47 -0
- package/types/jsonSchema.d.ts +90 -0
- package/types/lsp.d.ts +106 -0
- package/types/monaco.d.ts +8284 -0
- package/types/ssr.d.ts +14 -0
- package/types/textmate.d.ts +2 -0
- package/types/vscode.d.ts +303 -0
- package/types/workspace.d.ts +74 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/ssr/index.ts
|
|
2
|
+
import { setDefaultWasmLoader } from "../shiki.js";
|
|
3
|
+
import { getWasmInstance } from "../shiki-wasm.js";
|
|
4
|
+
|
|
5
|
+
// src/ssr/ssr.ts
|
|
6
|
+
import { getLanguageIdFromPath, initShiki } from "../shiki.js";
|
|
7
|
+
import { render } from "../shiki.js";
|
|
8
|
+
var ssrHighlighter;
|
|
9
|
+
async function initRenderHighlighter(options) {
|
|
10
|
+
const highlighter = await (ssrHighlighter ?? (ssrHighlighter = initShiki(options.shiki)));
|
|
11
|
+
const { filename, language, theme } = options;
|
|
12
|
+
const promises = [];
|
|
13
|
+
if (language || filename) {
|
|
14
|
+
const languageId = language ?? getLanguageIdFromPath(filename);
|
|
15
|
+
if (languageId && !highlighter.getLoadedLanguages().includes(languageId)) {
|
|
16
|
+
console.info(
|
|
17
|
+
`[modern-monaco] Loading garmmar '${languageId}' from ${options.shiki?.downloadCDN ?? "https://esm.sh"}/tm-grammars ...`
|
|
18
|
+
);
|
|
19
|
+
promises.push(highlighter.loadGrammarFromCDN(languageId));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (theme) {
|
|
23
|
+
if (!highlighter.getLoadedThemes().includes(theme)) {
|
|
24
|
+
console.info(`[modern-monaco] Loading theme '${theme}' from ${options.shiki?.downloadCDN ?? "https://esm.sh"}/tm-themes ...`);
|
|
25
|
+
promises.push(highlighter.loadThemeFromCDN(theme));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (promises.length > 0) {
|
|
29
|
+
await Promise.all(promises);
|
|
30
|
+
}
|
|
31
|
+
return highlighter;
|
|
32
|
+
}
|
|
33
|
+
async function renderToString(options) {
|
|
34
|
+
const highlighter = await initRenderHighlighter(options);
|
|
35
|
+
return render(highlighter, options);
|
|
36
|
+
}
|
|
37
|
+
async function renderToWebComponent(options) {
|
|
38
|
+
const prerender = await renderToString(options);
|
|
39
|
+
return '<monaco-editor><script type="application/json" class="monaco-editor-options">' + JSON.stringify(options) + '<\/script><div class="monaco-editor-prerender" style="width:100%;height:100%;">' + prerender + "</div></monaco-editor>";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/ssr/index.ts
|
|
43
|
+
setDefaultWasmLoader(getWasmInstance);
|
|
44
|
+
export {
|
|
45
|
+
renderToString,
|
|
46
|
+
renderToWebComponent
|
|
47
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/ssr/workerd.ts
|
|
2
|
+
import { setDefaultWasmLoader } from "../shiki.js";
|
|
3
|
+
|
|
4
|
+
// src/ssr/ssr.ts
|
|
5
|
+
import { getLanguageIdFromPath, initShiki } from "../shiki.js";
|
|
6
|
+
import { render } from "../shiki.js";
|
|
7
|
+
var ssrHighlighter;
|
|
8
|
+
async function initRenderHighlighter(options) {
|
|
9
|
+
const highlighter = await (ssrHighlighter ?? (ssrHighlighter = initShiki(options.shiki)));
|
|
10
|
+
const { filename, language, theme } = options;
|
|
11
|
+
const promises = [];
|
|
12
|
+
if (language || filename) {
|
|
13
|
+
const languageId = language ?? getLanguageIdFromPath(filename);
|
|
14
|
+
if (languageId && !highlighter.getLoadedLanguages().includes(languageId)) {
|
|
15
|
+
console.info(
|
|
16
|
+
`[modern-monaco] Loading garmmar '${languageId}' from ${options.shiki?.downloadCDN ?? "https://esm.sh"}/tm-grammars ...`
|
|
17
|
+
);
|
|
18
|
+
promises.push(highlighter.loadGrammarFromCDN(languageId));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (theme) {
|
|
22
|
+
if (!highlighter.getLoadedThemes().includes(theme)) {
|
|
23
|
+
console.info(`[modern-monaco] Loading theme '${theme}' from ${options.shiki?.downloadCDN ?? "https://esm.sh"}/tm-themes ...`);
|
|
24
|
+
promises.push(highlighter.loadThemeFromCDN(theme));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (promises.length > 0) {
|
|
28
|
+
await Promise.all(promises);
|
|
29
|
+
}
|
|
30
|
+
return highlighter;
|
|
31
|
+
}
|
|
32
|
+
async function renderToString(options) {
|
|
33
|
+
const highlighter = await initRenderHighlighter(options);
|
|
34
|
+
return render(highlighter, options);
|
|
35
|
+
}
|
|
36
|
+
async function renderToWebComponent(options) {
|
|
37
|
+
const prerender = await renderToString(options);
|
|
38
|
+
return '<monaco-editor><script type="application/json" class="monaco-editor-options">' + JSON.stringify(options) + '<\/script><div class="monaco-editor-prerender" style="width:100%;height:100%;">' + prerender + "</div></monaco-editor>";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/ssr/workerd.ts
|
|
42
|
+
setDefaultWasmLoader(import("../onig.wasm"));
|
|
43
|
+
export {
|
|
44
|
+
renderToString,
|
|
45
|
+
renderToWebComponent
|
|
46
|
+
};
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// src/util.ts
|
|
2
|
+
var enc = new TextEncoder();
|
|
3
|
+
var dec = new TextDecoder();
|
|
4
|
+
function encode(data) {
|
|
5
|
+
return typeof data === "string" ? enc.encode(data) : data;
|
|
6
|
+
}
|
|
7
|
+
function decode(data) {
|
|
8
|
+
return data instanceof Uint8Array ? dec.decode(data) : data;
|
|
9
|
+
}
|
|
10
|
+
function defineProperty(obj, prop, value) {
|
|
11
|
+
Object.defineProperty(obj, prop, { value });
|
|
12
|
+
}
|
|
13
|
+
function toURL(uri) {
|
|
14
|
+
return uri instanceof URL ? uri : new URL(uri, "file:///");
|
|
15
|
+
}
|
|
16
|
+
function filenameToURL(filename) {
|
|
17
|
+
if (filename.startsWith("file://")) {
|
|
18
|
+
filename = filename.slice(7);
|
|
19
|
+
}
|
|
20
|
+
const url = new URL(filename.replace(/[\/\\]+/g, "/"), "file:///");
|
|
21
|
+
if (url.pathname.endsWith("/")) {
|
|
22
|
+
url.pathname = url.pathname.slice(0, -1);
|
|
23
|
+
}
|
|
24
|
+
url.search = "";
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
function isPlainObject(v) {
|
|
28
|
+
return typeof v === "object" && v !== null && v.constructor === Object;
|
|
29
|
+
}
|
|
30
|
+
function debunce(fn, delay = 500) {
|
|
31
|
+
let timer = null;
|
|
32
|
+
return () => {
|
|
33
|
+
if (timer !== null) {
|
|
34
|
+
clearTimeout(timer);
|
|
35
|
+
}
|
|
36
|
+
timer = setTimeout(() => {
|
|
37
|
+
timer = null;
|
|
38
|
+
fn();
|
|
39
|
+
}, delay);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function createPersistTask(persist, delay = 500) {
|
|
43
|
+
let timer = null;
|
|
44
|
+
const askToExit = (e) => {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
return () => {
|
|
49
|
+
if (timer !== null) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
addEventListener("beforeunload", askToExit);
|
|
53
|
+
timer = setTimeout(async () => {
|
|
54
|
+
timer = null;
|
|
55
|
+
await persist();
|
|
56
|
+
removeEventListener("beforeunload", askToExit);
|
|
57
|
+
}, delay);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function createSyncPersistTask(persist, delay = 500) {
|
|
61
|
+
let timer = null;
|
|
62
|
+
return () => {
|
|
63
|
+
if (timer !== null) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
addEventListener("beforeunload", persist);
|
|
67
|
+
timer = setTimeout(() => {
|
|
68
|
+
timer = null;
|
|
69
|
+
removeEventListener("beforeunload", persist);
|
|
70
|
+
persist();
|
|
71
|
+
}, delay);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function createPersistStateStorage(storeKey, defaultValue) {
|
|
75
|
+
let state;
|
|
76
|
+
const init = defaultValue ?? {};
|
|
77
|
+
const storeValue = localStorage.getItem(storeKey);
|
|
78
|
+
if (storeValue) {
|
|
79
|
+
try {
|
|
80
|
+
for (const [key, value] of Object.entries(JSON.parse(storeValue))) {
|
|
81
|
+
init[key] = Object.freeze(value);
|
|
82
|
+
}
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.error(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const persist = createSyncPersistTask(() => localStorage.setItem(storeKey, JSON.stringify(state)), 1e3);
|
|
88
|
+
return state = createProxy(init, persist);
|
|
89
|
+
}
|
|
90
|
+
function createProxy(obj, onChange) {
|
|
91
|
+
let filled = false;
|
|
92
|
+
const proxy = new Proxy(/* @__PURE__ */ Object.create(null), {
|
|
93
|
+
get(target, key) {
|
|
94
|
+
return Reflect.get(target, key);
|
|
95
|
+
},
|
|
96
|
+
set(target, key, value) {
|
|
97
|
+
if (isPlainObject(value) && !Object.isFrozen(value)) {
|
|
98
|
+
value = createProxy(value, onChange);
|
|
99
|
+
}
|
|
100
|
+
const ok = Reflect.set(target, key, value);
|
|
101
|
+
if (ok && filled) {
|
|
102
|
+
onChange();
|
|
103
|
+
}
|
|
104
|
+
return ok;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
108
|
+
proxy[key] = value;
|
|
109
|
+
}
|
|
110
|
+
filled = true;
|
|
111
|
+
return proxy;
|
|
112
|
+
}
|
|
113
|
+
function supportLocalStorage() {
|
|
114
|
+
if (globalThis.localStorage) {
|
|
115
|
+
try {
|
|
116
|
+
localStorage.setItem("..", "");
|
|
117
|
+
localStorage.removeItem("..");
|
|
118
|
+
return true;
|
|
119
|
+
} catch {
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
function promisifyIDBRequest(req) {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
req.onsuccess = () => resolve(req.result);
|
|
127
|
+
req.onerror = () => reject(req.error);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async function openIDB(name, version = 1, ...stores) {
|
|
131
|
+
const req = indexedDB.open(name, version);
|
|
132
|
+
const promises = [];
|
|
133
|
+
req.onupgradeneeded = () => {
|
|
134
|
+
const db2 = req.result;
|
|
135
|
+
for (const { name: name2, keyPath, onCreate } of stores) {
|
|
136
|
+
if (!db2.objectStoreNames.contains(name2)) {
|
|
137
|
+
const store = db2.createObjectStore(name2, { keyPath });
|
|
138
|
+
if (onCreate) {
|
|
139
|
+
promises.push(onCreate(store));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const db = await promisifyIDBRequest(req);
|
|
145
|
+
await Promise.all(promises);
|
|
146
|
+
return db;
|
|
147
|
+
}
|
|
148
|
+
function openIDBCursor(store, range, callback, direction) {
|
|
149
|
+
return new Promise((resolve, reject) => {
|
|
150
|
+
const ocr = store.openCursor(range, direction);
|
|
151
|
+
ocr.onsuccess = () => {
|
|
152
|
+
const cursor = ocr.result;
|
|
153
|
+
if (cursor) {
|
|
154
|
+
if (callback(cursor) !== false) {
|
|
155
|
+
cursor.continue();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
resolve();
|
|
160
|
+
};
|
|
161
|
+
ocr.onerror = () => {
|
|
162
|
+
reject(ocr.error);
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function promiseWithResolvers() {
|
|
167
|
+
let resolve;
|
|
168
|
+
let reject;
|
|
169
|
+
const promise = new Promise((res, rej) => {
|
|
170
|
+
resolve = res;
|
|
171
|
+
reject = rej;
|
|
172
|
+
});
|
|
173
|
+
return { promise, resolve, reject };
|
|
174
|
+
}
|
|
175
|
+
export {
|
|
176
|
+
createPersistStateStorage,
|
|
177
|
+
createPersistTask,
|
|
178
|
+
createProxy,
|
|
179
|
+
createSyncPersistTask,
|
|
180
|
+
debunce,
|
|
181
|
+
decode,
|
|
182
|
+
defineProperty,
|
|
183
|
+
encode,
|
|
184
|
+
filenameToURL,
|
|
185
|
+
isPlainObject,
|
|
186
|
+
openIDB,
|
|
187
|
+
openIDBCursor,
|
|
188
|
+
promiseWithResolvers,
|
|
189
|
+
promisifyIDBRequest,
|
|
190
|
+
supportLocalStorage,
|
|
191
|
+
toURL
|
|
192
|
+
};
|