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