add light mode
This commit is contained in:
11 files changed
+673
-19
No files matched your search
@@ -5,6 +5,17 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>404 — Havox</title>
|
<title>404 — Havox</title>
|
||||||
<meta name="description" content="Page not found." />
|
<meta name="description" content="Page not found." />
|
||||||
|
<meta
|
||||||
|
name="theme-color"
|
||||||
|
content="#1e1e2e"
|
||||||
|
media="(prefers-color-scheme: dark)"
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
name="theme-color"
|
||||||
|
content="#eff1f5"
|
||||||
|
media="(prefers-color-scheme: light)"
|
||||||
|
/>
|
||||||
|
<script src="theme.js"></script>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link
|
<link
|
||||||
href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,400;0,700;1,400&family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,600;1,9..144,300&display=swap"
|
href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,400;0,700;1,400&family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,600;1,9..144,300&display=swap"
|
||||||
@@ -18,12 +29,22 @@
|
|||||||
<!-- ─── Nav ─────────────────────────────────────────────────── -->
|
<!-- ─── Nav ─────────────────────────────────────────────────── -->
|
||||||
<nav>
|
<nav>
|
||||||
<a href="index.html" class="nav-logo">havox</a>
|
<a href="index.html" class="nav-logo">havox</a>
|
||||||
|
<div class="nav-actions">
|
||||||
<ul class="nav-links">
|
<ul class="nav-links">
|
||||||
<li><a href="index.html#about">about</a></li>
|
<li><a href="index.html#about">about</a></li>
|
||||||
<li><a href="index.html#skills">skills</a></li>
|
<li><a href="index.html#skills">skills</a></li>
|
||||||
<li><a href="index.html#projects">projects</a></li>
|
<li><a href="index.html#projects">projects</a></li>
|
||||||
<li><a href="index.html#contact">contact</a></li>
|
<li><a href="index.html#contact">contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<button
|
||||||
|
class="theme-toggle"
|
||||||
|
type="button"
|
||||||
|
aria-label="Switch colour theme"
|
||||||
|
hidden
|
||||||
|
>
|
||||||
|
<span class="theme-icon" aria-hidden="true"></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<!-- ─── 404 ──────────────────────────────────────────────────── -->
|
<!-- ─── 404 ──────────────────────────────────────────────────── -->
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020-2026 Paweł Kuna
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454l0 .008"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 314 B |
@@ -0,0 +1,16 @@
|
|||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M8 12a4 4 0 1 0 8 0a4 4 0 1 0 -8 0" />
|
||||||
|
<path
|
||||||
|
d="M3 12h1m8 -9v1m8 8h1m-9 8v1m-6.4 -15.4l.7 .7m12.1 -.7l-.7 .7m0 11.4l.7 .7m-12.1 -.7l-.7 .7"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 370 B |
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
+22
-2
@@ -8,7 +8,17 @@
|
|||||||
name="description"
|
name="description"
|
||||||
content="Portfolio of John Gatward, a software engineer specialising in backend development, interactive visualisations, and self-hosted systems."
|
content="Portfolio of John Gatward, a software engineer specialising in backend development, interactive visualisations, and self-hosted systems."
|
||||||
/>
|
/>
|
||||||
<meta name="theme-color" content="#1e1e2e" />
|
<meta
|
||||||
|
name="theme-color"
|
||||||
|
content="#1e1e2e"
|
||||||
|
media="(prefers-color-scheme: dark)"
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
name="theme-color"
|
||||||
|
content="#eff1f5"
|
||||||
|
media="(prefers-color-scheme: light)"
|
||||||
|
/>
|
||||||
|
<script src="theme.js"></script>
|
||||||
<link rel="icon" href="icons/favicon.ico" sizes="any" />
|
<link rel="icon" href="icons/favicon.ico" sizes="any" />
|
||||||
<link rel="apple-touch-icon" href="icons/apple-touch-icon.png" />
|
<link rel="apple-touch-icon" href="icons/apple-touch-icon.png" />
|
||||||
<link
|
<link
|
||||||
@@ -31,12 +41,21 @@
|
|||||||
<!-- ─── Nav ─────────────────────────────────────────────────── -->
|
<!-- ─── Nav ─────────────────────────────────────────────────── -->
|
||||||
<nav>
|
<nav>
|
||||||
<a href="#hero" class="nav-logo">havox</a>
|
<a href="#hero" class="nav-logo">havox</a>
|
||||||
|
<div class="nav-actions">
|
||||||
<ul class="nav-links">
|
<ul class="nav-links">
|
||||||
<li><a href="#about">about</a></li>
|
<li><a href="#about">about</a></li>
|
||||||
<li><a href="#skills">skills</a></li>
|
<li><a href="#skills">skills</a></li>
|
||||||
<li><a href="#projects">projects</a></li>
|
<li><a href="#projects">projects</a></li>
|
||||||
<li><a href="#contact">contact</a></li>
|
<li><a href="#contact">contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<button
|
||||||
|
class="theme-toggle"
|
||||||
|
type="button"
|
||||||
|
aria-label="Switch colour theme"
|
||||||
|
hidden
|
||||||
|
>
|
||||||
|
<span class="theme-icon" aria-hidden="true"></span>
|
||||||
|
</button>
|
||||||
<details class="nav-menu">
|
<details class="nav-menu">
|
||||||
<summary>Menu</summary>
|
<summary>Menu</summary>
|
||||||
<ul class="mobile-nav-links">
|
<ul class="mobile-nav-links">
|
||||||
@@ -46,6 +65,7 @@
|
|||||||
<li><a href="#contact">contact</a></li>
|
<li><a href="#contact">contact</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<main id="main-content" tabindex="-1">
|
<main id="main-content" tabindex="-1">
|
||||||
@@ -129,7 +149,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="v-year">2026 → present</div>
|
<div class="v-year">2026 → present</div>
|
||||||
<div class="v-desc">
|
<div class="v-desc">
|
||||||
Catppuccin Mocha. Single page. Professional.
|
Catppuccin Mocha & Latte. Single page. Professional.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -128,8 +128,45 @@ function initProjectFilters() {
|
|||||||
|
|
||||||
let selectedFilter = 'all';
|
let selectedFilter = 'all';
|
||||||
let isExpanded = false;
|
let isExpanded = false;
|
||||||
|
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
|
||||||
|
const canAnimate = projectCards.every(
|
||||||
|
(card) => typeof card.animate === 'function'
|
||||||
|
);
|
||||||
|
const animations = new Map();
|
||||||
|
const cancelAnimations = () => {
|
||||||
|
animations.forEach((animation) => animation.cancel());
|
||||||
|
animations.clear();
|
||||||
|
};
|
||||||
|
|
||||||
const applyFilter = () => {
|
if (canAnimate) {
|
||||||
|
window.addEventListener('resize', cancelAnimations);
|
||||||
|
reducedMotion.addEventListener('change', () => {
|
||||||
|
if (reducedMotion.matches) cancelAnimations();
|
||||||
|
});
|
||||||
|
projectGrid?.addEventListener('focusin', (event) => {
|
||||||
|
const card = event.target.closest('.project-card');
|
||||||
|
animations.get(card)?.cancel();
|
||||||
|
animations.delete(card);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const applyFilter = (animate = false) => {
|
||||||
|
const shouldAnimate = animate && canAnimate && !reducedMotion.matches;
|
||||||
|
// Capture the current visual positions before cancelling an interrupted move.
|
||||||
|
const previous = new Map(
|
||||||
|
shouldAnimate
|
||||||
|
? projectCards
|
||||||
|
.filter((card) => !card.hidden)
|
||||||
|
.map((card) => [
|
||||||
|
card,
|
||||||
|
{
|
||||||
|
rect: card.getBoundingClientRect(),
|
||||||
|
opacity: window.getComputedStyle(card).opacity,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
: []
|
||||||
|
);
|
||||||
|
cancelAnimations();
|
||||||
const matchingCards = projectCards.filter(
|
const matchingCards = projectCards.filter(
|
||||||
(card) =>
|
(card) =>
|
||||||
selectedFilter === 'all' ||
|
selectedFilter === 'all' ||
|
||||||
@@ -139,6 +176,9 @@ function initProjectFilters() {
|
|||||||
? matchingCards
|
? matchingCards
|
||||||
: matchingCards.slice(0, DEFAULT_VISIBLE_PROJECTS);
|
: matchingCards.slice(0, DEFAULT_VISIBLE_PROJECTS);
|
||||||
const shownSet = new Set(shownCards);
|
const shownSet = new Set(shownCards);
|
||||||
|
const focusedCard = projectCards.find((card) =>
|
||||||
|
card.contains(document.activeElement)
|
||||||
|
);
|
||||||
projectCards.forEach((card) => {
|
projectCards.forEach((card) => {
|
||||||
card.hidden = !shownSet.has(card);
|
card.hidden = !shownSet.has(card);
|
||||||
});
|
});
|
||||||
@@ -171,6 +211,41 @@ function initProjectFilters() {
|
|||||||
? 'Show fewer projects'
|
? 'Show fewer projects'
|
||||||
: `Show ${remainingCount} more project${remainingCount === 1 ? '' : 's'}`;
|
: `Show ${remainingCount} more project${remainingCount === 1 ? '' : 's'}`;
|
||||||
}
|
}
|
||||||
|
if (focusedCard && !shownSet.has(focusedCard)) {
|
||||||
|
filterChips
|
||||||
|
.find((chip) => chip.dataset.filter === selectedFilter)
|
||||||
|
.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldAnimate) {
|
||||||
|
const positions = shownCards.map((card) => [
|
||||||
|
card,
|
||||||
|
card.getBoundingClientRect(),
|
||||||
|
]);
|
||||||
|
positions.forEach(([card, rect]) => {
|
||||||
|
const before = previous.get(card);
|
||||||
|
const x = before ? before.rect.left - rect.left : 0;
|
||||||
|
const y = before ? before.rect.top - rect.top : 12;
|
||||||
|
const opacity = before ? before.opacity : 0;
|
||||||
|
if (
|
||||||
|
card.contains(document.activeElement) ||
|
||||||
|
(x === 0 && y === 0 && Number(opacity) === 1)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const animation = card.animate(
|
||||||
|
[
|
||||||
|
{ transform: `translate(${x}px, ${y}px)`, opacity },
|
||||||
|
{ transform: 'translate(0px, 0px)', opacity: 1 },
|
||||||
|
],
|
||||||
|
{ duration: 280, easing: 'cubic-bezier(0.2, 0.8, 0.2, 1)' }
|
||||||
|
);
|
||||||
|
animations.set(card, animation);
|
||||||
|
animation.addEventListener('finish', () => {
|
||||||
|
if (animations.get(card) === animation) animations.delete(card);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
filterChips.forEach((chip) => {
|
filterChips.forEach((chip) => {
|
||||||
@@ -178,14 +253,14 @@ function initProjectFilters() {
|
|||||||
selectedFilter = chip.dataset.filter || 'all';
|
selectedFilter = chip.dataset.filter || 'all';
|
||||||
isExpanded = false;
|
isExpanded = false;
|
||||||
|
|
||||||
applyFilter();
|
applyFilter(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (seeMoreButton) {
|
if (seeMoreButton) {
|
||||||
seeMoreButton.addEventListener('click', () => {
|
seeMoreButton.addEventListener('click', () => {
|
||||||
isExpanded = !isExpanded;
|
isExpanded = !isExpanded;
|
||||||
applyFilter();
|
applyFilter(true);
|
||||||
if (!isExpanded) {
|
if (!isExpanded) {
|
||||||
seeMoreButton.scrollIntoView({ block: 'nearest', behavior: 'instant' });
|
seeMoreButton.scrollIntoView({ block: 'nearest', behavior: 'instant' });
|
||||||
}
|
}
|
||||||
@@ -196,7 +271,7 @@ function initProjectFilters() {
|
|||||||
resetButton.addEventListener('click', () => {
|
resetButton.addEventListener('click', () => {
|
||||||
selectedFilter = 'all';
|
selectedFilter = 'all';
|
||||||
isExpanded = false;
|
isExpanded = false;
|
||||||
applyFilter();
|
applyFilter(true);
|
||||||
filterChips.find((chip) => chip.dataset.filter === 'all').focus();
|
filterChips.find((chip) => chip.dataset.filter === 'all').focus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
src: url('fonts/geist-variable.ttf') format('truetype');
|
src: url('fonts/geist-variable.ttf') format('truetype');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ─── Catppuccin Mocha ─────────────────────────────────── */
|
/* ─── Catppuccin themes ────────────────────────────────── */
|
||||||
:root {
|
:root {
|
||||||
|
color-scheme: light dark;
|
||||||
--font-body: 'Geist', system-ui, sans-serif;
|
--font-body: 'Geist', system-ui, sans-serif;
|
||||||
--font-mono: 'JetBrains Mono', monospace;
|
--font-mono: 'JetBrains Mono', monospace;
|
||||||
--base: #1e1e2e;
|
--base: #1e1e2e;
|
||||||
@@ -36,6 +37,70 @@
|
|||||||
--pink: #f5c2e7;
|
--pink: #f5c2e7;
|
||||||
--flamingo: #f2cdcd;
|
--flamingo: #f2cdcd;
|
||||||
--rosewater: #f5e0dc;
|
--rosewater: #f5e0dc;
|
||||||
|
--nav-background: rgba(17, 17, 27, 0.85);
|
||||||
|
--accent-soft: rgba(203, 166, 247, 0.15);
|
||||||
|
--accent-selected: rgba(203, 166, 247, 0.18);
|
||||||
|
--accent-border: rgba(203, 166, 247, 0.7);
|
||||||
|
--on-accent: #11111b;
|
||||||
|
--link-accent: var(--mauve);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[data-theme='light'] {
|
||||||
|
color-scheme: light;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[data-theme='dark'] {
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Catppuccin Latte / Mocha; older browsers retain the original Mocha palette. */
|
||||||
|
@supports (color: light-dark(#eff1f5, #1e1e2e)) {
|
||||||
|
:root {
|
||||||
|
--base: light-dark(#eff1f5, #1e1e2e);
|
||||||
|
--mantle: light-dark(#e6e9ef, #181825);
|
||||||
|
--crust: light-dark(#dce0e8, #11111b);
|
||||||
|
--surface0: light-dark(#ccd0da, #313244);
|
||||||
|
--surface1: light-dark(#bcc0cc, #45475a);
|
||||||
|
--surface2: light-dark(#acb0be, #585b70);
|
||||||
|
--overlay0: light-dark(#9ca0b0, #6c7086);
|
||||||
|
--overlay1: light-dark(#8c8fa1, #7f849c);
|
||||||
|
--overlay2: light-dark(#7c7f93, #9399b2);
|
||||||
|
--text: light-dark(#4c4f69, #cdd6f4);
|
||||||
|
--subtext0: light-dark(#60647b, #a6adc8);
|
||||||
|
--subtext1: light-dark(#5c5f77, #bac2de);
|
||||||
|
--lavender: light-dark(#7287fd, #b4befe);
|
||||||
|
--blue: light-dark(#1e66f5, #89b4fa);
|
||||||
|
--sapphire: light-dark(#209fb5, #74c7ec);
|
||||||
|
--sky: light-dark(#04a5e5, #89dceb);
|
||||||
|
--teal: light-dark(#179299, #94e2d5);
|
||||||
|
--green: light-dark(#40a02b, #a6e3a1);
|
||||||
|
--yellow: light-dark(#df8e1d, #f9e2af);
|
||||||
|
--peach: light-dark(#fe640b, #fab387);
|
||||||
|
--maroon: light-dark(#e64553, #eba0ac);
|
||||||
|
--red: light-dark(#d20f39, #f38ba8);
|
||||||
|
--mauve: light-dark(#8839ef, #cba6f7);
|
||||||
|
--pink: light-dark(#ea76cb, #f5c2e7);
|
||||||
|
--flamingo: light-dark(#dd7878, #f2cdcd);
|
||||||
|
--rosewater: light-dark(#dc8a78, #f5e0dc);
|
||||||
|
--nav-background: light-dark(
|
||||||
|
rgba(239, 241, 245, 0.94),
|
||||||
|
rgba(17, 17, 27, 0.85)
|
||||||
|
);
|
||||||
|
--accent-soft: light-dark(
|
||||||
|
rgba(136, 57, 239, 0.03),
|
||||||
|
rgba(203, 166, 247, 0.15)
|
||||||
|
);
|
||||||
|
--accent-selected: light-dark(
|
||||||
|
rgba(136, 57, 239, 0.03),
|
||||||
|
rgba(203, 166, 247, 0.18)
|
||||||
|
);
|
||||||
|
--accent-border: light-dark(
|
||||||
|
rgba(136, 57, 239, 0.7),
|
||||||
|
rgba(203, 166, 247, 0.7)
|
||||||
|
);
|
||||||
|
--on-accent: light-dark(#eff1f5, #11111b);
|
||||||
|
--link-accent: light-dark(#8235e6, #cba6f7);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*,
|
*,
|
||||||
@@ -80,7 +145,7 @@ footer {
|
|||||||
|
|
||||||
::selection {
|
::selection {
|
||||||
background: var(--mauve);
|
background: var(--mauve);
|
||||||
color: var(--crust);
|
color: var(--on-accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
:focus-visible {
|
:focus-visible {
|
||||||
@@ -96,7 +161,7 @@ footer {
|
|||||||
padding: 0.6rem 1rem;
|
padding: 0.6rem 1rem;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background: var(--mauve);
|
background: var(--mauve);
|
||||||
color: var(--crust);
|
color: var(--on-accent);
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
@@ -138,7 +203,7 @@ nav {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 0 3rem;
|
padding: 0 3rem;
|
||||||
height: 56px;
|
height: 56px;
|
||||||
background: rgba(17, 17, 27, 0.85);
|
background: var(--nav-background);
|
||||||
backdrop-filter: blur(12px);
|
backdrop-filter: blur(12px);
|
||||||
border-bottom: 1px solid var(--surface0);
|
border-bottom: 1px solid var(--surface0);
|
||||||
}
|
}
|
||||||
@@ -160,6 +225,48 @@ nav {
|
|||||||
list-style: none;
|
list-style: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-toggle {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 44px;
|
||||||
|
width: 44px;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--subtext1);
|
||||||
|
cursor: pointer;
|
||||||
|
transition:
|
||||||
|
color 0.2s,
|
||||||
|
background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-toggle:hover {
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: var(--mauve);
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-icon {
|
||||||
|
display: block;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
background: currentColor;
|
||||||
|
-webkit-mask: url('icons/sun.svg') center / contain no-repeat;
|
||||||
|
mask: url('icons/sun.svg') center / contain no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-toggle[data-theme='dark'] .theme-icon {
|
||||||
|
-webkit-mask-image: url('icons/moon.svg');
|
||||||
|
mask-image: url('icons/moon.svg');
|
||||||
|
}
|
||||||
|
|
||||||
.nav-links a,
|
.nav-links a,
|
||||||
.mobile-nav-links a {
|
.mobile-nav-links a {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -298,7 +405,7 @@ section.full-width {
|
|||||||
|
|
||||||
.btn-primary {
|
.btn-primary {
|
||||||
background: var(--mauve);
|
background: var(--mauve);
|
||||||
color: var(--crust);
|
color: var(--on-accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-primary:hover {
|
.btn-primary:hover {
|
||||||
@@ -320,6 +427,7 @@ section.full-width {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn:active,
|
.btn:active,
|
||||||
|
.theme-toggle:active,
|
||||||
.filter-chip:active,
|
.filter-chip:active,
|
||||||
.projects-more-btn:active {
|
.projects-more-btn:active {
|
||||||
transform: scale(0.98);
|
transform: scale(0.98);
|
||||||
@@ -495,7 +603,7 @@ section.full-width {
|
|||||||
font-size: 0.6rem;
|
font-size: 0.6rem;
|
||||||
letter-spacing: 0.08em;
|
letter-spacing: 0.08em;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
background: rgba(203, 166, 247, 0.15);
|
background: var(--accent-soft);
|
||||||
color: var(--mauve);
|
color: var(--mauve);
|
||||||
padding: 0.1rem 0.45rem;
|
padding: 0.1rem 0.45rem;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
@@ -570,7 +678,7 @@ section.full-width {
|
|||||||
letter-spacing: 0.04em;
|
letter-spacing: 0.04em;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
background: var(--surface0);
|
background: var(--surface0);
|
||||||
color: var(--subtext1);
|
color: var(--text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ─── Tutorials / Projects shared ─────────────────────── */
|
/* ─── Tutorials / Projects shared ─────────────────────── */
|
||||||
@@ -662,10 +770,17 @@ section.full-width {
|
|||||||
|
|
||||||
#project-grid {
|
#project-grid {
|
||||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
border-radius: 0;
|
||||||
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
#project-grid .card {
|
#project-grid .card {
|
||||||
padding: 1.2rem;
|
padding: 1.2rem;
|
||||||
|
border: 1px solid var(--surface0);
|
||||||
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.project-filters {
|
.project-filters {
|
||||||
@@ -699,8 +814,8 @@ section.full-width {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.filter-chip.active {
|
.filter-chip.active {
|
||||||
background: rgba(203, 166, 247, 0.18);
|
background: var(--accent-selected);
|
||||||
border-color: rgba(203, 166, 247, 0.7);
|
border-color: var(--accent-border);
|
||||||
color: var(--mauve);
|
color: var(--mauve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -848,13 +963,13 @@ section.full-width {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
min-height: 44px;
|
min-height: 44px;
|
||||||
padding: 0 0.25rem;
|
padding: 0 0.25rem;
|
||||||
color: var(--mauve);
|
color: var(--link-accent);
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
text-underline-offset: 2px;
|
text-underline-offset: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-source a:hover {
|
.card-source a:hover {
|
||||||
color: var(--mauve);
|
color: var(--link-accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-desc a {
|
.card-desc a {
|
||||||
@@ -863,13 +978,13 @@ section.full-width {
|
|||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-height: 44px;
|
min-height: 44px;
|
||||||
color: var(--mauve);
|
color: var(--link-accent);
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
text-underline-offset: 2px;
|
text-underline-offset: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-desc a:hover {
|
.card-desc a:hover {
|
||||||
color: var(--mauve);
|
color: var(--link-accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ─── Contact ──────────────────────────────────────────── */
|
/* ─── Contact ──────────────────────────────────────────── */
|
||||||
@@ -1074,6 +1189,10 @@ footer a:hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 540px) {
|
@media (max-width: 540px) {
|
||||||
|
.nav-actions {
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
.nav-links {
|
.nav-links {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ function element(dataset = {}, textContent = '') {
|
|||||||
scrollIntoView() {
|
scrollIntoView() {
|
||||||
this.scrolledIntoView = true;
|
this.scrolledIntoView = true;
|
||||||
},
|
},
|
||||||
|
contains: () => false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +113,126 @@ function fixture({ missingFilter = false, reducedMotion = false } = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function animatedFixture(options) {
|
||||||
|
const f = fixture(options);
|
||||||
|
const animations = [];
|
||||||
|
const listeners = new Map();
|
||||||
|
const media = {
|
||||||
|
matches: options?.reducedMotion ?? false,
|
||||||
|
addEventListener: (name, listener) =>
|
||||||
|
listeners.set(`motion-${name}`, listener),
|
||||||
|
};
|
||||||
|
f.context.window.matchMedia = () => media;
|
||||||
|
f.context.window.addEventListener = (name, listener) =>
|
||||||
|
listeners.set(name, listener);
|
||||||
|
f.context.window.getComputedStyle = () => ({ opacity: '1' });
|
||||||
|
for (const card of f.cards) {
|
||||||
|
card.getBoundingClientRect = () => {
|
||||||
|
const index = f.visible().indexOf(card);
|
||||||
|
return { left: (index % 3) * 300, top: Math.floor(index / 3) * 200 };
|
||||||
|
};
|
||||||
|
card.animate = (frames, timing) => {
|
||||||
|
const animation = {
|
||||||
|
card,
|
||||||
|
frames,
|
||||||
|
timing,
|
||||||
|
cancelled: false,
|
||||||
|
cancel() {
|
||||||
|
this.cancelled = true;
|
||||||
|
},
|
||||||
|
addEventListener(name, listener) {
|
||||||
|
if (name === 'finish') this.finish = listener;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
animations.push(animation);
|
||||||
|
return animation;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { ...f, animations, listeners, media };
|
||||||
|
}
|
||||||
|
|
||||||
|
test('filtering moves retained cards and fades in new cards without delaying results', () => {
|
||||||
|
const f = animatedFixture();
|
||||||
|
f.start();
|
||||||
|
assert.equal(f.animations.length, 0);
|
||||||
|
const rust = f.chips.find((chip) => chip.dataset.filter === 'rust');
|
||||||
|
rust.click();
|
||||||
|
assert.equal(f.visible().length, 1);
|
||||||
|
assert.equal(
|
||||||
|
f.controls.get('#project-count').textContent,
|
||||||
|
'Showing 1 of 1 project (Rust)'
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
f.animations.some(
|
||||||
|
(animation) => animation.frames[0].transform !== 'translate(0px, 0px)'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
f.animations.every((animation) => animation.timing.duration === 280)
|
||||||
|
);
|
||||||
|
f.chips[0].click();
|
||||||
|
assert.equal(f.visible().length, 9);
|
||||||
|
assert.ok(
|
||||||
|
f.animations.some((animation) => animation.frames[0].opacity === 0)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('rapid filter changes cancel old animations and finish on the latest selection', () => {
|
||||||
|
const f = animatedFixture();
|
||||||
|
f.start();
|
||||||
|
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
|
||||||
|
const previous = [...f.animations];
|
||||||
|
f.chips[0].click();
|
||||||
|
assert.ok(previous.every((animation) => animation.cancelled));
|
||||||
|
const current = f.animations.filter((animation) => !animation.cancelled);
|
||||||
|
previous.forEach((animation) => animation.finish());
|
||||||
|
f.listeners.get('resize')();
|
||||||
|
assert.ok(current.every((animation) => animation.cancelled));
|
||||||
|
assert.equal(f.visible().length, 9);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('reduced motion is instant and enabling it cancels in-flight animations', () => {
|
||||||
|
const reduced = animatedFixture({ reducedMotion: true });
|
||||||
|
reduced.start();
|
||||||
|
reduced.chips.find((chip) => chip.dataset.filter === 'rust').click();
|
||||||
|
assert.equal(reduced.visible().length, 1);
|
||||||
|
assert.equal(reduced.animations.length, 0);
|
||||||
|
|
||||||
|
const f = animatedFixture();
|
||||||
|
f.start();
|
||||||
|
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
|
||||||
|
f.media.matches = true;
|
||||||
|
f.listeners.get('motion-change')();
|
||||||
|
assert.ok(f.animations.every((animation) => animation.cancelled));
|
||||||
|
const count = f.animations.length;
|
||||||
|
f.chips[0].click();
|
||||||
|
assert.equal(f.animations.length, count);
|
||||||
|
assert.equal(f.visible().length, 9);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('filtering restores focus when the focused project becomes hidden', () => {
|
||||||
|
const f = fixture();
|
||||||
|
f.start();
|
||||||
|
const focused = f.cards.find((card) => !card.dataset.tech.includes('rust'));
|
||||||
|
f.context.document.activeElement = focused;
|
||||||
|
focused.contains = (target) => target === focused;
|
||||||
|
const rust = f.chips.find((chip) => chip.dataset.filter === 'rust');
|
||||||
|
rust.click();
|
||||||
|
assert.equal(focused.hidden, true);
|
||||||
|
assert.equal(rust.focused, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keyboard focus immediately settles a moving project', () => {
|
||||||
|
const f = animatedFixture();
|
||||||
|
f.start();
|
||||||
|
f.chips.find((chip) => chip.dataset.filter === 'rust').click();
|
||||||
|
const animation = f.animations[0];
|
||||||
|
f.controls.get('#project-grid').dispatch('focusin', {
|
||||||
|
target: { closest: () => animation.card },
|
||||||
|
});
|
||||||
|
assert.equal(animation.cancelled, true);
|
||||||
|
});
|
||||||
|
|
||||||
test('projects start collapsed with an accurate count and remaining label', () => {
|
test('projects start collapsed with an accurate count and remaining label', () => {
|
||||||
const f = fixture();
|
const f = fixture();
|
||||||
f.start();
|
f.start();
|
||||||
|
|||||||
@@ -0,0 +1,187 @@
|
|||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const { readFileSync } = require('node:fs');
|
||||||
|
const { resolve } = require('node:path');
|
||||||
|
const { test } = require('node:test');
|
||||||
|
const { runInNewContext } = require('node:vm');
|
||||||
|
|
||||||
|
const root = resolve(__dirname, '..');
|
||||||
|
const script = readFileSync(resolve(root, 'theme.js'), 'utf8');
|
||||||
|
const html = readFileSync(resolve(root, 'index.html'), 'utf8');
|
||||||
|
|
||||||
|
function fixture({
|
||||||
|
dark = false,
|
||||||
|
saved = null,
|
||||||
|
storageError = null,
|
||||||
|
writeError = null,
|
||||||
|
} = {}) {
|
||||||
|
const dataset = {};
|
||||||
|
const storage = new Map(saved === null ? [] : [['havox-theme', saved]]);
|
||||||
|
const meta = [{ content: '#1e1e2e' }, { content: '#eff1f5' }];
|
||||||
|
const listeners = new Map();
|
||||||
|
const warnings = [];
|
||||||
|
const attributes = new Map();
|
||||||
|
const button = {
|
||||||
|
hidden: true,
|
||||||
|
dataset: {},
|
||||||
|
setAttribute: (name, value) => attributes.set(name, value),
|
||||||
|
getAttribute: (name) => attributes.get(name),
|
||||||
|
addEventListener: (name, listener) => listeners.set(name, listener),
|
||||||
|
};
|
||||||
|
const media = {
|
||||||
|
matches: dark,
|
||||||
|
addEventListener: (name, listener) =>
|
||||||
|
listeners.set(`system-${name}`, listener),
|
||||||
|
};
|
||||||
|
const context = {
|
||||||
|
document: {
|
||||||
|
documentElement: { dataset },
|
||||||
|
querySelectorAll: () => meta,
|
||||||
|
querySelector: () => button,
|
||||||
|
addEventListener: (name, listener) => listeners.set(name, listener),
|
||||||
|
},
|
||||||
|
window: {
|
||||||
|
matchMedia: (query) => {
|
||||||
|
assert.equal(query, '(prefers-color-scheme: dark)');
|
||||||
|
return media;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
localStorage: {
|
||||||
|
getItem: (key) => {
|
||||||
|
if (storageError) throw storageError;
|
||||||
|
return storage.get(key) ?? null;
|
||||||
|
},
|
||||||
|
setItem: (key, value) => {
|
||||||
|
if (storageError) throw storageError;
|
||||||
|
if (writeError) throw writeError;
|
||||||
|
storage.set(key, value);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
console: { warn: (...args) => warnings.push(args) },
|
||||||
|
};
|
||||||
|
runInNewContext(script, context);
|
||||||
|
return {
|
||||||
|
dataset,
|
||||||
|
storage,
|
||||||
|
meta,
|
||||||
|
button,
|
||||||
|
warnings,
|
||||||
|
ready: () => listeners.get('DOMContentLoaded')(),
|
||||||
|
toggle: () => listeners.get('click')(),
|
||||||
|
setSystemDark(value) {
|
||||||
|
media.matches = value;
|
||||||
|
listeners.get('system-change')();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test('system preference applies immediately and follows operating-system changes', () => {
|
||||||
|
for (const dark of [false, true]) {
|
||||||
|
const f = fixture({ dark });
|
||||||
|
assert.equal(f.dataset.theme, undefined);
|
||||||
|
assert.ok(
|
||||||
|
f.meta.every((meta) => meta.content === (dark ? '#1e1e2e' : '#eff1f5'))
|
||||||
|
);
|
||||||
|
assert.equal(f.button.hidden, true);
|
||||||
|
f.ready();
|
||||||
|
assert.equal(f.button.hidden, false);
|
||||||
|
assert.equal(f.button.dataset.theme, dark ? 'dark' : 'light');
|
||||||
|
assert.equal(
|
||||||
|
f.button.getAttribute('aria-label'),
|
||||||
|
`Switch to ${dark ? 'light' : 'dark'} theme`
|
||||||
|
);
|
||||||
|
f.setSystemDark(!dark);
|
||||||
|
assert.equal(f.button.dataset.theme, dark ? 'light' : 'dark');
|
||||||
|
assert.equal(
|
||||||
|
f.button.getAttribute('aria-label'),
|
||||||
|
`Switch to ${dark ? 'dark' : 'light'} theme`
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
f.meta.every((meta) => meta.content === (dark ? '#eff1f5' : '#1e1e2e'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('saved themes override the system before first paint', () => {
|
||||||
|
for (const saved of ['light', 'dark']) {
|
||||||
|
const f = fixture({ dark: saved === 'light', saved });
|
||||||
|
assert.equal(f.dataset.theme, saved);
|
||||||
|
f.ready();
|
||||||
|
assert.equal(f.button.dataset.theme, saved);
|
||||||
|
f.setSystemDark(saved === 'dark');
|
||||||
|
assert.equal(f.dataset.theme, saved);
|
||||||
|
assert.ok(
|
||||||
|
f.meta.every(
|
||||||
|
(meta) => meta.content === (saved === 'dark' ? '#1e1e2e' : '#eff1f5')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert.ok(html.indexOf('src="theme.js"') < html.indexOf('href="style.css"'));
|
||||||
|
const notFound = readFileSync(resolve(root, '404.html'), 'utf8');
|
||||||
|
assert.ok(
|
||||||
|
notFound.indexOf('src="theme.js"') < notFound.indexOf('href="style.css"')
|
||||||
|
);
|
||||||
|
assert.match(
|
||||||
|
notFound,
|
||||||
|
/class="theme-toggle"[\s\S]*?type="button"[\s\S]*?hidden/
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the button toggles the effective theme and persists the explicit choice', () => {
|
||||||
|
const f = fixture({ dark: true });
|
||||||
|
f.ready();
|
||||||
|
f.toggle();
|
||||||
|
assert.equal(f.dataset.theme, 'light');
|
||||||
|
assert.equal(f.storage.get('havox-theme'), 'light');
|
||||||
|
f.toggle();
|
||||||
|
assert.equal(f.dataset.theme, 'dark');
|
||||||
|
assert.equal(f.storage.get('havox-theme'), 'dark');
|
||||||
|
f.setSystemDark(false);
|
||||||
|
assert.equal(f.dataset.theme, 'dark');
|
||||||
|
assert.equal(f.button.dataset.theme, 'dark');
|
||||||
|
assert.ok(f.meta.every((meta) => meta.content === '#1e1e2e'));
|
||||||
|
const reloaded = fixture({
|
||||||
|
dark: false,
|
||||||
|
saved: f.storage.get('havox-theme'),
|
||||||
|
});
|
||||||
|
reloaded.ready();
|
||||||
|
assert.equal(reloaded.button.dataset.theme, 'dark');
|
||||||
|
reloaded.toggle();
|
||||||
|
assert.equal(reloaded.dataset.theme, 'light');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('invalid saved values do not become theme attributes', () => {
|
||||||
|
const f = fixture({ saved: 'unexpected' });
|
||||||
|
f.ready();
|
||||||
|
assert.equal(f.dataset.theme, undefined);
|
||||||
|
assert.equal(f.button.dataset.theme, 'light');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('blocked storage warns but does not prevent switching themes', () => {
|
||||||
|
const storageError = new Error('Storage denied');
|
||||||
|
storageError.name = 'SecurityError';
|
||||||
|
const f = fixture({ storageError });
|
||||||
|
f.ready();
|
||||||
|
f.toggle();
|
||||||
|
assert.equal(f.dataset.theme, 'dark');
|
||||||
|
assert.ok(f.meta.every((meta) => meta.content === '#1e1e2e'));
|
||||||
|
assert.equal(f.warnings.length, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('unexpected storage errors are not swallowed', () => {
|
||||||
|
assert.throws(
|
||||||
|
() => fixture({ storageError: new Error('Unexpected failure') }),
|
||||||
|
/Unexpected failure/
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('full storage does not prevent toggling in either direction', () => {
|
||||||
|
const writeError = new Error('Storage full');
|
||||||
|
writeError.name = 'QuotaExceededError';
|
||||||
|
const f = fixture({ writeError });
|
||||||
|
f.ready();
|
||||||
|
f.toggle();
|
||||||
|
assert.equal(f.dataset.theme, 'dark');
|
||||||
|
f.toggle();
|
||||||
|
assert.equal(f.dataset.theme, 'light');
|
||||||
|
assert.equal(f.warnings.length, 2);
|
||||||
|
});
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
const themeRoot = document.documentElement;
|
||||||
|
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
|
let selectedTheme = 'system';
|
||||||
|
let themeButton;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const savedTheme = localStorage.getItem('havox-theme');
|
||||||
|
if (savedTheme === 'light' || savedTheme === 'dark') {
|
||||||
|
selectedTheme = savedTheme;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error.name !== 'SecurityError') throw error;
|
||||||
|
console.warn('Theme preference storage is unavailable.', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyTheme() {
|
||||||
|
if (selectedTheme === 'system') {
|
||||||
|
delete themeRoot.dataset.theme;
|
||||||
|
} else {
|
||||||
|
themeRoot.dataset.theme = selectedTheme;
|
||||||
|
}
|
||||||
|
const dark =
|
||||||
|
selectedTheme === 'dark' ||
|
||||||
|
(selectedTheme === 'system' && systemTheme.matches);
|
||||||
|
document.querySelectorAll('meta[name="theme-color"]').forEach((meta) => {
|
||||||
|
meta.content = dark ? '#1e1e2e' : '#eff1f5';
|
||||||
|
});
|
||||||
|
if (themeButton) {
|
||||||
|
const action = `Switch to ${dark ? 'light' : 'dark'} theme`;
|
||||||
|
themeButton.dataset.theme = dark ? 'dark' : 'light';
|
||||||
|
themeButton.setAttribute('aria-label', action);
|
||||||
|
themeButton.title = `${dark ? 'Dark' : 'Light'} theme. ${action}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore the preference before the stylesheet paints the page.
|
||||||
|
applyTheme();
|
||||||
|
systemTheme.addEventListener('change', applyTheme);
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
themeButton = document.querySelector('.theme-toggle');
|
||||||
|
applyTheme();
|
||||||
|
themeButton.hidden = false;
|
||||||
|
themeButton.addEventListener('click', () => {
|
||||||
|
selectedTheme = themeButton.dataset.theme === 'dark' ? 'light' : 'dark';
|
||||||
|
applyTheme();
|
||||||
|
try {
|
||||||
|
localStorage.setItem('havox-theme', selectedTheme);
|
||||||
|
} catch (error) {
|
||||||
|
if (
|
||||||
|
error.name !== 'SecurityError' &&
|
||||||
|
error.name !== 'QuotaExceededError'
|
||||||
|
) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
console.warn('Theme preference could not be saved.', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user