@adecore/diagram 0.23.1 → 0.24.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { type NodeBox, type GroupBox, type EdgeLabelBox, type EdgeRoute, type DiagramLayout, NODE_MAX_WIDTH, CYLINDER_LID, EDGE_LABEL_MAX_WIDTH, EDGE_LABEL_PADDING, GROUP_PADDING, GROUP_LABEL_BAND, GROUP_LABEL_INSET, type NodeSize, sizeOfNode, sizeOfEdgeLabel, layersOf, layoutOf, LABEL_LINE, LABEL_SIZE, SUB_LINE, SUB_SIZE, estimateTextWidth, wrapText, type Point, type Rect } from './layout.ts';
1
+ export { type NodeBox, type GroupBox, type EdgeLabelBox, type EdgeRoute, type DiagramLayout, GROUP_LABEL_BAND, layoutOf, type Point, type Rect } from './layout.ts';
2
+ export { LABEL_SIZE, SUB_SIZE } from './text.ts';
2
3
  export { readingOrder } from './reading-order.ts';
3
4
  export { type ShapePaths, shapePaths, type TextLine, textLinesOf, edgeLabelLinesOf, edgePath, arrowHeadPath, dashOf } from './shapes.ts';
4
5
  export { type DiagramSvgOptions, DEFAULT_DIAGRAM_MARGIN, DEFAULT_NODE_TONE, DEFAULT_GROUP_TONE, DEFAULT_EDGE_TONE, toSvg } from './svg.ts';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export { NODE_MAX_WIDTH, CYLINDER_LID, EDGE_LABEL_MAX_WIDTH, EDGE_LABEL_PADDING, GROUP_PADDING, GROUP_LABEL_BAND, GROUP_LABEL_INSET, sizeOfNode, sizeOfEdgeLabel, layersOf, layoutOf, LABEL_LINE, LABEL_SIZE, SUB_LINE, SUB_SIZE, estimateTextWidth, wrapText } from './layout.js';
1
+ export { GROUP_LABEL_BAND, layoutOf } from './layout.js';
2
+ export { LABEL_SIZE, SUB_SIZE } from './text.js';
2
3
  export { readingOrder } from './reading-order.js';
3
4
  export { shapePaths, textLinesOf, edgeLabelLinesOf, edgePath, arrowHeadPath, dashOf } from './shapes.js';
4
5
  export { DEFAULT_DIAGRAM_MARGIN, DEFAULT_NODE_TONE, DEFAULT_GROUP_TONE, DEFAULT_EDGE_TONE, toSvg } from './svg.js';
package/dist/layout.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { DiagramDocument, DiagramEdge, DiagramNode } from './protocol.ts';
2
2
  import { type Point, type Rect } from '@adecore/drawing';
3
- export { LABEL_LINE, LABEL_SIZE, SUB_LINE, SUB_SIZE, estimateTextWidth, wrapText } from './text.ts';
4
3
  export type { Point, Rect } from '@adecore/drawing';
