mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
Adds Solarized Light, Solarized Dark, One Light and One Dark as built-in themes across the workbench, editor, terminal and Mermaid, keeping the original palettes (MIT notices in THIRD_PARTY_LICENSES.md, mapping in docs/themes.md). - Native window colours are read from tokens.css at build time (`theme_frame.rs`) instead of a second colour table. - Startup restores the built-in palette before first paint. - Editor schemes, the terminal and Mermaid refresh on switches between themes of the same kind. - The plugin packages of the same themes are removed. - A test requires every built-in palette theme to define each token (only listed ones may inherit from the base theme), so new tokens can't silently miss them. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VUYsdXA2nkF5v6zsC93dpn
43 lines
2.1 KiB
JavaScript
43 lines
2.1 KiB
JavaScript
/* global document, localStorage, window */
|
|
// Runs before the app's CSS loads: restores the last theme (theme.ts stores it)
|
|
// so a new window starts in it instead of flashing the light default.
|
|
// An external file because the CSP forbids inline scripts.
|
|
try {
|
|
const root = document.documentElement;
|
|
const addStyle = (id, css) => {
|
|
const style = document.createElement("style");
|
|
style.id = id;
|
|
style.textContent = css;
|
|
document.head.appendChild(style);
|
|
};
|
|
const last = JSON.parse(localStorage.getItem("openidea.theme") ?? "null");
|
|
if (last?.theme) root.dataset.theme = last.theme;
|
|
if (last?.contrast) root.dataset.contrast = last.contrast;
|
|
// A built-in palette theme (Solarized, One) over its light / dark base (tokens.css).
|
|
if (typeof last?.colorTheme === "string" && /^[a-z][a-z0-9-]*$/.test(last.colorTheme))
|
|
root.dataset.colorTheme = last.colorTheme;
|
|
// A plugin theme's stylesheet (plugins/bridge.ts), so the workbench doesn't
|
|
// show the built-in theme until the plugin host answers.
|
|
const plugin = JSON.parse(localStorage.getItem("openidea.pluginTheme") ?? "null");
|
|
if (typeof plugin?.id === "string" && typeof plugin.css === "string" && !/[<\\]|url\(/i.test(plugin.css)) {
|
|
addStyle("openidea-plugin-theme", plugin.css);
|
|
root.dataset.pluginTheme = plugin.id;
|
|
root.dataset.pluginThemeKind = root.dataset.theme = plugin.kind === "light" ? "light" : "dark";
|
|
delete root.dataset.contrast;
|
|
delete root.dataset.colorTheme;
|
|
}
|
|
// The splash's frame, text and accent colours, resolved by theme.ts (splash.css).
|
|
const colors = [
|
|
["--boot-frame", last?.frame],
|
|
["--boot-fg", last?.fg],
|
|
["--boot-accent", last?.accent],
|
|
].filter(([, v]) => typeof v === "string" && /^#[0-9a-f]{3,8}$/i.test(v));
|
|
if (colors.length) addStyle("openidea-boot-colors", `:root { ${colors.map(([k, v]) => `${k}: ${v};`).join(" ")} }`);
|
|
} catch {
|
|
/* storage unavailable */
|
|
}
|
|
// Settings windows (`settings-<parent>`) load this page too: splash.css drops the logo for them.
|
|
if (window.__TAURI_INTERNALS__?.metadata?.currentWindow?.label?.startsWith("settings-")) {
|
|
document.documentElement.dataset.window = "settings";
|
|
}
|