Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat(resume-export): add customizable export settings (font, size, margins, spacing) with token-based style builders

Khuram Niazee35798d1d5b
diff --git a/__tests__/ExportSettingsPanel.spec.tsx b/__tests__/ExportSettingsPanel.spec.tsx
index 6b7be6f..4cd99c2 100644
--- a/__tests__/ExportSettingsPanel.spec.tsx
+++ b/__tests__/ExportSettingsPanel.spec.tsx
@@ -1,36 +1,331 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
-import { describe, expect, it, vi } from "vitest";
+import { beforeAll, describe, expect, it, vi } from "vitest";
import { ExportSettingsPanel } from "@/components/profile/export-pdf-dialog/ExportSettingsPanel";
-import type { ResumeExportSettings } from "@/models/resumeExport.model";
+import { defaultResumeExportSettings } from "@/models/resumeExport.model";
-const simple: ResumeExportSettings = { template: "simple" };
+// The established shim for driving Radix Select in jsdom — see TaskForm.spec.
+beforeAll(() => {
+ window.HTMLElement.prototype.scrollIntoView = vi.fn();
+ window.HTMLElement.prototype.hasPointerCapture = vi.fn();
+});
+
+const renderPanel = (patch: Partial<typeof defaultResumeExportSettings> = {}) => {
+ const user = userEvent.setup();
+ const onChange = vi.fn();
+ render(
+ <ExportSettingsPanel
+ settings={{ ...defaultResumeExportSettings, ...patch }}
+ onChange={onChange}
+ />,
+ );
+ return { onChange, user };
+};
+
+describe("ExportSettingsPanel — structure", () => {
+ it("pins Template above the two disclosure groups", () => {
+ renderPanel();
+ expect(screen.getByRole("combobox", { name: "Template" })).toBeInTheDocument();
+ expect(
+ screen.getByRole("button", { name: /Typography/ }),
+ ).toHaveAttribute("aria-expanded", "true");
+ expect(screen.getByRole("button", { name: /Layout/ })).toHaveAttribute(
+ "aria-expanded",
+ "true",
+ );
+ });
-describe("ExportSettingsPanel", () => {
- it("renders a Template section with both layout options", () => {
- render(<ExportSettingsPanel settings={simple} onChange={vi.fn()} />);
+ it("renders a select for each named setting and a stepper for each number", () => {
+ renderPanel();
+ expect(screen.getByRole("combobox", { name: "Template" })).toBeInTheDocument();
+ expect(screen.getByRole("combobox", { name: "Font" })).toBeInTheDocument();
+ for (const label of [
+ "Font size",
+ "Line height",
+ "Margin top/bottom",
+ "Margin left/right",
+ "Section spacing",
+ "Entry spacing",
+ ]) {
+ expect(screen.getByRole("spinbutton", { name: label })).toBeInTheDocument();
+ }
+ });
- expect(screen.getByText("Template")).toBeInTheDocument();
- expect(screen.getByRole("radio", { name: "Simple" })).toBeInTheDocument();
+ it("shows the current value in every control", () => {
+ renderPanel({ template: "professional", font: "times", fontSize: 12.5 });
+ expect(screen.getByRole("combobox", { name: "Template" })).toHaveTextContent(
+ "Professional",
+ );
+ expect(screen.getByRole("combobox", { name: "Font" })).toHaveTextContent(
+ "Times",
+ );
+ expect(screen.getByRole("spinbutton", { name: "Font size" })).toHaveValue(
+ 12.5,
+ );
expect(
- screen.getByRole("radio", { name: "Professional" }),
+ screen.getByRole("spinbutton", { name: "Margin left/right" }),
+ ).toHaveValue(48);
+ });
+
+ it("gives each stepper its field's own bounds and step", () => {
+ renderPanel();
+ const size = screen.getByRole("spinbutton", { name: "Font size" });
+ expect(size).toHaveAttribute("min", "8");
+ expect(size).toHaveAttribute("max", "16");
+ expect(size).toHaveAttribute("step", "0.5");
+ const line = screen.getByRole("spinbutton", { name: "Line height" });
+ expect(line).toHaveAttribute("step", "0.05");
+ });
+});
+
+describe("ExportSettingsPanel — disclosure", () => {
+ it("hides a collapsed group's rows behind a value summary", async () => {
+ const { user } = renderPanel();
+
+ await user.click(screen.getByRole("button", { name: /Layout/ }));
+
+ expect(
+ screen.queryByRole("spinbutton", { name: "Section spacing" }),
+ ).not.toBeInTheDocument();
+ expect(
+ screen.getByText("40 × 48 pt margins • 6/8 pt spacing"),
).toBeInTheDocument();
});
- it("marks the current template as checked", () => {
- render(<ExportSettingsPanel settings={simple} onChange={vi.fn()} />);
+ it("summarises Typography with all three of its values", async () => {
+ const { user } = renderPanel({ font: "courier", fontSize: 9.5 });
+
+ await user.click(screen.getByRole("button", { name: /Typography/ }));
+
+ expect(screen.getByText("Courier • 9.5 pt • 1.4 line")).toBeInTheDocument();
+ });
+
+ it("does not show a summary while the group is open", () => {
+ renderPanel();
+ expect(
+ screen.queryByText(/40 × 48 pt margins/),
+ ).not.toBeInTheDocument();
+ });
+});
+
+describe("ExportSettingsPanel — stepper buttons", () => {
+ it("steps a value up by its own step, emitting the whole object", async () => {
+ const { onChange, user } = renderPanel();
+
+ await user.click(screen.getByRole("button", { name: "Increase Font size" }));
+
+ expect(onChange).toHaveBeenCalledWith({
+ ...defaultResumeExportSettings,
+ fontSize: 11.5,
+ });
+ });
+
+ it("steps a value down by its own step", async () => {
+ const { onChange, user } = renderPanel();
+
+ await user.click(
+ screen.getByRole("button", { name: "Decrease Margin left/right" }),
+ );
+
+ expect(onChange).toHaveBeenCalledWith({
+ ...defaultResumeExportSettings,
+ marginHorizontal: 46,
+ });
+ });
+
+ // 1.4 + 0.05 is 1.4500000000000002 in IEEE 754, which would land in the
+ // style sheet and in the JSON.stringify preview cache key.
+ it("rounds the step away from float drift", async () => {
+ const { onChange, user } = renderPanel();
+
+ await user.click(
+ screen.getByRole("button", { name: "Increase Line height" }),
+ );
+
+ expect(onChange).toHaveBeenCalledWith({
+ ...defaultResumeExportSettings,
+ lineHeight: 1.45,
+ });
+ });
+
+ it("clamps rather than stepping past a bound", async () => {
+ const { onChange, user } = renderPanel({ fontSize: 15.8 });
+
+ await user.click(screen.getByRole("button", { name: "Increase Font size" }));
+
+ expect(onChange).toHaveBeenCalledWith({
+ ...defaultResumeExportSettings,
+ fontSize: 16,
+ });
+ });
+
+ it("disables the button that would leave the range", () => {
+ renderPanel({ fontSize: 16, sectionSpacing: 0 });
+ expect(
+ screen.getByRole("button", { name: "Increase Font size" }),
+ ).toBeDisabled();
+ expect(
+ screen.getByRole("button", { name: "Decrease Font size" }),
+ ).toBeEnabled();
+ expect(
+ screen.getByRole("button", { name: "Decrease Section spacing" }),
+ ).toBeDisabled();
+ });
+
+ it("preserves key order so the preview cache key stays stable", async () => {
+ const { onChange, user } = renderPanel();
+
+ await user.click(
+ screen.getByRole("button", { name: "Increase Entry spacing" }),
+ );
+
+ expect(Object.keys(onChange.mock.calls[0][0])).toEqual(
+ Object.keys(defaultResumeExportSettings),
+ );
+ });
+});
+
+describe("ExportSettingsPanel — typing", () => {
+ it("commits a typed value that is in range", async () => {
+ const { onChange, user } = renderPanel();
+ const input = screen.getByRole("spinbutton", { name: "Section spacing" });
+
+ await user.clear(input);
+ await user.type(input, "18");
+
+ expect(onChange).toHaveBeenLastCalledWith({
+ ...defaultResumeExportSettings,
+ sectionSpacing: 18,
+ });
+ });
+
+ it("commits a value off the step grid without snapping it", async () => {
+ const { onChange, user } = renderPanel();
+ const input = screen.getByRole("spinbutton", { name: "Font size" });
+
+ await user.clear(input);
+ await user.type(input, "11.3");
+
+ expect(onChange).toHaveBeenLastCalledWith({
+ ...defaultResumeExportSettings,
+ fontSize: 11.3,
+ });
+ });
+
+ // Every prefix of "99" is out of range for an 18-90 field, so nothing
+ // commits on the way through. "400" would commit 40 as it was typed.
+ it("does not commit a value outside the range, and reverts on blur", async () => {
+ const { onChange, user } = renderPanel();
+ const input = screen.getByRole("spinbutton", { name: "Margin left/right" });
+
+ await user.clear(input);
+ await user.type(input, "99");
+ expect(onChange).not.toHaveBeenCalled();
+
+ await user.tab();
+ expect(input).toHaveValue(48);
+ });
+
+ it("does not commit an emptied field", async () => {
+ const { onChange, user } = renderPanel();
+
+ await user.clear(screen.getByRole("spinbutton", { name: "Entry spacing" }));
+
+ expect(onChange).not.toHaveBeenCalled();
+ });
+});
+
+describe("ExportSettingsPanel — selects", () => {
+ it("emits the whole object when the template changes", async () => {
+ const { onChange, user } = renderPanel();
+
+ await user.click(screen.getByRole("combobox", { name: "Template" }));
+ await user.click(screen.getByRole("option", { name: "Professional" }));
+
+ expect(onChange).toHaveBeenCalledWith({
+ ...defaultResumeExportSettings,
+ template: "professional",
+ });
+ });
+
+ it("emits the whole object when the font changes", async () => {
+ const { onChange, user } = renderPanel();
+
+ await user.click(screen.getByRole("combobox", { name: "Font" }));
+ await user.click(screen.getByRole("option", { name: "Courier" }));
+
+ expect(onChange).toHaveBeenCalledWith({
+ ...defaultResumeExportSettings,
+ font: "courier",
+ });
+ });
+});
+
+describe("ExportSettingsPanel — reset", () => {
+ it("renders no reset control when no handler is given", () => {
+ renderPanel();
+ expect(
+ screen.queryByRole("button", { name: "Reset to defaults" }),
+ ).not.toBeInTheDocument();
+ });
+
+ it("disables reset while the settings are the defaults", () => {
+ const onReset = vi.fn();
+ render(
+ <ExportSettingsPanel
+ settings={defaultResumeExportSettings}
+ onChange={vi.fn()}
+ onReset={onReset}
+ isDefault
+ />,
+ );
+ expect(
+ screen.getByRole("button", { name: "Reset to defaults" }),
+ ).toBeDisabled();
+ });
+
+ it("calls the handler once the settings have moved", async () => {
+ const user = userEvent.setup();
+ const onReset = vi.fn();
+ render(
+ <ExportSettingsPanel
+ settings={{ ...defaultResumeExportSettings, fontSize: 13 }}
+ onChange={vi.fn()}
+ onReset={onReset}
+ isDefault={false}
+ />,
+ );
+
+ await user.click(screen.getByRole("button", { name: "Reset to defaults" }));
- expect(screen.getByRole("radio", { name: "Simple" })).toBeChecked();
- expect(screen.getByRole("radio", { name: "Professional" })).not.toBeChecked();
+ expect(onReset).toHaveBeenCalledTimes(1);
});
- it("emits a whole settings object, not a bare layout", async () => {
- const onChange = vi.fn();
- render(<ExportSettingsPanel settings={simple} onChange={onChange} />);
+ // The stepper's draft state must follow a value it did not itself change.
+ it("shows the reset value in the stepper after the parent re-renders", () => {
+ const { rerender } = render(
+ <ExportSettingsPanel
+ settings={{ ...defaultResumeExportSettings, fontSize: 13 }}
+ onChange={vi.fn()}
+ onReset={vi.fn()}
+ isDefault={false}
+ />,
+ );
+ expect(screen.getByRole("spinbutton", { name: "Font size" })).toHaveValue(
+ 13,
+ );
- await userEvent.click(screen.getByRole("radio", { name: "Professional" }));
+ rerender(
+ <ExportSettingsPanel
+ settings={defaultResumeExportSettings}
+ onChange={vi.fn()}
+ onReset={vi.fn()}
+ isDefault
+ />,
+ );
- expect(onChange).toHaveBeenCalledTimes(1);
- expect(onChange).toHaveBeenCalledWith({ template: "professional" });
+ expect(screen.getByRole("spinbutton", { name: "Font size" })).toHaveValue(
+ 11,
+ );
});
});
diff --git a/__tests__/resumeExportSettings.spec.ts b/__tests__/resumeExportSettings.spec.ts
new file mode 100644
index 0000000..a6d151b
--- /dev/null
+++ b/__tests__/resumeExportSettings.spec.ts
@@ -0,0 +1,142 @@
+import { describe, it, expect } from "vitest";
+import {
+ clampNumericField,
+ defaultResumeExportSettings,
+ formatSettingValue,
+ RESUME_FONT_LABELS,
+ RESUME_NUMERIC_SETTINGS,
+ type ResumeNumericSetting,
+} from "@/models/resumeExport.model";
+
+describe("defaultResumeExportSettings", () => {
+ // Copied from simpleStyles, so buildSimpleStyles at the defaults is
+ // identity. Professional's four deltas are documented in the plan.
+ it("is Simple's own literals", () => {
+ expect(defaultResumeExportSettings).toEqual({
+ template: "simple",
+ font: "helvetica",
+ fontSize: 11,
+ lineHeight: 1.4,
+ marginVertical: 40,
+ marginHorizontal: 48,
+ sectionSpacing: 6,
+ entrySpacing: 8,
+ });
+ });
+
+ it("orders its keys template-first so the cache key is stable", () => {
+ expect(Object.keys(defaultResumeExportSettings)).toEqual([
+ "template",
+ "font",
+ "fontSize",
+ "lineHeight",
+ "marginVertical",
+ "marginHorizontal",
+ "sectionSpacing",
+ "entrySpacing",
+ ]);
+ });
+
+ it("puts every default inside its own field's range", () => {
+ for (const [field, spec] of Object.entries(RESUME_NUMERIC_SETTINGS)) {
+ const value = defaultResumeExportSettings[field as ResumeNumericSetting];
+ expect(value).toBeGreaterThanOrEqual(spec.min);
+ expect(value).toBeLessThanOrEqual(spec.max);
+ }
+ });
+});
+
+describe("RESUME_FONT_LABELS", () => {
+ it("labels the three standard-14 families", () => {
+ expect(RESUME_FONT_LABELS).toEqual({
+ helvetica: "Helvetica",
+ times: "Times",
+ courier: "Courier",
+ });
+ });
+});
+
+describe("RESUME_NUMERIC_SETTINGS", () => {
+ it("describes all six numeric settings", () => {
+ expect(Object.keys(RESUME_NUMERIC_SETTINGS)).toEqual([
+ "fontSize",
+ "lineHeight",
+ "marginVertical",
+ "marginHorizontal",
+ "sectionSpacing",
+ "entrySpacing",
+ ]);
+ });
+
+ it("gives font size half-point steps in points", () => {
+ expect(RESUME_NUMERIC_SETTINGS.fontSize).toEqual({
+ label: "Font size",
+ min: 8,
+ max: 16,
+ step: 0.5,
+ decimals: 1,
+ unit: "pt",
+ });
+ });
+
+ it("gives line height a unitless two-decimal scale", () => {
+ expect(RESUME_NUMERIC_SETTINGS.lineHeight.unit).toBe("");
+ expect(RESUME_NUMERIC_SETTINGS.lineHeight.step).toBe(0.05);
+ expect(RESUME_NUMERIC_SETTINGS.lineHeight.decimals).toBe(2);
+ });
+
+ it("gives every field a step it can reach from its own default", () => {
+ for (const [field, spec] of Object.entries(RESUME_NUMERIC_SETTINGS)) {
+ expect(spec.step).toBeGreaterThan(0);
+ expect(spec.min).toBeLessThan(spec.max);
+ expect(spec.label.length).toBeGreaterThan(0);
+ expect(defaultResumeExportSettings[field as ResumeNumericSetting]).toBeTypeOf(
+ "number",
+ );
+ }
+ });
+});
+
+describe("clampNumericField", () => {
+ it("returns a value already in range unchanged", () => {
+ expect(clampNumericField("fontSize", 12.5)).toBe(12.5);
+ expect(clampNumericField("marginVertical", 40)).toBe(40);
+ });
+
+ it("clamps to the field's own bounds", () => {
+ expect(clampNumericField("fontSize", 400)).toBe(16);
+ expect(clampNumericField("fontSize", -3)).toBe(8);
+ expect(clampNumericField("marginHorizontal", 1000)).toBe(90);
+ expect(clampNumericField("sectionSpacing", -1)).toBe(0);
+ });
+
+ // 1.4 + 0.05 is 1.4500000000000002, which would poison both the style
+ // sheet and the JSON.stringify preview cache key.
+ it("rounds away IEEE-754 drift at the field's precision", () => {
+ expect(clampNumericField("lineHeight", 1.4 + 0.05)).toBe(1.45);
+ expect(clampNumericField("fontSize", 11 + 0.5)).toBe(11.5);
+ expect(clampNumericField("marginVertical", 40.4)).toBe(40);
+ });
+
+ it("does not snap a typed value onto the step grid", () => {
+ expect(clampNumericField("fontSize", 11.3)).toBe(11.3);
+ expect(clampNumericField("marginVertical", 41)).toBe(41);
+ });
+
+ it("falls back to the field's default for anything that is not a number", () => {
+ for (const value of [null, undefined, "40", NaN, Infinity, {}, []]) {
+ expect(clampNumericField("marginVertical", value)).toBe(40);
+ }
+ });
+});
+
+describe("formatSettingValue", () => {
+ it("renders a bare number, with a unit where the field has one", () => {
+ expect(formatSettingValue("fontSize", 11)).toBe("11 pt");
+ expect(formatSettingValue("fontSize", 11.5)).toBe("11.5 pt");
+ expect(formatSettingValue("lineHeight", 1.4)).toBe("1.4");
+ expect(formatSettingValue("lineHeight", 1.45)).toBe("1.45");
+ expect(formatSettingValue("marginHorizontal", 48)).toBe("48 pt");
+ expect(formatSettingValue("entrySpacing", 8)).toBe("8 pt");
+ });
+});
diff --git a/__tests__/resumeExportTokens.spec.ts b/__tests__/resumeExportTokens.spec.ts
new file mode 100644
index 0000000..aeeae9b
--- /dev/null
+++ b/__tests__/resumeExportTokens.spec.ts
@@ -0,0 +1,118 @@
+import { describe, it, expect } from "vitest";
+import { defaultResumeExportSettings } from "@/models/resumeExport.model";
+import {
+ BASE_FONT_SIZE,
+ FONT_QUARTETS,
+ styleTokens,
+} from "@/components/profile/resume-pdf/styles/tokens";
+
+const tokens = (patch: Partial<typeof defaultResumeExportSettings> = {}) =>
+ styleTokens({ ...defaultResumeExportSettings, ...patch });
+
+describe("FONT_QUARTETS", () => {
+ it("names all four faces of each standard-14 family", () => {
+ expect(FONT_QUARTETS.helvetica).toEqual({
+ regular: "Helvetica",
+ bold: "Helvetica-Bold",
+ italic: "Helvetica-Oblique",
+ boldItalic: "Helvetica-BoldOblique",
+ });
+ expect(FONT_QUARTETS.courier).toEqual({
+ regular: "Courier",
+ bold: "Courier-Bold",
+ italic: "Courier-Oblique",
+ boldItalic: "Courier-BoldOblique",
+ });
+ });
+
+ // The regular Times face is Times-Roman; "Times" is not a registered name.
+ it("uses Times-Roman for the regular Times face", () => {
+ expect(FONT_QUARTETS.times.regular).toBe("Times-Roman");
+ expect(FONT_QUARTETS.times.italic).toBe("Times-Italic");
+ });
+});
+
+describe("styleTokens at the defaults", () => {
+ const t = tokens();
+
+ it("passes every setting straight through", () => {
+ expect(t.fontSize).toBe(11);
+ expect(t.lineHeight).toBe(1.4);
+ expect(t.marginVertical).toBe(40);
+ expect(t.marginHorizontal).toBe(48);
+ expect(t.sectionSpacing).toBe(6);
+ expect(t.entrySpacing).toBe(8);
+ expect(t.font).toBe(FONT_QUARTETS.helvetica);
+ });
+
+ // Identity, not "rounds to the same number": this is what makes
+ // buildSimpleStyles at the defaults reproduce the old sheet exactly.
+ it("returns every derived literal untouched", () => {
+ for (const literal of [9, 10, 11, 12, 13, 14, 20, 24, 110, 0.8, 1.4]) {
+ expect(t.pt(literal)).toBe(literal);
+ }
+ });
+
+ it("derives certificate spacing at three quarters of an entry gap", () => {
+ expect(t.certSpacing).toBe(6);
+ });
+});
+
+describe("the fontSize setting", () => {
+ it("assigns the base rather than scaling it", () => {
+ expect(tokens({ fontSize: 11.5 }).fontSize).toBe(11.5);
+ expect(tokens({ fontSize: 8 }).fontSize).toBe(8);
+ });
+
+ it("scales derived sizes proportionally, to one decimal", () => {
+ const t = tokens({ fontSize: 11.5 });
+ expect(t.pt(20)).toBe(20.9);
+ expect(t.pt(110)).toBe(115);
+ expect(t.pt(10)).toBe(10.5);
+ });
+
+ it("scales down as well as up", () => {
+ const t = tokens({ fontSize: 8 });
+ expect(t.pt(110)).toBe(80);
+ expect(t.pt(24)).toBe(17.5);
+ });
+
+ it("is proportional to the base the sheets are written against", () => {
+ expect(BASE_FONT_SIZE).toBe(11);
+ expect(tokens({ fontSize: 16 }).pt(BASE_FONT_SIZE)).toBe(16);
+ });
+
+ it("leaves every spacing token alone", () => {
+ const t = tokens({ fontSize: 16 });
+ expect(t.lineHeight).toBe(1.4);
+ expect(t.marginHorizontal).toBe(48);
+ expect(t.entrySpacing).toBe(8);
+ });
+});
+
+describe("the spacing settings", () => {
+ it("passes section and entry spacing through untouched", () => {
+ const t = tokens({ sectionSpacing: 20, entrySpacing: 12 });
+ expect(t.sectionSpacing).toBe(20);
+ expect(t.entrySpacing).toBe(12);
+ });
+
+ it("keeps certificate spacing a whole number below the entry gap", () => {
+ expect(tokens({ entrySpacing: 12 }).certSpacing).toBe(9);
+ expect(tokens({ entrySpacing: 0 }).certSpacing).toBe(0);
+ expect(tokens({ entrySpacing: 3 }).certSpacing).toBe(2);
+ });
+
+ it("leaves font metrics alone", () => {
+ expect(tokens({ sectionSpacing: 32 }).pt(20)).toBe(20);
+ });
+});
+
+describe("the font setting", () => {
+ it("selects the quartet without touching any number", () => {
+ const t = tokens({ font: "times" });
+ expect(t.font.bold).toBe("Times-Bold");
+ expect(t.fontSize).toBe(11);
+ expect(t.marginVertical).toBe(40);
+ });
+});
diff --git a/__tests__/resumeStyleBuilders.spec.ts b/__tests__/resumeStyleBuilders.spec.ts
new file mode 100644
index 0000000..a223549
--- /dev/null
+++ b/__tests__/resumeStyleBuilders.spec.ts
@@ -0,0 +1,344 @@
+import { describe, it, expect } from "vitest";
+import {
+ defaultResumeExportSettings,
+ RESUME_TEMPLATE_DEFAULTS,
+} from "@/models/resumeExport.model";
+import { buildSimpleStyles } from "@/components/profile/resume-pdf/styles/simple.styles";
+import { buildProfessionalStyles } from "@/components/profile/resume-pdf/styles/professional.styles";
+
+const simple = (patch: Partial<typeof defaultResumeExportSettings> = {}) =>
+ buildSimpleStyles({ ...defaultResumeExportSettings, ...patch }).styles;
+
+const professional = (
+ patch: Partial<typeof defaultResumeExportSettings> = {},
+) =>
+ buildProfessionalStyles({ ...defaultResumeExportSettings, ...patch }).styles;
+
+describe("buildSimpleStyles at the defaults", () => {
+ const s = simple();
+
+ // The defaults are copied from this sheet, so this is a hard identity.
+ it("keeps the page exactly as the static sheet had it", () => {
+ expect(s.page).toEqual({
+ fontFamily: "Helvetica",
+ fontSize: 11,
+ paddingTop: 40,
+ paddingBottom: 40,
+ paddingHorizontal: 48,
+ color: "#000000",
+ lineHeight: 1.4,
+ });
+ });
+
+ it("keeps the section title exactly as the static sheet had it", () => {
+ expect(s.sectionTitle).toEqual({
+ fontSize: 11,
+ fontFamily: "Helvetica-Bold",
+ textTransform: "uppercase",
+ letterSpacing: 0.8,
+ marginBottom: 3,
+ marginTop: 6,
+ });
+ });
+
+ it("keeps the remaining numbers unmoved", () => {
+ expect(s.heading.fontSize).toBe(20);
+ expect(s.heading.marginBottom).toBe(8);
+ expect(s.subheading.fontSize).toBe(12);
+ expect(s.contactLine.fontSize).toBe(10);
+ expect(s.divider.marginBottom).toBe(6);
+ expect(s.bodyText.fontSize).toBe(11);
+ expect(s.entryTitle.fontSize).toBe(11);
+ expect(s.entryMeta.fontSize).toBe(10);
+ expect(s.bullet.width).toBe(14);
+ expect(s.h2text.fontSize).toBe(13);
+ expect(s.skillRow.marginBottom).toBe(3);
+ expect(s.skillCat.width).toBe(110);
+ expect(s.skillVals.fontSize).toBe(11);
+ });
+
+ it("carries the literals lifted out of SimpleTemplate", () => {
+ expect(s.headerBlock.marginBottom).toBe(12);
+ expect(s.entryBlock.marginBottom).toBe(8);
+ expect(s.certBlock.marginBottom).toBe(6);
+ expect(s.contactRow).toEqual({ flexDirection: "row", flexWrap: "wrap" });
+ expect(s.link).toEqual({ color: "#000000", textDecoration: "none" });
+ });
+
+ it("returns an html style set aliasing the sheet's own objects", () => {
+ const { styles, htmlStyles } = buildSimpleStyles(defaultResumeExportSettings);
+ expect(htmlStyles.bulletChar).toBe("•");
+ expect(htmlStyles.bold).toBe(styles.bold);
+ });
+});
+
+describe("buildProfessionalStyles at the defaults", () => {
+ const s = professional();
+
+ // One shared number cannot equal two templates' literals. These four are
+ // the whole of Professional's sanctioned drift; see the plan's Context.
+ it("takes the shared defaults where it used to differ", () => {
+ expect(s.page.paddingTop).toBe(40); // was 36
+ expect(s.page.paddingHorizontal).toBe(48); // was 44
+ expect(s.page.lineHeight).toBe(1.4); // was 1.45
+ expect(s.sectionHeadingRow.marginTop).toBe(6); // was 12
+ });
+
+ it("keeps everything else on the page exactly as it was", () => {
+ expect(s.page.fontFamily).toBe("Helvetica");
+ expect(s.page.fontSize).toBe(11);
+ expect(s.page.paddingBottom).toBe(40);
+ expect(s.page.color).toBe("#1a1a1a");
+ });
+
+ it("keeps the accent colour hardcoded and unscaled", () => {
+ expect(s.sectionHeadingLabel.color).toBe("#34506e");
+ expect(s.headline.color).toBe("#34506e");
+ expect(s.bullet.color).toBe("#34506e");
+ expect(s.sectionHeadingRule.borderBottomColor).toBe("#34506e");
+ });
+
+ it("keeps the remaining numbers unmoved", () => {
+ expect(s.name.fontSize).toBe(24);
+ expect(s.name.marginBottom).toBe(16);
+ expect(s.headline.fontSize).toBe(12);
+ expect(s.contactLine.fontSize).toBe(10);
+ expect(s.thickRule.marginBottom).toBe(10);
+ expect(s.sectionHeadingRow.marginBottom).toBe(6);
+ expect(s.sectionHeadingLabel.marginRight).toBe(6);
+ expect(s.entryDate.fontSize).toBe(10);
+ expect(s.entryDate.marginLeft).toBe(8);
+ expect(s.entryMeta.marginBottom).toBe(3);
+ expect(s.bullet.width).toBe(12);
+ expect(s.twoColRow.gap).toBe(20);
+ });
+
+ it("carries the literals lifted out of ProfessionalTemplate", () => {
+ expect(s.summaryBlock.marginBottom).toBe(4);
+ expect(s.entryBlock.marginBottom).toBe(8);
+ expect(s.certBlock.marginBottom).toBe(6);
+ expect(s.skillTwoColRow).toEqual({
+ flexDirection: "row",
+ gap: 20,
+ marginBottom: 4,
+ });
+ expect(s.skillCatLabel.fontSize).toBe(9);
+ expect(s.skillVals.fontSize).toBe(10);
+ expect(s.link).toEqual({ color: "#1a1a1a", textDecoration: "none" });
+ });
+
+ it("returns an html style set with the professional bullet char", () => {
+ const { htmlStyles } = buildProfessionalStyles(defaultResumeExportSettings);
+ expect(htmlStyles.bulletChar).toBe("▪");
+ });
+
+ // Guards the regression the settings work introduced once: Professional
+ // reading Simple's defaults silently restyled every existing export.
+ it("reproduces its own shipped literals at its own defaults", () => {
+ const s = buildProfessionalStyles(
+ RESUME_TEMPLATE_DEFAULTS.professional,
+ ).styles;
+ expect(s.page.paddingTop).toBe(36);
+ expect(s.page.paddingHorizontal).toBe(44);
+ expect(s.page.lineHeight).toBe(1.45);
+ expect(s.sectionHeadingRow.marginTop).toBe(12);
+ expect(s.entryBlock.marginBottom).toBe(8);
+ expect(s.certBlock.marginBottom).toBe(6);
+ });
+});
+
+describe("the font setting", () => {
+ it("swaps every Simple face to the Times quartet", () => {
+ const s = simple({ font: "times" });
+ expect(s.page.fontFamily).toBe("Times-Roman");
+ expect(s.bold.fontFamily).toBe("Times-Bold");
+ expect(s.italic.fontFamily).toBe("Times-Italic");
+ expect(s.boldItalic.fontFamily).toBe("Times-BoldItalic");
+ expect(s.heading.fontFamily).toBe("Times-Bold");
+ expect(s.sectionTitle.fontFamily).toBe("Times-Bold");
+ expect(s.entryTitle.fontFamily).toBe("Times-Bold");
+ expect(s.h2text.fontFamily).toBe("Times-Bold");
+ expect(s.skillCat.fontFamily).toBe("Times-Bold");
+ });
+
+ it("swaps every Professional face to the Courier quartet", () => {
+ const s = professional({ font: "courier" });
+ expect(s.page.fontFamily).toBe("Courier");
+ expect(s.bold.fontFamily).toBe("Courier-Bold");
+ expect(s.italic.fontFamily).toBe("Courier-Oblique");
+ expect(s.boldItalic.fontFamily).toBe("Courier-BoldOblique");
+ expect(s.name.fontFamily).toBe("Courier-Bold");
+ expect(s.headline.fontFamily).toBe("Courier");
+ expect(s.contactLine.fontFamily).toBe("Courier");
+ expect(s.sectionHeadingLabel.fontFamily).toBe("Courier-Bold");
+ expect(s.entryTitle.fontFamily).toBe("Courier-Bold");
+ expect(s.entryTitleBlock.fontFamily).toBe("Courier-Bold");
+ expect(s.entryDate.fontFamily).toBe("Courier");
+ expect(s.h2text.fontFamily).toBe("Courier-Bold");
+ expect(s.skillCatLabel.fontFamily).toBe("Courier-Bold");
+ });
+
+ it("leaves every number alone", () => {
+ const s = simple({ font: "courier" });
+ expect(s.page.fontSize).toBe(11);
+ expect(s.page.paddingHorizontal).toBe(48);
+ expect(s.page.lineHeight).toBe(1.4);
+ expect(s.entryBlock.marginBottom).toBe(8);
+ });
+});
+
+describe("the fontSize setting", () => {
+ // The base is assigned, not scaled, so a half point survives intact.
+ it("puts the exact value on every base-size property", () => {
+ const s = simple({ fontSize: 11.5 });
+ expect(s.page.fontSize).toBe(11.5);
+ expect(s.bodyText.fontSize).toBe(11.5);
+ expect(s.sectionTitle.fontSize).toBe(11.5);
+ expect(s.entryTitle.fontSize).toBe(11.5);
+ expect(s.listText.fontSize).toBe(11.5);
+ expect(s.skillVals.fontSize).toBe(11.5);
+ expect(s.bullet.fontSize).toBe(11.5);
+ });
+
+ it("puts the exact value on Professional's base-size properties too", () => {
+ const s = professional({ fontSize: 9.5 });
+ expect(s.page.fontSize).toBe(9.5);
+ expect(s.sectionHeadingLabel.fontSize).toBe(9.5);
+ expect(s.entryTitleBlock.fontSize).toBe(9.5);
+ expect(s.listText.fontSize).toBe(9.5);
+ });
+
+ it("scales the Simple derived sizes proportionally", () => {
+ const s = simple({ fontSize: 13 });
+ expect(s.heading.fontSize).toBe(23.6); // 20 * 13/11
+ expect(s.subheading.fontSize).toBe(14.2);
+ expect(s.contactLine.fontSize).toBe(11.8);
+ expect(s.h2text.fontSize).toBe(15.4);
+ });
+
+ it("scales the Professional derived sizes proportionally", () => {
+ const s = professional({ fontSize: 8 });
+ expect(s.name.fontSize).toBe(17.5); // 24 * 8/11
+ expect(s.headline.fontSize).toBe(8.7);
+ expect(s.skillCatLabel.fontSize).toBe(6.5);
+ });
+
+ it("scales the two font-metric widths with the text", () => {
+ expect(simple({ fontSize: 13 }).skillCat.width).toBeGreaterThan(110);
+ expect(simple({ fontSize: 9 }).bullet.width).toBeLessThan(14);
+ expect(professional({ fontSize: 9 }).bullet.width).toBeLessThan(12);
+ });
+
+ it("leaves every margin, gap and line height alone", () => {
+ const s = simple({ fontSize: 16 });
+ expect(s.page.paddingHorizontal).toBe(48);
+ expect(s.page.lineHeight).toBe(1.4);
+ expect(s.entryBlock.marginBottom).toBe(8);
+ expect(s.sectionTitle.marginTop).toBe(6);
+ expect(s.divider.marginBottom).toBe(6);
+ });
+});
+
+describe("the lineHeight setting", () => {
+ it("assigns the exact value to the page and nothing else", () => {
+ const s = simple({ lineHeight: 1.75 });
+ expect(s.page.lineHeight).toBe(1.75);
+ expect(s.page.fontSize).toBe(11);
+ expect(s.page.paddingHorizontal).toBe(48);
+ expect(s.entryBlock.marginBottom).toBe(8);
+ });
+
+ it("gives both templates the same value now", () => {
+ expect(professional({ lineHeight: 1.2 }).page.lineHeight).toBe(
+ simple({ lineHeight: 1.2 }).page.lineHeight,
+ );
+ });
+});
+
+describe("the margin settings", () => {
+ it("assigns the vertical value to top and bottom, and nothing else", () => {
+ const s = simple({ marginVertical: 24 });
+ expect(s.page.paddingTop).toBe(24);
+ expect(s.page.paddingBottom).toBe(24);
+ expect(s.page.paddingHorizontal).toBe(48);
+ });
+
+ it("assigns the horizontal value to paddingHorizontal only", () => {
+ const s = professional({ marginHorizontal: 72 });
+ expect(s.page.paddingHorizontal).toBe(72);
+ expect(s.page.paddingTop).toBe(40);
+ expect(s.page.fontSize).toBe(11);
+ });
+
+ // Margins are page padding. They must not leak into block spacing.
+ it("leaves every block gap alone", () => {
+ const s = simple({ marginVertical: 90, marginHorizontal: 18 });
+ expect(s.entryBlock.marginBottom).toBe(8);
+ expect(s.sectionTitle.marginTop).toBe(6);
+ expect(s.headerBlock.marginBottom).toBe(12);
+ });
+});
+
+describe("the sectionSpacing setting", () => {
+ it("sets the gap above a Simple section heading", () => {
+ expect(simple({ sectionSpacing: 20 }).sectionTitle.marginTop).toBe(20);
+ expect(simple({ sectionSpacing: 0 }).sectionTitle.marginTop).toBe(0);
+ });
+
+ it("sets the gap above a Professional section heading", () => {
+ expect(
+ professional({ sectionSpacing: 20 }).sectionHeadingRow.marginTop,
+ ).toBe(20);
+ });
+
+ it("touches nothing else", () => {
+ const s = simple({ sectionSpacing: 32 });
+ expect(s.sectionTitle.marginBottom).toBe(3);
+ expect(s.divider.marginBottom).toBe(6);
+ expect(s.entryBlock.marginBottom).toBe(8);
+ expect(s.page.paddingTop).toBe(40);
+ expect(s.h2text.marginTop).toBe(4);
+ });
+});
+
+describe("the entrySpacing setting", () => {
+ it("sets the entry gap in both templates", () => {
+ expect(simple({ entrySpacing: 14 }).entryBlock.marginBottom).toBe(14);
+ expect(professional({ entrySpacing: 14 }).entryBlock.marginBottom).toBe(14);
+ });
+
+ it("derives the certificate gap at three quarters", () => {
+ expect(simple({ entrySpacing: 12 }).certBlock.marginBottom).toBe(9);
+ expect(professional({ entrySpacing: 12 }).certBlock.marginBottom).toBe(9);
+ expect(simple({ entrySpacing: 0 }).certBlock.marginBottom).toBe(0);
+ });
+
+ it("touches nothing else", () => {
+ const s = professional({ entrySpacing: 24 });
+ expect(s.summaryBlock.marginBottom).toBe(4);
+ expect(s.entryMeta.marginBottom).toBe(3);
+ expect(s.name.marginBottom).toBe(16);
+ expect(s.sectionHeadingRow.marginTop).toBe(6);
+ expect(s.page.paddingTop).toBe(40);
+ });
+});
+
+describe("what no setting may reach", () => {
+ // Horizontal measurements are not spacing controls, and rule weights are
+ // not spacing at all. Both stay literal under every setting.
+ it("leaves horizontal gutters and rule weights alone", () => {
+ for (const s of [
+ professional({ sectionSpacing: 32, entrySpacing: 32, fontSize: 16 }),
+ professional({ sectionSpacing: 0, entrySpacing: 0, fontSize: 8 }),
+ ]) {
+ expect(s.twoColRow.gap).toBe(20);
+ expect(s.skillTwoColRow.gap).toBe(20);
+ expect(s.entryDate.marginLeft).toBe(8);
+ expect(s.sectionHeadingLabel.marginRight).toBe(6);
+ expect(s.thickRule.borderBottomWidth).toBe(2);
+ expect(s.sectionHeadingRule.borderBottomWidth).toBe(0.75);
+ }
+ expect(simple({ fontSize: 16 }).divider.borderBottomWidth).toBe(0.5);
+ expect(simple({ fontSize: 16 }).sectionTitle.letterSpacing).toBe(0.8);
+ });
+});
diff --git a/__tests__/useResumeExportSettings.spec.tsx b/__tests__/useResumeExportSettings.spec.tsx
new file mode 100644
index 0000000..199def4
--- /dev/null
+++ b/__tests__/useResumeExportSettings.spec.tsx
@@ -0,0 +1,219 @@
+import { act, renderHook } from "@testing-library/react";
+import { beforeEach, describe, expect, it } from "vitest";
+import {
+ coerceResumeExportSettings,
+ useResumeExportSettings,
+} from "@/components/profile/resume-container/useResumeExportSettings";
+import { APP_CONSTANTS } from "@/lib/constants";
+import {
+ defaultResumeExportSettings,
+ RESUME_TEMPLATE_DEFAULTS,
+} from "@/models/resumeExport.model";
+
+const KEY = APP_CONSTANTS.RESUME_EXPORT_SETTINGS_STORAGE_KEY;
+
+beforeEach(() => {
+ localStorage.clear();
+});
+
+describe("coerceResumeExportSettings", () => {
+ it("falls back to the defaults for anything that is not an object", () => {
+ for (const value of [null, undefined, 7, "simple", []]) {
+ expect(coerceResumeExportSettings(value)).toEqual(
+ defaultResumeExportSettings,
+ );
+ }
+ });
+
+ it("keeps every valid value", () => {
+ const stored = {
+ template: "professional",
+ font: "times",
+ fontSize: 12.5,
+ lineHeight: 1.6,
+ marginVertical: 30,
+ marginHorizontal: 36,
+ sectionSpacing: 14,
+ entrySpacing: 10,
+ };
+ expect(coerceResumeExportSettings(stored)).toEqual(stored);
+ });
+
+ // A key written by an older build, or edited by hand, must never reach a
+ // style sheet as an unknown token.
+ it("drops a named value that is not one of its setting's options", () => {
+ const coerced = coerceResumeExportSettings({
+ template: "professional",
+ font: "comic-sans",
+ });
+ expect(coerced.template).toBe("professional");
+ expect(coerced.font).toBe("helvetica");
+ });
+
+ // paddingHorizontal: NaN reaches the PDF renderer. This is the guard.
+ it("clamps or discards a numeric value that is out of range or not a number", () => {
+ const coerced = coerceResumeExportSettings({
+ fontSize: 900,
+ lineHeight: -4,
+ marginVertical: NaN,
+ marginHorizontal: "48",
+ sectionSpacing: null,
+ entrySpacing: 10,
+ });
+ expect(coerced.fontSize).toBe(16);
+ expect(coerced.lineHeight).toBe(1);
+ expect(coerced.marginVertical).toBe(40);
+ expect(coerced.marginHorizontal).toBe(48);
+ expect(coerced.sectionSpacing).toBe(6);
+ expect(coerced.entrySpacing).toBe(10);
+ });
+
+ it("rounds a stored value to its field's precision", () => {
+ expect(
+ coerceResumeExportSettings({ lineHeight: 1.4500000000000002 }).lineHeight,
+ ).toBe(1.45);
+ });
+
+ it("fills in fields the stored object never had, from that template", () => {
+ expect(coerceResumeExportSettings({ template: "professional" })).toEqual(
+ RESUME_TEMPLATE_DEFAULTS.professional,
+ );
+ });
+
+ it("ignores keys that are not settings", () => {
+ const coerced = coerceResumeExportSettings({ zoom: 2, font: "courier" });
+ expect(coerced).toEqual({
+ ...defaultResumeExportSettings,
+ font: "courier",
+ });
+ });
+
+ // The preview cache key is JSON.stringify(settings), so order matters even
+ // when the stored object was written with its keys in a different one.
+ it("returns the defaults' key order whatever the stored order was", () => {
+ const coerced = coerceResumeExportSettings({
+ entrySpacing: 4,
+ template: "professional",
+ font: "times",
+ });
+ expect(Object.keys(coerced)).toEqual(
+ Object.keys(defaultResumeExportSettings),
+ );
+ });
+});
+
+describe("useResumeExportSettings", () => {
+ it("stays closed and not ready while the dialog is shut", () => {
+ const { result } = renderHook(() => useResumeExportSettings(false));
+
+ expect(result.current.ready).toBe(false);
+ expect(result.current.settings).toEqual(defaultResumeExportSettings);
+ });
+
+ it("reads storage on open and reports ready", () => {
+ localStorage.setItem(
+ KEY,
+ JSON.stringify({ ...defaultResumeExportSettings, sectionSpacing: 18 }),
+ );
+
+ const { result } = renderHook(() => useResumeExportSettings(true));
+
+ expect(result.current.ready).toBe(true);
+ expect(result.current.settings.sectionSpacing).toBe(18);
+ });
+
+ it("re-seeds every other field when the template changes", () => {
+ const { result } = renderHook(() => useResumeExportSettings(true));
+
+ act(() => {
+ result.current.setSettings({
+ ...defaultResumeExportSettings,
+ fontSize: 13,
+ marginVertical: 60,
+ });
+ });
+ act(() => {
+ result.current.setSettings({
+ ...result.current.settings,
+ template: "professional",
+ });
+ });
+
+ expect(result.current.settings).toEqual(
+ RESUME_TEMPLATE_DEFAULTS.professional,
+ );
+ expect(JSON.parse(localStorage.getItem(KEY)!)).toEqual(
+ RESUME_TEMPLATE_DEFAULTS.professional,
+ );
+ });
+
+ it("resets to the current template's defaults, not Simple's", () => {
+ const { result } = renderHook(() => useResumeExportSettings(true));
+
+ act(() => {
+ result.current.setSettings({
+ ...defaultResumeExportSettings,
+ template: "professional",
+ });
+ });
+ act(() => {
+ result.current.setSettings({
+ ...result.current.settings,
+ sectionSpacing: 30,
+ });
+ });
+ act(() => result.current.reset());
+
+ expect(result.current.settings).toEqual(
+ RESUME_TEMPLATE_DEFAULTS.professional,
+ );
+ });
+
+ it("writes through on every change", () => {
+ const { result } = renderHook(() => useResumeExportSettings(true));
+
+ act(() => {
+ result.current.setSettings({
+ ...defaultResumeExportSettings,
+ marginHorizontal: 64,
+ });
+ });
+
+ expect(result.current.settings.marginHorizontal).toBe(64);
+ expect(JSON.parse(localStorage.getItem(KEY)!).marginHorizontal).toBe(64);
+ });
+
+ it("resets back to the defaults and persists that", () => {
+ localStorage.setItem(
+ KEY,
+ JSON.stringify({ ...defaultResumeExportSettings, font: "courier" }),
+ );
+ const { result } = renderHook(() => useResumeExportSettings(true));
+
+ act(() => result.current.reset());
+
+ expect(result.current.settings).toEqual(defaultResumeExportSettings);
+ expect(JSON.parse(localStorage.getItem(KEY)!)).toEqual(
+ defaultResumeExportSettings,
+ );
+ });
+
+ it("survives a corrupt stored value", () => {
+ localStorage.setItem(KEY, "{not json");
+
+ const { result } = renderHook(() => useResumeExportSettings(true));
+
+ expect(result.current.settings).toEqual(defaultResumeExportSettings);
+ expect(result.current.ready).toBe(true);
+ });
+
+ it("survives a stored value from an older build", () => {
+ localStorage.setItem(KEY, JSON.stringify({ template: "professional" }));
+
+ const { result } = renderHook(() => useResumeExportSettings(true));
+
+ expect(result.current.settings).toEqual(
+ RESUME_TEMPLATE_DEFAULTS.professional,
+ );
+ });
+});
diff --git a/__tests__/useResumePdfPreview.spec.ts b/__tests__/useResumePdfPreview.spec.ts
index 3855b67..4ea2340 100644
--- a/__tests__/useResumePdfPreview.spec.ts
+++ b/__tests__/useResumePdfPreview.spec.ts
@@ -1,7 +1,10 @@
import { act, renderHook } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { ContactInfo, Resume } from "@/models/profile.model";
-import type { ResumeExportSettings } from "@/models/resumeExport.model";
+import {
+ defaultResumeExportSettings,
+ type ResumeExportSettings,
+} from "@/models/resumeExport.model";
const { generateResumePdfBlob } = vi.hoisted(() => ({
generateResumePdfBlob: vi.fn(),
@@ -31,8 +34,11 @@ const resume: Resume = {
const emptyResume: Resume = { id: "r2", title: "Untouched" };
-const simple: ResumeExportSettings = { template: "simple" };
-const professional: ResumeExportSettings = { template: "professional" };
+const simple: ResumeExportSettings = { ...defaultResumeExportSettings };
+const professional: ResumeExportSettings = {
+ ...defaultResumeExportSettings,
+ template: "professional",
+};
// Flushes pending microtasks (the dynamic import) and any expired timers.
const flush = (ms = 0) =>
diff --git a/package.json b/package.json
index 65ba845..1b8433d 100644
--- a/package.json
+++ b/package.json
@@ -2,6 +2,12 @@
"name": "jobsync",
"version": "1.1.17",
"private": true,
+ "browserslist": [
+ "chrome >= 111",
+ "edge >= 111",
+ "firefox >= 128",
+ "safari >= 16.4"
+ ],
"scripts": {
"dev": "next dev --turbopack -p 3737",
"dev:webpack": "next dev -p 3737",
diff --git a/src/components/profile/ExportPdfDialog.tsx b/src/components/profile/ExportPdfDialog.tsx
index 9ea8326..6463ab0 100644
--- a/src/components/profile/ExportPdfDialog.tsx
+++ b/src/components/profile/ExportPdfDialog.tsx
@@ -1,7 +1,6 @@
"use client";
-import { useEffect, useState } from "react";
-import { FileDown, Loader } from "lucide-react";
+import { FileDown } from "lucide-react";
import {
Dialog,
DialogContent,
@@ -13,19 +12,19 @@ import {
import { Button } from "../ui/button";
import type { Resume } from "@/models/profile.model";
import {
- defaultResumeExportSettings,
+ RESUME_TEMPLATE_DEFAULTS,
type ResumeExportSettings,
} from "@/models/resumeExport.model";
import { ExportSettingsPanel } from "./export-pdf-dialog/ExportSettingsPanel";
import { PdfPreviewPane } from "./export-pdf-dialog/PdfPreviewPane";
import { canExportResume } from "./resume-container/useResumePdfExport";
+import { useResumeExportSettings } from "./resume-container/useResumeExportSettings";
import { useResumePdfPreview } from "./resume-container/useResumePdfPreview";
type ExportPdfDialogProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
resume: Resume;
- isExporting: boolean;
onExport: (
settings: ResumeExportSettings,
prepared?: { blob: Blob; filename: string } | null,
@@ -36,29 +35,23 @@ export function ExportPdfDialog({
open,
onOpenChange,
resume,
- isExporting,
onExport,
}: ExportPdfDialogProps) {
- const [settings, setSettings] = useState<ResumeExportSettings>(
- defaultResumeExportSettings,
- );
-
- // Settings are not persisted: reset on close, so the next open already
- // holds the defaults on its very first render.
- useEffect(() => {
- if (!open) setSettings(defaultResumeExportSettings);
- }, [open]);
+ const { settings, setSettings, ready, reset } = useResumeExportSettings(open);
+ const isDefault =
+ JSON.stringify(settings) ===
+ JSON.stringify(RESUME_TEMPLATE_DEFAULTS[settings.template]);
const canExport = canExportResume(resume);
const { blob, filename, isGenerating, error } = useResumePdfPreview(
resume,
settings,
- open,
+ open && ready,
);
// Exporting mid-generation would download the template just switched away
// from, since Export reuses the previewed blob.
- const exportDisabled = isExporting || !canExport || isGenerating;
+ const exportDisabled = !canExport || isGenerating;
return (
<Dialog open={open} onOpenChange={onOpenChange}>
@@ -83,7 +76,12 @@ export function ExportPdfDialog({
/>
</div>
<div className="order-1 min-h-0 shrink-0 overflow-y-auto md:order-2 md:w-[34%]">
- <ExportSettingsPanel settings={settings} onChange={setSettings} />
+ <ExportSettingsPanel
+ settings={settings}
+ onChange={setSettings}
+ onReset={reset}
+ isDefault={isDefault}
+ />
</div>
</div>
@@ -92,7 +90,6 @@ export function ExportPdfDialog({
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
- disabled={isExporting}
>
Cancel
</Button>
@@ -107,17 +104,8 @@ export function ExportPdfDialog({
onExport(settings, prepared);
}}
>
- {isExporting ? (
- <>
- <Loader className="h-4 w-4 animate-spin" />
- Generating…
- </>
- ) : (
- <>
- <FileDown className="h-4 w-4" />
- Export
- </>
- )}
+ <FileDown className="h-4 w-4" />
+ Export
</Button>
</DialogFooter>
</DialogContent>
diff --git a/src/components/profile/ResumeContainer.tsx b/src/components/profile/ResumeContainer.tsx
index f910035..dc9fa7f 100644
--- a/src/components/profile/ResumeContainer.tsx
+++ b/src/components/profile/ResumeContainer.tsx
@@ -77,7 +77,6 @@ function ResumeContainer({
} = useResumeImport(resume);
const {
- isExporting,
showAttachConfirm,
setShowAttachConfirm,
handleExportPdf,
@@ -289,7 +288,6 @@ function ResumeContainer({
open={showExportDialog}
onOpenChange={setShowExportDialog}
resume={resume}
- isExporting={isExporting}
onExport={handleExportPdf}
/>
diff --git a/src/components/profile/export-pdf-dialog/ExportSettingsPanel.tsx b/src/components/profile/export-pdf-dialog/ExportSettingsPanel.tsx
index 501c18a..05352a0 100644
--- a/src/components/profile/export-pdf-dialog/ExportSettingsPanel.tsx
+++ b/src/components/profile/export-pdf-dialog/ExportSettingsPanel.tsx
@@ -1,56 +1,281 @@
"use client";
+import { useEffect, useState } from "react";
+import { ChevronDown, ChevronRight, Minus, Plus } from "lucide-react";
+import { Button } from "@/components/ui/button";
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from "@/components/ui/collapsible";
+import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
-import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import {
+ clampNumericField,
+ formatSettingValue,
+ RESUME_FONT_LABELS,
RESUME_LAYOUT_LABELS,
+ RESUME_NUMERIC_SETTINGS,
type ResumeExportSettings,
- type ResumeLayout,
+ type ResumeNumericSetting,
} from "@/models/resumeExport.model";
-const TEMPLATE_OPTIONS: ResumeLayout[] = ["simple", "professional"];
-
type ExportSettingsPanelProps = {
settings: ResumeExportSettings;
onChange: (settings: ResumeExportSettings) => void;
+ onReset?: () => void;
+ isDefault?: boolean;
};
-// Later settings land as sibling <section> blocks below Template; every
-// control emits a whole settings object so the preview cache key stays valid.
+// Wraps rather than clips: the control drops below the label on a narrow
+// settings column instead of overflowing it.
+const ROW =
+ "flex flex-wrap items-center justify-between gap-x-3 gap-y-2 border-b px-4 py-2.5 last:border-b-0";
+
+// A label element pointing at role="combobox" is named inconsistently across
+// accname implementations, so the trigger carries its own aria-label.
+function SelectRow<T extends string>({
+ id,
+ label,
+ value,
+ labels,
+ onSelect,
+}: {
+ id: string;
+ label: string;
+ value: T;
+ labels: Record<T, string>;
+ onSelect: (value: T) => void;
+}) {
+ return (
+ <div className={ROW}>
+ <Label htmlFor={id} className="cursor-pointer font-normal">
+ {label}
+ </Label>
+ <Select value={value} onValueChange={(next) => onSelect(next as T)}>
+ <SelectTrigger id={id} aria-label={label} className="ml-auto h-8 w-40">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {(Object.keys(labels) as T[]).map((key) => (
+ <SelectItem key={key} value={key}>
+ {labels[key]}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+ );
+}
+
+// The draft string is what is typed; only a parsed, in-range value is
+// committed upward. Clamping on every keystroke would snap a cleared field
+// to its minimum mid-edit.
+function StepperRow({
+ field,
+ value,
+ onCommit,
+}: {
+ field: ResumeNumericSetting;
+ value: number;
+ onCommit: (value: number) => void;
+}) {
+ const spec = RESUME_NUMERIC_SETTINGS[field];
+ const id = `resume-export-${field}`;
+ const [draft, setDraft] = useState(() => String(value));
+
+ // Resyncs when the value moves without the input being touched: Reset,
+ // or the first read from storage.
+ useEffect(() => {
+ setDraft(String(value));
+ }, [value]);
+
+ const stepBy = (direction: 1 | -1) =>
+ onCommit(clampNumericField(field, value + direction * spec.step));
+
+ const onDraftChange = (next: string) => {
+ setDraft(next);
+ const parsed = Number(next);
+ if (next.trim() === "" || !Number.isFinite(parsed)) return;
+ if (parsed < spec.min || parsed > spec.max) return;
+ onCommit(clampNumericField(field, parsed));
+ };
+
+ return (
+ <div className={ROW}>
+ <Label htmlFor={id} className="cursor-pointer font-normal">
+ {spec.label}
+ </Label>
+ <div className="ml-auto flex items-center gap-1">
+ <Button
+ type="button"
+ variant="outline"
+ size="icon"
+ className="h-7 w-7 shrink-0"
+ aria-label={`Decrease ${spec.label}`}
+ disabled={value <= spec.min}
+ onClick={() => stepBy(-1)}
+ >
+ <Minus className="h-3 w-3" aria-hidden />
+ </Button>
+ <Input
+ id={id}
+ type="number"
+ inputMode="decimal"
+ min={spec.min}
+ max={spec.max}
+ step={spec.step}
+ value={draft}
+ onChange={(event) => onDraftChange(event.target.value)}
+ onBlur={() => setDraft(String(value))}
+ className="h-7 w-16 px-2 text-center text-sm"
+ />
+ {spec.unit && (
+ <span className="w-4 text-xs text-muted-foreground">{spec.unit}</span>
+ )}
+ <Button
+ type="button"
+ variant="outline"
+ size="icon"
+ className="h-7 w-7 shrink-0"
+ aria-label={`Increase ${spec.label}`}
+ disabled={value >= spec.max}
+ onClick={() => stepBy(1)}
+ >
+ <Plus className="h-3 w-3" aria-hidden />
+ </Button>
+ </div>
+ </div>
+ );
+}
+
+function DisclosureGroup({
+ title,
+ summary,
+ children,
+}: {
+ title: string;
+ summary: string;
+ children: React.ReactNode;
+}) {
+ const [open, setOpen] = useState(true);
+
+ return (
+ <Collapsible open={open} onOpenChange={setOpen}>
+ <CollapsibleTrigger className="flex w-full items-center gap-1.5 text-sm font-semibold">
+ {open ? (
+ <ChevronDown className="h-4 w-4" aria-hidden />
+ ) : (
+ <ChevronRight className="h-4 w-4" aria-hidden />
+ )}
+ {title}
+ </CollapsibleTrigger>
+ {!open && (
+ <p className="pl-[1.375rem] text-xs text-muted-foreground">{summary}</p>
+ )}
+ <CollapsibleContent className="mt-2 rounded-lg border bg-muted/40">
+ {children}
+ </CollapsibleContent>
+ </Collapsible>
+ );
+}
+
export function ExportSettingsPanel({
settings,
onChange,
+ onReset,
+ isDefault,
}: ExportSettingsPanelProps) {
+ const setNumber = (field: ResumeNumericSetting) => (value: number) =>
+ onChange({ ...settings, [field]: value });
+
+ const typographySummary = [
+ RESUME_FONT_LABELS[settings.font],
+ formatSettingValue("fontSize", settings.fontSize),
+ `${formatSettingValue("lineHeight", settings.lineHeight)} line`,
+ ].join(" • ");
+
+ const layoutSummary = [
+ `${settings.marginVertical} × ${settings.marginHorizontal} pt margins`,
+ `${settings.sectionSpacing}/${settings.entrySpacing} pt spacing`,
+ ].join(" • ");
+
return (
<div className="flex flex-col gap-4">
- <section className="rounded-lg border bg-muted/40">
- <h3 className="border-b px-4 py-2.5 text-sm font-semibold">Template</h3>
- <RadioGroup
- className="gap-0 px-4"
+ {/* Template reshapes everything below it, so it never folds away. */}
+ <div className="rounded-lg border bg-muted/40">
+ <SelectRow
+ id="resume-export-template"
+ label="Template"
value={settings.template}
- onValueChange={(value) =>
- onChange({ ...settings, template: value as ResumeLayout })
- }
- >
- {TEMPLATE_OPTIONS.map((layout) => (
- <div
- key={layout}
- className="flex items-center justify-between gap-3 border-b py-3 last:border-b-0"
- >
- <Label
- htmlFor={`resume-template-${layout}`}
- className="cursor-pointer font-normal"
- >
- {RESUME_LAYOUT_LABELS[layout]}
- </Label>
- <RadioGroupItem
- id={`resume-template-${layout}`}
- value={layout}
- />
- </div>
- ))}
- </RadioGroup>
- </section>
+ labels={RESUME_LAYOUT_LABELS}
+ onSelect={(template) => onChange({ ...settings, template })}
+ />
+ </div>
+
+ <DisclosureGroup title="Typography" summary={typographySummary}>
+ <SelectRow
+ id="resume-export-font"
+ label="Font"
+ value={settings.font}
+ labels={RESUME_FONT_LABELS}
+ onSelect={(font) => onChange({ ...settings, font })}
+ />
+ <StepperRow
+ field="fontSize"
+ value={settings.fontSize}
+ onCommit={setNumber("fontSize")}
+ />
+ <StepperRow
+ field="lineHeight"
+ value={settings.lineHeight}
+ onCommit={setNumber("lineHeight")}
+ />
+ </DisclosureGroup>
+
+ <DisclosureGroup title="Layout" summary={layoutSummary}>
+ <StepperRow
+ field="marginVertical"
+ value={settings.marginVertical}
+ onCommit={setNumber("marginVertical")}
+ />
+ <StepperRow
+ field="marginHorizontal"
+ value={settings.marginHorizontal}
+ onCommit={setNumber("marginHorizontal")}
+ />
+ <StepperRow
+ field="sectionSpacing"
+ value={settings.sectionSpacing}
+ onCommit={setNumber("sectionSpacing")}
+ />
+ <StepperRow
+ field="entrySpacing"
+ value={settings.entrySpacing}
+ onCommit={setNumber("entrySpacing")}
+ />
+ </DisclosureGroup>
+
+ {onReset && (
+ <div className="flex justify-end">
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ onClick={onReset}
+ disabled={isDefault}
+ >
+ Reset to defaults
+ </Button>
+ </div>
+ )}
</div>
);
}
diff --git a/src/components/profile/export-pdf-dialog/PdfPreviewPane.tsx b/src/components/profile/export-pdf-dialog/PdfPreviewPane.tsx
index 4c31ba8..627ab6d 100644
--- a/src/components/profile/export-pdf-dialog/PdfPreviewPane.tsx
+++ b/src/components/profile/export-pdf-dialog/PdfPreviewPane.tsx
@@ -48,6 +48,8 @@ export function PdfPreviewPane({
const scrollRef = useRef<HTMLDivElement>(null);
const measureRef = useRef<HTMLDivElement>(null);
const pagesRef = useRef<HTMLDivElement>(null);
+ // What the observer last saw, against what was last committed to state.
+ const measuredRef = useRef({ width: 0, height: 0 });
const sizeRef = useRef({ width: 0, height: 0 });
const [size, setSize] = useState({ width: 0, height: 0 });
const [pageCount, setPageCount] = useState(0);
@@ -57,10 +59,16 @@ export function PdfPreviewPane({
// Read after mount: localStorage is unavailable during SSR, so seeding the
// initial state from it would cause a hydration mismatch.
useEffect(() => {
- const saved = getFromLocalStorage(
- APP_CONSTANTS.RESUME_PREVIEW_FIT_STORAGE_KEY,
- null,
- );
+ let saved: unknown = null;
+ try {
+ saved = getFromLocalStorage(
+ APP_CONSTANTS.RESUME_PREVIEW_FIT_STORAGE_KEY,
+ null,
+ );
+ } catch {
+ // getFromLocalStorage calls JSON.parse unguarded; a corrupt value
+ // would otherwise throw out of this effect and kill the dialog.
+ }
if (saved === "page" || saved === "width") setFitMode(saved);
}, []);
@@ -78,14 +86,18 @@ export function PdfPreviewPane({
// Width caps the page; the scroll box's height is what decides whether a
// whole page fits, so both are measured.
const observer = new ResizeObserver((entries) => {
- let { width, height } = sizeRef.current;
+ const next = { ...measuredRef.current };
for (const entry of entries) {
if (entry.target === measure) {
- width = Math.floor(entry.contentRect.width);
+ next.width = Math.floor(entry.contentRect.width);
} else {
- height = Math.floor(entry.contentRect.height);
+ next.height = Math.floor(entry.contentRect.height);
}
}
+ // Recorded before the zero-guard: the two targets can report in
+ // separate callbacks, and bailing early would drop the good half.
+ measuredRef.current = next;
+ const { width, height } = next;
if (width <= 0 || height <= 0) return;
if (width === sizeRef.current.width && height === sizeRef.current.height) {
return;
diff --git a/src/components/profile/resume-container/useResumeExportSettings.ts b/src/components/profile/resume-container/useResumeExportSettings.ts
new file mode 100644
index 0000000..eb8bb28
--- /dev/null
+++ b/src/components/profile/resume-container/useResumeExportSettings.ts
@@ -0,0 +1,101 @@
+"use client";
+import { useEffect, useState } from "react";
+import { APP_CONSTANTS } from "@/lib/constants";
+import {
+ clampNumericField,
+ defaultResumeExportSettings,
+ RESUME_FONT_LABELS,
+ RESUME_LAYOUT_LABELS,
+ RESUME_NUMERIC_SETTINGS,
+ RESUME_TEMPLATE_DEFAULTS,
+ type ResumeExportSettings,
+ type ResumeFont,
+ type ResumeLayout,
+ type ResumeNumericSetting,
+} from "@/models/resumeExport.model";
+import {
+ getFromLocalStorage,
+ saveToLocalStorage,
+} from "@/utils/localstorage.utils";
+
+const KEY = APP_CONSTANTS.RESUME_EXPORT_SETTINGS_STORAGE_KEY;
+
+// Rebuilt from a spread of the defaults, so the key order always comes from
+// that one literal — the preview cache key is JSON.stringify(settings).
+export function coerceResumeExportSettings(
+ stored: unknown,
+): ResumeExportSettings {
+ if (!stored || typeof stored !== "object" || Array.isArray(stored)) {
+ return { ...defaultResumeExportSettings };
+ }
+ const raw = stored as Record<string, unknown>;
+
+ // The template is read first: every other field falls back to that
+ // template's own default rather than to Simple's.
+ const template =
+ typeof raw.template === "string" && raw.template in RESUME_LAYOUT_LABELS
+ ? (raw.template as ResumeLayout)
+ : defaultResumeExportSettings.template;
+ const next = { ...RESUME_TEMPLATE_DEFAULTS[template] };
+
+ if (typeof raw.font === "string" && raw.font in RESUME_FONT_LABELS) {
+ next.font = raw.font as ResumeFont;
+ }
+
+ // Numeric settings: clampNumericField returns the field's default for
+ // anything that is not a finite number, so a missing key needs no guard.
+ for (const field of Object.keys(
+ RESUME_NUMERIC_SETTINGS,
+ ) as ResumeNumericSetting[]) {
+ next[field] = clampNumericField(field, raw[field], template);
+ }
+
+ return next;
+}
+
+function readStored(): ResumeExportSettings {
+ try {
+ return coerceResumeExportSettings(getFromLocalStorage(KEY, null));
+ } catch {
+ // getFromLocalStorage calls JSON.parse unguarded.
+ return { ...defaultResumeExportSettings };
+ }
+}
+
+// Reads on open rather than at mount: localStorage is unavailable during SSR,
+// and `ready` holds the preview back one commit so it generates once, with
+// the stored settings, instead of once with the defaults and again after.
+export function useResumeExportSettings(open: boolean) {
+ const [settings, setSettings] = useState<ResumeExportSettings>(
+ defaultResumeExportSettings,
+ );
+ const [ready, setReady] = useState(false);
+
+ useEffect(() => {
+ if (!open) {
+ setReady(false);
+ return;
+ }
+ setSettings(readStored());
+ setReady(true);
+ }, [open]);
+
+ // Picking a template re-seeds the rest: each template's defaults are its
+ // own shipped literals, so carrying the previous one's numbers across
+ // would silently restyle the template the user just chose.
+ const update = (next: ResumeExportSettings) => {
+ const applied =
+ next.template === settings.template
+ ? next
+ : { ...RESUME_TEMPLATE_DEFAULTS[next.template] };
+ setSettings(applied);
+ saveToLocalStorage(KEY, applied);
+ };
+
+ return {
+ settings,
+ setSettings: update,
+ ready,
+ reset: () => update({ ...RESUME_TEMPLATE_DEFAULTS[settings.template] }),
+ };
+}
diff --git a/src/components/profile/resume-pdf/ProfessionalTemplate.tsx b/src/components/profile/resume-pdf/ProfessionalTemplate.tsx
index 7564b95..3d10121 100644
--- a/src/components/profile/resume-pdf/ProfessionalTemplate.tsx
+++ b/src/components/profile/resume-pdf/ProfessionalTemplate.tsx
@@ -2,7 +2,7 @@ import React from "react";
import { Document, Link, Page, Text, View } from "@react-pdf/renderer";
import { format } from "date-fns";
import { Resume, ResumeSection, SectionType } from "@/models/profile.model";
-import { professionalStyles as s } from "./styles/professional.styles";
+import type { ProfessionalStyles } from "./styles/professional.styles";
import { ResumeHtmlNodes } from "./generateResumePdf";
function formatDate(date: Date | undefined | null): string {
@@ -20,7 +20,13 @@ function yearRange(startDate: Date, endDate?: Date | null): string {
return `${start} – ${end}`;
}
-function SectionHeading({ title }: { title: string }) {
+function SectionHeading({
+ title,
+ s,
+}: {
+ title: string;
+ s: ProfessionalStyles;
+}) {
return (
<View style={s.sectionHeadingRow}>
<Text style={s.sectionHeadingLabel}>{title}</Text>
@@ -30,14 +36,20 @@ function SectionHeading({ title }: { title: string }) {
}
// Renders sections that use licenseOrCertifications (CERTIFICATION, LICENSE, COURSE, etc.)
-function CertLikeSection({ section }: { section: ResumeSection }) {
+function CertLikeSection({
+ section,
+ s,
+}: {
+ section: ResumeSection;
+ s: ProfessionalStyles;
+}) {
const entries = section.licenseOrCertifications;
if (!entries || entries.length === 0) return null;
return (
<View>
- <SectionHeading title={section.sectionTitle} />
+ <SectionHeading title={section.sectionTitle} s={s} />
{entries.map((cert, i) => (
- <View key={cert.id ?? i} style={{ marginBottom: 6 }} wrap={false}>
+ <View key={cert.id ?? i} style={s.certBlock} wrap={false}>
<Text style={s.entryTitleBlock}>{cert.title}</Text>
<Text style={s.entryMeta}>{cert.organization}</Text>
{(cert.issueDate || cert.expirationDate) && (
@@ -62,9 +74,14 @@ function CertLikeSection({ section }: { section: ResumeSection }) {
type Props = {
resume: Resume;
htmlNodes: ResumeHtmlNodes;
+ styles: ProfessionalStyles;
};
-export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
+export function ProfessionalResumeDocument({
+ resume,
+ htmlNodes,
+ styles: s,
+}: Props) {
const { ContactInfo, ResumeSections } = resume;
const summarySection = ResumeSections?.find(
@@ -132,7 +149,7 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
{ContactInfo.url1 && (
<Link
src={ContactInfo.url1}
- style={{ color: "#1a1a1a", textDecoration: "none" }}
+ style={s.link}
>
{ContactInfo.url1.replace(/^https?:\/\/(www\.)?/, "")}
</Link>
@@ -141,7 +158,7 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
{ContactInfo.url2 && (
<Link
src={ContactInfo.url2}
- style={{ color: "#1a1a1a", textDecoration: "none" }}
+ style={s.link}
>
{ContactInfo.url2.replace(/^https?:\/\/(www\.)?/, "")}
</Link>
@@ -158,7 +175,7 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
{/* Summary — no section heading */}
{summarySection?.summary?.content && htmlNodes.summary.length > 0 && (
- <View style={{ marginBottom: 4 }}>{htmlNodes.summary}</View>
+ <View style={s.summaryBlock}>{htmlNodes.summary}</View>
)}
{/* Skills */}
@@ -173,7 +190,7 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
const hasCategories = Array.from(grouped.keys()).some((k) => k !== "");
return (
<View>
- <SectionHeading title={skillsSection.sectionTitle} />
+ <SectionHeading title={skillsSection.sectionTitle} s={s} />
{hasCategories ? (() => {
const entries = Array.from(grouped.entries());
const rows: (typeof entries)[] = [];
@@ -181,15 +198,15 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
rows.push(entries.slice(i, i + 2));
}
return rows.map((row, rowIdx) => (
- <View key={rowIdx} style={[s.twoColRow, { marginBottom: 4 }]}>
+ <View key={rowIdx} style={s.skillTwoColRow}>
{row.map(([cat, items]) => (
<View key={cat || "__flat"} style={s.twoColLeft}>
{cat ? (
- <Text style={{ fontSize: 9, fontFamily: "Helvetica-Bold", textTransform: "uppercase", marginBottom: 1 }}>
+ <Text style={s.skillCatLabel}>
{cat}
</Text>
) : null}
- <Text style={{ fontSize: 10 }}>
+ <Text style={s.skillVals}>
{items.map((sk) => sk.Tag?.label).filter(Boolean).join(" · ")}
</Text>
</View>
@@ -198,7 +215,7 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
</View>
));
})() : (
- <Text style={{ fontSize: 10 }}>
+ <Text style={s.skillVals}>
{sorted.map((sk) => sk.Tag?.label).filter(Boolean).join(" · ")}
</Text>
)}
@@ -210,9 +227,9 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
{experienceSection?.workExperiences &&
experienceSection.workExperiences.length > 0 && (
<View>
- <SectionHeading title={experienceSection.sectionTitle} />
+ <SectionHeading title={experienceSection.sectionTitle} s={s} />
{experienceSection.workExperiences.map((exp, i) => (
- <View key={exp.id ?? i} style={{ marginBottom: 8 }}>
+ <View key={exp.id ?? i} style={s.entryBlock}>
<View wrap={false}>
<View style={s.entryHeaderRow}>
<Text style={s.entryTitle}>{exp.jobTitle.label}</Text>
@@ -237,9 +254,9 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
if (sec.workExperiences && sec.workExperiences.length > 0) {
return (
<View key={sec.id}>
- <SectionHeading title={sec.sectionTitle} />
+ <SectionHeading title={sec.sectionTitle} s={s} />
{sec.workExperiences.map((exp, i) => (
- <View key={exp.id ?? i} style={{ marginBottom: 8 }}>
+ <View key={exp.id ?? i} style={s.entryBlock}>
<View wrap={false}>
<View style={s.entryHeaderRow}>
<Text style={s.entryTitle}>{exp.jobTitle.label}</Text>
@@ -259,7 +276,7 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
);
}
if (sec.licenseOrCertifications && sec.licenseOrCertifications.length > 0) {
- return <CertLikeSection key={sec.id} section={sec} />;
+ return <CertLikeSection key={sec.id} section={sec} s={s} />;
}
return null;
})}
@@ -271,9 +288,9 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
<View style={s.twoColLeft}>
{educationSection?.educations && educationSection.educations.length > 0 && (
<View>
- <SectionHeading title={educationSection.sectionTitle} />
+ <SectionHeading title={educationSection.sectionTitle} s={s} />
{educationSection.educations.map((edu, i) => (
- <View key={edu.id ?? i} style={{ marginBottom: 8 }}>
+ <View key={edu.id ?? i} style={s.entryBlock}>
<View wrap={false}>
<View style={s.entryHeaderRow}>
<Text style={s.entryTitle}>
@@ -294,7 +311,7 @@ export function ProfessionalResumeDocument({ resume, htmlNodes }: Props) {
{/* Right: Certifications and Licenses */}
<View style={s.twoColRight}>
{certLikeSections.map((sec) => (
- <CertLikeSection key={sec.id} section={sec} />
+ <CertLikeSection key={sec.id} section={sec} s={s} />
))}
</View>
</View>
diff --git a/src/components/profile/resume-pdf/SimpleTemplate.tsx b/src/components/profile/resume-pdf/SimpleTemplate.tsx
index 36c563f..fd5e589 100644
--- a/src/components/profile/resume-pdf/SimpleTemplate.tsx
+++ b/src/components/profile/resume-pdf/SimpleTemplate.tsx
@@ -2,7 +2,7 @@ import React from "react";
import { Document, Link, Page, Text, View } from "@react-pdf/renderer";
import { format } from "date-fns";
import { Resume, SectionType } from "@/models/profile.model";
-import { simpleStyles } from "./styles/simple.styles";
+import type { SimpleStyles } from "./styles/simple.styles";
import { ResumeHtmlNodes } from "./generateResumePdf";
function formatDate(date: Date | undefined | null): string {
@@ -14,11 +14,17 @@ function formatLocation(label: string | undefined): string {
return label && label !== "Not specified" ? label : "";
}
-function SectionHeading({ title }: { title: string }) {
+function SectionHeading({
+ title,
+ styles,
+}: {
+ title: string;
+ styles: SimpleStyles;
+}) {
return (
<View>
- <Text style={simpleStyles.sectionTitle}>{title}</Text>
- <View style={simpleStyles.divider} />
+ <Text style={styles.sectionTitle}>{title}</Text>
+ <View style={styles.divider} />
</View>
);
}
@@ -26,9 +32,10 @@ function SectionHeading({ title }: { title: string }) {
type Props = {
resume: Resume;
htmlNodes: ResumeHtmlNodes;
+ styles: SimpleStyles;
};
-export function SimpleResumeDocument({ resume, htmlNodes }: Props) {
+export function SimpleResumeDocument({ resume, htmlNodes, styles }: Props) {
const { ContactInfo, ResumeSections } = resume;
const skillsSection = ResumeSections?.find(
@@ -64,23 +71,23 @@ export function SimpleResumeDocument({ resume, htmlNodes }: Props) {
producer="react-pdf"
title={resume.title}
>
- <Page size="A4" style={simpleStyles.page} wrap>
+ <Page size="A4" style={styles.page} wrap>
{/* Header */}
{ContactInfo && (
- <View style={{ marginBottom: 12 }}>
- <Text style={simpleStyles.heading}>
+ <View style={styles.headerBlock}>
+ <Text style={styles.heading}>
{ContactInfo.firstName} {ContactInfo.lastName}
</Text>
{ContactInfo.headline ? (
- <Text style={simpleStyles.subheading}>{ContactInfo.headline}</Text>
+ <Text style={styles.subheading}>{ContactInfo.headline}</Text>
) : null}
{contactParts.length > 0 ? (
- <View style={{ flexDirection: "row", flexWrap: "wrap" }}>
+ <View style={styles.contactRow}>
{contactParts.map((part, i) => (
- <Text key={i} style={simpleStyles.contactLine}>
+ <Text key={i} style={styles.contactLine}>
{i > 0 ? " · " : ""}
{part.href ? (
- <Link src={part.href} style={{ color: "#000000", textDecoration: "none" }}>
+ <Link src={part.href} style={styles.link}>
{part.text}
</Link>
) : (
@@ -96,7 +103,7 @@ export function SimpleResumeDocument({ resume, htmlNodes }: Props) {
{/* Summary */}
{htmlNodes.summary.length > 0 && (
<View>
- <SectionHeading title="Summary" />
+ <SectionHeading title="Summary" styles={styles} />
{htmlNodes.summary}
</View>
)}
@@ -113,20 +120,20 @@ export function SimpleResumeDocument({ resume, htmlNodes }: Props) {
const hasCategories = Array.from(grouped.keys()).some((k) => k !== "");
return (
<View>
- <SectionHeading title={skillsSection.sectionTitle} />
+ <SectionHeading title={skillsSection.sectionTitle} styles={styles} />
{hasCategories ? (
Array.from(grouped.entries()).map(([cat, items]) => (
- <View key={cat || "__flat"} style={simpleStyles.skillRow}>
+ <View key={cat || "__flat"} style={styles.skillRow}>
{cat ? (
- <Text style={simpleStyles.skillCat}>{cat.toUpperCase()}</Text>
+ <Text style={styles.skillCat}>{cat.toUpperCase()}</Text>
) : null}
- <Text style={simpleStyles.skillVals}>
+ <Text style={styles.skillVals}>
{items.map((s) => s.Tag?.label).filter(Boolean).join(" · ")}
</Text>
</View>
))
) : (
- <Text style={simpleStyles.bodyText}>
+ <Text style={styles.bodyText}>
{sorted.map((s) => s.Tag?.label).filter(Boolean).join(" · ")}
</Text>
)}
@@ -138,14 +145,14 @@ export function SimpleResumeDocument({ resume, htmlNodes }: Props) {
{experienceSection?.workExperiences &&
experienceSection.workExperiences.length > 0 && (
<View>
- <SectionHeading title={experienceSection.sectionTitle} />
+ <SectionHeading title={experienceSection.sectionTitle} styles={styles} />
{experienceSection.workExperiences.map((exp, i) => (
- <View key={exp.id ?? i} style={{ marginBottom: 8 }}>
+ <View key={exp.id ?? i} style={styles.entryBlock}>
<View wrap={false}>
- <Text style={simpleStyles.entryTitle}>
+ <Text style={styles.entryTitle}>
{exp.jobTitle.label} — {exp.Company.label}
</Text>
- <Text style={simpleStyles.entryMeta}>
+ <Text style={styles.entryMeta}>
{formatDate(exp.startDate)} – {formatDate(exp.endDate)}
{formatLocation(exp.location.label) &&
` · ${formatLocation(exp.location.label)}`}
@@ -161,15 +168,15 @@ export function SimpleResumeDocument({ resume, htmlNodes }: Props) {
{educationSection?.educations &&
educationSection.educations.length > 0 && (
<View>
- <SectionHeading title={educationSection.sectionTitle} />
+ <SectionHeading title={educationSection.sectionTitle} styles={styles} />
{educationSection.educations.map((edu, i) => (
- <View key={edu.id ?? i} style={{ marginBottom: 8 }}>
+ <View key={edu.id ?? i} style={styles.entryBlock}>
<View wrap={false}>
- <Text style={simpleStyles.entryTitle}>{edu.institution}</Text>
- <Text style={simpleStyles.entryMeta}>
+ <Text style={styles.entryTitle}>{edu.institution}</Text>
+ <Text style={styles.entryMeta}>
{[edu.degree, edu.fieldOfStudy].filter(Boolean).join(", ")}
</Text>
- <Text style={simpleStyles.entryMeta}>
+ <Text style={styles.entryMeta}>
{formatDate(edu.startDate)} –{" "}
{edu.endDate ? formatDate(edu.endDate) : "Present"}
{formatLocation(edu.location.label) &&
@@ -186,13 +193,13 @@ export function SimpleResumeDocument({ resume, htmlNodes }: Props) {
{certificationSection?.licenseOrCertifications &&
certificationSection.licenseOrCertifications.length > 0 && (
<View>
- <SectionHeading title={certificationSection.sectionTitle} />
+ <SectionHeading title={certificationSection.sectionTitle} styles={styles} />
{certificationSection.licenseOrCertifications.map((cert, i) => (
- <View key={cert.id ?? i} style={{ marginBottom: 6 }} wrap={false}>
- <Text style={simpleStyles.entryTitle}>{cert.title}</Text>
- <Text style={simpleStyles.entryMeta}>{cert.organization}</Text>
+ <View key={cert.id ?? i} style={styles.certBlock} wrap={false}>
+ <Text style={styles.entryTitle}>{cert.title}</Text>
+ <Text style={styles.entryMeta}>{cert.organization}</Text>
{(cert.issueDate || cert.expirationDate) && (
- <Text style={simpleStyles.entryMeta}>
+ <Text style={styles.entryMeta}>
{[
cert.issueDate ? formatDate(cert.issueDate) : null,
cert.expirationDate ? formatDate(cert.expirationDate) : null,
@@ -202,7 +209,7 @@ export function SimpleResumeDocument({ resume, htmlNodes }: Props) {
</Text>
)}
{cert.credentialUrl && (
- <Text style={simpleStyles.entryMeta}>{cert.credentialUrl}</Text>
+ <Text style={styles.entryMeta}>{cert.credentialUrl}</Text>
)}
</View>
))}
diff --git a/src/components/profile/resume-pdf/generateResumePdf.tsx b/src/components/profile/resume-pdf/generateResumePdf.tsx
index 19ad7ef..c69f7bd 100644
--- a/src/components/profile/resume-pdf/generateResumePdf.tsx
+++ b/src/components/profile/resume-pdf/generateResumePdf.tsx
@@ -6,8 +6,9 @@ import {
defaultResumeExportSettings,
type ResumeExportSettings,
} from "./types";
-import { simpleHtmlStyles } from "./styles/simple.styles";
-import { professionalHtmlStyles } from "./styles/professional.styles";
+import type { HtmlStyleSet } from "./types";
+import { buildSimpleStyles } from "./styles/simple.styles";
+import { buildProfessionalStyles } from "./styles/professional.styles";
export type ResumeHtmlNodes = {
summary: React.ReactElement[];
@@ -25,14 +26,11 @@ export function sanitizeFilename(name: string): string {
return sanitized || "resume";
}
-export async function generateResumePdfBlob(
+// Parse HTML on the main thread before entering react-pdf's rendering context
+function buildHtmlNodes(
resume: Resume,
- settings: ResumeExportSettings = defaultResumeExportSettings,
-): Promise<{ blob: Blob; filename: string }> {
- const layout = settings.template;
- const htmlStyles = layout === "professional" ? professionalHtmlStyles : simpleHtmlStyles;
-
- // Parse HTML in the browser main thread before entering react-pdf's rendering context
+ htmlStyles: HtmlStyleSet,
+): ResumeHtmlNodes {
const summarySection = resume.ResumeSections?.find(
(s) => s.sectionType === SectionType.SUMMARY,
);
@@ -43,7 +41,7 @@ export async function generateResumePdfBlob(
(s) => s.sectionType === SectionType.EDUCATION,
);
- const htmlNodes: ResumeHtmlNodes = {
+ return {
summary: summarySection?.summary?.content
? htmlToPdfNodes(summarySection.summary.content, htmlStyles)
: [],
@@ -56,17 +54,41 @@ export async function generateResumePdfBlob(
edu.description ? htmlToPdfNodes(edu.description, htmlStyles) : [],
) ?? [],
};
+}
+
+export async function generateResumePdfBlob(
+ resume: Resume,
+ settings: ResumeExportSettings = defaultResumeExportSettings,
+): Promise<{ blob: Blob; filename: string }> {
+ const layout = settings.template;
const { pdf, Font } = await import("@react-pdf/renderer");
Font.registerHyphenationCallback((word) => [word]);
+ // Branch fully so each sheet narrows to its own template's prop type
let document: React.ReactElement;
if (layout === "professional") {
+ const { styles, htmlStyles } = buildProfessionalStyles(settings);
+ const htmlNodes = buildHtmlNodes(resume, htmlStyles);
const { ProfessionalResumeDocument } = await import("./ProfessionalTemplate");
- document = <ProfessionalResumeDocument resume={resume} htmlNodes={htmlNodes} />;
+ document = (
+ <ProfessionalResumeDocument
+ resume={resume}
+ htmlNodes={htmlNodes}
+ styles={styles}
+ />
+ );
} else {
+ const { styles, htmlStyles } = buildSimpleStyles(settings);
+ const htmlNodes = buildHtmlNodes(resume, htmlStyles);
const { SimpleResumeDocument } = await import("./SimpleTemplate");
- document = <SimpleResumeDocument resume={resume} htmlNodes={htmlNodes} />;
+ document = (
+ <SimpleResumeDocument
+ resume={resume}
+ htmlNodes={htmlNodes}
+ styles={styles}
+ />
+ );
}
const blob = await pdf(document as any).toBlob();
diff --git a/src/components/profile/resume-pdf/index.ts b/src/components/profile/resume-pdf/index.ts
index ec3f59c..84ec05e 100644
--- a/src/components/profile/resume-pdf/index.ts
+++ b/src/components/profile/resume-pdf/index.ts
@@ -1,4 +1,4 @@
export { downloadResumePdf, generateResumePdfBlob, sanitizeFilename } from "./generateResumePdf";
export { htmlToPdfNodes } from "./html-to-pdf";
-export type { ResumeExportSettings, ResumeLayout } from "./types";
-export { RESUME_LAYOUT_LABELS, defaultResumeExportSettings } from "./types";
+export type { ResumeLayout } from "./types";
+export { RESUME_LAYOUT_LABELS } from "./types";
diff --git a/src/components/profile/resume-pdf/styles/professional.styles.ts b/src/components/profile/resume-pdf/styles/professional.styles.ts
index 6e643f3..904593e 100644
--- a/src/components/profile/resume-pdf/styles/professional.styles.ts
+++ b/src/components/profile/resume-pdf/styles/professional.styles.ts
@@ -1,155 +1,186 @@
import { StyleSheet } from "@react-pdf/renderer";
import { HtmlStyleSet } from "../types";
+import type { ResumeExportSettings } from "@/models/resumeExport.model";
+import { styleTokens } from "./tokens";
const ACCENT = "#34506e";
const NEAR_BLACK = "#1a1a1a";
const GRAY = "#555555";
-export const professionalStyles = StyleSheet.create({
- page: {
- fontFamily: "Helvetica",
- fontSize: 11,
- paddingTop: 36,
- paddingBottom: 40,
- paddingHorizontal: 44,
- color: NEAR_BLACK,
- lineHeight: 1.45,
- },
- // Header
- headerRow: {
- flexDirection: "row",
- justifyContent: "space-between",
- alignItems: "flex-start",
- marginBottom: 8,
- },
- headerLeft: {
- flex: 1,
- },
- headerRight: {
- alignItems: "flex-end",
- },
- name: {
- fontFamily: "Helvetica-Bold",
- fontSize: 24,
- color: NEAR_BLACK,
- marginBottom: 16,
- },
- headline: {
- fontFamily: "Helvetica",
- fontSize: 12,
- color: ACCENT,
- textTransform: "uppercase",
- letterSpacing: 1.2,
- },
- contactLine: {
- fontFamily: "Helvetica",
- fontSize: 10,
- color: NEAR_BLACK,
- marginBottom: 1,
- },
- thickRule: {
- borderBottomWidth: 2,
- borderBottomColor: "#000000",
- marginBottom: 10,
- },
- // Section heading
- sectionHeadingRow: {
- flexDirection: "row",
- alignItems: "center",
- marginBottom: 6,
- marginTop: 12,
- },
- sectionHeadingLabel: {
- fontFamily: "Helvetica-Bold",
- fontSize: 11,
- color: ACCENT,
- textTransform: "uppercase",
- letterSpacing: 1.4,
- marginRight: 6,
- },
- sectionHeadingRule: {
- flex: 1,
- borderBottomWidth: 0.75,
- borderBottomColor: ACCENT,
- },
- // Body
- bodyText: {
- fontSize: 11,
- marginBottom: 2,
- },
- bold: { fontFamily: "Helvetica-Bold" },
- italic: { fontFamily: "Helvetica-Oblique" },
- boldItalic: { fontFamily: "Helvetica-BoldOblique" },
- h2text: {
- fontFamily: "Helvetica-Bold",
- fontSize: 13,
- marginBottom: 3,
- marginTop: 4,
- },
- // Entry rows
- entryHeaderRow: {
- flexDirection: "row",
- justifyContent: "space-between",
- alignItems: "flex-start",
- },
- entryTitle: {
- fontFamily: "Helvetica-Bold",
- fontSize: 11,
- color: NEAR_BLACK,
- flex: 1,
- },
- // Use when entryTitle is NOT inside entryHeaderRow (no row sibling to flex against)
- entryTitleBlock: {
- fontFamily: "Helvetica-Bold",
- fontSize: 11,
- color: NEAR_BLACK,
- },
- entryDate: {
- fontFamily: "Helvetica",
- fontSize: 10,
- color: GRAY,
- marginLeft: 8,
- },
- entryMeta: {
- fontSize: 10,
- color: GRAY,
- marginBottom: 3,
- },
- // List
- listRow: {
- flexDirection: "row",
- marginBottom: 1,
- },
- bullet: {
- width: 12,
- fontSize: 11,
- color: ACCENT,
- },
- listText: {
- flex: 1,
- fontSize: 11,
- },
- // Two-column section
- twoColRow: {
- flexDirection: "row",
- gap: 20,
- },
- twoColLeft: {
- flex: 1,
- },
- twoColRight: {
- flex: 1,
- },
-});
+export function buildProfessionalStyles(settings: ResumeExportSettings) {
+ const t = styleTokens(settings);
-export const professionalHtmlStyles: HtmlStyleSet = {
- bodyText: professionalStyles.bodyText,
- bold: professionalStyles.bold,
- italic: professionalStyles.italic,
- boldItalic: professionalStyles.boldItalic,
- h2text: professionalStyles.h2text,
- listRow: professionalStyles.listRow,
- bullet: professionalStyles.bullet,
- listText: professionalStyles.listText,
- bulletChar: "▪",
-};
+ const styles = StyleSheet.create({
+ page: {
+ fontFamily: t.font.regular,
+ fontSize: t.fontSize,
+ paddingTop: t.marginVertical,
+ paddingBottom: t.marginVertical,
+ paddingHorizontal: t.marginHorizontal,
+ color: NEAR_BLACK,
+ lineHeight: t.lineHeight,
+ },
+ // Header
+ headerRow: {
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "flex-start",
+ marginBottom: 8,
+ },
+ headerLeft: {
+ flex: 1,
+ },
+ headerRight: {
+ alignItems: "flex-end",
+ },
+ name: {
+ fontFamily: t.font.bold,
+ fontSize: t.pt(24),
+ color: NEAR_BLACK,
+ marginBottom: 16,
+ },
+ headline: {
+ fontFamily: t.font.regular,
+ fontSize: t.pt(12),
+ color: ACCENT,
+ textTransform: "uppercase",
+ letterSpacing: 1.2,
+ },
+ contactLine: {
+ fontFamily: t.font.regular,
+ fontSize: t.pt(10),
+ color: NEAR_BLACK,
+ marginBottom: 1,
+ },
+ thickRule: {
+ borderBottomWidth: 2,
+ borderBottomColor: "#000000",
+ marginBottom: 10,
+ },
+ // Section heading
+ sectionHeadingRow: {
+ flexDirection: "row",
+ alignItems: "center",
+ marginBottom: 6,
+ marginTop: t.sectionSpacing,
+ },
+ sectionHeadingLabel: {
+ fontFamily: t.font.bold,
+ fontSize: t.fontSize,
+ color: ACCENT,
+ textTransform: "uppercase",
+ letterSpacing: 1.4,
+ marginRight: 6,
+ },
+ sectionHeadingRule: {
+ flex: 1,
+ borderBottomWidth: 0.75,
+ borderBottomColor: ACCENT,
+ },
+ // Body
+ bodyText: {
+ fontSize: t.fontSize,
+ marginBottom: 2,
+ },
+ bold: { fontFamily: t.font.bold },
+ italic: { fontFamily: t.font.italic },
+ boldItalic: { fontFamily: t.font.boldItalic },
+ h2text: {
+ fontFamily: t.font.bold,
+ fontSize: t.pt(13),
+ marginBottom: 3,
+ marginTop: 4,
+ },
+ // Entry rows
+ entryHeaderRow: {
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "flex-start",
+ },
+ entryTitle: {
+ fontFamily: t.font.bold,
+ fontSize: t.fontSize,
+ color: NEAR_BLACK,
+ flex: 1,
+ },
+ // Use when entryTitle is NOT inside entryHeaderRow (no row sibling to flex against)
+ entryTitleBlock: {
+ fontFamily: t.font.bold,
+ fontSize: t.fontSize,
+ color: NEAR_BLACK,
+ },
+ entryDate: {
+ fontFamily: t.font.regular,
+ fontSize: t.pt(10),
+ color: GRAY,
+ marginLeft: 8,
+ },
+ entryMeta: {
+ fontSize: t.pt(10),
+ color: GRAY,
+ marginBottom: 3,
+ },
+ // List
+ listRow: {
+ flexDirection: "row",
+ marginBottom: 1,
+ },
+ bullet: {
+ width: t.pt(12),
+ fontSize: t.fontSize,
+ color: ACCENT,
+ },
+ listText: {
+ flex: 1,
+ fontSize: t.fontSize,
+ },
+ // Two-column section
+ twoColRow: {
+ flexDirection: "row",
+ gap: 20,
+ },
+ twoColLeft: {
+ flex: 1,
+ },
+ twoColRight: {
+ flex: 1,
+ },
+ // Lifted out of ProfessionalTemplate so the settings can reach them
+ summaryBlock: { marginBottom: 4 },
+ entryBlock: { marginBottom: t.entrySpacing },
+ certBlock: { marginBottom: t.certSpacing },
+ skillTwoColRow: {
+ flexDirection: "row",
+ gap: 20,
+ marginBottom: 4,
+ },
+ skillCatLabel: {
+ fontSize: t.pt(9),
+ fontFamily: t.font.bold,
+ textTransform: "uppercase",
+ marginBottom: 1,
+ },
+ skillVals: {
+ fontSize: t.pt(10),
+ },
+ link: { color: NEAR_BLACK, textDecoration: "none" },
+ });
+
+ const htmlStyles: HtmlStyleSet = {
+ bodyText: styles.bodyText,
+ bold: styles.bold,
+ italic: styles.italic,
+ boldItalic: styles.boldItalic,
+ h2text: styles.h2text,
+ listRow: styles.listRow,
+ bullet: styles.bullet,
+ listText: styles.listText,
+ bulletChar: "▪",
+ };
+
+ return { styles, htmlStyles };
+}
+
+export type ProfessionalStyles = ReturnType<
+ typeof buildProfessionalStyles
+>["styles"];
diff --git a/src/components/profile/resume-pdf/styles/simple.styles.ts b/src/components/profile/resume-pdf/styles/simple.styles.ts
index f6cacc1..84249c5 100644
--- a/src/components/profile/resume-pdf/styles/simple.styles.ts
+++ b/src/components/profile/resume-pdf/styles/simple.styles.ts
@@ -1,93 +1,109 @@
import { StyleSheet } from "@react-pdf/renderer";
import { HtmlStyleSet } from "../types";
+import type { ResumeExportSettings } from "@/models/resumeExport.model";
+import { styleTokens } from "./tokens";
-export const simpleStyles = StyleSheet.create({
- page: {
- fontFamily: "Helvetica",
- fontSize: 11,
- paddingTop: 40,
- paddingBottom: 40,
- paddingHorizontal: 48,
- color: "#000000",
- lineHeight: 1.4,
- },
- heading: {
- fontSize: 20,
- fontFamily: "Helvetica-Bold",
- marginBottom: 8,
- },
- subheading: {
- fontSize: 12,
- marginBottom: 2,
- },
- contactLine: {
- fontSize: 10,
- color: "#444444",
- marginBottom: 2,
- },
- sectionTitle: {
- fontSize: 11,
- fontFamily: "Helvetica-Bold",
- textTransform: "uppercase",
- letterSpacing: 0.8,
- marginBottom: 3,
- marginTop: 6,
- },
- divider: {
- borderBottomWidth: 0.5,
- borderBottomColor: "#000000",
- marginBottom: 6,
- },
- bold: { fontFamily: "Helvetica-Bold" },
- italic: { fontFamily: "Helvetica-Oblique" },
- boldItalic: { fontFamily: "Helvetica-BoldOblique" },
- bodyText: { fontSize: 11, marginBottom: 2 },
- entryTitle: {
- fontFamily: "Helvetica-Bold",
- fontSize: 11,
- marginBottom: 1,
- },
- entryMeta: {
- fontSize: 10,
- color: "#444444",
- marginBottom: 2,
- },
- listRow: {
- flexDirection: "row",
- marginBottom: 1,
- },
- bullet: { width: 14, fontSize: 11 },
- listText: { flex: 1, fontSize: 11 },
- h2text: {
- fontFamily: "Helvetica-Bold",
- fontSize: 13,
- marginBottom: 3,
- marginTop: 4,
- },
- skillRow: {
- flexDirection: "row",
- marginBottom: 3,
- },
- skillCat: {
- fontFamily: "Helvetica-Bold",
- fontSize: 10,
- width: 110,
- flexShrink: 0,
- },
- skillVals: {
- flex: 1,
- fontSize: 11,
- },
-});
+export function buildSimpleStyles(settings: ResumeExportSettings) {
+ const t = styleTokens(settings);
-export const simpleHtmlStyles: HtmlStyleSet = {
- bodyText: simpleStyles.bodyText,
- bold: simpleStyles.bold,
- italic: simpleStyles.italic,
- boldItalic: simpleStyles.boldItalic,
- h2text: simpleStyles.h2text,
- listRow: simpleStyles.listRow,
- bullet: simpleStyles.bullet,
- listText: simpleStyles.listText,
- bulletChar: "•",
-};
+ const styles = StyleSheet.create({
+ page: {
+ fontFamily: t.font.regular,
+ fontSize: t.fontSize,
+ paddingTop: t.marginVertical,
+ paddingBottom: t.marginVertical,
+ paddingHorizontal: t.marginHorizontal,
+ color: "#000000",
+ lineHeight: t.lineHeight,
+ },
+ heading: {
+ fontSize: t.pt(20),
+ fontFamily: t.font.bold,
+ marginBottom: 8,
+ },
+ subheading: {
+ fontSize: t.pt(12),
+ marginBottom: 2,
+ },
+ contactLine: {
+ fontSize: t.pt(10),
+ color: "#444444",
+ marginBottom: 2,
+ },
+ sectionTitle: {
+ fontSize: t.fontSize,
+ fontFamily: t.font.bold,
+ textTransform: "uppercase",
+ letterSpacing: 0.8,
+ marginBottom: 3,
+ marginTop: t.sectionSpacing,
+ },
+ divider: {
+ borderBottomWidth: 0.5,
+ borderBottomColor: "#000000",
+ marginBottom: 6,
+ },
+ bold: { fontFamily: t.font.bold },
+ italic: { fontFamily: t.font.italic },
+ boldItalic: { fontFamily: t.font.boldItalic },
+ bodyText: { fontSize: t.fontSize, marginBottom: 2 },
+ entryTitle: {
+ fontFamily: t.font.bold,
+ fontSize: t.fontSize,
+ marginBottom: 1,
+ },
+ entryMeta: {
+ fontSize: t.pt(10),
+ color: "#444444",
+ marginBottom: 2,
+ },
+ listRow: {
+ flexDirection: "row",
+ marginBottom: 1,
+ },
+ bullet: { width: t.pt(14), fontSize: t.fontSize },
+ listText: { flex: 1, fontSize: t.fontSize },
+ h2text: {
+ fontFamily: t.font.bold,
+ fontSize: t.pt(13),
+ marginBottom: 3,
+ marginTop: 4,
+ },
+ skillRow: {
+ flexDirection: "row",
+ marginBottom: 3,
+ },
+ skillCat: {
+ fontFamily: t.font.bold,
+ fontSize: t.pt(10),
+ width: t.pt(110),
+ flexShrink: 0,
+ },
+ skillVals: {
+ flex: 1,
+ fontSize: t.fontSize,
+ },
+ // Lifted out of SimpleTemplate so the settings can reach them
+ headerBlock: { marginBottom: 12 },
+ contactRow: { flexDirection: "row", flexWrap: "wrap" },
+ entryBlock: { marginBottom: t.entrySpacing },
+ certBlock: { marginBottom: t.certSpacing },
+ link: { color: "#000000", textDecoration: "none" },
+ });
+
+ const htmlStyles: HtmlStyleSet = {
+ bodyText: styles.bodyText,
+ bold: styles.bold,
+ italic: styles.italic,
+ boldItalic: styles.boldItalic,
+ h2text: styles.h2text,
+ listRow: styles.listRow,
+ bullet: styles.bullet,
+ listText: styles.listText,
+ bulletChar: "•",
+ };
+
+ return { styles, htmlStyles };
+}
+
+export type SimpleStyles = ReturnType<typeof buildSimpleStyles>["styles"];
diff --git a/src/components/profile/resume-pdf/styles/tokens.ts b/src/components/profile/resume-pdf/styles/tokens.ts
new file mode 100644
index 0000000..69cf41a
--- /dev/null
+++ b/src/components/profile/resume-pdf/styles/tokens.ts
@@ -0,0 +1,74 @@
+import type {
+ ResumeExportSettings,
+ ResumeFont,
+} from "@/models/resumeExport.model";
+
+export type FontQuartet = {
+ regular: string;
+ bold: string;
+ italic: string;
+ boldItalic: string;
+};
+
+// The three standard-14 families @react-pdf/font ships; anything else
+// would need font files shipped or fetched.
+export const FONT_QUARTETS: Record<ResumeFont, FontQuartet> = {
+ helvetica: {
+ regular: "Helvetica",
+ bold: "Helvetica-Bold",
+ italic: "Helvetica-Oblique",
+ boldItalic: "Helvetica-BoldOblique",
+ },
+ times: {
+ regular: "Times-Roman",
+ bold: "Times-Bold",
+ italic: "Times-Italic",
+ boldItalic: "Times-BoldItalic",
+ },
+ courier: {
+ regular: "Courier",
+ bold: "Courier-Bold",
+ italic: "Courier-Oblique",
+ boldItalic: "Courier-BoldOblique",
+ },
+};
+
+// Every derived size in both sheets is proportional to this.
+export const BASE_FONT_SIZE = 11;
+
+// Certificate blocks sit at three quarters of an entry gap in both
+// templates (6 against 8), so the ratio is identity at the default.
+const CERT_SPACING_RATIO = 0.75;
+
+export type StyleTokens = {
+ font: FontQuartet;
+ /** The base size itself. Assigned, never passed through `pt`. */
+ fontSize: number;
+ /** Sizes derived from the base, and the two font-metric widths. */
+ pt: (literal: number) => number;
+ lineHeight: number;
+ marginVertical: number;
+ marginHorizontal: number;
+ sectionSpacing: number;
+ entrySpacing: number;
+ certSpacing: number;
+};
+
+export function styleTokens(settings: ResumeExportSettings): StyleTokens {
+ const scale = settings.fontSize / BASE_FONT_SIZE;
+
+ return {
+ font: FONT_QUARTETS[settings.font],
+ fontSize: settings.fontSize,
+ // A scale of exactly 1 returns the literal untouched rather than
+ // rounding it, so the defaults reproduce the Simple sheet exactly.
+ pt: (literal) =>
+ scale === 1 ? literal : Math.round(literal * scale * 10) / 10,
+ lineHeight: settings.lineHeight,
+ marginVertical: settings.marginVertical,
+ marginHorizontal: settings.marginHorizontal,
+ sectionSpacing: settings.sectionSpacing,
+ entrySpacing: settings.entrySpacing,
+ certSpacing: Math.round(settings.entrySpacing * CERT_SPACING_RATIO),
+ };
+}
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index ce15306..aca700d 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -39,6 +39,7 @@ export const APP_CONSTANTS = {
LAST_JOB_SOURCE_STORAGE_KEY: "last-job-source",
JOBS_VIEW_MODE_STORAGE_KEY: "jobs-view-mode",
RESUME_PREVIEW_FIT_STORAGE_KEY: "resume-preview-fit",
+ RESUME_EXPORT_SETTINGS_STORAGE_KEY: "resume-export-settings",
SIDEBAR_DOM_ID: "app-sidebar",
// Paired so the rail width and its matching content offset can't drift.
SIDEBAR_WIDTH: {
diff --git a/src/models/resumeExport.model.ts b/src/models/resumeExport.model.ts
index 18f3752..daa92f0 100644
--- a/src/models/resumeExport.model.ts
+++ b/src/models/resumeExport.model.ts
@@ -1,15 +1,117 @@
export type ResumeLayout = "simple" | "professional";
+export type ResumeFont = "helvetica" | "times" | "courier";
export const RESUME_LAYOUT_LABELS: Record<ResumeLayout, string> = {
simple: "Simple",
professional: "Professional",
};
-// The preview cache key. Each future setting is one added field here.
+export const RESUME_FONT_LABELS: Record<ResumeFont, string> = {
+ helvetica: "Helvetica",
+ times: "Times",
+ courier: "Courier",
+};
+
+export type ResumeNumericSetting =
+ | "fontSize"
+ | "lineHeight"
+ | "marginVertical"
+ | "marginHorizontal"
+ | "sectionSpacing"
+ | "entrySpacing";
+
+export type NumericSettingSpec = {
+ label: string;
+ min: number;
+ max: number;
+ step: number;
+ // Places a value is rounded to on write; kills IEEE-754 step drift.
+ decimals: number;
+ unit: string;
+};
+
+// One table: the stepper rows, the summaries and the storage validator all
+// read their bounds from here.
+export const RESUME_NUMERIC_SETTINGS: Record<
+ ResumeNumericSetting,
+ NumericSettingSpec
+> = {
+ fontSize: { label: "Font size", min: 8, max: 16, step: 0.5, decimals: 1, unit: "pt" },
+ lineHeight: { label: "Line height", min: 1, max: 2, step: 0.05, decimals: 2, unit: "" },
+ marginVertical: { label: "Margin top/bottom", min: 18, max: 90, step: 2, decimals: 0, unit: "pt" },
+ marginHorizontal: { label: "Margin left/right", min: 18, max: 90, step: 2, decimals: 0, unit: "pt" },
+ sectionSpacing: { label: "Section spacing", min: 0, max: 32, step: 1, decimals: 0, unit: "pt" },
+ entrySpacing: { label: "Entry spacing", min: 0, max: 32, step: 1, decimals: 0, unit: "pt" },
+};
+
+// The preview cache key is JSON.stringify(settings), so this literal's key
+// order is the order every settings object must keep.
export interface ResumeExportSettings {
template: ResumeLayout;
+ font: ResumeFont;
+ fontSize: number;
+ lineHeight: number;
+ marginVertical: number;
+ marginHorizontal: number;
+ sectionSpacing: number;
+ entrySpacing: number;
}
-export const defaultResumeExportSettings: ResumeExportSettings = {
- template: "simple",
+// Each template's own literals, so building its styles at its own defaults
+// is identity — the settings only ever move a template off what it shipped.
+export const RESUME_TEMPLATE_DEFAULTS: Record<
+ ResumeLayout,
+ ResumeExportSettings
+> = {
+ simple: {
+ template: "simple",
+ font: "helvetica",
+ fontSize: 11,
+ lineHeight: 1.4,
+ marginVertical: 40,
+ marginHorizontal: 48,
+ sectionSpacing: 6,
+ entrySpacing: 8,
+ },
+ professional: {
+ template: "professional",
+ font: "helvetica",
+ fontSize: 11,
+ lineHeight: 1.45,
+ marginVertical: 36,
+ marginHorizontal: 44,
+ sectionSpacing: 12,
+ entrySpacing: 8,
+ },
};
+
+export const defaultResumeExportSettings = RESUME_TEMPLATE_DEFAULTS.simple;
+
+const roundTo = (value: number, decimals: number) => {
+ const factor = 10 ** decimals;
+ return Math.round(value * factor) / factor;
+};
+
+// Every write to a numeric setting goes through here — stepper buttons,
+// typed input and the stored-value validator alike.
+export function clampNumericField(
+ field: ResumeNumericSetting,
+ value: unknown,
+ template: ResumeLayout = "simple",
+): number {
+ if (typeof value !== "number" || !Number.isFinite(value)) {
+ return RESUME_TEMPLATE_DEFAULTS[template][field];
+ }
+ const spec = RESUME_NUMERIC_SETTINGS[field];
+ return roundTo(Math.min(spec.max, Math.max(spec.min, value)), spec.decimals);
+}
+
+// Reads the way the stepper input reads: a bare number, plus a unit when
+// the field has one. `decimals` is for rounding, not for display.
+export function formatSettingValue(
+ field: ResumeNumericSetting,
+ value: number,
+): string {
+ const spec = RESUME_NUMERIC_SETTINGS[field];
+ return spec.unit ? `${value} ${spec.unit}` : String(value);
+}