jspdf-utils 0.1.12 → 0.1.13
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 +246 -216
- package/package.json +1 -1
package/dist/html-to-pdf.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import W from "html2canvas";
|
|
2
2
|
const q = {
|
|
3
3
|
a0: [841, 1189],
|
|
4
4
|
a1: [594, 841],
|
|
@@ -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
|
+
}, U = {
|
|
14
14
|
a0: 40,
|
|
15
15
|
a1: 35,
|
|
16
16
|
a2: 30,
|
|
@@ -22,12 +22,12 @@ const q = {
|
|
|
22
22
|
legal: 25.4,
|
|
23
23
|
tabloid: 25
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
const e = t.format ?? "a4", [a, o] = q[e], i = t.pageWidth ?? a, n = t.pageHeight ?? o,
|
|
27
|
-
top:
|
|
28
|
-
right:
|
|
29
|
-
bottom:
|
|
30
|
-
left:
|
|
25
|
+
function M(t = {}) {
|
|
26
|
+
const e = t.format ?? "a4", [a, o] = q[e], i = t.pageWidth ?? a, n = t.pageHeight ?? o, l = U[e], r = {
|
|
27
|
+
top: l,
|
|
28
|
+
right: l,
|
|
29
|
+
bottom: l,
|
|
30
|
+
left: l
|
|
31
31
|
};
|
|
32
32
|
return {
|
|
33
33
|
unit: t.unit ?? "mm",
|
|
@@ -37,11 +37,11 @@ function A(t = {}) {
|
|
|
37
37
|
margin: { ...r, ...t.margin }
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
const a = t.offsetWidth, o = e.pageWidth - e.margin.left - e.margin.right, i = o / a,
|
|
42
|
-
return { renderedWidth: a, scale: i, contentWidthMm: o, pageContentPx:
|
|
40
|
+
function E(t, e) {
|
|
41
|
+
const a = t.offsetWidth, o = e.pageWidth - e.margin.left - e.margin.right, i = o / a, l = (e.pageHeight - e.margin.top - e.margin.bottom) / i;
|
|
42
|
+
return { renderedWidth: a, scale: i, contentWidthMm: o, pageContentPx: l };
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function P(t, e = 210) {
|
|
45
45
|
const a = t.cloneNode(!0);
|
|
46
46
|
return Object.assign(a.style, {
|
|
47
47
|
position: "fixed",
|
|
@@ -53,11 +53,11 @@ function E(t, e = 210) {
|
|
|
53
53
|
pointerEvents: "none"
|
|
54
54
|
}), document.body.appendChild(a), a;
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function B() {
|
|
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 N(t) {
|
|
61
61
|
for (const e of t.querySelectorAll("table")) {
|
|
62
62
|
const a = e.getAttribute("cellpadding");
|
|
63
63
|
if (a) {
|
|
@@ -74,14 +74,14 @@ function R(t, e) {
|
|
|
74
74
|
if (a.offsetHeight <= e) continue;
|
|
75
75
|
const o = Array.from(a.rows);
|
|
76
76
|
if (o.length === 0) continue;
|
|
77
|
-
const i = o[0].querySelector("th") !== null, n = i ? o[0] : null,
|
|
78
|
-
let c = [],
|
|
79
|
-
for (const f of
|
|
77
|
+
const i = o[0].querySelector("th") !== null, n = i ? o[0] : null, l = i ? o.slice(1) : o, r = n ? n.offsetHeight : 0, s = e - r - 2, g = [];
|
|
78
|
+
let c = [], h = 0;
|
|
79
|
+
for (const f of l) {
|
|
80
80
|
const d = f.offsetHeight;
|
|
81
|
-
|
|
81
|
+
h + d > s && c.length > 0 && (g.push(c), c = [], h = 0), c.push(f), h += d;
|
|
82
82
|
}
|
|
83
|
-
c.length > 0 &&
|
|
84
|
-
for (const f of
|
|
83
|
+
c.length > 0 && g.push(c);
|
|
84
|
+
for (const f of g) {
|
|
85
85
|
const d = a.cloneNode(!1);
|
|
86
86
|
n && d.appendChild(n.cloneNode(!0));
|
|
87
87
|
for (const m of f) d.appendChild(m.cloneNode(!0));
|
|
@@ -90,107 +90,107 @@ function R(t, e) {
|
|
|
90
90
|
a.remove();
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function T(t, e) {
|
|
94
94
|
for (const a of Array.from(t.querySelectorAll(":scope > *"))) {
|
|
95
95
|
const o = a;
|
|
96
96
|
if (o.offsetHeight <= e || o.tagName === "TABLE")
|
|
97
97
|
continue;
|
|
98
|
-
const i = o.tagName, n = o.getAttribute("style") || "",
|
|
99
|
-
|
|
98
|
+
const i = o.tagName, n = o.getAttribute("style") || "", l = getComputedStyle(o).width, r = (o.textContent || "").split(/\s+/).filter(Boolean), s = document.createElement(i);
|
|
99
|
+
s.setAttribute("style", n), Object.assign(s.style, {
|
|
100
100
|
position: "absolute",
|
|
101
101
|
visibility: "hidden",
|
|
102
|
-
width:
|
|
103
|
-
}), t.appendChild(
|
|
104
|
-
const
|
|
102
|
+
width: l
|
|
103
|
+
}), t.appendChild(s);
|
|
104
|
+
const g = [];
|
|
105
105
|
let c = 0;
|
|
106
106
|
for (; c < r.length; ) {
|
|
107
|
-
let
|
|
108
|
-
for (;
|
|
109
|
-
const m = Math.ceil((
|
|
110
|
-
|
|
107
|
+
let h = c + 1, f = r.length;
|
|
108
|
+
for (; h < f; ) {
|
|
109
|
+
const m = Math.ceil((h + f) / 2);
|
|
110
|
+
s.textContent = r.slice(c, m).join(" "), s.offsetHeight <= e ? h = m : f = m - 1;
|
|
111
111
|
}
|
|
112
112
|
const d = document.createElement(i);
|
|
113
|
-
d.setAttribute("style", n), d.textContent = r.slice(c,
|
|
113
|
+
d.setAttribute("style", n), d.textContent = r.slice(c, h).join(" "), g.push(d), c = h;
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
for (const
|
|
117
|
-
o.parentNode.insertBefore(
|
|
115
|
+
s.remove();
|
|
116
|
+
for (const h of g)
|
|
117
|
+
o.parentNode.insertBefore(h, o);
|
|
118
118
|
o.remove();
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function _(t, e, a) {
|
|
122
122
|
const o = Array.from(t.rows);
|
|
123
123
|
if (o.length === 0) return !1;
|
|
124
|
-
const i = o[0].querySelector("th") !== null, n = i ? o[0] : null,
|
|
125
|
-
if (
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
-
let
|
|
129
|
-
for (const d of
|
|
130
|
-
if (c + d.offsetHeight >
|
|
131
|
-
c += d.offsetHeight,
|
|
124
|
+
const i = o[0].querySelector("th") !== null, n = i ? o[0] : null, l = i ? o.slice(1) : o, r = n ? n.offsetHeight : 0;
|
|
125
|
+
if (l.length < 2) return !1;
|
|
126
|
+
const s = a - r - 2;
|
|
127
|
+
if (s <= 0) return !1;
|
|
128
|
+
let g = 0, c = 0;
|
|
129
|
+
for (const d of l) {
|
|
130
|
+
if (c + d.offsetHeight > s) break;
|
|
131
|
+
c += d.offsetHeight, g++;
|
|
132
132
|
}
|
|
133
|
-
if (
|
|
134
|
-
const
|
|
135
|
-
n &&
|
|
136
|
-
for (let d = 0; d <
|
|
137
|
-
|
|
133
|
+
if (g === 0 || g === l.length) return !1;
|
|
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));
|
|
138
138
|
const f = t.cloneNode(!1);
|
|
139
139
|
n && f.appendChild(n.cloneNode(!0));
|
|
140
|
-
for (let d =
|
|
141
|
-
f.appendChild(
|
|
142
|
-
return e.insertBefore(
|
|
140
|
+
for (let d = g; d < l.length; d++)
|
|
141
|
+
f.appendChild(l[d].cloneNode(!0));
|
|
142
|
+
return e.insertBefore(h, t), e.insertBefore(f, t), t.remove(), !0;
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function J(t, e, a) {
|
|
145
145
|
if (t.tagName === "TABLE" || t.tagName === "IMG") return !1;
|
|
146
146
|
const o = (t.textContent || "").split(/\s+/).filter(Boolean);
|
|
147
147
|
if (o.length < 2) return !1;
|
|
148
|
-
const i = t.tagName, n = t.getAttribute("style") || "",
|
|
148
|
+
const i = t.tagName, n = t.getAttribute("style") || "", l = getComputedStyle(t).width, r = document.createElement(i);
|
|
149
149
|
if (r.setAttribute("style", n), Object.assign(r.style, {
|
|
150
150
|
position: "absolute",
|
|
151
151
|
visibility: "hidden",
|
|
152
|
-
width:
|
|
152
|
+
width: l
|
|
153
153
|
}), e.appendChild(r), r.textContent = o[0], r.offsetHeight > a)
|
|
154
154
|
return r.remove(), !1;
|
|
155
|
-
let
|
|
156
|
-
for (;
|
|
157
|
-
const f = Math.ceil((
|
|
158
|
-
r.textContent = o.slice(0, f).join(" "), r.offsetHeight <= a ?
|
|
155
|
+
let s = 1, g = o.length;
|
|
156
|
+
for (; s < g; ) {
|
|
157
|
+
const f = Math.ceil((s + g) / 2);
|
|
158
|
+
r.textContent = o.slice(0, f).join(" "), r.offsetHeight <= a ? s = f : g = f - 1;
|
|
159
159
|
}
|
|
160
|
-
if (r.remove(),
|
|
160
|
+
if (r.remove(), s >= o.length) return !1;
|
|
161
161
|
const c = document.createElement(i);
|
|
162
|
-
c.setAttribute("style", n), c.textContent = o.slice(0,
|
|
163
|
-
const
|
|
164
|
-
return
|
|
162
|
+
c.setAttribute("style", n), c.textContent = o.slice(0, s).join(" ");
|
|
163
|
+
const h = document.createElement(i);
|
|
164
|
+
return h.setAttribute("style", n), h.textContent = o.slice(s).join(" "), e.insertBefore(c, t), e.insertBefore(h, t), t.remove(), !0;
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function I(t, e) {
|
|
167
167
|
let a = 0;
|
|
168
168
|
for (; a < t.children.length; ) {
|
|
169
|
-
const o = t.children[a], i = o.offsetTop, n = i + o.offsetHeight,
|
|
170
|
-
if (n >
|
|
171
|
-
const r =
|
|
169
|
+
const o = t.children[a], i = o.offsetTop, n = i + o.offsetHeight, l = (Math.floor(i / e) + 1) * e;
|
|
170
|
+
if (n > l) {
|
|
171
|
+
const r = l - i;
|
|
172
172
|
if (o.tagName === "TABLE") {
|
|
173
|
-
if (
|
|
173
|
+
if (_(
|
|
174
174
|
o,
|
|
175
175
|
t,
|
|
176
176
|
r
|
|
177
177
|
))
|
|
178
178
|
continue;
|
|
179
|
-
} else if (
|
|
179
|
+
} else if (J(o, t, r))
|
|
180
180
|
continue;
|
|
181
181
|
if (o.offsetHeight <= e) {
|
|
182
|
-
const
|
|
183
|
-
|
|
182
|
+
const s = document.createElement("div");
|
|
183
|
+
s.style.height = l - i + 1 + "px", o.parentNode.insertBefore(s, o), a++;
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
a++;
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
function
|
|
190
|
-
const a =
|
|
191
|
-
|
|
192
|
-
const n =
|
|
193
|
-
return R(i, n.pageContentPx),
|
|
189
|
+
function Q(t, e = {}) {
|
|
190
|
+
const a = M(e), o = B(), i = P(t, a.pageWidth);
|
|
191
|
+
N(i);
|
|
192
|
+
const n = E(i, a);
|
|
193
|
+
return R(i, n.pageContentPx), T(i, n.pageContentPx), I(i, n.pageContentPx), {
|
|
194
194
|
clone: i,
|
|
195
195
|
layout: n,
|
|
196
196
|
options: a,
|
|
@@ -199,8 +199,8 @@ function J(t, e = {}) {
|
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
|
-
async function
|
|
203
|
-
const { clone: o, layout: i, options: n, cleanup:
|
|
202
|
+
async function X(t, e, a = {}) {
|
|
203
|
+
const { clone: o, layout: i, options: n, cleanup: l } = Q(e, a);
|
|
204
204
|
try {
|
|
205
205
|
await new Promise((r) => {
|
|
206
206
|
t.html(o, {
|
|
@@ -216,11 +216,11 @@ async function Y(t, e, a = {}) {
|
|
|
216
216
|
});
|
|
217
217
|
});
|
|
218
218
|
} finally {
|
|
219
|
-
|
|
219
|
+
l();
|
|
220
220
|
}
|
|
221
|
-
return a.marginContent && await
|
|
221
|
+
return a.marginContent && await F(t, a.marginContent, a), t;
|
|
222
222
|
}
|
|
223
|
-
function
|
|
223
|
+
function L(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 I(t, e) {
|
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
-
async function
|
|
245
|
+
async function G(t, e, a, o) {
|
|
246
246
|
const i = document.createElement("div");
|
|
247
247
|
Object.assign(i.style, {
|
|
248
248
|
position: "fixed",
|
|
@@ -253,7 +253,7 @@ async function L(t, e, a, o) {
|
|
|
253
253
|
overflow: "hidden"
|
|
254
254
|
}), i.appendChild(t), document.body.appendChild(i);
|
|
255
255
|
try {
|
|
256
|
-
return await
|
|
256
|
+
return await W(i, {
|
|
257
257
|
scale: o,
|
|
258
258
|
backgroundColor: null
|
|
259
259
|
});
|
|
@@ -261,24 +261,24 @@ async function L(t, e, a, o) {
|
|
|
261
261
|
i.remove();
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
const
|
|
264
|
+
const z = ["top", "right", "bottom", "left"];
|
|
265
265
|
async function D(t, e, a) {
|
|
266
266
|
const o = {};
|
|
267
|
-
for (const i of
|
|
267
|
+
for (const i of z) {
|
|
268
268
|
const n = t[i];
|
|
269
269
|
if (n && typeof n != "function") {
|
|
270
|
-
const
|
|
271
|
-
o[i] = await
|
|
270
|
+
const l = L(i, e);
|
|
271
|
+
o[i] = await G(
|
|
272
272
|
n.cloneNode(!0),
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
l.width,
|
|
274
|
+
l.height,
|
|
275
275
|
a
|
|
276
276
|
);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
return o;
|
|
280
280
|
}
|
|
281
|
-
function
|
|
281
|
+
function Z(t, e) {
|
|
282
282
|
return t == null ? e.margin : typeof t == "number" ? { top: t, right: t, bottom: t, left: t } : {
|
|
283
283
|
top: t.top ?? e.margin.top,
|
|
284
284
|
right: t.right ?? e.margin.right,
|
|
@@ -286,50 +286,80 @@ function Q(t, e) {
|
|
|
286
286
|
left: t.left ?? e.margin.left
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
|
-
function
|
|
289
|
+
async function j(t, e, a, o, i, n, l, r) {
|
|
290
|
+
const s = document.createElement("div");
|
|
291
|
+
Object.assign(s.style, {
|
|
292
|
+
position: "fixed",
|
|
293
|
+
left: "-99999px",
|
|
294
|
+
top: "0",
|
|
295
|
+
width: `${e}px`,
|
|
296
|
+
height: `${a}px`,
|
|
297
|
+
overflow: "hidden",
|
|
298
|
+
whiteSpace: "nowrap",
|
|
299
|
+
fontSize: `${o}px`,
|
|
300
|
+
fontFamily: i,
|
|
301
|
+
fontWeight: n,
|
|
302
|
+
color: l,
|
|
303
|
+
display: "flex",
|
|
304
|
+
alignItems: "center",
|
|
305
|
+
gap: `${r}px`
|
|
306
|
+
});
|
|
307
|
+
const g = document.createElement("span");
|
|
308
|
+
g.textContent = t, Object.assign(g.style, {
|
|
309
|
+
position: "absolute",
|
|
310
|
+
visibility: "hidden",
|
|
311
|
+
whiteSpace: "nowrap",
|
|
312
|
+
fontSize: `${o}px`,
|
|
313
|
+
fontFamily: i,
|
|
314
|
+
fontWeight: n
|
|
315
|
+
}), document.body.appendChild(g);
|
|
316
|
+
const c = g.offsetWidth;
|
|
317
|
+
g.remove();
|
|
318
|
+
const h = Math.ceil(e / (c + r)) + 2;
|
|
319
|
+
for (let f = 0; f < h; f++) {
|
|
320
|
+
const d = document.createElement("span");
|
|
321
|
+
d.textContent = t, d.style.flexShrink = "0", s.appendChild(d);
|
|
322
|
+
}
|
|
323
|
+
document.body.appendChild(s);
|
|
324
|
+
try {
|
|
325
|
+
return await W(s, { scale: 1, backgroundColor: null });
|
|
326
|
+
} finally {
|
|
327
|
+
s.remove();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async function K(t, e, a, o, i, n, l) {
|
|
290
331
|
const {
|
|
291
332
|
text: r,
|
|
292
|
-
color:
|
|
293
|
-
fontSize:
|
|
333
|
+
color: s = "#000000",
|
|
334
|
+
fontSize: g = 2.5,
|
|
294
335
|
fontFamily: c = "Arial, sans-serif",
|
|
295
|
-
fontWeight:
|
|
296
|
-
} = e, f =
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
W(y, r);
|
|
302
|
-
else
|
|
303
|
-
for (let M = r.length - 1; M >= 1; M--) {
|
|
304
|
-
const H = r.substring(0, M);
|
|
305
|
-
if (y + t.measureText(H).width <= u) {
|
|
306
|
-
W(y, H);
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}, v = o + w, C = o + n - w;
|
|
311
|
-
b(v, C, (p, u) => t.fillText(u, p, i)), b(v, C, (p, u) => t.fillText(u, p, i + s)), t.save(), t.translate(o, i + s), t.rotate(-Math.PI / 2), b(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.save(), t.translate(o + n, i), t.rotate(Math.PI / 2), b(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.restore();
|
|
336
|
+
fontWeight: h = "normal"
|
|
337
|
+
} = e, f = g * a, d = (e.gap ?? g * 0.5) * a, m = f * 0.2, b = Math.ceil(f * 1.5), v = Math.round(n - m * 2), C = Math.round(l - m * 2), [y, p] = await Promise.all([
|
|
338
|
+
j(r, v, b, f, c, h, s, d),
|
|
339
|
+
j(r, C, b, f, c, h, s, d)
|
|
340
|
+
]), u = Math.round(b / 2);
|
|
341
|
+
t.drawImage(y, o + m, i - u), t.drawImage(y, o + m, i + l - u), t.save(), t.translate(o, i + l - m), t.rotate(-Math.PI / 2), t.drawImage(p, 0, -u), t.restore(), t.save(), t.translate(o + n, i + m), t.rotate(Math.PI / 2), t.drawImage(p, 0, -u), t.restore();
|
|
312
342
|
}
|
|
313
343
|
function k(t, e) {
|
|
314
|
-
return
|
|
344
|
+
return Z(t.margin, e);
|
|
315
345
|
}
|
|
316
|
-
async function
|
|
317
|
-
for (const
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
320
|
-
const c =
|
|
321
|
-
let
|
|
322
|
-
typeof
|
|
323
|
-
|
|
346
|
+
async function $(t, e, a, o, i, n, l, r) {
|
|
347
|
+
for (const s of z) {
|
|
348
|
+
const g = e[s];
|
|
349
|
+
if (!g) continue;
|
|
350
|
+
const c = L(s, o);
|
|
351
|
+
let h;
|
|
352
|
+
typeof g == "function" ? h = await G(
|
|
353
|
+
g(n, l),
|
|
324
354
|
c.width,
|
|
325
355
|
c.height,
|
|
326
356
|
r
|
|
327
|
-
) :
|
|
328
|
-
|
|
357
|
+
) : h = a[s], t.drawImage(
|
|
358
|
+
h,
|
|
329
359
|
0,
|
|
330
360
|
0,
|
|
331
|
-
|
|
332
|
-
|
|
361
|
+
h.width,
|
|
362
|
+
h.height,
|
|
333
363
|
Math.round(c.x * i),
|
|
334
364
|
Math.round(c.y * i),
|
|
335
365
|
Math.round(c.width * i),
|
|
@@ -337,8 +367,8 @@ async function F(t, e, a, o, i, n, s, r) {
|
|
|
337
367
|
);
|
|
338
368
|
}
|
|
339
369
|
if (e.contentBorder) {
|
|
340
|
-
const { color:
|
|
341
|
-
t.strokeStyle =
|
|
370
|
+
const { color: s = "#000000", width: g = 0.3 } = e.contentBorder, c = k(e.contentBorder, o);
|
|
371
|
+
t.strokeStyle = s, t.lineWidth = g * i, t.strokeRect(
|
|
342
372
|
Math.round(c.left * i),
|
|
343
373
|
Math.round(c.top * i),
|
|
344
374
|
Math.round((o.pageWidth - c.left - c.right) * i),
|
|
@@ -346,124 +376,124 @@ async function F(t, e, a, o, i, n, s, r) {
|
|
|
346
376
|
);
|
|
347
377
|
}
|
|
348
378
|
if (e.textBorder) {
|
|
349
|
-
const
|
|
350
|
-
|
|
379
|
+
const s = k(e.textBorder, o);
|
|
380
|
+
await K(
|
|
351
381
|
t,
|
|
352
382
|
e.textBorder,
|
|
353
383
|
i,
|
|
354
|
-
Math.round(
|
|
355
|
-
Math.round(
|
|
356
|
-
Math.round((o.pageWidth -
|
|
357
|
-
Math.round((o.pageHeight -
|
|
384
|
+
Math.round(s.left * i),
|
|
385
|
+
Math.round(s.top * i),
|
|
386
|
+
Math.round((o.pageWidth - s.left - s.right) * i),
|
|
387
|
+
Math.round((o.pageHeight - s.top - s.bottom) * i)
|
|
358
388
|
);
|
|
359
389
|
}
|
|
360
390
|
}
|
|
361
|
-
async function
|
|
362
|
-
const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n =
|
|
363
|
-
r.style.opacity = "1", r.style.left = "-99999px",
|
|
364
|
-
const
|
|
365
|
-
R(r,
|
|
391
|
+
async function tt(t, e = {}) {
|
|
392
|
+
const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n = M(e), l = B(), r = P(t, n.pageWidth);
|
|
393
|
+
r.style.opacity = "1", r.style.left = "-99999px", N(r);
|
|
394
|
+
const s = E(r, n);
|
|
395
|
+
R(r, s.pageContentPx), T(r, s.pageContentPx), I(r, s.pageContentPx);
|
|
366
396
|
try {
|
|
367
|
-
const
|
|
397
|
+
const g = await W(r, {
|
|
368
398
|
scale: i,
|
|
369
399
|
backgroundColor: "#ffffff"
|
|
370
|
-
}), { jsPDF: c } = await import("jspdf"),
|
|
371
|
-
orientation:
|
|
400
|
+
}), { jsPDF: c } = await import("jspdf"), h = n.pageWidth - n.margin.left - n.margin.right, f = n.pageHeight - n.margin.top - n.margin.bottom, d = g.width, m = f / h * d, b = Math.ceil(g.height / m), v = n.pageWidth > n.pageHeight ? "l" : "p", C = new c({
|
|
401
|
+
orientation: v,
|
|
372
402
|
unit: "mm",
|
|
373
403
|
format: [n.pageWidth, n.pageHeight]
|
|
374
404
|
});
|
|
375
|
-
for (let
|
|
376
|
-
const
|
|
405
|
+
for (let y = 0; y < b; y++) {
|
|
406
|
+
const p = Math.min(
|
|
377
407
|
m,
|
|
378
|
-
|
|
379
|
-
),
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
if (!
|
|
383
|
-
|
|
384
|
-
|
|
408
|
+
g.height - y * m
|
|
409
|
+
), u = document.createElement("canvas");
|
|
410
|
+
u.width = d, u.height = p;
|
|
411
|
+
const w = u.getContext("2d");
|
|
412
|
+
if (!w) throw new Error("Could not get canvas context");
|
|
413
|
+
w.fillStyle = "#ffffff", w.fillRect(0, 0, d, p), w.drawImage(
|
|
414
|
+
g,
|
|
385
415
|
0,
|
|
386
|
-
|
|
416
|
+
y * m,
|
|
387
417
|
d,
|
|
388
|
-
|
|
418
|
+
p,
|
|
389
419
|
0,
|
|
390
420
|
0,
|
|
391
421
|
d,
|
|
392
|
-
|
|
422
|
+
p
|
|
393
423
|
);
|
|
394
|
-
const
|
|
424
|
+
const A = u.toDataURL(
|
|
395
425
|
`image/${a.toLowerCase()}`,
|
|
396
426
|
o
|
|
397
427
|
);
|
|
398
|
-
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
428
|
+
y > 0 && C.addPage([n.pageWidth, n.pageHeight], v);
|
|
429
|
+
const H = p / d * h;
|
|
430
|
+
C.addImage(
|
|
431
|
+
A,
|
|
402
432
|
a,
|
|
403
433
|
n.margin.left,
|
|
404
434
|
n.margin.top,
|
|
405
|
-
|
|
406
|
-
|
|
435
|
+
h,
|
|
436
|
+
H,
|
|
407
437
|
void 0,
|
|
408
438
|
"FAST"
|
|
409
439
|
);
|
|
410
440
|
}
|
|
411
|
-
return e.marginContent && await
|
|
441
|
+
return e.marginContent && await F(C, e.marginContent, e), C;
|
|
412
442
|
} finally {
|
|
413
|
-
r.remove(),
|
|
443
|
+
r.remove(), l();
|
|
414
444
|
}
|
|
415
445
|
}
|
|
416
|
-
async function
|
|
417
|
-
const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n =
|
|
418
|
-
r.style.opacity = "1", r.style.left = "-99999px",
|
|
419
|
-
const
|
|
420
|
-
R(r,
|
|
446
|
+
async function V(t, e = {}) {
|
|
447
|
+
const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n = M(e), l = B(), r = P(t, n.pageWidth);
|
|
448
|
+
r.style.opacity = "1", r.style.left = "-99999px", N(r);
|
|
449
|
+
const s = E(r, n);
|
|
450
|
+
R(r, s.pageContentPx), T(r, s.pageContentPx), I(r, s.pageContentPx);
|
|
421
451
|
try {
|
|
422
|
-
const
|
|
452
|
+
const g = await W(r, {
|
|
423
453
|
scale: i,
|
|
424
454
|
backgroundColor: "#ffffff"
|
|
425
|
-
}), c = n.pageWidth - n.margin.left - n.margin.right,
|
|
426
|
-
for (let
|
|
427
|
-
const
|
|
455
|
+
}), c = n.pageWidth - n.margin.left - n.margin.right, h = n.pageHeight - n.margin.top - n.margin.bottom, f = g.width, d = h / c * f, m = f / c, b = Math.round(n.pageWidth * m), v = Math.round(n.pageHeight * m), C = Math.round(n.margin.top * m), y = Math.round(n.margin.left * m), p = Math.ceil(g.height / d), u = [], { marginContent: w } = e, A = w ? await D(w, n, i) : {};
|
|
456
|
+
for (let H = 0; H < p; H++) {
|
|
457
|
+
const O = Math.min(
|
|
428
458
|
d,
|
|
429
|
-
|
|
430
|
-
),
|
|
431
|
-
|
|
432
|
-
const
|
|
433
|
-
if (!
|
|
434
|
-
|
|
435
|
-
|
|
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(
|
|
465
|
+
g,
|
|
436
466
|
0,
|
|
437
|
-
|
|
467
|
+
H * d,
|
|
438
468
|
f,
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
469
|
+
O,
|
|
470
|
+
y,
|
|
471
|
+
C,
|
|
442
472
|
f,
|
|
443
|
-
|
|
444
|
-
),
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
473
|
+
O
|
|
474
|
+
), w && await $(
|
|
475
|
+
x,
|
|
476
|
+
w,
|
|
477
|
+
A,
|
|
448
478
|
n,
|
|
449
479
|
m,
|
|
450
|
-
|
|
451
|
-
|
|
480
|
+
H + 1,
|
|
481
|
+
p,
|
|
452
482
|
i
|
|
453
|
-
),
|
|
454
|
-
|
|
483
|
+
), u.push(
|
|
484
|
+
S.toDataURL(
|
|
455
485
|
`image/${a.toLowerCase()}`,
|
|
456
486
|
o
|
|
457
487
|
)
|
|
458
488
|
);
|
|
459
489
|
}
|
|
460
|
-
return
|
|
490
|
+
return u;
|
|
461
491
|
} finally {
|
|
462
|
-
r.remove(),
|
|
492
|
+
r.remove(), l();
|
|
463
493
|
}
|
|
464
494
|
}
|
|
465
|
-
async function
|
|
466
|
-
const o =
|
|
495
|
+
async function et(t, e, a = {}) {
|
|
496
|
+
const o = M(a), i = await V(t, a);
|
|
467
497
|
e.innerHTML = "", Object.assign(e.style, {
|
|
468
498
|
direction: "ltr",
|
|
469
499
|
width: "fit-content",
|
|
@@ -473,8 +503,8 @@ async function tt(t, e, a = {}) {
|
|
|
473
503
|
background: "#e0e0e0"
|
|
474
504
|
});
|
|
475
505
|
for (let n = 0; n < i.length; n++) {
|
|
476
|
-
const
|
|
477
|
-
|
|
506
|
+
const l = document.createElement("img");
|
|
507
|
+
l.src = i[n], l.alt = `Page ${n + 1}`, Object.assign(l.style, {
|
|
478
508
|
width: o.pageWidth + "mm",
|
|
479
509
|
maxWidth: "100%",
|
|
480
510
|
height: "auto",
|
|
@@ -483,27 +513,27 @@ async function tt(t, e, a = {}) {
|
|
|
483
513
|
border: "1px solid #bbb",
|
|
484
514
|
boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
|
|
485
515
|
marginBottom: "16px"
|
|
486
|
-
}), e.appendChild(
|
|
516
|
+
}), e.appendChild(l);
|
|
487
517
|
}
|
|
488
518
|
}
|
|
489
|
-
async function
|
|
490
|
-
const o =
|
|
519
|
+
async function F(t, e, a = {}) {
|
|
520
|
+
const o = M(a), i = t.getNumberOfPages(), n = 2, l = n * (96 / 25.4), r = Math.round(o.pageWidth * l), s = Math.round(o.pageHeight * l), g = await D(e, o, n);
|
|
491
521
|
for (let c = 1; c <= i; c++) {
|
|
492
522
|
t.setPage(c);
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
const f =
|
|
496
|
-
f && (await
|
|
523
|
+
const h = document.createElement("canvas");
|
|
524
|
+
h.width = r, h.height = s;
|
|
525
|
+
const f = h.getContext("2d");
|
|
526
|
+
f && (await $(
|
|
497
527
|
f,
|
|
498
528
|
e,
|
|
499
|
-
|
|
529
|
+
g,
|
|
500
530
|
o,
|
|
501
|
-
|
|
531
|
+
l,
|
|
502
532
|
c,
|
|
503
533
|
i,
|
|
504
534
|
n
|
|
505
535
|
), t.addImage(
|
|
506
|
-
|
|
536
|
+
h.toDataURL("image/png"),
|
|
507
537
|
"PNG",
|
|
508
538
|
0,
|
|
509
539
|
0,
|
|
@@ -514,18 +544,18 @@ async function z(t, e, a = {}) {
|
|
|
514
544
|
return t;
|
|
515
545
|
}
|
|
516
546
|
export {
|
|
517
|
-
|
|
547
|
+
U as PAGE_MARGINS,
|
|
518
548
|
q as PAGE_SIZES,
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
549
|
+
F as addMarginContent,
|
|
550
|
+
E as computeLayout,
|
|
551
|
+
P as createPrintClone,
|
|
552
|
+
I as insertPageBreakSpacers,
|
|
553
|
+
N as normalizeTableAttributes,
|
|
554
|
+
Q as prepare,
|
|
555
|
+
et as previewPageImages,
|
|
556
|
+
X as renderHTML,
|
|
557
|
+
tt as renderImagePDF,
|
|
558
|
+
V as renderPageImages,
|
|
529
559
|
R as splitOversizedTables,
|
|
530
|
-
|
|
560
|
+
T as splitOversizedText
|
|
531
561
|
};
|
package/package.json
CHANGED