jspdf-utils 0.1.13 → 0.1.14

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 +230 -161
  2. package/package.json +1 -1
@@ -10,7 +10,7 @@ const q = {
10
10
  letter: [215.9, 279.4],
11
11
  legal: [215.9, 355.6],
12
12
  tabloid: [279.4, 431.8]
13
- }, U = {
13
+ }, _ = {
14
14
  a0: 40,
15
15
  a1: 35,
16
16
  a2: 30,
@@ -23,7 +23,7 @@ const q = {
23
23
  tabloid: 25
24
24
  };
25
25
  function M(t = {}) {
26
- const e = t.format ?? "a4", [a, o] = q[e], i = t.pageWidth ?? a, n = t.pageHeight ?? o, l = U[e], r = {
26
+ const e = t.format ?? "a4", [a, o] = q[e], i = t.pageWidth ?? a, n = t.pageHeight ?? o, l = _[e], r = {
27
27
  top: l,
28
28
  right: l,
29
29
  bottom: l,
@@ -41,7 +41,7 @@ function E(t, e) {
41
41
  const a = t.offsetWidth, o = e.pageWidth - e.margin.left - e.margin.right, i = o / a, l = (e.pageHeight - e.margin.top - e.margin.bottom) / i;
42
42
  return { renderedWidth: a, scale: i, contentWidthMm: o, pageContentPx: l };
43
43
  }
44
- function P(t, e = 210) {
44
+ function B(t, e = 210) {
45
45
  const a = t.cloneNode(!0);
46
46
  return Object.assign(a.style, {
47
47
  position: "fixed",
@@ -53,11 +53,11 @@ function P(t, e = 210) {
53
53
  pointerEvents: "none"
54
54
  }), document.body.appendChild(a), a;
55
55
  }
56
- function B() {
56
+ 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 N(t) {
60
+ function P(t) {
61
61
  for (const e of t.querySelectorAll("table")) {
62
62
  const a = e.getAttribute("cellpadding");
63
63
  if (a) {
@@ -74,61 +74,61 @@ function R(t, e) {
74
74
  if (a.offsetHeight <= e) continue;
75
75
  const o = Array.from(a.rows);
76
76
  if (o.length === 0) continue;
77
- const i = o[0].querySelector("th") !== null, n = i ? o[0] : null, l = i ? o.slice(1) : o, r = n ? n.offsetHeight : 0, s = e - r - 2, g = [];
78
- let c = [], h = 0;
77
+ const i = o[0].querySelector("th") !== null, n = i ? o[0] : null, l = i ? o.slice(1) : o, r = n ? n.offsetHeight : 0, c = e - r - 2, g = [];
78
+ let s = [], h = 0;
79
79
  for (const f of l) {
80
80
  const d = f.offsetHeight;
81
- h + d > s && c.length > 0 && (g.push(c), c = [], h = 0), c.push(f), h += d;
81
+ h + d > c && s.length > 0 && (g.push(s), s = [], h = 0), s.push(f), h += d;
82
82
  }
83
- c.length > 0 && g.push(c);
83
+ s.length > 0 && g.push(s);
84
84
  for (const f of g) {
85
85
  const d = a.cloneNode(!1);
86
86
  n && d.appendChild(n.cloneNode(!0));
87
- for (const m of f) d.appendChild(m.cloneNode(!0));
87
+ for (const u of f) d.appendChild(u.cloneNode(!0));
88
88
  a.parentNode.insertBefore(d, a);
89
89
  }
90
90
  a.remove();
91
91
  }
92
92
  }
93
- function T(t, e) {
93
+ function F(t, e) {
94
94
  for (const a of Array.from(t.querySelectorAll(":scope > *"))) {
95
95
  const o = a;
96
96
  if (o.offsetHeight <= e || o.tagName === "TABLE")
97
97
  continue;
98
- const i = o.tagName, n = o.getAttribute("style") || "", l = getComputedStyle(o).width, r = (o.textContent || "").split(/\s+/).filter(Boolean), s = document.createElement(i);
99
- s.setAttribute("style", n), Object.assign(s.style, {
98
+ const i = o.tagName, n = o.getAttribute("style") || "", l = getComputedStyle(o).width, r = (o.textContent || "").split(/\s+/).filter(Boolean), c = document.createElement(i);
99
+ c.setAttribute("style", n), Object.assign(c.style, {
100
100
  position: "absolute",
101
101
  visibility: "hidden",
102
102
  width: l
103
- }), t.appendChild(s);
103
+ }), t.appendChild(c);
104
104
  const g = [];
105
- let c = 0;
106
- for (; c < r.length; ) {
107
- let h = c + 1, f = r.length;
105
+ let s = 0;
106
+ for (; s < r.length; ) {
107
+ let h = s + 1, f = r.length;
108
108
  for (; h < f; ) {
109
- const m = Math.ceil((h + f) / 2);
110
- s.textContent = r.slice(c, m).join(" "), s.offsetHeight <= e ? h = m : f = m - 1;
109
+ const u = Math.ceil((h + f) / 2);
110
+ c.textContent = r.slice(s, u).join(" "), c.offsetHeight <= e ? h = u : f = u - 1;
111
111
  }
112
112
  const d = document.createElement(i);
113
- d.setAttribute("style", n), d.textContent = r.slice(c, h).join(" "), g.push(d), c = h;
113
+ d.setAttribute("style", n), d.textContent = r.slice(s, h).join(" "), g.push(d), s = h;
114
114
  }
115
- s.remove();
115
+ c.remove();
116
116
  for (const h of g)
117
117
  o.parentNode.insertBefore(h, o);
118
118
  o.remove();
119
119
  }
120
120
  }
121
- function _(t, e, a) {
121
+ function U(t, e, a) {
122
122
  const o = Array.from(t.rows);
123
123
  if (o.length === 0) return !1;
124
124
  const i = o[0].querySelector("th") !== null, n = i ? o[0] : null, l = i ? o.slice(1) : o, r = n ? n.offsetHeight : 0;
125
125
  if (l.length < 2) return !1;
126
- const s = a - r - 2;
127
- if (s <= 0) return !1;
128
- let g = 0, c = 0;
126
+ const c = a - r - 2;
127
+ if (c <= 0) return !1;
128
+ let g = 0, s = 0;
129
129
  for (const d of l) {
130
- if (c + d.offsetHeight > s) break;
131
- c += d.offsetHeight, g++;
130
+ if (s + d.offsetHeight > c) break;
131
+ s += d.offsetHeight, g++;
132
132
  }
133
133
  if (g === 0 || g === l.length) return !1;
134
134
  const h = t.cloneNode(!1);
@@ -152,25 +152,25 @@ function J(t, e, a) {
152
152
  width: l
153
153
  }), e.appendChild(r), r.textContent = o[0], r.offsetHeight > a)
154
154
  return r.remove(), !1;
155
- let s = 1, g = o.length;
156
- for (; s < g; ) {
157
- const f = Math.ceil((s + g) / 2);
158
- r.textContent = o.slice(0, f).join(" "), r.offsetHeight <= a ? s = f : g = f - 1;
155
+ let c = 1, g = o.length;
156
+ for (; c < g; ) {
157
+ const f = Math.ceil((c + g) / 2);
158
+ r.textContent = o.slice(0, f).join(" "), r.offsetHeight <= a ? c = f : g = f - 1;
159
159
  }
160
- if (r.remove(), s >= o.length) return !1;
161
- const c = document.createElement(i);
162
- c.setAttribute("style", n), c.textContent = o.slice(0, s).join(" ");
160
+ if (r.remove(), c >= o.length) return !1;
161
+ const s = document.createElement(i);
162
+ s.setAttribute("style", n), s.textContent = o.slice(0, c).join(" ");
163
163
  const h = document.createElement(i);
164
- return h.setAttribute("style", n), h.textContent = o.slice(s).join(" "), e.insertBefore(c, t), e.insertBefore(h, t), t.remove(), !0;
164
+ return h.setAttribute("style", n), h.textContent = o.slice(c).join(" "), e.insertBefore(s, t), e.insertBefore(h, t), t.remove(), !0;
165
165
  }
166
- function I(t, e) {
166
+ function T(t, e) {
167
167
  let a = 0;
168
168
  for (; a < t.children.length; ) {
169
169
  const o = t.children[a], i = o.offsetTop, n = i + o.offsetHeight, l = (Math.floor(i / e) + 1) * e;
170
170
  if (n > l) {
171
171
  const r = l - i;
172
172
  if (o.tagName === "TABLE") {
173
- if (_(
173
+ if (U(
174
174
  o,
175
175
  t,
176
176
  r
@@ -179,18 +179,18 @@ function I(t, e) {
179
179
  } else if (J(o, t, r))
180
180
  continue;
181
181
  if (o.offsetHeight <= e) {
182
- const s = document.createElement("div");
183
- s.style.height = l - i + 1 + "px", o.parentNode.insertBefore(s, o), a++;
182
+ const c = document.createElement("div");
183
+ c.style.height = l - i + 1 + "px", o.parentNode.insertBefore(c, o), a++;
184
184
  }
185
185
  }
186
186
  a++;
187
187
  }
188
188
  }
189
189
  function Q(t, e = {}) {
190
- const a = M(e), o = B(), i = P(t, a.pageWidth);
191
- N(i);
190
+ const a = M(e), o = N(), i = B(t, a.pageWidth);
191
+ P(i);
192
192
  const n = E(i, a);
193
- return R(i, n.pageContentPx), T(i, n.pageContentPx), I(i, n.pageContentPx), {
193
+ return R(i, n.pageContentPx), F(i, n.pageContentPx), T(i, n.pageContentPx), {
194
194
  clone: i,
195
195
  layout: n,
196
196
  options: a,
@@ -199,7 +199,7 @@ function Q(t, e = {}) {
199
199
  }
200
200
  };
201
201
  }
202
- async function X(t, e, a = {}) {
202
+ async function tt(t, e, a = {}) {
203
203
  const { clone: o, layout: i, options: n, cleanup: l } = Q(e, a);
204
204
  try {
205
205
  await new Promise((r) => {
@@ -218,9 +218,9 @@ async function X(t, e, a = {}) {
218
218
  } finally {
219
219
  l();
220
220
  }
221
- return a.marginContent && await F(t, a.marginContent, a), t;
221
+ return a.marginContent && await $(t, a.marginContent, a), t;
222
222
  }
223
- function L(t, e) {
223
+ function k(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 L(t, e) {
242
242
  };
243
243
  }
244
244
  }
245
- async function G(t, e, a, o) {
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",
@@ -261,14 +261,14 @@ async function G(t, e, a, o) {
261
261
  i.remove();
262
262
  }
263
263
  }
264
- const z = ["top", "right", "bottom", "left"];
265
- async function D(t, e, a) {
264
+ const D = ["top", "right", "bottom", "left"];
265
+ async function G(t, e, a) {
266
266
  const o = {};
267
- for (const i of z) {
267
+ for (const i of D) {
268
268
  const n = t[i];
269
269
  if (n && typeof n != "function") {
270
- const l = L(i, e);
271
- o[i] = await G(
270
+ const l = k(i, e);
271
+ o[i] = await L(
272
272
  n.cloneNode(!0),
273
273
  l.width,
274
274
  l.height,
@@ -286,9 +286,10 @@ function Z(t, e) {
286
286
  left: t.left ?? e.margin.left
287
287
  };
288
288
  }
289
- async function j(t, e, a, o, i, n, l, r) {
290
- const s = document.createElement("div");
291
- Object.assign(s.style, {
289
+ const K = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
290
+ async function O(t, e, a, o, i, n, l, r, c = !1) {
291
+ const g = document.createElement("div");
292
+ Object.assign(g.style, {
292
293
  position: "fixed",
293
294
  left: "-99999px",
294
295
  top: "0",
@@ -302,132 +303,200 @@ async function j(t, e, a, o, i, n, l, r) {
302
303
  color: l,
303
304
  display: "flex",
304
305
  alignItems: "center",
305
- gap: `${r}px`
306
+ gap: `${r}px`,
307
+ direction: c ? "rtl" : "ltr"
306
308
  });
307
- const g = document.createElement("span");
308
- g.textContent = t, Object.assign(g.style, {
309
+ const s = document.createElement("span");
310
+ s.textContent = t, Object.assign(s.style, {
309
311
  position: "absolute",
310
312
  visibility: "hidden",
311
313
  whiteSpace: "nowrap",
312
314
  fontSize: `${o}px`,
313
315
  fontFamily: i,
314
316
  fontWeight: n
315
- }), document.body.appendChild(g);
316
- const c = g.offsetWidth;
317
- g.remove();
318
- const h = Math.ceil(e / (c + r)) + 2;
319
- for (let f = 0; f < h; f++) {
320
- const d = document.createElement("span");
321
- d.textContent = t, d.style.flexShrink = "0", s.appendChild(d);
317
+ }), document.body.appendChild(s);
318
+ const h = s.offsetWidth;
319
+ s.remove();
320
+ const f = Math.ceil(e / (h + r)) + 2;
321
+ for (let d = 0; d < f; d++) {
322
+ const u = document.createElement("span");
323
+ u.textContent = t, u.style.flexShrink = "0", g.appendChild(u);
322
324
  }
323
- document.body.appendChild(s);
325
+ document.body.appendChild(g);
324
326
  try {
325
- return await W(s, { scale: 1, backgroundColor: null });
327
+ return await W(g, {
328
+ scale: 1,
329
+ backgroundColor: null,
330
+ width: Math.ceil(e),
331
+ height: Math.ceil(a)
332
+ });
326
333
  } finally {
327
- s.remove();
334
+ g.remove();
328
335
  }
329
336
  }
330
- async function K(t, e, a, o, i, n, l) {
337
+ async function V(t, e, a, o, i, n, l) {
331
338
  const {
332
339
  text: r,
333
- color: s = "#000000",
340
+ color: c = "#000000",
334
341
  fontSize: g = 2.5,
335
- fontFamily: c = "Arial, sans-serif",
342
+ fontFamily: s = "Arial, sans-serif",
336
343
  fontWeight: h = "normal"
337
- } = e, f = g * a, d = (e.gap ?? g * 0.5) * a, m = f * 0.2, b = Math.ceil(f * 1.5), v = Math.round(n - m * 2), C = Math.round(l - m * 2), [y, p] = await Promise.all([
338
- j(r, v, b, f, c, h, s, d),
339
- j(r, C, b, f, c, h, s, d)
340
- ]), u = Math.round(b / 2);
341
- t.drawImage(y, o + m, i - u), t.drawImage(y, o + m, i + l - u), t.save(), t.translate(o, i + l - m), t.rotate(-Math.PI / 2), t.drawImage(p, 0, -u), t.restore(), t.save(), t.translate(o + n, i + m), t.rotate(Math.PI / 2), t.drawImage(p, 0, -u), t.restore();
344
+ } = e, f = g * a, d = (e.gap ?? g * 0.5) * a, u = f * 0.5, m = Math.ceil(f * 1.5), v = K.test(r);
345
+ console.log("isRtl", v);
346
+ const w = Math.round(n - u * 2), y = Math.round(l - u * 2), [b, C] = await Promise.all([
347
+ O(
348
+ r,
349
+ w,
350
+ m,
351
+ f,
352
+ s,
353
+ h,
354
+ c,
355
+ d,
356
+ v
357
+ ),
358
+ O(
359
+ r,
360
+ y,
361
+ m,
362
+ f,
363
+ s,
364
+ h,
365
+ c,
366
+ d,
367
+ v
368
+ )
369
+ ]), p = Math.round(m / 2);
370
+ t.drawImage(
371
+ b,
372
+ 0,
373
+ 0,
374
+ w,
375
+ m,
376
+ o + u,
377
+ i - p,
378
+ w,
379
+ m
380
+ ), t.drawImage(
381
+ b,
382
+ 0,
383
+ 0,
384
+ w,
385
+ m,
386
+ o + u,
387
+ i + l - p,
388
+ w,
389
+ m
390
+ ), t.save(), t.translate(o, i + l - u), t.rotate(-Math.PI / 2), t.drawImage(
391
+ C,
392
+ 0,
393
+ 0,
394
+ y,
395
+ m,
396
+ 0,
397
+ -p,
398
+ y,
399
+ m
400
+ ), t.restore(), t.save(), t.translate(o + n, i + u), t.rotate(Math.PI / 2), t.drawImage(
401
+ C,
402
+ 0,
403
+ 0,
404
+ y,
405
+ m,
406
+ 0,
407
+ -p,
408
+ y,
409
+ m
410
+ ), t.restore();
342
411
  }
343
- function k(t, e) {
412
+ function j(t, e) {
344
413
  return Z(t.margin, e);
345
414
  }
346
- async function $(t, e, a, o, i, n, l, r) {
347
- for (const s of z) {
348
- const g = e[s];
415
+ async function z(t, e, a, o, i, n, l, r) {
416
+ for (const c of D) {
417
+ const g = e[c];
349
418
  if (!g) continue;
350
- const c = L(s, o);
419
+ const s = k(c, o);
351
420
  let h;
352
- typeof g == "function" ? h = await G(
421
+ typeof g == "function" ? h = await L(
353
422
  g(n, l),
354
- c.width,
355
- c.height,
423
+ s.width,
424
+ s.height,
356
425
  r
357
- ) : h = a[s], t.drawImage(
426
+ ) : h = a[c], t.drawImage(
358
427
  h,
359
428
  0,
360
429
  0,
361
430
  h.width,
362
431
  h.height,
363
- Math.round(c.x * i),
364
- Math.round(c.y * i),
365
- Math.round(c.width * i),
366
- Math.round(c.height * i)
432
+ Math.round(s.x * i),
433
+ Math.round(s.y * i),
434
+ Math.round(s.width * i),
435
+ Math.round(s.height * i)
367
436
  );
368
437
  }
369
438
  if (e.contentBorder) {
370
- const { color: s = "#000000", width: g = 0.3 } = e.contentBorder, c = k(e.contentBorder, o);
371
- t.strokeStyle = s, t.lineWidth = g * i, t.strokeRect(
372
- Math.round(c.left * i),
373
- Math.round(c.top * i),
374
- Math.round((o.pageWidth - c.left - c.right) * i),
375
- Math.round((o.pageHeight - c.top - c.bottom) * i)
439
+ const { color: c = "#000000", width: g = 0.3 } = e.contentBorder, s = j(e.contentBorder, o);
440
+ t.strokeStyle = c, t.lineWidth = g * i, t.strokeRect(
441
+ Math.round(s.left * i),
442
+ Math.round(s.top * i),
443
+ Math.round((o.pageWidth - s.left - s.right) * i),
444
+ Math.round((o.pageHeight - s.top - s.bottom) * i)
376
445
  );
377
446
  }
378
447
  if (e.textBorder) {
379
- const s = k(e.textBorder, o);
380
- await K(
448
+ const c = j(e.textBorder, o);
449
+ await V(
381
450
  t,
382
451
  e.textBorder,
383
452
  i,
384
- Math.round(s.left * i),
385
- Math.round(s.top * i),
386
- Math.round((o.pageWidth - s.left - s.right) * i),
387
- Math.round((o.pageHeight - s.top - s.bottom) * i)
453
+ Math.round(c.left * i),
454
+ Math.round(c.top * i),
455
+ Math.round((o.pageWidth - c.left - c.right) * i),
456
+ Math.round((o.pageHeight - c.top - c.bottom) * i)
388
457
  );
389
458
  }
390
459
  }
391
- async function tt(t, e = {}) {
392
- const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n = M(e), l = B(), r = P(t, n.pageWidth);
393
- r.style.opacity = "1", r.style.left = "-99999px", N(r);
394
- const s = E(r, n);
395
- R(r, s.pageContentPx), T(r, s.pageContentPx), I(r, s.pageContentPx);
460
+ async function et(t, e = {}) {
461
+ const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n = M(e), l = N(), r = B(t, n.pageWidth);
462
+ r.style.opacity = "1", r.style.left = "-99999px", P(r);
463
+ const c = E(r, n);
464
+ R(r, c.pageContentPx), F(r, c.pageContentPx), T(r, c.pageContentPx);
396
465
  try {
397
466
  const g = await W(r, {
398
467
  scale: i,
399
468
  backgroundColor: "#ffffff"
400
- }), { jsPDF: c } = await import("jspdf"), h = n.pageWidth - n.margin.left - n.margin.right, f = n.pageHeight - n.margin.top - n.margin.bottom, d = g.width, m = f / h * d, b = Math.ceil(g.height / m), v = n.pageWidth > n.pageHeight ? "l" : "p", C = new c({
469
+ }), { jsPDF: s } = await import("jspdf"), h = n.pageWidth - n.margin.left - n.margin.right, f = n.pageHeight - n.margin.top - n.margin.bottom, d = g.width, u = f / h * d, m = Math.ceil(g.height / u), v = n.pageWidth > n.pageHeight ? "l" : "p", w = new s({
401
470
  orientation: v,
402
471
  unit: "mm",
403
472
  format: [n.pageWidth, n.pageHeight]
404
473
  });
405
- for (let y = 0; y < b; y++) {
406
- const p = Math.min(
407
- m,
408
- g.height - y * m
409
- ), u = document.createElement("canvas");
410
- u.width = d, u.height = p;
411
- const w = u.getContext("2d");
412
- if (!w) throw new Error("Could not get canvas context");
413
- w.fillStyle = "#ffffff", w.fillRect(0, 0, d, p), w.drawImage(
474
+ for (let y = 0; y < m; y++) {
475
+ const b = Math.min(
476
+ u,
477
+ g.height - y * u
478
+ ), C = document.createElement("canvas");
479
+ C.width = d, C.height = b;
480
+ const p = C.getContext("2d");
481
+ if (!p) throw new Error("Could not get canvas context");
482
+ p.fillStyle = "#ffffff", p.fillRect(0, 0, d, b), p.drawImage(
414
483
  g,
415
484
  0,
416
- y * m,
485
+ y * u,
417
486
  d,
418
- p,
487
+ b,
419
488
  0,
420
489
  0,
421
490
  d,
422
- p
491
+ b
423
492
  );
424
- const A = u.toDataURL(
493
+ const A = C.toDataURL(
425
494
  `image/${a.toLowerCase()}`,
426
495
  o
427
496
  );
428
- y > 0 && C.addPage([n.pageWidth, n.pageHeight], v);
429
- const H = p / d * h;
430
- C.addImage(
497
+ y > 0 && w.addPage([n.pageWidth, n.pageHeight], v);
498
+ const H = b / d * h;
499
+ w.addImage(
431
500
  A,
432
501
  a,
433
502
  n.margin.left,
@@ -438,62 +507,62 @@ async function tt(t, e = {}) {
438
507
  "FAST"
439
508
  );
440
509
  }
441
- return e.marginContent && await F(C, e.marginContent, e), C;
510
+ return e.marginContent && await $(w, e.marginContent, e), w;
442
511
  } finally {
443
512
  r.remove(), l();
444
513
  }
445
514
  }
446
- async function V(t, e = {}) {
447
- const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n = M(e), l = B(), r = P(t, n.pageWidth);
448
- r.style.opacity = "1", r.style.left = "-99999px", N(r);
449
- const s = E(r, n);
450
- R(r, s.pageContentPx), T(r, s.pageContentPx), I(r, s.pageContentPx);
515
+ async function Y(t, e = {}) {
516
+ const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n = M(e), l = N(), r = B(t, n.pageWidth);
517
+ r.style.opacity = "1", r.style.left = "-99999px", P(r);
518
+ const c = E(r, n);
519
+ R(r, c.pageContentPx), F(r, c.pageContentPx), T(r, c.pageContentPx);
451
520
  try {
452
521
  const g = await W(r, {
453
522
  scale: i,
454
523
  backgroundColor: "#ffffff"
455
- }), c = n.pageWidth - n.margin.left - n.margin.right, h = n.pageHeight - n.margin.top - n.margin.bottom, f = g.width, d = h / c * f, m = f / c, b = Math.round(n.pageWidth * m), v = Math.round(n.pageHeight * m), C = Math.round(n.margin.top * m), y = Math.round(n.margin.left * m), p = Math.ceil(g.height / d), u = [], { marginContent: w } = e, A = w ? await D(w, n, i) : {};
456
- for (let H = 0; H < p; H++) {
457
- const O = Math.min(
524
+ }), s = n.pageWidth - n.margin.left - n.margin.right, h = n.pageHeight - n.margin.top - n.margin.bottom, f = g.width, d = h / s * f, u = f / s, m = Math.round(n.pageWidth * u), v = Math.round(n.pageHeight * u), w = Math.round(n.margin.top * u), y = Math.round(n.margin.left * u), b = Math.ceil(g.height / d), C = [], { marginContent: p } = e, A = p ? await G(p, n, i) : {};
525
+ for (let H = 0; H < b; H++) {
526
+ const I = Math.min(
458
527
  d,
459
528
  g.height - H * d
460
529
  ), S = document.createElement("canvas");
461
- S.width = b, S.height = v;
530
+ S.width = m, S.height = v;
462
531
  const x = S.getContext("2d");
463
532
  if (!x) throw new Error("Could not get canvas context");
464
- x.fillStyle = "#ffffff", x.fillRect(0, 0, b, v), x.drawImage(
533
+ x.fillStyle = "#ffffff", x.fillRect(0, 0, m, v), x.drawImage(
465
534
  g,
466
535
  0,
467
536
  H * d,
468
537
  f,
469
- O,
538
+ I,
470
539
  y,
471
- C,
540
+ w,
472
541
  f,
473
- O
474
- ), w && await $(
542
+ I
543
+ ), p && await z(
475
544
  x,
476
- w,
545
+ p,
477
546
  A,
478
547
  n,
479
- m,
548
+ u,
480
549
  H + 1,
481
- p,
550
+ b,
482
551
  i
483
- ), u.push(
552
+ ), C.push(
484
553
  S.toDataURL(
485
554
  `image/${a.toLowerCase()}`,
486
555
  o
487
556
  )
488
557
  );
489
558
  }
490
- return u;
559
+ return C;
491
560
  } finally {
492
561
  r.remove(), l();
493
562
  }
494
563
  }
495
- async function et(t, e, a = {}) {
496
- const o = M(a), i = await V(t, a);
564
+ async function nt(t, e, a = {}) {
565
+ const o = M(a), i = await Y(t, a);
497
566
  e.innerHTML = "", Object.assign(e.style, {
498
567
  direction: "ltr",
499
568
  width: "fit-content",
@@ -516,20 +585,20 @@ async function et(t, e, a = {}) {
516
585
  }), e.appendChild(l);
517
586
  }
518
587
  }
519
- async function F(t, e, a = {}) {
520
- const o = M(a), i = t.getNumberOfPages(), n = 2, l = n * (96 / 25.4), r = Math.round(o.pageWidth * l), s = Math.round(o.pageHeight * l), g = await D(e, o, n);
521
- for (let c = 1; c <= i; c++) {
522
- t.setPage(c);
588
+ async function $(t, e, a = {}) {
589
+ const o = M(a), i = t.getNumberOfPages(), n = 2, l = n * (96 / 25.4), r = Math.round(o.pageWidth * l), c = Math.round(o.pageHeight * l), g = await G(e, o, n);
590
+ for (let s = 1; s <= i; s++) {
591
+ t.setPage(s);
523
592
  const h = document.createElement("canvas");
524
- h.width = r, h.height = s;
593
+ h.width = r, h.height = c;
525
594
  const f = h.getContext("2d");
526
- f && (await $(
595
+ f && (await z(
527
596
  f,
528
597
  e,
529
598
  g,
530
599
  o,
531
600
  l,
532
- c,
601
+ s,
533
602
  i,
534
603
  n
535
604
  ), t.addImage(
@@ -544,18 +613,18 @@ async function F(t, e, a = {}) {
544
613
  return t;
545
614
  }
546
615
  export {
547
- U as PAGE_MARGINS,
616
+ _ as PAGE_MARGINS,
548
617
  q as PAGE_SIZES,
549
- F as addMarginContent,
618
+ $ as addMarginContent,
550
619
  E as computeLayout,
551
- P as createPrintClone,
552
- I as insertPageBreakSpacers,
553
- N as normalizeTableAttributes,
620
+ B as createPrintClone,
621
+ T as insertPageBreakSpacers,
622
+ P as normalizeTableAttributes,
554
623
  Q as prepare,
555
- et as previewPageImages,
556
- X as renderHTML,
557
- tt as renderImagePDF,
558
- V as renderPageImages,
624
+ nt as previewPageImages,
625
+ tt as renderHTML,
626
+ et as renderImagePDF,
627
+ Y as renderPageImages,
559
628
  R as splitOversizedTables,
560
- T as splitOversizedText
629
+ F as splitOversizedText
561
630
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
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",