vrembem 1.37.0 → 1.40.1

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.
@@ -356,14 +356,6 @@
356
356
  });
357
357
  };
358
358
 
359
- var breakpoints = {
360
- xs: '480px',
361
- sm: '620px',
362
- md: '760px',
363
- lg: '990px',
364
- xl: '1380px'
365
- };
366
-
367
359
  var index = {
368
360
  __proto__: null,
369
361
  setInert: setInert,
@@ -381,8 +373,7 @@
381
373
  removeClass: removeClass,
382
374
  toggleClass: toggleClass,
383
375
  openTransition: openTransition,
384
- closeTransition: closeTransition,
385
- breakpoints: breakpoints
376
+ closeTransition: closeTransition
386
377
  };
387
378
 
388
379
  function _extends() {
@@ -500,7 +491,7 @@
500
491
  selectorInert: null,
501
492
  selectorOverflow: null,
502
493
  // Feature toggles
503
- breakpoints: breakpoints,
494
+ breakpoints: null,
504
495
  customEventPrefix: 'drawer:',
505
496
  eventListeners: true,
506
497
  stateSave: true,
@@ -562,6 +553,7 @@
562
553
  function Breakpoint(parent) {
563
554
  this.mediaQueryLists = [];
564
555
  this.parent = parent;
556
+ this.prefix = this.getVariablePrefix();
565
557
  this.__check = this.check.bind(this);
566
558
  }
567
559
 
@@ -574,7 +566,9 @@
574
566
  drawers.forEach(function (drawer) {
575
567
  var id = drawer.getAttribute("data-" + _this.parent.settings.dataDrawer);
576
568
  var key = drawer.getAttribute("data-" + _this.parent.settings.dataBreakpoint);
577
- var bp = _this.parent.settings.breakpoints[key] ? _this.parent.settings.breakpoints[key] : key;
569
+
570
+ var bp = _this.getBreakpoint(key);
571
+
578
572
  var mql = window.matchMedia('(min-width:' + bp + ')');
579
573
 
580
574
  _this.match(mql, drawer);
@@ -630,6 +624,25 @@
630
624
  }
631
625
  };
632
626
 
627
+ _proto.getBreakpoint = function getBreakpoint(key) {
628
+ var breakpoint = key;
629
+
630
+ if (this.parent.settings.breakpoints && this.parent.settings.breakpoints[key]) {
631
+ breakpoint = this.parent.settings.breakpoints[key];
632
+ } else if (getComputedStyle(document.body).getPropertyValue(this.prefix + key)) {
633
+ breakpoint = getComputedStyle(document.body).getPropertyValue(this.prefix + key);
634
+ }
635
+
636
+ return breakpoint;
637
+ };
638
+
639
+ _proto.getVariablePrefix = function getVariablePrefix() {
640
+ var prefix = '--';
641
+ prefix += getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
642
+ prefix += 'breakpoint-';
643
+ return prefix;
644
+ };
645
+
633
646
  return Breakpoint;
634
647
  }();
635
648
 
@@ -1260,7 +1273,12 @@
1260
1273
  var index = obj.collection.findIndex(function (item) {
1261
1274
  return item.target === popover.target;
1262
1275
  });
1263
- obj.collection[index].state = 'hide'; // Return the popover
1276
+ obj.collection[index].state = 'hide'; // Clear the memory if popover trigger matches the ones saved in memory
1277
+
1278
+ if (popover.trigger === obj.memory.trigger) {
1279
+ obj.memory.trigger = null;
1280
+ } // Return the popover
1281
+
1264
1282
 
1265
1283
  return popover;
1266
1284
  }
@@ -1274,7 +1292,9 @@
1274
1292
  return obj.collection;
1275
1293
  }
