@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.
@@ -507,6 +507,20 @@ function describeTarget(target) {
507
507
  const name = facts.label || facts.heading || facts.text || facts.alt || "";
508
508
  return quoted(noun, name);
509
509
  }
510
+ var GROUP_NAMED = 3;
511
+ function describeGroup(labels) {
512
+ const named = labels.slice(0, GROUP_NAMED).join(", ");
513
+ const more = labels.length > GROUP_NAMED ? ` and ${labels.length - GROUP_NAMED} more` : "";
514
+ return `${labels.length} elements: ${named}${more}`;
515
+ }
516
+ function describeArea(around) {
517
+ return `Area in ${around}`;
518
+ }
519
+ function describeComment(c) {
520
+ if (c.members?.length) return describeGroup(c.members.map((m) => m.label));
521
+ if (c.area) return describeArea(describeTarget(c.target));
522
+ return describeTarget(c.target);
523
+ }
510
524
 
511
525
  // src/core/overlay/overlay-renderer.ts
512
526
  var OVERLAY_ID = "__grabby-overlay__";
@@ -1157,11 +1171,114 @@ function buildUniqueSelector(el) {
1157
1171
  return steps.join(" > ");
1158
1172
  }
1159
1173
 
1174
+ // src/core/picker/region.ts
1175
+ var MAX_MEMBERS = 20;
1176
+ var INSIDE_RATIO = 0.85;
1177
+ var MIN_SIDE = 4;
1178
+ var MAX_VISITS = 4e3;
1179
+ var SKIP_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "HEAD", "META", "LINK", "BR", "WBR"]);
1180
+ function boxFromPoints(a, b) {
1181
+ return { left: Math.min(a.x, b.x), top: Math.min(a.y, b.y), right: Math.max(a.x, b.x), bottom: Math.max(a.y, b.y) };
1182
+ }
1183
+ function overlapArea(r, box) {
1184
+ const w = Math.min(r.right, box.right) - Math.max(r.left, box.left);
1185
+ const h2 = Math.min(r.bottom, box.bottom) - Math.max(r.top, box.top);
1186
+ return w > 0 && h2 > 0 ? w * h2 : 0;
1187
+ }
1188
+ function contains(r, box) {
1189
+ return r.left <= box.left && r.top <= box.top && r.right >= box.right && r.bottom >= box.bottom;
1190
+ }
1191
+ function isHidden(el) {
1192
+ const style = getComputedStyle(el);
1193
+ return style.visibility === "hidden" || style.opacity === "0";
1194
+ }
1195
+ function elementsInBox(box, isUiNode2, root2 = document.body) {
1196
+ const found = [];
1197
+ let visits = 0;
1198
+ const visit = (el) => {
1199
+ if (found.length >= MAX_MEMBERS || ++visits > MAX_VISITS) return;
1200
+ if (SKIP_TAGS.has(el.tagName) || isUiNode2(el) || el.hasAttribute(IGNORE_ATTR)) return;
1201
+ const r = el.getBoundingClientRect();
1202
+ const boxless = r.width === 0 && r.height === 0;
1203
+ if (!boxless && overlapArea(r, box) === 0) return;
1204
+ if (!boxless && r.width >= MIN_SIDE && r.height >= MIN_SIDE) {
1205
+ const inside = overlapArea(r, box) / (r.width * r.height);
1206
+ if (inside >= INSIDE_RATIO && detectKind(el) !== "section" && !isHidden(el)) {
1207
+ found.push(el);
1208
+ return;
1209
+ }
1210
+ }
1211
+ for (const child of Array.from(el.children)) visit(child);
1212
+ };
1213
+ for (const child of Array.from(root2.children)) visit(child);
1214
+ return found;
1215
+ }
1216
+ function commonContainer(elements) {
1217
+ if (elements.length === 0) return document.body;
1218
+ let candidate = elements[0].parentElement ?? document.body;
1219
+ while (candidate && !elements.every((el) => candidate.contains(el))) candidate = candidate.parentElement;
1220
+ return candidate ?? document.body;
1221
+ }
1222
+ function containerForBox(box, isUiNode2) {
1223
+ const cx = (box.left + box.right) / 2;
1224
+ const cy = (box.top + box.bottom) / 2;
1225
+ const stack = typeof document.elementsFromPoint === "function" ? document.elementsFromPoint(cx, cy) : [];
1226
+ for (const el of stack) {
1227
+ if (isUiNode2(el) || el.closest(`[${IGNORE_ATTR}]`)) continue;
1228
+ for (let cur = el; cur; cur = cur.parentElement) {
1229
+ if (contains(cur.getBoundingClientRect(), box)) return cur;
1230
+ }
1231
+ }
1232
+ return document.body;
1233
+ }
1234
+ var frac = (v) => Math.round(Math.min(1, Math.max(0, v)) * 1e3) / 1e3;
1235
+ function areaWithin(el, box) {
1236
+ const r = el.getBoundingClientRect();
1237
+ const w = r.width || 1;
1238
+ const h2 = r.height || 1;
1239
+ return {
1240
+ x: frac((box.left - r.left) / w),
1241
+ y: frac((box.top - r.top) / h2),
1242
+ w: frac((box.right - box.left) / w),
1243
+ h: frac((box.bottom - box.top) / h2)
1244
+ };
1245
+ }
1246
+ function areaToBox(el, area) {
1247
+ const r = el.getBoundingClientRect();
1248
+ return {
1249
+ left: r.left + area.x * r.width,
1250
+ top: r.top + area.y * r.height,
1251
+ right: r.left + (area.x + area.w) * r.width,
1252
+ bottom: r.top + (area.y + area.h) * r.height
1253
+ };
1254
+ }
1255
+ function unionBox(elements) {
1256
+ let out = null;
1257
+ for (const el of elements) {
1258
+ const r = el.getBoundingClientRect();
1259
+ if (r.width === 0 && r.height === 0) continue;
1260
+ out = out ? { left: Math.min(out.left, r.left), top: Math.min(out.top, r.top), right: Math.max(out.right, r.right), bottom: Math.max(out.bottom, r.bottom) } : { left: r.left, top: r.top, right: r.right, bottom: r.bottom };
1261
+ }
1262
+ return out;
1263
+ }
1264
+
1160
1265
  // src/core/picker/element-picker.ts
