vrembem 1.36.1 → 1.37.0

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.
@@ -106,6 +106,28 @@ class FocusTrap {
106
106
  this.target = null;
107
107
  }
108
108
 
109
+ refresh() {
110
+ // Check if a target has been set
111
+ if (!this.target) return; // Remove existing events
112
+
113
+ this.target.removeEventListener('keydown', this.__handlerFocusTrap);
114
+ this.target.removeEventListener('keydown', this.handlerFocusLock); // Get the focusable elements
115
+
116
+ this.focusable = this.getFocusable(); // Setup the focus handlers based on focusable length
117
+
118
+ if (this.focusable.length) {
119
+ // If there are focusable elements, setup focus trap
120
+ this.focusableFirst = this.focusable[0];
121
+ this.focusableLast = this.focusable[this.focusable.length - 1];
122
+ this.target.addEventListener('keydown', this.__handlerFocusTrap);
123
+ } else {
124
+ // If there are no focusable elements, setup focus lock
125
+ this.focusableFirst = null;
126
+ this.focusableLast = null;
127
+ this.target.addEventListener('keydown', this.handlerFocusLock);
128
+ }
129
+ }
130
+
109
131
  handlerFocusTrap(event) {
110
132
  const isTab = event.key === 'Tab' || event.keyCode === 9;
111
133
  if (!isTab) return;
@@ -792,6 +814,7 @@ class Drawer {
792
814
 
793
815
  focusTarget(drawer, this.settings);
794
816
  drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
817
+ detail: this,
795
818
  bubbles: true
796
819
  }));
797
820
  this.working = false;
@@ -819,6 +842,7 @@ class Drawer {
819
842
  focusTrigger(this);
820
843
  this.focusTrap.destroy();
821
844
  drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
845
+ detail: this,
822
846
  bubbles: true
823
847
  }));
824
848
  this.working = false;
@@ -1012,6 +1036,7 @@ class Modal {
1012
1036
  focusTarget(modal, this.settings);
1013
1037
  setInert(true, this.settings.selectorInert);
1014
1038
  modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
1039
+ detail: this,
1015
1040
  bubbles: true
1016
1041
  }));
1017
1042
  this.working = false;
@@ -1032,6 +1057,7 @@ class Modal {
1032
1057
  if (returnFocus) focusTrigger(this);
1033
1058
  this.focusTrap.destroy();
1034
1059
  modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
1060
+ detail: this,
1035
1061
  bubbles: true
1036
1062
  }));
1037
1063
  this.working = false;
@@ -1438,17 +1464,39 @@ function getBasePlacement(placement) {
1438
1464
  return placement.split('-')[0];
1439
1465
  }
1440
1466
 
