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.
Files changed (140) hide show
  1. package/README.md +172 -18
  2. package/dist/{codec-BnzBd5_I.d.cts → codec-CFdlbFLJ.d.cts} +16 -10
  3. package/dist/{codec-Dg_HWuH1.d.ts → codec-DTAgph2r.d.ts} +16 -10
  4. package/dist/codec.d.cts +1 -1
  5. package/dist/codec.d.ts +1 -1
  6. package/dist/{embedded-BONPxvS3.js → embedded-BnavfkP-.js} +3 -3
  7. package/dist/{embedded-wrtHCJ68.cjs → embedded-Bxyss_ck.cjs} +14 -2
  8. package/dist/image/sniff.cjs +26 -0
  9. package/dist/image/sniff.d.cts +1 -1
  10. package/dist/image/sniff.d.ts +1 -1
  11. package/dist/image/sniff.js +26 -0
  12. package/dist/index.cjs +34 -1
  13. package/dist/index.d.cts +20 -14
  14. package/dist/index.d.ts +20 -14
  15. package/dist/index.js +12 -6
  16. package/dist/{list-vhXd0Jf6.d.ts → list-7FO0SDqZ.d.ts} +14 -1
  17. package/dist/{list-Bttwr1mk.d.cts → list-BorrTJBY.d.cts} +14 -1
  18. package/dist/manifest.cjs +2 -0
  19. package/dist/manifest.js +2 -0
  20. package/dist/{ns-C14w-Zhf.d.cts → ns-DrleaIZQ.d.cts} +3 -1
  21. package/dist/{ns-CTyKJZeF.d.ts → ns-E0TfX9tZ.d.ts} +3 -1
  22. package/dist/ooo1/ns.cjs +9 -0
  23. package/dist/ooo1/ns.d.cts +2 -2
  24. package/dist/ooo1/ns.d.ts +2 -2
  25. package/dist/ooo1/ns.js +8 -1
  26. package/dist/ooo1/properties.cjs +30 -0
  27. package/dist/ooo1/properties.d.cts +6 -2
  28. package/dist/ooo1/properties.d.ts +6 -2
  29. package/dist/ooo1/properties.js +30 -1
  30. package/dist/ooo1/read.cjs +1 -1
  31. package/dist/ooo1/read.d.cts +1 -1
  32. package/dist/ooo1/read.d.ts +1 -1
  33. package/dist/ooo1/read.js +1 -1
  34. package/dist/ooo1/transform.cjs +290 -0
  35. package/dist/ooo1/transform.d.cts +2 -2
  36. package/dist/ooo1/transform.d.ts +2 -2
  37. package/dist/ooo1/transform.js +293 -4
  38. package/dist/ooo1/write.cjs +40 -0
  39. package/dist/ooo1/write.d.cts +2 -0
  40. package/dist/ooo1/write.d.ts +2 -0
  41. package/dist/ooo1/write.js +32 -0
  42. package/dist/package-io/scaffold.cjs +2 -1
  43. package/dist/package-io/scaffold.js +2 -1
  44. package/dist/{paragraph-BdwsQisB.d.cts → paragraph-Bf6Iq5wC.d.cts} +1 -1
  45. package/dist/{paragraph-BoVy1LrN.d.ts → paragraph-DtC86tft.d.ts} +1 -1
  46. package/dist/{path-CK0dIPgx.d.cts → path-8HQS-J7y.d.cts} +3 -1
  47. package/dist/{path-CK0dIPgx.d.ts → path-8HQS-J7y.d.ts} +3 -1
  48. package/dist/{read-Bo1GBjSE.d.ts → read-A3CJkqVM.d.ts} +3 -1
  49. package/dist/{read-RFqq4ckj.d.cts → read-BgnLFuSi.d.cts} +1 -1
  50. package/dist/{read-3yy5EFV_.d.ts → read-CqaZ01kU.d.ts} +1 -1
  51. package/dist/{read-tpfiT_n4.d.cts → read-fphkvCpR.d.cts} +3 -1
  52. package/dist/{shapes-DUzrrf7b.d.ts → shapes-B6Ms7ibr.d.ts} +1 -1
  53. package/dist/{shapes-BQhXAk0D.d.cts → shapes-CbBc9t0y.d.cts} +1 -1
  54. package/dist/{sniff-DGOBHA0O.d.cts → sniff-eR8lObzF.d.cts} +1 -1
  55. package/dist/{sniff-DGOBHA0O.d.ts → sniff-eR8lObzF.d.ts} +1 -1
  56. package/dist/{table-ByhqRnSG.d.cts → table-CECMtPxZ.d.cts} +6 -2
  57. package/dist/{table-DElqGcT0.d.ts → table-XuniPr2I.d.ts} +6 -2
  58. package/dist/{transform-SDysw9wx.d.cts → transform-DFCPKX7e.d.cts} +2 -1
  59. package/dist/{transform-DRr76JEu.d.ts → transform-DPliWQuD.d.ts} +2 -1
  60. package/dist/typed/draw/embedded.cjs +1 -1
  61. package/dist/typed/draw/embedded.js +1 -1
  62. package/dist/typed/draw/shapes.cjs +7 -2
  63. package/dist/typed/draw/shapes.d.cts +1 -1
  64. package/dist/typed/draw/shapes.d.ts +1 -1
  65. package/dist/typed/draw/shapes.js +7 -2
  66. package/dist/typed/draw/write-shapes.cjs +211 -0
  67. package/dist/typed/draw/write-shapes.d.cts +2 -0
  68. package/dist/typed/draw/write-shapes.d.ts +2 -0
  69. package/dist/typed/draw/write-shapes.js +204 -0
  70. package/dist/typed/draw/write-vectors.cjs +132 -0
  71. package/dist/typed/draw/write-vectors.d.cts +2 -0
  72. package/dist/typed/draw/write-vectors.d.ts +2 -0
  73. package/dist/typed/draw/write-vectors.js +129 -0
  74. package/dist/typed/odb/form.cjs +1 -1
  75. package/dist/typed/odb/form.js +1 -1
  76. package/dist/typed/odg/write.cjs +80 -0
  77. package/dist/typed/odg/write.d.cts +2 -0
  78. package/dist/typed/odg/write.d.ts +2 -0
  79. package/dist/typed/odg/write.js +77 -0
  80. package/dist/typed/odp/write.cjs +108 -0
  81. package/dist/typed/odp/write.d.cts +2 -0
  82. package/dist/typed/odp/write.d.ts +2 -0
  83. package/dist/typed/odp/write.js +105 -0
  84. package/dist/typed/ods/read.cjs +3 -1
  85. package/dist/typed/ods/read.d.cts +2 -2
  86. package/dist/typed/ods/read.d.ts +2 -2
  87. package/dist/typed/ods/read.js +2 -2
  88. package/dist/typed/ods/write.cjs +579 -0
  89. package/dist/typed/ods/write.d.cts +2 -0
  90. package/dist/typed/ods/write.d.ts +2 -0
  91. package/dist/typed/ods/write.js +576 -0
  92. package/dist/typed/odt/read.cjs +1 -1
  93. package/dist/typed/odt/read.js +1 -1
  94. package/dist/typed/odt/write.cjs +11 -141
  95. package/dist/typed/odt/write.d.cts +1 -1
  96. package/dist/typed/odt/write.d.ts +1 -1
  97. package/dist/typed/odt/write.js +10 -140
  98. package/dist/typed/shared/canonicalise.cjs +126 -0
  99. package/dist/typed/shared/canonicalise.d.cts +10 -0
  100. package/dist/typed/shared/canonicalise.d.ts +10 -0
  101. package/dist/typed/shared/canonicalise.js +120 -0
  102. package/dist/typed/shared/image.cjs +12 -0
  103. package/dist/typed/shared/image.d.cts +5 -0
  104. package/dist/typed/shared/image.d.ts +5 -0
  105. package/dist/typed/shared/image.js +11 -0
  106. package/dist/typed/shared/list.cjs +32 -0
  107. package/dist/typed/shared/list.d.cts +2 -2
  108. package/dist/typed/shared/list.d.ts +2 -2
  109. package/dist/typed/shared/list.js +28 -1
  110. package/dist/typed/shared/paragraph.d.cts +1 -1
  111. package/dist/typed/shared/paragraph.d.ts +1 -1
  112. package/dist/typed/shared/path.cjs +19 -0
  113. package/dist/typed/shared/path.d.cts +2 -2
  114. package/dist/typed/shared/path.d.ts +2 -2
  115. package/dist/typed/shared/path.js +18 -1
  116. package/dist/typed/shared/table.cjs +3 -0
  117. package/dist/typed/shared/table.d.cts +2 -2
  118. package/dist/typed/shared/table.d.ts +2 -2
  119. package/dist/typed/shared/table.js +1 -1
  120. package/dist/typed/shared/units.cjs +16 -1
  121. package/dist/typed/shared/units.d.cts +2 -2
  122. package/dist/typed/shared/units.d.ts +2 -2
  123. package/dist/typed/shared/units.js +16 -2
  124. package/dist/{units-BQSNkTQZ.d.cts → units-DdyaQolR.d.cts} +2 -1
  125. package/dist/{units-BQSNkTQZ.d.ts → units-DdyaQolR.d.ts} +2 -1
  126. package/dist/write-4kMi-asu.d.ts +14 -0
  127. package/dist/write-BZXpT8F6.d.cts +17 -0
  128. package/dist/write-BhG3t3fJ.d.cts +14 -0
  129. package/dist/write-BuLQmwLD.d.cts +14 -0
  130. package/dist/write-C2c4xBXs.d.cts +14 -0
  131. package/dist/{write-7Uu_wlkL.d.cts → write-CPATqG4v.d.cts} +1 -0
  132. package/dist/write-CfTE2jY8.d.ts +14 -0
  133. package/dist/write-DttX1rTC.d.ts +14 -0
  134. package/dist/{write-DGcI9W7Z.d.ts → write-JERychL3.d.ts} +1 -0
  135. package/dist/write-SKnCTU4C.d.ts +17 -0
  136. package/dist/write-shapes-Co7BrmMZ.d.ts +36 -0
  137. package/dist/write-shapes-D4piGKf4.d.cts +36 -0
  138. package/dist/write-vectors-B-RVHAKI.d.cts +11 -0
  139. package/dist/write-vectors-CYjZoVBW.d.ts +11 -0
  140. package/package.json +2 -2
