odf.js 1.12.1 → 1.13.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.
Files changed (178) hide show
  1. package/README.md +10 -0
  2. package/dist/codec.cjs +28 -0
  3. package/dist/codec.d.cts +72 -0
  4. package/dist/codec.d.ts +72 -0
  5. package/dist/codec.js +24 -0
  6. package/dist/image/sniff.cjs +28 -0
  7. package/dist/image/sniff.d.cts +5 -0
  8. package/dist/image/sniff.d.ts +5 -0
  9. package/dist/image/sniff.js +27 -0
  10. package/dist/index.cjs +156 -3242
  11. package/dist/index.d.cts +42 -679
  12. package/dist/index.d.ts +42 -679
  13. package/dist/index.js +42 -3129
  14. package/dist/manifest.cjs +252 -0
  15. package/dist/manifest.d.cts +41 -0
  16. package/dist/manifest.d.ts +41 -0
  17. package/dist/manifest.js +242 -0
  18. package/dist/media-type.cjs +27 -0
  19. package/dist/media-type.d.cts +20 -0
  20. package/dist/media-type.d.ts +20 -0
  21. package/dist/media-type.js +25 -0
  22. package/dist/mimetype.cjs +19 -0
  23. package/dist/mimetype.d.cts +7 -0
  24. package/dist/mimetype.d.ts +7 -0
  25. package/dist/mimetype.js +16 -0
  26. package/dist/model/node.cjs +67 -0
  27. package/dist/model/node.d.cts +2 -0
  28. package/dist/model/node.d.ts +2 -0
  29. package/dist/model/node.js +58 -0
  30. package/dist/model/package.cjs +19 -0
  31. package/dist/model/package.d.cts +114 -0
  32. package/dist/model/package.d.ts +114 -0
  33. package/dist/model/package.js +15 -0
  34. package/dist/node-CkBWRjNR.d.cts +83 -0
  35. package/dist/node-CkBWRjNR.d.ts +83 -0
  36. package/dist/ns.cjs +37 -0
  37. package/dist/ns.d.cts +32 -0
  38. package/dist/ns.d.ts +32 -0
  39. package/dist/ns.js +35 -0
  40. package/dist/package-io/read.cjs +35 -0
  41. package/dist/package-io/read.d.cts +5 -0
  42. package/dist/package-io/read.d.ts +5 -0
  43. package/dist/package-io/read.js +34 -0
  44. package/dist/package-io/write.cjs +36 -0
  45. package/dist/package-io/write.d.cts +7 -0
  46. package/dist/package-io/write.d.ts +7 -0
  47. package/dist/package-io/write.js +33 -0
  48. package/dist/styles/properties.cjs +286 -0
  49. package/dist/styles/properties.d.cts +45 -0
  50. package/dist/styles/properties.d.ts +45 -0
  51. package/dist/styles/properties.js +277 -0
  52. package/dist/styles/registry.cjs +212 -0
  53. package/dist/styles/registry.d.cts +37 -0
  54. package/dist/styles/registry.d.ts +37 -0
  55. package/dist/styles/registry.js +209 -0
  56. package/dist/styles/serialize.cjs +23 -0
  57. package/dist/styles/serialize.d.cts +7 -0
  58. package/dist/styles/serialize.d.ts +7 -0
  59. package/dist/styles/serialize.js +21 -0
  60. package/dist/styles/span.cjs +114 -0
  61. package/dist/styles/span.d.cts +5 -0
  62. package/dist/styles/span.d.ts +5 -0
  63. package/dist/styles/span.js +113 -0
  64. package/dist/typed/draw/shapes.cjs +314 -0
  65. package/dist/typed/draw/shapes.d.cts +14 -0
  66. package/dist/typed/draw/shapes.d.ts +14 -0
  67. package/dist/typed/draw/shapes.js +311 -0
  68. package/dist/typed/formula/read.cjs +48 -0
  69. package/dist/typed/formula/read.d.cts +12 -0
  70. package/dist/typed/formula/read.d.ts +12 -0
  71. package/dist/typed/formula/read.js +47 -0
  72. package/dist/typed/odb/read.cjs +112 -0
  73. package/dist/typed/odb/read.d.cts +17 -0
  74. package/dist/typed/odb/read.d.ts +17 -0
  75. package/dist/typed/odb/read.js +111 -0
  76. package/dist/typed/odg/read.cjs +30 -0
  77. package/dist/typed/odg/read.d.cts +10 -0
  78. package/dist/typed/odg/read.d.ts +10 -0
  79. package/dist/typed/odg/read.js +29 -0
  80. package/dist/typed/odm/read.cjs +37 -0
  81. package/dist/typed/odm/read.d.cts +15 -0
  82. package/dist/typed/odm/read.d.ts +15 -0
  83. package/dist/typed/odm/read.js +36 -0
  84. package/dist/typed/odp/read.cjs +39 -0
  85. package/dist/typed/odp/read.d.cts +10 -0
  86. package/dist/typed/odp/read.d.ts +10 -0
  87. package/dist/typed/odp/read.js +38 -0
  88. package/dist/typed/ods/read.cjs +318 -0
  89. package/dist/typed/ods/read.d.cts +10 -0
  90. package/dist/typed/ods/read.d.ts +10 -0
  91. package/dist/typed/ods/read.js +317 -0
  92. package/dist/typed/odt/read.cjs +112 -0
  93. package/dist/typed/odt/read.d.cts +10 -0
  94. package/dist/typed/odt/read.d.ts +10 -0
  95. package/dist/typed/odt/read.js +111 -0
  96. package/dist/typed/shared/a1.cjs +68 -0
  97. package/dist/typed/shared/a1.d.cts +18 -0
  98. package/dist/typed/shared/a1.d.ts +18 -0
  99. package/dist/typed/shared/a1.js +63 -0
  100. package/dist/typed/shared/cascade.cjs +102 -0
  101. package/dist/typed/shared/cascade.d.cts +22 -0
  102. package/dist/typed/shared/cascade.d.ts +22 -0
  103. package/dist/typed/shared/cascade.js +99 -0
  104. package/dist/typed/shared/color.cjs +14 -0
  105. package/dist/typed/shared/color.d.cts +6 -0
  106. package/dist/typed/shared/color.d.ts +6 -0
  107. package/dist/typed/shared/color.js +12 -0
  108. package/dist/typed/shared/geometry.cjs +79 -0
  109. package/dist/typed/shared/geometry.d.cts +12 -0
  110. package/dist/typed/shared/geometry.d.ts +12 -0
  111. package/dist/typed/shared/geometry.js +75 -0
  112. package/dist/typed/shared/masterpage.cjs +39 -0
  113. package/dist/typed/shared/masterpage.d.cts +8 -0
  114. package/dist/typed/shared/masterpage.d.ts +8 -0
  115. package/dist/typed/shared/masterpage.js +37 -0
  116. package/dist/typed/shared/metadata.cjs +42 -0
  117. package/dist/typed/shared/metadata.d.cts +7 -0
  118. package/dist/typed/shared/metadata.d.ts +7 -0
  119. package/dist/typed/shared/metadata.js +40 -0
  120. package/dist/typed/shared/paragraph.cjs +57 -0
  121. package/dist/typed/shared/paragraph.d.cts +7 -0
  122. package/dist/typed/shared/paragraph.d.ts +7 -0
  123. package/dist/typed/shared/paragraph.js +56 -0
  124. package/dist/typed/shared/path.cjs +261 -0
  125. package/dist/typed/shared/path.d.cts +34 -0
  126. package/dist/typed/shared/path.d.ts +34 -0
  127. package/dist/typed/shared/path.js +255 -0
  128. package/dist/typed/shared/style.cjs +8 -0
  129. package/dist/typed/shared/style.d.cts +2 -0
  130. package/dist/typed/shared/style.d.ts +2 -0
  131. package/dist/typed/shared/style.js +2 -0
  132. package/dist/typed/shared/table.cjs +84 -0
  133. package/dist/typed/shared/table.d.cts +7 -0
  134. package/dist/typed/shared/table.d.ts +7 -0
  135. package/dist/typed/shared/table.js +83 -0
  136. package/dist/typed/shared/text.cjs +43 -0
  137. package/dist/typed/shared/text.d.cts +8 -0
  138. package/dist/typed/shared/text.d.ts +8 -0
  139. package/dist/typed/shared/text.js +39 -0
  140. package/dist/typed/shared/transform.cjs +112 -0
  141. package/dist/typed/shared/transform.d.cts +26 -0
  142. package/dist/typed/shared/transform.d.ts +26 -0
  143. package/dist/typed/shared/transform.js +107 -0
  144. package/dist/typed/shared/units.cjs +35 -0
  145. package/dist/typed/shared/units.d.cts +2 -0
  146. package/dist/typed/shared/units.d.ts +2 -0
  147. package/dist/typed/shared/units.js +33 -0
  148. package/dist/units-7pCiECuP.d.cts +6 -0
  149. package/dist/units-7pCiECuP.d.ts +6 -0
  150. package/dist/util/base64.cjs +48 -0
  151. package/dist/util/base64.d.cts +5 -0
  152. package/dist/util/base64.d.ts +5 -0
  153. package/dist/util/base64.js +46 -0
  154. package/dist/xml/build.cjs +46 -0
  155. package/dist/xml/build.d.cts +5 -0
  156. package/dist/xml/build.d.ts +5 -0
  157. package/dist/xml/build.js +46 -0
  158. package/dist/xml/entities.cjs +19 -0
  159. package/dist/xml/entities.d.cts +5 -0
  160. package/dist/xml/entities.d.ts +5 -0
  161. package/dist/xml/entities.js +17 -0
  162. package/dist/xml/fragment.cjs +22 -0
  163. package/dist/xml/fragment.d.cts +6 -0
  164. package/dist/xml/fragment.d.ts +6 -0
  165. package/dist/xml/fragment.js +20 -0
  166. package/dist/xml/parse.cjs +88 -0
  167. package/dist/xml/parse.d.cts +5 -0
  168. package/dist/xml/parse.d.ts +5 -0
  169. package/dist/xml/parse.js +88 -0
  170. package/dist/xml/query.cjs +33 -0
  171. package/dist/xml/query.d.cts +9 -0
  172. package/dist/xml/query.d.ts +9 -0
  173. package/dist/xml/query.js +28 -0
  174. package/dist/zip.cjs +15 -0
  175. package/dist/zip.d.cts +9 -0
  176. package/dist/zip.d.ts +9 -0
  177. package/dist/zip.js +13 -0
  178. package/package.json +9 -1
