actuel-inactuel/site/plugins/loop/frontend/src/composables/getDialogPosition.ts
isUnknown ab7fd8b2ea
All checks were successful
Deploy / Deploy to Production (push) Successful in 6s
add kirby-loop plugin with French translations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 21:41:50 +01:00

39 lines
1.1 KiB
TypeScript

import { getDocumentHeight } from "./getDocumentHeight";
import { getDocumentWidth } from "./getDocumentWidth";
export const getDialogPosition = (marker: { pagePositionX: number, pagePositionY: number } | null,
dialogElement: HTMLDialogElement | null): { left: number, top: number } => {
// Default position (fallback)
let left = 0;
let top = 0;
if (!marker || !dialogElement) return { left, top };
// Get marker position
left = marker.pagePositionX;
top = marker.pagePositionY;
// Get dialog dimensions
const dialogWidth = dialogElement.offsetWidth;
const dialogHeight = dialogElement.offsetHeight;
// Get document dimensions
const documentWidth = getDocumentWidth();
const documentHeight = getDocumentHeight();
// Ensure dialog doesn't go off-screen to the right
if (left + dialogWidth > documentWidth) {
left = documentWidth - dialogWidth;
}
// Ensure dialog doesn't go off-screen to the bottom
if (top + dialogHeight > documentHeight) {
top = documentHeight - dialogHeight;
}
// Ensure dialog doesn't go off-screen to the left or top
left = Math.max(0, left);
top = Math.max(0, top);
return { left, top };
}