1266
+ var DRAG_PX = 6;
1267
+ var IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
1268
+ var PRESS_EVENTS = ["pointerdown", "mousedown", "pointerup", "mouseup", "touchstart"];
1269
+ function addKey(e) {
1270
+ return IS_MAC ? e.metaKey : e.ctrlKey;
1271
+ }
1161
1272
  function createElementPicker(deps) {
1162
1273
  let hoveredElement = null;
1163
1274
  let heldElement = null;
1164
1275
  let listening = false;
1276
+ let press = null;
1277
+ let dragBox = null;
1278
+ let dragFrame = null;
1279
+ let lastPoint = { x: 0, y: 0 };
1280
+ let swallowNextClick = false;
1281
+ let collected = [];
1165
1282
  function resolveComponentName(el) {
1166
1283
  const resolver = deps.getComponentResolver();
1167
1284
  if (!resolver) return null;
@@ -1191,14 +1308,93 @@ function createElementPicker(deps) {
1191
1308
  if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
1192
1309
  return exact ? raw : promoteTarget(raw);
1193
1310
  }
1311
+ function isOurs(el) {
1312
+ return !!deps.isToolbarElement?.(el) || deps.overlay.isOverlayElement(el) || deps.crosshair.isCrosshairElement(el);
1313
+ }
1194
1314
  function showOverlay(target) {
1195
1315
  const componentName = resolveComponentName(target);
1196
1316
  const sourcePath = resolveSourcePath(target);
1197
1317
  const cssClasses = filterAngularClasses(target.classList);
1198
1318
  deps.overlay.show(target, componentName, sourcePath, cssClasses);
1199
1319
  }
1320
+ const countLabel = (n) => `${n} element${n === 1 ? "" : "s"}`;
1321
+ function showCollected() {
1322
+ if (collected.length) {
1323
+ deps.groupOutline.show({ elements: collected }, `${countLabel(collected.length)} \xB7 release ${IS_MAC ? "\u2318" : "Ctrl"} to comment`);
1324
+ } else {
1325
+ deps.groupOutline.hide();
1326
+ }
1327
+ }
1328
+ function clearCollected() {
1329
+ if (!collected.length) return;
1330
+ collected = [];
1331
+ deps.groupOutline.hide();
1332
+ }
1333
+ function previewDrag() {
1334
+ dragFrame = null;
1335
+ if (!dragBox) return;
1336
+ deps.groupOutline.marquee(dragBox);
1337
+ const found = elementsInBox(dragBox, isOurs);
1338
+ if (found.length) deps.groupOutline.show({ elements: found }, countLabel(found.length));
1339
+ else deps.groupOutline.hide();
1340
+ }
1341
+ function endDrag() {
1342
+ dragBox = null;
1343
+ if (dragFrame !== null) cancelAnimationFrame(dragFrame);
1344
+ dragFrame = null;
1345
+ deps.groupOutline.marquee(null);
1346
+ deps.groupOutline.hide();
1347
+ }
1348
+ function finishDrag(point) {
1349
+ const box = dragBox;
1350
+ endDrag();
1351
+ const found = elementsInBox(box, isOurs);
1352
+ if (found.length === 1) {
1353
+ hoveredElement = found[0];
1354
+ deps.onSelect(found[0], point);
1355
+ } else if (found.length > 1) {
1356
+ deps.onSelectGroup(found, point);
1357
+ } else {
1358
+ const container = containerForBox(box, isOurs);
1359
+ deps.onSelectArea(container, areaWithin(container, box), point);
1360
+ }
1361
+ }
1362
+ function handlePress(e) {
1363
+ const origin = eventTarget(e);
1364
+ if (origin && deps.isToolbarElement?.(origin)) return;
1365
+ e.stopPropagation();
1366
+ if (e.type === "mousedown" || e.type === "touchstart") e.preventDefault();
1367
+ if (heldElement) return;
1368
+ const m = e;
1369
+ const down = e.type === "pointerdown" || e.type === "mousedown";
1370
+ if (down && m.button === 0 && !press) {
1371
+ press = { x: m.clientX, y: m.clientY };
1372
+ swallowNextClick = false;
1373
+ } else if (!down && e.type !== "touchstart" && press) {
1374
+ const point = { x: m.clientX, y: m.clientY };
1375
+ const start = press;
1376
+ press = null;
1377
+ if (dragBox) {
1378
+ dragBox = boxFromPoints(start, point);
1379
+ swallowNextClick = true;
1380
+ finishDrag(point);
1381
+ }
1382
+ }
1383
+ }
1200
1384
  function handleMouseMove(e) {
1201
1385
  if (heldElement) return;
1386
+ lastPoint = { x: e.clientX, y: e.clientY };
1387
+ if (press) {
1388
+ if (!dragBox && Math.hypot(e.clientX - press.x, e.clientY - press.y) < DRAG_PX) return;
1389
+ if (!dragBox) {
1390
+ clearCollected();
1391
+ deps.overlay.hide();
1392
+ hoveredElement = null;
1393
+ }
1394
+ dragBox = boxFromPoints(press, lastPoint);
1395
+ if (dragFrame === null) dragFrame = requestAnimationFrame(previewDrag);
1396
+ return;
1397
+ }
1202
1398
  const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
1203
1399
  if (!target || deps.overlay.isOverlayElement(target)) return;
1204
1400
  if (deps.crosshair.isCrosshairElement(target)) return;
@@ -1216,8 +1412,32 @@ function createElementPicker(deps) {
1216
1412
  e.preventDefault();
1217
1413
  e.stopPropagation();
1218
1414
  if (heldElement) return;
1219
- if (hoveredElement) {
1220
- deps.onSelect(hoveredElement, { x: e.clientX, y: e.clientY });
1415
+ if (swallowNextClick) {
1416
+ swallowNextClick = false;
1417
+ return;
1418
+ }
1419
+ if (!hoveredElement) return;
1420
+ lastPoint = { x: e.clientX, y: e.clientY };
1421
+ if (addKey(e)) {
1422
+ const at = collected.indexOf(hoveredElement);
1423
+ if (at >= 0) collected.splice(at, 1);
1424
+ else if (collected.length < MAX_MEMBERS) collected.push(hoveredElement);
1425
+ showCollected();
1426
+ return;
1427
+ }
1428
+ clearCollected();
1429
+ deps.onSelect(hoveredElement, lastPoint);
1430
+ }
1431
+ function handleKeyUp(e) {
1432
+ if (e.key !== (IS_MAC ? "Meta" : "Control") || !collected.length || heldElement) return;
1433
+ const elements = collected;
1434
+ collected = [];
1435
+ deps.groupOutline.hide();
1436
+ if (elements.length === 1) {
1437
+ hoveredElement = elements[0];
1438
+ deps.onSelect(elements[0], lastPoint);
1439
+ } else {
1440
+ deps.onSelectGroup(elements, lastPoint);
1221
1441
  }
1222
1442
  }
1223
1443
  return {
@@ -1225,31 +1445,46 @@ function createElementPicker(deps) {
1225
1445
  if (listening) return;
1226
1446
  listening = true;
1227
1447
  deps.crosshair.activate();
1448
+ for (const type of PRESS_EVENTS) window.addEventListener(type, handlePress, { capture: true, passive: false });
1228
1449
  document.addEventListener("mousemove", handleMouseMove, true);
1229
1450
  document.addEventListener("click", handleClick, true);
1451
+ window.addEventListener("keyup", handleKeyUp, true);
1230
1452
  },
1231
1453
  deactivate() {
1232
1454
  if (!listening) return;
1233
1455
  listening = false;
1234
1456
  hoveredElement = null;
1235
1457
  heldElement = null;
1458
+ press = null;
1459
+ swallowNextClick = false;
1460
+ collected = [];
1461
+ endDrag();
1236
1462
  deps.crosshair.hold(false);
1237
1463
  deps.crosshair.deactivate();
1464
+ for (const type of PRESS_EVENTS) window.removeEventListener(type, handlePress, true);
1238
1465
  document.removeEventListener("mousemove", handleMouseMove, true);
1239
1466
  document.removeEventListener("click", handleClick, true);
1467
+ window.removeEventListener("keyup", handleKeyUp, true);
1240
1468
  deps.overlay.hide();
1241
1469
  deps.onHover(null);
1242
1470
  },
1243
- hold(element) {
1471
+ hold(element, group) {
1244
1472
  if (!listening) return;
1245
1473
  heldElement = element;
1246
1474
  hoveredElement = element;
1475
+ press = null;
1247
1476
  deps.crosshair.hold(true);
1248
- showOverlay(element);
1477
+ if (group) {
1478
+ deps.overlay.hide();
1479
+ deps.groupOutline.show(group.spec, group.label);
1480
+ } else {
1481
+ showOverlay(element);
1482
+ }
1249
1483
  },
1250
1484
  release() {
1251
1485
  if (!heldElement) return;
1252
1486
  heldElement = null;
1487
+ deps.groupOutline.hide();
1253
1488
  deps.crosshair.hold(false);
1254
1489
  },
1255
1490
  isHolding() {
@@ -2000,10 +2235,15 @@ function header(comments, env, ctx) {
2000
2235
  }
2001
2236
  return lines;
2002
2237
  }
2238
+ var pct = (v) => `${Math.round(v * 100)}%`;
2239
+ function memberRefs(c, full) {
2240
+ return (c.members ?? []).map((m) => m.source ? location2(m.source.file, m.source.line, full) : m.selector).join(", ");
2241
+ }
2003
2242
  function compactLine(c, i, ctx) {
2004
2243
  const t = c.target;
2005
2244
  const where = t.source ? location2(t.source.file, t.source.line, true) : t.selector;
2006
- const parts = [where, t.component, `<${t.tag}>`].filter(Boolean).join(" ");
2245
+ const own = [where, t.component, `<${t.tag}>`].filter(Boolean).join(" ");
2246
+ const parts = c.members?.length ? `[${c.members.length} elements] ${memberRefs(c, true)}` : c.area ? `[area] in ${own}` : own;
2007
2247
  const who = ctx.showAuthors ? ` (${authorLabel(c.author)})` : "";
2008
2248
  const route = ctx.showRoutes ? ` [${c.page.route}]` : "";
2009
2249
  const id = ctx.showIds ? ` [id ${c.id}]` : "";
@@ -2020,7 +2260,20 @@ function detailBlock(c, i, ctx, groupHasSource, headedComponent) {
2020
2260
  } else if (t.source?.line != null && groupHasSource) {
2021
2261
  where.push(`line ${t.source.line}`);
2022
2262
  }
2263
+ if (c.members?.length) where.unshift("in");
2264
+ if (c.area) where.unshift("area in");
2023
2265
  b(where.join(" "));
2266
+ if (c.area) {
2267
+ const a = c.area;
2268
+ b(`region: ${pct(a.x)} from left, ${pct(a.y)} from top, ${pct(a.w)} wide, ${pct(a.h)} tall`);
2269
+ }
2270
+ if (c.members?.length) {
2271
+ b(`${c.members.length} elements:`);
2272
+ for (const m of c.members) {
2273
+ const at = m.source ? location2(m.source.file, m.source.line, full) : `selector \`${m.selector}\``;
2274
+ lines.push(` - \`${m.preview}\` (${m.kind})${m.component && m.component !== t.component ? ` ${m.component}` : ""} ${at}`);
2275
+ }
2276
+ }
2024
2277
  if (!t.source || full) b(`selector: \`${t.selector}\``);
2025
2278
  const plain = Object.entries(t.facts).filter(([k, v]) => !STYLE_FACTS.has(k) && !(PREVIEW_FACTS.has(k) && !full && inPreview(t.preview, v)));
2026
2279
  if (plain.length) b(plain.map(([k, v]) => `${k}: ${v}`).join(" \xB7 "));
@@ -2282,7 +2535,8 @@ function createCommentsPanel(callbacks, options = {}) {
2282
2535
  }
2283
2536
  function row2(comment, showAuthors) {
2284
2537
  const t = comment.target;
2285
- const meta = live ? [document.createTextNode(`${describeTarget(t)} `)] : [h("span", { class: "grabby-kind" }, t.kind)];
2538
+ const group = comment.members?.length ? `${comment.members.length} elements` : comment.area ? "area" : null;
2539
+ const meta = live ? [document.createTextNode(`${describeComment(comment)} `)] : [h("span", { class: "grabby-kind" }, group ?? t.kind)];
2286
2540
  if (!live) {
2287
2541
  if (t.component) meta.push(document.createTextNode(`${t.component} `));
2288
2542
  if (t.source) {
@@ -2512,6 +2766,13 @@ function createCommentPopover(callbacks) {
2512
2766
  font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding: 8px 4px; border: none;
2513
2767
  background: transparent; color: var(--grabby-text-muted, #64748b); cursor: pointer; text-decoration: underline;
2514
2768
  }
2769
+ #${POPOVER_ID} .grabby-cp-heading {
2770
+ font: 600 12px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
2771
+ color: #15803d;
2772
+ overflow: hidden;
2773
+ text-overflow: ellipsis;
2774
+ white-space: nowrap;
2775
+ }
2515
2776
  #${POPOVER_ID} .grabby-cp-edit-actions { display: flex; align-items: center; gap: 6px; }
2516
2777
  #${POPOVER_ID} .grabby-cp-edit-actions .grabby-cp-spacer { flex: 1; }
2517
2778
  #${POPOVER_ID} .grabby-cp-delete {
@@ -2550,18 +2811,18 @@ function createCommentPopover(callbacks) {
2550
2811
  getUiRoot().appendChild(popover);
2551
2812
  return popover;
2552
2813
  }
2553
- function position(el, anchor) {
2814
+ function position(el, anchor, box) {
2554
2815
  const vw = window.innerWidth;
2555
2816
  const vh = window.innerHeight;
2556
2817
  const fW = 300;
2557
2818
  const fH = 120;
2558
- if (!anchor) {
2819
+ if (!anchor && !box) {
2559
2820
  el.style.left = "50%";
2560
2821
  el.style.top = "24px";
2561
2822
  el.style.transform = "translateX(-50%)";
2562
2823
  return;
2563
2824
  }
2564
- const rect = anchor.getBoundingClientRect();
2825
+ const rect = box ? { ...box, width: box.right - box.left, height: box.bottom - box.top } : anchor.getBoundingClientRect();
2565
2826
  let left;
2566
2827
  let top;
2567
2828
  if (rect.right + 16 + fW <= vw) {
@@ -2715,8 +2976,12 @@ function createCommentPopover(callbacks) {
2715
2976
  currentCtx = { mode: opts.mode, entryId: opts.entryId };
2716
2977
  askIdentity = opts.askIdentity === true && opts.mode === "new";
2717
2978
  visible = true;
2979
+ textarea.placeholder = opts.placeholder ?? "What should change here?";
2980
+ if (opts.heading) {
2981
+ el.prepend(h("div", { class: "grabby-cp-heading", title: opts.heading }, opts.heading));
2982
+ }
2718
2983
  if (opts.mode === "edit") el.appendChild(editActions());
2719
- position(el, opts.anchor);
2984
+ position(el, opts.anchor, opts.anchorBox);
2720
2985
  attachKey();
2721
2986
  textarea?.focus();
2722
2987
  requestAnimationFrame(() => textarea?.focus());
@@ -3639,6 +3904,8 @@ function createMarkers(deps) {
3639
3904
  transition: transform 0.12s ease, box-shadow 0.15s ease;
3640
3905
  }
3641
3906
  .grabby-markers-layer .grabby-marker[hidden] { display: none; }
3907
+ /* Several elements or an area: a green square, like the outline it shows. */
3908
+ .grabby-markers-layer .grabby-marker.grabby-marker-group { border-radius: 6px; background: #16a34a; }
3642
3909
  .grabby-markers-layer .grabby-marker:hover,
3643
3910
  .grabby-markers-layer .grabby-marker:focus-visible {
3644
3911
  z-index: 1;
@@ -3803,6 +4070,7 @@ function createMarkers(deps) {
3803
4070
  host2.appendChild(entry.button);
3804
4071
  }
3805
4072
  entry.comment = comment;
4073
+ entry.button.classList.toggle("grabby-marker-group", !!(comment.members?.length || comment.area));
3806
4074
  const n = String(i + 1);
3807
4075
  entry.number.textContent = n;
3808
4076
  entry.button.setAttribute("aria-label", `Comment ${n}: ${preview(comment.comment)}. Click to edit.`);
@@ -3912,11 +4180,141 @@ function createMarkers(deps) {
3912
4180
  };
3913
4181
  }
3914
4182
 
4183
+ // src/core/overlay/group-outline.ts
4184
+ var LAYER_ID2 = "__grabby-group__";
4185
+ var STYLE_ID10 = "__grabby-group-styles__";
4186
+ var GREEN = "#16a34a";
4187
+ function createGroupOutline() {
4188
+ let layer = null;
4189
+ let marqueeEl = null;
4190
+ let labelEl = null;
4191
+ let boxes = [];
4192
+ let spec = null;
4193
+ let rafId = null;
4194
+ function ensureLayer() {
4195
+ if (layer) return layer;
4196
+ if (!hasStyles(STYLE_ID10)) {
4197
+ addStyles(STYLE_ID10, `
4198
+ #${LAYER_ID2} { position: fixed; inset: 0; pointer-events: none; z-index: ${Z_INDEX_OVERLAY}; }
4199
+ #${LAYER_ID2} .grabby-group-box {
4200
+ position: absolute; left: 0; top: 0; box-sizing: border-box;
4201
+ border: 2px dashed ${GREEN}; border-radius: 4px; background: rgba(22, 163, 74, 0.08);
4202
+ }
4203
+ #${LAYER_ID2} .grabby-group-marquee {
4204
+ position: absolute; left: 0; top: 0; box-sizing: border-box;
4205
+ border: 1px solid var(--grabby-accent, #2563eb); border-radius: 2px;
4206
+ background: color-mix(in srgb, var(--grabby-accent, #2563eb) 8%, transparent);
4207
+ }
4208
+ #${LAYER_ID2} .grabby-group-label {
4209
+ position: absolute; left: 0; top: 0; padding: 2px 6px; border-radius: 3px;
4210
+ background: ${GREEN}; color: #fff; white-space: nowrap;
4211
+ font: 600 11px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
4212
+ }
4213
+ #${LAYER_ID2} [hidden] { display: none; }
4214
+ `);
4215
+ }
4216
+ layer = document.createElement("div");
4217
+ layer.id = LAYER_ID2;
4218
+ getUiRoot().appendChild(layer);
4219
+ return layer;
4220
+ }
4221
+ function place(el, b) {
4222
+ el.style.transform = `translate(${Math.round(b.left)}px, ${Math.round(b.top)}px)`;
4223
+ el.style.width = `${Math.max(0, Math.round(b.right - b.left))}px`;
4224
+ el.style.height = `${Math.max(0, Math.round(b.bottom - b.top))}px`;
4225
+ }
4226
+ function currentBoxes() {
4227
+ if (!spec) return [];
4228
+ if ("area" in spec) return spec.element.isConnected ? [areaToBox(spec.element, spec.area)] : [];
4229
+ return spec.elements.flatMap((el) => {
4230
+ if (!el.isConnected) return [];
4231
+ const r = el.getBoundingClientRect();
4232
+ return r.width === 0 && r.height === 0 ? [] : [{ left: r.left, top: r.top, right: r.right, bottom: r.bottom }];
4233
+ });
4234
+ }
4235
+ function render() {
4236
+ const host2 = ensureLayer();
4237
+ const list = currentBoxes();
4238
+ while (boxes.length < list.length) {
4239
+ const b = document.createElement("div");
4240
+ b.className = "grabby-group-box";
4241
+ host2.insertBefore(b, labelEl);
4242
+ boxes.push(b);
4243
+ }
4244
+ boxes.forEach((b, i) => {
4245
+ b.hidden = i >= list.length;
4246
+ if (i < list.length) place(b, list[i]);
4247
+ });
4248
+ if (labelEl && !labelEl.hidden) {
4249
+ const u = spec && "elements" in spec ? unionBox(spec.elements) : list[0] ?? null;
4250
+ if (u) labelEl.style.transform = `translate(${Math.round(u.left)}px, ${Math.round(Math.max(0, u.top - 20))}px)`;
4251
+ }
4252
+ }
4253
+ function track() {
4254
+ rafId = null;
4255
+ if (!spec) return;
4256
+ render();
4257
+ rafId = requestAnimationFrame(track);
4258
+ }
4259
+ function stop() {
4260
+ if (rafId !== null) cancelAnimationFrame(rafId);
4261
+ rafId = null;
4262
+ }
4263
+ return {
4264
+ marquee(box) {
4265
+ if (!box) {
4266
+ if (marqueeEl) marqueeEl.hidden = true;
4267
+ return;
4268
+ }
4269
+ const host2 = ensureLayer();
4270
+ if (!marqueeEl) {
4271
+ marqueeEl = document.createElement("div");
4272
+ marqueeEl.className = "grabby-group-marquee";
4273
+ host2.appendChild(marqueeEl);
4274
+ }
4275
+ marqueeEl.hidden = false;
4276
+ place(marqueeEl, box);
4277
+ },
4278
+ show(next, label) {
4279
+ spec = next;
4280
+ const host2 = ensureLayer();
4281
+ if (!labelEl) {
4282
+ labelEl = document.createElement("div");
4283
+ labelEl.className = "grabby-group-label";
4284
+ host2.appendChild(labelEl);
4285
+ }
4286
+ labelEl.hidden = !label;
4287
+ labelEl.textContent = label ?? "";
4288
+ stop();
4289
+ track();
4290
+ },
4291
+ hide() {
4292
+ spec = null;
4293
+ stop();
4294
+ for (const b of boxes) b.hidden = true;
4295
+ if (labelEl) labelEl.hidden = true;
4296
+ },
4297
+ isVisible() {
4298
+ return spec !== null;
4299
+ },
4300
+ dispose() {
4301
+ stop();
4302
+ layer?.remove();
4303
+ layer = null;
4304
+ marqueeEl = null;
4305
+ labelEl = null;
4306
+ boxes = [];
4307
+ spec = null;
4308
+ removeStyles(STYLE_ID10);
4309
+ }
4310
+ };
4311
+ }
4312
+
3915
4313
  // src/core/overlay/select-feedback.ts
3916
- var STYLE_ID10 = "__grabby-feedback-styles__";
4314
+ var STYLE_ID11 = "__grabby-feedback-styles__";
3917
4315
  function injectStyles() {
3918
- if (hasStyles(STYLE_ID10)) return;
3919
- addStyles(STYLE_ID10, `
4316
+ if (hasStyles(STYLE_ID11)) return;
4317
+ addStyles(STYLE_ID11, `
3920
4318
  @keyframes grabby-flash {
3921
4319
  0% { opacity: 1; }
3922
4320
  100% { opacity: 0; transform: scale(1.02); }
@@ -3995,7 +4393,7 @@ function showSelectFeedback(element, label = "Selected") {
3995
4393
  setTimeout(cleanup, 1200);
3996
4394
  }
3997
4395
  function disposeFeedbackStyles() {
3998
- removeStyles(STYLE_ID10);
4396
+ removeStyles(STYLE_ID11);
3999
4397
  }
4000
4398
 
4001
4399
  // src/core/storage/history-persistence.ts
@@ -4418,6 +4816,21 @@ function captureTarget(el, deps) {
4418
4816
  extra
4419
4817
  };
4420
4818
  }
4819
+ var MEMBER_PREVIEW = 120;
4820
+ function captureMember(el, deps) {
4821
+ const cleanClasses = deps.cleanClasses ?? ((list) => list.filter((c) => !isNoiseClass(c)));
4822
+ const kind = detectKind(el);
4823
+ const { component, frames } = resolveStack(el, deps);
4824
+ return {
4825
+ kind,
4826
+ tag: el.tagName.toLowerCase(),
4827
+ component,
4828
+ source: resolveSource(el, deps, frames),
4829
+ selector: buildUniqueSelector(el),
4830
+ preview: kind === "section" ? `<${el.tagName.toLowerCase()}>` : truncate(buildPreview(el, cleanClasses), MEMBER_PREVIEW),
4831
+ label: describeElement(el)
4832
+ };
4833
+ }
4421
4834
 
4422
4835
  // src/core/capture/screenshot.ts
4423
4836
  var MAX_SIDE = 1200;
@@ -4491,16 +4904,28 @@ function withTimeout(promise, ms) {
4491
4904
  );
4492
4905
  });
4493
4906
  }
4494
- async function captureScreenshot(el) {
4907
+ var MAX_CLIP_DEPTH = 4e3;
4908
+ var clamp = (v, max) => Math.min(Math.max(v, 0), max);
4909
+ async function captureScreenshot(el, clip) {
4495
4910
  if (typeof window === "undefined" || !el.isConnected) return null;
4496
4911
  const rect = el.getBoundingClientRect();
4497
4912
  if (rect.width < 1 || rect.height < 1) return null;
4498
- const cssWidth = Math.min(rect.width, document.documentElement.scrollWidth || rect.width);
4499
- const cssHeight = Math.min(rect.height, MAX_CSS_HEIGHT);
4913
+ const fullWidth = Math.min(rect.width, document.documentElement.scrollWidth || rect.width);
4914
+ const region = clip ? {
4915
+ x: clamp(clip.left - rect.left, fullWidth),
4916
+ y: clamp(clip.top - rect.top, rect.height),
4917
+ right: clamp(clip.right - rect.left, fullWidth),
4918
+ bottom: clamp(clip.bottom - rect.top, rect.height)
4919
+ } : null;
4920
+ if (region && (region.right - region.x < 1 || region.bottom - region.y < 1 || region.bottom > MAX_CLIP_DEPTH)) return null;
4921
+ const cssWidth = fullWidth;
4922
+ const cssHeight = region ? region.bottom : Math.min(rect.height, MAX_CSS_HEIGHT);
4923
+ const outWidth = region ? region.right - region.x : cssWidth;
4924
+ const outHeight = region ? Math.min(region.bottom - region.y, MAX_CSS_HEIGHT) : cssHeight;
4500
4925
  const dpr = window.devicePixelRatio || 1;
4501
- const scale = Math.min(dpr, MAX_SIDE / Math.max(cssWidth, cssHeight));
4926
+ const scale = Math.min(dpr, MAX_SIDE / Math.max(outWidth, outHeight));
4502
4927
  const render = async () => {
4503
- const { createContext, destroyContext, domToBlob } = await import("modern-screenshot");
4928
+ const { createContext, destroyContext, domToBlob, domToCanvas } = await import("modern-screenshot");
4504
4929
  const context = await createContext(el, {
4505
4930
  width: cssWidth,
4506
4931
  height: cssHeight,
@@ -4517,13 +4942,22 @@ async function captureScreenshot(el) {
4517
4942
  context.sandbox = await getSandbox();
4518
4943
  let blob;
4519
4944
  try {
4520
- blob = await domToBlob(context);
4945
+ if (region) {
4946
+ const full = await domToCanvas(context);
4947
+ const crop = document.createElement("canvas");
4948
+ crop.width = Math.max(1, Math.round(outWidth * scale));
4949
+ crop.height = Math.max(1, Math.round(outHeight * scale));
4950
+ crop.getContext("2d")?.drawImage(full, region.x * scale, region.y * scale, outWidth * scale, outHeight * scale, 0, 0, crop.width, crop.height);
4951
+ blob = await new Promise((resolve) => crop.toBlob(resolve, "image/webp", 0.8));
4952
+ } else {
4953
+ blob = await domToBlob(context);
4954
+ }
4521
4955
  } finally {
4522
4956
  context.sandbox = void 0;
4523
4957
  destroyContext(context);
4524
4958
  }
4525
4959
  if (!blob) return null;
4526
- return { blob, width: Math.round(cssWidth * scale), height: Math.round(cssHeight * scale) };
4960
+ return { blob, width: Math.round(outWidth * scale), height: Math.round(outHeight * scale) };
4527
4961
  };
4528
4962
  return withTimeout(render(), TIMEOUT_MS + 1e3);
4529
4963
  }
@@ -5172,6 +5606,7 @@ function createGrabInstance(options) {
5172
5606
  }
5173
5607
  }
5174
5608
  const overlay = createOverlayRenderer({ plainLabels: live });
5609
+ const groupOutline = createGroupOutline();
5175
5610
  const crosshair = createCrosshair();
5176
5611
  const freezeOverlay = createFreezeOverlay();
5177
5612
  const pluginRegistry = createPluginRegistry();
@@ -5184,6 +5619,9 @@ function createGrabInstance(options) {
5184
5619
  const cleanClasses = (list) => adapters.cleanClasses(list.filter((c) => !isNoiseClass(c)));
5185
5620
  let selectedElement = null;
5186
5621
  let selectedPin;
5622
+ let selectedMembers = null;
5623
+ let selectedArea = null;
5624
+ const commentedMembers = /* @__PURE__ */ new Map();
5187
5625
  let pendingShot = null;
5188
5626
  const commentedElements = /* @__PURE__ */ new Map();
5189
5627
  let editingFromMarker = false;
@@ -5245,7 +5683,9 @@ function createGrabInstance(options) {
5245
5683
  column: c.target.source?.column ?? null
5246
5684
  };
5247
5685
  }
5248
- function saveComment(element, text, shot, pin) {
5686
+ function saveComment(element, text, shot, extras = {}) {
5687
+ const { pin, members, area } = extras;
5688
+ const deps = { componentResolver, sourceResolver, cleanClasses };
5249
5689
  const now = Date.now();
5250
5690
  const comment = {
5251
5691
  id: randomId(),
@@ -5259,13 +5699,16 @@ function createGrabInstance(options) {
5259
5699
  title: document.title,
5260
5700
  viewport: [window.innerWidth, window.innerHeight]
5261
5701
  },
5262
- target: captureTarget(element, { componentResolver, sourceResolver, cleanClasses }),
5702
+ target: captureTarget(element, deps),
5263
5703
  screenshot: null,
5264
5704
  framework: adapters.frameworkFor(element),
5265
5705
  ...outbox ? { sync: "pending" } : {},
5266
- ...pin ? { pin } : {}
5706
+ ...pin ? { pin } : {},
5707
+ ...members?.length ? { members: members.map((el) => captureMember(el, deps)) } : {},
5708
+ ...area ? { area } : {}
5267
5709
  };
5268
5710
  commentedElements.set(comment.id, element);
5711
+ if (members?.length) commentedMembers.set(comment.id, members);
5269
5712
  setComments([comment, ...comments()].slice(0, MAX_COMMENTS));
5270
5713
  pluginRegistry.callHook("onComment", comment, element);
5271
5714
  outbox?.send(comment.id);
@@ -5310,7 +5753,10 @@ function createGrabInstance(options) {
5310
5753
  const idSet = new Set(ids);
5311
5754
  const before = comments();
5312
5755
  const removed = before.filter((c) => idSet.has(c.id));
5313
- for (const id of ids) commentedElements.delete(id);
5756
+ for (const id of ids) {
5757
+ commentedElements.delete(id);
5758
+ commentedMembers.delete(id);
5759
+ }
5314
5760
  setComments(before.filter((c) => !idSet.has(c.id)));
5315
5761
  const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
5316
5762
  const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
@@ -5369,16 +5815,52 @@ function createGrabInstance(options) {
5369
5815
  commentPopover.hide();
5370
5816
  endMarkerEdit();
5371
5817
  if (picker.isHolding()) {
5372
- selectedElement = null;
5373
- selectedPin = void 0;
5374
- pendingShot = null;
5818
+ clearSelection();
5375
5819
  picker.release();
5376
5820
  }
5377
5821
  }
5822
+ function clearSelection() {
5823
+ selectedElement = null;
5824
+ selectedPin = void 0;
5825
+ selectedMembers = null;
5826
+ selectedArea = null;
5827
+ pendingShot = null;
5828
+ }
5378
5829
  function endMarkerEdit() {
5379
5830
  if (!editingFromMarker) return;
5380
5831
  editingFromMarker = false;
5381
5832
  overlay.hide();
5833
+ groupOutline.hide();
5834
+ }
5835
+ function pinIn(el, point) {
5836
+ const rect = el.getBoundingClientRect();
5837
+ const frac2 = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
5838
+ return {
5839
+ x: Math.round(frac2(point.x, rect.left, rect.width) * 1e3) / 1e3,
5840
+ y: Math.round(frac2(point.y, rect.top, rect.height) * 1e3) / 1e3
5841
+ };
5842
+ }
5843
+ function groupSpecFor(comment, element) {
5844
+ if (comment.area && element) return { spec: { element, area: comment.area }, label: "Area" };
5845
+ if (!comment.members?.length) return null;
5846
+ const known = commentedMembers.get(comment.id)?.filter((el) => el.isConnected);
5847
+ const elements = known?.length ? known : comment.members.flatMap((m) => safeQuery(m.selector) ?? []);
5848
+ return elements.length ? { spec: { elements }, label: `${comment.members.length} elements` } : null;
5849
+ }
5850
+ function beginGroupComment(container, point, spec, heading, label, clip) {
5851
+ selectedElement = container;
5852
+ selectedPin = pinIn(container, point);
5853
+ pendingShot = store.state.options.screenshots ? captureScreenshot(container, clip ?? void 0) : null;
5854
+ coachMark.dismiss();
5855
+ picker.hold(container, { spec, label });
5856
+ commentPopover.show({
5857
+ anchor: container,
5858
+ anchorBox: clip,
5859
+ mode: "new",
5860
+ askIdentity: shouldAskIdentity(),
5861
+ heading,
5862
+ placeholder: "What should change here?"
5863
+ });
5382
5864
  }
5383
5865
  function closeAllPopovers() {
5384
5866
  commentsPanel.hide();
@@ -5406,6 +5888,7 @@ function createGrabInstance(options) {
5406
5888
  const picker = createElementPicker({
5407
5889
  overlay,
5408
5890
  crosshair,
5891
+ groupOutline,
5409
5892
  getComponentResolver: () => componentResolver,
5410
5893
  getSourceResolver: () => sourceResolver,
5411
5894
  isToolbarElement: isAnyToolbarElement,
@@ -5418,18 +5901,24 @@ function createGrabInstance(options) {
5418
5901
  },
5419
5902
  onSelect(element, point) {
5420
5903
  selectedElement = element;
5421
- const rect = element.getBoundingClientRect();
5422
- const frac = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
5423
- selectedPin = {
5424
- x: Math.round(frac(point.x, rect.left, rect.width) * 1e3) / 1e3,
5425
- y: Math.round(frac(point.y, rect.top, rect.height) * 1e3) / 1e3
5426
- };
5904
+ selectedPin = pinIn(element, point);
5427
5905
  pendingShot = store.state.options.screenshots ? captureScreenshot(element) : null;
5428
5906
  pluginRegistry.callHook("onElementSelect", element);
5429
5907
  coachMark.dismiss();
5430
5908
  showSelectFeedback(element);
5431
5909
  picker.hold(element);
5432
5910
  commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
5911
+ },
5912
+ onSelectGroup(elements, point) {
5913
+ selectedMembers = elements;
5914
+ const heading = describeGroup(elements.map(describeElement));
5915
+ for (const el of elements) pluginRegistry.callHook("onElementSelect", el);
5916
+ beginGroupComment(commonContainer(elements), point, { elements }, heading, `${elements.length} elements`, unionBox(elements));
5917
+ },
5918
+ onSelectArea(container, area, point) {
5919
+ selectedArea = area;
5920
+ pluginRegistry.callHook("onElementSelect", container);
5921
+ beginGroupComment(container, point, { element: container, area }, describeArea(describeElement(container)), "Area", areaToBox(container, area));
5433
5922
  }
5434
5923
  });
5435
5924
  const markers = createMarkers({
@@ -5442,20 +5931,30 @@ function createGrabInstance(options) {
5442
5931
  },
5443
5932
  onHover(comment, element) {
5444
5933
  if (picker.isHolding() || editingFromMarker || commentPopover.isVisible()) return;
5445
- if (comment && element) overlay.show(element, comment.target.component, null, []);
5446
- else overlay.hide();
5934
+ const group = comment ? groupSpecFor(comment, element) : null;
5935
+ if (group) groupOutline.show(group.spec, group.label);
5936
+ else if (comment && element) overlay.show(element, comment.target.component, null, []);
5937
+ else {
5938
+ overlay.hide();
5939
+ groupOutline.hide();
5940
+ }
5447
5941
  },
5448
5942
  onOpen(comment, element, marker) {
5449
5943
  if (picker.isHolding()) return;
5450
5944
  closeAllPopovers();
5451
5945
  doDeactivate(true);
5452
5946
  editingFromMarker = true;
5453
- if (element) overlay.show(element, comment.target.component, null, []);
5947
+ const group = groupSpecFor(comment, element);
5948
+ if (group) groupOutline.show(group.spec, group.label);
5949
+ else if (element) overlay.show(element, comment.target.component, null, []);
5950
+ const spec = group?.spec;
5454
5951
  commentPopover.show({
5455
5952
  anchor: element ?? marker,
5953
+ anchorBox: spec ? "area" in spec ? areaToBox(spec.element, spec.area) : unionBox(spec.elements) : null,
5456
5954
  initialValue: comment.comment,
5457
5955
  mode: "edit",
5458
- entryId: comment.id
5956
+ entryId: comment.id,
5957
+ heading: comment.members?.length || comment.area ? describeComment(comment) : void 0
5459
5958
  });
5460
5959
  }
5461
5960
  });
@@ -5630,12 +6129,10 @@ function createGrabInstance(options) {
5630
6129
  if (identity) saveIdentity({ name: identity.name, anonymous: !identity.name });
5631
6130
  if (ctx.mode === "new") {
5632
6131
  const element = selectedElement;
6132
+ const extras = { pin: selectedPin, members: selectedMembers, area: selectedArea };
5633
6133
  const shot = pendingShot;
5634
- const pin = selectedPin;
5635
- selectedElement = null;
5636
- selectedPin = void 0;
5637
- pendingShot = null;
5638
- if (element) saveComment(element, value, shot, pin);
6134
+ clearSelection();
6135
+ if (element) saveComment(element, value, shot, extras);
5639
6136
  doDeactivate(true);
5640
6137
  return;
5641
6138
  }
@@ -5651,9 +6148,7 @@ function createGrabInstance(options) {
5651
6148
  },
5652
6149
  onCancel(ctx) {
5653
6150
  if (ctx.mode === "new") {
5654
- selectedElement = null;
5655
- selectedPin = void 0;
5656
- pendingShot = null;
6151
+ clearSelection();
5657
6152
  doDeactivate(true);
5658
6153
  return;
5659
6154
  }
@@ -5819,6 +6314,7 @@ function createGrabInstance(options) {
5819
6314
  crosshair.dispose();
5820
6315
  freezeOverlay.dispose();
5821
6316
  markers.dispose();
6317
+ groupOutline.dispose();
5822
6318
  disposeToast();
5823
6319
  disposeFeedbackStyles();
5824
6320
  pluginRegistry.dispose();