@@ -0,0 +1,63 @@
1
+ //#region src/typed/shared/a1.ts
2
+ const ALPHABET_SIZE = 26;
3
+ const ALPHABET_START_CODE = "A".charCodeAt(0);
4
+ function columnIndexToLetters(index) {
5
+ if (!Number.isInteger(index) || index < 0) throw new Error(`columnIndexToLetters: index must be a non-negative integer, got ${index}`);
6
+ let remaining = index + 1;
7
+ let letters = "";
8
+ while (remaining > 0) {
9
+ const digit = (remaining - 1) % ALPHABET_SIZE;
10
+ letters = String.fromCharCode(ALPHABET_START_CODE + digit) + letters;
11
+ remaining = Math.floor((remaining - 1) / ALPHABET_SIZE);
12
+ }
13
+ return letters;
14
+ }
15
+ function cellReference(columnIndex, rowIndex) {
16
+ if (!Number.isInteger(rowIndex) || rowIndex < 0) throw new Error(`cellReference: rowIndex must be a non-negative integer, got ${rowIndex}`);
17
+ return `${columnIndexToLetters(columnIndex)}${rowIndex + 1}`;
18
+ }
19
+ function columnLettersToIndex(letters) {
20
+ if (!/^[A-Z]+$/.test(letters)) return;
21
+ let index = 0;
22
+ for (const char of letters) index = index * ALPHABET_SIZE + (char.charCodeAt(0) - ALPHABET_START_CODE + 1);
23
+ return index - 1;
24
+ }
25
+ function parseCellReference(reference) {
26
+ const match = /^([A-Z]+)(\d+)$/.exec(reference);
27
+ if (match === null) return;
28
+ const [, letters, digits] = match;
29
+ if (letters === void 0 || digits === void 0) return;
30
+ const column = columnLettersToIndex(letters);
31
+ const row = Number.parseInt(digits, 10) - 1;
32
+ if (column === void 0 || row < 0) return;
33
+ return {
34
+ column,
35
+ row
36
+ };
37
+ }
38
+ function validateRepeatCount(repeatCount, caller) {
39
+ if (!Number.isInteger(repeatCount) || repeatCount < 1) throw new Error(`${caller}: repeatCount must be a positive integer, got ${repeatCount}`);
40
+ }
41
+ var TableCursor = class {
42
+ columnCursor = 0;
43
+ rowCursor = 0;
44
+ get columnIndex() {
45
+ return this.columnCursor;
46
+ }
47
+ get rowIndex() {
48
+ return this.rowCursor;
49
+ }
50
+ nextCell(repeatCount = 1) {
51
+ validateRepeatCount(repeatCount, "TableCursor.nextCell");
52
+ const reference = cellReference(this.columnCursor, this.rowCursor);
53
+ this.columnCursor += repeatCount;
54
+ return reference;
55
+ }
56
+ nextRow(repeatCount = 1) {
57
+ validateRepeatCount(repeatCount, "TableCursor.nextRow");
58
+ this.rowCursor += repeatCount;
59
+ this.columnCursor = 0;
60
+ }
61
+ };
62
+ //#endregion
63
+ export { TableCursor, cellReference, columnIndexToLetters, columnLettersToIndex, parseCellReference };
@@ -0,0 +1,102 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_styles_properties = require("../../styles/properties.cjs");
3
+ const require_styles_registry = require("../../styles/registry.cjs");
4
+ const require_xml_query = require("../../xml/query.cjs");
5
+ //#region src/typed/shared/cascade.ts
6
+ const STYLE_PARTS = ["content.xml", "styles.xml"];
7
+ const NAME_KEY_SEPARATOR = "\0";
8
+ function nameKey(family, name) {
9
+ return `${family}${NAME_KEY_SEPARATOR}${name}`;
10
+ }
11
+ function collectStyles(pkg) {
12
+ const byName = /* @__PURE__ */ new Map();
13
+ const defaultByFamily = /* @__PURE__ */ new Map();
14
+ for (const partPath of STYLE_PARTS) {
15
+ const part = pkg.parts[partPath];
16
+ if (part?.kind !== "xml") continue;
17
+ const root = require_xml_query.rootElement(part.nodes);
18
+ if (root === void 0) continue;
19
+ for (const containerTag of ["office:automatic-styles", "office:styles"]) {
20
+ const container = require_xml_query.findChildElement(root.children, containerTag);
21
+ if (container === void 0) continue;
22
+ for (const child of container.children) {
23
+ if (child.type !== "element") continue;
24
+ if (child.tag === "style:style") {
25
+ const name = require_xml_query.attrValue(child, "style:name");
26
+ const family = require_xml_query.attrValue(child, "style:family");
27
+ if (name === void 0 || family === void 0 || !require_styles_registry.isStyleFamily(family)) continue;
28
+ byName.set(nameKey(family, name), child);
29
+ } else if (child.tag === "style:default-style") {
30
+ const family = require_xml_query.attrValue(child, "style:family");
31
+ if (family === void 0 || !require_styles_registry.isStyleFamily(family)) continue;
32
+ if (!defaultByFamily.has(family)) defaultByFamily.set(family, child);
33
+ }
34
+ }
35
+ }
36
+ }
37
+ return {
38
+ byName,
39
+ defaultByFamily
40
+ };
41
+ }
42
+ function resolveStyleElementChain(styleName, family, pkg) {
43
+ const { byName, defaultByFamily } = collectStyles(pkg);
44
+ const diagnostics = [];
45
+ const elements = [];
46
+ const defaultElement = defaultByFamily.get(family);
47
+ if (defaultElement !== void 0) elements.push(defaultElement);
48
+ if (styleName === void 0) return {
49
+ elements,
50
+ diagnostics
51
+ };
52
+ const chain = [];
53
+ const visited = /* @__PURE__ */ new Set();
54
+ let currentName = styleName;
55
+ while (currentName !== void 0) {
56
+ const key = nameKey(family, currentName);
57
+ if (visited.has(key)) {
58
+ diagnostics.push({
59
+ severity: "warning",
60
+ message: `cyclic style:parent-style-name chain detected at style "${currentName}" (family "${family}") -- breaking the cycle and stopping cascade resolution at this point`
61
+ });
62
+ break;
63
+ }
64
+ visited.add(key);
65
+ const element = byName.get(key);
66
+ if (element === void 0) {
67
+ diagnostics.push({
68
+ severity: "warning",
69
+ message: `style "${currentName}" (family "${family}") was not found in content.xml or styles.xml -- stopping cascade resolution at this point`
70
+ });
71
+ break;
72
+ }
73
+ chain.push(element);
74
+ currentName = require_xml_query.attrValue(element, "style:parent-style-name");
75
+ }
76
+ chain.reverse();
77
+ elements.push(...chain);
78
+ return {
79
+ elements,
80
+ diagnostics
81
+ };
82
+ }
83
+ function resolveStyle(styleName, family, pkg) {
84
+ const { elements, diagnostics } = resolveStyleElementChain(styleName, family, pkg);
85
+ let properties = {};
86
+ for (const element of elements) properties = {
87
+ ...properties,
88
+ ...require_styles_properties.parseStyleElementProperties(element).properties
89
+ };
90
+ return {
91
+ properties,
92
+ diagnostics
93
+ };
94
+ }
95
+ function findStyleElement(styleName, family, pkg) {
96
+ const { byName } = collectStyles(pkg);
97
+ return byName.get(nameKey(family, styleName));
98
+ }
99
+ //#endregion
100
+ exports.findStyleElement = findStyleElement;
101
+ exports.resolveStyle = resolveStyle;
102
+ exports.resolveStyleElementChain = resolveStyleElementChain;
@@ -0,0 +1,22 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.cjs";
2
+ import { Package } from "../../model/package.cjs";
3
+ import { StyleProperties } from "../../styles/properties.cjs";
4
+ import { StyleFamily } from "../../styles/registry.cjs";
5
+ //#region src/typed/shared/cascade.d.ts
6
+ interface CascadeDiagnostic {
7
+ severity: 'warning';
8
+ message: string;
9
+ }
10
+ interface StyleCascadeResult {
11
+ properties: StyleProperties;
12
+ diagnostics: CascadeDiagnostic[];
13
+ }
14
+ interface StyleElementChainResult {
15
+ elements: XmlElement[];
16
+ diagnostics: CascadeDiagnostic[];
17
+ }
18
+ declare function resolveStyleElementChain(styleName: string | undefined, family: StyleFamily, pkg: Package): StyleElementChainResult;
19
+ declare function resolveStyle(styleName: string | undefined, family: StyleFamily, pkg: Package): StyleCascadeResult;
20
+ declare function findStyleElement(styleName: string, family: StyleFamily, pkg: Package): XmlElement | undefined;
21
+ //#endregion
22
+ export { CascadeDiagnostic, StyleCascadeResult, StyleElementChainResult, findStyleElement, resolveStyle, resolveStyleElementChain };
@@ -0,0 +1,22 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.js";
2
+ import { Package } from "../../model/package.js";
3
+ import { StyleProperties } from "../../styles/properties.js";
4
+ import { StyleFamily } from "../../styles/registry.js";
5
+ //#region src/typed/shared/cascade.d.ts
6
+ interface CascadeDiagnostic {
7
+ severity: 'warning';
8
+ message: string;
9
+ }
10
+ interface StyleCascadeResult {
11
+ properties: StyleProperties;
12
+ diagnostics: CascadeDiagnostic[];
13
+ }
14
+ interface StyleElementChainResult {
15
+ elements: XmlElement[];
16
+ diagnostics: CascadeDiagnostic[];
17
+ }
18
+ declare function resolveStyleElementChain(styleName: string | undefined, family: StyleFamily, pkg: Package): StyleElementChainResult;
19
+ declare function resolveStyle(styleName: string | undefined, family: StyleFamily, pkg: Package): StyleCascadeResult;
20
+ declare function findStyleElement(styleName: string, family: StyleFamily, pkg: Package): XmlElement | undefined;
21
+ //#endregion
22
+ export { CascadeDiagnostic, StyleCascadeResult, StyleElementChainResult, findStyleElement, resolveStyle, resolveStyleElementChain };
@@ -0,0 +1,99 @@
1
+ import { parseStyleElementProperties } from "../../styles/properties.js";
2
+ import { isStyleFamily } from "../../styles/registry.js";
3
+ import { attrValue, findChildElement, rootElement } from "../../xml/query.js";
4
+ //#region src/typed/shared/cascade.ts
5
+ const STYLE_PARTS = ["content.xml", "styles.xml"];
6
+ const NAME_KEY_SEPARATOR = "\0";
7
+ function nameKey(family, name) {
8
+ return `${family}${NAME_KEY_SEPARATOR}${name}`;
9
+ }
10
+ function collectStyles(pkg) {
11
+ const byName = /* @__PURE__ */ new Map();
12
+ const defaultByFamily = /* @__PURE__ */ new Map();
13
+ for (const partPath of STYLE_PARTS) {
14
+ const part = pkg.parts[partPath];
15
+ if (part?.kind !== "xml") continue;
16
+ const root = rootElement(part.nodes);
17
+ if (root === void 0) continue;
18
+ for (const containerTag of ["office:automatic-styles", "office:styles"]) {
19
+ const container = findChildElement(root.children, containerTag);
20
+ if (container === void 0) continue;
21
+ for (const child of container.children) {
22
+ if (child.type !== "element") continue;
23
+ if (child.tag === "style:style") {
24
+ const name = attrValue(child, "style:name");
25
+ const family = attrValue(child, "style:family");
26
+ if (name === void 0 || family === void 0 || !isStyleFamily(family)) continue;
27
+ byName.set(nameKey(family, name), child);
28
+ } else if (child.tag === "style:default-style") {
29
+ const family = attrValue(child, "style:family");
30
+ if (family === void 0 || !isStyleFamily(family)) continue;
31
+ if (!defaultByFamily.has(family)) defaultByFamily.set(family, child);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ return {
37
+ byName,
38
+ defaultByFamily
39
+ };
40
+ }
41
+ function resolveStyleElementChain(styleName, family, pkg) {
42
+ const { byName, defaultByFamily } = collectStyles(pkg);
43
+ const diagnostics = [];
44
+ const elements = [];
45
+ const defaultElement = defaultByFamily.get(family);
46
+ if (defaultElement !== void 0) elements.push(defaultElement);
47
+ if (styleName === void 0) return {
48
+ elements,
49
+ diagnostics
50
+ };
51
+ const chain = [];
52
+ const visited = /* @__PURE__ */ new Set();
53
+ let currentName = styleName;
54
+ while (currentName !== void 0) {
55
+ const key = nameKey(family, currentName);
56
+ if (visited.has(key)) {
57
+ diagnostics.push({
58
+ severity: "warning",
59
+ message: `cyclic style:parent-style-name chain detected at style "${currentName}" (family "${family}") -- breaking the cycle and stopping cascade resolution at this point`
60
+ });
61
+ break;
62
+ }
63
+ visited.add(key);
64
+ const element = byName.get(key);
65
+ if (element === void 0) {
66
+ diagnostics.push({
67
+ severity: "warning",
68
+ message: `style "${currentName}" (family "${family}") was not found in content.xml or styles.xml -- stopping cascade resolution at this point`
69
+ });
70
+ break;
71
+ }
72
+ chain.push(element);
73
+ currentName = attrValue(element, "style:parent-style-name");
74
+ }
75
+ chain.reverse();
76
+ elements.push(...chain);
77
+ return {
78
+ elements,
79
+ diagnostics
80
+ };
81
+ }
82
+ function resolveStyle(styleName, family, pkg) {
83
+ const { elements, diagnostics } = resolveStyleElementChain(styleName, family, pkg);
84
+ let properties = {};
85
+ for (const element of elements) properties = {
86
+ ...properties,
87
+ ...parseStyleElementProperties(element).properties
88
+ };
89
+ return {
90
+ properties,
91
+ diagnostics
92
+ };
93
+ }
94
+ function findStyleElement(styleName, family, pkg) {
95
+ const { byName } = collectStyles(pkg);
96
+ return byName.get(nameKey(family, styleName));
97
+ }
98
+ //#endregion
99
+ export { findStyleElement, resolveStyle, resolveStyleElementChain };
@@ -0,0 +1,14 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let document_schema_js = require("document-schema.js");
3
+ //#region src/typed/shared/color.ts
4
+ const ODF_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/;
5
+ function parseOdfColor(value) {
6
+ if (!ODF_COLOR_PATTERN.test(value)) return;
7
+ return (0, document_schema_js.rgbHexToColor)(value);
8
+ }
9
+ function formatOdfColor(color) {
10
+ return `#${(0, document_schema_js.colorToRgbHex)(color)}`;
11
+ }
12
+ //#endregion
13
+ exports.formatOdfColor = formatOdfColor;
14
+ exports.parseOdfColor = parseOdfColor;
@@ -0,0 +1,6 @@
1
+ import { Color } from "document-schema.js";
2
+ //#region src/typed/shared/color.d.ts
3
+ declare function parseOdfColor(value: string): Color | undefined;
4
+ declare function formatOdfColor(color: Color): string;
5
+ //#endregion
6
+ export { formatOdfColor, parseOdfColor };
@@ -0,0 +1,6 @@
1
+ import { Color } from "document-schema.js";
2
+ //#region src/typed/shared/color.d.ts
3
+ declare function parseOdfColor(value: string): Color | undefined;
4
+ declare function formatOdfColor(color: Color): string;
5
+ //#endregion
6
+ export { formatOdfColor, parseOdfColor };
@@ -0,0 +1,12 @@
1
+ import { colorToRgbHex, rgbHexToColor } from "document-schema.js";
2
+ //#region src/typed/shared/color.ts
3
+ const ODF_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/;
4
+ function parseOdfColor(value) {
5
+ if (!ODF_COLOR_PATTERN.test(value)) return;
6
+ return rgbHexToColor(value);
7
+ }
8
+ function formatOdfColor(color) {
9
+ return `#${colorToRgbHex(color)}`;
10
+ }
11
+ //#endregion
12
+ export { formatOdfColor, parseOdfColor };
@@ -0,0 +1,79 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_typed_shared_units = require("./units.cjs");
3
+ const require_xml_query = require("../../xml/query.cjs");
4
+ //#region src/typed/shared/geometry.ts
5
+ function parsePageSize(pageLayoutProperties) {
6
+ const widthValue = require_xml_query.attrValue(pageLayoutProperties, "fo:page-width");
7
+ const heightValue = require_xml_query.attrValue(pageLayoutProperties, "fo:page-height");
8
+ if (widthValue === void 0 || heightValue === void 0) return;
9
+ const widthPt = require_typed_shared_units.parseOdfLength(widthValue);
10
+ const heightPt = require_typed_shared_units.parseOdfLength(heightValue);
11
+ if (widthPt === void 0 || heightPt === void 0) return;
12
+ return {
13
+ widthPt,
14
+ heightPt
15
+ };
16
+ }
17
+ function parseMargins(pageLayoutProperties) {
18
+ const topValue = require_xml_query.attrValue(pageLayoutProperties, "fo:margin-top");
19
+ const rightValue = require_xml_query.attrValue(pageLayoutProperties, "fo:margin-right");
20
+ const bottomValue = require_xml_query.attrValue(pageLayoutProperties, "fo:margin-bottom");
21
+ const leftValue = require_xml_query.attrValue(pageLayoutProperties, "fo:margin-left");
22
+ if (topValue === void 0 || rightValue === void 0 || bottomValue === void 0 || leftValue === void 0) return;
23
+ const topPt = require_typed_shared_units.parseOdfLength(topValue);
24
+ const rightPt = require_typed_shared_units.parseOdfLength(rightValue);
25
+ const bottomPt = require_typed_shared_units.parseOdfLength(bottomValue);
26
+ const leftPt = require_typed_shared_units.parseOdfLength(leftValue);
27
+ if (topPt === void 0 || rightPt === void 0 || bottomPt === void 0 || leftPt === void 0) return;
28
+ return {
29
+ topPt,
30
+ rightPt,
31
+ bottomPt,
32
+ leftPt
33
+ };
34
+ }
35
+ function parseBox(element) {
36
+ const xValue = require_xml_query.attrValue(element, "svg:x");
37
+ const yValue = require_xml_query.attrValue(element, "svg:y");
38
+ const widthValue = require_xml_query.attrValue(element, "svg:width");
39
+ const heightValue = require_xml_query.attrValue(element, "svg:height");
40
+ if (xValue === void 0 || yValue === void 0 || widthValue === void 0 || heightValue === void 0) return;
41
+ const xPt = require_typed_shared_units.parseOdfLength(xValue);
42
+ const yPt = require_typed_shared_units.parseOdfLength(yValue);
43
+ const widthPt = require_typed_shared_units.parseOdfLength(widthValue);
44
+ const heightPt = require_typed_shared_units.parseOdfLength(heightValue);
45
+ if (xPt === void 0 || yPt === void 0 || widthPt === void 0 || heightPt === void 0) return;
46
+ return {
47
+ xPt,
48
+ yPt,
49
+ widthPt,
50
+ heightPt
51
+ };
52
+ }
53
+ function parseLinePoints(element) {
54
+ const x1Value = require_xml_query.attrValue(element, "svg:x1");
55
+ const y1Value = require_xml_query.attrValue(element, "svg:y1");
56
+ const x2Value = require_xml_query.attrValue(element, "svg:x2");
57
+ const y2Value = require_xml_query.attrValue(element, "svg:y2");
58
+ if (x1Value === void 0 || y1Value === void 0 || x2Value === void 0 || y2Value === void 0) return;
59
+ const x1Pt = require_typed_shared_units.parseOdfLength(x1Value);
60
+ const y1Pt = require_typed_shared_units.parseOdfLength(y1Value);
61
+ const x2Pt = require_typed_shared_units.parseOdfLength(x2Value);
62
+ const y2Pt = require_typed_shared_units.parseOdfLength(y2Value);
63
+ if (x1Pt === void 0 || y1Pt === void 0 || x2Pt === void 0 || y2Pt === void 0) return;
64
+ return {
65
+ from: {
66
+ xPt: x1Pt,
67
+ yPt: y1Pt
68
+ },
69
+ to: {
70
+ xPt: x2Pt,
71
+ yPt: y2Pt
72
+ }
73
+ };
74
+ }
75
+ //#endregion
76
+ exports.parseBox = parseBox;
77
+ exports.parseLinePoints = parseLinePoints;
78
+ exports.parseMargins = parseMargins;
79
+ exports.parsePageSize = parsePageSize;
@@ -0,0 +1,12 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.cjs";
2
+ import { Box, ContentPathPoint, Margins, PageSize } from "document-schema.js";
3
+ //#region src/typed/shared/geometry.d.ts
4
+ declare function parsePageSize(pageLayoutProperties: XmlElement): PageSize | undefined;
5
+ declare function parseMargins(pageLayoutProperties: XmlElement): Margins | undefined;
6
+ declare function parseBox(element: XmlElement): Box | undefined;
7
+ declare function parseLinePoints(element: XmlElement): {
8
+ from: ContentPathPoint;
9
+ to: ContentPathPoint;
10
+ } | undefined;
11
+ //#endregion
12
+ export { parseBox, parseLinePoints, parseMargins, parsePageSize };
@@ -0,0 +1,12 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.js";
2
+ import { Box, ContentPathPoint, Margins, PageSize } from "document-schema.js";
3
+ //#region src/typed/shared/geometry.d.ts
4
+ declare function parsePageSize(pageLayoutProperties: XmlElement): PageSize | undefined;
5
+ declare function parseMargins(pageLayoutProperties: XmlElement): Margins | undefined;
6
+ declare function parseBox(element: XmlElement): Box | undefined;
7
+ declare function parseLinePoints(element: XmlElement): {
8
+ from: ContentPathPoint;
9
+ to: ContentPathPoint;
10
+ } | undefined;
11
+ //#endregion
12
+ export { parseBox, parseLinePoints, parseMargins, parsePageSize };
@@ -0,0 +1,75 @@
1
+ import { parseOdfLength } from "./units.js";
2
+ import { attrValue } from "../../xml/query.js";
3
+ //#region src/typed/shared/geometry.ts
4
+ function parsePageSize(pageLayoutProperties) {
5
+ const widthValue = attrValue(pageLayoutProperties, "fo:page-width");
6
+ const heightValue = attrValue(pageLayoutProperties, "fo:page-height");
7
+ if (widthValue === void 0 || heightValue === void 0) return;
8
+ const widthPt = parseOdfLength(widthValue);
9
+ const heightPt = parseOdfLength(heightValue);
10
+ if (widthPt === void 0 || heightPt === void 0) return;
11
+ return {
12
+ widthPt,
13
+ heightPt
14
+ };
15
+ }
16
+ function parseMargins(pageLayoutProperties) {
17
+ const topValue = attrValue(pageLayoutProperties, "fo:margin-top");
18
+ const rightValue = attrValue(pageLayoutProperties, "fo:margin-right");
19
+ const bottomValue = attrValue(pageLayoutProperties, "fo:margin-bottom");
20
+ const leftValue = attrValue(pageLayoutProperties, "fo:margin-left");
21
+ if (topValue === void 0 || rightValue === void 0 || bottomValue === void 0 || leftValue === void 0) return;
22
+ const topPt = parseOdfLength(topValue);
23
+ const rightPt = parseOdfLength(rightValue);
24
+ const bottomPt = parseOdfLength(bottomValue);
25
+ const leftPt = parseOdfLength(leftValue);
26
+ if (topPt === void 0 || rightPt === void 0 || bottomPt === void 0 || leftPt === void 0) return;
27
+ return {
28
+ topPt,
29
+ rightPt,
30
+ bottomPt,
31
+ leftPt
32
+ };
33
+ }
34
+ function parseBox(element) {
35
+ const xValue = attrValue(element, "svg:x");
36
+ const yValue = attrValue(element, "svg:y");
37
+ const widthValue = attrValue(element, "svg:width");
38
+ const heightValue = attrValue(element, "svg:height");
39
+ if (xValue === void 0 || yValue === void 0 || widthValue === void 0 || heightValue === void 0) return;
40
+ const xPt = parseOdfLength(xValue);
41
+ const yPt = parseOdfLength(yValue);
42
+ const widthPt = parseOdfLength(widthValue);
43
+ const heightPt = parseOdfLength(heightValue);
44
+ if (xPt === void 0 || yPt === void 0 || widthPt === void 0 || heightPt === void 0) return;
45
+ return {
46
+ xPt,
47
+ yPt,
48
+ widthPt,
49
+ heightPt
50
+ };
51
+ }
52
+ function parseLinePoints(element) {
53
+ const x1Value = attrValue(element, "svg:x1");
54
+ const y1Value = attrValue(element, "svg:y1");
55
+ const x2Value = attrValue(element, "svg:x2");
56
+ const y2Value = attrValue(element, "svg:y2");
57
+ if (x1Value === void 0 || y1Value === void 0 || x2Value === void 0 || y2Value === void 0) return;
58
+ const x1Pt = parseOdfLength(x1Value);
59
+ const y1Pt = parseOdfLength(y1Value);
60
+ const x2Pt = parseOdfLength(x2Value);
61
+ const y2Pt = parseOdfLength(y2Value);
62
+ if (x1Pt === void 0 || y1Pt === void 0 || x2Pt === void 0 || y2Pt === void 0) return;
63
+ return {
64
+ from: {
65
+ xPt: x1Pt,
66
+ yPt: y1Pt
67
+ },
68
+ to: {
69
+ xPt: x2Pt,
70
+ yPt: y2Pt
71
+ }
72
+ };
73
+ }
74
+ //#endregion
75
+ export { parseBox, parseLinePoints, parseMargins, parsePageSize };
@@ -0,0 +1,39 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_query = require("../../xml/query.cjs");
3
+ const require_typed_shared_geometry = require("./geometry.cjs");
4
+ //#region src/typed/shared/masterpage.ts
5
+ const STYLES_PART = "styles.xml";
6
+ const AUTOMATIC_STYLE_PARTS = ["content.xml", STYLES_PART];
7
+ function findMasterPageElement(pkg, masterPageName) {
8
+ if (masterPageName === void 0) return;
9
+ const stylesPart = pkg.parts[STYLES_PART];
10
+ if (stylesPart?.kind !== "xml") return;
11
+ const root = require_xml_query.rootElement(stylesPart.nodes);
12
+ const masterStyles = root === void 0 ? void 0 : require_xml_query.findChildElement(root.children, "office:master-styles");
13
+ if (masterStyles === void 0) return;
14
+ return require_xml_query.childrenWithTag(masterStyles, "style:master-page").find((element) => require_xml_query.attrValue(element, "style:name") === masterPageName);
15
+ }
16
+ function findPageLayoutElement(pkg, pageLayoutName) {
17
+ if (pageLayoutName === void 0) return;
18
+ for (const partPath of AUTOMATIC_STYLE_PARTS) {
19
+ const part = pkg.parts[partPath];
20
+ if (part?.kind !== "xml") continue;
21
+ const root = require_xml_query.rootElement(part.nodes);
22
+ const automaticStyles = root === void 0 ? void 0 : require_xml_query.findChildElement(root.children, "office:automatic-styles");
23
+ if (automaticStyles === void 0) continue;
24
+ const found = require_xml_query.childrenWithTag(automaticStyles, "style:page-layout").find((element) => require_xml_query.attrValue(element, "style:name") === pageLayoutName);
25
+ if (found !== void 0) return found;
26
+ }
27
+ }
28
+ function resolvePageLayoutProperties(pkg, masterPageName) {
29
+ const masterPage = findMasterPageElement(pkg, masterPageName);
30
+ const pageLayout = findPageLayoutElement(pkg, masterPage === void 0 ? void 0 : require_xml_query.attrValue(masterPage, "style:page-layout-name"));
31
+ return pageLayout === void 0 ? void 0 : require_xml_query.childrenWithTag(pageLayout, "style:page-layout-properties")[0];
32
+ }
33
+ function resolveDrawPageSize(page, pkg) {
34
+ const properties = resolvePageLayoutProperties(pkg, require_xml_query.attrValue(page, "draw:master-page-name"));
35
+ return properties === void 0 ? void 0 : require_typed_shared_geometry.parsePageSize(properties);
36
+ }
37
+ //#endregion
38
+ exports.resolveDrawPageSize = resolveDrawPageSize;
39
+ exports.resolvePageLayoutProperties = resolvePageLayoutProperties;
@@ -0,0 +1,8 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.cjs";
2
+ import { Package } from "../../model/package.cjs";
3
+ import { PageSize } from "document-schema.js";
4
+ //#region src/typed/shared/masterpage.d.ts
5
+ declare function resolvePageLayoutProperties(pkg: Package, masterPageName: string | undefined): XmlElement | undefined;
6
+ declare function resolveDrawPageSize(page: XmlElement, pkg: Package): PageSize | undefined;
7
+ //#endregion
8
+ export { resolveDrawPageSize, resolvePageLayoutProperties };
@@ -0,0 +1,8 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.js";
2
+ import { Package } from "../../model/package.js";
3
+ import { PageSize } from "document-schema.js";
4
+ //#region src/typed/shared/masterpage.d.ts
5
+ declare function resolvePageLayoutProperties(pkg: Package, masterPageName: string | undefined): XmlElement | undefined;
6
+ declare function resolveDrawPageSize(page: XmlElement, pkg: Package): PageSize | undefined;
7
+ //#endregion
8
+ export { resolveDrawPageSize, resolvePageLayoutProperties };
@@ -0,0 +1,37 @@
1
+ import { attrValue, childrenWithTag, findChildElement, rootElement } from "../../xml/query.js";
2
+ import { parsePageSize } from "./geometry.js";
3
+ //#region src/typed/shared/masterpage.ts
4
+ const STYLES_PART = "styles.xml";
5
+ const AUTOMATIC_STYLE_PARTS = ["content.xml", STYLES_PART];
6
+ function findMasterPageElement(pkg, masterPageName) {
7
+ if (masterPageName === void 0) return;
8
+ const stylesPart = pkg.parts[STYLES_PART];
9
+ if (stylesPart?.kind !== "xml") return;
10
+ const root = rootElement(stylesPart.nodes);
11
+ const masterStyles = root === void 0 ? void 0 : findChildElement(root.children, "office:master-styles");
12
+ if (masterStyles === void 0) return;
13
+ return childrenWithTag(masterStyles, "style:master-page").find((element) => attrValue(element, "style:name") === masterPageName);
14
+ }
15
+ function findPageLayoutElement(pkg, pageLayoutName) {
16
+ if (pageLayoutName === void 0) return;
17
+ for (const partPath of AUTOMATIC_STYLE_PARTS) {
18
+ const part = pkg.parts[partPath];
19
+ if (part?.kind !== "xml") continue;
20
+ const root = rootElement(part.nodes);
21
+ const automaticStyles = root === void 0 ? void 0 : findChildElement(root.children, "office:automatic-styles");
22
+ if (automaticStyles === void 0) continue;
23
+ const found = childrenWithTag(automaticStyles, "style:page-layout").find((element) => attrValue(element, "style:name") === pageLayoutName);
24
+ if (found !== void 0) return found;
25
+ }
26
+ }
27
+ function resolvePageLayoutProperties(pkg, masterPageName) {
28
+ const masterPage = findMasterPageElement(pkg, masterPageName);
29
+ const pageLayout = findPageLayoutElement(pkg, masterPage === void 0 ? void 0 : attrValue(masterPage, "style:page-layout-name"));
30
+ return pageLayout === void 0 ? void 0 : childrenWithTag(pageLayout, "style:page-layout-properties")[0];
31
+ }
32
+ function resolveDrawPageSize(page, pkg) {
33
+ const properties = resolvePageLayoutProperties(pkg, attrValue(page, "draw:master-page-name"));
34
+ return properties === void 0 ? void 0 : parsePageSize(properties);
35
+ }
36
+ //#endregion
37
+ export { resolveDrawPageSize, resolvePageLayoutProperties };