glitchgrab 1.61.0 → 1.61.2

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.
package/dist/index.js CHANGED
@@ -72,6 +72,61 @@ __export(index_exports, {
72
72
  });
73
73
  module.exports = __toCommonJS(index_exports);
74
74
 
75
+ // src/origin.ts
76
+ var EXTENSION_RE = /\b(?:chrome|safari|moz|edge)-extension:\/\//;
77
+ var FRAME_RE = /^\s*at\s+(?:.*?\s+\()?(.+?):(\d+):(\d+)\)?\s*$/;
78
+ var MAX_FRAMES = 10;
79
+ function sameOriginAs(file, pageOrigin) {
80
+ if (file.startsWith("/")) return true;
81
+ try {
82
+ return new URL(file).origin === pageOrigin;
83
+ } catch (e) {
84
+ return false;
85
+ }
86
+ }
87
+ function parseFrames(stack, pageOrigin) {
88
+ if (!stack) return [];
89
+ const frames = [];
90
+ for (const raw of stack.split("\n")) {
91
+ const m = FRAME_RE.exec(raw);
92
+ if (!m) continue;
93
+ const file = m[1].replace(/^eval at .*?, /, "");
94
+ frames.push({
95
+ file,
96
+ line: Number(m[2]),
97
+ column: Number(m[3]),
98
+ sameOrigin: sameOriginAs(file, pageOrigin)
99
+ });
100
+ if (frames.length >= MAX_FRAMES) break;
101
+ }
102
+ return frames;
103
+ }
104
+ function classifyOrigin(stack, filename, pageOrigin) {
105
+ var _a, _b, _c;
106
+ const frames = parseFrames(stack, pageOrigin);
107
+ const top = (_c = (_b = (_a = frames[0]) == null ? void 0 : _a.file) != null ? _b : filename) != null ? _c : "";
108
+ const hasExtensionFrame = EXTENSION_RE.test(stack != null ? stack : "") || EXTENSION_RE.test(filename != null ? filename : "");
109
+ let origin;
110
+ if (hasExtensionFrame) origin = "extension";
111
+ else if (!top) origin = "unknown";
112
+ else if (top === "<anonymous>" || /\beval\b/.test(top)) origin = "eval";
113
+ else if (/^(?:blob|data):/.test(top)) origin = "injected";
114
+ else if (!sameOriginAs(top, pageOrigin)) origin = "injected";
115
+ else origin = "app";
116
+ return { origin, frames };
117
+ }
118
+ function originMetadata(stack, filename) {
119
+ try {
120
+ const { origin, frames } = classifyOrigin(stack, filename, window.location.origin);
121
+ return {
122
+ codeOrigin: origin,
123
+ ...frames.length ? { frames: JSON.stringify(frames) } : {}
124
+ };
125
+ } catch (e) {
126
+ return {};
127
+ }
128
+ }
129
+
75
130
  // src/provider.tsx
76
131
  var import_react6 = require("react");
77
132
 
@@ -1312,6 +1367,7 @@ function buildCapturedErrorPayload(error, options, cfg, capturedBy = "captureErr
1312
1367
  ...contextMetadata(context),
1313
1368
  ...(options == null ? void 0 : options.boundary) ? { boundary: options.boundary } : {},
1314
1369
  ...digest ? { digest } : {},
1370
+ ...originMetadata(err == null ? void 0 : err.stack),
1315
1371
  ...sessionMetadata(cfg.session),
1316
1372
  ...options == null ? void 0 : options.metadata
1317
1373
  }
@@ -1473,24 +1529,102 @@ async function encodeImageFile(file, maxLength = MAX_SCREENSHOT_DATA_URL_LENGTH)
1473
1529
  }
1474
1530
  return readAsDataUrl(file);
1475
1531
  }
