@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
48 lines (43 loc) • 2.29 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var index = require('../utils/index.js');
async function detectOverflow(state, options = {}) {
var _a, _b, _c, _d, _e, _f;
const { x, y, platform, rects, elements, strategy } = state;
const {
boundary = "clippingAncestors",
rootBoundary = "viewport",
elementContext = "floating",
altBoundary = false,
padding = 0
} = index.evaluate(options, state);
const paddingObject = index.getPaddingObject(padding);
const altContext = elementContext === "floating" ? "reference" : "floating";
const element = elements[altBoundary ? altContext : elementContext];
const clippingClientRect = index.rectToClientRect(
await platform.getClippingRect({
element: ((_b = await ((_a = platform.isElement) == null ? void 0 : _a.call(platform, element))) != null ? _b : true) ? element : element.contextElement || await ((_c = platform.getDocumentElement) == null ? void 0 : _c.call(platform, elements.floating)),
boundary,
rootBoundary,
strategy
})
);
const rect = elementContext === "floating" ? { ...rects.floating, x, y } : rects.reference;
const offsetParent = await ((_d = platform.getOffsetParent) == null ? void 0 : _d.call(platform, elements.floating));
const offsetScale = await ((_e = platform.isElement) == null ? void 0 : _e.call(platform, offsetParent)) ? await ((_f = platform.getScale) == null ? void 0 : _f.call(platform, offsetParent)) || { x: 1, y: 1 } : { x: 1, y: 1 };
const elementClientRect = index.rectToClientRect(
platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
rect,
offsetParent,
strategy
}) : rect
);
return {
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
};
}
exports.detectOverflow = detectOverflow;
//# sourceMappingURL=detect-overflow.js.map