jspdf-utils 0.1.11 → 0.1.12

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). */
@@ -22,7 +22,7 @@ const q = {
22
22
  legal: 25.4,
23
23
  tabloid: 25
24
24
  };
25
- function S(t = {}) {
25
+ function A(t = {}) {
26
26
  const e = t.format ?? "a4", [a, o] = q[e], i = t.pageWidth ?? a, n = t.pageHeight ?? o, s = $[e], r = {
27
27
  top: s,
28
28
  right: s,
@@ -187,7 +187,7 @@ function O(t, e) {
187
187
  }
188
188
  }
189
189
  function J(t, e = {}) {
190
- const a = S(e), o = N(), i = E(t, a.pageWidth);
190
+ const a = A(e), o = N(), i = E(t, a.pageWidth);
191
191
  T(i);
192
192
  const n = B(i, a);
193
193
  return R(i, n.pageContentPx), j(i, n.pageContentPx), O(i, n.pageContentPx), {
@@ -291,23 +291,24 @@ function Z(t, e, a, o, i, n, s) {
291
291
  text: r,
292
292
  color: l = "#000000",
293
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);
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);
301
302
  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);
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);
306
307
  break;
307
308
  }
308
309
  }
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();
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();
311
312
  }
312
313
  function k(t, e) {
313
314
  return Q(t.margin, e);
@@ -358,7 +359,7 @@ async function F(t, e, a, o, i, n, s, r) {
358
359
  }
359
360
  }
360
361
  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
+ const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n = A(e), s = N(), r = E(t, n.pageWidth);
362
363
  r.style.opacity = "1", r.style.left = "-99999px", T(r);
363
364
  const l = B(r, n);
364
365
  R(r, l.pageContentPx), j(r, l.pageContentPx), O(r, l.pageContentPx);
@@ -366,54 +367,54 @@ async function X(t, e = {}) {
366
367
  const h = await P(r, {
367
368
  scale: i,
368
369
  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,
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,
371
372
  unit: "mm",
372
373
  format: [n.pageWidth, n.pageHeight]
373
374
  });
374
- for (let v = 0; v < w; v++) {
375
- const p = Math.min(
375
+ for (let v = 0; v < x; v++) {
376
+ const C = Math.min(
376
377
  m,
377
378
  h.height - v * m
378
- ), u = document.createElement("canvas");
379
- 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(
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(
383
384
  h,
384
385
  0,
385
386
  v * m,
386
387
  d,
387
- p,
388
+ C,
388
389
  0,
389
390
  0,
390
391
  d,
391
- p
392
+ C
392
393
  );
393
- const H = u.toDataURL(
394
+ const W = p.toDataURL(
394
395
  `image/${a.toLowerCase()}`,
395
396
  o
396
397
  );
397
- v > 0 && x.addPage([n.pageWidth, n.pageHeight], C);
398
- const b = p / d * g;
399
- x.addImage(
400
- H,
398
+ v > 0 && b.addPage([n.pageWidth, n.pageHeight], w);
399
+ const y = C / d * g;
400
+ b.addImage(
401
+ W,
401
402
  a,
402
403
  n.margin.left,
403
404
  n.margin.top,
404
405
  g,
405
- b,
406
+ y,
406
407
  void 0,
407
408
  "FAST"
408
409
  );
409
410
  }
410
- return e.marginContent && await z(x, e.marginContent, e), x;
411
+ return e.marginContent && await z(b, e.marginContent, e), b;
411
412
  } finally {
412
413
  r.remove(), s();
413
414
  }
414
415
  }
415
416
  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
+ const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n = A(e), s = N(), r = E(t, n.pageWidth);
417
418
  r.style.opacity = "1", r.style.left = "-99999px", T(r);
418
419
  const l = B(r, n);
419
420
  R(r, l.pageContentPx), j(r, l.pageContentPx), O(r, l.pageContentPx);
@@ -421,48 +422,48 @@ async function K(t, e = {}) {
421
422
  const h = await P(r, {
422
423
  scale: i,
423
424
  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(
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(
427
428
  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(
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(
434
435
  h,
435
436
  0,
436
- b * d,
437
+ y * d,
437
438
  f,
438
- W,
439
+ M,
439
440
  v,
440
- x,
441
+ b,
441
442
  f,
442
- W
443
- ), y && await F(
444
- M,
445
- y,
446
- H,
443
+ M
444
+ ), u && await F(
445
+ S,
446
+ u,
447
+ W,
447
448
  n,
448
449
  m,
449
- b + 1,
450
- p,
450
+ y + 1,
451
+ C,
451
452
  i
452
- ), u.push(
453
- A.toDataURL(
453
+ ), p.push(
454
+ H.toDataURL(
454
455
  `image/${a.toLowerCase()}`,
455
456
  o
456
457
  )
457
458
  );
458
459
  }
459
- return u;
460
+ return p;
460
461
  } finally {
461
462
  r.remove(), s();
462
463
  }
463
464
  }
464
465
  async function tt(t, e, a = {}) {
465
- const o = S(a), i = await K(t, a);
466
+ const o = A(a), i = await K(t, a);
466
467
  e.innerHTML = "", Object.assign(e.style, {
467
468
  direction: "ltr",
468
469
  width: "fit-content",
@@ -486,7 +487,7 @@ async function tt(t, e, a = {}) {
486
487
  }
487
488
  }
488
489
  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);
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);
490
491
  for (let c = 1; c <= i; c++) {
491
492
  t.setPage(c);
492
493
  const g = document.createElement("canvas");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
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",