Socket
Socket
Sign inDemoInstall

@floating-ui/core

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@floating-ui/core - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

src/computeCoordsFromPlacement.d.mts

211

dist/floating-ui.core.esm.js

@@ -1,17 +0,4 @@

function getAlignment(placement) {
return placement.split('-')[1];
}
import { getSideAxis, getAlignmentAxis, getAxisLength, getSide, getAlignment, evaluate, getPaddingObject, rectToClientRect, min, clamp, placements, getAlignmentSides, getOppositeAlignmentPlacement, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, sides, max, getOppositeAxis } from '@floating-ui/utils';
export { rectToClientRect } from '@floating-ui/utils';
function getLengthFromAxis(axis) {
return axis === 'y' ? 'height' : 'width';
}
function getSide(placement) {
return placement.split('-')[0];
}
function getMainAxisFromPlacement(placement) {
return ['top', 'bottom'].includes(getSide(placement)) ? 'x' : 'y';
}
function computeCoordsFromPlacement(_ref, placement, rtl) {

@@ -22,9 +9,10 @@ let {

} = _ref;
const sideAxis = getSideAxis(placement);
const alignmentAxis = getAlignmentAxis(placement);
const alignLength = getAxisLength(alignmentAxis);
const side = getSide(placement);
const isVertical = sideAxis === 'y';
const commonX = reference.x + reference.width / 2 - floating.width / 2;
const commonY = reference.y + reference.height / 2 - floating.height / 2;
const mainAxis = getMainAxisFromPlacement(placement);
const length = getLengthFromAxis(mainAxis);
const commonAlign = reference[length] / 2 - floating[length] / 2;
const side = getSide(placement);
const isVertical = mainAxis === 'x';
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
let coords;

@@ -64,6 +52,6 @@ switch (side) {

case 'start':
coords[mainAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
break;
case 'end':
coords[mainAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
break;

@@ -166,35 +154,2 @@ }

function evaluate(value, param) {
return typeof value === 'function' ? value(param) : value;
}
function expandPaddingObject(padding) {
return {
top: 0,
right: 0,
bottom: 0,
left: 0,
...padding
};
}
function getSideObjectFromPadding(padding) {
return typeof padding !== 'number' ? expandPaddingObject(padding) : {
top: padding,
right: padding,
bottom: padding,
left: padding
};
}
function rectToClientRect(rect) {
return {
...rect,
top: rect.y,
left: rect.x,
right: rect.x + rect.width,
bottom: rect.y + rect.height
};
}
/**

@@ -228,3 +183,3 @@ * Resolves with an object of overflow side offsets that determine how much the

} = evaluate(options, state);
const paddingObject = getSideObjectFromPadding(padding);
const paddingObject = getPaddingObject(padding);
const altContext = elementContext === 'floating' ? 'reference' : 'floating';

@@ -264,9 +219,2 @@ const element = elements[altBoundary ? altContext : elementContext];

const min = Math.min;
const max = Math.max;
function within(min$1, value, max$1) {
return max(min$1, min(value, max$1));
}
/**

@@ -297,3 +245,3 @@ * Provides data to position an inner element of the floating element so that it

}
const paddingObject = getSideObjectFromPadding(padding);
const paddingObject = getPaddingObject(padding);
const coords = {

@@ -303,4 +251,4 @@ x,

};
const axis = getMainAxisFromPlacement(placement);
const length = getLengthFromAxis(axis);
const axis = getAlignmentAxis(placement);
const length = getAxisLength(axis);
const arrowDimensions = await platform.getDimensions(element);

@@ -333,3 +281,3 @@ const isYAxis = axis === 'y';

const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
const offset = within(min$1, center, max);
const offset = clamp(min$1, center, max);

@@ -352,40 +300,2 @@ // If the reference is small enough that the arrow's padding causes it to

const sides = ['top', 'right', 'bottom', 'left'];
const allPlacements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + "-start", side + "-end"), []);
const oppositeSideMap = {
left: 'right',
right: 'left',
bottom: 'top',
top: 'bottom'
};
function getOppositePlacement(placement) {
return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
}
function getAlignmentSides(placement, rects, rtl) {
if (rtl === void 0) {
rtl = false;
}
const alignment = getAlignment(placement);
const mainAxis = getMainAxisFromPlacement(placement);
const length = getLengthFromAxis(mainAxis);
let mainAlignmentSide = mainAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
if (rects.reference[length] > rects.floating[length]) {
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
}
return {
main: mainAlignmentSide,
cross: getOppositePlacement(mainAlignmentSide)
};
}
const oppositeAlignmentMap = {
start: 'end',
end: 'start'
};
function getOppositeAlignmentPlacement(placement) {
return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
}
function getPlacementList(alignment, autoAlignment, allowedPlacements) {

@@ -425,17 +335,14 @@ const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);

alignment,
allowedPlacements = allPlacements,
allowedPlacements = placements,
autoAlignment = true,
...detectOverflowOptions
} = evaluate(options, state);
const placements = alignment !== undefined || allowedPlacements === allPlacements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
const overflow = await detectOverflow(state, detectOverflowOptions);
const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
const currentPlacement = placements[currentIndex];
const currentPlacement = placements$1[currentIndex];
if (currentPlacement == null) {
return {};
}
const {
main,
cross
} = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));

@@ -446,7 +353,7 @@ // Make `computeCoords` start from the right place.

reset: {
placement: placements[0]
placement: placements$1[0]
}
};
}
const currentOverflows = [overflow[getSide(currentPlacement)], overflow[main], overflow[cross]];
const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
const allOverflows = [...(((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || []), {

@@ -456,3 +363,3 @@ placement: currentPlacement,

}];
const nextPlacement = placements[currentIndex + 1];
const nextPlacement = placements$1[currentIndex + 1];

@@ -500,36 +407,2 @@ // There are more placements to check.

function getExpandedPlacements(placement) {
const oppositePlacement = getOppositePlacement(placement);
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
}
function getSideList(side, isStart, rtl) {
const lr = ['left', 'right'];
const rl = ['right', 'left'];
const tb = ['top', 'bottom'];
const bt = ['bottom', 'top'];
switch (side) {
case 'top':
case 'bottom':
if (rtl) return isStart ? rl : lr;
return isStart ? lr : rl;
case 'left':
case 'right':
return isStart ? tb : bt;
default:
return [];
}
}
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
const alignment = getAlignment(placement);
let list = getSideList(getSide(placement), direction === 'start', rtl);
if (alignment) {
list = list.map(side => side + "-" + alignment);
if (flipAlignment) {
list = list.concat(list.map(getOppositeAlignmentPlacement));
}
}
return list;
}
/**

@@ -582,7 +455,4 @@ * Optimizes the visibility of the floating element by flipping the `placement`

if (checkCrossAxis) {
const {
main,
cross
} = getAlignmentSides(placement, rects, rtl);
overflows.push(overflow[main], overflow[cross]);
const sides = getAlignmentSides(placement, rects, rtl);
overflows.push(overflow[sides[0]], overflow[sides[1]]);
}

@@ -773,3 +643,3 @@ overflowsData = [...overflowsData, {

const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
const paddingObject = getSideObjectFromPadding(padding);
const paddingObject = getPaddingObject(padding);
function getBoundingClientRect() {

@@ -784,3 +654,3 @@ // There are two rects and they are disjoined.

if (clientRects.length >= 2) {
if (getMainAxisFromPlacement(placement) === 'x') {
if (getSideAxis(placement) === 'y') {
const firstRect = clientRects[0];

@@ -848,2 +718,4 @@ const lastRect = clientRects[clientRects.length - 1];

// For type backwards-compatibility, the `OffsetOptions` type was also
// Derivable.
async function convertValueToCoords(state, options) {

@@ -858,3 +730,3 @@ const {

const alignment = getAlignment(placement);
const isVertical = getMainAxisFromPlacement(placement) === 'x';
const isVertical = getSideAxis(placement) === 'y';
const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;

@@ -920,6 +792,2 @@ const crossAxisMulti = rtl && isVertical ? -1 : 1;

function getCrossAxis(axis) {
return axis === 'x' ? 'y' : 'x';
}
/**

@@ -965,4 +833,4 @@ * Optimizes the visibility of the floating element by shifting it in order to

const overflow = await detectOverflow(state, detectOverflowOptions);
const mainAxis = getMainAxisFromPlacement(getSide(placement));
const crossAxis = getCrossAxis(mainAxis);
const crossAxis = getSideAxis(getSide(placement));
const mainAxis = getOppositeAxis(crossAxis);
let mainAxisCoord = coords[mainAxis];

@@ -975,3 +843,3 @@ let crossAxisCoord = coords[crossAxis];

const max = mainAxisCoord - overflow[maxSide];
mainAxisCoord = within(min, mainAxisCoord, max);
mainAxisCoord = clamp(min, mainAxisCoord, max);
}

@@ -983,3 +851,3 @@ if (checkCrossAxis) {

const max = crossAxisCoord - overflow[maxSide];
crossAxisCoord = within(min, crossAxisCoord, max);
crossAxisCoord = clamp(min, crossAxisCoord, max);
}

@@ -1027,4 +895,4 @@ const limitedCoords = limiter.fn({

};
const mainAxis = getMainAxisFromPlacement(placement);
const crossAxis = getCrossAxis(mainAxis);
const crossAxis = getSideAxis(placement);
const mainAxis = getOppositeAxis(crossAxis);
let mainAxisCoord = coords[mainAxis];

@@ -1098,4 +966,3 @@ let crossAxisCoord = coords[crossAxis];

const alignment = getAlignment(placement);
const axis = getMainAxisFromPlacement(placement);
const isXAxis = axis === 'x';
const isYAxis = getSideAxis(placement) === 'y';
const {

@@ -1119,3 +986,3 @@ width,

let availableWidth = overflowAvailableWidth;
if (isXAxis) {
if (isYAxis) {
const maximumClippingWidth = width - overflow.left - overflow.right;

@@ -1132,3 +999,3 @@ availableWidth = alignment || noShift ? min(overflowAvailableWidth, maximumClippingWidth) : maximumClippingWidth;

const yMax = max(overflow.bottom, 0);
if (isXAxis) {
if (isYAxis) {
availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));

@@ -1157,2 +1024,2 @@ } else {

export { arrow, autoPlacement, computePosition, detectOverflow, flip, hide, inline, limitShift, offset, rectToClientRect, shift, size };
export { arrow, autoPlacement, computePosition, detectOverflow, flip, hide, inline, limitShift, offset, shift, size };

@@ -7,17 +7,118 @@ (function (global, factory) {

const sides = ['top', 'right', 'bottom', 'left'];
const alignments = ['start', 'end'];
const placements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + "-" + alignments[0], side + "-" + alignments[1]), []);
const min = Math.min;
const max = Math.max;
const oppositeSideMap = {
left: 'right',
right: 'left',
bottom: 'top',
top: 'bottom'
};
const oppositeAlignmentMap = {
start: 'end',
end: 'start'
};
function clamp(start, value, end) {
return max(start, min(value, end));
}
function evaluate(value, param) {
return typeof value === 'function' ? value(param) : value;
}
function getSide(placement) {
return placement.split('-')[0];
}
function getAlignment(placement) {
return placement.split('-')[1];
}
function getLengthFromAxis(axis) {
function getOppositeAxis(axis) {
return axis === 'x' ? 'y' : 'x';
}
function getAxisLength(axis) {
return axis === 'y' ? 'height' : 'width';
}
function getSide(placement) {
return placement.split('-')[0];
function getSideAxis(placement) {
return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
}
function getMainAxisFromPlacement(placement) {
return ['top', 'bottom'].includes(getSide(placement)) ? 'x' : 'y';
function getAlignmentAxis(placement) {
return getOppositeAxis(getSideAxis(placement));
}
function getAlignmentSides(placement, rects, rtl) {
if (rtl === void 0) {
rtl = false;
}
const alignment = getAlignment(placement);
const alignmentAxis = getAlignmentAxis(placement);
const length = getAxisLength(alignmentAxis);
let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
if (rects.reference[length] > rects.floating[length]) {
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
}
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
}
function getExpandedPlacements(placement) {
const oppositePlacement = getOppositePlacement(placement);
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
}
function getOppositeAlignmentPlacement(placement) {
return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
}
function getSideList(side, isStart, rtl) {
const lr = ['left', 'right'];
const rl = ['right', 'left'];
const tb = ['top', 'bottom'];
const bt = ['bottom', 'top'];
switch (side) {
case 'top':
case 'bottom':
if (rtl) return isStart ? rl : lr;
return isStart ? lr : rl;
case 'left':
case 'right':
return isStart ? tb : bt;
default:
return [];
}
}
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
const alignment = getAlignment(placement);
let list = getSideList(getSide(placement), direction === 'start', rtl);
if (alignment) {
list = list.map(side => side + "-" + alignment);
if (flipAlignment) {
list = list.concat(list.map(getOppositeAlignmentPlacement));
}
}
return list;
}
function getOppositePlacement(placement) {
return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
}
function expandPaddingObject(padding) {
return {
top: 0,
right: 0,
bottom: 0,
left: 0,
...padding
};
}
function getPaddingObject(padding) {
return typeof padding !== 'number' ? expandPaddingObject(padding) : {
top: padding,
right: padding,
bottom: padding,
left: padding
};
}
function rectToClientRect(rect) {
return {
...rect,
top: rect.y,
left: rect.x,
right: rect.x + rect.width,
bottom: rect.y + rect.height
};
}

@@ -29,9 +130,10 @@ function computeCoordsFromPlacement(_ref, placement, rtl) {

} = _ref;
const sideAxis = getSideAxis(placement);
const alignmentAxis = getAlignmentAxis(placement);
const alignLength = getAxisLength(alignmentAxis);
const side = getSide(placement);
const isVertical = sideAxis === 'y';
const commonX = reference.x + reference.width / 2 - floating.width / 2;
const commonY = reference.y + reference.height / 2 - floating.height / 2;
const mainAxis = getMainAxisFromPlacement(placement);
const length = getLengthFromAxis(mainAxis);
const commonAlign = reference[length] / 2 - floating[length] / 2;
const side = getSide(placement);
const isVertical = mainAxis === 'x';
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
let coords;

@@ -71,6 +173,6 @@ switch (side) {

case 'start':
coords[mainAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
break;
case 'end':
coords[mainAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
break;

@@ -173,35 +275,2 @@ }

function evaluate(value, param) {
return typeof value === 'function' ? value(param) : value;
}
function expandPaddingObject(padding) {
return {
top: 0,
right: 0,
bottom: 0,
left: 0,
...padding
};
}
function getSideObjectFromPadding(padding) {
return typeof padding !== 'number' ? expandPaddingObject(padding) : {
top: padding,
right: padding,
bottom: padding,
left: padding
};
}
function rectToClientRect(rect) {
return {
...rect,
top: rect.y,
left: rect.x,
right: rect.x + rect.width,
bottom: rect.y + rect.height
};
}
/**

@@ -235,3 +304,3 @@ * Resolves with an object of overflow side offsets that determine how much the

} = evaluate(options, state);
const paddingObject = getSideObjectFromPadding(padding);
const paddingObject = getPaddingObject(padding);
const altContext = elementContext === 'floating' ? 'reference' : 'floating';

@@ -271,9 +340,2 @@ const element = elements[altBoundary ? altContext : elementContext];

const min = Math.min;
const max = Math.max;
function within(min$1, value, max$1) {
return max(min$1, min(value, max$1));
}
/**

@@ -304,3 +366,3 @@ * Provides data to position an inner element of the floating element so that it

}
const paddingObject = getSideObjectFromPadding(padding);
const paddingObject = getPaddingObject(padding);
const coords = {

@@ -310,4 +372,4 @@ x,

};
const axis = getMainAxisFromPlacement(placement);
const length = getLengthFromAxis(axis);
const axis = getAlignmentAxis(placement);
const length = getAxisLength(axis);
const arrowDimensions = await platform.getDimensions(element);

@@ -340,3 +402,3 @@ const isYAxis = axis === 'y';

const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
const offset = within(min$1, center, max);
const offset = clamp(min$1, center, max);

@@ -359,40 +421,2 @@ // If the reference is small enough that the arrow's padding causes it to

const sides = ['top', 'right', 'bottom', 'left'];
const allPlacements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + "-start", side + "-end"), []);
const oppositeSideMap = {
left: 'right',
right: 'left',
bottom: 'top',
top: 'bottom'
};
function getOppositePlacement(placement) {
return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
}
function getAlignmentSides(placement, rects, rtl) {
if (rtl === void 0) {
rtl = false;
}
const alignment = getAlignment(placement);
const mainAxis = getMainAxisFromPlacement(placement);
const length = getLengthFromAxis(mainAxis);
let mainAlignmentSide = mainAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
if (rects.reference[length] > rects.floating[length]) {
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
}
return {
main: mainAlignmentSide,
cross: getOppositePlacement(mainAlignmentSide)
};
}
const oppositeAlignmentMap = {
start: 'end',
end: 'start'
};
function getOppositeAlignmentPlacement(placement) {
return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
}
function getPlacementList(alignment, autoAlignment, allowedPlacements) {

@@ -432,17 +456,14 @@ const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);

alignment,
allowedPlacements = allPlacements,
allowedPlacements = placements,
autoAlignment = true,
...detectOverflowOptions
} = evaluate(options, state);
const placements = alignment !== undefined || allowedPlacements === allPlacements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
const overflow = await detectOverflow(state, detectOverflowOptions);
const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
const currentPlacement = placements[currentIndex];
const currentPlacement = placements$1[currentIndex];
if (currentPlacement == null) {
return {};
}
const {
main,
cross
} = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));

@@ -453,7 +474,7 @@ // Make `computeCoords` start from the right place.

reset: {
placement: placements[0]
placement: placements$1[0]
}
};
}
const currentOverflows = [overflow[getSide(currentPlacement)], overflow[main], overflow[cross]];
const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
const allOverflows = [...(((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || []), {

@@ -463,3 +484,3 @@ placement: currentPlacement,

}];
const nextPlacement = placements[currentIndex + 1];
const nextPlacement = placements$1[currentIndex + 1];

@@ -507,36 +528,2 @@ // There are more placements to check.

function getExpandedPlacements(placement) {
const oppositePlacement = getOppositePlacement(placement);
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
}
function getSideList(side, isStart, rtl) {
const lr = ['left', 'right'];
const rl = ['right', 'left'];
const tb = ['top', 'bottom'];
const bt = ['bottom', 'top'];
switch (side) {
case 'top':
case 'bottom':
if (rtl) return isStart ? rl : lr;
return isStart ? lr : rl;
case 'left':
case 'right':
return isStart ? tb : bt;
default:
return [];
}
}
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
const alignment = getAlignment(placement);
let list = getSideList(getSide(placement), direction === 'start', rtl);
if (alignment) {
list = list.map(side => side + "-" + alignment);
if (flipAlignment) {
list = list.concat(list.map(getOppositeAlignmentPlacement));
}
}
return list;
}
/**

@@ -589,7 +576,4 @@ * Optimizes the visibility of the floating element by flipping the `placement`

if (checkCrossAxis) {
const {
main,
cross
} = getAlignmentSides(placement, rects, rtl);
overflows.push(overflow[main], overflow[cross]);
const sides = getAlignmentSides(placement, rects, rtl);
overflows.push(overflow[sides[0]], overflow[sides[1]]);
}

@@ -780,3 +764,3 @@ overflowsData = [...overflowsData, {

const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
const paddingObject = getSideObjectFromPadding(padding);
const paddingObject = getPaddingObject(padding);
function getBoundingClientRect() {

@@ -791,3 +775,3 @@ // There are two rects and they are disjoined.

if (clientRects.length >= 2) {
if (getMainAxisFromPlacement(placement) === 'x') {
if (getSideAxis(placement) === 'y') {
const firstRect = clientRects[0];

@@ -855,2 +839,4 @@ const lastRect = clientRects[clientRects.length - 1];

// For type backwards-compatibility, the `OffsetOptions` type was also
// Derivable.
async function convertValueToCoords(state, options) {

@@ -865,3 +851,3 @@ const {

const alignment = getAlignment(placement);
const isVertical = getMainAxisFromPlacement(placement) === 'x';
const isVertical = getSideAxis(placement) === 'y';
const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;

@@ -927,6 +913,2 @@ const crossAxisMulti = rtl && isVertical ? -1 : 1;

function getCrossAxis(axis) {
return axis === 'x' ? 'y' : 'x';
}
/**

@@ -972,4 +954,4 @@ * Optimizes the visibility of the floating element by shifting it in order to

const overflow = await detectOverflow(state, detectOverflowOptions);
const mainAxis = getMainAxisFromPlacement(getSide(placement));
const crossAxis = getCrossAxis(mainAxis);
const crossAxis = getSideAxis(getSide(placement));
const mainAxis = getOppositeAxis(crossAxis);
let mainAxisCoord = coords[mainAxis];

@@ -982,3 +964,3 @@ let crossAxisCoord = coords[crossAxis];

const max = mainAxisCoord - overflow[maxSide];
mainAxisCoord = within(min, mainAxisCoord, max);
mainAxisCoord = clamp(min, mainAxisCoord, max);
}

@@ -990,3 +972,3 @@ if (checkCrossAxis) {

const max = crossAxisCoord - overflow[maxSide];
crossAxisCoord = within(min, crossAxisCoord, max);
crossAxisCoord = clamp(min, crossAxisCoord, max);
}

@@ -1034,4 +1016,4 @@ const limitedCoords = limiter.fn({

};
const mainAxis = getMainAxisFromPlacement(placement);
const crossAxis = getCrossAxis(mainAxis);
const crossAxis = getSideAxis(placement);
const mainAxis = getOppositeAxis(crossAxis);
let mainAxisCoord = coords[mainAxis];

@@ -1105,4 +1087,3 @@ let crossAxisCoord = coords[crossAxis];

const alignment = getAlignment(placement);
const axis = getMainAxisFromPlacement(placement);
const isXAxis = axis === 'x';
const isYAxis = getSideAxis(placement) === 'y';
const {

@@ -1126,3 +1107,3 @@ width,

let availableWidth = overflowAvailableWidth;
if (isXAxis) {
if (isYAxis) {
const maximumClippingWidth = width - overflow.left - overflow.right;

@@ -1139,3 +1120,3 @@ availableWidth = alignment || noShift ? min(overflowAvailableWidth, maximumClippingWidth) : maximumClippingWidth;

const yMax = max(overflow.bottom, 0);
if (isXAxis) {
if (isYAxis) {
availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));

@@ -1177,4 +1158,2 @@ } else {

Object.defineProperty(exports, '__esModule', { value: true });
}));

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).FloatingUICore={})}(this,(function(t){"use strict";function e(t){return t.split("-")[1]}function n(t){return"y"===t?"height":"width"}function o(t){return t.split("-")[0]}function i(t){return["top","bottom"].includes(o(t))?"x":"y"}function r(t,r,a){let{reference:l,floating:s}=t;const c=l.x+l.width/2-s.width/2,f=l.y+l.height/2-s.height/2,u=i(r),m=n(u),d=l[m]/2-s[m]/2,g="x"===u;let p;switch(o(r)){case"top":p={x:c,y:l.y-s.height};break;case"bottom":p={x:c,y:l.y+l.height};break;case"right":p={x:l.x+l.width,y:f};break;case"left":p={x:l.x-s.width,y:f};break;default:p={x:l.x,y:l.y}}switch(e(r)){case"start":p[u]-=d*(a&&g?-1:1);break;case"end":p[u]+=d*(a&&g?-1:1)}return p}function a(t,e){return"function"==typeof t?t(e):t}function l(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}function s(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}async function c(t,e){var n;void 0===e&&(e={});const{x:o,y:i,platform:r,rects:c,elements:f,strategy:u}=t,{boundary:m="clippingAncestors",rootBoundary:d="viewport",elementContext:g="floating",altBoundary:p=!1,padding:h=0}=a(e,t),y=l(h),x=f[p?"floating"===g?"reference":"floating":g],w=s(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(x)))||n?x:x.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(f.floating)),boundary:m,rootBoundary:d,strategy:u})),v="floating"===g?{...c.floating,x:o,y:i}:c.reference,b=await(null==r.getOffsetParent?void 0:r.getOffsetParent(f.floating)),A=await(null==r.isElement?void 0:r.isElement(b))&&await(null==r.getScale?void 0:r.getScale(b))||{x:1,y:1},R=s(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({rect:v,offsetParent:b,strategy:u}):v);return{top:(w.top-R.top+y.top)/A.y,bottom:(R.bottom-w.bottom+y.bottom)/A.y,left:(w.left-R.left+y.left)/A.x,right:(R.right-w.right+y.right)/A.x}}const f=Math.min,u=Math.max;function m(t,e,n){return u(t,f(e,n))}const d=["top","right","bottom","left"],g=d.reduce(((t,e)=>t.concat(e,e+"-start",e+"-end")),[]),p={left:"right",right:"left",bottom:"top",top:"bottom"};function h(t){return t.replace(/left|right|bottom|top/g,(t=>p[t]))}function y(t,o,r){void 0===r&&(r=!1);const a=e(t),l=i(t),s=n(l);let c="x"===l?a===(r?"end":"start")?"right":"left":"start"===a?"bottom":"top";return o.reference[s]>o.floating[s]&&(c=h(c)),{main:c,cross:h(c)}}const x={start:"end",end:"start"};function w(t){return t.replace(/start|end/g,(t=>x[t]))}function v(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function b(t){return d.some((e=>t[e]>=0))}function A(t){const e=f(...t.map((t=>t.left))),n=f(...t.map((t=>t.top)));return{x:e,y:n,width:u(...t.map((t=>t.right)))-e,height:u(...t.map((t=>t.bottom)))-n}}function R(t){return"x"===t?"y":"x"}t.arrow=t=>({name:"arrow",options:t,async fn(o){const{x:r,y:s,placement:c,rects:u,platform:d,elements:g}=o,{element:p,padding:h=0}=a(t,o)||{};if(null==p)return{};const y=l(h),x={x:r,y:s},w=i(c),v=n(w),b=await d.getDimensions(p),A="y"===w,R=A?"top":"left",P=A?"bottom":"right",T=A?"clientHeight":"clientWidth",E=u.reference[v]+u.reference[w]-x[w]-u.floating[v],D=x[w]-u.reference[w],O=await(null==d.getOffsetParent?void 0:d.getOffsetParent(p));let L=O?O[T]:0;L&&await(null==d.isElement?void 0:d.isElement(O))||(L=g.floating[T]||u.floating[v]);const k=E/2-D/2,C=L/2-b[v]/2-1,B=f(y[R],C),H=f(y[P],C),S=B,j=L-b[v]-H,F=L/2-b[v]/2+k,M=m(S,F,j),z=null!=e(c)&&F!=M&&u.reference[v]/2-(F<S?B:H)-b[v]/2<0?F<S?S-F:j-F:0;return{[w]:x[w]-z,data:{[w]:M,centerOffset:F-M+z}}}}),t.autoPlacement=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(n){var i,r,l;const{rects:s,middlewareData:f,placement:u,platform:m,elements:d}=n,{crossAxis:p=!1,alignment:h,allowedPlacements:x=g,autoAlignment:v=!0,...b}=a(t,n),A=void 0!==h||x===g?function(t,n,i){return(t?[...i.filter((n=>e(n)===t)),...i.filter((n=>e(n)!==t))]:i.filter((t=>o(t)===t))).filter((o=>!t||e(o)===t||!!n&&w(o)!==o))}(h||null,v,x):x,R=await c(n,b),P=(null==(i=f.autoPlacement)?void 0:i.index)||0,T=A[P];if(null==T)return{};const{main:E,cross:D}=y(T,s,await(null==m.isRTL?void 0:m.isRTL(d.floating)));if(u!==T)return{reset:{placement:A[0]}};const O=[R[o(T)],R[E],R[D]],L=[...(null==(r=f.autoPlacement)?void 0:r.overflows)||[],{placement:T,overflows:O}],k=A[P+1];if(k)return{data:{index:P+1,overflows:L},reset:{placement:k}};const C=L.map((t=>{const n=e(t.placement);return[t.placement,n&&p?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),B=(null==(l=C.filter((t=>t[2].slice(0,e(t[0])?2:3).every((t=>t<=0))))[0])?void 0:l[0])||C[0][0];return B!==u?{data:{index:P+1,overflows:L},reset:{placement:B}}:{}}}},t.computePosition=async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:a=[],platform:l}=n,s=a.filter(Boolean),c=await(null==l.isRTL?void 0:l.isRTL(e));let f=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:u,y:m}=r(f,o,c),d=o,g={},p=0;for(let n=0;n<s.length;n++){const{name:a,fn:h}=s[n],{x:y,y:x,data:w,reset:v}=await h({x:u,y:m,initialPlacement:o,placement:d,strategy:i,middlewareData:g,rects:f,platform:l,elements:{reference:t,floating:e}});u=null!=y?y:u,m=null!=x?x:m,g={...g,[a]:{...g[a],...w}},v&&p<=50&&(p++,"object"==typeof v&&(v.placement&&(d=v.placement),v.rects&&(f=!0===v.rects?await l.getElementRects({reference:t,floating:e,strategy:i}):v.rects),({x:u,y:m}=r(f,d,c))),n=-1)}return{x:u,y:m,placement:d,strategy:i,middlewareData:g}},t.detectOverflow=c,t.flip=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(n){var i;const{placement:r,middlewareData:l,rects:s,initialPlacement:f,platform:u,elements:m}=n,{mainAxis:d=!0,crossAxis:g=!0,fallbackPlacements:p,fallbackStrategy:x="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:b=!0,...A}=a(t,n),R=o(r),P=o(f)===f,T=await(null==u.isRTL?void 0:u.isRTL(m.floating)),E=p||(P||!b?[h(f)]:function(t){const e=h(t);return[w(t),e,w(e)]}(f));p||"none"===v||E.push(...function(t,n,i,r){const a=e(t);let l=function(t,e,n){const o=["left","right"],i=["right","left"],r=["top","bottom"],a=["bottom","top"];switch(t){case"top":case"bottom":return n?e?i:o:e?o:i;case"left":case"right":return e?r:a;default:return[]}}(o(t),"start"===i,r);return a&&(l=l.map((t=>t+"-"+a)),n&&(l=l.concat(l.map(w)))),l}(f,b,v,T));const D=[f,...E],O=await c(n,A),L=[];let k=(null==(i=l.flip)?void 0:i.overflows)||[];if(d&&L.push(O[R]),g){const{main:t,cross:e}=y(r,s,T);L.push(O[t],O[e])}if(k=[...k,{placement:r,overflows:L}],!L.every((t=>t<=0))){var C,B;const t=((null==(C=l.flip)?void 0:C.index)||0)+1,e=D[t];if(e)return{data:{index:t,overflows:k},reset:{placement:e}};let n=null==(B=k.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:B.placement;if(!n)switch(x){case"bestFit":{var H;const t=null==(H=k.map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:H[0];t&&(n=t);break}case"initialPlacement":n=f}if(r!==n)return{reset:{placement:n}}}return{}}}},t.hide=function(t){return void 0===t&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:o="referenceHidden",...i}=a(t,e);switch(o){case"referenceHidden":{const t=v(await c(e,{...i,elementContext:"reference"}),n.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:b(t)}}}case"escaped":{const t=v(await c(e,{...i,altBoundary:!0}),n.floating);return{data:{escapedOffsets:t,escaped:b(t)}}}default:return{}}}}},t.inline=function(t){return void 0===t&&(t={}),{name:"inline",options:t,async fn(e){const{placement:n,elements:r,rects:c,platform:m,strategy:d}=e,{padding:g=2,x:p,y:h}=a(t,e),y=Array.from(await(null==m.getClientRects?void 0:m.getClientRects(r.reference))||[]),x=function(t){const e=t.slice().sort(((t,e)=>t.y-e.y)),n=[];let o=null;for(let t=0;t<e.length;t++){const i=e[t];!o||i.y-o.y>o.height/2?n.push([i]):n[n.length-1].push(i),o=i}return n.map((t=>s(A(t))))}(y),w=s(A(y)),v=l(g);const b=await m.getElementRects({reference:{getBoundingClientRect:function(){if(2===x.length&&x[0].left>x[1].right&&null!=p&&null!=h)return x.find((t=>p>t.left-v.left&&p<t.right+v.right&&h>t.top-v.top&&h<t.bottom+v.bottom))||w;if(x.length>=2){if("x"===i(n)){const t=x[0],e=x[x.length-1],i="top"===o(n),r=t.top,a=e.bottom,l=i?t.left:e.left,s=i?t.right:e.right;return{top:r,bottom:a,left:l,right:s,width:s-l,height:a-r,x:l,y:r}}const t="left"===o(n),e=u(...x.map((t=>t.right))),r=f(...x.map((t=>t.left))),a=x.filter((n=>t?n.left===r:n.right===e)),l=a[0].top,s=a[a.length-1].bottom;return{top:l,bottom:s,left:r,right:e,width:e-r,height:s-l,x:r,y:l}}return w}},floating:r.floating,strategy:d});return c.reference.x!==b.reference.x||c.reference.y!==b.reference.y||c.reference.width!==b.reference.width||c.reference.height!==b.reference.height?{reset:{rects:b}}:{}}}},t.limitShift=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:n,y:r,placement:l,rects:s,middlewareData:c}=e,{offset:f=0,mainAxis:u=!0,crossAxis:m=!0}=a(t,e),d={x:n,y:r},g=i(l),p=R(g);let h=d[g],y=d[p];const x=a(f,e),w="number"==typeof x?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(u){const t="y"===g?"height":"width",e=s.reference[g]-s.floating[t]+w.mainAxis,n=s.reference[g]+s.reference[t]-w.mainAxis;h<e?h=e:h>n&&(h=n)}if(m){var v,b;const t="y"===g?"width":"height",e=["top","left"].includes(o(l)),n=s.reference[p]-s.floating[t]+(e&&(null==(v=c.offset)?void 0:v[p])||0)+(e?0:w.crossAxis),i=s.reference[p]+s.reference[t]+(e?0:(null==(b=c.offset)?void 0:b[p])||0)-(e?w.crossAxis:0);y<n?y=n:y>i&&(y=i)}return{[g]:h,[p]:y}}}},t.offset=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(n){const{x:r,y:l}=n,s=await async function(t,n){const{placement:r,platform:l,elements:s}=t,c=await(null==l.isRTL?void 0:l.isRTL(s.floating)),f=o(r),u=e(r),m="x"===i(r),d=["left","top"].includes(f)?-1:1,g=c&&m?-1:1,p=a(n,t);let{mainAxis:h,crossAxis:y,alignmentAxis:x}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...p};return u&&"number"==typeof x&&(y="end"===u?-1*x:x),m?{x:y*g,y:h*d}:{x:h*d,y:y*g}}(n,t);return{x:r+s.x,y:l+s.y,data:s}}}},t.rectToClientRect=s,t.shift=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:l}=e,{mainAxis:s=!0,crossAxis:f=!1,limiter:u={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...d}=a(t,e),g={x:n,y:r},p=await c(e,d),h=i(o(l)),y=R(h);let x=g[h],w=g[y];if(s){const t="y"===h?"bottom":"right";x=m(x+p["y"===h?"top":"left"],x,x-p[t])}if(f){const t="y"===y?"bottom":"right";w=m(w+p["y"===y?"top":"left"],w,w-p[t])}const v=u.fn({...e,[h]:x,[y]:w});return{...v,data:{x:v.x-n,y:v.y-r}}}}},t.size=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(n){const{placement:r,rects:l,platform:s,elements:m}=n,{apply:d=(()=>{}),...g}=a(t,n),p=await c(n,g),h=o(r),y=e(r),x="x"===i(r),{width:w,height:v}=l.floating;let b,A;"top"===h||"bottom"===h?(b=h,A=y===(await(null==s.isRTL?void 0:s.isRTL(m.floating))?"start":"end")?"left":"right"):(A=h,b="end"===y?"top":"bottom");const R=v-p[b],P=w-p[A],T=!n.middlewareData.shift;let E=R,D=P;if(x){const t=w-p.left-p.right;D=y||T?f(P,t):t}else{const t=v-p.top-p.bottom;E=y||T?f(R,t):t}if(T&&!y){const t=u(p.left,0),e=u(p.right,0),n=u(p.top,0),o=u(p.bottom,0);x?D=w-2*(0!==t||0!==e?t+e:u(p.left,p.right)):E=v-2*(0!==n||0!==o?n+o:u(p.top,p.bottom))}await d({...n,availableWidth:D,availableHeight:E});const O=await s.getDimensions(m.floating);return w!==O.width||v!==O.height?{reset:{rects:!0}}:{}}}},Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).FloatingUICore={})}(this,(function(t){"use strict";const e=["top","right","bottom","left"],n=["start","end"],o=e.reduce(((t,e)=>t.concat(e,e+"-"+n[0],e+"-"+n[1])),[]),i=Math.min,r=Math.max,a={left:"right",right:"left",bottom:"top",top:"bottom"},l={start:"end",end:"start"};function s(t,e,n){return r(t,i(e,n))}function f(t,e){return"function"==typeof t?t(e):t}function c(t){return t.split("-")[0]}function u(t){return t.split("-")[1]}function m(t){return"x"===t?"y":"x"}function d(t){return"y"===t?"height":"width"}function g(t){return["top","bottom"].includes(c(t))?"y":"x"}function p(t){return m(g(t))}function h(t,e,n){void 0===n&&(n=!1);const o=u(t),i=p(t),r=d(i);let a="x"===i?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[r]>e.floating[r]&&(a=x(a)),[a,x(a)]}function y(t){return t.replace(/start|end/g,(t=>l[t]))}function x(t){return t.replace(/left|right|bottom|top/g,(t=>a[t]))}function w(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}function v(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}function b(t,e,n){let{reference:o,floating:i}=t;const r=g(e),a=p(e),l=d(a),s=c(e),f="y"===r,m=o.x+o.width/2-i.width/2,h=o.y+o.height/2-i.height/2,y=o[l]/2-i[l]/2;let x;switch(s){case"top":x={x:m,y:o.y-i.height};break;case"bottom":x={x:m,y:o.y+o.height};break;case"right":x={x:o.x+o.width,y:h};break;case"left":x={x:o.x-i.width,y:h};break;default:x={x:o.x,y:o.y}}switch(u(e)){case"start":x[a]-=y*(n&&f?-1:1);break;case"end":x[a]+=y*(n&&f?-1:1)}return x}async function A(t,e){var n;void 0===e&&(e={});const{x:o,y:i,platform:r,rects:a,elements:l,strategy:s}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:m="floating",altBoundary:d=!1,padding:g=0}=f(e,t),p=w(g),h=l[d?"floating"===m?"reference":"floating":m],y=v(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(h)))||n?h:h.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:s})),x="floating"===m?{...a.floating,x:o,y:i}:a.reference,b=await(null==r.getOffsetParent?void 0:r.getOffsetParent(l.floating)),A=await(null==r.isElement?void 0:r.isElement(b))&&await(null==r.getScale?void 0:r.getScale(b))||{x:1,y:1},R=v(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({rect:x,offsetParent:b,strategy:s}):x);return{top:(y.top-R.top+p.top)/A.y,bottom:(R.bottom-y.bottom+p.bottom)/A.y,left:(y.left-R.left+p.left)/A.x,right:(R.right-y.right+p.right)/A.x}}function R(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function P(t){return e.some((e=>t[e]>=0))}function T(t){const e=i(...t.map((t=>t.left))),n=i(...t.map((t=>t.top)));return{x:e,y:n,width:r(...t.map((t=>t.right)))-e,height:r(...t.map((t=>t.bottom)))-n}}t.arrow=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:a,platform:l,elements:c}=e,{element:m,padding:g=0}=f(t,e)||{};if(null==m)return{};const h=w(g),y={x:n,y:o},x=p(r),v=d(x),b=await l.getDimensions(m),A="y"===x,R=A?"top":"left",P=A?"bottom":"right",T=A?"clientHeight":"clientWidth",E=a.reference[v]+a.reference[x]-y[x]-a.floating[v],D=y[x]-a.reference[x],L=await(null==l.getOffsetParent?void 0:l.getOffsetParent(m));let O=L?L[T]:0;O&&await(null==l.isElement?void 0:l.isElement(L))||(O=c.floating[T]||a.floating[v]);const k=E/2-D/2,C=O/2-b[v]/2-1,B=i(h[R],C),H=i(h[P],C),S=B,F=O-b[v]-H,j=O/2-b[v]/2+k,z=s(S,j,F),M=null!=u(r)&&j!=z&&a.reference[v]/2-(j<S?B:H)-b[v]/2<0?j<S?S-j:F-j:0;return{[x]:y[x]-M,data:{[x]:z,centerOffset:j-z+M}}}}),t.autoPlacement=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var n,i,r;const{rects:a,middlewareData:l,placement:s,platform:m,elements:d}=e,{crossAxis:g=!1,alignment:p,allowedPlacements:x=o,autoAlignment:w=!0,...v}=f(t,e),b=void 0!==p||x===o?function(t,e,n){return(t?[...n.filter((e=>u(e)===t)),...n.filter((e=>u(e)!==t))]:n.filter((t=>c(t)===t))).filter((n=>!t||u(n)===t||!!e&&y(n)!==n))}(p||null,w,x):x,R=await A(e,v),P=(null==(n=l.autoPlacement)?void 0:n.index)||0,T=b[P];if(null==T)return{};const E=h(T,a,await(null==m.isRTL?void 0:m.isRTL(d.floating)));if(s!==T)return{reset:{placement:b[0]}};const D=[R[c(T)],R[E[0]],R[E[1]]],L=[...(null==(i=l.autoPlacement)?void 0:i.overflows)||[],{placement:T,overflows:D}],O=b[P+1];if(O)return{data:{index:P+1,overflows:L},reset:{placement:O}};const k=L.map((t=>{const e=u(t.placement);return[t.placement,e&&g?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),C=(null==(r=k.filter((t=>t[2].slice(0,u(t[0])?2:3).every((t=>t<=0))))[0])?void 0:r[0])||k[0][0];return C!==s?{data:{index:P+1,overflows:L},reset:{placement:C}}:{}}}},t.computePosition=async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:a}=n,l=r.filter(Boolean),s=await(null==a.isRTL?void 0:a.isRTL(e));let f=await a.getElementRects({reference:t,floating:e,strategy:i}),{x:c,y:u}=b(f,o,s),m=o,d={},g=0;for(let n=0;n<l.length;n++){const{name:r,fn:p}=l[n],{x:h,y:y,data:x,reset:w}=await p({x:c,y:u,initialPlacement:o,placement:m,strategy:i,middlewareData:d,rects:f,platform:a,elements:{reference:t,floating:e}});c=null!=h?h:c,u=null!=y?y:u,d={...d,[r]:{...d[r],...x}},w&&g<=50&&(g++,"object"==typeof w&&(w.placement&&(m=w.placement),w.rects&&(f=!0===w.rects?await a.getElementRects({reference:t,floating:e,strategy:i}):w.rects),({x:c,y:u}=b(f,m,s))),n=-1)}return{x:c,y:u,placement:m,strategy:i,middlewareData:d}},t.detectOverflow=A,t.flip=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n;const{placement:o,middlewareData:i,rects:r,initialPlacement:a,platform:l,elements:s}=e,{mainAxis:m=!0,crossAxis:d=!0,fallbackPlacements:g,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...b}=f(t,e),R=c(o),P=c(a)===a,T=await(null==l.isRTL?void 0:l.isRTL(s.floating)),E=g||(P||!v?[x(a)]:function(t){const e=x(t);return[y(t),e,y(e)]}(a));g||"none"===w||E.push(...function(t,e,n,o){const i=u(t);let r=function(t,e,n){const o=["left","right"],i=["right","left"],r=["top","bottom"],a=["bottom","top"];switch(t){case"top":case"bottom":return n?e?i:o:e?o:i;case"left":case"right":return e?r:a;default:return[]}}(c(t),"start"===n,o);return i&&(r=r.map((t=>t+"-"+i)),e&&(r=r.concat(r.map(y)))),r}(a,v,w,T));const D=[a,...E],L=await A(e,b),O=[];let k=(null==(n=i.flip)?void 0:n.overflows)||[];if(m&&O.push(L[R]),d){const t=h(o,r,T);O.push(L[t[0]],L[t[1]])}if(k=[...k,{placement:o,overflows:O}],!O.every((t=>t<=0))){var C,B;const t=((null==(C=i.flip)?void 0:C.index)||0)+1,e=D[t];if(e)return{data:{index:t,overflows:k},reset:{placement:e}};let n=null==(B=k.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:B.placement;if(!n)switch(p){case"bestFit":{var H;const t=null==(H=k.map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:H[0];t&&(n=t);break}case"initialPlacement":n=a}if(o!==n)return{reset:{placement:n}}}return{}}}},t.hide=function(t){return void 0===t&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:o="referenceHidden",...i}=f(t,e);switch(o){case"referenceHidden":{const t=R(await A(e,{...i,elementContext:"reference"}),n.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:P(t)}}}case"escaped":{const t=R(await A(e,{...i,altBoundary:!0}),n.floating);return{data:{escapedOffsets:t,escaped:P(t)}}}default:return{}}}}},t.inline=function(t){return void 0===t&&(t={}),{name:"inline",options:t,async fn(e){const{placement:n,elements:o,rects:a,platform:l,strategy:s}=e,{padding:u=2,x:m,y:d}=f(t,e),p=Array.from(await(null==l.getClientRects?void 0:l.getClientRects(o.reference))||[]),h=function(t){const e=t.slice().sort(((t,e)=>t.y-e.y)),n=[];let o=null;for(let t=0;t<e.length;t++){const i=e[t];!o||i.y-o.y>o.height/2?n.push([i]):n[n.length-1].push(i),o=i}return n.map((t=>v(T(t))))}(p),y=v(T(p)),x=w(u);const b=await l.getElementRects({reference:{getBoundingClientRect:function(){if(2===h.length&&h[0].left>h[1].right&&null!=m&&null!=d)return h.find((t=>m>t.left-x.left&&m<t.right+x.right&&d>t.top-x.top&&d<t.bottom+x.bottom))||y;if(h.length>=2){if("y"===g(n)){const t=h[0],e=h[h.length-1],o="top"===c(n),i=t.top,r=e.bottom,a=o?t.left:e.left,l=o?t.right:e.right;return{top:i,bottom:r,left:a,right:l,width:l-a,height:r-i,x:a,y:i}}const t="left"===c(n),e=r(...h.map((t=>t.right))),o=i(...h.map((t=>t.left))),a=h.filter((n=>t?n.left===o:n.right===e)),l=a[0].top,s=a[a.length-1].bottom;return{top:l,bottom:s,left:o,right:e,width:e-o,height:s-l,x:o,y:l}}return y}},floating:o.floating,strategy:s});return a.reference.x!==b.reference.x||a.reference.y!==b.reference.y||a.reference.width!==b.reference.width||a.reference.height!==b.reference.height?{reset:{rects:b}}:{}}}},t.limitShift=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:n,y:o,placement:i,rects:r,middlewareData:a}=e,{offset:l=0,mainAxis:s=!0,crossAxis:u=!0}=f(t,e),d={x:n,y:o},p=g(i),h=m(p);let y=d[h],x=d[p];const w=f(l,e),v="number"==typeof w?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(s){const t="y"===h?"height":"width",e=r.reference[h]-r.floating[t]+v.mainAxis,n=r.reference[h]+r.reference[t]-v.mainAxis;y<e?y=e:y>n&&(y=n)}if(u){var b,A;const t="y"===h?"width":"height",e=["top","left"].includes(c(i)),n=r.reference[p]-r.floating[t]+(e&&(null==(b=a.offset)?void 0:b[p])||0)+(e?0:v.crossAxis),o=r.reference[p]+r.reference[t]+(e?0:(null==(A=a.offset)?void 0:A[p])||0)-(e?v.crossAxis:0);x<n?x=n:x>o&&(x=o)}return{[h]:y,[p]:x}}}},t.offset=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){const{x:n,y:o}=e,i=await async function(t,e){const{placement:n,platform:o,elements:i}=t,r=await(null==o.isRTL?void 0:o.isRTL(i.floating)),a=c(n),l=u(n),s="y"===g(n),m=["left","top"].includes(a)?-1:1,d=r&&s?-1:1,p=f(e,t);let{mainAxis:h,crossAxis:y,alignmentAxis:x}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...p};return l&&"number"==typeof x&&(y="end"===l?-1*x:x),s?{x:y*d,y:h*m}:{x:h*m,y:y*d}}(e,t);return{x:n+i.x,y:o+i.y,data:i}}}},t.rectToClientRect=v,t.shift=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:o,placement:i}=e,{mainAxis:r=!0,crossAxis:a=!1,limiter:l={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...u}=f(t,e),d={x:n,y:o},p=await A(e,u),h=g(c(i)),y=m(h);let x=d[y],w=d[h];if(r){const t="y"===y?"bottom":"right";x=s(x+p["y"===y?"top":"left"],x,x-p[t])}if(a){const t="y"===h?"bottom":"right";w=s(w+p["y"===h?"top":"left"],w,w-p[t])}const v=l.fn({...e,[y]:x,[h]:w});return{...v,data:{x:v.x-n,y:v.y-o}}}}},t.size=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(e){const{placement:n,rects:o,platform:a,elements:l}=e,{apply:s=(()=>{}),...m}=f(t,e),d=await A(e,m),p=c(n),h=u(n),y="y"===g(n),{width:x,height:w}=o.floating;let v,b;"top"===p||"bottom"===p?(v=p,b=h===(await(null==a.isRTL?void 0:a.isRTL(l.floating))?"start":"end")?"left":"right"):(b=p,v="end"===h?"top":"bottom");const R=w-d[v],P=x-d[b],T=!e.middlewareData.shift;let E=R,D=P;if(y){const t=x-d.left-d.right;D=h||T?i(P,t):t}else{const t=w-d.top-d.bottom;E=h||T?i(R,t):t}if(T&&!h){const t=r(d.left,0),e=r(d.right,0),n=r(d.top,0),o=r(d.bottom,0);y?D=x-2*(0!==t||0!==e?t+e:r(d.left,d.right)):E=w-2*(0!==n||0!==o?n+o:r(d.top,d.bottom))}await s({...e,availableWidth:D,availableHeight:E});const L=await a.getDimensions(l.floating);return x!==L.width||w!==L.height?{reset:{rects:!0}}:{}}}}}));
{
"name": "@floating-ui/core",
"version": "1.3.1",
"version": "1.4.0",
"@rollingversions": {

@@ -18,17 +18,14 @@ "baseVersion": [

"unpkg": "./dist/floating-ui.core.umd.min.js",
"types": "./index.d.ts",
"types": "./src/types.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./index.d.ts",
"import": {
"browser": {
"development": "./dist/floating-ui.core.browser.mjs",
"default": "./dist/floating-ui.core.browser.min.mjs"
},
"types": "./src/types.d.mts",
"default": "./dist/floating-ui.core.mjs"
},
"types": "./src/types.d.ts",
"module": "./dist/floating-ui.core.esm.js",
"default": "./dist/floating-ui.core.umd.js"
},
"./package.json": "./package.json"
}
},

@@ -38,7 +35,7 @@ "sideEffects": false,

"dist/",
"index.d.ts",
"src/**/*.d.ts"
"**/*.d.ts",
"**/*.d.mts"
],
"scripts": {
"test": "jest test",
"test": "vitest --globals",
"dev": "rollup -c -w",

@@ -63,3 +60,6 @@ "build": "NODE_ENV=build rollup -c"

"positioning"
]
],
"dependencies": {
"@floating-ui/utils": "^0.1.0"
}
}

