jspdf-utils 0.1.22 → 0.1.24
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/dist/html-to-pdf.d.ts +15 -50
- package/dist/html-to-pdf.js +460 -451
- package/package.json +1 -1
package/dist/html-to-pdf.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export interface Margin {
|
|
|
12
12
|
left: number;
|
|
13
13
|
}
|
|
14
14
|
export type PageFormat = "a0" | "a1" | "a2" | "a3" | "a4" | "a5" | "a6" | "letter" | "legal" | "tabloid";
|
|
15
|
+
export type MarginInput = number | {
|
|
16
|
+
top?: number;
|
|
17
|
+
right?: number;
|
|
18
|
+
bottom?: number;
|
|
19
|
+
left?: number;
|
|
20
|
+
};
|
|
15
21
|
export interface PageOptions {
|
|
16
22
|
unit: string;
|
|
17
23
|
format: PageFormat;
|
|
@@ -19,6 +25,10 @@ export interface PageOptions {
|
|
|
19
25
|
pageHeight: number;
|
|
20
26
|
margin: Margin;
|
|
21
27
|
}
|
|
28
|
+
/** Input variant of PageOptions where margin accepts a number or partial sides. */
|
|
29
|
+
export type PageOptionsInput = Partial<Omit<PageOptions, "margin">> & {
|
|
30
|
+
margin?: MarginInput;
|
|
31
|
+
};
|
|
22
32
|
/** Standard page dimensions in mm (portrait). */
|
|
23
33
|
declare const PAGE_SIZES: Record<PageFormat, [number, number]>;
|
|
24
34
|
/** Standard margins in mm per format. */
|
|
@@ -35,46 +45,10 @@ export interface PrepareResult {
|
|
|
35
45
|
options: PageOptions;
|
|
36
46
|
cleanup: () => void;
|
|
37
47
|
}
|
|
38
|
-
/** Compute derived layout values from options. */
|
|
39
|
-
declare function computeLayout(container: HTMLElement, opts: PageOptions): Layout;
|
|
40
|
-
/**
|
|
41
|
-
* Clone an element and position it off-screen at print width for measurement.
|
|
42
|
-
*/
|
|
43
|
-
declare function createPrintClone(source: HTMLElement, pageWidth?: number): HTMLElement;
|
|
44
|
-
/**
|
|
45
|
-
* Convert HTML table attributes (cellpadding, cellspacing, border) to
|
|
46
|
-
* inline CSS so doc.html()'s renderer picks them up.
|
|
47
|
-
*/
|
|
48
|
-
declare function normalizeTableAttributes(container: HTMLElement): void;
|
|
49
|
-
/**
|
|
50
|
-
* Split tables that exceed one page height into smaller sub-tables,
|
|
51
|
-
* repeating the header row in each chunk.
|
|
52
|
-
*
|
|
53
|
-
* Only operates on direct-child tables of `container`.
|
|
54
|
-
*/
|
|
55
|
-
declare function splitOversizedTables(container: HTMLElement, pageContentPx: number): void;
|
|
56
|
-
/**
|
|
57
|
-
* Split direct-child elements (non-table) that are taller than one page
|
|
58
|
-
* into word-boundary chunks using binary search.
|
|
59
|
-
*/
|
|
60
|
-
declare function splitOversizedText(container: HTMLElement, pageContentPx: number): void;
|
|
61
|
-
/**
|
|
62
|
-
* Insert spacer divs so that no direct child straddles a page boundary.
|
|
63
|
-
* For tables and text elements, attempts to split at the boundary first
|
|
64
|
-
* so content fills the current page before flowing to the next.
|
|
65
|
-
*/
|
|
66
|
-
declare function insertPageBreakSpacers(container: HTMLElement, pageContentPx: number): void;
|
|
67
|
-
/**
|
|
68
|
-
* Prepare an HTML element for doc.html() rendering.
|
|
69
|
-
*
|
|
70
|
-
* Clones the element, splits oversized tables/text, and inserts page-break
|
|
71
|
-
* spacers. Returns the ready-to-render clone and layout metadata.
|
|
72
|
-
*/
|
|
73
|
-
declare function prepare(source: HTMLElement, opts?: Partial<PageOptions>): PrepareResult;
|
|
74
48
|
/**
|
|
75
49
|
* Render an HTML element to PDF using doc.html().
|
|
76
50
|
*/
|
|
77
|
-
declare function
|
|
51
|
+
declare function generatePDF(doc: jsPDF, source: HTMLElement, opts?: PageOptionsInput & Pick<ImagePDFOptions, "marginContent">): Promise<jsPDF>;
|
|
78
52
|
type MarginFactory = (page: number, totalPages: number) => HTMLElement;
|
|
79
53
|
export interface ContentBorder {
|
|
80
54
|
/** Stroke color (default: "#000000") */
|
|
@@ -130,25 +104,16 @@ export interface ImagePDFOptions {
|
|
|
130
104
|
* Render an HTML element as an image-based PDF. Each page is a rasterized
|
|
131
105
|
* screenshot — no selectable or extractable text in the output.
|
|
132
106
|
*/
|
|
133
|
-
declare function
|
|
107
|
+
declare function generateImagePDF(source: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions): Promise<jsPDF>;
|
|
134
108
|
/**
|
|
135
109
|
* Render an HTML element to an array of page images (data URLs).
|
|
136
110
|
* Each image represents a full page with margins, matching the
|
|
137
111
|
* visual output of renderImagePDF.
|
|
138
112
|
*/
|
|
139
|
-
declare function
|
|
113
|
+
declare function generateImages(source: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions): Promise<string[]>;
|
|
140
114
|
/**
|
|
141
115
|
* Render an HTML element as page images and inject them into a scrollable
|
|
142
116
|
* container. Each image is sized to match the page format dimensions.
|
|
143
117
|
*/
|
|
144
|
-
declare function
|
|
145
|
-
|
|
146
|
-
* Add HTML content to the margin areas of each page in a jsPDF document.
|
|
147
|
-
*
|
|
148
|
-
* Each slot (top, right, bottom, left) accepts either a static HTMLElement
|
|
149
|
-
* (rendered once and reused on every page) or a factory function that
|
|
150
|
-
* receives `(page, totalPages)` and returns an HTMLElement per page
|
|
151
|
-
* (useful for page numbers or dynamic content).
|
|
152
|
-
*/
|
|
153
|
-
declare function addMarginContent(doc: jsPDF, content: MarginContentInput, opts?: Partial<PageOptions>): Promise<jsPDF>;
|
|
154
|
-
export { PAGE_SIZES, PAGE_MARGINS, computeLayout, createPrintClone, normalizeTableAttributes, splitOversizedTables, splitOversizedText, insertPageBreakSpacers, prepare, renderHTML, renderImagePDF, renderPageImages, previewPageImages, addMarginContent, };
|
|
118
|
+
declare function previewImages(source: HTMLElement, container: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions): Promise<void>;
|
|
119
|
+
export { PAGE_SIZES, PAGE_MARGINS, generatePDF, generateImagePDF, generateImages, previewImages, };
|
package/dist/html-to-pdf.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
1
|
+
import S from "html2canvas";
|
|
2
|
+
const J = {
|
|
3
3
|
a0: [841, 1189],
|
|
4
4
|
a1: [594, 841],
|
|
5
5
|
a2: [420, 594],
|
|
@@ -10,7 +10,7 @@ const _ = {
|
|
|
10
10
|
letter: [215.9, 279.4],
|
|
11
11
|
legal: [215.9, 355.6],
|
|
12
12
|
tabloid: [279.4, 431.8]
|
|
13
|
-
},
|
|
13
|
+
}, Q = {
|
|
14
14
|
a0: 40,
|
|
15
15
|
a1: 35,
|
|
16
16
|
a2: 30,
|
|
@@ -22,693 +22,702 @@ const _ = {
|
|
|
22
22
|
legal: 25.4,
|
|
23
23
|
tabloid: 25
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
function M(t) {
|
|
26
|
+
return { top: t, right: t, bottom: t, left: t };
|
|
27
|
+
}
|
|
28
|
+
function Z(t, e) {
|
|
29
|
+
const a = M(Q[e]);
|
|
30
|
+
return t == null ? a : typeof t == "number" ? M(t) : {
|
|
31
|
+
top: t.top ?? a.top,
|
|
32
|
+
right: t.right ?? a.right,
|
|
33
|
+
bottom: t.bottom ?? a.bottom,
|
|
34
|
+
left: t.left ?? a.left
|
|
31
35
|
};
|
|
36
|
+
}
|
|
37
|
+
function x(t = {}) {
|
|
38
|
+
const e = t.format ?? "a4", [a, n] = J[e];
|
|
32
39
|
return {
|
|
33
|
-
unit:
|
|
34
|
-
format:
|
|
35
|
-
pageWidth:
|
|
36
|
-
pageHeight:
|
|
37
|
-
margin:
|
|
40
|
+
unit: t.unit ?? "mm",
|
|
41
|
+
format: e,
|
|
42
|
+
pageWidth: t.pageWidth ?? a,
|
|
43
|
+
pageHeight: t.pageHeight ?? n,
|
|
44
|
+
margin: Z(t.margin, e)
|
|
38
45
|
};
|
|
39
46
|
}
|
|
40
|
-
function
|
|
41
|
-
const a =
|
|
42
|
-
return { renderedWidth: a, scale:
|
|
47
|
+
function E(t, e) {
|
|
48
|
+
const a = t.offsetWidth, n = e.pageWidth - e.margin.left - e.margin.right, o = n / a, r = (e.pageHeight - e.margin.top - e.margin.bottom) / o;
|
|
49
|
+
return { renderedWidth: a, scale: o, contentWidthMm: n, pageContentPx: r };
|
|
43
50
|
}
|
|
44
|
-
function
|
|
45
|
-
const a =
|
|
51
|
+
function N(t, e = 210) {
|
|
52
|
+
const a = t.cloneNode(!0);
|
|
46
53
|
return Object.assign(a.style, {
|
|
47
54
|
position: "fixed",
|
|
48
55
|
top: "0",
|
|
49
56
|
left: "0",
|
|
50
57
|
boxSizing: "border-box",
|
|
51
|
-
width:
|
|
58
|
+
width: e + "mm",
|
|
52
59
|
opacity: "0.000001",
|
|
53
60
|
pointerEvents: "none"
|
|
54
61
|
}), document.body.appendChild(a), a;
|
|
55
62
|
}
|
|
56
|
-
async function
|
|
57
|
-
const
|
|
63
|
+
async function F(t) {
|
|
64
|
+
const e = Array.from(t.querySelectorAll("img"));
|
|
58
65
|
await Promise.all(
|
|
59
|
-
|
|
66
|
+
e.map((a) => {
|
|
60
67
|
if (!(a.complete && a.naturalWidth > 0))
|
|
61
|
-
return new Promise((
|
|
62
|
-
a.onload = () =>
|
|
68
|
+
return new Promise((n) => {
|
|
69
|
+
a.onload = () => n(), a.onerror = () => n();
|
|
63
70
|
});
|
|
64
71
|
})
|
|
65
72
|
);
|
|
66
73
|
}
|
|
67
|
-
async function
|
|
68
|
-
await
|
|
69
|
-
const
|
|
70
|
-
let a =
|
|
71
|
-
for (const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
+
async function K(t) {
|
|
75
|
+
await F(t);
|
|
76
|
+
const e = t.getBoundingClientRect();
|
|
77
|
+
let a = e.bottom;
|
|
78
|
+
for (const o of Array.from(t.querySelectorAll("*"))) {
|
|
79
|
+
const i = o.getBoundingClientRect().bottom;
|
|
80
|
+
i > a && (a = i);
|
|
74
81
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
82
|
+
const n = a - e.top;
|
|
83
|
+
n > t.offsetHeight && (t.style.minHeight = n + "px");
|
|
77
84
|
}
|
|
78
|
-
async function
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
await
|
|
82
|
-
n.map((t) => {
|
|
83
|
-
if (!(t.complete && t.naturalWidth > 0))
|
|
84
|
-
return new Promise((i) => {
|
|
85
|
-
t.onload = () => i(), t.onerror = () => i();
|
|
86
|
-
});
|
|
87
|
-
})
|
|
88
|
-
);
|
|
85
|
+
async function V(t) {
|
|
86
|
+
const e = Array.from(t.querySelectorAll("img"));
|
|
87
|
+
if (e.length === 0) return;
|
|
88
|
+
await F(t);
|
|
89
89
|
const a = 2;
|
|
90
|
-
for (const
|
|
91
|
-
if (!
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
90
|
+
for (const n of e) {
|
|
91
|
+
if (!n.naturalWidth || !n.naturalHeight || n.src.startsWith("data:image/svg")) continue;
|
|
92
|
+
const o = n.offsetWidth || n.naturalWidth, i = n.offsetHeight || n.naturalHeight, r = Math.min(o * a, n.naturalWidth), h = Math.min(i * a, n.naturalHeight);
|
|
93
|
+
if (n.naturalWidth <= r && n.naturalHeight <= h && n.src.startsWith("data:"))
|
|
94
94
|
continue;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
95
|
+
const s = document.createElement("canvas");
|
|
96
|
+
s.width = r, s.height = h;
|
|
97
|
+
const l = s.getContext("2d");
|
|
98
|
+
if (l)
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
l.drawImage(n, 0, 0, r, h), n.style.width = o + "px", n.style.height = i + "px", n.src = s.toDataURL("image/png");
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
function
|
|
106
|
-
const
|
|
107
|
-
return
|
|
105
|
+
function P() {
|
|
106
|
+
const t = document.createElement("style");
|
|
107
|
+
return t.setAttribute("data-jspdf-utils", ""), t.textContent = "img { display: inline !important; }", document.head.appendChild(t), () => t.remove();
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
for (const
|
|
111
|
-
const a =
|
|
109
|
+
function T(t) {
|
|
110
|
+
for (const e of Array.from(t.querySelectorAll("table"))) {
|
|
111
|
+
const a = e.getAttribute("cellpadding");
|
|
112
112
|
if (a) {
|
|
113
|
-
for (const
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
for (const n of Array.from(e.querySelectorAll("th, td")))
|
|
114
|
+
n.style.padding || (n.style.padding = a + "px");
|
|
115
|
+
e.removeAttribute("cellpadding");
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function I(t, e) {
|
|
120
120
|
for (const a of Array.from(
|
|
121
|
-
|
|
121
|
+
t.querySelectorAll(":scope > table")
|
|
122
122
|
)) {
|
|
123
|
-
if (a.offsetHeight <=
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
126
|
-
const
|
|
127
|
-
let
|
|
128
|
-
for (const
|
|
129
|
-
const
|
|
130
|
-
|
|
123
|
+
if (a.offsetHeight <= e) continue;
|
|
124
|
+
const n = D(a);
|
|
125
|
+
if (!n) continue;
|
|
126
|
+
const { headerRow: o, bodyRows: i, headerHeight: r } = n, h = e - r - 2, s = [];
|
|
127
|
+
let l = [], c = 0;
|
|
128
|
+
for (const d of i) {
|
|
129
|
+
const g = d.offsetHeight;
|
|
130
|
+
c + g > h && l.length > 0 && (s.push(l), l = [], c = 0), l.push(d), c += g;
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
for (const
|
|
134
|
-
const
|
|
135
|
-
o &&
|
|
136
|
-
for (const
|
|
137
|
-
a.parentNode.insertBefore(
|
|
132
|
+
l.length > 0 && s.push(l);
|
|
133
|
+
for (const d of s) {
|
|
134
|
+
const g = a.cloneNode(!1);
|
|
135
|
+
o && g.appendChild(o.cloneNode(!0));
|
|
136
|
+
for (const u of d) g.appendChild(u.cloneNode(!0));
|
|
137
|
+
a.parentNode.insertBefore(g, a);
|
|
138
138
|
}
|
|
139
139
|
a.remove();
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
function L(t, e, a, n) {
|
|
143
|
+
const o = document.createElement(t);
|
|
144
|
+
return o.setAttribute("style", e), Object.assign(o.style, {
|
|
145
|
+
position: "absolute",
|
|
146
|
+
visibility: "hidden",
|
|
147
|
+
width: a
|
|
148
|
+
}), n.appendChild(o), o;
|
|
149
|
+
}
|
|
150
|
+
function O(t, e, a, n) {
|
|
151
|
+
let o = n + 1, i = e.length;
|
|
152
|
+
for (; o < i; ) {
|
|
153
|
+
const r = Math.ceil((o + i) / 2);
|
|
154
|
+
t.textContent = e.slice(n, r).join(" "), t.offsetHeight <= a ? o = r : i = r - 1;
|
|
155
|
+
}
|
|
156
|
+
return o;
|
|
157
|
+
}
|
|
158
|
+
function D(t) {
|
|
159
|
+
const e = Array.from(t.rows);
|
|
160
|
+
if (e.length === 0) return null;
|
|
161
|
+
const a = e[0].querySelector("th") !== null, n = a ? e[0] : null, o = a ? e.slice(1) : e, i = n ? n.offsetHeight : 0;
|
|
162
|
+
return { rows: e, hasHeader: a, headerRow: n, bodyRows: o, headerHeight: i };
|
|
163
|
+
}
|
|
164
|
+
function k(t, e) {
|
|
165
|
+
for (const a of Array.from(t.querySelectorAll(":scope > *"))) {
|
|
166
|
+
const n = a;
|
|
167
|
+
if (n.offsetHeight <= e || n.tagName === "TABLE")
|
|
146
168
|
continue;
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}), e.appendChild(l);
|
|
153
|
-
const g = [];
|
|
154
|
-
let h = 0;
|
|
155
|
-
for (; h < r.length; ) {
|
|
156
|
-
let d = h + 1, u = r.length;
|
|
157
|
-
for (; d < u; ) {
|
|
158
|
-
const f = Math.ceil((d + u) / 2);
|
|
159
|
-
l.textContent = r.slice(h, f).join(" "), l.offsetHeight <= n ? d = f : u = f - 1;
|
|
160
|
-
}
|
|
161
|
-
const c = document.createElement(i);
|
|
162
|
-
c.setAttribute("style", o), c.textContent = r.slice(h, d).join(" "), g.push(c), h = d;
|
|
169
|
+
const o = n.tagName, i = n.getAttribute("style") || "", r = getComputedStyle(n).width, h = (n.textContent || "").split(/\s+/).filter(Boolean), s = L(o, i, r, t), l = [];
|
|
170
|
+
let c = 0;
|
|
171
|
+
for (; c < h.length; ) {
|
|
172
|
+
const d = O(s, h, e, c), g = document.createElement(o);
|
|
173
|
+
g.setAttribute("style", i), g.textContent = h.slice(c, d).join(" "), l.push(g), c = d;
|
|
163
174
|
}
|
|
164
|
-
|
|
165
|
-
for (const d of
|
|
166
|
-
|
|
167
|
-
|
|
175
|
+
s.remove();
|
|
176
|
+
for (const d of l)
|
|
177
|
+
n.parentNode.insertBefore(d, n);
|
|
178
|
+
n.remove();
|
|
168
179
|
}
|
|
169
180
|
}
|
|
170
|
-
function
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
175
|
-
const
|
|
176
|
-
if (
|
|
177
|
-
let
|
|
178
|
-
for (const
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
+
function Y(t, e, a) {
|
|
182
|
+
const n = D(t);
|
|
183
|
+
if (!n) return !1;
|
|
184
|
+
const { headerRow: o, bodyRows: i, headerHeight: r } = n;
|
|
185
|
+
if (i.length < 2) return !1;
|
|
186
|
+
const h = a - r - 2;
|
|
187
|
+
if (h <= 0) return !1;
|
|
188
|
+
let s = 0, l = 0;
|
|
189
|
+
for (const g of i) {
|
|
190
|
+
if (l + g.offsetHeight > h) break;
|
|
191
|
+
l += g.offsetHeight, s++;
|
|
181
192
|
}
|
|
182
|
-
if (
|
|
183
|
-
const
|
|
193
|
+
if (s === 0 || s === i.length) return !1;
|
|
194
|
+
const c = t.cloneNode(!1);
|
|
195
|
+
o && c.appendChild(o.cloneNode(!0));
|
|
196
|
+
for (let g = 0; g < s; g++)
|
|
197
|
+
c.appendChild(i[g].cloneNode(!0));
|
|
198
|
+
const d = t.cloneNode(!1);
|
|
184
199
|
o && d.appendChild(o.cloneNode(!0));
|
|
185
|
-
for (let
|
|
186
|
-
d.appendChild(
|
|
187
|
-
|
|
188
|
-
o && u.appendChild(o.cloneNode(!0));
|
|
189
|
-
for (let c = g; c < s.length; c++)
|
|
190
|
-
u.appendChild(s[c].cloneNode(!0));
|
|
191
|
-
return n.insertBefore(d, e), n.insertBefore(u, e), e.remove(), !0;
|
|
192
|
-
}
|
|
193
|
-
function V(e, n, a) {
|
|
194
|
-
if (e.tagName === "TABLE" || e.tagName === "IMG") return !1;
|
|
195
|
-
const t = (e.textContent || "").split(/\s+/).filter(Boolean);
|
|
196
|
-
if (t.length < 2) return !1;
|
|
197
|
-
const i = e.tagName, o = e.getAttribute("style") || "", s = getComputedStyle(e).width, r = document.createElement(i);
|
|
198
|
-
if (r.setAttribute("style", o), Object.assign(r.style, {
|
|
199
|
-
position: "absolute",
|
|
200
|
-
visibility: "hidden",
|
|
201
|
-
width: s
|
|
202
|
-
}), n.appendChild(r), r.textContent = t[0], r.offsetHeight > a)
|
|
203
|
-
return r.remove(), !1;
|
|
204
|
-
let l = 1, g = t.length;
|
|
205
|
-
for (; l < g; ) {
|
|
206
|
-
const u = Math.ceil((l + g) / 2);
|
|
207
|
-
r.textContent = t.slice(0, u).join(" "), r.offsetHeight <= a ? l = u : g = u - 1;
|
|
208
|
-
}
|
|
209
|
-
if (r.remove(), l >= t.length) return !1;
|
|
210
|
-
const h = document.createElement(i);
|
|
211
|
-
h.setAttribute("style", o), h.textContent = t.slice(0, l).join(" ");
|
|
212
|
-
const d = document.createElement(i);
|
|
213
|
-
return d.setAttribute("style", o), d.textContent = t.slice(l).join(" "), n.insertBefore(h, e), n.insertBefore(d, e), e.remove(), !0;
|
|
200
|
+
for (let g = s; g < i.length; g++)
|
|
201
|
+
d.appendChild(i[g].cloneNode(!0));
|
|
202
|
+
return e.insertBefore(c, t), e.insertBefore(d, t), t.remove(), !0;
|
|
214
203
|
}
|
|
215
|
-
function
|
|
204
|
+
function X(t, e, a) {
|
|
205
|
+
if (t.tagName === "TABLE" || t.tagName === "IMG") return !1;
|
|
206
|
+
const n = (t.textContent || "").split(/\s+/).filter(Boolean);
|
|
207
|
+
if (n.length < 2) return !1;
|
|
208
|
+
const o = t.tagName, i = t.getAttribute("style") || "", r = getComputedStyle(t).width, h = L(o, i, r, e);
|
|
209
|
+
if (h.textContent = n[0], h.offsetHeight > a)
|
|
210
|
+
return h.remove(), !1;
|
|
211
|
+
const s = O(h, n, a, 0);
|
|
212
|
+
if (h.remove(), s >= n.length) return !1;
|
|
213
|
+
const l = document.createElement(o);
|
|
214
|
+
l.setAttribute("style", i), l.textContent = n.slice(0, s).join(" ");
|
|
215
|
+
const c = document.createElement(o);
|
|
216
|
+
return c.setAttribute("style", i), c.textContent = n.slice(s).join(" "), e.insertBefore(l, t), e.insertBefore(c, t), t.remove(), !0;
|
|
217
|
+
}
|
|
218
|
+
function j(t, e) {
|
|
216
219
|
let a = 0;
|
|
217
|
-
for (; a <
|
|
218
|
-
const
|
|
219
|
-
if (
|
|
220
|
-
const
|
|
221
|
-
if (
|
|
222
|
-
if (
|
|
220
|
+
for (; a < t.children.length; ) {
|
|
221
|
+
const n = t.children[a], o = n.offsetTop, i = o + n.offsetHeight, r = (Math.floor(o / e) + 1) * e;
|
|
222
|
+
if (i > r) {
|
|
223
|
+
const h = r - o;
|
|
224
|
+
if (n.tagName === "TABLE") {
|
|
225
|
+
if (Y(
|
|
226
|
+
n,
|
|
223
227
|
t,
|
|
224
|
-
|
|
225
|
-
r
|
|
228
|
+
h
|
|
226
229
|
))
|
|
227
230
|
continue;
|
|
228
|
-
} else if (
|
|
231
|
+
} else if (X(n, t, h))
|
|
229
232
|
continue;
|
|
230
|
-
if (
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
+
if (n.offsetHeight <= e) {
|
|
234
|
+
const s = document.createElement("div");
|
|
235
|
+
s.style.height = r - o + 1 + "px", n.parentNode.insertBefore(s, n), a++;
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
238
|
a++;
|
|
236
239
|
}
|
|
237
240
|
}
|
|
238
|
-
function
|
|
239
|
-
const a =
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
return
|
|
243
|
-
clone:
|
|
244
|
-
layout:
|
|
241
|
+
function tt(t, e = {}) {
|
|
242
|
+
const a = x(e), n = P(), o = N(t, a.pageWidth);
|
|
243
|
+
T(o);
|
|
244
|
+
const i = E(o, a);
|
|
245
|
+
return I(o, i.pageContentPx), k(o, i.pageContentPx), j(o, i.pageContentPx), {
|
|
246
|
+
clone: o,
|
|
247
|
+
layout: i,
|
|
245
248
|
options: a,
|
|
246
249
|
cleanup: () => {
|
|
247
|
-
|
|
250
|
+
o.remove(), n();
|
|
248
251
|
}
|
|
249
252
|
};
|
|
250
253
|
}
|
|
251
|
-
async function
|
|
252
|
-
const { clone:
|
|
254
|
+
async function rt(t, e, a = {}) {
|
|
255
|
+
const { clone: n, layout: o, options: i, cleanup: r } = tt(e, a);
|
|
253
256
|
try {
|
|
254
|
-
await
|
|
255
|
-
|
|
256
|
-
callback: () =>
|
|
257
|
-
width:
|
|
258
|
-
windowWidth:
|
|
257
|
+
await V(n), await new Promise((h) => {
|
|
258
|
+
t.html(n, {
|
|
259
|
+
callback: () => h(),
|
|
260
|
+
width: o.contentWidthMm,
|
|
261
|
+
windowWidth: o.renderedWidth,
|
|
259
262
|
margin: [
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
i.margin.top,
|
|
264
|
+
i.margin.right,
|
|
265
|
+
i.margin.bottom,
|
|
266
|
+
i.margin.left
|
|
264
267
|
]
|
|
265
268
|
});
|
|
266
269
|
});
|
|
267
270
|
} finally {
|
|
268
|
-
|
|
271
|
+
r();
|
|
269
272
|
}
|
|
270
|
-
return a.marginContent && await
|
|
273
|
+
return a.marginContent && await _(t, a.marginContent, a), t;
|
|
271
274
|
}
|
|
272
|
-
function
|
|
273
|
-
switch (
|
|
275
|
+
function A(t, e) {
|
|
276
|
+
switch (t) {
|
|
274
277
|
case "top":
|
|
275
|
-
return { x: 0, y: 0, width:
|
|
278
|
+
return { x: 0, y: 0, width: e.pageWidth, height: e.margin.top };
|
|
276
279
|
case "bottom":
|
|
277
280
|
return {
|
|
278
281
|
x: 0,
|
|
279
|
-
y:
|
|
280
|
-
width:
|
|
281
|
-
height:
|
|
282
|
+
y: e.pageHeight - e.margin.bottom,
|
|
283
|
+
width: e.pageWidth,
|
|
284
|
+
height: e.margin.bottom
|
|
282
285
|
};
|
|
283
286
|
case "left":
|
|
284
|
-
return { x: 0, y: 0, width:
|
|
287
|
+
return { x: 0, y: 0, width: e.margin.left, height: e.pageHeight };
|
|
285
288
|
case "right":
|
|
286
289
|
return {
|
|
287
|
-
x:
|
|
290
|
+
x: e.pageWidth - e.margin.right,
|
|
288
291
|
y: 0,
|
|
289
|
-
width:
|
|
290
|
-
height:
|
|
292
|
+
width: e.margin.right,
|
|
293
|
+
height: e.pageHeight
|
|
291
294
|
};
|
|
292
295
|
}
|
|
293
296
|
}
|
|
294
|
-
async function
|
|
295
|
-
const
|
|
296
|
-
Object.assign(
|
|
297
|
+
async function B(t, e, a, n) {
|
|
298
|
+
const o = document.createElement("div");
|
|
299
|
+
Object.assign(o.style, {
|
|
297
300
|
position: "fixed",
|
|
298
301
|
left: "-99999px",
|
|
299
302
|
top: "0",
|
|
300
|
-
width:
|
|
303
|
+
width: e + "mm",
|
|
301
304
|
height: a + "mm",
|
|
302
305
|
overflow: "hidden"
|
|
303
|
-
}),
|
|
306
|
+
}), o.appendChild(t), document.body.appendChild(o);
|
|
304
307
|
try {
|
|
305
|
-
return await
|
|
306
|
-
scale:
|
|
308
|
+
return await S(o, {
|
|
309
|
+
scale: n,
|
|
307
310
|
backgroundColor: null
|
|
308
311
|
});
|
|
309
312
|
} finally {
|
|
310
|
-
|
|
313
|
+
o.remove();
|
|
311
314
|
}
|
|
312
315
|
}
|
|
313
|
-
const
|
|
314
|
-
async function G(
|
|
315
|
-
const
|
|
316
|
-
for (const
|
|
317
|
-
const
|
|
318
|
-
if (
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
316
|
+
const v = ["top", "right", "bottom", "left"];
|
|
317
|
+
async function G(t, e, a) {
|
|
318
|
+
const n = {};
|
|
319
|
+
for (const o of v) {
|
|
320
|
+
const i = t[o];
|
|
321
|
+
if (i && typeof i != "function") {
|
|
322
|
+
const r = A(o, e);
|
|
323
|
+
n[o] = await B(
|
|
324
|
+
i.cloneNode(!0),
|
|
325
|
+
r.width,
|
|
326
|
+
r.height,
|
|
324
327
|
a
|
|
325
328
|
);
|
|
326
329
|
}
|
|
327
330
|
}
|
|
328
|
-
return
|
|
329
|
-
}
|
|
330
|
-
function
|
|
331
|
-
return
|
|
332
|
-
top:
|
|
333
|
-
right:
|
|
334
|
-
bottom:
|
|
335
|
-
left:
|
|
331
|
+
return n;
|
|
332
|
+
}
|
|
333
|
+
function et(t, e) {
|
|
334
|
+
return t == null ? e.margin : typeof t == "number" ? M(t) : {
|
|
335
|
+
top: t.top ?? e.margin.top,
|
|
336
|
+
right: t.right ?? e.margin.right,
|
|
337
|
+
bottom: t.bottom ?? e.margin.bottom,
|
|
338
|
+
left: t.left ?? e.margin.left
|
|
336
339
|
};
|
|
337
340
|
}
|
|
338
|
-
const
|
|
339
|
-
async function
|
|
340
|
-
const
|
|
341
|
-
Object.assign(
|
|
341
|
+
const nt = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
|
|
342
|
+
async function R(t, e, a, n, o, i, r, h, s = !1) {
|
|
343
|
+
const l = document.createElement("div");
|
|
344
|
+
Object.assign(l.style, {
|
|
342
345
|
position: "fixed",
|
|
343
346
|
left: "-99999px",
|
|
344
347
|
top: "0",
|
|
345
|
-
width: `${
|
|
348
|
+
width: `${e}px`,
|
|
346
349
|
height: `${a}px`,
|
|
347
350
|
overflow: "hidden",
|
|
348
351
|
whiteSpace: "nowrap",
|
|
349
|
-
fontSize: `${
|
|
350
|
-
fontFamily:
|
|
351
|
-
fontWeight:
|
|
352
|
-
color:
|
|
352
|
+
fontSize: `${n}px`,
|
|
353
|
+
fontFamily: o,
|
|
354
|
+
fontWeight: i,
|
|
355
|
+
color: r,
|
|
353
356
|
display: "flex",
|
|
354
357
|
alignItems: "center",
|
|
355
|
-
gap: `${
|
|
356
|
-
direction:
|
|
358
|
+
gap: `${h}px`,
|
|
359
|
+
direction: s ? "rtl" : "ltr"
|
|
357
360
|
});
|
|
358
|
-
const
|
|
359
|
-
|
|
361
|
+
const c = document.createElement("span");
|
|
362
|
+
c.textContent = t, Object.assign(c.style, {
|
|
360
363
|
position: "absolute",
|
|
361
364
|
visibility: "hidden",
|
|
362
365
|
whiteSpace: "nowrap",
|
|
363
|
-
fontSize: `${
|
|
364
|
-
fontFamily:
|
|
365
|
-
fontWeight:
|
|
366
|
-
}), document.body.appendChild(
|
|
367
|
-
const d =
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
for (let
|
|
366
|
+
fontSize: `${n}px`,
|
|
367
|
+
fontFamily: o,
|
|
368
|
+
fontWeight: i
|
|
369
|
+
}), document.body.appendChild(c);
|
|
370
|
+
const d = c.offsetWidth;
|
|
371
|
+
c.remove();
|
|
372
|
+
const g = Math.ceil(e / (d + h)) + 2;
|
|
373
|
+
for (let u = 0; u < g; u++) {
|
|
371
374
|
const f = document.createElement("span");
|
|
372
|
-
f.textContent =
|
|
375
|
+
f.textContent = t, f.style.flexShrink = "0", l.appendChild(f);
|
|
373
376
|
}
|
|
374
|
-
document.body.appendChild(
|
|
377
|
+
document.body.appendChild(l);
|
|
375
378
|
try {
|
|
376
|
-
return await
|
|
379
|
+
return await S(l, {
|
|
377
380
|
scale: 3,
|
|
378
381
|
backgroundColor: null,
|
|
379
|
-
width: Math.ceil(
|
|
382
|
+
width: Math.ceil(e),
|
|
380
383
|
height: Math.ceil(a)
|
|
381
384
|
});
|
|
382
385
|
} finally {
|
|
383
|
-
|
|
386
|
+
l.remove();
|
|
384
387
|
}
|
|
385
388
|
}
|
|
386
|
-
async function U(
|
|
389
|
+
async function U(t, e, a, n, o, i, r) {
|
|
387
390
|
const {
|
|
388
|
-
text:
|
|
389
|
-
color:
|
|
390
|
-
fontSize:
|
|
391
|
-
fontFamily:
|
|
391
|
+
text: h,
|
|
392
|
+
color: s = "#000000",
|
|
393
|
+
fontSize: l = 2.5,
|
|
394
|
+
fontFamily: c = "Arial, sans-serif",
|
|
392
395
|
fontWeight: d = "normal"
|
|
393
|
-
} =
|
|
394
|
-
|
|
395
|
-
|
|
396
|
+
} = e, g = l * a, u = (e.gap ?? l * 0.5) * a, f = g * 0.5, m = Math.ceil(g * 2.5), p = nt.test(h), y = Math.round(i - f * 2), b = Math.round(r - f * 2), [w, C] = await Promise.all([
|
|
397
|
+
R(
|
|
398
|
+
h,
|
|
396
399
|
y,
|
|
397
400
|
m,
|
|
398
|
-
|
|
399
|
-
h,
|
|
400
|
-
d,
|
|
401
|
-
l,
|
|
401
|
+
g,
|
|
402
402
|
c,
|
|
403
|
+
d,
|
|
404
|
+
s,
|
|
405
|
+
u,
|
|
403
406
|
p
|
|
404
407
|
),
|
|
405
|
-
|
|
406
|
-
r,
|
|
407
|
-
w,
|
|
408
|
-
m,
|
|
409
|
-
u,
|
|
408
|
+
R(
|
|
410
409
|
h,
|
|
411
|
-
|
|
412
|
-
|
|
410
|
+
b,
|
|
411
|
+
m,
|
|
412
|
+
g,
|
|
413
413
|
c,
|
|
414
|
+
d,
|
|
415
|
+
s,
|
|
416
|
+
u,
|
|
414
417
|
p
|
|
415
418
|
)
|
|
416
|
-
]),
|
|
417
|
-
|
|
418
|
-
|
|
419
|
+
]), H = Math.round(m / 2);
|
|
420
|
+
t.drawImage(
|
|
421
|
+
w,
|
|
419
422
|
0,
|
|
420
423
|
0,
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
424
|
+
w.width,
|
|
425
|
+
w.height,
|
|
426
|
+
n + f,
|
|
427
|
+
o - H,
|
|
425
428
|
y,
|
|
426
429
|
m
|
|
427
|
-
),
|
|
428
|
-
|
|
430
|
+
), t.drawImage(
|
|
431
|
+
w,
|
|
429
432
|
0,
|
|
430
433
|
0,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
434
|
+
w.width,
|
|
435
|
+
w.height,
|
|
436
|
+
n + f,
|
|
437
|
+
o + r - H,
|
|
435
438
|
y,
|
|
436
439
|
m
|
|
437
|
-
),
|
|
440
|
+
), t.save(), t.translate(n, o + r - f), t.rotate(-Math.PI / 2), t.drawImage(
|
|
438
441
|
C,
|
|
439
442
|
0,
|
|
440
443
|
0,
|
|
441
444
|
C.width,
|
|
442
445
|
C.height,
|
|
443
446
|
0,
|
|
444
|
-
-
|
|
445
|
-
|
|
447
|
+
-H,
|
|
448
|
+
b,
|
|
446
449
|
m
|
|
447
|
-
),
|
|
450
|
+
), t.restore(), t.save(), t.translate(n + i, o + f), t.rotate(Math.PI / 2), t.drawImage(
|
|
448
451
|
C,
|
|
449
452
|
0,
|
|
450
453
|
0,
|
|
451
454
|
C.width,
|
|
452
455
|
C.height,
|
|
453
456
|
0,
|
|
454
|
-
-
|
|
455
|
-
|
|
457
|
+
-H,
|
|
458
|
+
b,
|
|
456
459
|
m
|
|
457
|
-
),
|
|
460
|
+
), t.restore();
|
|
458
461
|
}
|
|
459
|
-
function
|
|
460
|
-
return
|
|
462
|
+
function W(t, e) {
|
|
463
|
+
return et(t.margin, e);
|
|
461
464
|
}
|
|
462
|
-
async function
|
|
463
|
-
for (const
|
|
464
|
-
const
|
|
465
|
-
if (!
|
|
466
|
-
const
|
|
465
|
+
async function ot(t, e, a, n, o, i, r, h) {
|
|
466
|
+
for (const s of v) {
|
|
467
|
+
const l = e[s];
|
|
468
|
+
if (!l) continue;
|
|
469
|
+
const c = A(s, n);
|
|
467
470
|
let d;
|
|
468
|
-
typeof
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
) : d = a[
|
|
471
|
+
typeof l == "function" ? d = await B(
|
|
472
|
+
l(i, r),
|
|
473
|
+
c.width,
|
|
474
|
+
c.height,
|
|
475
|
+
h
|
|
476
|
+
) : d = a[s], t.drawImage(
|
|
474
477
|
d,
|
|
475
478
|
0,
|
|
476
479
|
0,
|
|
477
480
|
d.width,
|
|
478
481
|
d.height,
|
|
479
|
-
Math.round(
|
|
480
|
-
Math.round(
|
|
481
|
-
Math.round(
|
|
482
|
-
Math.round(
|
|
482
|
+
Math.round(c.x * o),
|
|
483
|
+
Math.round(c.y * o),
|
|
484
|
+
Math.round(c.width * o),
|
|
485
|
+
Math.round(c.height * o)
|
|
483
486
|
);
|
|
484
487
|
}
|
|
485
|
-
if (
|
|
486
|
-
const { color:
|
|
487
|
-
|
|
488
|
-
Math.round(
|
|
489
|
-
Math.round(
|
|
490
|
-
Math.round((
|
|
491
|
-
Math.round((
|
|
488
|
+
if (e.contentBorder) {
|
|
489
|
+
const { color: s = "#000000", width: l = 0.3 } = e.contentBorder, c = W(e.contentBorder, n);
|
|
490
|
+
t.strokeStyle = s, t.lineWidth = l * o, t.strokeRect(
|
|
491
|
+
Math.round(c.left * o),
|
|
492
|
+
Math.round(c.top * o),
|
|
493
|
+
Math.round((n.pageWidth - c.left - c.right) * o),
|
|
494
|
+
Math.round((n.pageHeight - c.top - c.bottom) * o)
|
|
492
495
|
);
|
|
493
496
|
}
|
|
494
|
-
if (
|
|
495
|
-
const
|
|
497
|
+
if (e.textBorder) {
|
|
498
|
+
const s = W(e.textBorder, n);
|
|
496
499
|
await U(
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
Math.round(
|
|
501
|
-
Math.round(
|
|
502
|
-
Math.round((
|
|
503
|
-
Math.round((
|
|
500
|
+
t,
|
|
501
|
+
e.textBorder,
|
|
502
|
+
o,
|
|
503
|
+
Math.round(s.left * o),
|
|
504
|
+
Math.round(s.top * o),
|
|
505
|
+
Math.round((n.pageWidth - s.left - s.right) * o),
|
|
506
|
+
Math.round((n.pageHeight - s.top - s.bottom) * o)
|
|
504
507
|
);
|
|
505
508
|
}
|
|
506
509
|
}
|
|
507
|
-
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
510
|
+
function q(t, e) {
|
|
511
|
+
const a = e.pageWidth - e.margin.left - e.margin.right, n = e.pageHeight - e.margin.top - e.margin.bottom, o = t.width, i = n / a * o, r = o / a;
|
|
512
|
+
return {
|
|
513
|
+
contentWidthMm: a,
|
|
514
|
+
contentHeightMm: n,
|
|
515
|
+
contentWidthPx: o,
|
|
516
|
+
contentHeightPx: i,
|
|
517
|
+
pxPerMm: r,
|
|
518
|
+
pageWidthPx: Math.round(e.pageWidth * r),
|
|
519
|
+
pageHeightPx: Math.round(e.pageHeight * r),
|
|
520
|
+
marginTopPx: Math.round(e.margin.top * r),
|
|
521
|
+
marginLeftPx: Math.round(e.margin.left * r)
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function $(t, e, a) {
|
|
525
|
+
const n = Math.min(
|
|
526
|
+
a.contentHeightPx,
|
|
527
|
+
t.height - e * a.contentHeightPx
|
|
528
|
+
), o = document.createElement("canvas");
|
|
529
|
+
o.width = a.pageWidthPx, o.height = a.pageHeightPx;
|
|
530
|
+
const i = o.getContext("2d");
|
|
531
|
+
if (!i) throw new Error("Could not get canvas context");
|
|
532
|
+
return i.fillStyle = "#ffffff", i.fillRect(0, 0, a.pageWidthPx, a.pageHeightPx), i.drawImage(
|
|
533
|
+
t,
|
|
534
|
+
0,
|
|
535
|
+
e * a.contentHeightPx,
|
|
536
|
+
a.contentWidthPx,
|
|
537
|
+
n,
|
|
538
|
+
a.marginLeftPx,
|
|
539
|
+
a.marginTopPx,
|
|
540
|
+
a.contentWidthPx,
|
|
541
|
+
n
|
|
542
|
+
), { canvas: o, ctx: i };
|
|
543
|
+
}
|
|
544
|
+
async function z(t, e) {
|
|
545
|
+
const a = P(), n = N(t, e.pageWidth);
|
|
546
|
+
n.style.opacity = "1", n.style.left = "-99999px", T(n);
|
|
547
|
+
const o = E(n, e);
|
|
548
|
+
return I(n, o.pageContentPx), k(n, o.pageContentPx), j(n, o.pageContentPx), await K(n), {
|
|
549
|
+
clone: n,
|
|
550
|
+
layout: o,
|
|
551
|
+
cleanup: () => {
|
|
552
|
+
n.remove(), a();
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
async function st(t, e = {}) {
|
|
557
|
+
const { imageFormat: a = "JPEG", imageQuality: n = 0.7, scale: o = 3 } = e, i = x(e), { clone: r, cleanup: h } = await z(t, i);
|
|
512
558
|
try {
|
|
513
|
-
const
|
|
514
|
-
scale:
|
|
559
|
+
const s = await S(r, {
|
|
560
|
+
scale: o,
|
|
515
561
|
backgroundColor: "#ffffff"
|
|
516
|
-
}), { jsPDF:
|
|
517
|
-
orientation:
|
|
562
|
+
}), { jsPDF: l } = await import("jspdf"), c = q(s, i), d = Math.ceil(s.height / c.contentHeightPx), g = i.pageWidth > i.pageHeight ? "l" : "p", u = new l({
|
|
563
|
+
orientation: g,
|
|
518
564
|
unit: "mm",
|
|
519
|
-
format: [
|
|
520
|
-
})
|
|
521
|
-
for (let
|
|
522
|
-
const
|
|
565
|
+
format: [i.pageWidth, i.pageHeight]
|
|
566
|
+
});
|
|
567
|
+
for (let f = 0; f < d; f++) {
|
|
568
|
+
const { canvas: m, ctx: p } = $(
|
|
569
|
+
s,
|
|
523
570
|
f,
|
|
524
|
-
|
|
525
|
-
),
|
|
526
|
-
W.width = b, W.height = C;
|
|
527
|
-
const v = W.getContext("2d");
|
|
528
|
-
if (!v) throw new Error("Could not get canvas context");
|
|
529
|
-
v.fillStyle = "#ffffff", v.fillRect(0, 0, b, C), v.drawImage(
|
|
530
|
-
g,
|
|
531
|
-
0,
|
|
532
|
-
H * f,
|
|
533
|
-
c,
|
|
534
|
-
M,
|
|
535
|
-
R,
|
|
536
|
-
x,
|
|
537
|
-
c,
|
|
538
|
-
M
|
|
539
|
-
);
|
|
540
|
-
const z = W.toDataURL(
|
|
571
|
+
c
|
|
572
|
+
), y = m.toDataURL(
|
|
541
573
|
`image/${a.toLowerCase()}`,
|
|
542
|
-
|
|
574
|
+
n
|
|
543
575
|
);
|
|
544
|
-
|
|
545
|
-
|
|
576
|
+
f > 0 && u.addPage([i.pageWidth, i.pageHeight], g), u.addImage(
|
|
577
|
+
y,
|
|
546
578
|
a,
|
|
547
579
|
0,
|
|
548
580
|
0,
|
|
549
|
-
|
|
550
|
-
|
|
581
|
+
i.pageWidth,
|
|
582
|
+
i.pageHeight,
|
|
551
583
|
void 0,
|
|
552
584
|
"SLOW"
|
|
553
585
|
);
|
|
554
586
|
}
|
|
555
|
-
return
|
|
587
|
+
return e.marginContent && await _(u, e.marginContent, e), u;
|
|
556
588
|
} finally {
|
|
557
|
-
|
|
589
|
+
h();
|
|
558
590
|
}
|
|
559
591
|
}
|
|
560
|
-
async function
|
|
561
|
-
const { imageFormat: a = "PNG", imageQuality:
|
|
562
|
-
r.style.opacity = "1", r.style.left = "-99999px", I(r);
|
|
563
|
-
const l = N(r, o);
|
|
564
|
-
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
|
|
592
|
+
async function at(t, e = {}) {
|
|
593
|
+
const { imageFormat: a = "PNG", imageQuality: n = 0.75, scale: o = 2 } = e, i = x(e), { clone: r, cleanup: h } = await z(t, i);
|
|
565
594
|
try {
|
|
566
|
-
const
|
|
567
|
-
scale:
|
|
595
|
+
const s = await S(r, {
|
|
596
|
+
scale: o,
|
|
568
597
|
backgroundColor: "#ffffff"
|
|
569
|
-
}),
|
|
570
|
-
for (let
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
v.fillStyle = "#ffffff", v.fillRect(0, 0, m, p), v.drawImage(
|
|
598
|
+
}), l = q(s, i), c = Math.ceil(s.height / l.contentHeightPx), d = [], { marginContent: g } = e, u = g ? await G(g, i, o) : {};
|
|
599
|
+
for (let f = 0; f < c; f++) {
|
|
600
|
+
const { canvas: m, ctx: p } = $(
|
|
601
|
+
s,
|
|
602
|
+
f,
|
|
603
|
+
l
|
|
604
|
+
);
|
|
605
|
+
g && await ot(
|
|
606
|
+
p,
|
|
579
607
|
g,
|
|
580
|
-
0,
|
|
581
|
-
H * c,
|
|
582
608
|
u,
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
),
|
|
589
|
-
|
|
590
|
-
x,
|
|
591
|
-
R,
|
|
592
|
-
o,
|
|
593
|
-
f,
|
|
594
|
-
H + 1,
|
|
595
|
-
b,
|
|
596
|
-
i
|
|
597
|
-
), C.push(
|
|
598
|
-
W.toDataURL(
|
|
609
|
+
i,
|
|
610
|
+
l.pxPerMm,
|
|
611
|
+
f + 1,
|
|
612
|
+
c,
|
|
613
|
+
o
|
|
614
|
+
), d.push(
|
|
615
|
+
m.toDataURL(
|
|
599
616
|
`image/${a.toLowerCase()}`,
|
|
600
|
-
|
|
617
|
+
n
|
|
601
618
|
)
|
|
602
619
|
);
|
|
603
620
|
}
|
|
604
|
-
return
|
|
621
|
+
return d;
|
|
605
622
|
} finally {
|
|
606
|
-
|
|
623
|
+
h();
|
|
607
624
|
}
|
|
608
625
|
}
|
|
609
|
-
async function
|
|
610
|
-
const
|
|
611
|
-
|
|
626
|
+
async function ct(t, e, a = {}) {
|
|
627
|
+
const n = x(a), o = await at(t, a);
|
|
628
|
+
e.innerHTML = "", Object.assign(e.style, {
|
|
612
629
|
direction: "ltr",
|
|
613
630
|
width: "fit-content",
|
|
614
|
-
height:
|
|
631
|
+
height: n.pageHeight + "mm",
|
|
615
632
|
maxHeight: "100vh",
|
|
616
|
-
overflowY:
|
|
633
|
+
overflowY: o.length > 1 ? "auto" : "hidden",
|
|
617
634
|
background: "#e0e0e0"
|
|
618
635
|
});
|
|
619
|
-
for (let
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
width:
|
|
636
|
+
for (let i = 0; i < o.length; i++) {
|
|
637
|
+
const r = document.createElement("img");
|
|
638
|
+
r.src = o[i], r.alt = `Page ${i + 1}`, Object.assign(r.style, {
|
|
639
|
+
width: n.pageWidth + "mm",
|
|
623
640
|
maxWidth: "100%",
|
|
624
641
|
height: "auto",
|
|
625
642
|
boxSizing: "border-box",
|
|
626
643
|
border: "1px solid #bbb",
|
|
627
644
|
boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
|
|
628
645
|
marginBottom: "16px"
|
|
629
|
-
}),
|
|
646
|
+
}), r.style.setProperty("display", "inline", "important"), e.appendChild(r);
|
|
630
647
|
}
|
|
631
648
|
}
|
|
632
|
-
async function
|
|
633
|
-
const
|
|
634
|
-
for (const
|
|
635
|
-
|
|
636
|
-
let
|
|
637
|
-
if (
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
const f =
|
|
649
|
+
async function _(t, e, a = {}) {
|
|
650
|
+
const n = x(a), o = t.getNumberOfPages(), i = 4, r = i * (96 / 25.4), h = P(), s = Math.round(n.pageWidth * r), l = Math.round(n.pageHeight * r), c = await G(e, n, i), d = {};
|
|
651
|
+
for (const u of v)
|
|
652
|
+
c[u] && (d[u] = c[u].toDataURL("image/png"));
|
|
653
|
+
let g;
|
|
654
|
+
if (e.textBorder) {
|
|
655
|
+
const u = document.createElement("canvas");
|
|
656
|
+
u.width = s, u.height = l;
|
|
657
|
+
const f = u.getContext("2d");
|
|
641
658
|
if (f) {
|
|
642
|
-
const m =
|
|
659
|
+
const m = W(e.textBorder, n);
|
|
643
660
|
await U(
|
|
644
661
|
f,
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
Math.round(m.left *
|
|
648
|
-
Math.round(m.top *
|
|
649
|
-
Math.round((
|
|
650
|
-
Math.round((
|
|
651
|
-
),
|
|
662
|
+
e.textBorder,
|
|
663
|
+
r,
|
|
664
|
+
Math.round(m.left * r),
|
|
665
|
+
Math.round(m.top * r),
|
|
666
|
+
Math.round((n.pageWidth - m.left - m.right) * r),
|
|
667
|
+
Math.round((n.pageHeight - m.top - m.bottom) * r)
|
|
668
|
+
), g = u.toDataURL("image/png");
|
|
652
669
|
}
|
|
653
670
|
}
|
|
654
|
-
for (let
|
|
655
|
-
|
|
656
|
-
for (const f of
|
|
657
|
-
const m =
|
|
671
|
+
for (let u = 1; u <= o; u++) {
|
|
672
|
+
t.setPage(u);
|
|
673
|
+
for (const f of v) {
|
|
674
|
+
const m = e[f];
|
|
658
675
|
if (!m) continue;
|
|
659
|
-
const p =
|
|
660
|
-
let y,
|
|
661
|
-
typeof m == "function" ? y = (await
|
|
662
|
-
m(
|
|
676
|
+
const p = A(f, n);
|
|
677
|
+
let y, b;
|
|
678
|
+
typeof m == "function" ? y = (await B(
|
|
679
|
+
m(u, o),
|
|
663
680
|
p.width,
|
|
664
681
|
p.height,
|
|
665
|
-
|
|
666
|
-
)).toDataURL("image/png") : (y = d[f],
|
|
682
|
+
i
|
|
683
|
+
)).toDataURL("image/png") : (y = d[f], b = `margin-${f}`), t.addImage(
|
|
667
684
|
y,
|
|
668
685
|
"PNG",
|
|
669
686
|
p.x,
|
|
670
687
|
p.y,
|
|
671
688
|
p.width,
|
|
672
689
|
p.height,
|
|
673
|
-
|
|
690
|
+
b,
|
|
674
691
|
"SLOW"
|
|
675
692
|
);
|
|
676
693
|
}
|
|
677
|
-
if (
|
|
678
|
-
const { color: f = "#000000", width: m = 0.3 } =
|
|
679
|
-
|
|
694
|
+
if (e.contentBorder) {
|
|
695
|
+
const { color: f = "#000000", width: m = 0.3 } = e.contentBorder, p = W(e.contentBorder, n);
|
|
696
|
+
t.setDrawColor(f), t.setLineWidth(m), t.rect(
|
|
680
697
|
p.left,
|
|
681
698
|
p.top,
|
|
682
|
-
|
|
683
|
-
|
|
699
|
+
n.pageWidth - p.left - p.right,
|
|
700
|
+
n.pageHeight - p.top - p.bottom
|
|
684
701
|
);
|
|
685
702
|
}
|
|
686
|
-
|
|
687
|
-
|
|
703
|
+
g && t.addImage(
|
|
704
|
+
g,
|
|
688
705
|
"PNG",
|
|
689
706
|
0,
|
|
690
707
|
0,
|
|
691
|
-
|
|
692
|
-
|
|
708
|
+
n.pageWidth,
|
|
709
|
+
n.pageHeight,
|
|
693
710
|
"text-border",
|
|
694
711
|
"SLOW"
|
|
695
712
|
);
|
|
696
713
|
}
|
|
697
|
-
return
|
|
714
|
+
return h(), t;
|
|
698
715
|
}
|
|
699
716
|
export {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
I as normalizeTableAttributes,
|
|
707
|
-
Y as prepare,
|
|
708
|
-
rt as previewPageImages,
|
|
709
|
-
it as renderHTML,
|
|
710
|
-
at as renderImagePDF,
|
|
711
|
-
nt as renderPageImages,
|
|
712
|
-
L as splitOversizedTables,
|
|
713
|
-
O as splitOversizedText
|
|
717
|
+
Q as PAGE_MARGINS,
|
|
718
|
+
J as PAGE_SIZES,
|
|
719
|
+
st as generateImagePDF,
|
|
720
|
+
at as generateImages,
|
|
721
|
+
rt as generatePDF,
|
|
722
|
+
ct as previewImages
|
|
714
723
|
};
|
package/package.json
CHANGED