@italia/popover 1.0.0-beta.6 → 1.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1176,7 +1176,7 @@ if (typeof window !== 'undefined') {
1176
1176
  window._itAnalytics = window._itAnalytics || {};
1177
1177
  window._itAnalytics = {
1178
1178
  ...window._itAnalytics,
1179
- version: '1.0.0-beta.6',
1179
+ version: '1.0.0-beta.8',
1180
1180
  };
1181
1181
  }
1182
1182
 
@@ -1277,12 +1277,12 @@ function getOppositePlacement(placement) {
1277
1277
  return oppositeSideMap[side] + placement.slice(side.length);
1278
1278
  }
1279
1279
  function expandPaddingObject(padding) {
1280
+ var _padding$top, _padding$right, _padding$bottom, _padding$left;
1280
1281
  return {
1281
- top: 0,
1282
- right: 0,
1283
- bottom: 0,
1284
- left: 0,
1285
- ...padding
1282
+ top: (_padding$top = padding.top) != null ? _padding$top : 0,
1283
+ right: (_padding$right = padding.right) != null ? _padding$right : 0,
1284
+ bottom: (_padding$bottom = padding.bottom) != null ? _padding$bottom : 0,
1285
+ left: (_padding$left = padding.left) != null ? _padding$left : 0
1286
1286
  };
1287
1287
  }
1288
1288
  function getPaddingObject(padding) {
@@ -1357,13 +1357,9 @@ function computeCoordsFromPlacement(_ref, placement, rtl) {
1357
1357
  y: reference.y
1358
1358
  };
1359
1359
  }
1360
- switch (getAlignment(placement)) {
1361
- case 'start':
1362
- coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
1363
- break;
1364
- case 'end':
1365
- coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
1366
- break;
1360
+ const alignment = getAlignment(placement);
1361
+ if (alignment) {
1362
+ coords[alignmentAxis] += commonAlign * (alignment === 'end' ? 1 : -1) * (rtl && isVertical ? -1 : 1);
1367
1363
  }
1368
1364
  return coords;
1369
1365
  }
@@ -1412,10 +1408,7 @@ async function detectOverflow(state, options) {
1412
1408
  height: rects.floating.height
1413
1409
  } : rects.reference;
1414
1410
  const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
1415
- const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
1416
- x: 1,
1417
- y: 1
1418
- } : {
1411
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) && (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
1419
1412
  x: 1,
1420
1413
  y: 1
1421
1414
  };
