@githumbi/grabby 0.4.0 → 0.5.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.
@@ -1211,7 +1211,7 @@ function createElementPicker(deps) {
1211
1211
  e.stopPropagation();
1212
1212
  if (heldElement) return;
1213
1213
  if (hoveredElement) {
1214
- deps.onSelect(hoveredElement);
1214
+ deps.onSelect(hoveredElement, { x: e.clientX, y: e.clientY });
1215
1215
  }
1216
1216
  }
1217
1217
  return {
@@ -1469,7 +1469,8 @@ function createWebhookPlugin(url) {
1469
1469
  type: "grabby.comment",
1470
1470
  version: 1,
1471
1471
  origin: typeof location !== "undefined" ? location.origin : null,
1472
- comment
1472
+ // The marker position is browser-only.
1473
+ comment: { ...comment, pin: void 0 }
1473
1474
  })
1474
1475
  }).catch(() => {
1475
1476
  });
@@ -1561,6 +1562,9 @@ ${vars.join("\n")}
1561
1562
 
1562
1563
  // src/core/toolbar/toolbar-renderer.ts
1563
1564
  var TOOLBAR_ID = "__grabby-toolbar__";
1565
+ var COLLAPSED_SIZE = 42;
1566
+ var EASE_OUT_EXPO = "cubic-bezier(0.19, 1, 0.22, 1)";
1567
+ var MORPH_MS = 360;
1564
1568
  var STYLE_ID3 = "__grabby-toolbar-styles__";
