jspdf-utils 0.1.12 → 0.1.13

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 +246 -216
  2. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import P from "html2canvas";
1
+ import W from "html2canvas";
2
2
  const q = {
3
3
  a0: [841, 1189],
4
4
  a1: [594, 841],
@@ -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
- }, $ = {
13
+ }, U = {
14
14
  a0: 40,
15
15
  a1: 35,
16
16
  a2: 30,
@@ -22,12 +22,12 @@ const q = {
22
22
  legal: 25.4,
23
23
  tabloid: 25
24
24
  };
25
- function A(t = {}) {
26
- const e = t.format ?? "a4", [a, o] = q[e], i = t.pageWidth ?? a, n = t.pageHeight ?? o, s = $[e], r = {
27
- top: s,
28
- right: s,
29
- bottom: s,
30
- left: s
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 = {
27
+ top: l,
28
+ right: l,
29
+ bottom: l,
30
+ left: l
31
31
  };
32
32
  return {
33
33
  unit: t.unit ?? "mm",
@@ -37,11 +37,11 @@ function A(t = {}) {
37
37
  margin: { ...r, ...t.margin }
38
38
  };
39
39
  }
40
- function B(t, e) {
41
- const a = t.offsetWidth, o = e.pageWidth - e.margin.left - e.margin.right, i = o / a, s = (e.pageHeight - e.margin.top - e.margin.bottom) / i;
42
- return { renderedWidth: a, scale: i, contentWidthMm: o, pageContentPx: s };
40
+ function E(t, e) {
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
+ return { renderedWidth: a, scale: i, contentWidthMm: o, pageContentPx: l };
43
43
  }
44
- function E(t, e = 210) {
44
+ function P(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 E(t, e = 210) {
53
53
  pointerEvents: "none"
54
54
  }), document.body.appendChild(a), a;
55
55
  }
56
- function N() {
56
+ function B() {
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 T(t) {
60
+ function N(t) {
61
61
  for (const e of t.querySelectorAll("table")) {
62
62
  const a = e.getAttribute("cellpadding");
63
63
  if (a) {
@@ -74,14 +74,14 @@ 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, s = i ? o.slice(1) : o, r = n ? n.offsetHeight : 0, l = e - r - 2, h = [];
78
- let c = [], g = 0;
79
- for (const f of s) {
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;
79
+ for (const f of l) {
80
80
  const d = f.offsetHeight;
81
- g + d > l && c.length > 0 && (h.push(c), c = [], g = 0), c.push(f), g += d;
81
+ h + d > s && c.length > 0 && (g.push(c), c = [], h = 0), c.push(f), h += d;
82
82
  }
83
- c.length > 0 && h.push(c);
84
- for (const f of h) {
83
+ c.length > 0 && g.push(c);
84
+ for (const f of g) {
85
85
  const d = a.cloneNode(!1);
86
86
  n && d.appendChild(n.cloneNode(!0));
87
87
  for (const m of f) d.appendChild(m.cloneNode(!0));
@@ -90,107 +90,107 @@ function R(t, e) {
90
90
  a.remove();
91
91
  }
92
92
  }
93
- function j(t, e) {
93
+ function T(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") || "", s = getComputedStyle(o).width, r = (o.textContent || "").split(/\s+/).filter(Boolean), l = document.createElement(i);
99
- l.setAttribute("style", n), Object.assign(l.style, {
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, {
100
100
  position: "absolute",
101
101
  visibility: "hidden",
102
- width: s
103
- }), t.appendChild(l);
104
- const h = [];
102
+ width: l
103
+ }), t.appendChild(s);
104
+ const g = [];
105
105
  let c = 0;
106
106
  for (; c < r.length; ) {
107
- let g = c + 1, f = r.length;
108
- for (; g < f; ) {
109
- const m = Math.ceil((g + f) / 2);
110
- l.textContent = r.slice(c, m).join(" "), l.offsetHeight <= e ? g = m : f = m - 1;
107
+ let h = c + 1, f = r.length;
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;
111
111
  }
112
112
  const d = document.createElement(i);
113
- d.setAttribute("style", n), d.textContent = r.slice(c, g).join(" "), h.push(d), c = g;
113
+ d.setAttribute("style", n), d.textContent = r.slice(c, h).join(" "), g.push(d), c = h;
114
114
  }
115
- l.remove();
116
- for (const g of h)
117
- o.parentNode.insertBefore(g, o);
115
+ s.remove();
116
+ for (const h of g)
117
+ o.parentNode.insertBefore(h, o);
118
118
  o.remove();
119
119
  }
120
120
  }
121
- function U(t, e, a) {
121
+ function _(t, e, a) {
122
122
  const o = Array.from(t.rows);
123
123
  if (o.length === 0) return !1;
124
- const i = o[0].querySelector("th") !== null, n = i ? o[0] : null, s = i ? o.slice(1) : o, r = n ? n.offsetHeight : 0;
125
- if (s.length < 2) return !1;
126
- const l = a - r - 2;
127
- if (l <= 0) return !1;
128
- let h = 0, c = 0;
129
- for (const d of s) {
130
- if (c + d.offsetHeight > l) break;
131
- c += d.offsetHeight, h++;
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
+ if (l.length < 2) return !1;
126
+ const s = a - r - 2;
127
+ if (s <= 0) return !1;
128
+ let g = 0, c = 0;
129
+ for (const d of l) {
130
+ if (c + d.offsetHeight > s) break;
131
+ c += d.offsetHeight, g++;
132
132
  }
133
- if (h === 0 || h === s.length) return !1;
134
- const g = t.cloneNode(!1);
135
- n && g.appendChild(n.cloneNode(!0));
136
- for (let d = 0; d < h; d++)
137
- g.appendChild(s[d].cloneNode(!0));
133
+ if (g === 0 || g === l.length) return !1;
134
+ const h = t.cloneNode(!1);
135
+ n && h.appendChild(n.cloneNode(!0));
136
+ for (let d = 0; d < g; d++)
137
+ h.appendChild(l[d].cloneNode(!0));
138
138
  const f = t.cloneNode(!1);
139
139
  n && f.appendChild(n.cloneNode(!0));
140
- for (let d = h; d < s.length; d++)
141
- f.appendChild(s[d].cloneNode(!0));
142
- return e.insertBefore(g, t), e.insertBefore(f, t), t.remove(), !0;
140
+ for (let d = g; d < l.length; d++)
141
+ f.appendChild(l[d].cloneNode(!0));
142
+ return e.insertBefore(h, t), e.insertBefore(f, t), t.remove(), !0;
143
143
  }
144
- function _(t, e, a) {
144
+ function J(t, e, a) {
145
145
  if (t.tagName === "TABLE" || t.tagName === "IMG") return !1;
146
146
  const o = (t.textContent || "").split(/\s+/).filter(Boolean);
147
147
  if (o.length < 2) return !1;
148
- const i = t.tagName, n = t.getAttribute("style") || "", s = getComputedStyle(t).width, r = document.createElement(i);
148
+ const i = t.tagName, n = t.getAttribute("style") || "", l = getComputedStyle(t).width, r = document.createElement(i);
149
149
  if (r.setAttribute("style", n), Object.assign(r.style, {
150
150
  position: "absolute",
151
151
  visibility: "hidden",
152
- width: s
152
+ width: l
153
153
  }), e.appendChild(r), r.textContent = o[0], r.offsetHeight > a)
154
154
  return r.remove(), !1;
155
- let l = 1, h = o.length;
156
- for (; l < h; ) {
157
- const f = Math.ceil((l + h) / 2);
158
- r.textContent = o.slice(0, f).join(" "), r.offsetHeight <= a ? l = f : h = f - 1;
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;
159
159
  }
160
- if (r.remove(), l >= o.length) return !1;
160
+ if (r.remove(), s >= o.length) return !1;
161
161
  const c = document.createElement(i);
162
- c.setAttribute("style", n), c.textContent = o.slice(0, l).join(" ");
163
- const g = document.createElement(i);
164
- return g.setAttribute("style", n), g.textContent = o.slice(l).join(" "), e.insertBefore(c, t), e.insertBefore(g, t), t.remove(), !0;
162
+ c.setAttribute("style", n), c.textContent = o.slice(0, s).join(" ");
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;
165
165
  }
166
- function O(t, e) {
166
+ function I(t, e) {
167
167
  let a = 0;
168
168
  for (; a < t.children.length; ) {
169
- const o = t.children[a], i = o.offsetTop, n = i + o.offsetHeight, s = (Math.floor(i / e) + 1) * e;
170
- if (n > s) {
171
- const r = s - i;
169
+ const o = t.children[a], i = o.offsetTop, n = i + o.offsetHeight, l = (Math.floor(i / e) + 1) * e;
170
+ if (n > l) {
171
+ const r = l - i;
172
172
  if (o.tagName === "TABLE") {
173
- if (U(
173
+ if (_(
174
174
  o,
175
175
  t,
176
176
  r
177
177
  ))
178
178
  continue;
179
- } else if (_(o, t, r))
179
+ } else if (J(o, t, r))
180
180
  continue;
181
181
  if (o.offsetHeight <= e) {
182
- const l = document.createElement("div");
183
- l.style.height = s - i + 1 + "px", o.parentNode.insertBefore(l, o), a++;
182
+ const s = document.createElement("div");
183
+ s.style.height = l - i + 1 + "px", o.parentNode.insertBefore(s, o), a++;
184
184
  }
185
185
  }
186
186
  a++;
187
187
  }
188
188
  }
189
- function J(t, e = {}) {
190
- const a = A(e), o = N(), i = E(t, a.pageWidth);
191
- T(i);
192
- const n = B(i, a);
193
- return R(i, n.pageContentPx), j(i, n.pageContentPx), O(i, n.pageContentPx), {
189
+ function Q(t, e = {}) {
190
+ const a = M(e), o = B(), i = P(t, a.pageWidth);
191
+ N(i);
192
+ const n = E(i, a);
193
+ return R(i, n.pageContentPx), T(i, n.pageContentPx), I(i, n.pageContentPx), {
194
194
  clone: i,
195
195
  layout: n,
196
196
  options: a,
@@ -199,8 +199,8 @@ function J(t, e = {}) {
199
199
  }
200
200
  };
201
201
  }
202
- async function Y(t, e, a = {}) {
203
- const { clone: o, layout: i, options: n, cleanup: s } = J(e, a);
202
+ async function X(t, e, a = {}) {
203
+ const { clone: o, layout: i, options: n, cleanup: l } = Q(e, a);
204
204
  try {
205
205
  await new Promise((r) => {
206
206
  t.html(o, {
@@ -216,11 +216,11 @@ async function Y(t, e, a = {}) {
216
216
  });
217
217
  });
218
218
  } finally {
219
- s();
219
+ l();
220
220
  }
221
- return a.marginContent && await z(t, a.marginContent, a), t;
221
+ return a.marginContent && await F(t, a.marginContent, a), t;
222
222
  }
223
- function I(t, e) {
223
+ function L(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 I(t, e) {
242
242
  };
243
243
  }
244
244
  }
245
- async function L(t, e, a, o) {
245
+ async function G(t, e, a, o) {
246
246
  const i = document.createElement("div");
247
247
  Object.assign(i.style, {
248
248
  position: "fixed",
@@ -253,7 +253,7 @@ async function L(t, e, a, o) {
253
253
  overflow: "hidden"
254
254
  }), i.appendChild(t), document.body.appendChild(i);
255
255
  try {
256
- return await P(i, {
256
+ return await W(i, {
257
257
  scale: o,
258
258
  backgroundColor: null
259
259
  });
@@ -261,24 +261,24 @@ async function L(t, e, a, o) {
261
261
  i.remove();
262
262
  }
263
263
  }
264
- const G = ["top", "right", "bottom", "left"];
264
+ const z = ["top", "right", "bottom", "left"];
265
265
  async function D(t, e, a) {
266
266
  const o = {};
267
- for (const i of G) {
267
+ for (const i of z) {
268
268
  const n = t[i];
269
269
  if (n && typeof n != "function") {
270
- const s = I(i, e);
271
- o[i] = await L(
270
+ const l = L(i, e);
271
+ o[i] = await G(
272
272
  n.cloneNode(!0),
273
- s.width,
274
- s.height,
273
+ l.width,
274
+ l.height,
275
275
  a
276
276
  );
277
277
  }
278
278
  }
279
279
  return o;
280
280
  }
281
- function Q(t, e) {
281
+ function Z(t, e) {
282
282
  return t == null ? e.margin : typeof t == "number" ? { top: t, right: t, bottom: t, left: t } : {
283
283
  top: t.top ?? e.margin.top,
284
284
  right: t.right ?? e.margin.right,
@@ -286,50 +286,80 @@ function Q(t, e) {
286
286
  left: t.left ?? e.margin.left
287
287
  };
288
288
  }
289
- function Z(t, e, a, o, i, n, s) {
289
+ async function j(t, e, a, o, i, n, l, r) {
290
+ const s = document.createElement("div");
291
+ Object.assign(s.style, {
292
+ position: "fixed",
293
+ left: "-99999px",
294
+ top: "0",
295
+ width: `${e}px`,
296
+ height: `${a}px`,
297
+ overflow: "hidden",
298
+ whiteSpace: "nowrap",
299
+ fontSize: `${o}px`,
300
+ fontFamily: i,
301
+ fontWeight: n,
302
+ color: l,
303
+ display: "flex",
304
+ alignItems: "center",
305
+ gap: `${r}px`
306
+ });
307
+ const g = document.createElement("span");
308
+ g.textContent = t, Object.assign(g.style, {
309
+ position: "absolute",
310
+ visibility: "hidden",
311
+ whiteSpace: "nowrap",
312
+ fontSize: `${o}px`,
313
+ fontFamily: i,
314
+ 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);
322
+ }
323
+ document.body.appendChild(s);
324
+ try {
325
+ return await W(s, { scale: 1, backgroundColor: null });
326
+ } finally {
327
+ s.remove();
328
+ }
329
+ }
330
+ async function K(t, e, a, o, i, n, l) {
290
331
  const {
291
332
  text: r,
292
- color: l = "#000000",
293
- fontSize: h = 2.5,
333
+ color: s = "#000000",
334
+ fontSize: g = 2.5,
294
335
  fontFamily: c = "Arial, sans-serif",
295
- fontWeight: g = "normal"
296
- } = e, f = h * a, d = (e.gap ?? h * 0.5) * a;
297
- t.save(), t.fillStyle = l, t.font = `${g} ${f}px ${c}`, t.textBaseline = "middle";
298
- const m = t.measureText(r).width, x = m + d, w = f * 0.2, b = (p, u, W) => {
299
- for (let y = p; y < u; y += x)
300
- if (y + m <= u)
301
- W(y, r);
302
- else
303
- for (let M = r.length - 1; M >= 1; M--) {
304
- const H = r.substring(0, M);
305
- if (y + t.measureText(H).width <= u) {
306
- W(y, H);
307
- break;
308
- }
309
- }
310
- }, v = o + w, C = o + n - w;
311
- b(v, C, (p, u) => t.fillText(u, p, i)), b(v, C, (p, u) => t.fillText(u, p, i + s)), t.save(), t.translate(o, i + s), t.rotate(-Math.PI / 2), b(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.save(), t.translate(o + n, i), t.rotate(Math.PI / 2), b(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.restore();
336
+ 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();
312
342
  }
313
343
  function k(t, e) {
314
- return Q(t.margin, e);
344
+ return Z(t.margin, e);
315
345
  }
316
- async function F(t, e, a, o, i, n, s, r) {
317
- for (const l of G) {
318
- const h = e[l];
319
- if (!h) continue;
320
- const c = I(l, o);
321
- let g;
322
- typeof h == "function" ? g = await L(
323
- h(n, s),
346
+ async function $(t, e, a, o, i, n, l, r) {
347
+ for (const s of z) {
348
+ const g = e[s];
349
+ if (!g) continue;
350
+ const c = L(s, o);
351
+ let h;
352
+ typeof g == "function" ? h = await G(
353
+ g(n, l),
324
354
  c.width,
325
355
  c.height,
326
356
  r
327
- ) : g = a[l], t.drawImage(
328
- g,
357
+ ) : h = a[s], t.drawImage(
358
+ h,
329
359
  0,
330
360
  0,
331
- g.width,
332
- g.height,
361
+ h.width,
362
+ h.height,
333
363
  Math.round(c.x * i),
334
364
  Math.round(c.y * i),
335
365
  Math.round(c.width * i),
@@ -337,8 +367,8 @@ async function F(t, e, a, o, i, n, s, r) {
337
367
  );
338
368
  }
339
369
  if (e.contentBorder) {
340
- const { color: l = "#000000", width: h = 0.3 } = e.contentBorder, c = k(e.contentBorder, o);
341
- t.strokeStyle = l, t.lineWidth = h * i, t.strokeRect(
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(
342
372
  Math.round(c.left * i),
343
373
  Math.round(c.top * i),
344
374
  Math.round((o.pageWidth - c.left - c.right) * i),
@@ -346,124 +376,124 @@ async function F(t, e, a, o, i, n, s, r) {
346
376
  );
347
377
  }
348
378
  if (e.textBorder) {
349
- const l = k(e.textBorder, o);
350
- Z(
379
+ const s = k(e.textBorder, o);
380
+ await K(
351
381
  t,
352
382
  e.textBorder,
353
383
  i,
354
- Math.round(l.left * i),
355
- Math.round(l.top * i),
356
- Math.round((o.pageWidth - l.left - l.right) * i),
357
- Math.round((o.pageHeight - l.top - l.bottom) * 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)
358
388
  );
359
389
  }
360
390
  }
361
- async function X(t, e = {}) {
362
- const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n = A(e), s = N(), r = E(t, n.pageWidth);
363
- r.style.opacity = "1", r.style.left = "-99999px", T(r);
364
- const l = B(r, n);
365
- R(r, l.pageContentPx), j(r, l.pageContentPx), O(r, l.pageContentPx);
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);
366
396
  try {
367
- const h = await P(r, {
397
+ const g = await W(r, {
368
398
  scale: i,
369
399
  backgroundColor: "#ffffff"
370
- }), { jsPDF: c } = await import("jspdf"), g = n.pageWidth - n.margin.left - n.margin.right, f = n.pageHeight - n.margin.top - n.margin.bottom, d = h.width, m = f / g * d, x = Math.ceil(h.height / m), w = n.pageWidth > n.pageHeight ? "l" : "p", b = new c({
371
- orientation: w,
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({
401
+ orientation: v,
372
402
  unit: "mm",
373
403
  format: [n.pageWidth, n.pageHeight]
374
404
  });
375
- for (let v = 0; v < x; v++) {
376
- const C = Math.min(
405
+ for (let y = 0; y < b; y++) {
406
+ const p = Math.min(
377
407
  m,
378
- h.height - v * m
379
- ), p = document.createElement("canvas");
380
- p.width = d, p.height = C;
381
- const u = p.getContext("2d");
382
- if (!u) throw new Error("Could not get canvas context");
383
- u.fillStyle = "#ffffff", u.fillRect(0, 0, d, C), u.drawImage(
384
- h,
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(
414
+ g,
385
415
  0,
386
- v * m,
416
+ y * m,
387
417
  d,
388
- C,
418
+ p,
389
419
  0,
390
420
  0,
391
421
  d,
392
- C
422
+ p
393
423
  );
394
- const W = p.toDataURL(
424
+ const A = u.toDataURL(
395
425
  `image/${a.toLowerCase()}`,
396
426
  o
397
427
  );
398
- v > 0 && b.addPage([n.pageWidth, n.pageHeight], w);
399
- const y = C / d * g;
400
- b.addImage(
401
- W,
428
+ y > 0 && C.addPage([n.pageWidth, n.pageHeight], v);
429
+ const H = p / d * h;
430
+ C.addImage(
431
+ A,
402
432
  a,
403
433
  n.margin.left,
404
434
  n.margin.top,
405
- g,
406
- y,
435
+ h,
436
+ H,
407
437
  void 0,
408
438
  "FAST"
409
439
  );
410
440
  }
411
- return e.marginContent && await z(b, e.marginContent, e), b;
441
+ return e.marginContent && await F(C, e.marginContent, e), C;
412
442
  } finally {
413
- r.remove(), s();
443
+ r.remove(), l();
414
444
  }
415
445
  }
416
- async function K(t, e = {}) {
417
- const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n = A(e), s = N(), r = E(t, n.pageWidth);
418
- r.style.opacity = "1", r.style.left = "-99999px", T(r);
419
- const l = B(r, n);
420
- R(r, l.pageContentPx), j(r, l.pageContentPx), O(r, l.pageContentPx);
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);
421
451
  try {
422
- const h = await P(r, {
452
+ const g = await W(r, {
423
453
  scale: i,
424
454
  backgroundColor: "#ffffff"
425
- }), c = n.pageWidth - n.margin.left - n.margin.right, g = n.pageHeight - n.margin.top - n.margin.bottom, f = h.width, d = g / c * f, m = f / c, x = Math.round(n.pageWidth * m), w = Math.round(n.pageHeight * m), b = Math.round(n.margin.top * m), v = Math.round(n.margin.left * m), C = Math.ceil(h.height / d), p = [], { marginContent: u } = e, W = u ? await D(u, n, i) : {};
426
- for (let y = 0; y < C; y++) {
427
- const M = Math.min(
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(
428
458
  d,
429
- h.height - y * d
430
- ), H = document.createElement("canvas");
431
- H.width = x, H.height = w;
432
- const S = H.getContext("2d");
433
- if (!S) throw new Error("Could not get canvas context");
434
- S.fillStyle = "#ffffff", S.fillRect(0, 0, x, w), S.drawImage(
435
- h,
459
+ g.height - H * d
460
+ ), S = document.createElement("canvas");
461
+ S.width = b, S.height = v;
462
+ const x = S.getContext("2d");
463
+ if (!x) throw new Error("Could not get canvas context");
464
+ x.fillStyle = "#ffffff", x.fillRect(0, 0, b, v), x.drawImage(
465
+ g,
436
466
  0,
437
- y * d,
467
+ H * d,
438
468
  f,
439
- M,
440
- v,
441
- b,
469
+ O,
470
+ y,
471
+ C,
442
472
  f,
443
- M
444
- ), u && await F(
445
- S,
446
- u,
447
- W,
473
+ O
474
+ ), w && await $(
475
+ x,
476
+ w,
477
+ A,
448
478
  n,
449
479
  m,
450
- y + 1,
451
- C,
480
+ H + 1,
481
+ p,
452
482
  i
453
- ), p.push(
454
- H.toDataURL(
483
+ ), u.push(
484
+ S.toDataURL(
455
485
  `image/${a.toLowerCase()}`,
456
486
  o
457
487
  )
458
488
  );
459
489
  }
460
- return p;
490
+ return u;
461
491
  } finally {
462
- r.remove(), s();
492
+ r.remove(), l();
463
493
  }
464
494
  }
465
- async function tt(t, e, a = {}) {
466
- const o = A(a), i = await K(t, a);
495
+ async function et(t, e, a = {}) {
496
+ const o = M(a), i = await V(t, a);
467
497
  e.innerHTML = "", Object.assign(e.style, {
468
498
  direction: "ltr",
469
499
  width: "fit-content",
@@ -473,8 +503,8 @@ async function tt(t, e, a = {}) {
473
503
  background: "#e0e0e0"
474
504
  });
475
505
  for (let n = 0; n < i.length; n++) {
476
- const s = document.createElement("img");
477
- s.src = i[n], s.alt = `Page ${n + 1}`, Object.assign(s.style, {
506
+ const l = document.createElement("img");
507
+ l.src = i[n], l.alt = `Page ${n + 1}`, Object.assign(l.style, {
478
508
  width: o.pageWidth + "mm",
479
509
  maxWidth: "100%",
480
510
  height: "auto",
@@ -483,27 +513,27 @@ async function tt(t, e, a = {}) {
483
513
  border: "1px solid #bbb",
484
514
  boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
485
515
  marginBottom: "16px"
486
- }), e.appendChild(s);
516
+ }), e.appendChild(l);
487
517
  }
488
518
  }
489
- async function z(t, e, a = {}) {
490
- const o = A(a), i = t.getNumberOfPages(), n = 2, s = n * (96 / 25.4), r = Math.round(o.pageWidth * s), l = Math.round(o.pageHeight * s), h = await D(e, o, n);
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);
491
521
  for (let c = 1; c <= i; c++) {
492
522
  t.setPage(c);
493
- const g = document.createElement("canvas");
494
- g.width = r, g.height = l;
495
- const f = g.getContext("2d");
496
- f && (await F(
523
+ const h = document.createElement("canvas");
524
+ h.width = r, h.height = s;
525
+ const f = h.getContext("2d");
526
+ f && (await $(
497
527
  f,
498
528
  e,
499
- h,
529
+ g,
500
530
  o,
501
- s,
531
+ l,
502
532
  c,
503
533
  i,
504
534
  n
505
535
  ), t.addImage(
506
- g.toDataURL("image/png"),
536
+ h.toDataURL("image/png"),
507
537
  "PNG",
508
538
  0,
509
539
  0,
@@ -514,18 +544,18 @@ async function z(t, e, a = {}) {
514
544
  return t;
515
545
  }
516
546
  export {
517
- $ as PAGE_MARGINS,
547
+ U as PAGE_MARGINS,
518
548
  q as PAGE_SIZES,
519
- z as addMarginContent,
520
- B as computeLayout,
521
- E as createPrintClone,
522
- O as insertPageBreakSpacers,
523
- T as normalizeTableAttributes,
524
- J as prepare,
525
- tt as previewPageImages,
526
- Y as renderHTML,
527
- X as renderImagePDF,
528
- K as renderPageImages,
549
+ F as addMarginContent,
550
+ E as computeLayout,
551
+ P as createPrintClone,
552
+ I as insertPageBreakSpacers,
553
+ N as normalizeTableAttributes,
554
+ Q as prepare,
555
+ et as previewPageImages,
556
+ X as renderHTML,
557
+ tt as renderImagePDF,
558
+ V as renderPageImages,
529
559
  R as splitOversizedTables,
530
- j as splitOversizedText
560
+ T as splitOversizedText
531
561
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
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",