abstract-document 20.0.3 → 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 (104) hide show
  1. package/README.md +3 -3
  2. package/lib/abstract-document/atoms/line-break.d.ts +1 -1
  3. package/lib/abstract-document/atoms/line-break.d.ts.map +1 -1
  4. package/lib/abstract-document/atoms/line-break.js +1 -1
  5. package/lib/abstract-document/atoms/line-break.js.map +1 -1
  6. package/lib/abstract-document/atoms/link-target.js +1 -1
  7. package/lib/abstract-document/atoms/text-run.d.ts.map +1 -1
  8. package/lib/abstract-document/atoms/text-run.js +1 -0
  9. package/lib/abstract-document/atoms/text-run.js.map +1 -1
  10. package/lib/abstract-document/markdown/markdown.js +1 -1
  11. package/lib/abstract-document/markdown/markdown.js.map +1 -1
  12. package/lib/abstract-document/numberings/numbering-format.d.ts.map +1 -1
  13. package/lib/abstract-document/primitives/layout-foundation-color.js +4 -4
  14. package/lib/abstract-document/primitives/layout-foundation-color.js.map +1 -1
  15. package/lib/abstract-document/primitives/layout-foundation.js +1 -1
  16. package/lib/abstract-document/primitives/point.js +1 -1
  17. package/lib/abstract-document/section-elements/paragraph.js +1 -1
  18. package/lib/abstract-document/section-elements/paragraph.js.map +1 -1
  19. package/lib/abstract-document/styles/paragraph-style.js +1 -1
  20. package/lib/abstract-document/styles/paragraph-style.js.map +1 -1
  21. package/lib/abstract-document/styles/table-cell-style.d.ts.map +1 -1
  22. package/lib/abstract-document/styles/table-cell-style.js +1 -1
  23. package/lib/abstract-document/styles/table-cell-style.js.map +1 -1
  24. package/lib/abstract-document/styles/table-style.js +1 -1
  25. package/lib/abstract-document/styles/table-style.js.map +1 -1
  26. package/lib/abstract-document/styles/text-style.js +1 -1
  27. package/lib/abstract-document/styles/text-style.js.map +1 -1
  28. package/lib/abstract-document-exporters/docx/string-utils.d.ts.map +1 -1
  29. package/lib/abstract-document-exporters/docx/string-utils.js +1 -3
  30. package/lib/abstract-document-exporters/docx/string-utils.js.map +1 -1
  31. package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
  32. package/lib/abstract-document-exporters/docx/xml-writer.js +1 -0
  33. package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
  34. package/lib/abstract-document-exporters/docx2/render-image.js +1 -1
  35. package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
  36. package/lib/abstract-document-exporters/docx2/render.d.ts.map +1 -1
  37. package/lib/abstract-document-exporters/docx2/render.js +9 -5
  38. package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
  39. package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
  40. package/lib/abstract-document-exporters/pdf/font.js +1 -0
  41. package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
  42. package/lib/abstract-document-exporters/pdf/measure.d.ts.map +1 -1
  43. package/lib/abstract-document-exporters/pdf/measure.js +3 -2
  44. package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
  45. package/lib/abstract-document-exporters/pdf/paginate.d.ts.map +1 -1
  46. package/lib/abstract-document-exporters/pdf/paginate.js +3 -2
  47. package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
  48. package/lib/abstract-document-exporters/pdf/pre-process.js +2 -1
  49. package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
  50. package/lib/abstract-document-exporters/pdf/render-image.js +1 -1
  51. package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
  52. package/lib/abstract-document-exporters/pdf/render.d.ts.map +1 -1
  53. package/lib/abstract-document-exporters/pdf/render.js +1 -0
  54. package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
  55. package/lib/abstract-document-exporters/pdf/std-fonts.js +1 -1
  56. package/lib/abstract-document-exporters/pdf/textRunRow.d.ts.map +1 -1
  57. package/lib/abstract-document-exporters/pdf/textRunRow.js +21 -15
  58. package/lib/abstract-document-exporters/pdf/textRunRow.js.map +1 -1
  59. package/lib/abstract-document-jsx/index.js.map +1 -1
  60. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +1 -1
  61. package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
  62. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
  63. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +7 -1
  64. package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
  65. package/package.json +4 -4
  66. package/src/abstract-document/atoms/line-break.ts +1 -1
  67. package/src/abstract-document/atoms/link-target.ts +1 -1
  68. package/src/abstract-document/atoms/text-run.ts +1 -0
  69. package/src/abstract-document/markdown/markdown.ts +2 -2
  70. package/src/abstract-document/numberings/numbering-format.ts +1 -7
  71. package/src/abstract-document/primitives/layout-foundation-color.ts +4 -4
  72. package/src/abstract-document/primitives/layout-foundation.ts +1 -1
  73. package/src/abstract-document/primitives/point.ts +1 -1
  74. package/src/abstract-document/section-elements/paragraph.ts +1 -1
  75. package/src/abstract-document/styles/paragraph-style.ts +1 -1
  76. package/src/abstract-document/styles/table-cell-style.ts +1 -8
  77. package/src/abstract-document/styles/table-style.ts +1 -1
  78. package/src/abstract-document/styles/text-style.ts +20 -20
  79. package/src/abstract-document-exporters/docx/string-utils.ts +1 -5
  80. package/src/abstract-document-exporters/docx/xml-writer.ts +1 -0
  81. package/src/abstract-document-exporters/docx2/render-image.ts +5 -5
  82. package/src/abstract-document-exporters/docx2/render.ts +62 -40
  83. package/src/abstract-document-exporters/pdf/font.ts +11 -10
  84. package/src/abstract-document-exporters/pdf/measure.ts +4 -2
  85. package/src/abstract-document-exporters/pdf/paginate.ts +11 -6
  86. package/src/abstract-document-exporters/pdf/pre-process.ts +2 -1
  87. package/src/abstract-document-exporters/pdf/render-image.ts +9 -9
  88. package/src/abstract-document-exporters/pdf/render.ts +1 -0
  89. package/src/abstract-document-exporters/pdf/std-fonts.ts +1 -1
  90. package/src/abstract-document-exporters/pdf/textRunRow.ts +108 -74
  91. package/src/abstract-document-jsx/index.ts +1 -1
  92. package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +10 -10
  93. package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +7 -1
  94. package/src/abstract-document-xml/xsd-template/styles.ts +1 -1
  95. package/lib/abstract-document/table/text-row.d.ts +0 -2
  96. package/lib/abstract-document/table/text-row.d.ts.map +0 -1
  97. package/lib/abstract-document/table/text-row.js +0 -2
  98. package/lib/abstract-document/table/text-row.js.map +0 -1
  99. package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts +0 -2
  100. package/lib/abstract-document-exporters/docx/docx-document-renderer.d.ts.map +0 -1
  101. package/lib/abstract-document-exporters/docx/docx-document-renderer.js +0 -1085
  102. package/lib/abstract-document-exporters/docx/docx-document-renderer.js.map +0 -1
  103. package/src/abstract-document/table/text-row.ts +0 -0
  104. 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
