@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
|
@@ -63,22 +63,25 @@ const MIN_LINE_WIDTH_EMU = 3175;
|
|
|
63
63
|
export function scaledLineWidthEmu(baseEmu, scale) {
|
|
64
64
|
return Math.max(MIN_LINE_WIDTH_EMU, Math.round(baseEmu * scale));
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Height kept free above a page-tall drawing (0.75in), so a heading fits on the same page. Headings keep
|
|
68
|
+
* with the next paragraph; a drawing as tall as the text area leaves no room for one, and Word and
|
|
69
|
+
* LibreOffice then leave the heading alone at the bottom of the previous page. Measured on 2026-11-26 with
|
|
70
|
+
* the bundled reference document: a Heading 1 needs about 46pt in Word (kept at 47pt of room, orphaned at
|
|
71
|
+
* 45pt) and less in LibreOffice 26.2.7; 0.75in adds a margin for a slightly larger heading style.
|
|
72
|
+
*/
|
|
73
|
+
const HEADING_ROOM_EMU = 685800;
|
|
74
|
+
/**
|
|
75
|
+
* Default drawing area in EMU, shared by every translator (`.docx` flowcharts, the other canvas
|
|
76
|
+
* diagrams, `.odt`): the text width of a Letter portrait page with 1in margins (6.5in), and its text
|
|
77
|
+
* height (9in) minus {@link HEADING_ROOM_EMU}. A caller that knows the real page passes
|
|
78
|
+
* `maxDrawingCx`/`maxDrawingCy` instead, already leaving that room (the CLI does).
|
|
79
|
+
*/
|
|
80
|
+
export const DEFAULT_MAX_DRAWING_CX = 5943600;
|
|
81
|
+
export const DEFAULT_MAX_DRAWING_CY = 8229600 - HEADING_ROOM_EMU;
|
|
82
|
+
/** The native (unscaled) EMU size of the drawing frame, never empty. */
|
|
75
83
|
function nativeExtent(widthPx, heightPx) {
|
|
76
|
-
|
|
77
|
-
const nativeCy = Math.max(1, Math.round(heightPx * EMU_PER_PX));
|
|
78
|
-
if (nativeCy > TALL_RATIO_RISK_HEIGHT && nativeCx / nativeCy < MIN_SAFE_ASPECT_RATIO) {
|
|
79
|
-
return { cx: Math.round(nativeCy * MIN_SAFE_ASPECT_RATIO), cy: nativeCy };
|
|
80
|
-
}
|
|
81
|
-
return { cx: nativeCx, cy: nativeCy };
|
|
84
|
+
return { cx: Math.max(1, Math.round(widthPx * EMU_PER_PX)), cy: Math.max(1, Math.round(heightPx * EMU_PER_PX)) };
|
|
82
85
|
}
|
|
83
86
|
/**
|
|
84
87
|
* Pixel canvas size -> the EMU extent of the drawing frame, scaled down
|
|
@@ -89,7 +92,7 @@ function nativeExtent(widthPx, heightPx) {
|
|
|
89
92
|
*/
|
|
90
93
|
export function scaledExtent(widthPx, heightPx, options = {}) {
|
|
91
94
|
const { cx: nativeCx, cy: nativeCy } = nativeExtent(widthPx, heightPx);
|
|
92
|
-
const scale = Math.min(1, (options.maxDrawingCx ??
|
|
95
|
+
const scale = Math.min(1, (options.maxDrawingCx ?? DEFAULT_MAX_DRAWING_CX) / nativeCx, (options.maxDrawingCy ?? DEFAULT_MAX_DRAWING_CY) / nativeCy);
|
|
93
96
|
return {
|
|
94
97
|
cx: Math.max(1, Math.round(nativeCx * scale)),
|
|
95
98
|
cy: Math.max(1, Math.round(nativeCy * scale)),
|
|
@@ -108,6 +111,7 @@ export function scaledExtent(widthPx, heightPx, options = {}) {
|
|
|
108
111
|
*/
|
|
109
112
|
export function wrapDrawingCanvas(content, widthPx, heightPx, docPrId, name, options = {}) {
|
|
110
113
|
const { cx, cy } = scaledExtent(widthPx, heightPx, options);
|
|
114
|
+
content = clampLabelFrames(content, cx);
|
|
111
115
|
return [
|
|
112
116
|
`<w:p ${NS.w}>`,
|
|
113
117
|
' <w:r>',
|
|
@@ -132,4 +136,67 @@ export function wrapDrawingCanvas(content, widthPx, heightPx, docPrId, name, opt
|
|
|
132
136
|
'</w:p>',
|
|
133
137
|
].join('\n');
|
|
134
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* The frame to give a one-line, unfilled text box so it renders where it was placed, in real Word as in
|
|
141
|
+
* LibreOffice. Never use `wrap="none"` for a text box: real Word resizes such a box to the width of its
|
|
142
|
+
* text, keeping its left edge (measured 2026-11-20 with Word's own PDF export, `noAutofit`, `txBox` and
|
|
143
|
+
* `anchorCtr` changing nothing), so centred text drifts left, right-aligned text detaches from what it
|
|
144
|
+
* labels, and a filled box shrinks or grows. Instead the box keeps `wrap="square"` and is widened on the
|
|
145
|
+
* side(s) the text may run into: both sides when centred, the left when right-aligned, the right when
|
|
146
|
+
* left-aligned. The box draws nothing, so the extra width is invisible and the text never wraps.
|
|
147
|
+
*
|
|
148
|
+
* `x` and `w` are in EMU; returns the widened frame, in EMU. The shape must be named
|
|
149
|
+
* `${LABEL_NAME} <id>`: {@link wrapDrawingCanvas} then brings the frame back inside the canvas, since
|
|
150
|
+
* LibreOffice moves the whole drawing when a shape reaches past the canvas edges.
|
|
151
|
+
*/
|
|
152
|
+
export function unwrappedTextFrame(x, w, align) {
|
|
153
|
+
// Room for text up to about three times the box, and at least one inch, on each open side.
|
|
154
|
+
const extra = Math.max(w, 914400);
|
|
155
|
+
if (align === 'center')
|
|
156
|
+
return { x: x - extra, w: w + 2 * extra };
|
|
157
|
+
if (align === 'right')
|
|
158
|
+
return { x: x - extra, w: w + extra };
|
|
159
|
+
return { x, w: w + extra };
|
|
160
|
+
}
|
|
161
|
+
/** `cNvPr` name prefix of a text frame widened by {@link unwrappedTextFrame}. */
|
|
162
|
+
export const LABEL_NAME = 'Label';
|
|
163
|
+
/**
|
|
164
|
+
* Bring every widened text frame (`name="Label <id>"`) back inside a canvas `canvasCx` EMU wide, keeping
|
|
165
|
+
* what its alignment anchors: the centre for centred text, the right edge for right-aligned, the left edge
|
|
166
|
+
* for left-aligned. The frame never ends up narrower than the box it was widened from, as long as that box
|
|
167
|
+
* was inside the canvas.
|
|
168
|
+
*/
|
|
169
|
+
function clampLabelFrames(content, canvasCx) {
|
|
170
|
+
return content.replace(/<wps:wsp>(?:(?!<\/wps:wsp>)[\s\S])*?<\/wps:wsp>/g, (shape) => {
|
|
171
|
+
if (!shape.includes(`name="${LABEL_NAME} `))
|
|
172
|
+
return shape;
|
|
173
|
+
const frame = /<a:off x="(-?\d+)" y="(-?\d+)"\/><a:ext cx="(\d+)"/.exec(shape);
|
|
174
|
+
if (!frame)
|
|
175
|
+
return shape;
|
|
176
|
+
const x = Number(frame[1]);
|
|
177
|
+
const w = Number(frame[3]);
|
|
178
|
+
const jc = /<w:jc w:val="(left|center|right)"\/>/.exec(shape)?.[1] ?? 'left';
|
|
179
|
+
let nx;
|
|
180
|
+
let nw;
|
|
181
|
+
if (jc === 'center') {
|
|
182
|
+
const c = x + w / 2;
|
|
183
|
+
const half = Math.min(w / 2, c, canvasCx - c);
|
|
184
|
+
if (half <= 0)
|
|
185
|
+
return shape;
|
|
186
|
+
nx = Math.round(c - half);
|
|
187
|
+
nw = Math.round(2 * half);
|
|
188
|
+
}
|
|
189
|
+
else if (jc === 'right') {
|
|
190
|
+
nx = Math.max(0, x);
|
|
191
|
+
nw = x + w - nx;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
nx = x;
|
|
195
|
+
nw = Math.min(w, canvasCx - x);
|
|
196
|
+
}
|
|
197
|
+
if (nw < 1 || (nx === x && nw === w))
|
|
198
|
+
return shape;
|
|
199
|
+
return shape.replace(frame[0], `<a:off x="${nx}" y="${frame[2]}"/><a:ext cx="${nw}"`);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
135
202
|
//# sourceMappingURL=canvas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../src/translator/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;qCACqC;AACrC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC;AAE/B,oFAAoF;AACpF,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,GAAG,EAAE,+EAA+E;IACpF,GAAG,EAAE,+EAA+E;IACpF,EAAE,EAAE,mFAAmF;IACvF,CAAC,EAAE,iEAAiE;IACpE,GAAG,EAAE,sEAAsE;IAC3E,CAAC,EAAE,+EAA+E;IAClF,CAAC,EAAE,wEAAwE;CAC5E,CAAC;AAEF;;;sCAGsC;AACtC,MAAM,UAAU,iBAAiB;IAC/B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC;AAED;;;gBAGgB;AAChB,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAE/B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAkB,EAAE,KAAa;IACpE,OAAO,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;kDAEkD;AAClD,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC;qEACqE;AACrE,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,KAAa;IAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;
|
|
1
|
+
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../src/translator/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;q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C,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QACnD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,KAAK,CAAC,CAAC,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Building blocks for DrawingML custom geometries (`a:custGeom`): paths authored in logical px, scaled to
|
|
3
|
+
* the shape by DrawingML itself, so a symbol moves and resizes as one shape in Word and PowerPoint.
|
|
4
|
+
* Extracted from `../diagrams/sequence/participant-glyph.ts` when the C4 translator became its second
|
|
5
|
+
* consumer (person, horizontal cylinder).
|
|
6
|
+
*/
|
|
7
|
+
/** Logical px -> path units. */
|
|
8
|
+
export declare const pathUnits: (v: number) => number;
|
|
9
|
+
/** A closed circle of radius `r` centred on (`cx`, `cy`). */
|
|
10
|
+
export declare function circlePath(cx: number, cy: number, r: number): string;
|
|
11
|
+
/** A polyline through `points`, closed when `closed`. */
|
|
12
|
+
export declare function polylinePath(points: Array<[number, number]>, closed?: boolean): string;
|
|
13
|
+
/** A rectangle at (`x`, `y`), `w` x `h`, with corners of radius `r` (clamped to half the shorter side). */
|
|
14
|
+
export declare function roundedRectPath(x: number, y: number, w: number, h: number, r: number): string;
|
|
15
|
+
/**
|
|
16
|
+
* A custom geometry of `w` x `h` px whose paths are given as `[fill, path ops]`: `norm` is filled and
|
|
17
|
+
* outlined, `none` only outlined, `darken` filled with a darker shade of the fill. A third element
|
|
18
|
+
* `{ stroke: false }` leaves that path without its outline (a background under outlined strokes).
|
|
19
|
+
*/
|
|
20
|
+
export declare function customGeometry(w: number, h: number, paths: Array<['norm' | 'none' | 'darken', string] | ['norm' | 'none' | 'darken', string, {
|
|
21
|
+
stroke: false;
|
|
22
|
+
}]>): string;
|
|
23
|
+
/**
|
|
24
|
+
* A cylinder lying on its side, `w` x `h` px, its visible end on the right, end caps `cap` px wide. Drawn
|
|
25
|
+
* here rather than with Word's `flowChartMagneticDrum`, whose caps take a third of the width whatever the
|
|
26
|
+
* height.
|
|
27
|
+
*/
|
|
28
|
+
export declare function horizontalCylinderGeometry(w: number, h: number, cap: number): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Building blocks for DrawingML custom geometries (`a:custGeom`): paths authored in logical px, scaled to
|
|
3
|
+
* the shape by DrawingML itself, so a symbol moves and resizes as one shape in Word and PowerPoint.
|
|
4
|
+
* Extracted from `../diagrams/sequence/participant-glyph.ts` when the C4 translator became its second
|
|
5
|
+
* consumer (person, horizontal cylinder).
|
|
6
|
+
*/
|
|
7
|
+
/** Path units per logical px: enough resolution for arcs and fractional sizes. */
|
|
8
|
+
const UNIT = 10;
|
|
9
|
+
/** Logical px -> path units. */
|
|
10
|
+
export const pathUnits = (v) => Math.round(v * UNIT);
|
|
11
|
+
/** A closed circle of radius `r` centred on (`cx`, `cy`). */
|
|
12
|
+
export function circlePath(cx, cy, r) {
|
|
13
|
+
const u = pathUnits;
|
|
14
|
+
return `<a:moveTo><a:pt x="${u(cx - r)}" y="${u(cy)}"/></a:moveTo><a:arcTo wR="${u(r)}" hR="${u(r)}" stAng="10800000" swAng="21600000"/><a:close/>`;
|
|
15
|
+
}
|
|
16
|
+
/** A polyline through `points`, closed when `closed`. */
|
|
17
|
+
export function polylinePath(points, closed = false) {
|
|
18
|
+
const u = pathUnits;
|
|
19
|
+
return (points.map(([x, y], i) => `<a:${i === 0 ? 'moveTo' : 'lnTo'}><a:pt x="${u(x)}" y="${u(y)}"/></a:${i === 0 ? 'moveTo' : 'lnTo'}>`).join('') +
|
|
20
|
+
(closed ? '<a:close/>' : ''));
|
|
21
|
+
}
|
|
22
|
+
/** A rectangle at (`x`, `y`), `w` x `h`, with corners of radius `r` (clamped to half the shorter side). */
|
|
23
|
+
export function roundedRectPath(x, y, w, h, r) {
|
|
24
|
+
const u = pathUnits;
|
|
25
|
+
const rr = Math.max(0, Math.min(r, w / 2, h / 2));
|
|
26
|
+
const arc = (stAng) => `<a:arcTo wR="${u(rr)}" hR="${u(rr)}" stAng="${stAng}" swAng="5400000"/>`;
|
|
27
|
+
return (`<a:moveTo><a:pt x="${u(x + rr)}" y="${u(y)}"/></a:moveTo>` +
|
|
28
|
+
`<a:lnTo><a:pt x="${u(x + w - rr)}" y="${u(y)}"/></a:lnTo>${arc(16200000)}` +
|
|
29
|
+
`<a:lnTo><a:pt x="${u(x + w)}" y="${u(y + h - rr)}"/></a:lnTo>${arc(0)}` +
|
|
30
|
+
`<a:lnTo><a:pt x="${u(x + rr)}" y="${u(y + h)}"/></a:lnTo>${arc(5400000)}` +
|
|
31
|
+
`<a:lnTo><a:pt x="${u(x)}" y="${u(y + rr)}"/></a:lnTo>${arc(10800000)}<a:close/>`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A custom geometry of `w` x `h` px whose paths are given as `[fill, path ops]`: `norm` is filled and
|
|
35
|
+
* outlined, `none` only outlined, `darken` filled with a darker shade of the fill. A third element
|
|
36
|
+
* `{ stroke: false }` leaves that path without its outline (a background under outlined strokes).
|
|
37
|
+
*/
|
|
38
|
+
export function customGeometry(w, h, paths) {
|
|
39
|
+
const body = paths
|
|
40
|
+
.map(([fill, ops, opts]) => `<a:path w="${pathUnits(w)}" h="${pathUnits(h)}"${fill === 'norm' ? '' : ` fill="${fill}"`}${opts?.stroke === false ? ' stroke="0"' : ''}>${ops}</a:path>`)
|
|
41
|
+
.join('');
|
|
42
|
+
return `<a:custGeom><a:avLst/><a:gdLst/><a:ahLst/><a:cxnLst/><a:rect l="l" t="t" r="r" b="b"/><a:pathLst>${body}</a:pathLst></a:custGeom>`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A cylinder lying on its side, `w` x `h` px, its visible end on the right, end caps `cap` px wide. Drawn
|
|
46
|
+
* here rather than with Word's `flowChartMagneticDrum`, whose caps take a third of the width whatever the
|
|
47
|
+
* height.
|
|
48
|
+
*/
|
|
49
|
+
export function horizontalCylinderGeometry(w, h, cap) {
|
|
50
|
+
const u = pathUnits;
|
|
51
|
+
const rx = cap;
|
|
52
|
+
const ry = h / 2;
|
|
53
|
+
const arc = (stAng, swAng) => `<a:arcTo wR="${u(rx)}" hR="${u(ry)}" stAng="${stAng}" swAng="${swAng}"/>`;
|
|
54
|
+
const outline = `<a:moveTo><a:pt x="${u(rx)}" y="0"/></a:moveTo><a:lnTo><a:pt x="${u(w - rx)}" y="0"/></a:lnTo>${arc(16200000, 10800000)}` +
|
|
55
|
+
`<a:lnTo><a:pt x="${u(rx)}" y="${u(h)}"/></a:lnTo>${arc(5400000, 10800000)}<a:close/>`;
|
|
56
|
+
const end = `<a:moveTo><a:pt x="${u(w - 2 * rx)}" y="${u(ry)}"/></a:moveTo>${arc(10800000, 21600000)}<a:close/>`;
|
|
57
|
+
return customGeometry(w, h, [['norm', outline], ['none', end]]);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=custom-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-geometry.js","sourceRoot":"","sources":["../../src/translator/custom-geometry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kFAAkF;AAClF,MAAM,IAAI,GAAG,EAAE,CAAC;AAEhB,gCAAgC;AAChC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AAErE,6DAA6D;AAC7D,MAAM,UAAU,UAAU,CAAC,EAAU,EAAE,EAAU,EAAE,CAAS;IAC1D,MAAM,CAAC,GAAG,SAAS,CAAC;IACpB,OAAO,sBA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,MAAM,EAAE,GAAG,GAAG,CAAC;IACf,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,MAAM,GAAG,GAAG,CAAC,KAAa,EAAE,KAAa,EAAU,EAAE,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,YAAY,KAAK,YAAY,KAAK,KAAK,CAAC;IACjI,MAAM,OAAO,GACX,sBAAsB,CAAC,CAAC,EAAE,CAAC,wCAAwC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,qBAAqB,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE;QAC1H,oBAAoB,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,eAAe,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC;IACzF,MAAM,GAAG,GAAG,sBAAsB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,iBAAiB,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC;IACjH,OAAO,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A routed edge as Word's own elbow connector (`bentConnector5`) instead of a free-form path.
|
|
3
|
+
*
|
|
4
|
+
* Word loads a connector whose geometry is an `a:custGeom` as a free-form shape: its `stCxn`/`endCxn`
|
|
5
|
+
* attachments are dropped and the line no longer follows its nodes when they move (measured on Word
|
|
6
|
+
* 16.0.20625 by the agent benchmark, `ROUTED_CONNECTOR_RESULTS.md`). A preset connector stays attached.
|
|
7
|
+
* `bentConnector5` draws, in its own box, `(0,0) -> (x1,0) -> (x1,y2) -> (x3,y2) -> (x3,h) -> (w,h)` with
|
|
8
|
+
* `x1 = w*adj1/100000`, `y2 = h*adj2/100000`, `x3 = w*adj3/100000` (ECMA-376 `presetShapeDefinitions.xml`):
|
|
9
|
+
* an exit stub, a leg out to a lane parallel to the flow, the lane, a leg back and an entry stub. That is
|
|
10
|
+
* the shape of the detour Dagre computes around an intermediate node, squared off.
|
|
11
|
+
*
|
|
12
|
+
* Everything here works in a local frame: origin at the source's connection site, `u` along the direction
|
|
13
|
+
* the connector leaves the source, `v` across it.
|
|
14
|
+
*/
|
|
15
|
+
export interface Point {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
}
|
|
19
|
+
/** A unit vector along one axis: the direction a connector leaves its source. */
|
|
20
|
+
export interface Direction {
|
|
21
|
+
x: -1 | 0 | 1;
|
|
22
|
+
y: -1 | 0 | 1;
|
|
23
|
+
}
|
|
24
|
+
/** The six corners of a `bentConnector5` path, start to end. */
|
|
25
|
+
export type ElbowRoute = [Point, Point, Point, Point, Point, Point];
|
|
26
|
+
/**
|
|
27
|
+
* The elbow route from `start` to `end` through the lane Dagre's `waypoints` run along, or `undefined`
|
|
28
|
+
* when no squared-off route stays clear of every obstacle (the caller then keeps Dagre's own polyline).
|
|
29
|
+
*
|
|
30
|
+
* The two legs stand where Dagre's detour leaves and rejoins the straight run (first and last waypoint
|
|
31
|
+
* along the flow). The lane is the line across the flow where most of the detour runs; when that one
|
|
32
|
+
* is blocked, each other line a waypoint sits on is tried, so the route only ever uses a corridor Dagre
|
|
33
|
+
* itself reserved. `clear(a, b)` says whether segment `a`-`b` avoids every node other than the two ends.
|
|
34
|
+
*/
|
|
35
|
+
export declare function elbowRoute(start: Point, end: Point, exit: Direction, waypoints: Point[], clear: (a: Point, b: Point) => boolean): ElbowRoute | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The `a:xfrm` and `a:prstGeom` drawing `route` (EMU) as a `bentConnector5` that leaves its source along
|
|
38
|
+
* `exit`.
|
|
39
|
+
*
|
|
40
|
+
* DrawingML draws a preset in its unrotated box, mirrors it (`flipH`/`flipV`), then turns it by `rot`
|
|
41
|
+
* about the box's centre. The box's `x` axis must end up along `exit` and its `y` axis across it, towards
|
|
42
|
+
* the end of the route: a horizontal exit needs no rotation, a vertical one a quarter turn (`rot` of 90°
|
|
43
|
+
* clockwise maps the box's `x` axis to screen `y` and its `y` axis to screen `-x`); the flips then pick
|
|
44
|
+
* the sense of each axis.
|
|
45
|
+
*
|
|
46
|
+
* When the route ends level with its start (the usual detour between two nodes on the same row), the
|
|
47
|
+
* box would have no height to scale `adj2` by, and a very thin one would push `adj2` past 32 bits. The
|
|
48
|
+
* height is then the smallest that keeps every `adj` a 32-bit integer; the drawn end moves across the
|
|
49
|
+
* flow by that height, under 1,000 EMU (0.03 mm) for a lane anywhere on a page, and Word keeps the
|
|
50
|
+
* connector attached to its node regardless.
|
|
51
|
+
*/
|
|
52
|
+
export declare function elbowConnectorGeometry(route: ElbowRoute, exit: Direction): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A routed edge as Word's own elbow connector (`bentConnector5`) instead of a free-form path.
|
|
3
|
+
*
|
|
4
|
+
* Word loads a connector whose geometry is an `a:custGeom` as a free-form shape: its `stCxn`/`endCxn`
|
|
5
|
+
* attachments are dropped and the line no longer follows its nodes when they move (measured on Word
|
|
6
|
+
* 16.0.20625 by the agent benchmark, `ROUTED_CONNECTOR_RESULTS.md`). A preset connector stays attached.
|
|
7
|
+
* `bentConnector5` draws, in its own box, `(0,0) -> (x1,0) -> (x1,y2) -> (x3,y2) -> (x3,h) -> (w,h)` with
|
|
8
|
+
* `x1 = w*adj1/100000`, `y2 = h*adj2/100000`, `x3 = w*adj3/100000` (ECMA-376 `presetShapeDefinitions.xml`):
|
|
9
|
+
* an exit stub, a leg out to a lane parallel to the flow, the lane, a leg back and an entry stub. That is
|
|
10
|
+
* the shape of the detour Dagre computes around an intermediate node, squared off.
|
|
11
|
+
*
|
|
12
|
+
* Everything here works in a local frame: origin at the source's connection site, `u` along the direction
|
|
13
|
+
* the connector leaves the source, `v` across it.
|
|
14
|
+
*/
|
|
15
|
+
const dot = (a, b) => a.x * b.x + a.y * b.y;
|
|
16
|
+
const sub = (a, b) => ({ x: a.x - b.x, y: a.y - b.y });
|
|
17
|
+
/** The perpendicular of `d` used as the `v` axis before it is oriented towards the detour. */
|
|
18
|
+
const across = (d) => ({ x: -d.y, y: d.x });
|
|
19
|
+
/**
|
|
20
|
+
* The elbow route from `start` to `end` through the lane Dagre's `waypoints` run along, or `undefined`
|
|
21
|
+
* when no squared-off route stays clear of every obstacle (the caller then keeps Dagre's own polyline).
|
|
22
|
+
*
|
|
23
|
+
* The two legs stand where Dagre's detour leaves and rejoins the straight run (first and last waypoint
|
|
24
|
+
* along the flow). The lane is the line across the flow where most of the detour runs; when that one
|
|
25
|
+
* is blocked, each other line a waypoint sits on is tried, so the route only ever uses a corridor Dagre
|
|
26
|
+
* itself reserved. `clear(a, b)` says whether segment `a`-`b` avoids every node other than the two ends.
|
|
27
|
+
*/
|
|
28
|
+
export function elbowRoute(start, end, exit, waypoints, clear) {
|
|
29
|
+
const v = across(exit);
|
|
30
|
+
const length = dot(sub(end, start), exit);
|
|
31
|
+
if (length <= 0 || waypoints.length === 0)
|
|
32
|
+
return undefined;
|
|
33
|
+
const local = waypoints.map((p) => ({ u: dot(sub(p, start), exit), v: dot(sub(p, start), v) }));
|
|
34
|
+
const x1 = local[0].u;
|
|
35
|
+
const x3 = local[local.length - 1].u;
|
|
36
|
+
if (x1 <= 0 || x3 >= length || x1 > x3)
|
|
37
|
+
return undefined;
|
|
38
|
+
// Each line across the flow, weighted by how much of the detour runs along it.
|
|
39
|
+
const runs = new Map();
|
|
40
|
+
local.forEach((p, i) => {
|
|
41
|
+
const next = local[i + 1];
|
|
42
|
+
const run = next && next.v === p.v ? Math.abs(next.u - p.u) : 0;
|
|
43
|
+
runs.set(p.v, (runs.get(p.v) ?? 0) + run);
|
|
44
|
+
});
|
|
45
|
+
const lanes = [...runs.entries()].sort((a, b) => b[1] - a[1] || Math.abs(a[0]) - Math.abs(b[0])).map(([lane]) => lane);
|
|
46
|
+
const toScreen = (u, w) => ({
|
|
47
|
+
x: start.x + u * exit.x + w * v.x,
|
|
48
|
+
y: start.y + u * exit.y + w * v.y,
|
|
49
|
+
});
|
|
50
|
+
const endAcross = dot(sub(end, start), v);
|
|
51
|
+
for (const lane of lanes) {
|
|
52
|
+
const route = [start, toScreen(x1, 0), toScreen(x1, lane), toScreen(x3, lane), toScreen(x3, endAcross), end];
|
|
53
|
+
if (route.every((p, i) => i === 0 || clear(route[i - 1], p)))
|
|
54
|
+
return route;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
/** Largest `adj` value written: a guide formula's `val` is read as a 32-bit integer. */
|
|
59
|
+
const MAX_ADJ = 2 ** 31 - 1;
|
|
60
|
+
/**
|
|
61
|
+
* The `a:xfrm` and `a:prstGeom` drawing `route` (EMU) as a `bentConnector5` that leaves its source along
|
|
62
|
+
* `exit`.
|
|
63
|
+
*
|
|
64
|
+
* DrawingML draws a preset in its unrotated box, mirrors it (`flipH`/`flipV`), then turns it by `rot`
|
|
65
|
+
* about the box's centre. The box's `x` axis must end up along `exit` and its `y` axis across it, towards
|
|
66
|
+
* the end of the route: a horizontal exit needs no rotation, a vertical one a quarter turn (`rot` of 90°
|
|
67
|
+
* clockwise maps the box's `x` axis to screen `y` and its `y` axis to screen `-x`); the flips then pick
|
|
68
|
+
* the sense of each axis.
|
|
69
|
+
*
|
|
70
|
+
* When the route ends level with its start (the usual detour between two nodes on the same row), the
|
|
71
|
+
* box would have no height to scale `adj2` by, and a very thin one would push `adj2` past 32 bits. The
|
|
72
|
+
* height is then the smallest that keeps every `adj` a 32-bit integer; the drawn end moves across the
|
|
73
|
+
* flow by that height, under 1,000 EMU (0.03 mm) for a lane anywhere on a page, and Word keeps the
|
|
74
|
+
* connector attached to its node regardless.
|
|
75
|
+
*/
|
|
76
|
+
export function elbowConnectorGeometry(route, exit) {
|
|
77
|
+
const [start, legOut, laneStart, , legBack, end] = route;
|
|
78
|
+
const toEnd = sub(end, start);
|
|
79
|
+
const cx = dot(toEnd, exit);
|
|
80
|
+
let w = across(exit);
|
|
81
|
+
if (dot(toEnd, w) < 0 || (dot(toEnd, w) === 0 && dot(sub(laneStart, start), w) < 0))
|
|
82
|
+
w = { x: -w.x, y: -w.y };
|
|
83
|
+
const laneAcross = dot(sub(laneStart, start), w);
|
|
84
|
+
const minHeight = Math.ceil((Math.abs(laneAcross) * 100000) / MAX_ADJ);
|
|
85
|
+
const cy = Math.max(1, dot(toEnd, w), minHeight);
|
|
86
|
+
const vertical = exit.x === 0;
|
|
87
|
+
// rot 0: x axis = (sx, 0), y axis = (0, sy). rot 90°: x axis = (0, sx), y axis = (-sy, 0).
|
|
88
|
+
const flipH = vertical ? exit.y < 0 : exit.x < 0;
|
|
89
|
+
const flipV = vertical ? w.x > 0 : w.y < 0;
|
|
90
|
+
const centre = { x: start.x + (exit.x * cx + w.x * cy) / 2, y: start.y + (exit.y * cx + w.y * cy) / 2 };
|
|
91
|
+
const adj = (value, size) => Math.round((value * 100000) / size);
|
|
92
|
+
const adj1 = adj(dot(sub(legOut, start), exit), cx);
|
|
93
|
+
const adj2 = adj(laneAcross, cy);
|
|
94
|
+
const adj3 = adj(dot(sub(legBack, start), exit), cx);
|
|
95
|
+
const attrs = `${vertical ? ' rot="5400000"' : ''}${flipH ? ' flipH="1"' : ''}${flipV ? ' flipV="1"' : ''}`;
|
|
96
|
+
return [
|
|
97
|
+
` <a:xfrm${attrs}>`,
|
|
98
|
+
` <a:off x="${Math.round(centre.x - cx / 2)}" y="${Math.round(centre.y - cy / 2)}"/>`,
|
|
99
|
+
` <a:ext cx="${cx}" cy="${cy}"/>`,
|
|
100
|
+
' </a:xfrm>',
|
|
101
|
+
' <a:prstGeom prst="bentConnector5">',
|
|
102
|
+
' <a:avLst>',
|
|
103
|
+
` <a:gd name="adj1" fmla="val ${adj1}"/>`,
|
|
104
|
+
` <a:gd name="adj2" fmla="val ${adj2}"/>`,
|
|
105
|
+
` <a:gd name="adj3" fmla="val ${adj3}"/>`,
|
|
106
|
+
' </a:avLst>',
|
|
107
|
+
' </a:prstGeom>',
|
|
108
|
+
].join('\n');
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=elbow-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elbow-connector.js","sourceRoot":"","sources":["../../src/translator/elbow-connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgBH,MAAM,GAAG,GAAG,CAAC,CAAQ,EAAE,CAAQ,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAClE,MAAM,GAAG,GAAG,CAAC,CAAQ,EAAE,CAAQ,EAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAE5E,8FAA8F;AAC9F,MAAM,MAAM,GAAG,CAAC,CAAY,EAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,KAAY,EACZ,GAAU,EACV,IAAe,EACf,SAAkB,EAClB,KAAsC;IAEtC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACvB,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;IAC1C,IAAI,MAAM,IAAI,CAAC,IAAI,SAAS,CA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AC;IAC5G,OAAO;QACL,gBAAgB,KAAK,GAAG;QACxB,qBAAqB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK;QAC5F,sBAAsB,EAAE,SAAS,EAAE,KAAK;QACxC,iBAAiB;QACjB,0CAA0C;QAC1C,mBAAmB;QACnB,yCAAyC,IAAI,KAAK;QAClD,yCAAyC,IAAI,KAAK;QAClD,yCAAyC,IAAI,KAAK;QAClD,oBAAoB;QACpB,qBAAqB;KACtB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -15,9 +15,12 @@
|
|
|
15
15
|
* marker/dash), and already had working private copies before this module
|
|
16
16
|
* existed — left alone rather than churned for a refactor they don't need.
|
|
17
17
|
*/
|
|
18
|
+
import type { LabelToken } from '../types.js';
|
|
18
19
|
/** `a:headEnd`/`a:tailEnd` marker presets this project has confirmed render
|
|
19
|
-
* correctly (see `../translator/ooxml-translator.ts`'s `ArrowMarker`).
|
|
20
|
-
|
|
20
|
+
* correctly (see `../translator/ooxml-translator.ts`'s `ArrowMarker`).
|
|
21
|
+
* `arrow` is the open arrowhead (two strokes, no fill), the requirement
|
|
22
|
+
* diagram's. */
|
|
23
|
+
export type ArrowMarker = 'none' | 'triangle' | 'arrow' | 'oval' | 'diamond';
|
|
21
24
|
export declare function scalePt(px: number, factor: number): number;
|
|
22
25
|
/** Point where the ray from a box's center toward `(tx, ty)` crosses the
|
|
23
26
|
* box's own axis-aligned border — used to trim a relationship line to each
|
|
@@ -80,11 +83,21 @@ export declare function shiftPoint(p: {
|
|
|
80
83
|
x: number;
|
|
81
84
|
y: number;
|
|
82
85
|
};
|
|
83
|
-
|
|
86
|
+
/**
|
|
87
|
+
* A plain or rounded rectangle. `cornerAdj` (rounded only) is DrawingML's `adj`, the corner radius as a
|
|
88
|
+
* fraction of the shorter side in 1/100000: without it Word's default (about a sixth of that side) applies,
|
|
89
|
+
* which grows with the box.
|
|
90
|
+
*/
|
|
91
|
+
export declare function rect(id: number, x: number, y: number, w: number, h: number, fill: string | undefined, line: string | undefined, name: string, roundRect?: boolean, cornerAdj?: number): string;
|
|
84
92
|
export declare function ellipse(id: number, x: number, y: number, w: number, h: number, fill: string, line?: string): string;
|
|
85
93
|
export declare function diamond(id: number, x: number, y: number, w: number, h: number, fill: string, line: string): string;
|
|
86
|
-
|
|
94
|
+
/**
|
|
95
|
+
* A borderless text box, one paragraph per entry of `lines`. An entry is plain text, or a label's rich text
|
|
96
|
+
* (`LabelToken[]`: bold/italic runs and line breaks), on which `opts.bold`/`opts.italic` add their emphasis.
|
|
97
|
+
*/
|
|
98
|
+
export declare function textBoxLines(id: number, x: number, y: number, w: number, h: number, lines: Array<string | LabelToken[]>, sizeHalfPt: number, opts?: {
|
|
87
99
|
bold?: boolean;
|
|
100
|
+
italic?: boolean;
|
|
88
101
|
align?: 'l' | 'ctr';
|
|
89
102
|
color?: string;
|
|
90
103
|
}): string;
|
|
@@ -96,3 +109,26 @@ export declare function textBoxLines(id: number, x: number, y: number, w: number
|
|
|
96
109
|
* `./ooxml-translator.ts` uses for flowchart arrowheads.
|
|
97
110
|
*/
|
|
98
111
|
export declare function connector(id: number, x1: number, y1: number, x2: number, y2: number, colorHex: string, widthEmu: number, dash: 'solid' | 'dash', headEnd: ArrowMarker, headSize: 'sm' | 'lg', tailEnd: ArrowMarker, tailSize: 'sm' | 'lg'): string;
|
|
112
|
+
/** Hollow end markers DrawingML's line ends cannot draw (they are always filled with the line colour). */
|
|
113
|
+
export type HollowMarker = 'triangle' | 'diamond';
|
|
114
|
+
/** Hollow marker size in px (`length` along the line, `width` across it): UML's open triangle and open diamond. */
|
|
115
|
+
export declare const HOLLOW_SIZE_PX: Readonly<Record<HollowMarker, {
|
|
116
|
+
length: number;
|
|
117
|
+
width: number;
|
|
118
|
+
}>>;
|
|
119
|
+
/**
|
|
120
|
+
* A hollow end marker (UML generalization / realization triangle, aggregation diamond): a closed polygon,
|
|
121
|
+
* white inside, outlined in the line colour, with its tip on `tip` and its body running back along the line
|
|
122
|
+
* towards `from`. Emitted right after the line it ends, so its white fill hides the line's last stretch.
|
|
123
|
+
* A separate shape from the line (a line end cannot be hollow), so it does not follow the line if a
|
|
124
|
+
* connected box is moved; the class diagram's boxes are not attached to their lines either.
|
|
125
|
+
*
|
|
126
|
+
* All coordinates and sizes in EMU. `length` is along the line, `width` across it.
|
|
127
|
+
*/
|
|
128
|
+
export declare function hollowMarker(id: number, kind: HollowMarker, tip: {
|
|
129
|
+
x: number;
|
|
130
|
+
y: number;
|
|
131
|
+
}, from: {
|
|
132
|
+
x: number;
|
|
133
|
+
y: number;
|
|
134
|
+
}, length: number, width: number, lineHex: string, lineEmu: number): string;
|
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
* marker/dash), and already had working private copies before this module
|
|
16
16
|
* existed — left alone rather than churned for a refactor they don't need.
|
|
17
17
|
*/
|
|
18
|
+
import { pathShape } from './path-shape.js';
|
|
19
|
+
import { renderLabelRuns } from './label-runs.js';
|
|
18
20
|
import { escapeXml } from './xml-escape.js';
|
|
19
|
-
import { EMU_PER_PX } from './canvas.js';
|
|
21
|
+
import { EMU_PER_PX, LABEL_NAME, unwrappedTextFrame } from './canvas.js';
|
|
20
22
|
export function scalePt(px, factor) {
|
|
21
23
|
return Math.round(px * EMU_PER_PX * factor);
|
|
22
24
|
}
|
|
@@ -85,7 +87,12 @@ export function perpendicularUnit(p1, p2) {
|
|
|
85
87
|
export function shiftPoint(p, ux, uy, amount) {
|
|
86
88
|
return { x: p.x + ux * amount, y: p.y + uy * amount };
|
|
87
89
|
}
|
|
88
|
-
|
|
90
|
+
/**
|
|
91
|
+
* A plain or rounded rectangle. `cornerAdj` (rounded only) is DrawingML's `adj`, the corner radius as a
|
|
92
|
+
* fraction of the shorter side in 1/100000: without it Word's default (about a sixth of that side) applies,
|
|
93
|
+
* which grows with the box.
|
|
94
|
+
*/
|
|
95
|
+
export function rect(id, x, y, w, h, fill, line, name, roundRect = false, cornerAdj) {
|
|
89
96
|
const fillXml = fill ? `<a:solidFill><a:srgbClr val="${fill}"/></a:solidFill>` : '<a:noFill/>';
|
|
90
97
|
const lineXml = line
|
|
91
98
|
? `<a:ln w="9525"><a:solidFill><a:srgbClr val="${line}"/></a:solidFill></a:ln>`
|
|
@@ -96,7 +103,9 @@ export function rect(id, x, y, w, h, fill, line, name, roundRect = false) {
|
|
|
96
103
|
' <wps:cNvSpPr/>',
|
|
97
104
|
' <wps:spPr>',
|
|
98
105
|
` <a:xfrm><a:off x="${x}" y="${y}"/><a:ext cx="${Math.max(1, w)}" cy="${Math.max(1, h)}"/></a:xfrm>`,
|
|
99
|
-
|
|
106
|
+
roundRect && cornerAdj !== undefined
|
|
107
|
+
? ` <a:prstGeom prst="roundRect"><a:avLst><a:gd name="adj" fmla="val ${Math.round(cornerAdj)}"/></a:avLst></a:prstGeom>`
|
|
108
|
+
: ` <a:prstGeom prst="${roundRect ? 'roundRect' : 'rect'}"><a:avLst/></a:prstGeom>`,
|
|
100
109
|
fillXml,
|
|
101
110
|
lineXml,
|
|
102
111
|
' </wps:spPr>',
|
|
@@ -138,21 +147,33 @@ export function diamond(id, x, y, w, h, fill, line) {
|
|
|
138
147
|
].join('\n');
|
|
139
148
|
}
|
|
140
149
|
const WORD_JC = { l: 'left', ctr: 'center' };
|
|
150
|
+
/**
|
|
151
|
+
* A borderless text box, one paragraph per entry of `lines`. An entry is plain text, or a label's rich text
|
|
152
|
+
* (`LabelToken[]`: bold/italic runs and line breaks), on which `opts.bold`/`opts.italic` add their emphasis.
|
|
153
|
+
*/
|
|
141
154
|
export function textBoxLines(id, x, y, w, h, lines, sizeHalfPt, opts = {}) {
|
|
142
155
|
const align = opts.align ?? 'l';
|
|
143
|
-
const
|
|
156
|
+
const frame = unwrappedTextFrame(x, w, WORD_JC[align]);
|
|
157
|
+
const emphasis = (opts.bold ? '<w:b/>' : '') + (opts.italic ? '<w:i/>' : '');
|
|
144
158
|
const color = opts.color ?? '000000';
|
|
159
|
+
const pPr = `<w:pPr><w:spacing w:before="0" w:after="0"/><w:jc w:val="${WORD_JC[align]}"/></w:pPr>`;
|
|
145
160
|
const paragraphs = lines
|
|
146
|
-
.map((line) =>
|
|
147
|
-
|
|
148
|
-
|
|
161
|
+
.map((line) => typeof line === 'string'
|
|
162
|
+
? ` <w:p>${pPr}` +
|
|
163
|
+
`<w:r><w:rPr>${emphasis}<w:color w:val="${color}"/><w:sz w:val="${sizeHalfPt}"/></w:rPr>` +
|
|
164
|
+
`<w:t xml:space="preserve">${escapeXml(line)}</w:t></w:r></w:p>`
|
|
165
|
+
: [
|
|
166
|
+
` <w:p>${pPr}`,
|
|
167
|
+
renderLabelRuns(line.map((t) => ('break' in t ? t : { ...t, bold: t.bold || opts.bold, italic: t.italic || opts.italic })), color, sizeHalfPt),
|
|
168
|
+
' </w:p>',
|
|
169
|
+
].join('\n'))
|
|
149
170
|
.join('\n');
|
|
150
171
|
return [
|
|
151
172
|
'<wps:wsp>',
|
|
152
|
-
` <wps:cNvPr id="${id}" name="
|
|
173
|
+
` <wps:cNvPr id="${id}" name="${LABEL_NAME} ${id}"/>`,
|
|
153
174
|
' <wps:cNvSpPr txBox="1"/>',
|
|
154
175
|
' <wps:spPr>',
|
|
155
|
-
` <a:xfrm><a:off x="${x}" y="${y}"/><a:ext cx="${Math.max(1, w)}" cy="${Math.max(1, h)}"/></a:xfrm>`,
|
|
176
|
+
` <a:xfrm><a:off x="${frame.x}" y="${y}"/><a:ext cx="${Math.max(1, frame.w)}" cy="${Math.max(1, h)}"/></a:xfrm>`,
|
|
156
177
|
' <a:prstGeom prst="rect"><a:avLst/></a:prstGeom>',
|
|
157
178
|
' <a:noFill/>',
|
|
158
179
|
' <a:ln><a:noFill/></a:ln>',
|
|
@@ -162,7 +183,7 @@ export function textBoxLines(id, x, y, w, h, lines, sizeHalfPt, opts = {}) {
|
|
|
162
183
|
paragraphs,
|
|
163
184
|
' </w:txbxContent>',
|
|
164
185
|
' </wps:txbx>',
|
|
165
|
-
` <wps:bodyPr wrap="
|
|
186
|
+
` <wps:bodyPr wrap="square" lIns="0" tIns="0" rIns="0" bIns="0" anchor="${align === 'ctr' ? 'ctr' : 't'}"/>`,
|
|
166
187
|
'</wps:wsp>',
|
|
167
188
|
].join('\n');
|
|
168
189
|
}
|
|
@@ -220,4 +241,35 @@ export function connector(id, x1, y1, x2, y2, colorHex, widthEmu, dash, headEnd,
|
|
|
220
241
|
.filter((line) => line.length > 0)
|
|
221
242
|
.join('\n');
|
|
222
243
|
}
|
|
244
|
+
/** Hollow marker size in px (`length` along the line, `width` across it): UML's open triangle and open diamond. */
|
|
245
|
+
export const HOLLOW_SIZE_PX = {
|
|
246
|
+
triangle: { length: 16, width: 14 },
|
|
247
|
+
diamond: { length: 20, width: 12 },
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* A hollow end marker (UML generalization / realization triangle, aggregation diamond): a closed polygon,
|
|
251
|
+
* white inside, outlined in the line colour, with its tip on `tip` and its body running back along the line
|
|
252
|
+
* towards `from`. Emitted right after the line it ends, so its white fill hides the line's last stretch.
|
|
253
|
+
* A separate shape from the line (a line end cannot be hollow), so it does not follow the line if a
|
|
254
|
+
* connected box is moved; the class diagram's boxes are not attached to their lines either.
|
|
255
|
+
*
|
|
256
|
+
* All coordinates and sizes in EMU. `length` is along the line, `width` across it.
|
|
257
|
+
*/
|
|
258
|
+
export function hollowMarker(id, kind, tip, from, length, width, lineHex, lineEmu) {
|
|
259
|
+
const dx = from.x - tip.x;
|
|
260
|
+
const dy = from.y - tip.y;
|
|
261
|
+
const norm = Math.hypot(dx, dy) || 1;
|
|
262
|
+
const ux = dx / norm;
|
|
263
|
+
const uy = dy / norm;
|
|
264
|
+
const nx = -uy;
|
|
265
|
+
const ny = ux;
|
|
266
|
+
const at = (along, across) => ({
|
|
267
|
+
x: Math.round(tip.x + ux * along + nx * across),
|
|
268
|
+
y: Math.round(tip.y + uy * along + ny * across),
|
|
269
|
+
});
|
|
270
|
+
const points = kind === 'triangle'
|
|
271
|
+
? [at(0, 0), at(length, width / 2), at(length, -width / 2)]
|
|
272
|
+
: [at(0, 0), at(length / 2, width / 2), at(length, 0), at(length / 2, -width / 2)];
|
|
273
|
+
return pathShape(id, points, true, 'FFFFFF', 100, lineHex, lineEmu);
|
|
274
|
+
}
|
|
223
275
|
//# sourceMappingURL=graph-shapes.js.map
|