documents.js 1.63.0 → 1.65.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 +124 -25
- package/dist/convert/convert.cjs +3 -3
- package/dist/convert/convert.d.cts +5 -2
- package/dist/convert/convert.d.ts +4 -1
- package/dist/convert/convert.js +3 -3
- 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/ooxml.d.cts +1 -1
- package/dist/fonts/registry.d.cts +1 -1
- 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 +56 -0
- package/dist/index.d.cts +24 -10
- package/dist/index.d.ts +23 -9
- package/dist/index.js +15 -2
- 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/compose.cjs +8 -0
- package/dist/mathml/compose.js +8 -0
- package/dist/mathml/layout-types.d.cts +14 -2
- package/dist/mathml/layout-types.d.ts +14 -2
- package/dist/mathml/layout.cjs +62 -3
- package/dist/mathml/layout.d.cts +1 -1
- package/dist/mathml/layout.d.ts +1 -1
- package/dist/mathml/layout.js +62 -3
- package/dist/mathml/metrics.d.cts +17 -1
- package/dist/mathml/metrics.d.ts +17 -1
- package/dist/mathml/operators.cjs +1 -1
- package/dist/mathml/operators.js +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-CtPhMD0f.d.cts → registry-lqJej0Jr.d.cts} +1 -1
- 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 +2 -2
|
@@ -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
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
3
|
+
const require_xml_edit = require("../../xml/edit.cjs");
|
|
4
|
+
const require_odf_package_formula = require("../../odf-package/formula.cjs");
|
|
5
|
+
const require_odf_package_media = require("../../odf-package/media.cjs");
|
|
6
|
+
const require_edit_ods_address = require("./address.cjs");
|
|
7
|
+
let ooxml_js = require("ooxml.js");
|
|
8
|
+
let odf_js = require("odf.js");
|
|
9
|
+
//#region src/edit/ods/floating.ts
|
|
10
|
+
const SHAPES_TAG = "table:shapes";
|
|
11
|
+
const DEFAULT_COLUMN_WIDTH_PT = 64;
|
|
12
|
+
const DEFAULT_ROW_HEIGHT_PT = 15;
|
|
13
|
+
function ensureTableShapes(tableElement) {
|
|
14
|
+
const existing = tableElement.children.find((child) => child.type === "element" && child.tag === SHAPES_TAG);
|
|
15
|
+
if (existing !== void 0) return existing;
|
|
16
|
+
const shapes = require_xml_fragment.el(SHAPES_TAG);
|
|
17
|
+
tableElement.children.unshift(shapes);
|
|
18
|
+
return shapes;
|
|
19
|
+
}
|
|
20
|
+
function isHiddenElement(node) {
|
|
21
|
+
return (0, ooxml_js.attr)(node, "table:visibility") === "collapse";
|
|
22
|
+
}
|
|
23
|
+
function resolvedColumnWidthPt(pkg, columnElement) {
|
|
24
|
+
if (isHiddenElement(columnElement)) return 0;
|
|
25
|
+
const styleName = (0, ooxml_js.attr)(columnElement, "table:style-name");
|
|
26
|
+
const styleElement = styleName === void 0 ? void 0 : (0, odf_js.findStyleElement)(styleName, "table-column", pkg);
|
|
27
|
+
const properties = styleElement === void 0 ? void 0 : require_xml_edit.directChildElement(styleElement, "style:table-column-properties");
|
|
28
|
+
const widthValue = properties === void 0 ? void 0 : (0, ooxml_js.attr)(properties, "style:column-width");
|
|
29
|
+
return widthValue === void 0 ? 0 : (0, odf_js.parseOdfLength)(widthValue) ?? 0;
|
|
30
|
+
}
|
|
31
|
+
function resolvedRowHeightPt(pkg, rowElement) {
|
|
32
|
+
if (isHiddenElement(rowElement)) return 0;
|
|
33
|
+
const styleName = (0, ooxml_js.attr)(rowElement, "table:style-name");
|
|
34
|
+
const styleElement = styleName === void 0 ? void 0 : (0, odf_js.findStyleElement)(styleName, "table-row", pkg);
|
|
35
|
+
const properties = styleElement === void 0 ? void 0 : require_xml_edit.directChildElement(styleElement, "style:table-row-properties");
|
|
36
|
+
const heightValue = properties === void 0 ? void 0 : (0, ooxml_js.attr)(properties, "style:row-height");
|
|
37
|
+
return heightValue === void 0 ? 0 : (0, odf_js.parseOdfLength)(heightValue) ?? 0;
|
|
38
|
+
}
|
|
39
|
+
function cumulativeColumnOffsetPt(pkg, tableElement, anchorColumn) {
|
|
40
|
+
let cursor = 0;
|
|
41
|
+
let offsetPt = 0;
|
|
42
|
+
for (const member of require_edit_ods_address.collectRunMembers(tableElement.children, require_edit_ods_address.isElementWithTag(require_edit_ods_address.COLUMN_TAG), require_edit_ods_address.HEADER_COLUMNS_TAG)) {
|
|
43
|
+
if (cursor >= anchorColumn) break;
|
|
44
|
+
const count = require_edit_ods_address.readRunRepeatCount(member.node, require_edit_ods_address.COLUMN_REPEAT_ATTR);
|
|
45
|
+
const overlap = Math.min(count, anchorColumn - cursor);
|
|
46
|
+
offsetPt += overlap * resolvedColumnWidthPt(pkg, member.node);
|
|
47
|
+
cursor += count;
|
|
48
|
+
}
|
|
49
|
+
if (cursor < anchorColumn) offsetPt += (anchorColumn - cursor) * DEFAULT_COLUMN_WIDTH_PT;
|
|
50
|
+
return offsetPt;
|
|
51
|
+
}
|
|
52
|
+
function cumulativeRowOffsetPt(pkg, tableElement, anchorRow) {
|
|
53
|
+
let cursor = 0;
|
|
54
|
+
let offsetPt = 0;
|
|
55
|
+
for (const member of require_edit_ods_address.collectRunMembers(tableElement.children, require_edit_ods_address.isElementWithTag(require_edit_ods_address.ROW_TAG), require_edit_ods_address.HEADER_ROWS_TAG)) {
|
|
56
|
+
if (cursor >= anchorRow) break;
|
|
57
|
+
const count = require_edit_ods_address.readRunRepeatCount(member.node, require_edit_ods_address.ROW_REPEAT_ATTR);
|
|
58
|
+
const overlap = Math.min(count, anchorRow - cursor);
|
|
59
|
+
offsetPt += overlap * resolvedRowHeightPt(pkg, member.node);
|
|
60
|
+
cursor += count;
|
|
61
|
+
}
|
|
62
|
+
if (cursor < anchorRow) offsetPt += (anchorRow - cursor) * DEFAULT_ROW_HEIGHT_PT;
|
|
63
|
+
return offsetPt;
|
|
64
|
+
}
|
|
65
|
+
function buildAbsoluteFrame(xPt, yPt, widthPt, heightPt, content) {
|
|
66
|
+
return require_xml_fragment.el("draw:frame", {
|
|
67
|
+
"svg:x": (0, odf_js.formatOdfLength)(xPt),
|
|
68
|
+
"svg:y": (0, odf_js.formatOdfLength)(yPt),
|
|
69
|
+
"svg:width": (0, odf_js.formatOdfLength)(widthPt),
|
|
70
|
+
"svg:height": (0, odf_js.formatOdfLength)(heightPt)
|
|
71
|
+
}, [content]);
|
|
72
|
+
}
|
|
73
|
+
function insertSheetImage(pkg, tableElement, image) {
|
|
74
|
+
const { partPath } = require_odf_package_media.addImageMedia(pkg, (0, odf_js.base64ToBytes)(image.base64), image.format);
|
|
75
|
+
const xPt = cumulativeColumnOffsetPt(pkg, tableElement, image.anchorColumn) + image.offsetXPt;
|
|
76
|
+
const yPt = cumulativeRowOffsetPt(pkg, tableElement, image.anchorRow) + image.offsetYPt;
|
|
77
|
+
const imageElement = require_xml_fragment.el("draw:image", { "xlink:href": partPath });
|
|
78
|
+
const frame = buildAbsoluteFrame(xPt, yPt, image.widthPt, image.heightPt, imageElement);
|
|
79
|
+
ensureTableShapes(tableElement).children.push(frame);
|
|
80
|
+
}
|
|
81
|
+
function insertSheetEmbeddedObject(pkg, tableElement, object) {
|
|
82
|
+
if (object.document.kind !== "formula") return;
|
|
83
|
+
const { href } = require_odf_package_formula.addFormulaObject(pkg, object.document.formula);
|
|
84
|
+
const objectElement = require_xml_fragment.el("draw:object", { "xlink:href": href });
|
|
85
|
+
const frame = buildAbsoluteFrame(object.frame.xPt, object.frame.yPt, object.frame.widthPt, object.frame.heightPt, objectElement);
|
|
86
|
+
ensureTableShapes(tableElement).children.push(frame);
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.insertSheetEmbeddedObject = insertSheetEmbeddedObject;
|
|
90
|
+
exports.insertSheetImage = insertSheetImage;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContentEmbeddedObject, ContentSheetImage } from "document-schema.js";
|
|
2
|
+
import { Package, XmlElement } from "odf.js";
|
|
3
|
+
//#region src/edit/ods/floating.d.ts
|
|
4
|
+
declare function insertSheetImage(pkg: Package, tableElement: XmlElement, image: ContentSheetImage): void;
|
|
5
|
+
declare function insertSheetEmbeddedObject(pkg: Package, tableElement: XmlElement, object: ContentEmbeddedObject): void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { insertSheetEmbeddedObject, insertSheetImage };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContentEmbeddedObject, ContentSheetImage } from "document-schema.js";
|
|
2
|
+
import { Package, XmlElement } from "odf.js";
|
|
3
|
+
//#region src/edit/ods/floating.d.ts
|
|
4
|
+
declare function insertSheetImage(pkg: Package, tableElement: XmlElement, image: ContentSheetImage): void;
|
|
5
|
+
declare function insertSheetEmbeddedObject(pkg: Package, tableElement: XmlElement, object: ContentEmbeddedObject): void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { insertSheetEmbeddedObject, insertSheetImage };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { el } from "../../xml/fragment.js";
|
|
2
|
+
import { directChildElement } from "../../xml/edit.js";
|
|
3
|
+
import { addFormulaObject } from "../../odf-package/formula.js";
|
|
4
|
+
import { addImageMedia } from "../../odf-package/media.js";
|
|
5
|
+
import { COLUMN_REPEAT_ATTR, COLUMN_TAG, HEADER_COLUMNS_TAG, HEADER_ROWS_TAG, ROW_REPEAT_ATTR, ROW_TAG, collectRunMembers, isElementWithTag, readRunRepeatCount } from "./address.js";
|
|
6
|
+
import { attr } from "ooxml.js";
|
|
7
|
+
import { base64ToBytes as base64ToBytes$1, findStyleElement, formatOdfLength, parseOdfLength } from "odf.js";
|
|
8
|
+
//#region src/edit/ods/floating.ts
|
|
9
|
+
const SHAPES_TAG = "table:shapes";
|
|
10
|
+
const DEFAULT_COLUMN_WIDTH_PT = 64;
|
|
11
|
+
const DEFAULT_ROW_HEIGHT_PT = 15;
|
|
12
|
+
function ensureTableShapes(tableElement) {
|
|
13
|
+
const existing = tableElement.children.find((child) => child.type === "element" && child.tag === SHAPES_TAG);
|
|
14
|
+
if (existing !== void 0) return existing;
|
|
15
|
+
const shapes = el(SHAPES_TAG);
|
|
16
|
+
tableElement.children.unshift(shapes);
|
|
17
|
+
return shapes;
|
|
18
|
+
}
|
|
19
|
+
function isHiddenElement(node) {
|
|
20
|
+
return attr(node, "table:visibility") === "collapse";
|
|
21
|
+
}
|
|
22
|
+
function resolvedColumnWidthPt(pkg, columnElement) {
|
|
23
|
+
if (isHiddenElement(columnElement)) return 0;
|
|
24
|
+
const styleName = attr(columnElement, "table:style-name");
|
|
25
|
+
const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-column", pkg);
|
|
26
|
+
const properties = styleElement === void 0 ? void 0 : directChildElement(styleElement, "style:table-column-properties");
|
|
27
|
+
const widthValue = properties === void 0 ? void 0 : attr(properties, "style:column-width");
|
|
28
|
+
return widthValue === void 0 ? 0 : parseOdfLength(widthValue) ?? 0;
|
|
29
|
+
}
|
|
30
|
+
function resolvedRowHeightPt(pkg, rowElement) {
|
|
31
|
+
if (isHiddenElement(rowElement)) return 0;
|
|
32
|
+
const styleName = attr(rowElement, "table:style-name");
|
|
33
|
+
const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-row", pkg);
|
|
34
|
+
const properties = styleElement === void 0 ? void 0 : directChildElement(styleElement, "style:table-row-properties");
|
|
35
|
+
const heightValue = properties === void 0 ? void 0 : attr(properties, "style:row-height");
|
|
36
|
+
return heightValue === void 0 ? 0 : parseOdfLength(heightValue) ?? 0;
|
|
37
|
+
}
|
|
38
|
+
function cumulativeColumnOffsetPt(pkg, tableElement, anchorColumn) {
|
|
39
|
+
let cursor = 0;
|
|
40
|
+
let offsetPt = 0;
|
|
41
|
+
for (const member of collectRunMembers(tableElement.children, isElementWithTag(COLUMN_TAG), HEADER_COLUMNS_TAG)) {
|
|
42
|
+
if (cursor >= anchorColumn) break;
|
|
43
|
+
const count = readRunRepeatCount(member.node, COLUMN_REPEAT_ATTR);
|
|
44
|
+
const overlap = Math.min(count, anchorColumn - cursor);
|
|
45
|
+
offsetPt += overlap * resolvedColumnWidthPt(pkg, member.node);
|
|
46
|
+
cursor += count;
|
|
47
|
+
}
|
|
48
|
+
if (cursor < anchorColumn) offsetPt += (anchorColumn - cursor) * DEFAULT_COLUMN_WIDTH_PT;
|
|
49
|
+
return offsetPt;
|
|
50
|
+
}
|
|
51
|
+
function cumulativeRowOffsetPt(pkg, tableElement, anchorRow) {
|
|
52
|
+
let cursor = 0;
|
|
53
|
+
let offsetPt = 0;
|
|
54
|
+
for (const member of collectRunMembers(tableElement.children, isElementWithTag(ROW_TAG), HEADER_ROWS_TAG)) {
|
|
55
|
+
if (cursor >= anchorRow) break;
|
|
56
|
+
const count = readRunRepeatCount(member.node, ROW_REPEAT_ATTR);
|
|
57
|
+
const overlap = Math.min(count, anchorRow - cursor);
|
|
58
|
+
offsetPt += overlap * resolvedRowHeightPt(pkg, member.node);
|
|
59
|
+
cursor += count;
|
|
60
|
+
}
|
|
61
|
+
if (cursor < anchorRow) offsetPt += (anchorRow - cursor) * DEFAULT_ROW_HEIGHT_PT;
|
|
62
|
+
return offsetPt;
|
|
63
|
+
}
|
|
64
|
+
function buildAbsoluteFrame(xPt, yPt, widthPt, heightPt, content) {
|
|
65
|
+
return el("draw:frame", {
|
|
66
|
+
"svg:x": formatOdfLength(xPt),
|
|
67
|
+
"svg:y": formatOdfLength(yPt),
|
|
68
|
+
"svg:width": formatOdfLength(widthPt),
|
|
69
|
+
"svg:height": formatOdfLength(heightPt)
|
|
70
|
+
}, [content]);
|
|
71
|
+
}
|
|
72
|
+
function insertSheetImage(pkg, tableElement, image) {
|
|
73
|
+
const { partPath } = addImageMedia(pkg, base64ToBytes$1(image.base64), image.format);
|
|
74
|
+
const xPt = cumulativeColumnOffsetPt(pkg, tableElement, image.anchorColumn) + image.offsetXPt;
|
|
75
|
+
const yPt = cumulativeRowOffsetPt(pkg, tableElement, image.anchorRow) + image.offsetYPt;
|
|
76
|
+
const imageElement = el("draw:image", { "xlink:href": partPath });
|
|
77
|
+
const frame = buildAbsoluteFrame(xPt, yPt, image.widthPt, image.heightPt, imageElement);
|
|
78
|
+
ensureTableShapes(tableElement).children.push(frame);
|
|
79
|
+
}
|
|
80
|
+
function insertSheetEmbeddedObject(pkg, tableElement, object) {
|
|
81
|
+
if (object.document.kind !== "formula") return;
|
|
82
|
+
const { href } = addFormulaObject(pkg, object.document.formula);
|
|
83
|
+
const objectElement = el("draw:object", { "xlink:href": href });
|
|
84
|
+
const frame = buildAbsoluteFrame(object.frame.xPt, object.frame.yPt, object.frame.widthPt, object.frame.heightPt, objectElement);
|
|
85
|
+
ensureTableShapes(tableElement).children.push(frame);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { insertSheetEmbeddedObject, insertSheetImage };
|
|
@@ -2,6 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
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
|
+
const require_edit_ods_address = require("./address.cjs");
|
|
6
|
+
const require_edit_ods_column_row = require("./column-row.cjs");
|
|
5
7
|
let ooxml_js = require("ooxml.js");
|
|
6
8
|
let odf_js = require("odf.js");
|
|
7
9
|
let document_schema_js = require("document-schema.js");
|
|
@@ -39,6 +41,89 @@ const DEFAULT_MARGINS = {
|
|
|
39
41
|
bottomPt: DEFAULT_MARGIN_PT,
|
|
40
42
|
leftPt: DEFAULT_MARGIN_PT
|
|
41
43
|
};
|
|
44
|
+
function hasManualBreak(pkg, element, family, propertiesTag) {
|
|
45
|
+
const styleName = (0, ooxml_js.attr)(element, "table:style-name");
|
|
46
|
+
const styleElement = styleName === void 0 ? void 0 : (0, odf_js.findStyleElement)(styleName, family, pkg);
|
|
47
|
+
const properties = styleElement === void 0 ? void 0 : directChild(styleElement, propertiesTag);
|
|
48
|
+
return properties !== void 0 && (0, ooxml_js.attr)(properties, "fo:break-before") === "page";
|
|
49
|
+
}
|
|
50
|
+
function scanTableStructure(pkg, tableElement) {
|
|
51
|
+
let columnCursor = 0;
|
|
52
|
+
let rowCursor = 0;
|
|
53
|
+
let repeatColumns;
|
|
54
|
+
let repeatRows;
|
|
55
|
+
const manualBreakColumns = [];
|
|
56
|
+
const manualBreakRows = [];
|
|
57
|
+
function processColumn(columnElement) {
|
|
58
|
+
if (hasManualBreak(pkg, columnElement, "table-column", "style:table-column-properties")) manualBreakColumns.push(columnCursor);
|
|
59
|
+
columnCursor += require_edit_ods_address.readRunRepeatCount(columnElement, require_edit_ods_address.COLUMN_REPEAT_ATTR);
|
|
60
|
+
}
|
|
61
|
+
function processRow(rowElement) {
|
|
62
|
+
const startIndex = rowCursor;
|
|
63
|
+
if (hasManualBreak(pkg, rowElement, "table-row", "style:table-row-properties")) manualBreakRows.push(startIndex);
|
|
64
|
+
rowCursor += require_edit_ods_address.readRunRepeatCount(rowElement, require_edit_ods_address.ROW_REPEAT_ATTR);
|
|
65
|
+
}
|
|
66
|
+
for (const child of tableElement.children) {
|
|
67
|
+
if (child.type !== "element") continue;
|
|
68
|
+
if (child.tag === "table:table-column") processColumn(child);
|
|
69
|
+
else if (child.tag === "table:table-header-columns") {
|
|
70
|
+
const startIndex = columnCursor;
|
|
71
|
+
for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-column") processColumn(headerChild);
|
|
72
|
+
if (columnCursor > startIndex) repeatColumns = {
|
|
73
|
+
start: startIndex,
|
|
74
|
+
end: columnCursor - 1
|
|
75
|
+
};
|
|
76
|
+
} else if (child.tag === "table:table-row") processRow(child);
|
|
77
|
+
else if (child.tag === "table:table-header-rows") {
|
|
78
|
+
const startIndex = rowCursor;
|
|
79
|
+
for (const headerChild of child.children) if (headerChild.type === "element" && headerChild.tag === "table:table-row") processRow(headerChild);
|
|
80
|
+
if (rowCursor > startIndex) repeatRows = {
|
|
81
|
+
start: startIndex,
|
|
82
|
+
end: rowCursor - 1
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
repeatColumns,
|
|
88
|
+
repeatRows,
|
|
89
|
+
manualBreakColumns,
|
|
90
|
+
manualBreakRows
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function parseA1WithOptionalSheetPrefix(cellPart) {
|
|
94
|
+
const dotIndex = cellPart.lastIndexOf(".");
|
|
95
|
+
const bareReference = dotIndex === -1 ? cellPart : cellPart.slice(dotIndex + 1);
|
|
96
|
+
return (0, odf_js.parseCellReference)(bareReference);
|
|
97
|
+
}
|
|
98
|
+
function parsePrintRanges(value) {
|
|
99
|
+
const first = value.split(" ").find((part) => part.length > 0);
|
|
100
|
+
if (first === void 0) return;
|
|
101
|
+
const separatorIndex = first.indexOf(":");
|
|
102
|
+
if (separatorIndex === -1) return;
|
|
103
|
+
const start = parseA1WithOptionalSheetPrefix(first.slice(0, separatorIndex));
|
|
104
|
+
const end = parseA1WithOptionalSheetPrefix(first.slice(separatorIndex + 1));
|
|
105
|
+
if (start === void 0 || end === void 0) return;
|
|
106
|
+
return {
|
|
107
|
+
startRow: start.row,
|
|
108
|
+
startColumn: start.column,
|
|
109
|
+
endRow: end.row,
|
|
110
|
+
endColumn: end.column
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function formatPrintRange(sheetName, range) {
|
|
114
|
+
return `${`${sheetName}.${(0, odf_js.cellReference)(range.startColumn, range.startRow)}`}:${`${sheetName}.${(0, odf_js.cellReference)(range.endColumn, range.endRow)}`}`;
|
|
115
|
+
}
|
|
116
|
+
function parseScalePercentage(value) {
|
|
117
|
+
const match = /^(\d+(?:\.\d+)?)%$/.exec(value);
|
|
118
|
+
if (match === null) return;
|
|
119
|
+
const numeric = match[1];
|
|
120
|
+
return numeric === void 0 ? void 0 : Number(numeric);
|
|
121
|
+
}
|
|
122
|
+
function parseNonNegativeInteger(value) {
|
|
123
|
+
if (value === void 0) return;
|
|
124
|
+
const parsed = Number.parseInt(value, 10);
|
|
125
|
+
return Number.isInteger(parsed) && parsed >= 0 ? parsed : void 0;
|
|
126
|
+
}
|
|
42
127
|
function readSheetPrintSettings(pkg, tableElement) {
|
|
43
128
|
const tableStyleName = (0, ooxml_js.attr)(tableElement, "table:style-name");
|
|
44
129
|
const tableStyleElement = tableStyleName === void 0 ? void 0 : (0, odf_js.findStyleElement)(tableStyleName, "table", pkg);
|
|
@@ -48,14 +133,67 @@ function readSheetPrintSettings(pkg, tableElement) {
|
|
|
48
133
|
const margins = layoutProperties === void 0 ? void 0 : (0, odf_js.parseMargins)(layoutProperties);
|
|
49
134
|
const printTokens = new Set((layoutProperties === void 0 ? void 0 : (0, ooxml_js.attr)(layoutProperties, "style:print"))?.split(" ").filter((token) => token.length > 0) ?? []);
|
|
50
135
|
const pageOrder = (layoutProperties === void 0 ? void 0 : (0, ooxml_js.attr)(layoutProperties, "style:print-page-order")) === "ltr" ? "overThenDown" : "downThenOver";
|
|
136
|
+
const scaleToRaw = layoutProperties === void 0 ? void 0 : (0, ooxml_js.attr)(layoutProperties, "style:scale-to");
|
|
137
|
+
const scalePercent = scaleToRaw === void 0 ? void 0 : parseScalePercentage(scaleToRaw);
|
|
138
|
+
const fitWidth = parseNonNegativeInteger(layoutProperties === void 0 ? void 0 : (0, ooxml_js.attr)(layoutProperties, "style:scale-to-X"));
|
|
139
|
+
const fitHeight = parseNonNegativeInteger(layoutProperties === void 0 ? void 0 : (0, ooxml_js.attr)(layoutProperties, "style:scale-to-Y"));
|
|
140
|
+
const fitToPages = fitWidth === void 0 || fitHeight === void 0 ? void 0 : {
|
|
141
|
+
width: fitWidth,
|
|
142
|
+
height: fitHeight
|
|
143
|
+
};
|
|
144
|
+
const printRangesRaw = (0, ooxml_js.attr)(tableElement, "table:print-ranges");
|
|
145
|
+
const printRange = printRangesRaw === void 0 ? void 0 : parsePrintRanges(printRangesRaw);
|
|
146
|
+
const { repeatColumns, repeatRows, manualBreakColumns, manualBreakRows } = scanTableStructure(pkg, tableElement);
|
|
147
|
+
const manualBreaks = manualBreakRows.length > 0 || manualBreakColumns.length > 0 ? {
|
|
148
|
+
rows: manualBreakRows,
|
|
149
|
+
columns: manualBreakColumns
|
|
150
|
+
} : void 0;
|
|
51
151
|
return {
|
|
52
152
|
pageSize: pageSize ?? document_schema_js.PAGE_SIZE_A4,
|
|
53
153
|
margins: margins ?? DEFAULT_MARGINS,
|
|
54
154
|
gridlines: printTokens.has("grid"),
|
|
55
155
|
headers: printTokens.has("headers"),
|
|
56
|
-
pageOrder
|
|
156
|
+
pageOrder,
|
|
157
|
+
...printRange !== void 0 ? { printRange } : {},
|
|
158
|
+
...scalePercent !== void 0 ? { scalePercent } : {},
|
|
159
|
+
...fitToPages !== void 0 ? { fitToPages } : {},
|
|
160
|
+
...repeatRows !== void 0 ? { repeatRows } : {},
|
|
161
|
+
...repeatColumns !== void 0 ? { repeatColumns } : {},
|
|
162
|
+
...manualBreaks !== void 0 ? { manualBreaks } : {}
|
|
57
163
|
};
|
|
58
164
|
}
|
|
165
|
+
function unwrapHeaderGroup(tableElement, wrapperTag) {
|
|
166
|
+
const index = tableElement.children.findIndex((child) => child.type === "element" && child.tag === wrapperTag);
|
|
167
|
+
if (index === -1) return;
|
|
168
|
+
const wrapper = tableElement.children[index];
|
|
169
|
+
if (wrapper?.type !== "element") return;
|
|
170
|
+
tableElement.children.splice(index, 1, ...wrapper.children);
|
|
171
|
+
}
|
|
172
|
+
function collectRangeElements(children, tag, repeatAttr, start, end) {
|
|
173
|
+
let cursor = 0;
|
|
174
|
+
const found = [];
|
|
175
|
+
children.forEach((node, position) => {
|
|
176
|
+
if (node.type !== "element" || node.tag !== tag) return;
|
|
177
|
+
const count = require_edit_ods_address.readRunRepeatCount(node, repeatAttr);
|
|
178
|
+
if (cursor >= start && cursor + count - 1 <= end) found.push({
|
|
179
|
+
position,
|
|
180
|
+
element: node
|
|
181
|
+
});
|
|
182
|
+
cursor += count;
|
|
183
|
+
});
|
|
184
|
+
return found;
|
|
185
|
+
}
|
|
186
|
+
function wrapRepeatRange(tableElement, memberTag, repeatAttr, wrapperTag, range, buildEmpty) {
|
|
187
|
+
require_edit_ods_address.replaceRun(tableElement.children, require_edit_ods_address.isElementWithTag(memberTag), range.start, repeatAttr, buildEmpty);
|
|
188
|
+
require_edit_ods_address.replaceRun(tableElement.children, require_edit_ods_address.isElementWithTag(memberTag), range.end, repeatAttr, buildEmpty);
|
|
189
|
+
const found = collectRangeElements(tableElement.children, memberTag, repeatAttr, range.start, range.end);
|
|
190
|
+
if (found.length === 0) return;
|
|
191
|
+
const firstPosition = found[0].position;
|
|
192
|
+
const elements = found.map((entry) => entry.element);
|
|
193
|
+
const positions = found.map((entry) => entry.position);
|
|
194
|
+
for (let i = positions.length - 1; i >= 0; i--) tableElement.children.splice(positions[i], 1);
|
|
195
|
+
tableElement.children.splice(firstPosition, 0, require_xml_fragment.el(wrapperTag, {}, elements));
|
|
196
|
+
}
|
|
59
197
|
function writeSheetPrintSettings(pkg, tableElement, settings) {
|
|
60
198
|
const stylesAutomaticStyles = findStylesAutomaticStyles(pkg);
|
|
61
199
|
const masterStyles = findMasterStyles(pkg);
|
|
@@ -70,7 +208,12 @@ function writeSheetPrintSettings(pkg, tableElement, settings) {
|
|
|
70
208
|
"fo:margin-bottom": (0, odf_js.formatOdfLength)(settings.margins.bottomPt),
|
|
71
209
|
"fo:margin-left": (0, odf_js.formatOdfLength)(settings.margins.leftPt),
|
|
72
210
|
...printTokens.length > 0 ? { "style:print": printTokens.join(" ") } : {},
|
|
73
|
-
"style:print-page-order": settings.pageOrder === "overThenDown" ? "ltr" : "ttb"
|
|
211
|
+
"style:print-page-order": settings.pageOrder === "overThenDown" ? "ltr" : "ttb",
|
|
212
|
+
...settings.scalePercent !== void 0 ? { "style:scale-to": `${settings.scalePercent}%` } : {},
|
|
213
|
+
...settings.fitToPages !== void 0 ? {
|
|
214
|
+
"style:scale-to-X": String(settings.fitToPages.width),
|
|
215
|
+
"style:scale-to-Y": String(settings.fitToPages.height)
|
|
216
|
+
} : {}
|
|
74
217
|
})]));
|
|
75
218
|
const masterPageName = require_edit_odt_automatic_styles.nextStyleName(masterStyles, "style:master-page", "OdsMasterPage");
|
|
76
219
|
masterStyles.children.push(require_xml_fragment.el("style:master-page", {
|
|
@@ -84,6 +227,19 @@ function writeSheetPrintSettings(pkg, tableElement, settings) {
|
|
|
84
227
|
"style:master-page-name": masterPageName
|
|
85
228
|
}));
|
|
86
229
|
require_xml_edit.setAttr(tableElement, "table:style-name", tableStyleName);
|
|
230
|
+
if (settings.printRange !== void 0) {
|
|
231
|
+
const sheetName = (0, ooxml_js.attr)(tableElement, "table:name");
|
|
232
|
+
if (sheetName === void 0) throw new Error("writeSheetPrintSettings: printRange requires tableElement to already carry a table:name");
|
|
233
|
+
require_xml_edit.setAttr(tableElement, "table:print-ranges", formatPrintRange(sheetName, settings.printRange));
|
|
234
|
+
}
|
|
235
|
+
unwrapHeaderGroup(tableElement, require_edit_ods_address.HEADER_COLUMNS_TAG);
|
|
236
|
+
if (settings.repeatColumns !== void 0) wrapRepeatRange(tableElement, require_edit_ods_address.COLUMN_TAG, require_edit_ods_address.COLUMN_REPEAT_ATTR, require_edit_ods_address.HEADER_COLUMNS_TAG, settings.repeatColumns, () => require_xml_fragment.el(require_edit_ods_address.COLUMN_TAG));
|
|
237
|
+
unwrapHeaderGroup(tableElement, require_edit_ods_address.HEADER_ROWS_TAG);
|
|
238
|
+
if (settings.repeatRows !== void 0) wrapRepeatRange(tableElement, require_edit_ods_address.ROW_TAG, require_edit_ods_address.ROW_REPEAT_ATTR, require_edit_ods_address.HEADER_ROWS_TAG, settings.repeatRows, () => require_xml_fragment.el(require_edit_ods_address.ROW_TAG));
|
|
239
|
+
if (settings.manualBreaks !== void 0) {
|
|
240
|
+
for (const columnIndex of settings.manualBreaks.columns) require_edit_ods_column_row.writeColumnManualBreak(pkg, tableElement, columnIndex);
|
|
241
|
+
for (const rowIndex of settings.manualBreaks.rows) require_edit_ods_column_row.writeRowManualBreak(pkg, tableElement, rowIndex);
|
|
242
|
+
}
|
|
87
243
|
}
|
|
88
244
|
//#endregion
|
|
89
245
|
exports.readSheetPrintSettings = readSheetPrintSettings;
|