@archie/devtools 0.0.7 → 0.0.10

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