1476
- var PALETTE = ["#ef4444", "#f59e0b", "#22c55e", "#3b82f6", "#a855f7", "#ffffff"];
1532
+ var PALETTE = ["#ef4444", "#facc15", "#22c55e", "#3b82f6", "#a855f7", "#ffffff"];
1533
+ var TOOL_DEFAULTS = {
1534
+ pen: { color: PALETTE[0], width: 4 },
1535
+ highlighter: { color: "#facc15", width: 22 },
1536
+ rect: { color: PALETTE[0], width: 4 },
1537
+ circle: { color: PALETTE[0], width: 4 },
1538
+ arrow: { color: PALETTE[0], width: 4 }
1539
+ };
1540
+ var WIDTH_RANGE = {
1541
+ pen: { min: 2, max: 12 },
1542
+ highlighter: { min: 10, max: 40 },
1543
+ rect: { min: 2, max: 12 },
1544
+ circle: { min: 2, max: 12 },
1545
+ arrow: { min: 2, max: 12 }
1546
+ };
1547
+ var HIGHLIGHT_ALPHA = 0.45;
1548
+ var HIGHLIGHT_WASH_ALPHA = 0.22;
1549
+ var MIN_RECT_SIZE = 3;
1550
+ function normalizeRect(r) {
1551
+ return {
1552
+ ...r,
1553
+ x: r.w < 0 ? r.x + r.w : r.x,
1554
+ y: r.h < 0 ? r.y + r.h : r.y,
1555
+ w: Math.abs(r.w),
1556
+ h: Math.abs(r.h)
1557
+ };
1558
+ }
1559
+ function hitTestRect(strokes, p, tolerance, selected) {
1560
+ if (selected !== null) {
1561
+ const s = strokes[selected];
1562
+ if ((s == null ? void 0 : s.type) === "rect") {
1563
+ const corners = [
1564
+ ["nw", s.x, s.y],
1565
+ ["ne", s.x + s.w, s.y],
1566
+ ["sw", s.x, s.y + s.h],
1567
+ ["se", s.x + s.w, s.y + s.h]
1568
+ ];
1569
+ for (const [handle, cx, cy] of corners) {
1570
+ if (Math.abs(p.x - cx) <= tolerance && Math.abs(p.y - cy) <= tolerance) {
1571
+ return { index: selected, handle };
1572
+ }
1573
+ }
1574
+ if (insideRect(s, p, tolerance)) return { index: selected, handle: "move" };
1575
+ }
1576
+ }
1577
+ for (let i = strokes.length - 1; i >= 0; i--) {
1578
+ const s = strokes[i];
1579
+ if (s.type !== "rect" || i === selected) continue;
1580
+ const band = tolerance + s.width / 2;
1581
+ if (insideRect(s, p, band) && !insideRect(s, p, -band)) return { index: i, handle: "move" };
1582
+ }
1583
+ return null;
1584
+ }
1585
+ function insideRect(r, p, pad) {
1586
+ return p.x >= r.x - pad && p.x <= r.x + r.w + pad && p.y >= r.y - pad && p.y <= r.y + r.h + pad;
1587
+ }
1588
+ function dragRect(orig, handle, dx, dy) {
1589
+ if (handle === "move") return { ...orig, x: orig.x + dx, y: orig.y + dy };
1590
+ const left = handle === "nw" || handle === "sw" ? orig.x + dx : orig.x;
1591
+ const right = handle === "ne" || handle === "se" ? orig.x + orig.w + dx : orig.x + orig.w;
1592
+ const top = handle === "nw" || handle === "ne" ? orig.y + dy : orig.y;
1593
+ const bottom = handle === "sw" || handle === "se" ? orig.y + orig.h + dy : orig.y + orig.h;
1594
+ return normalizeRect({ ...orig, x: left, y: top, w: right - left, h: bottom - top });
1595
+ }
1596
+ function strokePath(ctx, points) {
1597
+ ctx.beginPath();
1598
+ ctx.moveTo(points[0].x, points[0].y);
1599
+ for (let i = 1; i < points.length; i++) ctx.lineTo(points[i].x, points[i].y);
1600
+ ctx.stroke();
1601
+ }
1477
1602
  function drawStroke(ctx, s) {
1603
+ ctx.save();
1478
1604
  ctx.strokeStyle = s.color;
1479
1605
  ctx.lineWidth = s.width;
1480
1606
  ctx.lineCap = "round";
1481
1607
  ctx.lineJoin = "round";
1482
1608
  if (s.type === "freehand") {
1483
- if (s.points.length < 2) return;
1484
- ctx.beginPath();
1485
- ctx.moveTo(s.points[0].x, s.points[0].y);
1486
- for (let i = 1; i < s.points.length; i++) ctx.lineTo(s.points[i].x, s.points[i].y);
1487
- ctx.stroke();
1609
+ if (s.points.length >= 2) strokePath(ctx, s.points);
1610
+ } else if (s.type === "highlight") {
1611
+ if (s.points.length >= 2) {
1612
+ ctx.lineCap = "butt";
1613
+ ctx.globalCompositeOperation = "multiply";
1614
+ ctx.globalAlpha = HIGHLIGHT_ALPHA;
1615
+ strokePath(ctx, s.points);
1616
+ ctx.globalCompositeOperation = "source-over";
1617
+ ctx.globalAlpha = HIGHLIGHT_WASH_ALPHA;
1618
+ strokePath(ctx, s.points);
1619
+ }
1620
+ } else if (s.type === "rect") {
1621
+ ctx.lineJoin = "miter";
1622
+ ctx.strokeRect(s.x, s.y, s.w, s.h);
1488
1623
  } else if (s.type === "circle") {
1489
1624
  ctx.beginPath();
1490
1625
  ctx.arc(s.cx, s.cy, s.r, 0, Math.PI * 2);
1491
1626
  ctx.stroke();
1492
- } else {
1493
- if (Math.hypot(s.x2 - s.x1, s.y2 - s.y1) < 3) return;
1627
+ } else if (Math.hypot(s.x2 - s.x1, s.y2 - s.y1) >= 3) {
1494
1628
  const angle = Math.atan2(s.y2 - s.y1, s.x2 - s.x1);
1495
1629
  const head = Math.max(14, s.width * 4);
1496
1630
  ctx.beginPath();
@@ -1501,16 +1635,57 @@ function drawStroke(ctx, s) {
1501
1635
  ctx.lineTo(s.x2 - head * Math.cos(angle + Math.PI / 6), s.y2 - head * Math.sin(angle + Math.PI / 6));
1502
1636
  ctx.stroke();
1503
1637
  }
1638
+ ctx.restore();
1639
+ }
1640
+ function paintOrder(strokes) {
1641
+ return [...strokes.filter((s) => s.type === "highlight"), ...strokes.filter((s) => s.type !== "highlight")];
1642
+ }
1643
+ function drawSelection(ctx, r, scale) {
1644
+ const pad = r.width / 2 + 3 * scale;
1645
+ const size = 9 * scale;
1646
+ ctx.save();
1647
+ ctx.strokeStyle = "#22d3ee";
1648
+ ctx.lineWidth = 1.5 * scale;
1649
+ ctx.setLineDash([5 * scale, 4 * scale]);
1650
+ ctx.strokeRect(r.x - pad, r.y - pad, r.w + pad * 2, r.h + pad * 2);
1651
+ ctx.setLineDash([]);
1652
+ ctx.fillStyle = "#ffffff";
1653
+ for (const [cx, cy] of [
1654
+ [r.x, r.y],
1655
+ [r.x + r.w, r.y],
1656
+ [r.x, r.y + r.h],
1657
+ [r.x + r.w, r.y + r.h]
1658
+ ]) {
1659
+ ctx.fillRect(cx - size / 2, cy - size / 2, size, size);
1660
+ ctx.strokeRect(cx - size / 2, cy - size / 2, size, size);
1661
+ }
1662
+ ctx.restore();
1663
+ }
1664
+ function paintAnnotations(ctx, img, strokes, current, selected, scale) {
1665
+ const { width, height } = ctx.canvas;
1666
+ ctx.clearRect(0, 0, width, height);
1667
+ ctx.drawImage(img, 0, 0, width, height);
1668
+ for (const s of paintOrder(current ? [...strokes, current] : strokes)) drawStroke(ctx, s);
1669
+ const sel = selected !== null ? strokes[selected] : void 0;
1670
+ if ((sel == null ? void 0 : sel.type) === "rect") drawSelection(ctx, sel, scale);
1671
+ }
1672
+ function cursorFor(handle) {
1673
+ if (handle === "move") return "move";
1674
+ if (handle === "nw" || handle === "se") return "nwse-resize";
1675
+ if (handle === "ne" || handle === "sw") return "nesw-resize";
1676
+ return "crosshair";
1504
1677
  }
1505
1678
  function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1506
1679
  const canvasRef = (0, import_react2.useRef)(null);
1507
1680
  const imgRef = (0, import_react2.useRef)(null);
1681
+ const dragRef = (0, import_react2.useRef)(null);
1508
1682
  const [ready, setReady] = (0, import_react2.useState)(false);
1509
1683
  const [tool, setTool] = (0, import_react2.useState)("pen");
1510
- const [color, setColor] = (0, import_react2.useState)(PALETTE[0]);
1511
- const [strokeWidth, setStrokeWidth] = (0, import_react2.useState)(4);
1684
+ const [settings, setSettings] = (0, import_react2.useState)(TOOL_DEFAULTS);
1512
1685
  const [strokes, setStrokes] = (0, import_react2.useState)([]);
1513
1686
  const [currentStroke, setCurrentStroke] = (0, import_react2.useState)(null);
1687
+ const [selected, setSelected] = (0, import_react2.useState)(null);
1688
+ const { color, width: strokeWidth } = settings[tool];
1514
1689
  (0, import_react2.useEffect)(() => {
1515
1690
  const img = new Image();
1516
1691
  img.onload = () => {
@@ -1524,18 +1699,21 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1524
1699
  };
1525
1700
  img.src = imageSrc;
1526
1701
  }, [imageSrc]);
1527
- (0, import_react2.useEffect)(() => {
1528
- if (!ready) return;
1702
+ const displayScale = (canvas) => {
1703
+ const w = canvas.getBoundingClientRect().width;
1704
+ return w > 0 ? canvas.width / w : 1;
1705
+ };
1706
+ const paint = (showSelection) => {
1529
1707
  const canvas = canvasRef.current;
1530
1708
  const img = imgRef.current;
1531
1709
  if (!canvas || !img) return;
1532
1710
  const ctx = canvas.getContext("2d");
1533
1711
  if (!ctx) return;
1534
- ctx.clearRect(0, 0, canvas.width, canvas.height);
1535
- ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
1536
- for (const s of strokes) drawStroke(ctx, s);
1537
- if (currentStroke) drawStroke(ctx, currentStroke);
1538
- }, [ready, strokes, currentStroke]);
1712
+ paintAnnotations(ctx, img, strokes, currentStroke, showSelection ? selected : null, displayScale(canvas));
1713
+ };
1714
+ (0, import_react2.useEffect)(() => {
1715
+ if (ready) paint(true);
1716
+ });
1539
1717
  const getPos = (e) => {
1540
1718
  const canvas = e.currentTarget;
1541
1719
  const rect = canvas.getBoundingClientRect();
@@ -1544,32 +1722,76 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1544
1722
  y: (e.clientY - rect.top) * canvas.height / rect.height
1545
1723
  };
1546
1724
  };
