js.documents 1.65.0 → 1.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +9 -6
  2. package/dist/color-C98dn-pT.d.ts +2 -0
  3. package/dist/edit/docx/content.cjs +5 -0
  4. package/dist/edit/docx/content.js +5 -0
  5. package/dist/edit/docx/image.cjs +1 -0
  6. package/dist/edit/docx/image.d.cts +2 -2
  7. package/dist/edit/docx/image.d.ts +2 -2
  8. package/dist/edit/docx/image.js +1 -1
  9. package/dist/edit/docx/paragraph.cjs +10 -1
  10. package/dist/edit/docx/paragraph.d.cts +4 -3
  11. package/dist/edit/docx/paragraph.d.ts +4 -3
  12. package/dist/edit/docx/paragraph.js +13 -4
  13. package/dist/edit/docx/props.d.ts +1 -1
  14. package/dist/edit/docx/run.cjs +8 -1
  15. package/dist/edit/docx/run.d.cts +2 -2
  16. package/dist/edit/docx/run.d.ts +2 -2
  17. package/dist/edit/docx/run.js +8 -2
  18. package/dist/edit/docx/vector.cjs +69 -0
  19. package/dist/edit/docx/vector.d.cts +6 -0
  20. package/dist/edit/docx/vector.d.ts +6 -0
  21. package/dist/edit/docx/vector.js +68 -0
  22. package/dist/edit/drawingml/vector.cjs +113 -0
  23. package/dist/edit/drawingml/vector.d.cts +9 -0
  24. package/dist/edit/drawingml/vector.d.ts +9 -0
  25. package/dist/edit/drawingml/vector.js +109 -0
  26. package/dist/edit/odg/content.cjs +1 -26
  27. package/dist/edit/odg/content.js +1 -26
  28. package/dist/edit/odg/page.cjs +14 -1
  29. package/dist/edit/odg/page.d.cts +5 -3
  30. package/dist/edit/odg/page.d.ts +5 -3
  31. package/dist/edit/odg/page.js +14 -1
  32. package/dist/edit/odg/style.cjs +17 -3
  33. package/dist/edit/odg/style.d.cts +1 -0
  34. package/dist/edit/odg/style.d.ts +1 -0
  35. package/dist/edit/odg/style.js +17 -3
  36. package/dist/edit/odg/vector.cjs +65 -3
  37. package/dist/edit/odg/vector.d.cts +2 -2
  38. package/dist/edit/odg/vector.d.ts +2 -2
  39. package/dist/edit/odg/vector.js +63 -4
  40. package/dist/edit/odp/content.cjs +4 -1
  41. package/dist/edit/odp/content.js +5 -2
  42. package/dist/edit/odp/shape.cjs +1 -1
  43. package/dist/edit/odp/shape.d.cts +1 -1
  44. package/dist/edit/odp/shape.d.ts +1 -1
  45. package/dist/edit/odp/shape.js +1 -1
  46. package/dist/edit/odp/slide.cjs +4 -0
  47. package/dist/edit/odp/slide.d.cts +8 -5
  48. package/dist/edit/odp/slide.d.ts +9 -6
  49. package/dist/edit/odp/slide.js +4 -0
  50. package/dist/edit/odt/content.cjs +5 -0
  51. package/dist/edit/odt/content.d.ts +2 -2
  52. package/dist/edit/odt/content.js +5 -0
  53. package/dist/edit/odt/editor.cjs +7 -0
  54. package/dist/edit/odt/editor.d.cts +3 -2
  55. package/dist/edit/odt/editor.d.ts +5 -4
  56. package/dist/edit/odt/editor.js +7 -0
  57. package/dist/edit/odt/list.cjs +13 -0
  58. package/dist/edit/odt/list.d.cts +1 -1
  59. package/dist/edit/odt/list.d.ts +1 -1
  60. package/dist/edit/odt/list.js +13 -0
  61. package/dist/edit/odt/paragraph.d.ts +1 -1
  62. package/dist/edit/odt/run.d.ts +1 -1
  63. package/dist/edit/odt/table.d.ts +1 -1
  64. package/dist/edit/pptx/content.cjs +5 -2
  65. package/dist/edit/pptx/content.js +5 -2
  66. package/dist/edit/pptx/shape.cjs +2 -5
  67. package/dist/edit/pptx/shape.d.ts +1 -1
  68. package/dist/edit/pptx/shape.js +2 -5
  69. package/dist/edit/pptx/slide.cjs +7 -0
  70. package/dist/edit/pptx/slide.d.cts +6 -4
  71. package/dist/edit/pptx/slide.d.ts +8 -6
  72. package/dist/edit/pptx/slide.js +7 -0
  73. package/dist/edit/pptx/table.d.ts +1 -1
  74. package/dist/edit/pptx/vector.cjs +17 -0
  75. package/dist/edit/pptx/vector.d.cts +6 -0
  76. package/dist/edit/pptx/vector.d.ts +6 -0
  77. package/dist/edit/pptx/vector.js +16 -0
  78. package/dist/{image-BfRLAD9B.d.cts → image-DRqXQmEg.d.cts} +2 -1
  79. package/dist/{image-BfRLAD9B.d.ts → image-DRqXQmEg.d.ts} +2 -1
  80. package/dist/index.cjs +2 -2
  81. package/dist/index.d.cts +5 -5
  82. package/dist/index.d.ts +11 -11
  83. package/dist/index.js +2 -2
  84. package/dist/layout/shared.cjs +1 -0
  85. package/dist/layout/shared.js +1 -0
  86. package/dist/{list-BuBM9rwQ.d.cts → list-BzcN-LTJ.d.cts} +3 -0
  87. package/dist/{list-CvKxhy3y.d.ts → list-nlhN5bat.d.ts} +4 -1
  88. package/dist/markdown/write.cjs +1 -1
  89. package/dist/markdown/write.js +1 -1
  90. package/dist/model/color.d.ts +1 -1
  91. package/dist/model/embedded-drawing.cjs +47 -0
  92. package/dist/model/embedded-drawing.d.cts +4 -2
  93. package/dist/model/embedded-drawing.d.ts +4 -2
  94. package/dist/model/embedded-drawing.js +46 -1
  95. package/dist/{paragraph-CoUi_88j.d.ts → paragraph-DndYbWuT.d.ts} +1 -1
  96. package/dist/{run-D2rTWHbt.d.ts → run-BhYv2wJf.d.ts} +3 -2
  97. package/dist/{run-CJfh8rv3.d.ts → run-DtrwZwN6.d.ts} +1 -1
  98. package/dist/{run-B3GNScJH.d.cts → run-P0b2pDdX.d.cts} +2 -1
  99. package/dist/{shape-BkVcwPcf.d.ts → shape-B-TjU_Ej.d.ts} +1 -1
  100. package/dist/{shape-CXZ6fejV.d.cts → shape-C8qDhn0l.d.cts} +1 -1
  101. package/dist/{shape-CVXedeL7.d.ts → shape-XGp__l-J.d.ts} +2 -2
  102. package/dist/{table-DqfqMkVq.d.ts → table-BHeUmLzZ.d.ts} +1 -1
  103. package/dist/{table-DvS_7UQS.d.ts → table-DQpKafyl.d.ts} +1 -1
  104. package/dist/{vector-Puuqu_IT.d.cts → vector-D03KX8Ux.d.cts} +15 -2
  105. package/dist/{vector-Puuqu_IT.d.ts → vector-D03KX8Ux.d.ts} +15 -2
  106. package/package.json +2 -2
  107. package/dist/color-Bo228AY2.d.ts +0 -2
