This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Select region</title>
|
||||
<style>
|
||||
html, body { margin: 0; height: 100%; cursor: crosshair; background: rgba(0,0,0,0.25); user-select: none; }
|
||||
#hint { position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
|
||||
background: rgba(17,24,39,.9); color: #fff; padding: 6px 14px; border-radius: 6px;
|
||||
font: 13px system-ui, sans-serif; pointer-events: none; }
|
||||
#sel { position: fixed; border: 2px solid #2563eb; background: rgba(37,99,235,.15); display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="hint">Drag to select a region — Esc to cancel</div>
|
||||
<div id="sel"></div>
|
||||
<script>
|
||||
const sel = document.getElementById('sel');
|
||||
let start = null;
|
||||
function rectFrom(a, b) {
|
||||
return { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y), w: Math.abs(a.x - b.x), h: Math.abs(a.y - b.y) };
|
||||
}
|
||||
window.addEventListener('mousedown', (e) => { start = { x: e.clientX, y: e.clientY }; });
|
||||
window.addEventListener('mousemove', (e) => {
|
||||
if (!start) return;
|
||||
const r = rectFrom(start, { x: e.clientX, y: e.clientY });
|
||||
sel.style.display = 'block';
|
||||
sel.style.left = r.x + 'px'; sel.style.top = r.y + 'px';
|
||||
sel.style.width = r.w + 'px'; sel.style.height = r.h + 'px';
|
||||
});
|
||||
window.addEventListener('mouseup', (e) => {
|
||||
if (!start) return;
|
||||
const r = rectFrom(start, { x: e.clientX, y: e.clientY });
|
||||
window.regionPicker.done(r.w > 3 && r.h > 3 ? r : null);
|
||||
});
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') window.regionPicker.done(null);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user