aboutsummaryrefslogtreecommitdiff
path: root/browser/monaco.ts
diff options
context:
space:
mode:
Diffstat (limited to 'browser/monaco.ts')
-rw-r--r--browser/monaco.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/browser/monaco.ts b/browser/monaco.ts
new file mode 100644
index 0000000..ead061d
--- /dev/null
+++ b/browser/monaco.ts
@@ -0,0 +1,43 @@
+/*
+ * Vencord, a Discord client mod
+ * Copyright (c) 2023 Vendicated and contributors
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+import "./patch-worker";
+
+import * as monaco from "monaco-editor/esm/vs/editor/editor.main.js";
+
+declare global {
+ const baseUrl: string;
+ const getCurrentCss: () => Promise<string>;
+ const setCss: (css: string) => void;
+ const getTheme: () => string;
+}
+
+const BASE = "/dist/monaco/vs";
+
+self.MonacoEnvironment = {
+ getWorkerUrl(_moduleId: unknown, label: string) {
+ const path = label === "css" ? "/language/css/css.worker.js" : "/editor/editor.worker.js";
+ return new URL(BASE + path, baseUrl).toString();
+ }
+};
+
+getCurrentCss().then(css => {
+ const editor = monaco.editor.create(
+ document.getElementById("container")!,
+ {
+ value: css,
+ language: "css",
+ theme: getTheme(),
+ }
+ );
+ editor.onDidChangeModelContent(() =>
+ setCss(editor.getValue())
+ );
+ window.addEventListener("resize", () => {
+ // make monaco re-layout
+ editor.layout();
+ });
+});