@grethel-labs/excaliplant 0.3.6 → 0.5.2

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/CHANGELOG.md CHANGED
@@ -4,6 +4,83 @@ All notable changes to `@grethel-labs/excaliplant` are documented in this
4
4
  file. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+
11
+ - New `src/style/style.mjs` module with a single source of truth for
12
+ renderer styling. `getStyle()` / `setStyle()` / `resetStyle()` /
13
+ `loadStyleFromFile()` are exported from the package root, the CLI
14
+ exposes `excaliplant --style <file>`, and the `./style` subpath is
15
+ importable directly. The loader supports JSON and a small YAML
16
+ subset (nested maps, scalars, comments) so style overrides can live
17
+ in either format. Example presets ship as
18
+ [`style.example.json`](style.example.json) and
19
+ [`style.example.yaml`](style.example.yaml).
20
+ - Auto-shrink for box titles and descriptions: long unbreakable
21
+ identifiers now reduce their font size (down to `text.minFontSize`)
22
+ rather than overflowing. Disable via `text.autoShrink: false`. New
23
+ helper `measureFitted` is exported from `src/style/text.mjs`.
24
+ - Edge-label chips now carry `customData.role` markers
25
+ (`edgeLabelChip` / `edgeLabelText`) so renderers, tests, and
26
+ third-party tools can identify them reliably.
27
+ - Auto-generated single-page API reference at
28
+ [`docs/API.md`](docs/API.md). It replaces the previous TypeDoc HTML
29
+ site under `docs/api/` and is rendered from JSDoc by
30
+ [`docs/scripts/extract-api.mjs`](docs/scripts/extract-api.mjs) +
31
+ [`docs/API.template.md.njk`](docs/API.template.md.njk) on every
32
+ `npm run build:docs` run, so it can never drift from the README.
33
+ The TypeDoc devDependency was removed.
34
+
35
+ ### Changed
36
+
37
+ - Edge labels render as a compact tag in the connection's stroke
38
+ colour with white text by default (`edgeLabel.useLineColor`,
39
+ `edgeLabel.textColor`, `edgeLabel.maxWidth`, …). The chip itself is
40
+ emitted with `roughness: 0` and no rounded corners so it reads as a
41
+ clean badge sitting on the line; default font size dropped to 10 px.
42
+ - The `svg.mjs` renderer now honours the per-element `roughness`
43
+ field, so connection arrows / lines and edge-label chips appear
44
+ perfectly straight in the exported SVG / PNG (matching the existing
45
+ `roughness: 0` Excalidraw JSON output).
46
+ - `FONT` from `src/style/text.mjs` is now a live view of the active
47
+ style document. Existing reads (`FONT.sizeTitle`, `FONT.family`,
48
+ …) keep working; calls to `setStyle()` / `loadStyleFromFile()`
49
+ immediately propagate to sizing and rendering.
50
+
51
+ ## [0.3.7] - 2026-05-04
52
+
53
+ ### Added
54
+
55
+ - Class-diagram support for tplant-style PlantUML sources. The parser now
56
+ understands `class | abstract class | interface | enum` blocks with
57
+ generic type parameters (`Container<T extends Base>`), `extends`, and
58
+ `implements` clauses, so headers like
59
+ `class Child extends Parent` or `abstract class Foo implements Bar`
60
+ produce inheritance / realisation edges automatically.
61
+ - Connection multiplicity labels: `A "1" o-- "0..*" B : contains` is now
62
+ parsed and exposed as `Connection.fromMul` / `Connection.toMul`.
63
+ - New `enum` shape rendered as a UML class compartment with the
64
+ `«enumeration»` stereotype; `interface` boxes carrying members render
65
+ as compartment boxes with the `«interface»` stereotype.
66
+ - Member modifier tags (`{abstract}`, `{static}`, `{field}`, `{method}`)
67
+ survive `explodeBraces` and stay attached to the surrounding member
68
+ line.
69
+ - Class-diagram inheritance / realisation edges (`extends`,
70
+ `implements`) auto-vivify undeclared parents as stub class boxes,
71
+ matching PlantUML's implicit-declaration behaviour. Generic
72
+ component-style connections (`A --> B`) and bracket / paren / quoted
73
+ shorthand references (`[A]`, `(B)`, `"C"`) continue to drop silently
74
+ when undeclared, preserving existing component-diagram semantics.
75
+ - New `prefer-higher-version` git merge driver auto-resolves conflicts
76
+ on `package.json` / `package-lock.json` whose only disagreement is a
77
+ `"version": "x.y.z"` line by keeping the higher semver. Real
78
+ (non-version) conflicts are still surfaced for human review. Driver
79
+ is registered by `npm install` (via the `prepare` lifecycle hook) and
80
+ applied through `.gitattributes`. The auto-rebase workflow now runs
81
+ `npm ci` before rebasing so the driver is configured on the runner,
82
+ and regenerates docs after a successful rebase.
83
+
7
84
  ## [0.3.1] - 2026-05-04
