jspdf-utils 0.1.16 → 0.1.17
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 +183 -185
- package/package.json +1 -1
package/dist/html-to-pdf.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
1
|
+
import P from "html2canvas";
|
|
2
|
+
const _ = {
|
|
3
3
|
a0: [841, 1189],
|
|
4
4
|
a1: [594, 841],
|
|
5
5
|
a2: [420, 594],
|
|
@@ -10,7 +10,7 @@ const z = {
|
|
|
10
10
|
letter: [215.9, 279.4],
|
|
11
11
|
legal: [215.9, 355.6],
|
|
12
12
|
tabloid: [279.4, 431.8]
|
|
13
|
-
},
|
|
13
|
+
}, J = {
|
|
14
14
|
a0: 40,
|
|
15
15
|
a1: 35,
|
|
16
16
|
a2: 30,
|
|
@@ -22,8 +22,8 @@ const z = {
|
|
|
22
22
|
legal: 25.4,
|
|
23
23
|
tabloid: 25
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
const n = e.format ?? "a4", [a, t] =
|
|
25
|
+
function S(e = {}) {
|
|
26
|
+
const n = e.format ?? "a4", [a, t] = _[n], i = e.pageWidth ?? a, o = e.pageHeight ?? t, s = J[n], r = {
|
|
27
27
|
top: s,
|
|
28
28
|
right: s,
|
|
29
29
|
bottom: s,
|
|
@@ -41,7 +41,7 @@ function R(e, n) {
|
|
|
41
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
42
|
return { renderedWidth: a, scale: i, contentWidthMm: t, pageContentPx: s };
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function N(e, n = 210) {
|
|
45
45
|
const a = e.cloneNode(!0);
|
|
46
46
|
return Object.assign(a.style, {
|
|
47
47
|
position: "fixed",
|
|
@@ -63,7 +63,7 @@ function G(e) {
|
|
|
63
63
|
const t = a - n.top;
|
|
64
64
|
t > e.offsetHeight && (e.style.minHeight = t + "px");
|
|
65
65
|
}
|
|
66
|
-
async function
|
|
66
|
+
async function Q(e) {
|
|
67
67
|
const n = Array.from(e.querySelectorAll("img"));
|
|
68
68
|
if (n.length === 0) return;
|
|
69
69
|
await Promise.all(
|
|
@@ -90,11 +90,11 @@ async function J(e) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function F() {
|
|
94
94
|
const e = document.createElement("style");
|
|
95
95
|
return e.setAttribute("data-jspdf-utils", ""), e.textContent = "img { display: inline !important; }", document.head.appendChild(e), () => e.remove();
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function I(e) {
|
|
98
98
|
for (const n of e.querySelectorAll("table")) {
|
|
99
99
|
const a = n.getAttribute("cellpadding");
|
|
100
100
|
if (a) {
|
|
@@ -104,7 +104,7 @@ function F(e) {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function L(e, n) {
|
|
108
108
|
for (const a of Array.from(
|
|
109
109
|
e.querySelectorAll(":scope > table")
|
|
110
110
|
)) {
|
|
@@ -112,16 +112,16 @@ function I(e, n) {
|
|
|
112
112
|
const t = Array.from(a.rows);
|
|
113
113
|
if (t.length === 0) continue;
|
|
114
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 = [],
|
|
115
|
+
let c = [], u = 0;
|
|
116
116
|
for (const d of s) {
|
|
117
117
|
const g = d.offsetHeight;
|
|
118
|
-
|
|
118
|
+
u + g > l && c.length > 0 && (h.push(c), c = [], u = 0), c.push(d), u += g;
|
|
119
119
|
}
|
|
120
120
|
c.length > 0 && h.push(c);
|
|
121
121
|
for (const d of h) {
|
|
122
122
|
const g = a.cloneNode(!1);
|
|
123
123
|
o && g.appendChild(o.cloneNode(!0));
|
|
124
|
-
for (const
|
|
124
|
+
for (const f of d) g.appendChild(f.cloneNode(!0));
|
|
125
125
|
a.parentNode.insertBefore(g, a);
|
|
126
126
|
}
|
|
127
127
|
a.remove();
|
|
@@ -141,21 +141,21 @@ function O(e, n) {
|
|
|
141
141
|
const h = [];
|
|
142
142
|
let c = 0;
|
|
143
143
|
for (; c < r.length; ) {
|
|
144
|
-
let
|
|
145
|
-
for (;
|
|
146
|
-
const
|
|
147
|
-
l.textContent = r.slice(c,
|
|
144
|
+
let u = c + 1, d = r.length;
|
|
145
|
+
for (; u < d; ) {
|
|
146
|
+
const f = Math.ceil((u + d) / 2);
|
|
147
|
+
l.textContent = r.slice(c, f).join(" "), l.offsetHeight <= n ? u = f : d = f - 1;
|
|
148
148
|
}
|
|
149
149
|
const g = document.createElement(i);
|
|
150
|
-
g.setAttribute("style", o), g.textContent = r.slice(c,
|
|
150
|
+
g.setAttribute("style", o), g.textContent = r.slice(c, u).join(" "), h.push(g), c = u;
|
|
151
151
|
}
|
|
152
152
|
l.remove();
|
|
153
|
-
for (const
|
|
154
|
-
t.parentNode.insertBefore(
|
|
153
|
+
for (const u of h)
|
|
154
|
+
t.parentNode.insertBefore(u, t);
|
|
155
155
|
t.remove();
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
function
|
|
158
|
+
function Z(e, n, a) {
|
|
159
159
|
const t = Array.from(e.rows);
|
|
160
160
|
if (t.length === 0) return !1;
|
|
161
161
|
const i = t[0].querySelector("th") !== null, o = i ? t[0] : null, s = i ? t.slice(1) : t, r = o ? o.offsetHeight : 0;
|
|
@@ -168,17 +168,17 @@ function Q(e, n, a) {
|
|
|
168
168
|
c += g.offsetHeight, h++;
|
|
169
169
|
}
|
|
170
170
|
if (h === 0 || h === s.length) return !1;
|
|
171
|
-
const
|
|
172
|
-
o &&
|
|
171
|
+
const u = e.cloneNode(!1);
|
|
172
|
+
o && u.appendChild(o.cloneNode(!0));
|
|
173
173
|
for (let g = 0; g < h; g++)
|
|
174
|
-
|
|
174
|
+
u.appendChild(s[g].cloneNode(!0));
|
|
175
175
|
const d = e.cloneNode(!1);
|
|
176
176
|
o && d.appendChild(o.cloneNode(!0));
|
|
177
177
|
for (let g = h; g < s.length; g++)
|
|
178
178
|
d.appendChild(s[g].cloneNode(!0));
|
|
179
|
-
return n.insertBefore(
|
|
179
|
+
return n.insertBefore(u, e), n.insertBefore(d, e), e.remove(), !0;
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function K(e, n, a) {
|
|
182
182
|
if (e.tagName === "TABLE" || e.tagName === "IMG") return !1;
|
|
183
183
|
const t = (e.textContent || "").split(/\s+/).filter(Boolean);
|
|
184
184
|
if (t.length < 2) return !1;
|
|
@@ -197,23 +197,23 @@ function Z(e, n, a) {
|
|
|
197
197
|
if (r.remove(), l >= t.length) return !1;
|
|
198
198
|
const c = document.createElement(i);
|
|
199
199
|
c.setAttribute("style", o), c.textContent = t.slice(0, l).join(" ");
|
|
200
|
-
const
|
|
201
|
-
return
|
|
200
|
+
const u = document.createElement(i);
|
|
201
|
+
return u.setAttribute("style", o), u.textContent = t.slice(l).join(" "), n.insertBefore(c, e), n.insertBefore(u, e), e.remove(), !0;
|
|
202
202
|
}
|
|
203
|
-
function
|
|
203
|
+
function T(e, n) {
|
|
204
204
|
let a = 0;
|
|
205
205
|
for (; a < e.children.length; ) {
|
|
206
206
|
const t = e.children[a], i = t.offsetTop, o = i + t.offsetHeight, s = (Math.floor(i / n) + 1) * n;
|
|
207
207
|
if (o > s) {
|
|
208
208
|
const r = s - i;
|
|
209
209
|
if (t.tagName === "TABLE") {
|
|
210
|
-
if (
|
|
210
|
+
if (Z(
|
|
211
211
|
t,
|
|
212
212
|
e,
|
|
213
213
|
r
|
|
214
214
|
))
|
|
215
215
|
continue;
|
|
216
|
-
} else if (
|
|
216
|
+
} else if (K(t, e, r))
|
|
217
217
|
continue;
|
|
218
218
|
if (t.offsetHeight <= n) {
|
|
219
219
|
const l = document.createElement("div");
|
|
@@ -223,11 +223,11 @@ function L(e, n) {
|
|
|
223
223
|
a++;
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
const a =
|
|
228
|
-
|
|
226
|
+
function V(e, n = {}) {
|
|
227
|
+
const a = S(n), t = F(), i = N(e, a.pageWidth);
|
|
228
|
+
I(i);
|
|
229
229
|
const o = R(i, a);
|
|
230
|
-
return
|
|
230
|
+
return L(i, o.pageContentPx), O(i, o.pageContentPx), T(i, o.pageContentPx), {
|
|
231
231
|
clone: i,
|
|
232
232
|
layout: o,
|
|
233
233
|
options: a,
|
|
@@ -236,10 +236,10 @@ function K(e, n = {}) {
|
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
238
|
}
|
|
239
|
-
async function
|
|
240
|
-
const { clone: t, layout: i, options: o, cleanup: s } =
|
|
239
|
+
async function ot(e, n, a = {}) {
|
|
240
|
+
const { clone: t, layout: i, options: o, cleanup: s } = V(n, a);
|
|
241
241
|
try {
|
|
242
|
-
await
|
|
242
|
+
await Q(t), await new Promise((r) => {
|
|
243
243
|
e.html(t, {
|
|
244
244
|
callback: () => r(),
|
|
245
245
|
width: i.contentWidthMm,
|
|
@@ -257,7 +257,7 @@ async function nt(e, n, a = {}) {
|
|
|
257
257
|
}
|
|
258
258
|
return a.marginContent && await $(e, a.marginContent, a), e;
|
|
259
259
|
}
|
|
260
|
-
function
|
|
260
|
+
function j(e, n) {
|
|
261
261
|
switch (e) {
|
|
262
262
|
case "top":
|
|
263
263
|
return { x: 0, y: 0, width: n.pageWidth, height: n.margin.top };
|
|
@@ -279,7 +279,7 @@ function T(e, n) {
|
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
-
async function
|
|
282
|
+
async function k(e, n, a, t) {
|
|
283
283
|
const i = document.createElement("div");
|
|
284
284
|
Object.assign(i.style, {
|
|
285
285
|
position: "fixed",
|
|
@@ -290,7 +290,7 @@ async function j(e, n, a, t) {
|
|
|
290
290
|
overflow: "hidden"
|
|
291
291
|
}), i.appendChild(e), document.body.appendChild(i);
|
|
292
292
|
try {
|
|
293
|
-
return await
|
|
293
|
+
return await P(i, {
|
|
294
294
|
scale: t,
|
|
295
295
|
backgroundColor: null
|
|
296
296
|
});
|
|
@@ -298,14 +298,14 @@ async function j(e, n, a, t) {
|
|
|
298
298
|
i.remove();
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
-
const
|
|
301
|
+
const B = ["top", "right", "bottom", "left"];
|
|
302
302
|
async function q(e, n, a) {
|
|
303
303
|
const t = {};
|
|
304
|
-
for (const i of
|
|
304
|
+
for (const i of B) {
|
|
305
305
|
const o = e[i];
|
|
306
306
|
if (o && typeof o != "function") {
|
|
307
|
-
const s =
|
|
308
|
-
t[i] = await
|
|
307
|
+
const s = j(i, n);
|
|
308
|
+
t[i] = await k(
|
|
309
309
|
o.cloneNode(!0),
|
|
310
310
|
s.width,
|
|
311
311
|
s.height,
|
|
@@ -315,7 +315,7 @@ async function q(e, n, a) {
|
|
|
315
315
|
}
|
|
316
316
|
return t;
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function Y(e, n) {
|
|
319
319
|
return e == null ? n.margin : typeof e == "number" ? { top: e, right: e, bottom: e, left: e } : {
|
|
320
320
|
top: e.top ?? n.margin.top,
|
|
321
321
|
right: e.right ?? n.margin.right,
|
|
@@ -323,7 +323,7 @@ function V(e, n) {
|
|
|
323
323
|
left: e.left ?? n.margin.left
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
|
-
const
|
|
326
|
+
const X = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
|
|
327
327
|
async function D(e, n, a, t, i, o, s, r, l = !1) {
|
|
328
328
|
const h = document.createElement("div");
|
|
329
329
|
Object.assign(h.style, {
|
|
@@ -352,17 +352,17 @@ async function D(e, n, a, t, i, o, s, r, l = !1) {
|
|
|
352
352
|
fontFamily: i,
|
|
353
353
|
fontWeight: o
|
|
354
354
|
}), document.body.appendChild(c);
|
|
355
|
-
const
|
|
355
|
+
const u = c.offsetWidth;
|
|
356
356
|
c.remove();
|
|
357
|
-
const d = Math.ceil(n / (
|
|
357
|
+
const d = Math.ceil(n / (u + r)) + 2;
|
|
358
358
|
for (let g = 0; g < d; g++) {
|
|
359
|
-
const
|
|
360
|
-
|
|
359
|
+
const f = document.createElement("span");
|
|
360
|
+
f.textContent = e, f.style.flexShrink = "0", h.appendChild(f);
|
|
361
361
|
}
|
|
362
362
|
document.body.appendChild(h);
|
|
363
363
|
try {
|
|
364
|
-
return await
|
|
365
|
-
scale:
|
|
364
|
+
return await P(h, {
|
|
365
|
+
scale: 3,
|
|
366
366
|
backgroundColor: null,
|
|
367
367
|
width: Math.ceil(n),
|
|
368
368
|
height: Math.ceil(a)
|
|
@@ -377,93 +377,93 @@ async function U(e, n, a, t, i, o, s) {
|
|
|
377
377
|
color: l = "#000000",
|
|
378
378
|
fontSize: h = 2.5,
|
|
379
379
|
fontFamily: c = "Arial, sans-serif",
|
|
380
|
-
fontWeight:
|
|
381
|
-
} = n, d = h * a, g = (n.gap ?? h * 0.5) * a,
|
|
380
|
+
fontWeight: u = "normal"
|
|
381
|
+
} = n, d = h * a, g = (n.gap ?? h * 0.5) * a, f = d * 0.5, m = Math.ceil(d * 1.5), y = X.test(r), p = Math.round(o - f * 2), C = Math.round(s - f * 2), [w, b] = await Promise.all([
|
|
382
382
|
D(
|
|
383
383
|
r,
|
|
384
384
|
p,
|
|
385
385
|
m,
|
|
386
386
|
d,
|
|
387
387
|
c,
|
|
388
|
-
|
|
388
|
+
u,
|
|
389
389
|
l,
|
|
390
390
|
g,
|
|
391
|
-
|
|
391
|
+
y
|
|
392
392
|
),
|
|
393
393
|
D(
|
|
394
394
|
r,
|
|
395
|
-
|
|
395
|
+
C,
|
|
396
396
|
m,
|
|
397
397
|
d,
|
|
398
398
|
c,
|
|
399
|
-
|
|
399
|
+
u,
|
|
400
400
|
l,
|
|
401
401
|
g,
|
|
402
|
-
|
|
402
|
+
y
|
|
403
403
|
)
|
|
404
|
-
]),
|
|
404
|
+
]), x = Math.round(m / 2);
|
|
405
405
|
e.drawImage(
|
|
406
|
-
|
|
406
|
+
w,
|
|
407
407
|
0,
|
|
408
408
|
0,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
t +
|
|
412
|
-
i -
|
|
409
|
+
w.width,
|
|
410
|
+
w.height,
|
|
411
|
+
t + f,
|
|
412
|
+
i - x,
|
|
413
413
|
p,
|
|
414
414
|
m
|
|
415
415
|
), e.drawImage(
|
|
416
|
-
|
|
416
|
+
w,
|
|
417
417
|
0,
|
|
418
418
|
0,
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
t +
|
|
422
|
-
i + s -
|
|
419
|
+
w.width,
|
|
420
|
+
w.height,
|
|
421
|
+
t + f,
|
|
422
|
+
i + s - x,
|
|
423
423
|
p,
|
|
424
424
|
m
|
|
425
|
-
), e.save(), e.translate(t, i + s -
|
|
426
|
-
|
|
425
|
+
), e.save(), e.translate(t, i + s - f), e.rotate(-Math.PI / 2), e.drawImage(
|
|
426
|
+
b,
|
|
427
427
|
0,
|
|
428
428
|
0,
|
|
429
|
-
|
|
430
|
-
|
|
429
|
+
b.width,
|
|
430
|
+
b.height,
|
|
431
431
|
0,
|
|
432
|
-
-
|
|
433
|
-
|
|
432
|
+
-x,
|
|
433
|
+
C,
|
|
434
434
|
m
|
|
435
|
-
), e.restore(), e.save(), e.translate(t + o, i +
|
|
436
|
-
|
|
435
|
+
), e.restore(), e.save(), e.translate(t + o, i + f), e.rotate(Math.PI / 2), e.drawImage(
|
|
436
|
+
b,
|
|
437
437
|
0,
|
|
438
438
|
0,
|
|
439
|
-
|
|
440
|
-
|
|
439
|
+
b.width,
|
|
440
|
+
b.height,
|
|
441
441
|
0,
|
|
442
|
-
-
|
|
443
|
-
|
|
442
|
+
-x,
|
|
443
|
+
C,
|
|
444
444
|
m
|
|
445
445
|
), e.restore();
|
|
446
446
|
}
|
|
447
|
-
function
|
|
448
|
-
return
|
|
447
|
+
function A(e, n) {
|
|
448
|
+
return Y(e.margin, n);
|
|
449
449
|
}
|
|
450
|
-
async function
|
|
451
|
-
for (const l of
|
|
450
|
+
async function tt(e, n, a, t, i, o, s, r) {
|
|
451
|
+
for (const l of B) {
|
|
452
452
|
const h = n[l];
|
|
453
453
|
if (!h) continue;
|
|
454
|
-
const c =
|
|
455
|
-
let
|
|
456
|
-
typeof h == "function" ?
|
|
454
|
+
const c = j(l, t);
|
|
455
|
+
let u;
|
|
456
|
+
typeof h == "function" ? u = await k(
|
|
457
457
|
h(o, s),
|
|
458
458
|
c.width,
|
|
459
459
|
c.height,
|
|
460
460
|
r
|
|
461
|
-
) :
|
|
462
|
-
|
|
461
|
+
) : u = a[l], e.drawImage(
|
|
462
|
+
u,
|
|
463
463
|
0,
|
|
464
464
|
0,
|
|
465
|
-
|
|
466
|
-
|
|
465
|
+
u.width,
|
|
466
|
+
u.height,
|
|
467
467
|
Math.round(c.x * i),
|
|
468
468
|
Math.round(c.y * i),
|
|
469
469
|
Math.round(c.width * i),
|
|
@@ -471,7 +471,7 @@ async function X(e, n, a, t, i, o, s, r) {
|
|
|
471
471
|
);
|
|
472
472
|
}
|
|
473
473
|
if (n.contentBorder) {
|
|
474
|
-
const { color: l = "#000000", width: h = 0.3 } = n.contentBorder, c =
|
|
474
|
+
const { color: l = "#000000", width: h = 0.3 } = n.contentBorder, c = A(n.contentBorder, t);
|
|
475
475
|
e.strokeStyle = l, e.lineWidth = h * i, e.strokeRect(
|
|
476
476
|
Math.round(c.left * i),
|
|
477
477
|
Math.round(c.top * i),
|
|
@@ -480,7 +480,7 @@ async function X(e, n, a, t, i, o, s, r) {
|
|
|
480
480
|
);
|
|
481
481
|
}
|
|
482
482
|
if (n.textBorder) {
|
|
483
|
-
const l =
|
|
483
|
+
const l = A(n.textBorder, t);
|
|
484
484
|
await U(
|
|
485
485
|
e,
|
|
486
486
|
n.textBorder,
|
|
@@ -492,52 +492,50 @@ async function X(e, n, a, t, i, o, s, r) {
|
|
|
492
492
|
);
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
async function
|
|
496
|
-
const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o =
|
|
497
|
-
r.style.opacity = "1", r.style.left = "-99999px",
|
|
495
|
+
async function it(e, n = {}) {
|
|
496
|
+
const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o = S(n), s = F(), r = N(e, o.pageWidth);
|
|
497
|
+
r.style.opacity = "1", r.style.left = "-99999px", I(r);
|
|
498
498
|
const l = R(r, o);
|
|
499
|
-
|
|
499
|
+
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), G(r);
|
|
500
500
|
try {
|
|
501
|
-
const h = await
|
|
501
|
+
const h = await P(r, {
|
|
502
502
|
scale: i,
|
|
503
503
|
backgroundColor: "#ffffff"
|
|
504
|
-
}), { jsPDF: c } = await import("jspdf"),
|
|
505
|
-
orientation:
|
|
504
|
+
}), { jsPDF: c } = await import("jspdf"), u = o.pageWidth - o.margin.left - o.margin.right, d = o.pageHeight - o.margin.top - o.margin.bottom, g = h.width, f = d / u * g, m = Math.ceil(h.height / f), y = o.pageWidth > o.pageHeight ? "l" : "p", p = new c({
|
|
505
|
+
orientation: y,
|
|
506
506
|
unit: "mm",
|
|
507
507
|
format: [o.pageWidth, o.pageHeight]
|
|
508
|
-
});
|
|
509
|
-
for (let
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
h.height -
|
|
513
|
-
),
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
if (!
|
|
517
|
-
|
|
508
|
+
}), C = g / u, w = Math.round(o.pageWidth * C), b = Math.round(o.pageHeight * C), x = Math.round(o.margin.top * C), E = Math.round(o.margin.left * C);
|
|
509
|
+
for (let H = 0; H < m; H++) {
|
|
510
|
+
const M = Math.min(
|
|
511
|
+
f,
|
|
512
|
+
h.height - H * f
|
|
513
|
+
), W = document.createElement("canvas");
|
|
514
|
+
W.width = w, W.height = b;
|
|
515
|
+
const v = W.getContext("2d");
|
|
516
|
+
if (!v) throw new Error("Could not get canvas context");
|
|
517
|
+
v.fillStyle = "#ffffff", v.fillRect(0, 0, w, b), v.drawImage(
|
|
518
518
|
h,
|
|
519
519
|
0,
|
|
520
|
-
|
|
520
|
+
H * f,
|
|
521
521
|
g,
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
522
|
+
M,
|
|
523
|
+
E,
|
|
524
|
+
x,
|
|
525
525
|
g,
|
|
526
|
-
|
|
526
|
+
M
|
|
527
527
|
);
|
|
528
|
-
const
|
|
528
|
+
const z = W.toDataURL(
|
|
529
529
|
`image/${a.toLowerCase()}`,
|
|
530
530
|
t
|
|
531
531
|
);
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
p.addImage(
|
|
535
|
-
E,
|
|
532
|
+
H > 0 && p.addPage([o.pageWidth, o.pageHeight], y), p.addImage(
|
|
533
|
+
z,
|
|
536
534
|
a,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
535
|
+
0,
|
|
536
|
+
0,
|
|
537
|
+
o.pageWidth,
|
|
538
|
+
o.pageHeight,
|
|
541
539
|
void 0,
|
|
542
540
|
"SLOW"
|
|
543
541
|
);
|
|
@@ -547,57 +545,57 @@ async function ot(e, n = {}) {
|
|
|
547
545
|
r.remove(), s();
|
|
548
546
|
}
|
|
549
547
|
}
|
|
550
|
-
async function
|
|
551
|
-
const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o =
|
|
552
|
-
r.style.opacity = "1", r.style.left = "-99999px",
|
|
548
|
+
async function et(e, n = {}) {
|
|
549
|
+
const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o = S(n), s = F(), r = N(e, o.pageWidth);
|
|
550
|
+
r.style.opacity = "1", r.style.left = "-99999px", I(r);
|
|
553
551
|
const l = R(r, o);
|
|
554
|
-
|
|
552
|
+
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), G(r);
|
|
555
553
|
try {
|
|
556
|
-
const h = await
|
|
554
|
+
const h = await P(r, {
|
|
557
555
|
scale: i,
|
|
558
556
|
backgroundColor: "#ffffff"
|
|
559
|
-
}), c = o.pageWidth - o.margin.left - o.margin.right,
|
|
560
|
-
for (let H = 0; H <
|
|
561
|
-
const
|
|
557
|
+
}), c = o.pageWidth - o.margin.left - o.margin.right, u = o.pageHeight - o.margin.top - o.margin.bottom, d = h.width, g = u / c * d, f = d / c, m = Math.round(o.pageWidth * f), y = Math.round(o.pageHeight * f), p = Math.round(o.margin.top * f), C = Math.round(o.margin.left * f), w = Math.ceil(h.height / g), b = [], { marginContent: x } = n, E = x ? await q(x, o, i) : {};
|
|
558
|
+
for (let H = 0; H < w; H++) {
|
|
559
|
+
const M = Math.min(
|
|
562
560
|
g,
|
|
563
561
|
h.height - H * g
|
|
564
|
-
),
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
if (!
|
|
568
|
-
|
|
562
|
+
), W = document.createElement("canvas");
|
|
563
|
+
W.width = m, W.height = y;
|
|
564
|
+
const v = W.getContext("2d");
|
|
565
|
+
if (!v) throw new Error("Could not get canvas context");
|
|
566
|
+
v.fillStyle = "#ffffff", v.fillRect(0, 0, m, y), v.drawImage(
|
|
569
567
|
h,
|
|
570
568
|
0,
|
|
571
569
|
H * g,
|
|
572
570
|
d,
|
|
573
|
-
|
|
574
|
-
|
|
571
|
+
M,
|
|
572
|
+
C,
|
|
575
573
|
p,
|
|
576
574
|
d,
|
|
577
|
-
|
|
578
|
-
),
|
|
575
|
+
M
|
|
576
|
+
), x && await tt(
|
|
577
|
+
v,
|
|
579
578
|
x,
|
|
580
|
-
w,
|
|
581
579
|
E,
|
|
582
580
|
o,
|
|
583
|
-
|
|
581
|
+
f,
|
|
584
582
|
H + 1,
|
|
585
|
-
|
|
583
|
+
w,
|
|
586
584
|
i
|
|
587
|
-
),
|
|
588
|
-
|
|
585
|
+
), b.push(
|
|
586
|
+
W.toDataURL(
|
|
589
587
|
`image/${a.toLowerCase()}`,
|
|
590
588
|
t
|
|
591
589
|
)
|
|
592
590
|
);
|
|
593
591
|
}
|
|
594
|
-
return
|
|
592
|
+
return b;
|
|
595
593
|
} finally {
|
|
596
594
|
r.remove(), s();
|
|
597
595
|
}
|
|
598
596
|
}
|
|
599
|
-
async function
|
|
600
|
-
const t =
|
|
597
|
+
async function at(e, n, a = {}) {
|
|
598
|
+
const t = S(a), i = await et(e, a);
|
|
601
599
|
n.innerHTML = "", Object.assign(n.style, {
|
|
602
600
|
direction: "ltr",
|
|
603
601
|
width: "fit-content",
|
|
@@ -621,41 +619,41 @@ async function it(e, n, a = {}) {
|
|
|
621
619
|
}
|
|
622
620
|
}
|
|
623
621
|
async function $(e, n, a = {}) {
|
|
624
|
-
const t =
|
|
625
|
-
for (const d of
|
|
622
|
+
const t = S(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 = {};
|
|
623
|
+
for (const d of B)
|
|
626
624
|
h[d] && (c[d] = h[d].toDataURL("image/png"));
|
|
627
|
-
let
|
|
625
|
+
let u;
|
|
628
626
|
if (n.textBorder) {
|
|
629
627
|
const d = document.createElement("canvas");
|
|
630
628
|
d.width = r, d.height = l;
|
|
631
629
|
const g = d.getContext("2d");
|
|
632
630
|
if (g) {
|
|
633
|
-
const
|
|
631
|
+
const f = A(n.textBorder, t);
|
|
634
632
|
await U(
|
|
635
633
|
g,
|
|
636
634
|
n.textBorder,
|
|
637
635
|
s,
|
|
638
|
-
Math.round(
|
|
639
|
-
Math.round(
|
|
640
|
-
Math.round((t.pageWidth -
|
|
641
|
-
Math.round((t.pageHeight -
|
|
642
|
-
),
|
|
636
|
+
Math.round(f.left * s),
|
|
637
|
+
Math.round(f.top * s),
|
|
638
|
+
Math.round((t.pageWidth - f.left - f.right) * s),
|
|
639
|
+
Math.round((t.pageHeight - f.top - f.bottom) * s)
|
|
640
|
+
), u = d.toDataURL("image/png");
|
|
643
641
|
}
|
|
644
642
|
}
|
|
645
643
|
for (let d = 1; d <= i; d++) {
|
|
646
644
|
e.setPage(d);
|
|
647
|
-
for (const g of
|
|
648
|
-
const
|
|
649
|
-
if (!
|
|
650
|
-
const m =
|
|
651
|
-
let
|
|
652
|
-
typeof
|
|
653
|
-
|
|
645
|
+
for (const g of B) {
|
|
646
|
+
const f = n[g];
|
|
647
|
+
if (!f) continue;
|
|
648
|
+
const m = j(g, t);
|
|
649
|
+
let y, p;
|
|
650
|
+
typeof f == "function" ? y = (await k(
|
|
651
|
+
f(d, i),
|
|
654
652
|
m.width,
|
|
655
653
|
m.height,
|
|
656
654
|
o
|
|
657
|
-
)).toDataURL("image/png") : (
|
|
658
|
-
|
|
655
|
+
)).toDataURL("image/png") : (y = c[g], p = `margin-${g}`), e.addImage(
|
|
656
|
+
y,
|
|
659
657
|
"PNG",
|
|
660
658
|
m.x,
|
|
661
659
|
m.y,
|
|
@@ -666,16 +664,16 @@ async function $(e, n, a = {}) {
|
|
|
666
664
|
);
|
|
667
665
|
}
|
|
668
666
|
if (n.contentBorder) {
|
|
669
|
-
const { color: g = "#000000", width:
|
|
670
|
-
e.setDrawColor(g), e.setLineWidth(
|
|
667
|
+
const { color: g = "#000000", width: f = 0.3 } = n.contentBorder, m = A(n.contentBorder, t);
|
|
668
|
+
e.setDrawColor(g), e.setLineWidth(f), e.rect(
|
|
671
669
|
m.left,
|
|
672
670
|
m.top,
|
|
673
671
|
t.pageWidth - m.left - m.right,
|
|
674
672
|
t.pageHeight - m.top - m.bottom
|
|
675
673
|
);
|
|
676
674
|
}
|
|
677
|
-
|
|
678
|
-
|
|
675
|
+
u && e.addImage(
|
|
676
|
+
u,
|
|
679
677
|
"PNG",
|
|
680
678
|
0,
|
|
681
679
|
0,
|
|
@@ -688,18 +686,18 @@ async function $(e, n, a = {}) {
|
|
|
688
686
|
return e;
|
|
689
687
|
}
|
|
690
688
|
export {
|
|
691
|
-
|
|
692
|
-
|
|
689
|
+
J as PAGE_MARGINS,
|
|
690
|
+
_ as PAGE_SIZES,
|
|
693
691
|
$ as addMarginContent,
|
|
694
692
|
R as computeLayout,
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
693
|
+
N as createPrintClone,
|
|
694
|
+
T as insertPageBreakSpacers,
|
|
695
|
+
I as normalizeTableAttributes,
|
|
696
|
+
V as prepare,
|
|
697
|
+
at as previewPageImages,
|
|
698
|
+
ot as renderHTML,
|
|
699
|
+
it as renderImagePDF,
|
|
700
|
+
et as renderPageImages,
|
|
701
|
+
L as splitOversizedTables,
|
|
704
702
|
O as splitOversizedText
|
|
705
703
|
};
|
package/package.json
CHANGED