abstract-document 20.0.1 → 20.0.4

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 (194) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +3 -3
  3. package/lib/abstract-document/abstract-doc.d.ts +2 -2
  4. package/lib/abstract-document/abstract-doc.d.ts.map +1 -1
  5. package/lib/abstract-document/atoms/atom.d.ts +7 -7
  6. package/lib/abstract-document/atoms/atom.d.ts.map +1 -1
  7. package/lib/abstract-document/atoms/image.d.ts +1 -1
  8. package/lib/abstract-document/atoms/image.d.ts.map +1 -1
  9. package/lib/abstract-document/atoms/line-break.d.ts +1 -1
  10. package/lib/abstract-document/atoms/line-break.d.ts.map +1 -1
  11. package/lib/abstract-document/atoms/line-break.js +1 -1
  12. package/lib/abstract-document/atoms/line-break.js.map +1 -1
  13. package/lib/abstract-document/atoms/link-target.js +1 -1
  14. package/lib/abstract-document/atoms/text-run.d.ts.map +1 -1
  15. package/lib/abstract-document/atoms/text-run.js +1 -0
  16. package/lib/abstract-document/atoms/text-run.js.map +1 -1
  17. package/lib/abstract-document/default-styles.d.ts +2 -2
  18. package/lib/abstract-document/default-styles.d.ts.map +1 -1
  19. package/lib/abstract-document/markdown/markdown.d.ts +1 -1
  20. package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
  21. package/lib/abstract-document/markdown/markdown.js +6 -3
  22. package/lib/abstract-document/markdown/markdown.js.map +1 -1
  23. package/lib/abstract-document/markdown/types.d.ts +1 -1
  24. package/lib/abstract-document/markdown/types.d.ts.map +1 -1
  25. package/lib/abstract-document/numberings/numbering-definition.d.ts +1 -1
  26. package/lib/abstract-document/numberings/numbering-definition.d.ts.map +1 -1
  27. package/lib/abstract-document/numberings/numbering-format.d.ts.map +1 -1
  28. package/lib/abstract-document/numberings/numbering-level-definition.d.ts +1 -1
  29. package/lib/abstract-document/numberings/numbering-level-definition.d.ts.map +1 -1
  30. package/lib/abstract-document/page/master-page.d.ts +1 -1
  31. package/lib/abstract-document/page/master-page.d.ts.map +1 -1
  32. package/lib/abstract-document/page/section.d.ts +2 -2
  33. package/lib/abstract-document/page/section.d.ts.map +1 -1
  34. package/lib/abstract-document/primitives/image-resource.d.ts +1 -1
  35. package/lib/abstract-document/primitives/image-resource.d.ts.map +1 -1
  36. package/lib/abstract-document/primitives/layout-foundation-color.js +4 -4
  37. package/lib/abstract-document/primitives/layout-foundation-color.js.map +1 -1
  38. package/lib/abstract-document/primitives/layout-foundation.js +1 -1
  39. package/lib/abstract-document/primitives/point.js +1 -1
  40. package/lib/abstract-document/resources.d.ts +5 -5
  41. package/lib/abstract-document/resources.d.ts.map +1 -1
  42. package/lib/abstract-document/resources.js.map +1 -1
  43. package/lib/abstract-document/section-elements/group.d.ts +2 -2
  44. package/lib/abstract-document/section-elements/group.d.ts.map +1 -1
  45. package/lib/abstract-document/section-elements/page-break.d.ts +1 -1
  46. package/lib/abstract-document/section-elements/page-break.d.ts.map +1 -1
  47. package/lib/abstract-document/section-elements/paragraph.d.ts +3 -3
  48. package/lib/abstract-document/section-elements/paragraph.d.ts.map +1 -1
  49. package/lib/abstract-document/section-elements/paragraph.js +1 -1
  50. package/lib/abstract-document/section-elements/paragraph.js.map +1 -1
  51. package/lib/abstract-document/section-elements/section-element.d.ts +1 -1
  52. package/lib/abstract-document/section-elements/section-element.d.ts.map +1 -1
  53. package/lib/abstract-document/section-elements/table.d.ts +2 -2
  54. package/lib/abstract-document/section-elements/table.d.ts.map +1 -1
  55. package/lib/abstract-document/styles/group-style.d.ts +1 -1
  56. package/lib/abstract-document/styles/group-style.d.ts.map +1 -1
  57. package/lib/abstract-document/styles/paragraph-style.d.ts +1 -1
  58. package/lib/abstract-document/styles/paragraph-style.d.ts.map +1 -1
  59. package/lib/abstract-document/styles/paragraph-style.js +1 -1
  60. package/lib/abstract-document/styles/paragraph-style.js.map +1 -1
  61. package/lib/abstract-document/styles/table-cell-style.d.ts.map +1 -1
  62. package/lib/abstract-document/styles/table-cell-style.js +1 -1
  63. package/lib/abstract-document/styles/table-cell-style.js.map +1 -1
  64. package/lib/abstract-document/styles/table-style.d.ts +1 -1
  65. package/lib/abstract-document/styles/table-style.d.ts.map +1 -1
  66. package/lib/abstract-document/styles/table-style.js +1 -1
  67. package/lib/abstract-document/styles/table-style.js.map +1 -1
  68. package/lib/abstract-document/styles/text-style.js +1 -1
  69. package/lib/abstract-document/styles/text-style.js.map +1 -1
  70. package/lib/abstract-document/table/table-cell.d.ts +1 -1
  71. package/lib/abstract-document/table/table-cell.d.ts.map +1 -1
  72. package/lib/abstract-document/table/table-row.d.ts +1 -1
  73. package/lib/abstract-document/table/table-row.d.ts.map +1 -1
  74. package/lib/abstract-document-exporters/docx/ref-container.d.ts.map +1 -1
  75. package/lib/abstract-document-exporters/docx/string-utils.d.ts.map +1 -1
  76. package/lib/abstract-document-exporters/docx/string-utils.js +1 -3
  77. package/lib/abstract-document-exporters/docx/string-utils.js.map +1 -1
  78. package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
  79. package/lib/abstract-document-exporters/docx/xml-writer.js +1 -0
  80. package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
  81. package/lib/abstract-document-exporters/docx2/render-image.d.ts +4 -4
  82. package/lib/abstract-document-exporters/docx2/render-image.d.ts.map +1 -1
  83. package/lib/abstract-document-exporters/docx2/render-image.js +8 -14
  84. package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
  85. package/lib/abstract-document-exporters/docx2/render.d.ts.map +1 -1
  86. package/lib/abstract-document-exporters/docx2/render.js +37 -29
  87. package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
  88. package/lib/abstract-document-exporters/pdf/font.d.ts +2 -2
  89. package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
  90. package/lib/abstract-document-exporters/pdf/font.js +2 -1
  91. package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
  92. package/lib/abstract-document-exporters/pdf/measure.d.ts +1 -1
  93. package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
  94. package/lib/abstract-document-exporters/pdf/measure.js +3 -2
  95. package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
  96. package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
  97. package/lib/abstract-document-exporters/pdf/paginate.js +3 -2
  98. package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
  99. package/lib/abstract-document-exporters/pdf/pre-process.d.ts.map +1 -1
  100. package/lib/abstract-document-exporters/pdf/pre-process.js +3 -2
  101. package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
  102. package/lib/abstract-document-exporters/pdf/render-image.js +1 -3
  103. package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
  104. package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
  105. package/lib/abstract-document-exporters/pdf/render.js +1 -0
  106. package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
  107. package/lib/abstract-document-exporters/pdf/std-fonts.js +1 -1
  108. package/lib/abstract-document-exporters/pdf/textRunRow.d.ts.map +1 -1
  109. package/lib/abstract-document-exporters/pdf/textRunRow.js +21 -15
  110. package/lib/abstract-document-exporters/pdf/textRunRow.js.map +1 -1
  111. package/lib/abstract-document-exporters/pdf/update-refs.d.ts +1 -1
  112. package/lib/abstract-document-exporters/pdf/update-refs.d.ts.map +1 -1
  113. package/lib/abstract-document-exporters/shared/get_resources.d.ts +2 -2
  114. package/lib/abstract-document-exporters/shared/get_resources.d.ts.map +1 -1
  115. package/lib/abstract-document-exporters/shared/get_resources.js.map +1 -1
  116. package/lib/abstract-document-jsx/index.d.ts.map +1 -1
  117. package/lib/abstract-document-jsx/index.js.map +1 -1
  118. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts +3 -3
  119. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
  120. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +33 -33
  121. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
  122. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
  123. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +81 -75
  124. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
  125. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts +3 -2
  126. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
  127. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +1 -1
  128. package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
  129. package/lib/abstract-document-xml/xsd-template/custom-elements.d.ts.map +1 -1
  130. package/lib/abstract-document-xml/xsd-template/custom-elements.js +0 -1
  131. package/lib/abstract-document-xml/xsd-template/custom-elements.js.map +1 -1
  132. package/package.json +4 -4
  133. package/src/abstract-document/abstract-doc.ts +7 -7
  134. package/src/abstract-document/atoms/atom.ts +7 -7
  135. package/src/abstract-document/atoms/image.ts +1 -1
  136. package/src/abstract-document/atoms/line-break.ts +1 -1
  137. package/src/abstract-document/atoms/link-target.ts +1 -1
  138. package/src/abstract-document/atoms/text-run.ts +1 -0
  139. package/src/abstract-document/default-styles.ts +2 -2
  140. package/src/abstract-document/markdown/markdown.ts +11 -8
  141. package/src/abstract-document/markdown/types.ts +1 -1
  142. package/src/abstract-document/numberings/numbering-definition.ts +1 -1
  143. package/src/abstract-document/numberings/numbering-format.ts +1 -7
  144. package/src/abstract-document/numberings/numbering-level-definition.ts +1 -1
  145. package/src/abstract-document/page/master-page.ts +1 -1
  146. package/src/abstract-document/page/section.ts +2 -2
  147. package/src/abstract-document/primitives/image-resource.ts +1 -1
  148. package/src/abstract-document/primitives/layout-foundation-color.ts +4 -4
  149. package/src/abstract-document/primitives/layout-foundation.ts +1 -1
  150. package/src/abstract-document/primitives/point.ts +1 -1
  151. package/src/abstract-document/resources.ts +9 -8
  152. package/src/abstract-document/section-elements/group.ts +2 -2
  153. package/src/abstract-document/section-elements/page-break.ts +1 -1
  154. package/src/abstract-document/section-elements/paragraph.ts +4 -4
  155. package/src/abstract-document/section-elements/section-element.ts +1 -1
  156. package/src/abstract-document/section-elements/table.ts +2 -2
  157. package/src/abstract-document/styles/group-style.ts +1 -1
  158. package/src/abstract-document/styles/paragraph-style.ts +2 -2
  159. package/src/abstract-document/styles/table-cell-style.ts +1 -8
  160. package/src/abstract-document/styles/table-style.ts +2 -2
  161. package/src/abstract-document/styles/text-style.ts +20 -20
  162. package/src/abstract-document/table/table-cell.ts +1 -1
  163. package/src/abstract-document/table/table-row.ts +1 -1
  164. package/src/abstract-document-exporters/docx/string-utils.ts +1 -5
  165. package/src/abstract-document-exporters/docx/xml-writer.ts +1 -0
  166. package/src/abstract-document-exporters/docx2/render-image.ts +69 -57
  167. package/src/abstract-document-exporters/docx2/render.ts +104 -77
  168. package/src/abstract-document-exporters/pdf/font.ts +16 -15
  169. package/src/abstract-document-exporters/pdf/measure.ts +6 -3
  170. package/src/abstract-document-exporters/pdf/paginate.ts +11 -6
  171. package/src/abstract-document-exporters/pdf/pre-process.ts +3 -3
  172. package/src/abstract-document-exporters/pdf/render-image.ts +10 -12
  173. package/src/abstract-document-exporters/pdf/render.ts +5 -2
  174. package/src/abstract-document-exporters/pdf/std-fonts.ts +1 -1
  175. package/src/abstract-document-exporters/pdf/textRunRow.ts +108 -74
  176. package/src/abstract-document-exporters/pdf/update-refs.ts +2 -2
  177. package/src/abstract-document-exporters/shared/get_resources.ts +10 -9
  178. package/src/abstract-document-jsx/index.ts +1 -1
  179. package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +47 -46
  180. package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +118 -114
  181. package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +4 -13
  182. package/src/abstract-document-xml/xsd-template/custom-elements.ts +0 -1
  183. package/src/abstract-document-xml/xsd-template/styles.ts +1 -1
  184. package/src/custom_typings/pdfkit-standard-fonts/index.d.ts +0 -1
  185. package/lib/abstract-document/table/text-row.d.ts +0 -2
  186. package/lib/abstract-document/table/text-row.d.ts.map +0 -1
  187. package/lib/abstract-document/table/text-row.js +0 -2
  188. package/lib/abstract-document/table/text-row.js.map +0 -1
  189. package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts +0 -2
  190. package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts.map +0 -1
  191. package/lib/abstract-document-exporters/docx/docx-document-renderer.js +0 -1085
  192. package/lib/abstract-document-exporters/docx/docx-document-renderer.js.map +0 -1
  193. package/src/abstract-document/table/text-row.ts +0 -0
  194. package/src/abstract-document-exporters/docx/docx-document-renderer.ts +0 -1084
