jspdf-utils 0.1.11 → 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.
@@ -98,6 +98,8 @@ export interface TextBorder {
98
98
  fontSize?: number;
99
99
  /** Font family (default: "Arial, sans-serif") */
100
100
  fontFamily?: string;
101
+ /** Font weight (default: "normal") */
102
+ fontWeight?: string;
101
103
  /** Gap between repetitions in mm (default: fontSize * 0.5) */
102
104
  gap?: number;
103
105
  /** Distance in mm from the page edge to the text border (default: uses page margins). */
@@ -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 S(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 S(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 = S(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,49 +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,
294
- fontFamily: c = "Arial, sans-serif"
295
- } = e, g = h * a, f = (e.gap ?? h * 0.5) * a;
296
- t.save(), t.fillStyle = l, t.font = `${g}px ${c}`, t.textBaseline = "middle";
297
- const d = t.measureText(r).width, m = d + f, w = g * 0.2, C = (p, u, y) => {
298
- for (let H = p; H < u; H += m)
299
- if (H + d <= u)
300
- y(H, r);
301
- else
302
- for (let b = r.length - 1; b >= 1; b--) {
303
- const W = r.substring(0, b);
304
- if (H + t.measureText(W).width <= u) {
305
- y(H, W);
306
- break;
307
- }
308
- }
309
- }, x = o + w, v = o + n - w;
310
- C(x, v, (p, u) => t.fillText(u, p, i)), C(x, v, (p, u) => t.fillText(u, p, i + s)), t.save(), t.translate(o, i + s), t.rotate(-Math.PI / 2), C(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.save(), t.translate(o + n, i), t.rotate(Math.PI / 2), C(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.restore();
333
+ color: s = "#000000",
334
+ fontSize: g = 2.5,
335
+ fontFamily: c = "Arial, sans-serif",
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();
311
342
  }
312
343
  function k(t, e) {
313
- return Q(t.margin, e);
344
+ return Z(t.margin, e);
314
345
  }
315
- async function F(t, e, a, o, i, n, s, r) {
316
- for (const l of G) {
317
- const h = e[l];
318
- if (!h) continue;
319
- const c = I(l, o);
320
- let g;
321
- typeof h == "function" ? g = await L(
322
- 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),
323
354
  c.width,
324
355
  c.height,
325
356
  r
326
- ) : g = a[l], t.drawImage(
327
- g,
357
+ ) : h = a[s], t.drawImage(
358
+ h,
328
359
  0,
329
360
  0,
330
- g.width,
331
- g.height,
361
+ h.width,
362
+ h.height,
332
363
  Math.round(c.x * i),
333
364
  Math.round(c.y * i),
334
365
  Math.round(c.width * i),
@@ -336,8 +367,8 @@ async function F(t, e, a, o, i, n, s, r) {
336
367
  );
337
368
  }
338
369
  if (e.contentBorder) {
339
- const { color: l = "#000000", width: h = 0.3 } = e.contentBorder, c = k(e.contentBorder, o);
340
- 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(
341
372
  Math.round(c.left * i),
342
373
  Math.round(c.top * i),
343
374
  Math.round((o.pageWidth - c.left - c.right) * i),
@@ -345,44 +376,44 @@ async function F(t, e, a, o, i, n, s, r) {
345
376
  );
346
377
  }
347
378
  if (e.textBorder) {
348
- const l = k(e.textBorder, o);
349
- Z(
379
+ const s = k(e.textBorder, o);
380
+ await K(
350
381
  t,
351
382
  e.textBorder,
352
383
  i,
353
- Math.round(l.left * i),
354
- Math.round(l.top * i),
355
- Math.round((o.pageWidth - l.left - l.right) * i),
356
- 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)
357
388
  );
358
389
  }
359
390
  }
360
- async function X(t, e = {}) {
361
- const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n = S(e), s = N(), r = E(t, n.pageWidth);
362
- r.style.opacity = "1", r.style.left = "-99999px", T(r);
363
- const l = B(r, n);
364
- 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);
365
396
  try {
366
- const h = await P(r, {
397
+ const g = await W(r, {
367
398
  scale: i,
368
399
  backgroundColor: "#ffffff"
369
- }), { 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, w = Math.ceil(h.height / m), C = n.pageWidth > n.pageHeight ? "l" : "p", x = new c({
370
- orientation: C,
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,
371
402
  unit: "mm",
372
403
  format: [n.pageWidth, n.pageHeight]
373
404
  });
374
- for (let v = 0; v < w; v++) {
405
+ for (let y = 0; y < b; y++) {
375
406
  const p = Math.min(
376
407
  m,
377
- h.height - v * m
408
+ g.height - y * m
378
409
  ), u = document.createElement("canvas");
379
410
  u.width = d, u.height = p;
380
- const y = u.getContext("2d");
381
- if (!y) throw new Error("Could not get canvas context");
382
- y.fillStyle = "#ffffff", y.fillRect(0, 0, d, p), y.drawImage(
383
- h,
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,
384
415
  0,
385
- v * m,
416
+ y * m,
386
417
  d,
387
418
  p,
388
419
  0,
@@ -390,67 +421,67 @@ async function X(t, e = {}) {
390
421
  d,
391
422
  p
392
423
  );
393
- const H = u.toDataURL(
424
+ const A = u.toDataURL(
394
425
  `image/${a.toLowerCase()}`,
395
426
  o
396
427
  );
397
- v > 0 && x.addPage([n.pageWidth, n.pageHeight], C);
398
- const b = p / d * g;
399
- x.addImage(
400
- H,
428
+ y > 0 && C.addPage([n.pageWidth, n.pageHeight], v);
429
+ const H = p / d * h;
430
+ C.addImage(
431
+ A,
401
432
  a,
402
433
  n.margin.left,
403
434
  n.margin.top,
404
- g,
405
- b,
435
+ h,
436
+ H,
406
437
  void 0,
407
438
  "FAST"
408
439
  );
409
440
  }
410
- return e.marginContent && await z(x, e.marginContent, e), x;
441
+ return e.marginContent && await F(C, e.marginContent, e), C;
411
442
  } finally {
412
- r.remove(), s();
443
+ r.remove(), l();
413
444
  }
414
445
  }
415
- async function K(t, e = {}) {
416
- const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n = S(e), s = N(), r = E(t, n.pageWidth);
417
- r.style.opacity = "1", r.style.left = "-99999px", T(r);
418
- const l = B(r, n);
419
- 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);
420
451
  try {
421
- const h = await P(r, {
452
+ const g = await W(r, {
422
453
  scale: i,
423
454
  backgroundColor: "#ffffff"
424
- }), 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, w = Math.round(n.pageWidth * m), C = Math.round(n.pageHeight * m), x = Math.round(n.margin.top * m), v = Math.round(n.margin.left * m), p = Math.ceil(h.height / d), u = [], { marginContent: y } = e, H = y ? await D(y, n, i) : {};
425
- for (let b = 0; b < p; b++) {
426
- const W = 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(
427
458
  d,
428
- h.height - b * d
429
- ), A = document.createElement("canvas");
430
- A.width = w, A.height = C;
431
- const M = A.getContext("2d");
432
- if (!M) throw new Error("Could not get canvas context");
433
- M.fillStyle = "#ffffff", M.fillRect(0, 0, w, C), M.drawImage(
434
- 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,
435
466
  0,
436
- b * d,
437
- f,
438
- W,
439
- v,
440
- x,
467
+ H * d,
441
468
  f,
442
- W
443
- ), y && await F(
444
- M,
469
+ O,
445
470
  y,
446
- H,
471
+ C,
472
+ f,
473
+ O
474
+ ), w && await $(
475
+ x,
476
+ w,
477
+ A,
447
478
  n,
448
479
  m,
449
- b + 1,
480
+ H + 1,
450
481
  p,
451
482
  i
452
483
  ), u.push(
453
- A.toDataURL(
484
+ S.toDataURL(
454
485
  `image/${a.toLowerCase()}`,
455
486
  o
456
487
  )
@@ -458,11 +489,11 @@ async function K(t, e = {}) {
458
489
  }
459
490
  return u;
460
491
  } finally {
461
- r.remove(), s();
492
+ r.remove(), l();
462
493
  }
463
494
  }
464
- async function tt(t, e, a = {}) {
465
- const o = S(a), i = await K(t, a);
495
+ async function et(t, e, a = {}) {
496
+ const o = M(a), i = await V(t, a);
466
497
  e.innerHTML = "", Object.assign(e.style, {
467
498
  direction: "ltr",
468
499
  width: "fit-content",
@@ -472,8 +503,8 @@ async function tt(t, e, a = {}) {
472
503
  background: "#e0e0e0"
473
504
  });
474
505
  for (let n = 0; n < i.length; n++) {
475
- const s = document.createElement("img");
476
- 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, {
477
508
  width: o.pageWidth + "mm",
478
509
  maxWidth: "100%",
479
510
  height: "auto",
@@ -482,27 +513,27 @@ async function tt(t, e, a = {}) {
482
513
  border: "1px solid #bbb",
483
514
  boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
484
515
  marginBottom: "16px"
485
- }), e.appendChild(s);
516
+ }), e.appendChild(l);
486
517
  }
487
518
  }
488
- async function z(t, e, a = {}) {
489
- const o = S(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);
490
521
  for (let c = 1; c <= i; c++) {
491
522
  t.setPage(c);
492
- const g = document.createElement("canvas");
493
- g.width = r, g.height = l;
494
- const f = g.getContext("2d");
495
- 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 $(
496
527
  f,
497
528
  e,
498
- h,
529
+ g,
499
530
  o,
500
- s,
531
+ l,
501
532
  c,
502
533
  i,
503
534
  n
504
535
  ), t.addImage(
505
- g.toDataURL("image/png"),
536
+ h.toDataURL("image/png"),
506
537
  "PNG",
507
538
  0,
508
539
  0,
@@ -513,18 +544,18 @@ async function z(t, e, a = {}) {
513
544
  return t;
514
545
  }
515
546
  export {
516
- $ as PAGE_MARGINS,
547
+ U as PAGE_MARGINS,
517
548
  q as PAGE_SIZES,
518
- z as addMarginContent,
519
- B as computeLayout,
520
- E as createPrintClone,
521
- O as insertPageBreakSpacers,
522
- T as normalizeTableAttributes,
523
- J as prepare,
524
- tt as previewPageImages,
525
- Y as renderHTML,
526
- X as renderImagePDF,
527
- 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,
528
559
  R as splitOversizedTables,
529
- j as splitOversizedText
560
+ T as splitOversizedText
530
561
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.11",
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",