This commit is contained in:
Administrator
2022-04-18 06:52:24 +00:00
parent 28f29fa610
commit 01c592100d
474 changed files with 48732 additions and 1609 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
// @flow
export * from '../../lib/popper-base.js'

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
// @flow
export * from '../../lib/popper-lite.js'

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
// @flow
export * from '../../lib/popper.js'

View File

@@ -0,0 +1,258 @@
import getCompositeRect from "./dom-utils/getCompositeRect.js";
import getLayoutRect from "./dom-utils/getLayoutRect.js";
import listScrollParents from "./dom-utils/listScrollParents.js";
import getOffsetParent from "./dom-utils/getOffsetParent.js";
import getComputedStyle from "./dom-utils/getComputedStyle.js";
import orderModifiers from "./utils/orderModifiers.js";
import debounce from "./utils/debounce.js";
import validateModifiers from "./utils/validateModifiers.js";
import uniqueBy from "./utils/uniqueBy.js";
import getBasePlacement from "./utils/getBasePlacement.js";
import mergeByName from "./utils/mergeByName.js";
import detectOverflow from "./utils/detectOverflow.js";
import { isElement } from "./dom-utils/instanceOf.js";
import { auto } from "./enums.js";
var INVALID_ELEMENT_ERROR = 'Popper: Invalid reference or popper argument provided. They must be either a DOM element or virtual element.';
var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.';
var DEFAULT_OPTIONS = {
placement: 'bottom',
modifiers: [],
strategy: 'absolute'
};
function areValidElements() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return !args.some(function (element) {
return !(element && typeof element.getBoundingClientRect === 'function');
});
}
export function popperGenerator(generatorOptions) {
if (generatorOptions === void 0) {
generatorOptions = {};
}
var _generatorOptions = generatorOptions,
_generatorOptions$def = _generatorOptions.defaultModifiers,
defaultModifiers = _generatorOptions$def === void 0 ? [] : _generatorOptions$def,
_generatorOptions$def2 = _generatorOptions.defaultOptions,
defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
return function createPopper(reference, popper, options) {
if (options === void 0) {
options = defaultOptions;
}
var state = {
placement: 'bottom',
orderedModifiers: [],
options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
modifiersData: {},
elements: {
reference: reference,
popper: popper
},
attributes: {},
styles: {}
};
var effectCleanupFns = [];
var isDestroyed = false;
var instance = {
state: state,
setOptions: function setOptions(options) {
cleanupModifierEffects();
state.options = Object.assign({}, defaultOptions, state.options, options);
state.scrollParents = {
reference: isElement(reference) ? listScrollParents(reference) : reference.contextElement ? listScrollParents(reference.contextElement) : [],
popper: listScrollParents(popper)
}; // Orders the modifiers based on their dependencies and `phase`
// properties
var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers, state.options.modifiers))); // Strip out disabled modifiers
state.orderedModifiers = orderedModifiers.filter(function (m) {
return m.enabled;
}); // Validate the provided modifiers so that the consumer will get warned
// if one of the modifiers is invalid for any reason
if (false) {
var modifiers = uniqueBy([].concat(orderedModifiers, state.options.modifiers), function (_ref) {
var name = _ref.name;
return name;
});
validateModifiers(modifiers);
if (getBasePlacement(state.options.placement) === auto) {
var flipModifier = state.orderedModifiers.find(function (_ref2) {
var name = _ref2.name;
return name === 'flip';
});
if (!flipModifier) {
console.error(['Popper: "auto" placements require the "flip" modifier be', 'present and enabled to work.'].join(' '));
}
}
var _getComputedStyle = getComputedStyle(popper),
marginTop = _getComputedStyle.marginTop,
marginRight = _getComputedStyle.marginRight,
marginBottom = _getComputedStyle.marginBottom,
marginLeft = _getComputedStyle.marginLeft; // We no longer take into account `margins` on the popper, and it can
// cause bugs with positioning, so we'll warn the consumer
if ([marginTop, marginRight, marginBottom, marginLeft].some(function (margin) {
return parseFloat(margin);
})) {
console.warn(['Popper: CSS "margin" styles cannot be used to apply padding', 'between the popper and its reference element or boundary.', 'To replicate margin, use the `offset` modifier, as well as', 'the `padding` option in the `preventOverflow` and `flip`', 'modifiers.'].join(' '));
}
}
runModifierEffects();
return instance.update();
},
// Sync update it will always be executed, even if not necessary. This
// is useful for low frequency updates where sync behavior simplifies the
// logic.
// For high frequency updates (e.g. `resize` and `scroll` events), always
// prefer the async Popper#update method
forceUpdate: function forceUpdate() {
if (isDestroyed) {
return;
}
var _state$elements = state.elements,
reference = _state$elements.reference,
popper = _state$elements.popper; // Don't proceed if `reference` or `popper` are not valid elements
// anymore
if (!areValidElements(reference, popper)) {
if (false) {
console.error(INVALID_ELEMENT_ERROR);
}
return;
} // Store the reference and popper rects to be read by modifiers
state.rects = {
reference: getCompositeRect(reference, getOffsetParent(popper), state.options.strategy === 'fixed'),
popper: getLayoutRect(popper)
}; // Modifiers have the ability to reset the current update cycle. The
// most common use case for this is the `flip` modifier changing the
// placement, which then needs to re-run all the modifiers, because the
// logic was previously ran for the previous placement and is therefore
// stale/incorrect
state.reset = false;
state.placement = state.options.placement; // On each update cycle, the `modifiersData` property for each modifier
// is filled with the initial data specified by the modifier. This means
// it doesn't persist and is fresh on each update.
// To ensure persistent data, use `${name}#persistent`
state.orderedModifiers.forEach(function (modifier) {
return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
});
var __debug_loops__ = 0;
for (var index = 0; index < state.orderedModifiers.length; index++) {
if (false) {
__debug_loops__ += 1;
if (__debug_loops__ > 100) {
console.error(INFINITE_LOOP_ERROR);
break;
}
}
if (state.reset === true) {
state.reset = false;
index = -1;
continue;
}
var _state$orderedModifie = state.orderedModifiers[index],
fn = _state$orderedModifie.fn,
_state$orderedModifie2 = _state$orderedModifie.options,
_options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2,
name = _state$orderedModifie.name;
if (typeof fn === 'function') {
state = fn({
state: state,
options: _options,
name: name,
instance: instance
}) || state;
}
}
},
// Async and optimistically optimized update it will not be executed if
// not necessary (debounced to run at most once-per-tick)
update: debounce(function () {
return new Promise(function (resolve) {
instance.forceUpdate();
resolve(state);
});
}),
destroy: function destroy() {
cleanupModifierEffects();
isDestroyed = true;
}
};
if (!areValidElements(reference, popper)) {
if (false) {
console.error(INVALID_ELEMENT_ERROR);
}
return instance;
}
instance.setOptions(options).then(function (state) {
if (!isDestroyed && options.onFirstUpdate) {
options.onFirstUpdate(state);
}
}); // Modifiers have the ability to execute arbitrary code before the first
// update cycle runs. They will be executed in the same order as the update
// cycle. This is useful when a modifier adds some persistent data that
// other modifiers need to use, but the modifier is run after the dependent
// one.
function runModifierEffects() {
state.orderedModifiers.forEach(function (_ref3) {
var name = _ref3.name,
_ref3$options = _ref3.options,
options = _ref3$options === void 0 ? {} : _ref3$options,
effect = _ref3.effect;
if (typeof effect === 'function') {
var cleanupFn = effect({
state: state,
name: name,
instance: instance,
options: options
});
var noopFn = function noopFn() {};
effectCleanupFns.push(cleanupFn || noopFn);
}
});
}
function cleanupModifierEffects() {
effectCleanupFns.forEach(function (fn) {
return fn();
});
effectCleanupFns = [];
}
return instance;
};
}
export var createPopper = /*#__PURE__*/popperGenerator(); // eslint-disable-next-line import/no-unused-modules
export { detectOverflow };

View File

@@ -0,0 +1,23 @@
import { isShadowRoot } from "./instanceOf.js";
export default function contains(parent, child) {
var rootNode = child.getRootNode && child.getRootNode(); // First, attempt with faster native method
if (parent.contains(child)) {
return true;
} // then fallback to custom implementation with Shadow DOM support
else if (rootNode && isShadowRoot(rootNode)) {
var next = child;
do {
if (next && parent.isSameNode(next)) {
return true;
} // $FlowFixMe[prop-missing]: need a better way to handle this...
next = next.parentNode || next.host;
} while (next);
} // Give up, the result is false
return false;
}

View File

@@ -0,0 +1,28 @@
import { isHTMLElement } from "./instanceOf.js";
var round = Math.round;
export default function getBoundingClientRect(element, includeScale) {
if (includeScale === void 0) {
includeScale = false;
}
var rect = element.getBoundingClientRect();
var scaleX = 1;
var scaleY = 1;
if (isHTMLElement(element) && includeScale) {
// Fallback to 1 in case both values are `0`
scaleX = rect.width / element.offsetWidth || 1;
scaleY = rect.height / element.offsetHeight || 1;
}
return {
width: round(rect.width / scaleX),
height: round(rect.height / scaleY),
top: round(rect.top / scaleY),
right: round(rect.right / scaleX),
bottom: round(rect.bottom / scaleY),
left: round(rect.left / scaleX),
x: round(rect.left / scaleX),
y: round(rect.top / scaleY)
};
}

View File

@@ -0,0 +1,70 @@
import { viewport } from "../enums.js";
import getViewportRect from "./getViewportRect.js";
import getDocumentRect from "./getDocumentRect.js";
import listScrollParents from "./listScrollParents.js";
import getOffsetParent from "./getOffsetParent.js";
import getDocumentElement from "./getDocumentElement.js";
import getComputedStyle from "./getComputedStyle.js";
import { isElement, isHTMLElement } from "./instanceOf.js";
import getBoundingClientRect from "./getBoundingClientRect.js";
import getParentNode from "./getParentNode.js";
import contains from "./contains.js";
import getNodeName from "./getNodeName.js";
import rectToClientRect from "../utils/rectToClientRect.js";
import { max, min } from "../utils/math.js";
function getInnerBoundingClientRect(element) {
var rect = getBoundingClientRect(element);
rect.top = rect.top + element.clientTop;
rect.left = rect.left + element.clientLeft;
rect.bottom = rect.top + element.clientHeight;
rect.right = rect.left + element.clientWidth;
rect.width = element.clientWidth;
rect.height = element.clientHeight;
rect.x = rect.left;
rect.y = rect.top;
return rect;
}
function getClientRectFromMixedType(element, clippingParent) {
return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isHTMLElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
} // A "clipping parent" is an overflowable container with the characteristic of
// clipping (or hiding) overflowing elements with a position different from
// `initial`
function getClippingParents(element) {
var clippingParents = listScrollParents(getParentNode(element));
var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle(element).position) >= 0;
var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
if (!isElement(clipperElement)) {
return [];
} // $FlowFixMe[incompatible-return]: https://github.com/facebook/flow/issues/1414
return clippingParents.filter(function (clippingParent) {
return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== 'body';
});
} // Gets the maximum area that the element is visible in due to any number of
// clipping parents
export default function getClippingRect(element, boundary, rootBoundary) {
var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
var firstClippingParent = clippingParents[0];
var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
var rect = getClientRectFromMixedType(element, clippingParent);
accRect.top = max(rect.top, accRect.top);
accRect.right = min(rect.right, accRect.right);
accRect.bottom = min(rect.bottom, accRect.bottom);
accRect.left = max(rect.left, accRect.left);
return accRect;
}, getClientRectFromMixedType(element, firstClippingParent));
clippingRect.width = clippingRect.right - clippingRect.left;
clippingRect.height = clippingRect.bottom - clippingRect.top;
clippingRect.x = clippingRect.left;
clippingRect.y = clippingRect.top;
return clippingRect;
}

View File

@@ -0,0 +1,57 @@
import getBoundingClientRect from "./getBoundingClientRect.js";
import getNodeScroll from "./getNodeScroll.js";
import getNodeName from "./getNodeName.js";
import { isHTMLElement } from "./instanceOf.js";
import getWindowScrollBarX from "./getWindowScrollBarX.js";
import getDocumentElement from "./getDocumentElement.js";
import isScrollParent from "./isScrollParent.js";
function isElementScaled(element) {
var rect = element.getBoundingClientRect();
var scaleX = rect.width / element.offsetWidth || 1;
var scaleY = rect.height / element.offsetHeight || 1;
return scaleX !== 1 || scaleY !== 1;
} // Returns the composite rect of an element relative to its offsetParent.
// Composite means it takes into account transforms as well as layout.
export default function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
if (isFixed === void 0) {
isFixed = false;
}
var isOffsetParentAnElement = isHTMLElement(offsetParent);
var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
var documentElement = getDocumentElement(offsetParent);
var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled);
var scroll = {
scrollLeft: 0,
scrollTop: 0
};
var offsets = {
x: 0,
y: 0
};
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
if (getNodeName(offsetParent) !== 'body' || // https://github.com/popperjs/popper-core/issues/1078
isScrollParent(documentElement)) {
scroll = getNodeScroll(offsetParent);
}
if (isHTMLElement(offsetParent)) {
offsets = getBoundingClientRect(offsetParent, true);
offsets.x += offsetParent.clientLeft;
offsets.y += offsetParent.clientTop;
} else if (documentElement) {
offsets.x = getWindowScrollBarX(documentElement);
}
}
return {
x: rect.left + scroll.scrollLeft - offsets.x,
y: rect.top + scroll.scrollTop - offsets.y,
width: rect.width,
height: rect.height
};
}

View File

@@ -0,0 +1,4 @@
import getWindow from "./getWindow.js";
export default function getComputedStyle(element) {
return getWindow(element).getComputedStyle(element);
}

View File

@@ -0,0 +1,6 @@
import { isElement } from "./instanceOf.js";
export default function getDocumentElement(element) {
// $FlowFixMe[incompatible-return]: assume body is always available
return ((isElement(element) ? element.ownerDocument : // $FlowFixMe[prop-missing]
element.document) || window.document).documentElement;
}

View File

@@ -0,0 +1,29 @@
import getDocumentElement from "./getDocumentElement.js";
import getComputedStyle from "./getComputedStyle.js";
import getWindowScrollBarX from "./getWindowScrollBarX.js";
import getWindowScroll from "./getWindowScroll.js";
import { max } from "../utils/math.js"; // Gets the entire size of the scrollable document area, even extending outside
// of the `<html>` and `<body>` rect bounds if horizontally scrollable
export default function getDocumentRect(element) {
var _element$ownerDocumen;
var html = getDocumentElement(element);
var winScroll = getWindowScroll(element);
var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
var y = -winScroll.scrollTop;
if (getComputedStyle(body || html).direction === 'rtl') {
x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
}
return {
width: width,
height: height,
x: x,
y: y
};
}

View File

@@ -0,0 +1,6 @@
export default function getHTMLElementScroll(element) {
return {
scrollLeft: element.scrollLeft,
scrollTop: element.scrollTop
};
}

View File

@@ -0,0 +1,25 @@
import getBoundingClientRect from "./getBoundingClientRect.js"; // Returns the layout rect of an element relative to its offsetParent. Layout
// means it doesn't take into account transforms.
export default function getLayoutRect(element) {
var clientRect = getBoundingClientRect(element); // Use the clientRect sizes if it's not been transformed.
// Fixes https://github.com/popperjs/popper-core/issues/1223
var width = element.offsetWidth;
var height = element.offsetHeight;
if (Math.abs(clientRect.width - width) <= 1) {
width = clientRect.width;
}
if (Math.abs(clientRect.height - height) <= 1) {
height = clientRect.height;
}
return {
x: element.offsetLeft,
y: element.offsetTop,
width: width,
height: height
};
}

View File

@@ -0,0 +1,3 @@
export default function getNodeName(element) {
return element ? (element.nodeName || '').toLowerCase() : null;
}

View File

@@ -0,0 +1,11 @@
import getWindowScroll from "./getWindowScroll.js";
import getWindow from "./getWindow.js";
import { isHTMLElement } from "./instanceOf.js";
import getHTMLElementScroll from "./getHTMLElementScroll.js";
export default function getNodeScroll(node) {
if (node === getWindow(node) || !isHTMLElement(node)) {
return getWindowScroll(node);
} else {
return getHTMLElementScroll(node);
}
}

View File

@@ -0,0 +1,64 @@
import getWindow from "./getWindow.js";
import getNodeName from "./getNodeName.js";
import getComputedStyle from "./getComputedStyle.js";
import { isHTMLElement } from "./instanceOf.js";
import isTableElement from "./isTableElement.js";
import getParentNode from "./getParentNode.js";
function getTrueOffsetParent(element) {
if (!isHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
getComputedStyle(element).position === 'fixed') {
return null;
}
return element.offsetParent;
} // `.offsetParent` reports `null` for fixed elements, while absolute elements
// return the containing block
function getContainingBlock(element) {
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') !== -1;
var isIE = navigator.userAgent.indexOf('Trident') !== -1;
if (isIE && isHTMLElement(element)) {
// In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
var elementCss = getComputedStyle(element);
if (elementCss.position === 'fixed') {
return null;
}
}
var currentNode = getParentNode(element);
while (isHTMLElement(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
var css = getComputedStyle(currentNode); // This is non-exhaustive but covers the most common CSS properties that
// create a containing block.
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
if (css.transform !== 'none' || css.perspective !== 'none' || css.contain === 'paint' || ['transform', 'perspective'].indexOf(css.willChange) !== -1 || isFirefox && css.willChange === 'filter' || isFirefox && css.filter && css.filter !== 'none') {
return currentNode;
} else {
currentNode = currentNode.parentNode;
}
}
return null;
} // Gets the closest ancestor positioned element. Handles some edge cases,
// such as table ancestors and cross browser bugs.
export default function getOffsetParent(element) {
var window = getWindow(element);
var offsetParent = getTrueOffsetParent(element);
while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
offsetParent = getTrueOffsetParent(offsetParent);
}
if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static')) {
return window;
}
return offsetParent || getContainingBlock(element) || window;
}

View File

@@ -0,0 +1,19 @@
import getNodeName from "./getNodeName.js";
import getDocumentElement from "./getDocumentElement.js";
import { isShadowRoot } from "./instanceOf.js";
export default function getParentNode(element) {
if (getNodeName(element) === 'html') {
return element;
}
return (// this is a quicker (but less type safe) way to save quite some bytes from the bundle
// $FlowFixMe[incompatible-return]
// $FlowFixMe[prop-missing]
element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
element.parentNode || ( // DOM Element detected
isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
// $FlowFixMe[incompatible-call]: HTMLElement is a Node
getDocumentElement(element) // fallback
);
}

View File

@@ -0,0 +1,16 @@
import getParentNode from "./getParentNode.js";
import isScrollParent from "./isScrollParent.js";
import getNodeName from "./getNodeName.js";
import { isHTMLElement } from "./instanceOf.js";
export default function getScrollParent(node) {
if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
// $FlowFixMe[incompatible-return]: assume body is always available
return node.ownerDocument.body;
}
if (isHTMLElement(node) && isScrollParent(node)) {
return node;
}
return getScrollParent(getParentNode(node));
}

