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