@md2nativedocx/core 0.6.0 → 0.8.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 (242) hide show
  1. package/dist/diagrams/agentflow/parser.d.ts +20 -0
  2. package/dist/diagrams/agentflow/parser.js +155 -0
  3. package/dist/diagrams/agentflow/parser.js.map +1 -0
  4. package/dist/diagrams/architecture-diagram/icons.d.ts +24 -0
  5. package/dist/diagrams/architecture-diagram/icons.js +148 -0
  6. package/dist/diagrams/architecture-diagram/icons.js.map +1 -0
  7. package/dist/diagrams/architecture-diagram/layout.d.ts +71 -0
  8. package/dist/diagrams/architecture-diagram/layout.js +388 -0
  9. package/dist/diagrams/architecture-diagram/layout.js.map +1 -0
  10. package/dist/diagrams/architecture-diagram/parser.d.ts +14 -19
  11. package/dist/diagrams/architecture-diagram/parser.js +316 -113
  12. package/dist/diagrams/architecture-diagram/parser.js.map +1 -1
  13. package/dist/diagrams/architecture-diagram/translator.d.ts +26 -36
  14. package/dist/diagrams/architecture-diagram/translator.js +234 -147
  15. package/dist/diagrams/architecture-diagram/translator.js.map +1 -1
  16. package/dist/diagrams/architecture-diagram/types.d.ts +26 -16
  17. package/dist/diagrams/architecture-diagram/types.js +4 -14
  18. package/dist/diagrams/architecture-diagram/types.js.map +1 -1
  19. package/dist/diagrams/c4/parser.d.ts +11 -19
  20. package/dist/diagrams/c4/parser.js +242 -90
  21. package/dist/diagrams/c4/parser.js.map +1 -1
  22. package/dist/diagrams/c4/translator.d.ts +23 -43
  23. package/dist/diagrams/c4/translator.js +333 -204
  24. package/dist/diagrams/c4/translator.js.map +1 -1
  25. package/dist/diagrams/c4/types.d.ts +78 -45
  26. package/dist/diagrams/c4/types.js +17 -38
  27. package/dist/diagrams/c4/types.js.map +1 -1
  28. package/dist/diagrams/class-diagram/parser.d.ts +10 -11
  29. package/dist/diagrams/class-diagram/parser.js +322 -74
  30. package/dist/diagrams/class-diagram/parser.js.map +1 -1
  31. package/dist/diagrams/class-diagram/translator.d.ts +10 -10
  32. package/dist/diagrams/class-diagram/translator.js +305 -33
  33. package/dist/diagrams/class-diagram/translator.js.map +1 -1
  34. package/dist/diagrams/class-diagram/types.d.ts +61 -4
  35. package/dist/diagrams/er-diagram/parser.d.ts +22 -19
  36. package/dist/diagrams/er-diagram/parser.js +412 -89
  37. package/dist/diagrams/er-diagram/parser.js.map +1 -1
  38. package/dist/diagrams/er-diagram/translator.d.ts +8 -0
  39. package/dist/diagrams/er-diagram/translator.js +170 -38
  40. package/dist/diagrams/er-diagram/translator.js.map +1 -1
  41. package/dist/diagrams/er-diagram/types.d.ts +32 -5
  42. package/dist/diagrams/er-diagram/types.js +2 -5
  43. package/dist/diagrams/er-diagram/types.js.map +1 -1
  44. package/dist/diagrams/flowchart-source.d.ts +106 -0
  45. package/dist/diagrams/flowchart-source.js +272 -0
  46. package/dist/diagrams/flowchart-source.js.map +1 -0
  47. package/dist/diagrams/gantt/date-utils.d.ts +55 -33
  48. package/dist/diagrams/gantt/date-utils.js +147 -58
  49. package/dist/diagrams/gantt/date-utils.js.map +1 -1
  50. package/dist/diagrams/gantt/parser.d.ts +31 -22
  51. package/dist/diagrams/gantt/parser.js +259 -141
  52. package/dist/diagrams/gantt/parser.js.map +1 -1
  53. package/dist/diagrams/gantt/time-axis.d.ts +44 -0
  54. package/dist/diagrams/gantt/time-axis.js +158 -0
  55. package/dist/diagrams/gantt/time-axis.js.map +1 -0
  56. package/dist/diagrams/gantt/translator.d.ts +8 -5
  57. package/dist/diagrams/gantt/translator.js +72 -60
  58. package/dist/diagrams/gantt/translator.js.map +1 -1
  59. package/dist/diagrams/gantt/types.d.ts +25 -4
  60. package/dist/diagrams/gantt/types.js +4 -3
  61. package/dist/diagrams/gantt/types.js.map +1 -1
  62. package/dist/diagrams/mindmap/parser.d.ts +18 -14
  63. package/dist/diagrams/mindmap/parser.js +169 -69
  64. package/dist/diagrams/mindmap/parser.js.map +1 -1
  65. package/dist/diagrams/mindmap/translator.js +90 -35
  66. package/dist/diagrams/mindmap/translator.js.map +1 -1
  67. package/dist/diagrams/mindmap/types.d.ts +18 -0
  68. package/dist/diagrams/packet/parser.js +1 -1
  69. package/dist/diagrams/packet/parser.js.map +1 -1
  70. package/dist/diagrams/pie/translator.js +5 -4
  71. package/dist/diagrams/pie/translator.js.map +1 -1
  72. package/dist/diagrams/plantuml/class-parser.d.ts +2 -1
  73. package/dist/diagrams/plantuml/class-parser.js +19 -11
  74. package/dist/diagrams/plantuml/class-parser.js.map +1 -1
  75. package/dist/diagrams/plantuml/sequence-parser.d.ts +3 -2
  76. package/dist/diagrams/plantuml/sequence-parser.js +28 -12
  77. package/dist/diagrams/plantuml/sequence-parser.js.map +1 -1
  78. package/dist/diagrams/plantuml/state-parser.d.ts +5 -3
  79. package/dist/diagrams/plantuml/state-parser.js +141 -19
  80. package/dist/diagrams/plantuml/state-parser.js.map +1 -1
  81. package/dist/diagrams/quadrant/translator.js +5 -4
  82. package/dist/diagrams/quadrant/translator.js.map +1 -1
  83. package/dist/diagrams/railroad/layout.d.ts +89 -0
  84. package/dist/diagrams/railroad/layout.js +235 -0
  85. package/dist/diagrams/railroad/layout.js.map +1 -0
  86. package/dist/diagrams/railroad/parser.d.ts +37 -0
  87. package/dist/diagrams/railroad/parser.js +605 -0
  88. package/dist/diagrams/railroad/parser.js.map +1 -0
  89. package/dist/diagrams/railroad/translator.d.ts +11 -0
  90. package/dist/diagrams/railroad/translator.js +101 -0
  91. package/dist/diagrams/railroad/translator.js.map +1 -0
  92. package/dist/diagrams/railroad/types.d.ts +61 -0
  93. package/dist/diagrams/railroad/types.js +7 -0
  94. package/dist/diagrams/railroad/types.js.map +1 -0
  95. package/dist/diagrams/requirement-diagram/parser.d.ts +26 -19
  96. package/dist/diagrams/requirement-diagram/parser.js +249 -70
  97. package/dist/diagrams/requirement-diagram/parser.js.map +1 -1
  98. package/dist/diagrams/requirement-diagram/translator.d.ts +16 -11
  99. package/dist/diagrams/requirement-diagram/translator.js +170 -50
  100. package/dist/diagrams/requirement-diagram/translator.js.map +1 -1
  101. package/dist/diagrams/requirement-diagram/types.d.ts +30 -9
  102. package/dist/diagrams/requirement-diagram/types.js +7 -5
  103. package/dist/diagrams/requirement-diagram/types.js.map +1 -1
  104. package/dist/diagrams/sequence/parser.d.ts +8 -7
  105. package/dist/diagrams/sequence/parser.js +129 -32
  106. package/dist/diagrams/sequence/parser.js.map +1 -1
  107. package/dist/diagrams/sequence/participant-glyph.d.ts +38 -0
  108. package/dist/diagrams/sequence/participant-glyph.js +97 -0
  109. package/dist/diagrams/sequence/participant-glyph.js.map +1 -0
  110. package/dist/diagrams/sequence/participant-kind.d.ts +7 -0
  111. package/dist/diagrams/sequence/participant-kind.js +19 -0
  112. package/dist/diagrams/sequence/participant-kind.js.map +1 -0
  113. package/dist/diagrams/sequence/translator.d.ts +7 -3
  114. package/dist/diagrams/sequence/translator.js +140 -28
  115. package/dist/diagrams/sequence/translator.js.map +1 -1
  116. package/dist/diagrams/sequence/types.d.ts +24 -1
  117. package/dist/diagrams/state-diagram/parser.d.ts +24 -24
  118. package/dist/diagrams/state-diagram/parser.js +259 -73
  119. package/dist/diagrams/state-diagram/parser.js.map +1 -1
  120. package/dist/diagrams/state-diagram/translator.d.ts +13 -1
  121. package/dist/diagrams/state-diagram/translator.js +554 -72
  122. package/dist/diagrams/state-diagram/translator.js.map +1 -1
  123. package/dist/diagrams/state-diagram/types.d.ts +57 -11
  124. package/dist/diagrams/state-diagram/types.js +5 -7
  125. package/dist/diagrams/state-diagram/types.js.map +1 -1
  126. package/dist/diagrams/tree-view/implicit-root.d.ts +11 -0
  127. package/dist/diagrams/tree-view/implicit-root.js +14 -0
  128. package/dist/diagrams/tree-view/implicit-root.js.map +1 -0
  129. package/dist/diagrams/tree-view/parser.d.ts +23 -8
  130. package/dist/diagrams/tree-view/parser.js +242 -98
  131. package/dist/diagrams/tree-view/parser.js.map +1 -1
  132. package/dist/diagrams/tree-view/translator.d.ts +6 -5
  133. package/dist/diagrams/tree-view/translator.js +40 -23
  134. package/dist/diagrams/tree-view/translator.js.map +1 -1
  135. package/dist/diagrams/tree-view/types.d.ts +22 -6
  136. package/dist/diagrams/tree-view/types.js +2 -2
  137. package/dist/diagrams/treemap/parser.d.ts +2 -2
  138. package/dist/diagrams/treemap/parser.js +5 -12
  139. package/dist/diagrams/treemap/parser.js.map +1 -1
  140. package/dist/diagrams/usecase/parser.d.ts +24 -0
  141. package/dist/diagrams/usecase/parser.js +232 -0
  142. package/dist/diagrams/usecase/parser.js.map +1 -0
  143. package/dist/diagrams/venn/translator.js +5 -4
  144. package/dist/diagrams/venn/translator.js.map +1 -1
  145. package/dist/diagrams/zenuml/parser.d.ts +2 -2
  146. package/dist/diagrams/zenuml/parser.js +14 -7
  147. package/dist/diagrams/zenuml/parser.js.map +1 -1
  148. package/dist/index.d.ts +7 -1
  149. package/dist/index.js +5 -1
  150. package/dist/index.js.map +1 -1
  151. package/dist/layout/collapse-subgraphs.d.ts +18 -0
  152. package/dist/layout/collapse-subgraphs.js +80 -0
  153. package/dist/layout/collapse-subgraphs.js.map +1 -0
  154. package/dist/layout/layout.d.ts +11 -0
  155. package/dist/layout/layout.js +89 -17
  156. package/dist/layout/layout.js.map +1 -1
  157. package/dist/parser/css-named-colors.d.ts +7 -0
  158. package/dist/parser/css-named-colors.js +157 -0
  159. package/dist/parser/css-named-colors.js.map +1 -0
  160. package/dist/parser/css-style.d.ts +39 -0
  161. package/dist/parser/css-style.js +88 -0
  162. package/dist/parser/css-style.js.map +1 -0
  163. package/dist/parser/diagram-type.d.ts +12 -1
  164. package/dist/parser/diagram-type.js +4 -0
  165. package/dist/parser/diagram-type.js.map +1 -1
  166. package/dist/parser/entities.d.ts +5 -0
  167. package/dist/parser/entities.js +52 -0
  168. package/dist/parser/entities.js.map +1 -0
  169. package/dist/parser/frontmatter.d.ts +36 -0
  170. package/dist/parser/frontmatter.js +66 -0
  171. package/dist/parser/frontmatter.js.map +1 -0
  172. package/dist/parser/interactive.d.ts +13 -0
  173. package/dist/parser/interactive.js +17 -0
  174. package/dist/parser/interactive.js.map +1 -0
  175. package/dist/parser/label.d.ts +37 -0
  176. package/dist/parser/label.js +73 -0
  177. package/dist/parser/label.js.map +1 -0
  178. package/dist/parser/normalize-statements.d.ts +8 -0
  179. package/dist/parser/normalize-statements.js +17 -2
  180. package/dist/parser/normalize-statements.js.map +1 -1
  181. package/dist/parser/parser.d.ts +2 -1
  182. package/dist/parser/parser.js +345 -324
  183. package/dist/parser/parser.js.map +1 -1
  184. package/dist/render-diagram-odf.d.ts +2 -1
  185. package/dist/render-diagram-odf.js +39 -8
  186. package/dist/render-diagram-odf.js.map +1 -1
  187. package/dist/render-diagram.d.ts +11 -3
  188. package/dist/render-diagram.js +66 -23
  189. package/dist/render-diagram.js.map +1 -1
  190. package/dist/smartart/chain.js +1 -1
  191. package/dist/smartart/chain.js.map +1 -1
  192. package/dist/smartart/cycle.js +1 -1
  193. package/dist/smartart/cycle.js.map +1 -1
  194. package/dist/smartart/drawing.js +2 -10
  195. package/dist/smartart/drawing.js.map +1 -1
  196. package/dist/smartart/embed.d.ts +4 -3
  197. package/dist/smartart/embed.js +5 -4
  198. package/dist/smartart/embed.js.map +1 -1
  199. package/dist/smartart/from-graph.d.ts +13 -3
  200. package/dist/smartart/from-graph.js +39 -7
  201. package/dist/smartart/from-graph.js.map +1 -1
  202. package/dist/smartart/from-tree.d.ts +9 -5
  203. package/dist/smartart/from-tree.js +23 -11
  204. package/dist/smartart/from-tree.js.map +1 -1
  205. package/dist/smartart/text.d.ts +18 -4
  206. package/dist/smartart/text.js +32 -8
  207. package/dist/smartart/text.js.map +1 -1
  208. package/dist/smartart/tree-deep.js +1 -1
  209. package/dist/smartart/tree-deep.js.map +1 -1
  210. package/dist/smartart/tree.js +2 -2
  211. package/dist/smartart/tree.js.map +1 -1
  212. package/dist/translator/actor-figure.d.ts +45 -0
  213. package/dist/translator/actor-figure.js +46 -0
  214. package/dist/translator/actor-figure.js.map +1 -0
  215. package/dist/translator/boxes.d.ts +12 -1
  216. package/dist/translator/boxes.js +11 -6
  217. package/dist/translator/boxes.js.map +1 -1
  218. package/dist/translator/canvas.d.ts +28 -1
  219. package/dist/translator/canvas.js +83 -16
  220. package/dist/translator/canvas.js.map +1 -1
  221. package/dist/translator/custom-geometry.d.ts +28 -0
  222. package/dist/translator/custom-geometry.js +59 -0
  223. package/dist/translator/custom-geometry.js.map +1 -0
  224. package/dist/translator/elbow-connector.d.ts +52 -0
  225. package/dist/translator/elbow-connector.js +110 -0
  226. package/dist/translator/elbow-connector.js.map +1 -0
  227. package/dist/translator/graph-shapes.d.ts +40 -4
  228. package/dist/translator/graph-shapes.js +62 -10
  229. package/dist/translator/graph-shapes.js.map +1 -1
  230. package/dist/translator/label-runs.d.ts +14 -0
  231. package/dist/translator/label-runs.js +36 -0
  232. package/dist/translator/label-runs.js.map +1 -0
  233. package/dist/translator/odf-translator.js +56 -24
  234. package/dist/translator/odf-translator.js.map +1 -1
  235. package/dist/translator/ooxml-translator.d.ts +17 -11
  236. package/dist/translator/ooxml-translator.js +159 -146
  237. package/dist/translator/ooxml-translator.js.map +1 -1
  238. package/dist/translator/text-color.d.ts +9 -0
  239. package/dist/translator/text-color.js +17 -0
  240. package/dist/translator/text-color.js.map +1 -0
  241. package/dist/types.d.ts +27 -4
  242. package/package.json +1 -1
