@githumbi/grabby 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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();
@@ -296,6 +679,7 @@ function createCrosshair() {
296
679
  let hLine = null;
297
680
  let vLine = null;
298
681
  let listening = false;
682
+ let held = false;
299
683
  function injectStyles2() {
300
684
  if (hasStyles(CROSSHAIR_STYLE_ID)) return;
301
685
  addStyles(CROSSHAIR_STYLE_ID, `
@@ -318,7 +702,7 @@ function createCrosshair() {
318
702
  width: 1px;
319
703
  }
320
704
  `);
321
- addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active { cursor: crosshair !important; }", "document");
705
+ addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active:not(.grabby-crosshair-held) { cursor: crosshair !important; }", "document");
322
706
  }
323
707
  function ensureElements() {
324
708
  if (!hLine) {
@@ -335,7 +719,12 @@ function createCrosshair() {
335
719
  getUiRoot().appendChild(vLine);
336
720
  }
337
721
  }
722
+ function hideLines() {
723
+ if (hLine) hLine.style.top = "-10px";
724
+ if (vLine) vLine.style.left = "-10px";
725
+ }
338
726
  function handleMouseMove(e) {
727
+ if (held) return;
339
728
  if (hLine) {
340
729
  hLine.style.top = `${e.clientY}px`;
341
730
  }
@@ -356,13 +745,19 @@ function createCrosshair() {
356
745
  listening = false;
357
746
  document.body.classList.remove("grabby-crosshair-active");
358
747
  document.removeEventListener("mousemove", handleMouseMove, true);
359
- if (hLine) hLine.style.top = "-10px";
360
- if (vLine) vLine.style.left = "-10px";
748
+ hideLines();
749
+ },
750
+ hold(on) {
751
+ if (held === on) return;
752
+ held = on;
753
+ document.body.classList.toggle("grabby-crosshair-held", on);
754
+ if (on) hideLines();
361
755
  },
362
756
  isCrosshairElement(el) {
363
757
  return el === hLine || el === vLine || el.id === H_LINE_ID || el.id === V_LINE_ID;
364
758
  },
365
759
  dispose() {
760
+ this.hold(false);
366
761
  this.deactivate();
367
762
  hLine?.remove();
368
763
  vLine?.remove();
@@ -654,365 +1049,118 @@ function showToast(message, opts = {}) {
654
1049
  void toast.offsetHeight;
655
1050
  toast.classList.add("grabby-toast-visible");
656
1051
  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;
831
- }
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";
839
- }
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";
844
- }
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;
853
- }
854
- return el;
855
- }
856
-
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);
868
- }
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);
877
- }
878
- const qs = kept.toString();
879
- if (qs) route += `?${qs}`;
1052
+ toast.classList.remove("grabby-toast-visible");
1053
+ activeTimer = null;
1054
+ }, durationMs);
1055
+ }
1056
+ function hideToast() {
1057
+ if (activeTimer) {
1058
+ clearTimeout(activeTimer);
1059
+ activeTimer = null;
880
1060
  }
881
- if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
882
- return redact(route);
1061
+ toastEl?.classList.remove("grabby-toast-visible");
883
1062
  }
