Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet" />
<script>
(function () {
var stored = null;
try { stored = localStorage.getItem("theme"); } catch (error) {}
var dark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
document.documentElement.dataset.theme = stored || (dark ? "dark" : "light");
var choice = null;
try {
choice = localStorage.getItem("theme-choice");
if (!choice) {
var legacy = localStorage.getItem("theme");
if (legacy === "light" || legacy === "dark") {
choice = legacy;
localStorage.setItem("theme-choice", choice);
localStorage.removeItem("theme");
}
}
} catch (error) {}
if (choice !== "light" && choice !== "dark") choice = "system";
var dark = choice === "dark" ||
(choice === "system" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches);
document.documentElement.dataset.theme = dark ? "dark" : "light";
document.documentElement.dataset.themeChoice = choice;
document.documentElement.classList.add("js");
}());
</script>
<link rel="stylesheet" href="styles.css?v=mobile-veil-comments-1" />
<link rel="stylesheet" href="styles.css?v=mobile-veil-comments-2" />
</head>
<body>
<header class="topbar">
Expand All @@ -48,9 +61,14 @@
<a href="#contact" data-nav="contact">Contact</a>
</nav>
<div class="topbar-actions">
<button id="theme-toggle" class="icon-button" type="button" aria-label="Switch colour theme" aria-pressed="false">
<span aria-hidden="true">◐</span>
</button>
<label class="theme-select-label" for="theme-select">
<span class="visually-hidden">Цветовая тема</span>
<select id="theme-select" class="theme-select">
<option value="system">Системная</option>
<option value="light">Светлая</option>
<option value="dark">Тёмная</option>
</select>
</label>
<a class="topbar-link" href="https://github.com/axisrow" target="_blank" rel="noopener">GitHub ↗</a>
</div>
</div>
Expand Down Expand Up @@ -301,6 +319,6 @@ <h2>Need a system that should keep working?</h2>
</main>

<script src="effect-skins.js?v=mobile-hero-center-1"></script>
<script src="main.js?v=api-v3-visual-fix-3"></script>
<script src="main.js?v=api-v3-visual-fix-6"></script>
</body>
</html>
51 changes: 38 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"use strict";

var root = document.documentElement;
var themeToggle = document.getElementById("theme-toggle");
var themeSelect = document.getElementById("theme-select");
var systemThemeQuery = window.matchMedia("(prefers-color-scheme: dark)");
var menuToggle = document.getElementById("menu-toggle");
var sectionNavigation = document.getElementById("section-navigation");
var reduceMotionQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
Expand All @@ -13,19 +14,37 @@
var libraryReady = false;
var remountTimer = null;

function applyTheme(theme, persist) {
var nextTheme = theme === "dark" ? "dark" : "light";
root.dataset.theme = nextTheme;
if (themeToggle) {
themeToggle.setAttribute("aria-pressed", String(nextTheme === "dark"));
themeToggle.setAttribute("title", nextTheme === "dark" ? "Switch to light theme" : "Switch to dark theme");
}
function readStoredThemeChoice() {
// The <head> bootstrap script already resolved this (and migrated the
// legacy "theme" key) before main.js loaded; reuse it instead of
// re-reading localStorage. Fall back to a fresh read only if that
// bootstrap didn't run (e.g. it errored, or this is a test sandbox).
var stashed = root.dataset.themeChoice;
if (stashed === "light" || stashed === "dark" || stashed === "system") return stashed;
try {
var saved = localStorage.getItem("theme-choice");
if (saved === "light" || saved === "dark" || saved === "system") return saved;
} catch (error) {}
return "system";
}

function resolveTheme(choice) {
if (choice === "dark") return "dark";
if (choice === "light") return "light";
return systemThemeQuery.matches ? "dark" : "light";
}

function applyTheme(choice, persist) {
var next = choice === "dark" || choice === "light" ? choice : "system";
root.dataset.themeChoice = next;
root.dataset.theme = resolveTheme(next);
if (themeSelect) themeSelect.value = next;
if (persist) {
try { localStorage.setItem("theme", nextTheme); } catch (error) {}
try { localStorage.setItem("theme-choice", next); } catch (error) {}
}
}

applyTheme(root.dataset.theme || "light", false);
applyTheme(readStoredThemeChoice(), false);

function closeMenu() {
if (!menuToggle || !sectionNavigation) return;
Expand Down Expand Up @@ -222,13 +241,19 @@
}, 180);
}

if (themeToggle) {
themeToggle.addEventListener("click", function () {
applyTheme(root.dataset.theme === "dark" ? "light" : "dark", true);
if (themeSelect) {
themeSelect.addEventListener("change", function () {
applyTheme(themeSelect.value, true);
remountEffects();
});
}

systemThemeQuery.addEventListener("change", function () {
if (root.dataset.themeChoice !== "system") return;
applyTheme("system", false);
remountEffects();
});

if (menuToggle) {
menuToggle.addEventListener("click", function () {
toggleMenu();
Expand Down
53 changes: 51 additions & 2 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,51 @@ a {
transform: translateY(-1px);
}

.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}

.theme-select-label {
display: inline-flex;
}

.theme-select {
height: 38px;
padding: 0 28px 0 12px;
border: 1px solid var(--line);
border-radius: 10px;
background-color: var(--page-soft);
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 10px center;
color: var(--ink);
font: 500 12px/1 "IBM Plex Mono", monospace;
cursor: pointer;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
transition: border-color 180ms ease, background-color 180ms ease, transform 180ms ease;
}

.theme-select:hover {
border-color: var(--line-strong);
background-color: var(--surface-raised);
transform: translateY(-1px);
}

.theme-select:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}

main {
position: relative;
}
Expand Down Expand Up @@ -1502,7 +1547,7 @@ main {

.menu-toggle {
display: inline-flex;
grid-column: 2;
grid-column: 4;
}

.section-nav {
Expand Down Expand Up @@ -1559,14 +1604,18 @@ main {
}

.topbar-actions {
grid-column: 4;
grid-column: 3;
}

.icon-button {
width: 44px;
height: 44px;
}

.theme-select {
height: 44px;
}

.hero {
min-height: 100svh;
align-items: flex-end;
Expand Down