js.documents 1.62.0 → 1.64.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/README.md +150 -24
- package/dist/convert/convert.cjs +72 -20
- package/dist/convert/convert.d.cts +6 -2
- package/dist/convert/convert.d.ts +6 -2
- package/dist/convert/convert.js +73 -21
- package/dist/convert/local.cjs +15 -2
- package/dist/convert/local.js +15 -2
- package/dist/convert/port.d.cts +8 -4
- package/dist/convert/port.d.ts +8 -4
- package/dist/edit/docx/content.d.cts +1 -1
- package/dist/edit/docx/content.d.ts +1 -1
- package/dist/edit/docx/paragraph.d.cts +3 -3
- package/dist/edit/docx/paragraph.d.ts +3 -3
- package/dist/edit/ods/address.cjs +42 -24
- package/dist/edit/ods/address.d.cts +12 -2
- package/dist/edit/ods/address.d.ts +12 -2
- package/dist/edit/ods/address.js +39 -25
- package/dist/edit/ods/column-row.cjs +68 -6
- package/dist/edit/ods/column-row.d.cts +5 -1
- package/dist/edit/ods/column-row.d.ts +5 -1
- package/dist/edit/ods/column-row.js +68 -10
- package/dist/edit/ods/content.cjs +10 -2
- package/dist/edit/ods/content.js +10 -2
- package/dist/edit/ods/floating.cjs +90 -0
- package/dist/edit/ods/floating.d.cts +7 -0
- package/dist/edit/ods/floating.d.ts +7 -0
- package/dist/edit/ods/floating.js +88 -0
- package/dist/edit/ods/print-settings.cjs +158 -2
- package/dist/edit/ods/print-settings.js +159 -3
- package/dist/edit/ods/sheet.cjs +13 -0
- package/dist/edit/ods/sheet.d.cts +5 -1
- package/dist/edit/ods/sheet.d.ts +5 -1
- package/dist/edit/ods/sheet.js +14 -1
- package/dist/edit/odt/content.cjs +8 -4
- package/dist/edit/odt/content.js +8 -4
- package/dist/edit/odt/editor.cjs +7 -0
- package/dist/edit/odt/editor.d.cts +3 -0
- package/dist/edit/odt/editor.d.ts +3 -0
- package/dist/edit/odt/editor.js +7 -0
- package/dist/edit/odt/formula.cjs +19 -0
- package/dist/edit/odt/formula.d.cts +8 -0
- package/dist/edit/odt/formula.d.ts +8 -0
- package/dist/edit/odt/formula.js +17 -0
- package/dist/evaluate-BU5N1Jk1.d.ts +11 -0
- package/dist/evaluate-BhMXY6DM.d.cts +11 -0
- package/dist/firebird/backup.d.cts +1 -1
- package/dist/firebird/backup.d.ts +1 -1
- package/dist/firebird/data.cjs +30 -16
- package/dist/firebird/data.d.cts +3 -2
- package/dist/firebird/data.d.ts +3 -2
- package/dist/firebird/data.js +30 -17
- package/dist/fonts/obfuscation.cjs +50 -0
- package/dist/fonts/obfuscation.d.cts +9 -0
- package/dist/fonts/obfuscation.d.ts +9 -0
- package/dist/fonts/obfuscation.js +46 -0
- package/dist/fonts/odf.cjs +86 -0
- package/dist/fonts/odf.d.cts +9 -0
- package/dist/fonts/odf.d.ts +9 -0
- package/dist/fonts/odf.js +84 -0
- package/dist/fonts/ooxml.cjs +129 -0
- package/dist/fonts/ooxml.d.cts +9 -0
- package/dist/fonts/ooxml.d.ts +9 -0
- package/dist/fonts/ooxml.js +127 -0
- package/dist/fonts/registry.cjs +18 -0
- package/dist/fonts/registry.d.cts +2 -0
- package/dist/fonts/registry.d.ts +2 -0
- package/dist/fonts/registry.js +16 -0
- package/dist/formula-CgydMiTt.d.ts +10 -0
- package/dist/formula-CiwPw8nY.d.cts +10 -0
- package/dist/hsqldb/binary-script.d.cts +1 -1
- package/dist/hsqldb/binary-script.d.ts +1 -1
- package/dist/hsqldb/cache.d.cts +1 -1
- package/dist/hsqldb/cache.d.ts +1 -1
- package/dist/hsqldb/rowformat.cjs +22 -13
- package/dist/hsqldb/rowformat.js +22 -13
- package/dist/hsqldb/script.d.cts +1 -18
- package/dist/hsqldb/script.d.ts +1 -18
- package/dist/index.cjs +88 -0
- package/dist/index.d.cts +27 -9
- package/dist/index.d.ts +27 -9
- package/dist/index.js +20 -3
- package/dist/layout/sheets.cjs +30 -24
- package/dist/layout/sheets.js +31 -25
- package/dist/layout/slides.cjs +6 -4
- package/dist/layout/slides.js +7 -5
- package/dist/lexer-DGPWx_f2.d.cts +42 -0
- package/dist/lexer-DGPWx_f2.d.ts +42 -0
- package/dist/mathml/layout.d.cts +1 -1
- package/dist/mathml/layout.d.ts +1 -1
- package/dist/mathml/variant.d.cts +1 -6
- package/dist/mathml/variant.d.ts +1 -6
- package/dist/odb/csv.d.cts +1 -1
- package/dist/odb/csv.d.ts +1 -1
- package/dist/odb/formula/definition.cjs +49 -0
- package/dist/odb/formula/definition.d.cts +8 -0
- package/dist/odb/formula/definition.d.ts +8 -0
- package/dist/odb/formula/definition.js +46 -0
- package/dist/odb/formula/errors.cjs +47 -0
- package/dist/odb/formula/errors.d.cts +21 -0
- package/dist/odb/formula/errors.d.ts +21 -0
- package/dist/odb/formula/errors.js +43 -0
- package/dist/odb/formula/evaluate.cjs +283 -0
- package/dist/odb/formula/evaluate.d.cts +43 -0
- package/dist/odb/formula/evaluate.d.ts +43 -0
- package/dist/odb/formula/evaluate.js +281 -0
- package/dist/odb/formula/parser.cjs +198 -0
- package/dist/odb/formula/parser.d.cts +29 -0
- package/dist/odb/formula/parser.d.ts +29 -0
- package/dist/odb/formula/parser.js +197 -0
- package/dist/odb/read.d.cts +1 -1
- package/dist/odb/read.d.ts +1 -1
- package/dist/odb/report/content.cjs +27 -0
- package/dist/odb/report/content.d.cts +14 -0
- package/dist/odb/report/content.d.ts +14 -0
- package/dist/odb/report/content.js +25 -0
- package/dist/odb/report/render.cjs +106 -0
- package/dist/odb/report/render.d.cts +7 -0
- package/dist/odb/report/render.d.ts +7 -0
- package/dist/odb/report/render.js +106 -0
- package/dist/odb/report/source.cjs +45 -0
- package/dist/odb/report/source.d.cts +14 -0
- package/dist/odb/report/source.d.ts +14 -0
- package/dist/odb/report/source.js +42 -0
- package/dist/odb/spreadsheet.d.cts +1 -1
- package/dist/odb/spreadsheet.d.ts +1 -1
- package/dist/odb/sql/errors.cjs +38 -0
- package/dist/odb/sql/errors.d.cts +17 -0
- package/dist/odb/sql/errors.d.ts +17 -0
- package/dist/odb/sql/errors.js +35 -0
- package/dist/odb/sql/evaluate.cjs +312 -0
- package/dist/odb/sql/evaluate.d.cts +2 -0
- package/dist/odb/sql/evaluate.d.ts +2 -0
- package/dist/odb/sql/evaluate.js +311 -0
- package/dist/odb/sql/lexer.cjs +282 -0
- package/dist/odb/sql/lexer.d.cts +2 -0
- package/dist/odb/sql/lexer.d.ts +2 -0
- package/dist/odb/sql/lexer.js +281 -0
- package/dist/odb/sql/parser.cjs +479 -0
- package/dist/odb/sql/parser.d.cts +2 -0
- package/dist/odb/sql/parser.d.ts +2 -0
- package/dist/odb/sql/parser.js +478 -0
- package/dist/odb/values.cjs +75 -0
- package/dist/odb/values.d.cts +2 -0
- package/dist/odb/values.d.ts +2 -0
- package/dist/odb/values.js +69 -0
- package/dist/odf/odt/read.cjs +43 -21
- package/dist/odf/odt/read.js +43 -21
- package/dist/odf-package/formula.cjs +59 -0
- package/dist/odf-package/formula.d.cts +11 -0
- package/dist/odf-package/formula.d.ts +11 -0
- package/dist/odf-package/formula.js +58 -0
- package/dist/odf-package/manifest.cjs +29 -0
- package/dist/odf-package/manifest.d.cts +5 -2
- package/dist/odf-package/manifest.d.ts +5 -2
- package/dist/odf-package/manifest.js +30 -2
- package/dist/odf-package/media.cjs +2 -1
- package/dist/odf-package/media.js +2 -2
- package/dist/omml/read.cjs +265 -0
- package/dist/omml/read.d.cts +12 -0
- package/dist/omml/read.d.ts +12 -0
- package/dist/omml/read.js +263 -0
- package/dist/omml/shared.cjs +67 -0
- package/dist/omml/shared.d.cts +2 -0
- package/dist/omml/shared.d.ts +2 -0
- package/dist/omml/shared.js +64 -0
- package/dist/omml/write.cjs +3 -51
- package/dist/omml/write.d.cts +2 -2
- package/dist/omml/write.d.ts +2 -2
- package/dist/omml/write.js +1 -49
- package/dist/ooxml/docx/extras.cjs +15 -0
- package/dist/ooxml/docx/extras.d.cts +12 -0
- package/dist/ooxml/docx/extras.d.ts +12 -0
- package/dist/ooxml/docx/extras.js +14 -0
- package/dist/ooxml/docx/formula.cjs +109 -0
- package/dist/ooxml/docx/formula.d.cts +2 -0
- package/dist/ooxml/docx/formula.d.ts +2 -0
- package/dist/ooxml/docx/formula.js +108 -0
- package/dist/ooxml/docx/read.cjs +10 -2
- package/dist/ooxml/docx/read.d.cts +6 -2
- package/dist/ooxml/docx/read.d.ts +6 -2
- package/dist/ooxml/docx/read.js +11 -3
- package/dist/parser-B9vC1T6T.d.cts +101 -0
- package/dist/parser-DQSgYJzQ.d.ts +101 -0
- package/dist/registry-CrSqLIcn.d.ts +19 -0
- package/dist/registry-lqJej0Jr.d.cts +19 -0
- package/dist/script-DsGGIzGU.d.cts +19 -0
- package/dist/script-DsGGIzGU.d.ts +19 -0
- package/dist/shared-DLZ3IQUl.d.cts +15 -0
- package/dist/shared-DUOzjwcL.d.ts +15 -0
- package/dist/values-BetetbaH.d.cts +23 -0
- package/dist/values-BetetbaH.d.ts +23 -0
- package/dist/variant-BMrebjMw.d.cts +7 -0
- package/dist/variant-BMrebjMw.d.ts +7 -0
- package/dist/{write-DuyfnbL_.d.cts → write-BQ6SK8r8.d.cts} +2 -6
- package/dist/{write-Zqwx6pka.d.ts → write-THs7ipBq.d.ts} +2 -6
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as MathMlNode } from "../../nodes-pArN9ilm.cjs";
|
|
2
|
-
import {
|
|
1
|
+
import { r as MathMlNode$1 } from "../../nodes-pArN9ilm.cjs";
|
|
2
|
+
import { t as OmmlWriteResult } from "../../write-BQ6SK8r8.cjs";
|
|
3
3
|
import { n as MediaContext, t as ImageInit } from "../../image-BfRLAD9B.cjs";
|
|
4
4
|
import { n as RunInit, t as DocxRun } from "../../run-B3GNScJH.cjs";
|
|
5
5
|
import { ContentListMembership } from "document-schema.js";
|
|
@@ -34,7 +34,7 @@ declare class DocxParagraph {
|
|
|
34
34
|
set alignment(value: 'left' | 'center' | 'right' | 'justify' | undefined);
|
|
35
35
|
get list(): ContentListMembership | undefined;
|
|
36
36
|
set list(value: ContentListMembership | undefined);
|
|
37
|
-
appendOfficeMath(mathml: readonly MathMlNode[]): OmmlWriteResult & {
|
|
37
|
+
appendOfficeMath(mathml: readonly MathMlNode$1[]): OmmlWriteResult & {
|
|
38
38
|
readonly written: boolean;
|
|
39
39
|
};
|
|
40
40
|
insertImageAfter(image: ImageInit): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as MathMlNode } from "../../nodes-pArN9ilm.js";
|
|
2
|
-
import {
|
|
1
|
+
import { r as MathMlNode$1 } from "../../nodes-pArN9ilm.js";
|
|
2
|
+
import { t as OmmlWriteResult } from "../../write-THs7ipBq.js";
|
|
3
3
|
import { n as MediaContext, t as ImageInit } from "../../image-BfRLAD9B.js";
|
|
4
4
|
import { n as RunInit, t as DocxRun } from "../../run-D2rTWHbt.js";
|
|
5
5
|
import { Package, XmlElement, XmlNode } from "ooxml.js";
|
|
@@ -34,7 +34,7 @@ declare class DocxParagraph {
|
|
|
34
34
|
set alignment(value: 'left' | 'center' | 'right' | 'justify' | undefined);
|
|
35
35
|
get list(): ContentListMembership | undefined;
|
|
36
36
|
set list(value: ContentListMembership | undefined);
|
|
37
|
-
appendOfficeMath(mathml: readonly MathMlNode[]): OmmlWriteResult & {
|
|
37
|
+
appendOfficeMath(mathml: readonly MathMlNode$1[]): OmmlWriteResult & {
|
|
38
38
|
readonly written: boolean;
|
|
39
39
|
};
|
|
40
40
|
insertImageAfter(image: ImageInit): void;
|
|
@@ -7,6 +7,8 @@ const CELL_TAG = "table:table-cell";
|
|
|
7
7
|
const COVERED_CELL_TAG = "table:covered-table-cell";
|
|
8
8
|
const ROW_REPEAT_ATTR = "table:number-rows-repeated";
|
|
9
9
|
const COLUMN_REPEAT_ATTR = "table:number-columns-repeated";
|
|
10
|
+
const HEADER_ROWS_TAG = "table:table-header-rows";
|
|
11
|
+
const HEADER_COLUMNS_TAG = "table:table-header-columns";
|
|
10
12
|
function isElementWithTag(tag) {
|
|
11
13
|
return (node) => node.type === "element" && node.tag === tag;
|
|
12
14
|
}
|
|
@@ -16,12 +18,36 @@ function isCellOrCoveredCell(node) {
|
|
|
16
18
|
function validateIndex(value, label) {
|
|
17
19
|
if (!Number.isInteger(value) || value < 0) throw new Error(`${label} must be a non-negative integer, got ${value}`);
|
|
18
20
|
}
|
|
19
|
-
function
|
|
21
|
+
function readRunRepeatCount(node, attrName) {
|
|
20
22
|
const raw = node.attributes.find((attribute) => attribute.name === attrName)?.value;
|
|
21
23
|
if (raw === void 0) return 1;
|
|
22
24
|
const parsed = Number.parseInt(raw, 10);
|
|
23
25
|
return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
|
|
24
26
|
}
|
|
27
|
+
function collectRunMembers(children, isMember, headerWrapperTag) {
|
|
28
|
+
const members = [];
|
|
29
|
+
children.forEach((node, outerPosition) => {
|
|
30
|
+
if (node.type !== "element") return;
|
|
31
|
+
if (headerWrapperTag !== void 0 && node.tag === headerWrapperTag) {
|
|
32
|
+
node.children.forEach((inner, innerPosition) => {
|
|
33
|
+
if (isMember(inner)) members.push({
|
|
34
|
+
node: inner,
|
|
35
|
+
container: node.children,
|
|
36
|
+
containerPosition: innerPosition,
|
|
37
|
+
outerPosition
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (isMember(node)) members.push({
|
|
43
|
+
node,
|
|
44
|
+
container: children,
|
|
45
|
+
containerPosition: outerPosition,
|
|
46
|
+
outerPosition
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return members;
|
|
50
|
+
}
|
|
25
51
|
function withRepeatCount(node, attrName, count) {
|
|
26
52
|
const clone = structuredClone(node);
|
|
27
53
|
clone.attributes = clone.attributes.filter((attribute) => attribute.name !== attrName);
|
|
@@ -31,18 +57,12 @@ function withRepeatCount(node, attrName, count) {
|
|
|
31
57
|
});
|
|
32
58
|
return clone;
|
|
33
59
|
}
|
|
34
|
-
function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty) {
|
|
60
|
+
function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty, headerWrapperTag) {
|
|
35
61
|
validateIndex(targetIndex, "targetIndex");
|
|
36
|
-
const members =
|
|
37
|
-
children.forEach((node, position) => {
|
|
38
|
-
if (isMember(node)) members.push({
|
|
39
|
-
node,
|
|
40
|
-
position
|
|
41
|
-
});
|
|
42
|
-
});
|
|
62
|
+
const members = collectRunMembers(children, isMember, headerWrapperTag);
|
|
43
63
|
let cursor = 0;
|
|
44
64
|
for (const member of members) {
|
|
45
|
-
const count =
|
|
65
|
+
const count = readRunRepeatCount(member.node, repeatAttr);
|
|
46
66
|
if (targetIndex < cursor + count) {
|
|
47
67
|
const offset = targetIndex - cursor;
|
|
48
68
|
if (count === 1) return member.node;
|
|
@@ -53,14 +73,14 @@ function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty) {
|
|
|
53
73
|
target,
|
|
54
74
|
count - offset - 1 > 0 ? withRepeatCount(member.node, repeatAttr, count - offset - 1) : void 0
|
|
55
75
|
].filter((candidate) => candidate !== void 0);
|
|
56
|
-
|
|
76
|
+
member.container.splice(member.containerPosition, 1, ...replacement);
|
|
57
77
|
return target;
|
|
58
78
|
}
|
|
59
79
|
cursor += count;
|
|
60
80
|
}
|
|
61
81
|
const gap = targetIndex - cursor;
|
|
62
82
|
const lastMember = members[members.length - 1];
|
|
63
|
-
const insertAt = lastMember === void 0 ? children.length : lastMember.
|
|
83
|
+
const insertAt = lastMember === void 0 ? children.length : lastMember.outerPosition + 1;
|
|
64
84
|
const toInsert = [];
|
|
65
85
|
if (gap > 0) toInsert.push(withRepeatCount(buildEmpty(), repeatAttr, gap));
|
|
66
86
|
const target = buildEmpty();
|
|
@@ -70,39 +90,37 @@ function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty) {
|
|
|
70
90
|
}
|
|
71
91
|
function ensureColumnCoverage(tableElement, minCount) {
|
|
72
92
|
if (minCount <= 0) return;
|
|
73
|
-
const columnMembers =
|
|
74
|
-
|
|
75
|
-
if (isElementWithTag("table:table-column")(node)) columnMembers.push({
|
|
76
|
-
node,
|
|
77
|
-
position
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
const covered = columnMembers.reduce((sum, member) => sum + readRepeatCount(member.node, COLUMN_REPEAT_ATTR), 0);
|
|
93
|
+
const columnMembers = collectRunMembers(tableElement.children, isElementWithTag(COLUMN_TAG), HEADER_COLUMNS_TAG);
|
|
94
|
+
const covered = columnMembers.reduce((sum, member) => sum + readRunRepeatCount(member.node, COLUMN_REPEAT_ATTR), 0);
|
|
81
95
|
if (covered >= minCount) return;
|
|
82
96
|
const additional = minCount - covered;
|
|
83
97
|
const newColumn = withRepeatCount(require_xml_fragment.el(COLUMN_TAG), COLUMN_REPEAT_ATTR, additional);
|
|
84
98
|
const lastColumn = columnMembers[columnMembers.length - 1];
|
|
85
99
|
if (lastColumn === void 0) {
|
|
86
|
-
const
|
|
87
|
-
const insertAt =
|
|
100
|
+
const firstRowOrHeaderPosition = tableElement.children.findIndex((node) => isElementWithTag("table:table-row")(node) || isElementWithTag("table:table-header-rows")(node));
|
|
101
|
+
const insertAt = firstRowOrHeaderPosition === -1 ? tableElement.children.length : firstRowOrHeaderPosition;
|
|
88
102
|
tableElement.children.splice(insertAt, 0, newColumn);
|
|
89
|
-
} else tableElement.children.splice(lastColumn.
|
|
103
|
+
} else tableElement.children.splice(lastColumn.outerPosition + 1, 0, newColumn);
|
|
90
104
|
}
|
|
91
105
|
function resolveCellNode(tableElement, row, column) {
|
|
92
106
|
validateIndex(row, "row");
|
|
93
107
|
validateIndex(column, "column");
|
|
94
108
|
ensureColumnCoverage(tableElement, column + 1);
|
|
95
|
-
return replaceRun(replaceRun(tableElement.children, isElementWithTag(ROW_TAG), row, ROW_REPEAT_ATTR, () => require_xml_fragment.el(ROW_TAG)).children, isCellOrCoveredCell, column, COLUMN_REPEAT_ATTR, () => require_xml_fragment.el(CELL_TAG));
|
|
109
|
+
return replaceRun(replaceRun(tableElement.children, isElementWithTag(ROW_TAG), row, ROW_REPEAT_ATTR, () => require_xml_fragment.el(ROW_TAG), HEADER_ROWS_TAG).children, isCellOrCoveredCell, column, COLUMN_REPEAT_ATTR, () => require_xml_fragment.el(CELL_TAG));
|
|
96
110
|
}
|
|
97
111
|
//#endregion
|
|
98
112
|
exports.CELL_TAG = CELL_TAG;
|
|
99
113
|
exports.COLUMN_REPEAT_ATTR = COLUMN_REPEAT_ATTR;
|
|
100
114
|
exports.COLUMN_TAG = COLUMN_TAG;
|
|
101
115
|
exports.COVERED_CELL_TAG = COVERED_CELL_TAG;
|
|
116
|
+
exports.HEADER_COLUMNS_TAG = HEADER_COLUMNS_TAG;
|
|
117
|
+
exports.HEADER_ROWS_TAG = HEADER_ROWS_TAG;
|
|
102
118
|
exports.ROW_REPEAT_ATTR = ROW_REPEAT_ATTR;
|
|
103
119
|
exports.ROW_TAG = ROW_TAG;
|
|
120
|
+
exports.collectRunMembers = collectRunMembers;
|
|
104
121
|
exports.ensureColumnCoverage = ensureColumnCoverage;
|
|
105
122
|
exports.isCellOrCoveredCell = isCellOrCoveredCell;
|
|
106
123
|
exports.isElementWithTag = isElementWithTag;
|
|
124
|
+
exports.readRunRepeatCount = readRunRepeatCount;
|
|
107
125
|
exports.replaceRun = replaceRun;
|
|
108
126
|
exports.resolveCellNode = resolveCellNode;
|
|
@@ -6,10 +6,20 @@ declare const CELL_TAG = "table:table-cell";
|
|
|
6
6
|
declare const COVERED_CELL_TAG = "table:covered-table-cell";
|
|
7
7
|
declare const ROW_REPEAT_ATTR = "table:number-rows-repeated";
|
|
8
8
|
declare const COLUMN_REPEAT_ATTR = "table:number-columns-repeated";
|
|
9
|
+
declare const HEADER_ROWS_TAG = "table:table-header-rows";
|
|
10
|
+
declare const HEADER_COLUMNS_TAG = "table:table-header-columns";
|
|
9
11
|
declare function isElementWithTag(tag: string): (node: XmlNode) => node is XmlElement;
|
|
10
12
|
declare function isCellOrCoveredCell(node: XmlNode): node is XmlElement;
|
|
11
|
-
declare function
|
|
13
|
+
declare function readRunRepeatCount(node: XmlElement, attrName: string): number;
|
|
14
|
+
interface RunMember {
|
|
15
|
+
readonly node: XmlElement;
|
|
16
|
+
readonly container: XmlNode[];
|
|
17
|
+
readonly containerPosition: number;
|
|
18
|
+
readonly outerPosition: number;
|
|
19
|
+
}
|
|
20
|
+
declare function collectRunMembers(children: XmlNode[], isMember: (node: XmlNode) => node is XmlElement, headerWrapperTag: string | undefined): RunMember[];
|
|
21
|
+
declare function replaceRun(children: XmlNode[], isMember: (node: XmlNode) => node is XmlElement, targetIndex: number, repeatAttr: string, buildEmpty: () => XmlElement, headerWrapperTag?: string): XmlElement;
|
|
12
22
|
declare function ensureColumnCoverage(tableElement: XmlElement, minCount: number): void;
|
|
13
23
|
declare function resolveCellNode(tableElement: XmlElement, row: number, column: number): XmlElement;
|
|
14
24
|
//#endregion
|
|
15
|
-
export { CELL_TAG, COLUMN_REPEAT_ATTR, COLUMN_TAG, COVERED_CELL_TAG, ROW_REPEAT_ATTR, ROW_TAG, ensureColumnCoverage, isCellOrCoveredCell, isElementWithTag, replaceRun, resolveCellNode };
|
|
25
|
+
export { CELL_TAG, COLUMN_REPEAT_ATTR, COLUMN_TAG, COVERED_CELL_TAG, HEADER_COLUMNS_TAG, HEADER_ROWS_TAG, ROW_REPEAT_ATTR, ROW_TAG, RunMember, collectRunMembers, ensureColumnCoverage, isCellOrCoveredCell, isElementWithTag, readRunRepeatCount, replaceRun, resolveCellNode };
|
|
@@ -6,10 +6,20 @@ declare const CELL_TAG = "table:table-cell";
|
|
|
6
6
|
declare const COVERED_CELL_TAG = "table:covered-table-cell";
|
|
7
7
|
declare const ROW_REPEAT_ATTR = "table:number-rows-repeated";
|
|
8
8
|
declare const COLUMN_REPEAT_ATTR = "table:number-columns-repeated";
|
|
9
|
+
declare const HEADER_ROWS_TAG = "table:table-header-rows";
|
|
10
|
+
declare const HEADER_COLUMNS_TAG = "table:table-header-columns";
|
|
9
11
|
declare function isElementWithTag(tag: string): (node: XmlNode) => node is XmlElement;
|
|
10
12
|
declare function isCellOrCoveredCell(node: XmlNode): node is XmlElement;
|
|
11
|
-
declare function
|
|
13
|
+
declare function readRunRepeatCount(node: XmlElement, attrName: string): number;
|
|
14
|
+
interface RunMember {
|
|
15
|
+
readonly node: XmlElement;
|
|
16
|
+
readonly container: XmlNode[];
|
|
17
|
+
readonly containerPosition: number;
|
|
18
|
+
readonly outerPosition: number;
|
|
19
|
+
}
|
|
20
|
+
declare function collectRunMembers(children: XmlNode[], isMember: (node: XmlNode) => node is XmlElement, headerWrapperTag: string | undefined): RunMember[];
|
|
21
|
+
declare function replaceRun(children: XmlNode[], isMember: (node: XmlNode) => node is XmlElement, targetIndex: number, repeatAttr: string, buildEmpty: () => XmlElement, headerWrapperTag?: string): XmlElement;
|
|
12
22
|
declare function ensureColumnCoverage(tableElement: XmlElement, minCount: number): void;
|
|
13
23
|
declare function resolveCellNode(tableElement: XmlElement, row: number, column: number): XmlElement;
|
|
14
24
|
//#endregion
|
|
15
|
-
export { CELL_TAG, COLUMN_REPEAT_ATTR, COLUMN_TAG, COVERED_CELL_TAG, ROW_REPEAT_ATTR, ROW_TAG, ensureColumnCoverage, isCellOrCoveredCell, isElementWithTag, replaceRun, resolveCellNode };
|
|
25
|
+
export { CELL_TAG, COLUMN_REPEAT_ATTR, COLUMN_TAG, COVERED_CELL_TAG, HEADER_COLUMNS_TAG, HEADER_ROWS_TAG, ROW_REPEAT_ATTR, ROW_TAG, RunMember, collectRunMembers, ensureColumnCoverage, isCellOrCoveredCell, isElementWithTag, readRunRepeatCount, replaceRun, resolveCellNode };
|
package/dist/edit/ods/address.js
CHANGED
|
@@ -6,6 +6,8 @@ const CELL_TAG = "table:table-cell";
|
|
|
6
6
|
const COVERED_CELL_TAG = "table:covered-table-cell";
|
|
7
7
|
const ROW_REPEAT_ATTR = "table:number-rows-repeated";
|
|
8
8
|
const COLUMN_REPEAT_ATTR = "table:number-columns-repeated";
|
|
9
|
+
const HEADER_ROWS_TAG = "table:table-header-rows";
|
|
10
|
+
const HEADER_COLUMNS_TAG = "table:table-header-columns";
|
|
9
11
|
function isElementWithTag(tag) {
|
|
10
12
|
return (node) => node.type === "element" && node.tag === tag;
|
|
11
13
|
}
|
|
@@ -15,12 +17,36 @@ function isCellOrCoveredCell(node) {
|
|
|
15
17
|
function validateIndex(value, label) {
|
|
16
18
|
if (!Number.isInteger(value) || value < 0) throw new Error(`${label} must be a non-negative integer, got ${value}`);
|
|
17
19
|
}
|
|
18
|
-
function
|
|
20
|
+
function readRunRepeatCount(node, attrName) {
|
|
19
21
|
const raw = node.attributes.find((attribute) => attribute.name === attrName)?.value;
|
|
20
22
|
if (raw === void 0) return 1;
|
|
21
23
|
const parsed = Number.parseInt(raw, 10);
|
|
22
24
|
return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
|
|
23
25
|
}
|
|
26
|
+
function collectRunMembers(children, isMember, headerWrapperTag) {
|
|
27
|
+
const members = [];
|
|
28
|
+
children.forEach((node, outerPosition) => {
|
|
29
|
+
if (node.type !== "element") return;
|
|
30
|
+
if (headerWrapperTag !== void 0 && node.tag === headerWrapperTag) {
|
|
31
|
+
node.children.forEach((inner, innerPosition) => {
|
|
32
|
+
if (isMember(inner)) members.push({
|
|
33
|
+
node: inner,
|
|
34
|
+
container: node.children,
|
|
35
|
+
containerPosition: innerPosition,
|
|
36
|
+
outerPosition
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (isMember(node)) members.push({
|
|
42
|
+
node,
|
|
43
|
+
container: children,
|
|
44
|
+
containerPosition: outerPosition,
|
|
45
|
+
outerPosition
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return members;
|
|
49
|
+
}
|
|
24
50
|
function withRepeatCount(node, attrName, count) {
|
|
25
51
|
const clone = structuredClone(node);
|
|
26
52
|
clone.attributes = clone.attributes.filter((attribute) => attribute.name !== attrName);
|
|
@@ -30,18 +56,12 @@ function withRepeatCount(node, attrName, count) {
|
|
|
30
56
|
});
|
|
31
57
|
return clone;
|
|
32
58
|
}
|
|
33
|
-
function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty) {
|
|
59
|
+
function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty, headerWrapperTag) {
|
|
34
60
|
validateIndex(targetIndex, "targetIndex");
|
|
35
|
-
const members =
|
|
36
|
-
children.forEach((node, position) => {
|
|
37
|
-
if (isMember(node)) members.push({
|
|
38
|
-
node,
|
|
39
|
-
position
|
|
40
|
-
});
|
|
41
|
-
});
|
|
61
|
+
const members = collectRunMembers(children, isMember, headerWrapperTag);
|
|
42
62
|
let cursor = 0;
|
|
43
63
|
for (const member of members) {
|
|
44
|
-
const count =
|
|
64
|
+
const count = readRunRepeatCount(member.node, repeatAttr);
|
|
45
65
|
if (targetIndex < cursor + count) {
|
|
46
66
|
const offset = targetIndex - cursor;
|
|
47
67
|
if (count === 1) return member.node;
|
|
@@ -52,14 +72,14 @@ function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty) {
|
|
|
52
72
|
target,
|
|
53
73
|
count - offset - 1 > 0 ? withRepeatCount(member.node, repeatAttr, count - offset - 1) : void 0
|
|
54
74
|
].filter((candidate) => candidate !== void 0);
|
|
55
|
-
|
|
75
|
+
member.container.splice(member.containerPosition, 1, ...replacement);
|
|
56
76
|
return target;
|
|
57
77
|
}
|
|
58
78
|
cursor += count;
|
|
59
79
|
}
|
|
60
80
|
const gap = targetIndex - cursor;
|
|
61
81
|
const lastMember = members[members.length - 1];
|
|
62
|
-
const insertAt = lastMember === void 0 ? children.length : lastMember.
|
|
82
|
+
const insertAt = lastMember === void 0 ? children.length : lastMember.outerPosition + 1;
|
|
63
83
|
const toInsert = [];
|
|
64
84
|
if (gap > 0) toInsert.push(withRepeatCount(buildEmpty(), repeatAttr, gap));
|
|
65
85
|
const target = buildEmpty();
|
|
@@ -69,29 +89,23 @@ function replaceRun(children, isMember, targetIndex, repeatAttr, buildEmpty) {
|
|
|
69
89
|
}
|
|
70
90
|
function ensureColumnCoverage(tableElement, minCount) {
|
|
71
91
|
if (minCount <= 0) return;
|
|
72
|
-
const columnMembers =
|
|
73
|
-
|
|
74
|
-
if (isElementWithTag("table:table-column")(node)) columnMembers.push({
|
|
75
|
-
node,
|
|
76
|
-
position
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
const covered = columnMembers.reduce((sum, member) => sum + readRepeatCount(member.node, COLUMN_REPEAT_ATTR), 0);
|
|
92
|
+
const columnMembers = collectRunMembers(tableElement.children, isElementWithTag(COLUMN_TAG), HEADER_COLUMNS_TAG);
|
|
93
|
+
const covered = columnMembers.reduce((sum, member) => sum + readRunRepeatCount(member.node, COLUMN_REPEAT_ATTR), 0);
|
|
80
94
|
if (covered >= minCount) return;
|
|
81
95
|
const additional = minCount - covered;
|
|
82
96
|
const newColumn = withRepeatCount(el(COLUMN_TAG), COLUMN_REPEAT_ATTR, additional);
|
|
83
97
|
const lastColumn = columnMembers[columnMembers.length - 1];
|
|
84
98
|
if (lastColumn === void 0) {
|
|
85
|
-
const
|
|
86
|
-
const insertAt =
|
|
99
|
+
const firstRowOrHeaderPosition = tableElement.children.findIndex((node) => isElementWithTag("table:table-row")(node) || isElementWithTag("table:table-header-rows")(node));
|
|
100
|
+
const insertAt = firstRowOrHeaderPosition === -1 ? tableElement.children.length : firstRowOrHeaderPosition;
|
|
87
101
|
tableElement.children.splice(insertAt, 0, newColumn);
|
|
88
|
-
} else tableElement.children.splice(lastColumn.
|
|
102
|
+
} else tableElement.children.splice(lastColumn.outerPosition + 1, 0, newColumn);
|
|
89
103
|
}
|
|
90
104
|
function resolveCellNode(tableElement, row, column) {
|
|
91
105
|
validateIndex(row, "row");
|
|
92
106
|
validateIndex(column, "column");
|
|
93
107
|
ensureColumnCoverage(tableElement, column + 1);
|
|
94
|
-
return replaceRun(replaceRun(tableElement.children, isElementWithTag(ROW_TAG), row, ROW_REPEAT_ATTR, () => el(ROW_TAG)).children, isCellOrCoveredCell, column, COLUMN_REPEAT_ATTR, () => el(CELL_TAG));
|
|
108
|
+
return replaceRun(replaceRun(tableElement.children, isElementWithTag(ROW_TAG), row, ROW_REPEAT_ATTR, () => el(ROW_TAG), HEADER_ROWS_TAG).children, isCellOrCoveredCell, column, COLUMN_REPEAT_ATTR, () => el(CELL_TAG));
|
|
95
109
|
}
|
|
96
110
|
//#endregion
|
|
97
|
-
export { CELL_TAG, COLUMN_REPEAT_ATTR, COLUMN_TAG, COVERED_CELL_TAG, ROW_REPEAT_ATTR, ROW_TAG, ensureColumnCoverage, isCellOrCoveredCell, isElementWithTag, replaceRun, resolveCellNode };
|
|
111
|
+
export { CELL_TAG, COLUMN_REPEAT_ATTR, COLUMN_TAG, COVERED_CELL_TAG, HEADER_COLUMNS_TAG, HEADER_ROWS_TAG, ROW_REPEAT_ATTR, ROW_TAG, collectRunMembers, ensureColumnCoverage, isCellOrCoveredCell, isElementWithTag, readRunRepeatCount, replaceRun, resolveCellNode };
|
|
@@ -3,29 +3,91 @@ const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
|
3
3
|
const require_xml_edit = require("../../xml/edit.cjs");
|
|
4
4
|
const require_edit_odt_automatic_styles = require("../odt/automatic-styles.cjs");
|
|
5
5
|
const require_edit_ods_address = require("./address.cjs");
|
|
6
|
+
let ooxml_js = require("ooxml.js");
|
|
6
7
|
let odf_js = require("odf.js");
|
|
7
8
|
//#region src/edit/ods/column-row.ts
|
|
8
|
-
|
|
9
|
+
const VISIBILITY_ATTR = "table:visibility";
|
|
10
|
+
const VISIBILITY_COLLAPSE = "collapse";
|
|
11
|
+
function currentColumnStyleProperties(pkg, columnElement) {
|
|
12
|
+
const styleName = (0, ooxml_js.attr)(columnElement, "table:style-name");
|
|
13
|
+
const styleElement = styleName === void 0 ? void 0 : (0, odf_js.findStyleElement)(styleName, "table-column", pkg);
|
|
14
|
+
const properties = styleElement === void 0 ? void 0 : require_xml_edit.directChildElement(styleElement, "style:table-column-properties");
|
|
15
|
+
const widthValue = properties === void 0 ? void 0 : (0, ooxml_js.attr)(properties, "style:column-width");
|
|
16
|
+
return {
|
|
17
|
+
widthPt: widthValue === void 0 ? void 0 : (0, odf_js.parseOdfLength)(widthValue),
|
|
18
|
+
manualBreak: (properties === void 0 ? void 0 : (0, ooxml_js.attr)(properties, "fo:break-before")) === "page"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function currentRowStyleProperties(pkg, rowElement) {
|
|
22
|
+
const styleName = (0, ooxml_js.attr)(rowElement, "table:style-name");
|
|
23
|
+
const styleElement = styleName === void 0 ? void 0 : (0, odf_js.findStyleElement)(styleName, "table-row", pkg);
|
|
24
|
+
const properties = styleElement === void 0 ? void 0 : require_xml_edit.directChildElement(styleElement, "style:table-row-properties");
|
|
25
|
+
const heightValue = properties === void 0 ? void 0 : (0, ooxml_js.attr)(properties, "style:row-height");
|
|
26
|
+
return {
|
|
27
|
+
heightPt: heightValue === void 0 ? void 0 : (0, odf_js.parseOdfLength)(heightValue),
|
|
28
|
+
manualBreak: (properties === void 0 ? void 0 : (0, ooxml_js.attr)(properties, "fo:break-before")) === "page"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function applyColumnStyleProperties(pkg, tableElement, index, changes) {
|
|
9
32
|
require_edit_ods_address.ensureColumnCoverage(tableElement, index + 1);
|
|
10
|
-
const columnElement = require_edit_ods_address.replaceRun(tableElement.children, require_edit_ods_address.isElementWithTag(require_edit_ods_address.COLUMN_TAG), index, require_edit_ods_address.COLUMN_REPEAT_ATTR, () => require_xml_fragment.el(require_edit_ods_address.COLUMN_TAG));
|
|
33
|
+
const columnElement = require_edit_ods_address.replaceRun(tableElement.children, require_edit_ods_address.isElementWithTag(require_edit_ods_address.COLUMN_TAG), index, require_edit_ods_address.COLUMN_REPEAT_ATTR, () => require_xml_fragment.el(require_edit_ods_address.COLUMN_TAG), require_edit_ods_address.HEADER_COLUMNS_TAG);
|
|
34
|
+
const current = currentColumnStyleProperties(pkg, columnElement);
|
|
35
|
+
const widthPt = changes.widthPt ?? current.widthPt;
|
|
36
|
+
const manualBreak = changes.manualBreak ?? current.manualBreak;
|
|
11
37
|
const automaticStyles = require_edit_odt_automatic_styles.ensureAutomaticStyles(pkg);
|
|
12
38
|
const styleName = require_edit_odt_automatic_styles.nextStyleName(automaticStyles, "style:style", "OdsColumn");
|
|
13
39
|
automaticStyles.children.push(require_xml_fragment.el("style:style", {
|
|
14
40
|
"style:name": styleName,
|
|
15
41
|
"style:family": "table-column"
|
|
16
|
-
}, [require_xml_fragment.el("style:table-column-properties", {
|
|
42
|
+
}, [require_xml_fragment.el("style:table-column-properties", {
|
|
43
|
+
...widthPt !== void 0 ? { "style:column-width": (0, odf_js.formatOdfLength)(widthPt) } : {},
|
|
44
|
+
...manualBreak ? { "fo:break-before": "page" } : {}
|
|
45
|
+
})]));
|
|
17
46
|
require_xml_edit.setAttr(columnElement, "table:style-name", styleName);
|
|
18
47
|
}
|
|
19
|
-
function
|
|
20
|
-
const rowElement = require_edit_ods_address.replaceRun(tableElement.children, require_edit_ods_address.isElementWithTag(require_edit_ods_address.ROW_TAG), index, require_edit_ods_address.ROW_REPEAT_ATTR, () => require_xml_fragment.el(require_edit_ods_address.ROW_TAG));
|
|
48
|
+
function applyRowStyleProperties(pkg, tableElement, index, changes) {
|
|
49
|
+
const rowElement = require_edit_ods_address.replaceRun(tableElement.children, require_edit_ods_address.isElementWithTag(require_edit_ods_address.ROW_TAG), index, require_edit_ods_address.ROW_REPEAT_ATTR, () => require_xml_fragment.el(require_edit_ods_address.ROW_TAG), require_edit_ods_address.HEADER_ROWS_TAG);
|
|
50
|
+
const current = currentRowStyleProperties(pkg, rowElement);
|
|
51
|
+
const heightPt = changes.heightPt ?? current.heightPt;
|
|
52
|
+
const manualBreak = changes.manualBreak ?? current.manualBreak;
|
|
21
53
|
const automaticStyles = require_edit_odt_automatic_styles.ensureAutomaticStyles(pkg);
|
|
22
54
|
const styleName = require_edit_odt_automatic_styles.nextStyleName(automaticStyles, "style:style", "OdsRow");
|
|
23
55
|
automaticStyles.children.push(require_xml_fragment.el("style:style", {
|
|
24
56
|
"style:name": styleName,
|
|
25
57
|
"style:family": "table-row"
|
|
26
|
-
}, [require_xml_fragment.el("style:table-row-properties", {
|
|
58
|
+
}, [require_xml_fragment.el("style:table-row-properties", {
|
|
59
|
+
...heightPt !== void 0 ? { "style:row-height": (0, odf_js.formatOdfLength)(heightPt) } : {},
|
|
60
|
+
...manualBreak ? { "fo:break-before": "page" } : {}
|
|
61
|
+
})]));
|
|
27
62
|
require_xml_edit.setAttr(rowElement, "table:style-name", styleName);
|
|
28
63
|
}
|
|
64
|
+
function writeColumnWidth(pkg, tableElement, index, widthPt) {
|
|
65
|
+
applyColumnStyleProperties(pkg, tableElement, index, { widthPt });
|
|
66
|
+
}
|
|
67
|
+
function writeRowHeight(pkg, tableElement, index, heightPt) {
|
|
68
|
+
applyRowStyleProperties(pkg, tableElement, index, { heightPt });
|
|
69
|
+
}
|
|
70
|
+
function writeColumnManualBreak(pkg, tableElement, index) {
|
|
71
|
+
applyColumnStyleProperties(pkg, tableElement, index, { manualBreak: true });
|
|
72
|
+
}
|
|
73
|
+
function writeRowManualBreak(pkg, tableElement, index) {
|
|
74
|
+
applyRowStyleProperties(pkg, tableElement, index, { manualBreak: true });
|
|
75
|
+
}
|
|
76
|
+
function writeColumnHidden(tableElement, index, hidden) {
|
|
77
|
+
require_edit_ods_address.ensureColumnCoverage(tableElement, index + 1);
|
|
78
|
+
const columnElement = require_edit_ods_address.replaceRun(tableElement.children, require_edit_ods_address.isElementWithTag(require_edit_ods_address.COLUMN_TAG), index, require_edit_ods_address.COLUMN_REPEAT_ATTR, () => require_xml_fragment.el(require_edit_ods_address.COLUMN_TAG), require_edit_ods_address.HEADER_COLUMNS_TAG);
|
|
79
|
+
if (hidden) require_xml_edit.setAttr(columnElement, VISIBILITY_ATTR, VISIBILITY_COLLAPSE);
|
|
80
|
+
else require_xml_edit.removeAttr(columnElement, VISIBILITY_ATTR);
|
|
81
|
+
}
|
|
82
|
+
function writeRowHidden(tableElement, index, hidden) {
|
|
83
|
+
const rowElement = require_edit_ods_address.replaceRun(tableElement.children, require_edit_ods_address.isElementWithTag(require_edit_ods_address.ROW_TAG), index, require_edit_ods_address.ROW_REPEAT_ATTR, () => require_xml_fragment.el(require_edit_ods_address.ROW_TAG), require_edit_ods_address.HEADER_ROWS_TAG);
|
|
84
|
+
if (hidden) require_xml_edit.setAttr(rowElement, VISIBILITY_ATTR, VISIBILITY_COLLAPSE);
|
|
85
|
+
else require_xml_edit.removeAttr(rowElement, VISIBILITY_ATTR);
|
|
86
|
+
}
|
|
29
87
|
//#endregion
|
|
88
|
+
exports.writeColumnHidden = writeColumnHidden;
|
|
89
|
+
exports.writeColumnManualBreak = writeColumnManualBreak;
|
|
30
90
|
exports.writeColumnWidth = writeColumnWidth;
|
|
31
91
|
exports.writeRowHeight = writeRowHeight;
|
|
92
|
+
exports.writeRowHidden = writeRowHidden;
|
|
93
|
+
exports.writeRowManualBreak = writeRowManualBreak;
|
|
@@ -2,5 +2,9 @@ import { Package, XmlElement } from "odf.js";
|
|
|
2
2
|
//#region src/edit/ods/column-row.d.ts
|
|
3
3
|
declare function writeColumnWidth(pkg: Package, tableElement: XmlElement, index: number, widthPt: number): void;
|
|
4
4
|
declare function writeRowHeight(pkg: Package, tableElement: XmlElement, index: number, heightPt: number): void;
|
|
5
|
+
declare function writeColumnManualBreak(pkg: Package, tableElement: XmlElement, index: number): void;
|
|
6
|
+
declare function writeRowManualBreak(pkg: Package, tableElement: XmlElement, index: number): void;
|
|
7
|
+
declare function writeColumnHidden(tableElement: XmlElement, index: number, hidden: boolean): void;
|
|
8
|
+
declare function writeRowHidden(tableElement: XmlElement, index: number, hidden: boolean): void;
|
|
5
9
|
//#endregion
|
|
6
|
-
export { writeColumnWidth, writeRowHeight };
|
|
10
|
+
export { writeColumnHidden, writeColumnManualBreak, writeColumnWidth, writeRowHeight, writeRowHidden, writeRowManualBreak };
|
|
@@ -2,5 +2,9 @@ import { Package, XmlElement } from "odf.js";
|
|
|
2
2
|
//#region src/edit/ods/column-row.d.ts
|
|
3
3
|
declare function writeColumnWidth(pkg: Package, tableElement: XmlElement, index: number, widthPt: number): void;
|
|
4
4
|
declare function writeRowHeight(pkg: Package, tableElement: XmlElement, index: number, heightPt: number): void;
|
|
5
|
+
declare function writeColumnManualBreak(pkg: Package, tableElement: XmlElement, index: number): void;
|
|
6
|
+
declare function writeRowManualBreak(pkg: Package, tableElement: XmlElement, index: number): void;
|
|
7
|
+
declare function writeColumnHidden(tableElement: XmlElement, index: number, hidden: boolean): void;
|
|
8
|
+
declare function writeRowHidden(tableElement: XmlElement, index: number, hidden: boolean): void;
|
|
5
9
|
//#endregion
|
|
6
|
-
export { writeColumnWidth, writeRowHeight };
|
|
10
|
+
export { writeColumnHidden, writeColumnManualBreak, writeColumnWidth, writeRowHeight, writeRowHidden, writeRowManualBreak };
|
|
@@ -1,29 +1,87 @@
|
|
|
1
1
|
import { el } from "../../xml/fragment.js";
|
|
2
|
-
import { setAttr } from "../../xml/edit.js";
|
|
2
|
+
import { directChildElement, removeAttr, setAttr } from "../../xml/edit.js";
|
|
3
3
|
import { ensureAutomaticStyles, nextStyleName } from "../odt/automatic-styles.js";
|
|
4
|
-
import { COLUMN_REPEAT_ATTR, COLUMN_TAG, ROW_REPEAT_ATTR, ROW_TAG, ensureColumnCoverage, isElementWithTag, replaceRun } from "./address.js";
|
|
5
|
-
import {
|
|
4
|
+
import { COLUMN_REPEAT_ATTR, COLUMN_TAG, HEADER_COLUMNS_TAG, HEADER_ROWS_TAG, ROW_REPEAT_ATTR, ROW_TAG, ensureColumnCoverage, isElementWithTag, replaceRun } from "./address.js";
|
|
5
|
+
import { attr } from "ooxml.js";
|
|
6
|
+
import { findStyleElement, formatOdfLength, parseOdfLength } from "odf.js";
|
|
6
7
|
//#region src/edit/ods/column-row.ts
|
|
7
|
-
|
|
8
|
+
const VISIBILITY_ATTR = "table:visibility";
|
|
9
|
+
const VISIBILITY_COLLAPSE = "collapse";
|
|
10
|
+
function currentColumnStyleProperties(pkg, columnElement) {
|
|
11
|
+
const styleName = attr(columnElement, "table:style-name");
|
|
12
|
+
const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-column", pkg);
|
|
13
|
+
const properties = styleElement === void 0 ? void 0 : directChildElement(styleElement, "style:table-column-properties");
|
|
14
|
+
const widthValue = properties === void 0 ? void 0 : attr(properties, "style:column-width");
|
|
15
|
+
return {
|
|
16
|
+
widthPt: widthValue === void 0 ? void 0 : parseOdfLength(widthValue),
|
|
17
|
+
manualBreak: (properties === void 0 ? void 0 : attr(properties, "fo:break-before")) === "page"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function currentRowStyleProperties(pkg, rowElement) {
|
|
21
|
+
const styleName = attr(rowElement, "table:style-name");
|
|
22
|
+
const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-row", pkg);
|
|
23
|
+
const properties = styleElement === void 0 ? void 0 : directChildElement(styleElement, "style:table-row-properties");
|
|
24
|
+
const heightValue = properties === void 0 ? void 0 : attr(properties, "style:row-height");
|
|
25
|
+
return {
|
|
26
|
+
heightPt: heightValue === void 0 ? void 0 : parseOdfLength(heightValue),
|
|
27
|
+
manualBreak: (properties === void 0 ? void 0 : attr(properties, "fo:break-before")) === "page"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function applyColumnStyleProperties(pkg, tableElement, index, changes) {
|
|
8
31
|
ensureColumnCoverage(tableElement, index + 1);
|
|
9
|
-
const columnElement = replaceRun(tableElement.children, isElementWithTag(COLUMN_TAG), index, COLUMN_REPEAT_ATTR, () => el(COLUMN_TAG));
|
|
32
|
+
const columnElement = replaceRun(tableElement.children, isElementWithTag(COLUMN_TAG), index, COLUMN_REPEAT_ATTR, () => el(COLUMN_TAG), HEADER_COLUMNS_TAG);
|
|
33
|
+
const current = currentColumnStyleProperties(pkg, columnElement);
|
|
34
|
+
const widthPt = changes.widthPt ?? current.widthPt;
|
|
35
|
+
const manualBreak = changes.manualBreak ?? current.manualBreak;
|
|
10
36
|
const automaticStyles = ensureAutomaticStyles(pkg);
|
|
11
37
|
const styleName = nextStyleName(automaticStyles, "style:style", "OdsColumn");
|
|
12
38
|
automaticStyles.children.push(el("style:style", {
|
|
13
39
|
"style:name": styleName,
|
|
14
40
|
"style:family": "table-column"
|
|
15
|
-
}, [el("style:table-column-properties", {
|
|
41
|
+
}, [el("style:table-column-properties", {
|
|
42
|
+
...widthPt !== void 0 ? { "style:column-width": formatOdfLength(widthPt) } : {},
|
|
43
|
+
...manualBreak ? { "fo:break-before": "page" } : {}
|
|
44
|
+
})]));
|
|
16
45
|
setAttr(columnElement, "table:style-name", styleName);
|
|
17
46
|
}
|
|
18
|
-
function
|
|
19
|
-
const rowElement = replaceRun(tableElement.children, isElementWithTag(ROW_TAG), index, ROW_REPEAT_ATTR, () => el(ROW_TAG));
|
|
47
|
+
function applyRowStyleProperties(pkg, tableElement, index, changes) {
|
|
48
|
+
const rowElement = replaceRun(tableElement.children, isElementWithTag(ROW_TAG), index, ROW_REPEAT_ATTR, () => el(ROW_TAG), HEADER_ROWS_TAG);
|
|
49
|
+
const current = currentRowStyleProperties(pkg, rowElement);
|
|
50
|
+
const heightPt = changes.heightPt ?? current.heightPt;
|
|
51
|
+
const manualBreak = changes.manualBreak ?? current.manualBreak;
|
|
20
52
|
const automaticStyles = ensureAutomaticStyles(pkg);
|
|
21
53
|
const styleName = nextStyleName(automaticStyles, "style:style", "OdsRow");
|
|
22
54
|
automaticStyles.children.push(el("style:style", {
|
|
23
55
|
"style:name": styleName,
|
|
24
56
|
"style:family": "table-row"
|
|
25
|
-
}, [el("style:table-row-properties", {
|
|
57
|
+
}, [el("style:table-row-properties", {
|
|
58
|
+
...heightPt !== void 0 ? { "style:row-height": formatOdfLength(heightPt) } : {},
|
|
59
|
+
...manualBreak ? { "fo:break-before": "page" } : {}
|
|
60
|
+
})]));
|
|
26
61
|
setAttr(rowElement, "table:style-name", styleName);
|
|
27
62
|
}
|
|
63
|
+
function writeColumnWidth(pkg, tableElement, index, widthPt) {
|
|
64
|
+
applyColumnStyleProperties(pkg, tableElement, index, { widthPt });
|
|
65
|
+
}
|
|
66
|
+
function writeRowHeight(pkg, tableElement, index, heightPt) {
|
|
67
|
+
applyRowStyleProperties(pkg, tableElement, index, { heightPt });
|
|
68
|
+
}
|
|
69
|
+
function writeColumnManualBreak(pkg, tableElement, index) {
|
|
70
|
+
applyColumnStyleProperties(pkg, tableElement, index, { manualBreak: true });
|
|
71
|
+
}
|
|
72
|
+
function writeRowManualBreak(pkg, tableElement, index) {
|
|
73
|
+
applyRowStyleProperties(pkg, tableElement, index, { manualBreak: true });
|
|
74
|
+
}
|
|
75
|
+
function writeColumnHidden(tableElement, index, hidden) {
|
|
76
|
+
ensureColumnCoverage(tableElement, index + 1);
|
|
77
|
+
const columnElement = replaceRun(tableElement.children, isElementWithTag(COLUMN_TAG), index, COLUMN_REPEAT_ATTR, () => el(COLUMN_TAG), HEADER_COLUMNS_TAG);
|
|
78
|
+
if (hidden) setAttr(columnElement, VISIBILITY_ATTR, VISIBILITY_COLLAPSE);
|
|
79
|
+
else removeAttr(columnElement, VISIBILITY_ATTR);
|
|
80
|
+
}
|
|
81
|
+
function writeRowHidden(tableElement, index, hidden) {
|
|
82
|
+
const rowElement = replaceRun(tableElement.children, isElementWithTag(ROW_TAG), index, ROW_REPEAT_ATTR, () => el(ROW_TAG), HEADER_ROWS_TAG);
|
|
83
|
+
if (hidden) setAttr(rowElement, VISIBILITY_ATTR, VISIBILITY_COLLAPSE);
|
|
84
|
+
else removeAttr(rowElement, VISIBILITY_ATTR);
|
|
85
|
+
}
|
|
28
86
|
//#endregion
|
|
29
|
-
export { writeColumnWidth, writeRowHeight };
|
|
87
|
+
export { writeColumnHidden, writeColumnManualBreak, writeColumnWidth, writeRowHeight, writeRowHidden, writeRowManualBreak };
|
|
@@ -9,8 +9,16 @@ function buildOdsPackage(content) {
|
|
|
9
9
|
const odsSheet = editor.addSheet(sheet.name);
|
|
10
10
|
odsSheet.printSettings = sheet.printSettings;
|
|
11
11
|
for (const cell of sheet.cells) appendCell(odsSheet, cell);
|
|
12
|
-
for (const column of sheet.columns)
|
|
13
|
-
|
|
12
|
+
for (const column of sheet.columns) {
|
|
13
|
+
if (column.widthPt !== void 0) odsSheet.setColumnWidth(column.index, column.widthPt);
|
|
14
|
+
if (column.hidden === true) odsSheet.setColumnHidden(column.index, true);
|
|
15
|
+
}
|
|
16
|
+
for (const row of sheet.rows) {
|
|
17
|
+
if (row.heightPt !== void 0) odsSheet.setRowHeight(row.index, row.heightPt);
|
|
18
|
+
if (row.hidden === true) odsSheet.setRowHidden(row.index, true);
|
|
19
|
+
}
|
|
20
|
+
for (const image of sheet.images) odsSheet.addImage(image);
|
|
21
|
+
for (const embeddedObject of sheet.embeddedObjects ?? []) odsSheet.addEmbeddedObject(embeddedObject);
|
|
14
22
|
}
|
|
15
23
|
return editor.toPackage();
|
|
16
24
|
}
|
package/dist/edit/ods/content.js
CHANGED
|
@@ -8,8 +8,16 @@ function buildOdsPackage(content) {
|
|
|
8
8
|
const odsSheet = editor.addSheet(sheet.name);
|
|
9
9
|
odsSheet.printSettings = sheet.printSettings;
|
|
10
10
|
for (const cell of sheet.cells) appendCell(odsSheet, cell);
|
|
11
|
-
for (const column of sheet.columns)
|
|
12
|
-
|
|
11
|
+
for (const column of sheet.columns) {
|
|
12
|
+
if (column.widthPt !== void 0) odsSheet.setColumnWidth(column.index, column.widthPt);
|
|
13
|
+
if (column.hidden === true) odsSheet.setColumnHidden(column.index, true);
|
|
14
|
+
}
|
|
15
|
+
for (const row of sheet.rows) {
|
|
16
|
+
if (row.heightPt !== void 0) odsSheet.setRowHeight(row.index, row.heightPt);
|
|
17
|
+
if (row.hidden === true) odsSheet.setRowHidden(row.index, true);
|
|
18
|
+
}
|
|
19
|
+
for (const image of sheet.images) odsSheet.addImage(image);
|
|
20
|
+
for (const embeddedObject of sheet.embeddedObjects ?? []) odsSheet.addEmbeddedObject(embeddedObject);
|
|
13
21
|
}
|
|
14
22
|
return editor.toPackage();
|
|
15
23
|
}
|