paginate-pdf 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/chunk-HBSLYOBE.js +301 -0
- package/dist/chunk-HBSLYOBE.js.map +1 -0
- package/dist/chunk-IE5QDJFU.js +104 -0
- package/dist/chunk-IE5QDJFU.js.map +1 -0
- package/dist/index.cjs +427 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +461 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +14 -0
- package/dist/react.d.ts +14 -0
- package/dist/react.js +40 -0
- package/dist/react.js.map +1 -0
- package/dist/testing.cjs +132 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +7 -0
- package/dist/testing.d.ts +7 -0
- package/dist/testing.js +11 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-DGaknP5f.d.cts +82 -0
- package/dist/types-DGaknP5f.d.ts +82 -0
- package/package.json +78 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
paginatePdf: () => paginatePdf
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_html2canvas_pro = __toESM(require("html2canvas-pro"), 1);
|
|
37
|
+
var import_jspdf = require("jspdf");
|
|
38
|
+
|
|
39
|
+
// src/block-tree.ts
|
|
40
|
+
function isRenderable(element) {
|
|
41
|
+
if (!(element instanceof HTMLElement)) return false;
|
|
42
|
+
const styles = window.getComputedStyle(element);
|
|
43
|
+
return styles.display !== "none" && styles.visibility !== "hidden";
|
|
44
|
+
}
|
|
45
|
+
function collectBlockTree(root, shouldAvoidBreak) {
|
|
46
|
+
const rootTop = root.getBoundingClientRect().top;
|
|
47
|
+
function build(element) {
|
|
48
|
+
if (!isRenderable(element)) return null;
|
|
49
|
+
const rect = element.getBoundingClientRect();
|
|
50
|
+
if (rect.height <= 0) return null;
|
|
51
|
+
const node = {
|
|
52
|
+
top: rect.top - rootTop,
|
|
53
|
+
bottom: rect.bottom - rootTop
|
|
54
|
+
};
|
|
55
|
+
if (shouldAvoidBreak(element) || element.tagName === "TR") {
|
|
56
|
+
return { ...node, children: [], splittable: false };
|
|
57
|
+
}
|
|
58
|
+
const children = Array.from(element.children).map(build).filter((child) => child !== null);
|
|
59
|
+
return { ...node, children, splittable: children.length > 0 };
|
|
60
|
+
}
|
|
61
|
+
return Array.from(root.children).map(build).filter((child) => child !== null);
|
|
62
|
+
}
|
|
63
|
+
function collectTables(root) {
|
|
64
|
+
const rootTop = root.getBoundingClientRect().top;
|
|
65
|
+
const tables = [];
|
|
66
|
+
root.querySelectorAll("table").forEach((table) => {
|
|
67
|
+
const thead = table.querySelector(":scope > thead");
|
|
68
|
+
if (!thead || !isRenderable(thead)) return;
|
|
69
|
+
const tableRect = table.getBoundingClientRect();
|
|
70
|
+
const theadRect = thead.getBoundingClientRect();
|
|
71
|
+
if (tableRect.height <= 0 || theadRect.height <= 0) return;
|
|
72
|
+
tables.push({
|
|
73
|
+
top: tableRect.top - rootTop,
|
|
74
|
+
bottom: tableRect.bottom - rootTop,
|
|
75
|
+
theadTop: theadRect.top - rootTop,
|
|
76
|
+
theadBottom: theadRect.bottom - rootTop
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
return tables;
|
|
80
|
+
}
|
|
81
|
+
function findBreak(nodes, start, limit, minLead, minTail) {
|
|
82
|
+
let best = start;
|
|
83
|
+
for (const node of nodes) {
|
|
84
|
+
if (node.bottom <= start) continue;
|
|
85
|
+
if (node.top >= limit) break;
|
|
86
|
+
if (node.bottom <= limit) {
|
|
87
|
+
best = node.bottom;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (node.splittable) {
|
|
91
|
+
const inner = findBreak(node.children, start, limit, minLead, minTail);
|
|
92
|
+
const keptHere = inner - node.top;
|
|
93
|
+
const carriedOver = node.bottom - inner;
|
|
94
|
+
if (inner > best && keptHere >= minLead && carriedOver >= minTail) {
|
|
95
|
+
return inner;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (node.top > best) best = node.top;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
return best;
|
|
102
|
+
}
|
|
103
|
+
function findHeaderReserve(start, tables) {
|
|
104
|
+
for (const table of tables) {
|
|
105
|
+
const bodyStart = table.theadBottom;
|
|
106
|
+
if (start > bodyStart && start < table.bottom) {
|
|
107
|
+
return {
|
|
108
|
+
heightPx: table.theadBottom - table.theadTop,
|
|
109
|
+
header: { top: table.theadTop, bottom: table.theadBottom }
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
function computePageSlices(tree, contentHeightPx, totalHeightPx, minSplitLeadRatio, minSplitTailRatio, tables = []) {
|
|
116
|
+
if (contentHeightPx <= 0 || totalHeightPx <= 0) return [];
|
|
117
|
+
const minLead = contentHeightPx * minSplitLeadRatio;
|
|
118
|
+
const minTail = contentHeightPx * minSplitTailRatio;
|
|
119
|
+
const slices = [];
|
|
120
|
+
let start = 0;
|
|
121
|
+
while (start < totalHeightPx) {
|
|
122
|
+
const reserve = findHeaderReserve(start, tables);
|
|
123
|
+
const usableHeight = contentHeightPx - (reserve?.heightPx ?? 0);
|
|
124
|
+
const limit = start + usableHeight;
|
|
125
|
+
if (limit >= totalHeightPx) {
|
|
126
|
+
slices.push({ start, end: totalHeightPx, header: reserve?.header });
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
let end = findBreak(tree, start, limit, minLead, minTail);
|
|
130
|
+
if (end <= start) end = limit;
|
|
131
|
+
slices.push({ start, end, header: reserve?.header });
|
|
132
|
+
start = end;
|
|
133
|
+
}
|
|
134
|
+
return slices;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/capture.ts
|
|
138
|
+
var PAGE_FORMATS_MM = {
|
|
139
|
+
a4: [210, 297],
|
|
140
|
+
letter: [215.9, 279.4],
|
|
141
|
+
legal: [215.9, 355.6]
|
|
142
|
+
};
|
|
143
|
+
function resolvePageFormatMm(format) {
|
|
144
|
+
return Array.isArray(format) ? format : PAGE_FORMATS_MM[format];
|
|
145
|
+
}
|
|
146
|
+
async function waitForFonts() {
|
|
147
|
+
if (typeof document === "undefined" || !document.fonts) return;
|
|
148
|
+
try {
|
|
149
|
+
await document.fonts.ready;
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function waitForImages(root) {
|
|
154
|
+
const pending = Array.from(root.querySelectorAll("img")).map(
|
|
155
|
+
async (image) => {
|
|
156
|
+
if (image.complete && image.naturalWidth > 0) return;
|
|
157
|
+
await new Promise((resolve) => {
|
|
158
|
+
image.addEventListener("load", () => resolve(), { once: true });
|
|
159
|
+
image.addEventListener("error", () => resolve(), { once: true });
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
await Promise.all(pending);
|
|
164
|
+
}
|
|
165
|
+
function readAsDataUrl(blob) {
|
|
166
|
+
return new Promise((resolve, reject) => {
|
|
167
|
+
const reader = new FileReader();
|
|
168
|
+
reader.onload = () => resolve(String(reader.result));
|
|
169
|
+
reader.onerror = () => reject(reader.error);
|
|
170
|
+
reader.readAsDataURL(blob);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
async function inlineImageSources(root) {
|
|
174
|
+
const sources = Array.from(root.querySelectorAll("img")).map((image) => image.getAttribute("src")).filter((source) => Boolean(source)).filter((source) => !source.startsWith("data:"));
|
|
175
|
+
const uniqueSources = Array.from(new Set(sources));
|
|
176
|
+
const entries = await Promise.all(
|
|
177
|
+
uniqueSources.map(async (source) => {
|
|
178
|
+
try {
|
|
179
|
+
const response = await fetch(source, {
|
|
180
|
+
mode: "cors",
|
|
181
|
+
credentials: "omit"
|
|
182
|
+
});
|
|
183
|
+
if (!response.ok) return null;
|
|
184
|
+
return [source, await readAsDataUrl(await response.blob())];
|
|
185
|
+
} catch {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
return new Map(
|
|
191
|
+
entries.filter((entry) => entry !== null)
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
function resolveCaptureScale(preferredScale, widthPx, heightPx, maxCanvasDimension) {
|
|
195
|
+
const scale = Math.min(
|
|
196
|
+
preferredScale,
|
|
197
|
+
maxCanvasDimension / Math.max(widthPx, 1),
|
|
198
|
+
maxCanvasDimension / Math.max(heightPx, 1)
|
|
199
|
+
);
|
|
200
|
+
return Math.max(scale, 1);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/index.ts
|
|
204
|
+
var DEFAULT_AVOID_BREAK_ATTRIBUTE = "data-pdf-avoid-break";
|
|
205
|
+
function cropToDataUrl(source, range, canvasScale, background, imageQuality) {
|
|
206
|
+
const heightPx = Math.max(
|
|
207
|
+
Math.round((range.end - range.start) * canvasScale),
|
|
208
|
+
1
|
|
209
|
+
);
|
|
210
|
+
const page = document.createElement("canvas");
|
|
211
|
+
page.width = source.width;
|
|
212
|
+
page.height = heightPx;
|
|
213
|
+
const context = page.getContext("2d");
|
|
214
|
+
if (!context) return null;
|
|
215
|
+
context.fillStyle = background;
|
|
216
|
+
context.fillRect(0, 0, page.width, page.height);
|
|
217
|
+
context.drawImage(
|
|
218
|
+
source,
|
|
219
|
+
0,
|
|
220
|
+
Math.round(range.start * canvasScale),
|
|
221
|
+
source.width,
|
|
222
|
+
heightPx,
|
|
223
|
+
0,
|
|
224
|
+
0,
|
|
225
|
+
source.width,
|
|
226
|
+
heightPx
|
|
227
|
+
);
|
|
228
|
+
return page.toDataURL("image/jpeg", imageQuality);
|
|
229
|
+
}
|
|
230
|
+
function resolvePageNumberOptions(option) {
|
|
231
|
+
if (!option) return null;
|
|
232
|
+
const withDefaults = option === true ? {} : option;
|
|
233
|
+
return {
|
|
234
|
+
format: withDefaults.format ?? ((page, total) => `${page} / ${total}`),
|
|
235
|
+
position: withDefaults.position ?? "bottom-center",
|
|
236
|
+
fontSize: withDefaults.fontSize ?? 8,
|
|
237
|
+
color: withDefaults.color ?? "#828282"
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function stampPageNumbers(pdf, totalPages, marginMm, pageNumberOptions) {
|
|
241
|
+
if (totalPages < 2) return;
|
|
242
|
+
const pageWidth = pdf.internal.pageSize.getWidth();
|
|
243
|
+
const pageHeight = pdf.internal.pageSize.getHeight();
|
|
244
|
+
const y = pageHeight - marginMm / 2;
|
|
245
|
+
const x = pageNumberOptions.position === "bottom-left" ? marginMm : pageNumberOptions.position === "bottom-right" ? pageWidth - marginMm : pageWidth / 2;
|
|
246
|
+
const align = pageNumberOptions.position === "bottom-left" ? "left" : pageNumberOptions.position === "bottom-right" ? "right" : "center";
|
|
247
|
+
for (let page = 1; page <= totalPages; page += 1) {
|
|
248
|
+
pdf.setPage(page);
|
|
249
|
+
pdf.setFontSize(pageNumberOptions.fontSize);
|
|
250
|
+
pdf.setTextColor(pageNumberOptions.color);
|
|
251
|
+
pdf.text(pageNumberOptions.format(page, totalPages), x, y, { align });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async function paginatePdf(element, options = {}) {
|
|
255
|
+
const {
|
|
256
|
+
filename = "document.pdf",
|
|
257
|
+
format = "a4",
|
|
258
|
+
marginMm = 16,
|
|
259
|
+
scale: preferredScale = 2,
|
|
260
|
+
maxCanvasDimension = 16384,
|
|
261
|
+
imageQuality = 0.92,
|
|
262
|
+
background = "#ffffff",
|
|
263
|
+
border,
|
|
264
|
+
pageNumbers,
|
|
265
|
+
metadata,
|
|
266
|
+
repeatTableHeaders = true,
|
|
267
|
+
avoidBreakAttribute = DEFAULT_AVOID_BREAK_ATTRIBUTE,
|
|
268
|
+
minSplitLeadRatio = 0.08,
|
|
269
|
+
minSplitTailRatio = 0.02,
|
|
270
|
+
inlineCrossOriginImages = true,
|
|
271
|
+
waitForFonts: shouldWaitForFonts = true,
|
|
272
|
+
waitForImages: shouldWaitForImages = true,
|
|
273
|
+
save = true,
|
|
274
|
+
onProgress,
|
|
275
|
+
beforeCapture,
|
|
276
|
+
html2canvasOptions = {}
|
|
277
|
+
} = options;
|
|
278
|
+
onProgress?.({ phase: "preparing" });
|
|
279
|
+
await Promise.all([
|
|
280
|
+
shouldWaitForFonts ? waitForFonts() : Promise.resolve(),
|
|
281
|
+
shouldWaitForImages ? waitForImages(element) : Promise.resolve()
|
|
282
|
+
]);
|
|
283
|
+
const inlinedImages = inlineCrossOriginImages ? await inlineImageSources(element) : /* @__PURE__ */ new Map();
|
|
284
|
+
const elementWidth = element.offsetWidth;
|
|
285
|
+
const elementHeight = element.scrollHeight;
|
|
286
|
+
if (!elementWidth || !elementHeight) {
|
|
287
|
+
throw new Error(
|
|
288
|
+
"paginate-pdf: the element has no rendered size \u2014 is it attached to the document and visible?"
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
const scale = resolveCaptureScale(
|
|
292
|
+
preferredScale,
|
|
293
|
+
elementWidth,
|
|
294
|
+
elementHeight,
|
|
295
|
+
maxCanvasDimension
|
|
296
|
+
);
|
|
297
|
+
onProgress?.({ phase: "capturing" });
|
|
298
|
+
const canvas = await (0, import_html2canvas_pro.default)(element, {
|
|
299
|
+
scale,
|
|
300
|
+
useCORS: true,
|
|
301
|
+
backgroundColor: background,
|
|
302
|
+
logging: false,
|
|
303
|
+
...html2canvasOptions,
|
|
304
|
+
onclone: async (clonedDocument, clonedElement) => {
|
|
305
|
+
clonedElement.querySelectorAll("img").forEach((image) => {
|
|
306
|
+
const inlined = inlinedImages.get(image.getAttribute("src") ?? "");
|
|
307
|
+
if (inlined) image.setAttribute("src", inlined);
|
|
308
|
+
image.removeAttribute("srcset");
|
|
309
|
+
image.removeAttribute("loading");
|
|
310
|
+
});
|
|
311
|
+
await beforeCapture?.(clonedDocument, clonedElement);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
onProgress?.({ phase: "paginating" });
|
|
315
|
+
const [pageWidthMm, pageHeightMm] = resolvePageFormatMm(format);
|
|
316
|
+
const contentWidthMm = pageWidthMm - marginMm * 2;
|
|
317
|
+
const contentHeightMm = pageHeightMm - marginMm * 2;
|
|
318
|
+
const pxToMm = contentWidthMm / elementWidth;
|
|
319
|
+
const contentHeightPx = contentHeightMm / pxToMm;
|
|
320
|
+
const tree = collectBlockTree(
|
|
321
|
+
element,
|
|
322
|
+
(candidate) => candidate.hasAttribute(avoidBreakAttribute)
|
|
323
|
+
);
|
|
324
|
+
const tables = repeatTableHeaders ? collectTables(element) : [];
|
|
325
|
+
const slices = computePageSlices(
|
|
326
|
+
tree,
|
|
327
|
+
contentHeightPx,
|
|
328
|
+
elementHeight,
|
|
329
|
+
minSplitLeadRatio,
|
|
330
|
+
minSplitTailRatio,
|
|
331
|
+
tables
|
|
332
|
+
);
|
|
333
|
+
const pdf = new import_jspdf.jsPDF({
|
|
334
|
+
unit: "mm",
|
|
335
|
+
format,
|
|
336
|
+
orientation: "portrait",
|
|
337
|
+
compress: true
|
|
338
|
+
});
|
|
339
|
+
if (metadata) {
|
|
340
|
+
pdf.setProperties({
|
|
341
|
+
title: metadata.title ?? "",
|
|
342
|
+
author: metadata.author ?? "",
|
|
343
|
+
subject: metadata.subject ?? "",
|
|
344
|
+
keywords: metadata.keywords ?? "",
|
|
345
|
+
creator: metadata.creator ?? "paginate-pdf"
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
const canvasScale = canvas.width / elementWidth;
|
|
349
|
+
let hasPage = false;
|
|
350
|
+
if (border) {
|
|
351
|
+
pdf.setDrawColor(border.color);
|
|
352
|
+
pdf.setLineWidth(border.widthMm ?? 0.3);
|
|
353
|
+
}
|
|
354
|
+
slices.forEach((slice, index) => {
|
|
355
|
+
onProgress?.({
|
|
356
|
+
phase: "rendering-page",
|
|
357
|
+
page: index + 1,
|
|
358
|
+
totalPages: slices.length
|
|
359
|
+
});
|
|
360
|
+
if (hasPage) pdf.addPage();
|
|
361
|
+
hasPage = true;
|
|
362
|
+
let bodyStartMm = marginMm;
|
|
363
|
+
const bodyHeightMm = (slice.end - slice.start) * pxToMm;
|
|
364
|
+
if (slice.header) {
|
|
365
|
+
const headerImage = cropToDataUrl(
|
|
366
|
+
canvas,
|
|
367
|
+
{ start: slice.header.top, end: slice.header.bottom },
|
|
368
|
+
canvasScale,
|
|
369
|
+
background,
|
|
370
|
+
imageQuality
|
|
371
|
+
);
|
|
372
|
+
const headerHeightMm = (slice.header.bottom - slice.header.top) * pxToMm;
|
|
373
|
+
if (headerImage) {
|
|
374
|
+
pdf.addImage(
|
|
375
|
+
headerImage,
|
|
376
|
+
"JPEG",
|
|
377
|
+
marginMm,
|
|
378
|
+
marginMm,
|
|
379
|
+
contentWidthMm,
|
|
380
|
+
headerHeightMm
|
|
381
|
+
);
|
|
382
|
+
if (border) {
|
|
383
|
+
pdf.rect(marginMm, marginMm, contentWidthMm, headerHeightMm);
|
|
384
|
+
}
|
|
385
|
+
bodyStartMm = marginMm + headerHeightMm;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const pageImage = cropToDataUrl(
|
|
389
|
+
canvas,
|
|
390
|
+
slice,
|
|
391
|
+
canvasScale,
|
|
392
|
+
background,
|
|
393
|
+
imageQuality
|
|
394
|
+
);
|
|
395
|
+
if (!pageImage) return;
|
|
396
|
+
pdf.addImage(
|
|
397
|
+
pageImage,
|
|
398
|
+
"JPEG",
|
|
399
|
+
marginMm,
|
|
400
|
+
bodyStartMm,
|
|
401
|
+
contentWidthMm,
|
|
402
|
+
bodyHeightMm
|
|
403
|
+
);
|
|
404
|
+
if (border) {
|
|
405
|
+
pdf.rect(marginMm, bodyStartMm, contentWidthMm, bodyHeightMm);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
if (!hasPage) {
|
|
409
|
+
throw new Error("paginate-pdf: nothing was captured \u2014 the element may be empty.");
|
|
410
|
+
}
|
|
411
|
+
const resolvedPageNumbers = resolvePageNumberOptions(pageNumbers);
|
|
412
|
+
if (resolvedPageNumbers) {
|
|
413
|
+
stampPageNumbers(pdf, slices.length, marginMm, resolvedPageNumbers);
|
|
414
|
+
}
|
|
415
|
+
onProgress?.({ phase: "done", totalPages: slices.length });
|
|
416
|
+
if (save) pdf.save(filename);
|
|
417
|
+
return {
|
|
418
|
+
pageCount: slices.length,
|
|
419
|
+
blob: () => pdf.output("blob"),
|
|
420
|
+
save: (name) => pdf.save(name ?? filename)
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
424
|
+
0 && (module.exports = {
|
|
425
|
+
paginatePdf
|
|
426
|
+
});
|
|
427
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/block-tree.ts","../src/capture.ts"],"sourcesContent":["import html2canvas from \"html2canvas-pro\";\nimport { jsPDF } from \"jspdf\";\nimport { collectBlockTree, collectTables, computePageSlices } from \"./block-tree.js\";\nimport {\n inlineImageSources,\n resolveCaptureScale,\n resolvePageFormatMm,\n waitForFonts,\n waitForImages,\n} from \"./capture.js\";\nimport type {\n PageNumberOptions,\n PageSlice,\n PaginatePdfOptions,\n PaginatePdfResult,\n} from \"./types.js\";\n\nconst DEFAULT_AVOID_BREAK_ATTRIBUTE = \"data-pdf-avoid-break\";\n\nfunction cropToDataUrl(\n source: HTMLCanvasElement,\n range: { start: number; end: number },\n canvasScale: number,\n background: string,\n imageQuality: number,\n) {\n const heightPx = Math.max(\n Math.round((range.end - range.start) * canvasScale),\n 1,\n );\n\n const page = document.createElement(\"canvas\");\n page.width = source.width;\n page.height = heightPx;\n\n const context = page.getContext(\"2d\");\n if (!context) return null;\n\n context.fillStyle = background;\n context.fillRect(0, 0, page.width, page.height);\n context.drawImage(\n source,\n 0,\n Math.round(range.start * canvasScale),\n source.width,\n heightPx,\n 0,\n 0,\n source.width,\n heightPx,\n );\n\n return page.toDataURL(\"image/jpeg\", imageQuality);\n}\n\nfunction resolvePageNumberOptions(\n option: boolean | PageNumberOptions | undefined,\n): Required<PageNumberOptions> | null {\n if (!option) return null;\n\n const withDefaults = option === true ? {} : option;\n\n return {\n format: withDefaults.format ?? ((page, total) => `${page} / ${total}`),\n position: withDefaults.position ?? \"bottom-center\",\n fontSize: withDefaults.fontSize ?? 8,\n color: withDefaults.color ?? \"#828282\",\n };\n}\n\nfunction stampPageNumbers(\n pdf: jsPDF,\n totalPages: number,\n marginMm: number,\n pageNumberOptions: Required<PageNumberOptions>,\n) {\n if (totalPages < 2) return;\n\n const pageWidth = pdf.internal.pageSize.getWidth();\n const pageHeight = pdf.internal.pageSize.getHeight();\n const y = pageHeight - marginMm / 2;\n\n const x =\n pageNumberOptions.position === \"bottom-left\"\n ? marginMm\n : pageNumberOptions.position === \"bottom-right\"\n ? pageWidth - marginMm\n : pageWidth / 2;\n\n const align =\n pageNumberOptions.position === \"bottom-left\"\n ? \"left\"\n : pageNumberOptions.position === \"bottom-right\"\n ? \"right\"\n : \"center\";\n\n for (let page = 1; page <= totalPages; page += 1) {\n pdf.setPage(page);\n pdf.setFontSize(pageNumberOptions.fontSize);\n pdf.setTextColor(pageNumberOptions.color);\n pdf.text(pageNumberOptions.format(page, totalPages), x, y, { align });\n }\n}\n\nexport async function paginatePdf(\n element: HTMLElement,\n options: PaginatePdfOptions = {},\n): Promise<PaginatePdfResult> {\n const {\n filename = \"document.pdf\",\n format = \"a4\",\n marginMm = 16,\n scale: preferredScale = 2,\n maxCanvasDimension = 16384,\n imageQuality = 0.92,\n background = \"#ffffff\",\n border,\n pageNumbers,\n metadata,\n repeatTableHeaders = true,\n avoidBreakAttribute = DEFAULT_AVOID_BREAK_ATTRIBUTE,\n minSplitLeadRatio = 0.08,\n minSplitTailRatio = 0.02,\n inlineCrossOriginImages = true,\n waitForFonts: shouldWaitForFonts = true,\n waitForImages: shouldWaitForImages = true,\n save = true,\n onProgress,\n beforeCapture,\n html2canvasOptions = {},\n } = options;\n\n onProgress?.({ phase: \"preparing\" });\n\n await Promise.all([\n shouldWaitForFonts ? waitForFonts() : Promise.resolve(),\n shouldWaitForImages ? waitForImages(element) : Promise.resolve(),\n ]);\n\n const inlinedImages = inlineCrossOriginImages\n ? await inlineImageSources(element)\n : new Map<string, string>();\n\n const elementWidth = element.offsetWidth;\n const elementHeight = element.scrollHeight;\n if (!elementWidth || !elementHeight) {\n throw new Error(\n \"paginate-pdf: the element has no rendered size — is it attached to the document and visible?\",\n );\n }\n\n const scale = resolveCaptureScale(\n preferredScale,\n elementWidth,\n elementHeight,\n maxCanvasDimension,\n );\n\n onProgress?.({ phase: \"capturing\" });\n\n const canvas = await html2canvas(element, {\n scale,\n useCORS: true,\n backgroundColor: background,\n logging: false,\n ...html2canvasOptions,\n onclone: async (clonedDocument: Document, clonedElement: HTMLElement) => {\n clonedElement.querySelectorAll(\"img\").forEach((image) => {\n const inlined = inlinedImages.get(image.getAttribute(\"src\") ?? \"\");\n if (inlined) image.setAttribute(\"src\", inlined);\n\n image.removeAttribute(\"srcset\");\n image.removeAttribute(\"loading\");\n });\n\n await beforeCapture?.(clonedDocument, clonedElement);\n },\n });\n\n onProgress?.({ phase: \"paginating\" });\n\n const [pageWidthMm, pageHeightMm] = resolvePageFormatMm(format);\n const contentWidthMm = pageWidthMm - marginMm * 2;\n const contentHeightMm = pageHeightMm - marginMm * 2;\n const pxToMm = contentWidthMm / elementWidth;\n const contentHeightPx = contentHeightMm / pxToMm;\n\n const tree = collectBlockTree(element, (candidate) =>\n candidate.hasAttribute(avoidBreakAttribute),\n );\n const tables = repeatTableHeaders ? collectTables(element) : [];\n const slices: PageSlice[] = computePageSlices(\n tree,\n contentHeightPx,\n elementHeight,\n minSplitLeadRatio,\n minSplitTailRatio,\n tables,\n );\n\n const pdf = new jsPDF({\n unit: \"mm\",\n format,\n orientation: \"portrait\",\n compress: true,\n });\n\n if (metadata) {\n pdf.setProperties({\n title: metadata.title ?? \"\",\n author: metadata.author ?? \"\",\n subject: metadata.subject ?? \"\",\n keywords: metadata.keywords ?? \"\",\n creator: metadata.creator ?? \"paginate-pdf\",\n });\n }\n\n const canvasScale = canvas.width / elementWidth;\n let hasPage = false;\n\n if (border) {\n pdf.setDrawColor(border.color);\n pdf.setLineWidth(border.widthMm ?? 0.3);\n }\n\n slices.forEach((slice, index) => {\n onProgress?.({\n phase: \"rendering-page\",\n page: index + 1,\n totalPages: slices.length,\n });\n\n if (hasPage) pdf.addPage();\n hasPage = true;\n\n let bodyStartMm = marginMm;\n const bodyHeightMm = (slice.end - slice.start) * pxToMm;\n\n if (slice.header) {\n const headerImage = cropToDataUrl(\n canvas,\n { start: slice.header.top, end: slice.header.bottom },\n canvasScale,\n background,\n imageQuality,\n );\n const headerHeightMm =\n (slice.header.bottom - slice.header.top) * pxToMm;\n\n if (headerImage) {\n pdf.addImage(\n headerImage,\n \"JPEG\",\n marginMm,\n marginMm,\n contentWidthMm,\n headerHeightMm,\n );\n if (border) {\n pdf.rect(marginMm, marginMm, contentWidthMm, headerHeightMm);\n }\n bodyStartMm = marginMm + headerHeightMm;\n }\n }\n\n const pageImage = cropToDataUrl(\n canvas,\n slice,\n canvasScale,\n background,\n imageQuality,\n );\n if (!pageImage) return;\n\n pdf.addImage(\n pageImage,\n \"JPEG\",\n marginMm,\n bodyStartMm,\n contentWidthMm,\n bodyHeightMm,\n );\n\n if (border) {\n pdf.rect(marginMm, bodyStartMm, contentWidthMm, bodyHeightMm);\n }\n });\n\n if (!hasPage) {\n throw new Error(\"paginate-pdf: nothing was captured — the element may be empty.\");\n }\n\n const resolvedPageNumbers = resolvePageNumberOptions(pageNumbers);\n if (resolvedPageNumbers) {\n stampPageNumbers(pdf, slices.length, marginMm, resolvedPageNumbers);\n }\n\n onProgress?.({ phase: \"done\", totalPages: slices.length });\n\n if (save) pdf.save(filename);\n\n return {\n pageCount: slices.length,\n blob: () => pdf.output(\"blob\"),\n save: (name?: string) => pdf.save(name ?? filename),\n };\n}\n\nexport type {\n BorderOptions,\n PageFormat,\n PageNumberOptions,\n PaginatePdfOptions,\n PaginatePdfResult,\n PaginatePdfStage,\n PdfMetadata,\n} from \"./types.js\";\n","import type { BlockNode, PageSlice, TableInfo } from \"./types.js\";\n\nfunction isRenderable(element: Element): element is HTMLElement {\n if (!(element instanceof HTMLElement)) return false;\n\n const styles = window.getComputedStyle(element);\n\n return styles.display !== \"none\" && styles.visibility !== \"hidden\";\n}\n\nexport function collectBlockTree(\n root: HTMLElement,\n shouldAvoidBreak: (element: Element) => boolean,\n): BlockNode[] {\n const rootTop = root.getBoundingClientRect().top;\n\n function build(element: Element): BlockNode | null {\n if (!isRenderable(element)) return null;\n\n const rect = element.getBoundingClientRect();\n if (rect.height <= 0) return null;\n\n const node = {\n top: rect.top - rootTop,\n bottom: rect.bottom - rootTop,\n };\n\n if (\n shouldAvoidBreak(element) ||\n element.tagName === \"TR\"\n ) {\n return { ...node, children: [], splittable: false };\n }\n\n const children = Array.from(element.children)\n .map(build)\n .filter((child): child is BlockNode => child !== null);\n\n return { ...node, children, splittable: children.length > 0 };\n }\n\n return Array.from(root.children)\n .map(build)\n .filter((child): child is BlockNode => child !== null);\n}\n\nexport function collectTables(root: HTMLElement): TableInfo[] {\n const rootTop = root.getBoundingClientRect().top;\n const tables: TableInfo[] = [];\n\n root.querySelectorAll(\"table\").forEach((table) => {\n const thead = table.querySelector(\":scope > thead\");\n if (!thead || !isRenderable(thead)) return;\n\n const tableRect = table.getBoundingClientRect();\n const theadRect = thead.getBoundingClientRect();\n if (tableRect.height <= 0 || theadRect.height <= 0) return;\n\n tables.push({\n top: tableRect.top - rootTop,\n bottom: tableRect.bottom - rootTop,\n theadTop: theadRect.top - rootTop,\n theadBottom: theadRect.bottom - rootTop,\n });\n });\n\n return tables;\n}\n\nfunction findBreak(\n nodes: BlockNode[],\n start: number,\n limit: number,\n minLead: number,\n minTail: number,\n): number {\n let best = start;\n\n for (const node of nodes) {\n if (node.bottom <= start) continue;\n if (node.top >= limit) break;\n\n if (node.bottom <= limit) {\n best = node.bottom;\n continue;\n }\n\n if (node.splittable) {\n const inner = findBreak(node.children, start, limit, minLead, minTail);\n const keptHere = inner - node.top;\n const carriedOver = node.bottom - inner;\n\n if (inner > best && keptHere >= minLead && carriedOver >= minTail) {\n return inner;\n }\n }\n\n if (node.top > best) best = node.top;\n break;\n }\n\n return best;\n}\n\nfunction findHeaderReserve(start: number, tables: TableInfo[]) {\n for (const table of tables) {\n const bodyStart = table.theadBottom;\n if (start > bodyStart && start < table.bottom) {\n return {\n heightPx: table.theadBottom - table.theadTop,\n header: { top: table.theadTop, bottom: table.theadBottom },\n };\n }\n }\n return null;\n}\n\nexport function computePageSlices(\n tree: BlockNode[],\n contentHeightPx: number,\n totalHeightPx: number,\n minSplitLeadRatio: number,\n minSplitTailRatio: number,\n tables: TableInfo[] = [],\n): PageSlice[] {\n if (contentHeightPx <= 0 || totalHeightPx <= 0) return [];\n\n const minLead = contentHeightPx * minSplitLeadRatio;\n const minTail = contentHeightPx * minSplitTailRatio;\n const slices: PageSlice[] = [];\n let start = 0;\n\n while (start < totalHeightPx) {\n const reserve = findHeaderReserve(start, tables);\n const usableHeight = contentHeightPx - (reserve?.heightPx ?? 0);\n const limit = start + usableHeight;\n\n if (limit >= totalHeightPx) {\n slices.push({ start, end: totalHeightPx, header: reserve?.header });\n break;\n }\n\n let end = findBreak(tree, start, limit, minLead, minTail);\n\n if (end <= start) end = limit;\n\n slices.push({ start, end, header: reserve?.header });\n start = end;\n }\n\n return slices;\n}\n","import type { PageFormat } from \"./types.js\";\n\nconst PAGE_FORMATS_MM: Record<Exclude<PageFormat, [number, number]>, [number, number]> = {\n a4: [210, 297],\n letter: [215.9, 279.4],\n legal: [215.9, 355.6],\n};\n\nexport function resolvePageFormatMm(format: PageFormat): [number, number] {\n return Array.isArray(format) ? format : PAGE_FORMATS_MM[format];\n}\n\nexport async function waitForFonts() {\n if (typeof document === \"undefined\" || !document.fonts) return;\n\n try {\n await document.fonts.ready;\n } catch {\n /* empty */\n }\n}\n\nexport async function waitForImages(root: HTMLElement) {\n const pending = Array.from(root.querySelectorAll(\"img\")).map(\n async (image) => {\n if (image.complete && image.naturalWidth > 0) return;\n\n await new Promise<void>((resolve) => {\n image.addEventListener(\"load\", () => resolve(), { once: true });\n image.addEventListener(\"error\", () => resolve(), { once: true });\n });\n },\n );\n\n await Promise.all(pending);\n}\n\nfunction readAsDataUrl(blob: Blob) {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => resolve(String(reader.result));\n reader.onerror = () => reject(reader.error);\n reader.readAsDataURL(blob);\n });\n}\n\nexport async function inlineImageSources(root: HTMLElement) {\n const sources = Array.from(root.querySelectorAll(\"img\"))\n .map((image) => image.getAttribute(\"src\"))\n .filter((source): source is string => Boolean(source))\n .filter((source) => !source.startsWith(\"data:\"));\n\n const uniqueSources = Array.from(new Set(sources));\n\n const entries = await Promise.all(\n uniqueSources.map(async (source) => {\n try {\n const response = await fetch(source, {\n mode: \"cors\",\n credentials: \"omit\",\n });\n if (!response.ok) return null;\n\n return [source, await readAsDataUrl(await response.blob())] as const;\n } catch {\n return null;\n }\n }),\n );\n\n return new Map(\n entries.filter((entry): entry is [string, string] => entry !== null),\n );\n}\n\nexport function resolveCaptureScale(\n preferredScale: number,\n widthPx: number,\n heightPx: number,\n maxCanvasDimension: number,\n) {\n const scale = Math.min(\n preferredScale,\n maxCanvasDimension / Math.max(widthPx, 1),\n maxCanvasDimension / Math.max(heightPx, 1),\n );\n\n return Math.max(scale, 1);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAwB;AACxB,mBAAsB;;;ACCtB,SAAS,aAAa,SAA0C;AAC9D,MAAI,EAAE,mBAAmB,aAAc,QAAO;AAE9C,QAAM,SAAS,OAAO,iBAAiB,OAAO;AAE9C,SAAO,OAAO,YAAY,UAAU,OAAO,eAAe;AAC5D;AAEO,SAAS,iBACd,MACA,kBACa;AACb,QAAM,UAAU,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
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { P as PaginatePdfOptions, a as PaginatePdfResult } from './types-DGaknP5f.cjs';
|
|
2
|
+
export { B as BorderOptions, b as PageFormat, c as PageNumberOptions, d as PaginatePdfStage, e as PdfMetadata } from './types-DGaknP5f.cjs';
|
|
3
|
+
|
|
4
|
+
declare function paginatePdf(element: HTMLElement, options?: PaginatePdfOptions): Promise<PaginatePdfResult>;
|
|
5
|
+
|
|
6
|
+
export { PaginatePdfOptions, PaginatePdfResult, paginatePdf };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { P as PaginatePdfOptions, a as PaginatePdfResult } from './types-DGaknP5f.js';
|
|
2
|
+
export { B as BorderOptions, b as PageFormat, c as PageNumberOptions, d as PaginatePdfStage, e as PdfMetadata } from './types-DGaknP5f.js';
|
|
3
|
+
|
|
4
|
+
declare function paginatePdf(element: HTMLElement, options?: PaginatePdfOptions): Promise<PaginatePdfResult>;
|
|
5
|
+
|
|
6
|
+
export { PaginatePdfOptions, PaginatePdfResult, paginatePdf };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|