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