@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.
@@ -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();
@@ -290,6 +673,7 @@ function createCrosshair() {
290
673
  let hLine = null;
291
674
  let vLine = null;
292
675
  let listening = false;
676
+ let held = false;
293
677
  function injectStyles2() {
294
678
  if (hasStyles(CROSSHAIR_STYLE_ID)) return;
295
679
  addStyles(CROSSHAIR_STYLE_ID, `
@@ -312,7 +696,7 @@ function createCrosshair() {
312
696
  width: 1px;
313
697
  }
314
698
  `);
315
- addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active { cursor: crosshair !important; }", "document");
699
+ addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active:not(.grabby-crosshair-held) { cursor: crosshair !important; }", "document");
316
700
  }
317
701
  function ensureElements() {
318
702
  if (!hLine) {
@@ -329,7 +713,12 @@ function createCrosshair() {
329
713
  getUiRoot().appendChild(vLine);
330
714
  }
331
715
  }
716
+ function hideLines() {
717
+ if (hLine) hLine.style.top = "-10px";
718
+ if (vLine) vLine.style.left = "-10px";
719
+ }
332
720
  function handleMouseMove(e) {
721
+ if (held) return;
333
722
  if (hLine) {
334
723
  hLine.style.top = `${e.clientY}px`;
335
724
  }
@@ -350,13 +739,19 @@ function createCrosshair() {
350
739
  listening = false;
351
740
  document.body.classList.remove("grabby-crosshair-active");
352
741
  document.removeEventListener("mousemove", handleMouseMove, true);
353
- if (hLine) hLine.style.top = "-10px";
354
- if (vLine) vLine.style.left = "-10px";
742
+ hideLines();
743
+ },
744
+ hold(on) {
745
+ if (held === on) return;
746
+ held = on;
747
+ document.body.classList.toggle("grabby-crosshair-held", on);
748
+ if (on) hideLines();
355
749
  },
356
750
  isCrosshairElement(el) {
357
751
  return el === hLine || el === vLine || el.id === H_LINE_ID || el.id === V_LINE_ID;
358
752
  },
359
753
  dispose() {
754
+ this.hold(false);
360
755
  this.deactivate();
361
756
  hLine?.remove();
362
757
  vLine?.remove();
@@ -648,365 +1043,118 @@ function showToast(message, opts = {}) {
648
1043
  void toast.offsetHeight;
649
1044
  toast.classList.add("grabby-toast-visible");
650
1045
  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;
825
- }
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";
833
- }
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";
838
- }
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;
847
- }
848
- return el;
849
- }
850
-
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);
862
- }
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);
871
- }
872
- const qs = kept.toString();
873
- if (qs) route += `?${qs}`;
1046
+ toast.classList.remove("grabby-toast-visible");
1047
+ activeTimer = null;
1048
+ }, durationMs);
1049
+ }
1050
+ function hideToast() {
1051
+ if (activeTimer) {
1052
+ clearTimeout(activeTimer);
1053
+ activeTimer = null;
874
1054
  }
875
- if (loc.hash.startsWith("#/")) route += loc.hash.split("?")[0];
876
- return redact(route);
1055
+ toastEl?.classList.remove("grabby-toast-visible");
877
1056
  }
