From 40acf8f34a88b2b9a53086f0dec57f11b601aa03 Mon Sep 17 00:00:00 2001 From: Alex Lebens Date: Tue, 15 Jul 2025 21:02:04 -0500 Subject: [PATCH] strip theme transition on load to use early script --- src/components/Background.astro | 5 --- src/components/ThemeToggle.astro | 13 -------- src/layouts/Base.astro | 17 ---------- src/layouts/BaseLayout.astro | 42 ------------------------ src/layouts/Layout.astro | 55 +++++++++++--------------------- 5 files changed, 19 insertions(+), 113 deletions(-) delete mode 100644 src/layouts/Base.astro diff --git a/src/components/Background.astro b/src/components/Background.astro index 3b0a8ff..b3ac9bc 100644 --- a/src/components/Background.astro +++ b/src/components/Background.astro @@ -35,18 +35,13 @@ if (themeToggle && overlay) { themeToggle.addEventListener('click', () => { - // Add transitioning class to optimize performance document.documentElement.classList.add('theme-transitioning'); - // Fade in overlay overlay.style.opacity = '0.15'; overlay.style.transition = 'opacity 0.3s ease'; setTimeout(() => { - // Fade out overlay overlay.style.opacity = '0'; - - // Remove transitioning class after animation completes setTimeout(() => { document.documentElement.classList.remove('theme-transitioning'); }, 700); diff --git a/src/components/ThemeToggle.astro b/src/components/ThemeToggle.astro index 252bcdc..7e1c85e 100644 --- a/src/components/ThemeToggle.astro +++ b/src/components/ThemeToggle.astro @@ -52,19 +52,6 @@ function setupThemeToggle() { const themeToggles = document.querySelectorAll('[data-theme-toggle]'); - // Check for dark mode preference at the system level - const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; - - // Check for saved theme preference or use the system preference - const currentTheme = localStorage.getItem('theme') || (prefersDarkMode ? 'dark' : 'light'); - - // Apply the theme on initial load - if (currentTheme === 'dark') { - document.documentElement.classList.add('dark'); - } else { - document.documentElement.classList.remove('dark'); - } - // Create theme switch overlay element if it doesn't exist if (!document.querySelector('.theme-switch-overlay')) { const overlay = document.createElement('div'); diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro deleted file mode 100644 index 90219c9..0000000 --- a/src/layouts/Base.astro +++ /dev/null @@ -1,17 +0,0 @@ ---- -import Layout from './Layout.astro'; - -import directus from '../../lib/directus'; -import { readSingleton } from '@directus/sdk'; - -const global = await directus.request(readSingleton('global')); - -export interface Props { - title: string; - description?: string; -} ---- - - - - diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index 4a3079e..90219c9 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -15,45 +15,3 @@ export interface Props { - - diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index afd143d..756c3dc 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -27,16 +27,29 @@ const { title, description } = Astro.props; href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet" /> + + - -
-
-
@@ -48,36 +61,6 @@ const { title, description } = Astro.props;