jspdf-md-renderer 3.5.0 → 3.5.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 +50 -36
- package/dist/index.mjs +50 -36
- package/dist/index.umd.js +50 -36
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -330,28 +330,6 @@ const getCharWidth = (doc) => {
|
|
|
330
330
|
return doc.getTextDimensions("H").w;
|
|
331
331
|
};
|
|
332
332
|
//#endregion
|
|
333
|
-
//#region src/renderer/components/heading.ts
|
|
334
|
-
/**
|
|
335
|
-
* Renders heading elements.
|
|
336
|
-
*/
|
|
337
|
-
const renderHeading = (doc, element, indent, store, parentElementRenderer) => {
|
|
338
|
-
const size = 6 - (element?.depth ?? 0) > 0 ? 6 - (element?.depth ?? 0) : 1;
|
|
339
|
-
doc.setFontSize(store.options.page.defaultFontSize + size);
|
|
340
|
-
if (element?.items && element?.items.length > 0) for (const item of element?.items ?? []) parentElementRenderer(item, indent, store, false);
|
|
341
|
-
else {
|
|
342
|
-
const charHeight = getCharHight(doc);
|
|
343
|
-
doc.text(element?.content ?? "", store.X + indent, store.Y, {
|
|
344
|
-
align: "left",
|
|
345
|
-
maxWidth: store.options.page.maxContentWidth - indent,
|
|
346
|
-
baseline: "top"
|
|
347
|
-
});
|
|
348
|
-
store.recordContentY(store.Y + charHeight);
|
|
349
|
-
store.updateY(getCharHight(doc), "add");
|
|
350
|
-
}
|
|
351
|
-
doc.setFontSize(store.options.page.defaultFontSize);
|
|
352
|
-
store.updateX(store.options.page.xpading, "set");
|
|
353
|
-
};
|
|
354
|
-
//#endregion
|
|
355
333
|
//#region src/utils/handlePageBreak.ts
|
|
356
334
|
const HandlePageBreaks = (doc, store) => {
|
|
357
335
|
if (typeof store.options.pageBreakHandler === "function") store.options.pageBreakHandler(doc);
|
|
@@ -674,21 +652,31 @@ var JustifiedTextRenderer = class {
|
|
|
674
652
|
});
|
|
675
653
|
continue;
|
|
676
654
|
}
|
|
677
|
-
const
|
|
678
|
-
for (let
|
|
679
|
-
const
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
655
|
+
const lines = text.split("\n");
|
|
656
|
+
for (let partIndex = 0; partIndex < lines.length; partIndex++) {
|
|
657
|
+
const lineStr = lines[partIndex];
|
|
658
|
+
const words = lineStr.trim().split(/[ \t\r\v\f]+/).filter((w) => w.length > 0);
|
|
659
|
+
for (let i = 0; i < words.length; i++) {
|
|
660
|
+
const hasTrailingSpace = !(i === words.length - 1) || /[ \t\r\v\f]$/.test(lineStr);
|
|
661
|
+
result.push({
|
|
662
|
+
text: words[i],
|
|
663
|
+
width: this.measureWordWidth(doc, words[i], style, store),
|
|
664
|
+
style,
|
|
665
|
+
isLink: elIsLink,
|
|
666
|
+
href: elHref,
|
|
667
|
+
linkColor: elIsLink ? store.options.link?.linkColor || [
|
|
668
|
+
0,
|
|
669
|
+
0,
|
|
670
|
+
255
|
|
671
|
+
] : void 0,
|
|
672
|
+
hasTrailingSpace
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
if (partIndex < lines.length - 1) result.push({
|
|
676
|
+
text: "",
|
|
677
|
+
width: 0,
|
|
683
678
|
style,
|
|
684
|
-
|
|
685
|
-
href: elHref,
|
|
686
|
-
linkColor: elIsLink ? store.options.link?.linkColor || [
|
|
687
|
-
0,
|
|
688
|
-
0,
|
|
689
|
-
255
|
|
690
|
-
] : void 0,
|
|
691
|
-
hasTrailingSpace
|
|
679
|
+
isBr: true
|
|
692
680
|
});
|
|
693
681
|
}
|
|
694
682
|
}
|
|
@@ -886,6 +874,32 @@ var JustifiedTextRenderer = class {
|
|
|
886
874
|
}
|
|
887
875
|
};
|
|
888
876
|
//#endregion
|
|
877
|
+
//#region src/renderer/components/heading.ts
|
|
878
|
+
/**
|
|
879
|
+
* Renders heading elements.
|
|
880
|
+
*/
|
|
881
|
+
const renderHeading = (doc, element, indent, store, parentElementRenderer) => {
|
|
882
|
+
const size = 6 - (element?.depth ?? 0) > 0 ? 6 - (element?.depth ?? 0) : 1;
|
|
883
|
+
doc.setFontSize(store.options.page.defaultFontSize + size);
|
|
884
|
+
if (element?.items && element?.items.length > 0) {
|
|
885
|
+
const originalLineHeightFactor = store.options.page.defaultLineHeightFactor;
|
|
886
|
+
store.options.page.defaultLineHeightFactor = 1;
|
|
887
|
+
JustifiedTextRenderer.renderStyledParagraph(doc, element.items, store.X + indent, store.Y, store.options.page.maxContentWidth - indent, store, "left");
|
|
888
|
+
store.options.page.defaultLineHeightFactor = originalLineHeightFactor;
|
|
889
|
+
} else {
|
|
890
|
+
const charHeight = getCharHight(doc);
|
|
891
|
+
doc.text(element?.content ?? "", store.X + indent, store.Y, {
|
|
892
|
+
align: "left",
|
|
893
|
+
maxWidth: store.options.page.maxContentWidth - indent,
|
|
894
|
+
baseline: "top"
|
|
895
|
+
});
|
|
896
|
+
store.recordContentY(store.Y + charHeight);
|
|
897
|
+
store.updateY(getCharHight(doc), "add");
|
|
898
|
+
}
|
|
899
|
+
doc.setFontSize(store.options.page.defaultFontSize);
|
|
900
|
+
store.updateX(store.options.page.xpading, "set");
|
|
901
|
+
};
|
|
902
|
+
//#endregion
|
|
889
903
|
//#region src/utils/text-renderer.ts
|
|
890
904
|
var TextRenderer = class {
|
|
891
905
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -306,28 +306,6 @@ const getCharWidth = (doc) => {
|
|
|
306
306
|
return doc.getTextDimensions("H").w;
|
|
307
307
|
};
|
|
308
308
|
//#endregion
|
|
309
|
-
//#region src/renderer/components/heading.ts
|
|
310
|
-
/**
|
|
311
|
-
* Renders heading elements.
|
|
312
|
-
*/
|
|
313
|
-
const renderHeading = (doc, element, indent, store, parentElementRenderer) => {
|
|
314
|
-
const size = 6 - (element?.depth ?? 0) > 0 ? 6 - (element?.depth ?? 0) : 1;
|
|
315
|
-
doc.setFontSize(store.options.page.defaultFontSize + size);
|
|
316
|
-
if (element?.items && element?.items.length > 0) for (const item of element?.items ?? []) parentElementRenderer(item, indent, store, false);
|
|
317
|
-
else {
|
|
318
|
-
const charHeight = getCharHight(doc);
|
|
319
|
-
doc.text(element?.content ?? "", store.X + indent, store.Y, {
|
|
320
|
-
align: "left",
|
|
321
|
-
maxWidth: store.options.page.maxContentWidth - indent,
|
|
322
|
-
baseline: "top"
|
|
323
|
-
});
|
|
324
|
-
store.recordContentY(store.Y + charHeight);
|
|
325
|
-
store.updateY(getCharHight(doc), "add");
|
|
326
|
-
}
|
|
327
|
-
doc.setFontSize(store.options.page.defaultFontSize);
|
|
328
|
-
store.updateX(store.options.page.xpading, "set");
|
|
329
|
-
};
|
|
330
|
-
//#endregion
|
|
331
309
|
//#region src/utils/handlePageBreak.ts
|
|
332
310
|
const HandlePageBreaks = (doc, store) => {
|
|
333
311
|
if (typeof store.options.pageBreakHandler === "function") store.options.pageBreakHandler(doc);
|
|
@@ -650,21 +628,31 @@ var JustifiedTextRenderer = class {
|
|
|
650
628
|
});
|
|
651
629
|
continue;
|
|
652
630
|
}
|
|
653
|
-
const
|
|
654
|
-
for (let
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
631
|
+
const lines = text.split("\n");
|
|
632
|
+
for (let partIndex = 0; partIndex < lines.length; partIndex++) {
|
|
633
|
+
const lineStr = lines[partIndex];
|
|
634
|
+
const words = lineStr.trim().split(/[ \t\r\v\f]+/).filter((w) => w.length > 0);
|
|
635
|
+
for (let i = 0; i < words.length; i++) {
|
|
636
|
+
const hasTrailingSpace = !(i === words.length - 1) || /[ \t\r\v\f]$/.test(lineStr);
|
|
637
|
+
result.push({
|
|
638
|
+
text: words[i],
|
|
639
|
+
width: this.measureWordWidth(doc, words[i], style, store),
|
|
640
|
+
style,
|
|
641
|
+
isLink: elIsLink,
|
|
642
|
+
href: elHref,
|
|
643
|
+
linkColor: elIsLink ? store.options.link?.linkColor || [
|
|
644
|
+
0,
|
|
645
|
+
0,
|
|
646
|
+
255
|
|
647
|
+
] : void 0,
|
|
648
|
+
hasTrailingSpace
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
if (partIndex < lines.length - 1) result.push({
|
|
652
|
+
text: "",
|
|
653
|
+
width: 0,
|
|
659
654
|
style,
|
|
660
|
-
|
|
661
|
-
href: elHref,
|
|
662
|
-
linkColor: elIsLink ? store.options.link?.linkColor || [
|
|
663
|
-
0,
|
|
664
|
-
0,
|
|
665
|
-
255
|
|
666
|
-
] : void 0,
|
|
667
|
-
hasTrailingSpace
|
|
655
|
+
isBr: true
|
|
668
656
|
});
|
|
669
657
|
}
|
|
670
658
|
}
|
|
@@ -862,6 +850,32 @@ var JustifiedTextRenderer = class {
|
|
|
862
850
|
}
|
|
863
851
|
};
|
|
864
852
|
//#endregion
|
|
853
|
+
//#region src/renderer/components/heading.ts
|
|
854
|
+
/**
|
|
855
|
+
* Renders heading elements.
|
|
856
|
+
*/
|
|
857
|
+
const renderHeading = (doc, element, indent, store, parentElementRenderer) => {
|
|
858
|
+
const size = 6 - (element?.depth ?? 0) > 0 ? 6 - (element?.depth ?? 0) : 1;
|
|
859
|
+
doc.setFontSize(store.options.page.defaultFontSize + size);
|
|
860
|
+
if (element?.items && element?.items.length > 0) {
|
|
861
|
+
const originalLineHeightFactor = store.options.page.defaultLineHeightFactor;
|
|
862
|
+
store.options.page.defaultLineHeightFactor = 1;
|
|
863
|
+
JustifiedTextRenderer.renderStyledParagraph(doc, element.items, store.X + indent, store.Y, store.options.page.maxContentWidth - indent, store, "left");
|
|
864
|
+
store.options.page.defaultLineHeightFactor = originalLineHeightFactor;
|
|
865
|
+
} else {
|
|
866
|
+
const charHeight = getCharHight(doc);
|
|
867
|
+
doc.text(element?.content ?? "", store.X + indent, store.Y, {
|
|
868
|
+
align: "left",
|
|
869
|
+
maxWidth: store.options.page.maxContentWidth - indent,
|
|
870
|
+
baseline: "top"
|
|
871
|
+
});
|
|
872
|
+
store.recordContentY(store.Y + charHeight);
|
|
873
|
+
store.updateY(getCharHight(doc), "add");
|
|
874
|
+
}
|
|
875
|
+
doc.setFontSize(store.options.page.defaultFontSize);
|
|
876
|
+
store.updateX(store.options.page.xpading, "set");
|
|
877
|
+
};
|
|
878
|
+
//#endregion
|
|
865
879
|
//#region src/utils/text-renderer.ts
|
|
866
880
|
var TextRenderer = class {
|
|
867
881
|
/**
|
package/dist/index.umd.js
CHANGED
|
@@ -335,28 +335,6 @@
|
|
|
335
335
|
return doc.getTextDimensions("H").w;
|
|
336
336
|
};
|
|
337
337
|
//#endregion
|
|
338
|
-
//#region src/renderer/components/heading.ts
|
|
339
|
-
/**
|
|
340
|
-
* Renders heading elements.
|
|
341
|
-
*/
|
|
342
|
-
const renderHeading = (doc, element, indent, store, parentElementRenderer) => {
|
|
343
|
-
const size = 6 - (element?.depth ?? 0) > 0 ? 6 - (element?.depth ?? 0) : 1;
|
|
344
|
-
doc.setFontSize(store.options.page.defaultFontSize + size);
|
|
345
|
-
if (element?.items && element?.items.length > 0) for (const item of element?.items ?? []) parentElementRenderer(item, indent, store, false);
|
|
346
|
-
else {
|
|
347
|
-
const charHeight = getCharHight(doc);
|
|
348
|
-
doc.text(element?.content ?? "", store.X + indent, store.Y, {
|
|
349
|
-
align: "left",
|
|
350
|
-
maxWidth: store.options.page.maxContentWidth - indent,
|
|
351
|
-
baseline: "top"
|
|
352
|
-
});
|
|
353
|
-
store.recordContentY(store.Y + charHeight);
|
|
354
|
-
store.updateY(getCharHight(doc), "add");
|
|
355
|
-
}
|
|
356
|
-
doc.setFontSize(store.options.page.defaultFontSize);
|
|
357
|
-
store.updateX(store.options.page.xpading, "set");
|
|
358
|
-
};
|
|
359
|
-
//#endregion
|
|
360
338
|
//#region src/utils/handlePageBreak.ts
|
|
361
339
|
const HandlePageBreaks = (doc, store) => {
|
|
362
340
|
if (typeof store.options.pageBreakHandler === "function") store.options.pageBreakHandler(doc);
|
|
@@ -679,21 +657,31 @@
|
|
|
679
657
|
});
|
|
680
658
|
continue;
|
|
681
659
|
}
|
|
682
|
-
const
|
|
683
|
-
for (let
|
|
684
|
-
const
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
660
|
+
const lines = text.split("\n");
|
|
661
|
+
for (let partIndex = 0; partIndex < lines.length; partIndex++) {
|
|
662
|
+
const lineStr = lines[partIndex];
|
|
663
|
+
const words = lineStr.trim().split(/[ \t\r\v\f]+/).filter((w) => w.length > 0);
|
|
664
|
+
for (let i = 0; i < words.length; i++) {
|
|
665
|
+
const hasTrailingSpace = !(i === words.length - 1) || /[ \t\r\v\f]$/.test(lineStr);
|
|
666
|
+
result.push({
|
|
667
|
+
text: words[i],
|
|
668
|
+
width: this.measureWordWidth(doc, words[i], style, store),
|
|
669
|
+
style,
|
|
670
|
+
isLink: elIsLink,
|
|
671
|
+
href: elHref,
|
|
672
|
+
linkColor: elIsLink ? store.options.link?.linkColor || [
|
|
673
|
+
0,
|
|
674
|
+
0,
|
|
675
|
+
255
|
|
676
|
+
] : void 0,
|
|
677
|
+
hasTrailingSpace
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
if (partIndex < lines.length - 1) result.push({
|
|
681
|
+
text: "",
|
|
682
|
+
width: 0,
|
|
688
683
|
style,
|
|
689
|
-
|
|
690
|
-
href: elHref,
|
|
691
|
-
linkColor: elIsLink ? store.options.link?.linkColor || [
|
|
692
|
-
0,
|
|
693
|
-
0,
|
|
694
|
-
255
|
|
695
|
-
] : void 0,
|
|
696
|
-
hasTrailingSpace
|
|
684
|
+
isBr: true
|
|
697
685
|
});
|
|
698
686
|
}
|
|
699
687
|
}
|
|
@@ -891,6 +879,32 @@
|
|
|
891
879
|
}
|
|
892
880
|
};
|
|
893
881
|
//#endregion
|
|
882
|
+
//#region src/renderer/components/heading.ts
|
|
883
|
+
/**
|
|
884
|
+
* Renders heading elements.
|
|
885
|
+
*/
|
|
886
|
+
const renderHeading = (doc, element, indent, store, parentElementRenderer) => {
|
|
887
|
+
const size = 6 - (element?.depth ?? 0) > 0 ? 6 - (element?.depth ?? 0) : 1;
|
|
888
|
+
doc.setFontSize(store.options.page.defaultFontSize + size);
|
|
889
|
+
if (element?.items && element?.items.length > 0) {
|
|
890
|
+
const originalLineHeightFactor = store.options.page.defaultLineHeightFactor;
|
|
891
|
+
store.options.page.defaultLineHeightFactor = 1;
|
|
892
|
+
JustifiedTextRenderer.renderStyledParagraph(doc, element.items, store.X + indent, store.Y, store.options.page.maxContentWidth - indent, store, "left");
|
|
893
|
+
store.options.page.defaultLineHeightFactor = originalLineHeightFactor;
|
|
894
|
+
} else {
|
|
895
|
+
const charHeight = getCharHight(doc);
|
|
896
|
+
doc.text(element?.content ?? "", store.X + indent, store.Y, {
|
|
897
|
+
align: "left",
|
|
898
|
+
maxWidth: store.options.page.maxContentWidth - indent,
|
|
899
|
+
baseline: "top"
|
|
900
|
+
});
|
|
901
|
+
store.recordContentY(store.Y + charHeight);
|
|
902
|
+
store.updateY(getCharHight(doc), "add");
|
|
903
|
+
}
|
|
904
|
+
doc.setFontSize(store.options.page.defaultFontSize);
|
|
905
|
+
store.updateX(store.options.page.xpading, "set");
|
|
906
|
+
};
|
|
907
|
+
//#endregion
|
|
894
908
|
//#region src/utils/text-renderer.ts
|
|
895
909
|
var TextRenderer = class {
|
|
896
910
|
/**
|