authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 01:25:11-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 01:25:11-07:00
log5e828bf3de1c86d85afdd91a02cc4ca1a38d4aef
treea6c888f5c944d7e3c1a3001b4d3bc0436b2a2fb5
parenta21c0d724684fe3e1775014fa0dad14e483c8315
signature Signed by PGP key B5690EEEBB952194

refactor(mobile): keep appearance calculations private (#10043)


2 files changed, 10 insertions(+), 17 deletions(-)

apps/mobile/src/lib/appearancePreferences.test.ts+6-13
......@@ -2,11 +2,7 @@ import { describe, expect, it } from "vite-plus/test";
22
33import {
44 DEFAULT_BASE_FONT_SIZE,
5 deriveCodeFontSize,
6 deriveTerminalFontSize,
75 normalizeBaseFontSize,
8 normalizeCodeFontSize,
9 normalizeCodeWordBreak,
106 resolveAppearance,
117 resolveAppearancePreferences,
128 resolveMarkdownFontSizes,
......@@ -48,10 +44,8 @@ describe("appearancePreferences", () => {
4844 expect(appearance.isCodeFontSizeCustom).toBe(false);
4945
5046 const scaled = resolveAppearance(resolveAppearancePreferences({ baseFontSize: 22 }));
51 expect(scaled.terminalFontSize).toBe(deriveTerminalFontSize(22));
52 expect(scaled.codeFontSize).toBe(deriveCodeFontSize(22));
53 expect(scaled.terminalFontSize).toBeGreaterThan(10);
54 expect(scaled.codeFontSize).toBeGreaterThan(11);
47 expect(scaled.terminalFontSize).toBe(14);
48 expect(scaled.codeFontSize).toBe(17);
5549 });
5650
5751 it("applies explicit overrides over derived values", () => {
......@@ -67,8 +61,8 @@ describe("appearancePreferences", () => {
6761 it("clamps base and code font sizes", () => {
6862 expect(normalizeBaseFontSize(4)).toBe(11);
6963 expect(normalizeBaseFontSize(30)).toBe(22);
70 expect(normalizeCodeFontSize(4)).toBe(8);
71 expect(normalizeCodeFontSize(30)).toBe(18);
64 expect(resolveAppearancePreferences({ codeFontSize: 4 }).codeFontSize).toBe(8);
65 expect(resolveAppearancePreferences({ codeFontSize: 30 }).codeFontSize).toBe(18);
7266 });
7367
7468 it("steps terminal font size within bounds", () => {
......@@ -92,9 +86,8 @@ describe("appearancePreferences", () => {
9286 });
9387 });
9488
95 it("defaults code word break to false", () => {
96 expect(normalizeCodeWordBreak(undefined)).toBe(false);
97 expect(normalizeCodeWordBreak(true)).toBe(true);
89 it("keeps explicit code word break enabled", () => {
90 expect(resolveAppearancePreferences({ codeWordBreak: true }).codeWordBreak).toBe(true);
9891 });
9992
10093 it("returns the authored text scale at the 16pt default", () => {
apps/mobile/src/lib/appearancePreferences.ts+4-4
......@@ -75,7 +75,7 @@ export function normalizeBaseFontSize(value: number | null | undefined): number
7575 return Math.min(MAX_BASE_FONT_SIZE, Math.max(MIN_BASE_FONT_SIZE, Math.round(value)));
7676}
7777
78export function normalizeCodeFontSize(value: number | null | undefined): number {
78function normalizeCodeFontSize(value: number | null | undefined): number {
7979 if (typeof value !== "number" || !Number.isFinite(value)) {
8080 return DEFAULT_CODE_FONT_SIZE;
8181 }
......@@ -83,18 +83,18 @@ export function normalizeCodeFontSize(value: number | null | undefined): number
8383 return Math.min(MAX_CODE_FONT_SIZE, Math.max(MIN_CODE_FONT_SIZE, Math.round(value)));
8484}
8585
86export function normalizeCodeWordBreak(value: boolean | null | undefined): boolean {
86function normalizeCodeWordBreak(value: boolean | null | undefined): boolean {
8787 return value === true;
8888}
8989
9090/** Terminal size derived from base: 10.5pt at base 16, snapped to 0.5pt steps. */
91export function deriveTerminalFontSize(baseFontSize: number): number {
91function deriveTerminalFontSize(baseFontSize: number): number {
9292 const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;
9393 return normalizeTerminalFontSize(Math.round(DEFAULT_TERMINAL_FONT_SIZE * scale * 2) / 2);
9494}
9595
9696/** Code/diff size derived from base: 12pt at base 16. */
97export function deriveCodeFontSize(baseFontSize: number): number {
97function deriveCodeFontSize(baseFontSize: number): number {
9898 const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;
9999 return normalizeCodeFontSize(Math.round(DEFAULT_CODE_FONT_SIZE * scale));
100100}