1725
+ const hitAt = (canvas, p, pointerType) => tool === "rect" ? hitTestRect(strokes, p, (pointerType === "mouse" ? 8 : 16) * displayScale(canvas), selected) : null;
1547
1726
  const handlePointerDown = (e) => {
1548
1727
  e.currentTarget.setPointerCapture(e.pointerId);
1549
- const { x, y } = getPos(e);
1728
+ const p = getPos(e);
1729
+ const hit = hitAt(e.currentTarget, p, e.pointerType);
1730
+ if (hit) {
1731
+ setSelected(hit.index);
1732
+ dragRef.current = { index: hit.index, handle: hit.handle, start: p, orig: strokes[hit.index] };
1733
+ return;
1734
+ }
1735
+ setSelected(null);
1736
+ const { x, y } = p;
1737
+ const base = { color, width: strokeWidth };
1550
1738
  setCurrentStroke(
1551
- tool === "pen" ? { type: "freehand", color, width: strokeWidth, points: [{ x, y }] } : tool === "circle" ? { type: "circle", color, width: strokeWidth, cx: x, cy: y, r: 0 } : { type: "arrow", color, width: strokeWidth, x1: x, y1: y, x2: x, y2: y }
1739
+ tool === "pen" ? { type: "freehand", ...base, points: [p] } : tool === "highlighter" ? { type: "highlight", ...base, points: [p] } : tool === "rect" ? { type: "rect", ...base, x, y, w: 0, h: 0 } : tool === "circle" ? { type: "circle", ...base, cx: x, cy: y, r: 0 } : { type: "arrow", ...base, x1: x, y1: y, x2: x, y2: y }
1552
1740
  );
1553
1741
  };
