11d5ba0e63
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.
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
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);
|
|
});
|
|
});
|