feat(shared): add getPretextFontString formatter
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
import {
|
||||||
|
describe,
|
||||||
|
expect,
|
||||||
|
it,
|
||||||
|
} from 'vitest';
|
||||||
|
import { getPretextFontString } from './getPretextFontString';
|
||||||
|
|
||||||
|
describe('getPretextFontString', () => {
|
||||||
|
it('formats weight, px size and quoted family for pretext/canvas', () => {
|
||||||
|
expect(getPretextFontString(400, 48, 'Inter')).toBe('400 48px "Inter"');
|
||||||
|
});
|
||||||
|
it('preserves fractional sizes and quotes multi-word family names', () => {
|
||||||
|
expect(getPretextFontString(700, 12.5, 'PT Serif')).toBe('700 12.5px "PT Serif"');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Formats a font config into the string `@chenglou/pretext` and the Canvas 2D
|
||||||
|
* `font` property both expect: `weight sizepx "family"`.
|
||||||
|
*
|
||||||
|
* ponytail: deliberate copy of widgets/ComparisonView/lib's version — ADR-0002
|
||||||
|
* keeps the shelved morph tool untouched, so we don't move its util. Three lines
|
||||||
|
* is cheaper to duplicate than to refactor frozen code.
|
||||||
|
*
|
||||||
|
* @param weight - Numeric font weight (e.g. 400).
|
||||||
|
* @param sizePx - Font size in pixels.
|
||||||
|
* @param fontName - The font family name.
|
||||||
|
* @returns A formatted font string: `weight sizepx "fontName"`.
|
||||||
|
*/
|
||||||
|
export function getPretextFontString(weight: number, sizePx: number, fontName: string): string {
|
||||||
|
return `${weight} ${sizePx}px "${fontName}"`;
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ export { clampNumber } from './clampNumber/clampNumber';
|
|||||||
export { cn } from './cn';
|
export { cn } from './cn';
|
||||||
export { debounce } from './debounce/debounce';
|
export { debounce } from './debounce/debounce';
|
||||||
export { getDecimalPlaces } from './getDecimalPlaces/getDecimalPlaces';
|
export { getDecimalPlaces } from './getDecimalPlaces/getDecimalPlaces';
|
||||||
|
export { getPretextFontString } from './getPretextFontString/getPretextFontString';
|
||||||
export { getSkeletonWidth } from './getSkeletonWidth/getSkeletonWidth';
|
export { getSkeletonWidth } from './getSkeletonWidth/getSkeletonWidth';
|
||||||
export { roundToStepPrecision } from './roundToStepPrecision/roundToStepPrecision';
|
export { roundToStepPrecision } from './roundToStepPrecision/roundToStepPrecision';
|
||||||
export { smoothScroll } from './smoothScroll/smoothScroll';
|
export { smoothScroll } from './smoothScroll/smoothScroll';
|
||||||
|
|||||||
Reference in New Issue
Block a user