878
- function sanitizeUrl(raw, base = typeof location !== "undefined" ? location.href : "http://localhost/") {
879
- 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}`);
885
- } catch {
886
- return redact(raw.split(/[?#]/)[0]);
1057
+ function disposeToast() {
1058
+ if (activeTimer) {
1059
+ clearTimeout(activeTimer);
1060
+ activeTimer = null;
887
1061
  }
1062
+ toastEl?.remove();
1063
+ toastEl = null;
1064
+ removeStyles(TOAST_STYLE_ID);
888
1065
  }
889
1066
 
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;
1067
+ // src/core/utils.ts
1068
+ function filterAngularClasses(classList) {
1069
+ return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
930
1070
  }
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;
1071
+ function cssEscape(value) {
1072
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
1073
+ let out = "";
1074
+ for (let i = 0; i < value.length; i++) {
1075
+ const ch = value.charAt(i);
1076
+ const code = value.charCodeAt(i);
1077
+ if (code === 0) {
1078
+ out += "\uFFFD";
1079
+ continue;
1080
+ }
1081
+ if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && value.charCodeAt(0) === 45) {
1082
+ out += `\\${code.toString(16)} `;
1083
+ continue;
1084
+ }
1085
+ if (i === 0 && value.length === 1 && code === 45) {
1086
+ out += `\\${ch}`;
1087
+ continue;
1088
+ }
1089
+ if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
1090
+ out += ch;
1091
+ continue;
1092
+ }
1093
+ out += `\\${ch}`;
941
1094
  }
942
- return truncate(redact(raw.replace(/\s+/g, " ").trim()), max);
1095
+ return out;
943
1096
  }
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 ?? ""}`;
1097
+ function safeQuery(selector, root2 = document) {
1098
+ if (!selector) return null;
1099
+ try {
1100
+ return root2.querySelector(selector);
1101
+ } catch {
1102
+ return null;
948
1103
  }
949
- return raw.replace(/\s+/g, " ").trim();
950
1104
  }
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);
1105
+ var TEST_ID_ATTRS = ["data-testid", "data-test", "data-cy", "data-qa"];
1106
+ var MAX_SELECTOR_DEPTH = 8;
1107
+ function isUnique(selector, el) {
1108
+ try {
1109
+ const matches = el.ownerDocument.querySelectorAll(selector);
1110
+ return matches.length === 1 && matches[0] === el;
1111
+ } catch {
1112
+ return false;
956
1113
  }
957
- if (URL_ATTRS.has(name)) return truncate(sanitizeUrl(value), 120);
958
- return truncate(redact(value, { keepEmails: name === "placeholder" }), MAX_ATTR_CHARS);
959
1114
  }
960
- function openingTag(el, cleanClasses = (l) => l.filter((c) => !isNoiseClass(c))) {
1115
+ function stepFor(el) {
961
1116
  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;
1117
+ const parent = el.parentElement;
1118
+ if (!parent) return tag;
1119
+ const sameTag = Array.from(parent.children).filter((c) => c.tagName === el.tagName);
1120
+ if (sameTag.length === 1) return tag;
1121
+ return `${tag}:nth-of-type(${sameTag.indexOf(el) + 1})`;
1122
+ }
1123
+ function buildUniqueSelector(el) {
1124
+ for (const attr of TEST_ID_ATTRS) {
1125
+ const value = el.getAttribute(attr);
1126
+ if (value) {
1127
+ const sel = `[${attr}="${value.replace(/["\\]/g, "\\$&")}"]`;
1128
+ if (isUnique(sel, el)) return sel;
972
1129
  }
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
1130
  }
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);
1131
+ if (el.id) {
1132
+ const sel = `#${cssEscape(el.id)}`;
1133
+ if (isUnique(sel, el)) return sel;
987
1134
  }
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)`;
1135
+ const steps = [];
1136
+ let current = el;
1137
+ while (current && steps.length < MAX_SELECTOR_DEPTH) {
1138
+ if (current !== el && current.id) {
1139
+ const anchor = `#${cssEscape(current.id)}`;
1140
+ if (isUnique(anchor, current)) {
1141
+ steps.unshift(anchor);
1142
+ break;
1143
+ }
1144
+ }
1145
+ steps.unshift(stepFor(current));
1146
+ const sel = steps.join(" > ");
1147
+ if (isUnique(sel, el)) return sel;
1148
+ if (current.tagName === "BODY" || current.tagName === "HTML") break;
1149
+ current = current.parentElement;
1003
1150
  }
1004
- return truncate(`${open}${inner}</${tag}>`, MAX_PREVIEW_CHARS);
1151
+ return steps.join(" > ");
1005
1152
  }
1006
1153
 
1007
1154
  // src/core/picker/element-picker.ts
