@diagc/cli 1.10.0 → 1.10.1

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.
@@ -28,5 +28,7 @@ export interface BoxContext {
28
28
  export declare function typeMark(type: string | undefined, shape: TextShape, glyphs: Glyphs): string | undefined;
29
29
  export declare function boxText(vn: ViewNode, ctx: BoxContext): BoxText;
30
30
  /** What an edge says beside its line: the relation's labels, or an aggregate's own
31
- * label, then a causal link's polarity and delay. Cut to `LABEL_MAX`. */
31
+ * label, then a causal link's polarity and delay. Cut to `LABEL_MAX`, except a kind
32
+ * whose label wraps (a transition), which goes on to more lines past `LABEL_LINE_MAX`
33
+ * cells, the lines joined by `\n`. */
32
34
  export declare function edgeText(edge: ViewEdge, glyphs: Glyphs): string;
@@ -1,4 +1,4 @@
1
- import { ACTIVITY_END_TYPE, FB_EFFECT_TYPE, SM_DEEP_HISTORY_TYPE, SM_ENTRY_TYPE, SM_EXIT_TYPE, SM_FINAL_TYPE, SM_HISTORY_TYPE, SM_JUNCTION_TYPE, SM_STATE_TYPE, SM_TERMINATE_TYPE, formatTransition, } from '@diagc/core/internal';
1
+ import { ACTIVITY_END_TYPE, FB_EFFECT_TYPE, SM_DEEP_HISTORY_TYPE, SM_ENTRY_TYPE, SM_EXIT_TYPE, SM_FINAL_TYPE, SM_HISTORY_TYPE, SM_JUNCTION_TYPE, SM_STATE_TYPE, SM_TERMINATE_TYPE, formatTransition, LABEL_LINE_MAX, labelLines, wrapsLabel, } from '@diagc/core/internal';
2
2
  import { subtitleOf, typeLook } from './vocabulary.js';
3
3
  import { cellWidth, fitCells, printable, wrapCells } from './width.js';
4
4
  /** The cells a name or subtitle wraps at: about what a browser box shows on a line. */
@@ -90,7 +90,9 @@ export function boxText(vn, ctx) {
90
90
  return { lines, width: widthOf(lines), height: lines.length + 2 + extra, shape: look.shape, dashed };
91
91
  }
92
92
  /** What an edge says beside its line: the relation's labels, or an aggregate's own
93
- * label, then a causal link's polarity and delay. Cut to `LABEL_MAX`. */
93
+ * label, then a causal link's polarity and delay. Cut to `LABEL_MAX`, except a kind
94
+ * whose label wraps (a transition), which goes on to more lines past `LABEL_LINE_MAX`
95
+ * cells, the lines joined by `\n`. */
94
96
  export function edgeText(edge, glyphs) {
95
97
  const said = edge.constituents.length === 1
96
98
  ? (edge.labels ?? [])
@@ -103,5 +105,8 @@ export function edgeText(edge, glyphs) {
103
105
  parts.push(`(${edge.polarity})`);
104
106
  if (edge.delay === true)
105
107
  parts.push(glyphs.delay);
106
- return fitCells(parts.filter((p) => p !== '').join(' '), LABEL_MAX, glyphs.ellipsis);
108
+ const text = parts.filter((p) => p !== '').join(' ');
109
+ if (wrapsLabel(edge.kind))
110
+ return labelLines(text, LABEL_LINE_MAX, cellWidth).join('\n');
111
+ return fitCells(text, LABEL_MAX, glyphs.ellipsis);
107
112
  }
@@ -9,10 +9,16 @@ export type BoxGeometry = CellRect;
9
9
  * slanted instead, one cell a row, and end on the line they meet. */
10
10
  export interface Route {
11
11
  points: CellPoint[];
12
+ /** the label's top left cell; a wrapped label's `text` holds its lines split by `\n` */
12
13
  label?: CellPoint & {
13
14
  text: string;
14
15
  };
15
16
  }
17
+ /** The cells a label takes: its widest line, and a row for each line. */
18
+ export declare function labelExtent(text: string): {
19
+ width: number;
20
+ height: number;
21
+ };
16
22
  /** What a fishbone is drawn with besides boxes and routes, where it is drawn as the
17
23
  * fish (fish.ts). */
18
24
  export interface FishDrawing {
@@ -1,6 +1,11 @@
1
1
  import ELK from 'elkjs/lib/elk.bundled.js';
2
2
  import { DOWN, LEFT, RIGHT, UP } from './glyphs.js';
3
3
  import { cellWidth } from './width.js';
4
+ /** The cells a label takes: its widest line, and a row for each line. */
5
+ export function labelExtent(text) {
6
+ const lines = text.split('\n');
7
+ return { width: Math.max(...lines.map(cellWidth)), height: lines.length };
8
+ }
4
9
  /**
5
10
  * elk `layered`, in character cells: a node is as big as its text, and the gaps
6
11
  * are a few cells. elk's options do not inherit into nested graphs, and every one it
@@ -70,7 +75,7 @@ function elkEdges(view, labels) {
70
75
  id: e.id,
71
76
  sources: [e.from],
72
77
  targets: [e.to],
73
- ...(text !== '' ? { labels: [{ text, width: cellWidth(text), height: 1 }] } : {}),
78
+ ...(text !== '' ? { labels: [{ text, ...labelExtent(text) }] } : {}),
74
79
  };
75
80
  });
76
81
  }
@@ -289,8 +294,10 @@ function normalize(boxes, routes) {
289
294
  for (const r of routes.values()) {
290
295
  for (const p of r.points)
291
296
  span(p.x, p.x, p.y, p.y);
292
- if (r.label !== undefined)
293
- span(r.label.x, r.label.x + cellWidth(r.label.text) - 1, r.label.y, r.label.y);
297
+ if (r.label !== undefined) {
298
+ const { width, height } = labelExtent(r.label.text);
299
+ span(r.label.x, r.label.x + width - 1, r.label.y, r.label.y + height - 1);
300
+ }
294
301
  }
295
302
  if (xs.length === 0)
296
303
  return { width: 0, height: 0, boxes, routes };
@@ -2,7 +2,7 @@ import { parseColor } from './ansi.js';
2
2
  import { Canvas } from './canvas.js';
3
3
  import { BLACK, castShadows, CYAN, DESKTOP, dosFill, dosSlots, inkOn, mixed, WHITE, YELLOW } from './dos.js';
4
4
  import { DOWN, LEFT, RIGHT, UP } from './glyphs.js';
5
- import { STEP, towardBox } from './layout.js';
5
+ import { labelExtent, STEP, towardBox, } from './layout.js';
6
6
  import { kindLook, typeLook } from './vocabulary.js';
7
7
  import { cellWidth } from './width.js';
8
8
  export const WEIGHT = { solid: 'light', dashed: 'dashed', heavy: 'heavy' };
@@ -304,6 +304,14 @@ const labelStyle = (p, edge) => {
304
304
  const { style } = edgeInk(p, edge);
305
305
  return p.dos === undefined ? style : { ...style, fg: YELLOW };
306
306
  };
307
+ /** A label's lines, one a row, each centred in the room the layout gave the widest. */
308
+ function drawLabel(p, label, style) {
309
+ const { width } = labelExtent(label.text);
310
+ label.text.split('\n').forEach((line, i) => {
311
+ const x = label.x + Math.floor((width - cellWidth(line)) / 2);
312
+ p.canvas.text({ x, y: label.y + i }, line, style);
313
+ });
314
+ }
307
315
  /**
308
316
  * The scene as a canvas, in layers: open containers' frames from the outside in,
309
317
  * then the edges' lines, then the boxes over them (a box clears what is under it)
@@ -347,7 +355,7 @@ export function paint(scene, options) {
347
355
  for (const edge of edges) {
348
356
  const label = layout.routes.get(edge.id).label;
349
357
  if (label !== undefined)
350
- p.canvas.text(label, label.text, labelStyle(p, edge));
358
+ drawLabel(p, label, labelStyle(p, edge));
351
359
  drawEnd(p, edge, 'start');
352
360
  drawEnd(p, edge, 'end');
353
361
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagc/cli",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "Bogdan Frankovskyi",
@@ -45,7 +45,7 @@
45
45
  "fast-glob": "^3.3.0",
46
46
  "jiti": "^2.0.0",
47
47
  "playwright-core": "^1.62.0",
48
- "@diagc/core": "1.10.0"
48
+ "@diagc/core": "1.10.1"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"