-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(web): add local typography settings #1337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Danielalnajjar
wants to merge
4
commits into
pingdotgg:main
Choose a base branch
from
Danielalnajjar:codex/typography-settings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+610
−73
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6f1d9af
feat(web): persist typography settings
Danielalnajjar d742792
feat(web): apply typography preferences across UI
Danielalnajjar 2c1f78c
feat(web): add typography settings controls
Danielalnajjar d388c21
feat(web): sync terminal typography live
Danielalnajjar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { | ||
| getTerminalFontSizePx, | ||
| getUiFontSizePx, | ||
| normalizeFontFamilyOverride, | ||
| } from "./appTypography"; | ||
|
|
||
| describe("normalizeFontFamilyOverride", () => { | ||
| it("treats blank and whitespace-only values as no override", () => { | ||
| expect(normalizeFontFamilyOverride("")).toBeNull(); | ||
| expect(normalizeFontFamilyOverride(" ")).toBeNull(); | ||
| expect(normalizeFontFamilyOverride(undefined)).toBeNull(); | ||
| }); | ||
|
|
||
| it("trims non-empty font family overrides", () => { | ||
| expect(normalizeFontFamilyOverride(" Inter, system-ui, sans-serif ")).toBe( | ||
| "Inter, system-ui, sans-serif", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("font size helpers", () => { | ||
| it("maps interface sizes to conservative root pixel values", () => { | ||
| expect(getUiFontSizePx("sm")).toBe(15); | ||
| expect(getUiFontSizePx("md")).toBe(16); | ||
| expect(getUiFontSizePx("lg")).toBe(17); | ||
| }); | ||
|
|
||
| it("maps terminal sizes to xterm pixel values", () => { | ||
| expect(getTerminalFontSizePx("sm")).toBe(11); | ||
| expect(getTerminalFontSizePx("md")).toBe(12); | ||
| expect(getTerminalFontSizePx("lg")).toBe(13); | ||
| expect(getTerminalFontSizePx("xl")).toBe(14); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { useLayoutEffect } from "react"; | ||
| import { | ||
| DEFAULT_TERMINAL_FONT_SIZE, | ||
| type TerminalFontSize, | ||
| type UiFontSize, | ||
| useAppSettings, | ||
| } from "./appSettings"; | ||
|
|
||
| export const UI_FONT_SIZE_OPTIONS: ReadonlyArray<{ value: UiFontSize; label: string }> = [ | ||
| { value: "sm", label: "Small" }, | ||
| { value: "md", label: "Default" }, | ||
| { value: "lg", label: "Large" }, | ||
| ]; | ||
|
|
||
| export const TERMINAL_FONT_SIZE_OPTIONS: ReadonlyArray<{ | ||
| value: TerminalFontSize; | ||
| label: string; | ||
| }> = [ | ||
| { value: "sm", label: "Small" }, | ||
| { value: "md", label: "Default" }, | ||
| { value: "lg", label: "Large" }, | ||
| { value: "xl", label: "Extra large" }, | ||
| ]; | ||
|
|
||
| const DEFAULT_MONO_FONT_FAMILY = | ||
| '"SF Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace'; | ||
|
|
||
| const UI_FONT_SIZE_PX: Record<UiFontSize, number> = { | ||
| sm: 15, | ||
| md: 16, | ||
| lg: 17, | ||
| }; | ||
|
|
||
| const TERMINAL_FONT_SIZE_PX: Record<TerminalFontSize, number> = { | ||
| sm: 11, | ||
| md: 12, | ||
| lg: 13, | ||
| xl: 14, | ||
| }; | ||
|
|
||
| export function normalizeFontFamilyOverride(value: string | null | undefined): string | null { | ||
| const normalized = value?.trim(); | ||
| return normalized && normalized.length > 0 ? normalized : null; | ||
| } | ||
|
|
||
| export function getUiFontSizePx(value: UiFontSize): number { | ||
| return UI_FONT_SIZE_PX[value]; | ||
| } | ||
|
|
||
| export function getTerminalFontSizePx(value: TerminalFontSize): number { | ||
| return TERMINAL_FONT_SIZE_PX[value]; | ||
| } | ||
|
|
||
| function setRootStyleProperty(name: string, value: string | null): void { | ||
| if (value === null) { | ||
| document.documentElement.style.removeProperty(name); | ||
| return; | ||
| } | ||
|
|
||
| document.documentElement.style.setProperty(name, value); | ||
| } | ||
|
|
||
| function parsePx(value: string, fallback: number): number { | ||
| const parsed = Number.parseFloat(value); | ||
| return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback; | ||
| } | ||
|
|
||
| export function useAppTypography(): void { | ||
| const { settings } = useAppSettings(); | ||
|
|
||
| useLayoutEffect(() => { | ||
| setRootStyleProperty("--app-ui-font-size", `${getUiFontSizePx(settings.uiFontSize)}px`); | ||
| setRootStyleProperty( | ||
| "--app-terminal-font-size", | ||
| `${getTerminalFontSizePx(settings.terminalFontSize)}px`, | ||
| ); | ||
| setRootStyleProperty( | ||
| "--app-ui-font-family", | ||
| normalizeFontFamilyOverride(settings.uiFontFamily), | ||
| ); | ||
| setRootStyleProperty( | ||
| "--app-mono-font-family", | ||
| normalizeFontFamilyOverride(settings.monoFontFamily), | ||
| ); | ||
| }, [ | ||
| settings.monoFontFamily, | ||
| settings.terminalFontSize, | ||
| settings.uiFontFamily, | ||
| settings.uiFontSize, | ||
| ]); | ||
| } | ||
|
|
||
| export function readTerminalTypographyFromApp(): { fontFamily: string; fontSize: number } { | ||
| const rootStyles = getComputedStyle(document.documentElement); | ||
| const fontFamily = | ||
| rootStyles.getPropertyValue("--app-mono-font-family").trim() || DEFAULT_MONO_FONT_FAMILY; | ||
| const fontSize = parsePx( | ||
| rootStyles.getPropertyValue("--app-terminal-font-size"), | ||
| getTerminalFontSizePx(DEFAULT_TERMINAL_FONT_SIZE), | ||
| ); | ||
|
|
||
| return { | ||
| fontFamily, | ||
| fontSize, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEFAULT_MONO_FONT_FAMILYduplicates the default mono stack defined inindex.css(--app-mono-font-family). This creates a drift risk where the terminal fallback and the CSS default could diverge over time. Consider reusing a single source of truth (e.g., export the default stack from one place, or fall back to a genericmonospacewhen the CSS variable is missing).