TypeScript
refactor(mobile): keep appearance calculations private (#10043)
Julius Marminge5e828bf3de1c
diff --git a/apps/mobile/src/lib/appearancePreferences.test.ts b/apps/mobile/src/lib/appearancePreferences.test.tsindex af09637b4e9..417a66138d9 100644--- a/apps/mobile/src/lib/appearancePreferences.test.ts+++ b/apps/mobile/src/lib/appearancePreferences.test.ts@@ -2,11 +2,7 @@ import { describe, expect, it } from "vite-plus/test";import {DEFAULT_BASE_FONT_SIZE,- deriveCodeFontSize,- deriveTerminalFontSize,normalizeBaseFontSize,- normalizeCodeFontSize,- normalizeCodeWordBreak,resolveAppearance,resolveAppearancePreferences,resolveMarkdownFontSizes,@@ -48,10 +44,8 @@ describe("appearancePreferences", () => {expect(appearance.isCodeFontSizeCustom).toBe(false);const scaled = resolveAppearance(resolveAppearancePreferences({ baseFontSize: 22 }));- expect(scaled.terminalFontSize).toBe(deriveTerminalFontSize(22));- expect(scaled.codeFontSize).toBe(deriveCodeFontSize(22));- expect(scaled.terminalFontSize).toBeGreaterThan(10);- expect(scaled.codeFontSize).toBeGreaterThan(11);+ expect(scaled.terminalFontSize).toBe(14);+ expect(scaled.codeFontSize).toBe(17);});it("applies explicit overrides over derived values", () => {@@ -67,8 +61,8 @@ describe("appearancePreferences", () => {it("clamps base and code font sizes", () => {expect(normalizeBaseFontSize(4)).toBe(11);expect(normalizeBaseFontSize(30)).toBe(22);- expect(normalizeCodeFontSize(4)).toBe(8);- expect(normalizeCodeFontSize(30)).toBe(18);+ expect(resolveAppearancePreferences({ codeFontSize: 4 }).codeFontSize).toBe(8);+ expect(resolveAppearancePreferences({ codeFontSize: 30 }).codeFontSize).toBe(18);});it("steps terminal font size within bounds", () => {@@ -92,9 +86,8 @@ describe("appearancePreferences", () => {});});- it("defaults code word break to false", () => {- expect(normalizeCodeWordBreak(undefined)).toBe(false);- expect(normalizeCodeWordBreak(true)).toBe(true);+ it("keeps explicit code word break enabled", () => {+ expect(resolveAppearancePreferences({ codeWordBreak: true }).codeWordBreak).toBe(true);});it("returns the authored text scale at the 16pt default", () => {diff --git a/apps/mobile/src/lib/appearancePreferences.ts b/apps/mobile/src/lib/appearancePreferences.tsindex b81c5005654..2ce6a8b5a36 100644--- a/apps/mobile/src/lib/appearancePreferences.ts+++ b/apps/mobile/src/lib/appearancePreferences.ts@@ -75,7 +75,7 @@ export function normalizeBaseFontSize(value: number | null | undefined): numberreturn Math.min(MAX_BASE_FONT_SIZE, Math.max(MIN_BASE_FONT_SIZE, Math.round(value)));}-export function normalizeCodeFontSize(value: number | null | undefined): number {+function normalizeCodeFontSize(value: number | null | undefined): number {if (typeof value !== "number" || !Number.isFinite(value)) {return DEFAULT_CODE_FONT_SIZE;}@@ -83,18 +83,18 @@ export function normalizeCodeFontSize(value: number | null | undefined): numberreturn Math.min(MAX_CODE_FONT_SIZE, Math.max(MIN_CODE_FONT_SIZE, Math.round(value)));}-export function normalizeCodeWordBreak(value: boolean | null | undefined): boolean {+function normalizeCodeWordBreak(value: boolean | null | undefined): boolean {return value === true;}/** Terminal size derived from base: 10.5pt at base 16, snapped to 0.5pt steps. */-export function deriveTerminalFontSize(baseFontSize: number): number {+function deriveTerminalFontSize(baseFontSize: number): number {const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;return normalizeTerminalFontSize(Math.round(DEFAULT_TERMINAL_FONT_SIZE * scale * 2) / 2);}/** Code/diff size derived from base: 12pt at base 16. */-export function deriveCodeFontSize(baseFontSize: number): number {+function deriveCodeFontSize(baseFontSize: number): number {const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;return normalizeCodeFontSize(Math.round(DEFAULT_CODE_FONT_SIZE * scale));}