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";...@@ -2,11 +2,7 @@ import { describe, expect, it } from "vite-plus/test";
22
3import {3import {
4 DEFAULT_BASE_FONT_SIZE,4 DEFAULT_BASE_FONT_SIZE,
5 deriveCodeFontSize,
6 deriveTerminalFontSize,
7 normalizeBaseFontSize,5 normalizeBaseFontSize,
8 normalizeCodeFontSize,
9 normalizeCodeWordBreak,
10 resolveAppearance,6 resolveAppearance,
11 resolveAppearancePreferences,7 resolveAppearancePreferences,
12 resolveMarkdownFontSizes,8 resolveMarkdownFontSizes,
...@@ -48,10 +44,8 @@ describe("appearancePreferences", () => {...@@ -48,10 +44,8 @@ describe("appearancePreferences", () => {
48 expect(appearance.isCodeFontSizeCustom).toBe(false);44 expect(appearance.isCodeFontSizeCustom).toBe(false);
4945
50 const scaled = resolveAppearance(resolveAppearancePreferences({ baseFontSize: 22 }));46 const scaled = resolveAppearance(resolveAppearancePreferences({ baseFontSize: 22 }));
51 expect(scaled.terminalFontSize).toBe(deriveTerminalFontSize(22));47 expect(scaled.terminalFontSize).toBe(14);
52 expect(scaled.codeFontSize).toBe(deriveCodeFontSize(22));48 expect(scaled.codeFontSize).toBe(17);
53 expect(scaled.terminalFontSize).toBeGreaterThan(10);
54 expect(scaled.codeFontSize).toBeGreaterThan(11);
55 });49 });
5650
57 it("applies explicit overrides over derived values", () => {51 it("applies explicit overrides over derived values", () => {
...@@ -67,8 +61,8 @@ describe("appearancePreferences", () => {...@@ -67,8 +61,8 @@ describe("appearancePreferences", () => {
67 it("clamps base and code font sizes", () => {61 it("clamps base and code font sizes", () => {
68 expect(normalizeBaseFontSize(4)).toBe(11);62 expect(normalizeBaseFontSize(4)).toBe(11);
69 expect(normalizeBaseFontSize(30)).toBe(22);63 expect(normalizeBaseFontSize(30)).toBe(22);
70 expect(normalizeCodeFontSize(4)).toBe(8);64 expect(resolveAppearancePreferences({ codeFontSize: 4 }).codeFontSize).toBe(8);
71 expect(normalizeCodeFontSize(30)).toBe(18);65 expect(resolveAppearancePreferences({ codeFontSize: 30 }).codeFontSize).toBe(18);
72 });66 });
7367
74 it("steps terminal font size within bounds", () => {68 it("steps terminal font size within bounds", () => {
...@@ -92,9 +86,8 @@ describe("appearancePreferences", () => {...@@ -92,9 +86,8 @@ describe("appearancePreferences", () => {
92 });86 });
93 });87 });
9488
95 it("defaults code word break to false", () => {89 it("keeps explicit code word break enabled", () => {
96 expect(normalizeCodeWordBreak(undefined)).toBe(false);90 expect(resolveAppearancePreferences({ codeWordBreak: true }).codeWordBreak).toBe(true);
97 expect(normalizeCodeWordBreak(true)).toBe(true);
98 });91 });
9992
100 it("returns the authored text scale at the 16pt default", () => {93 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...@@ -75,7 +75,7 @@ export function normalizeBaseFontSize(value: number | null | undefined): number
75 return Math.min(MAX_BASE_FONT_SIZE, Math.max(MIN_BASE_FONT_SIZE, Math.round(value)));75 return Math.min(MAX_BASE_FONT_SIZE, Math.max(MIN_BASE_FONT_SIZE, Math.round(value)));
76}76}
7777
78export function normalizeCodeFontSize(value: number | null | undefined): number {78function normalizeCodeFontSize(value: number | null | undefined): number {
79 if (typeof value !== "number" || !Number.isFinite(value)) {79 if (typeof value !== "number" || !Number.isFinite(value)) {
80 return DEFAULT_CODE_FONT_SIZE;80 return DEFAULT_CODE_FONT_SIZE;
81 }81 }
...@@ -83,18 +83,18 @@ export function normalizeCodeFontSize(value: number | null | undefined): number...@@ -83,18 +83,18 @@ export function normalizeCodeFontSize(value: number | null | undefined): number
83 return Math.min(MAX_CODE_FONT_SIZE, Math.max(MIN_CODE_FONT_SIZE, Math.round(value)));83 return Math.min(MAX_CODE_FONT_SIZE, Math.max(MIN_CODE_FONT_SIZE, Math.round(value)));
84}84}
8585
86export function normalizeCodeWordBreak(value: boolean | null | undefined): boolean {86function normalizeCodeWordBreak(value: boolean | null | undefined): boolean {
87 return value === true;87 return value === true;
88}88}
8989
90/** Terminal size derived from base: 10.5pt at base 16, snapped to 0.5pt steps. */90/** 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 {
92 const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;92 const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;
93 return normalizeTerminalFontSize(Math.round(DEFAULT_TERMINAL_FONT_SIZE * scale * 2) / 2);93 return normalizeTerminalFontSize(Math.round(DEFAULT_TERMINAL_FONT_SIZE * scale * 2) / 2);
94}94}
9595
96/** Code/diff size derived from base: 12pt at base 16. */96/** Code/diff size derived from base: 12pt at base 16. */
97export function deriveCodeFontSize(baseFontSize: number): number {97function deriveCodeFontSize(baseFontSize: number): number {
98 const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;98 const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;
99 return normalizeCodeFontSize(Math.round(DEFAULT_CODE_FONT_SIZE * scale));99 return normalizeCodeFontSize(Math.round(DEFAULT_CODE_FONT_SIZE * scale));
100}100}