@githumbi/grabby 0.2.1 → 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.
@@ -142,12 +142,378 @@ function disposeUiRoot() {
142
142
  root = null;
143
143
  }
144
144
 
145
+ // src/core/capture/kind.ts
146
+ var ACTION_TAGS = /* @__PURE__ */ new Set(["BUTTON", "A", "SUMMARY"]);
147
+ var ACTION_ROLES = /* @__PURE__ */ new Set(["button", "link", "tab", "menuitem", "menuitemcheckbox", "menuitemradio", "switch", "option", "checkbox", "radio"]);
148
+ var BUTTON_INPUT_TYPES = /* @__PURE__ */ new Set(["button", "submit", "reset", "image"]);
149
+ var FIELD_TAGS = /* @__PURE__ */ new Set(["INPUT", "SELECT", "TEXTAREA"]);
150
+ var FIELD_ROLES = /* @__PURE__ */ new Set(["textbox", "combobox", "searchbox", "spinbutton", "slider"]);
151
+ var MEDIA_TAGS = /* @__PURE__ */ new Set(["IMG", "SVG", "VIDEO", "PICTURE", "CANVAS", "IFRAME", "AUDIO"]);
152
+ var TEXT_TAGS = /* @__PURE__ */ new Set([
153
+ "H1",
154
+ "H2",
155
+ "H3",
156
+ "H4",
157
+ "H5",
158
+ "H6",
159
+ "P",
160
+ "SPAN",
161
+ "LABEL",
162
+ "LI",
163
+ "STRONG",
164
+ "EM",
165
+ "B",
166
+ "I",
167
+ "SMALL",
168
+ "BLOCKQUOTE",
169
+ "CODE",
170
+ "PRE",
171
+ "TD",
172
+ "TH",
173
+ "DT",
174
+ "DD",
175
+ "FIGCAPTION",
176
+ "LEGEND",
177
+ "CAPTION",
178
+ "Q",
179
+ "CITE",
180
+ "MARK",
181
+ "TIME"
182
+ ]);
183
+ var PAGE_TAGS = /* @__PURE__ */ new Set(["HTML", "BODY", "MAIN"]);
184
+ var LANDMARK_TAGS = /* @__PURE__ */ new Set(["HEADER", "FOOTER", "NAV", "ASIDE"]);
185
+ var SECTION_AREA_RATIO = 0.6;
186
+ function role(el) {
187
+ return (el.getAttribute("role") ?? "").toLowerCase();
188
+ }
189
+ function isAction(el) {
190
+ if (ACTION_TAGS.has(el.tagName)) return el.tagName !== "A" || el.hasAttribute("href") || el.hasAttribute("role");
191
+ if (el.tagName === "INPUT" && BUTTON_INPUT_TYPES.has(el.type)) return true;
192
+ return ACTION_ROLES.has(role(el));
193
+ }
194
+ function isField(el) {
195
+ if (el.tagName === "INPUT") return !BUTTON_INPUT_TYPES.has(el.type);
196
+ if (FIELD_TAGS.has(el.tagName)) return true;
197
+ if (el.isContentEditable && el.getAttribute("contenteditable") !== null) return true;
198
+ return FIELD_ROLES.has(role(el));
199
+ }
200
+ function coversViewport(el) {
201
+ const rect = el.getBoundingClientRect();
202
+ const vw = window.innerWidth || document.documentElement.clientWidth;
203
+ const vh = window.innerHeight || document.documentElement.clientHeight;
204
+ if (!vw || !vh) return false;
205
+ const w = Math.max(0, Math.min(rect.right, vw) - Math.max(rect.left, 0));
206
+ const hgt = Math.max(0, Math.min(rect.bottom, vh) - Math.max(rect.top, 0));
207
+ return w * hgt / (vw * vh) >= SECTION_AREA_RATIO;
208
+ }
209
+ function hasElementChildren(el) {
210
+ return el.children.length > 0;
211
+ }
212
+ function detectKind(el) {
213
+ if (PAGE_TAGS.has(el.tagName)) return "section";
214
+ if (MEDIA_TAGS.has(el.tagName)) return "media";
215
+ if (isField(el)) return "field";
216
+ if (isAction(el)) return "action";
217
+ if (LANDMARK_TAGS.has(el.tagName) || role(el) === "main" || role(el) === "region") {
218
+ return coversViewport(el) ? "section" : "container";
219
+ }
220
+ if (TEXT_TAGS.has(el.tagName)) return "text";
221
+ if (!hasElementChildren(el) && (el.textContent ?? "").trim()) return "text";
222
+ if (coversViewport(el)) return "section";
223
+ return "container";
224
+ }
225
+ var PROMOTE_DEPTH = 3;
226
+ function promoteTarget(el) {
227
+ if (isAction(el) || isField(el)) return el;
228
+ let current = el.parentElement;
229
+ for (let depth = 0; current && depth < PROMOTE_DEPTH; depth++) {
230
+ if (isAction(current) || isField(current)) return current;
231
+ if (PAGE_TAGS.has(current.tagName)) break;
232
+ current = current.parentElement;
233
+ }
234
+ return el;
235
+ }
236
+
237
+ // src/core/capture/redact.ts
238
+ var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
239
+ var JWT = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
240
+ var BEARER = /\b(Bearer|Basic|Token)\s+[A-Za-z0-9._~+/=-]{8,}/gi;
241
+ var LONG_NUMBER = /\b\d(?:[ -]?\d){8,}\b/g;
242
+ var OPAQUE_TOKEN = /\b[A-Za-z0-9_-]{32,}\b/g;
243
+ var SENSITIVE_PARAM = /([?&#](?:access_token|id_token|token|key|api_key|apikey|secret|password|pass|auth|code|session|sig|signature)=)[^&#\s]*/gi;
244
+ function redact(text, options = {}) {
245
+ if (!text) return text;
246
+ const scrubbed = text.replace(SENSITIVE_PARAM, "$1[redacted]").replace(JWT, "[token]").replace(BEARER, "$1 [token]");
247
+ 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);
248
+ }
249
+ function sanitizeRoute(loc, keepParams = []) {
250
+ let route = loc.pathname || "/";
251
+ if (keepParams.length > 0 && loc.search) {
252
+ const params = new URLSearchParams(loc.search);
253
+ const kept = new URLSearchParams();
254
+ for (const name of keepParams) {
255
+ const value = params.get(name);
256
+ if (value !== null) kept.set(name, value);
257
+ }
258
+ const qs = kept.toString();
259
+ if (qs) route += `?${qs}`;
260
+ }
261
+ if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
262
+ return redact(route);
263
+ }
264
+ function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
265
+ try {
266
+ const url = new URL(raw, base);
267
+ if (url.protocol === "javascript:" || url.protocol === "data:" || url.protocol === "vbscript:") return `${url.protocol}\u2026`;
268
+ const baseUrl = new URL(base);
269
+ const path = url.pathname + (url.hash.startsWith("#/") ? url.hash : "");
270
+ return redact(url.origin === baseUrl.origin ? path : `${url.host}${path}`);
271
+ } catch {
272
+ return redact(raw.split(/[?#]/)[0]);
273
+ }
274
+ }
275
+
276
+ // src/core/capture/preview.ts
277
+ var MASK_ATTR = "data-grabby-mask";
278
+ var IGNORE_ATTR = "data-grabby-ignore";
279
+ var PRIORITY_ATTRS = [
280
+ "id",
281
+ "class",
282
+ "role",
283
+ "aria-label",
284
+ "data-testid",
285
+ "data-test",
286
+ "data-cy",
287
+ "name",
288
+ "type",
289
+ "href",
290
+ "src",
291
+ "alt",
292
+ "placeholder",
293
+ "title",
294
+ "for",
295
+ "aria-expanded",
296
+ "aria-selected",
297
+ "disabled"
298
+ ];
299
+ var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src"]);
300
+ var MAX_ATTRS = 8;
301
+ var MAX_CLASS_CHARS = 60;
302
+ var MAX_ATTR_CHARS = 80;
303
+ var MAX_TEXT_CHARS = 80;
304
+ var MAX_PREVIEW_CHARS = 300;
305
+ function isNoiseAttr(name) {
306
+ 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");
307
+ }
308
+ function isNoiseClass(name) {
309
+ return name.startsWith("ng-") || name.startsWith("_ng") || /^svelte-[a-z0-9]+$/i.test(name) || /^s-[A-Za-z0-9_-]{8,}$/.test(name);
310
+ }
311
+ function truncate(text, max) {
312
+ return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}\u2026`;
313
+ }
314
+ function isMasked(el) {
315
+ return el.closest(`[${MASK_ATTR}]`) !== null;
316
+ }
317
+ function textOf(el, max) {
318
+ if (isMasked(el)) return "[masked]";
319
+ let raw = "";
320
+ const walker = el.ownerDocument.createTreeWalker(el, NodeFilter.SHOW_TEXT);
321
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
322
+ const parent = node.parentElement;
323
+ if (parent && /^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE)$/.test(parent.tagName)) continue;
324
+ if (parent?.closest(`[${IGNORE_ATTR}], [${MASK_ATTR}]`)) continue;
325
+ raw += ` ${node.nodeValue ?? ""}`;
326
+ if (raw.length > max * 3) break;
327
+ }
328
+ return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
329
+ }
330
+ function ownText(el) {
331
+ let raw = "";
332
+ for (const node of Array.from(el.childNodes)) {
333
+ if (node.nodeType === Node.TEXT_NODE) raw += ` ${node.nodeValue ?? ""}`;
334
+ }
335
+ return raw.replace(/\s+/g, " ").trim();
336
+ }
337
+ function attrValue(el, name, value, cleanClasses) {
338
+ if (name === "class") {
339
+ const classes = cleanClasses(value.split(/\s+/).filter(Boolean));
340
+ if (classes.length === 0) return null;
341
+ return truncate(classes.join(" "), MAX_CLASS_CHARS);
342
+ }
343
+ if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
344
+ return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
345
+ }
346
+ function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
347
+ const tag = el.tagName.toLowerCase();
348
+ const attrs = [];
349
+ const seen2 = /* @__PURE__ */ new Set();
350
+ const add = (name) => {
351
+ if (attrs.length >= MAX_ATTRS || seen2.has(name) || isNoiseAttr(name)) return;
352
+ const raw = el.getAttribute(name);
353
+ if (raw === null) return;
354
+ seen2.add(name);
355
+ if (raw === "") {
356
+ attrs.push(name);
357
+ return;
358
+ }
359
+ const value = attrValue(el, name, raw, cleanClasses);
360
+ if (value !== null) attrs.push(`${name}="${value.replace(/"/g, "&quot;")}"`);
361
+ };
362
+ for (const name of PRIORITY_ATTRS) add(name);
363
+ for (const { name } of Array.from(el.attributes)) {
364
+ if (name.startsWith("aria-")) add(name);
365
+ }
366
+ return `<${tag}${attrs.length ? ` ${attrs.join(" ")}` : ""}>`;
367
+ }
368
+ function buildPreview(el, cleanClasses) {
369
+ const tag = el.tagName.toLowerCase();
370
+ const open = openingTag(el, cleanClasses);
371
+ if (/^(img|input|br|hr|meta|link|source|area|col|embed|wbr)$/.test(tag)) {
372
+ return truncate(open, MAX_PREVIEW_CHARS);
373
+ }
374
+ const children = Array.from(el.children).filter((c) => !c.hasAttribute(IGNORE_ATTR));
375
+ let inner;
376
+ if (isMasked(el)) {
377
+ inner = "[masked]";
378
+ } else if (children.length === 0) {
379
+ inner = truncate(redact(ownText(el)), MAX_TEXT_CHARS);
380
+ } else if (children.length <= 2) {
381
+ const text = truncate(redact(ownText(el)), 40);
382
+ const kids = children.map((c) => {
383
+ const t = textOf(c, 30);
384
+ return `<${c.tagName.toLowerCase()}${t ? `>${t}</${c.tagName.toLowerCase()}>` : " \u2026>"}`;
385
+ });
386
+ inner = [text, ...kids].filter(Boolean).join(" ");
387
+ } else {
388
+ inner = `(${children.length} elements)`;
389
+ }
390
+ return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
391
+ }
392
+
393
+ // src/core/capture/describe.ts
394
+ var MAX_NAME = 40;
395
+ var HEADING = /^h[1-6]$/;
396
+ function role2(el) {
397
+ return (el.getAttribute("role") ?? "").toLowerCase();
398
+ }
399
+ function hasBox(el) {
400
+ try {
401
+ const s = getComputedStyle(el);
402
+ const bordered = s.borderStyle !== "none" && parseFloat(s.borderWidth) > 0;
403
+ const shadow = !!s.boxShadow && s.boxShadow !== "none";
404
+ return shadow || bordered && parseFloat(s.borderRadius) > 0;
405
+ } catch {
406
+ return false;
407
+ }
408
+ }
409
+ function nounFor(tag, kind, r = "", inputType = "", boxed = false, titled = false) {
410
+ switch (kind) {
411
+ case "action":
412
+ if (r === "tab") return "Tab";
413
+ if (r.startsWith("menuitem")) return "Menu item";
414
+ if (r === "checkbox" || inputType === "checkbox") return "Checkbox";
415
+ if (r === "radio" || r === "option" || inputType === "radio") return "Option";
416
+ if (r === "switch") return "Switch";
417
+ if (tag === "a" || r === "link") return "Link";
418
+ return "Button";
419
+ case "field":
420
+ if (tag === "select" || r === "combobox") return "Dropdown";
421
+ if (tag === "textarea") return "Text area";
422
+ if (inputType === "checkbox") return "Checkbox";
423
+ if (inputType === "radio") return "Option";
424
+ if (inputType === "range" || r === "slider") return "Slider";
425
+ if (inputType === "file") return "File upload";
426
+ if (inputType === "search" || r === "searchbox") return "Search box";
427
+ if (/^(date|datetime-local|month|week|time)$/.test(inputType)) return "Date picker";
428
+ return "Text box";
429
+ case "media":
430
+ if (tag === "svg") return "Icon";
431
+ if (tag === "video") return "Video";
432
+ if (tag === "audio") return "Audio player";
433
+ if (tag === "iframe") return "Embedded content";
434
+ if (tag === "canvas") return "Chart or drawing";
435
+ return "Image";
436
+ case "text":
437
+ if (HEADING.test(tag) || r === "heading") return "Heading";
438
+ if (tag === "li") return "List item";
439
+ if (tag === "label") return "Label";
440
+ if (tag === "td" || tag === "th") return "Table cell";
441
+ if (tag === "blockquote" || tag === "q") return "Quote";
442
+ if (tag === "code" || tag === "pre") return "Code";
443
+ return "Text";
444
+ case "section":
445
+ if (tag === "html" || tag === "body") return "Whole page";
446
+ if (tag === "main" || r === "main") return "Main content";
447
+ if (tag === "header") return "Page header";
448
+ if (tag === "footer") return "Page footer";
449
+ if (tag === "nav") return "Navigation menu";
450
+ return "Page section";
451
+ default:
452
+ if (tag === "nav" || r === "navigation" || r === "menu" || r === "menubar") return "Menu";
453
+ if (tag === "header") return "Header";
454
+ if (tag === "footer") return "Footer";
455
+ if (tag === "aside") return "Sidebar";
456
+ if (tag === "form" || r === "form") return "Form";
457
+ if (tag === "table" || r === "table" || r === "grid") return "Table";
458
+ if (tag === "ul" || tag === "ol" || r === "list") return "List";
459
+ if (tag === "dialog" || r === "dialog" || r === "alertdialog") return "Pop-up";
460
+ if (boxed) return "Card";
461
+ if (titled) return "Section";
462
+ return "Area";
463
+ }
464
+ }
465
+ function fieldName(el) {
466
+ const labels = el.labels;
467
+ if (labels && labels.length) return textOf(labels[0], MAX_NAME);
468
+ return redact(el.getAttribute("aria-label") ?? "") || redact(el.getAttribute("placeholder") ?? "");
469
+ }
470
+ function firstHeading(el) {
471
+ return el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
472
+ }
473
+ function nameOf(el, kind) {
474
+ if (isMasked(el) || el.tagName === "BODY" || el.tagName === "HTML") return "";
475
+ const aria = redact(el.getAttribute("aria-label") ?? "");
476
+ switch (kind) {
477
+ case "action":
478
+ return aria || textOf(el, MAX_NAME) || redact(el.getAttribute("title") ?? "") || redact(el.querySelector("img[alt]")?.getAttribute("alt") ?? "");
479
+ case "field":
480
+ return fieldName(el);
481
+ case "media":
482
+ return redact(el.getAttribute("alt") ?? "") || aria || redact(el.getAttribute("title") ?? "");
483
+ case "text":
484
+ return textOf(el, MAX_NAME);
485
+ default: {
486
+ const heading = firstHeading(el);
487
+ return aria || (heading ? textOf(heading, MAX_NAME) : "");
488
+ }
489
+ }
490
+ }
491
+ function quoted(noun, name) {
492
+ const clean = truncate(name.replace(/\s+/g, " ").trim(), MAX_NAME);
493
+ return clean ? `${noun} \u201C${clean}\u201D` : noun;
494
+ }
495
+ function describeElement(el) {
496
+ const tag = el.tagName.toLowerCase();
497
+ const kind = tag === "svg" ? "media" : detectKind(el);
498
+ const r = role2(el);
499
+ const inputType = tag === "input" ? (el.type || "").toLowerCase() : "";
500
+ const container = kind === "container";
501
+ const noun = nounFor(tag, kind, r, inputType, container && hasBox(el), container && !!firstHeading(el));
502
+ return quoted(noun, nameOf(el, kind));
503
+ }
504
+ function describeTarget(target) {
505
+ const facts = target.facts ?? {};
506
+ const noun = nounFor(target.tag, target.kind, "", (facts.type ?? "").toLowerCase(), false, !!facts.heading);
507
+ const name = facts.label || facts.heading || facts.text || facts.alt || "";
508
+ return quoted(noun, name);
509
+ }
510
+
145
511
  // src/core/overlay/overlay-renderer.ts