@@ -11,2 +11,2 @@ export { computePosition } from './computePosition';

export { size } from './middleware/size';
export { rectToClientRect } from './utils/rectToClientRect';
export { rectToClientRect } from '@floating-ui/utils';

@@ -1,8 +0,3 @@

export type Alignment = 'start' | 'end';
export type Side = 'top' | 'right' | 'bottom' | 'left';
export type AlignedPlacement = `${Side}-${Alignment}`;
export type Placement = Side | AlignedPlacement;
export type Strategy = 'absolute' | 'fixed';
export type Axis = 'x' | 'y';
export type Length = 'width' | 'height';
import type { Axis, ClientRectObject, ElementRects, Length, Placement, Rect, SideObject, Strategy } from '@floating-ui/utils';
export type { AlignedPlacement, Alignment, Axis, ClientRectObject, ElementRects, Length, Padding, Placement, Rect, Side, SideObject, Strategy, VirtualElement, } from '@floating-ui/utils';
type Promisable<T> = T | Promise<T>;

@@ -48,5 +43,2 @@ /**

};
export type SideObject = {
[key in Side]: number;
};
export interface MiddlewareData {

@@ -131,15 +123,2 @@ [key: string]: any;

};
export type Rect = Coords & Dimensions;
export interface ElementRects {
reference: Rect;
floating: Rect;
}
/**
* Custom positioning reference element.
* @see https://floating-ui.com/docs/virtual-elements
*/
export type VirtualElement = {
getBoundingClientRect(): ClientRectObject;
contextElement?: any;
};
export type ReferenceElement = any;

@@ -164,4 +143,2 @@ export type FloatingElement = any;

export type MiddlewareArguments = MiddlewareState;
export type ClientRectObject = Rect & SideObject;
export type Padding = number | Partial<SideObject>;
export type Boundary = any;

@@ -180,2 +157,2 @@ export type RootBoundary = 'viewport' | 'document' | Rect;

export { size, SizeOptions } from './middleware/size';
export { rectToClientRect } from './utils/rectToClientRect';
export { rectToClientRect } from '@floating-ui/utils';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc