mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-26 09:54:43 +10:00
fcc10c6b31
Export parseFiniteNumber and parsePxValue from icon-size.ts (already the canonical home of these helpers). Remove the three private copies in rich-text-spacing.ts and import the shared ones instead. Claude-Session: https://claude.ai/code/session_012Bnvt1MghwHj4qQRxuQUGa
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import type { Style } from "@react-pdf/types";
|
|
import type { StyleInput } from "./styles";
|
|
import { composeStyles } from "./styles";
|
|
|
|
export const parseFiniteNumber = (value: unknown): number | undefined =>
|
|
typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
|
|
export const parsePxValue = (value: unknown): number | undefined => {
|
|
if (typeof value !== "string" || !value.endsWith("px")) return undefined;
|
|
|
|
const parsedValue = Number.parseFloat(value);
|
|
return Number.isFinite(parsedValue) ? parsedValue : undefined;
|
|
};
|
|
|
|
export const parseStyleFontSize = (fontSize: Style["fontSize"] | undefined): number | undefined =>
|
|
parseFiniteNumber(fontSize) ?? parsePxValue(fontSize);
|
|
|
|
export const resolveStyleFontSize = (...styles: StyleInput[]): number | undefined => {
|
|
for (let index = styles.length - 1; index >= 0; index -= 1) {
|
|
const composedStyles = composeStyles(styles[index]);
|
|
|
|
for (let styleIndex = composedStyles.length - 1; styleIndex >= 0; styleIndex -= 1) {
|
|
const style = composedStyles[styleIndex];
|
|
if (style === undefined) continue;
|
|
|
|
const fontSize = parseStyleFontSize(style.fontSize);
|
|
if (fontSize !== undefined) return fontSize;
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
};
|
|
|
|
export const resolveIconSize = (options: {
|
|
size?: number | string | undefined;
|
|
styles?: StyleInput[];
|
|
}): number | string | undefined => {
|
|
if (options.size !== undefined) return options.size;
|
|
|
|
return resolveStyleFontSize(...(options.styles ?? []));
|
|
};
|