odf.js 1.13.2 → 2.1.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 +19 -4
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +7 -3
- package/dist/ns.cjs +2 -1
- package/dist/ns.d.cts +1 -0
- package/dist/ns.d.ts +1 -0
- package/dist/ns.js +2 -1
- package/dist/typed/draw/embedded.cjs +42 -0
- package/dist/typed/draw/embedded.d.cts +13 -0
- package/dist/typed/draw/embedded.d.ts +13 -0
- package/dist/typed/draw/embedded.js +41 -0
- package/dist/typed/draw/shapes.cjs +86 -30
- package/dist/typed/draw/shapes.d.cts +4 -1
- package/dist/typed/draw/shapes.d.ts +4 -1
- package/dist/typed/draw/shapes.js +86 -30
- package/dist/typed/formula/read.cjs +14 -0
- package/dist/typed/formula/read.d.cts +3 -2
- package/dist/typed/formula/read.d.ts +3 -2
- package/dist/typed/formula/read.js +14 -1
- package/dist/typed/odb/form.cjs +85 -0
- package/dist/typed/odb/form.d.cts +31 -0
- package/dist/typed/odb/form.d.ts +31 -0
- package/dist/typed/odb/form.js +84 -0
- package/dist/typed/odb/read.cjs +60 -23
- package/dist/typed/odb/read.d.cts +15 -4
- package/dist/typed/odb/read.d.ts +15 -4
- package/dist/typed/odb/read.js +60 -24
- package/dist/typed/odb/report.cjs +161 -0
- package/dist/typed/odb/report.d.cts +48 -0
- package/dist/typed/odb/report.d.ts +48 -0
- package/dist/typed/odb/report.js +160 -0
- package/dist/typed/odb/subdocument.cjs +16 -0
- package/dist/typed/odb/subdocument.d.cts +8 -0
- package/dist/typed/odb/subdocument.d.ts +8 -0
- package/dist/typed/odb/subdocument.js +15 -0
- package/dist/typed/ods/read.cjs +98 -4
- package/dist/typed/ods/read.js +100 -6
- package/dist/typed/shared/table.cjs +94 -7
- package/dist/typed/shared/table.d.cts +9 -2
- package/dist/typed/shared/table.d.ts +9 -2
- package/dist/typed/shared/table.js +94 -8
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ const require_image_sniff = require("../../image/sniff.cjs");
|
|
|
4
4
|
const require_typed_shared_units = require("../shared/units.cjs");
|
|
5
5
|
const require_typed_shared_color = require("../shared/color.cjs");
|
|
6
6
|
const require_xml_query = require("../../xml/query.cjs");
|
|
7
|
+
const require_typed_shared_text = require("../shared/text.cjs");
|
|
7
8
|
const require_typed_shared_geometry = require("../shared/geometry.cjs");
|
|
8
9
|
const require_typed_shared_cascade = require("../shared/cascade.cjs");
|
|
9
10
|
const require_typed_shared_paragraph = require("../shared/paragraph.cjs");
|
|
@@ -37,20 +38,31 @@ function readFrameInsets(frame, pkg) {
|
|
|
37
38
|
}
|
|
38
39
|
return insets;
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
+
function readFrameAltText(frame) {
|
|
42
|
+
const title = require_xml_query.childrenWithTag(frame, "svg:title")[0];
|
|
43
|
+
const decodedTitle = title === void 0 ? void 0 : require_typed_shared_text.decodeOdfText(title);
|
|
44
|
+
if (decodedTitle !== void 0 && decodedTitle.length > 0) return decodedTitle;
|
|
45
|
+
const description = require_xml_query.childrenWithTag(frame, "svg:desc")[0];
|
|
46
|
+
const decodedDescription = description === void 0 ? void 0 : require_typed_shared_text.decodeOdfText(description);
|
|
47
|
+
return decodedDescription !== void 0 && decodedDescription.length > 0 ? decodedDescription : void 0;
|
|
48
|
+
}
|
|
49
|
+
function readDrawImageBlock(image, frame, frameBox, pkg) {
|
|
41
50
|
const href = require_xml_query.attrValue(image, "xlink:href");
|
|
42
51
|
const part = href === void 0 ? void 0 : pkg.parts[href];
|
|
43
52
|
if (part?.kind !== "binary") return;
|
|
44
53
|
const bytes = require_util_base64.base64ToBytes(part.base64);
|
|
45
54
|
const format = require_image_sniff.sniffImageFormat(bytes);
|
|
46
55
|
if (format === void 0) return;
|
|
47
|
-
|
|
56
|
+
const block = {
|
|
48
57
|
kind: "image",
|
|
49
58
|
format,
|
|
50
59
|
base64: part.base64,
|
|
51
60
|
widthPt: frameBox.widthPt,
|
|
52
61
|
heightPt: frameBox.heightPt
|
|
53
62
|
};
|
|
63
|
+
const altText = readFrameAltText(frame);
|
|
64
|
+
if (altText !== void 0) block.altText = altText;
|
|
65
|
+
return block;
|
|
54
66
|
}
|
|
55
67
|
function readDrawFrameContent(frame, frameBox, pkg) {
|
|
56
68
|
const table = require_xml_query.childrenWithTag(frame, "table:table")[0];
|
|
@@ -59,7 +71,7 @@ function readDrawFrameContent(frame, frameBox, pkg) {
|
|
|
59
71
|
if (textBox !== void 0) return require_xml_query.elementsWithTag(textBox.children, "text:p").map((p) => require_typed_shared_paragraph.readOdfParagraph(p, pkg));
|
|
60
72
|
const image = require_xml_query.childrenWithTag(frame, "draw:image")[0];
|
|
61
73
|
if (image !== void 0) {
|
|
62
|
-
const block = readDrawImageBlock(image, frameBox, pkg);
|
|
74
|
+
const block = readDrawImageBlock(image, frame, frameBox, pkg);
|
|
63
75
|
return block === void 0 ? [] : [block];
|
|
64
76
|
}
|
|
65
77
|
return [];
|
|
@@ -80,16 +92,20 @@ function readOwnTransformFunctions(element) {
|
|
|
80
92
|
const value = require_xml_query.attrValue(element, "draw:transform");
|
|
81
93
|
return value === void 0 ? [] : require_typed_shared_transform.parseOdfTransform(value);
|
|
82
94
|
}
|
|
83
|
-
function walkDrawShapes(children, groupFunctions, pkg, out) {
|
|
95
|
+
function walkDrawShapes(children, groupFunctions, pkg, out, indexState = { next: 0 }) {
|
|
84
96
|
for (const node of children) {
|
|
85
97
|
if (node.type !== "element") continue;
|
|
86
98
|
if (node.tag === "draw:frame") {
|
|
99
|
+
const zIndex = paintOrderKey(node, indexState);
|
|
87
100
|
const shape = readDrawFrame(node, groupFunctions, pkg);
|
|
88
|
-
if (shape !== void 0) out.push(
|
|
101
|
+
if (shape !== void 0) out.push({
|
|
102
|
+
...shape,
|
|
103
|
+
paintOrder: zIndex
|
|
104
|
+
});
|
|
89
105
|
} else if (node.tag === "draw:g") {
|
|
90
106
|
const ownFunctions = readOwnTransformFunctions(node);
|
|
91
107
|
const nested = ownFunctions.length === 0 ? groupFunctions : [...ownFunctions, ...groupFunctions];
|
|
92
|
-
walkDrawShapes(node.children, nested, pkg, out);
|
|
108
|
+
walkDrawShapes(node.children, nested, pkg, out, indexState);
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
}
|
|
@@ -97,7 +113,9 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
97
113
|
const styleName = require_xml_query.attrValue(element, "draw:style-name");
|
|
98
114
|
const { elements } = require_typed_shared_cascade.resolveStyleElementChain(styleName, "graphic", pkg);
|
|
99
115
|
let fill;
|
|
116
|
+
let fillRule;
|
|
100
117
|
let stroke;
|
|
118
|
+
let strokeStyle;
|
|
101
119
|
for (const styleElement of elements) {
|
|
102
120
|
const props = require_xml_query.childrenWithTag(styleElement, "style:graphic-properties")[0];
|
|
103
121
|
if (props === void 0) continue;
|
|
@@ -107,8 +125,15 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
107
125
|
const parsedFill = fillColorValue === void 0 ? void 0 : require_typed_shared_color.parseOdfColor(fillColorValue);
|
|
108
126
|
if (parsedFill !== void 0) fill = parsedFill;
|
|
109
127
|
}
|
|
110
|
-
|
|
111
|
-
|
|
128
|
+
const fillRuleValue = require_xml_query.attrValue(props, "svg:fill-rule");
|
|
129
|
+
if (fillRuleValue === "nonzero" || fillRuleValue === "evenodd") fillRule = fillRuleValue;
|
|
130
|
+
const strokeMode = require_xml_query.attrValue(props, "draw:stroke");
|
|
131
|
+
if (strokeMode === "none") {
|
|
132
|
+
stroke = void 0;
|
|
133
|
+
strokeStyle = void 0;
|
|
134
|
+
} else {
|
|
135
|
+
if (strokeMode === "dash") strokeStyle = "dashed";
|
|
136
|
+
else if (strokeMode === "solid") strokeStyle = "solid";
|
|
112
137
|
const strokeColorValue = require_xml_query.attrValue(props, "svg:stroke-color");
|
|
113
138
|
const strokeWidthValue = require_xml_query.attrValue(props, "svg:stroke-width");
|
|
114
139
|
const strokeColor = strokeColorValue === void 0 ? void 0 : require_typed_shared_color.parseOdfColor(strokeColorValue);
|
|
@@ -121,32 +146,38 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
121
146
|
}
|
|
122
147
|
return {
|
|
123
148
|
fill,
|
|
124
|
-
|
|
149
|
+
fillRule,
|
|
150
|
+
stroke: stroke === void 0 || strokeStyle === void 0 ? stroke : {
|
|
151
|
+
...stroke,
|
|
152
|
+
style: strokeStyle
|
|
153
|
+
}
|
|
125
154
|
};
|
|
126
155
|
}
|
|
127
|
-
function
|
|
156
|
+
function resolveVectorGeometry(element, groupFunctions) {
|
|
128
157
|
const geometry = require_typed_shared_transform.resolveOdfShapeGeometry(element);
|
|
129
158
|
if (geometry === void 0) return;
|
|
130
|
-
return require_typed_shared_transform.composeOdfGroupTransform(groupFunctions, geometry)
|
|
159
|
+
return require_typed_shared_transform.composeOdfGroupTransform(groupFunctions, geometry);
|
|
131
160
|
}
|
|
132
161
|
function readDrawRectVector(element, groupFunctions, pkg) {
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
162
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
163
|
+
if (geometry === void 0) return;
|
|
135
164
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
136
165
|
return {
|
|
137
166
|
kind: "rect",
|
|
138
|
-
frame,
|
|
167
|
+
frame: geometry.frame,
|
|
168
|
+
rotationDeg: geometry.rotationDeg,
|
|
139
169
|
fill,
|
|
140
170
|
stroke
|
|
141
171
|
};
|
|
142
172
|
}
|
|
143
173
|
function readDrawEllipseVector(element, groupFunctions, pkg) {
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
174
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
175
|
+
if (geometry === void 0) return;
|
|
146
176
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
147
177
|
return {
|
|
148
178
|
kind: "ellipse",
|
|
149
|
-
frame,
|
|
179
|
+
frame: geometry.frame,
|
|
180
|
+
rotationDeg: geometry.rotationDeg,
|
|
150
181
|
fill,
|
|
151
182
|
stroke
|
|
152
183
|
};
|
|
@@ -166,8 +197,9 @@ function readDrawLineVector(element, groupFunctions, pkg) {
|
|
|
166
197
|
};
|
|
167
198
|
}
|
|
168
199
|
function readDrawPathVector(element, groupFunctions, pkg) {
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
200
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
201
|
+
if (geometry === void 0) return;
|
|
202
|
+
const frame = geometry.frame;
|
|
171
203
|
const viewBoxValue = require_xml_query.attrValue(element, "svg:viewBox");
|
|
172
204
|
const viewBox = viewBoxValue === void 0 ? void 0 : require_typed_shared_path.parseOdfViewBox(viewBoxValue);
|
|
173
205
|
if (viewBox === void 0) return;
|
|
@@ -183,12 +215,14 @@ function readDrawPathVector(element, groupFunctions, pkg) {
|
|
|
183
215
|
}
|
|
184
216
|
if (rawSubpaths.length === 0) return;
|
|
185
217
|
const subpaths = require_typed_shared_path.buildOdfSubpaths(rawSubpaths, viewBox, frame);
|
|
186
|
-
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
218
|
+
const { fill, fillRule, stroke } = readOdfFillAndStroke(element, pkg);
|
|
187
219
|
return {
|
|
188
220
|
kind: "path",
|
|
189
221
|
frame,
|
|
222
|
+
rotationDeg: geometry.rotationDeg,
|
|
190
223
|
subpaths,
|
|
191
224
|
fill,
|
|
225
|
+
fillRule,
|
|
192
226
|
stroke
|
|
193
227
|
};
|
|
194
228
|
}
|
|
@@ -201,12 +235,13 @@ function readCustomShapeVector(element, groupFunctions, pkg) {
|
|
|
201
235
|
const geometryElement = require_xml_query.childrenWithTag(element, "draw:enhanced-geometry")[0];
|
|
202
236
|
const type = geometryElement === void 0 ? void 0 : require_xml_query.attrValue(geometryElement, "draw:type");
|
|
203
237
|
if (type === void 0 || !RECOGNIZED_CUSTOM_SHAPE_PRESETS.has(type)) return;
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
238
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
239
|
+
if (geometry === void 0) return;
|
|
206
240
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
207
241
|
return {
|
|
208
242
|
kind: type === "ellipse" ? "ellipse" : "rect",
|
|
209
|
-
frame,
|
|
243
|
+
frame: geometry.frame,
|
|
244
|
+
rotationDeg: geometry.rotationDeg,
|
|
210
245
|
fill,
|
|
211
246
|
stroke
|
|
212
247
|
};
|
|
@@ -247,7 +282,10 @@ function walkDrawPageContent(children, groupFunctions, pkg, indexState, shapesOu
|
|
|
247
282
|
const zIndex = paintOrderKey(node, indexState);
|
|
248
283
|
const shape = readDrawFrame(node, groupFunctions, pkg);
|
|
249
284
|
if (shape !== void 0) shapesOut.push({
|
|
250
|
-
value:
|
|
285
|
+
value: {
|
|
286
|
+
...shape,
|
|
287
|
+
paintOrder: zIndex
|
|
288
|
+
},
|
|
251
289
|
zIndex
|
|
252
290
|
});
|
|
253
291
|
} else if (node.tag === "draw:g") {
|
|
@@ -258,41 +296,59 @@ function walkDrawPageContent(children, groupFunctions, pkg, indexState, shapesOu
|
|
|
258
296
|
const zIndex = paintOrderKey(node, indexState);
|
|
259
297
|
const vector = readDrawRectVector(node, groupFunctions, pkg);
|
|
260
298
|
if (vector !== void 0) vectorsOut.push({
|
|
261
|
-
value:
|
|
299
|
+
value: {
|
|
300
|
+
...vector,
|
|
301
|
+
paintOrder: zIndex
|
|
302
|
+
},
|
|
262
303
|
zIndex
|
|
263
304
|
});
|
|
264
305
|
} else if (node.tag === "draw:ellipse" || node.tag === "draw:circle") {
|
|
265
306
|
const zIndex = paintOrderKey(node, indexState);
|
|
266
307
|
const vector = readDrawEllipseVector(node, groupFunctions, pkg);
|
|
267
308
|
if (vector !== void 0) vectorsOut.push({
|
|
268
|
-
value:
|
|
309
|
+
value: {
|
|
310
|
+
...vector,
|
|
311
|
+
paintOrder: zIndex
|
|
312
|
+
},
|
|
269
313
|
zIndex
|
|
270
314
|
});
|
|
271
315
|
} else if (node.tag === "draw:line") {
|
|
272
316
|
const zIndex = paintOrderKey(node, indexState);
|
|
273
317
|
const vector = readDrawLineVector(node, groupFunctions, pkg);
|
|
274
318
|
if (vector !== void 0) vectorsOut.push({
|
|
275
|
-
value:
|
|
319
|
+
value: {
|
|
320
|
+
...vector,
|
|
321
|
+
paintOrder: zIndex
|
|
322
|
+
},
|
|
276
323
|
zIndex
|
|
277
324
|
});
|
|
278
325
|
} else if (node.tag === "draw:path" || node.tag === "draw:polygon" || node.tag === "draw:polyline") {
|
|
279
326
|
const zIndex = paintOrderKey(node, indexState);
|
|
280
327
|
const vector = readDrawPathVector(node, groupFunctions, pkg);
|
|
281
328
|
if (vector !== void 0) vectorsOut.push({
|
|
282
|
-
value:
|
|
329
|
+
value: {
|
|
330
|
+
...vector,
|
|
331
|
+
paintOrder: zIndex
|
|
332
|
+
},
|
|
283
333
|
zIndex
|
|
284
334
|
});
|
|
285
335
|
} else if (node.tag === "draw:custom-shape") {
|
|
286
336
|
const zIndex = paintOrderKey(node, indexState);
|
|
287
337
|
const vector = readCustomShapeVector(node, groupFunctions, pkg);
|
|
288
338
|
if (vector !== void 0) vectorsOut.push({
|
|
289
|
-
value:
|
|
339
|
+
value: {
|
|
340
|
+
...vector,
|
|
341
|
+
paintOrder: zIndex
|
|
342
|
+
},
|
|
290
343
|
zIndex
|
|
291
344
|
});
|
|
292
345
|
else {
|
|
293
346
|
const shape = readCustomShapeAsTextShape(node, groupFunctions, pkg);
|
|
294
347
|
if (shape !== void 0) shapesOut.push({
|
|
295
|
-
value:
|
|
348
|
+
value: {
|
|
349
|
+
...shape,
|
|
350
|
+
paintOrder: zIndex
|
|
351
|
+
},
|
|
296
352
|
zIndex
|
|
297
353
|
});
|
|
298
354
|
}
|
|
@@ -4,7 +4,10 @@ import { OdfTransformFunction } from "../shared/transform.cjs";
|
|
|
4
4
|
import { ContentShape, ContentVector } from "document-schema.js";
|
|
5
5
|
//#region src/typed/draw/shapes.d.ts
|
|
6
6
|
declare function readDrawFrame(frame: XmlElement, groupFunctions: readonly OdfTransformFunction[], pkg: Package): ContentShape | undefined;
|
|
7
|
-
declare function walkDrawShapes(children: readonly XmlNode[], groupFunctions: readonly OdfTransformFunction[], pkg: Package, out: ContentShape[]): void;
|
|
7
|
+
declare function walkDrawShapes(children: readonly XmlNode[], groupFunctions: readonly OdfTransformFunction[], pkg: Package, out: ContentShape[], indexState?: DocumentIndexState): void;
|
|
8
|
+
interface DocumentIndexState {
|
|
9
|
+
next: number;
|
|
10
|
+
}
|
|
8
11
|
interface DrawPageContent {
|
|
9
12
|
readonly shapes: ContentShape[];
|
|
10
13
|
readonly vectors: ContentVector[];
|
|
@@ -4,7 +4,10 @@ import { OdfTransformFunction } from "../shared/transform.js";
|
|
|
4
4
|
import { ContentShape, ContentVector } from "document-schema.js";
|
|
5
5
|
//#region src/typed/draw/shapes.d.ts
|
|
6
6
|
declare function readDrawFrame(frame: XmlElement, groupFunctions: readonly OdfTransformFunction[], pkg: Package): ContentShape | undefined;
|
|
7
|
-
declare function walkDrawShapes(children: readonly XmlNode[], groupFunctions: readonly OdfTransformFunction[], pkg: Package, out: ContentShape[]): void;
|
|
7
|
+
declare function walkDrawShapes(children: readonly XmlNode[], groupFunctions: readonly OdfTransformFunction[], pkg: Package, out: ContentShape[], indexState?: DocumentIndexState): void;
|
|
8
|
+
interface DocumentIndexState {
|
|
9
|
+
next: number;
|
|
10
|
+
}
|
|
8
11
|
interface DrawPageContent {
|
|
9
12
|
readonly shapes: ContentShape[];
|
|
10
13
|
readonly vectors: ContentVector[];
|
|
@@ -3,6 +3,7 @@ import { sniffImageFormat } from "../../image/sniff.js";
|
|
|
3
3
|
import { parseOdfLength } from "../shared/units.js";
|
|
4
4
|
import { parseOdfColor } from "../shared/color.js";
|
|
5
5
|
import { attrValue, childrenWithTag, elementsWithTag } from "../../xml/query.js";
|
|
6
|
+
import { decodeOdfText } from "../shared/text.js";
|
|
6
7
|
import { parseLinePoints } from "../shared/geometry.js";
|
|
7
8
|
import { resolveStyleElementChain } from "../shared/cascade.js";
|
|
8
9
|
import { readOdfParagraph } from "../shared/paragraph.js";
|
|
@@ -36,20 +37,31 @@ function readFrameInsets(frame, pkg) {
|
|
|
36
37
|
}
|
|
37
38
|
return insets;
|
|
38
39
|
}
|
|
39
|
-
function
|
|
40
|
+
function readFrameAltText(frame) {
|
|
41
|
+
const title = childrenWithTag(frame, "svg:title")[0];
|
|
42
|
+
const decodedTitle = title === void 0 ? void 0 : decodeOdfText(title);
|
|
43
|
+
if (decodedTitle !== void 0 && decodedTitle.length > 0) return decodedTitle;
|
|
44
|
+
const description = childrenWithTag(frame, "svg:desc")[0];
|
|
45
|
+
const decodedDescription = description === void 0 ? void 0 : decodeOdfText(description);
|
|
46
|
+
return decodedDescription !== void 0 && decodedDescription.length > 0 ? decodedDescription : void 0;
|
|
47
|
+
}
|
|
48
|
+
function readDrawImageBlock(image, frame, frameBox, pkg) {
|
|
40
49
|
const href = attrValue(image, "xlink:href");
|
|
41
50
|
const part = href === void 0 ? void 0 : pkg.parts[href];
|
|
42
51
|
if (part?.kind !== "binary") return;
|
|
43
52
|
const bytes = base64ToBytes(part.base64);
|
|
44
53
|
const format = sniffImageFormat(bytes);
|
|
45
54
|
if (format === void 0) return;
|
|
46
|
-
|
|
55
|
+
const block = {
|
|
47
56
|
kind: "image",
|
|
48
57
|
format,
|
|
49
58
|
base64: part.base64,
|
|
50
59
|
widthPt: frameBox.widthPt,
|
|
51
60
|
heightPt: frameBox.heightPt
|
|
52
61
|
};
|
|
62
|
+
const altText = readFrameAltText(frame);
|
|
63
|
+
if (altText !== void 0) block.altText = altText;
|
|
64
|
+
return block;
|
|
53
65
|
}
|
|
54
66
|
function readDrawFrameContent(frame, frameBox, pkg) {
|
|
55
67
|
const table = childrenWithTag(frame, "table:table")[0];
|
|
@@ -58,7 +70,7 @@ function readDrawFrameContent(frame, frameBox, pkg) {
|
|
|
58
70
|
if (textBox !== void 0) return elementsWithTag(textBox.children, "text:p").map((p) => readOdfParagraph(p, pkg));
|
|
59
71
|
const image = childrenWithTag(frame, "draw:image")[0];
|
|
60
72
|
if (image !== void 0) {
|
|
61
|
-
const block = readDrawImageBlock(image, frameBox, pkg);
|
|
73
|
+
const block = readDrawImageBlock(image, frame, frameBox, pkg);
|
|
62
74
|
return block === void 0 ? [] : [block];
|
|
63
75
|
}
|
|
64
76
|
return [];
|
|
@@ -79,16 +91,20 @@ function readOwnTransformFunctions(element) {
|
|
|
79
91
|
const value = attrValue(element, "draw:transform");
|
|
80
92
|
return value === void 0 ? [] : parseOdfTransform(value);
|
|
81
93
|
}
|
|
82
|
-
function walkDrawShapes(children, groupFunctions, pkg, out) {
|
|
94
|
+
function walkDrawShapes(children, groupFunctions, pkg, out, indexState = { next: 0 }) {
|
|
83
95
|
for (const node of children) {
|
|
84
96
|
if (node.type !== "element") continue;
|
|
85
97
|
if (node.tag === "draw:frame") {
|
|
98
|
+
const zIndex = paintOrderKey(node, indexState);
|
|
86
99
|
const shape = readDrawFrame(node, groupFunctions, pkg);
|
|
87
|
-
if (shape !== void 0) out.push(
|
|
100
|
+
if (shape !== void 0) out.push({
|
|
101
|
+
...shape,
|
|
102
|
+
paintOrder: zIndex
|
|
103
|
+
});
|
|
88
104
|
} else if (node.tag === "draw:g") {
|
|
89
105
|
const ownFunctions = readOwnTransformFunctions(node);
|
|
90
106
|
const nested = ownFunctions.length === 0 ? groupFunctions : [...ownFunctions, ...groupFunctions];
|
|
91
|
-
walkDrawShapes(node.children, nested, pkg, out);
|
|
107
|
+
walkDrawShapes(node.children, nested, pkg, out, indexState);
|
|
92
108
|
}
|
|
93
109
|
}
|
|
94
110
|
}
|
|
@@ -96,7 +112,9 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
96
112
|
const styleName = attrValue(element, "draw:style-name");
|
|
97
113
|
const { elements } = resolveStyleElementChain(styleName, "graphic", pkg);
|
|
98
114
|
let fill;
|
|
115
|
+
let fillRule;
|
|
99
116
|
let stroke;
|
|
117
|
+
let strokeStyle;
|
|
100
118
|
for (const styleElement of elements) {
|
|
101
119
|
const props = childrenWithTag(styleElement, "style:graphic-properties")[0];
|
|
102
120
|
if (props === void 0) continue;
|
|
@@ -106,8 +124,15 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
106
124
|
const parsedFill = fillColorValue === void 0 ? void 0 : parseOdfColor(fillColorValue);
|
|
107
125
|
if (parsedFill !== void 0) fill = parsedFill;
|
|
108
126
|
}
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
const fillRuleValue = attrValue(props, "svg:fill-rule");
|
|
128
|
+
if (fillRuleValue === "nonzero" || fillRuleValue === "evenodd") fillRule = fillRuleValue;
|
|
129
|
+
const strokeMode = attrValue(props, "draw:stroke");
|
|
130
|
+
if (strokeMode === "none") {
|
|
131
|
+
stroke = void 0;
|
|
132
|
+
strokeStyle = void 0;
|
|
133
|
+
} else {
|
|
134
|
+
if (strokeMode === "dash") strokeStyle = "dashed";
|
|
135
|
+
else if (strokeMode === "solid") strokeStyle = "solid";
|
|
111
136
|
const strokeColorValue = attrValue(props, "svg:stroke-color");
|
|
112
137
|
const strokeWidthValue = attrValue(props, "svg:stroke-width");
|
|
113
138
|
const strokeColor = strokeColorValue === void 0 ? void 0 : parseOdfColor(strokeColorValue);
|
|
@@ -120,32 +145,38 @@ function readOdfFillAndStroke(element, pkg) {
|
|
|
120
145
|
}
|
|
121
146
|
return {
|
|
122
147
|
fill,
|
|
123
|
-
|
|
148
|
+
fillRule,
|
|
149
|
+
stroke: stroke === void 0 || strokeStyle === void 0 ? stroke : {
|
|
150
|
+
...stroke,
|
|
151
|
+
style: strokeStyle
|
|
152
|
+
}
|
|
124
153
|
};
|
|
125
154
|
}
|
|
126
|
-
function
|
|
155
|
+
function resolveVectorGeometry(element, groupFunctions) {
|
|
127
156
|
const geometry = resolveOdfShapeGeometry(element);
|
|
128
157
|
if (geometry === void 0) return;
|
|
129
|
-
return composeOdfGroupTransform(groupFunctions, geometry)
|
|
158
|
+
return composeOdfGroupTransform(groupFunctions, geometry);
|
|
130
159
|
}
|
|
131
160
|
function readDrawRectVector(element, groupFunctions, pkg) {
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
161
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
162
|
+
if (geometry === void 0) return;
|
|
134
163
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
135
164
|
return {
|
|
136
165
|
kind: "rect",
|
|
137
|
-
frame,
|
|
166
|
+
frame: geometry.frame,
|
|
167
|
+
rotationDeg: geometry.rotationDeg,
|
|
138
168
|
fill,
|
|
139
169
|
stroke
|
|
140
170
|
};
|
|
141
171
|
}
|
|
142
172
|
function readDrawEllipseVector(element, groupFunctions, pkg) {
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
173
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
174
|
+
if (geometry === void 0) return;
|
|
145
175
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
146
176
|
return {
|
|
147
177
|
kind: "ellipse",
|
|
148
|
-
frame,
|
|
178
|
+
frame: geometry.frame,
|
|
179
|
+
rotationDeg: geometry.rotationDeg,
|
|
149
180
|
fill,
|
|
150
181
|
stroke
|
|
151
182
|
};
|
|
@@ -165,8 +196,9 @@ function readDrawLineVector(element, groupFunctions, pkg) {
|
|
|
165
196
|
};
|
|
166
197
|
}
|
|
167
198
|
function readDrawPathVector(element, groupFunctions, pkg) {
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
199
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
200
|
+
if (geometry === void 0) return;
|
|
201
|
+
const frame = geometry.frame;
|
|
170
202
|
const viewBoxValue = attrValue(element, "svg:viewBox");
|
|
171
203
|
const viewBox = viewBoxValue === void 0 ? void 0 : parseOdfViewBox(viewBoxValue);
|
|
172
204
|
if (viewBox === void 0) return;
|
|
@@ -182,12 +214,14 @@ function readDrawPathVector(element, groupFunctions, pkg) {
|
|
|
182
214
|
}
|
|
183
215
|
if (rawSubpaths.length === 0) return;
|
|
184
216
|
const subpaths = buildOdfSubpaths(rawSubpaths, viewBox, frame);
|
|
185
|
-
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
217
|
+
const { fill, fillRule, stroke } = readOdfFillAndStroke(element, pkg);
|
|
186
218
|
return {
|
|
187
219
|
kind: "path",
|
|
188
220
|
frame,
|
|
221
|
+
rotationDeg: geometry.rotationDeg,
|
|
189
222
|
subpaths,
|
|
190
223
|
fill,
|
|
224
|
+
fillRule,
|
|
191
225
|
stroke
|
|
192
226
|
};
|
|
193
227
|
}
|
|
@@ -200,12 +234,13 @@ function readCustomShapeVector(element, groupFunctions, pkg) {
|
|
|
200
234
|
const geometryElement = childrenWithTag(element, "draw:enhanced-geometry")[0];
|
|
201
235
|
const type = geometryElement === void 0 ? void 0 : attrValue(geometryElement, "draw:type");
|
|
202
236
|
if (type === void 0 || !RECOGNIZED_CUSTOM_SHAPE_PRESETS.has(type)) return;
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
237
|
+
const geometry = resolveVectorGeometry(element, groupFunctions);
|
|
238
|
+
if (geometry === void 0) return;
|
|
205
239
|
const { fill, stroke } = readOdfFillAndStroke(element, pkg);
|
|
206
240
|
return {
|
|
207
241
|
kind: type === "ellipse" ? "ellipse" : "rect",
|
|
208
|
-
frame,
|
|
242
|
+
frame: geometry.frame,
|
|
243
|
+
rotationDeg: geometry.rotationDeg,
|
|
209
244
|
fill,
|
|
210
245
|
stroke
|
|
211
246
|
};
|
|
@@ -246,7 +281,10 @@ function walkDrawPageContent(children, groupFunctions, pkg, indexState, shapesOu
|
|
|
246
281
|
const zIndex = paintOrderKey(node, indexState);
|
|
247
282
|
const shape = readDrawFrame(node, groupFunctions, pkg);
|
|
248
283
|
if (shape !== void 0) shapesOut.push({
|
|
249
|
-
value:
|
|
284
|
+
value: {
|
|
285
|
+
...shape,
|
|
286
|
+
paintOrder: zIndex
|
|
287
|
+
},
|
|
250
288
|
zIndex
|
|
251
289
|
});
|
|
252
290
|
} else if (node.tag === "draw:g") {
|
|
@@ -257,41 +295,59 @@ function walkDrawPageContent(children, groupFunctions, pkg, indexState, shapesOu
|
|
|
257
295
|
const zIndex = paintOrderKey(node, indexState);
|
|
258
296
|
const vector = readDrawRectVector(node, groupFunctions, pkg);
|
|
259
297
|
if (vector !== void 0) vectorsOut.push({
|
|
260
|
-
value:
|
|
298
|
+
value: {
|
|
299
|
+
...vector,
|
|
300
|
+
paintOrder: zIndex
|
|
301
|
+
},
|
|
261
302
|
zIndex
|
|
262
303
|
});
|
|
263
304
|
} else if (node.tag === "draw:ellipse" || node.tag === "draw:circle") {
|
|
264
305
|
const zIndex = paintOrderKey(node, indexState);
|
|
265
306
|
const vector = readDrawEllipseVector(node, groupFunctions, pkg);
|
|
266
307
|
if (vector !== void 0) vectorsOut.push({
|
|
267
|
-
value:
|
|
308
|
+
value: {
|
|
309
|
+
...vector,
|
|
310
|
+
paintOrder: zIndex
|
|
311
|
+
},
|
|
268
312
|
zIndex
|
|
269
313
|
});
|
|
270
314
|
} else if (node.tag === "draw:line") {
|
|
271
315
|
const zIndex = paintOrderKey(node, indexState);
|
|
272
316
|
const vector = readDrawLineVector(node, groupFunctions, pkg);
|
|
273
317
|
if (vector !== void 0) vectorsOut.push({
|
|
274
|
-
value:
|
|
318
|
+
value: {
|
|
319
|
+
...vector,
|
|
320
|
+
paintOrder: zIndex
|
|
321
|
+
},
|
|
275
322
|
zIndex
|
|
276
323
|
});
|
|
277
324
|
} else if (node.tag === "draw:path" || node.tag === "draw:polygon" || node.tag === "draw:polyline") {
|
|
278
325
|
const zIndex = paintOrderKey(node, indexState);
|
|
279
326
|
const vector = readDrawPathVector(node, groupFunctions, pkg);
|
|
280
327
|
if (vector !== void 0) vectorsOut.push({
|
|
281
|
-
value:
|
|
328
|
+
value: {
|
|
329
|
+
...vector,
|
|
330
|
+
paintOrder: zIndex
|
|
331
|
+
},
|
|
282
332
|
zIndex
|
|
283
333
|
});
|
|
284
334
|
} else if (node.tag === "draw:custom-shape") {
|
|
285
335
|
const zIndex = paintOrderKey(node, indexState);
|
|
286
336
|
const vector = readCustomShapeVector(node, groupFunctions, pkg);
|
|
287
337
|
if (vector !== void 0) vectorsOut.push({
|
|
288
|
-
value:
|
|
338
|
+
value: {
|
|
339
|
+
...vector,
|
|
340
|
+
paintOrder: zIndex
|
|
341
|
+
},
|
|
289
342
|
zIndex
|
|
290
343
|
});
|
|
291
344
|
else {
|
|
292
345
|
const shape = readCustomShapeAsTextShape(node, groupFunctions, pkg);
|
|
293
346
|
if (shape !== void 0) shapesOut.push({
|
|
294
|
-
value:
|
|
347
|
+
value: {
|
|
348
|
+
...shape,
|
|
349
|
+
paintOrder: zIndex
|
|
350
|
+
},
|
|
295
351
|
zIndex
|
|
296
352
|
});
|
|
297
353
|
}
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_xml_entities = require("../../xml/entities.cjs");
|
|
3
3
|
const require_xml_query = require("../../xml/query.cjs");
|
|
4
4
|
const require_typed_shared_metadata = require("../shared/metadata.cjs");
|
|
5
|
+
let document_schema_js = require("document-schema.js");
|
|
5
6
|
//#region src/typed/formula/read.ts
|
|
6
7
|
const CONTENT_PART = "content.xml";
|
|
7
8
|
const MATH_ROOT_TAGS = ["math", "math:math"];
|
|
@@ -44,5 +45,18 @@ function readOdfFormula(pkg) {
|
|
|
44
45
|
metadata
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
function readOdfFormulaDocument(pkg) {
|
|
49
|
+
const { mathml, starMath, metadata } = readOdfFormula(pkg);
|
|
50
|
+
return {
|
|
51
|
+
kind: "formula",
|
|
52
|
+
formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
|
|
53
|
+
metadata,
|
|
54
|
+
formula: starMath === void 0 ? { mathml } : {
|
|
55
|
+
mathml,
|
|
56
|
+
starMath
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
47
60
|
//#endregion
|
|
48
61
|
exports.readOdfFormula = readOdfFormula;
|
|
62
|
+
exports.readOdfFormulaDocument = readOdfFormulaDocument;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { d as XmlNode } from "../../node-CkBWRjNR.cjs";
|
|
2
2
|
import { Package } from "../../model/package.cjs";
|
|
3
|
-
import { LayoutMetadata } from "document-schema.js";
|
|
3
|
+
import { ContentDocument, LayoutMetadata } from "document-schema.js";
|
|
4
4
|
//#region src/typed/formula/read.d.ts
|
|
5
5
|
interface OdfFormulaDocument {
|
|
6
6
|
starMath?: string;
|
|
@@ -8,5 +8,6 @@ interface OdfFormulaDocument {
|
|
|
8
8
|
metadata: LayoutMetadata;
|
|
9
9
|
}
|
|
10
10
|
declare function readOdfFormula(pkg: Package): OdfFormulaDocument;
|
|
11
|
+
declare function readOdfFormulaDocument(pkg: Package): ContentDocument;
|
|
11
12
|
//#endregion
|
|
12
|
-
export { OdfFormulaDocument, readOdfFormula };
|
|
13
|
+
export { OdfFormulaDocument, readOdfFormula, readOdfFormulaDocument };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { d as XmlNode } from "../../node-CkBWRjNR.js";
|
|
2
2
|
import { Package } from "../../model/package.js";
|
|
3
|
-
import { LayoutMetadata } from "document-schema.js";
|
|
3
|
+
import { ContentDocument, LayoutMetadata } from "document-schema.js";
|
|
4
4
|
//#region src/typed/formula/read.d.ts
|
|
5
5
|
interface OdfFormulaDocument {
|
|
6
6
|
starMath?: string;
|
|
@@ -8,5 +8,6 @@ interface OdfFormulaDocument {
|
|
|
8
8
|
metadata: LayoutMetadata;
|
|
9
9
|
}
|
|
10
10
|
declare function readOdfFormula(pkg: Package): OdfFormulaDocument;
|
|
11
|
+
declare function readOdfFormulaDocument(pkg: Package): ContentDocument;
|
|
11
12
|
//#endregion
|
|
12
|
-
export { OdfFormulaDocument, readOdfFormula };
|
|
13
|
+
export { OdfFormulaDocument, readOdfFormula, readOdfFormulaDocument };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { decodeXmlText } from "../../xml/entities.js";
|
|
2
2
|
import { attrValue, elementsWithTag, rootElement } from "../../xml/query.js";
|
|
3
3
|
import { readOdfMetadata } from "../shared/metadata.js";
|
|
4
|
+
import { CONTENT_FORMAT_VERSION } from "document-schema.js";
|
|
4
5
|
//#region src/typed/formula/read.ts
|
|
5
6
|
const CONTENT_PART = "content.xml";
|
|
6
7
|
const MATH_ROOT_TAGS = ["math", "math:math"];
|
|
@@ -43,5 +44,17 @@ function readOdfFormula(pkg) {
|
|
|
43
44
|
metadata
|
|
44
45
|
};
|
|
45
46
|
}
|
|
47
|
+
function readOdfFormulaDocument(pkg) {
|
|
48
|
+
const { mathml, starMath, metadata } = readOdfFormula(pkg);
|
|
49
|
+
return {
|
|
50
|
+
kind: "formula",
|
|
51
|
+
formatVersion: CONTENT_FORMAT_VERSION,
|
|
52
|
+
metadata,
|
|
53
|
+
formula: starMath === void 0 ? { mathml } : {
|
|
54
|
+
mathml,
|
|
55
|
+
starMath
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
46
59
|
//#endregion
|
|
47
|
-
export { readOdfFormula };
|
|
60
|
+
export { readOdfFormula, readOdfFormulaDocument };
|