jspdf-utils 0.1.16 → 0.1.17

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 +183 -185
  2. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import A from "html2canvas";
2
- const z = {
1
+ import P from "html2canvas";
2
+ const _ = {
3
3
  a0: [841, 1189],
4
4
  a1: [594, 841],
5
5
  a2: [420, 594],
@@ -10,7 +10,7 @@ const z = {
10
10
  letter: [215.9, 279.4],
11
11
  legal: [215.9, 355.6],
12
12
  tabloid: [279.4, 431.8]
13
- }, _ = {
13
+ }, J = {
14
14
  a0: 40,
15
15
  a1: 35,
16
16
  a2: 30,
@@ -22,8 +22,8 @@ const z = {
22
22
  legal: 25.4,
23
23
  tabloid: 25
24
24
  };
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 = {
25
+ function S(e = {}) {
26
+ const n = e.format ?? "a4", [a, t] = _[n], i = e.pageWidth ?? a, o = e.pageHeight ?? t, s = J[n], r = {
27
27
  top: s,
28
28
  right: s,
29
29
  bottom: s,
@@ -41,7 +41,7 @@ function R(e, n) {
41
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
42
  return { renderedWidth: a, scale: i, contentWidthMm: t, pageContentPx: s };
43
43
  }
44
- function P(e, n = 210) {
44
+ function N(e, n = 210) {
45
45
  const a = e.cloneNode(!0);
46
46
  return Object.assign(a.style, {
47
47
  position: "fixed",
@@ -63,7 +63,7 @@ function G(e) {
63
63
  const t = a - n.top;
64
64
  t > e.offsetHeight && (e.style.minHeight = t + "px");
65
65
  }
66
- async function J(e) {
66
+ async function Q(e) {
67
67
  const n = Array.from(e.querySelectorAll("img"));
68
68
  if (n.length === 0) return;
69
69
  await Promise.all(
@@ -90,11 +90,11 @@ async function J(e) {
90
90
  }
91
91
  }
92
92
  }
93
- function N() {
93
+ function F() {
94
94
  const e = document.createElement("style");
95
95
  return e.setAttribute("data-jspdf-utils", ""), e.textContent = "img { display: inline !important; }", document.head.appendChild(e), () => e.remove();
96
96
  }
97
- function F(e) {
97
+ function I(e) {
98
98
  for (const n of e.querySelectorAll("table")) {
99
99
  const a = n.getAttribute("cellpadding");
100
100
  if (a) {
@@ -104,7 +104,7 @@ function F(e) {
104
104
  }
105
105
  }
106
106
  }
107
- function I(e, n) {
107
+ function L(e, n) {
108
108
  for (const a of Array.from(
109
109
  e.querySelectorAll(":scope > table")
110
110
  )) {
@@ -112,16 +112,16 @@ function I(e, n) {
112
112
  const t = Array.from(a.rows);
113
113
  if (t.length === 0) continue;
114
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;
115
+ let c = [], u = 0;
116
116
  for (const d of s) {
117
117
  const g = d.offsetHeight;
118
- f + g > l && c.length > 0 && (h.push(c), c = [], f = 0), c.push(d), f += g;
118
+ u + g > l && c.length > 0 && (h.push(c), c = [], u = 0), c.push(d), u += g;
119
119
  }
120
120
  c.length > 0 && h.push(c);
121
121
  for (const d of h) {
122
122
  const g = a.cloneNode(!1);
123
123
  o && g.appendChild(o.cloneNode(!0));
124
- for (const u of d) g.appendChild(u.cloneNode(!0));
124
+ for (const f of d) g.appendChild(f.cloneNode(!0));
125
125
  a.parentNode.insertBefore(g, a);
126
126
  }
127
127
  a.remove();
@@ -141,21 +141,21 @@ function O(e, n) {
141
141
  const h = [];
142
142
  let c = 0;
143
143
  for (; c < r.length; ) {
144
- let f = c + 1, d = r.length;
145
- for (; f < d; ) {
146
- const u = Math.ceil((f + d) / 2);
147
- l.textContent = r.slice(c, u).join(" "), l.offsetHeight <= n ? f = u : d = u - 1;
144
+ let u = c + 1, d = r.length;
145
+ for (; u < d; ) {
146
+ const f = Math.ceil((u + d) / 2);
147
+ l.textContent = r.slice(c, f).join(" "), l.offsetHeight <= n ? u = f : d = f - 1;
148
148
  }
149
149
  const g = document.createElement(i);
150
- g.setAttribute("style", o), g.textContent = r.slice(c, f).join(" "), h.push(g), c = f;
150
+ g.setAttribute("style", o), g.textContent = r.slice(c, u).join(" "), h.push(g), c = u;
151
151
  }
152
152
  l.remove();
153
- for (const f of h)
154
- t.parentNode.insertBefore(f, t);
153
+ for (const u of h)
154
+ t.parentNode.insertBefore(u, t);
155
155
  t.remove();
156
156
  }
157
157
  }
158
- function Q(e, n, a) {
158
+ function Z(e, n, a) {
159
159
  const t = Array.from(e.rows);
160
160
  if (t.length === 0) return !1;
161
161
  const i = t[0].querySelector("th") !== null, o = i ? t[0] : null, s = i ? t.slice(1) : t, r = o ? o.offsetHeight : 0;
@@ -168,17 +168,17 @@ function Q(e, n, a) {
168
168
  c += g.offsetHeight, h++;
169
169
  }
170
170
  if (h === 0 || h === s.length) return !1;
171
- const f = e.cloneNode(!1);
172
- o && f.appendChild(o.cloneNode(!0));
171
+ const u = e.cloneNode(!1);
172
+ o && u.appendChild(o.cloneNode(!0));
173
173
  for (let g = 0; g < h; g++)
174
- f.appendChild(s[g].cloneNode(!0));
174
+ u.appendChild(s[g].cloneNode(!0));
175
175
  const d = e.cloneNode(!1);
176
176
  o && d.appendChild(o.cloneNode(!0));
177
177
  for (let g = h; g < s.length; g++)
178
178
  d.appendChild(s[g].cloneNode(!0));
179
- return n.insertBefore(f, e), n.insertBefore(d, e), e.remove(), !0;
179
+ return n.insertBefore(u, e), n.insertBefore(d, e), e.remove(), !0;
180
180
  }
181
- function Z(e, n, a) {
181
+ function K(e, n, a) {
182
182
  if (e.tagName === "TABLE" || e.tagName === "IMG") return !1;
183
183
  const t = (e.textContent || "").split(/\s+/).filter(Boolean);
184
184
  if (t.length < 2) return !1;
@@ -197,23 +197,23 @@ function Z(e, n, a) {
197
197
  if (r.remove(), l >= t.length) return !1;
198
198
  const c = document.createElement(i);
199
199
  c.setAttribute("style", o), c.textContent = t.slice(0, l).join(" ");
200
- const f = document.createElement(i);
201
- return f.setAttribute("style", o), f.textContent = t.slice(l).join(" "), n.insertBefore(c, e), n.insertBefore(f, e), e.remove(), !0;
200
+ const u = document.createElement(i);
201
+ return u.setAttribute("style", o), u.textContent = t.slice(l).join(" "), n.insertBefore(c, e), n.insertBefore(u, e), e.remove(), !0;
202
202
  }
203
- function L(e, n) {
203
+ function T(e, n) {
204
204
  let a = 0;
205
205
  for (; a < e.children.length; ) {
206
206
  const t = e.children[a], i = t.offsetTop, o = i + t.offsetHeight, s = (Math.floor(i / n) + 1) * n;
207
207
  if (o > s) {
208
208
  const r = s - i;
209
209
  if (t.tagName === "TABLE") {
210
- if (Q(
210
+ if (Z(
211
211
  t,
212
212
  e,
213
213
  r
214
214
  ))
215
215
  continue;
216
- } else if (Z(t, e, r))
216
+ } else if (K(t, e, r))
217
217
  continue;
218
218
  if (t.offsetHeight <= n) {
219
219
  const l = document.createElement("div");
@@ -223,11 +223,11 @@ function L(e, n) {
223
223
  a++;
224
224
  }
225
225
  }
226
- function K(e, n = {}) {
227
- const a = W(n), t = N(), i = P(e, a.pageWidth);
228
- F(i);
226
+ function V(e, n = {}) {
227
+ const a = S(n), t = F(), i = N(e, a.pageWidth);
228
+ I(i);
229
229
  const o = R(i, a);
230
- return I(i, o.pageContentPx), O(i, o.pageContentPx), L(i, o.pageContentPx), {
230
+ return L(i, o.pageContentPx), O(i, o.pageContentPx), T(i, o.pageContentPx), {
231
231
  clone: i,
232
232
  layout: o,
233
233
  options: a,
@@ -236,10 +236,10 @@ function K(e, n = {}) {
236
236
  }
237
237
  };
238
238
  }
239
- async function nt(e, n, a = {}) {
240
- const { clone: t, layout: i, options: o, cleanup: s } = K(n, a);
239
+ async function ot(e, n, a = {}) {
240
+ const { clone: t, layout: i, options: o, cleanup: s } = V(n, a);
241
241
  try {
242
- await J(t), await new Promise((r) => {
242
+ await Q(t), await new Promise((r) => {
243
243
  e.html(t, {
244
244
  callback: () => r(),
245
245
  width: i.contentWidthMm,
@@ -257,7 +257,7 @@ async function nt(e, n, a = {}) {
257
257
  }
258
258
  return a.marginContent && await $(e, a.marginContent, a), e;
259
259
  }
260
- function T(e, n) {
260
+ function j(e, n) {
261
261
  switch (e) {
262
262
  case "top":
263
263
  return { x: 0, y: 0, width: n.pageWidth, height: n.margin.top };
@@ -279,7 +279,7 @@ function T(e, n) {
279
279
  };
280
280
  }
281
281
  }
282
- async function j(e, n, a, t) {
282
+ async function k(e, n, a, t) {
283
283
  const i = document.createElement("div");
284
284
  Object.assign(i.style, {
285
285
  position: "fixed",
@@ -290,7 +290,7 @@ async function j(e, n, a, t) {
290
290
  overflow: "hidden"
291
291
  }), i.appendChild(e), document.body.appendChild(i);
292
292
  try {
293
- return await A(i, {
293
+ return await P(i, {
294
294
  scale: t,
295
295
  backgroundColor: null
296
296
  });
@@ -298,14 +298,14 @@ async function j(e, n, a, t) {
298
298
  i.remove();
299
299
  }
300
300
  }
301
- const S = ["top", "right", "bottom", "left"];
301
+ const B = ["top", "right", "bottom", "left"];
302
302
  async function q(e, n, a) {
303
303
  const t = {};
304
- for (const i of S) {
304
+ for (const i of B) {
305
305
  const o = e[i];
306
306
  if (o && typeof o != "function") {
307
- const s = T(i, n);
308
- t[i] = await j(
307
+ const s = j(i, n);
308
+ t[i] = await k(
309
309
  o.cloneNode(!0),
310
310
  s.width,
311
311
  s.height,
@@ -315,7 +315,7 @@ async function q(e, n, a) {
315
315
  }
316
316
  return t;
317
317
  }
318
- function V(e, n) {
318
+ function Y(e, n) {
319
319
  return e == null ? n.margin : typeof e == "number" ? { top: e, right: e, bottom: e, left: e } : {
320
320
  top: e.top ?? n.margin.top,
321
321
  right: e.right ?? n.margin.right,
@@ -323,7 +323,7 @@ function V(e, n) {
323
323
  left: e.left ?? n.margin.left
324
324
  };
325
325
  }
326
- const Y = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
326
+ const X = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
327
327
  async function D(e, n, a, t, i, o, s, r, l = !1) {
328
328
  const h = document.createElement("div");
329
329
  Object.assign(h.style, {
@@ -352,17 +352,17 @@ async function D(e, n, a, t, i, o, s, r, l = !1) {
352
352
  fontFamily: i,
353
353
  fontWeight: o
354
354
  }), document.body.appendChild(c);
355
- const f = c.offsetWidth;
355
+ const u = c.offsetWidth;
356
356
  c.remove();
357
- const d = Math.ceil(n / (f + r)) + 2;
357
+ const d = Math.ceil(n / (u + r)) + 2;
358
358
  for (let g = 0; g < d; g++) {
359
- const u = document.createElement("span");
360
- u.textContent = e, u.style.flexShrink = "0", h.appendChild(u);
359
+ const f = document.createElement("span");
360
+ f.textContent = e, f.style.flexShrink = "0", h.appendChild(f);
361
361
  }
362
362
  document.body.appendChild(h);
363
363
  try {
364
- return await A(h, {
365
- scale: 1,
364
+ return await P(h, {
365
+ scale: 3,
366
366
  backgroundColor: null,
367
367
  width: Math.ceil(n),
368
368
  height: Math.ceil(a)
@@ -377,93 +377,93 @@ async function U(e, n, a, t, i, o, s) {
377
377
  color: l = "#000000",
378
378
  fontSize: h = 2.5,
379
379
  fontFamily: c = "Arial, sans-serif",
380
- fontWeight: f = "normal"
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([
380
+ fontWeight: u = "normal"
381
+ } = n, d = h * a, g = (n.gap ?? h * 0.5) * a, f = d * 0.5, m = Math.ceil(d * 1.5), y = X.test(r), p = Math.round(o - f * 2), C = Math.round(s - f * 2), [w, b] = await Promise.all([
382
382
  D(
383
383
  r,
384
384
  p,
385
385
  m,
386
386
  d,
387
387
  c,
388
- f,
388
+ u,
389
389
  l,
390
390
  g,
391
- b
391
+ y
392
392
  ),
393
393
  D(
394
394
  r,
395
- y,
395
+ C,
396
396
  m,
397
397
  d,
398
398
  c,
399
- f,
399
+ u,
400
400
  l,
401
401
  g,
402
- b
402
+ y
403
403
  )
404
- ]), w = Math.round(m / 2);
404
+ ]), x = Math.round(m / 2);
405
405
  e.drawImage(
406
- C,
406
+ w,
407
407
  0,
408
408
  0,
409
- p,
410
- m,
411
- t + u,
412
- i - w,
409
+ w.width,
410
+ w.height,
411
+ t + f,
412
+ i - x,
413
413
  p,
414
414
  m
415
415
  ), e.drawImage(
416
- C,
416
+ w,
417
417
  0,
418
418
  0,
419
- p,
420
- m,
421
- t + u,
422
- i + s - w,
419
+ w.width,
420
+ w.height,
421
+ t + f,
422
+ i + s - x,
423
423
  p,
424
424
  m
425
- ), e.save(), e.translate(t, i + s - u), e.rotate(-Math.PI / 2), e.drawImage(
426
- v,
425
+ ), e.save(), e.translate(t, i + s - f), e.rotate(-Math.PI / 2), e.drawImage(
426
+ b,
427
427
  0,
428
428
  0,
429
- y,
430
- m,
429
+ b.width,
430
+ b.height,
431
431
  0,
432
- -w,
433
- y,
432
+ -x,
433
+ C,
434
434
  m
435
- ), e.restore(), e.save(), e.translate(t + o, i + u), e.rotate(Math.PI / 2), e.drawImage(
436
- v,
435
+ ), e.restore(), e.save(), e.translate(t + o, i + f), e.rotate(Math.PI / 2), e.drawImage(
436
+ b,
437
437
  0,
438
438
  0,
439
- y,
440
- m,
439
+ b.width,
440
+ b.height,
441
441
  0,
442
- -w,
443
- y,
442
+ -x,
443
+ C,
444
444
  m
445
445
  ), e.restore();
446
446
  }
447
- function B(e, n) {
448
- return V(e.margin, n);
447
+ function A(e, n) {
448
+ return Y(e.margin, n);
449
449
  }
450
- async function X(e, n, a, t, i, o, s, r) {
451
- for (const l of S) {
450
+ async function tt(e, n, a, t, i, o, s, r) {
451
+ for (const l of B) {
452
452
  const h = n[l];
453
453
  if (!h) continue;
454
- const c = T(l, t);
455
- let f;
456
- typeof h == "function" ? f = await j(
454
+ const c = j(l, t);
455
+ let u;
456
+ typeof h == "function" ? u = await k(
457
457
  h(o, s),
458
458
  c.width,
459
459
  c.height,
460
460
  r
461
- ) : f = a[l], e.drawImage(
462
- f,
461
+ ) : u = a[l], e.drawImage(
462
+ u,
463
463
  0,
464
464
  0,
465
- f.width,
466
- f.height,
465
+ u.width,
466
+ u.height,
467
467
  Math.round(c.x * i),
468
468
  Math.round(c.y * i),
469
469
  Math.round(c.width * i),
@@ -471,7 +471,7 @@ async function X(e, n, a, t, i, o, s, r) {
471
471
  );
472
472
  }
473
473
  if (n.contentBorder) {
474
- const { color: l = "#000000", width: h = 0.3 } = n.contentBorder, c = B(n.contentBorder, t);
474
+ const { color: l = "#000000", width: h = 0.3 } = n.contentBorder, c = A(n.contentBorder, t);
475
475
  e.strokeStyle = l, e.lineWidth = h * i, e.strokeRect(
476
476
  Math.round(c.left * i),
477
477
  Math.round(c.top * i),
@@ -480,7 +480,7 @@ async function X(e, n, a, t, i, o, s, r) {
480
480
  );
481
481
  }
482
482
  if (n.textBorder) {
483
- const l = B(n.textBorder, t);
483
+ const l = A(n.textBorder, t);
484
484
  await U(
485
485
  e,
486
486
  n.textBorder,
@@ -492,52 +492,50 @@ async function X(e, n, a, t, i, o, s, r) {
492
492
  );
493
493
  }
494
494
  }
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);
497
- r.style.opacity = "1", r.style.left = "-99999px", F(r);
495
+ async function it(e, n = {}) {
496
+ const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o = S(n), s = F(), r = N(e, o.pageWidth);
497
+ r.style.opacity = "1", r.style.left = "-99999px", I(r);
498
498
  const l = R(r, o);
499
- I(r, l.pageContentPx), O(r, l.pageContentPx), L(r, l.pageContentPx), G(r);
499
+ L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), G(r);
500
500
  try {
501
- const h = await A(r, {
501
+ const h = await P(r, {
502
502
  scale: i,
503
503
  backgroundColor: "#ffffff"
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({
505
- orientation: b,
504
+ }), { jsPDF: c } = await import("jspdf"), u = o.pageWidth - o.margin.left - o.margin.right, d = o.pageHeight - o.margin.top - o.margin.bottom, g = h.width, f = d / u * g, m = Math.ceil(h.height / f), y = o.pageWidth > o.pageHeight ? "l" : "p", p = new c({
505
+ orientation: y,
506
506
  unit: "mm",
507
507
  format: [o.pageWidth, o.pageHeight]
508
- });
509
- for (let y = 0; y < m; y++) {
510
- const C = Math.min(
511
- u,
512
- h.height - y * u
513
- ), v = document.createElement("canvas");
514
- v.width = g, v.height = C;
515
- const w = v.getContext("2d");
516
- if (!w) throw new Error("Could not get canvas context");
517
- w.fillStyle = "#ffffff", w.fillRect(0, 0, g, C), w.drawImage(
508
+ }), C = g / u, w = Math.round(o.pageWidth * C), b = Math.round(o.pageHeight * C), x = Math.round(o.margin.top * C), E = Math.round(o.margin.left * C);
509
+ for (let H = 0; H < m; H++) {
510
+ const M = Math.min(
511
+ f,
512
+ h.height - H * f
513
+ ), W = document.createElement("canvas");
514
+ W.width = w, W.height = b;
515
+ const v = W.getContext("2d");
516
+ if (!v) throw new Error("Could not get canvas context");
517
+ v.fillStyle = "#ffffff", v.fillRect(0, 0, w, b), v.drawImage(
518
518
  h,
519
519
  0,
520
- y * u,
520
+ H * f,
521
521
  g,
522
- C,
523
- 0,
524
- 0,
522
+ M,
523
+ E,
524
+ x,
525
525
  g,
526
- C
526
+ M
527
527
  );
528
- const E = v.toDataURL(
528
+ const z = W.toDataURL(
529
529
  `image/${a.toLowerCase()}`,
530
530
  t
531
531
  );
532
- y > 0 && p.addPage([o.pageWidth, o.pageHeight], b);
533
- const H = C / g * f;
534
- p.addImage(
535
- E,
532
+ H > 0 && p.addPage([o.pageWidth, o.pageHeight], y), p.addImage(
533
+ z,
536
534
  a,
537
- o.margin.left,
538
- o.margin.top,
539
- f,
540
- H,
535
+ 0,
536
+ 0,
537
+ o.pageWidth,
538
+ o.pageHeight,
541
539
  void 0,
542
540
  "SLOW"
543
541
  );
@@ -547,57 +545,57 @@ async function ot(e, n = {}) {
547
545
  r.remove(), s();
548
546
  }
549
547
  }
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);
552
- r.style.opacity = "1", r.style.left = "-99999px", F(r);
548
+ async function et(e, n = {}) {
549
+ const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o = S(n), s = F(), r = N(e, o.pageWidth);
550
+ r.style.opacity = "1", r.style.left = "-99999px", I(r);
553
551
  const l = R(r, o);
554
- I(r, l.pageContentPx), O(r, l.pageContentPx), L(r, l.pageContentPx), G(r);
552
+ L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), G(r);
555
553
  try {
556
- const h = await A(r, {
554
+ const h = await P(r, {
557
555
  scale: i,
558
556
  backgroundColor: "#ffffff"
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++) {
561
- const k = Math.min(
557
+ }), c = o.pageWidth - o.margin.left - o.margin.right, u = o.pageHeight - o.margin.top - o.margin.bottom, d = h.width, g = u / c * d, f = d / c, m = Math.round(o.pageWidth * f), y = Math.round(o.pageHeight * f), p = Math.round(o.margin.top * f), C = Math.round(o.margin.left * f), w = Math.ceil(h.height / g), b = [], { marginContent: x } = n, E = x ? await q(x, o, i) : {};
558
+ for (let H = 0; H < w; H++) {
559
+ const M = Math.min(
562
560
  g,
563
561
  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(
562
+ ), W = document.createElement("canvas");
563
+ W.width = m, W.height = y;
564
+ const v = W.getContext("2d");
565
+ if (!v) throw new Error("Could not get canvas context");
566
+ v.fillStyle = "#ffffff", v.fillRect(0, 0, m, y), v.drawImage(
569
567
  h,
570
568
  0,
571
569
  H * g,
572
570
  d,
573
- k,
574
- y,
571
+ M,
572
+ C,
575
573
  p,
576
574
  d,
577
- k
578
- ), w && await X(
575
+ M
576
+ ), x && await tt(
577
+ v,
579
578
  x,
580
- w,
581
579
  E,
582
580
  o,
583
- u,
581
+ f,
584
582
  H + 1,
585
- C,
583
+ w,
586
584
  i
587
- ), v.push(
588
- M.toDataURL(
585
+ ), b.push(
586
+ W.toDataURL(
589
587
  `image/${a.toLowerCase()}`,
590
588
  t
591
589
  )
592
590
  );
593
591
  }
594
- return v;
592
+ return b;
595
593
  } finally {
596
594
  r.remove(), s();
597
595
  }
598
596
  }
599
- async function it(e, n, a = {}) {
600
- const t = W(a), i = await tt(e, a);
597
+ async function at(e, n, a = {}) {
598
+ const t = S(a), i = await et(e, a);
601
599
  n.innerHTML = "", Object.assign(n.style, {
602
600
  direction: "ltr",
603
601
  width: "fit-content",
@@ -621,41 +619,41 @@ async function it(e, n, a = {}) {
621
619
  }
622
620
  }
623
621
  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 = {};
625
- for (const d of S)
622
+ const t = S(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 = {};
623
+ for (const d of B)
626
624
  h[d] && (c[d] = h[d].toDataURL("image/png"));
627
- let f;
625
+ let u;
628
626
  if (n.textBorder) {
629
627
  const d = document.createElement("canvas");
630
628
  d.width = r, d.height = l;
631
629
  const g = d.getContext("2d");
632
630
  if (g) {
633
- const u = B(n.textBorder, t);
631
+ const f = A(n.textBorder, t);
634
632
  await U(
635
633
  g,
636
634
  n.textBorder,
637
635
  s,
638
- Math.round(u.left * s),
639
- Math.round(u.top * s),
640
- Math.round((t.pageWidth - u.left - u.right) * s),
641
- Math.round((t.pageHeight - u.top - u.bottom) * s)
642
- ), f = d.toDataURL("image/png");
636
+ Math.round(f.left * s),
637
+ Math.round(f.top * s),
638
+ Math.round((t.pageWidth - f.left - f.right) * s),
639
+ Math.round((t.pageHeight - f.top - f.bottom) * s)
640
+ ), u = d.toDataURL("image/png");
643
641
  }
644
642
  }
645
643
  for (let d = 1; d <= i; d++) {
646
644
  e.setPage(d);
647
- for (const g of S) {
648
- const u = n[g];
649
- if (!u) continue;
650
- const m = T(g, t);
651
- let b, p;
652
- typeof u == "function" ? b = (await j(
653
- u(d, i),
645
+ for (const g of B) {
646
+ const f = n[g];
647
+ if (!f) continue;
648
+ const m = j(g, t);
649
+ let y, p;
650
+ typeof f == "function" ? y = (await k(
651
+ f(d, i),
654
652
  m.width,
655
653
  m.height,
656
654
  o
657
- )).toDataURL("image/png") : (b = c[g], p = `margin-${g}`), e.addImage(
658
- b,
655
+ )).toDataURL("image/png") : (y = c[g], p = `margin-${g}`), e.addImage(
656
+ y,
659
657
  "PNG",
660
658
  m.x,
661
659
  m.y,
@@ -666,16 +664,16 @@ async function $(e, n, a = {}) {
666
664
  );
667
665
  }
668
666
  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(
667
+ const { color: g = "#000000", width: f = 0.3 } = n.contentBorder, m = A(n.contentBorder, t);
668
+ e.setDrawColor(g), e.setLineWidth(f), e.rect(
671
669
  m.left,
672
670
  m.top,
673
671
  t.pageWidth - m.left - m.right,
674
672
  t.pageHeight - m.top - m.bottom
675
673
  );
676
674
  }
677
- f && e.addImage(
678
- f,
675
+ u && e.addImage(
676
+ u,
679
677
  "PNG",
680
678
  0,
681
679
  0,
@@ -688,18 +686,18 @@ async function $(e, n, a = {}) {
688
686
  return e;
689
687
  }
690
688
  export {
691
- _ as PAGE_MARGINS,
692
- z as PAGE_SIZES,
689
+ J as PAGE_MARGINS,
690
+ _ as PAGE_SIZES,
693
691
  $ as addMarginContent,
694
692
  R as computeLayout,
695
- P as createPrintClone,
696
- L as insertPageBreakSpacers,
697
- F as normalizeTableAttributes,
698
- K as prepare,
699
- it as previewPageImages,
700
- nt as renderHTML,
701
- ot as renderImagePDF,
702
- tt as renderPageImages,
703
- I as splitOversizedTables,
693
+ N as createPrintClone,
694
+ T as insertPageBreakSpacers,
695
+ I as normalizeTableAttributes,
696
+ V as prepare,
697
+ at as previewPageImages,
698
+ ot as renderHTML,
699
+ it as renderImagePDF,
700
+ et as renderPageImages,
701
+ L as splitOversizedTables,
704
702
  O as splitOversizedText
705
703
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
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",