abstract-document 20.1.6 → 20.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/abstract-document/atoms/text-run.d.ts.map +1 -1
- package/lib/abstract-document/atoms/text-run.js +1 -7
- package/lib/abstract-document/atoms/text-run.js.map +1 -1
- package/lib/abstract-document/markdown/markdown.d.ts.map +1 -1
- package/lib/abstract-document/markdown/markdown.js +58 -60
- package/lib/abstract-document/markdown/markdown.js.map +1 -1
- package/lib/abstract-document/resources.d.ts.map +1 -1
- package/lib/abstract-document/resources.js +1 -3
- package/lib/abstract-document/resources.js.map +1 -1
- package/lib/abstract-document/styles/table-style.js +2 -2
- package/lib/abstract-document/styles/table-style.js.map +1 -1
- package/lib/abstract-document/styles/text-style.js +6 -6
- package/lib/abstract-document/styles/text-style.js.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.d.ts.map +1 -1
- package/lib/abstract-document-exporters/docx/xml-writer.js +14 -17
- package/lib/abstract-document-exporters/docx/xml-writer.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render-image.js +9 -11
- package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/docx2/render.js +2 -6
- package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/font.js +1 -2
- package/lib/abstract-document-exporters/pdf/font.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/measure.js +3 -3
- package/lib/abstract-document-exporters/pdf/measure.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/paginate.js +1 -0
- package/lib/abstract-document-exporters/pdf/paginate.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/pre-process.js +4 -6
- package/lib/abstract-document-exporters/pdf/pre-process.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render-image.js +2 -2
- package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/render.js +23 -26
- package/lib/abstract-document-exporters/pdf/render.js.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.d.ts.map +1 -1
- package/lib/abstract-document-exporters/pdf/textRunRow.js +21 -23
- package/lib/abstract-document-exporters/pdf/textRunRow.js.map +1 -1
- package/lib/abstract-document-jsx/index.d.ts.map +1 -1
- package/lib/abstract-document-jsx/index.js +5 -5
- package/lib/abstract-document-jsx/index.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js +32 -29
- package/lib/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js +29 -46
- package/lib/abstract-document-xml/abstract-doc-of-xml/creator.js.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.d.ts.map +1 -1
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js +16 -5
- package/lib/abstract-document-xml/abstract-doc-of-xml/custom-elements.js.map +1 -1
- package/package.json +4 -4
- package/src/abstract-document/atoms/text-run.ts +1 -7
- package/src/abstract-document/markdown/markdown.ts +74 -76
- package/src/abstract-document/resources.ts +1 -3
- package/src/abstract-document/styles/table-style.ts +2 -2
- package/src/abstract-document/styles/text-style.ts +6 -6
- package/src/abstract-document-exporters/docx/xml-writer.ts +16 -19
- package/src/abstract-document-exporters/docx2/render-image.ts +11 -13
- package/src/abstract-document-exporters/docx2/render.ts +3 -7
- package/src/abstract-document-exporters/pdf/font.ts +1 -2
- package/src/abstract-document-exporters/pdf/measure.ts +9 -9
- package/src/abstract-document-exporters/pdf/paginate.ts +3 -2
- package/src/abstract-document-exporters/pdf/pre-process.ts +5 -7
- package/src/abstract-document-exporters/pdf/render-image.ts +9 -9
- package/src/abstract-document-exporters/pdf/render.ts +25 -28
- package/src/abstract-document-exporters/pdf/textRunRow.ts +32 -35
- package/src/abstract-document-jsx/index.ts +7 -7
- package/src/abstract-document-xml/abstract-doc-of-xml/abstract-doc-of-xml.ts +30 -27
- package/src/abstract-document-xml/abstract-doc-of-xml/creator.ts +38 -51
- package/src/abstract-document-xml/abstract-doc-of-xml/custom-elements.tsx +22 -8
- package/src/custom_typings/pdf2json/index.d.ts +10 -1
- package/src/custom_typings/remark-parse/index.d.ts +4 -1
- package/src/custom_typings/remark-sub-super/index.d.ts +4 -1
- package/src/custom_typings/svg-to-pdfkit/index.d.ts +4 -1
- package/src/custom_typings/unified/index.d.ts +8 -1
|
@@ -166,7 +166,7 @@ function measureParagraph(
|
|
|
166
166
|
currentRowHeight = 0;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
if (row.length === 1 && row[0]
|
|
169
|
+
if (row.length === 1 && row[0]!.type === "LineBreak") {
|
|
170
170
|
paragraphHeight += currentRowHeight;
|
|
171
171
|
} else if (hasAtomImage) {
|
|
172
172
|
paragraphHeight += desiredHeight + currentRowHeight;
|
|
@@ -276,7 +276,7 @@ export function measureTable(
|
|
|
276
276
|
// Try to find the minimal height required for each row
|
|
277
277
|
const cells = [];
|
|
278
278
|
for (let i = 0; i < rows.length; i++) {
|
|
279
|
-
cells.push(...rows[i]
|
|
279
|
+
cells.push(...rows[i]!.children.map((child) => ({ child, rowIndex: i })));
|
|
280
280
|
}
|
|
281
281
|
cells.sort((a, b) => {
|
|
282
282
|
if (a.child.rowSpan === b.child.rowSpan) {
|
|
@@ -287,16 +287,16 @@ export function measureTable(
|
|
|
287
287
|
});
|
|
288
288
|
const minRowHeights = Array.from({ length: rows.length }, () => 0);
|
|
289
289
|
for (const { child, rowIndex } of cells) {
|
|
290
|
-
const rowSpan = child.rowSpan || 1;
|
|
290
|
+
const rowSpan = Math.min(child.rowSpan || 1, rows.length - rowIndex);
|
|
291
291
|
let currentHeight = 0;
|
|
292
292
|
for (let i = rowIndex; i < rowIndex + rowSpan; i++) {
|
|
293
|
-
currentHeight += minRowHeights[i]
|
|
293
|
+
currentHeight += minRowHeights[i]!;
|
|
294
294
|
}
|
|
295
295
|
const adjustment = getDesiredSize(child, desiredSizes).height - currentHeight;
|
|
296
296
|
if (adjustment > 0) {
|
|
297
297
|
const adjustmentPerRow = adjustment / rowSpan;
|
|
298
298
|
for (let i = rowIndex; i < rowIndex + rowSpan; i++) {
|
|
299
|
-
minRowHeights[i] += adjustmentPerRow;
|
|
299
|
+
minRowHeights[i]! += adjustmentPerRow;
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
}
|
|
@@ -306,8 +306,8 @@ export function measureTable(
|
|
|
306
306
|
: table.columnWidths.reduce((a, b) => a + b, styleMargins.left + styleMargins.right);
|
|
307
307
|
let desiredHeight = styleMargins.top + styleMargins.bottom;
|
|
308
308
|
for (let i = 0; i < rows.length; i++) {
|
|
309
|
-
const row = rows[i]
|
|
310
|
-
const rowHeight = minRowHeights[i]
|
|
309
|
+
const row = rows[i]!;
|
|
310
|
+
const rowHeight = minRowHeights[i]!;
|
|
311
311
|
desiredHeight += rowHeight;
|
|
312
312
|
desiredSizes.set(row, AD.Size.create(desiredWidth, rowHeight));
|
|
313
313
|
for (const cell of row.children) {
|
|
@@ -460,7 +460,7 @@ function measureImage(resources: AD.Resources.Resources, availableSize: AD.Size.
|
|
|
460
460
|
desiredWidth = availableSize.width;
|
|
461
461
|
} else if (image.width) {
|
|
462
462
|
desiredWidth = image.width;
|
|
463
|
-
} else if (resource
|
|
463
|
+
} else if (resource.abstractImage.size.width) {
|
|
464
464
|
desiredWidth = resource.abstractImage.size.width * (image.height / resource.abstractImage.size.height);
|
|
465
465
|
}
|
|
466
466
|
|
|
@@ -469,7 +469,7 @@ function measureImage(resources: AD.Resources.Resources, availableSize: AD.Size.
|
|
|
469
469
|
desiredHeight = availableSize.height;
|
|
470
470
|
} else if (image.height) {
|
|
471
471
|
desiredHeight = image.height;
|
|
472
|
-
} else if (resource
|
|
472
|
+
} else if (resource.abstractImage.size.height) {
|
|
473
473
|
desiredHeight = resource.abstractImage.size.height * (image.width / resource.abstractImage.size.width);
|
|
474
474
|
}
|
|
475
475
|
if (!resource.scaleMaxHeight || !resource.scaleMaxWidth) {
|
|
@@ -41,7 +41,7 @@ function paginateSection(
|
|
|
41
41
|
let currentPage = previousPage;
|
|
42
42
|
for (let i = 0; i < children.length; ++i) {
|
|
43
43
|
const contentRect = getPageContentRect(desiredSizes, section, pages.length + 1);
|
|
44
|
-
const element = children[i]
|
|
44
|
+
const element = children[i]!;
|
|
45
45
|
if (element.type === "PageBreak") {
|
|
46
46
|
columns.push({ elements });
|
|
47
47
|
currentPage = createPage(resources, desiredSizes, currentPage, section, columns, pages.length === 0);
|
|
@@ -371,7 +371,8 @@ function splitTableAt(
|
|
|
371
371
|
//This causes them to be rendered like an empty cell
|
|
372
372
|
//while keeping the remaining rowspan which was calculated
|
|
373
373
|
//in the pre-process step
|
|
374
|
-
|
|
374
|
+
// splitTable selects an existing row, and only splits tables with at least two rows.
|
|
375
|
+
const splitRow = table.children[splitIndex]!;
|
|
375
376
|
const firstTailRow: Array<AD.TableCell.TableCell> = [];
|
|
376
377
|
for (const cell of splitRow.children) {
|
|
377
378
|
firstTailRow.push({ ...cell, dummy: false });
|
|
@@ -80,7 +80,7 @@ function preProcessParagraph(paragraph: AD.Paragraph.Paragraph, resources: AD.Re
|
|
|
80
80
|
if (numberOverride !== undefined) {
|
|
81
81
|
_numberingLevelItems.set(key, numberOverride);
|
|
82
82
|
} else if (!_numberingLevelItems.has(key)) {
|
|
83
|
-
_numberingLevelItems.set(key, levelDefinitions[level]
|
|
83
|
+
_numberingLevelItems.set(key, levelDefinitions[level]?.start ?? 1);
|
|
84
84
|
} else if (append !== true) {
|
|
85
85
|
_numberingLevelItems.set(key, (_numberingLevelItems.get(key) ?? 0) + 1);
|
|
86
86
|
}
|
|
@@ -158,7 +158,7 @@ function adjustParagraph(paragraph: AD.Paragraph.Paragraph): Array<AD.SectionEle
|
|
|
158
158
|
const lines = text.split("\n");
|
|
159
159
|
|
|
160
160
|
for (let i = 0; i < lines.length; i++) {
|
|
161
|
-
const line = lines[i]
|
|
161
|
+
const line = lines[i]!;
|
|
162
162
|
const tokens = line.split(spaceRegex).filter((t) => t.length !== 0);
|
|
163
163
|
for (const token of tokens) {
|
|
164
164
|
newChildren.push({
|
|
@@ -282,11 +282,9 @@ function preProcessTable(table: AD.Table.Table, resources: AD.Resources.Resource
|
|
|
282
282
|
const processedHeaders = [];
|
|
283
283
|
const processedChildren = [];
|
|
284
284
|
const rowSpans: Map<number, AD.TableCell.TableCell> = new Map();
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
processedHeaders.push(header);
|
|
289
|
-
}
|
|
285
|
+
for (const row of table.headerRows) {
|
|
286
|
+
const header = preProcessTableRow(row, rowSpans, resources);
|
|
287
|
+
processedHeaders.push(header);
|
|
290
288
|
}
|
|
291
289
|
for (const row of table.children) {
|
|
292
290
|
const children = preProcessTableRow(row, rowSpans, resources);
|
|
@@ -120,7 +120,7 @@ function abstractComponentToPdf(
|
|
|
120
120
|
break;
|
|
121
121
|
case "polyline":
|
|
122
122
|
for (let i = 0; i < component.points.length; ++i) {
|
|
123
|
-
const p = component.points[i]
|
|
123
|
+
const p = component.points[i]!;
|
|
124
124
|
if (i === 0) {
|
|
125
125
|
pdf.moveTo(p.x, p.y);
|
|
126
126
|
} else {
|
|
@@ -209,7 +209,7 @@ function addWithSvgToPdfKit(
|
|
|
209
209
|
let svgUpdated = svg;
|
|
210
210
|
["fill=", "stroke=", "color="].forEach((t) => {
|
|
211
211
|
let index = 0;
|
|
212
|
-
|
|
212
|
+
for (;;) {
|
|
213
213
|
index = svgUpdated.indexOf(t, index);
|
|
214
214
|
if (index === -1) {
|
|
215
215
|
break;
|
|
@@ -227,7 +227,7 @@ function addWithSvgToPdfKit(
|
|
|
227
227
|
|
|
228
228
|
["stroke-dasharray="].forEach((t) => {
|
|
229
229
|
let index = 0;
|
|
230
|
-
|
|
230
|
+
for (;;) {
|
|
231
231
|
index = svgUpdated.indexOf(t, index);
|
|
232
232
|
if (index === -1) {
|
|
233
233
|
break;
|
|
@@ -312,7 +312,7 @@ function applyStrokeDashStyle(pdf: PDFKit.PDFDocument, dashStyle: AbstractImage.
|
|
|
312
312
|
break;
|
|
313
313
|
}
|
|
314
314
|
const actualIndex = index + 1;
|
|
315
|
-
const replacementValue = dashes[actualIndex - 1] + dashes[actualIndex + 1]
|
|
315
|
+
const replacementValue = dashes[actualIndex - 1]! + dashes[actualIndex + 1]!;
|
|
316
316
|
dashes = dashes
|
|
317
317
|
.slice(0, actualIndex - 1)
|
|
318
318
|
.concat([replacementValue])
|
|
@@ -322,7 +322,7 @@ function applyStrokeDashStyle(pdf: PDFKit.PDFDocument, dashStyle: AbstractImage.
|
|
|
322
322
|
// The stroke array only having two elements (a dash value and space
|
|
323
323
|
// value) is a special case.
|
|
324
324
|
if (dashes.length === 1) {
|
|
325
|
-
dashes = [dashes[0]
|
|
325
|
+
dashes = [dashes[0]!, dashes[0]!];
|
|
326
326
|
if (dashes[0] === 0) {
|
|
327
327
|
pdf.strokeOpacity(0);
|
|
328
328
|
}
|
|
@@ -371,8 +371,8 @@ function applyStrokeDashStyle(pdf: PDFKit.PDFDocument, dashStyle: AbstractImage.
|
|
|
371
371
|
//
|
|
372
372
|
// ---␣␣-----␣␣␣␣
|
|
373
373
|
// ⎸
|
|
374
|
-
phase -= dashes[1]
|
|
375
|
-
dashes[dashes.length - 1] += dashes[1]
|
|
374
|
+
phase -= dashes[1]!;
|
|
375
|
+
dashes[dashes.length - 1]! += dashes[1]!;
|
|
376
376
|
dashes = dashes.slice(2);
|
|
377
377
|
}
|
|
378
378
|
if (dashes[dashes.length - 1] === 0) {
|
|
@@ -392,8 +392,8 @@ function applyStrokeDashStyle(pdf: PDFKit.PDFDocument, dashStyle: AbstractImage.
|
|
|
392
392
|
// ------␣␣␣␣---␣␣
|
|
393
393
|
// ⎸
|
|
394
394
|
//
|
|
395
|
-
phase += dashes[dashes.length - 2]
|
|
396
|
-
dashes[0] += dashes[dashes.length - 2]
|
|
395
|
+
phase += dashes[dashes.length - 2]!;
|
|
396
|
+
dashes[0]! += dashes[dashes.length - 2]!;
|
|
397
397
|
dashes = dashes.slice(0, -2);
|
|
398
398
|
}
|
|
399
399
|
}
|
|
@@ -67,9 +67,7 @@ function renderPage(parentResources: AD.Resources.Resources, pdfKit: PDFKit.PDFD
|
|
|
67
67
|
const contentRect = addPage(pdfKit, page);
|
|
68
68
|
|
|
69
69
|
page.namedDestionations.forEach((dest) => {
|
|
70
|
-
|
|
71
|
-
pdfKit.addNamedDestination(dest);
|
|
72
|
-
}
|
|
70
|
+
pdfKit.addNamedDestination(dest);
|
|
73
71
|
});
|
|
74
72
|
|
|
75
73
|
const { headerMargins, footerMargins } = getHeaderAndFooter(section, page.pageNo);
|
|
@@ -119,7 +117,7 @@ function renderPage(parentResources: AD.Resources.Resources, pdfKit: PDFKit.PDFD
|
|
|
119
117
|
for (let columnIndex = 0; columnIndex < page.columns.length; columnIndex++) {
|
|
120
118
|
const x = contentRect.x + columnStep * columnIndex;
|
|
121
119
|
let y = elementStart;
|
|
122
|
-
for (const element of page.columns[columnIndex]
|
|
120
|
+
for (const element of page.columns[columnIndex]!.elements) {
|
|
123
121
|
const elementSize = getDesiredSize(element, desiredSizes);
|
|
124
122
|
const isAbsolute = AD.Position.isPositionAbsolute(element);
|
|
125
123
|
renderSectionElement(
|
|
@@ -254,26 +252,24 @@ function renderParagraph(
|
|
|
254
252
|
continue;
|
|
255
253
|
}
|
|
256
254
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
currentWidth = atomSize.width;
|
|
276
|
-
}
|
|
255
|
+
// Atom is Image
|
|
256
|
+
if (previousAtomType !== "Image") {
|
|
257
|
+
// Previous was not image
|
|
258
|
+
rows.push(currentRow);
|
|
259
|
+
currentRow = [];
|
|
260
|
+
currentWidth = 0;
|
|
261
|
+
previousAtomType = atom.type;
|
|
262
|
+
}
|
|
263
|
+
const atomSize = getDesiredSize(atom, desiredSizes);
|
|
264
|
+
if (currentWidth + atomSize.width < availableWidth || currentRow.length === 0) {
|
|
265
|
+
// Image fits in current row/current row is empty
|
|
266
|
+
currentRow.push(atom);
|
|
267
|
+
currentWidth += atomSize.width;
|
|
268
|
+
} else {
|
|
269
|
+
// Image does not fit in current row
|
|
270
|
+
rows.push(currentRow);
|
|
271
|
+
currentRow = [atom];
|
|
272
|
+
currentWidth = atomSize.width;
|
|
277
273
|
}
|
|
278
274
|
}
|
|
279
275
|
if (currentRow.length > 0) {
|
|
@@ -287,7 +283,7 @@ function renderParagraph(
|
|
|
287
283
|
const newRows = rowsSplit(rows, availableWidth, desiredSizes, alignment, pdfKit, resources, style.textStyle);
|
|
288
284
|
const { newDesiredSizes, combinedRows } = rowsCombineTextRuns(resources, pdfKit, newRows, desiredSizes, alignment, style.textStyle);
|
|
289
285
|
for (let r = 0; r < combinedRows.length; r++) {
|
|
290
|
-
const row = combinedRows[r]
|
|
286
|
+
const row = combinedRows[r]!;
|
|
291
287
|
const isLast = r === combinedRows.length - 1;
|
|
292
288
|
if (row.length === 0) {
|
|
293
289
|
continue;
|
|
@@ -304,7 +300,7 @@ function renderParagraph(
|
|
|
304
300
|
x -= styleMargins.right;
|
|
305
301
|
}
|
|
306
302
|
|
|
307
|
-
if (row.length > 1 || row[0]
|
|
303
|
+
if (row.length > 1 || row[0]!.type === "Image" || row[0]!.type === "TextRun" || row[0]!.type === "TextField") {
|
|
308
304
|
// Using continued with alignment "center" or "right" is broken:
|
|
309
305
|
// https://github.com/foliojs/pdfkit/issues/240
|
|
310
306
|
// Therefore we have to position it ourself
|
|
@@ -744,8 +740,9 @@ function renderRow(
|
|
|
744
740
|
|
|
745
741
|
let height = rowSize.height;
|
|
746
742
|
if (cell.rowSpan > 1) {
|
|
747
|
-
|
|
748
|
-
|
|
743
|
+
const rows = [...table.headerRows, ...table.children];
|
|
744
|
+
for (let index = rowIndex + 1; index < Math.min(rowIndex + cell.rowSpan, rows.length); index++) {
|
|
745
|
+
height += getDesiredSize(rows[index]!, desiredSizes).height;
|
|
749
746
|
}
|
|
750
747
|
}
|
|
751
748
|
const cellSize = getDesiredSize(cell, desiredSizes);
|
|
@@ -37,7 +37,7 @@ export function rowsSplit(
|
|
|
37
37
|
let lastWasSpace = false;
|
|
38
38
|
|
|
39
39
|
for (let i = 0; i < row.length; i++) {
|
|
40
|
-
const atom = row[i]
|
|
40
|
+
const atom = row[i]!;
|
|
41
41
|
const size = getDesiredSize(atom, desiredSizes);
|
|
42
42
|
const width = size.width;
|
|
43
43
|
const height = size.height;
|
|
@@ -83,7 +83,7 @@ export function rowsSplit(
|
|
|
83
83
|
if (splittedWord.length > 0) {
|
|
84
84
|
const heightPerRow = height / splittedWord.length;
|
|
85
85
|
const [first, ...rest] = splittedWord;
|
|
86
|
-
if (!first
|
|
86
|
+
if (!first) {
|
|
87
87
|
continue;
|
|
88
88
|
}
|
|
89
89
|
//add the first to the current row
|
|
@@ -92,7 +92,7 @@ export function rowsSplit(
|
|
|
92
92
|
currentRow.push(newFirstRowAtom);
|
|
93
93
|
|
|
94
94
|
//then add new rows
|
|
95
|
-
for (const part of rest
|
|
95
|
+
for (const part of rest) {
|
|
96
96
|
newRows.push(currentRow);
|
|
97
97
|
const newAtom = { ...atom, text: part.text };
|
|
98
98
|
desiredSizes.set(newAtom, { width: part.width, height: heightPerRow });
|
|
@@ -175,7 +175,7 @@ export function rowsCombineTextRuns(
|
|
|
175
175
|
|
|
176
176
|
let currentString = "";
|
|
177
177
|
let currentHeight = 0;
|
|
178
|
-
let current: AD.
|
|
178
|
+
let current: AD.TextRun.TextRun | undefined = undefined;
|
|
179
179
|
let currentStyle: string = "";
|
|
180
180
|
|
|
181
181
|
const newRows: Array<ReadonlyArray<AD.Atom.Atom>> = [];
|
|
@@ -184,7 +184,7 @@ export function rowsCombineTextRuns(
|
|
|
184
184
|
let isFirst = true;
|
|
185
185
|
|
|
186
186
|
for (let i = 0; i < row.length; i++) {
|
|
187
|
-
const atom = row[i]
|
|
187
|
+
const atom = row[i]!;
|
|
188
188
|
const isLast = i === row.length - 1;
|
|
189
189
|
const measurement = getDesiredSize(atom, desiredSizes);
|
|
190
190
|
|
|
@@ -253,30 +253,28 @@ export function rowsCombineTextRuns(
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
if (isLast) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
currentString = currentString.slice(0, -1);
|
|
261
|
-
}
|
|
256
|
+
//does the last contain spaces at the end?
|
|
257
|
+
if (alignment === "right") {
|
|
258
|
+
while (currentString.endsWith(" ")) {
|
|
259
|
+
currentString = currentString.slice(0, -1);
|
|
262
260
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
isFirst = false;
|
|
261
|
+
}
|
|
262
|
+
if (isFirst && alignment === "left") {
|
|
263
|
+
while (currentString.startsWith(" ")) {
|
|
264
|
+
currentString = currentString.slice(1);
|
|
268
265
|
}
|
|
269
|
-
|
|
270
|
-
const newTextRun: AD.Atom.Atom = {
|
|
271
|
-
...current,
|
|
272
|
-
text: currentString,
|
|
273
|
-
};
|
|
274
|
-
newRow.push(newTextRun);
|
|
275
|
-
desiredSizes.set(newTextRun, {
|
|
276
|
-
width: stringWidth(current, pdf, currentString, resources, defaultStyle),
|
|
277
|
-
height: currentHeight,
|
|
278
|
-
});
|
|
266
|
+
isFirst = false;
|
|
279
267
|
}
|
|
268
|
+
|
|
269
|
+
const newTextRun: AD.Atom.Atom = {
|
|
270
|
+
...current,
|
|
271
|
+
text: currentString,
|
|
272
|
+
};
|
|
273
|
+
newRow.push(newTextRun);
|
|
274
|
+
desiredSizes.set(newTextRun, {
|
|
275
|
+
width: stringWidth(current, pdf, currentString, resources, defaultStyle),
|
|
276
|
+
height: currentHeight,
|
|
277
|
+
});
|
|
280
278
|
}
|
|
281
279
|
}
|
|
282
280
|
current = undefined;
|
|
@@ -295,15 +293,14 @@ function stringWidth(
|
|
|
295
293
|
resources: AD.Resources.Resources,
|
|
296
294
|
defaultStyle: AD.TextStyle.TextStyle
|
|
297
295
|
): number {
|
|
298
|
-
const style =
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
) as AD.TextStyle.TextStyle) ?? defaultStyle;
|
|
296
|
+
const style = (AD.Resources.getNestedStyle(
|
|
297
|
+
defaultStyle,
|
|
298
|
+
textRun.style,
|
|
299
|
+
"TextStyle",
|
|
300
|
+
textRun.styleName,
|
|
301
|
+
resources,
|
|
302
|
+
textRun.nestedStyleNames ?? []
|
|
303
|
+
) ?? defaultStyle) as AD.TextStyle.TextStyle;
|
|
307
304
|
|
|
308
305
|
const font = getFontNameStyle(style);
|
|
309
306
|
const fontSize = AD.TextStyle.calculateFontSize(style, 10);
|
|
@@ -32,15 +32,15 @@ export const AbstractDoc = (props?: AbstractDoc1.AbstractDocProps & ChildrenProp
|
|
|
32
32
|
export const Section = (props?: Section1.SectionProps & ChildrenProp): React.JSX.Element =>
|
|
33
33
|
Section1.create(props, props && (props.children as unknown as ReadonlyArray<SectionElement1.SectionElement>)) as unknown as React.JSX.Element;
|
|
34
34
|
export const Group = (props: Group1.GroupProps & ChildrenProp): React.JSX.Element =>
|
|
35
|
-
Group1.create(props, props
|
|
35
|
+
Group1.create(props, props.children as unknown as ReadonlyArray<SectionElement1.SectionElement>) as unknown as React.JSX.Element;
|
|
36
36
|
export const Paragraph = (props: Paragraph1.ParagraphProps & ChildrenProp): React.JSX.Element =>
|
|
37
|
-
Paragraph1.create(props, props
|
|
37
|
+
Paragraph1.create(props, props.children as unknown as ReadonlyArray<Atom1.Atom>) as unknown as React.JSX.Element;
|
|
38
38
|
export const Table = (props: Table1.TableProps & ChildrenProp): React.JSX.Element =>
|
|
39
|
-
Table1.create(props, props
|
|
39
|
+
Table1.create(props, props.children as unknown as ReadonlyArray<TableRow1.TableRow>) as unknown as React.JSX.Element;
|
|
40
40
|
export const TableRow = (props: TableRow1.TableRowProps & ChildrenProp): React.JSX.Element =>
|
|
41
|
-
TableRow1.create(props, props
|
|
41
|
+
TableRow1.create(props, props.children as unknown as ReadonlyArray<TableCell1.TableCell>) as unknown as React.JSX.Element;
|
|
42
42
|
export const TableCell = (props: TableCell1.TableCellProps & ChildrenProp): React.JSX.Element =>
|
|
43
|
-
TableCell1.create(props, props
|
|
43
|
+
TableCell1.create(props, props.children as unknown as ReadonlyArray<SectionElement1.SectionElement>) as unknown as React.JSX.Element;
|
|
44
44
|
export const HyperLink = (props: HyperLink1.HyperLinkProps): React.JSX.Element => HyperLink1.create(props) as unknown as React.JSX.Element;
|
|
45
45
|
export const LinkTarget = (props: LinkTarget1.LinkTargetProps): React.JSX.Element => LinkTarget1.create(props) as unknown as React.JSX.Element;
|
|
46
46
|
export const Image = (props: Image1.ImageProps): React.JSX.Element => Image1.create(props) as unknown as React.JSX.Element;
|
|
@@ -79,9 +79,9 @@ function renderChildren(element: FakeElement): Array<unknown> {
|
|
|
79
79
|
return [];
|
|
80
80
|
}
|
|
81
81
|
if (Array.isArray(c)) {
|
|
82
|
-
return c.map(render)
|
|
82
|
+
return c.map(render) as Array<unknown>;
|
|
83
83
|
}
|
|
84
|
-
return render(c);
|
|
84
|
+
return render(c) as unknown;
|
|
85
85
|
});
|
|
86
86
|
} else {
|
|
87
87
|
const elements = render(element.props.children); // Markdown returns an array of elements already
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseHandlebarsXml, type XmlElement } from "handlebars-xml";
|
|
2
2
|
import { getFontStyleName } from "../../abstract-document-exporters/pdf/font.js";
|
|
3
|
-
import { addResources, merge } from "../../abstract-document/abstract-doc.js";
|
|
3
|
+
import { addResources, create, merge } from "../../abstract-document/abstract-doc.js";
|
|
4
4
|
import type { AbstractDoc } from "../../abstract-document/index.js";
|
|
5
5
|
import type { Font } from "../../abstract-document/primitives/font.js";
|
|
6
6
|
import type { Resources } from "../../abstract-document/resources.js";
|
|
@@ -49,7 +49,8 @@ export function abstractDocXml(
|
|
|
49
49
|
): readonly [AbstractDoc.AbstractDoc, imageUrls: Record<string, true>, fontFamilies: Record<string, Partial<Record<keyof Font, boolean>>>] {
|
|
50
50
|
const xml = parseHandlebarsXml(template, data, partials);
|
|
51
51
|
const [imageUrls, fontFamilies, styleNames] = extractImageFontsStyleNames(xml);
|
|
52
|
-
const
|
|
52
|
+
const root = xml[0];
|
|
53
|
+
const doc = root === undefined ? create() : abstractDocXmlRecursive(creators(styleNames), root);
|
|
53
54
|
return [doc, imageUrls, fontFamilies];
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -57,31 +58,33 @@ export function abstractDocXml(
|
|
|
57
58
|
function abstractDocXmlRecursive(creators: Record<string, ADCreatorFn>, xmlElement: XmlElement, onlyChildren: boolean = false): any {
|
|
58
59
|
const children = [];
|
|
59
60
|
const props: Record<string, unknown> = {};
|
|
60
|
-
for (const childElement of xmlElement.children
|
|
61
|
+
for (const childElement of xmlElement.children) {
|
|
61
62
|
const childName = childElement.tagName;
|
|
62
|
-
if (childName
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
if (childName === "StyleNames") {
|
|
64
|
+
props["styles"] = abstractDocXmlRecursive(creators, childElement);
|
|
65
|
+
} else if (childName === "StyleName" && childElement.attributes["name"]) {
|
|
66
|
+
const type = childElement.attributes["type"];
|
|
67
|
+
if (type === undefined) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const styleName = StyleKey.create(type, childElement.attributes["name"]);
|
|
71
|
+
const style = abstractDocXmlRecursive(creators, childElement);
|
|
72
|
+
props[styleName] = style;
|
|
73
|
+
} else if (childName.startsWith(childName.charAt(0).toUpperCase())) {
|
|
74
|
+
// For uppercase elements we add them to the children key
|
|
75
|
+
children.push(abstractDocXmlRecursive(creators, childElement));
|
|
76
|
+
} else {
|
|
77
|
+
// For lowercase elements we add them as keys using their name
|
|
78
|
+
// Some special keys should directly have an array of children as value instead of an object with children key
|
|
79
|
+
const arrayedElements = ["header", "footer", "headerRows"];
|
|
80
|
+
const childrenOnly = arrayedElements.findIndex((e) => e === childName) !== -1;
|
|
81
|
+
const differentFirstPage = childElement.attributes["differentFirstPage"];
|
|
82
|
+
if (differentFirstPage === "true" && childName === "header") {
|
|
83
|
+
props["frontHeader"] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
84
|
+
} else if (differentFirstPage === "true" && childName === "footer") {
|
|
85
|
+
props["frontFooter"] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
72
86
|
} else {
|
|
73
|
-
|
|
74
|
-
// Some special keys should directly have an array of children as value instead of an object with children key
|
|
75
|
-
const arrayedElements = ["header", "footer", "headerRows"];
|
|
76
|
-
const childrenOnly = arrayedElements.findIndex((e) => e === childName) !== -1;
|
|
77
|
-
const differentFirstPage = childElement.attributes["differentFirstPage"];
|
|
78
|
-
if (differentFirstPage === "true" && childName === "header") {
|
|
79
|
-
props["frontHeader"] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
80
|
-
} else if (differentFirstPage === "true" && childName === "footer") {
|
|
81
|
-
props["frontFooter"] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
82
|
-
} else {
|
|
83
|
-
props[childName] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
84
|
-
}
|
|
87
|
+
props[childName] = abstractDocXmlRecursive(creators, childElement, childrenOnly);
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
}
|
|
@@ -185,7 +188,7 @@ function extractImageFontsStyleNames(
|
|
|
185
188
|
] {
|
|
186
189
|
let crFntFam = currentFontFamily;
|
|
187
190
|
xmlElement.forEach((item) => {
|
|
188
|
-
if (item.tagName.startsWith("Image") && item.attributes
|
|
191
|
+
if (item.tagName.startsWith("Image") && item.attributes["src"]) {
|
|
189
192
|
images[item.attributes["src"]] = true;
|
|
190
193
|
} else if (item.tagName === "style") {
|
|
191
194
|
const fontFamily = crFntFam ?? styleFamilies["Default"];
|
|
@@ -203,7 +206,7 @@ function extractImageFontsStyleNames(
|
|
|
203
206
|
crFntFam = fontFamily;
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
|
-
} else if (item.attributes
|
|
209
|
+
} else if (item.attributes["fontFamily"]) {
|
|
207
210
|
const styleName = getFontStyleName(item.attributes);
|
|
208
211
|
(fonts[item.attributes["fontFamily"]] ??= {})[styleName] = true;
|
|
209
212
|
if (item.tagName === "StyleName" && item.attributes["name"] && item.attributes["type"]) {
|