@githumbi/grabby 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/angular/index.d.ts +22 -1
- package/dist/angular/index.js +608 -63
- package/dist/angular/index.js.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/core/index.cjs +723 -178
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +608 -63
- package/dist/core/index.js.map +1 -1
- package/dist/export/index.cjs +19 -1
- package/dist/export/index.cjs.map +1 -1
- package/dist/export/index.d.cts +23 -2
- package/dist/export/index.d.ts +23 -2
- package/dist/export/index.js +19 -1
- package/dist/export/index.js.map +1 -1
- package/dist/grabby.global.js +177 -137
- package/dist/live/index.d.cts +1 -1
- package/dist/live/index.d.ts +1 -1
- package/dist/react/index.d.ts +22 -1
- package/dist/react/index.js +608 -63
- package/dist/react/index.js.map +1 -1
- package/dist/{types-BQDEG-Gl.d.cts → types-DOAcZ0U6.d.cts} +23 -2
- package/dist/{types-BQDEG-Gl.d.ts → types-DOAcZ0U6.d.ts} +23 -2
- package/package.json +1 -1
package/dist/core/index.js
CHANGED
|
@@ -507,6 +507,20 @@ function describeTarget(target) {
|
|
|
507
507
|
const name = facts.label || facts.heading || facts.text || facts.alt || "";
|
|
508
508
|
return quoted(noun, name);
|
|
509
509
|
}
|
|
510
|
+
var GROUP_NAMED = 3;
|
|
511
|
+
function describeGroup(labels) {
|
|
512
|
+
const named = labels.slice(0, GROUP_NAMED).join(", ");
|
|
513
|
+
const more = labels.length > GROUP_NAMED ? ` and ${labels.length - GROUP_NAMED} more` : "";
|
|
514
|
+
return `${labels.length} elements: ${named}${more}`;
|
|
515
|
+
}
|
|
516
|
+
function describeArea(around) {
|
|
517
|
+
return `Area in ${around}`;
|
|
518
|
+
}
|
|
519
|
+
function describeComment(c) {
|
|
520
|
+
if (c.members?.length) return describeGroup(c.members.map((m) => m.label));
|
|
521
|
+
if (c.area) return describeArea(describeTarget(c.target));
|
|
522
|
+
return describeTarget(c.target);
|
|
523
|
+
}
|
|
510
524
|
|
|
511
525
|
// src/core/overlay/overlay-renderer.ts
|
|
512
526
|
var OVERLAY_ID = "__grabby-overlay__";
|
|
@@ -1157,11 +1171,114 @@ function buildUniqueSelector(el) {
|
|
|
1157
1171
|
return steps.join(" > ");
|
|
1158
1172
|
}
|
|
1159
1173
|
|
|
1174
|
+
// src/core/picker/region.ts
|
|
1175
|
+
var MAX_MEMBERS = 20;
|
|
1176
|
+
var INSIDE_RATIO = 0.85;
|
|
1177
|
+
var MIN_SIDE = 4;
|
|
1178
|
+
var MAX_VISITS = 4e3;
|
|
1179
|
+
var SKIP_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "HEAD", "META", "LINK", "BR", "WBR"]);
|
|
1180
|
+
function boxFromPoints(a, b) {
|
|
1181
|
+
return { left: Math.min(a.x, b.x), top: Math.min(a.y, b.y), right: Math.max(a.x, b.x), bottom: Math.max(a.y, b.y) };
|
|
1182
|
+
}
|
|
1183
|
+
function overlapArea(r, box) {
|
|
1184
|
+
const w = Math.min(r.right, box.right) - Math.max(r.left, box.left);
|
|
1185
|
+
const h2 = Math.min(r.bottom, box.bottom) - Math.max(r.top, box.top);
|
|
1186
|
+
return w > 0 && h2 > 0 ? w * h2 : 0;
|
|
1187
|
+
}
|
|
1188
|
+
function contains(r, box) {
|
|
1189
|
+
return r.left <= box.left && r.top <= box.top && r.right >= box.right && r.bottom >= box.bottom;
|
|
1190
|
+
}
|
|
1191
|
+
function isHidden(el) {
|
|
1192
|
+
const style = getComputedStyle(el);
|
|
1193
|
+
return style.visibility === "hidden" || style.opacity === "0";
|
|
1194
|
+
}
|
|
1195
|
+
function elementsInBox(box, isUiNode2, root2 = document.body) {
|
|
1196
|
+
const found = [];
|
|
1197
|
+
let visits = 0;
|
|
1198
|
+
const visit = (el) => {
|
|
1199
|
+
if (found.length >= MAX_MEMBERS || ++visits > MAX_VISITS) return;
|
|
1200
|
+
if (SKIP_TAGS.has(el.tagName) || isUiNode2(el) || el.hasAttribute(IGNORE_ATTR)) return;
|
|
1201
|
+
const r = el.getBoundingClientRect();
|
|
1202
|
+
const boxless = r.width === 0 && r.height === 0;
|
|
1203
|
+
if (!boxless && overlapArea(r, box) === 0) return;
|
|
1204
|
+
if (!boxless && r.width >= MIN_SIDE && r.height >= MIN_SIDE) {
|
|
1205
|
+
const inside = overlapArea(r, box) / (r.width * r.height);
|
|
1206
|
+
if (inside >= INSIDE_RATIO && detectKind(el) !== "section" && !isHidden(el)) {
|
|
1207
|
+
found.push(el);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
for (const child of Array.from(el.children)) visit(child);
|
|
1212
|
+
};
|
|
1213
|
+
for (const child of Array.from(root2.children)) visit(child);
|
|
1214
|
+
return found;
|
|
1215
|
+
}
|
|
1216
|
+
function commonContainer(elements) {
|
|
1217
|
+
if (elements.length === 0) return document.body;
|
|
1218
|
+
let candidate = elements[0].parentElement ?? document.body;
|
|
1219
|
+
while (candidate && !elements.every((el) => candidate.contains(el))) candidate = candidate.parentElement;
|
|
1220
|
+
return candidate ?? document.body;
|
|
1221
|
+
}
|
|
1222
|
+
function containerForBox(box, isUiNode2) {
|
|
1223
|
+
const cx = (box.left + box.right) / 2;
|
|
1224
|
+
const cy = (box.top + box.bottom) / 2;
|
|
1225
|
+
const stack = typeof document.elementsFromPoint === "function" ? document.elementsFromPoint(cx, cy) : [];
|
|
1226
|
+
for (const el of stack) {
|
|
1227
|
+
if (isUiNode2(el) || el.closest(`[${IGNORE_ATTR}]`)) continue;
|
|
1228
|
+
for (let cur = el; cur; cur = cur.parentElement) {
|
|
1229
|
+
if (contains(cur.getBoundingClientRect(), box)) return cur;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
return document.body;
|
|
1233
|
+
}
|
|
1234
|
+
var frac = (v) => Math.round(Math.min(1, Math.max(0, v)) * 1e3) / 1e3;
|
|
1235
|
+
function areaWithin(el, box) {
|
|
1236
|
+
const r = el.getBoundingClientRect();
|
|
1237
|
+
const w = r.width || 1;
|
|
1238
|
+
const h2 = r.height || 1;
|
|
1239
|
+
return {
|
|
1240
|
+
x: frac((box.left - r.left) / w),
|
|
1241
|
+
y: frac((box.top - r.top) / h2),
|
|
1242
|
+
w: frac((box.right - box.left) / w),
|
|
1243
|
+
h: frac((box.bottom - box.top) / h2)
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
function areaToBox(el, area) {
|
|
1247
|
+
const r = el.getBoundingClientRect();
|
|
1248
|
+
return {
|
|
1249
|
+
left: r.left + area.x * r.width,
|
|
1250
|
+
top: r.top + area.y * r.height,
|
|
1251
|
+
right: r.left + (area.x + area.w) * r.width,
|
|
1252
|
+
bottom: r.top + (area.y + area.h) * r.height
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
function unionBox(elements) {
|
|
1256
|
+
let out = null;
|
|
1257
|
+
for (const el of elements) {
|
|
1258
|
+
const r = el.getBoundingClientRect();
|
|
1259
|
+
if (r.width === 0 && r.height === 0) continue;
|
|
1260
|
+
out = out ? { left: Math.min(out.left, r.left), top: Math.min(out.top, r.top), right: Math.max(out.right, r.right), bottom: Math.max(out.bottom, r.bottom) } : { left: r.left, top: r.top, right: r.right, bottom: r.bottom };
|
|
1261
|
+
}
|
|
1262
|
+
return out;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1160
1265
|
// src/core/picker/element-picker.ts
|
|
1266
|
+
var DRAG_PX = 6;
|
|
1267
|
+
var IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
1268
|
+
var PRESS_EVENTS = ["pointerdown", "mousedown", "pointerup", "mouseup", "touchstart"];
|
|
1269
|
+
function addKey(e) {
|
|
1270
|
+
return IS_MAC ? e.metaKey : e.ctrlKey;
|
|
1271
|
+
}
|
|
1161
1272
|
function createElementPicker(deps) {
|
|
1162
1273
|
let hoveredElement = null;
|
|
1163
1274
|
let heldElement = null;
|
|
1164
1275
|
let listening = false;
|
|
1276
|
+
let press = null;
|
|
1277
|
+
let dragBox = null;
|
|
1278
|
+
let dragFrame = null;
|
|
1279
|
+
let lastPoint = { x: 0, y: 0 };
|
|
1280
|
+
let swallowNextClick = false;
|
|
1281
|
+
let collected = [];
|
|
1165
1282
|
function resolveComponentName(el) {
|
|
1166
1283
|
const resolver = deps.getComponentResolver();
|
|
1167
1284
|
if (!resolver) return null;
|
|
@@ -1191,14 +1308,93 @@ function createElementPicker(deps) {
|
|
|
1191
1308
|
if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
|
|
1192
1309
|
return exact ? raw : promoteTarget(raw);
|
|
1193
1310
|
}
|
|
1311
|
+
function isOurs(el) {
|
|
1312
|
+
return !!deps.isToolbarElement?.(el) || deps.overlay.isOverlayElement(el) || deps.crosshair.isCrosshairElement(el);
|
|
1313
|
+
}
|
|
1194
1314
|
function showOverlay(target) {
|
|
1195
1315
|
const componentName = resolveComponentName(target);
|
|
1196
1316
|
const sourcePath = resolveSourcePath(target);
|
|
1197
1317
|
const cssClasses = filterAngularClasses(target.classList);
|
|
1198
1318
|
deps.overlay.show(target, componentName, sourcePath, cssClasses);
|
|
1199
1319
|
}
|
|
1320
|
+
const countLabel = (n) => `${n} element${n === 1 ? "" : "s"}`;
|
|
1321
|
+
function showCollected() {
|
|
1322
|
+
if (collected.length) {
|
|
1323
|
+
deps.groupOutline.show({ elements: collected }, `${countLabel(collected.length)} \xB7 release ${IS_MAC ? "\u2318" : "Ctrl"} to comment`);
|
|
1324
|
+
} else {
|
|
1325
|
+
deps.groupOutline.hide();
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
function clearCollected() {
|
|
1329
|
+
if (!collected.length) return;
|
|
1330
|
+
collected = [];
|
|
1331
|
+
deps.groupOutline.hide();
|
|
1332
|
+
}
|
|
1333
|
+
function previewDrag() {
|
|
1334
|
+
dragFrame = null;
|
|
1335
|
+
if (!dragBox) return;
|
|
1336
|
+
deps.groupOutline.marquee(dragBox);
|
|
1337
|
+
const found = elementsInBox(dragBox, isOurs);
|
|
1338
|
+
if (found.length) deps.groupOutline.show({ elements: found }, countLabel(found.length));
|
|
1339
|
+
else deps.groupOutline.hide();
|
|
1340
|
+
}
|
|
1341
|
+
function endDrag() {
|
|
1342
|
+
dragBox = null;
|
|
1343
|
+
if (dragFrame !== null) cancelAnimationFrame(dragFrame);
|
|
1344
|
+
dragFrame = null;
|
|
1345
|
+
deps.groupOutline.marquee(null);
|
|
1346
|
+
deps.groupOutline.hide();
|
|
1347
|
+
}
|
|
1348
|
+
function finishDrag(point) {
|
|
1349
|
+
const box = dragBox;
|
|
1350
|
+
endDrag();
|
|
1351
|
+
const found = elementsInBox(box, isOurs);
|
|
1352
|
+
if (found.length === 1) {
|
|
1353
|
+
hoveredElement = found[0];
|
|
1354
|
+
deps.onSelect(found[0], point);
|
|
1355
|
+
} else if (found.length > 1) {
|
|
1356
|
+
deps.onSelectGroup(found, point);
|
|
1357
|
+
} else {
|
|
1358
|
+
const container = containerForBox(box, isOurs);
|
|
1359
|
+
deps.onSelectArea(container, areaWithin(container, box), point);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
function handlePress(e) {
|
|
1363
|
+
const origin = eventTarget(e);
|
|
1364
|
+
if (origin && deps.isToolbarElement?.(origin)) return;
|
|
1365
|
+
e.stopPropagation();
|
|
1366
|
+
if (e.type === "mousedown" || e.type === "touchstart") e.preventDefault();
|
|
1367
|
+
if (heldElement) return;
|
|
1368
|
+
const m = e;
|
|
1369
|
+
const down = e.type === "pointerdown" || e.type === "mousedown";
|
|
1370
|
+
if (down && m.button === 0 && !press) {
|
|
1371
|
+
press = { x: m.clientX, y: m.clientY };
|
|
1372
|
+
swallowNextClick = false;
|
|
1373
|
+
} else if (!down && e.type !== "touchstart" && press) {
|
|
1374
|
+
const point = { x: m.clientX, y: m.clientY };
|
|
1375
|
+
const start = press;
|
|
1376
|
+
press = null;
|
|
1377
|
+
if (dragBox) {
|
|
1378
|
+
dragBox = boxFromPoints(start, point);
|
|
1379
|
+
swallowNextClick = true;
|
|
1380
|
+
finishDrag(point);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1200
1384
|
function handleMouseMove(e) {
|
|
1201
1385
|
if (heldElement) return;
|
|
1386
|
+
lastPoint = { x: e.clientX, y: e.clientY };
|
|
1387
|
+
if (press) {
|
|
1388
|
+
if (!dragBox && Math.hypot(e.clientX - press.x, e.clientY - press.y) < DRAG_PX) return;
|
|
1389
|
+
if (!dragBox) {
|
|
1390
|
+
clearCollected();
|
|
1391
|
+
deps.overlay.hide();
|
|
1392
|
+
hoveredElement = null;
|
|
1393
|
+
}
|
|
1394
|
+
dragBox = boxFromPoints(press, lastPoint);
|
|
1395
|
+
if (dragFrame === null) dragFrame = requestAnimationFrame(previewDrag);
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1202
1398
|
const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
|
|
1203
1399
|
if (!target || deps.overlay.isOverlayElement(target)) return;
|
|
1204
1400
|
if (deps.crosshair.isCrosshairElement(target)) return;
|
|
@@ -1216,8 +1412,32 @@ function createElementPicker(deps) {
|
|
|
1216
1412
|
e.preventDefault();
|
|
1217
1413
|
e.stopPropagation();
|
|
1218
1414
|
if (heldElement) return;
|
|
1219
|
-
if (
|
|
1220
|
-
|
|
1415
|
+
if (swallowNextClick) {
|
|
1416
|
+
swallowNextClick = false;
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
if (!hoveredElement) return;
|
|
1420
|
+
lastPoint = { x: e.clientX, y: e.clientY };
|
|
1421
|
+
if (addKey(e)) {
|
|
1422
|
+
const at = collected.indexOf(hoveredElement);
|
|
1423
|
+
if (at >= 0) collected.splice(at, 1);
|
|
1424
|
+
else if (collected.length < MAX_MEMBERS) collected.push(hoveredElement);
|
|
1425
|
+
showCollected();
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1428
|
+
clearCollected();
|
|
1429
|
+
deps.onSelect(hoveredElement, lastPoint);
|
|
1430
|
+
}
|
|
1431
|
+
function handleKeyUp(e) {
|
|
1432
|
+
if (e.key !== (IS_MAC ? "Meta" : "Control") || !collected.length || heldElement) return;
|
|
1433
|
+
const elements = collected;
|
|
1434
|
+
collected = [];
|
|
1435
|
+
deps.groupOutline.hide();
|
|
1436
|
+
if (elements.length === 1) {
|
|
1437
|
+
hoveredElement = elements[0];
|
|
1438
|
+
deps.onSelect(elements[0], lastPoint);
|
|
1439
|
+
} else {
|
|
1440
|
+
deps.onSelectGroup(elements, lastPoint);
|
|
1221
1441
|
}
|
|
1222
1442
|
}
|
|
1223
1443
|
return {
|
|
@@ -1225,31 +1445,46 @@ function createElementPicker(deps) {
|
|
|
1225
1445
|
if (listening) return;
|
|
1226
1446
|
listening = true;
|
|
1227
1447
|
deps.crosshair.activate();
|
|
1448
|
+
for (const type of PRESS_EVENTS) window.addEventListener(type, handlePress, { capture: true, passive: false });
|
|
1228
1449
|
document.addEventListener("mousemove", handleMouseMove, true);
|
|
1229
1450
|
document.addEventListener("click", handleClick, true);
|
|
1451
|
+
window.addEventListener("keyup", handleKeyUp, true);
|
|
1230
1452
|
},
|
|
1231
1453
|
deactivate() {
|
|
1232
1454
|
if (!listening) return;
|
|
1233
1455
|
listening = false;
|
|
1234
1456
|
hoveredElement = null;
|
|
1235
1457
|
heldElement = null;
|
|
1458
|
+
press = null;
|
|
1459
|
+
swallowNextClick = false;
|
|
1460
|
+
collected = [];
|
|
1461
|
+
endDrag();
|
|
1236
1462
|
deps.crosshair.hold(false);
|
|
1237
1463
|
deps.crosshair.deactivate();
|
|
1464
|
+
for (const type of PRESS_EVENTS) window.removeEventListener(type, handlePress, true);
|
|
1238
1465
|
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
1239
1466
|
document.removeEventListener("click", handleClick, true);
|
|
1467
|
+
window.removeEventListener("keyup", handleKeyUp, true);
|
|
1240
1468
|
deps.overlay.hide();
|
|
1241
1469
|
deps.onHover(null);
|
|
1242
1470
|
},
|
|
1243
|
-
hold(element) {
|
|
1471
|
+
hold(element, group) {
|
|
1244
1472
|
if (!listening) return;
|
|
1245
1473
|
heldElement = element;
|
|
1246
1474
|
hoveredElement = element;
|
|
1475
|
+
press = null;
|
|
1247
1476
|
deps.crosshair.hold(true);
|
|
1248
|
-
|
|
1477
|
+
if (group) {
|
|
1478
|
+
deps.overlay.hide();
|
|
1479
|
+
deps.groupOutline.show(group.spec, group.label);
|
|
1480
|
+
} else {
|
|
1481
|
+
showOverlay(element);
|
|
1482
|
+
}
|
|
1249
1483
|
},
|
|
1250
1484
|
release() {
|
|
1251
1485
|
if (!heldElement) return;
|
|
1252
1486
|
heldElement = null;
|
|
1487
|
+
deps.groupOutline.hide();
|
|
1253
1488
|
deps.crosshair.hold(false);
|
|
1254
1489
|
},
|
|
1255
1490
|
isHolding() {
|
|
@@ -2000,10 +2235,15 @@ function header(comments, env, ctx) {
|
|
|
2000
2235
|
}
|
|
2001
2236
|
return lines;
|
|
2002
2237
|
}
|
|
2238
|
+
var pct = (v) => `${Math.round(v * 100)}%`;
|
|
2239
|
+
function memberRefs(c, full) {
|
|
2240
|
+
return (c.members ?? []).map((m) => m.source ? location2(m.source.file, m.source.line, full) : m.selector).join(", ");
|
|
2241
|
+
}
|
|
2003
2242
|
function compactLine(c, i, ctx) {
|
|
2004
2243
|
const t = c.target;
|
|
2005
2244
|
const where = t.source ? location2(t.source.file, t.source.line, true) : t.selector;
|
|
2006
|
-
const
|
|
2245
|
+
const own = [where, t.component, `<${t.tag}>`].filter(Boolean).join(" ");
|
|
2246
|
+
const parts = c.members?.length ? `[${c.members.length} elements] ${memberRefs(c, true)}` : c.area ? `[area] in ${own}` : own;
|
|
2007
2247
|
const who = ctx.showAuthors ? ` (${authorLabel(c.author)})` : "";
|
|
2008
2248
|
const route = ctx.showRoutes ? ` [${c.page.route}]` : "";
|
|
2009
2249
|
const id = ctx.showIds ? ` [id ${c.id}]` : "";
|
|
@@ -2020,7 +2260,20 @@ function detailBlock(c, i, ctx, groupHasSource, headedComponent) {
|
|
|
2020
2260
|
} else if (t.source?.line != null && groupHasSource) {
|
|
2021
2261
|
where.push(`line ${t.source.line}`);
|
|
2022
2262
|
}
|
|
2263
|
+
if (c.members?.length) where.unshift("in");
|
|
2264
|
+
if (c.area) where.unshift("area in");
|
|
2023
2265
|
b(where.join(" "));
|
|
2266
|
+
if (c.area) {
|
|
2267
|
+
const a = c.area;
|
|
2268
|
+
b(`region: ${pct(a.x)} from left, ${pct(a.y)} from top, ${pct(a.w)} wide, ${pct(a.h)} tall`);
|
|
2269
|
+
}
|
|
2270
|
+
if (c.members?.length) {
|
|
2271
|
+
b(`${c.members.length} elements:`);
|
|
2272
|
+
for (const m of c.members) {
|
|
2273
|
+
const at = m.source ? location2(m.source.file, m.source.line, full) : `selector \`${m.selector}\``;
|
|
2274
|
+
lines.push(` - \`${m.preview}\` (${m.kind})${m.component && m.component !== t.component ? ` ${m.component}` : ""} ${at}`);
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2024
2277
|
if (!t.source || full) b(`selector: \`${t.selector}\``);
|
|
2025
2278
|
const plain = Object.entries(t.facts).filter(([k, v]) => !STYLE_FACTS.has(k) && !(PREVIEW_FACTS.has(k) && !full && inPreview(t.preview, v)));
|
|
2026
2279
|
if (plain.length) b(plain.map(([k, v]) => `${k}: ${v}`).join(" \xB7 "));
|
|
@@ -2282,7 +2535,8 @@ function createCommentsPanel(callbacks, options = {}) {
|
|
|
2282
2535
|
}
|
|
2283
2536
|
function row2(comment, showAuthors) {
|
|
2284
2537
|
const t = comment.target;
|
|
2285
|
-
const
|
|
2538
|
+
const group = comment.members?.length ? `${comment.members.length} elements` : comment.area ? "area" : null;
|
|
2539
|
+
const meta = live ? [document.createTextNode(`${describeComment(comment)} `)] : [h("span", { class: "grabby-kind" }, group ?? t.kind)];
|
|
2286
2540
|
if (!live) {
|
|
2287
2541
|
if (t.component) meta.push(document.createTextNode(`${t.component} `));
|
|
2288
2542
|
if (t.source) {
|
|
@@ -2512,6 +2766,13 @@ function createCommentPopover(callbacks) {
|
|
|
2512
2766
|
font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding: 8px 4px; border: none;
|
|
2513
2767
|
background: transparent; color: var(--grabby-text-muted, #64748b); cursor: pointer; text-decoration: underline;
|
|
2514
2768
|
}
|
|
2769
|
+
#${POPOVER_ID} .grabby-cp-heading {
|
|
2770
|
+
font: 600 12px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
2771
|
+
color: #15803d;
|
|
2772
|
+
overflow: hidden;
|
|
2773
|
+
text-overflow: ellipsis;
|
|
2774
|
+
white-space: nowrap;
|
|
2775
|
+
}
|
|
2515
2776
|
#${POPOVER_ID} .grabby-cp-edit-actions { display: flex; align-items: center; gap: 6px; }
|
|
2516
2777
|
#${POPOVER_ID} .grabby-cp-edit-actions .grabby-cp-spacer { flex: 1; }
|
|
2517
2778
|
#${POPOVER_ID} .grabby-cp-delete {
|
|
@@ -2550,18 +2811,18 @@ function createCommentPopover(callbacks) {
|
|
|
2550
2811
|
getUiRoot().appendChild(popover);
|
|
2551
2812
|
return popover;
|
|
2552
2813
|
}
|
|
2553
|
-
function position(el, anchor) {
|
|
2814
|
+
function position(el, anchor, box) {
|
|
2554
2815
|
const vw = window.innerWidth;
|
|
2555
2816
|
const vh = window.innerHeight;
|
|
2556
2817
|
const fW = 300;
|
|
2557
2818
|
const fH = 120;
|
|
2558
|
-
if (!anchor) {
|
|
2819
|
+
if (!anchor && !box) {
|
|
2559
2820
|
el.style.left = "50%";
|
|
2560
2821
|
el.style.top = "24px";
|
|
2561
2822
|
el.style.transform = "translateX(-50%)";
|
|
2562
2823
|
return;
|
|
2563
2824
|
}
|
|
2564
|
-
const rect = anchor.getBoundingClientRect();
|
|
2825
|
+
const rect = box ? { ...box, width: box.right - box.left, height: box.bottom - box.top } : anchor.getBoundingClientRect();
|
|
2565
2826
|
let left;
|
|
2566
2827
|
let top;
|
|
2567
2828
|
if (rect.right + 16 + fW <= vw) {
|
|
@@ -2715,8 +2976,12 @@ function createCommentPopover(callbacks) {
|
|
|
2715
2976
|
currentCtx = { mode: opts.mode, entryId: opts.entryId };
|
|
2716
2977
|
askIdentity = opts.askIdentity === true && opts.mode === "new";
|
|
2717
2978
|
visible = true;
|
|
2979
|
+
textarea.placeholder = opts.placeholder ?? "What should change here?";
|
|
2980
|
+
if (opts.heading) {
|
|
2981
|
+
el.prepend(h("div", { class: "grabby-cp-heading", title: opts.heading }, opts.heading));
|
|
2982
|
+
}
|
|
2718
2983
|
if (opts.mode === "edit") el.appendChild(editActions());
|
|
2719
|
-
position(el, opts.anchor);
|
|
2984
|
+
position(el, opts.anchor, opts.anchorBox);
|
|
2720
2985
|
attachKey();
|
|
2721
2986
|
textarea?.focus();
|
|
2722
2987
|
requestAnimationFrame(() => textarea?.focus());
|
|
@@ -3562,6 +3827,8 @@ function createFreezeOverlay() {
|
|
|
3562
3827
|
|
|
3563
3828
|
// src/core/overlay/markers.ts
|
|
3564
3829
|
var LAYER_ID = "__grabby-markers__";
|
|
3830
|
+
var DOC_LAYER_ID = "__grabby-markers-doc__";
|
|
3831
|
+
var CONTEXT_CHECK_MS = 1e3;
|
|
3565
3832
|
var TIP_ID = "__grabby-marker-tip__";
|
|
3566
3833
|
var STYLE_ID9 = "__grabby-marker-styles__";
|
|
3567
3834
|
var SIZE = 22;
|
|
@@ -3573,8 +3840,18 @@ var ICON_EDIT = {
|
|
|
3573
3840
|
size: 12,
|
|
3574
3841
|
shapes: paths("M10.5 2.5l3 3L6 13H3v-3z", "M9 4l3 3")
|
|
3575
3842
|
};
|
|
3843
|
+
function scrollContextOf(el) {
|
|
3844
|
+
for (let cur = el.parentElement; cur && cur !== document.body && cur !== document.documentElement; cur = cur.parentElement) {
|
|
3845
|
+
const style = getComputedStyle(cur);
|
|
3846
|
+
if (style.position === "fixed" || style.position === "sticky") return "screen";
|
|
3847
|
+
if (/(auto|scroll|overlay)/.test(style.overflowY + style.overflowX)) return "screen";
|
|
3848
|
+
}
|
|
3849
|
+
const own = getComputedStyle(el).position;
|
|
3850
|
+
return own === "fixed" || own === "sticky" ? "screen" : "page";
|
|
3851
|
+
}
|
|
3576
3852
|
function createMarkers(deps) {
|
|
3577
3853
|
let layer = null;
|
|
3854
|
+
let docLayer = null;
|
|
3578
3855
|
let tip = null;
|
|
3579
3856
|
let visible = false;
|
|
3580
3857
|
let route = "";
|
|
@@ -3585,13 +3862,27 @@ function createMarkers(deps) {
|
|
|
3585
3862
|
function injectStyles2() {
|
|
3586
3863
|
if (hasStyles(STYLE_ID9)) return;
|
|
3587
3864
|
addStyles(STYLE_ID9, `
|
|
3865
|
+
/*
|
|
3866
|
+
* Page coordinates: the browser moves these with the page as it
|
|
3867
|
+
* scrolls, so they never trail behind their element. (A fixed layer
|
|
3868
|
+
* repositioned from script lags a frame behind fast scrolling.)
|
|
3869
|
+
*/
|
|
3870
|
+
#${DOC_LAYER_ID} {
|
|
3871
|
+
position: absolute;
|
|
3872
|
+
left: 0;
|
|
3873
|
+
top: 0;
|
|
3874
|
+
width: 0;
|
|
3875
|
+
height: 0;
|
|
3876
|
+
pointer-events: none;
|
|
3877
|
+
z-index: ${Z_INDEX_CROSSHAIR};
|
|
3878
|
+
}
|
|
3588
3879
|
#${LAYER_ID} {
|
|
3589
3880
|
position: fixed;
|
|
3590
3881
|
inset: 0;
|
|
3591
3882
|
pointer-events: none;
|
|
3592
3883
|
z-index: ${Z_INDEX_CROSSHAIR};
|
|
3593
3884
|
}
|
|
3594
|
-
|
|
3885
|
+
.grabby-markers-layer .grabby-marker {
|
|
3595
3886
|
position: absolute;
|
|
3596
3887
|
left: 0;
|
|
3597
3888
|
top: 0;
|
|
@@ -3612,22 +3903,24 @@ function createMarkers(deps) {
|
|
|
3612
3903
|
pointer-events: auto;
|
|
3613
3904
|
transition: transform 0.12s ease, box-shadow 0.15s ease;
|
|
3614
3905
|
}
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3906
|
+
.grabby-markers-layer .grabby-marker[hidden] { display: none; }
|
|
3907
|
+
/* Several elements or an area: a green square, like the outline it shows. */
|
|
3908
|
+
.grabby-markers-layer .grabby-marker.grabby-marker-group { border-radius: 6px; background: #16a34a; }
|
|
3909
|
+
.grabby-markers-layer .grabby-marker:hover,
|
|
3910
|
+
.grabby-markers-layer .grabby-marker:focus-visible {
|
|
3618
3911
|
z-index: 1;
|
|
3619
3912
|
outline: none;
|
|
3620
3913
|
box-shadow: 0 0 0 2px #fff, 0 0 0 5px color-mix(in srgb, var(--grabby-accent, #2563eb) 35%, transparent), 0 2px 6px rgba(0, 0, 0, 0.25);
|
|
3621
3914
|
}
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3915
|
+
.grabby-markers-layer .grabby-marker-edit { display: none; }
|
|
3916
|
+
.grabby-markers-layer .grabby-marker:hover .grabby-marker-num,
|
|
3917
|
+
.grabby-markers-layer .grabby-marker:focus-visible .grabby-marker-num { display: none; }
|
|
3918
|
+
.grabby-markers-layer .grabby-marker:hover .grabby-marker-edit,
|
|
3919
|
+
.grabby-markers-layer .grabby-marker:focus-visible .grabby-marker-edit { display: block; }
|
|
3920
|
+
.grabby-markers-layer .grabby-marker-in {
|
|
3628
3921
|
animation: grabby-marker-in 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
|
|
3629
3922
|
}
|
|
3630
|
-
|
|
3923
|
+
.grabby-markers-layer .grabby-marker-out {
|
|
3631
3924
|
animation: grabby-marker-out 0.2s ease-out both;
|
|
3632
3925
|
pointer-events: none;
|
|
3633
3926
|
}
|
|
@@ -3661,7 +3954,7 @@ function createMarkers(deps) {
|
|
|
3661
3954
|
to { opacity: 1; transform: none; }
|
|
3662
3955
|
}
|
|
3663
3956
|
@media (prefers-reduced-motion: reduce) {
|
|
3664
|
-
|
|
3957
|
+
.grabby-markers-layer .grabby-marker-in, .grabby-markers-layer .grabby-marker-out, #${TIP_ID} { animation: none; }
|
|
3665
3958
|
}
|
|
3666
3959
|
`);
|
|
3667
3960
|
}
|
|
@@ -3670,11 +3963,15 @@ function createMarkers(deps) {
|
|
|
3670
3963
|
injectStyles2();
|
|
3671
3964
|
layer = document.createElement("div");
|
|
3672
3965
|
layer.id = LAYER_ID;
|
|
3966
|
+
layer.className = "grabby-markers-layer";
|
|
3967
|
+
docLayer = document.createElement("div");
|
|
3968
|
+
docLayer.id = DOC_LAYER_ID;
|
|
3969
|
+
docLayer.className = "grabby-markers-layer";
|
|
3673
3970
|
tip = document.createElement("div");
|
|
3674
3971
|
tip.id = TIP_ID;
|
|
3675
3972
|
tip.hidden = true;
|
|
3676
3973
|
tip.setAttribute("role", "tooltip");
|
|
3677
|
-
getUiRoot().append(layer, tip);
|
|
3974
|
+
getUiRoot().append(docLayer, layer, tip);
|
|
3678
3975
|
return layer;
|
|
3679
3976
|
}
|
|
3680
3977
|
function pageComments() {
|
|
@@ -3692,7 +3989,7 @@ function createMarkers(deps) {
|
|
|
3692
3989
|
button.className = "grabby-marker";
|
|
3693
3990
|
button.dataset.grabbyMarker = comment.id;
|
|
3694
3991
|
button.append(number, svgIcon(ICON_EDIT, "grabby-marker-edit"));
|
|
3695
|
-
const entry = { comment, button, number, element: null, lastLookup: 0 };
|
|
3992
|
+
const entry = { comment, button, number, element: null, lastLookup: 0, context: "page", contextCheckedAt: -Infinity };
|
|
3696
3993
|
button.addEventListener("click", (e) => {
|
|
3697
3994
|
e.preventDefault();
|
|
3698
3995
|
e.stopPropagation();
|
|
@@ -3773,6 +4070,7 @@ function createMarkers(deps) {
|
|
|
3773
4070
|
host2.appendChild(entry.button);
|
|
3774
4071
|
}
|
|
3775
4072
|
entry.comment = comment;
|
|
4073
|
+
entry.button.classList.toggle("grabby-marker-group", !!(comment.members?.length || comment.area));
|
|
3776
4074
|
const n = String(i + 1);
|
|
3777
4075
|
entry.number.textContent = n;
|
|
3778
4076
|
entry.button.setAttribute("aria-label", `Comment ${n}: ${preview(comment.comment)}. Click to edit.`);
|
|
@@ -3796,9 +4094,20 @@ function createMarkers(deps) {
|
|
|
3796
4094
|
entry.button.hidden = true;
|
|
3797
4095
|
continue;
|
|
3798
4096
|
}
|
|
4097
|
+
if (now - entry.contextCheckedAt >= CONTEXT_CHECK_MS) {
|
|
4098
|
+
entry.contextCheckedAt = now;
|
|
4099
|
+
entry.context = scrollContextOf(entry.element);
|
|
4100
|
+
const home = entry.context === "page" ? docLayer : layer;
|
|
4101
|
+
if (home && entry.button.parentElement !== home) home.appendChild(entry.button);
|
|
4102
|
+
}
|
|
3799
4103
|
const pin = entry.comment.pin ?? { x: 1, y: 0 };
|
|
3800
|
-
const
|
|
3801
|
-
|
|
4104
|
+
const maxX = (document.documentElement.clientWidth || window.innerWidth) - SIZE;
|
|
4105
|
+
let x = Math.max(0, Math.min(rect.left + pin.x * rect.width - SIZE / 2, maxX));
|
|
4106
|
+
let y = rect.top + pin.y * rect.height - SIZE / 2;
|
|
4107
|
+
if (entry.context === "page") {
|
|
4108
|
+
x += window.scrollX;
|
|
4109
|
+
y = Math.max(0, y + window.scrollY);
|
|
4110
|
+
}
|
|
3802
4111
|
entry.button.hidden = false;
|
|
3803
4112
|
entry.button.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
|
|
3804
4113
|
}
|
|
@@ -3828,6 +4137,9 @@ function createMarkers(deps) {
|
|
|
3828
4137
|
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
3829
4138
|
rafId = null;
|
|
3830
4139
|
}
|
|
4140
|
+
function handleScroll() {
|
|
4141
|
+
if (visible && entries.size) position(performance.now());
|
|
4142
|
+
}
|
|
3831
4143
|
return {
|
|
3832
4144
|
setVisible(next) {
|
|
3833
4145
|
if (next === visible) return;
|
|
@@ -3835,8 +4147,10 @@ function createMarkers(deps) {
|
|
|
3835
4147
|
if (next) {
|
|
3836
4148
|
route = deps.currentRoute();
|
|
3837
4149
|
lastRouteCheck = performance.now();
|
|
4150
|
+
document.addEventListener("scroll", handleScroll, { capture: true, passive: true });
|
|
3838
4151
|
sync(true);
|
|
3839
4152
|
} else {
|
|
4153
|
+
document.removeEventListener("scroll", handleScroll, true);
|
|
3840
4154
|
stop();
|
|
3841
4155
|
hideTip();
|
|
3842
4156
|
if (hovered) endHover(hovered);
|
|
@@ -3847,12 +4161,15 @@ function createMarkers(deps) {
|
|
|
3847
4161
|
sync(false);
|
|
3848
4162
|
},
|
|
3849
4163
|
isMarkerElement(el) {
|
|
3850
|
-
return
|
|
4164
|
+
return [layer, docLayer].some((l) => !!l && (l === el || l.contains(el)));
|
|
3851
4165
|
},
|
|
3852
4166
|
dispose() {
|
|
3853
4167
|
stop();
|
|
4168
|
+
document.removeEventListener("scroll", handleScroll, true);
|
|
3854
4169
|
entries.clear();
|
|
3855
4170
|
layer?.remove();
|
|
4171
|
+
docLayer?.remove();
|
|
4172
|
+
docLayer = null;
|
|
3856
4173
|
tip?.remove();
|
|
3857
4174
|
layer = null;
|
|
3858
4175
|
tip = null;
|
|
@@ -3863,11 +4180,141 @@ function createMarkers(deps) {
|
|
|
3863
4180
|
};
|
|
3864
4181
|
}
|
|
3865
4182
|
|
|
4183
|
+
// src/core/overlay/group-outline.ts
|
|
4184
|
+
var LAYER_ID2 = "__grabby-group__";
|
|
4185
|
+
var STYLE_ID10 = "__grabby-group-styles__";
|
|
4186
|
+
var GREEN = "#16a34a";
|
|
4187
|
+
function createGroupOutline() {
|
|
4188
|
+
let layer = null;
|
|
4189
|
+
let marqueeEl = null;
|
|
4190
|
+
let labelEl = null;
|
|
4191
|
+
let boxes = [];
|
|
4192
|
+
let spec = null;
|
|
4193
|
+
let rafId = null;
|
|
4194
|
+
function ensureLayer() {
|
|
4195
|
+
if (layer) return layer;
|
|
4196
|
+
if (!hasStyles(STYLE_ID10)) {
|
|
4197
|
+
addStyles(STYLE_ID10, `
|
|
4198
|
+
#${LAYER_ID2} { position: fixed; inset: 0; pointer-events: none; z-index: ${Z_INDEX_OVERLAY}; }
|
|
4199
|
+
#${LAYER_ID2} .grabby-group-box {
|
|
4200
|
+
position: absolute; left: 0; top: 0; box-sizing: border-box;
|
|
4201
|
+
border: 2px dashed ${GREEN}; border-radius: 4px; background: rgba(22, 163, 74, 0.08);
|
|
4202
|
+
}
|
|
4203
|
+
#${LAYER_ID2} .grabby-group-marquee {
|
|
4204
|
+
position: absolute; left: 0; top: 0; box-sizing: border-box;
|
|
4205
|
+
border: 1px solid var(--grabby-accent, #2563eb); border-radius: 2px;
|
|
4206
|
+
background: color-mix(in srgb, var(--grabby-accent, #2563eb) 8%, transparent);
|
|
4207
|
+
}
|
|
4208
|
+
#${LAYER_ID2} .grabby-group-label {
|
|
4209
|
+
position: absolute; left: 0; top: 0; padding: 2px 6px; border-radius: 3px;
|
|
4210
|
+
background: ${GREEN}; color: #fff; white-space: nowrap;
|
|
4211
|
+
font: 600 11px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
4212
|
+
}
|
|
4213
|
+
#${LAYER_ID2} [hidden] { display: none; }
|
|
4214
|
+
`);
|
|
4215
|
+
}
|
|
4216
|
+
layer = document.createElement("div");
|
|
4217
|
+
layer.id = LAYER_ID2;
|
|
4218
|
+
getUiRoot().appendChild(layer);
|
|
4219
|
+
return layer;
|
|
4220
|
+
}
|
|
4221
|
+
function place(el, b) {
|
|
4222
|
+
el.style.transform = `translate(${Math.round(b.left)}px, ${Math.round(b.top)}px)`;
|
|
4223
|
+
el.style.width = `${Math.max(0, Math.round(b.right - b.left))}px`;
|
|
4224
|
+
el.style.height = `${Math.max(0, Math.round(b.bottom - b.top))}px`;
|
|
4225
|
+
}
|
|
4226
|
+
function currentBoxes() {
|
|
4227
|
+
if (!spec) return [];
|
|
4228
|
+
if ("area" in spec) return spec.element.isConnected ? [areaToBox(spec.element, spec.area)] : [];
|
|
4229
|
+
return spec.elements.flatMap((el) => {
|
|
4230
|
+
if (!el.isConnected) return [];
|
|
4231
|
+
const r = el.getBoundingClientRect();
|
|
4232
|
+
return r.width === 0 && r.height === 0 ? [] : [{ left: r.left, top: r.top, right: r.right, bottom: r.bottom }];
|
|
4233
|
+
});
|
|
4234
|
+
}
|
|
4235
|
+
function render() {
|
|
4236
|
+
const host2 = ensureLayer();
|
|
4237
|
+
const list = currentBoxes();
|
|
4238
|
+
while (boxes.length < list.length) {
|
|
4239
|
+
const b = document.createElement("div");
|
|
4240
|
+
b.className = "grabby-group-box";
|
|
4241
|
+
host2.insertBefore(b, labelEl);
|
|
4242
|
+
boxes.push(b);
|
|
4243
|
+
}
|
|
4244
|
+
boxes.forEach((b, i) => {
|
|
4245
|
+
b.hidden = i >= list.length;
|
|
4246
|
+
if (i < list.length) place(b, list[i]);
|
|
4247
|
+
});
|
|
4248
|
+
if (labelEl && !labelEl.hidden) {
|
|
4249
|
+
const u = spec && "elements" in spec ? unionBox(spec.elements) : list[0] ?? null;
|
|
4250
|
+
if (u) labelEl.style.transform = `translate(${Math.round(u.left)}px, ${Math.round(Math.max(0, u.top - 20))}px)`;
|
|
4251
|
+
}
|
|
4252
|
+
}
|
|
4253
|
+
function track() {
|
|
4254
|
+
rafId = null;
|
|
4255
|
+
if (!spec) return;
|
|
4256
|
+
render();
|
|
4257
|
+
rafId = requestAnimationFrame(track);
|
|
4258
|
+
}
|
|
4259
|
+
function stop() {
|
|
4260
|
+
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
4261
|
+
rafId = null;
|
|
4262
|
+
}
|
|
4263
|
+
return {
|
|
4264
|
+
marquee(box) {
|
|
4265
|
+
if (!box) {
|
|
4266
|
+
if (marqueeEl) marqueeEl.hidden = true;
|
|
4267
|
+
return;
|
|
4268
|
+
}
|
|
4269
|
+
const host2 = ensureLayer();
|
|
4270
|
+
if (!marqueeEl) {
|
|
4271
|
+
marqueeEl = document.createElement("div");
|
|
4272
|
+
marqueeEl.className = "grabby-group-marquee";
|
|
4273
|
+
host2.appendChild(marqueeEl);
|
|
4274
|
+
}
|
|
4275
|
+
marqueeEl.hidden = false;
|
|
4276
|
+
place(marqueeEl, box);
|
|
4277
|
+
},
|
|
4278
|
+
show(next, label) {
|
|
4279
|
+
spec = next;
|
|
4280
|
+
const host2 = ensureLayer();
|
|
4281
|
+
if (!labelEl) {
|
|
4282
|
+
labelEl = document.createElement("div");
|
|
4283
|
+
labelEl.className = "grabby-group-label";
|
|
4284
|
+
host2.appendChild(labelEl);
|
|
4285
|
+
}
|
|
4286
|
+
labelEl.hidden = !label;
|
|
4287
|
+
labelEl.textContent = label ?? "";
|
|
4288
|
+
stop();
|
|
4289
|
+
track();
|
|
4290
|
+
},
|
|
4291
|
+
hide() {
|
|
4292
|
+
spec = null;
|
|
4293
|
+
stop();
|
|
4294
|
+
for (const b of boxes) b.hidden = true;
|
|
4295
|
+
if (labelEl) labelEl.hidden = true;
|
|
4296
|
+
},
|
|
4297
|
+
isVisible() {
|
|
4298
|
+
return spec !== null;
|
|
4299
|
+
},
|
|
4300
|
+
dispose() {
|
|
4301
|
+
stop();
|
|
4302
|
+
layer?.remove();
|
|
4303
|
+
layer = null;
|
|
4304
|
+
marqueeEl = null;
|
|
4305
|
+
labelEl = null;
|
|
4306
|
+
boxes = [];
|
|
4307
|
+
spec = null;
|
|
4308
|
+
removeStyles(STYLE_ID10);
|
|
4309
|
+
}
|
|
4310
|
+
};
|
|
4311
|
+
}
|
|
4312
|
+
|
|
3866
4313
|
// src/core/overlay/select-feedback.ts
|
|
3867
|
-
var
|
|
4314
|
+
var STYLE_ID11 = "__grabby-feedback-styles__";
|
|
3868
4315
|
function injectStyles() {
|
|
3869
|
-
if (hasStyles(
|
|
3870
|
-
addStyles(
|
|
4316
|
+
if (hasStyles(STYLE_ID11)) return;
|
|
4317
|
+
addStyles(STYLE_ID11, `
|
|
3871
4318
|
@keyframes grabby-flash {
|
|
3872
4319
|
0% { opacity: 1; }
|
|
3873
4320
|
100% { opacity: 0; transform: scale(1.02); }
|
|
@@ -3946,7 +4393,7 @@ function showSelectFeedback(element, label = "Selected") {
|
|
|
3946
4393
|
setTimeout(cleanup, 1200);
|
|
3947
4394
|
}
|
|
3948
4395
|
function disposeFeedbackStyles() {
|
|
3949
|
-
removeStyles(
|
|
4396
|
+
removeStyles(STYLE_ID11);
|
|
3950
4397
|
}
|
|
3951
4398
|
|
|
3952
4399
|
// src/core/storage/history-persistence.ts
|
|
@@ -4369,6 +4816,21 @@ function captureTarget(el, deps) {
|
|
|
4369
4816
|
extra
|
|
4370
4817
|
};
|
|
4371
4818
|
}
|
|
4819
|
+
var MEMBER_PREVIEW = 120;
|
|
4820
|
+
function captureMember(el, deps) {
|
|
4821
|
+
const cleanClasses = deps.cleanClasses ?? ((list) => list.filter((c) => !isNoiseClass(c)));
|
|
4822
|
+
const kind = detectKind(el);
|
|
4823
|
+
const { component, frames } = resolveStack(el, deps);
|
|
4824
|
+
return {
|
|
4825
|
+
kind,
|
|
4826
|
+
tag: el.tagName.toLowerCase(),
|
|
4827
|
+
component,
|
|
4828
|
+
source: resolveSource(el, deps, frames),
|
|
4829
|
+
selector: buildUniqueSelector(el),
|
|
4830
|
+
preview: kind === "section" ? `<${el.tagName.toLowerCase()}>` : truncate(buildPreview(el, cleanClasses), MEMBER_PREVIEW),
|
|
4831
|
+
label: describeElement(el)
|
|
4832
|
+
};
|
|
4833
|
+
}
|
|
4372
4834
|
|
|
4373
4835
|
// src/core/capture/screenshot.ts
|
|
4374
4836
|
var MAX_SIDE = 1200;
|
|
@@ -4442,16 +4904,28 @@ function withTimeout(promise, ms) {
|
|
|
4442
4904
|
);
|
|
4443
4905
|
});
|
|
4444
4906
|
}
|
|
4445
|
-
|
|
4907
|
+
var MAX_CLIP_DEPTH = 4e3;
|
|
4908
|
+
var clamp = (v, max) => Math.min(Math.max(v, 0), max);
|
|
4909
|
+
async function captureScreenshot(el, clip) {
|
|
4446
4910
|
if (typeof window === "undefined" || !el.isConnected) return null;
|
|
4447
4911
|
const rect = el.getBoundingClientRect();
|
|
4448
4912
|
if (rect.width < 1 || rect.height < 1) return null;
|
|
4449
|
-
const
|
|
4450
|
-
const
|
|
4913
|
+
const fullWidth = Math.min(rect.width, document.documentElement.scrollWidth || rect.width);
|
|
4914
|
+
const region = clip ? {
|
|
4915
|
+
x: clamp(clip.left - rect.left, fullWidth),
|
|
4916
|
+
y: clamp(clip.top - rect.top, rect.height),
|
|
4917
|
+
right: clamp(clip.right - rect.left, fullWidth),
|
|
4918
|
+
bottom: clamp(clip.bottom - rect.top, rect.height)
|
|
4919
|
+
} : null;
|
|
4920
|
+
if (region && (region.right - region.x < 1 || region.bottom - region.y < 1 || region.bottom > MAX_CLIP_DEPTH)) return null;
|
|
4921
|
+
const cssWidth = fullWidth;
|
|
4922
|
+
const cssHeight = region ? region.bottom : Math.min(rect.height, MAX_CSS_HEIGHT);
|
|
4923
|
+
const outWidth = region ? region.right - region.x : cssWidth;
|
|
4924
|
+
const outHeight = region ? Math.min(region.bottom - region.y, MAX_CSS_HEIGHT) : cssHeight;
|
|
4451
4925
|
const dpr = window.devicePixelRatio || 1;
|
|
4452
|
-
const scale = Math.min(dpr, MAX_SIDE / Math.max(
|
|
4926
|
+
const scale = Math.min(dpr, MAX_SIDE / Math.max(outWidth, outHeight));
|
|
4453
4927
|
const render = async () => {
|
|
4454
|
-
const { createContext, destroyContext, domToBlob } = await import("modern-screenshot");
|
|
4928
|
+
const { createContext, destroyContext, domToBlob, domToCanvas } = await import("modern-screenshot");
|
|
4455
4929
|
const context = await createContext(el, {
|
|
4456
4930
|
width: cssWidth,
|
|
4457
4931
|
height: cssHeight,
|
|
@@ -4468,13 +4942,22 @@ async function captureScreenshot(el) {
|
|
|
4468
4942
|
context.sandbox = await getSandbox();
|
|
4469
4943
|
let blob;
|
|
4470
4944
|
try {
|
|
4471
|
-
|
|
4945
|
+
if (region) {
|
|
4946
|
+
const full = await domToCanvas(context);
|
|
4947
|
+
const crop = document.createElement("canvas");
|
|
4948
|
+
crop.width = Math.max(1, Math.round(outWidth * scale));
|
|
4949
|
+
crop.height = Math.max(1, Math.round(outHeight * scale));
|
|
4950
|
+
crop.getContext("2d")?.drawImage(full, region.x * scale, region.y * scale, outWidth * scale, outHeight * scale, 0, 0, crop.width, crop.height);
|
|
4951
|
+
blob = await new Promise((resolve) => crop.toBlob(resolve, "image/webp", 0.8));
|
|
4952
|
+
} else {
|
|
4953
|
+
blob = await domToBlob(context);
|
|
4954
|
+
}
|
|
4472
4955
|
} finally {
|
|
4473
4956
|
context.sandbox = void 0;
|
|
4474
4957
|
destroyContext(context);
|
|
4475
4958
|
}
|
|
4476
4959
|
if (!blob) return null;
|
|
4477
|
-
return { blob, width: Math.round(
|
|
4960
|
+
return { blob, width: Math.round(outWidth * scale), height: Math.round(outHeight * scale) };
|
|
4478
4961
|
};
|
|
4479
4962
|
return withTimeout(render(), TIMEOUT_MS + 1e3);
|
|
4480
4963
|
}
|
|
@@ -5123,6 +5606,7 @@ function createGrabInstance(options) {
|
|
|
5123
5606
|
}
|
|
5124
5607
|
}
|
|
5125
5608
|
const overlay = createOverlayRenderer({ plainLabels: live });
|
|
5609
|
+
const groupOutline = createGroupOutline();
|
|
5126
5610
|
const crosshair = createCrosshair();
|
|
5127
5611
|
const freezeOverlay = createFreezeOverlay();
|
|
5128
5612
|
const pluginRegistry = createPluginRegistry();
|
|
@@ -5135,6 +5619,9 @@ function createGrabInstance(options) {
|
|
|
5135
5619
|
const cleanClasses = (list) => adapters.cleanClasses(list.filter((c) => !isNoiseClass(c)));
|
|
5136
5620
|
let selectedElement = null;
|
|
5137
5621
|
let selectedPin;
|
|
5622
|
+
let selectedMembers = null;
|
|
5623
|
+
let selectedArea = null;
|
|
5624
|
+
const commentedMembers = /* @__PURE__ */ new Map();
|
|
5138
5625
|
let pendingShot = null;
|
|
5139
5626
|
const commentedElements = /* @__PURE__ */ new Map();
|
|
5140
5627
|
let editingFromMarker = false;
|
|
@@ -5196,7 +5683,9 @@ function createGrabInstance(options) {
|
|
|
5196
5683
|
column: c.target.source?.column ?? null
|
|
5197
5684
|
};
|
|
5198
5685
|
}
|
|
5199
|
-
function saveComment(element, text, shot,
|
|
5686
|
+
function saveComment(element, text, shot, extras = {}) {
|
|
5687
|
+
const { pin, members, area } = extras;
|
|
5688
|
+
const deps = { componentResolver, sourceResolver, cleanClasses };
|
|
5200
5689
|
const now = Date.now();
|
|
5201
5690
|
const comment = {
|
|
5202
5691
|
id: randomId(),
|
|
@@ -5210,13 +5699,16 @@ function createGrabInstance(options) {
|
|
|
5210
5699
|
title: document.title,
|
|
5211
5700
|
viewport: [window.innerWidth, window.innerHeight]
|
|
5212
5701
|
},
|
|
5213
|
-
target: captureTarget(element,
|
|
5702
|
+
target: captureTarget(element, deps),
|
|
5214
5703
|
screenshot: null,
|
|
5215
5704
|
framework: adapters.frameworkFor(element),
|
|
5216
5705
|
...outbox ? { sync: "pending" } : {},
|
|
5217
|
-
...pin ? { pin } : {}
|
|
5706
|
+
...pin ? { pin } : {},
|
|
5707
|
+
...members?.length ? { members: members.map((el) => captureMember(el, deps)) } : {},
|
|
5708
|
+
...area ? { area } : {}
|
|
5218
5709
|
};
|
|
5219
5710
|
commentedElements.set(comment.id, element);
|
|
5711
|
+
if (members?.length) commentedMembers.set(comment.id, members);
|
|
5220
5712
|
setComments([comment, ...comments()].slice(0, MAX_COMMENTS));
|
|
5221
5713
|
pluginRegistry.callHook("onComment", comment, element);
|
|
5222
5714
|
outbox?.send(comment.id);
|
|
@@ -5261,7 +5753,10 @@ function createGrabInstance(options) {
|
|
|
5261
5753
|
const idSet = new Set(ids);
|
|
5262
5754
|
const before = comments();
|
|
5263
5755
|
const removed = before.filter((c) => idSet.has(c.id));
|
|
5264
|
-
for (const id of ids)
|
|
5756
|
+
for (const id of ids) {
|
|
5757
|
+
commentedElements.delete(id);
|
|
5758
|
+
commentedMembers.delete(id);
|
|
5759
|
+
}
|
|
5265
5760
|
setComments(before.filter((c) => !idSet.has(c.id)));
|
|
5266
5761
|
const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
|
|
5267
5762
|
const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
|
|
@@ -5320,16 +5815,52 @@ function createGrabInstance(options) {
|
|
|
5320
5815
|
commentPopover.hide();
|
|
5321
5816
|
endMarkerEdit();
|
|
5322
5817
|
if (picker.isHolding()) {
|
|
5323
|
-
|
|
5324
|
-
selectedPin = void 0;
|
|
5325
|
-
pendingShot = null;
|
|
5818
|
+
clearSelection();
|
|
5326
5819
|
picker.release();
|
|
5327
5820
|
}
|
|
5328
5821
|
}
|
|
5822
|
+
function clearSelection() {
|
|
5823
|
+
selectedElement = null;
|
|
5824
|
+
selectedPin = void 0;
|
|
5825
|
+
selectedMembers = null;
|
|
5826
|
+
selectedArea = null;
|
|
5827
|
+
pendingShot = null;
|
|
5828
|
+
}
|
|
5329
5829
|
function endMarkerEdit() {
|
|
5330
5830
|
if (!editingFromMarker) return;
|
|
5331
5831
|
editingFromMarker = false;
|
|
5332
5832
|
overlay.hide();
|
|
5833
|
+
groupOutline.hide();
|
|
5834
|
+
}
|
|
5835
|
+
function pinIn(el, point) {
|
|
5836
|
+
const rect = el.getBoundingClientRect();
|
|
5837
|
+
const frac2 = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
|
|
5838
|
+
return {
|
|
5839
|
+
x: Math.round(frac2(point.x, rect.left, rect.width) * 1e3) / 1e3,
|
|
5840
|
+
y: Math.round(frac2(point.y, rect.top, rect.height) * 1e3) / 1e3
|
|
5841
|
+
};
|
|
5842
|
+
}
|
|
5843
|
+
function groupSpecFor(comment, element) {
|
|
5844
|
+
if (comment.area && element) return { spec: { element, area: comment.area }, label: "Area" };
|
|
5845
|
+
if (!comment.members?.length) return null;
|
|
5846
|
+
const known = commentedMembers.get(comment.id)?.filter((el) => el.isConnected);
|
|
5847
|
+
const elements = known?.length ? known : comment.members.flatMap((m) => safeQuery(m.selector) ?? []);
|
|
5848
|
+
return elements.length ? { spec: { elements }, label: `${comment.members.length} elements` } : null;
|
|
5849
|
+
}
|
|
5850
|
+
function beginGroupComment(container, point, spec, heading, label, clip) {
|
|
5851
|
+
selectedElement = container;
|
|
5852
|
+
selectedPin = pinIn(container, point);
|
|
5853
|
+
pendingShot = store.state.options.screenshots ? captureScreenshot(container, clip ?? void 0) : null;
|
|
5854
|
+
coachMark.dismiss();
|
|
5855
|
+
picker.hold(container, { spec, label });
|
|
5856
|
+
commentPopover.show({
|
|
5857
|
+
anchor: container,
|
|
5858
|
+
anchorBox: clip,
|
|
5859
|
+
mode: "new",
|
|
5860
|
+
askIdentity: shouldAskIdentity(),
|
|
5861
|
+
heading,
|
|
5862
|
+
placeholder: "What should change here?"
|
|
5863
|
+
});
|
|
5333
5864
|
}
|
|
5334
5865
|
function closeAllPopovers() {
|
|
5335
5866
|
commentsPanel.hide();
|
|
@@ -5357,6 +5888,7 @@ function createGrabInstance(options) {
|
|
|
5357
5888
|
const picker = createElementPicker({
|
|
5358
5889
|
overlay,
|
|
5359
5890
|
crosshair,
|
|
5891
|
+
groupOutline,
|
|
5360
5892
|
getComponentResolver: () => componentResolver,
|
|
5361
5893
|
getSourceResolver: () => sourceResolver,
|
|
5362
5894
|
isToolbarElement: isAnyToolbarElement,
|
|
@@ -5369,18 +5901,24 @@ function createGrabInstance(options) {
|
|
|
5369
5901
|
},
|
|
5370
5902
|
onSelect(element, point) {
|
|
5371
5903
|
selectedElement = element;
|
|
5372
|
-
|
|
5373
|
-
const frac = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
|
|
5374
|
-
selectedPin = {
|
|
5375
|
-
x: Math.round(frac(point.x, rect.left, rect.width) * 1e3) / 1e3,
|
|
5376
|
-
y: Math.round(frac(point.y, rect.top, rect.height) * 1e3) / 1e3
|
|
5377
|
-
};
|
|
5904
|
+
selectedPin = pinIn(element, point);
|
|
5378
5905
|
pendingShot = store.state.options.screenshots ? captureScreenshot(element) : null;
|
|
5379
5906
|
pluginRegistry.callHook("onElementSelect", element);
|
|
5380
5907
|
coachMark.dismiss();
|
|
5381
5908
|
showSelectFeedback(element);
|
|
5382
5909
|
picker.hold(element);
|
|
5383
5910
|
commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
|
|
5911
|
+
},
|
|
5912
|
+
onSelectGroup(elements, point) {
|
|
5913
|
+
selectedMembers = elements;
|
|
5914
|
+
const heading = describeGroup(elements.map(describeElement));
|
|
5915
|
+
for (const el of elements) pluginRegistry.callHook("onElementSelect", el);
|
|
5916
|
+
beginGroupComment(commonContainer(elements), point, { elements }, heading, `${elements.length} elements`, unionBox(elements));
|
|
5917
|
+
},
|
|
5918
|
+
onSelectArea(container, area, point) {
|
|
5919
|
+
selectedArea = area;
|
|
5920
|
+
pluginRegistry.callHook("onElementSelect", container);
|
|
5921
|
+
beginGroupComment(container, point, { element: container, area }, describeArea(describeElement(container)), "Area", areaToBox(container, area));
|
|
5384
5922
|
}
|
|
5385
5923
|
});
|
|
5386
5924
|
const markers = createMarkers({
|
|
@@ -5393,20 +5931,30 @@ function createGrabInstance(options) {
|
|
|
5393
5931
|
},
|
|
5394
5932
|
onHover(comment, element) {
|
|
5395
5933
|
if (picker.isHolding() || editingFromMarker || commentPopover.isVisible()) return;
|
|
5396
|
-
|
|
5397
|
-
|
|
5934
|
+
const group = comment ? groupSpecFor(comment, element) : null;
|
|
5935
|
+
if (group) groupOutline.show(group.spec, group.label);
|
|
5936
|
+
else if (comment && element) overlay.show(element, comment.target.component, null, []);
|
|
5937
|
+
else {
|
|
5938
|
+
overlay.hide();
|
|
5939
|
+
groupOutline.hide();
|
|
5940
|
+
}
|
|
5398
5941
|
},
|
|
5399
5942
|
onOpen(comment, element, marker) {
|
|
5400
5943
|
if (picker.isHolding()) return;
|
|
5401
5944
|
closeAllPopovers();
|
|
5402
5945
|
doDeactivate(true);
|
|
5403
5946
|
editingFromMarker = true;
|
|
5404
|
-
|
|
5947
|
+
const group = groupSpecFor(comment, element);
|
|
5948
|
+
if (group) groupOutline.show(group.spec, group.label);
|
|
5949
|
+
else if (element) overlay.show(element, comment.target.component, null, []);
|
|
5950
|
+
const spec = group?.spec;
|
|
5405
5951
|
commentPopover.show({
|
|
5406
5952
|
anchor: element ?? marker,
|
|
5953
|
+
anchorBox: spec ? "area" in spec ? areaToBox(spec.element, spec.area) : unionBox(spec.elements) : null,
|
|
5407
5954
|
initialValue: comment.comment,
|
|
5408
5955
|
mode: "edit",
|
|
5409
|
-
entryId: comment.id
|
|
5956
|
+
entryId: comment.id,
|
|
5957
|
+
heading: comment.members?.length || comment.area ? describeComment(comment) : void 0
|
|
5410
5958
|
});
|
|
5411
5959
|
}
|
|
5412
5960
|
});
|
|
@@ -5581,12 +6129,10 @@ function createGrabInstance(options) {
|
|
|
5581
6129
|
if (identity) saveIdentity({ name: identity.name, anonymous: !identity.name });
|
|
5582
6130
|
if (ctx.mode === "new") {
|
|
5583
6131
|
const element = selectedElement;
|
|
6132
|
+
const extras = { pin: selectedPin, members: selectedMembers, area: selectedArea };
|
|
5584
6133
|
const shot = pendingShot;
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
selectedPin = void 0;
|
|
5588
|
-
pendingShot = null;
|
|
5589
|
-
if (element) saveComment(element, value, shot, pin);
|
|
6134
|
+
clearSelection();
|
|
6135
|
+
if (element) saveComment(element, value, shot, extras);
|
|
5590
6136
|
doDeactivate(true);
|
|
5591
6137
|
return;
|
|
5592
6138
|
}
|
|
@@ -5602,9 +6148,7 @@ function createGrabInstance(options) {
|
|
|
5602
6148
|
},
|
|
5603
6149
|
onCancel(ctx) {
|
|
5604
6150
|
if (ctx.mode === "new") {
|
|
5605
|
-
|
|
5606
|
-
selectedPin = void 0;
|
|
5607
|
-
pendingShot = null;
|
|
6151
|
+
clearSelection();
|
|
5608
6152
|
doDeactivate(true);
|
|
5609
6153
|
return;
|
|
5610
6154
|
}
|
|
@@ -5770,6 +6314,7 @@ function createGrabInstance(options) {
|
|
|
5770
6314
|
crosshair.dispose();
|
|
5771
6315
|
freezeOverlay.dispose();
|
|
5772
6316
|
markers.dispose();
|
|
6317
|
+
groupOutline.dispose();
|
|
5773
6318
|
disposeToast();
|
|
5774
6319
|
disposeFeedbackStyles();
|
|
5775
6320
|
pluginRegistry.dispose();
|