View File

@@ -0,0 +1,40 @@
import getWindow from "./getWindow.js";
import getDocumentElement from "./getDocumentElement.js";
import getWindowScrollBarX from "./getWindowScrollBarX.js";
export default function getViewportRect(element) {
var win = getWindow(element);
var html = getDocumentElement(element);
var visualViewport = win.visualViewport;
var width = html.clientWidth;
var height = html.clientHeight;
var x = 0;
var y = 0; // NB: This isn't supported on iOS <= 12. If the keyboard is open, the popper
// can be obscured underneath it.
// Also, `html.clientHeight` adds the bottom bar height in Safari iOS, even
// if it isn't open, so if this isn't available, the popper will be detected
// to overflow the bottom of the screen too early.
if (visualViewport) {
width = visualViewport.width;
height = visualViewport.height; // Uses Layout Viewport (like Chrome; Safari does not currently)
// In Chrome, it returns a value very close to 0 (+/-) but contains rounding
// errors due to floating point numbers, so we need to check precision.
// Safari returns a number <= 0, usually < -1 when pinch-zoomed
// Feature detection fails in mobile emulation mode in Chrome.
// Math.abs(win.innerWidth / visualViewport.scale - visualViewport.width) <
// 0.001
// Fallback here: "Not Safari" userAgent
if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
x = visualViewport.offsetLeft;
y = visualViewport.offsetTop;
}
}
return {
width: width,
height: height,
x: x + getWindowScrollBarX(element),
y: y
};
}

View File

@@ -0,0 +1,12 @@
export default function getWindow(node) {
if (node == null) {
return window;
}
if (node.toString() !== '[object Window]') {
var ownerDocument = node.ownerDocument;
return ownerDocument ? ownerDocument.defaultView || window : window;
}
return node;
}

View File

@@ -0,0 +1,10 @@
import getWindow from "./getWindow.js";
export default function getWindowScroll(node) {
var win = getWindow(node);
var scrollLeft = win.pageXOffset;
var scrollTop = win.pageYOffset;
return {
scrollLeft: scrollLeft,
scrollTop: scrollTop
};
}

View File

@@ -0,0 +1,13 @@
import getBoundingClientRect from "./getBoundingClientRect.js";
import getDocumentElement from "./getDocumentElement.js";
import getWindowScroll from "./getWindowScroll.js";
export default function getWindowScrollBarX(element) {
// If <html> has a CSS width greater than the viewport, then this will be
// incorrect for RTL.
// Popper 1 is broken in this case and never had a bug report so let's assume
// it's not an issue. I don't think anyone ever specifies width on <html>
// anyway.
// Browsers where the left scrollbar doesn't cause an issue report `0` for
// this (e.g. Edge 2019, IE11, Safari)
return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
}

View File

@@ -0,0 +1,23 @@
import getWindow from "./getWindow.js";
function isElement(node) {
var OwnElement = getWindow(node).Element;
return node instanceof OwnElement || node instanceof Element;
}
function isHTMLElement(node) {
var OwnElement = getWindow(node).HTMLElement;
return node instanceof OwnElement || node instanceof HTMLElement;
}
function isShadowRoot(node) {
// IE 11 has no ShadowRoot
if (typeof ShadowRoot === 'undefined') {
return false;
}
var OwnElement = getWindow(node).ShadowRoot;
return node instanceof OwnElement || node instanceof ShadowRoot;
}
export { isElement, isHTMLElement, isShadowRoot };

View File

@@ -0,0 +1,10 @@
import getComputedStyle from "./getComputedStyle.js";
export default function isScrollParent(element) {
// Firefox wants us to check `-x` and `-y` variations as well
var _getComputedStyle = getComputedStyle(element),
overflow = _getComputedStyle.overflow,
overflowX = _getComputedStyle.overflowX,
overflowY = _getComputedStyle.overflowY;
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
}

View File

@@ -0,0 +1,4 @@
import getNodeName from "./getNodeName.js";
export default function isTableElement(element) {
return ['table', 'td', 'th'].indexOf(getNodeName(element)) >= 0;
}

View File

@@ -0,0 +1,26 @@
import getScrollParent from "./getScrollParent.js";
import getParentNode from "./getParentNode.js";
import getWindow from "./getWindow.js";
import isScrollParent from "./isScrollParent.js";
/*
given a DOM element, return the list of all scroll parents, up the list of ancesors
until we get to the top window object. This list is what we attach scroll listeners
to, because if any of these parent elements scroll, we'll need to re-calculate the
reference element's position.
*/
export default function listScrollParents(element, list) {
var _element$ownerDocumen;
if (list === void 0) {
list = [];
}
var scrollParent = getScrollParent(element);
var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
var win = getWindow(scrollParent);
var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
var updatedList = list.concat(target);
return isBody ? updatedList : // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
updatedList.concat(listScrollParents(getParentNode(target)));
}

View File

@@ -0,0 +1,31 @@
export var top = 'top';
export var bottom = 'bottom';
export var right = 'right';
export var left = 'left';
export var auto = 'auto';
export var basePlacements = [top, bottom, right, left];
export var start = 'start';
export var end = 'end';
export var clippingParents = 'clippingParents';
export var viewport = 'viewport';
export var popper = 'popper';
export var reference = 'reference';
export var variationPlacements = /*#__PURE__*/basePlacements.reduce(function (acc, placement) {
return acc.concat([placement + "-" + start, placement + "-" + end]);
}, []);
export var placements = /*#__PURE__*/[].concat(basePlacements, [auto]).reduce(function (acc, placement) {
return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
}, []); // modifiers that need to read the DOM
export var beforeRead = 'beforeRead';
export var read = 'read';
export var afterRead = 'afterRead'; // pure-logic modifiers
export var beforeMain = 'beforeMain';
export var main = 'main';
export var afterMain = 'afterMain'; // modifier with the purpose to write to the DOM (or write into a framework state)
export var beforeWrite = 'beforeWrite';
export var write = 'write';
export var afterWrite = 'afterWrite';
export var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];

View File

@@ -0,0 +1,8 @@
export * from "./enums.js";
export * from "./modifiers/index.js"; // eslint-disable-next-line import/no-unused-modules
export { popperGenerator, detectOverflow, createPopper as createPopperBase } from "./createPopper.js"; // eslint-disable-next-line import/no-unused-modules
export { createPopper } from "./popper.js"; // eslint-disable-next-line import/no-unused-modules
export { createPopper as createPopperLite } from "./popper-lite.js";

View File

@@ -0,0 +1,84 @@
import getNodeName from "../dom-utils/getNodeName.js";
import { isHTMLElement } from "../dom-utils/instanceOf.js"; // This modifier takes the styles prepared by the `computeStyles` modifier
// and applies them to the HTMLElements such as popper and arrow
function applyStyles(_ref) {
var state = _ref.state;
Object.keys(state.elements).forEach(function (name) {
var style = state.styles[name] || {};
var attributes = state.attributes[name] || {};
var element = state.elements[name]; // arrow is optional + virtual elements
if (!isHTMLElement(element) || !getNodeName(element)) {
return;
} // Flow doesn't support to extend this property, but it's the most
// effective way to apply styles to an HTMLElement
// $FlowFixMe[cannot-write]
Object.assign(element.style, style);
Object.keys(attributes).forEach(function (name) {
var value = attributes[name];
if (value === false) {
element.removeAttribute(name);
} else {
element.setAttribute(name, value === true ? '' : value);
}
});
});
}
function effect(_ref2) {
var state = _ref2.state;
var initialStyles = {
popper: {
position: state.options.strategy,
left: '0',
top: '0',
margin: '0'
},
arrow: {
position: 'absolute'
},
reference: {}
};
Object.assign(state.elements.popper.style, initialStyles.popper);
state.styles = initialStyles;
if (state.elements.arrow) {
Object.assign(state.elements.arrow.style, initialStyles.arrow);
}
return function () {
Object.keys(state.elements).forEach(function (name) {
var element = state.elements[name];
var attributes = state.attributes[name] || {};
var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]); // Set all values to an empty string to unset them
var style = styleProperties.reduce(function (style, property) {
style[property] = '';
return style;
}, {}); // arrow is optional + virtual elements
if (!isHTMLElement(element) || !getNodeName(element)) {
return;
}
Object.assign(element.style, style);
Object.keys(attributes).forEach(function (attribute) {
element.removeAttribute(attribute);
});
});
};
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'applyStyles',
enabled: true,
phase: 'write',
fn: applyStyles,
effect: effect,
requires: ['computeStyles']
};

View File

@@ -0,0 +1,101 @@
import getBasePlacement from "../utils/getBasePlacement.js";
import getLayoutRect from "../dom-utils/getLayoutRect.js";
import contains from "../dom-utils/contains.js";
import getOffsetParent from "../dom-utils/getOffsetParent.js";
import getMainAxisFromPlacement from "../utils/getMainAxisFromPlacement.js";
import within from "../utils/within.js";
import mergePaddingObject from "../utils/mergePaddingObject.js";
import expandToHashMap from "../utils/expandToHashMap.js";
import { left, right, basePlacements, top, bottom } from "../enums.js";
import { isHTMLElement } from "../dom-utils/instanceOf.js"; // eslint-disable-next-line import/no-unused-modules
var toPaddingObject = function toPaddingObject(padding, state) {
padding = typeof padding === 'function' ? padding(Object.assign({}, state.rects, {
placement: state.placement
})) : padding;
return mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
};
function arrow(_ref) {
var _state$modifiersData$;
var state = _ref.state,
name = _ref.name,
options = _ref.options;
var arrowElement = state.elements.arrow;
var popperOffsets = state.modifiersData.popperOffsets;
var basePlacement = getBasePlacement(state.placement);
var axis = getMainAxisFromPlacement(basePlacement);
var isVertical = [left, right].indexOf(basePlacement) >= 0;
var len = isVertical ? 'height' : 'width';
if (!arrowElement || !popperOffsets) {
return;
}
var paddingObject = toPaddingObject(options.padding, state);
var arrowRect = getLayoutRect(arrowElement);
var minProp = axis === 'y' ? top : left;
var maxProp = axis === 'y' ? bottom : right;
var endDiff = state.rects.reference[len] + state.rects.reference[axis] - popperOffsets[axis] - state.rects.popper[len];
var startDiff = popperOffsets[axis] - state.rects.reference[axis];
var arrowOffsetParent = getOffsetParent(arrowElement);
var clientSize = arrowOffsetParent ? axis === 'y' ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
var centerToReference = endDiff / 2 - startDiff / 2; // Make sure the arrow doesn't overflow the popper if the center point is
// outside of the popper bounds
var min = paddingObject[minProp];
var max = clientSize - arrowRect[len] - paddingObject[maxProp];
var center = clientSize / 2 - arrowRect[len] / 2 + centerToReference;
var offset = within(min, center, max); // Prevents breaking syntax highlighting...
var axisProp = axis;
state.modifiersData[name] = (_state$modifiersData$ = {}, _state$modifiersData$[axisProp] = offset, _state$modifiersData$.centerOffset = offset - center, _state$modifiersData$);
}
function effect(_ref2) {
var state = _ref2.state,
options = _ref2.options;
var _options$element = options.element,
arrowElement = _options$element === void 0 ? '[data-popper-arrow]' : _options$element;
if (arrowElement == null) {
return;
} // CSS selector
if (typeof arrowElement === 'string') {
arrowElement = state.elements.popper.querySelector(arrowElement);
if (!arrowElement) {
return;
}
}
if (false) {
if (!isHTMLElement(arrowElement)) {
console.error(['Popper: "arrow" element must be an HTMLElement (not an SVGElement).', 'To use an SVG arrow, wrap it in an HTMLElement that will be used as', 'the arrow.'].join(' '));
}
}
if (!contains(state.elements.popper, arrowElement)) {
if (false) {
console.error(['Popper: "arrow" modifier\'s `element` must be a child of the popper', 'element.'].join(' '));
}
return;
}
state.elements.arrow = arrowElement;
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'arrow',
enabled: true,
phase: 'main',
fn: arrow,
effect: effect,
requires: ['popperOffsets'],
requiresIfExists: ['preventOverflow']
};

View File

@@ -0,0 +1,155 @@
import { top, left, right, bottom } from "../enums.js";
import getOffsetParent from "../dom-utils/getOffsetParent.js";
import getWindow from "../dom-utils/getWindow.js";
import getDocumentElement from "../dom-utils/getDocumentElement.js";
import getComputedStyle from "../dom-utils/getComputedStyle.js";
import getBasePlacement from "../utils/getBasePlacement.js";
import { round } from "../utils/math.js"; // eslint-disable-next-line import/no-unused-modules
var unsetSides = {
top: 'auto',
right: 'auto',
bottom: 'auto',
left: 'auto'
}; // Round the offsets to the nearest suitable subpixel based on the DPR.
// Zooming can change the DPR, but it seems to report a value that will
// cleanly divide the values into the appropriate subpixels.
function roundOffsetsByDPR(_ref) {
var x = _ref.x,
y = _ref.y;
var win = window;
var dpr = win.devicePixelRatio || 1;
return {
x: round(round(x * dpr) / dpr) || 0,
y: round(round(y * dpr) / dpr) || 0
};
}
export function mapToStyles(_ref2) {
var _Object$assign2;
var popper = _ref2.popper,
popperRect = _ref2.popperRect,
placement = _ref2.placement,
offsets = _ref2.offsets,
position = _ref2.position,
gpuAcceleration = _ref2.gpuAcceleration,
adaptive = _ref2.adaptive,
roundOffsets = _ref2.roundOffsets;
var _ref3 = roundOffsets === true ? roundOffsetsByDPR(offsets) : typeof roundOffsets === 'function' ? roundOffsets(offsets) : offsets,
_ref3$x = _ref3.x,
x = _ref3$x === void 0 ? 0 : _ref3$x,
_ref3$y = _ref3.y,
y = _ref3$y === void 0 ? 0 : _ref3$y;
var hasX = offsets.hasOwnProperty('x');
var hasY = offsets.hasOwnProperty('y');
var sideX = left;
var sideY = top;
var win = window;
if (adaptive) {
var offsetParent = getOffsetParent(popper);
var heightProp = 'clientHeight';
var widthProp = 'clientWidth';
if (offsetParent === getWindow(popper)) {
offsetParent = getDocumentElement(popper);
if (getComputedStyle(offsetParent).position !== 'static') {
heightProp = 'scrollHeight';
widthProp = 'scrollWidth';
}
} // $FlowFixMe[incompatible-cast]: force type refinement, we compare offsetParent with window above, but Flow doesn't detect it
offsetParent = offsetParent;
if (placement === top) {
sideY = bottom; // $FlowFixMe[prop-missing]
y -= offsetParent[heightProp] - popperRect.height;
y *= gpuAcceleration ? 1 : -1;
}
if (placement === left) {
sideX = right; // $FlowFixMe[prop-missing]
x -= offsetParent[widthProp] - popperRect.width;
x *= gpuAcceleration ? 1 : -1;
}
}
var commonStyles = Object.assign({
position: position
}, adaptive && unsetSides);
if (gpuAcceleration) {
var _Object$assign;
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));
}
return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
}
function computeStyles(_ref4) {
var state = _ref4.state,
options = _ref4.options;
var _options$gpuAccelerat = options.gpuAcceleration,
gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat,
_options$adaptive = options.adaptive,
adaptive = _options$adaptive === void 0 ? true : _options$adaptive,
_options$roundOffsets = options.roundOffsets,
roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
if (false) {
var transitionProperty = getComputedStyle(state.elements.popper).transitionProperty || '';
if (adaptive && ['transform', 'top', 'right', 'bottom', 'left'].some(function (property) {
return transitionProperty.indexOf(property) >= 0;
})) {
console.warn(['Popper: Detected CSS transitions on at least one of the following', 'CSS properties: "transform", "top", "right", "bottom", "left".', '\n\n', 'Disable the "computeStyles" modifier\'s `adaptive` option to allow', 'for smooth transitions, or remove these properties from the CSS', 'transition declaration on the popper element if only transitioning', 'opacity or background-color for example.', '\n\n', 'We recommend using the popper element as a wrapper around an inner', 'element that can have any CSS property transitioned for animations.'].join(' '));
}
}
var commonStyles = {
placement: getBasePlacement(state.placement),
popper: state.elements.popper,
popperRect: state.rects.popper,
gpuAcceleration: gpuAcceleration
};
if (state.modifiersData.popperOffsets != null) {
state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
offsets: state.modifiersData.popperOffsets,
position: state.options.strategy,
adaptive: adaptive,
roundOffsets: roundOffsets
})));
}
if (state.modifiersData.arrow != null) {
state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
offsets: state.modifiersData.arrow,
position: 'absolute',
adaptive: false,
roundOffsets: roundOffsets
})));
}
state.attributes.popper = Object.assign({}, state.attributes.popper, {
'data-popper-placement': state.placement
});
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'computeStyles',
enabled: true,
phase: 'beforeWrite',
fn: computeStyles,
data: {}
};

View File

@@ -0,0 +1,49 @@
import getWindow from "../dom-utils/getWindow.js"; // eslint-disable-next-line import/no-unused-modules
var passive = {
passive: true
};
function effect(_ref) {
var state = _ref.state,
instance = _ref.instance,
options = _ref.options;
var _options$scroll = options.scroll,
scroll = _options$scroll === void 0 ? true : _options$scroll,
_options$resize = options.resize,
resize = _options$resize === void 0 ? true : _options$resize;
var window = getWindow(state.elements.popper);
var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
if (scroll) {
scrollParents.forEach(function (scrollParent) {
scrollParent.addEventListener('scroll', instance.update, passive);
});
}
if (resize) {
window.addEventListener('resize', instance.update, passive);
}
return function () {
if (scroll) {
scrollParents.forEach(function (scrollParent) {
scrollParent.removeEventListener('scroll', instance.update, passive);
});
}
if (resize) {
window.removeEventListener('resize', instance.update, passive);
}
};
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'eventListeners',
enabled: true,
phase: 'write',
fn: function fn() {},
effect: effect,
data: {}
};

View File

