odf.js 1.12.0 → 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 +39 -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,255 @@
1
+ //#region src/typed/shared/path.ts
2
+ const VIEW_BOX_PATTERN = /^(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)$/;
3
+ function parseOdfViewBox(value) {
4
+ const match = VIEW_BOX_PATTERN.exec(value.trim());
5
+ if (match === null) return;
6
+ const minX = Number(match[1]);
7
+ const minY = Number(match[2]);
8
+ const width = Number(match[3]);
9
+ const height = Number(match[4]);
10
+ if (width <= 0 || height <= 0) return;
11
+ return {
12
+ minX,
13
+ minY,
14
+ width,
15
+ height
16
+ };
17
+ }
18
+ function parseOdfPointsList(value) {
19
+ const points = [];
20
+ for (const pair of value.trim().split(/\s+/)) {
21
+ if (pair.length === 0) continue;
22
+ const [xRaw, yRaw] = pair.split(",");
23
+ if (xRaw === void 0 || yRaw === void 0) continue;
24
+ const x = Number(xRaw);
25
+ const y = Number(yRaw);
26
+ if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
27
+ points.push({
28
+ x,
29
+ y
30
+ });
31
+ }
32
+ return points;
33
+ }
34
+ function rawSubpathFromPoints(points, closed) {
35
+ const start = points[0];
36
+ if (start === void 0) return;
37
+ return {
38
+ start,
39
+ segments: points.slice(1).map((to) => ({
40
+ kind: "line",
41
+ to
42
+ })),
43
+ closed
44
+ };
45
+ }
46
+ const COMMAND_LETTERS = /* @__PURE__ */ new Set([
47
+ "M",
48
+ "m",
49
+ "L",
50
+ "l",
51
+ "H",
52
+ "h",
53
+ "V",
54
+ "v",
55
+ "C",
56
+ "c",
57
+ "S",
58
+ "s",
59
+ "Q",
60
+ "q",
61
+ "T",
62
+ "t",
63
+ "A",
64
+ "a",
65
+ "Z",
66
+ "z"
67
+ ]);
68
+ function isCommandLetter(token) {
69
+ return COMMAND_LETTERS.has(token);
70
+ }
71
+ const PATH_TOKEN_PATTERN = /[MmLlHhVvCcSsQqTtAaZz]|-?(?:\d+\.\d+|\.\d+|\d+)(?:[eE][-+]?\d+)?/g;
72
+ function tokenizePathData(d) {
73
+ return d.match(PATH_TOKEN_PATTERN) ?? [];
74
+ }
75
+ function parseOdfPathData(d) {
76
+ const tokens = tokenizePathData(d);
77
+ const subpaths = [];
78
+ let current = {
79
+ x: 0,
80
+ y: 0
81
+ };
82
+ let subpathStart = {
83
+ x: 0,
84
+ y: 0
85
+ };
86
+ let activeSubpath;
87
+ let command;
88
+ let firstMInCommand = true;
89
+ function startSubpath(point) {
90
+ activeSubpath = {
91
+ start: point,
92
+ segments: [],
93
+ closed: false
94
+ };
95
+ subpaths.push(activeSubpath);
96
+ subpathStart = point;
97
+ current = point;
98
+ }
99
+ function pushSegment(segment, to) {
100
+ if (activeSubpath !== void 0) activeSubpath.segments.push(segment);
101
+ current = to;
102
+ }
103
+ let i = 0;
104
+ while (i < tokens.length) {
105
+ const token = tokens[i];
106
+ if (token === void 0) break;
107
+ if (isCommandLetter(token)) {
108
+ if (token === "Z" || token === "z") {
109
+ if (activeSubpath !== void 0) {
110
+ activeSubpath.closed = true;
111
+ current = subpathStart;
112
+ }
113
+ command = void 0;
114
+ i += 1;
115
+ continue;
116
+ }
117
+ command = token;
118
+ firstMInCommand = true;
119
+ i += 1;
120
+ continue;
121
+ }
122
+ if (command === void 0) {
123
+ i += 1;
124
+ continue;
125
+ }
126
+ const upper = command.toUpperCase();
127
+ const relative = command !== upper;
128
+ if (upper === "M" || upper === "L") {
129
+ const xTok = tokens[i];
130
+ const yTok = tokens[i + 1];
131
+ i += 2;
132
+ if (xTok === void 0 || yTok === void 0) break;
133
+ const x = Number(xTok);
134
+ const y = Number(yTok);
135
+ if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
136
+ const point = relative ? {
137
+ x: current.x + x,
138
+ y: current.y + y
139
+ } : {
140
+ x,
141
+ y
142
+ };
143
+ if (upper === "M" && firstMInCommand) {
144
+ startSubpath(point);
145
+ firstMInCommand = false;
146
+ } else pushSegment({
147
+ kind: "line",
148
+ to: point
149
+ }, point);
150
+ } else if (upper === "H") {
151
+ const xTok = tokens[i];
152
+ i += 1;
153
+ if (xTok === void 0) break;
154
+ const x = Number(xTok);
155
+ if (!Number.isFinite(x)) continue;
156
+ const point = relative ? {
157
+ x: current.x + x,
158
+ y: current.y
159
+ } : {
160
+ x,
161
+ y: current.y
162
+ };
163
+ pushSegment({
164
+ kind: "line",
165
+ to: point
166
+ }, point);
167
+ } else if (upper === "V") {
168
+ const yTok = tokens[i];
169
+ i += 1;
170
+ if (yTok === void 0) break;
171
+ const y = Number(yTok);
172
+ if (!Number.isFinite(y)) continue;
173
+ const point = relative ? {
174
+ x: current.x,
175
+ y: current.y + y
176
+ } : {
177
+ x: current.x,
178
+ y
179
+ };
180
+ pushSegment({
181
+ kind: "line",
182
+ to: point
183
+ }, point);
184
+ } else if (upper === "C") {
185
+ const rawArgs = tokens.slice(i, i + 6);
186
+ i += 6;
187
+ if (rawArgs.length < 6) break;
188
+ const x1 = Number(rawArgs[0]);
189
+ const y1 = Number(rawArgs[1]);
190
+ const x2 = Number(rawArgs[2]);
191
+ const y2 = Number(rawArgs[3]);
192
+ const x = Number(rawArgs[4]);
193
+ const y = Number(rawArgs[5]);
194
+ if (![
195
+ x1,
196
+ y1,
197
+ x2,
198
+ y2,
199
+ x,
200
+ y
201
+ ].every(Number.isFinite)) continue;
202
+ const control1 = relative ? {
203
+ x: current.x + x1,
204
+ y: current.y + y1
205
+ } : {
206
+ x: x1,
207
+ y: y1
208
+ };
209
+ const control2 = relative ? {
210
+ x: current.x + x2,
211
+ y: current.y + y2
212
+ } : {
213
+ x: x2,
214
+ y: y2
215
+ };
216
+ const to = relative ? {
217
+ x: current.x + x,
218
+ y: current.y + y
219
+ } : {
220
+ x,
221
+ y
222
+ };
223
+ pushSegment({
224
+ kind: "cubic",
225
+ control1,
226
+ control2,
227
+ to
228
+ }, to);
229
+ } else i += 1;
230
+ }
231
+ return subpaths;
232
+ }
233
+ function scaleOdfRawPoint(point, viewBox, frame) {
234
+ return {
235
+ xPt: (point.x - viewBox.minX) * (frame.widthPt / viewBox.width),
236
+ yPt: (point.y - viewBox.minY) * (frame.heightPt / viewBox.height)
237
+ };
238
+ }
239
+ function buildOdfSubpaths(rawSubpaths, viewBox, frame) {
240
+ return rawSubpaths.map((raw) => ({
241
+ start: scaleOdfRawPoint(raw.start, viewBox, frame),
242
+ closed: raw.closed,
243
+ segments: raw.segments.map((segment) => segment.kind === "line" ? {
244
+ kind: "line",
245
+ to: scaleOdfRawPoint(segment.to, viewBox, frame)
246
+ } : {
247
+ kind: "cubic",
248
+ control1: scaleOdfRawPoint(segment.control1, viewBox, frame),
249
+ control2: scaleOdfRawPoint(segment.control2, viewBox, frame),
250
+ to: scaleOdfRawPoint(segment.to, viewBox, frame)
251
+ })
252
+ }));
253
+ }
254
+ //#endregion
255
+ export { buildOdfSubpaths, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };
@@ -0,0 +1,8 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let document_schema_js = require("document-schema.js");
3
+ Object.defineProperty(exports, "AlignmentSchema", {
4
+ enumerable: true,
5
+ get: function() {
6
+ return document_schema_js.AlignmentSchema;
7
+ }
8
+ });
@@ -0,0 +1,2 @@
1
+ import { Alignment, AlignmentSchema } from "document-schema.js";
2
+ export { type Alignment, AlignmentSchema };
@@ -0,0 +1,2 @@
1
+ import { Alignment, AlignmentSchema } from "document-schema.js";
2
+ export { type Alignment, AlignmentSchema };
@@ -0,0 +1,2 @@
1
+ import { AlignmentSchema } from "document-schema.js";
2
+ export { AlignmentSchema };
@@ -0,0 +1,84 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_typed_shared_units = require("./units.cjs");
3
+ const require_typed_shared_color = require("./color.cjs");
4
+ const require_xml_query = require("../../xml/query.cjs");
5
+ const require_typed_shared_cascade = require("./cascade.cjs");
6
+ const require_typed_shared_paragraph = require("./paragraph.cjs");
7
+ //#region src/typed/shared/table.ts
8
+ function readRepeatCount(element, attrName) {
9
+ const raw = require_xml_query.attrValue(element, attrName);
10
+ if (raw === void 0) return 1;
11
+ const parsed = Number.parseInt(raw, 10);
12
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
13
+ }
14
+ function resolveColumnWidthPt(columnElement, pkg) {
15
+ const styleName = require_xml_query.attrValue(columnElement, "table:style-name");
16
+ const styleElement = styleName === void 0 ? void 0 : require_typed_shared_cascade.findStyleElement(styleName, "table-column", pkg);
17
+ const props = styleElement === void 0 ? void 0 : require_xml_query.childrenWithTag(styleElement, "style:table-column-properties")[0];
18
+ const widthValue = props === void 0 ? void 0 : require_xml_query.attrValue(props, "style:column-width");
19
+ return widthValue === void 0 ? 0 : require_typed_shared_units.parseOdfLength(widthValue) ?? 0;
20
+ }
21
+ function resolveRowHeightPt(rowElement, pkg) {
22
+ const styleName = require_xml_query.attrValue(rowElement, "table:style-name");
23
+ const styleElement = styleName === void 0 ? void 0 : require_typed_shared_cascade.findStyleElement(styleName, "table-row", pkg);
24
+ const props = styleElement === void 0 ? void 0 : require_xml_query.childrenWithTag(styleElement, "style:table-row-properties")[0];
25
+ const heightValue = props === void 0 ? void 0 : require_xml_query.attrValue(props, "style:row-height");
26
+ return heightValue === void 0 ? void 0 : require_typed_shared_units.parseOdfLength(heightValue);
27
+ }
28
+ function readTableCellBackground(cellElement, pkg) {
29
+ const styleName = require_xml_query.attrValue(cellElement, "table:style-name");
30
+ const styleElement = styleName === void 0 ? void 0 : require_typed_shared_cascade.findStyleElement(styleName, "table-cell", pkg);
31
+ const props = styleElement === void 0 ? void 0 : require_xml_query.childrenWithTag(styleElement, "style:table-cell-properties")[0];
32
+ const value = props === void 0 ? void 0 : require_xml_query.attrValue(props, "fo:background-color");
33
+ return value === void 0 ? void 0 : require_typed_shared_color.parseOdfColor(value);
34
+ }
35
+ function readTableCell(cellElement, pkg) {
36
+ const blocks = require_xml_query.childrenWithTag(cellElement, "text:p").map((p) => require_typed_shared_paragraph.readOdfParagraph(p, pkg));
37
+ const colSpanRaw = require_xml_query.attrValue(cellElement, "table:number-columns-spanned");
38
+ const rowSpanRaw = require_xml_query.attrValue(cellElement, "table:number-rows-spanned");
39
+ return {
40
+ blocks,
41
+ colSpan: colSpanRaw === void 0 ? void 0 : Number.parseInt(colSpanRaw, 10),
42
+ rowSpan: rowSpanRaw === void 0 ? void 0 : Number.parseInt(rowSpanRaw, 10),
43
+ background: readTableCellBackground(cellElement, pkg)
44
+ };
45
+ }
46
+ function readTableRow(rowElement, pkg) {
47
+ const cells = [];
48
+ for (const child of rowElement.children) {
49
+ if (child.type !== "element") continue;
50
+ if (child.tag === "table:covered-table-cell") {
51
+ const repeat = readRepeatCount(child, "table:number-columns-repeated");
52
+ for (let i = 0; i < repeat; i++) cells.push({ blocks: [] });
53
+ } else if (child.tag === "table:table-cell") {
54
+ const cell = readTableCell(child, pkg);
55
+ const repeat = readRepeatCount(child, "table:number-columns-repeated");
56
+ for (let i = 0; i < repeat; i++) cells.push(cell);
57
+ }
58
+ }
59
+ return {
60
+ cells,
61
+ heightPt: resolveRowHeightPt(rowElement, pkg)
62
+ };
63
+ }
64
+ function readOdfTable(tableElement, pkg) {
65
+ const columnWidthsPt = [];
66
+ for (const column of require_xml_query.childrenWithTag(tableElement, "table:table-column")) {
67
+ const widthPt = resolveColumnWidthPt(column, pkg);
68
+ const repeat = readRepeatCount(column, "table:number-columns-repeated");
69
+ for (let i = 0; i < repeat; i++) columnWidthsPt.push(widthPt);
70
+ }
71
+ const rows = [];
72
+ for (const rowElement of require_xml_query.childrenWithTag(tableElement, "table:table-row")) {
73
+ const row = readTableRow(rowElement, pkg);
74
+ const repeat = readRepeatCount(rowElement, "table:number-rows-repeated");
75
+ for (let i = 0; i < repeat; i++) rows.push(row);
76
+ }
77
+ return {
78
+ kind: "table",
79
+ rows,
80
+ columnWidthsPt
81
+ };
82
+ }
83
+ //#endregion
84
+ exports.readOdfTable = readOdfTable;
@@ -0,0 +1,7 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.cjs";
2
+ import { Package } from "../../model/package.cjs";
3
+ import { ContentTable } from "document-schema.js";
4
+ //#region src/typed/shared/table.d.ts
5
+ declare function readOdfTable(tableElement: XmlElement, pkg: Package): ContentTable;
6
+ //#endregion
7
+ export { readOdfTable };
@@ -0,0 +1,7 @@
1
+ import { l as XmlElement } from "../../node-CkBWRjNR.js";
2
+ import { Package } from "../../model/package.js";
3
+ import { ContentTable } from "document-schema.js";
4
+ //#region src/typed/shared/table.d.ts
5
+ declare function readOdfTable(tableElement: XmlElement, pkg: Package): ContentTable;
6
+ //#endregion
7
+ export { readOdfTable };
@@ -0,0 +1,83 @@
1
+ import { parseOdfLength } from "./units.js";
2
+ import { parseOdfColor } from "./color.js";
3
+ import { attrValue, childrenWithTag } from "../../xml/query.js";
4
+ import { findStyleElement } from "./cascade.js";
5
+ import { readOdfParagraph } from "./paragraph.js";
6
+ //#region src/typed/shared/table.ts
7
+ function readRepeatCount(element, attrName) {
8
+ const raw = attrValue(element, attrName);
9
+ if (raw === void 0) return 1;
10
+ const parsed = Number.parseInt(raw, 10);
11
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
12
+ }
13
+ function resolveColumnWidthPt(columnElement, pkg) {
14
+ const styleName = attrValue(columnElement, "table:style-name");
15
+ const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-column", pkg);
16
+ const props = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-column-properties")[0];
17
+ const widthValue = props === void 0 ? void 0 : attrValue(props, "style:column-width");
18
+ return widthValue === void 0 ? 0 : parseOdfLength(widthValue) ?? 0;
19
+ }
20
+ function resolveRowHeightPt(rowElement, pkg) {
21
+ const styleName = attrValue(rowElement, "table:style-name");
22
+ const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-row", pkg);
23
+ const props = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-row-properties")[0];
24
+ const heightValue = props === void 0 ? void 0 : attrValue(props, "style:row-height");
25
+ return heightValue === void 0 ? void 0 : parseOdfLength(heightValue);
26
+ }
27
+ function readTableCellBackground(cellElement, pkg) {
28
+ const styleName = attrValue(cellElement, "table:style-name");
29
+ const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-cell", pkg);
30
+ const props = styleElement === void 0 ? void 0 : childrenWithTag(styleElement, "style:table-cell-properties")[0];
31
+ const value = props === void 0 ? void 0 : attrValue(props, "fo:background-color");
32
+ return value === void 0 ? void 0 : parseOdfColor(value);
33
+ }
34
+ function readTableCell(cellElement, pkg) {
35
+ const blocks = childrenWithTag(cellElement, "text:p").map((p) => readOdfParagraph(p, pkg));
36
+ const colSpanRaw = attrValue(cellElement, "table:number-columns-spanned");
37
+ const rowSpanRaw = attrValue(cellElement, "table:number-rows-spanned");
38
+ return {
39
+ blocks,
40
+ colSpan: colSpanRaw === void 0 ? void 0 : Number.parseInt(colSpanRaw, 10),
41
+ rowSpan: rowSpanRaw === void 0 ? void 0 : Number.parseInt(rowSpanRaw, 10),
42
+ background: readTableCellBackground(cellElement, pkg)
43
+ };
44
+ }
45
+ function readTableRow(rowElement, pkg) {
46
+ const cells = [];
47
+ for (const child of rowElement.children) {
48
+ if (child.type !== "element") continue;
49
+ if (child.tag === "table:covered-table-cell") {
50
+ const repeat = readRepeatCount(child, "table:number-columns-repeated");
51
+ for (let i = 0; i < repeat; i++) cells.push({ blocks: [] });
52
+ } else if (child.tag === "table:table-cell") {
53
+ const cell = readTableCell(child, pkg);
54
+ const repeat = readRepeatCount(child, "table:number-columns-repeated");
55
+ for (let i = 0; i < repeat; i++) cells.push(cell);
56
+ }
57
+ }
58
+ return {
59
+ cells,
60
+ heightPt: resolveRowHeightPt(rowElement, pkg)
61
+ };
62
+ }
63
+ function readOdfTable(tableElement, pkg) {
64
+ const columnWidthsPt = [];
65
+ for (const column of childrenWithTag(tableElement, "table:table-column")) {
66
+ const widthPt = resolveColumnWidthPt(column, pkg);
67
+ const repeat = readRepeatCount(column, "table:number-columns-repeated");
68
+ for (let i = 0; i < repeat; i++) columnWidthsPt.push(widthPt);
69
+ }
70
+ const rows = [];
71
+ for (const rowElement of childrenWithTag(tableElement, "table:table-row")) {
72
+ const row = readTableRow(rowElement, pkg);
73
+ const repeat = readRepeatCount(rowElement, "table:number-rows-repeated");
74
+ for (let i = 0; i < repeat; i++) rows.push(row);
75
+ }
76
+ return {
77
+ kind: "table",
78
+ rows,
79
+ columnWidthsPt
80
+ };
81
+ }
82
+ //#endregion
83
+ export { readOdfTable };
@@ -0,0 +1,43 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_entities = require("../../xml/entities.cjs");
3
+ const require_xml_query = require("../../xml/query.cjs");
4
+ //#region src/typed/shared/text.ts
5
+ function getOdfSpaceCount(element) {
6
+ const raw = require_xml_query.attrValue(element, "text:c");
7
+ if (raw === void 0) return 1;
8
+ const parsed = Number.parseInt(raw, 10);
9
+ if (!Number.isInteger(parsed) || parsed < 0 || String(parsed) !== raw) throw new Error(`getOdfSpaceCount: text:s has a malformed text:c attribute: "${raw}"`);
10
+ return parsed;
11
+ }
12
+ function measureOdfNodeLength(node) {
13
+ if (node.type === "text") return node.value.length;
14
+ if (node.type !== "element") return 0;
15
+ if (node.tag === "text:s") return getOdfSpaceCount(node);
16
+ if (node.tag === "text:tab" || node.tag === "text:line-break") return 1;
17
+ if (node.tag === "text:span") return sumOdfNodeLength(node.children);
18
+ return 0;
19
+ }
20
+ function sumOdfNodeLength(nodes) {
21
+ let total = 0;
22
+ for (const node of nodes) total += measureOdfNodeLength(node);
23
+ return total;
24
+ }
25
+ function decodeOdfNode(node) {
26
+ if (node.type === "text") return require_xml_entities.decodeXmlText(node.value);
27
+ if (node.type !== "element") return "";
28
+ if (node.tag === "text:s") return " ".repeat(getOdfSpaceCount(node));
29
+ if (node.tag === "text:tab") return " ";
30
+ if (node.tag === "text:line-break") return "\n";
31
+ if (node.tag === "text:span") return decodeOdfText(node);
32
+ return "";
33
+ }
34
+ function decodeOdfText(container) {
35
+ let text = "";
36
+ for (const child of container.children) text += decodeOdfNode(child);
37
+ return text;
38
+ }
39
+ //#endregion
40
+ exports.decodeOdfText = decodeOdfText;
41
+ exports.getOdfSpaceCount = getOdfSpaceCount;
42
+ exports.measureOdfNodeLength = measureOdfNodeLength;
43
+ exports.sumOdfNodeLength = sumOdfNodeLength;
@@ -0,0 +1,8 @@
1
+ import { d as XmlNode, l as XmlElement } from "../../node-CkBWRjNR.cjs";
2
+ //#region src/typed/shared/text.d.ts
3
+ declare function getOdfSpaceCount(element: XmlElement): number;
4
+ declare function measureOdfNodeLength(node: XmlNode): number;
5
+ declare function sumOdfNodeLength(nodes: readonly XmlNode[]): number;
6
+ declare function decodeOdfText(container: XmlElement): string;
7
+ //#endregion
8
+ export { decodeOdfText, getOdfSpaceCount, measureOdfNodeLength, sumOdfNodeLength };
@@ -0,0 +1,8 @@
1
+ import { d as XmlNode, l as XmlElement } from "../../node-CkBWRjNR.js";
2
+ //#region src/typed/shared/text.d.ts
3
+ declare function getOdfSpaceCount(element: XmlElement): number;
4
+ declare function measureOdfNodeLength(node: XmlNode): number;
5
+ declare function sumOdfNodeLength(nodes: readonly XmlNode[]): number;
6
+ declare function decodeOdfText(container: XmlElement): string;
7
+ //#endregion
8
+ export { decodeOdfText, getOdfSpaceCount, measureOdfNodeLength, sumOdfNodeLength };
@@ -0,0 +1,39 @@
1
+ import { decodeXmlText } from "../../xml/entities.js";
2
+ import { attrValue } from "../../xml/query.js";
3
+ //#region src/typed/shared/text.ts
4
+ function getOdfSpaceCount(element) {
5
+ const raw = attrValue(element, "text:c");
6
+ if (raw === void 0) return 1;
7
+ const parsed = Number.parseInt(raw, 10);
8
+ if (!Number.isInteger(parsed) || parsed < 0 || String(parsed) !== raw) throw new Error(`getOdfSpaceCount: text:s has a malformed text:c attribute: "${raw}"`);
9
+ return parsed;
10
+ }
11
+ function measureOdfNodeLength(node) {
12
+ if (node.type === "text") return node.value.length;
13
+ if (node.type !== "element") return 0;
14
+ if (node.tag === "text:s") return getOdfSpaceCount(node);
15
+ if (node.tag === "text:tab" || node.tag === "text:line-break") return 1;
16
+ if (node.tag === "text:span") return sumOdfNodeLength(node.children);
17
+ return 0;
18
+ }
19
+ function sumOdfNodeLength(nodes) {
20
+ let total = 0;
21
+ for (const node of nodes) total += measureOdfNodeLength(node);
22
+ return total;
23
+ }
24
+ function decodeOdfNode(node) {
25
+ if (node.type === "text") return decodeXmlText(node.value);
26
+ if (node.type !== "element") return "";
27
+ if (node.tag === "text:s") return " ".repeat(getOdfSpaceCount(node));
28
+ if (node.tag === "text:tab") return " ";
29
+ if (node.tag === "text:line-break") return "\n";
30
+ if (node.tag === "text:span") return decodeOdfText(node);
31
+ return "";
32
+ }
33
+ function decodeOdfText(container) {
34
+ let text = "";
35
+ for (const child of container.children) text += decodeOdfNode(child);
36
+ return text;
37
+ }
38
+ //#endregion
39
+ export { decodeOdfText, getOdfSpaceCount, measureOdfNodeLength, sumOdfNodeLength };
@@ -0,0 +1,112 @@
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
+ const require_typed_shared_geometry = require("./geometry.cjs");
5
+ //#region src/typed/shared/transform.ts
6
+ const FUNCTION_PATTERN = /([a-zA-Z]+)\s*\(\s*([^)]*?)\s*\)/g;
7
+ function parseOdfTransform(value) {
8
+ const functions = [];
9
+ for (const match of value.matchAll(FUNCTION_PATTERN)) {
10
+ const name = match[1];
11
+ const argsRaw = match[2];
12
+ if (name === void 0 || argsRaw === void 0) continue;
13
+ const args = argsRaw.split(/\s+/).filter((arg) => arg.length > 0);
14
+ if (name === "rotate") {
15
+ const angleArg = args[0];
16
+ if (angleArg === void 0) continue;
17
+ const angleRad = Number(angleArg);
18
+ if (!Number.isFinite(angleRad)) continue;
19
+ functions.push({
20
+ kind: "rotate",
21
+ angleRad
22
+ });
23
+ } else if (name === "translate") {
24
+ const xArg = args[0];
25
+ if (xArg === void 0) continue;
26
+ const yArg = args[1];
27
+ const xPt = require_typed_shared_units.parseOdfLength(xArg);
28
+ const yPt = yArg === void 0 ? 0 : require_typed_shared_units.parseOdfLength(yArg);
29
+ if (xPt === void 0 || yPt === void 0) continue;
30
+ functions.push({
31
+ kind: "translate",
32
+ xPt,
33
+ yPt
34
+ });
35
+ }
36
+ }
37
+ return functions;
38
+ }
39
+ function applyOdfTransform(functions, point) {
40
+ let current = point;
41
+ for (const fn of functions) if (fn.kind === "rotate") {
42
+ const cos = Math.cos(fn.angleRad);
43
+ const sin = Math.sin(fn.angleRad);
44
+ current = {
45
+ xPt: current.xPt * cos + current.yPt * sin,
46
+ yPt: current.yPt * cos - current.xPt * sin
47
+ };
48
+ } else current = {
49
+ xPt: current.xPt + fn.xPt,
50
+ yPt: current.yPt + fn.yPt
51
+ };
52
+ return current;
53
+ }
54
+ function netRotationDeg(functions) {
55
+ let totalRad = 0;
56
+ for (const fn of functions) if (fn.kind === "rotate") totalRad += fn.angleRad;
57
+ return -totalRad * 180 / Math.PI;
58
+ }
59
+ function resolveOdfShapeGeometry(element) {
60
+ const transformValue = require_xml_query.attrValue(element, "draw:transform");
61
+ if (transformValue === void 0) {
62
+ const box = require_typed_shared_geometry.parseBox(element);
63
+ return box === void 0 ? void 0 : {
64
+ frame: box,
65
+ rotationDeg: void 0
66
+ };
67
+ }
68
+ const widthValue = require_xml_query.attrValue(element, "svg:width");
69
+ const heightValue = require_xml_query.attrValue(element, "svg:height");
70
+ if (widthValue === void 0 || heightValue === void 0) return;
71
+ const widthPt = require_typed_shared_units.parseOdfLength(widthValue);
72
+ const heightPt = require_typed_shared_units.parseOdfLength(heightValue);
73
+ if (widthPt === void 0 || heightPt === void 0) return;
74
+ const functions = parseOdfTransform(transformValue);
75
+ const center = applyOdfTransform(functions, {
76
+ xPt: widthPt / 2,
77
+ yPt: heightPt / 2
78
+ });
79
+ const rotationDeg = netRotationDeg(functions);
80
+ return {
81
+ frame: {
82
+ xPt: center.xPt - widthPt / 2,
83
+ yPt: center.yPt - heightPt / 2,
84
+ widthPt,
85
+ heightPt
86
+ },
87
+ rotationDeg: rotationDeg === 0 ? void 0 : rotationDeg
88
+ };
89
+ }
90
+ function composeOdfGroupTransform(groupFunctions, child) {
91
+ if (groupFunctions.length === 0) return child;
92
+ const newCenter = applyOdfTransform(groupFunctions, {
93
+ xPt: child.frame.xPt + child.frame.widthPt / 2,
94
+ yPt: child.frame.yPt + child.frame.heightPt / 2
95
+ });
96
+ const newRotationDeg = (child.rotationDeg ?? 0) + netRotationDeg(groupFunctions);
97
+ return {
98
+ frame: {
99
+ xPt: newCenter.xPt - child.frame.widthPt / 2,
100
+ yPt: newCenter.yPt - child.frame.heightPt / 2,
101
+ widthPt: child.frame.widthPt,
102
+ heightPt: child.frame.heightPt
103
+ },
104
+ rotationDeg: newRotationDeg === 0 ? void 0 : newRotationDeg
105
+ };
106
+ }
107
+ //#endregion
108
+ exports.applyOdfTransform = applyOdfTransform;
109
+ exports.composeOdfGroupTransform = composeOdfGroupTransform;
110
+ exports.netRotationDeg = netRotationDeg;
111
+ exports.parseOdfTransform = parseOdfTransform;
112
+ exports.resolveOdfShapeGeometry = resolveOdfShapeGeometry;