abstract-document 20.2.1 → 20.2.3

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.
Files changed (44) hide show
  1. package/lib/abstract-document/styles/text-style.d.ts +3 -0
  2. package/lib/abstract-document/styles/text-style.d.ts.map +1 -1
  3. package/lib/abstract-document/styles/text-style.js +1 -0
  4. package/lib/abstract-document/styles/text-style.js.map +1 -1
  5. package/lib/abstract-document-exporters/pdf/measure.js +14 -3
  6. package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
  7. package/lib/abstract-document-exporters/pdf/render.js +12 -1
  8. package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
  9. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +1 -0
  10. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
  11. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
  12. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +22 -2
  13. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
  14. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts +15 -0
  15. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
  16. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +21 -1
  17. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
  18. package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts +6 -0
  19. package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts.map +1 -1
  20. package/lib/abstract-document-xml/xsd-template/custom-elements.js +55 -0
  21. package/lib/abstract-document-xml/xsd-template/custom-elements.js.map +1 -1
  22. package/lib/abstract-document-xml/xsd-template/elements.d.ts +13 -12
  23. package/lib/abstract-document-xml/xsd-template/elements.d.ts.map +1 -1
  24. package/lib/abstract-document-xml/xsd-template/elements.js +18 -4
  25. package/lib/abstract-document-xml/xsd-template/elements.js.map +1 -1
  26. package/lib/abstract-document-xml/xsd-template/styles.d.ts +1 -1
  27. package/lib/abstract-document-xml/xsd-template/styles.d.ts.map +1 -1
  28. package/lib/abstract-document-xml/xsd-template/styles.js +9 -0
  29. package/lib/abstract-document-xml/xsd-template/styles.js.map +1 -1
  30. package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts +2 -2
  31. package/lib/abstract-document-xml/xsd-template/xsd-template.d.ts.map +1 -1
  32. package/lib/abstract-document-xml/xsd-template/xsd-template.js +4 -0
  33. package/lib/abstract-document-xml/xsd-template/xsd-template.js.map +1 -1
  34. package/package.json +2 -2
  35. package/src/abstract-document/styles/text-style.ts +4 -0
  36. package/src/abstract-document-exporters/pdf/measure.ts +15 -3
  37. package/src/abstract-document-exporters/pdf/render.ts +13 -1
  38. package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +1 -0
  39. package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +37 -1
  40. package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +42 -1
  41. package/src/abstract-document-xml/xsd-template/custom-elements.ts +58 -0
  42. package/src/abstract-document-xml/xsd-template/elements.ts +19 -4
  43. package/src/abstract-document-xml/xsd-template/styles.ts +9 -0
  44. package/src/abstract-document-xml/xsd-template/xsd-template.ts +4 -0
