@githumbi/grabby 0.5.1 → 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());
@@ -3672,6 +3937,8 @@ function createMarkers(deps) {
3672
3937
  transition: transform 0.12s ease, box-shadow 0.15s ease;
3673
3938
  }
3674
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; }
3675
3942
  .grabby-markers-layer .grabby-marker:hover,
3676
3943
  .grabby-markers-layer .grabby-marker:focus-visible {
3677
3944
  z-index: 1;
@@ -3836,6 +4103,7 @@ function createMarkers(deps) {
3836
4103
  host2.appendChild(entry.button);
3837
4104
  }
3838
4105
  entry.comment = comment;
4106
+ entry.button.classList.toggle("grabby-marker-group", !!(comment.members?.length || comment.area));
3839
4107
  const n = String(i + 1);
3840
4108
  entry.number.textContent = n;
3841
4109
  entry.button.setAttribute("aria-label", `Comment ${n}: ${preview(comment.comment)}. Click to edit.`);
@@ -3945,11 +4213,141 @@ function createMarkers(deps) {
3945
4213
  };
3946
4214
  }
3947
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
+
3948
4346
  // src/core/overlay/select-feedback.ts
3949
- var STYLE_ID10 = "__grabby-feedback-styles__";
4347
+ var STYLE_ID11 = "__grabby-feedback-styles__";
3950
4348
  function injectStyles() {
3951
- if (hasStyles(STYLE_ID10)) return;
3952
- addStyles(STYLE_ID10, `
4349
+ if (hasStyles(STYLE_ID11)) return;
4350
+ addStyles(STYLE_ID11, `
3953
4351
  @keyframes grabby-flash {
3954
4352
  0% { opacity: 1; }
3955
4353
  100% { opacity: 0; transform: scale(1.02); }
@@ -4028,7 +4426,7 @@ function showSelectFeedback(element, label = "Selected") {
4028
4426
  setTimeout(cleanup, 1200);
4029
4427
  }
4030
4428
  function disposeFeedbackStyles() {
4031
- removeStyles(STYLE_ID10);
4429
+ removeStyles(STYLE_ID11);
4032
4430
  }
4033
4431
 
4034
4432
  // src/core/storage/history-persistence.ts
@@ -4451,6 +4849,21 @@ function captureTarget(el, deps) {
4451
4849
  extra
4452
4850
  };
4453
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
+ }
4454
4867
 
4455
4868
  // src/core/capture/screenshot.ts
4456
4869
  var MAX_SIDE = 1200;
@@ -4524,16 +4937,28 @@ function withTimeout(promise, ms) {
4524
4937
  );
4525
4938
  });
4526
4939
  }
4527
- 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) {
4528
4943
  if (typeof window === "undefined" || !el.isConnected) return null;
4529
4944
  const rect = el.getBoundingClientRect();
4530
4945
  if (rect.width < 1 || rect.height < 1) return null;
4531
- const cssWidth = Math.min(rect.width, document.documentElement.scrollWidth || rect.width);
4532
- 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;
4533
4958
  const dpr = window.devicePixelRatio || 1;
4534
- const scale = Math.min(dpr, MAX_SIDE / Math.max(cssWidth, cssHeight));
4959
+ const scale = Math.min(dpr, MAX_SIDE / Math.max(outWidth, outHeight));
4535
4960
  const render = async () => {
4536
- const { createContext, destroyContext, domToBlob } = await import("modern-screenshot");
4961
+ const { createContext, destroyContext, domToBlob, domToCanvas } = await import("modern-screenshot");
4537
4962
  const context = await createContext(el, {
4538
4963
  width: cssWidth,
4539
4964
  height: cssHeight,
@@ -4550,13 +4975,22 @@ async function captureScreenshot(el) {
4550
4975
  context.sandbox = await getSandbox();
4551
4976
  let blob;
4552
4977
  try {
4553
- 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
+ }
4554
4988
  } finally {
4555
4989
  context.sandbox = void 0;
4556
4990
  destroyContext(context);
4557
4991
  }
4558
4992
  if (!blob) return null;
4559
- 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) };
4560
4994
  };
4561
4995
  return withTimeout(render(), TIMEOUT_MS + 1e3);
4562
4996
  }
