@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
47 lines (42 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var index = require('../../utils/index.js');
async function convertValueToCoords(state, options) {
var _a;
const { placement, platform, elements } = state;
const rtl = await ((_a = platform.isRTL) == null ? void 0 : _a.call(platform, elements.floating));
const side = index.getSide(placement);
const alignment = index.getAlignment(placement);
const isVertical = index.getSideAxis(placement) === "y";
const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
const crossAxisMulti = rtl && isVertical ? -1 : 1;
const rawValue = index.evaluate(options, state);
let { mainAxis, crossAxis, alignmentAxis } = typeof rawValue === "number" ? { mainAxis: rawValue, crossAxis: 0, alignmentAxis: null } : { mainAxis: 0, crossAxis: 0, alignmentAxis: null, ...rawValue };
if (alignment && typeof alignmentAxis === "number") {
crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
}
return isVertical ? { x: crossAxis * crossAxisMulti, y: mainAxis * mainAxisMulti } : { x: mainAxis * mainAxisMulti, y: crossAxis * crossAxisMulti };
}
const offset = (options = 0) => ({
name: "offset",
options,
async fn(state) {
var _a, _b;
const { x, y, placement, middlewareData } = state;
const diffCoords = await convertValueToCoords(state, options);
if (placement === ((_a = middlewareData.offset) == null ? void 0 : _a.placement) && ((_b = middlewareData.arrow) == null ? void 0 : _b.alignmentOffset)) {
return {};
}
return {
x: x + diffCoords.x,
y: y + diffCoords.y,
data: {
...diffCoords,
placement
}
};
}
});
exports.convertValueToCoords = convertValueToCoords;
exports.offset = offset;
//# sourceMappingURL=offset.js.map