jspdf-utils 0.1.19 → 0.1.21
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 +198 -199
- package/package.json +1 -1
package/dist/html-to-pdf.js
CHANGED
|
@@ -37,11 +37,11 @@ function S(e = {}) {
|
|
|
37
37
|
margin: { ...r, ...e.margin }
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function N(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 F(e, n = 210) {
|
|
45
45
|
const a = e.cloneNode(!0);
|
|
46
46
|
return Object.assign(a.style, {
|
|
47
47
|
position: "fixed",
|
|
@@ -68,7 +68,7 @@ async function q(e) {
|
|
|
68
68
|
await Q(e);
|
|
69
69
|
const n = e.getBoundingClientRect();
|
|
70
70
|
let a = n.bottom;
|
|
71
|
-
for (const i of e.querySelectorAll("*")) {
|
|
71
|
+
for (const i of Array.from(e.querySelectorAll("*"))) {
|
|
72
72
|
const o = i.getBoundingClientRect().bottom;
|
|
73
73
|
o > a && (a = o);
|
|
74
74
|
}
|
|
@@ -94,23 +94,23 @@ async function Z(e) {
|
|
|
94
94
|
continue;
|
|
95
95
|
const l = document.createElement("canvas");
|
|
96
96
|
l.width = s, l.height = r;
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
97
|
+
const g = l.getContext("2d");
|
|
98
|
+
if (g)
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
g.drawImage(t, 0, 0, s, r), t.style.width = i + "px", t.style.height = o + "px", t.src = l.toDataURL("image/png");
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function E() {
|
|
106
106
|
const e = document.createElement("style");
|
|
107
107
|
return e.setAttribute("data-jspdf-utils", ""), e.textContent = "img { display: inline !important; }", document.head.appendChild(e), () => e.remove();
|
|
108
108
|
}
|
|
109
109
|
function I(e) {
|
|
110
|
-
for (const n of e.querySelectorAll("table")) {
|
|
110
|
+
for (const n of Array.from(e.querySelectorAll("table"))) {
|
|
111
111
|
const a = n.getAttribute("cellpadding");
|
|
112
112
|
if (a) {
|
|
113
|
-
for (const t of n.querySelectorAll("th, td"))
|
|
113
|
+
for (const t of Array.from(n.querySelectorAll("th, td")))
|
|
114
114
|
t.style.padding || (t.style.padding = a + "px");
|
|
115
115
|
n.removeAttribute("cellpadding");
|
|
116
116
|
}
|
|
@@ -123,18 +123,18 @@ function L(e, n) {
|
|
|
123
123
|
if (a.offsetHeight <= n) continue;
|
|
124
124
|
const t = Array.from(a.rows);
|
|
125
125
|
if (t.length === 0) continue;
|
|
126
|
-
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,
|
|
127
|
-
let
|
|
128
|
-
for (const
|
|
129
|
-
const
|
|
130
|
-
|
|
126
|
+
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, g = [];
|
|
127
|
+
let h = [], d = 0;
|
|
128
|
+
for (const u of s) {
|
|
129
|
+
const c = u.offsetHeight;
|
|
130
|
+
d + c > l && h.length > 0 && (g.push(h), h = [], d = 0), h.push(u), d += c;
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
for (const
|
|
134
|
-
const
|
|
135
|
-
o &&
|
|
136
|
-
for (const f of
|
|
137
|
-
a.parentNode.insertBefore(
|
|
132
|
+
h.length > 0 && g.push(h);
|
|
133
|
+
for (const u of g) {
|
|
134
|
+
const c = a.cloneNode(!1);
|
|
135
|
+
o && c.appendChild(o.cloneNode(!0));
|
|
136
|
+
for (const f of u) c.appendChild(f.cloneNode(!0));
|
|
137
|
+
a.parentNode.insertBefore(c, a);
|
|
138
138
|
}
|
|
139
139
|
a.remove();
|
|
140
140
|
}
|
|
@@ -150,20 +150,20 @@ function O(e, n) {
|
|
|
150
150
|
visibility: "hidden",
|
|
151
151
|
width: s
|
|
152
152
|
}), e.appendChild(l);
|
|
153
|
-
const
|
|
154
|
-
let
|
|
155
|
-
for (;
|
|
156
|
-
let
|
|
157
|
-
for (;
|
|
158
|
-
const f = Math.ceil((
|
|
159
|
-
l.textContent = r.slice(
|
|
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
160
|
}
|
|
161
|
-
const
|
|
162
|
-
|
|
161
|
+
const c = document.createElement(i);
|
|
162
|
+
c.setAttribute("style", o), c.textContent = r.slice(h, d).join(" "), g.push(c), h = d;
|
|
163
163
|
}
|
|
164
164
|
l.remove();
|
|
165
|
-
for (const
|
|
166
|
-
t.parentNode.insertBefore(
|
|
165
|
+
for (const d of g)
|
|
166
|
+
t.parentNode.insertBefore(d, t);
|
|
167
167
|
t.remove();
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -174,21 +174,21 @@ function K(e, n, a) {
|
|
|
174
174
|
if (s.length < 2) return !1;
|
|
175
175
|
const l = a - r - 2;
|
|
176
176
|
if (l <= 0) return !1;
|
|
177
|
-
let
|
|
178
|
-
for (const
|
|
179
|
-
if (
|
|
180
|
-
|
|
177
|
+
let g = 0, h = 0;
|
|
178
|
+
for (const c of s) {
|
|
179
|
+
if (h + c.offsetHeight > l) break;
|
|
180
|
+
h += c.offsetHeight, g++;
|
|
181
181
|
}
|
|
182
|
-
if (
|
|
183
|
-
const u = e.cloneNode(!1);
|
|
184
|
-
o && u.appendChild(o.cloneNode(!0));
|
|
185
|
-
for (let g = 0; g < h; g++)
|
|
186
|
-
u.appendChild(s[g].cloneNode(!0));
|
|
182
|
+
if (g === 0 || g === s.length) return !1;
|
|
187
183
|
const d = e.cloneNode(!1);
|
|
188
184
|
o && d.appendChild(o.cloneNode(!0));
|
|
189
|
-
for (let
|
|
190
|
-
d.appendChild(s[
|
|
191
|
-
|
|
185
|
+
for (let c = 0; c < g; c++)
|
|
186
|
+
d.appendChild(s[c].cloneNode(!0));
|
|
187
|
+
const u = e.cloneNode(!1);
|
|
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
192
|
}
|
|
193
193
|
function V(e, n, a) {
|
|
194
194
|
if (e.tagName === "TABLE" || e.tagName === "IMG") return !1;
|
|
@@ -201,16 +201,16 @@ function V(e, n, a) {
|
|
|
201
201
|
width: s
|
|
202
202
|
}), n.appendChild(r), r.textContent = t[0], r.offsetHeight > a)
|
|
203
203
|
return r.remove(), !1;
|
|
204
|
-
let l = 1,
|
|
205
|
-
for (; l <
|
|
206
|
-
const
|
|
207
|
-
r.textContent = t.slice(0,
|
|
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
208
|
}
|
|
209
209
|
if (r.remove(), l >= t.length) return !1;
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
return
|
|
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;
|
|
214
214
|
}
|
|
215
215
|
function T(e, n) {
|
|
216
216
|
let a = 0;
|
|
@@ -236,9 +236,9 @@ function T(e, n) {
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
function Y(e, n = {}) {
|
|
239
|
-
const a = S(n), t =
|
|
239
|
+
const a = S(n), t = E(), i = F(e, a.pageWidth);
|
|
240
240
|
I(i);
|
|
241
|
-
const o =
|
|
241
|
+
const o = N(i, a);
|
|
242
242
|
return L(i, o.pageContentPx), O(i, o.pageContentPx), T(i, o.pageContentPx), {
|
|
243
243
|
clone: i,
|
|
244
244
|
layout: o,
|
|
@@ -291,7 +291,7 @@ function j(e, n) {
|
|
|
291
291
|
};
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
async function
|
|
294
|
+
async function D(e, n, a, t) {
|
|
295
295
|
const i = document.createElement("div");
|
|
296
296
|
Object.assign(i.style, {
|
|
297
297
|
position: "fixed",
|
|
@@ -317,7 +317,7 @@ async function G(e, n, a) {
|
|
|
317
317
|
const o = e[i];
|
|
318
318
|
if (o && typeof o != "function") {
|
|
319
319
|
const s = j(i, n);
|
|
320
|
-
t[i] = await
|
|
320
|
+
t[i] = await D(
|
|
321
321
|
o.cloneNode(!0),
|
|
322
322
|
s.width,
|
|
323
323
|
s.height,
|
|
@@ -336,9 +336,9 @@ function X(e, n) {
|
|
|
336
336
|
};
|
|
337
337
|
}
|
|
338
338
|
const tt = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
|
|
339
|
-
async function
|
|
340
|
-
const
|
|
341
|
-
Object.assign(
|
|
339
|
+
async function k(e, n, a, t, i, o, s, r, l = !1) {
|
|
340
|
+
const g = document.createElement("div");
|
|
341
|
+
Object.assign(g.style, {
|
|
342
342
|
position: "fixed",
|
|
343
343
|
left: "-99999px",
|
|
344
344
|
top: "0",
|
|
@@ -355,104 +355,104 @@ async function D(e, n, a, t, i, o, s, r, l = !1) {
|
|
|
355
355
|
gap: `${r}px`,
|
|
356
356
|
direction: l ? "rtl" : "ltr"
|
|
357
357
|
});
|
|
358
|
-
const
|
|
359
|
-
|
|
358
|
+
const h = document.createElement("span");
|
|
359
|
+
h.textContent = e, Object.assign(h.style, {
|
|
360
360
|
position: "absolute",
|
|
361
361
|
visibility: "hidden",
|
|
362
362
|
whiteSpace: "nowrap",
|
|
363
363
|
fontSize: `${t}px`,
|
|
364
364
|
fontFamily: i,
|
|
365
365
|
fontWeight: o
|
|
366
|
-
}), document.body.appendChild(
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
for (let
|
|
366
|
+
}), document.body.appendChild(h);
|
|
367
|
+
const d = h.offsetWidth;
|
|
368
|
+
h.remove();
|
|
369
|
+
const u = Math.ceil(n / (d + r)) + 2;
|
|
370
|
+
for (let c = 0; c < u; c++) {
|
|
371
371
|
const f = document.createElement("span");
|
|
372
|
-
f.textContent = e, f.style.flexShrink = "0",
|
|
372
|
+
f.textContent = e, f.style.flexShrink = "0", g.appendChild(f);
|
|
373
373
|
}
|
|
374
|
-
document.body.appendChild(
|
|
374
|
+
document.body.appendChild(g);
|
|
375
375
|
try {
|
|
376
|
-
return await P(
|
|
376
|
+
return await P(g, {
|
|
377
377
|
scale: 3,
|
|
378
378
|
backgroundColor: null,
|
|
379
379
|
width: Math.ceil(n),
|
|
380
380
|
height: Math.ceil(a)
|
|
381
381
|
});
|
|
382
382
|
} finally {
|
|
383
|
-
|
|
383
|
+
g.remove();
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
async function U(e, n, a, t, i, o, s) {
|
|
387
387
|
const {
|
|
388
388
|
text: r,
|
|
389
389
|
color: l = "#000000",
|
|
390
|
-
fontSize:
|
|
391
|
-
fontFamily:
|
|
392
|
-
fontWeight:
|
|
393
|
-
} = n,
|
|
394
|
-
|
|
390
|
+
fontSize: g = 2.5,
|
|
391
|
+
fontFamily: h = "Arial, sans-serif",
|
|
392
|
+
fontWeight: d = "normal"
|
|
393
|
+
} = n, u = g * a, c = (n.gap ?? g * 0.5) * a, f = u * 0.5, m = Math.ceil(u * 2.5), p = tt.test(r), y = Math.round(o - f * 2), w = Math.round(s - f * 2), [b, C] = await Promise.all([
|
|
394
|
+
k(
|
|
395
395
|
r,
|
|
396
|
-
|
|
396
|
+
y,
|
|
397
397
|
m,
|
|
398
|
-
d,
|
|
399
|
-
c,
|
|
400
398
|
u,
|
|
399
|
+
h,
|
|
400
|
+
d,
|
|
401
401
|
l,
|
|
402
|
-
|
|
403
|
-
|
|
402
|
+
c,
|
|
403
|
+
p
|
|
404
404
|
),
|
|
405
|
-
|
|
405
|
+
k(
|
|
406
406
|
r,
|
|
407
|
-
|
|
407
|
+
w,
|
|
408
408
|
m,
|
|
409
|
-
d,
|
|
410
|
-
c,
|
|
411
409
|
u,
|
|
410
|
+
h,
|
|
411
|
+
d,
|
|
412
412
|
l,
|
|
413
|
-
|
|
414
|
-
|
|
413
|
+
c,
|
|
414
|
+
p
|
|
415
415
|
)
|
|
416
416
|
]), x = Math.round(m / 2);
|
|
417
417
|
e.drawImage(
|
|
418
|
-
|
|
418
|
+
b,
|
|
419
419
|
0,
|
|
420
420
|
0,
|
|
421
|
-
|
|
422
|
-
|
|
421
|
+
b.width,
|
|
422
|
+
b.height,
|
|
423
423
|
t + f,
|
|
424
424
|
i - x,
|
|
425
|
-
|
|
425
|
+
y,
|
|
426
426
|
m
|
|
427
427
|
), e.drawImage(
|
|
428
|
-
|
|
428
|
+
b,
|
|
429
429
|
0,
|
|
430
430
|
0,
|
|
431
|
-
|
|
432
|
-
|
|
431
|
+
b.width,
|
|
432
|
+
b.height,
|
|
433
433
|
t + f,
|
|
434
434
|
i + s - x,
|
|
435
|
-
|
|
435
|
+
y,
|
|
436
436
|
m
|
|
437
437
|
), e.save(), e.translate(t, i + s - f), e.rotate(-Math.PI / 2), e.drawImage(
|
|
438
|
-
|
|
438
|
+
C,
|
|
439
439
|
0,
|
|
440
440
|
0,
|
|
441
|
-
|
|
442
|
-
|
|
441
|
+
C.width,
|
|
442
|
+
C.height,
|
|
443
443
|
0,
|
|
444
444
|
-x,
|
|
445
|
-
|
|
445
|
+
w,
|
|
446
446
|
m
|
|
447
447
|
), e.restore(), e.save(), e.translate(t + o, i + f), e.rotate(Math.PI / 2), e.drawImage(
|
|
448
|
-
|
|
448
|
+
C,
|
|
449
449
|
0,
|
|
450
450
|
0,
|
|
451
|
-
|
|
452
|
-
|
|
451
|
+
C.width,
|
|
452
|
+
C.height,
|
|
453
453
|
0,
|
|
454
454
|
-x,
|
|
455
|
-
|
|
455
|
+
w,
|
|
456
456
|
m
|
|
457
457
|
), e.restore();
|
|
458
458
|
}
|
|
@@ -461,34 +461,34 @@ function B(e, n) {
|
|
|
461
461
|
}
|
|
462
462
|
async function et(e, n, a, t, i, o, s, r) {
|
|
463
463
|
for (const l of A) {
|
|
464
|
-
const
|
|
465
|
-
if (!
|
|
466
|
-
const
|
|
467
|
-
let
|
|
468
|
-
typeof
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
464
|
+
const g = n[l];
|
|
465
|
+
if (!g) continue;
|
|
466
|
+
const h = j(l, t);
|
|
467
|
+
let d;
|
|
468
|
+
typeof g == "function" ? d = await D(
|
|
469
|
+
g(o, s),
|
|
470
|
+
h.width,
|
|
471
|
+
h.height,
|
|
472
472
|
r
|
|
473
|
-
) :
|
|
474
|
-
|
|
473
|
+
) : d = a[l], e.drawImage(
|
|
474
|
+
d,
|
|
475
475
|
0,
|
|
476
476
|
0,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
Math.round(
|
|
480
|
-
Math.round(
|
|
481
|
-
Math.round(
|
|
482
|
-
Math.round(
|
|
477
|
+
d.width,
|
|
478
|
+
d.height,
|
|
479
|
+
Math.round(h.x * i),
|
|
480
|
+
Math.round(h.y * i),
|
|
481
|
+
Math.round(h.width * i),
|
|
482
|
+
Math.round(h.height * i)
|
|
483
483
|
);
|
|
484
484
|
}
|
|
485
485
|
if (n.contentBorder) {
|
|
486
|
-
const { color: l = "#000000", width:
|
|
487
|
-
e.strokeStyle = l, e.lineWidth =
|
|
488
|
-
Math.round(
|
|
489
|
-
Math.round(
|
|
490
|
-
Math.round((t.pageWidth -
|
|
491
|
-
Math.round((t.pageHeight -
|
|
486
|
+
const { color: l = "#000000", width: g = 0.3 } = n.contentBorder, h = B(n.contentBorder, t);
|
|
487
|
+
e.strokeStyle = l, e.lineWidth = g * i, e.strokeRect(
|
|
488
|
+
Math.round(h.left * i),
|
|
489
|
+
Math.round(h.top * i),
|
|
490
|
+
Math.round((t.pageWidth - h.left - h.right) * i),
|
|
491
|
+
Math.round((t.pageHeight - h.top - h.bottom) * i)
|
|
492
492
|
);
|
|
493
493
|
}
|
|
494
494
|
if (n.textBorder) {
|
|
@@ -505,43 +505,43 @@ async function et(e, n, a, t, i, o, s, r) {
|
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
async function at(e, n = {}) {
|
|
508
|
-
const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o = S(n), s =
|
|
508
|
+
const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o = S(n), s = E(), r = F(e, o.pageWidth);
|
|
509
509
|
r.style.opacity = "1", r.style.left = "-99999px", I(r);
|
|
510
|
-
const l =
|
|
510
|
+
const l = N(r, o);
|
|
511
511
|
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
|
|
512
512
|
try {
|
|
513
|
-
const
|
|
513
|
+
const g = await P(r, {
|
|
514
514
|
scale: i,
|
|
515
515
|
backgroundColor: "#ffffff"
|
|
516
|
-
}), { jsPDF:
|
|
517
|
-
orientation:
|
|
516
|
+
}), { jsPDF: h } = await import("jspdf"), d = o.pageWidth - o.margin.left - o.margin.right, u = o.pageHeight - o.margin.top - o.margin.bottom, c = g.width, f = u / d * c, m = Math.ceil(g.height / f), p = o.pageWidth > o.pageHeight ? "l" : "p", y = new h({
|
|
517
|
+
orientation: p,
|
|
518
518
|
unit: "mm",
|
|
519
519
|
format: [o.pageWidth, o.pageHeight]
|
|
520
|
-
}),
|
|
520
|
+
}), w = c / d, b = Math.round(o.pageWidth * w), C = Math.round(o.pageHeight * w), x = Math.round(o.margin.top * w), R = Math.round(o.margin.left * w);
|
|
521
521
|
for (let H = 0; H < m; H++) {
|
|
522
522
|
const M = Math.min(
|
|
523
523
|
f,
|
|
524
|
-
|
|
524
|
+
g.height - H * f
|
|
525
525
|
), W = document.createElement("canvas");
|
|
526
|
-
W.width =
|
|
526
|
+
W.width = b, W.height = C;
|
|
527
527
|
const v = W.getContext("2d");
|
|
528
528
|
if (!v) throw new Error("Could not get canvas context");
|
|
529
|
-
v.fillStyle = "#ffffff", v.fillRect(0, 0,
|
|
530
|
-
|
|
529
|
+
v.fillStyle = "#ffffff", v.fillRect(0, 0, b, C), v.drawImage(
|
|
530
|
+
g,
|
|
531
531
|
0,
|
|
532
532
|
H * f,
|
|
533
|
-
|
|
533
|
+
c,
|
|
534
534
|
M,
|
|
535
|
-
|
|
535
|
+
R,
|
|
536
536
|
x,
|
|
537
|
-
|
|
537
|
+
c,
|
|
538
538
|
M
|
|
539
539
|
);
|
|
540
540
|
const z = W.toDataURL(
|
|
541
541
|
`image/${a.toLowerCase()}`,
|
|
542
542
|
t
|
|
543
543
|
);
|
|
544
|
-
H > 0 &&
|
|
544
|
+
H > 0 && y.addPage([o.pageWidth, o.pageHeight], p), y.addImage(
|
|
545
545
|
z,
|
|
546
546
|
a,
|
|
547
547
|
0,
|
|
@@ -552,56 +552,56 @@ async function at(e, n = {}) {
|
|
|
552
552
|
"SLOW"
|
|
553
553
|
);
|
|
554
554
|
}
|
|
555
|
-
return n.marginContent && await $(
|
|
555
|
+
return n.marginContent && await $(y, n.marginContent, n), y;
|
|
556
556
|
} finally {
|
|
557
557
|
r.remove(), s();
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
560
|
async function nt(e, n = {}) {
|
|
561
|
-
const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o = S(n), s =
|
|
561
|
+
const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o = S(n), s = E(), r = F(e, o.pageWidth);
|
|
562
562
|
r.style.opacity = "1", r.style.left = "-99999px", I(r);
|
|
563
|
-
const l =
|
|
563
|
+
const l = N(r, o);
|
|
564
564
|
L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
|
|
565
565
|
try {
|
|
566
|
-
const
|
|
566
|
+
const g = await P(r, {
|
|
567
567
|
scale: i,
|
|
568
568
|
backgroundColor: "#ffffff"
|
|
569
|
-
}),
|
|
570
|
-
for (let H = 0; H <
|
|
569
|
+
}), h = o.pageWidth - o.margin.left - o.margin.right, d = o.pageHeight - o.margin.top - o.margin.bottom, u = g.width, c = d / h * u, f = u / h, m = Math.round(o.pageWidth * f), p = Math.round(o.pageHeight * f), y = Math.round(o.margin.top * f), w = Math.round(o.margin.left * f), b = Math.ceil(g.height / c), C = [], { marginContent: x } = n, R = x ? await G(x, o, i) : {};
|
|
570
|
+
for (let H = 0; H < b; H++) {
|
|
571
571
|
const M = Math.min(
|
|
572
|
-
|
|
573
|
-
|
|
572
|
+
c,
|
|
573
|
+
g.height - H * c
|
|
574
574
|
), W = document.createElement("canvas");
|
|
575
|
-
W.width = m, W.height =
|
|
575
|
+
W.width = m, W.height = p;
|
|
576
576
|
const v = W.getContext("2d");
|
|
577
577
|
if (!v) throw new Error("Could not get canvas context");
|
|
578
|
-
v.fillStyle = "#ffffff", v.fillRect(0, 0, m,
|
|
579
|
-
|
|
578
|
+
v.fillStyle = "#ffffff", v.fillRect(0, 0, m, p), v.drawImage(
|
|
579
|
+
g,
|
|
580
580
|
0,
|
|
581
|
-
H *
|
|
582
|
-
|
|
581
|
+
H * c,
|
|
582
|
+
u,
|
|
583
583
|
M,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
584
|
+
w,
|
|
585
|
+
y,
|
|
586
|
+
u,
|
|
587
587
|
M
|
|
588
588
|
), x && await et(
|
|
589
589
|
v,
|
|
590
590
|
x,
|
|
591
|
-
|
|
591
|
+
R,
|
|
592
592
|
o,
|
|
593
593
|
f,
|
|
594
594
|
H + 1,
|
|
595
|
-
|
|
595
|
+
b,
|
|
596
596
|
i
|
|
597
|
-
),
|
|
597
|
+
), C.push(
|
|
598
598
|
W.toDataURL(
|
|
599
599
|
`image/${a.toLowerCase()}`,
|
|
600
600
|
t
|
|
601
601
|
)
|
|
602
602
|
);
|
|
603
603
|
}
|
|
604
|
-
return
|
|
604
|
+
return C;
|
|
605
605
|
} finally {
|
|
606
606
|
r.remove(), s();
|
|
607
607
|
}
|
|
@@ -623,65 +623,64 @@ async function rt(e, n, a = {}) {
|
|
|
623
623
|
maxWidth: "100%",
|
|
624
624
|
height: "auto",
|
|
625
625
|
boxSizing: "border-box",
|
|
626
|
-
display: "block",
|
|
627
626
|
border: "1px solid #bbb",
|
|
628
627
|
boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
|
|
629
628
|
marginBottom: "16px"
|
|
630
|
-
}), n.appendChild(s);
|
|
629
|
+
}), s.style.setProperty("display", "inline", "important"), n.appendChild(s);
|
|
631
630
|
}
|
|
632
631
|
}
|
|
633
632
|
async function $(e, n, a = {}) {
|
|
634
|
-
const t = S(a), i = e.getNumberOfPages(), o =
|
|
635
|
-
for (const
|
|
636
|
-
h[
|
|
633
|
+
const t = S(a), i = e.getNumberOfPages(), o = 4, s = o * (96 / 25.4), r = E(), l = Math.round(t.pageWidth * s), g = Math.round(t.pageHeight * s), h = await G(n, t, o), d = {};
|
|
634
|
+
for (const c of A)
|
|
635
|
+
h[c] && (d[c] = h[c].toDataURL("image/png"));
|
|
637
636
|
let u;
|
|
638
637
|
if (n.textBorder) {
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
if (
|
|
643
|
-
const
|
|
638
|
+
const c = document.createElement("canvas");
|
|
639
|
+
c.width = l, c.height = g;
|
|
640
|
+
const f = c.getContext("2d");
|
|
641
|
+
if (f) {
|
|
642
|
+
const m = B(n.textBorder, t);
|
|
644
643
|
await U(
|
|
645
|
-
|
|
644
|
+
f,
|
|
646
645
|
n.textBorder,
|
|
647
646
|
s,
|
|
648
|
-
Math.round(
|
|
649
|
-
Math.round(
|
|
650
|
-
Math.round((t.pageWidth -
|
|
651
|
-
Math.round((t.pageHeight -
|
|
652
|
-
), u =
|
|
647
|
+
Math.round(m.left * s),
|
|
648
|
+
Math.round(m.top * s),
|
|
649
|
+
Math.round((t.pageWidth - m.left - m.right) * s),
|
|
650
|
+
Math.round((t.pageHeight - m.top - m.bottom) * s)
|
|
651
|
+
), u = c.toDataURL("image/png");
|
|
653
652
|
}
|
|
654
653
|
}
|
|
655
|
-
for (let
|
|
656
|
-
e.setPage(
|
|
657
|
-
for (const
|
|
658
|
-
const
|
|
659
|
-
if (!
|
|
660
|
-
const
|
|
661
|
-
let y,
|
|
662
|
-
typeof
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
654
|
+
for (let c = 1; c <= i; c++) {
|
|
655
|
+
e.setPage(c);
|
|
656
|
+
for (const f of A) {
|
|
657
|
+
const m = n[f];
|
|
658
|
+
if (!m) continue;
|
|
659
|
+
const p = j(f, t);
|
|
660
|
+
let y, w;
|
|
661
|
+
typeof m == "function" ? y = (await D(
|
|
662
|
+
m(c, i),
|
|
663
|
+
p.width,
|
|
664
|
+
p.height,
|
|
666
665
|
o
|
|
667
|
-
)).toDataURL("image/png") : (y =
|
|
666
|
+
)).toDataURL("image/png") : (y = d[f], w = `margin-${f}`), e.addImage(
|
|
668
667
|
y,
|
|
669
668
|
"PNG",
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
669
|
+
p.x,
|
|
670
|
+
p.y,
|
|
671
|
+
p.width,
|
|
672
|
+
p.height,
|
|
673
|
+
w,
|
|
675
674
|
"SLOW"
|
|
676
675
|
);
|
|
677
676
|
}
|
|
678
677
|
if (n.contentBorder) {
|
|
679
|
-
const { color:
|
|
680
|
-
e.setDrawColor(
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
t.pageWidth -
|
|
684
|
-
t.pageHeight -
|
|
678
|
+
const { color: f = "#000000", width: m = 0.3 } = n.contentBorder, p = B(n.contentBorder, t);
|
|
679
|
+
e.setDrawColor(f), e.setLineWidth(m), e.rect(
|
|
680
|
+
p.left,
|
|
681
|
+
p.top,
|
|
682
|
+
t.pageWidth - p.left - p.right,
|
|
683
|
+
t.pageHeight - p.top - p.bottom
|
|
685
684
|
);
|
|
686
685
|
}
|
|
687
686
|
u && e.addImage(
|
|
@@ -695,14 +694,14 @@ async function $(e, n, a = {}) {
|
|
|
695
694
|
"SLOW"
|
|
696
695
|
);
|
|
697
696
|
}
|
|
698
|
-
return e;
|
|
697
|
+
return r(), e;
|
|
699
698
|
}
|
|
700
699
|
export {
|
|
701
700
|
J as PAGE_MARGINS,
|
|
702
701
|
_ as PAGE_SIZES,
|
|
703
702
|
$ as addMarginContent,
|
|
704
|
-
|
|
705
|
-
|
|
703
|
+
N as computeLayout,
|
|
704
|
+
F as createPrintClone,
|
|
706
705
|
T as insertPageBreakSpacers,
|
|
707
706
|
I as normalizeTableAttributes,
|
|
708
707
|
Y as prepare,
|
package/package.json
CHANGED