@@ -5205,6 +5639,7 @@ function createGrabInstance(options) {
5205
5639
  }
5206
5640
  }
5207
5641
  const overlay = createOverlayRenderer({ plainLabels: live });
5642
+ const groupOutline = createGroupOutline();
5208
5643
  const crosshair = createCrosshair();
5209
5644
  const freezeOverlay = createFreezeOverlay();
5210
5645
  const pluginRegistry = createPluginRegistry();
@@ -5217,6 +5652,9 @@ function createGrabInstance(options) {
5217
5652
  const cleanClasses = (list) => adapters.cleanClasses(list.filter((c) => !isNoiseClass(c)));
5218
5653
  let selectedElement = null;
5219
5654
  let selectedPin;
5655
+ let selectedMembers = null;
5656
+ let selectedArea = null;
5657
+ const commentedMembers = /* @__PURE__ */ new Map();
5220
5658
  let pendingShot = null;
5221
5659
  const commentedElements = /* @__PURE__ */ new Map();
5222
5660
  let editingFromMarker = false;
@@ -5278,7 +5716,9 @@ function createGrabInstance(options) {
5278
5716
  column: c.target.source?.column ?? null
5279
5717
  };
5280
5718
  }
5281
- 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 };
5282
5722
  const now = Date.now();
5283
5723
  const comment = {
5284
5724
  id: randomId(),
@@ -5292,13 +5732,16 @@ function createGrabInstance(options) {
5292
5732
  title: document.title,
5293
5733
  viewport: [window.innerWidth, window.innerHeight]
5294
5734
  },
5295
- target: captureTarget(element, { componentResolver, sourceResolver, cleanClasses }),
5735
+ target: captureTarget(element, deps),
5296
5736
  screenshot: null,
5297
5737
  framework: adapters.frameworkFor(element),
5298
5738
  ...outbox ? { sync: "pending" } : {},
5299
- ...pin ? { pin } : {}
5739
+ ...pin ? { pin } : {},
5740
+ ...members?.length ? { members: members.map((el) => captureMember(el, deps)) } : {},
5741
+ ...area ? { area } : {}
5300
5742
  };
5301
5743
  commentedElements.set(comment.id, element);
5744
+ if (members?.length) commentedMembers.set(comment.id, members);
5302
5745
  setComments([comment, ...comments()].slice(0, MAX_COMMENTS));
5303
5746
  pluginRegistry.callHook("onComment", comment, element);
5304
5747
  outbox?.send(comment.id);
@@ -5343,7 +5786,10 @@ function createGrabInstance(options) {
5343
5786
  const idSet = new Set(ids);
5344
5787
  const before = comments();
5345
5788
  const removed = before.filter((c) => idSet.has(c.id));
5346
- for (const id of ids) commentedElements.delete(id);
5789
+ for (const id of ids) {
5790
+ commentedElements.delete(id);
5791
+ commentedMembers.delete(id);
5792
+ }
5347
5793
  setComments(before.filter((c) => !idSet.has(c.id)));
5348
5794
  const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
5349
5795
  const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
@@ -5402,16 +5848,52 @@ function createGrabInstance(options) {
5402
5848
  commentPopover.hide();
5403
5849
  endMarkerEdit();
5404
5850
  if (picker.isHolding()) {
5405
- selectedElement = null;
5406
- selectedPin = void 0;
5407
- pendingShot = null;
5851
+ clearSelection();
5408
5852
  picker.release();
5409
5853
  }
5410
5854
  }
5855
+ function clearSelection() {
5856
+ selectedElement = null;
5857
+ selectedPin = void 0;
5858
+ selectedMembers = null;
5859
+ selectedArea = null;
5860
+ pendingShot = null;
5861
+ }
5411
5862
  function endMarkerEdit() {
5412
5863
  if (!editingFromMarker) return;
5413
5864
  editingFromMarker = false;
5414
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
+ });
5415
5897
  }
