yarramate 1.38.0 → 1.39.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.
@@ -1,2 +1,4 @@
1
1
  export { projectGraphForCanvas, type CanvasGraph, type CanvasNode, type CanvasEdge, } from '../graph-projection.js';
2
2
  export { foldTree, foldGraph, nestingTree, liftedEdgeId, NESTING_KIND_IDS, type FoldInput, type FoldNode, type FoldEdge, type FoldMembership, type FoldTree, type LiftedEdge, type NestingConflict, type SlotWiring, } from '../fold-tree.js';
3
+ export { edgeLabelText, type EdgeLabelData } from '../edge-label.js';
4
+ export { DEFAULT_LAYOUT, LAYOUT_MODES, type LayoutMode } from '../layout-mode.js';
@@ -5,3 +5,9 @@ export { projectGraphForCanvas, } from '../graph-projection.js';
5
5
  // an application is made of. `fold-tree.ts` imports nothing, so this subpath
6
6
  // stays runtime-neutral.
7
7
  export { foldTree, foldGraph, nestingTree, liftedEdgeId, NESTING_KIND_IDS, } from '../fold-tree.js';
8
+ // What an edge says (ADR 0147) and the mode list it depends on (#587). The
9
+ // editor entry has exported these since #576, but that entry is the mounted
10
+ // editor, so a Worker importing one pure function from it took React and
11
+ // cytoscape too. `edge-label.ts` and `layout-mode.ts` reach no package.
12
+ export { edgeLabelText } from '../edge-label.js';
13
+ export { DEFAULT_LAYOUT, LAYOUT_MODES } from '../layout-mode.js';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * What an edge says, kept in a module that imports nothing with a runtime of
3
+ * its own (#587). The canvas draws with it; a host that renders the same
4
+ * picture somewhere else, a server-side SVG Worker, imports it from
5
+ * `yarramate/adapter/visual-graph` without taking elkjs, React or cytoscape.
6
+ * It was first published from the editor entry (#576), which is where a
7
+ * consumer could not use it.
8
+ */
9
+ import { type LayoutMode } from './layout-mode.js';
10
+ /** The data fields an edge's label is decided from. */
11
+ export interface EdgeLabelData {
12
+ readonly name?: string | null;
13
+ readonly kindLabel?: string;
14
+ readonly coreKindLabel?: string;
15
+ /** An extension kind with a reading of its own (ADR 0159), else absent. */
16
+ readonly readingKind?: string;
17
+ /** A reading the endpoints decided (ADR 0160), else absent. */
18
+ readonly reading?: string;
19
+ readonly liftedCount?: number;
20
+ }
21
+ /**
22
+ * The one place that decides what an edge says (ADR 0147).
23
+ *
24
+ * A named relationship says its name. An unnamed one says its reading -
25
+ * "serves", or "served by" where the mode layers the served element above -
26
+ * unless kind labels are off, in which case the line style and arrowhead
27
+ * carry the kind alone. An extension kind has no reading in the table and is
28
+ * spelled out from its own name ("deploys to" for `deploys-to`), in the active
29
+ * voice whichever way it is layered, because nobody can conjugate a verb they
30
+ * have not seen. A lifted edge stands for several relationships and says how
31
+ * many.
32
+ */
33
+ export declare const edgeLabelText: (data: EdgeLabelData, mode: LayoutMode, showKindLabels: boolean) => string;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * What an edge says, kept in a module that imports nothing with a runtime of
3
+ * its own (#587). The canvas draws with it; a host that renders the same
4
+ * picture somewhere else, a server-side SVG Worker, imports it from
5
+ * `yarramate/adapter/visual-graph` without taking elkjs, React or cytoscape.
6
+ * It was first published from the editor entry (#576), which is where a
7
+ * consumer could not use it.
8
+ */
9
+ import { LAYERING_REVERSED_KINDS, reversesForLayering } from './layout-mode.js';
10
+ import { humanizeKind, relationshipReading } from './relationship-reading.js';
11
+ /**
12
+ * The one place that decides what an edge says (ADR 0147).
13
+ *
14
+ * A named relationship says its name. An unnamed one says its reading -
15
+ * "serves", or "served by" where the mode layers the served element above -
16
+ * unless kind labels are off, in which case the line style and arrowhead
17
+ * carry the kind alone. An extension kind has no reading in the table and is
18
+ * spelled out from its own name ("deploys to" for `deploys-to`), in the active
19
+ * voice whichever way it is layered, because nobody can conjugate a verb they
20
+ * have not seen. A lifted edge stands for several relationships and says how
21
+ * many.
22
+ */
23
+ export const edgeLabelText = (data, mode, showKindLabels) => {
24
+ if (typeof data.name === 'string' && data.name !== '')
25
+ return data.name;
26
+ if (!showKindLabels)
27
+ return '';
28
+ const core = data.coreKindLabel ?? '';
29
+ const kind = data.kindLabel ?? core;
30
+ const readingKind = data.readingKind;
31
+ const reading = data.reading !== undefined && data.reading !== ''
32
+ ? data.reading
33
+ : readingKind !== undefined && readingKind !== core
34
+ ? relationshipReading(readingKind)
35
+ : kind !== core && kind !== ''
36
+ ? humanizeKind(kind)
37
+ : relationshipReading(core, reversesForLayering(mode) && LAYERING_REVERSED_KINDS.has(core));
38
+ const count = typeof data.liftedCount === 'number' ? data.liftedCount : 0;
39
+ return count > 1 ? `${reading} ×${count}` : reading;
40
+ };