jspdf-utils 0.1.11 → 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.d.ts +2 -0
- package/dist/html-to-pdf.js +239 -208
- 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 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 S(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,49 +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:
|
|
294
|
-
fontFamily: c = "Arial, sans-serif"
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
else
|
|
302
|
-
for (let b = r.length - 1; b >= 1; b--) {
|
|
303
|
-
const W = r.substring(0, b);
|
|
304
|
-
if (H + t.measureText(W).width <= u) {
|
|
305
|
-
y(H, W);
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}, x = o + w, v = o + n - w;
|
|
310
|
-
C(x, v, (p, u) => t.fillText(u, p, i)), C(x, v, (p, u) => t.fillText(u, p, i + s)), t.save(), t.translate(o, i + s), t.rotate(-Math.PI / 2), C(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.save(), t.translate(o + n, i), t.rotate(Math.PI / 2), C(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.restore();
|
|
333
|
+
color: s = "#000000",
|
|
334
|
+
fontSize: g = 2.5,
|
|
335
|
+
fontFamily: c = "Arial, sans-serif",
|
|
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();
|
|
311
342
|
}
|
|
312
343
|
function k(t, e) {
|
|
313
|
-
return
|
|
344
|
+
return Z(t.margin, e);
|
|
314
345
|
}
|
|
315
|
-
async function
|
|
316
|
-
for (const
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
319
|
-
const c =
|
|
320
|
-
let
|
|
321
|
-
typeof
|
|
322
|
-
|
|
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),
|
|
323
354
|
c.width,
|
|
324
355
|
c.height,
|
|
325
356
|
r
|
|
326
|
-
) :
|
|
327
|
-
|
|
357
|
+
) : h = a[s], t.drawImage(
|
|
358
|
+
h,
|
|
328
359
|
0,
|
|
329
360
|
0,
|
|
330
|
-
|
|
331
|
-
|
|
361
|
+
h.width,
|
|
362
|
+
h.height,
|
|
332
363
|
Math.round(c.x * i),
|
|
333
364
|
Math.round(c.y * i),
|
|
334
365
|
Math.round(c.width * i),
|
|
@@ -336,8 +367,8 @@ async function F(t, e, a, o, i, n, s, r) {
|
|
|
336
367
|
);
|
|
337
368
|
}
|
|
338
369
|
if (e.contentBorder) {
|
|
339
|
-
const { color:
|
|
340
|
-
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(
|
|
341
372
|
Math.round(c.left * i),
|
|
342
373
|
Math.round(c.top * i),
|
|
343
374
|
Math.round((o.pageWidth - c.left - c.right) * i),
|
|
@@ -345,44 +376,44 @@ async function F(t, e, a, o, i, n, s, r) {
|
|
|
345
376
|
);
|
|
346
377
|
}
|
|
347
378
|
if (e.textBorder) {
|
|
348
|
-
const
|
|
349
|
-
|
|
379
|
+
const s = k(e.textBorder, o);
|
|
380
|
+
await K(
|
|
350
381
|
t,
|
|
351
382
|
e.textBorder,
|
|
352
383
|
i,
|
|
353
|
-
Math.round(
|
|
354
|
-
Math.round(
|
|
355
|
-
Math.round((o.pageWidth -
|
|
356
|
-
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)
|
|
357
388
|
);
|
|
358
389
|
}
|
|
359
390
|
}
|
|
360
|
-
async function
|
|
361
|
-
const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n =
|
|
362
|
-
r.style.opacity = "1", r.style.left = "-99999px",
|
|
363
|
-
const
|
|
364
|
-
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);
|
|
365
396
|
try {
|
|
366
|
-
const
|
|
397
|
+
const g = await W(r, {
|
|
367
398
|
scale: i,
|
|
368
399
|
backgroundColor: "#ffffff"
|
|
369
|
-
}), { jsPDF: c } = await import("jspdf"),
|
|
370
|
-
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,
|
|
371
402
|
unit: "mm",
|
|
372
403
|
format: [n.pageWidth, n.pageHeight]
|
|
373
404
|
});
|
|
374
|
-
for (let
|
|
405
|
+
for (let y = 0; y < b; y++) {
|
|
375
406
|
const p = Math.min(
|
|
376
407
|
m,
|
|
377
|
-
|
|
408
|
+
g.height - y * m
|
|
378
409
|
), u = document.createElement("canvas");
|
|
379
410
|
u.width = d, u.height = p;
|
|
380
|
-
const
|
|
381
|
-
if (!
|
|
382
|
-
|
|
383
|
-
|
|
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,
|
|
384
415
|
0,
|
|
385
|
-
|
|
416
|
+
y * m,
|
|
386
417
|
d,
|
|
387
418
|
p,
|
|
388
419
|
0,
|
|
@@ -390,67 +421,67 @@ async function X(t, e = {}) {
|
|
|
390
421
|
d,
|
|
391
422
|
p
|
|
392
423
|
);
|
|
393
|
-
const
|
|
424
|
+
const A = u.toDataURL(
|
|
394
425
|
`image/${a.toLowerCase()}`,
|
|
395
426
|
o
|
|
396
427
|
);
|
|
397
|
-
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
428
|
+
y > 0 && C.addPage([n.pageWidth, n.pageHeight], v);
|
|
429
|
+
const H = p / d * h;
|
|
430
|
+
C.addImage(
|
|
431
|
+
A,
|
|
401
432
|
a,
|
|
402
433
|
n.margin.left,
|
|
403
434
|
n.margin.top,
|
|
404
|
-
|
|
405
|
-
|
|
435
|
+
h,
|
|
436
|
+
H,
|
|
406
437
|
void 0,
|
|
407
438
|
"FAST"
|
|
408
439
|
);
|
|
409
440
|
}
|
|
410
|
-
return e.marginContent && await
|
|
441
|
+
return e.marginContent && await F(C, e.marginContent, e), C;
|
|
411
442
|
} finally {
|
|
412
|
-
r.remove(),
|
|
443
|
+
r.remove(), l();
|
|
413
444
|
}
|
|
414
445
|
}
|
|
415
|
-
async function
|
|
416
|
-
const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n =
|
|
417
|
-
r.style.opacity = "1", r.style.left = "-99999px",
|
|
418
|
-
const
|
|
419
|
-
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);
|
|
420
451
|
try {
|
|
421
|
-
const
|
|
452
|
+
const g = await W(r, {
|
|
422
453
|
scale: i,
|
|
423
454
|
backgroundColor: "#ffffff"
|
|
424
|
-
}), c = n.pageWidth - n.margin.left - n.margin.right,
|
|
425
|
-
for (let
|
|
426
|
-
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(
|
|
427
458
|
d,
|
|
428
|
-
|
|
429
|
-
),
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
if (!
|
|
433
|
-
|
|
434
|
-
|
|
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,
|
|
435
466
|
0,
|
|
436
|
-
|
|
437
|
-
f,
|
|
438
|
-
W,
|
|
439
|
-
v,
|
|
440
|
-
x,
|
|
467
|
+
H * d,
|
|
441
468
|
f,
|
|
442
|
-
|
|
443
|
-
), y && await F(
|
|
444
|
-
M,
|
|
469
|
+
O,
|
|
445
470
|
y,
|
|
446
|
-
|
|
471
|
+
C,
|
|
472
|
+
f,
|
|
473
|
+
O
|
|
474
|
+
), w && await $(
|
|
475
|
+
x,
|
|
476
|
+
w,
|
|
477
|
+
A,
|
|
447
478
|
n,
|
|
448
479
|
m,
|
|
449
|
-
|
|
480
|
+
H + 1,
|
|
450
481
|
p,
|
|
451
482
|
i
|
|
452
483
|
), u.push(
|
|
453
|
-
|
|
484
|
+
S.toDataURL(
|
|
454
485
|
`image/${a.toLowerCase()}`,
|
|
455
486
|
o
|
|
456
487
|
)
|
|
@@ -458,11 +489,11 @@ async function K(t, e = {}) {
|
|
|
458
489
|
}
|
|
459
490
|
return u;
|
|
460
491
|
} finally {
|
|
461
|
-
r.remove(),
|
|
492
|
+
r.remove(), l();
|
|
462
493
|
}
|
|
463
494
|
}
|
|
464
|
-
async function
|
|
465
|
-
const o =
|
|
495
|
+
async function et(t, e, a = {}) {
|
|
496
|
+
const o = M(a), i = await V(t, a);
|
|
466
497
|
e.innerHTML = "", Object.assign(e.style, {
|
|
467
498
|
direction: "ltr",
|
|
468
499
|
width: "fit-content",
|
|
@@ -472,8 +503,8 @@ async function tt(t, e, a = {}) {
|
|
|
472
503
|
background: "#e0e0e0"
|
|
473
504
|
});
|
|
474
505
|
for (let n = 0; n < i.length; n++) {
|
|
475
|
-
const
|
|
476
|
-
|
|
506
|
+
const l = document.createElement("img");
|
|
507
|
+
l.src = i[n], l.alt = `Page ${n + 1}`, Object.assign(l.style, {
|
|
477
508
|
width: o.pageWidth + "mm",
|
|
478
509
|
maxWidth: "100%",
|
|
479
510
|
height: "auto",
|
|
@@ -482,27 +513,27 @@ async function tt(t, e, a = {}) {
|
|
|
482
513
|
border: "1px solid #bbb",
|
|
483
514
|
boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
|
|
484
515
|
marginBottom: "16px"
|
|
485
|
-
}), e.appendChild(
|
|
516
|
+
}), e.appendChild(l);
|
|
486
517
|
}
|
|
487
518
|
}
|
|
488
|
-
async function
|
|
489
|
-
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);
|
|
490
521
|
for (let c = 1; c <= i; c++) {
|
|
491
522
|
t.setPage(c);
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
const f =
|
|
495
|
-
f && (await
|
|
523
|
+
const h = document.createElement("canvas");
|
|
524
|
+
h.width = r, h.height = s;
|
|
525
|
+
const f = h.getContext("2d");
|
|
526
|
+
f && (await $(
|
|
496
527
|
f,
|
|
497
528
|
e,
|
|
498
|
-
|
|
529
|
+
g,
|
|
499
530
|
o,
|
|
500
|
-
|
|
531
|
+
l,
|
|
501
532
|
c,
|
|
502
533
|
i,
|
|
503
534
|
n
|
|
504
535
|
), t.addImage(
|
|
505
|
-
|
|
536
|
+
h.toDataURL("image/png"),
|
|
506
537
|
"PNG",
|
|
507
538
|
0,
|
|
508
539
|
0,
|
|
@@ -513,18 +544,18 @@ async function z(t, e, a = {}) {
|
|
|
513
544
|
return t;
|
|
514
545
|
}
|
|
515
546
|
export {
|
|
516
|
-
|
|
547
|
+
U as PAGE_MARGINS,
|
|
517
548
|
q as PAGE_SIZES,
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
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,
|
|
528
559
|
R as splitOversizedTables,
|
|
529
|
-
|
|
560
|
+
T as splitOversizedText
|
|
530
561
|
};
|
package/package.json
CHANGED