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

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 (83) hide show
  1. package/dist/callsite.mjs +4 -63
  2. package/dist/change-view.mjs +6 -106
  3. package/dist/chunk-235BSS43.mjs +185 -0
  4. package/dist/chunk-2ACSNLS6.mjs +87 -0
  5. package/dist/chunk-2VDMQ3VF.mjs +520 -0
  6. package/dist/chunk-33U2S43X.mjs +121 -0
  7. package/dist/chunk-B3SAJ7QG.mjs +72 -0
  8. package/dist/chunk-BTCWJTXR.mjs +216 -0
  9. package/dist/chunk-CPZWLBCQ.mjs +35 -0
  10. package/dist/chunk-D25KZZBZ.mjs +212 -0
  11. package/dist/chunk-EBSROPWJ.mjs +314 -0
  12. package/dist/chunk-F664XLZL.mjs +743 -0
  13. package/dist/chunk-FY5K3QVT.mjs +35 -0
  14. package/dist/chunk-GDQXCOQB.mjs +43 -0
  15. package/dist/chunk-JLNWT36I.mjs +118 -0
  16. package/dist/chunk-JTHAZJJZ.mjs +780 -0
  17. package/dist/chunk-L6XQGNMW.mjs +106 -0
  18. package/dist/chunk-MN6O673L.mjs +90 -0
  19. package/dist/chunk-NDUBBBNL.mjs +70 -0
  20. package/dist/chunk-NT7YMK77.mjs +157 -0
  21. package/dist/chunk-NVULLJDH.mjs +120 -0
  22. package/dist/chunk-NWLSDERQ.mjs +68 -0
  23. package/dist/chunk-OPIGF5XB.mjs +184 -0
  24. package/dist/chunk-P5I7DWFX.mjs +292 -0
  25. package/dist/chunk-PSSBFXBD.mjs +155 -0
  26. package/dist/chunk-PTQ5VCYE.mjs +103 -0
  27. package/dist/chunk-UAEJ3N7F.mjs +76 -0
  28. package/dist/chunk-V6DKWEYD.mjs +67 -0
  29. package/dist/chunk-VO2V7AC5.mjs +80 -0
  30. package/dist/chunk-WGQH7RUW.mjs +25 -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.cjs +2 -1
  35. package/dist/detail-panel.d.ts.map +1 -1
  36. package/dist/detail-panel.js +1 -0
  37. package/dist/detail-panel.mjs +6 -280
  38. package/dist/diff.mjs +4 -201
  39. package/dist/dom.mjs +7 -176
  40. package/dist/export.mjs +6 -207
  41. package/dist/float.mjs +5 -206
  42. package/dist/format.mjs +5 -151
  43. package/dist/graph-view.mjs +9 -875
  44. package/dist/highlight.mjs +6 -113
  45. package/dist/history.cjs +14 -2
  46. package/dist/history.d.ts +8 -1
  47. package/dist/history.d.ts.map +1 -1
  48. package/dist/history.js +15 -2
  49. package/dist/history.mjs +4 -70
  50. package/dist/hook.cjs +26 -1
  51. package/dist/hook.d.ts +4 -0
  52. package/dist/hook.d.ts.map +1 -1
  53. package/dist/hook.js +13 -0
  54. package/dist/hook.mjs +16 -1719
  55. package/dist/index.cjs +34 -5
  56. package/dist/index.mjs +106 -4673
  57. package/dist/inspector.mjs +11 -677
  58. package/dist/instrument.mjs +9 -486
  59. package/dist/kind-filter.mjs +6 -148
  60. package/dist/menu.mjs +4 -116
  61. package/dist/observe.cjs +15 -1
  62. package/dist/observe.d.ts +2 -0
  63. package/dist/observe.d.ts.map +1 -1
  64. package/dist/observe.js +3 -0
  65. package/dist/observe.mjs +14 -1510
  66. package/dist/palette.mjs +6 -28
  67. package/dist/path.mjs +3 -21
  68. package/dist/plugin.mjs +9 -57
  69. package/dist/plugins/context.mjs +6 -71
  70. package/dist/plugins/directives.mjs +8 -68
  71. package/dist/plugins/index.cjs +1 -1
  72. package/dist/plugins/index.mjs +13 -136
  73. package/dist/source.mjs +12 -93
  74. package/dist/timeline.cjs +5 -2
  75. package/dist/timeline.d.ts.map +1 -1
  76. package/dist/timeline.js +5 -1
  77. package/dist/timeline.mjs +7 -323
  78. package/dist/tree.mjs +11 -558
  79. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  80. package/dist/value-pane.mjs +6 -196
  81. package/dist/wire.cjs +1 -1
  82. package/dist/wire.mjs +6 -86
  83. package/package.json +3 -3
