@githumbi/grabby 0.2.1 → 0.4.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.
@@ -230,12 +230,378 @@ function disposeUiRoot() {
230
230
  root = null;
231
231
  }
232
232
 
233
+ // src/core/capture/kind.ts
234
+ var ACTION_TAGS = /* @__PURE__ */ new Set(["BUTTON", "A", "SUMMARY"]);
235
+ var ACTION_ROLES = /* @__PURE__ */ new Set(["button", "link", "tab", "menuitem", "menuitemcheckbox", "menuitemradio", "switch", "option", "checkbox", "radio"]);
236
+ var BUTTON_INPUT_TYPES = /* @__PURE__ */ new Set(["button", "submit", "reset", "image"]);
237
+ var FIELD_TAGS = /* @__PURE__ */ new Set(["INPUT", "SELECT", "TEXTAREA"]);
238
+ var FIELD_ROLES = /* @__PURE__ */ new Set(["textbox", "combobox", "searchbox", "spinbutton", "slider"]);
239
+ var MEDIA_TAGS = /* @__PURE__ */ new Set(["IMG", "SVG", "VIDEO", "PICTURE", "CANVAS", "IFRAME", "AUDIO"]);
240
+ var TEXT_TAGS = /* @__PURE__ */ new Set([
241
+ "H1",
242
+ "H2",
243
+ "H3",
244
+ "H4",
245
+ "H5",
246
+ "H6",
247
+ "P",
248
+ "SPAN",
249
+ "LABEL",
250
+ "LI",
251
+ "STRONG",
252
+ "EM",
253
+ "B",
254
+ "I",
255
+ "SMALL",
256
+ "BLOCKQUOTE",
257
+ "CODE",
258
+ "PRE",
259
+ "TD",
260
+ "TH",
261
+ "DT",
262
+ "DD",
263
+ "FIGCAPTION",
264
+ "LEGEND",
265
+ "CAPTION",
266
+ "Q",
267
+ "CITE",
268
+ "MARK",
269
+ "TIME"
270
+ ]);
271
+ var PAGE_TAGS = /* @__PURE__ */ new Set(["HTML", "BODY", "MAIN"]);
272
+ var LANDMARK_TAGS = /* @__PURE__ */ new Set(["HEADER", "FOOTER", "NAV", "ASIDE"]);
273
+ var SECTION_AREA_RATIO = 0.6;
274
+ function role(el) {
275
+ return (el.getAttribute("role") ?? "").toLowerCase();
276
+ }
277
+ function isAction(el) {
278
+ if (ACTION_TAGS.has(el.tagName)) return el.tagName !== "A" || el.hasAttribute("href") || el.hasAttribute("role");
279
+ if (el.tagName === "INPUT" && BUTTON_INPUT_TYPES.has(el.type)) return true;
280
+ return ACTION_ROLES.has(role(el));
281
+ }
282
+ function isField(el) {
283
+ if (el.tagName === "INPUT") return !BUTTON_INPUT_TYPES.has(el.type);
284
+ if (FIELD_TAGS.has(el.tagName)) return true;
285
+ if (el.isContentEditable && el.getAttribute("contenteditable") !== null) return true;
286
+ return FIELD_ROLES.has(role(el));
287
+ }
288
+ function coversViewport(el) {
289
+ const rect = el.getBoundingClientRect();
290
+ const vw = window.innerWidth || document.documentElement.clientWidth;
291
+ const vh = window.innerHeight || document.documentElement.clientHeight;
292
+ if (!vw || !vh) return false;
293
+ const w = Math.max(0, Math.min(rect.right, vw) - Math.max(rect.left, 0));
294
+ const hgt = Math.max(0, Math.min(rect.bottom, vh) - Math.max(rect.top, 0));
295
+ return w * hgt / (vw * vh) >= SECTION_AREA_RATIO;
296
+ }
297
+ function hasElementChildren(el) {
298
+ return el.children.length > 0;
299
+ }
300
+ function detectKind(el) {
301
+ if (PAGE_TAGS.has(el.tagName)) return "section";
302
+ if (MEDIA_TAGS.has(el.tagName)) return "media";
303
+ if (isField(el)) return "field";
304
+ if (isAction(el)) return "action";
305
+ if (LANDMARK_TAGS.has(el.tagName) || role(el) === "main" || role(el) === "region") {
306
+ return coversViewport(el) ? "section" : "container";
307
+ }
308
+ if (TEXT_TAGS.has(el.tagName)) return "text";
309
+ if (!hasElementChildren(el) && (el.textContent ?? "").trim()) return "text";
310
+ if (coversViewport(el)) return "section";
311
+ return "container";
312
+ }
313
+ var PROMOTE_DEPTH = 3;
314
+ function promoteTarget(el) {
315
+ if (isAction(el) || isField(el)) return el;
316
+ let current = el.parentElement;
317
+ for (let depth = 0; current && depth < PROMOTE_DEPTH; depth++) {
318
+ if (isAction(current) || isField(current)) return current;
319
+ if (PAGE_TAGS.has(current.tagName)) break;
320
+ current = current.parentElement;
321
+ }
322
+ return el;
323
+ }
324
+
325
+ // src/core/capture/redact.ts
326
+ var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
327
+ var JWT = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
328
+ var BEARER = /\b(Bearer|Basic|Token)\s+[A-Za-z0-9._~+/=-]{8,}/gi;
329
+ var LONG_NUMBER = /\b\d(?:[ -]?\d){8,}\b/g;
330
+ var OPAQUE_TOKEN = /\b[A-Za-z0-9_-]{32,}\b/g;
331
+ var SENSITIVE_PARAM = /([?&#](?:access_token|id_token|token|key|api_key|apikey|secret|password|pass|auth|code|session|sig|signature)=)[^&#\s]*/gi;
332
+ function redact(text, options = {}) {
333
+ if (!text) return text;
334
+ const scrubbed = text.replace(SENSITIVE_PARAM, "$1[redacted]").replace(JWT, "[token]").replace(BEARER, "$1 [token]");
335
+ return (options.keepEmails ? scrubbed : scrubbed.replace(EMAIL, "[email]")).replace(LONG_NUMBER, "[number]").replace(OPAQUE_TOKEN, (m) => /\d/.test(m) && /[A-Za-z]/.test(m) ? "[token]" : m);
336
+ }
337
+ function sanitizeRoute(loc, keepParams = []) {
338
+ let route = loc.pathname || "/";
339
+ if (keepParams.length > 0 && loc.search) {
340
+ const params = new URLSearchParams(loc.search);
341
+ const kept = new URLSearchParams();
342
+ for (const name of keepParams) {
343
+ const value = params.get(name);
344
+ if (value !== null) kept.set(name, value);
345
+ }
346
+ const qs = kept.toString();
347
+ if (qs) route += `?${qs}`;
348
+ }
349
+ if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
350
+ return redact(route);
351
+ }
352
+ function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
353
+ try {
354
+ const url = new URL(raw, base);
355
+ if (url.protocol === "javascript:" || url.protocol === "data:" || url.protocol === "vbscript:") return `${url.protocol}\u2026`;
356
+ const baseUrl = new URL(base);
357
+ const path = url.pathname + (url.hash.startsWith("#/") ? url.hash : "");
358
+ return redact(url.origin === baseUrl.origin ? path : `${url.host}${path}`);
359
+ } catch {
360
+ return redact(raw.split(/[?#]/)[0]);
361
+ }
362
+ }
363
+
364
+ // src/core/capture/preview.ts
365
+ var MASK_ATTR = "data-grabby-mask";
366
+ var IGNORE_ATTR = "data-grabby-ignore";
367
+ var PRIORITY_ATTRS = [
368
+ "id",
369
+ "class",
370
+ "role",
371
+ "aria-label",
372
+ "data-testid",
373
+ "data-test",
374
+ "data-cy",
375
+ "name",
376
+ "type",
377
+ "href",
378
+ "src",
379
+ "alt",
380
+ "placeholder",
381
+ "title",
382
+ "for",
383
+ "aria-expanded",
384
+ "aria-selected",
385
+ "disabled"
386
+ ];
387
+ var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src"]);
388
+ var MAX_ATTRS = 8;
389
+ var MAX_CLASS_CHARS = 60;
390
+ var MAX_ATTR_CHARS = 80;
391
+ var MAX_TEXT_CHARS = 80;
392
+ var MAX_PREVIEW_CHARS = 300;
393
+ function isNoiseAttr(name) {
394
+ return name.startsWith("_ng") || name.startsWith("ng-reflect-") || name.startsWith("data-v-") || name.startsWith("data-grabby-") || name.startsWith("data-svelte") || name === "style" || name === "value" || name.startsWith("on");
395
+ }
396
+ function isNoiseClass(name) {
397
+ return name.startsWith("ng-") || name.startsWith("_ng") || /^svelte-[a-z0-9]+$/i.test(name) || /^s-[A-Za-z0-9_-]{8,}$/.test(name);
398
+ }
399
+ function truncate(text, max) {
400
+ return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}\u2026`;
401
+ }
402
+ function isMasked(el) {
403
+ return el.closest(`[${MASK_ATTR}]`) !== null;
404
+ }
405
+ function textOf(el, max) {
406
+ if (isMasked(el)) return "[masked]";
407
+ let raw = "";
408
+ const walker = el.ownerDocument.createTreeWalker(el, NodeFilter.SHOW_TEXT);
409
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
410
+ const parent = node.parentElement;
411
+ if (parent && /^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE)$/.test(parent.tagName)) continue;
412
+ if (parent?.closest(`[${IGNORE_ATTR}], [${MASK_ATTR}]`)) continue;
413
+ raw += ` ${node.nodeValue ?? ""}`;
414
+ if (raw.length > max * 3) break;
415
+ }
416
+ return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
417
+ }
418
+ function ownText(el) {
419
+ let raw = "";
420
+ for (const node of Array.from(el.childNodes)) {
421
+ if (node.nodeType === Node.TEXT_NODE) raw += ` ${node.nodeValue ?? ""}`;
422
+ }
423
+ return raw.replace(/\s+/g, " ").trim();
424
+ }
425
+ function attrValue(el, name, value, cleanClasses) {
426
+ if (name === "class") {
427
+ const classes = cleanClasses(value.split(/\s+/).filter(Boolean));
428
+ if (classes.length === 0) return null;
429
+ return truncate(classes.join(" "), MAX_CLASS_CHARS);
430
+ }
431
+ if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
432
+ return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
433
+ }
434
+ function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
435
+ const tag = el.tagName.toLowerCase();
436
+ const attrs = [];
437
+ const seen2 = /* @__PURE__ */ new Set();
438
+ const add = (name) => {
439
+ if (attrs.length >= MAX_ATTRS || seen2.has(name) || isNoiseAttr(name)) return;
440
+ const raw = el.getAttribute(name);
441
+ if (raw === null) return;
442
+ seen2.add(name);
443
+ if (raw === "") {
444
+ attrs.push(name);
445
+ return;
446
+ }
447
+ const value = attrValue(el, name, raw, cleanClasses);
448
+ if (value !== null) attrs.push(`${name}="${value.replace(/"/g, "&quot;")}"`);
449
+ };
450
+ for (const name of PRIORITY_ATTRS) add(name);
451
+ for (const { name } of Array.from(el.attributes)) {
452
+ if (name.startsWith("aria-")) add(name);
453
+ }
454
+ return `<${tag}${attrs.length ? ` ${attrs.join(" ")}` : ""}>`;
455
+ }
456
+ function buildPreview(el, cleanClasses) {
457
+ const tag = el.tagName.toLowerCase();
458
+ const open = openingTag(el, cleanClasses);
459
+ if (/^(img|input|br|hr|meta|link|source|area|col|embed|wbr)$/.test(tag)) {
460
+ return truncate(open, MAX_PREVIEW_CHARS);
461
+ }
462
+ const children = Array.from(el.children).filter((c) => !c.hasAttribute(IGNORE_ATTR));
463
+ let inner;
464
+ if (isMasked(el)) {
465
+ inner = "[masked]";
466
+ } else if (children.length === 0) {
467
+ inner = truncate(redact(ownText(el)), MAX_TEXT_CHARS);
468
+ } else if (children.length <= 2) {
469
+ const text = truncate(redact(ownText(el)), 40);
470
+ const kids = children.map((c) => {
471
+ const t = textOf(c, 30);
472
+ return `<${c.tagName.toLowerCase()}${t ? `>${t}</${c.tagName.toLowerCase()}>` : " \u2026>"}`;
473
+ });
474
+ inner = [text, ...kids].filter(Boolean).join(" ");
475
+ } else {
476
+ inner = `(${children.length} elements)`;
477
+ }
478
+ return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
479
+ }
480
+
481
+ // src/core/capture/describe.ts
482
+ var MAX_NAME = 40;
483
+ var HEADING = /^h[1-6]$/;
484
+ function role2(el) {
485
+ return (el.getAttribute("role") ?? "").toLowerCase();
486
+ }
487
+ function hasBox(el) {
488
+ try {
489
+ const s = getComputedStyle(el);
490
+ const bordered = s.borderStyle !== "none" && parseFloat(s.borderWidth) > 0;
491
+ const shadow = !!s.boxShadow && s.boxShadow !== "none";
492
+ return shadow || bordered && parseFloat(s.borderRadius) > 0;
493
+ } catch {
494
+ return false;
495
+ }
496
+ }
497
+ function nounFor(tag, kind, r = "", inputType = "", boxed = false, titled = false) {
498
+ switch (kind) {
499
+ case "action":
500
+ if (r === "tab") return "Tab";
501
+ if (r.startsWith("menuitem")) return "Menu item";
502
+ if (r === "checkbox" || inputType === "checkbox") return "Checkbox";
503
+ if (r === "radio" || r === "option" || inputType === "radio") return "Option";
504
+ if (r === "switch") return "Switch";
505
+ if (tag === "a" || r === "link") return "Link";
506
+ return "Button";
507
+ case "field":
508
+ if (tag === "select" || r === "combobox") return "Dropdown";
509
+ if (tag === "textarea") return "Text area";
510
+ if (inputType === "checkbox") return "Checkbox";
511
+ if (inputType === "radio") return "Option";
512
+ if (inputType === "range" || r === "slider") return "Slider";
513
+ if (inputType === "file") return "File upload";
514
+ if (inputType === "search" || r === "searchbox") return "Search box";
515
+ if (/^(date|datetime-local|month|week|time)$/.test(inputType)) return "Date picker";
516
+ return "Text box";
517
+ case "media":
518
+ if (tag === "svg") return "Icon";
519
+ if (tag === "video") return "Video";
520
+ if (tag === "audio") return "Audio player";
521
+ if (tag === "iframe") return "Embedded content";
522
+ if (tag === "canvas") return "Chart or drawing";
523
+ return "Image";
524
+ case "text":
525
+ if (HEADING.test(tag) || r === "heading") return "Heading";
526
+ if (tag === "li") return "List item";
527
+ if (tag === "label") return "Label";
528
+ if (tag === "td" || tag === "th") return "Table cell";
529
+ if (tag === "blockquote" || tag === "q") return "Quote";
530
+ if (tag === "code" || tag === "pre") return "Code";
531
+ return "Text";
532
+ case "section":
533
+ if (tag === "html" || tag === "body") return "Whole page";
534
+ if (tag === "main" || r === "main") return "Main content";
535
+ if (tag === "header") return "Page header";
536
+ if (tag === "footer") return "Page footer";
537
+ if (tag === "nav") return "Navigation menu";
538
+ return "Page section";
539
+ default:
540
+ if (tag === "nav" || r === "navigation" || r === "menu" || r === "menubar") return "Menu";
541
+ if (tag === "header") return "Header";
542
+ if (tag === "footer") return "Footer";
543
+ if (tag === "aside") return "Sidebar";
544
+ if (tag === "form" || r === "form") return "Form";
545
+ if (tag === "table" || r === "table" || r === "grid") return "Table";
546
+ if (tag === "ul" || tag === "ol" || r === "list") return "List";
547
+ if (tag === "dialog" || r === "dialog" || r === "alertdialog") return "Pop-up";
548
+ if (boxed) return "Card";
549
+ if (titled) return "Section";
550
+ return "Area";
551
+ }
552
+ }
553
+ function fieldName(el) {
554
+ const labels = el.labels;
555
+ if (labels && labels.length) return textOf(labels[0], MAX_NAME);
556
+ return redact(el.getAttribute("aria-label") ?? "") || redact(el.getAttribute("placeholder") ?? "");
557
+ }
558
+ function firstHeading(el) {
559
+ return el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
560
+ }
561
+ function nameOf(el, kind) {
562
+ if (isMasked(el) || el.tagName === "BODY" || el.tagName === "HTML") return "";
563
+ const aria = redact(el.getAttribute("aria-label") ?? "");
564
+ switch (kind) {
565
+ case "action":
566
+ return aria || textOf(el, MAX_NAME) || redact(el.getAttribute("title") ?? "") || redact(el.querySelector("img[alt]")?.getAttribute("alt") ?? "");
567
+ case "field":
568
+ return fieldName(el);
569
+ case "media":
570
+ return redact(el.getAttribute("alt") ?? "") || aria || redact(el.getAttribute("title") ?? "");
571
+ case "text":
572
+ return textOf(el, MAX_NAME);
573
+ default: {
574
+ const heading = firstHeading(el);
575
+ return aria || (heading ? textOf(heading, MAX_NAME) : "");
576
+ }
577
+ }
578
+ }
579
+ function quoted(noun, name) {
580
+ const clean = truncate(name.replace(/\s+/g, " ").trim(), MAX_NAME);
581
+ return clean ? `${noun} \u201C${clean}\u201D` : noun;
582
+ }
583
+ function describeElement(el) {
584
+ const tag = el.tagName.toLowerCase();
585
+ const kind = tag === "svg" ? "media" : detectKind(el);
586
+ const r = role2(el);
587
+ const inputType = tag === "input" ? (el.type || "").toLowerCase() : "";
588
+ const container = kind === "container";
589
+ const noun = nounFor(tag, kind, r, inputType, container && hasBox(el), container && !!firstHeading(el));
590
+ return quoted(noun, nameOf(el, kind));
591
+ }
592
+ function describeTarget(target) {
593
+ const facts = target.facts ?? {};
594
+ const noun = nounFor(target.tag, target.kind, "", (facts.type ?? "").toLowerCase(), false, !!facts.heading);
595
+ const name = facts.label || facts.heading || facts.text || facts.alt || "";
596
+ return quoted(noun, name);
597
+ }
598
+
233
599
  // src/core/overlay/overlay-renderer.ts