@@ -1588,17 +1581,16 @@ const arrow$1 = options => ({
1588
1581
 
1589
1582
  // Make sure the arrow doesn't overflow the floating element if the center
1590
1583
  // point is outside the floating element's bounds.
1591
- const min$1 = minPadding;
1592
1584
  const max = clientSize - arrowDimensions[length] - maxPadding;
1593
1585
  const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
1594
- const offset = clamp(min$1, center, max);
1586
+ const offset = clamp(minPadding, center, max);
1595
1587
 
1596
1588
  // If the reference is small enough that the arrow's padding causes it to
1597
1589
  // to point to nothing for an aligned placement, adjust the offset of the
1598
1590
  // floating element itself. To ensure `shift()` continues to take action,
1599
1591
  // a single reset is performed when this is true.
1600
- const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
1601
- const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
1592
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < minPadding ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
1593
+ const alignmentOffset = shouldAddOffset ? center < minPadding ? center - minPadding : center - max : 0;
1602
1594
  return {
1603
1595
  [axis]: coords[axis] + alignmentOffset,
1604
1596
  data: {
@@ -1872,23 +1864,16 @@ const shift$1 = function (options) {
1872
1864
  y
1873
1865
  };
1874
1866
  const overflow = await platform.detectOverflow(state, detectOverflowOptions);
1875
- const crossAxis = getSideAxis(getSide(placement));
1867
+ const crossAxis = getSideAxis(placement);
1876
1868
  const mainAxis = getOppositeAxis(crossAxis);
1877
1869
  let mainAxisCoord = coords[mainAxis];
1878
1870
  let crossAxisCoord = coords[crossAxis];
1871
+ const clampCoord = (axis, coord) => clamp(coord + overflow[axis === 'y' ? 'top' : 'left'], coord, coord - overflow[axis === 'y' ? 'bottom' : 'right']);
1879
1872
  if (checkMainAxis) {
1880
- const minSide = mainAxis === 'y' ? 'top' : 'left';
1881
- const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
1882
- const min = mainAxisCoord + overflow[minSide];
1883
- const max = mainAxisCoord - overflow[maxSide];
1884
- mainAxisCoord = clamp(min, mainAxisCoord, max);
1873
+ mainAxisCoord = clampCoord(mainAxis, mainAxisCoord);
1885
1874
  }
1886
1875
  if (checkCrossAxis) {
1887
- const minSide = crossAxis === 'y' ? 'top' : 'left';
1888
- const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
1889
- const min = crossAxisCoord + overflow[minSide];
1890
- const max = crossAxisCoord - overflow[maxSide];
1891
- crossAxisCoord = clamp(min, crossAxisCoord, max);
1876
+ crossAxisCoord = clampCoord(crossAxis, crossAxisCoord);
1892
1877
  }
1893
1878
  const limitedCoords = limiter.fn({
1894
1879
  ...state,
@@ -2045,7 +2030,7 @@ function getParentNode(node) {
2045
2030
  function getNearestOverflowAncestor(node) {
2046
2031
  const parentNode = getParentNode(node);
2047
2032
  if (isLastTraversableNode(parentNode)) {
2048
- return node.ownerDocument ? node.ownerDocument.body : node.body;
2033
+ return (node.ownerDocument || node).body;
2049
2034
  }
2050
2035
  if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
2051
2036
  return parentNode;
@@ -2142,10 +2127,7 @@ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
2142
2127
  if (isFixed === void 0) {
2143
2128
  isFixed = false;
2144
2129
  }
2145
- if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
2146
- return false;
2147
- }
2148
- return isFixed;
2130
+ return !!floatingOffsetParent && isFixed && floatingOffsetParent === getWindow(element);
2149
2131
  }
2150
2132
 
2151
2133
  function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
@@ -2172,12 +2154,12 @@ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetPar
2172
2154
  let y = (clientRect.top + visualOffsets.y) / scale.y;
2173
2155
  let width = clientRect.width / scale.x;
2174
2156
  let height = clientRect.height / scale.y;
2175
- if (domElement) {
2157
+ if (domElement && offsetParent) {
2176
2158
  const win = getWindow(domElement);
2177
- const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
2159
+ const offsetWin = isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
2178
2160
  let currentWin = win;
2179
2161
  let currentIFrame = getFrameElement(currentWin);
2180
- while (currentIFrame && offsetParent && offsetWin !== currentWin) {
2162
+ while (currentIFrame && offsetWin !== currentWin) {
2181
2163
  const iframeScale = getScale(currentIFrame);
2182
2164
  const iframeRect = currentIFrame.getBoundingClientRect();
2183
2165
  const css = getComputedStyle$1(currentIFrame);
@@ -2241,7 +2223,7 @@ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
2241
2223
  let scale = createCoords(1);
2242
2224
  const offsets = createCoords(0);
2243
2225
  const isOffsetParentAnElement = isHTMLElement(offsetParent);
2244
- if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2226
+ if (isOffsetParentAnElement || !isFixed) {
2245
2227
  if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
2246
2228
  scroll = getNodeScroll(offsetParent);
2247
2229
  }
@@ -2262,18 +2244,17 @@ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
2262
2244
  }
2263
2245
 
2264
2246
  function getClientRects(element) {
2265
- return Array.from(element.getClientRects());
2247
+ return element.getClientRects ? Array.from(element.getClientRects()) : [];
2266
2248
  }
2267
2249
 
2268
2250
  // Gets the entire size of the scrollable document area, even extending outside
2269
2251
  // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
2270
- function getDocumentRect(element) {
2271
- const html = getDocumentElement(element);
2272
- const scroll = getNodeScroll(element);
2273
- const body = element.ownerDocument.body;
2252
+ function getDocumentRect(html) {
2253
+ const scroll = getNodeScroll(html);
2254
+ const body = html.ownerDocument.body;
2274
2255
  const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
2275
2256
  const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
2276
- let x = -scroll.scrollLeft + getWindowScrollBarX(element);
2257
+ let x = -scroll.scrollLeft + getWindowScrollBarX(html);
2277
2258
  const y = -scroll.scrollTop;
2278
2259
  if (getComputedStyle$1(body).direction === 'rtl') {
2279
2260
  x += max(html.clientWidth, body.clientWidth) - width;
@@ -2290,7 +2271,11 @@ function getDocumentRect(element) {
2290
2271
  // calculation is affected by unusual styles.
2291
2272
  // Most scrollbars leave 15-18px of space.
2292
2273
  const SCROLLBAR_MAX = 25;
2293
- function getViewportRect(element, strategy) {
2274
+ function getViewportRect(element, strategy, rootBoundary) {
2275
+ if (rootBoundary === void 0) {
2276
+ rootBoundary = 'viewport';
2277
+ }
2278
+ const isLayoutViewport = rootBoundary === 'layoutViewport';
2294
2279
  const win = getWindow(element);
2295
2280
  const html = getDocumentElement(element);
2296
2281
  const visualViewport = win.visualViewport;
@@ -2299,31 +2284,42 @@ function getViewportRect(element, strategy) {
2299
2284
  let x = 0;
2300
2285
  let y = 0;
2301
2286
  if (visualViewport) {
2302
- width = visualViewport.width;
2303
- height = visualViewport.height;
2304
- const visualViewportBased = isWebKit();
2305
- if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
2306
- x = visualViewport.offsetLeft;
2307
- y = visualViewport.offsetTop;
2287
+ // Client coordinates are relative to the layout viewport, except in
2288
+ // WebKit with an `absolute` strategy, where they are relative to the
2289
+ // visual viewport.
2290
+ const layoutRelativeClientCoords = !isWebKit() || strategy === 'fixed';
2291
+ if (isLayoutViewport) {
2292
+ if (!layoutRelativeClientCoords) {
2293
+ x = -visualViewport.offsetLeft;
2294
+ y = -visualViewport.offsetTop;
2295
+ }
2296
+ } else {
2297
+ width = visualViewport.width;
2298
+ height = visualViewport.height;
2299
+ if (layoutRelativeClientCoords) {
2300
+ x = visualViewport.offsetLeft;
2301
+ y = visualViewport.offsetTop;
2302
+ }
2308
2303
  }
2309
2304
  }
2310
2305
  const windowScrollbarX = getWindowScrollBarX(html);
2311
- // <html> `overflow: hidden` + `scrollbar-gutter: stable` reduces the
2312
- // visual width of the <html> but this is not considered in the size
2313
- // of `html.clientWidth`.
2306
+ // `scrollbar-gutter: stable` on the <html> reserves gutter space that shrinks
2307
+ // the visual width but isn't reflected in `html.clientWidth`, so subtract it.
2308
+ // Only the inline-end (right) gutter can hold the scrollbar; `both-edges` also
2309
+ // reserves an empty inline-start gutter that clips nothing, so exclude just
2310
+ // the one scrollbar-side gutter — halve the measured (two-gutter) total. A
2311
+ // left-side scrollbar (`windowScrollbarX > 0`) is already handled by
2312
+ // `getHTMLOffset`/`visualViewport.width`; skip it here.
2314
2313
  if (windowScrollbarX <= 0) {
2315
2314
  const doc = html.ownerDocument;
2316
2315
  const body = doc.body;
2317
2316
  const bodyStyles = getComputedStyle(body);
2318
2317
  const bodyMarginInline = doc.compatMode === 'CSS1Compat' ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
2319
- const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
2320
- if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
2321
- width -= clippingStableScrollbarWidth;
2318
+ const reservedWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
2319
+ const gutter = getComputedStyle(html).scrollbarGutter === 'stable both-edges' ? reservedWidth / 2 : reservedWidth;
2320
+ if (gutter <= SCROLLBAR_MAX) {
2321
+ width -= gutter;
2322
2322
  }
2323
- } else if (windowScrollbarX <= SCROLLBAR_MAX) {
2324
- // If the <body> scrollbar is on the left, the width needs to be extended
2325
- // by the scrollbar amount so there isn't extra space on the right.
2326
- width += windowScrollbarX;
2327
2323
  }
2328
2324
  return {
2329
2325
  width,
@@ -2338,7 +2334,7 @@ function getInnerBoundingClientRect(element, strategy) {
2338
2334
  const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
2339
2335
  const top = clientRect.top + element.clientTop;
2340
2336
  const left = clientRect.left + element.clientLeft;
2341
- const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
2337
+ const scale = getScale(element);
2342
2338
  const width = element.clientWidth * scale.x;
2343
2339
  const height = element.clientHeight * scale.y;
2344
2340
  const x = left * scale.x;
@@ -2352,8 +2348,8 @@ function getInnerBoundingClientRect(element, strategy) {
2352
2348
  }
2353
2349
  function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
2354
2350
  let rect;
2355
- if (clippingAncestor === 'viewport') {
2356
- rect = getViewportRect(element, strategy);
2351
+ if (clippingAncestor === 'viewport' || clippingAncestor === 'layoutViewport') {
2352
+ rect = getViewportRect(element, strategy, clippingAncestor);
2357
2353
  } else if (clippingAncestor === 'document') {
2358
2354
  rect = getDocumentRect(getDocumentElement(element));
2359
2355
  } else if (isElement(clippingAncestor)) {
@@ -2369,13 +2365,6 @@ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy)
2369
2365
  }
2370
2366
  return rectToClientRect(rect);
2371
2367
  }
2372
- function hasFixedPositionAncestor(element, stopNode) {
2373
- const parentNode = getParentNode(element);
2374
- if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
2375
- return false;
2376
- }
2377
- return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
2378
- }
2379
2368
 
2380
2369
  // A "clipping ancestor" is an `overflow` element with the characteristic of
2381
2370
  // clipping (or hiding) child elements. This returns all clipping ancestors
@@ -2386,7 +2375,7 @@ function getClippingElementAncestors(element, cache) {
2386
2375
  return cachedResult;
2387
2376
  }
2388
2377
  let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
2389
- let currentContainingBlockComputedStyle = null;
2378
+ let lastKeptComputedStyle = null;
2390
2379
  const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
2391
2380
  let currentNode = elementIsFixed ? getParentNode(element) : element;
2392
2381
 
@@ -2394,16 +2383,20 @@ function getClippingElementAncestors(element, cache) {
2394
2383
  while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
2395
2384
  const computedStyle = getComputedStyle$1(currentNode);
2396
2385
  const currentNodeIsContaining = isContainingBlock(currentNode);
2397
- if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
2398
- currentContainingBlockComputedStyle = null;
2399
- }
2400
- const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && (currentContainingBlockComputedStyle.position === 'absolute' || currentContainingBlockComputedStyle.position === 'fixed') || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
2386
+ // Position of the containing block chain below the current node. A fixed
2387
+ // element whose containing block hasn't been found yet is a fixed chain.
2388
+ const lastPosition = lastKeptComputedStyle ? lastKeptComputedStyle.position : elementIsFixed ? 'fixed' : '';
2389
+
2390
+ // A non-containing ancestor does not clip the element when the chain
2391
+ // below it escapes it: a fixed chain escapes all ancestors up to the
2392
+ // next containing block, an absolute chain escapes static ancestors.
2393
+ const shouldDropCurrentNode = !currentNodeIsContaining && (lastPosition === 'fixed' || lastPosition === 'absolute' && computedStyle.position === 'static');
2401
2394
  if (shouldDropCurrentNode) {
2402
2395
  // Drop non-containing blocks.
2403
2396
  result = result.filter(ancestor => ancestor !== currentNode);
2404
2397
  } else {
2405
- // Record last containing block for next iteration.
2406
- currentContainingBlockComputedStyle = computedStyle;
2398
+ // The kept node carries the chain position for the next iteration.
2399
+ lastKeptComputedStyle = computedStyle;
2407
2400
  }
2408
2401
  currentNode = getParentNode(currentNode);
2409
2402
  }
@@ -2463,13 +2456,7 @@ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
2463
2456
  scrollTop: 0
2464
2457
  };
2465
2458
  const offsets = createCoords(0);
2466
-
2467
- // If the <body> scrollbar appears on the left (e.g. RTL systems). Use
2468
- // Firefox with layout.scrollbar.side = 3 in about:config to test this.
2469
- function setLeftRTLScrollbarOffset() {
2470
- offsets.x = getWindowScrollBarX(documentElement);
2471
- }
2472
- if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2459
+ if (isOffsetParentAnElement || !isFixed) {
2473
2460
  if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
2474
2461
  scroll = getNodeScroll(offsetParent);
2475
2462
  }
@@ -2477,12 +2464,13 @@ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
2477
2464
  const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
2478
2465
  offsets.x = offsetRect.x + offsetParent.clientLeft;
2479
2466
  offsets.y = offsetRect.y + offsetParent.clientTop;
2480
- } else if (documentElement) {
2481
- setLeftRTLScrollbarOffset();
2482
2467
  }
2483
2468
  }
2484
- if (isFixed && !isOffsetParentAnElement && documentElement) {
2485
- setLeftRTLScrollbarOffset();
2469
+
2470
+ // If the <body> scrollbar appears on the left (e.g. RTL systems). Use
2471
+ // Firefox with layout.scrollbar.side = 3 in about:config to test this.
2472
+ if (!isOffsetParentAnElement && documentElement) {
2473
+ offsets.x = getWindowScrollBarX(documentElement);
2486
2474
  }
2487
2475
  const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
2488
2476
  const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
@@ -2582,7 +2570,7 @@ function rectsAreEqual(a, b) {
2582
2570
  }
2583
2571
 
2584
2572
  // https://samthor.au/2021/observing-dom/
2585
- function observeMove(element, onMove) {
2573
+ function observeMove(element, onMove, ancestorResize) {
2586
2574
  let io = null;
2587
2575
  let timeoutId;
2588
2576
  const root = getDocumentElement(element);
@@ -2625,13 +2613,22 @@ function observeMove(element, onMove) {
2625
2613
  let isFirstUpdate = true;
2626
2614
  function handleObserve(entries) {
2627
2615
  const ratio = entries[0].intersectionRatio;
2616
+
2617
+ // The entry is a snapshot, so the reference may have moved since the
2618
+ // intersection was computed (under performance constraints, or between
2619
+ // consecutive frames of a multi-frame layout shift). The reported ratio
2620
+ // and the observed area are stale in that case and cannot be trusted to
2621
+ // detect subsequent movement, so refresh regardless of the ratio.
2622
+ if (!rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
2623
+ return refresh();
2624
+ }
2628
2625
  if (ratio !== threshold) {
2629
2626
  if (!isFirstUpdate) {
2630
2627
  return refresh();
2631
2628
  }
2632
2629
  if (!ratio) {
2633
- // If the reference is clipped, the ratio is 0. Throttle the refresh
2634
- // to prevent an infinite loop of updates.
2630
+ // If the reference is clipped in place, the ratio is 0. Throttle
2631
+ // the refresh to prevent an infinite loop of updates.
2635
2632
  timeoutId = setTimeout(() => {
2636
2633
  refresh(false, 1e-7);
2637
2634
  }, 1000);
@@ -2639,16 +2636,6 @@ function observeMove(element, onMove) {
2639
2636
  refresh(false, ratio);
2640
2637
  }
2641
2638
  }
2642
- if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
2643
- // It's possible that even though the ratio is reported as 1, the
2644
- // element is not actually fully within the IntersectionObserver's root
2645
- // area anymore. This can happen under performance constraints. This may
2646
- // be a bug in the browser's IntersectionObserver implementation. To
2647
- // work around this, we compare the element's bounding rect now with
2648
- // what it was at the time we created the IntersectionObserver. If they
2649
- // are not equal then the element moved, so we refresh.
2650
- refresh();
2651
- }
2652
2639
  isFirstUpdate = false;
2653
2640
  }
2654
2641
 
@@ -2665,8 +2652,18 @@ function observeMove(element, onMove) {
2665
2652
  }
2666
2653
  io.observe(element);
2667
2654
  }
2655
+ const win = getWindow(element);
2656
+ // The window is a resize ancestor, so when `ancestorResize` is enabled its
2657
+ // listener already runs the update on resize. Here we only need to rebuild
2658
+ // the `IntersectionObserver` for the new root size, skipping a redundant
2659
+ // update. When `ancestorResize` is disabled, this becomes the sole update.
2660
+ const handleResize = () => refresh(ancestorResize);
2661
+ win.addEventListener('resize', handleResize);
2668
2662
  refresh(true);
2669
- return cleanup;
2663
+ return () => {
2664
+ win.removeEventListener('resize', handleResize);
2665
+ cleanup();
2666
+ };
2670
2667
  }
2671
2668
 
2672
2669
  /**
@@ -2691,12 +2688,10 @@ function autoUpdate(reference, floating, update, options) {
2691
2688
  const referenceEl = unwrapElement(reference);
2692
2689
  const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...(floating ? getOverflowAncestors(floating) : [])] : [];
2693
2690
  ancestors.forEach(ancestor => {
2694
- ancestorScroll && ancestor.addEventListener('scroll', update, {
2695
- passive: true
2696
- });
2691
+ ancestorScroll && ancestor.addEventListener('scroll', update);
2697
2692
  ancestorResize && ancestor.addEventListener('resize', update);
2698
2693
  });
2699
- const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
2694
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update, ancestorResize) : null;
2700
2695
  let reobserveFrame = -1;
2701
2696
  let resizeObserver = null;
2702
2697
  if (elementResize) {
@@ -2790,11 +2785,9 @@ const computePosition = (reference, floating, options) => {
2790
2785
  // multiple lifecycle resets re-use the same result. It only lives for a
2791
2786
  // single call. If other functions become expensive, we can add them as well.
2792
2787
  const cache = new Map();
2793
- const mergedOptions = {
2794
- platform,
2795
- ...options
2796
- };
2788
+ const mergedOptions = options != null ? options : {};
2797
2789
  const platformWithCache = {
2790
+ ...platform,
2798
2791
  ...mergedOptions.platform,
2799
2792
  _c: cache
2800
2793
  };