@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.
@@ -136,12 +136,378 @@ function disposeUiRoot() {
136
136
  root = null;
137
137
  }
138
138
 
139
+ // src/core/capture/kind.ts
140
+ var ACTION_TAGS = /* @__PURE__ */ new Set(["BUTTON", "A", "SUMMARY"]);
141
+ var ACTION_ROLES = /* @__PURE__ */ new Set(["button", "link", "tab", "menuitem", "menuitemcheckbox", "menuitemradio", "switch", "option", "checkbox", "radio"]);
142
+ var BUTTON_INPUT_TYPES = /* @__PURE__ */ new Set(["button", "submit", "reset", "image"]);
143
+ var FIELD_TAGS = /* @__PURE__ */ new Set(["INPUT", "SELECT", "TEXTAREA"]);
144
+ var FIELD_ROLES = /* @__PURE__ */ new Set(["textbox", "combobox", "searchbox", "spinbutton", "slider"]);
145
+ var MEDIA_TAGS = /* @__PURE__ */ new Set(["IMG", "SVG", "VIDEO", "PICTURE", "CANVAS", "IFRAME", "AUDIO"]);
146
+ var TEXT_TAGS = /* @__PURE__ */ new Set([
147
+ "H1",
148
+ "H2",
149
+ "H3",
150
+ "H4",
151
+ "H5",
152
+ "H6",
153
+ "P",
154
+ "SPAN",
155
+ "LABEL",
156
+ "LI",
157
+ "STRONG",
158
+ "EM",
159
+ "B",
160
+ "I",
161
+ "SMALL",
162
+ "BLOCKQUOTE",
163
+ "CODE",
164
+ "PRE",
165
+ "TD",
166
+ "TH",
167
+ "DT",
168
+ "DD",
169
+ "FIGCAPTION",
170
+ "LEGEND",
171
+ "CAPTION",
172
+ "Q",
173
+ "CITE",
174
+ "MARK",
175
+ "TIME"
176
+ ]);
177
+ var PAGE_TAGS = /* @__PURE__ */ new Set(["HTML", "BODY", "MAIN"]);
178
+ var LANDMARK_TAGS = /* @__PURE__ */ new Set(["HEADER", "FOOTER", "NAV", "ASIDE"]);
179
+ var SECTION_AREA_RATIO = 0.6;
180
+ function role(el) {
181
+ return (el.getAttribute("role") ?? "").toLowerCase();
182
+ }
183
+ function isAction(el) {
184
+ if (ACTION_TAGS.has(el.tagName)) return el.tagName !== "A" || el.hasAttribute("href") || el.hasAttribute("role");
185
+ if (el.tagName === "INPUT" && BUTTON_INPUT_TYPES.has(el.type)) return true;
186
+ return ACTION_ROLES.has(role(el));
187
+ }
188
+ function isField(el) {
189
+ if (el.tagName === "INPUT") return !BUTTON_INPUT_TYPES.has(el.type);
190
+ if (FIELD_TAGS.has(el.tagName)) return true;
191
+ if (el.isContentEditable && el.getAttribute("contenteditable") !== null) return true;
192
+ return FIELD_ROLES.has(role(el));
193
+ }
194
+ function coversViewport(el) {
195
+ const rect = el.getBoundingClientRect();
196
+ const vw = window.innerWidth || document.documentElement.clientWidth;
197
+ const vh = window.innerHeight || document.documentElement.clientHeight;
198
+ if (!vw || !vh) return false;
199
+ const w = Math.max(0, Math.min(rect.right, vw) - Math.max(rect.left, 0));
200
+ const hgt = Math.max(0, Math.min(rect.bottom, vh) - Math.max(rect.top, 0));
201
+ return w * hgt / (vw * vh) >= SECTION_AREA_RATIO;
202
+ }
203
+ function hasElementChildren(el) {
204
+ return el.children.length > 0;
205
+ }
206
+ function detectKind(el) {
207
+ if (PAGE_TAGS.has(el.tagName)) return "section";
208
+ if (MEDIA_TAGS.has(el.tagName)) return "media";
209
+ if (isField(el)) return "field";
210
+ if (isAction(el)) return "action";
211
+ if (LANDMARK_TAGS.has(el.tagName) || role(el) === "main" || role(el) === "region") {
212
+ return coversViewport(el) ? "section" : "container";
213
+ }
214
+ if (TEXT_TAGS.has(el.tagName)) return "text";
215
+ if (!hasElementChildren(el) && (el.textContent ?? "").trim()) return "text";
216
+ if (coversViewport(el)) return "section";
217
+ return "container";
218
+ }
219
+ var PROMOTE_DEPTH = 3;
220
+ function promoteTarget(el) {
221
+ if (isAction(el) || isField(el)) return el;
222
+ let current = el.parentElement;
223
+ for (let depth = 0; current && depth < PROMOTE_DEPTH; depth++) {
224
+ if (isAction(current) || isField(current)) return current;
225
+ if (PAGE_TAGS.has(current.tagName)) break;
226
+ current = current.parentElement;
227
+ }
228
+ return el;
229
+ }
230
+
231
+ // src/core/capture/redact.ts
232
+ var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
233
+ var JWT = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
234
+ var BEARER = /\b(Bearer|Basic|Token)\s+[A-Za-z0-9._~+/=-]{8,}/gi;
235
+ var LONG_NUMBER = /\b\d(?:[ -]?\d){8,}\b/g;
236
+ var OPAQUE_TOKEN = /\b[A-Za-z0-9_-]{32,}\b/g;
237
+ var SENSITIVE_PARAM = /([?&#](?:access_token|id_token|token|key|api_key|apikey|secret|password|pass|auth|code|session|sig|signature)=)[^&#\s]*/gi;
238
+ function redact(text, options = {}) {
239
+ if (!text) return text;
240
+ const scrubbed = text.replace(SENSITIVE_PARAM, "$1[redacted]").replace(JWT, "[token]").replace(BEARER, "$1 [token]");
241
+ 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);
242
+ }
243
+ function sanitizeRoute(loc, keepParams = []) {
244
+ let route = loc.pathname || "/";
245
+ if (keepParams.length > 0 && loc.search) {
246
+ const params = new URLSearchParams(loc.search);
247
+ const kept = new URLSearchParams();
248
+ for (const name of keepParams) {
249
+ const value = params.get(name);
250
+ if (value !== null) kept.set(name, value);
251
+ }
252
+ const qs = kept.toString();
253
+ if (qs) route += `?${qs}`;
254
+ }
255
+ if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
256
+ return redact(route);
257
+ }
258
+ function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
259
+ try {
260
+ const url = new URL(raw, base);
261
+ if (url.protocol === "javascript:" || url.protocol === "data:" || url.protocol === "vbscript:") return `${url.protocol}\u2026`;
262
+ const baseUrl = new URL(base);
263
+ const path = url.pathname + (url.hash.startsWith("#/") ? url.hash : "");
264
+ return redact(url.origin === baseUrl.origin ? path : `${url.host}${path}`);
265
+ } catch {
266
+ return redact(raw.split(/[?#]/)[0]);
267
+ }
268
+ }
269
+
270
+ // src/core/capture/preview.ts
271
+ var MASK_ATTR = "data-grabby-mask";
272
+ var IGNORE_ATTR = "data-grabby-ignore";
273
+ var PRIORITY_ATTRS = [
274
+ "id",
275
+ "class",
276
+ "role",
277
+ "aria-label",
278
+ "data-testid",
279
+ "data-test",
280
+ "data-cy",
281
+ "name",
282
+ "type",
283
+ "href",
284
+ "src",
285
+ "alt",
286
+ "placeholder",
287
+ "title",
288
+ "for",
289
+ "aria-expanded",
290
+ "aria-selected",
291
+ "disabled"
292
+ ];
293
+ var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src"]);
294
+ var MAX_ATTRS = 8;
295
+ var MAX_CLASS_CHARS = 60;
296
+ var MAX_ATTR_CHARS = 80;
297
+ var MAX_TEXT_CHARS = 80;
298
+ var MAX_PREVIEW_CHARS = 300;
299
+ function isNoiseAttr(name) {
300
+ 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");
301
+ }
302
+ function isNoiseClass(name) {
303
+ return name.startsWith("ng-") || name.startsWith("_ng") || /^svelte-[a-z0-9]+$/i.test(name) || /^s-[A-Za-z0-9_-]{8,}$/.test(name);
304
+ }
305
+ function truncate(text, max) {
306
+ return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}\u2026`;
307
+ }
308
+ function isMasked(el) {
309
+ return el.closest(`[${MASK_ATTR}]`) !== null;
310
+ }
311
+ function textOf(el, max) {
312
+ if (isMasked(el)) return "[masked]";
313
+ let raw = "";
314
+ const walker = el.ownerDocument.createTreeWalker(el, NodeFilter.SHOW_TEXT);
315
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
316
+ const parent = node.parentElement;
317
+ if (parent && /^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE)$/.test(parent.tagName)) continue;
318
+ if (parent?.closest(`[${IGNORE_ATTR}], [${MASK_ATTR}]`)) continue;
319
+ raw += ` ${node.nodeValue ?? ""}`;
320
+ if (raw.length > max * 3) break;
321
+ }
322
+ return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
323
+ }
324
+ function ownText(el) {
325
+ let raw = "";
326
+ for (const node of Array.from(el.childNodes)) {
327
+ if (node.nodeType === Node.TEXT_NODE) raw += ` ${node.nodeValue ?? ""}`;
328
+ }
329
+ return raw.replace(/\s+/g, " ").trim();
330
+ }
331
+ function attrValue(el, name, value, cleanClasses) {
332
+ if (name === "class") {
333
+ const classes = cleanClasses(value.split(/\s+/).filter(Boolean));
334
+ if (classes.length === 0) return null;
335
+ return truncate(classes.join(" "), MAX_CLASS_CHARS);
336
+ }
337
+ if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
338
+ return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
339
+ }
340
+ function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
341
+ const tag = el.tagName.toLowerCase();
342
+ const attrs = [];
343
+ const seen2 = /* @__PURE__ */ new Set();
344
+ const add = (name) => {
345
+ if (attrs.length >= MAX_ATTRS || seen2.has(name) || isNoiseAttr(name)) return;
346
+ const raw = el.getAttribute(name);
347
+ if (raw === null) return;
348
+ seen2.add(name);
349
+ if (raw === "") {
350
+ attrs.push(name);
351
+ return;
352
+ }
353
+ const value = attrValue(el, name, raw, cleanClasses);
354
+ if (value !== null) attrs.push(`${name}="${value.replace(/"/g, "&quot;")}"`);
355
+ };
356
+ for (const name of PRIORITY_ATTRS) add(name);
357
+ for (const { name } of Array.from(el.attributes)) {
358
+ if (name.startsWith("aria-")) add(name);
359
+ }
360
+ return `<${tag}${attrs.length ? ` ${attrs.join(" ")}` : ""}>`;
361
+ }
362
+ function buildPreview(el, cleanClasses) {
363
+ const tag = el.tagName.toLowerCase();
364
+ const open = openingTag(el, cleanClasses);
365
+ if (/^(img|input|br|hr|meta|link|source|area|col|embed|wbr)$/.test(tag)) {
366
+ return truncate(open, MAX_PREVIEW_CHARS);
367
+ }
368
+ const children = Array.from(el.children).filter((c) => !c.hasAttribute(IGNORE_ATTR));
369
+ let inner;
370
+ if (isMasked(el)) {
371
+ inner = "[masked]";
372
+ } else if (children.length === 0) {
373
+ inner = truncate(redact(ownText(el)), MAX_TEXT_CHARS);
374
+ } else if (children.length <= 2) {
375
+ const text = truncate(redact(ownText(el)), 40);
376
+ const kids = children.map((c) => {
377
+ const t = textOf(c, 30);
378
+ return `<${c.tagName.toLowerCase()}${t ? `>${t}</${c.tagName.toLowerCase()}>` : " \u2026>"}`;
379
+ });
380
+ inner = [text, ...kids].filter(Boolean).join(" ");
381
+ } else {
382
+ inner = `(${children.length} elements)`;
383
+ }
384
+ return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
385
+ }
386
+
387
+ // src/core/capture/describe.ts
388
+ var MAX_NAME = 40;
389
+ var HEADING = /^h[1-6]$/;
390
+ function role2(el) {
391
+ return (el.getAttribute("role") ?? "").toLowerCase();
392
+ }
393
+ function hasBox(el) {
394
+ try {
395
+ const s = getComputedStyle(el);
396
+ const bordered = s.borderStyle !== "none" && parseFloat(s.borderWidth) > 0;
397
+ const shadow = !!s.boxShadow && s.boxShadow !== "none";
398
+ return shadow || bordered && parseFloat(s.borderRadius) > 0;
399
+ } catch {
400
+ return false;
401
+ }
402
+ }
403
+ function nounFor(tag, kind, r = "", inputType = "", boxed = false, titled = false) {
404
+ switch (kind) {
405
+ case "action":
406
+ if (r === "tab") return "Tab";
407
+ if (r.startsWith("menuitem")) return "Menu item";
408
+ if (r === "checkbox" || inputType === "checkbox") return "Checkbox";
409
+ if (r === "radio" || r === "option" || inputType === "radio") return "Option";
410
+ if (r === "switch") return "Switch";
411
+ if (tag === "a" || r === "link") return "Link";
412
+ return "Button";
413
+ case "field":
414
+ if (tag === "select" || r === "combobox") return "Dropdown";
415
+ if (tag === "textarea") return "Text area";
416
+ if (inputType === "checkbox") return "Checkbox";
417
+ if (inputType === "radio") return "Option";
418
+ if (inputType === "range" || r === "slider") return "Slider";
419
+ if (inputType === "file") return "File upload";
420
+ if (inputType === "search" || r === "searchbox") return "Search box";
421
+ if (/^(date|datetime-local|month|week|time)$/.test(inputType)) return "Date picker";
422
+ return "Text box";
423
+ case "media":
424
+ if (tag === "svg") return "Icon";
425
+ if (tag === "video") return "Video";
426
+ if (tag === "audio") return "Audio player";
427
+ if (tag === "iframe") return "Embedded content";
428
+ if (tag === "canvas") return "Chart or drawing";
429
+ return "Image";
430
+ case "text":
431
+ if (HEADING.test(tag) || r === "heading") return "Heading";
432
+ if (tag === "li") return "List item";
433
+ if (tag === "label") return "Label";
434
+ if (tag === "td" || tag === "th") return "Table cell";
435
+ if (tag === "blockquote" || tag === "q") return "Quote";
436
+ if (tag === "code" || tag === "pre") return "Code";
437
+ return "Text";
438
+ case "section":
439
+ if (tag === "html" || tag === "body") return "Whole page";
440
+ if (tag === "main" || r === "main") return "Main content";
441
+ if (tag === "header") return "Page header";
442
+ if (tag === "footer") return "Page footer";
443
+ if (tag === "nav") return "Navigation menu";
444
+ return "Page section";
445
+ default:
446
+ if (tag === "nav" || r === "navigation" || r === "menu" || r === "menubar") return "Menu";
447
+ if (tag === "header") return "Header";
448
+ if (tag === "footer") return "Footer";
449
+ if (tag === "aside") return "Sidebar";
450
+ if (tag === "form" || r === "form") return "Form";
451
+ if (tag === "table" || r === "table" || r === "grid") return "Table";
452
+ if (tag === "ul" || tag === "ol" || r === "list") return "List";
453
+ if (tag === "dialog" || r === "dialog" || r === "alertdialog") return "Pop-up";
454
+ if (boxed) return "Card";
455
+ if (titled) return "Section";
456
+ return "Area";
457
+ }
458
+ }
459
+ function fieldName(el) {
460
+ const labels = el.labels;
461
+ if (labels && labels.length) return textOf(labels[0], MAX_NAME);
462
+ return redact(el.getAttribute("aria-label") ?? "") || redact(el.getAttribute("placeholder") ?? "");
463
+ }
464
+ function firstHeading(el) {
465
+ return el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
466
+ }
467
+ function nameOf(el, kind) {
468
+ if (isMasked(el) || el.tagName === "BODY" || el.tagName === "HTML") return "";
469
+ const aria = redact(el.getAttribute("aria-label") ?? "");
470
+ switch (kind) {
471
+ case "action":
472
+ return aria || textOf(el, MAX_NAME) || redact(el.getAttribute("title") ?? "") || redact(el.querySelector("img[alt]")?.getAttribute("alt") ?? "");
473
+ case "field":
474
+ return fieldName(el);
475
+ case "media":
476
+ return redact(el.getAttribute("alt") ?? "") || aria || redact(el.getAttribute("title") ?? "");
477
+ case "text":
478
+ return textOf(el, MAX_NAME);
479
+ default: {
480
+ const heading = firstHeading(el);
481
+ return aria || (heading ? textOf(heading, MAX_NAME) : "");
482
+ }
483
+ }
484
+ }
485
+ function quoted(noun, name) {
486
+ const clean = truncate(name.replace(/\s+/g, " ").trim(), MAX_NAME);
487
+ return clean ? `${noun} \u201C${clean}\u201D` : noun;
488
+ }
489
+ function describeElement(el) {
490
+ const tag = el.tagName.toLowerCase();
491
+ const kind = tag === "svg" ? "media" : detectKind(el);
492
+ const r = role2(el);
493
+ const inputType = tag === "input" ? (el.type || "").toLowerCase() : "";
494
+ const container = kind === "container";
495
+ const noun = nounFor(tag, kind, r, inputType, container && hasBox(el), container && !!firstHeading(el));
496
+ return quoted(noun, nameOf(el, kind));
497
+ }
498
+ function describeTarget(target) {
499
+ const facts = target.facts ?? {};
500
+ const noun = nounFor(target.tag, target.kind, "", (facts.type ?? "").toLowerCase(), false, !!facts.heading);
501
+ const name = facts.label || facts.heading || facts.text || facts.alt || "";
502
+ return quoted(noun, name);
503
+ }
504
+
139
505
  // src/core/overlay/overlay-renderer.ts
