Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions content/picker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {getCssPath} from '../lib/css-path.js';

let overlay;
let tooltip;
export function startPicker() {
if (overlay) return;

// Create main overlay
overlay = document.createElement('div');
overlay.style.position = 'fixed';
overlay.style.top = '0';
Expand All @@ -14,6 +17,24 @@ export function startPicker() {
overlay.style.border = '2px solid #2ac3ff';
document.body.appendChild(overlay);

// Create tooltip
tooltip = document.createElement('div');
tooltip.style.position = 'fixed';
tooltip.style.zIndex = '2147483647';
tooltip.style.pointerEvents = 'none';
tooltip.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
tooltip.style.color = 'white';
tooltip.style.padding = '8px 12px';
tooltip.style.borderRadius = '6px';
tooltip.style.fontSize = '14px';
tooltip.style.fontFamily = 'Arial, sans-serif';
tooltip.style.whiteSpace = 'nowrap';
tooltip.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.3)';
tooltip.style.transform = 'translate(-50%, -100%)';
tooltip.style.marginTop = '-10px';
tooltip.textContent = 'Click an image to select';
document.body.appendChild(tooltip);

function move(e) {
const el = e.target;
const rect = el.getBoundingClientRect();
Expand All @@ -22,6 +43,10 @@ export function startPicker() {
overlay.style.left = rect.left + 'px';
overlay.style.width = rect.width + 'px';
overlay.style.height = rect.height + 'px';

// Update tooltip position
tooltip.style.left = e.clientX + 'px';
tooltip.style.top = e.clientY + 'px';
}

function click(e) {
Expand All @@ -35,8 +60,14 @@ export function startPicker() {
function cleanup() {
document.removeEventListener('mousemove', move, true);
document.removeEventListener('click', click, true);
overlay.remove();
overlay = null;
if (overlay) {
overlay.remove();
overlay = null;
}
if (tooltip) {
tooltip.remove();
tooltip = null;
}
}

document.addEventListener('mousemove', move, true);
Expand Down