@zukhruf/diagram 0.3.33 → 0.3.35

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.
Files changed (117) hide show
  1. package/README.md +98 -52
  2. package/dist/index.d.ts +5 -3
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/compiler/diagram-compile.d.ts +3 -4
  7. package/dist/lib/compiler/diagram-compile.d.ts.map +1 -1
  8. package/dist/lib/compiler/diagram-compile.js +85 -370
  9. package/dist/lib/compiler/diagram-compile.js.map +1 -1
  10. package/dist/lib/layouts/graph/attach.d.ts.map +1 -1
  11. package/dist/lib/layouts/graph/attach.js +64 -8
  12. package/dist/lib/layouts/graph/attach.js.map +1 -1
  13. package/dist/lib/layouts/graph/connections.d.ts +11 -4
  14. package/dist/lib/layouts/graph/connections.d.ts.map +1 -1
  15. package/dist/lib/layouts/graph/connections.js +43 -17
  16. package/dist/lib/layouts/graph/connections.js.map +1 -1
  17. package/dist/lib/layouts/graph/graph-layout-result.d.ts +4 -2
  18. package/dist/lib/layouts/graph/graph-layout-result.d.ts.map +1 -1
  19. package/dist/lib/layouts/graph/graph-layout-result.js.map +1 -1
  20. package/dist/lib/layouts/graph/gutters.js +40 -21
  21. package/dist/lib/layouts/graph/gutters.js.map +1 -1
  22. package/dist/lib/layouts/graph/labels.d.ts +16 -9
  23. package/dist/lib/layouts/graph/labels.d.ts.map +1 -1
  24. package/dist/lib/layouts/graph/labels.js +62 -18
  25. package/dist/lib/layouts/graph/labels.js.map +1 -1
  26. package/dist/lib/layouts/graph/layout.d.ts +1 -1
  27. package/dist/lib/layouts/graph/layout.d.ts.map +1 -1
  28. package/dist/lib/layouts/graph/layout.js +6 -3
  29. package/dist/lib/layouts/graph/layout.js.map +1 -1
  30. package/dist/lib/layouts/graph/measure.d.ts +8 -5
  31. package/dist/lib/layouts/graph/measure.d.ts.map +1 -1
  32. package/dist/lib/layouts/graph/measure.js +47 -9
  33. package/dist/lib/layouts/graph/measure.js.map +1 -1
  34. package/dist/lib/layouts/graph/min-heap.d.ts +1 -5
  35. package/dist/lib/layouts/graph/min-heap.d.ts.map +1 -1
  36. package/dist/lib/layouts/graph/min-heap.js +1 -5
  37. package/dist/lib/layouts/graph/min-heap.js.map +1 -1
  38. package/dist/lib/layouts/graph/node-content.d.ts +1 -1
  39. package/dist/lib/layouts/graph/node-content.d.ts.map +1 -1
  40. package/dist/lib/layouts/graph/node-content.js +26 -7
  41. package/dist/lib/layouts/graph/node-content.js.map +1 -1
  42. package/dist/lib/layouts/graph/path.d.ts +2 -10
  43. package/dist/lib/layouts/graph/path.d.ts.map +1 -1
  44. package/dist/lib/layouts/graph/path.js +11 -13
  45. package/dist/lib/layouts/graph/path.js.map +1 -1
  46. package/dist/lib/layouts/graph/round.d.ts +11 -0
  47. package/dist/lib/layouts/graph/round.d.ts.map +1 -0
  48. package/dist/lib/layouts/graph/round.js +181 -0
  49. package/dist/lib/layouts/graph/round.js.map +1 -0
  50. package/dist/lib/layouts/graph/route.d.ts +10 -6
  51. package/dist/lib/layouts/graph/route.d.ts.map +1 -1
  52. package/dist/lib/layouts/graph/route.js +68 -33
  53. package/dist/lib/layouts/graph/route.js.map +1 -1
  54. package/dist/lib/layouts/graph/sides.d.ts +10 -5
  55. package/dist/lib/layouts/graph/sides.d.ts.map +1 -1
  56. package/dist/lib/layouts/graph/sides.js +14 -7
  57. package/dist/lib/layouts/graph/sides.js.map +1 -1
  58. package/dist/lib/layouts/timeline/timeline-layout.d.ts +2 -1
  59. package/dist/lib/layouts/timeline/timeline-layout.d.ts.map +1 -1
  60. package/dist/lib/layouts/timeline/timeline-layout.js +9 -4
  61. package/dist/lib/layouts/timeline/timeline-layout.js.map +1 -1
  62. package/dist/lib/model/diagram-ir.d.ts +19 -156
  63. package/dist/lib/model/diagram-ir.d.ts.map +1 -1
  64. package/dist/lib/model/diagram-ir.js.map +1 -1
  65. package/dist/lib/model/validate-graph.d.ts +7 -0
  66. package/dist/lib/model/validate-graph.d.ts.map +1 -0
  67. package/dist/lib/model/validate-graph.js +54 -0
  68. package/dist/lib/model/validate-graph.js.map +1 -0
  69. package/dist/lib/react/Diagram.d.ts +3 -9
  70. package/dist/lib/react/Diagram.d.ts.map +1 -1
  71. package/dist/lib/react/Diagram.js +1 -13
  72. package/dist/lib/react/Diagram.js.map +1 -1
  73. package/dist/lib/react/diagram-types.d.ts +17 -46
  74. package/dist/lib/react/diagram-types.d.ts.map +1 -1
  75. package/dist/lib/react/diagram-types.js.map +1 -1
  76. package/dist/lib/renderers/canvas/graph-canvas.d.ts +2 -5
  77. package/dist/lib/renderers/canvas/graph-canvas.d.ts.map +1 -1
  78. package/dist/lib/renderers/canvas/graph-canvas.js +68 -43
  79. package/dist/lib/renderers/canvas/graph-canvas.js.map +1 -1
  80. package/dist/lib/renderers/html/graph-html.d.ts +2 -3
  81. package/dist/lib/renderers/html/graph-html.d.ts.map +1 -1
  82. package/dist/lib/renderers/html/graph-html.js +298 -289
  83. package/dist/lib/renderers/html/graph-html.js.map +1 -1
  84. package/dist/lib/renderers/shared/graph-parts.d.ts +3 -1
  85. package/dist/lib/renderers/shared/graph-parts.d.ts.map +1 -1
  86. package/dist/lib/renderers/shared/graph-parts.js +350 -418
  87. package/dist/lib/renderers/shared/graph-parts.js.map +1 -1
  88. package/dist/lib/renderers/shared/node-parts.d.ts +5 -6
  89. package/dist/lib/renderers/shared/node-parts.d.ts.map +1 -1
  90. package/dist/lib/renderers/shared/node-parts.js +112 -190
  91. package/dist/lib/renderers/shared/node-parts.js.map +1 -1
  92. package/dist/lib/renderers/shared/run-spans.js +2 -2
  93. package/dist/lib/renderers/shared/run-spans.js.map +1 -1
  94. package/dist/lib/renderers/shared/text-runs.d.ts +0 -6
  95. package/dist/lib/renderers/shared/text-runs.d.ts.map +1 -1
  96. package/dist/lib/renderers/shared/text-runs.js +0 -12
  97. package/dist/lib/renderers/shared/text-runs.js.map +1 -1
  98. package/dist/lib/renderers/svg/graph-svg.d.ts +1 -3
  99. package/dist/lib/renderers/svg/graph-svg.d.ts.map +1 -1
  100. package/dist/lib/renderers/svg/graph-svg.js +66 -80
  101. package/dist/lib/renderers/svg/graph-svg.js.map +1 -1
  102. package/dist/lib/renderers/svg/timeline-svg.d.ts.map +1 -1
  103. package/dist/lib/renderers/svg/timeline-svg.js +7 -5
  104. package/dist/lib/renderers/svg/timeline-svg.js.map +1 -1
  105. package/package.json +1 -1
  106. package/dist/lib/layouts/graph/graph-layout.d.ts +0 -154
  107. package/dist/lib/layouts/graph/graph-layout.d.ts.map +0 -1
  108. package/dist/lib/layouts/graph/graph-layout.js +0 -2340
  109. package/dist/lib/layouts/graph/graph-layout.js.map +0 -1
  110. package/dist/lib/layouts/graph/legacy-graph-layout.d.ts +0 -6
  111. package/dist/lib/layouts/graph/legacy-graph-layout.d.ts.map +0 -1
  112. package/dist/lib/layouts/graph/legacy-graph-layout.js +0 -542
  113. package/dist/lib/layouts/graph/legacy-graph-layout.js.map +0 -1
  114. package/dist/lib/layouts/text-metrics.d.ts +0 -7
  115. package/dist/lib/layouts/text-metrics.d.ts.map +0 -1
  116. package/dist/lib/layouts/text-metrics.js +0 -40
  117. package/dist/lib/layouts/text-metrics.js.map +0 -1
