@momoi-labs/kiso-react 0.16.1 → 0.16.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.
Files changed (2) hide show
  1. package/dist/diagram.js +19 -6
  2. package/package.json +1 -1
package/dist/diagram.js CHANGED
@@ -29,10 +29,12 @@ const statuses = {
29
29
  };
30
30
  const RADIUS = 8;
31
31
  /* An edge is two paths. The trunk is the horizontal run out of the source,
32
- shared by every edge that leaves it, so it is always drawn solid and
33
- neutral: two styles on one line would paint over each other. The branch
34
- is the rest, the turn onto the merge column, the vertical run and the
35
- straight run into the target, and it carries the edge's line and tone. */
32
+ shared by every edge that leaves it. It carries their line and tone when
33
+ they all agree, so a single dotted edge is dotted end to end; when they
34
+ differ it stays solid and neutral, since two styles on one line would
35
+ paint over each other. The branch is the rest, the turn onto the merge
36
+ column, the vertical run and the straight run into the target, and it
37
+ carries the edge's line and tone. */
36
38
  function elbow(sx, sy, tx, ty, mid) {
37
39
  const dy = ty - sy;
38
40
  if (Math.abs(dy) < 1)
@@ -102,7 +104,10 @@ function Diagram({ label, background, strength, borderStyle, cornerStyle, corner
102
104
  // labels never land on the same spot. One edge enters at the middle.
103
105
  const measured = edges.flatMap((edge) => {
104
106
  const target = box(edge.to);
105
- const sources = edge.from.map(box).filter((b) => b !== null);
107
+ const sources = edge.from.flatMap((id) => {
108
+ const found = box(id);
109
+ return found ? [{ ...found, id }] : [];
110
+ });
106
111
  return target && sources.length ? [{ edge, target, sources }] : [];
107
112
  });
108
113
  const entries = new Map();
@@ -113,6 +118,14 @@ function Diagram({ label, background, strength, borderStyle, cornerStyle, corner
113
118
  entries.set(item.edge, item.target.top + (item.target.height * (index + 1)) / (group.length + 1));
114
119
  });
115
120
  }
121
+ const leaving = new Map();
122
+ for (const edge of edges)
123
+ for (const id of edge.from)
124
+ leaving.set(id, [...(leaving.get(id) ?? []), edge]);
125
+ const trunkStyle = (id) => {
126
+ const [first, ...rest] = leaving.get(id) ?? [];
127
+ return first && rest.every((edge) => edge.line === first.line && edge.tone === first.tone) ? { line: first.line, tone: first.tone } : {};
128
+ };
116
129
  const next = { paths: [], labels: [] };
117
130
  for (const { edge, target, sources } of measured) {
118
131
  const ty = entries.get(edge) ?? target.y;
@@ -120,7 +133,7 @@ function Diagram({ label, background, strength, borderStyle, cornerStyle, corner
120
133
  const mid = (start + target.left) / 2;
121
134
  sources.forEach((source, index) => {
122
135
  const { trunk, branch } = elbow(source.right, source.y, target.left, ty, mid);
123
- next.paths.push({ key: `${edge.key}:${index}:trunk`, d: trunk, arrow: false });
136
+ next.paths.push({ key: `${edge.key}:${index}:trunk`, d: trunk, arrow: false, ...trunkStyle(source.id) });
124
137
  next.paths.push({ key: `${edge.key}:${index}`, d: branch, line: edge.line, tone: edge.tone, arrow: true });
125
138
  });
126
139
  // The label sits on the edge's own run into the target, above the line.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momoi-labs/kiso-react",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "Kiso React components built with shadcn/ui and Radix",
5
5
  "type": "module",
6
6
  "license": "MIT",