jspdf-utils 0.1.22 → 0.1.23

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.
@@ -12,6 +12,12 @@ export interface Margin {
12
12
  left: number;
13
13
  }
14
14
  export type PageFormat = "a0" | "a1" | "a2" | "a3" | "a4" | "a5" | "a6" | "letter" | "legal" | "tabloid";
15
+ export type MarginInput = number | {
16
+ top?: number;
17
+ right?: number;
18
+ bottom?: number;
19
+ left?: number;
20
+ };
15
21
  export interface PageOptions {
16
22
  unit: string;
17
23
  format: PageFormat;
@@ -19,6 +25,10 @@ export interface PageOptions {
19
25
  pageHeight: number;
20
26
  margin: Margin;
21
27
  }
28
+ /** Input variant of PageOptions where margin accepts a number or partial sides. */
29
+ export type PageOptionsInput = Partial<Omit<PageOptions, "margin">> & {
30
+ margin?: MarginInput;
31
+ };
22
32
  /** Standard page dimensions in mm (portrait). */
23
33
  declare const PAGE_SIZES: Record<PageFormat, [number, number]>;
24
34
  /** Standard margins in mm per format. */
@@ -35,46 +45,10 @@ export interface PrepareResult {
35
45
  options: PageOptions;
36
46
  cleanup: () => void;
37
47
  }
38
- /** Compute derived layout values from options. */
39
- declare function computeLayout(container: HTMLElement, opts: PageOptions): Layout;
40
- /**
41
- * Clone an element and position it off-screen at print width for measurement.
42
- */
43
- declare function createPrintClone(source: HTMLElement, pageWidth?: number): HTMLElement;
44
- /**
45
- * Convert HTML table attributes (cellpadding, cellspacing, border) to
46
- * inline CSS so doc.html()'s renderer picks them up.
47
- */
48
- declare function normalizeTableAttributes(container: HTMLElement): void;
49
- /**
50
- * Split tables that exceed one page height into smaller sub-tables,
51
- * repeating the header row in each chunk.
52
- *
53
- * Only operates on direct-child tables of `container`.
54
- */
55
- declare function splitOversizedTables(container: HTMLElement, pageContentPx: number): void;
56
- /**
57
- * Split direct-child elements (non-table) that are taller than one page
58
- * into word-boundary chunks using binary search.
59
- */
60
- declare function splitOversizedText(container: HTMLElement, pageContentPx: number): void;
61
- /**
62
- * Insert spacer divs so that no direct child straddles a page boundary.
63
- * For tables and text elements, attempts to split at the boundary first
64
- * so content fills the current page before flowing to the next.
65
- */
66
- declare function insertPageBreakSpacers(container: HTMLElement, pageContentPx: number): void;
67
- /**
68
- * Prepare an HTML element for doc.html() rendering.
69
- *
70
- * Clones the element, splits oversized tables/text, and inserts page-break
71
- * spacers. Returns the ready-to-render clone and layout metadata.
72
- */
73
- declare function prepare(source: HTMLElement, opts?: Partial<PageOptions>): PrepareResult;
74
48
  /**
75
49
  * Render an HTML element to PDF using doc.html().
76
50
  */
77
- declare function renderHTML(doc: jsPDF, source: HTMLElement, opts?: Partial<PageOptions> & Pick<ImagePDFOptions, "marginContent">): Promise<jsPDF>;
51
+ declare function generatePDF(doc: jsPDF, source: HTMLElement, opts?: PageOptionsInput & Pick<ImagePDFOptions, "marginContent">): Promise<jsPDF>;
78
52
  type MarginFactory = (page: number, totalPages: number) => HTMLElement;
79
53
  export interface ContentBorder {
80
54
  /** Stroke color (default: "#000000") */
@@ -130,25 +104,16 @@ export interface ImagePDFOptions {
130
104
  * Render an HTML element as an image-based PDF. Each page is a rasterized
131
105
  * screenshot — no selectable or extractable text in the output.
132
106
  */
133
- declare function renderImagePDF(source: HTMLElement, opts?: Partial<PageOptions> & ImagePDFOptions): Promise<jsPDF>;
107
+ declare function generateImagePDF(source: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions): Promise<jsPDF>;
134
108
  /**
135
109
  * Render an HTML element to an array of page images (data URLs).
136
110
  * Each image represents a full page with margins, matching the
137
111
  * visual output of renderImagePDF.
138
112
  */
139
- declare function renderPageImages(source: HTMLElement, opts?: Partial<PageOptions> & ImagePDFOptions): Promise<string[]>;
113
+ declare function generateImages(source: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions): Promise<string[]>;
140
114
  /**
141
115
  * Render an HTML element as page images and inject them into a scrollable
142
116
  * container. Each image is sized to match the page format dimensions.
143
117
  */
144
- declare function previewPageImages(source: HTMLElement, container: HTMLElement, opts?: Partial<PageOptions> & ImagePDFOptions): Promise<void>;
145
- /**
146
- * Add HTML content to the margin areas of each page in a jsPDF document.
147
- *
148
- * Each slot (top, right, bottom, left) accepts either a static HTMLElement
149
- * (rendered once and reused on every page) or a factory function that
150
- * receives `(page, totalPages)` and returns an HTMLElement per page
151
- * (useful for page numbers or dynamic content).
152
- */
153
- declare function addMarginContent(doc: jsPDF, content: MarginContentInput, opts?: Partial<PageOptions>): Promise<jsPDF>;
154
- export { PAGE_SIZES, PAGE_MARGINS, computeLayout, createPrintClone, normalizeTableAttributes, splitOversizedTables, splitOversizedText, insertPageBreakSpacers, prepare, renderHTML, renderImagePDF, renderPageImages, previewPageImages, addMarginContent, };
118
+ declare function previewImages(source: HTMLElement, container: HTMLElement, opts?: PageOptionsInput & ImagePDFOptions): Promise<void>;
119
+ export { PAGE_SIZES, PAGE_MARGINS, generatePDF, generateImagePDF, generateImages, previewImages, };
@@ -1,5 +1,5 @@
1
- import P from "html2canvas";
2
- const _ = {
1
+ import S from "html2canvas";
2
+ const J = {
3
3
  a0: [841, 1189],
4
4
  a1: [594, 841],
5
5
  a2: [420, 594],
@@ -10,7 +10,7 @@ const _ = {
10
10
  letter: [215.9, 279.4],
11
11
  legal: [215.9, 355.6],
12
12
  tabloid: [279.4, 431.8]
13
- }, J = {
13
+ }, Q = {
14
14
  a0: 40,
15
15
  a1: 35,
16
16
  a2: 30,
@@ -22,693 +22,694 @@ const _ = {
22
22
  legal: 25.4,
23
23
  tabloid: 25
24
24
  };
25
- function S(e = {}) {
26
- const n = e.format ?? "a4", [a, t] = _[n], i = e.pageWidth ?? a, o = e.pageHeight ?? t, s = J[n], r = {
27
- top: s,
28
- right: s,
29
- bottom: s,
30
- left: s
25
+ function M(t) {
26
+ return { top: t, right: t, bottom: t, left: t };
27
+ }
28
+ function Z(t, e) {
29
+ const a = M(Q[e]);
30
+ return t == null ? a : typeof t == "number" ? M(t) : {
31
+ top: t.top ?? a.top,
32
+ right: t.right ?? a.right,
33
+ bottom: t.bottom ?? a.bottom,
34
+ left: t.left ?? a.left
31
35
  };
36
+ }
37
+ function x(t = {}) {
38
+ const e = t.format ?? "a4", [a, n] = J[e];
32
39
  return {
33
- unit: e.unit ?? "mm",
34
- format: n,
35
- pageWidth: i,
36
- pageHeight: o,
37
- margin: { ...r, ...e.margin }
40
+ unit: t.unit ?? "mm",
41
+ format: e,
42
+ pageWidth: t.pageWidth ?? a,
43
+ pageHeight: t.pageHeight ?? n,
44
+ margin: Z(t.margin, e)
38
45
  };
39
46
  }
40
- function N(e, n) {
41
- const a = e.offsetWidth, t = n.pageWidth - n.margin.left - n.margin.right, i = t / a, s = (n.pageHeight - n.margin.top - n.margin.bottom) / i;
42
- return { renderedWidth: a, scale: i, contentWidthMm: t, pageContentPx: s };
47
+ function E(t, e) {
48
+ const a = t.offsetWidth, n = e.pageWidth - e.margin.left - e.margin.right, o = n / a, r = (e.pageHeight - e.margin.top - e.margin.bottom) / o;
49
+ return { renderedWidth: a, scale: o, contentWidthMm: n, pageContentPx: r };
43
50
  }
44
- function F(e, n = 210) {
45
- const a = e.cloneNode(!0);
51
+ function N(t, e = 210) {
52
+ const a = t.cloneNode(!0);
46
53
  return Object.assign(a.style, {
47
54
  position: "fixed",
48
55
  top: "0",
49
56
  left: "0",
50
57
  boxSizing: "border-box",
51
- width: n + "mm",
58
+ width: e + "mm",
52
59
  opacity: "0.000001",
53
60
  pointerEvents: "none"
54
61
  }), document.body.appendChild(a), a;
55
62
  }
56
- async function Q(e) {
57
- const n = Array.from(e.querySelectorAll("img"));
63
+ async function F(t) {
64
+ const e = Array.from(t.querySelectorAll("img"));
58
65
  await Promise.all(
59
- n.map((a) => {
66
+ e.map((a) => {
60
67
  if (!(a.complete && a.naturalWidth > 0))
61
- return new Promise((t) => {
62
- a.onload = () => t(), a.onerror = () => t();
68
+ return new Promise((n) => {
69
+ a.onload = () => n(), a.onerror = () => n();
63
70
  });
64
71
  })
65
72
  );
66
73
  }
67
- async function q(e) {
68
- await Q(e);
69
- const n = e.getBoundingClientRect();
70
- let a = n.bottom;
71
- for (const i of Array.from(e.querySelectorAll("*"))) {
72
- const o = i.getBoundingClientRect().bottom;
73
- o > a && (a = o);
74
+ async function K(t) {
75
+ await F(t);
76
+ const e = t.getBoundingClientRect();
77
+ let a = e.bottom;
78
+ for (const o of Array.from(t.querySelectorAll("*"))) {
79
+ const i = o.getBoundingClientRect().bottom;
80
+ i > a && (a = i);
74
81
  }
75
- const t = a - n.top;
76
- t > e.offsetHeight && (e.style.minHeight = t + "px");
82
+ const n = a - e.top;
83
+ n > t.offsetHeight && (t.style.minHeight = n + "px");
77
84
  }
78
- async function Z(e) {
79
- const n = Array.from(e.querySelectorAll("img"));
80
- if (n.length === 0) return;
81
- await Promise.all(
82
- n.map((t) => {
83
- if (!(t.complete && t.naturalWidth > 0))
84
- return new Promise((i) => {
85
- t.onload = () => i(), t.onerror = () => i();
86
- });
87
- })
88
- );
85
+ async function V(t) {
86
+ const e = Array.from(t.querySelectorAll("img"));
87
+ if (e.length === 0) return;
88
+ await F(t);
89
89
  const a = 2;
90
- for (const t of n) {
91
- if (!t.naturalWidth || !t.naturalHeight || t.src.startsWith("data:image/svg")) continue;
92
- const i = t.offsetWidth || t.naturalWidth, o = t.offsetHeight || t.naturalHeight, s = Math.min(i * a, t.naturalWidth), r = Math.min(o * a, t.naturalHeight);
93
- if (t.naturalWidth <= s && t.naturalHeight <= r && t.src.startsWith("data:"))
90
+ for (const n of e) {
91
+ if (!n.naturalWidth || !n.naturalHeight || n.src.startsWith("data:image/svg")) continue;
92
+ const o = n.offsetWidth || n.naturalWidth, i = n.offsetHeight || n.naturalHeight, r = Math.min(o * a, n.naturalWidth), h = Math.min(i * a, n.naturalHeight);
93
+ if (n.naturalWidth <= r && n.naturalHeight <= h && n.src.startsWith("data:"))
94
94
  continue;
95
- const l = document.createElement("canvas");
96
- l.width = s, l.height = r;
97
- const g = l.getContext("2d");
98
- if (g)
95
+ const s = document.createElement("canvas");
96
+ s.width = r, s.height = h;
97
+ const l = s.getContext("2d");
98
+ if (l)
99
99
  try {
100
- g.drawImage(t, 0, 0, s, r), t.style.width = i + "px", t.style.height = o + "px", t.src = l.toDataURL("image/png");
100
+ l.drawImage(n, 0, 0, r, h), n.style.width = o + "px", n.style.height = i + "px", n.src = s.toDataURL("image/png");
101
101
  } catch {
102
102
  }
103
103
  }
104
104
  }
105
- function E() {
106
- const e = document.createElement("style");
107
- return e.setAttribute("data-jspdf-utils", ""), e.textContent = "img { display: inline !important; }", document.head.appendChild(e), () => e.remove();
105
+ function P() {
106
+ const t = document.createElement("style");
107
+ return t.setAttribute("data-jspdf-utils", ""), t.textContent = "img { display: inline !important; }", document.head.appendChild(t), () => t.remove();
108
108
  }
109
- function I(e) {
110
- for (const n of Array.from(e.querySelectorAll("table"))) {
111
- const a = n.getAttribute("cellpadding");
109
+ function T(t) {
110
+ for (const e of Array.from(t.querySelectorAll("table"))) {
111
+ const a = e.getAttribute("cellpadding");
112
112
  if (a) {
113
- for (const t of Array.from(n.querySelectorAll("th, td")))
114
- t.style.padding || (t.style.padding = a + "px");
115
- n.removeAttribute("cellpadding");
113
+ for (const n of Array.from(e.querySelectorAll("th, td")))
114
+ n.style.padding || (n.style.padding = a + "px");
115
+ e.removeAttribute("cellpadding");
116
116
  }
117
117
  }
118
118
  }
119
- function L(e, n) {
119
+ function I(t, e) {
120
120
  for (const a of Array.from(
121
- e.querySelectorAll(":scope > table")
121
+ t.querySelectorAll(":scope > table")
122
122
  )) {
123
- if (a.offsetHeight <= n) continue;
124
- const t = Array.from(a.rows);
125
- if (t.length === 0) continue;
126
- const i = t[0].querySelector("th") !== null, o = i ? t[0] : null, s = i ? t.slice(1) : t, r = o ? o.offsetHeight : 0, l = n - r - 2, g = [];
127
- let h = [], d = 0;
128
- for (const u of s) {
129
- const c = u.offsetHeight;
130
- d + c > l && h.length > 0 && (g.push(h), h = [], d = 0), h.push(u), d += c;
123
+ if (a.offsetHeight <= e) continue;
124
+ const n = D(a);
125
+ if (!n) continue;
126
+ const { headerRow: o, bodyRows: i, headerHeight: r } = n, h = e - r - 2, s = [];
127
+ let l = [], c = 0;
128
+ for (const d of i) {
129
+ const g = d.offsetHeight;
130
+ c + g > h && l.length > 0 && (s.push(l), l = [], c = 0), l.push(d), c += g;
131
131
  }
132
- h.length > 0 && g.push(h);
133
- for (const u of g) {
134
- const c = a.cloneNode(!1);
135
- o && c.appendChild(o.cloneNode(!0));
136
- for (const f of u) c.appendChild(f.cloneNode(!0));
137
- a.parentNode.insertBefore(c, a);
132
+ l.length > 0 && s.push(l);
133
+ for (const d of s) {
134
+ const g = a.cloneNode(!1);
135
+ o && g.appendChild(o.cloneNode(!0));
136
+ for (const u of d) g.appendChild(u.cloneNode(!0));
137
+ a.parentNode.insertBefore(g, a);
138
138
  }
139
139
  a.remove();
140
140
  }
141
141
  }
142
- function O(e, n) {
143
- for (const a of Array.from(e.querySelectorAll(":scope > *"))) {
144
- const t = a;
145
- if (t.offsetHeight <= n || t.tagName === "TABLE")
142
+ function L(t, e, a, n) {
143
+ const o = document.createElement(t);
144
+ return o.setAttribute("style", e), Object.assign(o.style, {
145
+ position: "absolute",
146
+ visibility: "hidden",
147
+ width: a
148
+ }), n.appendChild(o), o;
149
+ }
150
+ function O(t, e, a, n) {
151
+ let o = n + 1, i = e.length;
152
+ for (; o < i; ) {
153
+ const r = Math.ceil((o + i) / 2);
154
+ t.textContent = e.slice(n, r).join(" "), t.offsetHeight <= a ? o = r : i = r - 1;
155
+ }
156
+ return o;
157
+ }
158
+ function D(t) {
159
+ const e = Array.from(t.rows);
160
+ if (e.length === 0) return null;
161
+ const a = e[0].querySelector("th") !== null, n = a ? e[0] : null, o = a ? e.slice(1) : e, i = n ? n.offsetHeight : 0;
162
+ return { rows: e, hasHeader: a, headerRow: n, bodyRows: o, headerHeight: i };
163
+ }
164
+ function k(t, e) {
165
+ for (const a of Array.from(t.querySelectorAll(":scope > *"))) {
166
+ const n = a;
167
+ if (n.offsetHeight <= e || n.tagName === "TABLE")
146
168
  continue;
147
- const i = t.tagName, o = t.getAttribute("style") || "", s = getComputedStyle(t).width, r = (t.textContent || "").split(/\s+/).filter(Boolean), l = document.createElement(i);
148
- l.setAttribute("style", o), Object.assign(l.style, {
149
- position: "absolute",
150
- visibility: "hidden",
151
- width: s
152
- }), e.appendChild(l);
153
- const g = [];
154
- let h = 0;
155
- for (; h < r.length; ) {
156
- let d = h + 1, u = r.length;
157
- for (; d < u; ) {
158
- const f = Math.ceil((d + u) / 2);
159
- l.textContent = r.slice(h, f).join(" "), l.offsetHeight <= n ? d = f : u = f - 1;
160
- }
161
- const c = document.createElement(i);
162
- c.setAttribute("style", o), c.textContent = r.slice(h, d).join(" "), g.push(c), h = d;
169
+ const o = n.tagName, i = n.getAttribute("style") || "", r = getComputedStyle(n).width, h = (n.textContent || "").split(/\s+/).filter(Boolean), s = L(o, i, r, t), l = [];
170
+ let c = 0;
171
+ for (; c < h.length; ) {
172
+ const d = O(s, h, e, c), g = document.createElement(o);
173
+ g.setAttribute("style", i), g.textContent = h.slice(c, d).join(" "), l.push(g), c = d;
163
174
  }
164
- l.remove();
165
- for (const d of g)
166
- t.parentNode.insertBefore(d, t);
167
- t.remove();
175
+ s.remove();
176
+ for (const d of l)
177
+ n.parentNode.insertBefore(d, n);
178
+ n.remove();
168
179
  }
169
180
  }
170
- function K(e, n, a) {
171
- const t = Array.from(e.rows);
172
- if (t.length === 0) return !1;
173
- const i = t[0].querySelector("th") !== null, o = i ? t[0] : null, s = i ? t.slice(1) : t, r = o ? o.offsetHeight : 0;
174
- if (s.length < 2) return !1;
175
- const l = a - r - 2;
176
- if (l <= 0) return !1;
177
- let g = 0, h = 0;
178
- for (const c of s) {
179
- if (h + c.offsetHeight > l) break;
180
- h += c.offsetHeight, g++;
181
+ function Y(t, e, a) {
182
+ const n = D(t);
183
+ if (!n) return !1;
184
+ const { headerRow: o, bodyRows: i, headerHeight: r } = n;
185
+ if (i.length < 2) return !1;
186
+ const h = a - r - 2;
187
+ if (h <= 0) return !1;
188
+ let s = 0, l = 0;
189
+ for (const g of i) {
190
+ if (l + g.offsetHeight > h) break;
191
+ l += g.offsetHeight, s++;
181
192
  }
182
- if (g === 0 || g === s.length) return !1;
183
- const d = e.cloneNode(!1);
193
+ if (s === 0 || s === i.length) return !1;
194
+ const c = t.cloneNode(!1);
195
+ o && c.appendChild(o.cloneNode(!0));
196
+ for (let g = 0; g < s; g++)
197
+ c.appendChild(i[g].cloneNode(!0));
198
+ const d = t.cloneNode(!1);
184
199
  o && d.appendChild(o.cloneNode(!0));
185
- for (let c = 0; c < g; c++)
186
- d.appendChild(s[c].cloneNode(!0));
187
- const u = e.cloneNode(!1);
188
- o && u.appendChild(o.cloneNode(!0));
189
- for (let c = g; c < s.length; c++)
190
- u.appendChild(s[c].cloneNode(!0));
191
- return n.insertBefore(d, e), n.insertBefore(u, e), e.remove(), !0;
192
- }
193
- function V(e, n, a) {
194
- if (e.tagName === "TABLE" || e.tagName === "IMG") return !1;
195
- const t = (e.textContent || "").split(/\s+/).filter(Boolean);
196
- if (t.length < 2) return !1;
197
- const i = e.tagName, o = e.getAttribute("style") || "", s = getComputedStyle(e).width, r = document.createElement(i);
198
- if (r.setAttribute("style", o), Object.assign(r.style, {
199
- position: "absolute",
200
- visibility: "hidden",
201
- width: s
202
- }), n.appendChild(r), r.textContent = t[0], r.offsetHeight > a)
203
- return r.remove(), !1;
204
- let l = 1, g = t.length;
205
- for (; l < g; ) {
206
- const u = Math.ceil((l + g) / 2);
207
- r.textContent = t.slice(0, u).join(" "), r.offsetHeight <= a ? l = u : g = u - 1;
208
- }
209
- if (r.remove(), l >= t.length) return !1;
210
- const h = document.createElement(i);
211
- h.setAttribute("style", o), h.textContent = t.slice(0, l).join(" ");
212
- const d = document.createElement(i);
213
- return d.setAttribute("style", o), d.textContent = t.slice(l).join(" "), n.insertBefore(h, e), n.insertBefore(d, e), e.remove(), !0;
200
+ for (let g = s; g < i.length; g++)
201
+ d.appendChild(i[g].cloneNode(!0));
202
+ return e.insertBefore(c, t), e.insertBefore(d, t), t.remove(), !0;
203
+ }
204
+ function X(t, e, a) {
205
+ if (t.tagName === "TABLE" || t.tagName === "IMG") return !1;
206
+ const n = (t.textContent || "").split(/\s+/).filter(Boolean);
207
+ if (n.length < 2) return !1;
208
+ const o = t.tagName, i = t.getAttribute("style") || "", r = getComputedStyle(t).width, h = L(o, i, r, e);
209
+ if (h.textContent = n[0], h.offsetHeight > a)
210
+ return h.remove(), !1;
211
+ const s = O(h, n, a, 0);
212
+ if (h.remove(), s >= n.length) return !1;
213
+ const l = document.createElement(o);
214
+ l.setAttribute("style", i), l.textContent = n.slice(0, s).join(" ");
215
+ const c = document.createElement(o);
216
+ return c.setAttribute("style", i), c.textContent = n.slice(s).join(" "), e.insertBefore(l, t), e.insertBefore(c, t), t.remove(), !0;
214
217
  }
215
- function T(e, n) {
218
+ function j(t, e) {
216
219
  let a = 0;
217
- for (; a < e.children.length; ) {
218
- const t = e.children[a], i = t.offsetTop, o = i + t.offsetHeight, s = (Math.floor(i / n) + 1) * n;
219
- if (o > s) {
220
- const r = s - i;
221
- if (t.tagName === "TABLE") {
222
- if (K(
220
+ for (; a < t.children.length; ) {
221
+ const n = t.children[a], o = n.offsetTop, i = o + n.offsetHeight, r = (Math.floor(o / e) + 1) * e;
222
+ if (i > r) {
223
+ const h = r - o;
224
+ if (n.tagName === "TABLE") {
225
+ if (Y(
226
+ n,
223
227
  t,
224
- e,
225
- r
228
+ h
226
229
  ))
227
230
  continue;
228
- } else if (V(t, e, r))
231
+ } else if (X(n, t, h))
229
232
  continue;
230
- if (t.offsetHeight <= n) {
231
- const l = document.createElement("div");
232
- l.style.height = s - i + 1 + "px", t.parentNode.insertBefore(l, t), a++;
233
+ if (n.offsetHeight <= e) {
234
+ const s = document.createElement("div");
235
+ s.style.height = r - o + 1 + "px", n.parentNode.insertBefore(s, n), a++;
233
236
  }
234
237
  }
235
238
  a++;
236
239
  }
237
240
  }
238
- function Y(e, n = {}) {
239
- const a = S(n), t = E(), i = F(e, a.pageWidth);
240
- I(i);
241
- const o = N(i, a);
242
- return L(i, o.pageContentPx), O(i, o.pageContentPx), T(i, o.pageContentPx), {
243
- clone: i,
244
- layout: o,
241
+ function tt(t, e = {}) {
242
+ const a = x(e), n = P(), o = N(t, a.pageWidth);
243
+ T(o);
244
+ const i = E(o, a);
245
+ return I(o, i.pageContentPx), k(o, i.pageContentPx), j(o, i.pageContentPx), {
246
+ clone: o,
247
+ layout: i,
245
248
  options: a,
246
249
  cleanup: () => {
247
- i.remove(), t();
250
+ o.remove(), n();
248
251
  }
249
252
  };
250
253
  }
251
- async function it(e, n, a = {}) {
252
- const { clone: t, layout: i, options: o, cleanup: s } = Y(n, a);
254
+ async function rt(t, e, a = {}) {
255
+ const { clone: n, layout: o, options: i, cleanup: r } = tt(e, a);
253
256
  try {
254
- await Z(t), await new Promise((r) => {
255
- e.html(t, {
256
- callback: () => r(),
257
- width: i.contentWidthMm,
258
- windowWidth: i.renderedWidth,
257
+ await V(n), await new Promise((h) => {
258
+ t.html(n, {
259
+ callback: () => h(),
260
+ width: o.contentWidthMm,
261
+ windowWidth: o.renderedWidth,
259
262
  margin: [
260
- o.margin.top,
261
- o.margin.right,
262
- o.margin.bottom,
263
- o.margin.left
263
+ i.margin.top,
264
+ i.margin.right,
265
+ i.margin.bottom,
266
+ i.margin.left
264
267
  ]
265
268
  });
266
269
  });
267
270
  } finally {
268
- s();
271
+ r();
269
272
  }
270
- return a.marginContent && await $(e, a.marginContent, a), e;
273
+ return a.marginContent && await _(t, a.marginContent, a), t;
271
274
  }
272
- function j(e, n) {
273
- switch (e) {
275
+ function A(t, e) {
276
+ switch (t) {
274
277
  case "top":
275
- return { x: 0, y: 0, width: n.pageWidth, height: n.margin.top };
278
+ return { x: 0, y: 0, width: e.pageWidth, height: e.margin.top };
276
279
  case "bottom":
277
280
  return {
278
281
  x: 0,
279
- y: n.pageHeight - n.margin.bottom,
280
- width: n.pageWidth,
281
- height: n.margin.bottom
282
+ y: e.pageHeight - e.margin.bottom,
283
+ width: e.pageWidth,
284
+ height: e.margin.bottom
282
285
  };
283
286
  case "left":
284
- return { x: 0, y: 0, width: n.margin.left, height: n.pageHeight };
287
+ return { x: 0, y: 0, width: e.margin.left, height: e.pageHeight };
285
288
  case "right":
286
289
  return {
287
- x: n.pageWidth - n.margin.right,
290
+ x: e.pageWidth - e.margin.right,
288
291
  y: 0,
289
- width: n.margin.right,
290
- height: n.pageHeight
292
+ width: e.margin.right,
293
+ height: e.pageHeight
291
294
  };
292
295
  }
293
296
  }
294
- async function D(e, n, a, t) {
295
- const i = document.createElement("div");
296
- Object.assign(i.style, {
297
+ async function B(t, e, a, n) {
298
+ const o = document.createElement("div");
299
+ Object.assign(o.style, {
297
300
  position: "fixed",
298
301
  left: "-99999px",
299
302
  top: "0",
300
- width: n + "mm",
303
+ width: e + "mm",
301
304
  height: a + "mm",
302
305
  overflow: "hidden"
303
- }), i.appendChild(e), document.body.appendChild(i);
306
+ }), o.appendChild(t), document.body.appendChild(o);
304
307
  try {
305
- return await P(i, {
306
- scale: t,
308
+ return await S(o, {
309
+ scale: n,
307
310
  backgroundColor: null
308
311
  });
309
312
  } finally {
310
- i.remove();
313
+ o.remove();
311
314
  }
312
315
  }
313
- const A = ["top", "right", "bottom", "left"];
314
- async function G(e, n, a) {
315
- const t = {};
316
- for (const i of A) {
317
- const o = e[i];
318
- if (o && typeof o != "function") {
319
- const s = j(i, n);
320
- t[i] = await D(
321
- o.cloneNode(!0),
322
- s.width,
323
- s.height,
316
+ const v = ["top", "right", "bottom", "left"];
317
+ async function G(t, e, a) {
318
+ const n = {};
319
+ for (const o of v) {
320
+ const i = t[o];
321
+ if (i && typeof i != "function") {
322
+ const r = A(o, e);
323
+ n[o] = await B(
324
+ i.cloneNode(!0),
325
+ r.width,
326
+ r.height,
324
327
  a
325
328
  );
326
329
  }
327
330
  }
328
- return t;
329
- }
330
- function X(e, n) {
331
- return e == null ? n.margin : typeof e == "number" ? { top: e, right: e, bottom: e, left: e } : {
332
- top: e.top ?? n.margin.top,
333
- right: e.right ?? n.margin.right,
334
- bottom: e.bottom ?? n.margin.bottom,
335
- left: e.left ?? n.margin.left
331
+ return n;
332
+ }
333
+ function et(t, e) {
334
+ return t == null ? e.margin : typeof t == "number" ? M(t) : {
335
+ top: t.top ?? e.margin.top,
336
+ right: t.right ?? e.margin.right,
337
+ bottom: t.bottom ?? e.margin.bottom,
338
+ left: t.left ?? e.margin.left
336
339
  };
337
340
  }
338
- const tt = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
339
- async function k(e, n, a, t, i, o, s, r, l = !1) {
340
- const g = document.createElement("div");
341
- Object.assign(g.style, {
341
+ const nt = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\u0590-\u05FF]/;
342
+ async function R(t, e, a, n, o, i, r, h, s = !1) {
343
+ const l = document.createElement("div");
344
+ Object.assign(l.style, {
342
345
  position: "fixed",
343
346
  left: "-99999px",
344
347
  top: "0",
345
- width: `${n}px`,
348
+ width: `${e}px`,
346
349
  height: `${a}px`,
347
350
  overflow: "hidden",
348
351
  whiteSpace: "nowrap",
349
- fontSize: `${t}px`,
350
- fontFamily: i,
351
- fontWeight: o,
352
- color: s,
352
+ fontSize: `${n}px`,
353
+ fontFamily: o,
354
+ fontWeight: i,
355
+ color: r,
353
356
  display: "flex",
354
357
  alignItems: "center",
355
- gap: `${r}px`,
356
- direction: l ? "rtl" : "ltr"
358
+ gap: `${h}px`,
359
+ direction: s ? "rtl" : "ltr"
357
360
  });
358
- const h = document.createElement("span");
359
- h.textContent = e, Object.assign(h.style, {
361
+ const c = document.createElement("span");
362
+ c.textContent = t, Object.assign(c.style, {
360
363
  position: "absolute",
361
364
  visibility: "hidden",
362
365
  whiteSpace: "nowrap",
363
- fontSize: `${t}px`,
364
- fontFamily: i,
365
- fontWeight: o
366
- }), document.body.appendChild(h);
367
- const d = h.offsetWidth;
368
- h.remove();
369
- const u = Math.ceil(n / (d + r)) + 2;
370
- for (let c = 0; c < u; c++) {
366
+ fontSize: `${n}px`,
367
+ fontFamily: o,
368
+ fontWeight: i
369
+ }), document.body.appendChild(c);
370
+ const d = c.offsetWidth;
371
+ c.remove();
372
+ const g = Math.ceil(e / (d + h)) + 2;
373
+ for (let u = 0; u < g; u++) {
371
374
  const f = document.createElement("span");
372
- f.textContent = e, f.style.flexShrink = "0", g.appendChild(f);
375
+ f.textContent = t, f.style.flexShrink = "0", l.appendChild(f);
373
376
  }
374
- document.body.appendChild(g);
377
+ document.body.appendChild(l);
375
378
  try {
376
- return await P(g, {
379
+ return await S(l, {
377
380
  scale: 3,
378
381
  backgroundColor: null,
379
- width: Math.ceil(n),
382
+ width: Math.ceil(e),
380
383
  height: Math.ceil(a)
381
384
  });
382
385
  } finally {
383
- g.remove();
386
+ l.remove();
384
387
  }
385
388
  }
386
- async function U(e, n, a, t, i, o, s) {
389
+ async function U(t, e, a, n, o, i, r) {
387
390
  const {
388
- text: r,
389
- color: l = "#000000",
390
- fontSize: g = 2.5,
391
- fontFamily: h = "Arial, sans-serif",
391
+ text: h,
392
+ color: s = "#000000",
393
+ fontSize: l = 2.5,
394
+ fontFamily: c = "Arial, sans-serif",
392
395
  fontWeight: d = "normal"
393
- } = n, u = g * a, c = (n.gap ?? g * 0.5) * a, f = u * 0.5, m = Math.ceil(u * 2.5), p = tt.test(r), y = Math.round(o - f * 2), w = Math.round(s - f * 2), [b, C] = await Promise.all([
394
- k(
395
- r,
396
+ } = e, g = l * a, u = (e.gap ?? l * 0.5) * a, f = g * 0.5, m = Math.ceil(g * 2.5), p = nt.test(h), y = Math.round(i - f * 2), b = Math.round(r - f * 2), [w, C] = await Promise.all([
397
+ R(
398
+ h,
396
399
  y,
397
400
  m,
398
- u,
399
- h,
400
- d,
401
- l,
401
+ g,
402
402
  c,
403
+ d,
404
+ s,
405
+ u,
403
406
  p
404
407
  ),
405
- k(
406
- r,
407
- w,
408
- m,
409
- u,
408
+ R(
410
409
  h,
411
- d,
412
- l,
410
+ b,
411
+ m,
412
+ g,
413
413
  c,
414
+ d,
415
+ s,
416
+ u,
414
417
  p
415
418
  )
416
- ]), x = Math.round(m / 2);
417
- e.drawImage(
418
- b,
419
+ ]), H = Math.round(m / 2);
420
+ t.drawImage(
421
+ w,
419
422
  0,
420
423
  0,
421
- b.width,
422
- b.height,
423
- t + f,
424
- i - x,
424
+ w.width,
425
+ w.height,
426
+ n + f,
427
+ o - H,
425
428
  y,
426
429
  m
427
- ), e.drawImage(
428
- b,
430
+ ), t.drawImage(
431
+ w,
429
432
  0,
430
433
  0,
431
- b.width,
432
- b.height,
433
- t + f,
434
- i + s - x,
434
+ w.width,
435
+ w.height,
436
+ n + f,
437
+ o + r - H,
435
438
  y,
436
439
  m
437
- ), e.save(), e.translate(t, i + s - f), e.rotate(-Math.PI / 2), e.drawImage(
440
+ ), t.save(), t.translate(n, o + r - f), t.rotate(-Math.PI / 2), t.drawImage(
438
441
  C,
439
442
  0,
440
443
  0,
441
444
  C.width,
442
445
  C.height,
443
446
  0,
444
- -x,
445
- w,
447
+ -H,
448
+ b,
446
449
  m
447
- ), e.restore(), e.save(), e.translate(t + o, i + f), e.rotate(Math.PI / 2), e.drawImage(
450
+ ), t.restore(), t.save(), t.translate(n + i, o + f), t.rotate(Math.PI / 2), t.drawImage(
448
451
  C,
449
452
  0,
450
453
  0,
451
454
  C.width,
452
455
  C.height,
453
456
  0,
454
- -x,
455
- w,
457
+ -H,
458
+ b,
456
459
  m
457
- ), e.restore();
460
+ ), t.restore();
458
461
  }
459
- function B(e, n) {
460
- return X(e.margin, n);
462
+ function W(t, e) {
463
+ return et(t.margin, e);
461
464
  }
462
- async function et(e, n, a, t, i, o, s, r) {
463
- for (const l of A) {
464
- const g = n[l];
465
- if (!g) continue;
466
- const h = j(l, t);
465
+ async function ot(t, e, a, n, o, i, r, h) {
466
+ for (const s of v) {
467
+ const l = e[s];
468
+ if (!l) continue;
469
+ const c = A(s, n);
467
470
  let d;
468
- typeof g == "function" ? d = await D(
469
- g(o, s),
470
- h.width,
471
- h.height,
472
- r
473
- ) : d = a[l], e.drawImage(
471
+ typeof l == "function" ? d = await B(
472
+ l(i, r),
473
+ c.width,
474
+ c.height,
475
+ h
476
+ ) : d = a[s], t.drawImage(
474
477
  d,
475
478
  0,
476
479
  0,
477
480
  d.width,
478
481
  d.height,
479
- Math.round(h.x * i),
480
- Math.round(h.y * i),
481
- Math.round(h.width * i),
482
- Math.round(h.height * i)
482
+ Math.round(c.x * o),
483
+ Math.round(c.y * o),
484
+ Math.round(c.width * o),
485
+ Math.round(c.height * o)
483
486
  );
484
487
  }
485
- if (n.contentBorder) {
486
- const { color: l = "#000000", width: g = 0.3 } = n.contentBorder, h = B(n.contentBorder, t);
487
- e.strokeStyle = l, e.lineWidth = g * i, e.strokeRect(
488
- Math.round(h.left * i),
489
- Math.round(h.top * i),
490
- Math.round((t.pageWidth - h.left - h.right) * i),
491
- Math.round((t.pageHeight - h.top - h.bottom) * i)
488
+ if (e.contentBorder) {
489
+ const { color: s = "#000000", width: l = 0.3 } = e.contentBorder, c = W(e.contentBorder, n);
490
+ t.strokeStyle = s, t.lineWidth = l * o, t.strokeRect(
491
+ Math.round(c.left * o),
492
+ Math.round(c.top * o),
493
+ Math.round((n.pageWidth - c.left - c.right) * o),
494
+ Math.round((n.pageHeight - c.top - c.bottom) * o)
492
495
  );
493
496
  }
494
- if (n.textBorder) {
495
- const l = B(n.textBorder, t);
497
+ if (e.textBorder) {
498
+ const s = W(e.textBorder, n);
496
499
  await U(
497
- e,
498
- n.textBorder,
499
- i,
500
- Math.round(l.left * i),
501
- Math.round(l.top * i),
502
- Math.round((t.pageWidth - l.left - l.right) * i),
503
- Math.round((t.pageHeight - l.top - l.bottom) * i)
500
+ t,
501
+ e.textBorder,
502
+ o,
503
+ Math.round(s.left * o),
504
+ Math.round(s.top * o),
505
+ Math.round((n.pageWidth - s.left - s.right) * o),
506
+ Math.round((n.pageHeight - s.top - s.bottom) * o)
504
507
  );
505
508
  }
506
509
  }
507
- async function at(e, n = {}) {
508
- const { imageFormat: a = "JPEG", imageQuality: t = 0.7, scale: i = 2 } = n, o = S(n), s = E(), r = F(e, o.pageWidth);
509
- r.style.opacity = "1", r.style.left = "-99999px", I(r);
510
- const l = N(r, o);
511
- L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
510
+ function q(t, e) {
511
+ const a = e.pageWidth - e.margin.left - e.margin.right, n = e.pageHeight - e.margin.top - e.margin.bottom, o = t.width, i = n / a * o, r = o / a;
512
+ return {
513
+ contentWidthMm: a,
514
+ contentHeightMm: n,
515
+ contentWidthPx: o,
516
+ contentHeightPx: i,
517
+ pxPerMm: r,
518
+ pageWidthPx: Math.round(e.pageWidth * r),
519
+ pageHeightPx: Math.round(e.pageHeight * r),
520
+ marginTopPx: Math.round(e.margin.top * r),
521
+ marginLeftPx: Math.round(e.margin.left * r)
522
+ };
523
+ }
524
+ function $(t, e, a) {
525
+ const n = Math.min(
526
+ a.contentHeightPx,
527
+ t.height - e * a.contentHeightPx
528
+ ), o = document.createElement("canvas");
529
+ o.width = a.pageWidthPx, o.height = a.pageHeightPx;
530
+ const i = o.getContext("2d");
531
+ if (!i) throw new Error("Could not get canvas context");
532
+ return i.fillStyle = "#ffffff", i.fillRect(0, 0, a.pageWidthPx, a.pageHeightPx), i.drawImage(
533
+ t,
534
+ 0,
535
+ e * a.contentHeightPx,
536
+ a.contentWidthPx,
537
+ n,
538
+ a.marginLeftPx,
539
+ a.marginTopPx,
540
+ a.contentWidthPx,
541
+ n
542
+ ), { canvas: o, ctx: i };
543
+ }
544
+ async function z(t, e) {
545
+ const a = P(), n = N(t, e.pageWidth);
546
+ n.style.opacity = "1", n.style.left = "-99999px", T(n);
547
+ const o = E(n, e);
548
+ return I(n, o.pageContentPx), k(n, o.pageContentPx), j(n, o.pageContentPx), await K(n), {
549
+ clone: n,
550
+ layout: o,
551
+ cleanup: () => {
552
+ n.remove(), a();
553
+ }
554
+ };
555
+ }
556
+ async function st(t, e = {}) {
557
+ const { imageFormat: a = "JPEG", imageQuality: n = 0.7, scale: o = 2 } = e, i = x(e), { clone: r, cleanup: h } = await z(t, i);
512
558
  try {
513
- const g = await P(r, {
514
- scale: i,
559
+ const s = await S(r, {
560
+ scale: o,
515
561
  backgroundColor: "#ffffff"
516
- }), { jsPDF: h } = await import("jspdf"), d = o.pageWidth - o.margin.left - o.margin.right, u = o.pageHeight - o.margin.top - o.margin.bottom, c = g.width, f = u / d * c, m = Math.ceil(g.height / f), p = o.pageWidth > o.pageHeight ? "l" : "p", y = new h({
517
- orientation: p,
562
+ }), { jsPDF: l } = await import("jspdf"), c = q(s, i), d = Math.ceil(s.height / c.contentHeightPx), g = i.pageWidth > i.pageHeight ? "l" : "p", u = new l({
563
+ orientation: g,
518
564
  unit: "mm",
519
- format: [o.pageWidth, o.pageHeight]
520
- }), w = c / d, b = Math.round(o.pageWidth * w), C = Math.round(o.pageHeight * w), x = Math.round(o.margin.top * w), R = Math.round(o.margin.left * w);
521
- for (let H = 0; H < m; H++) {
522
- const M = Math.min(
523
- f,
524
- g.height - H * f
525
- ), W = document.createElement("canvas");
526
- W.width = b, W.height = C;
527
- const v = W.getContext("2d");
528
- if (!v) throw new Error("Could not get canvas context");
529
- v.fillStyle = "#ffffff", v.fillRect(0, 0, b, C), v.drawImage(
530
- g,
531
- 0,
532
- H * f,
533
- c,
534
- M,
535
- R,
536
- x,
537
- c,
538
- M
539
- );
540
- const z = W.toDataURL(
565
+ format: [i.pageWidth, i.pageHeight]
566
+ });
567
+ for (let f = 0; f < d; f++) {
568
+ const { canvas: m, ctx: p } = $(s, f, c), y = m.toDataURL(
541
569
  `image/${a.toLowerCase()}`,
542
- t
570
+ n
543
571
  );
544
- H > 0 && y.addPage([o.pageWidth, o.pageHeight], p), y.addImage(
545
- z,
572
+ f > 0 && u.addPage([i.pageWidth, i.pageHeight], g), u.addImage(
573
+ y,
546
574
  a,
547
575
  0,
548
576
  0,
549
- o.pageWidth,
550
- o.pageHeight,
577
+ i.pageWidth,
578
+ i.pageHeight,
551
579
  void 0,
552
580
  "SLOW"
553
581
  );
554
582
  }
555
- return n.marginContent && await $(y, n.marginContent, n), y;
583
+ return e.marginContent && await _(u, e.marginContent, e), u;
556
584
  } finally {
557
- r.remove(), s();
585
+ h();
558
586
  }
559
587
  }
560
- async function nt(e, n = {}) {
561
- const { imageFormat: a = "PNG", imageQuality: t = 0.75, scale: i = 2 } = n, o = S(n), s = E(), r = F(e, o.pageWidth);
562
- r.style.opacity = "1", r.style.left = "-99999px", I(r);
563
- const l = N(r, o);
564
- L(r, l.pageContentPx), O(r, l.pageContentPx), T(r, l.pageContentPx), await q(r);
588
+ async function at(t, e = {}) {
589
+ const { imageFormat: a = "PNG", imageQuality: n = 0.75, scale: o = 2 } = e, i = x(e), { clone: r, cleanup: h } = await z(t, i);
565
590
  try {
566
- const g = await P(r, {
567
- scale: i,
591
+ const s = await S(r, {
592
+ scale: o,
568
593
  backgroundColor: "#ffffff"
569
- }), h = o.pageWidth - o.margin.left - o.margin.right, d = o.pageHeight - o.margin.top - o.margin.bottom, u = g.width, c = d / h * u, f = u / h, m = Math.round(o.pageWidth * f), p = Math.round(o.pageHeight * f), y = Math.round(o.margin.top * f), w = Math.round(o.margin.left * f), b = Math.ceil(g.height / c), C = [], { marginContent: x } = n, R = x ? await G(x, o, i) : {};
570
- for (let H = 0; H < b; H++) {
571
- const M = Math.min(
572
- c,
573
- g.height - H * c
574
- ), W = document.createElement("canvas");
575
- W.width = m, W.height = p;
576
- const v = W.getContext("2d");
577
- if (!v) throw new Error("Could not get canvas context");
578
- v.fillStyle = "#ffffff", v.fillRect(0, 0, m, p), v.drawImage(
594
+ }), l = q(s, i), c = Math.ceil(s.height / l.contentHeightPx), d = [], { marginContent: g } = e, u = g ? await G(g, i, o) : {};
595
+ for (let f = 0; f < c; f++) {
596
+ const { canvas: m, ctx: p } = $(s, f, l);
597
+ g && await ot(
598
+ p,
579
599
  g,
580
- 0,
581
- H * c,
582
- u,
583
- M,
584
- w,
585
- y,
586
600
  u,
587
- M
588
- ), x && await et(
589
- v,
590
- x,
591
- R,
592
- o,
593
- f,
594
- H + 1,
595
- b,
596
- i
597
- ), C.push(
598
- W.toDataURL(
601
+ i,
602
+ l.pxPerMm,
603
+ f + 1,
604
+ c,
605
+ o
606
+ ), d.push(
607
+ m.toDataURL(
599
608
  `image/${a.toLowerCase()}`,
600
- t
609
+ n
601
610
  )
602
611
  );
603
612
  }
604
- return C;
613
+ return d;
605
614
  } finally {
606
- r.remove(), s();
615
+ h();
607
616
  }
608
617
  }
609
- async function rt(e, n, a = {}) {
610
- const t = S(a), i = await nt(e, a);
611
- n.innerHTML = "", Object.assign(n.style, {
618
+ async function ct(t, e, a = {}) {
619
+ const n = x(a), o = await at(t, a);
620
+ e.innerHTML = "", Object.assign(e.style, {
612
621
  direction: "ltr",
613
622
  width: "fit-content",
614
- height: t.pageHeight + "mm",
623
+ height: n.pageHeight + "mm",
615
624
  maxHeight: "100vh",
616
- overflowY: i.length > 1 ? "auto" : "hidden",
625
+ overflowY: o.length > 1 ? "auto" : "hidden",
617
626
  background: "#e0e0e0"
618
627
  });
619
- for (let o = 0; o < i.length; o++) {
620
- const s = document.createElement("img");
621
- s.src = i[o], s.alt = `Page ${o + 1}`, Object.assign(s.style, {
622
- width: t.pageWidth + "mm",
628
+ for (let i = 0; i < o.length; i++) {
629
+ const r = document.createElement("img");
630
+ r.src = o[i], r.alt = `Page ${i + 1}`, Object.assign(r.style, {
631
+ width: n.pageWidth + "mm",
623
632
  maxWidth: "100%",
624
633
  height: "auto",
625
634
  boxSizing: "border-box",
626
635
  border: "1px solid #bbb",
627
636
  boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
628
637
  marginBottom: "16px"
629
- }), s.style.setProperty("display", "inline", "important"), n.appendChild(s);
638
+ }), r.style.setProperty("display", "inline", "important"), e.appendChild(r);
630
639
  }
631
640
  }
632
- async function $(e, n, a = {}) {
633
- const t = S(a), i = e.getNumberOfPages(), o = 4, s = o * (96 / 25.4), r = E(), l = Math.round(t.pageWidth * s), g = Math.round(t.pageHeight * s), h = await G(n, t, o), d = {};
634
- for (const c of A)
635
- h[c] && (d[c] = h[c].toDataURL("image/png"));
636
- let u;
637
- if (n.textBorder) {
638
- const c = document.createElement("canvas");
639
- c.width = l, c.height = g;
640
- const f = c.getContext("2d");
641
+ async function _(t, e, a = {}) {
642
+ const n = x(a), o = t.getNumberOfPages(), i = 4, r = i * (96 / 25.4), h = P(), s = Math.round(n.pageWidth * r), l = Math.round(n.pageHeight * r), c = await G(e, n, i), d = {};
643
+ for (const u of v)
644
+ c[u] && (d[u] = c[u].toDataURL("image/png"));
645
+ let g;
646
+ if (e.textBorder) {
647
+ const u = document.createElement("canvas");
648
+ u.width = s, u.height = l;
649
+ const f = u.getContext("2d");
641
650
  if (f) {
642
- const m = B(n.textBorder, t);
651
+ const m = W(e.textBorder, n);
643
652
  await U(
644
653
  f,
645
- n.textBorder,
646
- s,
647
- Math.round(m.left * s),
648
- Math.round(m.top * s),
649
- Math.round((t.pageWidth - m.left - m.right) * s),
650
- Math.round((t.pageHeight - m.top - m.bottom) * s)
651
- ), u = c.toDataURL("image/png");
654
+ e.textBorder,
655
+ r,
656
+ Math.round(m.left * r),
657
+ Math.round(m.top * r),
658
+ Math.round((n.pageWidth - m.left - m.right) * r),
659
+ Math.round((n.pageHeight - m.top - m.bottom) * r)
660
+ ), g = u.toDataURL("image/png");
652
661
  }
653
662
  }
654
- for (let c = 1; c <= i; c++) {
655
- e.setPage(c);
656
- for (const f of A) {
657
- const m = n[f];
663
+ for (let u = 1; u <= o; u++) {
664
+ t.setPage(u);
665
+ for (const f of v) {
666
+ const m = e[f];
658
667
  if (!m) continue;
659
- const p = j(f, t);
660
- let y, w;
661
- typeof m == "function" ? y = (await D(
662
- m(c, i),
668
+ const p = A(f, n);
669
+ let y, b;
670
+ typeof m == "function" ? y = (await B(
671
+ m(u, o),
663
672
  p.width,
664
673
  p.height,
665
- o
666
- )).toDataURL("image/png") : (y = d[f], w = `margin-${f}`), e.addImage(
674
+ i
675
+ )).toDataURL("image/png") : (y = d[f], b = `margin-${f}`), t.addImage(
667
676
  y,
668
677
  "PNG",
669
678
  p.x,
670
679
  p.y,
671
680
  p.width,
672
681
  p.height,
673
- w,
682
+ b,
674
683
  "SLOW"
675
684
  );
676
685
  }
677
- if (n.contentBorder) {
678
- const { color: f = "#000000", width: m = 0.3 } = n.contentBorder, p = B(n.contentBorder, t);
679
- e.setDrawColor(f), e.setLineWidth(m), e.rect(
686
+ if (e.contentBorder) {
687
+ const { color: f = "#000000", width: m = 0.3 } = e.contentBorder, p = W(e.contentBorder, n);
688
+ t.setDrawColor(f), t.setLineWidth(m), t.rect(
680
689
  p.left,
681
690
  p.top,
682
- t.pageWidth - p.left - p.right,
683
- t.pageHeight - p.top - p.bottom
691
+ n.pageWidth - p.left - p.right,
692
+ n.pageHeight - p.top - p.bottom
684
693
  );
685
694
  }
686
- u && e.addImage(
687
- u,
695
+ g && t.addImage(
696
+ g,
688
697
  "PNG",
689
698
  0,
690
699
  0,
691
- t.pageWidth,
692
- t.pageHeight,
700
+ n.pageWidth,
701
+ n.pageHeight,
693
702
  "text-border",
694
703
  "SLOW"
695
704
  );
696
705
  }
697
- return r(), e;
706
+ return h(), t;
698
707
  }
699
708
  export {
700
- J as PAGE_MARGINS,
701
- _ as PAGE_SIZES,
702
- $ as addMarginContent,
703
- N as computeLayout,
704
- F as createPrintClone,
705
- T as insertPageBreakSpacers,
706
- I as normalizeTableAttributes,
707
- Y as prepare,
708
- rt as previewPageImages,
709
- it as renderHTML,
710
- at as renderImagePDF,
711
- nt as renderPageImages,
712
- L as splitOversizedTables,
713
- O as splitOversizedText
709
+ Q as PAGE_MARGINS,
710
+ J as PAGE_SIZES,
711
+ st as generateImagePDF,
712
+ at as generateImages,
713
+ rt as generatePDF,
714
+ ct as previewImages
714
715
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspdf-utils",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
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",