@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.
@@ -501,6 +501,20 @@ function describeTarget(target) {
501
501
  const name = facts.label || facts.heading || facts.text || facts.alt || "";
502
502
  return quoted(noun, name);
503
503
  }
504
+ var GROUP_NAMED = 3;
505
+ function describeGroup(labels) {
506
+ const named = labels.slice(0, GROUP_NAMED).join(", ");
507
+ const more = labels.length > GROUP_NAMED ? ` and ${labels.length - GROUP_NAMED} more` : "";
508
+ return `${labels.length} elements: ${named}${more}`;
509
+ }
510
+ function describeArea(around) {
511
+ return `Area in ${around}`;
512
+ }
513
+ function describeComment(c) {
514
+ if (c.members?.length) return describeGroup(c.members.map((m) => m.label));
515
+ if (c.area) return describeArea(describeTarget(c.target));
516
+ return describeTarget(c.target);
517
+ }
504
518
 
505
519
  // src/core/overlay/overlay-renderer.ts
506
520
  var OVERLAY_ID = "__grabby-overlay__";
@@ -1151,11 +1165,114 @@ function buildUniqueSelector(el) {
1151
1165
  return steps.join(" > ");
1152
1166
  }
1153
1167
 
1168
+ // src/core/picker/region.ts
1169
+ var MAX_MEMBERS = 20;
1170
+ var INSIDE_RATIO = 0.85;
1171
+ var MIN_SIDE = 4;
1172
+ var MAX_VISITS = 4e3;
1173
+ var SKIP_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "HEAD", "META", "LINK", "BR", "WBR"]);
1174
+ function boxFromPoints(a, b) {
1175
+ 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) };
1176
+ }
1177
+ function overlapArea(r, box) {
1178
+ const w = Math.min(r.right, box.right) - Math.max(r.left, box.left);
1179
+ const h2 = Math.min(r.bottom, box.bottom) - Math.max(r.top, box.top);
1180
+ return w > 0 && h2 > 0 ? w * h2 : 0;
1181
+ }
1182
+ function contains(r, box) {
1183
+ return r.left <= box.left && r.top <= box.top && r.right >= box.right && r.bottom >= box.bottom;
1184
+ }
1185
+ function isHidden(el) {
1186
+ const style = getComputedStyle(el);
1187
+ return style.visibility === "hidden" || style.opacity === "0";
1188
+ }
1189
+ function elementsInBox(box, isUiNode2, root2 = document.body) {
1190
+ const found = [];
1191
+ let visits = 0;
1192
+ const visit = (el) => {
1193
+ if (found.length >= MAX_MEMBERS || ++visits > MAX_VISITS) return;
1194
+ if (SKIP_TAGS.has(el.tagName) || isUiNode2(el) || el.hasAttribute(IGNORE_ATTR)) return;
1195
+ const r = el.getBoundingClientRect();
1196
+ const boxless = r.width === 0 && r.height === 0;
1197
+ if (!boxless && overlapArea(r, box) === 0) return;
1198
+ if (!boxless && r.width >= MIN_SIDE && r.height >= MIN_SIDE) {
1199
+ const inside = overlapArea(r, box) / (r.width * r.height);
1200
+ if (inside >= INSIDE_RATIO && detectKind(el) !== "section" && !isHidden(el)) {
1201
+ found.push(el);
1202
+ return;
1203
+ }
1204
+ }
1205
+ for (const child of Array.from(el.children)) visit(child);
1206
+ };
1207
+ for (const child of Array.from(root2.children)) visit(child);
1208
+ return found;
1209
+ }
1210
+ function commonContainer(elements) {
1211
+ if (elements.length === 0) return document.body;
1212
+ let candidate = elements[0].parentElement ?? document.body;
1213
+ while (candidate && !elements.every((el) => candidate.contains(el))) candidate = candidate.parentElement;
1214
+ return candidate ?? document.body;
1215
+ }
1216
+ function containerForBox(box, isUiNode2) {
1217
+ const cx = (box.left + box.right) / 2;
1218
+ const cy = (box.top + box.bottom) / 2;
1219
+ const stack = typeof document.elementsFromPoint === "function" ? document.elementsFromPoint(cx, cy) : [];
1220
+ for (const el of stack) {
1221
+ if (isUiNode2(el) || el.closest(`[${IGNORE_ATTR}]`)) continue;
1222
+ for (let cur = el; cur; cur = cur.parentElement) {
1223
+ if (contains(cur.getBoundingClientRect(), box)) return cur;
1224
+ }
1225
+ }
1226
+ return document.body;
1227
+ }
1228
+ var frac = (v) => Math.round(Math.min(1, Math.max(0, v)) * 1e3) / 1e3;
1229
+ function areaWithin(el, box) {
1230
+ const r = el.getBoundingClientRect();
1231
+ const w = r.width || 1;
1232
+ const h2 = r.height || 1;
1233
+ return {
1234
+ x: frac((box.left - r.left) / w),
1235
+ y: frac((box.top - r.top) / h2),
1236
+ w: frac((box.right - box.left) / w),
1237
+ h: frac((box.bottom - box.top) / h2)
1238
+ };
1239
+ }
1240
+ function areaToBox(el, area) {
1241
+ const r = el.getBoundingClientRect();
1242
+ return {
1243
+ left: r.left + area.x * r.width,
1244
+ top: r.top + area.y * r.height,
1245
+ right: r.left + (area.x + area.w) * r.width,
1246
+ bottom: r.top + (area.y + area.h) * r.height
1247
+ };
1248
+ }
1249
+ function unionBox(elements) {
1250
+ let out = null;
1251
+ for (const el of elements) {
1252
+ const r = el.getBoundingClientRect();
1253
+ if (r.width === 0 && r.height === 0) continue;
1254
+ 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 };
1255
+ }
1256
+ return out;
1257
+ }
1258
+
1154
1259
  // src/core/picker/element-picker.ts