@@ -41,6 +41,12 @@
41
41
  */
42
42
  import { EDGE_LABEL_PAD_X_PX, SUBGRAPH_TITLE_HEIGHT, edgeLabelSize } from '../layout/layout.js';
43
43
  import { escapeXml } from './xml-escape.js';
44
+ import { DEFAULT_MAX_DRAWING_CX, DEFAULT_MAX_DRAWING_CY } from './canvas.js';
45
+ import { renderLabelRuns } from './label-runs.js';
46
+ import { HOLLOW_SIZE_PX, hollowMarker } from './graph-shapes.js';
47
+ import { actorConnectBox, actorFigure } from './actor-figure.js';
48
+ import { textColorFor } from './text-color.js';
49
+ import { elbowConnectorGeometry, elbowRoute } from './elbow-connector.js';
44
50
  /** Pixels -> EMU (English Metric Units). Word uses 914400 EMU per inch; at 96
45
51
  * DPI that is 9525 EMU per pixel. */
46
52
  const EMU_PER_PX = 9525;
@@ -141,48 +147,6 @@ function scaledLineWidth(baseEmu, scale) {
141
147
  function arrowMarkerSize(baseWidthEmu, scale) {
142
148
  return baseWidthEmu * scale < MIN_LINE_WIDTH_EMU ? 'sm' : 'med';
143
149
  }
144
- /**
145
- * Usable page area in EMU for Pandoc's default reference document (US Letter,
146
- * 1 inch margins => 6.5in x 9in). A drawing larger than this is scaled down
147
- * uniformly rather than being clipped by Word: `wp:extent` and the group's
148
- * `a:ext` shrink while `a:chOff`/`a:chExt` stay in native coordinates, so Word
149
- * applies the homothety to every child shape for us.
150
- *
151
- * These are only the *default* fallback now (`export_customization_SPEC.md`
152
- * §2.4): a caller whose export uses a different page format/orientation/
153
- * margins (Lot 1) passes the real usable area via `TranslateOptions.maxDrawingCx`/
154
- * `maxDrawingCy` instead of relying on this Letter-portrait assumption.
155
- *
156
- * Height IS capped, on purpose, even though the drawing is `wp:inline` (flows
157
- * with the text) and one might expect Word to paginate an over-height inline
158
- * object the way it does an oversized picture. It does not, for this element
159
- * — see {@link MIN_SAFE_ASPECT_RATIO} for what's actually going on and why a
160
- * height cap alone was never the whole story. Not verified against real
161
- * Word; treat the multi-page case as genuinely unresolved (see TODO.md).
162
- */
163
- const MAX_DRAWING_CX = 5943600;
164
- const MAX_DRAWING_CY = 8229600;
165
- /**
166
- * Above this native (unscaled) height, a `wpc:wpc`/`wpg:wgp` group renders in
167
- * LibreOffice ONLY IF its width:height ratio is at least
168
- * {@link MIN_SAFE_ASPECT_RATIO} — narrower than that, and headless
169
- * `soffice --convert-to png/pdf` produces nothing at all for it: no shapes,
170
- * no error, no partial output, just the surrounding document text. Below this
171
- * height, any ratio renders fine, however narrow (verified down to 0.09).
172
- *
173
- * Found empirically with ~25 controlled renders (fixed content, only height
174
- * and/or width varied): e.g. at a fixed native height of 13.75in, width
175
- * 10.62in (ratio 0.77) rendered nothing while width 12.5in (ratio 0.91)
176
- * rendered correctly — same height, only the ratio changed. Bracketed the
177
- * height cliff itself (at ratio-safe / unscaled shapes) between 7.92in
178
- * (renders) and 9.38in (does not). Neither boundary was pinned to exact
179
- * precision, so both constants below carry a safety margin: 7.5in is below
180
- * the lowest observed safe height, 1.0 is above the highest observed unsafe
181
- * ratio. Not explained by LibreOffice's source (no access to it), and not
182
- * verified in real Word.
183
- */
184
- const TALL_RATIO_RISK_HEIGHT = 6858000; // 7.5in
185
- const MIN_SAFE_ASPECT_RATIO = 1.0;
186
150
  /**
187
151
  * Map a node shape to its DrawingML preset geometry (spec §6.1, extended to
188
152
  * the v11.3+ `@{ shape: ... }` catalog — see `SHAPE_ALIAS_MAP` in
@@ -222,6 +186,8 @@ export const PRST_BY_SHAPE = {
222
186
  horizontalCylinder: 'flowChartMagneticDisk',
223
187
  linedCylinder: 'flowChartMagneticDrum',
224
188
  manualInput: 'flowChartManualInput',
189
+ actor: 'rect', // drawn by actorGeometryXml (custom geometry), never as this preset
190
+ collapsedGroup: 'roundRect', // a folded subgraph; subgraph colours, see renderContent
225
191
  asymmetric: 'homePlate', // Mermaid's asymmetric/flag shape (id>Text]); closest built-in preset
226
192
  };
227
193
  /**
@@ -259,6 +225,9 @@ const LINE_STYLE_BY_EDGE = {
259
225
  circleBoth: { dash: 'solid', width: 12700, headEnd: 'oval', tailEnd: 'oval' },
260
226
  crossBoth: { dash: 'solid', width: 12700, headEnd: 'diamond', tailEnd: 'diamond' },
261
227
  invisible: { dash: 'solid', width: 12700, headEnd: 'none', tailEnd: 'none', invisible: true },
228
+ // The hollow triangle is a separate polygon laid over the end of the line (see renderEdge).
229
+ generalization: { dash: 'solid', width: 12700, headEnd: 'none', tailEnd: 'none' },
230
+ realization: { dash: 'dash', width: 12700, headEnd: 'none', tailEnd: 'none' },
262
231
  };
263
232
  /** Namespaces declared inline on the root `wpg:wgp` (self-contained, rule #3). */
264
233
  const NS = {
@@ -290,20 +259,6 @@ function createIdAllocator() {
290
259
  function hexColor(value, fallback) {
291
260
  return value !== undefined && /^[0-9A-Fa-f]{6}$/.test(value) ? value.toUpperCase() : fallback;
292
261
  }
293
- /**
294
- * Pick a readable text color for a shape fill, so labels stay visible on both
295
- * light and dark fills. Word resolves shape text color from the theme
296
- * (`a:fontRef` -> `lt1`, i.e. white), which is invisible on the light default
297
- * fill; an explicit run color overrides it.
298
- */
299
- function textColorFor(fillHex) {
300
- const r = parseInt(fillHex.slice(0, 2), 16);
301
- const g = parseInt(fillHex.slice(2, 4), 16);
302
- const b = parseInt(fillHex.slice(4, 6), 16);
303
- // Relative luminance (sRGB coefficients, WCAG's simplified form).
304
- const luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
305
- return luminance > 0.6 ? '000000' : 'FFFFFF';
306
- }
307
262
  /** Default node-text insets (EMU, unscaled): 0.1in left/right, 0.05in
308
263
  * top/bottom — Word's own defaults for a text-bearing shape. */
309
264
  const NODE_TEXT_INSET_X = 91440;
@@ -377,15 +332,22 @@ export function translateToOoxml(flowchart, layout, options = {}) {
377
332
  return wrapInParagraph(content, bb, docPrId, maxExtent);
378
333
  }
379
334
  function maxExtentOf(options) {
380
- return { cx: options.maxDrawingCx ?? MAX_DRAWING_CX, cy: options.maxDrawingCy ?? MAX_DRAWING_CY };
335
+ return { cx: options.maxDrawingCx ?? DEFAULT_MAX_DRAWING_CX, cy: options.maxDrawingCy ?? DEFAULT_MAX_DRAWING_CY };
381
336
  }
382
337
  /**
383
- * Size, in points, of the node labels as written in the `.docx`: the base 12 pt scaled down by the factor
384
- * that fits the diagram on the page. Used to warn when a diagram became too small to read (TODO R2.3).
338
+ * How the node labels fit the page, for the warning when a diagram became too small to read (TODO R2.3):
339
+ * `fontPt`, their size in points as written in the `.docx` (the base 12 pt scaled down by the factor that
340
+ * fits the diagram on the page), and `tooTall`, whether the content overflows the page more in height
341
+ * than in width.
385
342
  */
386
- export function effectiveNodeFontPt(layout, options = {}) {
387
- const { scale } = scaledExtent(computeBoundingBox(layout), maxExtentOf(options));
388
- return (scaledFontSizeHalfPt(NODE_FONT_SIZE_HALFPT, scale)) / 2;
343
+ export function nodeTextFit(layout, options = {}) {
344
+ const bb = computeBoundingBox(layout);
345
+ const maxExtent = maxExtentOf(options);
346
+ const { scale } = scaledExtent(bb, maxExtent);
347
+ return {
348
+ fontPt: scaledFontSizeHalfPt(NODE_FONT_SIZE_HALFPT, scale) / 2,
349
+ tooTall: bb.height / maxExtent.cy > bb.width / maxExtent.cx,
350
+ };
389
351
  }
390
352
  /**
391
353
  * Render subgraphs + nodes + edges as siblings directly under the drawing
@@ -421,8 +383,9 @@ function renderContent(flowchart, layout, fill, line, nextId, scale) {
421
383
  }
422
384
  // Render subgraph titles (spec §6.1) as flat shapes, then nodes and edges.
423
385
  const renderedSubgraphs = new Set();
386
+ const containerIds = new Map();
424
387
  for (const sg of flowchart.subgraphs) {
425
- parts.push(renderSubgraph(sg, flowchart, layout, renderedSubgraphs, nextId, scale));
388
+ parts.push(renderSubgraph(sg, flowchart, layout, renderedSubgraphs, nextId, scale, containerIds));
426
389
  }
427
390
  for (const node of flowchart.nodes) {
428
391
  const box = layout.nodes[node.id];
@@ -430,18 +393,38 @@ function renderContent(flowchart, layout, fill, line, nextId, scale) {
430
393
  continue;
431
394
  // Per-node fill/stroke from classDef/style/`:::` take priority over the
432
395
  // global default (spec §6.3).
433
- const nodeFill = hexColor(node.fill, fill);
434
- const nodeLine = hexColor(node.stroke, line);
396
+ // A folded subgraph keeps the colours of an open one, so it still reads as a group.
397
+ const folded = node.shape === 'collapsedGroup';
398
+ const nodeFill = hexColor(node.fill, folded ? SUBGRAPH_FILL : fill);
399
+ const nodeLine = hexColor(node.stroke, folded ? SUBGRAPH_LINE : line);
435
400
  const nodeText = node.textColor === undefined ? undefined : hexColor(node.textColor, textColorFor(nodeFill));
436
401
  parts.push(renderNode(nodeIds.get(node.id), node.id, node.label, node.labelRuns, node.shape, box, nodeFill, nodeLine, scale, nodeText));
437
402
  }
403
+ // Connectors attach to an actor's figure, not to the wider box that also holds its label.
404
+ const actorIds = new Set(flowchart.nodes.filter((n) => n.shape === 'actor').map((n) => n.id));
405
+ // One object per node (cached): a self-loop is recognised by its two ends being the same Box object.
406
+ const attachBoxes = new Map();
407
+ // An end that is no node is a subgraph (`A --> S`): the connector stops at its container's border.
408
+ const attachBox = (id) => {
409
+ const box = layout.nodes[id];
410
+ if (!box)
411
+ return layout.subgraphs[id];
412
+ if (!actorIds.has(id))
413
+ return box;
414
+ let attach = attachBoxes.get(id);
415
+ if (!attach) {
416
+ attach = actorConnectBox(box);
417
+ attachBoxes.set(id, attach);
418
+ }
419
+ return attach;
420
+ };
438
421
  flowchart.edges.forEach((edge, i) => {
439
- const from = layout.nodes[edge.from];
440
- const to = layout.nodes[edge.to];
422
+ const from = attachBox(edge.from);
423
+ const to = attachBox(edge.to);
441
424
  if (!from || !to)
442
425
  return;
443
- const fromId = nodeIds.get(edge.from);
444
- const toId = nodeIds.get(edge.to);
426
+ const fromId = nodeIds.get(edge.from) ?? containerIds.get(edge.from);
427
+ const toId = nodeIds.get(edge.to) ?? containerIds.get(edge.to);
445
428
  if (fromId === undefined || toId === undefined)
446
429
  return;
447
430
  const dagrePoints = layout.edges[i] ?? [];
@@ -477,7 +460,7 @@ function renderContent(flowchart, layout, fill, line, nextId, scale) {
477
460
  * `wpg`/`wps`/`pic`/`r` namespaces those children need are declared here,
478
461
  * on the canvas, instead of on a root group element that no longer exists.
479
462
  */
480
- function wrapInParagraph(content, bb, docPrId, maxExtent = { cx: MAX_DRAWING_CX, cy: MAX_DRAWING_CY }) {
463
+ function wrapInParagraph(content, bb, docPrId, maxExtent = { cx: DEFAULT_MAX_DRAWING_CX, cy: DEFAULT_MAX_DRAWING_CY }) {
481
464
  const { cx, cy } = scaledExtent(bb, maxExtent);
482
465
  return [
483
466
  `<w:p ${NS.w}>`,
@@ -503,22 +486,9 @@ function wrapInParagraph(content, bb, docPrId, maxExtent = { cx: MAX_DRAWING_CX,
503
486
  '</w:p>',
504
487
  ].join('\n');
505
488
  }
506
- /**
507
- * The native (unscaled) EMU size of the drawing frame, widened past the
508
- * content's actual width when needed to stay clear of the LibreOffice
509
- * narrow-tall rendering failure (see {@link MIN_SAFE_ASPECT_RATIO}). The
510
- * padding is inert canvas margin to the right of the content — it does not
511
- * move or resize any node, subgraph, or edge, it only makes the frame's own
512
- * declared bounding box wide enough to render at all. `wp:extent`
513
- * (via {@link scaledExtent}) derives from this same padded value.
514
- */
489
+ /** The native (unscaled) EMU size of the drawing frame: the content's bounding box, never empty. */
515
490
  function nativeExtent(bb) {
516
- const nativeCx = Math.max(1, Math.round(bb.width * EMU_PER_PX));
517
- const nativeCy = Math.max(1, Math.round(bb.height * EMU_PER_PX));
518
- if (nativeCy > TALL_RATIO_RISK_HEIGHT && nativeCx / nativeCy < MIN_SAFE_ASPECT_RATIO) {
519
- return { cx: Math.round(nativeCy * MIN_SAFE_ASPECT_RATIO), cy: nativeCy };
520
- }
521
- return { cx: nativeCx, cy: nativeCy };
491
+ return { cx: Math.max(1, Math.round(bb.width * EMU_PER_PX)), cy: Math.max(1, Math.round(bb.height * EMU_PER_PX)) };
522
492
  }
523
493
  /**
524
494
  * Convert a pixel bounding box to the EMU extent of the drawing frame, scaled
@@ -526,7 +496,7 @@ function nativeExtent(bb) {
526
496
  * factor so the group's `a:ext` can shrink in step with `wp:extent` while its
527
497
  * `a:chExt` stays in native coordinates.
528
498
  */
529
- function scaledExtent(bb, maxExtent = { cx: MAX_DRAWING_CX, cy: MAX_DRAWING_CY }) {
499
+ function scaledExtent(bb, maxExtent = { cx: DEFAULT_MAX_DRAWING_CX, cy: DEFAULT_MAX_DRAWING_CY }) {
530
500
  const { cx: nativeCx, cy: nativeCy } = nativeExtent(bb);
531
501
  const scale = Math.min(1, maxExtent.cx / nativeCx, maxExtent.cy / nativeCy);
532
502
  return {
@@ -555,7 +525,7 @@ function scaledExtent(bb, maxExtent = { cx: MAX_DRAWING_CX, cy: MAX_DRAWING_CY }
555
525
  * `wps:wsp` at the equivalent absolute coordinates lands correctly. A flat
556
526
  * shape sidesteps the whole question, and needs no group logic at all.
557
527
  */
558
- function renderSubgraph(sg, flowchart, layout, rendered, nextId, scale) {
528
+ function renderSubgraph(sg, flowchart, layout, rendered, nextId, scale, containerIds) {
559
529
  if (rendered.has(sg.id))
560
530
  return '';
561
531
  rendered.add(sg.id);
@@ -579,8 +549,11 @@ function renderSubgraph(sg, flowchart, layout, rendered, nextId, scale) {
579
549
  // default subgraph border style. Rendered first (behind, per emission
580
550
  // order = z-order in this format) so it never occludes member nodes/edges,
581
551
  // which are drawn later in `renderContent`.
552
+ // Its shape id is kept: a link to the subgraph (`A --> S`) attaches its connector to this box.
553
+ const containerId = nextId();
554
+ containerIds.set(sg.id, containerId);
582
555
  parts.push(' <wps:wsp>');
583
- parts.push(` <wps:cNvPr id="${nextId()}" name="${safeTitle} (container)"/>`);
556
+ parts.push(` <wps:cNvPr id="${containerId}" name="${safeTitle} (container)"/>`);
584
557
  parts.push(' <wps:cNvSpPr/>');
585
558
  parts.push(' <wps:spPr>');
586
559
  parts.push(' <a:xfrm>');
@@ -623,10 +596,55 @@ function renderSubgraph(sg, flowchart, layout, rendered, nextId, scale) {
623
596
  for (const childId of sg.subgraphIds) {
624
597
  const child = flowchart.subgraphs.find((s) => s.id === childId);
625
598
  if (child)
626
- parts.push(renderSubgraph(child, flowchart, layout, rendered, nextId, scale));
599
+ parts.push(renderSubgraph(child, flowchart, layout, rendered, nextId, scale, containerIds));
627
600
  }
628
601
  return parts.join('\n');
629
602
  }
603
+ /**
604
+ * The `a:custGeom` of an `actor` node (UML stick figure): the head is filled, body, arms and legs are open
605
+ * strokes, the text area is the part of the box below the figure, and the four connection sites are the
606
+ * box's edge midpoints (same order as the presets: top, left, bottom, right). Coordinates are absolute EMU
607
+ * for the box as generated; resizing the shape in Word stretches the figure like any custom shape.
608
+ */
609
+ function actorGeometryXml(w, h) {
610
+ const f = actorFigure(w, h);
611
+ const n = (v) => Math.round(v);
612
+ const { cx, cy, r } = f.head;
613
+ const strokes = f.strokes
614
+ .map((points) => {
615
+ const [first, ...rest] = points;
616
+ return [
617
+ ` <a:moveTo><a:pt x="${n(first.x)}" y="${n(first.y)}"/></a:moveTo>`,
618
+ ...rest.map((p) => ` <a:lnTo><a:pt x="${n(p.x)}" y="${n(p.y)}"/></a:lnTo>`),
619
+ ].join('\n');
620
+ })
621
+ .join('\n');
622
+ const angles = ['16200000', '10800000', '5400000', '0'];
623
+ // Sites and text area are ratios of the shape's own size (`*/ w x W`), not absolute EMU: LibreOffice reads
624
+ // absolute values in a 21600-unit space, which hid the label and sent glued connectors to the wrong point.
625
+ const sites = f.sites.map((p, i) => `<a:gd name="cx${i}" fmla="*/ w ${n(p.x)} ${w}"/><a:gd name="cy${i}" fmla="*/ h ${n(p.y)} ${h}"/>`).join('');
626
+ return [
627
+ ' <a:custGeom>',
628
+ ' <a:avLst/>',
629
+ ` <a:gdLst><a:gd name="textTop" fmla="*/ h ${n(f.textTop)} ${h}"/>${sites}</a:gdLst>`,
630
+ ' <a:ahLst/>',
631
+ ' <a:cxnLst>',
632
+ ...f.sites.map((_, i) => ` <a:cxn ang="${angles[i]}"><a:pos x="cx${i}" y="cy${i}"/></a:cxn>`),
633
+ ' </a:cxnLst>',
634
+ ' <a:rect l="l" t="textTop" r="r" b="b"/>',
635
+ ' <a:pathLst>',
636
+ ` <a:path w="${w}" h="${h}">`,
637
+ ` <a:moveTo><a:pt x="${n(cx - r)}" y="${n(cy)}"/></a:moveTo>`,
638
+ ` <a:arcTo wR="${n(r)}" hR="${n(r)}" stAng="10800000" swAng="21600000"/>`,
639
+ ' <a:close/>',
640
+ ' </a:path>',
641
+ ` <a:path w="${w}" h="${h}" fill="none">`,
642
+ strokes,
643
+ ' </a:path>',
644
+ ' </a:pathLst>',
645
+ ' </a:custGeom>',
646
+ ].join('\n');
647
+ }
630
648
  /**
631
649
  * Render a single node as a `wps:wsp` (wordprocessing shape).
632
650
  *
@@ -648,7 +666,9 @@ function renderNode(id, mermaidId, label, labelRuns, shape, box, fill, line, sca
648
666
  const flipAttr = flip === 'flipH' ? ' flipH="1"' : flip === 'flipV' ? ' flipV="1"' : '';
649
667
  const safeLabel = escapeXml(label);
650
668
  const safeMermaidId = escapeXml(mermaidId);
651
- const textColor = textColorOverride ?? textColorFor(fill);
669
+ // An actor's label sits below the figure, on the page: dark text whatever the figure's fill.
670
+ const textColor = textColorOverride ?? (shape === 'actor' ? '000000' : textColorFor(fill));
671
+ const geometry = shape === 'actor' ? actorGeometryXml(w, h) : ` <a:prstGeom prst="${prst}"><a:avLst/></a:prstGeom>`;
652
672
  return [
653
673
  ' <wps:wsp>',
654
674
  ` <wps:cNvPr id="${id}" name="${safeLabel}" descr="${safeMermaidId}"/>`,
@@ -658,9 +678,7 @@ function renderNode(id, mermaidId, label, labelRuns, shape, box, fill, line, sca
658
678
  ` <a:off x="${x}" y="${y}"/>`,
659
679
  ` <a:ext cx="${w}" cy="${h}"/>`,
660
680
  ' </a:xfrm>',
661
- ` <a:prstGeom prst="${prst}">`,
662
- ' <a:avLst/>',
663
- ' </a:prstGeom>',
681
+ geometry,
664
682
  ` <a:solidFill><a:srgbClr val="${fill}"/></a:solidFill>`,
665
683
  ` <a:ln w="${scaledLineWidth(12700, scale)}" cap="flat" cmpd="sng" algn="ctr">`,
666
684
  ` <a:solidFill><a:srgbClr val="${line}"/></a:solidFill>`,
@@ -688,38 +706,6 @@ function renderNode(id, mermaidId, label, labelRuns, shape, box, fill, line, sca
688
706
  ' </wps:wsp>',
689
707
  ].join('\n');
690
708
  }
691
- /**
692
- * Render a label's rich-text body (`types.ts`'s `LabelToken[]` — bold/italic
693
- * runs and `<br/>` line breaks, spec follow-up "rich-text runs") as the
694
- * `w:r`/`w:br` children of one `w:p`, shared by {@link renderNode} and
695
- * {@link renderEdgeLabel} (identical shape, only color/size differ). A break
696
- * token is its own run holding a bare `w:br` — WordprocessingML requires the
697
- * break element inside a run, but that run carries no `w:rPr`/`w:t` of its
698
- * own — so a `<br/>` moves to a new line within this same paragraph instead
699
- * of starting a new (differently-spaced) paragraph.
700
- */
701
- function renderLabelRuns(tokens, color, sizeHalfPt) {
702
- return tokens
703
- .map((token) => {
704
- if ('break' in token) {
705
- return [' <w:r>', ' <w:br/>', ' </w:r>'].join('\n');
706
- }
707
- // CT_RPr is an ordered sequence (ECMA-376 §17.3.2.28): b, i, color, sz.
708
- const rPr = [];
709
- if (token.bold)
710
- rPr.push('<w:b/>');
711
- if (token.italic)
712
- rPr.push('<w:i/>');
713
- rPr.push(`<w:color w:val="${color}"/>`, `<w:sz w:val="${sizeHalfPt}"/>`);
714
- return [
715
- ' <w:r>',
716
- ` <w:rPr>${rPr.join('')}</w:rPr>`,
717
- ` <w:t xml:space="preserve">${escapeXml(token.text)}</w:t>`,
718
- ' </w:r>',
719
- ].join('\n');
720
- })
721
- .join('\n');
722
- }
723
709
  /**
724
710
  * The `wps:style` element Word emits for a connector, referencing the document
725
711
  * theme. Unlike a shape, a connector has no fill (`fillRef idx="0"`) and uses
@@ -760,8 +746,10 @@ function connectorStyle() {
760
746
  * `straightConnectorGeometry`) is a literal point list computed by
761
747
  * `sitePoint()` below, unaffected by this constant and geometrically correct
762
748
  * either way. That's why the old (wrong) mapping never produced a visibly
763
- * broken connector in LibreOffice — LibreOffice draws the literal path we
764
- * provide — but did in a real Word, which appears to prefer its own
749
+ * broken connector in LibreOffice — LibreOffice drew the literal path we
750
+ * provided (no longer so for a routed connector: LibreOffice 26.8 redraws it
751
+ * between its two sites itself, free-form path or elbow alike, measured
752
+ * 2026-11-24) — but did in a real Word, which appears to prefer its own
765
753
  * connection-site semantics over the static geometry for at least some
766
754
  * shapes/paths. Not independently re-verified against a real Word document
767
755
  * with a horizontal connector (`tools/word-reference/` only has the vertical
@@ -889,11 +877,22 @@ function connectorGeometry(from, to, dagrePoints, otherBoxes) {
889
877
  const start = sitePoint(from, stSide);
890
878
  const end = sitePoint(to, endSide);
891
879
  const rawWaypoints = dagrePoints.length > 2 ? dagrePoints.slice(1, -1) : [];
892
- const needsRouting = rawWaypoints.length > 0 &&
893
- otherBoxes.some((box) => segmentIntersectsBox(start.x, start.y, end.x, end.y, box));
894
- const waypoints = needsRouting ? rawWaypoints : [];
895
- return { stSide, endSide, points: [start, ...waypoints, end] };
880
+ const clear = (a, b) => !otherBoxes.some((box) => segmentIntersectsBox(a.x, a.y, b.x, b.y, box));
881
+ if (rawWaypoints.length === 0 || clear(start, end))
882
+ return { stSide, endSide, points: [start, end] };
883
+ const exit = EXIT_BY_SITE[stSide];
884
+ const elbow = elbowRoute(start, end, exit, rawWaypoints, clear);
885
+ if (elbow)
886
+ return { stSide, endSide, points: elbow, elbowExit: exit };
887
+ return { stSide, endSide, points: [start, ...rawWaypoints, end] };
896
888
  }
889
+ /** The direction a connector leaves a box from each connection site. */
890
+ const EXIT_BY_SITE = {
891
+ [SITE.top]: { x: 0, y: -1 },
892
+ [SITE.right]: { x: 1, y: 0 },
893
+ [SITE.bottom]: { x: 0, y: 1 },
894
+ [SITE.left]: { x: -1, y: 0 },
895
+ };
897
896
  /**
898
897
  * The point at a given fraction (0..1) of the way along a polyline's total
899
898
  * length — used to place an edge label on a bent connector's actual path
@@ -947,16 +946,12 @@ function straightConnectorGeometry(startX, startY, endX, endY) {
947
946
  }
948
947
  /**
949
948
  * The `a:custGeom`/`a:xfrm` for a connector Dagre routed around an
950
- * intermediate rank's nodes (spec §9 "0 croisement de flèches") — an explicit
951
- * `moveTo`/`lnTo*` path through every waypoint, rather than one of Word's
952
- * built-in `bentConnectorN`/`curvedConnectorN` presets: those are parametrized
953
- * by a handful of `adj` guide values with no documented public formula for
954
- * "here are N arbitrary points, produce the adj values that trace them", so
955
- * reproducing Dagre's routing through them would mean reverse-engineering
956
- * Word's own connector-routing heuristic. A custom path draws exactly the
957
- * route Dagre already computed, no guessing involved. `wps:cNvCnPr` still
958
- * carries `stCxn`/`endCxn` for the magnetic-attachment behaviour (spec §6.2)
959
- * — that comes from being declared a connection shape, not from the geometry.
949
+ * intermediate rank's nodes (spec §9 "0 croisement de flèches") when no
950
+ * squared-off elbow ({@link elbowRoute}) stays clear of the nodes: an explicit
951
+ * `moveTo`/`lnTo*` path through every waypoint. It is the fallback because
952
+ * Word loads a connector with a custom geometry as a free-form shape and drops
953
+ * its `stCxn`/`endCxn` (measured on Word 16.0.20625 by the agent benchmark),
954
+ * so the line no longer follows its nodes; the elbow keeps that attachment.
960
955
  *
961
956
  * The path's own coordinate space is set to exactly the shape's EMU extent
962
957
  * (`w`/`h` on `a:path` equal to `a:ext`'s `cx`/`cy`), so every path point can
@@ -995,7 +990,9 @@ function bentConnectorGeometry(points) {
995
990
  * Render an edge as a `wps:wsp` connector (with `wps:cNvCnPr`), following the
996
991
  * route Dagre computed (`dagrePoints`, from `LayoutResult.edges`) when the
997
992
  * straight line between the two connection sites would actually cross
998
- * another node — see {@link connectorGeometry}.
993
+ * another node — see {@link connectorGeometry}: squared off as Word's own
994
+ * elbow connector when that stays clear ({@link elbowConnectorGeometry}),
995
+ * Dagre's polyline otherwise ({@link bentConnectorGeometry}).
999
996
  *
1000
997
  * `cNvPr/name` is set to `"{mermaidFromId}--{mermaidToId}"` rather than a
1001
998
  * generic label (spec follow-up, `docs/specs/FUTURE_docx2mermaid_SPEC.md` §4) — no
@@ -1028,14 +1025,17 @@ function renderEdge(fromId, toId, mermaidFromId, mermaidToId, type, from, to, da
1028
1025
  // converted, not pre-scaled here since `scaledLineWidth` below applies the
1029
1026
  // diagram's overall `scale` uniformly to whichever width wins.
1030
1027
  const baseWidthEmu = strokeWidthPx !== undefined ? Math.max(1, Math.round(strokeWidthPx * EMU_PER_PX)) : lineStyle.width;
1031
- const { stSide, endSide, points } = connectorGeometry(from, to, dagrePoints, otherBoxes);
1028
+ const { stSide, endSide, points, elbowExit } = connectorGeometry(from, to, dagrePoints, otherBoxes);
1032
1029
  const emuPoints = points.map((p) => ({
1033
1030
  x: Math.round(p.x * EMU_PER_PX * scale),
1034
1031
  y: Math.round(p.y * EMU_PER_PX * scale),
1035
1032
  }));
1033
+ // Rounding each coordinate the same way keeps an elbow route's segments axis-aligned in EMU.
1036
1034
  const geometry = emuPoints.length === 2
1037
1035
  ? straightConnectorGeometry(emuPoints[0].x, emuPoints[0].y, emuPoints[1].x, emuPoints[1].y)
1038
- : bentConnectorGeometry(emuPoints);
1036
+ : elbowExit
1037
+ ? elbowConnectorGeometry(emuPoints, elbowExit)
1038
+ : bentConnectorGeometry(emuPoints);
1039
1039
  const markerSize = arrowMarkerSize(baseWidthEmu, scale);
1040
1040
  const headEnd = lineStyle.headEnd !== 'none'
1041
1041
  ? ` <a:headEnd type="${lineStyle.headEnd}" w="${markerSize}" len="${markerSize}"/>`
@@ -1053,7 +1053,7 @@ function renderEdge(fromId, toId, mermaidFromId, mermaidToId, type, from, to, da
1053
1053
  ` <a:endCxn id="${toId}" idx="${endSide}"/>`,
1054
1054
  ' </wps:cNvCnPr>',
1055
1055
  ].join('\n');
1056
- return [
1056
+ const connectorXml = [
1057
1057
  ' <wps:wsp>',
1058
1058
  ` <wps:cNvPr id="${nextId()}" name="${safeName}"/>`,
1059
1059
  connectionProps,
@@ -1073,6 +1073,16 @@ function renderEdge(fromId, toId, mermaidFromId, mermaidToId, type, from, to, da
1073
1073
  ' <wps:bodyPr/>',
1074
1074
  ' </wps:wsp>',
1075
1075
  ].join('\n');
1076
+ if (type !== 'generalization' && type !== 'realization')
1077
+ return connectorXml;
1078
+ // UML's open triangle at the target: a line end is always filled, so it is its own white polygon over the end
1079
+ // of the line (the connector stays attached to its two shapes; the triangle does not follow if one is moved).
1080
+ const tip = emuPoints[emuPoints.length - 1];
1081
+ const before = emuPoints[emuPoints.length - 2] ?? tip;
1082
+ const size = HOLLOW_SIZE_PX.triangle;
1083
+ const unit = EMU_PER_PX * scale;
1084
+ const triangle = hollowMarker(nextId(), 'triangle', tip, before, Math.round(size.length * unit), Math.round(size.width * unit), line, scaledLineWidth(baseWidthEmu, scale));
1085
+ return `${connectorXml}\n${triangle}`;
1076
1086
  }
1077
1087
  /**
1078
1088
  * An edge label's box size in EMU. The size itself (sized to the label's own
@@ -1126,7 +1136,10 @@ function renderEdgeLabel(labelRuns, from, to, dagrePoints, otherBoxes, id, scale
1126
1136
  ' </w:p>',
1127
1137
  ' </w:txbxContent>',
1128
1138
  ' </wps:txbx>',
1129
- ` <wps:bodyPr rot="0" vert="horz" wrap="none" lIns="${insetEmu}" tIns="0" rIns="${insetEmu}" bIns="0"`,
1139
+ // `wrap="square"`, never `"none"`: real Word shrinks a `wrap="none"` box to its text with the left edge
1140
+ // fixed, which shifted every label left of its edge (see `unwrappedTextFrame` in `canvas.ts`). The box
1141
+ // is already sized to its text with a safety margin (`edgeLabelSize`), so the text does not wrap.
1142
+ ` <wps:bodyPr rot="0" vert="horz" wrap="square" lIns="${insetEmu}" tIns="0" rIns="${insetEmu}" bIns="0"`,
1130
1143
  ' anchor="ctr" anchorCtr="1"><a:noAutofit/></wps:bodyPr>',
1131
1144
  ' </wps:wsp>',
1132
1145
  ].join('\n');