From 5232b85e12454c1b6a69e07311f157249c7a2d18 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 16 Apr 2025 09:26:04 +0200 Subject: [PATCH] Adjust font size --- public/typography.css | 3 +- src/App.svelte | 30 ++++++++++++++++++-- src/components/AssigneeInput.svelte | 2 +- src/components/FontSizeSwitch.svelte | 37 +++++++++++++++++++++++++ src/components/Icon.svelte | 23 +++++++++------ src/components/IssueSecondColumn.svelte | 2 +- src/components/LabelInput.svelte | 2 +- src/components/Reviews.svelte | 2 +- src/components/Settings.svelte | 7 +++++ src/lib/appearance.svelte.ts | 36 ++++++++++++++++++++++++ src/views/repo/Issues.svelte | 2 +- 11 files changed, 130 insertions(+), 16 deletions(-) create mode 100644 src/components/FontSizeSwitch.svelte create mode 100644 src/lib/appearance.svelte.ts diff --git a/public/typography.css b/public/typography.css index 9b14fb025..108809277 100644 --- a/public/typography.css +++ b/public/typography.css @@ -58,6 +58,7 @@ } :root { + --font-size: 16px; --font-family-sans-serif: Inter, sans-serif; --font-family-monospace: monospace; --font-weight-regular: 400; @@ -89,7 +90,7 @@ html { font-feature-settings: "zero"; /* The root element font size has to be set in px, * otherwise Safari breaks. */ - font-size: 16px; + font-size: var(--font-size); font-weight: var(--font-weight-regular); /* On Safari this aligns text with different font-faces properly vertically. */ line-height: 22px; diff --git a/src/App.svelte b/src/App.svelte index 807ffa443..bf3d82da8 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -7,11 +7,17 @@ import * as router from "@app/lib/router"; import { checkAuth, startup } from "@app/lib/auth.svelte"; - import { dynamicInterval } from "@app/lib/interval"; import { createEventEmittersOnce } from "@app/lib/startup.svelte"; + import { dynamicInterval } from "@app/lib/interval"; import { invoke } from "@app/lib/invoke"; + import { + resetFontSize, + increaseFontSize, + decreaseFontSize, + fontSettings, + } from "@app/lib/appearance.svelte"; import { theme } from "@app/components/ThemeSwitch.svelte"; - import { unreachable } from "@app/lib/utils"; + import { unreachable, isMac } from "@app/lib/utils"; import Auth from "@app/views/booting/Auth.svelte"; import CreateIdentity from "@app/views/booting/CreateIdentity.svelte"; @@ -70,9 +76,29 @@ } }); + $effect(() => + document.documentElement.style.setProperty( + "--font-size", + `${fontSettings.size}px`, + ), + ); $effect(() => document.documentElement.setAttribute("data-theme", $theme)); + { + const auxiliarKey = isMac() ? e.metaKey : e.ctrlKey; + // Handles the position of the plus key on different keyboard layouts. + const plusKey = e.key === "1" || e.key === "="; + if (auxiliarKey && (e.key === "+" || plusKey)) { + increaseFontSize(); + } else if (auxiliarKey && e.key === "-") { + decreaseFontSize(); + } else if (auxiliarKey && e.key.toLowerCase() === "0") { + resetFontSize(); + } + }} /> + {#if $activeRouteStore.resource === "booting"} {#if startup.error?.code === "IdentityError.MissingProfile"} diff --git a/src/components/AssigneeInput.svelte b/src/components/AssigneeInput.svelte index e4eea64a5..0c244b5ce 100644 --- a/src/components/AssigneeInput.svelte +++ b/src/components/AssigneeInput.svelte @@ -144,7 +144,7 @@ }} name="cross" /> {:else} - (showInput = true)}> + (showInput = true)}> {/if} {/if} diff --git a/src/components/FontSizeSwitch.svelte b/src/components/FontSizeSwitch.svelte new file mode 100644 index 000000000..e81c7577e --- /dev/null +++ b/src/components/FontSizeSwitch.svelte @@ -0,0 +1,37 @@ + + + + +
+ + + + + +
diff --git a/src/components/Icon.svelte b/src/components/Icon.svelte index 105486cc1..0f6f70296 100644 --- a/src/components/Icon.svelte +++ b/src/components/Icon.svelte @@ -8,6 +8,7 @@ styleDisplay?: string; styleVerticalAlign?: string; name: + | "add" | "arrow-left" | "arrow-right" | "arrow-right-hollow" @@ -39,13 +40,14 @@ | "file" | "filter" | "home" - | "info" | "inbox" + | "info" | "issue" | "issue-closed" | "label" | "lock" | "markdown" + | "minus" | "moon" | "more-vertical" | "none" @@ -115,7 +117,14 @@ height={size} fill="currentColor" viewBox="0 0 16 16"> - {#if name === "arrow-left"} + {#if name === "add"} + + + + + + + {:else if name === "arrow-left"} @@ -734,6 +743,8 @@ + {:else if name === "minus"} + {:else if name === "moon"} @@ -929,12 +940,8 @@ {:else if name === "plus"} - - - - - - + + {:else if name === "reply"} diff --git a/src/components/IssueSecondColumn.svelte b/src/components/IssueSecondColumn.svelte index 2b402899b..6dcd3ca9f 100644 --- a/src/components/IssueSecondColumn.svelte +++ b/src/components/IssueSecondColumn.svelte @@ -150,7 +150,7 @@ }); } }}> - New + New diff --git a/src/components/LabelInput.svelte b/src/components/LabelInput.svelte index 9557dde84..44e1efdfc 100644 --- a/src/components/LabelInput.svelte +++ b/src/components/LabelInput.svelte @@ -120,7 +120,7 @@ }} name="cross" /> {:else} - (showInput = true)}> + (showInput = true)}> {/if} {/if} diff --git a/src/components/Reviews.svelte b/src/components/Reviews.svelte index 38c85e846..6380f8177 100644 --- a/src/components/Reviews.svelte +++ b/src/components/Reviews.svelte @@ -103,7 +103,7 @@ disabled={hasOwnReview} {onclick} title={hasOwnReview ? "You already published a review" : undefined}> - + Review {/snippet} diff --git a/src/components/Settings.svelte b/src/components/Settings.svelte index b2e0e15a2..e8bbe480b 100644 --- a/src/components/Settings.svelte +++ b/src/components/Settings.svelte @@ -3,6 +3,7 @@ import AnnounceSwitch from "./AnnounceSwitch.svelte"; import Border from "./Border.svelte"; + import FontSizeSwitch from "./FontSizeSwitch.svelte"; import Icon from "./Icon.svelte"; import NakedButton from "./NakedButton.svelte"; import Popover from "./Popover.svelte"; @@ -50,6 +51,12 @@ style:width="100%"> Announce changes +
+ Font size +
{/snippet} diff --git a/src/lib/appearance.svelte.ts b/src/lib/appearance.svelte.ts new file mode 100644 index 000000000..df5e0b15d --- /dev/null +++ b/src/lib/appearance.svelte.ts @@ -0,0 +1,36 @@ +export const fontSettings = $state({ size: loadFontSize() }); +const step = 2; +const minFontSize = 14; +const maxFontSize = 24; + + +export function increaseFontSize() { + if (fontSettings.size + step <= maxFontSize) { + setFontSize(fontSettings.size + step); + } +} + +export function decreaseFontSize() { + if (fontSettings.size - step >= minFontSize) { + setFontSize(fontSettings.size - step); + } +} + +export function resetFontSize() { + setFontSize(16); +} + +function loadFontSize(): number { + const storedFontSize = localStorage ? localStorage.getItem("fontSize") : "16"; + + if (storedFontSize === null) { + return 16; + } else { + return parseInt(storedFontSize); + } +} + +function setFontSize(size: number) { + fontSettings.size = size; + localStorage.setItem("fontSize", size.toString()); +} diff --git a/src/views/repo/Issues.svelte b/src/views/repo/Issues.svelte index 11ee98407..fcb0bacd9 100644 --- a/src/views/repo/Issues.svelte +++ b/src/views/repo/Issues.svelte @@ -142,7 +142,7 @@ rid: repo.rid, }); }}> - New + New