+ }
@@ -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 {
@@ -43,7 +43,7 @@ export async function abstractDocsXml(
43
43
  const combinedReport = addResources(merge(...abstractDocs), resources);
44
44
  return { type: "Ok", value: combinedReport };
45
45
  } catch (e) {
46
- return { type: "Err", error: typeof e === "string" ? e : (e as any).message };
46
+ return { type: "Err", error: typeof e === "string" ? e : e.message };
47
47
  }
48
48
  }
49
49
 
@@ -54,11 +54,11 @@ export function abstractDocXml(
54
54
  ): readonly [
55
55
  AbstractDoc.AbstractDoc,
56
56
  imageUrls: Record<string, true>,
57
- fontFamilies: Record<string, Partial<Record<keyof Font, boolean>>>
57
+ fontFamilies: Record<string, Partial<Record<keyof Font, boolean>>>,
58
58
  ] {
59
59
  const xml = parseHandlebarsXml(template, data, partials);
60
60
  const [imageUrls, fontFamilies, styleNames] = extractImageFontsStyleNames(xml);
61
- const doc = abstractDocXmlRecursive(creators(styleNames), xml[0]!);
61
+ const doc = abstractDocXmlRecursive(creators(styleNames), xml[0]);
62
62
  return [doc, imageUrls, fontFamilies];
63
63
  }
64
64
 
