Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.0 KB
Raw Blame
const MOBILE_HINT_USABLE_HEIGHT = 128;

export const getMobileHintPosition = (anchorTop: number, anchorBottom: number, hintHeight: number,
                                      viewportTop: number, viewportBottom: number, heightLimit = Infinity,
                                      gap = 0) => {
    const visibleAnchorTop = Math.max(viewportTop, Math.min(anchorTop, viewportBottom));
    const visibleAnchorBottom = Math.max(visibleAnchorTop, Math.min(anchorBottom, viewportBottom));
    const spaceAbove = Math.max(0, visibleAnchorTop - viewportTop - gap);
    const spaceBelow = Math.max(0, viewportBottom - visibleAnchorBottom - gap);
    const usableHeight = Math.min(MOBILE_HINT_USABLE_HEIGHT, Math.max(0, heightLimit));
    const below = spaceAbove < usableHeight && spaceBelow > spaceAbove;
    const maxHeight = Math.min(below ? spaceBelow : spaceAbove, Math.max(0, heightLimit));
    const height = Math.min(hintHeight, maxHeight);
    return {
        maxHeight,
        top: below ? visibleAnchorBottom + gap : visibleAnchorTop - gap - height,
    };
};