@@ -0,0 +1,184 @@
1
+ // src/dom.ts
2
+ var LOC_TAG = "__fx_loc";
3
+ function locationOf(element) {
4
+ return element[LOC_TAG];
5
+ }
6
+ var DOM_BUDGET = 200;
7
+ function describeElement(element) {
8
+ let out = element.tagName.toLowerCase();
9
+ if (element.id) out += `#${element.id}`;
10
+ const classes = element.classList;
11
+ if (classes.length > 0) {
12
+ out += `.${classes[0]}`;
13
+ if (classes.length > 1) out += `.${classes[1]}`;
14
+ }
15
+ return out;
16
+ }
17
+ function describeAll(graph, roots, writtenBy, kinds, extraFor) {
18
+ const owners = /* @__PURE__ */ new Map();
19
+ const writers = /* @__PURE__ */ new Map();
20
+ const rendered = /* @__PURE__ */ new Map();
21
+ for (const node of graph.values()) {
22
+ if (kinds.has(node.kind)) {
23
+ const found = roots(node.id);
24
+ rendered.set(node.id, found);
25
+ for (const element of found) if (!owners.has(element)) owners.set(element, node.id);
26
+ continue;
27
+ }
28
+ for (const element of writtenBy(node.id)) {
29
+ const held = writers.get(element);
30
+ if (held) held.push(node.id);
31
+ else writers.set(element, [node.id]);
32
+ }
33
+ }
34
+ const { claimed, containers } = claimOrphans(graph, rendered, writtenBy, kinds, owners);
35
+ const claims = /* @__PURE__ */ new Map();
36
+ for (const [element, id] of claimed) {
37
+ const held = claims.get(id);
38
+ if (held) held.push(element);
39
+ else claims.set(id, [element]);
40
+ }
41
+ const landing = landings(graph, rendered, writtenBy, kinds, claimed, containers);
42
+ const out = /* @__PURE__ */ new Map();
43
+ for (const node of graph.values()) {
44
+ if (!kinds.has(node.kind)) continue;
45
+ const budget = { left: DOM_BUDGET };
46
+ const walk = (element) => {
47
+ const owner = owners.get(element) ?? claimed.get(element);
48
+ const where = locationOf(element);
49
+ if (owner !== void 0 && owner !== node.id) {
50
+ return { label: describeElement(element), children: [], owner, element, ...where ? { at: where } : {} };
51
+ }
52
+ if (containers.has(element)) {
53
+ return { label: describeElement(element), children: [], container: true, element, ...where ? { at: where } : {} };
54
+ }
55
+ const children = [];
56
+ const kids = element.children;
57
+ for (let i = 0, n = kids.length; i < n && budget.left > 0; i++) {
58
+ budget.left -= 1;
59
+ children.push(walk(kids[i]));
60
+ }
61
+ const writes = writers.get(element);
62
+ const extra = extraFor?.(element);
63
+ const inside = landing.get(element)?.filter((id) => within(graph, id, node.id));
64
+ return {
65
+ label: describeElement(element),
66
+ children,
67
+ element,
68
+ ...where ? { at: where } : {},
69
+ ...writes?.length ? { writes } : {},
70
+ ...inside?.length ? { inside } : {},
71
+ ...extra ? { extra } : {}
72
+ };
73
+ };
74
+ out.set(node.id, [...rendered.get(node.id) ?? [], ...claims.get(node.id) ?? []].map(walk));
75
+ }
76
+ return out;
77
+ }
78
+ function within(graph, id, ancestor) {
79
+ const seen = /* @__PURE__ */ new Set();
80
+ for (let at = graph.get(id)?.createdIn; at !== void 0 && !seen.has(at); at = graph.get(at)?.createdIn) {
81
+ if (at === ancestor) return true;
82
+ seen.add(at);
83
+ }
84
+ return false;
85
+ }
86
+ function landings(graph, rendered, writtenBy, kinds, claimed, containers) {
87
+ const claimers = new Set(claimed.values());
88
+ const landing = /* @__PURE__ */ new Map();
89
+ for (const node of graph.values()) {
90
+ if (!kinds.has(node.kind) || (rendered.get(node.id) ?? []).length) continue;
91
+ if (claimers.has(node.id)) continue;
92
+ let shallowest;
93
+ let best = Infinity;
94
+ for (const element of writtenBy(node.id)) {
95
+ if (containers.has(element)) continue;
96
+ const depth = depthInDocument(element);
97
+ if (depth < best) {
98
+ best = depth;
99
+ shallowest = element;
100
+ }
101
+ }
102
+ if (!shallowest) continue;
103
+ const held = landing.get(shallowest);
104
+ if (held) held.push(node.id);
105
+ else landing.set(shallowest, [node.id]);
106
+ }
107
+ for (const [element, ids] of landing) {
108
+ landing.set(element, ids.filter((id) => !ids.some((other) => other !== id && within(graph, id, other))));
109
+ }
110
+ return landing;
111
+ }
112
+ function tagDepths(graph, kinds) {
113
+ const depth = /* @__PURE__ */ new Map();
114
+ const of = (id, seen) => {
115
+ const held = depth.get(id);
116
+ if (held !== void 0) return held;
117
+ if (seen.has(id)) return 0;
118
+ seen.add(id);
119
+ const parent = graph.get(id)?.createdIn;
120
+ const value = parent === void 0 ? 0 : of(parent, seen) + 1;
121
+ depth.set(id, value);
122
+ return value;
123
+ };
124
+ for (const node of graph.values()) if (kinds.has(node.kind)) of(node.id, /* @__PURE__ */ new Set());
125
+ return depth;
126
+ }
127
+ function depthInDocument(element) {
128
+ let steps = 0;
129
+ for (let at = element.parentElement; at; at = at.parentElement) steps++;
130
+ return steps;
131
+ }
132
+ function claimOrphans(graph, rendered, writtenBy, kinds, owners) {
133
+ const depth = tagDepths(graph, kinds);
134
+ const wraps = (element) => {
135
+ for (const owned of owners.keys()) if (element !== owned && element.contains(owned)) return true;
136
+ return false;
137
+ };
138
+ const writing = /* @__PURE__ */ new Map();
139
+ for (const node of graph.values()) {
140
+ if (!kinds.has(node.kind) || (rendered.get(node.id) ?? []).length) continue;
141
+ for (const element of writtenBy(node.id)) {
142
+ if (owners.has(element)) continue;
143
+ const held = writing.get(element);
144
+ if (held) held.push(node.id);
145
+ else writing.set(element, [node.id]);
146
+ }
147
+ }
148
+ const claimed = /* @__PURE__ */ new Map();
149
+ const containers = /* @__PURE__ */ new Set();
150
+ const covered = (element) => {
151
+ for (let at = element.parentElement; at; at = at.parentElement) {
152
+ if (owners.has(at) || claimed.has(at)) return true;
153
+ }
154
+ return false;
155
+ };
156
+ const order = [...writing.keys()].sort((a, b) => depthInDocument(a) - depthInDocument(b));
157
+ for (const element of order) {
158
+ if (covered(element)) continue;
159
+ const ids = writing.get(element);
160
+ const container = wraps(element);
161
+ const pick = ids.reduce((best, id) => {
162
+ const a = depth.get(id) ?? 0;
163
+ const b = depth.get(best) ?? 0;
164
+ return container ? a < b ? id : best : a > b ? id : best;
165
+ });
166
+ claimed.set(element, pick);
167
+ if (container) containers.add(element);
168
+ }
169
+ return { claimed, containers };
170
+ }
171
+ function withoutElements(nodes) {
172
+ return nodes.map(({ element, children, ...rest }) => ({
173
+ ...rest,
174
+ children: withoutElements(children)
175
+ }));
176
+ }
177
+
178
+ export {
179
+ DOM_BUDGET,
180
+ describeElement,
181
+ describeAll,
182
+ tagDepths,
183
+ withoutElements
184
+ };
@@ -0,0 +1,292 @@
1
+ import {
2
+ VALUE_PANE_CSS,
3
+ createValuePane
4
+ } from "./chunk-Z6KYHEKY.mjs";
5
+ import {
6
+ shortenPath
7
+ } from "./chunk-WGQH7RUW.mjs";
8
+ import {
9
+ kindRules
10
+ } from "./chunk-FY5K3QVT.mjs";
11
+ import {
12
+ pluginElementRows,
13
+ pluginRows
14
+ } from "./chunk-V6DKWEYD.mjs";
15
+ import {
16
+ nodeState,
17
+ nodeVersion
18
+ } from "./chunk-EBSROPWJ.mjs";
19
+ import {
20
+ formatValue
21
+ } from "./chunk-NT7YMK77.mjs";
22
+
23
+ // src/inspector.ts
24
+ var escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
25
+ var clip = (text, n = 140) => text.length > n ? `${text.slice(0, n - 1)}…` : text;
26
+ var place = (text, source, live) => {
27
+ if (!source || !live || !source.file) return escape(text);
28
+ return `<button type="button" class="ins-at" data-file="${escape(source.file)}" data-line="${source.line ?? ""}" data-column="${source.column ?? ""}" title="Open ${escape(source.file)}">${escape(text)}</button>`;
29
+ };
30
+ var at = (source, root) => source ? `${source.file ? shortenPath(source.file, root) : ""}:${source.line ?? ""}:${source.column ?? ""}` : "";
31
+ var bothAt = (source, root) => {
32
+ if (!source) return "";
33
+ const out = source.compiled;
34
+ const same = out?.line === source.line && out?.column === source.column;
35
+ return out && !same ? `${at(source, root)} · out ${out.line ?? ""}:${out.column ?? ""}` : at(source, root);
36
+ };
37
+ function authoredPlace(node) {
38
+ for (const place2 of [node.source, node.declaredAt, node.usedAt]) {
39
+ if (place2 && !place2.external) return place2;
40
+ }
41
+ return node.declaredAt ?? node.source ?? node.usedAt;
42
+ }
43
+ function reaches(graph, id) {
44
+ const count = /* @__PURE__ */ new Map();
45
+ const writesHere = (nodes) => nodes.some((n) => n.writes?.includes(id) || writesHere(n.children));
46
+ for (const node of graph.values()) {
47
+ if (node.id === id || !node.dom?.length) continue;
48
+ if (writesHere(node.dom)) count.set(node.label, (count.get(node.label) ?? 0) + 1);
49
+ }
50
+ return [...count].map(([label, n]) => n > 1 ? `${label} ×${n}` : label);
51
+ }
52
+ function valueOf(node, limit) {
53
+ if (node.read) {
54
+ try {
55
+ return formatValue(node.read(), limit);
56
+ } catch {
57
+ }
58
+ }
59
+ return node.detail ?? node.value ?? "";
60
+ }
61
+ function createInspector(host, options = {}) {
62
+ const empty = options.empty ?? "click a node to inspect";
63
+ const limit = options.limit ?? 600;
64
+ const reveals = typeof options.onReveal === "function";
65
+ const root = options.root;
66
+ const edits = typeof options.onEdit === "function";
67
+ let editing = null;
68
+ let field = null;
69
+ let internals = options.internals === true;
70
+ let pane = null;
71
+ const doc = host.ownerDocument;
72
+ host.addEventListener("click", (event) => {
73
+ const cell = event.target?.closest?.("[data-full]");
74
+ if (!cell) return;
75
+ pane ??= createValuePane(host);
76
+ pane.open(cell.dataset.label || "value", cell.dataset.full || "");
77
+ });
78
+ const header = doc.createElement("div");
79
+ header.className = "ins-header";
80
+ const bar = doc.createElement("label");
81
+ bar.className = "ins-bar";
82
+ const box = doc.createElement("input");
83
+ box.type = "checkbox";
84
+ box.checked = internals;
85
+ bar.append(box, doc.createTextNode("framework"));
86
+ bar.title = "Also show where the framework created this, not only where it was written";
87
+ const body = doc.createElement("div");
88
+ body.className = "ins-body";
89
+ header.appendChild(bar);
90
+ host.replaceChildren(header, body);
91
+ box.addEventListener("change", () => {
92
+ internals = box.checked;
93
+ signature = "";
94
+ });
95
+ if (edits) {
96
+ host.addEventListener("click", (event) => {
97
+ const cell = event.target?.closest?.(".ins-edit");
98
+ if (!cell || editing !== null) return;
99
+ const id = Number(cell.dataset.id);
100
+ editing = id;
101
+ const input = host.ownerDocument.createElement("input");
102
+ field = input;
103
+ input.className = "ins-input";
104
+ input.value = cell.dataset.raw ?? "";
105
+ cell.replaceWith(input);
106
+ input.focus();
107
+ input.select();
108
+ const done = (commit) => {
109
+ if (editing === null) return;
110
+ editing = null;
111
+ field = null;
112
+ signature = "";
113
+ if (commit) options.onEdit(id, input.value);
114
+ };
115
+ input.addEventListener("keydown", (e) => {
116
+ if (e.key === "Enter") done(true);
117
+ else if (e.key === "Escape") done(false);
118
+ });
119
+ input.addEventListener("blur", () => done(true));
120
+ });
121
+ }
122
+ if (reveals) {
123
+ host.addEventListener("click", (event) => {
124
+ const button = event.target?.closest?.(".ins-at");
125
+ if (!button) return;
126
+ const line = Number(button.dataset.line);
127
+ const column = Number(button.dataset.column);
128
+ options.onReveal({
129
+ file: button.dataset.file,
130
+ ...Number.isFinite(line) && button.dataset.line ? { line } : {},
131
+ ...Number.isFinite(column) && button.dataset.column ? { column } : {}
132
+ });
133
+ });
134
+ }
135
+ let signature = "";
136
+ return {
137
+ show(graph, id) {
138
+ const node = id == null ? void 0 : graph.get(id);
139
+ if (!node) {
140
+ if (signature === "empty") return;
141
+ signature = "empty";
142
+ body.innerHTML = `<span class="ins-empty">${escape(empty)}</span>`;
143
+ return;
144
+ }
145
+ const labelOf = (other) => graph.get(other)?.label ?? "?";
146
+ const reads = [...node.deps].map(labelOf);
147
+ const feeds = [...graph.values()].filter((n) => n.deps.has(node.id) && n.kind !== "binding").map((n) => n.label);
148
+ const writes = [...node.writes].map(labelOf);
149
+ const value = valueOf(node, limit);
150
+ const state = nodeState(node);
151
+ const synthetic = node.kind === "binding" || node.kind === "setter" || node.kind === "group";
152
+ const owner = node.createdIn !== void 0 ? graph.get(node.createdIn)?.label : void 0;
153
+ const reaching = reaches(graph, node.id);
154
+ const made = [...graph.values()].filter((n) => n.createdIn === node.id).map((n) => n.label);
155
+ const bound = node.targets?.length ? node.targets.map((t) => {
156
+ const where = bothAt(t.source, root);
157
+ const what = escape(t.name ? `${t.name} of ${t.element}` : t.element);
158
+ return where ? `${what} (${place(where, t.source, reveals)})` : what;
159
+ }).join(", ") : node.bindings ? `${node.bindings} dom binding${node.bindings > 1 ? "s" : ""}` : "";
160
+ const relations = [
161
+ `<span>↤ reads ${reads.length ? `<b>${escape(reads.join(", "))}</b>` : "<i>nothing</i>"}</span>`,
162
+ // `bound` already carries markup for the places a value reaches, so only the
163
+ // labels are escaped here.
164
+ `<span>↦ feeds ${feeds.length || bound ? `<b>${[...feeds.map(escape), bound].filter(Boolean).join(", ")}</b>` : "<i>nothing yet</i>"}</span>`,
165
+ writes.length ? `<span>✎ writes <b>${escape(writes.join(", "))}</b></span>` : "",
166
+ // Where the value is set from code the graph has no node for.
167
+ node.setAt?.length ? `<span>⌁ set at <b>${node.setAt.map((w) => place(bothAt(w, root), w, reveals)).join(", ")}</b></span>` : "",
168
+ owner ? `<span>◧ made in <b>${escape(owner)}</b></span>` : "",
169
+ reaching.length ? `<span>◨ reaches <b>${escape(reaching.join(", "))}</b></span>` : "",
170
+ ...pluginRows(node, graph).map((row) => {
171
+ const where = row.at && { ...row.at, file: row.at.file ?? node.source?.file };
172
+ const text = where?.file ? bothAt(where, root) : "";
173
+ const more = row.value !== void 0 && row.value.length > 140;
174
+ return `<span${more ? ` class="ins-more" data-full="${escape(row.value)}" data-label="${escape(row.label)}"` : ""} title="${escape(row.value ?? row.label)}">⌘ ${escape(row.label)}${row.value ? `=<b>${escape(clip(row.value))}</b>` : ""}${text ? ` ${place(text, where, reveals)}` : ""}</span>`;
175
+ }),
176
+ // What the tag was written with. A prop's position has no file of its own: it was
177
+ // written on the tag, so it belongs to whichever file that is.
178
+ ...(node.props ?? []).map((p) => {
179
+ const where = p.at && { ...p.at, file: p.at.file ?? node.source?.file };
180
+ const at2 = where?.file ? bothAt(where, root) : "";
181
+ return `<span>⇥ ${escape(p.name)}=<b>${escape(clip(p.value ?? "", 60))}</b>${at2 ? ` ${place(at2, where, reveals)}` : ""}</span>`;
182
+ }),
183
+ made.length ? `<span>▸ made <b>${escape(made.join(", "))}</b></span>` : ""
184
+ ].filter(Boolean).join("");
185
+ const next = `${node.id}|${node.kind}|${value}|${node.runs}|${state ?? ""}|${relations}|${at(node.source, root)}|${at(node.usedAt, root)}|${bound}`;
186
+ if (editing !== null && field?.isConnected !== true) {
187
+ editing = null;
188
+ field = null;
189
+ }
190
+ if (editing !== null) return;
191
+ if (next === signature) return;
192
+ signature = next;
193
+ body.innerHTML = `<div class="ins-head"><span class="ins-kind n-${node.kind}">${node.kind}</span><b>${escape(node.label)}</b>` + (synthetic ? '<span class="ins-meta">not a node</span></div>' : `<span class="ins-meta">v${nodeVersion(node)} · ${node.runs} runs${state ? ` · ${state}` : ""}</span></div>`) + (edits && node.kind === "state" ? `<div class="ins-val ins-edit" data-id="${node.id}" data-raw="${escape(value)}" title="Click to set ${escape(node.label)}">${escape(clip(value))}</div>` : `<div class="ins-val${value.length > 140 ? " ins-more" : ""}"${value.length > 140 ? ` data-full="${escape(value)}" data-label="${escape(node.label)}"` : ""} title="${escape(value)}">${escape(clip(value))}</div>`) + `<div class="ins-rel">${relations}</div>` + // Only when the graph carries one. A snapshot from a build that was not marked has
194
+ // no locations at all, and an empty line there reads as missing data.
195
+ (node.source ? `<div class="ins-source">${node.source.external ? "📦" : "📍"} ${place(bothAt(node.source, root), node.source, reveals)}</div>` : "") + // A component is created where its tag is written; where it is declared is somewhere
196
+ // else, and only worth a line when it is.
197
+ (node.declaredAt && at(node.declaredAt, root) !== at(node.source, root) ? `<div class="ins-source">◧ ${node.kind === "custom-element" ? "defined at" : "declared"} ${place(at(node.declaredAt, root), node.declaredAt, reveals)}</div>` : "") + // A node a package made on the application's behalf: the package's line is where it
198
+ // was created, and this is the line that asked for it.
199
+ (node.usedAt ? `<div class="ins-source">↗ used at ${place(bothAt(node.usedAt, root), node.usedAt, reveals)}</div>` : "") + // Nothing said where it came from at all: the compiler did not mark this project and
200
+ // the stack had nothing to offer either. Saying so beats a card that just sits there.
201
+ (!node.source && !node.usedAt && !node.declaredAt ? '<div class="ins-source">— no source: build without sourceLocations</div>' : "");
202
+ },
203
+ showElement(graph, pick) {
204
+ if (!pick) {
205
+ if (signature === "empty") return;
206
+ signature = "empty";
207
+ body.innerHTML = `<span class="ins-empty">${escape(empty)}</span>`;
208
+ return;
209
+ }
210
+ const owner = pick.owner === void 0 ? void 0 : graph.get(pick.owner);
211
+ const writers = (pick.writes ?? []).map((id) => graph.get(id)).filter((n) => n !== void 0);
212
+ const bindingAt = (node) => node.targets?.find((t) => t.element === pick.label || t.element.endsWith(` in ${pick.label}`))?.source;
213
+ const rows = writers.map((node) => {
214
+ const where = bindingAt(node);
215
+ const text = where ? bothAt(where, root) : "";
216
+ return `<span>⌁ <b>${escape(node.label)}</b>${text ? ` ${place(text, where, reveals)}` : ""}</span>`;
217
+ }).join("");
218
+ const relations = [
219
+ owner ? `<span>◧ rendered by <b>${escape(owner.label)}</b></span>` : "<span>◧ rendered by <i>nothing in the graph</i></span>",
220
+ writers.length ? rows : "<span>⌁ <i>nothing writes here</i></span>",
221
+ ...pluginElementRows(pick.extra).map((row) => {
222
+ const where = row.at && { ...row.at, file: row.at.file ?? owner?.source?.file };
223
+ const text = where?.file ? bothAt(where, root) : "";
224
+ const more = row.value !== void 0 && row.value.length > 140;
225
+ return `<span${more ? ` class="ins-more" data-full="${escape(row.value)}" data-label="${escape(row.label)}"` : ""} title="${escape(row.value ?? row.label)}">⌘ ${escape(row.label)}${row.value ? `=<b>${escape(clip(row.value))}</b>` : ""}${text ? ` ${place(text, where, reveals)}` : ""}</span>`;
226
+ })
227
+ ].join("");
228
+ const source = pick.at ?? (owner && (owner.declaredAt ?? authoredPlace(owner)));
229
+ const madeIn = internals && owner?.source && owner.source !== source ? owner.source : void 0;
230
+ const next = `el|${pick.key}|${pick.label}|${relations}|${at(source, root)}|${at(madeIn, root)}`;
231
+ if (editing !== null && field?.isConnected !== true) {
232
+ editing = null;
233
+ field = null;
234
+ }
235
+ if (editing !== null) return;
236
+ if (next === signature) return;
237
+ signature = next;
238
+ body.innerHTML = `<div class="ins-head"><span class="ins-kind n-element">element</span><b>${escape(pick.label)}</b><span class="ins-meta">not a node</span></div><div class="ins-rel">${relations}</div>` + // The tag's own line. An element has no position of its own in the graph, only the
239
+ // component that rendered it does: so this is as close as the source gets.
240
+ (source ? `<div class="ins-source">${source.external ? "📦" : "📍"} ${place(bothAt(source, root), source, reveals)}</div>` : "") + (madeIn ? `<div class="ins-source">📦 made in ${place(bothAt(madeIn, root), madeIn, reveals)}</div>` : "");
241
+ },
242
+ clear() {
243
+ signature = "";
244
+ body.innerHTML = `<span class="ins-empty">${escape(empty)}</span>`;
245
+ }
246
+ };
247
+ }
248
+ var INSPECTOR_CSS = `
249
+ ${VALUE_PANE_CSS}
250
+ /* Anything cut to fit says so, and opens the whole of it. */
251
+ .ins-more { cursor: zoom-in; }
252
+ .ins-header{ display: flex; align-items: center; gap: 8px; padding: .3rem .5rem; }
253
+ .ins-body { padding: .5rem; }
254
+ .ins-more:hover { text-decoration: underline dotted; }
255
+ .ins-empty { color: var(--fx-muted, #8a90a2); font-size: 12px; }
256
+ .ins-bar {
257
+ display: flex; align-items: center; gap: 5px; margin-bottom: 6px;
258
+ font-size: 10.5px; color: var(--fx-muted, #8a90a2); cursor: pointer; user-select: none;
259
+ }
260
+ .ins-bar:hover { color: var(--fx-label, #e7e9ee); }
261
+ .ins-bar input { width: 11px; height: 11px; margin: 0; accent-color: var(--fx-accent, #5eead4); }
262
+ .ins-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
263
+ .ins-head b { font-size: 13px; color: var(--fx-label, #e7e9ee); }
264
+ .ins-kind { font-family: ui-monospace, monospace; font-size: 9.5px; text-transform: uppercase; letter-spacing: 1px; }
265
+ ${kindRules((k) => `.ins-kind.n-${k}`, "color")}
266
+ .ins-meta { margin-left: auto; color: var(--fx-muted, #8a90a2); font-family: ui-monospace, monospace; font-size: 10.5px; }
267
+ .ins-val { font-family: ui-monospace, monospace; font-size: 12px; color: var(--fx-label, #e7e9ee); word-break: break-word; }
268
+ .ins-rel { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 6px; color: var(--fx-muted, #8a90a2); font-size: 11.5px; }
269
+ .ins-rel b { color: var(--fx-label, #e7e9ee); font-weight: 600; }
270
+ .ins-rel i { font-style: normal; opacity: .6; }
271
+ .ins-edit { cursor: text; border-bottom: 1px dashed var(--fx-line, #262a35); }
272
+ .ins-edit:hover { border-bottom-color: var(--fx-accent, #5eead4); }
273
+ .ins-input {
274
+ width: 100%; box-sizing: border-box; padding: 1px 4px;
275
+ font: inherit; font-family: ui-monospace, monospace;
276
+ color: var(--fx-label, #e7e9ee); background: var(--fx-bg, #0f1115);
277
+ border: 1px solid var(--fx-accent, #5eead4); border-radius: 3px;
278
+ }
279
+ .ins-at {
280
+ font: inherit; color: inherit; background: none; border: 0; padding: 0;
281
+ cursor: pointer; text-decoration: underline; text-decoration-style: dotted;
282
+ text-underline-offset: 2px;
283
+ }
284
+ .ins-at:hover { color: var(--fx-accent, #5eead4); }
285
+ .ins-at:focus-visible { outline: 1px solid var(--fx-accent, #5eead4); outline-offset: 1px; }
286
+ .ins-source { margin-top: 6px; font-family: ui-monospace, monospace; font-size: 10.5px; color: var(--fx-muted, #8a90a2); }
287
+ `;
288
+
289
+ export {
290
+ createInspector,
291
+ INSPECTOR_CSS
292
+ };
@@ -0,0 +1,155 @@
1
+ // src/kind-filter.ts
2
+ var FILTERABLE_KINDS = [
3
+ "state",
4
+ "memo",
5
+ "effect",
6
+ "store",
7
+ "resource",
8
+ "component",
9
+ "provider",
10
+ "control",
11
+ "router",
12
+ "handler",
13
+ "context",
14
+ "directive",
15
+ "custom-element",
16
+ "module",
17
+ "service"
18
+ ];
19
+ var LABEL = { handler: "route", "custom-element": "custom element" };
20
+ function createKindFilter(host, options) {
21
+ const doc = host.ownerDocument;
22
+ const kinds = options.kinds ?? FILTERABLE_KINDS;
23
+ const on = new Set(kinds);
24
+ const root = doc.createElement("div");
25
+ root.className = "fx-kinds";
26
+ const button = doc.createElement("button");
27
+ button.type = "button";
28
+ button.className = "fx-kinds-button fx-dropdown-btn";
29
+ button.setAttribute("aria-haspopup", "true");
30
+ button.setAttribute("aria-expanded", "false");
31
+ button.title = "Choose which kinds of node the graph draws";
32
+ const caret = doc.createElement("div");
33
+ caret.className = "fx-dropdown-caret";
34
+ const panel = doc.createElement("div");
35
+ panel.className = "fx-kinds-panel";
36
+ if (options.panelClass) {
37
+ panel.classList.add(...options.panelClass.split(/\s+/).filter((c) => c));
38
+ }
39
+ panel.hidden = true;
40
+ const all = doc.createElement("input");
41
+ all.type = "checkbox";
42
+ const allRow = doc.createElement("label");
43
+ allRow.className = "fx-kinds-all";
44
+ allRow.append(all, doc.createTextNode("all"));
45
+ const boxes = /* @__PURE__ */ new Map();
46
+ for (const kind of kinds) {
47
+ const box = doc.createElement("input");
48
+ box.type = "checkbox";
49
+ box.checked = true;
50
+ const row = doc.createElement("label");
51
+ row.append(box, doc.createTextNode(LABEL[kind] ?? kind));
52
+ panel.append(row);
53
+ boxes.set(kind, box);
54
+ }
55
+ panel.prepend(allRow);
56
+ root.append(button, panel);
57
+ host.append(root);
58
+ const everything = () => on.size === kinds.length;
59
+ const chosen = () => kinds.filter((kind) => on.has(kind));
60
+ function paint() {
61
+ const name = options.label ?? "Kinds";
62
+ button.textContent = everything() ? name : `${name} · ${on.size}`;
63
+ button.classList.toggle("on", !everything());
64
+ all.checked = everything();
65
+ button.appendChild(caret);
66
+ all.indeterminate = on.size > 0 && !everything();
67
+ for (const [kind, box] of boxes) box.checked = on.has(kind);
68
+ }
69
+ function report() {
70
+ options.onChange(everything() ? null : chosen());
71
+ }
72
+ for (const [kind, box] of boxes) {
73
+ box.addEventListener("change", () => {
74
+ if (box.checked) on.add(kind);
75
+ else on.delete(kind);
76
+ paint();
77
+ report();
78
+ });
79
+ }
80
+ all.addEventListener("change", () => {
81
+ for (const kind of kinds) on.add(kind);
82
+ paint();
83
+ report();
84
+ });
85
+ const close = () => {
86
+ panel.hidden = true;
87
+ button.setAttribute("aria-expanded", "false");
88
+ };
89
+ button.addEventListener("click", (event) => {
90
+ event.stopPropagation();
91
+ panel.hidden = !panel.hidden;
92
+ button.setAttribute("aria-expanded", String(!panel.hidden));
93
+ });
94
+ panel.addEventListener("click", (event) => event.stopPropagation());
95
+ const away = () => close();
96
+ const key = (event) => {
97
+ if (event.key === "Escape") close();
98
+ };
99
+ doc.addEventListener("click", away);
100
+ doc.addEventListener("keydown", key);
101
+ paint();
102
+ return {
103
+ get selected() {
104
+ return chosen();
105
+ },
106
+ select(next) {
107
+ on.clear();
108
+ for (const kind of next ?? kinds) on.add(kind);
109
+ paint();
110
+ },
111
+ destroy() {
112
+ doc.removeEventListener("click", away);
113
+ doc.removeEventListener("keydown", key);
114
+ root.remove();
115
+ }
116
+ };
117
+ }
118
+ var KIND_FILTER_CSS = `
119
+ .fx-kinds { position: relative; display: inline-flex; }
120
+ .fx-kinds-button { white-space: nowrap; }
121
+ /* The hidden attribute is display:none from the user agent, which a class setting display outranks. */
122
+ .fx-kinds-panel[hidden] { display: none; }
123
+ .fx-kinds-panel {
124
+ position: absolute; top: calc(100% + 4px); z-index: 40;
125
+ display: grid; gap: 2px; padding: 6px 8px; min-width: 132px;
126
+ background: var(--fx-panel, #14161c);
127
+ border: 1px solid var(--fx-line, #262a35); border-radius: 6px;
128
+ box-shadow: 0 6px 18px rgba(0, 0, 0, .38);
129
+ }
130
+ .fx-kinds-panel:not(.fx-panel-left){ right: 0; }
131
+ .fx-kinds-panel.fx-panel-left { left: 0; }
132
+ .fx-kinds-panel label {
133
+ display: flex; align-items: center; gap: 6px;
134
+ font-size: 11px; color: var(--fx-muted, #8a90a2); cursor: pointer; user-select: none;
135
+ }
136
+ .fx-kinds-panel label:hover { color: var(--fx-label, #e7e9ee); }
137
+ .fx-kinds-panel input { width: 11px; height: 11px; margin: 0; accent-color: var(--fx-accent, #5eead4); }
138
+ .fx-kinds-all {
139
+ padding-bottom: 4px; margin-bottom: 2px;
140
+ border-bottom: 1px solid var(--fx-line, #262a35);
141
+ color: var(--fx-label, #e7e9ee) !important;
142
+ }
143
+ `;
144
+ var DROPDOWN_FILTER_CSS = `
145
+ .fx-dropdown-btn { background-color: transparent; appearance: none; border: 1px solid var(--line-strong); outline: none; border-radius: .25rem; padding-block: .25rem; padding-inline: .875rem; font-size: .75rem; cursor: pointer }
146
+ .fx-dropdown-btn:hover { border-color: color-mix(in oklab, var(--accent) 50%, transparent); background-color: var(--bg); }
147
+ .fx-dropdown-caret { width: 0;height: 0;border-left: .15rem solid transparent; border-right: .15rem solid transparent; border-top: .15rem solid currentColor; transition: transform 0.2s ease; right: .4rem; top: 50%; color: color-mix(in oklab, var(--muted) 50%, transparent); position: absolute; }
148
+ `;
149
+
150
+ export {
151
+ FILTERABLE_KINDS,
152
+ createKindFilter,
153
+ KIND_FILTER_CSS,
154
+ DROPDOWN_FILTER_CSS
155
+ };