alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
1,114 lines (1,110 loc) • 35.5 kB
JavaScript
// node_modules/@floating-ui/core/dist/floating-ui.core.mjs
function getSide(placement) {
return placement.split("-")[0];
}
function getAlignment(placement) {
return placement.split("-")[1];
}
function getMainAxisFromPlacement(placement) {
return ["top", "bottom"].includes(getSide(placement)) ? "x" : "y";
}
function getLengthFromAxis(axis) {
return axis === "y" ? "height" : "width";
}
function computeCoordsFromPlacement(_ref, placement, rtl) {
let {
reference,
floating
} = _ref;
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";
let coords;
switch (side) {
case "top":
coords = {
x: commonX,
y: reference.y - floating.height
};
break;
case "bottom":
coords = {
x: commonX,
y: reference.y + reference.height
};
break;
case "right":
coords = {
x: reference.x + reference.width,
y: commonY
};
break;
case "left":
coords = {
x: reference.x - floating.width,
y: commonY
};
break;
default:
coords = {
x: reference.x,
y: reference.y
};
}
switch (getAlignment(placement)) {
case "start":
coords[mainAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
break;
case "end":
coords[mainAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
break;
}
return coords;
}
var computePosition = async (reference, floating, config) => {
const {
placement = "bottom",
strategy = "absolute",
middleware = [],
platform: platform2
} = config;
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
if (process.env.NODE_ENV !== "production") {
if (platform2 == null) {
console.error(["Floating UI: `platform` property was not passed to config. If you", "want to use Floating UI on the web, install @floating-ui/dom", "instead of the /core package. Otherwise, you can create your own", "`platform`: https://floating-ui.com/docs/platform"].join(" "));
}
if (middleware.filter((_ref) => {
let {
name
} = _ref;
return name === "autoPlacement" || name === "flip";
}).length > 1) {
throw new Error(["Floating UI: duplicate `flip` and/or `autoPlacement`", "middleware detected. This will lead to an infinite loop. Ensure only", "one of either has been passed to the `middleware` array."].join(" "));
}
}
let rects = await platform2.getElementRects({
reference,
floating,
strategy
});
let {
x,
y
} = computeCoordsFromPlacement(rects, placement, rtl);
let statefulPlacement = placement;
let middlewareData = {};
let _debug_loop_count_ = 0;
for (let i = 0; i < middleware.length; i++) {
if (process.env.NODE_ENV !== "production") {
_debug_loop_count_++;
if (_debug_loop_count_ > 100) {
throw new Error(["Floating UI: The middleware lifecycle appears to be", "running in an infinite loop. This is usually caused by a `reset`", "continually being returned without a break condition."].join(" "));
}
}
const {
name,
fn
} = middleware[i];
const {
x: nextX,
y: nextY,
data,
reset
} = await fn({
x,
y,
initialPlacement: placement,
placement: statefulPlacement,
strategy,
middlewareData,
rects,
platform: platform2,
elements: {
reference,
floating
}
});
x = nextX != null ? nextX : x;
y = nextY != null ? nextY : y;
middlewareData = {
...middlewareData,
[name]: {
...middlewareData[name],
...data
}
};
if (reset) {
if (typeof reset === "object") {
if (reset.placement) {
statefulPlacement = reset.placement;
}
if (reset.rects) {
rects = reset.rects === true ? await platform2.getElementRects({
reference,
floating,
strategy
}) : reset.rects;
}
({
x,
y
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
}
i = -1;
continue;
}
}
return {
x,
y,
placement: statefulPlacement,
strategy,
middlewareData
};
};
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
};
}
async function detectOverflow(middlewareArguments, options) {
var _await$platform$isEle;
if (options === void 0) {
options = {};
}
const {
x,
y,
platform: platform2,
rects,
elements,
strategy
} = middlewareArguments;
const {
boundary = "clippingAncestors",
rootBoundary = "viewport",
elementContext = "floating",
altBoundary = false,
padding = 0
} = options;
const paddingObject = getSideObjectFromPadding(padding);
const altContext = elementContext === "floating" ? "reference" : "floating";
const element = elements[altBoundary ? altContext : elementContext];
const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
element: ((_await$platform$isEle = await (platform2.isElement == null ? void 0 : platform2.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
boundary,
rootBoundary,
strategy
}));
const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
rect: elementContext === "floating" ? {
...rects.floating,
x,
y
} : rects.reference,
offsetParent: await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating)),
strategy
}) : rects[elementContext]);
return {
top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
right: elementClientRect.right - clippingClientRect.right + paddingObject.right
};
}
var max = Math.max;
var hash$1 = {
left: "right",
right: "left",
bottom: "top",
top: "bottom"
};
function getOppositePlacement(placement) {
return placement.replace(/left|right|bottom|top/g, (matched) => hash$1[matched]);
}
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)
};
}
var hash = {
start: "end",
end: "start"
};
function getOppositeAlignmentPlacement(placement) {
return placement.replace(/start|end/g, (matched) => hash[matched]);
}
function getExpandedPlacements(placement) {
const oppositePlacement = getOppositePlacement(placement);
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
}
var flip = function(options) {
if (options === void 0) {
options = {};
}
return {
name: "flip",
options,
async fn(middlewareArguments) {
var _middlewareData$flip;
const {
placement,
middlewareData,
rects,
initialPlacement,
platform: platform2,
elements
} = middlewareArguments;
const {
mainAxis: checkMainAxis = true,
crossAxis: checkCrossAxis = true,
fallbackPlacements: specifiedFallbackPlacements,
fallbackStrategy = "bestFit",
flipAlignment = true,
...detectOverflowOptions
} = options;
const side = getSide(placement);
const isBasePlacement = side === initialPlacement;
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
const placements = [initialPlacement, ...fallbackPlacements];
const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
const overflows = [];
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
if (checkMainAxis) {
overflows.push(overflow[side]);
}
if (checkCrossAxis) {
const {
main,
cross
} = getAlignmentSides(placement, rects, await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)));
overflows.push(overflow[main], overflow[cross]);
}
overflowsData = [...overflowsData, {
placement,
overflows
}];
if (!overflows.every((side2) => side2 <= 0)) {
var _middlewareData$flip$, _middlewareData$flip2;
const nextIndex = ((_middlewareData$flip$ = (_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) != null ? _middlewareData$flip$ : 0) + 1;
const nextPlacement = placements[nextIndex];
if (nextPlacement) {
return {
data: {
index: nextIndex,
overflows: overflowsData
},
reset: {
placement: nextPlacement
}
};
}
let resetPlacement = "bottom";
switch (fallbackStrategy) {
case "bestFit": {
var _overflowsData$map$so;
const placement2 = (_overflowsData$map$so = overflowsData.map((d) => [d, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$map$so[0].placement;
if (placement2) {
resetPlacement = placement2;
}
break;
}
case "initialPlacement":
resetPlacement = initialPlacement;
break;
}
if (placement !== resetPlacement) {
return {
reset: {
placement: resetPlacement
}
};
}
}
return {};
}
};
};
async function convertValueToCoords(middlewareArguments, value) {
const {
placement,
platform: platform2,
elements
} = middlewareArguments;
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
const side = getSide(placement);
const alignment = getAlignment(placement);
const isVertical = getMainAxisFromPlacement(placement) === "x";
const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
const crossAxisMulti = rtl && isVertical ? -1 : 1;
const rawValue = typeof value === "function" ? value(middlewareArguments) : value;
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
};
}
var offset = function(value) {
if (value === void 0) {
value = 0;
}
return {
name: "offset",
options: value,
async fn(middlewareArguments) {
const {
x,
y
} = middlewareArguments;
const diffCoords = await convertValueToCoords(middlewareArguments, value);
return {
x: x + diffCoords.x,
y: y + diffCoords.y,
data: diffCoords
};
}
};
};
var size = function(options) {
if (options === void 0) {
options = {};
}
return {
name: "size",
options,
async fn(middlewareArguments) {
const {
placement,
rects,
platform: platform2,
elements
} = middlewareArguments;
const {
apply,
...detectOverflowOptions
} = options;
const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
const side = getSide(placement);
const alignment = getAlignment(placement);
let heightSide;
let widthSide;
if (side === "top" || side === "bottom") {
heightSide = side;
widthSide = alignment === (await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)) ? "start" : "end") ? "left" : "right";
} else {
widthSide = side;
heightSide = alignment === "end" ? "top" : "bottom";
}
const xMin = max(overflow.left, 0);
const xMax = max(overflow.right, 0);
const yMin = max(overflow.top, 0);
const yMax = max(overflow.bottom, 0);
const dimensions = {
availableHeight: rects.floating.height - (["left", "right"].includes(placement) ? 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom)) : overflow[heightSide]),
availableWidth: rects.floating.width - (["top", "bottom"].includes(placement) ? 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right)) : overflow[widthSide])
};
const prevDimensions = await platform2.getDimensions(elements.floating);
apply == null ? void 0 : apply({
...middlewareArguments,
...dimensions
});
const nextDimensions = await platform2.getDimensions(elements.floating);
if (prevDimensions.width !== nextDimensions.width || prevDimensions.height !== nextDimensions.height) {
return {
reset: {
rects: true
}
};
}
return {};
}
};
};
// node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs
function isWindow(value) {
return value && value.document && value.location && value.alert && value.setInterval;
}
function getWindow(node) {
if (node == null) {
return window;
}
if (!isWindow(node)) {
const ownerDocument = node.ownerDocument;
return ownerDocument ? ownerDocument.defaultView || window : window;
}
return node;
}
function getComputedStyle$1(element) {
return getWindow(element).getComputedStyle(element);
}
function getNodeName(node) {
return isWindow(node) ? "" : node ? (node.nodeName || "").toLowerCase() : "";
}
function getUAString() {
const uaData = navigator.userAgentData;
if (uaData != null && uaData.brands) {
return uaData.brands.map((item) => item.brand + "/" + item.version).join(" ");
}
return navigator.userAgent;
}
function isHTMLElement(value) {
return value instanceof getWindow(value).HTMLElement;
}
function isElement(value) {
return value instanceof getWindow(value).Element;
}
function isNode(value) {
return value instanceof getWindow(value).Node;
}
function isShadowRoot(node) {
if (typeof ShadowRoot === "undefined") {
return false;
}
const OwnElement = getWindow(node).ShadowRoot;
return node instanceof OwnElement || node instanceof ShadowRoot;
}
function isOverflowElement(element) {
const {
overflow,
overflowX,
overflowY
} = getComputedStyle$1(element);
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
}
function isTableElement(element) {
return ["table", "td", "th"].includes(getNodeName(element));
}
function isContainingBlock(element) {
const isFirefox = /firefox/i.test(getUAString());
const css = getComputedStyle$1(element);
return css.transform !== "none" || css.perspective !== "none" || // @ts-ignore (TS 4.1 compat)
css.contain === "paint" || ["transform", "perspective"].includes(css.willChange) || isFirefox && css.willChange === "filter" || isFirefox && (css.filter ? css.filter !== "none" : false);
}
function isLayoutViewport() {
return !/^((?!chrome|android).)*safari/i.test(getUAString());
}
var min = Math.min;
var max2 = Math.max;
var round = Math.round;
function getBoundingClientRect(element, includeScale, isFixedStrategy) {
var _win$visualViewport$o, _win$visualViewport, _win$visualViewport$o2, _win$visualViewport2;
if (includeScale === void 0) {
includeScale = false;
}
if (isFixedStrategy === void 0) {
isFixedStrategy = false;
}
const clientRect = element.getBoundingClientRect();
let scaleX = 1;
let scaleY = 1;
if (includeScale && isHTMLElement(element)) {
scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
}
const win = isElement(element) ? getWindow(element) : window;
const addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
const x = (clientRect.left + (addVisualOffsets ? (_win$visualViewport$o = (_win$visualViewport = win.visualViewport) == null ? void 0 : _win$visualViewport.offsetLeft) != null ? _win$visualViewport$o : 0 : 0)) / scaleX;
const y = (clientRect.top + (addVisualOffsets ? (_win$visualViewport$o2 = (_win$visualViewport2 = win.visualViewport) == null ? void 0 : _win$visualViewport2.offsetTop) != null ? _win$visualViewport$o2 : 0 : 0)) / scaleY;
const width = clientRect.width / scaleX;
const height = clientRect.height / scaleY;
return {
width,
height,
top: y,
right: x + width,
bottom: y + height,
left: x,
x,
y
};
}
function getDocumentElement(node) {
return ((isNode(node) ? node.ownerDocument : node.document) || window.document).documentElement;
}
function getNodeScroll(element) {
if (isElement(element)) {
return {
scrollLeft: element.scrollLeft,
scrollTop: element.scrollTop
};
}
return {
scrollLeft: element.pageXOffset,
scrollTop: element.pageYOffset
};
}
function getWindowScrollBarX(element) {
return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
}
function isScaled(element) {
const rect = getBoundingClientRect(element);
return round(rect.width) !== element.offsetWidth || round(rect.height) !== element.offsetHeight;
}
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
const isOffsetParentAnElement = isHTMLElement(offsetParent);
const documentElement = getDocumentElement(offsetParent);
const rect = getBoundingClientRect(
element,
// @ts-ignore - checked above (TS 4.1 compat)
isOffsetParentAnElement && isScaled(offsetParent),
strategy === "fixed"
);
let scroll = {
scrollLeft: 0,
scrollTop: 0
};
const offsets = {
x: 0,
y: 0
};
if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== "fixed") {
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
scroll = getNodeScroll(offsetParent);
}
if (isHTMLElement(offsetParent)) {
const offsetRect = getBoundingClientRect(offsetParent, true);
offsets.x = offsetRect.x + offsetParent.clientLeft;
offsets.y = offsetRect.y + offsetParent.clientTop;
} else if (documentElement) {
offsets.x = getWindowScrollBarX(documentElement);
}
}
return {
x: rect.left + scroll.scrollLeft - offsets.x,
y: rect.top + scroll.scrollTop - offsets.y,
width: rect.width,
height: rect.height
};
}
function getParentNode(node) {
if (getNodeName(node) === "html") {
return node;
}
return (
// this is a quicker (but less type safe) way to save quite some bytes from the bundle
// @ts-ignore
node.assignedSlot || // step into the shadow DOM of the parent of a slotted node
node.parentNode || // DOM Element detected
(isShadowRoot(node) ? node.host : null) || // ShadowRoot detected
getDocumentElement(node)
);
}
function getTrueOffsetParent(element) {
if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
return null;
}
return element.offsetParent;
}
function getContainingBlock(element) {
let currentNode = getParentNode(element);
if (isShadowRoot(currentNode)) {
currentNode = currentNode.host;
}
while (isHTMLElement(currentNode) && !["html", "body"].includes(getNodeName(currentNode))) {
if (isContainingBlock(currentNode)) {
return currentNode;
} else {
currentNode = currentNode.parentNode;
}
}
return null;
}
function getOffsetParent(element) {
const window2 = getWindow(element);
let offsetParent = getTrueOffsetParent(element);
while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === "static") {
offsetParent = getTrueOffsetParent(offsetParent);
}
if (offsetParent && (getNodeName(offsetParent) === "html" || getNodeName(offsetParent) === "body" && getComputedStyle(offsetParent).position === "static" && !isContainingBlock(offsetParent))) {
return window2;
}
return offsetParent || getContainingBlock(element) || window2;
}
function getDimensions(element) {
if (isHTMLElement(element)) {
return {
width: element.offsetWidth,
height: element.offsetHeight
};
}
const rect = getBoundingClientRect(element);
return {
width: rect.width,
height: rect.height
};
}
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
let {
rect,
offsetParent,
strategy
} = _ref;
const isOffsetParentAnElement = isHTMLElement(offsetParent);
const documentElement = getDocumentElement(offsetParent);
if (offsetParent === documentElement) {
return rect;
}
let scroll = {
scrollLeft: 0,
scrollTop: 0
};
const offsets = {
x: 0,
y: 0
};
if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== "fixed") {
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
scroll = getNodeScroll(offsetParent);
}
if (isHTMLElement(offsetParent)) {
const offsetRect = getBoundingClientRect(offsetParent, true);
offsets.x = offsetRect.x + offsetParent.clientLeft;
offsets.y = offsetRect.y + offsetParent.clientTop;
}
}
return {
...rect,
x: rect.x - scroll.scrollLeft + offsets.x,
y: rect.y - scroll.scrollTop + offsets.y
};
}
function getViewportRect(element, strategy) {
const win = getWindow(element);
const html = getDocumentElement(element);
const visualViewport = win.visualViewport;
let width = html.clientWidth;
let height = html.clientHeight;
let x = 0;
let y = 0;
if (visualViewport) {
width = visualViewport.width;
height = visualViewport.height;
const layoutViewport = isLayoutViewport();
if (layoutViewport || !layoutViewport && strategy === "fixed") {
x = visualViewport.offsetLeft;
y = visualViewport.offsetTop;
}
}
return {
width,
height,
x,
y
};
}
function getDocumentRect(element) {
var _element$ownerDocumen;
const html = getDocumentElement(element);
const scroll = getNodeScroll(element);
const body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
const width = max2(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
const height = max2(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
const y = -scroll.scrollTop;
if (getComputedStyle$1(body || html).direction === "rtl") {
x += max2(html.clientWidth, body ? body.clientWidth : 0) - width;
}
return {
width,
height,
x,
y
};
}
function getNearestOverflowAncestor(node) {
const parentNode = getParentNode(node);
if (["html", "body", "#document"].includes(getNodeName(parentNode))) {
return node.ownerDocument.body;
}
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
return parentNode;
}
return getNearestOverflowAncestor(parentNode);
}
function getOverflowAncestors(node, list) {
var _node$ownerDocument;
if (list === void 0) {
list = [];
}
const scrollableAncestor = getNearestOverflowAncestor(node);
const isBody = scrollableAncestor === ((_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.body);
const win = getWindow(scrollableAncestor);
const target = isBody ? [win].concat(win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []) : scrollableAncestor;
const updatedList = list.concat(target);
return isBody ? updatedList : (
// @ts-ignore: isBody tells us target will be an HTMLElement here
updatedList.concat(getOverflowAncestors(target))
);
}
function contains(parent, child) {
const rootNode = child == null ? void 0 : child.getRootNode == null ? void 0 : child.getRootNode();
if (parent != null && parent.contains(child)) {
return true;
} else if (rootNode && isShadowRoot(rootNode)) {
let next = child;
do {
if (next && parent === next) {
return true;
}
next = next.parentNode || next.host;
} while (next);
}
return false;
}
function getInnerBoundingClientRect(element, strategy) {
const clientRect = getBoundingClientRect(element, false, strategy === "fixed");
const top = clientRect.top + element.clientTop;
const left = clientRect.left + element.clientLeft;
return {
top,
left,
x: left,
y: top,
right: left + element.clientWidth,
bottom: top + element.clientHeight,
width: element.clientWidth,
height: element.clientHeight
};
}
function getClientRectFromClippingAncestor(element, clippingParent, strategy) {
if (clippingParent === "viewport") {
return rectToClientRect(getViewportRect(element, strategy));
}
if (isElement(clippingParent)) {
return getInnerBoundingClientRect(clippingParent, strategy);
}
return rectToClientRect(getDocumentRect(getDocumentElement(element)));
}
function getClippingAncestors(element) {
const clippingAncestors = getOverflowAncestors(element);
const canEscapeClipping = ["absolute", "fixed"].includes(getComputedStyle$1(element).position);
const clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
if (!isElement(clipperElement)) {
return [];
}
return clippingAncestors.filter((clippingAncestors2) => isElement(clippingAncestors2) && contains(clippingAncestors2, clipperElement) && getNodeName(clippingAncestors2) !== "body");
}
function getClippingRect(_ref) {
let {
element,
boundary,
rootBoundary,
strategy
} = _ref;
const mainClippingAncestors = boundary === "clippingAncestors" ? getClippingAncestors(element) : [].concat(boundary);
const clippingAncestors = [...mainClippingAncestors, rootBoundary];
const firstClippingAncestor = clippingAncestors[0];
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
accRect.top = max2(rect.top, accRect.top);
accRect.right = min(rect.right, accRect.right);
accRect.bottom = min(rect.bottom, accRect.bottom);
accRect.left = max2(rect.left, accRect.left);
return accRect;
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
return {
width: clippingRect.right - clippingRect.left,
height: clippingRect.bottom - clippingRect.top,
x: clippingRect.left,
y: clippingRect.top
};
}
var platform = {
getClippingRect,
convertOffsetParentRelativeRectToViewportRelativeRect,
isElement,
getDimensions,
getOffsetParent,
getDocumentElement,
getElementRects: (_ref) => {
let {
reference,
floating,
strategy
} = _ref;
return {
reference: getRectRelativeToOffsetParent(reference, getOffsetParent(floating), strategy),
floating: {
...getDimensions(floating),
x: 0,
y: 0
}
};
},
getClientRects: (element) => Array.from(element.getClientRects()),
isRTL: (element) => getComputedStyle$1(element).direction === "rtl"
};
function autoUpdate(reference, floating, update, options) {
if (options === void 0) {
options = {};
}
const {
ancestorScroll: _ancestorScroll = true,
ancestorResize: _ancestorResize = true,
elementResize = true,
animationFrame = false
} = options;
const ancestorScroll = _ancestorScroll && !animationFrame;
const ancestorResize = _ancestorResize && !animationFrame;
const ancestors = ancestorScroll || ancestorResize ? [...isElement(reference) ? getOverflowAncestors(reference) : [], ...getOverflowAncestors(floating)] : [];
ancestors.forEach((ancestor) => {
ancestorScroll && ancestor.addEventListener("scroll", update, {
passive: true
});
ancestorResize && ancestor.addEventListener("resize", update);
});
let observer = null;
if (elementResize) {
observer = new ResizeObserver(update);
isElement(reference) && !animationFrame && observer.observe(reference);
observer.observe(floating);
}
let frameId;
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
if (animationFrame) {
frameLoop();
}
function frameLoop() {
const nextRefRect = getBoundingClientRect(reference);
if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
update();
}
prevRefRect = nextRefRect;
frameId = requestAnimationFrame(frameLoop);
}
if (!elementResize) {
update();
}
return () => {
var _observer;
ancestors.forEach((ancestor) => {
ancestorScroll && ancestor.removeEventListener("scroll", update);
ancestorResize && ancestor.removeEventListener("resize", update);
});
(_observer = observer) == null ? void 0 : _observer.disconnect();
observer = null;
if (animationFrame) {
cancelAnimationFrame(frameId);
}
};
}
var computePosition2 = (reference, floating, options) => computePosition(reference, floating, {
platform,
...options
});
// node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.mjs
import * as React from "react";
import { useLayoutEffect, useEffect } from "react";
import * as ReactDOM from "react-dom";
var index = typeof document !== "undefined" ? useLayoutEffect : useEffect;
function deepEqual(a, b) {
if (a === b) {
return true;
}
if (typeof a !== typeof b) {
return false;
}
if (typeof a === "function" && a.toString() === b.toString()) {
return true;
}
let length, i, keys;
if (a && b && typeof a == "object") {
if (Array.isArray(a)) {
length = a.length;
if (length != b.length)
return false;
for (i = length; i-- !== 0; ) {
if (!deepEqual(a[i], b[i])) {
return false;
}
}
return true;
}
keys = Object.keys(a);
length = keys.length;
if (length !== Object.keys(b).length) {
return false;
}
for (i = length; i-- !== 0; ) {
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) {
return false;
}
}
for (i = length; i-- !== 0; ) {
const key = keys[i];
if (key === "_owner" && a.$$typeof) {
continue;
}
if (!deepEqual(a[key], b[key])) {
return false;
}
}
return true;
}
return a !== a && b !== b;
}
function useLatestRef(value) {
const ref = React.useRef(value);
index(() => {
ref.current = value;
});
return ref;
}
function useFloating(_temp) {
let {
middleware,
placement = "bottom",
strategy = "absolute",
whileElementsMounted
} = _temp === void 0 ? {} : _temp;
const reference = React.useRef(null);
const floating = React.useRef(null);
const whileElementsMountedRef = useLatestRef(whileElementsMounted);
const cleanupRef = React.useRef(null);
const [data, setData] = React.useState({
// Setting these to `null` will allow the consumer to determine if
// `computePosition()` has run yet
x: null,
y: null,
strategy,
placement,
middlewareData: {}
});
const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
if (!deepEqual(latestMiddleware == null ? void 0 : latestMiddleware.map((_ref) => {
let {
options
} = _ref;
return options;
}), middleware == null ? void 0 : middleware.map((_ref2) => {
let {
options
} = _ref2;
return options;
}))) {
setLatestMiddleware(middleware);
}
const update = React.useCallback(() => {
if (!reference.current || !floating.current) {
return;
}
computePosition2(reference.current, floating.current, {
middleware: latestMiddleware,
placement,
strategy
}).then((data2) => {
if (isMountedRef.current) {
ReactDOM.flushSync(() => {
setData(data2);
});
}
});
}, [latestMiddleware, placement, strategy]);
index(() => {
if (isMountedRef.current) {
update();
}
}, [update]);
const isMountedRef = React.useRef(false);
index(() => {
isMountedRef.current = true;
return () => {
isMountedRef.current = false;
};
}, []);
const runElementMountCallback = React.useCallback(() => {
if (typeof cleanupRef.current === "function") {
cleanupRef.current();
cleanupRef.current = null;
}
if (reference.current && floating.current) {
if (whileElementsMountedRef.current) {
const cleanupFn = whileElementsMountedRef.current(reference.current, floating.current, update);
cleanupRef.current = cleanupFn;
} else {
update();
}
}
}, [update, whileElementsMountedRef]);
const setReference = React.useCallback((node) => {
reference.current = node;
runElementMountCallback();
}, [runElementMountCallback]);
const setFloating = React.useCallback((node) => {
floating.current = node;
runElementMountCallback();
}, [runElementMountCallback]);
const refs = React.useMemo(() => ({
reference,
floating
}), []);
return React.useMemo(() => ({
...data,
update,
refs,
reference: setReference,
floating: setFloating
}), [data, update, refs, setReference, setFloating]);
}
export {
flip,
offset,
size,
autoUpdate,
useFloating
};