jspdf-utils 0.1.16 → 0.1.18

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 +194 -184
  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",
@@ -53,7 +53,19 @@ function P(e, n = 210) {
53
53
  pointerEvents: "none"
54
54
  }), document.body.appendChild(a), a;
55
55
  }
56
- function G(e) {
56
+ async function Q(e) {
57
+ const n = Array.from(e.querySelectorAll("img"));
58
+ await Promise.all(
59
+ n.map((a) => {
60
+ if (!(a.complete && a.naturalWidth > 0))
61
+ return new Promise((t) => {
62
+ a.onload = () => t(), a.onerror = () => t();
63
+ });
64
+ })
65
+ );
66
+ }
67
+ async function q(e) {
68
+ await Q(e);
57
69
  const n = e.getBoundingClientRect();
58
70
  let a = n.bottom;
59
71
  for (const i of e.querySelectorAll("*")) {
@@ -63,7 +75,7 @@ function G(e) {
63
75
  const t = a - n.top;
64
76
  t > e.offsetHeight && (e.style.minHeight = t + "px");
65
77
  }
66
- async function J(e) {
78
+ async function Z(e) {
67
79
  const n = Array.from(e.querySelectorAll("img"));
68
80
  if (n.length === 0) return;
69
81
  await Promise.all(
@@ -90,11 +102,11 @@ async function J(e) {
90
102
  }
91
103
  }
92
104
  }
93
- function N() {
105
+ function F() {
94
106
  const e = document.createElement("style");
95
107
  return e.setAttribute("data-jspdf-utils", ""), e.textContent = "img { display: inline !important; }", document.head.appendChild(e), () => e.remove();
96
108
  }
97
- function F(e) {
109
+ function I(e) {
98
110
  for (const n of e.querySelectorAll("table")) {
99
111
  const a = n.getAttribute("cellpadding");
100
112
  if (a) {
@@ -104,7 +116,7 @@ function F(e) {
104
116
  }
105
117
  }
106
118
  }
107
- function I(e, n) {
119
+ function L(e, n) {
108
120
  for (const a of Array.from(
109
121
  e.querySelectorAll(":scope > table")
110
122
  )) {
@@ -112,16 +124,16 @@ function I(e, n) {
112
124
  const t = Array.from(a.rows);
113
125
  if (t.length === 0) continue;
114
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 = [];
115
- let c = [], f = 0;
127
+ let c = [], u = 0;
116
128
  for (const d of s) {
117
129
  const g = d.offsetHeight;
118
- f + g > l && c.length > 0 && (h.push(c), c = [], f = 0), c.push(d), f += g;
130
+ u + g > l && c.length > 0 && (h.push(c), c = [], u = 0), c.push(d), u += g;
119
131
  }
120
132
  c.length > 0 && h.push(c);
121
133
  for (const d of h) {
122
134
  const g = a.cloneNode(!1);
123
135
  o && g.appendChild(o.cloneNode(!0));
124
- for (const u of d) g.appendChild(u.cloneNode(!0));
136
+ for (const f of d) g.appendChild(f.cloneNode(!0));
125
137
  a.parentNode.insertBefore(g, a);
126
138
  }
127
139
  a.remove();
@@ -141,21 +153,21 @@ function O(e, n) {
141
153
  const h = [];
142
154
  let c = 0;
143
155
  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;
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;
148
160
  }
149
161
  const g = document.createElement(i);
150
- g.setAttribute("style", o), g.textContent = r.slice(c, f).join(" "), h.push(g), c = f;
162
+ g.setAttribute("style", o), g.textContent = r.slice(c, u).join(" "), h.push(g), c = u;
151
163
  }
152
164
  l.remove();
153
- for (const f of h)
154
- t.parentNode.insertBefore(f, t);
165
+ for (const u of h)
166
+ t.parentNode.insertBefore(u, t);
155
167
  t.remove();
156
168
  }
157
169
  }
158
- function Q(e, n, a) {
170
+ function K(e, n, a) {
159
171
  const t = Array.from(e.rows);
160
172
  if (t.length === 0) return !1;
161
173
  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 +180,17 @@ function Q(e, n, a) {
168
180
  c += g.offsetHeight, h++;
169
181
  }
170
182
  if (h === 0 || h === s.length) return !1;
171
- const f = e.cloneNode(!1);
172
- o && f.appendChild(o.cloneNode(!0));
183
+ const u = e.cloneNode(!1);
184
+ o && u.appendChild(o.cloneNode(!0));
173
185
  for (let g = 0; g < h; g++)
174
- f.appendChild(s[g].cloneNode(!0));
186
+ u.appendChild(s[g].cloneNode(!0));
175
187
  const d = e.cloneNode(!1);
176
188
  o && d.appendChild(o.cloneNode(!0));
177
189
  for (let g = h; g < s.length; g++)
178
190
  d.appendChild(s[g].cloneNode(!0));
179
- return n.insertBefore(f, e), n.insertBefore(d, e), e.remove(), !0;
191
+ return n.insertBefore(u, e), n.insertBefore(d, e), e.remove(), !0;
180
192
  }
181
- function Z(e, n, a) {
193
+ function V(e, n, a) {
182
194
  if (e.tagName === "TABLE" || e.tagName === "IMG") return !1;
183
195
  const t = (e.textContent || "").split(/\s+/).filter(Boolean);
184
196
  if (t.length < 2) return !1;
@@ -197,23 +209,23 @@ function Z(e, n, a) {
197
209
  if (r.remove(), l >= t.length) return !1;
198
210
  const c = document.createElement(i);
199
211
  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;
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;
202
214
  }
203
- function L(e, n) {
215
+ function T(e, n) {
204
216
  let a = 0;
205
217
  for (; a < e.children.length; ) {
206
218
  const t = e.children[a], i = t.offsetTop, o = i + t.offsetHeight, s = (Math.floor(i / n) + 1) * n;
207
219
  if (o > s) {
208
220
  const r = s - i;
209
221
  if (t.tagName === "TABLE") {
210
- if (Q(
222
+ if (K(
211
223
  t,
212
224
  e,
213
225
  r
214
226
  ))
215
227
  continue;
216
- } else if (Z(t, e, r))
228
+ } else if (V(t, e, r))
217
229
  continue;
218
230
  if (t.offsetHeight <= n) {
219
231
  const l = document.createElement("div");
@@ -223,11 +235,11 @@ function L(e, n) {
223
235
  a++;
224
236
  }
225
237
  }
226
- function K(e, n = {}) {
227
- const a = W(n), t = N(), i = P(e, a.pageWidth);
228
- F(i);
238
+ function Y(e, n = {}) {
239
+ const a = S(n), t = F(), i = N(e, a.pageWidth);
240
+ I(i);
229
241
  const o = R(i, a);
230
- return I(i, o.pageContentPx), O(i, o.pageContentPx), L(i, o.pageContentPx), {
242
+ return L(i, o.pageContentPx), O(i, o.pageContentPx), T(i, o.pageContentPx), {
231
243
  clone: i,
232
244
  layout: o,
233
245
  options: a,
@@ -236,10 +248,10 @@ function K(e, n = {}) {
236
248
  }
237
249
  };
238
250
  }
239
- async function nt(e, n, a = {}) {
240
- const { clone: t, layout: i, options: o, cleanup: s } = K(n, a);
251
+ async function it(e, n, a = {}) {
252
+ const { clone: t, layout: i, options: o, cleanup: s } = Y(n, a);
241
253
  try {
242
- await J(t), await new Promise((r) => {
254
+ await Z(t), await new Promise((r) => {
243
255
  e.html(t, {
244
256
  callback: () => r(),
245
257
  width: i.contentWidthMm,
@@ -257,7 +269,7 @@ async function nt(e, n, a = {}) {
257
269
  }
258
270
  return a.marginContent && await $(e, a.marginContent, a), e;
259
271
  }
260
- function T(e, n) {
272
+ function j(e, n) {
261
273
  switch (e) {
262
274
  case "top":
263
275
  return { x: 0, y: 0, width: n.pageWidth, height: n.margin.top };
@@ -279,7 +291,7 @@ function T(e, n) {
279
291
  };
280
292
  }
281
293
  }
282
- async function j(e, n, a, t) {
294
+ async function k(e, n, a, t) {
283
295
  const i = document.createElement("div");
284
296
  Object.assign(i.style, {
285
297
  position: "fixed",
@@ -290,7 +302,7 @@ async function j(e, n, a, t) {
290
302
  overflow: "hidden"
291
303
  }), i.appendChild(e), document.body.appendChild(i);
292
304
  try {
293
- return await A(i, {
305
+ return await P(i, {
294
306
  scale: t,
295
307
  backgroundColor: null
296
308
  });
@@ -298,14 +310,14 @@ async function j(e, n, a, t) {
298
310
  i.remove();
299
311
  }
300
312
  }
301
- const S = ["top", "right", "bottom", "left"];
302
- async function q(e, n, a) {
313
+ const A = ["top", "right", "bottom", "left"];
314
+ async function G(e, n, a) {
303
315
  const t = {};
304
- for (const i of S) {
316
+ for (const i of A) {
305
317
  const o = e[i];
306
318
  if (o && typeof o != "function") {
307
- const s = T(i, n);
308
- t[i] = await j(
319
+ const s = j(i, n);
320
+ t[i] = await k(
309
321
  o.cloneNode(!0),
310
322
  s.width,
311
323
  s.height,
@@ -315,7 +327,7 @@ async function q(e, n, a) {
315
327
  }
316
328
  return t;
317
329
  }
318
- function V(e, n) {
330
+ function X(e, n) {
319
331
  return e == null ? n.margin : typeof e == "number" ? { top: e, right: e, bottom: e, left: e } : {
320
332
  top: e.top ?? n.margin.top,
321
333
  right: e.right ?? n.margin.right,
@@ -323,7 +335,7 @@ function V(e, n) {
323
335
  left: e.left ?? n.margin.left
324
336
  };
325
337
  }
326
- const Y = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
338
+ const tt = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
327
339
  async function D(e, n, a, t, i, o, s, r, l = !1) {
328
340
  const h = document.createElement("div");
329
341
  Object.assign(h.style, {
@@ -352,17 +364,17 @@ async function D(e, n, a, t, i, o, s, r, l = !1) {
352
364
  fontFamily: i,
353
365
  fontWeight: o
354
366
  }), document.body.appendChild(c);
355
- const f = c.offsetWidth;
367
+ const u = c.offsetWidth;
356
368
  c.remove();
357
- const d = Math.ceil(n / (f + r)) + 2;
369
+ const d = Math.ceil(n / (u + r)) + 2;
358
370
  for (let g = 0; g < d; g++) {
359
- const u = document.createElement("span");
360
- u.textContent = e, u.style.flexShrink = "0", h.appendChild(u);
371
+ const f = document.createElement("span");
372
+ f.textContent = e, f.style.flexShrink = "0", h.appendChild(f);
361
373
  }
362
374
  document.body.appendChild(h);
363
375
  try {
364
- return await A(h, {
365
- scale: 1,
376
+ return await P(h, {
377
+ scale: 3,
366
378
  backgroundColor: null,
367
379
  width: Math.ceil(n),
368
380
  height: Math.ceil(a)
@@ -377,93 +389,93 @@ async function U(e, n, a, t, i, o, s) {
377
389
  color: l = "#000000",
378
390
  fontSize: h = 2.5,
379
391
  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([
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([
382
394
  D(
383
395
  r,
384
396
  p,
385
397
  m,
386
398
  d,
387
399
  c,
388
- f,
400
+ u,
389
401
  l,
390
402
  g,
391
- b
403
+ y
392
404
  ),
393
405
  D(
394
406
  r,
395
- y,
407
+ C,
396
408
  m,
397
409
  d,
398
410
  c,
399
- f,
411
+ u,
400
412
  l,
401
413
  g,
402
- b
414
+ y
403
415
  )
404
- ]), w = Math.round(m / 2);
416
+ ]), x = Math.round(m / 2);
405
417
  e.drawImage(
406
- C,
418
+ w,
407
419
  0,
408
420
  0,
409
- p,
410
- m,
411
- t + u,
412
- i - w,
421
+ w.width,
422
+ w.height,
423
+ t + f,
424
+ i - x,
413
425
  p,
414
426
  m
415
427
  ), e.drawImage(
416
- C,
428
+ w,
417
429
  0,
418
430
  0,
419
- p,
420
- m,
421
- t + u,
422
- i + s - w,
431
+ w.width,
432
+ w.height,
433
+ t + f,
434
+ i + s - x,
423
435
  p,
424
436
  m
425
- ), e.save(), e.translate(t, i + s - u), e.rotate(-Math.PI / 2), e.drawImage(
426
- v,
437
+ ), e.save(), e.translate(t, i + s - f), e.rotate(-Math.PI / 2), e.drawImage(
438
+ b,
427
439
  0,
428
440
  0,
429
- y,
430
- m,
441
+ b.width,
442
+ b.height,
431
443
  0,
432
- -w,
433
- y,
444
+ -x,
445
+ C,
434
446
  m
435
- ), e.restore(), e.save(), e.translate(t + o, i + u), e.rotate(Math.PI / 2), e.drawImage(
436
- v,
447
+ ), e.restore(), e.save(), e.translate(t + o, i + f), e.rotate(Math.PI / 2), e.drawImage(
448
+ b,
437
449
  0,
438
450
  0,
439
- y,
440
- m,
451
+ b.width,
452
+ b.height,
441
453
  0,
442
- -w,
443
- y,
454
+ -x,
455
+ C,
444
456
  m
445
457
  ), e.restore();
446
458
  }
447
459
  function B(e, n) {
448
- return V(e.margin, n);
460
+ return X(e.margin, n);
449
461
  }
450
- async function X(e, n, a, t, i, o, s, r) {
451
- for (const l of S) {
462
+ async function et(e, n, a, t, i, o, s, r) {
463
+ for (const l of A) {
452
464
  const h = n[l];
453
465
  if (!h) continue;
454
- const c = T(l, t);
455
- let f;
456
- typeof h == "function" ? f = await j(
466
+ const c = j(l, t);
467
+ let u;
468
+ typeof h == "function" ? u = await k(
457
469
  h(o, s),
458
470
  c.width,
459
471
  c.height,
460
472
  r
461
- ) : f = a[l], e.drawImage(
462
- f,
473
+ ) : u = a[l], e.drawImage(
474
+ u,
463
475
  0,
464
476
  0,
465
- f.width,
466
- f.height,
477
+ u.width,
478
+ u.height,
467
479
  Math.round(c.x * i),
468
480
  Math.round(c.y * i),
469
481
  Math.round(c.width * i),
@@ -492,52 +504,50 @@ async function X(e, n, a, t, i, o, s, r) {
492
504
  );
493
505
  }
494
506
  }
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);
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);
509
+ r.style.opacity = "1", r.style.left = "-99999px", I(r);
498
510
  const l = R(r, o);
499
- I(r, l.pageContentPx), O(r, l.pageContentPx), L(r, l.pageContentPx), G(r);
511
+ L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
500
512
  try {
501
- const h = await A(r, {
513
+ const h = await P(r, {
502
514
  scale: i,
503
515
  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,
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,
506
518
  unit: "mm",
507
519
  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(
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);
521
+ for (let H = 0; H < m; H++) {
522
+ const M = Math.min(
523
+ f,
524
+ h.height - H * f
525
+ ), W = document.createElement("canvas");
526
+ W.width = w, W.height = b;
527
+ const v = W.getContext("2d");
528
+ if (!v) throw new Error("Could not get canvas context");
529
+ v.fillStyle = "#ffffff", v.fillRect(0, 0, w, b), v.drawImage(
518
530
  h,
519
531
  0,
520
- y * u,
532
+ H * f,
521
533
  g,
522
- C,
523
- 0,
524
- 0,
534
+ M,
535
+ E,
536
+ x,
525
537
  g,
526
- C
538
+ M
527
539
  );
528
- const E = v.toDataURL(
540
+ const z = W.toDataURL(
529
541
  `image/${a.toLowerCase()}`,
530
542
  t
531
543
  );
532
- y > 0 && p.addPage([o.pageWidth, o.pageHeight], b);
533
- const H = C / g * f;
534
- p.addImage(
535
- E,
544
+ H > 0 && p.addPage([o.pageWidth, o.pageHeight], y), p.addImage(
545
+ z,
536
546
  a,
537
- o.margin.left,
538
- o.margin.top,
539
- f,
540
- H,
547
+ 0,
548
+ 0,
549
+ o.pageWidth,
550
+ o.pageHeight,
541
551
  void 0,
542
552
  "SLOW"
543
553
  );
@@ -547,57 +557,57 @@ async function ot(e, n = {}) {
547
557
  r.remove(), s();
548
558
  }
549
559
  }
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);
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);
562
+ r.style.opacity = "1", r.style.left = "-99999px", I(r);
553
563
  const l = R(r, o);
554
- I(r, l.pageContentPx), O(r, l.pageContentPx), L(r, l.pageContentPx), G(r);
564
+ L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
555
565
  try {
556
- const h = await A(r, {
566
+ const h = await P(r, {
557
567
  scale: i,
558
568
  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(
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++) {
571
+ const M = Math.min(
562
572
  g,
563
573
  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(
574
+ ), W = document.createElement("canvas");
575
+ W.width = m, W.height = y;
576
+ const v = W.getContext("2d");
577
+ if (!v) throw new Error("Could not get canvas context");
578
+ v.fillStyle = "#ffffff", v.fillRect(0, 0, m, y), v.drawImage(
569
579
  h,
570
580
  0,
571
581
  H * g,
572
582
  d,
573
- k,
574
- y,
583
+ M,
584
+ C,
575
585
  p,
576
586
  d,
577
- k
578
- ), w && await X(
587
+ M
588
+ ), x && await et(
589
+ v,
579
590
  x,
580
- w,
581
591
  E,
582
592
  o,
583
- u,
593
+ f,
584
594
  H + 1,
585
- C,
595
+ w,
586
596
  i
587
- ), v.push(
588
- M.toDataURL(
597
+ ), b.push(
598
+ W.toDataURL(
589
599
  `image/${a.toLowerCase()}`,
590
600
  t
591
601
  )
592
602
  );
593
603
  }
594
- return v;
604
+ return b;
595
605
  } finally {
596
606
  r.remove(), s();
597
607
  }
598
608
  }
599
- async function it(e, n, a = {}) {
600
- const t = W(a), i = await tt(e, a);
609
+ async function rt(e, n, a = {}) {
610
+ const t = S(a), i = await nt(e, a);
601
611
  n.innerHTML = "", Object.assign(n.style, {
602
612
  direction: "ltr",
603
613
  width: "fit-content",
@@ -621,41 +631,41 @@ async function it(e, n, a = {}) {
621
631
  }
622
632
  }
623
633
  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)
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)
626
636
  h[d] && (c[d] = h[d].toDataURL("image/png"));
627
- let f;
637
+ let u;
628
638
  if (n.textBorder) {
629
639
  const d = document.createElement("canvas");
630
640
  d.width = r, d.height = l;
631
641
  const g = d.getContext("2d");
632
642
  if (g) {
633
- const u = B(n.textBorder, t);
643
+ const f = B(n.textBorder, t);
634
644
  await U(
635
645
  g,
636
646
  n.textBorder,
637
647
  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");
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");
643
653
  }
644
654
  }
645
655
  for (let d = 1; d <= i; d++) {
646
656
  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),
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),
654
664
  m.width,
655
665
  m.height,
656
666
  o
657
- )).toDataURL("image/png") : (b = c[g], p = `margin-${g}`), e.addImage(
658
- b,
667
+ )).toDataURL("image/png") : (y = c[g], p = `margin-${g}`), e.addImage(
668
+ y,
659
669
  "PNG",
660
670
  m.x,
661
671
  m.y,
@@ -666,16 +676,16 @@ async function $(e, n, a = {}) {
666
676
  );
667
677
  }
668
678
  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(
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(
671
681
  m.left,
672
682
  m.top,
673
683
  t.pageWidth - m.left - m.right,
674
684
  t.pageHeight - m.top - m.bottom
675
685
  );
676
686
  }
677
- f && e.addImage(
678
- f,
687
+ u && e.addImage(
688
+ u,
679
689
  "PNG",
680
690
  0,
681
691
  0,
@@ -688,18 +698,18 @@ async function $(e, n, a = {}) {
688
698
  return e;
689
699
  }
690
700
  export {
691
- _ as PAGE_MARGINS,
692
- z as PAGE_SIZES,
701
+ J as PAGE_MARGINS,
702
+ _ as PAGE_SIZES,
693
703
  $ as addMarginContent,
694
704
  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,
705
+ N as createPrintClone,
706
+ T as insertPageBreakSpacers,
707
+ I as normalizeTableAttributes,
708
+ Y as prepare,
709
+ rt as previewPageImages,
710
+ it as renderHTML,
711
+ at as renderImagePDF,
712
+ nt as renderPageImages,
713
+ L as splitOversizedTables,
704
714
  O as splitOversizedText
705
715
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
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",