package/README.md CHANGED
@@ -125,7 +125,7 @@ Two props also change the look:
125
125
  - `accent`: the highlight color. It is `green` (the default), `primary`, `neutral`, or a CSS color.
126
126
  - `stylePreset`: `default`, or `sketch`. The `sketch` preset draws black ink on white, and makes each tone the same gray.
127
127
 
128
- The SVG text uses the font `ui-monospace, 'Geist Mono', monospace`. The layout calculates the width of a label from the widths of a monospace font.
128
+ The text uses the fonts Geist Sans and Geist Mono. The stylesheet loads them from `@fontsource/geist-sans` and `@fontsource/geist-mono`, which install with the package. The graph layout measures each text with a table of the glyph widths of these fonts. Thus the text fits its box on each operating system and in server rendering. See [ADR 0003](./docs/adr/0003-the-graph-layout-is-a-content-sized-grid.md).
129
129
 
130
130
  ## Effects
131
131
 
@@ -154,10 +154,10 @@ The source of truth is `src/lib/react/Diagram.tsx`, `src/lib/react/diagram-types
154
154
 
155
155
  The renderer sets the layout. `SvgGraphDiagram`, `CanvasGraphDiagram` and `HtmlGraphDiagram` draw a **graph**. `SvgTimelineDiagram` draws a **timeline**.
156
156
 
157
- - **Graph primitives:** `Node`, `Box`, `Card`, `Port`, `Label`, `Float`, `Phantom`, `Marker`, `Appliance`, `Connector`, `Junction`, `Edge`, `Arrow`, `Wire`, `Group`, `Guide`, `Text`, `Note`.
157
+ - **Graph primitives:** `Node`, `Box`, `Card`, `Port`, `Label`, `Float`, `Marker`, `Appliance`, `Connector`, `Junction`, `Note`, `Edge`, `Arrow`, `Wire`, `Group`, `Content`.
158
158
  - **Timeline primitives:** `Lane`, `Signal`, `Frame`.
159
159
 
160
- `Line` makes a label with more than one line, in both layouts. `Content` goes into a `Box`, a `Card` or a `Node`, one time. `Waypoint`, `Entry` and `Exit` go into an edge.
160
+ `Line` makes a label with more than one line, in both layouts. `Content` goes into a `Box`, a `Card` or a `Node`, one time.
161
161
 
162
162
  ### Timeline primitives
163
163
 
@@ -182,28 +182,44 @@ The layout splits the line into two stubs. The stub at the source has no arrowhe
182
182
 
183
183
  ### Graph primitives
184
184
 
185
- Each node has an `id`, and a `row` and a `col` in the grid. `colSpan`, `width` and `height` change its size.
186
-
187
- | Primitive | What it is | Default frame | Notes |
188
- | ------------------- | ----------------------------------------------------------- | ------------- | --------------------------------------------------------------------- |
189
- | `Diagram.Node` | The general node | `solid` | Prefer `Box` or `Card`. |
190
- | `Diagram.Box` | A node with a solid border and centered text | `solid` | The usual node. |
191
- | `Diagram.Card` | A node with a solid border and text that starts at the left | `solid` | For a node with a `description` or `items`. |
192
- | `Diagram.Port` | A node with no header | `transparent` | Often holds a set of labels under a box. |
193
- | `Diagram.Label` | Text at a grid position | `none` | For a section title or the label of an axis. |
194
- | `Diagram.Float` | A flat node | `flat` | An edge cannot attach to it. |
195
- | `Diagram.Phantom` | A node that is not visible | `none` | An edge can attach to it. Use it to make an edge go through one cell. |
196
- | `Diagram.Marker` | A node with an `icon`, for example `server` or `user` | `none` | The icon is required. |
197
- | `Diagram.Appliance` | A hardware device | `none` | `appliancePorts`, `antenna` and `slant` change the drawing. |
198
- | `Diagram.Connector` | A small node with round corners and an optional `icon` | `solid` | The default size is 148 × 40. |
199
- | `Diagram.Junction` | A small circle where edges meet | `none` | The default size is 16 × 16. |
185
+ A graph is a grid of cells. Give each node an `id`, and a `row` and a `col`: integers from 0. `rowSpan` and `colSpan` let a node cover more cells. One node at most is in a cell. You do not give sizes in pixels. The layout measures the content of each node, and gives each row and each column the size of its largest content.
186
+
187
+ | Primitive | What it is | Default frame | Size |
188
+ | ------------------- | ----------------------------------------------------------- | ------------- | --------------------------------------- |
189
+ | `Diagram.Node` | The general node | `solid` | Fills its area. Prefer `Box` or `Card`. |
190
+ | `Diagram.Box` | A node with a solid border and centered text | `solid` | Fills its area. The usual node. |
191
+ | `Diagram.Card` | A node with a solid border and text that starts at the left | `solid` | Fills its area. |
192
+ | `Diagram.Port` | A node with no header | `transparent` | Fills its area. |
193
+ | `Diagram.Label` | Text at a grid position | `none` | Fills its area. |
194
+ | `Diagram.Float` | A flat node. An edge cannot attach to it. | `flat` | Fills its area. |
195
+ | `Diagram.Marker` | A node with an `icon`, for example `server` or `user` | `none` | Its own size. The icon is required. |
196
+ | `Diagram.Appliance` | A hardware device | `none` | Its own size. |
197
+ | `Diagram.Connector` | A small node with round corners and an optional `icon` | `solid` | Its own size. |
198
+ | `Diagram.Junction` | A small circle where edges meet | `none` | Its own size. |
199
+ | `Diagram.Note` | Text with no frame, with an optional leader to a `target` | `none` | Its own size. |
200
+
201
+ A node that keeps its own size goes at the center of its area.
200
202
 
201
203
  Other props of a node:
202
204
 
203
- - `tone`, `texture` and `accent` set its colors.
205
+ - `tone`, `texture` and `accent` set its colors. `frame` sets its border.
206
+ - `description` and `items` add text under the title of a card.
204
207
  - `caption` puts text next to the node, on the side that `captionSide` sets.
205
- - `ports` gives node ports: named points on a side, where an edge can attach.
206
- - `stack` draws copies of the frame behind the node, for a set of equal items.
208
+ - `ports` gives node ports: named points on a side, where an edge can attach. When a side has ports, each edge to that side must name a port.
209
+ - `stack` draws copies of the frame behind the node, for a set of equal items. `stackDirection` sets where the copies go.
210
+ - `appliancePorts` and `antenna` change the drawing of an appliance.
211
+
212
+ A note explains a node or a group. With a `target`, the layout draws a leader from the note to it:
213
+
214
+ ```tsx
215
+ <Diagram.Box id="cert-manager" row={2} col={5}>
216
+ cert-manager
217
+ </Diagram.Box>
218
+ <Diagram.Note id="cert-note" row={2} col={7} target="cert-manager">
219
+ <Diagram.Line>Manages</Diagram.Line>
220
+ <Diagram.Line>certificates</Diagram.Line>
221
+ </Diagram.Note>
222
+ ```
207
223
 
208
224
  ### Edges
209
225
 
@@ -213,45 +229,72 @@ Other props of a node:
213
229
  | `Diagram.Wire` | An edge with no arrowhead | No | When the direction is clear or the same both ways. |
214
230
  | `Diagram.Edge` | The general edge; set `headless` yourself | You select it | Prefer `Arrow` or `Wire`. |
215
231
 
216
- The required props are `from` and `to`. Other props: `lineStyle` (`solid`, `dashed`, `dotted`), `direction` (`forward`, `both`, `none`), `route` (`orthogonal`, `straight`), `dim`, `accent`, the `label*` props, and the `badge*` props for an icon on the edge.
232
+ The required props are `from` and `to`. Each is the id of a node or a group, or `id:port` for a node port. The other props are:
217
233
 
218
- An edge accepts these children: text and `Diagram.Line` for its label, and `Diagram.Entry`, `Diagram.Exit` and `Diagram.Waypoint`.
234
+ - `lineStyle` (`solid`, `dashed`, `dotted`), `direction` (`forward`, `both`, `none`), `weight` (`regular`, `bold`), `dim`, `accent`, and `headless`.
235
+ - `exitSide` and `entrySide` (`top`, `right`, `bottom`, `left`): the side of the source where the edge goes out, and the side of the target where it goes in.
236
+ - `layer` (`background`, `foreground`): whether the edge draws below or above the nodes.
237
+ - `labelFrame`: a box around the label.
238
+ - `badgeIcon` and `badgeLabel`: an icon on the edge.
239
+ - `channel`: a name that the layout copies to the `data-diagram-edge-channel` attribute.
219
240
 
220
- ### Groups
241
+ The text children and the `Diagram.Line` children of an edge are its label.
221
242
 
222
- `Diagram.Group` draws a rectangle around a set of nodes. Put the nodes in it as children, or give each node a `group` prop.
243
+ The router in `src/lib/layouts/graph/route.ts` selects each path:
223
244
 
224
- The required prop is `id`. The optional props are `label`, `accent`, `tone`, `texture`, `rx` (the corner radius), `tight` (bounds that fit the nodes closely), `padding`, `dividers`, `frame` (`solid`, `dashed`, `none`), and `rowStart`, `rowEnd`, `colStart`, `colEnd` (the bounds). When you do not give the bounds, the compiler calculates them from the rows and columns of the nodes.
245
+ - Each path is orthogonal. The router finds it with A\*, and it goes around the nodes, the captions, the group labels, and the labels of the edges that routed before it.
246
+ - The router routes the nearest edges first.
247
+ - When you do not give `exitSide` and `entrySide`, the router selects the sides from the cells of the two ends.
248
+ - The edges on one side of a node divide that side into equal slots, in the order of their other ends, so they do not cross.
249
+ - The router puts each label beside the longest segment of its edge, at the first free position.
225
250
 
226
- ### Edge routing
251
+ The layout throws when an edge has no route, or when a label has no free position. Each error names the edge. Then give `exitSide` or `entrySide`, move a node to a different cell, or split the diagram. When the problem is general, fix the router. See [the internals](./docs/internals.md).
252
+
253
+ ### Groups
227
254
 
228
- | Primitive | What it does |
229
- | ------------------ | --------------------------------------------------------------------------------------- |
230
- | `Diagram.Entry` | Sets the side of the target where the edge goes in: `top`, `right`, `bottom` or `left`. |
231
- | `Diagram.Exit` | Sets the side of the source where the edge goes out. |
232
- | `Diagram.Waypoint` | Gives a point that the edge goes through: `{ x, y }`, a grid cell, a guide, or a node. |
255
+ `Diagram.Group` draws a rectangle around a set of nodes. Put the nodes in it as children. A group can be in a group.
233
256
 
234
- Use them when the router draws a crossing, or draws an edge around a node.
257
+ The required prop is `id`. The optional props are `label`, `labelAlign`, `labelSide` (`top`, `bottom`), `titleBand` (a band behind the label), `accent`, `tone`, `texture`, `fill`, `frame` (`solid`, `dashed`, `none`), `ports`, and `dividers` (a line through each gutter in the group).
235
258
 
236
- The router in `src/lib/layouts/graph/graph-layout.ts` does these things:
259
+ The area of a group is the smallest area that holds its members. To give a larger area, set `row`, `col`, `rowSpan` and `colSpan`:
237
260
 
238
- - A self-edge (`from` is the same as `to`) is a loop around the node. The default loop is above the node. `Exit` and `Entry` can select a different side.
239
- - Two edges in the same row that go in opposite directions get two lanes. For example, `running → paused` stays direct, and `paused → running` goes below the nodes.
240
- - An edge in the same row that goes from right to left goes below the row, not across the top of the row.
241
- - Return edges from the same source to the same side get different corridors. A longer return, for example `paused → idle`, goes deeper than a shorter return, for example `paused → running`.
242
- - The router puts each edge label from the geometry of its path.
261
+ ```tsx
262
+ <Diagram.Group id="bug" row={0} col={3} colSpan={5} label="BUG">
263
+ <Diagram.Box id="reproduce" row={0} col={3}>
264
+ Reproduce
265
+ </Diagram.Box>
266
+ <Diagram.Box id="review-fix" row={0} col={6}>
267
+ Review fix
268
+ </Diagram.Box>
269
+ </Diagram.Group>
270
+ ```
243
271
 
244
- When the default paths still cross, use `Entry`, `Exit` and `Waypoint`. When the problem is general, fix the router instead. See [the internals](./docs/internals.md).
272
+ The border, the padding and the title band of a group go in the gutters between the rows and the columns. Thus a group never covers a node. The layout throws when two sibling groups overlap, when a node is in the area of a group that it is not a member of, and when an explicit area does not hold all of the members.
245
273
 
246
274
  ### Primitives for both layouts
247
275
 
248
- | Primitive | What it is |
249
- | ----------------- | ---------------------------------------------------------------------------------------------- |
250
- | `Diagram.Text` | A free annotation: `{ x, y }`, or next to a `target` node, with an optional leader line. |
251
- | `Diagram.Note` | The same as `Diagram.Text`. |
252
- | `Diagram.Line` | One line of a label with more than one line. It goes into a lane, a signal, a node or an edge. |
253
- | `Diagram.Guide` | A vertical or horizontal line that helps to align things. |
254
- | `Diagram.Content` | Real React content in a `Box`, a `Card` or a `Node`. Only `HtmlGraphDiagram` draws it. |
276
+ | Primitive | What it is |
277
+ | -------------- | ---------------------------------------------------------------------------------------------- |
278
+ | `Diagram.Line` | One line of a label with more than one line. It goes into a lane, a signal, a node or an edge. |
279
+
280
+ ### Content
281
+
282
+ `Diagram.Content` holds real React content in a `Box`, a `Card` or a `Node`. Only `HtmlGraphDiagram` draws it. The layout cannot measure React content, so give its size in pixels with `size`. The layout keeps a space of that size under the label:
283
+
284
+ ```tsx
285
+ <HtmlGraphDiagram title="Query">
286
+ <Diagram.Box id="database" row={0} col={0}>
287
+ Database
288
+ <Diagram.Content size={{ w: 96, h: 56 }}>
289
+ <button type="button">Run query</button>
290
+ </Diagram.Content>
291
+ </Diagram.Box>
292
+ </HtmlGraphDiagram>
293
+ ```
294
+
295
+ ### The layout without React
296
+
297
+ `layoutGraph(ir)` calculates the layout of a graph and returns a `GraphLayout`: the boxes of the nodes, the rectangles of the groups, the paths of the edges and the leaders, the positions of each text, and the `viewBox`. It is a pure, synchronous function. The renderers call it, and only copy its values. The package exports it and its types.
255
298
 
256
299
  ### Labels
257
300
 
@@ -269,8 +312,8 @@ The compiler checks the children, and it throws with a clear message:
269
312
  - A renderer accepts only primitives as children.
270
313
  - A React fragment (`<>…</>`) throws. Write the primitives directly, or give an array of primitives.
271
314
  - A different component, for example `<MyHelper />`, throws with the name of the component.
272
- - A lane, a signal, an edge and a frame accept only their own children: text, `Line`, `Entry`, `Exit` and `Waypoint`, and `Signal` in a frame.
273
- - A duplicate `id` of a node, a group, a guide or a lane throws, with the id in the message.
315
+ - A lane, a signal, an edge and a frame accept only their own children: text and `Line`, and `Signal` in a frame.
316
+ - A duplicate `id` of a node, a group or a lane throws, with the id in the message.
274
317
  - An edge to a missing `from` or `to` throws, with both ends in the message.
275
318
 
276
319
  ### Renderer props
@@ -291,7 +334,7 @@ Each renderer takes these props:
291
334
  | `viewport` | `{ fit?, zoom? }` | `fit: 'width'` | How the drawing fits its container: `width`, `contain` or `natural`. `zoom` scales it. |
292
335
  | `paper` | `boolean \| { fill?, stroke?, rx? }` | | A rectangle behind the drawing. `fill` is `background` or `surface`. |
293
336
 
294
- The graph renderers also take `graph`: the size of the columns and rows, and the padding. `HtmlGraphDiagram` takes `viewport.zoom`, but not `viewport.fit`. Only `SvgGraphDiagram` takes `effects`.
337
+ `HtmlGraphDiagram` takes `viewport.zoom`, but not `viewport.fit`. Only `SvgGraphDiagram` takes `effects`.
295
338
 
296
339
  The package does not set the width of a diagram on a page. Give the classes of your page layout with `className`.
297
340
 
@@ -300,6 +343,8 @@ The package does not set the width of a diagram on a page. Give the classes of y
300
343
  - **Internals**: [docs/internals.md](./docs/internals.md) tells how the compiler, the layouts and the renderers divide the work, and which mistakes the code had before.
301
344
  - **Decisions**: the [architecture decision records](./docs/adr) tell why the design is as it is.
302
345
  1. [The diagram is a zukhruf package](./docs/adr/0001-the-diagram-is-a-zukhruf-package.md)
346
+ 2. [The examples are a playground app in zukhruf](./docs/adr/0002-the-examples-are-a-playground-app-in-zukhruf.md)
347
+ 3. [The graph layout is a content-sized grid](./docs/adr/0003-the-graph-layout-is-a-content-sized-grid.md)
303
348
 
304
349
  ## Development
305
350
 
@@ -317,9 +362,10 @@ npx nx run diagram:lint # lints the code
317
362
  src/
318
363
  lib/model/ the IR types, and parseEndpointRef, which reads the from and to of an edge
319
364
  lib/compiler/ reads the primitives, and makes the IR
320
- lib/layouts/ the pure geometry of the graph and the timeline
365
+ lib/layouts/ the pure geometry of the graph and the timeline; text/ measures text with the glyph table
321
366
  lib/renderers/ svg/, canvas/, html/ and webgpu/ draw the layouts; shared/ holds the parts that they share
322
367
  lib/react/ the Diagram primitives and the chrome
368
+ testing/ the oracle (assertSoundLayout), and the script that writes the glyph table; the build does not ship them
323
369
  index.ts the entry
324
- styles.css registers dist with @source
370
+ styles.css loads the Geist fonts, and registers dist with @source
325
371
  ```
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- export { Diagram, type DiagramAccent, type DiagramApplianceProps, type DiagramConnectorProps, type DiagramContentProps, type DiagramEdgeProps, type DiagramEffects, type DiagramEntryProps, type DiagramExitProps, type DiagramFrameProps, type DiagramGroupProps, type DiagramGuideProps, type DiagramJunctionProps, type DiagramLaneProps, type DiagramLineProps, type DiagramMarkerProps, type DiagramMode, type DiagramNodeProps, type DiagramPaper, type DiagramPhantomProps, type DiagramProps, type DiagramSignalProps, type DiagramStackDirection, type DiagramStylePreset, type DiagramTextProps, type DiagramViewport, type DiagramWaypointProps, } from './lib/react/Diagram.tsx';
1
+ export { Diagram, type DiagramAccent, type DiagramApplianceProps, type DiagramConnectorProps, type DiagramContentProps, type DiagramEdgeProps, type DiagramEffects, type DiagramFrameProps, type DiagramGroupProps, type DiagramJunctionProps, type DiagramLaneProps, type DiagramLineProps, type DiagramMarkerProps, type DiagramMode, type DiagramNodeProps, type DiagramNoteProps, type DiagramPaper, type DiagramProps, type DiagramSignalProps, type DiagramStackDirection, type DiagramStylePreset, type DiagramViewport, } from './lib/react/Diagram.tsx';
2
2
  export { SvgGraphDiagram, type SvgGraphDiagramProps, } from './lib/renderers/svg/graph-svg.tsx';
