/* @oracle/oraclejet-preact: undefined */
import { u as useResizeObserver } from './useResizeObserver-838164c1.js';
import { useRef, useState, useCallback } from 'preact/hooks';

/**
 * Default Redwood line-height overrides cause false positives as the Range sizes are always for a 'normal'
 * line-height, and none of the default scale fonts have 'normal' line-height values. This causes offsets
 * of between 0.5px and 1.5px. As a true truncation will cause an offset of closer to a full line height
 * (at least 12px for 2xs text), use a larger offset value than the currently observed 1.5px max to reduce the likelihood of false positives.
 */
const verticalTruncationOffset = 5;
const useDetectTruncation = (isDisabled = false) => {
    const rootRef = useRef(null);
    const [isTextTruncated, setIsTextTruncated] = useState(false);
    const detectTruncation = useCallback(() => {
        if (rootRef.current && !isDisabled) {
            const element = rootRef.current;
            const range = new Range();
            range.selectNodeContents(element);
            const untruncatedText = range.getBoundingClientRect();
            const renderedText = element.getBoundingClientRect();
            setIsTextTruncated(untruncatedText.width > renderedText.width ||
                untruncatedText.height > renderedText.height + verticalTruncationOffset);
        }
    }, [isDisabled]);
    useResizeObserver(rootRef, detectTruncation, { isDisabled: isDisabled });
    const detectTruncationProps = {
        ref: rootRef
    };
    return { detectTruncationProps, isTextTruncated };
};

export { useDetectTruncation as u };
//# sourceMappingURL=useDetectTruncation-2d400634.js.map