234
600
  var OVERLAY_ID = "__grabby-overlay__";
235
601
  var LABEL_ID = "__grabby-label__";
236
602
  var STYLE_ID = "__grabby-styles__";
237
603
  var MAX_LABEL_CLASSES = 3;
238
- function createOverlayRenderer() {
604
+ function createOverlayRenderer(options = {}) {
239
605
  let overlay = null;
240
606
  let label = null;
241
607
  let rafId = null;
@@ -243,6 +609,7 @@ function createOverlayRenderer() {
243
609
  let currentComponentName = null;
244
610
  let currentSourcePath = null;
245
611
  let currentCssClasses = [];
612
+ let currentPlainLabel = "";
246
613
  function injectStyles2() {
247
614
  if (hasStyles(STYLE_ID)) return;
248
615
  addStyles(STYLE_ID, `
@@ -270,6 +637,11 @@ function createOverlayRenderer() {
270
637
  overflow: hidden;
271
638
  text-overflow: ellipsis;
272
639
  }
640
+ #${LABEL_ID}.grabby-plain {
641
+ font: 600 12px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
642
+ padding: 3px 8px;
643
+ border-radius: 6px;
644
+ }
273
645
  `);
274
646
  }
275
647
  function ensureElements() {
@@ -282,6 +654,7 @@ function createOverlayRenderer() {
282
654
  if (!label) {
283
655
  label = document.createElement("div");
284
656
  label.id = LABEL_ID;
657
+ if (options.plainLabels) label.className = "grabby-plain";
285
658
  getUiRoot().appendChild(label);
286
659
  }
287
660
  }
@@ -300,6 +673,11 @@ function createOverlayRenderer() {
300
673
  overlay.style.display = "block";
301
674
  const tag = currentElement.tagName.toLowerCase();
302
675
  let labelText = `<${tag}>`;
676
+ if (options.plainLabels) {
677
+ label.textContent = `${currentPlainLabel} \xB7 Click to select`;
678
+ placeLabel(rect);
679
+ return;
680
+ }
303
681
  if (currentCssClasses.length > 0) {
304
682
  const shown = currentCssClasses.slice(0, MAX_LABEL_CLASSES);
305
683
  labelText += ` .${shown.join(".")}${currentCssClasses.length > shown.length ? "\u2026" : ""}`;
@@ -311,6 +689,10 @@ function createOverlayRenderer() {
311
689
  labelText += ` \u2014 ${currentSourcePath}`;
312
690
  }
313
691
  label.textContent = labelText;
692
+ placeLabel(rect);
693
+ }
694
+ function placeLabel(rect) {
695
+ if (!label) return;
314
696
  const labelHeight = 20;
315
697
  const gap = 4;
316
698
  let labelTop = rect.top - labelHeight - gap;
@@ -343,6 +725,7 @@ function createOverlayRenderer() {
343
725
  ensureElements();
344
726
  currentElement = element;
345
727
  currentComponentName = componentName;
728
+ if (options.plainLabels) currentPlainLabel = describeElement(element);
346
729
  currentSourcePath = sourcePath ?? null;
347
730
  currentCssClasses = cssClasses ?? [];
348
731
  stopTracking();
@@ -384,6 +767,7 @@ function createCrosshair() {
384
767
  let hLine = null;
385
768
  let vLine = null;
386
769
  let listening = false;
770
+ let held = false;
387
771
  function injectStyles2() {
388
772
  if (hasStyles(CROSSHAIR_STYLE_ID)) return;
389
773
  addStyles(CROSSHAIR_STYLE_ID, `
@@ -406,7 +790,7 @@ function createCrosshair() {
406
790
  width: 1px;
407
791
  }
408
792
  `);
409
- addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active { cursor: crosshair !important; }", "document");
793
+ addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active:not(.grabby-crosshair-held) { cursor: crosshair !important; }", "document");
410
794
  }
411
795
  function ensureElements() {
412
796
  if (!hLine) {
@@ -423,7 +807,12 @@ function createCrosshair() {
423
807
  getUiRoot().appendChild(vLine);
424
808
  }
425
809
  }
810
+ function hideLines() {
811
+ if (hLine) hLine.style.top = "-10px";
812
+ if (vLine) vLine.style.left = "-10px";
813
+ }
426
814
  function handleMouseMove(e) {
815
+ if (held) return;
427
816
  if (hLine) {
428
817
  hLine.style.top = `${e.clientY}px`;
429
818
  }
@@ -444,13 +833,19 @@ function createCrosshair() {
444
833
  listening = false;
445
834
  document.body.classList.remove("grabby-crosshair-active");
446
835
  document.removeEventListener("mousemove", handleMouseMove, true);
447
- if (hLine) hLine.style.top = "-10px";
448
- if (vLine) vLine.style.left = "-10px";
836
+ hideLines();
837
+ },
838
+ hold(on) {
839
+ if (held === on) return;
840
+ held = on;
841
+ document.body.classList.toggle("grabby-crosshair-held", on);
842
+ if (on) hideLines();
449
843
  },
450
844
  isCrosshairElement(el) {
451
845
  return el === hLine || el === vLine || el.id === H_LINE_ID || el.id === V_LINE_ID;
452
846
  },
453
847
  dispose() {
848
+ this.hold(false);
454
849
  this.deactivate();
455
850
  hLine?.remove();
456
851
  vLine?.remove();
@@ -742,365 +1137,118 @@ function showToast(message, opts = {}) {
742
1137
  void toast.offsetHeight;
743
1138
  toast.classList.add("grabby-toast-visible");
744
1139
  activeTimer = setTimeout(() => {
745
- toast.classList.remove("grabby-toast-visible");
746
- activeTimer = null;
747
- }, durationMs);
748
- }
749
- function hideToast() {
750
- if (activeTimer) {
751
- clearTimeout(activeTimer);
752
- activeTimer = null;
753
- }
754
- toastEl?.classList.remove("grabby-toast-visible");
755
- }
756
- function disposeToast() {
757
- if (activeTimer) {
758
- clearTimeout(activeTimer);
759
- activeTimer = null;
760
- }
761
- toastEl?.remove();
762
- toastEl = null;
763
- removeStyles(TOAST_STYLE_ID);
764
- }
765
-
766
- // src/core/utils.ts
767
- function filterAngularClasses(classList) {
768
- return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
769
- }
770
- function cssEscape(value) {
771
- if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
772
- let out = "";
773
- for (let i = 0; i < value.length; i++) {
774
- const ch = value.charAt(i);
775
- const code = value.charCodeAt(i);
776
- if (code === 0) {
777
- out += "\uFFFD";
778
- continue;
779
- }
780
- if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
781
- out += `\\${code.toString(16)} `;
782
- continue;
783
- }
784
- if (i === 0 && value.length === 1 && code === 45) {
785
- out += `\\${ch}`;
786
- continue;
787
- }
788
- if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
789
- out += ch;
790
- continue;
791
- }
792
- out += `\\${ch}`;
793
- }
794
- return out;
795
- }
796
- function safeQuery(selector, root2 = document) {
797
- if (!selector) return null;
798
- try {
799
- return root2.querySelector(selector);
800
- } catch {
801
- return null;
802
- }
803
- }
804
- var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
805
- var MAX_SELECTOR_DEPTH = 8;
806
- function isUnique(selector, el) {
807
- try {
808
- const matches = el.ownerDocument.querySelectorAll(selector);
809
- return matches.length === 1 && matches[0] === el;
810
- } catch {
811
- return false;
812
- }
813
- }
814
- function stepFor(el) {
815
- const tag = el.tagName.toLowerCase();
816
- const parent = el.parentElement;
817
- if (!parent) return tag;
818
- const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
819
- if (sameTag.length === 1) return tag;
820
- return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
821
- }
822
- function buildUniqueSelector(el) {
823
- for (const attr of TEST_ID_ATTRS) {
824
- const value = el.getAttribute(attr);
825
- if (value) {
826
- const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
827
- if (isUnique(sel, el)) return sel;
828
- }
829
- }
830
- if (el.id) {
831
- const sel = `#${cssEscape(el.id)}`;
832
- if (isUnique(sel, el)) return sel;
833
- }
834
- const steps = [];
835
- let current = el;
836
- while (current && steps.length < MAX_SELECTOR_DEPTH) {
837
- if (current !== el && current.id) {
838
- const anchor = `#${cssEscape(current.id)}`;
839
- if (isUnique(anchor, current)) {
840
- steps.unshift(anchor);
841
- break;
842
- }
843
- }
844
- steps.unshift(stepFor(current));
845
- const sel = steps.join(" > ");
846
- if (isUnique(sel, el)) return sel;
847
- if (current.tagName === "BODY" || current.tagName === "HTML") break;
848
- current = current.parentElement;
849
- }
850
- return steps.join(" > ");
851
- }
852
-
853
- // src/core/capture/kind.ts
854
- var ACTION_TAGS = /* @__PURE__ */ new Set(["BUTTON", "A", "SUMMARY"]);
855
- var ACTION_ROLES = /* @__PURE__ */ new Set(["button", "link", "tab", "menuitem", "menuitemcheckbox", "menuitemradio", "switch", "option", "checkbox", "radio"]);
856
- var BUTTON_INPUT_TYPES = /* @__PURE__ */ new Set(["button", "submit", "reset", "image"]);
857
- var FIELD_TAGS = /* @__PURE__ */ new Set(["INPUT", "SELECT", "TEXTAREA"]);
858
- var FIELD_ROLES = /* @__PURE__ */ new Set(["textbox", "combobox", "searchbox", "spinbutton", "slider"]);
859
- var MEDIA_TAGS = /* @__PURE__ */ new Set(["IMG", "SVG", "VIDEO", "PICTURE", "CANVAS", "IFRAME", "AUDIO"]);
860
- var TEXT_TAGS = /* @__PURE__ */ new Set([
861
- "H1",
862
- "H2",
863
- "H3",
864
- "H4",
865
- "H5",
866
- "H6",
867
- "P",
868
- "SPAN",
869
- "LABEL",
870
- "LI",
871
- "STRONG",
872
- "EM",
873
- "B",
874
- "I",
875
- "SMALL",
876
- "BLOCKQUOTE",
877
- "CODE",
878
- "PRE",
879
- "TD",
880
- "TH",
881
- "DT",
882
- "DD",
883
- "FIGCAPTION",
884
- "LEGEND",
885
- "CAPTION",
886
- "Q",
887
- "CITE",
888
- "MARK",
889
- "TIME"
890
- ]);
891
- var PAGE_TAGS = /* @__PURE__ */ new Set(["HTML", "BODY", "MAIN"]);
892
- var LANDMARK_TAGS = /* @__PURE__ */ new Set(["HEADER", "FOOTER", "NAV", "ASIDE"]);
893
- var SECTION_AREA_RATIO = 0.6;
894
- function role(el) {
895
- return (el.getAttribute("role") ?? "").toLowerCase();
896
- }
897
- function isAction(el) {
898
- if (ACTION_TAGS.has(el.tagName)) return el.tagName !== "A" || el.hasAttribute("href") || el.hasAttribute("role");
899
- if (el.tagName === "INPUT" && BUTTON_INPUT_TYPES.has(el.type)) return true;
900
- return ACTION_ROLES.has(role(el));
901
- }
902
- function isField(el) {
903
- if (el.tagName === "INPUT") return !BUTTON_INPUT_TYPES.has(el.type);
904
- if (FIELD_TAGS.has(el.tagName)) return true;
905
- if (el.isContentEditable && el.getAttribute("contenteditable") !== null) return true;
906
- return FIELD_ROLES.has(role(el));
907
- }
908
- function coversViewport(el) {
909
- const rect = el.getBoundingClientRect();
910
- const vw = window.innerWidth || document.documentElement.clientWidth;
911
- const vh = window.innerHeight || document.documentElement.clientHeight;
912
- if (!vw || !vh) return false;
913
- const w = Math.max(0, Math.min(rect.right, vw) - Math.max(rect.left, 0));
914
- const hgt = Math.max(0, Math.min(rect.bottom, vh) - Math.max(rect.top, 0));
915
- return w * hgt / (vw * vh) >= SECTION_AREA_RATIO;
916
- }
917
- function hasElementChildren(el) {
918
- return el.children.length > 0;
919
- }
920
- function detectKind(el) {
921
- if (PAGE_TAGS.has(el.tagName)) return "section";
922
- if (MEDIA_TAGS.has(el.tagName)) return "media";
923
- if (isField(el)) return "field";
924
- if (isAction(el)) return "action";
925
- if (LANDMARK_TAGS.has(el.tagName) || role(el) === "main" || role(el) === "region") {
926
- return coversViewport(el) ? "section" : "container";
927
- }
928
- if (TEXT_TAGS.has(el.tagName)) return "text";
929
- if (!hasElementChildren(el) && (el.textContent ?? "").trim()) return "text";
930
- if (coversViewport(el)) return "section";
931
- return "container";
932
- }
933
- var PROMOTE_DEPTH = 3;
934
- function promoteTarget(el) {
935
- if (isAction(el) || isField(el)) return el;
936
- let current = el.parentElement;
937
- for (let depth = 0; current && depth < PROMOTE_DEPTH; depth++) {
938
- if (isAction(current) || isField(current)) return current;
939
- if (PAGE_TAGS.has(current.tagName)) break;
940
- current = current.parentElement;
941
- }
942
- return el;
943
- }
944
-
945
- // src/core/capture/redact.ts
946
- var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
947
- var JWT = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
948
- var BEARER = /\b(Bearer|Basic|Token)\s+[A-Za-z0-9._~+/=-]{8,}/gi;
949
- var LONG_NUMBER = /\b\d(?:[ -]?\d){8,}\b/g;
950
- var OPAQUE_TOKEN = /\b[A-Za-z0-9_-]{32,}\b/g;
951
- var SENSITIVE_PARAM = /([?&#](?:access_token|id_token|token|key|api_key|apikey|secret|password|pass|auth|code|session|sig|signature)=)[^&#\s]*/gi;
952
- function redact(text, options = {}) {
953
- if (!text) return text;
954
- const scrubbed = text.replace(SENSITIVE_PARAM, "$1[redacted]").replace(JWT, "[token]").replace(BEARER, "$1 [token]");
955
- return (options.keepEmails ? scrubbed : scrubbed.replace(EMAIL, "[email]")).replace(LONG_NUMBER, "[number]").replace(OPAQUE_TOKEN, (m) => /\d/.test(m) && /[A-Za-z]/.test(m) ? "[token]" : m);
956
- }
957
- function sanitizeRoute(loc, keepParams = []) {
958
- let route = loc.pathname || "/";
959
- if (keepParams.length > 0 && loc.search) {
960
- const params = new URLSearchParams(loc.search);
961
- const kept = new URLSearchParams();
962
- for (const name of keepParams) {
963
- const value = params.get(name);
964
- if (value !== null) kept.set(name, value);
965
- }
966
- const qs = kept.toString();
967
- if (qs) route += `?${qs}`;
1140
+ toast.classList.remove("grabby-toast-visible");
1141
+ activeTimer = null;
1142
+ }, durationMs);
1143
+ }
1144
+ function hideToast() {
1145
+ if (activeTimer) {
1146
+ clearTimeout(activeTimer);
1147
+ activeTimer = null;
968
1148
  }
969
- if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
970
- return redact(route);
1149
+ toastEl?.classList.remove("grabby-toast-visible");
971
1150
  }
972
- function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
973
- try {
974
- const url = new URL(raw, base);
975
- if (url.protocol === "javascript:" || url.protocol === "data:" || url.protocol === "vbscript:") return `${url.protocol}\u2026`;
976
- const baseUrl = new URL(base);
977
- const path = url.pathname + (url.hash.startsWith("#/") ? url.hash : "");
978
- return redact(url.origin === baseUrl.origin ? path : `${url.host}${path}`);
979
- } catch {
980
- return redact(raw.split(/[?#]/)[0]);
1151
+ function disposeToast() {
1152
+ if (activeTimer) {
1153
+ clearTimeout(activeTimer);
1154
+ activeTimer = null;
981
1155
  }
1156
+ toastEl?.remove();
1157
+ toastEl = null;
1158
+ removeStyles(TOAST_STYLE_ID);
982
1159
  }
983
1160
 
984
- // src/core/capture/preview.ts
985
- var MASK_ATTR = "data-grabby-mask";
986
- var IGNORE_ATTR = "data-grabby-ignore";
987
- var PRIORITY_ATTRS = [
988
- "id",
989
- "class",
990
- "role",
991
- "aria-label",
992
- "data-testid",
993
- "data-test",
994
- "data-cy",
995
- "name",
996
- "type",
997
- "href",
998
- "src",
999
- "alt",
1000
- "placeholder",
1001
- "title",
1002
- "for",
1003
- "aria-expanded",
1004
- "aria-selected",
1005
- "disabled"
1006
- ];
1007
- var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src"]);
1008
- var MAX_ATTRS = 8;
1009
- var MAX_CLASS_CHARS = 60;
1010
- var MAX_ATTR_CHARS = 80;
1011
- var MAX_TEXT_CHARS = 80;
1012
- var MAX_PREVIEW_CHARS = 300;
1013
- function isNoiseAttr(name) {
1014
- return name.startsWith("_ng") || name.startsWith("ng-reflect-") || name.startsWith("data-v-") || name.startsWith("data-grabby-") || name.startsWith("data-svelte") || name === "style" || name === "value" || name.startsWith("on");
1015
- }
1016
- function isNoiseClass(name) {
1017
- return name.startsWith("ng-") || name.startsWith("_ng") || /^svelte-[a-z0-9]+$/i.test(name) || /^s-[A-Za-z0-9_-]{8,}$/.test(name);
1018
- }
1019
- function truncate(text, max) {
1020
- return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}\u2026`;
1021
- }
1022
- function isMasked(el) {
1023
- return el.closest(`[${MASK_ATTR}]`) !== null;
1161
+ // src/core/utils.ts
1162
+ function filterAngularClasses(classList) {
1163
+ return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
1024
1164
  }
1025
- function textOf(el, max) {
1026
- if (isMasked(el)) return "[masked]";
1027
- let raw = "";
1028
- const walker = el.ownerDocument.createTreeWalker(el, NodeFilter.SHOW_TEXT);
1029
- for (let node = walker.nextNode(); node; node = walker.nextNode()) {
1030
- const parent = node.parentElement;
1031
- if (parent && /^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE)$/.test(parent.tagName)) continue;
1032
- if (parent?.closest(`[${IGNORE_ATTR}], [${MASK_ATTR}]`)) continue;
1033
- raw += ` ${node.nodeValue ?? ""}`;
1034
- if (raw.length > max * 3) break;
1165
+ function cssEscape(value) {
1166
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
1167
+ let out = "";
1168
+ for (let i = 0; i < value.length; i++) {
1169
+ const ch = value.charAt(i);
1170
+ const code = value.charCodeAt(i);
1171
+ if (code === 0) {
1172
+ out += "\uFFFD";
1173
+ continue;
1174
+ }
1175
+ if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
1176
+ out += `\\${code.toString(16)} `;
1177
+ continue;
1178
+ }
1179
+ if (i === 0 && value.length === 1 && code === 45) {
1180
+ out += `\\${ch}`;
1181
+ continue;
1182
+ }
1183
+ if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
1184
+ out += ch;
1185
+ continue;
1186
+ }
1187
+ out += `\\${ch}`;
1035
1188
  }
1036
- return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
1189
+ return out;
1037
1190
  }
1038
- function ownText(el) {
1039
- let raw = "";
1040
- for (const node of Array.from(el.childNodes)) {
1041
- if (node.nodeType === Node.TEXT_NODE) raw += ` ${node.nodeValue ?? ""}`;
1191
+ function safeQuery(selector, root2 = document) {
1192
+ if (!selector) return null;
1193
+ try {
1194
+ return root2.querySelector(selector);
1195
+ } catch {
1196
+ return null;
1042
1197
  }
1043
- return raw.replace(/\s+/g, " ").trim();
1044
1198
  }
1045
- function attrValue(el, name, value, cleanClasses) {
1046
- if (name === "class") {
1047
- const classes = cleanClasses(value.split(/\s+/).filter(Boolean));
1048
- if (classes.length === 0) return null;
1049
- return truncate(classes.join(" "), MAX_CLASS_CHARS);
1199
+ var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
1200
+ var MAX_SELECTOR_DEPTH = 8;
1201
+ function isUnique(selector, el) {
1202
+ try {
1203
+ const matches = el.ownerDocument.querySelectorAll(selector);
1204
+ return matches.length === 1 && matches[0] === el;
1205
+ } catch {
1206
+ return false;
1050
1207
  }
1051
- if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
1052
- return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
1053
1208
  }
1054
- function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
1209
+ function stepFor(el) {
1055
1210
  const tag = el.tagName.toLowerCase();
1056
- const attrs = [];
1057
- const seen2 = /* @__PURE__ */ new Set();
1058
- const add = (name) => {
1059
- if (attrs.length >= MAX_ATTRS || seen2.has(name) || isNoiseAttr(name)) return;
1060
- const raw = el.getAttribute(name);
1061
- if (raw === null) return;
1062
- seen2.add(name);
1063
- if (raw === "") {
1064
- attrs.push(name);
1065
- return;
1211
+ const parent = el.parentElement;
1212
+ if (!parent) return tag;
1213
+ const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
1214
+ if (sameTag.length === 1) return tag;
1215
+ return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
1216
+ }
1217
+ function buildUniqueSelector(el) {
1218
+ for (const attr of TEST_ID_ATTRS) {
1219
+ const value = el.getAttribute(attr);
1220
+ if (value) {
1221
+ const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
1222
+ if (isUnique(sel, el)) return sel;
1066
1223
  }
1067
- const value = attrValue(el, name, raw, cleanClasses);
1068
- if (value !== null) attrs.push(`${name}="${value.replace(/"/g, "&quot;")}"`);
1069
- };
1070
- for (const name of PRIORITY_ATTRS) add(name);
1071
- for (const { name } of Array.from(el.attributes)) {
1072
- if (name.startsWith("aria-")) add(name);
1073
1224
  }
1074
- return `<${tag}${attrs.length ? ` ${attrs.join(" ")}` : ""}>`;
1075
- }
1076
- function buildPreview(el, cleanClasses) {
1077
- const tag = el.tagName.toLowerCase();
1078
- const open = openingTag(el, cleanClasses);
1079
- if (/^(img|input|br|hr|meta|link|source|area|col|embed|wbr)$/.test(tag)) {
1080
- return truncate(open, MAX_PREVIEW_CHARS);
1225
+ if (el.id) {
1226
+ const sel = `#${cssEscape(el.id)}`;
1227
+ if (isUnique(sel, el)) return sel;
1081
1228
  }
1082
- const children = Array.from(el.children).filter((c) => !c.hasAttribute(IGNORE_ATTR));
1083
- let inner;
1084
- if (isMasked(el)) {
1085
- inner = "[masked]";
1086
- } else if (children.length === 0) {
1087
- inner = truncate(redact(ownText(el)), MAX_TEXT_CHARS);
1088
- } else if (children.length <= 2) {
1089
- const text = truncate(redact(ownText(el)), 40);
1090
- const kids = children.map((c) => {
1091
- const t = textOf(c, 30);
1092
- return `<${c.tagName.toLowerCase()}${t ? `>${t}</${c.tagName.toLowerCase()}>` : " \u2026>"}`;
1093
- });
1094
- inner = [text, ...kids].filter(Boolean).join(" ");
1095
- } else {
1096
- inner = `(${children.length} elements)`;
1229
+ const steps = [];
1230
+ let current = el;
1231
+ while (current && steps.length < MAX_SELECTOR_DEPTH) {
1232
+ if (current !== el && current.id) {
1233
+ const anchor = `#${cssEscape(current.id)}`;
1234
+ if (isUnique(anchor, current)) {
1235
+ steps.unshift(anchor);
1236
+ break;
1237
+ }
1238
+ }
1239
+ steps.unshift(stepFor(current));
1240
+ const sel = steps.join(" > ");
1241
+ if (isUnique(sel, el)) return sel;
1242
+ if (current.tagName === "BODY" || current.tagName === "HTML") break;
1243
+ current = current.parentElement;
1097
1244
  }
1098
- return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
1245
+ return steps.join(" > ");
1099
1246
  }
1100
1247
 
1101
1248
  // src/core/picker/element-picker.ts
1102
1249
  function createElementPicker(deps) {
1103
1250
  let hoveredElement = null;
1251
+ let heldElement = null;
1104
1252
  let listening = false;
1105
1253
  function resolveComponentName(el) {
1106
1254
  const resolver = deps.getComponentResolver();
@@ -1131,17 +1279,21 @@ function createElementPicker(deps) {
1131
1279
  if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
1132
1280
  return exact ? raw : promoteTarget(raw);
1133
1281
  }
1282
+ function showOverlay(target) {
1283
+ const componentName = resolveComponentName(target);
1284
+ const sourcePath = resolveSourcePath(target);
1285
+ const cssClasses = filterAngularClasses(target.classList);
1286
+ deps.overlay.show(target, componentName, sourcePath, cssClasses);
1287
+ }
1134
1288
  function handleMouseMove(e) {
1289
+ if (heldElement) return;
1135
1290
  const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
1136
1291
  if (!target || deps.overlay.isOverlayElement(target)) return;
1137
1292
  if (deps.crosshair.isCrosshairElement(target)) return;
1138
1293
  if (deps.isToolbarElement?.(target)) return;
1139
1294
  if (target === hoveredElement) return;
1140
1295
  hoveredElement = target;
1141
- const componentName = resolveComponentName(target);
1142
- const sourcePath = resolveSourcePath(target);
1143
- const cssClasses = filterAngularClasses(target.classList);
1144
- deps.overlay.show(target, componentName, sourcePath, cssClasses);
1296
+ showOverlay(target);
1145
1297
  deps.onHover(target);
1146
1298
  }
1147
1299
  function handleClick(e) {
@@ -1151,6 +1303,7 @@ function createElementPicker(deps) {
1151
1303
  if (target && (deps.isToolbarElement?.(target) || deps.crosshair.isCrosshairElement(target))) return;
1152
1304
  e.preventDefault();
1153
1305
  e.stopPropagation();
1306
+ if (heldElement) return;
1154
1307
  if (hoveredElement) {
1155
1308
  deps.onSelect(hoveredElement);
1156
1309
  }
@@ -1167,12 +1320,29 @@ function createElementPicker(deps) {
1167
1320
  if (!listening) return;
1168
1321
  listening = false;
1169
1322
  hoveredElement = null;
1323
+ heldElement = null;
1324
+ deps.crosshair.hold(false);
1170
1325
  deps.crosshair.deactivate();
1171
1326
  document.removeEventListener("mousemove", handleMouseMove, true);
1172
1327
  document.removeEventListener("click", handleClick, true);
1173
1328
  deps.overlay.hide();
1174
1329
  deps.onHover(null);
1175
1330
  },
1331
+ hold(element) {
1332
+ if (!listening) return;
1333
+ heldElement = element;
1334
+ hoveredElement = element;
1335
+ deps.crosshair.hold(true);
1336
+ showOverlay(element);
1337
+ },
1338
+ release() {
1339
+ if (!heldElement) return;
1340
+ heldElement = null;
1341
+ deps.crosshair.hold(false);
1342
+ },
1343
+ isHolding() {
1344
+ return heldElement !== null;
1345
+ },
1176
1346
  getHoveredElement() {
1177
1347
  return hoveredElement;
1178
1348
  },
@@ -1225,6 +1395,7 @@ function matchesCombo(e, parsed) {
1225
1395
  function createKeyboardHandler(deps) {
1226
1396
  let holdTimer = null;
1227
1397
  let holdActivated = false;
1398
+ let togglePending = false;
1228
1399
  let listening = false;
1229
1400
  function handleKeyDown(e) {
1230
1401
  if (!deps.getEnableInInputs() && isEditableElement(eventTarget(e))) return;
@@ -1247,6 +1418,7 @@ function createKeyboardHandler(deps) {
1247
1418
  }
1248
1419
  } else {
1249
1420
  e.preventDefault();
1421
+ togglePending = true;
1250
1422
  }
1251
1423
  }
1252
1424
  function handleKeyUp(e) {
@@ -1263,6 +1435,8 @@ function createKeyboardHandler(deps) {
1263
1435
  deps.onDeactivate();
1264
1436
  }
1265
1437
  } else {
1438
+ if (!togglePending) return;
1439
+ togglePending = false;
1266
1440
  if (deps.isActive()) {
1267
1441
  deps.onDeactivate();
1268
1442
  } else {
@@ -1285,6 +1459,7 @@ function createKeyboardHandler(deps) {
1285
1459
  holdTimer = null;
1286
1460
  }
1287
1461
  holdActivated = false;
1462
+ togglePending = false;
1288
1463
  document.removeEventListener("keydown", handleKeyDown, true);
1289
1464
  document.removeEventListener("keyup", handleKeyUp, true);
1290
1465
  },
@@ -1500,6 +1675,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1500
1675
  let allElements = /* @__PURE__ */ new Set();
1501
1676
  let badge = null;
1502
1677
  let status = null;
1678
+ let expandBadge = null;
1679
+ let collapsed = false;
1503
1680
  function injectStyles2() {
1504
1681
  if (hasStyles(STYLE_ID3)) return;
1505
1682
  addStyles(STYLE_ID3, `
@@ -1615,6 +1792,24 @@ function createToolbarRenderer(callbacks, options = {}) {
1615
1792
  background: var(--grabby-accent-hover, #1d4ed8);
1616
1793
  color: #fff;
1617
1794
  }
1795
+ #${TOOLBAR_ID} button.grabby-btn-expand { display: none; }
1796
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed {
1797
+ left: auto;
1798
+ right: 20px;
1799
+ transform: none;
1800
+ padding: 4px;
1801
+ }
1802
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed.grabby-toolbar-hidden {
1803
+ transform: translateY(20px);
1804
+ }
1805
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > * { display: none !important; }
1806
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > button.grabby-btn-expand {
1807
+ display: flex !important;
1808
+ width: 40px;
1809
+ height: 40px;
1810
+ border-radius: 50%;
1811
+ color: var(--grabby-accent, #2563eb);
1812
+ }
1618
1813
  #${TOOLBAR_ID} .grabby-toolbar-left.grabby-toolbar-left-hidden {
1619
1814
  max-width: 0;
1620
1815
  opacity: 0;
@@ -1655,6 +1850,12 @@ function createToolbarRenderer(callbacks, options = {}) {
1655
1850
  buttons.history.appendChild(badge);
1656
1851
  buttons.enable = createButton("enable", ICON_POWER, "Enable/Disable", callbacks.onEnableToggle);
1657
1852
  buttons.dismiss = createButton("dismiss", ICON_DISMISS, options.dismissLabel ?? "Dismiss toolbar", callbacks.onDismiss);
1853
+ buttons.expand = createButton("expand", ICON_GRAB, options.expandLabel ?? "Open Grabby toolbar", () => callbacks.onExpand?.());
1854
+ buttons.expand.classList.add("grabby-btn-expand");
1855
+ expandBadge = document.createElement("span");
1856
+ expandBadge.className = "grabby-badge";
1857
+ expandBadge.hidden = true;
1858
+ buttons.expand.appendChild(expandBadge);
1658
1859
  const divider = document.createElement("span");
1659
1860
  divider.className = "grabby-toolbar-divider";
1660
1861
  leftGroup = document.createElement("div");
@@ -1685,6 +1886,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1685
1886
  }
1686
1887
  if (!options.hideEnable) container.appendChild(buttons.enable);
1687
1888
  container.appendChild(buttons.dismiss);
1889
+ container.appendChild(buttons.expand);
1890
+ container.classList.toggle("grabby-toolbar-collapsed", collapsed);
1688
1891
  getUiRoot().appendChild(container);
1689
1892
  allElements.clear();
1690
1893
  allElements.add(container);
@@ -1712,9 +1915,10 @@ function createToolbarRenderer(callbacks, options = {}) {
1712
1915
  buttons.selection.classList.remove("grabby-btn-active");
1713
1916
  }
1714
1917
  const count = state.toolbar.comments.length;
1715
- if (badge) {
1716
- badge.hidden = count === 0;
1717
- badge.textContent = count > 99 ? "99+" : String(count);
1918
+ for (const b of [badge, expandBadge]) {
1919
+ if (!b) continue;
1920
+ b.hidden = count === 0;
1921
+ b.textContent = count > 99 ? "99+" : String(count);
1718
1922
  }
1719
1923
  buttons.history.setAttribute("aria-label", count ? `Comments (${count})` : "Comments");
1720
1924
  if (status && buttons.finish) {
@@ -1732,6 +1936,17 @@ function createToolbarRenderer(callbacks, options = {}) {
1732
1936
  leftGroup?.classList.add("grabby-toolbar-left-hidden");
1733
1937
  }
1734
1938
  },
1939
+ collapse() {
1940
+ collapsed = true;
1941
+ container?.classList.add("grabby-toolbar-collapsed");
1942
+ },
1943
+ expand() {
1944
+ collapsed = false;
1945
+ container?.classList.remove("grabby-toolbar-collapsed");
1946
+ },
1947
+ isCollapsed() {
1948
+ return collapsed;
1949
+ },
1735
1950
  isToolbarElement(el) {
1736
1951
  if (allElements.has(el)) return true;
1737
1952
  let current = el;
@@ -1749,6 +1964,7 @@ function createToolbarRenderer(callbacks, options = {}) {
1749
1964
  leftGroup = null;
1750
1965
  buttons = {};
1751
1966
  badge = null;
1967
+ expandBadge = null;
1752
1968
  status = null;
1753
1969
  allElements.clear();
1754
1970
  }
@@ -2085,16 +2301,18 @@ function createCommentsPanel(callbacks, options = {}) {
2085
2301
  }
2086
2302
  function row2(comment, showAuthors) {
2087
2303
  const t = comment.target;
2088
- const meta = [h("span", { class: "grabby-kind" }, t.kind)];
2089
- if (t.component) meta.push(document.createTextNode(`${t.component} `));
2090
- if (t.source) {
2091
- meta.push(h("a", {
2092
- href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
2093
- title: `Open ${t.source.file} in VS Code`,
2094
- onclick: (e) => e.stopPropagation()
2095
- }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2096
- } else if (!t.component) {
2097
- meta.push(document.createTextNode(`<${t.tag}>`));
2304
+ const meta = live ? [document.createTextNode(`${describeTarget(t)} `)] : [h("span", { class: "grabby-kind" }, t.kind)];
2305
+ if (!live) {
2306
+ if (t.component) meta.push(document.createTextNode(`${t.component} `));
2307
+ if (t.source) {
2308
+ meta.push(h("a", {
2309
+ href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
2310
+ title: `Open ${t.source.file} in VS Code`,
2311
+ onclick: (e) => e.stopPropagation()
2312
+ }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2313
+ } else if (!t.component) {
2314
+ meta.push(document.createTextNode(`<${t.tag}>`));
2315
+ }
2098
2316
  }
2099
2317
  const tail = [showAuthors && !live ? authorLabel(comment.author) : "", formatRelativeTime(comment.createdAt)].filter(Boolean);
2100
2318
  meta.push(document.createTextNode(` \xB7 ${tail.join(" \xB7 ")}`));
@@ -2967,7 +3185,7 @@ function loadJobs() {
2967
3185
  const raw = localStorage.getItem(STORE_KEY);
2968
3186
  const jobs = raw ? JSON.parse(raw) : [];
2969
3187
  if (!Array.isArray(jobs)) return [];
2970
- return jobs.filter((j) => typeof j.id === "string" && (j.kind === "comment" || j.kind === "shot")).map((j) => typeof j.created === "number" ? j : { ...j, created: Date.now() });
3188
+ return jobs.filter((j) => typeof j.id === "string" && (j.kind === "comment" || j.kind === "shot" || j.kind === "delete" && typeof j.session === "string")).map((j) => typeof j.created === "number" ? j : { ...j, created: Date.now() });
2971
3189
  } catch {
2972
3190
  return [];
2973
3191
  }
@@ -3024,7 +3242,21 @@ function createOutbox(deps) {
3024
3242
  body
3025
3243
  });
3026
3244
  }
3245
+ function deleteComment(id, session2) {
3246
+ return fetch(`${base}/v1/comments/${encodeURIComponent(id)}`, {
3247
+ method: "DELETE",
3248
+ credentials: "omit",
3249
+ keepalive: true,
3250
+ headers: headers({ "X-Grabby-Session": session2 })
3251
+ });
3252
+ }
3027
3253
  async function deliver(job) {
3254
+ if (job.kind === "delete") {
3255
+ const res2 = await deleteComment(job.id, job.session);
3256
+ if (res2.ok || res2.status === 404) return "done";
3257
+ if (res2.status === 429 || res2.status >= 500) return "retry";
3258
+ return "drop";
3259
+ }
3028
3260
  const comment = deps.getComment(job.id);
3029
3261
  if (!comment) return "drop";
3030
3262
  if (job.kind === "comment") {
@@ -3089,6 +3321,19 @@ function createOutbox(deps) {
3089
3321
  if (jobs.length) schedule(500);
3090
3322
  return {
3091
3323
  send: (id) => add(id, "comment"),
3324
+ remove(id, sessionId, delayMs = 0) {
3325
+ jobs = jobs.filter((j) => j.id !== id);
3326
+ jobs.push({ id, kind: "delete", session: sessionId, attempts: 0, next: Date.now() + delayMs, created: Date.now() });
3327
+ save();
3328
+ schedule(0);
3329
+ },
3330
+ cancelRemove(id) {
3331
+ const job = jobs.find((j) => j.id === id && j.kind === "delete");
3332
+ if (!job) return false;
3333
+ jobs = jobs.filter((j) => j !== job);
3334
+ save();
3335
+ return job.attempts === 0;
3336
+ },
3092
3337
  sendScreenshot: (id) => {
3093
3338
  if (!jobs.some((j) => j.id === id && j.kind === "comment")) add(id, "shot");
3094
3339
  },
@@ -3096,11 +3341,18 @@ function createOutbox(deps) {
3096
3341
  flush: onOnline,
3097
3342
  flushOnExit() {
3098
3343
  for (const job of jobs) {
3344
+ if (job.kind === "delete") {
3345
+ job.attempts += 1;
3346
+ deleteComment(job.id, job.session).catch(() => {
3347
+ });
3348
+ continue;
3349
+ }
3099
3350
  if (job.kind !== "comment") continue;
3100
3351
  const comment = deps.getComment(job.id);
3101
3352
  if (comment) postComment(comment).catch(() => {
3102
3353
  });
3103
3354
  }
3355
+ save();
3104
3356
  },
3105
3357
  dispose() {
3106
3358
  disposed = true;
@@ -3723,13 +3975,13 @@ function childSummary(el, resolver) {
3723
3975
  if (counts.size > 6) parts.push("\u2026");
3724
3976
  return parts.join(", ");
3725
3977
  }
3726
- function firstHeading(el) {
3978
+ function firstHeading2(el) {
3727
3979
  const heading = el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
3728
3980
  return heading ? textOf(heading, 60) : "";
3729
3981
  }
3730
3982
  function containerFacts(el, resolver) {
3731
3983
  const f = {};
3732
- put(f, "heading", firstHeading(el));
3984
+ put(f, "heading", firstHeading2(el));
3733
3985
  put(f, "contains", childSummary(el, resolver));
3734
3986
  put(f, "size", size(el));
3735
3987
  put(f, "layout", formatStyles(customStyles(el, CONTAINER_STYLES)));
@@ -3740,7 +3992,7 @@ function sectionFacts(el, resolver) {
3740
3992
  put(f, "title", redact(el.ownerDocument.title));
3741
3993
  put(f, "viewport", `${window.innerWidth}\xD7${window.innerHeight}`);
3742
3994
  const regions = Array.from(el.querySelectorAll('header, nav, main, aside, footer, section, [role="region"]')).filter((r) => !r.parentElement?.closest('header, nav, main, aside, footer, section, [role="region"]') || r.parentElement === el).slice(0, 8).map((r) => {
3743
- const heading = firstHeading(r);
3995
+ const heading = firstHeading2(r);
3744
3996
  return heading ? `${r.tagName.toLowerCase()} "${truncate(heading, 30)}"` : r.tagName.toLowerCase();
3745
3997
  });
3746
3998
  put(f, "regions", regions.join(", "));
@@ -4407,6 +4659,21 @@ function flushLeftovers(options) {
4407
4659
  }
4408
4660
  });
4409
4661
  }
4662
+ var COLLAPSED_KEY = "grabby:v1:collapsed";
4663
+ function loadCollapsed() {
4664
+ try {
4665
+ return sessionStorage.getItem(COLLAPSED_KEY) === "1";
4666
+ } catch {
4667
+ return false;
4668
+ }
4669
+ }
4670
+ function saveCollapsed(on) {
4671
+ try {
4672
+ if (on) sessionStorage.setItem(COLLAPSED_KEY, "1");
4673
+ else sessionStorage.removeItem(COLLAPSED_KEY);
4674
+ } catch {
4675
+ }
4676
+ }
4410
4677
  function isDevMode() {
4411
4678
  try {
4412
4679
  if (typeof ngDevMode !== "undefined" && ngDevMode === false) return false;
@@ -4475,7 +4742,7 @@ function createGrabInstance(options) {
4475
4742
  store.state.toolbar = { ...store.state.toolbar, comments: persisted };
4476
4743
  }
4477
4744
  }
4478
- const overlay = createOverlayRenderer();
4745
+ const overlay = createOverlayRenderer({ plainLabels: live });
4479
4746
  const crosshair = createCrosshair();
4480
4747
  const freezeOverlay = createFreezeOverlay();
4481
4748
  const pluginRegistry = createPluginRegistry();
@@ -4489,6 +4756,7 @@ function createGrabInstance(options) {
4489
4756
  let selectedElement = null;
4490
4757
  let pendingShot = null;
4491
4758
  let level = loadLevel(merged.detailLevel);
4759
+ let collapsed = loadCollapsed();
4492
4760
  const pendingShotDeletes = /* @__PURE__ */ new Map();
4493
4761
  themeManager.apply(store.state.toolbar.themeMode);
4494
4762
  updateToastOffset();
@@ -4603,12 +4871,15 @@ function createGrabInstance(options) {
4603
4871
  pluginRegistry.callHook("onScreenshot", updated, result.blob);
4604
4872
  outbox?.sendScreenshot(id);
4605
4873
  }
4606
- function removeComments(ids, message) {
4874
+ function removeComments(ids, message, withdraw = false) {
4607
4875
  if (ids.length === 0) return;
4608
4876
  const idSet = new Set(ids);
4609
4877
  const before = comments();
4610
4878
  const removed = before.filter((c) => idSet.has(c.id));
4611
4879
  setComments(before.filter((c) => !idSet.has(c.id)));
4880
+ const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
4881
+ const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
4882
+ for (const c of withdrawn) outbox.remove(c.id, c.author.sessionId, message ? UNDO_MS + 500 : 0);
4612
4883
  const shotIds = removed.flatMap((c) => c.screenshot?.localId ? [c.screenshot.localId] : []);
4613
4884
  const key = randomId();
4614
4885
  pendingShotDeletes.set(key, setTimeout(() => {
@@ -4624,8 +4895,11 @@ function createGrabInstance(options) {
4624
4895
  clearTimeout(pendingShotDeletes.get(key));
4625
4896
  pendingShotDeletes.delete(key);
4626
4897
  const present = new Set(comments().map((c) => c.id));
4627
- const restored = [...removed.filter((c) => !present.has(c.id)), ...comments()].sort((a, b) => b.createdAt - a.createdAt);
4898
+ const resend = new Set(withdrawn.filter((c) => !present.has(c.id) && (!outbox.cancelRemove(c.id) || c.sync !== "sent" || hadQueued.has(c.id))).map((c) => c.id));
4899
+ const back = removed.filter((c) => !present.has(c.id)).map((c) => resend.has(c.id) ? { ...c, sync: "pending" } : c);
4900
+ const restored = [...back, ...comments()].sort((a, b) => b.createdAt - a.createdAt);
4628
4901
  setComments(restored);
4902
+ for (const id of resend) outbox?.send(id);
4629
4903
  showToast(`Restored ${removed.length} comment${removed.length === 1 ? "" : "s"}`);
4630
4904
  }
4631
4905
  }]
@@ -4656,9 +4930,17 @@ function createGrabInstance(options) {
4656
4930
  function isAnyToolbarElement(el) {
4657
4931
  return isUiNode(el) || freezeOverlay.isFreezeElement(el);
4658
4932
  }
4933
+ function hideCommentPopover() {
4934
+ commentPopover.hide();
4935
+ if (picker.isHolding()) {
4936
+ selectedElement = null;
4937
+ pendingShot = null;
4938
+ picker.release();
4939
+ }
4940
+ }
4659
4941
  function closeAllPopovers() {
4660
4942
  commentsPanel.hide();
4661
- commentPopover.hide();
4943
+ hideCommentPopover();
4662
4944
  copySheet.close();
4663
4945
  finishSheet.close();
4664
4946
  }
@@ -4698,6 +4980,7 @@ function createGrabInstance(options) {
4698
4980
  pluginRegistry.callHook("onElementSelect", element);
4699
4981
  coachMark.dismiss();
4700
4982
  showSelectFeedback(element);
4983
+ picker.hold(element);
4701
4984
  commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
4702
4985
  }
4703
4986
  });
@@ -4708,6 +4991,7 @@ function createGrabInstance(options) {
4708
4991
  store.state.toolbar = { ...store.state.toolbar, visible: true };
4709
4992
  toolbar.show();
4710
4993
  }
4994
+ if (collapsed) expandToolbar();
4711
4995
  closeAllPopovers();
4712
4996
  store.state.active = true;
4713
4997
  picker.activate();
@@ -4742,7 +5026,7 @@ function createGrabInstance(options) {
4742
5026
  }
4743
5027
  },
4744
5028
  onHistory() {
4745
- commentPopover.hide();
5029
+ hideCommentPopover();
4746
5030
  copySheet.close();
4747
5031
  if (commentsPanel.isVisible()) {
4748
5032
  commentsPanel.hide();
@@ -4759,16 +5043,28 @@ function createGrabInstance(options) {
4759
5043
  }
4760
5044
  toolbar.update(store.state);
4761
5045
  },
4762
- onDismiss() {
4763
- const { pending, failed } = reviewCounts();
4764
- if (live && outbox && (pending || failed)) {
4765
- openFinishSheet();
4766
- return;
4767
- }
4768
- exitFeedbackMode();
4769
- },
5046
+ // Close collapses the toolbar into a round button in the bottom-right
5047
+ // corner instead of removing it, so nothing is lost and it's one click
5048
+ // back. Comments keep sending while it's collapsed.
5049
+ onDismiss: collapseToolbar,
5050
+ onExpand: expandToolbar,
4770
5051
  onFinish: openFinishSheet
4771
- }, live ? { label: "Comment", dismissLabel: "Exit feedback mode", hideEnable: true, review: !!merged.server } : {});
5052
+ }, live ? { label: "Comment", dismissLabel: "Hide toolbar", expandLabel: "Leave feedback", hideEnable: true, review: !!merged.server } : { dismissLabel: "Hide toolbar", expandLabel: "Open Grabby toolbar" });
5053
+ function collapseToolbar() {
5054
+ closeAllPopovers();
5055
+ coachMark.dismiss();
5056
+ doDeactivate(true);
5057
+ collapsed = true;
5058
+ toolbar.collapse();
5059
+ saveCollapsed(true);
5060
+ updateToastOffset();
5061
+ }
5062
+ function expandToolbar() {
5063
+ collapsed = false;
5064
+ toolbar.expand();
5065
+ saveCollapsed(false);
5066
+ updateToastOffset();
5067
+ }
4772
5068
  const commentsPanel = createCommentsPanel({
4773
5069
  onHover(comment) {
4774
5070
  const el = comment ? safeQuery(comment.target.selector) : null;
@@ -4791,7 +5087,7 @@ function createGrabInstance(options) {
4791
5087
  },
4792
5088
  onDelete(comment) {
4793
5089
  overlay.hide();
4794
- removeComments([comment.id], "Comment deleted");
5090
+ removeComments([comment.id], "Comment deleted", true);
4795
5091
  },
4796
5092
  onCopyAll() {
4797
5093
  overlay.hide();
@@ -4800,7 +5096,7 @@ function createGrabInstance(options) {
4800
5096
  onClearAll() {
4801
5097
  overlay.hide();
4802
5098
  const n = comments().length;
4803
- removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`);
5099
+ removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`, true);
4804
5100
  commentsPanel.hide();
4805
5101
  },
4806
5102
  onChangeIdentity() {
@@ -4905,7 +5201,7 @@ function createGrabInstance(options) {
4905
5201
  }
4906
5202
  window.addEventListener("beforeunload", handleBeforeUnload);
4907
5203
  function updateToastOffset() {
4908
- if (store.state.toolbar.visible) {
5204
+ if (store.state.toolbar.visible && !collapsed) {
4909
5205
  document.documentElement.style.setProperty("--grabby-toast-bottom", TOOLBAR_TOAST_OFFSET);
4910
5206
  } else {
4911
5207
  document.documentElement.style.removeProperty("--grabby-toast-bottom");
@@ -5002,7 +5298,7 @@ function createGrabInstance(options) {
5002
5298
  return exportText(list, opts.level ?? level);
5003
5299
  },
5004
5300
  deleteComment(id) {
5005
- removeComments([id], null);
5301
+ removeComments([id], null, true);
5006
5302
  },
5007
5303
  clearComments() {
5008
5304
  removeComments(comments().map((c) => c.id), null);
@@ -5055,9 +5351,10 @@ function createGrabInstance(options) {
5055
5351
  keyboard.start();
5056
5352
  }
5057
5353
  store.state.toolbar = { ...store.state.toolbar, visible: false };
5354
+ if (collapsed) toolbar.collapse();
5058
5355
  if (live && merged.showToolbar) {
5059
5356
  api.showToolbar();
5060
- coachMark.maybeShow();
5357
+ if (!collapsed) coachMark.maybeShow();
5061
5358
  }
5062
5359
  store.subscribe((state, key) => {
5063
5360
  if (key === "options") {