@@ -0,0 +1,147 @@
import getOppositePlacement from "../utils/getOppositePlacement.js";
import getBasePlacement from "../utils/getBasePlacement.js";
import getOppositeVariationPlacement from "../utils/getOppositeVariationPlacement.js";
import detectOverflow from "../utils/detectOverflow.js";
import computeAutoPlacement from "../utils/computeAutoPlacement.js";
import { bottom, top, start, right, left, auto } from "../enums.js";
import getVariation from "../utils/getVariation.js"; // eslint-disable-next-line import/no-unused-modules
function getExpandedFallbackPlacements(placement) {
if (getBasePlacement(placement) === auto) {
return [];
}
var oppositePlacement = getOppositePlacement(placement);
return [getOppositeVariationPlacement(placement), oppositePlacement, getOppositeVariationPlacement(oppositePlacement)];
}
function flip(_ref) {
var state = _ref.state,
options = _ref.options,
name = _ref.name;
if (state.modifiersData[name]._skip) {
return;
}
var _options$mainAxis = options.mainAxis,
checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
_options$altAxis = options.altAxis,
checkAltAxis = _options$altAxis === void 0 ? true : _options$altAxis,
specifiedFallbackPlacements = options.fallbackPlacements,
padding = options.padding,
boundary = options.boundary,
rootBoundary = options.rootBoundary,
altBoundary = options.altBoundary,
_options$flipVariatio = options.flipVariations,
flipVariations = _options$flipVariatio === void 0 ? true : _options$flipVariatio,
allowedAutoPlacements = options.allowedAutoPlacements;
var preferredPlacement = state.options.placement;
var basePlacement = getBasePlacement(preferredPlacement);
var isBasePlacement = basePlacement === preferredPlacement;
var fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipVariations ? [getOppositePlacement(preferredPlacement)] : getExpandedFallbackPlacements(preferredPlacement));
var placements = [preferredPlacement].concat(fallbackPlacements).reduce(function (acc, placement) {
return acc.concat(getBasePlacement(placement) === auto ? computeAutoPlacement(state, {
placement: placement,
boundary: boundary,
rootBoundary: rootBoundary,
padding: padding,
flipVariations: flipVariations,
allowedAutoPlacements: allowedAutoPlacements
}) : placement);
}, []);
var referenceRect = state.rects.reference;
var popperRect = state.rects.popper;
var checksMap = new Map();
var makeFallbackChecks = true;
var firstFittingPlacement = placements[0];
for (var i = 0; i < placements.length; i++) {
var placement = placements[i];
var _basePlacement = getBasePlacement(placement);
var isStartVariation = getVariation(placement) === start;
var isVertical = [top, bottom].indexOf(_basePlacement) >= 0;
var len = isVertical ? 'width' : 'height';
var overflow = detectOverflow(state, {
placement: placement,
boundary: boundary,
rootBoundary: rootBoundary,
altBoundary: altBoundary,
padding: padding
});
var mainVariationSide = isVertical ? isStartVariation ? right : left : isStartVariation ? bottom : top;
if (referenceRect[len] > popperRect[len]) {
mainVariationSide = getOppositePlacement(mainVariationSide);
}
var altVariationSide = getOppositePlacement(mainVariationSide);
var checks = [];
if (checkMainAxis) {
checks.push(overflow[_basePlacement] <= 0);
}
if (checkAltAxis) {
checks.push(overflow[mainVariationSide] <= 0, overflow[altVariationSide] <= 0);
}
if (checks.every(function (check) {
return check;
})) {
firstFittingPlacement = placement;
makeFallbackChecks = false;
break;
}
checksMap.set(placement, checks);
}
if (makeFallbackChecks) {
// `2` may be desired in some cases research later
var numberOfChecks = flipVariations ? 3 : 1;
var _loop = function _loop(_i) {
var fittingPlacement = placements.find(function (placement) {
var checks = checksMap.get(placement);
if (checks) {
return checks.slice(0, _i).every(function (check) {
return check;
});
}
});
if (fittingPlacement) {
firstFittingPlacement = fittingPlacement;
return "break";
}
};
for (var _i = numberOfChecks; _i > 0; _i--) {
var _ret = _loop(_i);
if (_ret === "break") break;
}
}
if (state.placement !== firstFittingPlacement) {
state.modifiersData[name]._skip = true;
state.placement = firstFittingPlacement;
state.reset = true;
}
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'flip',
enabled: true,
phase: 'main',
fn: flip,
requiresIfExists: ['offset'],
data: {
_skip: false
}
};

View File

@@ -0,0 +1,61 @@
import { top, bottom, left, right } from "../enums.js";
import detectOverflow from "../utils/detectOverflow.js";
function getSideOffsets(overflow, rect, preventedOffsets) {
if (preventedOffsets === void 0) {
preventedOffsets = {
x: 0,
y: 0
};
}
return {
top: overflow.top - rect.height - preventedOffsets.y,
right: overflow.right - rect.width + preventedOffsets.x,
bottom: overflow.bottom - rect.height + preventedOffsets.y,
left: overflow.left - rect.width - preventedOffsets.x
};
}
function isAnySideFullyClipped(overflow) {
return [top, right, bottom, left].some(function (side) {
return overflow[side] >= 0;
});
}
function hide(_ref) {
var state = _ref.state,
name = _ref.name;
var referenceRect = state.rects.reference;
var popperRect = state.rects.popper;
var preventedOffsets = state.modifiersData.preventOverflow;
var referenceOverflow = detectOverflow(state, {
elementContext: 'reference'
});
var popperAltOverflow = detectOverflow(state, {
altBoundary: true
});
var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
state.modifiersData[name] = {
referenceClippingOffsets: referenceClippingOffsets,
popperEscapeOffsets: popperEscapeOffsets,
isReferenceHidden: isReferenceHidden,
hasPopperEscaped: hasPopperEscaped
};
state.attributes.popper = Object.assign({}, state.attributes.popper, {
'data-popper-reference-hidden': isReferenceHidden,
'data-popper-escaped': hasPopperEscaped
});
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'hide',
enabled: true,
phase: 'main',
requiresIfExists: ['preventOverflow'],
fn: hide
};

View File

@@ -0,0 +1,9 @@
export { default as applyStyles } from "./applyStyles.js";
export { default as arrow } from "./arrow.js";
export { default as computeStyles } from "./computeStyles.js";
export { default as eventListeners } from "./eventListeners.js";
export { default as flip } from "./flip.js";
export { default as hide } from "./hide.js";
export { default as offset } from "./offset.js";
export { default as popperOffsets } from "./popperOffsets.js";
export { default as preventOverflow } from "./preventOverflow.js";

View File

@@ -0,0 +1,53 @@
import getBasePlacement from "../utils/getBasePlacement.js";
import { top, left, right, placements } from "../enums.js";
export function distanceAndSkiddingToXY(placement, rects, offset) {
var basePlacement = getBasePlacement(placement);
var invertDistance = [left, top].indexOf(basePlacement) >= 0 ? -1 : 1;
var _ref = typeof offset === 'function' ? offset(Object.assign({}, rects, {
placement: placement
})) : offset,
skidding = _ref[0],
distance = _ref[1];
skidding = skidding || 0;
distance = (distance || 0) * invertDistance;
return [left, right].indexOf(basePlacement) >= 0 ? {
x: distance,
y: skidding
} : {
x: skidding,
y: distance
};
}
function offset(_ref2) {
var state = _ref2.state,
options = _ref2.options,
name = _ref2.name;
var _options$offset = options.offset,
offset = _options$offset === void 0 ? [0, 0] : _options$offset;
var data = placements.reduce(function (acc, placement) {
acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset);
return acc;
}, {});
var _data$state$placement = data[state.placement],
x = _data$state$placement.x,
y = _data$state$placement.y;
if (state.modifiersData.popperOffsets != null) {
state.modifiersData.popperOffsets.x += x;
state.modifiersData.popperOffsets.y += y;
}
state.modifiersData[name] = data;
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'offset',
enabled: true,
phase: 'main',
requires: ['popperOffsets'],
fn: offset
};

View File

@@ -0,0 +1,25 @@
import computeOffsets from "../utils/computeOffsets.js";
function popperOffsets(_ref) {
var state = _ref.state,
name = _ref.name;
// Offsets are the actual position the popper needs to have to be
// properly positioned near its reference element
// This is the most basic placement, and will be adjusted by
// the modifiers in the next step
state.modifiersData[name] = computeOffsets({
reference: state.rects.reference,
element: state.rects.popper,
strategy: 'absolute',
placement: state.placement
});
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'popperOffsets',
enabled: true,
phase: 'read',
fn: popperOffsets,
data: {}
};

View File

@@ -0,0 +1,123 @@
import { top, left, right, bottom, start } from "../enums.js";
import getBasePlacement from "../utils/getBasePlacement.js";
import getMainAxisFromPlacement from "../utils/getMainAxisFromPlacement.js";
import getAltAxis from "../utils/getAltAxis.js";
import within from "../utils/within.js";
import getLayoutRect from "../dom-utils/getLayoutRect.js";
import getOffsetParent from "../dom-utils/getOffsetParent.js";
import detectOverflow from "../utils/detectOverflow.js";
import getVariation from "../utils/getVariation.js";
import getFreshSideObject from "../utils/getFreshSideObject.js";
import { max as mathMax, min as mathMin } from "../utils/math.js";
function preventOverflow(_ref) {
var state = _ref.state,
options = _ref.options,
name = _ref.name;
var _options$mainAxis = options.mainAxis,
checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
_options$altAxis = options.altAxis,
checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis,
boundary = options.boundary,
rootBoundary = options.rootBoundary,
altBoundary = options.altBoundary,
padding = options.padding,
_options$tether = options.tether,
tether = _options$tether === void 0 ? true : _options$tether,
_options$tetherOffset = options.tetherOffset,
tetherOffset = _options$tetherOffset === void 0 ? 0 : _options$tetherOffset;
var overflow = detectOverflow(state, {
boundary: boundary,
rootBoundary: rootBoundary,
padding: padding,
altBoundary: altBoundary
});
var basePlacement = getBasePlacement(state.placement);
var variation = getVariation(state.placement);
var isBasePlacement = !variation;
var mainAxis = getMainAxisFromPlacement(basePlacement);
var altAxis = getAltAxis(mainAxis);
var popperOffsets = state.modifiersData.popperOffsets;
var referenceRect = state.rects.reference;
var popperRect = state.rects.popper;
var tetherOffsetValue = typeof tetherOffset === 'function' ? tetherOffset(Object.assign({}, state.rects, {
placement: state.placement
})) : tetherOffset;
var data = {
x: 0,
y: 0
};
if (!popperOffsets) {
return;
}
if (checkMainAxis || checkAltAxis) {
var mainSide = mainAxis === 'y' ? top : left;
var altSide = mainAxis === 'y' ? bottom : right;
var len = mainAxis === 'y' ? 'height' : 'width';
var offset = popperOffsets[mainAxis];
var min = popperOffsets[mainAxis] + overflow[mainSide];
var max = popperOffsets[mainAxis] - overflow[altSide];
var additive = tether ? -popperRect[len] / 2 : 0;
var minLen = variation === start ? referenceRect[len] : popperRect[len];
var maxLen = variation === start ? -popperRect[len] : -referenceRect[len]; // We need to include the arrow in the calculation so the arrow doesn't go
// outside the reference bounds
var arrowElement = state.elements.arrow;
var arrowRect = tether && arrowElement ? getLayoutRect(arrowElement) : {
width: 0,
height: 0
};
var arrowPaddingObject = state.modifiersData['arrow#persistent'] ? state.modifiersData['arrow#persistent'].padding : getFreshSideObject();
var arrowPaddingMin = arrowPaddingObject[mainSide];
var arrowPaddingMax = arrowPaddingObject[altSide]; // If the reference length is smaller than the arrow length, we don't want
// to include its full size in the calculation. If the reference is small
// and near the edge of a boundary, the popper can overflow even if the
// reference is not overflowing as well (e.g. virtual elements with no
// width or height)
var arrowLen = within(0, referenceRect[len], arrowRect[len]);
var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - tetherOffsetValue : minLen - arrowLen - arrowPaddingMin - tetherOffsetValue;
var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + tetherOffsetValue : maxLen + arrowLen + arrowPaddingMax + tetherOffsetValue;
var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
var clientOffset = arrowOffsetParent ? mainAxis === 'y' ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
var offsetModifierValue = state.modifiersData.offset ? state.modifiersData.offset[state.placement][mainAxis] : 0;
var tetherMin = popperOffsets[mainAxis] + minOffset - offsetModifierValue - clientOffset;
var tetherMax = popperOffsets[mainAxis] + maxOffset - offsetModifierValue;
if (checkMainAxis) {
var preventedOffset = within(tether ? mathMin(min, tetherMin) : min, offset, tether ? mathMax(max, tetherMax) : max);
popperOffsets[mainAxis] = preventedOffset;
data[mainAxis] = preventedOffset - offset;
}
if (checkAltAxis) {
var _mainSide = mainAxis === 'x' ? top : left;
var _altSide = mainAxis === 'x' ? bottom : right;
var _offset = popperOffsets[altAxis];
var _min = _offset + overflow[_mainSide];
var _max = _offset - overflow[_altSide];
var _preventedOffset = within(tether ? mathMin(_min, tetherMin) : _min, _offset, tether ? mathMax(_max, tetherMax) : _max);
popperOffsets[altAxis] = _preventedOffset;
data[altAxis] = _preventedOffset - _offset;
}
}
state.modifiersData[name] = data;
} // eslint-disable-next-line import/no-unused-modules
export default {
name: 'preventOverflow',
enabled: true,
phase: 'main',
fn: preventOverflow,
requiresIfExists: ['offset']
};

View File

@@ -0,0 +1,3 @@
import { createPopper, popperGenerator, detectOverflow } from "./createPopper.js";
// eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, detectOverflow };

View File

@@ -0,0 +1,11 @@
import { popperGenerator, detectOverflow } from "./createPopper.js";
import eventListeners from "./modifiers/eventListeners.js";
import popperOffsets from "./modifiers/popperOffsets.js";
import computeStyles from "./modifiers/computeStyles.js";
import applyStyles from "./modifiers/applyStyles.js";
var defaultModifiers = [eventListeners, popperOffsets, computeStyles, applyStyles];
var createPopper = /*#__PURE__*/popperGenerator({
defaultModifiers: defaultModifiers
}); // eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, defaultModifiers, detectOverflow };

View File

@@ -0,0 +1,20 @@
import { popperGenerator, detectOverflow } from "./createPopper.js";
import eventListeners from "./modifiers/eventListeners.js";
import popperOffsets from "./modifiers/popperOffsets.js";
import computeStyles from "./modifiers/computeStyles.js";
import applyStyles from "./modifiers/applyStyles.js";
import offset from "./modifiers/offset.js";
import flip from "./modifiers/flip.js";
import preventOverflow from "./modifiers/preventOverflow.js";
import arrow from "./modifiers/arrow.js";
import hide from "./modifiers/hide.js";
var defaultModifiers = [eventListeners, popperOffsets, computeStyles, applyStyles, offset, flip, preventOverflow, arrow, hide];
var createPopper = /*#__PURE__*/popperGenerator({
defaultModifiers: defaultModifiers
}); // eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, defaultModifiers, detectOverflow }; // eslint-disable-next-line import/no-unused-modules
export { createPopper as createPopperLite } from "./popper-lite.js"; // eslint-disable-next-line import/no-unused-modules
export * from "./modifiers/index.js";

View File

@@ -0,0 +1,47 @@
import getVariation from "./getVariation.js";
import { variationPlacements, basePlacements, placements as allPlacements } from "../enums.js";
import detectOverflow from "./detectOverflow.js";
import getBasePlacement from "./getBasePlacement.js";
export default function computeAutoPlacement(state, options) {
if (options === void 0) {
options = {};
}
var _options = options,
placement = _options.placement,
boundary = _options.boundary,
rootBoundary = _options.rootBoundary,
padding = _options.padding,
flipVariations = _options.flipVariations,
_options$allowedAutoP = _options.allowedAutoPlacements,
allowedAutoPlacements = _options$allowedAutoP === void 0 ? allPlacements : _options$allowedAutoP;
var variation = getVariation(placement);
var placements = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function (placement) {
return getVariation(placement) === variation;
}) : basePlacements;
var allowedPlacements = placements.filter(function (placement) {
return allowedAutoPlacements.indexOf(placement) >= 0;
});
if (allowedPlacements.length === 0) {
allowedPlacements = placements;
if (false) {
console.error(['Popper: The `allowedAutoPlacements` option did not allow any', 'placements. Ensure the `placement` option matches the variation', 'of the allowed placements.', 'For example, "auto" cannot be used to allow "bottom-start".', 'Use "auto-start" instead.'].join(' '));
}
} // $FlowFixMe[incompatible-type]: Flow seems to have problems with two array unions...
var overflows = allowedPlacements.reduce(function (acc, placement) {
acc[placement] = detectOverflow(state, {
placement: placement,
boundary: boundary,
rootBoundary: rootBoundary,
padding: padding
})[getBasePlacement(placement)];
return acc;
}, {});
return Object.keys(overflows).sort(function (a, b) {
return overflows[a] - overflows[b];
});
}

View File

@@ -0,0 +1,70 @@
import getBasePlacement from "./getBasePlacement.js";
import getVariation from "./getVariation.js";
import getMainAxisFromPlacement from "./getMainAxisFromPlacement.js";
import { top, right, bottom, left, start, end } from "../enums.js";
export default function computeOffsets(_ref) {
var reference = _ref.reference,
element = _ref.element,
placement = _ref.placement;
var basePlacement = placement ? getBasePlacement(placement) : null;
var variation = placement ? getVariation(placement) : null;
var commonX = reference.x + reference.width / 2 - element.width / 2;
var commonY = reference.y + reference.height / 2 - element.height / 2;
var offsets;
switch (basePlacement) {
case top:
offsets = {
x: commonX,
y: reference.y - element.height
};
break;
case bottom:
offsets = {
x: commonX,
y: reference.y + reference.height
};
break;
case right:
offsets = {
x: reference.x + reference.width,
y: commonY
};
break;
case left:
offsets = {
x: reference.x - element.width,
y: commonY
};
break;
default:
offsets = {
x: reference.x,
y: reference.y
};
}
var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
if (mainAxis != null) {
var len = mainAxis === 'y' ? 'height' : 'width';
switch (variation) {
case start:
offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
break;
case end:
offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
break;
default:
}
}
return offsets;
}

View File

@@ -0,0 +1,15 @@
export default function debounce(fn) {
var pending;
return function () {
if (!pending) {
pending = new Promise(function (resolve) {
Promise.resolve().then(function () {
pending = undefined;
resolve(fn());
});
});
}
return pending;
};
}

View File

