vrembem 1.35.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.
@@ -58,6 +58,8 @@ const camelCase = str => {
58
58
  });
59
59
  };
60
60
 
61
+ var focusableSelectors = ['a[href]:not([tabindex^="-"])', 'area[href]:not([tabindex^="-"])', 'input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])', 'input[type="radio"]:not([disabled]):not([tabindex^="-"])', 'select:not([disabled]):not([tabindex^="-"])', 'textarea:not([disabled]):not([tabindex^="-"])', 'button:not([disabled]):not([tabindex^="-"])', 'iframe:not([tabindex^="-"])', 'audio[controls]:not([tabindex^="-"])', 'video[controls]:not([tabindex^="-"])', '[contenteditable]:not([tabindex^="-"])', '[tabindex]:not([tabindex^="-"])'];
62
+
61
63
  const focusTarget = (target, settings) => {
62
64
  const innerFocus = target.querySelector(`[data-${settings.dataFocus}]`);
63
65
 
@@ -104,6 +106,28 @@ class FocusTrap {
104
106
  this.target = null;
105
107
  }
106
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
+
107
131
  handlerFocusTrap(event) {
108
132
  const isTab = event.key === 'Tab' || event.keyCode === 9;
109
133
  if (!isTab) return;
@@ -130,7 +154,7 @@ class FocusTrap {
130
154
  const focusable = [];
131
155
  const initFocus = document.activeElement;
132
156
  const initScrollTop = this.inner ? this.inner.scrollTop : 0;
133
- this.target.querySelectorAll('a[href]:not([disabled]),button:not([disabled]),textarea:not([disabled]),input[type="text"]:not([disabled]),input[type="radio"]:not([disabled]),input[type="checkbox"]:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])').forEach(el => {
157
+ this.target.querySelectorAll(focusableSelectors.join(',')).forEach(el => {
134
158
  el.focus();
135
159
 
136
160
  if (el === document.activeElement) {
@@ -790,6 +814,7 @@ class Drawer {
790
814
 
791
815
  focusTarget(drawer, this.settings);
792
816
  drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
817
+ detail: this,
793
818
  bubbles: true
794
819
  }));
795
820
  this.working = false;
@@ -817,6 +842,7 @@ class Drawer {
817
842
  focusTrigger(this);
818
843
  this.focusTrap.destroy();
819
844
  drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
845
+ detail: this,
820
846
  bubbles: true
821
847
  }));
822
848
  this.working = false;
@@ -1010,6 +1036,7 @@ class Modal {
1010
1036
  focusTarget(modal, this.settings);
1011
1037
  setInert(true, this.settings.selectorInert);
1012
1038
  modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
1039
+ detail: this,
1013
1040
  bubbles: true
1014
1041
  }));
1015
1042
  this.working = false;
@@ -1030,6 +1057,7 @@ class Modal {
1030
1057
  if (returnFocus) focusTrigger(this);
1031
1058
  this.focusTrap.destroy();
1032
1059
  modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
1060
+ detail: this,
1033
1061
  bubbles: true
1034
1062
  }));
1035
1063
  this.working = false;
@@ -1436,17 +1464,39 @@ function getBasePlacement(placement) {
1436
1464
  return placement.split('-')[0];
1437
1465
  }
1438
1466
 