1565
1569
  function syncSummary(comments) {
1566
1570
  if (comments.length === 0) return null;
@@ -1582,7 +1586,13 @@ function createToolbarRenderer(callbacks, options = {}) {
1582
1586
  let badge = null;
1583
1587
  let status = null;
1584
1588
  let expandBadge = null;
1589
+ let content = null;
1585
1590
  let collapsed = false;
1591
+ let morphTimer = null;
1592
+ function clearMorph() {
1593
+ if (morphTimer) clearTimeout(morphTimer);
1594
+ morphTimer = null;
1595
+ }
1586
1596
  function injectStyles2() {
1587
1597
  if (hasStyles(STYLE_ID3)) return;
1588
1598
  addStyles(STYLE_ID3, `
@@ -1602,7 +1612,21 @@ function createToolbarRenderer(callbacks, options = {}) {
1602
1612
  box-shadow: 0 4px 16px var(--grabby-toolbar-shadow, rgba(0, 0, 0, 0.12));
1603
1613
  pointer-events: auto;
1604
1614
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
1605
- transition: opacity 0.2s ease, transform 0.2s ease;
1615
+ box-sizing: border-box;
1616
+ height: ${COLLAPSED_SIZE}px;
1617
+ overflow: hidden;
1618
+ justify-content: flex-end;
1619
+ transition: opacity 0.2s ease, transform 0.2s ease,
1620
+ left ${MORPH_MS}ms ${EASE_OUT_EXPO}, width ${MORPH_MS}ms ${EASE_OUT_EXPO};
1621
+ }
1622
+ #${TOOLBAR_ID} .grabby-toolbar-content {
1623
+ display: flex;
1624
+ align-items: center;
1625
+ gap: 2px;
1626
+ flex-shrink: 0;
1627
+ transform-origin: right center;
1628
+ transition: opacity 0.24s ease-out, filter 0.3s cubic-bezier(0.22, 1, 0.36, 1),
1629
+ transform 0.42s ${EASE_OUT_EXPO}, visibility 0s;
1606
1630
  }
1607
1631
  #${TOOLBAR_ID}.grabby-toolbar-hidden {
1608
1632
  opacity: 0;
@@ -1698,23 +1722,44 @@ function createToolbarRenderer(callbacks, options = {}) {
1698
1722
  background: var(--grabby-accent-hover, #1d4ed8);
1699
1723
  color: #fff;
1700
1724
  }
1701
- #${TOOLBAR_ID} button.grabby-btn-expand { display: none; }
1725
+ #${TOOLBAR_ID} button.grabby-btn-expand {
1726
+ position: absolute;
1727
+ left: 50%;
1728
+ top: 50%;
1729
+ translate: -50% -50%;
1730
+ color: var(--grabby-accent, #2563eb);
1731
+ opacity: 0;
1732
+ scale: 0.6;
1733
+ visibility: hidden;
1734
+ pointer-events: none;
1735
+ transition: opacity 0.2s ease-out, scale 0.3s ${EASE_OUT_EXPO}, visibility 0s 0.2s;
1736
+ }
1737
+ #${TOOLBAR_ID} button.grabby-btn-expand .grabby-badge { top: -3px; right: -5px; }
1702
1738
  #${TOOLBAR_ID}.grabby-toolbar-collapsed {
1703
- left: auto;
1704
- right: 20px;
1705
- transform: none;
1739
+ left: calc(100% - 20px - ${COLLAPSED_SIZE / 2}px);
1706
1740
  padding: 4px;
1707
1741
  }
1708
- #${TOOLBAR_ID}.grabby-toolbar-collapsed.grabby-toolbar-hidden {
1709
- transform: translateY(20px);
1742
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed .grabby-toolbar-content {
1743
+ opacity: 0;
1744
+ filter: blur(6px);
1745
+ transform: scale(0.4);
1746
+ pointer-events: none;
1747
+ visibility: hidden;
1748
+ transition: opacity 0.24s ease-out, filter 0.3s cubic-bezier(0.22, 1, 0.36, 1),
1749
+ transform 0.42s ${EASE_OUT_EXPO}, visibility 0s 0.3s;
1710
1750
  }
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);
1751
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed button.grabby-btn-expand {
1752
+ opacity: 1;
1753
+ scale: 1;
1754
+ visibility: visible;
1755
+ pointer-events: auto;
1756
+ transition: opacity 0.24s ease-out 0.08s, scale 0.36s ${EASE_OUT_EXPO} 0.08s, visibility 0s;
1757
+ }
1758
+ @media (prefers-reduced-motion: reduce) {
1759
+ #${TOOLBAR_ID}, #${TOOLBAR_ID} .grabby-toolbar-content, #${TOOLBAR_ID} button.grabby-btn-expand {
1760
+ transition-duration: 0s !important;
1761
+ transition-delay: 0s !important;
1762
+ }
1718
1763
  }
1719
1764
  #${TOOLBAR_ID} .grabby-toolbar-left.grabby-toolbar-left-hidden {
1720
1765
  max-width: 0;
@@ -1769,7 +1814,9 @@ function createToolbarRenderer(callbacks, options = {}) {
1769
1814
  leftGroup.appendChild(buttons.selection);
1770
1815
  leftGroup.appendChild(buttons.history);
1771
1816
  leftGroup.appendChild(divider);
1772
- container.appendChild(leftGroup);
1817
+ content = document.createElement("div");
1818
+ content.className = "grabby-toolbar-content";
1819
+ content.appendChild(leftGroup);
1773
1820
  if (options.review) {
1774
1821
  status = document.createElement("span");
1775
1822
  status.className = "grabby-toolbar-status";
@@ -1786,18 +1833,22 @@ function createToolbarRenderer(callbacks, options = {}) {
1786
1833
  e.stopPropagation();
1787
1834
  callbacks.onFinish?.();
1788
1835
  });
1789
- container.appendChild(status);
1790
- container.appendChild(buttons.finish);
1836
+ content.appendChild(status);
1837
+ content.appendChild(buttons.finish);
1791
1838
  allElements.add(status);
1792
1839
  }
1793
- if (!options.hideEnable) container.appendChild(buttons.enable);
1794
- container.appendChild(buttons.dismiss);
1795
- container.appendChild(buttons.expand);
1796
- container.classList.toggle("grabby-toolbar-collapsed", collapsed);
1840
+ if (!options.hideEnable) content.appendChild(buttons.enable);
1841
+ content.appendChild(buttons.dismiss);
1842
+ container.append(content, buttons.expand);
1843
+ if (collapsed) {
1844
+ container.classList.add("grabby-toolbar-collapsed");
1845
+ container.style.width = `${COLLAPSED_SIZE}px`;
1846
+ }
1797
1847
  getUiRoot().appendChild(container);
1798
1848
  allElements.clear();
1799
1849
  allElements.add(container);
1800
1850
  allElements.add(leftGroup);
1851
+ allElements.add(content);
1801
1852
  allElements.add(divider);
1802
1853
  for (const btn of Object.values(buttons)) {
1803
1854
  allElements.add(btn);
@@ -1843,12 +1894,28 @@ function createToolbarRenderer(callbacks, options = {}) {
1843
1894
  }
1844
1895
  },
1845
1896
  collapse() {
1897
+ if (collapsed) return;
1846
1898
  collapsed = true;
1847
- container?.classList.add("grabby-toolbar-collapsed");
1899
+ if (!container) return;
1900
+ clearMorph();
1901
+ container.style.width = `${container.offsetWidth}px`;
1902
+ void container.offsetWidth;
1903
+ container.classList.add("grabby-toolbar-collapsed");
1904
+ container.style.width = `${COLLAPSED_SIZE}px`;
1848
1905
  },
1849
1906
  expand() {
1907
+ if (!collapsed) return;
1850
1908
  collapsed = false;
1851
- container?.classList.remove("grabby-toolbar-collapsed");
1909
+ if (!container) return;
1910
+ clearMorph();
1911
+ container.classList.remove("grabby-toolbar-collapsed");
1912
+ const cs = getComputedStyle(container);
1913
+ const chrome = ["paddingLeft", "paddingRight", "borderLeftWidth", "borderRightWidth"].reduce((sum, k) => sum + (parseFloat(cs[k]) || 0), 0);
1914
+ container.style.width = `${(content?.offsetWidth ?? 0) + chrome}px`;
1915
+ morphTimer = setTimeout(() => {
1916
+ morphTimer = null;
1917
+ if (!collapsed && container) container.style.width = "";
1918
+ }, MORPH_MS + 40);
1852
1919
  },
1853
1920
  isCollapsed() {
1854
1921
  return collapsed;
@@ -1864,10 +1931,12 @@ function createToolbarRenderer(callbacks, options = {}) {
1864
1931
  return false;
1865
1932
  },
1866
1933
  dispose() {
1934
+ clearMorph();
1867
1935
  container?.remove();
1868
1936
  removeStyles(STYLE_ID3);
1869
1937
  container = null;
1870
1938
  leftGroup = null;
1939
+ content = null;
1871
1940
  buttons = {};
1872
1941
  badge = null;
1873
1942
  expandBadge = null;
@@ -2437,6 +2506,18 @@ function createCommentPopover(callbacks) {
2437
2506
  font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding: 8px 4px; border: none;
2438
2507
  background: transparent; color: var(--grabby-text-muted, #64748b); cursor: pointer; text-decoration: underline;
2439
2508
  }
2509
+ #${POPOVER_ID} .grabby-cp-edit-actions { display: flex; align-items: center; gap: 6px; }
2510
+ #${POPOVER_ID} .grabby-cp-edit-actions .grabby-cp-spacer { flex: 1; }
2511
+ #${POPOVER_ID} .grabby-cp-delete {
2512
+ font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding: 8px 6px; border: none;
2513
+ border-radius: 8px; background: transparent; color: #b91c1c; cursor: pointer;
2514
+ }
2515
+ #${POPOVER_ID} .grabby-cp-delete:hover { background: rgba(185, 28, 28, 0.08); }
2516
+ #${POPOVER_ID} .grabby-cp-cancel {
2517
+ font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding: 8px 10px; border: none;
2518
+ border-radius: 8px; background: transparent; color: var(--grabby-text-muted, #64748b); cursor: pointer;
2519
+ }
2520
+ #${POPOVER_ID} .grabby-cp-cancel:hover { background: var(--grabby-surface, #f1f5f9); }
2440
2521
  #${POPOVER_ID} .grabby-cp-hint {
2441
2522
  font-size: 11px;
2442
2523
  color: var(--grabby-text-muted, #94a3b8);
@@ -2498,6 +2579,37 @@ function createCommentPopover(callbacks) {
2498
2579
  function isEditable(el) {
2499
2580
  return !!el && el !== textarea && el !== nameInput && isEditableElement(el);
2500
2581
  }
2582
+ function save() {
2583
+ const v = textarea?.value.trim();
2584
+ if (!v) return;
2585
+ pendingValue = v;
2586
+ if (askIdentity) showIdentityStep();
2587
+ else finish();
2588
+ }
2589
+ function editActions() {
2590
+ const act = (fn) => (e) => {
2591
+ e.stopPropagation();
2592
+ fn();
2593
+ };
2594
+ const cancel = () => {
2595
+ const ctx = currentCtx;
2596
+ doHide();
2597
+ callbacks.onCancel(ctx);
2598
+ };
2599
+ const del = () => {
2600
+ const ctx = currentCtx;
2601
+ doHide();
2602
+ callbacks.onDelete?.(ctx);
2603
+ };
2604
+ return h(
2605
+ "div",
2606
+ { class: "grabby-cp-edit-actions" },
2607
+ callbacks.onDelete ? h("button", { type: "button", class: "grabby-cp-delete", "data-grabby-delete": "", onclick: act(del) }, "Delete") : null,
2608
+ h("span", { class: "grabby-cp-spacer" }),
2609
+ h("button", { type: "button", class: "grabby-cp-cancel", "data-grabby-cancel": "", onclick: act(cancel) }, "Cancel"),
2610
+ h("button", { type: "button", class: "grabby-cp-post", "data-grabby-save": "", onclick: act(save) }, "Save")
2611
+ );
2612
+ }
2501
2613
  function finish(identity) {
2502
2614
  const ctx = currentCtx;
2503
2615
  const value = pendingValue;
@@ -2563,11 +2675,7 @@ function createCommentPopover(callbacks) {
2563
2675
  e.stopImmediatePropagation();
2564
2676
  if (e.key === "Enter" && !e.shiftKey) {
2565
2677
  e.preventDefault();
2566
- const v = textarea.value.trim();
2567
- if (!v) return;
2568
- pendingValue = v;
2569
- if (askIdentity) showIdentityStep();
2570
- else finish();
2678
+ save();
2571
2679
  } else if (e.key === "Escape") {
2572
2680
  e.preventDefault();
2573
2681
  const ctx = currentCtx;
@@ -2601,6 +2709,7 @@ function createCommentPopover(callbacks) {
2601
2709
  currentCtx = { mode: opts.mode, entryId: opts.entryId };
2602
2710
  askIdentity = opts.askIdentity === true && opts.mode === "new";
2603
2711
  visible = true;
2712
+ if (opts.mode === "edit") el.appendChild(editActions());
2604
2713
  position(el, opts.anchor);
2605
2714
  attachKey();
2606
2715
  textarea?.focus();
@@ -3132,9 +3241,10 @@ function createOutbox(deps) {
3132
3241
  }, delay);
3133
3242
  }
3134
3243
  function wireShape(c) {
3135
- const { screenshot: _shot, sync: _sync, ...rest } = c;
3244
+ const { screenshot: _shot, sync: _sync, pin: _pin, ...rest } = c;
3136
3245
  void _shot;
3137
3246
  void _sync;
3247
+ void _pin;
3138
3248
  return rest;
3139
3249
  }
3140
3250
  function postComment(comment) {
@@ -3483,11 +3593,314 @@ function createFreezeOverlay() {
3483
3593
  };
3484
3594
  }
3485
3595
 
3596
+ // src/core/overlay/markers.ts
3597
+ var LAYER_ID = "__grabby-markers__";
3598
+ var TIP_ID = "__grabby-marker-tip__";
3599
+ var STYLE_ID9 = "__grabby-marker-styles__";
3600
+ var SIZE = 22;
3601
+ var ROUTE_CHECK_MS = 250;
3602
+ var LOOKUP_RETRY_MS = 500;
3603
+ var STAGGER_MS = 30;
3604
+ var TIP_MAX = 140;
3605
+ var ICON_EDIT = {
3606
+ size: 12,
3607
+ shapes: paths("M10.5 2.5l3 3L6 13H3v-3z", "M9 4l3 3")
3608
+ };
3609
+ function createMarkers(deps) {
3610
+ let layer = null;
3611
+ let tip = null;
3612
+ let visible = false;
3613
+ let route = "";
3614
+ let rafId = null;
3615
+ let lastRouteCheck = 0;
3616
+ let hovered = null;
3617
+ const entries = /* @__PURE__ */ new Map();
3618
+ function injectStyles2() {
3619
+ if (hasStyles(STYLE_ID9)) return;
3620
+ addStyles(STYLE_ID9, `
3621
+ #${LAYER_ID} {
3622
+ position: fixed;
3623
+ inset: 0;
3624
+ pointer-events: none;
3625
+ z-index: ${Z_INDEX_CROSSHAIR};
3626
+ }
3627
+ #${LAYER_ID} .grabby-marker {
3628
+ position: absolute;
3629
+ left: 0;
3630
+ top: 0;
3631
+ width: ${SIZE}px;
3632
+ height: ${SIZE}px;
3633
+ margin: 0;
3634
+ padding: 0;
3635
+ border: none;
3636
+ border-radius: 50%;
3637
+ background: var(--grabby-accent, #2563eb);
3638
+ color: #fff;
3639
+ box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0, 0, 0, 0.25);
3640
+ font: 600 11px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
3641
+ display: flex;
3642
+ align-items: center;
3643
+ justify-content: center;
3644
+ cursor: pointer;
3645
+ pointer-events: auto;
3646
+ transition: transform 0.12s ease, box-shadow 0.15s ease;
3647
+ }
3648
+ #${LAYER_ID} .grabby-marker[hidden] { display: none; }
3649
+ #${LAYER_ID} .grabby-marker:hover,
3650
+ #${LAYER_ID} .grabby-marker:focus-visible {
3651
+ z-index: 1;
3652
+ outline: none;
3653
+ box-shadow: 0 0 0 2px #fff, 0 0 0 5px color-mix(in srgb, var(--grabby-accent, #2563eb) 35%, transparent), 0 2px 6px rgba(0, 0, 0, 0.25);
3654
+ }
3655
+ #${LAYER_ID} .grabby-marker-edit { display: none; }
3656
+ #${LAYER_ID} .grabby-marker:hover .grabby-marker-num,
3657
+ #${LAYER_ID} .grabby-marker:focus-visible .grabby-marker-num { display: none; }
3658
+ #${LAYER_ID} .grabby-marker:hover .grabby-marker-edit,
3659
+ #${LAYER_ID} .grabby-marker:focus-visible .grabby-marker-edit { display: block; }
3660
+ #${LAYER_ID} .grabby-marker-in {
3661
+ animation: grabby-marker-in 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
3662
+ }
3663
+ #${LAYER_ID} .grabby-marker-out {
3664
+ animation: grabby-marker-out 0.2s ease-out both;
3665
+ pointer-events: none;
3666
+ }
3667
+ @keyframes grabby-marker-in {
3668
+ from { opacity: 0; scale: 0.3; }
3669
+ to { opacity: 1; scale: 1; }
3670
+ }
3671
+ @keyframes grabby-marker-out {
3672
+ from { opacity: 1; scale: 1; }
3673
+ to { opacity: 0; scale: 0.3; }
3674
+ }
3675
+ #${TIP_ID} {
3676
+ position: fixed;
3677
+ z-index: ${Z_INDEX_CROSSHAIR};
3678
+ max-width: 260px;
3679
+ padding: 8px 10px;
3680
+ border-radius: 10px;
3681
+ background: var(--grabby-label-bg, #1e293b);
3682
+ color: #fff;
3683
+ font: 12px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
3684
+ box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
3685
+ pointer-events: none;
3686
+ white-space: pre-wrap;
3687
+ overflow-wrap: anywhere;
3688
+ animation: grabby-marker-tip-in 0.12s ease both;
3689
+ }
3690
+ #${TIP_ID}[hidden] { display: none; }
3691
+ #${TIP_ID} .grabby-marker-tip-hint { display: block; margin-top: 4px; opacity: 0.6; font-size: 11px; }
3692
+ @keyframes grabby-marker-tip-in {
3693
+ from { opacity: 0; transform: translateY(-2px); }
3694
+ to { opacity: 1; transform: none; }
3695
+ }
3696
+ @media (prefers-reduced-motion: reduce) {
3697
+ #${LAYER_ID} .grabby-marker-in, #${LAYER_ID} .grabby-marker-out, #${TIP_ID} { animation: none; }
3698
+ }
3699
+ `);
3700
+ }
3701
+ function ensureLayer() {
3702
+ if (layer) return layer;
3703
+ injectStyles2();
3704
+ layer = document.createElement("div");
3705
+ layer.id = LAYER_ID;
3706
+ tip = document.createElement("div");
3707
+ tip.id = TIP_ID;
3708
+ tip.hidden = true;
3709
+ tip.setAttribute("role", "tooltip");
3710
+ getUiRoot().append(layer, tip);
3711
+ return layer;
3712
+ }
3713
+ function pageComments() {
3714
+ return deps.getComments().filter((c) => c.page.route === route).reverse();
3715
+ }
3716
+ function preview(text) {
3717
+ const flat = text.trim();
3718
+ return flat.length > TIP_MAX ? `${flat.slice(0, TIP_MAX - 1)}\u2026` : flat;
3719
+ }
3720
+ function createEntry(comment) {
3721
+ const number = document.createElement("span");
3722
+ number.className = "grabby-marker-num";
3723
+ const button = document.createElement("button");
3724
+ button.type = "button";
3725
+ button.className = "grabby-marker";
3726
+ button.dataset.grabbyMarker = comment.id;
3727
+ button.append(number, svgIcon(ICON_EDIT, "grabby-marker-edit"));
3728
+ const entry = { comment, button, number, element: null, lastLookup: 0 };
3729
+ button.addEventListener("click", (e) => {
3730
+ e.preventDefault();
3731
+ e.stopPropagation();
3732
+ hideTip();
3733
+ deps.onOpen(entry.comment, entry.element, button);
3734
+ });
3735
+ button.addEventListener("mouseenter", () => startHover(entry));
3736
+ button.addEventListener("focus", () => startHover(entry));
3737
+ button.addEventListener("mouseleave", () => endHover(entry));
3738
+ button.addEventListener("blur", () => endHover(entry));
3739
+ return entry;
3740
+ }
3741
+ function startHover(entry) {
3742
+ hovered = entry;
3743
+ showTip(entry);
3744
+ deps.onHover(entry.comment, entry.element);
3745
+ }
3746
+ function endHover(entry) {
3747
+ if (hovered !== entry) return;
3748
+ hovered = null;
3749
+ hideTip();
3750
+ deps.onHover(null, null);
3751
+ }
3752
+ function showTip(entry) {
3753
+ if (!tip) return;
3754
+ const hint = document.createElement("span");
3755
+ hint.className = "grabby-marker-tip-hint";
3756
+ hint.textContent = "Click to edit";
3757
+ tip.replaceChildren(document.createTextNode(preview(entry.comment.comment)), hint);
3758
+ tip.hidden = false;
3759
+ placeTip(entry);
3760
+ }
3761
+ function placeTip(entry) {
3762
+ if (!tip || tip.hidden) return;
3763
+ const m = entry.button.getBoundingClientRect();
3764
+ const t = tip.getBoundingClientRect();
3765
+ const left = Math.max(8, Math.min(m.left + m.width / 2 - t.width / 2, window.innerWidth - t.width - 8));
3766
+ const below = m.bottom + 8;
3767
+ const top = below + t.height > window.innerHeight - 8 ? m.top - 8 - t.height : below;
3768
+ tip.style.left = `${left}px`;
3769
+ tip.style.top = `${Math.max(8, top)}px`;
3770
+ }
3771
+ function hideTip() {
3772
+ if (tip) tip.hidden = true;
3773
+ }
3774
+ function animateIn(button, delay) {
3775
+ button.classList.remove("grabby-marker-out", "grabby-marker-in");
3776
+ button.style.animationDelay = `${delay}ms`;
3777
+ void button.offsetWidth;
3778
+ button.classList.add("grabby-marker-in");
3779
+ }
3780
+ function removeEntry(id, animate) {
3781
+ const entry = entries.get(id);
3782
+ if (!entry) return;
3783
+ entries.delete(id);
3784
+ if (hovered === entry) endHover(entry);
3785
+ if (!animate) {
3786
+ entry.button.remove();
3787
+ return;
3788
+ }
3789
+ entry.button.style.animationDelay = "0ms";
3790
+ entry.button.classList.remove("grabby-marker-in");
3791
+ entry.button.classList.add("grabby-marker-out");
3792
+ setTimeout(() => entry.button.remove(), 220);
3793
+ }
3794
+ function sync(fresh) {
3795
+ if (!visible) return;
3796
+ const host2 = ensureLayer();
3797
+ const list = pageComments();
3798
+ const ids = new Set(list.map((c) => c.id));
3799
+ for (const id of [...entries.keys()]) if (!ids.has(id)) removeEntry(id, !fresh);
3800
+ list.forEach((comment, i) => {
3801
+ let entry = entries.get(comment.id);
3802
+ const isNew = !entry;
3803
+ if (!entry) {
3804
+ entry = createEntry(comment);
3805
+ entries.set(comment.id, entry);
3806
+ host2.appendChild(entry.button);
3807
+ }
3808
+ entry.comment = comment;
3809
+ const n = String(i + 1);
3810
+ entry.number.textContent = n;
3811
+ entry.button.setAttribute("aria-label", `Comment ${n}: ${preview(comment.comment)}. Click to edit.`);
3812
+ if (fresh || isNew) animateIn(entry.button, fresh ? i * STAGGER_MS : 0);
3813
+ });
3814
+ if (hovered && entries.get(hovered.comment.id) === hovered) showTip(hovered);
3815
+ position(performance.now());
3816
+ schedule();
3817
+ }
3818
+ function position(now) {
3819
+ for (const entry of entries.values()) {
3820
+ if (!entry.element?.isConnected) {
3821
+ entry.element = null;
3822
+ if (now - entry.lastLookup >= LOOKUP_RETRY_MS) {
3823
+ entry.lastLookup = now;
3824
+ entry.element = deps.findElement(entry.comment);
3825
+ }
3826
+ }
3827
+ const rect = entry.element?.getBoundingClientRect();
3828
+ if (!rect || rect.width === 0 && rect.height === 0) {
3829
+ entry.button.hidden = true;
3830
+ continue;
3831
+ }
3832
+ const pin = entry.comment.pin ?? { x: 1, y: 0 };
3833
+ const x = rect.left + pin.x * rect.width - SIZE / 2;
3834
+ const y = rect.top + pin.y * rect.height - SIZE / 2;
3835
+ entry.button.hidden = false;
3836
+ entry.button.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
3837
+ }
3838
+ if (hovered) placeTip(hovered);
3839
+ }
3840
+ function frame() {
3841
+ rafId = null;
3842
+ const now = performance.now();
3843
+ if (!visible) return;
3844
+ if (now - lastRouteCheck >= ROUTE_CHECK_MS) {
3845
+ lastRouteCheck = now;
3846
+ const next = deps.currentRoute();
3847
+ if (next !== route) {
3848
+ route = next;
3849
+ for (const id of [...entries.keys()]) removeEntry(id, false);
3850
+ sync(true);
3851
+ return;
3852
+ }
3853
+ }
3854
+ position(now);
3855
+ schedule();
3856
+ }
3857
+ function schedule() {
3858
+ if (rafId === null && visible) rafId = requestAnimationFrame(frame);
3859
+ }
3860
+ function stop() {
3861
+ if (rafId !== null) cancelAnimationFrame(rafId);
3862
+ rafId = null;
3863
+ }
3864
+ return {
3865
+ setVisible(next) {
3866
+ if (next === visible) return;
3867
+ visible = next;
3868
+ if (next) {
3869
+ route = deps.currentRoute();
3870
+ lastRouteCheck = performance.now();
3871
+ sync(true);
3872
+ } else {
3873
+ stop();
3874
+ hideTip();
3875
+ if (hovered) endHover(hovered);
3876
+ for (const id of [...entries.keys()]) removeEntry(id, true);
3877
+ }
3878
+ },
3879
+ refresh() {
3880
+ sync(false);
3881
+ },
3882
+ isMarkerElement(el) {
3883
+ return !!layer && (layer === el || layer.contains(el));
3884
+ },
3885
+ dispose() {
3886
+ stop();
3887
+ entries.clear();
3888
+ layer?.remove();
3889
+ tip?.remove();
3890
+ layer = null;
3891
+ tip = null;
3892
+ hovered = null;
3893
+ visible = false;
3894
+ removeStyles(STYLE_ID9);
3895
+ }
3896
+ };
3897
+ }
3898
+
3486
3899
  // src/core/overlay/select-feedback.ts
3487
- var STYLE_ID9 = "__grabby-feedback-styles__";
3900
+ var STYLE_ID10 = "__grabby-feedback-styles__";
3488
3901
  function injectStyles() {
3489
- if (hasStyles(STYLE_ID9)) return;
3490
- addStyles(STYLE_ID9, `
3902
+ if (hasStyles(STYLE_ID10)) return;
3903
+ addStyles(STYLE_ID10, `
3491
3904
  @keyframes grabby-flash {
3492
3905
  0% { opacity: 1; }
3493
3906
  100% { opacity: 0; transform: scale(1.02); }
@@ -3566,7 +3979,7 @@ function showSelectFeedback(element, label = "Selected") {
3566
3979
  setTimeout(cleanup, 1200);
3567
3980
  }
3568
3981
  function disposeFeedbackStyles() {
3569
- removeStyles(STYLE_ID9);
3982
+ removeStyles(STYLE_ID10);
3570
3983
  }
3571
3984
 
3572
3985
  // src/core/storage/history-persistence.ts
@@ -4754,7 +5167,10 @@ function createGrabInstance(options) {
4754
5167
  let sourceResolver = adapters.resolveSource;
4755
5168
  const cleanClasses = (list) => adapters.cleanClasses(list.filter((c) => !isNoiseClass(c)));
4756
5169
  let selectedElement = null;
5170
+ let selectedPin;
4757
5171
  let pendingShot = null;
5172
+ const commentedElements = /* @__PURE__ */ new Map();
5173
+ let editingFromMarker = false;
4758
5174
  let level = loadLevel(merged.detailLevel);
4759
5175
  let collapsed = loadCollapsed();
4760
5176
  const pendingShotDeletes = /* @__PURE__ */ new Map();
@@ -4813,7 +5229,7 @@ function createGrabInstance(options) {
4813
5229
  column: c.target.source?.column ?? null
4814
5230
  };
4815
5231
  }
4816
- function saveComment(element, text, shot) {
5232
+ function saveComment(element, text, shot, pin) {
4817
5233
  const now = Date.now();
4818
5234
  const comment = {
4819
5235
  id: randomId(),
@@ -4830,8 +5246,10 @@ function createGrabInstance(options) {
4830
5246
  target: captureTarget(element, { componentResolver, sourceResolver, cleanClasses }),
4831
5247
  screenshot: null,
4832
5248
  framework: adapters.frameworkFor(element),
4833
- ...outbox ? { sync: "pending" } : {}
5249
+ ...outbox ? { sync: "pending" } : {},
5250
+ ...pin ? { pin } : {}
4834
5251
  };
5252
+ commentedElements.set(comment.id, element);
4835
5253
  setComments([comment, ...comments()].slice(0, MAX_COMMENTS));
4836
5254
  pluginRegistry.callHook("onComment", comment, element);
4837
5255
  outbox?.send(comment.id);
@@ -4876,6 +5294,7 @@ function createGrabInstance(options) {
4876
5294
  const idSet = new Set(ids);
4877
5295
  const before = comments();
4878
5296
  const removed = before.filter((c) => idSet.has(c.id));
5297
+ for (const id of ids) commentedElements.delete(id);
4879
5298
  setComments(before.filter((c) => !idSet.has(c.id)));
4880
5299
  const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
4881
5300
  const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
@@ -4932,12 +5351,19 @@ function createGrabInstance(options) {
4932
5351
  }
4933
5352
  function hideCommentPopover() {
4934
5353
  commentPopover.hide();
5354
+ endMarkerEdit();
4935
5355
  if (picker.isHolding()) {
4936
5356
  selectedElement = null;
5357
+ selectedPin = void 0;
4937
5358
  pendingShot = null;
4938
5359
  picker.release();
4939
5360
  }
4940
5361
  }
5362
+ function endMarkerEdit() {
5363
+ if (!editingFromMarker) return;
5364
+ editingFromMarker = false;
5365
+ overlay.hide();
5366
+ }
4941
5367
  function closeAllPopovers() {
4942
5368
  commentsPanel.hide();
4943
5369
  hideCommentPopover();
@@ -4974,8 +5400,14 @@ function createGrabInstance(options) {
4974
5400
  pluginRegistry.callHook("onElementHover", element);
4975
5401
  }
4976
5402
  },
4977
- onSelect(element) {
5403
+ onSelect(element, point) {
4978
5404
  selectedElement = element;
5405
+ const rect = element.getBoundingClientRect();
5406
+ const frac = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
5407
+ selectedPin = {
5408
+ x: Math.round(frac(point.x, rect.left, rect.width) * 1e3) / 1e3,
5409
+ y: Math.round(frac(point.y, rect.top, rect.height) * 1e3) / 1e3
5410
+ };
4979
5411
  pendingShot = store.state.options.screenshots ? captureScreenshot(element) : null;
4980
5412
  pluginRegistry.callHook("onElementSelect", element);
4981
5413
  coachMark.dismiss();
@@ -4984,6 +5416,36 @@ function createGrabInstance(options) {
4984
5416
  commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
4985
5417
  }
4986
5418
  });
5419
+ const markers = createMarkers({
5420
+ getComments: comments,
5421
+ currentRoute: () => sanitizeRoute(location, store.state.options.captureQueryParams),
5422
+ findElement(comment) {
5423
+ const known = commentedElements.get(comment.id);
5424
+ if (known?.isConnected) return known;
5425
+ return safeQuery(comment.target.selector);
5426
+ },
5427
+ onHover(comment, element) {
5428
+ if (picker.isHolding() || editingFromMarker || commentPopover.isVisible()) return;
5429
+ if (comment && element) overlay.show(element, comment.target.component, null, []);
5430
+ else overlay.hide();
5431
+ },
5432
+ onOpen(comment, element, marker) {
5433
+ if (picker.isHolding()) return;
5434
+ closeAllPopovers();
5435
+ doDeactivate(true);
5436
+ editingFromMarker = true;
5437
+ if (element) overlay.show(element, comment.target.component, null, []);
5438
+ commentPopover.show({
5439
+ anchor: element ?? marker,
5440
+ initialValue: comment.comment,
5441
+ mode: "edit",
5442
+ entryId: comment.id
5443
+ });
5444
+ }
5445
+ });
5446
+ function updateMarkers() {
5447
+ markers.setVisible(store.state.toolbar.visible && !collapsed && store.state.options.enabled);
5448
+ }
4987
5449
  function doActivate() {
4988
5450
  if (!store.state.options.enabled) return;
4989
5451
  if (store.state.active) return;
@@ -5058,12 +5520,14 @@ function createGrabInstance(options) {
5058
5520
  toolbar.collapse();
5059
5521
  saveCollapsed(true);
5060
5522
  updateToastOffset();
5523
+ updateMarkers();
5061
5524
  }
5062
5525
  function expandToolbar() {
5063
5526
  collapsed = false;
5064
5527
  toolbar.expand();
5065
5528
  saveCollapsed(false);
5066
5529
  updateToastOffset();
5530
+ updateMarkers();
5067
5531
  }
5068
5532
  const commentsPanel = createCommentsPanel({
5069
5533
  onHover(comment) {
@@ -5151,9 +5615,11 @@ function createGrabInstance(options) {
5151
5615
  if (ctx.mode === "new") {
5152
5616
  const element = selectedElement;
5153
5617
  const shot = pendingShot;
5618
+ const pin = selectedPin;
5154
5619
  selectedElement = null;
5620
+ selectedPin = void 0;
5155
5621
  pendingShot = null;
5156
- if (element) saveComment(element, value, shot);
5622
+ if (element) saveComment(element, value, shot, pin);
5157
5623
  doDeactivate(true);
5158
5624
  return;
5159
5625
  }
@@ -5164,16 +5630,23 @@ function createGrabInstance(options) {
5164
5630
  setComments(updated);
5165
5631
  outbox?.send(ctx.entryId);
5166
5632
  showToast("Comment updated");
5167
- commentsPanel.show([...updated]);
5633
+ if (editingFromMarker) endMarkerEdit();
5634
+ else commentsPanel.show([...updated]);
5168
5635
  },
5169
5636
  onCancel(ctx) {
5170
5637
  if (ctx.mode === "new") {
5171
5638
  selectedElement = null;
5639
+ selectedPin = void 0;
5172
5640
  pendingShot = null;
5173
5641
  doDeactivate(true);
5174
5642
  return;
5175
5643
  }
5176
- commentsPanel.show([...comments()]);
5644
+ if (editingFromMarker) endMarkerEdit();
5645
+ else commentsPanel.show([...comments()]);
5646
+ },
5647
+ onDelete(ctx) {
5648
+ endMarkerEdit();
5649
+ if (ctx.entryId) removeComments([ctx.entryId], "Comment deleted", true);
5177
5650
  }
5178
5651
  });
5179
5652
  function handleDocumentClick(e) {
@@ -5329,6 +5802,7 @@ function createGrabInstance(options) {
5329
5802
  overlay.dispose();
5330
5803
  crosshair.dispose();
5331
5804
  freezeOverlay.dispose();
5805
+ markers.dispose();
5332
5806
  disposeToast();
5333
5807
  disposeFeedbackStyles();
5334
5808
  pluginRegistry.dispose();
@@ -5365,8 +5839,11 @@ function createGrabInstance(options) {
5365
5839
  doDeactivate(true);
5366
5840
  }
5367
5841
  }
5842
+ if (key === "options") updateMarkers();
5368
5843
  if (key === "toolbar") {
5369
5844
  updateToastOffset();
5845
+ updateMarkers();
5846
+ markers.refresh();
5370
5847
  if (state.options.persistHistory) {
5371
5848
  if (state.toolbar.comments.length > 0) {
5372
5849
  saveHistory(state.toolbar.comments);
@@ -5388,6 +5865,7 @@ function createGrabInstance(options) {
5388
5865
  if (merged.webhookUrl) {
5389
5866
  api.registerPlugin(createWebhookPlugin(merged.webhookUrl));
5390
5867
  }
5868
+ updateMarkers();
5391
5869
  return api;
5392
5870
  }
5393
5871