3
3
  export { SvgTimelineDiagram, type SvgTimelineDiagramProps, } from './lib/renderers/svg/timeline-svg.tsx';
4
4
  export { CanvasGraphDiagram, type CanvasGraphDiagramProps, } from './lib/renderers/canvas/graph-canvas.tsx';
5
5
  export { HtmlGraphDiagram, type HtmlGraphDiagramProps, } from './lib/renderers/html/graph-html.tsx';
6
- export type { Box, DiagramAnchor, DiagramAnnotation, DiagramEdge, DiagramEdgeDirection, DiagramEdgeLabelSide, DiagramEdgeLineStyle, DiagramFrameElement, DiagramGraphIR, DiagramGraphLayout, DiagramGroup, DiagramGuide, DiagramLabelLine, DiagramLane, DiagramMarker, DiagramNode, DiagramNodeIcon, DiagramNodePort, DiagramSide, DiagramSignal, DiagramTextColor, DiagramTextAlign, DiagramTexture, DiagramTimelineSpec, DiagramTone, DiagramViewportFit, Point, } from './lib/model/diagram-ir.ts';
7
- export type { DiagramFontFace } from './lib/layouts/text-metrics.ts';
6
+ export { layoutGraph } from './lib/layouts/graph/layout.ts';
7
+ export type { EdgeLabelLayout, EdgeLayout, GraphLayout, GroupLayout, LeaderLayout, NodeLayout, PortLayout, TextAnchor, TextRun, } from './lib/layouts/graph/graph-layout-result.ts';
8
+ export type { Font, FontFace, FontWeight } from './lib/layouts/text/font.ts';
9
+ export type { Box, DiagramEdge, DiagramEdgeDirection, DiagramEdgeLineStyle, DiagramEdgeWeight, DiagramFrameElement, DiagramGraphIR, DiagramGroup, DiagramLabelLine, DiagramLane, DiagramMarker, DiagramNode, DiagramNodeContent, DiagramNodeIcon, DiagramNodePort, DiagramSide, DiagramSignal, DiagramTextColor, DiagramTexture, DiagramTimelineSpec, DiagramTone, DiagramViewportFit, Point, } from './lib/model/diagram-ir.ts';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,oBAAoB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,eAAe,EACf,KAAK,oBAAoB,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,GAC7B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,GAC7B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,qCAAqC,CAAC;AAC7C,YAAY,EACV,GAAG,EACH,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,eAAe,EACf,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,KAAK,GACN,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,eAAe,EACf,KAAK,oBAAoB,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,GAC7B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,GAC7B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,YAAY,EACV,eAAe,EACf,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,GACR,MAAM,4CAA4C,CAAC;AACpD,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7E,YAAY,EACV,GAAG,EACH,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,KAAK,GACN,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -3,4 +3,5 @@ export { SvgGraphDiagram } from "./lib/renderers/svg/graph-svg.js";
3
3
  export { SvgTimelineDiagram } from "./lib/renderers/svg/timeline-svg.js";
