import { positionInfoType } from "@/lib/type/ComponentType"; /** * 计算截图工具栏位置 * @param position 裁剪框位置信息 * @param toolWidth 截图工具栏宽度 */ export function calculateToolLocation( position: positionInfoType, toolWidth: number ) { const toolHeight = 100; // 工具栏X轴坐标 = (裁剪框的宽度 - 工具栏的宽度) / 2 + 裁剪框距离左侧的距离 let mouseX = (position.width - toolWidth) / 2 + position.startX; // 工具栏Y轴坐标 let mouseY = position.startY + position.height + 10; // 底部边缘 if (mouseY > innerHeight - toolHeight) { mouseY = position.startY - toolHeight; } // 顶部边缘 if (mouseY < 0) mouseY = 0; // 左侧边缘 if (mouseX <= 0) mouseX = 0; // 右侧边缘 if (mouseX >= innerWidth - toolWidth) mouseX = innerWidth - toolWidth; return { mouseX, mouseY }; }