@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.
- package/dist/diagrams/agentflow/parser.d.ts +20 -0
- package/dist/diagrams/agentflow/parser.js +155 -0
- package/dist/diagrams/agentflow/parser.js.map +1 -0
- package/dist/diagrams/architecture-diagram/icons.d.ts +24 -0
- package/dist/diagrams/architecture-diagram/icons.js +148 -0
- package/dist/diagrams/architecture-diagram/icons.js.map +1 -0
- package/dist/diagrams/architecture-diagram/layout.d.ts +71 -0
- package/dist/diagrams/architecture-diagram/layout.js +388 -0
- package/dist/diagrams/architecture-diagram/layout.js.map +1 -0
- package/dist/diagrams/architecture-diagram/parser.d.ts +14 -19
- package/dist/diagrams/architecture-diagram/parser.js +316 -113
- package/dist/diagrams/architecture-diagram/parser.js.map +1 -1
- package/dist/diagrams/architecture-diagram/translator.d.ts +26 -36
- package/dist/diagrams/architecture-diagram/translator.js +234 -147
- package/dist/diagrams/architecture-diagram/translator.js.map +1 -1
- package/dist/diagrams/architecture-diagram/types.d.ts +26 -16
- package/dist/diagrams/architecture-diagram/types.js +4 -14
- package/dist/diagrams/architecture-diagram/types.js.map +1 -1
- package/dist/diagrams/c4/parser.d.ts +11 -19
- package/dist/diagrams/c4/parser.js +242 -90
- package/dist/diagrams/c4/parser.js.map +1 -1
- package/dist/diagrams/c4/translator.d.ts +23 -43
- package/dist/diagrams/c4/translator.js +333 -204
- package/dist/diagrams/c4/translator.js.map +1 -1
- package/dist/diagrams/c4/types.d.ts +78 -45
- package/dist/diagrams/c4/types.js +17 -38
- package/dist/diagrams/c4/types.js.map +1 -1
- package/dist/diagrams/class-diagram/parser.d.ts +10 -11
- package/dist/diagrams/class-diagram/parser.js +322 -74
- package/dist/diagrams/class-diagram/parser.js.map +1 -1
- package/dist/diagrams/class-diagram/translator.d.ts +10 -10
- package/dist/diagrams/class-diagram/translator.js +305 -33
- package/dist/diagrams/class-diagram/translator.js.map +1 -1
- package/dist/diagrams/class-diagram/types.d.ts +61 -4
- package/dist/diagrams/er-diagram/parser.d.ts +22 -19
- package/dist/diagrams/er-diagram/parser.js +412 -89
- package/dist/diagrams/er-diagram/parser.js.map +1 -1
- package/dist/diagrams/er-diagram/translator.d.ts +8 -0
- package/dist/diagrams/er-diagram/translator.js +170 -38
- package/dist/diagrams/er-diagram/translator.js.map +1 -1
- package/dist/diagrams/er-diagram/types.d.ts +32 -5
- package/dist/diagrams/er-diagram/types.js +2 -5
- package/dist/diagrams/er-diagram/types.js.map +1 -1
- package/dist/diagrams/flowchart-source.d.ts +106 -0
- package/dist/diagrams/flowchart-source.js +272 -0
- package/dist/diagrams/flowchart-source.js.map +1 -0
- package/dist/diagrams/gantt/date-utils.d.ts +55 -33
- package/dist/diagrams/gantt/date-utils.js +147 -58
- package/dist/diagrams/gantt/date-utils.js.map +1 -1
- package/dist/diagrams/gantt/parser.d.ts +31 -22
- package/dist/diagrams/gantt/parser.js +259 -141
- package/dist/diagrams/gantt/parser.js.map +1 -1
- package/dist/diagrams/gantt/time-axis.d.ts +44 -0
- package/dist/diagrams/gantt/time-axis.js +158 -0
- package/dist/diagrams/gantt/time-axis.js.map +1 -0
- package/dist/diagrams/gantt/translator.d.ts +8 -5
- package/dist/diagrams/gantt/translator.js +72 -60
- package/dist/diagrams/gantt/translator.js.map +1 -1
- package/dist/diagrams/gantt/types.d.ts +25 -4
- package/dist/diagrams/gantt/types.js +4 -3
- package/dist/diagrams/gantt/types.js.map +1 -1
- package/dist/diagrams/mindmap/parser.d.ts +18 -14
- package/dist/diagrams/mindmap/parser.js +169 -69
- package/dist/diagrams/mindmap/parser.js.map +1 -1
- package/dist/diagrams/mindmap/translator.js +90 -35
- package/dist/diagrams/mindmap/translator.js.map +1 -1
- package/dist/diagrams/mindmap/types.d.ts +18 -0
- package/dist/diagrams/packet/parser.js +1 -1
- package/dist/diagrams/packet/parser.js.map +1 -1
- package/dist/diagrams/pie/translator.js +5 -4
- package/dist/diagrams/pie/translator.js.map +1 -1
- package/dist/diagrams/plantuml/class-parser.d.ts +2 -1
- package/dist/diagrams/plantuml/class-parser.js +19 -11
- package/dist/diagrams/plantuml/class-parser.js.map +1 -1
- package/dist/diagrams/plantuml/sequence-parser.d.ts +3 -2
- package/dist/diagrams/plantuml/sequence-parser.js +28 -12
- package/dist/diagrams/plantuml/sequence-parser.js.map +1 -1
- package/dist/diagrams/plantuml/state-parser.d.ts +5 -3
- package/dist/diagrams/plantuml/state-parser.js +141 -19
- package/dist/diagrams/plantuml/state-parser.js.map +1 -1
- package/dist/diagrams/quadrant/translator.js +5 -4
- package/dist/diagrams/quadrant/translator.js.map +1 -1
- package/dist/diagrams/railroad/layout.d.ts +89 -0
- package/dist/diagrams/railroad/layout.js +235 -0
- package/dist/diagrams/railroad/layout.js.map +1 -0
- package/dist/diagrams/railroad/parser.d.ts +37 -0
- package/dist/diagrams/railroad/parser.js +605 -0
- package/dist/diagrams/railroad/parser.js.map +1 -0
- package/dist/diagrams/railroad/translator.d.ts +11 -0
- package/dist/diagrams/railroad/translator.js +101 -0
- package/dist/diagrams/railroad/translator.js.map +1 -0
- package/dist/diagrams/railroad/types.d.ts +61 -0
- package/dist/diagrams/railroad/types.js +7 -0
- package/dist/diagrams/railroad/types.js.map +1 -0
- package/dist/diagrams/requirement-diagram/parser.d.ts +26 -19
- package/dist/diagrams/requirement-diagram/parser.js +249 -70
- package/dist/diagrams/requirement-diagram/parser.js.map +1 -1
- package/dist/diagrams/requirement-diagram/translator.d.ts +16 -11
- package/dist/diagrams/requirement-diagram/translator.js +170 -50
- package/dist/diagrams/requirement-diagram/translator.js.map +1 -1
- package/dist/diagrams/requirement-diagram/types.d.ts +30 -9
- package/dist/diagrams/requirement-diagram/types.js +7 -5
- package/dist/diagrams/requirement-diagram/types.js.map +1 -1
- package/dist/diagrams/sequence/parser.d.ts +8 -7
- package/dist/diagrams/sequence/parser.js +129 -32
- package/dist/diagrams/sequence/parser.js.map +1 -1
- package/dist/diagrams/sequence/participant-glyph.d.ts +38 -0
- package/dist/diagrams/sequence/participant-glyph.js +97 -0
- package/dist/diagrams/sequence/participant-glyph.js.map +1 -0
- package/dist/diagrams/sequence/participant-kind.d.ts +7 -0
- package/dist/diagrams/sequence/participant-kind.js +19 -0
- package/dist/diagrams/sequence/participant-kind.js.map +1 -0
- package/dist/diagrams/sequence/translator.d.ts +7 -3
- package/dist/diagrams/sequence/translator.js +140 -28
- package/dist/diagrams/sequence/translator.js.map +1 -1
- package/dist/diagrams/sequence/types.d.ts +24 -1
- package/dist/diagrams/state-diagram/parser.d.ts +24 -24
- package/dist/diagrams/state-diagram/parser.js +259 -73
- package/dist/diagrams/state-diagram/parser.js.map +1 -1
- package/dist/diagrams/state-diagram/translator.d.ts +13 -1
- package/dist/diagrams/state-diagram/translator.js +554 -72
- package/dist/diagrams/state-diagram/translator.js.map +1 -1
- package/dist/diagrams/state-diagram/types.d.ts +57 -11
- package/dist/diagrams/state-diagram/types.js +5 -7
- package/dist/diagrams/state-diagram/types.js.map +1 -1
- package/dist/diagrams/tree-view/implicit-root.d.ts +11 -0
- package/dist/diagrams/tree-view/implicit-root.js +14 -0
- package/dist/diagrams/tree-view/implicit-root.js.map +1 -0
- package/dist/diagrams/tree-view/parser.d.ts +23 -8
- package/dist/diagrams/tree-view/parser.js +242 -98
- package/dist/diagrams/tree-view/parser.js.map +1 -1
- package/dist/diagrams/tree-view/translator.d.ts +6 -5
- package/dist/diagrams/tree-view/translator.js +40 -23
- package/dist/diagrams/tree-view/translator.js.map +1 -1
- package/dist/diagrams/tree-view/types.d.ts +22 -6
- package/dist/diagrams/tree-view/types.js +2 -2
- package/dist/diagrams/treemap/parser.d.ts +2 -2
- package/dist/diagrams/treemap/parser.js +5 -12
- package/dist/diagrams/treemap/parser.js.map +1 -1
- package/dist/diagrams/usecase/parser.d.ts +24 -0
- package/dist/diagrams/usecase/parser.js +232 -0
- package/dist/diagrams/usecase/parser.js.map +1 -0
- package/dist/diagrams/venn/translator.js +5 -4
- package/dist/diagrams/venn/translator.js.map +1 -1
- package/dist/diagrams/zenuml/parser.d.ts +2 -2
- package/dist/diagrams/zenuml/parser.js +14 -7
- package/dist/diagrams/zenuml/parser.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/layout/collapse-subgraphs.d.ts +18 -0
- package/dist/layout/collapse-subgraphs.js +80 -0
- package/dist/layout/collapse-subgraphs.js.map +1 -0
- package/dist/layout/layout.d.ts +11 -0
- package/dist/layout/layout.js +89 -17
- package/dist/layout/layout.js.map +1 -1
- package/dist/parser/css-named-colors.d.ts +7 -0
- package/dist/parser/css-named-colors.js +157 -0
- package/dist/parser/css-named-colors.js.map +1 -0
- package/dist/parser/css-style.d.ts +39 -0
- package/dist/parser/css-style.js +88 -0
- package/dist/parser/css-style.js.map +1 -0
- package/dist/parser/diagram-type.d.ts +12 -1
- package/dist/parser/diagram-type.js +4 -0
- package/dist/parser/diagram-type.js.map +1 -1
- package/dist/parser/entities.d.ts +5 -0
- package/dist/parser/entities.js +52 -0
- package/dist/parser/entities.js.map +1 -0
- package/dist/parser/frontmatter.d.ts +36 -0
- package/dist/parser/frontmatter.js +66 -0
- package/dist/parser/frontmatter.js.map +1 -0
- package/dist/parser/interactive.d.ts +13 -0
- package/dist/parser/interactive.js +17 -0
- package/dist/parser/interactive.js.map +1 -0
- package/dist/parser/label.d.ts +37 -0
- package/dist/parser/label.js +73 -0
- package/dist/parser/label.js.map +1 -0
- package/dist/parser/normalize-statements.d.ts +8 -0
- package/dist/parser/normalize-statements.js +17 -2
- package/dist/parser/normalize-statements.js.map +1 -1
- package/dist/parser/parser.d.ts +2 -1
- package/dist/parser/parser.js +345 -324
- package/dist/parser/parser.js.map +1 -1
- package/dist/render-diagram-odf.d.ts +2 -1
- package/dist/render-diagram-odf.js +39 -8
- package/dist/render-diagram-odf.js.map +1 -1
- package/dist/render-diagram.d.ts +11 -3
- package/dist/render-diagram.js +66 -23
- package/dist/render-diagram.js.map +1 -1
- package/dist/smartart/chain.js +1 -1
- package/dist/smartart/chain.js.map +1 -1
- package/dist/smartart/cycle.js +1 -1
- package/dist/smartart/cycle.js.map +1 -1
- package/dist/smartart/drawing.js +2 -10
- package/dist/smartart/drawing.js.map +1 -1
- package/dist/smartart/embed.d.ts +4 -3
- package/dist/smartart/embed.js +5 -4
- package/dist/smartart/embed.js.map +1 -1
- package/dist/smartart/from-graph.d.ts +13 -3
- package/dist/smartart/from-graph.js +39 -7
- package/dist/smartart/from-graph.js.map +1 -1
- package/dist/smartart/from-tree.d.ts +9 -5
- package/dist/smartart/from-tree.js +23 -11
- package/dist/smartart/from-tree.js.map +1 -1
- package/dist/smartart/text.d.ts +18 -4
- package/dist/smartart/text.js +32 -8
- package/dist/smartart/text.js.map +1 -1
- package/dist/smartart/tree-deep.js +1 -1
- package/dist/smartart/tree-deep.js.map +1 -1
- package/dist/smartart/tree.js +2 -2
- package/dist/smartart/tree.js.map +1 -1
- package/dist/translator/actor-figure.d.ts +45 -0
- package/dist/translator/actor-figure.js +46 -0
- package/dist/translator/actor-figure.js.map +1 -0
- package/dist/translator/boxes.d.ts +12 -1
- package/dist/translator/boxes.js +11 -6
- package/dist/translator/boxes.js.map +1 -1
- package/dist/translator/canvas.d.ts +28 -1
- package/dist/translator/canvas.js +83 -16
- package/dist/translator/canvas.js.map +1 -1
- package/dist/translator/custom-geometry.d.ts +28 -0
- package/dist/translator/custom-geometry.js +59 -0
- package/dist/translator/custom-geometry.js.map +1 -0
- package/dist/translator/elbow-connector.d.ts +52 -0
- package/dist/translator/elbow-connector.js +110 -0
- package/dist/translator/elbow-connector.js.map +1 -0
- package/dist/translator/graph-shapes.d.ts +40 -4
- package/dist/translator/graph-shapes.js +62 -10
- package/dist/translator/graph-shapes.js.map +1 -1
- package/dist/translator/label-runs.d.ts +14 -0
- package/dist/translator/label-runs.js +36 -0
- package/dist/translator/label-runs.js.map +1 -0
- package/dist/translator/odf-translator.js +56 -24
- package/dist/translator/odf-translator.js.map +1 -1
- package/dist/translator/ooxml-translator.d.ts +17 -11
- package/dist/translator/ooxml-translator.js +159 -146
- package/dist/translator/ooxml-translator.js.map +1 -1
- package/dist/translator/text-color.d.ts +9 -0
- package/dist/translator/text-color.js +17 -0
- package/dist/translator/text-color.js.map +1 -0
- package/dist/types.d.ts +27 -4
- 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 ??
|
|
335
|
+
return { cx: options.maxDrawingCx ?? DEFAULT_MAX_DRAWING_CX, cy: options.maxDrawingCy ?? DEFAULT_MAX_DRAWING_CY };
|
|
381
336
|
}
|
|
382
337
|
/**
|
|
383
|
-
*
|
|
384
|
-
*
|
|
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
|
|
387
|
-
const
|
|
388
|
-
|
|
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
|
-
|
|
434
|
-
const
|
|
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 =
|
|
440
|
-
const 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:
|
|
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
|
-
|
|
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:
|
|
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="${
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
764
|
-
*
|
|
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
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
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")
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
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
|
-
:
|
|
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
|
-
|
|
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
|
-
`
|
|
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');
|