context_drop 0.1.1 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +68 -11
- data/app/assets/javascripts/context_drop/context_drop.js +1263 -616
- data/app/controllers/context_drop/configs_controller.rb +3 -1
- data/app/javascript/context_drop/__tests__/api-client.test.ts +310 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +158 -3
- data/app/javascript/context_drop/api-client.ts +153 -48
- data/app/javascript/context_drop/element-picker.ts +894 -485
- data/app/javascript/context_drop/icons.ts +2 -0
- data/app/javascript/context_drop/screenshot.ts +7 -1
- data/app/javascript/context_drop/styles.ts +88 -39
- data/app/javascript/context_drop/types.ts +1 -0
- data/app/javascript/context_drop/widget.ts +150 -61
- data/lib/context_drop/version.rb +1 -1
- metadata +2 -1
|
@@ -452,6 +452,7 @@
|
|
|
452
452
|
const ICON_CHEVRON_UP = `<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="3.5 10 8 5.5 12.5 10"/></svg>`;
|
|
453
453
|
const ICON_CHEVRON_DOWN = `<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="3.5 6 8 10.5 12.5 6"/></svg>`;
|
|
454
454
|
const ICON_CHEVRON_RIGHT = `<svg viewBox="0 0 16 16" width="11" height="11" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="6 3.5 10.5 8 6 12.5"/></svg>`;
|
|
455
|
+
const ICON_SCROLL_VERTICAL = `<svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="5.25 5.75 8 3 10.75 5.75"/><polyline points="5.25 10.25 8 13 10.75 10.25"/></svg>`;
|
|
455
456
|
const ICON_CAMERA = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6.5h2.5l1.4-2h6.2l1.4 2H17a1.5 1.5 0 0 1 1.5 1.5v7.5A1.5 1.5 0 0 1 17 17H3a1.5 1.5 0 0 1-1.5-1.5V8A1.5 1.5 0 0 1 3 6.5z"/><circle cx="10" cy="11.5" r="2.75"/></svg>`;
|
|
456
457
|
const ICON_IMAGE = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.5" y="3.5" width="15" height="13" rx="2"/><circle cx="7" cy="8" r="1.3"/><path d="M17.5 13.2l-3.8-3.7L6 16.5"/></svg>`;
|
|
457
458
|
const ICON_SEND = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.85" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 16V4"/><polyline points="5 9 10 4 15 9"/></svg>`;
|
|
@@ -557,21 +558,18 @@
|
|
|
557
558
|
|
|
558
559
|
/* Custom themed scrollbars */
|
|
559
560
|
.cd-chat-thread::-webkit-scrollbar,
|
|
560
|
-
.cd-tray::-webkit-scrollbar
|
|
561
|
-
.cd-breadcrumb-scroll::-webkit-scrollbar {
|
|
561
|
+
.cd-tray::-webkit-scrollbar {
|
|
562
562
|
width: 6px;
|
|
563
563
|
height: 6px;
|
|
564
564
|
}
|
|
565
565
|
|
|
566
566
|
.cd-chat-thread::-webkit-scrollbar-track,
|
|
567
|
-
.cd-tray::-webkit-scrollbar-track
|
|
568
|
-
.cd-breadcrumb-scroll::-webkit-scrollbar-track {
|
|
567
|
+
.cd-tray::-webkit-scrollbar-track {
|
|
569
568
|
background: transparent;
|
|
570
569
|
}
|
|
571
570
|
|
|
572
571
|
.cd-chat-thread::-webkit-scrollbar-thumb,
|
|
573
|
-
.cd-tray::-webkit-scrollbar-thumb
|
|
574
|
-
.cd-breadcrumb-scroll::-webkit-scrollbar-thumb {
|
|
572
|
+
.cd-tray::-webkit-scrollbar-thumb {
|
|
575
573
|
background: var(--cd-border);
|
|
576
574
|
border-radius: 9999px;
|
|
577
575
|
}
|
|
@@ -676,14 +674,15 @@
|
|
|
676
674
|
font-variant-numeric: tabular-nums;
|
|
677
675
|
}
|
|
678
676
|
|
|
679
|
-
/* Compact Minimized Bar (active while pinning elements or minimized) */
|
|
677
|
+
/* Compact Minimized Session Coach Bar (active while pinning elements or minimized) */
|
|
680
678
|
.cd-compact-bar {
|
|
681
679
|
pointer-events: auto;
|
|
682
680
|
display: flex;
|
|
683
681
|
align-items: center;
|
|
684
682
|
gap: 8px;
|
|
685
|
-
width:
|
|
686
|
-
|
|
683
|
+
width: max-content;
|
|
684
|
+
min-width: 390px;
|
|
685
|
+
max-width: min(560px, calc(100vw - 24px));
|
|
687
686
|
padding: 7px 10px;
|
|
688
687
|
background: var(--cd-surface);
|
|
689
688
|
color: var(--cd-ink);
|
|
@@ -702,52 +701,93 @@
|
|
|
702
701
|
.cd-compact-status {
|
|
703
702
|
display: flex;
|
|
704
703
|
align-items: center;
|
|
705
|
-
gap:
|
|
704
|
+
gap: 7px;
|
|
706
705
|
flex: 1;
|
|
707
706
|
min-width: 0;
|
|
707
|
+
overflow: hidden;
|
|
708
708
|
}
|
|
709
709
|
|
|
710
|
-
.cd-
|
|
711
|
-
display: flex;
|
|
710
|
+
.cd-compact-coach-text {
|
|
711
|
+
display: inline-flex;
|
|
712
712
|
align-items: center;
|
|
713
|
-
gap:
|
|
714
|
-
|
|
713
|
+
gap: 5px;
|
|
714
|
+
font-size: 12px;
|
|
715
|
+
color: var(--cd-ink-secondary);
|
|
715
716
|
white-space: nowrap;
|
|
716
|
-
|
|
717
|
-
|
|
717
|
+
overflow: hidden;
|
|
718
|
+
text-overflow: ellipsis;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
.cd-compact-coach-text strong {
|
|
722
|
+
color: var(--cd-ink);
|
|
723
|
+
font-weight: 600;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
.cd-compact-wheel-icon {
|
|
727
|
+
display: inline-flex;
|
|
728
|
+
align-items: center;
|
|
729
|
+
color: var(--cd-accent);
|
|
730
|
+
flex-shrink: 0;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
.cd-compact-pinned-pill {
|
|
734
|
+
display: inline-flex;
|
|
735
|
+
align-items: center;
|
|
736
|
+
gap: 5px;
|
|
737
|
+
padding: 2px 5px 2px 6px;
|
|
738
|
+
background: var(--cd-surface-elevated);
|
|
739
|
+
border: 1px solid var(--cd-border);
|
|
740
|
+
border-radius: 7px;
|
|
718
741
|
min-width: 0;
|
|
719
|
-
|
|
742
|
+
max-width: 220px;
|
|
720
743
|
}
|
|
721
744
|
|
|
722
|
-
.cd-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
border-radius: 5px;
|
|
731
|
-
cursor: pointer;
|
|
745
|
+
.cd-compact-pinned-count {
|
|
746
|
+
font-size: 10.5px;
|
|
747
|
+
font-weight: 700;
|
|
748
|
+
font-variant-numeric: tabular-nums;
|
|
749
|
+
padding: 1px 5px;
|
|
750
|
+
border-radius: 4px;
|
|
751
|
+
background: var(--cd-pin-soft);
|
|
752
|
+
color: var(--cd-pin-hover);
|
|
732
753
|
flex-shrink: 0;
|
|
733
754
|
}
|
|
734
755
|
|
|
735
|
-
.cd-
|
|
736
|
-
|
|
756
|
+
.cd-compact-pinned-selector {
|
|
757
|
+
font-family: var(--cd-mono);
|
|
758
|
+
font-size: 11px;
|
|
737
759
|
color: var(--cd-ink);
|
|
760
|
+
overflow: hidden;
|
|
761
|
+
text-overflow: ellipsis;
|
|
762
|
+
white-space: nowrap;
|
|
738
763
|
}
|
|
739
764
|
|
|
740
|
-
.cd-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
765
|
+
.cd-compact-step-group {
|
|
766
|
+
display: inline-flex;
|
|
767
|
+
align-items: center;
|
|
768
|
+
gap: 2px;
|
|
769
|
+
flex-shrink: 0;
|
|
745
770
|
}
|
|
746
771
|
|
|
747
|
-
.cd-
|
|
772
|
+
.cd-kbd {
|
|
748
773
|
display: inline-flex;
|
|
749
|
-
|
|
750
|
-
|
|
774
|
+
align-items: center;
|
|
775
|
+
justify-content: center;
|
|
776
|
+
font-family: var(--cd-mono);
|
|
777
|
+
font-size: 10px;
|
|
778
|
+
font-weight: 600;
|
|
779
|
+
line-height: 1.1;
|
|
780
|
+
padding: 2px 5px;
|
|
781
|
+
border-radius: 4px;
|
|
782
|
+
background: var(--cd-surface-recessed);
|
|
783
|
+
border: 1px solid var(--cd-border);
|
|
784
|
+
color: var(--cd-ink-secondary);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
.cd-btn-primary .cd-kbd {
|
|
788
|
+
background: rgba(250, 249, 246, 0.16);
|
|
789
|
+
border-color: rgba(250, 249, 246, 0.26);
|
|
790
|
+
color: var(--cd-surface);
|
|
751
791
|
}
|
|
752
792
|
|
|
753
793
|
/* Main Floating Chatbox Composer Window */
|
|
@@ -860,11 +900,16 @@
|
|
|
860
900
|
transition: background-color 0.12s ease, color 0.12s ease;
|
|
861
901
|
}
|
|
862
902
|
|
|
863
|
-
.cd-icon-btn:hover {
|
|
903
|
+
.cd-icon-btn:hover:not(:disabled) {
|
|
864
904
|
background: rgba(17, 19, 24, 0.06);
|
|
865
905
|
color: var(--cd-ink);
|
|
866
906
|
}
|
|
867
907
|
|
|
908
|
+
.cd-icon-btn:disabled {
|
|
909
|
+
opacity: 0.36;
|
|
910
|
+
cursor: not-allowed;
|
|
911
|
+
}
|
|
912
|
+
|
|
868
913
|
/* Conversational Chat Thread */
|
|
869
914
|
.cd-chat-thread {
|
|
870
915
|
display: flex;
|
|
@@ -1146,10 +1191,15 @@
|
|
|
1146
1191
|
border-color: #252a34;
|
|
1147
1192
|
}
|
|
1148
1193
|
|
|
1149
|
-
@media (max-width:
|
|
1194
|
+
@media (max-width: 520px) {
|
|
1150
1195
|
.cd-composer,
|
|
1151
1196
|
.cd-compact-bar {
|
|
1152
1197
|
width: calc(100vw - 20px);
|
|
1198
|
+
min-width: 0;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
.cd-compact-bar {
|
|
1202
|
+
flex-wrap: wrap;
|
|
1153
1203
|
}
|
|
1154
1204
|
}
|
|
1155
1205
|
`;
|
|
@@ -1157,83 +1207,188 @@
|
|
|
1157
1207
|
// --- Module: api-client.ts ---
|
|
1158
1208
|
class ContextDropApiClient {
|
|
1159
1209
|
baseUrl ;
|
|
1210
|
+
cachedCsrfToken = null;
|
|
1211
|
+
inFlightConfigPromise = null;
|
|
1160
1212
|
|
|
1161
1213
|
constructor(baseUrl = "/context_drop") {
|
|
1162
1214
|
this.baseUrl = baseUrl.replace(/\/+$/, "") || "/context_drop";
|
|
1163
1215
|
}
|
|
1164
1216
|
|
|
1165
1217
|
getCsrfToken() {
|
|
1218
|
+
const metaToken = this.getMetaCsrfToken();
|
|
1219
|
+
if (metaToken) {
|
|
1220
|
+
return metaToken;
|
|
1221
|
+
}
|
|
1222
|
+
return this.cachedCsrfToken;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
setCsrfToken(token ) {
|
|
1226
|
+
this.cachedCsrfToken = token ? token.trim() : null;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
getMetaCsrfToken() {
|
|
1166
1230
|
if (typeof document === "undefined") return null;
|
|
1167
1231
|
const meta = document.querySelector('meta[name="csrf-token"]');
|
|
1168
|
-
|
|
1232
|
+
const content = meta ? meta.getAttribute("content") : null;
|
|
1233
|
+
return content && content.trim().length > 0 ? content.trim() : null;
|
|
1169
1234
|
}
|
|
1170
1235
|
|
|
1171
1236
|
async fetchConfig() {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1237
|
+
if (this.inFlightConfigPromise) {
|
|
1238
|
+
return this.inFlightConfigPromise;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
this.inFlightConfigPromise = (async () => {
|
|
1242
|
+
try {
|
|
1243
|
+
const response = await fetch(`${this.baseUrl}/config`, {
|
|
1244
|
+
method: "GET",
|
|
1245
|
+
credentials: "same-origin",
|
|
1246
|
+
headers: {
|
|
1247
|
+
Accept: "application/json"
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
|
|
1251
|
+
if (!response.ok) {
|
|
1252
|
+
throw new Error(`Failed to fetch ContextDrop config (${response.status})`);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
const config = (await response.json()) ;
|
|
1256
|
+
if (config && typeof config.csrf_token === "string" && config.csrf_token.trim().length > 0) {
|
|
1257
|
+
this.cachedCsrfToken = config.csrf_token.trim();
|
|
1258
|
+
if (typeof document !== "undefined") {
|
|
1259
|
+
const meta = document.querySelector('meta[name="csrf-token"]');
|
|
1260
|
+
if (meta) {
|
|
1261
|
+
meta.setAttribute("content", this.cachedCsrfToken);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
return config;
|
|
1266
|
+
} finally {
|
|
1267
|
+
this.inFlightConfigPromise = null;
|
|
1177
1268
|
}
|
|
1178
|
-
});
|
|
1269
|
+
})();
|
|
1270
|
+
|
|
1271
|
+
return this.inFlightConfigPromise;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
async resolveCsrfToken(forceRefresh = false) {
|
|
1275
|
+
if (!forceRefresh) {
|
|
1276
|
+
const metaToken = this.getMetaCsrfToken();
|
|
1277
|
+
if (metaToken) {
|
|
1278
|
+
return metaToken;
|
|
1279
|
+
}
|
|
1280
|
+
if (this.cachedCsrfToken) {
|
|
1281
|
+
return this.cachedCsrfToken;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1179
1284
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1285
|
+
try {
|
|
1286
|
+
const config = await this.fetchConfig();
|
|
1287
|
+
if (config && config.csrf_token) {
|
|
1288
|
+
return config.csrf_token.trim();
|
|
1289
|
+
}
|
|
1290
|
+
} catch {
|
|
1291
|
+
// Continue and fall back to current token or null
|
|
1182
1292
|
}
|
|
1183
1293
|
|
|
1184
|
-
return
|
|
1294
|
+
return this.cachedCsrfToken || this.getMetaCsrfToken();
|
|
1185
1295
|
}
|
|
1186
1296
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1297
|
+
isCsrfError(status , message ) {
|
|
1298
|
+
if (status !== 422) return false;
|
|
1299
|
+
return /csrf|authenticity/i.test(message);
|
|
1300
|
+
}
|
|
1190
1301
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1302
|
+
async executeWithCsrfRetry (
|
|
1303
|
+
requestFn ,
|
|
1304
|
+
defaultErrorMessage
|
|
1305
|
+
) {
|
|
1306
|
+
let csrfToken = await this.resolveCsrfToken(false);
|
|
1307
|
+
let response = await requestFn(csrfToken);
|
|
1308
|
+
|
|
1309
|
+
if (response.ok) {
|
|
1310
|
+
return (await response.json()) ;
|
|
1197
1311
|
}
|
|
1198
1312
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1313
|
+
if (response.status === 422) {
|
|
1314
|
+
const rawText = await response.text();
|
|
1315
|
+
let parsedError = null;
|
|
1316
|
+
try {
|
|
1317
|
+
const json = JSON.parse(rawText) ;
|
|
1318
|
+
if (json && typeof json.error === "string") {
|
|
1319
|
+
parsedError = json.error;
|
|
1320
|
+
}
|
|
1321
|
+
} catch {
|
|
1322
|
+
// Not JSON
|
|
1323
|
+
}
|
|
1205
1324
|
|
|
1206
|
-
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1325
|
+
const errorMessage = parsedError || rawText || "";
|
|
1326
|
+
const shouldRetryCsrf =
|
|
1327
|
+
this.isCsrfError(response.status, errorMessage) || (!csrfToken && response.status === 422);
|
|
1328
|
+
|
|
1329
|
+
if (shouldRetryCsrf) {
|
|
1330
|
+
csrfToken = await this.resolveCsrfToken(true);
|
|
1331
|
+
response = await requestFn(csrfToken);
|
|
1332
|
+
if (response.ok) {
|
|
1333
|
+
return (await response.json()) ;
|
|
1334
|
+
}
|
|
1335
|
+
const retryErrBody = await response.json().catch(() => ({}));
|
|
1336
|
+
throw new Error(
|
|
1337
|
+
(retryErrBody ).error || `${defaultErrorMessage} (${response.status})`
|
|
1338
|
+
);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
throw new Error(parsedError || errorMessage || `${defaultErrorMessage} (${response.status})`);
|
|
1209
1342
|
}
|
|
1210
1343
|
|
|
1211
|
-
|
|
1344
|
+
const errBody = await response.json().catch(() => ({}));
|
|
1345
|
+
throw new Error(
|
|
1346
|
+
(errBody ).error || `${defaultErrorMessage} (${response.status})`
|
|
1347
|
+
);
|
|
1212
1348
|
}
|
|
1213
1349
|
|
|
1214
|
-
async
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1217
|
-
|
|
1350
|
+
async uploadAttachment(file , filename ) {
|
|
1351
|
+
const makeRequest = async (csrfToken ) => {
|
|
1352
|
+
const formData = new FormData();
|
|
1353
|
+
formData.append("file", file, filename);
|
|
1354
|
+
|
|
1355
|
+
const headers = {
|
|
1356
|
+
Accept: "application/json"
|
|
1357
|
+
};
|
|
1358
|
+
if (csrfToken) {
|
|
1359
|
+
headers["X-CSRF-Token"] = csrfToken;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
return fetch(`${this.baseUrl}/attachments`, {
|
|
1363
|
+
method: "POST",
|
|
1364
|
+
credentials: "same-origin",
|
|
1365
|
+
headers,
|
|
1366
|
+
body: formData
|
|
1367
|
+
});
|
|
1218
1368
|
};
|
|
1219
|
-
const csrf = this.getCsrfToken();
|
|
1220
|
-
if (csrf) {
|
|
1221
|
-
headers["X-CSRF-Token"] = csrf;
|
|
1222
|
-
}
|
|
1223
1369
|
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
credentials: "same-origin",
|
|
1227
|
-
headers,
|
|
1228
|
-
body: JSON.stringify({ feedback: payload })
|
|
1229
|
-
});
|
|
1370
|
+
return this.executeWithCsrfRetry(makeRequest, "Upload failed");
|
|
1371
|
+
}
|
|
1230
1372
|
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1373
|
+
async submitFeedback(payload ) {
|
|
1374
|
+
const makeRequest = async (csrfToken ) => {
|
|
1375
|
+
const headers = {
|
|
1376
|
+
"Content-Type": "application/json",
|
|
1377
|
+
Accept: "application/json"
|
|
1378
|
+
};
|
|
1379
|
+
if (csrfToken) {
|
|
1380
|
+
headers["X-CSRF-Token"] = csrfToken;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
return fetch(`${this.baseUrl}/feedback`, {
|
|
1384
|
+
method: "POST",
|
|
1385
|
+
credentials: "same-origin",
|
|
1386
|
+
headers,
|
|
1387
|
+
body: JSON.stringify({ feedback: payload })
|
|
1388
|
+
});
|
|
1389
|
+
};
|
|
1235
1390
|
|
|
1236
|
-
return (
|
|
1391
|
+
return this.executeWithCsrfRetry(makeRequest, "Submission failed");
|
|
1237
1392
|
}
|
|
1238
1393
|
}
|
|
1239
1394
|
|
|
@@ -1346,7 +1501,13 @@
|
|
|
1346
1501
|
// Paint visible non-excluded DOM elements approximation onto canvas
|
|
1347
1502
|
const visibleNodes = document.body ? Array.from(document.body.querySelectorAll("*")) : [];
|
|
1348
1503
|
for (const node of visibleNodes) {
|
|
1349
|
-
if (
|
|
1504
|
+
if (
|
|
1505
|
+
node.closest("context-drop-widget") ||
|
|
1506
|
+
node.hasAttribute("data-context-drop-ui") ||
|
|
1507
|
+
node.closest("[data-context-drop-ui]")
|
|
1508
|
+
) {
|
|
1509
|
+
continue;
|
|
1510
|
+
}
|
|
1350
1511
|
if (isElementExcluded(node, customExcludedSelectors)) continue;
|
|
1351
1512
|
|
|
1352
1513
|
const r = node.getBoundingClientRect();
|
|
@@ -1440,26 +1601,66 @@
|
|
|
1440
1601
|
}
|
|
1441
1602
|
|
|
1442
1603
|
// --- Module: element-picker.ts ---
|
|
1604
|
+
const WHEEL_STEP_THRESHOLD = 26;
|
|
1605
|
+
const WHEEL_STEP_COOLDOWN_MS = 80;
|
|
1606
|
+
const SCRUB_JITTER_LOCK_PX = 28;
|
|
1607
|
+
const MAX_VISIBLE_STACK_ROWS = 5;
|
|
1608
|
+
|
|
1609
|
+
function isDomElementNode(node ) {
|
|
1610
|
+
if (!node || typeof node !== "object") return false;
|
|
1611
|
+
if (typeof window !== "undefined" && node === window) return false;
|
|
1612
|
+
if ((node ).nodeType !== 1) return false;
|
|
1613
|
+
const tag = ((node ).tagName || "").toUpperCase();
|
|
1614
|
+
return tag.length > 0 && tag !== "WINDOW";
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
function formatCandidateLabel(tagName , selector ) {
|
|
1618
|
+
if (selector.startsWith(tagName)) {
|
|
1619
|
+
return selector;
|
|
1620
|
+
}
|
|
1621
|
+
if (selector.startsWith("#") || selector.startsWith(".")) {
|
|
1622
|
+
return `${tagName}${selector}`;
|
|
1623
|
+
}
|
|
1624
|
+
return selector;
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
function isPointInsideRect(
|
|
1628
|
+
x ,
|
|
1629
|
+
y ,
|
|
1630
|
+
rect ,
|
|
1631
|
+
tolerance = 2
|
|
1632
|
+
) {
|
|
1633
|
+
const left = (rect.left ?? rect.x ?? 0) - tolerance;
|
|
1634
|
+
const top = (rect.top ?? rect.y ?? 0) - tolerance;
|
|
1635
|
+
return x >= left && x <= left + rect.width + tolerance * 2 && y >= top && y <= top + rect.height + tolerance * 2;
|
|
1636
|
+
}
|
|
1443
1637
|
class ElementPicker {
|
|
1444
1638
|
active = false;
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1639
|
+
isScrubbingLayers = false;
|
|
1640
|
+
scrubOriginX = 0;
|
|
1641
|
+
scrubOriginY = 0;
|
|
1448
1642
|
lastPointerX = 0;
|
|
1449
1643
|
lastPointerY = 0;
|
|
1450
1644
|
wheelAccumulator = 0;
|
|
1645
|
+
lastWheelStepAt = 0;
|
|
1451
1646
|
|
|
1452
1647
|
callbacks ;
|
|
1453
1648
|
overlayEl = null;
|
|
1454
1649
|
leafOutlineEl = null;
|
|
1455
|
-
|
|
1650
|
+
hudEl = null;
|
|
1456
1651
|
pinMarkerEl = null;
|
|
1457
|
-
|
|
1652
|
+
pinnedMarkersContainerEl = null;
|
|
1653
|
+
toastEl = null;
|
|
1458
1654
|
previewOverlayEl = null;
|
|
1459
1655
|
|
|
1656
|
+
pulseTimer = null;
|
|
1657
|
+
nudgeTimer = null;
|
|
1658
|
+
toastTimer = null;
|
|
1659
|
+
|
|
1460
1660
|
candidateStack = [];
|
|
1461
1661
|
activeCandidateIndex = 0;
|
|
1462
1662
|
leafElement = null;
|
|
1663
|
+
lastAction = null;
|
|
1463
1664
|
previousCursor = "";
|
|
1464
1665
|
|
|
1465
1666
|
boundMouseMove ;
|
|
@@ -1476,7 +1677,7 @@
|
|
|
1476
1677
|
this.boundPointerCapture = this.handlePointerSuppression.bind(this);
|
|
1477
1678
|
this.boundWheelCapture = this.handleWheelCapture.bind(this);
|
|
1478
1679
|
this.boundKeyDown = this.handleKeyDown.bind(this);
|
|
1479
|
-
this.boundScrollOrResize = this.
|
|
1680
|
+
this.boundScrollOrResize = this.handleViewportScrollOrResize.bind(this);
|
|
1480
1681
|
}
|
|
1481
1682
|
|
|
1482
1683
|
isActive() {
|
|
@@ -1484,7 +1685,11 @@
|
|
|
1484
1685
|
}
|
|
1485
1686
|
|
|
1486
1687
|
isAnchored() {
|
|
1487
|
-
return
|
|
1688
|
+
return false;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
isScrubbing() {
|
|
1692
|
+
return this.isScrubbingLayers;
|
|
1488
1693
|
}
|
|
1489
1694
|
|
|
1490
1695
|
getActiveCandidate() {
|
|
@@ -1500,10 +1705,13 @@
|
|
|
1500
1705
|
return;
|
|
1501
1706
|
}
|
|
1502
1707
|
this.active = true;
|
|
1503
|
-
this.
|
|
1708
|
+
this.isScrubbingLayers = false;
|
|
1709
|
+
this.wheelAccumulator = 0;
|
|
1710
|
+
this.lastWheelStepAt = 0;
|
|
1504
1711
|
this.candidateStack = [];
|
|
1505
1712
|
this.activeCandidateIndex = 0;
|
|
1506
1713
|
this.leafElement = null;
|
|
1714
|
+
this.lastAction = null;
|
|
1507
1715
|
|
|
1508
1716
|
this.hideExternalPreview();
|
|
1509
1717
|
|
|
@@ -1513,6 +1721,7 @@
|
|
|
1513
1721
|
}
|
|
1514
1722
|
|
|
1515
1723
|
this.mountSelectionUi();
|
|
1724
|
+
this.refreshPinnedMarkers();
|
|
1516
1725
|
this.notifyStateChange();
|
|
1517
1726
|
|
|
1518
1727
|
window.addEventListener("mousemove", this.boundMouseMove, { capture: true, passive: true });
|
|
@@ -1529,10 +1738,13 @@
|
|
|
1529
1738
|
stop() {
|
|
1530
1739
|
if (!this.active) return;
|
|
1531
1740
|
this.active = false;
|
|
1532
|
-
this.
|
|
1741
|
+
this.isScrubbingLayers = false;
|
|
1742
|
+
this.wheelAccumulator = 0;
|
|
1533
1743
|
this.candidateStack = [];
|
|
1534
1744
|
this.activeCandidateIndex = 0;
|
|
1535
1745
|
this.leafElement = null;
|
|
1746
|
+
this.lastAction = null;
|
|
1747
|
+
this.clearTimers();
|
|
1536
1748
|
|
|
1537
1749
|
if (typeof document !== "undefined" && document.body) {
|
|
1538
1750
|
document.body.style.cursor = this.previousCursor;
|
|
@@ -1555,9 +1767,6 @@
|
|
|
1555
1767
|
this.callbacks.onExit();
|
|
1556
1768
|
}
|
|
1557
1769
|
|
|
1558
|
-
/**
|
|
1559
|
-
* Allows the widget or breadcrumb bar to select or preview a specific DOM element directly.
|
|
1560
|
-
*/
|
|
1561
1770
|
focusCandidateElement(el ) {
|
|
1562
1771
|
if (!this.active) return;
|
|
1563
1772
|
const excluded = this.callbacks.getExcludedSelectors();
|
|
@@ -1572,10 +1781,10 @@
|
|
|
1572
1781
|
this.activeCandidateIndex = this.candidateStack.length - 1;
|
|
1573
1782
|
}
|
|
1574
1783
|
|
|
1784
|
+
this.isScrubbingLayers = this.candidateStack.length > 1;
|
|
1785
|
+
this.scrubOriginX = this.lastPointerX;
|
|
1786
|
+
this.scrubOriginY = this.lastPointerY;
|
|
1575
1787
|
this.updateOverlayPosition();
|
|
1576
|
-
if (this.anchored) {
|
|
1577
|
-
this.renderLayerPopover();
|
|
1578
|
-
}
|
|
1579
1788
|
this.notifyStateChange();
|
|
1580
1789
|
}
|
|
1581
1790
|
|
|
@@ -1585,16 +1794,75 @@
|
|
|
1585
1794
|
if (!snapshot) return false;
|
|
1586
1795
|
|
|
1587
1796
|
this.callbacks.onSelect(snapshot, el);
|
|
1588
|
-
this.
|
|
1797
|
+
this.lastAction = { kind: "pinned", selector: snapshot.selector };
|
|
1798
|
+
this.isScrubbingLayers = false;
|
|
1799
|
+
this.refreshPinnedMarkers();
|
|
1589
1800
|
|
|
1590
1801
|
if (!this.callbacks.canSelectMore()) {
|
|
1591
1802
|
this.stop();
|
|
1592
1803
|
} else {
|
|
1804
|
+
this.updateOverlayPosition();
|
|
1593
1805
|
this.notifyStateChange();
|
|
1594
1806
|
}
|
|
1595
1807
|
return true;
|
|
1596
1808
|
}
|
|
1597
1809
|
|
|
1810
|
+
refreshPinnedMarkers() {
|
|
1811
|
+
if (!this.active || !this.pinnedMarkersContainerEl) return;
|
|
1812
|
+
this.pinnedMarkersContainerEl.innerHTML = "";
|
|
1813
|
+
|
|
1814
|
+
const pinnedEntries = this.callbacks.getPinnedElements ? this.callbacks.getPinnedElements() : [];
|
|
1815
|
+
pinnedEntries.forEach((entry, index) => {
|
|
1816
|
+
if (!entry.element || typeof entry.element.getBoundingClientRect !== "function") return;
|
|
1817
|
+
const rect = entry.element.getBoundingClientRect();
|
|
1818
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
1819
|
+
|
|
1820
|
+
const markerFrame = document.createElement("div");
|
|
1821
|
+
markerFrame.setAttribute("data-context-drop-ui", "pinned-badge");
|
|
1822
|
+
markerFrame.style.cssText = [
|
|
1823
|
+
"position: fixed",
|
|
1824
|
+
"pointer-events: none",
|
|
1825
|
+
`left: ${rect.left}px`,
|
|
1826
|
+
`top: ${rect.top}px`,
|
|
1827
|
+
`width: ${rect.width}px`,
|
|
1828
|
+
`height: ${rect.height}px`,
|
|
1829
|
+
"border: 1.5px dashed rgba(194, 65, 12, 0.72)",
|
|
1830
|
+
"background: rgba(194, 65, 12, 0.04)",
|
|
1831
|
+
"border-radius: 6px"
|
|
1832
|
+
].join(";");
|
|
1833
|
+
|
|
1834
|
+
const badge = document.createElement("div");
|
|
1835
|
+
const badgeTop = rect.top < 26 ? "4px" : "-22px";
|
|
1836
|
+
badge.style.cssText = [
|
|
1837
|
+
"position: absolute",
|
|
1838
|
+
`top: ${badgeTop}`,
|
|
1839
|
+
"right: -1px",
|
|
1840
|
+
"display: inline-flex",
|
|
1841
|
+
"align-items: center",
|
|
1842
|
+
"gap: 4px",
|
|
1843
|
+
"padding: 2px 6px",
|
|
1844
|
+
"border-radius: 9999px",
|
|
1845
|
+
"background: #c2410c",
|
|
1846
|
+
"color: #faf9f6",
|
|
1847
|
+
"border: 1px solid #faf9f6",
|
|
1848
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
1849
|
+
"font-size: 10px",
|
|
1850
|
+
"font-weight: 700",
|
|
1851
|
+
"font-variant-numeric: tabular-nums",
|
|
1852
|
+
"line-height: 1.2",
|
|
1853
|
+
"max-width: 160px",
|
|
1854
|
+
"overflow: hidden",
|
|
1855
|
+
"text-overflow: ellipsis",
|
|
1856
|
+
"white-space: nowrap",
|
|
1857
|
+
"box-shadow: 0 4px 10px -2px rgba(17, 19, 24, 0.25)"
|
|
1858
|
+
].join(";");
|
|
1859
|
+
badge.textContent = `#${index + 1} ${entry.selector}`;
|
|
1860
|
+
|
|
1861
|
+
markerFrame.appendChild(badge);
|
|
1862
|
+
this.pinnedMarkersContainerEl?.appendChild(markerFrame);
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1598
1866
|
showExternalPreview(el ) {
|
|
1599
1867
|
if (typeof document === "undefined" || !document.body) return;
|
|
1600
1868
|
if (!el || this.active) {
|
|
@@ -1638,20 +1906,58 @@
|
|
|
1638
1906
|
this.previewOverlayEl = null;
|
|
1639
1907
|
}
|
|
1640
1908
|
|
|
1641
|
-
cycleDepth(delta ) {
|
|
1909
|
+
cycleDepth(delta , revealStack = true) {
|
|
1642
1910
|
if (!this.active || this.candidateStack.length <= 1) return;
|
|
1911
|
+
|
|
1912
|
+
const wasScrubbing = this.isScrubbingLayers;
|
|
1913
|
+
if (revealStack) {
|
|
1914
|
+
this.isScrubbingLayers = true;
|
|
1915
|
+
this.scrubOriginX = this.lastPointerX;
|
|
1916
|
+
this.scrubOriginY = this.lastPointerY;
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1643
1919
|
const next = Math.max(
|
|
1644
1920
|
0,
|
|
1645
1921
|
Math.min(this.candidateStack.length - 1, this.activeCandidateIndex + delta)
|
|
1646
1922
|
);
|
|
1923
|
+
|
|
1647
1924
|
if (next !== this.activeCandidateIndex) {
|
|
1648
1925
|
this.activeCandidateIndex = next;
|
|
1649
1926
|
this.updateOverlayPosition();
|
|
1650
|
-
if (this.anchored) {
|
|
1651
|
-
this.renderLayerPopover();
|
|
1652
|
-
}
|
|
1653
1927
|
this.notifyStateChange();
|
|
1928
|
+
} else if (!wasScrubbing && this.isScrubbingLayers) {
|
|
1929
|
+
this.updateOverlayPosition();
|
|
1930
|
+
this.triggerHudBoundaryNudge(delta < 0 ? -3 : 3);
|
|
1931
|
+
this.notifyStateChange();
|
|
1932
|
+
} else {
|
|
1933
|
+
this.triggerHudBoundaryNudge(delta < 0 ? -3 : 3);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
clearTimers() {
|
|
1938
|
+
if (this.pulseTimer !== null) {
|
|
1939
|
+
clearTimeout(this.pulseTimer);
|
|
1940
|
+
this.pulseTimer = null;
|
|
1941
|
+
}
|
|
1942
|
+
if (this.nudgeTimer !== null) {
|
|
1943
|
+
clearTimeout(this.nudgeTimer);
|
|
1944
|
+
this.nudgeTimer = null;
|
|
1945
|
+
}
|
|
1946
|
+
if (this.toastTimer !== null) {
|
|
1947
|
+
clearTimeout(this.toastTimer);
|
|
1948
|
+
this.toastTimer = null;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
findPinnedIndex(el ) {
|
|
1953
|
+
if (!this.callbacks.getPinnedElements) return null;
|
|
1954
|
+
const pinned = this.callbacks.getPinnedElements();
|
|
1955
|
+
for (let i = 0; i < pinned.length; i += 1) {
|
|
1956
|
+
if (pinned[i].element === el) {
|
|
1957
|
+
return { index: i, entry: pinned[i] };
|
|
1958
|
+
}
|
|
1654
1959
|
}
|
|
1960
|
+
return null;
|
|
1655
1961
|
}
|
|
1656
1962
|
|
|
1657
1963
|
notifyStateChange() {
|
|
@@ -1662,16 +1968,27 @@
|
|
|
1662
1968
|
: [];
|
|
1663
1969
|
this.callbacks.onStateChange({
|
|
1664
1970
|
active: this.active,
|
|
1665
|
-
anchored:
|
|
1971
|
+
anchored: false,
|
|
1972
|
+
scrubbing: this.isScrubbingLayers,
|
|
1666
1973
|
activeCandidate,
|
|
1667
1974
|
candidateStack: [...this.candidateStack],
|
|
1668
|
-
ancestors
|
|
1975
|
+
ancestors,
|
|
1976
|
+
lastAction: this.lastAction
|
|
1669
1977
|
});
|
|
1670
1978
|
}
|
|
1671
1979
|
|
|
1672
1980
|
mountSelectionUi() {
|
|
1673
1981
|
if (typeof document === "undefined" || !document.body) return;
|
|
1674
1982
|
|
|
1983
|
+
const pinnedMarkers = document.createElement("div");
|
|
1984
|
+
pinnedMarkers.setAttribute("data-context-drop-ui", "pinned-markers");
|
|
1985
|
+
pinnedMarkers.style.cssText = [
|
|
1986
|
+
"position: fixed",
|
|
1987
|
+
"inset: 0",
|
|
1988
|
+
"pointer-events: none",
|
|
1989
|
+
"z-index: 2147483643"
|
|
1990
|
+
].join(";");
|
|
1991
|
+
|
|
1675
1992
|
// Secondary ghost outline showing the innermost leaf element when cycling up to parent/overlapping layers
|
|
1676
1993
|
const leafOutline = document.createElement("div");
|
|
1677
1994
|
leafOutline.setAttribute("data-context-drop-ui", "leaf-outline");
|
|
@@ -1696,40 +2013,36 @@
|
|
|
1696
2013
|
"background: rgba(29, 78, 216, 0.10)",
|
|
1697
2014
|
"border-radius: 6px",
|
|
1698
2015
|
"display: none",
|
|
1699
|
-
"transition: left 0.06s cubic-bezier(0.22, 1, 0.36, 1), top 0.06s cubic-bezier(0.22, 1, 0.36, 1), width 0.06s cubic-bezier(0.22, 1, 0.36, 1), height 0.06s cubic-bezier(0.22, 1, 0.36, 1)"
|
|
2016
|
+
"transition: left 0.06s cubic-bezier(0.22, 1, 0.36, 1), top 0.06s cubic-bezier(0.22, 1, 0.36, 1), width 0.06s cubic-bezier(0.22, 1, 0.36, 1), height 0.06s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.16s ease, background-color 0.16s ease"
|
|
1700
2017
|
].join(";");
|
|
1701
2018
|
|
|
1702
|
-
// Floating HUD
|
|
1703
|
-
const
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
"position:
|
|
1707
|
-
"
|
|
1708
|
-
"left: -2px",
|
|
2019
|
+
// Viewport-clamped Floating HUD (Compact 2-line coach on hover, inline 5-row wheel-scrubbed stack on scroll)
|
|
2020
|
+
const hud = document.createElement("div");
|
|
2021
|
+
hud.setAttribute("data-context-drop-ui", "label");
|
|
2022
|
+
hud.style.cssText = [
|
|
2023
|
+
"position: fixed",
|
|
2024
|
+
"z-index: 2147483646",
|
|
1709
2025
|
"background: #111318",
|
|
1710
2026
|
"color: #faf9f6",
|
|
1711
|
-
"
|
|
1712
|
-
"
|
|
1713
|
-
"font-variant-numeric: tabular-nums",
|
|
1714
|
-
"line-height: 1.3",
|
|
1715
|
-
"padding: 4px 8px",
|
|
1716
|
-
"border-radius: 6px",
|
|
1717
|
-
"white-space: nowrap",
|
|
2027
|
+
"border: 1px solid rgba(250, 249, 246, 0.16)",
|
|
2028
|
+
"border-radius: 10px",
|
|
1718
2029
|
"pointer-events: none",
|
|
1719
|
-
"display:
|
|
1720
|
-
"
|
|
1721
|
-
"
|
|
1722
|
-
"
|
|
2030
|
+
"display: none",
|
|
2031
|
+
"overflow: hidden",
|
|
2032
|
+
"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
|
|
2033
|
+
"font-size: 11.5px",
|
|
2034
|
+
"line-height: 1.35",
|
|
2035
|
+
"box-shadow: 0 16px 34px -8px rgba(17, 19, 24, 0.40), 0 6px 14px -4px rgba(17, 19, 24, 0.22)",
|
|
2036
|
+
"transition: transform 0.12s cubic-bezier(0.22, 1, 0.36, 1)"
|
|
1723
2037
|
].join(";");
|
|
1724
|
-
overlay.appendChild(label);
|
|
1725
2038
|
|
|
1726
|
-
// Floating Pin marker that follows the pointer
|
|
2039
|
+
// Floating Pin marker that follows the pointer
|
|
1727
2040
|
const pinMarker = document.createElement("div");
|
|
1728
2041
|
pinMarker.setAttribute("data-context-drop-ui", "pin-marker");
|
|
1729
2042
|
pinMarker.style.cssText = [
|
|
1730
2043
|
"position: fixed",
|
|
1731
2044
|
"pointer-events: none",
|
|
1732
|
-
"z-index:
|
|
2045
|
+
"z-index: 2147483647",
|
|
1733
2046
|
"width: 28px",
|
|
1734
2047
|
"height: 28px",
|
|
1735
2048
|
"margin-left: -6px",
|
|
@@ -1746,55 +2059,68 @@
|
|
|
1746
2059
|
].join(";");
|
|
1747
2060
|
pinMarker.innerHTML = ICON_PIN;
|
|
1748
2061
|
|
|
1749
|
-
//
|
|
1750
|
-
const
|
|
1751
|
-
|
|
1752
|
-
|
|
2062
|
+
// Tactile floating confirmation pill near cursor on pin / unpin
|
|
2063
|
+
const toast = document.createElement("div");
|
|
2064
|
+
toast.setAttribute("data-context-drop-ui", "pin-toast");
|
|
2065
|
+
toast.style.cssText = [
|
|
1753
2066
|
"position: fixed",
|
|
2067
|
+
"pointer-events: none",
|
|
1754
2068
|
"z-index: 2147483647",
|
|
1755
|
-
"width: 348px",
|
|
1756
|
-
"max-width: calc(100vw - 24px)",
|
|
1757
|
-
"background: #faf9f6",
|
|
1758
|
-
"color: #111318",
|
|
1759
|
-
"border: 1px solid #d6d3cd",
|
|
1760
|
-
"border-radius: 12px",
|
|
1761
|
-
"box-shadow: 0 22px 44px -12px rgba(17, 19, 24, 0.26), 0 6px 14px -4px rgba(17, 19, 24, 0.10)",
|
|
1762
|
-
"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
1763
|
-
"font-size: 12px",
|
|
1764
2069
|
"display: none",
|
|
1765
|
-
"
|
|
1766
|
-
"
|
|
2070
|
+
"align-items: center",
|
|
2071
|
+
"gap: 6px",
|
|
2072
|
+
"padding: 6px 10px",
|
|
2073
|
+
"border-radius: 9999px",
|
|
2074
|
+
"background: #111318",
|
|
2075
|
+
"color: #faf9f6",
|
|
2076
|
+
"border: 1px solid rgba(250, 249, 246, 0.18)",
|
|
2077
|
+
"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
|
|
2078
|
+
"font-size: 11.5px",
|
|
2079
|
+
"font-weight: 500",
|
|
2080
|
+
"white-space: nowrap",
|
|
2081
|
+
"box-shadow: 0 12px 24px -6px rgba(17, 19, 24, 0.34)"
|
|
1767
2082
|
].join(";");
|
|
1768
2083
|
|
|
2084
|
+
document.body.appendChild(pinnedMarkers);
|
|
1769
2085
|
document.body.appendChild(leafOutline);
|
|
1770
2086
|
document.body.appendChild(overlay);
|
|
2087
|
+
document.body.appendChild(hud);
|
|
1771
2088
|
document.body.appendChild(pinMarker);
|
|
1772
|
-
document.body.appendChild(
|
|
2089
|
+
document.body.appendChild(toast);
|
|
1773
2090
|
|
|
2091
|
+
this.pinnedMarkersContainerEl = pinnedMarkers;
|
|
1774
2092
|
this.leafOutlineEl = leafOutline;
|
|
1775
2093
|
this.overlayEl = overlay;
|
|
1776
|
-
this.
|
|
2094
|
+
this.hudEl = hud;
|
|
1777
2095
|
this.pinMarkerEl = pinMarker;
|
|
1778
|
-
this.
|
|
2096
|
+
this.toastEl = toast;
|
|
1779
2097
|
}
|
|
1780
2098
|
|
|
1781
2099
|
unmountSelectionUi() {
|
|
1782
|
-
for (const el of [
|
|
2100
|
+
for (const el of [
|
|
2101
|
+
this.pinnedMarkersContainerEl,
|
|
2102
|
+
this.leafOutlineEl,
|
|
2103
|
+
this.overlayEl,
|
|
2104
|
+
this.hudEl,
|
|
2105
|
+
this.pinMarkerEl,
|
|
2106
|
+
this.toastEl
|
|
2107
|
+
]) {
|
|
1783
2108
|
if (el && el.parentNode) {
|
|
1784
2109
|
el.parentNode.removeChild(el);
|
|
1785
2110
|
}
|
|
1786
2111
|
}
|
|
2112
|
+
this.pinnedMarkersContainerEl = null;
|
|
1787
2113
|
this.leafOutlineEl = null;
|
|
1788
2114
|
this.overlayEl = null;
|
|
1789
|
-
this.
|
|
2115
|
+
this.hudEl = null;
|
|
1790
2116
|
this.pinMarkerEl = null;
|
|
1791
|
-
this.
|
|
2117
|
+
this.toastEl = null;
|
|
1792
2118
|
}
|
|
1793
2119
|
|
|
1794
2120
|
isInternalUiEvent(event ) {
|
|
1795
2121
|
const path = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
1796
2122
|
for (const node of path) {
|
|
1797
|
-
if (node
|
|
2123
|
+
if (isDomElementNode(node)) {
|
|
1798
2124
|
if (
|
|
1799
2125
|
node.tagName.toLowerCase() === "context-drop-widget" ||
|
|
1800
2126
|
node.hasAttribute("data-context-drop-ui") ||
|
|
@@ -1805,7 +2131,7 @@
|
|
|
1805
2131
|
}
|
|
1806
2132
|
}
|
|
1807
2133
|
}
|
|
1808
|
-
const rawTarget = event.target
|
|
2134
|
+
const rawTarget = isDomElementNode(event.target) ? event.target : null;
|
|
1809
2135
|
if (
|
|
1810
2136
|
rawTarget &&
|
|
1811
2137
|
typeof rawTarget.closest === "function" &&
|
|
@@ -1822,7 +2148,7 @@
|
|
|
1822
2148
|
try {
|
|
1823
2149
|
const fromPoint = document.elementsFromPoint(clientX, clientY);
|
|
1824
2150
|
for (const el of fromPoint) {
|
|
1825
|
-
if (el
|
|
2151
|
+
if (isDomElementNode(el)) {
|
|
1826
2152
|
results.push(el);
|
|
1827
2153
|
}
|
|
1828
2154
|
}
|
|
@@ -1832,12 +2158,12 @@
|
|
|
1832
2158
|
}
|
|
1833
2159
|
if (event && typeof event.composedPath === "function") {
|
|
1834
2160
|
for (const node of event.composedPath()) {
|
|
1835
|
-
if (node
|
|
2161
|
+
if (isDomElementNode(node) && !results.includes(node)) {
|
|
1836
2162
|
results.push(node);
|
|
1837
2163
|
}
|
|
1838
2164
|
}
|
|
1839
2165
|
}
|
|
1840
|
-
if (event && event.target
|
|
2166
|
+
if (event && isDomElementNode(event.target) && !results.includes(event.target)) {
|
|
1841
2167
|
results.unshift(event.target);
|
|
1842
2168
|
}
|
|
1843
2169
|
return results;
|
|
@@ -1852,17 +2178,39 @@
|
|
|
1852
2178
|
this.leafElement = null;
|
|
1853
2179
|
this.candidateStack = [];
|
|
1854
2180
|
this.activeCandidateIndex = 0;
|
|
2181
|
+
this.isScrubbingLayers = false;
|
|
1855
2182
|
return;
|
|
1856
2183
|
}
|
|
1857
2184
|
|
|
1858
|
-
// Preserve depth
|
|
2185
|
+
// Preserve depth & inline stack when pointer stays inside the exact same primary leaf element
|
|
1859
2186
|
if (this.leafElement === primary && this.candidateStack.length > 0) {
|
|
1860
2187
|
return;
|
|
1861
2188
|
}
|
|
1862
2189
|
|
|
2190
|
+
// Pointer-jitter lock: if user scrubbed to a specific layer and nudges the mouse slightly (<=28px)
|
|
2191
|
+
// across child boundaries inside that selected element right before clicking, keep it locked.
|
|
2192
|
+
if (this.isScrubbingLayers && this.candidateStack.length > 0) {
|
|
2193
|
+
const lockedCandidate = this.getActiveCandidate();
|
|
2194
|
+
const travel = Math.hypot(clientX - this.scrubOriginX, clientY - this.scrubOriginY);
|
|
2195
|
+
if (
|
|
2196
|
+
lockedCandidate &&
|
|
2197
|
+
travel <= SCRUB_JITTER_LOCK_PX &&
|
|
2198
|
+
(pointElements.includes(lockedCandidate.element) ||
|
|
2199
|
+
isPointInsideRect(clientX, clientY, lockedCandidate.element.getBoundingClientRect()))
|
|
2200
|
+
) {
|
|
2201
|
+
return;
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
|
|
1863
2205
|
this.leafElement = primary;
|
|
1864
2206
|
this.candidateStack = resolveCandidateStack(primary, pointElements, excluded, 10);
|
|
1865
2207
|
this.activeCandidateIndex = 0;
|
|
2208
|
+
this.isScrubbingLayers = false;
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
handleViewportScrollOrResize() {
|
|
2212
|
+
this.refreshPinnedMarkers();
|
|
2213
|
+
this.updateOverlayPosition();
|
|
1866
2214
|
}
|
|
1867
2215
|
|
|
1868
2216
|
handleMouseMove(event ) {
|
|
@@ -1871,12 +2219,9 @@
|
|
|
1871
2219
|
this.lastPointerX = event.clientX;
|
|
1872
2220
|
this.lastPointerY = event.clientY;
|
|
1873
2221
|
|
|
1874
|
-
if (this.anchored) {
|
|
1875
|
-
return;
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
2222
|
if (this.isInternalUiEvent(event)) {
|
|
1879
2223
|
if (this.overlayEl) this.overlayEl.style.display = "none";
|
|
2224
|
+
if (this.hudEl) this.hudEl.style.display = "none";
|
|
1880
2225
|
if (this.leafOutlineEl) this.leafOutlineEl.style.display = "none";
|
|
1881
2226
|
if (this.pinMarkerEl) this.pinMarkerEl.style.display = "none";
|
|
1882
2227
|
return;
|
|
@@ -1893,484 +2238,697 @@
|
|
|
1893
2238
|
this.notifyStateChange();
|
|
1894
2239
|
}
|
|
1895
2240
|
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
this.overlayEl.style.display = "none";
|
|
1902
|
-
if (this.leafOutlineEl) this.leafOutlineEl.style.display = "none";
|
|
1903
|
-
return;
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
const rect = currentCandidate.element.getBoundingClientRect();
|
|
1907
|
-
if (rect.width <= 0 || rect.height <= 0) {
|
|
1908
|
-
this.overlayEl.style.display = "none";
|
|
1909
|
-
return;
|
|
1910
|
-
}
|
|
2241
|
+
createSpanEl(text ) {
|
|
2242
|
+
const span = document.createElement("span");
|
|
2243
|
+
span.textContent = text;
|
|
2244
|
+
return span;
|
|
2245
|
+
}
|
|
1911
2246
|
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
2247
|
+
createKbdEl(text ) {
|
|
2248
|
+
const kbd = document.createElement("kbd");
|
|
2249
|
+
kbd.textContent = text;
|
|
2250
|
+
kbd.style.cssText = [
|
|
2251
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2252
|
+
"font-size: 10px",
|
|
2253
|
+
"font-weight: 600",
|
|
2254
|
+
"line-height: 1.1",
|
|
2255
|
+
"padding: 1px 4px",
|
|
2256
|
+
"border-radius: 4px",
|
|
2257
|
+
"background: rgba(250, 249, 246, 0.14)",
|
|
2258
|
+
"border: 1px solid rgba(250, 249, 246, 0.24)",
|
|
2259
|
+
"color: #faf9f6"
|
|
2260
|
+
].join(";");
|
|
2261
|
+
return kbd;
|
|
2262
|
+
}
|
|
1917
2263
|
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
2264
|
+
renderCompactHudContent(
|
|
2265
|
+
currentCandidate ,
|
|
2266
|
+
rect
|
|
2267
|
+
) {
|
|
2268
|
+
if (!this.hudEl) return;
|
|
2269
|
+
this.hudEl.innerHTML = "";
|
|
2270
|
+
this.hudEl.style.width = "auto";
|
|
2271
|
+
this.hudEl.style.maxWidth = "min(440px, calc(100vw - 20px))";
|
|
1926
2272
|
|
|
1927
2273
|
const total = this.candidateStack.length;
|
|
1928
2274
|
const pos = this.activeCandidateIndex + 1;
|
|
1929
2275
|
const dims = `${Math.round(rect.width)}×${Math.round(rect.height)}`;
|
|
1930
|
-
const
|
|
1931
|
-
|
|
2276
|
+
const pinnedInfo = this.findPinnedIndex(currentCandidate.element);
|
|
2277
|
+
const hasOverlap = this.candidateStack.some((c) => c.relation === "overlap");
|
|
1932
2278
|
|
|
1933
|
-
//
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
} else {
|
|
1943
|
-
this.leafOutlineEl.style.display = "none";
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
handleWheelCapture(event ) {
|
|
1949
|
-
if (!this.active) return;
|
|
1950
|
-
|
|
1951
|
-
// Allow natural scrolling inside the layer popover or widget itself
|
|
1952
|
-
if (this.isInternalUiEvent(event)) {
|
|
1953
|
-
return;
|
|
1954
|
-
}
|
|
2279
|
+
// Top Row: Identity + Dimensions + Layer Count
|
|
2280
|
+
const topRow = document.createElement("div");
|
|
2281
|
+
topRow.style.cssText = [
|
|
2282
|
+
"display: flex",
|
|
2283
|
+
"align-items: center",
|
|
2284
|
+
"gap: 6px",
|
|
2285
|
+
"padding: 6px 9px 5px",
|
|
2286
|
+
"white-space: nowrap"
|
|
2287
|
+
].join(";");
|
|
1955
2288
|
|
|
1956
|
-
if (
|
|
1957
|
-
|
|
2289
|
+
if (pinnedInfo) {
|
|
2290
|
+
const pinnedPill = document.createElement("span");
|
|
2291
|
+
pinnedPill.textContent = `#${pinnedInfo.index + 1} Pinned`;
|
|
2292
|
+
pinnedPill.style.cssText = [
|
|
2293
|
+
"padding: 1px 5px",
|
|
2294
|
+
"border-radius: 4px",
|
|
2295
|
+
"background: #c2410c",
|
|
2296
|
+
"color: #faf9f6",
|
|
2297
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2298
|
+
"font-size: 10px",
|
|
2299
|
+
"font-weight: 700",
|
|
2300
|
+
"font-variant-numeric: tabular-nums",
|
|
2301
|
+
"flex-shrink: 0"
|
|
2302
|
+
].join(";");
|
|
2303
|
+
topRow.appendChild(pinnedPill);
|
|
1958
2304
|
}
|
|
1959
2305
|
|
|
1960
|
-
|
|
1961
|
-
|
|
2306
|
+
const selectorSpan = document.createElement("span");
|
|
2307
|
+
selectorSpan.textContent = formatCandidateLabel(
|
|
2308
|
+
currentCandidate.tagName,
|
|
2309
|
+
currentCandidate.selector
|
|
2310
|
+
);
|
|
2311
|
+
selectorSpan.style.cssText = [
|
|
2312
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2313
|
+
"font-size: 11.5px",
|
|
2314
|
+
"font-weight: 600",
|
|
2315
|
+
"color: #faf9f6",
|
|
2316
|
+
"max-width: 230px",
|
|
2317
|
+
"overflow: hidden",
|
|
2318
|
+
"text-overflow: ellipsis",
|
|
2319
|
+
"white-space: nowrap"
|
|
2320
|
+
].join(";");
|
|
2321
|
+
topRow.appendChild(selectorSpan);
|
|
1962
2322
|
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
2323
|
+
const dimsSpan = document.createElement("span");
|
|
2324
|
+
dimsSpan.textContent = dims;
|
|
2325
|
+
dimsSpan.style.cssText = [
|
|
2326
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2327
|
+
"font-size: 10.5px",
|
|
2328
|
+
"font-variant-numeric: tabular-nums",
|
|
2329
|
+
"color: #cbd5e1",
|
|
2330
|
+
"flex-shrink: 0"
|
|
2331
|
+
].join(";");
|
|
2332
|
+
topRow.appendChild(dimsSpan);
|
|
1970
2333
|
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
2334
|
+
if (total > 1) {
|
|
2335
|
+
const layerPill = document.createElement("span");
|
|
2336
|
+
layerPill.style.cssText = [
|
|
2337
|
+
"display: inline-flex",
|
|
2338
|
+
"align-items: center",
|
|
2339
|
+
"gap: 3px",
|
|
2340
|
+
"padding: 1px 6px",
|
|
2341
|
+
"border-radius: 9999px",
|
|
2342
|
+
"background: rgba(29, 78, 216, 0.36)",
|
|
2343
|
+
"border: 1px solid rgba(96, 165, 250, 0.45)",
|
|
2344
|
+
"color: #dbeafe",
|
|
2345
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2346
|
+
"font-size: 10px",
|
|
2347
|
+
"font-weight: 600",
|
|
2348
|
+
"font-variant-numeric: tabular-nums",
|
|
2349
|
+
"flex-shrink: 0"
|
|
2350
|
+
].join(";");
|
|
2351
|
+
const iconWrap = document.createElement("span");
|
|
2352
|
+
iconWrap.style.cssText = "display: inline-flex; width: 11px; height: 11px; align-items: center;";
|
|
2353
|
+
iconWrap.innerHTML = ICON_LAYERS;
|
|
2354
|
+
const countText = document.createElement("span");
|
|
2355
|
+
countText.textContent = `${pos}/${total}`;
|
|
2356
|
+
layerPill.appendChild(iconWrap);
|
|
2357
|
+
layerPill.appendChild(countText);
|
|
2358
|
+
topRow.appendChild(layerPill);
|
|
1975
2359
|
}
|
|
1976
2360
|
|
|
1977
|
-
|
|
1978
|
-
event.preventDefault();
|
|
1979
|
-
event.stopPropagation();
|
|
1980
|
-
if (typeof event.stopImmediatePropagation === "function") {
|
|
1981
|
-
event.stopImmediatePropagation();
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
2361
|
+
this.hudEl.appendChild(topRow);
|
|
1984
2362
|
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
2363
|
+
// Bottom Row: Action Coaching Strip
|
|
2364
|
+
const coachRow = document.createElement("div");
|
|
2365
|
+
coachRow.style.cssText = [
|
|
2366
|
+
"display: flex",
|
|
2367
|
+
"align-items: center",
|
|
2368
|
+
"gap: 8px",
|
|
2369
|
+
"padding: 4px 9px 5px",
|
|
2370
|
+
"background: rgba(250, 249, 246, 0.05)",
|
|
2371
|
+
"border-top: 1px solid rgba(250, 249, 246, 0.10)",
|
|
2372
|
+
"font-size: 10.5px",
|
|
2373
|
+
"color: #cbd5e1",
|
|
2374
|
+
"white-space: nowrap"
|
|
2375
|
+
].join(";");
|
|
1990
2376
|
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
2377
|
+
const clickHint = document.createElement("span");
|
|
2378
|
+
const clickStrong = document.createElement("strong");
|
|
2379
|
+
clickStrong.style.cssText = pinnedInfo
|
|
2380
|
+
? "color: #ffedd5; font-weight: 600;"
|
|
2381
|
+
: "color: #faf9f6; font-weight: 600;";
|
|
2382
|
+
clickStrong.textContent = "Click";
|
|
2383
|
+
clickHint.appendChild(clickStrong);
|
|
2384
|
+
clickHint.appendChild(this.createSpanEl(pinnedInfo ? " to unpin" : " to pin"));
|
|
2385
|
+
coachRow.appendChild(clickHint);
|
|
2386
|
+
|
|
2387
|
+
if (total > 1) {
|
|
2388
|
+
const scrollHint = document.createElement("span");
|
|
2389
|
+
scrollHint.style.cssText = "display: inline-flex; align-items: center; gap: 3px;";
|
|
2390
|
+
const wheelIcon = document.createElement("span");
|
|
2391
|
+
wheelIcon.style.cssText = "display: inline-flex; color: #dbeafe;";
|
|
2392
|
+
wheelIcon.innerHTML = ICON_SCROLL_VERTICAL;
|
|
2393
|
+
const scrollStrong = document.createElement("strong");
|
|
2394
|
+
scrollStrong.style.cssText = hasOverlap
|
|
2395
|
+
? "color: #dbeafe; font-weight: 600;"
|
|
2396
|
+
: "color: #faf9f6; font-weight: 600;";
|
|
2397
|
+
scrollStrong.textContent = "Scroll wheel";
|
|
2398
|
+
scrollHint.appendChild(wheelIcon);
|
|
2399
|
+
scrollHint.appendChild(scrollStrong);
|
|
2400
|
+
scrollHint.appendChild(
|
|
2401
|
+
this.createSpanEl(hasOverlap ? " for element behind" : ` for ${total} layers`)
|
|
2402
|
+
);
|
|
2403
|
+
coachRow.appendChild(scrollHint);
|
|
1995
2404
|
}
|
|
1996
2405
|
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
this.
|
|
2000
|
-
this.
|
|
2406
|
+
const escHint = document.createElement("span");
|
|
2407
|
+
escHint.style.cssText = "display: inline-flex; align-items: center; gap: 4px;";
|
|
2408
|
+
escHint.appendChild(this.createKbdEl("Esc"));
|
|
2409
|
+
escHint.appendChild(this.createSpanEl("done"));
|
|
2410
|
+
coachRow.appendChild(escHint);
|
|
2001
2411
|
|
|
2002
|
-
|
|
2003
|
-
if (!activeCandidate) return;
|
|
2004
|
-
|
|
2005
|
-
// Fast-path: Shift+Click or single-layer target pins immediately
|
|
2006
|
-
if (event.shiftKey || this.candidateStack.length === 1) {
|
|
2007
|
-
this.selectElementDirectly(activeCandidate.element);
|
|
2008
|
-
return;
|
|
2009
|
-
}
|
|
2010
|
-
|
|
2011
|
-
// Otherwise anchor the floating pin and open the Layer & Hierarchy Disambiguation Popover
|
|
2012
|
-
this.anchored = true;
|
|
2013
|
-
if (this.pinMarkerEl) {
|
|
2014
|
-
this.pinMarkerEl.style.display = "inline-flex";
|
|
2015
|
-
this.pinMarkerEl.style.left = `${this.anchorX}px`;
|
|
2016
|
-
this.pinMarkerEl.style.top = `${this.anchorY}px`;
|
|
2017
|
-
this.pinMarkerEl.style.transform = "scale(1.08)";
|
|
2018
|
-
}
|
|
2019
|
-
this.updateOverlayPosition();
|
|
2020
|
-
this.renderLayerPopover();
|
|
2021
|
-
this.notifyStateChange();
|
|
2412
|
+
this.hudEl.appendChild(coachRow);
|
|
2022
2413
|
}
|
|
2023
2414
|
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
this.pinMarkerEl.style.left = `${this.lastPointerX}px`;
|
|
2033
|
-
this.pinMarkerEl.style.top = `${this.lastPointerY}px`;
|
|
2034
|
-
}
|
|
2035
|
-
this.notifyStateChange();
|
|
2036
|
-
}
|
|
2037
|
-
|
|
2038
|
-
renderLayerPopover() {
|
|
2039
|
-
if (!this.popoverEl || typeof window === "undefined") return;
|
|
2040
|
-
const activeCandidate = this.getActiveCandidate();
|
|
2041
|
-
if (!activeCandidate) return;
|
|
2415
|
+
renderScrubbingHudContent(
|
|
2416
|
+
currentCandidate ,
|
|
2417
|
+
rect
|
|
2418
|
+
) {
|
|
2419
|
+
if (!this.hudEl) return;
|
|
2420
|
+
this.hudEl.innerHTML = "";
|
|
2421
|
+
this.hudEl.style.width = "320px";
|
|
2422
|
+
this.hudEl.style.maxWidth = "calc(100vw - 20px)";
|
|
2042
2423
|
|
|
2043
|
-
this.
|
|
2044
|
-
this.
|
|
2424
|
+
const total = this.candidateStack.length;
|
|
2425
|
+
const pos = this.activeCandidateIndex + 1;
|
|
2045
2426
|
|
|
2046
|
-
// Header
|
|
2427
|
+
// Header Strip
|
|
2047
2428
|
const header = document.createElement("div");
|
|
2048
2429
|
header.style.cssText = [
|
|
2049
2430
|
"display: flex",
|
|
2050
2431
|
"align-items: center",
|
|
2051
2432
|
"justify-content: space-between",
|
|
2052
2433
|
"gap: 8px",
|
|
2053
|
-
"padding: 10px
|
|
2054
|
-
"background:
|
|
2055
|
-
"border-bottom: 1px solid
|
|
2056
|
-
].join(";");
|
|
2057
|
-
|
|
2058
|
-
const titleGroup = document.createElement("div");
|
|
2059
|
-
titleGroup.style.cssText = "display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; color: #111318;";
|
|
2060
|
-
const layersIconSpan = document.createElement("span");
|
|
2061
|
-
layersIconSpan.style.cssText = "display: inline-flex; color: #c2410c;";
|
|
2062
|
-
layersIconSpan.innerHTML = ICON_LAYERS;
|
|
2063
|
-
const titleText = document.createElement("span");
|
|
2064
|
-
titleText.textContent = `Choose Element Layer (${this.candidateStack.length})`;
|
|
2065
|
-
titleGroup.appendChild(layersIconSpan);
|
|
2066
|
-
titleGroup.appendChild(titleText);
|
|
2067
|
-
|
|
2068
|
-
const headerActions = document.createElement("div");
|
|
2069
|
-
headerActions.style.cssText = "display: flex; align-items: center; gap: 4px;";
|
|
2070
|
-
|
|
2071
|
-
const stepUpBtn = document.createElement("button");
|
|
2072
|
-
stepUpBtn.type = "button";
|
|
2073
|
-
stepUpBtn.title = "Step to parent/outer layer (Up arrow)";
|
|
2074
|
-
stepUpBtn.setAttribute("aria-label", "Step to outer layer");
|
|
2075
|
-
stepUpBtn.style.cssText = [
|
|
2076
|
-
"display: inline-flex",
|
|
2077
|
-
"align-items: center",
|
|
2078
|
-
"justify-content: center",
|
|
2079
|
-
"width: 24px",
|
|
2080
|
-
"height: 24px",
|
|
2081
|
-
"border-radius: 6px",
|
|
2082
|
-
"border: 1px solid #d6d3cd",
|
|
2083
|
-
"background: #faf9f6",
|
|
2084
|
-
"color: #111318",
|
|
2085
|
-
"cursor: pointer"
|
|
2434
|
+
"padding: 6px 10px",
|
|
2435
|
+
"background: rgba(250, 249, 246, 0.05)",
|
|
2436
|
+
"border-bottom: 1px solid rgba(250, 249, 246, 0.12)"
|
|
2086
2437
|
].join(";");
|
|
2087
|
-
stepUpBtn.innerHTML = ICON_CHEVRON_UP;
|
|
2088
|
-
stepUpBtn.disabled = this.activeCandidateIndex >= this.candidateStack.length - 1;
|
|
2089
|
-
stepUpBtn.addEventListener("click", (ev) => {
|
|
2090
|
-
ev.stopPropagation();
|
|
2091
|
-
this.cycleDepth(1);
|
|
2092
|
-
});
|
|
2093
|
-
|
|
2094
|
-
const stepDownBtn = document.createElement("button");
|
|
2095
|
-
stepDownBtn.type = "button";
|
|
2096
|
-
stepDownBtn.title = "Step to inner/child layer (Down arrow)";
|
|
2097
|
-
stepDownBtn.setAttribute("aria-label", "Step to inner layer");
|
|
2098
|
-
stepDownBtn.style.cssText = stepUpBtn.style.cssText;
|
|
2099
|
-
stepDownBtn.innerHTML = ICON_CHEVRON_DOWN;
|
|
2100
|
-
stepDownBtn.disabled = this.activeCandidateIndex <= 0;
|
|
2101
|
-
stepDownBtn.addEventListener("click", (ev) => {
|
|
2102
|
-
ev.stopPropagation();
|
|
2103
|
-
this.cycleDepth(-1);
|
|
2104
|
-
});
|
|
2105
2438
|
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
"color: #
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
headerActions.appendChild(stepDownBtn);
|
|
2129
|
-
headerActions.appendChild(stepUpBtn);
|
|
2130
|
-
headerActions.appendChild(closeBtn);
|
|
2131
|
-
header.appendChild(titleGroup);
|
|
2132
|
-
header.appendChild(headerActions);
|
|
2133
|
-
this.popoverEl.appendChild(header);
|
|
2134
|
-
|
|
2135
|
-
// Interactive DOM Breadcrumb Bar
|
|
2136
|
-
const ancestors = resolveAncestorChain(
|
|
2137
|
-
activeCandidate.element,
|
|
2138
|
-
this.callbacks.getExcludedSelectors(),
|
|
2139
|
-
6
|
|
2140
|
-
);
|
|
2141
|
-
if (ancestors.length > 0) {
|
|
2142
|
-
const breadcrumbBar = document.createElement("div");
|
|
2143
|
-
breadcrumbBar.setAttribute("data-context-drop-ui", "breadcrumb-bar");
|
|
2144
|
-
breadcrumbBar.style.cssText = [
|
|
2145
|
-
"display: flex",
|
|
2146
|
-
"align-items: center",
|
|
2147
|
-
"flex-wrap: wrap",
|
|
2148
|
-
"gap: 3px",
|
|
2149
|
-
"padding: 7px 12px",
|
|
2150
|
-
"background: #f5f3ee",
|
|
2151
|
-
"border-bottom: 1px solid #e4e1da",
|
|
2152
|
-
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2153
|
-
"font-size: 11px"
|
|
2154
|
-
].join(";");
|
|
2155
|
-
|
|
2156
|
-
ancestors.forEach((ancEl, idx) => {
|
|
2157
|
-
if (idx > 0) {
|
|
2158
|
-
const sep = document.createElement("span");
|
|
2159
|
-
sep.style.cssText = "display: inline-flex; color: #687082;";
|
|
2160
|
-
sep.innerHTML = ICON_CHEVRON_RIGHT;
|
|
2161
|
-
breadcrumbBar.appendChild(sep);
|
|
2162
|
-
}
|
|
2163
|
-
|
|
2164
|
-
const isCurrent = ancEl === activeCandidate.element;
|
|
2165
|
-
const crumbBtn = document.createElement("button");
|
|
2166
|
-
crumbBtn.type = "button";
|
|
2167
|
-
crumbBtn.textContent = computeSelector(ancEl);
|
|
2168
|
-
crumbBtn.style.cssText = [
|
|
2169
|
-
"appearance: none",
|
|
2170
|
-
"border: 1px solid " + (isCurrent ? "#1d4ed8" : "transparent"),
|
|
2171
|
-
"background: " + (isCurrent ? "#dbeafe" : "transparent"),
|
|
2172
|
-
"color: " + (isCurrent ? "#1e3a8a" : "#4b5262"),
|
|
2173
|
-
"font-family: inherit",
|
|
2174
|
-
"font-size: 11px",
|
|
2175
|
-
"font-weight: " + (isCurrent ? "600" : "500"),
|
|
2176
|
-
"padding: 2px 5px",
|
|
2177
|
-
"border-radius: 4px",
|
|
2178
|
-
"cursor: pointer",
|
|
2179
|
-
"max-width: 130px",
|
|
2180
|
-
"overflow: hidden",
|
|
2181
|
-
"text-overflow: ellipsis",
|
|
2182
|
-
"white-space: nowrap"
|
|
2183
|
-
].join(";");
|
|
2184
|
-
|
|
2185
|
-
crumbBtn.addEventListener("mouseenter", () => {
|
|
2186
|
-
this.focusCandidateElement(ancEl);
|
|
2187
|
-
});
|
|
2188
|
-
crumbBtn.addEventListener("click", (ev) => {
|
|
2189
|
-
ev.stopPropagation();
|
|
2190
|
-
this.selectElementDirectly(ancEl);
|
|
2191
|
-
});
|
|
2192
|
-
|
|
2193
|
-
breadcrumbBar.appendChild(crumbBtn);
|
|
2194
|
-
});
|
|
2195
|
-
|
|
2196
|
-
this.popoverEl.appendChild(breadcrumbBar);
|
|
2197
|
-
}
|
|
2439
|
+
const headerLeft = document.createElement("div");
|
|
2440
|
+
headerLeft.style.cssText =
|
|
2441
|
+
"display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: #faf9f6;";
|
|
2442
|
+
const layersIcon = document.createElement("span");
|
|
2443
|
+
layersIcon.style.cssText = "display: inline-flex; color: #60a5fa;";
|
|
2444
|
+
layersIcon.innerHTML = ICON_LAYERS;
|
|
2445
|
+
const headerTitle = document.createElement("span");
|
|
2446
|
+
headerTitle.textContent = "Select Layer";
|
|
2447
|
+
headerLeft.appendChild(layersIcon);
|
|
2448
|
+
headerLeft.appendChild(headerTitle);
|
|
2449
|
+
|
|
2450
|
+
const headerRight = document.createElement("div");
|
|
2451
|
+
headerRight.style.cssText =
|
|
2452
|
+
"display: inline-flex; align-items: center; gap: 5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10.5px; font-variant-numeric: tabular-nums; color: #cbd5e1;";
|
|
2453
|
+
const wheelSpan = document.createElement("span");
|
|
2454
|
+
wheelSpan.style.cssText = "display: inline-flex; color: #dbeafe;";
|
|
2455
|
+
wheelSpan.innerHTML = ICON_SCROLL_VERTICAL;
|
|
2456
|
+
const ratioSpan = document.createElement("span");
|
|
2457
|
+
ratioSpan.textContent = `${pos}/${total}`;
|
|
2458
|
+
headerRight.appendChild(wheelSpan);
|
|
2459
|
+
headerRight.appendChild(ratioSpan);
|
|
2198
2460
|
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2461
|
+
header.appendChild(headerLeft);
|
|
2462
|
+
header.appendChild(headerRight);
|
|
2463
|
+
this.hudEl.appendChild(header);
|
|
2464
|
+
|
|
2465
|
+
// Non-scrolling Sliding Window of Layers (max 5 rows)
|
|
2466
|
+
const start =
|
|
2467
|
+
total <= MAX_VISIBLE_STACK_ROWS
|
|
2468
|
+
? 0
|
|
2469
|
+
: Math.max(0, Math.min(this.activeCandidateIndex - 2, total - MAX_VISIBLE_STACK_ROWS));
|
|
2470
|
+
const end = Math.min(total, start + MAX_VISIBLE_STACK_ROWS);
|
|
2471
|
+
|
|
2472
|
+
const listWrap = document.createElement("div");
|
|
2473
|
+
listWrap.setAttribute("data-context-drop-ui", "hud-layer-list");
|
|
2474
|
+
listWrap.style.cssText = [
|
|
2205
2475
|
"display: flex",
|
|
2206
2476
|
"flex-direction: column",
|
|
2207
|
-
"gap:
|
|
2477
|
+
"gap: 2px",
|
|
2478
|
+
"padding: 5px"
|
|
2208
2479
|
].join(";");
|
|
2209
2480
|
|
|
2481
|
+
if (start > 0) {
|
|
2482
|
+
const aboveHint = document.createElement("div");
|
|
2483
|
+
aboveHint.textContent = `${start} inner layer${start > 1 ? "s" : ""} above`;
|
|
2484
|
+
aboveHint.style.cssText =
|
|
2485
|
+
"font-size: 10px; color: #cbd5e1; padding: 1px 7px; font-variant-numeric: tabular-nums;";
|
|
2486
|
+
listWrap.appendChild(aboveHint);
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2210
2489
|
const relationLabels = {
|
|
2211
2490
|
target: "Topmost",
|
|
2212
|
-
overlap: "
|
|
2491
|
+
overlap: "Behind",
|
|
2213
2492
|
child: "Child",
|
|
2214
2493
|
ancestor: "Parent"
|
|
2215
2494
|
};
|
|
2216
2495
|
|
|
2217
|
-
|
|
2496
|
+
for (let idx = start; idx < end; idx += 1) {
|
|
2497
|
+
const candidate = this.candidateStack[idx];
|
|
2218
2498
|
const isSelected = idx === this.activeCandidateIndex;
|
|
2219
|
-
const
|
|
2220
|
-
|
|
2499
|
+
const candPinned = this.findPinnedIndex(candidate.element);
|
|
2500
|
+
|
|
2501
|
+
const row = document.createElement("div");
|
|
2221
2502
|
row.setAttribute("data-context-drop-layer-index", String(idx));
|
|
2503
|
+
if (isSelected) {
|
|
2504
|
+
row.setAttribute("data-selected", "true");
|
|
2505
|
+
}
|
|
2222
2506
|
row.style.cssText = [
|
|
2223
|
-
"appearance: none",
|
|
2224
|
-
"width: 100%",
|
|
2225
|
-
"text-align: left",
|
|
2226
2507
|
"display: flex",
|
|
2227
|
-
"
|
|
2228
|
-
"
|
|
2229
|
-
"
|
|
2230
|
-
"
|
|
2231
|
-
"border:
|
|
2232
|
-
"
|
|
2233
|
-
"
|
|
2234
|
-
"cursor: pointer",
|
|
2235
|
-
"transition: background-color 0.1s ease"
|
|
2508
|
+
"align-items: center",
|
|
2509
|
+
"justify-content: space-between",
|
|
2510
|
+
"gap: 6px",
|
|
2511
|
+
"padding: " + (isSelected ? "5px 7px" : "4px 7px"),
|
|
2512
|
+
"border-radius: 7px",
|
|
2513
|
+
"border: 1px solid " + (isSelected ? "#60a5fa" : "transparent"),
|
|
2514
|
+
"background: " + (isSelected ? "rgba(29, 78, 216, 0.34)" : "transparent")
|
|
2236
2515
|
].join(";");
|
|
2237
2516
|
|
|
2238
|
-
const topLine = document.createElement("div");
|
|
2239
|
-
topLine.style.cssText = "display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%;";
|
|
2240
|
-
|
|
2241
2517
|
const leftGroup = document.createElement("div");
|
|
2242
|
-
leftGroup.style.cssText = "display: flex; align-items: center; gap:
|
|
2518
|
+
leftGroup.style.cssText = "display: flex; align-items: center; gap: 5px; min-width: 0; flex: 1;";
|
|
2243
2519
|
|
|
2244
2520
|
const relBadge = document.createElement("span");
|
|
2245
2521
|
relBadge.textContent = relationLabels[candidate.relation] || "Layer";
|
|
2522
|
+
const relBg =
|
|
2523
|
+
candidate.relation === "target"
|
|
2524
|
+
? "rgba(255, 237, 213, 0.16)"
|
|
2525
|
+
: candidate.relation === "overlap"
|
|
2526
|
+
? "rgba(252, 231, 243, 0.20)"
|
|
2527
|
+
: "rgba(226, 232, 240, 0.14)";
|
|
2528
|
+
const relColor =
|
|
2529
|
+
candidate.relation === "target"
|
|
2530
|
+
? "#ffedd5"
|
|
2531
|
+
: candidate.relation === "overlap"
|
|
2532
|
+
? "#fee2e2"
|
|
2533
|
+
: "#cbd5e1";
|
|
2246
2534
|
relBadge.style.cssText = [
|
|
2247
|
-
"font-size:
|
|
2535
|
+
"font-size: 9.5px",
|
|
2248
2536
|
"font-weight: 600",
|
|
2249
2537
|
"padding: 1px 5px",
|
|
2250
2538
|
"border-radius: 4px",
|
|
2251
|
-
|
|
2252
|
-
|
|
2539
|
+
`background: ${relBg}`,
|
|
2540
|
+
`color: ${relColor}`,
|
|
2253
2541
|
"flex-shrink: 0"
|
|
2254
2542
|
].join(";");
|
|
2255
2543
|
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2258
|
-
|
|
2544
|
+
const selText = document.createElement("span");
|
|
2545
|
+
selText.textContent = formatCandidateLabel(candidate.tagName, candidate.selector);
|
|
2546
|
+
selText.style.cssText = [
|
|
2259
2547
|
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2260
|
-
"font-size:
|
|
2261
|
-
"font-weight: 600",
|
|
2262
|
-
"color: #
|
|
2548
|
+
"font-size: 11px",
|
|
2549
|
+
"font-weight: " + (isSelected ? "600" : "500"),
|
|
2550
|
+
"color: " + (isSelected ? "#faf9f6" : "#e2e8f0"),
|
|
2263
2551
|
"overflow: hidden",
|
|
2264
2552
|
"text-overflow: ellipsis",
|
|
2265
2553
|
"white-space: nowrap"
|
|
2266
2554
|
].join(";");
|
|
2267
2555
|
|
|
2268
2556
|
leftGroup.appendChild(relBadge);
|
|
2269
|
-
leftGroup.appendChild(
|
|
2557
|
+
leftGroup.appendChild(selText);
|
|
2270
2558
|
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
row.appendChild(topLine);
|
|
2284
|
-
|
|
2285
|
-
if (candidate.textPreview) {
|
|
2286
|
-
const previewLine = document.createElement("div");
|
|
2287
|
-
previewLine.textContent = `"${candidate.textPreview}"`;
|
|
2288
|
-
previewLine.style.cssText = [
|
|
2289
|
-
"font-size: 11px",
|
|
2290
|
-
"color: #4b5262",
|
|
2291
|
-
"overflow: hidden",
|
|
2292
|
-
"text-overflow: ellipsis",
|
|
2293
|
-
"white-space: nowrap",
|
|
2294
|
-
"padding-left: 2px"
|
|
2559
|
+
if (candPinned) {
|
|
2560
|
+
const pinTag = document.createElement("span");
|
|
2561
|
+
pinTag.textContent = `#${candPinned.index + 1}`;
|
|
2562
|
+
pinTag.style.cssText = [
|
|
2563
|
+
"padding: 0 4px",
|
|
2564
|
+
"border-radius: 4px",
|
|
2565
|
+
"background: #c2410c",
|
|
2566
|
+
"color: #faf9f6",
|
|
2567
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2568
|
+
"font-size: 9.5px",
|
|
2569
|
+
"font-weight: 700",
|
|
2570
|
+
"flex-shrink: 0"
|
|
2295
2571
|
].join(";");
|
|
2296
|
-
|
|
2572
|
+
leftGroup.appendChild(pinTag);
|
|
2297
2573
|
}
|
|
2298
2574
|
|
|
2299
|
-
row.
|
|
2300
|
-
if (this.activeCandidateIndex !== idx) {
|
|
2301
|
-
this.activeCandidateIndex = idx;
|
|
2302
|
-
this.updateOverlayPosition();
|
|
2303
|
-
this.notifyStateChange();
|
|
2304
|
-
}
|
|
2305
|
-
});
|
|
2575
|
+
row.appendChild(leftGroup);
|
|
2306
2576
|
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2577
|
+
if (isSelected) {
|
|
2578
|
+
const actionBadge = document.createElement("span");
|
|
2579
|
+
actionBadge.textContent = candPinned ? "Click unpin" : "Click to pin";
|
|
2580
|
+
actionBadge.style.cssText = [
|
|
2581
|
+
"padding: 1px 6px",
|
|
2582
|
+
"border-radius: 4px",
|
|
2583
|
+
"background: " + (candPinned ? "rgba(250, 249, 246, 0.18)" : "#c2410c"),
|
|
2584
|
+
"color: #faf9f6",
|
|
2585
|
+
"font-size: 10px",
|
|
2586
|
+
"font-weight: 600",
|
|
2587
|
+
"flex-shrink: 0"
|
|
2588
|
+
].join(";");
|
|
2589
|
+
row.appendChild(actionBadge);
|
|
2590
|
+
} else {
|
|
2591
|
+
const rowDims = document.createElement("span");
|
|
2592
|
+
rowDims.textContent = `${Math.round(candidate.rect.width)}×${Math.round(candidate.rect.height)}`;
|
|
2593
|
+
rowDims.style.cssText = [
|
|
2594
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
2595
|
+
"font-size: 10px",
|
|
2596
|
+
"font-variant-numeric: tabular-nums",
|
|
2597
|
+
"color: #cbd5e1",
|
|
2598
|
+
"flex-shrink: 0"
|
|
2599
|
+
].join(";");
|
|
2600
|
+
row.appendChild(rowDims);
|
|
2601
|
+
}
|
|
2311
2602
|
|
|
2312
|
-
|
|
2313
|
-
}
|
|
2603
|
+
listWrap.appendChild(row);
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
if (end < total) {
|
|
2607
|
+
const belowHint = document.createElement("div");
|
|
2608
|
+
belowHint.textContent = `${total - end} parent layer${total - end > 1 ? "s" : ""} below`;
|
|
2609
|
+
belowHint.style.cssText =
|
|
2610
|
+
"font-size: 10px; color: #cbd5e1; padding: 1px 7px; font-variant-numeric: tabular-nums;";
|
|
2611
|
+
listWrap.appendChild(belowHint);
|
|
2612
|
+
}
|
|
2314
2613
|
|
|
2315
|
-
this.
|
|
2614
|
+
this.hudEl.appendChild(listWrap);
|
|
2316
2615
|
|
|
2317
|
-
// Footer
|
|
2616
|
+
// Footer Strip
|
|
2318
2617
|
const footer = document.createElement("div");
|
|
2319
2618
|
footer.style.cssText = [
|
|
2320
2619
|
"display: flex",
|
|
2321
2620
|
"align-items: center",
|
|
2322
2621
|
"justify-content: space-between",
|
|
2323
|
-
"
|
|
2324
|
-
"
|
|
2325
|
-
"
|
|
2622
|
+
"gap: 8px",
|
|
2623
|
+
"padding: 5px 10px",
|
|
2624
|
+
"background: rgba(250, 249, 246, 0.04)",
|
|
2625
|
+
"border-top: 1px solid rgba(250, 249, 246, 0.10)",
|
|
2626
|
+
"font-size: 10.5px",
|
|
2627
|
+
"color: #cbd5e1"
|
|
2326
2628
|
].join(";");
|
|
2327
2629
|
|
|
2328
|
-
const
|
|
2329
|
-
|
|
2330
|
-
|
|
2630
|
+
const dimsLabel = document.createElement("span");
|
|
2631
|
+
dimsLabel.textContent = `${Math.round(rect.width)}×${Math.round(rect.height)}`;
|
|
2632
|
+
dimsLabel.style.cssText =
|
|
2633
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; font-variant-numeric: tabular-nums;";
|
|
2634
|
+
|
|
2635
|
+
const keysHint = document.createElement("span");
|
|
2636
|
+
keysHint.style.cssText = "display: inline-flex; align-items: center; gap: 4px;";
|
|
2637
|
+
keysHint.appendChild(this.createKbdEl("Enter"));
|
|
2638
|
+
keysHint.appendChild(this.createSpanEl("pin · "));
|
|
2639
|
+
keysHint.appendChild(this.createKbdEl("Esc"));
|
|
2640
|
+
keysHint.appendChild(this.createSpanEl("done"));
|
|
2641
|
+
|
|
2642
|
+
footer.appendChild(dimsLabel);
|
|
2643
|
+
footer.appendChild(keysHint);
|
|
2644
|
+
this.hudEl.appendChild(footer);
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
positionHudElement(rect ) {
|
|
2648
|
+
if (!this.hudEl || typeof window === "undefined") return;
|
|
2649
|
+
|
|
2650
|
+
const vw = window.innerWidth || 1024;
|
|
2651
|
+
const vh = window.innerHeight || 768;
|
|
2652
|
+
const fallbackWidth = this.isScrubbingLayers ? 320 : 300;
|
|
2653
|
+
const visibleRows = Math.min(this.candidateStack.length, MAX_VISIBLE_STACK_ROWS);
|
|
2654
|
+
const fallbackHeight = this.isScrubbingLayers ? 66 + visibleRows * 30 : 54;
|
|
2655
|
+
|
|
2656
|
+
const hudWidth = (this.hudEl ).offsetWidth || fallbackWidth;
|
|
2657
|
+
const hudHeight = (this.hudEl ).offsetHeight || fallbackHeight;
|
|
2658
|
+
|
|
2659
|
+
const clampedLeft = Math.max(10, Math.min(rect.left, vw - hudWidth - 10));
|
|
2660
|
+
let top = rect.top - hudHeight - 8;
|
|
2661
|
+
|
|
2662
|
+
if (top < 10) {
|
|
2663
|
+
const belowTop = rect.top + rect.height + 8;
|
|
2664
|
+
if (belowTop + hudHeight <= vh - 10) {
|
|
2665
|
+
top = belowTop;
|
|
2666
|
+
} else {
|
|
2667
|
+
// Large container spanning viewport: place near top-left of visible area, stepping below cursor if close
|
|
2668
|
+
const insideTop = Math.max(10, rect.top + 8);
|
|
2669
|
+
if (
|
|
2670
|
+
Math.abs(this.lastPointerY - insideTop) < hudHeight + 18 &&
|
|
2671
|
+
this.lastPointerX < clampedLeft + hudWidth + 24
|
|
2672
|
+
) {
|
|
2673
|
+
top = Math.min(vh - hudHeight - 10, this.lastPointerY + 22);
|
|
2674
|
+
} else {
|
|
2675
|
+
top = insideTop;
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
this.hudEl.style.left = `${Math.round(clampedLeft)}px`;
|
|
2681
|
+
this.hudEl.style.top = `${Math.round(Math.max(10, top))}px`;
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
updateOverlayPosition() {
|
|
2685
|
+
if (!this.overlayEl || !this.hudEl) return;
|
|
2686
|
+
|
|
2687
|
+
const currentCandidate = this.getActiveCandidate();
|
|
2688
|
+
if (!currentCandidate) {
|
|
2689
|
+
this.overlayEl.style.display = "none";
|
|
2690
|
+
this.hudEl.style.display = "none";
|
|
2691
|
+
if (this.leafOutlineEl) this.leafOutlineEl.style.display = "none";
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
const rect = currentCandidate.element.getBoundingClientRect();
|
|
2696
|
+
if (rect.width <= 0 || rect.height <= 0) {
|
|
2697
|
+
this.overlayEl.style.display = "none";
|
|
2698
|
+
this.hudEl.style.display = "none";
|
|
2699
|
+
return;
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
this.overlayEl.style.display = "block";
|
|
2703
|
+
this.overlayEl.style.left = `${rect.left}px`;
|
|
2704
|
+
this.overlayEl.style.top = `${rect.top}px`;
|
|
2705
|
+
this.overlayEl.style.width = `${rect.width}px`;
|
|
2706
|
+
this.overlayEl.style.height = `${rect.height}px`;
|
|
2707
|
+
|
|
2708
|
+
this.hudEl.style.display = "block";
|
|
2709
|
+
if (this.isScrubbingLayers && this.candidateStack.length > 1) {
|
|
2710
|
+
this.renderScrubbingHudContent(currentCandidate, rect);
|
|
2711
|
+
} else {
|
|
2712
|
+
this.renderCompactHudContent(currentCandidate, rect);
|
|
2713
|
+
}
|
|
2714
|
+
this.positionHudElement(rect);
|
|
2715
|
+
|
|
2716
|
+
// Show ghost leaf outline when inspecting an ancestor or overlapping layer
|
|
2717
|
+
if (this.leafOutlineEl) {
|
|
2718
|
+
if (
|
|
2719
|
+
this.activeCandidateIndex > 0 &&
|
|
2720
|
+
this.leafElement &&
|
|
2721
|
+
this.leafElement !== currentCandidate.element
|
|
2722
|
+
) {
|
|
2723
|
+
const leafRect = this.leafElement.getBoundingClientRect();
|
|
2724
|
+
this.leafOutlineEl.style.display = "block";
|
|
2725
|
+
this.leafOutlineEl.style.left = `${leafRect.left}px`;
|
|
2726
|
+
this.leafOutlineEl.style.top = `${leafRect.top}px`;
|
|
2727
|
+
this.leafOutlineEl.style.width = `${leafRect.width}px`;
|
|
2728
|
+
this.leafOutlineEl.style.height = `${leafRect.height}px`;
|
|
2729
|
+
} else {
|
|
2730
|
+
this.leafOutlineEl.style.display = "none";
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
triggerHudBoundaryNudge(offsetY ) {
|
|
2736
|
+
if (!this.hudEl) return;
|
|
2737
|
+
this.hudEl.style.transform = `translateY(${offsetY}px)`;
|
|
2738
|
+
if (this.nudgeTimer !== null) {
|
|
2739
|
+
clearTimeout(this.nudgeTimer);
|
|
2740
|
+
}
|
|
2741
|
+
this.nudgeTimer = setTimeout(() => {
|
|
2742
|
+
if (this.hudEl) {
|
|
2743
|
+
this.hudEl.style.transform = "translateY(0)";
|
|
2744
|
+
}
|
|
2745
|
+
this.nudgeTimer = null;
|
|
2746
|
+
}, 120);
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
flashSelectionPulse(kind ) {
|
|
2750
|
+
if (!this.overlayEl) return;
|
|
2751
|
+
if (kind === "pinned") {
|
|
2752
|
+
this.overlayEl.style.borderColor = "#15803d";
|
|
2753
|
+
this.overlayEl.style.background = "rgba(21, 128, 61, 0.14)";
|
|
2754
|
+
} else {
|
|
2755
|
+
this.overlayEl.style.borderColor = "#c2410c";
|
|
2756
|
+
this.overlayEl.style.background = "rgba(194, 65, 12, 0.12)";
|
|
2757
|
+
}
|
|
2758
|
+
if (this.pulseTimer !== null) {
|
|
2759
|
+
clearTimeout(this.pulseTimer);
|
|
2760
|
+
}
|
|
2761
|
+
this.pulseTimer = setTimeout(() => {
|
|
2762
|
+
if (this.overlayEl) {
|
|
2763
|
+
this.overlayEl.style.borderColor = "#1d4ed8";
|
|
2764
|
+
this.overlayEl.style.background = "rgba(29, 78, 216, 0.10)";
|
|
2765
|
+
}
|
|
2766
|
+
this.pulseTimer = null;
|
|
2767
|
+
}, 280);
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2770
|
+
showCursorToast(selector , kind , x , y ) {
|
|
2771
|
+
if (!this.toastEl || typeof window === "undefined") return;
|
|
2772
|
+
this.toastEl.innerHTML = "";
|
|
2331
2773
|
|
|
2332
|
-
const
|
|
2333
|
-
|
|
2334
|
-
pinNowBtn.setAttribute("data-context-drop-ui", "confirm-pin-btn");
|
|
2335
|
-
pinNowBtn.style.cssText = [
|
|
2774
|
+
const iconBadge = document.createElement("span");
|
|
2775
|
+
iconBadge.style.cssText = [
|
|
2336
2776
|
"display: inline-flex",
|
|
2337
2777
|
"align-items: center",
|
|
2338
|
-
"
|
|
2339
|
-
"
|
|
2340
|
-
"
|
|
2341
|
-
"border:
|
|
2342
|
-
"background: #
|
|
2778
|
+
"justify-content: center",
|
|
2779
|
+
"width: 16px",
|
|
2780
|
+
"height: 16px",
|
|
2781
|
+
"border-radius: 9999px",
|
|
2782
|
+
"background: " + (kind === "pinned" ? "#15803d" : "#4b5262"),
|
|
2343
2783
|
"color: #faf9f6",
|
|
2344
|
-
"
|
|
2345
|
-
"font-weight: 600",
|
|
2346
|
-
"cursor: pointer"
|
|
2784
|
+
"flex-shrink: 0"
|
|
2347
2785
|
].join(";");
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
this.
|
|
2786
|
+
iconBadge.innerHTML = ICON_CHECK;
|
|
2787
|
+
this.toastEl.appendChild(iconBadge);
|
|
2788
|
+
|
|
2789
|
+
const primaryText = document.createElement("span");
|
|
2790
|
+
primaryText.textContent = kind === "pinned" ? "Pinned " : "Removed ";
|
|
2791
|
+
this.toastEl.appendChild(primaryText);
|
|
2792
|
+
|
|
2793
|
+
const monoSel = document.createElement("span");
|
|
2794
|
+
monoSel.textContent = selector;
|
|
2795
|
+
monoSel.style.cssText =
|
|
2796
|
+
"font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 600; color: #faf9f6; max-width: 160px; overflow: hidden; text-overflow: ellipsis;";
|
|
2797
|
+
this.toastEl.appendChild(monoSel);
|
|
2798
|
+
|
|
2799
|
+
if (kind === "pinned") {
|
|
2800
|
+
const nextHint = document.createElement("span");
|
|
2801
|
+
nextHint.style.cssText =
|
|
2802
|
+
"display: inline-flex; align-items: center; gap: 4px; color: #cbd5e1; font-size: 10.5px; margin-left: 2px;";
|
|
2803
|
+
nextHint.appendChild(this.createSpanEl("· Click more or"));
|
|
2804
|
+
nextHint.appendChild(this.createKbdEl("Esc"));
|
|
2805
|
+
this.toastEl.appendChild(nextHint);
|
|
2806
|
+
}
|
|
2360
2807
|
|
|
2361
|
-
|
|
2808
|
+
this.toastEl.style.display = "inline-flex";
|
|
2362
2809
|
const vw = window.innerWidth || 1024;
|
|
2363
2810
|
const vh = window.innerHeight || 768;
|
|
2364
|
-
const
|
|
2365
|
-
const
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
this.anchorY + popHeight + 20 > vh
|
|
2369
|
-
? Math.max(12, this.anchorY - popHeight - 12)
|
|
2370
|
-
: Math.max(12, this.anchorY + 14);
|
|
2811
|
+
const left = Math.max(10, Math.min(x + 14, vw - 310));
|
|
2812
|
+
const top = Math.max(10, Math.min(y + 16, vh - 44));
|
|
2813
|
+
this.toastEl.style.left = `${Math.round(left)}px`;
|
|
2814
|
+
this.toastEl.style.top = `${Math.round(top)}px`;
|
|
2371
2815
|
|
|
2372
|
-
this.
|
|
2373
|
-
|
|
2816
|
+
if (this.toastTimer !== null) {
|
|
2817
|
+
clearTimeout(this.toastTimer);
|
|
2818
|
+
}
|
|
2819
|
+
this.toastTimer = setTimeout(() => {
|
|
2820
|
+
if (this.toastEl) {
|
|
2821
|
+
this.toastEl.style.display = "none";
|
|
2822
|
+
}
|
|
2823
|
+
this.toastTimer = null;
|
|
2824
|
+
}, 1450);
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
commitCandidateSelection(el , x , y ) {
|
|
2828
|
+
const existingPinned = this.findPinnedIndex(el);
|
|
2829
|
+
if (existingPinned && this.callbacks.onUnselect) {
|
|
2830
|
+
this.callbacks.onUnselect(existingPinned.entry.clientRef, el);
|
|
2831
|
+
this.lastAction = { kind: "unpinned", selector: existingPinned.entry.selector };
|
|
2832
|
+
this.isScrubbingLayers = false;
|
|
2833
|
+
this.refreshPinnedMarkers();
|
|
2834
|
+
this.flashSelectionPulse("unpinned");
|
|
2835
|
+
this.showCursorToast(existingPinned.entry.selector, "unpinned", x, y);
|
|
2836
|
+
this.updateOverlayPosition();
|
|
2837
|
+
this.notifyStateChange();
|
|
2838
|
+
return;
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
const excluded = this.callbacks.getExcludedSelectors();
|
|
2842
|
+
const snapshot = captureElementSnapshot(el, excluded);
|
|
2843
|
+
if (!snapshot) return;
|
|
2844
|
+
|
|
2845
|
+
this.callbacks.onSelect(snapshot, el);
|
|
2846
|
+
this.lastAction = { kind: "pinned", selector: snapshot.selector };
|
|
2847
|
+
this.isScrubbingLayers = false;
|
|
2848
|
+
this.refreshPinnedMarkers();
|
|
2849
|
+
|
|
2850
|
+
if (!this.callbacks.canSelectMore()) {
|
|
2851
|
+
this.stop();
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
this.flashSelectionPulse("pinned");
|
|
2856
|
+
this.showCursorToast(snapshot.selector, "pinned", x, y);
|
|
2857
|
+
this.updateOverlayPosition();
|
|
2858
|
+
this.notifyStateChange();
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
handleWheelCapture(event ) {
|
|
2862
|
+
if (!this.active) return;
|
|
2863
|
+
if (this.isInternalUiEvent(event)) return;
|
|
2864
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
2865
|
+
|
|
2866
|
+
if (this.candidateStack.length <= 1) {
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
event.preventDefault();
|
|
2871
|
+
event.stopPropagation();
|
|
2872
|
+
|
|
2873
|
+
const normalizedDelta = event.deltaMode === 1 ? event.deltaY * 32 : event.deltaY;
|
|
2874
|
+
if (normalizedDelta === 0) return;
|
|
2875
|
+
|
|
2876
|
+
// Reset accumulator immediately when the user reverses scroll direction
|
|
2877
|
+
if (this.wheelAccumulator * normalizedDelta < 0) {
|
|
2878
|
+
this.wheelAccumulator = 0;
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
this.wheelAccumulator += normalizedDelta;
|
|
2882
|
+
if (Math.abs(this.wheelAccumulator) < WHEEL_STEP_THRESHOLD) {
|
|
2883
|
+
return;
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
const now = Date.now();
|
|
2887
|
+
if (now - this.lastWheelStepAt < WHEEL_STEP_COOLDOWN_MS) {
|
|
2888
|
+
this.wheelAccumulator = 0;
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
const step = this.wheelAccumulator > 0 ? 1 : -1;
|
|
2893
|
+
this.wheelAccumulator = 0;
|
|
2894
|
+
this.lastWheelStepAt = now;
|
|
2895
|
+
this.cycleDepth(step, true);
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
handlePointerSuppression(event ) {
|
|
2899
|
+
if (!this.active) return;
|
|
2900
|
+
if (this.isInternalUiEvent(event)) {
|
|
2901
|
+
return;
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
// Intercept host page pointer events in capture phase so links/buttons do not fire
|
|
2905
|
+
event.preventDefault();
|
|
2906
|
+
event.stopPropagation();
|
|
2907
|
+
if (typeof event.stopImmediatePropagation === "function") {
|
|
2908
|
+
event.stopImmediatePropagation();
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
handleClickCapture(event ) {
|
|
2913
|
+
if (!this.active) return;
|
|
2914
|
+
if (this.isInternalUiEvent(event)) {
|
|
2915
|
+
return;
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
event.preventDefault();
|
|
2919
|
+
event.stopPropagation();
|
|
2920
|
+
if (typeof event.stopImmediatePropagation === "function") {
|
|
2921
|
+
event.stopImmediatePropagation();
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
this.lastPointerX = event.clientX;
|
|
2925
|
+
this.lastPointerY = event.clientY;
|
|
2926
|
+
this.updateCandidatesFromPoint(event.clientX, event.clientY, event);
|
|
2927
|
+
|
|
2928
|
+
const activeCandidate = this.getActiveCandidate();
|
|
2929
|
+
if (!activeCandidate) return;
|
|
2930
|
+
|
|
2931
|
+
this.commitCandidateSelection(activeCandidate.element, event.clientX, event.clientY);
|
|
2374
2932
|
}
|
|
2375
2933
|
|
|
2376
2934
|
handleKeyDown(event ) {
|
|
@@ -2379,25 +2937,21 @@
|
|
|
2379
2937
|
if (event.key === "Escape") {
|
|
2380
2938
|
event.preventDefault();
|
|
2381
2939
|
event.stopPropagation();
|
|
2382
|
-
|
|
2383
|
-
this.closeLayerPopover();
|
|
2384
|
-
} else {
|
|
2385
|
-
this.stop();
|
|
2386
|
-
}
|
|
2940
|
+
this.stop();
|
|
2387
2941
|
return;
|
|
2388
2942
|
}
|
|
2389
2943
|
|
|
2390
2944
|
if (event.key === "ArrowUp" || event.key === "[") {
|
|
2391
2945
|
event.preventDefault();
|
|
2392
2946
|
event.stopPropagation();
|
|
2393
|
-
this.cycleDepth(1);
|
|
2947
|
+
this.cycleDepth(1, true);
|
|
2394
2948
|
return;
|
|
2395
2949
|
}
|
|
2396
2950
|
|
|
2397
2951
|
if (event.key === "ArrowDown" || event.key === "]") {
|
|
2398
2952
|
event.preventDefault();
|
|
2399
2953
|
event.stopPropagation();
|
|
2400
|
-
this.cycleDepth(-1);
|
|
2954
|
+
this.cycleDepth(-1, true);
|
|
2401
2955
|
return;
|
|
2402
2956
|
}
|
|
2403
2957
|
|
|
@@ -2406,7 +2960,11 @@
|
|
|
2406
2960
|
if (candidate) {
|
|
2407
2961
|
event.preventDefault();
|
|
2408
2962
|
event.stopPropagation();
|
|
2409
|
-
this.
|
|
2963
|
+
this.commitCandidateSelection(
|
|
2964
|
+
candidate.element,
|
|
2965
|
+
this.lastPointerX || 80,
|
|
2966
|
+
this.lastPointerY || 80
|
|
2967
|
+
);
|
|
2410
2968
|
}
|
|
2411
2969
|
}
|
|
2412
2970
|
}
|
|
@@ -2458,7 +3016,11 @@
|
|
|
2458
3016
|
rootContainer = null;
|
|
2459
3017
|
composerEl = null;
|
|
2460
3018
|
compactBarEl = null;
|
|
2461
|
-
|
|
3019
|
+
compactStatusEl = null;
|
|
3020
|
+
compactStepGroupEl = null;
|
|
3021
|
+
compactLayerUpBtn = null;
|
|
3022
|
+
compactLayerDownBtn = null;
|
|
3023
|
+
compactDoneBtn = null;
|
|
2462
3024
|
compactPinBtn = null;
|
|
2463
3025
|
pinDockEl = null;
|
|
2464
3026
|
floatingPinBtn = null;
|
|
@@ -2482,10 +3044,19 @@
|
|
|
2482
3044
|
onSelect: (snapshot, el) => {
|
|
2483
3045
|
const added = this.addElementReference(snapshot, el);
|
|
2484
3046
|
if (added) {
|
|
2485
|
-
this.
|
|
3047
|
+
const count = this.elementReferences.length;
|
|
3048
|
+
this.showStatus(
|
|
3049
|
+
count === 1
|
|
3050
|
+
? `Pinned ${snapshot.selector}`
|
|
3051
|
+
: `Pinned ${count} elements (latest: ${snapshot.selector})`,
|
|
3052
|
+
"success"
|
|
3053
|
+
);
|
|
2486
3054
|
}
|
|
2487
3055
|
this.syncUiStates();
|
|
2488
3056
|
},
|
|
3057
|
+
onUnselect: (clientRef) => {
|
|
3058
|
+
this.removeElementReference(clientRef);
|
|
3059
|
+
},
|
|
2489
3060
|
onExit: () => {
|
|
2490
3061
|
this.isMinimized = false;
|
|
2491
3062
|
this.openComposer();
|
|
@@ -2493,9 +3064,21 @@
|
|
|
2493
3064
|
},
|
|
2494
3065
|
canSelectMore: () => this.elementReferences.length < this.config.limits.max_element_references,
|
|
2495
3066
|
getExcludedSelectors: () => this.config.privacy.excluded_selectors,
|
|
3067
|
+
getPinnedElements: () =>
|
|
3068
|
+
this.elementReferences
|
|
3069
|
+
.map((ref) => {
|
|
3070
|
+
const node = this.elementDomNodes.get(ref.client_ref);
|
|
3071
|
+
return node
|
|
3072
|
+
? { clientRef: ref.client_ref, selector: ref.selector, element: node }
|
|
3073
|
+
: null;
|
|
3074
|
+
})
|
|
3075
|
+
.filter(
|
|
3076
|
+
(item) =>
|
|
3077
|
+
item !== null
|
|
3078
|
+
),
|
|
2496
3079
|
onStateChange: (state) => {
|
|
2497
|
-
this.renderCompactBreadcrumbs(state.activeCandidate, state.ancestors);
|
|
2498
3080
|
this.syncPinActiveIndicators(state.active);
|
|
3081
|
+
this.renderCompactCoachBar(state.active, state.candidateStack.length);
|
|
2499
3082
|
}
|
|
2500
3083
|
});
|
|
2501
3084
|
}
|
|
@@ -2612,6 +3195,7 @@
|
|
|
2612
3195
|
if (elementNode) {
|
|
2613
3196
|
this.elementDomNodes.set(snapshot.client_ref, elementNode);
|
|
2614
3197
|
}
|
|
3198
|
+
this.picker?.refreshPinnedMarkers();
|
|
2615
3199
|
this.renderTray();
|
|
2616
3200
|
this.syncUiStates();
|
|
2617
3201
|
return true;
|
|
@@ -2621,6 +3205,7 @@
|
|
|
2621
3205
|
this.elementReferences = this.elementReferences.filter((el) => el.client_ref !== clientRef);
|
|
2622
3206
|
this.elementDomNodes.delete(clientRef);
|
|
2623
3207
|
this.picker?.hideExternalPreview();
|
|
3208
|
+
this.picker?.refreshPinnedMarkers();
|
|
2624
3209
|
this.renderTray();
|
|
2625
3210
|
this.syncUiStates();
|
|
2626
3211
|
}
|
|
@@ -2646,6 +3231,9 @@
|
|
|
2646
3231
|
limits: { ...this.config.limits, ...(parsed.limits || {}) },
|
|
2647
3232
|
privacy: { ...this.config.privacy, ...(parsed.privacy || {}) }
|
|
2648
3233
|
};
|
|
3234
|
+
if (parsed.csrf_token) {
|
|
3235
|
+
this.apiClient.setCsrfToken(parsed.csrf_token);
|
|
3236
|
+
}
|
|
2649
3237
|
} catch {
|
|
2650
3238
|
// Ignore malformed JSON attribute
|
|
2651
3239
|
}
|
|
@@ -2812,20 +3400,12 @@
|
|
|
2812
3400
|
|
|
2813
3401
|
const compactStatus = document.createElement("div");
|
|
2814
3402
|
compactStatus.className = "cd-compact-status";
|
|
2815
|
-
|
|
2816
|
-
breadcrumbScroll.className = "cd-breadcrumb-scroll";
|
|
2817
|
-
this.compactBreadcrumbEl = breadcrumbScroll;
|
|
2818
|
-
compactStatus.appendChild(breadcrumbScroll);
|
|
3403
|
+
this.compactStatusEl = compactStatus;
|
|
2819
3404
|
compactBar.appendChild(compactStatus);
|
|
2820
3405
|
|
|
2821
|
-
const
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
compactLayerUp.title = "Step to outer/parent element (Up arrow)";
|
|
2825
|
-
compactLayerUp.setAttribute("aria-label", "Step to parent element");
|
|
2826
|
-
compactLayerUp.innerHTML = ICON_CHEVRON_UP;
|
|
2827
|
-
compactLayerUp.addEventListener("click", () => this.picker?.cycleDepth(1));
|
|
2828
|
-
compactBar.appendChild(compactLayerUp);
|
|
3406
|
+
const compactStepGroup = document.createElement("div");
|
|
3407
|
+
compactStepGroup.className = "cd-compact-step-group";
|
|
3408
|
+
this.compactStepGroupEl = compactStepGroup;
|
|
2829
3409
|
|
|
2830
3410
|
const compactLayerDown = document.createElement("button");
|
|
2831
3411
|
compactLayerDown.type = "button";
|
|
@@ -2833,15 +3413,29 @@
|
|
|
2833
3413
|
compactLayerDown.title = "Step to inner/child element (Down arrow)";
|
|
2834
3414
|
compactLayerDown.setAttribute("aria-label", "Step to child element");
|
|
2835
3415
|
compactLayerDown.innerHTML = ICON_CHEVRON_DOWN;
|
|
2836
|
-
compactLayerDown.addEventListener("click", () => this.picker?.cycleDepth(-1));
|
|
2837
|
-
|
|
3416
|
+
compactLayerDown.addEventListener("click", () => this.picker?.cycleDepth(-1, true));
|
|
3417
|
+
this.compactLayerDownBtn = compactLayerDown;
|
|
3418
|
+
compactStepGroup.appendChild(compactLayerDown);
|
|
3419
|
+
|
|
3420
|
+
const compactLayerUp = document.createElement("button");
|
|
3421
|
+
compactLayerUp.type = "button";
|
|
3422
|
+
compactLayerUp.className = "cd-icon-btn";
|
|
3423
|
+
compactLayerUp.title = "Step to outer/parent element (Up arrow)";
|
|
3424
|
+
compactLayerUp.setAttribute("aria-label", "Step to parent element");
|
|
3425
|
+
compactLayerUp.innerHTML = ICON_CHEVRON_UP;
|
|
3426
|
+
compactLayerUp.addEventListener("click", () => this.picker?.cycleDepth(1, true));
|
|
3427
|
+
this.compactLayerUpBtn = compactLayerUp;
|
|
3428
|
+
compactStepGroup.appendChild(compactLayerUp);
|
|
3429
|
+
|
|
3430
|
+
compactBar.appendChild(compactStepGroup);
|
|
2838
3431
|
|
|
2839
3432
|
const expandBtn = document.createElement("button");
|
|
2840
3433
|
expandBtn.type = "button";
|
|
2841
|
-
expandBtn.className = "cd-btn
|
|
2842
|
-
expandBtn.setAttribute("aria-label", "
|
|
2843
|
-
expandBtn.innerHTML =
|
|
3434
|
+
expandBtn.className = "cd-btn";
|
|
3435
|
+
expandBtn.setAttribute("aria-label", "Cancel pinning and return to chatbox");
|
|
3436
|
+
expandBtn.innerHTML = `<span>Cancel</span><kbd class="cd-kbd">Esc</kbd>`;
|
|
2844
3437
|
expandBtn.addEventListener("click", () => this.expandFromCompactBar());
|
|
3438
|
+
this.compactDoneBtn = expandBtn;
|
|
2845
3439
|
compactBar.appendChild(expandBtn);
|
|
2846
3440
|
|
|
2847
3441
|
// 2. Main Floating Chatbox Composer Window
|
|
@@ -3069,7 +3663,6 @@
|
|
|
3069
3663
|
root.appendChild(pinDock);
|
|
3070
3664
|
this.shadow.appendChild(root);
|
|
3071
3665
|
|
|
3072
|
-
this.renderCompactBreadcrumbs(null, []);
|
|
3073
3666
|
this.syncUiStates();
|
|
3074
3667
|
}
|
|
3075
3668
|
|
|
@@ -3120,48 +3713,102 @@
|
|
|
3120
3713
|
}
|
|
3121
3714
|
|
|
3122
3715
|
this.syncPinActiveIndicators(pickerActive);
|
|
3716
|
+
this.renderCompactCoachBar(
|
|
3717
|
+
pickerActive,
|
|
3718
|
+
this.picker ? this.picker.getCandidateStack().length : 0
|
|
3719
|
+
);
|
|
3123
3720
|
}
|
|
3124
3721
|
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
) {
|
|
3129
|
-
if (!this.compactBreadcrumbEl) return;
|
|
3130
|
-
this.compactBreadcrumbEl.innerHTML = "";
|
|
3722
|
+
renderCompactCoachBar(pickerActive , candidateCount = 0) {
|
|
3723
|
+
if (!this.compactStatusEl) return;
|
|
3724
|
+
this.compactStatusEl.innerHTML = "";
|
|
3131
3725
|
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
this.
|
|
3140
|
-
|
|
3726
|
+
const pinnedCount = this.elementReferences.length;
|
|
3727
|
+
const totalContextCount = pinnedCount + this.attachments.length;
|
|
3728
|
+
|
|
3729
|
+
if (this.compactStepGroupEl) {
|
|
3730
|
+
this.compactStepGroupEl.hidden = !pickerActive;
|
|
3731
|
+
}
|
|
3732
|
+
if (this.compactLayerUpBtn) {
|
|
3733
|
+
this.compactLayerUpBtn.disabled = candidateCount <= 1;
|
|
3734
|
+
}
|
|
3735
|
+
if (this.compactLayerDownBtn) {
|
|
3736
|
+
this.compactLayerDownBtn.disabled = candidateCount <= 1;
|
|
3141
3737
|
}
|
|
3142
3738
|
|
|
3143
|
-
|
|
3144
|
-
if (
|
|
3145
|
-
const
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
this.
|
|
3739
|
+
if (pickerActive) {
|
|
3740
|
+
if (pinnedCount === 0) {
|
|
3741
|
+
const coach = document.createElement("span");
|
|
3742
|
+
coach.className = "cd-compact-coach-text";
|
|
3743
|
+
coach.innerHTML = `<strong>Click</strong><span>element to pin</span><span>·</span><span class="cd-compact-wheel-icon">${ICON_SCROLL_VERTICAL}</span><strong>Scroll</strong><span>layers</span>`;
|
|
3744
|
+
this.compactStatusEl.appendChild(coach);
|
|
3745
|
+
} else {
|
|
3746
|
+
const latest = this.elementReferences[pinnedCount - 1];
|
|
3747
|
+
const pill = document.createElement("div");
|
|
3748
|
+
pill.className = "cd-compact-pinned-pill";
|
|
3749
|
+
|
|
3750
|
+
const countSpan = document.createElement("span");
|
|
3751
|
+
countSpan.className = "cd-compact-pinned-count";
|
|
3752
|
+
countSpan.textContent = `${pinnedCount} pinned`;
|
|
3753
|
+
|
|
3754
|
+
const selSpan = document.createElement("span");
|
|
3755
|
+
selSpan.className = "cd-compact-pinned-selector";
|
|
3756
|
+
selSpan.textContent = latest.selector;
|
|
3757
|
+
selSpan.title = latest.dom_path || latest.selector;
|
|
3758
|
+
|
|
3759
|
+
const undoBtn = document.createElement("button");
|
|
3760
|
+
undoBtn.type = "button";
|
|
3761
|
+
undoBtn.className = "cd-chip-remove";
|
|
3762
|
+
undoBtn.title = `Remove ${latest.selector}`;
|
|
3763
|
+
undoBtn.setAttribute("aria-label", `Undo pin ${latest.selector}`);
|
|
3764
|
+
undoBtn.innerHTML = ICON_CLOSE;
|
|
3765
|
+
undoBtn.addEventListener("click", (ev) => {
|
|
3766
|
+
ev.stopPropagation();
|
|
3767
|
+
this.removeElementReference(latest.client_ref);
|
|
3768
|
+
});
|
|
3769
|
+
|
|
3770
|
+
pill.appendChild(countSpan);
|
|
3771
|
+
pill.appendChild(selSpan);
|
|
3772
|
+
pill.appendChild(undoBtn);
|
|
3773
|
+
this.compactStatusEl.appendChild(pill);
|
|
3774
|
+
|
|
3775
|
+
const addMore = document.createElement("span");
|
|
3776
|
+
addMore.className = "cd-compact-coach-text";
|
|
3777
|
+
addMore.textContent = "Click another to add";
|
|
3778
|
+
this.compactStatusEl.appendChild(addMore);
|
|
3149
3779
|
}
|
|
3150
3780
|
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3781
|
+
if (this.compactDoneBtn) {
|
|
3782
|
+
if (pinnedCount > 0) {
|
|
3783
|
+
this.compactDoneBtn.className = "cd-btn cd-btn-primary";
|
|
3784
|
+
this.compactDoneBtn.setAttribute(
|
|
3785
|
+
"aria-label",
|
|
3786
|
+
"Finish pinning elements and return to chatbox"
|
|
3787
|
+
);
|
|
3788
|
+
this.compactDoneBtn.innerHTML = `${ICON_CHECK}<span>Done (${pinnedCount})</span><kbd class="cd-kbd">Esc</kbd>`;
|
|
3789
|
+
} else {
|
|
3790
|
+
this.compactDoneBtn.className = "cd-btn";
|
|
3791
|
+
this.compactDoneBtn.setAttribute("aria-label", "Cancel pinning and return to chatbox");
|
|
3792
|
+
this.compactDoneBtn.innerHTML = `<span>Cancel</span><kbd class="cd-kbd">Esc</kbd>`;
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
return;
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
// Minimized while not actively in Pin Mode
|
|
3799
|
+
const summary = document.createElement("span");
|
|
3800
|
+
summary.className = "cd-compact-coach-text";
|
|
3801
|
+
summary.textContent =
|
|
3802
|
+
totalContextCount > 0
|
|
3803
|
+
? `${totalContextCount} context item${totalContextCount > 1 ? "s" : ""} attached`
|
|
3804
|
+
: "Chatbox minimized";
|
|
3805
|
+
this.compactStatusEl.appendChild(summary);
|
|
3806
|
+
|
|
3807
|
+
if (this.compactDoneBtn) {
|
|
3808
|
+
this.compactDoneBtn.className = "cd-btn cd-btn-primary";
|
|
3809
|
+
this.compactDoneBtn.setAttribute("aria-label", "Return to chatbox");
|
|
3810
|
+
this.compactDoneBtn.innerHTML = `${ICON_EXPAND}<span>Chat</span>`;
|
|
3811
|
+
}
|
|
3165
3812
|
}
|
|
3166
3813
|
|
|
3167
3814
|
renderChatThread() {
|
|
@@ -3179,7 +3826,7 @@
|
|
|
3179
3826
|
const p2 = document.createElement("p");
|
|
3180
3827
|
p2.className = "cd-chat-empty-hint";
|
|
3181
3828
|
p2.textContent =
|
|
3182
|
-
"
|
|
3829
|
+
"Click Pin Element, scroll the wheel to step through overlapping layers, click once to pin, and press Esc when done.";
|
|
3183
3830
|
|
|
3184
3831
|
emptyBox.appendChild(p1);
|
|
3185
3832
|
emptyBox.appendChild(p2);
|