jspdf-utils 0.1.12 → 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 +331 -232
  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
+ }, _ = {
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 = _[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 B(t, e = 210) {
45
45
  const a = t.cloneNode(!0);
46
46
  return Object.assign(a.style, {
47
47
  position: "fixed",
@@ -57,7 +57,7 @@ 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 T(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,101 +74,101 @@ 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, c = e - r - 2, g = [];
78
+ let s = [], 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 > c && s.length > 0 && (g.push(s), s = [], h = 0), s.push(f), h += d;
82
82
  }
83
- c.length > 0 && h.push(c);
84
- for (const f of h) {
83
+ s.length > 0 && g.push(s);
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 j(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") || "", 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), c = document.createElement(i);
99
+ c.setAttribute("style", n), Object.assign(c.style, {
100
100
  position: "absolute",
101
101
  visibility: "hidden",
102
- width: s
103
- }), t.appendChild(l);
104
- const h = [];
105
- let c = 0;
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;
102
+ width: l
103
+ }), t.appendChild(c);
104
+ const g = [];
105
+ let s = 0;
106
+ for (; s < r.length; ) {
107
+ let h = s + 1, f = r.length;
108
+ for (; h < f; ) {
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, g).join(" "), h.push(d), c = g;
113
+ d.setAttribute("style", n), d.textContent = r.slice(s, h).join(" "), g.push(d), s = h;
114
114
  }
115
- l.remove();
116
- for (const g of h)
117
- o.parentNode.insertBefore(g, o);
115
+ c.remove();
116
+ for (const h of g)
117
+ o.parentNode.insertBefore(h, o);
118
118
  o.remove();
119
119
  }
120
120
  }
121
121
  function U(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 c = a - r - 2;
127
+ if (c <= 0) return !1;
128
+ let g = 0, s = 0;
129
+ for (const d of l) {
130
+ if (s + d.offsetHeight > c) break;
131
+ s += 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 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(), l >= o.length) return !1;
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;
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
+ const h = document.createElement(i);
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 O(t, e) {
166
+ function T(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
173
  if (U(
174
174
  o,
@@ -176,21 +176,21 @@ function O(t, e) {
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 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
- 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 = N(), i = B(t, a.pageWidth);
191
+ P(i);
192
+ const n = E(i, a);
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,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 tt(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 $(t, a.marginContent, a), t;
222
222
  }
223
- function I(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 };
@@ -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"];
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 G) {
267
+ for (const i of D) {
268
268
  const n = t[i];
269
269
  if (n && typeof n != "function") {
270
- const s = I(i, e);
270
+ const l = k(i, e);
271
271
  o[i] = await L(
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,184 +286,283 @@ 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
+ 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, {
293
+ position: "fixed",
294
+ left: "-99999px",
295
+ top: "0",
296
+ width: `${e}px`,
297
+ height: `${a}px`,
298
+ overflow: "hidden",
299
+ whiteSpace: "nowrap",
300
+ fontSize: `${o}px`,
301
+ fontFamily: i,
302
+ fontWeight: n,
303
+ color: l,
304
+ display: "flex",
305
+ alignItems: "center",
306
+ gap: `${r}px`,
307
+ direction: c ? "rtl" : "ltr"
308
+ });
309
+ const s = document.createElement("span");
310
+ s.textContent = t, Object.assign(s.style, {
311
+ position: "absolute",
312
+ visibility: "hidden",
313
+ whiteSpace: "nowrap",
314
+ fontSize: `${o}px`,
315
+ fontFamily: i,
316
+ fontWeight: n
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);
324
+ }
325
+ document.body.appendChild(g);
326
+ try {
327
+ return await W(g, {
328
+ scale: 1,
329
+ backgroundColor: null,
330
+ width: Math.ceil(e),
331
+ height: Math.ceil(a)
332
+ });
333
+ } finally {
334
+ g.remove();
335
+ }
336
+ }
337
+ async function V(t, e, a, o, i, n, l) {
290
338
  const {
291
339
  text: r,
292
- color: l = "#000000",
293
- fontSize: h = 2.5,
294
- 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();
340
+ color: c = "#000000",
341
+ fontSize: g = 2.5,
342
+ fontFamily: s = "Arial, sans-serif",
343
+ fontWeight: h = "normal"
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();
312
411
  }
313
- function k(t, e) {
314
- return Q(t.margin, e);
412
+ function j(t, e) {
413
+ return Z(t.margin, e);
315
414
  }
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),
324
- c.width,
325
- c.height,
415
+ async function z(t, e, a, o, i, n, l, r) {
416
+ for (const c of D) {
417
+ const g = e[c];
418
+ if (!g) continue;
419
+ const s = k(c, o);
420
+ let h;
421
+ typeof g == "function" ? h = await L(
422
+ g(n, l),
423
+ s.width,
424
+ s.height,
326
425
  r
327
- ) : g = a[l], t.drawImage(
328
- g,
426
+ ) : h = a[c], t.drawImage(
427
+ h,
329
428
  0,
330
429
  0,
331
- g.width,
332
- g.height,
333
- Math.round(c.x * i),
334
- Math.round(c.y * i),
335
- Math.round(c.width * i),
336
- Math.round(c.height * i)
430
+ h.width,
431
+ h.height,
432
+ Math.round(s.x * i),
433
+ Math.round(s.y * i),
434
+ Math.round(s.width * i),
435
+ Math.round(s.height * i)
337
436
  );
338
437
  }
339
438
  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(
342
- Math.round(c.left * i),
343
- Math.round(c.top * i),
344
- Math.round((o.pageWidth - c.left - c.right) * i),
345
- 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)
346
445
  );
347
446
  }
348
447
  if (e.textBorder) {
349
- const l = k(e.textBorder, o);
350
- Z(
448
+ const c = j(e.textBorder, o);
449
+ await V(
351
450
  t,
352
451
  e.textBorder,
353
452
  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)
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)
358
457
  );
359
458
  }
360
459
  }
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);
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);
366
465
  try {
367
- const h = await P(r, {
466
+ const g = await W(r, {
368
467
  scale: i,
369
468
  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,
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({
470
+ orientation: v,
372
471
  unit: "mm",
373
472
  format: [n.pageWidth, n.pageHeight]
374
473
  });
375
- for (let v = 0; v < x; v++) {
376
- const C = Math.min(
377
- 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,
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(
483
+ g,
385
484
  0,
386
- v * m,
485
+ y * u,
387
486
  d,
388
- C,
487
+ b,
389
488
  0,
390
489
  0,
391
490
  d,
392
- C
491
+ b
393
492
  );
394
- const W = p.toDataURL(
493
+ const A = C.toDataURL(
395
494
  `image/${a.toLowerCase()}`,
396
495
  o
397
496
  );
398
- v > 0 && b.addPage([n.pageWidth, n.pageHeight], w);
399
- const y = C / d * g;
400
- b.addImage(
401
- W,
497
+ y > 0 && w.addPage([n.pageWidth, n.pageHeight], v);
498
+ const H = b / d * h;
499
+ w.addImage(
500
+ A,
402
501
  a,
403
502
  n.margin.left,
404
503
  n.margin.top,
405
- g,
406
- y,
504
+ h,
505
+ H,
407
506
  void 0,
408
507
  "FAST"
409
508
  );
410
509
  }
411
- return e.marginContent && await z(b, e.marginContent, e), b;
510
+ return e.marginContent && await $(w, e.marginContent, e), w;
412
511
  } finally {
413
- r.remove(), s();
512
+ r.remove(), l();
414
513
  }
415
514
  }
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);
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);
421
520
  try {
422
- const h = await P(r, {
521
+ const g = await W(r, {
423
522
  scale: i,
424
523
  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(
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(
428
527
  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,
528
+ g.height - H * d
529
+ ), S = document.createElement("canvas");
530
+ S.width = m, S.height = v;
531
+ const x = S.getContext("2d");
532
+ if (!x) throw new Error("Could not get canvas context");
533
+ x.fillStyle = "#ffffff", x.fillRect(0, 0, m, v), x.drawImage(
534
+ g,
436
535
  0,
437
- y * d,
536
+ H * d,
438
537
  f,
439
- M,
440
- v,
441
- b,
538
+ I,
539
+ y,
540
+ w,
442
541
  f,
443
- M
444
- ), u && await F(
445
- S,
446
- u,
447
- W,
542
+ I
543
+ ), p && await z(
544
+ x,
545
+ p,
546
+ A,
448
547
  n,
449
- m,
450
- y + 1,
451
- C,
548
+ u,
549
+ H + 1,
550
+ b,
452
551
  i
453
- ), p.push(
454
- H.toDataURL(
552
+ ), C.push(
553
+ S.toDataURL(
455
554
  `image/${a.toLowerCase()}`,
456
555
  o
457
556
  )
458
557
  );
459
558
  }
460
- return p;
559
+ return C;
461
560
  } finally {
462
- r.remove(), s();
561
+ r.remove(), l();
463
562
  }
464
563
  }
465
- async function tt(t, e, a = {}) {
466
- const o = A(a), i = await K(t, a);
564
+ async function nt(t, e, a = {}) {
565
+ const o = M(a), i = await Y(t, a);
467
566
  e.innerHTML = "", Object.assign(e.style, {
468
567
  direction: "ltr",
469
568
  width: "fit-content",
@@ -473,8 +572,8 @@ async function tt(t, e, a = {}) {
473
572
  background: "#e0e0e0"
474
573
  });
475
574
  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, {
575
+ const l = document.createElement("img");
576
+ l.src = i[n], l.alt = `Page ${n + 1}`, Object.assign(l.style, {
478
577
  width: o.pageWidth + "mm",
479
578
  maxWidth: "100%",
480
579
  height: "auto",
@@ -483,27 +582,27 @@ async function tt(t, e, a = {}) {
483
582
  border: "1px solid #bbb",
484
583
  boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
485
584
  marginBottom: "16px"
486
- }), e.appendChild(s);
585
+ }), e.appendChild(l);
487
586
  }
488
587
  }
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);
491
- for (let c = 1; c <= i; c++) {
492
- 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(
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);
592
+ const h = document.createElement("canvas");
593
+ h.width = r, h.height = c;
594
+ const f = h.getContext("2d");
595
+ f && (await z(
497
596
  f,
498
597
  e,
499
- h,
598
+ g,
500
599
  o,
600
+ l,
501
601
  s,
502
- c,
503
602
  i,
504
603
  n
505
604
  ), t.addImage(
506
- g.toDataURL("image/png"),
605
+ h.toDataURL("image/png"),
507
606
  "PNG",
508
607
  0,
509
608
  0,
@@ -514,18 +613,18 @@ async function z(t, e, a = {}) {
514
613
  return t;
515
614
  }
516
615
  export {
517
- $ as PAGE_MARGINS,
616
+ _ as PAGE_MARGINS,
518
617
  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,
618
+ $ as addMarginContent,
619
+ E as computeLayout,
620
+ B as createPrintClone,
621
+ T as insertPageBreakSpacers,
622
+ P as normalizeTableAttributes,
623
+ Q as prepare,
624
+ nt as previewPageImages,
625
+ tt as renderHTML,
626
+ et as renderImagePDF,
627
+ Y as renderPageImages,
529
628
  R as splitOversizedTables,
530
- j as splitOversizedText
629
+ F as splitOversizedText
531
630
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.12",
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",