mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-12 05:55:02 +10:00
refactor(pdf): deduplicate parseFiniteNumber/parsePxValue/parseFontSize
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
This commit is contained in:
@@ -2,10 +2,10 @@ import type { Style } from "@react-pdf/types";
|
||||
import type { StyleInput } from "./styles";
|
||||
import { composeStyles } from "./styles";
|
||||
|
||||
const parseFiniteNumber = (value: unknown): number | undefined =>
|
||||
export const parseFiniteNumber = (value: unknown): number | undefined =>
|
||||
typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
||||
|
||||
const parsePxValue = (value: unknown): number | undefined => {
|
||||
export const parsePxValue = (value: unknown): number | undefined => {
|
||||
if (typeof value !== "string" || !value.endsWith("px")) return undefined;
|
||||
|
||||
const parsedValue = Number.parseFloat(value);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Style } from "@react-pdf/types";
|
||||
import type { StyleInput } from "./styles";
|
||||
import { NodeType } from "node-html-parser";
|
||||
import { parseFiniteNumber, parsePxValue, parseStyleFontSize } from "./icon-size";
|
||||
import { composeStyles } from "./styles";
|
||||
|
||||
type RichTextSpacingElement = {
|
||||
@@ -18,19 +19,6 @@ type RichTextProseSpacing = {
|
||||
listItem: Style;
|
||||
};
|
||||
|
||||
const parseFiniteNumber = (value: unknown): number | undefined =>
|
||||
typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
const parseFontSize = (fontSize: Style["fontSize"]): number | undefined =>
|
||||
parseFiniteNumber(fontSize) ?? parsePxValue(fontSize);
|
||||
|
||||
const parseLineHeight = (
|
||||
lineHeight: Style["lineHeight"],
|
||||
): { type: "multiplier" | "absolute"; value: number } | undefined => {
|
||||
@@ -129,7 +117,7 @@ export const resolveRichTextBodyLineHeight = (...styles: StyleInput[]): number |
|
||||
let bodyLineHeight: ReturnType<typeof parseLineHeight>;
|
||||
|
||||
for (const style of composeStyles(...styles)) {
|
||||
const fontSize = parseFontSize(style.fontSize);
|
||||
const fontSize = parseStyleFontSize(style.fontSize);
|
||||
if (fontSize !== undefined) bodyFontSize = fontSize;
|
||||
|
||||
const lineHeight = parseLineHeight(style.lineHeight);
|
||||
|
||||
Reference in New Issue
Block a user