Makes fonts configurable, adds additional themes

This commit is contained in:
Alicia Sykes committed 2025-09-22 19:07:12 +01:00
1 parent e58cc3a6df
commit 6f68601f44
7 files changed
+149 -47

No files matched your search

@@ -342,19 +342,20 @@
height: 1rem;
border-radius: var(--radius-xs);
border: 1px solid var(--border-secondary);
&.theme-light {
background: linear-gradient(135deg, #f4f2fa 50%, #fff 50%);
}
&.theme-dark {
background: linear-gradient(135deg, #0d1117 50%, #161b22 50%);
}
&.theme-ocean {
background: linear-gradient(135deg, #1a4c7a 50%, #2d5f8f 50%);
opacity: 0.6;
}
&.theme-purple {
background: linear-gradient(135deg, #473180 50%, #9052d3 50%);
opacity: 0.6;
}
}
.language-dropdown {
@@ -456,8 +457,9 @@
gap: var(--spacing-xs);
min-width: 0;
flex: 1;
font-weight: 400;
.toggle-description {
display: none;
color: var(--text-secondary);
font-size: var(--font-size-xs);
line-height: 1.3;
+20 -6
View File
@@ -106,15 +106,16 @@
flex-direction: column;
gap: var(--spacing-sm);
padding: var(--spacing-lg);
background-color: var(--bg-secondary);
background: linear-gradient(225deg, var(--bg-secondary), color-mix(in srgb, var(--bg-secondary), var(--bg-tertiary) 70%));
border: 1px solid var(--border-primary);
border-radius: var(--radius-lg);
text-decoration: none;
color: inherit;
transition: all var(--transition-fast);
transition: all var(--transition-fast), background 0.5s ease-in-out;
position: relative;
height: 100%;
min-width: 0;
overflow: hidden;
.card-header {
display: flex;
@@ -122,6 +123,7 @@
justify-content: space-between;
gap: var(--spacing-sm);
margin: 0 0 var(--spacing-xs) 0;
z-index: 1;
h3 {
font-size: var(--font-size-lg);
@@ -203,6 +205,8 @@
align-items: flex-start;
gap: 1rem;
min-width: 0;
position: relative;
z-index: 1;
}
.tool-content {
@@ -210,11 +214,17 @@
}
&:hover {
background-color: var(--surface-hover);
border-color: var(--color-primary);
// border-color: var(--color-primary);
transform: translateY(-2px);
box-shadow: var(--shadow-lg);
background: linear-gradient(
180deg,
var(--bg-secondary),
color-mix(in srgb, var(--bg-secondary), var(--bg-tertiary) 85%)
);
&::before {
opacity: 1;
}
.tool-arrow {
transform: translateX(4px);
color: var(--color-primary);
@@ -228,7 +238,10 @@
var(--shadow-lg),
0 0 0 4px color-mix(in srgb, var(--color-primary), transparent 85%);
border-color: var(--color-primary);
background-color: var(--surface-hover);
&::before {
opacity: 0.5;
}
}
@media (max-width: 768px) {
@@ -246,6 +259,7 @@
border-radius: var(--radius-lg);
color: var(--bg-secondary);
flex-shrink: 0;
transition: all 0.5s ease;
}
.tool-content {
+30
View File
@@ -86,6 +86,23 @@ const DEFAULT_OPTIONS: AccessibilityOption[] = [
},
];
// Font loading state tracking
let dyslexicFontLoaded = false;
function loadDyslexicFont() {
if (dyslexicFontLoaded) return;
// Create a link element to load the font
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://fonts.cdnfonts.com/css/opendyslexic';
link.crossOrigin = 'anonymous';
// Add to document head
document.head.appendChild(link);
dyslexicFontLoaded = true;
}
function createAccessibilityStore() {
const { subscribe, set, update } = writable<AccessibilitySettings>({
options: DEFAULT_OPTIONS,
@@ -121,6 +138,11 @@ function createAccessibilityStore() {
});
set({ options });
// Load dyslexic font if it's enabled
if (options.some(opt => opt.id === 'dyslexia-font' && opt.enabled)) {
loadDyslexicFont();
}
}
},
@@ -134,6 +156,14 @@ function createAccessibilityStore() {
if (browser) {
localStorage.setItem(STORAGE_KEY, JSON.stringify(newSettings));
// Load dyslexic font if dyslexia-font option was just enabled
if (optionId === 'dyslexia-font') {
const isEnabled = newOptions.find(opt => opt.id === 'dyslexia-font')?.enabled;
if (isEnabled) {
loadDyslexicFont();
}
}
}
return newSettings;
+68 -29
View File
@@ -1,23 +1,69 @@
import { writable } from 'svelte/store';
import { browser } from '$app/environment';
export type ThemeOption = 'light' | 'dark' | 'ocean';
export type ThemeOption = string;
export interface Theme {
id: ThemeOption;
name: string;
available: boolean;
preview?: string;
font?: {
name: string;
url: string;
fallback?: string;
};
}
const STORAGE_KEY = 'theme';
// Track loaded fonts to avoid duplicates
const loadedFonts = new Set<string>();
// Helper function to load custom fonts
function loadCustomFont(fontConfig: { name: string; url: string; fallback?: string }) {
if (!browser || loadedFonts.has(fontConfig.url)) return;
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = fontConfig.url;
link.crossOrigin = 'anonymous';
// Add fallback handling
link.onerror = () => {
console.warn(`Failed to load font from ${fontConfig.url}`);
};
document.head.appendChild(link);
loadedFonts.add(fontConfig.url);
}
// Helper function to apply theme classes and load fonts
function applyThemeClasses(theme: ThemeOption) {
if (!browser) return;
// Remove all existing theme classes
const allThemeClasses = themes.map(t => `theme-${t.id}`);
document.documentElement.classList.remove(...allThemeClasses);
// Add the current theme class (except for default 'dark' theme)
if (theme !== 'dark') {
document.documentElement.classList.add(`theme-${theme}`);
}
// Load custom font if the theme has one
const themeConfig = themes.find(t => t.id === theme);
if (themeConfig?.font) {
loadCustomFont(themeConfig.font);
}
}
// Available themes configuration
export const themes: Theme[] = [
{
id: 'light',
name: 'Light',
available: true,
available: true,
},
{
id: 'dark',
@@ -28,6 +74,21 @@ export const themes: Theme[] = [
id: 'ocean',
name: 'Ocean',
available: true,
font: {
name: 'Inter',
url: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap',
fallback: 'sans-serif'
}
},
{
id: 'purple',
name: 'Purple',
available: true,
font: {
name: 'Poppins',
url: 'https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap',
fallback: 'sans'
}
},
];
@@ -41,21 +102,13 @@ function createThemeStore() {
init: () => {
if (browser) {
const saved = localStorage.getItem(STORAGE_KEY);
const initialTheme =
saved === 'light' || saved === 'dark' || saved === 'ocean' ? (saved as ThemeOption) : 'dark';
const isValidTheme = themes.some(t => t.id === saved && t.available);
const initialTheme = isValidTheme ? (saved as ThemeOption) : 'dark';
set(initialTheme);
// Apply theme to document
if (initialTheme === 'light') {
document.documentElement.classList.add('theme-light');
document.documentElement.classList.remove('theme-dark', 'theme-ocean');
} else if (initialTheme === 'ocean') {
document.documentElement.classList.add('theme-ocean');
document.documentElement.classList.remove('theme-light', 'theme-dark');
} else {
document.documentElement.classList.remove('theme-light', 'theme-ocean');
}
applyThemeClasses(initialTheme);
return initialTheme;
}
@@ -77,16 +130,7 @@ function createThemeStore() {
localStorage.setItem(STORAGE_KEY, theme);
// Apply theme classes to document
if (theme === 'light') {
document.documentElement.classList.add('theme-light');
document.documentElement.classList.remove('theme-dark', 'theme-ocean');
} else if (theme === 'ocean') {
document.documentElement.classList.add('theme-ocean');
document.documentElement.classList.remove('theme-light', 'theme-dark');
} else {
// Default to dark
document.documentElement.classList.remove('theme-light', 'theme-ocean');
}
applyThemeClasses(theme);
}
},
@@ -98,12 +142,7 @@ function createThemeStore() {
if (browser) {
localStorage.setItem(STORAGE_KEY, newTheme);
if (newTheme === 'light') {
document.documentElement.classList.add('theme-light');
document.documentElement.classList.remove('theme-dark');
} else {
document.documentElement.classList.remove('theme-light');
}
applyThemeClasses(newTheme);
}
return newTheme;
-3
View File
@@ -113,9 +113,6 @@ html[data-a11y~='scale-large'] {
/* Dyslexia-Friendly Font */
html[data-a11y~='dyslexia-font'] {
/* Import OpenDyslexic font when needed */
@import url('https://fonts.cdnfonts.com/css/opendyslexic');
font-family: 'OpenDyslexic', 'Comic Sans MS', 'Trebuchet MS', 'Verdana', sans-serif;
letter-spacing: 0.05em;
line-height: 1.6;
+5 -3
View File
@@ -15,7 +15,7 @@ html {
}
body {
font-family: var(--font-mono);
font-family: var(--font-body);
font-size: var(--font-size-sm);
line-height: 1.5;
color: var(--text-primary);
@@ -32,6 +32,7 @@ h3,
h4,
h5,
h6 {
font-family: var(--font-heading);
font-weight: 600;
line-height: 1.3;
margin-bottom: var(--spacing-sm);
@@ -57,7 +58,7 @@ p {
input,
select,
textarea {
font-family: inherit;
font-family: var(--font-body);
font-size: inherit;
color: var(--text-primary);
background-color: var(--bg-secondary);
@@ -87,7 +88,7 @@ input::placeholder {
/* Buttons */
button {
font-family: inherit;
font-family: var(--font-body);
font-size: inherit;
cursor: pointer;
border: none;
@@ -120,6 +121,7 @@ button.btn-icon svg {
/* Labels */
label {
font-family: var(--font-body);
font-size: var(--font-size-xs);
font-weight: 600;
color: var(--text-primary);
+20 -2
View File
@@ -54,7 +54,9 @@
--spacing-xl: 2rem;
--spacing-2xl: 3rem;
/* Font */
/* Font categories */
--font-body: 'Roboto Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
--font-heading: 'Roboto Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
--font-mono: 'Roboto Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
--font-size-2xs: 0.6rem;
--font-size-xs: 0.75rem;
@@ -80,9 +82,25 @@ html[data-theme='ocean'] {
--bg-secondary: #212c3d;
--bg-tertiary: #151e2f;
--text-secondary: #a0a7b0;
--surface-hover: #2b384b;
--border-primary: #30405b;
--font-heading: 'Inter', sans-serif;
--font-body: 'Inter', sans-serif;
}
.theme-purple,
html[data-theme='purple'] {
--color-primary: #cca6ff;
--color-primary-hover: #d4b6fd;
--color-primary-dark: #8d67c0;
--bg-primary: #13182b;
--bg-secondary: #101b31;
--bg-tertiary: #222e45;
--text-secondary: #a0a7b0;
--surface-hover: #2b384b;
--border-primary: #30405b;
--font-body: 'Poppins', sans-serif;
--font-heading: 'Poppins', sans-serif;
}
/* Light theme */