1008
1155
  function createElementPicker(deps) {
1009
1156
  let hoveredElement = null;
1157
+ let heldElement = null;
1010
1158
  let listening = false;
1011
1159
  function resolveComponentName(el) {
1012
1160
  const resolver = deps.getComponentResolver();
@@ -1037,17 +1185,21 @@ function createElementPicker(deps) {
1037
1185
  if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
1038
1186
  return exact ? raw : promoteTarget(raw);
1039
1187
  }
1188
+ function showOverlay(target) {
1189
+ const componentName = resolveComponentName(target);
1190
+ const sourcePath = resolveSourcePath(target);
1191
+ const cssClasses = filterAngularClasses(target.classList);
1192
+ deps.overlay.show(target, componentName, sourcePath, cssClasses);
1193
+ }
1040
1194
  function handleMouseMove(e) {
1195
+ if (heldElement) return;
1041
1196
  const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
1042
1197
  if (!target || deps.overlay.isOverlayElement(target)) return;
1043
1198
  if (deps.crosshair.isCrosshairElement(target)) return;
1044
1199
  if (deps.isToolbarElement?.(target)) return;
1045
1200
  if (target === hoveredElement) return;
1046
1201
  hoveredElement = target;
1047
- const componentName = resolveComponentName(target);
1048
- const sourcePath = resolveSourcePath(target);
1049
- const cssClasses = filterAngularClasses(target.classList);
1050
- deps.overlay.show(target, componentName, sourcePath, cssClasses);
1202
+ showOverlay(target);
1051
1203
  deps.onHover(target);
1052
1204
  }
1053
1205
  function handleClick(e) {
@@ -1057,6 +1209,7 @@ function createElementPicker(deps) {
1057
1209
  if (target && (deps.isToolbarElement?.(target) || deps.crosshair.isCrosshairElement(target))) return;
1058
1210
  e.preventDefault();
1059
1211
  e.stopPropagation();
1212
+ if (heldElement) return;
1060
1213
  if (hoveredElement) {
1061
1214
  deps.onSelect(hoveredElement);
1062
1215
  }
@@ -1073,12 +1226,29 @@ function createElementPicker(deps) {
1073
1226
  if (!listening) return;
1074
1227
  listening = false;
1075
1228
  hoveredElement = null;
1229
+ heldElement = null;
1230
+ deps.crosshair.hold(false);
1076
1231
  deps.crosshair.deactivate();
1077
1232
  document.removeEventListener("mousemove", handleMouseMove, true);
1078
1233
  document.removeEventListener("click", handleClick, true);
1079
1234
  deps.overlay.hide();
1080
1235
  deps.onHover(null);
1081
1236
  },
1237
+ hold(element) {
1238
+ if (!listening) return;
1239
+ heldElement = element;
1240
+ hoveredElement = element;
1241
+ deps.crosshair.hold(true);
1242
+ showOverlay(element);
1243
+ },
1244
+ release() {
1245
+ if (!heldElement) return;
1246
+ heldElement = null;
1247
+ deps.crosshair.hold(false);
1248
+ },
1249
+ isHolding() {
1250
+ return heldElement !== null;
1251
+ },
1082
1252
  getHoveredElement() {
1083
1253
  return hoveredElement;
1084
1254
  },
@@ -1131,6 +1301,7 @@ function matchesCombo(e, parsed) {
1131
1301
  function createKeyboardHandler(deps) {
1132
1302
  let holdTimer = null;
1133
1303
  let holdActivated = false;
1304
+ let togglePending = false;
1134
1305
  let listening = false;
1135
1306
  function handleKeyDown(e) {
1136
1307
  if (!deps.getEnableInInputs() && isEditableElement(eventTarget(e))) return;
@@ -1153,6 +1324,7 @@ function createKeyboardHandler(deps) {
1153
1324
  }
1154
1325
  } else {
1155
1326
  e.preventDefault();
1327
+ togglePending = true;
1156
1328
  }
1157
1329
  }
1158
1330
  function handleKeyUp(e) {
@@ -1169,6 +1341,8 @@ function createKeyboardHandler(deps) {
1169
1341
  deps.onDeactivate();
1170
1342
  }
1171
1343
  } else {
1344
+ if (!togglePending) return;
1345
+ togglePending = false;
1172
1346
  if (deps.isActive()) {
1173
1347
  deps.onDeactivate();
1174
1348
  } else {
@@ -1191,6 +1365,7 @@ function createKeyboardHandler(deps) {
1191
1365
  holdTimer = null;
1192
1366
  }
1193
1367
  holdActivated = false;
1368
+ togglePending = false;
1194
1369
  document.removeEventListener("keydown", handleKeyDown, true);
1195
1370
  document.removeEventListener("keyup", handleKeyUp, true);
1196
1371
  },
@@ -1406,6 +1581,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1406
1581
  let allElements = /* @__PURE__ */ new Set();
1407
1582
  let badge = null;
1408
1583
  let status = null;
1584
+ let expandBadge = null;
1585
+ let collapsed = false;
1409
1586
  function injectStyles2() {
1410
1587
  if (hasStyles(STYLE_ID3)) return;
1411
1588
  addStyles(STYLE_ID3, `
@@ -1521,6 +1698,24 @@ function createToolbarRenderer(callbacks, options = {}) {
1521
1698
  background: var(--grabby-accent-hover, #1d4ed8);
1522
1699
  color: #fff;
1523
1700
  }
1701
+ #${TOOLBAR_ID} button.grabby-btn-expand { display: none; }
1702
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed {
1703
+ left: auto;
1704
+ right: 20px;
1705
+ transform: none;
1706
+ padding: 4px;
1707
+ }
1708
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed.grabby-toolbar-hidden {
1709
+ transform: translateY(20px);
1710
+ }
1711
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > * { display: none !important; }
1712
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > button.grabby-btn-expand {
1713
+ display: flex !important;
1714
+ width: 40px;
1715
+ height: 40px;
1716
+ border-radius: 50%;
1717
+ color: var(--grabby-accent, #2563eb);
1718
+ }
1524
1719
  #${TOOLBAR_ID} .grabby-toolbar-left.grabby-toolbar-left-hidden {
1525
1720
  max-width: 0;
1526
1721
  opacity: 0;
@@ -1561,6 +1756,12 @@ function createToolbarRenderer(callbacks, options = {}) {
1561
1756
  buttons.history.appendChild(badge);
1562
1757
  buttons.enable = createButton("enable", ICON_POWER, "Enable/Disable", callbacks.onEnableToggle);
1563
1758
  buttons.dismiss = createButton("dismiss", ICON_DISMISS, options.dismissLabel ?? "Dismiss toolbar", callbacks.onDismiss);
1759
+ buttons.expand = createButton("expand", ICON_GRAB, options.expandLabel ?? "Open Grabby toolbar", () => callbacks.onExpand?.());
1760
+ buttons.expand.classList.add("grabby-btn-expand");
1761
+ expandBadge = document.createElement("span");
1762
+ expandBadge.className = "grabby-badge";
1763
+ expandBadge.hidden = true;
1764
+ buttons.expand.appendChild(expandBadge);
1564
1765
  const divider = document.createElement("span");
1565
1766
  divider.className = "grabby-toolbar-divider";
1566
1767
  leftGroup = document.createElement("div");
@@ -1591,6 +1792,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1591
1792
  }
1592
1793
  if (!options.hideEnable) container.appendChild(buttons.enable);
1593
1794
  container.appendChild(buttons.dismiss);
1795
+ container.appendChild(buttons.expand);
1796
+ container.classList.toggle("grabby-toolbar-collapsed", collapsed);
1594
1797
  getUiRoot().appendChild(container);
1595
1798
  allElements.clear();
1596
1799
  allElements.add(container);
@@ -1618,9 +1821,10 @@ function createToolbarRenderer(callbacks, options = {}) {
1618
1821
  buttons.selection.classList.remove("grabby-btn-active");
1619
1822
  }
1620
1823
  const count = state.toolbar.comments.length;
1621
- if (badge) {
1622
- badge.hidden = count === 0;
1623
- badge.textContent = count > 99 ? "99+" : String(count);
1824
+ for (const b of [badge, expandBadge]) {
1825
+ if (!b) continue;
1826
+ b.hidden = count === 0;
1827
+ b.textContent = count > 99 ? "99+" : String(count);
1624
1828
  }
1625
1829
  buttons.history.setAttribute("aria-label", count ? `Comments (${count})` : "Comments");
1626
1830
  if (status && buttons.finish) {
@@ -1638,6 +1842,17 @@ function createToolbarRenderer(callbacks, options = {}) {
1638
1842
  leftGroup?.classList.add("grabby-toolbar-left-hidden");
1639
1843
  }
1640
1844
  },
1845
+ collapse() {
1846
+ collapsed = true;
1847
+ container?.classList.add("grabby-toolbar-collapsed");
1848
+ },
1849
+ expand() {
1850
+ collapsed = false;
1851
+ container?.classList.remove("grabby-toolbar-collapsed");
1852
+ },
1853
+ isCollapsed() {
1854
+ return collapsed;
1855
+ },
1641
1856
  isToolbarElement(el) {
1642
1857
  if (allElements.has(el)) return true;
1643
1858
  let current = el;
@@ -1655,6 +1870,7 @@ function createToolbarRenderer(callbacks, options = {}) {
1655
1870
  leftGroup = null;
1656
1871
  buttons = {};
1657
1872
  badge = null;
1873
+ expandBadge = null;
1658
1874
  status = null;
1659
1875
  allElements.clear();
1660
1876
  }
@@ -1991,16 +2207,18 @@ function createCommentsPanel(callbacks, options = {}) {
1991
2207
  }
1992
2208
  function row2(comment, showAuthors) {
1993
2209
  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}>`));
2210
+ const meta = live ? [document.createTextNode(`${describeTarget(t)} `)] : [h("span", { class: "grabby-kind" }, t.kind)];
2211
+ if (!live) {
2212
+ if (t.component) meta.push(document.createTextNode(`${t.component} `));
2213
+ if (t.source) {
2214
+ meta.push(h("a", {
2215
+ href: vsCodeUri2(t.source.file, t.source.line, t.source.column),
2216
+ title: `Open ${t.source.file} in VS Code`,
2217
+ onclick: (e) => e.stopPropagation()
2218
+ }, `${basename2(t.source.file)}${t.source.line != null ? `:${t.source.line}` : ""}`));
2219
+ } else if (!t.component) {
2220
+ meta.push(document.createTextNode(`<${t.tag}>`));
2221
+ }
2004
2222
  }
2005
2223
  const tail = [showAuthors && !live ? authorLabel(comment.author) : "", formatRelativeTime(comment.createdAt)].filter(Boolean);
2006
2224
  meta.push(document.createTextNode(` \xB7 ${tail.join(" \xB7 ")}`));
@@ -2873,7 +3091,7 @@ function loadJobs() {
2873
3091
  const raw = localStorage.getItem(STORE_KEY);
2874
3092
  const jobs = raw ? JSON.parse(raw) : [];
2875
3093
  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() });
3094
+ 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
3095
  } catch {
2878
3096
  return [];
2879
3097
  }
@@ -2930,7 +3148,21 @@ function createOutbox(deps) {
2930
3148
  body
2931
3149
  });
2932
3150
  }
3151
+ function deleteComment(id, session2) {
3152
+ return fetch(`${base}/v1/comments/${encodeURIComponent(id)}`, {
3153
+ method: "DELETE",
3154
+ credentials: "omit",
3155
+ keepalive: true,
3156
+ headers: headers({ "X-Grabby-Session": session2 })
3157
+ });
3158
+ }
2933
3159
  async function deliver(job) {
3160
+ if (job.kind === "delete") {
3161
+ const res2 = await deleteComment(job.id, job.session);
3162
+ if (res2.ok || res2.status === 404) return "done";
3163
+ if (res2.status === 429 || res2.status >= 500) return "retry";
3164
+ return "drop";
3165
+ }
2934
3166
  const comment = deps.getComment(job.id);
2935
3167
  if (!comment) return "drop";
2936
3168
  if (job.kind === "comment") {
@@ -2995,6 +3227,19 @@ function createOutbox(deps) {
2995
3227
  if (jobs.length) schedule(500);
2996
3228
  return {
2997
3229
  send: (id) => add(id, "comment"),
3230
+ remove(id, sessionId, delayMs = 0) {
3231
+ jobs = jobs.filter((j) => j.id !== id);
3232
+ jobs.push({ id, kind: "delete", session: sessionId, attempts: 0, next: Date.now() + delayMs, created: Date.now() });
3233
+ save();
3234
+ schedule(0);
3235
+ },
3236
+ cancelRemove(id) {
3237
+ const job = jobs.find((j) => j.id === id && j.kind === "delete");
3238
+ if (!job) return false;
3239
+ jobs = jobs.filter((j) => j !== job);
3240
+ save();
3241
+ return job.attempts === 0;
3242
+ },
2998
3243
  sendScreenshot: (id) => {
2999
3244
  if (!jobs.some((j) => j.id === id && j.kind === "comment")) add(id, "shot");
3000
3245
  },
@@ -3002,11 +3247,18 @@ function createOutbox(deps) {
3002
3247
  flush: onOnline,
3003
3248
  flushOnExit() {
3004
3249
  for (const job of jobs) {
3250
+ if (job.kind === "delete") {
3251
+ job.attempts += 1;
3252
+ deleteComment(job.id, job.session).catch(() => {
3253
+ });
3254
+ continue;
3255
+ }
3005
3256
  if (job.kind !== "comment") continue;
3006
3257
  const comment = deps.getComment(job.id);
3007
3258
  if (comment) postComment(comment).catch(() => {
3008
3259
  });
3009
3260
  }
3261
+ save();
3010
3262
  },
3011
3263
  dispose() {
3012
3264
  disposed = true;
@@ -3629,13 +3881,13 @@ function childSummary(el, resolver) {
3629
3881
  if (counts.size > 6) parts.push("\u2026");
3630
3882
  return parts.join(", ");
3631
3883
  }
3632
- function firstHeading(el) {
3884
+ function firstHeading2(el) {
3633
3885
  const heading = el.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
3634
3886
  return heading ? textOf(heading, 60) : "";
3635
3887
  }
3636
3888
  function containerFacts(el, resolver) {
3637
3889
  const f = {};
3638
- put(f, "heading", firstHeading(el));
3890
+ put(f, "heading", firstHeading2(el));
3639
3891
  put(f, "contains", childSummary(el, resolver));
3640
3892
  put(f, "size", size(el));
3641
3893
  put(f, "layout", formatStyles(customStyles(el, CONTAINER_STYLES)));
@@ -3646,7 +3898,7 @@ function sectionFacts(el, resolver) {
3646
3898
  put(f, "title", redact(el.ownerDocument.title));
3647
3899
  put(f, "viewport", `${window.innerWidth}\xD7${window.innerHeight}`);
3648
3900
  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);
3901
+ const heading = firstHeading2(r);
3650
3902
  return heading ? `${r.tagName.toLowerCase()} "${truncate(heading, 30)}"` : r.tagName.toLowerCase();
3651
3903
  });
3652
3904
  put(f, "regions", regions.join(", "));
@@ -4407,6 +4659,21 @@ function flushLeftovers(options) {
4407
4659
  }
4408
4660
  });
4409
4661
  }
4662
+ var COLLAPSED_KEY = "grabby:v1:collapsed";
4663
+ function loadCollapsed() {
4664
+ try {
4665
+ return sessionStorage.getItem(COLLAPSED_KEY) === "1";
4666
+ } catch {
4667
+ return false;
4668
+ }
4669
+ }
4670
+ function saveCollapsed(on) {
4671
+ try {
4672
+ if (on) sessionStorage.setItem(COLLAPSED_KEY, "1");
4673
+ else sessionStorage.removeItem(COLLAPSED_KEY);
4674
+ } catch {
4675
+ }
4676
+ }
4410
4677
  function isDevMode() {
4411
4678
  try {
4412
4679
  if (typeof ngDevMode !== "undefined" && ngDevMode === false) return false;
@@ -4475,7 +4742,7 @@ function createGrabInstance(options) {
4475
4742
  store.state.toolbar = { ...store.state.toolbar, comments: persisted };
4476
4743
  }
4477
4744
  }
4478
- const overlay = createOverlayRenderer();
4745
+ const overlay = createOverlayRenderer({ plainLabels: live });
4479
4746
  const crosshair = createCrosshair();
4480
4747
  const freezeOverlay = createFreezeOverlay();
4481
4748
  const pluginRegistry = createPluginRegistry();
@@ -4489,6 +4756,7 @@ function createGrabInstance(options) {
4489
4756
  let selectedElement = null;
4490
4757
  let pendingShot = null;
4491
4758
  let level = loadLevel(merged.detailLevel);
4759
+ let collapsed = loadCollapsed();
4492
4760
  const pendingShotDeletes = /* @__PURE__ */ new Map();
4493
4761
  themeManager.apply(store.state.toolbar.themeMode);
4494
4762
  updateToastOffset();
@@ -4603,12 +4871,15 @@ function createGrabInstance(options) {
4603
4871
  pluginRegistry.callHook("onScreenshot", updated, result.blob);
4604
4872
  outbox?.sendScreenshot(id);
4605
4873
  }
4606
- function removeComments(ids, message) {
4874
+ function removeComments(ids, message, withdraw = false) {
4607
4875
  if (ids.length === 0) return;
4608
4876
  const idSet = new Set(ids);
4609
4877
  const before = comments();
4610
4878
  const removed = before.filter((c) => idSet.has(c.id));
4611
4879
  setComments(before.filter((c) => !idSet.has(c.id)));
4880
+ const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
4881
+ const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
4882
+ for (const c of withdrawn) outbox.remove(c.id, c.author.sessionId, message ? UNDO_MS + 500 : 0);
4612
4883
  const shotIds = removed.flatMap((c) => c.screenshot?.localId ? [c.screenshot.localId] : []);
4613
4884
  const key = randomId();
4614
4885
  pendingShotDeletes.set(key, setTimeout(() => {
@@ -4624,8 +4895,11 @@ function createGrabInstance(options) {
4624
4895
  clearTimeout(pendingShotDeletes.get(key));
4625
4896
  pendingShotDeletes.delete(key);
4626
4897
  const present = new Set(comments().map((c) => c.id));
4627
- const restored = [...removed.filter((c) => !present.has(c.id)), ...comments()].sort((a, b) => b.createdAt - a.createdAt);
4898
+ const resend = new Set(withdrawn.filter((c) => !present.has(c.id) && (!outbox.cancelRemove(c.id) || c.sync !== "sent" || hadQueued.has(c.id))).map((c) => c.id));
4899
+ const back = removed.filter((c) => !present.has(c.id)).map((c) => resend.has(c.id) ? { ...c, sync: "pending" } : c);
4900
+ const restored = [...back, ...comments()].sort((a, b) => b.createdAt - a.createdAt);
4628
4901
  setComments(restored);
4902
+ for (const id of resend) outbox?.send(id);
4629
4903
  showToast(`Restored ${removed.length} comment${removed.length === 1 ? "" : "s"}`);
4630
4904
  }
4631
4905
  }]
@@ -4656,9 +4930,17 @@ function createGrabInstance(options) {
4656
4930
  function isAnyToolbarElement(el) {
4657
4931
  return isUiNode(el) || freezeOverlay.isFreezeElement(el);
4658
4932
  }
4933
+ function hideCommentPopover() {
4934
+ commentPopover.hide();
4935
+ if (picker.isHolding()) {
4936
+ selectedElement = null;
4937
+ pendingShot = null;
4938
+ picker.release();
4939
+ }
4940
+ }
4659
4941
  function closeAllPopovers() {
4660
4942
  commentsPanel.hide();
4661
- commentPopover.hide();
4943
+ hideCommentPopover();
4662
4944
  copySheet.close();
4663
4945
  finishSheet.close();
4664
4946
  }
@@ -4698,6 +4980,7 @@ function createGrabInstance(options) {
4698
4980
  pluginRegistry.callHook("onElementSelect", element);
4699
4981
  coachMark.dismiss();
4700
4982
  showSelectFeedback(element);
4983
+ picker.hold(element);
4701
4984
  commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
4702
4985
  }
4703
4986
  });
@@ -4708,6 +4991,7 @@ function createGrabInstance(options) {
4708
4991
  store.state.toolbar = { ...store.state.toolbar, visible: true };
4709
4992
  toolbar.show();
4710
4993
  }
4994
+ if (collapsed) expandToolbar();
4711
4995
  closeAllPopovers();
4712
4996
  store.state.active = true;
4713
4997
  picker.activate();
@@ -4742,7 +5026,7 @@ function createGrabInstance(options) {
4742
5026
  }
4743
5027
  },
4744
5028
  onHistory() {
4745
- commentPopover.hide();
5029
+ hideCommentPopover();
4746
5030
  copySheet.close();
4747
5031
  if (commentsPanel.isVisible()) {
4748
5032
  commentsPanel.hide();
@@ -4759,16 +5043,28 @@ function createGrabInstance(options) {
4759
5043
  }
4760
5044
  toolbar.update(store.state);
4761
5045
  },
4762
- onDismiss() {
4763
- const { pending, failed } = reviewCounts();
4764
- if (live && outbox && (pending || failed)) {
4765
- openFinishSheet();
4766
- return;
4767
- }
4768
- exitFeedbackMode();
4769
- },
5046
+ // Close collapses the toolbar into a round button in the bottom-right
5047
+ // corner instead of removing it, so nothing is lost and it's one click
5048
+ // back. Comments keep sending while it's collapsed.
5049
+ onDismiss: collapseToolbar,
5050
+ onExpand: expandToolbar,
4770
5051
  onFinish: openFinishSheet
4771
- }, live ? { label: "Comment", dismissLabel: "Exit feedback mode", hideEnable: true, review: !!merged.server } : {});
5052
+ }, live ? { label: "Comment", dismissLabel: "Hide toolbar", expandLabel: "Leave feedback", hideEnable: true, review: !!merged.server } : { dismissLabel: "Hide toolbar", expandLabel: "Open Grabby toolbar" });
5053
+ function collapseToolbar() {
5054
+ closeAllPopovers();
5055
+ coachMark.dismiss();
5056
+ doDeactivate(true);
5057
+ collapsed = true;
5058
+ toolbar.collapse();
5059
+ saveCollapsed(true);
5060
+ updateToastOffset();
5061
+ }
5062
+ function expandToolbar() {
5063
+ collapsed = false;
5064
+ toolbar.expand();
5065
+ saveCollapsed(false);
5066
+ updateToastOffset();
5067
+ }
4772
5068
  const commentsPanel = createCommentsPanel({
4773
5069
  onHover(comment) {
4774
5070
  const el = comment ? safeQuery(comment.target.selector) : null;
@@ -4791,7 +5087,7 @@ function createGrabInstance(options) {
4791
5087
  },
4792
5088
  onDelete(comment) {
4793
5089
  overlay.hide();
4794
- removeComments([comment.id], "Comment deleted");
5090
+ removeComments([comment.id], "Comment deleted", true);
4795
5091
  },
4796
5092
  onCopyAll() {
4797
5093
  overlay.hide();
@@ -4800,7 +5096,7 @@ function createGrabInstance(options) {
4800
5096
  onClearAll() {
4801
5097
  overlay.hide();
4802
5098
  const n = comments().length;
4803
- removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`);
5099
+ removeComments(comments().map((c) => c.id), `Cleared ${n} comment${n === 1 ? "" : "s"}`, true);
4804
5100
  commentsPanel.hide();
4805
5101
  },
4806
5102
  onChangeIdentity() {
@@ -4905,7 +5201,7 @@ function createGrabInstance(options) {
4905
5201
  }
4906
5202
  window.addEventListener("beforeunload", handleBeforeUnload);
4907
5203
  function updateToastOffset() {
4908
- if (store.state.toolbar.visible) {
5204
+ if (store.state.toolbar.visible && !collapsed) {
4909
5205
  document.documentElement.style.setProperty("--grabby-toast-bottom", TOOLBAR_TOAST_OFFSET);
4910
5206
  } else {
4911
5207
  document.documentElement.style.removeProperty("--grabby-toast-bottom");
@@ -5002,7 +5298,7 @@ function createGrabInstance(options) {
5002
5298
  return exportText(list, opts.level ?? level);
5003
5299
  },
5004
5300
  deleteComment(id) {
5005
- removeComments([id], null);
5301
+ removeComments([id], null, true);
5006
5302
  },
5007
5303
  clearComments() {
5008
5304
  removeComments(comments().map((c) => c.id), null);
@@ -5055,9 +5351,10 @@ function createGrabInstance(options) {
5055
5351
  keyboard.start();
5056
5352
  }
5057
5353
  store.state.toolbar = { ...store.state.toolbar, visible: false };
5354
+ if (collapsed) toolbar.collapse();
5058
5355
  if (live && merged.showToolbar) {
5059
5356
  api.showToolbar();
5060
- coachMark.maybeShow();
5357
+ if (!collapsed) coachMark.maybeShow();
5061
5358
  }
5062
5359
  store.subscribe((state, key) => {
5063
5360
  if (key === "options") {