effect-atom-svelte-devtools 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/dist/atom-devtools.svelte +585 -0
- package/dist/atom-devtools.svelte.d.ts +28 -0
- package/dist/graph/atom-graph.svelte +244 -0
- package/dist/graph/atom-graph.svelte.d.ts +38 -0
- package/dist/graph/frame-graph.svelte +408 -0
- package/dist/graph/frame-graph.svelte.d.ts +52 -0
- package/dist/graph/index.d.ts +5 -0
- package/dist/graph/index.js +7 -0
- package/dist/graph/layout.d.ts +65 -0
- package/dist/graph/layout.js +531 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/internal/format.d.ts +20 -0
- package/dist/internal/format.js +138 -0
- package/dist/internal/graph-view.svelte +127 -0
- package/dist/internal/graph-view.svelte.d.ts +10 -0
- package/dist/internal/label.d.ts +35 -0
- package/dist/internal/label.js +139 -0
- package/dist/internal/model.svelte.d.ts +75 -0
- package/dist/internal/model.svelte.js +286 -0
- package/dist/internal/names.d.ts +29 -0
- package/dist/internal/names.js +55 -0
- package/dist/internal/sheets-view.svelte +446 -0
- package/dist/internal/sheets-view.svelte.d.ts +11 -0
- package/dist/internal/timeline-view.svelte +291 -0
- package/dist/internal/timeline-view.svelte.d.ts +9 -0
- package/dist/internal/transform.d.ts +17 -0
- package/dist/internal/transform.js +401 -0
- package/dist/vite.d.ts +52 -0
- package/dist/vite.js +97 -0
- package/package.json +78 -4
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tone a value's pulse takes: green for a Success, red for a Failure, and the accent for a
|
|
3
|
+
* plain value or a result still waiting for the next.
|
|
4
|
+
*/
|
|
5
|
+
export const toneOf = (state, waiting = false) => {
|
|
6
|
+
if (waiting) {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
if (state === "Success") {
|
|
10
|
+
return "success";
|
|
11
|
+
}
|
|
12
|
+
return state === "Failure" ? "failure" : "";
|
|
13
|
+
};
|
|
14
|
+
// The first line, and the space between rows: room for a two-line label above each.
|
|
15
|
+
const top = 40;
|
|
16
|
+
const row = 38;
|
|
17
|
+
// The extra a row of dots needs below it for their keys.
|
|
18
|
+
const keyRoom = 26;
|
|
19
|
+
// Components sit in a column of their own at 72%, with their labels to the right of them.
|
|
20
|
+
const componentColumn = 0.72;
|
|
21
|
+
/** A key as a dot's caption: an object's values (`1 · en`), or the argument as written. */
|
|
22
|
+
const keyOf = (args) => {
|
|
23
|
+
try {
|
|
24
|
+
const value = JSON.parse(args);
|
|
25
|
+
if (value && typeof value === "object") {
|
|
26
|
+
return Object.values(value).map(String).join(" · ");
|
|
27
|
+
}
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return args;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const append = (map, key, value) => {
|
|
35
|
+
map.set(key, [...(map.get(key) ?? []), value]);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* A family's or factory's atoms on one row: the group's first member stands for it in the layout,
|
|
39
|
+
* and `canon` maps each member to it. Only for three or more members, read one at a time.
|
|
40
|
+
*/
|
|
41
|
+
const groupFamilies = (atoms, readNow) => {
|
|
42
|
+
const canon = new Map();
|
|
43
|
+
const groups = new Map();
|
|
44
|
+
const byName = new Map();
|
|
45
|
+
for (const atom of atoms.values()) {
|
|
46
|
+
const match = /^(?<name>[^(]+)\((?<args>.*)\)$/su.exec(atom.label ?? "");
|
|
47
|
+
if (match?.groups?.name !== undefined && match.groups.args !== undefined) {
|
|
48
|
+
append(byName, match.groups.name, {
|
|
49
|
+
args: match.groups.args,
|
|
50
|
+
id: atom.id,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const [name, members] of byName) {
|
|
55
|
+
const [first] = members;
|
|
56
|
+
if (!first ||
|
|
57
|
+
members.length < 3 ||
|
|
58
|
+
members.filter(({ id }) => readNow.has(id)).length > 1) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const seenKeys = new Set();
|
|
62
|
+
const dots = members.map(({ args, id }) => {
|
|
63
|
+
const repeat = seenKeys.has(args);
|
|
64
|
+
seenKeys.add(args);
|
|
65
|
+
return { id, key: keyOf(args), label: `${name}(${args})`, repeat };
|
|
66
|
+
});
|
|
67
|
+
groups.set(first.id, { dots, keys: seenKeys.size, name });
|
|
68
|
+
for (const { id } of members) {
|
|
69
|
+
canon.set(id, first.id);
|
|
70
|
+
if (id !== first.id) {
|
|
71
|
+
atoms.delete(id);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { canon, groups };
|
|
76
|
+
};
|
|
77
|
+
/** Each drawn atom's parents, through the groups. */
|
|
78
|
+
const parentsOf = (links, atoms, canonical) => {
|
|
79
|
+
const parents = new Map();
|
|
80
|
+
for (const link of links) {
|
|
81
|
+
const from = canonical(link.from);
|
|
82
|
+
const to = canonical(link.to);
|
|
83
|
+
if (from !== to &&
|
|
84
|
+
atoms.has(from) &&
|
|
85
|
+
atoms.has(to) &&
|
|
86
|
+
!parents.get(to)?.includes(from)) {
|
|
87
|
+
append(parents, to, from);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return parents;
|
|
91
|
+
};
|
|
92
|
+
/** How far each atom is from a source: the longest chain of parents above it. */
|
|
93
|
+
const depthsOf = (atoms, parents) => {
|
|
94
|
+
const depths = new Map();
|
|
95
|
+
const depth = (id, seen) => {
|
|
96
|
+
const known = depths.get(id);
|
|
97
|
+
if (known !== undefined) {
|
|
98
|
+
return known;
|
|
99
|
+
}
|
|
100
|
+
seen.add(id);
|
|
101
|
+
const from = (parents.get(id) ?? []).filter((parent) => !seen.has(parent));
|
|
102
|
+
const value = from.length === 0 ? 0 : 1 + Math.max(...from.map((p) => depth(p, seen)));
|
|
103
|
+
depths.set(id, value);
|
|
104
|
+
return value;
|
|
105
|
+
};
|
|
106
|
+
for (const id of atoms.keys()) {
|
|
107
|
+
depth(id, new Set());
|
|
108
|
+
}
|
|
109
|
+
return depths;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* What each component instance does with each atom; instances of one component that use the same
|
|
113
|
+
* atoms the same way are one node with a count (`card.svelte ×3`).
|
|
114
|
+
*/
|
|
115
|
+
const componentsOf = (readers, atoms, canonical) => {
|
|
116
|
+
const instances = new Map();
|
|
117
|
+
for (const reader of readers) {
|
|
118
|
+
const atom = canonical(reader.atom);
|
|
119
|
+
if (!atoms.has(atom)) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const key = `${reader.name}#${reader.instance ?? 0}`;
|
|
123
|
+
const instance = instances.get(key) ?? {
|
|
124
|
+
count: 1,
|
|
125
|
+
key,
|
|
126
|
+
label: reader.name,
|
|
127
|
+
uses: new Map(),
|
|
128
|
+
};
|
|
129
|
+
instances.set(key, instance);
|
|
130
|
+
instance.uses.set(atom, (instance.uses.get(atom) ?? new Set()).add(reader.kind));
|
|
131
|
+
}
|
|
132
|
+
const components = new Map();
|
|
133
|
+
for (const instance of instances.values()) {
|
|
134
|
+
const uses = [...instance.uses]
|
|
135
|
+
.map(([atom, kinds]) => `${atom}:${[...kinds].toSorted().join("+")}`)
|
|
136
|
+
.toSorted()
|
|
137
|
+
.join(",");
|
|
138
|
+
const key = `c${instance.label}|${uses}`;
|
|
139
|
+
const known = components.get(key);
|
|
140
|
+
if (known) {
|
|
141
|
+
known.count += 1;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
components.set(key, { ...instance, count: 1, key });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return components;
|
|
148
|
+
};
|
|
149
|
+
/** Where things go: a column and a track for each key (`a<id>` for an atom, a component's key). */
|
|
150
|
+
class Tracks {
|
|
151
|
+
rows = new Map();
|
|
152
|
+
columns = new Map();
|
|
153
|
+
count = 0;
|
|
154
|
+
place(column, key, wanted) {
|
|
155
|
+
const taken = new Set([...this.columns]
|
|
156
|
+
.filter(([, at]) => at === column)
|
|
157
|
+
.map(([other]) => this.rows.get(other)));
|
|
158
|
+
let track = wanted ?? this.count;
|
|
159
|
+
while (taken.has(track)) {
|
|
160
|
+
track += 1;
|
|
161
|
+
}
|
|
162
|
+
this.rows.set(key, track);
|
|
163
|
+
this.columns.set(key, column);
|
|
164
|
+
this.count = Math.max(this.count, track + 1);
|
|
165
|
+
return track;
|
|
166
|
+
}
|
|
167
|
+
first(keys) {
|
|
168
|
+
const known = keys
|
|
169
|
+
.map((key) => this.rows.get(key))
|
|
170
|
+
.filter((track) => track !== undefined);
|
|
171
|
+
return known.length > 0 ? Math.min(...known) : undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Places atoms depth first: a source, then what derives from it, then the next source, so a derived
|
|
176
|
+
* atom sits under its parent. The first child takes its parent's track, unless a component reads the
|
|
177
|
+
* parent, which keeps its track clear to the component; and the components that read only one atom
|
|
178
|
+
* sit together as a block from that atom's track down, the next atom starting below the block.
|
|
179
|
+
*/
|
|
180
|
+
const placeAtoms = (shape, tracks) => {
|
|
181
|
+
const readDirectly = new Set([...shape.components.values()].flatMap((component) => [
|
|
182
|
+
...component.uses.keys(),
|
|
183
|
+
]));
|
|
184
|
+
const children = new Map();
|
|
185
|
+
for (const [child, from] of shape.parents) {
|
|
186
|
+
for (const parent of from) {
|
|
187
|
+
append(children, parent, child);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const exclusive = new Map();
|
|
191
|
+
for (const component of shape.components.values()) {
|
|
192
|
+
const [only] = component.uses.keys();
|
|
193
|
+
if (component.uses.size === 1 && only !== undefined) {
|
|
194
|
+
append(exclusive, only, component);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const visit = (id, wanted) => {
|
|
198
|
+
if (tracks.rows.has(`a${id}`)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const track = tracks.place(shape.depths.get(id) ?? 0, `a${id}`, wanted);
|
|
202
|
+
tracks.count = Math.max(tracks.count, track + (exclusive.get(id)?.length ?? 1));
|
|
203
|
+
for (const [index, child] of (children.get(id) ?? []).entries()) {
|
|
204
|
+
visit(child, index === 0 && !readDirectly.has(id) ? track : undefined);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
for (const atom of shape.atoms.values()) {
|
|
208
|
+
if ((shape.parents.get(atom.id) ?? []).length === 0) {
|
|
209
|
+
visit(atom.id, undefined);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Anything left (a cycle, say) still gets a place.
|
|
213
|
+
for (const atom of shape.atoms.values()) {
|
|
214
|
+
visit(atom.id, undefined);
|
|
215
|
+
}
|
|
216
|
+
return exclusive;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Places components: each block from its atom's track down, then the others on the track of an atom
|
|
220
|
+
* they use where it's free, then the rest below, grouped by the track they'd have liked.
|
|
221
|
+
*/
|
|
222
|
+
const placeComponents = (shape, tracks, exclusive) => {
|
|
223
|
+
for (const [atom, block] of exclusive) {
|
|
224
|
+
const start = tracks.rows.get(`a${atom}`) ?? 0;
|
|
225
|
+
for (const [index, component] of block.entries()) {
|
|
226
|
+
tracks.place(shape.atomColumns, component.key, start + index);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const wantedTrack = (component) => tracks.first([...component.uses.keys()].map((a) => `a${a}`));
|
|
230
|
+
const leftover = [];
|
|
231
|
+
for (const component of shape.components.values()) {
|
|
232
|
+
if (tracks.rows.has(component.key)) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const wanted = wantedTrack(component);
|
|
236
|
+
const taken = [...tracks.columns].some(([key, column]) => column === shape.atomColumns && tracks.rows.get(key) === wanted);
|
|
237
|
+
if (wanted === undefined || taken) {
|
|
238
|
+
leftover.push(component);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
tracks.place(shape.atomColumns, component.key, wanted);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const order = (component) => wantedTrack(component) ?? Number.POSITIVE_INFINITY;
|
|
245
|
+
for (const component of leftover.toSorted((a, b) => order(a) - order(b))) {
|
|
246
|
+
tracks.place(shape.atomColumns, component.key, tracks.count);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
/** Where on the page a key is drawn: x as a fraction of the width, y in pixels. */
|
|
250
|
+
const positions = (shape, tracks, dotted) => {
|
|
251
|
+
const hasComponents = shape.components.size > 0;
|
|
252
|
+
const x = (column) => {
|
|
253
|
+
if (hasComponents && column === shape.atomColumns) {
|
|
254
|
+
return componentColumn;
|
|
255
|
+
}
|
|
256
|
+
const span = hasComponents ? 0.52 : 0.84;
|
|
257
|
+
return shape.atomColumns === 1
|
|
258
|
+
? 0.04
|
|
259
|
+
: 0.04 + (column * (span - 0.04)) / (shape.atomColumns - 1);
|
|
260
|
+
};
|
|
261
|
+
// A row of dots has its keys under it: every track after one moves down to make room.
|
|
262
|
+
const trackY = (track) => top + track * row + [...dotted].filter((t) => t < track).length * keyRoom;
|
|
263
|
+
const at = (key) => {
|
|
264
|
+
const column = tracks.columns.get(key) ?? 0;
|
|
265
|
+
return { column, x: x(column), y: trackY(tracks.rows.get(key) ?? 0) };
|
|
266
|
+
};
|
|
267
|
+
return { at, trackY };
|
|
268
|
+
};
|
|
269
|
+
const groupNode = (id, group, x, y) => {
|
|
270
|
+
const repeats = group.dots.filter((dot) => dot.repeat).length;
|
|
271
|
+
const keys = `${group.keys} ${group.keys === 1 ? "key" : "keys"}`;
|
|
272
|
+
return {
|
|
273
|
+
id: `g${id}`,
|
|
274
|
+
kind: "junction",
|
|
275
|
+
label: `${group.name}(…)`,
|
|
276
|
+
note: `${group.dots.length} atoms for ${keys}${repeats > 0 ? ` · ${repeats} repeat a key` : ""}`,
|
|
277
|
+
side: "ne",
|
|
278
|
+
x,
|
|
279
|
+
y,
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
const componentNote = (component) => {
|
|
283
|
+
const kinds = new Set([...component.uses.values()].flatMap((uses) => [...uses]));
|
|
284
|
+
if (!kinds.has("write")) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
return kinds.size === 1 ? "writes" : "reads, writes";
|
|
288
|
+
};
|
|
289
|
+
/** The marks: atoms, groups and components, with labels and notes. */
|
|
290
|
+
const nodesOf = (shape, groups, at) => {
|
|
291
|
+
const columns = shape.atomColumns + (shape.components.size > 0 ? 1 : 0);
|
|
292
|
+
// Two atoms with one name (one atom scoped twice, say) are told apart by a number.
|
|
293
|
+
const names = new Map();
|
|
294
|
+
for (const atom of shape.atoms.values()) {
|
|
295
|
+
names.set(atom.label ?? "atom", (names.get(atom.label ?? "atom") ?? 0) + 1);
|
|
296
|
+
}
|
|
297
|
+
const named = new Map();
|
|
298
|
+
const nodes = [];
|
|
299
|
+
for (const atom of shape.atoms.values()) {
|
|
300
|
+
const { column, x, y } = at(`a${atom.id}`);
|
|
301
|
+
const group = groups.get(atom.id);
|
|
302
|
+
if (group) {
|
|
303
|
+
nodes.push(groupNode(atom.id, group, x, y));
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const name = atom.label ?? "atom";
|
|
307
|
+
const index = (named.get(name) ?? 0) + 1;
|
|
308
|
+
named.set(name, index);
|
|
309
|
+
const last = shape.components.size === 0 && column === columns - 1 && columns > 1;
|
|
310
|
+
nodes.push({
|
|
311
|
+
id: `a${atom.id}`,
|
|
312
|
+
kind: atom.status === "removed" ? "gone" : "atom",
|
|
313
|
+
label: (names.get(name) ?? 0) > 1 ? `${name} #${index}` : name,
|
|
314
|
+
note: atom.note,
|
|
315
|
+
side: last ? "nw" : "ne",
|
|
316
|
+
x,
|
|
317
|
+
y,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
for (const component of shape.components.values()) {
|
|
321
|
+
const { x, y } = at(component.key);
|
|
322
|
+
nodes.push({
|
|
323
|
+
id: component.key,
|
|
324
|
+
kind: "component",
|
|
325
|
+
label: component.count > 1
|
|
326
|
+
? `${component.label} ×${component.count}`
|
|
327
|
+
: component.label,
|
|
328
|
+
note: componentNote(component),
|
|
329
|
+
side: "ne",
|
|
330
|
+
x,
|
|
331
|
+
y,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return nodes;
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* The edges. One that changes track turns between its columns at an offset of its source's own, so
|
|
338
|
+
* edges from different sources never share a vertical line; into a component it gathers on a
|
|
339
|
+
* collector (a component reading several atoms has its own; components reading one atom share that
|
|
340
|
+
* atom's trunk); and one that would run through a node goes round along a lane of its own.
|
|
341
|
+
*/
|
|
342
|
+
const routeEdges = ({ at, lastRow, nodes, shape, trackY }) => {
|
|
343
|
+
const sources = new Map();
|
|
344
|
+
const collectors = new Map();
|
|
345
|
+
const sourceCount = new Set([
|
|
346
|
+
...[...shape.parents.values()].flat(),
|
|
347
|
+
...[...shape.components.values()].flatMap((component) => [
|
|
348
|
+
...component.uses.keys(),
|
|
349
|
+
]),
|
|
350
|
+
]).size;
|
|
351
|
+
const blocked = (y, x1, x2) => nodes.some((node) => node.y === y &&
|
|
352
|
+
node.x > Math.min(x1, x2) + 1e-6 &&
|
|
353
|
+
node.x < Math.max(x1, x2) - 1e-6);
|
|
354
|
+
let lanes = 0;
|
|
355
|
+
const edges = [];
|
|
356
|
+
const turnAt = (from, to, a, b, collector) => {
|
|
357
|
+
const source = sources.get(from) ?? sources.size;
|
|
358
|
+
sources.set(from, source);
|
|
359
|
+
if (!collector) {
|
|
360
|
+
return (a.x + b.x) / 2 + (source - (sourceCount - 1) / 2) * 0.018;
|
|
361
|
+
}
|
|
362
|
+
const single = (shape.components.get(to)?.uses.size ?? 0) === 1;
|
|
363
|
+
const owner = single ? `from ${from}` : `into ${to}`;
|
|
364
|
+
const index = collectors.get(owner) ?? collectors.size;
|
|
365
|
+
collectors.set(owner, index);
|
|
366
|
+
return b.x - 0.025 - index * 0.016;
|
|
367
|
+
};
|
|
368
|
+
const route = (from, to, dashed, collector = false) => {
|
|
369
|
+
const a = at(from);
|
|
370
|
+
const b = at(to);
|
|
371
|
+
const middle = turnAt(from, to, a, b, collector && a.y !== b.y);
|
|
372
|
+
const same = a.y === b.y;
|
|
373
|
+
const direct = same
|
|
374
|
+
? [
|
|
375
|
+
[a.x, a.y],
|
|
376
|
+
[b.x, b.y],
|
|
377
|
+
]
|
|
378
|
+
: [
|
|
379
|
+
[a.x, a.y],
|
|
380
|
+
[middle, a.y],
|
|
381
|
+
[middle, b.y],
|
|
382
|
+
[b.x, b.y],
|
|
383
|
+
];
|
|
384
|
+
const through = same
|
|
385
|
+
? blocked(a.y, a.x, b.x)
|
|
386
|
+
: blocked(a.y, a.x, middle) || blocked(b.y, middle, b.x);
|
|
387
|
+
if (!through) {
|
|
388
|
+
edges.push({ dashed, id: `${from}>${to}`, points: direct, to });
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const lane = trackY(lastRow + 1 + lanes) - row / 2;
|
|
392
|
+
lanes += 1;
|
|
393
|
+
const gap = 0.015;
|
|
394
|
+
edges.push({
|
|
395
|
+
dashed,
|
|
396
|
+
id: `${from}>${to}`,
|
|
397
|
+
points: [
|
|
398
|
+
[a.x, a.y],
|
|
399
|
+
[a.x + gap, a.y],
|
|
400
|
+
[a.x + gap, lane],
|
|
401
|
+
[b.x - gap, lane],
|
|
402
|
+
[b.x - gap, b.y],
|
|
403
|
+
[b.x, b.y],
|
|
404
|
+
],
|
|
405
|
+
to,
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
for (const [child, from] of shape.parents) {
|
|
409
|
+
for (const parent of from) {
|
|
410
|
+
route(`a${parent}`, `a${child}`, false);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
for (const component of shape.components.values()) {
|
|
414
|
+
for (const [atom, kinds] of component.uses) {
|
|
415
|
+
// An atom the component only writes to: dashed, since nothing flows back to it.
|
|
416
|
+
route(`a${atom}`, component.key, kinds.size === 1 && kinds.has("write"), true);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return { edges, lanes };
|
|
420
|
+
};
|
|
421
|
+
/** An edge's runs, as pairs of points. */
|
|
422
|
+
const runsOf = (points) => points.slice(1).flatMap((end, index) => {
|
|
423
|
+
const start = points[index];
|
|
424
|
+
return start ? [[start, end]] : [];
|
|
425
|
+
});
|
|
426
|
+
/**
|
|
427
|
+
* Where one edge's vertical run crosses the middle of another's horizontal one, and they're not
|
|
428
|
+
* headed for the same node, the horizontal one breaks for a few pixels either side: a crossing reads
|
|
429
|
+
* as passing over, not as a junction. Where lines join, one ends on the other, so they never meet
|
|
430
|
+
* this test.
|
|
431
|
+
*/
|
|
432
|
+
const breakCrossings = (edges, width) => {
|
|
433
|
+
const half = width > 0 ? 4 / width : 0;
|
|
434
|
+
if (half === 0) {
|
|
435
|
+
return [...edges];
|
|
436
|
+
}
|
|
437
|
+
const verticals = edges.flatMap((edge) => runsOf(edge.points).flatMap(([[x1, y1], [x2, y2]]) => x1 === x2 && y1 !== y2
|
|
438
|
+
? [{ to: edge.to, x: x1, y1: Math.min(y1, y2), y2: Math.max(y1, y2) }]
|
|
439
|
+
: []));
|
|
440
|
+
return edges.flatMap((edge) => {
|
|
441
|
+
const [start] = edge.points;
|
|
442
|
+
if (!start) {
|
|
443
|
+
return [];
|
|
444
|
+
}
|
|
445
|
+
const pieces = [[start]];
|
|
446
|
+
for (const [[x1, y1], [x2, y2]] of runsOf(edge.points)) {
|
|
447
|
+
if (y1 === y2) {
|
|
448
|
+
const forward = x2 > x1;
|
|
449
|
+
const crossings = verticals
|
|
450
|
+
.filter((v) => v.to !== edge.to && y1 > v.y1 && y1 < v.y2)
|
|
451
|
+
.map((v) => v.x)
|
|
452
|
+
.filter((vx) => vx > Math.min(x1, x2) + half && vx < Math.max(x1, x2) - half)
|
|
453
|
+
.toSorted((a, b) => (forward ? a - b : b - a));
|
|
454
|
+
const toward = forward ? -1 : 1;
|
|
455
|
+
for (const vx of crossings) {
|
|
456
|
+
pieces.at(-1)?.push([vx + toward * half, y1]);
|
|
457
|
+
pieces.push([[vx - toward * half, y1]]);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
pieces.at(-1)?.push([x2, y2]);
|
|
461
|
+
}
|
|
462
|
+
return pieces.map((points, part) => ({
|
|
463
|
+
...edge,
|
|
464
|
+
id: `${edge.id}~${part}`,
|
|
465
|
+
points,
|
|
466
|
+
}));
|
|
467
|
+
});
|
|
468
|
+
};
|
|
469
|
+
/** Each group's dots, along its track after its marker, spaced to fit before the components. */
|
|
470
|
+
const dotRows = (groups, at, hasComponents, readNow, status, width) => [...groups].map(([first, group]) => {
|
|
471
|
+
const { x: start, y } = at(`a${first}`);
|
|
472
|
+
const end = hasComponents ? componentColumn - 0.06 : 0.94;
|
|
473
|
+
const step = Math.min(72 / Math.max(width, 1), (end - start - 0.04) / group.dots.length);
|
|
474
|
+
return {
|
|
475
|
+
dots: group.dots.map((dot, index) => ({
|
|
476
|
+
...dot,
|
|
477
|
+
read: readNow.has(dot.id),
|
|
478
|
+
removed: status.get(dot.id) === "removed",
|
|
479
|
+
x: start + 0.04 + (index + 0.5) * step,
|
|
480
|
+
y,
|
|
481
|
+
})),
|
|
482
|
+
// Each dot's key fits under it only with room to spare; otherwise it's in the dot's title.
|
|
483
|
+
keys: step * Math.max(width, 1) >= 56,
|
|
484
|
+
};
|
|
485
|
+
});
|
|
486
|
+
/**
|
|
487
|
+
* Lays a graph out for a box `width` pixels wide (only the gaps at crossings and the dots' spacing
|
|
488
|
+
* depend on it: x is a fraction of the width, y is in pixels). Undefined when there's nothing to draw.
|
|
489
|
+
*/
|
|
490
|
+
export const layoutGraph = (input, width) => {
|
|
491
|
+
if (input.atoms.length === 0) {
|
|
492
|
+
return undefined;
|
|
493
|
+
}
|
|
494
|
+
const readers = input.readers ?? [];
|
|
495
|
+
// In the order they were first seen (ids count up), so an atom keeps its place and its number.
|
|
496
|
+
const atoms = new Map(input.atoms.toSorted((a, b) => a.id - b.id).map((atom) => [atom.id, atom]));
|
|
497
|
+
const status = new Map(input.atoms.map((atom) => [atom.id, atom.status]));
|
|
498
|
+
const readNow = new Set([
|
|
499
|
+
...readers.map((reader) => reader.atom),
|
|
500
|
+
...input.atoms.filter((atom) => atom.read === true).map((atom) => atom.id),
|
|
501
|
+
]);
|
|
502
|
+
const { canon, groups } = groupFamilies(atoms, readNow);
|
|
503
|
+
const canonical = (id) => canon.get(id) ?? id;
|
|
504
|
+
const parents = parentsOf(input.links, atoms, canonical);
|
|
505
|
+
const depths = depthsOf(atoms, parents);
|
|
506
|
+
const components = componentsOf(readers, atoms, canonical);
|
|
507
|
+
const shape = {
|
|
508
|
+
atomColumns: Math.max(...depths.values()) + 1,
|
|
509
|
+
atoms,
|
|
510
|
+
components,
|
|
511
|
+
depths,
|
|
512
|
+
parents,
|
|
513
|
+
};
|
|
514
|
+
const tracks = new Tracks();
|
|
515
|
+
placeComponents(shape, tracks, placeAtoms(shape, tracks));
|
|
516
|
+
const dotted = new Set([...groups.keys()].map((first) => tracks.rows.get(`a${first}`) ?? 0));
|
|
517
|
+
const { at, trackY } = positions(shape, tracks, dotted);
|
|
518
|
+
const nodes = nodesOf(shape, groups, at);
|
|
519
|
+
const lastRow = Math.max(...tracks.rows.values());
|
|
520
|
+
const { edges, lanes } = routeEdges({ at, lastRow, nodes, shape, trackY });
|
|
521
|
+
const height = trackY(lastRow) +
|
|
522
|
+
(lanes > 0 ? lanes * row - row / 2 : 0) +
|
|
523
|
+
(dotted.has(lastRow) ? keyRoom : 0) +
|
|
524
|
+
16;
|
|
525
|
+
return {
|
|
526
|
+
dots: dotRows(groups, at, components.size > 0, readNow, status, width),
|
|
527
|
+
edges: breakCrossings(edges, width),
|
|
528
|
+
height,
|
|
529
|
+
nodes,
|
|
530
|
+
};
|
|
531
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Developer tools for effect-atom-svelte: a panel that shows the atom registry live.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A panel docked along the bottom of the window, with the registry's dependency graph, a sheet per
|
|
8
|
+
* atom and a timeline of everything the registry does. Development only.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.2.0
|
|
11
|
+
* @category components
|
|
12
|
+
*/
|
|
13
|
+
export { default as AtomDevtools } from "./atom-devtools.svelte";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Developer tools for effect-atom-svelte: a panel that shows the atom registry live.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A panel docked along the bottom of the window, with the registry's dependency graph, a sheet per
|
|
8
|
+
* atom and a timeline of everything the registry does. Development only.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.2.0
|
|
11
|
+
* @category components
|
|
12
|
+
*/
|
|
13
|
+
export { default as AtomDevtools } from "./atom-devtools.svelte";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The state of an atom's value, for its marks and its sheet. */
|
|
2
|
+
export type ValueState = {
|
|
3
|
+
readonly _tag: "Value";
|
|
4
|
+
} | {
|
|
5
|
+
readonly _tag: "Initial" | "Success" | "Failure";
|
|
6
|
+
readonly waiting: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const valueState: (value: unknown) => ValueState;
|
|
9
|
+
/** A short description of the state: `Success, waiting`. */
|
|
10
|
+
export declare const stateText: (state: ValueState) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Turns a value into plain data to print: an `AsyncResult` as its tag and contents, a failure's
|
|
13
|
+
* cause pretty-printed, Effect's data types through their own `toJSON`, maps and sets as entries,
|
|
14
|
+
* and anything too deep, too long or circular cut short.
|
|
15
|
+
*/
|
|
16
|
+
export declare const plain: (value: unknown, depth?: number, seen?: Set<object>) => unknown;
|
|
17
|
+
/** The value written out in full, for its sheet. */
|
|
18
|
+
export declare const detail: (value: unknown) => string;
|
|
19
|
+
/** The value on one line, cut to `length` characters. */
|
|
20
|
+
export declare const preview: (value: unknown, length?: number) => string;
|