1441
- function getBoundingClientRect(element) {
1467
+ // import { isHTMLElement } from './instanceOf';
1468
+ function getBoundingClientRect(element, // eslint-disable-next-line unused-imports/no-unused-vars
1469
+ includeScale) {
1470
+
1442
1471
  var rect = element.getBoundingClientRect();
1472
+ var scaleX = 1;
1473
+ var scaleY = 1; // FIXME:
1474
+ // `offsetWidth` returns an integer while `getBoundingClientRect`
1475
+ // returns a float. This results in `scaleX` or `scaleY` being
1476
+ // non-1 when it should be for elements that aren't a full pixel in
1477
+ // width or height.
1478
+ // if (isHTMLElement(element) && includeScale) {
1479
+ // const offsetHeight = element.offsetHeight;
1480
+ // const offsetWidth = element.offsetWidth;
1481
+ // // Do not attempt to divide by 0, otherwise we get `Infinity` as scale
1482
+ // // Fallback to 1 in case both values are `0`
1483
+ // if (offsetWidth > 0) {
1484
+ // scaleX = rect.width / offsetWidth || 1;
1485
+ // }
1486
+ // if (offsetHeight > 0) {
1487
+ // scaleY = rect.height / offsetHeight || 1;
1488
+ // }
1489
+ // }
1490
+
1443
1491
  return {
1444
- width: rect.width,
1445
- height: rect.height,
1446
- top: rect.top,
1447
- right: rect.right,
1448
- bottom: rect.bottom,
1449
- left: rect.left,
1450
- x: rect.left,
1451
- y: rect.top
1492
+ width: rect.width / scaleX,
1493
+ height: rect.height / scaleY,
1494
+ top: rect.top / scaleY,
1495
+ right: rect.right / scaleX,
1496
+ bottom: rect.bottom / scaleY,
1497
+ left: rect.left / scaleX,
1498
+ x: rect.left / scaleX,
1499
+ y: rect.top / scaleY
1452
1500
  };
1453
1501
  }
1454
1502
 
@@ -1703,6 +1751,10 @@ var arrow$1 = {
1703
1751
  requiresIfExists: ['preventOverflow']
1704
1752
  };
1705
1753
 
1754
+ function getVariation(placement) {
1755
+ return placement.split('-')[1];
1756
+ }
1757
+
1706
1758
  var unsetSides = {
1707
1759
  top: 'auto',
1708
1760
  right: 'auto',
@@ -1729,6 +1781,7 @@ function mapToStyles(_ref2) {
1729
1781
  var popper = _ref2.popper,
1730
1782
  popperRect = _ref2.popperRect,
1731
1783
  placement = _ref2.placement,
1784
+ variation = _ref2.variation,
1732
1785
  offsets = _ref2.offsets,
1733
1786
  position = _ref2.position,
1734
1787
  gpuAcceleration = _ref2.gpuAcceleration,
@@ -1755,7 +1808,7 @@ function mapToStyles(_ref2) {
1755
1808
  if (offsetParent === getWindow(popper)) {
1756
1809
  offsetParent = getDocumentElement(popper);
1757
1810
 
1758
- if (getComputedStyle$1(offsetParent).position !== 'static') {
1811
+ if (getComputedStyle$1(offsetParent).position !== 'static' && position === 'absolute') {
1759
1812
  heightProp = 'scrollHeight';
1760
1813
  widthProp = 'scrollWidth';
1761
1814
  }
@@ -1764,14 +1817,14 @@ function mapToStyles(_ref2) {
1764
1817
 
1765
1818
  offsetParent = offsetParent;
1766
1819
 
1767
- if (placement === top) {
1820
+ if (placement === top || (placement === left || placement === right) && variation === end) {
1768
1821
  sideY = bottom; // $FlowFixMe[prop-missing]
1769
1822
 
1770
1823
  y -= offsetParent[heightProp] - popperRect.height;
1771
1824
  y *= gpuAcceleration ? 1 : -1;
1772
1825
  }
1773
1826
 
1774
- if (placement === left) {
1827
+ if (placement === left || (placement === top || placement === bottom) && variation === end) {
1775
1828
  sideX = right; // $FlowFixMe[prop-missing]
1776
1829
 
1777
1830
  x -= offsetParent[widthProp] - popperRect.width;
@@ -1786,7 +1839,7 @@ function mapToStyles(_ref2) {
1786
1839
  if (gpuAcceleration) {
1787
1840
  var _Object$assign;
1788
1841
 
1789
- return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? '0' : '', _Object$assign[sideX] = hasX ? '0' : '', _Object$assign.transform = (win.devicePixelRatio || 1) < 2 ? "translate(" + x + "px, " + y + "px)" : "translate3d(" + x + "px, " + y + "px, 0)", _Object$assign));
1842
+ return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? '0' : '', _Object$assign[sideX] = hasX ? '0' : '', _Object$assign.transform = (win.devicePixelRatio || 1) <= 1 ? "translate(" + x + "px, " + y + "px)" : "translate3d(" + x + "px, " + y + "px, 0)", _Object$assign));
1790
1843
  }
1791
1844
 
1792
1845
  return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
@@ -1804,6 +1857,7 @@ function computeStyles(_ref4) {
1804
1857
 
1805
1858
  var commonStyles = {
1806
1859
  placement: getBasePlacement(state.placement),
1860
+ variation: getVariation(state.placement),
1807
1861
  popper: state.elements.popper,
1808
1862
  popperRect: state.rects.popper,
1809
1863
  gpuAcceleration: gpuAcceleration
@@ -2106,10 +2160,6 @@ function getClippingRect(element, boundary, rootBoundary) {
2106
2160
  return clippingRect;
2107
2161
  }
2108
2162
 
2109
- function getVariation(placement) {
2110
- return placement.split('-')[1];
2111
- }
2112
-
2113
2163
  function computeOffsets(_ref) {
2114
2164
  var reference = _ref.reference,
2115
2165
  element = _ref.element,
@@ -2195,11 +2245,10 @@ function detectOverflow(state, options) {
2195
2245
  padding = _options$padding === void 0 ? 0 : _options$padding;
2196
2246
  var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
2197
2247
  var altContext = elementContext === popper ? reference : popper;
2198
- var referenceElement = state.elements.reference;
2199
2248
  var popperRect = state.rects.popper;
2200
2249
  var element = state.elements[altBoundary ? altContext : elementContext];
2201
2250
  var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
2202
- var referenceClientRect = getBoundingClientRect(referenceElement);
2251
+ var referenceClientRect = getBoundingClientRect(state.elements.reference);
2203
2252
  var popperOffsets = computeOffsets({
2204
2253
  reference: referenceClientRect,
2205
2254
  element: popperRect,
@@ -2676,16 +2725,24 @@ function getNodeScroll(node) {
2676
2725
  }
2677
2726
  }
2678
2727
 
2728
+ function isElementScaled(element) {
2729
+ var rect = element.getBoundingClientRect();
2730
+ var scaleX = rect.width / element.offsetWidth || 1;
2731
+ var scaleY = rect.height / element.offsetHeight || 1;
2732
+ return scaleX !== 1 || scaleY !== 1;
2733
+ } // Returns the composite rect of an element relative to its offsetParent.
2679
2734
  // Composite means it takes into account transforms as well as layout.
2680
2735
 
2736
+
2681
2737
  function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
2682
2738
  if (isFixed === void 0) {
2683
2739
  isFixed = false;
2684
2740
  }
2685
2741
 
2742
+ var isOffsetParentAnElement = isHTMLElement(offsetParent);
2743
+ isHTMLElement(offsetParent) && isElementScaled(offsetParent);
2686
2744
  var documentElement = getDocumentElement(offsetParent);
2687
2745
  var rect = getBoundingClientRect(elementOrVirtualElement);
2688
- var isOffsetParentAnElement = isHTMLElement(offsetParent);
2689
2746
  var scroll = {
2690
2747
  scrollLeft: 0,
2691
2748
  scrollTop: 0
@@ -2839,7 +2896,8 @@ function popperGenerator(generatorOptions) {
2839
2896
  var isDestroyed = false;
2840
2897
  var instance = {
2841
2898
  state: state,
2842
- setOptions: function setOptions(options) {
2899
+ setOptions: function setOptions(setOptionsAction) {
2900
+ var options = typeof setOptionsAction === 'function' ? setOptionsAction(state.options) : setOptionsAction;
2843
2901
  cleanupModifierEffects();
2844
2902
  state.options = Object.assign({}, defaultOptions, state.options, options);
2845
2903
  state.scrollParents = {