4
4
  export { CanvasGraphDiagram } from "./lib/renderers/canvas/graph-canvas.js";
5
5
  export { HtmlGraphDiagram } from "./lib/renderers/html/graph-html.js";
6
+ export { layoutGraph } from "./lib/layouts/graph/layout.js";
6
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Diagram","SvgGraphDiagram","SvgTimelineDiagram","CanvasGraphDiagram","HtmlGraphDiagram"],"sources":["../src/index.ts"],"sourcesContent":["export {\n Diagram,\n type DiagramAccent,\n type DiagramApplianceProps,\n type DiagramConnectorProps,\n type DiagramContentProps,\n type DiagramEdgeProps,\n type DiagramEffects,\n type DiagramEntryProps,\n type DiagramExitProps,\n type DiagramFrameProps,\n type DiagramGroupProps,\n type DiagramGuideProps,\n type DiagramJunctionProps,\n type DiagramLaneProps,\n type DiagramLineProps,\n type DiagramMarkerProps,\n type DiagramMode,\n type DiagramNodeProps,\n type DiagramPaper,\n type DiagramPhantomProps,\n type DiagramProps,\n type DiagramSignalProps,\n type DiagramStackDirection,\n type DiagramStylePreset,\n type DiagramTextProps,\n type DiagramViewport,\n type DiagramWaypointProps,\n} from './lib/react/Diagram.tsx';\nexport {\n SvgGraphDiagram,\n type SvgGraphDiagramProps,\n} from './lib/renderers/svg/graph-svg.tsx';\nexport {\n SvgTimelineDiagram,\n type SvgTimelineDiagramProps,\n} from './lib/renderers/svg/timeline-svg.tsx';\nexport {\n CanvasGraphDiagram,\n type CanvasGraphDiagramProps,\n} from './lib/renderers/canvas/graph-canvas.tsx';\nexport {\n HtmlGraphDiagram,\n type HtmlGraphDiagramProps,\n} from './lib/renderers/html/graph-html.tsx';\nexport type {\n Box,\n DiagramAnchor,\n DiagramAnnotation,\n DiagramEdge,\n DiagramEdgeDirection,\n DiagramEdgeLabelSide,\n DiagramEdgeLineStyle,\n DiagramFrameElement,\n DiagramGraphIR,\n DiagramGraphLayout,\n DiagramGroup,\n DiagramGuide,\n DiagramLabelLine,\n DiagramLane,\n DiagramMarker,\n DiagramNode,\n DiagramNodeIcon,\n DiagramNodePort,\n DiagramSide,\n DiagramSignal,\n DiagramTextColor,\n DiagramTextAlign,\n DiagramTexture,\n DiagramTimelineSpec,\n DiagramTone,\n DiagramViewportFit,\n Point,\n} from './lib/model/diagram-ir.ts';\nexport type { DiagramFontFace } from './lib/layouts/text-metrics.ts';\n"],"mappings":"AAAA,SACEA,OAAO,QA2BF,wBAAyB;AAChC,SACEC,eAAe,QAEV,kCAAmC;AAC1C,SACEC,kBAAkB,QAEb,qCAAsC;AAC7C,SACEC,kBAAkB,QAEb,wCAAyC;AAChD,SACEC,gBAAgB,QAEX,oCAAqC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["Diagram","SvgGraphDiagram","SvgTimelineDiagram","CanvasGraphDiagram","HtmlGraphDiagram","layoutGraph"],"sources":["../src/index.ts"],"sourcesContent":["export {\n Diagram,\n type DiagramAccent,\n type DiagramApplianceProps,\n type DiagramConnectorProps,\n type DiagramContentProps,\n type DiagramEdgeProps,\n type DiagramEffects,\n type DiagramFrameProps,\n type DiagramGroupProps,\n type DiagramJunctionProps,\n type DiagramLaneProps,\n type DiagramLineProps,\n type DiagramMarkerProps,\n type DiagramMode,\n type DiagramNodeProps,\n type DiagramNoteProps,\n type DiagramPaper,\n type DiagramProps,\n type DiagramSignalProps,\n type DiagramStackDirection,\n type DiagramStylePreset,\n type DiagramViewport,\n} from './lib/react/Diagram.tsx';\nexport {\n SvgGraphDiagram,\n type SvgGraphDiagramProps,\n} from './lib/renderers/svg/graph-svg.tsx';\nexport {\n SvgTimelineDiagram,\n type SvgTimelineDiagramProps,\n} from './lib/renderers/svg/timeline-svg.tsx';\nexport {\n CanvasGraphDiagram,\n type CanvasGraphDiagramProps,\n} from './lib/renderers/canvas/graph-canvas.tsx';\nexport {\n HtmlGraphDiagram,\n type HtmlGraphDiagramProps,\n} from './lib/renderers/html/graph-html.tsx';\nexport { layoutGraph } from './lib/layouts/graph/layout.ts';\nexport type {\n EdgeLabelLayout,\n EdgeLayout,\n GraphLayout,\n GroupLayout,\n LeaderLayout,\n NodeLayout,\n PortLayout,\n TextAnchor,\n TextRun,\n} from './lib/layouts/graph/graph-layout-result.ts';\nexport type { Font, FontFace, FontWeight } from './lib/layouts/text/font.ts';\nexport type {\n Box,\n DiagramEdge,\n DiagramEdgeDirection,\n DiagramEdgeLineStyle,\n DiagramEdgeWeight,\n DiagramFrameElement,\n DiagramGraphIR,\n DiagramGroup,\n DiagramLabelLine,\n DiagramLane,\n DiagramMarker,\n DiagramNode,\n DiagramNodeContent,\n DiagramNodeIcon,\n DiagramNodePort,\n DiagramSide,\n DiagramSignal,\n DiagramTextColor,\n DiagramTexture,\n DiagramTimelineSpec,\n DiagramTone,\n DiagramViewportFit,\n Point,\n} from './lib/model/diagram-ir.ts';\n"],"mappings":"AAAA,SACEA,OAAO,QAsBF,wBAAyB;AAChC,SACEC,eAAe,QAEV,kCAAmC;AAC1C,SACEC,kBAAkB,QAEb,qCAAsC;AAC7C,SACEC,kBAAkB,QAEb,wCAAyC;AAChD,SACEC,gBAAgB,QAEX,oCAAqC;AAC5C,SAASC,WAAW,QAAQ,+BAA+B","ignoreList":[]}
@@ -1,16 +1,15 @@
1
1
  import { type ReactNode } from 'react';