146
512
  var OVERLAY_ID = "__grabby-overlay__";
147
513
  var LABEL_ID = "__grabby-label__";
148
514
  var STYLE_ID = "__grabby-styles__";
149
515
  var MAX_LABEL_CLASSES = 3;
150
- function createOverlayRenderer() {
516
+ function createOverlayRenderer(options = {}) {
151
517
  let overlay = null;
152
518
  let label = null;
153
519
  let rafId = null;
@@ -155,6 +521,7 @@ function createOverlayRenderer() {
155
521
  let currentComponentName = null;
156
522
  let currentSourcePath = null;
157
523
  let currentCssClasses = [];
524
+ let currentPlainLabel = "";
158
525
  function injectStyles2() {
159
526
  if (hasStyles(STYLE_ID)) return;
160
527
  addStyles(STYLE_ID, `
@@ -182,6 +549,11 @@ function createOverlayRenderer() {
182
549
  overflow: hidden;
183
550
  text-overflow: ellipsis;
184
551
  }
552
+ #${LABEL_ID}.grabby-plain {
553
+ font: 600 12px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
554
+ padding: 3px 8px;
555
+ border-radius: 6px;
556
+ }
185
557
  `);
186
558
  }
187
559
  function ensureElements() {
@@ -194,6 +566,7 @@ function createOverlayRenderer() {
194
566
  if (!label) {
195
567
  label = document.createElement("div");
196
568
  label.id = LABEL_ID;
569
+ if (options.plainLabels) label.className = "grabby-plain";
197
570
  getUiRoot().appendChild(label);
198
571
  }
199
572
  }
@@ -212,6 +585,11 @@ function createOverlayRenderer() {
212
585
  overlay.style.display = "block";
213
586
  const tag = currentElement.tagName.toLowerCase();
214
587
  let labelText = `<${tag}>`;
588
+ if (options.plainLabels) {
589
+ label.textContent = `${currentPlainLabel} \xB7 Click to select`;
590
+ placeLabel(rect);
591
+ return;
592
+ }
215
593
  if (currentCssClasses.length > 0) {
216
594
  const shown = currentCssClasses.slice(0, MAX_LABEL_CLASSES);
217
595
  labelText += ` .${shown.join(".")}${currentCssClasses.length > shown.length ? "\u2026" : ""}`;
@@ -223,6 +601,10 @@ function createOverlayRenderer() {
223
601
  labelText += ` \u2014 ${currentSourcePath}`;
224
602
  }
225
603
  label.textContent = labelText;
604
+ placeLabel(rect);
605
+ }
606
+ function placeLabel(rect) {
607
+ if (!label) return;
226
608
  const labelHeight = 20;
227
609
  const gap = 4;
228
610
  let labelTop = rect.top - labelHeight - gap;
@@ -255,6 +637,7 @@ function createOverlayRenderer() {
255
637
  ensureElements();
256
638
  currentElement = element;
257
639
  currentComponentName = componentName;
640
+ if (options.plainLabels) currentPlainLabel = describeElement(element);
258
641
  currentSourcePath = sourcePath ?? null;
259
642
  currentCssClasses = cssClasses ?? [];
260
643
  stopTracking();
@@ -654,360 +1037,112 @@ function showToast(message, opts = {}) {
654
1037
  void toast.offsetHeight;
655
1038
  toast.classList.add("grabby-toast-visible");
656
1039
  activeTimer = setTimeout(() => {
657
- toast.classList.remove("grabby-toast-visible");
658
- activeTimer = null;
659
- }, durationMs);
660
- }
661
- function hideToast() {
662
- if (activeTimer) {
663
- clearTimeout(activeTimer);
664
- activeTimer = null;
665
- }
666
- toastEl?.classList.remove("grabby-toast-visible");
667
- }
668
- function disposeToast() {
669
- if (activeTimer) {
670
- clearTimeout(activeTimer);
671
- activeTimer = null;
672
- }
673
- toastEl?.remove();
674
- toastEl = null;
675
- removeStyles(TOAST_STYLE_ID);
676
- }
677
-
678
- // src/core/utils.ts
679
- function filterAngularClasses(classList) {
680
- return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
681
- }
682
- function cssEscape(value) {
683
- if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
684
- let out = "";
685
- for (let i = 0; i < value.length; i++) {
686
- const ch = value.charAt(i);
687
- const code = value.charCodeAt(i);
688
- if (code === 0) {
689
- out += "\uFFFD";
690
- continue;
691
- }
692
- if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
693
- out += `\\${code.toString(16)} `;
694
- continue;
695
- }
696
- if (i === 0 && value.length === 1 && code === 45) {
697
- out += `\\${ch}`;
698
- continue;
699
- }
700
- if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
701
- out += ch;
702
- continue;
703
- }
704
- out += `\\${ch}`;
705
- }
706
- return out;
707
- }
708
- function safeQuery(selector, root2 = document) {
709
- if (!selector) return null;
710
- try {
711
- return root2.querySelector(selector);
712
- } catch {
713
- return null;
714
- }
715
- }
716
- var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
717
- var MAX_SELECTOR_DEPTH = 8;
718
- function isUnique(selector, el) {
719
- try {
720
- const matches = el.ownerDocument.querySelectorAll(selector);
721
- return matches.length === 1 && matches[0] === el;
722
- } catch {
723
- return false;
724
- }
725
- }
726
- function stepFor(el) {
727
- const tag = el.tagName.toLowerCase();
728
- const parent = el.parentElement;
729
- if (!parent) return tag;
730
- const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
731
- if (sameTag.length === 1) return tag;
732
- return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
733
- }
734
- function buildUniqueSelector(el) {
735
- for (const attr of TEST_ID_ATTRS) {
736
- const value = el.getAttribute(attr);
737
- if (value) {
738
- const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
739
- if (isUnique(sel, el)) return sel;
740
- }
741
- }
742
- if (el.id) {
743
- const sel = `#${cssEscape(el.id)}`;
744
- if (isUnique(sel, el)) return sel;
745
- }
746
- const steps = [];
747
- let current = el;
748
- while (current && steps.length < MAX_SELECTOR_DEPTH) {
749
- if (current !== el && current.id) {
750
- const anchor = `#${cssEscape(current.id)}`;
751
- if (isUnique(anchor, current)) {
752
- steps.unshift(anchor);
753
- break;
754
- }
755
- }
756
- steps.unshift(stepFor(current));
757
- const sel = steps.join(" > ");
758
- if (isUnique(sel, el)) return sel;
759
- if (current.tagName === "BODY" || current.tagName === "HTML") break;
760
- current = current.parentElement;
761
- }
762
- return steps.join(" > ");
763
- }
764
-
765
- // src/core/capture/kind.ts
766
- var ACTION_TAGS = /* @__PURE__ */ new Set(["BUTTON", "A", "SUMMARY"]);
767
- var ACTION_ROLES = /* @__PURE__ */ new Set(["button", "link", "tab", "menuitem", "menuitemcheckbox", "menuitemradio", "switch", "option", "checkbox", "radio"]);
768
- var BUTTON_INPUT_TYPES = /* @__PURE__ */ new Set(["button", "submit", "reset", "image"]);
769
- var FIELD_TAGS = /* @__PURE__ */ new Set(["INPUT", "SELECT", "TEXTAREA"]);
770
- var FIELD_ROLES = /* @__PURE__ */ new Set(["textbox", "combobox", "searchbox", "spinbutton", "slider"]);
771
- var MEDIA_TAGS = /* @__PURE__ */ new Set(["IMG", "SVG", "VIDEO", "PICTURE", "CANVAS", "IFRAME", "AUDIO"]);
772
- var TEXT_TAGS = /* @__PURE__ */ new Set([
773
- "H1",
774
- "H2",
775
- "H3",
776
- "H4",
777
- "H5",
778
- "H6",
779
- "P",
780
- "SPAN",
781
- "LABEL",
782
- "LI",
783
- "STRONG",
784
- "EM",
785
- "B",
786
- "I",
787
- "SMALL",
788
- "BLOCKQUOTE",
789
- "CODE",
790
- "PRE",
791
- "TD",
792
- "TH",
793
- "DT",
794
- "DD",
795
- "FIGCAPTION",
796
- "LEGEND",
797
- "CAPTION",
798
- "Q",
799
- "CITE",
800
- "MARK",
801
- "TIME"
802
- ]);
803
- var PAGE_TAGS = /* @__PURE__ */ new Set(["HTML", "BODY", "MAIN"]);
804
- var LANDMARK_TAGS = /* @__PURE__ */ new Set(["HEADER", "FOOTER", "NAV", "ASIDE"]);
805
- var SECTION_AREA_RATIO = 0.6;
806
- function role(el) {
807
- return (el.getAttribute("role") ?? "").toLowerCase();
808
- }
809
- function isAction(el) {
810
- if (ACTION_TAGS.has(el.tagName)) return el.tagName !== "A" || el.hasAttribute("href") || el.hasAttribute("role");
811
- if (el.tagName === "INPUT" && BUTTON_INPUT_TYPES.has(el.type)) return true;
812
- return ACTION_ROLES.has(role(el));
813
- }
814
- function isField(el) {
815
- if (el.tagName === "INPUT") return !BUTTON_INPUT_TYPES.has(el.type);
816
- if (FIELD_TAGS.has(el.tagName)) return true;
817
- if (el.isContentEditable && el.getAttribute("contenteditable") !== null) return true;
818
- return FIELD_ROLES.has(role(el));
819
- }
820
- function coversViewport(el) {
821
- const rect = el.getBoundingClientRect();
822
- const vw = window.innerWidth || document.documentElement.clientWidth;
823
- const vh = window.innerHeight || document.documentElement.clientHeight;
824
- if (!vw || !vh) return false;
825
- const w = Math.max(0, Math.min(rect.right, vw) - Math.max(rect.left, 0));
826
- const hgt = Math.max(0, Math.min(rect.bottom, vh) - Math.max(rect.top, 0));
827
- return w * hgt / (vw * vh) >= SECTION_AREA_RATIO;
828
- }
829
- function hasElementChildren(el) {
830
- return el.children.length > 0;
1040
+ toast.classList.remove("grabby-toast-visible");
1041
+ activeTimer = null;
1042
+ }, durationMs);
831
1043
  }
832
- function detectKind(el) {
833
- if (PAGE_TAGS.has(el.tagName)) return "section";
834
- if (MEDIA_TAGS.has(el.tagName)) return "media";
835
- if (isField(el)) return "field";
836
- if (isAction(el)) return "action";
837
- if (LANDMARK_TAGS.has(el.tagName) || role(el) === "main" || role(el) === "region") {
838
- return coversViewport(el) ? "section" : "container";
1044
+ function hideToast() {
1045
+ if (activeTimer) {
1046
+ clearTimeout(activeTimer);
1047
+ activeTimer = null;
839
1048
  }
840
- if (TEXT_TAGS.has(el.tagName)) return "text";
841
- if (!hasElementChildren(el) && (el.textContent ?? "").trim()) return "text";
842
- if (coversViewport(el)) return "section";
843
- return "container";
1049
+ toastEl?.classList.remove("grabby-toast-visible");
844
1050
  }
845
- var PROMOTE_DEPTH = 3;
846
- function promoteTarget(el) {
847
- if (isAction(el) || isField(el)) return el;
848
- let current = el.parentElement;
849
- for (let depth = 0; current && depth < PROMOTE_DEPTH; depth++) {
850
- if (isAction(current) || isField(current)) return current;
851
- if (PAGE_TAGS.has(current.tagName)) break;
852
- current = current.parentElement;
1051
+ function disposeToast() {
1052
+ if (activeTimer) {
1053
+ clearTimeout(activeTimer);
1054
+ activeTimer = null;
853
1055
  }
854
- return el;
1056
+ toastEl?.remove();
1057
+ toastEl = null;
1058
+ removeStyles(TOAST_STYLE_ID);
855
1059
  }
856
1060
 
857
- // src/core/capture/redact.ts
858
- var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
859
- var JWT = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
860
- var BEARER = /\b(Bearer|Basic|Token)\s+[A-Za-z0-9._~+/=-]{8,}/gi;
861
- var LONG_NUMBER = /\b\d(?:[ -]?\d){8,}\b/g;
862
- var OPAQUE_TOKEN = /\b[A-Za-z0-9_-]{32,}\b/g;
863
- var SENSITIVE_PARAM = /([?&#](?:access_token|id_token|token|key|api_key|apikey|secret|password|pass|auth|code|session|sig|signature)=)[^&#\s]*/gi;
864
- function redact(text, options = {}) {
865
- if (!text) return text;
866
- const scrubbed = text.replace(SENSITIVE_PARAM, "$1[redacted]").replace(JWT, "[token]").replace(BEARER, "$1 [token]");
867
- 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);
1061
+ // src/core/utils.ts
1062
+ function filterAngularClasses(classList) {
1063
+ return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
868
1064
  }
869
- function sanitizeRoute(loc, keepParams = []) {
870
- let route = loc.pathname || "/";
871
- if (keepParams.length > 0 && loc.search) {
872
- const params = new URLSearchParams(loc.search);
873
- const kept = new URLSearchParams();
874
- for (const name of keepParams) {
875
- const value = params.get(name);
876
- if (value !== null) kept.set(name, value);
1065
+ function cssEscape(value) {
1066
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
1067
+ let out = "";
1068
+ for (let i = 0; i < value.length; i++) {
1069
+ const ch = value.charAt(i);
1070
+ const code = value.charCodeAt(i);
1071
+ if (code === 0) {
1072
+ out += "\uFFFD";
1073
+ continue;
877
1074
  }
878
- const qs = kept.toString();
879
- if (qs) route += `?${qs}`;
1075
+ if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
1076
+ out += `\\${code.toString(16)} `;
1077
+ continue;
1078
+ }
1079
+ if (i === 0 && value.length === 1 && code === 45) {
1080
+ out += `\\${ch}`;
1081
+ continue;
1082
+ }
1083
+ if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
1084
+ out += ch;
1085
+ continue;
1086
+ }
1087
+ out += `\\${ch}`;
880
1088
  }
881
- if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
882
- return redact(route);
1089
+ return out;
883
1090
  }
884
- function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
1091
+ function safeQuery(selector, root2 = document) {
1092
+ if (!selector) return null;
885
1093
  try {
886
- const url = new URL(raw, base);
887
- if (url.protocol === "javascript:" || url.protocol === "data:" || url.protocol === "vbscript:") return `${url.protocol}\u2026`;
888
- const baseUrl = new URL(base);
889
- const path = url.pathname + (url.hash.startsWith("#/") ? url.hash : "");
890
- return redact(url.origin === baseUrl.origin ? path : `${url.host}${path}`);
1094
+ return root2.querySelector(selector);
891
1095
  } catch {
892
- return redact(raw.split(/[?#]/)[0]);
893
- }
894
- }
895
-
896
- // src/core/capture/preview.ts
897
- var MASK_ATTR = "data-grabby-mask";
898
- var IGNORE_ATTR = "data-grabby-ignore";
899
- var PRIORITY_ATTRS = [
900
- "id",
901
- "class",
902
- "role",
903
- "aria-label",
904
- "data-testid",
905
- "data-test",
906
- "data-cy",
907
- "name",
908
- "type",
909
- "href",
910
- "src",
911
- "alt",
912
- "placeholder",
913
- "title",
914
- "for",
915
- "aria-expanded",
916
- "aria-selected",
917
- "disabled"
918
- ];
919
- var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src"]);
920
- var MAX_ATTRS = 8;
921
- var MAX_CLASS_CHARS = 60;
922
- var MAX_ATTR_CHARS = 80;
923
- var MAX_TEXT_CHARS = 80;
924
- var MAX_PREVIEW_CHARS = 300;
925
- function isNoiseAttr(name) {
926
- 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");
927
- }
928
- function isNoiseClass(name) {
929
- return name.startsWith("ng-") || name.startsWith("_ng") || /^svelte-[a-z0-9]+$/i.test(name) || /^s-[A-Za-z0-9_-]{8,}$/.test(name);
930
- }
931
- function truncate(text, max) {
932
- return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}\u2026`;
933
- }
934
- function isMasked(el) {
935
- return el.closest(`[${MASK_ATTR}]`) !== null;
936
- }
937
- function textOf(el, max) {
938
- if (isMasked(el)) return "[masked]";
939
- let raw = "";
940
- const walker = el.ownerDocument.createTreeWalker(el, NodeFilter.SHOW_TEXT);
941
- for (let node = walker.nextNode(); node; node = walker.nextNode()) {
942
- const parent = node.parentElement;
943
- if (parent && /^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE)$/.test(parent.tagName)) continue;
944
- if (parent?.closest(`[${IGNORE_ATTR}], [${MASK_ATTR}]`)) continue;
945
- raw += ` ${node.nodeValue ?? ""}`;
946
- if (raw.length > max * 3) break;
947
- }
948
- return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
949
- }
950
- function ownText(el) {
951
- let raw = "";
952
- for (const node of Array.from(el.childNodes)) {
953
- if (node.nodeType === Node.TEXT_NODE) raw += ` ${node.nodeValue ?? ""}`;
1096
+ return null;
954
1097
  }
955
- return raw.replace(/\s+/g, " ").trim();
956
1098
  }
957
- function attrValue(el, name, value, cleanClasses) {
958
- if (name === "class") {
959
- const classes = cleanClasses(value.split(/\s+/).filter(Boolean));
960
- if (classes.length === 0) return null;
961
- return truncate(classes.join(" "), MAX_CLASS_CHARS);
1099
+ var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
1100
+ var MAX_SELECTOR_DEPTH = 8;
1101
+ function isUnique(selector, el) {
1102
+ try {
1103
+ const matches = el.ownerDocument.querySelectorAll(selector);
1104
+ return matches.length === 1 && matches[0] === el;
1105
+ } catch {
1106
+ return false;
962
1107
  }
963
- if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
964
- return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
965
1108
  }
966
- function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
1109
+ function stepFor(el) {
967
1110
  const tag = el.tagName.toLowerCase();
968
- const attrs = [];
969
- const seen2 = /* @__PURE__ */ new Set();
970
- const add = (name) => {
971
- if (attrs.length >= MAX_ATTRS || seen2.has(name) || isNoiseAttr(name)) return;
972
- const raw = el.getAttribute(name);
973
- if (raw === null) return;
974
- seen2.add(name);
975
- if (raw === "") {
976
- attrs.push(name);
977
- return;
1111
+ const parent = el.parentElement;
1112
+ if (!parent) return tag;
1113
+ const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
1114
+ if (sameTag.length === 1) return tag;
1115
+ return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
1116
+ }
1117
+ function buildUniqueSelector(el) {
1118
+ for (const attr of TEST_ID_ATTRS) {
1119
+ const value = el.getAttribute(attr);
1120
+ if (value) {
1121
+ const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
1122
+ if (isUnique(sel, el)) return sel;
978
1123
  }
979
- const value = attrValue(el, name, raw, cleanClasses);
980
- if (value !== null) attrs.push(`${name}="${value.replace(/"/g, "&quot;")}"`);
981
- };
982
- for (const name of PRIORITY_ATTRS) add(name);
983
- for (const { name } of Array.from(el.attributes)) {
984
- if (name.startsWith("aria-")) add(name);
985
1124
  }
986
- return `<${tag}${attrs.length ? ` ${attrs.join(" ")}` : ""}>`;
987
- }
988
- function buildPreview(el, cleanClasses) {
989
- const tag = el.tagName.toLowerCase();
990
- const open = openingTag(el, cleanClasses);
991
- if (/^(img|input|br|hr|meta|link|source|area|col|embed|wbr)$/.test(tag)) {
992
- return truncate(open, MAX_PREVIEW_CHARS);
1125
+ if (el.id) {
1126
+ const sel = `#${cssEscape(el.id)}`;
1127
+ if (isUnique(sel, el)) return sel;
993
1128
  }
994
- const children = Array.from(el.children).filter((c) => !c.hasAttribute(IGNORE_ATTR));
995
- let inner;
996
- if (isMasked(el)) {
997
- inner = "[masked]";
998
- } else if (children.length === 0) {
999
- inner = truncate(redact(ownText(el)), MAX_TEXT_CHARS);
1000
- } else if (children.length <= 2) {
1001
- const text = truncate(redact(ownText(el)), 40);
1002
- const kids = children.map((c) => {
1003
- const t = textOf(c, 30);
1004
- return `<${c.tagName.toLowerCase()}${t ? `>${t}</${c.tagName.toLowerCase()}>` : " \u2026>"}`;
1005
- });
1006
- inner = [text, ...kids].filter(Boolean).join(" ");
1007
- } else {
1008
- inner = `(${children.length} elements)`;
1129
+ const steps = [];
1130
+ let current = el;
1131
+ while (current && steps.length < MAX_SELECTOR_DEPTH) {
1132
+ if (current !== el && current.id) {
1133
+ const anchor = `#${cssEscape(current.id)}`;
1134
+ if (isUnique(anchor, current)) {
1135
+ steps.unshift(anchor);
1136
+ break;
1137
+ }
1138
+ }
1139
+ steps.unshift(stepFor(current));
1140
+ const sel = steps.join(" > ");
1141
+ if (isUnique(sel, el)) return sel;
1142
+ if (current.tagName === "BODY" || current.tagName === "HTML") break;
1143
+ current = current.parentElement;
1009
1144
  }
1010
- return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
1145
+ return steps.join(" > ");
1011
1146
  }
1012
1147
 
1013
1148
  // src/core/picker/element-picker.ts
@@ -1137,6 +1272,7 @@ function matchesCombo(e, parsed) {
1137
1272
  function createKeyboardHandler(deps) {
1138
1273
  let holdTimer = null;
1139
1274
  let holdActivated = false;
1275
+ let togglePending = false;
1140
1276
  let listening = false;
1141
1277
  function handleKeyDown(e) {
1142
1278
  if (!deps.getEnableInInputs() && isEditableElement(eventTarget(e))) return;
@@ -1159,6 +1295,7 @@ function createKeyboardHandler(deps) {
1159
1295
  }
1160
1296
  } else {
1161
1297
  e.preventDefault();
1298
+ togglePending = true;
1162
1299
  }
1163
1300
  }
1164
1301
  function handleKeyUp(e) {
@@ -1175,6 +1312,8 @@ function createKeyboardHandler(deps) {
1175
1312
  deps.onDeactivate();
1176
1313
  }
1177
1314
  } else {
1315
+ if (!togglePending) return;
1316
+ togglePending = false;
1178
1317
  if (deps.isActive()) {
1179
1318
  deps.onDeactivate();
1180
1319
  } else {
@@ -1197,6 +1336,7 @@ function createKeyboardHandler(deps) {
1197
1336
  holdTimer = null;
1198
1337
  }
1199
1338
  holdActivated = false;
1339
+ togglePending = false;
1200
1340
  document.removeEventListener("keydown", handleKeyDown, true);
1201
1341
  document.removeEventListener("keyup", handleKeyUp, true);
1202
1342
  },
@@ -1997,16 +2137,18 @@ function createCommentsPanel(callbacks, options = {}) {
1997
2137
  }
1998
2138
  function row2(comment, showAuthors) {
1999
2139
  const t = comment.target;
2000
- const meta = [h("span", { class: "grabby-kind" }, t.kind)];
2001
- if (t.component) meta.push(document.createTextNode(`${t.component} `));
2002
- if (t.source) {
2003
- meta.push(h("a", {
2004
- href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
2005
- title: `Open ${t.source.file} in VS Code`,
2006
- onclick: (e) => e.stopPropagation()
2007
- }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2008
- } else if (!t.component) {
2009
- meta.push(document.createTextNode(`<${t.tag}>`));
2140
+ const meta = live ? [document.createTextNode(`${describeTarget(t)} `)] : [h("span", { class: "grabby-kind" }, t.kind)];
2141
+ if (!live) {
2142
+ if (t.component) meta.push(document.createTextNode(`${t.component} `));
2143
+ if (t.source) {
2144
+ meta.push(h("a", {
2145
+ href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
2146
+ title: `Open ${t.source.file} in VS Code`,
2147
+ onclick: (e) => e.stopPropagation()
2148
+ }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2149
+ } else if (!t.component) {
2150
+ meta.push(document.createTextNode(`<${t.tag}>`));
2151
+ }
2010
2152
  }
2011
2153
  const tail = [showAuthors && !live ? authorLabel(comment.author) : "", formatRelativeTime(comment.createdAt)].filter(Boolean);
2012
2154
  meta.push(document.createTextNode(` \xB7 ${tail.join(" \xB7 ")}`));
@@ -2879,7 +3021,7 @@ function loadJobs() {
2879
3021
  const raw = localStorage.getItem(STORE_KEY);
2880
3022
  const jobs = raw ? JSON.parse(raw) : [];
2881
3023
  if (!Array.isArray(jobs)) return [];
2882
- 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() });
3024
+ 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() });
2883
3025
  } catch {
2884
3026
  return [];
2885
3027
  }
@@ -2936,7 +3078,21 @@ function createOutbox(deps) {
2936
3078
  body
2937
3079
  });
2938
3080
  }
3081
+ function deleteComment(id, session) {
3082
+ return fetch(`${base}/v1/comments/${encodeURIComponent(id)}`, {
3083
+ method: "DELETE",
3084
+ credentials: "omit",
3085
+ keepalive: true,
3086
+ headers: headers({ "X-Grabby-Session": session })
3087
+ });
3088
+ }
2939
3089
  async function deliver(job) {
3090
+ if (job.kind === "delete") {
3091
+ const res2 = await deleteComment(job.id, job.session);
3092
+ if (res2.ok || res2.status === 404) return "done";
3093
+ if (res2.status === 429 || res2.status >= 500) return "retry";
3094
+ return "drop";
3095
+ }
2940
3096
  const comment = deps.getComment(job.id);
2941
3097
  if (!comment) return "drop";
2942
3098
  if (job.kind === "comment") {
@@ -3001,6 +3157,19 @@ function createOutbox(deps) {
3001
3157
  if (jobs.length) schedule(500);
3002
3158
  return {
3003
3159
  send: (id) => add(id, "comment"),
3160
+ remove(id, sessionId, delayMs = 0) {
3161
+ jobs = jobs.filter((j) => j.id !== id);
3162
+ jobs.push({ id, kind: "delete", session: sessionId, attempts: 0, next: Date.now() + delayMs, created: Date.now() });
3163
+ save();
3164
+ schedule(0);
3165
+ },
3166
+ cancelRemove(id) {
3167
+ const job = jobs.find((j) => j.id === id && j.kind === "delete");
3168
+ if (!job) return false;
3169
+ jobs = jobs.filter((j) => j !== job);
3170
+ save();
3171
+ return job.attempts === 0;
3172
+ },
3004
3173
  sendScreenshot: (id) => {
3005
3174
  if (!jobs.some((j) => j.id === id && j.kind === "comment")) add(id, "shot");
3006
3175
  },
@@ -3008,11 +3177,18 @@ function createOutbox(deps) {
3008
3177
  flush: onOnline,
3009
3178
  flushOnExit() {
3010
3179
  for (const job of jobs) {
3180
+ if (job.kind === "delete") {
3181
+ job.attempts += 1;
3182
+ deleteComment(job.id, job.session).catch(() => {
3183
+ });
3184
+ continue;
3185
+ }
3011
3186
  if (job.kind !== "comment") continue;
3012
3187
  const comment = deps.getComment(job.id);
3013
3188
  if (comment) postComment(comment).catch(() => {
3014
3189
  });
3015
3190
  }
3191
+ save();
3016
3192
  },
3017
3193
  dispose() {
3018
3194
  disposed = true;
@@ -3596,13 +3772,13 @@ function childSummary(el, resolver) {
3596
3772
  if (counts.size > 6) parts.push("\u2026");
3597
3773
  return parts.join(", ");
3598
3774
  }
3599
- function firstHeading(el) {
3775
+ function firstHeading2(el) {
3600
3776
  const heading = el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
3601
3777
  return heading ? textOf(heading, 60) : "";
3602
3778
  }
3603
3779
  function containerFacts(el, resolver) {
3604
3780
  const f = {};
3605
- put(f, "heading", firstHeading(el));
3781
+ put(f, "heading", firstHeading2(el));
3606
3782
  put(f, "contains", childSummary(el, resolver));
3607
3783
  put(f, "size", size(el));
3608
3784
  put(f, "layout", formatStyles(customStyles(el, CONTAINER_STYLES)));
@@ -3613,7 +3789,7 @@ function sectionFacts(el, resolver) {
3613
3789
  put(f, "title", redact(el.ownerDocument.title));
3614
3790
  put(f, "viewport", `${window.innerWidth}\xD7${window.innerHeight}`);
3615
3791
  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) => {
3616
- const heading = firstHeading(r);
3792
+ const heading = firstHeading2(r);
3617
3793
  return heading ? `${r.tagName.toLowerCase()} "${truncate(heading, 30)}"` : r.tagName.toLowerCase();
3618
3794
  });
3619
3795
  put(f, "regions", regions.join(", "));
@@ -4442,7 +4618,7 @@ function createGrabInstance(options) {
4442
4618
  store.state.toolbar = { ...store.state.toolbar, comments: persisted };
4443
4619
  }
4444
4620
  }
4445
- const overlay = createOverlayRenderer();
4621
+ const overlay = createOverlayRenderer({ plainLabels: live });
4446
4622
  const crosshair = createCrosshair();
4447
4623
  const freezeOverlay = createFreezeOverlay();
4448
4624
  const pluginRegistry = createPluginRegistry();
@@ -4570,12 +4746,15 @@ function createGrabInstance(options) {
4570
4746
  pluginRegistry.callHook("onScreenshot", updated, result.blob);
4571
4747
  outbox?.sendScreenshot(id);
4572
4748
  }
4573
- function removeComments(ids, message) {
4749
+ function removeComments(ids, message, withdraw = false) {
4574
4750
  if (ids.length === 0) return;
4575
4751
  const idSet = new Set(ids);
4576
4752
  const before = comments();
4577
4753
  const removed = before.filter((c) => idSet.has(c.id));
4578
4754
  setComments(before.filter((c) => !idSet.has(c.id)));
4755
+ const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
4756
+ const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
4757
+ for (const c of withdrawn) outbox.remove(c.id, c.author.sessionId, message ? UNDO_MS + 500 : 0);
4579
4758
  const shotIds = removed.flatMap((c) => c.screenshot?.localId ? [c.screenshot.localId] : []);
4580
4759
  const key = randomId();
4581
4760
  pendingShotDeletes.set(key, setTimeout(() => {
@@ -4591,8 +4770,11 @@ function createGrabInstance(options) {
4591
4770
  clearTimeout(pendingShotDeletes.get(key));
4592
4771
  pendingShotDeletes.delete(key);
4593
4772
  const present = new Set(comments().map((c) => c.id));
4594
- const restored = [...removed.filter((c) => !present.has(c.id)), ...comments()].sort((a, b) => b.createdAt - a.createdAt);
4773
+ 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));
4774
+ const back = removed.filter((c) => !present.has(c.id)).map((c) => resend.has(c.id) ? { ...c, sync: "pending" } : c);
4775
+ const restored = [...back, ...comments()].sort((a, b) => b.createdAt - a.createdAt);
4595
4776
  setComments(restored);
4777
+ for (const id of resend) outbox?.send(id);
4596
4778
  showToast(`Restored ${removed.length} comment${removed.length === 1 ? "" : "s"}`);
4597
4779
  }
4598
4780
  }]
@@ -4758,7 +4940,7 @@ function createGrabInstance(options) {
4758
4940
  },
4759
4941
  onDelete(comment) {
4760
4942
  overlay.hide();
4761
- removeComments([comment.id], "Comment deleted");
4943
+ removeComments([comment.id], "Comment deleted", true);
4762
4944
  },
4763
4945
  onCopyAll() {
4764
4946
  overlay.hide();
@@ -4767,7 +4949,7 @@ function createGrabInstance(options) {
4767
4949
  onClearAll() {
4768
4950
  overlay.hide();
4769
4951
  const n = comments().length;
4770
- removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`);
4952
+ removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`, true);
4771
4953
  commentsPanel.hide();
4772
4954
  },
4773
4955
  onChangeIdentity() {
@@ -4969,7 +5151,7 @@ function createGrabInstance(options) {
4969
5151
  return exportText(list, opts.level ?? level);
4970
5152
  },
4971
5153
  deleteComment(id) {
4972
- removeComments([id], null);
5154
+ removeComments([id], null, true);
4973
5155
  },
4974
5156
  clearComments() {
4975
5157
  removeComments(comments().map((c) => c.id), null);