1554
1742
  const handlePointerMove = (e) => {
1555
- if (!currentStroke) return;
1556
- const { x, y } = getPos(e);
1743
+ var _a;
1744
+ const p = getPos(e);
1745
+ const drag = dragRef.current;
1746
+ if (drag) {
1747
+ const next = dragRect(drag.orig, drag.handle, p.x - drag.start.x, p.y - drag.start.y);
1748
+ setStrokes((s) => s.map((st, i) => i === drag.index ? next : st));
1749
+ return;
1750
+ }
1751
+ if (!currentStroke) {
1752
+ e.currentTarget.style.cursor = cursorFor((_a = hitAt(e.currentTarget, p, e.pointerType)) == null ? void 0 : _a.handle);
1753
+ return;
1754
+ }
1755
+ const { x, y } = p;
1557
1756
  setCurrentStroke((prev) => {
1558
1757
  if (!prev) return prev;
1559
- if (prev.type === "freehand") return { ...prev, points: [...prev.points, { x, y }] };
1758
+ if (prev.type === "freehand" || prev.type === "highlight") return { ...prev, points: [...prev.points, p] };
1759
+ if (prev.type === "rect") return { ...prev, w: x - prev.x, h: y - prev.y };
1560
1760
  if (prev.type === "arrow") return { ...prev, x2: x, y2: y };
1561
1761
  return { ...prev, r: Math.hypot(x - prev.cx, y - prev.cy) };
1562
1762
  });
1563
1763
  };