@@ -0,0 +1,129 @@
1
+ import { el } from "../../xml/fragment.js";
2
+ import { encodeXmlText } from "../../xml/entities.js";
3
+ import { formatOdfLength } from "../shared/units.js";
4
+ import { formatOdfColor } from "../shared/color.js";
5
+ import { formatOdfPathData, formatOdfViewBox } from "../shared/path.js";
6
+ import { canonicalColor } from "../shared/canonicalise.js";
7
+ import { frameGeometryAttrs, odfZIndexOf } from "./write-shapes.js";
8
+ //#region src/typed/draw/write-vectors.ts
9
+ function unsupportedVector(what) {
10
+ 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.`);
11
+ }
12
+ function odfStrokeMode(style) {
13
+ if (style === void 0 || style === "solid") return "solid";
14
+ if (style === "dashed") return "dash";
15
+ 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)`);
16
+ }
17
+ function vectorGraphicStyleName(paint, state) {
18
+ const properties = {};
19
+ if (paint.fill === void 0) properties["draw:fill"] = "none";
20
+ else {
21
+ properties["draw:fill"] = "solid";
22
+ properties["draw:fill-color"] = formatOdfColor(paint.fill);
23
+ }
24
+ if (paint.fillRule !== void 0) properties["svg:fill-rule"] = paint.fillRule;
25
+ if (paint.stroke === void 0) properties["draw:stroke"] = "none";
26
+ else {
27
+ 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)`);
28
+ properties["draw:stroke"] = odfStrokeMode(paint.stroke.style);
29
+ properties["svg:stroke-color"] = formatOdfColor(paint.stroke.color);
30
+ properties["svg:stroke-width"] = formatOdfLength(paint.stroke.widthPt);
31
+ }
32
+ return state.registry.intern({
33
+ properties: {},
34
+ family: "graphic",
35
+ propertyElements: [el("style:graphic-properties", properties)]
36
+ });
37
+ }
38
+ function zIndexAttrs(paintOrder, documentIndex) {
39
+ const zIndex = odfZIndexOf(paintOrder) ?? documentIndex;
40
+ return { "draw:z-index": String(zIndex) };
41
+ }
42
+ function writeDrawVector(vector, state, documentIndex) {
43
+ if (vector.kind === "line") {
44
+ const styleName = vectorGraphicStyleName({
45
+ fill: void 0,
46
+ fillRule: void 0,
47
+ stroke: vector.stroke
48
+ }, state);
49
+ return el("draw:line", {
50
+ ...zIndexAttrs(vector.paintOrder, documentIndex),
51
+ "svg:x1": formatOdfLength(vector.from.xPt),
52
+ "svg:y1": formatOdfLength(vector.from.yPt),
53
+ "svg:x2": formatOdfLength(vector.to.xPt),
54
+ "svg:y2": formatOdfLength(vector.to.yPt),
55
+ "draw:style-name": encodeXmlText(styleName)
56
+ });
57
+ }
58
+ if (vector.kind === "path") {
59
+ 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)");
60
+ 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)`);
61
+ const styleName = vectorGraphicStyleName({
62
+ fill: vector.fill,
63
+ fillRule: vector.fillRule,
64
+ stroke: vector.stroke
65
+ }, state);
66
+ return el("draw:path", {
67
+ ...zIndexAttrs(vector.paintOrder, documentIndex),
68
+ ...frameGeometryAttrs(vector.frame, vector.rotationDeg),
69
+ "svg:viewBox": formatOdfViewBox(vector.frame),
70
+ "svg:d": formatOdfPathData(vector.subpaths),
71
+ "draw:style-name": encodeXmlText(styleName)
72
+ });
73
+ }
74
+ const styleName = vectorGraphicStyleName({
75
+ fill: vector.fill,
76
+ fillRule: void 0,
77
+ stroke: vector.stroke
78
+ }, state);
79
+ return el(vector.kind === "rect" ? "draw:rect" : "draw:ellipse", {
80
+ ...zIndexAttrs(vector.paintOrder, documentIndex),
81
+ ...frameGeometryAttrs(vector.frame, vector.rotationDeg),
82
+ "draw:style-name": encodeXmlText(styleName)
83
+ });
84
+ }
85
+ function writeDrawVectors(vectors, state, baseIndex) {
86
+ return vectors.map((vector, index) => writeDrawVector(vector, state, baseIndex + index));
87
+ }
88
+ function canonicalDrawVector(vector, documentIndex) {
89
+ const paintOrder = odfZIndexOf(vector.paintOrder) ?? documentIndex;
90
+ if (vector.kind === "line") return {
91
+ kind: "line",
92
+ from: vector.from,
93
+ to: vector.to,
94
+ stroke: canonicalStroke(vector.stroke),
95
+ paintOrder
96
+ };
97
+ const paint = {
98
+ ...vector.rotationDeg !== void 0 && vector.rotationDeg !== 0 ? { rotationDeg: vector.rotationDeg } : {},
99
+ ...vector.fill !== void 0 ? { fill: canonicalColor(vector.fill) } : {},
100
+ ...vector.stroke !== void 0 ? { stroke: canonicalStroke(vector.stroke) } : {}
101
+ };
102
+ if (vector.kind === "path") return {
103
+ kind: "path",
104
+ frame: vector.frame,
105
+ subpaths: vector.subpaths.map((subpath) => ({
106
+ start: subpath.start,
107
+ segments: [...subpath.segments],
108
+ closed: subpath.closed
109
+ })),
110
+ ...vector.fillRule !== void 0 ? { fillRule: vector.fillRule } : {},
111
+ ...paint,
112
+ paintOrder
113
+ };
114
+ return {
115
+ kind: vector.kind,
116
+ frame: vector.frame,
117
+ ...paint,
118
+ paintOrder
119
+ };
120
+ }
121
+ function canonicalStroke(stroke) {
122
+ return {
123
+ color: canonicalColor(stroke.color),
124
+ widthPt: stroke.widthPt,
125
+ style: stroke.style ?? "solid"
126
+ };
127
+ }
128
+ //#endregion
129
+ export { canonicalDrawVector, writeDrawVector, writeDrawVectors };
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_xml_query = require("../../xml/query.cjs");
3
3
  const require_typed_odb_subdocument = require("./subdocument.cjs");