1260
+ var DRAG_PX = 6;
1261
+ var IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
1262
+ var PRESS_EVENTS = ["pointerdown", "mousedown", "pointerup", "mouseup", "touchstart"];
1263
+ function addKey(e) {
1264
+ return IS_MAC ? e.metaKey : e.ctrlKey;
1265
+ }
1155
1266
  function createElementPicker(deps) {
1156
1267
  let hoveredElement = null;
1157
1268
  let heldElement = null;
1158
1269
  let listening = false;
1270
+ let press = null;
1271
+ let dragBox = null;
1272
+ let dragFrame = null;
1273
+ let lastPoint = { x: 0, y: 0 };
1274
+ let swallowNextClick = false;
1275
+ let collected = [];
1159
1276
  function resolveComponentName(el) {
1160
1277
  const resolver = deps.getComponentResolver();
1161
1278
  if (!resolver) return null;
@@ -1185,14 +1302,93 @@ function createElementPicker(deps) {
1185
1302
  if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
1186
1303
  return exact ? raw : promoteTarget(raw);
1187
1304
  }
1305
+ function isOurs(el) {
1306
+ return !!deps.isToolbarElement?.(el) || deps.overlay.isOverlayElement(el) || deps.crosshair.isCrosshairElement(el);
1307
+ }
1188
1308
  function showOverlay(target) {
1189
1309
  const componentName = resolveComponentName(target);
1190
1310
  const sourcePath = resolveSourcePath(target);
1191
1311
  const cssClasses = filterAngularClasses(target.classList);
1192
1312
  deps.overlay.show(target, componentName, sourcePath, cssClasses);
1193
1313
  }
1314
+ const countLabel = (n) => `${n} element${n === 1 ? "" : "s"}`;
1315
+ function showCollected() {
1316
+ if (collected.length) {
1317
+ deps.groupOutline.show({ elements: collected }, `${countLabel(collected.length)} \xB7 release ${IS_MAC ? "\u2318" : "Ctrl"} to comment`);
1318
+ } else {
1319
+ deps.groupOutline.hide();
1320
+ }
1321
+ }
1322
+ function clearCollected() {
1323
+ if (!collected.length) return;
1324
+ collected = [];
1325
+ deps.groupOutline.hide();
1326
+ }
1327
+ function previewDrag() {
1328
+ dragFrame = null;
1329
+ if (!dragBox) return;
1330
+ deps.groupOutline.marquee(dragBox);
1331
+ const found = elementsInBox(dragBox, isOurs);
1332
+ if (found.length) deps.groupOutline.show({ elements: found }, countLabel(found.length));
1333
+ else deps.groupOutline.hide();
1334
+ }
1335
+ function endDrag() {
1336
+ dragBox = null;
1337
+ if (dragFrame !== null) cancelAnimationFrame(dragFrame);
1338
+ dragFrame = null;
1339
+ deps.groupOutline.marquee(null);
1340
+ deps.groupOutline.hide();
1341
+ }
1342
+ function finishDrag(point) {
1343
+ const box = dragBox;
1344
+ endDrag();
1345
+ const found = elementsInBox(box, isOurs);
1346
+ if (found.length === 1) {
1347
+ hoveredElement = found[0];
1348
+ deps.onSelect(found[0], point);
1349
+ } else if (found.length > 1) {
1350
+ deps.onSelectGroup(found, point);
1351
+ } else {
1352
+ const container = containerForBox(box, isOurs);
1353
+ deps.onSelectArea(container, areaWithin(container, box), point);
1354
+ }
1355
+ }
1356
+ function handlePress(e) {
1357
+ const origin = eventTarget(e);
1358
+ if (origin && deps.isToolbarElement?.(origin)) return;
1359
+ e.stopPropagation();
1360
+ if (e.type === "mousedown" || e.type === "touchstart") e.preventDefault();
1361
+ if (heldElement) return;
1362
+ const m = e;
1363
+ const down = e.type === "pointerdown" || e.type === "mousedown";
1364
+ if (down && m.button === 0 && !press) {
1365
+ press = { x: m.clientX, y: m.clientY };
1366
+ swallowNextClick = false;
1367
+ } else if (!down && e.type !== "touchstart" && press) {
1368
+ const point = { x: m.clientX, y: m.clientY };
1369
+ const start = press;
1370
+ press = null;
1371
+ if (dragBox) {
1372
+ dragBox = boxFromPoints(start, point);
1373
+ swallowNextClick = true;
1374
+ finishDrag(point);
1375
+ }
1376
+ }
1377
+ }
1194
1378
  function handleMouseMove(e) {
1195
1379
  if (heldElement) return;
1380
+ lastPoint = { x: e.clientX, y: e.clientY };
1381
+ if (press) {
1382
+ if (!dragBox && Math.hypot(e.clientX - press.x, e.clientY - press.y) < DRAG_PX) return;
1383
+ if (!dragBox) {
1384
+ clearCollected();
1385
+ deps.overlay.hide();
1386
+ hoveredElement = null;
1387
+ }
1388
+ dragBox = boxFromPoints(press, lastPoint);
1389
+ if (dragFrame === null) dragFrame = requestAnimationFrame(previewDrag);
1390
+ return;
1391
+ }
1196
1392
  const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
1197
1393
  if (!target || deps.overlay.isOverlayElement(target)) return;
1198
1394
  if (deps.crosshair.isCrosshairElement(target)) return;
@@ -1210,8 +1406,32 @@ function createElementPicker(deps) {
1210
1406
  e.preventDefault();
1211
1407
  e.stopPropagation();
1212
1408
  if (heldElement) return;
1213
- if (hoveredElement) {
1214
- deps.onSelect(hoveredElement, { x: e.clientX, y: e.clientY });
1409
+ if (swallowNextClick) {
1410
+ swallowNextClick = false;
1411
+ return;
1412
+ }
1413
+ if (!hoveredElement) return;
1414
+ lastPoint = { x: e.clientX, y: e.clientY };
1415
+ if (addKey(e)) {
1416
+ const at = collected.indexOf(hoveredElement);
1417
+ if (at >= 0) collected.splice(at, 1);
1418
+ else if (collected.length < MAX_MEMBERS) collected.push(hoveredElement);
1419
+ showCollected();
1420
+ return;
1421
+ }
1422
+ clearCollected();
1423
+ deps.onSelect(hoveredElement, lastPoint);
1424
+ }
1425
+ function handleKeyUp(e) {
1426
+ if (e.key !== (IS_MAC ? "Meta" : "Control") || !collected.length || heldElement) return;
1427
+ const elements = collected;
1428
+ collected = [];
1429
+ deps.groupOutline.hide();
1430
+ if (elements.length === 1) {
1431
+ hoveredElement = elements[0];
1432
+ deps.onSelect(elements[0], lastPoint);
1433
+ } else {
1434
+ deps.onSelectGroup(elements, lastPoint);
1215
1435
  }
1216
1436
  }
1217
1437
  return {
@@ -1219,31 +1439,46 @@ function createElementPicker(deps) {
1219
1439
  if (listening) return;
1220
1440
  listening = true;
1221
1441
  deps.crosshair.activate();
1442
+ for (const type of PRESS_EVENTS) window.addEventListener(type, handlePress, { capture: true, passive: false });
1222
1443
  document.addEventListener("mousemove", handleMouseMove, true);
1223
1444
  document.addEventListener("click", handleClick, true);
1445
+ window.addEventListener("keyup", handleKeyUp, true);
1224
1446
  },
1225
1447
  deactivate() {
1226
1448
  if (!listening) return;
1227
1449
  listening = false;
1228
1450
  hoveredElement = null;
1229
1451
  heldElement = null;
1452
+ press = null;
1453
+ swallowNextClick = false;
1454
+ collected = [];
1455
+ endDrag();
1230
1456
  deps.crosshair.hold(false);
1231
1457
  deps.crosshair.deactivate();
1458
+ for (const type of PRESS_EVENTS) window.removeEventListener(type, handlePress, true);
1232
1459
  document.removeEventListener("mousemove", handleMouseMove, true);
1233
1460
  document.removeEventListener("click", handleClick, true);
1461
+ window.removeEventListener("keyup", handleKeyUp, true);
1234
1462
  deps.overlay.hide();
1235
1463
  deps.onHover(null);
1236
1464
  },
1237
- hold(element) {
1465
+ hold(element, group) {
1238
1466
  if (!listening) return;
1239
1467
  heldElement = element;
1240
1468
  hoveredElement = element;
1469
+ press = null;
1241
1470
  deps.crosshair.hold(true);
1242
- showOverlay(element);
1471
+ if (group) {
1472
+ deps.overlay.hide();
1473
+ deps.groupOutline.show(group.spec, group.label);
1474
+ } else {
1475
+ showOverlay(element);
1476
+ }
1243
1477
  },
1244
1478
  release() {
1245
1479
  if (!heldElement) return;
1246
1480
  heldElement = null;
1481
+ deps.groupOutline.hide();
1247
1482
  deps.crosshair.hold(false);
1248
1483
  },
1249
1484
  isHolding() {
@@ -1994,10 +2229,15 @@ function header(comments, env, ctx) {
1994
2229
  }
1995
2230
  return lines;
1996
2231
  }
2232
+ var pct = (v) => `${Math.round(v * 100)}%`;
2233
+ function memberRefs(c, full) {
2234
+ return (c.members ?? []).map((m) => m.source ? location2(m.source.file, m.source.line, full) : m.selector).join(", ");
2235
+ }
1997
2236
  function compactLine(c, i, ctx) {
1998
2237
  const t = c.target;
1999
2238
  const where = t.source ? location2(t.source.file, t.source.line, true) : t.selector;
2000
- const parts = [where, t.component, `<${t.tag}>`].filter(Boolean).join(" ");
2239
+ const own = [where, t.component, `<${t.tag}>`].filter(Boolean).join(" ");
2240
+ const parts = c.members?.length ? `[${c.members.length} elements] ${memberRefs(c, true)}` : c.area ? `[area] in ${own}` : own;
2001
2241
  const who = ctx.showAuthors ? ` (${authorLabel(c.author)})` : "";
2002
2242
  const route = ctx.showRoutes ? ` [${c.page.route}]` : "";
2003
2243
  const id = ctx.showIds ? ` [id ${c.id}]` : "";
@@ -2014,7 +2254,20 @@ function detailBlock(c, i, ctx, groupHasSource, headedComponent) {
2014
2254
  } else if (t.source?.line != null && groupHasSource) {
2015
2255
  where.push(`line ${t.source.line}`);
2016
2256
  }
2257
+ if (c.members?.length) where.unshift("in");
2258
+ if (c.area) where.unshift("area in");
2017
2259
  b(where.join(" "));
2260
+ if (c.area) {
2261
+ const a = c.area;
2262
+ b(`region: ${pct(a.x)} from left, ${pct(a.y)} from top, ${pct(a.w)} wide, ${pct(a.h)} tall`);
2263
+ }
2264
+ if (c.members?.length) {
2265
+ b(`${c.members.length} elements:`);
2266
+ for (const m of c.members) {
2267
+ const at = m.source ? location2(m.source.file, m.source.line, full) : `selector \`${m.selector}\``;
2268
+ lines.push(` - \`${m.preview}\` (${m.kind})${m.component && m.component !== t.component ? ` ${m.component}` : ""} ${at}`);
2269
+ }
2270
+ }
2018
2271
  if (!t.source || full) b(`selector: \`${t.selector}\``);
2019
2272
  const plain = Object.entries(t.facts).filter(([k, v]) => !STYLE_FACTS.has(k) && !(PREVIEW_FACTS.has(k) && !full && inPreview(t.preview, v)));
2020
2273
  if (plain.length) b(plain.map(([k, v]) => `${k}: ${v}`).join(" \xB7 "));
@@ -2276,7 +2529,8 @@ function createCommentsPanel(callbacks, options = {}) {
2276
2529
  }
2277
2530
  function row2(comment, showAuthors) {
2278
2531
  const t = comment.target;
2279
- const meta = live ? [document.createTextNode(`${describeTarget(t)} `)] : [h("span", { class: "grabby-kind" }, t.kind)];
2532
+ const group = comment.members?.length ? `${comment.members.length} elements` : comment.area ? "area" : null;
2533
+ const meta = live ? [document.createTextNode(`${describeComment(comment)} `)] : [h("span", { class: "grabby-kind" }, group ?? t.kind)];
2280
2534
  if (!live) {
2281
2535
  if (t.component) meta.push(document.createTextNode(`${t.component} `));
2282
2536
  if (t.source) {
@@ -2506,6 +2760,13 @@ function createCommentPopover(callbacks) {
2506
2760
  font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding: 8px 4px; border: none;
2507
2761
  background: transparent; color: var(--grabby-text-muted, #64748b); cursor: pointer; text-decoration: underline;
2508
2762
  }
2763
+ #${POPOVER_ID} .grabby-cp-heading {
2764
+ font: 600 12px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
2765
+ color: #15803d;
2766
+ overflow: hidden;
2767
+ text-overflow: ellipsis;
2768
+ white-space: nowrap;
2769
+ }
2509
2770
  #${POPOVER_ID} .grabby-cp-edit-actions { display: flex; align-items: center; gap: 6px; }
2510
2771
  #${POPOVER_ID} .grabby-cp-edit-actions .grabby-cp-spacer { flex: 1; }
2511
2772
  #${POPOVER_ID} .grabby-cp-delete {
@@ -2544,18 +2805,18 @@ function createCommentPopover(callbacks) {
2544
2805
  getUiRoot().appendChild(popover);
2545
2806
  return popover;
2546
2807
  }
2547
- function position(el, anchor) {
2808
+ function position(el, anchor, box) {
2548
2809
  const vw = window.innerWidth;
2549
2810
  const vh = window.innerHeight;
2550
2811
  const fW = 300;
2551
2812
  const fH = 120;
2552
- if (!anchor) {
2813
+ if (!anchor && !box) {
2553
2814
  el.style.left = "50%";
2554
2815
  el.style.top = "24px";
2555
2816
  el.style.transform = "translateX(-50%)";
2556
2817
  return;
2557
2818
  }
2558
- const rect = anchor.getBoundingClientRect();
2819
+ const rect = box ? { ...box, width: box.right - box.left, height: box.bottom - box.top } : anchor.getBoundingClientRect();
2559
2820
  let left;
2560
2821
  let top;
2561
2822
  if (rect.right + 16 + fW <= vw) {
@@ -2709,8 +2970,12 @@ function createCommentPopover(callbacks) {
2709
2970
  currentCtx = { mode: opts.mode, entryId: opts.entryId };
2710
2971
  askIdentity = opts.askIdentity === true && opts.mode === "new";
2711
2972
  visible = true;
2973
+ textarea.placeholder = opts.placeholder ?? "What should change here?";
2974
+ if (opts.heading) {
2975
+ el.prepend(h("div", { class: "grabby-cp-heading", title: opts.heading }, opts.heading));
2976
+ }
2712
2977
  if (opts.mode === "edit") el.appendChild(editActions());
2713
- position(el, opts.anchor);
2978
+ position(el, opts.anchor, opts.anchorBox);
2714
2979
  attachKey();
2715
2980
  textarea?.focus();
2716
2981
  requestAnimationFrame(() => textarea?.focus());
@@ -3595,6 +3860,8 @@ function createFreezeOverlay() {
3595
3860
 
3596
3861
  // src/core/overlay/markers.ts
3597
3862
  var LAYER_ID = "__grabby-markers__";
3863
+ var DOC_LAYER_ID = "__grabby-markers-doc__";
3864
+ var CONTEXT_CHECK_MS = 1e3;
3598
3865
  var TIP_ID = "__grabby-marker-tip__";
3599
3866
  var STYLE_ID9 = "__grabby-marker-styles__";
3600
3867
  var SIZE = 22;
@@ -3606,8 +3873,18 @@ var ICON_EDIT = {
3606
3873
  size: 12,
3607
3874
  shapes: paths("M10.5 2.5l3 3L6 13H3v-3z", "M9 4l3 3")
3608
3875
  };
3876
+ function scrollContextOf(el) {
3877
+ for (let cur = el.parentElement; cur && cur !== document.body && cur !== document.documentElement; cur = cur.parentElement) {
3878
+ const style = getComputedStyle(cur);
3879
+ if (style.position === "fixed" || style.position === "sticky") return "screen";
3880
+ if (/(auto|scroll|overlay)/.test(style.overflowY + style.overflowX)) return "screen";
3881
+ }
3882
+ const own = getComputedStyle(el).position;
3883
+ return own === "fixed" || own === "sticky" ? "screen" : "page";
3884
+ }
3609
3885
  function createMarkers(deps) {
3610
3886
  let layer = null;
3887
+ let docLayer = null;
3611
3888
  let tip = null;
3612
3889
  let visible = false;
3613
3890
  let route = "";
@@ -3618,13 +3895,27 @@ function createMarkers(deps) {
3618
3895
  function injectStyles2() {
3619
3896
  if (hasStyles(STYLE_ID9)) return;
3620
3897
  addStyles(STYLE_ID9, `
3898
+ /*
3899
+ * Page coordinates: the browser moves these with the page as it
3900
+ * scrolls, so they never trail behind their element. (A fixed layer
3901
+ * repositioned from script lags a frame behind fast scrolling.)
3902
+ */
3903
+ #${DOC_LAYER_ID} {
3904
+ position: absolute;
3905
+ left: 0;
3906
+ top: 0;
3907
+ width: 0;
3908
+ height: 0;
3909
+ pointer-events: none;
3910
+ z-index: ${Z_INDEX_CROSSHAIR};
3911
+ }
3621
3912
  #${LAYER_ID} {
3622
3913
  position: fixed;
3623
3914
  inset: 0;
3624
3915
  pointer-events: none;
3625
3916
  z-index: ${Z_INDEX_CROSSHAIR};
3626
3917
  }
3627
- #${LAYER_ID} .grabby-marker {
3918
+ .grabby-markers-layer .grabby-marker {
3628
3919
  position: absolute;
3629
3920
  left: 0;
3630
3921
  top: 0;
@@ -3645,22 +3936,24 @@ function createMarkers(deps) {
3645
3936
  pointer-events: auto;
3646
3937
  transition: transform 0.12s ease, box-shadow 0.15s ease;
3647
3938
  }
3648
- #${LAYER_ID} .grabby-marker[hidden] { display: none; }
3649
- #${LAYER_ID} .grabby-marker:hover,
3650
- #${LAYER_ID} .grabby-marker:focus-visible {
3939
+ .grabby-markers-layer .grabby-marker[hidden] { display: none; }
3940
+ /* Several elements or an area: a green square, like the outline it shows. */
3941
+ .grabby-markers-layer .grabby-marker.grabby-marker-group { border-radius: 6px; background: #16a34a; }
3942
+ .grabby-markers-layer .grabby-marker:hover,
3943
+ .grabby-markers-layer .grabby-marker:focus-visible {
3651
3944
  z-index: 1;
3652
3945
  outline: none;
3653
3946
  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);
3654
3947
  }
3655
- #${LAYER_ID} .grabby-marker-edit { display: none; }
3656
- #${LAYER_ID} .grabby-marker:hover .grabby-marker-num,
3657
- #${LAYER_ID} .grabby-marker:focus-visible .grabby-marker-num { display: none; }
3658
- #${LAYER_ID} .grabby-marker:hover .grabby-marker-edit,
3659
- #${LAYER_ID} .grabby-marker:focus-visible .grabby-marker-edit { display: block; }
3660
- #${LAYER_ID} .grabby-marker-in {
3948
+ .grabby-markers-layer .grabby-marker-edit { display: none; }
3949
+ .grabby-markers-layer .grabby-marker:hover .grabby-marker-num,
3950
+ .grabby-markers-layer .grabby-marker:focus-visible .grabby-marker-num { display: none; }
3951
+ .grabby-markers-layer .grabby-marker:hover .grabby-marker-edit,
3952
+ .grabby-markers-layer .grabby-marker:focus-visible .grabby-marker-edit { display: block; }
3953
+ .grabby-markers-layer .grabby-marker-in {
3661
3954
  animation: grabby-marker-in 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
3662
3955
  }
3663
- #${LAYER_ID} .grabby-marker-out {
3956
+ .grabby-markers-layer .grabby-marker-out {
3664
3957
  animation: grabby-marker-out 0.2s ease-out both;
3665
3958
  pointer-events: none;
3666
3959
  }
@@ -3694,7 +3987,7 @@ function createMarkers(deps) {
3694
3987
  to { opacity: 1; transform: none; }
3695
3988
  }
3696
3989
  @media (prefers-reduced-motion: reduce) {
3697
- #${LAYER_ID} .grabby-marker-in, #${LAYER_ID} .grabby-marker-out, #${TIP_ID} { animation: none; }
3990
+ .grabby-markers-layer .grabby-marker-in, .grabby-markers-layer .grabby-marker-out, #${TIP_ID} { animation: none; }
3698
3991
  }
3699
3992
  `);
3700
3993
  }
@@ -3703,11 +3996,15 @@ function createMarkers(deps) {
3703
3996
  injectStyles2();
3704
3997
  layer = document.createElement("div");
3705
3998
  layer.id = LAYER_ID;
3999
+ layer.className = "grabby-markers-layer";
4000
+ docLayer = document.createElement("div");
4001
+ docLayer.id = DOC_LAYER_ID;
4002
+ docLayer.className = "grabby-markers-layer";
3706
4003
  tip = document.createElement("div");
3707
4004
  tip.id = TIP_ID;
3708
4005
  tip.hidden = true;
3709
4006
  tip.setAttribute("role", "tooltip");
3710
- getUiRoot().append(layer, tip);
4007
+ getUiRoot().append(docLayer, layer, tip);
3711
4008
  return layer;
3712
4009
  }
3713
4010
  function pageComments() {
@@ -3725,7 +4022,7 @@ function createMarkers(deps) {
3725
4022
  button.className = "grabby-marker";
3726
4023
  button.dataset.grabbyMarker = comment.id;
3727
4024
  button.append(number, svgIcon(ICON_EDIT, "grabby-marker-edit"));
3728
- const entry = { comment, button, number, element: null, lastLookup: 0 };
4025
+ const entry = { comment, button, number, element: null, lastLookup: 0, context: "page", contextCheckedAt: -Infinity };
3729
4026
  button.addEventListener("click", (e) => {
3730
4027
  e.preventDefault();
3731
4028
  e.stopPropagation();
@@ -3806,6 +4103,7 @@ function createMarkers(deps) {
3806
4103
  host2.appendChild(entry.button);
3807
4104
  }
3808
4105
  entry.comment = comment;
4106
+ entry.button.classList.toggle("grabby-marker-group", !!(comment.members?.length || comment.area));
3809
4107
  const n = String(i + 1);
3810
4108
  entry.number.textContent = n;
3811
4109
  entry.button.setAttribute("aria-label", `Comment ${n}: ${preview(comment.comment)}. Click to edit.`);
@@ -3829,9 +4127,20 @@ function createMarkers(deps) {
3829
4127
  entry.button.hidden = true;
3830
4128
  continue;
3831
4129
  }
4130
+ if (now - entry.contextCheckedAt >= CONTEXT_CHECK_MS) {
4131
+ entry.contextCheckedAt = now;
4132
+ entry.context = scrollContextOf(entry.element);
4133
+ const home = entry.context === "page" ? docLayer : layer;
4134
+ if (home && entry.button.parentElement !== home) home.appendChild(entry.button);
4135
+ }
3832
4136
  const pin = entry.comment.pin ?? { x: 1, y: 0 };
3833
- const x = rect.left + pin.x * rect.width - SIZE / 2;
3834
- const y = rect.top + pin.y * rect.height - SIZE / 2;
4137
+ const maxX = (document.documentElement.clientWidth || window.innerWidth) - SIZE;
4138
+ let x = Math.max(0, Math.min(rect.left + pin.x * rect.width - SIZE / 2, maxX));
4139
+ let y = rect.top + pin.y * rect.height - SIZE / 2;
4140
+ if (entry.context === "page") {
4141
+ x += window.scrollX;
4142
+ y = Math.max(0, y + window.scrollY);
4143
+ }
3835
4144
  entry.button.hidden = false;
3836
4145
  entry.button.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
3837
4146
  }
@@ -3861,6 +4170,9 @@ function createMarkers(deps) {
3861
4170
  if (rafId !== null) cancelAnimationFrame(rafId);
3862
4171
  rafId = null;
3863
4172
  }
4173
+ function handleScroll() {
4174
+ if (visible && entries.size) position(performance.now());
4175
+ }
3864
4176
  return {
3865
4177
  setVisible(next) {
3866
4178
  if (next === visible) return;
@@ -3868,8 +4180,10 @@ function createMarkers(deps) {
3868
4180
  if (next) {
3869
4181
  route = deps.currentRoute();
3870
4182
  lastRouteCheck = performance.now();
4183
+ document.addEventListener("scroll", handleScroll, { capture: true, passive: true });
3871
4184
  sync(true);
3872
4185
  } else {
4186
+ document.removeEventListener("scroll", handleScroll, true);
3873
4187
  stop();
3874
4188
  hideTip();
3875
4189
  if (hovered) endHover(hovered);
@@ -3880,12 +4194,15 @@ function createMarkers(deps) {
3880
4194
  sync(false);
3881
4195
  },
3882
4196
  isMarkerElement(el) {
3883
- return !!layer && (layer === el || layer.contains(el));
4197
+ return [layer, docLayer].some((l) => !!l && (l === el || l.contains(el)));
3884
4198
  },
3885
4199
  dispose() {
3886
4200
  stop();
4201
+ document.removeEventListener("scroll", handleScroll, true);
3887
4202
  entries.clear();
3888
4203
  layer?.remove();
4204
+ docLayer?.remove();
4205
+ docLayer = null;
3889
4206
  tip?.remove();
3890
4207
  layer = null;
3891
4208
  tip = null;
@@ -3896,11 +4213,141 @@ function createMarkers(deps) {
3896
4213
  };
3897
4214
  }
3898
4215
 
4216
+ // src/core/overlay/group-outline.ts
4217
+ var LAYER_ID2 = "__grabby-group__";
4218
+ var STYLE_ID10 = "__grabby-group-styles__";
4219
+ var GREEN = "#16a34a";
4220
+ function createGroupOutline() {
4221
+ let layer = null;
4222
+ let marqueeEl = null;
4223
+ let labelEl = null;
4224
+ let boxes = [];
4225
+ let spec = null;
4226
+ let rafId = null;
4227
+ function ensureLayer() {
4228
+ if (layer) return layer;
4229
+ if (!hasStyles(STYLE_ID10)) {
4230
+ addStyles(STYLE_ID10, `
4231
+ #${LAYER_ID2} { position: fixed; inset: 0; pointer-events: none; z-index: ${Z_INDEX_OVERLAY}; }
4232
+ #${LAYER_ID2} .grabby-group-box {
4233
+ position: absolute; left: 0; top: 0; box-sizing: border-box;
4234
+ border: 2px dashed ${GREEN}; border-radius: 4px; background: rgba(22, 163, 74, 0.08);
4235
+ }
4236
+ #${LAYER_ID2} .grabby-group-marquee {
4237
+ position: absolute; left: 0; top: 0; box-sizing: border-box;
4238
+ border: 1px solid var(--grabby-accent, #2563eb); border-radius: 2px;
4239
+ background: color-mix(in srgb, var(--grabby-accent, #2563eb) 8%, transparent);
4240
+ }
4241
+ #${LAYER_ID2} .grabby-group-label {
4242
+ position: absolute; left: 0; top: 0; padding: 2px 6px; border-radius: 3px;
4243
+ background: ${GREEN}; color: #fff; white-space: nowrap;
4244
+ font: 600 11px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
4245
+ }
4246
+ #${LAYER_ID2} [hidden] { display: none; }
4247
+ `);
4248
+ }
4249
+ layer = document.createElement("div");
4250
+ layer.id = LAYER_ID2;
4251
+ getUiRoot().appendChild(layer);
4252
+ return layer;
4253
+ }
4254
+ function place(el, b) {
4255
+ el.style.transform = `translate(${Math.round(b.left)}px, ${Math.round(b.top)}px)`;
4256
+ el.style.width = `${Math.max(0, Math.round(b.right - b.left))}px`;
4257
+ el.style.height = `${Math.max(0, Math.round(b.bottom - b.top))}px`;
4258
+ }
4259
+ function currentBoxes() {
4260
+ if (!spec) return [];
4261
+ if ("area" in spec) return spec.element.isConnected ? [areaToBox(spec.element, spec.area)] : [];
4262
+ return spec.elements.flatMap((el) => {
4263
+ if (!el.isConnected) return [];
4264
+ const r = el.getBoundingClientRect();
4265
+ return r.width === 0 && r.height === 0 ? [] : [{ left: r.left, top: r.top, right: r.right, bottom: r.bottom }];
4266
+ });
4267
+ }
4268
+ function render() {
4269
+ const host2 = ensureLayer();
4270
+ const list = currentBoxes();
4271
+ while (boxes.length < list.length) {
4272
+ const b = document.createElement("div");
4273
+ b.className = "grabby-group-box";
4274
+ host2.insertBefore(b, labelEl);
4275
+ boxes.push(b);
4276
+ }
4277
+ boxes.forEach((b, i) => {
4278
+ b.hidden = i >= list.length;
4279
+ if (i < list.length) place(b, list[i]);
4280
+ });
4281
+ if (labelEl && !labelEl.hidden) {
4282
+ const u = spec && "elements" in spec ? unionBox(spec.elements) : list[0] ?? null;
4283
+ if (u) labelEl.style.transform = `translate(${Math.round(u.left)}px, ${Math.round(Math.max(0, u.top - 20))}px)`;
4284
+ }
4285
+ }
4286
+ function track() {
4287
+ rafId = null;
4288
+ if (!spec) return;
4289
+ render();
4290
+ rafId = requestAnimationFrame(track);
4291
+ }
4292
+ function stop() {
4293
+ if (rafId !== null) cancelAnimationFrame(rafId);
4294
+ rafId = null;
4295
+ }
4296
+ return {
4297
+ marquee(box) {
4298
+ if (!box) {
4299
+ if (marqueeEl) marqueeEl.hidden = true;
4300
+ return;
4301
+ }
4302
+ const host2 = ensureLayer();
4303
+ if (!marqueeEl) {
4304
+ marqueeEl = document.createElement("div");
4305
+ marqueeEl.className = "grabby-group-marquee";
4306
+ host2.appendChild(marqueeEl);
4307
+ }
4308
+ marqueeEl.hidden = false;
4309
+ place(marqueeEl, box);
4310
+ },
4311
+ show(next, label) {
4312
+ spec = next;
4313
+ const host2 = ensureLayer();
4314
+ if (!labelEl) {
4315
+ labelEl = document.createElement("div");
4316
+ labelEl.className = "grabby-group-label";
4317
+ host2.appendChild(labelEl);
4318
+ }
4319
+ labelEl.hidden = !label;
4320
+ labelEl.textContent = label ?? "";
4321
+ stop();
4322
+ track();
4323
+ },
4324
+ hide() {
4325
+ spec = null;
4326
+ stop();
4327
+ for (const b of boxes) b.hidden = true;
4328
+ if (labelEl) labelEl.hidden = true;
4329
+ },
4330
+ isVisible() {
4331
+ return spec !== null;
4332
+ },
4333
+ dispose() {
4334
+ stop();
4335
+ layer?.remove();
4336
+ layer = null;
4337
+ marqueeEl = null;
4338
+ labelEl = null;
4339
+ boxes = [];
4340
+ spec = null;
4341
+ removeStyles(STYLE_ID10);
4342
+ }
4343
+ };
4344
+ }
4345
+
3899
4346
  // src/core/overlay/select-feedback.ts
3900
- var STYLE_ID10 = "__grabby-feedback-styles__";
4347
+ var STYLE_ID11 = "__grabby-feedback-styles__";
3901
4348
  function injectStyles() {
3902
- if (hasStyles(STYLE_ID10)) return;
3903
- addStyles(STYLE_ID10, `
4349
+ if (hasStyles(STYLE_ID11)) return;
4350
+ addStyles(STYLE_ID11, `
3904
4351
  @keyframes grabby-flash {
3905
4352
  0% { opacity: 1; }
3906
4353
  100% { opacity: 0; transform: scale(1.02); }
@@ -3979,7 +4426,7 @@ function showSelectFeedback(element, label = "Selected") {
3979
4426
  setTimeout(cleanup, 1200);
3980
4427
  }
3981
4428
  function disposeFeedbackStyles() {
3982
- removeStyles(STYLE_ID10);
4429
+ removeStyles(STYLE_ID11);
3983
4430
  }
3984
4431
 
3985
4432
  // src/core/storage/history-persistence.ts
@@ -4402,6 +4849,21 @@ function captureTarget(el, deps) {
4402
4849
  extra
4403
4850
  };
4404
4851
  }
4852
+ var MEMBER_PREVIEW = 120;
4853
+ function captureMember(el, deps) {
4854
+ const cleanClasses = deps.cleanClasses ?? ((list) => list.filter((c) => !isNoiseClass(c)));
4855
+ const kind = detectKind(el);
4856
+ const { component, frames } = resolveStack(el, deps);
4857
+ return {
4858
+ kind,
4859
+ tag: el.tagName.toLowerCase(),
4860
+ component,
4861
+ source: resolveSource(el, deps, frames),
4862
+ selector: buildUniqueSelector(el),
4863
+ preview: kind === "section" ? `<${el.tagName.toLowerCase()}>` : truncate(buildPreview(el, cleanClasses), MEMBER_PREVIEW),
4864
+ label: describeElement(el)
4865
+ };
4866
+ }
4405
4867
 
4406
4868
  // src/core/capture/screenshot.ts
4407
4869
  var MAX_SIDE = 1200;
@@ -4475,16 +4937,28 @@ function withTimeout(promise, ms) {
4475
4937
  );
4476
4938
  });
4477
4939
  }
4478
- async function captureScreenshot(el) {
4940
+ var MAX_CLIP_DEPTH = 4e3;
4941
+ var clamp = (v, max) => Math.min(Math.max(v, 0), max);
4942
+ async function captureScreenshot(el, clip) {
4479
4943
  if (typeof window === "undefined" || !el.isConnected) return null;
4480
4944
  const rect = el.getBoundingClientRect();
4481
4945
  if (rect.width < 1 || rect.height < 1) return null;
4482
- const cssWidth = Math.min(rect.width, document.documentElement.scrollWidth || rect.width);
4483
- const cssHeight = Math.min(rect.height, MAX_CSS_HEIGHT);
4946
+ const fullWidth = Math.min(rect.width, document.documentElement.scrollWidth || rect.width);
4947
+ const region = clip ? {
4948
+ x: clamp(clip.left - rect.left, fullWidth),
4949
+ y: clamp(clip.top - rect.top, rect.height),
4950
+ right: clamp(clip.right - rect.left, fullWidth),
4951
+ bottom: clamp(clip.bottom - rect.top, rect.height)
4952
+ } : null;
4953
+ if (region && (region.right - region.x < 1 || region.bottom - region.y < 1 || region.bottom > MAX_CLIP_DEPTH)) return null;
4954
+ const cssWidth = fullWidth;
4955
+ const cssHeight = region ? region.bottom : Math.min(rect.height, MAX_CSS_HEIGHT);
4956
+ const outWidth = region ? region.right - region.x : cssWidth;
4957
+ const outHeight = region ? Math.min(region.bottom - region.y, MAX_CSS_HEIGHT) : cssHeight;
4484
4958
  const dpr = window.devicePixelRatio || 1;
4485
- const scale = Math.min(dpr, MAX_SIDE / Math.max(cssWidth, cssHeight));
4959
+ const scale = Math.min(dpr, MAX_SIDE / Math.max(outWidth, outHeight));
4486
4960
  const render = async () => {
4487
- const { createContext, destroyContext, domToBlob } = await import("modern-screenshot");
4961
+ const { createContext, destroyContext, domToBlob, domToCanvas } = await import("modern-screenshot");
4488
4962
  const context = await createContext(el, {
4489
4963
  width: cssWidth,
4490
4964
  height: cssHeight,
@@ -4501,13 +4975,22 @@ async function captureScreenshot(el) {
4501
4975
  context.sandbox = await getSandbox();
4502
4976
  let blob;
4503
4977
  try {
4504
- blob = await domToBlob(context);
4978
+ if (region) {
4979
+ const full = await domToCanvas(context);
4980
+ const crop = document.createElement("canvas");
4981
+ crop.width = Math.max(1, Math.round(outWidth * scale));
4982
+ crop.height = Math.max(1, Math.round(outHeight * scale));
4983
+ crop.getContext("2d")?.drawImage(full, region.x * scale, region.y * scale, outWidth * scale, outHeight * scale, 0, 0, crop.width, crop.height);
4984
+ blob = await new Promise((resolve) => crop.toBlob(resolve, "image/webp", 0.8));
4985
+ } else {
4986
+ blob = await domToBlob(context);
4987
+ }
4505
4988
  } finally {
4506
4989
  context.sandbox = void 0;
4507
4990
  destroyContext(context);
4508
4991
  }
4509
4992
  if (!blob) return null;
4510
- return { blob, width: Math.round(cssWidth * scale), height: Math.round(cssHeight * scale) };
4993
+ return { blob, width: Math.round(outWidth * scale), height: Math.round(outHeight * scale) };
4511
4994
  };
4512
4995
  return withTimeout(render(), TIMEOUT_MS + 1e3);
4513
4996
  }
@@ -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, pin) {
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, { componentResolver, sourceResolver, cleanClasses }),
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) commentedElements.delete(id);
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
- selectedElement = null;
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
- const rect = element.getBoundingClientRect();
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
- if (comment && element) overlay.show(element, comment.target.component, null, []);
5430
- else overlay.hide();
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
- if (element) overlay.show(element, comment.target.component, null, []);
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
- const pin = selectedPin;
5619
- selectedElement = null;
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
- selectedElement = null;
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();