Skip to content

Commit a53981e

Browse files
authored
🤖 Merge PR DefinitelyTyped#74433 [pdfmake] Add properties for 0.3.3 by @kryops
1 parent ccae791 commit a53981e

File tree

3 files changed

+134
-7
lines changed

3 files changed

+134
-7
lines changed

types/pdfmake/interfaces.d.ts

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,21 @@ export interface Style {
726726
*/
727727
decorationColor?: string | undefined;
728728

729+
/**
730+
* Line thickness of the {@link decoration} in `pt`.
731+
*
732+
* If used in combination with a {@link decorationStyle}, this value is only used as a baseline
733+
* for the computation of the actual line width.
734+
*
735+
* Defaults to a value derived from the {@link fontSize}.
736+
*/
737+
decorationThickness?: number | undefined;
738+
729739
/**
730740
* Margins to apply.
731741
*
732742
* Overrides the single-side `marginXXX` properties, unless this value is inherited
733-
* from a style and they are set directly on the content object.
743+
* from another style.
734744
*
735745
* Ignored for content within an inline text array
736746
* (`{ text: [{ ... }] }`).
@@ -741,31 +751,31 @@ export interface Style {
741751
* Margin in `pt` to apply above the content.
742752
*
743753
* If {@link margin} is set, this value is ignored, unless the margin was inherited
744-
* from a style and the value is set directly on the content object.
754+
* from another style.
745755
*/
746756
marginTop?: number | undefined;
747757

748758
/**
749759
* Margin in `pt` to apply to the right of the content.
750760
*
751761
* If {@link margin} is set, this value is ignored, unless the margin was inherited
752-
* from a style and the value is set directly on the content object.
762+
* from another style.
753763
*/
754764
marginRight?: number | undefined;
755765

756766
/**
757767
* Margin in `pt` to apply below the content.
758768
*
759769
* If {@link margin} is set, this value is ignored, unless the margin was inherited
760-
* from a style and the value is set directly on the content object.
770+
* from another style.
761771
*/
762772
marginBottom?: number | undefined;
763773

764774
/**
765775
* Margin in `pt` to apply to the left of the content.
766776
*
767777
* If {@link margin} is set, this value is ignored, unless the margin was inherited
768-
* from a style and the value is set directly on the content object.
778+
* from another style.
769779
*/
770780
marginLeft?: number | undefined;
771781

@@ -872,6 +882,21 @@ export interface Style {
872882
columnGap?: number | undefined;
873883
}
874884

885+
/**
886+
* Named style defined in {@link TDocumentDefinitions.styles}.
887+
*/
888+
export interface NamedStyle extends Style {
889+
/**
890+
* Names of other styles in {@link TDocumentDefinitions.styles} to extend.
891+
*
892+
* An array applies the styles in the given order, later styles overriding
893+
* properties from the earlier ones.
894+
*
895+
* Extended styles are overridden by the properties on this style.
896+
*/
897+
extends?: string | string[] | undefined;
898+
}
899+
875900
/**
876901
* Applies one or more styles.
877902
*
@@ -1623,6 +1648,27 @@ export interface TableOfContent {
16231648
* {@link ContentTocItem.tocItem} to its ID
16241649
*/
16251650
id?: string | undefined;
1651+
1652+
/**
1653+
* If set to `true`, the table of contents is hidden when it contains no items.
1654+
*/
1655+
hideEmpty?: boolean | undefined;
1656+
1657+
/**
1658+
* Controls how the items are sorted.
1659+
*
1660+
* Defaults to `page`.
1661+
*/
1662+
sortBy?: "page" | "title" | undefined;
1663+
1664+
/**
1665+
* Specifies the locale used for sorting as BCP 47 language tag, e.g. `en-US`.
1666+
*
1667+
* Only relevant if {@link sortBy} is set to `title`.
1668+
*
1669+
* Defaults to the system locale.
1670+
*/
1671+
sortLocale?: string | undefined;
16261672
}
16271673

16281674
/**
@@ -1990,7 +2036,7 @@ export interface ImageCover {
19902036
* Dictionary of reusable style definitions that can be referenced by their key.
19912037
*/
19922038
export interface StyleDictionary {
1993-
[name: string]: Style;
2039+
[name: string]: NamedStyle;
19942040
}
19952041

19962042
/**
@@ -2264,7 +2310,7 @@ export interface TDocumentDefinitions {
22642310
/**
22652311
* Dictionary for reusable styles to be referenced by their key throughout the document.
22662312
*
2267-
* To define styles that should apply by default, use {@link defaultStyles} instead.
2313+
* To define styles that should apply by default, use {@link defaultStyle} instead.
22682314
*/
22692315
styles?: StyleDictionary | undefined;
22702316

types/pdfmake/test/pdfmake-examples-tests.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,50 @@ const margins: TDocumentDefinitions = {
912912
},
913913
};
914914

