odf.js 6.3.0 → 6.4.1
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 +172 -18
- package/dist/{codec-BnzBd5_I.d.cts → codec-CFdlbFLJ.d.cts} +16 -10
- package/dist/{codec-Dg_HWuH1.d.ts → codec-DTAgph2r.d.ts} +16 -10
- package/dist/codec.d.cts +1 -1
- package/dist/codec.d.ts +1 -1
- package/dist/{embedded-BONPxvS3.js → embedded-BnavfkP-.js} +3 -3
- package/dist/{embedded-wrtHCJ68.cjs → embedded-Bxyss_ck.cjs} +14 -2
- package/dist/image/sniff.cjs +26 -0
- package/dist/image/sniff.d.cts +1 -1
- package/dist/image/sniff.d.ts +1 -1
- package/dist/image/sniff.js +26 -0
- package/dist/index.cjs +34 -1
- package/dist/index.d.cts +20 -14
- package/dist/index.d.ts +20 -14
- package/dist/index.js +12 -6
- package/dist/{list-vhXd0Jf6.d.ts → list-7FO0SDqZ.d.ts} +14 -1
- package/dist/{list-Bttwr1mk.d.cts → list-BorrTJBY.d.cts} +14 -1
- package/dist/manifest.cjs +2 -0
- package/dist/manifest.js +2 -0
- package/dist/{ns-C14w-Zhf.d.cts → ns-DrleaIZQ.d.cts} +3 -1
- package/dist/{ns-CTyKJZeF.d.ts → ns-E0TfX9tZ.d.ts} +3 -1
- package/dist/ooo1/ns.cjs +9 -0
- package/dist/ooo1/ns.d.cts +2 -2
- package/dist/ooo1/ns.d.ts +2 -2
- package/dist/ooo1/ns.js +8 -1
- package/dist/ooo1/properties.cjs +30 -0
- package/dist/ooo1/properties.d.cts +6 -2
- package/dist/ooo1/properties.d.ts +6 -2
- package/dist/ooo1/properties.js +30 -1
- package/dist/ooo1/read.cjs +1 -1
- package/dist/ooo1/read.d.cts +1 -1
- package/dist/ooo1/read.d.ts +1 -1
- package/dist/ooo1/read.js +1 -1
- package/dist/ooo1/transform.cjs +290 -0
- package/dist/ooo1/transform.d.cts +2 -2
- package/dist/ooo1/transform.d.ts +2 -2
- package/dist/ooo1/transform.js +293 -4
- package/dist/ooo1/write.cjs +40 -0
- package/dist/ooo1/write.d.cts +2 -0
- package/dist/ooo1/write.d.ts +2 -0
- package/dist/ooo1/write.js +32 -0
- package/dist/package-io/scaffold.cjs +2 -1
- package/dist/package-io/scaffold.js +2 -1
- package/dist/{paragraph-BdwsQisB.d.cts → paragraph-Bf6Iq5wC.d.cts} +1 -1
- package/dist/{paragraph-BoVy1LrN.d.ts → paragraph-DtC86tft.d.ts} +1 -1
- package/dist/{path-CK0dIPgx.d.cts → path-8HQS-J7y.d.cts} +3 -1
- package/dist/{path-CK0dIPgx.d.ts → path-8HQS-J7y.d.ts} +3 -1
- package/dist/{read-Bo1GBjSE.d.ts → read-A3CJkqVM.d.ts} +3 -1
- package/dist/{read-RFqq4ckj.d.cts → read-BgnLFuSi.d.cts} +1 -1
- package/dist/{read-3yy5EFV_.d.ts → read-CqaZ01kU.d.ts} +1 -1
- package/dist/{read-tpfiT_n4.d.cts → read-fphkvCpR.d.cts} +3 -1
- package/dist/{shapes-DUzrrf7b.d.ts → shapes-B6Ms7ibr.d.ts} +1 -1
- package/dist/{shapes-BQhXAk0D.d.cts → shapes-CbBc9t0y.d.cts} +1 -1
- package/dist/{sniff-DGOBHA0O.d.cts → sniff-eR8lObzF.d.cts} +1 -1
- package/dist/{sniff-DGOBHA0O.d.ts → sniff-eR8lObzF.d.ts} +1 -1
- package/dist/{table-ByhqRnSG.d.cts → table-CECMtPxZ.d.cts} +6 -2
- package/dist/{table-DElqGcT0.d.ts → table-XuniPr2I.d.ts} +6 -2
- package/dist/{transform-SDysw9wx.d.cts → transform-DFCPKX7e.d.cts} +2 -1
- package/dist/{transform-DRr76JEu.d.ts → transform-DPliWQuD.d.ts} +2 -1
- package/dist/typed/draw/embedded.cjs +1 -1
- package/dist/typed/draw/embedded.js +1 -1
- package/dist/typed/draw/shapes.cjs +7 -2
- package/dist/typed/draw/shapes.d.cts +1 -1
- package/dist/typed/draw/shapes.d.ts +1 -1
- package/dist/typed/draw/shapes.js +7 -2
- package/dist/typed/draw/write-shapes.cjs +211 -0
- package/dist/typed/draw/write-shapes.d.cts +2 -0
- package/dist/typed/draw/write-shapes.d.ts +2 -0
- package/dist/typed/draw/write-shapes.js +204 -0
- package/dist/typed/draw/write-vectors.cjs +132 -0
- package/dist/typed/draw/write-vectors.d.cts +2 -0
- package/dist/typed/draw/write-vectors.d.ts +2 -0
- package/dist/typed/draw/write-vectors.js +129 -0
- package/dist/typed/odb/form.cjs +1 -1
- package/dist/typed/odb/form.js +1 -1
- package/dist/typed/odg/write.cjs +80 -0
- package/dist/typed/odg/write.d.cts +2 -0
- package/dist/typed/odg/write.d.ts +2 -0
- package/dist/typed/odg/write.js +77 -0
- package/dist/typed/odp/write.cjs +108 -0
- package/dist/typed/odp/write.d.cts +2 -0
- package/dist/typed/odp/write.d.ts +2 -0
- package/dist/typed/odp/write.js +105 -0
- package/dist/typed/ods/read.cjs +3 -1
- package/dist/typed/ods/read.d.cts +2 -2
- package/dist/typed/ods/read.d.ts +2 -2
- package/dist/typed/ods/read.js +2 -2
- package/dist/typed/ods/write.cjs +579 -0
- package/dist/typed/ods/write.d.cts +2 -0
- package/dist/typed/ods/write.d.ts +2 -0
- package/dist/typed/ods/write.js +576 -0
- package/dist/typed/odt/read.cjs +1 -1
- package/dist/typed/odt/read.js +1 -1
- package/dist/typed/odt/write.cjs +11 -141
- package/dist/typed/odt/write.d.cts +1 -1
- package/dist/typed/odt/write.d.ts +1 -1
- package/dist/typed/odt/write.js +10 -140
- package/dist/typed/shared/canonicalise.cjs +126 -0
- package/dist/typed/shared/canonicalise.d.cts +10 -0
- package/dist/typed/shared/canonicalise.d.ts +10 -0
- package/dist/typed/shared/canonicalise.js +120 -0
- package/dist/typed/shared/image.cjs +12 -0
- package/dist/typed/shared/image.d.cts +5 -0
- package/dist/typed/shared/image.d.ts +5 -0
- package/dist/typed/shared/image.js +11 -0
- package/dist/typed/shared/list.cjs +32 -0
- package/dist/typed/shared/list.d.cts +2 -2
- package/dist/typed/shared/list.d.ts +2 -2
- package/dist/typed/shared/list.js +28 -1
- package/dist/typed/shared/paragraph.d.cts +1 -1
- package/dist/typed/shared/paragraph.d.ts +1 -1
- package/dist/typed/shared/path.cjs +19 -0
- package/dist/typed/shared/path.d.cts +2 -2
- package/dist/typed/shared/path.d.ts +2 -2
- package/dist/typed/shared/path.js +18 -1
- package/dist/typed/shared/table.cjs +3 -0
- package/dist/typed/shared/table.d.cts +2 -2
- package/dist/typed/shared/table.d.ts +2 -2
- package/dist/typed/shared/table.js +1 -1
- package/dist/typed/shared/units.cjs +16 -1
- package/dist/typed/shared/units.d.cts +2 -2
- package/dist/typed/shared/units.d.ts +2 -2
- package/dist/typed/shared/units.js +16 -2
- package/dist/{units-BQSNkTQZ.d.cts → units-DdyaQolR.d.cts} +2 -1
- package/dist/{units-BQSNkTQZ.d.ts → units-DdyaQolR.d.ts} +2 -1
- package/dist/write-4kMi-asu.d.ts +14 -0
- package/dist/write-BZXpT8F6.d.cts +17 -0
- package/dist/write-BhG3t3fJ.d.cts +14 -0
- package/dist/write-BuLQmwLD.d.cts +14 -0
- package/dist/write-C2c4xBXs.d.cts +14 -0
- package/dist/{write-7Uu_wlkL.d.cts → write-CPATqG4v.d.cts} +1 -0
- package/dist/write-CfTE2jY8.d.ts +14 -0
- package/dist/write-DttX1rTC.d.ts +14 -0
- package/dist/{write-DGcI9W7Z.d.ts → write-JERychL3.d.ts} +1 -0
- package/dist/write-SKnCTU4C.d.ts +17 -0
- package/dist/write-shapes-Co7BrmMZ.d.ts +36 -0
- package/dist/write-shapes-D4piGKf4.d.cts +36 -0
- package/dist/write-vectors-B-RVHAKI.d.cts +11 -0
- package/dist/write-vectors-CYjZoVBW.d.ts +11 -0
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_util_base64 = require("../../util/base64.cjs");
|
|
3
3
|
const require_image_sniff = require("../../image/sniff.cjs");
|
|
4
|
+
const require_xml_entities = require("../../xml/entities.cjs");
|
|
4
5
|
const require_typed_shared_units = require("../shared/units.cjs");
|
|
5
6
|
const require_typed_shared_color = require("../shared/color.cjs");
|
|
6
7
|
const require_xml_query = require("../../xml/query.cjs");
|
|
@@ -40,6 +41,10 @@ function readFrameInsets(frame, pkg) {
|
|
|
40
41
|
}
|
|
41
42
|
return insets;
|
|
42
43
|
}
|
|
44
|
+
function readDrawName(element) {
|
|
45
|
+
const raw = require_xml_query.attrValue(element, "draw:name");
|
|
46
|
+
return raw === void 0 ? void 0 : require_xml_entities.decodeXmlText(raw);
|
|
47
|
+
}
|
|
43
48
|
function readFrameAltText(frame) {
|
|
44
49
|
const title = require_xml_query.childrenWithTag(frame, "svg:title")[0];
|
|
45
50
|
const decodedTitle = title === void 0 ? void 0 : require_typed_shared_text.decodeOdfText(title);
|
|
@@ -97,7 +102,7 @@ function readDrawFrame(frame, groupFunctions, pkg, listIdState = { next: 1 }, fl
|
|
|
97
102
|
if (ownGeometry === void 0) return;
|
|
98
103
|
const geometry = require_typed_shared_transform.composeOdfGroupTransform(groupFunctions, ownGeometry);
|
|
99
104
|
return {
|
|
100
|
-
name:
|
|
105
|
+
name: readDrawName(frame),
|
|
101
106
|
frame: geometry.frame,
|
|
102
107
|
rotationDeg: geometry.rotationDeg,
|
|
103
108
|
...readFrameInsets(frame, pkg),
|
|
@@ -287,7 +292,7 @@ function readCustomShapeAsTextShape(element, groupFunctions, pkg) {
|
|
|
287
292
|
const geometry = require_typed_shared_transform.composeOdfGroupTransform(groupFunctions, ownGeometry);
|
|
288
293
|
const enhancedGeometry = require_xml_query.childrenWithTag(element, "draw:enhanced-geometry")[0];
|
|
289
294
|
return {
|
|
290
|
-
name:
|
|
295
|
+
name: readDrawName(element),
|
|
291
296
|
frame: geometry.frame,
|
|
292
297
|
rotationDeg: geometry.rotationDeg,
|
|
293
298
|
...readFrameInsets(element, pkg),
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as walkDrawShapes, i as readDrawPageContent, n as readDrawFrame, r as readDrawImageBlock, t as DrawPageContent } from "../../shapes-
|
|
1
|
+
import { a as walkDrawShapes, i as readDrawPageContent, n as readDrawFrame, r as readDrawImageBlock, t as DrawPageContent } from "../../shapes-CbBc9t0y.cjs";
|
|
2
2
|
export { DrawPageContent, readDrawFrame, readDrawImageBlock, readDrawPageContent, walkDrawShapes };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as walkDrawShapes, i as readDrawPageContent, n as readDrawFrame, r as readDrawImageBlock, t as DrawPageContent } from "../../shapes-
|
|
1
|
+
import { a as walkDrawShapes, i as readDrawPageContent, n as readDrawFrame, r as readDrawImageBlock, t as DrawPageContent } from "../../shapes-B6Ms7ibr.js";
|
|
2
2
|
export { DrawPageContent, readDrawFrame, readDrawImageBlock, readDrawPageContent, walkDrawShapes };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { base64ToBytes } from "../../util/base64.js";
|
|
2
2
|
import { sniffImageFormat } from "../../image/sniff.js";
|
|
3
|
+
import { decodeXmlText } from "../../xml/entities.js";
|
|
3
4
|
import { parseOdfLength } from "../shared/units.js";
|
|
4
5
|
import { parseOdfColor } from "../shared/color.js";
|
|
5
6
|
import { attrValue, childrenWithTag, elementsWithTag } from "../../xml/query.js";
|
|
@@ -39,6 +40,10 @@ function readFrameInsets(frame, pkg) {
|
|
|
39
40
|
}
|
|
40
41
|
return insets;
|
|
41
42
|
}
|
|
43
|
+
function readDrawName(element) {
|
|
44
|
+
const raw = attrValue(element, "draw:name");
|
|
45
|
+
return raw === void 0 ? void 0 : decodeXmlText(raw);
|
|
46
|
+
}
|
|
42
47
|
function readFrameAltText(frame) {
|
|
43
48
|
const title = childrenWithTag(frame, "svg:title")[0];
|
|
44
49
|
const decodedTitle = title === void 0 ? void 0 : decodeOdfText(title);
|
|
@@ -96,7 +101,7 @@ function readDrawFrame(frame, groupFunctions, pkg, listIdState = { next: 1 }, fl
|
|
|
96
101
|
if (ownGeometry === void 0) return;
|
|
97
102
|
const geometry = composeOdfGroupTransform(groupFunctions, ownGeometry);
|
|
98
103
|
return {
|
|
99
|
-
name:
|
|
104
|
+
name: readDrawName(frame),
|
|
100
105
|
frame: geometry.frame,
|
|
101
106
|
rotationDeg: geometry.rotationDeg,
|
|
102
107
|
...readFrameInsets(frame, pkg),
|
|
@@ -286,7 +291,7 @@ function readCustomShapeAsTextShape(element, groupFunctions, pkg) {
|
|
|
286
291
|
const geometry = composeOdfGroupTransform(groupFunctions, ownGeometry);
|
|
287
292
|
const enhancedGeometry = childrenWithTag(element, "draw:enhanced-geometry")[0];
|
|
288
293
|
return {
|
|
289
|
-
name:
|
|
294
|
+
name: readDrawName(element),
|
|
290
295
|
frame: geometry.frame,
|
|
291
296
|
rotationDeg: geometry.rotationDeg,
|
|
292
297
|
...readFrameInsets(element, pkg),
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
3
|
+
const require_xml_entities = require("../../xml/entities.cjs");
|
|
4
|
+
const require_typed_shared_units = require("../shared/units.cjs");
|
|
5
|
+
const require_typed_shared_list = require("../shared/list.cjs");
|
|
6
|
+
const require_typed_shared_paragraph = require("../shared/paragraph.cjs");
|
|
7
|
+
const require_typed_shared_table = require("../shared/table.cjs");
|
|
8
|
+
const require_typed_shared_image = require("../shared/image.cjs");
|
|
9
|
+
const require_typed_shared_canonicalise = require("../shared/canonicalise.cjs");
|
|
10
|
+
//#region src/typed/draw/write-shapes.ts
|
|
11
|
+
function unsupportedShapeContent(what) {
|
|
12
|
+
return /* @__PURE__ */ new Error(`writeDrawFrame: a shape carries ${what}, which this writer does not write yet -- refusing rather than producing a document that silently lost it. See ExaDev/documents.js for the tracked follow-up covering the fidelity constructs.`);
|
|
13
|
+
}
|
|
14
|
+
function planShapeContent(blocks, listState) {
|
|
15
|
+
require_typed_shared_list.closeListPlan(listState);
|
|
16
|
+
if (blocks.length === 1) {
|
|
17
|
+
const only = blocks[0];
|
|
18
|
+
if (only.kind === "table") return {
|
|
19
|
+
kind: "table",
|
|
20
|
+
table: only
|
|
21
|
+
};
|
|
22
|
+
if (only.kind === "image") return {
|
|
23
|
+
kind: "image",
|
|
24
|
+
image: only
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const paragraphs = [];
|
|
28
|
+
for (const block of blocks) {
|
|
29
|
+
if (block.kind === "table") throw unsupportedShapeContent("a table alongside other content (a draw:frame's own content is exactly one of table:table/draw:text-box/draw:image, never a mix)");
|
|
30
|
+
if (block.kind === "image") throw unsupportedShapeContent("an image alongside other content (same reason)");
|
|
31
|
+
if (block.kind === "pageBreak") throw unsupportedShapeContent("a page break (no ODF spelling inside a shape's own text)");
|
|
32
|
+
if (block.kind === "embeddedObject") throw unsupportedShapeContent("an embedded object");
|
|
33
|
+
if (block.kind === "constructStart" || block.kind === "constructEnd") throw unsupportedShapeContent("a construct boundary marker");
|
|
34
|
+
if (block.constructs !== void 0 && block.constructs.length > 0) throw unsupportedShapeContent("a run-level construct extent (a field, bookmark, note, annotation, or tracked change)");
|
|
35
|
+
if (block.headingLevel !== void 0) throw unsupportedShapeContent("a heading (a shape's own draw:text-box has no text:h reading path)");
|
|
36
|
+
const canonicalId = require_typed_shared_list.planListMembership(block.list, listState);
|
|
37
|
+
paragraphs.push(canonicalId === void 0 ? {
|
|
38
|
+
...block,
|
|
39
|
+
list: void 0
|
|
40
|
+
} : {
|
|
41
|
+
...block,
|
|
42
|
+
list: {
|
|
43
|
+
numId: canonicalId,
|
|
44
|
+
level: block.list.level
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
kind: "text",
|
|
50
|
+
paragraphs
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function createDrawShapeWriteState(pkg, registry, contentAutomaticStyles) {
|
|
54
|
+
return {
|
|
55
|
+
pkg,
|
|
56
|
+
registry,
|
|
57
|
+
contentAutomaticStyles,
|
|
58
|
+
nextImage: 1,
|
|
59
|
+
nextTable: 1,
|
|
60
|
+
nextListStyle: 1,
|
|
61
|
+
listStyleByKind: /* @__PURE__ */ new Map()
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function listStyleNameFor(kind, state) {
|
|
65
|
+
const existing = state.listStyleByKind.get(kind);
|
|
66
|
+
if (existing !== void 0) return existing;
|
|
67
|
+
const name = `SL${state.nextListStyle}`;
|
|
68
|
+
state.nextListStyle += 1;
|
|
69
|
+
state.listStyleByKind.set(kind, name);
|
|
70
|
+
state.contentAutomaticStyles.children.push(require_typed_shared_list.buildOdfListStyle(name, kind));
|
|
71
|
+
return name;
|
|
72
|
+
}
|
|
73
|
+
function frameGeometryAttrs(frame, rotationDeg) {
|
|
74
|
+
if (rotationDeg === void 0 || rotationDeg === 0) return {
|
|
75
|
+
"svg:x": require_typed_shared_units.formatOdfLength(frame.xPt),
|
|
76
|
+
"svg:y": require_typed_shared_units.formatOdfLength(frame.yPt),
|
|
77
|
+
"svg:width": require_typed_shared_units.formatOdfLength(frame.widthPt),
|
|
78
|
+
"svg:height": require_typed_shared_units.formatOdfLength(frame.heightPt)
|
|
79
|
+
};
|
|
80
|
+
const angleRad = -rotationDeg * Math.PI / 180;
|
|
81
|
+
const cos = Math.cos(angleRad);
|
|
82
|
+
const sin = Math.sin(angleRad);
|
|
83
|
+
const halfWidthPt = frame.widthPt / 2;
|
|
84
|
+
const halfHeightPt = frame.heightPt / 2;
|
|
85
|
+
const txPt = frame.xPt + halfWidthPt - halfWidthPt * cos - halfHeightPt * sin;
|
|
86
|
+
const tyPt = frame.yPt + halfHeightPt - halfHeightPt * cos + halfWidthPt * sin;
|
|
87
|
+
return {
|
|
88
|
+
"svg:width": require_typed_shared_units.formatOdfLength(frame.widthPt),
|
|
89
|
+
"svg:height": require_typed_shared_units.formatOdfLength(frame.heightPt),
|
|
90
|
+
"draw:transform": `rotate(${require_typed_shared_units.formatOdfNumber(angleRad)}) translate(${require_typed_shared_units.formatOdfLength(txPt)} ${require_typed_shared_units.formatOdfLength(tyPt)})`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function shapeGraphicStyleName(shape, state) {
|
|
94
|
+
const properties = {
|
|
95
|
+
"draw:fill": "none",
|
|
96
|
+
"draw:stroke": "none"
|
|
97
|
+
};
|
|
98
|
+
if (shape.insetLeftPt !== 0 || shape.insetTopPt !== 0 || shape.insetRightPt !== 0 || shape.insetBottomPt !== 0) {
|
|
99
|
+
properties["fo:padding-left"] = require_typed_shared_units.formatOdfLength(shape.insetLeftPt);
|
|
100
|
+
properties["fo:padding-top"] = require_typed_shared_units.formatOdfLength(shape.insetTopPt);
|
|
101
|
+
properties["fo:padding-right"] = require_typed_shared_units.formatOdfLength(shape.insetRightPt);
|
|
102
|
+
properties["fo:padding-bottom"] = require_typed_shared_units.formatOdfLength(shape.insetBottomPt);
|
|
103
|
+
}
|
|
104
|
+
return state.registry.intern({
|
|
105
|
+
properties: {},
|
|
106
|
+
family: "graphic",
|
|
107
|
+
propertyElements: [require_xml_fragment.el("style:graphic-properties", properties)]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function writeShapeTextBox(paragraphs, state) {
|
|
111
|
+
const out = [];
|
|
112
|
+
let openList;
|
|
113
|
+
const closeList = () => {
|
|
114
|
+
if (openList === void 0) return;
|
|
115
|
+
const kind = require_typed_shared_list.listKindOf(openList.numId);
|
|
116
|
+
const built = require_typed_shared_list.writeOdfList(openList.entries, kind === void 0 ? void 0 : listStyleNameFor(kind, state));
|
|
117
|
+
openList.element.attributes = built.attributes;
|
|
118
|
+
openList.element.children = built.children;
|
|
119
|
+
openList = void 0;
|
|
120
|
+
};
|
|
121
|
+
for (const paragraph of paragraphs) {
|
|
122
|
+
const element = require_typed_shared_paragraph.writeOdfParagraph(paragraph, state.registry);
|
|
123
|
+
const membership = paragraph.list;
|
|
124
|
+
if (membership?.numId === void 0) {
|
|
125
|
+
closeList();
|
|
126
|
+
out.push(element);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (openList !== void 0 && openList.numId !== membership.numId) closeList();
|
|
130
|
+
if (openList === void 0) {
|
|
131
|
+
const listElement = require_xml_fragment.el("text:list");
|
|
132
|
+
openList = {
|
|
133
|
+
numId: membership.numId,
|
|
134
|
+
entries: [],
|
|
135
|
+
element: listElement
|
|
136
|
+
};
|
|
137
|
+
out.push(listElement);
|
|
138
|
+
}
|
|
139
|
+
openList.entries.push({
|
|
140
|
+
level: membership.level,
|
|
141
|
+
element
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
closeList();
|
|
145
|
+
return require_xml_fragment.el("draw:text-box", {}, out);
|
|
146
|
+
}
|
|
147
|
+
const PICTURES_DIRECTORY = "Pictures";
|
|
148
|
+
function writeShapeImage(image, state) {
|
|
149
|
+
const extension = require_typed_shared_image.imageExtension(image.format);
|
|
150
|
+
const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
|
|
151
|
+
state.nextImage += 1;
|
|
152
|
+
state.pkg.parts[path] = {
|
|
153
|
+
kind: "binary",
|
|
154
|
+
base64: image.base64
|
|
155
|
+
};
|
|
156
|
+
const children = [require_xml_fragment.el("draw:image", {
|
|
157
|
+
"xlink:href": require_xml_entities.encodeXmlText(path),
|
|
158
|
+
"xlink:type": "simple",
|
|
159
|
+
"xlink:show": "embed",
|
|
160
|
+
"xlink:actuate": "onLoad"
|
|
161
|
+
})];
|
|
162
|
+
if (image.altText !== void 0) children.push(require_xml_fragment.el("svg:title", {}, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(image.altText))]));
|
|
163
|
+
return children;
|
|
164
|
+
}
|
|
165
|
+
function odfZIndexOf(paintOrder) {
|
|
166
|
+
if (paintOrder === void 0 || !Number.isSafeInteger(paintOrder) || paintOrder < 0) return;
|
|
167
|
+
return paintOrder;
|
|
168
|
+
}
|
|
169
|
+
function writeDrawFrame(shape, listState, state, documentIndex) {
|
|
170
|
+
const zIndex = odfZIndexOf(shape.paintOrder) ?? documentIndex;
|
|
171
|
+
const attributes = {
|
|
172
|
+
"draw:z-index": String(zIndex),
|
|
173
|
+
...frameGeometryAttrs(shape.frame, shape.rotationDeg)
|
|
174
|
+
};
|
|
175
|
+
if (shape.name !== void 0) attributes["draw:name"] = require_xml_entities.encodeXmlText(shape.name);
|
|
176
|
+
attributes["draw:style-name"] = require_xml_entities.encodeXmlText(shapeGraphicStyleName(shape, state));
|
|
177
|
+
const content = planShapeContent(shape.blocks, listState);
|
|
178
|
+
const children = content.kind === "table" ? [require_typed_shared_table.writeOdfTable(content.table, state.registry, `DrawTable${state.nextTable++}`)] : content.kind === "image" ? writeShapeImage(content.image, state) : [writeShapeTextBox(content.paragraphs, state)];
|
|
179
|
+
return require_xml_fragment.el("draw:frame", attributes, children);
|
|
180
|
+
}
|
|
181
|
+
function canonicalDrawShape(shape, documentIndex, listState) {
|
|
182
|
+
const content = planShapeContent(shape.blocks, listState);
|
|
183
|
+
const blocks = content.kind === "table" ? [require_typed_shared_canonicalise.canonicalTable(content.table)] : content.kind === "image" ? [{
|
|
184
|
+
...require_typed_shared_canonicalise.canonicalImage(content.image),
|
|
185
|
+
widthPt: shape.frame.widthPt,
|
|
186
|
+
heightPt: shape.frame.heightPt
|
|
187
|
+
}] : content.paragraphs.map((paragraph) => require_typed_shared_canonicalise.canonicalParagraph(paragraph, paragraph.list?.numId));
|
|
188
|
+
const canonical = {
|
|
189
|
+
frame: shape.frame,
|
|
190
|
+
insetLeftPt: shape.insetLeftPt,
|
|
191
|
+
insetTopPt: shape.insetTopPt,
|
|
192
|
+
insetRightPt: shape.insetRightPt,
|
|
193
|
+
insetBottomPt: shape.insetBottomPt,
|
|
194
|
+
paintOrder: odfZIndexOf(shape.paintOrder) ?? documentIndex,
|
|
195
|
+
blocks
|
|
196
|
+
};
|
|
197
|
+
if (shape.name !== void 0) canonical.name = shape.name;
|
|
198
|
+
if (shape.rotationDeg !== void 0 && shape.rotationDeg !== 0) canonical.rotationDeg = shape.rotationDeg;
|
|
199
|
+
return canonical;
|
|
200
|
+
}
|
|
201
|
+
function writeDrawShapes(shapes, listState, state) {
|
|
202
|
+
return shapes.map((shape, index) => writeDrawFrame(shape, listState, state, index));
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
exports.canonicalDrawShape = canonicalDrawShape;
|
|
206
|
+
exports.createDrawShapeWriteState = createDrawShapeWriteState;
|
|
207
|
+
exports.frameGeometryAttrs = frameGeometryAttrs;
|
|
208
|
+
exports.odfZIndexOf = odfZIndexOf;
|
|
209
|
+
exports.planShapeContent = planShapeContent;
|
|
210
|
+
exports.writeDrawFrame = writeDrawFrame;
|
|
211
|
+
exports.writeDrawShapes = writeDrawShapes;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as frameGeometryAttrs, c as writeDrawFrame, i as createDrawShapeWriteState, l as writeDrawShapes, n as ShapeContentPlan, o as odfZIndexOf, r as canonicalDrawShape, s as planShapeContent, t as DrawShapeWriteState } from "../../write-shapes-D4piGKf4.cjs";
|
|
2
|
+
export { DrawShapeWriteState, ShapeContentPlan, canonicalDrawShape, createDrawShapeWriteState, frameGeometryAttrs, odfZIndexOf, planShapeContent, writeDrawFrame, writeDrawShapes };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as frameGeometryAttrs, c as writeDrawFrame, i as createDrawShapeWriteState, l as writeDrawShapes, n as ShapeContentPlan, o as odfZIndexOf, r as canonicalDrawShape, s as planShapeContent, t as DrawShapeWriteState } from "../../write-shapes-Co7BrmMZ.js";
|
|
2
|
+
export { DrawShapeWriteState, ShapeContentPlan, canonicalDrawShape, createDrawShapeWriteState, frameGeometryAttrs, odfZIndexOf, planShapeContent, writeDrawFrame, writeDrawShapes };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { el, txt } from "../../xml/fragment.js";
|
|
2
|
+
import { encodeXmlText } from "../../xml/entities.js";
|
|
3
|
+
import { formatOdfLength, formatOdfNumber } from "../shared/units.js";
|
|
4
|
+
import { buildOdfListStyle, closeListPlan, listKindOf, planListMembership, writeOdfList } from "../shared/list.js";
|
|
5
|
+
import { writeOdfParagraph } from "../shared/paragraph.js";
|
|
6
|
+
import { writeOdfTable } from "../shared/table.js";
|
|
7
|
+
import { imageExtension } from "../shared/image.js";
|
|
8
|
+
import { canonicalImage, canonicalParagraph, canonicalTable } from "../shared/canonicalise.js";
|
|
9
|
+
//#region src/typed/draw/write-shapes.ts
|
|
10
|
+
function unsupportedShapeContent(what) {
|
|
11
|
+
return /* @__PURE__ */ new Error(`writeDrawFrame: a shape carries ${what}, which this writer does not write yet -- refusing rather than producing a document that silently lost it. See ExaDev/documents.js for the tracked follow-up covering the fidelity constructs.`);
|
|
12
|
+
}
|
|
13
|
+
function planShapeContent(blocks, listState) {
|
|
14
|
+
closeListPlan(listState);
|
|
15
|
+
if (blocks.length === 1) {
|
|
16
|
+
const only = blocks[0];
|
|
17
|
+
if (only.kind === "table") return {
|
|
18
|
+
kind: "table",
|
|
19
|
+
table: only
|
|
20
|
+
};
|
|
21
|
+
if (only.kind === "image") return {
|
|
22
|
+
kind: "image",
|
|
23
|
+
image: only
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const paragraphs = [];
|
|
27
|
+
for (const block of blocks) {
|
|
28
|
+
if (block.kind === "table") throw unsupportedShapeContent("a table alongside other content (a draw:frame's own content is exactly one of table:table/draw:text-box/draw:image, never a mix)");
|
|
29
|
+
if (block.kind === "image") throw unsupportedShapeContent("an image alongside other content (same reason)");
|
|
30
|
+
if (block.kind === "pageBreak") throw unsupportedShapeContent("a page break (no ODF spelling inside a shape's own text)");
|
|
31
|
+
if (block.kind === "embeddedObject") throw unsupportedShapeContent("an embedded object");
|
|
32
|
+
if (block.kind === "constructStart" || block.kind === "constructEnd") throw unsupportedShapeContent("a construct boundary marker");
|
|
33
|
+
if (block.constructs !== void 0 && block.constructs.length > 0) throw unsupportedShapeContent("a run-level construct extent (a field, bookmark, note, annotation, or tracked change)");
|
|
34
|
+
if (block.headingLevel !== void 0) throw unsupportedShapeContent("a heading (a shape's own draw:text-box has no text:h reading path)");
|
|
35
|
+
const canonicalId = planListMembership(block.list, listState);
|
|
36
|
+
paragraphs.push(canonicalId === void 0 ? {
|
|
37
|
+
...block,
|
|
38
|
+
list: void 0
|
|
39
|
+
} : {
|
|
40
|
+
...block,
|
|
41
|
+
list: {
|
|
42
|
+
numId: canonicalId,
|
|
43
|
+
level: block.list.level
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
kind: "text",
|
|
49
|
+
paragraphs
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function createDrawShapeWriteState(pkg, registry, contentAutomaticStyles) {
|
|
53
|
+
return {
|
|
54
|
+
pkg,
|
|
55
|
+
registry,
|
|
56
|
+
contentAutomaticStyles,
|
|
57
|
+
nextImage: 1,
|
|
58
|
+
nextTable: 1,
|
|
59
|
+
nextListStyle: 1,
|
|
60
|
+
listStyleByKind: /* @__PURE__ */ new Map()
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function listStyleNameFor(kind, state) {
|
|
64
|
+
const existing = state.listStyleByKind.get(kind);
|
|
65
|
+
if (existing !== void 0) return existing;
|
|
66
|
+
const name = `SL${state.nextListStyle}`;
|
|
67
|
+
state.nextListStyle += 1;
|
|
68
|
+
state.listStyleByKind.set(kind, name);
|
|
69
|
+
state.contentAutomaticStyles.children.push(buildOdfListStyle(name, kind));
|
|
70
|
+
return name;
|
|
71
|
+
}
|
|
72
|
+
function frameGeometryAttrs(frame, rotationDeg) {
|
|
73
|
+
if (rotationDeg === void 0 || rotationDeg === 0) return {
|
|
74
|
+
"svg:x": formatOdfLength(frame.xPt),
|
|
75
|
+
"svg:y": formatOdfLength(frame.yPt),
|
|
76
|
+
"svg:width": formatOdfLength(frame.widthPt),
|
|
77
|
+
"svg:height": formatOdfLength(frame.heightPt)
|
|
78
|
+
};
|
|
79
|
+
const angleRad = -rotationDeg * Math.PI / 180;
|
|
80
|
+
const cos = Math.cos(angleRad);
|
|
81
|
+
const sin = Math.sin(angleRad);
|
|
82
|
+
const halfWidthPt = frame.widthPt / 2;
|
|
83
|
+
const halfHeightPt = frame.heightPt / 2;
|
|
84
|
+
const txPt = frame.xPt + halfWidthPt - halfWidthPt * cos - halfHeightPt * sin;
|
|
85
|
+
const tyPt = frame.yPt + halfHeightPt - halfHeightPt * cos + halfWidthPt * sin;
|
|
86
|
+
return {
|
|
87
|
+
"svg:width": formatOdfLength(frame.widthPt),
|
|
88
|
+
"svg:height": formatOdfLength(frame.heightPt),
|
|
89
|
+
"draw:transform": `rotate(${formatOdfNumber(angleRad)}) translate(${formatOdfLength(txPt)} ${formatOdfLength(tyPt)})`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function shapeGraphicStyleName(shape, state) {
|
|
93
|
+
const properties = {
|
|
94
|
+
"draw:fill": "none",
|
|
95
|
+
"draw:stroke": "none"
|
|
96
|
+
};
|
|
97
|
+
if (shape.insetLeftPt !== 0 || shape.insetTopPt !== 0 || shape.insetRightPt !== 0 || shape.insetBottomPt !== 0) {
|
|
98
|
+
properties["fo:padding-left"] = formatOdfLength(shape.insetLeftPt);
|
|
99
|
+
properties["fo:padding-top"] = formatOdfLength(shape.insetTopPt);
|
|
100
|
+
properties["fo:padding-right"] = formatOdfLength(shape.insetRightPt);
|
|
101
|
+
properties["fo:padding-bottom"] = formatOdfLength(shape.insetBottomPt);
|
|
102
|
+
}
|
|
103
|
+
return state.registry.intern({
|
|
104
|
+
properties: {},
|
|
105
|
+
family: "graphic",
|
|
106
|
+
propertyElements: [el("style:graphic-properties", properties)]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function writeShapeTextBox(paragraphs, state) {
|
|
110
|
+
const out = [];
|
|
111
|
+
let openList;
|
|
112
|
+
const closeList = () => {
|
|
113
|
+
if (openList === void 0) return;
|
|
114
|
+
const kind = listKindOf(openList.numId);
|
|
115
|
+
const built = writeOdfList(openList.entries, kind === void 0 ? void 0 : listStyleNameFor(kind, state));
|
|
116
|
+
openList.element.attributes = built.attributes;
|
|
117
|
+
openList.element.children = built.children;
|
|
118
|
+
openList = void 0;
|
|
119
|
+
};
|
|
120
|
+
for (const paragraph of paragraphs) {
|
|
121
|
+
const element = writeOdfParagraph(paragraph, state.registry);
|
|
122
|
+
const membership = paragraph.list;
|
|
123
|
+
if (membership?.numId === void 0) {
|
|
124
|
+
closeList();
|
|
125
|
+
out.push(element);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (openList !== void 0 && openList.numId !== membership.numId) closeList();
|
|
129
|
+
if (openList === void 0) {
|
|
130
|
+
const listElement = el("text:list");
|
|
131
|
+
openList = {
|
|
132
|
+
numId: membership.numId,
|
|
133
|
+
entries: [],
|
|
134
|
+
element: listElement
|
|
135
|
+
};
|
|
136
|
+
out.push(listElement);
|
|
137
|
+
}
|
|
138
|
+
openList.entries.push({
|
|
139
|
+
level: membership.level,
|
|
140
|
+
element
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
closeList();
|
|
144
|
+
return el("draw:text-box", {}, out);
|
|
145
|
+
}
|
|
146
|
+
const PICTURES_DIRECTORY = "Pictures";
|
|
147
|
+
function writeShapeImage(image, state) {
|
|
148
|
+
const extension = imageExtension(image.format);
|
|
149
|
+
const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
|
|
150
|
+
state.nextImage += 1;
|
|
151
|
+
state.pkg.parts[path] = {
|
|
152
|
+
kind: "binary",
|
|
153
|
+
base64: image.base64
|
|
154
|
+
};
|
|
155
|
+
const children = [el("draw:image", {
|
|
156
|
+
"xlink:href": encodeXmlText(path),
|
|
157
|
+
"xlink:type": "simple",
|
|
158
|
+
"xlink:show": "embed",
|
|
159
|
+
"xlink:actuate": "onLoad"
|
|
160
|
+
})];
|
|
161
|
+
if (image.altText !== void 0) children.push(el("svg:title", {}, [txt(encodeXmlText(image.altText))]));
|
|
162
|
+
return children;
|
|
163
|
+
}
|
|
164
|
+
function odfZIndexOf(paintOrder) {
|
|
165
|
+
if (paintOrder === void 0 || !Number.isSafeInteger(paintOrder) || paintOrder < 0) return;
|
|
166
|
+
return paintOrder;
|
|
167
|
+
}
|
|
168
|
+
function writeDrawFrame(shape, listState, state, documentIndex) {
|
|
169
|
+
const zIndex = odfZIndexOf(shape.paintOrder) ?? documentIndex;
|
|
170
|
+
const attributes = {
|
|
171
|
+
"draw:z-index": String(zIndex),
|
|
172
|
+
...frameGeometryAttrs(shape.frame, shape.rotationDeg)
|
|
173
|
+
};
|
|
174
|
+
if (shape.name !== void 0) attributes["draw:name"] = encodeXmlText(shape.name);
|
|
175
|
+
attributes["draw:style-name"] = encodeXmlText(shapeGraphicStyleName(shape, state));
|
|
176
|
+
const content = planShapeContent(shape.blocks, listState);
|
|
177
|
+
const children = content.kind === "table" ? [writeOdfTable(content.table, state.registry, `DrawTable${state.nextTable++}`)] : content.kind === "image" ? writeShapeImage(content.image, state) : [writeShapeTextBox(content.paragraphs, state)];
|
|
178
|
+
return el("draw:frame", attributes, children);
|
|
179
|
+
}
|
|
180
|
+
function canonicalDrawShape(shape, documentIndex, listState) {
|
|
181
|
+
const content = planShapeContent(shape.blocks, listState);
|
|
182
|
+
const blocks = content.kind === "table" ? [canonicalTable(content.table)] : content.kind === "image" ? [{
|
|
183
|
+
...canonicalImage(content.image),
|
|
184
|
+
widthPt: shape.frame.widthPt,
|
|
185
|
+
heightPt: shape.frame.heightPt
|
|
186
|
+
}] : content.paragraphs.map((paragraph) => canonicalParagraph(paragraph, paragraph.list?.numId));
|
|
187
|
+
const canonical = {
|
|
188
|
+
frame: shape.frame,
|
|
189
|
+
insetLeftPt: shape.insetLeftPt,
|
|
190
|
+
insetTopPt: shape.insetTopPt,
|
|
191
|
+
insetRightPt: shape.insetRightPt,
|
|
192
|
+
insetBottomPt: shape.insetBottomPt,
|
|
193
|
+
paintOrder: odfZIndexOf(shape.paintOrder) ?? documentIndex,
|
|
194
|
+
blocks
|
|
195
|
+
};
|
|
196
|
+
if (shape.name !== void 0) canonical.name = shape.name;
|
|
197
|
+
if (shape.rotationDeg !== void 0 && shape.rotationDeg !== 0) canonical.rotationDeg = shape.rotationDeg;
|
|
198
|
+
return canonical;
|
|
199
|
+
}
|
|
200
|
+
function writeDrawShapes(shapes, listState, state) {
|
|
201
|
+
return shapes.map((shape, index) => writeDrawFrame(shape, listState, state, index));
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
export { canonicalDrawShape, createDrawShapeWriteState, frameGeometryAttrs, odfZIndexOf, planShapeContent, writeDrawFrame, writeDrawShapes };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
3
|
+
const require_xml_entities = require("../../xml/entities.cjs");
|
|
4
|
+
const require_typed_shared_units = require("../shared/units.cjs");
|
|
5
|
+
const require_typed_shared_color = require("../shared/color.cjs");
|
|
6
|
+
const require_typed_shared_path = require("../shared/path.cjs");
|
|
7
|
+
const require_typed_shared_canonicalise = require("../shared/canonicalise.cjs");
|
|
8
|
+
const require_typed_draw_write_shapes = require("./write-shapes.cjs");
|
|
9
|
+
//#region src/typed/draw/write-vectors.ts
|
|
10
|
+
function unsupportedVector(what) {
|
|
11
|
+
return /* @__PURE__ */ new Error(`writeDrawVector: a vector carries ${what}, which ODF has no spelling for -- refusing rather than producing a document that silently lost it or renders differently. See ExaDev/documents.js for the tracked follow-up.`);
|
|
12
|
+
}
|
|
13
|
+
function odfStrokeMode(style) {
|
|
14
|
+
if (style === void 0 || style === "solid") return "solid";
|
|
15
|
+
if (style === "dashed") return "dash";
|
|
16
|
+
throw unsupportedVector(`a '${style}' stroke style (draw:stroke is enumerated to exactly none/solid/dash -- ODF's vector-stroke model has no dotted or double spelling)`);
|
|
17
|
+
}
|
|
18
|
+
function vectorGraphicStyleName(paint, state) {
|
|
19
|
+
const properties = {};
|
|
20
|
+
if (paint.fill === void 0) properties["draw:fill"] = "none";
|
|
21
|
+
else {
|
|
22
|
+
properties["draw:fill"] = "solid";
|
|
23
|
+
properties["draw:fill-color"] = require_typed_shared_color.formatOdfColor(paint.fill);
|
|
24
|
+
}
|
|
25
|
+
if (paint.fillRule !== void 0) properties["svg:fill-rule"] = paint.fillRule;
|
|
26
|
+
if (paint.stroke === void 0) properties["draw:stroke"] = "none";
|
|
27
|
+
else {
|
|
28
|
+
if (!(paint.stroke.widthPt > 0)) throw unsupportedVector(`a stroke of width ${paint.stroke.widthPt}pt (svg:stroke-width must be positive for a stroke to exist at all)`);
|
|
29
|
+
properties["draw:stroke"] = odfStrokeMode(paint.stroke.style);
|
|
30
|
+
properties["svg:stroke-color"] = require_typed_shared_color.formatOdfColor(paint.stroke.color);
|
|
31
|
+
properties["svg:stroke-width"] = require_typed_shared_units.formatOdfLength(paint.stroke.widthPt);
|
|
32
|
+
}
|
|
33
|
+
return state.registry.intern({
|
|
34
|
+
properties: {},
|
|
35
|
+
family: "graphic",
|
|
36
|
+
propertyElements: [require_xml_fragment.el("style:graphic-properties", properties)]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function zIndexAttrs(paintOrder, documentIndex) {
|
|
40
|
+
const zIndex = require_typed_draw_write_shapes.odfZIndexOf(paintOrder) ?? documentIndex;
|
|
41
|
+
return { "draw:z-index": String(zIndex) };
|
|
42
|
+
}
|
|
43
|
+
function writeDrawVector(vector, state, documentIndex) {
|
|
44
|
+
if (vector.kind === "line") {
|
|
45
|
+
const styleName = vectorGraphicStyleName({
|
|
46
|
+
fill: void 0,
|
|
47
|
+
fillRule: void 0,
|
|
48
|
+
stroke: vector.stroke
|
|
49
|
+
}, state);
|
|
50
|
+
return require_xml_fragment.el("draw:line", {
|
|
51
|
+
...zIndexAttrs(vector.paintOrder, documentIndex),
|
|
52
|
+
"svg:x1": require_typed_shared_units.formatOdfLength(vector.from.xPt),
|
|
53
|
+
"svg:y1": require_typed_shared_units.formatOdfLength(vector.from.yPt),
|
|
54
|
+
"svg:x2": require_typed_shared_units.formatOdfLength(vector.to.xPt),
|
|
55
|
+
"svg:y2": require_typed_shared_units.formatOdfLength(vector.to.yPt),
|
|
56
|
+
"draw:style-name": require_xml_entities.encodeXmlText(styleName)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (vector.kind === "path") {
|
|
60
|
+
if (vector.subpaths.length === 0) throw unsupportedVector("no subpaths at all (an empty svg:d reads back as an element with no resolvable geometry, so the whole vector would vanish)");
|
|
61
|
+
if (!(vector.frame.widthPt > 0) || !(vector.frame.heightPt > 0)) throw unsupportedVector(`a frame of ${vector.frame.widthPt}pt x ${vector.frame.heightPt}pt (a path's svg:viewBox states the extent its own coordinates are scaled against, which cannot be zero or negative)`);
|
|
62
|
+
const styleName = vectorGraphicStyleName({
|
|
63
|
+
fill: vector.fill,
|
|
64
|
+
fillRule: vector.fillRule,
|
|
65
|
+
stroke: vector.stroke
|
|
66
|
+
}, state);
|
|
67
|
+
return require_xml_fragment.el("draw:path", {
|
|
68
|
+
...zIndexAttrs(vector.paintOrder, documentIndex),
|
|
69
|
+
...require_typed_draw_write_shapes.frameGeometryAttrs(vector.frame, vector.rotationDeg),
|
|
70
|
+
"svg:viewBox": require_typed_shared_path.formatOdfViewBox(vector.frame),
|
|
71
|
+
"svg:d": require_typed_shared_path.formatOdfPathData(vector.subpaths),
|
|
72
|
+
"draw:style-name": require_xml_entities.encodeXmlText(styleName)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const styleName = vectorGraphicStyleName({
|
|
76
|
+
fill: vector.fill,
|
|
77
|
+
fillRule: void 0,
|
|
78
|
+
stroke: vector.stroke
|
|
79
|
+
}, state);
|
|
80
|
+
return require_xml_fragment.el(vector.kind === "rect" ? "draw:rect" : "draw:ellipse", {
|
|
81
|
+
...zIndexAttrs(vector.paintOrder, documentIndex),
|
|
82
|
+
...require_typed_draw_write_shapes.frameGeometryAttrs(vector.frame, vector.rotationDeg),
|
|
83
|
+
"draw:style-name": require_xml_entities.encodeXmlText(styleName)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function writeDrawVectors(vectors, state, baseIndex) {
|
|
87
|
+
return vectors.map((vector, index) => writeDrawVector(vector, state, baseIndex + index));
|
|
88
|
+
}
|
|
89
|
+
function canonicalDrawVector(vector, documentIndex) {
|
|
90
|
+
const paintOrder = require_typed_draw_write_shapes.odfZIndexOf(vector.paintOrder) ?? documentIndex;
|
|
91
|
+
if (vector.kind === "line") return {
|
|
92
|
+
kind: "line",
|
|
93
|
+
from: vector.from,
|
|
94
|
+
to: vector.to,
|
|
95
|
+
stroke: canonicalStroke(vector.stroke),
|
|
96
|
+
paintOrder
|
|
97
|
+
};
|
|
98
|
+
const paint = {
|
|
99
|
+
...vector.rotationDeg !== void 0 && vector.rotationDeg !== 0 ? { rotationDeg: vector.rotationDeg } : {},
|
|
100
|
+
...vector.fill !== void 0 ? { fill: require_typed_shared_canonicalise.canonicalColor(vector.fill) } : {},
|
|
101
|
+
...vector.stroke !== void 0 ? { stroke: canonicalStroke(vector.stroke) } : {}
|
|
102
|
+
};
|
|
103
|
+
if (vector.kind === "path") return {
|
|
104
|
+
kind: "path",
|
|
105
|
+
frame: vector.frame,
|
|
106
|
+
subpaths: vector.subpaths.map((subpath) => ({
|
|
107
|
+
start: subpath.start,
|
|
108
|
+
segments: [...subpath.segments],
|
|
109
|
+
closed: subpath.closed
|
|
110
|
+
})),
|
|
111
|
+
...vector.fillRule !== void 0 ? { fillRule: vector.fillRule } : {},
|
|
112
|
+
...paint,
|
|
113
|
+
paintOrder
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
kind: vector.kind,
|
|
117
|
+
frame: vector.frame,
|
|
118
|
+
...paint,
|
|
119
|
+
paintOrder
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function canonicalStroke(stroke) {
|
|
123
|
+
return {
|
|
124
|
+
color: require_typed_shared_canonicalise.canonicalColor(stroke.color),
|
|
125
|
+
widthPt: stroke.widthPt,
|
|
126
|
+
style: stroke.style ?? "solid"
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
exports.canonicalDrawVector = canonicalDrawVector;
|
|
131
|
+
exports.writeDrawVector = writeDrawVector;
|
|
132
|
+
exports.writeDrawVectors = writeDrawVectors;
|