@githumbi/grabby 0.2.0 → 0.3.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();
@@ -742,360 +1125,112 @@ function showToast(message, opts = {}) {
742
1125
  void toast.offsetHeight;
743
1126
  toast.classList.add("grabby-toast-visible");
744
1127
  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;
1128
+ toast.classList.remove("grabby-toast-visible");
1129
+ activeTimer = null;
1130
+ }, durationMs);
919
1131
  }
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";
1132
+ function hideToast() {
1133
+ if (activeTimer) {
1134
+ clearTimeout(activeTimer);
1135
+ activeTimer = null;
927
1136
  }
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";
1137
+ toastEl?.classList.remove("grabby-toast-visible");
932
1138
  }
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;
1139
+ function disposeToast() {
1140
+ if (activeTimer) {
1141
+ clearTimeout(activeTimer);
1142
+ activeTimer = null;
941
1143
  }
942
- return el;
1144
+ toastEl?.remove();
1145
+ toastEl = null;
1146
+ removeStyles(TOAST_STYLE_ID);
943
1147
  }
944
1148
 
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);
1149
+ // src/core/utils.ts
1150
+ function filterAngularClasses(classList) {
1151
+ return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
956
1152
  }
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);
1153
+ function cssEscape(value) {
1154
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
1155
+ let out = "";
1156
+ for (let i = 0; i < value.length; i++) {
1157
+ const ch = value.charAt(i);
1158
+ const code = value.charCodeAt(i);
1159
+ if (code === 0) {
1160
+ out += "\uFFFD";
1161
+ continue;
965
1162
  }
966
- const qs = kept.toString();
967
- if (qs) route += `?${qs}`;
1163
+ if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
1164
+ out += `\\${code.toString(16)} `;
1165
+ continue;
1166
+ }
1167
+ if (i === 0 && value.length === 1 && code === 45) {
1168
+ out += `\\${ch}`;
1169
+ continue;
1170
+ }
1171
+ if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
1172
+ out += ch;
1173
+ continue;
1174
+ }
1175
+ out += `\\${ch}`;
968
1176
  }
969
- if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
970
- return redact(route);
1177
+ return out;
971
1178
  }
972
- function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
1179
+ function safeQuery(selector, root2 = document) {
1180
+ if (!selector) return null;
973
1181
  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}`);
1182
+ return root2.querySelector(selector);
979
1183
  } catch {
980
- return redact(raw.split(/[?#]/)[0]);
981
- }
982
- }
983
-
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;
1024
- }
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;
1035
- }
1036
- return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
1037
- }
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 ?? ""}`;
1184
+ return null;
1042
1185
  }
1043
- return raw.replace(/\s+/g, " ").trim();
1044
1186
  }
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);
1187
+ var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
1188
+ var MAX_SELECTOR_DEPTH = 8;
1189
+ function isUnique(selector, el) {
1190
+ try {
1191
+ const matches = el.ownerDocument.querySelectorAll(selector);
1192
+ return matches.length === 1 && matches[0] === el;
1193
+ } catch {
1194
+ return false;
1050
1195
  }
1051
- if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
1052
- return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
1053
1196
  }
1054
- function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
1197
+ function stepFor(el) {
1055
1198
  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;
1199
+ const parent = el.parentElement;
1200
+ if (!parent) return tag;
1201
+ const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
1202
+ if (sameTag.length === 1) return tag;
1203
+ return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
1204
+ }
1205
+ function buildUniqueSelector(el) {
1206
+ for (const attr of TEST_ID_ATTRS) {
1207
+ const value = el.getAttribute(attr);
1208
+ if (value) {
1209
+ const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
1210
+ if (isUnique(sel, el)) return sel;
1066
1211
  }
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
1212
  }
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);
1213
+ if (el.id) {
1214
+ const sel = `#${cssEscape(el.id)}`;
1215
+ if (isUnique(sel, el)) return sel;
1081
1216
  }
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)`;
1217
+ const steps = [];
1218
+ let current = el;
1219
+ while (current && steps.length < MAX_SELECTOR_DEPTH) {
1220
+ if (current !== el && current.id) {
1221
+ const anchor = `#${cssEscape(current.id)}`;
1222
+ if (isUnique(anchor, current)) {
1223
+ steps.unshift(anchor);
1224
+ break;
1225
+ }
1226
+ }
1227
+ steps.unshift(stepFor(current));
1228
+ const sel = steps.join(" > ");
1229
+ if (isUnique(sel, el)) return sel;
1230
+ if (current.tagName === "BODY" || current.tagName === "HTML") break;
1231
+ current = current.parentElement;
1097
1232
  }
