diff options
| author | Adam <[email protected]> | 2025-12-28 06:41:54 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-12-28 06:41:59 -0600 |
| commit | 82a876da4de0074ca3d4d6af9a31dc6e8cf20c3a (patch) | |
| tree | e83d71404c832ff59b351540f4a56eecf2b97b36 /packages/app | |
| parent | 69a15ae9c1e6737728649cebf3a4009d9ae8edd3 (diff) | |
| download | opencode-82a876da4de0074ca3d4d6af9a31dc6e8cf20c3a.tar.gz opencode-82a876da4de0074ca3d4d6af9a31dc6e8cf20c3a.zip | |
chore: cleanup
Diffstat (limited to 'packages/app')
| -rw-r--r-- | packages/app/index.html | 31 | ||||
| -rw-r--r-- | packages/app/script/inject-theme-preload.ts | 18 | ||||
| -rw-r--r-- | packages/app/vite.js | 18 |
3 files changed, 29 insertions, 38 deletions
diff --git a/packages/app/index.html b/packages/app/index.html index 4f003c05b..ea4237804 100644 --- a/packages/app/index.html +++ b/packages/app/index.html @@ -13,9 +13,36 @@ <meta name="theme-color" content="#131010" media="(prefers-color-scheme: dark)" /> <meta property="og:image" content="/social-share.png" /> <meta property="twitter:image" content="/social-share.png" /> - <!-- Theme preload script - injected by Vite plugin to avoid FOUC --> + <!-- Theme preload script - applies cached theme to avoid FOUC --> <script id="oc-theme-preload-script"> - /* THEME_PRELOAD_SCRIPT */ + ;(function () { + var themeId = localStorage.getItem("opencode-theme-id") + if (!themeId) return + + var scheme = localStorage.getItem("opencode-color-scheme") || "system" + var isDark = scheme === "dark" || (scheme === "system" && matchMedia("(prefers-color-scheme: dark)").matches) + var mode = isDark ? "dark" : "light" + + document.documentElement.dataset.theme = themeId + document.documentElement.dataset.colorScheme = mode + + if (themeId === "oc-1") return + + var css = localStorage.getItem("opencode-theme-css-" + themeId + "-" + mode) + if (css) { + var style = document.createElement("style") + style.id = "oc-theme-preload" + style.textContent = + ":root{color-scheme:" + + mode + + ";--text-mix-blend-mode:" + + (isDark ? "plus-lighter" : "multiply") + + ";" + + css + + "}" + document.head.appendChild(style) + } + })() </script> </head> <body class="antialiased overscroll-none text-12-regular overflow-hidden"> diff --git a/packages/app/script/inject-theme-preload.ts b/packages/app/script/inject-theme-preload.ts deleted file mode 100644 index 511ab7a3b..000000000 --- a/packages/app/script/inject-theme-preload.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Injects the theme preload script into index.html. - * Run this as part of the build process. - */ - -import { generatePreloadScript } from "@opencode-ai/ui/theme" - -const htmlPath = new URL("../index.html", import.meta.url).pathname -const html = await Bun.file(htmlPath).text() - -const script = generatePreloadScript() -const injectedHtml = html.replace( - /<script id="oc-theme-preload-script">\s*\/\* THEME_PRELOAD_SCRIPT \*\/\s*<\/script>/, - `<script id="oc-theme-preload-script">${script}</script>`, -) - -await Bun.write(htmlPath, injectedHtml) -console.log("Injected theme preload script into index.html") diff --git a/packages/app/vite.js b/packages/app/vite.js index 5ab368836..6b8fd6137 100644 --- a/packages/app/vite.js +++ b/packages/app/vite.js @@ -1,23 +1,6 @@ import solidPlugin from "vite-plugin-solid" import tailwindcss from "@tailwindcss/vite" import { fileURLToPath } from "url" -import { generatePreloadScript } from "@opencode-ai/ui/theme" - -/** - * Vite plugin that injects the theme preload script into index.html. - * This ensures the theme is applied before the page renders, avoiding FOUC. - * @type {import("vite").Plugin} - */ -const themePreloadPlugin = { - name: "opencode-desktop:theme-preload", - transformIndexHtml(html) { - const script = generatePreloadScript() - return html.replace( - /<script id="oc-theme-preload-script">\s*\/\* THEME_PRELOAD_SCRIPT \*\/\s*<\/script>/, - `<script id="oc-theme-preload-script">${script}</script>`, - ) - }, -} /** * @type {import("vite").PluginOption} @@ -38,7 +21,6 @@ export default [ } }, }, - themePreloadPlugin, tailwindcss(), solidPlugin(), ] |
