jspdf-utils 0.1.18 → 0.1.21

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 +198 -199
  2. package/package.json +1 -1
@@ -37,11 +37,11 @@ function S(e = {}) {
37
37
  margin: { ...r, ...e.margin }
38
38
  };
39
39
  }
40
- function R(e, n) {
40
+ function N(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 N(e, n = 210) {
44
+ function F(e, n = 210) {
45
45
  const a = e.cloneNode(!0);
46
46
  return Object.assign(a.style, {
47
47
  position: "fixed",
@@ -68,7 +68,7 @@ async function q(e) {
68
68
  await Q(e);
69
69
  const n = e.getBoundingClientRect();
70
70
  let a = n.bottom;
71
- for (const i of e.querySelectorAll("*")) {
71
+ for (const i of Array.from(e.querySelectorAll("*"))) {
72
72
  const o = i.getBoundingClientRect().bottom;
73
73
  o > a && (a = o);
74
74
  }
@@ -94,23 +94,23 @@ async function Z(e) {
94
94
  continue;
95
95
  const l = document.createElement("canvas");
96
96
  l.width = s, l.height = r;
97
- const h = l.getContext("2d");
98
- if (h)
97
+ const g = l.getContext("2d");
98
+ if (g)
99
99
  try {
100
- h.drawImage(t, 0, 0, s, r), t.style.width = i + "px", t.style.height = o + "px", t.src = l.toDataURL("image/png");
100
+ g.drawImage(t, 0, 0, s, r), t.style.width = i + "px", t.style.height = o + "px", t.src = l.toDataURL("image/png");
101
101
  } catch {
102
102
  }
103
103
  }
104
104
  }
105
- function F() {
105
+ function E() {
106
106
  const e = document.createElement("style");
107
107
  return e.setAttribute("data-jspdf-utils", ""), e.textContent = "img { display: inline !important; }", document.head.appendChild(e), () => e.remove();
108
108
  }
109
109
  function I(e) {
110
- for (const n of e.querySelectorAll("table")) {
110
+ for (const n of Array.from(e.querySelectorAll("table"))) {
111
111
  const a = n.getAttribute("cellpadding");
112
112
  if (a) {
113
- for (const t of n.querySelectorAll("th, td"))
113
+ for (const t of Array.from(n.querySelectorAll("th, td")))
114
114
  t.style.padding || (t.style.padding = a + "px");
115
115
  n.removeAttribute("cellpadding");
116
116
  }
@@ -123,18 +123,18 @@ function L(e, n) {
123
123
  if (a.offsetHeight <= n) continue;
124
124
  const t = Array.from(a.rows);
125
125
  if (t.length === 0) continue;
126
- 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 = [];
127
- let c = [], u = 0;
128
- for (const d of s) {
129
- const g = d.offsetHeight;
130
- u + g > l && c.length > 0 && (h.push(c), c = [], u = 0), c.push(d), u += g;
126
+ 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, g = [];
127
+ let h = [], d = 0;
128
+ for (const u of s) {
129
+ const c = u.offsetHeight;
130
+ d + c > l && h.length > 0 && (g.push(h), h = [], d = 0), h.push(u), d += c;
131
131
  }
132
- c.length > 0 && h.push(c);
133
- for (const d of h) {
134
- const g = a.cloneNode(!1);
135
- o && g.appendChild(o.cloneNode(!0));
136
- for (const f of d) g.appendChild(f.cloneNode(!0));
137
- a.parentNode.insertBefore(g, a);
132
+ h.length > 0 && g.push(h);
133
+ for (const u of g) {
134
+ const c = a.cloneNode(!1);
135
+ o && c.appendChild(o.cloneNode(!0));
136
+ for (const f of u) c.appendChild(f.cloneNode(!0));
137
+ a.parentNode.insertBefore(c, a);
138
138
  }
139
139
  a.remove();
140
140
  }
@@ -150,20 +150,20 @@ function O(e, n) {
150
150
  visibility: "hidden",
151
151
  width: s
152
152
  }), e.appendChild(l);
153
- const h = [];
154
- let c = 0;
155
- for (; c < r.length; ) {
156
- let u = c + 1, d = r.length;
157
- for (; u < d; ) {
158
- const f = Math.ceil((u + d) / 2);
159
- l.textContent = r.slice(c, f).join(" "), l.offsetHeight <= n ? u = f : d = f - 1;
153
+ const g = [];
154
+ let h = 0;
155
+ for (; h < r.length; ) {
156
+ let d = h + 1, u = r.length;
157
+ for (; d < u; ) {
158
+ const f = Math.ceil((d + u) / 2);
159
+ l.textContent = r.slice(h, f).join(" "), l.offsetHeight <= n ? d = f : u = f - 1;
160
160
  }
161
- const g = document.createElement(i);
162
- g.setAttribute("style", o), g.textContent = r.slice(c, u).join(" "), h.push(g), c = u;
161
+ const c = document.createElement(i);
162
+ c.setAttribute("style", o), c.textContent = r.slice(h, d).join(" "), g.push(c), h = d;
163
163
  }
164
164
  l.remove();
165
- for (const u of h)
166
- t.parentNode.insertBefore(u, t);
165
+ for (const d of g)
166
+ t.parentNode.insertBefore(d, t);
167
167
  t.remove();
168
168
  }
169
169
  }
@@ -174,21 +174,21 @@ function K(e, n, a) {
174
174
  if (s.length < 2) return !1;
175
175
  const l = a - r - 2;
176
176
  if (l <= 0) return !1;
177
- let h = 0, c = 0;
178
- for (const g of s) {
179
- if (c + g.offsetHeight > l) break;
180
- c += g.offsetHeight, h++;
177
+ let g = 0, h = 0;
178
+ for (const c of s) {
179
+ if (h + c.offsetHeight > l) break;
180
+ h += c.offsetHeight, g++;
181
181
  }
182
- if (h === 0 || h === s.length) return !1;
183
- const u = e.cloneNode(!1);
184
- o && u.appendChild(o.cloneNode(!0));
185
- for (let g = 0; g < h; g++)
186
- u.appendChild(s[g].cloneNode(!0));
182
+ if (g === 0 || g === s.length) return !1;
187
183
  const d = e.cloneNode(!1);
188
184
  o && d.appendChild(o.cloneNode(!0));
189
- for (let g = h; g < s.length; g++)
190
- d.appendChild(s[g].cloneNode(!0));
191
- return n.insertBefore(u, e), n.insertBefore(d, e), e.remove(), !0;
185
+ for (let c = 0; c < g; c++)
186
+ d.appendChild(s[c].cloneNode(!0));
187
+ const u = e.cloneNode(!1);
188
+ o && u.appendChild(o.cloneNode(!0));
189
+ for (let c = g; c < s.length; c++)
190
+ u.appendChild(s[c].cloneNode(!0));
191
+ return n.insertBefore(d, e), n.insertBefore(u, e), e.remove(), !0;
192
192
  }
193
193
  function V(e, n, a) {
194
194
  if (e.tagName === "TABLE" || e.tagName === "IMG") return !1;
@@ -201,16 +201,16 @@ function V(e, n, a) {
201
201
  width: s
202
202
  }), n.appendChild(r), r.textContent = t[0], r.offsetHeight > a)
203
203
  return r.remove(), !1;
204
- let l = 1, h = t.length;
205
- for (; l < h; ) {
206
- const d = Math.ceil((l + h) / 2);
207
- r.textContent = t.slice(0, d).join(" "), r.offsetHeight <= a ? l = d : h = d - 1;
204
+ let l = 1, g = t.length;
205
+ for (; l < g; ) {
206
+ const u = Math.ceil((l + g) / 2);
207
+ r.textContent = t.slice(0, u).join(" "), r.offsetHeight <= a ? l = u : g = u - 1;
208
208
  }
209
209
  if (r.remove(), l >= t.length) return !1;
210
- const c = document.createElement(i);
211
- c.setAttribute("style", o), c.textContent = t.slice(0, l).join(" ");
212
- const u = document.createElement(i);
213
- return u.setAttribute("style", o), u.textContent = t.slice(l).join(" "), n.insertBefore(c, e), n.insertBefore(u, e), e.remove(), !0;
210
+ const h = document.createElement(i);
211
+ h.setAttribute("style", o), h.textContent = t.slice(0, l).join(" ");
212
+ const d = document.createElement(i);
213
+ return d.setAttribute("style", o), d.textContent = t.slice(l).join(" "), n.insertBefore(h, e), n.insertBefore(d, e), e.remove(), !0;
214
214
  }
215
215
  function T(e, n) {
216
216
  let a = 0;
@@ -236,9 +236,9 @@ function T(e, n) {
236
236
  }
237
237
  }
238
238
  function Y(e, n = {}) {
239
- const a = S(n), t = F(), i = N(e, a.pageWidth);
239
+ const a = S(n), t = E(), i = F(e, a.pageWidth);
240
240
  I(i);
241
- const o = R(i, a);
241
+ const o = N(i, a);
242
242
  return L(i, o.pageContentPx), O(i, o.pageContentPx), T(i, o.pageContentPx), {
243
243
  clone: i,
244
244
  layout: o,
@@ -291,7 +291,7 @@ function j(e, n) {
291
291
  };
292
292
  }
293
293
  }
294
- async function k(e, n, a, t) {
294
+ async function D(e, n, a, t) {
295
295
  const i = document.createElement("div");
296
296
  Object.assign(i.style, {
297
297
  position: "fixed",
@@ -317,7 +317,7 @@ async function G(e, n, a) {
317
317
  const o = e[i];
318
318
  if (o && typeof o != "function") {
319
319
  const s = j(i, n);
320
- t[i] = await k(
320
+ t[i] = await D(
321
321
  o.cloneNode(!0),
322
322
  s.width,
323
323
  s.height,
@@ -336,9 +336,9 @@ function X(e, n) {
336
336
  };
337
337
  }
338
338
  const tt = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
339
- async function D(e, n, a, t, i, o, s, r, l = !1) {
340
- const h = document.createElement("div");
341
- Object.assign(h.style, {
339
+ async function k(e, n, a, t, i, o, s, r, l = !1) {
340
+ const g = document.createElement("div");
341
+ Object.assign(g.style, {
342
342
  position: "fixed",
343
343
  left: "-99999px",
344
344
  top: "0",
@@ -355,104 +355,104 @@ async function D(e, n, a, t, i, o, s, r, l = !1) {
355
355
  gap: `${r}px`,
356
356
  direction: l ? "rtl" : "ltr"
357
357
  });
358
- const c = document.createElement("span");
359
- c.textContent = e, Object.assign(c.style, {
358
+ const h = document.createElement("span");
359
+ h.textContent = e, Object.assign(h.style, {
360
360
  position: "absolute",
361
361
  visibility: "hidden",
362
362
  whiteSpace: "nowrap",
363
363
  fontSize: `${t}px`,
364
364
  fontFamily: i,
365
365
  fontWeight: o
366
- }), document.body.appendChild(c);
367
- const u = c.offsetWidth;
368
- c.remove();
369
- const d = Math.ceil(n / (u + r)) + 2;
370
- for (let g = 0; g < d; g++) {
366
+ }), document.body.appendChild(h);
367
+ const d = h.offsetWidth;
368
+ h.remove();
369
+ const u = Math.ceil(n / (d + r)) + 2;
370
+ for (let c = 0; c < u; c++) {
371
371
  const f = document.createElement("span");
372
- f.textContent = e, f.style.flexShrink = "0", h.appendChild(f);
372
+ f.textContent = e, f.style.flexShrink = "0", g.appendChild(f);
373
373
  }
374
- document.body.appendChild(h);
374
+ document.body.appendChild(g);
375
375
  try {
376
- return await P(h, {
376
+ return await P(g, {
377
377
  scale: 3,
378
378
  backgroundColor: null,
379
379
  width: Math.ceil(n),
380
380
  height: Math.ceil(a)
381
381
  });
382
382
  } finally {
383
- h.remove();
383
+ g.remove();
384
384
  }
385
385
  }
386
386
  async function U(e, n, a, t, i, o, s) {
387
387
  const {
388
388
  text: r,
389
389
  color: l = "#000000",
390
- fontSize: h = 2.5,
391
- fontFamily: c = "Arial, sans-serif",
392
- fontWeight: u = "normal"
393
- } = n, d = h * a, g = (n.gap ?? h * 0.5) * a, f = d * 0.5, m = Math.ceil(d * 2), y = tt.test(r), p = Math.round(o - f * 2), C = Math.round(s - f * 2), [w, b] = await Promise.all([
394
- D(
390
+ fontSize: g = 2.5,
391
+ fontFamily: h = "Arial, sans-serif",
392
+ fontWeight: d = "normal"
393
+ } = n, u = g * a, c = (n.gap ?? g * 0.5) * a, f = u * 0.5, m = Math.ceil(u * 2.5), p = tt.test(r), y = Math.round(o - f * 2), w = Math.round(s - f * 2), [b, C] = await Promise.all([
394
+ k(
395
395
  r,
396
- p,
396
+ y,
397
397
  m,
398
- d,
399
- c,
400
398
  u,
399
+ h,
400
+ d,
401
401
  l,
402
- g,
403
- y
402
+ c,
403
+ p
404
404
  ),
405
- D(
405
+ k(
406
406
  r,
407
- C,
407
+ w,
408
408
  m,
409
- d,
410
- c,
411
409
  u,
410
+ h,
411
+ d,
412
412
  l,
413
- g,
414
- y
413
+ c,
414
+ p
415
415
  )
416
416
  ]), x = Math.round(m / 2);
417
417
  e.drawImage(
418
- w,
418
+ b,
419
419
  0,
420
420
  0,
421
- w.width,
422
- w.height,
421
+ b.width,
422
+ b.height,
423
423
  t + f,
424
424
  i - x,
425
- p,
425
+ y,
426
426
  m
427
427
  ), e.drawImage(
428
- w,
428
+ b,
429
429
  0,
430
430
  0,
431
- w.width,
432
- w.height,
431
+ b.width,
432
+ b.height,
433
433
  t + f,
434
434
  i + s - x,
435
- p,
435
+ y,
436
436
  m
437
437
  ), e.save(), e.translate(t, i + s - f), e.rotate(-Math.PI / 2), e.drawImage(
438
- b,
438
+ C,
439
439
  0,
440
440
  0,
441
- b.width,
442
- b.height,
441
+ C.width,
442
+ C.height,
443
443
  0,
444
444
  -x,
445
- C,
445
+ w,
446
446
  m
447
447
  ), e.restore(), e.save(), e.translate(t + o, i + f), e.rotate(Math.PI / 2), e.drawImage(
448
- b,
448
+ C,
449
449
  0,
450
450
  0,
451
- b.width,
452
- b.height,
451
+ C.width,
452
+ C.height,
453
453
  0,
454
454
  -x,
455
- C,
455
+ w,
456
456
  m
457
457
  ), e.restore();
458
458
  }
@@ -461,34 +461,34 @@ function B(e, n) {
461
461
  }
462
462
  async function et(e, n, a, t, i, o, s, r) {
463
463
  for (const l of A) {
464
- const h = n[l];
465
- if (!h) continue;
466
- const c = j(l, t);
467
- let u;
468
- typeof h == "function" ? u = await k(
469
- h(o, s),
470
- c.width,
471
- c.height,
464
+ const g = n[l];
465
+ if (!g) continue;
466
+ const h = j(l, t);
467
+ let d;
468
+ typeof g == "function" ? d = await D(
469
+ g(o, s),
470
+ h.width,
471
+ h.height,
472
472
  r
473
- ) : u = a[l], e.drawImage(
474
- u,
473
+ ) : d = a[l], e.drawImage(
474
+ d,
475
475
  0,
476
476
  0,
477
- u.width,
478
- u.height,
479
- Math.round(c.x * i),
480
- Math.round(c.y * i),
481
- Math.round(c.width * i),
482
- Math.round(c.height * i)
477
+ d.width,
478
+ d.height,
479
+ Math.round(h.x * i),
480
+ Math.round(h.y * i),
481
+ Math.round(h.width * i),
482
+ Math.round(h.height * i)
483
483
  );
484
484
  }
485
485
  if (n.contentBorder) {
486
- const { color: l = "#000000", width: h = 0.3 } = n.contentBorder, c = B(n.contentBorder, t);
487
- e.strokeStyle = l, e.lineWidth = h * i, e.strokeRect(
488
- Math.round(c.left * i),
489
- Math.round(c.top * i),
490
- Math.round((t.pageWidth - c.left - c.right) * i),
491
- Math.round((t.pageHeight - c.top - c.bottom) * i)
486
+ const { color: l = "#000000", width: g = 0.3 } = n.contentBorder, h = B(n.contentBorder, t);
487
+ e.strokeStyle = l, e.lineWidth = g * i, e.strokeRect(
488
+ Math.round(h.left * i),
489
+ Math.round(h.top * i),
490
+ Math.round((t.pageWidth - h.left - h.right) * i),
491
+ Math.round((t.pageHeight - h.top - h.bottom) * i)
492
492
  );
493
493
  }
494
494
  if (n.textBorder) {
@@ -505,43 +505,43 @@ async function et(e, n, a, t, i, o, s, r) {
505
505
  }
506
506
  }
507
507
  async function at(e, n = {}) {
508
- const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o = S(n), s = F(), r = N(e, o.pageWidth);
508
+ const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o = S(n), s = E(), r = F(e, o.pageWidth);
509
509
  r.style.opacity = "1", r.style.left = "-99999px", I(r);
510
- const l = R(r, o);
510
+ const l = N(r, o);
511
511
  L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
512
512
  try {
513
- const h = await P(r, {
513
+ const g = await P(r, {
514
514
  scale: i,
515
515
  backgroundColor: "#ffffff"
516
- }), { 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({
517
- orientation: y,
516
+ }), { jsPDF: h } = await import("jspdf"), d = o.pageWidth - o.margin.left - o.margin.right, u = o.pageHeight - o.margin.top - o.margin.bottom, c = g.width, f = u / d * c, m = Math.ceil(g.height / f), p = o.pageWidth > o.pageHeight ? "l" : "p", y = new h({
517
+ orientation: p,
518
518
  unit: "mm",
519
519
  format: [o.pageWidth, o.pageHeight]
520
- }), 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);
520
+ }), w = c / d, b = Math.round(o.pageWidth * w), C = Math.round(o.pageHeight * w), x = Math.round(o.margin.top * w), R = Math.round(o.margin.left * w);
521
521
  for (let H = 0; H < m; H++) {
522
522
  const M = Math.min(
523
523
  f,
524
- h.height - H * f
524
+ g.height - H * f
525
525
  ), W = document.createElement("canvas");
526
- W.width = w, W.height = b;
526
+ W.width = b, W.height = C;
527
527
  const v = W.getContext("2d");
528
528
  if (!v) throw new Error("Could not get canvas context");
529
- v.fillStyle = "#ffffff", v.fillRect(0, 0, w, b), v.drawImage(
530
- h,
529
+ v.fillStyle = "#ffffff", v.fillRect(0, 0, b, C), v.drawImage(
530
+ g,
531
531
  0,
532
532
  H * f,
533
- g,
533
+ c,
534
534
  M,
535
- E,
535
+ R,
536
536
  x,
537
- g,
537
+ c,
538
538
  M
539
539
  );
540
540
  const z = W.toDataURL(
541
541
  `image/${a.toLowerCase()}`,
542
542
  t
543
543
  );
544
- H > 0 && p.addPage([o.pageWidth, o.pageHeight], y), p.addImage(
544
+ H > 0 && y.addPage([o.pageWidth, o.pageHeight], p), y.addImage(
545
545
  z,
546
546
  a,
547
547
  0,
@@ -552,56 +552,56 @@ async function at(e, n = {}) {
552
552
  "SLOW"
553
553
  );
554
554
  }
555
- return n.marginContent && await $(p, n.marginContent, n), p;
555
+ return n.marginContent && await $(y, n.marginContent, n), y;
556
556
  } finally {
557
557
  r.remove(), s();
558
558
  }
559
559
  }
560
560
  async function nt(e, n = {}) {
561
- const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o = S(n), s = F(), r = N(e, o.pageWidth);
561
+ const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o = S(n), s = E(), r = F(e, o.pageWidth);
562
562
  r.style.opacity = "1", r.style.left = "-99999px", I(r);
563
- const l = R(r, o);
563
+ const l = N(r, o);
564
564
  L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
565
565
  try {
566
- const h = await P(r, {
566
+ const g = await P(r, {
567
567
  scale: i,
568
568
  backgroundColor: "#ffffff"
569
- }), 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 G(x, o, i) : {};
570
- for (let H = 0; H < w; H++) {
569
+ }), h = o.pageWidth - o.margin.left - o.margin.right, d = o.pageHeight - o.margin.top - o.margin.bottom, u = g.width, c = d / h * u, f = u / h, m = Math.round(o.pageWidth * f), p = Math.round(o.pageHeight * f), y = Math.round(o.margin.top * f), w = Math.round(o.margin.left * f), b = Math.ceil(g.height / c), C = [], { marginContent: x } = n, R = x ? await G(x, o, i) : {};
570
+ for (let H = 0; H < b; H++) {
571
571
  const M = Math.min(
572
- g,
573
- h.height - H * g
572
+ c,
573
+ g.height - H * c
574
574
  ), W = document.createElement("canvas");
575
- W.width = m, W.height = y;
575
+ W.width = m, W.height = p;
576
576
  const v = W.getContext("2d");
577
577
  if (!v) throw new Error("Could not get canvas context");
578
- v.fillStyle = "#ffffff", v.fillRect(0, 0, m, y), v.drawImage(
579
- h,
578
+ v.fillStyle = "#ffffff", v.fillRect(0, 0, m, p), v.drawImage(
579
+ g,
580
580
  0,
581
- H * g,
582
- d,
581
+ H * c,
582
+ u,
583
583
  M,
584
- C,
585
- p,
586
- d,
584
+ w,
585
+ y,
586
+ u,
587
587
  M
588
588
  ), x && await et(
589
589
  v,
590
590
  x,
591
- E,
591
+ R,
592
592
  o,
593
593
  f,
594
594
  H + 1,
595
- w,
595
+ b,
596
596
  i
597
- ), b.push(
597
+ ), C.push(
598
598
  W.toDataURL(
599
599
  `image/${a.toLowerCase()}`,
600
600
  t
601
601
  )
602
602
  );
603
603
  }
604
- return b;
604
+ return C;
605
605
  } finally {
606
606
  r.remove(), s();
607
607
  }
@@ -623,65 +623,64 @@ async function rt(e, n, a = {}) {
623
623
  maxWidth: "100%",
624
624
  height: "auto",
625
625
  boxSizing: "border-box",
626
- display: "block",
627
626
  border: "1px solid #bbb",
628
627
  boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
629
628
  marginBottom: "16px"
630
- }), n.appendChild(s);
629
+ }), s.style.setProperty("display", "inline", "important"), n.appendChild(s);
631
630
  }
632
631
  }
633
632
  async function $(e, n, a = {}) {
634
- 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 G(n, t, o), c = {};
635
- for (const d of A)
636
- h[d] && (c[d] = h[d].toDataURL("image/png"));
633
+ const t = S(a), i = e.getNumberOfPages(), o = 4, s = o * (96 / 25.4), r = E(), l = Math.round(t.pageWidth * s), g = Math.round(t.pageHeight * s), h = await G(n, t, o), d = {};
634
+ for (const c of A)
635
+ h[c] && (d[c] = h[c].toDataURL("image/png"));
637
636
  let u;
638
637
  if (n.textBorder) {
639
- const d = document.createElement("canvas");
640
- d.width = r, d.height = l;
641
- const g = d.getContext("2d");
642
- if (g) {
643
- const f = B(n.textBorder, t);
638
+ const c = document.createElement("canvas");
639
+ c.width = l, c.height = g;
640
+ const f = c.getContext("2d");
641
+ if (f) {
642
+ const m = B(n.textBorder, t);
644
643
  await U(
645
- g,
644
+ f,
646
645
  n.textBorder,
647
646
  s,
648
- Math.round(f.left * s),
649
- Math.round(f.top * s),
650
- Math.round((t.pageWidth - f.left - f.right) * s),
651
- Math.round((t.pageHeight - f.top - f.bottom) * s)
652
- ), u = d.toDataURL("image/png");
647
+ Math.round(m.left * s),
648
+ Math.round(m.top * s),
649
+ Math.round((t.pageWidth - m.left - m.right) * s),
650
+ Math.round((t.pageHeight - m.top - m.bottom) * s)
651
+ ), u = c.toDataURL("image/png");
653
652
  }
654
653
  }
655
- for (let d = 1; d <= i; d++) {
656
- e.setPage(d);
657
- for (const g of A) {
658
- const f = n[g];
659
- if (!f) continue;
660
- const m = j(g, t);
661
- let y, p;
662
- typeof f == "function" ? y = (await k(
663
- f(d, i),
664
- m.width,
665
- m.height,
654
+ for (let c = 1; c <= i; c++) {
655
+ e.setPage(c);
656
+ for (const f of A) {
657
+ const m = n[f];
658
+ if (!m) continue;
659
+ const p = j(f, t);
660
+ let y, w;
661
+ typeof m == "function" ? y = (await D(
662
+ m(c, i),
663
+ p.width,
664
+ p.height,
666
665
  o
667
- )).toDataURL("image/png") : (y = c[g], p = `margin-${g}`), e.addImage(
666
+ )).toDataURL("image/png") : (y = d[f], w = `margin-${f}`), e.addImage(
668
667
  y,
669
668
  "PNG",
670
- m.x,
671
- m.y,
672
- m.width,
673
- m.height,
674
- p,
669
+ p.x,
670
+ p.y,
671
+ p.width,
672
+ p.height,
673
+ w,
675
674
  "SLOW"
676
675
  );
677
676
  }
678
677
  if (n.contentBorder) {
679
- const { color: g = "#000000", width: f = 0.3 } = n.contentBorder, m = B(n.contentBorder, t);
680
- e.setDrawColor(g), e.setLineWidth(f), e.rect(
681
- m.left,
682
- m.top,
683
- t.pageWidth - m.left - m.right,
684
- t.pageHeight - m.top - m.bottom
678
+ const { color: f = "#000000", width: m = 0.3 } = n.contentBorder, p = B(n.contentBorder, t);
679
+ e.setDrawColor(f), e.setLineWidth(m), e.rect(
680
+ p.left,
681
+ p.top,
682
+ t.pageWidth - p.left - p.right,
683
+ t.pageHeight - p.top - p.bottom
685
684
  );
686
685
  }
687
686
  u && e.addImage(
@@ -695,14 +694,14 @@ async function $(e, n, a = {}) {
695
694
  "SLOW"
696
695
  );
697
696
  }
698
- return e;
697
+ return r(), e;
699
698
  }
700
699
  export {
701
700
  J as PAGE_MARGINS,
702
701
  _ as PAGE_SIZES,
703
702
  $ as addMarginContent,
704
- R as computeLayout,
705
- N as createPrintClone,
703
+ N as computeLayout,
704
+ F as createPrintClone,
706
705
  T as insertPageBreakSpacers,
707
706
  I as normalizeTableAttributes,
708
707
  Y as prepare,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.18",
3
+ "version": "0.1.21",
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",