Write the logic template for updating themes

This commit is contained in:
2023-12-15 15:49:33 +01:00
parent eb103dbebd
commit 69cd462c68
3 changed files with 30 additions and 2 deletions

View File

@ -126,8 +126,8 @@
<div id="documentation" class="hidden"> <div id="documentation" class="hidden">
<div id="documentation-page" class="flex flex-row transparent"> <div id="documentation-page" class="flex flex-row transparent">
<aside class="w-1/8 flex-shrink-0 h-screen overflow-y-auto p-1 lg:p-6 lineHighlight bg-color5"> <aside class="w-1/8 flex-shrink-0 h-screen overflow-y-auto p-1 lg:p-6 lineHighlight">
<nav class="text-xl sm:text-sm overflow-y-scroll mb-24 bg-color6"> <nav class="text-xl sm:text-sm overflow-y-scroll mb-24">
<details class="" open> <details class="" open>
<summary class="font-semibold lg:text-xl text-orange-300">Basics</summary> <summary class="font-semibold lg:text-xl text-orange-300">Basics</summary>
<div class="flex flex-col"> <div class="flex flex-col">

View File

@ -18,6 +18,7 @@ import {
syntaxHighlighting, syntaxHighlighting,
indentOnInput, indentOnInput,
bracketMatching, bracketMatching,
HighlightStyle,
} from "@codemirror/language"; } from "@codemirror/language";
import { defaultKeymap, historyKeymap, history } from "@codemirror/commands"; import { defaultKeymap, historyKeymap, history } from "@codemirror/commands";
import { searchKeymap, highlightSelectionMatches } from "@codemirror/search"; import { searchKeymap, highlightSelectionMatches } from "@codemirror/search";
@ -36,6 +37,15 @@ import { inlineHoveringTips } from "./documentation/inlineHelp";
import { toposCompletions, soundCompletions } from "./documentation/inlineHelp"; import { toposCompletions, soundCompletions } from "./documentation/inlineHelp";
import { javascriptLanguage } from "@codemirror/lang-javascript"; import { javascriptLanguage } from "@codemirror/lang-javascript";
export const updateCodeMirrorTheme = (theme: {[key: string]: string}): Extension => {
let toposTheme = EditorView.theme({
});
let toposHighlightStyle = HighlightStyle.define([]);
return [ toposTheme, syntaxHighlighting(toposHighlightStyle),
]
}
export const jsCompletions = javascriptLanguage.data.of({ export const jsCompletions = javascriptLanguage.data.of({
autocomplete: toposCompletions, autocomplete: toposCompletions,
}); });

View File

@ -32,6 +32,7 @@ import { installWindowBehaviors } from "./WindowBehavior";
import { makeNumberExtensions } from "./extensions/NumberExtensions"; import { makeNumberExtensions } from "./extensions/NumberExtensions";
// @ts-ignore // @ts-ignore
import { registerSW } from "virtual:pwa-register"; import { registerSW } from "virtual:pwa-register";
import colors from "./colors.json";
if ("serviceWorker" in navigator) { if ("serviceWorker" in navigator) {
registerSW(); registerSW();
@ -569,6 +570,23 @@ export class Editor {
ctx.scale(dpr, dpr); ctx.scale(dpr, dpr);
} }
} }
private updateInterfaceTheme(selected_theme: {[key: string]: string}): void {
// We will update CSS variables to change the theme
for (const [key, value] of Object.entries(selected_theme)) {
document.documentElement.style.setProperty(key, value);
}
}
private readTheme(theme_name: string): void {
// Check if the theme exists in colors.json
let themes: Record<string, { [key: string]: any }> = colors;
let selected_theme = themes[theme_name];
if (selected_theme) {
this.updateInterfaceTheme(selected_theme);
updateCodeMirrorTheme(selected_theme);
}
}
} }
let app = new Editor(); let app = new Editor();