dramaling-vocab-learning/frontend/lib/utils/popupPositioning.ts

41 lines
920 B
TypeScript

// 簡化的定位工具 - 臨時恢復版本
export interface PopupPosition {
x: number
y: number
placement: 'top' | 'bottom' | 'center'
}
export interface ClickPosition {
x: number
y: number
width: number
height: number
}
export function calculateSmartPopupPosition(
clickRect: ClickPosition,
popupWidth: number = 384,
popupHeight: number = 400
): PopupPosition {
// 簡化版本:總是使用居中
return {
x: window.innerWidth / 2,
y: window.innerHeight / 2,
placement: 'center'
}
}
export function isMobileDevice(): boolean {
if (typeof window === 'undefined') return false
return window.innerWidth <= 768
}
export function getElementPosition(element: HTMLElement): ClickPosition {
const rect = element.getBoundingClientRect()
return {
x: rect.left,
y: rect.top,
width: rect.width,
height: rect.height
}
}