4
- const require_embedded = require("../../embedded-wrtHCJ68.cjs");
4
+ const require_embedded = require("../../embedded-Bxyss_ck.cjs");
5
5
  const require_typed_shared_forms = require("../shared/forms.cjs");
6
6
  const require_typed_odb_read = require("./read.cjs");
7
7
  //#region src/typed/odb/form.ts
@@ -1,6 +1,6 @@
1
1
  import { findChildElement, rootElement } from "../../xml/query.js";
2
2
  import { subDocumentPackage } from "./subdocument.js";
3
- import { a as readOdtContent } from "../../embedded-BONPxvS3.js";
3
+ import { a as readOdtContent } from "../../embedded-BnavfkP-.js";
4
4
  import { readOdfFormDefinitions } from "../shared/forms.js";
5
5
  import { resolveOdbComponent } from "./read.js";
6
6
  //#region src/typed/odb/form.ts
@@ -0,0 +1,80 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_media_type = require("../../media-type.cjs");
3
+ const require_xml_fragment = require("../../xml/fragment.cjs");
4
+ const require_xml_entities = require("../../xml/entities.cjs");
5
+ const require_manifest = require("../../manifest.cjs");
6
+ const require_typed_shared_units = require("../shared/units.cjs");
7
+ const require_styles_registry = require("../../styles/registry.cjs");
8
+ const require_typed_shared_metadata = require("../shared/metadata.cjs");
9
+ const require_package_io_scaffold = require("../../package-io/scaffold.cjs");
10
+ const require_typed_shared_canonicalise = require("../shared/canonicalise.cjs");
11
+ const require_typed_draw_write_shapes = require("../draw/write-shapes.cjs");
12
+ const require_typed_draw_write_vectors = require("../draw/write-vectors.cjs");
13
+ let document_schema_js = require("document-schema.js");
14
+ //#region src/typed/odg/write.ts
15
+ const CONTENT_PART = "content.xml";
16
+ const STYLES_PART = "styles.xml";
17
+ function sortByPaintOrder(items) {
18
+ return items.slice().sort((a, b) => a.paintOrder - b.paintOrder);
19
+ }
20
+ function canonicalPage(page, listState) {
21
+ const shapes = page.shapes.map((shape, index) => require_typed_draw_write_shapes.canonicalDrawShape(shape, index, listState));
22
+ const vectors = page.vectors.map((vector, index) => require_typed_draw_write_vectors.canonicalDrawVector(vector, page.shapes.length + index));
23
+ return {
24
+ size: page.size,
25
+ shapes: sortByPaintOrder(shapes),
26
+ vectors: sortByPaintOrder(vectors)
27
+ };
28
+ }
29
+ function normaliseOdgContent(document) {
30
+ if (document.kind !== "drawing") throw new Error(`normaliseOdgContent: expected a 'drawing' document, got '${document.kind}'`);
31
+ const listState = { next: 1 };
32
+ return {
33
+ kind: "drawing",
34
+ metadata: require_typed_shared_canonicalise.canonicalMetadata(document.metadata),
35
+ pages: document.pages.map((page) => canonicalPage(page, listState))
36
+ };
37
+ }
38
+ function drawPageLayoutElement(name, pageSize) {
39
+ return require_xml_fragment.el("style:page-layout", { "style:name": require_xml_entities.encodeXmlText(name) }, [require_xml_fragment.el("style:page-layout-properties", {
40
+ "fo:page-width": require_typed_shared_units.formatOdfLength(pageSize.widthPt),
41
+ "fo:page-height": require_typed_shared_units.formatOdfLength(pageSize.heightPt),
42
+ "style:print-orientation": pageSize.widthPt > pageSize.heightPt ? "landscape" : "portrait"
43
+ })]);
44
+ }
45
+ function writeOdgContent(document, options = {}) {
46
+ if (document.kind !== "drawing") throw new Error(`writeOdgContent: expected a 'drawing' document, got '${document.kind}' -- odf.js writes .odg from the drawing arm only`);
47
+ const version = options.version ?? "1.3";
48
+ const drawingElement = require_xml_fragment.el("office:drawing");
49
+ const pkg = require_package_io_scaffold.createOdfPackage(options.template ? require_media_type.ODF_MEDIA_TYPES.otg : require_media_type.ODF_MEDIA_TYPES.odg, drawingElement, version);
50
+ const registry = require_styles_registry.StyleRegistry.forPart(pkg, CONTENT_PART, { otherPart: {
51
+ pkg,
52
+ partPath: STYLES_PART
53
+ } });
54
+ const contentAutomaticStyles = require_package_io_scaffold.odfPartContainer(pkg, CONTENT_PART, "office:automatic-styles");
55
+ const stylesAutomaticStyles = require_package_io_scaffold.odfPartContainer(pkg, STYLES_PART, "office:automatic-styles");
56
+ const masterStyles = require_package_io_scaffold.odfPartContainer(pkg, STYLES_PART, "office:master-styles");
57
+ const shapeState = require_typed_draw_write_shapes.createDrawShapeWriteState(pkg, registry, contentAutomaticStyles);
58
+ const listState = { next: 1 };
59
+ document.pages.forEach((page, index) => {
60
+ const masterPageName = `MP${index + 1}`;
61
+ const pageLayoutName = `PM${index + 1}`;
62
+ stylesAutomaticStyles.children.push(drawPageLayoutElement(pageLayoutName, page.size));
63
+ masterStyles.children.push(require_xml_fragment.el("style:master-page", {
64
+ "style:name": require_xml_entities.encodeXmlText(masterPageName),
65
+ "style:page-layout-name": require_xml_entities.encodeXmlText(pageLayoutName)
66
+ }));
67
+ const children = [...require_typed_draw_write_shapes.writeDrawShapes(page.shapes, listState, shapeState), ...require_typed_draw_write_vectors.writeDrawVectors(page.vectors, shapeState, page.shapes.length)];
68
+ drawingElement.children.push(require_xml_fragment.el("draw:page", { "draw:master-page-name": require_xml_entities.encodeXmlText(masterPageName) }, children));
69
+ });
70
+ require_typed_shared_metadata.writeOdfMetadata(pkg, document.metadata, version);
71
+ require_manifest.syncManifest(pkg, { version });
72
+ return pkg;
73
+ }
74
+ function writeOdg(document, options = {}) {
75
+ return writeOdgContent((0, document_schema_js.flattenTree)(document), options);
76
+ }
77
+ //#endregion
78
+ exports.normaliseOdgContent = normaliseOdgContent;
79
+ exports.writeOdg = writeOdg;
80
+ exports.writeOdgContent = writeOdgContent;
@@ -0,0 +1,2 @@
1
+ import { i as writeOdgContent, n as normaliseOdgContent, r as writeOdg, t as OdgWriteOptions } from "../../write-C2c4xBXs.cjs";
2
+ export { OdgWriteOptions, normaliseOdgContent, writeOdg, writeOdgContent };
@@ -0,0 +1,2 @@
1
+ import { i as writeOdgContent, n as normaliseOdgContent, r as writeOdg, t as OdgWriteOptions } from "../../write-4kMi-asu.js";
2
+ export { OdgWriteOptions, normaliseOdgContent, writeOdg, writeOdgContent };
@@ -0,0 +1,77 @@
1
+ import { ODF_MEDIA_TYPES } from "../../media-type.js";
2
+ import { el } from "../../xml/fragment.js";
3
+ import { encodeXmlText } from "../../xml/entities.js";
4
+ import { syncManifest } from "../../manifest.js";
5
+ import { formatOdfLength } from "../shared/units.js";
6
+ import { StyleRegistry } from "../../styles/registry.js";
7
+ import { writeOdfMetadata } from "../shared/metadata.js";
8
+ import { createOdfPackage, odfPartContainer } from "../../package-io/scaffold.js";
9
+ import { canonicalMetadata } from "../shared/canonicalise.js";
10
+ import { canonicalDrawShape, createDrawShapeWriteState, writeDrawShapes } from "../draw/write-shapes.js";
11
+ import { canonicalDrawVector, writeDrawVectors } from "../draw/write-vectors.js";
12
+ import { flattenTree } from "document-schema.js";
13
+ //#region src/typed/odg/write.ts
14
+ const CONTENT_PART = "content.xml";
15
+ const STYLES_PART = "styles.xml";
16
+ function sortByPaintOrder(items) {
17
+ return items.slice().sort((a, b) => a.paintOrder - b.paintOrder);
18
+ }
19
+ function canonicalPage(page, listState) {
20
+ const shapes = page.shapes.map((shape, index) => canonicalDrawShape(shape, index, listState));
21
+ const vectors = page.vectors.map((vector, index) => canonicalDrawVector(vector, page.shapes.length + index));
22
+ return {
23
+ size: page.size,
24
+ shapes: sortByPaintOrder(shapes),
25
+ vectors: sortByPaintOrder(vectors)
26
+ };
27
+ }
28
+ function normaliseOdgContent(document) {
29
+ if (document.kind !== "drawing") throw new Error(`normaliseOdgContent: expected a 'drawing' document, got '${document.kind}'`);
30
+ const listState = { next: 1 };
31
+ return {
32
+ kind: "drawing",
33
+ metadata: canonicalMetadata(document.metadata),
34
+ pages: document.pages.map((page) => canonicalPage(page, listState))
35
+ };
36
+ }
37
+ function drawPageLayoutElement(name, pageSize) {
38
+ return el("style:page-layout", { "style:name": encodeXmlText(name) }, [el("style:page-layout-properties", {
39
+ "fo:page-width": formatOdfLength(pageSize.widthPt),
40
+ "fo:page-height": formatOdfLength(pageSize.heightPt),
41
+ "style:print-orientation": pageSize.widthPt > pageSize.heightPt ? "landscape" : "portrait"
42
+ })]);
43
+ }
44
+ function writeOdgContent(document, options = {}) {
45
+ if (document.kind !== "drawing") throw new Error(`writeOdgContent: expected a 'drawing' document, got '${document.kind}' -- odf.js writes .odg from the drawing arm only`);
46
+ const version = options.version ?? "1.3";
47
+ const drawingElement = el("office:drawing");
48
+ const pkg = createOdfPackage(options.template ? ODF_MEDIA_TYPES.otg : ODF_MEDIA_TYPES.odg, drawingElement, version);
49
+ const registry = StyleRegistry.forPart(pkg, CONTENT_PART, { otherPart: {
50
+ pkg,
51
+ partPath: STYLES_PART
52
+ } });
53
+ const contentAutomaticStyles = odfPartContainer(pkg, CONTENT_PART, "office:automatic-styles");
54
+ const stylesAutomaticStyles = odfPartContainer(pkg, STYLES_PART, "office:automatic-styles");
55
+ const masterStyles = odfPartContainer(pkg, STYLES_PART, "office:master-styles");
56
+ const shapeState = createDrawShapeWriteState(pkg, registry, contentAutomaticStyles);
57
+ const listState = { next: 1 };
58
+ document.pages.forEach((page, index) => {
59
+ const masterPageName = `MP${index + 1}`;
60
+ const pageLayoutName = `PM${index + 1}`;
61
+ stylesAutomaticStyles.children.push(drawPageLayoutElement(pageLayoutName, page.size));
62
+ masterStyles.children.push(el("style:master-page", {
63
+ "style:name": encodeXmlText(masterPageName),
64
+ "style:page-layout-name": encodeXmlText(pageLayoutName)
65
+ }));
66
+ const children = [...writeDrawShapes(page.shapes, listState, shapeState), ...writeDrawVectors(page.vectors, shapeState, page.shapes.length)];
67
+ drawingElement.children.push(el("draw:page", { "draw:master-page-name": encodeXmlText(masterPageName) }, children));
68
+ });
69
+ writeOdfMetadata(pkg, document.metadata, version);
70
+ syncManifest(pkg, { version });
71
+ return pkg;
72
+ }
73
+ function writeOdg(document, options = {}) {
74
+ return writeOdgContent(flattenTree(document), options);
75
+ }
76
+ //#endregion
77
+ export { normaliseOdgContent, writeOdg, writeOdgContent };
@@ -0,0 +1,108 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_media_type = require("../../media-type.cjs");
3
+ const require_xml_fragment = require("../../xml/fragment.cjs");
4
+ const require_xml_entities = require("../../xml/entities.cjs");
5
+ const require_manifest = require("../../manifest.cjs");
6
+ const require_typed_shared_units = require("../shared/units.cjs");
7
+ const require_styles_registry = require("../../styles/registry.cjs");
8
+ const require_typed_shared_text = require("../shared/text.cjs");
9
+ const require_typed_shared_metadata = require("../shared/metadata.cjs");
10
+ const require_package_io_scaffold = require("../../package-io/scaffold.cjs");
11
+ const require_typed_shared_canonicalise = require("../shared/canonicalise.cjs");
12
+ const require_typed_draw_write_shapes = require("../draw/write-shapes.cjs");
13
+ let document_schema_js = require("document-schema.js");
14
+ //#region src/typed/odp/write.ts
15
+ const CONTENT_PART = "content.xml";
16
+ const STYLES_PART = "styles.xml";
17
+ function canonicalSlide(slide, listState) {
18
+ return {
19
+ size: slide.size,
20
+ shapes: slide.shapes.map((shape, index) => require_typed_draw_write_shapes.canonicalDrawShape(shape, index, listState)),
21
+ notes: slide.notes
22
+ };
23
+ }
24
+ function normaliseOdpContent(document) {
25
+ if (document.kind !== "presentation") throw new Error(`normaliseOdpContent: expected a 'presentation' document, got '${document.kind}'`);
26
+ const listState = { next: 1 };
27
+ return {
28
+ kind: "presentation",
29
+ metadata: require_typed_shared_canonicalise.canonicalMetadata(document.metadata),
30
+ slides: document.slides.map((slide) => canonicalSlide(slide, listState))
31
+ };
32
+ }
33
+ function slidePageLayoutElement(name, pageSize) {
34
+ return require_xml_fragment.el("style:page-layout", { "style:name": require_xml_entities.encodeXmlText(name) }, [require_xml_fragment.el("style:page-layout-properties", {
35
+ "fo:page-width": require_typed_shared_units.formatOdfLength(pageSize.widthPt),
36
+ "fo:page-height": require_typed_shared_units.formatOdfLength(pageSize.heightPt),
37
+ "style:print-orientation": pageSize.widthPt > pageSize.heightPt ? "landscape" : "portrait"
38
+ })]);
39
+ }
40
+ const NOTES_FRAME_BOX = {
41
+ xPt: 42,
42
+ yPt: 320,
43
+ widthPt: 500,
44
+ heightPt: 260
45
+ };
46
+ function notesPageLayoutName(state, stylesAutomaticStyles) {
47
+ if (state.name !== void 0) return state.name;
48
+ const name = "PM0";
49
+ state.name = name;
50
+ stylesAutomaticStyles.children.push(require_xml_fragment.el("style:page-layout", { "style:name": name }, [require_xml_fragment.el("style:page-layout-properties", {
51
+ "fo:page-width": require_typed_shared_units.formatOdfLength(document_schema_js.PAGE_SIZE_A4.widthPt),
52
+ "fo:page-height": require_typed_shared_units.formatOdfLength(document_schema_js.PAGE_SIZE_A4.heightPt),
53
+ "style:print-orientation": "portrait"
54
+ })]));
55
+ return name;
56
+ }
57
+ function writeSlideNotes(notes, state, stylesAutomaticStyles) {
58
+ if (notes.length === 0) return;
59
+ const paragraphs = notes.split("\n").map((line) => require_xml_fragment.el("text:p", {}, require_typed_shared_text.buildOdfInlineNodes(require_typed_shared_text.segmentOdfText(line, true, true))));
60
+ const frame = require_xml_fragment.el("draw:frame", {
61
+ "presentation:class": "notes",
62
+ "svg:x": require_typed_shared_units.formatOdfLength(NOTES_FRAME_BOX.xPt),
63
+ "svg:y": require_typed_shared_units.formatOdfLength(NOTES_FRAME_BOX.yPt),
64
+ "svg:width": require_typed_shared_units.formatOdfLength(NOTES_FRAME_BOX.widthPt),
65
+ "svg:height": require_typed_shared_units.formatOdfLength(NOTES_FRAME_BOX.heightPt)
66
+ }, [require_xml_fragment.el("draw:text-box", {}, paragraphs)]);
67
+ return require_xml_fragment.el("presentation:notes", { "style:page-layout-name": notesPageLayoutName(state, stylesAutomaticStyles) }, [frame]);
68
+ }
69
+ function writeOdpContent(document, options = {}) {
70
+ if (document.kind !== "presentation") throw new Error(`writeOdpContent: expected a 'presentation' document, got '${document.kind}' -- odf.js writes .odp from the presentation arm only`);
71
+ const version = options.version ?? "1.3";
72
+ const presentationElement = require_xml_fragment.el("office:presentation");
73
+ const pkg = require_package_io_scaffold.createOdfPackage(options.template ? require_media_type.ODF_MEDIA_TYPES.otp : require_media_type.ODF_MEDIA_TYPES.odp, presentationElement, version);
74
+ const registry = require_styles_registry.StyleRegistry.forPart(pkg, CONTENT_PART, { otherPart: {
75
+ pkg,
76
+ partPath: STYLES_PART
77
+ } });
78
+ const contentAutomaticStyles = require_package_io_scaffold.odfPartContainer(pkg, CONTENT_PART, "office:automatic-styles");
79
+ const stylesAutomaticStyles = require_package_io_scaffold.odfPartContainer(pkg, STYLES_PART, "office:automatic-styles");
80
+ const masterStyles = require_package_io_scaffold.odfPartContainer(pkg, STYLES_PART, "office:master-styles");
81
+ const shapeState = require_typed_draw_write_shapes.createDrawShapeWriteState(pkg, registry, contentAutomaticStyles);
82
+ const listState = { next: 1 };
83
+ const notesPageLayout = { name: void 0 };
84
+ document.slides.forEach((slide, index) => {
85
+ const masterPageName = `MP${index + 1}`;
86
+ const pageLayoutName = `PM${index + 1}`;
87
+ stylesAutomaticStyles.children.push(slidePageLayoutElement(pageLayoutName, slide.size));
88
+ masterStyles.children.push(require_xml_fragment.el("style:master-page", {
89
+ "style:name": require_xml_entities.encodeXmlText(masterPageName),
90
+ "style:page-layout-name": require_xml_entities.encodeXmlText(pageLayoutName)
91
+ }));
92
+ const shapeElements = require_typed_draw_write_shapes.writeDrawShapes(slide.shapes, listState, shapeState);
93
+ const notesElement = writeSlideNotes(slide.notes, notesPageLayout, stylesAutomaticStyles);
94
+ const children = [...shapeElements];
95
+ if (notesElement !== void 0) children.push(notesElement);
96
+ presentationElement.children.push(require_xml_fragment.el("draw:page", { "draw:master-page-name": require_xml_entities.encodeXmlText(masterPageName) }, children));
97
+ });
98
+ require_typed_shared_metadata.writeOdfMetadata(pkg, document.metadata, version);
99
+ require_manifest.syncManifest(pkg, { version });
100
+ return pkg;
101
+ }
102
+ function writeOdp(document, options = {}) {
103
+ return writeOdpContent((0, document_schema_js.flattenTree)(document), options);
104
+ }
105
+ //#endregion
106
+ exports.normaliseOdpContent = normaliseOdpContent;
107
+ exports.writeOdp = writeOdp;
108
+ exports.writeOdpContent = writeOdpContent;
@@ -0,0 +1,2 @@
1
+ import { i as writeOdpContent, n as normaliseOdpContent, r as writeOdp, t as OdpWriteOptions } from "../../write-BhG3t3fJ.cjs";
2
+ export { OdpWriteOptions, normaliseOdpContent, writeOdp, writeOdpContent };
@@ -0,0 +1,2 @@
1
+ import { i as writeOdpContent, n as normaliseOdpContent, r as writeOdp, t as OdpWriteOptions } from "../../write-CfTE2jY8.js";
2
+ export { OdpWriteOptions, normaliseOdpContent, writeOdp, writeOdpContent };
@@ -0,0 +1,105 @@
1
+ import { ODF_MEDIA_TYPES } from "../../media-type.js";
2
+ import { el } from "../../xml/fragment.js";
3
+ import { encodeXmlText } from "../../xml/entities.js";
4
+ import { syncManifest } from "../../manifest.js";
5
+ import { formatOdfLength } from "../shared/units.js";
6
+ import { StyleRegistry } from "../../styles/registry.js";
7
+ import { buildOdfInlineNodes, segmentOdfText } from "../shared/text.js";
8
+ import { writeOdfMetadata } from "../shared/metadata.js";
9
+ import { createOdfPackage, odfPartContainer } from "../../package-io/scaffold.js";
10
+ import { canonicalMetadata } from "../shared/canonicalise.js";
11
+ import { canonicalDrawShape, createDrawShapeWriteState, writeDrawShapes } from "../draw/write-shapes.js";
12
+ import { PAGE_SIZE_A4, flattenTree } from "document-schema.js";
13
+ //#region src/typed/odp/write.ts
14
+ const CONTENT_PART = "content.xml";
15
+ const STYLES_PART = "styles.xml";
16
+ function canonicalSlide(slide, listState) {
17
+ return {
18
+ size: slide.size,
19
+ shapes: slide.shapes.map((shape, index) => canonicalDrawShape(shape, index, listState)),
20
+ notes: slide.notes
21
+ };
22
+ }
23
+ function normaliseOdpContent(document) {
24
+ if (document.kind !== "presentation") throw new Error(`normaliseOdpContent: expected a 'presentation' document, got '${document.kind}'`);
25
+ const listState = { next: 1 };
26
+ return {
27
+ kind: "presentation",
28
+ metadata: canonicalMetadata(document.metadata),
29
+ slides: document.slides.map((slide) => canonicalSlide(slide, listState))
30
+ };
31
+ }
32
+ function slidePageLayoutElement(name, pageSize) {
33
+ return el("style:page-layout", { "style:name": encodeXmlText(name) }, [el("style:page-layout-properties", {
34
+ "fo:page-width": formatOdfLength(pageSize.widthPt),
35
+ "fo:page-height": formatOdfLength(pageSize.heightPt),
36
+ "style:print-orientation": pageSize.widthPt > pageSize.heightPt ? "landscape" : "portrait"
37
+ })]);
38
+ }
39
+ const NOTES_FRAME_BOX = {
40
+ xPt: 42,
41
+ yPt: 320,
42
+ widthPt: 500,
43
+ heightPt: 260
44
+ };
45
+ function notesPageLayoutName(state, stylesAutomaticStyles) {
46
+ if (state.name !== void 0) return state.name;
47
+ const name = "PM0";
48
+ state.name = name;
49
+ stylesAutomaticStyles.children.push(el("style:page-layout", { "style:name": name }, [el("style:page-layout-properties", {
50
+ "fo:page-width": formatOdfLength(PAGE_SIZE_A4.widthPt),
51
+ "fo:page-height": formatOdfLength(PAGE_SIZE_A4.heightPt),
52
+ "style:print-orientation": "portrait"
53
+ })]));
54
+ return name;
55
+ }
56
+ function writeSlideNotes(notes, state, stylesAutomaticStyles) {
57
+ if (notes.length === 0) return;
58
+ const paragraphs = notes.split("\n").map((line) => el("text:p", {}, buildOdfInlineNodes(segmentOdfText(line, true, true))));
59
+ const frame = el("draw:frame", {
60
+ "presentation:class": "notes",
61
+ "svg:x": formatOdfLength(NOTES_FRAME_BOX.xPt),
62
+ "svg:y": formatOdfLength(NOTES_FRAME_BOX.yPt),
63
+ "svg:width": formatOdfLength(NOTES_FRAME_BOX.widthPt),
64
+ "svg:height": formatOdfLength(NOTES_FRAME_BOX.heightPt)
65
+ }, [el("draw:text-box", {}, paragraphs)]);
66
+ return el("presentation:notes", { "style:page-layout-name": notesPageLayoutName(state, stylesAutomaticStyles) }, [frame]);
67
+ }
68
+ function writeOdpContent(document, options = {}) {
69
+ if (document.kind !== "presentation") throw new Error(`writeOdpContent: expected a 'presentation' document, got '${document.kind}' -- odf.js writes .odp from the presentation arm only`);
70
+ const version = options.version ?? "1.3";
71
+ const presentationElement = el("office:presentation");
72
+ const pkg = createOdfPackage(options.template ? ODF_MEDIA_TYPES.otp : ODF_MEDIA_TYPES.odp, presentationElement, version);
73
+ const registry = StyleRegistry.forPart(pkg, CONTENT_PART, { otherPart: {
74
+ pkg,
75
+ partPath: STYLES_PART
76
+ } });
77
+ const contentAutomaticStyles = odfPartContainer(pkg, CONTENT_PART, "office:automatic-styles");
78
+ const stylesAutomaticStyles = odfPartContainer(pkg, STYLES_PART, "office:automatic-styles");
79
+ const masterStyles = odfPartContainer(pkg, STYLES_PART, "office:master-styles");
80
+ const shapeState = createDrawShapeWriteState(pkg, registry, contentAutomaticStyles);
81
+ const listState = { next: 1 };
82
+ const notesPageLayout = { name: void 0 };
83
+ document.slides.forEach((slide, index) => {
84
+ const masterPageName = `MP${index + 1}`;
85
+ const pageLayoutName = `PM${index + 1}`;
86
+ stylesAutomaticStyles.children.push(slidePageLayoutElement(pageLayoutName, slide.size));
87
+ masterStyles.children.push(el("style:master-page", {
88
+ "style:name": encodeXmlText(masterPageName),
89
+ "style:page-layout-name": encodeXmlText(pageLayoutName)
90
+ }));
91
+ const shapeElements = writeDrawShapes(slide.shapes, listState, shapeState);
92
+ const notesElement = writeSlideNotes(slide.notes, notesPageLayout, stylesAutomaticStyles);
93
+ const children = [...shapeElements];
94
+ if (notesElement !== void 0) children.push(notesElement);
95
+ presentationElement.children.push(el("draw:page", { "draw:master-page-name": encodeXmlText(masterPageName) }, children));
96
+ });
97
+ writeOdfMetadata(pkg, document.metadata, version);
98
+ syncManifest(pkg, { version });
99
+ return pkg;
100
+ }
101
+ function writeOdp(document, options = {}) {
102
+ return writeOdpContent(flattenTree(document), options);
103
+ }
104
+ //#endregion
105
+ export { normaliseOdpContent, writeOdp, writeOdpContent };
@@ -1,4 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_embedded = require("../../embedded-wrtHCJ68.cjs");
2
+ const require_embedded = require("../../embedded-Bxyss_ck.cjs");
3
+ exports.DEFAULT_COLUMN_WIDTH_PT = require_embedded.DEFAULT_COLUMN_WIDTH_PT;
4
+ exports.DEFAULT_ROW_HEIGHT_PT = require_embedded.DEFAULT_ROW_HEIGHT_PT;
3
5
  exports.readOds = require_embedded.readOds;
