@zag-js/dom-query
Version:
The dom helper library for zag.js machines
46 lines (44 loc) • 1.88 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/point.ts
var point_exports = {};
__export(point_exports, {
getRelativePoint: () => getRelativePoint
});
module.exports = __toCommonJS(point_exports);
var import_shared = require("./shared.js");
function getRelativePoint(point, element) {
const { left, top, width, height } = element.getBoundingClientRect();
const offset = { x: point.x - left, y: point.y - top };
const percent = { x: (0, import_shared.clamp)(offset.x / width), y: (0, import_shared.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 };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getRelativePoint
});