jspdf-utils 0.1.17 → 0.1.19
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 +52 -40
- package/package.json +1 -1
package/dist/html-to-pdf.js
CHANGED
|
@@ -53,7 +53,19 @@ function N(e, n = 210) {
|
|
|
53
53
|
pointerEvents: "none"
|
|
54
54
|
}), document.body.appendChild(a), a;
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
async function Q(e) {
|
|
57
|
+
const n = Array.from(e.querySelectorAll("img"));
|
|
58
|
+
await Promise.all(
|
|
59
|
+
n.map((a) => {
|
|
60
|
+
if (!(a.complete && a.naturalWidth > 0))
|
|
61
|
+
return new Promise((t) => {
|
|
62
|
+
a.onload = () => t(), a.onerror = () => t();
|
|
63
|
+
});
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
async function q(e) {
|
|
68
|
+
await Q(e);
|
|
57
69
|
const n = e.getBoundingClientRect();
|
|
58
70
|
let a = n.bottom;
|
|
59
71
|
for (const i of e.querySelectorAll("*")) {
|
|
@@ -63,7 +75,7 @@ function G(e) {
|
|
|
63
75
|
const t = a - n.top;
|
|
64
76
|
t > e.offsetHeight && (e.style.minHeight = t + "px");
|
|
65
77
|
}
|
|
66
|
-
async function
|
|
78
|
+
async function Z(e) {
|
|
67
79
|
const n = Array.from(e.querySelectorAll("img"));
|
|
68
80
|
if (n.length === 0) return;
|
|
69
81
|
await Promise.all(
|
|
@@ -155,7 +167,7 @@ function O(e, n) {
|
|
|
155
167
|
t.remove();
|
|
156
168
|
}
|
|
157
169
|
}
|
|
158
|
-
function
|
|
170
|
+
function K(e, n, a) {
|
|
159
171
|
const t = Array.from(e.rows);
|
|
160
172
|
if (t.length === 0) return !1;
|
|
161
173
|
const i = t[0].querySelector("th") !== null, o = i ? t[0] : null, s = i ? t.slice(1) : t, r = o ? o.offsetHeight : 0;
|
|
@@ -178,7 +190,7 @@ function Z(e, n, a) {
|
|
|
178
190
|
d.appendChild(s[g].cloneNode(!0));
|
|
179
191
|
return n.insertBefore(u, e), n.insertBefore(d, e), e.remove(), !0;
|
|
180
192
|
}
|
|
181
|
-
function
|
|
193
|
+
function V(e, n, a) {
|
|
182
194
|
if (e.tagName === "TABLE" || e.tagName === "IMG") return !1;
|
|
183
195
|
const t = (e.textContent || "").split(/\s+/).filter(Boolean);
|
|
184
196
|
if (t.length < 2) return !1;
|
|
@@ -207,13 +219,13 @@ function T(e, n) {
|
|
|
207
219
|
if (o > s) {
|
|
208
220
|
const r = s - i;
|
|
209
221
|
if (t.tagName === "TABLE") {
|
|
210
|
-
if (
|
|
222
|
+
if (K(
|
|
211
223
|
t,
|
|
212
224
|
e,
|
|
213
225
|
r
|
|
214
226
|
))
|
|
215
227
|
continue;
|
|
216
|
-
} else if (
|
|
228
|
+
} else if (V(t, e, r))
|
|
217
229
|
continue;
|
|
218
230
|
if (t.offsetHeight <= n) {
|
|
219
231
|
const l = document.createElement("div");
|
|
@@ -223,7 +235,7 @@ function T(e, n) {
|
|
|
223
235
|
a++;
|
|
224
236
|
}
|
|
225
237
|
}
|
|
226
|
-
function
|
|
238
|
+
function Y(e, n = {}) {
|
|
227
239
|
const a = S(n), t = F(), i = N(e, a.pageWidth);
|
|
228
240
|
I(i);
|
|
229
241
|
const o = R(i, a);
|
|
@@ -236,10 +248,10 @@ function V(e, n = {}) {
|
|
|
236
248
|
}
|
|
237
249
|
};
|
|
238
250
|
}
|
|
239
|
-
async function
|
|
240
|
-
const { clone: t, layout: i, options: o, cleanup: s } =
|
|
251
|
+
async function it(e, n, a = {}) {
|
|
252
|
+
const { clone: t, layout: i, options: o, cleanup: s } = Y(n, a);
|
|
241
253
|
try {
|
|
242
|
-
await
|
|
254
|
+
await Z(t), await new Promise((r) => {
|
|
243
255
|
e.html(t, {
|
|
244
256
|
callback: () => r(),
|
|
245
257
|
width: i.contentWidthMm,
|
|
@@ -298,10 +310,10 @@ async function k(e, n, a, t) {
|
|
|
298
310
|
i.remove();
|
|
299
311
|
}
|
|
300
312
|
}
|
|
301
|
-
const
|
|
302
|
-
async function
|
|
313
|
+
const A = ["top", "right", "bottom", "left"];
|
|
314
|
+
async function G(e, n, a) {
|
|
303
315
|
const t = {};
|
|
304
|
-
for (const i of
|
|
316
|
+
for (const i of A) {
|
|
305
317
|
const o = e[i];
|
|
306
318
|
if (o && typeof o != "function") {
|
|
307
319
|
const s = j(i, n);
|
|
@@ -315,7 +327,7 @@ async function q(e, n, a) {
|
|
|
315
327
|
}
|
|
316
328
|
return t;
|
|
317
329
|
}
|
|
318
|
-
function
|
|
330
|
+
function X(e, n) {
|
|
319
331
|
return e == null ? n.margin : typeof e == "number" ? { top: e, right: e, bottom: e, left: e } : {
|
|
320
332
|
top: e.top ?? n.margin.top,
|
|
321
333
|
right: e.right ?? n.margin.right,
|
|
@@ -323,7 +335,7 @@ function Y(e, n) {
|
|
|
323
335
|
left: e.left ?? n.margin.left
|
|
324
336
|
};
|
|
325
337
|
}
|
|
326
|
-
const
|
|
338
|
+
const tt = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
|
|
327
339
|
async function D(e, n, a, t, i, o, s, r, l = !1) {
|
|
328
340
|
const h = document.createElement("div");
|
|
329
341
|
Object.assign(h.style, {
|
|
@@ -378,7 +390,7 @@ async function U(e, n, a, t, i, o, s) {
|
|
|
378
390
|
fontSize: h = 2.5,
|
|
379
391
|
fontFamily: c = "Arial, sans-serif",
|
|
380
392
|
fontWeight: u = "normal"
|
|
381
|
-
} = n, d = h * a, g = (n.gap ?? h * 0.5) * a, f = d * 0.5, m = Math.ceil(d *
|
|
393
|
+
} = n, d = h * a, g = (n.gap ?? h * 0.5) * a, f = d * 0.5, m = Math.ceil(d * 2.5), y = tt.test(r), p = Math.round(o - f * 2), C = Math.round(s - f * 2), [w, b] = await Promise.all([
|
|
382
394
|
D(
|
|
383
395
|
r,
|
|
384
396
|
p,
|
|
@@ -444,11 +456,11 @@ async function U(e, n, a, t, i, o, s) {
|
|
|
444
456
|
m
|
|
445
457
|
), e.restore();
|
|
446
458
|
}
|
|
447
|
-
function
|
|
448
|
-
return
|
|
459
|
+
function B(e, n) {
|
|
460
|
+
return X(e.margin, n);
|
|
449
461
|
}
|
|
450
|
-
async function
|
|
451
|
-
for (const l of
|
|
462
|
+
async function et(e, n, a, t, i, o, s, r) {
|
|
463
|
+
for (const l of A) {
|
|
452
464
|
const h = n[l];
|
|
453
465
|
if (!h) continue;
|
|
454
466
|
const c = j(l, t);
|
|
@@ -471,7 +483,7 @@ async function tt(e, n, a, t, i, o, s, r) {
|
|
|
471
483
|
);
|
|
472
484
|
}
|
|
473
485
|
if (n.contentBorder) {
|
|
474
|
-
const { color: l = "#000000", width: h = 0.3 } = n.contentBorder, c =
|
|
486
|
+
const { color: l = "#000000", width: h = 0.3 } = n.contentBorder, c = B(n.contentBorder, t);
|
|
475
487
|
e.strokeStyle = l, e.lineWidth = h * i, e.strokeRect(
|
|
476
488
|
Math.round(c.left * i),
|
|
477
489
|
Math.round(c.top * i),
|
|
@@ -480,7 +492,7 @@ async function tt(e, n, a, t, i, o, s, r) {
|
|
|
480
492
|
);
|
|
481
493
|
}
|
|
482
494
|
if (n.textBorder) {
|
|
483
|
-
const l =
|
|
495
|
+
const l = B(n.textBorder, t);
|
|
484
496
|
await U(
|
|
485
497
|
e,
|
|
486
498
|
n.textBorder,
|
|
@@ -492,11 +504,11 @@ async function tt(e, n, a, t, i, o, s, r) {
|
|
|
492
504
|
);
|
|
493
505
|
}
|
|
494
506
|
}
|
|
495
|
-
async function
|
|
507
|
+
async function at(e, n = {}) {
|
|
496
508
|
const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o = S(n), s = F(), r = N(e, o.pageWidth);
|
|
497
509
|
r.style.opacity = "1", r.style.left = "-99999px", I(r);
|
|
498
510
|
const l = R(r, o);
|
|
499
|
-
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx),
|
|
511
|
+
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
|
|
500
512
|
try {
|
|
501
513
|
const h = await P(r, {
|
|
502
514
|
scale: i,
|
|
@@ -545,16 +557,16 @@ async function it(e, n = {}) {
|
|
|
545
557
|
r.remove(), s();
|
|
546
558
|
}
|
|
547
559
|
}
|
|
548
|
-
async function
|
|
560
|
+
async function nt(e, n = {}) {
|
|
549
561
|
const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o = S(n), s = F(), r = N(e, o.pageWidth);
|
|
550
562
|
r.style.opacity = "1", r.style.left = "-99999px", I(r);
|
|
551
563
|
const l = R(r, o);
|
|
552
|
-
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx),
|
|
564
|
+
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
|
|
553
565
|
try {
|
|
554
566
|
const h = await P(r, {
|
|
555
567
|
scale: i,
|
|
556
568
|
backgroundColor: "#ffffff"
|
|
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
|
|
569
|
+
}), 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 G(x, o, i) : {};
|
|
558
570
|
for (let H = 0; H < w; H++) {
|
|
559
571
|
const M = Math.min(
|
|
560
572
|
g,
|
|
@@ -573,7 +585,7 @@ async function et(e, n = {}) {
|
|
|
573
585
|
p,
|
|
574
586
|
d,
|
|
575
587
|
M
|
|
576
|
-
), x && await
|
|
588
|
+
), x && await et(
|
|
577
589
|
v,
|
|
578
590
|
x,
|
|
579
591
|
E,
|
|
@@ -594,8 +606,8 @@ async function et(e, n = {}) {
|
|
|
594
606
|
r.remove(), s();
|
|
595
607
|
}
|
|
596
608
|
}
|
|
597
|
-
async function
|
|
598
|
-
const t = S(a), i = await
|
|
609
|
+
async function rt(e, n, a = {}) {
|
|
610
|
+
const t = S(a), i = await nt(e, a);
|
|
599
611
|
n.innerHTML = "", Object.assign(n.style, {
|
|
600
612
|
direction: "ltr",
|
|
601
613
|
width: "fit-content",
|
|
@@ -619,8 +631,8 @@ async function at(e, n, a = {}) {
|
|
|
619
631
|
}
|
|
620
632
|
}
|
|
621
633
|
async function $(e, n, a = {}) {
|
|
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
|
|
623
|
-
for (const d of
|
|
634
|
+
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 G(n, t, o), c = {};
|
|
635
|
+
for (const d of A)
|
|
624
636
|
h[d] && (c[d] = h[d].toDataURL("image/png"));
|
|
625
637
|
let u;
|
|
626
638
|
if (n.textBorder) {
|
|
@@ -628,7 +640,7 @@ async function $(e, n, a = {}) {
|
|
|
628
640
|
d.width = r, d.height = l;
|
|
629
641
|
const g = d.getContext("2d");
|
|
630
642
|
if (g) {
|
|
631
|
-
const f =
|
|
643
|
+
const f = B(n.textBorder, t);
|
|
632
644
|
await U(
|
|
633
645
|
g,
|
|
634
646
|
n.textBorder,
|
|
@@ -642,7 +654,7 @@ async function $(e, n, a = {}) {
|
|
|
642
654
|
}
|
|
643
655
|
for (let d = 1; d <= i; d++) {
|
|
644
656
|
e.setPage(d);
|
|
645
|
-
for (const g of
|
|
657
|
+
for (const g of A) {
|
|
646
658
|
const f = n[g];
|
|
647
659
|
if (!f) continue;
|
|
648
660
|
const m = j(g, t);
|
|
@@ -664,7 +676,7 @@ async function $(e, n, a = {}) {
|
|
|
664
676
|
);
|
|
665
677
|
}
|
|
666
678
|
if (n.contentBorder) {
|
|
667
|
-
const { color: g = "#000000", width: f = 0.3 } = n.contentBorder, m =
|
|
679
|
+
const { color: g = "#000000", width: f = 0.3 } = n.contentBorder, m = B(n.contentBorder, t);
|
|
668
680
|
e.setDrawColor(g), e.setLineWidth(f), e.rect(
|
|
669
681
|
m.left,
|
|
670
682
|
m.top,
|
|
@@ -693,11 +705,11 @@ export {
|
|
|
693
705
|
N as createPrintClone,
|
|
694
706
|
T as insertPageBreakSpacers,
|
|
695
707
|
I as normalizeTableAttributes,
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
708
|
+
Y as prepare,
|
|
709
|
+
rt as previewPageImages,
|
|
710
|
+
it as renderHTML,
|
|
711
|
+
at as renderImagePDF,
|
|
712
|
+
nt as renderPageImages,
|
|
701
713
|
L as splitOversizedTables,
|
|
702
714
|
O as splitOversizedText
|
|
703
715
|
};
|
package/package.json
CHANGED