Skip to content

armgit / pdfcn

Public Imported from GitHub
0

Beautiful pdf components, built on Takumi and Forme. 100% Free, Zero config, one command setup.

feat: upgrade takumi-pdf to 0.9 and repeat report footers on every page

Kane Wang9c237d7f53f4
diff --git a/app/api/pdf/takumi/route.tsx b/app/api/pdf/takumi/route.tsx
index 49a6e7a..e848668 100644
--- a/app/api/pdf/takumi/route.tsx
+++ b/app/api/pdf/takumi/route.tsx
@@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";
import path from "node:path";
import { fromJsx } from "@takumi-rs/helpers/jsx";
-import { render } from "takumi-pdf";
+import { render } from "takumi-pdf/next";
import { demos } from "@/examples/__index__";
import { getTakumiPreviewOptions } from "@/examples/preview-config";
diff --git a/components/pdf-preview.tsx b/components/pdf-preview.tsx
index efab0f5..0eb0b64 100644
--- a/components/pdf-preview.tsx
+++ b/components/pdf-preview.tsx
@@ -1,13 +1,13 @@
"use client";
import { createElement, useEffect, useRef, useState } from "react";
+import takumiWasmUrl from "takumi-pdf/wasm-url";
import { replacePreviewImageSources } from "@/examples/preview-assets";
import { cn } from "@/lib/utils";
import type { BaseName } from "@/registry/bases";
import type { PdfcnTheme } from "@/registry/themes";
-const TAKUMI_WASM_PATH = "/takumi_pdf_wasm_bg.wasm";
const PREVIEW_LOGO_PATH = "/favicon.png";
let takumiWasmReady: Promise<unknown> | undefined;
@@ -21,10 +21,10 @@ interface PdfPreviewProps {
}
const startTakumi = async (
- initialize: (input: { module_or_path: string }) => Promise<unknown>
+ initialize: (input: { module_or_path: URL }) => Promise<unknown>
) => {
try {
- return await initialize({ module_or_path: TAKUMI_WASM_PATH });
+ return await initialize({ module_or_path: takumiWasmUrl });
} catch (error) {
takumiWasmReady = undefined;
throw error;
@@ -32,12 +32,30 @@ const startTakumi = async (
};
const initializeTakumi = (
- initialize: (input: { module_or_path: string }) => Promise<unknown>
+ initialize: (input: { module_or_path: URL }) => Promise<unknown>
) => {
takumiWasmReady ??= startTakumi(initialize);
+
return takumiWasmReady;
};
+const loadTakumiElement = async (name: string, theme?: PdfcnTheme) => {
+ if (theme) {
+ const { InvoiceClassicDocument } =
+ await import("@/registry/bases/takumi/blocks/invoice-classic/invoice-classic");
+
+ return createElement(InvoiceClassicDocument, { theme });
+ }
+
+ const { demos } = await import("@/examples/__index__");
+ const Demo = demos.takumi[name];
+ if (!Demo) {
+ throw new Error(`Unknown Takumi demo: ${name}`);
+ }
+
+ return createElement(Demo);
+};
+
const loadPreviewLogo = async () => {
const response = await fetch(PREVIEW_LOGO_PATH);
if (!response.ok) {
@@ -86,59 +104,28 @@ export const PdfPreview = ({
let pdfBytes: Uint8Array;
if (base === "takumi") {
- if (theme) {
- const [
- { InvoiceClassicDocument },
- { default: initialize, render },
- { fromJsx },
- images,
- ] = await Promise.all([
- import("@/registry/bases/takumi/blocks/invoice-classic/invoice-classic"),
- import("takumi-pdf"),
- import("@takumi-rs/helpers/jsx"),
- loadPreviewLogo(),
- ]);
+ const [
+ { default: initialize, render },
+ { fromJsx },
+ { getTakumiPreviewOptions },
+ images,
+ element,
+ ] = await Promise.all([
+ import("takumi-pdf/no-init"),
+ import("@takumi-rs/helpers/jsx"),
+ import("@/examples/preview-config"),
+ loadPreviewLogo(),
+ loadTakumiElement(name, theme),
+ ]);
- await initializeTakumi(initialize);
- const { node, stylesheets } = await fromJsx(
- createElement(InvoiceClassicDocument, { theme })
- );
- const { getTakumiPreviewOptions } =
- await import("@/examples/preview-config");
- const buffer = await render(node, {
- ...getTakumiPreviewOptions(name),
- images,
- stylesheets,
- });
- pdfBytes = new Uint8Array(buffer);
- } else {
- const [
- { demos },
- { default: initialize, render },
- { fromJsx },
- { getTakumiPreviewOptions },
- images,
- ] = await Promise.all([
- import("@/examples/__index__"),
- import("takumi-pdf"),
- import("@takumi-rs/helpers/jsx"),
- import("@/examples/preview-config"),
- loadPreviewLogo(),
- ]);
- const Demo = demos.takumi[name];
- if (!Demo) {
- throw new Error(`Unknown Takumi demo: ${name}`);
- }
-
- await initializeTakumi(initialize);
- const { node, stylesheets } = await fromJsx(createElement(Demo));
- const buffer = await render(node, {
- ...getTakumiPreviewOptions(name),
- images,
- stylesheets,
- });
- pdfBytes = new Uint8Array(buffer);
- }
+ await initializeTakumi(initialize);
+ const { node, stylesheets } = await fromJsx(element);
+ const buffer = await render(node, {
+ ...getTakumiPreviewOptions(name),
+ images,
+ stylesheets,
+ });
+ pdfBytes = new Uint8Array(buffer);
} else if (theme) {
const [
{ InvoiceClassicDocument },
diff --git a/components/playground/geometry.ts b/components/playground/geometry.ts
index 53b9d8b..746fbc0 100644
--- a/components/playground/geometry.ts
+++ b/components/playground/geometry.ts
@@ -1,6 +1,16 @@
+import type { PageMarginSide } from "takumi-pdf";
+
const PX_PER_MM = 96 / 25.4;
const PAGE_SIZES = {
+ a3: { height: 420 * PX_PER_MM, width: 297 * PX_PER_MM },
a4: { height: 297 * PX_PER_MM, width: 210 * PX_PER_MM },
+ a5: { height: 210 * PX_PER_MM, width: 148 * PX_PER_MM },
+ b4: { height: 353 * PX_PER_MM, width: 250 * PX_PER_MM },
+ b5: { height: 250 * PX_PER_MM, width: 176 * PX_PER_MM },
+ "jis-b4": { height: 364 * PX_PER_MM, width: 257 * PX_PER_MM },
+ "jis-b5": { height: 257 * PX_PER_MM, width: 182 * PX_PER_MM },
+ ledger: { height: 17 * 96, width: 11 * 96 },
+ legal: { height: 14 * 96, width: 8.5 * 96 },
letter: { height: 11 * 96, width: 8.5 * 96 },
};
const DEFAULT_PAGE_MARGIN = 48;
@@ -14,15 +24,20 @@ export interface OutputGeometry {
label: string;
}
+// An auto margin is the height of a band the renderer measures, which this HTML
+// preview cannot know, so it stands in the default.
+const sidePadding = (side: PageMarginSide): number =>
+ side === "auto" ? DEFAULT_PAGE_MARGIN : side;
+
const marginPadding = (margin: PdfOptions["margin"]): string => {
- if (margin === undefined) {
+ if (margin === undefined || margin === "auto") {
return `${DEFAULT_PAGE_MARGIN}px`;
}
if (typeof margin === "number") {
return `${margin}px`;
}
const { top = 0, right = 0, bottom = 0, left = 0 } = margin;
- return `${top}px ${right}px ${bottom}px ${left}px`;
+ return `${sidePadding(top)}px ${sidePadding(right)}px ${sidePadding(bottom)}px ${sidePadding(left)}px`;
};
const pdfGeometry = (pdf: PdfOptions): OutputGeometry => {
diff --git a/components/playground/worker.ts b/components/playground/worker.ts
index bd284db..079feab 100644
--- a/components/playground/worker.ts
+++ b/components/playground/worker.ts
@@ -1,7 +1,8 @@
import type * as React from "react";
import { renderToStaticMarkup } from "react-dom/server";
-import initPdf, { render } from "takumi-pdf";
-import type { PageSize } from "takumi-pdf";
+import initPdf, { render } from "takumi-pdf/no-init";
+import type { PageSize } from "takumi-pdf/no-init";
+import wasmUrl from "takumi-pdf/wasm-url";
import { evaluateCodeExports, renderReact } from "./evaluate";
import { outputGeometry } from "./geometry";
@@ -12,10 +13,6 @@ import type { RenderMessageInput } from "./schema";
const postMessage = (message: RenderMessageInput, transfer?: Transferable[]) =>
self.postMessage(message, { transfer });
-const TAKUMI_WASM_URL = new URL(
- "/takumi_pdf_wasm_bg.wasm",
- self.location.origin
-);
const PREVIEW_LOGO_PATH = "/favicon.png";
let imagesReady:
@@ -46,7 +43,7 @@ const getImages = () => {
};
const initWasm = async () => {
- wasmReady ??= initPdf({ module_or_path: TAKUMI_WASM_URL });
+ wasmReady ??= initPdf({ module_or_path: wasmUrl });
await wasmReady;
};
diff --git a/examples/preview-config.ts b/examples/preview-config.tsx
similarity index 61%
rename from examples/preview-config.ts
rename to examples/preview-config.tsx
index bbddc1c..ef7ee0b 100644
--- a/examples/preview-config.ts
+++ b/examples/preview-config.tsx
@@ -1,5 +1,8 @@
import type { RenderOptions } from "takumi-pdf";
+import { PageFooter } from "@/registry/bases/takumi/components/page-footer/page-footer";
+import { PdfPageNumber } from "@/registry/bases/takumi/components/page-number/page-number";
+import { PdfcnThemeProvider } from "@/registry/bases/takumi/components/theme-provider";
import { pointToCssPixel } from "@/registry/bases/takumi/lib/pdf-primitives";
const DEFAULT_MARGIN = 40;
@@ -29,6 +32,26 @@ const COMPONENT_MARGINS: Record<string, number> = {
text: 30,
};
+const REPORT_NAMES = new Set([
+ "report-financial",
+ "report-marketing",
+ "report-operations",
+ "report-security",
+]);
+
+// A footer repeats on every page as a render option, which is also what lets the
+// page counter count.
+const reportFooter = (
+ <PdfcnThemeProvider>
+ <PageFooter
+ centerText="Generated with pdfcn"
+ leftText="Confidential — Internal Use"
+ rightText={<PdfPageNumber size="xs" />}
+ variant="three-column"
+ />
+ </PdfcnThemeProvider>
+);
+
const COMPONENT_SIZES: Record<
string,
Extract<RenderOptions, { viewport?: never }>["size"]
@@ -50,6 +73,7 @@ export const getTakumiPreviewOptions = (name: string): RenderOptions => {
: pointToCssPixel(COMPONENT_MARGINS[name] ?? DEFAULT_MARGIN);
return {
+ footer: REPORT_NAMES.has(name) ? reportFooter : undefined,
margin: { bottom: margin, left: margin, right: margin, top: margin },
size: COMPONENT_SIZES[name] ?? "a4",
};
diff --git a/next.config.mjs b/next.config.mjs
index 64ee84d..02edc9a 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -55,17 +55,9 @@ const nextConfig = {
];
},
serverExternalPackages: [
- "takumi-pdf",
"@formepdf/core",
"@takumi-rs/helpers",
],
- turbopack: {
- rules: {
- "*.wasm": {
- type: "wasm",
- },
- },
- },
};
const withMDX = createMDX({});
diff --git a/package.json b/package.json
index 8d8a275..f00d99a 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,7 @@
"@formepdf/core": "^0.10.5",
"@formepdf/react": "^0.10.5",
"@tailwindcss/postcss": "^4.2.4",
- "@takumi-rs/helpers": "^2.5.11",
+ "@takumi-rs/helpers": "^2.9.0",
"@vercel/analytics": "^2.0.1",
"@web-kits/audio": "^0.1.0",
"class-variance-authority": "^0.7.1",
@@ -45,7 +45,7 @@
"sonner": "^2.0.7",
"sucrase": "^3.35.1",
"tailwind-merge": "^3.5.0",
- "takumi-pdf": "^0.4.1",
+ "takumi-pdf": "^0.9.0",
"ts-morph": "^26.0.0",
"vaul": "^1.1.2",
"web-haptics": "^0.0.6",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 758a6a6..9c96279 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -18,8 +18,8 @@ importers:
specifier: ^4.2.4
version: 4.2.4
'@takumi-rs/helpers':
- specifier: ^2.5.11
- version: 2.5.11([email protected])
+ specifier: ^2.9.0
+ version: 2.9.0([email protected])
'@vercel/analytics':
specifier: ^2.0.1
@@ -102,8 +102,8 @@ importers:
specifier: ^3.5.0
version: 3.5.0
takumi-pdf:
- specifier: ^0.4.1
- version: 0.4.1([email protected])
+ specifier: ^0.9.0
+ version: 0.9.0([email protected])
ts-morph:
specifier: ^26.0.0
version: 26.0.0
@@ -2161,8 +2161,8 @@ packages:
'@tailwindcss/[email protected]':
resolution: {integrity: sha512-wgAVj6nUWAolAu8YFvzT2cTBIElWHkjZwFYovF+xsqKsW2ADxM/X2opxj5NsF/qVccAOjRNe8X2IdPzMsWyHTg==}
- '@takumi-rs/[email protected]':
- resolution: {integrity: sha512-J6Fl3QMDfV/zKdiTUzJ16VJSUX778imyoVkU90uoqe0Fc9lK1/DVCmTpXq87jTjnkokAb9w2Y1hCT1XnyxqnAg==}
+ '@takumi-rs/[email protected]':
+ resolution: {integrity: sha512-hlt0W0nILorfAnLA3HtsaFHR2L7IFHpZBeVc3TE6W991f1E/TozvCMj6gLxcmR4pBTYAaFypvlaRDvBYRiMpaQ==}
engines: {node: '>=18'}
peerDependencies:
preact: ^10.0.0
@@ -2228,6 +2228,7 @@ packages:
resolution: {integrity: sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g==}
+ deprecated: Potential CWE-502 - Update to 1.3.1 or higher
'@vercel/[email protected]':
resolution: {integrity: sha512-MTQG6V9qQrt1tsDeF+2Uoo5aPjqbVPys1xvnIftXSJYG2SrwXRHnqEvVoYID7BTruDz4lCd2Z7rM1BdkUehk2g==}
@@ -4286,8 +4287,8 @@ packages:
resolution: {integrity: sha512-HhKppgO81FQof5m6TEnuBWCZGgfRAWbaeOaGT00KOy/Pf/j6oUihdvBpA7ltCeAvZpFhW3j0PTclkxsd4IXYDA==}
- resolution: {integrity: sha512-gYGZOUVRsI490cwC0WCNfFU5lGaZhWyr5i7udB6D7MrHwb3CzECbg40ECpieyKP3TBaVKC6lQwsg5UUJDsDSZw==}
+ resolution: {integrity: sha512-A/U1XNiaomRmK3NQCDZzF/3e/lBBYjMzQBr/QDRowF0Jc3epjeo7qisIxrKbpvHxojn3TqZKvsv55Cpk/cKOqQ==}
engines: {node: '>=18'}
peerDependencies:
react: ^18.0.0 || ^19.0.0
@@ -6368,7 +6369,7 @@ snapshots:
postcss: 8.5.10
tailwindcss: 4.2.4
optionalDependencies:
react: 19.2.5
@@ -8879,9 +8880,9 @@ snapshots:
dependencies:
- '@takumi-rs/helpers': 2.5.11([email protected])
+ '@takumi-rs/helpers': 2.9.0([email protected])
optionalDependencies:
react: 19.2.5
transitivePeerDependencies:
diff --git a/registry/bases/takumi/blocks/report-financial/report-layout.tsx b/registry/bases/takumi/blocks/report-financial/report-layout.tsx
index 5040f6f..8816057 100644
--- a/registry/bases/takumi/blocks/report-financial/report-layout.tsx
+++ b/registry/bases/takumi/blocks/report-financial/report-layout.tsx
@@ -3,7 +3,6 @@ import { DataTable } from "@/registry/bases/takumi/components/data-table/data-ta
import { PdfGraph } from "@/registry/bases/takumi/components/graph/graph";
import { KeyValue } from "@/registry/bases/takumi/components/key-value/key-value";
import { PdfList } from "@/registry/bases/takumi/components/list/list";
-import { PageFooter } from "@/registry/bases/takumi/components/page-footer/page-footer";
import { PageHeader } from "@/registry/bases/takumi/components/page-header/page-header";
import { Section } from "@/registry/bases/takumi/components/section/section";
import { Text } from "@/registry/bases/takumi/components/text/text";
@@ -226,15 +225,6 @@ export const ReportLayout = ({
))}
</View>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
<Page size="A4" style={[styles.page, styles.pageBreak]}>
@@ -318,15 +308,6 @@ export const ReportLayout = ({
}}
/>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
<Page size="A4" style={styles.page}>
@@ -370,15 +351,6 @@ export const ReportLayout = ({
</View>
</View>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
</Document>
);
diff --git a/registry/bases/takumi/blocks/report-marketing/report-layout.tsx b/registry/bases/takumi/blocks/report-marketing/report-layout.tsx
index 5040f6f..8816057 100644
--- a/registry/bases/takumi/blocks/report-marketing/report-layout.tsx
+++ b/registry/bases/takumi/blocks/report-marketing/report-layout.tsx
@@ -3,7 +3,6 @@ import { DataTable } from "@/registry/bases/takumi/components/data-table/data-ta
import { PdfGraph } from "@/registry/bases/takumi/components/graph/graph";
import { KeyValue } from "@/registry/bases/takumi/components/key-value/key-value";
import { PdfList } from "@/registry/bases/takumi/components/list/list";
-import { PageFooter } from "@/registry/bases/takumi/components/page-footer/page-footer";
import { PageHeader } from "@/registry/bases/takumi/components/page-header/page-header";
import { Section } from "@/registry/bases/takumi/components/section/section";
import { Text } from "@/registry/bases/takumi/components/text/text";
@@ -226,15 +225,6 @@ export const ReportLayout = ({
))}
</View>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
<Page size="A4" style={[styles.page, styles.pageBreak]}>
@@ -318,15 +308,6 @@ export const ReportLayout = ({
}}
/>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
<Page size="A4" style={styles.page}>
@@ -370,15 +351,6 @@ export const ReportLayout = ({
</View>
</View>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
</Document>
);
diff --git a/registry/bases/takumi/blocks/report-operations/report-layout.tsx b/registry/bases/takumi/blocks/report-operations/report-layout.tsx
index 5040f6f..8816057 100644
--- a/registry/bases/takumi/blocks/report-operations/report-layout.tsx
+++ b/registry/bases/takumi/blocks/report-operations/report-layout.tsx
@@ -3,7 +3,6 @@ import { DataTable } from "@/registry/bases/takumi/components/data-table/data-ta
import { PdfGraph } from "@/registry/bases/takumi/components/graph/graph";
import { KeyValue } from "@/registry/bases/takumi/components/key-value/key-value";
import { PdfList } from "@/registry/bases/takumi/components/list/list";
-import { PageFooter } from "@/registry/bases/takumi/components/page-footer/page-footer";
import { PageHeader } from "@/registry/bases/takumi/components/page-header/page-header";
import { Section } from "@/registry/bases/takumi/components/section/section";
import { Text } from "@/registry/bases/takumi/components/text/text";
@@ -226,15 +225,6 @@ export const ReportLayout = ({
))}
</View>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
<Page size="A4" style={[styles.page, styles.pageBreak]}>
@@ -318,15 +308,6 @@ export const ReportLayout = ({
}}
/>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
<Page size="A4" style={styles.page}>
@@ -370,15 +351,6 @@ export const ReportLayout = ({
</View>
</View>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
</Document>
);
diff --git a/registry/bases/takumi/blocks/report-security/report-layout.tsx b/registry/bases/takumi/blocks/report-security/report-layout.tsx
index 5040f6f..8816057 100644
--- a/registry/bases/takumi/blocks/report-security/report-layout.tsx
+++ b/registry/bases/takumi/blocks/report-security/report-layout.tsx
@@ -3,7 +3,6 @@ import { DataTable } from "@/registry/bases/takumi/components/data-table/data-ta
import { PdfGraph } from "@/registry/bases/takumi/components/graph/graph";
import { KeyValue } from "@/registry/bases/takumi/components/key-value/key-value";
import { PdfList } from "@/registry/bases/takumi/components/list/list";
-import { PageFooter } from "@/registry/bases/takumi/components/page-footer/page-footer";
import { PageHeader } from "@/registry/bases/takumi/components/page-header/page-header";
import { Section } from "@/registry/bases/takumi/components/section/section";
import { Text } from "@/registry/bases/takumi/components/text/text";
@@ -226,15 +225,6 @@ export const ReportLayout = ({
))}
</View>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
<Page size="A4" style={[styles.page, styles.pageBreak]}>
@@ -318,15 +308,6 @@ export const ReportLayout = ({
}}
/>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
<Page size="A4" style={styles.page}>
@@ -370,15 +351,6 @@ export const ReportLayout = ({
</View>
</View>
</Section>
-
- <PageFooter
- variant="three-column"
- leftText="Confidential — Internal Use"
- centerText="Generated with pdfcn"
- rightText="Page 1 of 1"
- sticky
- pagePadding={theme.spacing.page.marginLeft}
- />
</Page>
</Document>
);
diff --git a/registry/bases/takumi/components/page-footer/page-footer.tsx b/registry/bases/takumi/components/page-footer/page-footer.tsx
index 81ec77d..97e98d5 100644
--- a/registry/bases/takumi/components/page-footer/page-footer.tsx
+++ b/registry/bases/takumi/components/page-footer/page-footer.tsx
@@ -1,3 +1,5 @@
+import type { ReactNode } from "react";
+
import {
usePdfcnTheme,
useSafeMemo,
@@ -26,9 +28,9 @@ export type PageFooterVariant =
* @see {@link PageFooterProps}
*/
export interface PageFooterProps extends Omit<PDFComponentProps, "children"> {
- leftText?: string;
- rightText?: string;
- centerText?: string;
+ leftText?: ReactNode;
+ rightText?: ReactNode;
+ centerText?: ReactNode;
/**
* @default 'simple'
*/
@@ -237,8 +239,8 @@ const renderBranded = (
containerStyles: Style[],
leftStyle: Style[],
rightStyle: Style[],
- leftText: string | undefined,
- rightText: string | undefined,
+ leftText: ReactNode,
+ rightText: ReactNode,
noWrap: boolean
) => (
<View wrap={!noWrap} style={containerStyles}>
@@ -251,8 +253,8 @@ const renderCentered = (
styles: Styles,
containerStyles: Style[],
textStyle: Style[],
- leftText: string | undefined,
- rightText: string | undefined,
+ leftText: ReactNode,
+ rightText: ReactNode,
noWrap: boolean
) => (
<View wrap={!noWrap} style={containerStyles}>
@@ -267,8 +269,8 @@ const renderThreeColumn = (
leftStyle: Style[],
centerStyle: Style[],
rightStyle: Style[],
- leftText: string | undefined,
- rightText: string | undefined,
+ leftText: ReactNode,
+ rightText: ReactNode,
address: string | undefined,
phone: string | undefined,
email: string | undefined,
@@ -298,8 +300,8 @@ const renderDetailed = (
addrStyle: Style[],
contactStyle: Style[],
pageNumStyle: Style[],
- leftText: string | undefined,
- rightText: string | undefined,
+ leftText: ReactNode,
+ rightText: ReactNode,
address: string | undefined,
phone: string | undefined,
email: string | undefined,
@@ -327,8 +329,8 @@ const renderMinimal = (
containerStyles: Style[],
leftStyle: Style[],
rightStyle: Style[],
- leftText: string | undefined,
- rightText: string | undefined,
+ leftText: ReactNode,
+ rightText: ReactNode,
noWrap: boolean
) => (
<View wrap={!noWrap} style={containerStyles}>
@@ -343,9 +345,9 @@ const renderSimple = (
leftStyle: Style[],
centerStyle: Style[],
rightStyle: Style[],
- leftText: string | undefined,
- centerText: string | undefined,
- rightText: string | undefined,
+ leftText: ReactNode,
+ centerText: ReactNode,
+ rightText: ReactNode,
noWrap: boolean
) => (
<View wrap={!noWrap} style={containerStyles}>
diff --git a/registry/bases/takumi/components/watermark/watermark.tsx b/registry/bases/takumi/components/watermark/watermark.tsx
index 64ea525..7313cb5 100644
--- a/registry/bases/takumi/components/watermark/watermark.tsx
+++ b/registry/bases/takumi/components/watermark/watermark.tsx
@@ -20,8 +20,8 @@ export type WatermarkPosition =
| "bottom-right";
/**
- * Diagonal watermark overlaid across the full page using absolute positioning.
- * Props - `text` | `opacity` | `fontSize` | `color` | `angle` | `position` | `fixed` | `style`
+ * Diagonal watermark overlaid across the full page, repeated on every page.
+ * Props - `text` | `opacity` | `fontSize` | `color` | `angle` | `position` | `style`
* @see {@link PdfWatermarkProps}
*/
export interface PdfWatermarkProps extends Omit<PDFComponentProps, "children"> {
@@ -31,10 +31,6 @@ export interface PdfWatermarkProps extends Omit<PDFComponentProps, "children"> {
color?: string;
angle?: number;
position?: WatermarkPosition;
- /**
- * @default true
- */
- fixed?: boolean;
children?: never;
}
@@ -49,7 +45,7 @@ const createWatermarkStyles = (t: PdfcnTheme) => {
justifyContent: "center",
left: 0,
pointerEvents: "none",
- position: "absolute",
+ position: "fixed",
right: 0,
top: 0,
zIndex: -1,
diff --git a/registry/bases/takumi/lib/pdf-primitives.tsx b/registry/bases/takumi/lib/pdf-primitives.tsx
index 609e41c..6742bce 100644
--- a/registry/bases/takumi/lib/pdf-primitives.tsx
+++ b/registry/bases/takumi/lib/pdf-primitives.tsx
@@ -167,8 +167,8 @@ const flatten = (style?: StyleInput): Record<string, unknown> | undefined => {
export const View = ({ children, style, className, ...rest }: ViewProps) => {
const {
- wrap: _w,
- fixed: _f,
+ wrap,
+ fixed,
break: br,
minPresenceAhead: _m,
...dom
@@ -181,6 +181,12 @@ export const View = ({ children, style, className, ...rest }: ViewProps) => {
if (br) {
Object.assign(merged, { breakBefore: "page" });
}
+ if (wrap === false) {
+ Object.assign(merged, { breakInside: "avoid" });
+ }
+ if (fixed) {
+ Object.assign(merged, { position: "fixed" });
+ }
return (
<div
className={className}
diff --git a/registry/bases/takumi/lib/pdf-svg.tsx b/registry/bases/takumi/lib/pdf-svg.tsx
index fdb841c..aea8a85 100644
--- a/registry/bases/takumi/lib/pdf-svg.tsx
+++ b/registry/bases/takumi/lib/pdf-svg.tsx
@@ -1,4 +1,3 @@
-import { Children, Fragment, cloneElement, isValidElement } from "react";
import type { CSSProperties, ReactNode, SVGProps } from "react";
import {
@@ -6,38 +5,6 @@ import {
pointToCssPixel,
} from "@/registry/bases/takumi/lib/pdf-primitives";
-type SvgChildProps = Record<string, unknown> & {
- children?: ReactNode;
-};
-
-const resolveSvgChildren = (children: ReactNode): ReactNode =>
- Children.map(children, (child) => {
- if (!isValidElement<SvgChildProps>(child)) {
- return child;
- }
-
- if (typeof child.type === "function") {
- const resolved = (child.type as (props: SvgChildProps) => ReactNode)(
- child.props
- );
- return resolveSvgChildren(resolved);
- }
-
- if ((child.type as unknown) === Fragment) {
- return resolveSvgChildren(child.props.children);
- }
-
- if (child.props.children === undefined) {
- return child;
- }
-
- return cloneElement(
- child,
- undefined,
- resolveSvgChildren(child.props.children)
- );
- });
-
export const Svg = ({
children,
style,
@@ -70,7 +37,7 @@ export const Svg = ({
width={numericWidth === undefined ? width : pointToCssPixel(numericWidth)}
{...rest}
>
- {resolveSvgChildren(children)}
+ {children}
</svg>
);
};