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