vendor: 4,186 bytes, lines 1-109
1import { rectToClientRect, arrow as arrow$1, autoPlacement as autoPlacement$1, detectOverflow as detectOverflow$1, flip as flip$1, hide as hide$1, inline as inline$1, limitShift as limitShift$1, offset as offset$1, shift as shift$1, size as size$1, computePosition as computePosition$1 } from '@floating-ui/core'; 2 3/** 4 * Custom positioning reference element. 5 * @see https://floating-ui.com/docs/virtual-elements 6 */ 7 8const min = Math.min; 9const max = Math.max; 10const round = Math.round; 11const floor = Math.floor; 12const createCoords = v => ({ 13 x: v, 14 y: v 15}); 16 17function hasWindow() { 18 return typeof window !== 'undefined'; 19} 20function getNodeName(node) { 21 if (isNode(node)) { 22 return (node.nodeName || '').toLowerCase(); 23 } 24 // Mocked nodes in testing environments may not be instances of Node. By 25 // returning `#document` an infinite loop won't occur. 26 // https://github.com/floating-ui/floating-ui/issues/2317 27 return '#document'; 28} 29function getWindow(node) { 30 var _node$ownerDocument; 31 return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window; 32} 33function getDocumentElement(node) { 34 var _ref; 35 return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement; 36} 37function isNode(value) { 38 if (!hasWindow()) { 39 return false; 40 } 41 return value instanceof Node || value instanceof getWindow(value).Node; 42} 43function isElement(value) { 44 if (!hasWindow()) { 45 return false; 46 } 47 return value instanceof Element || value instanceof getWindow(value).Element; 48} 49function isHTMLElement(value) { 50 if (!hasWindow()) { 51 return false; 52 } 53 return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement; 54} 55function isShadowRoot(value) { 56 if (!hasWindow() || typeof ShadowRoot === 'undefined') { 57 return false; 58 } 59 return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot; 60} 61const invalidOverflowDisplayValues = /*#__PURE__*/new Set(['inline', 'contents']); 62function isOverflowElement(element) { 63 const { 64 overflow, 65 overflowX, 66 overflowY, 67 display 68 } = getComputedStyle(element); 69 return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !invalidOverflowDisplayValues.has(display); 70} 71const tableElements = /*#__PURE__*/new Set(['table', 'td', 'th']); 72function isTableElement(element) { 73 return tableElements.has(getNodeName(element)); 74} 75const topLayerSelectors = [':popover-open', ':modal']; 76function isTopLayer(element) { 77 return topLayerSelectors.some(selector => { 78 try { 79 return element.matches(selector); 80 } catch (_e) { 81 return false; 82 } 83 }); 84} 85const transformProperties = ['transform', 'translate', 'scale', 'rotate', 'perspective']; 86const willChangeValues = ['transform', 'translate', 'scale', 'rotate', 'perspective', 'filter']; 87const containValues = ['paint', 'layout', 'strict', 'content']; 88function isContainingBlock(elementOrCss) { 89 const webkit = isWebKit(); 90 const css = isElement(elementOrCss) ? getComputedStyle(elementOrCss) : elementOrCss; 91 92 // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block 93 // https://drafts.csswg.org/css-transforms-2/#individual-transforms 94 return transformProperties.some(value => css[value] ? css[value] !== 'none' : false) || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || willChangeValues.some(value => (css.willChange || '').includes(value)) || containValues.some(value => (css.contain || '').includes(value)); 95} 96function getContainingBlock(element) { 97 let currentNode = getParentNode(element); 98 while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) { 99 if (isContainingBlock(currentNode)) { 100 return currentNode; 101 } else if (isTopLayer(currentNode)) { 102 return null; 103 } 104 currentNode = getParentNode(currentNode); 105 } 106 return null; 107} 108function isWebKit() { 109 if (typeof CSS === 'undefined' || !CSS.supports) return false;
110 return CSS.supports('-webkit-backdrop-filter', 'none'); 111} 112const lastTraversableNodeNames = /*#__PURE__*/new Set(['html', 'body', '#document']); 113function isLastTraversableNode(node) { 114 return lastTraversableNodeNames.ha
vendor: 9,554 bytes, lines 114-418
114s(getNodeName(node)); 115} 116function getComputedStyle(element) { 117 return getWindow(element).getComputedStyle(element); 118} 119function getNodeScroll(element) { 120 if (isElement(element)) { 121 return { 122 scrollLeft: element.scrollLeft, 123 scrollTop: element.scrollTop 124 }; 125 } 126 return { 127 scrollLeft: element.scrollX, 128 scrollTop: element.scrollY 129 }; 130} 131function getParentNode(node) { 132 if (getNodeName(node) === 'html') { 133 return node; 134 } 135 const result = 136 // Step into the shadow DOM of the parent of a slotted node. 137 node.assignedSlot || 138 // DOM Element detected. 139 node.parentNode || 140 // ShadowRoot detected. 141 isShadowRoot(node) && node.host || 142 // Fallback. 143 getDocumentElement(node); 144 return isShadowRoot(result) ? result.host : result; 145} 146function getNearestOverflowAncestor(node) { 147 const parentNode = getParentNode(node); 148 if (isLastTraversableNode(parentNode)) { 149 return node.ownerDocument ? node.ownerDocument.body : node.body; 150 } 151 if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) { 152 return parentNode; 153 } 154 return getNearestOverflowAncestor(parentNode); 155} 156function getOverflowAncestors(node, list, traverseIframes) { 157 var _node$ownerDocument2; 158 if (list === void 0) { 159 list = []; 160 } 161 if (traverseIframes === void 0) { 162 traverseIframes = true; 163 } 164 const scrollableAncestor = getNearestOverflowAncestor(node); 165 const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body); 166 const win = getWindow(scrollableAncestor); 167 if (isBody) { 168 const frameElement = getFrameElement(win); 169 return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []); 170 } 171 return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes)); 172} 173function getFrameElement(win) { 174 return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null; 175} 176 177function getCssDimensions(element) { 178 const css = getComputedStyle(element); 179 // In testing environments, the `width` and `height` properties are empty 180 // strings for SVG elements, returning NaN. Fallback to `0` in this case. 181 let width = parseFloat(css.width) || 0; 182 let height = parseFloat(css.height) || 0; 183 const hasOffset = isHTMLElement(element); 184 const offsetWidth = hasOffset ? element.offsetWidth : width; 185 const offsetHeight = hasOffset ? element.offsetHeight : height; 186 const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight; 187 if (shouldFallback) { 188 width = offsetWidth; 189 height = offsetHeight; 190 } 191 return { 192 width, 193 height, 194 $: shouldFallback 195 }; 196} 197 198function unwrapElement(element) { 199 return !isElement(element) ? element.contextElement : element; 200} 201 202function getScale(element) { 203 const domElement = unwrapElement(element); 204 if (!isHTMLElement(domElement)) { 205 return createCoords(1); 206 } 207 const rect = domElement.getBoundingClientRect(); 208 const { 209 width, 210 height, 211 $ 212 } = getCssDimensions(domElement); 213 let x = ($ ? round(rect.width) : rect.width) / width; 214 let y = ($ ? round(rect.height) : rect.height) / height; 215 216 // 0, NaN, or Infinity should always fallback to 1. 217 218 if (!x || !Number.isFinite(x)) { 219 x = 1; 220 } 221 if (!y || !Number.isFinite(y)) { 222 y = 1; 223 } 224 return { 225 x, 226 y 227 }; 228} 229 230const noOffsets = /*#__PURE__*/createCoords(0); 231function getVisualOffsets(element) { 232 const win = getWindow(element); 233 if (!isWebKit() || !win.visualViewport) { 234 return noOffsets; 235 } 236 return { 237 x: win.visualViewport.offsetLeft, 238 y: win.visualViewport.offsetTop 239 }; 240} 241function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) { 242 if (isFixed === void 0) { 243 isFixed = false; 244 } 245 if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) { 246 return false; 247 } 248 return isFixed; 249} 250 251function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) { 252 if (includeScale === void 0) { 253 includeScale = false; 254 } 255 if (isFixedStrategy === void 0) { 256 isFixedStrategy = false; 257 } 258 const clientRect = element.getBoundingClientRect(); 259 const domElement = unwrapElement(element); 260 let scale = createCoords(1); 261 if (includeScale) { 262 if (offsetParent) { 263 if (isElement(offsetParent)) { 264 scale = getScale(offsetParent); 265 } 266 } else { 267 scale = getScale(element); 268 } 269 } 270 const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0); 271 let x = (clientRect.left + visualOffsets.x) / scale.x; 272 let y = (clientRect.top + visualOffsets.y) / scale.y; 273 let width = clientRect.width / scale.x; 274 let height = clientRect.height / scale.y; 275 if (domElement) { 276 const win = getWindow(domElement); 277 const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent; 278 let currentWin = win; 279 let currentIFrame = getFrameElement(currentWin); 280 while (currentIFrame && offsetParent && offsetWin !== currentWin) { 281 const iframeScale = getScale(currentIFrame); 282 const iframeRect = currentIFrame.getBoundingClientRect(); 283 const css = getComputedStyle(currentIFrame); 284 const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x; 285 const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y; 286 x *= iframeScale.x; 287 y *= iframeScale.y; 288 width *= iframeScale.x; 289 height *= iframeScale.y; 290 x += left; 291 y += top; 292 currentWin = getWindow(currentIFrame); 293 currentIFrame = getFrameElement(currentWin); 294 } 295 } 296 return rectToClientRect({ 297 width, 298 height, 299 x, 300 y 301 }); 302} 303 304// If <html> has a CSS width greater than the viewport, then this will be 305// incorrect for RTL. 306function getWindowScrollBarX(element, rect) { 307 const leftScroll = getNodeScroll(element).scrollLeft; 308 if (!rect) { 309 return getBoundingClientRect(getDocumentElement(element)).left + leftScroll; 310 } 311 return rect.left + leftScroll; 312} 313 314function getHTMLOffset(documentElement, scroll, ignoreScrollbarX) { 315 if (ignoreScrollbarX === void 0) { 316 ignoreScrollbarX = false; 317 } 318 const htmlRect = documentElement.getBoundingClientRect(); 319 const x = htmlRect.left + scroll.scrollLeft - (ignoreScrollbarX ? 0 : 320 // RTL <body> scrollbar. 321 getWindowScrollBarX(documentElement, htmlRect)); 322 const y = htmlRect.top + scroll.scrollTop; 323 return { 324 x, 325 y 326 }; 327} 328 329function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) { 330 let { 331 elements, 332 rect, 333 offsetParent, 334 strategy 335 } = _ref; 336 const isFixed = strategy === 'fixed'; 337 const documentElement = getDocumentElement(offsetParent); 338 const topLayer = elements ? isTopLayer(elements.floating) : false; 339 if (offsetParent === documentElement || topLayer && isFixed) { 340 return rect; 341 } 342 let scroll = { 343 scrollLeft: 0, 344 scrollTop: 0 345 }; 346 let scale = createCoords(1); 347 const offsets = createCoords(0); 348 const isOffsetParentAnElement = isHTMLElement(offsetParent); 349 if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) { 350 if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) { 351 scroll = getNodeScroll(offsetParent); 352 } 353 if (isHTMLElement(offsetParent)) { 354 const offsetRect = getBoundingClientRect(offsetParent); 355 scale = getScale(offsetParent); 356 offsets.x = offsetRect.x + offsetParent.clientLeft; 357 offsets.y = offsetRect.y + offsetParent.clientTop; 358 } 359 } 360 const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll, true) : createCoords(0); 361 return { 362 width: rect.width * scale.x, 363 height: rect.height * scale.y, 364 x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x, 365 y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y 366 }; 367} 368 369function getClientRects(element) { 370 return Array.from(element.getClientRects()); 371} 372 373// Gets the entire size of the scrollable document area, even extending outside 374// of the `<html>` and `<body>` rect bounds if horizontally scrollable. 375function getDocumentRect(element) { 376 const html = getDocumentElement(element); 377 const scroll = getNodeScroll(element); 378 const body = element.ownerDocument.body; 379 const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth); 380 const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight); 381 let x = -scroll.scrollLeft + getWindowScrollBarX(element); 382 const y = -scroll.scrollTop; 383 if (getComputedStyle(body).direction === 'rtl') { 384 x += max(html.clientWidth, body.clientWidth) - width; 385 } 386 return { 387 width, 388 height, 389 x, 390 y 391 }; 392} 393 394function getViewportRect(element, strategy) { 395 const win = getWindow(element); 396 const html = getDocumentElement(element); 397 const visualViewport = win.visualViewport; 398 let width = html.clientWidth; 399 let height = html.clientHeight; 400 let x = 0; 401 let y = 0; 402 if (visualViewport) { 403 width = visualViewport.width; 404 height = visualViewport.height; 405 const visualViewportBased = isWebKit(); 406 if (!visualViewportBased || visualViewportBased && strategy === 'fixed') { 407 x = visualViewport.offsetLeft; 408 y = visualViewport.offsetTop; 409 } 410 } 411 return { 412 width, 413 height, 414 x, 415 y 416 }; 417} 418
vendor: 6,081 bytes, lines 419-565
419const absoluteOrFixed = /*#__PURE__*/new Set(['absolute', 'fixed']); 420// Returns the inner client rect, subtracting scrollbars if present. 421function getInnerBoundingClientRect(element, strategy) { 422 const clientRect = getBoundingClientRect(element, true, strategy === 'fixed'); 423 const top = clientRect.top + element.clientTop; 424 const left = clientRect.left + element.clientLeft; 425 const scale = isHTMLElement(element) ? getScale(element) : createCoords(1); 426 const width = element.clientWidth * scale.x; 427 const height = element.clientHeight * scale.y; 428 const x = left * scale.x; 429 const y = top * scale.y; 430 return { 431 width, 432 height, 433 x, 434 y 435 }; 436} 437function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) { 438 let rect; 439 if (clippingAncestor === 'viewport') { 440 rect = getViewportRect(element, strategy); 441 } else if (clippingAncestor === 'document') { 442 rect = getDocumentRect(getDocumentElement(element)); 443 } else if (isElement(clippingAncestor)) { 444 rect = getInnerBoundingClientRect(clippingAncestor, strategy); 445 } else { 446 const visualOffsets = getVisualOffsets(element); 447 rect = { 448 x: clippingAncestor.x - visualOffsets.x, 449 y: clippingAncestor.y - visualOffsets.y, 450 width: clippingAncestor.width, 451 height: clippingAncestor.height 452 }; 453 } 454 return rectToClientRect(rect); 455} 456function hasFixedPositionAncestor(element, stopNode) { 457 const parentNode = getParentNode(element); 458 if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) { 459 return false; 460 } 461 return getComputedStyle(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode); 462} 463 464// A "clipping ancestor" is an `overflow` element with the characteristic of 465// clipping (or hiding) child elements. This returns all clipping ancestors 466// of the given element up the tree. 467function getClippingElementAncestors(element, cache) { 468 const cachedResult = cache.get(element); 469 if (cachedResult) { 470 return cachedResult; 471 } 472 let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body'); 473 let currentContainingBlockComputedStyle = null; 474 const elementIsFixed = getComputedStyle(element).position === 'fixed'; 475 let currentNode = elementIsFixed ? getParentNode(element) : element; 476 477 // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block 478 while (isElement(currentNode) && !isLastTraversableNode(currentNode)) { 479 const computedStyle = getComputedStyle(currentNode); 480 const currentNodeIsContaining = isContainingBlock(currentNode); 481 if (!currentNodeIsContaining && computedStyle.position === 'fixed') { 482 currentContainingBlockComputedStyle = null; 483 } 484 const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && absoluteOrFixed.has(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode); 485 if (shouldDropCurrentNode) { 486 // Drop non-containing blocks. 487 result = result.filter(ancestor => ancestor !== currentNode); 488 } else { 489 // Record last containing block for next iteration. 490 currentContainingBlockComputedStyle = computedStyle; 491 } 492 currentNode = getParentNode(currentNode); 493 } 494 cache.set(element, result); 495 return result; 496} 497 498// Gets the maximum area that the element is visible in due to any number of 499// clipping ancestors. 500function getClippingRect(_ref) { 501 let { 502 element, 503 boundary, 504 rootBoundary, 505 strategy 506 } = _ref; 507 const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary); 508 const clippingAncestors = [...elementClippingAncestors, rootBoundary]; 509 const firstClippingAncestor = clippingAncestors[0]; 510 const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => { 511 const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy); 512 accRect.top = max(rect.top, accRect.top); 513 accRect.right = min(rect.right, accRect.right); 514 accRect.bottom = min(rect.bottom, accRect.bottom); 515 accRect.left = max(rect.left, accRect.left); 516 return accRect; 517 }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy)); 518 return { 519 width: clippingRect.right - clippingRect.left, 520 height: clippingRect.bottom - clippingRect.top, 521 x: clippingRect.left, 522 y: clippingRect.top 523 }; 524} 525 526function getDimensions(element) { 527 const { 528 width, 529 height 530 } = getCssDimensions(element); 531 return { 532 width, 533 height 534 }; 535} 536 537function getRectRelativeToOffsetParent(element, offsetParent, strategy) { 538 const isOffsetParentAnElement = isHTMLElement(offsetParent); 539 const documentElement = getDocumentElement(offsetParent); 540 const isFixed = strategy === 'fixed'; 541 const rect = getBoundingClientRect(element, true, isFixed, offsetParent); 542 let scroll = { 543 scrollLeft: 0, 544 scrollTop: 0 545 }; 546 const offsets = createCoords(0); 547 548 // If the <body> scrollbar appears on the left (e.g. RTL systems). Use 549 // Firefox with layout.scrollbar.side = 3 in about:config to test this. 550 function setLeftRTLScrollbarOffset() { 551 offsets.x = getWindowScrollBarX(documentElement); 552 } 553 if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) { 554 if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) { 555 scroll = getNodeScroll(offsetParent); 556 } 557 if (isOffsetParentAnElement) { 558 const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent); 559 offsets.x = offsetRect.x + offsetParent.clientLeft; 560 offsets.y = offsetRect.y + offsetParent.clientTop; 561 } else if (documentElement) { 562 setLeftRTLScrollbarOffset(); 563 } 564 } 565 if (isFixed && !isOffsetParentAnElement && documentElement) {
vendor: 5,458 bytes, lines 566-733
566 setLeftRTLScrollbarOffset(); 567 } 568 const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0); 569 const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x; 570 const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y; 571 return { 572 x, 573 y, 574 width: rect.width, 575 height: rect.height 576 }; 577} 578 579function isStaticPositioned(element) { 580 return getComputedStyle(element).position === 'static'; 581} 582 583function getTrueOffsetParent(element, polyfill) { 584 if (!isHTMLElement(element) || getComputedStyle(element).position === 'fixed') { 585 return null; 586 } 587 if (polyfill) { 588 return polyfill(element); 589 } 590 let rawOffsetParent = element.offsetParent; 591 592 // Firefox returns the <html> element as the offsetParent if it's non-static, 593 // while Chrome and Safari return the <body> element. The <body> element must 594 // be used to perform the correct calculations even if the <html> element is 595 // non-static. 596 if (getDocumentElement(element) === rawOffsetParent) { 597 rawOffsetParent = rawOffsetParent.ownerDocument.body; 598 } 599 return rawOffsetParent; 600} 601 602// Gets the closest ancestor positioned element. Handles some edge cases, 603// such as table ancestors and cross browser bugs. 604function getOffsetParent(element, polyfill) { 605 const win = getWindow(element); 606 if (isTopLayer(element)) { 607 return win; 608 } 609 if (!isHTMLElement(element)) { 610 let svgOffsetParent = getParentNode(element); 611 while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) { 612 if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) { 613 return svgOffsetParent; 614 } 615 svgOffsetParent = getParentNode(svgOffsetParent); 616 } 617 return win; 618 } 619 let offsetParent = getTrueOffsetParent(element, polyfill); 620 while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) { 621 offsetParent = getTrueOffsetParent(offsetParent, polyfill); 622 } 623 if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) { 624 return win; 625 } 626 return offsetParent || getContainingBlock(element) || win; 627} 628 629const getElementRects = async function (data) { 630 const getOffsetParentFn = this.getOffsetParent || getOffsetParent; 631 const getDimensionsFn = this.getDimensions; 632 const floatingDimensions = await getDimensionsFn(data.floating); 633 return { 634 reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy), 635 floating: { 636 x: 0, 637 y: 0, 638 width: floatingDimensions.width, 639 height: floatingDimensions.height 640 } 641 }; 642}; 643 644function isRTL(element) { 645 return getComputedStyle(element).direction === 'rtl'; 646} 647 648const platform = { 649 convertOffsetParentRelativeRectToViewportRelativeRect, 650 getDocumentElement, 651 getClippingRect, 652 getOffsetParent, 653 getElementRects, 654 getClientRects, 655 getDimensions, 656 getScale, 657 isElement, 658 isRTL 659}; 660 661function rectsAreEqual(a, b) { 662 return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height; 663} 664 665// https://samthor.au/2021/observing-dom/ 666function observeMove(element, onMove) { 667 let io = null; 668 let timeoutId; 669 const root = getDocumentElement(element); 670 function cleanup() { 671 var _io; 672 clearTimeout(timeoutId); 673 (_io = io) == null || _io.disconnect(); 674 io = null; 675 } 676 function refresh(skip, threshold) { 677 if (skip === void 0) { 678 skip = false; 679 } 680 if (threshold === void 0) { 681 threshold = 1; 682 } 683 cleanup(); 684 const elementRectForRootMargin = element.getBoundingClientRect(); 685 const { 686 left, 687 top, 688 width, 689 height 690 } = elementRectForRootMargin; 691 if (!skip) { 692 onMove(); 693 } 694 if (!width || !height) { 695 return; 696 } 697 const insetTop = floor(top); 698 const insetRight = floor(root.clientWidth - (left + width)); 699 const insetBottom = floor(root.clientHeight - (top + height)); 700 const insetLeft = floor(left); 701 const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px"; 702 const options = { 703 rootMargin, 704 threshold: max(0, min(1, threshold)) || 1 705 }; 706 let isFirstUpdate = true; 707 function handleObserve(entries) { 708 const ratio = entries[0].intersectionRatio; 709 if (ratio !== threshold) { 710 if (!isFirstUpdate) { 711 return refresh(); 712 } 713 if (!ratio) { 714 // If the reference is clipped, the ratio is 0. Throttle the refresh 715 // to prevent an infinite loop of updates. 716 timeoutId = setTimeout(() => { 717 refresh(false, 1e-7); 718 }, 1000); 719 } else { 720 refresh(false, ratio); 721 } 722 } 723 if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) { 724 // It's possible that even though the ratio is reported as 1, the 725 // element is not actually fully within the IntersectionObserver's root 726 // area anymore. This can happen under performance constraints. This may 727 // be a bug in the browser's IntersectionObserver implementation. To 728 // work around this, we compare the element's bounding rect now with 729 // what it was at the time we created the IntersectionObserver. If they 730 // are not equal then the element moved, so we refresh. 731 refresh(); 732 } 733 isFirstUpdate = false;
vendor: 5,694 bytes, lines 734-903
734 } 735 736 // Older browsers don't support a `document` as the root and will throw an 737 // error. 738 try { 739 io = new IntersectionObserver(handleObserve, { 740 ...options, 741 // Handle <iframe>s 742 root: root.ownerDocument 743 }); 744 } catch (_e) { 745 io = new IntersectionObserver(handleObserve, options); 746 } 747 io.observe(element); 748 } 749 refresh(true); 750 return cleanup; 751} 752 753/** 754 * Automatically updates the position of the floating element when necessary. 755 * Should only be called when the floating element is mounted on the DOM or 756 * visible on the screen. 757 * @returns cleanup function that should be invoked when the floating element is 758 * removed from the DOM or hidden from the screen. 759 * @see https://floating-ui.com/docs/autoUpdate 760 */ 761function autoUpdate(reference, floating, update, options) { 762 if (options === void 0) { 763 options = {}; 764 } 765 const { 766 ancestorScroll = true, 767 ancestorResize = true, 768 elementResize = typeof ResizeObserver === 'function', 769 layoutShift = typeof IntersectionObserver === 'function', 770 animationFrame = false 771 } = options; 772 const referenceEl = unwrapElement(reference); 773 const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : []; 774 ancestors.forEach(ancestor => { 775 ancestorScroll && ancestor.addEventListener('scroll', update, { 776 passive: true 777 }); 778 ancestorResize && ancestor.addEventListener('resize', update); 779 }); 780 const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null; 781 let reobserveFrame = -1; 782 let resizeObserver = null; 783 if (elementResize) { 784 resizeObserver = new ResizeObserver(_ref => { 785 let [firstEntry] = _ref; 786 if (firstEntry && firstEntry.target === referenceEl && resizeObserver) { 787 // Prevent update loops when using the `size` middleware. 788 // https://github.com/floating-ui/floating-ui/issues/1740 789 resizeObserver.unobserve(floating); 790 cancelAnimationFrame(reobserveFrame); 791 reobserveFrame = requestAnimationFrame(() => { 792 var _resizeObserver; 793 (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating); 794 }); 795 } 796 update(); 797 }); 798 if (referenceEl && !animationFrame) { 799 resizeObserver.observe(referenceEl); 800 } 801 resizeObserver.observe(floating); 802 } 803 let frameId; 804 let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null; 805 if (animationFrame) { 806 frameLoop(); 807 } 808 function frameLoop() { 809 const nextRefRect = getBoundingClientRect(reference); 810 if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) { 811 update(); 812 } 813 prevRefRect = nextRefRect; 814 frameId = requestAnimationFrame(frameLoop); 815 } 816 update(); 817 return () => { 818 var _resizeObserver2; 819 ancestors.forEach(ancestor => { 820 ancestorScroll && ancestor.removeEventListener('scroll', update); 821 ancestorResize && ancestor.removeEventListener('resize', update); 822 }); 823 cleanupIo == null || cleanupIo(); 824 (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect(); 825 resizeObserver = null; 826 if (animationFrame) { 827 cancelAnimationFrame(frameId); 828 } 829 }; 830} 831 832/** 833 * Resolves with an object of overflow side offsets that determine how much the 834 * element is overflowing a given clipping boundary on each side. 835 * - positive = overflowing the boundary by that number of pixels 836 * - negative = how many pixels left before it will overflow 837 * - 0 = lies flush with the boundary 838 * @see https://floating-ui.com/docs/detectOverflow 839 */ 840const detectOverflow = detectOverflow$1; 841 842/** 843 * Modifies the placement by translating the floating element along the 844 * specified axes. 845 * A number (shorthand for `mainAxis` or distance), or an axes configuration 846 * object may be passed. 847 * @see https://floating-ui.com/docs/offset 848 */ 849const offset = offset$1; 850 851/** 852 * Optimizes the visibility of the floating element by choosing the placement 853 * that has the most space available automatically, without needing to specify a 854 * preferred placement. Alternative to `flip`. 855 * @see https://floating-ui.com/docs/autoPlacement 856 */ 857const autoPlacement = autoPlacement$1; 858 859/** 860 * Optimizes the visibility of the floating element by shifting it in order to 861 * keep it in view when it will overflow the clipping boundary. 862 * @see https://floating-ui.com/docs/shift 863 */ 864const shift = shift$1; 865 866/** 867 * Optimizes the visibility of the floating element by flipping the `placement` 868 * in order to keep it in view when the preferred placement(s) will overflow the 869 * clipping boundary. Alternative to `autoPlacement`. 870 * @see https://floating-ui.com/docs/flip 871 */ 872const flip = flip$1; 873 874/** 875 * Provides data that allows you to change the size of the floating element â 876 * for instance, prevent it from overflowing the clipping boundary or match the 877 * width of the reference element. 878 * @see https://floating-ui.com/docs/size 879 */ 880const size = size$1; 881 882/** 883 * Provides data to hide the floating element in applicable situations, such as 884 * when it is not in the same clipping context as the reference element. 885 * @see https://floating-ui.com/docs/hide 886 */ 887const hide = hide$1; 888 889/** 890 * Provides data to position an inner element of the floating element so that it 891 * appears centered to the reference element. 892 * @see https://floating-ui.com/docs/arrow 893 */ 894const arrow = arrow$1; 895 896/** 897 * Provides improved positioning for inline reference elements that can span 898 * over multiple lines, such as hyperlinks or range selections. 899 * @see https://floating-ui.com/docs/inline 900 */ 901const inline = inline$1; 902 903/**
904 * Built-in `limiter` that will stop `shift()` at a certain point. 905 */ 906const limitShift = limitShift$1; 907 908/** 909 * Computes the `x` and `y` coordinates that will place the floating element 910 * next to a given reference element. 911 */ 912const computePosition = (reference, floating, options) => { 913 // This caches the expensive `getClippingElementAncestors` function so that 914 // multiple lifecycle resets re-use the same result. It only lives for a 915 // single call. If other functions become expensive, we can add them as well. 916 const cache = new Map(); 917 const mergedOptions = { 918 platform, 919 ...options 920 }; 921 const platformWithCache = { 922 ...mergedOptions.platform, 923 _c: cache 924 }; 925 return computePosition$1(reference, floating, { 926 ...mergedOptions, 927 platform: platformWithCache 928 }); 929}; 930 931export { arrow, autoPlacement, autoUpdate, computePosition, detectOverflow, flip, getOverflowAncestors, hide, inline, limitShift, offset, platform, shift, size };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.