@aylith/inspekt-core 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/built-in.d.ts +17 -0
- package/dist/actions/built-in.d.ts.map +1 -0
- package/dist/adapters/generic.d.ts +3 -0
- package/dist/adapters/generic.d.ts.map +1 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/react.d.ts +3 -0
- package/dist/adapters/react.d.ts.map +1 -0
- package/dist/adapters/solid.d.ts +3 -0
- package/dist/adapters/solid.d.ts.map +1 -0
- package/dist/adapters/svelte.d.ts +3 -0
- package/dist/adapters/svelte.d.ts.map +1 -0
- package/dist/adapters/types.d.ts +19 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/vue.d.ts +3 -0
- package/dist/adapters/vue.d.ts.map +1 -0
- package/dist/capability-probe-AKVKYSDE.js +107 -0
- package/dist/capability-probe-AKVKYSDE.js.map +1 -0
- package/dist/components/rich-select.d.ts +62 -0
- package/dist/components/rich-select.d.ts.map +1 -0
- package/dist/components/tooltip.d.ts +34 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/detection/capability-probe.d.ts +31 -0
- package/dist/detection/capability-probe.d.ts.map +1 -0
- package/dist/detection/fiber-detector.d.ts +12 -0
- package/dist/detection/fiber-detector.d.ts.map +1 -0
- package/dist/detection/source-detector.d.ts +30 -0
- package/dist/detection/source-detector.d.ts.map +1 -0
- package/dist/detection/vue-detector.d.ts +14 -0
- package/dist/detection/vue-detector.d.ts.map +1 -0
- package/dist/fiber-detector-CFB7M7OY.js +50 -0
- package/dist/fiber-detector-CFB7M7OY.js.map +1 -0
- package/dist/highlight/bounding-boxes.d.ts +20 -0
- package/dist/highlight/bounding-boxes.d.ts.map +1 -0
- package/dist/highlight/highlighter.d.ts +11 -0
- package/dist/highlight/highlighter.d.ts.map +1 -0
- package/dist/highlight/prism.d.ts +23 -0
- package/dist/highlight/prism.d.ts.map +1 -0
- package/dist/index.cjs +3560 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3222 -0
- package/dist/index.js.map +1 -0
- package/dist/overlay/overlay.d.ts +30 -0
- package/dist/overlay/overlay.d.ts.map +1 -0
- package/dist/popover/popover.d.ts +54 -0
- package/dist/popover/popover.d.ts.map +1 -0
- package/dist/runtime/context.d.ts +3 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/freeze.d.ts +2 -0
- package/dist/runtime/freeze.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/open-file.d.ts +2 -0
- package/dist/runtime/open-file.d.ts.map +1 -0
- package/dist/snippet/cache.d.ts +13 -0
- package/dist/snippet/cache.d.ts.map +1 -0
- package/dist/snippet/snippet-resolver.d.ts +21 -0
- package/dist/snippet/snippet-resolver.d.ts.map +1 -0
- package/dist/snippet/sourcemap-resolver.d.ts +9 -0
- package/dist/snippet/sourcemap-resolver.d.ts.map +1 -0
- package/dist/sourcemap-resolver-3PQ6R6PU.js +182 -0
- package/dist/sourcemap-resolver-3PQ6R6PU.js.map +1 -0
- package/dist/styles.d.ts +2 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/tree-panel/tree-panel.d.ts +33 -0
- package/dist/tree-panel/tree-panel.d.ts.map +1 -0
- package/dist/types.d.ts +148 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +51 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3222 @@
|
|
|
1
|
+
// src/detection/vue-detector.ts
|
|
2
|
+
function fromVue3(el) {
|
|
3
|
+
let cmp = el.__vueParentComponent;
|
|
4
|
+
while (cmp) {
|
|
5
|
+
const file = cmp.type?.__file;
|
|
6
|
+
if (file) {
|
|
7
|
+
const name = cmp.type?.__name ?? cmp.type?.name ?? fileNameOf(file);
|
|
8
|
+
return {
|
|
9
|
+
filePath: file,
|
|
10
|
+
line: 1,
|
|
11
|
+
column: 1,
|
|
12
|
+
componentName: name,
|
|
13
|
+
rawPath: `${file}:1:1:${name}`
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
cmp = cmp.parent ?? null;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function fromVue2(el) {
|
|
21
|
+
let vm = el.__vue__;
|
|
22
|
+
while (vm) {
|
|
23
|
+
const file = vm.$options?.__file;
|
|
24
|
+
if (file) {
|
|
25
|
+
const name = vm.$options?.name ?? vm.$options?._componentTag ?? fileNameOf(file);
|
|
26
|
+
return {
|
|
27
|
+
filePath: file,
|
|
28
|
+
line: 1,
|
|
29
|
+
column: 1,
|
|
30
|
+
componentName: name,
|
|
31
|
+
rawPath: `${file}:1:1:${name}`
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
vm = vm.$parent ?? null;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function fileNameOf(path) {
|
|
39
|
+
return path.split("/").pop()?.replace(/\.\w+$/, "") ?? "Unknown";
|
|
40
|
+
}
|
|
41
|
+
function vueSourceFor(element) {
|
|
42
|
+
const el = element;
|
|
43
|
+
return fromVue3(el) ?? fromVue2(el);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/detection/source-detector.ts
|
|
47
|
+
var SOURCE_ATTRIBUTE = "data-insp-path";
|
|
48
|
+
function parseSourceAttribute(value) {
|
|
49
|
+
const parts = value.split(":");
|
|
50
|
+
if (parts.length < 2) return null;
|
|
51
|
+
let filePath;
|
|
52
|
+
let rest;
|
|
53
|
+
if (/^[A-Z]$/i.test(parts[0] ?? "") && parts[1]?.startsWith("\\")) {
|
|
54
|
+
filePath = `${parts[0]}:${parts[1]}`;
|
|
55
|
+
rest = parts.slice(2);
|
|
56
|
+
} else {
|
|
57
|
+
filePath = parts[0];
|
|
58
|
+
rest = parts.slice(1);
|
|
59
|
+
}
|
|
60
|
+
const line = parseInt(rest[0] ?? "", 10);
|
|
61
|
+
const column = parseInt(rest[1] ?? "", 10);
|
|
62
|
+
const componentName = rest[2] ?? filePath.split("/").pop()?.replace(/\.\w+$/, "") ?? "Unknown";
|
|
63
|
+
if (isNaN(line)) return null;
|
|
64
|
+
return {
|
|
65
|
+
filePath,
|
|
66
|
+
line,
|
|
67
|
+
column: isNaN(column) ? 1 : column,
|
|
68
|
+
componentName,
|
|
69
|
+
rawPath: value
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function findSourceAttribute(element) {
|
|
73
|
+
return element.getAttribute(SOURCE_ATTRIBUTE);
|
|
74
|
+
}
|
|
75
|
+
function findClosestSource(element) {
|
|
76
|
+
let current = element;
|
|
77
|
+
while (current) {
|
|
78
|
+
const attrValue = findSourceAttribute(current);
|
|
79
|
+
if (attrValue) {
|
|
80
|
+
const source = parseSourceAttribute(attrValue);
|
|
81
|
+
if (source) return { element: current, source };
|
|
82
|
+
}
|
|
83
|
+
current = current.parentElement;
|
|
84
|
+
}
|
|
85
|
+
const vueSource = vueSourceFor(element);
|
|
86
|
+
if (vueSource) return { element, source: vueSource };
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function elementToInspected(domElement, source, pathMapping = {}, detectionSource = "attribute") {
|
|
90
|
+
let resolvedPath = source.filePath;
|
|
91
|
+
for (const [containerPath, hostPath] of Object.entries(pathMapping)) {
|
|
92
|
+
if (resolvedPath.startsWith(containerPath)) {
|
|
93
|
+
resolvedPath = resolvedPath.replace(containerPath, hostPath);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
filePath: resolvedPath,
|
|
99
|
+
line: source.line,
|
|
100
|
+
column: source.column,
|
|
101
|
+
componentName: source.componentName,
|
|
102
|
+
rawPath: source.rawPath,
|
|
103
|
+
domElement,
|
|
104
|
+
tagName: domElement.tagName.toLowerCase(),
|
|
105
|
+
classList: Array.from(domElement.classList),
|
|
106
|
+
id: domElement.id || null,
|
|
107
|
+
boundingRect: domElement.getBoundingClientRect(),
|
|
108
|
+
ancestors: [],
|
|
109
|
+
children: [],
|
|
110
|
+
props: null,
|
|
111
|
+
framework: detectionSource === "fiber" ? "react" : "unknown",
|
|
112
|
+
detectionSource
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/highlight/highlighter.ts
|
|
117
|
+
var HIGHLIGHT_ATTR = "data-inspekt-highlight";
|
|
118
|
+
var Highlighter = class {
|
|
119
|
+
highlights = /* @__PURE__ */ new Map();
|
|
120
|
+
config;
|
|
121
|
+
constructor(config) {
|
|
122
|
+
this.config = config;
|
|
123
|
+
}
|
|
124
|
+
highlight(element, type = "selected") {
|
|
125
|
+
if (this.highlights.has(element)) {
|
|
126
|
+
this.unhighlight(element);
|
|
127
|
+
}
|
|
128
|
+
const state = {
|
|
129
|
+
element,
|
|
130
|
+
originalOutline: element.style.outline,
|
|
131
|
+
originalOutlineOffset: element.style.outlineOffset,
|
|
132
|
+
originalBoxShadow: element.style.boxShadow,
|
|
133
|
+
type
|
|
134
|
+
};
|
|
135
|
+
this.highlights.set(element, state);
|
|
136
|
+
element.setAttribute(HIGHLIGHT_ATTR, type);
|
|
137
|
+
switch (type) {
|
|
138
|
+
case "selected":
|
|
139
|
+
element.style.outline = `2px solid ${this.config.color}`;
|
|
140
|
+
element.style.outlineOffset = "2px";
|
|
141
|
+
if (this.config.style === "glow") {
|
|
142
|
+
element.style.boxShadow = `0 0 8px 2px ${this.config.color}40`;
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
case "hovered":
|
|
146
|
+
element.style.outline = "2px dashed #a855f7";
|
|
147
|
+
element.style.outlineOffset = "2px";
|
|
148
|
+
break;
|
|
149
|
+
case "border":
|
|
150
|
+
element.style.outline = `1px solid ${this.config.color}60`;
|
|
151
|
+
element.style.outlineOffset = "0px";
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
unhighlight(element) {
|
|
156
|
+
const state = this.highlights.get(element);
|
|
157
|
+
if (!state) return;
|
|
158
|
+
element.style.outline = state.originalOutline;
|
|
159
|
+
element.style.outlineOffset = state.originalOutlineOffset;
|
|
160
|
+
element.style.boxShadow = state.originalBoxShadow;
|
|
161
|
+
element.removeAttribute(HIGHLIGHT_ATTR);
|
|
162
|
+
this.highlights.delete(element);
|
|
163
|
+
}
|
|
164
|
+
unhighlightAll() {
|
|
165
|
+
for (const [element] of this.highlights) {
|
|
166
|
+
this.unhighlight(element);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
updateConfig(config) {
|
|
170
|
+
this.config = config;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/highlight/bounding-boxes.ts
|
|
175
|
+
var BoundingBoxOverlay = class {
|
|
176
|
+
constructor(shadowRoot) {
|
|
177
|
+
this.shadowRoot = shadowRoot;
|
|
178
|
+
this.container = document.createElement("div");
|
|
179
|
+
this.container.className = "inspekt-bbox-layer";
|
|
180
|
+
this.shadowRoot.appendChild(this.container);
|
|
181
|
+
}
|
|
182
|
+
shadowRoot;
|
|
183
|
+
container;
|
|
184
|
+
boxes = [];
|
|
185
|
+
mounted = false;
|
|
186
|
+
rafHandle = null;
|
|
187
|
+
resizeObserver = null;
|
|
188
|
+
mutationObserver = null;
|
|
189
|
+
enable() {
|
|
190
|
+
if (this.mounted) return;
|
|
191
|
+
this.mounted = true;
|
|
192
|
+
this.scan();
|
|
193
|
+
window.addEventListener("scroll", this.scheduleRepaint, true);
|
|
194
|
+
window.addEventListener("resize", this.scheduleRepaint);
|
|
195
|
+
this.resizeObserver = new ResizeObserver(this.scheduleRepaint);
|
|
196
|
+
for (const { el } of this.boxes) this.resizeObserver.observe(el);
|
|
197
|
+
this.mutationObserver = new MutationObserver(this.scheduleRescan);
|
|
198
|
+
this.mutationObserver.observe(document.body, {
|
|
199
|
+
childList: true,
|
|
200
|
+
subtree: true,
|
|
201
|
+
attributes: true,
|
|
202
|
+
attributeFilter: ["data-insp-path"]
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
disable() {
|
|
206
|
+
if (!this.mounted) return;
|
|
207
|
+
this.mounted = false;
|
|
208
|
+
window.removeEventListener("scroll", this.scheduleRepaint, true);
|
|
209
|
+
window.removeEventListener("resize", this.scheduleRepaint);
|
|
210
|
+
this.resizeObserver?.disconnect();
|
|
211
|
+
this.mutationObserver?.disconnect();
|
|
212
|
+
this.resizeObserver = null;
|
|
213
|
+
this.mutationObserver = null;
|
|
214
|
+
if (this.rafHandle !== null) cancelAnimationFrame(this.rafHandle);
|
|
215
|
+
this.rafHandle = null;
|
|
216
|
+
this.clear();
|
|
217
|
+
}
|
|
218
|
+
destroy() {
|
|
219
|
+
this.disable();
|
|
220
|
+
this.container.remove();
|
|
221
|
+
}
|
|
222
|
+
clear() {
|
|
223
|
+
this.container.innerHTML = "";
|
|
224
|
+
this.boxes = [];
|
|
225
|
+
}
|
|
226
|
+
scan() {
|
|
227
|
+
this.clear();
|
|
228
|
+
const seen = /* @__PURE__ */ new Set();
|
|
229
|
+
const nodes = document.querySelectorAll("[data-insp-path]");
|
|
230
|
+
for (const node of nodes) {
|
|
231
|
+
const hit = findClosestSource(node);
|
|
232
|
+
if (!hit || seen.has(hit.element)) continue;
|
|
233
|
+
seen.add(hit.element);
|
|
234
|
+
this.boxes.push(this.makeBox(hit.element, hit.source));
|
|
235
|
+
}
|
|
236
|
+
this.repaint();
|
|
237
|
+
}
|
|
238
|
+
makeBox(el, source) {
|
|
239
|
+
const box = document.createElement("div");
|
|
240
|
+
box.className = "inspekt-bbox";
|
|
241
|
+
const label = document.createElement("span");
|
|
242
|
+
label.className = "inspekt-bbox-label";
|
|
243
|
+
label.textContent = `${source.componentName} \xB7 ${fileTail(source.filePath)}:${source.line}`;
|
|
244
|
+
box.appendChild(label);
|
|
245
|
+
this.container.appendChild(box);
|
|
246
|
+
return { el, box, label, source };
|
|
247
|
+
}
|
|
248
|
+
scheduleRepaint = () => {
|
|
249
|
+
if (this.rafHandle !== null) return;
|
|
250
|
+
this.rafHandle = requestAnimationFrame(() => {
|
|
251
|
+
this.rafHandle = null;
|
|
252
|
+
this.repaint();
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
scheduleRescan = () => {
|
|
256
|
+
if (this.rafHandle !== null) cancelAnimationFrame(this.rafHandle);
|
|
257
|
+
this.rafHandle = requestAnimationFrame(() => {
|
|
258
|
+
this.rafHandle = null;
|
|
259
|
+
this.scan();
|
|
260
|
+
if (this.resizeObserver) {
|
|
261
|
+
this.resizeObserver.disconnect();
|
|
262
|
+
for (const { el } of this.boxes) this.resizeObserver.observe(el);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
repaint() {
|
|
267
|
+
for (const binding of this.boxes) {
|
|
268
|
+
const rect = binding.el.getBoundingClientRect();
|
|
269
|
+
if (rect.width === 0 || rect.height === 0) {
|
|
270
|
+
binding.box.style.display = "none";
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
binding.box.style.display = "";
|
|
274
|
+
binding.box.style.transform = `translate(${rect.left}px, ${rect.top}px)`;
|
|
275
|
+
binding.box.style.width = `${rect.width}px`;
|
|
276
|
+
binding.box.style.height = `${rect.height}px`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
function fileTail(path) {
|
|
281
|
+
return path.split("/").pop() ?? path;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/snippet/snippet-resolver.ts
|
|
285
|
+
var CACHE_LIMIT = 100;
|
|
286
|
+
var cache = /* @__PURE__ */ new Map();
|
|
287
|
+
function cacheKey(opts) {
|
|
288
|
+
return `${opts.filePath}:${opts.line}:${opts.context ?? 5}`;
|
|
289
|
+
}
|
|
290
|
+
function lruTouch(key, value) {
|
|
291
|
+
cache.delete(key);
|
|
292
|
+
cache.set(key, value);
|
|
293
|
+
if (cache.size > CACHE_LIMIT) {
|
|
294
|
+
const oldest = cache.keys().next().value;
|
|
295
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function fetchFromDevServer(opts) {
|
|
299
|
+
if (!opts.serverUrl) return null;
|
|
300
|
+
const fetcher = opts.fetcher ?? fetch;
|
|
301
|
+
const url = new URL("/__inspekt/snippet", opts.serverUrl);
|
|
302
|
+
url.searchParams.set("file", opts.filePath);
|
|
303
|
+
url.searchParams.set("line", String(opts.line));
|
|
304
|
+
url.searchParams.set("context", String(opts.context ?? 5));
|
|
305
|
+
try {
|
|
306
|
+
const res = await fetcher(url.toString(), { method: "GET" });
|
|
307
|
+
if (!res.ok) return null;
|
|
308
|
+
const data = await res.json();
|
|
309
|
+
return { ...data, source: "devserver" };
|
|
310
|
+
} catch {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async function resolveSnippet(opts) {
|
|
315
|
+
const key = cacheKey(opts);
|
|
316
|
+
if (cache.has(key)) {
|
|
317
|
+
return cache.get(key) ?? null;
|
|
318
|
+
}
|
|
319
|
+
const stat = opts.staticSnippets?.[opts.filePath];
|
|
320
|
+
if (stat) {
|
|
321
|
+
const startLine = stat.startLine ?? 1;
|
|
322
|
+
const snippet = {
|
|
323
|
+
startLine,
|
|
324
|
+
endLine: startLine + stat.lines.length - 1,
|
|
325
|
+
targetLine: opts.line,
|
|
326
|
+
lines: stat.lines,
|
|
327
|
+
language: stat.language,
|
|
328
|
+
source: "devserver"
|
|
329
|
+
};
|
|
330
|
+
lruTouch(key, snippet);
|
|
331
|
+
return snippet;
|
|
332
|
+
}
|
|
333
|
+
const fromServer = await fetchFromDevServer(opts);
|
|
334
|
+
if (fromServer) {
|
|
335
|
+
lruTouch(key, fromServer);
|
|
336
|
+
return fromServer;
|
|
337
|
+
}
|
|
338
|
+
if (opts.sourceMapEnabled) {
|
|
339
|
+
try {
|
|
340
|
+
const mod = await import("./sourcemap-resolver-3PQ6R6PU.js");
|
|
341
|
+
const fromMap = await mod.resolveFromSourceMap({
|
|
342
|
+
filePath: opts.filePath,
|
|
343
|
+
line: opts.line,
|
|
344
|
+
context: opts.context,
|
|
345
|
+
fetcher: opts.fetcher
|
|
346
|
+
});
|
|
347
|
+
if (fromMap) {
|
|
348
|
+
lruTouch(key, fromMap);
|
|
349
|
+
return fromMap;
|
|
350
|
+
}
|
|
351
|
+
} catch {
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
lruTouch(key, null);
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/highlight/prism.ts
|
|
359
|
+
import Prism from "prismjs";
|
|
360
|
+
import "prismjs/components/prism-markup.js";
|
|
361
|
+
import "prismjs/components/prism-clike.js";
|
|
362
|
+
import "prismjs/components/prism-javascript.js";
|
|
363
|
+
import "prismjs/components/prism-jsx.js";
|
|
364
|
+
import "prismjs/components/prism-typescript.js";
|
|
365
|
+
import "prismjs/components/prism-tsx.js";
|
|
366
|
+
import "prismjs/components/prism-css.js";
|
|
367
|
+
import "prismjs/components/prism-json.js";
|
|
368
|
+
function resolveGrammarKey(lang) {
|
|
369
|
+
switch ((lang || "").toLowerCase()) {
|
|
370
|
+
case "js":
|
|
371
|
+
case "jsx":
|
|
372
|
+
case "mjs":
|
|
373
|
+
case "cjs":
|
|
374
|
+
return "jsx";
|
|
375
|
+
case "ts":
|
|
376
|
+
case "tsx":
|
|
377
|
+
return "tsx";
|
|
378
|
+
case "javascript":
|
|
379
|
+
return "javascript";
|
|
380
|
+
case "typescript":
|
|
381
|
+
return "typescript";
|
|
382
|
+
case "json":
|
|
383
|
+
return "json";
|
|
384
|
+
case "css":
|
|
385
|
+
case "scss":
|
|
386
|
+
case "less":
|
|
387
|
+
return "css";
|
|
388
|
+
case "html":
|
|
389
|
+
case "htm":
|
|
390
|
+
case "xml":
|
|
391
|
+
case "svg":
|
|
392
|
+
case "markup":
|
|
393
|
+
return "markup";
|
|
394
|
+
default:
|
|
395
|
+
return "plain";
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
function tokenizeToLines(code, lang) {
|
|
399
|
+
const key = resolveGrammarKey(lang);
|
|
400
|
+
const grammar = key === "plain" ? void 0 : Prism.languages[key];
|
|
401
|
+
if (!grammar) {
|
|
402
|
+
return code.split("\n").map((text) => ({ tokens: [{ text, type: "" }] }));
|
|
403
|
+
}
|
|
404
|
+
const tokens = Prism.tokenize(code, grammar);
|
|
405
|
+
return splitTokensIntoLines(tokens);
|
|
406
|
+
}
|
|
407
|
+
function splitTokensIntoLines(nodes) {
|
|
408
|
+
const lines = [{ tokens: [] }];
|
|
409
|
+
const current = () => lines[lines.length - 1].tokens;
|
|
410
|
+
function visit(node, parentType) {
|
|
411
|
+
if (typeof node === "string") {
|
|
412
|
+
pushText(node, parentType);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (Array.isArray(node)) {
|
|
416
|
+
for (const n of node) visit(n, parentType);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const type = parentType ? `${parentType} ${node.type}` : node.type;
|
|
420
|
+
visit(node.content, type);
|
|
421
|
+
}
|
|
422
|
+
function pushText(text, type) {
|
|
423
|
+
let buf = text;
|
|
424
|
+
while (buf.length > 0) {
|
|
425
|
+
const nl = buf.indexOf("\n");
|
|
426
|
+
if (nl === -1) {
|
|
427
|
+
if (buf.length > 0) current().push({ text: buf, type });
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const before = buf.slice(0, nl);
|
|
431
|
+
if (before.length > 0) current().push({ text: before, type });
|
|
432
|
+
lines.push({ tokens: [] });
|
|
433
|
+
buf = buf.slice(nl + 1);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
for (const n of nodes) visit(n, "");
|
|
437
|
+
return lines;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// src/components/tooltip.ts
|
|
441
|
+
import {
|
|
442
|
+
autoUpdate,
|
|
443
|
+
computePosition,
|
|
444
|
+
flip,
|
|
445
|
+
offset,
|
|
446
|
+
shift
|
|
447
|
+
} from "@floating-ui/dom";
|
|
448
|
+
var counter = 0;
|
|
449
|
+
function attachTooltip(trigger, content, opts = {}) {
|
|
450
|
+
const enterDelay = opts.enterDelay ?? 200;
|
|
451
|
+
const leaveDelay = opts.leaveDelay ?? 80;
|
|
452
|
+
const placement = opts.placement ?? "top";
|
|
453
|
+
const offsetPx = opts.offsetPx ?? 8;
|
|
454
|
+
const root = opts.root ?? document.body;
|
|
455
|
+
const isRich = typeof content !== "string";
|
|
456
|
+
let bubble = null;
|
|
457
|
+
let enterTimer = null;
|
|
458
|
+
let leaveTimer = null;
|
|
459
|
+
let cleanupAutoUpdate = null;
|
|
460
|
+
const id = `inspekt-tooltip-${++counter}`;
|
|
461
|
+
function show() {
|
|
462
|
+
if (bubble) return;
|
|
463
|
+
bubble = document.createElement("div");
|
|
464
|
+
bubble.className = "inspekt-tooltip";
|
|
465
|
+
bubble.id = id;
|
|
466
|
+
bubble.setAttribute("role", "tooltip");
|
|
467
|
+
bubble.style.position = "fixed";
|
|
468
|
+
bubble.style.top = "0";
|
|
469
|
+
bubble.style.left = "0";
|
|
470
|
+
bubble.style.zIndex = "2147483647";
|
|
471
|
+
if (typeof content === "string") {
|
|
472
|
+
bubble.textContent = content;
|
|
473
|
+
} else {
|
|
474
|
+
bubble.classList.add("inspekt-tooltip--rich");
|
|
475
|
+
bubble.appendChild(content);
|
|
476
|
+
}
|
|
477
|
+
root.appendChild(bubble);
|
|
478
|
+
cleanupAutoUpdate = autoUpdate(trigger, bubble, update);
|
|
479
|
+
if (isRich) {
|
|
480
|
+
bubble.addEventListener("mouseenter", cancelLeave);
|
|
481
|
+
bubble.addEventListener("mouseleave", scheduleHide);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function hide() {
|
|
485
|
+
if (!bubble) return;
|
|
486
|
+
cleanupAutoUpdate?.();
|
|
487
|
+
cleanupAutoUpdate = null;
|
|
488
|
+
bubble.remove();
|
|
489
|
+
bubble = null;
|
|
490
|
+
}
|
|
491
|
+
function update() {
|
|
492
|
+
if (!bubble) return;
|
|
493
|
+
void computePosition(trigger, bubble, {
|
|
494
|
+
placement,
|
|
495
|
+
strategy: "fixed",
|
|
496
|
+
middleware: [offset(offsetPx), flip(), shift({ padding: 6 })]
|
|
497
|
+
}).then(({ x, y }) => {
|
|
498
|
+
if (!bubble || !bubble.isConnected) return;
|
|
499
|
+
bubble.style.left = `${Math.round(x)}px`;
|
|
500
|
+
bubble.style.top = `${Math.round(y)}px`;
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
function scheduleShow() {
|
|
504
|
+
cancelLeave();
|
|
505
|
+
if (enterTimer) clearTimeout(enterTimer);
|
|
506
|
+
enterTimer = setTimeout(() => {
|
|
507
|
+
enterTimer = null;
|
|
508
|
+
show();
|
|
509
|
+
}, enterDelay);
|
|
510
|
+
}
|
|
511
|
+
function scheduleHide() {
|
|
512
|
+
if (enterTimer) {
|
|
513
|
+
clearTimeout(enterTimer);
|
|
514
|
+
enterTimer = null;
|
|
515
|
+
}
|
|
516
|
+
if (leaveTimer) clearTimeout(leaveTimer);
|
|
517
|
+
leaveTimer = setTimeout(() => {
|
|
518
|
+
leaveTimer = null;
|
|
519
|
+
hide();
|
|
520
|
+
}, leaveDelay);
|
|
521
|
+
}
|
|
522
|
+
function cancelLeave() {
|
|
523
|
+
if (leaveTimer) {
|
|
524
|
+
clearTimeout(leaveTimer);
|
|
525
|
+
leaveTimer = null;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function onKey(e) {
|
|
529
|
+
if (e.key === "Escape") hide();
|
|
530
|
+
}
|
|
531
|
+
trigger.setAttribute("aria-describedby", id);
|
|
532
|
+
trigger.addEventListener("mouseenter", scheduleShow);
|
|
533
|
+
trigger.addEventListener("mouseleave", scheduleHide);
|
|
534
|
+
trigger.addEventListener("focus", scheduleShow);
|
|
535
|
+
trigger.addEventListener("blur", scheduleHide);
|
|
536
|
+
trigger.addEventListener("keydown", onKey);
|
|
537
|
+
return function detach() {
|
|
538
|
+
if (enterTimer) clearTimeout(enterTimer);
|
|
539
|
+
if (leaveTimer) clearTimeout(leaveTimer);
|
|
540
|
+
trigger.removeEventListener("mouseenter", scheduleShow);
|
|
541
|
+
trigger.removeEventListener("mouseleave", scheduleHide);
|
|
542
|
+
trigger.removeEventListener("focus", scheduleShow);
|
|
543
|
+
trigger.removeEventListener("blur", scheduleHide);
|
|
544
|
+
trigger.removeEventListener("keydown", onKey);
|
|
545
|
+
trigger.removeAttribute("aria-describedby");
|
|
546
|
+
hide();
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// src/popover/popover.ts
|
|
551
|
+
var ICON_COPY = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V5a2 2 0 0 1 2-2h10"/></svg>`;
|
|
552
|
+
var ICON_HTML = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>`;
|
|
553
|
+
var ICON_CONSOLE = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>`;
|
|
554
|
+
var ICON_INFO = `<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9.5"/><line x1="12" y1="11" x2="12" y2="16.5"/><circle cx="12" cy="7.8" r="0.6" fill="currentColor" stroke="none"/></svg>`;
|
|
555
|
+
var DEFAULT_SNIPPET_CONFIG = {
|
|
556
|
+
context: 5,
|
|
557
|
+
defaultExpanded: false,
|
|
558
|
+
sourceMapEnabled: false
|
|
559
|
+
};
|
|
560
|
+
var Popover = class {
|
|
561
|
+
constructor(shadowRoot) {
|
|
562
|
+
this.shadowRoot = shadowRoot;
|
|
563
|
+
this.container = document.createElement("div");
|
|
564
|
+
this.container.className = "inspekt-popover";
|
|
565
|
+
this.container.style.display = "none";
|
|
566
|
+
this.shadowRoot.appendChild(this.container);
|
|
567
|
+
}
|
|
568
|
+
shadowRoot;
|
|
569
|
+
container;
|
|
570
|
+
visible = false;
|
|
571
|
+
pinned = false;
|
|
572
|
+
snippetConfig = { ...DEFAULT_SNIPPET_CONFIG };
|
|
573
|
+
/** Lock the popover in place — hover/move handlers will not reposition or
|
|
574
|
+
* hide it until {@link unpin} is called. Clicks set this; Escape clears it. */
|
|
575
|
+
pin() {
|
|
576
|
+
this.pinned = true;
|
|
577
|
+
}
|
|
578
|
+
unpin() {
|
|
579
|
+
this.pinned = false;
|
|
580
|
+
}
|
|
581
|
+
isPinned() {
|
|
582
|
+
return this.pinned;
|
|
583
|
+
}
|
|
584
|
+
configureSnippet(config) {
|
|
585
|
+
this.snippetConfig = { ...this.snippetConfig, ...config };
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Fallback popover for Standalone-on-an-unbuilt-page: no source attrs,
|
|
589
|
+
* no React fibers — so we show DOM info (selector, classes, id) plus a
|
|
590
|
+
* minimal action set. Keeps Inspekt useful as a pure inspection tool.
|
|
591
|
+
*/
|
|
592
|
+
showDom(domElement, position, onCopySelector, onCopyHtml, onConsoleLog) {
|
|
593
|
+
this.container.innerHTML = "";
|
|
594
|
+
const selector = computeSelector(domElement);
|
|
595
|
+
const header = document.createElement("div");
|
|
596
|
+
header.className = "inspekt-popover-header";
|
|
597
|
+
const eyebrow = document.createElement("div");
|
|
598
|
+
eyebrow.className = "inspekt-popover-path-dir inspekt-popover-path-dir-row";
|
|
599
|
+
const eyebrowText = document.createElement("span");
|
|
600
|
+
eyebrowText.textContent = "DOM element";
|
|
601
|
+
eyebrow.appendChild(eyebrowText);
|
|
602
|
+
const infoBadge = document.createElement("span");
|
|
603
|
+
infoBadge.className = "inspekt-info-badge";
|
|
604
|
+
infoBadge.setAttribute("tabindex", "0");
|
|
605
|
+
infoBadge.setAttribute("aria-label", "Why no source data?");
|
|
606
|
+
infoBadge.innerHTML = `${ICON_INFO}<span class="inspekt-info-badge-label">No source</span>`;
|
|
607
|
+
attachTooltip(
|
|
608
|
+
infoBadge,
|
|
609
|
+
"No Inspekt source data on this page. Build with the Inspekt plugin (Vite, Webpack, Rspack, esbuild) to get editor-jump and file paths.",
|
|
610
|
+
{ root: this.shadowRoot, enterDelay: 100 }
|
|
611
|
+
);
|
|
612
|
+
eyebrow.appendChild(infoBadge);
|
|
613
|
+
const sel = document.createElement("div");
|
|
614
|
+
sel.className = "inspekt-popover-path-file";
|
|
615
|
+
sel.textContent = selector;
|
|
616
|
+
header.appendChild(eyebrow);
|
|
617
|
+
header.appendChild(sel);
|
|
618
|
+
this.container.appendChild(header);
|
|
619
|
+
const actionsBar = document.createElement("div");
|
|
620
|
+
actionsBar.className = "inspekt-popover-actions";
|
|
621
|
+
const copyBtn = document.createElement("button");
|
|
622
|
+
copyBtn.className = "inspekt-popover-action";
|
|
623
|
+
copyBtn.setAttribute("aria-label", "Copy CSS selector");
|
|
624
|
+
copyBtn.innerHTML = ICON_COPY;
|
|
625
|
+
attachTooltip(copyBtn, "Copy CSS selector", {
|
|
626
|
+
root: this.shadowRoot
|
|
627
|
+
});
|
|
628
|
+
copyBtn.addEventListener("click", async (e) => {
|
|
629
|
+
e.preventDefault();
|
|
630
|
+
e.stopPropagation();
|
|
631
|
+
const ok = await onCopySelector(selector);
|
|
632
|
+
this.showToast(ok ? "Copied" : "Copy failed");
|
|
633
|
+
setTimeout(() => this.hide(), 700);
|
|
634
|
+
});
|
|
635
|
+
actionsBar.appendChild(copyBtn);
|
|
636
|
+
const htmlBtn = document.createElement("button");
|
|
637
|
+
htmlBtn.className = "inspekt-popover-action";
|
|
638
|
+
htmlBtn.setAttribute("aria-label", "Copy HTML");
|
|
639
|
+
htmlBtn.innerHTML = ICON_HTML;
|
|
640
|
+
attachTooltip(htmlBtn, "Copy HTML (outerHTML)", {
|
|
641
|
+
root: this.shadowRoot
|
|
642
|
+
});
|
|
643
|
+
htmlBtn.addEventListener("click", async (e) => {
|
|
644
|
+
e.preventDefault();
|
|
645
|
+
e.stopPropagation();
|
|
646
|
+
const ok = await onCopyHtml(domElement.outerHTML);
|
|
647
|
+
this.showToast(ok ? "HTML copied" : "Copy failed");
|
|
648
|
+
setTimeout(() => this.hide(), 700);
|
|
649
|
+
});
|
|
650
|
+
actionsBar.appendChild(htmlBtn);
|
|
651
|
+
const logBtn = document.createElement("button");
|
|
652
|
+
logBtn.className = "inspekt-popover-action";
|
|
653
|
+
logBtn.setAttribute("aria-label", "console.log this element");
|
|
654
|
+
logBtn.innerHTML = ICON_CONSOLE;
|
|
655
|
+
attachTooltip(logBtn, "console.log this element", {
|
|
656
|
+
root: this.shadowRoot
|
|
657
|
+
});
|
|
658
|
+
logBtn.addEventListener("click", (e) => {
|
|
659
|
+
e.preventDefault();
|
|
660
|
+
e.stopPropagation();
|
|
661
|
+
onConsoleLog();
|
|
662
|
+
this.showToast("Logged to console");
|
|
663
|
+
setTimeout(() => this.hide(), 700);
|
|
664
|
+
});
|
|
665
|
+
actionsBar.appendChild(logBtn);
|
|
666
|
+
this.container.appendChild(actionsBar);
|
|
667
|
+
this.positionAt(position.x, position.y);
|
|
668
|
+
this.container.style.display = "block";
|
|
669
|
+
this.visible = true;
|
|
670
|
+
}
|
|
671
|
+
/** Brief feedback toast attached to the shadow root. */
|
|
672
|
+
showToast(message) {
|
|
673
|
+
const existing = this.shadowRoot.querySelector(".inspekt-popover-toast");
|
|
674
|
+
if (existing) existing.remove();
|
|
675
|
+
const toast = document.createElement("div");
|
|
676
|
+
toast.className = "inspekt-popover-toast";
|
|
677
|
+
toast.textContent = message;
|
|
678
|
+
this.shadowRoot.appendChild(toast);
|
|
679
|
+
setTimeout(() => toast.remove(), 1200);
|
|
680
|
+
}
|
|
681
|
+
show(element, actions, position) {
|
|
682
|
+
this.container.innerHTML = "";
|
|
683
|
+
const header = document.createElement("div");
|
|
684
|
+
header.className = "inspekt-popover-header";
|
|
685
|
+
const pathDir = document.createElement("div");
|
|
686
|
+
pathDir.className = "inspekt-popover-path-dir";
|
|
687
|
+
const parts = element.filePath.split("/");
|
|
688
|
+
pathDir.textContent = parts.slice(0, -1).join("/") + "/";
|
|
689
|
+
const pathFile = document.createElement("div");
|
|
690
|
+
pathFile.className = "inspekt-popover-path-file";
|
|
691
|
+
pathFile.textContent = `${parts[parts.length - 1]}:${element.line}`;
|
|
692
|
+
header.appendChild(pathDir);
|
|
693
|
+
header.appendChild(pathFile);
|
|
694
|
+
this.container.appendChild(header);
|
|
695
|
+
const snippetSection = this.buildSnippetSection(element);
|
|
696
|
+
this.container.appendChild(snippetSection);
|
|
697
|
+
const actionsBar = document.createElement("div");
|
|
698
|
+
actionsBar.className = "inspekt-popover-actions";
|
|
699
|
+
for (const action of actions) {
|
|
700
|
+
const btn = document.createElement("button");
|
|
701
|
+
btn.className = "inspekt-popover-action";
|
|
702
|
+
btn.setAttribute("aria-label", action.label);
|
|
703
|
+
btn.innerHTML = action.icon;
|
|
704
|
+
attachTooltip(btn, action.label, {
|
|
705
|
+
root: this.shadowRoot
|
|
706
|
+
});
|
|
707
|
+
btn.addEventListener("click", (e) => {
|
|
708
|
+
e.stopPropagation();
|
|
709
|
+
action.handler(element);
|
|
710
|
+
this.hide();
|
|
711
|
+
});
|
|
712
|
+
actionsBar.appendChild(btn);
|
|
713
|
+
}
|
|
714
|
+
this.container.appendChild(actionsBar);
|
|
715
|
+
this.positionAt(position.x, position.y);
|
|
716
|
+
this.container.style.display = "block";
|
|
717
|
+
this.visible = true;
|
|
718
|
+
}
|
|
719
|
+
buildSnippetSection(element) {
|
|
720
|
+
const section = document.createElement("div");
|
|
721
|
+
section.className = "inspekt-snippet";
|
|
722
|
+
section.hidden = true;
|
|
723
|
+
const initialState = this.snippetConfig.defaultExpanded ? "expanded" : "collapsed";
|
|
724
|
+
section.dataset["state"] = initialState;
|
|
725
|
+
const toggle = document.createElement("button");
|
|
726
|
+
toggle.type = "button";
|
|
727
|
+
toggle.className = "inspekt-snippet-toggle";
|
|
728
|
+
toggle.textContent = initialState === "collapsed" ? "Show source \u25BE" : "Hide source \u25B4";
|
|
729
|
+
const body = document.createElement("div");
|
|
730
|
+
body.className = "inspekt-snippet-body";
|
|
731
|
+
if (initialState === "collapsed") body.hidden = true;
|
|
732
|
+
section.appendChild(toggle);
|
|
733
|
+
section.appendChild(body);
|
|
734
|
+
void this.resolveAndMountSnippet(section, toggle, body, element, initialState);
|
|
735
|
+
return section;
|
|
736
|
+
}
|
|
737
|
+
async resolveAndMountSnippet(section, toggle, body, element, initialState) {
|
|
738
|
+
const snippet = await resolveSnippet({
|
|
739
|
+
filePath: element.filePath,
|
|
740
|
+
line: element.line,
|
|
741
|
+
serverUrl: this.snippetConfig.serverUrl,
|
|
742
|
+
context: this.snippetConfig.context,
|
|
743
|
+
sourceMapEnabled: this.snippetConfig.sourceMapEnabled,
|
|
744
|
+
staticSnippets: this.snippetConfig.staticSnippets
|
|
745
|
+
});
|
|
746
|
+
if (!snippet) {
|
|
747
|
+
section.remove();
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
element.snippet = snippet;
|
|
751
|
+
section.hidden = false;
|
|
752
|
+
let rendered = false;
|
|
753
|
+
const expand = () => {
|
|
754
|
+
section.dataset["state"] = "expanded";
|
|
755
|
+
body.dataset["state"] = "expanded";
|
|
756
|
+
body.hidden = false;
|
|
757
|
+
toggle.textContent = "Hide source \u25B4";
|
|
758
|
+
if (!rendered) {
|
|
759
|
+
rendered = true;
|
|
760
|
+
body.innerHTML = "";
|
|
761
|
+
body.appendChild(this.renderSnippet(snippet));
|
|
762
|
+
}
|
|
763
|
+
requestAnimationFrame(() => {
|
|
764
|
+
const target = body.querySelector(".inspekt-line-target");
|
|
765
|
+
target?.scrollIntoView({ block: "center", inline: "nearest" });
|
|
766
|
+
});
|
|
767
|
+
};
|
|
768
|
+
const collapse = () => {
|
|
769
|
+
section.dataset["state"] = "collapsed";
|
|
770
|
+
body.dataset["state"] = "collapsed";
|
|
771
|
+
body.hidden = true;
|
|
772
|
+
toggle.textContent = "Show source \u25BE";
|
|
773
|
+
};
|
|
774
|
+
toggle.addEventListener("click", (e) => {
|
|
775
|
+
e.stopPropagation();
|
|
776
|
+
if (section.dataset["state"] === "collapsed") expand();
|
|
777
|
+
else collapse();
|
|
778
|
+
});
|
|
779
|
+
if (initialState === "expanded") expand();
|
|
780
|
+
}
|
|
781
|
+
renderSnippet(snippet) {
|
|
782
|
+
const pre = document.createElement("pre");
|
|
783
|
+
pre.className = "inspekt-snippet-pre";
|
|
784
|
+
pre.dataset["language"] = snippet.language;
|
|
785
|
+
const highlighted = tokenizeToLines(snippet.lines.join("\n"), snippet.language);
|
|
786
|
+
snippet.lines.forEach((rawText, index) => {
|
|
787
|
+
const lineNumber = snippet.startLine + index;
|
|
788
|
+
const isTarget = lineNumber === snippet.targetLine;
|
|
789
|
+
const lineEl = document.createElement("span");
|
|
790
|
+
lineEl.className = isTarget ? "inspekt-line inspekt-line-target" : "inspekt-line";
|
|
791
|
+
const num = document.createElement("span");
|
|
792
|
+
num.className = "inspekt-line-no";
|
|
793
|
+
num.textContent = String(lineNumber);
|
|
794
|
+
lineEl.appendChild(num);
|
|
795
|
+
const code = document.createElement("span");
|
|
796
|
+
code.className = "inspekt-line-code";
|
|
797
|
+
const tokens = highlighted[index]?.tokens;
|
|
798
|
+
if (!tokens || tokens.length === 0) {
|
|
799
|
+
code.textContent = rawText;
|
|
800
|
+
} else {
|
|
801
|
+
for (const tok of tokens) {
|
|
802
|
+
if (!tok.type) {
|
|
803
|
+
code.appendChild(document.createTextNode(tok.text));
|
|
804
|
+
} else {
|
|
805
|
+
const span = document.createElement("span");
|
|
806
|
+
span.className = `token ${tok.type}`;
|
|
807
|
+
span.textContent = tok.text;
|
|
808
|
+
code.appendChild(span);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
lineEl.appendChild(code);
|
|
813
|
+
pre.appendChild(lineEl);
|
|
814
|
+
pre.appendChild(document.createTextNode("\n"));
|
|
815
|
+
});
|
|
816
|
+
return pre;
|
|
817
|
+
}
|
|
818
|
+
hide() {
|
|
819
|
+
this.container.style.display = "none";
|
|
820
|
+
this.visible = false;
|
|
821
|
+
this.pinned = false;
|
|
822
|
+
}
|
|
823
|
+
isVisible() {
|
|
824
|
+
return this.visible;
|
|
825
|
+
}
|
|
826
|
+
positionAt(x, y) {
|
|
827
|
+
const padding = 8;
|
|
828
|
+
const vpWidth = window.innerWidth;
|
|
829
|
+
const vpHeight = window.innerHeight;
|
|
830
|
+
this.container.style.display = "block";
|
|
831
|
+
this.container.style.left = "0px";
|
|
832
|
+
this.container.style.top = "0px";
|
|
833
|
+
const rect = this.container.getBoundingClientRect();
|
|
834
|
+
let left = x;
|
|
835
|
+
let top = y + 10;
|
|
836
|
+
if (left + rect.width + padding > vpWidth) {
|
|
837
|
+
left = vpWidth - rect.width - padding;
|
|
838
|
+
}
|
|
839
|
+
if (left < padding) left = padding;
|
|
840
|
+
if (top + rect.height + padding > vpHeight) {
|
|
841
|
+
top = y - rect.height - 10;
|
|
842
|
+
}
|
|
843
|
+
if (top < padding) top = padding;
|
|
844
|
+
this.container.style.left = `${left}px`;
|
|
845
|
+
this.container.style.top = `${top}px`;
|
|
846
|
+
}
|
|
847
|
+
destroy() {
|
|
848
|
+
this.container.remove();
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
function computeSelector(el) {
|
|
852
|
+
const tag = el.tagName.toLowerCase();
|
|
853
|
+
if (el.id) return `${tag}#${el.id}`;
|
|
854
|
+
const classes = Array.from(el.classList).slice(0, 2);
|
|
855
|
+
if (classes.length) return `${tag}.${classes.join(".")}`;
|
|
856
|
+
return tag;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// src/overlay/overlay.ts
|
|
860
|
+
var MAX_VISIBLE_BADGES = 200;
|
|
861
|
+
var Overlay = class {
|
|
862
|
+
constructor(shadowRoot) {
|
|
863
|
+
this.shadowRoot = shadowRoot;
|
|
864
|
+
this.container = document.createElement("div");
|
|
865
|
+
this.container.className = "inspekt-overlay";
|
|
866
|
+
this.container.style.display = "none";
|
|
867
|
+
this.shadowRoot.appendChild(this.container);
|
|
868
|
+
}
|
|
869
|
+
shadowRoot;
|
|
870
|
+
badges = [];
|
|
871
|
+
mutationObserver = null;
|
|
872
|
+
intersectionObserver = null;
|
|
873
|
+
debounceTimer = null;
|
|
874
|
+
container;
|
|
875
|
+
visible = false;
|
|
876
|
+
show() {
|
|
877
|
+
this.visible = true;
|
|
878
|
+
this.container.style.display = "block";
|
|
879
|
+
this.scan();
|
|
880
|
+
this.startObserving();
|
|
881
|
+
}
|
|
882
|
+
hide() {
|
|
883
|
+
this.visible = false;
|
|
884
|
+
this.container.style.display = "none";
|
|
885
|
+
this.clear();
|
|
886
|
+
this.stopObserving();
|
|
887
|
+
}
|
|
888
|
+
toggle() {
|
|
889
|
+
if (this.visible) this.hide();
|
|
890
|
+
else this.show();
|
|
891
|
+
}
|
|
892
|
+
isVisible() {
|
|
893
|
+
return this.visible;
|
|
894
|
+
}
|
|
895
|
+
scan() {
|
|
896
|
+
this.clear();
|
|
897
|
+
const elements = document.querySelectorAll(
|
|
898
|
+
"[data-insp-path], [data-insp-path]"
|
|
899
|
+
);
|
|
900
|
+
const detected = new Set(elements);
|
|
901
|
+
const outermost = [];
|
|
902
|
+
for (const el of elements) {
|
|
903
|
+
let parent = el.parentElement;
|
|
904
|
+
let isNested = false;
|
|
905
|
+
while (parent) {
|
|
906
|
+
if (detected.has(parent)) {
|
|
907
|
+
isNested = true;
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
parent = parent.parentElement;
|
|
911
|
+
}
|
|
912
|
+
if (!isNested) outermost.push(el);
|
|
913
|
+
}
|
|
914
|
+
const toRender = outermost.slice(0, MAX_VISIBLE_BADGES);
|
|
915
|
+
this.intersectionObserver = new IntersectionObserver(
|
|
916
|
+
(entries) => {
|
|
917
|
+
for (const entry of entries) {
|
|
918
|
+
const badge = this.badges.find((b) => b.element === entry.target);
|
|
919
|
+
if (!badge) continue;
|
|
920
|
+
if (entry.isIntersecting) {
|
|
921
|
+
badge.visible = true;
|
|
922
|
+
badge.badgeElement.style.display = "block";
|
|
923
|
+
this.positionBadge(badge.badgeElement, badge.element);
|
|
924
|
+
} else {
|
|
925
|
+
badge.visible = false;
|
|
926
|
+
badge.badgeElement.style.display = "none";
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
{ rootMargin: "50px" }
|
|
931
|
+
);
|
|
932
|
+
for (const el of toRender) {
|
|
933
|
+
const attrValue = findSourceAttribute(el);
|
|
934
|
+
if (!attrValue) continue;
|
|
935
|
+
const source = parseSourceAttribute(attrValue);
|
|
936
|
+
if (!source) continue;
|
|
937
|
+
this.createBadge(el, source.componentName);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
createBadge(element, componentName) {
|
|
941
|
+
const badge = document.createElement("div");
|
|
942
|
+
badge.className = "inspekt-badge";
|
|
943
|
+
badge.textContent = componentName;
|
|
944
|
+
badge.addEventListener("click", (e) => {
|
|
945
|
+
e.stopPropagation();
|
|
946
|
+
element.dispatchEvent(
|
|
947
|
+
new CustomEvent("inspekt:badge-click", {
|
|
948
|
+
bubbles: true,
|
|
949
|
+
detail: { element }
|
|
950
|
+
})
|
|
951
|
+
);
|
|
952
|
+
});
|
|
953
|
+
badge.addEventListener("mouseenter", () => {
|
|
954
|
+
element.dispatchEvent(
|
|
955
|
+
new CustomEvent("inspekt:badge-hover", {
|
|
956
|
+
bubbles: true,
|
|
957
|
+
detail: { element }
|
|
958
|
+
})
|
|
959
|
+
);
|
|
960
|
+
});
|
|
961
|
+
badge.addEventListener("mouseleave", () => {
|
|
962
|
+
element.dispatchEvent(
|
|
963
|
+
new CustomEvent("inspekt:badge-leave", {
|
|
964
|
+
bubbles: true,
|
|
965
|
+
detail: { element }
|
|
966
|
+
})
|
|
967
|
+
);
|
|
968
|
+
});
|
|
969
|
+
this.container.appendChild(badge);
|
|
970
|
+
this.positionBadge(badge, element);
|
|
971
|
+
const badgeEntry = { element, componentName, badgeElement: badge, visible: true };
|
|
972
|
+
this.badges.push(badgeEntry);
|
|
973
|
+
this.intersectionObserver?.observe(element);
|
|
974
|
+
}
|
|
975
|
+
positionBadge(badge, target) {
|
|
976
|
+
const rect = target.getBoundingClientRect();
|
|
977
|
+
const badgeHeight = 18;
|
|
978
|
+
const badgeWidth = badge.offsetWidth || 60;
|
|
979
|
+
const scrollX = window.scrollX;
|
|
980
|
+
const scrollY = window.scrollY;
|
|
981
|
+
let left = rect.left + scrollX;
|
|
982
|
+
let top = rect.top + scrollY - badgeHeight - 2;
|
|
983
|
+
const vpWidth = window.innerWidth;
|
|
984
|
+
if (left + badgeWidth > vpWidth + scrollX) {
|
|
985
|
+
left = vpWidth + scrollX - badgeWidth - 4;
|
|
986
|
+
}
|
|
987
|
+
if (left < scrollX + 4) {
|
|
988
|
+
left = scrollX + 4;
|
|
989
|
+
}
|
|
990
|
+
if (top < scrollY) {
|
|
991
|
+
top = rect.bottom + scrollY + 2;
|
|
992
|
+
}
|
|
993
|
+
badge.style.left = `${left}px`;
|
|
994
|
+
badge.style.top = `${top}px`;
|
|
995
|
+
}
|
|
996
|
+
updatePositions() {
|
|
997
|
+
for (const { badgeElement, element, visible } of this.badges) {
|
|
998
|
+
if (visible) {
|
|
999
|
+
this.positionBadge(badgeElement, element);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
startObserving() {
|
|
1004
|
+
this.mutationObserver = new MutationObserver(() => {
|
|
1005
|
+
if (this.debounceTimer) clearTimeout(this.debounceTimer);
|
|
1006
|
+
this.debounceTimer = setTimeout(() => this.scan(), 100);
|
|
1007
|
+
});
|
|
1008
|
+
this.mutationObserver.observe(document.body, {
|
|
1009
|
+
childList: true,
|
|
1010
|
+
subtree: true
|
|
1011
|
+
});
|
|
1012
|
+
window.addEventListener("scroll", this.handleScrollResize, true);
|
|
1013
|
+
window.addEventListener("resize", this.handleScrollResize);
|
|
1014
|
+
}
|
|
1015
|
+
stopObserving() {
|
|
1016
|
+
this.mutationObserver?.disconnect();
|
|
1017
|
+
this.mutationObserver = null;
|
|
1018
|
+
this.intersectionObserver?.disconnect();
|
|
1019
|
+
this.intersectionObserver = null;
|
|
1020
|
+
if (this.debounceTimer) {
|
|
1021
|
+
clearTimeout(this.debounceTimer);
|
|
1022
|
+
this.debounceTimer = null;
|
|
1023
|
+
}
|
|
1024
|
+
window.removeEventListener("scroll", this.handleScrollResize, true);
|
|
1025
|
+
window.removeEventListener("resize", this.handleScrollResize);
|
|
1026
|
+
}
|
|
1027
|
+
handleScrollResize = () => {
|
|
1028
|
+
if (this.debounceTimer) clearTimeout(this.debounceTimer);
|
|
1029
|
+
this.debounceTimer = setTimeout(() => this.updatePositions(), 16);
|
|
1030
|
+
};
|
|
1031
|
+
clear() {
|
|
1032
|
+
this.intersectionObserver?.disconnect();
|
|
1033
|
+
for (const { badgeElement } of this.badges) {
|
|
1034
|
+
badgeElement.remove();
|
|
1035
|
+
}
|
|
1036
|
+
this.badges = [];
|
|
1037
|
+
}
|
|
1038
|
+
destroy() {
|
|
1039
|
+
this.hide();
|
|
1040
|
+
this.container.remove();
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
// src/actions/built-in.ts
|
|
1045
|
+
var EDITOR_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg>`;
|
|
1046
|
+
var COPY_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`;
|
|
1047
|
+
var GITHUB_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23A11.509 11.509 0 0 1 12 5.803c1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576C20.566 21.797 24 17.3 24 12c0-6.627-5.373-12-12-12z"/></svg>`;
|
|
1048
|
+
var CONSOLE_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" x2="20" y1="19" y2="19"/></svg>`;
|
|
1049
|
+
function createOpenEditorAction(serverUrl, editor, customEditors = []) {
|
|
1050
|
+
return {
|
|
1051
|
+
id: "open-editor",
|
|
1052
|
+
label: "Open in Editor",
|
|
1053
|
+
icon: EDITOR_ICON,
|
|
1054
|
+
handler(element) {
|
|
1055
|
+
const url = `${serverUrl}/__inspekt/open`;
|
|
1056
|
+
const body = JSON.stringify({
|
|
1057
|
+
file: element.filePath,
|
|
1058
|
+
line: element.line,
|
|
1059
|
+
column: element.column,
|
|
1060
|
+
editor
|
|
1061
|
+
});
|
|
1062
|
+
fetch(url, {
|
|
1063
|
+
method: "POST",
|
|
1064
|
+
headers: { "Content-Type": "application/json" },
|
|
1065
|
+
body
|
|
1066
|
+
}).catch(() => {
|
|
1067
|
+
const protocol = editorProtocol(editor, element, customEditors);
|
|
1068
|
+
if (protocol) window.open(protocol, "_blank");
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function createCopyPathAction() {
|
|
1074
|
+
return {
|
|
1075
|
+
id: "copy-path",
|
|
1076
|
+
label: "Copy Path",
|
|
1077
|
+
icon: COPY_ICON,
|
|
1078
|
+
handler(element) {
|
|
1079
|
+
const text = `${element.filePath}:${element.line}`;
|
|
1080
|
+
navigator.clipboard.writeText(text).catch(() => {
|
|
1081
|
+
const textarea = document.createElement("textarea");
|
|
1082
|
+
textarea.value = text;
|
|
1083
|
+
textarea.style.position = "fixed";
|
|
1084
|
+
textarea.style.opacity = "0";
|
|
1085
|
+
document.body.appendChild(textarea);
|
|
1086
|
+
textarea.select();
|
|
1087
|
+
document.execCommand("copy");
|
|
1088
|
+
document.body.removeChild(textarea);
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
function createOpenGithubAction(repo, branch) {
|
|
1094
|
+
return {
|
|
1095
|
+
id: "open-github",
|
|
1096
|
+
label: "Open on GitHub",
|
|
1097
|
+
icon: GITHUB_ICON,
|
|
1098
|
+
handler(element) {
|
|
1099
|
+
if (!repo) return;
|
|
1100
|
+
const url = `https://github.com/${repo}/blob/${branch}/${element.filePath}#L${element.line}`;
|
|
1101
|
+
window.open(url, "_blank");
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
function createConsoleLogAction() {
|
|
1106
|
+
return {
|
|
1107
|
+
id: "console-log",
|
|
1108
|
+
label: "Log to Console",
|
|
1109
|
+
icon: CONSOLE_ICON,
|
|
1110
|
+
handler(element) {
|
|
1111
|
+
console.group(`[Inspekt] ${element.componentName}`);
|
|
1112
|
+
console.log("File:", `${element.filePath}:${element.line}:${element.column}`);
|
|
1113
|
+
console.log("Element:", element.domElement);
|
|
1114
|
+
console.log("Tag:", element.tagName);
|
|
1115
|
+
if (element.props) console.log("Props:", element.props);
|
|
1116
|
+
console.groupEnd();
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
function editorProtocol(editor, element, customEditors = []) {
|
|
1121
|
+
const { filePath, line, column } = element;
|
|
1122
|
+
for (const ce of customEditors) {
|
|
1123
|
+
if (ce.value === editor) {
|
|
1124
|
+
return ce.urlTemplate.replace(/\{file\}/g, encodeURIComponent(filePath)).replace(/\{line\}/g, String(line)).replace(/\{column\}/g, String(column));
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
switch (editor) {
|
|
1128
|
+
case "vscode":
|
|
1129
|
+
return `vscode://file/${filePath}:${line}:${column}`;
|
|
1130
|
+
case "vscode-insiders":
|
|
1131
|
+
return `vscode-insiders://file/${filePath}:${line}:${column}`;
|
|
1132
|
+
case "cursor":
|
|
1133
|
+
return `cursor://file/${filePath}:${line}:${column}`;
|
|
1134
|
+
case "windsurf":
|
|
1135
|
+
return `windsurf://file/${filePath}:${line}:${column}`;
|
|
1136
|
+
case "webstorm":
|
|
1137
|
+
return `webstorm://open?file=${filePath}&line=${line}&column=${column}`;
|
|
1138
|
+
case "phpstorm":
|
|
1139
|
+
return `phpstorm://open?file=${filePath}&line=${line}&column=${column}`;
|
|
1140
|
+
case "idea":
|
|
1141
|
+
return `idea://open?file=${filePath}&line=${line}&column=${column}`;
|
|
1142
|
+
case "zed":
|
|
1143
|
+
return `zed://file/${filePath}:${line}:${column}`;
|
|
1144
|
+
case "sublime":
|
|
1145
|
+
return `subl://open?url=file://${filePath}&line=${line}&column=${column}`;
|
|
1146
|
+
// JetBrains family — query-string shape, same as webstorm/phpstorm/idea.
|
|
1147
|
+
case "pycharm":
|
|
1148
|
+
return `pycharm://open?file=${filePath}&line=${line}&column=${column}`;
|
|
1149
|
+
case "rubymine":
|
|
1150
|
+
return `rubymine://open?file=${filePath}&line=${line}&column=${column}`;
|
|
1151
|
+
case "goland":
|
|
1152
|
+
return `goland://open?file=${filePath}&line=${line}&column=${column}`;
|
|
1153
|
+
case "clion":
|
|
1154
|
+
return `clion://open?file=${filePath}&line=${line}&column=${column}`;
|
|
1155
|
+
case "rider":
|
|
1156
|
+
return `rider://open?file=${filePath}&line=${line}&column=${column}`;
|
|
1157
|
+
// VS Code family
|
|
1158
|
+
case "vscodium":
|
|
1159
|
+
return `vscodium://file/${filePath}:${line}:${column}`;
|
|
1160
|
+
// AI editors — VS Code fork URL shape. Trae/Antigravity/Qoder/CodeBuddy
|
|
1161
|
+
// are inferred (vendor docs don't enumerate the file-open scheme); we
|
|
1162
|
+
// surface this in the UI as "(unverified)" so users can test before
|
|
1163
|
+
// committing.
|
|
1164
|
+
case "trae":
|
|
1165
|
+
return `trae://file/${filePath}:${line}:${column}`;
|
|
1166
|
+
case "kiro":
|
|
1167
|
+
return `kiro://file/${filePath}:${line}:${column}`;
|
|
1168
|
+
case "antigravity":
|
|
1169
|
+
return `antigravity://file/${filePath}:${line}:${column}`;
|
|
1170
|
+
case "pearai":
|
|
1171
|
+
return `pearai://file/${filePath}:${line}:${column}`;
|
|
1172
|
+
case "qoder":
|
|
1173
|
+
return `qoder://file/${filePath}:${line}:${column}`;
|
|
1174
|
+
case "codebuddy":
|
|
1175
|
+
return `codebuddy://file/${filePath}:${line}:${column}`;
|
|
1176
|
+
default:
|
|
1177
|
+
return `vscode://file/${filePath}:${line}:${column}`;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// src/tree-panel/tree-panel.ts
|
|
1182
|
+
var TreePanel = class {
|
|
1183
|
+
constructor(shadowRoot, options) {
|
|
1184
|
+
this.shadowRoot = shadowRoot;
|
|
1185
|
+
this.options = options;
|
|
1186
|
+
this.container = document.createElement("div");
|
|
1187
|
+
this.container.className = `inspekt-tree-panel inspekt-tree-${options.position}`;
|
|
1188
|
+
this.container.style.display = "none";
|
|
1189
|
+
this.shadowRoot.appendChild(this.container);
|
|
1190
|
+
this.buildUI();
|
|
1191
|
+
}
|
|
1192
|
+
shadowRoot;
|
|
1193
|
+
options;
|
|
1194
|
+
container;
|
|
1195
|
+
visible = false;
|
|
1196
|
+
searchInput = null;
|
|
1197
|
+
treeContainer = null;
|
|
1198
|
+
filter = "";
|
|
1199
|
+
buildUI() {
|
|
1200
|
+
const header = document.createElement("div");
|
|
1201
|
+
header.className = "inspekt-tree-header";
|
|
1202
|
+
const title = document.createElement("span");
|
|
1203
|
+
title.className = "inspekt-tree-title";
|
|
1204
|
+
title.textContent = "Component Tree";
|
|
1205
|
+
const closeBtn = document.createElement("button");
|
|
1206
|
+
closeBtn.className = "inspekt-tree-close";
|
|
1207
|
+
closeBtn.innerHTML = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`;
|
|
1208
|
+
closeBtn.addEventListener("click", () => this.hide());
|
|
1209
|
+
header.appendChild(title);
|
|
1210
|
+
header.appendChild(closeBtn);
|
|
1211
|
+
this.container.appendChild(header);
|
|
1212
|
+
const searchWrap = document.createElement("div");
|
|
1213
|
+
searchWrap.className = "inspekt-tree-search";
|
|
1214
|
+
this.searchInput = document.createElement("input");
|
|
1215
|
+
this.searchInput.type = "text";
|
|
1216
|
+
this.searchInput.placeholder = "Filter components...";
|
|
1217
|
+
this.searchInput.className = "inspekt-tree-search-input";
|
|
1218
|
+
this.searchInput.addEventListener("input", () => {
|
|
1219
|
+
this.filter = this.searchInput.value.toLowerCase();
|
|
1220
|
+
this.renderCurrentTree();
|
|
1221
|
+
});
|
|
1222
|
+
searchWrap.appendChild(this.searchInput);
|
|
1223
|
+
this.container.appendChild(searchWrap);
|
|
1224
|
+
this.treeContainer = document.createElement("div");
|
|
1225
|
+
this.treeContainer.className = "inspekt-tree-content";
|
|
1226
|
+
this.container.appendChild(this.treeContainer);
|
|
1227
|
+
const resizeHandle = document.createElement("div");
|
|
1228
|
+
resizeHandle.className = `inspekt-tree-resize inspekt-tree-resize-${this.options.position === "right" ? "left" : "right"}`;
|
|
1229
|
+
this.container.appendChild(resizeHandle);
|
|
1230
|
+
this.setupResize(resizeHandle);
|
|
1231
|
+
}
|
|
1232
|
+
currentTree = null;
|
|
1233
|
+
show() {
|
|
1234
|
+
this.visible = true;
|
|
1235
|
+
this.container.style.display = "flex";
|
|
1236
|
+
}
|
|
1237
|
+
hide() {
|
|
1238
|
+
this.visible = false;
|
|
1239
|
+
this.container.style.display = "none";
|
|
1240
|
+
}
|
|
1241
|
+
toggle() {
|
|
1242
|
+
if (this.visible) this.hide();
|
|
1243
|
+
else this.show();
|
|
1244
|
+
}
|
|
1245
|
+
isVisible() {
|
|
1246
|
+
return this.visible;
|
|
1247
|
+
}
|
|
1248
|
+
updateTree(tree) {
|
|
1249
|
+
this.currentTree = tree;
|
|
1250
|
+
this.renderCurrentTree();
|
|
1251
|
+
}
|
|
1252
|
+
selectElement(element) {
|
|
1253
|
+
if (!this.treeContainer) return;
|
|
1254
|
+
const nodes = this.treeContainer.querySelectorAll(".inspekt-tree-node");
|
|
1255
|
+
for (const node of nodes) {
|
|
1256
|
+
node.classList.remove("inspekt-tree-node-selected");
|
|
1257
|
+
const path = node.getAttribute("data-path");
|
|
1258
|
+
if (path === `${element.filePath}:${element.line}`) {
|
|
1259
|
+
node.classList.add("inspekt-tree-node-selected");
|
|
1260
|
+
node.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
renderCurrentTree() {
|
|
1265
|
+
if (!this.treeContainer) return;
|
|
1266
|
+
this.treeContainer.innerHTML = "";
|
|
1267
|
+
if (!this.currentTree) {
|
|
1268
|
+
const empty = document.createElement("div");
|
|
1269
|
+
empty.className = "inspekt-tree-empty";
|
|
1270
|
+
empty.textContent = "No component tree detected";
|
|
1271
|
+
this.treeContainer.appendChild(empty);
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
const fragment = document.createDocumentFragment();
|
|
1275
|
+
this.renderNode(this.currentTree, fragment, 0);
|
|
1276
|
+
this.treeContainer.appendChild(fragment);
|
|
1277
|
+
}
|
|
1278
|
+
renderNode(node, parent, depth) {
|
|
1279
|
+
if (this.filter && !this.matchesFilter(node)) return;
|
|
1280
|
+
const row = document.createElement("div");
|
|
1281
|
+
row.className = "inspekt-tree-node";
|
|
1282
|
+
row.setAttribute("data-path", `${node.filePath ?? ""}:${node.line ?? ""}`);
|
|
1283
|
+
row.style.paddingLeft = `${depth * 16 + 8}px`;
|
|
1284
|
+
const hasChildren = node.children.length > 0;
|
|
1285
|
+
const arrow = document.createElement("span");
|
|
1286
|
+
arrow.className = "inspekt-tree-arrow";
|
|
1287
|
+
if (hasChildren) {
|
|
1288
|
+
arrow.innerHTML = `<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>`;
|
|
1289
|
+
arrow.classList.add("inspekt-tree-arrow-expanded");
|
|
1290
|
+
}
|
|
1291
|
+
row.appendChild(arrow);
|
|
1292
|
+
const name = document.createElement("span");
|
|
1293
|
+
name.className = "inspekt-tree-name";
|
|
1294
|
+
name.textContent = node.name;
|
|
1295
|
+
row.appendChild(name);
|
|
1296
|
+
if (this.options.showLineNumbers && node.line) {
|
|
1297
|
+
const line = document.createElement("span");
|
|
1298
|
+
line.className = "inspekt-tree-line";
|
|
1299
|
+
line.textContent = `:${node.line}`;
|
|
1300
|
+
row.appendChild(line);
|
|
1301
|
+
}
|
|
1302
|
+
if (this.options.showProps && node.props) {
|
|
1303
|
+
const propsEl = document.createElement("span");
|
|
1304
|
+
propsEl.className = "inspekt-tree-props";
|
|
1305
|
+
const entries = Object.entries(node.props).slice(0, 3);
|
|
1306
|
+
propsEl.textContent = entries.map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(" ");
|
|
1307
|
+
row.appendChild(propsEl);
|
|
1308
|
+
}
|
|
1309
|
+
row.addEventListener("click", (e) => {
|
|
1310
|
+
e.stopPropagation();
|
|
1311
|
+
this.options.onSelect(node);
|
|
1312
|
+
if (hasChildren) {
|
|
1313
|
+
const childContainer = row.nextElementSibling;
|
|
1314
|
+
if (childContainer?.classList.contains("inspekt-tree-children")) {
|
|
1315
|
+
const isCollapsed = childContainer.classList.toggle("inspekt-tree-collapsed");
|
|
1316
|
+
arrow.classList.toggle("inspekt-tree-arrow-collapsed", isCollapsed);
|
|
1317
|
+
arrow.classList.toggle("inspekt-tree-arrow-expanded", !isCollapsed);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
this.treeContainer.querySelectorAll(".inspekt-tree-node-selected").forEach((n) => n.classList.remove("inspekt-tree-node-selected"));
|
|
1321
|
+
row.classList.add("inspekt-tree-node-selected");
|
|
1322
|
+
});
|
|
1323
|
+
row.addEventListener("mouseenter", () => this.options.onHover(node));
|
|
1324
|
+
row.addEventListener("mouseleave", () => this.options.onHover(null));
|
|
1325
|
+
parent.appendChild(row);
|
|
1326
|
+
if (hasChildren) {
|
|
1327
|
+
const childContainer = document.createElement("div");
|
|
1328
|
+
childContainer.className = "inspekt-tree-children";
|
|
1329
|
+
for (const child of node.children) {
|
|
1330
|
+
this.renderNode(child, childContainer, depth + 1);
|
|
1331
|
+
}
|
|
1332
|
+
parent.appendChild(childContainer);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
matchesFilter(node) {
|
|
1336
|
+
if (node.name.toLowerCase().includes(this.filter)) return true;
|
|
1337
|
+
return node.children.some((child) => this.matchesFilter(child));
|
|
1338
|
+
}
|
|
1339
|
+
setupResize(handle) {
|
|
1340
|
+
let startX;
|
|
1341
|
+
let startWidth;
|
|
1342
|
+
const isRight = this.options.position === "right";
|
|
1343
|
+
const onMouseMove = (e) => {
|
|
1344
|
+
const dx = e.clientX - startX;
|
|
1345
|
+
const newWidth = isRight ? startWidth - dx : startWidth + dx;
|
|
1346
|
+
this.container.style.width = `${Math.max(200, Math.min(600, newWidth))}px`;
|
|
1347
|
+
};
|
|
1348
|
+
const onMouseUp = () => {
|
|
1349
|
+
document.removeEventListener("mousemove", onMouseMove);
|
|
1350
|
+
document.removeEventListener("mouseup", onMouseUp);
|
|
1351
|
+
this.container.style.userSelect = "";
|
|
1352
|
+
};
|
|
1353
|
+
handle.addEventListener("mousedown", (e) => {
|
|
1354
|
+
e.preventDefault();
|
|
1355
|
+
startX = e.clientX;
|
|
1356
|
+
startWidth = this.container.offsetWidth;
|
|
1357
|
+
this.container.style.userSelect = "none";
|
|
1358
|
+
document.addEventListener("mousemove", onMouseMove);
|
|
1359
|
+
document.addEventListener("mouseup", onMouseUp);
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
destroy() {
|
|
1363
|
+
this.container.remove();
|
|
1364
|
+
}
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
// src/adapters/react.ts
|
|
1368
|
+
var FIBER_KEY_PREFIX = "__reactFiber$";
|
|
1369
|
+
var INTERNAL_KEY_PREFIX = "__reactInternalInstance$";
|
|
1370
|
+
function getFiberFromElement(element) {
|
|
1371
|
+
for (const key of Object.keys(element)) {
|
|
1372
|
+
if (key.startsWith(FIBER_KEY_PREFIX) || key.startsWith(INTERNAL_KEY_PREFIX)) {
|
|
1373
|
+
return element[key];
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
return null;
|
|
1377
|
+
}
|
|
1378
|
+
function isUserComponent(fiber) {
|
|
1379
|
+
const tag = fiber["tag"];
|
|
1380
|
+
return tag === 0 || tag === 1 || tag === 11 || tag === 14 || tag === 15;
|
|
1381
|
+
}
|
|
1382
|
+
function getComponentName(fiber) {
|
|
1383
|
+
const type = fiber["type"];
|
|
1384
|
+
if (!type) return "Unknown";
|
|
1385
|
+
if (typeof type === "function") {
|
|
1386
|
+
return type.displayName ?? type.name ?? "Anonymous";
|
|
1387
|
+
}
|
|
1388
|
+
if (typeof type === "object") {
|
|
1389
|
+
const render = type["render"];
|
|
1390
|
+
if (render) return render.displayName ?? render.name ?? "ForwardRef";
|
|
1391
|
+
const innerType = type["type"];
|
|
1392
|
+
if (innerType) return innerType.displayName ?? innerType.name ?? "Memo";
|
|
1393
|
+
}
|
|
1394
|
+
if (typeof type === "string") return type;
|
|
1395
|
+
return "Unknown";
|
|
1396
|
+
}
|
|
1397
|
+
function getProps(fiber) {
|
|
1398
|
+
const memoizedProps = fiber["memoizedProps"];
|
|
1399
|
+
if (!memoizedProps) return null;
|
|
1400
|
+
const cleaned = {};
|
|
1401
|
+
for (const [key, value] of Object.entries(memoizedProps)) {
|
|
1402
|
+
if (key === "children") continue;
|
|
1403
|
+
if (typeof value === "function") {
|
|
1404
|
+
cleaned[key] = `[Function: ${value.name || "anonymous"}]`;
|
|
1405
|
+
} else if (typeof value === "object" && value !== null) {
|
|
1406
|
+
cleaned[key] = "[Object]";
|
|
1407
|
+
} else {
|
|
1408
|
+
cleaned[key] = value;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return Object.keys(cleaned).length > 0 ? cleaned : null;
|
|
1412
|
+
}
|
|
1413
|
+
function getSourceFromFiber(fiber) {
|
|
1414
|
+
const debugSource = fiber["_debugSource"];
|
|
1415
|
+
if (debugSource) {
|
|
1416
|
+
return {
|
|
1417
|
+
filePath: debugSource["fileName"] ?? "",
|
|
1418
|
+
line: debugSource["lineNumber"] ?? 0,
|
|
1419
|
+
column: debugSource["columnNumber"] ?? 0
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
const stateNode = fiber["stateNode"];
|
|
1423
|
+
if (stateNode && stateNode instanceof HTMLElement) {
|
|
1424
|
+
const attr = findSourceAttribute(stateNode);
|
|
1425
|
+
if (attr) {
|
|
1426
|
+
const parsed = parseSourceAttribute(attr);
|
|
1427
|
+
if (parsed) return { filePath: parsed.filePath, line: parsed.line, column: parsed.column };
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
return null;
|
|
1431
|
+
}
|
|
1432
|
+
function fiberToNode(fiber, depth) {
|
|
1433
|
+
if (!isUserComponent(fiber)) return null;
|
|
1434
|
+
const name = getComponentName(fiber);
|
|
1435
|
+
const source = getSourceFromFiber(fiber);
|
|
1436
|
+
const stateNode = fiber["stateNode"];
|
|
1437
|
+
const domElement = stateNode instanceof HTMLElement ? stateNode : findDomElement(fiber);
|
|
1438
|
+
const node = {
|
|
1439
|
+
name,
|
|
1440
|
+
filePath: source?.filePath ?? null,
|
|
1441
|
+
line: source?.line ?? null,
|
|
1442
|
+
column: source?.column ?? null,
|
|
1443
|
+
domElement,
|
|
1444
|
+
props: getProps(fiber),
|
|
1445
|
+
children: [],
|
|
1446
|
+
framework: "react",
|
|
1447
|
+
depth
|
|
1448
|
+
};
|
|
1449
|
+
let child = fiber["child"];
|
|
1450
|
+
while (child) {
|
|
1451
|
+
const childNode = fiberToNode(child, depth + 1);
|
|
1452
|
+
if (childNode) {
|
|
1453
|
+
node.children.push(childNode);
|
|
1454
|
+
} else {
|
|
1455
|
+
const grandchildren = collectUserChildren(child, depth + 1);
|
|
1456
|
+
node.children.push(...grandchildren);
|
|
1457
|
+
}
|
|
1458
|
+
child = child["sibling"];
|
|
1459
|
+
}
|
|
1460
|
+
return node;
|
|
1461
|
+
}
|
|
1462
|
+
function collectUserChildren(fiber, depth) {
|
|
1463
|
+
const result = [];
|
|
1464
|
+
let child = fiber["child"];
|
|
1465
|
+
while (child) {
|
|
1466
|
+
const node = fiberToNode(child, depth);
|
|
1467
|
+
if (node) {
|
|
1468
|
+
result.push(node);
|
|
1469
|
+
} else {
|
|
1470
|
+
result.push(...collectUserChildren(child, depth));
|
|
1471
|
+
}
|
|
1472
|
+
child = child["sibling"];
|
|
1473
|
+
}
|
|
1474
|
+
return result;
|
|
1475
|
+
}
|
|
1476
|
+
function findDomElement(fiber) {
|
|
1477
|
+
let current = fiber;
|
|
1478
|
+
while (current) {
|
|
1479
|
+
const stateNode = current["stateNode"];
|
|
1480
|
+
if (stateNode instanceof HTMLElement) return stateNode;
|
|
1481
|
+
current = current["child"];
|
|
1482
|
+
}
|
|
1483
|
+
return null;
|
|
1484
|
+
}
|
|
1485
|
+
function findRootFiber(container) {
|
|
1486
|
+
for (const key of Object.keys(container)) {
|
|
1487
|
+
if (key.startsWith("__reactContainer$")) {
|
|
1488
|
+
return container[key];
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
const root = container["_reactRootContainer"];
|
|
1492
|
+
if (root) {
|
|
1493
|
+
const internalRoot = root["_internalRoot"];
|
|
1494
|
+
if (internalRoot) {
|
|
1495
|
+
return internalRoot["current"];
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return null;
|
|
1499
|
+
}
|
|
1500
|
+
var reactAdapter = {
|
|
1501
|
+
name: "react",
|
|
1502
|
+
detect() {
|
|
1503
|
+
const root = document.getElementById("root") ?? document.getElementById("app") ?? document.querySelector("[data-reactroot]");
|
|
1504
|
+
if (!root) return false;
|
|
1505
|
+
for (const key of Object.keys(root)) {
|
|
1506
|
+
if (key.startsWith("__reactContainer$") || key.startsWith(FIBER_KEY_PREFIX) || key.startsWith(INTERNAL_KEY_PREFIX)) {
|
|
1507
|
+
return true;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return !!root["_reactRootContainer"];
|
|
1511
|
+
},
|
|
1512
|
+
getComponentTree(root) {
|
|
1513
|
+
const rootFiber = findRootFiber(root);
|
|
1514
|
+
if (!rootFiber) return null;
|
|
1515
|
+
const appFiber = rootFiber["child"];
|
|
1516
|
+
if (!appFiber) return null;
|
|
1517
|
+
return fiberToNode(appFiber, 0);
|
|
1518
|
+
},
|
|
1519
|
+
getComponentAtElement(element) {
|
|
1520
|
+
const fiber = getFiberFromElement(element);
|
|
1521
|
+
if (!fiber) return null;
|
|
1522
|
+
let current = fiber;
|
|
1523
|
+
while (current) {
|
|
1524
|
+
if (isUserComponent(current)) {
|
|
1525
|
+
return fiberToNode(current, 0);
|
|
1526
|
+
}
|
|
1527
|
+
current = current["return"];
|
|
1528
|
+
}
|
|
1529
|
+
return null;
|
|
1530
|
+
},
|
|
1531
|
+
getAncestors(element) {
|
|
1532
|
+
const fiber = getFiberFromElement(element);
|
|
1533
|
+
if (!fiber) return [];
|
|
1534
|
+
const ancestors = [];
|
|
1535
|
+
let current = fiber["return"];
|
|
1536
|
+
while (current) {
|
|
1537
|
+
if (isUserComponent(current)) {
|
|
1538
|
+
const node = fiberToNode(current, 0);
|
|
1539
|
+
if (node) {
|
|
1540
|
+
node.children = [];
|
|
1541
|
+
ancestors.push(node);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
current = current["return"];
|
|
1545
|
+
}
|
|
1546
|
+
return ancestors;
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1550
|
+
// src/adapters/vue.ts
|
|
1551
|
+
var VUE_KEY = "__vue__";
|
|
1552
|
+
var VUE3_KEY = "__vue_app__";
|
|
1553
|
+
var VUE_PARENT_KEY = "__vueParentComponent";
|
|
1554
|
+
function getVueInstance(element) {
|
|
1555
|
+
const vue3 = element[VUE_PARENT_KEY];
|
|
1556
|
+
if (vue3) return vue3;
|
|
1557
|
+
const vue2 = element[VUE_KEY];
|
|
1558
|
+
if (vue2) return vue2;
|
|
1559
|
+
return null;
|
|
1560
|
+
}
|
|
1561
|
+
function getComponentName2(instance) {
|
|
1562
|
+
if (instance.type) {
|
|
1563
|
+
return instance.type.name ?? instance.type.__name ?? "Anonymous";
|
|
1564
|
+
}
|
|
1565
|
+
if (instance.$options) {
|
|
1566
|
+
return instance.$options.name ?? instance.$options._componentTag ?? "Anonymous";
|
|
1567
|
+
}
|
|
1568
|
+
return "Unknown";
|
|
1569
|
+
}
|
|
1570
|
+
function getFilePath(instance) {
|
|
1571
|
+
if (instance.type?.__file) return instance.type.__file;
|
|
1572
|
+
if (instance.$options?.__file) return instance.$options.__file;
|
|
1573
|
+
return null;
|
|
1574
|
+
}
|
|
1575
|
+
function getElement(instance) {
|
|
1576
|
+
if (instance.subTree?.el instanceof HTMLElement) return instance.subTree.el;
|
|
1577
|
+
if (instance.$el instanceof HTMLElement) return instance.$el;
|
|
1578
|
+
return null;
|
|
1579
|
+
}
|
|
1580
|
+
function getProps2(instance) {
|
|
1581
|
+
const raw = instance.props ?? instance.$props;
|
|
1582
|
+
if (!raw || Object.keys(raw).length === 0) return null;
|
|
1583
|
+
const cleaned = {};
|
|
1584
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
1585
|
+
if (typeof value === "function") {
|
|
1586
|
+
cleaned[key] = `[Function]`;
|
|
1587
|
+
} else if (typeof value === "object" && value !== null) {
|
|
1588
|
+
cleaned[key] = "[Object]";
|
|
1589
|
+
} else {
|
|
1590
|
+
cleaned[key] = value;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
return cleaned;
|
|
1594
|
+
}
|
|
1595
|
+
function instanceToNode(instance, depth) {
|
|
1596
|
+
const name = getComponentName2(instance);
|
|
1597
|
+
const file = getFilePath(instance);
|
|
1598
|
+
const el = getElement(instance);
|
|
1599
|
+
let filePath = file;
|
|
1600
|
+
let line = null;
|
|
1601
|
+
if (el) {
|
|
1602
|
+
const attr = findSourceAttribute(el);
|
|
1603
|
+
if (attr) {
|
|
1604
|
+
const source = parseSourceAttribute(attr);
|
|
1605
|
+
if (source) {
|
|
1606
|
+
filePath = source.filePath;
|
|
1607
|
+
line = source.line;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
return {
|
|
1612
|
+
name,
|
|
1613
|
+
filePath,
|
|
1614
|
+
line,
|
|
1615
|
+
column: null,
|
|
1616
|
+
domElement: el,
|
|
1617
|
+
props: getProps2(instance),
|
|
1618
|
+
children: [],
|
|
1619
|
+
framework: "vue",
|
|
1620
|
+
depth
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
var vueAdapter = {
|
|
1624
|
+
name: "vue",
|
|
1625
|
+
detect() {
|
|
1626
|
+
const root = document.getElementById("app") ?? document.getElementById("root");
|
|
1627
|
+
if (!root) return false;
|
|
1628
|
+
return !!(root[VUE3_KEY] || root[VUE_KEY]);
|
|
1629
|
+
},
|
|
1630
|
+
getComponentTree(root) {
|
|
1631
|
+
const rootNode = {
|
|
1632
|
+
name: "App",
|
|
1633
|
+
filePath: null,
|
|
1634
|
+
line: null,
|
|
1635
|
+
column: null,
|
|
1636
|
+
domElement: root,
|
|
1637
|
+
props: null,
|
|
1638
|
+
children: [],
|
|
1639
|
+
framework: "vue",
|
|
1640
|
+
depth: 0
|
|
1641
|
+
};
|
|
1642
|
+
function walkDOM(el, parent, depth) {
|
|
1643
|
+
for (const child of Array.from(el.children)) {
|
|
1644
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
1645
|
+
const instance = getVueInstance(child);
|
|
1646
|
+
if (instance) {
|
|
1647
|
+
const node = instanceToNode(instance, depth);
|
|
1648
|
+
parent.children.push(node);
|
|
1649
|
+
walkDOM(child, node, depth + 1);
|
|
1650
|
+
} else {
|
|
1651
|
+
walkDOM(child, parent, depth);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
walkDOM(root, rootNode, 1);
|
|
1656
|
+
return rootNode.children.length > 0 ? rootNode : null;
|
|
1657
|
+
},
|
|
1658
|
+
getComponentAtElement(element) {
|
|
1659
|
+
const instance = getVueInstance(element);
|
|
1660
|
+
if (!instance) return null;
|
|
1661
|
+
return instanceToNode(instance, 0);
|
|
1662
|
+
},
|
|
1663
|
+
getAncestors(element) {
|
|
1664
|
+
const ancestors = [];
|
|
1665
|
+
let instance = getVueInstance(element);
|
|
1666
|
+
while (instance) {
|
|
1667
|
+
const parent = instance.parent ?? instance.$parent;
|
|
1668
|
+
if (parent) {
|
|
1669
|
+
ancestors.push(instanceToNode(parent, 0));
|
|
1670
|
+
}
|
|
1671
|
+
instance = parent ?? null;
|
|
1672
|
+
}
|
|
1673
|
+
return ancestors;
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
// src/adapters/svelte.ts
|
|
1678
|
+
var SVELTE_CONTEXT_KEY = "__svelte_meta";
|
|
1679
|
+
function getSvelteContext(element) {
|
|
1680
|
+
return element[SVELTE_CONTEXT_KEY];
|
|
1681
|
+
}
|
|
1682
|
+
function getComponentNameFromFile(file) {
|
|
1683
|
+
const parts = file.split("/");
|
|
1684
|
+
const filename = parts[parts.length - 1] ?? "";
|
|
1685
|
+
return filename.replace(/\.svelte$/, "");
|
|
1686
|
+
}
|
|
1687
|
+
var svelteAdapter = {
|
|
1688
|
+
name: "svelte",
|
|
1689
|
+
detect() {
|
|
1690
|
+
return document.querySelector(`[class*="svelte-"]`) !== null || document.querySelector("[data-svelte-h]") !== null;
|
|
1691
|
+
},
|
|
1692
|
+
getComponentTree(root) {
|
|
1693
|
+
const rootNode = {
|
|
1694
|
+
name: "App",
|
|
1695
|
+
filePath: null,
|
|
1696
|
+
line: null,
|
|
1697
|
+
column: null,
|
|
1698
|
+
domElement: root,
|
|
1699
|
+
props: null,
|
|
1700
|
+
children: [],
|
|
1701
|
+
framework: "svelte",
|
|
1702
|
+
depth: 0
|
|
1703
|
+
};
|
|
1704
|
+
function walkDOM(el, parent, depth) {
|
|
1705
|
+
for (const child of Array.from(el.children)) {
|
|
1706
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
1707
|
+
const attr = findSourceAttribute(child);
|
|
1708
|
+
if (attr) {
|
|
1709
|
+
const source = parseSourceAttribute(attr);
|
|
1710
|
+
if (source) {
|
|
1711
|
+
const node = {
|
|
1712
|
+
name: source.componentName,
|
|
1713
|
+
filePath: source.filePath,
|
|
1714
|
+
line: source.line,
|
|
1715
|
+
column: source.column,
|
|
1716
|
+
domElement: child,
|
|
1717
|
+
props: null,
|
|
1718
|
+
children: [],
|
|
1719
|
+
framework: "svelte",
|
|
1720
|
+
depth
|
|
1721
|
+
};
|
|
1722
|
+
parent.children.push(node);
|
|
1723
|
+
walkDOM(child, node, depth + 1);
|
|
1724
|
+
continue;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
const ctx = getSvelteContext(child);
|
|
1728
|
+
if (ctx?.loc?.file) {
|
|
1729
|
+
const node = {
|
|
1730
|
+
name: getComponentNameFromFile(ctx.loc.file),
|
|
1731
|
+
filePath: ctx.loc.file,
|
|
1732
|
+
line: ctx.loc.line ?? null,
|
|
1733
|
+
column: ctx.loc.column ?? null,
|
|
1734
|
+
domElement: child,
|
|
1735
|
+
props: null,
|
|
1736
|
+
children: [],
|
|
1737
|
+
framework: "svelte",
|
|
1738
|
+
depth
|
|
1739
|
+
};
|
|
1740
|
+
parent.children.push(node);
|
|
1741
|
+
walkDOM(child, node, depth + 1);
|
|
1742
|
+
continue;
|
|
1743
|
+
}
|
|
1744
|
+
walkDOM(child, parent, depth);
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
walkDOM(root, rootNode, 1);
|
|
1748
|
+
return rootNode.children.length > 0 ? rootNode : null;
|
|
1749
|
+
},
|
|
1750
|
+
getComponentAtElement(element) {
|
|
1751
|
+
const attr = findSourceAttribute(element);
|
|
1752
|
+
if (attr) {
|
|
1753
|
+
const source = parseSourceAttribute(attr);
|
|
1754
|
+
if (source) {
|
|
1755
|
+
return {
|
|
1756
|
+
name: source.componentName,
|
|
1757
|
+
filePath: source.filePath,
|
|
1758
|
+
line: source.line,
|
|
1759
|
+
column: source.column,
|
|
1760
|
+
domElement: element,
|
|
1761
|
+
props: null,
|
|
1762
|
+
children: [],
|
|
1763
|
+
framework: "svelte",
|
|
1764
|
+
depth: 0
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
const ctx = getSvelteContext(element);
|
|
1769
|
+
if (ctx?.loc?.file) {
|
|
1770
|
+
return {
|
|
1771
|
+
name: getComponentNameFromFile(ctx.loc.file),
|
|
1772
|
+
filePath: ctx.loc.file,
|
|
1773
|
+
line: ctx.loc.line ?? null,
|
|
1774
|
+
column: ctx.loc.column ?? null,
|
|
1775
|
+
domElement: element,
|
|
1776
|
+
props: null,
|
|
1777
|
+
children: [],
|
|
1778
|
+
framework: "svelte",
|
|
1779
|
+
depth: 0
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
return null;
|
|
1783
|
+
},
|
|
1784
|
+
getAncestors(element) {
|
|
1785
|
+
const ancestors = [];
|
|
1786
|
+
let current = element.parentElement;
|
|
1787
|
+
while (current) {
|
|
1788
|
+
const node = this.getComponentAtElement(current);
|
|
1789
|
+
if (node) ancestors.push(node);
|
|
1790
|
+
current = current.parentElement;
|
|
1791
|
+
}
|
|
1792
|
+
return ancestors;
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
|
|
1796
|
+
// src/adapters/solid.ts
|
|
1797
|
+
var SOLID_DEV_KEY = "_$owner";
|
|
1798
|
+
function getSolidOwner(element) {
|
|
1799
|
+
return element[SOLID_DEV_KEY];
|
|
1800
|
+
}
|
|
1801
|
+
var solidAdapter = {
|
|
1802
|
+
name: "solid",
|
|
1803
|
+
detect() {
|
|
1804
|
+
return document.querySelector("[data-hk]") !== null || !!document["_$HY"];
|
|
1805
|
+
},
|
|
1806
|
+
getComponentTree(root) {
|
|
1807
|
+
const rootNode = {
|
|
1808
|
+
name: "App",
|
|
1809
|
+
filePath: null,
|
|
1810
|
+
line: null,
|
|
1811
|
+
column: null,
|
|
1812
|
+
domElement: root,
|
|
1813
|
+
props: null,
|
|
1814
|
+
children: [],
|
|
1815
|
+
framework: "solid",
|
|
1816
|
+
depth: 0
|
|
1817
|
+
};
|
|
1818
|
+
function walkDOM(el, parent, depth) {
|
|
1819
|
+
for (const child of Array.from(el.children)) {
|
|
1820
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
1821
|
+
const attr = findSourceAttribute(child);
|
|
1822
|
+
if (attr) {
|
|
1823
|
+
const source = parseSourceAttribute(attr);
|
|
1824
|
+
if (source) {
|
|
1825
|
+
const node = {
|
|
1826
|
+
name: source.componentName,
|
|
1827
|
+
filePath: source.filePath,
|
|
1828
|
+
line: source.line,
|
|
1829
|
+
column: source.column,
|
|
1830
|
+
domElement: child,
|
|
1831
|
+
props: null,
|
|
1832
|
+
children: [],
|
|
1833
|
+
framework: "solid",
|
|
1834
|
+
depth
|
|
1835
|
+
};
|
|
1836
|
+
parent.children.push(node);
|
|
1837
|
+
walkDOM(child, node, depth + 1);
|
|
1838
|
+
continue;
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
const owner = getSolidOwner(child);
|
|
1842
|
+
if (owner?.componentName || owner?.name) {
|
|
1843
|
+
const node = {
|
|
1844
|
+
name: owner.componentName ?? owner.name ?? "Component",
|
|
1845
|
+
filePath: owner.sourceMap?.file ?? null,
|
|
1846
|
+
line: owner.sourceMap?.line ?? null,
|
|
1847
|
+
column: owner.sourceMap?.column ?? null,
|
|
1848
|
+
domElement: child,
|
|
1849
|
+
props: null,
|
|
1850
|
+
children: [],
|
|
1851
|
+
framework: "solid",
|
|
1852
|
+
depth
|
|
1853
|
+
};
|
|
1854
|
+
parent.children.push(node);
|
|
1855
|
+
walkDOM(child, node, depth + 1);
|
|
1856
|
+
continue;
|
|
1857
|
+
}
|
|
1858
|
+
walkDOM(child, parent, depth);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
walkDOM(root, rootNode, 1);
|
|
1862
|
+
return rootNode.children.length > 0 ? rootNode : null;
|
|
1863
|
+
},
|
|
1864
|
+
getComponentAtElement(element) {
|
|
1865
|
+
const attr = findSourceAttribute(element);
|
|
1866
|
+
if (attr) {
|
|
1867
|
+
const source = parseSourceAttribute(attr);
|
|
1868
|
+
if (source) {
|
|
1869
|
+
return {
|
|
1870
|
+
name: source.componentName,
|
|
1871
|
+
filePath: source.filePath,
|
|
1872
|
+
line: source.line,
|
|
1873
|
+
column: source.column,
|
|
1874
|
+
domElement: element,
|
|
1875
|
+
props: null,
|
|
1876
|
+
children: [],
|
|
1877
|
+
framework: "solid",
|
|
1878
|
+
depth: 0
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
const owner = getSolidOwner(element);
|
|
1883
|
+
if (owner?.componentName || owner?.name) {
|
|
1884
|
+
return {
|
|
1885
|
+
name: owner.componentName ?? owner.name ?? "Component",
|
|
1886
|
+
filePath: owner.sourceMap?.file ?? null,
|
|
1887
|
+
line: owner.sourceMap?.line ?? null,
|
|
1888
|
+
column: owner.sourceMap?.column ?? null,
|
|
1889
|
+
domElement: element,
|
|
1890
|
+
props: null,
|
|
1891
|
+
children: [],
|
|
1892
|
+
framework: "solid",
|
|
1893
|
+
depth: 0
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
return null;
|
|
1897
|
+
},
|
|
1898
|
+
getAncestors(element) {
|
|
1899
|
+
const ancestors = [];
|
|
1900
|
+
let current = element.parentElement;
|
|
1901
|
+
while (current) {
|
|
1902
|
+
const node = this.getComponentAtElement(current);
|
|
1903
|
+
if (node) ancestors.push(node);
|
|
1904
|
+
current = current.parentElement;
|
|
1905
|
+
}
|
|
1906
|
+
return ancestors;
|
|
1907
|
+
}
|
|
1908
|
+
};
|
|
1909
|
+
|
|
1910
|
+
// src/adapters/generic.ts
|
|
1911
|
+
function buildTreeFromDOM(element, depth) {
|
|
1912
|
+
const nodes = [];
|
|
1913
|
+
for (const child of Array.from(element.children)) {
|
|
1914
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
1915
|
+
if (child.tagName === "INSPEKT-ROOT") continue;
|
|
1916
|
+
if (child.tagName === "SCRIPT" || child.tagName === "STYLE") continue;
|
|
1917
|
+
const attr = findSourceAttribute(child);
|
|
1918
|
+
if (attr) {
|
|
1919
|
+
const source = parseSourceAttribute(attr);
|
|
1920
|
+
if (source) {
|
|
1921
|
+
const node = {
|
|
1922
|
+
name: source.componentName,
|
|
1923
|
+
filePath: source.filePath,
|
|
1924
|
+
line: source.line,
|
|
1925
|
+
column: source.column,
|
|
1926
|
+
domElement: child,
|
|
1927
|
+
props: null,
|
|
1928
|
+
children: buildTreeFromDOM(child, depth + 1),
|
|
1929
|
+
framework: "unknown",
|
|
1930
|
+
depth
|
|
1931
|
+
};
|
|
1932
|
+
nodes.push(node);
|
|
1933
|
+
continue;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
nodes.push(...buildTreeFromDOM(child, depth));
|
|
1937
|
+
}
|
|
1938
|
+
return nodes;
|
|
1939
|
+
}
|
|
1940
|
+
var genericAdapter = {
|
|
1941
|
+
name: "generic",
|
|
1942
|
+
detect() {
|
|
1943
|
+
return document.querySelector("[data-insp-path], [data-insp-path]") !== null;
|
|
1944
|
+
},
|
|
1945
|
+
getComponentTree(root) {
|
|
1946
|
+
const children = buildTreeFromDOM(root, 1);
|
|
1947
|
+
if (children.length === 0) return null;
|
|
1948
|
+
return {
|
|
1949
|
+
name: "Root",
|
|
1950
|
+
filePath: null,
|
|
1951
|
+
line: null,
|
|
1952
|
+
column: null,
|
|
1953
|
+
domElement: root,
|
|
1954
|
+
props: null,
|
|
1955
|
+
children,
|
|
1956
|
+
framework: "unknown",
|
|
1957
|
+
depth: 0
|
|
1958
|
+
};
|
|
1959
|
+
},
|
|
1960
|
+
getComponentAtElement(element) {
|
|
1961
|
+
const attr = findSourceAttribute(element);
|
|
1962
|
+
if (!attr) return null;
|
|
1963
|
+
const source = parseSourceAttribute(attr);
|
|
1964
|
+
if (!source) return null;
|
|
1965
|
+
return {
|
|
1966
|
+
name: source.componentName,
|
|
1967
|
+
filePath: source.filePath,
|
|
1968
|
+
line: source.line,
|
|
1969
|
+
column: source.column,
|
|
1970
|
+
domElement: element,
|
|
1971
|
+
props: null,
|
|
1972
|
+
children: buildTreeFromDOM(element, 1),
|
|
1973
|
+
framework: "unknown",
|
|
1974
|
+
depth: 0
|
|
1975
|
+
};
|
|
1976
|
+
},
|
|
1977
|
+
getAncestors(element) {
|
|
1978
|
+
const ancestors = [];
|
|
1979
|
+
let current = element.parentElement;
|
|
1980
|
+
while (current) {
|
|
1981
|
+
const attr = findSourceAttribute(current);
|
|
1982
|
+
if (attr) {
|
|
1983
|
+
const source = parseSourceAttribute(attr);
|
|
1984
|
+
if (source) {
|
|
1985
|
+
ancestors.push({
|
|
1986
|
+
name: source.componentName,
|
|
1987
|
+
filePath: source.filePath,
|
|
1988
|
+
line: source.line,
|
|
1989
|
+
column: source.column,
|
|
1990
|
+
domElement: current,
|
|
1991
|
+
props: null,
|
|
1992
|
+
children: [],
|
|
1993
|
+
framework: "unknown",
|
|
1994
|
+
depth: 0
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
current = current.parentElement;
|
|
1999
|
+
}
|
|
2000
|
+
return ancestors;
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
|
|
2004
|
+
// src/adapters/index.ts
|
|
2005
|
+
var adapters = [
|
|
2006
|
+
reactAdapter,
|
|
2007
|
+
vueAdapter,
|
|
2008
|
+
svelteAdapter,
|
|
2009
|
+
solidAdapter
|
|
2010
|
+
];
|
|
2011
|
+
function detectAdapter() {
|
|
2012
|
+
for (const adapter of adapters) {
|
|
2013
|
+
if (adapter.detect()) return adapter;
|
|
2014
|
+
}
|
|
2015
|
+
return genericAdapter;
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
// src/styles.ts
|
|
2019
|
+
var STYLES = (
|
|
2020
|
+
/* css */
|
|
2021
|
+
`
|
|
2022
|
+
:host {
|
|
2023
|
+
all: initial;
|
|
2024
|
+
position: fixed;
|
|
2025
|
+
top: 0;
|
|
2026
|
+
left: 0;
|
|
2027
|
+
width: 0;
|
|
2028
|
+
height: 0;
|
|
2029
|
+
z-index: 2147483647;
|
|
2030
|
+
pointer-events: none;
|
|
2031
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
2032
|
+
font-size: 13px;
|
|
2033
|
+
line-height: 1.4;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
*, *::before, *::after {
|
|
2037
|
+
box-sizing: border-box;
|
|
2038
|
+
margin: 0;
|
|
2039
|
+
padding: 0;
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
/* Theme variables */
|
|
2043
|
+
:host {
|
|
2044
|
+
--dl-bg: #1e1e2e;
|
|
2045
|
+
--dl-bg-hover: #313244;
|
|
2046
|
+
--dl-text: #cdd6f4;
|
|
2047
|
+
--dl-text-dim: #a6adc8;
|
|
2048
|
+
--dl-border: #45475a;
|
|
2049
|
+
--dl-accent: #3b82f6;
|
|
2050
|
+
--dl-accent-dim: #3b82f640;
|
|
2051
|
+
--dl-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
|
2052
|
+
--dl-radius: 8px;
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
:host(.inspekt-light) {
|
|
2056
|
+
--dl-bg: #ffffff;
|
|
2057
|
+
--dl-bg-hover: #f1f5f9;
|
|
2058
|
+
--dl-text: #1e293b;
|
|
2059
|
+
--dl-text-dim: #64748b;
|
|
2060
|
+
--dl-border: #e2e8f0;
|
|
2061
|
+
--dl-accent: #3b82f6;
|
|
2062
|
+
--dl-accent-dim: #3b82f620;
|
|
2063
|
+
--dl-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
/* Popover */
|
|
2067
|
+
.inspekt-popover {
|
|
2068
|
+
position: fixed;
|
|
2069
|
+
background: var(--dl-bg);
|
|
2070
|
+
border: 1px solid var(--dl-border);
|
|
2071
|
+
border-radius: var(--dl-radius);
|
|
2072
|
+
box-shadow: var(--dl-shadow);
|
|
2073
|
+
color: var(--dl-text);
|
|
2074
|
+
min-width: 200px;
|
|
2075
|
+
max-width: 400px;
|
|
2076
|
+
overflow: hidden;
|
|
2077
|
+
pointer-events: auto;
|
|
2078
|
+
z-index: 2147483647;
|
|
2079
|
+
animation: inspekt-fade-in 0.15s ease;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
@keyframes inspekt-fade-in {
|
|
2083
|
+
from { opacity: 0; transform: translateY(4px); }
|
|
2084
|
+
to { opacity: 1; transform: translateY(0); }
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
.inspekt-popover-header {
|
|
2088
|
+
padding: 8px 12px;
|
|
2089
|
+
border-bottom: 1px solid var(--dl-border);
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
.inspekt-popover-path-dir {
|
|
2093
|
+
font-size: 11px;
|
|
2094
|
+
color: var(--dl-text-dim);
|
|
2095
|
+
overflow: hidden;
|
|
2096
|
+
text-overflow: ellipsis;
|
|
2097
|
+
white-space: nowrap;
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
.inspekt-popover-path-file {
|
|
2101
|
+
font-size: 13px;
|
|
2102
|
+
font-weight: 600;
|
|
2103
|
+
color: var(--dl-text);
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
.inspekt-popover-actions {
|
|
2107
|
+
display: flex;
|
|
2108
|
+
gap: 2px;
|
|
2109
|
+
padding: 6px 8px;
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
/* Snippet section */
|
|
2113
|
+
.inspekt-snippet {
|
|
2114
|
+
border-bottom: 1px solid var(--dl-border);
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
.inspekt-snippet-toggle {
|
|
2118
|
+
display: flex;
|
|
2119
|
+
align-items: center;
|
|
2120
|
+
width: 100%;
|
|
2121
|
+
padding: 6px 12px;
|
|
2122
|
+
background: transparent;
|
|
2123
|
+
border: none;
|
|
2124
|
+
color: var(--dl-text-dim);
|
|
2125
|
+
font-size: 11px;
|
|
2126
|
+
font-weight: 500;
|
|
2127
|
+
cursor: pointer;
|
|
2128
|
+
font-family: inherit;
|
|
2129
|
+
text-align: left;
|
|
2130
|
+
pointer-events: auto;
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
.inspekt-snippet-toggle:hover {
|
|
2134
|
+
background: var(--dl-bg-hover);
|
|
2135
|
+
color: var(--dl-text);
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
.inspekt-snippet-body {
|
|
2139
|
+
padding: 0;
|
|
2140
|
+
max-width: 600px;
|
|
2141
|
+
max-height: 240px;
|
|
2142
|
+
overflow: auto;
|
|
2143
|
+
border-top: 1px solid var(--dl-border);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
.inspekt-snippet-pre {
|
|
2147
|
+
margin: 0;
|
|
2148
|
+
padding: 8px 0;
|
|
2149
|
+
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Consolas', monospace;
|
|
2150
|
+
font-size: 12px;
|
|
2151
|
+
line-height: 1.5;
|
|
2152
|
+
color: var(--dl-text);
|
|
2153
|
+
background: transparent;
|
|
2154
|
+
white-space: pre;
|
|
2155
|
+
tab-size: 2;
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
.inspekt-line {
|
|
2159
|
+
display: inline-flex;
|
|
2160
|
+
align-items: baseline;
|
|
2161
|
+
padding: 0 12px 0 0;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
.inspekt-line-target {
|
|
2165
|
+
background: var(--dl-accent-dim);
|
|
2166
|
+
border-left: 2px solid var(--dl-accent);
|
|
2167
|
+
padding-left: 10px;
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
.inspekt-line:not(.inspekt-line-target) {
|
|
2171
|
+
padding-left: 12px;
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
.inspekt-line-no {
|
|
2175
|
+
display: inline-block;
|
|
2176
|
+
min-width: 30px;
|
|
2177
|
+
text-align: right;
|
|
2178
|
+
color: var(--dl-text-dim);
|
|
2179
|
+
margin-right: 10px;
|
|
2180
|
+
user-select: none;
|
|
2181
|
+
flex-shrink: 0;
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
.inspekt-line-code {
|
|
2185
|
+
white-space: pre;
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
.inspekt-snippet-skeleton,
|
|
2189
|
+
.inspekt-snippet-empty {
|
|
2190
|
+
padding: 12px;
|
|
2191
|
+
font-size: 11px;
|
|
2192
|
+
color: var(--dl-text-dim);
|
|
2193
|
+
text-align: center;
|
|
2194
|
+
font-style: italic;
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
.inspekt-popover-action {
|
|
2198
|
+
display: flex;
|
|
2199
|
+
align-items: center;
|
|
2200
|
+
justify-content: center;
|
|
2201
|
+
width: 32px;
|
|
2202
|
+
height: 32px;
|
|
2203
|
+
border: none;
|
|
2204
|
+
border-radius: 6px;
|
|
2205
|
+
background: transparent;
|
|
2206
|
+
color: var(--dl-text-dim);
|
|
2207
|
+
cursor: pointer;
|
|
2208
|
+
transition: all 0.15s ease;
|
|
2209
|
+
pointer-events: auto;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
.inspekt-popover-action:hover {
|
|
2213
|
+
background: var(--dl-bg-hover);
|
|
2214
|
+
color: var(--dl-text);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
.inspekt-popover-action:active {
|
|
2218
|
+
transform: scale(0.92);
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
.inspekt-popover-action svg {
|
|
2222
|
+
width: 16px;
|
|
2223
|
+
height: 16px;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
/* Popover toast \u2014 brief feedback after Copy / console.log actions */
|
|
2227
|
+
.inspekt-popover-toast {
|
|
2228
|
+
position: fixed;
|
|
2229
|
+
bottom: 24px;
|
|
2230
|
+
left: 50%;
|
|
2231
|
+
transform: translateX(-50%);
|
|
2232
|
+
padding: 6px 14px;
|
|
2233
|
+
background: var(--dl-text);
|
|
2234
|
+
color: var(--dl-bg);
|
|
2235
|
+
font: 500 12px/1.4 inherit;
|
|
2236
|
+
border-radius: 999px;
|
|
2237
|
+
box-shadow: var(--dl-shadow);
|
|
2238
|
+
pointer-events: none;
|
|
2239
|
+
z-index: 2147483647;
|
|
2240
|
+
animation: inspekt-toast 1.2s ease;
|
|
2241
|
+
}
|
|
2242
|
+
@keyframes inspekt-toast {
|
|
2243
|
+
0% { opacity: 0; transform: translate(-50%, 6px); }
|
|
2244
|
+
15%, 80% { opacity: 1; transform: translate(-50%, 0); }
|
|
2245
|
+
100% { opacity: 0; transform: translate(-50%, 0); }
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
/* Info badge \u2014 small pill rendered in the DOM-fallback popover header.
|
|
2249
|
+
Shows an info icon + "No source" label so users see it without hover. */
|
|
2250
|
+
.inspekt-info-badge {
|
|
2251
|
+
display: inline-flex;
|
|
2252
|
+
align-items: center;
|
|
2253
|
+
gap: 4px;
|
|
2254
|
+
padding: 2px 8px 2px 6px;
|
|
2255
|
+
border-radius: 999px;
|
|
2256
|
+
background: var(--dl-bg-hover);
|
|
2257
|
+
color: var(--dl-text-dim);
|
|
2258
|
+
font-size: 10.5px;
|
|
2259
|
+
font-weight: 500;
|
|
2260
|
+
letter-spacing: 0.01em;
|
|
2261
|
+
line-height: 1.4;
|
|
2262
|
+
cursor: help;
|
|
2263
|
+
flex-shrink: 0;
|
|
2264
|
+
margin-left: 8px;
|
|
2265
|
+
border: 1px solid var(--dl-border);
|
|
2266
|
+
text-transform: none;
|
|
2267
|
+
}
|
|
2268
|
+
.inspekt-info-badge:hover,
|
|
2269
|
+
.inspekt-info-badge:focus-visible {
|
|
2270
|
+
color: var(--dl-text);
|
|
2271
|
+
border-color: var(--dl-accent);
|
|
2272
|
+
outline: none;
|
|
2273
|
+
}
|
|
2274
|
+
.inspekt-info-badge svg { display: block; }
|
|
2275
|
+
.inspekt-info-badge-label {
|
|
2276
|
+
white-space: nowrap;
|
|
2277
|
+
}
|
|
2278
|
+
.inspekt-popover-path-dir-row {
|
|
2279
|
+
display: flex;
|
|
2280
|
+
align-items: center;
|
|
2281
|
+
gap: 4px;
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
/* Tooltip (replaces native title="") */
|
|
2285
|
+
.inspekt-tooltip {
|
|
2286
|
+
position: fixed;
|
|
2287
|
+
max-width: 280px;
|
|
2288
|
+
padding: 6px 10px;
|
|
2289
|
+
background: var(--dl-bg);
|
|
2290
|
+
color: var(--dl-text);
|
|
2291
|
+
border: 1px solid var(--dl-border);
|
|
2292
|
+
border-radius: 6px;
|
|
2293
|
+
box-shadow: var(--dl-shadow);
|
|
2294
|
+
font-size: 12px;
|
|
2295
|
+
line-height: 1.4;
|
|
2296
|
+
pointer-events: none;
|
|
2297
|
+
z-index: 2147483647;
|
|
2298
|
+
opacity: 0;
|
|
2299
|
+
animation: inspekt-tt-in 120ms ease-out forwards;
|
|
2300
|
+
}
|
|
2301
|
+
.inspekt-tooltip--rich {
|
|
2302
|
+
pointer-events: auto;
|
|
2303
|
+
max-width: 320px;
|
|
2304
|
+
padding: 10px 12px;
|
|
2305
|
+
}
|
|
2306
|
+
@keyframes inspekt-tt-in {
|
|
2307
|
+
from { opacity: 0; transform: translateY(2px); }
|
|
2308
|
+
to { opacity: 1; transform: translateY(0); }
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
/* Wider source snippet body when accordion is expanded (1.5\xD7 collapsed) */
|
|
2312
|
+
.inspekt-snippet-body[data-state='expanded'] {
|
|
2313
|
+
max-width: 900px;
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
/* Prism syntax tokens \u2014 neutral palette mapped to theme variables. */
|
|
2317
|
+
.inspekt-snippet-pre .token.comment,
|
|
2318
|
+
.inspekt-snippet-pre .token.prolog,
|
|
2319
|
+
.inspekt-snippet-pre .token.doctype,
|
|
2320
|
+
.inspekt-snippet-pre .token.cdata { color: var(--dl-text-dim); font-style: italic; }
|
|
2321
|
+
.inspekt-snippet-pre .token.punctuation { color: var(--dl-text-dim); }
|
|
2322
|
+
.inspekt-snippet-pre .token.namespace { opacity: 0.7; }
|
|
2323
|
+
.inspekt-snippet-pre .token.property,
|
|
2324
|
+
.inspekt-snippet-pre .token.tag,
|
|
2325
|
+
.inspekt-snippet-pre .token.constant,
|
|
2326
|
+
.inspekt-snippet-pre .token.symbol,
|
|
2327
|
+
.inspekt-snippet-pre .token.deleted { color: #e06c75; }
|
|
2328
|
+
.inspekt-snippet-pre .token.boolean,
|
|
2329
|
+
.inspekt-snippet-pre .token.number { color: #d19a66; }
|
|
2330
|
+
.inspekt-snippet-pre .token.selector,
|
|
2331
|
+
.inspekt-snippet-pre .token.attr-name,
|
|
2332
|
+
.inspekt-snippet-pre .token.string,
|
|
2333
|
+
.inspekt-snippet-pre .token.char,
|
|
2334
|
+
.inspekt-snippet-pre .token.builtin,
|
|
2335
|
+
.inspekt-snippet-pre .token.inserted { color: #98c379; }
|
|
2336
|
+
.inspekt-snippet-pre .token.operator,
|
|
2337
|
+
.inspekt-snippet-pre .token.entity,
|
|
2338
|
+
.inspekt-snippet-pre .token.url,
|
|
2339
|
+
.inspekt-snippet-pre .language-css .token.string,
|
|
2340
|
+
.inspekt-snippet-pre .style .token.string { color: #56b6c2; }
|
|
2341
|
+
.inspekt-snippet-pre .token.atrule,
|
|
2342
|
+
.inspekt-snippet-pre .token.attr-value,
|
|
2343
|
+
.inspekt-snippet-pre .token.keyword { color: #c678dd; }
|
|
2344
|
+
.inspekt-snippet-pre .token.function,
|
|
2345
|
+
.inspekt-snippet-pre .token.class-name { color: #61afef; }
|
|
2346
|
+
.inspekt-snippet-pre .token.regex,
|
|
2347
|
+
.inspekt-snippet-pre .token.important,
|
|
2348
|
+
.inspekt-snippet-pre .token.variable { color: #d19a66; }
|
|
2349
|
+
.inspekt-snippet-pre .token.important,
|
|
2350
|
+
.inspekt-snippet-pre .token.bold { font-weight: bold; }
|
|
2351
|
+
.inspekt-snippet-pre .token.italic { font-style: italic; }
|
|
2352
|
+
|
|
2353
|
+
/* Overlay badges */
|
|
2354
|
+
.inspekt-overlay {
|
|
2355
|
+
position: absolute;
|
|
2356
|
+
top: 0;
|
|
2357
|
+
left: 0;
|
|
2358
|
+
pointer-events: none;
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
.inspekt-badge {
|
|
2362
|
+
position: absolute;
|
|
2363
|
+
background: var(--dl-accent);
|
|
2364
|
+
color: #fff;
|
|
2365
|
+
font-size: 10px;
|
|
2366
|
+
font-weight: 600;
|
|
2367
|
+
padding: 1px 6px;
|
|
2368
|
+
border-radius: 4px;
|
|
2369
|
+
white-space: nowrap;
|
|
2370
|
+
pointer-events: auto;
|
|
2371
|
+
cursor: pointer;
|
|
2372
|
+
opacity: 0.9;
|
|
2373
|
+
transition: opacity 0.15s ease;
|
|
2374
|
+
z-index: 2147483646;
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
.inspekt-badge:hover {
|
|
2378
|
+
opacity: 1;
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
/* Pulse animation for selected highlight */
|
|
2382
|
+
@keyframes inspekt-pulse {
|
|
2383
|
+
0%, 100% { box-shadow: 0 0 0 0 var(--dl-accent-dim); }
|
|
2384
|
+
50% { box-shadow: 0 0 8px 4px var(--dl-accent-dim); }
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
/* Tree Panel */
|
|
2388
|
+
.inspekt-tree-panel {
|
|
2389
|
+
position: fixed;
|
|
2390
|
+
top: 0;
|
|
2391
|
+
height: 100vh;
|
|
2392
|
+
width: 320px;
|
|
2393
|
+
background: var(--dl-bg);
|
|
2394
|
+
border-left: 1px solid var(--dl-border);
|
|
2395
|
+
color: var(--dl-text);
|
|
2396
|
+
display: flex;
|
|
2397
|
+
flex-direction: column;
|
|
2398
|
+
pointer-events: auto;
|
|
2399
|
+
z-index: 2147483647;
|
|
2400
|
+
box-shadow: var(--dl-shadow);
|
|
2401
|
+
animation: inspekt-slide-in 0.2s ease;
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
.inspekt-tree-right { right: 0; border-left: 1px solid var(--dl-border); border-right: none; }
|
|
2405
|
+
.inspekt-tree-left { left: 0; border-right: 1px solid var(--dl-border); border-left: none; }
|
|
2406
|
+
|
|
2407
|
+
@keyframes inspekt-slide-in {
|
|
2408
|
+
from { opacity: 0; transform: translateX(20px); }
|
|
2409
|
+
to { opacity: 1; transform: translateX(0); }
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
.inspekt-tree-header {
|
|
2413
|
+
display: flex;
|
|
2414
|
+
align-items: center;
|
|
2415
|
+
justify-content: space-between;
|
|
2416
|
+
padding: 10px 12px;
|
|
2417
|
+
border-bottom: 1px solid var(--dl-border);
|
|
2418
|
+
flex-shrink: 0;
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
.inspekt-tree-title {
|
|
2422
|
+
font-weight: 600;
|
|
2423
|
+
font-size: 13px;
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
.inspekt-tree-close {
|
|
2427
|
+
display: flex;
|
|
2428
|
+
align-items: center;
|
|
2429
|
+
justify-content: center;
|
|
2430
|
+
width: 24px;
|
|
2431
|
+
height: 24px;
|
|
2432
|
+
border: none;
|
|
2433
|
+
border-radius: 4px;
|
|
2434
|
+
background: transparent;
|
|
2435
|
+
color: var(--dl-text-dim);
|
|
2436
|
+
cursor: pointer;
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
.inspekt-tree-close:hover {
|
|
2440
|
+
background: var(--dl-bg-hover);
|
|
2441
|
+
color: var(--dl-text);
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
.inspekt-tree-search {
|
|
2445
|
+
padding: 6px 12px;
|
|
2446
|
+
border-bottom: 1px solid var(--dl-border);
|
|
2447
|
+
flex-shrink: 0;
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
.inspekt-tree-search-input {
|
|
2451
|
+
width: 100%;
|
|
2452
|
+
padding: 5px 8px;
|
|
2453
|
+
border: 1px solid var(--dl-border);
|
|
2454
|
+
border-radius: 6px;
|
|
2455
|
+
background: var(--dl-bg-hover);
|
|
2456
|
+
color: var(--dl-text);
|
|
2457
|
+
font-size: 12px;
|
|
2458
|
+
outline: none;
|
|
2459
|
+
font-family: inherit;
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
.inspekt-tree-search-input:focus {
|
|
2463
|
+
border-color: var(--dl-accent);
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2466
|
+
.inspekt-tree-search-input::placeholder {
|
|
2467
|
+
color: var(--dl-text-dim);
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
.inspekt-tree-content {
|
|
2471
|
+
flex: 1;
|
|
2472
|
+
overflow-y: auto;
|
|
2473
|
+
padding: 4px 0;
|
|
2474
|
+
scrollbar-width: thin;
|
|
2475
|
+
scrollbar-color: var(--dl-border) transparent;
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
.inspekt-tree-content::-webkit-scrollbar { width: 6px; }
|
|
2479
|
+
.inspekt-tree-content::-webkit-scrollbar-thumb { background: var(--dl-border); border-radius: 3px; }
|
|
2480
|
+
|
|
2481
|
+
.inspekt-tree-node {
|
|
2482
|
+
display: flex;
|
|
2483
|
+
align-items: center;
|
|
2484
|
+
gap: 4px;
|
|
2485
|
+
padding: 3px 8px;
|
|
2486
|
+
cursor: pointer;
|
|
2487
|
+
min-height: 26px;
|
|
2488
|
+
transition: background 0.1s ease;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
.inspekt-tree-node:hover {
|
|
2492
|
+
background: var(--dl-bg-hover);
|
|
2493
|
+
}
|
|
2494
|
+
|
|
2495
|
+
.inspekt-tree-node-selected {
|
|
2496
|
+
background: var(--dl-accent-dim) !important;
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
.inspekt-tree-arrow {
|
|
2500
|
+
display: flex;
|
|
2501
|
+
align-items: center;
|
|
2502
|
+
justify-content: center;
|
|
2503
|
+
width: 14px;
|
|
2504
|
+
height: 14px;
|
|
2505
|
+
flex-shrink: 0;
|
|
2506
|
+
transition: transform 0.15s ease;
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
.inspekt-tree-arrow svg { color: var(--dl-text-dim); }
|
|
2510
|
+
|
|
2511
|
+
.inspekt-tree-arrow-expanded { transform: rotate(0deg); }
|
|
2512
|
+
.inspekt-tree-arrow-collapsed { transform: rotate(-90deg); }
|
|
2513
|
+
|
|
2514
|
+
.inspekt-tree-name {
|
|
2515
|
+
font-size: 12px;
|
|
2516
|
+
font-weight: 500;
|
|
2517
|
+
color: #c792ea;
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
:host(.inspekt-light) .inspekt-tree-name {
|
|
2521
|
+
color: #7c3aed;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
.inspekt-tree-line {
|
|
2525
|
+
font-size: 11px;
|
|
2526
|
+
color: var(--dl-text-dim);
|
|
2527
|
+
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Consolas', monospace;
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
.inspekt-tree-props {
|
|
2531
|
+
font-size: 10px;
|
|
2532
|
+
color: var(--dl-text-dim);
|
|
2533
|
+
overflow: hidden;
|
|
2534
|
+
text-overflow: ellipsis;
|
|
2535
|
+
white-space: nowrap;
|
|
2536
|
+
max-width: 120px;
|
|
2537
|
+
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Consolas', monospace;
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
.inspekt-tree-children.inspekt-tree-collapsed {
|
|
2541
|
+
display: none;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
.inspekt-tree-empty {
|
|
2545
|
+
padding: 16px;
|
|
2546
|
+
text-align: center;
|
|
2547
|
+
color: var(--dl-text-dim);
|
|
2548
|
+
font-size: 12px;
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
/* Resize handle */
|
|
2552
|
+
.inspekt-tree-resize {
|
|
2553
|
+
position: absolute;
|
|
2554
|
+
top: 0;
|
|
2555
|
+
width: 4px;
|
|
2556
|
+
height: 100%;
|
|
2557
|
+
cursor: col-resize;
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
.inspekt-tree-resize-left { left: 0; }
|
|
2561
|
+
.inspekt-tree-resize-right { right: 0; }
|
|
2562
|
+
|
|
2563
|
+
.inspekt-tree-resize:hover {
|
|
2564
|
+
background: var(--dl-accent);
|
|
2565
|
+
opacity: 0.5;
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
/* Bounding-box overlay \u2014 view mode & "Show bounding boxes" toggle */
|
|
2569
|
+
.inspekt-bbox-layer {
|
|
2570
|
+
position: fixed;
|
|
2571
|
+
inset: 0;
|
|
2572
|
+
pointer-events: none;
|
|
2573
|
+
z-index: 2147483646;
|
|
2574
|
+
}
|
|
2575
|
+
.inspekt-bbox {
|
|
2576
|
+
position: fixed;
|
|
2577
|
+
top: 0;
|
|
2578
|
+
left: 0;
|
|
2579
|
+
box-sizing: border-box;
|
|
2580
|
+
border: 1.5px dashed var(--dl-accent, oklch(0.62 0.18 285));
|
|
2581
|
+
background: oklch(0.62 0.18 285 / 0.05);
|
|
2582
|
+
pointer-events: none;
|
|
2583
|
+
will-change: transform, width, height;
|
|
2584
|
+
border-radius: 2px;
|
|
2585
|
+
}
|
|
2586
|
+
.inspekt-bbox-label {
|
|
2587
|
+
position: absolute;
|
|
2588
|
+
top: -18px;
|
|
2589
|
+
left: 0;
|
|
2590
|
+
font: 500 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
2591
|
+
color: #fff;
|
|
2592
|
+
background: var(--dl-accent, oklch(0.55 0.18 285));
|
|
2593
|
+
padding: 2px 5px;
|
|
2594
|
+
border-radius: 3px 3px 3px 0;
|
|
2595
|
+
white-space: nowrap;
|
|
2596
|
+
pointer-events: none;
|
|
2597
|
+
max-width: 280px;
|
|
2598
|
+
overflow: hidden;
|
|
2599
|
+
text-overflow: ellipsis;
|
|
2600
|
+
}
|
|
2601
|
+
`
|
|
2602
|
+
);
|
|
2603
|
+
|
|
2604
|
+
// src/components/rich-select.ts
|
|
2605
|
+
import {
|
|
2606
|
+
autoUpdate as autoUpdate2,
|
|
2607
|
+
computePosition as computePosition2,
|
|
2608
|
+
flip as flip2,
|
|
2609
|
+
offset as offset2,
|
|
2610
|
+
shift as shift2,
|
|
2611
|
+
size
|
|
2612
|
+
} from "@floating-ui/dom";
|
|
2613
|
+
function createRichSelect(opts) {
|
|
2614
|
+
let current = opts.value;
|
|
2615
|
+
let listEl = null;
|
|
2616
|
+
let activeIndex = -1;
|
|
2617
|
+
let cleanupAutoUpdate = null;
|
|
2618
|
+
const tooltipDetachers = [];
|
|
2619
|
+
const trigger = document.createElement("button");
|
|
2620
|
+
trigger.type = "button";
|
|
2621
|
+
trigger.className = "inspekt-rich-select-trigger";
|
|
2622
|
+
trigger.setAttribute("aria-haspopup", "listbox");
|
|
2623
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
2624
|
+
if (opts.ariaLabel) trigger.setAttribute("aria-label", opts.ariaLabel);
|
|
2625
|
+
opts.anchor.replaceChildren(trigger);
|
|
2626
|
+
renderTrigger();
|
|
2627
|
+
trigger.addEventListener("click", (e) => {
|
|
2628
|
+
e.preventDefault();
|
|
2629
|
+
if (listEl) close();
|
|
2630
|
+
else open();
|
|
2631
|
+
});
|
|
2632
|
+
trigger.addEventListener("keydown", (e) => {
|
|
2633
|
+
if (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") {
|
|
2634
|
+
e.preventDefault();
|
|
2635
|
+
open();
|
|
2636
|
+
}
|
|
2637
|
+
});
|
|
2638
|
+
function renderTrigger() {
|
|
2639
|
+
trigger.innerHTML = "";
|
|
2640
|
+
const item = opts.items.find((i) => i.value === current) ?? opts.items[0];
|
|
2641
|
+
if (!item) return;
|
|
2642
|
+
trigger.appendChild(renderIcon(item));
|
|
2643
|
+
const labelEl = document.createElement("span");
|
|
2644
|
+
labelEl.className = "rs-label";
|
|
2645
|
+
labelEl.textContent = item.label;
|
|
2646
|
+
trigger.appendChild(labelEl);
|
|
2647
|
+
}
|
|
2648
|
+
function renderIcon(item) {
|
|
2649
|
+
if (item.icon) {
|
|
2650
|
+
if (/^<svg|^<\?xml/.test(item.icon.trim())) {
|
|
2651
|
+
const wrap = document.createElement("span");
|
|
2652
|
+
wrap.className = "rs-icon";
|
|
2653
|
+
wrap.innerHTML = item.icon;
|
|
2654
|
+
return wrap;
|
|
2655
|
+
}
|
|
2656
|
+
const img = document.createElement("img");
|
|
2657
|
+
img.className = "rs-icon";
|
|
2658
|
+
img.src = item.icon;
|
|
2659
|
+
img.alt = "";
|
|
2660
|
+
return img;
|
|
2661
|
+
}
|
|
2662
|
+
const tile = document.createElement("span");
|
|
2663
|
+
tile.className = "inspekt-rich-select-item-letter";
|
|
2664
|
+
tile.textContent = (item.label[0] ?? "?").toUpperCase();
|
|
2665
|
+
return tile;
|
|
2666
|
+
}
|
|
2667
|
+
function open() {
|
|
2668
|
+
if (listEl) return;
|
|
2669
|
+
listEl = document.createElement("div");
|
|
2670
|
+
listEl.className = "inspekt-rich-select-list";
|
|
2671
|
+
listEl.setAttribute("role", "listbox");
|
|
2672
|
+
let lastGroup;
|
|
2673
|
+
opts.items.forEach((item, i) => {
|
|
2674
|
+
if (item.group && item.group !== lastGroup) {
|
|
2675
|
+
const header = document.createElement("div");
|
|
2676
|
+
header.className = "inspekt-rich-select-group-header";
|
|
2677
|
+
header.setAttribute("role", "presentation");
|
|
2678
|
+
header.textContent = item.group;
|
|
2679
|
+
listEl.appendChild(header);
|
|
2680
|
+
}
|
|
2681
|
+
lastGroup = item.group;
|
|
2682
|
+
const row = document.createElement("div");
|
|
2683
|
+
row.className = "inspekt-rich-select-item";
|
|
2684
|
+
if (item.action) row.classList.add("inspekt-rich-select-item-action");
|
|
2685
|
+
row.setAttribute("role", "option");
|
|
2686
|
+
row.dataset["value"] = item.value;
|
|
2687
|
+
if (!item.action && item.value === current) row.dataset["selected"] = "true";
|
|
2688
|
+
row.appendChild(renderIcon(item));
|
|
2689
|
+
const body = document.createElement("div");
|
|
2690
|
+
body.className = "inspekt-rich-select-item-body";
|
|
2691
|
+
const labelEl = document.createElement("span");
|
|
2692
|
+
labelEl.className = "inspekt-rich-select-item-label";
|
|
2693
|
+
labelEl.textContent = item.label;
|
|
2694
|
+
body.appendChild(labelEl);
|
|
2695
|
+
if (item.hint) {
|
|
2696
|
+
const hintEl = document.createElement("span");
|
|
2697
|
+
hintEl.className = "inspekt-rich-select-item-hint";
|
|
2698
|
+
hintEl.textContent = item.hint;
|
|
2699
|
+
body.appendChild(hintEl);
|
|
2700
|
+
}
|
|
2701
|
+
row.appendChild(body);
|
|
2702
|
+
row.addEventListener("mouseenter", () => setActive(i));
|
|
2703
|
+
row.addEventListener("click", (e) => {
|
|
2704
|
+
e.preventDefault();
|
|
2705
|
+
e.stopPropagation();
|
|
2706
|
+
if (item.action) {
|
|
2707
|
+
close();
|
|
2708
|
+
item.action();
|
|
2709
|
+
return;
|
|
2710
|
+
}
|
|
2711
|
+
select(item.value);
|
|
2712
|
+
});
|
|
2713
|
+
if (item.popover) {
|
|
2714
|
+
tooltipDetachers.push(
|
|
2715
|
+
attachTooltip(row, item.popover(), {
|
|
2716
|
+
enterDelay: opts.popoverDelay ?? 50,
|
|
2717
|
+
leaveDelay: 200,
|
|
2718
|
+
placement: opts.popoverPlacement ?? "top"
|
|
2719
|
+
})
|
|
2720
|
+
);
|
|
2721
|
+
}
|
|
2722
|
+
listEl.appendChild(row);
|
|
2723
|
+
});
|
|
2724
|
+
listEl.style.position = "fixed";
|
|
2725
|
+
listEl.style.top = "0";
|
|
2726
|
+
listEl.style.left = "0";
|
|
2727
|
+
document.body.appendChild(listEl);
|
|
2728
|
+
cleanupAutoUpdate = autoUpdate2(trigger, listEl, updateListPosition);
|
|
2729
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
2730
|
+
setActive(opts.items.findIndex((i) => i.value === current));
|
|
2731
|
+
document.addEventListener("mousedown", onOutside, true);
|
|
2732
|
+
document.addEventListener("keydown", onKey, true);
|
|
2733
|
+
}
|
|
2734
|
+
function close() {
|
|
2735
|
+
if (!listEl) return;
|
|
2736
|
+
for (const d of tooltipDetachers) d();
|
|
2737
|
+
tooltipDetachers.length = 0;
|
|
2738
|
+
cleanupAutoUpdate?.();
|
|
2739
|
+
cleanupAutoUpdate = null;
|
|
2740
|
+
listEl.remove();
|
|
2741
|
+
listEl = null;
|
|
2742
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
2743
|
+
document.removeEventListener("mousedown", onOutside, true);
|
|
2744
|
+
document.removeEventListener("keydown", onKey, true);
|
|
2745
|
+
}
|
|
2746
|
+
function updateListPosition() {
|
|
2747
|
+
if (!listEl) return;
|
|
2748
|
+
const list = listEl;
|
|
2749
|
+
const triggerWidth = trigger.getBoundingClientRect().width;
|
|
2750
|
+
list.style.minWidth = `${triggerWidth}px`;
|
|
2751
|
+
void computePosition2(trigger, list, {
|
|
2752
|
+
placement: "bottom-start",
|
|
2753
|
+
strategy: "fixed",
|
|
2754
|
+
middleware: [
|
|
2755
|
+
offset2(4),
|
|
2756
|
+
flip2(),
|
|
2757
|
+
shift2({ padding: 8 }),
|
|
2758
|
+
size({
|
|
2759
|
+
apply({ availableHeight }) {
|
|
2760
|
+
list.style.maxHeight = `${Math.max(160, availableHeight - 8)}px`;
|
|
2761
|
+
},
|
|
2762
|
+
padding: 8
|
|
2763
|
+
})
|
|
2764
|
+
]
|
|
2765
|
+
}).then(({ x, y }) => {
|
|
2766
|
+
list.style.left = `${Math.round(x)}px`;
|
|
2767
|
+
list.style.top = `${Math.round(y)}px`;
|
|
2768
|
+
});
|
|
2769
|
+
}
|
|
2770
|
+
function setActive(i) {
|
|
2771
|
+
if (!listEl) return;
|
|
2772
|
+
activeIndex = i;
|
|
2773
|
+
const rows = listEl.querySelectorAll(".inspekt-rich-select-item");
|
|
2774
|
+
rows.forEach((r, idx) => {
|
|
2775
|
+
if (idx === i) r.dataset["active"] = "true";
|
|
2776
|
+
else delete r.dataset["active"];
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
function select(value) {
|
|
2780
|
+
if (value !== current) {
|
|
2781
|
+
current = value;
|
|
2782
|
+
renderTrigger();
|
|
2783
|
+
opts.onChange(value);
|
|
2784
|
+
}
|
|
2785
|
+
close();
|
|
2786
|
+
}
|
|
2787
|
+
function onOutside(e) {
|
|
2788
|
+
const t = e.target;
|
|
2789
|
+
if (listEl?.contains(t) || trigger.contains(t)) return;
|
|
2790
|
+
if (t instanceof Element && t.closest(".inspekt-tooltip")) {
|
|
2791
|
+
setTimeout(close, 0);
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
close();
|
|
2795
|
+
}
|
|
2796
|
+
function onKey(e) {
|
|
2797
|
+
if (!listEl) return;
|
|
2798
|
+
if (e.key === "Escape") {
|
|
2799
|
+
e.preventDefault();
|
|
2800
|
+
close();
|
|
2801
|
+
trigger.focus();
|
|
2802
|
+
return;
|
|
2803
|
+
}
|
|
2804
|
+
if (e.key === "ArrowDown") {
|
|
2805
|
+
e.preventDefault();
|
|
2806
|
+
setActive(Math.min(opts.items.length - 1, activeIndex + 1));
|
|
2807
|
+
return;
|
|
2808
|
+
}
|
|
2809
|
+
if (e.key === "ArrowUp") {
|
|
2810
|
+
e.preventDefault();
|
|
2811
|
+
setActive(Math.max(0, activeIndex - 1));
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2814
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2815
|
+
e.preventDefault();
|
|
2816
|
+
const item = opts.items[activeIndex];
|
|
2817
|
+
if (!item) return;
|
|
2818
|
+
if (item.action) {
|
|
2819
|
+
close();
|
|
2820
|
+
item.action();
|
|
2821
|
+
} else {
|
|
2822
|
+
select(item.value);
|
|
2823
|
+
}
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2826
|
+
if (e.key.length === 1) {
|
|
2827
|
+
const ch = e.key.toLowerCase();
|
|
2828
|
+
const next = opts.items.findIndex((it) => it.label.toLowerCase().startsWith(ch));
|
|
2829
|
+
if (next >= 0) setActive(next);
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
return {
|
|
2833
|
+
setValue(value) {
|
|
2834
|
+
current = value;
|
|
2835
|
+
renderTrigger();
|
|
2836
|
+
},
|
|
2837
|
+
getValue() {
|
|
2838
|
+
return current;
|
|
2839
|
+
},
|
|
2840
|
+
destroy() {
|
|
2841
|
+
close();
|
|
2842
|
+
trigger.remove();
|
|
2843
|
+
}
|
|
2844
|
+
};
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
// src/index.ts
|
|
2848
|
+
var DEFAULT_OPTIONS = {
|
|
2849
|
+
// Default preserves the legacy click-mod behavior: page interactions never
|
|
2850
|
+
// intercepted unless Ctrl+Alt is held. Empty array = always-on hover.
|
|
2851
|
+
requireModifiers: ["ctrl", "alt"],
|
|
2852
|
+
showBoundingBoxes: false,
|
|
2853
|
+
shortcut: { key: "click", modifiers: ["ctrl", "alt"] },
|
|
2854
|
+
toggleShortcut: { key: "i", modifiers: ["ctrl", "alt"] },
|
|
2855
|
+
theme: "auto",
|
|
2856
|
+
highlight: {
|
|
2857
|
+
color: "#3b82f6",
|
|
2858
|
+
style: "glow",
|
|
2859
|
+
animation: "pulse"
|
|
2860
|
+
},
|
|
2861
|
+
badge: {
|
|
2862
|
+
show: true,
|
|
2863
|
+
position: "auto",
|
|
2864
|
+
showPath: false
|
|
2865
|
+
},
|
|
2866
|
+
borders: false,
|
|
2867
|
+
actions: ["open-editor", "copy-path", "open-github", "console-log"],
|
|
2868
|
+
editor: "cursor",
|
|
2869
|
+
editorPathBase: "",
|
|
2870
|
+
githubRepo: "",
|
|
2871
|
+
githubBranch: "main",
|
|
2872
|
+
pathMapping: {},
|
|
2873
|
+
treePanel: {
|
|
2874
|
+
enabled: true,
|
|
2875
|
+
position: "right",
|
|
2876
|
+
showProps: true,
|
|
2877
|
+
showLineNumbers: true
|
|
2878
|
+
},
|
|
2879
|
+
sourceAttribute: "data-insp-path",
|
|
2880
|
+
serverUrl: "",
|
|
2881
|
+
defaultSnippetExpanded: false,
|
|
2882
|
+
snippetContext: 5,
|
|
2883
|
+
sourceMapEnabled: false,
|
|
2884
|
+
customEditors: []
|
|
2885
|
+
};
|
|
2886
|
+
function createInspekt(userOptions = {}) {
|
|
2887
|
+
const options = { ...DEFAULT_OPTIONS, ...userOptions };
|
|
2888
|
+
let capabilityTeardown = null;
|
|
2889
|
+
if (userOptions.highlight) options.highlight = { ...DEFAULT_OPTIONS.highlight, ...userOptions.highlight };
|
|
2890
|
+
if (userOptions.badge) options.badge = { ...DEFAULT_OPTIONS.badge, ...userOptions.badge };
|
|
2891
|
+
if (userOptions.treePanel) options.treePanel = { ...DEFAULT_OPTIONS.treePanel, ...userOptions.treePanel };
|
|
2892
|
+
if (userOptions.shortcut) options.shortcut = { ...DEFAULT_OPTIONS.shortcut, ...userOptions.shortcut };
|
|
2893
|
+
if (userOptions.toggleShortcut) options.toggleShortcut = { ...DEFAULT_OPTIONS.toggleShortcut, ...userOptions.toggleShortcut };
|
|
2894
|
+
let enabled = false;
|
|
2895
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
2896
|
+
const customActions = /* @__PURE__ */ new Map();
|
|
2897
|
+
const host = document.createElement("inspekt-root");
|
|
2898
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
2899
|
+
const style = document.createElement("style");
|
|
2900
|
+
style.textContent = STYLES;
|
|
2901
|
+
shadow.appendChild(style);
|
|
2902
|
+
applyTheme(host, options.theme);
|
|
2903
|
+
const highlighter = new Highlighter(options.highlight);
|
|
2904
|
+
const popover = new Popover(shadow);
|
|
2905
|
+
popover.configureSnippet({
|
|
2906
|
+
serverUrl: options.serverUrl || void 0,
|
|
2907
|
+
context: options.snippetContext,
|
|
2908
|
+
defaultExpanded: options.defaultSnippetExpanded,
|
|
2909
|
+
sourceMapEnabled: options.sourceMapEnabled,
|
|
2910
|
+
staticSnippets: options.staticSnippets
|
|
2911
|
+
});
|
|
2912
|
+
const overlay = new Overlay(shadow);
|
|
2913
|
+
const bboxOverlay = new BoundingBoxOverlay(shadow);
|
|
2914
|
+
const adapter = detectAdapter();
|
|
2915
|
+
let treePanel = null;
|
|
2916
|
+
if (options.treePanel.enabled) {
|
|
2917
|
+
treePanel = new TreePanel(shadow, {
|
|
2918
|
+
position: options.treePanel.position,
|
|
2919
|
+
showProps: options.treePanel.showProps,
|
|
2920
|
+
showLineNumbers: options.treePanel.showLineNumbers,
|
|
2921
|
+
onSelect(node) {
|
|
2922
|
+
if (node.domElement) {
|
|
2923
|
+
highlighter.unhighlightAll();
|
|
2924
|
+
highlighter.highlight(node.domElement, "selected");
|
|
2925
|
+
node.domElement.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
2926
|
+
}
|
|
2927
|
+
emit("tree-select", node);
|
|
2928
|
+
},
|
|
2929
|
+
onHover(node) {
|
|
2930
|
+
highlighter.unhighlightAll();
|
|
2931
|
+
if (node?.domElement) {
|
|
2932
|
+
highlighter.highlight(node.domElement, "hovered");
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
});
|
|
2936
|
+
}
|
|
2937
|
+
function refreshTree() {
|
|
2938
|
+
if (!treePanel) return;
|
|
2939
|
+
const root = document.getElementById("root") ?? document.getElementById("app") ?? document.body;
|
|
2940
|
+
const tree = adapter.getComponentTree(root);
|
|
2941
|
+
treePanel.updateTree(tree);
|
|
2942
|
+
}
|
|
2943
|
+
function getActions() {
|
|
2944
|
+
const builtInMap = {
|
|
2945
|
+
"open-editor": () => createOpenEditorAction(options.serverUrl, options.editor, options.customEditors),
|
|
2946
|
+
"copy-path": () => createCopyPathAction(),
|
|
2947
|
+
"open-github": () => createOpenGithubAction(options.githubRepo, options.githubBranch),
|
|
2948
|
+
"console-log": () => createConsoleLogAction()
|
|
2949
|
+
};
|
|
2950
|
+
const result = [];
|
|
2951
|
+
for (const id of options.actions) {
|
|
2952
|
+
const factory = builtInMap[id];
|
|
2953
|
+
if (factory) {
|
|
2954
|
+
result.push(factory());
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
for (const action of customActions.values()) {
|
|
2958
|
+
result.push(action);
|
|
2959
|
+
}
|
|
2960
|
+
return result;
|
|
2961
|
+
}
|
|
2962
|
+
function modifiersOk(e) {
|
|
2963
|
+
return options.requireModifiers.every((mod) => {
|
|
2964
|
+
switch (mod) {
|
|
2965
|
+
case "ctrl":
|
|
2966
|
+
return e.ctrlKey || e.metaKey;
|
|
2967
|
+
case "alt":
|
|
2968
|
+
return e.altKey;
|
|
2969
|
+
case "shift":
|
|
2970
|
+
return e.shiftKey;
|
|
2971
|
+
case "meta":
|
|
2972
|
+
return e.metaKey;
|
|
2973
|
+
}
|
|
2974
|
+
});
|
|
2975
|
+
}
|
|
2976
|
+
function handleClick(e) {
|
|
2977
|
+
if (!enabled) return;
|
|
2978
|
+
const clickTarget = e.target;
|
|
2979
|
+
const isInsideInspekt = clickTarget?.tagName === "INSPEKT-ROOT";
|
|
2980
|
+
if (popover.isPinned() && !isInsideInspekt) {
|
|
2981
|
+
popover.unpin();
|
|
2982
|
+
popover.hide();
|
|
2983
|
+
highlighter.unhighlightAll();
|
|
2984
|
+
}
|
|
2985
|
+
if (e.shiftKey && e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
2986
|
+
e.preventDefault();
|
|
2987
|
+
e.stopPropagation();
|
|
2988
|
+
const target2 = e.target;
|
|
2989
|
+
const result2 = findClosestSource(target2);
|
|
2990
|
+
if (result2) {
|
|
2991
|
+
const inspected = elementToInspected(result2.element, result2.source, options.pathMapping);
|
|
2992
|
+
const editorAction = getActions().find((a) => a.id === "open-editor");
|
|
2993
|
+
if (editorAction) editorAction.handler(inspected);
|
|
2994
|
+
emit("action", "open-editor", inspected);
|
|
2995
|
+
}
|
|
2996
|
+
return;
|
|
2997
|
+
}
|
|
2998
|
+
if (!modifiersOk(e)) return;
|
|
2999
|
+
const target = e.target;
|
|
3000
|
+
const result = findClosestSource(target);
|
|
3001
|
+
const isFallback = !result && isFallbackTarget(target);
|
|
3002
|
+
if (!result && !isFallback) return;
|
|
3003
|
+
e.preventDefault();
|
|
3004
|
+
e.stopPropagation();
|
|
3005
|
+
if (result) {
|
|
3006
|
+
const inspected = elementToInspected(result.element, result.source, options.pathMapping);
|
|
3007
|
+
highlighter.unhighlightAll();
|
|
3008
|
+
highlighter.highlight(result.element, "selected");
|
|
3009
|
+
popover.show(inspected, getActions(), { x: e.clientX, y: e.clientY });
|
|
3010
|
+
popover.pin();
|
|
3011
|
+
treePanel?.selectElement(inspected);
|
|
3012
|
+
emit("inspect", inspected);
|
|
3013
|
+
} else if (isFallback) {
|
|
3014
|
+
showDomFallback(target, e.clientX, e.clientY);
|
|
3015
|
+
popover.pin();
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
function showDomFallback(el, x, y) {
|
|
3019
|
+
highlighter.unhighlightAll();
|
|
3020
|
+
highlighter.highlight(el, "selected");
|
|
3021
|
+
popover.showDom(
|
|
3022
|
+
el,
|
|
3023
|
+
{ x, y },
|
|
3024
|
+
async (selector) => copyToClipboard(selector),
|
|
3025
|
+
async (html) => copyToClipboard(html),
|
|
3026
|
+
() => {
|
|
3027
|
+
console.log("[Inspekt]", el);
|
|
3028
|
+
}
|
|
3029
|
+
);
|
|
3030
|
+
}
|
|
3031
|
+
async function copyToClipboard(text) {
|
|
3032
|
+
if (navigator.clipboard?.writeText) {
|
|
3033
|
+
try {
|
|
3034
|
+
await navigator.clipboard.writeText(text);
|
|
3035
|
+
return true;
|
|
3036
|
+
} catch {
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
try {
|
|
3040
|
+
const ta = document.createElement("textarea");
|
|
3041
|
+
ta.value = text;
|
|
3042
|
+
ta.style.cssText = "position:fixed;top:-1000px;left:-1000px;opacity:0;pointer-events:none;";
|
|
3043
|
+
document.body.appendChild(ta);
|
|
3044
|
+
ta.focus();
|
|
3045
|
+
ta.select();
|
|
3046
|
+
const ok = document.execCommand("copy");
|
|
3047
|
+
ta.remove();
|
|
3048
|
+
return ok;
|
|
3049
|
+
} catch {
|
|
3050
|
+
return false;
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
function handleKeydown(e) {
|
|
3054
|
+
if (matchesShortcut(e, options.toggleShortcut)) {
|
|
3055
|
+
e.preventDefault();
|
|
3056
|
+
instance.toggle();
|
|
3057
|
+
return;
|
|
3058
|
+
}
|
|
3059
|
+
if (e.key === "Escape" && popover.isVisible()) {
|
|
3060
|
+
popover.unpin();
|
|
3061
|
+
popover.hide();
|
|
3062
|
+
highlighter.unhighlightAll();
|
|
3063
|
+
}
|
|
3064
|
+
if (e.key === "o" && e.ctrlKey && e.altKey) {
|
|
3065
|
+
e.preventDefault();
|
|
3066
|
+
overlay.toggle();
|
|
3067
|
+
}
|
|
3068
|
+
if (e.key === "t" && e.ctrlKey && e.altKey) {
|
|
3069
|
+
e.preventDefault();
|
|
3070
|
+
if (treePanel) {
|
|
3071
|
+
treePanel.toggle();
|
|
3072
|
+
if (treePanel.isVisible()) refreshTree();
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
function matchesShortcut(e, shortcut) {
|
|
3077
|
+
if (e.key.toLowerCase() !== shortcut.key.toLowerCase()) return false;
|
|
3078
|
+
const needCtrl = shortcut.modifiers.includes("ctrl");
|
|
3079
|
+
const needAlt = shortcut.modifiers.includes("alt");
|
|
3080
|
+
const needShift = shortcut.modifiers.includes("shift");
|
|
3081
|
+
const needMeta = shortcut.modifiers.includes("meta");
|
|
3082
|
+
return (needCtrl ? e.ctrlKey || e.metaKey : true) && (needAlt ? e.altKey : true) && (needShift ? e.shiftKey : true) && (needMeta ? e.metaKey : true);
|
|
3083
|
+
}
|
|
3084
|
+
function handleMouseMove(e) {
|
|
3085
|
+
if (!enabled) return;
|
|
3086
|
+
if (popover.isPinned()) return;
|
|
3087
|
+
if (!modifiersOk(e)) {
|
|
3088
|
+
highlighter.unhighlightAll();
|
|
3089
|
+
popover.hide();
|
|
3090
|
+
return;
|
|
3091
|
+
}
|
|
3092
|
+
const target = e.target;
|
|
3093
|
+
const result = findClosestSource(target);
|
|
3094
|
+
highlighter.unhighlightAll();
|
|
3095
|
+
if (result) {
|
|
3096
|
+
highlighter.highlight(result.element, "selected");
|
|
3097
|
+
const inspected = elementToInspected(result.element, result.source, options.pathMapping);
|
|
3098
|
+
popover.show(inspected, getActions(), { x: e.clientX, y: e.clientY });
|
|
3099
|
+
treePanel?.selectElement(inspected);
|
|
3100
|
+
emit("inspect", inspected);
|
|
3101
|
+
} else if (isFallbackTarget(target)) {
|
|
3102
|
+
showDomFallback(target, e.clientX, e.clientY);
|
|
3103
|
+
} else {
|
|
3104
|
+
popover.hide();
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
function isFallbackTarget(el) {
|
|
3108
|
+
if (!el) return false;
|
|
3109
|
+
if (el === document.body || el === document.documentElement) return false;
|
|
3110
|
+
if (el.tagName === "INSPEKT-ROOT") return false;
|
|
3111
|
+
return true;
|
|
3112
|
+
}
|
|
3113
|
+
function emit(event, ...args) {
|
|
3114
|
+
const handlers = listeners.get(event);
|
|
3115
|
+
if (handlers) {
|
|
3116
|
+
for (const handler of handlers) {
|
|
3117
|
+
handler(...args);
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
function applyTheme(el, theme) {
|
|
3122
|
+
el.classList.remove("inspekt-light", "inspekt-dark");
|
|
3123
|
+
if (theme === "auto") {
|
|
3124
|
+
const isDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
3125
|
+
if (!isDark) el.classList.add("inspekt-light");
|
|
3126
|
+
} else if (theme === "light") {
|
|
3127
|
+
el.classList.add("inspekt-light");
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
3131
|
+
const themeHandler = () => applyTheme(host, options.theme);
|
|
3132
|
+
mediaQuery.addEventListener("change", themeHandler);
|
|
3133
|
+
document.addEventListener("inspekt:settings-update", ((e) => {
|
|
3134
|
+
const newSettings = e.detail;
|
|
3135
|
+
Object.assign(options, newSettings);
|
|
3136
|
+
if (newSettings.highlight) highlighter.updateConfig(options.highlight);
|
|
3137
|
+
applyTheme(host, options.theme);
|
|
3138
|
+
if (enabled) {
|
|
3139
|
+
if (options.showBoundingBoxes === true) bboxOverlay.enable();
|
|
3140
|
+
else bboxOverlay.disable();
|
|
3141
|
+
}
|
|
3142
|
+
}));
|
|
3143
|
+
const instance = {
|
|
3144
|
+
enable() {
|
|
3145
|
+
if (enabled) return;
|
|
3146
|
+
enabled = true;
|
|
3147
|
+
document.body.appendChild(host);
|
|
3148
|
+
document.addEventListener("click", handleClick, true);
|
|
3149
|
+
document.addEventListener("keydown", handleKeydown, true);
|
|
3150
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
3151
|
+
window.__INSPEKT__ = { version: "0.1.0", options };
|
|
3152
|
+
document.dispatchEvent(new CustomEvent("inspekt:status", { detail: { enabled: true } }));
|
|
3153
|
+
void import("./capability-probe-AKVKYSDE.js").then(({ watchCapabilities }) => {
|
|
3154
|
+
if (!enabled) return;
|
|
3155
|
+
capabilityTeardown = watchCapabilities({
|
|
3156
|
+
serverUrl: options.serverUrl || void 0,
|
|
3157
|
+
sourceMapEnabled: options.sourceMapEnabled
|
|
3158
|
+
});
|
|
3159
|
+
});
|
|
3160
|
+
if (treePanel && options.treePanel.enabled) {
|
|
3161
|
+
setTimeout(() => refreshTree(), 100);
|
|
3162
|
+
}
|
|
3163
|
+
if (options.showBoundingBoxes) {
|
|
3164
|
+
bboxOverlay.enable();
|
|
3165
|
+
}
|
|
3166
|
+
emit("enable");
|
|
3167
|
+
},
|
|
3168
|
+
disable() {
|
|
3169
|
+
if (!enabled) return;
|
|
3170
|
+
enabled = false;
|
|
3171
|
+
popover.hide();
|
|
3172
|
+
overlay.hide();
|
|
3173
|
+
treePanel?.hide();
|
|
3174
|
+
bboxOverlay.disable();
|
|
3175
|
+
highlighter.unhighlightAll();
|
|
3176
|
+
capabilityTeardown?.();
|
|
3177
|
+
capabilityTeardown = null;
|
|
3178
|
+
document.removeEventListener("click", handleClick, true);
|
|
3179
|
+
document.removeEventListener("keydown", handleKeydown, true);
|
|
3180
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
3181
|
+
host.remove();
|
|
3182
|
+
document.dispatchEvent(new CustomEvent("inspekt:status", { detail: { enabled: false } }));
|
|
3183
|
+
emit("disable");
|
|
3184
|
+
},
|
|
3185
|
+
toggle() {
|
|
3186
|
+
if (enabled) instance.disable();
|
|
3187
|
+
else instance.enable();
|
|
3188
|
+
},
|
|
3189
|
+
destroy() {
|
|
3190
|
+
instance.disable();
|
|
3191
|
+
popover.destroy();
|
|
3192
|
+
overlay.destroy();
|
|
3193
|
+
treePanel?.destroy();
|
|
3194
|
+
bboxOverlay.destroy();
|
|
3195
|
+
mediaQuery.removeEventListener("change", themeHandler);
|
|
3196
|
+
listeners.clear();
|
|
3197
|
+
customActions.clear();
|
|
3198
|
+
delete window.__INSPEKT__;
|
|
3199
|
+
},
|
|
3200
|
+
registerAction(action) {
|
|
3201
|
+
customActions.set(action.id, action);
|
|
3202
|
+
},
|
|
3203
|
+
unregisterAction(id) {
|
|
3204
|
+
customActions.delete(id);
|
|
3205
|
+
},
|
|
3206
|
+
on(event, handler) {
|
|
3207
|
+
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
3208
|
+
listeners.get(event).add(handler);
|
|
3209
|
+
},
|
|
3210
|
+
off(event, handler) {
|
|
3211
|
+
listeners.get(event)?.delete(handler);
|
|
3212
|
+
}
|
|
3213
|
+
};
|
|
3214
|
+
return instance;
|
|
3215
|
+
}
|
|
3216
|
+
export {
|
|
3217
|
+
attachTooltip,
|
|
3218
|
+
createInspekt,
|
|
3219
|
+
createRichSelect,
|
|
3220
|
+
tokenizeToLines
|
|
3221
|
+
};
|
|
3222
|
+
//# sourceMappingURL=index.js.map
|