@fluixi/devtools 1.0.0-alpha.107 → 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.
- package/dist/callsite.mjs +4 -63
- package/dist/change-view.mjs +6 -106
- package/dist/chunk-2VDMQ3VF.mjs +520 -0
- package/dist/chunk-33U2S43X.mjs +121 -0
- package/dist/chunk-4P45Y5EB.mjs +214 -0
- package/dist/chunk-B3SAJ7QG.mjs +72 -0
- package/dist/chunk-CPZWLBCQ.mjs +35 -0
- package/dist/chunk-D25KZZBZ.mjs +212 -0
- package/dist/chunk-EBSROPWJ.mjs +314 -0
- package/dist/chunk-F664XLZL.mjs +743 -0
- package/dist/chunk-FY5K3QVT.mjs +35 -0
- package/dist/chunk-G7Z7CVP5.mjs +184 -0
- package/dist/chunk-GDQXCOQB.mjs +43 -0
- package/dist/chunk-L6XQGNMW.mjs +106 -0
- package/dist/chunk-MN6O673L.mjs +90 -0
- package/dist/chunk-NDUBBBNL.mjs +70 -0
- package/dist/chunk-NT7YMK77.mjs +157 -0
- package/dist/chunk-NVULLJDH.mjs +120 -0
- package/dist/chunk-NWLSDERQ.mjs +68 -0
- package/dist/chunk-OPIGF5XB.mjs +184 -0
- package/dist/chunk-P5I7DWFX.mjs +292 -0
- package/dist/chunk-PKARAAIS.mjs +75 -0
- package/dist/chunk-PSSBFXBD.mjs +155 -0
- package/dist/chunk-PTQ5VCYE.mjs +103 -0
- package/dist/chunk-PU4MJ5RU.mjs +107 -0
- package/dist/chunk-UAEJ3N7F.mjs +76 -0
- package/dist/chunk-V6DKWEYD.mjs +67 -0
- package/dist/chunk-VO2V7AC5.mjs +80 -0
- package/dist/chunk-WGQH7RUW.mjs +25 -0
- package/dist/chunk-Y5OQWBAM.mjs +777 -0
- package/dist/chunk-Z6KYHEKY.mjs +64 -0
- package/dist/copy.mjs +3 -39
- package/dist/describe.mjs +3 -31
- package/dist/detail-panel.mjs +6 -280
- package/dist/diff.mjs +4 -201
- package/dist/dom.mjs +7 -176
- package/dist/export.mjs +6 -207
- package/dist/float.mjs +5 -206
- package/dist/format.mjs +5 -151
- package/dist/graph-view.mjs +9 -875
- package/dist/highlight.mjs +6 -113
- package/dist/history.mjs +4 -70
- package/dist/hook.mjs +16 -1719
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +106 -4673
- package/dist/inspector.mjs +11 -677
- package/dist/instrument.mjs +9 -486
- package/dist/kind-filter.mjs +6 -148
- package/dist/menu.mjs +4 -116
- package/dist/observe.mjs +14 -1510
- package/dist/palette.mjs +6 -28
- package/dist/path.mjs +3 -21
- package/dist/plugin.mjs +9 -57
- package/dist/plugins/context.mjs +6 -71
- package/dist/plugins/directives.mjs +8 -68
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.mjs +13 -136
- package/dist/source.mjs +12 -93
- package/dist/timeline.mjs +7 -323
- package/dist/tree.mjs +11 -558
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/value-pane.mjs +6 -196
- package/dist/wire.cjs +1 -1
- package/dist/wire.mjs +6 -86
- package/package.json +3 -3
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// src/highlight.ts
|
|
2
|
+
var LAYER = "fx-highlight-layer";
|
|
3
|
+
var overlay = null;
|
|
4
|
+
function build(doc) {
|
|
5
|
+
const layer = doc.createElement("div");
|
|
6
|
+
layer.id = LAYER;
|
|
7
|
+
layer.style.cssText = "position:fixed;inset:0;z-index:2147483646;pointer-events:none;contain:strict;";
|
|
8
|
+
const label = doc.createElement("div");
|
|
9
|
+
label.style.cssText = "position:absolute;padding:1px 5px;border-radius:3px;background:#5eead4;color:#07131a;font:11px/1.5 ui-monospace,monospace;white-space:nowrap;";
|
|
10
|
+
layer.append(label);
|
|
11
|
+
doc.body.appendChild(layer);
|
|
12
|
+
return { layer, boxes: [], label };
|
|
13
|
+
}
|
|
14
|
+
function boxIn(overlay2, index) {
|
|
15
|
+
const held = overlay2.boxes[index];
|
|
16
|
+
if (held) return held;
|
|
17
|
+
const box = overlay2.layer.ownerDocument.createElement("div");
|
|
18
|
+
box.style.cssText = "position:absolute;border:1px solid #5eead4;background:rgba(94,234,212,.16);border-radius:2px;transition:none;";
|
|
19
|
+
overlay2.layer.append(box);
|
|
20
|
+
overlay2.boxes.push(box);
|
|
21
|
+
return box;
|
|
22
|
+
}
|
|
23
|
+
function showHighlight(target, text) {
|
|
24
|
+
const elements = (Array.isArray(target) ? target : [target]).filter(
|
|
25
|
+
(el) => el?.isConnected
|
|
26
|
+
);
|
|
27
|
+
const first = elements[0];
|
|
28
|
+
const doc = first?.ownerDocument;
|
|
29
|
+
if (!doc?.body) {
|
|
30
|
+
hideHighlight();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!overlay || overlay.layer.ownerDocument !== doc || !overlay.layer.isConnected) {
|
|
34
|
+
overlay = build(doc);
|
|
35
|
+
}
|
|
36
|
+
const { label, layer } = overlay;
|
|
37
|
+
layer.style.display = "";
|
|
38
|
+
let top = Infinity;
|
|
39
|
+
let left = Infinity;
|
|
40
|
+
let bottom = 0;
|
|
41
|
+
elements.forEach((element, index) => {
|
|
42
|
+
const rect = element.getBoundingClientRect();
|
|
43
|
+
const box = boxIn(overlay, index);
|
|
44
|
+
box.style.display = "";
|
|
45
|
+
box.style.left = `${rect.left}px`;
|
|
46
|
+
box.style.top = `${rect.top}px`;
|
|
47
|
+
box.style.width = `${rect.width}px`;
|
|
48
|
+
box.style.height = `${rect.height}px`;
|
|
49
|
+
top = Math.min(top, rect.top);
|
|
50
|
+
left = Math.min(left, rect.left);
|
|
51
|
+
bottom = Math.max(bottom, rect.bottom);
|
|
52
|
+
});
|
|
53
|
+
for (let i = elements.length; i < overlay.boxes.length; i++) {
|
|
54
|
+
overlay.boxes[i].style.display = "none";
|
|
55
|
+
}
|
|
56
|
+
if (!text) {
|
|
57
|
+
label.style.display = "none";
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
label.style.display = "";
|
|
61
|
+
label.textContent = text;
|
|
62
|
+
label.style.left = `${Math.max(2, left)}px`;
|
|
63
|
+
label.style.top = top >= 20 ? `${top - 18}px` : `${bottom + 4}px`;
|
|
64
|
+
}
|
|
65
|
+
function hideHighlight() {
|
|
66
|
+
if (overlay) overlay.layer.style.display = "none";
|
|
67
|
+
}
|
|
68
|
+
function removeHighlight() {
|
|
69
|
+
overlay?.layer.remove();
|
|
70
|
+
overlay = null;
|
|
71
|
+
}
|
|
72
|
+
function startPicking(options) {
|
|
73
|
+
const doc = options.document ?? globalThis.document;
|
|
74
|
+
if (!doc?.body) return () => {
|
|
75
|
+
};
|
|
76
|
+
const was = doc.body.style.cursor;
|
|
77
|
+
doc.body.style.cursor = "crosshair";
|
|
78
|
+
const under = (event) => {
|
|
79
|
+
const target = event.target;
|
|
80
|
+
return target?.closest?.(`#${LAYER}`) ? null : target;
|
|
81
|
+
};
|
|
82
|
+
const move = (event) => {
|
|
83
|
+
const element = under(event);
|
|
84
|
+
const id = options.nodeAt(element);
|
|
85
|
+
if (element && id !== void 0) showHighlight(element, options.describe?.(id, element));
|
|
86
|
+
else hideHighlight();
|
|
87
|
+
};
|
|
88
|
+
const click = (event) => {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
const target = under(event);
|
|
92
|
+
const id = options.nodeAt(target);
|
|
93
|
+
if (!options.sticky) stop();
|
|
94
|
+
if (id !== void 0) options.onPick(id, target);
|
|
95
|
+
else if (!options.sticky) options.onCancel?.();
|
|
96
|
+
};
|
|
97
|
+
const key = (event) => {
|
|
98
|
+
if (event.key !== "Escape") return;
|
|
99
|
+
stop();
|
|
100
|
+
options.onCancel?.();
|
|
101
|
+
};
|
|
102
|
+
const stop = () => {
|
|
103
|
+
doc.body.style.cursor = was;
|
|
104
|
+
doc.removeEventListener("pointermove", move, true);
|
|
105
|
+
doc.removeEventListener("click", click, true);
|
|
106
|
+
doc.removeEventListener("keydown", key, true);
|
|
107
|
+
hideHighlight();
|
|
108
|
+
};
|
|
109
|
+
doc.addEventListener("pointermove", move, true);
|
|
110
|
+
doc.addEventListener("click", click, true);
|
|
111
|
+
doc.addEventListener("keydown", key, true);
|
|
112
|
+
return stop;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
showHighlight,
|
|
117
|
+
hideHighlight,
|
|
118
|
+
removeHighlight,
|
|
119
|
+
startPicking
|
|
120
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/callsite.ts
|
|
2
|
+
var EXTENSION = ["chrome-extension://", "moz-extension://", "safari-web-extension://", "extension://"];
|
|
3
|
+
var INTERNAL = [
|
|
4
|
+
"/packages/reactive/",
|
|
5
|
+
"/packages/dom/",
|
|
6
|
+
"/packages/core/",
|
|
7
|
+
"/packages/devtools/",
|
|
8
|
+
"/packages/web-components/",
|
|
9
|
+
"/packages/auth/",
|
|
10
|
+
"/packages/oauth2/",
|
|
11
|
+
"/packages/session/",
|
|
12
|
+
"/packages/router/",
|
|
13
|
+
"/packages/head/",
|
|
14
|
+
"/packages/start/",
|
|
15
|
+
"/packages/server/",
|
|
16
|
+
"/packages/template-runtime/",
|
|
17
|
+
"/@fluixi/",
|
|
18
|
+
"node_modules",
|
|
19
|
+
"fluixi-devtools",
|
|
20
|
+
...EXTENSION
|
|
21
|
+
];
|
|
22
|
+
var REPORTING = [
|
|
23
|
+
"/packages/reactive/src/lib/signal/graph/",
|
|
24
|
+
"/packages/devtools/",
|
|
25
|
+
"fluixi-devtools",
|
|
26
|
+
// Not a fallback either: naming the agent as where a node came from is worse than nothing.
|
|
27
|
+
...EXTENSION
|
|
28
|
+
];
|
|
29
|
+
var FRAME = /(?:at\s+(?:[^(]*\()?)([^()\s]+):(\d+):(\d+)\)?$/;
|
|
30
|
+
var isInternal = (frame) => INTERNAL.some((part) => frame.includes(part));
|
|
31
|
+
function locate(frame, origin) {
|
|
32
|
+
const match = FRAME.exec(frame);
|
|
33
|
+
if (!match) return void 0;
|
|
34
|
+
let file = match[1];
|
|
35
|
+
if (origin && file.startsWith(origin)) file = file.slice(origin.length);
|
|
36
|
+
file = file.replace(/^\/@fs\//, "/").replace(/\?.*$/, "").replace(/^\//, "");
|
|
37
|
+
return file ? { file, line: Number(match[2]), column: Number(match[3]) } : void 0;
|
|
38
|
+
}
|
|
39
|
+
function callSite(stack, origin) {
|
|
40
|
+
if (!stack) return void 0;
|
|
41
|
+
let fallback;
|
|
42
|
+
for (const line of stack.split("\n")) {
|
|
43
|
+
const frame = line.trim();
|
|
44
|
+
if (!frame.startsWith("at ")) continue;
|
|
45
|
+
if (!isInternal(frame)) {
|
|
46
|
+
const location = locate(frame, origin);
|
|
47
|
+
if (location) return { location, external: false };
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!fallback && !REPORTING.some((part) => frame.includes(part))) fallback = locate(frame, origin);
|
|
51
|
+
}
|
|
52
|
+
return fallback ? { location: { ...fallback, external: true }, external: true } : void 0;
|
|
53
|
+
}
|
|
54
|
+
function currentCallSite(origin) {
|
|
55
|
+
const errors = Error;
|
|
56
|
+
const limit = errors.stackTraceLimit;
|
|
57
|
+
errors.stackTraceLimit = 50;
|
|
58
|
+
try {
|
|
59
|
+
return callSite(new Error().stack, origin);
|
|
60
|
+
} finally {
|
|
61
|
+
errors.stackTraceLimit = limit;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
callSite,
|
|
67
|
+
currentCallSite
|
|
68
|
+
};
|
|
@@ -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) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[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
|
+
};
|