Files
parcer/src/components/recorder/Highlighter.tsx

89 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-06-14 23:19:35 +05:30
import React from 'react';
2024-06-14 21:48:23 +05:30
import styled from "styled-components";
import { coordinateMapper } from '../../helpers/coordinateMapper';
2024-06-14 21:48:23 +05:30
interface HighlighterProps {
unmodifiedRect: DOMRect;
displayedSelector: string;
width: number;
height: number;
canvasRect: DOMRect;
};
2025-03-27 00:25:27 +05:30
const HighlighterComponent = ({ unmodifiedRect, displayedSelector = '', width, height, canvasRect }: HighlighterProps) => {
2024-06-14 21:48:23 +05:30
if (!unmodifiedRect) {
return null;
} else {
const mappedRect = coordinateMapper.mapBrowserRectToCanvas(unmodifiedRect);
2024-06-14 21:48:23 +05:30
const rect = {
top: mappedRect.top + canvasRect.top + window.scrollY,
left: mappedRect.left + canvasRect.left + window.scrollX,
right: mappedRect.right + canvasRect.left,
bottom: mappedRect.bottom + canvasRect.top,
width: mappedRect.width,
height: mappedRect.height,
2024-06-14 21:48:23 +05:30
};
return (
<div>
<HighlighterOutline
id="Highlighter-outline"
top={rect.top}
left={rect.left}
width={rect.width}
height={rect.height}
/>
2024-10-24 00:05:44 +05:30
{/* <HighlighterLabel
2024-06-14 21:48:23 +05:30
id="Highlighter-label"
top={rect.top + rect.height + 8}
left={rect.left}
>
{displayedSelector}
2024-10-24 00:05:44 +05:30
</HighlighterLabel> */}
2024-06-14 21:48:23 +05:30
</div>
);
}
}
2025-03-27 00:25:27 +05:30
export const Highlighter = React.memo(HighlighterComponent);
2024-06-14 21:48:23 +05:30
const HighlighterOutline = styled.div<HighlighterOutlineProps>`
box-sizing: border-box;
pointer-events: none !important;
position: fixed !important;
background: #ff5d5b26 !important;
2025-03-20 16:46:26 +05:30
outline: 2px solid #ff00c3 !important;
2024-06-14 21:48:23 +05:30
z-index: 2147483647 !important;
top: ${(p: HighlighterOutlineProps) => p.top}px;
left: ${(p: HighlighterOutlineProps) => p.left}px;
width: ${(p: HighlighterOutlineProps) => p.width}px;
height: ${(p: HighlighterOutlineProps) => p.height}px;
`;
const HighlighterLabel = styled.div<HighlighterLabelProps>`
pointer-events: none !important;
position: fixed !important;
background: #080a0b !important;
color: white !important;
padding: 8px !important;
font-family: monospace !important;
border-radius: 5px !important;
z-index: 2147483647 !important;
top: ${(p: HighlighterLabelProps) => p.top}px;
left: ${(p: HighlighterLabelProps) => p.left}px;
`;
2024-06-14 23:19:35 +05:30
interface HighlighterLabelProps {
2024-06-14 21:48:23 +05:30
top: number;
left: number;
}
interface HighlighterOutlineProps {
top: number;
left: number;
width: number;
height: number;
}