jspdf-utils 0.1.14 → 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 +445 -370
- 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 z = {
|
|
3
3
|
a0: [841, 1189],
|
|
4
4
|
a1: [594, 841],
|
|
5
5
|
a2: [420, 594],
|
|
@@ -22,559 +22,594 @@ const q = {
|
|
|
22
22
|
legal: 25.4,
|
|
23
23
|
tabloid: 25
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
top:
|
|
28
|
-
right:
|
|
29
|
-
bottom:
|
|
30
|
-
left:
|
|
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
|
+
top: s,
|
|
28
|
+
right: s,
|
|
29
|
+
bottom: s,
|
|
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
|
-
pageHeight:
|
|
37
|
-
margin: { ...r, ...
|
|
36
|
+
pageHeight: o,
|
|
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
|
|
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 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");
|
|
65
|
+
}
|
|
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
|
+
}
|
|
56
93
|
function N() {
|
|
57
|
-
const
|
|
58
|
-
return
|
|
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();
|
|
59
96
|
}
|
|
60
|
-
function
|
|
61
|
-
for (const
|
|
62
|
-
const a =
|
|
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
|
|
79
|
-
for (const
|
|
80
|
-
const
|
|
81
|
-
|
|
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;
|
|
116
|
+
for (const d of s) {
|
|
117
|
+
const g = d.offsetHeight;
|
|
118
|
+
f + g > l && c.length > 0 && (h.push(c), c = [], f = 0), c.push(d), f += g;
|
|
82
119
|
}
|
|
83
|
-
|
|
84
|
-
for (const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
for (const u of
|
|
88
|
-
a.parentNode.insertBefore(
|
|
120
|
+
c.length > 0 && h.push(c);
|
|
121
|
+
for (const d of h) {
|
|
122
|
+
const g = a.cloneNode(!1);
|
|
123
|
+
o && g.appendChild(o.cloneNode(!0));
|
|
124
|
+
for (const u of d) g.appendChild(u.cloneNode(!0));
|
|
125
|
+
a.parentNode.insertBefore(g, a);
|
|
89
126
|
}
|
|
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
|
-
width:
|
|
103
|
-
}),
|
|
104
|
-
const
|
|
105
|
-
let
|
|
106
|
-
for (;
|
|
107
|
-
let
|
|
108
|
-
for (;
|
|
109
|
-
const u = Math.ceil((
|
|
110
|
-
|
|
139
|
+
width: s
|
|
140
|
+
}), e.appendChild(l);
|
|
141
|
+
const h = [];
|
|
142
|
+
let c = 0;
|
|
143
|
+
for (; c < r.length; ) {
|
|
144
|
+
let f = c + 1, d = r.length;
|
|
145
|
+
for (; f < d; ) {
|
|
146
|
+
const u = Math.ceil((f + d) / 2);
|
|
147
|
+
l.textContent = r.slice(c, u).join(" "), l.offsetHeight <= n ? f = u : d = u - 1;
|
|
111
148
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
149
|
+
const g = document.createElement(i);
|
|
150
|
+
g.setAttribute("style", o), g.textContent = r.slice(c, f).join(" "), h.push(g), c = f;
|
|
114
151
|
}
|
|
115
|
-
|
|
116
|
-
for (const
|
|
117
|
-
|
|
118
|
-
|
|
152
|
+
l.remove();
|
|
153
|
+
for (const f of h)
|
|
154
|
+
t.parentNode.insertBefore(f, t);
|
|
155
|
+
t.remove();
|
|
119
156
|
}
|
|
120
157
|
}
|
|
121
|
-
function
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
const i =
|
|
125
|
-
if (
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
-
let
|
|
129
|
-
for (const
|
|
130
|
-
if (
|
|
131
|
-
|
|
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;
|
|
162
|
+
if (s.length < 2) return !1;
|
|
163
|
+
const l = a - r - 2;
|
|
164
|
+
if (l <= 0) return !1;
|
|
165
|
+
let h = 0, c = 0;
|
|
166
|
+
for (const g of s) {
|
|
167
|
+
if (c + g.offsetHeight > l) break;
|
|
168
|
+
c += g.offsetHeight, h++;
|
|
132
169
|
}
|
|
133
|
-
if (
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
for (let
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
for (let
|
|
141
|
-
|
|
142
|
-
return
|
|
170
|
+
if (h === 0 || h === s.length) return !1;
|
|
171
|
+
const f = e.cloneNode(!1);
|
|
172
|
+
o && f.appendChild(o.cloneNode(!0));
|
|
173
|
+
for (let g = 0; g < h; g++)
|
|
174
|
+
f.appendChild(s[g].cloneNode(!0));
|
|
175
|
+
const d = e.cloneNode(!1);
|
|
176
|
+
o && d.appendChild(o.cloneNode(!0));
|
|
177
|
+
for (let g = h; g < s.length; g++)
|
|
178
|
+
d.appendChild(s[g].cloneNode(!0));
|
|
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 =
|
|
149
|
-
if (r.setAttribute("style",
|
|
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);
|
|
186
|
+
if (r.setAttribute("style", o), Object.assign(r.style, {
|
|
150
187
|
position: "absolute",
|
|
151
188
|
visibility: "hidden",
|
|
152
|
-
width:
|
|
153
|
-
}),
|
|
189
|
+
width: s
|
|
190
|
+
}), n.appendChild(r), r.textContent = t[0], r.offsetHeight > a)
|
|
154
191
|
return r.remove(), !1;
|
|
155
|
-
let
|
|
156
|
-
for (;
|
|
157
|
-
const
|
|
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
|
-
|
|
163
|
-
const
|
|
164
|
-
return
|
|
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(" ");
|
|
200
|
+
const f = document.createElement(i);
|
|
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
|
|
203
|
+
function L(e, n) {
|
|
167
204
|
let a = 0;
|
|
168
|
-
for (; a <
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
171
|
-
const r =
|
|
172
|
-
if (
|
|
173
|
-
if (
|
|
174
|
-
o,
|
|
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;
|
|
207
|
+
if (o > s) {
|
|
208
|
+
const r = s - i;
|
|
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 =
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
return
|
|
226
|
+
function K(e, n = {}) {
|
|
227
|
+
const a = W(n), t = N(), i = P(e, a.pageWidth);
|
|
228
|
+
F(i);
|
|
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
|
-
layout:
|
|
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,
|
|
210
247
|
margin: [
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
248
|
+
o.margin.top,
|
|
249
|
+
o.margin.right,
|
|
250
|
+
o.margin.bottom,
|
|
251
|
+
o.margin.left
|
|
215
252
|
]
|
|
216
253
|
});
|
|
217
254
|
});
|
|
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
|
|
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
|
|
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
|
-
return await
|
|
257
|
-
scale:
|
|
293
|
+
return await A(i, {
|
|
294
|
+
scale: t,
|
|
258
295
|
backgroundColor: null
|
|
259
296
|
});
|
|
260
297
|
} finally {
|
|
261
298
|
i.remove();
|
|
262
299
|
}
|
|
263
300
|
}
|
|
264
|
-
const
|
|
265
|
-
async function
|
|
266
|
-
const
|
|
267
|
-
for (const i of
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
301
|
+
const S = ["top", "right", "bottom", "left"];
|
|
302
|
+
async function q(e, n, a) {
|
|
303
|
+
const t = {};
|
|
304
|
+
for (const i of S) {
|
|
305
|
+
const o = e[i];
|
|
306
|
+
if (o && typeof o != "function") {
|
|
307
|
+
const s = T(i, n);
|
|
308
|
+
t[i] = await j(
|
|
309
|
+
o.cloneNode(!0),
|
|
310
|
+
s.width,
|
|
311
|
+
s.height,
|
|
275
312
|
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
|
|
291
|
-
const
|
|
292
|
-
Object.assign(
|
|
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) {
|
|
328
|
+
const h = document.createElement("div");
|
|
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
|
-
fontWeight:
|
|
303
|
-
color:
|
|
339
|
+
fontWeight: o,
|
|
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
|
-
fontWeight:
|
|
317
|
-
}), document.body.appendChild(
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
for (let
|
|
353
|
+
fontWeight: o
|
|
354
|
+
}), document.body.appendChild(c);
|
|
355
|
+
const f = c.offsetWidth;
|
|
356
|
+
c.remove();
|
|
357
|
+
const d = Math.ceil(n / (f + r)) + 2;
|
|
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
|
-
document.body.appendChild(
|
|
362
|
+
document.body.appendChild(h);
|
|
326
363
|
try {
|
|
327
|
-
return await
|
|
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:
|
|
341
|
-
fontSize:
|
|
342
|
-
fontFamily:
|
|
343
|
-
fontWeight:
|
|
344
|
-
} =
|
|
345
|
-
|
|
346
|
-
const w = Math.round(n - u * 2), y = Math.round(l - u * 2), [b, C] = await Promise.all([
|
|
347
|
-
O(
|
|
377
|
+
color: l = "#000000",
|
|
378
|
+
fontSize: h = 2.5,
|
|
379
|
+
fontFamily: c = "Arial, sans-serif",
|
|
380
|
+
fontWeight: f = "normal"
|
|
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([
|
|
382
|
+
D(
|
|
348
383
|
r,
|
|
349
|
-
|
|
384
|
+
p,
|
|
350
385
|
m,
|
|
351
|
-
f,
|
|
352
|
-
s,
|
|
353
|
-
h,
|
|
354
|
-
c,
|
|
355
386
|
d,
|
|
356
|
-
|
|
387
|
+
c,
|
|
388
|
+
f,
|
|
389
|
+
l,
|
|
390
|
+
g,
|
|
391
|
+
b
|
|
357
392
|
),
|
|
358
|
-
|
|
393
|
+
D(
|
|
359
394
|
r,
|
|
360
395
|
y,
|
|
361
396
|
m,
|
|
362
|
-
f,
|
|
363
|
-
s,
|
|
364
|
-
h,
|
|
365
|
-
c,
|
|
366
397
|
d,
|
|
367
|
-
|
|
398
|
+
c,
|
|
399
|
+
f,
|
|
400
|
+
l,
|
|
401
|
+
g,
|
|
402
|
+
b
|
|
368
403
|
)
|
|
369
|
-
]),
|
|
370
|
-
|
|
371
|
-
|
|
404
|
+
]), w = Math.round(m / 2);
|
|
405
|
+
e.drawImage(
|
|
406
|
+
C,
|
|
372
407
|
0,
|
|
373
408
|
0,
|
|
374
|
-
|
|
409
|
+
p,
|
|
375
410
|
m,
|
|
376
|
-
|
|
377
|
-
i -
|
|
378
|
-
|
|
411
|
+
t + u,
|
|
412
|
+
i - w,
|
|
413
|
+
p,
|
|
379
414
|
m
|
|
380
|
-
),
|
|
381
|
-
|
|
415
|
+
), e.drawImage(
|
|
416
|
+
C,
|
|
382
417
|
0,
|
|
383
418
|
0,
|
|
384
|
-
|
|
419
|
+
p,
|
|
385
420
|
m,
|
|
386
|
-
|
|
387
|
-
i +
|
|
388
|
-
|
|
421
|
+
t + u,
|
|
422
|
+
i + s - w,
|
|
423
|
+
p,
|
|
389
424
|
m
|
|
390
|
-
),
|
|
391
|
-
|
|
425
|
+
), e.save(), e.translate(t, i + s - u), e.rotate(-Math.PI / 2), e.drawImage(
|
|
426
|
+
v,
|
|
392
427
|
0,
|
|
393
428
|
0,
|
|
394
429
|
y,
|
|
395
430
|
m,
|
|
396
431
|
0,
|
|
397
|
-
-
|
|
432
|
+
-w,
|
|
398
433
|
y,
|
|
399
434
|
m
|
|
400
|
-
),
|
|
401
|
-
|
|
435
|
+
), e.restore(), e.save(), e.translate(t + o, i + u), e.rotate(Math.PI / 2), e.drawImage(
|
|
436
|
+
v,
|
|
402
437
|
0,
|
|
403
438
|
0,
|
|
404
439
|
y,
|
|
405
440
|
m,
|
|
406
441
|
0,
|
|
407
|
-
-
|
|
442
|
+
-w,
|
|
408
443
|
y,
|
|
409
444
|
m
|
|
410
|
-
),
|
|
445
|
+
), e.restore();
|
|
411
446
|
}
|
|
412
|
-
function
|
|
413
|
-
return
|
|
447
|
+
function B(e, n) {
|
|
448
|
+
return V(e.margin, n);
|
|
414
449
|
}
|
|
415
|
-
async function
|
|
416
|
-
for (const
|
|
417
|
-
const
|
|
418
|
-
if (!
|
|
419
|
-
const
|
|
420
|
-
let
|
|
421
|
-
typeof
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
450
|
+
async function X(e, n, a, t, i, o, s, r) {
|
|
451
|
+
for (const l of S) {
|
|
452
|
+
const h = n[l];
|
|
453
|
+
if (!h) continue;
|
|
454
|
+
const c = T(l, t);
|
|
455
|
+
let f;
|
|
456
|
+
typeof h == "function" ? f = await j(
|
|
457
|
+
h(o, s),
|
|
458
|
+
c.width,
|
|
459
|
+
c.height,
|
|
425
460
|
r
|
|
426
|
-
) :
|
|
427
|
-
|
|
461
|
+
) : f = a[l], e.drawImage(
|
|
462
|
+
f,
|
|
428
463
|
0,
|
|
429
464
|
0,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
Math.round(
|
|
433
|
-
Math.round(
|
|
434
|
-
Math.round(
|
|
435
|
-
Math.round(
|
|
465
|
+
f.width,
|
|
466
|
+
f.height,
|
|
467
|
+
Math.round(c.x * i),
|
|
468
|
+
Math.round(c.y * i),
|
|
469
|
+
Math.round(c.width * i),
|
|
470
|
+
Math.round(c.height * i)
|
|
436
471
|
);
|
|
437
472
|
}
|
|
438
|
-
if (
|
|
439
|
-
const { color:
|
|
440
|
-
|
|
441
|
-
Math.round(
|
|
442
|
-
Math.round(
|
|
443
|
-
Math.round((
|
|
444
|
-
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)
|
|
445
480
|
);
|
|
446
481
|
}
|
|
447
|
-
if (
|
|
448
|
-
const
|
|
449
|
-
await
|
|
450
|
-
|
|
451
|
-
|
|
482
|
+
if (n.textBorder) {
|
|
483
|
+
const l = B(n.textBorder, t);
|
|
484
|
+
await U(
|
|
485
|
+
e,
|
|
486
|
+
n.textBorder,
|
|
452
487
|
i,
|
|
453
|
-
Math.round(
|
|
454
|
-
Math.round(
|
|
455
|
-
Math.round((
|
|
456
|
-
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)
|
|
457
492
|
);
|
|
458
493
|
}
|
|
459
494
|
}
|
|
460
|
-
async function
|
|
461
|
-
const { imageFormat: a = "JPEG", imageQuality:
|
|
462
|
-
r.style.opacity = "1", r.style.left = "-99999px",
|
|
463
|
-
const
|
|
464
|
-
|
|
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);
|
|
497
|
+
r.style.opacity = "1", r.style.left = "-99999px", F(r);
|
|
498
|
+
const l = R(r, o);
|
|
499
|
+
I(r, l.pageContentPx), O(r, l.pageContentPx), L(r, l.pageContentPx), G(r);
|
|
465
500
|
try {
|
|
466
|
-
const
|
|
501
|
+
const h = await A(r, {
|
|
467
502
|
scale: i,
|
|
468
503
|
backgroundColor: "#ffffff"
|
|
469
|
-
}), { jsPDF:
|
|
470
|
-
orientation:
|
|
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({
|
|
505
|
+
orientation: b,
|
|
471
506
|
unit: "mm",
|
|
472
|
-
format: [
|
|
507
|
+
format: [o.pageWidth, o.pageHeight]
|
|
473
508
|
});
|
|
474
509
|
for (let y = 0; y < m; y++) {
|
|
475
|
-
const
|
|
510
|
+
const C = Math.min(
|
|
476
511
|
u,
|
|
477
|
-
|
|
478
|
-
),
|
|
479
|
-
|
|
480
|
-
const
|
|
481
|
-
if (!
|
|
482
|
-
|
|
483
|
-
|
|
512
|
+
h.height - y * u
|
|
513
|
+
), v = document.createElement("canvas");
|
|
514
|
+
v.width = g, v.height = C;
|
|
515
|
+
const w = v.getContext("2d");
|
|
516
|
+
if (!w) throw new Error("Could not get canvas context");
|
|
517
|
+
w.fillStyle = "#ffffff", w.fillRect(0, 0, g, C), w.drawImage(
|
|
518
|
+
h,
|
|
484
519
|
0,
|
|
485
520
|
y * u,
|
|
486
|
-
|
|
487
|
-
|
|
521
|
+
g,
|
|
522
|
+
C,
|
|
488
523
|
0,
|
|
489
524
|
0,
|
|
490
|
-
|
|
491
|
-
|
|
525
|
+
g,
|
|
526
|
+
C
|
|
492
527
|
);
|
|
493
|
-
const
|
|
528
|
+
const E = v.toDataURL(
|
|
494
529
|
`image/${a.toLowerCase()}`,
|
|
495
|
-
|
|
530
|
+
t
|
|
496
531
|
);
|
|
497
|
-
y > 0 &&
|
|
498
|
-
const H =
|
|
499
|
-
|
|
500
|
-
|
|
532
|
+
y > 0 && p.addPage([o.pageWidth, o.pageHeight], b);
|
|
533
|
+
const H = C / g * f;
|
|
534
|
+
p.addImage(
|
|
535
|
+
E,
|
|
501
536
|
a,
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
537
|
+
o.margin.left,
|
|
538
|
+
o.margin.top,
|
|
539
|
+
f,
|
|
505
540
|
H,
|
|
506
541
|
void 0,
|
|
507
|
-
"
|
|
542
|
+
"SLOW"
|
|
508
543
|
);
|
|
509
544
|
}
|
|
510
|
-
return
|
|
545
|
+
return n.marginContent && await $(p, n.marginContent, n), p;
|
|
511
546
|
} finally {
|
|
512
|
-
r.remove(),
|
|
547
|
+
r.remove(), s();
|
|
513
548
|
}
|
|
514
549
|
}
|
|
515
|
-
async function
|
|
516
|
-
const { imageFormat: a = "PNG", imageQuality:
|
|
517
|
-
r.style.opacity = "1", r.style.left = "-99999px",
|
|
518
|
-
const
|
|
519
|
-
|
|
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);
|
|
552
|
+
r.style.opacity = "1", r.style.left = "-99999px", F(r);
|
|
553
|
+
const l = R(r, o);
|
|
554
|
+
I(r, l.pageContentPx), O(r, l.pageContentPx), L(r, l.pageContentPx), G(r);
|
|
520
555
|
try {
|
|
521
|
-
const
|
|
556
|
+
const h = await A(r, {
|
|
522
557
|
scale: i,
|
|
523
558
|
backgroundColor: "#ffffff"
|
|
524
|
-
}),
|
|
525
|
-
for (let H = 0; H <
|
|
526
|
-
const
|
|
527
|
-
d,
|
|
528
|
-
g.height - H * d
|
|
529
|
-
), S = document.createElement("canvas");
|
|
530
|
-
S.width = m, S.height = v;
|
|
531
|
-
const x = S.getContext("2d");
|
|
532
|
-
if (!x) throw new Error("Could not get canvas context");
|
|
533
|
-
x.fillStyle = "#ffffff", x.fillRect(0, 0, m, v), x.drawImage(
|
|
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++) {
|
|
561
|
+
const k = Math.min(
|
|
534
562
|
g,
|
|
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(
|
|
569
|
+
h,
|
|
535
570
|
0,
|
|
536
|
-
H *
|
|
537
|
-
|
|
538
|
-
|
|
571
|
+
H * g,
|
|
572
|
+
d,
|
|
573
|
+
k,
|
|
539
574
|
y,
|
|
540
|
-
w,
|
|
541
|
-
f,
|
|
542
|
-
I
|
|
543
|
-
), p && await z(
|
|
544
|
-
x,
|
|
545
575
|
p,
|
|
546
|
-
|
|
547
|
-
|
|
576
|
+
d,
|
|
577
|
+
k
|
|
578
|
+
), w && await X(
|
|
579
|
+
x,
|
|
580
|
+
w,
|
|
581
|
+
E,
|
|
582
|
+
o,
|
|
548
583
|
u,
|
|
549
584
|
H + 1,
|
|
550
|
-
|
|
585
|
+
C,
|
|
551
586
|
i
|
|
552
|
-
),
|
|
553
|
-
|
|
587
|
+
), v.push(
|
|
588
|
+
M.toDataURL(
|
|
554
589
|
`image/${a.toLowerCase()}`,
|
|
555
|
-
|
|
590
|
+
t
|
|
556
591
|
)
|
|
557
592
|
);
|
|
558
593
|
}
|
|
559
|
-
return
|
|
594
|
+
return v;
|
|
560
595
|
} finally {
|
|
561
|
-
r.remove(),
|
|
596
|
+
r.remove(), s();
|
|
562
597
|
}
|
|
563
598
|
}
|
|
564
|
-
async function
|
|
565
|
-
const
|
|
566
|
-
|
|
599
|
+
async function it(e, n, a = {}) {
|
|
600
|
+
const t = W(a), i = await tt(e, a);
|
|
601
|
+
n.innerHTML = "", Object.assign(n.style, {
|
|
567
602
|
direction: "ltr",
|
|
568
603
|
width: "fit-content",
|
|
569
|
-
height:
|
|
604
|
+
height: t.pageHeight + "mm",
|
|
570
605
|
maxHeight: "100vh",
|
|
571
606
|
overflowY: "auto",
|
|
572
607
|
background: "#e0e0e0"
|
|
573
608
|
});
|
|
574
|
-
for (let
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
width:
|
|
609
|
+
for (let o = 0; o < i.length; o++) {
|
|
610
|
+
const s = document.createElement("img");
|
|
611
|
+
s.src = i[o], s.alt = `Page ${o + 1}`, Object.assign(s.style, {
|
|
612
|
+
width: t.pageWidth + "mm",
|
|
578
613
|
maxWidth: "100%",
|
|
579
614
|
height: "auto",
|
|
580
615
|
boxSizing: "border-box",
|
|
@@ -582,49 +617,89 @@ async function nt(t, e, a = {}) {
|
|
|
582
617
|
border: "1px solid #bbb",
|
|
583
618
|
boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
|
|
584
619
|
marginBottom: "16px"
|
|
585
|
-
}),
|
|
620
|
+
}), n.appendChild(s);
|
|
586
621
|
}
|
|
587
622
|
}
|
|
588
|
-
async function $(
|
|
589
|
-
const
|
|
590
|
-
for (
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
const
|
|
595
|
-
|
|
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 = {};
|
|
625
|
+
for (const d of S)
|
|
626
|
+
h[d] && (c[d] = h[d].toDataURL("image/png"));
|
|
627
|
+
let f;
|
|
628
|
+
if (n.textBorder) {
|
|
629
|
+
const d = document.createElement("canvas");
|
|
630
|
+
d.width = r, d.height = l;
|
|
631
|
+
const g = d.getContext("2d");
|
|
632
|
+
if (g) {
|
|
633
|
+
const u = B(n.textBorder, t);
|
|
634
|
+
await U(
|
|
635
|
+
g,
|
|
636
|
+
n.textBorder,
|
|
637
|
+
s,
|
|
638
|
+
Math.round(u.left * s),
|
|
639
|
+
Math.round(u.top * s),
|
|
640
|
+
Math.round((t.pageWidth - u.left - u.right) * s),
|
|
641
|
+
Math.round((t.pageHeight - u.top - u.bottom) * s)
|
|
642
|
+
), f = d.toDataURL("image/png");
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
for (let d = 1; d <= i; d++) {
|
|
646
|
+
e.setPage(d);
|
|
647
|
+
for (const g of S) {
|
|
648
|
+
const u = n[g];
|
|
649
|
+
if (!u) continue;
|
|
650
|
+
const m = T(g, t);
|
|
651
|
+
let b, p;
|
|
652
|
+
typeof u == "function" ? b = (await j(
|
|
653
|
+
u(d, i),
|
|
654
|
+
m.width,
|
|
655
|
+
m.height,
|
|
656
|
+
o
|
|
657
|
+
)).toDataURL("image/png") : (b = c[g], p = `margin-${g}`), e.addImage(
|
|
658
|
+
b,
|
|
659
|
+
"PNG",
|
|
660
|
+
m.x,
|
|
661
|
+
m.y,
|
|
662
|
+
m.width,
|
|
663
|
+
m.height,
|
|
664
|
+
p,
|
|
665
|
+
"SLOW"
|
|
666
|
+
);
|
|
667
|
+
}
|
|
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(
|
|
671
|
+
m.left,
|
|
672
|
+
m.top,
|
|
673
|
+
t.pageWidth - m.left - m.right,
|
|
674
|
+
t.pageHeight - m.top - m.bottom
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
f && e.addImage(
|
|
596
678
|
f,
|
|
597
|
-
e,
|
|
598
|
-
g,
|
|
599
|
-
o,
|
|
600
|
-
l,
|
|
601
|
-
s,
|
|
602
|
-
i,
|
|
603
|
-
n
|
|
604
|
-
), t.addImage(
|
|
605
|
-
h.toDataURL("image/png"),
|
|
606
679
|
"PNG",
|
|
607
680
|
0,
|
|
608
681
|
0,
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
682
|
+
t.pageWidth,
|
|
683
|
+
t.pageHeight,
|
|
684
|
+
"text-border",
|
|
685
|
+
"SLOW"
|
|
686
|
+
);
|
|
612
687
|
}
|
|
613
|
-
return
|
|
688
|
+
return e;
|
|
614
689
|
}
|
|
615
690
|
export {
|
|
616
691
|
_ as PAGE_MARGINS,
|
|
617
|
-
|
|
692
|
+
z as PAGE_SIZES,
|
|
618
693
|
$ as addMarginContent,
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
694
|
+
R as computeLayout,
|
|
695
|
+
P as createPrintClone,
|
|
696
|
+
L as insertPageBreakSpacers,
|
|
697
|
+
F as normalizeTableAttributes,
|
|
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
|
|
630
705
|
};
|
package/package.json
CHANGED