jspdf-utils 0.1.10 → 0.1.11

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 +235 -245
  2. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import W from "html2canvas";
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 P(t = {}) {
26
- const e = t.format ?? "a4", [a, n] = q[e], i = t.pageWidth ?? a, o = t.pageHeight ?? n, s = $[e], r = {
25
+ function S(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: o,
36
+ pageHeight: n,
37
37
  margin: { ...r, ...t.margin }
38
38
  };
39
39
  }
40
- function x(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 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 B(t, e = 210) {
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 E(t) {
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 n of e.querySelectorAll("th, td"))
65
- n.style.padding || (n.style.padding = a + "px");
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 T(t, e) {
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 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, g = e - r - 2, d = [];
78
- let c = [], l = 0;
79
- for (const m of s) {
80
- const h = m.offsetHeight;
81
- l + h > g && c.length > 0 && (d.push(c), c = [], l = 0), c.push(m), l += h;
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 && d.push(c);
84
- for (const m of d) {
85
- const h = a.cloneNode(!1);
86
- o && h.appendChild(o.cloneNode(!0));
87
- for (const f of m) h.appendChild(f.cloneNode(!0));
88
- a.parentNode.insertBefore(h, a);
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 R(t, e) {
93
+ function j(t, e) {
94
94
  for (const a of Array.from(t.querySelectorAll(":scope > *"))) {
95
- const n = a;
96
- if (n.offsetHeight <= e || n.tagName === "TABLE")
95
+ const o = a;
96
+ if (o.offsetHeight <= e || o.tagName === "TABLE")
97
97
  continue;
98
- const i = n.tagName, o = n.getAttribute("style") || "", s = getComputedStyle(n).width, r = (n.textContent || "").split(/\s+/).filter(Boolean), g = document.createElement(i);
99
- g.setAttribute("style", o), Object.assign(g.style, {
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(g);
104
- const d = [];
103
+ }), t.appendChild(l);
104
+ const h = [];
105
105
  let c = 0;
106
106
  for (; c < r.length; ) {
107
- let l = c + 1, m = r.length;
108
- for (; l < m; ) {
109
- const f = Math.ceil((l + m) / 2);
110
- g.textContent = r.slice(c, f).join(" "), g.offsetHeight <= e ? l = f : m = f - 1;
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 h = document.createElement(i);
113
- h.setAttribute("style", o), h.textContent = r.slice(c, l).join(" "), d.push(h), c = l;
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
- g.remove();
116
- for (const l of d)
117
- n.parentNode.insertBefore(l, n);
118
- n.remove();
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 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;
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 g = a - r - 2;
127
- if (g <= 0) return !1;
128
- let d = 0, c = 0;
129
- for (const h of s) {
130
- if (c + h.offsetHeight > g) break;
131
- c += h.offsetHeight, d++;
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 (d === 0 || d === s.length) return !1;
134
- const l = t.cloneNode(!1);
135
- o && l.appendChild(o.cloneNode(!0));
136
- for (let h = 0; h < d; h++)
137
- l.appendChild(s[h].cloneNode(!0));
138
- const m = t.cloneNode(!1);
139
- o && m.appendChild(o.cloneNode(!0));
140
- for (let h = d; h < s.length; h++)
141
- m.appendChild(s[h].cloneNode(!0));
142
- return e.insertBefore(l, t), e.insertBefore(m, t), t.remove(), !0;
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 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);
149
- if (r.setAttribute("style", o), Object.assign(r.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 = n[0], r.offsetHeight > a)
153
+ }), e.appendChild(r), r.textContent = o[0], r.offsetHeight > a)
154
154
  return r.remove(), !1;
155
- let g = 1, d = n.length;
156
- for (; g < d; ) {
157
- const m = Math.ceil((g + d) / 2);
158
- r.textContent = n.slice(0, m).join(" "), r.offsetHeight <= a ? g = m : d = m - 1;
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(), g >= n.length) return !1;
160
+ if (r.remove(), l >= o.length) return !1;
161
161
  const c = document.createElement(i);
162
- c.setAttribute("style", o), c.textContent = n.slice(0, g).join(" ");
163
- const l = document.createElement(i);
164
- return l.setAttribute("style", o), l.textContent = n.slice(g).join(" "), e.insertBefore(c, t), e.insertBefore(l, t), t.remove(), !0;
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 j(t, e) {
166
+ function O(t, e) {
167
167
  let a = 0;
168
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;
170
- if (o > s) {
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 (n.tagName === "TABLE") {
172
+ if (o.tagName === "TABLE") {
173
173
  if (U(
174
- n,
174
+ o,
175
175
  t,
176
176
  r
177
177
  ))
178
178
  continue;
179
- } else if (_(n, t, r))
179
+ } else if (_(o, t, r))
180
180
  continue;
181
- if (n.offsetHeight <= e) {
182
- const g = document.createElement("div");
183
- g.style.height = s - i + 1 + "px", n.parentNode.insertBefore(g, n), a++;
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 = P(e), n = N(), i = B(t, a.pageWidth);
191
- E(i);
192
- const o = x(i, a);
193
- return T(i, o.pageContentPx), R(i, o.pageContentPx), j(i, o.pageContentPx), {
190
+ const a = S(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: o,
195
+ layout: n,
196
196
  options: a,
197
197
  cleanup: () => {
198
- i.remove(), n();
198
+ i.remove(), o();
199
199
  }
200
200
  };
201
201
  }
202
202
  async function Y(t, e, a = {}) {
203
- const { clone: n, layout: i, options: o, cleanup: s } = J(e, a);
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(n, {
206
+ t.html(o, {
207
207
  callback: () => r(),
208
208
  width: i.contentWidthMm,
209
209
  windowWidth: i.renderedWidth,
210
210
  margin: [
211
- o.margin.top,
212
- o.margin.right,
213
- o.margin.bottom,
214
- o.margin.left
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 k(t, e) {
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, n) {
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 W(i, {
257
- scale: n,
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 n = {};
266
+ const o = {};
267
267
  for (const i of G) {
268
- const o = t[i];
269
- if (o && typeof o != "function") {
270
- const s = k(i, e);
271
- n[i] = await L(
272
- o.cloneNode(!0),
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 n;
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,49 @@ function Q(t, e) {
286
286
  left: t.left ?? e.margin.left
287
287
  };
288
288
  }
289
- function Z(t, e, a, n, i, o, s) {
289
+ function Z(t, e, a, o, i, n, s) {
290
290
  const {
291
291
  text: r,
292
- color: g = "#000000",
293
- fontSize: d = 2.5,
292
+ color: l = "#000000",
293
+ fontSize: h = 2.5,
294
294
  fontFamily: c = "Arial, sans-serif"
295
- } = e, l = d * a, m = (e.gap ?? d * 0.5) * a;
296
- t.save(), t.fillStyle = g, t.font = `${l}px ${c}`, t.textBaseline = "middle";
297
- const h = t.measureText(r).width + m, f = l * 0.5;
298
- t.save(), t.beginPath(), t.rect(
299
- n + f,
300
- i - l,
301
- o - f * 2,
302
- l * 2
303
- ), t.clip();
304
- for (let u = n + f; u < n + o - f; u += h)
305
- t.fillText(r, u, i);
306
- t.restore(), t.save(), t.beginPath(), t.rect(
307
- n + f,
308
- i + s - l,
309
- o - f * 2,
310
- l * 2
311
- ), t.clip();
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();
295
+ } = e, g = h * a, f = (e.gap ?? h * 0.5) * a;
296
+ t.save(), t.fillStyle = l, t.font = `${g}px ${c}`, t.textBaseline = "middle";
297
+ const d = t.measureText(r).width, m = d + f, w = g * 0.2, C = (p, u, y) => {
298
+ for (let H = p; H < u; H += m)
299
+ if (H + d <= u)
300
+ y(H, r);
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();
321
311
  }
322
- function I(t, e) {
312
+ function k(t, e) {
323
313
  return Q(t.margin, e);
324
314
  }
325
- async function F(t, e, a, n, i, o, s, r) {
326
- for (const g of G) {
327
- const d = e[g];
328
- if (!d) continue;
329
- const c = k(g, n);
330
- let l;
331
- typeof d == "function" ? l = await L(
332
- d(o, s),
315
+ async function F(t, e, a, o, i, n, s, r) {
316
+ for (const l of G) {
317
+ const h = e[l];
318
+ if (!h) continue;
319
+ const c = I(l, o);
320
+ let g;
321
+ typeof h == "function" ? g = await L(
322
+ h(n, s),
333
323
  c.width,
334
324
  c.height,
335
325
  r
336
- ) : l = a[g], t.drawImage(
337
- l,
326
+ ) : g = a[l], t.drawImage(
327
+ g,
338
328
  0,
339
329
  0,
340
- l.width,
341
- l.height,
330
+ g.width,
331
+ g.height,
342
332
  Math.round(c.x * i),
343
333
  Math.round(c.y * i),
344
334
  Math.round(c.width * i),
@@ -346,145 +336,145 @@ async function F(t, e, a, n, i, o, s, r) {
346
336
  );
347
337
  }
348
338
  if (e.contentBorder) {
349
- const { color: g = "#000000", width: d = 0.3 } = e.contentBorder, c = I(e.contentBorder, n);
350
- t.strokeStyle = g, t.lineWidth = d * i, t.strokeRect(
339
+ const { color: l = "#000000", width: h = 0.3 } = e.contentBorder, c = k(e.contentBorder, o);
340
+ t.strokeStyle = l, t.lineWidth = h * i, t.strokeRect(
351
341
  Math.round(c.left * i),
352
342
  Math.round(c.top * i),
353
- Math.round((n.pageWidth - c.left - c.right) * i),
354
- Math.round((n.pageHeight - c.top - c.bottom) * i)
343
+ Math.round((o.pageWidth - c.left - c.right) * i),
344
+ Math.round((o.pageHeight - c.top - c.bottom) * i)
355
345
  );
356
346
  }
357
347
  if (e.textBorder) {
358
- const g = I(e.textBorder, n);
348
+ const l = k(e.textBorder, o);
359
349
  Z(
360
350
  t,
361
351
  e.textBorder,
362
352
  i,
363
- Math.round(g.left * i),
364
- Math.round(g.top * i),
365
- Math.round((n.pageWidth - g.left - g.right) * i),
366
- Math.round((n.pageHeight - g.top - g.bottom) * i)
353
+ Math.round(l.left * i),
354
+ Math.round(l.top * i),
355
+ Math.round((o.pageWidth - l.left - l.right) * i),
356
+ Math.round((o.pageHeight - l.top - l.bottom) * i)
367
357
  );
368
358
  }
369
359
  }
370
360
  async function X(t, e = {}) {
371
- const { imageFormat: a = "JPEG", imageQuality: n = 1, scale: i = 2 } = e, o = P(e), s = N(), r = B(t, o.pageWidth);
372
- r.style.opacity = "1", r.style.left = "-99999px", E(r);
373
- const g = x(r, o);
374
- T(r, g.pageContentPx), R(r, g.pageContentPx), j(r, g.pageContentPx);
361
+ const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n = S(e), s = N(), r = E(t, n.pageWidth);
362
+ r.style.opacity = "1", r.style.left = "-99999px", T(r);
363
+ const l = B(r, n);
364
+ R(r, l.pageContentPx), j(r, l.pageContentPx), O(r, l.pageContentPx);
375
365
  try {
376
- const d = await W(r, {
366
+ const h = await P(r, {
377
367
  scale: i,
378
368
  backgroundColor: "#ffffff"
379
- }), { jsPDF: c } = await import("jspdf"), l = o.pageWidth - o.margin.left - o.margin.right, m = o.pageHeight - o.margin.top - o.margin.bottom, h = d.width, f = m / l * h, u = Math.ceil(d.height / f), H = o.pageWidth > o.pageHeight ? "l" : "p", v = new c({
380
- orientation: H,
369
+ }), { 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, w = Math.ceil(h.height / m), C = n.pageWidth > n.pageHeight ? "l" : "p", x = new c({
370
+ orientation: C,
381
371
  unit: "mm",
382
- format: [o.pageWidth, o.pageHeight]
372
+ format: [n.pageWidth, n.pageHeight]
383
373
  });
384
- for (let w = 0; w < u; w++) {
385
- const y = Math.min(
386
- f,
387
- d.height - w * f
388
- ), b = document.createElement("canvas");
389
- b.width = h, b.height = y;
390
- const p = b.getContext("2d");
391
- if (!p) throw new Error("Could not get canvas context");
392
- p.fillStyle = "#ffffff", p.fillRect(0, 0, h, y), p.drawImage(
393
- d,
394
- 0,
395
- w * f,
374
+ for (let v = 0; v < w; v++) {
375
+ const p = Math.min(
376
+ m,
377
+ h.height - v * m
378
+ ), u = document.createElement("canvas");
379
+ u.width = d, u.height = p;
380
+ const y = u.getContext("2d");
381
+ if (!y) throw new Error("Could not get canvas context");
382
+ y.fillStyle = "#ffffff", y.fillRect(0, 0, d, p), y.drawImage(
396
383
  h,
397
- y,
384
+ 0,
385
+ v * m,
386
+ d,
387
+ p,
398
388
  0,
399
389
  0,
400
- h,
401
- y
390
+ d,
391
+ p
402
392
  );
403
- const A = b.toDataURL(
393
+ const H = u.toDataURL(
404
394
  `image/${a.toLowerCase()}`,
405
- n
395
+ o
406
396
  );
407
- w > 0 && v.addPage([o.pageWidth, o.pageHeight], H);
408
- const C = y / h * l;
409
- v.addImage(
410
- A,
397
+ v > 0 && x.addPage([n.pageWidth, n.pageHeight], C);
398
+ const b = p / d * g;
399
+ x.addImage(
400
+ H,
411
401
  a,
412
- o.margin.left,
413
- o.margin.top,
414
- l,
415
- C,
402
+ n.margin.left,
403
+ n.margin.top,
404
+ g,
405
+ b,
416
406
  void 0,
417
407
  "FAST"
418
408
  );
419
409
  }
420
- return e.marginContent && await z(v, e.marginContent, e), v;
410
+ return e.marginContent && await z(x, e.marginContent, e), x;
421
411
  } finally {
422
412
  r.remove(), s();
423
413
  }
424
414
  }
425
415
  async function K(t, e = {}) {
426
- const { imageFormat: a = "PNG", imageQuality: n = 1, scale: i = 2 } = e, o = P(e), s = N(), r = B(t, o.pageWidth);
427
- r.style.opacity = "1", r.style.left = "-99999px", E(r);
428
- const g = x(r, o);
429
- T(r, g.pageContentPx), R(r, g.pageContentPx), j(r, g.pageContentPx);
416
+ const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n = S(e), s = N(), r = E(t, n.pageWidth);
417
+ r.style.opacity = "1", r.style.left = "-99999px", T(r);
418
+ const l = B(r, n);
419
+ R(r, l.pageContentPx), j(r, l.pageContentPx), O(r, l.pageContentPx);
430
420
  try {
431
- const d = await W(r, {
421
+ const h = await P(r, {
432
422
  scale: i,
433
423
  backgroundColor: "#ffffff"
434
- }), c = o.pageWidth - o.margin.left - o.margin.right, l = o.pageHeight - o.margin.top - o.margin.bottom, m = d.width, h = l / c * m, f = m / c, u = Math.round(o.pageWidth * f), H = Math.round(o.pageHeight * f), v = Math.round(o.margin.top * f), w = Math.round(o.margin.left * f), y = Math.ceil(d.height / h), b = [], { marginContent: p } = e, A = p ? await D(p, o, i) : {};
435
- for (let C = 0; C < y; C++) {
436
- const O = Math.min(
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(
424
+ }), 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, w = Math.round(n.pageWidth * m), C = Math.round(n.pageHeight * m), x = Math.round(n.margin.top * m), v = Math.round(n.margin.left * m), p = Math.ceil(h.height / d), u = [], { marginContent: y } = e, H = y ? await D(y, n, i) : {};
425
+ for (let b = 0; b < p; b++) {
426
+ const W = Math.min(
444
427
  d,
428
+ h.height - b * d
429
+ ), A = document.createElement("canvas");
430
+ A.width = w, A.height = C;
431
+ const M = A.getContext("2d");
432
+ if (!M) throw new Error("Could not get canvas context");
433
+ M.fillStyle = "#ffffff", M.fillRect(0, 0, w, C), M.drawImage(
434
+ h,
445
435
  0,
446
- C * h,
447
- m,
448
- O,
449
- w,
436
+ b * d,
437
+ f,
438
+ W,
450
439
  v,
451
- m,
452
- O
453
- ), p && await F(
454
- M,
455
- p,
456
- A,
457
- o,
440
+ x,
458
441
  f,
459
- C + 1,
442
+ W
443
+ ), y && await F(
444
+ M,
460
445
  y,
446
+ H,
447
+ n,
448
+ m,
449
+ b + 1,
450
+ p,
461
451
  i
462
- ), b.push(
463
- S.toDataURL(
452
+ ), u.push(
453
+ A.toDataURL(
464
454
  `image/${a.toLowerCase()}`,
465
- n
455
+ o
466
456
  )
467
457
  );
468
458
  }
469
- return b;
459
+ return u;
470
460
  } finally {
471
461
  r.remove(), s();
472
462
  }
473
463
  }
474
464
  async function tt(t, e, a = {}) {
475
- const n = P(a), i = await K(t, a);
465
+ const o = S(a), i = await K(t, a);
476
466
  e.innerHTML = "", Object.assign(e.style, {
477
467
  direction: "ltr",
478
468
  width: "fit-content",
479
- height: n.pageHeight + "mm",
469
+ height: o.pageHeight + "mm",
480
470
  maxHeight: "100vh",
481
471
  overflowY: "auto",
482
472
  background: "#e0e0e0"
483
473
  });
484
- for (let o = 0; o < i.length; o++) {
474
+ for (let n = 0; n < i.length; n++) {
485
475
  const s = document.createElement("img");
486
- s.src = i[o], s.alt = `Page ${o + 1}`, Object.assign(s.style, {
487
- width: n.pageWidth + "mm",
476
+ s.src = i[n], s.alt = `Page ${n + 1}`, Object.assign(s.style, {
477
+ width: o.pageWidth + "mm",
488
478
  maxWidth: "100%",
489
479
  height: "auto",
490
480
  boxSizing: "border-box",
@@ -496,28 +486,28 @@ async function tt(t, e, a = {}) {
496
486
  }
497
487
  }
498
488
  async function z(t, e, a = {}) {
499
- const n = P(a), i = t.getNumberOfPages(), o = 2, s = o * (96 / 25.4), r = Math.round(n.pageWidth * s), g = Math.round(n.pageHeight * s), d = await D(e, n, o);
489
+ const o = S(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
490
  for (let c = 1; c <= i; c++) {
501
491
  t.setPage(c);
502
- const l = document.createElement("canvas");
503
- l.width = r, l.height = g;
504
- const m = l.getContext("2d");
505
- m && (await F(
506
- m,
492
+ const g = document.createElement("canvas");
493
+ g.width = r, g.height = l;
494
+ const f = g.getContext("2d");
495
+ f && (await F(
496
+ f,
507
497
  e,
508
- d,
509
- n,
498
+ h,
499
+ o,
510
500
  s,
511
501
  c,
512
502
  i,
513
- o
503
+ n
514
504
  ), t.addImage(
515
- l.toDataURL("image/png"),
505
+ g.toDataURL("image/png"),
516
506
  "PNG",
517
507
  0,
518
508
  0,
519
- n.pageWidth,
520
- n.pageHeight
509
+ o.pageWidth,
510
+ o.pageHeight
521
511
  ));
522
512
  }
523
513
  return t;
@@ -526,15 +516,15 @@ export {
526
516
  $ as PAGE_MARGINS,
527
517
  q as PAGE_SIZES,
528
518
  z as addMarginContent,
529
- x as computeLayout,
530
- B as createPrintClone,
531
- j as insertPageBreakSpacers,
532
- E as normalizeTableAttributes,
519
+ B as computeLayout,
520
+ E as createPrintClone,
521
+ O as insertPageBreakSpacers,
522
+ T as normalizeTableAttributes,
533
523
  J as prepare,
534
524
  tt as previewPageImages,
535
525
  Y as renderHTML,
536
526
  X as renderImagePDF,
537
527
  K as renderPageImages,
538
- T as splitOversizedTables,
539
- R as splitOversizedText
528
+ R as splitOversizedTables,
529
+ j as splitOversizedText
540
530
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
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",