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