jspdf-md-renderer 3.3.0 → 3.3.1
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 +208 -197
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { marked as
|
|
2
|
-
import
|
|
1
|
+
import { marked as O } from "marked";
|
|
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_", q = /(!\[[^\]]*\]\()([^)]+)(\))\s*\{([^}]+)\}/g, U = /(\w+)\s*=\s*(\w+)/g, G = ["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 ? `#${
|
|
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
7
|
}, V = (t) => {
|
|
8
8
|
const e = {};
|
|
9
9
|
let i;
|
|
10
10
|
for (; (i = U.exec(t)) !== null; ) {
|
|
11
|
-
const r = i[1].toLowerCase(),
|
|
11
|
+
const r = i[1].toLowerCase(), p = i[2];
|
|
12
12
|
switch (r) {
|
|
13
13
|
case "width":
|
|
14
14
|
case "w": {
|
|
15
|
-
const o = parseInt(
|
|
15
|
+
const o = parseInt(p, 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(p, 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 = p.toLowerCase();
|
|
27
|
+
G.includes(
|
|
28
28
|
o
|
|
29
29
|
) && (e.align = o);
|
|
30
30
|
break;
|
|
@@ -34,39 +34,39 @@ const D = "__jmr_", q = /(!\[[^\]]*\]\()([^)]+)(\))\s*\{([^}]+)\}/g, U = /(\w+)\
|
|
|
34
34
|
return e;
|
|
35
35
|
}, Z = (t) => t.replace(
|
|
36
36
|
q,
|
|
37
|
-
(e, i, r,
|
|
37
|
+
(e, i, r, p, o) => {
|
|
38
38
|
const l = V(o), a = Q(l);
|
|
39
|
-
return `${i}${r}${a}${
|
|
39
|
+
return `${i}${r}${a}${p}`;
|
|
40
40
|
}
|
|
41
41
|
), K = (t) => {
|
|
42
|
-
const e = t.indexOf(`#${
|
|
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 +
|
|
45
|
+
const i = t.substring(0, e), r = t.substring(e + 1 + A.length), p = {}, o = r.split("&");
|
|
46
46
|
for (const l of o) {
|
|
47
47
|
const [a, s] = l.split("=");
|
|
48
48
|
switch (a) {
|
|
49
49
|
case "w": {
|
|
50
50
|
const g = parseInt(s, 10);
|
|
51
|
-
!isNaN(g) && g > 0 && (
|
|
51
|
+
!isNaN(g) && g > 0 && (p.width = g);
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
54
|
case "h": {
|
|
55
55
|
const g = parseInt(s, 10);
|
|
56
|
-
!isNaN(g) && g > 0 && (
|
|
56
|
+
!isNaN(g) && g > 0 && (p.height = g);
|
|
57
57
|
break;
|
|
58
58
|
}
|
|
59
59
|
case "a": {
|
|
60
|
-
|
|
60
|
+
G.includes(
|
|
61
61
|
s
|
|
62
|
-
) && (
|
|
62
|
+
) && (p.align = s);
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
return { cleanHref: i, attrs:
|
|
67
|
+
return { cleanHref: i, attrs: p };
|
|
68
68
|
}, M = async (t) => {
|
|
69
|
-
const e = Z(t), i = await
|
|
69
|
+
const e = Z(t), i = await O.lexer(e, {
|
|
70
70
|
async: !0,
|
|
71
71
|
gfm: !0
|
|
72
72
|
});
|
|
@@ -237,9 +237,9 @@ 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 C = (t) => t.getTextDimensions("H").h * n.options.page.defaultLineHeightFactor,
|
|
241
|
-
const
|
|
242
|
-
if (t.setFontSize(n.options.page.defaultFontSize +
|
|
240
|
+
const C = (t) => t.getTextDimensions("H").h * n.options.page.defaultLineHeightFactor, H = (t) => t.getTextDimensions("H").w * n.options.page.defaultLineHeightFactor, et = (t, e, i, r) => {
|
|
241
|
+
const p = 6 - (e?.depth ?? 0) > 0 ? 6 - (e?.depth ?? 0) : 1;
|
|
242
|
+
if (t.setFontSize(n.options.page.defaultFontSize + p), e?.items && e?.items.length > 0)
|
|
243
243
|
for (const o of e?.items ?? [])
|
|
244
244
|
r(o, i, !1);
|
|
245
245
|
else {
|
|
@@ -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,12 +284,12 @@ 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
|
+
), p = e.match(
|
|
288
288
|
/<svg[^>]*\sviewBox=(?:'|")[^'"]*(?:'|")/i
|
|
289
289
|
);
|
|
290
290
|
let o = i ? parseFloat(i[1]) : 0, l = r ? parseFloat(r[1]) : 0;
|
|
291
|
-
if ((!o || !l) &&
|
|
292
|
-
const a =
|
|
291
|
+
if ((!o || !l) && p) {
|
|
292
|
+
const a = p[0].match(
|
|
293
293
|
/viewBox=(?:'|")([^'"]+)(?:'|")/i
|
|
294
294
|
);
|
|
295
295
|
if (a) {
|
|
@@ -302,13 +302,13 @@ const C = (t) => t.getTextDimensions("H").h * n.options.page.defaultLineHeightFa
|
|
|
302
302
|
console.warn("Failed to extract SVG dimensions:", e);
|
|
303
303
|
}
|
|
304
304
|
return null;
|
|
305
|
-
},
|
|
305
|
+
}, $ = (t, e, i, r, p = "mm") => {
|
|
306
306
|
if (!e.data)
|
|
307
307
|
return { finalWidth: 0, finalHeight: 0 };
|
|
308
308
|
let o = e.naturalWidth || 0, l = e.naturalHeight || 0;
|
|
309
309
|
if (!o || !l)
|
|
310
310
|
if (e.data.startsWith("data:image/svg")) {
|
|
311
|
-
const c =
|
|
311
|
+
const c = _(e.data);
|
|
312
312
|
c && (o = c.width, l = c.height);
|
|
313
313
|
} else
|
|
314
314
|
try {
|
|
@@ -322,7 +322,7 @@ const C = (t) => t.getTextDimensions("H").h * n.options.page.defaultLineHeightFa
|
|
|
322
322
|
}
|
|
323
323
|
const a = l > 0 ? o / l : 1;
|
|
324
324
|
let s, g;
|
|
325
|
-
if (e.width && e.height ? (s = k(e.width,
|
|
325
|
+
if (e.width && e.height ? (s = k(e.width, p), g = k(e.height, p)) : e.width ? (s = k(e.width, p), g = s / a) : e.height ? (g = k(e.height, p), s = g * a) : (s = k(o, p), g = k(l, p)), s > i) {
|
|
326
326
|
const c = i / s;
|
|
327
327
|
s = i, g = g * c;
|
|
328
328
|
}
|
|
@@ -331,7 +331,7 @@ const C = (t) => t.getTextDimensions("H").h * n.options.page.defaultLineHeightFa
|
|
|
331
331
|
g = r, s = s * c;
|
|
332
332
|
}
|
|
333
333
|
return { finalWidth: s, finalHeight: g };
|
|
334
|
-
},
|
|
334
|
+
}, J = async (t) => {
|
|
335
335
|
for (const e of t) {
|
|
336
336
|
if (e.type === u.Image && e.src)
|
|
337
337
|
try {
|
|
@@ -343,7 +343,7 @@ 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(),
|
|
346
|
+
const r = await i.blob(), p = await new Promise(
|
|
347
347
|
(o, l) => {
|
|
348
348
|
const a = new FileReader();
|
|
349
349
|
a.onloadend = () => {
|
|
@@ -355,19 +355,19 @@ const C = (t) => t.getTextDimensions("H").h * n.options.page.defaultLineHeightFa
|
|
|
355
355
|
}, a.onerror = l, a.readAsDataURL(r);
|
|
356
356
|
}
|
|
357
357
|
);
|
|
358
|
-
e.data =
|
|
358
|
+
e.data = p;
|
|
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 p = document.createElement("canvas"), o = _(
|
|
364
364
|
e.data
|
|
365
365
|
), l = o ? o.width : r.width || 300, a = o ? o.height : r.height || 150;
|
|
366
366
|
e.naturalWidth = l, e.naturalHeight = a;
|
|
367
367
|
const s = 4;
|
|
368
|
-
|
|
369
|
-
const g =
|
|
370
|
-
g ? (g.scale(s, s), g.drawImage(r, 0, 0, l, a), i(
|
|
368
|
+
p.width = l * s, p.height = a * s;
|
|
369
|
+
const g = p.getContext("2d");
|
|
370
|
+
g ? (g.scale(s, s), g.drawImage(r, 0, 0, l, a), i(p.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,7 +394,7 @@ 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, p = e.getFontSize(), o = () => {
|
|
398
398
|
const a = n.options.font.bold?.name;
|
|
399
399
|
return a && a !== "" ? a : r;
|
|
400
400
|
}, l = () => {
|
|
@@ -416,7 +416,7 @@ class A {
|
|
|
416
416
|
break;
|
|
417
417
|
case "codespan":
|
|
418
418
|
e.setFont("courier", "normal"), e.setFontSize(
|
|
419
|
-
|
|
419
|
+
p * this.getCodespanOptions().fontSizeScale
|
|
420
420
|
);
|
|
421
421
|
break;
|
|
422
422
|
default:
|
|
@@ -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 p = e.getFont(), o = e.getFontSize();
|
|
434
434
|
this.applyStyle(e, r);
|
|
435
435
|
const l = e.getTextWidth(i), a = e.getCharSpace?.() ?? 0, s = l + i.length * a;
|
|
436
|
-
return e.setFont(
|
|
436
|
+
return e.setFont(p.fontName, p.fontStyle), e.setFontSize(o), s;
|
|
437
437
|
}
|
|
438
438
|
/**
|
|
439
439
|
* Extract style from element type string.
|
|
@@ -454,10 +454,10 @@ 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",
|
|
457
|
+
static flattenToWords(e, i, r = "normal", p = !1, o) {
|
|
458
458
|
const l = [];
|
|
459
459
|
for (const a of i) {
|
|
460
|
-
const s = this.getStyleFromType(a.type, r), g = a.type === "link" ||
|
|
460
|
+
const s = this.getStyleFromType(a.type, r), g = a.type === "link" || p, c = a.href || o;
|
|
461
461
|
if (a.items && a.items.length > 0) {
|
|
462
462
|
const f = this.flattenToWords(
|
|
463
463
|
e,
|
|
@@ -468,12 +468,12 @@ class A {
|
|
|
468
468
|
);
|
|
469
469
|
l.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
|
l.push({
|
|
479
479
|
text: "",
|
|
@@ -490,12 +490,12 @@ 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 && l.push({
|
|
495
|
+
text: h,
|
|
496
496
|
width: this.measureWordWidth(
|
|
497
497
|
e,
|
|
498
|
-
|
|
498
|
+
h,
|
|
499
499
|
s
|
|
500
500
|
),
|
|
501
501
|
style: s,
|
|
@@ -509,11 +509,11 @@ 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[
|
|
515
|
+
for (let h = 0; h < d.length; h++) {
|
|
516
|
+
const m = d[h];
|
|
517
517
|
l.push({
|
|
518
518
|
text: m,
|
|
519
519
|
width: this.measureWordWidth(e, m, s),
|
|
@@ -532,29 +532,29 @@ class A {
|
|
|
532
532
|
* Correctly tracks totalTextWidth (sum of word widths only) for justification.
|
|
533
533
|
*/
|
|
534
534
|
static breakIntoLines(e, i, r) {
|
|
535
|
-
const
|
|
535
|
+
const p = [];
|
|
536
536
|
let o = [], l = 0, a = 0, s = C(e) * n.options.page.defaultLineHeightFactor;
|
|
537
537
|
const g = e.getTextWidth(" ");
|
|
538
538
|
for (let c = 0; c < i.length; c++) {
|
|
539
|
-
const f = i[c], d = o.length > 0 ? g + f.width : f.width,
|
|
540
|
-
a + d > r && o.length > 0 ? (
|
|
539
|
+
const f = i[c], d = o.length > 0 ? g + f.width : f.width, h = f.isImage && f.imageHeight ? f.imageHeight : C(e) * n.options.page.defaultLineHeightFactor;
|
|
540
|
+
a + d > r && o.length > 0 ? (p.push({
|
|
541
541
|
words: o,
|
|
542
542
|
totalTextWidth: l,
|
|
543
543
|
isLastLine: !1,
|
|
544
544
|
lineHeight: s
|
|
545
|
-
}), o = [f], l = f.width, a = f.width, s =
|
|
545
|
+
}), o = [f], l = f.width, a = f.width, s = h) : (o.push(f), l += f.width, a += d, s = Math.max(s, h));
|
|
546
546
|
}
|
|
547
|
-
return o.length > 0 &&
|
|
547
|
+
return o.length > 0 && p.push({
|
|
548
548
|
words: o,
|
|
549
549
|
totalTextWidth: l,
|
|
550
550
|
isLastLine: !0,
|
|
551
551
|
lineHeight: s
|
|
552
|
-
}),
|
|
552
|
+
}), p;
|
|
553
553
|
}
|
|
554
554
|
/**
|
|
555
555
|
* Render a single word with its style applied.
|
|
556
556
|
*/
|
|
557
|
-
static renderWord(e, i, r,
|
|
557
|
+
static renderWord(e, i, r, p) {
|
|
558
558
|
const o = e.getFont(), l = 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 {
|
|
@@ -570,7 +570,7 @@ class A {
|
|
|
570
570
|
c && ["PNG", "JPEG", "JPG", "WEBP", "GIF"].includes(c) && (s = c === "JPG" ? "JPEG" : c);
|
|
571
571
|
}
|
|
572
572
|
if (i.width > 0 && (i.imageHeight || 0) > 0) {
|
|
573
|
-
const g = i.imageHeight || 0, c =
|
|
573
|
+
const g = i.imageHeight || 0, c = p - g;
|
|
574
574
|
e.addImage(
|
|
575
575
|
i.imageElement.data,
|
|
576
576
|
s,
|
|
@@ -590,36 +590,36 @@ class A {
|
|
|
590
590
|
const g = C(e), c = s.padding;
|
|
591
591
|
e.setFillColor(s.backgroundColor), e.rect(
|
|
592
592
|
r - c,
|
|
593
|
-
|
|
593
|
+
p - c,
|
|
594
594
|
i.width + c * 2,
|
|
595
595
|
g + c * 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, p, { baseline: "top" });
|
|
601
601
|
}
|
|
602
602
|
if (i.isLink && i.href) {
|
|
603
603
|
const s = i.isImage && i.imageHeight ? i.imageHeight : C(e);
|
|
604
|
-
e.link(r,
|
|
604
|
+
e.link(r, p, i.width, s, { url: i.href });
|
|
605
605
|
}
|
|
606
606
|
e.setFont(o.fontName, o.fontStyle), e.setFontSize(l), e.setTextColor(a);
|
|
607
607
|
}
|
|
608
608
|
/**
|
|
609
609
|
* Render a single line with specified alignment.
|
|
610
610
|
*/
|
|
611
|
-
static renderAlignedLine(e, i, r,
|
|
611
|
+
static renderAlignedLine(e, i, r, p, o, l = "left") {
|
|
612
612
|
const { words: a, totalTextWidth: s, isLastLine: g } = i;
|
|
613
613
|
if (a.length === 0) return;
|
|
614
614
|
const c = e.getTextWidth(" ");
|
|
615
615
|
let f = r, d = c;
|
|
616
|
-
const
|
|
616
|
+
const h = s + (a.length - 1) * c;
|
|
617
617
|
switch (l) {
|
|
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
|
!g && a.length > 1 && (d = (o - s) / (a.length - 1));
|
|
@@ -629,9 +629,9 @@ class A {
|
|
|
629
629
|
const x = C(e) * n.options.page.defaultLineHeightFactor;
|
|
630
630
|
for (let F = 0; F < a.length; F++) {
|
|
631
631
|
const b = a[F];
|
|
632
|
-
let
|
|
632
|
+
let y = p;
|
|
633
633
|
const w = b.isImage && b.imageHeight ? b.imageHeight : x;
|
|
634
|
-
w < i.lineHeight && (
|
|
634
|
+
w < i.lineHeight && (y = p + (i.lineHeight - w)), this.renderWord(e, b, m, y), m += b.width, F < a.length - 1 && (m += d);
|
|
635
635
|
}
|
|
636
636
|
}
|
|
637
637
|
/**
|
|
@@ -645,11 +645,11 @@ 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,
|
|
648
|
+
static renderStyledParagraph(e, i, r, p, o, l) {
|
|
649
649
|
const a = l ?? n.options.content?.textAlignment ?? "left", s = this.flattenToWords(e, i);
|
|
650
650
|
if (s.length === 0) return;
|
|
651
651
|
const g = this.breakIntoLines(e, s, o);
|
|
652
|
-
let c =
|
|
652
|
+
let c = p;
|
|
653
653
|
for (const d of g)
|
|
654
654
|
c + d.lineHeight > n.options.page.maxContentHeight && (Y(e), c = n.Y), this.renderAlignedLine(
|
|
655
655
|
e,
|
|
@@ -668,8 +668,8 @@ 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, p, o) {
|
|
672
|
+
this.renderStyledParagraph(e, i, r, p, o);
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
675
|
class T {
|
|
@@ -682,9 +682,9 @@ 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,
|
|
685
|
+
static renderText(e, i, r = n.X, p = n.Y, o, l = !1) {
|
|
686
686
|
const a = e.splitTextToSize(i, o), s = C(e), g = s * n.options.page.defaultLineHeightFactor;
|
|
687
|
-
let c =
|
|
687
|
+
let c = p;
|
|
688
688
|
for (let f = 0; f < a.length; f++) {
|
|
689
689
|
const d = a[f];
|
|
690
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, {
|
|
@@ -698,7 +698,7 @@ class T {
|
|
|
698
698
|
}
|
|
699
699
|
const nt = (t, e, i, r) => {
|
|
700
700
|
n.activateInlineLock(), t.setFontSize(n.options.page.defaultFontSize);
|
|
701
|
-
const
|
|
701
|
+
const p = 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,24 +716,24 @@ 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
|
+
p
|
|
725
725
|
), a.length = 0);
|
|
726
726
|
};
|
|
727
727
|
for (const g of e.items)
|
|
728
728
|
o.includes(g.type) ? a.push(g) : (s(), r(g, 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
|
+
p
|
|
737
737
|
);
|
|
738
738
|
} else {
|
|
739
739
|
const o = e.content ?? "", l = n.options.content?.textAlignment ?? "left";
|
|
@@ -742,15 +742,15 @@ const nt = (t, e, i, r) => {
|
|
|
742
742
|
o,
|
|
743
743
|
n.X + i,
|
|
744
744
|
n.Y,
|
|
745
|
-
|
|
745
|
+
p,
|
|
746
746
|
l === "justify"
|
|
747
747
|
);
|
|
748
748
|
}
|
|
749
749
|
n.updateX(n.options.page.xpading), n.deactivateInlineLock();
|
|
750
750
|
}, it = (t, e, i, r) => {
|
|
751
751
|
t.setFontSize(n.options.page.defaultFontSize);
|
|
752
|
-
for (const [
|
|
753
|
-
const l = e.ordered ? (e.start ?? 0) +
|
|
752
|
+
for (const [p, o] of e?.items?.entries() ?? []) {
|
|
753
|
+
const l = e.ordered ? (e.start ?? 0) + p : e.start;
|
|
754
754
|
r(
|
|
755
755
|
o,
|
|
756
756
|
i + 1,
|
|
@@ -759,51 +759,51 @@ const nt = (t, e, i, r) => {
|
|
|
759
759
|
e.ordered
|
|
760
760
|
);
|
|
761
761
|
}
|
|
762
|
-
}, st = (t, e, i, r,
|
|
762
|
+
}, st = (t, e, i, r, p, o) => {
|
|
763
763
|
n.Y + C(t) >= n.options.page.maxContentHeight && Y(t);
|
|
764
|
-
const l = n.options, a = i * l.page.indent, s = o ? `${
|
|
764
|
+
const l = n.options, a = i * l.page.indent, s = o ? `${p}. ` : "• ", g = l.page.xpading;
|
|
765
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
766
|
const c = t.getTextWidth(s), f = g + a + c, d = l.page.maxContentWidth - a - c;
|
|
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(g, "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
|
+
p,
|
|
783
783
|
x.ordered ?? !1
|
|
784
784
|
)) : x.type === u.ListItem ? (m(), r(
|
|
785
785
|
x,
|
|
786
786
|
i,
|
|
787
787
|
!0,
|
|
788
|
-
|
|
788
|
+
p,
|
|
789
789
|
o
|
|
790
|
-
)) :
|
|
790
|
+
)) : h.push(x);
|
|
791
791
|
m();
|
|
792
792
|
} else if (e.content) {
|
|
793
|
-
const
|
|
793
|
+
const h = l.content?.textAlignment ?? "left";
|
|
794
794
|
T.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
|
-
}, at = (t, e, i, r,
|
|
803
|
+
}, at = (t, e, i, r, p, o, l, a = !0) => {
|
|
804
804
|
if (e?.items && e?.items.length > 0)
|
|
805
805
|
for (const s of e?.items ?? [])
|
|
806
|
-
|
|
806
|
+
p(
|
|
807
807
|
s,
|
|
808
808
|
i,
|
|
809
809
|
r,
|
|
@@ -815,33 +815,33 @@ const nt = (t, e, i, r) => {
|
|
|
815
815
|
const s = n.options, g = i * s.page.indent, c = r ? l ? `${o}. ` : "• " : "", f = e.content || "", d = s.page.xpading;
|
|
816
816
|
if (!f && !c) return;
|
|
817
817
|
if (!f.trim() && !c) {
|
|
818
|
-
const
|
|
819
|
-
if (
|
|
820
|
-
const m =
|
|
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, F = m * x;
|
|
821
821
|
n.Y + F > s.page.maxContentHeight ? Y(t) : (n.updateY(F, "add"), n.recordContentY(n.Y));
|
|
822
822
|
}
|
|
823
823
|
return;
|
|
824
824
|
}
|
|
825
825
|
if (n.updateX(d, "set"), r && c) {
|
|
826
|
-
const
|
|
826
|
+
const h = t.getTextWidth(c), m = s.page.maxContentWidth - g - h;
|
|
827
827
|
t.setFont(s.font.regular.name, s.font.regular.style), t.text(c, d + g, n.Y, {
|
|
828
828
|
baseline: "top"
|
|
829
829
|
}), T.renderText(
|
|
830
830
|
t,
|
|
831
831
|
f,
|
|
832
|
-
d + g +
|
|
832
|
+
d + g + h,
|
|
833
833
|
n.Y,
|
|
834
834
|
m,
|
|
835
835
|
a
|
|
836
836
|
);
|
|
837
837
|
} else {
|
|
838
|
-
const
|
|
838
|
+
const h = s.page.maxContentWidth - g;
|
|
839
839
|
T.renderText(
|
|
840
840
|
t,
|
|
841
841
|
f,
|
|
842
842
|
d + g,
|
|
843
843
|
n.Y,
|
|
844
|
-
|
|
844
|
+
h,
|
|
845
845
|
a
|
|
846
846
|
);
|
|
847
847
|
}
|
|
@@ -856,41 +856,41 @@ const nt = (t, e, i, r) => {
|
|
|
856
856
|
n.Y
|
|
857
857
|
), t.setLineWidth(0.1), t.setLineDashPattern([], 0), n.updateY(C(t), "add");
|
|
858
858
|
}, rt = (t, e, i, r) => {
|
|
859
|
-
const
|
|
859
|
+
const p = t.getFont(), o = t.getFontSize();
|
|
860
860
|
t.setFont("courier", "normal");
|
|
861
861
|
const l = n.options.page.defaultFontSize * 0.9;
|
|
862
862
|
t.setFontSize(l);
|
|
863
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]+$/, "");
|
|
864
864
|
if (!d) {
|
|
865
|
-
t.setFont(
|
|
865
|
+
t.setFont(p.fontName, p.fontStyle), t.setFontSize(o);
|
|
866
866
|
return;
|
|
867
867
|
}
|
|
868
|
-
const
|
|
869
|
-
for (;
|
|
870
|
-
|
|
871
|
-
if (
|
|
872
|
-
t.setFont(
|
|
868
|
+
const h = t.splitTextToSize(d, s);
|
|
869
|
+
for (; h.length > 0 && h[h.length - 1].trim() === ""; )
|
|
870
|
+
h.pop();
|
|
871
|
+
if (h.length === 0) {
|
|
872
|
+
t.setFont(p.fontName, p.fontStyle), t.setFontSize(o);
|
|
873
873
|
return;
|
|
874
874
|
}
|
|
875
875
|
const m = 4, x = "#EEEEEE", F = "#DDDDDD";
|
|
876
876
|
let b = 0;
|
|
877
|
-
for (; b <
|
|
878
|
-
const
|
|
877
|
+
for (; b < h.length; ) {
|
|
878
|
+
const y = n.options.page.maxContentHeight - n.Y, w = h.length - b, L = y - m * 2;
|
|
879
879
|
let S = Math.floor(L / c);
|
|
880
880
|
if (S <= 0) {
|
|
881
881
|
Y(t);
|
|
882
882
|
continue;
|
|
883
883
|
}
|
|
884
884
|
S > w && (S = w);
|
|
885
|
-
const
|
|
885
|
+
const j = h.slice(
|
|
886
886
|
b,
|
|
887
887
|
b + S
|
|
888
|
-
), E = b === 0, X = b + S >=
|
|
888
|
+
), E = b === 0, X = b + S >= h.length, N = S * c;
|
|
889
889
|
if (E && n.updateY(m, "add"), t.setFillColor(x), t.setDrawColor(F), t.roundedRect(
|
|
890
890
|
n.X,
|
|
891
891
|
n.Y - m,
|
|
892
892
|
n.options.page.maxContentWidth,
|
|
893
|
-
|
|
893
|
+
N + (E ? m : 0) + (X ? m : 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 j)
|
|
908
|
+
t.text(P, n.X + 4, R, { baseline: "top" }), R += c;
|
|
909
|
+
n.updateY(N, "add"), n.recordContentY(n.Y + (X ? m : 0)), X && n.updateY(m, "add"), b += S, b < h.length && Y(t);
|
|
910
910
|
}
|
|
911
|
-
t.setFont(
|
|
911
|
+
t.setFont(p.fontName, p.fontStyle), t.setFontSize(o);
|
|
912
912
|
}, lt = (t, e, i) => {
|
|
913
|
-
const r = t.getFont().fontName,
|
|
913
|
+
const r = t.getFont().fontName, p = t.getFont().fontStyle, o = t.getFontSize(), l = (s) => {
|
|
914
914
|
switch (s) {
|
|
915
915
|
case "normal":
|
|
916
916
|
return 0;
|
|
@@ -934,18 +934,18 @@ const nt = (t, e, i, r) => {
|
|
|
934
934
|
"bolditalic"
|
|
935
935
|
) : g === "codespan" ? (t.setFont("courier", "normal"), t.setFontSize(o * 0.9)) : t.setFont(
|
|
936
936
|
n.options.font.regular.name,
|
|
937
|
-
|
|
937
|
+
p
|
|
938
938
|
);
|
|
939
|
-
const c = n.options.page.maxContentWidth - i - n.X, f = t.splitTextToSize(s, c), d = g === "codespan",
|
|
939
|
+
const c = n.options.page.maxContentWidth - i - n.X, f = t.splitTextToSize(s, c), d = g === "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 F = t.getTextWidth(f[x]) +
|
|
943
|
+
const F = t.getTextWidth(f[x]) + H(t), b = C(t);
|
|
944
944
|
t.setFillColor(m), t.roundedRect(
|
|
945
|
-
n.X + i -
|
|
946
|
-
n.Y -
|
|
947
|
-
F +
|
|
948
|
-
b +
|
|
945
|
+
n.X + i - h,
|
|
946
|
+
n.Y - h,
|
|
947
|
+
F + h * 2,
|
|
948
|
+
b + h * 2,
|
|
949
949
|
2,
|
|
950
950
|
2,
|
|
951
951
|
"F"
|
|
@@ -955,7 +955,7 @@ const nt = (t, e, i, r) => {
|
|
|
955
955
|
baseline: "top",
|
|
956
956
|
maxWidth: c
|
|
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
960
|
), x < f.length - 1 && (n.updateY(C(t), "add"), n.updateX(
|
|
961
961
|
n.options.page.xpading,
|
|
@@ -965,12 +965,12 @@ const nt = (t, e, i, r) => {
|
|
|
965
965
|
else if (f.length > 1) {
|
|
966
966
|
const x = f[0], F = f?.slice(1)?.join(" ");
|
|
967
967
|
if (d) {
|
|
968
|
-
const w = t.getTextWidth(x) +
|
|
968
|
+
const w = t.getTextWidth(x) + H(t), L = C(t);
|
|
969
969
|
t.setFillColor(m), t.roundedRect(
|
|
970
|
-
n.X + (i >= 2 ? i + 2 : 0) -
|
|
971
|
-
n.Y -
|
|
972
|
-
w +
|
|
973
|
-
L +
|
|
970
|
+
n.X + (i >= 2 ? i + 2 : 0) - h,
|
|
971
|
+
n.Y - h,
|
|
972
|
+
w + h * 2,
|
|
973
|
+
L + h * 2,
|
|
974
974
|
2,
|
|
975
975
|
2,
|
|
976
976
|
"F"
|
|
@@ -991,12 +991,12 @@ const nt = (t, e, i, r) => {
|
|
|
991
991
|
b
|
|
992
992
|
).forEach((w) => {
|
|
993
993
|
if (d) {
|
|
994
|
-
const L = t.getTextWidth(w) +
|
|
994
|
+
const L = t.getTextWidth(w) + H(t), S = C(t);
|
|
995
995
|
t.setFillColor(m), t.roundedRect(
|
|
996
|
-
n.X +
|
|
997
|
-
n.Y -
|
|
998
|
-
L +
|
|
999
|
-
S +
|
|
996
|
+
n.X + H(t) - h,
|
|
997
|
+
n.Y - h,
|
|
998
|
+
L + h * 2,
|
|
999
|
+
S + h * 2,
|
|
1000
1000
|
2,
|
|
1001
1001
|
2,
|
|
1002
1002
|
"F"
|
|
@@ -1004,7 +1004,7 @@ const nt = (t, e, i, r) => {
|
|
|
1004
1004
|
}
|
|
1005
1005
|
t.text(
|
|
1006
1006
|
w,
|
|
1007
|
-
n.X +
|
|
1007
|
+
n.X + H(t),
|
|
1008
1008
|
n.Y,
|
|
1009
1009
|
{
|
|
1010
1010
|
baseline: "top",
|
|
@@ -1014,12 +1014,12 @@ const nt = (t, e, i, r) => {
|
|
|
1014
1014
|
});
|
|
1015
1015
|
} else {
|
|
1016
1016
|
if (d) {
|
|
1017
|
-
const x = t.getTextWidth(s) +
|
|
1017
|
+
const x = t.getTextWidth(s) + H(t), F = C(t);
|
|
1018
1018
|
t.setFillColor(m), t.roundedRect(
|
|
1019
|
-
n.X + i -
|
|
1020
|
-
n.Y -
|
|
1021
|
-
x +
|
|
1022
|
-
F +
|
|
1019
|
+
n.X + i - h,
|
|
1020
|
+
n.Y - h,
|
|
1021
|
+
x + h * 2,
|
|
1022
|
+
F + h * 2,
|
|
1023
1023
|
2,
|
|
1024
1024
|
2,
|
|
1025
1025
|
"F"
|
|
@@ -1029,7 +1029,7 @@ const nt = (t, e, i, r) => {
|
|
|
1029
1029
|
baseline: "top",
|
|
1030
1030
|
maxWidth: c
|
|
1031
1031
|
}), n.updateX(
|
|
1032
|
-
t.getTextDimensions(s).w + (i >= 2 ? s.split(" ").length + 2 : 2) * l(g) * 0.5 + (d ?
|
|
1032
|
+
t.getTextDimensions(s).w + (i >= 2 ? s.split(" ").length + 2 : 2) * l(g) * 0.5 + (d ? h * 2 : 0),
|
|
1033
1033
|
"add"
|
|
1034
1034
|
);
|
|
1035
1035
|
}
|
|
@@ -1054,24 +1054,24 @@ const nt = (t, e, i, r) => {
|
|
|
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,
|
|
1057
|
+
t.setFont(r, p), t.setFontSize(o);
|
|
1058
1058
|
}, gt = (t, e, i) => {
|
|
1059
|
-
const r = t.getFont().fontName,
|
|
1059
|
+
const r = t.getFont().fontName, p = t.getFont().fontStyle, o = t.getFontSize(), l = t.getTextColor(), a = n.options.link?.linkColor || [0, 0, 255];
|
|
1060
1060
|
t.setTextColor(...a);
|
|
1061
1061
|
const s = n.options.page.maxContentWidth - i - n.X, g = e.text || e.content || "", c = e.href || "", f = t.splitTextToSize(g, 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 = C(t) / 2;
|
|
1065
1065
|
t.link(
|
|
1066
1066
|
n.X + i,
|
|
1067
1067
|
n.Y,
|
|
1068
|
-
|
|
1068
|
+
h,
|
|
1069
1069
|
m,
|
|
1070
1070
|
{ url: c }
|
|
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,7 +1080,7 @@ 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 = C(t) / 2;
|
|
1084
1084
|
t.link(
|
|
1085
1085
|
n.X + i,
|
|
1086
1086
|
n.Y,
|
|
@@ -1092,17 +1092,17 @@ const nt = (t, e, i, r) => {
|
|
|
1092
1092
|
maxWidth: s
|
|
1093
1093
|
}), n.updateX(n.options.page.xpading + i), n.updateY(x, "add");
|
|
1094
1094
|
const F = n.options.page.maxContentWidth - i - n.options.page.xpading;
|
|
1095
|
-
t.splitTextToSize(
|
|
1096
|
-
const w = t.getTextDimensions(
|
|
1095
|
+
t.splitTextToSize(h, F).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
1102
|
{ url: c }
|
|
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",
|
|
@@ -1111,33 +1111,33 @@ const nt = (t, e, i, r) => {
|
|
|
1111
1111
|
);
|
|
1112
1112
|
});
|
|
1113
1113
|
} else {
|
|
1114
|
-
const d = t.getTextDimensions(g).w,
|
|
1114
|
+
const d = t.getTextDimensions(g).w, h = C(t) / 2;
|
|
1115
1115
|
t.link(
|
|
1116
1116
|
n.X + i,
|
|
1117
1117
|
n.Y,
|
|
1118
1118
|
d,
|
|
1119
|
-
|
|
1119
|
+
h,
|
|
1120
1120
|
{ url: c }
|
|
1121
1121
|
), t.text(g, 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,
|
|
1126
|
+
t.setFont(r, p), t.setFontSize(o), t.setTextColor(l);
|
|
1127
1127
|
}, ct = (t, e, i, r) => {
|
|
1128
|
-
const
|
|
1129
|
-
e.items && e.items.length > 0 && e.items.forEach((
|
|
1130
|
-
r(
|
|
1128
|
+
const p = n.options, o = i + 1, l = n.X + i * p.page.indent, a = n.Y, s = l + p.page.indent / 2, g = a, c = 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 =
|
|
1134
|
+
for (let h = c; h <= d; h++) {
|
|
1135
|
+
t.setPage(h);
|
|
1136
|
+
const m = h === c, x = h === d, F = m ? g : p.page.topmargin, b = x ? f : p.page.maxContentHeight;
|
|
1137
1137
|
t.line(s, F, s, b);
|
|
1138
1138
|
}
|
|
1139
1139
|
n.recordContentY(), t.setPage(d);
|
|
1140
|
-
},
|
|
1140
|
+
}, pt = (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"))
|
|
@@ -1151,38 +1151,38 @@ const nt = (t, e, i, r) => {
|
|
|
1151
1151
|
return i === "JPG" ? "JPEG" : i;
|
|
1152
1152
|
}
|
|
1153
1153
|
return "JPEG";
|
|
1154
|
-
},
|
|
1154
|
+
}, ht = (t, e, i) => {
|
|
1155
1155
|
if (!e.data)
|
|
1156
1156
|
return;
|
|
1157
|
-
const r = n.options,
|
|
1157
|
+
const r = n.options, p = r.page.unit || "mm", o = i * r.page.indent, l = r.page.maxContentWidth - o, a = n.X + o;
|
|
1158
1158
|
let s = n.Y;
|
|
1159
1159
|
try {
|
|
1160
|
-
const g = r.page.maxContentHeight - r.page.topmargin, { finalWidth: c, finalHeight: f } =
|
|
1160
|
+
const g = r.page.maxContentHeight - r.page.topmargin, { finalWidth: c, finalHeight: f } = $(
|
|
1161
1161
|
t,
|
|
1162
1162
|
e,
|
|
1163
1163
|
l,
|
|
1164
1164
|
g,
|
|
1165
|
-
|
|
1165
|
+
p
|
|
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 + l - c;
|
|
1173
1173
|
break;
|
|
1174
1174
|
case "center":
|
|
1175
|
-
|
|
1175
|
+
h = a + (l - c) / 2;
|
|
1176
1176
|
break;
|
|
1177
1177
|
default:
|
|
1178
|
-
|
|
1178
|
+
h = a;
|
|
1179
1179
|
break;
|
|
1180
1180
|
}
|
|
1181
|
-
const m =
|
|
1181
|
+
const m = pt(e);
|
|
1182
1182
|
c > 0 && f > 0 && t.addImage(
|
|
1183
1183
|
e.data,
|
|
1184
1184
|
m,
|
|
1185
|
-
|
|
1185
|
+
h,
|
|
1186
1186
|
s,
|
|
1187
1187
|
c,
|
|
1188
1188
|
f
|
|
@@ -1190,17 +1190,28 @@ const nt = (t, e, i, r) => {
|
|
|
1190
1190
|
} catch (g) {
|
|
1191
1191
|
console.warn("Failed to render image", g);
|
|
1192
1192
|
}
|
|
1193
|
-
}, ft = (
|
|
1193
|
+
}, ft = () => {
|
|
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
|
+
);
|
|
1204
|
+
}, dt = (t, e, i) => {
|
|
1194
1205
|
if (!e.header || !e.rows)
|
|
1195
1206
|
return;
|
|
1196
|
-
const r = n.options,
|
|
1207
|
+
const r = n.options, p = r.page.xmargin + i * r.page.indent, o = [e.header.map((s) => s.content || "")], l = e.rows.map(
|
|
1197
1208
|
(s) => s.map((g) => g.content || "")
|
|
1198
1209
|
), a = r.table || {};
|
|
1199
|
-
|
|
1210
|
+
ft()(t, {
|
|
1200
1211
|
head: o,
|
|
1201
1212
|
body: l,
|
|
1202
1213
|
startY: n.Y,
|
|
1203
|
-
margin: { left:
|
|
1214
|
+
margin: { left: p, 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,
|
|
@@ -1235,21 +1246,21 @@ const nt = (t, e, i, r) => {
|
|
|
1235
1246
|
image: {
|
|
1236
1247
|
defaultAlign: "left"
|
|
1237
1248
|
}
|
|
1238
|
-
},
|
|
1249
|
+
}, ut = (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,
|
|
1245
1256
|
font: i,
|
|
1246
1257
|
image: r
|
|
1247
1258
|
};
|
|
1248
|
-
},
|
|
1249
|
-
const r =
|
|
1259
|
+
}, bt = async (t, e, i) => {
|
|
1260
|
+
const r = ut(i);
|
|
1250
1261
|
n.initialize(r);
|
|
1251
|
-
const
|
|
1252
|
-
await
|
|
1262
|
+
const p = await M(e);
|
|
1263
|
+
await J(p);
|
|
1253
1264
|
const o = (l, a = 0, s = !1, g = 0, c = !1, f = !0) => {
|
|
1254
1265
|
const d = a * r.page.indent;
|
|
1255
1266
|
switch (l.type) {
|
|
@@ -1290,10 +1301,10 @@ const nt = (t, e, i, r) => {
|
|
|
1290
1301
|
ct(t, l, a, o);
|
|
1291
1302
|
break;
|
|
1292
1303
|
case u.Image:
|
|
1293
|
-
|
|
1304
|
+
ht(t, l, a);
|
|
1294
1305
|
break;
|
|
1295
1306
|
case u.Table:
|
|
1296
|
-
|
|
1307
|
+
dt(t, l, a);
|
|
1297
1308
|
break;
|
|
1298
1309
|
case u.Raw:
|
|
1299
1310
|
case u.Text:
|
|
@@ -1319,11 +1330,11 @@ const nt = (t, e, i, r) => {
|
|
|
1319
1330
|
break;
|
|
1320
1331
|
}
|
|
1321
1332
|
};
|
|
1322
|
-
for (const l of
|
|
1333
|
+
for (const l of p)
|
|
1323
1334
|
o(l);
|
|
1324
1335
|
r.endCursorYHandler(n.Y);
|
|
1325
1336
|
};
|
|
1326
1337
|
export {
|
|
1327
1338
|
M as MdTextParser,
|
|
1328
|
-
|
|
1339
|
+
bt as MdTextRender
|
|
1329
1340
|
};
|