@@ -189,16 +189,16 @@ function extractImageFontsStyleNames(
189
189
  styleNames: Record<string, string> = {},
190
190
  images: Record<string, true> = {},
191
191
  fonts: Record<string, Partial<Record<keyof Font, boolean>>> = {},
192
- currentFontFamily: string | undefined = undefined
192
+ currentFontFamily?: string
193
193
  ): readonly [
194
194
  imageUrls: Record<string, true>,
195
195
  fontFamilies: Record<string, Partial<Record<keyof Font, boolean>>>,
196
- styleNames: Record<string, string>
196
+ styleNames: Record<string, string>,
197
197
  ] {
198
198
  let crFntFam = currentFontFamily;
199
199
  xmlElement.forEach((item) => {
200
200
  if (item.tagName.startsWith("Image") && item.attributes?.["src"]) {
201
- images[item.attributes["src"] as string] = true;
201
+ images[item.attributes["src"]] = true;
202
202
  } else if (item.tagName === "style") {
203
203
  const fontFamily = crFntFam ?? styleFamilies["Default"];
204
204
  if (fontFamily) {
@@ -217,15 +217,15 @@ function extractImageFontsStyleNames(
217
217
  }
218
218
  } else if (item.attributes?.["fontFamily"]) {
219
219
  const styleName = getFontStyleName(item.attributes);
220
- (fonts[item.attributes["fontFamily"] as string] ??= {})[styleName] = true;
220
+ (fonts[item.attributes["fontFamily"]] ??= {})[styleName] = true;
221
221
  if (item.tagName === "StyleName" && item.attributes["name"] && item.attributes["type"]) {
222
- styleNames[item.attributes["name"] as string] = item.attributes["type"];
222
+ styleNames[item.attributes["name"]] = item.attributes["type"];
223
223
  }
224
224
  } else if (item.tagName === "StyleName" && item.attributes["name"] && item.attributes["type"]) {
225
- styleNames[item.attributes["name"] as string] = item.attributes["type"];
225
+ styleNames[item.attributes["name"]] = item.attributes["type"];
226
226
  if (item.attributes["type"] === "TextStyle" && item.attributes["fontFamily"]) {
227
227
  const styleName = getFontStyleName(item.attributes);
228
- styleFamilies[item.attributes["name"] as string] = item.attributes["fontFamily"];
228
+ styleFamilies[item.attributes["name"]] = item.attributes["fontFamily"];
229
229
  (fonts[item.attributes["fontFamily"]] ??= {})[styleName] = true;
230
230
  }
231
231
  }
@@ -71,6 +71,7 @@ export const propsCreators: Record<string, ADCreatorFn> = {
71
71
  },
72
72
  columnWidths: (props: { readonly columnWidths: string; readonly columnMultiplier: string }): unknown => {
73
73
  const columnWidths = (props.columnWidths ?? "")
74
+ // oxlint-disable-next-line typescript/no-unnecessary-type-conversion -- allProps can carry non-strings
74
75
  .toString()
75
76
  .split(",")
76
77
  .map((item: string) => {
@@ -87,10 +88,13 @@ export const propsCreators: Record<string, ADCreatorFn> = {
87
88
  return props.paperSize;
88
89
  }
89
90
  const parts = props.paperSize.split("x");
90
- return { width: Number(parts[0]) ?? 595, height: Number(parts[1]) ?? 842 };
91
+ const width = Number(parts[0] ?? 595);
92
+ const height = Number(parts[1] ?? 842);
93
+ return { width: Number.isNaN(width) ? 595 : width, height: Number.isNaN(height) ? 842 : height };
91
94
  },
92
95
  borders: (props: { readonly borders: string }): unknown => {
93
96
  const borders: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
97
+ // oxlint-disable-next-line typescript/no-unnecessary-type-conversion -- allProps can carry non-strings
94
98
  const propBorders = props.borders.toString().split(" ");
95
99
  if (!propBorders) {
96
100
  return borders;
@@ -157,6 +161,7 @@ export const propsCreators: Record<string, ADCreatorFn> = {
157
161
  padding: (props: { readonly padding: string }): unknown => {
158
162
  const padding: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
159
163
 
164
+ // oxlint-disable-next-line typescript/no-unnecessary-type-conversion -- allProps can carry non-strings
160
165
  const paddings = props.padding.toString().split(" ");
161
166
  if (!paddings) {
162
167
  return padding;
@@ -222,6 +227,7 @@ export const propsCreators: Record<string, ADCreatorFn> = {
222
227
  },
223
228
  margins: (props: { readonly margins: string }): unknown => {
224
229
  const margins: { [k: string]: number } = { top: 0, right: 0, bottom: 0, left: 0 };
230
+ // oxlint-disable-next-line typescript/no-unnecessary-type-conversion -- allProps can carry non-strings
225
231
  const propMargins = props.margins.toString().split(" ");
226
232
  if (!propMargins) {
227
233
  return margins;
@@ -319,4 +319,4 @@ export const layoutFoundation = `<xs:complexType name="LayoutFoundation">
319
319
  export const pageColumnLayout = `<xs:complexType name="PageColumnLayout">
320
320
  <xs:attribute name="columnCount" type="xs:decimal" />
321
321
  <xs:attribute name="columnGap" type="xs:decimal" />
322
- </xs:complexType>`;
322
+ </xs:complexType>`;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=text-row.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"text-row.d.ts","sourceRoot":"","sources":["../../../src/abstract-document/table/text-row.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=text-row.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"text-row.js","sourceRoot":"","sources":["../../../src/abstract-document/table/text-row.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=docx-document-renderer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docx-document-renderer.d.ts","sourceRoot":"","sources":["../../../src/abstract-document-exporters/docx/docx-document-renderer.ts"],"names":[],"mappings":""}