js.documents 1.65.0 → 1.67.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 (119) hide show
  1. package/README.md +18 -11
  2. package/dist/color-C98dn-pT.d.ts +2 -0
  3. package/dist/convert/convert.cjs +2 -1
  4. package/dist/convert/convert.js +2 -1
  5. package/dist/edit/docx/content.cjs +5 -0
  6. package/dist/edit/docx/content.js +5 -0
  7. package/dist/edit/docx/image.cjs +1 -0
  8. package/dist/edit/docx/image.d.cts +2 -2
  9. package/dist/edit/docx/image.d.ts +2 -2
  10. package/dist/edit/docx/image.js +1 -1
  11. package/dist/edit/docx/paragraph.cjs +10 -1
  12. package/dist/edit/docx/paragraph.d.cts +4 -3
  13. package/dist/edit/docx/paragraph.d.ts +4 -3
  14. package/dist/edit/docx/paragraph.js +13 -4
  15. package/dist/edit/docx/props.d.ts +1 -1
  16. package/dist/edit/docx/run.cjs +8 -1
  17. package/dist/edit/docx/run.d.cts +2 -2
  18. package/dist/edit/docx/run.d.ts +2 -2
  19. package/dist/edit/docx/run.js +8 -2
  20. package/dist/edit/docx/vector.cjs +69 -0
  21. package/dist/edit/docx/vector.d.cts +6 -0
  22. package/dist/edit/docx/vector.d.ts +6 -0
  23. package/dist/edit/docx/vector.js +68 -0
  24. package/dist/edit/drawingml/vector.cjs +113 -0
  25. package/dist/edit/drawingml/vector.d.cts +9 -0
  26. package/dist/edit/drawingml/vector.d.ts +9 -0
  27. package/dist/edit/drawingml/vector.js +109 -0
  28. package/dist/edit/odg/content.cjs +1 -26
  29. package/dist/edit/odg/content.js +1 -26
  30. package/dist/edit/odg/page.cjs +14 -1
  31. package/dist/edit/odg/page.d.cts +5 -3
  32. package/dist/edit/odg/page.d.ts +5 -3
  33. package/dist/edit/odg/page.js +14 -1
  34. package/dist/edit/odg/style.cjs +17 -3
  35. package/dist/edit/odg/style.d.cts +1 -0
  36. package/dist/edit/odg/style.d.ts +1 -0
  37. package/dist/edit/odg/style.js +17 -3
  38. package/dist/edit/odg/vector.cjs +65 -3
  39. package/dist/edit/odg/vector.d.cts +2 -2
  40. package/dist/edit/odg/vector.d.ts +2 -2
  41. package/dist/edit/odg/vector.js +63 -4
  42. package/dist/edit/odp/content.cjs +4 -1
  43. package/dist/edit/odp/content.js +5 -2
  44. package/dist/edit/odp/shape.cjs +1 -1
  45. package/dist/edit/odp/shape.d.cts +1 -1
  46. package/dist/edit/odp/shape.d.ts +1 -1
  47. package/dist/edit/odp/shape.js +1 -1
  48. package/dist/edit/odp/slide.cjs +4 -0
  49. package/dist/edit/odp/slide.d.cts +8 -5
  50. package/dist/edit/odp/slide.d.ts +9 -6
  51. package/dist/edit/odp/slide.js +4 -0
  52. package/dist/edit/odt/content.cjs +5 -0
  53. package/dist/edit/odt/content.d.ts +2 -2
  54. package/dist/edit/odt/content.js +5 -0
  55. package/dist/edit/odt/editor.cjs +7 -0
  56. package/dist/edit/odt/editor.d.cts +3 -2
  57. package/dist/edit/odt/editor.d.ts +5 -4
  58. package/dist/edit/odt/editor.js +7 -0
  59. package/dist/edit/odt/list.cjs +13 -0
  60. package/dist/edit/odt/list.d.cts +1 -1
  61. package/dist/edit/odt/list.d.ts +1 -1
  62. package/dist/edit/odt/list.js +13 -0
  63. package/dist/edit/odt/paragraph.d.ts +1 -1
  64. package/dist/edit/odt/run.d.ts +1 -1
  65. package/dist/edit/odt/table.d.ts +1 -1
  66. package/dist/edit/pptx/content.cjs +5 -2
  67. package/dist/edit/pptx/content.js +5 -2
  68. package/dist/edit/pptx/shape.cjs +2 -5
  69. package/dist/edit/pptx/shape.d.ts +1 -1
  70. package/dist/edit/pptx/shape.js +2 -5
  71. package/dist/edit/pptx/slide.cjs +7 -0
  72. package/dist/edit/pptx/slide.d.cts +6 -4
  73. package/dist/edit/pptx/slide.d.ts +8 -6
  74. package/dist/edit/pptx/slide.js +7 -0
  75. package/dist/edit/pptx/table.d.ts +1 -1
  76. package/dist/edit/pptx/vector.cjs +17 -0
  77. package/dist/edit/pptx/vector.d.cts +6 -0
  78. package/dist/edit/pptx/vector.d.ts +6 -0
  79. package/dist/edit/pptx/vector.js +16 -0
  80. package/dist/{image-BfRLAD9B.d.cts → image-DRqXQmEg.d.cts} +2 -1
  81. package/dist/{image-BfRLAD9B.d.ts → image-DRqXQmEg.d.ts} +2 -1
  82. package/dist/index.cjs +2 -2
  83. package/dist/index.d.cts +6 -6
  84. package/dist/index.d.ts +12 -12
  85. package/dist/index.js +2 -2
  86. package/dist/layout/engine.cjs +1 -5
  87. package/dist/layout/engine.js +1 -5
  88. package/dist/layout/shared.cjs +6 -0
  89. package/dist/layout/shared.d.cts +2 -1
  90. package/dist/layout/shared.d.ts +2 -1
  91. package/dist/layout/shared.js +6 -1
  92. package/dist/layout/sheets.cjs +70 -9
  93. package/dist/layout/sheets.d.cts +7 -3
  94. package/dist/layout/sheets.d.ts +7 -3
  95. package/dist/layout/sheets.js +72 -11
  96. package/dist/layout/slides.cjs +1 -5
  97. package/dist/layout/slides.js +1 -5
  98. package/dist/{list-BuBM9rwQ.d.cts → list-BzcN-LTJ.d.cts} +3 -0
  99. package/dist/{list-CvKxhy3y.d.ts → list-nlhN5bat.d.ts} +4 -1
  100. package/dist/markdown/write.cjs +1 -1
  101. package/dist/markdown/write.js +1 -1
  102. package/dist/model/color.d.ts +1 -1
  103. package/dist/model/embedded-drawing.cjs +47 -0
  104. package/dist/model/embedded-drawing.d.cts +4 -2
  105. package/dist/model/embedded-drawing.d.ts +4 -2
  106. package/dist/model/embedded-drawing.js +46 -1
  107. package/dist/{paragraph-CoUi_88j.d.ts → paragraph-DndYbWuT.d.ts} +1 -1
  108. package/dist/{run-D2rTWHbt.d.ts → run-BhYv2wJf.d.ts} +3 -2
  109. package/dist/{run-CJfh8rv3.d.ts → run-DtrwZwN6.d.ts} +1 -1
  110. package/dist/{run-B3GNScJH.d.cts → run-P0b2pDdX.d.cts} +2 -1
  111. package/dist/{shape-BkVcwPcf.d.ts → shape-B-TjU_Ej.d.ts} +1 -1
  112. package/dist/{shape-CXZ6fejV.d.cts → shape-C8qDhn0l.d.cts} +1 -1
  113. package/dist/{shape-CVXedeL7.d.ts → shape-XGp__l-J.d.ts} +2 -2
  114. package/dist/{table-DqfqMkVq.d.ts → table-BHeUmLzZ.d.ts} +1 -1
  115. package/dist/{table-DvS_7UQS.d.ts → table-DQpKafyl.d.ts} +1 -1
  116. package/dist/{vector-Puuqu_IT.d.cts → vector-D03KX8Ux.d.cts} +15 -2
  117. package/dist/{vector-Puuqu_IT.d.ts → vector-D03KX8Ux.d.ts} +15 -2
  118. package/package.json +3 -3
  119. package/dist/color-Bo228AY2.d.ts +0 -2
