UNPKG

ngx-bootstrap-ci

Version:
1,236 lines (1,192 loc) • 140 kB
import { Injectable, ElementRef, RendererFactory2, Inject, PLATFORM_ID } from '@angular/core'; import { isPlatformBrowser } from '@angular/common'; import { fromEvent, merge, of, animationFrameScheduler, Subject } from 'rxjs'; /** * @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 const /** @type {?} */ window = element.ownerDocument.defaultView; const /** @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 const { overflow, overflowX, overflowY } = getStyleComputedProperty(element); 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 */ const /** @type {?} */ isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ const /** @type {?} */ isIE11 = isBrowser && !!((/** @type {?} */ (window)).MSInputMethodContext && (/** @type {?} */ (document)).documentMode); const /** @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; } const /** @type {?} */ noOffsetParent = isIE(10) ? document.body : null; // NOTE: 1 DOM access here let /** @type {?} */ offsetParent = element.offsetParent || null; // Skip hidden elements which don't have an offsetParent let /** @type {?} */ sibling; while (offsetParent === noOffsetParent && element.nextElementSibling) { sibling = element.nextElementSibling; offsetParent = sibling.offsetParent; } const /** @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) { const { nodeName } = element; 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 */ const /** @type {?} */ order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING; const /** @type {?} */ start = order ? element1 : element2; const /** @type {?} */ end = order ? element2 : element1; // Get common ancestor container const /** @type {?} */ range = document.createRange(); range.setStart(start, 0); range.setEnd(end, 0); const { commonAncestorContainer } = range; // 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 const /** @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) { const /** @type {?} */ sideA = axis === 'x' ? 'Left' : 'Top'; const /** @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) { const /** @type {?} */ body = document.body; const /** @type {?} */ html = document.documentElement; const /** @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 = 'top') { const /** @type {?} */ upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft'; const /** @type {?} */ nodeName = element.nodeName; if (nodeName === 'BODY' || nodeName === 'HTML') { const /** @type {?} */ html = element.ownerDocument.documentElement; const /** @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 Object.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) { let /** @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(); const /** @type {?} */ scrollTop = getScroll(element, 'top'); const /** @type {?} */ scrollLeft = getScroll(element, 'left'); rect.top += scrollTop; rect.left += scrollLeft; rect.bottom += scrollTop; rect.right += scrollLeft; } else { rect = element.getBoundingClientRect(); } } catch (/** @type {?} */ e) { return undefined; } const /** @type {?} */ result = { left: rect.left, top: rect.top, width: rect.right - rect.left, height: rect.bottom - rect.top }; // subtract scrollbar size from sizes const /** @type {?} */ sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {}; const /** @type {?} */ width = sizes.width || element.clientWidth || result.right - result.left; const /** @type {?} */ height = sizes.height || element.clientHeight || result.bottom - result.top; let /** @type {?} */ horizScrollbar = element.offsetWidth - width; let /** @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) { const /** @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 = false) { const /** @type {?} */ scrollTop = getScroll(element, 'top'); const /** @type {?} */ scrollLeft = getScroll(element, 'left'); const /** @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 = false) { const /** @type {?} */ isIE10 = isIE(10); const /** @type {?} */ isHTML = parent.nodeName === 'HTML'; const /** @type {?} */ childrenRect = getBoundingClientRect(children); const /** @type {?} */ parentRect = getBoundingClientRect(parent); const /** @type {?} */ scrollParent = getScrollParent(children); const /** @type {?} */ styles = getStyleComputedProperty(parent); const /** @type {?} */ borderTopWidth = parseFloat(styles.borderTopWidth); const /** @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); } let /** @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) { const /** @type {?} */ marginTop = parseFloat(styles.marginTop); const /** @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 = false) { const /** @type {?} */ html = element.ownerDocument.documentElement; const /** @type {?} */ relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html); const /** @type {?} */ width = Math.max(html.clientWidth, window.innerWidth || 0); const /** @type {?} */ height = Math.max(html.clientHeight, window.innerHeight || 0); const /** @type {?} */ scrollTop = !excludeScroll ? getScroll(html) : 0; const /** @type {?} */ scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0; const /** @type {?} */ offset = { top: scrollTop - Number(relativeOffset.top) + Number(relativeOffset.marginTop), left: scrollLeft - Number(relativeOffset.left) + Number(relativeOffset.marginLeft), width, height }; return getClientRect(offset); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} element * @return {?} */ function isFixed(element) { const /** @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; } let /** @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 = 0, boundariesElement, fixedPosition = false) { // NOTE: 1 DOM access here let /** @type {?} */ boundaries = { top: 0, left: 0 }; const /** @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 let /** @type {?} */ boundariesNode; 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; } const /** @type {?} */ offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition); // In case of HTML, we need a different computation if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) { const { height, width } = getWindowSizes(target.ownerDocument); 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({ width, 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 = ['top', 'left', 'bottom', 'right'], boundariesElement = 'viewport', padding = 0) { if (placement.indexOf('auto') === -1) { return placement; } const /** @type {?} */ boundaries = getBoundaries(target, host, padding, boundariesElement); const /** @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 } }; const /** @type {?} */ sortedAreas = Object.keys(rects) .map(key => (Object.assign({ key }, rects[key], { area: getArea(rects[key]) }))) .sort((a, b) => b.area - a.area); let /** @type {?} */ filteredAreas = sortedAreas.filter(({ width, height }) => width >= target.clientWidth && height >= target.clientHeight); filteredAreas = allowedPositions .reduce((obj, key) => { return Object.assign({}, obj, { [key]: filteredAreas[key] }); }, {}); const /** @type {?} */ computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key; const /** @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) { const /** @type {?} */ hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' }; return placement.replace(/left|right|bottom|top/g, matched => 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) { const /** @type {?} */ window = element.ownerDocument.defaultView; const /** @type {?} */ styles = window.getComputedStyle(element); const /** @type {?} */ x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0); const /** @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 = null) { const /** @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) { const /** @type {?} */ placement = position.split(' ')[0]; // Get target node sizes const /** @type {?} */ targetRect = getOuterSizes(target); // Add position, width and height to our offsets object const /** @type {?} */ targetOffsets = { width: targetRect.width, height: targetRect.height }; // depending by the target placement we have to compute its offsets slightly differently const /** @type {?} */ isHoriz = ['right', 'left'].indexOf(placement) !== -1; const /** @type {?} */ mainSide = isHoriz ? 'top' : 'left'; const /** @type {?} */ secondarySide = isHoriz ? 'left' : 'top'; const /** @type {?} */ measurement = isHoriz ? 'height' : 'width'; const /** @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) { const /** @type {?} */ target = data.instance.target; const /** @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((prop) => { let /** @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) { let /** @type {?} */ targetOffsets = data.offsets.target; // if arrowElement is a string, suppose it's a CSS selector const /** @type {?} */ arrowElement = data.instance.target.querySelector('.arrow'); // if arrowElement is not found, don't run the modifier if (!arrowElement) { return data; } const /** @type {?} */ isVertical = ['left', 'right'].indexOf(data.placement) !== -1; const /** @type {?} */ len = isVertical ? 'height' : 'width'; const /** @type {?} */ sideCapitalized = isVertical ? 'Top' : 'Left'; const /** @type {?} */ side = sideCapitalized.toLowerCase(); const /** @type {?} */ altSide = isVertical ? 'left' : 'top'; const /** @type {?} */ opSide = isVertical ? 'bottom' : 'right'; const /** @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 const /** @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 const /** @type {?} */ css = getStyleComputedProperty(data.instance.target); const /** @type {?} */ targetMarginSide = parseFloat(css[`margin${sideCapitalized}`]); const /** @type {?} */ targetBorderSide = parseFloat(css[`border${sideCapitalized}Width`]); let /** @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 = { [side]: Math.round(sideValue), [altSide]: '' // make sure to unset any eventual altSide value from the DOM node }; data.instance.arrow = arrowElement; return data; } /** * @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 = Object.assign({}, data.offsets.target, getTargetOffsets(data.instance.target, data.offsets.host, data.placement)); return data; } const /** @type {?} */ boundaries = getBoundaries(data.instance.target, data.instance.host, 0, // padding 'viewport', false // positionFixed ); let /** @type {?} */ placement = data.placement.split(' ')[0]; let /** @type {?} */ variation = data.placement.split(' ')[1] || ''; const /** @type {?} */ offsetsHost = data.offsets.host; const /** @type {?} */ target = data.instance.target; const /** @type {?} */ host = data.instance.host; const /** @type {?} */ adaptivePosition = variation ? computeAutoPlacement('auto', offsetsHost, target, host, ['top', 'bottom']) : computeAutoPlacement('auto', offsetsHost, target, host); const /** @type {?} */ flipOrder = [placement, adaptivePosition]; /* tslint:disable-next-line: cyclomatic-complexity */ flipOrder.forEach((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 const /** @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)); const /** @type {?} */ overflowsLeft = Math.floor(data.offsets.target.left) < Math.floor(boundaries.left); const /** @type {?} */ overflowsRight = Math.floor(data.offsets.target.right) > Math.floor(boundaries.right); const /** @type {?} */ overflowsTop = Math.floor(data.offsets.target.top) < Math.floor(boundaries.top); const /** @type {?} */ overflowsBottom = Math.floor(data.offsets.target.bottom) > Math.floor(boundaries.bottom); const /** @type {?} */ overflowsBoundaries = (placement === 'left' && overflowsLeft) || (placement === 'right' && overflowsRight) || (placement === 'top' && overflowsTop) || (placement === 'bottom' && overflowsBottom); // flip the variation if required const /** @type {?} */ isVertical = ['top', 'bottom'].indexOf(placement) !== -1; const /** @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 = Object.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) { const /** @type {?} */ hostElPosition = getReferenceOffsets(targetElement, hostElement); const /** @type {?} */ placementAuto = !!position.match(/auto/g); // support old placements 'auto left|right|top|bottom' let /** @type {?} */ placement = !!position.match(/auto\s(left|right|top|bottom)/g) ? position.split(' ')[1] || '' : position; const /** @type {?} */ targetOffset = getTargetOffsets(targetElement, hostElPosition, placement); placement = computeAutoPlacement(placement, hostElPosition, targetElement, hostElement); return { options, instance: { target: targetElement, host: hostElement, arrow: null }, offsets: { target: targetOffset, host: hostElPosition, arrow: null }, positionFixed: false, placement, 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 const /** @type {?} */ transformProp = 'transform'; const /** @type {?} */ targetStyles = data.instance.target.style; // assignment to help minification const { top, left, [transformProp]: transform } = targetStyles; targetStyles.top = ''; targetStyles.left = ''; targetStyles[transformProp] = ''; const /** @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; const /** @type {?} */ order = ['left', 'right', 'top', 'bottom']; const /** @type {?} */ check = { /** * @param {?} placement * @return {?} */ primary(placement) { let /** @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 { [placement]: value }; }, /** * @param {?} placement * @return {?} */ secondary(placement) { const /** @type {?} */ mainSide = placement === 'right' ? 'left' : 'top'; let /** @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 { [mainSide]: value }; } }; let /** @type {?} */ side; order.forEach(placement => { side = ['left', 'top'] .indexOf(placement) !== -1 ? 'primary' : 'secondary'; data.offsets.target = Object.assign({}, data.offsets.target, check[side](placement)); }); return data; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} data * @return {?} */ function shift(data) { const /** @type {?} */ placement = data.placement; const /** @type {?} */ basePlacement = placement.split(' ')[0]; const /** @type {?} */ shiftvariation = placement.split(' ')[1]; if (shiftvariation) { const { host, target } = data.offsets; const /** @type {?} */ isVertical = ['bottom', 'top'].indexOf(basePlacement) !== -1; const /** @type {?} */ side = isVertical ? 'left' : 'top'; const /** @type {?} */ measurement = isVertical ? 'width' : 'height'; const /** @type {?} */ shiftOffsets = { left: { [side]: host[side] }, right: { [side]: host[side] + host[measurement] - host[measurement] } }; data.offsets.target = Object.assign({}, target, shiftOffsets[shiftvariation]); } return data; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class Positioning { /** * @param {?} hostElement * @param {?} targetElement * @param {?=} round * @return {?} */ position(hostElement, targetElement, round = true) { return this.offset(hostElement, targetElement, false); } /** * @param {?} hostElement * @param {?} targetElement * @param {?=} round * @return {?} */ offset(hostElement, targetElement, round = true) { return getReferenceOffsets(targetElement, hostElement); } /** * @param {?} hostElement * @param {?} targetElement * @param {?} position * @param {?=} appendToBody * @param {?=} options * @return {?} */ positionElements(hostElement, targetElement, position, appendToBody, options) { const /** @type {?} */ chainOfModifiers = [flip, shift, preventOverflow, arrow]; return chainOfModifiers.reduce((modifiedData, modifier) => modifier(modifiedData), initData(targetElement, hostElement, position, options)); } } const /** @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) { const /** @type {?} */ data = positionService.positionElements(hostElement, targetElement, placement, appendToBody, options); setAllStyles$$1(data, renderer); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class PositioningService { /** * @param {?} rendererFactory * @param {?} platformId */ constructor(rendererFactory, platformId) { this.update$$ = new Subject(); this.positionElements = new Map(); if (isPlatformBrowser(platformId)) { merge(fromEvent(window, 'scroll'), fromEvent(window, 'resize'), of(0, animationFrameScheduler), this.update$$) .subscribe(() => { this.positionElements .forEach((positionElement) => { positionElements(_getHtmlElement(positionElement.target), _getHtmlElement(positionElement.element), positionElement.attachment, positionElement.appendToBody, this.options, rendererFactory.createRenderer(null, null)); }); }); } } /** * @param {?} options * @return {?} */ position(options) { this.addPositionElement(options); this.update$$.next(); } /** * @param {?} options * @return {?} */ addPositionElement(options) { this.positionElements.set(_getHtmlElement(options.element), options); } /** * @param {?} elRef * @return {?} */ deletePositionElement(elRef) { this.positionElements.delete(_getHtmlElement(elRef)); } /** * @param {?} options * @return {?} */ setOptions(options) { this.options = options; } } PositioningService.decorators = [ { type: Injectable } ]; /** @nocollapse */ PositioningService.ctorParameters = () => [ { type: RendererFactory2, }, { type: undefined, decorators: [{ type: Inject, args: [PLATFORM_ID,] },] }, ]; /** * @param {?} element * @return {?} */ function _getHtmlElement(element) { // it means that we got a selector if (typeof element === 'string') { return document.querySelector(element); } if (element instanceof ElementRef) { return element.nativeElement; } return element; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ export { positionElements, Positioning, PositioningService }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmd4LWJvb3RzdHJhcC1wb3NpdGlvbmluZy5qcy5tYXAiLCJzb3VyY2VzIjpbIm5nOi8vbmd4LWJvb3RzdHJhcC9wb3NpdGlvbmluZy91dGlscy9nZXRTdHlsZUNvbXB1dGVkUHJvcGVydHkudHMiLCJuZzovL25neC1ib290c3RyYXAvcG9zaXRpb25pbmcvdXRpbHMvZ2V0UGFyZW50Tm9kZS50cyIsIm5nOi8vbmd4LWJvb3RzdHJhcC9wb3NpdGlvbmluZy91dGlscy9nZXRTY3JvbGxQYXJlbnQudHMiLCJuZzovL25neC1ib290c3RyYXAvcG9zaXRpb25pbmcvdXRpbHMvaXNCcm93c2VyLnRzIiwibmc6Ly9uZ3gtYm9vdHN0cmFwL3Bvc2l0aW9uaW5nL3V0aWxzL2lzSUUudHMiLCJuZzovL25neC1ib290c3RyYXAvcG9zaXRpb25pbmcvdXRpbHMvZ2V0T2Zmc2V0UGFyZW50LnRzIiwibmc6Ly9uZ3gtYm9vdHN0cmFwL3Bvc2l0aW9uaW5nL3V0aWxzL2lzT2Zmc2V0Q29udGFpbmVyLnRzIiwibmc6Ly9uZ3gtYm9vdHN0cmFwL3Bvc2l0aW9uaW5nL3V0aWxzL2dldFJvb3QudHMiLCJuZzovL25neC1ib290c3RyYXAvcG9zaXRpb25pbmcvdXRpbHMvZmluZENvbW1vbk9mZnNldFBhcmVudC50cyIsIm5nOi8vbmd4LWJvb3RzdHJhcC9wb3NpdGlvbmluZy91dGlscy9nZXRCb3JkZXJzU2l6ZS50cyIsIm5nOi8vbmd4LWJvb3RzdHJhcC9wb3NpdGlvbmluZy91dGlscy9nZXRXaW5kb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