140
506
  var OVERLAY_ID = "__grabby-overlay__";
141
507
  var LABEL_ID = "__grabby-label__";
142
508
  var STYLE_ID = "__grabby-styles__";
143
509
  var MAX_LABEL_CLASSES = 3;
144
- function createOverlayRenderer() {
510
+ function createOverlayRenderer(options = {}) {
145
511
  let overlay = null;
146
512
  let label = null;
147
513
  let rafId = null;
@@ -149,6 +515,7 @@ function createOverlayRenderer() {
149
515
  let currentComponentName = null;
150
516
  let currentSourcePath = null;
151
517
  let currentCssClasses = [];
518
+ let currentPlainLabel = "";
152
519
  function injectStyles2() {
153
520
  if (hasStyles(STYLE_ID)) return;
154
521
  addStyles(STYLE_ID, `
@@ -176,6 +543,11 @@ function createOverlayRenderer() {
176
543
  overflow: hidden;
177
544
  text-overflow: ellipsis;
178
545
  }
546
+ #${LABEL_ID}.grabby-plain {
547
+ font: 600 12px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
548
+ padding: 3px 8px;
549
+ border-radius: 6px;
550
+ }
179
551
  `);
180
552
  }
181
553
  function ensureElements() {
@@ -188,6 +560,7 @@ function createOverlayRenderer() {
188
560
  if (!label) {
189
561
  label = document.createElement("div");
190
562
  label.id = LABEL_ID;
563
+ if (options.plainLabels) label.className = "grabby-plain";
191
564
  getUiRoot().appendChild(label);
192
565
  }
193
566
  }
@@ -206,6 +579,11 @@ function createOverlayRenderer() {
206
579
  overlay.style.display = "block";
207
580
  const tag = currentElement.tagName.toLowerCase();
208
581
  let labelText = `<${tag}>`;
582
+ if (options.plainLabels) {
583
+ label.textContent = `${currentPlainLabel} \xB7 Click to select`;
584
+ placeLabel(rect);
585
+ return;
586
+ }
209
587
  if (currentCssClasses.length > 0) {
210
588
  const shown = currentCssClasses.slice(0, MAX_LABEL_CLASSES);
211
589
  labelText += ` .${shown.join(".")}${currentCssClasses.length > shown.length ? "\u2026" : ""}`;
@@ -217,6 +595,10 @@ function createOverlayRenderer() {
217
595
  labelText += ` \u2014 ${currentSourcePath}`;
218
596
  }
219
597
  label.textContent = labelText;
598
+ placeLabel(rect);
599
+ }
600
+ function placeLabel(rect) {
601
+ if (!label) return;
220
602
  const labelHeight = 20;
221
603
  const gap = 4;
222
604
  let labelTop = rect.top - labelHeight - gap;
@@ -249,6 +631,7 @@ function createOverlayRenderer() {
249
631
  ensureElements();
250
632
  currentElement = element;
251
633
  currentComponentName = componentName;
634
+ if (options.plainLabels) currentPlainLabel = describeElement(element);
252
635
  currentSourcePath = sourcePath ?? null;
253
636
  currentCssClasses = cssClasses ?? [];
254
637
  stopTracking();
@@ -648,360 +1031,112 @@ function showToast(message, opts = {}) {
648
1031
  void toast.offsetHeight;
649
1032
  toast.classList.add("grabby-toast-visible");
650
1033
  activeTimer = setTimeout(() => {
651
- toast.classList.remove("grabby-toast-visible");
652
- activeTimer = null;
653
- }, durationMs);
654
- }
655
- function hideToast() {
656
- if (activeTimer) {
657
- clearTimeout(activeTimer);
658
- activeTimer = null;
659
- }
660
- toastEl?.classList.remove("grabby-toast-visible");
661
- }
662
- function disposeToast() {
663
- if (activeTimer) {
664
- clearTimeout(activeTimer);
665
- activeTimer = null;
666
- }
667
- toastEl?.remove();
668
- toastEl = null;
669
- removeStyles(TOAST_STYLE_ID);
670
- }
671
-
672
- // src/core/utils.ts
673
- function filterAngularClasses(classList) {
674
- return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
675
- }
676
- function cssEscape(value) {
677
- if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
678
- let out = "";
679
- for (let i = 0; i < value.length; i++) {
680
- const ch = value.charAt(i);
681
- const code = value.charCodeAt(i);
682
- if (code === 0) {
683
- out += "\uFFFD";
684
- continue;
685
- }
686
- if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
687
- out += `\\${code.toString(16)} `;
688
- continue;
689
- }
690
- if (i === 0 && value.length === 1 && code === 45) {
691
- out += `\\${ch}`;
692
- continue;
693
- }
694
- if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
695
- out += ch;
696
- continue;
697
- }
698
- out += `\\${ch}`;
699
- }
700
- return out;
701
- }
702
- function safeQuery(selector, root2 = document) {
703
- if (!selector) return null;
704
- try {
705
- return root2.querySelector(selector);
706
- } catch {
707
- return null;
708
- }
709
- }
710
- var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
711
- var MAX_SELECTOR_DEPTH = 8;
712
- function isUnique(selector, el) {
713
- try {
714
- const matches = el.ownerDocument.querySelectorAll(selector);
715
- return matches.length === 1 && matches[0] === el;
716
- } catch {
717
- return false;
718
- }
719
- }
720
- function stepFor(el) {
721
- const tag = el.tagName.toLowerCase();
722
- const parent = el.parentElement;
723
- if (!parent) return tag;
724
- const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
725
- if (sameTag.length === 1) return tag;
726
- return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
727
- }
728
- function buildUniqueSelector(el) {
729
- for (const attr of TEST_ID_ATTRS) {
730
- const value = el.getAttribute(attr);
731
- if (value) {
732
- const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
733
- if (isUnique(sel, el)) return sel;
734
- }
735
- }
736
- if (el.id) {
737
- const sel = `#${cssEscape(el.id)}`;
738
- if (isUnique(sel, el)) return sel;
739
- }
740
- const steps = [];
741
- let current = el;
742
- while (current && steps.length < MAX_SELECTOR_DEPTH) {
743
- if (current !== el && current.id) {
744
- const anchor = `#${cssEscape(current.id)}`;
745
- if (isUnique(anchor, current)) {
746
- steps.unshift(anchor);
747
- break;
748
- }
749
- }
750
- steps.unshift(stepFor(current));
751
- const sel = steps.join(" > ");
752
- if (isUnique(sel, el)) return sel;
753
- if (current.tagName === "BODY" || current.tagName === "HTML") break;
754
- current = current.parentElement;
755
- }
756
- return steps.join(" > ");
757
- }
758
-
759
- // src/core/capture/kind.ts
760
- var ACTION_TAGS = /* @__PURE__ */ new Set(["BUTTON", "A", "SUMMARY"]);
761
- var ACTION_ROLES = /* @__PURE__ */ new Set(["button", "link", "tab", "menuitem", "menuitemcheckbox", "menuitemradio", "switch", "option", "checkbox", "radio"]);
762
- var BUTTON_INPUT_TYPES = /* @__PURE__ */ new Set(["button", "submit", "reset", "image"]);
763
- var FIELD_TAGS = /* @__PURE__ */ new Set(["INPUT", "SELECT", "TEXTAREA"]);
764
- var FIELD_ROLES = /* @__PURE__ */ new Set(["textbox", "combobox", "searchbox", "spinbutton", "slider"]);
765
- var MEDIA_TAGS = /* @__PURE__ */ new Set(["IMG", "SVG", "VIDEO", "PICTURE", "CANVAS", "IFRAME", "AUDIO"]);
766
- var TEXT_TAGS = /* @__PURE__ */ new Set([
767
- "H1",
768
- "H2",
769
- "H3",
770
- "H4",
771
- "H5",
772
- "H6",
773
- "P",
774
- "SPAN",
775
- "LABEL",
776
- "LI",
777
- "STRONG",
778
- "EM",
779
- "B",
780
- "I",
781
- "SMALL",
782
- "BLOCKQUOTE",
783
- "CODE",
784
- "PRE",
785
- "TD",
786
- "TH",
787
- "DT",
788
- "DD",
789
- "FIGCAPTION",
790
- "LEGEND",
791
- "CAPTION",
792
- "Q",
793
- "CITE",
794
- "MARK",
795
- "TIME"
796
- ]);
797
- var PAGE_TAGS = /* @__PURE__ */ new Set(["HTML", "BODY", "MAIN"]);
798
- var LANDMARK_TAGS = /* @__PURE__ */ new Set(["HEADER", "FOOTER", "NAV", "ASIDE"]);
799
- var SECTION_AREA_RATIO = 0.6;
800
- function role(el) {
801
- return (el.getAttribute("role") ?? "").toLowerCase();
802
- }
803
- function isAction(el) {
804
- if (ACTION_TAGS.has(el.tagName)) return el.tagName !== "A" || el.hasAttribute("href") || el.hasAttribute("role");
805
- if (el.tagName === "INPUT" && BUTTON_INPUT_TYPES.has(el.type)) return true;
806
- return ACTION_ROLES.has(role(el));
807
- }
808
- function isField(el) {
809
- if (el.tagName === "INPUT") return !BUTTON_INPUT_TYPES.has(el.type);
810
- if (FIELD_TAGS.has(el.tagName)) return true;
811
- if (el.isContentEditable && el.getAttribute("contenteditable") !== null) return true;
812
- return FIELD_ROLES.has(role(el));
813
- }
814
- function coversViewport(el) {
815
- const rect = el.getBoundingClientRect();
816
- const vw = window.innerWidth || document.documentElement.clientWidth;
817
- const vh = window.innerHeight || document.documentElement.clientHeight;
818
- if (!vw || !vh) return false;
819
- const w = Math.max(0, Math.min(rect.right, vw) - Math.max(rect.left, 0));
820
- const hgt = Math.max(0, Math.min(rect.bottom, vh) - Math.max(rect.top, 0));
821
- return w * hgt / (vw * vh) >= SECTION_AREA_RATIO;
822
- }
823
- function hasElementChildren(el) {
824
- return el.children.length > 0;
1034
+ toast.classList.remove("grabby-toast-visible");
1035
+ activeTimer = null;
1036
+ }, durationMs);
825
1037
  }
826
- function detectKind(el) {
827
- if (PAGE_TAGS.has(el.tagName)) return "section";
828
- if (MEDIA_TAGS.has(el.tagName)) return "media";
829
- if (isField(el)) return "field";
830
- if (isAction(el)) return "action";
831
- if (LANDMARK_TAGS.has(el.tagName) || role(el) === "main" || role(el) === "region") {
832
- return coversViewport(el) ? "section" : "container";
1038
+ function hideToast() {
1039
+ if (activeTimer) {
1040
+ clearTimeout(activeTimer);
1041
+ activeTimer = null;
833
1042
  }
834
- if (TEXT_TAGS.has(el.tagName)) return "text";
835
- if (!hasElementChildren(el) && (el.textContent ?? "").trim()) return "text";
836
- if (coversViewport(el)) return "section";
837
- return "container";
1043
+ toastEl?.classList.remove("grabby-toast-visible");
838
1044
  }
839
- var PROMOTE_DEPTH = 3;
840
- function promoteTarget(el) {
841
- if (isAction(el) || isField(el)) return el;
842
- let current = el.parentElement;
843
- for (let depth = 0; current && depth < PROMOTE_DEPTH; depth++) {
844
- if (isAction(current) || isField(current)) return current;
845
- if (PAGE_TAGS.has(current.tagName)) break;
846
- current = current.parentElement;
1045
+ function disposeToast() {
1046
+ if (activeTimer) {
1047
+ clearTimeout(activeTimer);
1048
+ activeTimer = null;
847
1049
  }
848
- return el;
1050
+ toastEl?.remove();
1051
+ toastEl = null;
1052
+ removeStyles(TOAST_STYLE_ID);
849
1053
  }
850
1054
 
851
- // src/core/capture/redact.ts
852
- var EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
853
- var JWT = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
854
- var BEARER = /\b(Bearer|Basic|Token)\s+[A-Za-z0-9._~+/=-]{8,}/gi;
855
- var LONG_NUMBER = /\b\d(?:[ -]?\d){8,}\b/g;
856
- var OPAQUE_TOKEN = /\b[A-Za-z0-9_-]{32,}\b/g;
857
- var SENSITIVE_PARAM = /([?&#](?:access_token|id_token|token|key|api_key|apikey|secret|password|pass|auth|code|session|sig|signature)=)[^&#\s]*/gi;
858
- function redact(text, options = {}) {
859
- if (!text) return text;
860
- const scrubbed = text.replace(SENSITIVE_PARAM, "$1[redacted]").replace(JWT, "[token]").replace(BEARER, "$1 [token]");
861
- 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);
1055
+ // src/core/utils.ts
1056
+ function filterAngularClasses(classList) {
1057
+ return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
862
1058
  }
863
- function sanitizeRoute(loc, keepParams = []) {
864
- let route = loc.pathname || "/";
865
- if (keepParams.length > 0 && loc.search) {
866
- const params = new URLSearchParams(loc.search);
867
- const kept = new URLSearchParams();
868
- for (const name of keepParams) {
869
- const value = params.get(name);
870
- if (value !== null) kept.set(name, value);
1059
+ function cssEscape(value) {
1060
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
1061
+ let out = "";
1062
+ for (let i = 0; i < value.length; i++) {
1063
+ const ch = value.charAt(i);
1064
+ const code = value.charCodeAt(i);
1065
+ if (code === 0) {
1066
+ out += "\uFFFD";
1067
+ continue;
871
1068
  }
872
- const qs = kept.toString();
873
- if (qs) route += `?${qs}`;
1069
+ if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
1070
+ out += `\\${code.toString(16)} `;
1071
+ continue;
1072
+ }
1073
+ if (i === 0 && value.length === 1 && code === 45) {
1074
+ out += `\\${ch}`;
1075
+ continue;
1076
+ }
1077
+ if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
1078
+ out += ch;
1079
+ continue;
1080
+ }
1081
+ out += `\\${ch}`;
874
1082
  }
875
- if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
876
- return redact(route);
1083
+ return out;
877
1084
  }
878
- function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
1085
+ function safeQuery(selector, root2 = document) {
1086
+ if (!selector) return null;
879
1087
  try {
880
- const url = new URL(raw, base);
881
- if (url.protocol === "javascript:" || url.protocol === "data:" || url.protocol === "vbscript:") return `${url.protocol}\u2026`;
882
- const baseUrl = new URL(base);
883
- const path = url.pathname + (url.hash.startsWith("#/") ? url.hash : "");
884
- return redact(url.origin === baseUrl.origin ? path : `${url.host}${path}`);
1088
+ return root2.querySelector(selector);
885
1089
  } catch {
886
- return redact(raw.split(/[?#]/)[0]);
887
- }
888
- }
889
-
890
- // src/core/capture/preview.ts
891
- var MASK_ATTR = "data-grabby-mask";
892
- var IGNORE_ATTR = "data-grabby-ignore";
893
- var PRIORITY_ATTRS = [
894
- "id",
895
- "class",
896
- "role",
897
- "aria-label",
898
- "data-testid",
899
- "data-test",
900
- "data-cy",
901
- "name",
902
- "type",
903
- "href",
904
- "src",
905
- "alt",
906
- "placeholder",
907
- "title",
908
- "for",
909
- "aria-expanded",
910
- "aria-selected",
911
- "disabled"
912
- ];
913
- var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src"]);
914
- var MAX_ATTRS = 8;
915
- var MAX_CLASS_CHARS = 60;
916
- var MAX_ATTR_CHARS = 80;
917
- var MAX_TEXT_CHARS = 80;
918
- var MAX_PREVIEW_CHARS = 300;
919
- function isNoiseAttr(name) {
920
- 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");
921
- }
922
- function isNoiseClass(name) {
923
- return name.startsWith("ng-") || name.startsWith("_ng") || /^svelte-[a-z0-9]+$/i.test(name) || /^s-[A-Za-z0-9_-]{8,}$/.test(name);
924
- }
925
- function truncate(text, max) {
926
- return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}\u2026`;
927
- }
928
- function isMasked(el) {
929
- return el.closest(`[${MASK_ATTR}]`) !== null;
930
- }
931
- function textOf(el, max) {
932
- if (isMasked(el)) return "[masked]";
933
- let raw = "";
934
- const walker = el.ownerDocument.createTreeWalker(el, NodeFilter.SHOW_TEXT);
935
- for (let node = walker.nextNode(); node; node = walker.nextNode()) {
936
- const parent = node.parentElement;
937
- if (parent && /^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE)$/.test(parent.tagName)) continue;
938
- if (parent?.closest(`[${IGNORE_ATTR}], [${MASK_ATTR}]`)) continue;
939
- raw += ` ${node.nodeValue ?? ""}`;
940
- if (raw.length > max * 3) break;
941
- }
942
- return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
943
- }
944
- function ownText(el) {
945
- let raw = "";
946
- for (const node of Array.from(el.childNodes)) {
947
- if (node.nodeType === Node.TEXT_NODE) raw += ` ${node.nodeValue ?? ""}`;
1090
+ return null;
948
1091
  }
949
- return raw.replace(/\s+/g, " ").trim();
950
1092
  }
951
- function attrValue(el, name, value, cleanClasses) {
952
- if (name === "class") {
953
- const classes = cleanClasses(value.split(/\s+/).filter(Boolean));
954
- if (classes.length === 0) return null;
955
- return truncate(classes.join(" "), MAX_CLASS_CHARS);
1093
+ var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
1094
+ var MAX_SELECTOR_DEPTH = 8;
1095
+ function isUnique(selector, el) {
1096
+ try {
1097
+ const matches = el.ownerDocument.querySelectorAll(selector);
1098
+ return matches.length === 1 && matches[0] === el;
1099
+ } catch {
1100
+ return false;
956
1101
  }
957
- if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
958
- return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
959
1102
  }
960
- function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
1103
+ function stepFor(el) {
961
1104
  const tag = el.tagName.toLowerCase();
962
- const attrs = [];
963
- const seen2 = /* @__PURE__ */ new Set();
964
- const add = (name) => {
965
- if (attrs.length >= MAX_ATTRS || seen2.has(name) || isNoiseAttr(name)) return;
966
- const raw = el.getAttribute(name);
967
- if (raw === null) return;
968
- seen2.add(name);
969
- if (raw === "") {
970
- attrs.push(name);
971
- return;
1105
+ const parent = el.parentElement;
1106
+ if (!parent) return tag;
1107
+ const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
1108
+ if (sameTag.length === 1) return tag;
1109
+ return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
1110
+ }
1111
+ function buildUniqueSelector(el) {
1112
+ for (const attr of TEST_ID_ATTRS) {
1113
+ const value = el.getAttribute(attr);
1114
+ if (value) {
1115
+ const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
1116
+ if (isUnique(sel, el)) return sel;
972
1117
  }
973
- const value = attrValue(el, name, raw, cleanClasses);
974
- if (value !== null) attrs.push(`${name}="${value.replace(/"/g, "&quot;")}"`);
975
- };
976
- for (const name of PRIORITY_ATTRS) add(name);
977
- for (const { name } of Array.from(el.attributes)) {
978
- if (name.startsWith("aria-")) add(name);
979
1118
  }
980
- return `<${tag}${attrs.length ? ` ${attrs.join(" ")}` : ""}>`;
981
- }
982
- function buildPreview(el, cleanClasses) {
983
- const tag = el.tagName.toLowerCase();
984
- const open = openingTag(el, cleanClasses);
985
- if (/^(img|input|br|hr|meta|link|source|area|col|embed|wbr)$/.test(tag)) {
986
- return truncate(open, MAX_PREVIEW_CHARS);
1119
+ if (el.id) {
1120
+ const sel = `#${cssEscape(el.id)}`;
1121
+ if (isUnique(sel, el)) return sel;
987
1122
  }
988
- const children = Array.from(el.children).filter((c) => !c.hasAttribute(IGNORE_ATTR));
989
- let inner;
990
- if (isMasked(el)) {
991
- inner = "[masked]";
992
- } else if (children.length === 0) {
993
- inner = truncate(redact(ownText(el)), MAX_TEXT_CHARS);
994
- } else if (children.length <= 2) {
995
- const text = truncate(redact(ownText(el)), 40);
996
- const kids = children.map((c) => {
997
- const t = textOf(c, 30);
998
- return `<${c.tagName.toLowerCase()}${t ? `>${t}</${c.tagName.toLowerCase()}>` : " \u2026>"}`;
999
- });
1000
- inner = [text, ...kids].filter(Boolean).join(" ");
1001
- } else {
1002
- inner = `(${children.length} elements)`;
1123
+ const steps = [];
1124
+ let current = el;
1125
+ while (current && steps.length < MAX_SELECTOR_DEPTH) {
1126
+ if (current !== el && current.id) {
1127
+ const anchor = `#${cssEscape(current.id)}`;
1128
+ if (isUnique(anchor, current)) {
1129
+ steps.unshift(anchor);
1130
+ break;
1131
+ }
1132
+ }
1133
+ steps.unshift(stepFor(current));
1134
+ const sel = steps.join(" > ");
1135
+ if (isUnique(sel, el)) return sel;
1136
+ if (current.tagName === "BODY" || current.tagName === "HTML") break;
1137
+ current = current.parentElement;
1003
1138
  }
1004
- return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
1139
+ return steps.join(" > ");
1005
1140
  }
1006
1141
 
1007
1142
  // src/core/picker/element-picker.ts
@@ -1131,6 +1266,7 @@ function matchesCombo(e, parsed) {
1131
1266
  function createKeyboardHandler(deps) {
1132
1267
  let holdTimer = null;
1133
1268
  let holdActivated = false;
1269
+ let togglePending = false;
1134
1270
  let listening = false;
1135
1271
  function handleKeyDown(e) {
1136
1272
  if (!deps.getEnableInInputs() && isEditableElement(eventTarget(e))) return;
@@ -1153,6 +1289,7 @@ function createKeyboardHandler(deps) {
1153
1289
  }
1154
1290
  } else {
1155
1291
  e.preventDefault();
1292
+ togglePending = true;
1156
1293
  }
1157
1294
  }
1158
1295
  function handleKeyUp(e) {
@@ -1169,6 +1306,8 @@ function createKeyboardHandler(deps) {
1169
1306
  deps.onDeactivate();
1170
1307
  }
1171
1308
  } else {
1309
+ if (!togglePending) return;
1310
+ togglePending = false;
1172
1311
  if (deps.isActive()) {
1173
1312
  deps.onDeactivate();
1174
1313
  } else {
@@ -1191,6 +1330,7 @@ function createKeyboardHandler(deps) {
1191
1330
  holdTimer = null;
1192
1331
  }
1193
1332
  holdActivated = false;
1333
+ togglePending = false;
1194
1334
  document.removeEventListener("keydown", handleKeyDown, true);
1195
1335
  document.removeEventListener("keyup", handleKeyUp, true);
1196
1336
  },
@@ -1991,16 +2131,18 @@ function createCommentsPanel(callbacks, options = {}) {
1991
2131
  }
1992
2132
  function row2(comment, showAuthors) {
1993
2133
  const t = comment.target;
1994
- const meta = [h("span", { class: "grabby-kind" }, t.kind)];
1995
- if (t.component) meta.push(document.createTextNode(`${t.component} `));
1996
- if (t.source) {
1997
- meta.push(h("a", {
1998
- href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
1999
- title: `Open ${t.source.file} in VS Code`,
2000
- onclick: (e) => e.stopPropagation()
2001
- }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2002
- } else if (!t.component) {
2003
- meta.push(document.createTextNode(`<${t.tag}>`));
2134
+ const meta = live ? [document.createTextNode(`${describeTarget(t)} `)] : [h("span", { class: "grabby-kind" }, t.kind)];
2135
+ if (!live) {
2136
+ if (t.component) meta.push(document.createTextNode(`${t.component} `));
2137
+ if (t.source) {
2138
+ meta.push(h("a", {
2139
+ href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
2140
+ title: `Open ${t.source.file} in VS Code`,
2141
+ onclick: (e) => e.stopPropagation()
2142
+ }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2143
+ } else if (!t.component) {
2144
+ meta.push(document.createTextNode(`<${t.tag}>`));
2145
+ }
2004
2146
  }
2005
2147
  const tail = [showAuthors && !live ? authorLabel(comment.author) : "", formatRelativeTime(comment.createdAt)].filter(Boolean);
2006
2148
  meta.push(document.createTextNode(` \xB7 ${tail.join(" \xB7 ")}`));
@@ -2873,7 +3015,7 @@ function loadJobs() {
2873
3015
  const raw = localStorage.getItem(STORE_KEY);
2874
3016
  const jobs = raw ? JSON.parse(raw) : [];
2875
3017
  if (!Array.isArray(jobs)) return [];
2876
- 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() });
3018
+ 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() });
2877
3019
  } catch {
2878
3020
  return [];
2879
3021
  }
@@ -2930,7 +3072,21 @@ function createOutbox(deps) {
2930
3072
  body
2931
3073
  });
2932
3074
  }
3075
+ function deleteComment(id, session2) {
3076
+ return fetch(`${base}/v1/comments/${encodeURIComponent(id)}`, {
3077
+ method: "DELETE",
3078
+ credentials: "omit",
3079
+ keepalive: true,
3080
+ headers: headers({ "X-Grabby-Session": session2 })
3081
+ });
3082
+ }
2933
3083
  async function deliver(job) {
3084
+ if (job.kind === "delete") {
3085
+ const res2 = await deleteComment(job.id, job.session);
3086
+ if (res2.ok || res2.status === 404) return "done";
3087
+ if (res2.status === 429 || res2.status >= 500) return "retry";
3088
+ return "drop";
3089
+ }
2934
3090
  const comment = deps.getComment(job.id);
2935
3091
  if (!comment) return "drop";
2936
3092
  if (job.kind === "comment") {
@@ -2995,6 +3151,19 @@ function createOutbox(deps) {
2995
3151
  if (jobs.length) schedule(500);
2996
3152
  return {
2997
3153
  send: (id) => add(id, "comment"),
3154
+ remove(id, sessionId, delayMs = 0) {
3155
+ jobs = jobs.filter((j) => j.id !== id);
3156
+ jobs.push({ id, kind: "delete", session: sessionId, attempts: 0, next: Date.now() + delayMs, created: Date.now() });
3157
+ save();
3158
+ schedule(0);
3159
+ },
3160
+ cancelRemove(id) {
3161
+ const job = jobs.find((j) => j.id === id && j.kind === "delete");
3162
+ if (!job) return false;
3163
+ jobs = jobs.filter((j) => j !== job);
3164
+ save();
3165
+ return job.attempts === 0;
3166
+ },
2998
3167
  sendScreenshot: (id) => {
2999
3168
  if (!jobs.some((j) => j.id === id && j.kind === "comment")) add(id, "shot");
3000
3169
  },
@@ -3002,11 +3171,18 @@ function createOutbox(deps) {
3002
3171
  flush: onOnline,
3003
3172
  flushOnExit() {
3004
3173
  for (const job of jobs) {
3174
+ if (job.kind === "delete") {
3175
+ job.attempts += 1;
3176
+ deleteComment(job.id, job.session).catch(() => {
3177
+ });
3178
+ continue;
3179
+ }
3005
3180
  if (job.kind !== "comment") continue;
3006
3181
  const comment = deps.getComment(job.id);
3007
3182
  if (comment) postComment(comment).catch(() => {
3008
3183
  });
3009
3184
  }
3185
+ save();
3010
3186
  },
3011
3187
  dispose() {
3012
3188
  disposed = true;
@@ -3629,13 +3805,13 @@ function childSummary(el, resolver) {
3629
3805
  if (counts.size > 6) parts.push("\u2026");
3630
3806
  return parts.join(", ");
3631
3807
  }
3632
- function firstHeading(el) {
3808
+ function firstHeading2(el) {
3633
3809
  const heading = el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
3634
3810
  return heading ? textOf(heading, 60) : "";
3635
3811
  }
3636
3812
  function containerFacts(el, resolver) {
3637
3813
  const f = {};
3638
- put(f, "heading", firstHeading(el));
3814
+ put(f, "heading", firstHeading2(el));
3639
3815
  put(f, "contains", childSummary(el, resolver));
3640
3816
  put(f, "size", size(el));
3641
3817
  put(f, "layout", formatStyles(customStyles(el, CONTAINER_STYLES)));
@@ -3646,7 +3822,7 @@ function sectionFacts(el, resolver) {
3646
3822
  put(f, "title", redact(el.ownerDocument.title));
3647
3823
  put(f, "viewport", `${window.innerWidth}\xD7${window.innerHeight}`);
3648
3824
  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) => {
3649
- const heading = firstHeading(r);
3825
+ const heading = firstHeading2(r);
3650
3826
  return heading ? `${r.tagName.toLowerCase()} "${truncate(heading, 30)}"` : r.tagName.toLowerCase();
3651
3827
  });
3652
3828
  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);