jspdf-md-renderer 3.1.0 → 3.3.0

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.
package/dist/index.mjs CHANGED
@@ -1,23 +1,90 @@
1
- import { marked as R } from "marked";
2
- import A from "jspdf-autotable";
1
+ import { marked as j } from "marked";
2
+ import O from "jspdf-autotable";
3
3
  var u = /* @__PURE__ */ ((t) => (t.Heading = "heading", t.Paragraph = "paragraph", t.List = "list", t.ListItem = "list_item", t.Blockquote = "blockquote", t.Code = "code", t.CodeSpan = "codespan", t.Table = "table", t.Html = "html", t.Hr = "hr", t.Image = "image", t.Link = "link", t.Strong = "strong", t.Em = "em", t.TableHeader = "table_header", t.TableCell = "table_cell", t.Raw = "raw", t.Text = "text", t))(u || {});
4
- const j = async (t) => {
5
- const n = await R.lexer(t, { async: !0, gfm: !0 });
6
- return W(n);
4
+ const D = "__jmr_", q = /(!\[[^\]]*\]\()([^)]+)(\))\s*\{([^}]+)\}/g, U = /(\w+)\s*=\s*(\w+)/g, R = ["left", "center", "right"], Q = (t) => {
5
+ const e = [];
6
+ return t.width !== void 0 && e.push(`w=${t.width}`), t.height !== void 0 && e.push(`h=${t.height}`), t.align && e.push(`a=${t.align}`), e.length > 0 ? `#${D}${e.join("&")}` : "";
7
+ }, V = (t) => {
8
+ const e = {};
9
+ let i;
10
+ for (; (i = U.exec(t)) !== null; ) {
11
+ const r = i[1].toLowerCase(), h = i[2];
12
+ switch (r) {
13
+ case "width":
14
+ case "w": {
15
+ const o = parseInt(h, 10);
16
+ !isNaN(o) && o > 0 && (e.width = o);
17
+ break;
18
+ }
19
+ case "height":
20
+ case "h": {
21
+ const o = parseInt(h, 10);
22
+ !isNaN(o) && o > 0 && (e.height = o);
23
+ break;
24
+ }
25
+ case "align": {
26
+ const o = h.toLowerCase();
27
+ R.includes(
28
+ o
29
+ ) && (e.align = o);
30
+ break;
31
+ }
32
+ }
33
+ }
34
+ return e;
35
+ }, Z = (t) => t.replace(
36
+ q,
37
+ (e, i, r, h, o) => {
38
+ const l = V(o), a = Q(l);
39
+ return `${i}${r}${a}${h}`;
40
+ }
41
+ ), K = (t) => {
42
+ const e = t.indexOf(`#${D}`);
43
+ if (e === -1)
44
+ return { cleanHref: t, attrs: {} };
45
+ const i = t.substring(0, e), r = t.substring(e + 1 + D.length), h = {}, o = r.split("&");
46
+ for (const l of o) {
47
+ const [a, s] = l.split("=");
48
+ switch (a) {
49
+ case "w": {
50
+ const g = parseInt(s, 10);
51
+ !isNaN(g) && g > 0 && (h.width = g);
52
+ break;
53
+ }
54
+ case "h": {
55
+ const g = parseInt(s, 10);
56
+ !isNaN(g) && g > 0 && (h.height = g);
57
+ break;
58
+ }
59
+ case "a": {
60
+ R.includes(
61
+ s
62
+ ) && (h.align = s);
63
+ break;
64
+ }
65
+ }
66
+ }
67
+ return { cleanHref: i, attrs: h };
68
+ }, M = async (t) => {
69
+ const e = Z(t), i = await j.lexer(e, {
70
+ async: !0,
71
+ gfm: !0
72
+ });
73
+ return W(i);
7
74
  }, W = (t) => {
8
- const n = [];
9
- return t.forEach((s) => {
75
+ const e = [];
76
+ return t.forEach((i) => {
10
77
  try {
11
- const g = O[s.type];
12
- g ? n.push(g(s)) : n.push({
78
+ const r = tt[i.type];
79
+ r ? e.push(r(i)) : e.push({
13
80
  type: u.Raw,
14
- content: s.raw
81
+ content: i.raw
15
82
  });
16
- } catch (g) {
17
- console.error("Failed to handle token ==>", s, g);
83
+ } catch (r) {
84
+ console.error("Failed to handle token ==>", i, r);
18
85
  }
19
- }), n;
20
- }, O = {
86
+ }), e;
87
+ }, tt = {
21
88
  [u.Heading]: (t) => ({
22
89
  type: u.Heading,
23
90
  depth: t.depth,
@@ -47,22 +114,28 @@ const j = async (t) => {
47
114
  }),
48
115
  [u.Table]: (t) => ({
49
116
  type: u.Table,
50
- header: t.header.map((n) => ({
117
+ header: t.header.map((e) => ({
51
118
  type: u.TableHeader,
52
- content: n.text
119
+ content: e.text
53
120
  })),
54
121
  rows: t.rows.map(
55
- (n) => n.map((s) => ({
122
+ (e) => e.map((i) => ({
56
123
  type: u.TableCell,
57
- content: s.text
124
+ content: i.text
58
125
  }))
59
126
  )
60
127
  }),
61
- [u.Image]: (t) => ({
62
- type: u.Image,
63
- src: t.href,
64
- alt: t.text
65
- }),
128
+ [u.Image]: (t) => {
129
+ const { cleanHref: e, attrs: i } = K(t.href);
130
+ return {
131
+ type: u.Image,
132
+ src: e,
133
+ alt: t.text,
134
+ width: i.width,
135
+ height: i.height,
136
+ align: i.align
137
+ };
138
+ },
66
139
  [u.Link]: (t) => ({
67
140
  type: u.Link,
68
141
  href: t.href,
@@ -99,15 +172,15 @@ const j = async (t) => {
99
172
  content: t.text,
100
173
  items: t.tokens ? W(t.tokens) : []
101
174
  })
102
- }, H = class H {
103
- static initialize(n) {
104
- this.options_ = n, this.cursor = { x: n.cursor.x, y: n.cursor.y }, this.lastContentY_ = n.cursor.y;
175
+ }, I = class I {
176
+ static initialize(e) {
177
+ this.options_ = e, this.cursor = { x: e.cursor.x, y: e.cursor.y }, this.lastContentY_ = e.cursor.y;
105
178
  }
106
179
  static getCursor() {
107
180
  return this.cursor;
108
181
  }
109
- static setCursor(n) {
110
- this.cursor = n;
182
+ static setCursor(e) {
183
+ this.cursor = e;
111
184
  }
112
185
  static get options() {
113
186
  return this.options_;
@@ -127,8 +200,8 @@ const j = async (t) => {
127
200
  * @param operation 'set' to assign a new value, 'add' to increment the current value.
128
201
  * @default operation = 'set'
129
202
  */
130
- static updateX(n, s = "set") {
131
- s === "set" ? this.cursor.x = n : s === "add" && (this.cursor.x += n);
203
+ static updateX(e, i = "set") {
204
+ i === "set" ? this.cursor.x = e : i === "add" && (this.cursor.x += e);
132
205
  }
133
206
  /**
134
207
  * Updates the y pointer of the cursor.
@@ -136,8 +209,8 @@ const j = async (t) => {
136
209
  * @param operation 'set' to assign a new value, 'add' to increment the current value.
137
210
  * @default operation = 'set'
138
211
  */
139
- static updateY(n, s = "set") {
140
- s === "set" ? this.cursor.y = n : s === "add" && (this.cursor.y += n);
212
+ static updateY(e, i = "set") {
213
+ i === "set" ? this.cursor.y = e : i === "add" && (this.cursor.y += e);
141
214
  }
142
215
  /**
143
216
  * Records a Y position as the bottom of rendered content.
@@ -145,8 +218,8 @@ const j = async (t) => {
145
218
  * where their actual text content ends, ignoring any trailing margins.
146
219
  * @param specificY Optional Y value to record. Defaults to current cursor Y.
147
220
  */
148
- static recordContentY(n) {
149
- this.lastContentY_ = n !== void 0 ? n : this.cursor.y;
221
+ static recordContentY(e) {
222
+ this.lastContentY_ = e !== void 0 ? e : this.cursor.y;
150
223
  }
151
224
  /**
152
225
  * Gets the last Y position recorded as content bottom.
@@ -162,75 +235,192 @@ const j = async (t) => {
162
235
  return this.cursor.y;
163
236
  }
164
237
  };
165
- H.cursor = { x: 0, y: 0 }, H.lastContentY_ = 0, H.inlineLock = !1;
166
- let e = H;
167
- const b = (t) => t.getTextDimensions("H").h * e.options.page.defaultLineHeightFactor, y = (t) => t.getTextDimensions("H").w * e.options.page.defaultLineHeightFactor, q = (t, n, s, g) => {
168
- const c = 6 - (n?.depth ?? 0) > 0 ? 6 - (n?.depth ?? 0) : 1;
169
- if (t.setFontSize(e.options.page.defaultFontSize + c), n?.items && n?.items.length > 0)
170
- for (const l of n?.items ?? [])
171
- g(l, s, !1);
238
+ I.cursor = { x: 0, y: 0 }, I.lastContentY_ = 0, I.inlineLock = !1;
239
+ let n = I;
240
+ const C = (t) => t.getTextDimensions("H").h * n.options.page.defaultLineHeightFactor, y = (t) => t.getTextDimensions("H").w * n.options.page.defaultLineHeightFactor, et = (t, e, i, r) => {
241
+ const h = 6 - (e?.depth ?? 0) > 0 ? 6 - (e?.depth ?? 0) : 1;
242
+ if (t.setFontSize(n.options.page.defaultFontSize + h), e?.items && e?.items.length > 0)
243
+ for (const o of e?.items ?? [])
244
+ r(o, i, !1);
172
245
  else {
173
- const l = b(t);
246
+ const o = C(t);
174
247
  t.text(
175
- n?.content ?? "",
176
- e.X + s,
177
- e.Y,
248
+ e?.content ?? "",
249
+ n.X + i,
250
+ n.Y,
178
251
  {
179
252
  align: "left",
180
- maxWidth: e.options.page.maxContentWidth - s,
253
+ maxWidth: n.options.page.maxContentWidth - i,
181
254
  baseline: "top"
182
255
  }
183
- ), e.recordContentY(e.Y + l), e.updateY(l, "add");
256
+ ), n.recordContentY(n.Y + o), n.updateY(o, "add");
257
+ }
258
+ t.setFontSize(n.options.page.defaultFontSize), n.updateX(n.options.page.xpading, "set");
259
+ }, Y = (t) => {
260
+ typeof n.options.pageBreakHandler == "function" ? n.options.pageBreakHandler(t) : t.addPage(
261
+ n.options.page?.format,
262
+ n.options.page?.orientation
263
+ ), n.updateY(n.options.page.topmargin), n.updateX(n.options.page.xpading);
264
+ }, z = 96, k = (t, e = "mm") => {
265
+ switch (e) {
266
+ case "pt":
267
+ return t * 72 / z;
268
+ case "in":
269
+ return t / z;
270
+ case "px":
271
+ return t;
272
+ default:
273
+ return t * 25.4 / z;
274
+ }
275
+ }, G = (t) => {
276
+ try {
277
+ let e = "";
278
+ if (t.includes("base64,")) {
279
+ const a = t.split("base64,")[1];
280
+ typeof window < "u" && typeof window.atob == "function" ? e = decodeURIComponent(escape(window.atob(a))) : typeof Buffer < "u" ? e = Buffer.from(a, "base64").toString("utf-8") : e = decodeURIComponent(escape(atob(a)));
281
+ } else
282
+ e = decodeURIComponent(t.split(",")[1] || "");
283
+ const i = e.match(
284
+ /<svg[^>]*\swidth=(?:'|")([0-9.]+)[a-zA-Z]*(?:'|")/i
285
+ ), r = e.match(
286
+ /<svg[^>]*\sheight=(?:'|")([0-9.]+)[a-zA-Z]*(?:'|")/i
287
+ ), h = e.match(
288
+ /<svg[^>]*\sviewBox=(?:'|")[^'"]*(?:'|")/i
289
+ );
290
+ let o = i ? parseFloat(i[1]) : 0, l = r ? parseFloat(r[1]) : 0;
291
+ if ((!o || !l) && h) {
292
+ const a = h[0].match(
293
+ /viewBox=(?:'|")([^'"]+)(?:'|")/i
294
+ );
295
+ if (a) {
296
+ const s = a[1].split(/[ ,]+/).filter(Boolean).map(parseFloat);
297
+ s.length >= 4 && (o = o || s[2], l = l || s[3]);
298
+ }
299
+ }
300
+ if (o > 0 && l > 0) return { width: o, height: l };
301
+ } catch (e) {
302
+ console.warn("Failed to extract SVG dimensions:", e);
303
+ }
304
+ return null;
305
+ }, _ = (t, e, i, r, h = "mm") => {
306
+ if (!e.data)
307
+ return { finalWidth: 0, finalHeight: 0 };
308
+ let o = e.naturalWidth || 0, l = e.naturalHeight || 0;
309
+ if (!o || !l)
310
+ if (e.data.startsWith("data:image/svg")) {
311
+ const c = G(e.data);
312
+ c && (o = c.width, l = c.height);
313
+ } else
314
+ try {
315
+ const c = t.getImageProperties(e.data);
316
+ o = c.width, l = c.height;
317
+ } catch (c) {
318
+ console.warn(
319
+ "Failed to get image properties for intrinsic sizing:",
320
+ c
321
+ );
322
+ }
323
+ const a = l > 0 ? o / l : 1;
324
+ let s, g;
325
+ if (e.width && e.height ? (s = k(e.width, h), g = k(e.height, h)) : e.width ? (s = k(e.width, h), g = s / a) : e.height ? (g = k(e.height, h), s = g * a) : (s = k(o, h), g = k(l, h)), s > i) {
326
+ const c = i / s;
327
+ s = i, g = g * c;
328
+ }
329
+ if (g > r) {
330
+ const c = r / g;
331
+ g = r, s = s * c;
332
+ }
333
+ return { finalWidth: s, finalHeight: g };
334
+ }, $ = async (t) => {
335
+ for (const e of t) {
336
+ if (e.type === u.Image && e.src)
337
+ try {
338
+ if (e.src.startsWith("data:"))
339
+ e.data = e.src;
340
+ else {
341
+ const i = await fetch(e.src);
342
+ if (!i.ok)
343
+ throw new Error(
344
+ `Failed to fetch image: ${i.statusText}`
345
+ );
346
+ const r = await i.blob(), h = await new Promise(
347
+ (o, l) => {
348
+ const a = new FileReader();
349
+ a.onloadend = () => {
350
+ typeof a.result == "string" ? o(a.result) : l(
351
+ new Error(
352
+ "Failed to convert image to base64 string"
353
+ )
354
+ );
355
+ }, a.onerror = l, a.readAsDataURL(r);
356
+ }
357
+ );
358
+ e.data = h;
359
+ }
360
+ e.data && e.data.startsWith("data:image/svg") && typeof window < "u" && typeof document < "u" && (e.data = await new Promise((i) => {
361
+ const r = new Image();
362
+ r.onload = () => {
363
+ const h = document.createElement("canvas"), o = G(
364
+ e.data
365
+ ), l = o ? o.width : r.width || 300, a = o ? o.height : r.height || 150;
366
+ e.naturalWidth = l, e.naturalHeight = a;
367
+ const s = 4;
368
+ h.width = l * s, h.height = a * s;
369
+ const g = h.getContext("2d");
370
+ g ? (g.scale(s, s), g.drawImage(r, 0, 0, l, a), i(h.toDataURL("image/png"))) : i(e.data);
371
+ }, r.onerror = () => i(e.data), r.src = e.data;
372
+ }));
373
+ } catch (i) {
374
+ console.warn(
375
+ `[jspdf-md-renderer] Warning: Failed to load image at ${e.src}. It will be skipped.`,
376
+ i
377
+ );
378
+ }
379
+ e.items && e.items.length > 0 && await $(e.items);
184
380
  }
185
- t.setFontSize(e.options.page.defaultFontSize), e.updateX(e.options.page.xpading, "set");
186
- }, w = (t) => {
187
- typeof e.options.pageBreakHandler == "function" ? e.options.pageBreakHandler(t) : t.addPage(
188
- e.options.page?.format,
189
- e.options.page?.orientation
190
- ), e.updateY(e.options.page.topmargin), e.updateX(e.options.page.xpading);
191
381
  };
192
- class E {
382
+ class A {
193
383
  // Default codespan styling (can be overridden via RenderStore.options.codespan)
194
384
  static getCodespanOptions() {
195
- const n = e.options.codespan ?? {};
385
+ const e = n.options.codespan ?? {};
196
386
  return {
197
- backgroundColor: n.backgroundColor ?? "#EEEEEE",
198
- padding: n.padding ?? 0.5,
199
- showBackground: n.showBackground !== !1,
200
- fontSizeScale: n.fontSizeScale ?? 0.9
387
+ backgroundColor: e.backgroundColor ?? "#EEEEEE",
388
+ padding: e.padding ?? 0.5,
389
+ showBackground: e.showBackground !== !1,
390
+ fontSizeScale: e.fontSizeScale ?? 0.9
201
391
  };
202
392
  }
203
393
  /**
204
394
  * Apply font style to the jsPDF document.
205
395
  */
206
- static applyStyle(n, s) {
207
- const g = n.getFont().fontName, c = n.getFontSize(), l = () => {
208
- const i = e.options.font.bold?.name;
209
- return i && i !== "" ? i : g;
210
- }, r = () => {
211
- const i = e.options.font.regular?.name;
212
- return i && i !== "" ? i : g;
396
+ static applyStyle(e, i) {
397
+ const r = e.getFont().fontName, h = e.getFontSize(), o = () => {
398
+ const a = n.options.font.bold?.name;
399
+ return a && a !== "" ? a : r;
400
+ }, l = () => {
401
+ const a = n.options.font.regular?.name;
402
+ return a && a !== "" ? a : r;
213
403
  };
214
- switch (s) {
404
+ switch (i) {
215
405
  case "bold":
216
- n.setFont(
217
- l(),
218
- e.options.font.bold?.style || "bold"
406
+ e.setFont(
407
+ o(),
408
+ n.options.font.bold?.style || "bold"
219
409
  );
220
410
  break;
221
411
  case "italic":
222
- n.setFont(r(), "italic");
412
+ e.setFont(l(), "italic");
223
413
  break;
224
414
  case "bolditalic":
225
- n.setFont(l(), "bolditalic");
415
+ e.setFont(o(), "bolditalic");
226
416
  break;
227
417
  case "codespan":
228
- n.setFont("courier", "normal"), n.setFontSize(
229
- c * this.getCodespanOptions().fontSizeScale
418
+ e.setFont("courier", "normal"), e.setFontSize(
419
+ h * this.getCodespanOptions().fontSizeScale
230
420
  );
231
421
  break;
232
422
  default:
233
- n.setFont(r(), n.getFont().fontStyle);
423
+ e.setFont(l(), e.getFont().fontStyle);
234
424
  break;
235
425
  }
236
426
  }
@@ -239,60 +429,79 @@ class E {
239
429
  * NOTE: jsPDF's getTextWidth() does NOT include charSpace in its calculation,
240
430
  * so we must manually add it: effectiveWidth = getTextWidth(text) + (text.length * charSpace)
241
431
  */
242
- static measureWordWidth(n, s, g) {
243
- const c = n.getFont(), l = n.getFontSize();
244
- this.applyStyle(n, g);
245
- const r = n.getTextWidth(s), i = n.getCharSpace?.() ?? 0, a = r + s.length * i;
246
- return n.setFont(c.fontName, c.fontStyle), n.setFontSize(l), a;
432
+ static measureWordWidth(e, i, r) {
433
+ const h = e.getFont(), o = e.getFontSize();
434
+ this.applyStyle(e, r);
435
+ const l = e.getTextWidth(i), a = e.getCharSpace?.() ?? 0, s = l + i.length * a;
436
+ return e.setFont(h.fontName, h.fontStyle), e.setFontSize(o), s;
247
437
  }
248
438
  /**
249
439
  * Extract style from element type string.
250
440
  */
251
- static getStyleFromType(n, s) {
252
- switch (n) {
441
+ static getStyleFromType(e, i) {
442
+ switch (e) {
253
443
  case "strong":
254
- return s === "italic" ? "bolditalic" : "bold";
444
+ return i === "italic" ? "bolditalic" : "bold";
255
445
  case "em":
256
- return s === "bold" ? "bolditalic" : "italic";
446
+ return i === "bold" ? "bolditalic" : "italic";
257
447
  case "codespan":
258
448
  return "codespan";
259
449
  default:
260
- return s || "normal";
450
+ return i || "normal";
261
451
  }
262
452
  }
263
453
  /**
264
454
  * Flatten ParsedElement tree into an array of StyledWordInfo.
265
455
  * Handles nested inline elements.
266
456
  */
267
- static flattenToWords(n, s, g = "normal", c = !1, l) {
268
- const r = [];
269
- for (const i of s) {
270
- const a = this.getStyleFromType(i.type, g), h = i.type === "link" || c, p = i.href || l;
271
- if (i.items && i.items.length > 0) {
457
+ static flattenToWords(e, i, r = "normal", h = !1, o) {
458
+ const l = [];
459
+ for (const a of i) {
460
+ const s = this.getStyleFromType(a.type, r), g = a.type === "link" || h, c = a.href || o;
461
+ if (a.items && a.items.length > 0) {
272
462
  const f = this.flattenToWords(
273
- n,
274
- i.items,
463
+ e,
464
+ a.items,
465
+ s,
466
+ g,
467
+ c
468
+ );
469
+ l.push(...f);
470
+ } else if (a.type === "image") {
471
+ const f = n.options.page.maxContentHeight - n.options.page.topmargin, d = n.options.page.maxContentWidth - n.options.page.indent * 0, p = n.options.page.unit || "mm", { finalWidth: m, finalHeight: x } = _(
472
+ e,
275
473
  a,
276
- h,
474
+ d,
475
+ f,
277
476
  p
278
477
  );
279
- r.push(...f);
478
+ l.push({
479
+ text: "",
480
+ width: m,
481
+ style: s,
482
+ isLink: g,
483
+ href: c,
484
+ linkColor: g ? n.options.link?.linkColor || [0, 0, 255] : void 0,
485
+ isImage: !0,
486
+ imageElement: a,
487
+ imageHeight: x
488
+ });
280
489
  } else {
281
- const f = i.content || i.text || "";
490
+ const f = a.content || a.text || "";
282
491
  if (!f) continue;
283
- if (a === "codespan") {
284
- const o = f.trim();
285
- o && r.push({
286
- text: o,
492
+ if (s === "codespan") {
493
+ const p = f.trim();
494
+ p && l.push({
495
+ text: p,
287
496
  width: this.measureWordWidth(
288
- n,
289
- o,
290
- a
497
+ e,
498
+ p,
499
+ s
291
500
  ),
292
- style: a,
293
- isLink: h,
294
- href: p,
295
- linkColor: h ? e.options.link?.linkColor || [
501
+ style: s,
502
+ isLink: g,
503
+ href: c,
504
+ linkColor: g ? n.options.link?.linkColor || [
296
505
  0,
297
506
  0,
298
507
  255
@@ -300,93 +509,130 @@ class E {
300
509
  });
301
510
  continue;
302
511
  }
303
- const d = f.split(/\s+/).filter((o) => o.length > 0);
512
+ const d = f.split(/\s+/).filter((p) => p.length > 0);
304
513
  if (d.length === 0)
305
514
  continue;
306
- for (let o = 0; o < d.length; o++) {
307
- const m = d[o];
308
- r.push({
515
+ for (let p = 0; p < d.length; p++) {
516
+ const m = d[p];
517
+ l.push({
309
518
  text: m,
310
- width: this.measureWordWidth(n, m, a),
311
- style: a,
312
- isLink: h,
313
- href: p,
314
- linkColor: h ? e.options.link?.linkColor || [0, 0, 255] : void 0
519
+ width: this.measureWordWidth(e, m, s),
520
+ style: s,
521
+ isLink: g,
522
+ href: c,
523
+ linkColor: g ? n.options.link?.linkColor || [0, 0, 255] : void 0
315
524
  });
316
525
  }
317
526
  }
318
527
  }
319
- return r;
528
+ return l;
320
529
  }
321
530
  /**
322
531
  * Break a flat list of words into lines that fit within maxWidth.
323
532
  * Correctly tracks totalTextWidth (sum of word widths only) for justification.
324
533
  */
325
- static breakIntoLines(n, s, g) {
326
- const c = [];
327
- let l = [], r = 0, i = 0;
328
- const a = n.getTextWidth(" ");
329
- for (let h = 0; h < s.length; h++) {
330
- const p = s[h], f = l.length > 0 ? a + p.width : p.width;
331
- i + f > g && l.length > 0 ? (c.push({
332
- words: l,
333
- totalTextWidth: r,
334
- isLastLine: !1
335
- }), l = [p], r = p.width, i = p.width) : (l.push(p), r += p.width, i += f);
534
+ static breakIntoLines(e, i, r) {
535
+ const h = [];
536
+ let o = [], l = 0, a = 0, s = C(e) * n.options.page.defaultLineHeightFactor;
537
+ const g = e.getTextWidth(" ");
538
+ for (let c = 0; c < i.length; c++) {
539
+ const f = i[c], d = o.length > 0 ? g + f.width : f.width, p = f.isImage && f.imageHeight ? f.imageHeight : C(e) * n.options.page.defaultLineHeightFactor;
540
+ a + d > r && o.length > 0 ? (h.push({
541
+ words: o,
542
+ totalTextWidth: l,
543
+ isLastLine: !1,
544
+ lineHeight: s
545
+ }), o = [f], l = f.width, a = f.width, s = p) : (o.push(f), l += f.width, a += d, s = Math.max(s, p));
336
546
  }
337
- return l.length > 0 && c.push({
338
- words: l,
339
- totalTextWidth: r,
340
- isLastLine: !0
341
- }), c;
547
+ return o.length > 0 && h.push({
548
+ words: o,
549
+ totalTextWidth: l,
550
+ isLastLine: !0,
551
+ lineHeight: s
552
+ }), h;
342
553
  }
343
554
  /**
344
555
  * Render a single word with its style applied.
345
556
  */
346
- static renderWord(n, s, g, c) {
347
- const l = n.getFont(), r = n.getFontSize(), i = n.getTextColor();
348
- if (this.applyStyle(n, s.style), s.isLink && s.linkColor && n.setTextColor(...s.linkColor), s.style === "codespan") {
349
- const a = this.getCodespanOptions();
350
- if (a.showBackground) {
351
- const h = b(n), p = a.padding;
352
- n.setFillColor(a.backgroundColor), n.rect(
353
- g - p,
354
- c - p,
355
- s.width + p * 2,
356
- h + p * 2,
357
- "F"
358
- ), n.setFillColor("#000000");
557
+ static renderWord(e, i, r, h) {
558
+ const o = e.getFont(), l = e.getFontSize(), a = e.getTextColor();
559
+ if (this.applyStyle(e, i.style), i.isLink && i.linkColor && e.setTextColor(...i.linkColor), i.isImage && i.imageElement && i.imageElement.data)
560
+ try {
561
+ let s = "JPEG";
562
+ if (i.imageElement.data.startsWith("data:image/png"))
563
+ s = "PNG";
564
+ else if (i.imageElement.data.startsWith("data:image/webp"))
565
+ s = "WEBP";
566
+ else if (i.imageElement.data.startsWith("data:image/gif"))
567
+ s = "GIF";
568
+ else if (i.imageElement.src) {
569
+ const c = i.imageElement.src.split("?")[0].split("#")[0].split(".").pop()?.toUpperCase();
570
+ c && ["PNG", "JPEG", "JPG", "WEBP", "GIF"].includes(c) && (s = c === "JPG" ? "JPEG" : c);
571
+ }
572
+ if (i.width > 0 && (i.imageHeight || 0) > 0) {
573
+ const g = i.imageHeight || 0, c = h - g;
574
+ e.addImage(
575
+ i.imageElement.data,
576
+ s,
577
+ r,
578
+ c,
579
+ i.width,
580
+ g
581
+ );
582
+ }
583
+ } catch (s) {
584
+ console.warn("Failed to render inline image", s);
585
+ }
586
+ else {
587
+ if (i.style === "codespan") {
588
+ const s = this.getCodespanOptions();
589
+ if (s.showBackground) {
590
+ const g = C(e), c = s.padding;
591
+ e.setFillColor(s.backgroundColor), e.rect(
592
+ r - c,
593
+ h - c,
594
+ i.width + c * 2,
595
+ g + c * 2,
596
+ "F"
597
+ ), e.setFillColor("#000000");
598
+ }
359
599
  }
600
+ e.text(i.text, r, h, { baseline: "top" });
360
601
  }
361
- if (n.text(s.text, g, c, { baseline: "top" }), s.isLink && s.href) {
362
- const a = b(n) / 2;
363
- n.link(g, c, s.width, a, { url: s.href });
602
+ if (i.isLink && i.href) {
603
+ const s = i.isImage && i.imageHeight ? i.imageHeight : C(e);
604
+ e.link(r, h, i.width, s, { url: i.href });
364
605
  }
365
- n.setFont(l.fontName, l.fontStyle), n.setFontSize(r), n.setTextColor(i);
606
+ e.setFont(o.fontName, o.fontStyle), e.setFontSize(l), e.setTextColor(a);
366
607
  }
367
608
  /**
368
609
  * Render a single line with specified alignment.
369
610
  */
370
- static renderAlignedLine(n, s, g, c, l, r = "left") {
371
- const { words: i, totalTextWidth: a, isLastLine: h } = s;
372
- if (i.length === 0) return;
373
- const p = n.getTextWidth(" ");
374
- let f = g, d = p;
375
- const o = a + (i.length - 1) * p;
376
- switch (r) {
611
+ static renderAlignedLine(e, i, r, h, o, l = "left") {
612
+ const { words: a, totalTextWidth: s, isLastLine: g } = i;
613
+ if (a.length === 0) return;
614
+ const c = e.getTextWidth(" ");
615
+ let f = r, d = c;
616
+ const p = s + (a.length - 1) * c;
617
+ switch (l) {
377
618
  case "right":
378
- f = g + l - o;
619
+ f = r + o - p;
379
620
  break;
380
621
  case "center":
381
- f = g + (l - o) / 2;
622
+ f = r + (o - p) / 2;
382
623
  break;
383
624
  case "justify":
384
- !h && i.length > 1 && (d = (l - a) / (i.length - 1));
625
+ !g && a.length > 1 && (d = (o - s) / (a.length - 1));
385
626
  break;
386
627
  }
387
628
  let m = f;
388
- for (let x = 0; x < i.length; x++)
389
- this.renderWord(n, i[x], m, c), m += i[x].width, x < i.length - 1 && (m += d);
629
+ const x = C(e) * n.options.page.defaultLineHeightFactor;
630
+ for (let F = 0; F < a.length; F++) {
631
+ const b = a[F];
632
+ let H = h;
633
+ const w = b.isImage && b.imageHeight ? b.imageHeight : x;
634
+ w < i.lineHeight && (H = h + (i.lineHeight - w)), this.renderWord(e, b, m, H), m += b.width, F < a.length - 1 && (m += d);
635
+ }
390
636
  }
391
637
  /**
392
638
  * Main entry point: Render a paragraph with mixed inline elements.
@@ -399,34 +645,34 @@ class E {
399
645
  * @param maxWidth Maximum width for text wrapping
400
646
  * @param alignment Optional alignment override (defaults to RenderStore option)
401
647
  */
402
- static renderStyledParagraph(n, s, g, c, l, r) {
403
- const i = r ?? e.options.content?.textAlignment ?? "left", a = this.flattenToWords(n, s);
404
- if (a.length === 0) return;
405
- const h = this.breakIntoLines(n, a, l), p = b(n) * e.options.page.defaultLineHeightFactor;
406
- let f = c;
407
- for (const o of h)
408
- f + p > e.options.page.maxContentHeight && (w(n), f = e.Y), this.renderAlignedLine(
409
- n,
648
+ static renderStyledParagraph(e, i, r, h, o, l) {
649
+ const a = l ?? n.options.content?.textAlignment ?? "left", s = this.flattenToWords(e, i);
650
+ if (s.length === 0) return;
651
+ const g = this.breakIntoLines(e, s, o);
652
+ let c = h;
653
+ for (const d of g)
654
+ c + d.lineHeight > n.options.page.maxContentHeight && (Y(e), c = n.Y), this.renderAlignedLine(
655
+ e,
656
+ d,
657
+ r,
658
+ c,
410
659
  o,
411
- g,
412
- f,
413
- l,
414
- i
415
- ), e.recordContentY(f + b(n)), f += p, e.updateY(p, "add");
416
- const d = h[h.length - 1];
417
- if (d) {
418
- const o = d.totalTextWidth + (d.words.length - 1) * n.getTextWidth(" ");
419
- e.updateX(g + o, "set");
660
+ a
661
+ ), n.recordContentY(c + d.lineHeight), c += d.lineHeight, n.updateY(d.lineHeight, "add");
662
+ const f = g[g.length - 1];
663
+ if (f) {
664
+ const d = f.totalTextWidth + (f.words.length - 1) * e.getTextWidth(" ");
665
+ n.updateX(r + d, "set");
420
666
  }
421
667
  }
422
668
  /**
423
669
  * @deprecated Use renderStyledParagraph instead
424
670
  */
425
- static renderJustifiedParagraph(n, s, g, c, l) {
426
- this.renderStyledParagraph(n, s, g, c, l);
671
+ static renderJustifiedParagraph(e, i, r, h, o) {
672
+ this.renderStyledParagraph(e, i, r, h, o);
427
673
  }
428
674
  }
429
- class X {
675
+ class T {
430
676
  /**
431
677
  * Renders text with automatic line wrapping and page breaking.
432
678
  * @param doc jsPDF instance
@@ -436,228 +682,236 @@ class X {
436
682
  * @param maxWidth Max width for text wrapping
437
683
  * @param justify Whether to justify the text
438
684
  */
439
- static renderText(n, s, g = e.X, c = e.Y, l, r = !1) {
440
- const i = n.splitTextToSize(s, l), a = b(n), h = a * e.options.page.defaultLineHeightFactor;
441
- let p = c;
442
- for (let f = 0; f < i.length; f++) {
443
- const d = i[f];
444
- p + h > e.options.page.maxContentHeight && (w(n), p = e.Y), r ? f === i.length - 1 ? n.text(d, g, p, { baseline: "top" }) : n.text(d, g, p, {
445
- maxWidth: l,
685
+ static renderText(e, i, r = n.X, h = n.Y, o, l = !1) {
686
+ const a = e.splitTextToSize(i, o), s = C(e), g = s * n.options.page.defaultLineHeightFactor;
687
+ let c = h;
688
+ for (let f = 0; f < a.length; f++) {
689
+ const d = a[f];
690
+ c + g > n.options.page.maxContentHeight && (Y(e), c = n.Y), l ? f === a.length - 1 ? e.text(d, r, c, { baseline: "top" }) : e.text(d, r, c, {
691
+ maxWidth: o,
446
692
  align: "justify",
447
693
  baseline: "top"
448
- }) : n.text(d, g, p, { baseline: "top" }), e.recordContentY(p + a), p += h, e.updateY(h, "add");
694
+ }) : e.text(d, r, c, { baseline: "top" }), n.recordContentY(c + s), c += g, n.updateY(g, "add");
449
695
  }
450
- return p;
696
+ return c;
451
697
  }
452
698
  }
453
- const _ = (t, n, s, g) => {
454
- e.activateInlineLock(), t.setFontSize(e.options.page.defaultFontSize);
455
- const c = e.options.page.maxContentWidth - s;
456
- if (n?.items && n?.items.length > 0)
457
- if (n.items.some(
458
- (r) => !["strong", "em", "text", "codespan", "link"].includes(
459
- r.type
460
- )
699
+ const nt = (t, e, i, r) => {
700
+ n.activateInlineLock(), t.setFontSize(n.options.page.defaultFontSize);
701
+ const h = n.options.page.maxContentWidth - i;
702
+ if (e?.items && e?.items.length > 0) {
703
+ if (e.items.length === 1 && e.items[0].type === "image") {
704
+ r(e.items[0], i, !1), n.updateX(n.options.page.xpading), n.deactivateInlineLock();
705
+ return;
706
+ }
707
+ const o = [
708
+ "strong",
709
+ "em",
710
+ "text",
711
+ "codespan",
712
+ "link",
713
+ "image"
714
+ ];
715
+ if (e.items.some(
716
+ (a) => !o.includes(a.type)
461
717
  )) {
462
- const r = [], i = () => {
463
- r.length > 0 && (E.renderStyledParagraph(
718
+ const a = [], s = () => {
719
+ a.length > 0 && (A.renderStyledParagraph(
464
720
  t,
465
- r,
466
- e.X + s,
467
- e.Y,
468
- c
469
- ), r.length = 0);
721
+ a,
722
+ n.X + i,
723
+ n.Y,
724
+ h
725
+ ), a.length = 0);
470
726
  };
471
- for (const a of n.items)
472
- ["strong", "em", "text", "codespan", "link"].includes(
473
- a.type
474
- ) ? r.push(a) : (i(), g(a, s, !1));
475
- i();
727
+ for (const g of e.items)
728
+ o.includes(g.type) ? a.push(g) : (s(), r(g, i, !1));
729
+ s();
476
730
  } else
477
- E.renderStyledParagraph(
731
+ A.renderStyledParagraph(
478
732
  t,
479
- n.items,
480
- e.X + s,
481
- e.Y,
482
- c
733
+ e.items,
734
+ n.X + i,
735
+ n.Y,
736
+ h
483
737
  );
484
- else {
485
- const l = n.content ?? "", r = e.options.content?.textAlignment ?? "left";
486
- l.trim() && X.renderText(
738
+ } else {
739
+ const o = e.content ?? "", l = n.options.content?.textAlignment ?? "left";
740
+ o.trim() && T.renderText(
487
741
  t,
488
- l,
489
- e.X + s,
490
- e.Y,
491
- c,
492
- r === "justify"
742
+ o,
743
+ n.X + i,
744
+ n.Y,
745
+ h,
746
+ l === "justify"
493
747
  );
494
748
  }
495
- e.updateX(e.options.page.xpading), e.deactivateInlineLock();
496
- }, $ = (t, n, s, g) => {
497
- t.setFontSize(e.options.page.defaultFontSize);
498
- for (const [c, l] of n?.items?.entries() ?? []) {
499
- const r = n.ordered ? (n.start ?? 0) + c : n.start;
500
- g(
501
- l,
502
- s + 1,
749
+ n.updateX(n.options.page.xpading), n.deactivateInlineLock();
750
+ }, it = (t, e, i, r) => {
751
+ t.setFontSize(n.options.page.defaultFontSize);
752
+ for (const [h, o] of e?.items?.entries() ?? []) {
753
+ const l = e.ordered ? (e.start ?? 0) + h : e.start;
754
+ r(
755
+ o,
756
+ i + 1,
503
757
  !0,
504
- r,
505
- n.ordered
758
+ l,
759
+ e.ordered
506
760
  );
507
761
  }
508
- }, J = (t, n, s, g, c, l) => {
509
- e.Y + b(t) >= e.options.page.maxContentHeight && w(t);
510
- const r = e.options, i = s * r.page.indent, a = l ? `${c}. ` : "• ", h = r.page.xpading;
511
- e.updateX(h, "set"), t.setFont(r.font.regular.name, r.font.regular.style), t.text(a, h + i, e.Y, { baseline: "top" });
512
- const p = t.getTextWidth(a), f = h + i + p, d = r.page.maxContentWidth - i - p;
513
- if (n.items && n.items.length > 0) {
514
- const o = [], m = () => {
515
- o.length > 0 && (E.renderStyledParagraph(
762
+ }, st = (t, e, i, r, h, o) => {
763
+ n.Y + C(t) >= n.options.page.maxContentHeight && Y(t);
764
+ const l = n.options, a = i * l.page.indent, s = o ? `${h}. ` : "• ", g = l.page.xpading;
765
+ n.updateX(g, "set"), t.setFont(l.font.regular.name, l.font.regular.style), t.text(s, g + a, n.Y, { baseline: "top" });
766
+ const c = t.getTextWidth(s), f = g + a + c, d = l.page.maxContentWidth - a - c;
767
+ if (e.items && e.items.length > 0) {
768
+ const p = [], m = () => {
769
+ p.length > 0 && (A.renderStyledParagraph(
516
770
  t,
517
- o,
771
+ p,
518
772
  f,
519
- e.Y,
773
+ n.Y,
520
774
  d
521
- ), o.length = 0, e.updateX(h, "set"));
775
+ ), p.length = 0, n.updateX(g, "set"));
522
776
  };
523
- for (const x of n.items)
524
- x.type === u.List ? (m(), g(
777
+ for (const x of e.items)
778
+ x.type === u.List ? (m(), r(
525
779
  x,
526
- s,
780
+ i,
527
781
  !0,
528
- c,
782
+ h,
529
783
  x.ordered ?? !1
530
- )) : x.type === u.ListItem ? (m(), g(
784
+ )) : x.type === u.ListItem ? (m(), r(
531
785
  x,
532
- s,
786
+ i,
533
787
  !0,
534
- c,
535
- l
536
- )) : o.push(x);
788
+ h,
789
+ o
790
+ )) : p.push(x);
537
791
  m();
538
- } else if (n.content) {
539
- const o = r.content?.textAlignment ?? "left";
540
- X.renderText(
792
+ } else if (e.content) {
793
+ const p = l.content?.textAlignment ?? "left";
794
+ T.renderText(
541
795
  t,
542
- n.content,
796
+ e.content,
543
797
  f,
544
- e.Y,
798
+ n.Y,
545
799
  d,
546
- o === "justify"
800
+ p === "justify"
547
801
  );
548
802
  }
549
- }, G = (t, n, s, g, c, l, r, i = !0) => {
550
- if (n?.items && n?.items.length > 0)
551
- for (const a of n?.items ?? [])
552
- c(
553
- a,
803
+ }, at = (t, e, i, r, h, o, l, a = !0) => {
804
+ if (e?.items && e?.items.length > 0)
805
+ for (const s of e?.items ?? [])
806
+ h(
554
807
  s,
555
- g,
556
- l,
808
+ i,
557
809
  r,
558
- i
810
+ o,
811
+ l,
812
+ a
559
813
  );
560
814
  else {
561
- const a = e.options, h = s * a.page.indent, p = g ? r ? `${l}. ` : "• " : "", f = n.content || "", d = a.page.xpading;
562
- if (!f && !p) return;
563
- if (!f.trim() && !p) {
564
- const o = (f.match(/\n/g) || []).length;
565
- if (o > 1) {
566
- const m = o - 1, x = t.getTextDimensions("A").h * a.page.defaultLineHeightFactor, C = m * x;
567
- e.Y + C > a.page.maxContentHeight ? w(t) : (e.updateY(C, "add"), e.recordContentY(e.Y));
815
+ const s = n.options, g = i * s.page.indent, c = r ? l ? `${o}. ` : "• " : "", f = e.content || "", d = s.page.xpading;
816
+ if (!f && !c) return;
817
+ if (!f.trim() && !c) {
818
+ const p = (f.match(/\n/g) || []).length;
819
+ if (p > 1) {
820
+ const m = p - 1, x = t.getTextDimensions("A").h * s.page.defaultLineHeightFactor, F = m * x;
821
+ n.Y + F > s.page.maxContentHeight ? Y(t) : (n.updateY(F, "add"), n.recordContentY(n.Y));
568
822
  }
569
823
  return;
570
824
  }
571
- if (e.updateX(d, "set"), g && p) {
572
- const o = t.getTextWidth(p), m = a.page.maxContentWidth - h - o;
573
- t.setFont(a.font.regular.name, a.font.regular.style), t.text(p, d + h, e.Y, {
825
+ if (n.updateX(d, "set"), r && c) {
826
+ const p = t.getTextWidth(c), m = s.page.maxContentWidth - g - p;
827
+ t.setFont(s.font.regular.name, s.font.regular.style), t.text(c, d + g, n.Y, {
574
828
  baseline: "top"
575
- }), X.renderText(
829
+ }), T.renderText(
576
830
  t,
577
831
  f,
578
- d + h + o,
579
- e.Y,
832
+ d + g + p,
833
+ n.Y,
580
834
  m,
581
- i
835
+ a
582
836
  );
583
837
  } else {
584
- const o = a.page.maxContentWidth - h;
585
- X.renderText(
838
+ const p = s.page.maxContentWidth - g;
839
+ T.renderText(
586
840
  t,
587
841
  f,
588
- d + h,
589
- e.Y,
590
- o,
591
- i
842
+ d + g,
843
+ n.Y,
844
+ p,
845
+ a
592
846
  );
593
847
  }
594
- e.updateX(d, "set");
848
+ n.updateX(d, "set");
595
849
  }
596
- }, U = (t) => {
597
- const n = t.internal.pageSize.getWidth();
850
+ }, ot = (t) => {
851
+ const e = t.internal.pageSize.getWidth();
598
852
  t.setLineDashPattern([1, 1], 0), t.setLineWidth(0.1), t.line(
599
- e.options.page.xpading,
600
- e.Y,
601
- n - e.options.page.xpading,
602
- e.Y
603
- ), t.setLineWidth(0.1), t.setLineDashPattern([], 0), e.updateY(b(t), "add");
604
- }, K = (t, n, s, g) => {
605
- const c = t.getFont(), l = t.getFontSize();
853
+ n.options.page.xpading,
854
+ n.Y,
855
+ e - n.options.page.xpading,
856
+ n.Y
857
+ ), t.setLineWidth(0.1), t.setLineDashPattern([], 0), n.updateY(C(t), "add");
858
+ }, rt = (t, e, i, r) => {
859
+ const h = t.getFont(), o = t.getFontSize();
606
860
  t.setFont("courier", "normal");
607
- const r = e.options.page.defaultFontSize * 0.9;
608
- t.setFontSize(r);
609
- const i = s * e.options.page.indent, a = e.options.page.maxContentWidth - i - 8, h = t.getLineHeightFactor(), p = r / t.internal.scaleFactor * h, d = (n.code ?? "").replace(/[\r\n\s]+$/, "");
861
+ const l = n.options.page.defaultFontSize * 0.9;
862
+ t.setFontSize(l);
863
+ const a = i * n.options.page.indent, s = n.options.page.maxContentWidth - a - 8, g = t.getLineHeightFactor(), c = l / t.internal.scaleFactor * g, d = (e.code ?? "").replace(/[\r\n\s]+$/, "");
610
864
  if (!d) {
611
- t.setFont(c.fontName, c.fontStyle), t.setFontSize(l);
865
+ t.setFont(h.fontName, h.fontStyle), t.setFontSize(o);
612
866
  return;
613
867
  }
614
- const o = t.splitTextToSize(d, a);
615
- for (; o.length > 0 && o[o.length - 1].trim() === ""; )
616
- o.pop();
617
- if (o.length === 0) {
618
- t.setFont(c.fontName, c.fontStyle), t.setFontSize(l);
868
+ const p = t.splitTextToSize(d, s);
869
+ for (; p.length > 0 && p[p.length - 1].trim() === ""; )
870
+ p.pop();
871
+ if (p.length === 0) {
872
+ t.setFont(h.fontName, h.fontStyle), t.setFontSize(o);
619
873
  return;
620
874
  }
621
- const m = 4, x = "#EEEEEE", C = "#DDDDDD";
622
- let F = 0;
623
- for (; F < o.length; ) {
624
- const k = e.options.page.maxContentHeight - e.Y, S = o.length - F, L = k - m * 2;
625
- let Y = Math.floor(L / p);
626
- if (Y <= 0) {
627
- w(t);
875
+ const m = 4, x = "#EEEEEE", F = "#DDDDDD";
876
+ let b = 0;
877
+ for (; b < p.length; ) {
878
+ const H = n.options.page.maxContentHeight - n.Y, w = p.length - b, L = H - m * 2;
879
+ let S = Math.floor(L / c);
880
+ if (S <= 0) {
881
+ Y(t);
628
882
  continue;
629
883
  }
630
- Y > S && (Y = S);
631
- const N = o.slice(
632
- F,
633
- F + Y
634
- ), T = F === 0, z = F + Y >= o.length, P = Y * p;
635
- if (T && e.updateY(m, "add"), t.setFillColor(x), t.setDrawColor(C), t.roundedRect(
636
- e.X,
637
- e.Y - m,
638
- e.options.page.maxContentWidth,
639
- P + (T ? m : 0) + (z ? m : 0),
884
+ S > w && (S = w);
885
+ const J = p.slice(
886
+ b,
887
+ b + S
888
+ ), E = b === 0, X = b + S >= p.length, B = S * c;
889
+ if (E && n.updateY(m, "add"), t.setFillColor(x), t.setDrawColor(F), t.roundedRect(
890
+ n.X,
891
+ n.Y - m,
892
+ n.options.page.maxContentWidth,
893
+ B + (E ? m : 0) + (X ? m : 0),
640
894
  2,
641
895
  2,
642
896
  "FD"
643
- ), T && n.lang) {
644
- const I = t.getFontSize();
897
+ ), E && e.lang) {
898
+ const P = t.getFontSize();
645
899
  t.setFontSize(10), t.setTextColor("#666666"), t.text(
646
- n.lang,
647
- e.X + e.options.page.maxContentWidth - t.getTextWidth(n.lang) - 4,
648
- e.Y,
900
+ e.lang,
901
+ n.X + n.options.page.maxContentWidth - t.getTextWidth(e.lang) - 4,
902
+ n.Y,
649
903
  { baseline: "top" }
650
- ), t.setFontSize(I), t.setTextColor("#000000");
904
+ ), t.setFontSize(P), t.setTextColor("#000000");
651
905
  }
652
- let D = e.Y;
653
- for (const I of N)
654
- t.text(I, e.X + 4, D, { baseline: "top" }), D += p;
655
- e.updateY(P, "add"), e.recordContentY(e.Y + (z ? m : 0)), z && e.updateY(m, "add"), F += Y, F < o.length && w(t);
906
+ let N = n.Y;
907
+ for (const P of J)
908
+ t.text(P, n.X + 4, N, { baseline: "top" }), N += c;
909
+ n.updateY(B, "add"), n.recordContentY(n.Y + (X ? m : 0)), X && n.updateY(m, "add"), b += S, b < p.length && Y(t);
656
910
  }
657
- t.setFont(c.fontName, c.fontStyle), t.setFontSize(l);
658
- }, Q = (t, n, s) => {
659
- const g = t.getFont().fontName, c = t.getFont().fontStyle, l = t.getFontSize(), r = (a) => {
660
- switch (a) {
911
+ t.setFont(h.fontName, h.fontStyle), t.setFontSize(o);
912
+ }, lt = (t, e, i) => {
913
+ const r = t.getFont().fontName, h = t.getFont().fontStyle, o = t.getFontSize(), l = (s) => {
914
+ switch (s) {
661
915
  case "normal":
662
916
  return 0;
663
917
  case "bold":
@@ -671,52 +925,52 @@ const _ = (t, n, s, g) => {
671
925
  default:
672
926
  return 0;
673
927
  }
674
- }, i = (a, h) => {
675
- h === "bold" ? t.setFont(
676
- e.options.font.bold.name && e.options.font.bold.name !== "" ? e.options.font.bold.name : g,
677
- e.options.font.bold.style || "bold"
678
- ) : h === "italic" ? t.setFont(e.options.font.regular.name, "italic") : h === "bolditalic" ? t.setFont(
679
- e.options.font.bold.name && e.options.font.bold.name !== "" ? e.options.font.bold.name : g,
928
+ }, a = (s, g) => {
929
+ g === "bold" ? t.setFont(
930
+ n.options.font.bold.name && n.options.font.bold.name !== "" ? n.options.font.bold.name : r,
931
+ n.options.font.bold.style || "bold"
932
+ ) : g === "italic" ? t.setFont(n.options.font.regular.name, "italic") : g === "bolditalic" ? t.setFont(
933
+ n.options.font.bold.name && n.options.font.bold.name !== "" ? n.options.font.bold.name : r,
680
934
  "bolditalic"
681
- ) : h === "codespan" ? (t.setFont("courier", "normal"), t.setFontSize(l * 0.9)) : t.setFont(
682
- e.options.font.regular.name,
683
- c
935
+ ) : g === "codespan" ? (t.setFont("courier", "normal"), t.setFontSize(o * 0.9)) : t.setFont(
936
+ n.options.font.regular.name,
937
+ h
684
938
  );
685
- const p = e.options.page.maxContentWidth - s - e.X, f = t.splitTextToSize(a, p), d = h === "codespan", o = 1, m = "#EEEEEE";
686
- if (e.isInlineLockActive)
939
+ const c = n.options.page.maxContentWidth - i - n.X, f = t.splitTextToSize(s, c), d = g === "codespan", p = 1, m = "#EEEEEE";
940
+ if (n.isInlineLockActive)
687
941
  for (let x = 0; x < f.length; x++) {
688
942
  if (d) {
689
- const C = t.getTextWidth(f[x]) + y(t), F = b(t);
943
+ const F = t.getTextWidth(f[x]) + y(t), b = C(t);
690
944
  t.setFillColor(m), t.roundedRect(
691
- e.X + s - o,
692
- e.Y - o,
693
- C + o * 2,
694
- F + o * 2,
945
+ n.X + i - p,
946
+ n.Y - p,
947
+ F + p * 2,
948
+ b + p * 2,
695
949
  2,
696
950
  2,
697
951
  "F"
698
952
  ), t.setFillColor("#000000");
699
953
  }
700
- t.text(f[x], e.X + s, e.Y, {
954
+ t.text(f[x], n.X + i, n.Y, {
701
955
  baseline: "top",
702
- maxWidth: p
703
- }), e.updateX(
704
- t.getTextDimensions(f[x]).w + (d ? o * 2 : 1),
956
+ maxWidth: c
957
+ }), n.updateX(
958
+ t.getTextDimensions(f[x]).w + (d ? p * 2 : 1),
705
959
  "add"
706
- ), x < f.length - 1 && (e.updateY(b(t), "add"), e.updateX(
707
- e.options.page.xpading,
960
+ ), x < f.length - 1 && (n.updateY(C(t), "add"), n.updateX(
961
+ n.options.page.xpading,
708
962
  "set"
709
963
  ));
710
964
  }
711
965
  else if (f.length > 1) {
712
- const x = f[0], C = f?.slice(1)?.join(" ");
966
+ const x = f[0], F = f?.slice(1)?.join(" ");
713
967
  if (d) {
714
- const S = t.getTextWidth(x) + y(t), L = b(t);
968
+ const w = t.getTextWidth(x) + y(t), L = C(t);
715
969
  t.setFillColor(m), t.roundedRect(
716
- e.X + (s >= 2 ? s + 2 : 0) - o,
717
- e.Y - o,
718
- S + o * 2,
719
- L + o * 2,
970
+ n.X + (i >= 2 ? i + 2 : 0) - p,
971
+ n.Y - p,
972
+ w + p * 2,
973
+ L + p * 2,
720
974
  2,
721
975
  2,
722
976
  "F"
@@ -724,244 +978,240 @@ const _ = (t, n, s, g) => {
724
978
  }
725
979
  t.text(
726
980
  x,
727
- e.X + (s >= 2 ? s + 2 * r(h) : 0),
728
- e.Y,
981
+ n.X + (i >= 2 ? i + 2 * l(g) : 0),
982
+ n.Y,
729
983
  {
730
984
  baseline: "top",
731
- maxWidth: p
985
+ maxWidth: c
732
986
  }
733
- ), e.updateX(e.options.page.xpading + s), e.updateY(b(t), "add");
734
- const F = e.options.page.maxContentWidth - s - e.options.page.xpading;
987
+ ), n.updateX(n.options.page.xpading + i), n.updateY(C(t), "add");
988
+ const b = n.options.page.maxContentWidth - i - n.options.page.xpading;
735
989
  t.splitTextToSize(
736
- C,
737
- F
738
- ).forEach((S) => {
990
+ F,
991
+ b
992
+ ).forEach((w) => {
739
993
  if (d) {
740
- const L = t.getTextWidth(S) + y(t), Y = b(t);
994
+ const L = t.getTextWidth(w) + y(t), S = C(t);
741
995
  t.setFillColor(m), t.roundedRect(
742
- e.X + y(t) - o,
743
- e.Y - o,
744
- L + o * 2,
745
- Y + o * 2,
996
+ n.X + y(t) - p,
997
+ n.Y - p,
998
+ L + p * 2,
999
+ S + p * 2,
746
1000
  2,
747
1001
  2,
748
1002
  "F"
749
1003
  ), t.setFillColor("#000000");
750
1004
  }
751
1005
  t.text(
752
- S,
753
- e.X + y(t),
754
- e.Y,
1006
+ w,
1007
+ n.X + y(t),
1008
+ n.Y,
755
1009
  {
756
1010
  baseline: "top",
757
- maxWidth: F
1011
+ maxWidth: b
758
1012
  }
759
1013
  );
760
1014
  });
761
1015
  } else {
762
1016
  if (d) {
763
- const x = t.getTextWidth(a) + y(t), C = b(t);
1017
+ const x = t.getTextWidth(s) + y(t), F = C(t);
764
1018
  t.setFillColor(m), t.roundedRect(
765
- e.X + s - o,
766
- e.Y - o,
767
- x + o * 2,
768
- C + o * 2,
1019
+ n.X + i - p,
1020
+ n.Y - p,
1021
+ x + p * 2,
1022
+ F + p * 2,
769
1023
  2,
770
1024
  2,
771
1025
  "F"
772
1026
  ), t.setFillColor("#000000");
773
1027
  }
774
- t.text(a, e.X + s, e.Y, {
1028
+ t.text(s, n.X + i, n.Y, {
775
1029
  baseline: "top",
776
- maxWidth: p
777
- }), e.updateX(
778
- t.getTextDimensions(a).w + (s >= 2 ? a.split(" ").length + 2 : 2) * r(h) * 0.5 + (d ? o * 2 : 0),
1030
+ maxWidth: c
1031
+ }), n.updateX(
1032
+ t.getTextDimensions(s).w + (i >= 2 ? s.split(" ").length + 2 : 2) * l(g) * 0.5 + (d ? p * 2 : 0),
779
1033
  "add"
780
1034
  );
781
1035
  }
782
1036
  };
783
- if (n.type === "text" && n.items && n.items.length > 0)
784
- for (const a of n.items)
785
- if (a.type === "codespan")
786
- i(a.content || "", "codespan");
787
- else if (a.type === "em" || a.type === "strong") {
788
- const h = a.type === "em" ? "italic" : "bold";
789
- if (a.items && a.items.length > 0)
790
- for (const p of a.items)
791
- p.type === "strong" && h === "italic" || p.type === "em" && h === "bold" ? i(
792
- p.content || "",
1037
+ if (e.type === "text" && e.items && e.items.length > 0)
1038
+ for (const s of e.items)
1039
+ if (s.type === "codespan")
1040
+ a(s.content || "", "codespan");
1041
+ else if (s.type === "em" || s.type === "strong") {
1042
+ const g = s.type === "em" ? "italic" : "bold";
1043
+ if (s.items && s.items.length > 0)
1044
+ for (const c of s.items)
1045
+ c.type === "strong" && g === "italic" || c.type === "em" && g === "bold" ? a(
1046
+ c.content || "",
793
1047
  "bolditalic"
794
- ) : i(
795
- p.content || "",
796
- h
1048
+ ) : a(
1049
+ c.content || "",
1050
+ g
797
1051
  );
798
1052
  else
799
- i(a.content || "", h);
1053
+ a(s.content || "", g);
800
1054
  } else
801
- i(a.content || "", "normal");
802
- else n.type === "em" ? i(n.content || "", "italic") : n.type === "strong" ? i(n.content || "", "bold") : n.type === "codespan" ? i(n.content || "", "codespan") : i(n.content || "", "normal");
803
- t.setFont(g, c), t.setFontSize(l);
804
- }, V = (t, n, s) => {
805
- const g = t.getFont().fontName, c = t.getFont().fontStyle, l = t.getFontSize(), r = t.getTextColor(), i = e.options.link?.linkColor || [0, 0, 255];
806
- t.setTextColor(...i);
807
- const a = e.options.page.maxContentWidth - s - e.X, h = n.text || n.content || "", p = n.href || "", f = t.splitTextToSize(h, a);
808
- if (e.isInlineLockActive)
1055
+ a(s.content || "", "normal");
1056
+ else e.type === "em" ? a(e.content || "", "italic") : e.type === "strong" ? a(e.content || "", "bold") : e.type === "codespan" ? a(e.content || "", "codespan") : a(e.content || "", "normal");
1057
+ t.setFont(r, h), t.setFontSize(o);
1058
+ }, gt = (t, e, i) => {
1059
+ const r = t.getFont().fontName, h = t.getFont().fontStyle, o = t.getFontSize(), l = t.getTextColor(), a = n.options.link?.linkColor || [0, 0, 255];
1060
+ t.setTextColor(...a);
1061
+ const s = n.options.page.maxContentWidth - i - n.X, g = e.text || e.content || "", c = e.href || "", f = t.splitTextToSize(g, s);
1062
+ if (n.isInlineLockActive)
809
1063
  for (let d = 0; d < f.length; d++) {
810
- const o = t.getTextDimensions(f[d]).w, m = b(t) / 2;
1064
+ const p = t.getTextDimensions(f[d]).w, m = C(t) / 2;
811
1065
  t.link(
812
- e.X + s,
813
- e.Y,
814
- o,
1066
+ n.X + i,
1067
+ n.Y,
1068
+ p,
815
1069
  m,
816
- { url: p }
817
- ), t.text(f[d], e.X + s, e.Y, {
1070
+ { url: c }
1071
+ ), t.text(f[d], n.X + i, n.Y, {
818
1072
  baseline: "top",
819
- maxWidth: a
820
- }), e.updateX(o + 1, "add"), e.X + o > e.options.page.maxContentWidth - s && (e.updateY(m, "add"), e.updateX(
821
- e.options.page.xpading + s,
1073
+ maxWidth: s
1074
+ }), n.updateX(p + 1, "add"), n.X + p > n.options.page.maxContentWidth - i && (n.updateY(m, "add"), n.updateX(
1075
+ n.options.page.xpading + i,
822
1076
  "set"
823
- )), d < f.length - 1 && (e.updateY(m, "add"), e.updateX(
824
- e.options.page.xpading + s,
1077
+ )), d < f.length - 1 && (n.updateY(m, "add"), n.updateX(
1078
+ n.options.page.xpading + i,
825
1079
  "set"
826
1080
  ));
827
1081
  }
828
1082
  else if (f.length > 1) {
829
- const d = f[0], o = f?.slice(1)?.join(" "), m = t.getTextDimensions(d).w, x = b(t) / 2;
1083
+ const d = f[0], p = f?.slice(1)?.join(" "), m = t.getTextDimensions(d).w, x = C(t) / 2;
830
1084
  t.link(
831
- e.X + s,
832
- e.Y,
1085
+ n.X + i,
1086
+ n.Y,
833
1087
  m,
834
1088
  x,
835
- { url: p }
836
- ), t.text(d, e.X + s, e.Y, {
1089
+ { url: c }
1090
+ ), t.text(d, n.X + i, n.Y, {
837
1091
  baseline: "top",
838
- maxWidth: a
839
- }), e.updateX(e.options.page.xpading + s), e.updateY(x, "add");
840
- const C = e.options.page.maxContentWidth - s - e.options.page.xpading;
841
- t.splitTextToSize(o, C).forEach((k) => {
842
- const S = t.getTextDimensions(k).w;
1092
+ maxWidth: s
1093
+ }), n.updateX(n.options.page.xpading + i), n.updateY(x, "add");
1094
+ const F = n.options.page.maxContentWidth - i - n.options.page.xpading;
1095
+ t.splitTextToSize(p, F).forEach((H) => {
1096
+ const w = t.getTextDimensions(H).w;
843
1097
  t.link(
844
- e.X + y(t),
845
- e.Y,
846
- S,
1098
+ n.X + y(t),
1099
+ n.Y,
1100
+ w,
847
1101
  x,
848
- { url: p }
1102
+ { url: c }
849
1103
  ), t.text(
850
- k,
851
- e.X + y(t),
852
- e.Y,
1104
+ H,
1105
+ n.X + y(t),
1106
+ n.Y,
853
1107
  {
854
1108
  baseline: "top",
855
- maxWidth: C
1109
+ maxWidth: F
856
1110
  }
857
1111
  );
858
1112
  });
859
1113
  } else {
860
- const d = t.getTextDimensions(h).w, o = b(t) / 2;
1114
+ const d = t.getTextDimensions(g).w, p = C(t) / 2;
861
1115
  t.link(
862
- e.X + s,
863
- e.Y,
1116
+ n.X + i,
1117
+ n.Y,
864
1118
  d,
865
- o,
866
- { url: p }
867
- ), t.text(h, e.X + s, e.Y, {
1119
+ p,
1120
+ { url: c }
1121
+ ), t.text(g, n.X + i, n.Y, {
868
1122
  baseline: "top",
869
- maxWidth: a
870
- }), e.updateX(d + 2, "add");
1123
+ maxWidth: s
1124
+ }), n.updateX(d + 2, "add");
871
1125
  }
872
- t.setFont(g, c), t.setFontSize(l), t.setTextColor(r);
873
- }, Z = (t, n, s, g) => {
874
- const c = e.options, l = s + 1, r = e.X + s * c.page.indent, i = e.Y, a = r + c.page.indent / 2, h = i, p = t.internal.getCurrentPageInfo().pageNumber;
875
- n.items && n.items.length > 0 && n.items.forEach((o) => {
876
- g(o, l);
1126
+ t.setFont(r, h), t.setFontSize(o), t.setTextColor(l);
1127
+ }, ct = (t, e, i, r) => {
1128
+ const h = n.options, o = i + 1, l = n.X + i * h.page.indent, a = n.Y, s = l + h.page.indent / 2, g = a, c = t.internal.getCurrentPageInfo().pageNumber;
1129
+ e.items && e.items.length > 0 && e.items.forEach((p) => {
1130
+ r(p, o);
877
1131
  });
878
- const f = e.Y, d = t.internal.getCurrentPageInfo().pageNumber;
1132
+ const f = n.Y, d = t.internal.getCurrentPageInfo().pageNumber;
879
1133
  t.setDrawColor(100), t.setLineWidth(1);
880
- for (let o = p; o <= d; o++) {
881
- t.setPage(o);
882
- const m = o === p, x = o === d, C = m ? h : c.page.topmargin, F = x ? f : c.page.maxContentHeight;
883
- t.line(a, C, a, F);
1134
+ for (let p = c; p <= d; p++) {
1135
+ t.setPage(p);
1136
+ const m = p === c, x = p === d, F = m ? g : h.page.topmargin, b = x ? f : h.page.maxContentHeight;
1137
+ t.line(s, F, s, b);
1138
+ }
1139
+ n.recordContentY(), t.setPage(d);
1140
+ }, ht = (t) => {
1141
+ if (t.data) {
1142
+ if (t.data.startsWith("data:image/png")) return "PNG";
1143
+ if (t.data.startsWith("data:image/jpeg") || t.data.startsWith("data:image/jpg"))
1144
+ return "JPEG";
1145
+ if (t.data.startsWith("data:image/webp") || t.data.startsWith("data:image/webp")) return "WEBP";
1146
+ if (t.data.startsWith("data:image/gif")) return "GIF";
884
1147
  }
885
- e.recordContentY(), t.setPage(d);
886
- }, M = (t, n, s) => {
887
- if (!n.data)
1148
+ if (t.src) {
1149
+ const i = t.src.split("?")[0].split("#")[0].split(".").pop()?.toUpperCase();
1150
+ if (i && ["PNG", "JPEG", "JPG", "WEBP", "GIF"].includes(i))
1151
+ return i === "JPG" ? "JPEG" : i;
1152
+ }
1153
+ return "JPEG";
1154
+ }, pt = (t, e, i) => {
1155
+ if (!e.data)
888
1156
  return;
889
- const g = e.options, c = e.X + s * g.page.indent;
890
- let l = e.Y;
891
- const r = g.page.maxContentWidth - s * g.page.indent;
1157
+ const r = n.options, h = r.page.unit || "mm", o = i * r.page.indent, l = r.page.maxContentWidth - o, a = n.X + o;
1158
+ let s = n.Y;
892
1159
  try {
893
- const i = t.getImageProperties(n.data), a = i.width, h = i.height;
894
- let p = a, f = h;
895
- const d = a / h;
896
- p > 0 && (p = r, f = p / d), l + f > g.page.maxContentHeight && (t.addPage(), l = g.page.topmargin, e.updateY(l));
897
- let o = n.src?.split(".").pop()?.toUpperCase() || "JPEG";
898
- n.data.startsWith("data:image/png") ? o = "PNG" : n.data.startsWith("data:image/jpeg") || n.data.startsWith("data:image/jpg") ? o = "JPEG" : n.data.startsWith("data:image/webp") && (o = "WEBP"), t.addImage(
899
- n.data,
900
- o,
901
- c,
1160
+ const g = r.page.maxContentHeight - r.page.topmargin, { finalWidth: c, finalHeight: f } = _(
1161
+ t,
1162
+ e,
902
1163
  l,
1164
+ g,
1165
+ h
1166
+ );
1167
+ s + f > r.page.maxContentHeight && (Y(t), s = n.Y);
1168
+ const d = e.align || r.image?.defaultAlign || "left";
1169
+ let p;
1170
+ switch (d) {
1171
+ case "right":
1172
+ p = a + l - c;
1173
+ break;
1174
+ case "center":
1175
+ p = a + (l - c) / 2;
1176
+ break;
1177
+ default:
1178
+ p = a;
1179
+ break;
1180
+ }
1181
+ const m = ht(e);
1182
+ c > 0 && f > 0 && t.addImage(
1183
+ e.data,
1184
+ m,
903
1185
  p,
1186
+ s,
1187
+ c,
904
1188
  f
905
- ), e.updateY(f, "add"), e.recordContentY();
906
- } catch (i) {
907
- console.warn("Failed to render image", i);
1189
+ ), n.updateY(f, "add"), n.recordContentY();
1190
+ } catch (g) {
1191
+ console.warn("Failed to render image", g);
908
1192
  }
909
- }, tt = (t, n, s) => {
910
- if (!n.header || !n.rows)
1193
+ }, ft = (t, e, i) => {
1194
+ if (!e.header || !e.rows)
911
1195
  return;
912
- const g = e.options, c = g.page.xmargin + s * g.page.indent, l = [n.header.map((a) => a.content || "")], r = n.rows.map(
913
- (a) => a.map((h) => h.content || "")
914
- ), i = g.table || {};
915
- A(t, {
916
- head: l,
917
- body: r,
918
- startY: e.Y,
919
- margin: { left: c, right: g.page.xmargin },
920
- ...i,
921
- didDrawPage: (a) => {
922
- i.didDrawPage && i.didDrawPage(a);
1196
+ const r = n.options, h = r.page.xmargin + i * r.page.indent, o = [e.header.map((s) => s.content || "")], l = e.rows.map(
1197
+ (s) => s.map((g) => g.content || "")
1198
+ ), a = r.table || {};
1199
+ O(t, {
1200
+ head: o,
1201
+ body: l,
1202
+ startY: n.Y,
1203
+ margin: { left: h, right: r.page.xmargin },
1204
+ ...a,
1205
+ didDrawPage: (s) => {
1206
+ a.didDrawPage && a.didDrawPage(s);
923
1207
  },
924
- didDrawCell: (a) => {
925
- i.didDrawCell && i.didDrawCell(a), e.setCursor({
926
- x: e.X,
927
- y: a.cell.y + 2 * g.page.lineSpace
1208
+ didDrawCell: (s) => {
1209
+ a.didDrawCell && a.didDrawCell(s), n.setCursor({
1210
+ x: n.X,
1211
+ y: s.cell.y + s.cell.height + 2 * r.page.lineSpace
928
1212
  });
929
1213
  }
930
1214
  });
931
- }, B = async (t) => {
932
- for (const n of t) {
933
- if (n.type === u.Image && n.src)
934
- try {
935
- if (n.src.startsWith("data:"))
936
- n.data = n.src;
937
- else {
938
- const s = await fetch(n.src);
939
- if (!s.ok)
940
- throw new Error(
941
- `Failed to fetch image: ${s.statusText}`
942
- );
943
- const g = await s.blob(), c = await new Promise(
944
- (l, r) => {
945
- const i = new FileReader();
946
- i.onloadend = () => {
947
- typeof i.result == "string" ? l(i.result) : r(
948
- new Error(
949
- "Failed to convert image to base64 string"
950
- )
951
- );
952
- }, i.onerror = r, i.readAsDataURL(g);
953
- }
954
- );
955
- n.data = c;
956
- }
957
- } catch (s) {
958
- console.warn(
959
- `[jspdf-md-renderer] Warning: Failed to load image at ${n.src}. It will be skipped.`,
960
- s
961
- );
962
- }
963
- n.items && n.items.length > 0 && await B(n.items);
964
- }
965
1215
  }, v = {
966
1216
  page: {
967
1217
  indent: 10,
@@ -981,83 +1231,87 @@ const _ = (t, n, s, g) => {
981
1231
  bold: { name: "helvetica", style: "bold" },
982
1232
  regular: { name: "helvetica", style: "normal" },
983
1233
  light: { name: "helvetica", style: "light" }
1234
+ },
1235
+ image: {
1236
+ defaultAlign: "left"
984
1237
  }
985
- }, et = (t) => {
1238
+ }, dt = (t) => {
986
1239
  if (!t)
987
1240
  throw new Error("RenderOption is required");
988
- const n = { ...v.page, ...t.page }, s = { ...v.font, ...t.font };
989
- return n.maxContentWidth || (n.maxContentWidth = 190), n.maxContentHeight || (n.maxContentHeight = 277), {
1241
+ const e = { ...v.page, ...t.page }, i = { ...v.font, ...t.font }, r = { ...v.image, ...t.image };
1242
+ return e.maxContentWidth || (e.maxContentWidth = 190), e.maxContentHeight || (e.maxContentHeight = 277), {
990
1243
  ...t,
991
- page: n,
992
- font: s
1244
+ page: e,
1245
+ font: i,
1246
+ image: r
993
1247
  };
994
- }, it = async (t, n, s) => {
995
- const g = et(s);
996
- e.initialize(g);
997
- const c = await j(n);
998
- await B(c);
999
- const l = (r, i = 0, a = !1, h = 0, p = !1, f = !0) => {
1000
- const d = i * g.page.indent;
1001
- switch (r.type) {
1248
+ }, xt = async (t, e, i) => {
1249
+ const r = dt(i);
1250
+ n.initialize(r);
1251
+ const h = await M(e);
1252
+ await $(h);
1253
+ const o = (l, a = 0, s = !1, g = 0, c = !1, f = !0) => {
1254
+ const d = a * r.page.indent;
1255
+ switch (l.type) {
1002
1256
  case u.Heading:
1003
- q(t, r, d, l);
1257
+ et(t, l, d, o);
1004
1258
  break;
1005
1259
  case u.Paragraph:
1006
- _(t, r, d, l);
1260
+ nt(t, l, d, o);
1007
1261
  break;
1008
1262
  case u.List:
1009
- $(t, r, i, l);
1263
+ it(t, l, a, o);
1010
1264
  break;
1011
1265
  case u.ListItem:
1012
- J(
1266
+ st(
1013
1267
  t,
1014
- r,
1015
- i,
1016
1268
  l,
1017
- h,
1018
- p
1269
+ a,
1270
+ o,
1271
+ g,
1272
+ c
1019
1273
  );
1020
1274
  break;
1021
1275
  case u.Hr:
1022
- U(t);
1276
+ ot(t);
1023
1277
  break;
1024
1278
  case u.Code:
1025
- K(t, r, i);
1279
+ rt(t, l, a);
1026
1280
  break;
1027
1281
  case u.Strong:
1028
1282
  case u.Em:
1029
1283
  case u.CodeSpan:
1030
- Q(t, r, d);
1284
+ lt(t, l, d);
1031
1285
  break;
1032
1286
  case u.Link:
1033
- V(t, r, d);
1287
+ gt(t, l, d);
1034
1288
  break;
1035
1289
  case u.Blockquote:
1036
- Z(t, r, i, l);
1290
+ ct(t, l, a, o);
1037
1291
  break;
1038
1292
  case u.Image:
1039
- M(t, r, i);
1293
+ pt(t, l, a);
1040
1294
  break;
1041
1295
  case u.Table:
1042
- tt(t, r, i);
1296
+ ft(t, l, a);
1043
1297
  break;
1044
1298
  case u.Raw:
1045
1299
  case u.Text:
1046
- G(
1300
+ at(
1047
1301
  t,
1048
- r,
1049
- i,
1050
- a,
1051
1302
  l,
1052
- h,
1053
- p,
1054
- g.page.defaultFontSize > 0
1303
+ a,
1304
+ s,
1305
+ o,
1306
+ g,
1307
+ c,
1308
+ r.page.defaultFontSize > 0
1055
1309
  // Using validOptions here if needed, or just true for justify
1056
1310
  );
1057
1311
  break;
1058
1312
  default:
1059
1313
  console.warn(
1060
- `Warning: Unsupported element type encountered: ${r.type}.
1314
+ `Warning: Unsupported element type encountered: ${l.type}.
1061
1315
  If you believe this element type should be supported, please create an issue at:
1062
1316
  https://github.com/JeelGajera/jspdf-md-renderer/issues
1063
1317
  with details of the element and expected behavior. Thanks for helping to improve this library!`
@@ -1065,11 +1319,11 @@ const _ = (t, n, s, g) => {
1065
1319
  break;
1066
1320
  }
1067
1321
  };
1068
- for (const r of c)
1069
- l(r);
1070
- g.endCursorYHandler(e.Y);
1322
+ for (const l of h)
1323
+ o(l);
1324
+ r.endCursorYHandler(n.Y);
1071
1325
  };
1072
1326
  export {
1073
- j as MdTextParser,
1074
- it as MdTextRender
1327
+ M as MdTextParser,
1328
+ xt as MdTextRender
1075
1329
  };