5416
5898
  function closeAllPopovers() {
5417
5899
  commentsPanel.hide();
@@ -5439,6 +5921,7 @@ function createGrabInstance(options) {
5439
5921
  const picker = createElementPicker({
5440
5922
  overlay,
5441
5923
  crosshair,
5924
+ groupOutline,
5442
5925
  getComponentResolver: () => componentResolver,
5443
5926
  getSourceResolver: () => sourceResolver,
5444
5927
  isToolbarElement: isAnyToolbarElement,
@@ -5451,18 +5934,24 @@ function createGrabInstance(options) {
5451
5934
  },
5452
5935
  onSelect(element, point) {
5453
5936
  selectedElement = element;
5454
- const rect = element.getBoundingClientRect();
5455
- const frac = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
5456
- selectedPin = {
5457
- x: Math.round(frac(point.x, rect.left, rect.width) * 1e3) / 1e3,
5458
- y: Math.round(frac(point.y, rect.top, rect.height) * 1e3) / 1e3
5459
- };
5937
+ selectedPin = pinIn(element, point);
5460
5938
  pendingShot = store.state.options.screenshots ? captureScreenshot(element) : null;
5461
5939
  pluginRegistry.callHook("onElementSelect", element);
5462
5940
  coachMark.dismiss();
5463
5941
  showSelectFeedback(element);
5464
5942
  picker.hold(element);
5465
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));
5466
5955
  }
5467
5956
  });
5468
5957
  const markers = createMarkers({
@@ -5475,20 +5964,30 @@ function createGrabInstance(options) {
5475
5964
  },
5476
5965
  onHover(comment, element) {
5477
5966
  if (picker.isHolding() || editingFromMarker || commentPopover.isVisible()) return;
5478
- if (comment && element) overlay.show(element, comment.target.component, null, []);
5479
- 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
+ }
5480
5974
  },
5481
5975
  onOpen(comment, element, marker) {
5482
5976
  if (picker.isHolding()) return;
5483
5977
  closeAllPopovers();
5484
5978
  doDeactivate(true);
5485
5979
  editingFromMarker = true;
5486
- 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;
5487
5984
  commentPopover.show({
5488
5985
  anchor: element ?? marker,
5986
+ anchorBox: spec ? "area" in spec ? areaToBox(spec.element, spec.area) : unionBox(spec.elements) : null,
5489
5987
  initialValue: comment.comment,
5490
5988
  mode: "edit",
5491
- entryId: comment.id
5989
+ entryId: comment.id,
5990
+ heading: comment.members?.length || comment.area ? describeComment(comment) : void 0
5492
5991
  });
5493
5992
  }
5494
5993
  });
@@ -5663,12 +6162,10 @@ function createGrabInstance(options) {
5663
6162
  if (identity) saveIdentity({ name: identity.name, anonymous: !identity.name });
5664
6163
  if (ctx.mode === "new") {
5665
6164
  const element = selectedElement;
6165
+ const extras = { pin: selectedPin, members: selectedMembers, area: selectedArea };
5666
6166
  const shot = pendingShot;
5667
- const pin = selectedPin;
5668
- selectedElement = null;
5669
- selectedPin = void 0;
5670
- pendingShot = null;
5671
- if (element) saveComment(element, value, shot, pin);
6167
+ clearSelection();
6168
+ if (element) saveComment(element, value, shot, extras);
5672
6169
  doDeactivate(true);
5673
6170
  return;
5674
6171
  }
@@ -5684,9 +6181,7 @@ function createGrabInstance(options) {
5684
6181
  },
5685
6182
  onCancel(ctx) {
5686
6183
  if (ctx.mode === "new") {
5687
- selectedElement = null;
5688
- selectedPin = void 0;
5689
- pendingShot = null;
6184
+ clearSelection();
5690
6185
  doDeactivate(true);
5691
6186
  return;
5692
6187
  }
@@ -5852,6 +6347,7 @@ function createGrabInstance(options) {
5852
6347
  crosshair.dispose();
5853
6348
  freezeOverlay.dispose();
5854
6349
  markers.dispose();
6350
+ groupOutline.dispose();
5855
6351
  disposeToast();
5856
6352
  disposeFeedbackStyles();
5857
6353
  pluginRegistry.dispose();