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