glitchgrab 1.61.1 → 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 +212 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +212 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1529,24 +1529,102 @@ async function encodeImageFile(file, maxLength = MAX_SCREENSHOT_DATA_URL_LENGTH)
|
|
|
1529
1529
|
}
|
|
1530
1530
|
return readAsDataUrl(file);
|
|
1531
1531
|
}
|
|
1532
|
-
var PALETTE = ["#ef4444", "#
|
|
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
|
+
}
|
|
1533
1602
|
function drawStroke(ctx, s) {
|
|
1603
|
+
ctx.save();
|
|
1534
1604
|
ctx.strokeStyle = s.color;
|
|
1535
1605
|
ctx.lineWidth = s.width;
|
|
1536
1606
|
ctx.lineCap = "round";
|
|
1537
1607
|
ctx.lineJoin = "round";
|
|
1538
1608
|
if (s.type === "freehand") {
|
|
1539
|
-
if (s.points.length
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
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);
|
|
1544
1623
|
} else if (s.type === "circle") {
|
|
1545
1624
|
ctx.beginPath();
|
|
1546
1625
|
ctx.arc(s.cx, s.cy, s.r, 0, Math.PI * 2);
|
|
1547
1626
|
ctx.stroke();
|
|
1548
|
-
} else {
|
|
1549
|
-
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) {
|
|
1550
1628
|
const angle = Math.atan2(s.y2 - s.y1, s.x2 - s.x1);
|
|
1551
1629
|
const head = Math.max(14, s.width * 4);
|
|
1552
1630
|
ctx.beginPath();
|
|
@@ -1557,16 +1635,57 @@ function drawStroke(ctx, s) {
|
|
|
1557
1635
|
ctx.lineTo(s.x2 - head * Math.cos(angle + Math.PI / 6), s.y2 - head * Math.sin(angle + Math.PI / 6));
|
|
1558
1636
|
ctx.stroke();
|
|
1559
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";
|
|
1560
1677
|
}
|
|
1561
1678
|
function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
1562
1679
|
const canvasRef = (0, import_react2.useRef)(null);
|
|
1563
1680
|
const imgRef = (0, import_react2.useRef)(null);
|
|
1681
|
+
const dragRef = (0, import_react2.useRef)(null);
|
|
1564
1682
|
const [ready, setReady] = (0, import_react2.useState)(false);
|
|
1565
1683
|
const [tool, setTool] = (0, import_react2.useState)("pen");
|
|
1566
|
-
const [
|
|
1567
|
-
const [strokeWidth, setStrokeWidth] = (0, import_react2.useState)(4);
|
|
1684
|
+
const [settings, setSettings] = (0, import_react2.useState)(TOOL_DEFAULTS);
|
|
1568
1685
|
const [strokes, setStrokes] = (0, import_react2.useState)([]);
|
|
1569
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];
|
|
1570
1689
|
(0, import_react2.useEffect)(() => {
|
|
1571
1690
|
const img = new Image();
|
|
1572
1691
|
img.onload = () => {
|
|
@@ -1580,18 +1699,21 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
|
1580
1699
|
};
|
|
1581
1700
|
img.src = imageSrc;
|
|
1582
1701
|
}, [imageSrc]);
|
|
1583
|
-
|
|
1584
|
-
|
|
1702
|
+
const displayScale = (canvas) => {
|
|
1703
|
+
const w = canvas.getBoundingClientRect().width;
|
|
1704
|
+
return w > 0 ? canvas.width / w : 1;
|
|
1705
|
+
};
|
|
1706
|
+
const paint = (showSelection) => {
|
|
1585
1707
|
const canvas = canvasRef.current;
|
|
1586
1708
|
const img = imgRef.current;
|
|
1587
1709
|
if (!canvas || !img) return;
|
|
1588
1710
|
const ctx = canvas.getContext("2d");
|
|
1589
1711
|
if (!ctx) return;
|
|
1590
|
-
ctx
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
if (
|
|
1594
|
-
}
|
|
1712
|
+
paintAnnotations(ctx, img, strokes, currentStroke, showSelection ? selected : null, displayScale(canvas));
|
|
1713
|
+
};
|
|
1714
|
+
(0, import_react2.useEffect)(() => {
|
|
1715
|
+
if (ready) paint(true);
|
|
1716
|
+
});
|
|
1595
1717
|
const getPos = (e) => {
|
|
1596
1718
|
const canvas = e.currentTarget;
|
|
1597
1719
|
const rect = canvas.getBoundingClientRect();
|
|
@@ -1600,32 +1722,76 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
|
1600
1722
|
y: (e.clientY - rect.top) * canvas.height / rect.height
|
|
1601
1723
|
};
|
|
1602
1724
|
};
|
|
1725
|
+
const hitAt = (canvas, p, pointerType) => tool === "rect" ? hitTestRect(strokes, p, (pointerType === "mouse" ? 8 : 16) * displayScale(canvas), selected) : null;
|
|
1603
1726
|
const handlePointerDown = (e) => {
|
|
1604
1727
|
e.currentTarget.setPointerCapture(e.pointerId);
|
|
1605
|
-
const
|
|
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 };
|
|
1606
1738
|
setCurrentStroke(
|
|
1607
|
-
tool === "pen" ? { type: "freehand",
|
|
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 }
|
|
1608
1740
|
);
|
|
1609
1741
|
};
|
|
1610
1742
|
const handlePointerMove = (e) => {
|
|
1611
|
-
|
|
1612
|
-
const
|
|
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;
|
|
1613
1756
|
setCurrentStroke((prev) => {
|
|
1614
1757
|
if (!prev) return prev;
|
|
1615
|
-
if (prev.type === "freehand") return { ...prev, points: [...prev.points,
|
|
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 };
|
|
1616
1760
|
if (prev.type === "arrow") return { ...prev, x2: x, y2: y };
|
|
1617
1761
|
return { ...prev, r: Math.hypot(x - prev.cx, y - prev.cy) };
|
|
1618
1762
|
});
|
|
1619
1763
|
};
|
|
1620
1764
|
const handlePointerUp = () => {
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
return
|
|
1624
|
-
}
|
|
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);
|
|
1625
1790
|
};
|
|
1626
1791
|
const handleSave = () => {
|
|
1627
1792
|
const canvas = canvasRef.current;
|
|
1628
1793
|
if (!canvas) return;
|
|
1794
|
+
paint(false);
|
|
1629
1795
|
onSave(encodeScreenshot(canvas));
|
|
1630
1796
|
};
|
|
1631
1797
|
const iconBtn = (active = false) => ({
|
|
@@ -1669,6 +1835,7 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
|
1669
1835
|
onPointerDown: handlePointerDown,
|
|
1670
1836
|
onPointerMove: handlePointerMove,
|
|
1671
1837
|
onPointerUp: handlePointerUp,
|
|
1838
|
+
onPointerCancel: handlePointerUp,
|
|
1672
1839
|
style: {
|
|
1673
1840
|
maxWidth: "100%",
|
|
1674
1841
|
maxHeight: "calc(100vh - 140px)",
|
|
@@ -1692,15 +1859,17 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
|
1692
1859
|
maxWidth: "100%"
|
|
1693
1860
|
},
|
|
1694
1861
|
children: [
|
|
1695
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () =>
|
|
1696
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () =>
|
|
1697
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () =>
|
|
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" }) }) }),
|
|
1698
1867
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { width: "1px", height: "20px", background: "rgba(255,255,255,0.15)" } }),
|
|
1699
1868
|
PALETTE.map((c) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1700
1869
|
"button",
|
|
1701
1870
|
{
|
|
1702
1871
|
type: "button",
|
|
1703
|
-
onClick: () =>
|
|
1872
|
+
onClick: () => applySetting({ color: c }),
|
|
1704
1873
|
"aria-label": `Color ${c}`,
|
|
1705
1874
|
style: {
|
|
1706
1875
|
width: "22px",
|
|
@@ -1719,7 +1888,7 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
|
1719
1888
|
{
|
|
1720
1889
|
type: "color",
|
|
1721
1890
|
value: color,
|
|
1722
|
-
onChange: (e) =>
|
|
1891
|
+
onChange: (e) => applySetting({ color: e.target.value }),
|
|
1723
1892
|
title: "Custom color",
|
|
1724
1893
|
"aria-label": "Custom color",
|
|
1725
1894
|
style: {
|
|
@@ -1737,11 +1906,11 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
|
1737
1906
|
"input",
|
|
1738
1907
|
{
|
|
1739
1908
|
type: "range",
|
|
1740
|
-
min:
|
|
1741
|
-
max:
|
|
1909
|
+
min: WIDTH_RANGE[tool].min,
|
|
1910
|
+
max: WIDTH_RANGE[tool].max,
|
|
1742
1911
|
value: strokeWidth,
|
|
1743
|
-
onChange: (e) =>
|
|
1744
|
-
title: "Stroke width",
|
|
1912
|
+
onChange: (e) => applySetting({ width: Number(e.target.value) }),
|
|
1913
|
+
title: tool === "rect" ? "Border thickness" : "Stroke width",
|
|
1745
1914
|
"aria-label": "Stroke width",
|
|
1746
1915
|
style: { width: "70px" }
|
|
1747
1916
|
}
|
|
@@ -1751,7 +1920,10 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
|
1751
1920
|
"button",
|
|
1752
1921
|
{
|
|
1753
1922
|
type: "button",
|
|
1754
|
-
onClick: () =>
|
|
1923
|
+
onClick: () => {
|
|
1924
|
+
setStrokes((s) => s.slice(0, -1));
|
|
1925
|
+
setSelected(null);
|
|
1926
|
+
},
|
|
1755
1927
|
disabled: strokes.length === 0,
|
|
1756
1928
|
style: { ...iconBtn(), opacity: strokes.length === 0 ? 0.35 : 1 },
|
|
1757
1929
|
title: "Undo",
|
|
@@ -1763,7 +1935,10 @@ function AnnotationCanvas({ imageSrc, onSave, onCancel }) {
|
|
|
1763
1935
|
"button",
|
|
1764
1936
|
{
|
|
1765
1937
|
type: "button",
|
|
1766
|
-
onClick: () =>
|
|
1938
|
+
onClick: () => {
|
|
1939
|
+
setStrokes([]);
|
|
1940
|
+
setSelected(null);
|
|
1941
|
+
},
|
|
1767
1942
|
disabled: strokes.length === 0,
|
|
1768
1943
|
style: { ...iconBtn(), opacity: strokes.length === 0 ? 0.35 : 1 },
|
|
1769
1944
|
title: "Clear all",
|