@abbox/inspector 0.4.9 → 0.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/host/client-bridge.d.ts.map +1 -1
- package/dist/host/client-bridge.js +19 -1
- package/dist/host/validate.d.ts.map +1 -1
- package/dist/host/validate.js +28 -1
- package/dist/runtime/inspector.d.ts.map +1 -1
- package/dist/runtime/inspector.js +13 -2
- package/dist/runtime/overlay.d.ts +3 -0
- package/dist/runtime/overlay.d.ts.map +1 -1
- package/dist/runtime/overlay.js +31 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-bridge.d.ts","sourceRoot":"","sources":["../../src/host/client-bridge.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,
|
|
1
|
+
{"version":3,"file":"client-bridge.d.ts","sourceRoot":"","sources":["../../src/host/client-bridge.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CA2FjB"}
|
|
@@ -9,8 +9,26 @@ export function createInspectorClient(options) {
|
|
|
9
9
|
const send = (message) => {
|
|
10
10
|
if (!win.parent || win.parent === win)
|
|
11
11
|
return;
|
|
12
|
+
let sent = false;
|
|
13
|
+
// Try each allowed origin
|
|
12
14
|
for (const targetOrigin of allowedOrigins) {
|
|
13
|
-
|
|
15
|
+
try {
|
|
16
|
+
win.parent.postMessage(message, targetOrigin);
|
|
17
|
+
sent = true;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
// Try next origin
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// If all allowed origins failed, try wildcard
|
|
25
|
+
if (!sent) {
|
|
26
|
+
try {
|
|
27
|
+
win.parent.postMessage(message, "*");
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
// Give up silently
|
|
31
|
+
}
|
|
14
32
|
}
|
|
15
33
|
};
|
|
16
34
|
const base = () => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/host/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAsB,MAAM,gBAAgB,CAAC;AAE3E,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,GACvB,gBAAgB,GAAG,IAAI,CAKzB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,MAAM,GACnB,IAAI,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/host/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAsB,MAAM,gBAAgB,CAAC;AAE3E,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,GACvB,gBAAgB,GAAG,IAAI,CAKzB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,MAAM,GACnB,IAAI,CA6BN"}
|
package/dist/host/validate.js
CHANGED
|
@@ -9,5 +9,32 @@ export function validateIncomingMessage(data, origin, options) {
|
|
|
9
9
|
return data;
|
|
10
10
|
}
|
|
11
11
|
export function postToTarget(target, message, targetOrigin) {
|
|
12
|
-
|
|
12
|
+
// Try primary origin first
|
|
13
|
+
try {
|
|
14
|
+
target.postMessage(message, targetOrigin);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Silently fail and try fallback
|
|
19
|
+
}
|
|
20
|
+
// Try localhost/127.0.0.1 variant
|
|
21
|
+
const variant = targetOrigin
|
|
22
|
+
.replace("://localhost", "://127.0.0.1")
|
|
23
|
+
.replace("://127.0.0.1", "://localhost");
|
|
24
|
+
if (variant !== targetOrigin) {
|
|
25
|
+
try {
|
|
26
|
+
target.postMessage(message, variant);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Silently fail and try wildcard
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Last resort: wildcard (bypasses origin check)
|
|
34
|
+
try {
|
|
35
|
+
target.postMessage(message, "*");
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Give up silently
|
|
39
|
+
}
|
|
13
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspector.d.ts","sourceRoot":"","sources":["../../src/runtime/inspector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"inspector.d.ts","sourceRoot":"","sources":["../../src/runtime/inspector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAkBxE,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAClD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,sBAAsB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,gBAAgB,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;IACpD,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC;IACrD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CA0OlB"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { runtimeElementRefFor } from "./element-ref.js";
|
|
2
2
|
import { extractMetadata, findSourceLocation, sourceKeyFor, sourceMappingStatus, } from "./metadata.js";
|
|
3
|
-
import { createOverlay, hideHighlight, positionHighlight, rectForElement, renderChangeMarkers, } from "./overlay.js";
|
|
3
|
+
import { createOverlay, hideHighlight, hideSelectedHighlight, positionHighlight, positionSelectedHighlight, rectForElement, renderChangeMarkers, } from "./overlay.js";
|
|
4
4
|
export function createInspectorRuntime(options) {
|
|
5
5
|
const { document: doc, window: win } = options;
|
|
6
6
|
const overlay = createOverlay(doc);
|
|
7
7
|
let enabled = false;
|
|
8
8
|
let hovered = null;
|
|
9
|
+
let selected = null;
|
|
9
10
|
const refIdToElement = new Map();
|
|
10
11
|
let markers = [];
|
|
11
12
|
let focusedMarkerId = null;
|
|
@@ -49,8 +50,12 @@ export function createInspectorRuntime(options) {
|
|
|
49
50
|
select(target);
|
|
50
51
|
};
|
|
51
52
|
const onScrollOrResize = () => {
|
|
52
|
-
if (
|
|
53
|
+
if (selected) {
|
|
54
|
+
positionSelectedHighlight(overlay.selectedHighlight, rectForElement(selected));
|
|
55
|
+
}
|
|
56
|
+
if (hovered) {
|
|
53
57
|
positionHighlight(overlay.highlight, rectForElement(hovered));
|
|
58
|
+
}
|
|
54
59
|
if (markers.length) {
|
|
55
60
|
renderChangeMarkers(overlay.markerLayer, markers, (id) => refIdToElement.get(id) ?? null, options.onChangeMarkerSelected);
|
|
56
61
|
}
|
|
@@ -76,7 +81,10 @@ export function createInspectorRuntime(options) {
|
|
|
76
81
|
options.onHover?.(payloadFor(el));
|
|
77
82
|
}
|
|
78
83
|
function select(el) {
|
|
84
|
+
console.log("[inspector] element selected", el.tagName);
|
|
85
|
+
selected = el;
|
|
79
86
|
hovered = el;
|
|
87
|
+
positionSelectedHighlight(overlay.selectedHighlight, rectForElement(el));
|
|
80
88
|
positionHighlight(overlay.highlight, rectForElement(el));
|
|
81
89
|
options.onSelect?.(payloadFor(el));
|
|
82
90
|
}
|
|
@@ -125,7 +133,9 @@ export function createInspectorRuntime(options) {
|
|
|
125
133
|
}
|
|
126
134
|
function clearSelection() {
|
|
127
135
|
hovered = null;
|
|
136
|
+
selected = null;
|
|
128
137
|
hideHighlight(overlay.highlight);
|
|
138
|
+
hideSelectedHighlight(overlay.selectedHighlight);
|
|
129
139
|
options.onClear?.();
|
|
130
140
|
}
|
|
131
141
|
win.addEventListener("scroll", onScrollOrResize, true);
|
|
@@ -145,6 +155,7 @@ export function createInspectorRuntime(options) {
|
|
|
145
155
|
teardownListeners();
|
|
146
156
|
hovered = null;
|
|
147
157
|
hideHighlight(overlay.highlight);
|
|
158
|
+
hideSelectedHighlight(overlay.selectedHighlight);
|
|
148
159
|
clearSelection();
|
|
149
160
|
},
|
|
150
161
|
isEnabled: () => enabled,
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { ChangeMarker, ElementRect } from "../protocol.js";
|
|
2
2
|
export type OverlayHandles = {
|
|
3
3
|
highlight: HTMLDivElement;
|
|
4
|
+
selectedHighlight: HTMLDivElement;
|
|
4
5
|
markerLayer: HTMLDivElement;
|
|
5
6
|
destroy: () => void;
|
|
6
7
|
};
|
|
7
8
|
export declare function createOverlay(root: Document): OverlayHandles;
|
|
8
9
|
export declare function positionHighlight(highlight: HTMLDivElement, rect: ElementRect): void;
|
|
10
|
+
export declare function positionSelectedHighlight(selectedHighlight: HTMLDivElement, rect: ElementRect): void;
|
|
9
11
|
export declare function hideHighlight(highlight: HTMLDivElement): void;
|
|
12
|
+
export declare function hideSelectedHighlight(selectedHighlight: HTMLDivElement): void;
|
|
10
13
|
export declare function rectForElement(el: Element): ElementRect;
|
|
11
14
|
export declare function renderChangeMarkers(layer: HTMLDivElement, markers: ChangeMarker[], resolveElement: (refId: string) => Element | null, onSelect?: (changeId: string) => void): void;
|
|
12
15
|
//# sourceMappingURL=overlay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../src/runtime/overlay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../src/runtime/overlay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMhE,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,cAAc,CAAC;IAC1B,iBAAiB,EAAE,cAAc,CAAC;IAClC,WAAW,EAAE,cAAc,CAAC;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,CAiD5D;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,cAAc,EACzB,IAAI,EAAE,WAAW,GAChB,IAAI,CAQN;AAED,wBAAgB,yBAAyB,CACvC,iBAAiB,EAAE,cAAc,EACjC,IAAI,EAAE,WAAW,GAChB,IAAI,CASN;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,CAE7D;AAED,wBAAgB,qBAAqB,CAAC,iBAAiB,EAAE,cAAc,GAAG,IAAI,CAE7E;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,OAAO,GAAG,WAAW,CAQvD;AAOD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,YAAY,EAAE,EACvB,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,EACjD,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GACpC,IAAI,CA+DN"}
|
package/dist/runtime/overlay.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
const HIGHLIGHT_Z = 2147483646;
|
|
2
|
+
const SELECTED_HIGHLIGHT_Z = 2147483643;
|
|
2
3
|
const MARKER_Z = 2147483645;
|
|
3
4
|
export function createOverlay(root) {
|
|
5
|
+
console.log("[inspector] creating overlay");
|
|
6
|
+
const selectedHighlight = root.createElement("div");
|
|
7
|
+
selectedHighlight.setAttribute("data-abbox-inspector", "selected-highlight");
|
|
8
|
+
Object.assign(selectedHighlight.style, {
|
|
9
|
+
position: "fixed",
|
|
10
|
+
pointerEvents: "none",
|
|
11
|
+
border: "40px dashed #2563eb",
|
|
12
|
+
background: "rgba(37, 99, 235, 0.06)",
|
|
13
|
+
borderRadius: "2px",
|
|
14
|
+
zIndex: String(SELECTED_HIGHLIGHT_Z),
|
|
15
|
+
display: "none",
|
|
16
|
+
boxSizing: "border-box",
|
|
17
|
+
});
|
|
4
18
|
const highlight = root.createElement("div");
|
|
5
19
|
highlight.setAttribute("data-abbox-inspector", "highlight");
|
|
6
20
|
Object.assign(highlight.style, {
|
|
7
21
|
position: "fixed",
|
|
8
22
|
pointerEvents: "none",
|
|
9
|
-
border: "
|
|
23
|
+
border: "20px solid #2563eb",
|
|
10
24
|
background: "rgba(37, 99, 235, 0.12)",
|
|
11
25
|
borderRadius: "2px",
|
|
12
26
|
zIndex: String(HIGHLIGHT_Z),
|
|
@@ -21,11 +35,13 @@ export function createOverlay(root) {
|
|
|
21
35
|
pointerEvents: "none",
|
|
22
36
|
zIndex: String(MARKER_Z),
|
|
23
37
|
});
|
|
24
|
-
root.body.append(highlight, markerLayer);
|
|
38
|
+
root.body.append(selectedHighlight, highlight, markerLayer);
|
|
25
39
|
return {
|
|
26
40
|
highlight,
|
|
41
|
+
selectedHighlight,
|
|
27
42
|
markerLayer,
|
|
28
43
|
destroy: () => {
|
|
44
|
+
selectedHighlight.remove();
|
|
29
45
|
highlight.remove();
|
|
30
46
|
markerLayer.remove();
|
|
31
47
|
},
|
|
@@ -40,9 +56,22 @@ export function positionHighlight(highlight, rect) {
|
|
|
40
56
|
height: `${rect.height}px`,
|
|
41
57
|
});
|
|
42
58
|
}
|
|
59
|
+
export function positionSelectedHighlight(selectedHighlight, rect) {
|
|
60
|
+
console.log("[inspector] positioning selected highlight at", rect);
|
|
61
|
+
Object.assign(selectedHighlight.style, {
|
|
62
|
+
display: "block",
|
|
63
|
+
left: `${rect.x}px`,
|
|
64
|
+
top: `${rect.y}px`,
|
|
65
|
+
width: `${rect.width}px`,
|
|
66
|
+
height: `${rect.height}px`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
43
69
|
export function hideHighlight(highlight) {
|
|
44
70
|
highlight.style.display = "none";
|
|
45
71
|
}
|
|
72
|
+
export function hideSelectedHighlight(selectedHighlight) {
|
|
73
|
+
selectedHighlight.style.display = "none";
|
|
74
|
+
}
|
|
46
75
|
export function rectForElement(el) {
|
|
47
76
|
const r = el.getBoundingClientRect();
|
|
48
77
|
return {
|