diff --git a/packages/codemirror/index.mjs b/packages/codemirror/index.mjs
index c847c32c..8f2d1630 100644
--- a/packages/codemirror/index.mjs
+++ b/packages/codemirror/index.mjs
@@ -2,3 +2,4 @@ export * from './codemirror.mjs';
export * from './highlight.mjs';
export * from './flash.mjs';
export * from './slider.mjs';
+export * from './themes.mjs';
diff --git a/packages/codemirror/themes.mjs b/packages/codemirror/themes.mjs
index 1f520623..71fb7642 100644
--- a/packages/codemirror/themes.mjs
+++ b/packages/codemirror/themes.mjs
@@ -473,6 +473,9 @@ function stringifySafe(json) {
return JSON.stringify(json, getCircularReplacer());
}
+export const theme = (theme) => themes[theme] || themes.strudelTheme;
+
+// css style injection helpers
export function injectStyle(rule) {
const newStyle = document.createElement('style');
document.head.appendChild(newStyle);
@@ -481,4 +484,38 @@ export function injectStyle(rule) {
return () => styleSheet.deleteRule(ruleIndex);
}
-export const theme = (theme) => themes[theme] || themes.strudelTheme;
+let currentTheme, resetThemeStyle, themeStyle;
+export function initTheme(theme) {
+ themeStyle = document.createElement('style');
+ themeStyle.id = 'strudel-theme';
+ document.head.append(themeStyle);
+ activateTheme(theme);
+}
+
+export function activateTheme(name) {
+ if (currentTheme === name) {
+ return;
+ }
+ if (!settings[name]) {
+ console.warn('theme', name, 'has no settings.. defaulting to strudelTheme settings');
+ }
+ const themeSettings = settings[name] || settings.strudelTheme;
+ // set css variables
+ themeStyle.innerHTML = `:root {
+ ${Object.entries(themeSettings)
+ // important to override fallback
+ .map(([key, value]) => `--${key}: ${value} !important;`)
+ .join('\n')}
+ }`;
+ // tailwind dark mode
+ if (themeSettings.light) {
+ document.documentElement.classList.remove('dark');
+ } else {
+ document.documentElement.classList.add('dark');
+ }
+ resetThemeStyle?.();
+ resetThemeStyle = undefined;
+ if (themeSettings.customStyle) {
+ resetThemeStyle = injectStyle(themeSettings.customStyle);
+ }
+}
diff --git a/website/src/components/HeadCommonNew.astro b/website/src/components/HeadCommonNew.astro
new file mode 100644
index 00000000..9f323a7a
--- /dev/null
+++ b/website/src/components/HeadCommonNew.astro
@@ -0,0 +1,58 @@
+---
+import { pwaInfo } from 'virtual:pwa-info';
+import '../styles/index.css';
+
+const { BASE_URL } = import.meta.env;
+const baseNoTrailing = BASE_URL.endsWith('/') ? BASE_URL.slice(0, -1) : BASE_URL;
+---
+
+
+
+
+
+
+
+
+
+
+
+
+
+