@@ -1,9 +1,9 @@
1
1
  import { r as MathMlNode$1 } from "../../nodes-pArN9ilm.js";
2
2
  import { t as OmmlWriteResult } from "../../write-THs7ipBq.js";
3
- import { n as MediaContext, t as ImageInit } from "../../image-BfRLAD9B.js";
4
- import { n as RunInit, t as DocxRun } from "../../run-D2rTWHbt.js";
3
+ import { n as MediaContext, t as ImageInit } from "../../image-DRqXQmEg.js";
4
+ import { n as RunInit, t as DocxRun } from "../../run-BhYv2wJf.js";
5
5
  import { Package, XmlElement, XmlNode } from "ooxml.js";
6
- import { ContentListMembership } from "document-schema.js";
6
+ import { ContentListMembership, ContentVector } from "document-schema.js";
7
7
  //#region src/edit/docx/paragraph.d.ts
8
8
  interface ParagraphInit {
9
9
  readonly text?: string;
@@ -37,6 +37,7 @@ declare class DocxParagraph {
37
37
  appendOfficeMath(mathml: readonly MathMlNode$1[]): OmmlWriteResult & {
38
38
  readonly written: boolean;
39
39
  };
40
+ appendVectorAnchors(vectors: readonly ContentVector[]): void;
40
41
  insertImageAfter(image: ImageInit): void;
41
42
  remove(): void;
42
43
  }
@@ -1,10 +1,11 @@
1
1
  import { el } from "../../xml/fragment.js";
2
2
  import { buildOfficeMathParagraph } from "../../omml/write.js";
3
3
  import { getOrCreateChildElement, removeChild } from "../../xml/edit.js";
4
- import { insertImageMedia } from "./image.js";
4
+ import { insertImageMedia, nextDrawingId } from "./image.js";
5
5
  import { PPR_ORDER, ensureFirstChild, getAlignment, getStyleId, setAlignment, setStyleId } from "./props.js";
6
- import { DocxRun, buildRun } from "./run.js";
7
- import { attr, textContent } from "ooxml.js";
6
+ import { DocxRun, buildRun, wordprocessingText } from "./run.js";
7
+ import { buildAnchoredVectorDrawing } from "./vector.js";
8
+ import { attr } from "ooxml.js";
8
9
  //#region src/edit/docx/paragraph.ts
9
10
  function directChild(parent, tag) {
10
11
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
@@ -28,7 +29,7 @@ var DocxParagraph = class {
28
29
  return create ? ensureFirstChild(node, "w:pPr") : directChild(node, "w:pPr");
29
30
  }
30
31
  get text() {
31
- return textContent(this.live());
32
+ return wordprocessingText(this.live());
32
33
  }
33
34
  runs() {
34
35
  const node = this.live();
@@ -117,6 +118,14 @@ var DocxParagraph = class {
117
118
  written: true
118
119
  };
119
120
  }
121
+ appendVectorAnchors(vectors) {
122
+ const node = this.live();
123
+ if (this.imageContext === void 0) throw new Error("appendVectorAnchors requires a paragraph opened through a DocxEditor");
124
+ const { documentRoot } = this.imageContext;
125
+ vectors.forEach((vector, index) => {
126
+ node.children.push(el("w:r", {}, [buildAnchoredVectorDrawing(vector, nextDrawingId(documentRoot), index)]));
127
+ });
128
+ }
120
129
  insertImageAfter(image) {
121
130
  const node = this.live();
122
131
  if (this.imageContext === void 0) throw new Error("insertImageAfter requires a paragraph opened through a DocxEditor");
@@ -1,4 +1,4 @@
1
- import { n as LayoutColor } from "../../color-Bo228AY2.js";
1
+ import { n as LayoutColor } from "../../color-C98dn-pT.js";
2
2
  import { XmlElement } from "ooxml.js";
3
3
  //#region src/edit/docx/props.d.ts
4
4
  declare const RPR_ORDER: readonly string[];
@@ -3,9 +3,15 @@ const require_xml_fragment = require("../../xml/fragment.cjs");
3
3
  const require_xml_entities = require("../../xml/entities.cjs");
4
4
  const require_xml_edit = require("../../xml/edit.cjs");
5
5
  const require_edit_docx_props = require("./props.cjs");
6
+ const require_xml_query = require("../../xml/query.cjs");
6
7
  let ooxml_js = require("ooxml.js");
7
8
  let document_schema_js = require("document-schema.js");
8
9
  //#region src/edit/docx/run.ts
10
+ function wordprocessingText(element) {
11
+ let out = "";
12
+ for (const cursor of require_xml_query.walkElements([element])) if (cursor.node.tag === "w:t") out += (0, ooxml_js.textContent)(cursor.node);
13
+ return out;
14
+ }
9
15
  function directChild(parent, tag) {
10
16
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
11
17
  }
@@ -38,7 +44,7 @@ var DocxRun = class {
38
44
  return create ? require_edit_docx_props.ensureFirstChild(node, "w:rPr") : directChild(node, "w:rPr");
39
45
  }
40
46
  get text() {
41
- return (0, ooxml_js.textContent)(this.live());
47
+ return wordprocessingText(this.live());
42
48
  }
43
49
  set text(value) {
44
50
  const tNode = findOrCreateT(this.live());
@@ -141,3 +147,4 @@ function buildRun(init = {}) {
141
147
  //#endregion
142
148
  exports.DocxRun = DocxRun;
143
149
  exports.buildRun = buildRun;
150
+ exports.wordprocessingText = wordprocessingText;
@@ -1,2 +1,2 @@
1
- import { n as RunInit, r as buildRun, t as DocxRun } from "../../run-B3GNScJH.cjs";
2
- export { DocxRun, RunInit, buildRun };
1
+ import { i as wordprocessingText, n as RunInit, r as buildRun, t as DocxRun } from "../../run-P0b2pDdX.cjs";
2
+ export { DocxRun, RunInit, buildRun, wordprocessingText };
@@ -1,2 +1,2 @@
1
- import { n as RunInit, r as buildRun, t as DocxRun } from "../../run-D2rTWHbt.js";
2
- export { DocxRun, RunInit, buildRun };
1
+ import { i as wordprocessingText, n as RunInit, r as buildRun, t as DocxRun } from "../../run-BhYv2wJf.js";
2
+ export { DocxRun, RunInit, buildRun, wordprocessingText };
@@ -3,8 +3,14 @@ import { el, txt } from "../../xml/fragment.js";
3
3
  import { encodeXmlText, needsSpacePreserve } from "../../xml/entities.js";
4
4
  import { removeChild, setAttr } from "../../xml/edit.js";
5
5
  import { RPR_ORDER, ensureFirstChild, getColor, getFontFamily, getSizePt, getToggle, setColor, setFontFamily, setSizePt, setToggle } from "./props.js";
6
+ import { walkElements } from "../../xml/query.js";
6
7
  import { textContent } from "ooxml.js";
7
8
  //#region src/edit/docx/run.ts
9
+ function wordprocessingText(element) {
10
+ let out = "";
11
+ for (const cursor of walkElements([element])) if (cursor.node.tag === "w:t") out += textContent(cursor.node);
12
+ return out;
13
+ }
8
14
  function directChild(parent, tag) {
9
15
  for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
10
16
  }
@@ -37,7 +43,7 @@ var DocxRun = class {
37
43
  return create ? ensureFirstChild(node, "w:rPr") : directChild(node, "w:rPr");
38
44
  }
39
45
  get text() {
40
- return textContent(this.live());
46
+ return wordprocessingText(this.live());
41
47
  }
42
48
  set text(value) {
43
49
  const tNode = findOrCreateT(this.live());
@@ -138,4 +144,4 @@ function buildRun(init = {}) {
138
144
  return run;
139
145
  }
140
146
  //#endregion
141
- export { DocxRun, buildRun };
147
+ export { DocxRun, buildRun, wordprocessingText };
@@ -0,0 +1,69 @@
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
+ const require_edit_drawingml_vector = require("../drawingml/vector.cjs");
5
+ //#region src/edit/docx/vector.ts
6
+ const DRAWING_NS = {
7
+ wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
8
+ a: "http://schemas.openxmlformats.org/drawingml/2006/main",
9
+ wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
10
+ };
11
+ const ANCHOR_ATTRS = {
12
+ distT: "0",
13
+ distB: "0",
14
+ distL: "0",
15
+ distR: "0",
16
+ simplePos: "0",
17
+ locked: "0",
18
+ layoutInCell: "1",
19
+ allowOverlap: "1",
20
+ behindDoc: "1"
21
+ };
22
+ function position(tag, offsetPt) {
23
+ return require_xml_fragment.el(tag, { relativeFrom: "page" }, [require_xml_fragment.el("wp:posOffset", {}, [require_xml_fragment.txt(String(require_model_units.ptToEmu(offsetPt)))])]);
24
+ }
25
+ function buildAnchoredVectorDrawing(vector, drawingId, relativeHeight) {
26
+ const frame = require_edit_drawingml_vector.vectorPlacementBox(vector);
27
+ const cx = String(require_model_units.ptToEmu(frame.widthPt));
28
+ const cy = String(require_model_units.ptToEmu(frame.heightPt));
29
+ const name = require_edit_drawingml_vector.vectorShapeName(vector, drawingId);
30
+ const wsp = require_xml_fragment.el("wps:wsp", {}, [
31
+ require_xml_fragment.el("wps:cNvSpPr"),
32
+ require_xml_fragment.el("wps:spPr", {}, require_edit_drawingml_vector.buildVectorShapeProperties(vector)),
33
+ require_xml_fragment.el("wps:bodyPr")
34
+ ]);
35
+ const anchor = require_xml_fragment.el("wp:anchor", {
36
+ ...ANCHOR_ATTRS,
37
+ relativeHeight: String(relativeHeight)
38
+ }, [
39
+ require_xml_fragment.el("wp:simplePos", {
40
+ x: "0",
41
+ y: "0"
42
+ }),
43
+ position("wp:positionH", frame.xPt),
44
+ position("wp:positionV", frame.yPt),
45
+ require_xml_fragment.el("wp:extent", {
46
+ cx,
47
+ cy
48
+ }),
49
+ require_xml_fragment.el("wp:effectExtent", {
50
+ l: "0",
51
+ t: "0",
52
+ r: "0",
53
+ b: "0"
54
+ }),
55
+ require_xml_fragment.el("wp:wrapNone"),
56
+ require_xml_fragment.el("wp:docPr", {
57
+ id: String(drawingId),
58
+ name
59
+ }),
60
+ require_xml_fragment.el("a:graphic", {}, [require_xml_fragment.el("a:graphicData", { uri: DRAWING_NS.wps }, [wsp])])
61
+ ]);
62
+ return require_xml_fragment.el("w:drawing", {
63
+ "xmlns:wp": DRAWING_NS.wp,
64
+ "xmlns:a": DRAWING_NS.a,
65
+ "xmlns:wps": DRAWING_NS.wps
66
+ }, [anchor]);
67
+ }
68
+ //#endregion
69
+ exports.buildAnchoredVectorDrawing = buildAnchoredVectorDrawing;
@@ -0,0 +1,6 @@
1
+ import { ContentVector } from "document-schema.js";
2
+ import { XmlElement } from "ooxml.js";
3
+ //#region src/edit/docx/vector.d.ts
4
+ declare function buildAnchoredVectorDrawing(vector: ContentVector, drawingId: number, relativeHeight: number): XmlElement;
5
+ //#endregion
6
+ export { buildAnchoredVectorDrawing };
@@ -0,0 +1,6 @@
1
+ import { XmlElement } from "ooxml.js";
2
+ import { ContentVector } from "document-schema.js";
3
+ //#region src/edit/docx/vector.d.ts
4
+ declare function buildAnchoredVectorDrawing(vector: ContentVector, drawingId: number, relativeHeight: number): XmlElement;
5
+ //#endregion
6
+ export { buildAnchoredVectorDrawing };
@@ -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;