/**
 * Convert annotation color to CSS rgba() string.
 */
export function colorToRgba(color, opacity, defaultColor = "rgba(255, 255, 0, 0.3)") {
    if (!color)
        return defaultColor;
    const r = Math.round(color.r * 255);
    const g = Math.round(color.g * 255);
    const b = Math.round(color.b * 255);
    return `rgba(${r}, ${g}, ${b}, ${opacity})`;
}
/**
 * Convert annotation color to CSS rgb() string.
 */
export function colorToRgb(color, defaultColor = "rgb(0, 0, 0)") {
    if (!color)
        return defaultColor;
    const r = Math.round(color.r * 255);
    const g = Math.round(color.g * 255);
    const b = Math.round(color.b * 255);
    return `rgb(${r}, ${g}, ${b})`;
}
/**
 * Scale a point from page coordinates to screen pixels.
 */
export function scalePoint(point, scale) {
    return {
        x: point.x * scale,
        y: point.y * scale,
    };
}
/**
 * Scale bounds from page coordinates to screen pixels.
 */
export function scaleBounds(bounds, scale) {
    return {
        x: bounds.x * scale,
        y: bounds.y * scale,
        width: bounds.width * scale,
        height: bounds.height * scale,
    };
}
/**
 * Apply bounds as inline styles to an element.
 */
export function applyBoundsStyle(el, bounds, scale) {
    el.style.position = "absolute";
    el.style.left = `${bounds.x * scale}px`;
    el.style.top = `${bounds.y * scale}px`;
    el.style.width = `${bounds.width * scale}px`;
    el.style.height = `${bounds.height * scale}px`;
}
/**
 * Create an SVG element sized to cover the annotation layer.
 */
export function createSvgOverlay() {
    const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
    svg.style.position = "absolute";
    svg.style.top = "0";
    svg.style.left = "0";
    svg.style.width = "100%";
    svg.style.height = "100%";
    svg.style.pointerEvents = "none";
    svg.style.overflow = "visible";
    return svg;
}
/**
 * Create SVG namespace element helper.
 */
export function createSvgElement(tagName) {
    return document.createElementNS("http://www.w3.org/2000/svg", tagName);
}
/**
 * Check if two bounds are approximately equal (for highlight matching).
 */
export function boundsMatch(a, b, epsilon = 0.1) {
    return (Math.abs(a.x - b.x) < epsilon &&
        Math.abs(a.y - b.y) < epsilon &&
        Math.abs(a.width - b.width) < epsilon &&
        Math.abs(a.height - b.height) < epsilon);
}
//# sourceMappingURL=utils.js.map