UNPKG

@zag-js/popper

Version:

Dynamic positioning logic for ui machines

67 lines (65 loc) 2.14 kB
"use strict"; 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/get-anchor.ts var get_anchor_exports = {}; __export(get_anchor_exports, { createDOMRect: () => createDOMRect, getAnchorElement: () => getAnchorElement }); module.exports = __toCommonJS(get_anchor_exports); var import_dom_query = require("@zag-js/dom-query"); function createDOMRect(x = 0, y = 0, width = 0, height = 0) { if (typeof DOMRect === "function") { return new DOMRect(x, y, width, height); } const rect = { x, y, width, height, top: y, right: x + width, bottom: y + height, left: x }; return { ...rect, toJSON: () => rect }; } function getDOMRect(anchorRect) { if (!anchorRect) return createDOMRect(); const { x, y, width, height } = anchorRect; return createDOMRect(x, y, width, height); } function getAnchorElement(anchorElement, getAnchorRect) { return { contextElement: (0, import_dom_query.isHTMLElement)(anchorElement) ? anchorElement : anchorElement?.contextElement, getBoundingClientRect: () => { const anchor = anchorElement; const anchorRect = getAnchorRect?.(anchor); if (anchorRect || !anchor) { return getDOMRect(anchorRect); } return anchor.getBoundingClientRect(); } }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createDOMRect, getAnchorElement });