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