884
- function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
885
- 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}`);
891
- } catch {
892
- return redact(raw.split(/[?#]/)[0]);
1063
+ function disposeToast() {
1064
+ if (activeTimer) {
1065
+ clearTimeout(activeTimer);
1066
+ activeTimer = null;
893
1067
  }
1068
+ toastEl?.remove();
1069
+ toastEl = null;
1070
+ removeStyles(TOAST_STYLE_ID);
894
1071
  }
895
1072
 
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;
1073
+ // src/core/utils.ts
1074
+ function filterAngularClasses(classList) {
1075
+ return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
936
1076
  }
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;
1077
+ function cssEscape(value) {
1078
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
1079
+ let out = "";
1080
+ for (let i = 0; i < value.length; i++) {
1081
+ const ch = value.charAt(i);
1082
+ const code = value.charCodeAt(i);
1083
+ if (code === 0) {
1084
+ out += "\uFFFD";
1085
+ continue;
1086
+ }
1087
+ if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
1088
+ out += `\\${code.toString(16)} `;
1089
+ continue;
1090
+ }
1091
+ if (i === 0 && value.length === 1 && code === 45) {
1092
+ out += `\\${ch}`;
1093
+ continue;
1094
+ }
1095
+ if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
1096
+ out += ch;
1097
+ continue;
1098
+ }
1099
+ out += `\\${ch}`;
947
1100
  }
948
- return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
1101
+ return out;
949
1102
  }
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 ?? ""}`;
1103
+ function safeQuery(selector, root2 = document) {
1104
+ if (!selector) return null;
1105
+ try {
1106
+ return root2.querySelector(selector);
1107
+ } catch {
1108
+ return null;
954
1109
  }
955
- return raw.replace(/\s+/g, " ").trim();
956
1110
  }
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);
1111
+ var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
1112
+ var MAX_SELECTOR_DEPTH = 8;
1113
+ function isUnique(selector, el) {
1114
+ try {
1115
+ const matches = el.ownerDocument.querySelectorAll(selector);
1116
+ return matches.length === 1 && matches[0] === el;
1117
+ } catch {
1118
+ return false;
962
1119
  }
963
- if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
964
- return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
965
1120
  }
966
- function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
1121
+ function stepFor(el) {
967
1122
  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;
1123
+ const parent = el.parentElement;
1124
+ if (!parent) return tag;
1125
+ const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
1126
+ if (sameTag.length === 1) return tag;
1127
+ return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
1128
+ }
1129
+ function buildUniqueSelector(el) {
1130
+ for (const attr of TEST_ID_ATTRS) {
1131
+ const value = el.getAttribute(attr);
1132
+ if (value) {
1133
+ const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
1134
+ if (isUnique(sel, el)) return sel;
978
1135
  }
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
1136
  }
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);
1137
+ if (el.id) {
1138
+ const sel = `#${cssEscape(el.id)}`;
1139
+ if (isUnique(sel, el)) return sel;
993
1140
  }
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)`;
1141
+ const steps = [];
1142
+ let current = el;
1143
+ while (current && steps.length < MAX_SELECTOR_DEPTH) {
1144
+ if (current !== el && current.id) {
1145
+ const anchor = `#${cssEscape(current.id)}`;
1146
+ if (isUnique(anchor, current)) {
1147
+ steps.unshift(anchor);
1148
+ break;
1149
+ }
1150
+ }
1151
+ steps.unshift(stepFor(current));
1152
+ const sel = steps.join(" > ");
1153
+ if (isUnique(sel, el)) return sel;
1154
+ if (current.tagName === "BODY" || current.tagName === "HTML") break;
1155
+ current = current.parentElement;
1009
1156
  }
1010
- return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
1157
+ return steps.join(" > ");
1011
1158
  }
1012
1159
 
1013
1160
  // src/core/picker/element-picker.ts