@@ -0,0 +1,64 @@
import getBoundingClientRect from "../dom-utils/getBoundingClientRect.js";
import getClippingRect from "../dom-utils/getClippingRect.js";
import getDocumentElement from "../dom-utils/getDocumentElement.js";
import computeOffsets from "./computeOffsets.js";
import rectToClientRect from "./rectToClientRect.js";
import { clippingParents, reference, popper, bottom, top, right, basePlacements, viewport } from "../enums.js";
import { isElement } from "../dom-utils/instanceOf.js";
import mergePaddingObject from "./mergePaddingObject.js";
import expandToHashMap from "./expandToHashMap.js"; // eslint-disable-next-line import/no-unused-modules
export default function detectOverflow(state, options) {
if (options === void 0) {
options = {};
}
var _options = options,
_options$placement = _options.placement,
placement = _options$placement === void 0 ? state.placement : _options$placement,
_options$boundary = _options.boundary,
boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
_options$rootBoundary = _options.rootBoundary,
rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
_options$elementConte = _options.elementContext,
elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
_options$altBoundary = _options.altBoundary,
altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
_options$padding = _options.padding,
padding = _options$padding === void 0 ? 0 : _options$padding;
var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
var altContext = elementContext === popper ? reference : popper;
var referenceElement = state.elements.reference;
var popperRect = state.rects.popper;
var element = state.elements[altBoundary ? altContext : elementContext];
var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
var referenceClientRect = getBoundingClientRect(referenceElement);
var popperOffsets = computeOffsets({
reference: referenceClientRect,
element: popperRect,
strategy: 'absolute',
placement: placement
});
var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect; // positive = overflowing the clipping rect
// 0 or negative = within the clipping rect
var overflowOffsets = {
top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
right: elementClientRect.right - clippingClientRect.right + paddingObject.right
};
var offsetData = state.modifiersData.offset; // Offsets can be applied only to the popper element
if (elementContext === popper && offsetData) {
var offset = offsetData[placement];
Object.keys(overflowOffsets).forEach(function (key) {
var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
overflowOffsets[key] += offset[axis] * multiply;
});
}
return overflowOffsets;
}

View File

@@ -0,0 +1,6 @@
export default function expandToHashMap(value, keys) {
return keys.reduce(function (hashMap, key) {
hashMap[key] = value;
return hashMap;
}, {});
}

View File

@@ -0,0 +1,9 @@
export default function format(str) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return [].concat(args).reduce(function (p, c) {
return p.replace(/%s/, c);
}, str);
}

View File

@@ -0,0 +1,3 @@
export default function getAltAxis(axis) {
return axis === 'x' ? 'y' : 'x';
}

View File

@@ -0,0 +1,3 @@
export default function getAltLen(len) {
return len === 'width' ? 'height' : 'width';
}

View File

@@ -0,0 +1,4 @@
import { auto } from "../enums.js";
export default function getBasePlacement(placement) {
return placement.split('-')[0];
}

View File

@@ -0,0 +1,8 @@
export default function getFreshSideObject() {
return {
top: 0,
right: 0,
bottom: 0,
left: 0
};
}

View File

@@ -0,0 +1,3 @@
export default function getMainAxisFromPlacement(placement) {
return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
}

View File

@@ -0,0 +1,11 @@
var hash = {
left: 'right',
right: 'left',
bottom: 'top',
top: 'bottom'
};
export default function getOppositePlacement(placement) {
return placement.replace(/left|right|bottom|top/g, function (matched) {
return hash[matched];
});
}

View File

@@ -0,0 +1,9 @@
var hash = {
start: 'end',
end: 'start'
};
export default function getOppositeVariationPlacement(placement) {
return placement.replace(/start|end/g, function (matched) {
return hash[matched];
});
}

View File

@@ -0,0 +1,3 @@
export default function getVariation(placement) {
return placement.split('-')[1];
}

View File

@@ -0,0 +1,3 @@
export var max = Math.max;
export var min = Math.min;
export var round = Math.round;

View File

@@ -0,0 +1,14 @@
export default function mergeByName(modifiers) {
var merged = modifiers.reduce(function (merged, current) {
var existing = merged[current.name];
merged[current.name] = existing ? Object.assign({}, existing, current, {
options: Object.assign({}, existing.options, current.options),
data: Object.assign({}, existing.data, current.data)
}) : current;
return merged;
}, {}); // IE11 does not support Object.values
return Object.keys(merged).map(function (key) {
return merged[key];
});
}

View File

@@ -0,0 +1,4 @@
import getFreshSideObject from "./getFreshSideObject.js";
export default function mergePaddingObject(paddingObject) {
return Object.assign({}, getFreshSideObject(), paddingObject);
}

View File

@@ -0,0 +1,44 @@
import { modifierPhases } from "../enums.js"; // source: https://stackoverflow.com/questions/49875255
function order(modifiers) {
var map = new Map();
var visited = new Set();
var result = [];
modifiers.forEach(function (modifier) {
map.set(modifier.name, modifier);
}); // On visiting object, check for its dependencies and visit them recursively
function sort(modifier) {
visited.add(modifier.name);
var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
requires.forEach(function (dep) {
if (!visited.has(dep)) {
var depModifier = map.get(dep);
if (depModifier) {
sort(depModifier);
}
}
});
result.push(modifier);
}
modifiers.forEach(function (modifier) {
if (!visited.has(modifier.name)) {
// check for visited object
sort(modifier);
}
});
return result;
}
export default function orderModifiers(modifiers) {
// order based on dependencies
var orderedModifiers = order(modifiers); // order based on phase
return modifierPhases.reduce(function (acc, phase) {
return acc.concat(orderedModifiers.filter(function (modifier) {
return modifier.phase === phase;
}));
}, []);
}

View File

@@ -0,0 +1,8 @@
export default function rectToClientRect(rect) {
return Object.assign({}, rect, {
left: rect.x,
top: rect.y,
right: rect.x + rect.width,
bottom: rect.y + rect.height
});
}

View File

@@ -0,0 +1,11 @@
export default function uniqueBy(arr, fn) {
var identifiers = new Set();
return arr.filter(function (item) {
var identifier = fn(item);
if (!identifiers.has(identifier)) {
identifiers.add(identifier);
return true;
}
});
}

View File

@@ -0,0 +1,76 @@
import format from "./format.js";
import { modifierPhases } from "../enums.js";
var INVALID_MODIFIER_ERROR = 'Popper: modifier "%s" provided an invalid %s property, expected %s but got %s';
var MISSING_DEPENDENCY_ERROR = 'Popper: modifier "%s" requires "%s", but "%s" modifier is not available';
var VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'effect', 'requires', 'options'];
export default function validateModifiers(modifiers) {
modifiers.forEach(function (modifier) {
Object.keys(modifier).forEach(function (key) {
switch (key) {
case 'name':
if (typeof modifier.name !== 'string') {
console.error(format(INVALID_MODIFIER_ERROR, String(modifier.name), '"name"', '"string"', "\"" + String(modifier.name) + "\""));
}
break;
case 'enabled':
if (typeof modifier.enabled !== 'boolean') {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"enabled"', '"boolean"', "\"" + String(modifier.enabled) + "\""));
}
case 'phase':
if (modifierPhases.indexOf(modifier.phase) < 0) {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"phase"', "either " + modifierPhases.join(', '), "\"" + String(modifier.phase) + "\""));
}
break;
case 'fn':
if (typeof modifier.fn !== 'function') {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"fn"', '"function"', "\"" + String(modifier.fn) + "\""));
}
break;
case 'effect':
if (typeof modifier.effect !== 'function') {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"effect"', '"function"', "\"" + String(modifier.fn) + "\""));
}
break;
case 'requires':
if (!Array.isArray(modifier.requires)) {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"requires"', '"array"', "\"" + String(modifier.requires) + "\""));
}
break;
case 'requiresIfExists':
if (!Array.isArray(modifier.requiresIfExists)) {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"requiresIfExists"', '"array"', "\"" + String(modifier.requiresIfExists) + "\""));
}
break;
case 'options':
case 'data':
break;
default:
console.error("PopperJS: an invalid property has been provided to the \"" + modifier.name + "\" modifier, valid properties are " + VALID_PROPERTIES.map(function (s) {
return "\"" + s + "\"";
}).join(', ') + "; but \"" + key + "\" was provided.");
}
modifier.requires && modifier.requires.forEach(function (requirement) {
if (modifiers.find(function (mod) {
return mod.name === requirement;
}) == null) {
console.error(format(MISSING_DEPENDENCY_ERROR, String(modifier.name), requirement, requirement));
}
});
});
});
}

View File

@@ -0,0 +1,4 @@
import { max as mathMax, min as mathMin } from "./math.js";
export default function within(min, value, max) {
return mathMax(min, mathMin(value, max));
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
// @flow
export * from '../../lib/popper-base.js'

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
// @flow
export * from '../../lib/popper-lite.js'

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
// @flow
export * from '../../lib/popper.js'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
/*!
* Bootstrap Reboot v5.1.0 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors
* Copyright 2011-2021 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md)
*/*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}

View File

