mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-24 15:22:20 +10:00
refactor(stylesheet): move Semantic CSS to the browser (#3329)
This commit is contained in:
@@ -1,22 +1,10 @@
|
||||
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";
|
||||
|
||||
export type {
|
||||
PdfPreflightFailure,
|
||||
PdfPreflightPageLimits,
|
||||
PdfPreflightResult,
|
||||
RenderPreflightPdfResult,
|
||||
StylesheetPreflightInput,
|
||||
StylesheetPreflightRunner,
|
||||
} from "./semantic/preflight-core";
|
||||
export { renderPreflightPdf } from "./semantic/preflight-core";
|
||||
|
||||
export type CreateResumePdfFileOptions = {
|
||||
data: ResumeData;
|
||||
@@ -25,11 +13,13 @@ export type CreateResumePdfFileOptions = {
|
||||
resolveSectionTitle?: SectionTitleResolver | undefined;
|
||||
};
|
||||
|
||||
export type CreateResumePdfFileResultOptions = CreateResumePdfFileOptions & {
|
||||
inspection?: ResolvedResumeRuntime | undefined;
|
||||
};
|
||||
|
||||
const renderResumePdfFile = async ({ data, filename, template, resolveSectionTitle }: CreateResumePdfFileOptions) => {
|
||||
export const createResumePdfFile = async ({
|
||||
data: input,
|
||||
filename,
|
||||
template,
|
||||
resolveSectionTitle,
|
||||
}: CreateResumePdfFileOptions): Promise<File> => {
|
||||
const data = parseResumeData(input);
|
||||
const document = createElement(ResumeDocument, {
|
||||
data,
|
||||
template: template ?? data.metadata.template,
|
||||
@@ -41,28 +31,3 @@ const renderResumePdfFile = async ({ data, filename, template, resolveSectionTit
|
||||
|
||||
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