UNPKG

ngx-bootstrap-ci

Version:
1,275 lines (1,232 loc) • 164 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs')) : typeof define === 'function' && define.amd ? define('ngx-bootstrap/positioning', ['exports', '@angular/core', '@angular/common', 'rxjs'], factory) : (factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].positioning = {}),global.ng.core,global.ng.common,global.rxjs)); }(this, (function (exports,core,common,rxjs) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ 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); }; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Get CSS computed property of the given element * @param {?} element * @param {?=} property * @return {?} */ function getStyleComputedProperty(element, property) { if (element.nodeType !== 1) { return []; } // NOTE: 1 DOM access here var /** @type {?} */ window = element.ownerDocument.defaultView; var /** @type {?} */ css = window.getComputedStyle(element, null); return property ? css[property] : css; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Returns the parentNode or the host of the element * @param {?} element * @return {?} */ function getParentNode(element) { if (element.nodeName === 'HTML') { return element; } return element.parentNode || element.host; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @return {?} */ function getScrollParent(element) { // Return body, `getScroll` will take care to get the correct `scrollTop` from it if (!element) { return document.body; } switch (element.nodeName) { case 'HTML': case 'BODY': return element.ownerDocument.body; case '#document': return element.body; default: } // Firefox want us to check `-x` and `-y` variations as well var _a = getStyleComputedProperty(element), overflow = _a.overflow, overflowX = _a.overflowX, overflowY = _a.overflowY; if (/(auto|scroll|overlay)/.test(String(overflow) + String(overflowY) + String(overflowX))) { return element; } return getScrollParent(getParentNode(element)); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var /** @type {?} */ isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var /** @type {?} */ isIE11 = isBrowser && !!(((window)).MSInputMethodContext && ((document)).documentMode); var /** @type {?} */ isIE10 = isBrowser && /MSIE 10/.test(navigator.userAgent); /** * @param {?=} version * @return {?} */ function isIE(version) { if (version === 11) { return isIE11; } if (version === 10) { return isIE10; } return isIE11 || isIE10; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @return {?} */ function getOffsetParent(element) { if (!element) { return document.documentElement; } var /** @type {?} */ noOffsetParent = isIE(10) ? document.body : null; // NOTE: 1 DOM access here var /** @type {?} */ offsetParent = element.offsetParent || null; // Skip hidden elements which don't have an offsetParent var /** @type {?} */ sibling; while (offsetParent === noOffsetParent && element.nextElementSibling) { sibling = element.nextElementSibling; offsetParent = sibling.offsetParent; } var /** @type {?} */ nodeName = offsetParent && offsetParent.nodeName; if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') { return sibling ? sibling.ownerDocument.documentElement : document.documentElement; } // .offsetParent will return the closest TH, TD or TABLE in case // no offsetParent is present, I hate this job... if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') { return getOffsetParent(offsetParent); } return offsetParent; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @return {?} */ function isOffsetContainer(element) { var nodeName = element.nodeName; if (nodeName === 'BODY') { return false; } return (nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Finds the root node (document, shadowDOM root) of the given element * @param {?} node * @return {?} */ function getRoot(node) { if (node.parentNode !== null) { return getRoot(node.parentNode); } return node; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element1 * @param {?} element2 * @return {?} */ function findCommonOffsetParent(element1, element2) { // This check is needed to avoid errors in case one of the elements isn't defined for any reason if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) { return document.documentElement; } // Here we make sure to give as "start" the element that comes first in the DOM /* tslint:disable-next-line: no-bitwise */ var /** @type {?} */ order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING; var /** @type {?} */ start = order ? element1 : element2; var /** @type {?} */ end = order ? element2 : element1; // Get common ancestor container var /** @type {?} */ range = document.createRange(); range.setStart(start, 0); range.setEnd(end, 0); var commonAncestorContainer = range.commonAncestorContainer; // Both nodes are inside #document if ((element1 !== commonAncestorContainer && element2 !== commonAncestorContainer) || start.contains(end)) { if (isOffsetContainer(commonAncestorContainer)) { return commonAncestorContainer; } return getOffsetParent(commonAncestorContainer); } // one of the nodes is inside shadowDOM, find which one var /** @type {?} */ element1root = getRoot(element1); if (element1root.host) { return findCommonOffsetParent(element1root.host, element2); } else { return findCommonOffsetParent(element1, getRoot(element2).host); } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Helper to detect borders of a given element */ /** * @param {?} styles * @param {?} axis * @return {?} */ function getBordersSize(styles, axis) { var /** @type {?} */ sideA = axis === 'x' ? 'Left' : 'Top'; var /** @type {?} */ sideB = sideA === 'Left' ? 'Right' : 'Bottom'; return (parseFloat(styles["border" + sideA + "Width"]) + parseFloat(styles["border" + sideB + "Width"])); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} axis * @param {?} body * @param {?} html * @param {?} computedStyle * @return {?} */ function getSize(axis, body, html, computedStyle) { return Math.max(body["offset" + axis], body["scroll" + axis], html["client" + axis], html["offset" + axis], html["scroll" + axis], isIE(10) ? (parseInt(html["offset" + axis], 10) + parseInt(computedStyle["margin" + (axis === 'Height' ? 'Top' : 'Left')], 10) + parseInt(computedStyle["margin" + (axis === 'Height' ? 'Bottom' : 'Right')], 10)) : 0); } /** * @param {?} document * @return {?} */ function getWindowSizes(document) { var /** @type {?} */ body = document.body; var /** @type {?} */ html = document.documentElement; var /** @type {?} */ computedStyle = isIE(10) && getComputedStyle(html); return { height: getSize('Height', body, html, computedStyle), width: getSize('Width', body, html, computedStyle) }; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Gets the scroll value of the given element in the given side (top and left) * @param {?} element * @param {?=} side * @return {?} */ function getScroll(element, side) { if (side === void 0) { side = 'top'; } var /** @type {?} */ upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft'; var /** @type {?} */ nodeName = element.nodeName; if (nodeName === 'BODY' || nodeName === 'HTML') { var /** @type {?} */ html = element.ownerDocument.documentElement; var /** @type {?} */ scrollingElement = element.ownerDocument.scrollingElement || html; return scrollingElement[upperSide]; } return element[upperSide]; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} offsets * @return {?} */ function getClientRect(offsets) { return __assign({}, offsets, { right: offsets.left + offsets.width, bottom: offsets.top + offsets.height }); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @return {?} */ function getBoundingClientRect(element) { var /** @type {?} */ rect = {}; // IE10 10 FIX: Please, don't ask, the element isn't // considered in DOM in some circumstances... // This isn't reproducible in IE10 compatibility mode of IE11 try { if (isIE(10)) { rect = element.getBoundingClientRect(); var /** @type {?} */ scrollTop = getScroll(element, 'top'); var /** @type {?} */ scrollLeft = getScroll(element, 'left'); rect.top += scrollTop; rect.left += scrollLeft; rect.bottom += scrollTop; rect.right += scrollLeft; } else { rect = element.getBoundingClientRect(); } } catch (e) { return undefined; } var /** @type {?} */ result = { left: rect.left, top: rect.top, width: rect.right - rect.left, height: rect.bottom - rect.top }; // subtract scrollbar size from sizes var /** @type {?} */ sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {}; var /** @type {?} */ width = sizes.width || element.clientWidth || result.right - result.left; var /** @type {?} */ height = sizes.height || element.clientHeight || result.bottom - result.top; var /** @type {?} */ horizScrollbar = element.offsetWidth - width; var /** @type {?} */ vertScrollbar = element.offsetHeight - height; // if an hypothetical scrollbar is detected, we must be sure it's not a `border` // we make this check conditional for performance reasons if (horizScrollbar || vertScrollbar) { var /** @type {?} */ styles = getStyleComputedProperty(element); horizScrollbar -= getBordersSize(styles, 'x'); vertScrollbar -= getBordersSize(styles, 'y'); result.width -= horizScrollbar; result.height -= vertScrollbar; } return getClientRect(result); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} rect * @param {?} element * @param {?=} subtract * @return {?} */ function includeScroll(rect, element, subtract) { if (subtract === void 0) { subtract = false; } var /** @type {?} */ scrollTop = getScroll(element, 'top'); var /** @type {?} */ scrollLeft = getScroll(element, 'left'); var /** @type {?} */ modifier = subtract ? -1 : 1; rect.top += scrollTop * modifier; rect.bottom += scrollTop * modifier; rect.left += scrollLeft * modifier; rect.right += scrollLeft * modifier; return rect; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} children * @param {?} parent * @param {?=} fixedPosition * @return {?} */ function getOffsetRectRelativeToArbitraryNode(children, parent, fixedPosition) { if (fixedPosition === void 0) { fixedPosition = false; } var /** @type {?} */ isIE10 = isIE(10); var /** @type {?} */ isHTML = parent.nodeName === 'HTML'; var /** @type {?} */ childrenRect = getBoundingClientRect(children); var /** @type {?} */ parentRect = getBoundingClientRect(parent); var /** @type {?} */ scrollParent = getScrollParent(children); var /** @type {?} */ styles = getStyleComputedProperty(parent); var /** @type {?} */ borderTopWidth = parseFloat(styles.borderTopWidth); var /** @type {?} */ borderLeftWidth = parseFloat(styles.borderLeftWidth); // In cases where the parent is fixed, we must ignore negative scroll in offset calc if (fixedPosition && isHTML) { parentRect.top = Math.max(parentRect.top, 0); parentRect.left = Math.max(parentRect.left, 0); } var /** @type {?} */ offsets = getClientRect({ top: childrenRect.top - parentRect.top - borderTopWidth, left: childrenRect.left - parentRect.left - borderLeftWidth, width: childrenRect.width, height: childrenRect.height }); offsets.marginTop = 0; offsets.marginLeft = 0; // Subtract margins of documentElement in case it's being used as parent // we do this only on HTML because it's the only element that behaves // differently when margins are applied to it. The margins are included in // the box of the documentElement, in the other cases not. if (!isIE10 && isHTML) { var /** @type {?} */ marginTop = parseFloat(styles.marginTop); var /** @type {?} */ marginLeft = parseFloat(styles.marginLeft); offsets.top -= borderTopWidth - marginTop; offsets.bottom -= borderTopWidth - marginTop; offsets.left -= borderLeftWidth - marginLeft; offsets.right -= borderLeftWidth - marginLeft; // Attach marginTop and marginLeft because in some circumstances we may need them offsets.marginTop = marginTop; offsets.marginLeft = marginLeft; } if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') { offsets = includeScroll(offsets, parent); } return offsets; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @param {?=} excludeScroll * @return {?} */ function getViewportOffsetRectRelativeToArtbitraryNode(element, excludeScroll) { if (excludeScroll === void 0) { excludeScroll = false; } var /** @type {?} */ html = element.ownerDocument.documentElement; var /** @type {?} */ relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html); var /** @type {?} */ width = Math.max(html.clientWidth, window.innerWidth || 0); var /** @type {?} */ height = Math.max(html.clientHeight, window.innerHeight || 0); var /** @type {?} */ scrollTop = !excludeScroll ? getScroll(html) : 0; var /** @type {?} */ scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0; var /** @type {?} */ offset = { top: scrollTop - Number(relativeOffset.top) + Number(relativeOffset.marginTop), left: scrollLeft - Number(relativeOffset.left) + Number(relativeOffset.marginLeft), width: width, height: height }; return getClientRect(offset); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @return {?} */ function isFixed(element) { var /** @type {?} */ nodeName = element.nodeName; if (nodeName === 'BODY' || nodeName === 'HTML') { return false; } if (getStyleComputedProperty(element, 'position') === 'fixed') { return true; } return isFixed(getParentNode(element)); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @return {?} */ function getFixedPositionOffsetParent(element) { // This check is needed to avoid errors in case one of the elements isn't defined for any reason if (!element || !element.parentElement || isIE()) { return document.documentElement; } var /** @type {?} */ el = element.parentElement; while (el && getStyleComputedProperty(el, 'transform') === 'none') { el = el.parentElement; } return el || document.documentElement; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} target * @param {?} host * @param {?=} padding * @param {?=} boundariesElement * @param {?=} fixedPosition * @return {?} */ function getBoundaries(target, host, padding, boundariesElement, fixedPosition) { if (padding === void 0) { padding = 0; } if (fixedPosition === void 0) { fixedPosition = false; } // NOTE: 1 DOM access here var /** @type {?} */ boundaries = { top: 0, left: 0 }; var /** @type {?} */ offsetParent = fixedPosition ? getFixedPositionOffsetParent(target) : findCommonOffsetParent(target, host); // Handle viewport case if (boundariesElement === 'viewport') { boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition); } else { // Handle other cases based on DOM element used as boundaries var /** @type {?} */ boundariesNode = void 0; if (boundariesElement === 'scrollParent') { boundariesNode = getScrollParent(getParentNode(host)); if (boundariesNode.nodeName === 'BODY') { boundariesNode = target.ownerDocument.documentElement; } } else if (boundariesElement === 'window') { boundariesNode = target.ownerDocument.documentElement; } else { boundariesNode = boundariesElement; } var /** @type {?} */ offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition); // In case of HTML, we need a different computation if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) { var _a = getWindowSizes(target.ownerDocument), height = _a.height, width = _a.width; boundaries.top += offsets.top - offsets.marginTop; boundaries.bottom = Number(height) + Number(offsets.top); boundaries.left += offsets.left - offsets.marginLeft; boundaries.right = Number(width) + Number(offsets.left); } else { // for all the other DOM elements, this one is good boundaries = offsets; } } // Add paddings boundaries.left += padding; boundaries.top += padding; boundaries.right -= padding; boundaries.bottom -= padding; return boundaries; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} __0 * @return {?} */ function getArea(_a) { var width = _a.width, height = _a.height; return width * height; } /** * @param {?} placement * @param {?} refRect * @param {?} target * @param {?} host * @param {?=} allowedPositions * @param {?=} boundariesElement * @param {?=} padding * @return {?} */ function computeAutoPlacement(placement, refRect, target, host, allowedPositions, boundariesElement, padding) { if (allowedPositions === void 0) { allowedPositions = ['top', 'left', 'bottom', 'right']; } if (boundariesElement === void 0) { boundariesElement = 'viewport'; } if (padding === void 0) { padding = 0; } if (placement.indexOf('auto') === -1) { return placement; } var /** @type {?} */ boundaries = getBoundaries(target, host, padding, boundariesElement); var /** @type {?} */ rects = { top: { width: boundaries.width, height: refRect.top - boundaries.top }, right: { width: boundaries.right - refRect.right, height: boundaries.height }, bottom: { width: boundaries.width, height: boundaries.bottom - refRect.bottom }, left: { width: refRect.left - boundaries.left, height: boundaries.height } }; var /** @type {?} */ sortedAreas = Object.keys(rects) .map(function (key) { return (__assign({ key: key }, rects[key], { area: getArea(rects[key]) })); }) .sort(function (a, b) { return b.area - a.area; }); var /** @type {?} */ filteredAreas = sortedAreas.filter(function (_a) { var width = _a.width, height = _a.height; return width >= target.clientWidth && height >= target.clientHeight; }); filteredAreas = allowedPositions .reduce(function (obj, key) { return __assign({}, obj, (_a = {}, _a[key] = filteredAreas[key], _a)); var _a; }, {}); var /** @type {?} */ computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key; var /** @type {?} */ variation = placement.split(' ')[1]; target.className = target.className.replace(/auto/g, computedPlacement); return computedPlacement + (variation ? "-" + variation : ''); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} data * @return {?} */ function getOffsets(data) { return { width: data.offsets.target.width, height: data.offsets.target.height, left: Math.floor(data.offsets.target.left), top: Math.round(data.offsets.target.top), bottom: Math.round(data.offsets.target.bottom), right: Math.floor(data.offsets.target.right) }; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Get the opposite placement of the given one * @param {?} placement * @return {?} */ function getOppositePlacement(placement) { var /** @type {?} */ hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' }; return placement.replace(/left|right|bottom|top/g, function (matched) { return hash[matched]; }); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Get the opposite placement variation of the given one * @param {?} variation * @return {?} */ function getOppositeVariation(variation) { if (variation === 'right') { return 'left'; } else if (variation === 'left') { return 'right'; } return variation; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Get the outer sizes of the given element (offset size + margins) * @param {?} element * @return {?} */ function getOuterSizes(element) { var /** @type {?} */ window = element.ownerDocument.defaultView; var /** @type {?} */ styles = window.getComputedStyle(element); var /** @type {?} */ x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0); var /** @type {?} */ y = parseFloat(styles.marginLeft || 0) + parseFloat(styles.marginRight || 0); return { width: Number(element.offsetWidth) + y, height: Number(element.offsetHeight) + x }; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} target * @param {?} host * @param {?=} fixedPosition * @return {?} */ function getReferenceOffsets(target, host, fixedPosition) { if (fixedPosition === void 0) { fixedPosition = null; } var /** @type {?} */ commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(target) : findCommonOffsetParent(target, host); return getOffsetRectRelativeToArbitraryNode(host, commonOffsetParent, fixedPosition); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} target * @param {?} hostOffsets * @param {?} position * @return {?} */ function getTargetOffsets(target, hostOffsets, position) { var /** @type {?} */ placement = position.split(' ')[0]; // Get target node sizes var /** @type {?} */ targetRect = getOuterSizes(target); // Add position, width and height to our offsets object var /** @type {?} */ targetOffsets = { width: targetRect.width, height: targetRect.height }; // depending by the target placement we have to compute its offsets slightly differently var /** @type {?} */ isHoriz = ['right', 'left'].indexOf(placement) !== -1; var /** @type {?} */ mainSide = isHoriz ? 'top' : 'left'; var /** @type {?} */ secondarySide = isHoriz ? 'left' : 'top'; var /** @type {?} */ measurement = isHoriz ? 'height' : 'width'; var /** @type {?} */ secondaryMeasurement = !isHoriz ? 'height' : 'width'; targetOffsets[mainSide] = hostOffsets[mainSide] + hostOffsets[measurement] / 2 - targetRect[measurement] / 2; targetOffsets[secondarySide] = placement === secondarySide ? hostOffsets[secondarySide] - targetRect[secondaryMeasurement] : hostOffsets[getOppositePlacement(secondarySide)]; return targetOffsets; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Helper used to know if the given modifier is enabled. * @param {?} options * @param {?} modifierName * @return {?} */ function isModifierEnabled(options, modifierName) { return options && options.modifiers && options.modifiers[modifierName] && options.modifiers[modifierName].enabled; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Tells if a given input is a number * @param {?} n * @return {?} */ function isNumeric(n) { return n !== '' && !isNaN(parseFloat(n)) && isFinite(n); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} data * @param {?=} renderer * @return {?} */ function setAllStyles$$1(data, renderer) { var /** @type {?} */ target = data.instance.target; var /** @type {?} */ offsets = getOffsets(data); setStyles(target, { 'will-change': 'transform', top: '0px', left: '0px', transform: "translate3d(" + offsets.left + "px, " + offsets.top + "px, 0px)" }, renderer); if (data.instance.arrow) { setStyles(data.instance.arrow, data.offsets.arrow, renderer); } if (data.placementAuto) { if (renderer) { renderer.setAttribute(target, 'class', target.className.replace(/bs-popover-auto/g, "bs-popover-" + data.placement)); renderer.setAttribute(target, 'class', target.className.replace(/bs-tooltip-auto/g, "bs-tooltip-" + data.placement)); renderer.setAttribute(target, 'class', target.className.replace(/\sauto/g, "s" + data.placement)); if (target.className.match(/popover/g)) { renderer.addClass(target, 'popover-auto'); } if (target.className.match(/tooltip/g)) { renderer.addClass(target, 'tooltip-auto'); } } else { target.className = target.className.replace(/bs-popover-auto/g, "bs-popover-" + data.placement); target.className = target.className.replace(/bs-tooltip-auto/g, "bs-tooltip-" + data.placement); target.className = target.className.replace(/\sauto/g, "s" + data.placement); if (target.className.match(/popover/g)) { target.classList.add('popover-auto'); } if (target.className.match(/tooltip/g)) { target.classList.add('tooltip-auto'); } } } if (renderer) { renderer.setAttribute(target, 'class', target.className.replace(/left|right|top|bottom/g, "" + data.placement)); } else { target.className = target.className.replace(/left|right|top|bottom/g, "" + data.placement); } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @param {?} styles * @param {?=} renderer * @return {?} */ function setStyles(element, styles, renderer) { Object.keys(styles).forEach(function (prop) { var /** @type {?} */ unit = ''; // add unit if the value is numeric and is one of the following if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) { unit = 'px'; } if (renderer) { renderer.setStyle(element, prop, "" + String(styles[prop]) + unit); return; } element.style[prop] = String(styles[prop]) + unit; }); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} data * @return {?} */ function arrow(data) { var /** @type {?} */ targetOffsets = data.offsets.target; // if arrowElement is a string, suppose it's a CSS selector var /** @type {?} */ arrowElement = data.instance.target.querySelector('.arrow'); // if arrowElement is not found, don't run the modifier if (!arrowElement) { return data; } var /** @type {?} */ isVertical = ['left', 'right'].indexOf(data.placement) !== -1; var /** @type {?} */ len = isVertical ? 'height' : 'width'; var /** @type {?} */ sideCapitalized = isVertical ? 'Top' : 'Left'; var /** @type {?} */ side = sideCapitalized.toLowerCase(); var /** @type {?} */ altSide = isVertical ? 'left' : 'top'; var /** @type {?} */ opSide = isVertical ? 'bottom' : 'right'; var /** @type {?} */ arrowElementSize = getOuterSizes(arrowElement)[len]; // top/left side if (data.offsets.host[opSide] - arrowElementSize < targetOffsets[side]) { targetOffsets[side] -= targetOffsets[side] - (data.offsets.host[opSide] - arrowElementSize); } // bottom/right side if (Number(data.offsets.host[side]) + Number(arrowElementSize) > targetOffsets[opSide]) { targetOffsets[side] += Number(data.offsets.host[side]) + Number(arrowElementSize) - Number(targetOffsets[opSide]); } targetOffsets = getClientRect(targetOffsets); // compute center of the target var /** @type {?} */ center = Number(data.offsets.host[side]) + Number(data.offsets.host[len] / 2 - arrowElementSize / 2); // Compute the sideValue using the updated target offsets // take target margin in account because we don't have this info available var /** @type {?} */ css = getStyleComputedProperty(data.instance.target); var /** @type {?} */ targetMarginSide = parseFloat(css["margin" + sideCapitalized]); var /** @type {?} */ targetBorderSide = parseFloat(css["border" + sideCapitalized + "Width"]); var /** @type {?} */ sideValue = center - targetOffsets[side] - targetMarginSide - targetBorderSide; // prevent arrowElement from being placed not contiguously to its target sideValue = Math.max(Math.min(targetOffsets[len] - arrowElementSize, sideValue), 0); data.offsets.arrow = (_a = {}, _a[side] = Math.round(sideValue), _a[altSide] = '' // make sure to unset any eventual altSide value from the DOM node , _a); data.instance.arrow = arrowElement; return data; var _a; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} data * @return {?} */ function flip(data) { data.offsets.target = getClientRect(data.offsets.target); if (!isModifierEnabled(data.options, 'flip')) { data.offsets.target = __assign({}, data.offsets.target, getTargetOffsets(data.instance.target, data.offsets.host, data.placement)); return data; } var /** @type {?} */ boundaries = getBoundaries(data.instance.target, data.instance.host, 0, // padding 'viewport', false // positionFixed ); var /** @type {?} */ placement = data.placement.split(' ')[0]; var /** @type {?} */ variation = data.placement.split(' ')[1] || ''; var /** @type {?} */ offsetsHost = data.offsets.host; var /** @type {?} */ target = data.instance.target; var /** @type {?} */ host = data.instance.host; var /** @type {?} */ adaptivePosition = variation ? computeAutoPlacement('auto', offsetsHost, target, host, ['top', 'bottom']) : computeAutoPlacement('auto', offsetsHost, target, host); var /** @type {?} */ flipOrder = [placement, adaptivePosition]; /* tslint:disable-next-line: cyclomatic-complexity */ flipOrder.forEach(function (step, index) { if (placement !== step || flipOrder.length === index + 1) { return data; } placement = data.placement.split(' ')[0]; // using floor because the host offsets may contain decimals we are not going to consider here var /** @type {?} */ overlapsRef = (placement === 'left' && Math.floor(data.offsets.target.right) > Math.floor(data.offsets.host.left)) || (placement === 'right' && Math.floor(data.offsets.target.left) < Math.floor(data.offsets.host.right)) || (placement === 'top' && Math.floor(data.offsets.target.bottom) > Math.floor(data.offsets.host.top)) || (placement === 'bottom' && Math.floor(data.offsets.target.top) < Math.floor(data.offsets.host.bottom)); var /** @type {?} */ overflowsLeft = Math.floor(data.offsets.target.left) < Math.floor(boundaries.left); var /** @type {?} */ overflowsRight = Math.floor(data.offsets.target.right) > Math.floor(boundaries.right); var /** @type {?} */ overflowsTop = Math.floor(data.offsets.target.top) < Math.floor(boundaries.top); var /** @type {?} */ overflowsBottom = Math.floor(data.offsets.target.bottom) > Math.floor(boundaries.bottom); var /** @type {?} */ overflowsBoundaries = (placement === 'left' && overflowsLeft) || (placement === 'right' && overflowsRight) || (placement === 'top' && overflowsTop) || (placement === 'bottom' && overflowsBottom); // flip the variation if required var /** @type {?} */ isVertical = ['top', 'bottom'].indexOf(placement) !== -1; var /** @type {?} */ flippedVariation = ((isVertical && variation === 'left' && overflowsLeft) || (isVertical && variation === 'right' && overflowsRight) || (!isVertical && variation === 'left' && overflowsTop) || (!isVertical && variation === 'right' && overflowsBottom)); if (overlapsRef || overflowsBoundaries || flippedVariation) { if (overlapsRef || overflowsBoundaries) { placement = flipOrder[index + 1]; } if (flippedVariation) { variation = getOppositeVariation(variation); } data.placement = placement + (variation ? " " + variation : ''); data.offsets.target = __assign({}, data.offsets.target, getTargetOffsets(data.instance.target, data.offsets.host, data.placement)); } }); return data; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} targetElement * @param {?} hostElement * @param {?} position * @param {?} options * @return {?} */ function initData(targetElement, hostElement, position, options) { var /** @type {?} */ hostElPosition = getReferenceOffsets(targetElement, hostElement); var /** @type {?} */ placementAuto = !!position.match(/auto/g); // support old placements 'auto left|right|top|bottom' var /** @type {?} */ placement = !!position.match(/auto\s(left|right|top|bottom)/g) ? position.split(' ')[1] || '' : position; var /** @type {?} */ targetOffset = getTargetOffsets(targetElement, hostElPosition, placement); placement = computeAutoPlacement(placement, hostElPosition, targetElement, hostElement); return { options: options, instance: { target: targetElement, host: hostElement, arrow: null }, offsets: { target: targetOffset, host: hostElPosition, arrow: null }, positionFixed: false, placement: placement, placementAuto: placementAuto }; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} data * @return {?} */ function preventOverflow(data) { // NOTE: DOM access here // resets the targetOffsets's position so that the document size can be calculated excluding // the size of the targetOffsets element itself var /** @type {?} */ transformProp = 'transform'; var /** @type {?} */ targetStyles = data.instance.target.style; // assignment to help minification var top = targetStyles.top, left = targetStyles.left, _a = transformProp, transform = targetStyles[_a]; targetStyles.top = ''; targetStyles.left = ''; targetStyles[transformProp] = ''; var /** @type {?} */ boundaries = getBoundaries(data.instance.target, data.instance.host, 0, // padding 'scrollParent', false // positionFixed ); // NOTE: DOM access here // restores the original style properties after the offsets have been computed targetStyles.top = top; targetStyles.left = left; targetStyles[transformProp] = transform; var /** @type {?} */ order = ['left', 'right', 'top', 'bottom']; var /** @type {?} */ check = { primary: /** * @param {?} placement * @return {?} */ function (placement) { var /** @type {?} */ value = data.offsets.target[placement]; if (data.offsets.target[placement] < boundaries[placement] && !false // options.escapeWithReference ) { value = Math.max(data.offsets.target[placement], boundaries[placement]); } return _a = {}, _a[placement] = value, _a; var _a; }, secondary: /** * @param {?} placement * @return {?} */ function (placement) { var /** @type {?} */ mainSide = placement === 'right' ? 'left' : 'top'; var /** @type {?} */ value = data.offsets.target[mainSide]; if (data.offsets.target[placement] > boundaries[placement] && !false // escapeWithReference ) { value = Math.min(data.offsets.target[mainSide], boundaries[placement] - (placement === 'right' ? data.offsets.target.width : data.offsets.target.height)); } return _a = {}, _a[mainSide] = value, _a; var _a; } }; var /** @type {?} */ side; order.forEach(function (placement) { side = ['left', 'top'] .indexOf(placement) !== -1 ? 'primary' : 'secondary'; data.offsets.target = __assign({}, data.offsets.target, check[side](placement)); }); return data; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} data * @return {?} */ function shift(data) { var /** @type {?} */ placement = data.placement; var /** @type {?} */ basePlacement = placement.split(' ')[0]; var /** @type {?} */ shiftvariation = placement.split(' ')[1]; if (shiftvariation) { var _a = data.offsets, host = _a.host, target = _a.target; var /** @type {?} */ isVertical = ['bottom', 'top'].indexOf(basePlacement) !== -1; var /** @type {?} */ side = isVertical ? 'left' : 'top'; var /** @type {?} */ measurement = isVertical ? 'width' : 'height'; var /** @type {?} */ shiftOffsets = { left: (_b = {}, _b[side] = host[side], _b), right: (_c = {}, _c[side] = host[side] + host[measurement] - host[measurement], _c) }; data.offsets.target = __assign({}, target, shiftOffsets[shiftvariation]); } return data; var _b, _c; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var Positioning = (function () { function Positioning() { } /** * @param {?} hostElement * @param {?} targetElement * @param {?=} round * @return {?} */ Positioning.prototype.position = /** * @param {?} hostElement * @param {?} targetElement * @param {?=} round * @return {?} */ function (hostElement, targetElement, round) { if (round === void 0) { round = true; } return this.offset(hostElement, targetElement, false); }; /** * @param {?} hostElement * @param {?} targetElement * @param {?=} round * @return {?} */ Positioning.prototype.offset = /** * @param {?} hostElement * @param {?} targetElement * @param {?=} round * @return {?} */ function (hostElement, targetElement, round) { if (round === void 0) { round = true; } return getReferenceOffsets(targetElement, hostElement); }; /** * @param {?} hostElement * @param {?} targetElement * @param {?} position * @param {?=} appendToBody * @param {?=} options * @return {?} */ Positioning.prototype.positionElements = /** * @param {?} hostElement * @param {?} targetElement * @param {?} position * @param {?=} appendToBody * @param {?=} options * @return {?} */ function (hostElement, targetElement, position, appendToBody, options) { var /** @type {?} */ chainOfModifiers = [flip, shift, preventOverflow, arrow]; return chainOfModifiers.reduce(function (modifiedData, modifier) { return modifier(modifiedData); }, initData(targetElement, hostElement, position, options)); }; return Positioning; }()); var /** @type {?} */ positionService = new Positioning(); /** * @param {?} hostElement * @param {?} targetElement * @param {?} placement * @param {?=} appendToBody * @param {?=} options * @param {?=} renderer * @return {?} */ function positionElements(hostElement, targetElement, placement, appendToBody, options, renderer) { var /** @type {?} */ data = positionService.positionElements(hostElement, targetElement, placement, appendToBody, options); setAllStyles$$1(data, renderer); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var PositioningService = (function () { function PositioningService(rendererFactory, platformId) { var _this = this; this.update$$ = new rxjs.Subject(); this.positionElements = new Map(); if (common.isPlatformBrowser(platformId)) { rxjs.merge(rxjs.fromEvent(window, 'scroll'), rxjs.fromEvent(window, 'resize'), rxjs.of(0, rxjs.animationFrameScheduler), this.update$$) .subscribe(function () { _this.positionElements .forEach(function (positionElement) { positionElements(_getHtmlElement(positionElement.target), _getHtmlElement(positionElement.element), positionElement.attachment, positionElement.appendToBody, _this.options, rendererFactory.createRenderer(null, null)); }); }); } } /** * @param {?} options * @return {?} */ PositioningService.prototype.position = /** * @param {?} options * @return {?} */ function (options) { this.