mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-24 07:12:18 +10:00
feat: add semantic CSS stylesheets (#3274)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor Agent
parent
4ac19f81b3
commit
d2ffbf9618
@@ -1,23 +1,35 @@
|
||||
import type { ResumeData } from "@reactive-resume/schema/resume/data";
|
||||
import type { Template } from "@reactive-resume/schema/templates";
|
||||
import type { SectionTitleResolver } from "./section-title";
|
||||
import type { ResolvedResumeRuntime, ResumePdfRenderResult } from "./semantic";
|
||||
import { createElement } from "react";
|
||||
import { parseResumeData } from "@reactive-resume/schema/resume/data";
|
||||
import { renderToBuffer } from "#react-pdf-renderer";
|
||||
import { ResumeDocument } from "./document";
|
||||
import { hasSemanticErrors, inspectResumePdf } from "./semantic";
|
||||
|
||||
type CreateResumePdfFileOptions = {
|
||||
export type {
|
||||
PdfPreflightFailure,
|
||||
PdfPreflightPageLimits,
|
||||
PdfPreflightResult,
|
||||
RenderPreflightPdfResult,
|
||||
StylesheetPreflightInput,
|
||||
StylesheetPreflightRunner,
|
||||
} from "./semantic/preflight-core";
|
||||
export { renderPreflightPdf } from "./semantic/preflight-core";
|
||||
|
||||
export type CreateResumePdfFileOptions = {
|
||||
data: ResumeData;
|
||||
filename: string;
|
||||
template?: Template | undefined;
|
||||
resolveSectionTitle?: SectionTitleResolver | undefined;
|
||||
};
|
||||
|
||||
export const createResumePdfFile = async ({
|
||||
data,
|
||||
filename,
|
||||
template,
|
||||
resolveSectionTitle,
|
||||
}: CreateResumePdfFileOptions) => {
|
||||
export type CreateResumePdfFileResultOptions = CreateResumePdfFileOptions & {
|
||||
inspection?: ResolvedResumeRuntime | undefined;
|
||||
};
|
||||
|
||||
const renderResumePdfFile = async ({ data, filename, template, resolveSectionTitle }: CreateResumePdfFileOptions) => {
|
||||
const document = createElement(ResumeDocument, {
|
||||
data,
|
||||
template: template ?? data.metadata.template,
|
||||
@@ -29,3 +41,28 @@ export const createResumePdfFile = async ({
|
||||
|
||||
return new File([bytes], filename, { type: "application/pdf" });
|
||||
};
|
||||
|
||||
export const createResumePdfFileResult = async ({
|
||||
inspection,
|
||||
...options
|
||||
}: CreateResumePdfFileResultOptions): Promise<ResumePdfRenderResult<File>> => {
|
||||
const normalizedOptions = { ...options, data: parseResumeData(options.data) };
|
||||
const resolvedInspection = inspection ?? inspectResumePdf(normalizedOptions);
|
||||
if (hasSemanticErrors(resolvedInspection)) {
|
||||
return { ok: false, diagnostics: resolvedInspection.diagnostics };
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
value: await renderResumePdfFile(normalizedOptions),
|
||||
diagnostics: resolvedInspection.diagnostics,
|
||||
};
|
||||
};
|
||||
|
||||
export const createResumePdfFile = async (options: CreateResumePdfFileOptions): Promise<File> => {
|
||||
const result = await createResumePdfFileResult(options);
|
||||
if (!result.ok) {
|
||||
throw new Error("The semantic stylesheet could not be rendered.", { cause: result.diagnostics });
|
||||
}
|
||||
return result.value;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user