mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-22 22:02:40 +03:00
Implemented font size switching in settings
This commit is contained in:
1 parent
e1383dd76b
commit
8917acd019
7 files changed
+252
-55
No files matched your search
@@ -9,6 +9,7 @@
|
||||
import { customCss } from '$lib/stores/customCss';
|
||||
import { siteCustomization } from '$lib/stores/siteCustomization';
|
||||
import { primaryColor } from '$lib/stores/primaryColor';
|
||||
import { fontScale, fontScaleOptions, type FontScaleLevel } from '$lib/stores/fontScale';
|
||||
import { storage } from '$lib/utils/localStorage';
|
||||
|
||||
interface Props {
|
||||
@@ -30,6 +31,7 @@
|
||||
let currentNavbarDisplay = $state(navbarDisplay);
|
||||
let currentHomepageLayout = $state(homepageLayout);
|
||||
let currentCustomCss = $state(customCss);
|
||||
let currentFontScale = $state(fontScale);
|
||||
|
||||
// Form inputs
|
||||
let cssInput = $state('');
|
||||
@@ -120,6 +122,8 @@
|
||||
navbarDisplay.setMode((e.currentTarget as HTMLSelectElement).value as NavbarDisplayMode),
|
||||
homepageChange: (e: Event) =>
|
||||
homepageLayout.setMode((e.currentTarget as HTMLSelectElement).value as HomepageLayoutMode),
|
||||
fontScaleChange: (e: Event) =>
|
||||
fontScale.setLevel(parseInt((e.currentTarget as HTMLInputElement).value, 10) as FontScaleLevel),
|
||||
linkClick: () => onClose?.(),
|
||||
|
||||
applyCustomCss: () => {
|
||||
@@ -272,6 +276,29 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if standalone}
|
||||
<div class="settings-section font-size-section">
|
||||
<h3>Font Scale</h3>
|
||||
<div class="font-scale-slider">
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max="4"
|
||||
step="1"
|
||||
value={$currentFontScale}
|
||||
oninput={handlers.fontScaleChange}
|
||||
aria-label="Font scale"
|
||||
class="slider"
|
||||
/>
|
||||
<div class="slider-labels">
|
||||
{#each fontScaleOptions as option (option.level)}
|
||||
<span class="slider-label" class:active={$currentFontScale === option.level}>{option.label}</span>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Language Selection -->
|
||||
<div class="settings-section language-section">
|
||||
<h3>Language</h3>
|
||||
@@ -548,6 +575,9 @@
|
||||
margin: 0;
|
||||
|
||||
&.theme-section {
|
||||
grid-row: span 3;
|
||||
}
|
||||
&.language-section {
|
||||
grid-row: span 2;
|
||||
}
|
||||
&.accessibility-section {
|
||||
@@ -639,20 +669,8 @@
|
||||
color: var(--text-secondary);
|
||||
|
||||
&:hover:not(.disabled) {
|
||||
background: var(--surface-hover);
|
||||
border-color: var(--border-secondary);
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: color-mix(in srgb, var(--color-primary), transparent 90%);
|
||||
border-color: var(--color-primary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.theme-preview {
|
||||
@@ -662,23 +680,104 @@
|
||||
border: 1px solid var(--border-secondary);
|
||||
}
|
||||
|
||||
.font-scale-slider {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-sm);
|
||||
|
||||
.slider {
|
||||
width: 100%;
|
||||
height: 0.375rem;
|
||||
background: linear-gradient(to right, var(--bg-tertiary) 0%, var(--border-primary) 50%, var(--bg-tertiary) 100%);
|
||||
border-radius: var(--radius-sm);
|
||||
outline: none;
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
|
||||
&::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
background: var(--color-primary);
|
||||
border: 2px solid var(--bg-secondary);
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
&::-moz-range-thumb {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
background: var(--color-primary);
|
||||
border: 2px solid var(--bg-secondary);
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus {
|
||||
&::-webkit-slider-thumb {
|
||||
outline: 2px solid var(--color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
&::-moz-range-thumb {
|
||||
outline: 2px solid var(--color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.slider-labels {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-tertiary);
|
||||
margin-top: var(--spacing-xs);
|
||||
|
||||
.slider-label {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
transition: all var(--transition-fast);
|
||||
font-size: var(--font-size-xs);
|
||||
|
||||
&.active {
|
||||
color: var(--color-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
&:first-child {
|
||||
text-align: left;
|
||||
}
|
||||
&:last-child {
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.language-dropdown {
|
||||
gap: var(--spacing-xs);
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
|
||||
}
|
||||
|
||||
.language-option {
|
||||
padding: var(--spacing-sm);
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
|
||||
.language-option,
|
||||
.theme-option {
|
||||
&:hover:not(.disabled) {
|
||||
background: var(--surface-hover);
|
||||
color: var(--text-primary);
|
||||
@@ -696,6 +795,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
.language-option {
|
||||
padding: var(--spacing-sm);
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.navbar-select-wrapper {
|
||||
position: relative;
|
||||
display: block;
|
||||
@@ -857,11 +968,11 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.show-more-btn {
|
||||
.show-more-btn,
|
||||
.custom-color-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
width: 100%;
|
||||
padding: var(--spacing-sm);
|
||||
background: transparent;
|
||||
border: 1px solid var(--border-primary);
|
||||
@@ -870,14 +981,18 @@
|
||||
font-size: var(--font-size-xs);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
margin-top: var(--spacing-sm);
|
||||
justify-content: center;
|
||||
|
||||
&:hover {
|
||||
background: var(--surface-hover);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.show-more-btn {
|
||||
width: 100%;
|
||||
margin-top: var(--spacing-sm);
|
||||
justify-content: center;
|
||||
|
||||
&[aria-expanded='true'] {
|
||||
color: var(--color-primary);
|
||||
@@ -1006,24 +1121,9 @@
|
||||
|
||||
.custom-color-toggle {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--text-secondary);
|
||||
font-size: var(--font-size-sm);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
|
||||
&:hover {
|
||||
background: var(--surface-hover);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.custom-color-inputs {
|
||||
|
||||
@@ -66,4 +66,10 @@ export const DEFAULT_LANGUAGE = env.NTB_DEFAULT_LANGUAGE ?? 'en';
|
||||
*/
|
||||
export const PRIMARY_COLOR = env.NTB_PRIMARY_COLOR ?? '';
|
||||
|
||||
/**
|
||||
* Default font scale level
|
||||
* Options: 0 (Very Small), 1 (Small), 2 (Normal), 3 (Large), 4 (Very Large)
|
||||
*/
|
||||
export const DEFAULT_FONT_SCALE = parseInt(env.NTB_FONT_SCALE ?? '2', 10);
|
||||
|
||||
export const SHOW_TIPS_ON_HOMEPAGE = !!env.NTB_SHOW_TIPS_ON_HOMEPAGE;
|
||||
@@ -0,0 +1,79 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
import { storage } from '$lib/utils/localStorage';
|
||||
import { DEFAULT_FONT_SCALE } from '$lib/config/customizable-settings';
|
||||
|
||||
export type FontScaleLevel = 0 | 1 | 2 | 3 | 4;
|
||||
|
||||
export interface FontScaleOption {
|
||||
level: FontScaleLevel;
|
||||
label: string;
|
||||
scale: number;
|
||||
}
|
||||
|
||||
export const fontScaleOptions: FontScaleOption[] = [
|
||||
{ level: 0, label: 'Extra Small', scale: 0.85 },
|
||||
{ level: 1, label: 'Small', scale: 0.925 },
|
||||
{ level: 2, label: 'Normal', scale: 1.0 },
|
||||
{ level: 3, label: 'Large', scale: 1.075 },
|
||||
{ level: 4, label: 'Extra Large', scale: 1.15 },
|
||||
];
|
||||
|
||||
const STORAGE_KEY = 'font-scale';
|
||||
|
||||
function isValidLevel(level: unknown): level is FontScaleLevel {
|
||||
return typeof level === 'number' && level >= 0 && level <= 4;
|
||||
}
|
||||
|
||||
function applyFontScale(level: FontScaleLevel) {
|
||||
if (!browser) return;
|
||||
|
||||
const option = fontScaleOptions.find((opt) => opt.level === level);
|
||||
if (!option) return;
|
||||
|
||||
document.documentElement.style.setProperty('--font-scale', option.scale.toString());
|
||||
}
|
||||
|
||||
function createFontScaleStore() {
|
||||
const defaultLevel = isValidLevel(DEFAULT_FONT_SCALE) ? DEFAULT_FONT_SCALE : 2;
|
||||
const { subscribe, set } = writable<FontScaleLevel>(defaultLevel);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
|
||||
// Initialize from localStorage or default
|
||||
init: () => {
|
||||
if (browser) {
|
||||
const saved = localStorage.getItem(STORAGE_KEY);
|
||||
const savedLevel = saved ? parseInt(saved, 10) : null;
|
||||
const initialLevel = savedLevel !== null && isValidLevel(savedLevel) ? savedLevel : defaultLevel;
|
||||
|
||||
set(initialLevel);
|
||||
applyFontScale(initialLevel);
|
||||
|
||||
return initialLevel;
|
||||
}
|
||||
return defaultLevel;
|
||||
},
|
||||
|
||||
// Set font scale level
|
||||
setLevel: (level: FontScaleLevel) => {
|
||||
if (!isValidLevel(level)) return;
|
||||
|
||||
set(level);
|
||||
|
||||
if (browser) {
|
||||
storage.setItem(STORAGE_KEY, level.toString(), { serialize: false });
|
||||
applyFontScale(level);
|
||||
}
|
||||
},
|
||||
|
||||
// Get scale value for a level
|
||||
getScale: (level: FontScaleLevel): number => {
|
||||
const option = fontScaleOptions.find((opt) => opt.level === level);
|
||||
return option?.scale ?? 1.0;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const fontScale = createFontScaleStore();
|
||||
@@ -9,7 +9,7 @@
|
||||
import { ALL_PAGES, type NavItem } from '$lib/constants/nav';
|
||||
|
||||
// Defensive helper to safely read values
|
||||
const safely = <T>(fn: () => T, fallback: T): T => {
|
||||
const safely = <T,>(fn: () => T, fallback: T): T => {
|
||||
try {
|
||||
return fn();
|
||||
} catch (err) {
|
||||
@@ -19,7 +19,9 @@
|
||||
};
|
||||
|
||||
let status = $derived(safely(() => $page.status ?? 500, 500));
|
||||
let message = $derived(safely(() => $page.error?.message ?? 'An unexpected error occurred', 'An unexpected error occurred'));
|
||||
let message = $derived(
|
||||
safely(() => $page.error?.message ?? 'An unexpected error occurred', 'An unexpected error occurred'),
|
||||
);
|
||||
let errorId = $derived(safely(() => ($page.error as any)?.errorId, undefined));
|
||||
|
||||
let suggestions = $state<NavItem[]>([]);
|
||||
@@ -29,7 +31,10 @@
|
||||
try {
|
||||
if (!path || path === '/') return [];
|
||||
|
||||
const query = path.toLowerCase().replace(/^\/|\/$/g, '').replace(/[_-]/g, ' ');
|
||||
const query = path
|
||||
.toLowerCase()
|
||||
.replace(/^\/|\/$/g, '')
|
||||
.replace(/[_-]/g, ' ');
|
||||
const tokens = query.split(/[/\s]+/).filter((t) => t.length > 1);
|
||||
if (tokens.length === 0) return [];
|
||||
|
||||
@@ -52,7 +57,10 @@
|
||||
|
||||
// Acronym match
|
||||
if (tokens.length === 1) {
|
||||
const acronym = label.split(/\s+/).map((w) => w[0]).join('');
|
||||
const acronym = label
|
||||
.split(/\s+/)
|
||||
.map((w) => w[0])
|
||||
.join('');
|
||||
if (acronym === tokens[0]) score += 200;
|
||||
}
|
||||
|
||||
@@ -186,7 +194,6 @@
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{:else}
|
||||
<div class="error-suggestions">
|
||||
<h3>What can you do?</h3>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
import { customCss } from '$lib/stores/customCss';
|
||||
import { siteCustomization } from '$lib/stores/siteCustomization';
|
||||
import { primaryColor } from '$lib/stores/primaryColor';
|
||||
import { fontScale } from '$lib/stores/fontScale';
|
||||
import { ALL_PAGES } from '$lib/constants/nav';
|
||||
import { initializeOfflineSupport } from '$lib/stores/offline';
|
||||
import { bookmarks } from '$lib/stores/bookmarks';
|
||||
@@ -137,6 +138,7 @@
|
||||
customCss.init();
|
||||
siteCustomization.init();
|
||||
primaryColor.init();
|
||||
fontScale.init();
|
||||
initializeOfflineSupport();
|
||||
|
||||
// Add global keyboard shortcuts
|
||||
|
||||
@@ -55,18 +55,21 @@
|
||||
--spacing-xl: 2rem;
|
||||
--spacing-2xl: 3rem;
|
||||
|
||||
/* Font scale (adjustable via settings) */
|
||||
--font-scale: 1;
|
||||
|
||||
/* Font categories */
|
||||
--font-body: 'Fira Code', 'Monaco', 'Menlo', 'Consolas', monospace;
|
||||
--font-heading: 'Fira Code', 'Monaco', 'Menlo', 'Consolas', monospace;
|
||||
--font-mono: 'Fira Code', 'Monaco', 'Menlo', 'Consolas', monospace;
|
||||
--font-size-2xs: 0.6rem;
|
||||
--font-size-xs: 0.75rem;
|
||||
--font-size-sm: 0.875rem;
|
||||
--font-size-md: 1rem;
|
||||
--font-size-lg: 1.125rem;
|
||||
--font-size-xl: 1.25rem;
|
||||
--font-size-2xl: 1.5rem;
|
||||
--font-size-3xl: 2rem;
|
||||
--font-size-2xs: calc(0.6rem * var(--font-scale));
|
||||
--font-size-xs: calc(0.75rem * var(--font-scale));
|
||||
--font-size-sm: calc(0.875rem * var(--font-scale));
|
||||
--font-size-md: calc(1rem * var(--font-scale));
|
||||
--font-size-lg: calc(1.125rem * var(--font-scale));
|
||||
--font-size-xl: calc(1.25rem * var(--font-scale));
|
||||
--font-size-2xl: calc(1.5rem * var(--font-scale));
|
||||
--font-size-3xl: calc(2rem * var(--font-scale));
|
||||
|
||||
/* Transitions */
|
||||
--transition-fast: 0.15s ease;
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 4.5 KiB |
Reference in new issue
Block a user