mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-22 16:03:29 +10:00
chore: update postcss to version 8.5.14 and sort font weights in typography components
This commit is contained in:
@@ -171,6 +171,10 @@ export function getWebFontSource(family: string, weight: FontWeight = "400", ita
|
||||
return webFont.files[key] ?? (italic ? webFont.files[weight] : undefined) ?? webFont.preview;
|
||||
}
|
||||
|
||||
export function sortFontWeights<T extends string>(fontWeights: T[]): T[] {
|
||||
return [...fontWeights].sort((a, b) => Number(a) - Number(b));
|
||||
}
|
||||
|
||||
export function getFallbackWebFontFamilies(family: string) {
|
||||
if (isStandardPdfFontFamily(family)) return [];
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Template } from "@reactive-resume/schema/templates";
|
||||
import type { ComponentType } from "react";
|
||||
import type { SectionTitleResolver } from "./section-title";
|
||||
import { Document } from "@react-pdf/renderer";
|
||||
import { useMemo } from "react";
|
||||
import { RenderProvider } from "./context";
|
||||
import { registerFonts } from "./hooks/use-register-fonts";
|
||||
import { getTemplatePage } from "./templates";
|
||||
@@ -22,14 +23,12 @@ export type ResumeDocumentProps = {
|
||||
|
||||
export const ResumeDocument = ({ data, template, resolveSectionTitle }: ResumeDocumentProps) => {
|
||||
const TemplatePageComponent = getTemplatePage(template);
|
||||
const typography = registerFonts(data.metadata.typography);
|
||||
const typography = registerFonts(data.metadata.typography) as Typography;
|
||||
|
||||
// `registerFonts` widens `fontFamily` to `string | string[]` for CJK
|
||||
// fallback (#2986); the cast carries that wider runtime value through
|
||||
// `ResumeData` without changing the public schema.
|
||||
const resumeData =
|
||||
typography === data.metadata.typography
|
||||
? data
|
||||
: { ...data, metadata: { ...data.metadata, typography: typography as unknown as Typography } };
|
||||
const resumeData = useMemo(() => ({ ...data, metadata: { ...data.metadata, typography } }), [data, typography]);
|
||||
|
||||
return (
|
||||
<RenderProvider data={resumeData} resolveSectionTitle={resolveSectionTitle}>
|
||||
|
||||
@@ -85,4 +85,18 @@ describe("registerFonts", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("returns typography with font weights sorted ascending", async () => {
|
||||
vi.spyOn(Font, "register").mockImplementation(() => {});
|
||||
const { registerFonts } = await import("./use-register-fonts");
|
||||
|
||||
const pdfTypography = registerFonts({
|
||||
...typography,
|
||||
body: { ...typography.body, fontFamily: "Source Sans 3", fontWeights: ["800", "600", "400"] },
|
||||
heading: { ...typography.heading, fontFamily: "Source Sans 3", fontWeights: ["900", "500"] },
|
||||
});
|
||||
|
||||
expect(pdfTypography.body.fontWeights).toEqual(["400", "600", "800"]);
|
||||
expect(pdfTypography.heading.fontWeights).toEqual(["500", "900"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
getPdfCjkFallbackFontFamily,
|
||||
getWebFontSource,
|
||||
isStandardPdfFontFamily,
|
||||
sortFontWeights,
|
||||
} from "@reactive-resume/fonts";
|
||||
|
||||
type FontWeightRange = {
|
||||
@@ -53,15 +54,13 @@ const resolvePdfFontFamily = (family: string) => {
|
||||
const resolvePdfTypography = (typography: Typography): Typography => {
|
||||
const bodyFontFamily = resolvePdfFontFamily(typography.body.fontFamily);
|
||||
const headingFontFamily = resolvePdfFontFamily(typography.heading.fontFamily);
|
||||
|
||||
if (bodyFontFamily === typography.body.fontFamily && headingFontFamily === typography.heading.fontFamily) {
|
||||
return typography;
|
||||
}
|
||||
const bodyFontWeights = sortFontWeights(typography.body.fontWeights);
|
||||
const headingFontWeights = sortFontWeights(typography.heading.fontWeights);
|
||||
|
||||
return {
|
||||
...typography,
|
||||
body: { ...typography.body, fontFamily: bodyFontFamily },
|
||||
heading: { ...typography.heading, fontFamily: headingFontFamily },
|
||||
body: { ...typography.body, fontFamily: bodyFontFamily, fontWeights: bodyFontWeights },
|
||||
heading: { ...typography.heading, fontFamily: headingFontFamily, fontWeights: headingFontWeights },
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@typescript/native-preview": "7.0.0-dev.20260510.1",
|
||||
"postcss": "^8.5.14",
|
||||
"tailwindcss": "^4.3.0",
|
||||
"typescript": "^6.0.3"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user