@@ -0,0 +1,7 @@
/*!
* Bootstrap Reboot v5.1.0 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors
* Copyright 2011-2021 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md)
*/*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-right:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-right:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:right}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:right;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:right}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}[type=email],[type=number],[type=tel],[type=url]{direction:ltr}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,34 @@
.chartist-tooltip {
position: absolute;
display: inline-block;
opacity: 0;
min-width: 5em;
padding: .5em;
background: #F4C63D;
color: #453D3F;
font-family: Oxygen,Helvetica,Arial,sans-serif;
font-weight: 700;
text-align: center;
pointer-events: none;
z-index: 1;
-webkit-transition: opacity .2s linear;
-moz-transition: opacity .2s linear;
-o-transition: opacity .2s linear;
transition: opacity .2s linear; }
.chartist-tooltip:before {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 0;
height: 0;
margin-left: -15px;
border: 15px solid transparent;
border-top-color: #F4C63D; }
.chartist-tooltip.tooltip-show {
opacity: 1; }
.ct-area, .ct-line {
pointer-events: none; }
/*# sourceMappingURL=chartist-plugin-tooltip.css.map */

View File

@@ -0,0 +1,7 @@
/* chartist-plugin-tooltip 0.0.17
* Copyright © 2016 Markus Padourek
* Free to use under the WTFPL license.
* http://www.wtfpl.net/
*/
!function(a,b){"function"==typeof define&&define.amd?define(["chartist"],function(c){return a.returnExportsGlobal=b(c)}):"object"==typeof exports?module.exports=b(require("chartist")):a["Chartist.plugins.tooltips"]=b(Chartist)}(this,function(a){return function(a,b,c){"use strict";function d(a){f(a,"tooltip-show")||(a.className=a.className+" tooltip-show")}function e(a){var b=new RegExp("tooltip-show\\s*","gi");a.className=a.className.replace(b,"").trim()}function f(a,b){return(" "+a.getAttribute("class")+" ").indexOf(" "+b+" ")>-1}function g(a,b){do a=a.nextSibling;while(a&&!f(a,b));return a}function h(a){return a.innerText||a.textContent}var i={currency:void 0,currencyFormatCallback:void 0,tooltipOffset:{x:0,y:-20},anchorToPoint:!1,appendToBody:!1,class:void 0,pointClass:"ct-point"};c.plugins=c.plugins||{},c.plugins.tooltip=function(j){return j=c.extend({},i,j),function(i){function k(a,b,c){n.addEventListener(a,function(a){b&&!f(a.target,b)||c(a)})}function l(b){p=p||o.offsetHeight,q=q||o.offsetWidth;var c,d,e=-q/2+j.tooltipOffset.x,f=-p+j.tooltipOffset.y;if(j.appendToBody)o.style.top=b.pageY+f+"px",o.style.left=b.pageX+e+"px";else{var g=n.getBoundingClientRect(),h=b.pageX-g.left-a.pageXOffset,i=b.pageY-g.top-a.pageYOffset;!0===j.anchorToPoint&&b.target.x2&&b.target.y2&&(c=parseInt(b.target.x2.baseVal.value),d=parseInt(b.target.y2.baseVal.value)),o.style.top=(d||i)+f+"px",o.style.left=(c||h)+e+"px"}}var m=j.pointClass;i instanceof c.Bar?m="ct-bar":i instanceof c.Pie&&(m=i.options.donut?"ct-slice-donut":"ct-slice-pie");var n=i.container,o=n.querySelector(".chartist-tooltip");o||(o=b.createElement("div"),o.className=j.class?"chartist-tooltip "+j.class:"chartist-tooltip",j.appendToBody?b.body.appendChild(o):n.appendChild(o));var p=o.offsetHeight,q=o.offsetWidth;e(o),k("mouseover",m,function(a){var e=a.target,f="",k=i instanceof c.Pie?e:e.parentNode,m=k?e.parentNode.getAttribute("ct:meta")||e.parentNode.getAttribute("ct:series-name"):"",n=e.getAttribute("ct:meta")||m||"",r=!!n,s=e.getAttribute("ct:value");if(j.transformTooltipTextFnc&&"function"==typeof j.transformTooltipTextFnc&&(s=j.transformTooltipTextFnc(s)),j.tooltipFnc&&"function"==typeof j.tooltipFnc)f=j.tooltipFnc(n,s);else{if(j.metaIsHTML){var t=b.createElement("textarea");t.innerHTML=n,n=t.value}if(n='<span class="chartist-tooltip-meta">'+n+"</span>",r)f+=n+"<br>";else if(i instanceof c.Pie){var u=g(e,"ct-label");u&&(f+=h(u)+"<br>")}s&&(j.currency&&(s=void 0!=j.currencyFormatCallback?j.currencyFormatCallback(s,j):j.currency+s.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g,"$1,")),s='<span class="chartist-tooltip-value">'+s+"</span>",f+=s)}f&&(o.innerHTML=f,l(a),d(o),p=o.offsetHeight,q=o.offsetWidth)}),k("mouseout",m,function(){e(o)}),k("mousemove",null,function(a){!1===j.anchorToPoint&&l(a)})}}}(window,document,a),a.plugins.tooltips});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,441 @@
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var NotyfNotification = /** @class */ (function () {
function NotyfNotification(options) {
this.options = options;
this.listeners = {};
}
NotyfNotification.prototype.on = function (eventType, cb) {
var callbacks = this.listeners[eventType] || [];
this.listeners[eventType] = callbacks.concat([cb]);
};
NotyfNotification.prototype.triggerEvent = function (eventType, event) {
var _this = this;
var callbacks = this.listeners[eventType] || [];
callbacks.forEach(function (cb) { return cb({ target: _this, event: event }); });
};
return NotyfNotification;
}());
var NotyfArrayEvent;
(function (NotyfArrayEvent) {
NotyfArrayEvent[NotyfArrayEvent["Add"] = 0] = "Add";
NotyfArrayEvent[NotyfArrayEvent["Remove"] = 1] = "Remove";
})(NotyfArrayEvent || (NotyfArrayEvent = {}));
var NotyfArray = /** @class */ (function () {
function NotyfArray() {
this.notifications = [];
}
NotyfArray.prototype.push = function (elem) {
this.notifications.push(elem);
this.updateFn(elem, NotyfArrayEvent.Add, this.notifications);
};
NotyfArray.prototype.splice = function (index, num) {
var elem = this.notifications.splice(index, num)[0];
this.updateFn(elem, NotyfArrayEvent.Remove, this.notifications);
return elem;
};
NotyfArray.prototype.indexOf = function (elem) {
return this.notifications.indexOf(elem);
};
NotyfArray.prototype.onUpdate = function (fn) {
this.updateFn = fn;
};
return NotyfArray;
}());
var NotyfEvent;
(function (NotyfEvent) {
NotyfEvent["Dismiss"] = "dismiss";
NotyfEvent["Click"] = "click";
})(NotyfEvent || (NotyfEvent = {}));
var DEFAULT_OPTIONS = {
types: [
{
type: 'success',
className: 'notyf__toast--success',
backgroundColor: '#3dc763',
icon: {
className: 'notyf__icon--success',
tagName: 'i',
},
},
{
type: 'error',
className: 'notyf__toast--error',
backgroundColor: '#ed3d3d',
icon: {
className: 'notyf__icon--error',
tagName: 'i',
},
},
],
duration: 2000,
ripple: true,
position: {
x: 'right',
y: 'bottom',
},
dismissible: false,
};
var NotyfView = /** @class */ (function () {
function NotyfView() {
this.notifications = [];
this.events = {};
this.X_POSITION_FLEX_MAP = {
left: 'flex-start',
center: 'center',
right: 'flex-end',
};
this.Y_POSITION_FLEX_MAP = {
top: 'flex-start',
center: 'center',
bottom: 'flex-end',
};
// Creates the main notifications container
var docFrag = document.createDocumentFragment();
var notyfContainer = this._createHTMLElement({ tagName: 'div', className: 'notyf' });
docFrag.appendChild(notyfContainer);
document.body.appendChild(docFrag);
this.container = notyfContainer;
// Identifies the main animation end event
this.animationEndEventName = this._getAnimationEndEventName();
this._createA11yContainer();
}
NotyfView.prototype.on = function (event, cb) {
var _a;
this.events = __assign(__assign({}, this.events), (_a = {}, _a[event] = cb, _a));
};
NotyfView.prototype.update = function (notification, type) {
if (type === NotyfArrayEvent.Add) {
this.addNotification(notification);
}
else if (type === NotyfArrayEvent.Remove) {
this.removeNotification(notification);
}
};
NotyfView.prototype.removeNotification = function (notification) {
var _this = this;
var renderedNotification = this._popRenderedNotification(notification);
var node;
if (!renderedNotification) {
return;
}
node = renderedNotification.node;
node.classList.add('notyf__toast--disappear');
var handleEvent;
node.addEventListener(this.animationEndEventName, (handleEvent = function (event) {
if (event.target === node) {
node.removeEventListener(_this.animationEndEventName, handleEvent);
_this.container.removeChild(node);
}
}));
};
NotyfView.prototype.addNotification = function (notification) {
var node = this._renderNotification(notification);
this.notifications.push({ notification: notification, node: node });
// For a11y purposes, we still want to announce that there's a notification in the screen
// even if it comes with no message.
this._announce(notification.options.message || 'Notification');
};
NotyfView.prototype._renderNotification = function (notification) {
var _a;
var card = this._buildNotificationCard(notification);
var className = notification.options.className;
if (className) {
(_a = card.classList).add.apply(_a, className.split(' '));
}
this.container.appendChild(card);
return card;
};
NotyfView.prototype._popRenderedNotification = function (notification) {
var idx = -1;
for (var i = 0; i < this.notifications.length && idx < 0; i++) {
if (this.notifications[i].notification === notification) {
idx = i;
}
}
if (idx !== -1) {
return this.notifications.splice(idx, 1)[0];
}
return;
};
NotyfView.prototype.getXPosition = function (options) {
var _a;
return ((_a = options === null || options === void 0 ? void 0 : options.position) === null || _a === void 0 ? void 0 : _a.x) || 'right';
};
NotyfView.prototype.getYPosition = function (options) {
var _a;
return ((_a = options === null || options === void 0 ? void 0 : options.position) === null || _a === void 0 ? void 0 : _a.y) || 'bottom';
};
NotyfView.prototype.adjustContainerAlignment = function (options) {
var align = this.X_POSITION_FLEX_MAP[this.getXPosition(options)];
var justify = this.Y_POSITION_FLEX_MAP[this.getYPosition(options)];
var style = this.container.style;
style.setProperty('justify-content', justify);
style.setProperty('align-items', align);
};
NotyfView.prototype._buildNotificationCard = function (notification) {
var _this = this;
var options = notification.options;
var iconOpts = options.icon;
// Adjust container according to position (e.g. top-left, bottom-center, etc)
this.adjustContainerAlignment(options);
// Create elements
var notificationElem = this._createHTMLElement({ tagName: 'div', className: 'notyf__toast' });
var ripple = this._createHTMLElement({ tagName: 'div', className: 'notyf__ripple' });
var wrapper = this._createHTMLElement({ tagName: 'div', className: 'notyf__wrapper' });
var message = this._createHTMLElement({ tagName: 'div', className: 'notyf__message' });
message.innerHTML = options.message || '';
var mainColor = options.background || options.backgroundColor;
// Build the icon and append it to the card
if (iconOpts) {
var iconContainer = this._createHTMLElement({ tagName: 'div', className: 'notyf__icon' });
if (typeof iconOpts === 'string' || iconOpts instanceof String)
iconContainer.innerHTML = new String(iconOpts).valueOf();
if (typeof iconOpts === 'object') {
var _a = iconOpts.tagName, tagName = _a === void 0 ? 'i' : _a, className_1 = iconOpts.className, text = iconOpts.text, _b = iconOpts.color, color = _b === void 0 ? mainColor : _b;
var iconElement = this._createHTMLElement({ tagName: tagName, className: className_1, text: text });
if (color)
iconElement.style.color = color;
iconContainer.appendChild(iconElement);
}
wrapper.appendChild(iconContainer);
}
wrapper.appendChild(message);
notificationElem.appendChild(wrapper);
// Add ripple if applicable, else just paint the full toast
if (mainColor) {
if (options.ripple) {
ripple.style.background = mainColor;
notificationElem.appendChild(ripple);
}
else {
notificationElem.style.background = mainColor;
}
}
// Add dismiss button
if (options.dismissible) {
var dismissWrapper = this._createHTMLElement({ tagName: 'div', className: 'notyf__dismiss' });
var dismissButton = this._createHTMLElement({
tagName: 'button',
className: 'notyf__dismiss-btn',
});
dismissWrapper.appendChild(dismissButton);
wrapper.appendChild(dismissWrapper);
notificationElem.classList.add("notyf__toast--dismissible");
dismissButton.addEventListener('click', function (event) {
var _a, _b;
(_b = (_a = _this.events)[NotyfEvent.Dismiss]) === null || _b === void 0 ? void 0 : _b.call(_a, { target: notification, event: event });
event.stopPropagation();
});
}
notificationElem.addEventListener('click', function (event) { var _a, _b; return (_b = (_a = _this.events)[NotyfEvent.Click]) === null || _b === void 0 ? void 0 : _b.call(_a, { target: notification, event: event }); });
// Adjust margins depending on whether its an upper or lower notification
var className = this.getYPosition(options) === 'top' ? 'upper' : 'lower';
notificationElem.classList.add("notyf__toast--" + className);
return notificationElem;
};
NotyfView.prototype._createHTMLElement = function (_a) {
var tagName = _a.tagName, className = _a.className, text = _a.text;
var elem = document.createElement(tagName);
if (className) {
elem.className = className;
}
elem.textContent = text || null;
return elem;
};
/**
* Creates an invisible container which will announce the notyfs to
* screen readers
*/
NotyfView.prototype._createA11yContainer = function () {
var a11yContainer = this._createHTMLElement({ tagName: 'div', className: 'notyf-announcer' });
a11yContainer.setAttribute('aria-atomic', 'true');
a11yContainer.setAttribute('aria-live', 'polite');
// Set the a11y container to be visible hidden. Can't use display: none as
// screen readers won't read it.
a11yContainer.style.border = '0';
a11yContainer.style.clip = 'rect(0 0 0 0)';
a11yContainer.style.height = '1px';
a11yContainer.style.margin = '-1px';
a11yContainer.style.overflow = 'hidden';
a11yContainer.style.padding = '0';
a11yContainer.style.position = 'absolute';
a11yContainer.style.width = '1px';
a11yContainer.style.outline = '0';
document.body.appendChild(a11yContainer);
this.a11yContainer = a11yContainer;
};
/**
* Announces a message to screenreaders.
*/
NotyfView.prototype._announce = function (message) {
var _this = this;
this.a11yContainer.textContent = '';
// This 100ms timeout is necessary for some browser + screen-reader combinations:
// - Both JAWS and NVDA over IE11 will not announce anything without a non-zero timeout.
// - With Chrome and IE11 with NVDA or JAWS, a repeated (identical) message won't be read a
// second time without clearing and then using a non-zero delay.
// (using JAWS 17 at time of this writing).
// https://github.com/angular/material2/blob/master/src/cdk/a11y/live-announcer/live-announcer.ts
setTimeout(function () {
_this.a11yContainer.textContent = message;
}, 100);
};
/**
* Determine which animationend event is supported
*/
NotyfView.prototype._getAnimationEndEventName = function () {
var el = document.createElement('_fake');
var transitions = {
MozTransition: 'animationend',
OTransition: 'oAnimationEnd',
WebkitTransition: 'webkitAnimationEnd',
transition: 'animationend',
};
var t;
for (t in transitions) {
if (el.style[t] !== undefined) {
return transitions[t];
}
}
// No supported animation end event. Using "animationend" as a fallback
return 'animationend';
};
return NotyfView;
}());
/**
* Main controller class. Defines the main Notyf API.
*/
var Notyf = /** @class */ (function () {
function Notyf(opts) {
var _this = this;
this.dismiss = this._removeNotification;
this.notifications = new NotyfArray();
this.view = new NotyfView();
var types = this.registerTypes(opts);
this.options = __assign(__assign({}, DEFAULT_OPTIONS), opts);
this.options.types = types;
this.notifications.onUpdate(function (elem, type) { return _this.view.update(elem, type); });
this.view.on(NotyfEvent.Dismiss, function (_a) {
var target = _a.target, event = _a.event;
_this._removeNotification(target);
// tslint:disable-next-line: no-string-literal
target['triggerEvent'](NotyfEvent.Dismiss, event);
});
// tslint:disable-next-line: no-string-literal
this.view.on(NotyfEvent.Click, function (_a) {
var target = _a.target, event = _a.event;
return target['triggerEvent'](NotyfEvent.Click, event);
});
}
Notyf.prototype.error = function (payload) {
var options = this.normalizeOptions('error', payload);
return this.open(options);
};
Notyf.prototype.success = function (payload) {
var options = this.normalizeOptions('success', payload);
return this.open(options);
};
Notyf.prototype.open = function (options) {
var defaultOpts = this.options.types.find(function (_a) {
var type = _a.type;
return type === options.type;
}) || {};
var config = __assign(__assign({}, defaultOpts), options);
this.assignProps(['ripple', 'position', 'dismissible'], config);
var notification = new NotyfNotification(config);
this._pushNotification(notification);
return notification;
};
Notyf.prototype.dismissAll = function () {
while (this.notifications.splice(0, 1))
;
};
/**
* Assigns properties to a config object based on two rules:
* 1. If the config object already sets that prop, leave it as so
* 2. Otherwise, use the default prop from the global options
*
* It's intended to build the final config object to open a notification. e.g. if
* 'dismissible' is not set, then use the value from the global config.
*
* @param props - properties to be assigned to the config object
* @param config - object whose properties need to be set
*/
Notyf.prototype.assignProps = function (props, config) {
var _this = this;
props.forEach(function (prop) {
// intentional double equality to check for both null and undefined
config[prop] = config[prop] == null ? _this.options[prop] : config[prop];
});
};
Notyf.prototype._pushNotification = function (notification) {
var _this = this;
this.notifications.push(notification);
var duration = notification.options.duration !== undefined ? notification.options.duration : this.options.duration;
if (duration) {
setTimeout(function () { return _this._removeNotification(notification); }, duration);
}
};
Notyf.prototype._removeNotification = function (notification) {
var index = this.notifications.indexOf(notification);
if (index !== -1) {
this.notifications.splice(index, 1);
}
};
Notyf.prototype.normalizeOptions = function (type, payload) {
var options = { type: type };
if (typeof payload === 'string') {
options.message = payload;
}
else if (typeof payload === 'object') {
options = __assign(__assign({}, options), payload);
}
return options;
};
Notyf.prototype.registerTypes = function (opts) {
var incomingTypes = ((opts && opts.types) || []).slice();
var finalDefaultTypes = DEFAULT_OPTIONS.types.map(function (defaultType) {
// find if there's a default type within the user input's types, if so, it means the user
// wants to change some of the default settings
var userTypeIdx = -1;
incomingTypes.forEach(function (t, idx) {
if (t.type === defaultType.type)
userTypeIdx = idx;
});
var userType = userTypeIdx !== -1 ? incomingTypes.splice(userTypeIdx, 1)[0] : {};
return __assign(__assign({}, defaultType), userType);
});
return finalDefaultTypes.concat(incomingTypes);
};
return Notyf;
}());
export { DEFAULT_OPTIONS, Notyf, NotyfArray, NotyfArrayEvent, NotyfEvent, NotyfNotification, NotyfView };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,449 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.Notyf = factory());
}(this, (function () { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var NotyfNotification = /** @class */ (function () {
function NotyfNotification(options) {
this.options = options;
this.listeners = {};
}
NotyfNotification.prototype.on = function (eventType, cb) {
var callbacks = this.listeners[eventType] || [];
this.listeners[eventType] = callbacks.concat([cb]);
};
NotyfNotification.prototype.triggerEvent = function (eventType, event) {
var _this = this;
var callbacks = this.listeners[eventType] || [];
callbacks.forEach(function (cb) { return cb({ target: _this, event: event }); });
};
return NotyfNotification;
}());
var NotyfArrayEvent;
(function (NotyfArrayEvent) {
NotyfArrayEvent[NotyfArrayEvent["Add"] = 0] = "Add";
NotyfArrayEvent[NotyfArrayEvent["Remove"] = 1] = "Remove";
})(NotyfArrayEvent || (NotyfArrayEvent = {}));
var NotyfArray = /** @class */ (function () {
function NotyfArray() {
this.notifications = [];
}
NotyfArray.prototype.push = function (elem) {
this.notifications.push(elem);
this.updateFn(elem, NotyfArrayEvent.Add, this.notifications);
};
NotyfArray.prototype.splice = function (index, num) {
var elem = this.notifications.splice(index, num)[0];
this.updateFn(elem, NotyfArrayEvent.Remove, this.notifications);
return elem;
};
NotyfArray.prototype.indexOf = function (elem) {
return this.notifications.indexOf(elem);
};
NotyfArray.prototype.onUpdate = function (fn) {
this.updateFn = fn;
};
return NotyfArray;
}());
var NotyfEvent;
(function (NotyfEvent) {
NotyfEvent["Dismiss"] = "dismiss";
NotyfEvent["Click"] = "click";
})(NotyfEvent || (NotyfEvent = {}));
var DEFAULT_OPTIONS = {
types: [
{
type: 'success',
className: 'notyf__toast--success',
backgroundColor: '#3dc763',
icon: {
className: 'notyf__icon--success',
tagName: 'i',
},
},
{
type: 'error',
className: 'notyf__toast--error',
backgroundColor: '#ed3d3d',
icon: {
className: 'notyf__icon--error',
tagName: 'i',
},
},
],
duration: 2000,
ripple: true,
position: {
x: 'right',
y: 'bottom',
},
dismissible: false,
};
var NotyfView = /** @class */ (function () {
function NotyfView() {
this.notifications = [];
this.events = {};
this.X_POSITION_FLEX_MAP = {
left: 'flex-start',
center: 'center',
right: 'flex-end',
};
this.Y_POSITION_FLEX_MAP = {
top: 'flex-start',
center: 'center',
bottom: 'flex-end',
};
// Creates the main notifications container
var docFrag = document.createDocumentFragment();
var notyfContainer = this._createHTMLElement({ tagName: 'div', className: 'notyf' });
docFrag.appendChild(notyfContainer);
document.body.appendChild(docFrag);
this.container = notyfContainer;
// Identifies the main animation end event
this.animationEndEventName = this._getAnimationEndEventName();
this._createA11yContainer();
}
NotyfView.prototype.on = function (event, cb) {
var _a;
this.events = __assign(__assign({}, this.events), (_a = {}, _a[event] = cb, _a));
};
NotyfView.prototype.update = function (notification, type) {
if (type === NotyfArrayEvent.Add) {
this.addNotification(notification);
}
else if (type === NotyfArrayEvent.Remove) {
this.removeNotification(notification);
}
};
NotyfView.prototype.removeNotification = function (notification) {
var _this = this;
var renderedNotification = this._popRenderedNotification(notification);
var node;
if (!renderedNotification) {
return;
}
node = renderedNotification.node;
node.classList.add('notyf__toast--disappear');
var handleEvent;
node.addEventListener(this.animationEndEventName, (handleEvent = function (event) {
if (event.target === node) {
node.removeEventListener(_this.animationEndEventName, handleEvent);
_this.container.removeChild(node);
}
}));
};
NotyfView.prototype.addNotification = function (notification) {
var node = this._renderNotification(notification);
this.notifications.push({ notification: notification, node: node });
// For a11y purposes, we still want to announce that there's a notification in the screen
// even if it comes with no message.
this._announce(notification.options.message || 'Notification');
};
NotyfView.prototype._renderNotification = function (notification) {
var _a;
var card = this._buildNotificationCard(notification);
var className = notification.options.className;
if (className) {
(_a = card.classList).add.apply(_a, className.split(' '));
}
this.container.appendChild(card);
return card;
};
NotyfView.prototype._popRenderedNotification = function (notification) {
var idx = -1;
for (var i = 0; i < this.notifications.length && idx < 0; i++) {
if (this.notifications[i].notification === notification) {
idx = i;
}
}
if (idx !== -1) {
return this.notifications.splice(idx, 1)[0];
}
return;
};
NotyfView.prototype.getXPosition = function (options) {
var _a;
return ((_a = options === null || options === void 0 ? void 0 : options.position) === null || _a === void 0 ? void 0 : _a.x) || 'right';
};
NotyfView.prototype.getYPosition = function (options) {
var _a;
return ((_a = options === null || options === void 0 ? void 0 : options.position) === null || _a === void 0 ? void 0 : _a.y) || 'bottom';
};
NotyfView.prototype.adjustContainerAlignment = function (options) {
var align = this.X_POSITION_FLEX_MAP[this.getXPosition(options)];
var justify = this.Y_POSITION_FLEX_MAP[this.getYPosition(options)];
var style = this.container.style;
style.setProperty('justify-content', justify);
style.setProperty('align-items', align);
};
NotyfView.prototype._buildNotificationCard = function (notification) {
var _this = this;
var options = notification.options;
var iconOpts = options.icon;
// Adjust container according to position (e.g. top-left, bottom-center, etc)
this.adjustContainerAlignment(options);
// Create elements
var notificationElem = this._createHTMLElement({ tagName: 'div', className: 'notyf__toast' });
var ripple = this._createHTMLElement({ tagName: 'div', className: 'notyf__ripple' });
var wrapper = this._createHTMLElement({ tagName: 'div', className: 'notyf__wrapper' });
var message = this._createHTMLElement({ tagName: 'div', className: 'notyf__message' });
message.innerHTML = options.message || '';
var mainColor = options.background || options.backgroundColor;
// Build the icon and append it to the card
if (iconOpts) {
var iconContainer = this._createHTMLElement({ tagName: 'div', className: 'notyf__icon' });
if (typeof iconOpts === 'string' || iconOpts instanceof String)
iconContainer.innerHTML = new String(iconOpts).valueOf();
if (typeof iconOpts === 'object') {
var _a = iconOpts.tagName, tagName = _a === void 0 ? 'i' : _a, className_1 = iconOpts.className, text = iconOpts.text, _b = iconOpts.color, color = _b === void 0 ? mainColor : _b;
var iconElement = this._createHTMLElement({ tagName: tagName, className: className_1, text: text });
if (color)
iconElement.style.color = color;
iconContainer.appendChild(iconElement);
}
wrapper.appendChild(iconContainer);
}
wrapper.appendChild(message);
notificationElem.appendChild(wrapper);
// Add ripple if applicable, else just paint the full toast
if (mainColor) {
if (options.ripple) {
ripple.style.background = mainColor;
notificationElem.appendChild(ripple);
}
else {
notificationElem.style.background = mainColor;
}
}
// Add dismiss button
if (options.dismissible) {
var dismissWrapper = this._createHTMLElement({ tagName: 'div', className: 'notyf__dismiss' });
var dismissButton = this._createHTMLElement({
tagName: 'button',
className: 'notyf__dismiss-btn',
});
dismissWrapper.appendChild(dismissButton);
wrapper.appendChild(dismissWrapper);
notificationElem.classList.add("notyf__toast--dismissible");
dismissButton.addEventListener('click', function (event) {
var _a, _b;
(_b = (_a = _this.events)[NotyfEvent.Dismiss]) === null || _b === void 0 ? void 0 : _b.call(_a, { target: notification, event: event });
event.stopPropagation();
});
}
notificationElem.addEventListener('click', function (event) { var _a, _b; return (_b = (_a = _this.events)[NotyfEvent.Click]) === null || _b === void 0 ? void 0 : _b.call(_a, { target: notification, event: event }); });
// Adjust margins depending on whether its an upper or lower notification
var className = this.getYPosition(options) === 'top' ? 'upper' : 'lower';
notificationElem.classList.add("notyf__toast--" + className);
return notificationElem;
};
NotyfView.prototype._createHTMLElement = function (_a) {
var tagName = _a.tagName, className = _a.className, text = _a.text;
var elem = document.createElement(tagName);
if (className) {
elem.className = className;
}
elem.textContent = text || null;
return elem;
};
/**
* Creates an invisible container which will announce the notyfs to
* screen readers
*/
NotyfView.prototype._createA11yContainer = function () {
var a11yContainer = this._createHTMLElement({ tagName: 'div', className: 'notyf-announcer' });
a11yContainer.setAttribute('aria-atomic', 'true');
a11yContainer.setAttribute('aria-live', 'polite');
// Set the a11y container to be visible hidden. Can't use display: none as
// screen readers won't read it.
a11yContainer.style.border = '0';
a11yContainer.style.clip = 'rect(0 0 0 0)';
a11yContainer.style.height = '1px';
a11yContainer.style.margin = '-1px';
a11yContainer.style.overflow = 'hidden';
a11yContainer.style.padding = '0';
a11yContainer.style.position = 'absolute';
a11yContainer.style.width = '1px';
a11yContainer.style.outline = '0';
document.body.appendChild(a11yContainer);
this.a11yContainer = a11yContainer;
};
/**
* Announces a message to screenreaders.
*/
NotyfView.prototype._announce = function (message) {
var _this = this;
this.a11yContainer.textContent = '';
// This 100ms timeout is necessary for some browser + screen-reader combinations:
// - Both JAWS and NVDA over IE11 will not announce anything without a non-zero timeout.
// - With Chrome and IE11 with NVDA or JAWS, a repeated (identical) message won't be read a
// second time without clearing and then using a non-zero delay.
// (using JAWS 17 at time of this writing).
// https://github.com/angular/material2/blob/master/src/cdk/a11y/live-announcer/live-announcer.ts
setTimeout(function () {
_this.a11yContainer.textContent = message;
}, 100);
};
/**
* Determine which animationend event is supported
*/
NotyfView.prototype._getAnimationEndEventName = function () {
var el = document.createElement('_fake');
var transitions = {
MozTransition: 'animationend',
OTransition: 'oAnimationEnd',
WebkitTransition: 'webkitAnimationEnd',
transition: 'animationend',
};
var t;
for (t in transitions) {
if (el.style[t] !== undefined) {
return transitions[t];
}
}
// No supported animation end event. Using "animationend" as a fallback
return 'animationend';
};
return NotyfView;
}());
/**
* Main controller class. Defines the main Notyf API.
*/
var Notyf = /** @class */ (function () {
function Notyf(opts) {
var _this = this;
this.dismiss = this._removeNotification;
this.notifications = new NotyfArray();
this.view = new NotyfView();
var types = this.registerTypes(opts);
this.options = __assign(__assign({}, DEFAULT_OPTIONS), opts);
this.options.types = types;
this.notifications.onUpdate(function (elem, type) { return _this.view.update(elem, type); });
this.view.on(NotyfEvent.Dismiss, function (_a) {
var target = _a.target, event = _a.event;
_this._removeNotification(target);
// tslint:disable-next-line: no-string-literal
target['triggerEvent'](NotyfEvent.Dismiss, event);
});
// tslint:disable-next-line: no-string-literal
this.view.on(NotyfEvent.Click, function (_a) {
var target = _a.target, event = _a.event;
return target['triggerEvent'](NotyfEvent.Click, event);
});
}
Notyf.prototype.error = function (payload) {
var options = this.normalizeOptions('error', payload);
return this.open(options);
};
Notyf.prototype.success = function (payload) {
var options = this.normalizeOptions('success', payload);
return this.open(options);
};
Notyf.prototype.open = function (options) {
var defaultOpts = this.options.types.find(function (_a) {
var type = _a.type;
return type === options.type;
}) || {};
var config = __assign(__assign({}, defaultOpts), options);
this.assignProps(['ripple', 'position', 'dismissible'], config);
var notification = new NotyfNotification(config);
this._pushNotification(notification);
return notification;
};
Notyf.prototype.dismissAll = function () {
while (this.notifications.splice(0, 1))
;
};
/**
* Assigns properties to a config object based on two rules:
* 1. If the config object already sets that prop, leave it as so
* 2. Otherwise, use the default prop from the global options
*
* It's intended to build the final config object to open a notification. e.g. if
* 'dismissible' is not set, then use the value from the global config.
*
* @param props - properties to be assigned to the config object
* @param config - object whose properties need to be set
*/
Notyf.prototype.assignProps = function (props, config) {
var _this = this;
props.forEach(function (prop) {
// intentional double equality to check for both null and undefined
config[prop] = config[prop] == null ? _this.options[prop] : config[prop];
});
};
Notyf.prototype._pushNotification = function (notification) {
var _this = this;
this.notifications.push(notification);
var duration = notification.options.duration !== undefined ? notification.options.duration : this.options.duration;
if (duration) {
setTimeout(function () { return _this._removeNotification(notification); }, duration);
}
};
Notyf.prototype._removeNotification = function (notification) {
var index = this.notifications.indexOf(notification);
if (index !== -1) {
this.notifications.splice(index, 1);
}
};
Notyf.prototype.normalizeOptions = function (type, payload) {
var options = { type: type };
if (typeof payload === 'string') {
options.message = payload;
}
else if (typeof payload === 'object') {
options = __assign(__assign({}, options), payload);
}
return options;
};
Notyf.prototype.registerTypes = function (opts) {
var incomingTypes = ((opts && opts.types) || []).slice();
var finalDefaultTypes = DEFAULT_OPTIONS.types.map(function (defaultType) {
// find if there's a default type within the user input's types, if so, it means the user
// wants to change some of the default settings
var userTypeIdx = -1;
incomingTypes.forEach(function (t, idx) {
if (t.type === defaultType.type)
userTypeIdx = idx;
});
var userType = userTypeIdx !== -1 ? incomingTypes.splice(userTypeIdx, 1)[0] : {};
return __assign(__assign({}, defaultType), userType);
});
return finalDefaultTypes.concat(incomingTypes);
};
return Notyf;
}());
return Notyf;
})));

