effect-atom-svelte-devtools 0.2.2 → 0.4.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/README.md CHANGED
@@ -6,7 +6,7 @@ Developer tools for [effect-atom-svelte](https://atom.jarrednorris.dev): a panel
6
6
  bun add -D effect-atom-svelte-devtools
7
7
  ```
8
8
 
9
- It reads effect-atom-svelte's inspector, which is new in effect-atom-svelte 0.2: devtools 0.2 goes with effect-atom-svelte 0.2.
9
+ It reads effect-atom-svelte's inspector (`effect-atom-svelte/inspector`), so each release works with particular effect-atom-svelte versions: its `peerDependencies` say which.
10
10
 
11
11
  ## The panel
12
12
 
@@ -42,7 +42,7 @@ It has three views, and settings:
42
42
 
43
43
  - **Graph**: the atoms and what reads what, laid out on tracks with sources on the left, as the effect-atom-svelte docs draw their examples. A value that changes rings, in green when it's a `Success` and red when it's a `Failure`; a cross marks an interrupted effect or a removed atom; a family's atoms share a row of dots. Click an atom to open its sheet. "Plumbing" shows the atoms runtimes, mutations and stores make, which are hidden by default; an atom that reads one is linked to whatever is upstream of it.
44
44
  - **Sheets**: a cover sheet with the registry's totals, then one sheet per atom: its value or `AsyncResult` state, what it reads and what reads it, what happened to it lately, and a title block with where it was declared (click to open it in your editor), keep-alive, idle TTL and readers.
45
- - **Timeline**: every computation, update, interruption and finalizer, newest first. A computation says why it ran: its first read, a refresh, or which atoms it reads changed. Click an atom to see only its rows.
45
+ - **Timeline**: every computation, update, interruption and finalizer, newest first. A computation says why it ran: its first read, a refresh, which atoms it reads changed, or an invalidation, such as a reactivity key a mutation invalidated or the atom refreshing itself. Click an atom to see only its rows.
46
46
  - **Settings**: the shortcut (click Change and press a new one: it needs Ctrl, Alt or Meta, or a function key, so it can't catch typing), and the button's corner, opacity and size. Drag the button to move it, too: it settles in the nearest corner. A faded button is opaque again while you point at it or focus it. The panel saves its settings in `localStorage`.
47
47
 
48
48
  It follows the registry of the nearest `RegistryProvider`, or a `registry` you pass it. With more than one provider mounted, a picker switches between them. It reads what the registry does through `effect-atom-svelte/inspector`, which starts watching when the panel mounts and costs nothing before.
@@ -104,6 +104,7 @@ export default defineConfig({
104
104
 
105
105
  - Only the dev server applies it, unless you pass `builds: true`: then production builds are labelled too (without keeping values across reloads, which builds don't have), for a page that shows atoms' names in production.
106
106
  - Put it before `sveltekit()` or `svelte()`, so it sees components before they are compiled. It warns if it comes after.
107
+ - `include` and `exclude` pick the files it labels, as Vite filter patterns. By default it labels Svelte components and JavaScript and TypeScript modules, and leaves anything in `node_modules` alone.
107
108
  - The atom is labelled in place and keeps its identity. `Atom.withLabel` would return a copy.
108
109
  - A label your code sets with `Atom.withLabel` wins. The one an `Atom.serializable` atom takes from its key (an RPC query's `AtomRpc:listTodos:home-todos`) gives way to the variable's name.
109
110
  - Members of an `Atom.family` are labelled with their argument, as `todoAtom(3)`.
@@ -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?: "auto" | "light" | "dark" | undefined;
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
@@ -76,7 +83,10 @@
76
83
  const storageKey = "effect-atom-svelte-devtools";
77
84
  const load = (): Partial<Saved> => {
78
85
  try {
79
- return JSON.parse(localStorage.getItem(storageKey) ?? "{}") as Partial<Saved>;
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>;
80
90
  } catch {
81
91
  return {};
82
92
  }
@@ -137,9 +147,15 @@
137
147
 
138
148
  const stopWatching = watchRegistries((list) => {
139
149
  // A registry given as a prop stays in the picker, even one no provider holds.
140
- registries = registry !== undefined && !list.includes(registry) ? [registry, ...list] : list;
150
+ registries =
151
+ registry !== undefined && !list.includes(registry)
152
+ ? [registry, ...list]
153
+ : list;
141
154
  if (chosen === undefined || !registries.includes(chosen)) {
142
- chosen = nearest !== undefined && registries.includes(nearest) ? nearest : (registries[0] ?? nearest);
155
+ chosen =
156
+ nearest !== undefined && registries.includes(nearest)
157
+ ? nearest
158
+ : (registries[0] ?? nearest);
143
159
  }
144
160
  });
145
161
 
@@ -148,10 +164,10 @@
148
164
  const media = matchMedia("(prefers-color-scheme: dark)");
149
165
  const readTheme = () => {
150
166
  dark =
151
- theme === "dark" ||
152
- (theme === "auto" &&
153
- (root.classList.contains("dark") ||
154
- (!root.classList.contains("light") && media.matches)));
167
+ theme === "auto"
168
+ ? root.classList.contains("dark") ||
169
+ (!root.classList.contains("light") && media.matches)
170
+ : theme === "dark";
155
171
  };
156
172
  readTheme();
157
173
  const observer = new MutationObserver(readTheme);
@@ -202,7 +218,9 @@
202
218
  // How tall the dock is drawn: enlarged, it takes most of the window; otherwise what was dragged,
203
219
  // kept between a usable minimum and most of the window.
204
220
  const shown = $derived(
205
- expanded ? Math.round(innerHeight * 0.85) : Math.min(Math.max(height, 160), innerHeight * 0.85)
221
+ expanded
222
+ ? Math.round(innerHeight * 0.85)
223
+ : Math.min(Math.max(height, 160), innerHeight * 0.85)
206
224
  );
207
225
 
208
226
  // While open, the page gets room below its end, so the dock never hides the last of it.
@@ -221,7 +239,10 @@
221
239
  /** Drags the dock's top line: the dock follows the pointer until it's let go. */
222
240
  const resize = (event: PointerEvent) => {
223
241
  event.preventDefault();
224
- const handle = event.currentTarget as HTMLElement;
242
+ const handle = event.currentTarget;
243
+ if (!(handle instanceof HTMLElement)) {
244
+ return;
245
+ }
225
246
  handle.setPointerCapture(event.pointerId);
226
247
  const start = event.clientY;
227
248
  const from = shown;
@@ -283,13 +304,22 @@
283
304
  // As aria-keyshortcuts writes it: "Alt+Shift+A".
284
305
  const keyShortcuts = $derived.by(() => {
285
306
  const parsed = parseShortcut(shortcut);
286
- return parsed === undefined ? undefined : formatShortcut(parsed, false).replaceAll(" ", "+").replace("Ctrl", "Control");
307
+ return parsed === undefined
308
+ ? undefined
309
+ : formatShortcut(parsed, false)
310
+ .replaceAll(" ", "+")
311
+ .replace("Ctrl", "Control");
287
312
  });
288
313
 
289
314
  /** The shortcut, from anywhere on the page: opens the panel, or closes it. */
290
315
  const onShortcut = (event: KeyboardEvent) => {
291
316
  const parsed = parseShortcut(shortcut);
292
- if (!enabled || !mounted || parsed === undefined || !matchesShortcut(event, parsed)) {
317
+ if (
318
+ !enabled ||
319
+ !mounted ||
320
+ parsed === undefined ||
321
+ !matchesShortcut(event, parsed)
322
+ ) {
293
323
  return;
294
324
  }
295
325
  event.preventDefault();
@@ -308,7 +338,10 @@
308
338
  if (event.button !== 0) {
309
339
  return;
310
340
  }
311
- const button = event.currentTarget as HTMLElement;
341
+ const button = event.currentTarget;
342
+ if (!(button instanceof HTMLElement)) {
343
+ return;
344
+ }
312
345
  const box = button.getBoundingClientRect();
313
346
  const offsetX = event.clientX - box.left;
314
347
  const offsetY = event.clientY - box.top;
@@ -321,7 +354,10 @@
321
354
  // From the press on, so a quick drag that leaves the button still moves it.
322
355
  button.setPointerCapture(event.pointerId);
323
356
  const move = (next: PointerEvent) => {
324
- if (!dragged && Math.hypot(next.clientX - startX, next.clientY - startY) < 5) {
357
+ if (
358
+ !dragged &&
359
+ Math.hypot(next.clientX - startX, next.clientY - startY) < 5
360
+ ) {
325
361
  return;
326
362
  }
327
363
  dragged = true;
@@ -357,7 +393,8 @@
357
393
  selected = id;
358
394
  tab = "sheets";
359
395
  };
360
- const registryName = (index: number) => (index === 0 ? "registry 1" : `registry ${index + 1}`);
396
+ const registryName = (index: number) =>
397
+ index === 0 ? "registry 1" : `registry ${index + 1}`;
361
398
  const tabs: readonly { readonly id: Tab; readonly label: string }[] = [
362
399
  { id: "graph", label: "Graph" },
363
400
  { id: "sheets", label: "Sheets" },
@@ -385,7 +422,8 @@
385
422
  void closePanel();
386
423
  }
387
424
  }}
388
- tabindex="-1">
425
+ tabindex="-1"
426
+ >
389
427
  <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
390
428
  <div
391
429
  aria-label="Resize the panel"
@@ -399,12 +437,18 @@
399
437
  onpointerdown={resize}
400
438
  role="separator"
401
439
  tabindex="0"
402
- title="Drag to resize; double-click to reset"></div>
440
+ title="Drag to resize; double-click to reset"
441
+ ></div>
403
442
  <header class="bar">
404
443
  <span class="cell title"><b aria-hidden="true">◎</b> Atoms</span>
405
444
  <nav aria-label="Views" class="tabs">
406
445
  {#each tabs as item, index (item.id)}
407
- <button aria-pressed={tab === item.id} class="cell tab" onclick={() => (tab = item.id)} type="button">
446
+ <button
447
+ aria-pressed={tab === item.id}
448
+ class="cell tab"
449
+ onclick={() => (tab = item.id)}
450
+ type="button"
451
+ >
408
452
  <b>{pad(index + 1)}</b>
409
453
  {item.label}
410
454
  </button>
@@ -412,18 +456,32 @@
412
456
  </nav>
413
457
  <span class="spacer"></span>
414
458
  <span class="cell count">Atoms <b>{pad(model.totals.atoms)}</b></span>
415
- <span class="cell count">Readers <b>{pad(model.totals.readers)}</b></span>
416
- <span class="cell count">Updates <b>{pad(model.totals.updates)}</b></span>
417
- <span class="cell count" class:alert={model.totals.interruptions > 0}>Interrupted <b>{pad(model.totals.interruptions)}</b></span>
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
+ >
418
468
  {#if registries.length > 1}
419
469
  <label class="cell">
420
470
  <span class="sr">Registry</span>
421
471
  <select
422
472
  class="picker"
423
- onchange={(event) => (chosen = registries[Number(event.currentTarget.value)])}
424
- value={String(registries.indexOf(chosen as AtomRegistry.AtomRegistry))}>
473
+ onchange={(event) =>
474
+ (chosen = registries[Number(event.currentTarget.value)])}
475
+ value={String(
476
+ registries.indexOf(chosen as AtomRegistry.AtomRegistry)
477
+ )}
478
+ >
425
479
  {#each registries as item, index (item)}
426
- <option value={String(index)}>{registryName(index)}{item === nearest ? " (this one)" : ""}</option>
480
+ <option value={String(index)}
481
+ >{registryName(index)}{item === nearest
482
+ ? " (this one)"
483
+ : ""}</option
484
+ >
427
485
  {/each}
428
486
  </select>
429
487
  </label>
@@ -432,43 +490,85 @@
432
490
  <input bind:checked={showPlumbing} type="checkbox" />
433
491
  Plumbing
434
492
  </label>
435
- <button aria-label={expanded ? "Shrink the panel" : "Enlarge the panel"} class="cell icon" onclick={() => (expanded = !expanded)} title={expanded ? "Shrink" : "Enlarge"} type="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
+ >
436
500
  <svg aria-hidden="true" height="12" viewBox="0 0 12 12" width="12">
437
501
  {#if expanded}
438
- <path d="M2 5h8M2 7h8" fill="none" stroke="currentColor" stroke-width="1.25" />
502
+ <path
503
+ d="M2 5h8M2 7h8"
504
+ fill="none"
505
+ stroke="currentColor"
506
+ stroke-width="1.25"
507
+ />
439
508
  {:else}
440
- <path d="M2 4l4-3 4 3M2 8l4 3 4-3" fill="none" stroke="currentColor" stroke-width="1.25" />
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
+ />
441
515
  {/if}
442
516
  </svg>
443
517
  </button>
444
- <button aria-label="Close the panel" class="cell icon" onclick={closePanel} title="Close (Esc)" type="button">
518
+ <button
519
+ aria-label="Close the panel"
520
+ class="cell icon"
521
+ onclick={closePanel}
522
+ title="Close (Esc)"
523
+ type="button"
524
+ >
445
525
  <svg aria-hidden="true" height="12" viewBox="0 0 12 12" width="12">
446
- <path d="M2.5 2.5l7 7M9.5 2.5l-7 7" fill="none" stroke="currentColor" stroke-width="1.25" />
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
+ />
447
532
  </svg>
448
533
  </button>
449
534
  </header>
450
535
 
451
536
  {#if model.partial}
452
537
  <p class="notice">
453
- This registry isn't the one effect-atom-svelte's inspector was written for (a newer Effect?), so only atoms added and removed are shown.
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.
454
541
  </p>
455
542
  {:else if model.unlabelled}
456
543
  <p class="notice">
457
- No atom has a name. Add <code>atomLabels()</code> from <code>effect-atom-svelte-devtools/vite</code> to your Vite config to name them after their variables.
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.
458
547
  </p>
459
548
  {/if}
460
549
 
461
550
  <div class="body">
462
551
  {#if tab === "graph"}
463
552
  <div class="scroll">
464
- <GraphView atoms={model.atoms} onselect={select} {selected} {showPlumbing} />
553
+ <GraphView
554
+ atoms={model.atoms}
555
+ onselect={select}
556
+ {selected}
557
+ {showPlumbing}
558
+ />
465
559
  </div>
466
560
  {:else if tab === "sheets"}
467
561
  <SheetsView {model} onselect={select} {selected} {showPlumbing} />
468
562
  {:else if tab === "timeline"}
469
563
  <TimelineView {model} onselect={select} {showPlumbing} />
470
564
  {:else}
471
- <SettingsView bind:corner bind:opacity bind:scale bind:shortcut defaultShortcut={appShortcut} />
565
+ <SettingsView
566
+ bind:corner
567
+ bind:opacity
568
+ bind:scale
569
+ bind:shortcut
570
+ defaultShortcut={appShortcut}
571
+ />
472
572
  {/if}
473
573
  </div>
474
574
  </section>
@@ -485,8 +585,10 @@
485
585
  onclick={launch}
486
586
  onpointerdown={drag}
487
587
  title="Atom devtools ({shortcutLabel}). Drag to move."
488
- type="button">
489
- <b aria-hidden="true">◎</b> Atoms <span class="n">{pad(model.totals.atoms)}</span>
588
+ type="button"
589
+ >
590
+ <b aria-hidden="true">◎</b> Atoms
591
+ <span class="n">{pad(model.totals.atoms)}</span>
490
592
  </button>
491
593
  {/if}
492
594
  </div>
@@ -511,7 +613,15 @@
511
613
  --pulse: var(--accent);
512
614
  --success: var(--tone-success, #16a34a);
513
615
  --alert: var(--tone-failure, #dc2626);
514
- --mono: var(--font-mono, ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace);
616
+ --mono: var(
617
+ --font-mono,
618
+ ui-monospace,
619
+ "SF Mono",
620
+ "JetBrains Mono",
621
+ Menlo,
622
+ Consolas,
623
+ monospace
624
+ );
515
625
  --serif: var(--font-serif, ui-serif, Georgia, "Times New Roman", serif);
516
626
  --radius: 6px;
517
627
  color: var(--ink);
@@ -637,7 +747,8 @@
637
747
  outline: none;
638
748
  }
639
749
  .resize:hover {
640
- box-shadow: inset 0 -1px 0 color-mix(in oklab, var(--accent) 60%, transparent);
750
+ box-shadow: inset 0 -1px 0
751
+ color-mix(in oklab, var(--accent) 60%, transparent);
641
752
  }
642
753
  /* The bar: a row of ruled cells, as the docs' site header is. */
643
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?: "auto" | "light" | "dark" | undefined;
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>(`[data-to="a${id}"]`) ?? []) {
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 = (event.target as Element | null)?.closest<HTMLElement>("[data-node]");
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)));
@@ -85,11 +90,14 @@
85
90
  // Again after each new layout: a node whose kind or side changes has its classes written over,
86
91
  // and a node drawn later has none.
87
92
  void layout;
88
- for (const element of host?.querySelectorAll("[data-node].selected") ?? []) {
93
+ for (const element of host?.querySelectorAll("[data-node].selected") ??
94
+ []) {
89
95
  element.classList.remove("selected");
90
96
  }
91
97
  if (selected !== undefined) {
92
- host?.querySelector(`[data-node="a${selected}"]`)?.classList.add("selected");
98
+ host
99
+ ?.querySelector(`[data-node="a${selected}"]`)
100
+ ?.classList.add("selected");
93
101
  }
94
102
  });
95
103
  </script>
@@ -104,13 +112,22 @@
104
112
  onclick={onselect ? click : undefined}
105
113
  >
106
114
  {#if layout}
107
- <FrameGraph edges={layout.edges} interactive={onselect !== undefined} nodes={layout.nodes} />
115
+ <FrameGraph
116
+ edges={layout.edges}
117
+ interactive={onselect !== undefined}
118
+ nodes={layout.nodes}
119
+ />
108
120
  {#each layout.dots as row, index (index)}
109
121
  {#each row.dots as dot (dot.id)}
110
122
  <span
111
123
  style:left="{dot.x * width}px"
112
124
  style:top="{dot.y}px"
113
- class={["dot", dot.read && "read", dot.repeat && "repeat", dot.removed && "removed"]}
125
+ class={[
126
+ "dot",
127
+ dot.read && "read",
128
+ dot.repeat && "repeat",
129
+ dot.removed && "removed",
130
+ ]}
114
131
  data-node="a{dot.id}"
115
132
  title={dot.label}
116
133
  >
@@ -183,15 +200,26 @@
183
200
  }
184
201
  .dot.removed i {
185
202
  background:
186
- linear-gradient(45deg, transparent 42%, var(--brand-text, #b45309) 42% 58%, transparent 58%),
187
- linear-gradient(-45deg, transparent 42%, var(--brand-text, #b45309) 42% 58%, transparent 58%);
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
+ );
188
215
  border: 0;
189
216
  }
190
217
  .dot:global(.pulse) i {
191
218
  animation: dot-mark 0.9s ease-out;
192
219
  }
193
220
  .dot:global(.selected) i {
194
- box-shadow: 0 0 0 3px color-mix(in oklab, var(--brand, #d97706) 40%, transparent);
221
+ box-shadow: 0 0 0 3px
222
+ color-mix(in oklab, var(--brand, #d97706) 40%, transparent);
195
223
  }
196
224
  .key {
197
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?: { readonly left: number; readonly right: number; readonly top: number };
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(in oklab, var(--foreground, #18181b) 30%, var(--graph-background, var(--background, #fff)));
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 color-mix(in oklab, var(--brand, #d97706) 40%, transparent);
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(45deg, transparent 45%, var(--brand-text, #b45309) 45% 55%, transparent 55%),
257
- linear-gradient(-45deg, transparent 45%, var(--brand-text, #b45309) 45% 55%, transparent 55%);
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(--font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
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(45deg, transparent 42%, var(--brand-text, #b45309) 42% 58%, transparent 58%),
387
- linear-gradient(-45deg, transparent 42%, var(--brand-text, #b45309) 42% 58%, transparent 58%);
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
- export type Kind = "effect" | "atom" | "component" | "junction" | "gone";
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. */