@@ -4,7 +4,10 @@ import {
4
4
  AbstractDoc,
5
5
  DefaultStyles,
6
6
  Group,
7
+ HyperLink,
7
8
  Image,
9
+ LineBreak,
10
+ LinkTarget,
8
11
  Markdown,
9
12
  PageBreak,
10
13
  Paragraph,
@@ -18,7 +21,17 @@ import {
18
21
  ImageResource,
19
22
  } from "../../abstract-document/index.js";
20
23
  import type { ImageCellProps, ImageParagraphProps, ImageRowProps } from "./custom-elements.js";
21
- import { TextRow, TextCell, TextParagraph, ImageCell, ImageParagraph, ImageRow } from "./custom-elements.js";
24
+ import {
25
+ TextRow,
26
+ TextCell,
27
+ TextParagraph,
28
+ HyperLinkRow,
29
+ HyperLinkCell,
30
+ HyperLinkParagraph,
31
+ ImageCell,
32
+ ImageParagraph,
33
+ ImageRow,
34
+ } from "./custom-elements.js";
22
35
 
23
36
  export type ADCreatorFn = (props?: Record<string, unknown>, children?: ReadonlyArray<unknown>) => unknown;
24
37
 
@@ -30,7 +43,14 @@ export const creators: (styleNames: Record<string, string>) => Record<string, AD
30
43
  TextRow: (props) => TextRow({ ...props, text: requireText(props) }, styleNames),
31
44
  TextCell: (props) => TextCell({ ...props, text: requireText(props) }, styleNames),
32
45
  TextParagraph: (props) => TextParagraph({ ...props, text: requireText(props) }, styleNames),
46
+ HyperLinkRow: (props) => HyperLinkRow({ ...props, text: requireText(props), target: requireTarget(props, "HyperLinkRow") }, styleNames),
47
+ HyperLinkParagraph: (props) =>
48
+ HyperLinkParagraph({ ...props, text: requireText(props), target: requireTarget(props, "HyperLinkParagraph") }, styleNames),
49
+ HyperLinkCell: (props) => HyperLinkCell({ ...props, text: requireText(props), target: requireTarget(props, "HyperLinkCell") }, styleNames),
33
50
  TextRun: (props) => TextRun.create({ ...props, text: requireText(props) }),
51
+ HyperLink: (props) => HyperLink.create({ ...props, text: requireText(props), target: requireTarget(props, "HyperLink") }),
52
+ LinkTarget: (props) => LinkTarget.create({ name: requireName(props) }),
53
+ LineBreak: (props) => LineBreak.create(props),
34
54
  ImageRow: ((props: Record<string, unknown>) => ImageRow(imageProps(props) as unknown as ImageRowProps, styleNames)) as ADCreatorFn,
35
55
  ImageCell: ((props: Record<string, unknown>) => ImageCell(imageProps(props) as unknown as ImageCellProps, styleNames)) as ADCreatorFn,
36
56
  ImageParagraph: ((props: Record<string, unknown>) =>
@@ -346,6 +366,22 @@ function requireText(props: Record<string, unknown> | undefined): string {
346
366
  return typeof text === "string" ? text : "";
347
367
  }
348
368
 
369
+ function requireTarget(props: Record<string, unknown> | undefined, element: string): string {
370
+ const target = props?.["target"];
371
+ if (typeof target !== "string") {
372
+ throw new Error(`<${element}> requires a "target" attribute`);
373
+ }
374
+ return target;
375
+ }
376
+
377
+ function requireName(props: Record<string, unknown> | undefined): string {
378
+ const name = props?.["name"];
379
+ if (typeof name !== "string") {
380
+ throw new Error('<LinkTarget> requires a "name" attribute');
381
+ }
382
+ return name;
383
+ }
384
+
349
385
  const validFieldTypes: ReadonlyArray<TextField.FieldType> = ["Date", "PageNumber", "TotalPages", "PageNumberOf"];
350
386
 
351
387
  function requireFieldType(props: Record<string, unknown> | undefined): TextField.FieldType {
@@ -1,6 +1,6 @@
1
1
  import type { ImageProps } from "../../abstract-document/atoms/image.js";
2
2
  import type { TextStyle, ParagraphStyle, TableCellStyle } from "../../abstract-document/index.js";
3
- import { TextRun, Paragraph, TableCell, TableRow, Image } from "../../abstract-document/index.js";
3
+ import { TextRun, Paragraph, TableCell, TableRow, Image, HyperLink } from "../../abstract-document/index.js";
4
4
  import type { ParagraphProps } from "../../abstract-document/section-elements/paragraph.js";
5
5
  //dummy2
6
6
 
@@ -87,6 +87,47 @@ export function TextParagraph(props: TextParagraphProps, styleNameTypes: Record<
87
87
  return Paragraph.create({ style, styleName: styleNames.ParagraphStyle }, [textRun]);
88
88
  }
89
89
 
90
+ export type HyperLinkParagraphProps = TextParagraphProps & {
91
+ readonly target: string;
92
+ };
93
+
94
+ export function HyperLinkParagraph(props: HyperLinkParagraphProps, styleNameTypes: Record<string, string>): Paragraph.Paragraph {
95
+ const { text, target, textStyle, style } = props;
96
+ const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
97
+ const hyperLink = HyperLink.create({
98
+ text,
99
+ target,
100
+ style: textStyle ? { ...textStyle, type: "TextStyle" } : undefined,
101
+ styleName: styleNames.TextStyle,
102
+ });
103
+ return Paragraph.create({ style, styleName: styleNames.ParagraphStyle }, [hyperLink]);
104
+ }
105
+
106
+ export type HyperLinkCellProps = Omit<HyperLinkParagraphProps, "style"> & {
107
+ readonly columnSpan?: number;
108
+ readonly rowSpan?: number;
109
+ readonly style?: TableCellStyle.TableCellStyle;
110
+ readonly paragraphStyle?: ParagraphStyle.ParagraphStyle;
111
+ };
112
+
113
+ export function HyperLinkCell(props: HyperLinkCellProps, styleNameTypes: Record<string, string>): TableCell.TableCell {
114
+ const { paragraphStyle, style, columnSpan, rowSpan } = props;
115
+ const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
116
+ const paragraph = HyperLinkParagraph(
117
+ { ...props, style: paragraphStyle ? { ...paragraphStyle, type: "ParagraphStyle" } : undefined },
118
+ styleNameTypes
119
+ );
120
+ return TableCell.create({ columnSpan, rowSpan, style, styleName: styleNames.TableCellStyle }, [paragraph]);
121
+ }
122
+
123
+ export type HyperLinkRowProps = Omit<HyperLinkCellProps, "style"> & {
124
+ readonly cellStyle?: TableCellStyle.TableCellStyle;
125
+ };
126
+
127
+ export function HyperLinkRow(props: HyperLinkRowProps, styleNameTypes: Record<string, string>): TableRow.TableRow {
128
+ return TableRow.create({}, [HyperLinkCell({ ...props, style: props.cellStyle }, styleNameTypes)]);
129
+ }
130
+
90
131
  export type ImageRowProps = Omit<ImageCellProps, "style"> & {
91
132
  readonly cellStyle?: TableCellStyle.TableCellStyle;
92
133
  };
@@ -68,6 +68,64 @@ export const textParagraph = `<xs:complexType name="TextParagraph">
68
68
  </xs:complexType>`;
69
69
  export const textParagraphElement = `<xs:element name="TextParagraph" type="TextParagraph" maxOccurs="unbounded" />`;
70
70
 
71
+ export const hyperLinkParagraph = `<xs:complexType name="HyperLinkParagraph">
72
+ <xs:annotation>
73
+ <xs:documentation>Shortcut to create \\<Paragraph> \\<HyperLink text="..." target="..." /> \\</Paragraph></xs:documentation>
74
+ </xs:annotation>
75
+ <xs:choice minOccurs="0" maxOccurs="1">
76
+ <xs:element name="style" type="ParagraphStyle" />
77
+ </xs:choice>
78
+ <xs:choice minOccurs="0" maxOccurs="1">
79
+ <xs:element name="textStyle" type="TextStyle" />
80
+ </xs:choice>
81
+ <xs:attribute name="styleNames" type="xs:string" />
82
+ <xs:attribute name="target" type="xs:string" use="required" />
83
+ <xs:attribute name="text" type="xs:string" use="required" />
84
+ </xs:complexType>`;
85
+ export const hyperLinkParagraphElement = `<xs:element name="HyperLinkParagraph" type="HyperLinkParagraph" maxOccurs="unbounded" />`;
86
+
87
+ export const hyperLinkCell = `<xs:complexType name="HyperLinkCell">
88
+ <xs:annotation>
89
+ <xs:documentation>Shortcut to create a \\<TableCell> \\<Paragraph> \\<HyperLink text="..." target="..." /> \\</Paragraph> \\</TableCell></xs:documentation>
90
+ </xs:annotation>
91
+ <xs:choice minOccurs="0" maxOccurs="1">
92
+ <xs:element name="style" type="TableCellStyle" />
93
+ </xs:choice>
94
+ <xs:choice minOccurs="0" maxOccurs="1">
95
+ <xs:element name="paragraphStyle" type="ParagraphStyle" />
96
+ </xs:choice>
97
+ <xs:choice minOccurs="0" maxOccurs="1">
98
+ <xs:element name="textStyle" type="TextStyle" />
99
+ </xs:choice>
100
+ <xs:attribute name="styleNames" type="xs:string" />
101
+ <xs:attribute name="target" type="xs:string" use="required" />
102
+ <xs:attribute name="columnSpan" type="xs:integer" />
103
+ <xs:attribute name="rowSpan" type="xs:integer" />
104
+ <xs:attribute name="text" type="xs:string" use="required" />
105
+ </xs:complexType>`;
106
+ export const hyperLinkCellElement = `<xs:element name="HyperLinkCell" type="HyperLinkCell" minOccurs="0" maxOccurs="unbounded" />`;
107
+
108
+ export const hyperLinkRow = `<xs:complexType name="HyperLinkRow">
109
+ <xs:annotation>
110
+ <xs:documentation>Shortcut to create a \\<TableRow> \\<TableCell> \\<Paragraph> \\<HyperLink text="..." target="..." /> \\</Paragraph> \\</TableCell> \\</TableRow></xs:documentation>
111
+ </xs:annotation>
112
+ <xs:choice minOccurs="0" maxOccurs="1">
113
+ <xs:element name="cellStyle" type="TableCellStyle" />
114
+ </xs:choice>
115
+ <xs:choice minOccurs="0" maxOccurs="1">
116
+ <xs:element name="paragraphStyle" type="ParagraphStyle" />
117
+ </xs:choice>
118
+ <xs:choice minOccurs="0" maxOccurs="1">
119
+ <xs:element name="textStyle" type="TextStyle" />
120
+ </xs:choice>
121
+ <xs:attribute name="styleNames" type="xs:string" />
122
+ <xs:attribute name="target" type="xs:string" use="required" />
123
+ <xs:attribute name="columnSpan" type="xs:integer" />
124
+ <xs:attribute name="rowSpan" type="xs:integer" />
125
+ <xs:attribute name="text" type="xs:string" use="required" />
126
+ </xs:complexType>`;
127
+ export const hyperLinkRowElement = `<xs:element name="HyperLinkRow" type="HyperLinkRow" maxOccurs="unbounded" />`;
128
+
71
129
  export const imageRow = `<xs:complexType name="ImageRow">
72
130
  <xs:annotation>
73
131
  <xs:documentation>Shortcut to create a \\<TableRow> \\<TableCell> \\<Paragraph> \\<Image src text="..." /> \\</Paragraph> \\</TableCell> \\</TableRow></xs:documentation>
@@ -16,6 +16,7 @@ export const section = `<xs:complexType name="Section">
16
16
  <xs:element name="PageBreak" type="PageBreak" minOccurs="0" />
17
17
  <xs:element name="Paragraph" type="Paragraph" minOccurs="0" />
18
18
  ${Custom.textParagraphElement}
19
+ ${Custom.hyperLinkParagraphElement}
19
20
  ${Custom.imageParagraphElement}
20
21
  <xs:element name="Markdown" type="Markdown" minOccurs="0" />
21
22
  <xs:element name="page" type="page" minOccurs="0" maxOccurs="1"></xs:element>
@@ -38,6 +39,7 @@ const sectionElementBody = `<xs:element name="Table" type="Table" minOccurs="0"
38
39
  <xs:element name="PageBreak" type="PageBreak" minOccurs="0" />
39
40
  <xs:element name="Paragraph" type="Paragraph" minOccurs="0" />
40
41
  ${Custom.textParagraphElement}
42
+ ${Custom.hyperLinkParagraphElement}
41
43
  ${Custom.imageParagraphElement}
42
44
  <xs:element name="Markdown" type="Markdown" minOccurs="0" />`;
43
45
 
@@ -61,6 +63,7 @@ export const group = `<xs:complexType name="Group">
61
63
  <xs:element name="PageBreak" type="PageBreak" minOccurs="0" />
62
64
  <xs:element name="Paragraph" type="Paragraph" minOccurs="0" />
63
65
  ${Custom.textParagraphElement}
66
+ ${Custom.hyperLinkParagraphElement}
64
67
  ${Custom.imageParagraphElement}
65
68
  <xs:element name="style" type="GroupStyle" minOccurs="0" />
66
69
  </xs:choice>
@@ -75,6 +78,7 @@ export const table = `<xs:complexType name="Table">
75
78
  <xs:choice minOccurs="1">
76
79
  <xs:element name="TableRow" type="TableRow" maxOccurs="unbounded" />
77
80
  ${Custom.textRowElement}
81
+ ${Custom.hyperLinkRowElement}
78
82
  ${Custom.imageRowElement}
79
83
  </xs:choice>
80
84
  </xs:sequence>
@@ -96,6 +100,7 @@ export const headerRows = `<xs:complexType name="headerRows">
96
100
  <xs:choice minOccurs="1" maxOccurs="unbounded">
97
101
  <xs:element name="TableRow" type="TableRow"/>
98
102
  ${Custom.textRowElement}
103
+ ${Custom.hyperLinkRowElement}
99
104
  ${Custom.imageRowElement}
100
105
  </xs:choice>
101
106
  </xs:sequence>
@@ -105,6 +110,7 @@ export const tableRow = `<xs:complexType name="TableRow">
105
110
  <xs:choice maxOccurs="unbounded">
106
111
  <xs:element name="TableCell" type="TableCell" minOccurs="0" maxOccurs="unbounded" />
107
112
  ${Custom.textCellElement}
113
+ ${Custom.hyperLinkCellElement}
108
114
  ${Custom.imageCellElement}
109
115
  </xs:choice>
110
116
  </xs:complexType>`;
@@ -117,6 +123,7 @@ export const tableCell = `<xs:complexType name="TableCell">
117
123
  <xs:element name="PageBreak" type="PageBreak" minOccurs="0" maxOccurs="unbounded" />
118
124
  <xs:element name="Paragraph" type="Paragraph" minOccurs="0" maxOccurs="unbounded" />
119
125
  ${Custom.textParagraphElement}
126
+ ${Custom.hyperLinkParagraphElement}
120
127
  ${Custom.imageParagraphElement}
121
128
  <xs:element name="Markdown" type="Markdown" minOccurs="0" maxOccurs="unbounded" />
122
129
  </xs:choice>
@@ -141,7 +148,8 @@ export const paragraph = `<xs:complexType name="Paragraph">
141
148
  <xs:element name="Image" type="Image" minOccurs="0" maxOccurs="unbounded"></xs:element>
142
149
  <xs:element name="HyperLink" type="HyperLink" minOccurs="0" maxOccurs="unbounded"></xs:element>
143
150
  <xs:element name="LinkTarget" type="LinkTarget" minOccurs="0" maxOccurs="unbounded"></xs:element>
144
- <xs:element name="TocSeperator" type="TocSeperator" minOccurs="0" maxOccurs="unbounded"></xs:element>
151
+ <xs:element name="LineBreak" type="LineBreak" minOccurs="0" maxOccurs="unbounded"></xs:element>
152
+ <xs:element name="TocSeparator" type="TocSeparator" minOccurs="0" maxOccurs="unbounded"></xs:element>
145
153
  <xs:element name="style" type="ParagraphStyle" minOccurs="0" maxOccurs="1"></xs:element>
146
154
  </xs:choice>
147
155
  <xs:attribute name="styleName" type="xs:string" >
@@ -160,16 +168,23 @@ export const hyperLink = `<xs:complexType name="HyperLink">
160
168
  <xs:documentation>Refrence to a TextStyle that is defined in \\<AbstractDoc> \\<StyleNames> \\<StyleName name="..." /> \\</StyleNames> \\</AbstractDoc></xs:documentation>
161
169
  </xs:annotation>
162
170
  </xs:attribute>
163
- <xs:attribute name="target" type="xs:string" />
171
+ <xs:attribute name="target" type="xs:string" use="required" />
164
172
  <xs:attribute name="text" type="xs:string" />
165
173
  </xs:complexType>`;
166
174
 
167
- export const tocSeparator = `<xs:complexType name="TocSeperator">
175
+ export const tocSeparator = `<xs:complexType name="TocSeparator">
168
176
  <xs:attribute name="width" type="xs:decimal" />
169
177
  </xs:complexType>`;
170
178
 
171
179
  export const linkTarget = `<xs:complexType name="LinkTarget">
172
- <xs:attribute name="name" type="xs:string" />
180
+ <xs:attribute name="name" type="xs:string" use="required" />
181
+ </xs:complexType>`;
182
+
183
+ export const lineBreak = `<xs:complexType name="LineBreak">
184
+ <xs:choice minOccurs="0" maxOccurs="1">
185
+ <xs:element name="style" type="TextStyle" />
186
+ </xs:choice>
187
+ <xs:attribute name="styleName" type="xs:string" />
173
188
  </xs:complexType>`;
174
189
 
175
190
  export const textRun = `<xs:complexType name="TextRun">
@@ -255,6 +255,15 @@ export const textStyle = `<xs:complexType name="TextStyle">
255
255
  <xs:attribute name="indent" type="xs:decimal" />
256
256
  <xs:attribute name="color" type="xs:string" />
257
257
  <xs:attribute name="fontFamily" type="xs:string" />
258
+ <xs:attribute name="transform">
259
+ <xs:simpleType>
260
+ <xs:restriction base="xs:string">
261
+ <xs:enumeration value="normal" />
262
+ <xs:enumeration value="uppercase" />
263
+ <xs:enumeration value="lowercase" />
264
+ </xs:restriction>
265
+ </xs:simpleType>
266
+ </xs:attribute>
258
267
  <xs:attribute name="baseline">
259
268
  <xs:simpleType>
260
269
  <xs:restriction base="xs:string">
@@ -14,6 +14,7 @@ ${Elements.image}
14
14
  ${Elements.textField}
15
15
  ${Elements.textRun}
16
16
  ${Elements.hyperLink}
17
+ ${Elements.lineBreak}
17
18
  ${Elements.tocSeparator}
18
19
  ${Elements.linkTarget}
19
20
  ${Styles.position}
@@ -33,6 +34,9 @@ ${Elements.tableCell}
33
34
  ${CustomElements.textRow}
34
35
  ${CustomElements.textCell}
35
36
  ${CustomElements.textParagraph}
37
+ ${CustomElements.hyperLinkParagraph}
38
+ ${CustomElements.hyperLinkCell}
39
+ ${CustomElements.hyperLinkRow}
36
40
  ${CustomElements.imageRow}
37
41
  ${CustomElements.imageCell}
38
42
  ${CustomElements.imageParagraph}`;