"use client"; import styles from "@prototype/lib/prototype-comments/ui/capture-styles.module.scss"; import { getPortalRelativeClientRect, getPrototypeHighlightPortalContainer, type PortalRelativeRect, } from "@prototype/lib/tool-portal"; import { useEffect, useState, type ReactNode } from "react"; import { createPortal } from "react-dom"; type PrototypeTargetHighlightLayerProps = { children: ReactNode; marker?: "capture" | "target" | "share"; }; export function PrototypeTargetHighlightLayer({ children, marker, }: PrototypeTargetHighlightLayerProps) { const [portal, setPortal] = useState(null); useEffect(() => { setPortal(getPrototypeHighlightPortalContainer() ?? null); }, []); if (!portal) return null; return createPortal(
{children}
, portal, ); } export function useHighlightPortalContainer(): HTMLElement | null { const [portal, setPortal] = useState(null); useEffect(() => { setPortal(getPrototypeHighlightPortalContainer() ?? null); }, []); return portal; } export function toHighlightPortalStyle( rect: Pick, portal: HTMLElement | null, ): PortalRelativeRect { if (!portal) { return { left: rect.left, top: rect.top, width: rect.width, height: rect.height, }; } return getPortalRelativeClientRect(rect, portal); }