@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/angular/index.js
CHANGED
|
@@ -595,6 +595,20 @@ function describeTarget(target) {
|
|
|
595
595
|
const name = facts.label || facts.heading || facts.text || facts.alt || "";
|
|
596
596
|
return quoted(noun, name);
|
|
597
597
|
}
|
|
598
|
+
var GROUP_NAMED = 3;
|
|
599
|
+
function describeGroup(labels) {
|
|
600
|
+
const named = labels.slice(0, GROUP_NAMED).join(", ");
|
|
601
|
+
const more = labels.length > GROUP_NAMED ? ` and ${labels.length - GROUP_NAMED} more` : "";
|
|
602
|
+
return `${labels.length} elements: ${named}${more}`;
|
|
603
|
+
}
|
|
604
|
+
function describeArea(around) {
|
|
605
|
+
return `Area in ${around}`;
|
|
606
|
+
}
|
|
607
|
+
function describeComment(c) {
|
|
608
|
+
if (c.members?.length) return describeGroup(c.members.map((m) => m.label));
|
|
609
|
+
if (c.area) return describeArea(describeTarget(c.target));
|
|
610
|
+
return describeTarget(c.target);
|
|
611
|
+
}
|
|
598
612
|
|
|
599
613
|
// src/core/overlay/overlay-renderer.ts
|
|
600
614
|
var OVERLAY_ID = "__grabby-overlay__";
|
|
@@ -1245,11 +1259,114 @@ function buildUniqueSelector(el) {
|
|
|
1245
1259
|
return steps.join(" > ");
|
|
1246
1260
|
}
|
|
1247
1261
|
|
|
1262
|
+
// src/core/picker/region.ts
|
|
1263
|
+
var MAX_MEMBERS = 20;
|
|
1264
|
+
var INSIDE_RATIO = 0.85;
|
|
1265
|
+
var MIN_SIDE = 4;
|
|
1266
|
+
var MAX_VISITS = 4e3;
|
|
1267
|
+
var SKIP_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "HEAD", "META", "LINK", "BR", "WBR"]);
|
|
1268
|
+
function boxFromPoints(a, b) {
|
|
1269
|
+
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) };
|
|
1270
|
+
}
|
|
1271
|
+
function overlapArea(r, box) {
|
|
1272
|
+
const w = Math.min(r.right, box.right) - Math.max(r.left, box.left);
|
|
1273
|
+
const h2 = Math.min(r.bottom, box.bottom) - Math.max(r.top, box.top);
|
|
1274
|
+
return w > 0 && h2 > 0 ? w * h2 : 0;
|
|
1275
|
+
}
|
|
1276
|
+
function contains(r, box) {
|
|
1277
|
+
return r.left <= box.left && r.top <= box.top && r.right >= box.right && r.bottom >= box.bottom;
|
|
1278
|
+
}
|
|
1279
|
+
function isHidden(el) {
|
|
1280
|
+
const style = getComputedStyle(el);
|
|
1281
|
+
return style.visibility === "hidden" || style.opacity === "0";
|
|
1282
|
+
}
|
|
1283
|
+
function elementsInBox(box, isUiNode2, root2 = document.body) {
|
|
1284
|
+
const found = [];
|
|
1285
|
+
let visits = 0;
|
|
1286
|
+
const visit = (el) => {
|
|
1287
|
+
if (found.length >= MAX_MEMBERS || ++visits > MAX_VISITS) return;
|
|
1288
|
+
if (SKIP_TAGS.has(el.tagName) || isUiNode2(el) || el.hasAttribute(IGNORE_ATTR)) return;
|
|
1289
|
+
const r = el.getBoundingClientRect();
|
|
1290
|
+
const boxless = r.width === 0 && r.height === 0;
|
|
1291
|
+
if (!boxless && overlapArea(r, box) === 0) return;
|
|
1292
|
+
if (!boxless && r.width >= MIN_SIDE && r.height >= MIN_SIDE) {
|
|
1293
|
+
const inside = overlapArea(r, box) / (r.width * r.height);
|
|
1294
|
+
if (inside >= INSIDE_RATIO && detectKind(el) !== "section" && !isHidden(el)) {
|
|
1295
|
+
found.push(el);
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
for (const child of Array.from(el.children)) visit(child);
|
|
1300
|
+
};
|
|
1301
|
+
for (const child of Array.from(root2.children)) visit(child);
|
|
1302
|
+
return found;
|
|
1303
|
+
}
|
|
1304
|
+
function commonContainer(elements) {
|
|
1305
|
+
if (elements.length === 0) return document.body;
|
|
1306
|
+
let candidate = elements[0].parentElement ?? document.body;
|
|
1307
|
+
while (candidate && !elements.every((el) => candidate.contains(el))) candidate = candidate.parentElement;
|
|
1308
|
+
return candidate ?? document.body;
|
|
1309
|
+
}
|
|
1310
|
+
function containerForBox(box, isUiNode2) {
|
|
1311
|
+
const cx = (box.left + box.right) / 2;
|
|
1312
|
+
const cy = (box.top + box.bottom) / 2;
|
|
1313
|
+
const stack = typeof document.elementsFromPoint === "function" ? document.elementsFromPoint(cx, cy) : [];
|
|
1314
|
+
for (const el of stack) {
|
|
1315
|
+
if (isUiNode2(el) || el.closest(`[${IGNORE_ATTR}]`)) continue;
|
|
1316
|
+
for (let cur = el; cur; cur = cur.parentElement) {
|
|
1317
|
+
if (contains(cur.getBoundingClientRect(), box)) return cur;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return document.body;
|
|
1321
|
+
}
|
|
1322
|
+
var frac = (v) => Math.round(Math.min(1, Math.max(0, v)) * 1e3) / 1e3;
|
|
1323
|
+
function areaWithin(el, box) {
|
|
1324
|
+
const r = el.getBoundingClientRect();
|
|
1325
|
+
const w = r.width || 1;
|
|
1326
|
+
const h2 = r.height || 1;
|
|
1327
|
+
return {
|
|
1328
|
+
x: frac((box.left - r.left) / w),
|
|
1329
|
+
y: frac((box.top - r.top) / h2),
|
|
1330
|
+
w: frac((box.right - box.left) / w),
|
|
1331
|
+
h: frac((box.bottom - box.top) / h2)
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
function areaToBox(el, area) {
|
|
1335
|
+
const r = el.getBoundingClientRect();
|
|
1336
|
+
return {
|
|
1337
|
+
left: r.left + area.x * r.width,
|
|
1338
|
+
top: r.top + area.y * r.height,
|
|
1339
|
+
right: r.left + (area.x + area.w) * r.width,
|
|
1340
|
+
bottom: r.top + (area.y + area.h) * r.height
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
function unionBox(elements) {
|
|
1344
|
+
let out = null;
|
|
1345
|
+
for (const el of elements) {
|
|
1346
|
+
const r = el.getBoundingClientRect();
|
|
1347
|
+
if (r.width === 0 && r.height === 0) continue;
|
|
1348
|
+
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 };
|
|
1349
|
+
}
|
|
1350
|
+
return out;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1248
1353
|
// src/core/picker/element-picker.ts
|
|
1354
|
+
var DRAG_PX = 6;
|
|
1355
|
+
var IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
1356
|
+
var PRESS_EVENTS = ["pointerdown", "mousedown", "pointerup", "mouseup", "touchstart"];
|
|
1357
|
+
function addKey(e) {
|
|
1358
|
+
return IS_MAC ? e.metaKey : e.ctrlKey;
|
|
1359
|
+
}
|
|
1249
1360
|
function createElementPicker(deps) {
|
|
1250
1361
|
let hoveredElement = null;
|
|
1251
1362
|
let heldElement = null;
|
|
1252
1363
|
let listening = false;
|
|
1364
|
+
let press = null;
|
|
1365
|
+
let dragBox = null;
|
|
1366
|
+
let dragFrame = null;
|
|
1367
|
+
let lastPoint = { x: 0, y: 0 };
|
|
1368
|
+
let swallowNextClick = false;
|
|
1369
|
+
let collected = [];
|
|
1253
1370
|
function resolveComponentName(el) {
|
|
1254
1371
|
const resolver = deps.getComponentResolver();
|
|
1255
1372
|
if (!resolver) return null;
|
|
@@ -1279,14 +1396,93 @@ function createElementPicker(deps) {
|
|
|
1279
1396
|
if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
|
|
1280
1397
|
return exact ? raw : promoteTarget(raw);
|
|
1281
1398
|
}
|
|
1399
|
+
function isOurs(el) {
|
|
1400
|
+
return !!deps.isToolbarElement?.(el) || deps.overlay.isOverlayElement(el) || deps.crosshair.isCrosshairElement(el);
|
|
1401
|
+
}
|
|
1282
1402
|
function showOverlay(target) {
|
|
1283
1403
|
const componentName = resolveComponentName(target);
|
|
1284
1404
|
const sourcePath = resolveSourcePath(target);
|
|
1285
1405
|
const cssClasses = filterAngularClasses(target.classList);
|
|
1286
1406
|
deps.overlay.show(target, componentName, sourcePath, cssClasses);
|
|
1287
1407
|
}
|
|
1408
|
+
const countLabel = (n) => `${n} element${n === 1 ? "" : "s"}`;
|
|
1409
|
+
function showCollected() {
|
|
1410
|
+
if (collected.length) {
|
|
1411
|
+
deps.groupOutline.show({ elements: collected }, `${countLabel(collected.length)} \xB7 release ${IS_MAC ? "\u2318" : "Ctrl"} to comment`);
|
|
1412
|
+
} else {
|
|
1413
|
+
deps.groupOutline.hide();
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
function clearCollected() {
|
|
1417
|
+
if (!collected.length) return;
|
|
1418
|
+
collected = [];
|
|
1419
|
+
deps.groupOutline.hide();
|
|
1420
|
+
}
|
|
1421
|
+
function previewDrag() {
|
|
1422
|
+
dragFrame = null;
|
|
1423
|
+
if (!dragBox) return;
|
|
1424
|
+
deps.groupOutline.marquee(dragBox);
|
|
1425
|
+
const found = elementsInBox(dragBox, isOurs);
|
|
1426
|
+
if (found.length) deps.groupOutline.show({ elements: found }, countLabel(found.length));
|
|
1427
|
+
else deps.groupOutline.hide();
|
|
1428
|
+
}
|
|
1429
|
+
function endDrag() {
|
|
1430
|
+
dragBox = null;
|
|
1431
|
+
if (dragFrame !== null) cancelAnimationFrame(dragFrame);
|
|
1432
|
+
dragFrame = null;
|
|
1433
|
+
deps.groupOutline.marquee(null);
|
|
1434
|
+
deps.groupOutline.hide();
|
|
1435
|
+
}
|
|
1436
|
+
function finishDrag(point) {
|
|
1437
|
+
const box = dragBox;
|
|
1438
|
+
endDrag();
|
|
1439
|
+
const found = elementsInBox(box, isOurs);
|
|
1440
|
+
if (found.length === 1) {
|
|
1441
|
+
hoveredElement = found[0];
|
|
1442
|
+
deps.onSelect(found[0], point);
|
|
1443
|
+
} else if (found.length > 1) {
|
|
1444
|
+
deps.onSelectGroup(found, point);
|
|
1445
|
+
} else {
|
|
1446
|
+
const container = containerForBox(box, isOurs);
|
|
1447
|
+
deps.onSelectArea(container, areaWithin(container, box), point);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
function handlePress(e) {
|
|
1451
|
+
const origin = eventTarget(e);
|
|
1452
|
+
if (origin && deps.isToolbarElement?.(origin)) return;
|
|
1453
|
+
e.stopPropagation();
|
|
1454
|
+
if (e.type === "mousedown" || e.type === "touchstart") e.preventDefault();
|
|
1455
|
+
if (heldElement) return;
|
|
1456
|
+
const m = e;
|
|
1457
|
+
const down = e.type === "pointerdown" || e.type === "mousedown";
|
|
1458
|
+
if (down && m.button === 0 && !press) {
|
|
1459
|
+
press = { x: m.clientX, y: m.clientY };
|
|
1460
|
+
swallowNextClick = false;
|
|
1461
|
+
} else if (!down && e.type !== "touchstart" && press) {
|
|
1462
|
+
const point = { x: m.clientX, y: m.clientY };
|
|
1463
|
+
const start = press;
|
|
1464
|
+
press = null;
|
|
1465
|
+
if (dragBox) {
|
|
1466
|
+
dragBox = boxFromPoints(start, point);
|
|
1467
|
+
swallowNextClick = true;
|
|
1468
|
+
finishDrag(point);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1288
1472
|
function handleMouseMove(e) {
|
|
1289
1473
|
if (heldElement) return;
|
|
1474
|
+
lastPoint = { x: e.clientX, y: e.clientY };
|
|
1475
|
+
if (press) {
|
|
1476
|
+
if (!dragBox && Math.hypot(e.clientX - press.x, e.clientY - press.y) < DRAG_PX) return;
|
|
1477
|
+
if (!dragBox) {
|
|
1478
|
+
clearCollected();
|
|
1479
|
+
deps.overlay.hide();
|
|
1480
|
+
hoveredElement = null;
|
|
1481
|
+
}
|
|
1482
|
+
dragBox = boxFromPoints(press, lastPoint);
|
|
1483
|
+
if (dragFrame === null) dragFrame = requestAnimationFrame(previewDrag);
|
|
1484
|
+
return;
|
|
1485
|
+
}
|
|
1290
1486
|
const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
|
|
1291
1487
|
if (!target || deps.overlay.isOverlayElement(target)) return;
|
|
1292
1488
|
if (deps.crosshair.isCrosshairElement(target)) return;
|
|
@@ -1304,8 +1500,32 @@ function createElementPicker(deps) {
|
|
|
1304
1500
|
e.preventDefault();
|
|
1305
1501
|
e.stopPropagation();
|
|
1306
1502
|
if (heldElement) return;
|
|
1307
|
-
if (
|
|
1308
|
-
|
|
1503
|
+
if (swallowNextClick) {
|
|
1504
|
+
swallowNextClick = false;
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
if (!hoveredElement) return;
|
|
1508
|
+
lastPoint = { x: e.clientX, y: e.clientY };
|
|
1509
|
+
if (addKey(e)) {
|
|
1510
|
+
const at = collected.indexOf(hoveredElement);
|
|
1511
|
+
if (at >= 0) collected.splice(at, 1);
|
|
1512
|
+
else if (collected.length < MAX_MEMBERS) collected.push(hoveredElement);
|
|
1513
|
+
showCollected();
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
clearCollected();
|
|
1517
|
+
deps.onSelect(hoveredElement, lastPoint);
|
|
1518
|
+
}
|
|
1519
|
+
function handleKeyUp(e) {
|
|
1520
|
+
if (e.key !== (IS_MAC ? "Meta" : "Control") || !collected.length || heldElement) return;
|
|
1521
|
+
const elements = collected;
|
|
1522
|
+
collected = [];
|
|
1523
|
+
deps.groupOutline.hide();
|
|
1524
|
+
if (elements.length === 1) {
|
|
1525
|
+
hoveredElement = elements[0];
|
|
1526
|
+
deps.onSelect(elements[0], lastPoint);
|
|
1527
|
+
} else {
|
|
1528
|
+
deps.onSelectGroup(elements, lastPoint);
|
|
1309
1529
|
}
|
|
1310
1530
|
}
|
|
1311
1531
|
return {
|
|
@@ -1313,31 +1533,46 @@ function createElementPicker(deps) {
|
|
|
1313
1533
|
if (listening) return;
|
|
1314
1534
|
listening = true;
|
|
1315
1535
|
deps.crosshair.activate();
|
|
1536
|
+
for (const type of PRESS_EVENTS) window.addEventListener(type, handlePress, { capture: true, passive: false });
|
|
1316
1537
|
document.addEventListener("mousemove", handleMouseMove, true);
|
|
1317
1538
|
document.addEventListener("click", handleClick, true);
|
|
1539
|
+
window.addEventListener("keyup", handleKeyUp, true);
|
|
1318
1540
|
},
|
|
1319
1541
|
deactivate() {
|
|
1320
1542
|
if (!listening) return;
|
|
1321
1543
|
listening = false;
|
|
1322
1544
|
hoveredElement = null;
|
|
1323
1545
|
heldElement = null;
|
|
1546
|
+
press = null;
|
|
1547
|
+
swallowNextClick = false;
|
|
1548
|
+
collected = [];
|
|
1549
|
+
endDrag();
|
|
1324
1550
|
deps.crosshair.hold(false);
|
|
1325
1551
|
deps.crosshair.deactivate();
|
|
1552
|
+
for (const type of PRESS_EVENTS) window.removeEventListener(type, handlePress, true);
|
|
1326
1553
|
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
1327
1554
|
document.removeEventListener("click", handleClick, true);
|
|
1555
|
+
window.removeEventListener("keyup", handleKeyUp, true);
|
|
1328
1556
|
deps.overlay.hide();
|
|
1329
1557
|
deps.onHover(null);
|
|
1330
1558
|
},
|
|
1331
|
-
hold(element) {
|
|
1559
|
+
hold(element, group) {
|
|
1332
1560
|
if (!listening) return;
|
|
1333
1561
|
heldElement = element;
|
|
1334
1562
|
hoveredElement = element;
|
|
1563
|
+
press = null;
|
|
1335
1564
|
deps.crosshair.hold(true);
|
|
1336
|
-
|
|
1565
|
+
if (group) {
|
|
1566
|
+
deps.overlay.hide();
|
|
1567
|
+
deps.groupOutline.show(group.spec, group.label);
|
|
1568
|
+
} else {
|
|
1569
|
+
showOverlay(element);
|
|
1570
|
+
}
|
|
1337
1571
|
},
|
|
1338
1572
|
release() {
|
|
1339
1573
|
if (!heldElement) return;
|
|
1340
1574
|
heldElement = null;
|
|
1575
|
+
deps.groupOutline.hide();
|
|
1341
1576
|
deps.crosshair.hold(false);
|
|
1342
1577
|
},
|
|
1343
1578
|
isHolding() {
|
|
@@ -2088,10 +2323,15 @@ function header(comments, env, ctx) {
|
|
|
2088
2323
|
}
|
|
2089
2324
|
return lines;
|
|
2090
2325
|
}
|
|
2326
|
+
var pct = (v) => `${Math.round(v * 100)}%`;
|
|
2327
|
+
function memberRefs(c, full) {
|
|
2328
|
+
return (c.members ?? []).map((m) => m.source ? location2(m.source.file, m.source.line, full) : m.selector).join(", ");
|
|
2329
|
+
}
|
|
2091
2330
|
function compactLine(c, i, ctx) {
|
|
2092
2331
|
const t = c.target;
|
|
2093
2332
|
const where = t.source ? location2(t.source.file, t.source.line, true) : t.selector;
|
|
2094
|
-
const
|
|
2333
|
+
const own = [where, t.component, `<${t.tag}>`].filter(Boolean).join(" ");
|
|
2334
|
+
const parts = c.members?.length ? `[${c.members.length} elements] ${memberRefs(c, true)}` : c.area ? `[area] in ${own}` : own;
|
|
2095
2335
|
const who = ctx.showAuthors ? ` (${authorLabel(c.author)})` : "";
|
|
2096
2336
|
const route = ctx.showRoutes ? ` [${c.page.route}]` : "";
|
|
2097
2337
|
const id = ctx.showIds ? ` [id ${c.id}]` : "";
|
|
@@ -2108,7 +2348,20 @@ function detailBlock(c, i, ctx, groupHasSource, headedComponent) {
|
|
|
2108
2348
|
} else if (t.source?.line != null && groupHasSource) {
|
|
2109
2349
|
where.push(`line ${t.source.line}`);
|
|
2110
2350
|
}
|
|
2351
|
+
if (c.members?.length) where.unshift("in");
|
|
2352
|
+
if (c.area) where.unshift("area in");
|
|
2111
2353
|
b(where.join(" "));
|
|
2354
|
+
if (c.area) {
|
|
2355
|
+
const a = c.area;
|
|
2356
|
+
b(`region: ${pct(a.x)} from left, ${pct(a.y)} from top, ${pct(a.w)} wide, ${pct(a.h)} tall`);
|
|
2357
|
+
}
|
|
2358
|
+
if (c.members?.length) {
|
|
2359
|
+
b(`${c.members.length} elements:`);
|
|
2360
|
+
for (const m of c.members) {
|
|
2361
|
+
const at = m.source ? location2(m.source.file, m.source.line, full) : `selector \`${m.selector}\``;
|
|
2362
|
+
lines.push(` - \`${m.preview}\` (${m.kind})${m.component && m.component !== t.component ? ` ${m.component}` : ""} ${at}`);
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2112
2365
|
if (!t.source || full) b(`selector: \`${t.selector}\``);
|
|
2113
2366
|
const plain = Object.entries(t.facts).filter(([k, v]) => !STYLE_FACTS.has(k) && !(PREVIEW_FACTS.has(k) && !full && inPreview(t.preview, v)));
|
|
2114
2367
|
if (plain.length) b(plain.map(([k, v]) => `${k}: ${v}`).join(" \xB7 "));
|
|
@@ -2370,7 +2623,8 @@ function createCommentsPanel(callbacks, options = {}) {
|
|
|
2370
2623
|
}
|
|
2371
2624
|
function row2(comment, showAuthors) {
|
|
2372
2625
|
const t = comment.target;
|
|
2373
|
-
const
|
|
2626
|
+
const group = comment.members?.length ? `${comment.members.length} elements` : comment.area ? "area" : null;
|
|
2627
|
+
const meta = live ? [document.createTextNode(`${describeComment(comment)} `)] : [h("span", { class: "grabby-kind" }, group ?? t.kind)];
|
|
2374
2628
|
if (!live) {
|
|
2375
2629
|
if (t.component) meta.push(document.createTextNode(`${t.component} `));
|
|
2376
2630
|
if (t.source) {
|
|
@@ -2600,6 +2854,13 @@ function createCommentPopover(callbacks) {
|
|
|
2600
2854
|
font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding: 8px 4px; border: none;
|
|
2601
2855
|
background: transparent; color: var(--grabby-text-muted, #64748b); cursor: pointer; text-decoration: underline;
|
|
2602
2856
|
}
|
|
2857
|
+
#${POPOVER_ID} .grabby-cp-heading {
|
|
2858
|
+
font: 600 12px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
2859
|
+
color: #15803d;
|
|
2860
|
+
overflow: hidden;
|
|
2861
|
+
text-overflow: ellipsis;
|
|
2862
|
+
white-space: nowrap;
|
|
2863
|
+
}
|
|
2603
2864
|
#${POPOVER_ID} .grabby-cp-edit-actions { display: flex; align-items: center; gap: 6px; }
|
|
2604
2865
|
#${POPOVER_ID} .grabby-cp-edit-actions .grabby-cp-spacer { flex: 1; }
|
|
2605
2866
|
#${POPOVER_ID} .grabby-cp-delete {
|
|
@@ -2638,18 +2899,18 @@ function createCommentPopover(callbacks) {
|
|
|
2638
2899
|
getUiRoot().appendChild(popover);
|
|
2639
2900
|
return popover;
|
|
2640
2901
|
}
|
|
2641
|
-
function position(el, anchor) {
|
|
2902
|
+
function position(el, anchor, box) {
|
|
2642
2903
|
const vw = window.innerWidth;
|
|
2643
2904
|
const vh = window.innerHeight;
|
|
2644
2905
|
const fW = 300;
|
|
2645
2906
|
const fH = 120;
|
|
2646
|
-
if (!anchor) {
|
|
2907
|
+
if (!anchor && !box) {
|
|
2647
2908
|
el.style.left = "50%";
|
|
2648
2909
|
el.style.top = "24px";
|
|
2649
2910
|
el.style.transform = "translateX(-50%)";
|
|
2650
2911
|
return;
|
|
2651
2912
|
}
|
|
2652
|
-
const rect = anchor.getBoundingClientRect();
|
|
2913
|
+
const rect = box ? { ...box, width: box.right - box.left, height: box.bottom - box.top } : anchor.getBoundingClientRect();
|
|
2653
2914
|
let left;
|
|
2654
2915
|
let top;
|
|
2655
2916
|
if (rect.right + 16 + fW <= vw) {
|
|
@@ -2803,8 +3064,12 @@ function createCommentPopover(callbacks) {
|
|
|
2803
3064
|
currentCtx = { mode: opts.mode, entryId: opts.entryId };
|
|
2804
3065
|
askIdentity = opts.askIdentity === true && opts.mode === "new";
|
|
2805
3066
|
visible = true;
|
|
3067
|
+
textarea.placeholder = opts.placeholder ?? "What should change here?";
|
|
3068
|
+
if (opts.heading) {
|
|
3069
|
+
el.prepend(h("div", { class: "grabby-cp-heading", title: opts.heading }, opts.heading));
|
|
3070
|
+
}
|
|
2806
3071
|
if (opts.mode === "edit") el.appendChild(editActions());
|
|
2807
|
-
position(el, opts.anchor);
|
|
3072
|
+
position(el, opts.anchor, opts.anchorBox);
|
|
2808
3073
|
attachKey();
|
|
2809
3074
|
textarea?.focus();
|
|
2810
3075
|
requestAnimationFrame(() => textarea?.focus());
|
|
@@ -3689,6 +3954,8 @@ function createFreezeOverlay() {
|
|
|
3689
3954
|
|
|
3690
3955
|
// src/core/overlay/markers.ts
|
|
3691
3956
|
var LAYER_ID = "__grabby-markers__";
|
|
3957
|
+
var DOC_LAYER_ID = "__grabby-markers-doc__";
|
|
3958
|
+
var CONTEXT_CHECK_MS = 1e3;
|
|
3692
3959
|
var TIP_ID = "__grabby-marker-tip__";
|
|
3693
3960
|
var STYLE_ID9 = "__grabby-marker-styles__";
|
|
3694
3961
|
var SIZE = 22;
|
|
@@ -3700,8 +3967,18 @@ var ICON_EDIT = {
|
|
|
3700
3967
|
size: 12,
|
|
3701
3968
|
shapes: paths("M10.5 2.5l3 3L6 13H3v-3z", "M9 4l3 3")
|
|
3702
3969
|
};
|
|
3970
|
+
function scrollContextOf(el) {
|
|
3971
|
+
for (let cur = el.parentElement; cur && cur !== document.body && cur !== document.documentElement; cur = cur.parentElement) {
|
|
3972
|
+
const style = getComputedStyle(cur);
|
|
3973
|
+
if (style.position === "fixed" || style.position === "sticky") return "screen";
|
|
3974
|
+
if (/(auto|scroll|overlay)/.test(style.overflowY + style.overflowX)) return "screen";
|
|
3975
|
+
}
|
|
3976
|
+
const own = getComputedStyle(el).position;
|
|
3977
|
+
return own === "fixed" || own === "sticky" ? "screen" : "page";
|
|
3978
|
+
}
|
|
3703
3979
|
function createMarkers(deps) {
|
|
3704
3980
|
let layer = null;
|
|
3981
|
+
let docLayer = null;
|
|
3705
3982
|
let tip = null;
|
|
3706
3983
|
let visible = false;
|
|
3707
3984
|
let route = "";
|
|
@@ -3712,13 +3989,27 @@ function createMarkers(deps) {
|
|
|
3712
3989
|
function injectStyles2() {
|
|
3713
3990
|
if (hasStyles(STYLE_ID9)) return;
|
|
3714
3991
|
addStyles(STYLE_ID9, `
|
|
3992
|
+
/*
|
|
3993
|
+
* Page coordinates: the browser moves these with the page as it
|
|
3994
|
+
* scrolls, so they never trail behind their element. (A fixed layer
|
|
3995
|
+
* repositioned from script lags a frame behind fast scrolling.)
|
|
3996
|
+
*/
|
|
3997
|
+
#${DOC_LAYER_ID} {
|
|
3998
|
+
position: absolute;
|
|
3999
|
+
left: 0;
|
|
4000
|
+
top: 0;
|
|
4001
|
+
width: 0;
|
|
4002
|
+
height: 0;
|
|
4003
|
+
pointer-events: none;
|
|
4004
|
+
z-index: ${Z_INDEX_CROSSHAIR};
|
|
4005
|
+
}
|
|
3715
4006
|
#${LAYER_ID} {
|
|
3716
4007
|
position: fixed;
|
|
3717
4008
|
inset: 0;
|
|
3718
4009
|
pointer-events: none;
|
|
3719
4010
|
z-index: ${Z_INDEX_CROSSHAIR};
|
|
3720
4011
|
}
|
|
3721
|
-
|
|
4012
|
+
.grabby-markers-layer .grabby-marker {
|
|
3722
4013
|
position: absolute;
|
|
3723
4014
|
left: 0;
|
|
3724
4015
|
top: 0;
|
|
@@ -3739,22 +4030,24 @@ function createMarkers(deps) {
|
|
|
3739
4030
|
pointer-events: auto;
|
|
3740
4031
|
transition: transform 0.12s ease, box-shadow 0.15s ease;
|
|
3741
4032
|
}
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
4033
|
+
.grabby-markers-layer .grabby-marker[hidden] { display: none; }
|
|
4034
|
+
/* Several elements or an area: a green square, like the outline it shows. */
|
|
4035
|
+
.grabby-markers-layer .grabby-marker.grabby-marker-group { border-radius: 6px; background: #16a34a; }
|
|
4036
|
+
.grabby-markers-layer .grabby-marker:hover,
|
|
4037
|
+
.grabby-markers-layer .grabby-marker:focus-visible {
|
|
3745
4038
|
z-index: 1;
|
|
3746
4039
|
outline: none;
|
|
3747
4040
|
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);
|
|
3748
4041
|
}
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
4042
|
+
.grabby-markers-layer .grabby-marker-edit { display: none; }
|
|
4043
|
+
.grabby-markers-layer .grabby-marker:hover .grabby-marker-num,
|
|
4044
|
+
.grabby-markers-layer .grabby-marker:focus-visible .grabby-marker-num { display: none; }
|
|
4045
|
+
.grabby-markers-layer .grabby-marker:hover .grabby-marker-edit,
|
|
4046
|
+
.grabby-markers-layer .grabby-marker:focus-visible .grabby-marker-edit { display: block; }
|
|
4047
|
+
.grabby-markers-layer .grabby-marker-in {
|
|
3755
4048
|
animation: grabby-marker-in 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
|
|
3756
4049
|
}
|
|
3757
|
-
|
|
4050
|
+
.grabby-markers-layer .grabby-marker-out {
|
|
3758
4051
|
animation: grabby-marker-out 0.2s ease-out both;
|
|
3759
4052
|
pointer-events: none;
|
|
3760
4053
|
}
|
|
@@ -3788,7 +4081,7 @@ function createMarkers(deps) {
|
|
|
3788
4081
|
to { opacity: 1; transform: none; }
|
|
3789
4082
|
}
|
|
3790
4083
|
@media (prefers-reduced-motion: reduce) {
|
|
3791
|
-
|
|
4084
|
+
.grabby-markers-layer .grabby-marker-in, .grabby-markers-layer .grabby-marker-out, #${TIP_ID} { animation: none; }
|
|
3792
4085
|
}
|
|
3793
4086
|
`);
|
|
3794
4087
|
}
|
|
@@ -3797,11 +4090,15 @@ function createMarkers(deps) {
|
|
|
3797
4090
|
injectStyles2();
|
|
3798
4091
|
layer = document.createElement("div");
|
|
3799
4092
|
layer.id = LAYER_ID;
|
|
4093
|
+
layer.className = "grabby-markers-layer";
|
|
4094
|
+
docLayer = document.createElement("div");
|
|
4095
|
+
docLayer.id = DOC_LAYER_ID;
|
|
4096
|
+
docLayer.className = "grabby-markers-layer";
|
|
3800
4097
|
tip = document.createElement("div");
|
|
3801
4098
|
tip.id = TIP_ID;
|
|
3802
4099
|
tip.hidden = true;
|
|
3803
4100
|
tip.setAttribute("role", "tooltip");
|
|
3804
|
-
getUiRoot().append(layer, tip);
|
|
4101
|
+
getUiRoot().append(docLayer, layer, tip);
|
|
3805
4102
|
return layer;
|
|
3806
4103
|
}
|
|
3807
4104
|
function pageComments() {
|
|
@@ -3819,7 +4116,7 @@ function createMarkers(deps) {
|
|
|
3819
4116
|
button.className = "grabby-marker";
|
|
3820
4117
|
button.dataset.grabbyMarker = comment.id;
|
|
3821
4118
|
button.append(number, svgIcon(ICON_EDIT, "grabby-marker-edit"));
|
|
3822
|
-
const entry = { comment, button, number, element: null, lastLookup: 0 };
|
|
4119
|
+
const entry = { comment, button, number, element: null, lastLookup: 0, context: "page", contextCheckedAt: -Infinity };
|
|
3823
4120
|
button.addEventListener("click", (e) => {
|
|
3824
4121
|
e.preventDefault();
|
|
3825
4122
|
e.stopPropagation();
|
|
@@ -3900,6 +4197,7 @@ function createMarkers(deps) {
|
|
|
3900
4197
|
host2.appendChild(entry.button);
|
|
3901
4198
|
}
|
|
3902
4199
|
entry.comment = comment;
|
|
4200
|
+
entry.button.classList.toggle("grabby-marker-group", !!(comment.members?.length || comment.area));
|
|
3903
4201
|
const n = String(i + 1);
|
|
3904
4202
|
entry.number.textContent = n;
|
|
3905
4203
|
entry.button.setAttribute("aria-label", `Comment ${n}: ${preview(comment.comment)}. Click to edit.`);
|
|
@@ -3923,9 +4221,20 @@ function createMarkers(deps) {
|
|
|
3923
4221
|
entry.button.hidden = true;
|
|
3924
4222
|
continue;
|
|
3925
4223
|
}
|
|
4224
|
+
if (now - entry.contextCheckedAt >= CONTEXT_CHECK_MS) {
|
|
4225
|
+
entry.contextCheckedAt = now;
|
|
4226
|
+
entry.context = scrollContextOf(entry.element);
|
|
4227
|
+
const home = entry.context === "page" ? docLayer : layer;
|
|
4228
|
+
if (home && entry.button.parentElement !== home) home.appendChild(entry.button);
|
|
4229
|
+
}
|
|
3926
4230
|
const pin = entry.comment.pin ?? { x: 1, y: 0 };
|
|
3927
|
-
const
|
|
3928
|
-
|
|
4231
|
+
const maxX = (document.documentElement.clientWidth || window.innerWidth) - SIZE;
|
|
4232
|
+
let x = Math.max(0, Math.min(rect.left + pin.x * rect.width - SIZE / 2, maxX));
|
|
4233
|
+
let y = rect.top + pin.y * rect.height - SIZE / 2;
|
|
4234
|
+
if (entry.context === "page") {
|
|
4235
|
+
x += window.scrollX;
|
|
4236
|
+
y = Math.max(0, y + window.scrollY);
|
|
4237
|
+
}
|
|
3929
4238
|
entry.button.hidden = false;
|
|
3930
4239
|
entry.button.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
|
|
3931
4240
|
}
|
|
@@ -3955,6 +4264,9 @@ function createMarkers(deps) {
|
|
|
3955
4264
|
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
3956
4265
|
rafId = null;
|
|
3957
4266
|
}
|
|
4267
|
+
function handleScroll() {
|
|
4268
|
+
if (visible && entries.size) position(performance.now());
|
|
4269
|
+
}
|
|
3958
4270
|
return {
|
|
3959
4271
|
setVisible(next) {
|
|
3960
4272
|
if (next === visible) return;
|
|
@@ -3962,8 +4274,10 @@ function createMarkers(deps) {
|
|
|
3962
4274
|
if (next) {
|
|
3963
4275
|
route = deps.currentRoute();
|
|
3964
4276
|
lastRouteCheck = performance.now();
|
|
4277
|
+
document.addEventListener("scroll", handleScroll, { capture: true, passive: true });
|
|
3965
4278
|
sync(true);
|
|
3966
4279
|
} else {
|
|
4280
|
+
document.removeEventListener("scroll", handleScroll, true);
|
|
3967
4281
|
stop();
|
|
3968
4282
|
hideTip();
|
|
3969
4283
|
if (hovered) endHover(hovered);
|
|
@@ -3974,12 +4288,15 @@ function createMarkers(deps) {
|
|
|
3974
4288
|
sync(false);
|
|
3975
4289
|
},
|
|
3976
4290
|
isMarkerElement(el) {
|
|
3977
|
-
return
|
|
4291
|
+
return [layer, docLayer].some((l) => !!l && (l === el || l.contains(el)));
|
|
3978
4292
|
},
|
|
3979
4293
|
dispose() {
|
|
3980
4294
|
stop();
|
|
4295
|
+
document.removeEventListener("scroll", handleScroll, true);
|
|
3981
4296
|
entries.clear();
|
|
3982
4297
|
layer?.remove();
|
|
4298
|
+
docLayer?.remove();
|
|
4299
|
+
docLayer = null;
|
|
3983
4300
|
tip?.remove();
|
|
3984
4301
|
layer = null;
|
|
3985
4302
|
tip = null;
|
|
@@ -3990,11 +4307,141 @@ function createMarkers(deps) {
|
|
|
3990
4307
|
};
|
|
3991
4308
|
}
|
|
3992
4309
|
|
|
4310
|
+
// src/core/overlay/group-outline.ts
|
|
4311
|
+
var LAYER_ID2 = "__grabby-group__";
|
|
4312
|
+
var STYLE_ID10 = "__grabby-group-styles__";
|
|
4313
|
+
var GREEN = "#16a34a";
|
|
4314
|
+
function createGroupOutline() {
|
|
4315
|
+
let layer = null;
|
|
4316
|
+
let marqueeEl = null;
|
|
4317
|
+
let labelEl = null;
|
|
4318
|
+
let boxes = [];
|
|
4319
|
+
let spec = null;
|
|
4320
|
+
let rafId = null;
|
|
4321
|
+
function ensureLayer() {
|
|
4322
|
+
if (layer) return layer;
|
|
4323
|
+
if (!hasStyles(STYLE_ID10)) {
|
|
4324
|
+
addStyles(STYLE_ID10, `
|
|
4325
|
+
#${LAYER_ID2} { position: fixed; inset: 0; pointer-events: none; z-index: ${Z_INDEX_OVERLAY}; }
|
|
4326
|
+
#${LAYER_ID2} .grabby-group-box {
|
|
4327
|
+
position: absolute; left: 0; top: 0; box-sizing: border-box;
|
|
4328
|
+
border: 2px dashed ${GREEN}; border-radius: 4px; background: rgba(22, 163, 74, 0.08);
|
|
4329
|
+
}
|
|
4330
|
+
#${LAYER_ID2} .grabby-group-marquee {
|
|
4331
|
+
position: absolute; left: 0; top: 0; box-sizing: border-box;
|
|
4332
|
+
border: 1px solid var(--grabby-accent, #2563eb); border-radius: 2px;
|
|
4333
|
+
background: color-mix(in srgb, var(--grabby-accent, #2563eb) 8%, transparent);
|
|
4334
|
+
}
|
|
4335
|
+
#${LAYER_ID2} .grabby-group-label {
|
|
4336
|
+
position: absolute; left: 0; top: 0; padding: 2px 6px; border-radius: 3px;
|
|
4337
|
+
background: ${GREEN}; color: #fff; white-space: nowrap;
|
|
4338
|
+
font: 600 11px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
4339
|
+
}
|
|
4340
|
+
#${LAYER_ID2} [hidden] { display: none; }
|
|
4341
|
+
`);
|
|
4342
|
+
}
|
|
4343
|
+
layer = document.createElement("div");
|
|
4344
|
+
layer.id = LAYER_ID2;
|
|
4345
|
+
getUiRoot().appendChild(layer);
|
|
4346
|
+
return layer;
|
|
4347
|
+
}
|
|
4348
|
+
function place(el, b) {
|
|
4349
|
+
el.style.transform = `translate(${Math.round(b.left)}px, ${Math.round(b.top)}px)`;
|
|
4350
|
+
el.style.width = `${Math.max(0, Math.round(b.right - b.left))}px`;
|
|
4351
|
+
el.style.height = `${Math.max(0, Math.round(b.bottom - b.top))}px`;
|
|
4352
|
+
}
|
|
4353
|
+
function currentBoxes() {
|
|
4354
|
+
if (!spec) return [];
|
|
4355
|
+
if ("area" in spec) return spec.element.isConnected ? [areaToBox(spec.element, spec.area)] : [];
|
|
4356
|
+
return spec.elements.flatMap((el) => {
|
|
4357
|
+
if (!el.isConnected) return [];
|
|
4358
|
+
const r = el.getBoundingClientRect();
|
|
4359
|
+
return r.width === 0 && r.height === 0 ? [] : [{ left: r.left, top: r.top, right: r.right, bottom: r.bottom }];
|
|
4360
|
+
});
|
|
4361
|
+
}
|
|
4362
|
+
function render() {
|
|
4363
|
+
const host2 = ensureLayer();
|
|
4364
|
+
const list = currentBoxes();
|
|
4365
|
+
while (boxes.length < list.length) {
|
|
4366
|
+
const b = document.createElement("div");
|
|
4367
|
+
b.className = "grabby-group-box";
|
|
4368
|
+
host2.insertBefore(b, labelEl);
|
|
4369
|
+
boxes.push(b);
|
|
4370
|
+
}
|
|
4371
|
+
boxes.forEach((b, i) => {
|
|
4372
|
+
b.hidden = i >= list.length;
|
|
4373
|
+
if (i < list.length) place(b, list[i]);
|
|
4374
|
+
});
|
|
4375
|
+
if (labelEl && !labelEl.hidden) {
|
|
4376
|
+
const u = spec && "elements" in spec ? unionBox(spec.elements) : list[0] ?? null;
|
|
4377
|
+
if (u) labelEl.style.transform = `translate(${Math.round(u.left)}px, ${Math.round(Math.max(0, u.top - 20))}px)`;
|
|
4378
|
+
}
|
|
4379
|
+
}
|
|
4380
|
+
function track() {
|
|
4381
|
+
rafId = null;
|
|
4382
|
+
if (!spec) return;
|
|
4383
|
+
render();
|
|
4384
|
+
rafId = requestAnimationFrame(track);
|
|
4385
|
+
}
|
|
4386
|
+
function stop() {
|
|
4387
|
+
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
4388
|
+
rafId = null;
|
|
4389
|
+
}
|
|
4390
|
+
return {
|
|
4391
|
+
marquee(box) {
|
|
4392
|
+
if (!box) {
|
|
4393
|
+
if (marqueeEl) marqueeEl.hidden = true;
|
|
4394
|
+
return;
|
|
4395
|
+
}
|
|
4396
|
+
const host2 = ensureLayer();
|
|
4397
|
+
if (!marqueeEl) {
|
|
4398
|
+
marqueeEl = document.createElement("div");
|
|
4399
|
+
marqueeEl.className = "grabby-group-marquee";
|
|
4400
|
+
host2.appendChild(marqueeEl);
|
|
4401
|
+
}
|
|
4402
|
+
marqueeEl.hidden = false;
|
|
4403
|
+
place(marqueeEl, box);
|
|
4404
|
+
},
|
|
4405
|
+
show(next, label) {
|
|
4406
|
+
spec = next;
|
|
4407
|
+
const host2 = ensureLayer();
|
|
4408
|
+
if (!labelEl) {
|
|
4409
|
+
labelEl = document.createElement("div");
|
|
4410
|
+
labelEl.className = "grabby-group-label";
|
|
4411
|
+
host2.appendChild(labelEl);
|
|
4412
|
+
}
|
|
4413
|
+
labelEl.hidden = !label;
|
|
4414
|
+
labelEl.textContent = label ?? "";
|
|
4415
|
+
stop();
|
|
4416
|
+
track();
|
|
4417
|
+
},
|
|
4418
|
+
hide() {
|
|
4419
|
+
spec = null;
|
|
4420
|
+
stop();
|
|
4421
|
+
for (const b of boxes) b.hidden = true;
|
|
4422
|
+
if (labelEl) labelEl.hidden = true;
|
|
4423
|
+
},
|
|
4424
|
+
isVisible() {
|
|
4425
|
+
return spec !== null;
|
|
4426
|
+
},
|
|
4427
|
+
dispose() {
|
|
4428
|
+
stop();
|
|
4429
|
+
layer?.remove();
|
|
4430
|
+
layer = null;
|
|
4431
|
+
marqueeEl = null;
|
|
4432
|
+
labelEl = null;
|
|
4433
|
+
boxes = [];
|
|
4434
|
+
spec = null;
|
|
4435
|
+
removeStyles(STYLE_ID10);
|
|
4436
|
+
}
|
|
4437
|
+
};
|
|
4438
|
+
}
|
|
4439
|
+
|
|
3993
4440
|
// src/core/overlay/select-feedback.ts
|
|
3994
|
-
var
|
|
4441
|
+
var STYLE_ID11 = "__grabby-feedback-styles__";
|
|
3995
4442
|
function injectStyles() {
|
|
3996
|
-
if (hasStyles(
|
|
3997
|
-
addStyles(
|
|
4443
|
+
if (hasStyles(STYLE_ID11)) return;
|
|
4444
|
+
addStyles(STYLE_ID11, `
|
|
3998
4445
|
@keyframes grabby-flash {
|
|
3999
4446
|
0% { opacity: 1; }
|
|
4000
4447
|
100% { opacity: 0; transform: scale(1.02); }
|
|
@@ -4073,7 +4520,7 @@ function showSelectFeedback(element, label = "Selected") {
|
|
|
4073
4520
|
setTimeout(cleanup, 1200);
|
|
4074
4521
|
}
|
|
4075
4522
|
function disposeFeedbackStyles() {
|
|
4076
|
-
removeStyles(
|
|
4523
|
+
removeStyles(STYLE_ID11);
|
|
4077
4524
|
}
|
|
4078
4525
|
|
|
4079
4526
|
// src/core/storage/history-persistence.ts
|
|
@@ -4496,6 +4943,21 @@ function captureTarget(el, deps) {
|
|
|
4496
4943
|
extra
|
|
4497
4944
|
};
|
|
4498
4945
|
}
|
|
4946
|
+
var MEMBER_PREVIEW = 120;
|
|
4947
|
+
function captureMember(el, deps) {
|
|
4948
|
+
const cleanClasses = deps.cleanClasses ?? ((list) => list.filter((c) => !isNoiseClass(c)));
|
|
4949
|
+
const kind = detectKind(el);
|
|
4950
|
+
const { component, frames } = resolveStack(el, deps);
|
|
4951
|
+
return {
|
|
4952
|
+
kind,
|
|
4953
|
+
tag: el.tagName.toLowerCase(),
|
|
4954
|
+
component,
|
|
4955
|
+
source: resolveSource2(el, deps, frames),
|
|
4956
|
+
selector: buildUniqueSelector(el),
|
|
4957
|
+
preview: kind === "section" ? `<${el.tagName.toLowerCase()}>` : truncate(buildPreview(el, cleanClasses), MEMBER_PREVIEW),
|
|
4958
|
+
label: describeElement(el)
|
|
4959
|
+
};
|
|
4960
|
+
}
|
|
4499
4961
|
|
|
4500
4962
|
// src/core/capture/screenshot.ts
|
|
4501
4963
|
var MAX_SIDE = 1200;
|
|
@@ -4569,16 +5031,28 @@ function withTimeout(promise, ms) {
|
|
|
4569
5031
|
);
|
|
4570
5032
|
});
|
|
4571
5033
|
}
|
|
4572
|
-
|
|
5034
|
+
var MAX_CLIP_DEPTH = 4e3;
|
|
5035
|
+
var clamp = (v, max) => Math.min(Math.max(v, 0), max);
|
|
5036
|
+
async function captureScreenshot(el, clip) {
|
|
4573
5037
|
if (typeof window === "undefined" || !el.isConnected) return null;
|
|
4574
5038
|
const rect = el.getBoundingClientRect();
|
|
4575
5039
|
if (rect.width < 1 || rect.height < 1) return null;
|
|
4576
|
-
const
|
|
4577
|
-
const
|
|
5040
|
+
const fullWidth = Math.min(rect.width, document.documentElement.scrollWidth || rect.width);
|
|
5041
|
+
const region = clip ? {
|
|
5042
|
+
x: clamp(clip.left - rect.left, fullWidth),
|
|
5043
|
+
y: clamp(clip.top - rect.top, rect.height),
|
|
5044
|
+
right: clamp(clip.right - rect.left, fullWidth),
|
|
5045
|
+
bottom: clamp(clip.bottom - rect.top, rect.height)
|
|
5046
|
+
} : null;
|
|
5047
|
+
if (region && (region.right - region.x < 1 || region.bottom - region.y < 1 || region.bottom > MAX_CLIP_DEPTH)) return null;
|
|
5048
|
+
const cssWidth = fullWidth;
|
|
5049
|
+
const cssHeight = region ? region.bottom : Math.min(rect.height, MAX_CSS_HEIGHT);
|
|
5050
|
+
const outWidth = region ? region.right - region.x : cssWidth;
|
|
5051
|
+
const outHeight = region ? Math.min(region.bottom - region.y, MAX_CSS_HEIGHT) : cssHeight;
|
|
4578
5052
|
const dpr = window.devicePixelRatio || 1;
|
|
4579
|
-
const scale = Math.min(dpr, MAX_SIDE / Math.max(
|
|
5053
|
+
const scale = Math.min(dpr, MAX_SIDE / Math.max(outWidth, outHeight));
|
|
4580
5054
|
const render = async () => {
|
|
4581
|
-
const { createContext, destroyContext, domToBlob } = await import("modern-screenshot");
|
|
5055
|
+
const { createContext, destroyContext, domToBlob, domToCanvas } = await import("modern-screenshot");
|
|
4582
5056
|
const context = await createContext(el, {
|
|
4583
5057
|
width: cssWidth,
|
|
4584
5058
|
height: cssHeight,
|
|
@@ -4595,13 +5069,22 @@ async function captureScreenshot(el) {
|
|
|
4595
5069
|
context.sandbox = await getSandbox();
|
|
4596
5070
|
let blob;
|
|
4597
5071
|
try {
|
|
4598
|
-
|
|
5072
|
+
if (region) {
|
|
5073
|
+
const full = await domToCanvas(context);
|
|
5074
|
+
const crop = document.createElement("canvas");
|
|
5075
|
+
crop.width = Math.max(1, Math.round(outWidth * scale));
|
|
5076
|
+
crop.height = Math.max(1, Math.round(outHeight * scale));
|
|
5077
|
+
crop.getContext("2d")?.drawImage(full, region.x * scale, region.y * scale, outWidth * scale, outHeight * scale, 0, 0, crop.width, crop.height);
|
|
5078
|
+
blob = await new Promise((resolve) => crop.toBlob(resolve, "image/webp", 0.8));
|
|
5079
|
+
} else {
|
|
5080
|
+
blob = await domToBlob(context);
|
|
5081
|
+
}
|
|
4599
5082
|
} finally {
|
|
4600
5083
|
context.sandbox = void 0;
|
|
4601
5084
|
destroyContext(context);
|
|
4602
5085
|
}
|
|
4603
5086
|
if (!blob) return null;
|
|
4604
|
-
return { blob, width: Math.round(
|
|
5087
|
+
return { blob, width: Math.round(outWidth * scale), height: Math.round(outHeight * scale) };
|
|
4605
5088
|
};
|
|
4606
5089
|
return withTimeout(render(), TIMEOUT_MS + 1e3);
|
|
4607
5090
|
}
|
|
@@ -5156,6 +5639,7 @@ function createGrabInstance(options) {
|
|
|
5156
5639
|
}
|
|
5157
5640
|
}
|
|
5158
5641
|
const overlay = createOverlayRenderer({ plainLabels: live });
|
|
5642
|
+
const groupOutline = createGroupOutline();
|
|
5159
5643
|
const crosshair = createCrosshair();
|
|
5160
5644
|
const freezeOverlay = createFreezeOverlay();
|
|
5161
5645
|
const pluginRegistry = createPluginRegistry();
|
|
@@ -5168,6 +5652,9 @@ function createGrabInstance(options) {
|
|
|
5168
5652
|
const cleanClasses = (list) => adapters.cleanClasses(list.filter((c) => !isNoiseClass(c)));
|
|
5169
5653
|
let selectedElement = null;
|
|
5170
5654
|
let selectedPin;
|
|
5655
|
+
let selectedMembers = null;
|
|
5656
|
+
let selectedArea = null;
|
|
5657
|
+
const commentedMembers = /* @__PURE__ */ new Map();
|
|
5171
5658
|
let pendingShot = null;
|
|
5172
5659
|
const commentedElements = /* @__PURE__ */ new Map();
|
|
5173
5660
|
let editingFromMarker = false;
|
|
@@ -5229,7 +5716,9 @@ function createGrabInstance(options) {
|
|
|
5229
5716
|
column: c.target.source?.column ?? null
|
|
5230
5717
|
};
|
|
5231
5718
|
}
|
|
5232
|
-
function saveComment(element, text, shot,
|
|
5719
|
+
function saveComment(element, text, shot, extras = {}) {
|
|
5720
|
+
const { pin, members, area } = extras;
|
|
5721
|
+
const deps = { componentResolver, sourceResolver, cleanClasses };
|
|
5233
5722
|
const now = Date.now();
|
|
5234
5723
|
const comment = {
|
|
5235
5724
|
id: randomId(),
|
|
@@ -5243,13 +5732,16 @@ function createGrabInstance(options) {
|
|
|
5243
5732
|
title: document.title,
|
|
5244
5733
|
viewport: [window.innerWidth, window.innerHeight]
|
|
5245
5734
|
},
|
|
5246
|
-
target: captureTarget(element,
|
|
5735
|
+
target: captureTarget(element, deps),
|
|
5247
5736
|
screenshot: null,
|
|
5248
5737
|
framework: adapters.frameworkFor(element),
|
|
5249
5738
|
...outbox ? { sync: "pending" } : {},
|
|
5250
|
-
...pin ? { pin } : {}
|
|
5739
|
+
...pin ? { pin } : {},
|
|
5740
|
+
...members?.length ? { members: members.map((el) => captureMember(el, deps)) } : {},
|
|
5741
|
+
...area ? { area } : {}
|
|
5251
5742
|
};
|
|
5252
5743
|
commentedElements.set(comment.id, element);
|
|
5744
|
+
if (members?.length) commentedMembers.set(comment.id, members);
|
|
5253
5745
|
setComments([comment, ...comments()].slice(0, MAX_COMMENTS));
|
|
5254
5746
|
pluginRegistry.callHook("onComment", comment, element);
|
|
5255
5747
|
outbox?.send(comment.id);
|
|
@@ -5294,7 +5786,10 @@ function createGrabInstance(options) {
|
|
|
5294
5786
|
const idSet = new Set(ids);
|
|
5295
5787
|
const before = comments();
|
|
5296
5788
|
const removed = before.filter((c) => idSet.has(c.id));
|
|
5297
|
-
for (const id of ids)
|
|
5789
|
+
for (const id of ids) {
|
|
5790
|
+
commentedElements.delete(id);
|
|
5791
|
+
commentedMembers.delete(id);
|
|
5792
|
+
}
|
|
5298
5793
|
setComments(before.filter((c) => !idSet.has(c.id)));
|
|
5299
5794
|
const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
|
|
5300
5795
|
const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
|
|
@@ -5353,16 +5848,52 @@ function createGrabInstance(options) {
|
|
|
5353
5848
|
commentPopover.hide();
|
|
5354
5849
|
endMarkerEdit();
|
|
5355
5850
|
if (picker.isHolding()) {
|
|
5356
|
-
|
|
5357
|
-
selectedPin = void 0;
|
|
5358
|
-
pendingShot = null;
|
|
5851
|
+
clearSelection();
|
|
5359
5852
|
picker.release();
|
|
5360
5853
|
}
|
|
5361
5854
|
}
|
|
5855
|
+
function clearSelection() {
|
|
5856
|
+
selectedElement = null;
|
|
5857
|
+
selectedPin = void 0;
|
|
5858
|
+
selectedMembers = null;
|
|
5859
|
+
selectedArea = null;
|
|
5860
|
+
pendingShot = null;
|
|
5861
|
+
}
|
|
5362
5862
|
function endMarkerEdit() {
|
|
5363
5863
|
if (!editingFromMarker) return;
|
|
5364
5864
|
editingFromMarker = false;
|
|
5365
5865
|
overlay.hide();
|
|
5866
|
+
groupOutline.hide();
|
|
5867
|
+
}
|
|
5868
|
+
function pinIn(el, point) {
|
|
5869
|
+
const rect = el.getBoundingClientRect();
|
|
5870
|
+
const frac2 = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
|
|
5871
|
+
return {
|
|
5872
|
+
x: Math.round(frac2(point.x, rect.left, rect.width) * 1e3) / 1e3,
|
|
5873
|
+
y: Math.round(frac2(point.y, rect.top, rect.height) * 1e3) / 1e3
|
|
5874
|
+
};
|
|
5875
|
+
}
|
|
5876
|
+
function groupSpecFor(comment, element) {
|
|
5877
|
+
if (comment.area && element) return { spec: { element, area: comment.area }, label: "Area" };
|
|
5878
|
+
if (!comment.members?.length) return null;
|
|
5879
|
+
const known = commentedMembers.get(comment.id)?.filter((el) => el.isConnected);
|
|
5880
|
+
const elements = known?.length ? known : comment.members.flatMap((m) => safeQuery(m.selector) ?? []);
|
|
5881
|
+
return elements.length ? { spec: { elements }, label: `${comment.members.length} elements` } : null;
|
|
5882
|
+
}
|
|
5883
|
+
function beginGroupComment(container, point, spec, heading, label, clip) {
|
|
5884
|
+
selectedElement = container;
|
|
5885
|
+
selectedPin = pinIn(container, point);
|
|
5886
|
+
pendingShot = store.state.options.screenshots ? captureScreenshot(container, clip ?? void 0) : null;
|
|
5887
|
+
coachMark.dismiss();
|
|
5888
|
+
picker.hold(container, { spec, label });
|
|
5889
|
+
commentPopover.show({
|
|
5890
|
+
anchor: container,
|
|
5891
|
+
anchorBox: clip,
|
|
5892
|
+
mode: "new",
|
|
5893
|
+
askIdentity: shouldAskIdentity(),
|
|
5894
|
+
heading,
|
|
5895
|
+
placeholder: "What should change here?"
|
|
5896
|
+
});
|
|
5366
5897
|
}
|
|
5367
5898
|
function closeAllPopovers() {
|
|
5368
5899
|
commentsPanel.hide();
|
|
@@ -5390,6 +5921,7 @@ function createGrabInstance(options) {
|
|
|
5390
5921
|
const picker = createElementPicker({
|
|
5391
5922
|
overlay,
|
|
5392
5923
|
crosshair,
|
|
5924
|
+
groupOutline,
|
|
5393
5925
|
getComponentResolver: () => componentResolver,
|
|
5394
5926
|
getSourceResolver: () => sourceResolver,
|
|
5395
5927
|
isToolbarElement: isAnyToolbarElement,
|
|
@@ -5402,18 +5934,24 @@ function createGrabInstance(options) {
|
|
|
5402
5934
|
},
|
|
5403
5935
|
onSelect(element, point) {
|
|
5404
5936
|
selectedElement = element;
|
|
5405
|
-
|
|
5406
|
-
const frac = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
|
|
5407
|
-
selectedPin = {
|
|
5408
|
-
x: Math.round(frac(point.x, rect.left, rect.width) * 1e3) / 1e3,
|
|
5409
|
-
y: Math.round(frac(point.y, rect.top, rect.height) * 1e3) / 1e3
|
|
5410
|
-
};
|
|
5937
|
+
selectedPin = pinIn(element, point);
|
|
5411
5938
|
pendingShot = store.state.options.screenshots ? captureScreenshot(element) : null;
|
|
5412
5939
|
pluginRegistry.callHook("onElementSelect", element);
|
|
5413
5940
|
coachMark.dismiss();
|
|
5414
5941
|
showSelectFeedback(element);
|
|
5415
5942
|
picker.hold(element);
|
|
5416
5943
|
commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
|
|
5944
|
+
},
|
|
5945
|
+
onSelectGroup(elements, point) {
|
|
5946
|
+
selectedMembers = elements;
|
|
5947
|
+
const heading = describeGroup(elements.map(describeElement));
|
|
5948
|
+
for (const el of elements) pluginRegistry.callHook("onElementSelect", el);
|
|
5949
|
+
beginGroupComment(commonContainer(elements), point, { elements }, heading, `${elements.length} elements`, unionBox(elements));
|
|
5950
|
+
},
|
|
5951
|
+
onSelectArea(container, area, point) {
|
|
5952
|
+
selectedArea = area;
|
|
5953
|
+
pluginRegistry.callHook("onElementSelect", container);
|
|
5954
|
+
beginGroupComment(container, point, { element: container, area }, describeArea(describeElement(container)), "Area", areaToBox(container, area));
|
|
5417
5955
|
}
|
|
5418
5956
|
});
|
|
5419
5957
|
const markers = createMarkers({
|
|
@@ -5426,20 +5964,30 @@ function createGrabInstance(options) {
|
|
|
5426
5964
|
},
|
|
5427
5965
|
onHover(comment, element) {
|
|
5428
5966
|
if (picker.isHolding() || editingFromMarker || commentPopover.isVisible()) return;
|
|
5429
|
-
|
|
5430
|
-
|
|
5967
|
+
const group = comment ? groupSpecFor(comment, element) : null;
|
|
5968
|
+
if (group) groupOutline.show(group.spec, group.label);
|
|
5969
|
+
else if (comment && element) overlay.show(element, comment.target.component, null, []);
|
|
5970
|
+
else {
|
|
5971
|
+
overlay.hide();
|
|
5972
|
+
groupOutline.hide();
|
|
5973
|
+
}
|
|
5431
5974
|
},
|
|
5432
5975
|
onOpen(comment, element, marker) {
|
|
5433
5976
|
if (picker.isHolding()) return;
|
|
5434
5977
|
closeAllPopovers();
|
|
5435
5978
|
doDeactivate(true);
|
|
5436
5979
|
editingFromMarker = true;
|
|
5437
|
-
|
|
5980
|
+
const group = groupSpecFor(comment, element);
|
|
5981
|
+
if (group) groupOutline.show(group.spec, group.label);
|
|
5982
|
+
else if (element) overlay.show(element, comment.target.component, null, []);
|
|
5983
|
+
const spec = group?.spec;
|
|
5438
5984
|
commentPopover.show({
|
|
5439
5985
|
anchor: element ?? marker,
|
|
5986
|
+
anchorBox: spec ? "area" in spec ? areaToBox(spec.element, spec.area) : unionBox(spec.elements) : null,
|
|
5440
5987
|
initialValue: comment.comment,
|
|
5441
5988
|
mode: "edit",
|
|
5442
|
-
entryId: comment.id
|
|
5989
|
+
entryId: comment.id,
|
|
5990
|
+
heading: comment.members?.length || comment.area ? describeComment(comment) : void 0
|
|
5443
5991
|
});
|
|
5444
5992
|
}
|
|
5445
5993
|
});
|
|
@@ -5614,12 +6162,10 @@ function createGrabInstance(options) {
|
|
|
5614
6162
|
if (identity) saveIdentity({ name: identity.name, anonymous: !identity.name });
|
|
5615
6163
|
if (ctx.mode === "new") {
|
|
5616
6164
|
const element = selectedElement;
|
|
6165
|
+
const extras = { pin: selectedPin, members: selectedMembers, area: selectedArea };
|
|
5617
6166
|
const shot = pendingShot;
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
selectedPin = void 0;
|
|
5621
|
-
pendingShot = null;
|
|
5622
|
-
if (element) saveComment(element, value, shot, pin);
|
|
6167
|
+
clearSelection();
|
|
6168
|
+
if (element) saveComment(element, value, shot, extras);
|
|
5623
6169
|
doDeactivate(true);
|
|
5624
6170
|
return;
|
|
5625
6171
|
}
|
|
@@ -5635,9 +6181,7 @@ function createGrabInstance(options) {
|
|
|
5635
6181
|
},
|
|
5636
6182
|
onCancel(ctx) {
|
|
5637
6183
|
if (ctx.mode === "new") {
|
|
5638
|
-
|
|
5639
|
-
selectedPin = void 0;
|
|
5640
|
-
pendingShot = null;
|
|
6184
|
+
clearSelection();
|
|
5641
6185
|
doDeactivate(true);
|
|
5642
6186
|
return;
|
|
5643
6187
|
}
|
|
@@ -5803,6 +6347,7 @@ function createGrabInstance(options) {
|
|
|
5803
6347
|
crosshair.dispose();
|
|
5804
6348
|
freezeOverlay.dispose();
|
|
5805
6349
|
markers.dispose();
|
|
6350
|
+
groupOutline.dispose();
|
|
5806
6351
|
disposeToast();
|
|
5807
6352
|
disposeFeedbackStyles();
|
|
5808
6353
|
pluginRegistry.dispose();
|