915+
const namedStylesWithExtends: TDocumentDefinitions = {
916+
content: [
917+
{
918+
text: "This is a header, using header style",
919+
style: "header",
920+
},
921+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam.\n\n",
922+
{
923+
text: "Subheader 1 - using subheader style",
924+
style: "subheader",
925+
},
926+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam posset, eveniunt specie deorsus efficiat sermone instituendarum fuisse veniat, eademque mutat debeo. Delectet plerique protervi diogenem dixerit logikh levius probabo adipiscuntur afficitur, factis magistra inprobitatem aliquo andriam obiecta, religionis, imitarentur studiis quam, clamat intereant vulgo admonitionem operis iudex stabilitas vacillare scriptum nixam, reperiri inveniri maestitiam istius eaque dissentias idcirco gravis, refert suscipiet recte sapiens oportet ipsam terentianus, perpauca sedatio aliena video.",
927+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam posset, eveniunt specie deorsus efficiat sermone instituendarum fuisse veniat, eademque mutat debeo. Delectet plerique protervi diogenem dixerit logikh levius probabo adipiscuntur afficitur, factis magistra inprobitatem aliquo andriam obiecta, religionis, imitarentur studiis quam, clamat intereant vulgo admonitionem operis iudex stabilitas vacillare scriptum nixam, reperiri inveniri maestitiam istius eaque dissentias idcirco gravis, refert suscipiet recte sapiens oportet ipsam terentianus, perpauca sedatio aliena video.",
928+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam posset, eveniunt specie deorsus efficiat sermone instituendarum fuisse veniat, eademque mutat debeo. Delectet plerique protervi diogenem dixerit logikh levius probabo adipiscuntur afficitur, factis magistra inprobitatem aliquo andriam obiecta, religionis, imitarentur studiis quam, clamat intereant vulgo admonitionem operis iudex stabilitas vacillare scriptum nixam, reperiri inveniri maestitiam istius eaque dissentias idcirco gravis, refert suscipiet recte sapiens oportet ipsam terentianus, perpauca sedatio aliena video.\n\n",
929+
{
930+
text: "Subheader 2 - using subheader style",
931+
style: "subheader",
932+
},
933+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam posset, eveniunt specie deorsus efficiat sermone instituendarum fuisse veniat, eademque mutat debeo. Delectet plerique protervi diogenem dixerit logikh levius probabo adipiscuntur afficitur, factis magistra inprobitatem aliquo andriam obiecta, religionis, imitarentur studiis quam, clamat intereant vulgo admonitionem operis iudex stabilitas vacillare scriptum nixam, reperiri inveniri maestitiam istius eaque dissentias idcirco gravis, refert suscipiet recte sapiens oportet ipsam terentianus, perpauca sedatio aliena video.",
934+
"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Confectum ponit legam, perferendis nomine miserum, animi. Moveat nesciunt triari naturam posset, eveniunt specie deorsus efficiat sermone instituendarum fuisse veniat, eademque mutat debeo. Delectet plerique protervi diogenem dixerit logikh levius probabo adipiscuntur afficitur, factis magistra inprobitatem aliquo andriam obiecta, religionis, imitarentur studiis quam, clamat intereant vulgo admonitionem operis iudex stabilitas vacillare scriptum nixam, reperiri inveniri maestitiam istius eaque dissentias idcirco gravis, refert suscipiet recte sapiens oportet ipsam terentianus, perpauca sedatio aliena video.\n\n",
935+
{
936+
text:
937+
"It is possible to apply multiple styles, by passing an array. This paragraph uses two styles: quote and small. When multiple styles are provided, they are evaluated in the specified order which is important in case they define the same properties",
938+
style: ["quote", "small"],
939+
},
940+
],
941+
styles: {
942+
header: {
943+
fontSize: 18,
944+
bold: true,
945+
},
946+
subheader: {
947+
fontSize: 15,
948+
extends: "header",
949+
},
950+
quote: {
951+
italics: true,
952+
},
953+
small: {
954+
fontSize: 8,
955+
},
956+
},
957+
};
958+
915959
const pageReference: TDocumentDefinitions = {
916960
content: [
917961
{
@@ -2467,6 +2511,15 @@ const textDecorations: TDocumentDefinitions = {
24672511
},
24682512
],
24692513
},
2514+
" ",
2515+
{
2516+
columns: [
2517+
{ text: "Dashed style", decoration: "underline", decorationStyle: "dashed", decorationThickness: 3 },
2518+
{ text: "Dotted style", decoration: "underline", decorationStyle: "dotted", decorationThickness: 3 },
2519+
{ text: "Double style", decoration: "underline", decorationStyle: "double", decorationThickness: 3 },
2520+
{ text: "Wavy style", decoration: "underline", decorationStyle: "wavy", decorationThickness: 3 },
2521+
],
2522+
},
24702523
],
24712524
};
24722525

@@ -2483,6 +2536,8 @@ const toc: TDocumentDefinitions = {
24832536
textMargin: [0, 0, 0, 0],
24842537
textStyle: { italics: true },
24852538
numberStyle: { bold: true },
2539+
sortBy: "page",
2540+
sortLocale: "cs",
24862541
},
24872542
},
24882543
{

types/pdfmake/test/pdfmake-interfaces-tests.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
ContentImage,
66
ContentOrderedList,
77
ContentSvg,
8+
ContentToc,
89
ContentUnorderedList,
910
CustomTableLayout,
11+
StyleDictionary,
1012
Table,
1113
TableCell,
1214
TDocumentDefinitions,
@@ -403,3 +405,27 @@ const svgWithLink: Content = [
403405
link: "http://foo.bar",
404406
},
405407
];
408+
409+
const hideEmptyToC: ContentToc = {
410+
toc: {
411+
hideEmpty: true,
412+
},
413+
};
414+
415+
const styleExtends: StyleDictionary = {
416+
header: {
417+
fontSize: 18,
418+
bold: true,
419+
},
420+
subheader: {
421+
fontSize: 15,
422+
extends: "header",
423+
},
424+
smallheader: {
425+
italics: true,
426+
extends: ["subheader", "small"],
427+
},
428+
small: {
429+
fontSize: 8,
430+
},
431+
};

0 commit comments

Comments
 (0)