@inspecto-dev/core 0.2.0-alpha.4 → 0.3.0-alpha.1
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 +14 -5
- package/dist/chunk-JPRRZPBL.js +46 -0
- package/dist/component-HSGKWEXV.js +6312 -0
- package/dist/component-HSGKWEXV.js.map +1 -0
- package/dist/index.cjs +6394 -904
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -14
- package/dist/index.d.ts +88 -14
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-C4KO2HLL.js +0 -25
- package/dist/component-VOGY7YTT.js +0 -1115
- package/dist/component-VOGY7YTT.js.map +0 -1
- /package/dist/{chunk-C4KO2HLL.js.map → chunk-JPRRZPBL.js.map} +0 -0
|
@@ -1,1115 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__async
|
|
3
|
-
} from "./chunk-C4KO2HLL.js";
|
|
4
|
-
|
|
5
|
-
// src/styles.ts
|
|
6
|
-
var overlayClass = "inspecto-overlay";
|
|
7
|
-
var menuClass = "inspecto-menu";
|
|
8
|
-
var menuItemClass = "inspecto-menu-item";
|
|
9
|
-
var loadingSpinnerClass = "inspecto-spinner";
|
|
10
|
-
var errorMsgClass = "inspecto-error";
|
|
11
|
-
var badgeClass = "inspecto-badge";
|
|
12
|
-
var menuInputClass = "inspecto-menu-input";
|
|
13
|
-
var menuInputWrapperClass = "inspecto-menu-input-wrapper";
|
|
14
|
-
var menuInputIconClass = "inspecto-menu-input-icon";
|
|
15
|
-
var tooltipClass = "inspecto-tooltip";
|
|
16
|
-
var tooltipTopClass = "inspecto-tooltip-top";
|
|
17
|
-
var tooltipBottomClass = "inspecto-tooltip-bottom";
|
|
18
|
-
var tagClass = "inspecto-tag";
|
|
19
|
-
var idClass = "inspecto-id";
|
|
20
|
-
var classClass = "inspecto-class";
|
|
21
|
-
var dimClass = "inspecto-dim";
|
|
22
|
-
var separatorClass = "inspecto-separator";
|
|
23
|
-
var sourceClass = "inspecto-source";
|
|
24
|
-
var shortcutIconClass = "ai-shortcut-icon";
|
|
25
|
-
var darkVars = `
|
|
26
|
-
--inspecto-menu-bg: #252526;
|
|
27
|
-
--inspecto-menu-border: #454545;
|
|
28
|
-
--inspecto-menu-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
|
|
29
|
-
--inspecto-text: #cccccc;
|
|
30
|
-
--inspecto-text-muted: #858585;
|
|
31
|
-
--inspecto-hover-bg: #04395e;
|
|
32
|
-
--inspecto-hover-text: #ffffff;
|
|
33
|
-
--inspecto-hover-icon: #ffffff;
|
|
34
|
-
--inspecto-input-bg: #3c3c3c;
|
|
35
|
-
--inspecto-input-border: #007acc;
|
|
36
|
-
--inspecto-shortcut-text: #858585;
|
|
37
|
-
--inspecto-badge-bg: rgba(30, 30, 30, 0.7);
|
|
38
|
-
--inspecto-badge-text: #e5e5e5;
|
|
39
|
-
--inspecto-badge-active-bg: #007acc;
|
|
40
|
-
--inspecto-badge-active-text: #ffffff;
|
|
41
|
-
--inspecto-badge-border: 1px solid rgba(255, 255, 255, 0.1);
|
|
42
|
-
|
|
43
|
-
--inspecto-tooltip-bg: #222222;
|
|
44
|
-
--inspecto-tooltip-text: #cccccc;
|
|
45
|
-
--inspecto-tooltip-border: #444;
|
|
46
|
-
--inspecto-tooltip-shadow: 0 2px 10px rgba(0,0,0,0.5);
|
|
47
|
-
--inspecto-tag-color: #d16969;
|
|
48
|
-
--inspecto-id-color: #d16969;
|
|
49
|
-
--inspecto-class-color: #9cdcfe;
|
|
50
|
-
--inspecto-dim-color: #858585;
|
|
51
|
-
--inspecto-error-color: #ef4444;
|
|
52
|
-
`;
|
|
53
|
-
var inspectorStyles = `
|
|
54
|
-
:host {
|
|
55
|
-
/* Light theme (default) */
|
|
56
|
-
--inspecto-menu-bg: #ffffff;
|
|
57
|
-
--inspecto-menu-border: #d4d4d4;
|
|
58
|
-
--inspecto-menu-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
59
|
-
--inspecto-text: #333333;
|
|
60
|
-
--inspecto-text-muted: #6b7280;
|
|
61
|
-
--inspecto-hover-bg: #0060c0;
|
|
62
|
-
--inspecto-hover-text: #ffffff;
|
|
63
|
-
--inspecto-hover-icon: #ffffff;
|
|
64
|
-
--inspecto-input-bg: #ffffff;
|
|
65
|
-
--inspecto-input-border: #007acc;
|
|
66
|
-
--inspecto-shortcut-text: #9ca3af;
|
|
67
|
-
--inspecto-badge-bg: rgba(30, 30, 30, 0.7);
|
|
68
|
-
--inspecto-badge-text: #e5e5e5;
|
|
69
|
-
--inspecto-badge-active-bg: #007acc;
|
|
70
|
-
--inspecto-badge-active-text: #ffffff;
|
|
71
|
-
--inspecto-badge-border: 1px solid rgba(255, 255, 255, 0.1);
|
|
72
|
-
|
|
73
|
-
/* Chrome DevTools like colors */
|
|
74
|
-
--inspecto-overlay-border: #4285f4; /* Google Blue */
|
|
75
|
-
--inspecto-overlay-bg: rgba(66, 133, 244, 0.2);
|
|
76
|
-
--inspecto-tooltip-bg: #ffffff;
|
|
77
|
-
--inspecto-tooltip-text: #333333;
|
|
78
|
-
--inspecto-tooltip-border: #ccc;
|
|
79
|
-
--inspecto-tooltip-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
80
|
-
|
|
81
|
-
--inspecto-tag-color: #8b008b; /* Dark magenta */
|
|
82
|
-
--inspecto-id-color: #8b008b;
|
|
83
|
-
--inspecto-class-color: #00008b; /* Dark blue */
|
|
84
|
-
--inspecto-dim-color: #555555;
|
|
85
|
-
--inspecto-error-color: #ef4444;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
:host([data-theme="dark"]) {
|
|
89
|
-
${darkVars}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@media (prefers-color-scheme: dark) {
|
|
93
|
-
:host(:not([data-theme="light"])) {
|
|
94
|
-
${darkVars}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.${overlayClass} {
|
|
99
|
-
position: fixed;
|
|
100
|
-
pointer-events: none;
|
|
101
|
-
z-index: 2147483646;
|
|
102
|
-
border: 1px dashed var(--inspecto-overlay-border);
|
|
103
|
-
background: var(--inspecto-overlay-bg);
|
|
104
|
-
box-sizing: border-box;
|
|
105
|
-
transition: all 0.05s linear;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
.${tooltipClass} {
|
|
109
|
-
position: fixed;
|
|
110
|
-
pointer-events: none;
|
|
111
|
-
z-index: 2147483647;
|
|
112
|
-
background: var(--inspecto-tooltip-bg);
|
|
113
|
-
color: var(--inspecto-tooltip-text);
|
|
114
|
-
border: 1px solid var(--inspecto-tooltip-border);
|
|
115
|
-
border-radius: 4px;
|
|
116
|
-
box-shadow: var(--inspecto-tooltip-shadow);
|
|
117
|
-
padding: 6px 10px;
|
|
118
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
119
|
-
font-size: 12px;
|
|
120
|
-
line-height: 1.4;
|
|
121
|
-
transition: all 0.05s linear;
|
|
122
|
-
display: flex;
|
|
123
|
-
flex-direction: column;
|
|
124
|
-
gap: 4px;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/* Create the small pointer arrow like Chrome DevTools */
|
|
128
|
-
.${tooltipClass}::after {
|
|
129
|
-
content: '';
|
|
130
|
-
position: absolute;
|
|
131
|
-
width: 0;
|
|
132
|
-
height: 0;
|
|
133
|
-
border-style: solid;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
.${tooltipTopClass}::after {
|
|
137
|
-
bottom: -6px;
|
|
138
|
-
left: var(--inspecto-arrow-left, 10px);
|
|
139
|
-
border-width: 6px 6px 0 6px;
|
|
140
|
-
border-color: var(--inspecto-tooltip-bg) transparent transparent transparent;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
.${tooltipBottomClass}::after {
|
|
144
|
-
top: -6px;
|
|
145
|
-
left: var(--inspecto-arrow-left, 10px);
|
|
146
|
-
border-width: 0 6px 6px 6px;
|
|
147
|
-
border-color: transparent transparent var(--inspecto-tooltip-bg) transparent;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/* Outline for the arrow to match border */
|
|
151
|
-
.${tooltipClass}::before {
|
|
152
|
-
content: '';
|
|
153
|
-
position: absolute;
|
|
154
|
-
width: 0;
|
|
155
|
-
height: 0;
|
|
156
|
-
border-style: solid;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
.${tooltipTopClass}::before {
|
|
160
|
-
bottom: -7px;
|
|
161
|
-
left: calc(var(--inspecto-arrow-left, 10px) - 1px);
|
|
162
|
-
border-width: 7px 7px 0 7px;
|
|
163
|
-
border-color: var(--inspecto-tooltip-border) transparent transparent transparent;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
.${tooltipBottomClass}::before {
|
|
167
|
-
top: -7px;
|
|
168
|
-
left: calc(var(--inspecto-arrow-left, 10px) - 1px);
|
|
169
|
-
border-width: 0 7px 7px 7px;
|
|
170
|
-
border-color: transparent transparent var(--inspecto-tooltip-border) transparent;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
.${tagClass} {
|
|
174
|
-
color: var(--inspecto-tag-color);
|
|
175
|
-
font-weight: 600;
|
|
176
|
-
font-family: monospace;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
.${idClass} {
|
|
180
|
-
color: var(--inspecto-id-color);
|
|
181
|
-
font-weight: 600;
|
|
182
|
-
font-family: monospace;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
.${classClass} {
|
|
186
|
-
color: var(--inspecto-class-color);
|
|
187
|
-
font-family: monospace;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
.${dimClass} {
|
|
191
|
-
color: var(--inspecto-dim-color);
|
|
192
|
-
margin-left: 4px;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
.${separatorClass} {
|
|
196
|
-
height: 1px;
|
|
197
|
-
background: var(--inspecto-tooltip-border);
|
|
198
|
-
margin: 2px -10px;
|
|
199
|
-
opacity: 0.5;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
.${sourceClass} {
|
|
203
|
-
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
204
|
-
font-size: 11px;
|
|
205
|
-
color: var(--inspecto-text-muted);
|
|
206
|
-
white-space: nowrap;
|
|
207
|
-
overflow: hidden;
|
|
208
|
-
text-overflow: ellipsis;
|
|
209
|
-
max-width: 300px;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
.${menuClass} {
|
|
213
|
-
position: fixed;
|
|
214
|
-
z-index: 2147483647;
|
|
215
|
-
background: var(--inspecto-menu-bg);
|
|
216
|
-
border: 1px solid var(--inspecto-menu-border);
|
|
217
|
-
border-radius: 6px;
|
|
218
|
-
padding: 6px;
|
|
219
|
-
min-width: 300px;
|
|
220
|
-
box-shadow: var(--inspecto-menu-shadow);
|
|
221
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
222
|
-
color: var(--inspecto-text);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
.${menuInputWrapperClass} {
|
|
226
|
-
display: flex;
|
|
227
|
-
align-items: center;
|
|
228
|
-
border: 1px solid var(--inspecto-menu-border);
|
|
229
|
-
border-radius: 4px;
|
|
230
|
-
padding: 6px 8px;
|
|
231
|
-
margin: 4px;
|
|
232
|
-
margin-bottom: 8px;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
.${menuInputWrapperClass}:focus-within {
|
|
236
|
-
border-color: var(--inspecto-input-border);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
.${menuInputClass} {
|
|
240
|
-
width: 100%;
|
|
241
|
-
border: none;
|
|
242
|
-
outline: none;
|
|
243
|
-
font-size: 13px;
|
|
244
|
-
color: var(--inspecto-text);
|
|
245
|
-
background: transparent;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
.${menuInputClass}::placeholder {
|
|
249
|
-
color: var(--inspecto-text-muted);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
.${menuInputIconClass} {
|
|
253
|
-
color: var(--inspecto-text-muted);
|
|
254
|
-
display: flex;
|
|
255
|
-
align-items: center;
|
|
256
|
-
justify-content: center;
|
|
257
|
-
margin-left: 4px;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
.${menuInputIconClass}:hover {
|
|
261
|
-
color: var(--inspecto-text);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
.${menuItemClass} {
|
|
265
|
-
display: flex;
|
|
266
|
-
align-items: center;
|
|
267
|
-
gap: 8px;
|
|
268
|
-
width: 100%;
|
|
269
|
-
padding: 6px 10px;
|
|
270
|
-
margin: 2px 0;
|
|
271
|
-
border: none;
|
|
272
|
-
border-radius: 4px;
|
|
273
|
-
background: transparent;
|
|
274
|
-
color: var(--inspecto-text);
|
|
275
|
-
font-size: 13px;
|
|
276
|
-
cursor: pointer;
|
|
277
|
-
text-align: left;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
.${menuItemClass}:hover {
|
|
281
|
-
background: var(--inspecto-hover-bg);
|
|
282
|
-
color: var(--inspecto-hover-text);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
.${menuItemClass} .${shortcutIconClass} {
|
|
286
|
-
margin-left: auto;
|
|
287
|
-
color: var(--inspecto-text-muted);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
.${menuItemClass}:hover .${shortcutIconClass} {
|
|
291
|
-
color: var(--inspecto-hover-icon);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
@keyframes spin {
|
|
295
|
-
to { transform: rotate(360deg); }
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
.${loadingSpinnerClass} {
|
|
299
|
-
width: 14px;
|
|
300
|
-
height: 14px;
|
|
301
|
-
border: 2px solid var(--inspecto-overlay-border);
|
|
302
|
-
border-top-color: transparent;
|
|
303
|
-
border-radius: 50%;
|
|
304
|
-
animation: spin 0.7s linear infinite;
|
|
305
|
-
margin: 4px auto;
|
|
306
|
-
display: block;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
.${errorMsgClass} {
|
|
310
|
-
font-size: 11px;
|
|
311
|
-
color: var(--inspecto-error-color);
|
|
312
|
-
padding: 4px 8px;
|
|
313
|
-
text-align: center;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
.${badgeClass} {
|
|
317
|
-
position: fixed;
|
|
318
|
-
bottom: 16px;
|
|
319
|
-
right: 16px;
|
|
320
|
-
z-index: 2147483645;
|
|
321
|
-
background: var(--inspecto-badge-bg);
|
|
322
|
-
color: var(--inspecto-badge-text);
|
|
323
|
-
border: var(--inspecto-badge-border);
|
|
324
|
-
border-radius: 20px;
|
|
325
|
-
padding: 6px 12px;
|
|
326
|
-
font-size: 12px;
|
|
327
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
328
|
-
cursor: grab;
|
|
329
|
-
opacity: 0.85;
|
|
330
|
-
transition: background 0.2s, color 0.2s, opacity 0.2s, box-shadow 0.2s;
|
|
331
|
-
pointer-events: all;
|
|
332
|
-
backdrop-filter: blur(4px);
|
|
333
|
-
-webkit-backdrop-filter: blur(4px);
|
|
334
|
-
display: flex;
|
|
335
|
-
align-items: center;
|
|
336
|
-
gap: 6px;
|
|
337
|
-
user-select: none;
|
|
338
|
-
-webkit-user-select: none;
|
|
339
|
-
touch-action: none;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
.${badgeClass}:active {
|
|
343
|
-
cursor: grabbing;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
.${badgeClass}-close {
|
|
347
|
-
display: inline-flex;
|
|
348
|
-
align-items: center;
|
|
349
|
-
justify-content: center;
|
|
350
|
-
width: 16px;
|
|
351
|
-
height: 16px;
|
|
352
|
-
border-radius: 50%;
|
|
353
|
-
background: transparent;
|
|
354
|
-
color: currentColor;
|
|
355
|
-
font-size: 14px;
|
|
356
|
-
line-height: 1;
|
|
357
|
-
opacity: 0.5;
|
|
358
|
-
transition: opacity 0.2s, background 0.2s;
|
|
359
|
-
margin-left: 2px;
|
|
360
|
-
cursor: pointer;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
.${badgeClass}-close:hover {
|
|
364
|
-
opacity: 1;
|
|
365
|
-
background: rgba(255, 255, 255, 0.2);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
.${badgeClass}.active {
|
|
369
|
-
background: var(--inspecto-badge-active-bg);
|
|
370
|
-
color: var(--inspecto-badge-active-text);
|
|
371
|
-
border: 1px solid transparent;
|
|
372
|
-
box-shadow: 0 0 10px rgba(0, 122, 204, 0.3);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
.${badgeClass}.disabled {
|
|
376
|
-
background: rgba(30, 30, 30, 0.4);
|
|
377
|
-
color: rgba(229, 229, 229, 0.5);
|
|
378
|
-
text-decoration: line-through;
|
|
379
|
-
border: 1px dashed rgba(255, 255, 255, 0.1);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
.${badgeClass}.disabled .${badgeClass}-close {
|
|
383
|
-
opacity: 0.8;
|
|
384
|
-
text-decoration: none;
|
|
385
|
-
transform: rotate(45deg);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
.${badgeClass}:hover {
|
|
389
|
-
opacity: 1;
|
|
390
|
-
}
|
|
391
|
-
`;
|
|
392
|
-
|
|
393
|
-
// src/overlay.ts
|
|
394
|
-
var GAP = 8;
|
|
395
|
-
var EDGE_MARGIN = 4;
|
|
396
|
-
function createOverlay(shadowRoot) {
|
|
397
|
-
const overlay = document.createElement("div");
|
|
398
|
-
overlay.className = overlayClass;
|
|
399
|
-
overlay.style.display = "none";
|
|
400
|
-
const tooltip = document.createElement("div");
|
|
401
|
-
tooltip.className = tooltipClass;
|
|
402
|
-
const tagSpan = document.createElement("span");
|
|
403
|
-
tagSpan.className = tagClass;
|
|
404
|
-
const idSpan = document.createElement("span");
|
|
405
|
-
idSpan.className = idClass;
|
|
406
|
-
const classSpan = document.createElement("span");
|
|
407
|
-
classSpan.className = classClass;
|
|
408
|
-
const dimSpan = document.createElement("span");
|
|
409
|
-
dimSpan.className = dimClass;
|
|
410
|
-
const separator = document.createElement("div");
|
|
411
|
-
separator.className = separatorClass;
|
|
412
|
-
const sourceSpan = document.createElement("div");
|
|
413
|
-
sourceSpan.className = sourceClass;
|
|
414
|
-
tooltip.appendChild(tagSpan);
|
|
415
|
-
tooltip.appendChild(idSpan);
|
|
416
|
-
tooltip.appendChild(classSpan);
|
|
417
|
-
tooltip.appendChild(document.createTextNode(" "));
|
|
418
|
-
tooltip.appendChild(dimSpan);
|
|
419
|
-
tooltip.appendChild(separator);
|
|
420
|
-
tooltip.appendChild(sourceSpan);
|
|
421
|
-
shadowRoot.appendChild(overlay);
|
|
422
|
-
shadowRoot.appendChild(tooltip);
|
|
423
|
-
function show(el, sourceLabel) {
|
|
424
|
-
const rect = el.getBoundingClientRect();
|
|
425
|
-
overlay.style.display = "block";
|
|
426
|
-
overlay.style.left = `${rect.left}px`;
|
|
427
|
-
overlay.style.top = `${rect.top}px`;
|
|
428
|
-
overlay.style.width = `${rect.width}px`;
|
|
429
|
-
overlay.style.height = `${rect.height}px`;
|
|
430
|
-
const tagName = el.tagName.toLowerCase();
|
|
431
|
-
tagSpan.textContent = tagName;
|
|
432
|
-
idSpan.textContent = el.id ? `#${el.id}` : "";
|
|
433
|
-
const classes = Array.from(el.classList).map((c) => `.${c}`).join("");
|
|
434
|
-
classSpan.textContent = classes;
|
|
435
|
-
dimSpan.textContent = `${Math.round(rect.width)} \xD7 ${Math.round(rect.height)}`;
|
|
436
|
-
sourceSpan.textContent = sourceLabel;
|
|
437
|
-
tooltip.style.visibility = "hidden";
|
|
438
|
-
tooltip.style.display = "block";
|
|
439
|
-
const tooltipRect = tooltip.getBoundingClientRect();
|
|
440
|
-
const viewportWidth = document.documentElement.clientWidth || window.innerWidth;
|
|
441
|
-
const viewportHeight = document.documentElement.clientHeight || window.innerHeight;
|
|
442
|
-
let tooltipTop = rect.top - tooltipRect.height - GAP;
|
|
443
|
-
let isBottom = false;
|
|
444
|
-
if (tooltipTop < EDGE_MARGIN) {
|
|
445
|
-
tooltipTop = rect.bottom + GAP;
|
|
446
|
-
if (tooltipTop + tooltipRect.height > viewportHeight - EDGE_MARGIN) {
|
|
447
|
-
tooltipTop = viewportHeight - tooltipRect.height - EDGE_MARGIN;
|
|
448
|
-
}
|
|
449
|
-
isBottom = true;
|
|
450
|
-
}
|
|
451
|
-
tooltip.classList.toggle(tooltipBottomClass, isBottom);
|
|
452
|
-
tooltip.classList.toggle(tooltipTopClass, !isBottom);
|
|
453
|
-
let tooltipLeft = rect.left;
|
|
454
|
-
if (tooltipLeft + tooltipRect.width > viewportWidth - EDGE_MARGIN) {
|
|
455
|
-
tooltipLeft = viewportWidth - tooltipRect.width - EDGE_MARGIN;
|
|
456
|
-
}
|
|
457
|
-
if (tooltipLeft < EDGE_MARGIN) {
|
|
458
|
-
tooltipLeft = EDGE_MARGIN;
|
|
459
|
-
}
|
|
460
|
-
const targetPointX = rect.left + Math.min(15, rect.width / 2);
|
|
461
|
-
let arrowLeft = targetPointX - tooltipLeft;
|
|
462
|
-
arrowLeft = Math.max(6, Math.min(arrowLeft, tooltipRect.width - 18));
|
|
463
|
-
tooltip.style.left = `${tooltipLeft}px`;
|
|
464
|
-
tooltip.style.top = `${tooltipTop}px`;
|
|
465
|
-
tooltip.style.setProperty("--inspecto-arrow-left", `${arrowLeft}px`);
|
|
466
|
-
tooltip.style.visibility = "visible";
|
|
467
|
-
}
|
|
468
|
-
function hide() {
|
|
469
|
-
overlay.style.display = "none";
|
|
470
|
-
tooltip.style.display = "none";
|
|
471
|
-
}
|
|
472
|
-
return { show, hide };
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// src/intents.ts
|
|
476
|
-
function CUSTOM_PROMPT_TEMPLATE(userPrompt) {
|
|
477
|
-
return userPrompt;
|
|
478
|
-
}
|
|
479
|
-
function detectFramework(fileName) {
|
|
480
|
-
var _a;
|
|
481
|
-
const ext = ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
482
|
-
switch (ext) {
|
|
483
|
-
case "vue":
|
|
484
|
-
return "Vue";
|
|
485
|
-
case "svelte":
|
|
486
|
-
return "Svelte";
|
|
487
|
-
case "astro":
|
|
488
|
-
return "Astro";
|
|
489
|
-
case "jsx":
|
|
490
|
-
case "tsx":
|
|
491
|
-
return "React";
|
|
492
|
-
case "ts":
|
|
493
|
-
case "js":
|
|
494
|
-
return "JavaScript/TypeScript";
|
|
495
|
-
default:
|
|
496
|
-
return "UI";
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
function buildPrompt(template, location, snippetResult) {
|
|
500
|
-
var _a, _b, _c;
|
|
501
|
-
const shortFile = (_a = location.file.split("/").pop()) != null ? _a : location.file;
|
|
502
|
-
const ext = ((_b = shortFile.split(".").pop()) == null ? void 0 : _b.toLowerCase()) || "tsx";
|
|
503
|
-
const framework = detectFramework(shortFile);
|
|
504
|
-
let finalPrompt = template.replace(/\{\{file\}\}/g, location.file).replace(/\{\{line\}\}/g, String(location.line)).replace(/\{\{column\}\}/g, String(location.column)).replace(/\{\{ext\}\}/g, ext).replace(/\{\{framework\}\}/g, framework).replace(/\{\{name\}\}/g, shortFile);
|
|
505
|
-
if (snippetResult && snippetResult.snippet) {
|
|
506
|
-
const name = (_c = snippetResult.name) != null ? _c : shortFile;
|
|
507
|
-
finalPrompt = finalPrompt.replace(/\{\{name\}\}/g, name);
|
|
508
|
-
finalPrompt += `
|
|
509
|
-
|
|
510
|
-
Context from \`${location.file}\` (line ${location.line}):
|
|
511
|
-
\`\`\`${ext}
|
|
512
|
-
${snippetResult.snippet}
|
|
513
|
-
\`\`\``;
|
|
514
|
-
}
|
|
515
|
-
return finalPrompt;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// src/http.ts
|
|
519
|
-
import { INSPECTO_API_PATHS } from "@inspecto-dev/types";
|
|
520
|
-
var BASE_URL = globalThis.__AI_INSPECTOR_SERVER_URL__ || "http://127.0.0.1:5678";
|
|
521
|
-
function setBaseUrl(url) {
|
|
522
|
-
BASE_URL = url.replace(/\/$/, "");
|
|
523
|
-
}
|
|
524
|
-
var cachedConfig = null;
|
|
525
|
-
function fetchIdeInfo(force = false) {
|
|
526
|
-
return __async(this, null, function* () {
|
|
527
|
-
if (cachedConfig && !force) return cachedConfig;
|
|
528
|
-
try {
|
|
529
|
-
const res = yield fetch(`${BASE_URL}${INSPECTO_API_PATHS.CLIENT_CONFIG}`);
|
|
530
|
-
if (!res.ok) return null;
|
|
531
|
-
cachedConfig = yield res.json();
|
|
532
|
-
return cachedConfig;
|
|
533
|
-
} catch (e) {
|
|
534
|
-
return null;
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
function openFile(req) {
|
|
539
|
-
return __async(this, null, function* () {
|
|
540
|
-
try {
|
|
541
|
-
const res = yield fetch(`${BASE_URL}${INSPECTO_API_PATHS.IDE_OPEN}`, {
|
|
542
|
-
method: "POST",
|
|
543
|
-
headers: { "Content-Type": "application/json" },
|
|
544
|
-
body: JSON.stringify(req)
|
|
545
|
-
});
|
|
546
|
-
return res.ok;
|
|
547
|
-
} catch (e) {
|
|
548
|
-
return false;
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
function fetchSnippet(file, line, column, maxLines = 100) {
|
|
553
|
-
return __async(this, null, function* () {
|
|
554
|
-
const params = new URLSearchParams({
|
|
555
|
-
file,
|
|
556
|
-
line: String(line),
|
|
557
|
-
column: String(column),
|
|
558
|
-
maxLines: String(maxLines)
|
|
559
|
-
});
|
|
560
|
-
const res = yield fetch(`${BASE_URL}${INSPECTO_API_PATHS.PROJECT_SNIPPET}?${params}`);
|
|
561
|
-
if (!res.ok) {
|
|
562
|
-
const err = yield res.json().catch(() => ({}));
|
|
563
|
-
throw Object.assign(new Error("snippet fetch failed"), { errorCode: err.errorCode });
|
|
564
|
-
}
|
|
565
|
-
return res.json();
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
function sendToAi(req) {
|
|
569
|
-
return __async(this, null, function* () {
|
|
570
|
-
var _a;
|
|
571
|
-
const res = yield fetch(`${BASE_URL}${INSPECTO_API_PATHS.AI_DISPATCH}`, {
|
|
572
|
-
method: "POST",
|
|
573
|
-
headers: { "Content-Type": "application/json" },
|
|
574
|
-
body: JSON.stringify(req)
|
|
575
|
-
});
|
|
576
|
-
if (!res.ok) {
|
|
577
|
-
const err = yield res.json().catch(() => ({}));
|
|
578
|
-
return {
|
|
579
|
-
success: false,
|
|
580
|
-
error: (_a = err.error) != null ? _a : "Request failed",
|
|
581
|
-
errorCode: err.errorCode
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
return res.json();
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
// src/menu.ts
|
|
589
|
-
var MENU_WIDTH = 280;
|
|
590
|
-
function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose) {
|
|
591
|
-
var _a, _b;
|
|
592
|
-
const maxSnippetLines = (_a = options.maxSnippetLines) != null ? _a : 100;
|
|
593
|
-
const includeSnippet = (_b = options.includeSnippet) != null ? _b : false;
|
|
594
|
-
const menu = document.createElement("div");
|
|
595
|
-
menu.className = menuClass;
|
|
596
|
-
const { input, inputWrapper, sendIcon } = createAskInput(options.askPlaceholder);
|
|
597
|
-
menu.appendChild(inputWrapper);
|
|
598
|
-
const separator = document.createElement("div");
|
|
599
|
-
separator.style.height = "1px";
|
|
600
|
-
separator.style.background = "var(--inspecto-menu-border)";
|
|
601
|
-
separator.style.margin = "8px 4px 6px 4px";
|
|
602
|
-
menu.appendChild(separator);
|
|
603
|
-
const loadingEl = document.createElement("div");
|
|
604
|
-
loadingEl.className = loadingSpinnerClass;
|
|
605
|
-
menu.appendChild(loadingEl);
|
|
606
|
-
const viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
|
|
607
|
-
const safeWidth = viewportWidth > 0 ? viewportWidth : MENU_WIDTH;
|
|
608
|
-
menu.style.left = `${Math.min(clickX, Math.max(safeWidth - MENU_WIDTH, 0))}px`;
|
|
609
|
-
menu.style.visibility = "hidden";
|
|
610
|
-
menu.style.display = "block";
|
|
611
|
-
shadowRoot.appendChild(menu);
|
|
612
|
-
const updatePosition = () => {
|
|
613
|
-
const rect = menu.getBoundingClientRect();
|
|
614
|
-
const viewportHeight = Math.max(
|
|
615
|
-
document.documentElement.clientHeight || 0,
|
|
616
|
-
window.innerHeight || 0
|
|
617
|
-
);
|
|
618
|
-
const safeHeight = viewportHeight > 0 ? viewportHeight : rect.height + 16;
|
|
619
|
-
menu.style.top = `${Math.min(clickY + 8, Math.max(safeHeight - rect.height - 8, 0))}px`;
|
|
620
|
-
};
|
|
621
|
-
updatePosition();
|
|
622
|
-
menu.style.visibility = "visible";
|
|
623
|
-
setTimeout(() => input.focus(), 0);
|
|
624
|
-
const onDocClick = (e) => {
|
|
625
|
-
const path = e.composedPath();
|
|
626
|
-
if (path.includes(menu)) return;
|
|
627
|
-
cleanup();
|
|
628
|
-
};
|
|
629
|
-
setTimeout(() => document.addEventListener("click", onDocClick, { capture: true }), 0);
|
|
630
|
-
function cleanup() {
|
|
631
|
-
document.removeEventListener("click", onDocClick, { capture: true });
|
|
632
|
-
menu.remove();
|
|
633
|
-
onClose();
|
|
634
|
-
}
|
|
635
|
-
const handleSend = (promptText, snippetText, disable, restore) => __async(null, null, function* () {
|
|
636
|
-
var _a2, _b2;
|
|
637
|
-
disable();
|
|
638
|
-
const opened = yield openFile(location);
|
|
639
|
-
if (!opened) {
|
|
640
|
-
restore();
|
|
641
|
-
showError(menu, "Unable to open file in the IDE.", "IDE_UNAVAILABLE");
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
yield new Promise((r) => setTimeout(r, 100));
|
|
645
|
-
const result = yield sendToAi({ location, snippet: snippetText, prompt: promptText });
|
|
646
|
-
if (result.success) {
|
|
647
|
-
if ((_a2 = result.fallbackPayload) == null ? void 0 : _a2.prompt) {
|
|
648
|
-
try {
|
|
649
|
-
yield navigator.clipboard.writeText(result.fallbackPayload.prompt);
|
|
650
|
-
} catch (e) {
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
cleanup();
|
|
654
|
-
} else {
|
|
655
|
-
restore();
|
|
656
|
-
showError(menu, (_b2 = result.error) != null ? _b2 : "Unknown error", result.errorCode);
|
|
657
|
-
}
|
|
658
|
-
});
|
|
659
|
-
const submitAsk = () => __async(null, null, function* () {
|
|
660
|
-
if (!input.value.trim()) return;
|
|
661
|
-
input.disabled = true;
|
|
662
|
-
sendIcon.style.pointerEvents = "none";
|
|
663
|
-
try {
|
|
664
|
-
let snippetResult = null;
|
|
665
|
-
if (includeSnippet) {
|
|
666
|
-
snippetResult = yield fetchSnippet(
|
|
667
|
-
location.file,
|
|
668
|
-
location.line,
|
|
669
|
-
location.column,
|
|
670
|
-
maxSnippetLines
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
const prompt = buildPrompt(
|
|
674
|
-
CUSTOM_PROMPT_TEMPLATE(input.value.trim()),
|
|
675
|
-
location,
|
|
676
|
-
snippetResult
|
|
677
|
-
);
|
|
678
|
-
yield handleSend(
|
|
679
|
-
prompt,
|
|
680
|
-
(snippetResult == null ? void 0 : snippetResult.snippet) || "",
|
|
681
|
-
() => {
|
|
682
|
-
},
|
|
683
|
-
// already disabled
|
|
684
|
-
() => {
|
|
685
|
-
input.disabled = false;
|
|
686
|
-
sendIcon.style.pointerEvents = "auto";
|
|
687
|
-
}
|
|
688
|
-
);
|
|
689
|
-
} catch (err) {
|
|
690
|
-
input.disabled = false;
|
|
691
|
-
sendIcon.style.pointerEvents = "auto";
|
|
692
|
-
showError(menu, err.message, err.errorCode);
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
input.addEventListener("keydown", (e) => {
|
|
696
|
-
if (e.key === "Enter") submitAsk();
|
|
697
|
-
});
|
|
698
|
-
sendIcon.addEventListener("click", submitAsk);
|
|
699
|
-
fetchIdeInfo().then((ideInfo) => {
|
|
700
|
-
var _a2, _b2, _c, _d;
|
|
701
|
-
loadingEl.remove();
|
|
702
|
-
const intents = (ideInfo == null ? void 0 : ideInfo.prompts) || [];
|
|
703
|
-
for (const intent of intents) {
|
|
704
|
-
if (intent.isAction && intent.id === "open-in-editor") {
|
|
705
|
-
const btn2 = document.createElement("button");
|
|
706
|
-
btn2.className = menuItemClass;
|
|
707
|
-
const span = document.createElement("span");
|
|
708
|
-
span.textContent = (_a2 = intent.label) != null ? _a2 : "Unknown";
|
|
709
|
-
btn2.appendChild(span);
|
|
710
|
-
const shortcutDiv = document.createElement("div");
|
|
711
|
-
shortcutDiv.className = shortcutIconClass;
|
|
712
|
-
shortcutDiv.textContent = "\u21B5";
|
|
713
|
-
btn2.appendChild(shortcutDiv);
|
|
714
|
-
btn2.addEventListener("click", (e) => __async(null, null, function* () {
|
|
715
|
-
e.stopPropagation();
|
|
716
|
-
btn2.disabled = true;
|
|
717
|
-
const opened = yield openFile(location);
|
|
718
|
-
if (opened) {
|
|
719
|
-
cleanup();
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
btn2.disabled = false;
|
|
723
|
-
showError(menu, "Unable to open file in the IDE.", "IDE_UNAVAILABLE");
|
|
724
|
-
}));
|
|
725
|
-
menu.appendChild(btn2);
|
|
726
|
-
continue;
|
|
727
|
-
}
|
|
728
|
-
let fullPromptTemplate = (_b2 = intent.prompt) != null ? _b2 : "";
|
|
729
|
-
if (intent.prependPrompt)
|
|
730
|
-
fullPromptTemplate = intent.prependPrompt + "\n\n" + fullPromptTemplate;
|
|
731
|
-
if (intent.appendPrompt)
|
|
732
|
-
fullPromptTemplate = fullPromptTemplate + "\n\n" + intent.appendPrompt;
|
|
733
|
-
const label = (_d = (_c = intent.label) != null ? _c : intent.id) != null ? _d : "Unknown";
|
|
734
|
-
const btn = document.createElement("button");
|
|
735
|
-
btn.className = menuItemClass;
|
|
736
|
-
btn.textContent = label;
|
|
737
|
-
btn.addEventListener("click", (e) => __async(null, null, function* () {
|
|
738
|
-
e.stopPropagation();
|
|
739
|
-
btn.disabled = true;
|
|
740
|
-
btn.textContent = "Sending...";
|
|
741
|
-
try {
|
|
742
|
-
let snippetResult = null;
|
|
743
|
-
if (includeSnippet) {
|
|
744
|
-
snippetResult = yield fetchSnippet(
|
|
745
|
-
location.file,
|
|
746
|
-
location.line,
|
|
747
|
-
location.column,
|
|
748
|
-
maxSnippetLines
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
const prompt = buildPrompt(fullPromptTemplate, location, snippetResult);
|
|
752
|
-
yield handleSend(
|
|
753
|
-
prompt,
|
|
754
|
-
(snippetResult == null ? void 0 : snippetResult.snippet) || "",
|
|
755
|
-
() => {
|
|
756
|
-
},
|
|
757
|
-
// already disabled
|
|
758
|
-
() => {
|
|
759
|
-
btn.disabled = false;
|
|
760
|
-
btn.textContent = label;
|
|
761
|
-
}
|
|
762
|
-
);
|
|
763
|
-
} catch (err) {
|
|
764
|
-
btn.disabled = false;
|
|
765
|
-
btn.textContent = label;
|
|
766
|
-
showError(menu, err.message, err.errorCode);
|
|
767
|
-
}
|
|
768
|
-
}));
|
|
769
|
-
menu.appendChild(btn);
|
|
770
|
-
}
|
|
771
|
-
updatePosition();
|
|
772
|
-
}).catch((err) => {
|
|
773
|
-
var _a2;
|
|
774
|
-
loadingEl.remove();
|
|
775
|
-
const isServerDown = err instanceof TypeError;
|
|
776
|
-
showError(
|
|
777
|
-
menu,
|
|
778
|
-
isServerDown ? "Cannot connect to inspector server. Is the dev server running?" : err.message,
|
|
779
|
-
(_a2 = err.errorCode) != null ? _a2 : "UNKNOWN"
|
|
780
|
-
);
|
|
781
|
-
updatePosition();
|
|
782
|
-
});
|
|
783
|
-
return cleanup;
|
|
784
|
-
}
|
|
785
|
-
function createAskInput(placeholder) {
|
|
786
|
-
const inputWrapper = document.createElement("div");
|
|
787
|
-
inputWrapper.className = menuInputWrapperClass;
|
|
788
|
-
const input = document.createElement("input");
|
|
789
|
-
input.className = menuInputClass;
|
|
790
|
-
input.type = "text";
|
|
791
|
-
input.placeholder = placeholder != null ? placeholder : "Describe how to change this component...";
|
|
792
|
-
const sendIcon = document.createElement("div");
|
|
793
|
-
sendIcon.className = menuInputIconClass;
|
|
794
|
-
sendIcon.innerHTML = `<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>`;
|
|
795
|
-
sendIcon.style.cursor = "pointer";
|
|
796
|
-
inputWrapper.appendChild(input);
|
|
797
|
-
inputWrapper.appendChild(sendIcon);
|
|
798
|
-
return { input, inputWrapper, sendIcon };
|
|
799
|
-
}
|
|
800
|
-
function showError(menu, message, errorCode) {
|
|
801
|
-
var _a;
|
|
802
|
-
(_a = menu.querySelector(`.${errorMsgClass}`)) == null ? void 0 : _a.remove();
|
|
803
|
-
const errEl = document.createElement("div");
|
|
804
|
-
errEl.className = errorMsgClass;
|
|
805
|
-
errEl.textContent = errorCode === "FILE_NOT_FOUND" ? "Source file not found. Is the server running?" : `Error: ${message}`;
|
|
806
|
-
menu.appendChild(errEl);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
// src/component.ts
|
|
810
|
-
var ATTR_NAME = "data-inspecto";
|
|
811
|
-
function parseAttrValue(value) {
|
|
812
|
-
const parts = value.split(":");
|
|
813
|
-
if (parts.length < 3) return null;
|
|
814
|
-
const col = parseInt(parts[parts.length - 1], 10);
|
|
815
|
-
const line = parseInt(parts[parts.length - 2], 10);
|
|
816
|
-
const file = parts.slice(0, parts.length - 2).join(":");
|
|
817
|
-
if (isNaN(line) || isNaN(col) || !file) return null;
|
|
818
|
-
return { file, line, column: col };
|
|
819
|
-
}
|
|
820
|
-
function findInspectable(el) {
|
|
821
|
-
while (el) {
|
|
822
|
-
if (el.hasAttribute(ATTR_NAME)) return el;
|
|
823
|
-
el = el.parentElement;
|
|
824
|
-
}
|
|
825
|
-
return null;
|
|
826
|
-
}
|
|
827
|
-
function parseHotKeyString(hotKey) {
|
|
828
|
-
const keys = hotKey.split("+").map((k) => k.trim().toLowerCase());
|
|
829
|
-
const result = [];
|
|
830
|
-
if (keys.includes("alt") || keys.includes("option")) result.push("altKey");
|
|
831
|
-
if (keys.includes("ctrl") || keys.includes("control")) result.push("ctrlKey");
|
|
832
|
-
if (keys.includes("meta") || keys.includes("cmd") || keys.includes("command") || keys.includes("win"))
|
|
833
|
-
result.push("metaKey");
|
|
834
|
-
if (keys.includes("shift")) result.push("shiftKey");
|
|
835
|
-
return result;
|
|
836
|
-
}
|
|
837
|
-
function hotKeysHeld(event, hotKeys) {
|
|
838
|
-
if (!hotKeys) return false;
|
|
839
|
-
const mappedKeys = parseHotKeyString(hotKeys);
|
|
840
|
-
if (mappedKeys.length === 0) return false;
|
|
841
|
-
return mappedKeys.every((key) => event[key]);
|
|
842
|
-
}
|
|
843
|
-
var BaseElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
844
|
-
};
|
|
845
|
-
var InspectoElement = class extends BaseElement {
|
|
846
|
-
constructor() {
|
|
847
|
-
super(...arguments);
|
|
848
|
-
this.options = {};
|
|
849
|
-
this.serverHotKeys = null;
|
|
850
|
-
this.active = false;
|
|
851
|
-
this.disabled = false;
|
|
852
|
-
this.isDragging = false;
|
|
853
|
-
this.hasMoved = false;
|
|
854
|
-
this.dragStartX = 0;
|
|
855
|
-
this.dragStartY = 0;
|
|
856
|
-
this.badgeInitialRight = 16;
|
|
857
|
-
this.badgeInitialBottom = 16;
|
|
858
|
-
this.cleanupMenu = null;
|
|
859
|
-
this.onDragStart = (e) => {
|
|
860
|
-
var _a;
|
|
861
|
-
if (e.button !== 0) return;
|
|
862
|
-
if ((_a = e.target.classList) == null ? void 0 : _a.contains(`${badgeClass}-close`)) return;
|
|
863
|
-
e.preventDefault();
|
|
864
|
-
this.isDragging = true;
|
|
865
|
-
this.hasMoved = false;
|
|
866
|
-
const rect = this.badge.getBoundingClientRect();
|
|
867
|
-
this.dragStartX = e.clientX - rect.left;
|
|
868
|
-
this.dragStartY = e.clientY - rect.top;
|
|
869
|
-
document.addEventListener("mousemove", this.onDragMove);
|
|
870
|
-
document.addEventListener("mouseup", this.onDragEnd);
|
|
871
|
-
};
|
|
872
|
-
this.onDragMove = (e) => {
|
|
873
|
-
if (!this.isDragging) return;
|
|
874
|
-
this.hasMoved = true;
|
|
875
|
-
let newLeft = e.clientX - this.dragStartX;
|
|
876
|
-
let newTop = e.clientY - this.dragStartY;
|
|
877
|
-
const badgeWidth = this.badge.offsetWidth;
|
|
878
|
-
const badgeHeight = this.badge.offsetHeight;
|
|
879
|
-
newLeft = Math.max(0, Math.min(newLeft, window.innerWidth - badgeWidth));
|
|
880
|
-
newTop = Math.max(0, Math.min(newTop, window.innerHeight - badgeHeight));
|
|
881
|
-
this.badge.style.transition = "none";
|
|
882
|
-
this.badge.style.right = "auto";
|
|
883
|
-
this.badge.style.bottom = "auto";
|
|
884
|
-
this.badge.style.left = `${newLeft}px`;
|
|
885
|
-
this.badge.style.top = `${newTop}px`;
|
|
886
|
-
};
|
|
887
|
-
this.onDragEnd = () => {
|
|
888
|
-
document.removeEventListener("mousemove", this.onDragMove);
|
|
889
|
-
document.removeEventListener("mouseup", this.onDragEnd);
|
|
890
|
-
this.badge.style.transition = "";
|
|
891
|
-
setTimeout(() => {
|
|
892
|
-
this.isDragging = false;
|
|
893
|
-
}, 0);
|
|
894
|
-
};
|
|
895
|
-
this.onMouseMove = (e) => {
|
|
896
|
-
var _a;
|
|
897
|
-
const isActive = this.isInspectorActive(e);
|
|
898
|
-
if (!isActive) {
|
|
899
|
-
this.overlay.hide();
|
|
900
|
-
return;
|
|
901
|
-
}
|
|
902
|
-
const target = findInspectable(e.target);
|
|
903
|
-
if (!target) {
|
|
904
|
-
this.overlay.hide();
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
907
|
-
const attrValue = target.getAttribute(ATTR_NAME);
|
|
908
|
-
const loc = parseAttrValue(attrValue);
|
|
909
|
-
const label = loc ? `${(_a = loc.file.split("/").pop()) != null ? _a : ""}:${loc.line}` : attrValue;
|
|
910
|
-
this.overlay.show(target, label);
|
|
911
|
-
e.stopPropagation();
|
|
912
|
-
};
|
|
913
|
-
this.onClick = (e) => {
|
|
914
|
-
this.handleTrigger(e);
|
|
915
|
-
};
|
|
916
|
-
this.onContextMenu = (e) => {
|
|
917
|
-
if (this.isInspectorActive(e)) {
|
|
918
|
-
this.handleTrigger(e);
|
|
919
|
-
}
|
|
920
|
-
};
|
|
921
|
-
this.onKeyDown = (e) => {
|
|
922
|
-
var _a;
|
|
923
|
-
if (e.key === "Escape") {
|
|
924
|
-
(_a = this.cleanupMenu) == null ? void 0 : _a.call(this);
|
|
925
|
-
this.overlay.hide();
|
|
926
|
-
}
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
connectedCallback() {
|
|
930
|
-
this.shadowRootEl = this.attachShadow({ mode: "open" });
|
|
931
|
-
const style = document.createElement("style");
|
|
932
|
-
style.textContent = inspectorStyles;
|
|
933
|
-
this.shadowRootEl.appendChild(style);
|
|
934
|
-
this.overlay = createOverlay(this.shadowRootEl);
|
|
935
|
-
this.badge = this.createBadge();
|
|
936
|
-
this.setupListeners();
|
|
937
|
-
if (this.options.defaultActive) {
|
|
938
|
-
this.setActive(true);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
disconnectedCallback() {
|
|
942
|
-
this.teardownListeners();
|
|
943
|
-
}
|
|
944
|
-
configure(options) {
|
|
945
|
-
this.options = options;
|
|
946
|
-
if (options.serverUrl) {
|
|
947
|
-
setBaseUrl(options.serverUrl);
|
|
948
|
-
}
|
|
949
|
-
if (options.theme === "dark") {
|
|
950
|
-
this.setAttribute("data-theme", "dark");
|
|
951
|
-
} else if (options.theme === "light") {
|
|
952
|
-
this.setAttribute("data-theme", "light");
|
|
953
|
-
} else {
|
|
954
|
-
this.removeAttribute("data-theme");
|
|
955
|
-
}
|
|
956
|
-
fetchIdeInfo(true).then((info) => {
|
|
957
|
-
if ((info == null ? void 0 : info.hotKeys) !== void 0) {
|
|
958
|
-
this.serverHotKeys = info.hotKeys;
|
|
959
|
-
this.updateBadgeContent();
|
|
960
|
-
}
|
|
961
|
-
if ((info == null ? void 0 : info.theme) !== void 0) {
|
|
962
|
-
if (info.theme === "dark") {
|
|
963
|
-
this.setAttribute("data-theme", "dark");
|
|
964
|
-
} else if (info.theme === "light") {
|
|
965
|
-
this.setAttribute("data-theme", "light");
|
|
966
|
-
} else {
|
|
967
|
-
this.removeAttribute("data-theme");
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
if ((info == null ? void 0 : info.includeSnippet) !== void 0) {
|
|
971
|
-
this.options.includeSnippet = info.includeSnippet;
|
|
972
|
-
}
|
|
973
|
-
}).catch(() => {
|
|
974
|
-
});
|
|
975
|
-
}
|
|
976
|
-
createBadge() {
|
|
977
|
-
const btn = document.createElement("button");
|
|
978
|
-
btn.className = badgeClass;
|
|
979
|
-
btn.style.display = "flex";
|
|
980
|
-
const textSpan = document.createElement("span");
|
|
981
|
-
textSpan.textContent = "Inspecto Ready";
|
|
982
|
-
const closeBtn = document.createElement("span");
|
|
983
|
-
closeBtn.className = `${badgeClass}-close`;
|
|
984
|
-
closeBtn.innerHTML = "\xD7";
|
|
985
|
-
closeBtn.title = "Pause Inspector";
|
|
986
|
-
closeBtn.addEventListener("click", (e) => {
|
|
987
|
-
e.stopPropagation();
|
|
988
|
-
this.toggleDisabled();
|
|
989
|
-
});
|
|
990
|
-
btn.appendChild(textSpan);
|
|
991
|
-
btn.appendChild(closeBtn);
|
|
992
|
-
btn.addEventListener("mousedown", this.onDragStart);
|
|
993
|
-
btn.addEventListener("click", (e) => {
|
|
994
|
-
if (this.hasMoved) {
|
|
995
|
-
this.hasMoved = false;
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
if (this.disabled) {
|
|
999
|
-
this.toggleDisabled();
|
|
1000
|
-
} else {
|
|
1001
|
-
this.setActive(!this.active);
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
this.shadowRootEl.appendChild(btn);
|
|
1005
|
-
return btn;
|
|
1006
|
-
}
|
|
1007
|
-
toggleDisabled() {
|
|
1008
|
-
var _a;
|
|
1009
|
-
this.disabled = !this.disabled;
|
|
1010
|
-
if (this.disabled) {
|
|
1011
|
-
this.active = false;
|
|
1012
|
-
this.overlay.hide();
|
|
1013
|
-
(_a = this.cleanupMenu) == null ? void 0 : _a.call(this);
|
|
1014
|
-
this.cleanupMenu = null;
|
|
1015
|
-
}
|
|
1016
|
-
this.updateBadgeContent();
|
|
1017
|
-
}
|
|
1018
|
-
dismiss() {
|
|
1019
|
-
this.badge.style.display = "none";
|
|
1020
|
-
this.setActive(false);
|
|
1021
|
-
}
|
|
1022
|
-
getHotKeyHint() {
|
|
1023
|
-
const hotKeys = this.getEffectiveHotKeys();
|
|
1024
|
-
if (hotKeys === false) return "Inspecto Ready";
|
|
1025
|
-
const isMac = typeof navigator !== "undefined" && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
1026
|
-
const keys = hotKeys.split("+").map((k) => k.trim().toLowerCase());
|
|
1027
|
-
const displayKeys = keys.map((k) => {
|
|
1028
|
-
if (k === "alt" || k === "option") return isMac ? "\u2325" : "Alt";
|
|
1029
|
-
if (k === "cmd" || k === "meta" || k === "win" || k === "command") return isMac ? "\u2318" : "Win";
|
|
1030
|
-
if (k === "ctrl" || k === "control") return isMac ? "\u2303" : "Ctrl";
|
|
1031
|
-
if (k === "shift") return isMac ? "\u21E7" : "Shift";
|
|
1032
|
-
return k.charAt(0).toUpperCase() + k.slice(1);
|
|
1033
|
-
});
|
|
1034
|
-
return `Hold ${displayKeys.join(" + ")} to Inspect`;
|
|
1035
|
-
}
|
|
1036
|
-
getEffectiveHotKeys() {
|
|
1037
|
-
if (this.options.hotKeys !== void 0) return this.options.hotKeys;
|
|
1038
|
-
if (this.serverHotKeys !== null) return this.serverHotKeys;
|
|
1039
|
-
return "alt";
|
|
1040
|
-
}
|
|
1041
|
-
updateBadgeContent() {
|
|
1042
|
-
const textSpan = this.badge.querySelector("span");
|
|
1043
|
-
if (!textSpan) return;
|
|
1044
|
-
if (this.disabled) {
|
|
1045
|
-
textSpan.textContent = "Inspector Paused";
|
|
1046
|
-
this.badge.classList.remove("active");
|
|
1047
|
-
this.badge.classList.add("disabled");
|
|
1048
|
-
} else if (this.active) {
|
|
1049
|
-
textSpan.textContent = "\u{1F50D} Inspecting...";
|
|
1050
|
-
this.badge.classList.remove("disabled");
|
|
1051
|
-
this.badge.classList.add("active");
|
|
1052
|
-
} else {
|
|
1053
|
-
textSpan.textContent = this.getHotKeyHint();
|
|
1054
|
-
this.badge.classList.remove("active", "disabled");
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
setActive(value) {
|
|
1058
|
-
var _a;
|
|
1059
|
-
this.active = value;
|
|
1060
|
-
this.updateBadgeContent();
|
|
1061
|
-
if (!value) {
|
|
1062
|
-
this.overlay.hide();
|
|
1063
|
-
(_a = this.cleanupMenu) == null ? void 0 : _a.call(this);
|
|
1064
|
-
this.cleanupMenu = null;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
handleTrigger(e) {
|
|
1068
|
-
var _a;
|
|
1069
|
-
if (!this.isInspectorActive(e)) return;
|
|
1070
|
-
const target = findInspectable(e.target);
|
|
1071
|
-
if (!target) return;
|
|
1072
|
-
e.preventDefault();
|
|
1073
|
-
e.stopPropagation();
|
|
1074
|
-
const attrValue = target.getAttribute(ATTR_NAME);
|
|
1075
|
-
const loc = parseAttrValue(attrValue);
|
|
1076
|
-
if (!loc) return;
|
|
1077
|
-
(_a = this.cleanupMenu) == null ? void 0 : _a.call(this);
|
|
1078
|
-
this.cleanupMenu = showIntentMenu(
|
|
1079
|
-
this.shadowRootEl,
|
|
1080
|
-
loc,
|
|
1081
|
-
e.clientX,
|
|
1082
|
-
e.clientY,
|
|
1083
|
-
this.options,
|
|
1084
|
-
() => {
|
|
1085
|
-
this.cleanupMenu = null;
|
|
1086
|
-
}
|
|
1087
|
-
);
|
|
1088
|
-
}
|
|
1089
|
-
isInspectorActive(e) {
|
|
1090
|
-
if (this.disabled) return false;
|
|
1091
|
-
if (this.active) return true;
|
|
1092
|
-
const hotKeys = this.getEffectiveHotKeys();
|
|
1093
|
-
if (hotKeys === false) return false;
|
|
1094
|
-
return hotKeysHeld(e, hotKeys);
|
|
1095
|
-
}
|
|
1096
|
-
setupListeners() {
|
|
1097
|
-
document.addEventListener("mousemove", this.onMouseMove, true);
|
|
1098
|
-
document.addEventListener("click", this.onClick, true);
|
|
1099
|
-
document.addEventListener("contextmenu", this.onContextMenu, true);
|
|
1100
|
-
document.addEventListener("keydown", this.onKeyDown, true);
|
|
1101
|
-
}
|
|
1102
|
-
teardownListeners() {
|
|
1103
|
-
document.removeEventListener("mousemove", this.onMouseMove, true);
|
|
1104
|
-
document.removeEventListener("click", this.onClick, true);
|
|
1105
|
-
document.removeEventListener("contextmenu", this.onContextMenu, true);
|
|
1106
|
-
document.removeEventListener("keydown", this.onKeyDown, true);
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
|
-
if (typeof customElements !== "undefined") {
|
|
1110
|
-
customElements.define("inspecto-overlay", InspectoElement);
|
|
1111
|
-
}
|
|
1112
|
-
export {
|
|
1113
|
-
InspectoElement
|
|
1114
|
-
};
|
|
1115
|
-
//# sourceMappingURL=component-VOGY7YTT.js.map
|