) => {
if (highlighterData && canvasRef?.current) {
const canvasRect = canvasRef.current.getBoundingClientRect();
const clickX = e.clientX - canvasRect.left;
const clickY = e.clientY - canvasRect.top;
const highlightRect = highlighterData.rect;
if (
clickX >= highlightRect.left &&
clickX <= highlightRect.right &&
clickY >= highlightRect.top &&
clickY <= highlightRect.bottom
) {
setShowConfirmation(true);
}
}
};
const handleConfirmation = (confirmed: boolean) => {
if (confirmed) {
console.log(`User confirmed interaction with: ${highlighterData?.selector}`);
} else {
console.log('User declined interaction');
}
setShowConfirmation(false);
};
return (
{
showConfirmation ? (
setShowConfirmation(false)}
canBeClosed={false}
>
handleConfirmation(true)}
onNo={() => handleConfirmation(false)}
/>
) : null
}
{(getText && !showConfirmation && highlighterData?.rect != null && highlighterData?.rect.top != null) && canvasRef?.current ?
: null}
);
};
const drawImage = (image: string, canvas: HTMLCanvasElement): void => {
const ctx = canvas.getContext('2d');
const img = new Image();
img.src = image;
img.onload = () => {
URL.revokeObjectURL(img.src);
ctx?.drawImage(img, 0, 0, 1280, 720);
};
};