Skip to content
Closed
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
22 changes: 22 additions & 0 deletions web/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

/* ---- Light Theme (default) ---- */
:root, [data-theme="light"] {
color-scheme: light;
--bg-primary: #fdfbff;
--bg-secondary: #f9f4fb;
--bg-tertiary: #f2e9f4;
Expand Down Expand Up @@ -78,6 +79,7 @@

/* ---- Dark Theme ---- */
[data-theme="dark"] {
color-scheme: dark;
--bg-primary: #0f1117;
--bg-secondary: #151821;
--bg-tertiary: #1a1d28;
Expand Down Expand Up @@ -242,6 +244,26 @@ p {
color: white;
}

/* ---- Docs syntax highlighting ---- */
.hl-comment { color: #64748b; }
.hl-command { color: var(--accent); }
.hl-arg,
.hl-flag { color: #15803d; }
.hl-operator { color: #6b7280; }
.hl-value { color: #a16207; }
.hl-keyword { color: #7c3aed; }
.hl-string { color: #c2410c; }
.hl-builtin { color: #0369a1; }

[data-theme="dark"] .hl-comment { color: #94a3b8; }
[data-theme="dark"] .hl-arg,
[data-theme="dark"] .hl-flag { color: #22c55e; }
[data-theme="dark"] .hl-operator { color: #e5e7eb; }
[data-theme="dark"] .hl-value { color: #eab308; }
[data-theme="dark"] .hl-keyword { color: #a855f7; }
[data-theme="dark"] .hl-string { color: #f97316; }
[data-theme="dark"] .hl-builtin { color: #0ea5e9; }

/* Scrollbar */
::-webkit-scrollbar {
width: 6px;
Expand Down
11 changes: 6 additions & 5 deletions web/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
/>
<script>
(function() {
var pref = localStorage.getItem('hashprep-theme') || 'system';
var theme = pref;
if (pref === 'system') {
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
var pref;
try { pref = localStorage.getItem('hashprep-theme') || 'system'; } catch(e) { pref = 'system'; }
var theme = pref === 'system'
? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
: pref;
document.documentElement.setAttribute('data-theme', theme);
document.documentElement.style.colorScheme = theme;
})();
</script>
%sveltekit.head%
Expand Down
17 changes: 15 additions & 2 deletions web/src/lib/theme.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ import { browser } from '$app/environment';

type Theme = 'light' | 'dark';

function safeLocalStorage(action: 'get' | 'set', key: string, value?: string): string | null {
try {
if (action === 'get') return localStorage.getItem(key);
localStorage.setItem(key, value!);
return null;
} catch {
return null;
}
}

function getSystemTheme(): Theme {
if (!browser) return 'light';
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}

function getStoredPreference(): 'light' | 'dark' | 'system' {
if (!browser) return 'system';
return (localStorage.getItem('hashprep-theme') as 'light' | 'dark' | 'system') || 'system';
return (safeLocalStorage('get', 'hashprep-theme') as 'light' | 'dark' | 'system') || 'system';
}

let preference = $state<'light' | 'dark' | 'system'>(getStoredPreference());
Expand All @@ -18,12 +28,15 @@ let resolved = $derived<Theme>(preference === 'system' ? getSystemTheme() : pref
function apply(t: Theme) {
if (!browser) return;
document.documentElement.setAttribute('data-theme', t);
// Safari needs color-scheme set explicitly to reliably trigger a full
// style recalculation when the theme attribute changes on <html>.
document.documentElement.style.colorScheme = t;
}

function setPreference(pref: 'light' | 'dark' | 'system') {
preference = pref;
if (browser) {
localStorage.setItem('hashprep-theme', pref);
safeLocalStorage('set', 'hashprep-theme', pref);
}
apply(pref === 'system' ? getSystemTheme() : pref);
}
Expand Down
47 changes: 0 additions & 47 deletions web/src/routes/docs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,6 @@ summary = analyzer.analyze()</code></pre>
margin-bottom: 20px;
}

code {
font-family: var(--font-mono);
}

pre::before {
position: absolute;
inset-block-start: 6px;
Expand All @@ -742,49 +738,6 @@ summary = analyzer.analyze()</code></pre>
content: 'Python';
}

/* Syntax highlighting — light-mode defaults */
.hl-comment {
color: #64748b;
}

.hl-command {
color: var(--accent);
}

.hl-arg,
.hl-flag {
color: #15803d;
}

.hl-operator {
color: #6b7280;
}

.hl-value {
color: #a16207;
}

.hl-keyword {
color: #7c3aed;
}

.hl-string {
color: #c2410c;
}

.hl-builtin {
color: #0369a1;
}

/* Syntax highlighting — dark-mode overrides */
:global([data-theme="dark"]) .hl-comment { color: #94a3b8; }
:global([data-theme="dark"]) .hl-arg,
:global([data-theme="dark"]) .hl-flag { color: #22c55e; }
:global([data-theme="dark"]) .hl-operator { color: #e5e7eb; }
:global([data-theme="dark"]) .hl-value { color: #eab308; }
:global([data-theme="dark"]) .hl-keyword { color: #a855f7; }
:global([data-theme="dark"]) .hl-string { color: #f97316; }
:global([data-theme="dark"]) .hl-builtin { color: #0ea5e9; }

@media (max-width: 960px) {
.docs-layout {
Expand Down
3 changes: 3 additions & 0 deletions web/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cleanUrls": true
}
Loading