@archie/devtools 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -13
- package/dist/chunk-6MYORGLK.mjs +21 -0
- package/dist/{client.mjs → chunk-EQV632XF.mjs} +25 -14
- package/dist/chunk-NYVHR4QL.mjs +74 -0
- package/dist/client/client.d.mts +2 -0
- package/dist/client/client.d.ts +2 -0
- package/dist/{client.js → client/client.js} +26 -14
- package/dist/client/client.mjs +6 -0
- package/dist/client/inject-inspector/auto.d.mts +2 -0
- package/dist/client/inject-inspector/auto.d.ts +2 -0
- package/dist/client/inject-inspector/auto.js +1197 -0
- package/dist/client/inject-inspector/auto.mjs +7 -0
- package/dist/client/inject-inspector/injectInspector.d.mts +33 -0
- package/dist/client/inject-inspector/injectInspector.d.ts +33 -0
- package/dist/client/inject-inspector/injectInspector.js +1216 -0
- package/dist/client/inject-inspector/injectInspector.mjs +7 -0
- package/dist/client/route-listener/routeListener.js +90 -0
- package/dist/client/route-listener/routeListener.mjs +6 -0
- package/dist/constants/archieOrigins.d.mts +24 -0
- package/dist/constants/archieOrigins.d.ts +24 -0
- package/dist/constants/archieOrigins.js +47 -0
- package/dist/constants/archieOrigins.mjs +10 -0
- package/dist/inspector-LTHUYUGW.mjs +1094 -0
- package/package.json +21 -7
- package/dist/{client.d.mts → client/route-listener/routeListener.d.mts} +19 -19
- package/dist/{client.d.ts → client/route-listener/routeListener.d.ts} +19 -19
|
@@ -0,0 +1,1094 @@
|
|
|
1
|
+
// src/client/inject-inspector/inspector.js
|
|
2
|
+
function runInspector() {
|
|
3
|
+
;
|
|
4
|
+
(function() {
|
|
5
|
+
"use strict";
|
|
6
|
+
if (window._inspectorQuerySelectorProtected) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
window._inspectorQuerySelectorProtected = true;
|
|
10
|
+
const originalQuerySelector = document.querySelector.bind(document);
|
|
11
|
+
const originalQuerySelectorAll = document.querySelectorAll.bind(document);
|
|
12
|
+
var PROBLEMATIC_SELECTOR_PATTERNS = [
|
|
13
|
+
/\/\d+/,
|
|
14
|
+
/\[backdrop-filter\]/,
|
|
15
|
+
/supports-\[/,
|
|
16
|
+
/:\d+\.\d+/,
|
|
17
|
+
/\.bg-background\/\d+/,
|
|
18
|
+
/\.supports-\[backdrop-filter\]/,
|
|
19
|
+
/bg-background\/\d+/,
|
|
20
|
+
/supports-\[/
|
|
21
|
+
];
|
|
22
|
+
function isProblematicSelector(selector) {
|
|
23
|
+
if (!selector || typeof selector !== "string") return false;
|
|
24
|
+
return PROBLEMATIC_SELECTOR_PATTERNS.some(function(p) {
|
|
25
|
+
return p.test(selector);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function isSelectorSyntaxError(e) {
|
|
29
|
+
return e && (e.name === "SyntaxError" || e.message && (e.message.includes("not a valid selector") || e.message.includes("Failed to execute")));
|
|
30
|
+
}
|
|
31
|
+
const protectedQuerySelector = function(selector) {
|
|
32
|
+
try {
|
|
33
|
+
if (!selector || typeof selector !== "string") {
|
|
34
|
+
return originalQuerySelector(selector);
|
|
35
|
+
}
|
|
36
|
+
if (isProblematicSelector(selector)) return null;
|
|
37
|
+
return originalQuerySelector(selector);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (isSelectorSyntaxError(e)) return null;
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const protectedQuerySelectorAll = function(selector) {
|
|
44
|
+
try {
|
|
45
|
+
if (!selector || typeof selector !== "string") {
|
|
46
|
+
return originalQuerySelectorAll(selector);
|
|
47
|
+
}
|
|
48
|
+
if (isProblematicSelector(selector)) return document.createDocumentFragment();
|
|
49
|
+
return originalQuerySelectorAll(selector);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (isSelectorSyntaxError(e)) return document.createDocumentFragment();
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
Object.defineProperty(document, "querySelector", {
|
|
56
|
+
value: protectedQuerySelector,
|
|
57
|
+
writable: false,
|
|
58
|
+
configurable: false
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(document, "querySelectorAll", {
|
|
61
|
+
value: protectedQuerySelectorAll,
|
|
62
|
+
writable: false,
|
|
63
|
+
configurable: false
|
|
64
|
+
});
|
|
65
|
+
})();
|
|
66
|
+
(function() {
|
|
67
|
+
"use strict";
|
|
68
|
+
var TARGET_ORIGIN = typeof window !== "undefined" && window.__ARCHIE_INSPECTOR_TARGET_ORIGIN__ || "";
|
|
69
|
+
function postMessageToParent(msg) {
|
|
70
|
+
if (window.parent !== window && TARGET_ORIGIN && TARGET_ORIGIN !== "*") {
|
|
71
|
+
window.parent.postMessage(msg, TARGET_ORIGIN);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
var ALLOWED_ORIGINS = typeof window !== "undefined" && window.__ARCHIE_INSPECTOR_ALLOWED_ORIGINS__ || null;
|
|
75
|
+
function isOriginAllowed(origin) {
|
|
76
|
+
if (!origin) return false;
|
|
77
|
+
if (!Array.isArray(ALLOWED_ORIGINS) || ALLOWED_ORIGINS.length === 0 || ALLOWED_ORIGINS === "*") return false;
|
|
78
|
+
return ALLOWED_ORIGINS.indexOf(origin) !== -1;
|
|
79
|
+
}
|
|
80
|
+
var SCROLL_LISTENER_OPTS = { capture: true, passive: true };
|
|
81
|
+
var RESIZE_LISTENER_OPTS = { passive: true };
|
|
82
|
+
if (typeof window.__ARCHIE_INSPECTOR__ === "undefined") {
|
|
83
|
+
window.__ARCHIE_INSPECTOR__ = {};
|
|
84
|
+
}
|
|
85
|
+
if (typeof window._inspectorDebug === "undefined") {
|
|
86
|
+
window._inspectorDebug = false;
|
|
87
|
+
}
|
|
88
|
+
window.__ARCHIE_INSPECTOR__.debug = window._inspectorDebug;
|
|
89
|
+
function inspectorLog() {
|
|
90
|
+
if (window._inspectorDebug) {
|
|
91
|
+
console.log.apply(console, arguments);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function inspectorWarn() {
|
|
95
|
+
if (window._inspectorDebug) {
|
|
96
|
+
console.warn.apply(console, arguments);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
postMessageToParent({
|
|
100
|
+
type: "INSPECTOR_SCRIPT_LOADED",
|
|
101
|
+
timestamp: Date.now(),
|
|
102
|
+
version: "2.0.3"
|
|
103
|
+
});
|
|
104
|
+
if (window._inspectorMessageHandler) {
|
|
105
|
+
try {
|
|
106
|
+
window.removeEventListener("message", window._inspectorMessageHandler);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
}
|
|
109
|
+
delete window._inspectorMessageHandler;
|
|
110
|
+
}
|
|
111
|
+
if (window._inspectorSelectedElement) {
|
|
112
|
+
try {
|
|
113
|
+
if (!window._inspectorSelectedElement.parentNode || !document.contains(window._inspectorSelectedElement)) {
|
|
114
|
+
window._inspectorSelectedElement = null;
|
|
115
|
+
}
|
|
116
|
+
} catch (e) {
|
|
117
|
+
window._inspectorSelectedElement = null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let isInspecting = false;
|
|
121
|
+
let isElementSelected = false;
|
|
122
|
+
let highlightedElement = null;
|
|
123
|
+
let overlay = null;
|
|
124
|
+
let selectedElement = null;
|
|
125
|
+
let selectedElements = [];
|
|
126
|
+
let selectedElementBadge = null;
|
|
127
|
+
let eventBlockers = [];
|
|
128
|
+
let lastMultiSelectIntent = false;
|
|
129
|
+
var inspectorCleanupMap = /* @__PURE__ */ new WeakMap();
|
|
130
|
+
var BADGE_UPDATE_DELAY_MS = 50;
|
|
131
|
+
if (!window._inspectorSelectedElement) {
|
|
132
|
+
window._inspectorSelectedElement = null;
|
|
133
|
+
}
|
|
134
|
+
window.__ARCHIE_INSPECTOR__.selectedElement = window._inspectorSelectedElement;
|
|
135
|
+
function isInspectorElement(element) {
|
|
136
|
+
if (!element) return false;
|
|
137
|
+
return element === overlay || element === selectedElementBadge || element.id === "inspector-ping-effect" || element.closest && element.closest("[data-inspector-badge]");
|
|
138
|
+
}
|
|
139
|
+
function getElementFromPoint(x, y, fallbackTarget) {
|
|
140
|
+
try {
|
|
141
|
+
const element = document.elementFromPoint(x, y);
|
|
142
|
+
if (element && element !== document.body && element !== document.documentElement) {
|
|
143
|
+
return element;
|
|
144
|
+
}
|
|
145
|
+
} catch (err) {
|
|
146
|
+
}
|
|
147
|
+
return fallbackTarget || null;
|
|
148
|
+
}
|
|
149
|
+
function applyInspectorStyles(element) {
|
|
150
|
+
if (!element) return;
|
|
151
|
+
element.style.setProperty("outline", "2px solid #3b82f6", "important");
|
|
152
|
+
element.style.setProperty("outline-offset", "2px", "important");
|
|
153
|
+
element.setAttribute("data-inspector-editing", "true");
|
|
154
|
+
element.style.setProperty("transition", "all 0.1s ease-in-out", "important");
|
|
155
|
+
element.style.setProperty("position", "relative", "important");
|
|
156
|
+
element.style.setProperty("z-index", "10000", "important");
|
|
157
|
+
}
|
|
158
|
+
function removeInspectorStyles(element) {
|
|
159
|
+
if (!element) return;
|
|
160
|
+
element.style.removeProperty("outline");
|
|
161
|
+
element.style.removeProperty("outline-offset");
|
|
162
|
+
element.removeAttribute("data-inspector-editing");
|
|
163
|
+
element.style.removeProperty("transition");
|
|
164
|
+
element.style.removeProperty("position");
|
|
165
|
+
element.style.removeProperty("z-index");
|
|
166
|
+
}
|
|
167
|
+
function getElementCleanup(element) {
|
|
168
|
+
return element ? inspectorCleanupMap.get(element) : null;
|
|
169
|
+
}
|
|
170
|
+
function setElementCleanup(element, cleanup) {
|
|
171
|
+
if (!element) return;
|
|
172
|
+
var prev = inspectorCleanupMap.get(element);
|
|
173
|
+
if (prev) {
|
|
174
|
+
window.removeEventListener("scroll", prev.scroll, true);
|
|
175
|
+
window.removeEventListener("resize", prev.resize);
|
|
176
|
+
}
|
|
177
|
+
inspectorCleanupMap.set(element, cleanup);
|
|
178
|
+
}
|
|
179
|
+
function deleteElementCleanup(element) {
|
|
180
|
+
if (!element) return;
|
|
181
|
+
var prev = inspectorCleanupMap.get(element);
|
|
182
|
+
if (prev) {
|
|
183
|
+
window.removeEventListener("scroll", prev.scroll, true);
|
|
184
|
+
window.removeEventListener("resize", prev.resize);
|
|
185
|
+
}
|
|
186
|
+
inspectorCleanupMap.delete(element);
|
|
187
|
+
}
|
|
188
|
+
function cleanupElementListeners(element) {
|
|
189
|
+
if (!element) return;
|
|
190
|
+
deleteElementCleanup(element);
|
|
191
|
+
}
|
|
192
|
+
function setupBadgePositionListeners(element) {
|
|
193
|
+
if (!element) return;
|
|
194
|
+
function updateBadgePosition() {
|
|
195
|
+
if (selectedElement && selectedElementBadge) {
|
|
196
|
+
var rect = selectedElement.getBoundingClientRect();
|
|
197
|
+
var scrollX = window.pageXOffset || document.documentElement.scrollLeft;
|
|
198
|
+
var scrollY = window.pageYOffset || document.documentElement.scrollTop;
|
|
199
|
+
selectedElementBadge.style.top = rect.top + scrollY + "px";
|
|
200
|
+
selectedElementBadge.style.left = rect.left + scrollX + "px";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
window.addEventListener("scroll", updateBadgePosition, SCROLL_LISTENER_OPTS);
|
|
204
|
+
window.addEventListener("resize", updateBadgePosition, RESIZE_LISTENER_OPTS);
|
|
205
|
+
setElementCleanup(element, {
|
|
206
|
+
scroll: updateBadgePosition,
|
|
207
|
+
resize: updateBadgePosition
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function setupEventBlockers() {
|
|
211
|
+
removeEventBlockers();
|
|
212
|
+
const eventsToBlock = [
|
|
213
|
+
"click",
|
|
214
|
+
"mousedown",
|
|
215
|
+
"mouseup",
|
|
216
|
+
"dblclick",
|
|
217
|
+
"contextmenu",
|
|
218
|
+
"submit",
|
|
219
|
+
"change",
|
|
220
|
+
"input",
|
|
221
|
+
"focus",
|
|
222
|
+
"blur",
|
|
223
|
+
"keydown",
|
|
224
|
+
"keyup"
|
|
225
|
+
];
|
|
226
|
+
const blockEvent = function(e) {
|
|
227
|
+
if (!isInspecting) return;
|
|
228
|
+
if (e.type === "mousemove" || e.type === "pointermove" || isInspectorElement(e.target)) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
e.stopPropagation();
|
|
233
|
+
e.stopImmediatePropagation();
|
|
234
|
+
return false;
|
|
235
|
+
};
|
|
236
|
+
eventsToBlock.forEach(function(eventType) {
|
|
237
|
+
document.addEventListener(eventType, blockEvent, {
|
|
238
|
+
capture: true,
|
|
239
|
+
passive: false
|
|
240
|
+
});
|
|
241
|
+
eventBlockers.push({ type: eventType, handler: blockEvent });
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function removeEventBlockers() {
|
|
245
|
+
eventBlockers.forEach(function(blocker) {
|
|
246
|
+
document.removeEventListener(blocker.type, blocker.handler, {
|
|
247
|
+
capture: true,
|
|
248
|
+
passive: false
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
eventBlockers = [];
|
|
252
|
+
}
|
|
253
|
+
const updateMultiSelectIntent = (event) => {
|
|
254
|
+
if (!isInspecting) return;
|
|
255
|
+
lastMultiSelectIntent = event.metaKey || event.ctrlKey;
|
|
256
|
+
};
|
|
257
|
+
document.addEventListener("pointerdown", updateMultiSelectIntent, true);
|
|
258
|
+
document.addEventListener(
|
|
259
|
+
"pointerup",
|
|
260
|
+
(event) => {
|
|
261
|
+
if (!event.metaKey && !event.ctrlKey) {
|
|
262
|
+
lastMultiSelectIntent = false;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
true
|
|
266
|
+
);
|
|
267
|
+
document.addEventListener(
|
|
268
|
+
"keyup",
|
|
269
|
+
(event) => {
|
|
270
|
+
if (!event.metaKey && !event.ctrlKey) {
|
|
271
|
+
lastMultiSelectIntent = false;
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
true
|
|
275
|
+
);
|
|
276
|
+
function getSelectedElement() {
|
|
277
|
+
if (selectedElement && selectedElement.parentNode !== null && document.contains(selectedElement)) {
|
|
278
|
+
return selectedElement;
|
|
279
|
+
}
|
|
280
|
+
if (window._inspectorSelectedElement && window._inspectorSelectedElement.parentNode !== null && document.contains(window._inspectorSelectedElement)) {
|
|
281
|
+
selectedElement = window._inspectorSelectedElement;
|
|
282
|
+
return selectedElement;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const element = document.querySelector('[data-inspector-editing="true"]');
|
|
286
|
+
if (element && document.contains(element)) {
|
|
287
|
+
selectedElement = element;
|
|
288
|
+
window._inspectorSelectedElement = element;
|
|
289
|
+
if (window.__ARCHIE_INSPECTOR__) window.__ARCHIE_INSPECTOR__.selectedElement = element;
|
|
290
|
+
return element;
|
|
291
|
+
}
|
|
292
|
+
} catch (e) {
|
|
293
|
+
}
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
function updateSharedHighlights() {
|
|
297
|
+
const sharedElements = document.querySelectorAll(
|
|
298
|
+
'[data-inspector-shared="true"]'
|
|
299
|
+
);
|
|
300
|
+
sharedElements.forEach((el) => {
|
|
301
|
+
el.removeAttribute("data-inspector-shared");
|
|
302
|
+
if (!selectedElements.includes(el) && el !== highlightedElement) {
|
|
303
|
+
el.style.removeProperty("outline");
|
|
304
|
+
el.style.removeProperty("outline-offset");
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
const targets = [];
|
|
308
|
+
if (selectedElements && selectedElements.length > 0) {
|
|
309
|
+
selectedElements.forEach((el) => targets.push(el));
|
|
310
|
+
}
|
|
311
|
+
if (highlightedElement && !selectedElements.includes(highlightedElement)) {
|
|
312
|
+
targets.push(highlightedElement);
|
|
313
|
+
}
|
|
314
|
+
targets.forEach((target) => {
|
|
315
|
+
const componentRoot = target.closest("[data-inspector-relative-path]");
|
|
316
|
+
if (!componentRoot) return;
|
|
317
|
+
const path = componentRoot.getAttribute("data-inspector-relative-path");
|
|
318
|
+
const line = componentRoot.getAttribute("data-inspector-line");
|
|
319
|
+
const column = componentRoot.getAttribute("data-inspector-column");
|
|
320
|
+
if (!path || !line || !column) return;
|
|
321
|
+
const selector = `[data-inspector-relative-path="${path}"][data-inspector-line="${line}"][data-inspector-column="${column}"]`;
|
|
322
|
+
const newShared = document.querySelectorAll(selector);
|
|
323
|
+
newShared.forEach((el) => {
|
|
324
|
+
if (selectedElements.includes(el) || el === highlightedElement) return;
|
|
325
|
+
el.setAttribute("data-inspector-shared", "true");
|
|
326
|
+
el.style.setProperty(
|
|
327
|
+
"outline",
|
|
328
|
+
"2px dashed rgba(59, 130, 246, 0.2)",
|
|
329
|
+
"important"
|
|
330
|
+
);
|
|
331
|
+
el.style.setProperty("outline-offset", "2px", "important");
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function highlightElement(element) {
|
|
336
|
+
if (!element || selectedElements.includes(element)) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (highlightedElement && highlightedElement !== element) {
|
|
340
|
+
highlightedElement.style.outline = "";
|
|
341
|
+
highlightedElement.style.transition = "";
|
|
342
|
+
highlightedElement.style.outlineOffset = "";
|
|
343
|
+
highlightedElement.style.border = "";
|
|
344
|
+
}
|
|
345
|
+
highlightedElement = element;
|
|
346
|
+
element.style.outline = "";
|
|
347
|
+
element.style.outlineOffset = "";
|
|
348
|
+
element.style.border = "";
|
|
349
|
+
element.style.transition = "";
|
|
350
|
+
element.style.setProperty("outline", "2px solid #3b82f6", "important");
|
|
351
|
+
element.style.setProperty("outline-offset", "2px", "important");
|
|
352
|
+
updateSharedHighlights();
|
|
353
|
+
}
|
|
354
|
+
function removeHighlight() {
|
|
355
|
+
if (highlightedElement) {
|
|
356
|
+
highlightedElement.style.outline = "";
|
|
357
|
+
highlightedElement.style.transition = "";
|
|
358
|
+
highlightedElement.style.outlineOffset = "";
|
|
359
|
+
highlightedElement.style.border = "";
|
|
360
|
+
highlightedElement = null;
|
|
361
|
+
}
|
|
362
|
+
const pingEffect = document.getElementById("inspector-ping-effect");
|
|
363
|
+
if (pingEffect) {
|
|
364
|
+
pingEffect.remove();
|
|
365
|
+
}
|
|
366
|
+
if (overlay) {
|
|
367
|
+
overlay.remove();
|
|
368
|
+
overlay = null;
|
|
369
|
+
}
|
|
370
|
+
updateSharedHighlights();
|
|
371
|
+
}
|
|
372
|
+
function createSelectedBadge(element) {
|
|
373
|
+
}
|
|
374
|
+
function removeSelectedBadge() {
|
|
375
|
+
if (selectedElementBadge) {
|
|
376
|
+
selectedElementBadge.remove();
|
|
377
|
+
selectedElementBadge = null;
|
|
378
|
+
}
|
|
379
|
+
selectedElements.forEach((el) => {
|
|
380
|
+
if (el && el._inspectorPingCleanup) {
|
|
381
|
+
window.removeEventListener(
|
|
382
|
+
"scroll",
|
|
383
|
+
el._inspectorPingCleanup.scroll,
|
|
384
|
+
true
|
|
385
|
+
);
|
|
386
|
+
window.removeEventListener("resize", el._inspectorPingCleanup.resize);
|
|
387
|
+
if (el._inspectorPingCleanup.pingElement) {
|
|
388
|
+
el._inspectorPingCleanup.pingElement.remove();
|
|
389
|
+
}
|
|
390
|
+
delete el._inspectorPingCleanup;
|
|
391
|
+
}
|
|
392
|
+
removeInspectorStyles(el);
|
|
393
|
+
if (el.style) {
|
|
394
|
+
el.style.removeProperty("transition");
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
if (selectedElement && !selectedElements.includes(selectedElement)) {
|
|
398
|
+
removeInspectorStyles(selectedElement);
|
|
399
|
+
if (selectedElement.style) {
|
|
400
|
+
selectedElement.style.removeProperty("transition");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
selectedElement = null;
|
|
404
|
+
isElementSelected = false;
|
|
405
|
+
}
|
|
406
|
+
function getElementSelector(element) {
|
|
407
|
+
if (!element) return "";
|
|
408
|
+
if (element.id) {
|
|
409
|
+
return "#" + element.id;
|
|
410
|
+
}
|
|
411
|
+
let selector = element.tagName.toLowerCase();
|
|
412
|
+
if (element.className && typeof element.className === "string" && element.className.trim()) {
|
|
413
|
+
const classes = element.className.trim().split(/\s+/).filter((c) => c && c.length > 0);
|
|
414
|
+
if (classes.length > 0) {
|
|
415
|
+
selector += "." + classes.slice(0, 2).join(".");
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return selector;
|
|
419
|
+
}
|
|
420
|
+
function extractMetadata(element) {
|
|
421
|
+
if (!element) return null;
|
|
422
|
+
const computed = window.getComputedStyle(element);
|
|
423
|
+
const rect = element.getBoundingClientRect();
|
|
424
|
+
const attributes = {};
|
|
425
|
+
for (let i = 0; i < element.attributes.length; i++) {
|
|
426
|
+
const attr = element.attributes[i];
|
|
427
|
+
attributes[attr.name] = attr.value;
|
|
428
|
+
}
|
|
429
|
+
let inspectorInfo = null;
|
|
430
|
+
let currentElement = element;
|
|
431
|
+
while (currentElement && currentElement !== document.body && currentElement !== document.documentElement) {
|
|
432
|
+
const relativePath = currentElement.getAttribute(
|
|
433
|
+
"data-inspector-relative-path"
|
|
434
|
+
);
|
|
435
|
+
const line = currentElement.getAttribute("data-inspector-line");
|
|
436
|
+
const column = currentElement.getAttribute("data-inspector-column");
|
|
437
|
+
if (relativePath && line) {
|
|
438
|
+
inspectorInfo = {
|
|
439
|
+
file: relativePath,
|
|
440
|
+
line: parseInt(line, 10),
|
|
441
|
+
column: column ? parseInt(column, 10) : 1
|
|
442
|
+
};
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
currentElement = currentElement.parentElement;
|
|
446
|
+
}
|
|
447
|
+
function getCssSelector(el) {
|
|
448
|
+
if (!el) return "";
|
|
449
|
+
if (el.id) {
|
|
450
|
+
return "#" + el.id;
|
|
451
|
+
}
|
|
452
|
+
if (el.hasAttribute && el.hasAttribute("data-inspector-editing")) {
|
|
453
|
+
const relativePath = el.getAttribute("data-inspector-relative-path");
|
|
454
|
+
const line = el.getAttribute("data-inspector-line");
|
|
455
|
+
if (relativePath && line) {
|
|
456
|
+
const tagName = el.nodeName.toLowerCase();
|
|
457
|
+
const inspectorSelector = tagName + '[data-inspector-line="' + line + '"][data-inspector-relative-path="' + relativePath + '"]';
|
|
458
|
+
try {
|
|
459
|
+
const matches = document.querySelectorAll(inspectorSelector);
|
|
460
|
+
if (matches.length === 1) {
|
|
461
|
+
return inspectorSelector;
|
|
462
|
+
}
|
|
463
|
+
} catch (e) {
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const path = [];
|
|
468
|
+
let current = el;
|
|
469
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && current !== document.body && current !== document.documentElement) {
|
|
470
|
+
let selector = current.nodeName.toLowerCase();
|
|
471
|
+
if (current.className && typeof current.className === "string" && current.className.trim()) {
|
|
472
|
+
const classes = current.className.trim().split(/\s+/).filter(function(c) {
|
|
473
|
+
return c && c.length > 0 && c.length < 50;
|
|
474
|
+
});
|
|
475
|
+
if (classes.length > 0 && classes.length <= 3) {
|
|
476
|
+
selector += "." + classes.slice(0, 2).join(".");
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
let sibling = current;
|
|
480
|
+
let nth = 1;
|
|
481
|
+
while (sibling.previousElementSibling) {
|
|
482
|
+
sibling = sibling.previousElementSibling;
|
|
483
|
+
if (sibling.nodeName === current.nodeName) {
|
|
484
|
+
nth++;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (nth > 1) {
|
|
488
|
+
selector += ":nth-of-type(" + nth + ")";
|
|
489
|
+
}
|
|
490
|
+
path.unshift(selector);
|
|
491
|
+
current = current.parentElement;
|
|
492
|
+
}
|
|
493
|
+
return path.length > 0 ? path.join(" > ") : el.nodeName.toLowerCase();
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
tagName: element.tagName.toLowerCase(),
|
|
497
|
+
id: element.id || null,
|
|
498
|
+
className: element.className && typeof element.className === "string" ? element.className.trim() || null : null,
|
|
499
|
+
textContent: element.textContent ? element.textContent.trim().slice(0, 200) : null,
|
|
500
|
+
innerHTML: element.innerHTML ? element.innerHTML.slice(0, 500) : null,
|
|
501
|
+
attributes,
|
|
502
|
+
// Inspector source info from data-inspector-* attributes
|
|
503
|
+
inspectorSource: inspectorInfo,
|
|
504
|
+
computedStyles: {
|
|
505
|
+
display: computed.display,
|
|
506
|
+
position: computed.position,
|
|
507
|
+
width: computed.width,
|
|
508
|
+
height: computed.height,
|
|
509
|
+
margin: computed.margin,
|
|
510
|
+
padding: computed.padding,
|
|
511
|
+
fontSize: computed.fontSize,
|
|
512
|
+
color: computed.color,
|
|
513
|
+
backgroundColor: computed.backgroundColor,
|
|
514
|
+
border: computed.border,
|
|
515
|
+
borderRadius: computed.borderRadius,
|
|
516
|
+
textAlign: computed.textAlign,
|
|
517
|
+
fontFamily: computed.fontFamily,
|
|
518
|
+
fontWeight: computed.fontWeight,
|
|
519
|
+
lineHeight: computed.lineHeight,
|
|
520
|
+
letterSpacing: computed.letterSpacing
|
|
521
|
+
},
|
|
522
|
+
boundingRect: {
|
|
523
|
+
x: rect.x,
|
|
524
|
+
y: rect.y,
|
|
525
|
+
width: rect.width,
|
|
526
|
+
height: rect.height,
|
|
527
|
+
top: rect.top,
|
|
528
|
+
left: rect.left,
|
|
529
|
+
bottom: rect.bottom,
|
|
530
|
+
right: rect.right
|
|
531
|
+
},
|
|
532
|
+
cssSelector: getCssSelector(element)
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
const messageHandler = function(event) {
|
|
536
|
+
if (!isOriginAllowed(event.origin)) return;
|
|
537
|
+
if (!event.data || typeof event.data !== "object" || typeof event.data.type !== "string")
|
|
538
|
+
return;
|
|
539
|
+
if (event.data && event.data.type && event.data.type !== "GET_ELEMENT_POSITION") {
|
|
540
|
+
inspectorLog("[Inspector] Received message:", event.data.type, event.data);
|
|
541
|
+
}
|
|
542
|
+
if (event.data && event.data.type === "START_INSPECTION") {
|
|
543
|
+
selectedElement = null;
|
|
544
|
+
selectedElements = [];
|
|
545
|
+
window._inspectorSelectedElement = null;
|
|
546
|
+
lastMultiSelectIntent = false;
|
|
547
|
+
isInspecting = true;
|
|
548
|
+
const applyCursorStyles = () => {
|
|
549
|
+
if (document.body) {
|
|
550
|
+
document.body.style.cursor = "crosshair";
|
|
551
|
+
document.body.style.userSelect = "none";
|
|
552
|
+
} else {
|
|
553
|
+
setTimeout(applyCursorStyles, 100);
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
applyCursorStyles();
|
|
557
|
+
setupEventBlockers();
|
|
558
|
+
} else if (event.data && event.data.type === "STOP_INSPECTION") {
|
|
559
|
+
isInspecting = false;
|
|
560
|
+
isElementSelected = false;
|
|
561
|
+
removeEventBlockers();
|
|
562
|
+
if (document.body) {
|
|
563
|
+
document.body.style.cursor = "";
|
|
564
|
+
document.body.style.userSelect = "";
|
|
565
|
+
}
|
|
566
|
+
removeHighlight();
|
|
567
|
+
removeSelectedBadge();
|
|
568
|
+
selectedElements = [];
|
|
569
|
+
lastMultiSelectIntent = false;
|
|
570
|
+
updateSharedHighlights();
|
|
571
|
+
postMessageToParent({ type: "STOP_INSPECTION" });
|
|
572
|
+
} else if (event.data && event.data.type === "SHOW_SELECTED_ELEMENT") {
|
|
573
|
+
const { selector } = event.data;
|
|
574
|
+
let element = null;
|
|
575
|
+
try {
|
|
576
|
+
element = document.querySelector(selector);
|
|
577
|
+
} catch (e) {
|
|
578
|
+
element = getSelectedElement();
|
|
579
|
+
}
|
|
580
|
+
if (!element) {
|
|
581
|
+
element = getSelectedElement();
|
|
582
|
+
}
|
|
583
|
+
if (element) {
|
|
584
|
+
removeSelectedBadge();
|
|
585
|
+
updateSharedHighlights();
|
|
586
|
+
removeHighlight();
|
|
587
|
+
selectedElement = element;
|
|
588
|
+
window._inspectorSelectedElement = element;
|
|
589
|
+
if (window.__ARCHIE_INSPECTOR__) window.__ARCHIE_INSPECTOR__.selectedElement = element;
|
|
590
|
+
isElementSelected = true;
|
|
591
|
+
applyInspectorStyles(element);
|
|
592
|
+
createSelectedBadge(element);
|
|
593
|
+
setupBadgePositionListeners(element);
|
|
594
|
+
}
|
|
595
|
+
} else if (event.data && event.data.type === "SELECT_PARENT_ELEMENT") {
|
|
596
|
+
const element = getSelectedElement();
|
|
597
|
+
if (element && element.parentElement && element.parentElement !== document.body && element.parentElement !== document.documentElement) {
|
|
598
|
+
const parentElement = element.parentElement;
|
|
599
|
+
const metadata = extractMetadata(parentElement);
|
|
600
|
+
if (selectedElement) {
|
|
601
|
+
removeInspectorStyles(selectedElement);
|
|
602
|
+
cleanupElementListeners(selectedElement);
|
|
603
|
+
}
|
|
604
|
+
selectedElement = parentElement;
|
|
605
|
+
window._inspectorSelectedElement = parentElement;
|
|
606
|
+
if (window.__ARCHIE_INSPECTOR__) window.__ARCHIE_INSPECTOR__.selectedElement = parentElement;
|
|
607
|
+
isElementSelected = true;
|
|
608
|
+
applyInspectorStyles(parentElement);
|
|
609
|
+
setupBadgePositionListeners(parentElement);
|
|
610
|
+
postMessageToParent({
|
|
611
|
+
type: "ELEMENT_SELECTED",
|
|
612
|
+
metadata
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
} else if (event.data && event.data.type === "HIDE_SELECTED_ELEMENT") {
|
|
616
|
+
if (selectedElement) {
|
|
617
|
+
deleteElementCleanup(selectedElement);
|
|
618
|
+
}
|
|
619
|
+
if (selectedElement) {
|
|
620
|
+
removeInspectorStyles(selectedElement);
|
|
621
|
+
const computed = window.getComputedStyle(selectedElement);
|
|
622
|
+
const borderWidth = computed.borderWidth;
|
|
623
|
+
const borderColor = computed.borderColor;
|
|
624
|
+
const borderStyle = computed.borderStyle;
|
|
625
|
+
const inlineBorderWidth = selectedElement.style.getPropertyValue("border-width");
|
|
626
|
+
const inlineBorderColor = selectedElement.style.getPropertyValue("border-color");
|
|
627
|
+
const inlineBorderStyle = selectedElement.style.getPropertyValue("border-style");
|
|
628
|
+
inspectorLog("[Inspector] Hiding element, user styles check:", {
|
|
629
|
+
computed: { borderWidth, borderColor, borderStyle },
|
|
630
|
+
inline: {
|
|
631
|
+
borderWidth: inlineBorderWidth,
|
|
632
|
+
borderColor: inlineBorderColor,
|
|
633
|
+
borderStyle: inlineBorderStyle
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
removeSelectedBadge();
|
|
638
|
+
updateSharedHighlights();
|
|
639
|
+
isElementSelected = false;
|
|
640
|
+
} else if (event.data && event.data.type === "GET_ELEMENT_POSITION") {
|
|
641
|
+
const { selector } = event.data;
|
|
642
|
+
let element = null;
|
|
643
|
+
if (selector) {
|
|
644
|
+
try {
|
|
645
|
+
element = document.querySelector(selector);
|
|
646
|
+
} catch (e) {
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (!element) {
|
|
650
|
+
element = getSelectedElement();
|
|
651
|
+
}
|
|
652
|
+
if (element) {
|
|
653
|
+
if (element.getAttribute("data-inspector-editing") === "true") {
|
|
654
|
+
applyInspectorStyles(element);
|
|
655
|
+
}
|
|
656
|
+
const rect = element.getBoundingClientRect();
|
|
657
|
+
postMessageToParent({
|
|
658
|
+
type: "ELEMENT_POSITION_UPDATE",
|
|
659
|
+
selector,
|
|
660
|
+
boundingRect: {
|
|
661
|
+
x: rect.x,
|
|
662
|
+
y: rect.y,
|
|
663
|
+
width: rect.width,
|
|
664
|
+
height: rect.height,
|
|
665
|
+
top: rect.top,
|
|
666
|
+
left: rect.left,
|
|
667
|
+
bottom: rect.bottom,
|
|
668
|
+
right: rect.right
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
} else if (event.data && event.data.type === "APPLY_STYLE_CHANGE") {
|
|
673
|
+
const { selector, property, value } = event.data;
|
|
674
|
+
inspectorLog("[Inspector] Received APPLY_STYLE_CHANGE:", {
|
|
675
|
+
selector,
|
|
676
|
+
property,
|
|
677
|
+
value
|
|
678
|
+
});
|
|
679
|
+
let element = null;
|
|
680
|
+
element = getSelectedElement();
|
|
681
|
+
if (element) {
|
|
682
|
+
inspectorLog(
|
|
683
|
+
"[Inspector] Found element via getSelectedElement (priority method)"
|
|
684
|
+
);
|
|
685
|
+
try {
|
|
686
|
+
const elementSelector = getElementSelector(element);
|
|
687
|
+
if (elementSelector === selector) {
|
|
688
|
+
inspectorLog(
|
|
689
|
+
"[Inspector] Selected element selector matches:",
|
|
690
|
+
elementSelector
|
|
691
|
+
);
|
|
692
|
+
} else {
|
|
693
|
+
inspectorLog(
|
|
694
|
+
"[Inspector] Selected element selector differs but using it anyway (user is editing this element):",
|
|
695
|
+
elementSelector,
|
|
696
|
+
"vs",
|
|
697
|
+
selector
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
} catch (e) {
|
|
701
|
+
inspectorWarn("[Inspector] Error verifying selected element:", e);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
if (!element) {
|
|
705
|
+
try {
|
|
706
|
+
const editingElement = document.querySelector(
|
|
707
|
+
'[data-inspector-editing="true"]'
|
|
708
|
+
);
|
|
709
|
+
if (editingElement) {
|
|
710
|
+
inspectorLog("[Inspector] Found element via data-inspector-editing");
|
|
711
|
+
element = editingElement;
|
|
712
|
+
try {
|
|
713
|
+
const elementSelector = getElementSelector(editingElement);
|
|
714
|
+
if (elementSelector === selector) {
|
|
715
|
+
inspectorLog(
|
|
716
|
+
"[Inspector] Editing element selector matches:",
|
|
717
|
+
elementSelector
|
|
718
|
+
);
|
|
719
|
+
} else {
|
|
720
|
+
inspectorLog(
|
|
721
|
+
"[Inspector] Editing element selector differs but using it:",
|
|
722
|
+
elementSelector,
|
|
723
|
+
"vs",
|
|
724
|
+
selector
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
} catch (e) {
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
} catch (e) {
|
|
731
|
+
inspectorWarn("[Inspector] Error finding editing element:", e);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (!element) {
|
|
735
|
+
try {
|
|
736
|
+
const foundElement = document.querySelector(selector);
|
|
737
|
+
if (foundElement) {
|
|
738
|
+
inspectorLog("[Inspector] Found element by selector:", selector);
|
|
739
|
+
element = foundElement;
|
|
740
|
+
}
|
|
741
|
+
} catch (e) {
|
|
742
|
+
inspectorWarn("[Inspector] Error querying selector:", selector, e);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (!element) {
|
|
746
|
+
inspectorWarn(
|
|
747
|
+
"[Inspector] Element not found for selector:",
|
|
748
|
+
selector,
|
|
749
|
+
"property:",
|
|
750
|
+
property
|
|
751
|
+
);
|
|
752
|
+
setTimeout(() => {
|
|
753
|
+
try {
|
|
754
|
+
const retryElement = document.querySelector(selector);
|
|
755
|
+
if (retryElement) {
|
|
756
|
+
inspectorLog("[Inspector] Found element on retry");
|
|
757
|
+
const kebabProperty2 = property.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
758
|
+
retryElement.style.setProperty(kebabProperty2, value, "important");
|
|
759
|
+
inspectorLog(
|
|
760
|
+
"[Inspector] Applied style on retry:",
|
|
761
|
+
property,
|
|
762
|
+
"=",
|
|
763
|
+
value
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
} catch (e) {
|
|
767
|
+
inspectorWarn("[Inspector] Retry also failed:", e);
|
|
768
|
+
}
|
|
769
|
+
}, 100);
|
|
770
|
+
postMessageToParent({
|
|
771
|
+
type: "STYLE_CHANGE_FAILED",
|
|
772
|
+
selector,
|
|
773
|
+
property,
|
|
774
|
+
value,
|
|
775
|
+
error: "Element not found"
|
|
776
|
+
});
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
const kebabProperty = property.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
780
|
+
element.style.setProperty(kebabProperty, value, "important");
|
|
781
|
+
const camelProperty = property.replace(
|
|
782
|
+
/-([a-z])/g,
|
|
783
|
+
(g) => g[1].toUpperCase()
|
|
784
|
+
);
|
|
785
|
+
if (element.style.hasOwnProperty(camelProperty)) {
|
|
786
|
+
element.style[camelProperty] = value;
|
|
787
|
+
}
|
|
788
|
+
const componentRoot = element.closest("[data-inspector-relative-path]");
|
|
789
|
+
if (componentRoot) {
|
|
790
|
+
const path = componentRoot.getAttribute("data-inspector-relative-path");
|
|
791
|
+
const line = componentRoot.getAttribute("data-inspector-line");
|
|
792
|
+
const column = componentRoot.getAttribute("data-inspector-column");
|
|
793
|
+
if (path && line && column) {
|
|
794
|
+
const selector2 = `[data-inspector-relative-path="${path}"][data-inspector-line="${line}"][data-inspector-column="${column}"]`;
|
|
795
|
+
const sharedNodes = document.querySelectorAll(selector2);
|
|
796
|
+
sharedNodes.forEach((sharedEl) => {
|
|
797
|
+
if (sharedEl === element) return;
|
|
798
|
+
sharedEl.style.setProperty(kebabProperty, value, "important");
|
|
799
|
+
if (sharedEl.style.hasOwnProperty(camelProperty)) {
|
|
800
|
+
sharedEl.style[camelProperty] = value;
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const appliedValue = element.style.getPropertyValue(kebabProperty);
|
|
806
|
+
inspectorLog(
|
|
807
|
+
"[Inspector] Applied style:",
|
|
808
|
+
property,
|
|
809
|
+
"=",
|
|
810
|
+
value,
|
|
811
|
+
"to element:",
|
|
812
|
+
selector,
|
|
813
|
+
"found:",
|
|
814
|
+
!!element,
|
|
815
|
+
"verified:",
|
|
816
|
+
appliedValue
|
|
817
|
+
);
|
|
818
|
+
postMessageToParent({
|
|
819
|
+
type: "STYLE_CHANGE_APPLIED",
|
|
820
|
+
selector,
|
|
821
|
+
property,
|
|
822
|
+
value
|
|
823
|
+
});
|
|
824
|
+
} else if (event.data && event.data.type === "APPLY_CLASS_NAME_CHANGE") {
|
|
825
|
+
const { selector, className, action } = event.data;
|
|
826
|
+
inspectorLog("[Inspector] Received APPLY_CLASS_NAME_CHANGE:", {
|
|
827
|
+
selector,
|
|
828
|
+
className,
|
|
829
|
+
action
|
|
830
|
+
});
|
|
831
|
+
let element = getSelectedElement();
|
|
832
|
+
if (!element) {
|
|
833
|
+
try {
|
|
834
|
+
element = document.querySelector(selector);
|
|
835
|
+
} catch (e) {
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (!element) {
|
|
839
|
+
postMessageToParent({
|
|
840
|
+
type: "STYLE_CHANGE_FAILED",
|
|
841
|
+
selector,
|
|
842
|
+
error: "Element not found for class change"
|
|
843
|
+
});
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
const classes = className.split(/\s+/).filter(Boolean);
|
|
847
|
+
classes.forEach((cls) => {
|
|
848
|
+
if (action === "remove") {
|
|
849
|
+
element.classList.remove(cls);
|
|
850
|
+
} else if (action === "toggle") {
|
|
851
|
+
element.classList.toggle(cls);
|
|
852
|
+
} else {
|
|
853
|
+
element.classList.add(cls);
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
const componentRoot = element.closest("[data-inspector-relative-path]");
|
|
857
|
+
if (componentRoot) {
|
|
858
|
+
const path = componentRoot.getAttribute("data-inspector-relative-path");
|
|
859
|
+
const line = componentRoot.getAttribute("data-inspector-line");
|
|
860
|
+
const column = componentRoot.getAttribute("data-inspector-column");
|
|
861
|
+
if (path && line && column) {
|
|
862
|
+
const sharedSelector = `[data-inspector-relative-path="${path}"][data-inspector-line="${line}"][data-inspector-column="${column}"]`;
|
|
863
|
+
const sharedNodes = document.querySelectorAll(sharedSelector);
|
|
864
|
+
sharedNodes.forEach((sharedEl) => {
|
|
865
|
+
if (sharedEl === element) return;
|
|
866
|
+
classes.forEach((cls) => {
|
|
867
|
+
if (action === "remove") {
|
|
868
|
+
sharedEl.classList.remove(cls);
|
|
869
|
+
} else if (action === "toggle") {
|
|
870
|
+
sharedEl.classList.toggle(cls);
|
|
871
|
+
} else {
|
|
872
|
+
sharedEl.classList.add(cls);
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
postMessageToParent({
|
|
879
|
+
type: "STYLE_CHANGE_APPLIED",
|
|
880
|
+
selector,
|
|
881
|
+
className,
|
|
882
|
+
action
|
|
883
|
+
});
|
|
884
|
+
} else if (event.data && event.data.type === "APPLY_TEXT_CHANGE") {
|
|
885
|
+
const { selector, text } = event.data;
|
|
886
|
+
const element = getSelectedElement();
|
|
887
|
+
if (!element) {
|
|
888
|
+
postMessageToParent({
|
|
889
|
+
type: "TEXT_CHANGE_FAILED",
|
|
890
|
+
selector,
|
|
891
|
+
text,
|
|
892
|
+
error: "Element not found"
|
|
893
|
+
});
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
element.textContent = text;
|
|
897
|
+
postMessageToParent({
|
|
898
|
+
type: "TEXT_CHANGE_APPLIED",
|
|
899
|
+
selector,
|
|
900
|
+
text
|
|
901
|
+
});
|
|
902
|
+
} else if (event.data && event.data.type === "REMOVE_ELEMENT") {
|
|
903
|
+
const { selector } = event.data;
|
|
904
|
+
const element = getSelectedElement();
|
|
905
|
+
if (!element) {
|
|
906
|
+
postMessageToParent({
|
|
907
|
+
type: "ELEMENT_REMOVAL_FAILED",
|
|
908
|
+
selector,
|
|
909
|
+
error: "Element not found"
|
|
910
|
+
});
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
element.remove();
|
|
914
|
+
const index = selectedElements.indexOf(element);
|
|
915
|
+
if (index > -1) {
|
|
916
|
+
selectedElements.splice(index, 1);
|
|
917
|
+
}
|
|
918
|
+
if (selectedElements.length === 0) {
|
|
919
|
+
selectedElement = null;
|
|
920
|
+
window._inspectorSelectedElement = null;
|
|
921
|
+
isElementSelected = false;
|
|
922
|
+
removeSelectedBadge();
|
|
923
|
+
} else {
|
|
924
|
+
selectedElement = selectedElements[selectedElements.length - 1];
|
|
925
|
+
window._inspectorSelectedElement = selectedElement;
|
|
926
|
+
removeSelectedBadge();
|
|
927
|
+
selectedElements.forEach((el) => createSelectedBadge(el));
|
|
928
|
+
}
|
|
929
|
+
updateSharedHighlights();
|
|
930
|
+
postMessageToParent({
|
|
931
|
+
type: "ELEMENT_REMOVED",
|
|
932
|
+
selector
|
|
933
|
+
});
|
|
934
|
+
} else if (event.data && event.data.type === "REVERT_CHANGES") {
|
|
935
|
+
removeHighlight();
|
|
936
|
+
removeSelectedBadge();
|
|
937
|
+
updateSharedHighlights();
|
|
938
|
+
selectedElements.forEach((el) => {
|
|
939
|
+
el.removeAttribute("data-inspector-editing");
|
|
940
|
+
el.style.outline = "";
|
|
941
|
+
el.style.outlineOffset = "";
|
|
942
|
+
el.style.border = "";
|
|
943
|
+
el.style.boxShadow = "";
|
|
944
|
+
el.style.transition = "";
|
|
945
|
+
el.style.position = "";
|
|
946
|
+
el.style.zIndex = "";
|
|
947
|
+
});
|
|
948
|
+
if (selectedElement && !selectedElements.includes(selectedElement)) {
|
|
949
|
+
selectedElement.removeAttribute("data-inspector-editing");
|
|
950
|
+
selectedElement.style.outline = "";
|
|
951
|
+
selectedElement.style.outlineOffset = "";
|
|
952
|
+
selectedElement.style.border = "";
|
|
953
|
+
selectedElement.style.boxShadow = "";
|
|
954
|
+
selectedElement.style.transition = "";
|
|
955
|
+
selectedElement.style.position = "";
|
|
956
|
+
selectedElement.style.zIndex = "";
|
|
957
|
+
}
|
|
958
|
+
selectedElement = null;
|
|
959
|
+
selectedElements = [];
|
|
960
|
+
window._inspectorSelectedElement = null;
|
|
961
|
+
isInspecting = false;
|
|
962
|
+
isElementSelected = false;
|
|
963
|
+
lastMultiSelectIntent = false;
|
|
964
|
+
if (document.body) {
|
|
965
|
+
document.body.style.cursor = "";
|
|
966
|
+
document.body.style.userSelect = "";
|
|
967
|
+
}
|
|
968
|
+
location.reload();
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
window._inspectorMessageHandler = messageHandler;
|
|
972
|
+
if (window.__ARCHIE_INSPECTOR__) window.__ARCHIE_INSPECTOR__.messageHandler = messageHandler;
|
|
973
|
+
window.addEventListener("message", messageHandler);
|
|
974
|
+
var mousemoveScheduled = false;
|
|
975
|
+
document.addEventListener(
|
|
976
|
+
"mousemove",
|
|
977
|
+
function(e) {
|
|
978
|
+
if (!isInspecting) return;
|
|
979
|
+
if (mousemoveScheduled) return;
|
|
980
|
+
mousemoveScheduled = true;
|
|
981
|
+
requestAnimationFrame(function() {
|
|
982
|
+
mousemoveScheduled = false;
|
|
983
|
+
var target = getElementFromPoint(e.clientX, e.clientY, e.target);
|
|
984
|
+
if (!target || target === document.body || target === document.documentElement || isInspectorElement(target) || target === highlightedElement || selectedElements.includes(target)) {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (target !== highlightedElement && target !== selectedElement) {
|
|
988
|
+
highlightElement(target);
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
},
|
|
992
|
+
true
|
|
993
|
+
);
|
|
994
|
+
const inspectorClickHandler = function(e) {
|
|
995
|
+
if (!isInspecting) return;
|
|
996
|
+
const target = getElementFromPoint(e.clientX, e.clientY, e.target);
|
|
997
|
+
if (!target || target === document.body || target === document.documentElement || isInspectorElement(target)) {
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
e.preventDefault();
|
|
1001
|
+
e.stopPropagation();
|
|
1002
|
+
e.stopImmediatePropagation();
|
|
1003
|
+
if (target && target !== overlay && target !== selectedElementBadge) {
|
|
1004
|
+
const isMultiSelect = e.metaKey || e.ctrlKey || lastMultiSelectIntent === true;
|
|
1005
|
+
removeHighlight();
|
|
1006
|
+
if (isMultiSelect) {
|
|
1007
|
+
const index = selectedElements.indexOf(target);
|
|
1008
|
+
if (index > -1) {
|
|
1009
|
+
selectedElements.splice(index, 1);
|
|
1010
|
+
removeInspectorStyles(target);
|
|
1011
|
+
cleanupElementListeners(target);
|
|
1012
|
+
} else {
|
|
1013
|
+
selectedElements.push(target);
|
|
1014
|
+
applyInspectorStyles(target);
|
|
1015
|
+
}
|
|
1016
|
+
selectedElements.forEach((el) => {
|
|
1017
|
+
if (el) {
|
|
1018
|
+
applyInspectorStyles(el);
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
} else {
|
|
1022
|
+
const previousSelection = [...selectedElements];
|
|
1023
|
+
previousSelection.forEach((el) => {
|
|
1024
|
+
removeInspectorStyles(el);
|
|
1025
|
+
cleanupElementListeners(el);
|
|
1026
|
+
});
|
|
1027
|
+
selectedElements = [];
|
|
1028
|
+
selectedElements = [target];
|
|
1029
|
+
applyInspectorStyles(target);
|
|
1030
|
+
}
|
|
1031
|
+
selectedElement = selectedElements.length > 0 ? selectedElements[selectedElements.length - 1] : null;
|
|
1032
|
+
window._inspectorSelectedElement = selectedElement;
|
|
1033
|
+
if (window.__ARCHIE_INSPECTOR__) window.__ARCHIE_INSPECTOR__.selectedElement = selectedElement;
|
|
1034
|
+
isElementSelected = selectedElements.length > 0;
|
|
1035
|
+
selectedElements.forEach((el) => {
|
|
1036
|
+
createSelectedBadge(el);
|
|
1037
|
+
});
|
|
1038
|
+
updateSharedHighlights();
|
|
1039
|
+
if (isMultiSelect) {
|
|
1040
|
+
selectedElements.forEach((el) => {
|
|
1041
|
+
if (el) {
|
|
1042
|
+
applyInspectorStyles(el);
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
setTimeout(function() {
|
|
1047
|
+
updateSharedHighlights();
|
|
1048
|
+
if (isMultiSelect && selectedElements.length > 0) {
|
|
1049
|
+
selectedElements.forEach(function(el) {
|
|
1050
|
+
if (el) applyInspectorStyles(el);
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
}, BADGE_UPDATE_DELAY_MS);
|
|
1054
|
+
if (selectedElement) setupBadgePositionListeners(selectedElement);
|
|
1055
|
+
const metadataArray = selectedElements.map((el) => extractMetadata(el));
|
|
1056
|
+
const metadataPayload = metadataArray.length === 1 ? metadataArray[0] : metadataArray;
|
|
1057
|
+
postMessageToParent({
|
|
1058
|
+
type: "ELEMENT_SELECTED",
|
|
1059
|
+
metadata: metadataPayload
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
document.addEventListener("click", inspectorClickHandler, true);
|
|
1064
|
+
document.addEventListener(
|
|
1065
|
+
"click",
|
|
1066
|
+
function(e) {
|
|
1067
|
+
if (isElementSelected && !isInspecting && !isInspectorElement(e.target)) {
|
|
1068
|
+
e.preventDefault();
|
|
1069
|
+
e.stopPropagation();
|
|
1070
|
+
e.stopImmediatePropagation();
|
|
1071
|
+
}
|
|
1072
|
+
},
|
|
1073
|
+
true
|
|
1074
|
+
);
|
|
1075
|
+
document.addEventListener("keydown", function(e) {
|
|
1076
|
+
if (e.key === "Escape" && (isInspecting || isElementSelected)) {
|
|
1077
|
+
isInspecting = false;
|
|
1078
|
+
isElementSelected = false;
|
|
1079
|
+
removeEventBlockers();
|
|
1080
|
+
if (document.body) {
|
|
1081
|
+
document.body.style.cursor = "";
|
|
1082
|
+
document.body.style.userSelect = "";
|
|
1083
|
+
}
|
|
1084
|
+
removeHighlight();
|
|
1085
|
+
removeSelectedBadge();
|
|
1086
|
+
updateSharedHighlights();
|
|
1087
|
+
postMessageToParent({ type: "INSPECTION_CANCELLED" });
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
})();
|
|
1091
|
+
}
|
|
1092
|
+
export {
|
|
1093
|
+
runInspector as default
|
|
1094
|
+
};
|