@@ -0,0 +1,68 @@
1
+ import { el, txt } from "../../xml/fragment.js";
2
+ import { ptToEmu } from "../../model/units.js";
3
+ import { buildVectorShapeProperties, vectorPlacementBox, vectorShapeName } from "../drawingml/vector.js";
4
+ //#region src/edit/docx/vector.ts
5
+ const DRAWING_NS = {
6
+ wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
7
+ a: "http://schemas.openxmlformats.org/drawingml/2006/main",
8
+ wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
9
+ };
10
+ const ANCHOR_ATTRS = {
11
+ distT: "0",
12
+ distB: "0",
13
+ distL: "0",
14
+ distR: "0",
15
+ simplePos: "0",
16
+ locked: "0",
17
+ layoutInCell: "1",
18
+ allowOverlap: "1",
19
+ behindDoc: "1"
20
+ };
21
+ function position(tag, offsetPt) {
22
+ return el(tag, { relativeFrom: "page" }, [el("wp:posOffset", {}, [txt(String(ptToEmu(offsetPt)))])]);
23
+ }
24
+ function buildAnchoredVectorDrawing(vector, drawingId, relativeHeight) {
25
+ const frame = vectorPlacementBox(vector);
26
+ const cx = String(ptToEmu(frame.widthPt));
27
+ const cy = String(ptToEmu(frame.heightPt));
28
+ const name = vectorShapeName(vector, drawingId);
29
+ const wsp = el("wps:wsp", {}, [
30
+ el("wps:cNvSpPr"),
31
+ el("wps:spPr", {}, buildVectorShapeProperties(vector)),
32
+ el("wps:bodyPr")
33
+ ]);
34
+ const anchor = el("wp:anchor", {
35
+ ...ANCHOR_ATTRS,
36
+ relativeHeight: String(relativeHeight)
37
+ }, [
38
+ el("wp:simplePos", {
39
+ x: "0",
40
+ y: "0"
41
+ }),
42
+ position("wp:positionH", frame.xPt),
43
+ position("wp:positionV", frame.yPt),
44
+ el("wp:extent", {
45
+ cx,
46
+ cy
47
+ }),
48
+ el("wp:effectExtent", {
49
+ l: "0",
50
+ t: "0",
51
+ r: "0",
52
+ b: "0"
53
+ }),
54
+ el("wp:wrapNone"),
55
+ el("wp:docPr", {
56
+ id: String(drawingId),
57
+ name
58
+ }),
59
+ el("a:graphic", {}, [el("a:graphicData", { uri: DRAWING_NS.wps }, [wsp])])
60
+ ]);
61
+ return el("w:drawing", {
62
+ "xmlns:wp": DRAWING_NS.wp,
63
+ "xmlns:a": DRAWING_NS.a,
64
+ "xmlns:wps": DRAWING_NS.wps
65
+ }, [anchor]);
66
+ }
67
+ //#endregion
68
+ export { buildAnchoredVectorDrawing };
@@ -0,0 +1,113 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_fragment = require("../../xml/fragment.cjs");
3
+ const require_model_units = require("../../model/units.cjs");
4
+ let document_schema_js = require("document-schema.js");
5
+ //#region src/edit/drawingml/vector.ts
6
+ function drawingMlColorHex(color) {
7
+ return (0, document_schema_js.colorToRgbHex)(color).toUpperCase();
8
+ }
9
+ function solidFillOrNone(fill) {
10
+ return fill === void 0 ? require_xml_fragment.el("a:noFill") : require_xml_fragment.el("a:solidFill", {}, [require_xml_fragment.el("a:srgbClr", { val: drawingMlColorHex(fill) })]);
11
+ }
12
+ function outline(stroke) {
13
+ if (stroke === void 0) return require_xml_fragment.el("a:ln", {}, [require_xml_fragment.el("a:noFill")]);
14
+ return require_xml_fragment.el("a:ln", { w: String(require_model_units.ptToEmu(stroke.widthPt)) }, [require_xml_fragment.el("a:solidFill", {}, [require_xml_fragment.el("a:srgbClr", { val: drawingMlColorHex(stroke.color) })])]);
15
+ }
16
+ function placementOf(vector) {
17
+ if (vector.kind !== "line") return {
18
+ frame: vector.frame,
19
+ flipH: false,
20
+ flipV: false
21
+ };
22
+ const { from, to } = vector;
23
+ return {
24
+ frame: {
25
+ xPt: Math.min(from.xPt, to.xPt),
26
+ yPt: Math.min(from.yPt, to.yPt),
27
+ widthPt: Math.abs(to.xPt - from.xPt),
28
+ heightPt: Math.abs(to.yPt - from.yPt)
29
+ },
30
+ flipH: to.xPt < from.xPt,
31
+ flipV: to.yPt < from.yPt
32
+ };
33
+ }
34
+ const ROTATION_UNITS_PER_DEGREE = 6e4;
35
+ function transform(placement, rotationDeg) {
36
+ const attrs = {};
37
+ if (rotationDeg !== void 0 && rotationDeg !== 0) attrs.rot = String(Math.round(rotationDeg * ROTATION_UNITS_PER_DEGREE));
38
+ if (placement.flipH) attrs.flipH = "1";
39
+ if (placement.flipV) attrs.flipV = "1";
40
+ return require_xml_fragment.el("a:xfrm", attrs, [require_xml_fragment.el("a:off", {
41
+ x: String(require_model_units.ptToEmu(placement.frame.xPt)),
42
+ y: String(require_model_units.ptToEmu(placement.frame.yPt))
43
+ }), require_xml_fragment.el("a:ext", {
44
+ cx: String(require_model_units.ptToEmu(placement.frame.widthPt)),
45
+ cy: String(require_model_units.ptToEmu(placement.frame.heightPt))
46
+ })]);
47
+ }
48
+ function pt(xPt, yPt) {
49
+ return require_xml_fragment.el("a:pt", {
50
+ x: String(require_model_units.ptToEmu(xPt)),
51
+ y: String(require_model_units.ptToEmu(yPt))
52
+ });
53
+ }
54
+ function customGeometry(frame, subpaths) {
55
+ const paths = subpaths.map((subpath) => {
56
+ const commands = [require_xml_fragment.el("a:moveTo", {}, [pt(subpath.start.xPt, subpath.start.yPt)])];
57
+ for (const segment of subpath.segments) if (segment.kind === "line") commands.push(require_xml_fragment.el("a:lnTo", {}, [pt(segment.to.xPt, segment.to.yPt)]));
58
+ else commands.push(require_xml_fragment.el("a:cubicBezTo", {}, [
59
+ pt(segment.control1.xPt, segment.control1.yPt),
60
+ pt(segment.control2.xPt, segment.control2.yPt),
61
+ pt(segment.to.xPt, segment.to.yPt)
62
+ ]));
63
+ if (subpath.closed) commands.push(require_xml_fragment.el("a:close"));
64
+ return require_xml_fragment.el("a:path", {
65
+ w: String(require_model_units.ptToEmu(frame.widthPt)),
66
+ h: String(require_model_units.ptToEmu(frame.heightPt))
67
+ }, commands);
68
+ });
69
+ return require_xml_fragment.el("a:custGeom", {}, [
70
+ require_xml_fragment.el("a:avLst"),
71
+ require_xml_fragment.el("a:gdLst"),
72
+ require_xml_fragment.el("a:ahLst"),
73
+ require_xml_fragment.el("a:cxnLst"),
74
+ require_xml_fragment.el("a:rect", {
75
+ l: "0",
76
+ t: "0",
77
+ r: "r",
78
+ b: "b"
79
+ }),
80
+ require_xml_fragment.el("a:pathLst", {}, paths)
81
+ ]);
82
+ }
83
+ const PRESET_BY_KIND = {
84
+ rect: "rect",
85
+ ellipse: "ellipse",
86
+ line: "line"
87
+ };
88
+ function geometry(vector) {
89
+ if (vector.kind === "path") return customGeometry(vector.frame, vector.subpaths);
90
+ return require_xml_fragment.el("a:prstGeom", { prst: PRESET_BY_KIND[vector.kind] }, [require_xml_fragment.el("a:avLst")]);
91
+ }
92
+ function buildVectorShapeProperties(vector) {
93
+ const placement = placementOf(vector);
94
+ const fill = vector.kind === "line" ? void 0 : vector.fill;
95
+ const stroke = vector.stroke;
96
+ return [
97
+ transform(placement, vector.kind === "line" ? void 0 : vector.rotationDeg),
98
+ geometry(vector),
99
+ solidFillOrNone(fill),
100
+ outline(stroke)
101
+ ];
102
+ }
103
+ function vectorPlacementBox(vector) {
104
+ return placementOf(vector).frame;
105
+ }
106
+ function vectorShapeName(vector, id) {
107
+ return `${vector.kind.charAt(0).toUpperCase()}${vector.kind.slice(1)} ${id}`;
108
+ }
109
+ //#endregion
110
+ exports.buildVectorShapeProperties = buildVectorShapeProperties;
111
+ exports.drawingMlColorHex = drawingMlColorHex;
112
+ exports.vectorPlacementBox = vectorPlacementBox;
113
+ exports.vectorShapeName = vectorShapeName;
@@ -0,0 +1,9 @@
1
+ import { Box, Color, ContentVector } from "document-schema.js";
2
+ import { XmlNode } from "ooxml.js";
3
+ //#region src/edit/drawingml/vector.d.ts
4
+ declare function drawingMlColorHex(color: Color): string;
5
+ declare function buildVectorShapeProperties(vector: ContentVector): XmlNode[];
6
+ declare function vectorPlacementBox(vector: ContentVector): Box;
7
+ declare function vectorShapeName(vector: ContentVector, id: number): string;
8
+ //#endregion
9
+ export { buildVectorShapeProperties, drawingMlColorHex, vectorPlacementBox, vectorShapeName };
@@ -0,0 +1,9 @@
1
+ import { XmlNode } from "ooxml.js";
2
+ import { Box, Color, ContentVector } from "document-schema.js";
3
+ //#region src/edit/drawingml/vector.d.ts
4
+ declare function drawingMlColorHex(color: Color): string;
5
+ declare function buildVectorShapeProperties(vector: ContentVector): XmlNode[];
6
+ declare function vectorPlacementBox(vector: ContentVector): Box;
7
+ declare function vectorShapeName(vector: ContentVector, id: number): string;
8
+ //#endregion
9
+ export { buildVectorShapeProperties, drawingMlColorHex, vectorPlacementBox, vectorShapeName };
@@ -0,0 +1,109 @@
1
+ import { el } from "../../xml/fragment.js";
2
+ import { ptToEmu } from "../../model/units.js";
3
+ import { colorToRgbHex } from "document-schema.js";
4
+ //#region src/edit/drawingml/vector.ts
5
+ function drawingMlColorHex(color) {
6
+ return colorToRgbHex(color).toUpperCase();
7
+ }
8
+ function solidFillOrNone(fill) {
9
+ return fill === void 0 ? el("a:noFill") : el("a:solidFill", {}, [el("a:srgbClr", { val: drawingMlColorHex(fill) })]);
10
+ }
11
+ function outline(stroke) {
12
+ if (stroke === void 0) return el("a:ln", {}, [el("a:noFill")]);
13
+ return el("a:ln", { w: String(ptToEmu(stroke.widthPt)) }, [el("a:solidFill", {}, [el("a:srgbClr", { val: drawingMlColorHex(stroke.color) })])]);
14
+ }
15
+ function placementOf(vector) {
16
+ if (vector.kind !== "line") return {
17
+ frame: vector.frame,
18
+ flipH: false,
19
+ flipV: false
20
+ };
21
+ const { from, to } = vector;
22
+ return {
23
+ frame: {
24
+ xPt: Math.min(from.xPt, to.xPt),
25
+ yPt: Math.min(from.yPt, to.yPt),
26
+ widthPt: Math.abs(to.xPt - from.xPt),
27
+ heightPt: Math.abs(to.yPt - from.yPt)
28
+ },
29
+ flipH: to.xPt < from.xPt,
30
+ flipV: to.yPt < from.yPt
31
+ };
32
+ }
33
+ const ROTATION_UNITS_PER_DEGREE = 6e4;
34
+ function transform(placement, rotationDeg) {
35
+ const attrs = {};
36
+ if (rotationDeg !== void 0 && rotationDeg !== 0) attrs.rot = String(Math.round(rotationDeg * ROTATION_UNITS_PER_DEGREE));
37
+ if (placement.flipH) attrs.flipH = "1";
38
+ if (placement.flipV) attrs.flipV = "1";
39
+ return el("a:xfrm", attrs, [el("a:off", {
40
+ x: String(ptToEmu(placement.frame.xPt)),
41
+ y: String(ptToEmu(placement.frame.yPt))
42
+ }), el("a:ext", {
43
+ cx: String(ptToEmu(placement.frame.widthPt)),
44
+ cy: String(ptToEmu(placement.frame.heightPt))
45
+ })]);
46
+ }
47
+ function pt(xPt, yPt) {
48
+ return el("a:pt", {
49
+ x: String(ptToEmu(xPt)),
50
+ y: String(ptToEmu(yPt))
51
+ });
52
+ }
53
+ function customGeometry(frame, subpaths) {
54
+ const paths = subpaths.map((subpath) => {
55
+ const commands = [el("a:moveTo", {}, [pt(subpath.start.xPt, subpath.start.yPt)])];
56
+ for (const segment of subpath.segments) if (segment.kind === "line") commands.push(el("a:lnTo", {}, [pt(segment.to.xPt, segment.to.yPt)]));
57
+ else commands.push(el("a:cubicBezTo", {}, [
58
+ pt(segment.control1.xPt, segment.control1.yPt),
59
+ pt(segment.control2.xPt, segment.control2.yPt),
60
+ pt(segment.to.xPt, segment.to.yPt)
61
+ ]));
62
+ if (subpath.closed) commands.push(el("a:close"));
63
+ return el("a:path", {
64
+ w: String(ptToEmu(frame.widthPt)),
65
+ h: String(ptToEmu(frame.heightPt))
66
+ }, commands);
67
+ });
68
+ return el("a:custGeom", {}, [
69
+ el("a:avLst"),
70
+ el("a:gdLst"),
71
+ el("a:ahLst"),
72
+ el("a:cxnLst"),
73
+ el("a:rect", {
74
+ l: "0",
75
+ t: "0",
76
+ r: "r",
77
+ b: "b"
78
+ }),
79
+ el("a:pathLst", {}, paths)
80
+ ]);
81
+ }
82
+ const PRESET_BY_KIND = {
83
+ rect: "rect",
84
+ ellipse: "ellipse",
85
+ line: "line"
86
+ };
87
+ function geometry(vector) {
88
+ if (vector.kind === "path") return customGeometry(vector.frame, vector.subpaths);
89
+ return el("a:prstGeom", { prst: PRESET_BY_KIND[vector.kind] }, [el("a:avLst")]);
90
+ }
91
+ function buildVectorShapeProperties(vector) {
92
+ const placement = placementOf(vector);
93
+ const fill = vector.kind === "line" ? void 0 : vector.fill;
94
+ const stroke = vector.stroke;
95
+ return [
96
+ transform(placement, vector.kind === "line" ? void 0 : vector.rotationDeg),
97
+ geometry(vector),
98
+ solidFillOrNone(fill),
99
+ outline(stroke)
100
+ ];
101
+ }
102
+ function vectorPlacementBox(vector) {
103
+ return placementOf(vector).frame;
104
+ }
105
+ function vectorShapeName(vector, id) {
106
+ return `${vector.kind.charAt(0).toUpperCase()}${vector.kind.slice(1)} ${id}`;
107
+ }
108
+ //#endregion
109
+ export { buildVectorShapeProperties, drawingMlColorHex, vectorPlacementBox, vectorShapeName };
@@ -11,36 +11,11 @@ function buildOdgPackage(content) {
11
11
  if (firstPage !== void 0) editor.pageSize = firstPage.size;
12
12
  for (const page of content.pages) {
13
13
  const odgPage = editor.addPage();
14
- for (const entry of require_model_paint_order.mergeByPaintOrder(page.vectors, page.shapes)) if (entry.kind === "vector") appendVector(odgPage, entry.value);
14
+ for (const entry of require_model_paint_order.mergeByPaintOrder(page.vectors, page.shapes)) if (entry.kind === "vector") odgPage.addVector(entry.value);
15
15
  else appendShape(odgPage, entry.value);
16
16
  }
17
17
  return editor.toPackage();
18
18
  }