@@ -8,17 +8,25 @@ type LongWordSplit = {
8
8
  readonly width: number;
9
9
  };
10
10
 
11
- export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, availableWidth: number, desiredSizes: Map<{}, AD.Size.Size>, alignment: PdfKitAlignment, pdf: PDFKit.PDFDocument, resources: AD.Resources.Resources, defaultStyle: AD.TextStyle.TextStyle): ReadonlyArray<ReadonlyArray<AD.Atom.Atom>> {
11
+ export function rowsSplit(
12
+ rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>,
13
+ availableWidth: number,
14
+ desiredSizes: Map<{}, AD.Size.Size>,
15
+ alignment: PdfKitAlignment,
16
+ pdf: PDFKit.PDFDocument,
17
+ resources: AD.Resources.Resources,
18
+ defaultStyle: AD.TextStyle.TextStyle
19
+ ): ReadonlyArray<ReadonlyArray<AD.Atom.Atom>> {
12
20
  const newRows: Array<ReadonlyArray<AD.Atom.Atom>> = [];
13
21
 
14
- for(const row of rows) {
15
- if(row.length < 1) {
22
+ for (const row of rows) {
23
+ if (row.length < 1) {
16
24
  newRows.push(row);
17
25
  continue;
18
26
  }
19
-
27
+
20
28
  const width = row.reduce((a, b) => a + getDesiredSize(b, desiredSizes).width, 0);
21
- if(width < availableWidth) {
29
+ if (width < availableWidth) {
22
30
  newRows.push(row);
23
31
  continue;
24
32
  }
@@ -28,45 +36,41 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
28
36
  let currentWidth = 0;
29
37
  let lastWasSpace = false;
30
38
 
31
- for(let i = 0; i < row.length; i++) {
39
+ for (let i = 0; i < row.length; i++) {
32
40
  const atom = row[i];
33
41
  const size = getDesiredSize(atom, desiredSizes);
34
42
  const width = size.width;
35
43
  const height = size.height;
36
44
 
37
- if(atom.type !== "TextRun") {
45
+ if (atom.type !== "TextRun") {
38
46
  currentRow.push(atom);
39
47
  currentWidth += width;
40
48
  continue;
41
49
  }
42
50
 
43
-
44
- const isSpace = atom.text.replaceAll(/[\p{Zs}]/ug, "").length === 0;
51
+ const isSpace = atom.text.replaceAll(/[\p{Zs}]/gu, "").length === 0;
45
52
  const lastSpace = lastWasSpace;
46
53
  lastWasSpace = isSpace;
47
54
 
48
55
  //if the next atom is a space, we need to split this row early if it doesnt fit
49
56
  const nextAtom = row[i + 1];
50
- const nextWidthIfSpace =
51
- !isSpace
52
- && nextAtom
53
- && nextAtom.type === "TextRun"
54
- && nextAtom.text.replaceAll(/[\p{Zs}]/ug, "").length === 0
57
+ const nextWidthIfSpace =
58
+ !isSpace && nextAtom && nextAtom.type === "TextRun" && nextAtom.text.replaceAll(/[\p{Zs}]/gu, "").length === 0
55
59
  ? getDesiredSize(nextAtom, desiredSizes).width
56
60
  : 0;
57
61
 
58
- if(isSpace && currentWidth === 0 && i !== 0 && (alignment === "left" || alignment === "justify")) {
62
+ if (isSpace && currentWidth === 0 && i !== 0 && (alignment === "left" || alignment === "justify")) {
59
63
  continue;
60
64
  }
61
-
62
- if((currentWidth + width + nextWidthIfSpace) < availableWidth) {
65
+
66
+ if (currentWidth + width + nextWidthIfSpace < availableWidth) {
63
67
  currentRow.push(atom);
64
68
  currentWidth += width;
65
69
  continue;
66
70
  }
67
71
 
68
72
  //was it a space??
69
- if(isSpace) {
73
+ if (isSpace) {
70
74
  newRows.push(currentRow);
71
75
  currentRow = [];
72
76
  currentWidth = 0;
@@ -76,10 +80,10 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
76
80
  //it is now longer than the remaning size
77
81
  const remSize = availableWidth - (currentWidth + nextWidthIfSpace);
78
82
  const splittedWord = splitWord(atom, remSize, availableWidth, pdf, resources, defaultStyle);
79
- if(splittedWord.length > 0) {
83
+ if (splittedWord.length > 0) {
80
84
  const heightPerRow = height / splittedWord.length;
81
85
  const [first, ...rest] = splittedWord;
82
- if(!first && !rest) {
86
+ if (!first && !rest) {
83
87
  continue;
84
88
  }
85
89
  //add the first to the current row
@@ -88,7 +92,7 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
88
92
  currentRow.push(newFirstRowAtom);
89
93
 
90
94
  //then add new rows
91
- for(const part of rest ?? []) {
95
+ for (const part of rest ?? []) {
92
96
  newRows.push(currentRow);
93
97
  const newAtom = { ...atom, text: part.text };
94
98
  desiredSizes.set(newAtom, { width: part.width, height: heightPerRow });
@@ -98,11 +102,15 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
98
102
  continue;
99
103
  }
100
104
 
101
- newRows.push((lastSpace && (alignment === "right" || alignment === "justify")) ? currentRow.slice(0, -1) : currentRow);
105
+ newRows.push(
106
+ lastSpace && (alignment === "right" || alignment === "justify") ? currentRow.slice(0, -1) : currentRow
107
+ );
102
108
  currentRow = [atom];
103
109
  currentWidth = width;
104
110
  }
105
- newRows.push((lastWasSpace && (alignment === "right" || alignment === "justify")) ? currentRow.slice(0, -1) : currentRow);
111
+ newRows.push(
112
+ lastWasSpace && (alignment === "right" || alignment === "justify") ? currentRow.slice(0, -1) : currentRow
113
+ );
106
114
  }
107
115
  return newRows;
108
116
  }
@@ -110,27 +118,34 @@ export function rowsSplit(rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, avai
110
118
  /*
111
119
  the first entry fits inside the current row
112
120
  */
113
- function splitWord(word: AD.TextRun.TextRun, firstRowRemainingWidth: number, rowWidth: number, pdf: PDFKit.PDFDocument, resources: AD.Resources.Resources, defaultStyle: AD.TextStyle.TextStyle): ReadonlyArray<LongWordSplit> {
121
+ function splitWord(
122
+ word: AD.TextRun.TextRun,
123
+ firstRowRemainingWidth: number,
124
+ rowWidth: number,
125
+ pdf: PDFKit.PDFDocument,
126
+ resources: AD.Resources.Resources,
127
+ defaultStyle: AD.TextStyle.TextStyle
128
+ ): ReadonlyArray<LongWordSplit> {
114
129
  const strings: Array<LongWordSplit> = [];
115
130
  const totalWidth = stringWidth(word, pdf, word.text, resources, defaultStyle);
116
- if(totalWidth < rowWidth) {
131
+ if (totalWidth < rowWidth) {
117
132
  return [];
118
133
  }
119
134
 
120
135
  let currentString = "";
121
136
  let atFirstRow = true;
122
- for(const char of word.text) {
137
+ for (const char of word.text) {
123
138
  const remWidth = atFirstRow ? firstRowRemainingWidth : rowWidth;
124
139
  const newString = currentString + char;
125
140
  const newWidth = stringWidth(word, pdf, newString, resources, defaultStyle);
126
- if(newWidth < remWidth) {
141
+ if (newWidth < remWidth) {
127
142
  currentString = newString;
128
143
  continue;
129
144
  }
130
145
 
131
146
  strings.push({
132
147
  text: currentString,
133
- width: newWidth
148
+ width: newWidth,
134
149
  });
135
150
 
136
151
  //reset
@@ -139,19 +154,26 @@ function splitWord(word: AD.TextRun.TextRun, firstRowRemainingWidth: number, row
139
154
  }
140
155
 
141
156
  //add any remainder
142
- if(currentString !== "") {
157
+ if (currentString !== "") {
143
158
  const newWidth = stringWidth(word, pdf, currentString, resources, defaultStyle);
144
159
  strings.push({
145
160
  text: currentString,
146
- width: newWidth
161
+ width: newWidth,
147
162
  });
148
163
  }
149
164
 
150
165
  return strings;
151
166
  }
152
167
 
153
- export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFKit.PDFDocument, rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>, desiredSizes: Map<{}, AD.Size.Size>, alignment: PdfKitAlignment, defaultStyle: AD.TextStyle.TextStyle): { newDesiredSizes: Map<{}, AD.Size.Size>; combinedRows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>> } {
154
- if(alignment === "justify") {
168
+ export function rowsCombineTextRuns(
169
+ resources: AD.Resources.Resources,
170
+ pdf: PDFKit.PDFDocument,
171
+ rows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>>,
172
+ desiredSizes: Map<{}, AD.Size.Size>,
173
+ alignment: PdfKitAlignment,
174
+ defaultStyle: AD.TextStyle.TextStyle
175
+ ): { newDesiredSizes: Map<{}, AD.Size.Size>; combinedRows: ReadonlyArray<ReadonlyArray<AD.Atom.Atom>> } {
176
+ if (alignment === "justify") {
155
177
  return { combinedRows: rows, newDesiredSizes: desiredSizes };
156
178
  }
157
179
 
@@ -161,31 +183,34 @@ export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFK
161
183
  let currentStyle: string = "";
162
184
 
163
185
  const newRows: Array<ReadonlyArray<AD.Atom.Atom>> = [];
164
- for(const row of rows) {
186
+ for (const row of rows) {
165
187
  const newRow: Array<AD.Atom.Atom> = [];
166
188
  let isFirst = true;
167
189
 
168
- for(let i = 0; i < row.length; i++) {
190
+ for (let i = 0; i < row.length; i++) {
169
191
  const atom = row[i];
170
192
  const isLast = i === row.length - 1;
171
193
  const measurement = getDesiredSize(atom, desiredSizes);
172
194
 
173
- if(atom.type !== "TextRun") {
174
- if(current !== undefined) {
195
+ if (atom.type !== "TextRun") {
196
+ if (current !== undefined) {
175
197
  const newTextRun = {
176
198
  ...current,
177
- text: currentString
199
+ text: currentString,
178
200
  };
179
- if(isFirst && alignment === "left") {
180
- while(currentString.startsWith(" ")) {
201
+ if (isFirst && alignment === "left") {
202
+ while (currentString.startsWith(" ")) {
181
203
  currentString = currentString.slice(1);
182
204
  }
183
205
  isFirst = false;
184
- } else if(isFirst) {
206
+ } else if (isFirst) {
185
207
  isFirst = false;
186
208
  }
187
209
  newRow.push(newTextRun);
188
- desiredSizes.set(newTextRun, { width: stringWidth(current, pdf, currentString, resources, defaultStyle), height: currentHeight });
210
+ desiredSizes.set(newTextRun, {
211
+ width: stringWidth(current, pdf, currentString, resources, defaultStyle),
212
+ height: currentHeight,
213
+ });
189
214
  currentString = "";
190
215
  currentStyle = "";
191
216
  currentHeight = 0;
@@ -195,35 +220,40 @@ export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFK
195
220
  continue;
196
221
  }
197
222
 
198
- const style = JSON.stringify(AD.Resources.getNestedStyle(
199
- defaultStyle,
200
- atom.style,
201
- "TextStyle",
202
- atom.styleName,
203
- resources,
204
- atom.nestedStyleNames || []
205
- ));
206
-
207
- if(current === undefined) {
223
+ const style = JSON.stringify(
224
+ AD.Resources.getNestedStyle(
225
+ defaultStyle,
226
+ atom.style,
227
+ "TextStyle",
228
+ atom.styleName,
229
+ resources,
230
+ atom.nestedStyleNames || []
231
+ )
232
+ );
233
+
234
+ if (current === undefined) {
208
235
  currentString = atom.text;
209
236
  current = atom;
210
237
  currentHeight = Math.max(measurement.height, currentHeight);
211
238
  currentStyle = style;
212
- } else if(style !== currentStyle) {
239
+ } else if (style !== currentStyle) {
213
240
  const newTextRun = {
214
241
  ...current,
215
- text: currentString
242
+ text: currentString,
216
243
  };
217
- if(isFirst && alignment === "left") {
218
- while(currentString.startsWith(" ")) {
244
+ if (isFirst && alignment === "left") {
245
+ while (currentString.startsWith(" ")) {
219
246
  currentString = currentString.slice(1);
220
247
  }
221
248
  isFirst = false;
222
- } else if(isFirst) {
249
+ } else if (isFirst) {
223
250
  isFirst = false;
224
251
  }
225
252
  newRow.push(newTextRun);
226
- desiredSizes.set(newTextRun, { width: stringWidth(current, pdf, currentString, resources, defaultStyle), height: currentHeight });
253
+ desiredSizes.set(newTextRun, {
254
+ width: stringWidth(current, pdf, currentString, resources, defaultStyle),
255
+ height: currentHeight,
256
+ });
227
257
  currentString = atom.text;
228
258
  currentHeight = Math.max(measurement.height, currentHeight);
229
259
  current = atom;
@@ -233,16 +263,16 @@ export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFK
233
263
  currentHeight = Math.max(measurement.height, currentHeight);
234
264
  }
235
265
 
236
- if(isLast) {
237
- if(current) {
266
+ if (isLast) {
267
+ if (current) {
238
268
  //does the last contain spaces at the end?
239
- if(alignment === "right") {
240
- while(currentString.endsWith(" ")) {
269
+ if (alignment === "right") {
270
+ while (currentString.endsWith(" ")) {
241
271
  currentString = currentString.slice(0, -1);
242
272
  }
243
273
  }
244
- if(isFirst && alignment === "left") {
245
- while(currentString.startsWith(" ")) {
274
+ if (isFirst && alignment === "left") {
275
+ while (currentString.startsWith(" ")) {
246
276
  currentString = currentString.slice(1);
247
277
  }
248
278
  isFirst = false;
@@ -251,9 +281,12 @@ export function rowsCombineTextRuns(resources: AD.Resources.Resources, pdf: PDFK
251
281
  const newTextRun: AD.Atom.Atom = {
252
282
  ...current,
253
283
  text: currentString,
254
- }
284
+ };
255
285
  newRow.push(newTextRun);
256
- desiredSizes.set(newTextRun, { width: stringWidth(current, pdf, currentString, resources, defaultStyle), height: currentHeight });
286
+ desiredSizes.set(newTextRun, {
287
+ width: stringWidth(current, pdf, currentString, resources, defaultStyle),
288
+ height: currentHeight,
289
+ });
257
290
  }
258
291
  }
259
292
  }
@@ -273,14 +306,15 @@ function stringWidth(
273
306
  resources: AD.Resources.Resources,
274
307
  defaultStyle: AD.TextStyle.TextStyle
275
308
  ): number {
276
- const style = AD.Resources.getNestedStyle(
277
- defaultStyle,
278
- textRun.style,
279
- "TextStyle",
280
- textRun.styleName,
281
- resources,
282
- textRun.nestedStyleNames || []
283
- ) as AD.TextStyle.TextStyle ?? defaultStyle;
309
+ const style =
310
+ (AD.Resources.getNestedStyle(
311
+ defaultStyle,
312
+ textRun.style,
313
+ "TextStyle",
314
+ textRun.styleName,
315
+ resources,
316
+ textRun.nestedStyleNames || []
317
+ ) as AD.TextStyle.TextStyle) ?? defaultStyle;
284
318
 
285
319
  const font = getFontNameStyle(style);
286
320
  const fontSize = AD.TextStyle.calculateFontSize(style, 10);
@@ -305,4 +339,4 @@ function getDesiredSize(element: {}, desiredSizes: Map<{}, AD.Size.Size>): AD.Si
305
339
  return size;
306
340
  }
307
341
  throw new Error("Could not find size for element!");
308
- }
342
+ }
@@ -1,5 +1,5 @@
1
- import * as AD from "../../abstract-document/index.js";
2
- import { Page } from "./paginate.js";
1
+ import type * as AD from "../../abstract-document/index.js";
2
+ import type { Page } from "./paginate.js";
3
3
 
4
4
  export function updatePageRefs(pages: ReadonlyArray<Page>): Array<Page> {
5
5
  return pages.map((page) => updateRefsOnPage(page, pages));
@@ -1,13 +1,14 @@
1
1
  import { exhaustiveCheck } from "ts-exhaustive-check";
2
- import { AbstractDoc } from "../../abstract-document/abstract-doc.js";
3
- import { Resources, mergeResources } from "../../abstract-document/resources.js";
4
- import { Group } from "../../abstract-document/section-elements/group.js";
5
- import { Table } from "../../abstract-document/section-elements/table.js";
6
- import { SectionElement } from "../../abstract-document/section-elements/section-element.js";
7
- import { Paragraph } from "../../abstract-document/section-elements/paragraph.js";
8
- import { Section } from "../../abstract-document/page/section.js";
9
- import { TableRow } from "../../abstract-document/table/table-row.js";
10
- import { TableCell } from "../../abstract-document/table/table-cell.js";
2
+ import type { AbstractDoc } from "../../abstract-document/abstract-doc.js";
3
+ import type { Resources } from "../../abstract-document/resources.js";
4
+ import { mergeResources } from "../../abstract-document/resources.js";
5
+ import type { Group } from "../../abstract-document/section-elements/group.js";
6
+ import type { Table } from "../../abstract-document/section-elements/table.js";
7
+ import type { SectionElement } from "../../abstract-document/section-elements/section-element.js";
8
+ import type { Paragraph } from "../../abstract-document/section-elements/paragraph.js";
9
+ import type { Section } from "../../abstract-document/page/section.js";
10
+ import type { TableRow } from "../../abstract-document/table/table-row.js";
11
+ import type { TableCell } from "../../abstract-document/table/table-cell.js";
11
12
 
12
13
  export function getResources(doc: AbstractDoc): Resources {
13
14
  const resources = doc.children.map((s) => getResourcesSection(s));
@@ -55,7 +55,7 @@ export function render(element: any): any {
55
55
  }
56
56
  const props = element.props || {};
57
57
  const children = renderChildren(element);
58
- return (element.type as any)({ ...props, children });
58
+ return element.type({ ...props, children });
59
59
  }
60
60
 
61
61
  function renderChildren(element: React.ReactElement<any>): any {
@@ -1,11 +1,12 @@
1
1
  import { addResources, merge } from "../../abstract-document/abstract-doc.js";
2
- import { AbstractDoc } from "../../abstract-document/index.js";
2
+ import type { AbstractDoc } from "../../abstract-document/index.js";
3
3
  import * as StyleKey from "../../abstract-document/styles/style-key.js";
4
- import { Resources } from "../../abstract-document/resources.js";
5
- import { ADCreatorFn, creators, propsCreators } from "./creator.js";
4
+ import type { Resources } from "../../abstract-document/resources.js";
5
+ import type { ADCreatorFn } from "./creator.js";
6
+ import { creators, propsCreators } from "./creator.js";
6
7
  import { parseHandlebarsXml, type XmlElement } from "handlebars-xml";
7
8
  import { getFontStyleName } from "../../abstract-document-exporters/pdf/font.js";
8
- import { Font } from "../../abstract-document/primitives/font.js";
9
+ import type { Font } from "../../abstract-document/primitives/font.js";
9
10
 
10
11
  export type TemplateInput = {
11
12
  readonly template: string;
@@ -42,7 +43,7 @@ export async function abstractDocsXml(
42
43
  const combinedReport = addResources(merge(...abstractDocs), resources);
43
44
  return { type: "Ok", value: combinedReport };
44
45
  } catch (e) {
45
- return { type: "Err", error: typeof e === "string" ? e : (e as any).message };
46
+ return { type: "Err", error: typeof e === "string" ? e : e.message };
46
47
  }
47
48
  }
48
49
 
@@ -53,11 +54,11 @@ export function abstractDocXml(
53
54
  ): readonly [
54
55
  AbstractDoc.AbstractDoc,
55
56
  imageUrls: Record<string, true>,
56
- fontFamilies: Record<string, Partial<Record<keyof Font, boolean>>>
57
+ fontFamilies: Record<string, Partial<Record<keyof Font, boolean>>>,
57
58
  ] {
58
59
  const xml = parseHandlebarsXml(template, data, partials);
59
60
  const [imageUrls, fontFamilies, styleNames] = extractImageFontsStyleNames(xml);
60
- const doc = abstractDocXmlRecursive(creators(styleNames), xml[0]!);
61
+ const doc = abstractDocXmlRecursive(creators(styleNames), xml[0]);
61
62
  return [doc, imageUrls, fontFamilies];
62
63
  }
63
64
 
@@ -72,9 +73,9 @@ function abstractDocXmlRecursive(
72
73
  const childName = childElement.tagName;
73
74
  if (childName !== undefined) {
74
75
  if (childName === "StyleNames") {
75
- props.styles = abstractDocXmlRecursive(creators, childElement);
76
- } else if (childName === "StyleName" && childElement.attributes && childElement.attributes.name) {
77
- const styleName = StyleKey.create(childElement.attributes.type, childElement.attributes.name);
76
+ props["styles"] = abstractDocXmlRecursive(creators, childElement);
77
+ } else if (childName === "StyleName" && childElement.attributes && childElement.attributes["name"]) {
78
+ const styleName = StyleKey.create(childElement.attributes["type"], childElement.attributes["name"]);
78
79
  const style = abstractDocXmlRecursive(creators, childElement);
79
80
  props[styleName] = style;
80
81
  } else if (childName.startsWith(childName.charAt(0).toUpperCase())) {
@@ -85,11 +86,11 @@ function abstractDocXmlRecursive(
85
86
  // Some special keys should directly have an array of children as value instead of an object with children key
86
87
  const arrayedElements = ["header", "footer", "headerRows"];
87
88
  const childrenOnly = arrayedElements.findIndex((e) => e === childName) !== -1;
88
- const differentFirstPage = childElement.attributes.differentFirstPage;
89
+ const differentFirstPage = childElement.attributes["differentFirstPage"];
89
90
  if (differentFirstPage === "true" && childName === "header") {
90
- props.frontHeader = abstractDocXmlRecursive(creators, childElement, childrenOnly);
91
+ props["frontHeader"] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
91
92
  } else if (differentFirstPage === "true" && childName === "footer") {
92
- props.frontFooter = abstractDocXmlRecursive(creators, childElement, childrenOnly);
93
+ props["frontFooter"] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
93
94
  } else {
94
95
  props[childName] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
95
96
  }
@@ -119,19 +120,19 @@ function abstractDocXmlRecursive(
119
120
  }
120
121
 
121
122
  // Elements styling needs to have style: {type= "StyleName" }. Occures when having a <style></style> element.
122
- if (typeof obj.style === "object") {
123
- if (obj.columnSpan) {
124
- obj.style = { ...obj.style, type: "TableCellStyle" };
123
+ if (typeof obj["style"] === "object") {
124
+ if (obj["columnSpan"]) {
125
+ obj["style"] = { ...obj["style"], type: "TableCellStyle" };
125
126
  } else {
126
- switch (obj.type) {
127
+ switch (obj["type"]) {
127
128
  case "page":
128
- obj.style = { ...obj.style, type: "MasterPageStyle" };
129
+ obj["style"] = { ...obj["style"], type: "MasterPageStyle" };
129
130
  break;
130
131
  case "Group":
131
- obj.style = { ...obj.style, type: "GroupStyle" };
132
+ obj["style"] = { ...obj["style"], type: "GroupStyle" };
132
133
  break;
133
134
  case "Table":
134
- obj.style = { ...obj.style, type: "TableStyle" };
135
+ obj["style"] = { ...obj["style"], type: "TableStyle" };
135
136
  break;
136
137
  // Cell is missing type in abstract doc?!?!?!
137
138
  // case "TableCell":
@@ -142,12 +143,12 @@ function abstractDocXmlRecursive(
142
143
  case "TextParagraph":
143
144
  case "ImageParagraph":
144
145
  case "Paragraph":
145
- obj.style = { ...obj.style, type: "ParagraphStyle" };
146
+ obj["style"] = { ...obj["style"], type: "ParagraphStyle" };
146
147
  break;
147
148
  case "TextField":
148
149
  case "HyperLink":
149
150
  case "TextRun":
150
- obj.style = { ...obj.style, type: "TextStyle" };
151
+ obj["style"] = { ...obj["style"], type: "TextStyle" };
151
152
  break;
152
153
  default:
153
154
  break;
@@ -156,7 +157,7 @@ function abstractDocXmlRecursive(
156
157
  }
157
158
 
158
159
  if (children.length > 0) {
159
- obj.children = children;
160
+ obj["children"] = children;
160
161
  }
161
162
  return obj;
162
163
  }
@@ -188,49 +189,49 @@ function extractImageFontsStyleNames(
188
189
  styleNames: Record<string, string> = {},
189
190
  images: Record<string, true> = {},
190
191
  fonts: Record<string, Partial<Record<keyof Font, boolean>>> = {},
191
- currentFontFamily: string | undefined = undefined,
192
+ currentFontFamily?: string
192
193
  ): readonly [
193
194
  imageUrls: Record<string, true>,
194
195
  fontFamilies: Record<string, Partial<Record<keyof Font, boolean>>>,
195
- styleNames: Record<string, string>
196
+ styleNames: Record<string, string>,
196
197
  ] {
197
198
  let crFntFam = currentFontFamily;
198
199
  xmlElement.forEach((item) => {
199
- if (item.tagName.startsWith("Image") && item.attributes?.src) {
200
- images[item.attributes.src as string] = true;
200
+ if (item.tagName.startsWith("Image") && item.attributes?.["src"]) {
201
+ images[item.attributes["src"]] = true;
201
202
  } else if (item.tagName === "style") {
202
- const fontFamily = crFntFam ?? styleFamilies.Default;
203
- if(fontFamily) {
203
+ const fontFamily = crFntFam ?? styleFamilies["Default"];
204
+ if (fontFamily) {
204
205
  const styleName = getFontStyleName(item.attributes);
205
206
  (fonts[fontFamily] ??= {})[styleName] = true;
206
207
  }
207
- } else if(item.attributes.styleName !== undefined) {
208
- crFntFam = styleFamilies[item.attributes.styleName] ?? crFntFam;
209
- } else if (item.attributes.styleNames !== undefined) {
210
- const style = item.attributes.styleNames.split(",").find((style) => styleFamilies[style]);
211
- if(style) {
208
+ } else if (item.attributes["styleName"] !== undefined) {
209
+ crFntFam = styleFamilies[item.attributes["styleName"]] ?? crFntFam;
210
+ } else if (item.attributes["styleNames"] !== undefined) {
211
+ const style = item.attributes["styleNames"].split(",").find((style) => styleFamilies[style]);
212
+ if (style) {
212
213
  const fontFamily = styleFamilies[style];
213
- if(fontFamily) {
214
+ if (fontFamily) {
214
215
  crFntFam = fontFamily;
215
216
  }
216
217
  }
217
- } else if (item.attributes?.fontFamily) {
218
+ } else if (item.attributes?.["fontFamily"]) {
218
219
  const styleName = getFontStyleName(item.attributes);
219
- (fonts[item.attributes.fontFamily as string] ??= {})[styleName] = true;
220
- if (item.tagName === "StyleName" && item.attributes.name && item.attributes.type) {
221
- styleNames[item.attributes.name as string] = item.attributes.type;
220
+ (fonts[item.attributes["fontFamily"]] ??= {})[styleName] = true;
221
+ if (item.tagName === "StyleName" && item.attributes["name"] && item.attributes["type"]) {
222
+ styleNames[item.attributes["name"]] = item.attributes["type"];
222
223
  }
223
- } else if (item.tagName === "StyleName" && item.attributes.name && item.attributes.type) {
224
- styleNames[item.attributes.name as string] = item.attributes.type;
225
- if(item.attributes.type === "TextStyle" && item.attributes.fontFamily) {
224
+ } else if (item.tagName === "StyleName" && item.attributes["name"] && item.attributes["type"]) {
225
+ styleNames[item.attributes["name"]] = item.attributes["type"];
226
+ if (item.attributes["type"] === "TextStyle" && item.attributes["fontFamily"]) {
226
227
  const styleName = getFontStyleName(item.attributes);
227
- styleFamilies[item.attributes.name as string] = item.attributes.fontFamily;
228
- (fonts[item.attributes.fontFamily] ??= {})[styleName] = true;
228
+ styleFamilies[item.attributes["name"]] = item.attributes["fontFamily"];
229
+ (fonts[item.attributes["fontFamily"]] ??= {})[styleName] = true;
229
230
  }
230
231
  }
231
- if(item.children.length > 0) {
232
+ if (item.children.length > 0) {
232
233
  extractImageFontsStyleNames(item.children, styleFamilies, styleNames, images, fonts, crFntFam);
233
234
  }
234
235
  });
235
236
  return [images, fonts, styleNames];
236
- }
237
+ }