1014
1161
  function createElementPicker(deps) {
1015
1162
  let hoveredElement = null;
1163
+ let heldElement = null;
1016
1164
  let listening = false;
1017
1165
  function resolveComponentName(el) {
1018
1166
  const resolver = deps.getComponentResolver();
@@ -1043,17 +1191,21 @@ function createElementPicker(deps) {
1043
1191
  if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
1044
1192
  return exact ? raw : promoteTarget(raw);
1045
1193
  }
1194
+ function showOverlay(target) {
1195
+ const componentName = resolveComponentName(target);
1196
+ const sourcePath = resolveSourcePath(target);
1197
+ const cssClasses = filterAngularClasses(target.classList);
1198
+ deps.overlay.show(target, componentName, sourcePath, cssClasses);
1199
+ }
1046
1200
  function handleMouseMove(e) {
1201
+ if (heldElement) return;
1047
1202
  const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
1048
1203
  if (!target || deps.overlay.isOverlayElement(target)) return;
1049
1204
  if (deps.crosshair.isCrosshairElement(target)) return;
1050
1205
  if (deps.isToolbarElement?.(target)) return;
1051
1206
  if (target === hoveredElement) return;
1052
1207
  hoveredElement = target;
1053
- const componentName = resolveComponentName(target);
1054
- const sourcePath = resolveSourcePath(target);
1055
- const cssClasses = filterAngularClasses(target.classList);
1056
- deps.overlay.show(target, componentName, sourcePath, cssClasses);
1208
+ showOverlay(target);
1057
1209
  deps.onHover(target);
1058
1210
  }
1059
1211
  function handleClick(e) {
@@ -1063,6 +1215,7 @@ function createElementPicker(deps) {
1063
1215
  if (target && (deps.isToolbarElement?.(target) || deps.crosshair.isCrosshairElement(target))) return;
1064
1216
  e.preventDefault();
1065
1217
  e.stopPropagation();
1218
+ if (heldElement) return;
1066
1219
  if (hoveredElement) {
1067
1220
  deps.onSelect(hoveredElement);
1068
1221
  }
@@ -1079,12 +1232,29 @@ function createElementPicker(deps) {
1079
1232
  if (!listening) return;
1080
1233
  listening = false;
1081
1234
  hoveredElement = null;
1235
+ heldElement = null;
1236
+ deps.crosshair.hold(false);
1082
1237
  deps.crosshair.deactivate();
1083
1238
  document.removeEventListener("mousemove", handleMouseMove, true);
1084
1239
  document.removeEventListener("click", handleClick, true);
1085
1240
  deps.overlay.hide();
1086
1241
  deps.onHover(null);
1087
1242
  },
1243
+ hold(element) {
1244
+ if (!listening) return;
1245
+ heldElement = element;
1246
+ hoveredElement = element;
1247
+ deps.crosshair.hold(true);
1248
+ showOverlay(element);
1249
+ },
1250
+ release() {
1251
+ if (!heldElement) return;
1252
+ heldElement = null;
1253
+ deps.crosshair.hold(false);
1254
+ },
1255
+ isHolding() {
1256
+ return heldElement !== null;
1257
+ },
1088
1258
  getHoveredElement() {
1089
1259
  return hoveredElement;
1090
1260
  },
@@ -1137,6 +1307,7 @@ function matchesCombo(e, parsed) {
1137
1307
  function createKeyboardHandler(deps) {
1138
1308
  let holdTimer = null;
1139
1309
  let holdActivated = false;
1310
+ let togglePending = false;
1140
1311
  let listening = false;
1141
1312
  function handleKeyDown(e) {
1142
1313
  if (!deps.getEnableInInputs() && isEditableElement(eventTarget(e))) return;
@@ -1159,6 +1330,7 @@ function createKeyboardHandler(deps) {
1159
1330
  }
1160
1331
  } else {
1161
1332
  e.preventDefault();
1333
+ togglePending = true;
1162
1334
  }
1163
1335
  }
1164
1336
  function handleKeyUp(e) {
@@ -1175,6 +1347,8 @@ function createKeyboardHandler(deps) {
1175
1347
  deps.onDeactivate();
1176
1348
  }
1177
1349
  } else {
1350
+ if (!togglePending) return;
1351
+ togglePending = false;
1178
1352
  if (deps.isActive()) {
1179
1353
  deps.onDeactivate();
1180
1354
  } else {
@@ -1197,6 +1371,7 @@ function createKeyboardHandler(deps) {
1197
1371
  holdTimer = null;
1198
1372
  }
1199
1373
  holdActivated = false;
1374
+ togglePending = false;
1200
1375
  document.removeEventListener("keydown", handleKeyDown, true);
1201
1376
  document.removeEventListener("keyup", handleKeyUp, true);
1202
1377
  },
@@ -1412,6 +1587,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1412
1587
  let allElements = /* @__PURE__ */ new Set();
1413
1588
  let badge = null;
1414
1589
  let status = null;
1590
+ let expandBadge = null;
1591
+ let collapsed = false;
1415
1592
  function injectStyles2() {
1416
1593
  if (hasStyles(STYLE_ID3)) return;
1417
1594
  addStyles(STYLE_ID3, `
@@ -1527,6 +1704,24 @@ function createToolbarRenderer(callbacks, options = {}) {
1527
1704
  background: var(--grabby-accent-hover, #1d4ed8);
1528
1705
  color: #fff;
1529
1706
  }
1707
+ #${TOOLBAR_ID} button.grabby-btn-expand { display: none; }
1708
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed {
1709
+ left: auto;
1710
+ right: 20px;
1711
+ transform: none;
1712
+ padding: 4px;
1713
+ }
1714
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed.grabby-toolbar-hidden {
1715
+ transform: translateY(20px);
1716
+ }
1717
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > * { display: none !important; }
1718
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > button.grabby-btn-expand {
1719
+ display: flex !important;
1720
+ width: 40px;
1721
+ height: 40px;
1722
+ border-radius: 50%;
1723
+ color: var(--grabby-accent, #2563eb);
1724
+ }
1530
1725
  #${TOOLBAR_ID} .grabby-toolbar-left.grabby-toolbar-left-hidden {
1531
1726
  max-width: 0;
1532
1727
  opacity: 0;
@@ -1567,6 +1762,12 @@ function createToolbarRenderer(callbacks, options = {}) {
1567
1762
  buttons.history.appendChild(badge);
1568
1763
  buttons.enable = createButton("enable", ICON_POWER, "Enable/Disable", callbacks.onEnableToggle);
1569
1764
  buttons.dismiss = createButton("dismiss", ICON_DISMISS, options.dismissLabel ?? "Dismiss toolbar", callbacks.onDismiss);
1765
+ buttons.expand = createButton("expand", ICON_GRAB, options.expandLabel ?? "Open Grabby toolbar", () => callbacks.onExpand?.());
1766
+ buttons.expand.classList.add("grabby-btn-expand");
1767
+ expandBadge = document.createElement("span");
1768
+ expandBadge.className = "grabby-badge";
1769
+ expandBadge.hidden = true;
1770
+ buttons.expand.appendChild(expandBadge);
1570
1771
  const divider = document.createElement("span");
1571
1772
  divider.className = "grabby-toolbar-divider";
1572
1773
  leftGroup = document.createElement("div");
@@ -1597,6 +1798,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1597
1798
  }
1598
1799
  if (!options.hideEnable) container.appendChild(buttons.enable);
1599
1800
  container.appendChild(buttons.dismiss);
1801
+ container.appendChild(buttons.expand);
1802
+ container.classList.toggle("grabby-toolbar-collapsed", collapsed);
1600
1803
  getUiRoot().appendChild(container);
1601
1804
  allElements.clear();
1602
1805
  allElements.add(container);
@@ -1624,9 +1827,10 @@ function createToolbarRenderer(callbacks, options = {}) {
1624
1827
  buttons.selection.classList.remove("grabby-btn-active");
1625
1828
  }
1626
1829
  const count = state.toolbar.comments.length;
1627
- if (badge) {
1628
- badge.hidden = count === 0;
1629
- badge.textContent = count > 99 ? "99+" : String(count);
1830
+ for (const b of [badge, expandBadge]) {
1831
+ if (!b) continue;
1832
+ b.hidden = count === 0;
1833
+ b.textContent = count > 99 ? "99+" : String(count);
1630
1834
  }
1631
1835
  buttons.history.setAttribute("aria-label", count ? `Comments (${count})` : "Comments");
1632
1836
  if (status && buttons.finish) {
@@ -1644,6 +1848,17 @@ function createToolbarRenderer(callbacks, options = {}) {
1644
1848
  leftGroup?.classList.add("grabby-toolbar-left-hidden");
1645
1849
  }
1646
1850
  },
1851
+ collapse() {
1852
+ collapsed = true;
1853
+ container?.classList.add("grabby-toolbar-collapsed");
1854
+ },
1855
+ expand() {
1856
+ collapsed = false;
1857
+ container?.classList.remove("grabby-toolbar-collapsed");
1858
+ },
1859
+ isCollapsed() {
1860
+ return collapsed;
1861
+ },
1647
1862
  isToolbarElement(el) {
1648
1863
  if (allElements.has(el)) return true;
1649
1864
  let current = el;
@@ -1661,6 +1876,7 @@ function createToolbarRenderer(callbacks, options = {}) {
1661
1876
  leftGroup = null;
1662
1877
  buttons = {};
1663
1878
  badge = null;
1879
+ expandBadge = null;
1664
1880
  status = null;
1665
1881
  allElements.clear();
1666
1882
  }
@@ -1997,16 +2213,18 @@ function createCommentsPanel(callbacks, options = {}) {
1997
2213
  }
1998
2214
  function row2(comment, showAuthors) {
1999
2215
  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}>`));
2216
+ const meta = live ? [document.createTextNode(`${describeTarget(t)} `)] : [h("span", { class: "grabby-kind" }, t.kind)];
2217
+ if (!live) {
2218
+ if (t.component) meta.push(document.createTextNode(`${t.component} `));
2219
+ if (t.source) {
2220
+ meta.push(h("a", {
2221
+ href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
2222
+ title: `Open ${t.source.file} in VS Code`,
2223
+ onclick: (e) => e.stopPropagation()
2224
+ }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2225
+ } else if (!t.component) {
2226
+ meta.push(document.createTextNode(`<${t.tag}>`));
2227
+ }
2010
2228
  }
2011
2229
  const tail = [showAuthors && !live ? authorLabel(comment.author) : "", formatRelativeTime(comment.createdAt)].filter(Boolean);
2012
2230
  meta.push(document.createTextNode(` \xB7 ${tail.join(" \xB7 ")}`));
@@ -2879,7 +3097,7 @@ function loadJobs() {
2879
3097
  const raw = localStorage.getItem(STORE_KEY);
2880
3098
  const jobs = raw ? JSON.parse(raw) : [];
2881
3099
  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() });
3100
+ 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
3101
  } catch {
2884
3102
  return [];
2885
3103
  }
@@ -2936,7 +3154,21 @@ function createOutbox(deps) {
2936
3154
  body
2937
3155
  });
2938
3156
  }
3157
+ function deleteComment(id, session) {
3158
+ return fetch(`${base}/v1/comments/${encodeURIComponent(id)}`, {
3159
+ method: "DELETE",
3160
+ credentials: "omit",
3161
+ keepalive: true,
3162
+ headers: headers({ "X-Grabby-Session": session })
3163
+ });
3164
+ }
2939
3165
  async function deliver(job) {
3166
+ if (job.kind === "delete") {
3167
+ const res2 = await deleteComment(job.id, job.session);
3168
+ if (res2.ok || res2.status === 404) return "done";
3169
+ if (res2.status === 429 || res2.status >= 500) return "retry";
3170
+ return "drop";
3171
+ }
2940
3172
  const comment = deps.getComment(job.id);
2941
3173
  if (!comment) return "drop";
2942
3174
  if (job.kind === "comment") {
@@ -3001,6 +3233,19 @@ function createOutbox(deps) {
3001
3233
  if (jobs.length) schedule(500);
3002
3234
  return {
3003
3235
  send: (id) => add(id, "comment"),
3236
+ remove(id, sessionId, delayMs = 0) {
3237
+ jobs = jobs.filter((j) => j.id !== id);
3238
+ jobs.push({ id, kind: "delete", session: sessionId, attempts: 0, next: Date.now() + delayMs, created: Date.now() });
3239
+ save();
3240
+ schedule(0);
3241
+ },
3242
+ cancelRemove(id) {
3243
+ const job = jobs.find((j) => j.id === id && j.kind === "delete");
3244
+ if (!job) return false;
3245
+ jobs = jobs.filter((j) => j !== job);
3246
+ save();
3247
+ return job.attempts === 0;
3248
+ },
3004
3249
  sendScreenshot: (id) => {
3005
3250
  if (!jobs.some((j) => j.id === id && j.kind === "comment")) add(id, "shot");
3006
3251
  },
@@ -3008,11 +3253,18 @@ function createOutbox(deps) {
3008
3253
  flush: onOnline,
3009
3254
  flushOnExit() {
3010
3255
  for (const job of jobs) {
3256
+ if (job.kind === "delete") {
3257
+ job.attempts += 1;
3258
+ deleteComment(job.id, job.session).catch(() => {
3259
+ });
3260
+ continue;
3261
+ }
3011
3262
  if (job.kind !== "comment") continue;
3012
3263
  const comment = deps.getComment(job.id);
3013
3264
  if (comment) postComment(comment).catch(() => {
3014
3265
  });
3015
3266
  }
3267
+ save();
3016
3268
  },
3017
3269
  dispose() {
3018
3270
  disposed = true;
@@ -3596,13 +3848,13 @@ function childSummary(el, resolver) {
3596
3848
  if (counts.size > 6) parts.push("\u2026");
3597
3849
  return parts.join(", ");
3598
3850
  }
3599
- function firstHeading(el) {
3851
+ function firstHeading2(el) {
3600
3852
  const heading = el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
3601
3853
  return heading ? textOf(heading, 60) : "";
3602
3854
  }
3603
3855
  function containerFacts(el, resolver) {
3604
3856
  const f = {};
3605
- put(f, "heading", firstHeading(el));
3857
+ put(f, "heading", firstHeading2(el));
3606
3858
  put(f, "contains", childSummary(el, resolver));
3607
3859
  put(f, "size", size(el));
3608
3860
  put(f, "layout", formatStyles(customStyles(el, CONTAINER_STYLES)));
@@ -3613,7 +3865,7 @@ function sectionFacts(el, resolver) {
3613
3865
  put(f, "title", redact(el.ownerDocument.title));
3614
3866
  put(f, "viewport", `${window.innerWidth}\xD7${window.innerHeight}`);
3615
3867
  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);
3868
+ const heading = firstHeading2(r);
3617
3869
  return heading ? `${r.tagName.toLowerCase()} "${truncate(heading, 30)}"` : r.tagName.toLowerCase();
3618
3870
  });
3619
3871
  put(f, "regions", regions.join(", "));
@@ -4374,6 +4626,21 @@ function flushLeftovers(options) {
4374
4626
  }
4375
4627
  });
4376
4628
  }
4629
+ var COLLAPSED_KEY = "grabby:v1:collapsed";
4630
+ function loadCollapsed() {
4631
+ try {
4632
+ return sessionStorage.getItem(COLLAPSED_KEY) === "1";
4633
+ } catch {
4634
+ return false;
4635
+ }
4636
+ }
4637
+ function saveCollapsed(on) {
4638
+ try {
4639
+ if (on) sessionStorage.setItem(COLLAPSED_KEY, "1");
4640
+ else sessionStorage.removeItem(COLLAPSED_KEY);
4641
+ } catch {
4642
+ }
4643
+ }
4377
4644
  function isDevMode() {
4378
4645
  try {
4379
4646
  if (typeof ngDevMode !== "undefined" && ngDevMode === false) return false;
@@ -4442,7 +4709,7 @@ function createGrabInstance(options) {
4442
4709
  store.state.toolbar = { ...store.state.toolbar, comments: persisted };
4443
4710
  }
4444
4711
  }
4445
- const overlay = createOverlayRenderer();
4712
+ const overlay = createOverlayRenderer({ plainLabels: live });
4446
4713
  const crosshair = createCrosshair();
4447
4714
  const freezeOverlay = createFreezeOverlay();
4448
4715
  const pluginRegistry = createPluginRegistry();
@@ -4456,6 +4723,7 @@ function createGrabInstance(options) {
4456
4723
  let selectedElement = null;
4457
4724
  let pendingShot = null;
4458
4725
  let level = loadLevel(merged.detailLevel);
4726
+ let collapsed = loadCollapsed();
4459
4727
  const pendingShotDeletes = /* @__PURE__ */ new Map();
4460
4728
  themeManager.apply(store.state.toolbar.themeMode);
4461
4729
  updateToastOffset();
@@ -4570,12 +4838,15 @@ function createGrabInstance(options) {
4570
4838
  pluginRegistry.callHook("onScreenshot", updated, result.blob);
4571
4839
  outbox?.sendScreenshot(id);
4572
4840
  }
4573
- function removeComments(ids, message) {
4841
+ function removeComments(ids, message, withdraw = false) {
4574
4842
  if (ids.length === 0) return;
4575
4843
  const idSet = new Set(ids);
4576
4844
  const before = comments();
4577
4845
  const removed = before.filter((c) => idSet.has(c.id));
4578
4846
  setComments(before.filter((c) => !idSet.has(c.id)));
4847
+ const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
4848
+ const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
4849
+ for (const c of withdrawn) outbox.remove(c.id, c.author.sessionId, message ? UNDO_MS + 500 : 0);
4579
4850
  const shotIds = removed.flatMap((c) => c.screenshot?.localId ? [c.screenshot.localId] : []);
4580
4851
  const key = randomId();
4581
4852
  pendingShotDeletes.set(key, setTimeout(() => {
@@ -4591,8 +4862,11 @@ function createGrabInstance(options) {
4591
4862
  clearTimeout(pendingShotDeletes.get(key));
4592
4863
  pendingShotDeletes.delete(key);
4593
4864
  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);
4865
+ 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));
4866
+ const back = removed.filter((c) => !present.has(c.id)).map((c) => resend.has(c.id) ? { ...c, sync: "pending" } : c);
4867
+ const restored = [...back, ...comments()].sort((a, b) => b.createdAt - a.createdAt);
4595
4868
  setComments(restored);
4869
+ for (const id of resend) outbox?.send(id);
4596
4870
  showToast(`Restored ${removed.length} comment${removed.length === 1 ? "" : "s"}`);
4597
4871
  }
4598
4872
  }]
@@ -4623,9 +4897,17 @@ function createGrabInstance(options) {
4623
4897
  function isAnyToolbarElement(el) {
4624
4898
  return isUiNode(el) || freezeOverlay.isFreezeElement(el);
4625
4899
  }
4900
+ function hideCommentPopover() {
4901
+ commentPopover.hide();
4902
+ if (picker.isHolding()) {
4903
+ selectedElement = null;
4904
+ pendingShot = null;
4905
+ picker.release();
4906
+ }
4907
+ }
4626
4908
  function closeAllPopovers() {
4627
4909
  commentsPanel.hide();
4628
- commentPopover.hide();
4910
+ hideCommentPopover();
4629
4911
  copySheet.close();
4630
4912
  finishSheet.close();
4631
4913
  }
@@ -4665,6 +4947,7 @@ function createGrabInstance(options) {
4665
4947
  pluginRegistry.callHook("onElementSelect", element);
4666
4948
  coachMark.dismiss();
4667
4949
  showSelectFeedback(element);
4950
+ picker.hold(element);
4668
4951
  commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
4669
4952
  }
4670
4953
  });
@@ -4675,6 +4958,7 @@ function createGrabInstance(options) {
4675
4958
  store.state.toolbar = { ...store.state.toolbar, visible: true };
4676
4959
  toolbar.show();
4677
4960
  }
4961
+ if (collapsed) expandToolbar();
4678
4962
  closeAllPopovers();
4679
4963
  store.state.active = true;
4680
4964
  picker.activate();
@@ -4709,7 +4993,7 @@ function createGrabInstance(options) {
4709
4993
  }
4710
4994
  },
4711
4995
  onHistory() {
4712
- commentPopover.hide();
4996
+ hideCommentPopover();
4713
4997
  copySheet.close();
4714
4998
  if (commentsPanel.isVisible()) {
4715
4999
  commentsPanel.hide();
@@ -4726,16 +5010,28 @@ function createGrabInstance(options) {
4726
5010
  }
4727
5011
  toolbar.update(store.state);
4728
5012
  },
4729
- onDismiss() {
4730
- const { pending, failed } = reviewCounts();
4731
- if (live && outbox && (pending || failed)) {
4732
- openFinishSheet();
4733
- return;
4734
- }
4735
- exitFeedbackMode();
4736
- },
5013
+ // Close collapses the toolbar into a round button in the bottom-right
5014
+ // corner instead of removing it, so nothing is lost and it's one click
5015
+ // back. Comments keep sending while it's collapsed.
5016
+ onDismiss: collapseToolbar,
5017
+ onExpand: expandToolbar,
4737
5018
  onFinish: openFinishSheet
4738
- }, live ? { label: "Comment", dismissLabel: "Exit feedback mode", hideEnable: true, review: !!merged.server } : {});
5019
+ }, live ? { label: "Comment", dismissLabel: "Hide toolbar", expandLabel: "Leave feedback", hideEnable: true, review: !!merged.server } : { dismissLabel: "Hide toolbar", expandLabel: "Open Grabby toolbar" });
5020
+ function collapseToolbar() {
5021
+ closeAllPopovers();
5022
+ coachMark.dismiss();
5023
+ doDeactivate(true);
5024
+ collapsed = true;
5025
+ toolbar.collapse();
5026
+ saveCollapsed(true);
5027
+ updateToastOffset();
5028
+ }
5029
+ function expandToolbar() {
5030
+ collapsed = false;
5031
+ toolbar.expand();
5032
+ saveCollapsed(false);
5033
+ updateToastOffset();
5034
+ }
4739
5035
  const commentsPanel = createCommentsPanel({
4740
5036
  onHover(comment) {
4741
5037
  const el = comment ? safeQuery(comment.target.selector) : null;
@@ -4758,7 +5054,7 @@ function createGrabInstance(options) {
4758
5054
  },
4759
5055
  onDelete(comment) {
4760
5056
  overlay.hide();
4761
- removeComments([comment.id], "Comment deleted");
5057
+ removeComments([comment.id], "Comment deleted", true);
4762
5058
  },
4763
5059
  onCopyAll() {
4764
5060
  overlay.hide();
@@ -4767,7 +5063,7 @@ function createGrabInstance(options) {
4767
5063
  onClearAll() {
4768
5064
  overlay.hide();
4769
5065
  const n = comments().length;
4770
- removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`);
5066
+ removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`, true);
4771
5067
  commentsPanel.hide();
4772
5068
  },
4773
5069
  onChangeIdentity() {
@@ -4872,7 +5168,7 @@ function createGrabInstance(options) {
4872
5168
  }
4873
5169
  window.addEventListener("beforeunload", handleBeforeUnload);
4874
5170
  function updateToastOffset() {
4875
- if (store.state.toolbar.visible) {
5171
+ if (store.state.toolbar.visible && !collapsed) {
4876
5172
  document.documentElement.style.setProperty("--grabby-toast-bottom", TOOLBAR_TOAST_OFFSET);
4877
5173
  } else {
4878
5174
  document.documentElement.style.removeProperty("--grabby-toast-bottom");
@@ -4969,7 +5265,7 @@ function createGrabInstance(options) {
4969
5265
  return exportText(list, opts.level ?? level);
4970
5266
  },
4971
5267
  deleteComment(id) {
4972
- removeComments([id], null);
5268
+ removeComments([id], null, true);
4973
5269
  },
4974
5270
  clearComments() {
4975
5271
  removeComments(comments().map((c) => c.id), null);
@@ -5022,9 +5318,10 @@ function createGrabInstance(options) {
5022
5318
  keyboard.start();
5023
5319
  }
5024
5320
  store.state.toolbar = { ...store.state.toolbar, visible: false };
5321
+ if (collapsed) toolbar.collapse();
5025
5322
  if (live && merged.showToolbar) {
5026
5323
  api.showToolbar();
5027
- coachMark.maybeShow();
5324
+ if (!collapsed) coachMark.maybeShow();
5028
5325
  }
5029
5326
  store.subscribe((state, key) => {
5030
5327
  if (key === "options") {