!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("rxjs")):"function"==typeof define&&define.amd?define("ngx-bootstrap/positioning",["exports","@angular/core","@angular/common","rxjs"],e):e(((t=t||self)["ngx-bootstrap"]=t["ngx-bootstrap"]||{},t["ngx-bootstrap"].positioning={}),t.ng.core,t.ng.common,t.rxjs)}(this,function(t,e,o,n){"use strict";var r=function(){return(r=Object.assign||function(t){for(var e,o=1,n=arguments.length;o=o.clientWidth&&n>=o.clientHeight}),h=(p=p.filter(function(t){return i.some(function(e){return e===t.key})})).length>0?p[0].key:u[0].key,c=t.split(" ")[1];return o.className=o.className.replace(/bs-tooltip-auto/g,"bs-tooltip-"+h),h+(c?"-"+c:"")}function O(t){var e=t.ownerDocument.defaultView.getComputedStyle(t),o=parseFloat(e.marginTop||0)+parseFloat(e.marginBottom||0),n=parseFloat(e.marginLeft||0)+parseFloat(e.marginRight||0);return{width:Number(t.offsetWidth)+n,height:Number(t.offsetHeight)+o}}function T(t,e,o){return void 0===o&&(o=null),M(e,o?x(t):m(t,e),o)}function D(t,e,o){var n=o.split(" ")[0],r=O(t),i={width:r.width,height:r.height},a=-1!==["right","left"].indexOf(n),f=a?"top":"left",s=a?"left":"top",l=a?"height":"width",u=a?"width":"height";return i[f]=e[f]+e[l]/2-r[l]/2,i[s]=n===s?e[s]-r[u]:e[function(t){var e={left:"right",right:"left",bottom:"top",top:"bottom"};return t.replace(/left|right|bottom|top/g,function(t){return e[t]})}(s)],i}function L(t,e){return t&&t.modifiers&&t.modifiers[e]&&t.modifiers[e].enabled}function S(t,e,o){Object.keys(e).forEach(function(n){var r,i="";-1!==["width","height","top","right","bottom","left"].indexOf(n)&&(""!==(r=e[n])&&!isNaN(parseFloat(r))&&isFinite(r))&&(i="px"),o?o.setStyle(t,n,""+String(e[n])+i):t.style[n]=String(e[n])+i})}function P(t){var e,o=t.offsets.target,n=t.instance.target.querySelector(".arrow");if(!n)return t;var r=-1!==["left","right"].indexOf(t.placement),a=r?"height":"width",f=r?"Top":"Left",s=f.toLowerCase(),l=r?"left":"top",u=r?"bottom":"right",p=O(n)[a];t.offsets.host[u]-po[u]&&(o[s]+=Number(t.offsets.host[s])+Number(p)-Number(o[u])),o=w(o);var h=Number(t.offsets.host[s])+Number(t.offsets.host[a]/2-p/2),c=i(t.instance.target),m=parseFloat(c["margin"+f]),g=parseFloat(c["border"+f+"Width"]),d=h-o[s]-m-g;return d=Math.max(Math.min(o[a]-p,d),0),t.offsets.arrow=((e={})[s]=Math.round(d),e[l]="",e),t.instance.arrow=n,t}function F(t){if(t.offsets.target=w(t.offsets.target),!L(t.options,"flip"))return t.offsets.target=r({},t.offsets.target,D(t.instance.target,t.offsets.host,t.placement)),t;var e=E(t.instance.target,t.instance.host,0,"viewport",!1),o=t.placement.split(" ")[0],n=t.placement.split(" ")[1]||"",i=N("auto",t.offsets.host,t.instance.target,t.instance.host,t.options.allowedPositions),a=[o,i];return a.forEach(function(i,f){if(o!==i||a.length===f+1)return t;var s="left"===(o=t.placement.split(" ")[0])&&Math.floor(t.offsets.target.right)>Math.floor(t.offsets.host.left)||"right"===o&&Math.floor(t.offsets.target.left)Math.floor(t.offsets.host.top)||"bottom"===o&&Math.floor(t.offsets.target.top)Math.floor(e.right),p=Math.floor(t.offsets.target.top)Math.floor(e.bottom),c="left"===o&&l||"right"===o&&u||"top"===o&&p||"bottom"===o&&h,m=-1!==["top","bottom"].indexOf(o),g=m&&"left"===n&&l||m&&"right"===n&&u||!m&&"left"===n&&p||!m&&"right"===n&&h;(s||c||g)&&((s||c)&&(o=a[f+1]),g&&(n=function(t){return"right"===t?"left":"left"===t?"right":t}(n)),t.placement=o+(n?" "+n:""),t.offsets.target=r({},t.offsets.target,D(t.instance.target,t.offsets.host,t.placement)))}),t}function H(t){if(!L(t.options,"preventOverflow"))return t;var e=t.instance.target.style,o=e.top,n=e.left,i=e.transform;e.top="",e.left="",e.transform="";var a=E(t.instance.target,t.instance.host,0,"scrollParent",!1);e.top=o,e.left=n,e.transform=i;var f,s={primary:function(e){var o,n=t.offsets.target[e];return t.offsets.target[e]a[e]&&(r=Math.min(t.offsets.target[n],a[e]-("right"===e?t.offsets.target.width:t.offsets.target.height))),(o={})[n]=r,o}};return["left","right","top","bottom"].forEach(function(e){f=-1!==["left","top"].indexOf(e)?"primary":"secondary",t.offsets.target=r({},t.offsets.target,s[f](e))}),t}function B(t){var e,o,n=t.placement,i=n.split(" ")[0],a=n.split(" ")[1];if(a){var f=t.offsets,s=f.host,l=f.target,u=-1!==["bottom","top"].indexOf(i),p=u?"left":"top",h=u?"width":"height",c={start:(e={},e[p]=s[p],e),end:(o={},o[p]=s[p]+s[h]-l[h],o)};t.offsets.target=r({},l,c[a])}return t}var j=function(){function t(){}return t.prototype.position=function(t,e,o){return this.offset(t,e,!1)},t.prototype.offset=function(t,e,o){return T(e,t)},t.prototype.positionElements=function(t,e,o,n,r){return[F,B,H,P].reduce(function(t,e){return e(t)},function(t,e,o,n){var r=T(t,e);o.match(/^(auto)*\s*(left|right|top|bottom)*$/)||o.match(/^(left|right|top|bottom)*\s*(start|end)*$/)||(o="auto");var i=!!o.match(/auto/g),a=o.match(/auto\s(left|right|top|bottom)/)?o.split(" ")[1]||"auto":o;return{options:n,instance:{target:t,host:e,arrow:null},offsets:{target:D(t,r,a),host:r,arrow:null},positionFixed:!1,placement:a=N(a,r,t,e,n?n.allowedPositions:void 0),placementAuto:i}}(e,t,o,r))},t}(),W=new j;function I(t,e,o,n,r,i){var a=W.positionElements(t,e,o,n,r),f=function(t){return{width:t.offsets.target.width,height:t.offsets.target.height,left:Math.floor(t.offsets.target.left),top:Math.round(t.offsets.target.top),bottom:Math.round(t.offsets.target.bottom),right:Math.floor(t.offsets.target.right)}}(a);S(e,{"will-change":"transform",top:"0px",left:"0px",transform:"translate3d("+f.left+"px, "+f.top+"px, 0px)"},i),a.instance.arrow&&S(a.instance.arrow,a.offsets.arrow,i),function(t,e){var o=t.instance.target,n=o.className;t.placementAuto&&(-1!==(n=(n=(n=n.replace(/bs-popover-auto/g,"bs-popover-"+t.placement)).replace(/bs-tooltip-auto/g,"bs-tooltip-"+t.placement)).replace(/\sauto/g," "+t.placement)).indexOf("popover")&&-1===n.indexOf("popover-auto")&&(n+=" popover-auto"),-1!==n.indexOf("tooltip")&&-1===n.indexOf("tooltip-auto")&&(n+=" tooltip-auto")),n=n.replace(/left|right|top|bottom/g,""+t.placement.split(" ")[0]),e?e.setAttribute(o,"class",n):o.className=n}(a,i)}var $=function(){function t(t,e,r){var i=this;this.update$$=new n.Subject,this.positionElements=new Map,this.isDisabled=!1,o.isPlatformBrowser(r)&&t.runOutsideAngular(function(){i.triggerEvent$=n.merge(n.fromEvent(window,"scroll",{passive:!0}),n.fromEvent(window,"resize",{passive:!0}),n.of(0,n.animationFrameScheduler),i.update$$),i.triggerEvent$.subscribe(function(){i.isDisabled||i.positionElements.forEach(function(t){I(C(t.target),C(t.element),t.attachment,t.appendToBody,i.options,e.createRenderer(null,null))})})})}return t.prototype.position=function(t){this.addPositionElement(t)},Object.defineProperty(t.prototype,"event$",{get:function(){return this.triggerEvent$},enumerable:!0,configurable:!0}),t.prototype.disable=function(){this.isDisabled=!0},t.prototype.enable=function(){this.isDisabled=!1},t.prototype.addPositionElement=function(t){this.positionElements.set(C(t.element),t)},t.prototype.calcPosition=function(){this.update$$.next()},t.prototype.deletePositionElement=function(t){this.positionElements.delete(C(t))},t.prototype.setOptions=function(t){this.options=t},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:e.NgZone},{type:e.RendererFactory2},{type:Number,decorators:[{type:e.Inject,args:[e.PLATFORM_ID]}]}]},t}();function C(t){return"string"==typeof t?document.querySelector(t):t instanceof e.ElementRef?t.nativeElement:t}t.Positioning=j,t.PositioningService=$,t.positionElements=I,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ngx-bootstrap-positioning.umd.min.js.map