1564
1764
  const handlePointerUp = () => {
1565
- setCurrentStroke((prev) => {
1566
- if (prev) setStrokes((s) => [...s, prev]);
1567
- return null;
1568
- });
1765
+ if (dragRef.current) {
1766
+ dragRef.current = null;
1767
+ return;
1768
+ }
1769
+ const done = currentStroke;
1770
+ setCurrentStroke(null);
1771
+ if (!done) return;
1772
+ if (done.type === "rect") {
1773
+ const r = normalizeRect(done);
1774
+ if (r.w < MIN_RECT_SIZE || r.h < MIN_RECT_SIZE) return;
1775
+ setStrokes((s) => [...s, r]);
1776
+ setSelected(strokes.length);
1777
+ return;
1778
+ }
1779
+ setStrokes((s) => [...s, done]);
1780
+ };
1781
+ const applySetting = (patch) => {
1782
+ setSettings((s) => ({ ...s, [tool]: { ...s[tool], ...patch } }));
1783
+ if (selected !== null) {
1784
+ setStrokes((s) => s.map((st, i) => i === selected && st.type === "rect" ? { ...st, ...patch } : st));
1785
+ }
1786
+ };
1787
+ const chooseTool = (t) => {
1788
+ setTool(t);
1789
+ setSelected(null);
1569
1790
  };