4
6
  exports.readOdsContent = require_embedded.readOdsContent;
@@ -1,2 +1,2 @@
1
- import { n as readOds, r as readOdsContent, t as OdsDocument } from "../../read-tpfiT_n4.cjs";
2
- export { OdsDocument, readOds, readOdsContent };
1
+ import { a as readOdsContent, i as readOds, n as DEFAULT_ROW_HEIGHT_PT, r as OdsDocument, t as DEFAULT_COLUMN_WIDTH_PT } from "../../read-fphkvCpR.cjs";
2
+ export { DEFAULT_COLUMN_WIDTH_PT, DEFAULT_ROW_HEIGHT_PT, OdsDocument, readOds, readOdsContent };
@@ -1,2 +1,2 @@
1
- import { n as readOds, r as readOdsContent, t as OdsDocument } from "../../read-Bo1GBjSE.js";
2
- export { OdsDocument, readOds, readOdsContent };
1
+ import { a as readOdsContent, i as readOds, n as DEFAULT_ROW_HEIGHT_PT, r as OdsDocument, t as DEFAULT_COLUMN_WIDTH_PT } from "../../read-A3CJkqVM.js";
2
+ export { DEFAULT_COLUMN_WIDTH_PT, DEFAULT_ROW_HEIGHT_PT, OdsDocument, readOds, readOdsContent };
@@ -1,2 +1,2 @@
1
- import { o as readOds, s as readOdsContent } from "../../embedded-BONPxvS3.js";
2
- export { readOds, readOdsContent };
1
+ import { c as readOds, l as readOdsContent, o as DEFAULT_COLUMN_WIDTH_PT, s as DEFAULT_ROW_HEIGHT_PT } from "../../embedded-BnavfkP-.js";
2
+ export { DEFAULT_COLUMN_WIDTH_PT, DEFAULT_ROW_HEIGHT_PT, readOds, readOdsContent };