@fluixi/devtools 1.0.0-alpha.108 → 1.0.0-alpha.109

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 (65) hide show
  1. package/dist/callsite.mjs +4 -63
  2. package/dist/change-view.mjs +6 -106
  3. package/dist/chunk-2VDMQ3VF.mjs +520 -0
  4. package/dist/chunk-33U2S43X.mjs +121 -0
  5. package/dist/chunk-4P45Y5EB.mjs +214 -0
  6. package/dist/chunk-B3SAJ7QG.mjs +72 -0
  7. package/dist/chunk-CPZWLBCQ.mjs +35 -0
  8. package/dist/chunk-D25KZZBZ.mjs +212 -0
  9. package/dist/chunk-EBSROPWJ.mjs +314 -0
  10. package/dist/chunk-F664XLZL.mjs +743 -0
  11. package/dist/chunk-FY5K3QVT.mjs +35 -0
  12. package/dist/chunk-G7Z7CVP5.mjs +184 -0
  13. package/dist/chunk-GDQXCOQB.mjs +43 -0
  14. package/dist/chunk-L6XQGNMW.mjs +106 -0
  15. package/dist/chunk-MN6O673L.mjs +90 -0
  16. package/dist/chunk-NDUBBBNL.mjs +70 -0
  17. package/dist/chunk-NT7YMK77.mjs +157 -0
  18. package/dist/chunk-NVULLJDH.mjs +120 -0
  19. package/dist/chunk-NWLSDERQ.mjs +68 -0
  20. package/dist/chunk-OPIGF5XB.mjs +184 -0
  21. package/dist/chunk-P5I7DWFX.mjs +292 -0
  22. package/dist/chunk-PKARAAIS.mjs +75 -0
  23. package/dist/chunk-PSSBFXBD.mjs +155 -0
  24. package/dist/chunk-PTQ5VCYE.mjs +103 -0
  25. package/dist/chunk-PU4MJ5RU.mjs +107 -0
  26. package/dist/chunk-UAEJ3N7F.mjs +76 -0
  27. package/dist/chunk-V6DKWEYD.mjs +67 -0
  28. package/dist/chunk-VO2V7AC5.mjs +80 -0
  29. package/dist/chunk-WGQH7RUW.mjs +25 -0
  30. package/dist/chunk-Y5OQWBAM.mjs +777 -0
  31. package/dist/chunk-Z6KYHEKY.mjs +64 -0
  32. package/dist/copy.mjs +3 -39
  33. package/dist/describe.mjs +3 -31
  34. package/dist/detail-panel.mjs +6 -280
  35. package/dist/diff.mjs +4 -201
  36. package/dist/dom.mjs +7 -176
  37. package/dist/export.mjs +6 -207
  38. package/dist/float.mjs +5 -206
  39. package/dist/format.mjs +5 -151
  40. package/dist/graph-view.mjs +9 -875
  41. package/dist/highlight.mjs +6 -113
  42. package/dist/history.mjs +4 -70
  43. package/dist/hook.mjs +16 -1719
  44. package/dist/index.cjs +1 -1
  45. package/dist/index.mjs +106 -4673
  46. package/dist/inspector.mjs +11 -677
  47. package/dist/instrument.mjs +9 -486
  48. package/dist/kind-filter.mjs +6 -148
  49. package/dist/menu.mjs +4 -116
  50. package/dist/observe.mjs +14 -1510
  51. package/dist/palette.mjs +6 -28
  52. package/dist/path.mjs +3 -21
  53. package/dist/plugin.mjs +9 -57
  54. package/dist/plugins/context.mjs +6 -71
  55. package/dist/plugins/directives.mjs +8 -68
  56. package/dist/plugins/index.cjs +1 -1
  57. package/dist/plugins/index.mjs +13 -136
  58. package/dist/source.mjs +12 -93
  59. package/dist/timeline.mjs +7 -323
  60. package/dist/tree.mjs +11 -558
  61. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  62. package/dist/value-pane.mjs +6 -196
  63. package/dist/wire.cjs +1 -1
  64. package/dist/wire.mjs +6 -86
  65. package/package.json +3 -3