1276
1294
  function hideCheck(popover, obj) {
1277
- // Needed to correctly check which element is currently being focused
1295
+ // Only run hideCheck if provided popover is currently open
1296
+ if (popover.state != 'show') return; // Needed to correctly check which element is currently being focused
1297
+
1278
1298
  setTimeout(function () {
1279
1299
  // Check if trigger or target are being hovered
1280
1300
  var isHovered = popover.target.closest(':hover') === popover.target || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or target are being focused
@@ -1306,7 +1326,8 @@
1306
1326
 
1307
1327
  for (var prop in config) {
1308
1328
  // Get the CSS variable property values
1309
- var val = styles.getPropertyValue("--popover-" + prop).trim(); // If a value was found, replace the default in config obj
1329
+ var prefix = getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
1330
+ var val = styles.getPropertyValue("--" + prefix + "popover-" + prop).trim(); // If a value was found, replace the default in config obj
1310
1331
 
1311
1332
  if (val) {
1312
1333
  config[prop] = val;
@@ -1443,13 +1464,31 @@
1443
1464
  if (popover.target.classList.contains(this.settings.stateActive)) {
1444
1465
  hide$2(popover, this);
1445
1466
  } else {
1467
+ this.memory.trigger = popover.trigger;
1446
1468
  show(popover, this);
1447
1469
  documentClick(popover, this);
1448
1470
  }
1449
1471
  }
1450
1472
  function handlerKeydown(event) {
1451
- if (event.key === 'Escape') {
1452
- hideAll(this);
1473
+ var _this = this;
1474
+
1475
+ switch (event.key) {
1476
+ case 'Escape':
1477
+ if (this.memory.trigger) {
1478
+ this.memory.trigger.focus();
1479
+ }
1480
+
1481
+ hideAll(this);
1482
+ return;
1483
+
1484
+ case 'Tab':
1485
+ this.collection.forEach(function (popover) {
1486
+ hideCheck(popover, _this);
1487
+ });
1488
+ return;
1489
+
1490
+ default:
1491
+ return;
1453
1492
  }
1454
1493
  }
1455
1494
  function documentClick(popover, obj) {
@@ -1627,29 +1666,32 @@
1627
1666
  return placement.split('-')[0];
1628
1667
  }
1629
1668
 
1630
- // import { isHTMLElement } from './instanceOf';
1631
- function getBoundingClientRect(element, // eslint-disable-next-line unused-imports/no-unused-vars
1632
- includeScale) {
1669
+ var max = Math.max;
1670
+ var min = Math.min;
1671
+ var round = Math.round;
1672
+
1673
+ function getBoundingClientRect(element, includeScale) {
1674
+ if (includeScale === void 0) {
1675
+ includeScale = false;
1676
+ }
1633
1677
 
1634
1678
  var rect = element.getBoundingClientRect();
1635
1679
  var scaleX = 1;
1636
- var scaleY = 1; // FIXME:
1637
- // `offsetWidth` returns an integer while `getBoundingClientRect`
1638
- // returns a float. This results in `scaleX` or `scaleY` being
1639
- // non-1 when it should be for elements that aren't a full pixel in
1640
- // width or height.
1641
- // if (isHTMLElement(element) && includeScale) {
1642
- // const offsetHeight = element.offsetHeight;
1643
- // const offsetWidth = element.offsetWidth;
1644
- // // Do not attempt to divide by 0, otherwise we get `Infinity` as scale
1645
- // // Fallback to 1 in case both values are `0`
1646
- // if (offsetWidth > 0) {
1647
- // scaleX = rect.width / offsetWidth || 1;
1648
- // }
1649
- // if (offsetHeight > 0) {
1650
- // scaleY = rect.height / offsetHeight || 1;
1651
- // }
1652
- // }
1680
+ var scaleY = 1;
1681
+
1682
+ if (isHTMLElement(element) && includeScale) {
1683
+ var offsetHeight = element.offsetHeight;
1684
+ var offsetWidth = element.offsetWidth; // Do not attempt to divide by 0, otherwise we get `Infinity` as scale
1685
+ // Fallback to 1 in case both values are `0`
1686
+
1687
+ if (offsetWidth > 0) {
1688
+ scaleX = round(rect.width) / offsetWidth || 1;
1689
+ }
1690
+
1691
+ if (offsetHeight > 0) {
1692
+ scaleY = round(rect.height) / offsetHeight || 1;
1693
+ }
1694
+ }
1653
1695
 
1654
1696
  return {
1655
1697
  width: rect.width / scaleX,
@@ -1804,13 +1846,13 @@
1804
1846
  return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
1805
1847
  }
1806
1848
 
1807
- var max = Math.max;
1808
- var min = Math.min;
1809
- var round = Math.round;
1810
-
1811
1849
  function within(min$1, value, max$1) {
1812
1850
  return max(min$1, min(value, max$1));
1813
1851
  }
1852
+ function withinMaxClamp(min, value, max) {
1853
+ var v = within(min, value, max);
1854
+ return v > max ? max : v;
1855
+ }
1814
1856
 
1815
1857
  function getFreshSideObject() {
1816
1858
  return {
@@ -1933,8 +1975,8 @@
1933
1975
  var win = window;
1934
1976
  var dpr = win.devicePixelRatio || 1;
1935
1977
  return {
1936
- x: round(round(x * dpr) / dpr) || 0,
1937
- y: round(round(y * dpr) / dpr) || 0
1978
+ x: round(x * dpr) / dpr || 0,
1979
+ y: round(y * dpr) / dpr || 0
1938
1980
  };
1939
1981
  }
1940
1982
 
@@ -1949,14 +1991,23 @@
1949
1991
  position = _ref2.position,
1950
1992
  gpuAcceleration = _ref2.gpuAcceleration,
1951
1993
  adaptive = _ref2.adaptive,
1952
- roundOffsets = _ref2.roundOffsets;
1953
-
1954
- var _ref3 = roundOffsets === true ? roundOffsetsByDPR(offsets) : typeof roundOffsets === 'function' ? roundOffsets(offsets) : offsets,
1955
- _ref3$x = _ref3.x,
1956
- x = _ref3$x === void 0 ? 0 : _ref3$x,
1957
- _ref3$y = _ref3.y,
1958
- y = _ref3$y === void 0 ? 0 : _ref3$y;
1994
+ roundOffsets = _ref2.roundOffsets,
1995
+ isFixed = _ref2.isFixed;
1996
+ var _offsets$x = offsets.x,
1997
+ x = _offsets$x === void 0 ? 0 : _offsets$x,
1998
+ _offsets$y = offsets.y,
1999
+ y = _offsets$y === void 0 ? 0 : _offsets$y;
2000
+
2001
+ var _ref3 = typeof roundOffsets === 'function' ? roundOffsets({
2002
+ x: x,
2003
+ y: y
2004
+ }) : {
2005
+ x: x,
2006
+ y: y
2007
+ };
1959
2008
 
2009
+ x = _ref3.x;
2010
+ y = _ref3.y;
1960
2011
  var hasX = offsets.hasOwnProperty('x');
1961
2012
  var hasY = offsets.hasOwnProperty('y');
1962
2013
  var sideX = left;
@@ -1981,16 +2032,18 @@
1981
2032
  offsetParent = offsetParent;
1982
2033
 
1983
2034
  if (placement === top || (placement === left || placement === right) && variation === end) {
1984
- sideY = bottom; // $FlowFixMe[prop-missing]
1985
-
1986
- y -= offsetParent[heightProp] - popperRect.height;
2035
+ sideY = bottom;
2036
+ var offsetY = isFixed && win.visualViewport ? win.visualViewport.height : // $FlowFixMe[prop-missing]
2037
+ offsetParent[heightProp];
2038
+ y -= offsetY - popperRect.height;
1987
2039
  y *= gpuAcceleration ? 1 : -1;
1988
2040
  }
1989
2041
 
1990
2042
  if (placement === left || (placement === top || placement === bottom) && variation === end) {
1991
- sideX = right; // $FlowFixMe[prop-missing]
1992
-
1993
- x -= offsetParent[widthProp] - popperRect.width;
2043
+ sideX = right;
2044
+ var offsetX = isFixed && win.visualViewport ? win.visualViewport.width : // $FlowFixMe[prop-missing]
2045
+ offsetParent[widthProp];
2046
+ x -= offsetX - popperRect.width;
1994
2047
  x *= gpuAcceleration ? 1 : -1;
1995
2048
  }
1996
2049
  }
@@ -1999,6 +2052,17 @@
1999
2052
  position: position
2000
2053
  }, adaptive && unsetSides);
2001
2054
 
2055
+ var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
2056
+ x: x,
2057
+ y: y
2058
+ }) : {
2059
+ x: x,
2060
+ y: y
2061
+ };
2062
+
2063
+ x = _ref4.x;
2064
+ y = _ref4.y;
2065
+
2002
2066
  if (gpuAcceleration) {
2003
2067
  var _Object$assign;
2004
2068
 
@@ -2008,9 +2072,9 @@
2008
2072
  return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
2009
2073
  }
2010
2074
 
2011
- function computeStyles(_ref4) {
2012
- var state = _ref4.state,
2013
- options = _ref4.options;
2075
+ function computeStyles(_ref5) {
2076
+ var state = _ref5.state,
2077
+ options = _ref5.options;
2014
2078
  var _options$gpuAccelerat = options.gpuAcceleration,
2015
2079
  gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat,
2016
2080
  _options$adaptive = options.adaptive,
@@ -2023,7 +2087,8 @@
2023
2087
  variation: getVariation(state.placement),
2024
2088
  popper: state.elements.popper,
2025
2089
  popperRect: state.rects.popper,
2026
- gpuAcceleration: gpuAcceleration
2090
+ gpuAcceleration: gpuAcceleration,
2091
+ isFixed: state.options.strategy === 'fixed'
2027
2092
  };
2028
2093
 
2029
2094
  if (state.modifiersData.popperOffsets != null) {
@@ -2281,7 +2346,7 @@
2281
2346
  }
2282
2347
 
2283
2348
  function getClientRectFromMixedType(element, clippingParent) {
2284
- return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isHTMLElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
2349
+ return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
2285
2350
  } // A "clipping parent" is an overflowable container with the characteristic of
2286
2351
  // clipping (or hiding) overflowing elements with a position different from
2287
2352
  // `initial`
@@ -2794,6 +2859,14 @@
2794
2859
  var tetherOffsetValue = typeof tetherOffset === 'function' ? tetherOffset(Object.assign({}, state.rects, {
2795
2860
  placement: state.placement
2796
2861
  })) : tetherOffset;
2862
+ var normalizedTetherOffsetValue = typeof tetherOffsetValue === 'number' ? {
2863
+ mainAxis: tetherOffsetValue,
2864
+ altAxis: tetherOffsetValue
2865
+ } : Object.assign({
2866
+ mainAxis: 0,
2867
+ altAxis: 0
2868
+ }, tetherOffsetValue);
2869
+ var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
2797
2870
  var data = {
2798
2871
  x: 0,
2799
2872
  y: 0
@@ -2803,13 +2876,15 @@
2803
2876
  return;
2804
2877
  }
2805
2878
 
2806
- if (checkMainAxis || checkAltAxis) {
2879
+ if (checkMainAxis) {
2880
+ var _offsetModifierState$;
2881
+
2807
2882
  var mainSide = mainAxis === 'y' ? top : left;
2808
2883
  var altSide = mainAxis === 'y' ? bottom : right;
2809
2884
  var len = mainAxis === 'y' ? 'height' : 'width';
2810
2885
  var offset = popperOffsets[mainAxis];
2811
- var min$1 = popperOffsets[mainAxis] + overflow[mainSide];
2812
- var max$1 = popperOffsets[mainAxis] - overflow[altSide];
2886
+ var min$1 = offset + overflow[mainSide];
2887
+ var max$1 = offset - overflow[altSide];
2813
2888
  var additive = tether ? -popperRect[len] / 2 : 0;
2814
2889
  var minLen = variation === start ? referenceRect[len] : popperRect[len];
2815
2890
  var maxLen = variation === start ? -popperRect[len] : -referenceRect[len]; // We need to include the arrow in the calculation so the arrow doesn't go
@@ -2829,36 +2904,45 @@
2829
2904
  // width or height)
2830
2905
 
2831
2906
  var arrowLen = within(0, referenceRect[len], arrowRect[len]);
2832
- var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - tetherOffsetValue : minLen - arrowLen - arrowPaddingMin - tetherOffsetValue;
2833
- var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + tetherOffsetValue : maxLen + arrowLen + arrowPaddingMax + tetherOffsetValue;
2907
+ var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
2908
+ var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
2834
2909
  var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
2835
2910
  var clientOffset = arrowOffsetParent ? mainAxis === 'y' ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
2836
- var offsetModifierValue = state.modifiersData.offset ? state.modifiersData.offset[state.placement][mainAxis] : 0;
2837
- var tetherMin = popperOffsets[mainAxis] + minOffset - offsetModifierValue - clientOffset;
2838
- var tetherMax = popperOffsets[mainAxis] + maxOffset - offsetModifierValue;
2911
+ var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
2912
+ var tetherMin = offset + minOffset - offsetModifierValue - clientOffset;
2913
+ var tetherMax = offset + maxOffset - offsetModifierValue;
2914
+ var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset, tether ? max(max$1, tetherMax) : max$1);
2915
+ popperOffsets[mainAxis] = preventedOffset;
2916
+ data[mainAxis] = preventedOffset - offset;
2917
+ }
2839
2918
 
2840
- if (checkMainAxis) {
2841
- var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset, tether ? max(max$1, tetherMax) : max$1);
2842
- popperOffsets[mainAxis] = preventedOffset;
2843
- data[mainAxis] = preventedOffset - offset;
2844
- }
2919
+ if (checkAltAxis) {
2920
+ var _offsetModifierState$2;
2845
2921
 
2846
- if (checkAltAxis) {
2847
- var _mainSide = mainAxis === 'x' ? top : left;
2922
+ var _mainSide = mainAxis === 'x' ? top : left;
2848
2923
 
2849
- var _altSide = mainAxis === 'x' ? bottom : right;
2924
+ var _altSide = mainAxis === 'x' ? bottom : right;
2850
2925
 
2851
- var _offset = popperOffsets[altAxis];
2926
+ var _offset = popperOffsets[altAxis];
2852
2927
 
2853
- var _min = _offset + overflow[_mainSide];
2928
+ var _len = altAxis === 'y' ? 'height' : 'width';
2854
2929
 
2855
- var _max = _offset - overflow[_altSide];
2930
+ var _min = _offset + overflow[_mainSide];
2856
2931
 
2857
- var _preventedOffset = within(tether ? min(_min, tetherMin) : _min, _offset, tether ? max(_max, tetherMax) : _max);
2932
+ var _max = _offset - overflow[_altSide];
2858
2933
 
2859
- popperOffsets[altAxis] = _preventedOffset;
2860
- data[altAxis] = _preventedOffset - _offset;
2861
- }
2934
+ var isOriginSide = [top, left].indexOf(basePlacement) !== -1;
2935
+
2936
+ var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
2937
+
2938
+ var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
2939
+
2940
+ var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
2941
+
2942
+ var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
2943
+
2944
+ popperOffsets[altAxis] = _preventedOffset;
2945
+ data[altAxis] = _preventedOffset - _offset;
2862
2946
  }
2863
2947
 
2864
2948
  state.modifiersData[name] = data;
@@ -2890,8 +2974,8 @@
2890
2974
 
2891
2975
  function isElementScaled(element) {
2892
2976
  var rect = element.getBoundingClientRect();
2893
- var scaleX = rect.width / element.offsetWidth || 1;
2894
- var scaleY = rect.height / element.offsetHeight || 1;
2977
+ var scaleX = round(rect.width) / element.offsetWidth || 1;
2978
+ var scaleY = round(rect.height) / element.offsetHeight || 1;
2895
2979
  return scaleX !== 1 || scaleY !== 1;
2896
2980
  } // Returns the composite rect of an element relative to its offsetParent.
2897
2981
  // Composite means it takes into account transforms as well as layout.
@@ -2903,9 +2987,9 @@
2903
2987
  }
2904
2988
 
2905
2989
  var isOffsetParentAnElement = isHTMLElement(offsetParent);
2906
- isHTMLElement(offsetParent) && isElementScaled(offsetParent);
2990
+ var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
2907
2991
  var documentElement = getDocumentElement(offsetParent);
2908
- var rect = getBoundingClientRect(elementOrVirtualElement);
2992
+ var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled);
2909
2993
  var scroll = {
2910
2994
  scrollLeft: 0,
2911
2995
  scrollTop: 0
@@ -2922,7 +3006,7 @@
2922
3006
  }
2923
3007
 
2924
3008
  if (isHTMLElement(offsetParent)) {
2925
- offsets = getBoundingClientRect(offsetParent);
3009
+ offsets = getBoundingClientRect(offsetParent, true);
2926
3010
  offsets.x += offsetParent.clientLeft;
2927
3011
  offsets.y += offsetParent.clientTop;
2928
3012
  } else if (documentElement) {
@@ -3372,6 +3456,9 @@
3372
3456
  this.defaults = defaults;
3373
3457
  this.settings = _extends({}, this.defaults, options);
3374
3458
  this.collection = [];
3459
+ this.memory = {
3460
+ trigger: null
3461
+ };
3375
3462
  this.__handlerKeydown = handlerKeydown.bind(this);
3376
3463
  if (this.settings.autoInit) this.init();
3377
3464
  }