1098
- return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
1233
+ return steps.join(" > ");
1099
1234
  }
1100
1235
 
1101
1236
  // src/core/picker/element-picker.ts
@@ -1225,6 +1360,7 @@ function matchesCombo(e, parsed) {
1225
1360
  function createKeyboardHandler(deps) {
1226
1361
  let holdTimer = null;
1227
1362
  let holdActivated = false;
1363
+ let togglePending = false;
1228
1364
  let listening = false;
1229
1365
  function handleKeyDown(e) {
1230
1366
  if (!deps.getEnableInInputs() && isEditableElement(eventTarget(e))) return;
@@ -1247,6 +1383,7 @@ function createKeyboardHandler(deps) {
1247
1383
  }
1248
1384
  } else {
1249
1385
  e.preventDefault();
1386
+ togglePending = true;
1250
1387
  }
1251
1388
  }
1252
1389
  function handleKeyUp(e) {
@@ -1263,6 +1400,8 @@ function createKeyboardHandler(deps) {
1263
1400
  deps.onDeactivate();
1264
1401
  }
1265
1402
  } else {
1403
+ if (!togglePending) return;
1404
+ togglePending = false;
1266
1405
  if (deps.isActive()) {
1267
1406
  deps.onDeactivate();
1268
1407
  } else {
@@ -1285,6 +1424,7 @@ function createKeyboardHandler(deps) {
1285
1424
  holdTimer = null;
1286
1425
  }
1287
1426
  holdActivated = false;
1427
+ togglePending = false;
1288
1428
  document.removeEventListener("keydown", handleKeyDown, true);
1289
1429
  document.removeEventListener("keyup", handleKeyUp, true);
1290
1430
  },
@@ -2085,16 +2225,18 @@ function createCommentsPanel(callbacks, options = {}) {
2085
2225
  }
2086
2226
  function row2(comment, showAuthors) {
2087
2227
  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}>`));
2228
+ const meta = live ? [document.createTextNode(`${describeTarget(t)} `)] : [h("span", { class: "grabby-kind" }, t.kind)];
2229
+ if (!live) {
2230
+ if (t.component) meta.push(document.createTextNode(`${t.component} `));
2231
+ if (t.source) {
2232
+ meta.push(h("a", {
2233
+ href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
2234
+ title: `Open ${t.source.file} in VS Code`,
2235
+ onclick: (e) => e.stopPropagation()
2236
+ }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2237
+ } else if (!t.component) {
2238
+ meta.push(document.createTextNode(`<${t.tag}>`));
2239
+ }
2098
2240
  }
2099
2241
  const tail = [showAuthors && !live ? authorLabel(comment.author) : "", formatRelativeTime(comment.createdAt)].filter(Boolean);
2100
2242
  meta.push(document.createTextNode(` \xB7 ${tail.join(" \xB7 ")}`));
@@ -2967,7 +3109,7 @@ function loadJobs() {
2967
3109
  const raw = localStorage.getItem(STORE_KEY);
2968
3110
  const jobs = raw ? JSON.parse(raw) : [];
2969
3111
  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() });
3112
+ 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
3113
  } catch {
2972
3114
  return [];
2973
3115
  }
@@ -3024,7 +3166,21 @@ function createOutbox(deps) {
3024
3166
  body
3025
3167
  });
3026
3168
  }
3169
+ function deleteComment(id, session2) {
3170
+ return fetch(`${base}/v1/comments/${encodeURIComponent(id)}`, {
3171
+ method: "DELETE",
3172
+ credentials: "omit",
3173
+ keepalive: true,
3174
+ headers: headers({ "X-Grabby-Session": session2 })
3175
+ });
3176
+ }
3027
3177
  async function deliver(job) {
3178
+ if (job.kind === "delete") {
3179
+ const res2 = await deleteComment(job.id, job.session);
3180
+ if (res2.ok || res2.status === 404) return "done";
3181
+ if (res2.status === 429 || res2.status >= 500) return "retry";
3182
+ return "drop";
3183
+ }
3028
3184
  const comment = deps.getComment(job.id);
3029
3185
  if (!comment) return "drop";
3030
3186
  if (job.kind === "comment") {
@@ -3089,6 +3245,19 @@ function createOutbox(deps) {
3089
3245
  if (jobs.length) schedule(500);
3090
3246
  return {
3091
3247
  send: (id) => add(id, "comment"),
3248
+ remove(id, sessionId, delayMs = 0) {
3249
+ jobs = jobs.filter((j) => j.id !== id);
3250
+ jobs.push({ id, kind: "delete", session: sessionId, attempts: 0, next: Date.now() + delayMs, created: Date.now() });
3251
+ save();
3252
+ schedule(0);
3253
+ },
3254
+ cancelRemove(id) {
3255
+ const job = jobs.find((j) => j.id === id && j.kind === "delete");
3256
+ if (!job) return false;
3257
+ jobs = jobs.filter((j) => j !== job);
3258
+ save();
3259
+ return job.attempts === 0;
3260
+ },
3092
3261
  sendScreenshot: (id) => {
3093
3262
  if (!jobs.some((j) => j.id === id && j.kind === "comment")) add(id, "shot");
3094
3263
  },
@@ -3096,11 +3265,18 @@ function createOutbox(deps) {
3096
3265
  flush: onOnline,
3097
3266
  flushOnExit() {
3098
3267
  for (const job of jobs) {
3268
+ if (job.kind === "delete") {
3269
+ job.attempts += 1;
3270
+ deleteComment(job.id, job.session).catch(() => {
3271
+ });
3272
+ continue;
3273
+ }
3099
3274
  if (job.kind !== "comment") continue;
3100
3275
  const comment = deps.getComment(job.id);
3101
3276
  if (comment) postComment(comment).catch(() => {
3102
3277
  });
3103
3278
  }
3279
+ save();
3104
3280
  },
3105
3281
  dispose() {
3106
3282
  disposed = true;
@@ -3723,13 +3899,13 @@ function childSummary(el, resolver) {
3723
3899
  if (counts.size > 6) parts.push("\u2026");
3724
3900
  return parts.join(", ");
3725
3901
  }
3726
- function firstHeading(el) {
3902
+ function firstHeading2(el) {
3727
3903
  const heading = el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
3728
3904
  return heading ? textOf(heading, 60) : "";
3729
3905
  }
3730
3906
  function containerFacts(el, resolver) {
3731
3907
  const f = {};
3732
- put(f, "heading", firstHeading(el));
3908
+ put(f, "heading", firstHeading2(el));
3733
3909
  put(f, "contains", childSummary(el, resolver));
3734
3910
  put(f, "size", size(el));
3735
3911
  put(f, "layout", formatStyles(customStyles(el, CONTAINER_STYLES)));
@@ -3740,7 +3916,7 @@ function sectionFacts(el, resolver) {
3740
3916
  put(f, "title", redact(el.ownerDocument.title));
3741
3917
  put(f, "viewport", `${window.innerWidth}\xD7${window.innerHeight}`);
3742
3918
  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);
3919
+ const heading = firstHeading2(r);
3744
3920
  return heading ? `${r.tagName.toLowerCase()} "${truncate(heading, 30)}"` : r.tagName.toLowerCase();
3745
3921
  });
3746
3922
  put(f, "regions", regions.join(", "));
@@ -4475,7 +4651,7 @@ function createGrabInstance(options) {
4475
4651
  store.state.toolbar = { ...store.state.toolbar, comments: persisted };
4476
4652
  }
4477
4653
  }
4478
- const overlay = createOverlayRenderer();
4654
+ const overlay = createOverlayRenderer({ plainLabels: live });
4479
4655
  const crosshair = createCrosshair();
4480
4656
  const freezeOverlay = createFreezeOverlay();
4481
4657
  const pluginRegistry = createPluginRegistry();
@@ -4603,12 +4779,15 @@ function createGrabInstance(options) {
4603
4779
  pluginRegistry.callHook("onScreenshot", updated, result.blob);
4604
4780
  outbox?.sendScreenshot(id);
4605
4781
  }
4606
- function removeComments(ids, message) {
4782
+ function removeComments(ids, message, withdraw = false) {
4607
4783
  if (ids.length === 0) return;
4608
4784
  const idSet = new Set(ids);
4609
4785
  const before = comments();
4610
4786
  const removed = before.filter((c) => idSet.has(c.id));
4611
4787
  setComments(before.filter((c) => !idSet.has(c.id)));
4788
+ const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
4789
+ const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
4790
+ for (const c of withdrawn) outbox.remove(c.id, c.author.sessionId, message ? UNDO_MS + 500 : 0);
4612
4791
  const shotIds = removed.flatMap((c) => c.screenshot?.localId ? [c.screenshot.localId] : []);
4613
4792
  const key = randomId();
4614
4793
  pendingShotDeletes.set(key, setTimeout(() => {
@@ -4624,8 +4803,11 @@ function createGrabInstance(options) {
4624
4803
  clearTimeout(pendingShotDeletes.get(key));
4625
4804
  pendingShotDeletes.delete(key);
4626
4805
  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);
4806
+ 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));
4807
+ const back = removed.filter((c) => !present.has(c.id)).map((c) => resend.has(c.id) ? { ...c, sync: "pending" } : c);
4808
+ const restored = [...back, ...comments()].sort((a, b) => b.createdAt - a.createdAt);
4628
4809
  setComments(restored);
4810
+ for (const id of resend) outbox?.send(id);
4629
4811
  showToast(`Restored ${removed.length} comment${removed.length === 1 ? "" : "s"}`);
4630
4812
  }
4631
4813
  }]
@@ -4791,7 +4973,7 @@ function createGrabInstance(options) {
4791
4973
  },
4792
4974
  onDelete(comment) {
4793
4975
  overlay.hide();
4794
- removeComments([comment.id], "Comment deleted");
4976
+ removeComments([comment.id], "Comment deleted", true);
4795
4977
  },
4796
4978
  onCopyAll() {
4797
4979
  overlay.hide();
@@ -4800,7 +4982,7 @@ function createGrabInstance(options) {
4800
4982
  onClearAll() {
4801
4983
  overlay.hide();
4802
4984
  const n = comments().length;
4803
- removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`);
4985
+ removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`, true);
4804
4986
  commentsPanel.hide();
4805
4987
  },
4806
4988
  onChangeIdentity() {
@@ -5002,7 +5184,7 @@ function createGrabInstance(options) {
5002
5184
  return exportText(list, opts.level ?? level);
5003
5185
  },
5004
5186
  deleteComment(id) {
5005
- removeComments([id], null);
5187
+ removeComments([id], null, true);
5006
5188
  },
5007
5189
  clearComments() {
5008
5190
  removeComments(comments().map((c) => c.id), null);