1439
- function getBoundingClientRect(element) {
1467
+ // import { isHTMLElement } from './instanceOf';
1468
+ function getBoundingClientRect(element, // eslint-disable-next-line unused-imports/no-unused-vars
1469
+ includeScale) {
1470
+
1440
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
+
1441
1491
  return {
1442
- width: rect.width,
1443
- height: rect.height,
1444
- top: rect.top,
1445
- right: rect.right,
1446
- bottom: rect.bottom,
1447
- left: rect.left,
1448
- x: rect.left,
1449
- 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
1450
1500
  };
1451
1501
  }
1452
1502
 
@@ -1701,6 +1751,10 @@ var arrow$1 = {
1701
1751
  requiresIfExists: ['preventOverflow']
1702
1752
  };
1703
1753
 
1754
+ function getVariation(placement) {
1755
+ return placement.split('-')[1];
1756
+ }
1757
+
1704
1758
  var unsetSides = {
1705
1759
  top: 'auto',
1706
1760
  right: 'auto',
@@ -1727,6 +1781,7 @@ function mapToStyles(_ref2) {
1727
1781
  var popper = _ref2.popper,
1728
1782
  popperRect = _ref2.popperRect,
1729
1783
  placement = _ref2.placement,
1784
+ variation = _ref2.variation,
1730
1785
  offsets = _ref2.offsets,
1731
1786
  position = _ref2.position,
1732
1787
  gpuAcceleration = _ref2.gpuAcceleration,
@@ -1753,7 +1808,7 @@ function mapToStyles(_ref2) {
1753
1808
  if (offsetParent === getWindow(popper)) {
1754
1809
  offsetParent = getDocumentElement(popper);
1755
1810
 
1756
- if (getComputedStyle$1(offsetParent).position !== 'static') {
1811
+ if (getComputedStyle$1(offsetParent).position !== 'static' && position === 'absolute') {
1757
1812
  heightProp = 'scrollHeight';
1758
1813
  widthProp = 'scrollWidth';
1759
1814
  }
@@ -1762,14 +1817,14 @@ function mapToStyles(_ref2) {
1762
1817
 
1763
1818
  offsetParent = offsetParent;
1764
1819
 
1765
- if (placement === top) {
1820
+ if (placement === top || (placement === left || placement === right) && variation === end) {
1766
1821
  sideY = bottom; // $FlowFixMe[prop-missing]
1767
1822
 
1768
1823
  y -= offsetParent[heightProp] - popperRect.height;
1769
1824
  y *= gpuAcceleration ? 1 : -1;
1770
1825
  }
1771
1826
 
1772
- if (placement === left) {
1827
+ if (placement === left || (placement === top || placement === bottom) && variation === end) {
1773
1828
  sideX = right; // $FlowFixMe[prop-missing]
1774
1829
 
1775
1830
  x -= offsetParent[widthProp] - popperRect.width;
@@ -1784,7 +1839,7 @@ function mapToStyles(_ref2) {
1784
1839
  if (gpuAcceleration) {
1785
1840
  var _Object$assign;
1786
1841
 
1787
- 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));
1788
1843
  }
1789
1844
 
1790
1845
  return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
@@ -1802,6 +1857,7 @@ function computeStyles(_ref4) {
1802
1857
 
1803
1858
  var commonStyles = {
1804
1859
  placement: getBasePlacement(state.placement),
1860
+ variation: getVariation(state.placement),
1805
1861
  popper: state.elements.popper,
1806
1862
  popperRect: state.rects.popper,
1807
1863
  gpuAcceleration: gpuAcceleration
@@ -2104,10 +2160,6 @@ function getClippingRect(element, boundary, rootBoundary) {
2104
2160
  return clippingRect;
2105
2161
  }
2106
2162
 
2107
- function getVariation(placement) {
2108
- return placement.split('-')[1];
2109
- }
2110
-
2111
2163
  function computeOffsets(_ref) {
2112
2164
  var reference = _ref.reference,
2113
2165
  element = _ref.element,
@@ -2193,11 +2245,10 @@ function detectOverflow(state, options) {
2193
2245
  padding = _options$padding === void 0 ? 0 : _options$padding;
2194
2246
  var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
2195
2247
  var altContext = elementContext === popper ? reference : popper;
2196
- var referenceElement = state.elements.reference;
2197
2248
  var popperRect = state.rects.popper;
2198
2249
  var element = state.elements[altBoundary ? altContext : elementContext];
2199
2250
  var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
2200
- var referenceClientRect = getBoundingClientRect(referenceElement);
2251
+ var referenceClientRect = getBoundingClientRect(state.elements.reference);
2201
2252
  var popperOffsets = computeOffsets({
2202
2253
  reference: referenceClientRect,
2203
2254
  element: popperRect,
@@ -2674,16 +2725,24 @@ function getNodeScroll(node) {
2674
2725
  }
2675
2726
  }
2676
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.
2677
2734
  // Composite means it takes into account transforms as well as layout.
2678
2735
 
2736
+
2679
2737
  function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
2680
2738
  if (isFixed === void 0) {
2681
2739
  isFixed = false;
2682
2740
  }
2683
2741
 
2742
+ var isOffsetParentAnElement = isHTMLElement(offsetParent);
2743
+ isHTMLElement(offsetParent) && isElementScaled(offsetParent);
2684
2744
  var documentElement = getDocumentElement(offsetParent);
2685
2745
  var rect = getBoundingClientRect(elementOrVirtualElement);
2686
- var isOffsetParentAnElement = isHTMLElement(offsetParent);
2687
2746
  var scroll = {
2688
2747
  scrollLeft: 0,
2689
2748
  scrollTop: 0
@@ -2837,7 +2896,8 @@ function popperGenerator(generatorOptions) {
2837
2896
  var isDestroyed = false;
2838
2897
  var instance = {
2839
2898
  state: state,
2840
- setOptions: function setOptions(options) {
2899
+ setOptions: function setOptions(setOptionsAction) {
2900
+ var options = typeof setOptionsAction === 'function' ? setOptionsAction(state.options) : setOptionsAction;
2841
2901
  cleanupModifierEffects();
2842
2902
  state.options = Object.assign({}, defaultOptions, state.options, options);
2843
2903
  state.scrollParents = {