1570
1791
  const handleSave = () => {
1571
1792
  const canvas = canvasRef.current;
1572
1793
  if (!canvas) return;
1794
+ paint(false);
1573
1795
  onSave(encodeScreenshot(canvas));
1574
1796
  };
1575
1797
  const iconBtn = (active = false) => ({
@@ -1613,6 +1835,7 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1613
1835
  onPointerDown: handlePointerDown,
1614
1836
  onPointerMove: handlePointerMove,
1615
1837
  onPointerUp: handlePointerUp,
1838
+ onPointerCancel: handlePointerUp,
1616
1839
  style: {
1617
1840
  maxWidth: "100%",
1618
1841
  maxHeight: "calc(100vh - 140px)",
@@ -1636,15 +1859,17 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1636
1859
  maxWidth: "100%"
1637
1860
  },
1638
1861
  children: [
1639
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => setTool("pen"), style: iconBtn(tool === "pen"), title: "Freehand", "aria-label": "Freehand tool", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 20h9M16.5 3.5a2.12 2.12 0 013 3L7 19l-4 1 1-4L16.5 3.5z", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) }) }),
1640
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => setTool("circle"), style: iconBtn(tool === "circle"), title: "Circle", "aria-label": "Circle tool", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "8", stroke: "currentColor", strokeWidth: "1.8" }) }) }),
1641
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => setTool("arrow"), style: iconBtn(tool === "arrow"), title: "Arrow", "aria-label": "Arrow tool", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5 19L19 5M19 5h-8M19 5v8", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) }) }),
1862
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => chooseTool("pen"), style: iconBtn(tool === "pen"), title: "Freehand", "aria-label": "Freehand tool", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 20h9M16.5 3.5a2.12 2.12 0 013 3L7 19l-4 1 1-4L16.5 3.5z", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) }) }),
1863
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => chooseTool("highlighter"), style: iconBtn(tool === "highlighter"), title: "Highlighter", "aria-label": "Highlighter tool", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 11l-6 6v3h9l3-3M22 12l-4.6 4.6a2 2 0 01-2.8 0l-5.2-5.2a2 2 0 010-2.8L14 4", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) }) }),
1864
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => chooseTool("rect"), style: iconBtn(tool === "rect"), title: "Rectangle \u2014 drag to draw, then drag it or its corners to adjust", "aria-label": "Rectangle tool", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "4", y: "5", width: "16", height: "14", rx: "1.5", stroke: "currentColor", strokeWidth: "1.8" }) }) }),
1865
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => chooseTool("circle"), style: iconBtn(tool === "circle"), title: "Circle", "aria-label": "Circle tool", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "8", stroke: "currentColor", strokeWidth: "1.8" }) }) }),
1866
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => chooseTool("arrow"), style: iconBtn(tool === "arrow"), title: "Arrow", "aria-label": "Arrow tool", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5 19L19 5M19 5h-8M19 5v8", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" }) }) }),
1642
1867
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { width: "1px", height: "20px", background: "rgba(255,255,255,0.15)" } }),
1643
1868
  PALETTE.map((c) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1644
1869
  "button",
1645
1870
  {
1646
1871
  type: "button",
1647
- onClick: () => setColor(c),
1872
+ onClick: () => applySetting({ color: c }),
1648
1873
  "aria-label": `Color ${c}`,
1649
1874
  style: {
1650
1875
  width: "22px",
@@ -1663,7 +1888,7 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1663
1888
  {
1664
1889
  type: "color",
1665
1890
  value: color,
1666
- onChange: (e) => setColor(e.target.value),
1891
+ onChange: (e) => applySetting({ color: e.target.value }),
1667
1892
  title: "Custom color",
1668
1893
  "aria-label": "Custom color",
1669
1894
  style: {
@@ -1681,11 +1906,11 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1681
1906
  "input",
1682
1907
  {
1683
1908
  type: "range",
1684
- min: 2,
1685
- max: 12,
1909
+ min: WIDTH_RANGE[tool].min,
1910
+ max: WIDTH_RANGE[tool].max,
1686
1911
  value: strokeWidth,
1687
- onChange: (e) => setStrokeWidth(Number(e.target.value)),
1688
- title: "Stroke width",
1912
+ onChange: (e) => applySetting({ width: Number(e.target.value) }),
1913
+ title: tool === "rect" ? "Border thickness" : "Stroke width",
1689
1914
  "aria-label": "Stroke width",
1690
1915
  style: { width: "70px" }
1691
1916
  }
@@ -1695,7 +1920,10 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1695
1920
  "button",
1696
1921
  {
1697
1922
  type: "button",
1698
- onClick: () => setStrokes((s) => s.slice(0, -1)),
1923
+ onClick: () => {
1924
+ setStrokes((s) => s.slice(0, -1));
1925
+ setSelected(null);
1926
+ },
1699
1927
  disabled: strokes.length === 0,
1700
1928
  style: { ...iconBtn(), opacity: strokes.length === 0 ? 0.35 : 1 },
1701
1929
  title: "Undo",
@@ -1707,7 +1935,10 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
1707
1935
  "button",
1708
1936
  {
1709
1937
  type: "button",
1710
- onClick: () => setStrokes([]),
1938
+ onClick: () => {
1939
+ setStrokes([]);
1940
+ setSelected(null);
1941
+ },
1711
1942
  disabled: strokes.length === 0,
1712
1943
  style: { ...iconBtn(), opacity: strokes.length === 0 ? 0.35 : 1 },
1713
1944
  title: "Clear all",
@@ -10326,7 +10557,7 @@ function GlitchgrabProviderInner({
10326
10557
  return matchesIgnorePatterns(message, ignoreErrors);
10327
10558
  };
10328
10559
  const handleError = (event) => {
10329
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
10560
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10330
10561
  try {
10331
10562
  const isOpaqueCrossOrigin = event.message === "Script error." || event.message === "Script error" || !event.error && !event.filename;
10332
10563
  if (isOpaqueCrossOrigin) {
@@ -10365,11 +10596,12 @@ function GlitchgrabProviderInner({
10365
10596
  visitedPages: JSON.stringify(context.visitedPages),
10366
10597
  ...contextMetadata(context),
10367
10598
  filename: (_e = event.filename) != null ? _e : "",
10368
- lineno: String((_f = event.lineno) != null ? _f : ""),
10369
- colno: String((_g = event.colno) != null ? _g : ""),
10599
+ ...originMetadata((_f = event.error) == null ? void 0 : _f.stack, event.filename),
10600
+ lineno: String((_g = event.lineno) != null ? _g : ""),
10601
+ colno: String((_h = event.colno) != null ? _h : ""),
10370
10602
  // The root patch could not attach (React internals moved, or a
10371
10603
  // root it does not know): still label it and send the DOM context.
10372
- ...isHydrationError((_h = event.error) != null ? _h : event.message) ? hydrationMetadata((_i = event.error) != null ? _i : event.message) : {},
10604
+ ...isHydrationError((_i = event.error) != null ? _i : event.message) ? hydrationMetadata((_j = event.error) != null ? _j : event.message) : {},
10373
10605
  ...(session == null ? void 0 : session.userId) ? { sessionUserId: session.userId } : {},
10374
10606
  ...(session == null ? void 0 : session.name) ? { sessionUserName: String(session.name) } : {},
10375
10607
  ...(session == null ? void 0 : session.email) ? { sessionUserEmail: String(session.email) } : {},
@@ -10421,6 +10653,7 @@ function GlitchgrabProviderInner({
10421
10653
  visitedPages: JSON.stringify(context.visitedPages),
10422
10654
  ...contextMetadata(context),
10423
10655
  type: "unhandledrejection",
10656
+ ...originMetadata(errStack),
10424
10657
  ...description.details ? { rejectionReason: description.details } : {},
10425
10658
  ...(session == null ? void 0 : session.userId) ? { sessionUserId: session.userId } : {},
10426
10659
  ...(session == null ? void 0 : session.name) ? { sessionUserName: String(session.name) } : {},