View File

@@ -0,0 +1 @@
.noUi-target,.noUi-target *{-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;-ms-touch-action:none;touch-action:none;-ms-user-select:none;-moz-user-select:none;user-select:none;-moz-box-sizing:border-box;box-sizing:border-box}.noUi-target{position:relative}.noUi-base,.noUi-connects{width:100%;height:100%;position:relative;z-index:1}.noUi-connects{overflow:hidden;z-index:0}.noUi-connect,.noUi-origin{will-change:transform;position:absolute;z-index:1;top:0;right:0;-ms-transform-origin:0 0;-webkit-transform-origin:0 0;-webkit-transform-style:preserve-3d;transform-origin:0 0;transform-style:flat}.noUi-connect{height:100%;width:100%}.noUi-origin{height:10%;width:10%}.noUi-txt-dir-rtl.noUi-horizontal .noUi-origin{left:0;right:auto}.noUi-vertical .noUi-origin{width:0}.noUi-horizontal .noUi-origin{height:0}.noUi-handle{-webkit-backface-visibility:hidden;backface-visibility:hidden;position:absolute}.noUi-touch-area{height:100%;width:100%}.noUi-state-tap .noUi-connect,.noUi-state-tap .noUi-origin{-webkit-transition:transform .3s;transition:transform .3s}.noUi-state-drag *{cursor:inherit!important}.noUi-horizontal{height:18px}.noUi-horizontal .noUi-handle{width:34px;height:28px;right:-17px;top:-6px}.noUi-vertical{width:18px}.noUi-vertical .noUi-handle{width:28px;height:34px;right:-6px;top:-17px}.noUi-txt-dir-rtl.noUi-horizontal .noUi-handle{left:-17px;right:auto}.noUi-target{background:#FAFAFA;border-radius:4px;border:1px solid #D3D3D3;box-shadow:inset 0 1px 1px #F0F0F0,0 3px 6px -5px #BBB}.noUi-connects{border-radius:3px}.noUi-connect{background:#3FB8AF}.noUi-draggable{cursor:ew-resize}.noUi-vertical .noUi-draggable{cursor:ns-resize}.noUi-handle{border:1px solid #D9D9D9;border-radius:3px;background:#FFF;cursor:default;box-shadow:inset 0 0 1px #FFF,inset 0 1px 7px #EBEBEB,0 3px 6px -3px #BBB}.noUi-active{box-shadow:inset 0 0 1px #FFF,inset 0 1px 7px #DDD,0 3px 6px -3px #BBB}.noUi-handle:after,.noUi-handle:before{content:"";display:block;position:absolute;height:14px;width:1px;background:#E8E7E6;left:14px;top:6px}.noUi-handle:after{left:17px}.noUi-vertical .noUi-handle:after,.noUi-vertical .noUi-handle:before{width:14px;height:1px;left:6px;top:14px}.noUi-vertical .noUi-handle:after{top:17px}[disabled] .noUi-connect{background:#B8B8B8}[disabled] .noUi-handle,[disabled].noUi-handle,[disabled].noUi-target{cursor:not-allowed}.noUi-pips,.noUi-pips *{-moz-box-sizing:border-box;box-sizing:border-box}.noUi-pips{position:absolute;color:#999}.noUi-value{position:absolute;white-space:nowrap;text-align:center}.noUi-value-sub{color:#ccc;font-size:10px}.noUi-marker{position:absolute;background:#CCC}.noUi-marker-sub{background:#AAA}.noUi-marker-large{background:#AAA}.noUi-pips-horizontal{padding:10px 0;height:80px;top:100%;left:0;width:100%}.noUi-value-horizontal{-webkit-transform:translate(-50%,50%);transform:translate(-50%,50%)}.noUi-rtl .noUi-value-horizontal{-webkit-transform:translate(50%,50%);transform:translate(50%,50%)}.noUi-marker-horizontal.noUi-marker{margin-left:-1px;width:2px;height:5px}.noUi-marker-horizontal.noUi-marker-sub{height:10px}.noUi-marker-horizontal.noUi-marker-large{height:15px}.noUi-pips-vertical{padding:0 10px;height:100%;top:0;left:100%}.noUi-value-vertical{-webkit-transform:translate(0,-50%);transform:translate(0,-50%);padding-left:25px}.noUi-rtl .noUi-value-vertical{-webkit-transform:translate(0,50%);transform:translate(0,50%)}.noUi-marker-vertical.noUi-marker{width:5px;height:2px;margin-top:-1px}.noUi-marker-vertical.noUi-marker-sub{width:10px}.noUi-marker-vertical.noUi-marker-large{width:15px}.noUi-tooltip{display:block;position:absolute;border:1px solid #D9D9D9;border-radius:3px;background:#fff;color:#000;padding:5px;text-align:center;white-space:nowrap}.noUi-horizontal .noUi-tooltip{-webkit-transform:translate(-50%,0);transform:translate(-50%,0);left:50%;bottom:120%}.noUi-vertical .noUi-tooltip{-webkit-transform:translate(0,-50%);transform:translate(0,-50%);top:50%;right:120%}.noUi-horizontal .noUi-origin>.noUi-tooltip{-webkit-transform:translate(50%,0);transform:translate(50%,0);left:auto;bottom:10px}.noUi-vertical .noUi-origin>.noUi-tooltip{-webkit-transform:translate(0,-18px);transform:translate(0,-18px);top:auto;right:28px}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"Omyb":[function(require,module,exports) {
"use strict";function e(e,t){var r=window.MutationObserver;if(r){var n=new r(t);return n.observe(e,{childList:!0,subtree:!0}),n}return e.addEventListener("DOMNodeInserted",t,!1),e.addEventListener("DOMNodeRemoved",t,!1),null}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=e;
},{}],"A8OV":[function(require,module,exports) {
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("../helpers/observe-dom"));function s(){var e=this,s=this.options.container;s instanceof HTMLElement&&("static"===window.getComputedStyle(s).position&&(s.style.position="relative"));this._observer=t.default(document.querySelector("body"),function(){Object.keys(e.trackedElements).forEach(function(t){e.on("enter",t),e.on("leave",t)})}),s.addEventListener("scroll",this._scroll,{passive:!0}),window.addEventListener("resize",this._scroll,{passive:!0}),this._scroll(),this.attached=!0}exports.default=s;
},{"../helpers/observe-dom":"Omyb"}],"OJn0":[function(require,module,exports) {
"use strict";function e(e,t){if(!e)throw new Error("You should specify the element you want to test");"string"==typeof e&&(e=document.querySelector(e));var n=e.getBoundingClientRect();return n.bottom-t.tolerance>0&&n.right-t.tolerance>0&&n.left+t.tolerance<(window.innerWidth||document.documentElement.clientWidth)&&n.top+t.tolerance<(window.innerHeight||document.documentElement.clientHeight)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=e;
},{}],"m6QN":[function(require,module,exports) {
"use strict";function e(e,t){if(!e)throw new Error("You should specify the element you want to test");if("string"==typeof e&&(e=document.querySelector(e)),"string"==typeof t&&(t={tolerance:0,container:document.querySelector(t)}),"string"==typeof t.container&&(t.container=document.querySelector(t.container)),t instanceof HTMLElement&&(t={tolerance:0,container:t}),!t.container)throw new Error("You should specify a container element");var o=t.container.getBoundingClientRect();return e.offsetTop+e.clientHeight-t.tolerance>t.container.scrollTop&&e.offsetLeft+e.clientWidth-t.tolerance>t.container.scrollLeft&&e.offsetLeft+t.tolerance<o.width+t.container.scrollLeft&&e.offsetTop+t.tolerance<o.height+t.container.scrollTop}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=e;
},{}],"VqMh":[function(require,module,exports) {
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var i=e(require("./in-viewport")),n=e(require("./in-container"));function t(e,t){void 0===e&&(e={}),void 0===t&&(t={container:window,tolerance:0});var o,r=Object.keys(e);r.length&&(o=t.container===window?i.default:n.default,r.forEach(function(i){e[i].nodes.forEach(function(n){if(o(n.node,t)?(n.wasVisible=n.isVisible,n.isVisible=!0):(n.wasVisible=n.isVisible,n.isVisible=!1),!0===n.isVisible&&!1===n.wasVisible){if(!e[i].enter)return;Object.keys(e[i].enter).forEach(function(t){"function"==typeof e[i].enter[t]&&e[i].enter[t](n.node,"enter")})}if(!1===n.isVisible&&!0===n.wasVisible){if(!e[i].leave)return;Object.keys(e[i].leave).forEach(function(t){"function"==typeof e[i].leave[t]&&e[i].leave[t](n.node,"leave")})}})}))}exports.default=t;
},{"./in-viewport":"OJn0","./in-container":"m6QN"}],"GRp5":[function(require,module,exports) {
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("../helpers/scroll-handler"));function r(){var e,r=this;return function(){clearTimeout(e),e=setTimeout(function(){t.default(r.trackedElements,r.options)},r.options.debounce)}}exports.default=r;
},{"../helpers/scroll-handler":"VqMh"}],"FO0g":[function(require,module,exports) {
"use strict";function e(){this._observer instanceof MutationObserver&&this._observer.disconnect(),this.options.container.removeEventListener("scroll",this._scroll),window.removeEventListener("resize",this._scroll),this.attached=!1}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=e;
},{}],"nGOL":[function(require,module,exports) {
"use strict";function e(e,t,s){var l=Object.keys(this.trackedElements[t].enter||{}),n=Object.keys(this.trackedElements[t].leave||{});if({}.hasOwnProperty.call(this.trackedElements,t))if(s){if(this.trackedElements[t][e]){var r="function"==typeof s?s.name:s;delete this.trackedElements[t][e][r]}}else delete this.trackedElements[t][e];l.length||n.length||delete this.trackedElements[t]}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=e;
},{}],"NKIH":[function(require,module,exports) {
"use strict";function e(e,t,r){if(!e)throw new Error("No event given. Choose either enter or leave");if(!t)throw new Error("No selector to track");if(["enter","leave"].indexOf(e)<0)throw new Error(e+" event is not supported");({}).hasOwnProperty.call(this.trackedElements,t)||(this.trackedElements[t]={}),this.trackedElements[t].nodes=[];for(var s=0,n=document.querySelectorAll(t);s<n.length;s++){var o={isVisible:!1,wasVisible:!1,node:n[s]};this.trackedElements[t].nodes.push(o)}"function"==typeof r&&(this.trackedElements[t][e]||(this.trackedElements[t][e]={}),this.trackedElements[t][e][r.name||"anonymous"]=r)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=e;
},{}],"QCba":[function(require,module,exports) {
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("./methods/attach")),r=e(require("./methods/debounced-scroll")),n=e(require("./methods/destroy")),o=e(require("./methods/off")),i=e(require("./methods/on")),u=e(require("./helpers/in-viewport"));function a(e){void 0===e&&(e={tolerance:0,debounce:100,container:window}),this.options={},this.trackedElements={},Object.defineProperties(this.options,{container:{configurable:!1,enumerable:!1,get:function(){var t;return"string"==typeof e.container?t=document.querySelector(e.container):e.container instanceof HTMLElement&&(t=e.container),t||window},set:function(t){e.container=t}},debounce:{get:function(){return e.debounce||100},set:function(t){e.debounce=t}},tolerance:{get:function(){return e.tolerance||0},set:function(t){e.tolerance=t}}}),Object.defineProperty(this,"_scroll",{enumerable:!1,configurable:!1,writable:!1,value:this._debouncedScroll.call(this)}),this.attach()}Object.defineProperties(a.prototype,{_debouncedScroll:{configurable:!1,writable:!1,enumerable:!1,value:r.default},attach:{configurable:!1,writable:!1,enumerable:!1,value:t.default},destroy:{configurable:!1,writable:!1,enumerable:!1,value:n.default},off:{configurable:!1,writable:!1,enumerable:!1,value:o.default},on:{configurable:!1,writable:!1,enumerable:!1,value:i.default}}),a.check=u.default,exports.default=a;
},{"./methods/attach":"A8OV","./methods/debounced-scroll":"GRp5","./methods/destroy":"FO0g","./methods/off":"nGOL","./methods/on":"NKIH","./helpers/in-viewport":"OJn0"}]},{},["QCba"], null)

View File

