UNPKG

@zag-js/dom-query

Version:

The dom helper library for zag.js machines

23 lines (21 loc) 850 B
import "./chunk-QZ7TP4HQ.mjs"; // src/point.ts import { clamp } from "./shared.mjs"; function getRelativePoint(point, element) { const { left, top, width, height } = element.getBoundingClientRect(); const offset = { x: point.x - left, y: point.y - top }; const percent = { x: clamp(offset.x / width), y: clamp(offset.y / height) }; function getPercentValue(options = {}) { const { dir = "ltr", orientation = "horizontal", inverted } = options; const invertX = typeof inverted === "object" ? inverted.x : inverted; const invertY = typeof inverted === "object" ? inverted.y : inverted; if (orientation === "horizontal") { return dir === "rtl" || invertX ? 1 - percent.x : percent.x; } return invertY ? 1 - percent.y : percent.y; } return { offset, percent, getPercentValue }; } export { getRelativePoint };