19
- function appendVector(page, vector) {
20
- if (vector.kind === "line") {
21
- page.addLine({
22
- from: vector.from,
23
- to: vector.to,
24
- stroke: vector.stroke
25
- });
26
- return;
27
- }
28
- const built = vector.kind === "rect" ? page.addRect({
29
- frame: vector.frame,
30
- fill: vector.fill,
31
- stroke: vector.stroke
32
- }) : vector.kind === "ellipse" ? page.addEllipse({
33
- frame: vector.frame,
34
- fill: vector.fill,
35
- stroke: vector.stroke
36
- }) : page.addPath({
37
- frame: vector.frame,
38
- subpaths: vector.subpaths,
39
- fill: vector.fill,
40
- stroke: vector.stroke
41
- });
42
- if (vector.rotationDeg !== void 0) built.rotationDeg = vector.rotationDeg;
43
- }
44
19
  function appendShape(page, shape) {
45
20
  const [onlyBlock] = shape.blocks;
46
21
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
@@ -10,36 +10,11 @@ function buildOdgPackage(content) {
10
10
  if (firstPage !== void 0) editor.pageSize = firstPage.size;
11
11
  for (const page of content.pages) {
12
12
  const odgPage = editor.addPage();
13
- for (const entry of mergeByPaintOrder(page.vectors, page.shapes)) if (entry.kind === "vector") appendVector(odgPage, entry.value);
13
+ for (const entry of mergeByPaintOrder(page.vectors, page.shapes)) if (entry.kind === "vector") odgPage.addVector(entry.value);
14
14
  else appendShape(odgPage, entry.value);
15
15
  }
16
16
  return editor.toPackage();
17
17
  }
18
- function appendVector(page, vector) {
19
- if (vector.kind === "line") {
20
- page.addLine({
21
- from: vector.from,
22
- to: vector.to,
23
- stroke: vector.stroke
24
- });
25
- return;
26
- }
27
- const built = vector.kind === "rect" ? page.addRect({
28
- frame: vector.frame,
29
- fill: vector.fill,
30
- stroke: vector.stroke
31
- }) : vector.kind === "ellipse" ? page.addEllipse({
32
- frame: vector.frame,
33
- fill: vector.fill,
34
- stroke: vector.stroke
35
- }) : page.addPath({
36
- frame: vector.frame,
37
- subpaths: vector.subpaths,
38
- fill: vector.fill,
39
- stroke: vector.stroke
40
- });
41
- if (vector.rotationDeg !== void 0) built.rotationDeg = vector.rotationDeg;
42
- }
43
18
  function appendShape(page, shape) {
44
19
  const [onlyBlock] = shape.blocks;
45
20
  if (shape.blocks.length === 1 && onlyBlock?.kind === "image") {
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_xml_edit = require("../../xml/edit.cjs");
3
+ const require_edit_odg_vector = require("./vector.cjs");
3
4
  const require_edit_odp_shape = require("../odp/shape.cjs");
4
5
  const require_edit_odp_image = require("../odp/image.cjs");
5
- const require_edit_odg_vector = require("./vector.cjs");
6
6
  //#region src/edit/odg/page.ts
7
7
  var OdgPage = class {
8
8
  container;
@@ -37,6 +37,16 @@ var OdgPage = class {
37
37
  node.children.push(frameElement);
38
38
  return new require_edit_odp_shape.OdpShape(node.children, frameElement, this.context.pkg);
39
39
  }
40
+ vectors() {
41
+ const node = this.live();
42
+ const out = [];
43
+ for (const child of node.children) {
44
+ if (child.type !== "element") continue;
45
+ const vector = require_edit_odg_vector.wrapVectorElement(node.children, child, this.context.pkg);
46
+ if (vector !== void 0) out.push(vector);
47
+ }
48
+ return out;
49
+ }
40
50
  addRect(init) {
41
51
  const node = this.live();
42
52
  const element = require_edit_odg_vector.buildRectElement(this.context.pkg, init);
@@ -61,6 +71,9 @@ var OdgPage = class {
61
71
  node.children.push(element);
62
72
  return new require_edit_odg_vector.OdgPathVector(node.children, element, this.context.pkg);
63
73
  }
74
+ addVector(vector) {
75
+ return require_edit_odg_vector.appendVectorTo(this.live().children, this.context.pkg, vector);
76
+ }
64
77
  remove() {
65
78
  require_xml_edit.removeChild(this.container, this.live());
66
79
  this.removed = true;
@@ -1,7 +1,7 @@
1
1
  import { t as ImageInit } from "../../image-M5SezZVI.cjs";
2
- import { t as OdpShape } from "../../shape-CXZ6fejV.cjs";
3
- import { a as OdgLineVector, n as LineVectorInit, o as OdgPathVector, r as OdgBoxVector, s as PathVectorInit, t as BoxVectorInit } from "../../vector-Puuqu_IT.cjs";
4
- import { Box } from "document-schema.js";
2
+ import { t as OdpShape } from "../../shape-C8qDhn0l.cjs";
3
+ import { a as OdgLineVector, l as PathVectorInit, n as LineVectorInit, o as OdgPathVector, r as OdgBoxVector, s as OdgVector, t as BoxVectorInit } from "../../vector-D03KX8Ux.cjs";
4
+ import { Box, ContentVector } from "document-schema.js";
5
5
  import { Package, XmlElement, XmlNode } from "odf.js";
6
6
  //#region src/edit/odg/page.d.ts
7
7
  interface TextBoxInit {
@@ -24,10 +24,12 @@ declare class OdgPage {
24
24
  shapes(): OdpShape[];
25
25
  addTextBox(init: TextBoxInit): OdpShape;
26
26
  addImage(init: PageImageInit): OdpShape;
27
+ vectors(): OdgVector[];
27
28
  addRect(init: BoxVectorInit): OdgBoxVector;
28
29
  addEllipse(init: BoxVectorInit): OdgBoxVector;
29
30
  addLine(init: LineVectorInit): OdgLineVector;
30
31
  addPath(init: PathVectorInit): OdgPathVector;
32
+ addVector(vector: ContentVector): OdgVector;
31
33
  remove(): void;
32
34
  }
33
35
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { t as ImageInit } from "../../image-DHcA9kaK.js";
2
- import { t as OdpShape } from "../../shape-CVXedeL7.js";
3
- import { a as OdgLineVector, n as LineVectorInit, o as OdgPathVector, r as OdgBoxVector, s as PathVectorInit, t as BoxVectorInit } from "../../vector-Puuqu_IT.js";
4
- import { Box } from "document-schema.js";
2
+ import { t as OdpShape } from "../../shape-XGp__l-J.js";
3
+ import { a as OdgLineVector, l as PathVectorInit, n as LineVectorInit, o as OdgPathVector, r as OdgBoxVector, s as OdgVector, t as BoxVectorInit } from "../../vector-D03KX8Ux.js";
4
+ import { Box, ContentVector } from "document-schema.js";
5
5
  import { Package, XmlElement, XmlNode } from "odf.js";
6
6
  //#region src/edit/odg/page.d.ts
7
7
  interface TextBoxInit {
@@ -24,10 +24,12 @@ declare class OdgPage {
24
24
  shapes(): OdpShape[];
25
25
  addTextBox(init: TextBoxInit): OdpShape;
26
26
  addImage(init: PageImageInit): OdpShape;
27
+ vectors(): OdgVector[];
27
28
  addRect(init: BoxVectorInit): OdgBoxVector;
28
29
  addEllipse(init: BoxVectorInit): OdgBoxVector;
29
30
  addLine(init: LineVectorInit): OdgLineVector;
30
31
  addPath(init: PathVectorInit): OdgPathVector;
32
+ addVector(vector: ContentVector): OdgVector;
31
33
  remove(): void;
32
34
  }
33
35
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { removeChild } from "../../xml/edit.js";
2
+ import { OdgBoxVector, OdgLineVector, OdgPathVector, appendVectorTo, buildEllipseElement, buildLineElement, buildPathElement, buildRectElement, wrapVectorElement } from "./vector.js";
2
3
  import { OdpShape, buildTextBoxFrame } from "../odp/shape.js";
3
4
  import { insertImageFrameMedia } from "../odp/image.js";
4
- import { OdgBoxVector, OdgLineVector, OdgPathVector, buildEllipseElement, buildLineElement, buildPathElement, buildRectElement } from "./vector.js";
5
5
  //#region src/edit/odg/page.ts
6
6
  var OdgPage = class {
7
7
  container;
@@ -36,6 +36,16 @@ var OdgPage = class {
36
36
  node.children.push(frameElement);
37
37
  return new OdpShape(node.children, frameElement, this.context.pkg);
38
38
  }
39
+ vectors() {
40
+ const node = this.live();
41
+ const out = [];
42
+ for (const child of node.children) {
43
+ if (child.type !== "element") continue;
44
+ const vector = wrapVectorElement(node.children, child, this.context.pkg);
45
+ if (vector !== void 0) out.push(vector);
46
+ }
47
+ return out;
48
+ }
39
49
  addRect(init) {
40
50
  const node = this.live();
41
51
  const element = buildRectElement(this.context.pkg, init);
@@ -60,6 +70,9 @@ var OdgPage = class {
60
70
  node.children.push(element);
61
71
  return new OdgPathVector(node.children, element, this.context.pkg);
62
72
  }
73
+ addVector(vector) {
74
+ return appendVectorTo(this.live().children, this.context.pkg, vector);
75
+ }
63
76
  remove() {
64
77
  removeChild(this.container, this.live());
65
78
  this.removed = true;
@@ -6,8 +6,16 @@ let ooxml_js = require("ooxml.js");
6
6
  let odf_js = require("odf.js");
7
7
  //#region src/edit/odg/style.ts
8
8
  const GRAPHIC_STYLE_PREFIX = "gr";
9
+ const TEXT_FLOW_ANCHOR_ATTRS = {
10
+ "style:wrap": "run-through",
11
+ "style:run-through": "background",
12
+ "style:horizontal-pos": "from-left",
13
+ "style:horizontal-rel": "page",
14
+ "style:vertical-pos": "from-top",
15
+ "style:vertical-rel": "page"
16
+ };
9
17
  function graphicPropertyAttrs(init) {
10
- const attrs = {};
18
+ const attrs = init.textFlowAnchored === true ? { ...TEXT_FLOW_ANCHOR_ATTRS } : {};
11
19
  if (init.fill === void 0) attrs["draw:fill"] = "none";
12
20
  else {
13
21
  attrs["draw:fill"] = "solid";
@@ -61,17 +69,23 @@ function readGraphicStroke(pkg, element) {
61
69
  widthPt
62
70
  };
63
71
  }
72
+ function readGraphicTextFlowAnchored(pkg, element) {
73
+ const props = graphicProperties(pkg, element);
74
+ return props !== void 0 && (0, ooxml_js.attr)(props, "style:vertical-rel") === TEXT_FLOW_ANCHOR_ATTRS["style:vertical-rel"];
75
+ }
64
76
  function setGraphicFill(pkg, element, fill) {
65
77
  const name = buildGraphicStyle(pkg, {
66
78
  fill,
67
- stroke: readGraphicStroke(pkg, element)
79
+ stroke: readGraphicStroke(pkg, element),
80
+ textFlowAnchored: readGraphicTextFlowAnchored(pkg, element)
68
81
  });
69
82
  require_xml_edit.setAttr(element, "draw:style-name", name);
70
83
  }
71
84
  function setGraphicStroke(pkg, element, stroke) {
72
85
  const name = buildGraphicStyle(pkg, {
73
86
  fill: readGraphicFill(pkg, element),
74
- stroke
87
+ stroke,
88
+ textFlowAnchored: readGraphicTextFlowAnchored(pkg, element)
75
89
  });
76
90
  require_xml_edit.setAttr(element, "draw:style-name", name);
77
91
  }
@@ -4,6 +4,7 @@ import { Package, XmlElement } from "odf.js";
4
4
  interface GraphicStyleInit {
5
5
  readonly fill?: Color;
6
6
  readonly stroke?: ContentStroke;
7
+ readonly textFlowAnchored?: boolean;
7
8
  }
8
9
  declare function buildGraphicStyle(pkg: Package, init: GraphicStyleInit): string;
9
10
  declare function readGraphicFill(pkg: Package, element: XmlElement): Color | undefined;
@@ -4,6 +4,7 @@ import { Package, XmlElement } from "odf.js";
4
4
  interface GraphicStyleInit {
5
5
  readonly fill?: Color;
6
6
  readonly stroke?: ContentStroke;
7
+ readonly textFlowAnchored?: boolean;
7
8
  }
8
9
  declare function buildGraphicStyle(pkg: Package, init: GraphicStyleInit): string;
9
10
  declare function readGraphicFill(pkg: Package, element: XmlElement): Color | undefined;
@@ -5,8 +5,16 @@ import { attr } from "ooxml.js";
5
5
  import { formatOdfColor, formatOdfLength, parseOdfColor, parseOdfLength } from "odf.js";
6
6
  //#region src/edit/odg/style.ts
7
7
  const GRAPHIC_STYLE_PREFIX = "gr";
8
+ const TEXT_FLOW_ANCHOR_ATTRS = {
9
+ "style:wrap": "run-through",
10
+ "style:run-through": "background",
11
+ "style:horizontal-pos": "from-left",
12
+ "style:horizontal-rel": "page",
13
+ "style:vertical-pos": "from-top",
14
+ "style:vertical-rel": "page"
15
+ };
8
16
  function graphicPropertyAttrs(init) {
9
- const attrs = {};
17
+ const attrs = init.textFlowAnchored === true ? { ...TEXT_FLOW_ANCHOR_ATTRS } : {};
10
18
  if (init.fill === void 0) attrs["draw:fill"] = "none";
11
19
  else {
12
20
  attrs["draw:fill"] = "solid";
@@ -60,17 +68,23 @@ function readGraphicStroke(pkg, element) {
60
68
  widthPt
61
69
  };
62
70
  }
71
+ function readGraphicTextFlowAnchored(pkg, element) {
72
+ const props = graphicProperties(pkg, element);
73
+ return props !== void 0 && attr(props, "style:vertical-rel") === TEXT_FLOW_ANCHOR_ATTRS["style:vertical-rel"];
74
+ }
63
75
  function setGraphicFill(pkg, element, fill) {
64
76
  const name = buildGraphicStyle(pkg, {
65
77
  fill,
66
- stroke: readGraphicStroke(pkg, element)
78
+ stroke: readGraphicStroke(pkg, element),
79
+ textFlowAnchored: readGraphicTextFlowAnchored(pkg, element)
67
80
  });
68
81
  setAttr(element, "draw:style-name", name);
69
82
  }
70
83
  function setGraphicStroke(pkg, element, stroke) {
71
84
  const name = buildGraphicStyle(pkg, {
72
85
  fill: readGraphicFill(pkg, element),
73
- stroke
86
+ stroke,
87
+ textFlowAnchored: readGraphicTextFlowAnchored(pkg, element)
74
88
  });
75
89
  setAttr(element, "draw:style-name", name);
76
90
  }