2
- import type { DiagramGraphIR, DiagramGraphLayout, DiagramTimelineSpec } from '../model/diagram-ir.ts';
2
+ import type { DiagramGraphIR, DiagramTimelineSpec } from '../model/diagram-ir.ts';
3
3
  export declare const DIAGRAM_PRIMITIVE: unique symbol;
4
- declare const PRIMITIVE_KINDS: readonly ["node", "box", "card", "port", "label", "float", "phantom", "appliance", "connector", "junction", "edge", "arrow", "wire", "group", "text", "line", "lane", "signal", "frame", "marker", "guide", "waypoint", "entry", "exit", "content"];
4
+ declare const PRIMITIVE_KINDS: readonly ["node", "box", "card", "port", "label", "float", "appliance", "connector", "junction", "edge", "arrow", "wire", "group", "note", "line", "lane", "signal", "frame", "marker", "content"];
5
5
  export type PrimitiveKind = (typeof PRIMITIVE_KINDS)[number];
6
6
  export type PrimitiveComponent<P> = ((props: P) => null) & {
7
7
  [DIAGRAM_PRIMITIVE]: PrimitiveKind;
8
8
  };
9
9
  export declare function primitive<P>(kind: PrimitiveKind): PrimitiveComponent<P>;
10
10
  export declare function primitiveKind(node: ReactNode): PrimitiveKind | null;