@@ -0,0 +1,404 @@
/**
* Observes DOM mutations and runs a callback function when
* detecting one.
*
* @param {node} obj The DOM node you want to observe
* @param {function} callback The callback function you want to call
* @return {MutationObserver} obs The mutation observer instance used to track DOM mutations
*/
function observeDOM(obj, callback) {
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
/* istanbul ignore else */
if (MutationObserver) {
var obs = new MutationObserver(callback);
obs.observe(obj, {
childList: true,
subtree: true
});
return obs;
}
obj.addEventListener('DOMNodeInserted', callback, false);
obj.addEventListener('DOMNodeRemoved', callback, false);
return null;
}
/**
* Attaches the scroll event handler
*
* @return {void}
*/
function attach() {
var _this = this;
var container = this.options.container;
if (container instanceof HTMLElement) {
var style = window.getComputedStyle(container);
if (style.position === 'static') {
container.style.position = 'relative';
}
}
this._observer = observeDOM(document.querySelector('body'), function () {
Object.keys(_this.trackedElements).forEach(function (element) {
_this.on('enter', element);
_this.on('leave', element);
});
});
container.addEventListener('scroll', this._scroll, { passive: true });
window.addEventListener('resize', this._scroll, { passive: true });
this._scroll();
this.attached = true;
}
/**
* Checks an element's position in respect to the viewport
* and determines wether it's inside the viewport.
*
* @param {node} element The DOM node you want to check
* @return {boolean} A boolean value that indicates wether is on or off the viewport.
*/
function inViewport(el) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { tolerance: 0 };
if (!el) {
throw new Error('You should specify the element you want to test');
}
if (typeof el === 'string') {
el = document.querySelector(el);
}
var elRect = el.getBoundingClientRect();
return (
// Check bottom boundary
elRect.bottom - options.tolerance > 0 &&
// Check right boundary
elRect.right - options.tolerance > 0 &&
// Check left boundary
elRect.left + options.tolerance < (window.innerWidth || document.documentElement.clientWidth) &&
// Check top boundary
elRect.top + options.tolerance < (window.innerHeight || document.documentElement.clientHeight)
);
}
/**
* Checks an element's position in respect to a HTMLElement
* and determines wether it's within its boundaries.
*
* @param {node} element The DOM node you want to check
* @return {boolean} A boolean value that indicates wether is on or off the container.
*/
function inContainer(el) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { tolerance: 0, container: '' };
if (!el) {
throw new Error('You should specify the element you want to test');
}
if (typeof el === 'string') {
el = document.querySelector(el);
}
if (typeof options === 'string') {
options = {
tolerance: 0,
container: document.querySelector(options)
};
}
if (typeof options.container === 'string') {
options.container = document.querySelector(options.container);
}
if (options instanceof HTMLElement) {
options = {
tolerance: 0,
container: options
};
}
if (!options.container) {
throw new Error('You should specify a container element');
}
var containerRect = options.container.getBoundingClientRect();
return (
// // Check bottom boundary
el.offsetTop + el.clientHeight - options.tolerance > options.container.scrollTop &&
// Check right boundary
el.offsetLeft + el.clientWidth - options.tolerance > options.container.scrollLeft &&
// Check left boundary
el.offsetLeft + options.tolerance < containerRect.width + options.container.scrollLeft &&
// // Check top boundary
el.offsetTop + options.tolerance < containerRect.height + options.container.scrollTop
);
}
// TODO: Refactor this so it can be easily tested
/* istanbul ignore next */
function eventHandler() {
var trackedElements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { tolerance: 0 };
var selectors = Object.keys(trackedElements);
var testVisibility = void 0;
if (!selectors.length) return;
if (options.container === window) {
testVisibility = inViewport;
} else {
testVisibility = inContainer;
}
selectors.forEach(function (selector) {
trackedElements[selector].nodes.forEach(function (item) {
if (testVisibility(item.node, options)) {
item.wasVisible = item.isVisible;
item.isVisible = true;
} else {
item.wasVisible = item.isVisible;
item.isVisible = false;
}
if (item.isVisible === true && item.wasVisible === false) {
if (!trackedElements[selector].enter) return;
Object.keys(trackedElements[selector].enter).forEach(function (callback) {
if (typeof trackedElements[selector].enter[callback] === 'function') {
trackedElements[selector].enter[callback](item.node, 'enter');
}
});
}
if (item.isVisible === false && item.wasVisible === true) {
if (!trackedElements[selector].leave) return;
Object.keys(trackedElements[selector].leave).forEach(function (callback) {
if (typeof trackedElements[selector].leave[callback] === 'function') {
trackedElements[selector].leave[callback](item.node, 'leave');
}
});
}
});
});
}
/**
* Debounces the scroll event to avoid performance issues
*
* @return {void}
*/
function debouncedScroll() {
var _this = this;
var timeout = void 0;
if (this.options.debounce === false) {
return function () {
return eventHandler(_this.trackedElements, _this.options);
};
}
return function () {
clearTimeout(timeout);
timeout = setTimeout(function () {
eventHandler(_this.trackedElements, _this.options);
}, _this.options.debounce);
};
}
/**
* Removes the scroll event handler
*
* @return {void}
*/
function destroy() {
if (this._observer instanceof MutationObserver) {
this._observer.disconnect();
}
this.options.container.removeEventListener('scroll', this._scroll);
window.removeEventListener('resize', this._scroll);
this.attached = false;
}
/**
* Stops tracking elements matching a CSS selector. If a selector has no
* callbacks it gets removed.
*
* @param {string} event The event you want to stop tracking (enter or leave)
* @param {string} selector The CSS selector you want to stop tracking
* @return {void}
*/
function off(event, selector, handler) {
var enterCallbacks = Object.keys(this.trackedElements[selector].enter || {});
var leaveCallbacks = Object.keys(this.trackedElements[selector].leave || {});
if ({}.hasOwnProperty.call(this.trackedElements, selector)) {
if (handler) {
if (this.trackedElements[selector][event]) {
var callbackName = typeof handler === 'function' ? handler.name : handler;
delete this.trackedElements[selector][event][callbackName];
}
} else {
delete this.trackedElements[selector][event];
}
}
if (!enterCallbacks.length && !leaveCallbacks.length) {
delete this.trackedElements[selector];
}
}
/**
* Starts tracking elements matching a CSS selector
*
* @param {string} event The event you want to track (enter or leave)
* @param {string} selector The element you want to track
* @param {function} callback The callback function to handle the event
* @return {void}
*/
function on(event, selector, callback) {
var allowed = ['enter', 'leave'];
if (!event) throw new Error('No event given. Choose either enter or leave');
if (!selector) throw new Error('No selector to track');
if (allowed.indexOf(event) < 0) throw new Error(event + ' event is not supported');
if (!{}.hasOwnProperty.call(this.trackedElements, selector)) {
this.trackedElements[selector] = {};
}
this.trackedElements[selector].nodes = [];
for (var i = 0, elems = document.querySelectorAll(selector); i < elems.length; i++) {
var item = {
isVisible: false,
wasVisible: false,
node: elems[i]
};
this.trackedElements[selector].nodes.push(item);
}
if (typeof callback === 'function') {
if (!this.trackedElements[selector][event]) {
this.trackedElements[selector][event] = {};
}
this.trackedElements[selector][event][callback.name || 'anonymous'] = callback;
}
}
/**
* Detects wether DOM nodes enter or leave the viewport
*
* @constructor
* @param {object} options The configuration object
*/
function OnScreen() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { tolerance: 0, debounce: 100, container: window };
this.options = {};
this.trackedElements = {};
Object.defineProperties(this.options, {
container: {
configurable: false,
enumerable: false,
get: function get() {
var container = void 0;
if (typeof options.container === 'string') {
container = document.querySelector(options.container);
} else if (options.container instanceof HTMLElement) {
container = options.container;
}
return container || window;
},
set: function set(value) {
options.container = value;
}
},
debounce: {
get: function get() {
if (options.debounce === false) {
return false;
}
return parseInt(options.debounce, 10) || 100;
},
set: function set(value) {
options.debounce = value;
}
},
tolerance: {
get: function get() {
return parseInt(options.tolerance, 10) || 0;
},
set: function set(value) {
options.tolerance = value;
}
}
});
Object.defineProperty(this, '_scroll', {
enumerable: false,
configurable: false,
writable: false,
value: this._debouncedScroll.call(this)
});
this.attach();
}
Object.defineProperties(OnScreen.prototype, {
_debouncedScroll: {
configurable: false,
writable: false,
enumerable: false,
value: debouncedScroll
},
attach: {
configurable: false,
writable: false,
enumerable: false,
value: attach
},
destroy: {
configurable: false,
writable: false,
enumerable: false,
value: destroy
},
off: {
configurable: false,
writable: false,
enumerable: false,
value: off
},
on: {
configurable: false,
writable: false,
enumerable: false,
value: on
}
});
OnScreen.check = inViewport;
export default OnScreen;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,889 @@
/**
* SimpleBar.js - v5.3.5
* Scrollbars, simpler.
* https://grsmto.github.io/simplebar/
*
* Made by Adrien Denat from a fork by Jonathan Nicol
* Under MIT License
*/
import 'core-js/modules/es.array.filter';
import 'core-js/modules/es.array.for-each';
import 'core-js/modules/es.array.iterator';
import 'core-js/modules/es.object.assign';
import 'core-js/modules/es.object.to-string';
import 'core-js/modules/es.parse-int';
import 'core-js/modules/es.string.iterator';
import 'core-js/modules/es.weak-map';
import 'core-js/modules/web.dom-collections.iterator';
import throttle from 'lodash.throttle';
import debounce from 'lodash.debounce';
import memoize from 'lodash.memoize';
import { ResizeObserver } from '@juggle/resize-observer';
import canUseDOM from 'can-use-dom';
import 'core-js/modules/es.array.reduce';
import 'core-js/modules/es.function.name';
import 'core-js/modules/es.regexp.exec';
import 'core-js/modules/es.string.match';
import 'core-js/modules/es.string.replace';
function getElementWindow(element) {
if (!element || !element.ownerDocument || !element.ownerDocument.defaultView) {
return window;
}
return element.ownerDocument.defaultView;
}
function getElementDocument(element) {
if (!element || !element.ownerDocument) {
return document;
}
return element.ownerDocument;
}
var cachedScrollbarWidth = null;
var cachedDevicePixelRatio = null;
if (canUseDOM) {
window.addEventListener('resize', function () {
if (cachedDevicePixelRatio !== window.devicePixelRatio) {
cachedDevicePixelRatio = window.devicePixelRatio;
cachedScrollbarWidth = null;
}
});
}
function scrollbarWidth(el) {
if (cachedScrollbarWidth === null) {
var document = getElementDocument(el);
if (typeof document === 'undefined') {
cachedScrollbarWidth = 0;
return cachedScrollbarWidth;
}
var body = document.body;
var box = document.createElement('div');
box.classList.add('simplebar-hide-scrollbar');
body.appendChild(box);
var width = box.getBoundingClientRect().right;
body.removeChild(box);
cachedScrollbarWidth = width;
}
return cachedScrollbarWidth;
}
var SimpleBar =
/*#__PURE__*/
function () {
function SimpleBar(element, options) {
var _this = this;
this.onScroll = function () {
var elWindow = getElementWindow(_this.el);
if (!_this.scrollXTicking) {
elWindow.requestAnimationFrame(_this.scrollX);
_this.scrollXTicking = true;
}
if (!_this.scrollYTicking) {
elWindow.requestAnimationFrame(_this.scrollY);
_this.scrollYTicking = true;
}
};
this.scrollX = function () {
if (_this.axis.x.isOverflowing) {
_this.showScrollbar('x');
_this.positionScrollbar('x');
}
_this.scrollXTicking = false;
};
this.scrollY = function () {
if (_this.axis.y.isOverflowing) {
_this.showScrollbar('y');
_this.positionScrollbar('y');
}
_this.scrollYTicking = false;
};
this.onMouseEnter = function () {
_this.showScrollbar('x');
_this.showScrollbar('y');
};
this.onMouseMove = function (e) {
_this.mouseX = e.clientX;
_this.mouseY = e.clientY;
if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
_this.onMouseMoveForAxis('x');
}
if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
_this.onMouseMoveForAxis('y');
}
};
this.onMouseLeave = function () {
_this.onMouseMove.cancel();
if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
_this.onMouseLeaveForAxis('x');
}
if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
_this.onMouseLeaveForAxis('y');
}
_this.mouseX = -1;
_this.mouseY = -1;
};
this.onWindowResize = function () {
// Recalculate scrollbarWidth in case it's a zoom
_this.scrollbarWidth = _this.getScrollbarWidth();
_this.hideNativeScrollbar();
};
this.hideScrollbars = function () {
_this.axis.x.track.rect = _this.axis.x.track.el.getBoundingClientRect();
_this.axis.y.track.rect = _this.axis.y.track.el.getBoundingClientRect();
if (!_this.isWithinBounds(_this.axis.y.track.rect)) {
_this.axis.y.scrollbar.el.classList.remove(_this.classNames.visible);
_this.axis.y.isVisible = false;
}
if (!_this.isWithinBounds(_this.axis.x.track.rect)) {
_this.axis.x.scrollbar.el.classList.remove(_this.classNames.visible);
_this.axis.x.isVisible = false;
}
};
this.onPointerEvent = function (e) {
var isWithinTrackXBounds, isWithinTrackYBounds;
_this.axis.x.track.rect = _this.axis.x.track.el.getBoundingClientRect();
_this.axis.y.track.rect = _this.axis.y.track.el.getBoundingClientRect();
if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
isWithinTrackXBounds = _this.isWithinBounds(_this.axis.x.track.rect);
}
if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
isWithinTrackYBounds = _this.isWithinBounds(_this.axis.y.track.rect);
} // If any pointer event is called on the scrollbar
if (isWithinTrackXBounds || isWithinTrackYBounds) {
// Preventing the event's default action stops text being
// selectable during the drag.
e.preventDefault(); // Prevent event leaking
e.stopPropagation();
if (e.type === 'mousedown') {
if (isWithinTrackXBounds) {
_this.axis.x.scrollbar.rect = _this.axis.x.scrollbar.el.getBoundingClientRect();
if (_this.isWithinBounds(_this.axis.x.scrollbar.rect)) {
_this.onDragStart(e, 'x');
} else {
_this.onTrackClick(e, 'x');
}
}
if (isWithinTrackYBounds) {
_this.axis.y.scrollbar.rect = _this.axis.y.scrollbar.el.getBoundingClientRect();
if (_this.isWithinBounds(_this.axis.y.scrollbar.rect)) {
_this.onDragStart(e, 'y');
} else {
_this.onTrackClick(e, 'y');
}
}
}
}
};
this.drag = function (e) {
var eventOffset;
var track = _this.axis[_this.draggedAxis].track;
var trackSize = track.rect[_this.axis[_this.draggedAxis].sizeAttr];
var scrollbar = _this.axis[_this.draggedAxis].scrollbar;
var contentSize = _this.contentWrapperEl[_this.axis[_this.draggedAxis].scrollSizeAttr];
var hostSize = parseInt(_this.elStyles[_this.axis[_this.draggedAxis].sizeAttr], 10);
e.preventDefault();
e.stopPropagation();
if (_this.draggedAxis === 'y') {
eventOffset = e.pageY;
} else {
eventOffset = e.pageX;
} // Calculate how far the user's mouse is from the top/left of the scrollbar (minus the dragOffset).
var dragPos = eventOffset - track.rect[_this.axis[_this.draggedAxis].offsetAttr] - _this.axis[_this.draggedAxis].dragOffset; // Convert the mouse position into a percentage of the scrollbar height/width.
var dragPerc = dragPos / (trackSize - scrollbar.size); // Scroll the content by the same percentage.
var scrollPos = dragPerc * (contentSize - hostSize); // Fix browsers inconsistency on RTL
if (_this.draggedAxis === 'x') {
scrollPos = _this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? scrollPos - (trackSize + scrollbar.size) : scrollPos;
scrollPos = _this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollPos : scrollPos;
}
_this.contentWrapperEl[_this.axis[_this.draggedAxis].scrollOffsetAttr] = scrollPos;
};
this.onEndDrag = function (e) {
var elDocument = getElementDocument(_this.el);
var elWindow = getElementWindow(_this.el);
e.preventDefault();
e.stopPropagation();
_this.el.classList.remove(_this.classNames.dragging);
elDocument.removeEventListener('mousemove', _this.drag, true);
elDocument.removeEventListener('mouseup', _this.onEndDrag, true);
_this.removePreventClickId = elWindow.setTimeout(function () {
// Remove these asynchronously so we still suppress click events
// generated simultaneously with mouseup.
elDocument.removeEventListener('click', _this.preventClick, true);
elDocument.removeEventListener('dblclick', _this.preventClick, true);
_this.removePreventClickId = null;
});
};
this.preventClick = function (e) {
e.preventDefault();
e.stopPropagation();
};
this.el = element;
this.minScrollbarWidth = 20;
this.options = Object.assign({}, SimpleBar.defaultOptions, {}, options);
this.classNames = Object.assign({}, SimpleBar.defaultOptions.classNames, {}, this.options.classNames);
this.axis = {
x: {
scrollOffsetAttr: 'scrollLeft',
sizeAttr: 'width',
scrollSizeAttr: 'scrollWidth',
offsetSizeAttr: 'offsetWidth',
offsetAttr: 'left',
overflowAttr: 'overflowX',
dragOffset: 0,
isOverflowing: true,
isVisible: false,
forceVisible: false,
track: {},
scrollbar: {}
},
y: {
scrollOffsetAttr: 'scrollTop',
sizeAttr: 'height',
scrollSizeAttr: 'scrollHeight',
offsetSizeAttr: 'offsetHeight',
offsetAttr: 'top',
overflowAttr: 'overflowY',
dragOffset: 0,
isOverflowing: true,
isVisible: false,
forceVisible: false,
track: {},
scrollbar: {}
}
};
this.removePreventClickId = null; // Don't re-instantiate over an existing one
if (SimpleBar.instances.has(this.el)) {
return;
}
this.recalculate = throttle(this.recalculate.bind(this), 64);
this.onMouseMove = throttle(this.onMouseMove.bind(this), 64);
this.hideScrollbars = debounce(this.hideScrollbars.bind(this), this.options.timeout);
this.onWindowResize = debounce(this.onWindowResize.bind(this), 64, {
leading: true
});
SimpleBar.getRtlHelpers = memoize(SimpleBar.getRtlHelpers);
this.init();
}
/**
* Static properties
*/
/**
* Helper to fix browsers inconsistency on RTL:
* - Firefox inverts the scrollbar initial position
* - IE11 inverts both scrollbar position and scrolling offset
* Directly inspired by @KingSora's OverlayScrollbars https://github.com/KingSora/OverlayScrollbars/blob/master/js/OverlayScrollbars.js#L1634
*/
SimpleBar.getRtlHelpers = function getRtlHelpers() {
var dummyDiv = document.createElement('div');
dummyDiv.innerHTML = '<div class="hs-dummy-scrollbar-size"><div style="height: 200%; width: 200%; margin: 10px 0;"></div></div>';
var scrollbarDummyEl = dummyDiv.firstElementChild;
document.body.appendChild(scrollbarDummyEl);
var dummyContainerChild = scrollbarDummyEl.firstElementChild;
scrollbarDummyEl.scrollLeft = 0;
var dummyContainerOffset = SimpleBar.getOffset(scrollbarDummyEl);
var dummyContainerChildOffset = SimpleBar.getOffset(dummyContainerChild);
scrollbarDummyEl.scrollLeft = 999;
var dummyContainerScrollOffsetAfterScroll = SimpleBar.getOffset(dummyContainerChild);
return {
// determines if the scrolling is responding with negative values
isRtlScrollingInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left && dummyContainerChildOffset.left - dummyContainerScrollOffsetAfterScroll.left !== 0,
// determines if the origin scrollbar position is inverted or not (positioned on left or right)
isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
};
};
SimpleBar.getOffset = function getOffset(el) {
var rect = el.getBoundingClientRect();
var elDocument = getElementDocument(el);
var elWindow = getElementWindow(el);
return {
top: rect.top + (elWindow.pageYOffset || elDocument.documentElement.scrollTop),
left: rect.left + (elWindow.pageXOffset || elDocument.documentElement.scrollLeft)
};
};
var _proto = SimpleBar.prototype;
_proto.init = function init() {
// Save a reference to the instance, so we know this DOM node has already been instancied
SimpleBar.instances.set(this.el, this); // We stop here on server-side
if (canUseDOM) {
this.initDOM();
this.scrollbarWidth = this.getScrollbarWidth();
this.recalculate();
this.initListeners();
}
};
_proto.initDOM = function initDOM() {
var _this2 = this;
// make sure this element doesn't have the elements yet
if (Array.prototype.filter.call(this.el.children, function (child) {
return child.classList.contains(_this2.classNames.wrapper);
}).length) {
// assume that element has his DOM already initiated
this.wrapperEl = this.el.querySelector("." + this.classNames.wrapper);
this.contentWrapperEl = this.options.scrollableNode || this.el.querySelector("." + this.classNames.contentWrapper);
this.contentEl = this.options.contentNode || this.el.querySelector("." + this.classNames.contentEl);
this.offsetEl = this.el.querySelector("." + this.classNames.offset);
this.maskEl = this.el.querySelector("." + this.classNames.mask);
this.placeholderEl = this.findChild(this.wrapperEl, "." + this.classNames.placeholder);
this.heightAutoObserverWrapperEl = this.el.querySelector("." + this.classNames.heightAutoObserverWrapperEl);
this.heightAutoObserverEl = this.el.querySelector("." + this.classNames.heightAutoObserverEl);
this.axis.x.track.el = this.findChild(this.el, "." + this.classNames.track + "." + this.classNames.horizontal);
this.axis.y.track.el = this.findChild(this.el, "." + this.classNames.track + "." + this.classNames.vertical);
} else {
// Prepare DOM
this.wrapperEl = document.createElement('div');
this.contentWrapperEl = document.createElement('div');
this.offsetEl = document.createElement('div');
this.maskEl = document.createElement('div');
this.contentEl = document.createElement('div');
this.placeholderEl = document.createElement('div');
this.heightAutoObserverWrapperEl = document.createElement('div');
this.heightAutoObserverEl = document.createElement('div');
this.wrapperEl.classList.add(this.classNames.wrapper);
this.contentWrapperEl.classList.add(this.classNames.contentWrapper);
this.offsetEl.classList.add(this.classNames.offset);
this.maskEl.classList.add(this.classNames.mask);
this.contentEl.classList.add(this.classNames.contentEl);
this.placeholderEl.classList.add(this.classNames.placeholder);
this.heightAutoObserverWrapperEl.classList.add(this.classNames.heightAutoObserverWrapperEl);
this.heightAutoObserverEl.classList.add(this.classNames.heightAutoObserverEl);
while (this.el.firstChild) {
this.contentEl.appendChild(this.el.firstChild);
}
this.contentWrapperEl.appendChild(this.contentEl);
this.offsetEl.appendChild(this.contentWrapperEl);
this.maskEl.appendChild(this.offsetEl);
this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl);
this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl);
this.wrapperEl.appendChild(this.maskEl);
this.wrapperEl.appendChild(this.placeholderEl);
this.el.appendChild(this.wrapperEl);
}
if (!this.axis.x.track.el || !this.axis.y.track.el) {
var track = document.createElement('div');
var scrollbar = document.createElement('div');
track.classList.add(this.classNames.track);
scrollbar.classList.add(this.classNames.scrollbar);
track.appendChild(scrollbar);
this.axis.x.track.el = track.cloneNode(true);
this.axis.x.track.el.classList.add(this.classNames.horizontal);
this.axis.y.track.el = track.cloneNode(true);
this.axis.y.track.el.classList.add(this.classNames.vertical);
this.el.appendChild(this.axis.x.track.el);
this.el.appendChild(this.axis.y.track.el);
}
this.axis.x.scrollbar.el = this.axis.x.track.el.querySelector("." + this.classNames.scrollbar);
this.axis.y.scrollbar.el = this.axis.y.track.el.querySelector("." + this.classNames.scrollbar);
if (!this.options.autoHide) {
this.axis.x.scrollbar.el.classList.add(this.classNames.visible);
this.axis.y.scrollbar.el.classList.add(this.classNames.visible);
}
this.el.setAttribute('data-simplebar', 'init');
};
_proto.initListeners = function initListeners() {
var _this3 = this;
var elWindow = getElementWindow(this.el); // Event listeners
if (this.options.autoHide) {
this.el.addEventListener('mouseenter', this.onMouseEnter);
}
['mousedown', 'click', 'dblclick'].forEach(function (e) {
_this3.el.addEventListener(e, _this3.onPointerEvent, true);
});
['touchstart', 'touchend', 'touchmove'].forEach(function (e) {
_this3.el.addEventListener(e, _this3.onPointerEvent, {
capture: true,
passive: true
});
});
this.el.addEventListener('mousemove', this.onMouseMove);
this.el.addEventListener('mouseleave', this.onMouseLeave);
this.contentWrapperEl.addEventListener('scroll', this.onScroll); // Browser zoom triggers a window resize
elWindow.addEventListener('resize', this.onWindowResize); // Hack for https://github.com/WICG/ResizeObserver/issues/38
var resizeObserverStarted = false;
var resizeObserver = elWindow.ResizeObserver || ResizeObserver;
this.resizeObserver = new resizeObserver(function () {
if (!resizeObserverStarted) return;
_this3.recalculate();
});
this.resizeObserver.observe(this.el);
this.resizeObserver.observe(this.contentEl);
elWindow.requestAnimationFrame(function () {
resizeObserverStarted = true;
}); // This is required to detect horizontal scroll. Vertical scroll only needs the resizeObserver.
this.mutationObserver = new elWindow.MutationObserver(this.recalculate);
this.mutationObserver.observe(this.contentEl, {
childList: true,
subtree: true,
characterData: true
});
};
_proto.recalculate = function recalculate() {
var elWindow = getElementWindow(this.el);
this.elStyles = elWindow.getComputedStyle(this.el);
this.isRtl = this.elStyles.direction === 'rtl';
var isHeightAuto = this.heightAutoObserverEl.offsetHeight <= 1;
var isWidthAuto = this.heightAutoObserverEl.offsetWidth <= 1;
var contentElOffsetWidth = this.contentEl.offsetWidth;
var contentWrapperElOffsetWidth = this.contentWrapperEl.offsetWidth;
var elOverflowX = this.elStyles.overflowX;
var elOverflowY = this.elStyles.overflowY;
this.contentEl.style.padding = this.elStyles.paddingTop + " " + this.elStyles.paddingRight + " " + this.elStyles.paddingBottom + " " + this.elStyles.paddingLeft;
this.wrapperEl.style.margin = "-" + this.elStyles.paddingTop + " -" + this.elStyles.paddingRight + " -" + this.elStyles.paddingBottom + " -" + this.elStyles.paddingLeft;
var contentElScrollHeight = this.contentEl.scrollHeight;
var contentElScrollWidth = this.contentEl.scrollWidth;
this.contentWrapperEl.style.height = isHeightAuto ? 'auto' : '100%'; // Determine placeholder size
this.placeholderEl.style.width = isWidthAuto ? contentElOffsetWidth + "px" : 'auto';
this.placeholderEl.style.height = contentElScrollHeight + "px";
var contentWrapperElOffsetHeight = this.contentWrapperEl.offsetHeight;
this.axis.x.isOverflowing = contentElScrollWidth > contentElOffsetWidth;
this.axis.y.isOverflowing = contentElScrollHeight > contentWrapperElOffsetHeight; // Set isOverflowing to false if user explicitely set hidden overflow
this.axis.x.isOverflowing = elOverflowX === 'hidden' ? false : this.axis.x.isOverflowing;
this.axis.y.isOverflowing = elOverflowY === 'hidden' ? false : this.axis.y.isOverflowing;
this.axis.x.forceVisible = this.options.forceVisible === 'x' || this.options.forceVisible === true;
this.axis.y.forceVisible = this.options.forceVisible === 'y' || this.options.forceVisible === true;
this.hideNativeScrollbar(); // Set isOverflowing to false if scrollbar is not necessary (content is shorter than offset)
var offsetForXScrollbar = this.axis.x.isOverflowing ? this.scrollbarWidth : 0;
var offsetForYScrollbar = this.axis.y.isOverflowing ? this.scrollbarWidth : 0;
this.axis.x.isOverflowing = this.axis.x.isOverflowing && contentElScrollWidth > contentWrapperElOffsetWidth - offsetForYScrollbar;
this.axis.y.isOverflowing = this.axis.y.isOverflowing && contentElScrollHeight > contentWrapperElOffsetHeight - offsetForXScrollbar;
this.axis.x.scrollbar.size = this.getScrollbarSize('x');
this.axis.y.scrollbar.size = this.getScrollbarSize('y');
this.axis.x.scrollbar.el.style.width = this.axis.x.scrollbar.size + "px";
this.axis.y.scrollbar.el.style.height = this.axis.y.scrollbar.size + "px";
this.positionScrollbar('x');
this.positionScrollbar('y');
this.toggleTrackVisibility('x');
this.toggleTrackVisibility('y');
}
/**
* Calculate scrollbar size
*/
;
_proto.getScrollbarSize = function getScrollbarSize(axis) {
if (axis === void 0) {
axis = 'y';
}
if (!this.axis[axis].isOverflowing) {
return 0;
}
var contentSize = this.contentEl[this.axis[axis].scrollSizeAttr];
var trackSize = this.axis[axis].track.el[this.axis[axis].offsetSizeAttr];
var scrollbarSize;
var scrollbarRatio = trackSize / contentSize; // Calculate new height/position of drag handle.
scrollbarSize = Math.max(~~(scrollbarRatio * trackSize), this.options.scrollbarMinSize);
if (this.options.scrollbarMaxSize) {
scrollbarSize = Math.min(scrollbarSize, this.options.scrollbarMaxSize);
}
return scrollbarSize;
};
_proto.positionScrollbar = function positionScrollbar(axis) {
if (axis === void 0) {
axis = 'y';
}
if (!this.axis[axis].isOverflowing) {
return;
}
var contentSize = this.contentWrapperEl[this.axis[axis].scrollSizeAttr];
var trackSize = this.axis[axis].track.el[this.axis[axis].offsetSizeAttr];
var hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
var scrollbar = this.axis[axis].scrollbar;
var scrollOffset = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
scrollOffset = axis === 'x' && this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollOffset : scrollOffset;
var scrollPourcent = scrollOffset / (contentSize - hostSize);
var handleOffset = ~~((trackSize - scrollbar.size) * scrollPourcent);
handleOffset = axis === 'x' && this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? handleOffset + (trackSize - scrollbar.size) : handleOffset;
scrollbar.el.style.transform = axis === 'x' ? "translate3d(" + handleOffset + "px, 0, 0)" : "translate3d(0, " + handleOffset + "px, 0)";
};
_proto.toggleTrackVisibility = function toggleTrackVisibility(axis) {
if (axis === void 0) {
axis = 'y';
}
var track = this.axis[axis].track.el;
var scrollbar = this.axis[axis].scrollbar.el;
if (this.axis[axis].isOverflowing || this.axis[axis].forceVisible) {
track.style.visibility = 'visible';
this.contentWrapperEl.style[this.axis[axis].overflowAttr] = 'scroll';
} else {
track.style.visibility = 'hidden';
this.contentWrapperEl.style[this.axis[axis].overflowAttr] = 'hidden';
} // Even if forceVisible is enabled, scrollbar itself should be hidden
if (this.axis[axis].isOverflowing) {
scrollbar.style.display = 'block';
} else {
scrollbar.style.display = 'none';
}
};
_proto.hideNativeScrollbar = function hideNativeScrollbar() {
this.offsetEl.style[this.isRtl ? 'left' : 'right'] = this.axis.y.isOverflowing || this.axis.y.forceVisible ? "-" + this.scrollbarWidth + "px" : 0;
this.offsetEl.style.bottom = this.axis.x.isOverflowing || this.axis.x.forceVisible ? "-" + this.scrollbarWidth + "px" : 0;
}
/**
* On scroll event handling
*/
;
_proto.onMouseMoveForAxis = function onMouseMoveForAxis(axis) {
if (axis === void 0) {
axis = 'y';
}
this.axis[axis].track.rect = this.axis[axis].track.el.getBoundingClientRect();
this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
var isWithinScrollbarBoundsX = this.isWithinBounds(this.axis[axis].scrollbar.rect);
if (isWithinScrollbarBoundsX) {
this.axis[axis].scrollbar.el.classList.add(this.classNames.hover);
} else {
this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
}
if (this.isWithinBounds(this.axis[axis].track.rect)) {
this.showScrollbar(axis);
this.axis[axis].track.el.classList.add(this.classNames.hover);
} else {
this.axis[axis].track.el.classList.remove(this.classNames.hover);
}
};
_proto.onMouseLeaveForAxis = function onMouseLeaveForAxis(axis) {
if (axis === void 0) {
axis = 'y';
}
this.axis[axis].track.el.classList.remove(this.classNames.hover);
this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
};
/**
* Show scrollbar
*/
_proto.showScrollbar = function showScrollbar(axis) {
if (axis === void 0) {
axis = 'y';
}
var scrollbar = this.axis[axis].scrollbar.el;
if (!this.axis[axis].isVisible) {
scrollbar.classList.add(this.classNames.visible);
this.axis[axis].isVisible = true;
}
if (this.options.autoHide) {
this.hideScrollbars();
}
}
/**
* Hide Scrollbar
*/
;
/**
* on scrollbar handle drag movement starts
*/
_proto.onDragStart = function onDragStart(e, axis) {
if (axis === void 0) {
axis = 'y';
}
var elDocument = getElementDocument(this.el);
var elWindow = getElementWindow(this.el);
var scrollbar = this.axis[axis].scrollbar; // Measure how far the user's mouse is from the top of the scrollbar drag handle.
var eventOffset = axis === 'y' ? e.pageY : e.pageX;
this.axis[axis].dragOffset = eventOffset - scrollbar.rect[this.axis[axis].offsetAttr];
this.draggedAxis = axis;
this.el.classList.add(this.classNames.dragging);
elDocument.addEventListener('mousemove', this.drag, true);
elDocument.addEventListener('mouseup', this.onEndDrag, true);
if (this.removePreventClickId === null) {
elDocument.addEventListener('click', this.preventClick, true);
elDocument.addEventListener('dblclick', this.preventClick, true);
} else {
elWindow.clearTimeout(this.removePreventClickId);
this.removePreventClickId = null;
}
}
/**
* Drag scrollbar handle
*/
;
_proto.onTrackClick = function onTrackClick(e, axis) {
var _this4 = this;
if (axis === void 0) {
axis = 'y';
}
if (!this.options.clickOnTrack) return;
var elWindow = getElementWindow(this.el);
this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
var scrollbar = this.axis[axis].scrollbar;
var scrollbarOffset = scrollbar.rect[this.axis[axis].offsetAttr];
var hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
var scrolled = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
var t = axis === 'y' ? this.mouseY - scrollbarOffset : this.mouseX - scrollbarOffset;
var dir = t < 0 ? -1 : 1;
var scrollSize = dir === -1 ? scrolled - hostSize : scrolled + hostSize;
var scrollTo = function scrollTo() {
if (dir === -1) {
if (scrolled > scrollSize) {
var _this4$contentWrapper;
scrolled -= _this4.options.clickOnTrackSpeed;
_this4.contentWrapperEl.scrollTo((_this4$contentWrapper = {}, _this4$contentWrapper[_this4.axis[axis].offsetAttr] = scrolled, _this4$contentWrapper));
elWindow.requestAnimationFrame(scrollTo);
}
} else {
if (scrolled < scrollSize) {
var _this4$contentWrapper2;
scrolled += _this4.options.clickOnTrackSpeed;
_this4.contentWrapperEl.scrollTo((_this4$contentWrapper2 = {}, _this4$contentWrapper2[_this4.axis[axis].offsetAttr] = scrolled, _this4$contentWrapper2));
elWindow.requestAnimationFrame(scrollTo);
}
}
};
scrollTo();
}
/**
* Getter for content element
*/
;
_proto.getContentElement = function getContentElement() {
return this.contentEl;
}
/**
* Getter for original scrolling element
*/
;
_proto.getScrollElement = function getScrollElement() {
return this.contentWrapperEl;
};
_proto.getScrollbarWidth = function getScrollbarWidth() {
// Try/catch for FF 56 throwing on undefined computedStyles
try {
// Detect browsers supporting CSS scrollbar styling and do not calculate
if (getComputedStyle(this.contentWrapperEl, '::-webkit-scrollbar').display === 'none' || 'scrollbarWidth' in document.documentElement.style || '-ms-overflow-style' in document.documentElement.style) {
return 0;
} else {
return scrollbarWidth(this.el);
}
} catch (e) {
return scrollbarWidth(this.el);
}
};
_proto.removeListeners = function removeListeners() {
var _this5 = this;
var elWindow = getElementWindow(this.el); // Event listeners
if (this.options.autoHide) {
this.el.removeEventListener('mouseenter', this.onMouseEnter);
}
['mousedown', 'click', 'dblclick'].forEach(function (e) {
_this5.el.removeEventListener(e, _this5.onPointerEvent, true);
});
['touchstart', 'touchend', 'touchmove'].forEach(function (e) {
_this5.el.removeEventListener(e, _this5.onPointerEvent, {
capture: true,
passive: true
});
});
this.el.removeEventListener('mousemove', this.onMouseMove);
this.el.removeEventListener('mouseleave', this.onMouseLeave);
if (this.contentWrapperEl) {
this.contentWrapperEl.removeEventListener('scroll', this.onScroll);
}
elWindow.removeEventListener('resize', this.onWindowResize);
if (this.mutationObserver) {
this.mutationObserver.disconnect();
}
if (this.resizeObserver) {
this.resizeObserver.disconnect();
} // Cancel all debounced functions
this.recalculate.cancel();
this.onMouseMove.cancel();
this.hideScrollbars.cancel();
this.onWindowResize.cancel();
}
/**
* UnMount mutation observer and delete SimpleBar instance from DOM element
*/
;
_proto.unMount = function unMount() {
this.removeListeners();
SimpleBar.instances.delete(this.el);
}
/**
* Check if mouse is within bounds
*/
;
_proto.isWithinBounds = function isWithinBounds(bbox) {
return this.mouseX >= bbox.left && this.mouseX <= bbox.left + bbox.width && this.mouseY >= bbox.top && this.mouseY <= bbox.top + bbox.height;
}
/**
* Find element children matches query
*/
;
_proto.findChild = function findChild(el, query) {
var matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
return Array.prototype.filter.call(el.children, function (child) {
return matches.call(child, query);
})[0];
};
return SimpleBar;
}();
SimpleBar.defaultOptions = {
autoHide: true,
forceVisible: false,
clickOnTrack: true,
clickOnTrackSpeed: 40,
classNames: {
contentEl: 'simplebar-content',
contentWrapper: 'simplebar-content-wrapper',
offset: 'simplebar-offset',
mask: 'simplebar-mask',
wrapper: 'simplebar-wrapper',
placeholder: 'simplebar-placeholder',
scrollbar: 'simplebar-scrollbar',
track: 'simplebar-track',
heightAutoObserverWrapperEl: 'simplebar-height-auto-observer-wrapper',
heightAutoObserverEl: 'simplebar-height-auto-observer',
visible: 'simplebar-visible',
horizontal: 'simplebar-horizontal',
vertical: 'simplebar-vertical',
hover: 'simplebar-hover',
dragging: 'simplebar-dragging'
},
scrollbarMinSize: 25,
scrollbarMaxSize: 0,
timeout: 1000
};
SimpleBar.instances = new WeakMap();
export default SimpleBar;
//# sourceMappingURL=simplebar-core.esm.js.map

Some files were not shown because too many files have changed in this diff Show More