refactor(pdf): introduce createBaseTemplateStyles factory (~1,150 lines removed)

Move 14 identical style slots (text/heading/div/inline/link/small/bold/
richParagraph/richListItemRow/richListItemMarker/richListItemContent/
splitRow/alignEnd/picture) from all 15 template Page.tsx files into a
single createBaseTemplateStyles factory in templates/shared. Each template
now spreads …base and keeps only its real overrides. Resolved StyleSheet
values are identical to before. Update rtl-fixture and rich-text-template-
styles tests to guard the factory file rather than each template directly.

Claude-Session: https://claude.ai/code/session_012Bnvt1MghwHj4qQRxuQUGa
This commit is contained in:
Amruth Pillai
2026-07-04 20:13:42 +02:00
parent 0701f3b62a
commit f3a60432df
18 changed files with 207 additions and 1154 deletions
@@ -4,6 +4,8 @@ import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const templatesDir = fileURLToPath(new URL("../", import.meta.url));
// ponytail: richListItemContent moved to shared factory; guard the factory directly.
const factoryFile = fileURLToPath(new URL("./base-template-styles.ts", import.meta.url));
const templatePageFiles = readdirSync(templatesDir, { withFileTypes: true }).flatMap((entry) => {
if (!entry.isDirectory() || entry.name === "shared") return [];
@@ -15,14 +17,31 @@ const templatePageFiles = readdirSync(templatesDir, { withFileTypes: true }).fla
});
describe("rich text template styles", () => {
it.each(
templatePageFiles.map((file) => [basename(file), file]),
)("%s keeps list item rich text on the global body line height", (_name, file) => {
const source = readFileSync(file, "utf8");
// The shared factory owns richListItemContent for all 15 templates.
it("base factory keeps list item rich text on the global body line height", () => {
const source = readFileSync(factoryFile, "utf8");
const richListItemContentBlock = source.match(/richListItemContent:\s*{(?<body>[\s\S]*?)^\s*},/m);
expect(richListItemContentBlock?.groups?.body).toBeDefined();
expect(richListItemContentBlock?.groups?.body).toContain("...bodyText");
expect(richListItemContentBlock?.groups?.body).not.toMatch(/\blineHeight:/);
});
it.each(
templatePageFiles.map((file) => [basename(file), file]),
)("%s keeps list item rich text on the global body line height", (_name, file) => {
const source = readFileSync(file, "utf8");
if (source.includes("createBaseTemplateStyles")) {
// Factory handles richListItemContent; guard is on the factory test above.
expect(source).toContain("createBaseTemplateStyles");
return;
}
// Legacy: template defines richListItemContent inline — no lineHeight override allowed.
const richListItemContentBlock = source.match(/richListItemContent:\s*{(?<body>[\s\S]*?)^\s*},/m);
expect(richListItemContentBlock?.groups?.body).toBeDefined();
expect(richListItemContentBlock?.groups?.body).toContain("...bodyText");
expect(richListItemContentBlock?.groups?.body).not.toMatch(/\blineHeight:/);
});
});