11
- export declare function compileGraph(children: ReactNode, layout: DiagramGraphLayout | undefined): DiagramGraphIR;
11
+ export declare function compileGraph(children: ReactNode): DiagramGraphIR;
12
12
  export declare function compileTimeline(children: ReactNode): DiagramTimelineSpec;
13
- export declare function validateGraph(ir: DiagramGraphIR): void;
14
13
  export declare function validateTimeline(ir: DiagramTimelineSpec): void;
15
14
  export {};
16
15
  //# sourceMappingURL=diagram-compile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diagram-compile.d.ts","sourceRoot":"","sources":["../../../src/lib/compiler/diagram-compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAIV,cAAc,EACd,kBAAkB,EAOlB,mBAAmB,EAEpB,MAAM,wBAAwB,CAAC;AAuBhC,eAAO,MAAM,iBAAiB,eAA2C,CAAC;AAE1E,QAAA,MAAM,eAAe,qPA0BX,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG;IACzD,CAAC,iBAAiB,CAAC,EAAE,aAAa,CAAC;CACpC,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAEvE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa,GAAG,IAAI,CAMnE;AA6CD,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,SAAS,EACnB,MAAM,EAAE,kBAAkB,GAAG,SAAS,GACrC,cAAc,CAmBhB;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,GAAG,mBAAmB,CAkBxE;AA0mBD,wBAAgB,aAAa,CAAC,EAAE,EAAE,cAAc,QA0I/C;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,mBAAmB,QAoBvD"}
1
+ {"version":3,"file":"diagram-compile.d.ts","sourceRoot":"","sources":["../../../src/lib/compiler/diagram-compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAGV,cAAc,EAOd,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAiBhC,eAAO,MAAM,iBAAiB,eAA2C,CAAC;AAE1E,QAAA,MAAM,eAAe,oMAqBX,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG;IACzD,CAAC,iBAAiB,CAAC,EAAE,aAAa,CAAC;CACpC,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAEvE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa,GAAG,IAAI,CAMnE;AAuCD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,GAAG,cAAc,CAgBhE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,GAAG,mBAAmB,CAgBxE;AAqYD,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,mBAAmB,QAoBvD"}