8
85
 
9
86
  ### Fixed
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![node](https://img.shields.io/node/v/@grethel-labs/excaliplant.svg)](https://nodejs.org)
8
8
  [![license](https://img.shields.io/npm/l/@grethel-labs/excaliplant.svg)](./LICENSE)
9
9
 
10
- > PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser. &nbsp;·&nbsp; **v0.3.6** &nbsp;·&nbsp; 86 tests &nbsp;·&nbsp; MIT
10
+ > PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser. &nbsp;·&nbsp; **v0.5.2** &nbsp;·&nbsp; 116 tests &nbsp;·&nbsp; MIT
11
11
 
12
12
  `@grethel-labs/excaliplant` takes PlantUML source, runs it through a plugin-based
13
13
  parser, lays it out with [ELK](https://github.com/kieler/elkjs), and
@@ -103,13 +103,17 @@ Lower-level entry points are also exported:
103
103
  | `excalidrawJsonToCanvasSvg(…)` | …same, letter-boxed onto a fixed-aspect canvas |
104
104
  | `svgToPng(svg)` | Rasterise SVG to PNG (`@resvg/resvg-js`) |
105
105
 
106
+ The complete list of exported symbols, with parameter tables and
107
+ return types, lives in [`docs/API.md`](./docs/API.md). It is
108
+ regenerated from JSDoc on every `npm run build:docs` run.
109
+
106
110
  ### Run the tests
107
111
 
108
112
  ```sh
109
113
  npm test
110
114
  ```
111
115
 
112
- Ships with **86 tests** across functional, edge-case,
116
+ Ships with **116 tests** across functional, edge-case,
113
117
  security (XSS / ReDoS / prototype-pollution), and self-introspection
114
118
  suites.
115
119
 
@@ -190,6 +194,7 @@ PlantUML text
190
194
  excaliplant
191
195
  ├── assets
192
196
  │ └── fonts
197
+ │ ├── Excalifont-Regular.ttf
193
198
  │ ├── Excalifont-Regular.woff2
194
199
  │ └── LICENSE.txt
195
200
  ├── bin
@@ -200,13 +205,17 @@ excaliplant
200
205
  │ │ ├── build-docs.mjs
201
206
  │ │ ├── check-build-manifest.mjs
202
207
  │ │ ├── config.mjs
208
+ │ │ ├── extract-api.mjs
203
209
  │ │ ├── extract-docs.mjs
204
210
  │ │ ├── file-tree.mjs
205
211
  │ │ └── self-diagrams.mjs
212
+ │ ├── API.md
213
+ │ ├── API.template.md.njk
206
214
  │ └── README.template.md.njk
207
215
  ├── scripts
208
216
  │ ├── auto-patch-deps.mjs
209
217
  │ ├── bump-release-version.mjs
218
+ │ ├── merge-driver-prefer-higher-version.mjs
210
219
  │ ├── prepublish-guard.mjs
211
220
  │ ├── setup-merge-drivers.mjs
212
221
  │ └── smoke.mjs
@@ -237,13 +246,16 @@ excaliplant
237
246
  │ └── style
238
247
  │ ├── colors.mjs
239
248
  │ ├── font.mjs
249
+ │ ├── style.mjs
240
250
  │ └── text.mjs
241
251
  ├── tests
242
252
  │ ├── edge_cases.test.mjs
243
253
  │ ├── functional_more.test.mjs
254
+ │ ├── merge_driver.test.mjs
244
255
  │ ├── plantuml.test.mjs
245
256
  │ ├── security.test.mjs
246
- │ └── self_introspection.test.mjs
257
+ │ ├── self_introspection.test.mjs
258
+ │ └── style.test.mjs
247
259
  ├── AGENTS.md
248
260
  ├── CHANGELOG.md
249
261
  ├── CLAUDE.md
@@ -255,13 +267,15 @@ excaliplant
255
267
  ├── THIRD_PARTY_NOTICES.md
256
268
  ├── index.mjs
257
269
  ├── package.json
258
- ├── tsconfig.json
259
- └── typedoc.json
270
+ ├── style.example.json
271
+ ├── style.example.yaml
272
+ └── tsconfig.json
260
273
  ```
261
274
 
262
- Generated artefacts (`docs/ressources/generated/`, `docs/api/`) live
263
- in `.gitignore` — they are rebuilt by `npm run build:docs` and
264
- `npm run build:api`.
275
+ Generated artefacts (`docs/ressources/generated/`) live in
276
+ `.gitignore` — they are rebuilt by `npm run build:docs`. The
277
+ single-page API reference at [`docs/API.md`](./docs/API.md) is
278
+ generated by the same command from JSDoc.
265
279
 
266
280
  ## Module documentation
267
281
 
package/SECURITY.md CHANGED
@@ -37,7 +37,8 @@ patched release within 30 days for confirmed high/critical issues.
37
37
  - Treat `renderPlantUml(input)` like any other untrusted-input parser.
38
38
  Run it inside a worker / isolated process if your input source is
39
39
  hostile.
40
- - The SVG output **inlines the Excalifont woff2** as a `data:` URL.
40
+ - The SVG output **inlines the Excalifont woff2** as a `data:` URL;
41
+ PNG rasterisation loads the bundled TrueType copy through `resvg`.
41
42
  Some sandboxing environments restrict data URLs in fonts; if that
42
43
  applies, post-process the SVG to drop the `<style>` block.
43
44
  - The PNG path uses `@resvg/resvg-js` which executes as native code
@@ -4,17 +4,18 @@ This package bundles or depends on the following third-party works.
4
4
 
5
5
  ---
6
6
 
7
- ## Excalifont (Latin subset, woff2)
7
+ ## Excalifont (Latin subset, woff2 + TrueType)
8
8
 
9
9
  - Path: [`assets/fonts/Excalifont-Regular.woff2`](assets/fonts/Excalifont-Regular.woff2)
10
+ - Path: [`assets/fonts/Excalifont-Regular.ttf`](assets/fonts/Excalifont-Regular.ttf)
10
11
  - Upstream: <https://github.com/excalidraw/excalidraw>
11
12
  - License: SIL Open Font License 1.1 (OFL-1.1)
12
13
  - Reproduction of the OFL notice is bundled alongside the binary at
13
14
  [`assets/fonts/LICENSE.txt`](assets/fonts/LICENSE.txt).
14
15
 
15
- The font is embedded into exported SVG / PNG documents as a `data:`
16
- URL so they render with the same hand-drawn Excalidraw look in any
17
- context (GitHub README rendering, sandboxed `<img>` hosts, …).
16
+ The woff2 file is embedded into exported SVG documents as a `data:` URL.
17
+ The TrueType copy is loaded by `@resvg/resvg-js` for PNG rasterisation,
18
+ because resvg's `fontFiles` loader does not load woff2 files.
18
19
 
19
20
  ---
20
21
 
@@ -1,7 +1,7 @@
1
1
  Excalifont
2
2
  ==========
3
3
 
4
- The Excalifont woff2 font file in this directory is bundled into
4
+ The Excalifont woff2 and decompressed TrueType font files in this directory are bundled into
5
5
  @grethel-labs/excaliplant so SVG and PNG exports render text in the
6
6
  same hand-drawn typeface that Excalidraw uses on screen.
7
7
 
@@ -37,6 +37,7 @@ Options:
37
37
  --label <s> Source label written to appState.name.
38
38
  --no-canvas For --svg: emit a tightly-cropped SVG without the 4:3 letterbox.
39
39
  --rng-seed <n> Override the deterministic seed (use --rng-seed=random for non-determinism).
40
+ --style <file> Load a JSON or YAML style override (see style.example.json).
40
41
  --max-input-bytes <N>
41
42
  Reject stdin/file input larger than N bytes
42
43
  (default ${DEFAULT_MAX_INPUT_BYTES}, ceiling ${MAX_INPUT_BYTES_CEILING}).
@@ -121,6 +122,9 @@ function parseArgs(argv) {
121
122
  case "--rng-seed":
122
123
  opts.rngSeed = argv[++i];
123
124
  break;
125
+ case "--style":
126
+ opts.styleFile = argv[++i];
127
+ break;
124
128
  case "--max-input-bytes": {
125
129
  const n = parsePositiveInt(argv[++i], "--max-input-bytes");
126
130
  if (n > MAX_INPUT_BYTES_CEILING) {
@@ -215,6 +219,11 @@ async function main() {
215
219
  die(1, e?.message || String(e));
216
220
  }
217
221
 
222
+ if (opts.styleFile) {
223
+ const { loadStyleFromFile } = await import("../src/style/style.mjs");
224
+ loadStyleFromFile(opts.styleFile);
225
+ }
226
+
218
227
  // Build deterministic / overridable RNG.
219
228
  let rng;
220
229
  if (opts.rngSeed === "random") {
package/index.mjs CHANGED
@@ -65,6 +65,16 @@ export {
65
65
  export { svgToPng } from "./src/render/png.mjs";
66
66
  export { EXCALIDRAW_SCHEMA, ROUNDNESS } from "./src/render/schema.mjs";
67
67
  export { createSeededRng, stableHash32 } from "./src/render/rng.mjs";
68
+ export {
69
+ DEFAULT_STYLE,
70
+ EXCALIDRAW_FONT_FAMILY,
71
+ getStyle,
72
+ setStyle,
73
+ resetStyle,
74
+ loadStyleFromFile,
75
+ resolveFontFamilyId,
76
+ parseSimpleYaml,
77
+ } from "./src/style/style.mjs";
68
78
  export {
69
79
  Box,
70
80
  Connection,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grethel-labs/excaliplant",
3
- "version": "0.3.6",
3
+ "version": "0.5.2",
4
4
  "description": "PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser.",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
@@ -30,14 +30,15 @@
30
30
  "./render/png": "./src/render/png.mjs",
31
31
  "./render/schema": "./src/render/schema.mjs",
32
32
  "./render/rng": "./src/render/rng.mjs",
33
- "./model": "./src/model/diagram.mjs"
33
+ "./model": "./src/model/diagram.mjs",
34
+ "./style": "./src/style/style.mjs"
34
35
  },
35
36
  "scripts": {
36
- "test": "node --test tests/edge_cases.test.mjs tests/functional_more.test.mjs tests/plantuml.test.mjs tests/security.test.mjs tests/self_introspection.test.mjs",
37
+ "test": "node --test tests/edge_cases.test.mjs tests/functional_more.test.mjs tests/merge_driver.test.mjs tests/plantuml.test.mjs tests/security.test.mjs tests/self_introspection.test.mjs tests/style.test.mjs",
37
38
  "typecheck": "tsc -p tsconfig.json",
38
39
  "build:docs": "node docs/scripts/build-docs.mjs",
39
- "build:api": "typedoc",
40
- "build": "npm run build:docs && npm run build:api",
40
+ "build:api": "node docs/scripts/build-docs.mjs",
41
+ "build": "npm run build:docs",
41
42
  "format": "prettier --write .",
42
43
  "format:check": "prettier --check .",
43
44
  "prepare": "husky && node scripts/setup-merge-drivers.mjs",
@@ -83,7 +84,6 @@
83
84
  "nunjucks": "^3.2.4",
84
85
  "prettier": "^3.8.3",
85
86
  "tree-node-cli": "^3.0.0",
86
- "typedoc": "^0.28.19",
87
87
  "typescript": "^6.0.3"
88
88
  }
89
89
  }
@@ -7,7 +7,7 @@
7
7
  // of a container share the same content width so titles align.
8
8
 
9
9
  import { Box, Plane, Subplane } from "../model/diagram.mjs";
10
- import { FONT, measureLine, measureWrapped } from "../style/text.mjs";
10
+ import { FONT, measureLine, measureWrapped, measureFitted } from "../style/text.mjs";
11
11
 
12
12
  /**
13
13
  * Default padding / spacing constants used by {@link sizeDiagram}.
@@ -110,23 +110,45 @@ function sizeBox(box, width) {
110
110
  const innerWidth = Math.max(20, width - SIZING.boxPaddingX * 2);
111
111
  // Auto-wrap the title so long labels stay inside the box. Manual
112
112
  // line breaks ("\n") are preserved by wrapping each segment
113
- // independently.
113
+ // independently. `measureFitted` shrinks the font size when a
114
+ // single token would still overflow the inner width at the
115
+ // configured base size — long unbreakable identifiers (e.g.
116
+ // "AVeryLongClassName") then visibly shrink instead of overflowing.
114
117
  const titleSegments = String(box.title || "").split("\n");
115
118
  /** @type {string[]} */
116
119
  const wrappedTitleLines = [];
120
+ let titleFontSize = FONT.sizeTitle;
117
121
  for (const seg of titleSegments) {
118
- const wrapped = measureWrapped(seg, FONT.sizeTitle, innerWidth);
119
- if (wrapped.lines.length === 0) wrappedTitleLines.push("");
120
- else wrappedTitleLines.push(...wrapped.lines);
122
+ const fitted = measureFitted(seg, FONT.sizeTitle, innerWidth);
123
+ titleFontSize = Math.min(titleFontSize, fitted.fontSize);
124
+ if (fitted.lines.length === 0) wrappedTitleLines.push("");
125
+ else wrappedTitleLines.push(...fitted.lines);
126
+ }
127
+ // Re-wrap every segment at the chosen size so all title lines share
128
+ // one font size (mixed-size titles look broken).
129
+ if (titleFontSize !== FONT.sizeTitle) {
130
+ wrappedTitleLines.length = 0;
131
+ for (const seg of titleSegments) {
132
+ const w = measureWrapped(seg, titleFontSize, innerWidth);
133
+ if (w.lines.length === 0) wrappedTitleLines.push("");
134
+ else wrappedTitleLines.push(...w.lines);
135
+ }
121
136
  }
122
137
  // Cache the wrapped title so the renderer can emit the exact same
123
138
  // line breaks the sizing pass measured.
124
139
  box._wrappedTitle = wrappedTitleLines.join("\n");
125
- const titleHeight = wrappedTitleLines.length * FONT.sizeTitle * FONT.lineHeight;
126
- const description = box.description
127
- ? measureWrapped(box.description, FONT.sizeDescription, innerWidth)
128
- : { height: 0, lines: /** @type {string[]} */ ([]) };
129
- if (box.description) box._wrappedDescription = description.lines.join("\n");
140
+ box._wrappedTitleFontSize = titleFontSize;
141
+ const titleHeight = wrappedTitleLines.length * titleFontSize * FONT.lineHeight;
142
+ let descriptionFontSize = FONT.sizeDescription;
143
+ /** @type {{height:number, lines:string[]}} */
144
+ let description = { height: 0, lines: [] };
145
+ if (box.description) {
146
+ const fittedDesc = measureFitted(box.description, FONT.sizeDescription, innerWidth);
147
+ descriptionFontSize = fittedDesc.fontSize;
148
+ description = { height: fittedDesc.height, lines: fittedDesc.lines };
149
+ box._wrappedDescription = description.lines.join("\n");
150
+ box._wrappedDescriptionFontSize = descriptionFontSize;
151
+ }
130
152
  let textHeight = SIZING.boxPaddingY + titleHeight;
131
153
  if (box.stereotype) textHeight += FONT.sizeDescription * FONT.lineHeight;
132
154
  if (description.height) textHeight += SIZING.boxTitleGap + description.height;
@@ -143,7 +165,16 @@ function sizeBox(box, width) {
143
165
  shapeMin = Math.max(shapeMin, 110 + titleHeight);
144
166
  break;
145
167
  case "interface":
146
- shapeMin = Math.max(shapeMin, 70 + titleHeight);
168
+ // Class-diagram interface: sized like a class once it has
169
+ // members or an explicit stereotype.
170
+ if ((box.members && box.members.length) || box.stereotype) {
171
+ shapeMin = Math.max(
172
+ shapeMin,
173
+ textHeight + (box.members?.length ?? 0) * FONT.sizeDescription * FONT.lineHeight + 12,
174
+ );
175
+ } else {
176
+ shapeMin = Math.max(shapeMin, 70 + titleHeight);
177
+ }
147
178
  break;
148
179
  case "usecase":
149
180
  shapeMin = Math.max(shapeMin, 70);
@@ -159,6 +190,7 @@ function sizeBox(box, width) {
159
190
  shapeMin = Math.max(shapeMin, textHeight + 8);
160
191
  break;
161
192
  case "class":
193
+ case "enum":
162
194
  if (box.members && box.members.length) {
163
195
  shapeMin = Math.max(
164
196
  shapeMin,
@@ -36,6 +36,7 @@ export const SHAPES = [
36
36
  "interface",
37
37
  "entity",
38
38
  "class",
39
+ "enum",
39
40
  "note",
40
41
  ];
41
42
 
@@ -82,6 +83,15 @@ export class Box {
82
83
  this._wrappedTitle = undefined;
83
84
  /** @type {string|undefined} */
84
85
  this._wrappedDescription = undefined;
86
+ /**
87
+ * Auto-shrunk font sizes computed by the sizing pass when a long
88
+ * unbreakable token would otherwise overflow the box. Defaults to
89
+ * the active style's `font.sizeTitle` / `font.sizeDescription`.
90
+ * @type {number|undefined}
91
+ */
92
+ this._wrappedTitleFontSize = undefined;
93
+ /** @type {number|undefined} */
94
+ this._wrappedDescriptionFontSize = undefined;
85
95
  }
86
96
  /** @returns {Plane | null} The owning plane (direct or via a {@link Subplane} parent). */
87
97
  get plane() {
@@ -221,6 +231,8 @@ export class Connection {
221
231
  * @param {string|null} [spec.startArrowhead] Excalidraw arrowhead at the source side.
222
232
  * @param {string|null} [spec.endArrowhead] Excalidraw arrowhead at the target side.
223
233
  * @param {string|null} [spec.directionHint] Layout hint: up | down | left | right.
234
+ * @param {string} [spec.fromMul] Multiplicity label rendered next to the source endpoint.
235
+ * @param {string} [spec.toMul] Multiplicity label rendered next to the target endpoint.
224
236
  */
225
237
  constructor({
226
238
  id,
@@ -232,6 +244,8 @@ export class Connection {
232
244
  startArrowhead = null,
233
245
  endArrowhead = "arrow",
234
246
  directionHint = null,
247
+ fromMul = "",
248
+ toMul = "",
235
249
  }) {
236
250
  this.id = id;
237
251
  this.from = from;
@@ -245,6 +259,18 @@ export class Connection {
245
259
  this.endArrowhead = endArrowhead;
246
260
  /** @type {string|null} */
247
261
  this.directionHint = directionHint; // up|down|left|right|null
262
+ /**
263
+ * Multiplicity label rendered next to the source endpoint (e.g. `1`).
264
+ * Empty when no multiplicity was declared.
265
+ * @type {string}
266
+ */
267
+ this.fromMul = fromMul;
268
+ /**
269
+ * Multiplicity label rendered next to the target endpoint (e.g. `0..*`).
270
+ * Empty when no multiplicity was declared.
271
+ * @type {string}
272
+ */
273
+ this.toMul = toMul;
248
274
  /** @type {string|null} */
249
275
  this.fromSide = null;
250
276
  /** @type {string|null} */
@@ -156,15 +156,39 @@ export function createComponentContext() {
156
156
  },
157
157
 
158
158
  finalize() {
159
+ // Auto-vivify endpoints for connections that explicitly opted in
160
+ // (currently: class-diagram inheritance/realisation edges queued
161
+ // by `classBlockPlugin` for headers like
162
+ // `class Child extends Parent`, where the parent is implicitly
163
+ // declared). Generic component-style connections (`A --> B`) do
164
+ // *not* opt in, so the long-standing behaviour of dropping edges
165
+ // to undeclared boxes is preserved. Bracket/paren/quoted shorthand
166
+ // references (`[A]`, `(B)`, `"C"`) also never auto-vivify.
167
+ const ensureEndpoint = (
168
+ /** @type {string} */ id,
169
+ /** @type {boolean} */ shorthand,
170
+ /** @type {boolean} */ allowVivify,
171
+ ) => {
172
+ const existing = boxes.get(id);
173
+ if (existing) return existing;
174
+ if (shorthand || !allowVivify) return null;
175
+ const box = new Box({ id, title: id, shape: "class" });
176
+ boxes.set(id, box);
177
+ ensureFloatingPlane().addBox(box);
178
+ return box;
179
+ };
159
180
  // Resolve connections.
160
181
  for (const c of pendingConnections) {
161
- const fromBox = boxes.get(c.fromId);
162
- const toBox = boxes.get(c.toId);
182
+ const fromBox = ensureEndpoint(c.fromId, !!c.fromShorthand, !!c.allowVivify);
183
+ const toBox = ensureEndpoint(c.toId, !!c.toShorthand, !!c.allowVivify);
163
184
  if (!fromBox || !toBox || fromBox === toBox) continue;
164
185
  const [from, to] = c.reversed ? [toBox, fromBox] : [fromBox, toBox];
165
186
  const [startAh, endAh] = c.reversed
166
187
  ? [c.endArrowhead, c.startArrowhead]
167
188
  : [c.startArrowhead, c.endArrowhead];
189
+ const [fromMul, toMul] = c.reversed
190
+ ? [c.toMul || "", c.fromMul || ""]
191
+ : [c.fromMul || "", c.toMul || ""];
168
192
  diagram.addConnection(
169
193
  new Connection({
170
194
  id: `${c.fromId}->${c.toId}#${diagram.connections.length}`,
@@ -176,6 +200,8 @@ export function createComponentContext() {
176
200
  startArrowhead: startAh,
177
201
  endArrowhead: endAh,
178
202
  directionHint: c.directionHint,
203
+ fromMul,
204
+ toMul,
179
205
  }),
180
206
  );
181
207
  }
@@ -45,6 +45,7 @@ import {
45
45
  usecaseParensPlugin,
46
46
  shapeKeywordPlugin,
47
47
  } from "./plugins/component/shapes.mjs";
48
+ import { classBlockPlugin } from "./plugins/component/class_block.mjs";
48
49
  import { connectionPlugin } from "./plugins/component/connections.mjs";
49
50
  import { noteOfPlugin, noteFreePlugin, noteBlockPlugin } from "./plugins/component/notes.mjs";
50
51
 
@@ -74,7 +75,12 @@ export const DEFAULT_COMPONENT_PLUGINS = [
74
75
  noteBlockPlugin,
75
76
  noteOfPlugin,
76
77
  noteFreePlugin,
77
- shapeKeywordPlugin, // owns the class-block start
78
+ // class-diagram declarations (incl. `abstract class`, `interface`,
79
+ // `enum`, generics, `extends`, `implements`) — must run before the
80
+ // legacy `shapeKeywordPlugin` so the brace-form variants enter
81
+ // member-collection mode instead of being treated as containers.
82
+ classBlockPlugin,
83
+ shapeKeywordPlugin, // owns the legacy class-block start
78
84
  containerPlugin,
79
85
  bracketBoxPlugin,
80
86
  usecaseParensPlugin,