@@ -0,0 +1,35 @@
1
+ // src/palette.ts
2
+ var KIND_COLOR = {
3
+ state: "#34d399",
4
+ memo: "#a78bfa",
5
+ effect: "#fbbf24",
6
+ store: "#38bdf8",
7
+ resource: "#fb7185",
8
+ component: "#f0abfc",
9
+ provider: "#fb923c",
10
+ control: "#22d3ee",
11
+ router: "#818cf8",
12
+ handler: "#f472b6",
13
+ context: "#a3e635",
14
+ directive: "#5eead4",
15
+ binding: "#5eead4",
16
+ setter: "#fb7185",
17
+ group: "#8a90a2",
18
+ element: "#8a90a2",
19
+ "custom-element": "#2dd4bf",
20
+ module: "#facc15",
21
+ service: "#60a5fa"
22
+ };
23
+ var kindVar = (kind) => `--fx-kind-${kind}`;
24
+ var kindColor = (kind) => `var(${kindVar(kind)}, ${KIND_COLOR[kind]})`;
25
+ var KINDS = Object.keys(KIND_COLOR);
26
+ function kindRules(selector, property) {
27
+ return KINDS.map((kind) => `${selector(kind)} { ${property}: ${kindColor(kind)}; }`).join("\n");
28
+ }
29
+
30
+ export {
31
+ KIND_COLOR,
32
+ kindVar,
33
+ kindColor,
34
+ kindRules
35
+ };
@@ -0,0 +1,184 @@
1
+ import {
2
+ CHANGE_CSS,
3
+ changeRows,
4
+ handleCopyClick
5
+ } from "./chunk-UAEJ3N7F.mjs";
6
+
7
+ // src/detail-panel.ts
8
+ var escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
9
+ var clock = (t) => {
10
+ const d = new Date(t);
11
+ const pad = (n, w = 2) => String(n).padStart(w, "0");
12
+ return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad(d.getMilliseconds(), 3)}`;
13
+ };
14
+ var VERBS = {
15
+ write: "written",
16
+ ran: "ran",
17
+ created: "made",
18
+ disposed: "gone"
19
+ };
20
+ var MIN_W = 320;
21
+ var MIN_H = 200;
22
+ function draggable(handle, onMove) {
23
+ handle.addEventListener("pointerdown", (event) => {
24
+ if (event.button !== 0) return;
25
+ if (event.target.closest("button")) return;
26
+ event.preventDefault();
27
+ event.stopPropagation();
28
+ handle.setPointerCapture(event.pointerId);
29
+ let lastX = event.clientX;
30
+ let lastY = event.clientY;
31
+ const move = (e) => {
32
+ onMove(e.clientX - lastX, e.clientY - lastY);
33
+ lastX = e.clientX;
34
+ lastY = e.clientY;
35
+ };
36
+ const stop = () => {
37
+ handle.removeEventListener("pointermove", move);
38
+ handle.removeEventListener("pointerup", stop);
39
+ handle.removeEventListener("pointercancel", stop);
40
+ handle.removeEventListener("lostpointercapture", stop);
41
+ if (handle.hasPointerCapture(event.pointerId)) handle.releasePointerCapture(event.pointerId);
42
+ };
43
+ handle.addEventListener("pointermove", move);
44
+ handle.addEventListener("pointerup", stop);
45
+ handle.addEventListener("pointercancel", stop);
46
+ handle.addEventListener("lostpointercapture", stop);
47
+ });
48
+ }
49
+ function createDetailPanel(host, options = {}) {
50
+ const panel = host.ownerDocument.createElement("div");
51
+ panel.className = "dp-panel";
52
+ panel.hidden = true;
53
+ panel.innerHTML = '<div class="dp-bar"><span class="dp-title"></span><button type="button" class="dp-close" title="Close" aria-label="Close">✕</button></div><div class="dp-body"></div><div class="dp-grip" title="Drag to resize"></div>';
54
+ host.appendChild(panel);
55
+ const title = panel.querySelector(".dp-title");
56
+ const body = panel.querySelector(".dp-body");
57
+ const bar = panel.querySelector(".dp-bar");
58
+ const grip = panel.querySelector(".dp-grip");
59
+ let x = 0;
60
+ let y = 0;
61
+ let width = 520;
62
+ let height = 380;
63
+ let open = false;
64
+ const place = () => {
65
+ panel.style.left = `${Math.round(x)}px`;
66
+ panel.style.top = `${Math.round(y)}px`;
67
+ panel.style.width = `${Math.round(width)}px`;
68
+ panel.style.height = `${Math.round(height)}px`;
69
+ };
70
+ draggable(bar, (dx, dy) => {
71
+ const view = panel.ownerDocument.defaultView;
72
+ x = Math.max(0, Math.min((view?.innerWidth ?? width) - 60, x + dx));
73
+ y = Math.max(0, Math.min((view?.innerHeight ?? height) - 30, y + dy));
74
+ place();
75
+ });
76
+ draggable(grip, (dx, dy) => {
77
+ width = Math.max(MIN_W, width + dx);
78
+ height = Math.max(MIN_H, height + dy);
79
+ place();
80
+ });
81
+ panel.querySelector(".dp-close")?.addEventListener("click", () => close());
82
+ body.addEventListener("click", (e) => {
83
+ if (handleCopyClick(e)) return;
84
+ const row = e.target.closest(".dp-node");
85
+ if (row?.dataset.id) options.onPick?.(Number(row.dataset.id));
86
+ });
87
+ function close() {
88
+ open = false;
89
+ panel.hidden = true;
90
+ }
91
+ return {
92
+ open(commit, graph) {
93
+ const nameOf = (e) => graph.get(e.id)?.label ?? e.label ?? `#${e.id}`;
94
+ const cause = commit.cause;
95
+ title.textContent = cause ? `${nameOf(cause)} · ${clock(commit.t)}` : `${commit.commit === 0 ? "first render" : `commit ${commit.commit}`} · ${clock(commit.t)}`;
96
+ const headline = cause && cause.from !== void 0 && cause.to !== void 0 ? `<div class="dp-change"><span class="ch-from">${escape(cause.from)}</span><span class="ch-arrow">→</span><span class="ch-to">${escape(cause.to)}</span></div>` : "";
97
+ const groups = ["write", "ran", "created", "disposed"].map((kind) => {
98
+ const rows = commit.events.filter((e) => e.kind === kind && e !== cause);
99
+ if (!rows.length) return "";
100
+ const seen = /* @__PURE__ */ new Map();
101
+ for (const event of rows) {
102
+ const found = seen.get(event.id);
103
+ if (found) found.count++;
104
+ else seen.set(event.id, { name: nameOf(event), count: 1 });
105
+ }
106
+ const items = [...seen].map(
107
+ ([id, { name, count }]) => `<button type="button" class="dp-node" data-id="${id}">${escape(name)}${count > 1 ? ` ×${count}` : ""}</button>`
108
+ ).join("");
109
+ return `<div class="dp-group"><div class="dp-verb">${VERBS[kind]}</div><div class="dp-nodes">${items}</div></div>`;
110
+ }).join("");
111
+ const node = cause ? graph.get(cause.id) : void 0;
112
+ const where = (t) => {
113
+ if (!t.source) return "";
114
+ const file = (t.source.file ?? "").split("/").pop() ?? "";
115
+ const out = t.source.compiled;
116
+ const tail = out && out.line !== t.source.line ? ` · out ${out.line}` : "";
117
+ return ` — ${file}:${t.source.line ?? ""}${tail}`;
118
+ };
119
+ const targets = node?.targets?.length ? `<div class="dp-group"><div class="dp-verb">updates</div><div class="dp-targets">${node.targets.map(
120
+ (t) => `<div>${escape(t.name ? `${t.name} of ${t.element}` : t.element)}<span class="dp-where">${escape(where(t))}</span></div>`
121
+ ).join("")}</div></div>` : "";
122
+ body.innerHTML = headline + changeRows(cause?.change) + groups + targets;
123
+ if (!open) {
124
+ const view = panel.ownerDocument.defaultView;
125
+ x = Math.max(12, ((view?.innerWidth ?? 900) - width) / 2);
126
+ y = Math.max(12, ((view?.innerHeight ?? 600) - height) / 3);
127
+ place();
128
+ }
129
+ open = true;
130
+ panel.hidden = false;
131
+ },
132
+ close,
133
+ get isOpen() {
134
+ return open;
135
+ },
136
+ destroy() {
137
+ panel.remove();
138
+ }
139
+ };
140
+ }
141
+ var DETAIL_PANEL_CSS = `
142
+ .dp-panel {
143
+ position: fixed; z-index: 40; display: flex; flex-direction: column;
144
+ border: 1px solid var(--fx-line, #ffffff26); border-radius: 8px;
145
+ background: var(--fx-panel, #14161c); color: var(--fx-label, #e7e9ee);
146
+ box-shadow: 0 12px 40px rgba(0, 0, 0, .45); overflow: hidden;
147
+ }
148
+ .dp-panel[hidden] { display: none; }
149
+ .dp-bar {
150
+ display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px;
151
+ cursor: move; user-select: none;
152
+ border-bottom: 1px solid var(--fx-line, #ffffff1f);
153
+ }
154
+ .dp-title { font-family: ui-monospace, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
155
+ .dp-close {
156
+ margin-left: auto; width: 22px; height: 20px; padding: 0; cursor: pointer; font: inherit; font-size: 11px;
157
+ border: 1px solid var(--fx-line, #ffffff1f); border-radius: 4px;
158
+ background: transparent; color: var(--fx-muted, #8a90a2);
159
+ }
160
+ .dp-close:hover { color: var(--fx-label, #e7e9ee); }
161
+ .dp-body { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; }
162
+ .dp-change { font-family: ui-monospace, monospace; font-size: 12px; overflow-wrap: anywhere; }
163
+ .dp-group { margin-top: 10px; }
164
+ .dp-verb { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--fx-muted, #8a90a2); }
165
+ .dp-nodes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
166
+ .dp-node {
167
+ padding: 2px 7px; cursor: pointer; font: inherit; font-family: ui-monospace, monospace; font-size: 11px;
168
+ border: 1px solid var(--fx-line, #ffffff1f); border-radius: 999px;
169
+ background: transparent; color: var(--fx-label, #e7e9ee);
170
+ }
171
+ .dp-node:hover { border-color: var(--fx-accent, #5eead4); }
172
+ .dp-targets { margin-top: 4px; font-family: ui-monospace, monospace; font-size: 11px; color: var(--fx-label, #e7e9ee); }
173
+ .dp-where { color: var(--fx-muted, #8a90a2); }
174
+ /* Bottom-right, where every desktop puts it. */
175
+ .dp-grip {
176
+ position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize;
177
+ background: linear-gradient(135deg, transparent 50%, var(--fx-line, #ffffff40) 50%);
178
+ }
179
+ ${CHANGE_CSS}`;
180
+
181
+ export {
182
+ createDetailPanel,
183
+ DETAIL_PANEL_CSS
184
+ };
@@ -0,0 +1,43 @@
1
+ // src/copy.ts
2
+ function confirmOn(button, said = "copied") {
3
+ if (!button) return;
4
+ const was = button.textContent;
5
+ button.textContent = said;
6
+ setTimeout(() => {
7
+ button.textContent = was;
8
+ }, 1200);
9
+ }
10
+ function fallback(text, button) {
11
+ try {
12
+ const doc = button?.ownerDocument ?? document;
13
+ const area = doc.createElement("textarea");
14
+ area.value = text;
15
+ area.setAttribute("readonly", "");
16
+ area.style.position = "fixed";
17
+ area.style.opacity = "0";
18
+ doc.body.appendChild(area);
19
+ area.select();
20
+ doc.execCommand("copy");
21
+ area.remove();
22
+ confirmOn(button);
23
+ return true;
24
+ } catch {
25
+ return false;
26
+ }
27
+ }
28
+ async function copyText(text, button) {
29
+ const clipboard = globalThis.navigator?.clipboard;
30
+ if (clipboard?.writeText) {
31
+ try {
32
+ await clipboard.writeText(text);
33
+ confirmOn(button);
34
+ return true;
35
+ } catch {
36
+ }
37
+ }
38
+ return fallback(text, button);
39
+ }
40
+
41
+ export {
42
+ copyText
43
+ };
@@ -0,0 +1,106 @@
1
+ // src/source.ts
2
+ var MARKER = "__fx_source";
3
+ var COMPONENT_MARKER = "__fx_component";
4
+ var CLASS_MARKER = "__fx_class";
5
+ var HOLE_MARKER = "__fx_hole";
6
+ var PROPS_MARKER = "__fx_props";
7
+ var MARKS = "__FLUIXI_DEVTOOLS_MARKS__";
8
+ var host = globalThis;
9
+ var shared = host[MARKS] ?? {
10
+ pending: null,
11
+ expiring: false,
12
+ components: /* @__PURE__ */ new Map()
13
+ };
14
+ host[MARKS] = shared;
15
+ shared.classes ??= /* @__PURE__ */ new WeakMap();
16
+ function markReactiveSource(file, line, column, name, self) {
17
+ const location = locate(file, line, column);
18
+ if (shared.pending && location.external && !shared.pending.location?.external) return;
19
+ shared.pending = self && typeof self === "object" ? { name, location, self } : { name, location };
20
+ shared.expiring = false;
21
+ }
22
+ function dropReactiveSource() {
23
+ shared.pending = null;
24
+ }
25
+ function locate(file, line, column) {
26
+ const external = !!file && (/^([a-zA-Z]:)?[\\/]/.test(file) || file.includes("node_modules/"));
27
+ return external ? { file, line, column, external } : { file, line, column };
28
+ }
29
+ function markComponentSource(name, file, line, column) {
30
+ const seen = shared.components.get(name);
31
+ const next = locate(file, line, column);
32
+ if (seen === void 0) {
33
+ shared.components.set(name, next);
34
+ return;
35
+ }
36
+ if (!seen || seen.file !== file || seen.line !== line) shared.components.set(name, null);
37
+ }
38
+ function markClassSource(constructor, file, line, column) {
39
+ if (typeof constructor === "function") shared.classes.set(constructor, locate(file, line, column));
40
+ }
41
+ function classSource(constructor) {
42
+ return typeof constructor === "function" ? shared.classes.get(constructor) : void 0;
43
+ }
44
+ function componentSource(name) {
45
+ return shared.components.get(name) ?? void 0;
46
+ }
47
+ function takeReactiveSource() {
48
+ const mark = shared.pending;
49
+ if (mark) {
50
+ if (mark.name !== void 0 || mark.self) shared.pending = { location: mark.location };
51
+ if (!shared.expiring) {
52
+ shared.expiring = true;
53
+ queueMicrotask(() => {
54
+ shared.expiring = false;
55
+ shared.pending = null;
56
+ });
57
+ }
58
+ }
59
+ return mark;
60
+ }
61
+ var HOLES = /* @__PURE__ */ new WeakMap();
62
+ var HOLE_TAG = "__fx_at";
63
+ function markHole(accessor, line, column, name) {
64
+ if (accessor && (typeof accessor === "object" || typeof accessor === "function")) {
65
+ const at = name === void 0 ? { line, column } : { line, column, name };
66
+ HOLES.set(accessor, at);
67
+ try {
68
+ Object.defineProperty(accessor, HOLE_TAG, { value: at, configurable: true });
69
+ } catch {
70
+ }
71
+ }
72
+ shared.pending = null;
73
+ return accessor;
74
+ }
75
+ var PROPS = /* @__PURE__ */ new WeakMap();
76
+ function markProps(props, at) {
77
+ if (props && typeof props === "object") PROPS.set(props, at);
78
+ return props;
79
+ }
80
+ function propsLocations(props) {
81
+ return props && typeof props === "object" ? PROPS.get(props) : void 0;
82
+ }
83
+ function holeLocation(accessor) {
84
+ if (!accessor || typeof accessor !== "object" && typeof accessor !== "function") return void 0;
85
+ return HOLES.get(accessor) ?? accessor[HOLE_TAG];
86
+ }
87
+ function installSourceMarker() {
88
+ if (typeof host[MARKER] !== "function") host[MARKER] = markReactiveSource;
89
+ if (typeof host[COMPONENT_MARKER] !== "function") host[COMPONENT_MARKER] = markComponentSource;
90
+ if (typeof host[CLASS_MARKER] !== "function") host[CLASS_MARKER] = markClassSource;
91
+ if (typeof host[HOLE_MARKER] !== "function") host[HOLE_MARKER] = markHole;
92
+ if (typeof host[PROPS_MARKER] !== "function") host[PROPS_MARKER] = markProps;
93
+ }
94
+
95
+ export {
96
+ markReactiveSource,
97
+ dropReactiveSource,
98
+ markComponentSource,
99
+ markClassSource,
100
+ classSource,
101
+ componentSource,
102
+ takeReactiveSource,
103
+ propsLocations,
104
+ holeLocation,
105
+ installSourceMarker
106
+ };
@@ -0,0 +1,90 @@
1
+ // src/wire.ts
2
+ var STATE_NAME = { 0: "clean", 1: "check", 2: "dirty" };
3
+ var STATE_CODE = { clean: 0, check: 1, dirty: 2 };
4
+ function serializeGraph(graph, now = Date.now(), options = {}) {
5
+ const nodes = [];
6
+ const wanted = options.ids ? new Set(options.ids) : null;
7
+ for (const node of graph.values()) {
8
+ if (wanted && !wanted.has(node.id)) continue;
9
+ const state = typeof node.core?.state === "number" ? STATE_NAME[node.core.state] : void 0;
10
+ nodes.push({
11
+ id: node.id,
12
+ label: node.label,
13
+ kind: node.kind,
14
+ authored: node.authored,
15
+ deps: [...node.deps],
16
+ writes: [...node.writes],
17
+ value: node.value,
18
+ detail: node.detail,
19
+ runs: node.runs,
20
+ lastPulse: node.lastPulse,
21
+ order: node.order,
22
+ version: node.core?.version,
23
+ state,
24
+ loading: node.loading,
25
+ lazy: node.lazy,
26
+ props: node.props,
27
+ extra: node.extra,
28
+ source: node.source,
29
+ declaredAt: node.declaredAt,
30
+ usedAt: node.usedAt,
31
+ createdIn: node.createdIn,
32
+ scope: node.scope,
33
+ bindings: node.bindings,
34
+ targets: node.targets,
35
+ setAt: node.setAt,
36
+ // Falls back to what the node already carries, so a relay that re-serialises a
37
+ // snapshot it received does not drop the description.
38
+ dom: options.dom?.(node.id) ?? node.dom
39
+ });
40
+ }
41
+ const removed = options.removed ? [...options.removed] : void 0;
42
+ const events = options.events?.length ? [...options.events] : void 0;
43
+ const cursor = options.cursor;
44
+ return wanted ? { t: now, nodes, partial: true, removed, events, cursor } : { t: now, nodes, events, cursor };
45
+ }
46
+ function snapshotToRenderMap(snapshot) {
47
+ const map = /* @__PURE__ */ new Map();
48
+ for (const node of snapshot.nodes) {
49
+ map.set(node.id, {
50
+ id: node.id,
51
+ label: node.label,
52
+ kind: node.kind,
53
+ authored: node.authored,
54
+ deps: new Set(node.deps),
55
+ writes: new Set(node.writes),
56
+ value: node.value,
57
+ detail: node.detail,
58
+ runs: node.runs,
59
+ lastPulse: node.lastPulse,
60
+ order: node.order,
61
+ core: { version: node.version, state: node.state ? STATE_CODE[node.state] : void 0 },
62
+ loading: node.loading,
63
+ lazy: node.lazy,
64
+ props: node.props,
65
+ extra: node.extra,
66
+ source: node.source,
67
+ declaredAt: node.declaredAt,
68
+ usedAt: node.usedAt,
69
+ createdIn: node.createdIn,
70
+ scope: node.scope,
71
+ bindings: node.bindings,
72
+ targets: node.targets,
73
+ setAt: node.setAt,
74
+ dom: node.dom
75
+ });
76
+ }
77
+ return map;
78
+ }
79
+ function applySnapshot(graph, snapshot) {
80
+ if (!snapshot.partial) return snapshotToRenderMap(snapshot);
81
+ for (const [id, node] of snapshotToRenderMap(snapshot)) graph.set(id, node);
82
+ for (const id of snapshot.removed ?? []) graph.delete(id);
83
+ return graph;
84
+ }
85
+
86
+ export {
87
+ serializeGraph,
88
+ snapshotToRenderMap,
89
+ applySnapshot
90
+ };
@@ -0,0 +1,70 @@
1
+ import {
2
+ registerDevtoolsPlugin
3
+ } from "./chunk-V6DKWEYD.mjs";
4
+ import {
5
+ shorten
6
+ } from "./chunk-NT7YMK77.mjs";
7
+
8
+ // src/plugins/context.ts
9
+ var NAME = "context";
10
+ var contextPlugin = {
11
+ name: NAME,
12
+ collect(ctx) {
13
+ const nodes = /* @__PURE__ */ new Map();
14
+ ctx.onContext((report) => {
15
+ if (report.owner === void 0) return;
16
+ let node = nodes.get(report.id);
17
+ if (node === void 0) {
18
+ const label = report.name === "context" && report.ownerLabel ? `${report.ownerLabel} context` : report.name;
19
+ node = ctx.add({
20
+ label,
21
+ kind: "context",
22
+ // A context is created at module scope with nothing running, so the only line it
23
+ // can carry is the one that provided or read it.
24
+ ...report.at ? { source: report.at } : {},
25
+ // The router's own contexts are the framework's, and belong in its card rather
26
+ // than beside the ones the application wrote.
27
+ authored: report.at?.external !== true,
28
+ // Under whoever provided it. A context read with no provider above it belongs to
29
+ // the reader, which is the honest place for a default value.
30
+ createdIn: report.owner,
31
+ // Short on the card, whole in the inspector, the way every other node works.
32
+ ...report.value !== void 0 ? { value: shorten(report.value), detail: report.value } : {}
33
+ });
34
+ nodes.set(report.id, node);
35
+ }
36
+ if (report.kind === "provide") ctx.retype(report.owner, "provider");
37
+ const held = ctx.annotation(report.owner) ?? [];
38
+ const already = held.some((n) => n.name === report.name && n.kind === report.kind);
39
+ if (already) return;
40
+ held.push({
41
+ name: report.name,
42
+ kind: report.kind,
43
+ ...report.value !== void 0 ? { value: report.value } : {}
44
+ });
45
+ ctx.annotate(report.owner, held);
46
+ });
47
+ },
48
+ rows(node) {
49
+ const notes = node.extra?.[NAME];
50
+ if (!notes?.length) return [];
51
+ return notes.map((note) => ({
52
+ label: note.kind === "provide" ? `provides ${note.name}` : `reads ${note.name}`,
53
+ ...note.value !== void 0 ? { value: note.value } : {}
54
+ }));
55
+ },
56
+ badge(node) {
57
+ const notes = node.extra?.[NAME];
58
+ if (!notes?.length) return void 0;
59
+ const given = notes.filter((n) => n.kind === "provide");
60
+ if (given.length === 1) return `provides ${given[0].name}`;
61
+ if (given.length > 1) return `provides ${given.length}`;
62
+ return notes.length === 1 ? `reads ${notes[0].name}` : `reads ${notes.length}`;
63
+ }
64
+ };
65
+ registerDevtoolsPlugin(contextPlugin);
66
+
67
+ export {
68
+ NAME,
69
+ contextPlugin
70
+ };
@@ -0,0 +1,157 @@
1
+ // src/format.ts
2
+ var MAX_DEPTH = 3;
3
+ var MAX_ENTRIES = 8;
4
+ function domName(v) {
5
+ if (typeof v?.nodeType !== "number" || typeof v.nodeName !== "string") return null;
6
+ return v.tagName ? `<${v.tagName.toLowerCase()}>` : `#${v.nodeName.toLowerCase()}`;
7
+ }
8
+ function fnName(v) {
9
+ return v.name ? `ƒ ${v.name}()` : "ƒ";
10
+ }
11
+ function className(v) {
12
+ const name = v.constructor?.name;
13
+ return name && name !== "Object" ? `${name} ` : "";
14
+ }
15
+ function primitive(v) {
16
+ if (v === null) return "null";
17
+ switch (typeof v) {
18
+ case "undefined":
19
+ return "undefined";
20
+ case "string":
21
+ return JSON.stringify(v);
22
+ case "number":
23
+ case "boolean":
24
+ return String(v);
25
+ case "bigint":
26
+ return `${v}n`;
27
+ case "symbol":
28
+ return v.toString();
29
+ case "function":
30
+ return fnName(v);
31
+ default:
32
+ return null;
33
+ }
34
+ }
35
+ function walk(value, depth, seen) {
36
+ const simple = primitive(value);
37
+ if (simple !== null) return simple;
38
+ const object = value;
39
+ if (seen.has(object)) return "[circular]";
40
+ const dom = domName(object);
41
+ if (dom) return dom;
42
+ if (object instanceof Date) return Number.isNaN(object.getTime()) ? "Invalid Date" : object.toISOString();
43
+ if (object instanceof RegExp) return String(object);
44
+ if (object instanceof Error) return `${object.name}: ${object.message}`;
45
+ if (object instanceof Promise) return "Promise";
46
+ if (ArrayBuffer.isView(object)) {
47
+ return `${className(object).trim()}(${object.length ?? ""})`;
48
+ }
49
+ if (depth >= MAX_DEPTH) return Array.isArray(object) ? "[…]" : "{…}";
50
+ seen.add(object);
51
+ try {
52
+ if (Array.isArray(object)) {
53
+ const shown2 = object.slice(0, MAX_ENTRIES).map((item) => walk(item, depth + 1, seen));
54
+ if (object.length > MAX_ENTRIES) shown2.push("…");
55
+ return `[${shown2.join(", ")}]`;
56
+ }
57
+ if (object instanceof Map) {
58
+ const shown2 = [];
59
+ for (const [k, v] of object) {
60
+ if (shown2.length === MAX_ENTRIES) {
61
+ shown2.push("…");
62
+ break;
63
+ }
64
+ shown2.push(`${walk(k, depth + 1, seen)} => ${walk(v, depth + 1, seen)}`);
65
+ }
66
+ return `Map(${object.size}) {${shown2.join(", ")}}`;
67
+ }
68
+ if (object instanceof Set) {
69
+ const shown2 = [];
70
+ for (const item of object) {
71
+ if (shown2.length === MAX_ENTRIES) {
72
+ shown2.push("…");
73
+ break;
74
+ }
75
+ shown2.push(walk(item, depth + 1, seen));
76
+ }
77
+ return `Set(${object.size}) {${shown2.join(", ")}}`;
78
+ }
79
+ const keys = Object.keys(object);
80
+ const shown = keys.slice(0, MAX_ENTRIES).map((key) => {
81
+ let read;
82
+ try {
83
+ const descriptor = Object.getOwnPropertyDescriptor(object, key);
84
+ if (descriptor?.get) return `${key}: [getter]`;
85
+ read = walk(object[key], depth + 1, seen);
86
+ } catch {
87
+ read = "[unreadable]";
88
+ }
89
+ return `${key}: ${read}`;
90
+ });
91
+ if (keys.length > MAX_ENTRIES) shown.push("…");
92
+ return `${className(object)}{${shown.join(", ")}}`;
93
+ } finally {
94
+ seen.delete(object);
95
+ }
96
+ }
97
+ function formatValue(value, limit = 240) {
98
+ let text;
99
+ try {
100
+ text = walk(value, 0, /* @__PURE__ */ new Set());
101
+ } catch {
102
+ text = "[unreadable]";
103
+ }
104
+ return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;
105
+ }
106
+ function shorten(text, limit = 18) {
107
+ return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;
108
+ }
109
+ function indentValue(text, pad = " ") {
110
+ const out = [];
111
+ let depth = 0;
112
+ let quote = null;
113
+ let line = "";
114
+ const flush = () => {
115
+ if (line.trim()) out.push(pad.repeat(depth) + line.trim());
116
+ line = "";
117
+ };
118
+ for (let i = 0; i < text.length; i++) {
119
+ const c = text[i];
120
+ if (quote) {
121
+ line += c;
122
+ if (c === quote && text[i - 1] !== "\\") quote = null;
123
+ continue;
124
+ }
125
+ if (c === '"' || c === "'") {
126
+ quote = c;
127
+ line += c;
128
+ continue;
129
+ }
130
+ if (c === "{" || c === "[") {
131
+ line += c;
132
+ flush();
133
+ depth++;
134
+ continue;
135
+ }
136
+ if (c === "}" || c === "]") {
137
+ flush();
138
+ depth = Math.max(0, depth - 1);
139
+ line = c;
140
+ continue;
141
+ }
142
+ if (c === ",") {
143
+ line += c;
144
+ flush();
145
+ continue;
146
+ }
147
+ line += c;
148
+ }
149
+ flush();
150
+ return out.join("\n");
151
+ }
152
+
153
+ export {
154
+ formatValue,
155
+ shorten,
156
+ indentValue
157
+ };