ooxml.js 2.7.0 → 2.8.0
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/dist/typed/docx/read.cjs +29 -18
- package/dist/typed/docx/read.js +29 -18
- package/package.json +1 -1
package/dist/typed/docx/read.cjs
CHANGED
|
@@ -266,10 +266,18 @@ function readRawCell(tc, context, rels, pkg) {
|
|
|
266
266
|
blocks: readBodyBlocks(tc.children, context, rels, pkg)
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
|
+
function readRowHeightPt(tr) {
|
|
270
|
+
const trPr = require_typed_util.childrenWithTag(tr, "w:trPr")[0];
|
|
271
|
+
if (trPr === void 0) return;
|
|
272
|
+
const trHeight = require_typed_util.childrenWithTag(trPr, "w:trHeight")[0];
|
|
273
|
+
const val = trHeight === void 0 ? void 0 : require_typed_util.attr(trHeight, "w:val");
|
|
274
|
+
return val === void 0 ? void 0 : require_typed_shared_units.twipsToPt(Number(val));
|
|
275
|
+
}
|
|
269
276
|
function readTable(tbl, context, rels, pkg) {
|
|
270
277
|
const tblGrid = require_typed_util.childrenWithTag(tbl, "w:tblGrid")[0];
|
|
271
278
|
const columnWidthsPt = tblGrid === void 0 ? [] : require_typed_util.childrenWithTag(tblGrid, "w:gridCol").map((col) => require_typed_shared_units.twipsToPt(Number(require_typed_util.attr(col, "w:w") ?? "0")));
|
|
272
|
-
const
|
|
279
|
+
const trs = require_typed_util.childrenWithTag(tbl, "w:tr");
|
|
280
|
+
const rawRows = trs.map((tr) => require_typed_util.childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels, pkg)));
|
|
273
281
|
const rowColumnIndices = rawRows.map((row) => {
|
|
274
282
|
const indices = [];
|
|
275
283
|
let col = 0;
|
|
@@ -282,23 +290,26 @@ function readTable(tbl, context, rels, pkg) {
|
|
|
282
290
|
return {
|
|
283
291
|
kind: "table",
|
|
284
292
|
columnWidthsPt,
|
|
285
|
-
rows: rawRows.map((row, rowIndex) => ({
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
293
|
+
rows: rawRows.map((row, rowIndex) => ({
|
|
294
|
+
heightPt: readRowHeightPt(trs[rowIndex]),
|
|
295
|
+
cells: row.map((cell, cellIndex) => {
|
|
296
|
+
if (cell.isVMergeContinuation) return { blocks: [] };
|
|
297
|
+
const colIndex = rowColumnIndices[rowIndex][cellIndex];
|
|
298
|
+
let rowSpan = 1;
|
|
299
|
+
for (let r = rowIndex + 1; r < rawRows.length; r++) {
|
|
300
|
+
const matchIndex = rowColumnIndices[r].indexOf(colIndex);
|
|
301
|
+
if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
|
|
302
|
+
rowSpan++;
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
blocks: cell.blocks,
|
|
306
|
+
colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
|
|
307
|
+
rowSpan: rowSpan > 1 ? rowSpan : void 0,
|
|
308
|
+
background: cell.background,
|
|
309
|
+
borders: cell.borders
|
|
310
|
+
};
|
|
311
|
+
})
|
|
312
|
+
}))
|
|
302
313
|
};
|
|
303
314
|
}
|
|
304
315
|
function readBodyBlocks(nodes, context, rels, pkg) {
|
package/dist/typed/docx/read.js
CHANGED
|
@@ -265,10 +265,18 @@ function readRawCell(tc, context, rels, pkg) {
|
|
|
265
265
|
blocks: readBodyBlocks(tc.children, context, rels, pkg)
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
|
+
function readRowHeightPt(tr) {
|
|
269
|
+
const trPr = childrenWithTag(tr, "w:trPr")[0];
|
|
270
|
+
if (trPr === void 0) return;
|
|
271
|
+
const trHeight = childrenWithTag(trPr, "w:trHeight")[0];
|
|
272
|
+
const val = trHeight === void 0 ? void 0 : attr(trHeight, "w:val");
|
|
273
|
+
return val === void 0 ? void 0 : twipsToPt(Number(val));
|
|
274
|
+
}
|
|
268
275
|
function readTable(tbl, context, rels, pkg) {
|
|
269
276
|
const tblGrid = childrenWithTag(tbl, "w:tblGrid")[0];
|
|
270
277
|
const columnWidthsPt = tblGrid === void 0 ? [] : childrenWithTag(tblGrid, "w:gridCol").map((col) => twipsToPt(Number(attr(col, "w:w") ?? "0")));
|
|
271
|
-
const
|
|
278
|
+
const trs = childrenWithTag(tbl, "w:tr");
|
|
279
|
+
const rawRows = trs.map((tr) => childrenWithTag(tr, "w:tc").map((tc) => readRawCell(tc, context, rels, pkg)));
|
|
272
280
|
const rowColumnIndices = rawRows.map((row) => {
|
|
273
281
|
const indices = [];
|
|
274
282
|
let col = 0;
|
|
@@ -281,23 +289,26 @@ function readTable(tbl, context, rels, pkg) {
|
|
|
281
289
|
return {
|
|
282
290
|
kind: "table",
|
|
283
291
|
columnWidthsPt,
|
|
284
|
-
rows: rawRows.map((row, rowIndex) => ({
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
292
|
+
rows: rawRows.map((row, rowIndex) => ({
|
|
293
|
+
heightPt: readRowHeightPt(trs[rowIndex]),
|
|
294
|
+
cells: row.map((cell, cellIndex) => {
|
|
295
|
+
if (cell.isVMergeContinuation) return { blocks: [] };
|
|
296
|
+
const colIndex = rowColumnIndices[rowIndex][cellIndex];
|
|
297
|
+
let rowSpan = 1;
|
|
298
|
+
for (let r = rowIndex + 1; r < rawRows.length; r++) {
|
|
299
|
+
const matchIndex = rowColumnIndices[r].indexOf(colIndex);
|
|
300
|
+
if (!(matchIndex === -1 ? void 0 : rawRows[r][matchIndex])?.isVMergeContinuation) break;
|
|
301
|
+
rowSpan++;
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
blocks: cell.blocks,
|
|
305
|
+
colSpan: cell.gridSpan > 1 ? cell.gridSpan : void 0,
|
|
306
|
+
rowSpan: rowSpan > 1 ? rowSpan : void 0,
|
|
307
|
+
background: cell.background,
|
|
308
|
+
borders: cell.borders
|
|
309
|
+
};
|
|
310
|
+
})
|
|
311
|
+
}))
|
|
301
312
|
};
|
|
302
313
|
}
|
|
303
314
|
function readBodyBlocks(nodes, context, rels, pkg) {
|
package/package.json
CHANGED