5
4
  export interface NodeBox extends Rect {
6
5
  id: string;
@@ -29,16 +28,12 @@ export interface DiagramLayout {
29
28
  edges: EdgeRoute[];
30
29
  bounds: Rect;
31
30
  }
32
- export declare const NODE_MAX_WIDTH = 280;
33
31
  export declare const CYLINDER_LID = 10;
34
- export declare const EDGE_LABEL_MAX_WIDTH = 160;
35
32
  export declare const EDGE_LABEL_PADDING: {
36
33
  x: number;
37
34
  y: number;
38
35
  };
39
- export declare const GROUP_PADDING = 20;
40
36
  export declare const GROUP_LABEL_BAND = 24;
41
- export declare const GROUP_LABEL_INSET = 12;
42
37
  export interface NodeSize {
43
38
  w: number;
44
39
  h: number;
@@ -46,10 +41,5 @@ export interface NodeSize {
46
41
  sub: string[];
47
42
  }
48
43
  export declare function sizeOfNode(node: Pick<DiagramNode, 'label' | 'sub' | 'shape'>): NodeSize;
49
- export declare function sizeOfEdgeLabel(text: string): {
50
- w: number;
51
- h: number;
52
- lines: string[];
53
- };
54
44
  export declare function layersOf(nodes: readonly Pick<DiagramNode, 'id'>[], edges: readonly Pick<DiagramEdge, 'from' | 'to'>[]): Map<string, number>;
55
45
  export declare function layoutOf(document: Pick<DiagramDocument, 'meta' | 'nodes' | 'groups' | 'edges'>): DiagramLayout;
package/dist/layout.js CHANGED
@@ -4,23 +4,22 @@ import { DUMMY_MARGIN, NODE_MARGIN, bandCode } from './graph.js';
4
4
  import { orderLayers } from './order.js';
5
5
  import { routeChannel } from './route.js';
6
6
  import { LABEL_LINE, LABEL_SIZE, SUB_LINE, SUB_SIZE, estimateTextWidth, widestLine, wrapText } from './text.js';
7
- export { LABEL_LINE, LABEL_SIZE, SUB_LINE, SUB_SIZE, estimateTextWidth, wrapText } from './text.js';
8
7
  const NODE_PADDING_X = 16;
9
8
  const NODE_PADDING_Y = 13;
10
9
  const NODE_MIN_WIDTH = 120;
11
- export const NODE_MAX_WIDTH = 280;
10
+ const NODE_MAX_WIDTH = 280;
12
11
  const TEXT_MAX_WIDTH = NODE_MAX_WIDTH - NODE_PADDING_X * 2;
13
12
  /* A diamond holds its text in the middle of its box, so its lines are shorter and the box is twice their size. */
14
13
  const DIAMOND_TEXT_MAX_WIDTH = 160;
15
14
  const DIAMOND_MIN = { w: 168, h: 72 };
16
15
  /* The extra height of a cylinder, for the lid its text stays under. */
17
16
  export const CYLINDER_LID = 10;
18
- export const EDGE_LABEL_MAX_WIDTH = 160;
17
+ const EDGE_LABEL_MAX_WIDTH = 160;
19
18
  export const EDGE_LABEL_PADDING = { x: 4, y: 2 };
20
- export const GROUP_PADDING = 20;
19
+ const GROUP_PADDING = 20;
21
20
  /* The band on top of a group where its label sits. */
22
21
  export const GROUP_LABEL_BAND = 24;
23
- export const GROUP_LABEL_INSET = 12;
22
+ const GROUP_LABEL_INSET = 12;
24
23
  /* Room between a layer's widest box and the first thing in the channel after it. */
25
24
  const EDGE_CLEAR = 20;
26
25
  /* How far a loop on one node reaches out of its box. */
@@ -54,7 +53,7 @@ export function sizeOfNode(node) {
54
53
  return { w: even(Math.max(NODE_MIN_WIDTH, textWidth + paddingX * 2)), h: even(h), label, sub };
55
54
  }
56
55
  /* The box of an edge's label before it is placed: wrapped narrower than a node, on a padding of its own. */
57
- export function sizeOfEdgeLabel(text) {
56
+ function sizeOfEdgeLabel(text) {
58
57
  const lines = wrapText(text, SUB_SIZE, false, EDGE_LABEL_MAX_WIDTH);
59
58
  return {
60
59
  w: even(widestLine(lines, SUB_SIZE, false) + EDGE_LABEL_PADDING.x * 2),
package/dist/svg.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEFAULT_FONT_STACKS, DEFAULT_PALETTE, DEFAULT_PAPER } from '@adecore/drawing';
1
+ import { DEFAULT_FONT_STACKS, DEFAULT_PALETTE, DEFAULT_PAPER, escapeXml } from '@adecore/drawing';
2
2
  import { GROUP_LABEL_BAND, layoutOf } from './layout.js';
3
3
  import { arrowHeadPath, dashOf, edgeLabelLinesOf, edgePath, shapePaths, textLinesOf } from './shapes.js';
4
4
  import { SUB_SIZE } from './text.js';
@@ -7,12 +7,6 @@ export const DEFAULT_DIAGRAM_MARGIN = 32;
7
7
  export const DEFAULT_NODE_TONE = 'ink';
8
8
  export const DEFAULT_GROUP_TONE = 'muted';
9
9
  export const DEFAULT_EDGE_TONE = 'muted';
10
- // XML has no way to write a control character other than tab and the line breaks, not even escaped.
11
- // oxlint-disable-next-line no-control-regex
12
- const NOT_XML = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g;
13
- function escapeXml(value) {
14
- return value.replace(NOT_XML, '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
15
- }
16
10
  /* The whole diagram as one SVG string, from the same layout and paths a view draws with its own elements. */
17
11
  export function toSvg(document, options = {}) {
18
12
  const palette = options.palette ?? DEFAULT_PALETTE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/diagram",
3
- "version": "0.23.1",
3
+ "version": "0.24.1",
4
4
  "description": "Directed graph schemas, layered layout, SVG export and reading order.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "author": "Bas Milius",
@@ -19,6 +19,7 @@
19
19
  "dist",
20
20
  "src",
21
21
  "!src/**/*.test.ts",
22
+ "!src/**/__snapshots__",
22
23
  "!src/fixtures"
23
24
  ],
24
25
  "exports": {
@@ -44,7 +45,7 @@
44
45
  "typescript": "^7.0.2"
45
46
  },
46
47
  "dependencies": {
47
- "@adecore/drawing": "0.23.1",
48
+ "@adecore/drawing": "0.24.1",
48
49
  "zod": "^4.6.5"
49
50
  }
50
51
  }
package/src/index.ts CHANGED
@@ -4,27 +4,12 @@ export {
4
4
  type EdgeLabelBox,
5
5
  type EdgeRoute,
6
6
  type DiagramLayout,
7
- NODE_MAX_WIDTH,
8
- CYLINDER_LID,
9
- EDGE_LABEL_MAX_WIDTH,
10
- EDGE_LABEL_PADDING,
11
- GROUP_PADDING,
12
7
  GROUP_LABEL_BAND,
13
- GROUP_LABEL_INSET,
14
- type NodeSize,
15
- sizeOfNode,
16
- sizeOfEdgeLabel,
17
- layersOf,
18
8
  layoutOf,
19
- LABEL_LINE,
20
- LABEL_SIZE,
21
- SUB_LINE,
22
- SUB_SIZE,
23
- estimateTextWidth,
24
- wrapText,
25
9
  type Point,
26
10
  type Rect
27
11
  } from './layout.ts';
12
+ export { LABEL_SIZE, SUB_SIZE } from './text.ts';
28
13
  export { readingOrder } from './reading-order.ts';
29
14
  export { type ShapePaths, shapePaths, type TextLine, textLinesOf, edgeLabelLinesOf, edgePath, arrowHeadPath, dashOf } from './shapes.ts';
30
15
  export { type DiagramSvgOptions, DEFAULT_DIAGRAM_MARGIN, DEFAULT_NODE_TONE, DEFAULT_GROUP_TONE, DEFAULT_EDGE_TONE, toSvg } from './svg.ts';
package/src/layout.ts CHANGED
@@ -6,8 +6,6 @@ import { orderLayers } from './order.ts';
6
6
  import { routeChannel, type ChannelHop, type ChannelLabel } from './route.ts';
7
7
  import { LABEL_LINE, LABEL_SIZE, SUB_LINE, SUB_SIZE, estimateTextWidth, widestLine, wrapText } from './text.ts';
8
8
 
9
- export { LABEL_LINE, LABEL_SIZE, SUB_LINE, SUB_SIZE, estimateTextWidth, wrapText } from './text.ts';
10
-
11
9
  export type { Point, Rect } from '@adecore/drawing';
12
10
 
13
11
  export interface NodeBox extends Rect {
@@ -56,19 +54,19 @@ export interface DiagramLayout {
56
54
  const NODE_PADDING_X = 16;
57
55
  const NODE_PADDING_Y = 13;
58
56
  const NODE_MIN_WIDTH = 120;
59
- export const NODE_MAX_WIDTH = 280;
57
+ const NODE_MAX_WIDTH = 280;
60
58
  const TEXT_MAX_WIDTH = NODE_MAX_WIDTH - NODE_PADDING_X * 2;
61
59
  /* A diamond holds its text in the middle of its box, so its lines are shorter and the box is twice their size. */
62
60
  const DIAMOND_TEXT_MAX_WIDTH = 160;
63
61
  const DIAMOND_MIN = { w: 168, h: 72 };
64
62
  /* The extra height of a cylinder, for the lid its text stays under. */
65
63
  export const CYLINDER_LID = 10;
66
- export const EDGE_LABEL_MAX_WIDTH = 160;
64
+ const EDGE_LABEL_MAX_WIDTH = 160;
67
65
  export const EDGE_LABEL_PADDING = { x: 4, y: 2 };
68
- export const GROUP_PADDING = 20;
66
+ const GROUP_PADDING = 20;
69
67
  /* The band on top of a group where its label sits. */
70
68
  export const GROUP_LABEL_BAND = 24;
71
- export const GROUP_LABEL_INSET = 12;
69
+ const GROUP_LABEL_INSET = 12;
72
70
  /* Room between a layer's widest box and the first thing in the channel after it. */
73
71
  const EDGE_CLEAR = 20;
74
72
  /* How far a loop on one node reaches out of its box. */
@@ -112,7 +110,7 @@ export function sizeOfNode(node: Pick<DiagramNode, 'label' | 'sub' | 'shape'>):
112
110
  }
113
111
 
114
112
  /* The box of an edge's label before it is placed: wrapped narrower than a node, on a padding of its own. */
115
- export function sizeOfEdgeLabel(text: string): { w: number; h: number; lines: string[] } {
113
+ function sizeOfEdgeLabel(text: string): { w: number; h: number; lines: string[] } {
116
114
  const lines = wrapText(text, SUB_SIZE, false, EDGE_LABEL_MAX_WIDTH);
117
115
  return {
118
116
  w: even(widestLine(lines, SUB_SIZE, false) + EDGE_LABEL_PADDING.x * 2),
package/src/svg.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { DrawingColor } from '@adecore/drawing/protocol';
2
2
  import type { DiagramDocument } from './protocol.ts';
3
- import { DEFAULT_FONT_STACKS, DEFAULT_PALETTE, DEFAULT_PAPER } from '@adecore/drawing';
3
+ import { DEFAULT_FONT_STACKS, DEFAULT_PALETTE, DEFAULT_PAPER, escapeXml } from '@adecore/drawing';
4
4
  import { GROUP_LABEL_BAND, layoutOf, type DiagramLayout } from './layout.ts';
5
5
  import { arrowHeadPath, dashOf, edgeLabelLinesOf, edgePath, shapePaths, textLinesOf } from './shapes.ts';
6
6
  import { SUB_SIZE } from './text.ts';
@@ -26,14 +26,6 @@ export const DEFAULT_NODE_TONE: DrawingColor = 'ink';
26
26
  export const DEFAULT_GROUP_TONE: DrawingColor = 'muted';
27
27
  export const DEFAULT_EDGE_TONE: DrawingColor = 'muted';
28
28
 
29
- // XML has no way to write a control character other than tab and the line breaks, not even escaped.
30
- // oxlint-disable-next-line no-control-regex
31
- const NOT_XML = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g;
32
-
33
- function escapeXml(value: string): string {
34
- return value.replace(NOT_XML, '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
35
- }
36
-
37
29
  /* The whole diagram as one SVG string, from the same layout and paths a view draws with its own elements. */
38
30
  export function toSvg(document: Pick<DiagramDocument, 'meta' | 'nodes' | 'groups' | 'edges'>, options: DiagramSvgOptions = {}): string {
39
31
  const palette = options.palette ?? DEFAULT_PALETTE;