refactor(ComparisonView): extract strut-height and settled-text from Line
Workflow / build (pull_request) Successful in 1m27s
Workflow / e2e (pull_request) Successful in 1m15s
Workflow / publish (pull_request) Has been skipped

Pull the baseline-strut height math into a documented computeStrutHeight
util (named constants for the empirical 0.34 / 1.1 factors, with a unit
test) and the per-side native text runs into a SettledText component.
Strut statics move to Tailwind classes with only the height as style:height;
drop the now-redundant style-string $derived bindings.
This commit is contained in:
Ilia Mashkov
2026-06-06 08:59:21 +03:00
parent 99e9a1fb2c
commit 11d5ba0e63
5 changed files with 123 additions and 33 deletions
@@ -0,0 +1,28 @@
import {
describe,
expect,
it,
} from 'vitest';
import { computeStrutHeight } from './computeStrutHeight';
describe('computeStrutHeight', () => {
it('uses the centering height when the line-height is generous', () => {
// centering = 40/2 + 16*0.34 = 25.44; floor = 16*1.1 = 17.6 → centering wins.
expect(computeStrutHeight(40, 16)).toBeCloseTo(25.44, 5);
});
it('falls back to the ascent floor when the line-height is tight', () => {
// centering = 16/2 + 16*0.34 = 13.44; floor = 16*1.1 = 17.6 → floor wins.
expect(computeStrutHeight(16, 16)).toBeCloseTo(17.6, 5);
});
it('treats the floor and centering height as equal at the crossover line-height', () => {
// centering == floor when lineHeight = 1.52 * fontSize → 24.32 for 16px.
expect(computeStrutHeight(24.32, 16)).toBeCloseTo(17.6, 5);
});
it('scales with font size', () => {
// centering = 60/2 + 32*0.34 = 40.88; floor = 32*1.1 = 35.2 → centering wins.
expect(computeStrutHeight(60, 32)).toBeCloseTo(40.88, 5);
});
});