effect-atom-svelte-devtools 0.2.1 → 0.3.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/dist/atom-devtools.svelte +164 -43
- package/dist/atom-devtools.svelte.d.ts +2 -1
- package/dist/graph/atom-graph.svelte +40 -9
- package/dist/graph/frame-graph.svelte +45 -37
- package/dist/graph/frame-graph.svelte.d.ts +1 -24
- package/dist/graph/graph-types.d.ts +28 -0
- package/dist/graph/graph-types.js +2 -0
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/layout.d.ts +5 -2
- package/dist/graph/layout.js +8 -4
- package/dist/internal/format.d.ts +6 -6
- package/dist/internal/format.js +106 -70
- package/dist/internal/graph-view.svelte +23 -16
- package/dist/internal/label.js +40 -17
- package/dist/internal/model.svelte.js +41 -29
- package/dist/internal/names.d.ts +1 -1
- package/dist/internal/names.js +24 -4
- package/dist/internal/settings-view.svelte +35 -8
- package/dist/internal/sheets-view.svelte +112 -36
- package/dist/internal/shortcut.d.ts +4 -1
- package/dist/internal/shortcut.js +19 -7
- package/dist/internal/timeline-view.svelte +79 -26
- package/dist/internal/transform.js +179 -74
- package/dist/vite.js +4 -2
- package/package.json +9 -8
|
@@ -16,27 +16,34 @@
|
|
|
16
16
|
shows how. To show it in production too, as the effect-atom-svelte docs do, set `production`.
|
|
17
17
|
-->
|
|
18
18
|
<script lang="ts">
|
|
19
|
-
import { BROWSER, DEV } from "esm-env";
|
|
20
|
-
import type { AtomRegistry } from "effect/reactivity";
|
|
21
19
|
import { getRegistry } from "effect-atom-svelte";
|
|
22
20
|
import { inspect, watchRegistries } from "effect-atom-svelte/inspector";
|
|
21
|
+
import type { AtomRegistry } from "effect/reactivity";
|
|
22
|
+
import { BROWSER, DEV } from "esm-env";
|
|
23
23
|
import { onMount, tick } from "svelte";
|
|
24
24
|
|
|
25
25
|
import GraphView from "./internal/graph-view.svelte";
|
|
26
26
|
import { Model } from "./internal/model.svelte.js";
|
|
27
27
|
import SettingsView from "./internal/settings-view.svelte";
|
|
28
28
|
import type { Corner } from "./internal/settings-view.svelte";
|
|
29
|
-
import { defaultShortcut, formatShortcut, matchesShortcut, parseShortcut } from "./internal/shortcut.js";
|
|
30
29
|
import SheetsView from "./internal/sheets-view.svelte";
|
|
30
|
+
import {
|
|
31
|
+
defaultShortcut,
|
|
32
|
+
formatShortcut,
|
|
33
|
+
matchesShortcut,
|
|
34
|
+
parseShortcut,
|
|
35
|
+
} from "./internal/shortcut.js";
|
|
31
36
|
import TimelineView from "./internal/timeline-view.svelte";
|
|
32
37
|
|
|
38
|
+
type Theme = "auto" | "light" | "dark";
|
|
39
|
+
|
|
33
40
|
interface Props {
|
|
34
41
|
/** The registry to show. Defaults to the nearest `RegistryProvider`'s. */
|
|
35
42
|
readonly registry?: AtomRegistry.AtomRegistry | undefined;
|
|
36
43
|
/** Whether the panel starts open. Defaults to how it was left. */
|
|
37
44
|
readonly open?: boolean | undefined;
|
|
38
45
|
/** Light paper, a dark blueprint, or the page's own (`auto`: a `dark` class on `<html>`, or the system's). */
|
|
39
|
-
readonly theme?:
|
|
46
|
+
readonly theme?: Theme | undefined;
|
|
40
47
|
/**
|
|
41
48
|
* Shows the panel in production builds too, for a site that lets its visitors watch its atoms.
|
|
42
49
|
* Without it the panel renders nothing outside development. In production it follows the
|
|
@@ -65,15 +72,21 @@
|
|
|
65
72
|
readonly plumbing: boolean;
|
|
66
73
|
readonly expanded: boolean;
|
|
67
74
|
readonly height: number;
|
|
68
|
-
|
|
75
|
+
/** Only one changed in the settings: otherwise the app's, which may change. */
|
|
76
|
+
readonly shortcut: string | undefined;
|
|
69
77
|
readonly corner: Corner;
|
|
70
78
|
readonly opacity: number;
|
|
71
79
|
readonly scale: number;
|
|
80
|
+
/** Set from 0.2.2, whose `shortcut` is only one chosen in the settings; 0.2.1 saved the default. */
|
|
81
|
+
readonly shortcutChosen: true;
|
|
72
82
|
}
|
|
73
83
|
const storageKey = "effect-atom-svelte-devtools";
|
|
74
84
|
const load = (): Partial<Saved> => {
|
|
75
85
|
try {
|
|
76
|
-
|
|
86
|
+
// SAFETY: only `save` writes this key, from a `Saved`; an older version wrote a part of one.
|
|
87
|
+
return JSON.parse(
|
|
88
|
+
localStorage.getItem(storageKey) ?? "{}"
|
|
89
|
+
) as Partial<Saved>;
|
|
77
90
|
} catch {
|
|
78
91
|
return {};
|
|
79
92
|
}
|
|
@@ -120,7 +133,13 @@
|
|
|
120
133
|
showPlumbing = saved.plumbing ?? false;
|
|
121
134
|
expanded = saved.expanded ?? false;
|
|
122
135
|
height = saved.height ?? 320;
|
|
123
|
-
|
|
136
|
+
// Settings saved by 0.2.1, without `shortcutChosen`, hold the default even when nobody chose it,
|
|
137
|
+
// which would hide a shortcut the app sets: there the default counts as unset.
|
|
138
|
+
shortcut =
|
|
139
|
+
saved.shortcut === undefined ||
|
|
140
|
+
(saved.shortcutChosen !== true && saved.shortcut === defaultShortcut)
|
|
141
|
+
? appShortcut
|
|
142
|
+
: saved.shortcut;
|
|
124
143
|
corner = saved.corner ?? "bottom-right";
|
|
125
144
|
opacity = saved.opacity ?? 1;
|
|
126
145
|
scale = saved.scale ?? 1;
|
|
@@ -128,9 +147,15 @@
|
|
|
128
147
|
|
|
129
148
|
const stopWatching = watchRegistries((list) => {
|
|
130
149
|
// A registry given as a prop stays in the picker, even one no provider holds.
|
|
131
|
-
registries =
|
|
150
|
+
registries =
|
|
151
|
+
registry !== undefined && !list.includes(registry)
|
|
152
|
+
? [registry, ...list]
|
|
153
|
+
: list;
|
|
132
154
|
if (chosen === undefined || !registries.includes(chosen)) {
|
|
133
|
-
chosen =
|
|
155
|
+
chosen =
|
|
156
|
+
nearest !== undefined && registries.includes(nearest)
|
|
157
|
+
? nearest
|
|
158
|
+
: (registries[0] ?? nearest);
|
|
134
159
|
}
|
|
135
160
|
});
|
|
136
161
|
|
|
@@ -139,10 +164,10 @@
|
|
|
139
164
|
const media = matchMedia("(prefers-color-scheme: dark)");
|
|
140
165
|
const readTheme = () => {
|
|
141
166
|
dark =
|
|
142
|
-
theme === "
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
167
|
+
theme === "auto"
|
|
168
|
+
? root.classList.contains("dark") ||
|
|
169
|
+
(!root.classList.contains("light") && media.matches)
|
|
170
|
+
: theme === "dark";
|
|
146
171
|
};
|
|
147
172
|
readTheme();
|
|
148
173
|
const observer = new MutationObserver(readTheme);
|
|
@@ -179,7 +204,8 @@
|
|
|
179
204
|
open,
|
|
180
205
|
plumbing: showPlumbing,
|
|
181
206
|
scale,
|
|
182
|
-
shortcut,
|
|
207
|
+
shortcut: shortcut === appShortcut ? undefined : shortcut,
|
|
208
|
+
shortcutChosen: true,
|
|
183
209
|
tab,
|
|
184
210
|
};
|
|
185
211
|
try {
|
|
@@ -192,7 +218,9 @@
|
|
|
192
218
|
// How tall the dock is drawn: enlarged, it takes most of the window; otherwise what was dragged,
|
|
193
219
|
// kept between a usable minimum and most of the window.
|
|
194
220
|
const shown = $derived(
|
|
195
|
-
expanded
|
|
221
|
+
expanded
|
|
222
|
+
? Math.round(innerHeight * 0.85)
|
|
223
|
+
: Math.min(Math.max(height, 160), innerHeight * 0.85)
|
|
196
224
|
);
|
|
197
225
|
|
|
198
226
|
// While open, the page gets room below its end, so the dock never hides the last of it.
|
|
@@ -211,7 +239,10 @@
|
|
|
211
239
|
/** Drags the dock's top line: the dock follows the pointer until it's let go. */
|
|
212
240
|
const resize = (event: PointerEvent) => {
|
|
213
241
|
event.preventDefault();
|
|
214
|
-
const handle = event.currentTarget
|
|
242
|
+
const handle = event.currentTarget;
|
|
243
|
+
if (!(handle instanceof HTMLElement)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
215
246
|
handle.setPointerCapture(event.pointerId);
|
|
216
247
|
const start = event.clientY;
|
|
217
248
|
const from = shown;
|
|
@@ -273,13 +304,22 @@
|
|
|
273
304
|
// As aria-keyshortcuts writes it: "Alt+Shift+A".
|
|
274
305
|
const keyShortcuts = $derived.by(() => {
|
|
275
306
|
const parsed = parseShortcut(shortcut);
|
|
276
|
-
return parsed === undefined
|
|
307
|
+
return parsed === undefined
|
|
308
|
+
? undefined
|
|
309
|
+
: formatShortcut(parsed, false)
|
|
310
|
+
.replaceAll(" ", "+")
|
|
311
|
+
.replace("Ctrl", "Control");
|
|
277
312
|
});
|
|
278
313
|
|
|
279
314
|
/** The shortcut, from anywhere on the page: opens the panel, or closes it. */
|
|
280
315
|
const onShortcut = (event: KeyboardEvent) => {
|
|
281
316
|
const parsed = parseShortcut(shortcut);
|
|
282
|
-
if (
|
|
317
|
+
if (
|
|
318
|
+
!enabled ||
|
|
319
|
+
!mounted ||
|
|
320
|
+
parsed === undefined ||
|
|
321
|
+
!matchesShortcut(event, parsed)
|
|
322
|
+
) {
|
|
283
323
|
return;
|
|
284
324
|
}
|
|
285
325
|
event.preventDefault();
|
|
@@ -298,7 +338,10 @@
|
|
|
298
338
|
if (event.button !== 0) {
|
|
299
339
|
return;
|
|
300
340
|
}
|
|
301
|
-
const button = event.currentTarget
|
|
341
|
+
const button = event.currentTarget;
|
|
342
|
+
if (!(button instanceof HTMLElement)) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
302
345
|
const box = button.getBoundingClientRect();
|
|
303
346
|
const offsetX = event.clientX - box.left;
|
|
304
347
|
const offsetY = event.clientY - box.top;
|
|
@@ -311,7 +354,10 @@
|
|
|
311
354
|
// From the press on, so a quick drag that leaves the button still moves it.
|
|
312
355
|
button.setPointerCapture(event.pointerId);
|
|
313
356
|
const move = (next: PointerEvent) => {
|
|
314
|
-
if (
|
|
357
|
+
if (
|
|
358
|
+
!dragged &&
|
|
359
|
+
Math.hypot(next.clientX - startX, next.clientY - startY) < 5
|
|
360
|
+
) {
|
|
315
361
|
return;
|
|
316
362
|
}
|
|
317
363
|
dragged = true;
|
|
@@ -347,7 +393,8 @@
|
|
|
347
393
|
selected = id;
|
|
348
394
|
tab = "sheets";
|
|
349
395
|
};
|
|
350
|
-
const registryName = (index: number) =>
|
|
396
|
+
const registryName = (index: number) =>
|
|
397
|
+
index === 0 ? "registry 1" : `registry ${index + 1}`;
|
|
351
398
|
const tabs: readonly { readonly id: Tab; readonly label: string }[] = [
|
|
352
399
|
{ id: "graph", label: "Graph" },
|
|
353
400
|
{ id: "sheets", label: "Sheets" },
|
|
@@ -375,7 +422,8 @@
|
|
|
375
422
|
void closePanel();
|
|
376
423
|
}
|
|
377
424
|
}}
|
|
378
|
-
tabindex="-1"
|
|
425
|
+
tabindex="-1"
|
|
426
|
+
>
|
|
379
427
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
380
428
|
<div
|
|
381
429
|
aria-label="Resize the panel"
|
|
@@ -389,12 +437,18 @@
|
|
|
389
437
|
onpointerdown={resize}
|
|
390
438
|
role="separator"
|
|
391
439
|
tabindex="0"
|
|
392
|
-
title="Drag to resize; double-click to reset"
|
|
440
|
+
title="Drag to resize; double-click to reset"
|
|
441
|
+
></div>
|
|
393
442
|
<header class="bar">
|
|
394
443
|
<span class="cell title"><b aria-hidden="true">◎</b> Atoms</span>
|
|
395
444
|
<nav aria-label="Views" class="tabs">
|
|
396
445
|
{#each tabs as item, index (item.id)}
|
|
397
|
-
<button
|
|
446
|
+
<button
|
|
447
|
+
aria-pressed={tab === item.id}
|
|
448
|
+
class="cell tab"
|
|
449
|
+
onclick={() => (tab = item.id)}
|
|
450
|
+
type="button"
|
|
451
|
+
>
|
|
398
452
|
<b>{pad(index + 1)}</b>
|
|
399
453
|
{item.label}
|
|
400
454
|
</button>
|
|
@@ -402,18 +456,32 @@
|
|
|
402
456
|
</nav>
|
|
403
457
|
<span class="spacer"></span>
|
|
404
458
|
<span class="cell count">Atoms <b>{pad(model.totals.atoms)}</b></span>
|
|
405
|
-
<span class="cell count"
|
|
406
|
-
|
|
407
|
-
|
|
459
|
+
<span class="cell count"
|
|
460
|
+
>Readers <b>{pad(model.totals.readers)}</b></span
|
|
461
|
+
>
|
|
462
|
+
<span class="cell count"
|
|
463
|
+
>Updates <b>{pad(model.totals.updates)}</b></span
|
|
464
|
+
>
|
|
465
|
+
<span class="cell count" class:alert={model.totals.interruptions > 0}
|
|
466
|
+
>Interrupted <b>{pad(model.totals.interruptions)}</b></span
|
|
467
|
+
>
|
|
408
468
|
{#if registries.length > 1}
|
|
409
469
|
<label class="cell">
|
|
410
470
|
<span class="sr">Registry</span>
|
|
411
471
|
<select
|
|
412
472
|
class="picker"
|
|
413
|
-
onchange={(event) =>
|
|
414
|
-
|
|
473
|
+
onchange={(event) =>
|
|
474
|
+
(chosen = registries[Number(event.currentTarget.value)])}
|
|
475
|
+
value={String(
|
|
476
|
+
registries.indexOf(chosen as AtomRegistry.AtomRegistry)
|
|
477
|
+
)}
|
|
478
|
+
>
|
|
415
479
|
{#each registries as item, index (item)}
|
|
416
|
-
<option value={String(index)}
|
|
480
|
+
<option value={String(index)}
|
|
481
|
+
>{registryName(index)}{item === nearest
|
|
482
|
+
? " (this one)"
|
|
483
|
+
: ""}</option
|
|
484
|
+
>
|
|
417
485
|
{/each}
|
|
418
486
|
</select>
|
|
419
487
|
</label>
|
|
@@ -422,43 +490,85 @@
|
|
|
422
490
|
<input bind:checked={showPlumbing} type="checkbox" />
|
|
423
491
|
Plumbing
|
|
424
492
|
</label>
|
|
425
|
-
<button
|
|
493
|
+
<button
|
|
494
|
+
aria-label={expanded ? "Shrink the panel" : "Enlarge the panel"}
|
|
495
|
+
class="cell icon"
|
|
496
|
+
onclick={() => (expanded = !expanded)}
|
|
497
|
+
title={expanded ? "Shrink" : "Enlarge"}
|
|
498
|
+
type="button"
|
|
499
|
+
>
|
|
426
500
|
<svg aria-hidden="true" height="12" viewBox="0 0 12 12" width="12">
|
|
427
501
|
{#if expanded}
|
|
428
|
-
<path
|
|
502
|
+
<path
|
|
503
|
+
d="M2 5h8M2 7h8"
|
|
504
|
+
fill="none"
|
|
505
|
+
stroke="currentColor"
|
|
506
|
+
stroke-width="1.25"
|
|
507
|
+
/>
|
|
429
508
|
{:else}
|
|
430
|
-
<path
|
|
509
|
+
<path
|
|
510
|
+
d="M2 4l4-3 4 3M2 8l4 3 4-3"
|
|
511
|
+
fill="none"
|
|
512
|
+
stroke="currentColor"
|
|
513
|
+
stroke-width="1.25"
|
|
514
|
+
/>
|
|
431
515
|
{/if}
|
|
432
516
|
</svg>
|
|
433
517
|
</button>
|
|
434
|
-
<button
|
|
518
|
+
<button
|
|
519
|
+
aria-label="Close the panel"
|
|
520
|
+
class="cell icon"
|
|
521
|
+
onclick={closePanel}
|
|
522
|
+
title="Close (Esc)"
|
|
523
|
+
type="button"
|
|
524
|
+
>
|
|
435
525
|
<svg aria-hidden="true" height="12" viewBox="0 0 12 12" width="12">
|
|
436
|
-
<path
|
|
526
|
+
<path
|
|
527
|
+
d="M2.5 2.5l7 7M9.5 2.5l-7 7"
|
|
528
|
+
fill="none"
|
|
529
|
+
stroke="currentColor"
|
|
530
|
+
stroke-width="1.25"
|
|
531
|
+
/>
|
|
437
532
|
</svg>
|
|
438
533
|
</button>
|
|
439
534
|
</header>
|
|
440
535
|
|
|
441
536
|
{#if model.partial}
|
|
442
537
|
<p class="notice">
|
|
443
|
-
This registry isn't the one effect-atom-svelte's inspector was
|
|
538
|
+
This registry isn't the one effect-atom-svelte's inspector was
|
|
539
|
+
written for (a newer Effect?), so only atoms added and removed are
|
|
540
|
+
shown.
|
|
444
541
|
</p>
|
|
445
542
|
{:else if model.unlabelled}
|
|
446
543
|
<p class="notice">
|
|
447
|
-
No atom has a name. Add <code>atomLabels()</code> from
|
|
544
|
+
No atom has a name. Add <code>atomLabels()</code> from
|
|
545
|
+
<code>effect-atom-svelte-devtools/vite</code> to your Vite config to name
|
|
546
|
+
them after their variables.
|
|
448
547
|
</p>
|
|
449
548
|
{/if}
|
|
450
549
|
|
|
451
550
|
<div class="body">
|
|
452
551
|
{#if tab === "graph"}
|
|
453
552
|
<div class="scroll">
|
|
454
|
-
<GraphView
|
|
553
|
+
<GraphView
|
|
554
|
+
atoms={model.atoms}
|
|
555
|
+
onselect={select}
|
|
556
|
+
{selected}
|
|
557
|
+
{showPlumbing}
|
|
558
|
+
/>
|
|
455
559
|
</div>
|
|
456
560
|
{:else if tab === "sheets"}
|
|
457
561
|
<SheetsView {model} onselect={select} {selected} {showPlumbing} />
|
|
458
562
|
{:else if tab === "timeline"}
|
|
459
563
|
<TimelineView {model} onselect={select} {showPlumbing} />
|
|
460
564
|
{:else}
|
|
461
|
-
<SettingsView
|
|
565
|
+
<SettingsView
|
|
566
|
+
bind:corner
|
|
567
|
+
bind:opacity
|
|
568
|
+
bind:scale
|
|
569
|
+
bind:shortcut
|
|
570
|
+
defaultShortcut={appShortcut}
|
|
571
|
+
/>
|
|
462
572
|
{/if}
|
|
463
573
|
</div>
|
|
464
574
|
</section>
|
|
@@ -475,8 +585,10 @@
|
|
|
475
585
|
onclick={launch}
|
|
476
586
|
onpointerdown={drag}
|
|
477
587
|
title="Atom devtools ({shortcutLabel}). Drag to move."
|
|
478
|
-
type="button"
|
|
479
|
-
|
|
588
|
+
type="button"
|
|
589
|
+
>
|
|
590
|
+
<b aria-hidden="true">◎</b> Atoms
|
|
591
|
+
<span class="n">{pad(model.totals.atoms)}</span>
|
|
480
592
|
</button>
|
|
481
593
|
{/if}
|
|
482
594
|
</div>
|
|
@@ -501,7 +613,15 @@
|
|
|
501
613
|
--pulse: var(--accent);
|
|
502
614
|
--success: var(--tone-success, #16a34a);
|
|
503
615
|
--alert: var(--tone-failure, #dc2626);
|
|
504
|
-
--mono: var(
|
|
616
|
+
--mono: var(
|
|
617
|
+
--font-mono,
|
|
618
|
+
ui-monospace,
|
|
619
|
+
"SF Mono",
|
|
620
|
+
"JetBrains Mono",
|
|
621
|
+
Menlo,
|
|
622
|
+
Consolas,
|
|
623
|
+
monospace
|
|
624
|
+
);
|
|
505
625
|
--serif: var(--font-serif, ui-serif, Georgia, "Times New Roman", serif);
|
|
506
626
|
--radius: 6px;
|
|
507
627
|
color: var(--ink);
|
|
@@ -627,7 +747,8 @@
|
|
|
627
747
|
outline: none;
|
|
628
748
|
}
|
|
629
749
|
.resize:hover {
|
|
630
|
-
box-shadow: inset 0 -1px 0
|
|
750
|
+
box-shadow: inset 0 -1px 0
|
|
751
|
+
color-mix(in oklab, var(--accent) 60%, transparent);
|
|
631
752
|
}
|
|
632
753
|
/* The bar: a row of ruled cells, as the docs' site header is. */
|
|
633
754
|
.bar {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { AtomRegistry } from "effect/reactivity";
|
|
2
|
+
type Theme = "auto" | "light" | "dark";
|
|
2
3
|
interface Props {
|
|
3
4
|
/** The registry to show. Defaults to the nearest `RegistryProvider`'s. */
|
|
4
5
|
readonly registry?: AtomRegistry.AtomRegistry | undefined;
|
|
5
6
|
/** Whether the panel starts open. Defaults to how it was left. */
|
|
6
7
|
readonly open?: boolean | undefined;
|
|
7
8
|
/** Light paper, a dark blueprint, or the page's own (`auto`: a `dark` class on `<html>`, or the system's). */
|
|
8
|
-
readonly theme?:
|
|
9
|
+
readonly theme?: Theme | undefined;
|
|
9
10
|
/**
|
|
10
11
|
* Shows the panel in production builds too, for a site that lets its visitors watch its atoms.
|
|
11
12
|
* Without it the panel renders nothing outside development. In production it follows the
|
|
@@ -59,7 +59,9 @@
|
|
|
59
59
|
mark.dataset.tone = tone;
|
|
60
60
|
replay(mark, "pulse");
|
|
61
61
|
}
|
|
62
|
-
for (const edge of host?.querySelectorAll<HTMLElement>(
|
|
62
|
+
for (const edge of host?.querySelectorAll<HTMLElement>(
|
|
63
|
+
`[data-to="a${id}"]`
|
|
64
|
+
) ?? []) {
|
|
63
65
|
edge.dataset.tone = tone;
|
|
64
66
|
replay(edge, "flash");
|
|
65
67
|
}
|
|
@@ -74,7 +76,10 @@
|
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
const click = (event: MouseEvent) => {
|
|
77
|
-
const target =
|
|
79
|
+
const target =
|
|
80
|
+
event.target instanceof Element
|
|
81
|
+
? event.target.closest<HTMLElement>("[data-node]")
|
|
82
|
+
: null;
|
|
78
83
|
const id = target?.dataset.node;
|
|
79
84
|
if (onselect && id?.startsWith("a")) {
|
|
80
85
|
onselect(Number(id.slice(1)));
|
|
@@ -82,11 +87,17 @@
|
|
|
82
87
|
};
|
|
83
88
|
|
|
84
89
|
$effect(() => {
|
|
85
|
-
|
|
90
|
+
// Again after each new layout: a node whose kind or side changes has its classes written over,
|
|
91
|
+
// and a node drawn later has none.
|
|
92
|
+
void layout;
|
|
93
|
+
for (const element of host?.querySelectorAll("[data-node].selected") ??
|
|
94
|
+
[]) {
|
|
86
95
|
element.classList.remove("selected");
|
|
87
96
|
}
|
|
88
97
|
if (selected !== undefined) {
|
|
89
|
-
host
|
|
98
|
+
host
|
|
99
|
+
?.querySelector(`[data-node="a${selected}"]`)
|
|
100
|
+
?.classList.add("selected");
|
|
90
101
|
}
|
|
91
102
|
});
|
|
92
103
|
</script>
|
|
@@ -101,13 +112,22 @@
|
|
|
101
112
|
onclick={onselect ? click : undefined}
|
|
102
113
|
>
|
|
103
114
|
{#if layout}
|
|
104
|
-
<FrameGraph
|
|
115
|
+
<FrameGraph
|
|
116
|
+
edges={layout.edges}
|
|
117
|
+
interactive={onselect !== undefined}
|
|
118
|
+
nodes={layout.nodes}
|
|
119
|
+
/>
|
|
105
120
|
{#each layout.dots as row, index (index)}
|
|
106
121
|
{#each row.dots as dot (dot.id)}
|
|
107
122
|
<span
|
|
108
123
|
style:left="{dot.x * width}px"
|
|
109
124
|
style:top="{dot.y}px"
|
|
110
|
-
class={[
|
|
125
|
+
class={[
|
|
126
|
+
"dot",
|
|
127
|
+
dot.read && "read",
|
|
128
|
+
dot.repeat && "repeat",
|
|
129
|
+
dot.removed && "removed",
|
|
130
|
+
]}
|
|
111
131
|
data-node="a{dot.id}"
|
|
112
132
|
title={dot.label}
|
|
113
133
|
>
|
|
@@ -180,15 +200,26 @@
|
|
|
180
200
|
}
|
|
181
201
|
.dot.removed i {
|
|
182
202
|
background:
|
|
183
|
-
linear-gradient(
|
|
184
|
-
|
|
203
|
+
linear-gradient(
|
|
204
|
+
45deg,
|
|
205
|
+
transparent 42%,
|
|
206
|
+
var(--brand-text, #b45309) 42% 58%,
|
|
207
|
+
transparent 58%
|
|
208
|
+
),
|
|
209
|
+
linear-gradient(
|
|
210
|
+
-45deg,
|
|
211
|
+
transparent 42%,
|
|
212
|
+
var(--brand-text, #b45309) 42% 58%,
|
|
213
|
+
transparent 58%
|
|
214
|
+
);
|
|
185
215
|
border: 0;
|
|
186
216
|
}
|
|
187
217
|
.dot:global(.pulse) i {
|
|
188
218
|
animation: dot-mark 0.9s ease-out;
|
|
189
219
|
}
|
|
190
220
|
.dot:global(.selected) i {
|
|
191
|
-
box-shadow: 0 0 0 3px
|
|
221
|
+
box-shadow: 0 0 0 3px
|
|
222
|
+
color-mix(in oklab, var(--brand, #d97706) 40%, transparent);
|
|
192
223
|
}
|
|
193
224
|
.key {
|
|
194
225
|
color: var(--muted-foreground, #52525b);
|
|
@@ -13,36 +13,8 @@
|
|
|
13
13
|
rounds a 1px line to whole device pixels; drawn the same way from the same coordinate, the graph
|
|
14
14
|
rounds the same way, so it stays on its line. Edges must be horizontal or vertical.
|
|
15
15
|
-->
|
|
16
|
-
<script module lang="ts">
|
|
17
|
-
export type Kind = "effect" | "atom" | "component" | "junction" | "gone";
|
|
18
|
-
|
|
19
|
-
export interface GraphNode {
|
|
20
|
-
readonly x: number;
|
|
21
|
-
readonly y: number;
|
|
22
|
-
readonly kind: Kind;
|
|
23
|
-
readonly label?: string | undefined;
|
|
24
|
-
readonly note?: string | undefined;
|
|
25
|
-
/** Which side of the node its label sits: north-east (the default), south-east, and so on. */
|
|
26
|
-
readonly side?: "ne" | "se" | "nw" | "sw" | undefined;
|
|
27
|
-
/** The step at which it appears, with the edge that reaches it. */
|
|
28
|
-
readonly step?: number | undefined;
|
|
29
|
-
/** Names the node, for a live graph to find it again (`data-node`) and pulse it. */
|
|
30
|
-
readonly id?: string | undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface GraphEdge {
|
|
34
|
-
readonly points: readonly (readonly [x: number, y: number])[];
|
|
35
|
-
readonly lit?: boolean | undefined;
|
|
36
|
-
readonly dashed?: boolean | undefined;
|
|
37
|
-
readonly step?: number | undefined;
|
|
38
|
-
/** The node it leads to (`data-to`), so a live graph can light the edges into a node. */
|
|
39
|
-
readonly to?: string | undefined;
|
|
40
|
-
/** Keeps an edge's element across redraws of a live graph. */
|
|
41
|
-
readonly id?: string | undefined;
|
|
42
|
-
}
|
|
43
|
-
</script>
|
|
44
|
-
|
|
45
16
|
<script lang="ts">
|
|
17
|
+
import type { GraphEdge, GraphNode, Kind } from "./graph-types.js";
|
|
46
18
|
/**
|
|
47
19
|
* Where the frame's lines start, from the graph's box: `left` is the left edge of the line at
|
|
48
20
|
* x = 0, `right` that of the line at x = 1 less the box's width, and `top` is added to every y.
|
|
@@ -57,7 +29,11 @@
|
|
|
57
29
|
/** Whether atoms take clicks (atom-graph.svelte selects them); the rest stays inert. */
|
|
58
30
|
interactive?: boolean;
|
|
59
31
|
nodes: readonly GraphNode[];
|
|
60
|
-
origin?: {
|
|
32
|
+
origin?: {
|
|
33
|
+
readonly left: number;
|
|
34
|
+
readonly right: number;
|
|
35
|
+
readonly top: number;
|
|
36
|
+
};
|
|
61
37
|
} = $props();
|
|
62
38
|
|
|
63
39
|
// contentRect keeps fractions of a pixel, which clientWidth would round away.
|
|
@@ -173,7 +149,11 @@
|
|
|
173
149
|
/* A run of an edge: a 1px border, like the frame's own lines. */
|
|
174
150
|
/* Solid, mixed with what's behind the graph: a translucent line brightens where two runs overlap. */
|
|
175
151
|
.edge {
|
|
176
|
-
--edge: color-mix(
|
|
152
|
+
--edge: color-mix(
|
|
153
|
+
in oklab,
|
|
154
|
+
var(--foreground, #18181b) 30%,
|
|
155
|
+
var(--graph-background, var(--background, #fff))
|
|
156
|
+
);
|
|
177
157
|
position: absolute;
|
|
178
158
|
}
|
|
179
159
|
.edge.horizontal {
|
|
@@ -205,7 +185,8 @@
|
|
|
205
185
|
pointer-events: auto;
|
|
206
186
|
}
|
|
207
187
|
.node:global(.selected) i {
|
|
208
|
-
box-shadow: 0 0 0 3px
|
|
188
|
+
box-shadow: 0 0 0 3px
|
|
189
|
+
color-mix(in oklab, var(--brand, #d97706) 40%, transparent);
|
|
209
190
|
}
|
|
210
191
|
/* Above every edge, so labels and marks are never crossed. */
|
|
211
192
|
.node {
|
|
@@ -253,15 +234,32 @@
|
|
|
253
234
|
}
|
|
254
235
|
.node.gone i {
|
|
255
236
|
background:
|
|
256
|
-
linear-gradient(
|
|
257
|
-
|
|
237
|
+
linear-gradient(
|
|
238
|
+
45deg,
|
|
239
|
+
transparent 45%,
|
|
240
|
+
var(--brand-text, #b45309) 45% 55%,
|
|
241
|
+
transparent 55%
|
|
242
|
+
),
|
|
243
|
+
linear-gradient(
|
|
244
|
+
-45deg,
|
|
245
|
+
transparent 45%,
|
|
246
|
+
var(--brand-text, #b45309) 45% 55%,
|
|
247
|
+
transparent 55%
|
|
248
|
+
);
|
|
258
249
|
border: 0;
|
|
259
250
|
}
|
|
260
251
|
/* Backed with what's behind the graph (--graph-background), so a label hides the lines under it. */
|
|
261
252
|
.label {
|
|
262
253
|
background: var(--graph-background, var(--background, #fff));
|
|
263
254
|
color: var(--foreground, #18181b);
|
|
264
|
-
font-family: var(
|
|
255
|
+
font-family: var(
|
|
256
|
+
--font-mono,
|
|
257
|
+
ui-monospace,
|
|
258
|
+
"SF Mono",
|
|
259
|
+
Menlo,
|
|
260
|
+
Consolas,
|
|
261
|
+
monospace
|
|
262
|
+
);
|
|
265
263
|
font-size: 0.7rem;
|
|
266
264
|
line-height: 1.3;
|
|
267
265
|
padding: 0 0.3rem;
|
|
@@ -383,8 +381,18 @@
|
|
|
383
381
|
0%,
|
|
384
382
|
60% {
|
|
385
383
|
background:
|
|
386
|
-
linear-gradient(
|
|
387
|
-
|
|
384
|
+
linear-gradient(
|
|
385
|
+
45deg,
|
|
386
|
+
transparent 42%,
|
|
387
|
+
var(--brand-text, #b45309) 42% 58%,
|
|
388
|
+
transparent 58%
|
|
389
|
+
),
|
|
390
|
+
linear-gradient(
|
|
391
|
+
-45deg,
|
|
392
|
+
transparent 42%,
|
|
393
|
+
var(--brand-text, #b45309) 42% 58%,
|
|
394
|
+
transparent 58%
|
|
395
|
+
);
|
|
388
396
|
border-color: var(--brand-text, #b45309);
|
|
389
397
|
scale: 1.4;
|
|
390
398
|
}
|
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export interface GraphNode {
|
|
3
|
-
readonly x: number;
|
|
4
|
-
readonly y: number;
|
|
5
|
-
readonly kind: Kind;
|
|
6
|
-
readonly label?: string | undefined;
|
|
7
|
-
readonly note?: string | undefined;
|
|
8
|
-
/** Which side of the node its label sits: north-east (the default), south-east, and so on. */
|
|
9
|
-
readonly side?: "ne" | "se" | "nw" | "sw" | undefined;
|
|
10
|
-
/** The step at which it appears, with the edge that reaches it. */
|
|
11
|
-
readonly step?: number | undefined;
|
|
12
|
-
/** Names the node, for a live graph to find it again (`data-node`) and pulse it. */
|
|
13
|
-
readonly id?: string | undefined;
|
|
14
|
-
}
|
|
15
|
-
export interface GraphEdge {
|
|
16
|
-
readonly points: readonly (readonly [x: number, y: number])[];
|
|
17
|
-
readonly lit?: boolean | undefined;
|
|
18
|
-
readonly dashed?: boolean | undefined;
|
|
19
|
-
readonly step?: number | undefined;
|
|
20
|
-
/** The node it leads to (`data-to`), so a live graph can light the edges into a node. */
|
|
21
|
-
readonly to?: string | undefined;
|
|
22
|
-
/** Keeps an edge's element across redraws of a live graph. */
|
|
23
|
-
readonly id?: string | undefined;
|
|
24
|
-
}
|
|
1
|
+
import type { GraphEdge, GraphNode } from "./graph-types.ts";
|
|
25
2
|
type $$ComponentProps = {
|
|
26
3
|
edges: readonly GraphEdge[];
|
|
27
4
|
/** Whether atoms take clicks (atom-graph.svelte selects them); the rest stays inert. */
|