UNPKG

vuesax-alpha

Version:
42 lines (39 loc) 1.72 kB
import { getSide, getAlignment, getSideAxis, evaluate } from '../../utils/index.mjs'; 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 = getSide(placement); const alignment = getAlignment(placement); const isVertical = getSideAxis(placement) === "y"; const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1; const crossAxisMulti = rtl && isVertical ? -1 : 1; const rawValue = 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 } }; } }); export { convertValueToCoords, offset }; //# sourceMappingURL=offset.mjs.map