ngx-bootstrap
Version:
Angular Bootstrap
2 lines • 16.8 kB
JavaScript
!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="undefined"!=typeof globalThis?globalThis: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";function r(t,e){if(1!==t.nodeType)return[];var o=t.ownerDocument.defaultView,n=null==o?void 0:o.getComputedStyle(t,null);return e?n&&n[e]:n}var i="undefined"!=typeof window&&"undefined"!=typeof document,l=i&&!(!window.MSInputMethodContext||!document.documentMode),a=i&&!(!window.MSInputMethodContext||!/MSIE 10/.test(navigator.userAgent));function f(t){return 11===t?l:10===t?a:l||a}function s(t){if(!t)return document.documentElement;for(var e=f(10)?document.body:null,o=null==t?void 0:t.offsetParent,n=void 0;o===e&&t.nextElementSibling&&n!==t.nextElementSibling;)o=(n=t.nextElementSibling).offsetParent;var i=o&&o.nodeName;return i&&"BODY"!==i&&"HTML"!==i?o&&-1!==["TH","TD","TABLE"].indexOf(o.nodeName)&&"static"===r(o,"position")?s(o):o:n?n.ownerDocument.documentElement:document.documentElement}function u(t){return null!==t.parentNode?u(t.parentNode):t}function d(t,e){if(!(t&&t.nodeType&&e&&e.nodeType))return document.documentElement;var o=t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING,n=o?t:e,r=o?e:t,i=document.createRange();i.setStart(n,0),i.setEnd(r,0);var l,a,f=i.commonAncestorContainer;if(t!==f&&e!==f||n.contains(r))return"BODY"===(a=(l=f).nodeName)||"HTML"!==a&&s(l.firstElementChild)!==l?s(f):f;var p=u(t);return p.host?d(p.host,e):d(t,u(e).host)}function p(t){if(!t||!t.parentElement||f())return document.documentElement;for(var e=t.parentElement;(null==e?void 0:e.parentElement)&&"none"===r(e,"transform");)e=e.parentElement;return e||document.documentElement}function h(t,e){var o="x"===e?"Left":"Top",n="Left"===o?"Right":"Bottom";return parseFloat(t["border"+o+"Width"])+parseFloat(t["border"+n+"Width"])}function c(t,e,o,n){var r=e,i=o,l=n;return Math.max(r["offset"+t],r["scroll"+t],i["client"+t],i["offset"+t],i["scroll"+t],f(10)?parseInt(i["offset"+t],10)+parseInt(l["margin"+("Height"===t?"Top":"Left")],10)+parseInt(l["margin"+("Height"===t?"Bottom":"Right")],10):0)}function m(t){var e=t.body,o=t.documentElement,n=f(10)?getComputedStyle(o):void 0;return{height:c("Height",e,o,n),width:c("Width",e,o,n)}}function g(t,e){void 0===e&&(e="top");var o="top"===e?"scrollTop":"scrollLeft",n=t.nodeName;if("BODY"===n||"HTML"===n){var r=t.ownerDocument.documentElement;return(t.ownerDocument.scrollingElement||r)[o]}return t[o]}function v(t){return Object.assign(Object.assign({},t),{right:(t.left||0)+t.width,bottom:(t.top||0)+t.height})}function b(t){return"number"==typeof t||"[object Number]"===Object.prototype.toString.call(t)}function w(t){var e=t.getBoundingClientRect();try{if(f(10)){var o=g(t,"top"),n=g(t,"left");e&&b(e.top)&&b(e.left)&&b(e.bottom)&&b(e.right)&&(e.top+=o,e.left+=n,e.bottom+=o,e.right+=n)}}catch(t){return e}if(!(e&&b(e.top)&&b(e.left)&&b(e.bottom)&&b(e.right)))return e;var i={left:e.left,top:e.top,width:e.right-e.left,height:e.bottom-e.top},l="HTML"===t.nodeName?m(t.ownerDocument):void 0,a=(null==l?void 0:l.width)||t.clientWidth||b(i.right)&&b(i.left)&&i.right-i.left||0,s=(null==l?void 0:l.height)||t.clientHeight||b(i.bottom)&&b(i.top)&&i.bottom-i.top||0,u=t.offsetWidth-a,d=t.offsetHeight-s;if(u||d){var p=r(t);u-=h(p,"x"),d-=h(p,"y"),i.width-=u,i.height-=d}return v(i)}function y(t){return"HTML"===t.nodeName?t:t.parentNode||t.host}function N(t){if(!t)return document.body;switch(t.nodeName){case"HTML":case"BODY":return t.ownerDocument.body;case"#document":return t.body}var e=r(t),o=e.overflow,n=e.overflowX,i=e.overflowY;return/(auto|scroll|overlay)/.test(String(o)+String(i)+String(n))?t:N(y(t))}function M(t,e,o){var n,i,l,a,s,u;void 0===o&&(o=!1);var d=f(10),p="HTML"===e.nodeName,h=w(t),c=w(e),m=N(t),y=r(e),M=parseFloat(y.borderTopWidth),O=parseFloat(y.borderLeftWidth);o&&p&&(c.top=Math.max(null!==(n=c.top)&&void 0!==n?n:0,0),c.left=Math.max(null!==(i=c.left)&&void 0!==i?i:0,0));var x=v({top:(null!==(l=h.top)&&void 0!==l?l:0)-(null!==(a=c.top)&&void 0!==a?a:0)-M,left:(null!==(s=h.left)&&void 0!==s?s:0)-(null!==(u=c.left)&&void 0!==u?u:0)-O,width:h.width,height:h.height});if(x.marginTop=0,x.marginLeft=0,!d&&p){var E=parseFloat(y.marginTop),T=parseFloat(y.marginLeft);b(x.top)&&(x.top-=M-E),b(x.bottom)&&(x.bottom-=M-E),b(x.left)&&(x.left-=O-T),b(x.right)&&(x.right-=O-T),x.marginTop=E,x.marginLeft=T}return(d&&!o?e.contains(m):e===m&&"BODY"!==m.nodeName)&&(x=function(t,e,o){void 0===o&&(o=!1);var n=g(e,"top"),r=g(e,"left"),i=o?-1:1;return b(t.top)&&(t.top+=n*i),b(t.bottom)&&(t.bottom+=n*i),b(t.left)&&(t.left+=r*i),b(t.right)&&(t.right+=r*i),t}(x,e)),x}function O(t){var e=t.nodeName;return"BODY"!==e&&"HTML"!==e&&("fixed"===r(t,"position")||O(y(t)))}function x(t,e,o,n,r){void 0===o&&(o=0),void 0===r&&(r=!1);var i={top:0,left:0},l=r?p(t):d(t,e);if("viewport"===n)i=function(t,e){void 0===e&&(e=!1);var o=t.ownerDocument.documentElement,n=M(t,o),r=Math.max(o.clientWidth,window.innerWidth||0),i=Math.max(o.clientHeight,window.innerHeight||0),l=e?0:g(o),a=e?0:g(o,"left");return v({top:l-Number(null==n?void 0:n.top)+Number(null==n?void 0:n.marginTop),left:a-Number(null==n?void 0:n.left)+Number(null==n?void 0:n.marginLeft),width:r,height:i})}(l,r);else{var a=void 0;"scrollParent"===n?"BODY"===(a=N(y(e))).nodeName&&(a=t.ownerDocument.documentElement):a="window"===n?t.ownerDocument.documentElement:n;var f=M(a,l,r);if(f&&"HTML"===a.nodeName&&!O(l)){var s=m(t.ownerDocument),u=s.height,h=s.width;b(i.top)&&b(f.top)&&b(f.marginTop)&&(i.top+=f.top-f.marginTop),b(i.top)&&(i.bottom=Number(u)+Number(f.top)),b(i.left)&&b(f.left)&&b(f.marginLeft)&&(i.left+=f.left-f.marginLeft),b(i.top)&&(i.right=Number(h)+Number(f.left))}else f&&(i=f)}return b(i.left)&&(i.left+=o),b(i.top)&&(i.top+=o),b(i.right)&&(i.right-=o),b(i.bottom)&&(i.bottom-=o),i}function E(t,e,o,n,r,i,l){var a,f,s,u;if(void 0===r&&(r=["top","bottom","right","left"]),void 0===i&&(i="viewport"),void 0===l&&(l=0),-1===t.indexOf("auto"))return t;var d=x(o,n,l,i),p={top:{width:null!==(a=d.width)&&void 0!==a?a:0,height:e.top&&d.top?e.top-d.top:0},right:{width:d.right&&e.right?d.right-e.right:0,height:null!==(f=d.height)&&void 0!==f?f:0},bottom:{width:null!==(s=d.width)&&void 0!==s?s:0,height:d.bottom&&e.bottom?d.bottom-e.bottom:0},left:{width:e.left&&d.left?e.left-d.left:0,height:null!==(u=d.height)&&void 0!==u?u:0}},h=Object.keys(p).map((function(t){return Object.assign(Object.assign({key:t},p[t]),{area:(e=p[t],e.width*e.height)});var e})).sort((function(t,e){return e.area-t.area})),c=h.filter((function(t){var e=t.width,n=t.height;return e>=o.clientWidth&&n>=o.clientHeight})),m=(c=c.filter((function(t){return r.some((function(e){return e===t.key}))}))).length>0?c[0].key:h[0].key,g=t.split(" ")[1];return o.className=o.className.replace(/bs-tooltip-auto/g,"bs-tooltip-"+m),m+(g?"-"+g:"")}var T=function(t,e){return void 0===e&&(e=0),t?parseFloat(t):e};function j(t){var e=t.ownerDocument.defaultView,o=null==e?void 0:e.getComputedStyle(t),n=T(null==o?void 0:o.marginTop)+T(null==o?void 0:o.marginBottom),r=T(null==o?void 0:o.marginLeft)+T(null==o?void 0:o.marginRight);return{width:Number(t.offsetWidth)+r,height:Number(t.offsetHeight)+n}}function L(t,e,o){return M(e,o?p(t):d(t,e),o)}function D(t,e,o){var n,r,i,l=o.split(" ")[0],a=j(t),f={width:a.width,height:a.height},s=-1!==["right","left"].indexOf(l),u=s?"top":"left",d=s?"left":"top",p=s?"height":"width",h=s?"width":"height";return f[u]=(null!==(n=e[u])&&void 0!==n?n:0)+e[p]/2-a[p]/2,f[d]=l===d?(null!==(r=e[d])&&void 0!==r?r:0)-a[h]:null!==(i=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]}))}(d)])&&void 0!==i?i:0,f}function S(t,e){var o;return!!(null===(o=t.modifiers[e])||void 0===o?void 0:o.enabled)}function P(t,e,o){t&&e&&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(Number(r)))&&(i="px"),o?o.setStyle(t,n,""+String(e[n])+i):t.style[n]=String(e[n])+i}))}function F(t){var e,o,n,i,l,a,f,s=t.offsets.target,u=t.instance.target.querySelector(".arrow");if(!u)return t;var d=-1!==["left","right"].indexOf(t.placement.split(" ")[0]),p=d?"height":"width",h=d?"Top":"Left",c=h.toLowerCase(),m=d?"left":"top",g=d?"bottom":"right",b=j(u)[p],w=t.placement.split(" ")[1];(null!==(o=t.offsets.host[g])&&void 0!==o?o:0)-b<(null!==(n=s[c])&&void 0!==n?n:0)&&(s[c]-=(null!==(i=s[c])&&void 0!==i?i:0)-((null!==(l=t.offsets.host[g])&&void 0!==l?l:0)-b)),Number(t.offsets.host[c])+Number(b)>(null!==(a=s[g])&&void 0!==a?a:0)&&(s[c]+=Number(t.offsets.host[c])+Number(b)-Number(s[g])),s=v(s);var y,N=r(t.instance.target),M=parseFloat(N["margin"+h]),O=parseFloat(N["border"+h+"Width"]);if(w){var x=parseFloat(N.borderRadius),E=Number(M+O+x);y=c===w?Number(t.offsets.host[c])+E:Number(t.offsets.host[c])+Number(t.offsets.host[p]-E)}else y=Number(t.offsets.host[c])+Number(t.offsets.host[p]/2-b/2);var T=y-(null!==(f=s[c])&&void 0!==f?f:0)-M-O;return T=Math.max(Math.min(s[p]-b,T),0),t.offsets.arrow=((e={})[c]=Math.round(T),e[m]="",e),t.instance.arrow=u,t}function H(t){if(t.offsets.target=v(t.offsets.target),!S(t.options,"flip"))return t.offsets.target=Object.assign(Object.assign({},t.offsets.target),D(t.instance.target,t.offsets.host,t.placement)),t;var e=x(t.instance.target,t.instance.host,0,"viewport",!1),o=t.placement.split(" ")[0],n=t.placement.split(" ")[1]||"",r=E("auto",t.offsets.host,t.instance.target,t.instance.host,t.options.allowedPositions),i=[o,r];return i.forEach((function(r,l){var a,f,s,u,d,p,h,c,m,g,v,b,w,y,N,M;if(o===r&&i.length!==l+1){var O="left"===(o=t.placement.split(" ")[0])&&Math.floor(null!==(a=t.offsets.target.right)&&void 0!==a?a:0)>Math.floor(null!==(f=t.offsets.host.left)&&void 0!==f?f:0)||"right"===o&&Math.floor(null!==(s=t.offsets.target.left)&&void 0!==s?s:0)<Math.floor(null!==(u=t.offsets.host.right)&&void 0!==u?u:0)||"top"===o&&Math.floor(null!==(d=t.offsets.target.bottom)&&void 0!==d?d:0)>Math.floor(null!==(p=t.offsets.host.top)&&void 0!==p?p:0)||"bottom"===o&&Math.floor(null!==(h=t.offsets.target.top)&&void 0!==h?h:0)<Math.floor(null!==(c=t.offsets.host.bottom)&&void 0!==c?c:0),x=Math.floor(null!==(m=t.offsets.target.left)&&void 0!==m?m:0)<Math.floor(null!==(g=e.left)&&void 0!==g?g:0),E=Math.floor(null!==(v=t.offsets.target.right)&&void 0!==v?v:0)>Math.floor(null!==(b=e.right)&&void 0!==b?b:0),T=Math.floor(null!==(w=t.offsets.target.top)&&void 0!==w?w:0)<Math.floor(null!==(y=e.top)&&void 0!==y?y:0),j=Math.floor(null!==(N=t.offsets.target.bottom)&&void 0!==N?N:0)>Math.floor(null!==(M=e.bottom)&&void 0!==M?M:0),L="left"===o&&x||"right"===o&&E||"top"===o&&T||"bottom"===o&&j,S=-1!==["top","bottom"].indexOf(o),P=S&&"left"===n&&x||S&&"right"===n&&E||!S&&"left"===n&&T||!S&&"right"===n&&j;(O||L||P)&&((O||L)&&(o=i[l+1]),P&&(n=function(t){return"right"===t?"left":"left"===t?"right":t}(n)),t.placement=o+(n?" "+n:""),t.offsets.target=Object.assign(Object.assign({},t.offsets.target),D(t.instance.target,t.offsets.host,t.placement)))}})),t}function I(t){var e;if(!S(t.options,"preventOverflow"))return t;var o=t.instance.target.style,n=o,r=n.top,i=n.left,l=n.transform;o.top="",o.left="",o.transform="";var a=x(t.instance.target,t.instance.host,0,(null===(e=t.options.modifiers.preventOverflow)||void 0===e?void 0:e.boundariesElement)||"scrollParent",!1);o.top=r,o.left=i,o.transform=l;var f={primary:function(e){var o,n,r,i,l,f=t.offsets.target[e];return(null!==(n=t.offsets.target[e])&&void 0!==n?n:0)<(null!==(r=a[e])&&void 0!==r?r:0)&&(f=Math.max(null!==(i=t.offsets.target[e])&&void 0!==i?i:0,null!==(l=a[e])&&void 0!==l?l:0)),(o={})[e]=f,o},secondary:function(e){var o,n,r,i,l,f="right"===e?"left":"top",s=t.offsets.target[f];return(null!==(n=t.offsets.target[e])&&void 0!==n?n:0)<(null!==(r=a[e])&&void 0!==r?r:0)&&(s=Math.min(null!==(i=t.offsets.target[f])&&void 0!==i?i:0,(null!==(l=a[e])&&void 0!==l?l:0)-("right"===e?t.offsets.target.width:t.offsets.target.height))),(o={})[f]=s,o}};return["left","right","top","bottom"].forEach((function(e){var o=-1!==["left","top"].indexOf(e)?f.primary:f.secondary;t.offsets.target=Object.assign(Object.assign({},t.offsets.target),o(e))})),t}function B(t){var e,o,n,r,i=t.placement,l=i.split(" ")[0],a=i.split(" ")[1];if(a){var f=t.offsets,s=f.host,u=f.target,d=-1!==["bottom","top"].indexOf(l),p=d?"left":"top",h=d?"width":"height",c={start:(e={},e[p]=s[p],e),end:(o={},o[p]=(null!==(r=s[p])&&void 0!==r?r:0)+s[h]-u[h],o)};t.offsets.target=Object.assign(Object.assign({},u),((n={})[p]=p===a?c.start[p]:c.end[p],n))}return t}var W=function(){function t(){}return t.prototype.position=function(t,e){return this.offset(t,e)},t.prototype.offset=function(t,e){return L(e,t)},t.prototype.positionElements=function(t,e,o,n,r){var i=[H,B,I,F],l=function(t,e,o,n){if(t&&e){var r=L(t,e);o.match(/^(auto)*\s*(left|right|top|bottom)*$/)||o.match(/^(left|right|top|bottom)*(?: (left|right|top|bottom))?\s*(start|end)*$/)||(o="auto");var i=!!o.match(/auto/g),l=o.match(/auto\s(left|right|top|bottom)/)?o.split(" ")[1]||"auto":o,a=l.match(/^(left|right|top|bottom)* ?(?!\1)(left|right|top|bottom)?/);return a&&(l=a[1]+(a[2]?" "+a[2]:"")),-1!==["left right","right left","top bottom","bottom top"].indexOf(l)&&(l="auto"),{options:n||{modifiers:{}},instance:{target:t,host:e,arrow:void 0},offsets:{target:D(t,r,l),host:r,arrow:void 0},positionFixed:!1,placement:l=E(l,r,t,e,n?n.allowedPositions:void 0),placementAuto:i}}}(e,t,o,r);if(l)return i.reduce((function(t,e){return e(t)}),l)},t}(),R=new W;function $(t,e,o,n,r,i){var l=R.positionElements(t,e,o,n,r);if(l){var a=function(t){var e,o,n,r;return{width:t.offsets.target.width,height:t.offsets.target.height,left:Math.floor(null!==(e=t.offsets.target.left)&&void 0!==e?e:0),top:Math.round(null!==(o=t.offsets.target.top)&&void 0!==o?o:0),bottom:Math.round(null!==(n=t.offsets.target.bottom)&&void 0!==n?n:0),right:Math.floor(null!==(r=t.offsets.target.right)&&void 0!==r?r:0)}}(l);P(e,{"will-change":"transform",top:"0px",left:"0px",transform:"translate3d("+a.left+"px, "+a.top+"px, 0px)"},i),l.instance.arrow&&P(l.instance.arrow,l.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}(l,i)}}var C=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){$(A(t.target),A(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:!1,configurable:!0}),t.prototype.disable=function(){this.isDisabled=!0},t.prototype.enable=function(){this.isDisabled=!1},t.prototype.addPositionElement=function(t){this.positionElements.set(A(t.element),t)},t.prototype.calcPosition=function(){this.update$$.next()},t.prototype.deletePositionElement=function(t){this.positionElements.delete(A(t))},t.prototype.setOptions=function(t){this.options=t},t}();function A(t){return"string"==typeof t?document.querySelector(t):t instanceof e.ElementRef?t.nativeElement:null!=t?t:null}C.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new C(e.ɵɵinject(e.NgZone),e.ɵɵinject(e.RendererFactory2),e.ɵɵinject(e.PLATFORM_ID))},token:C,providedIn:"root"}),C.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],C.ctorParameters=function(){return[{type:e.NgZone},{type:e.RendererFactory2},{type:Number,decorators:[{type:e.Inject,args:[e.PLATFORM_ID]}]}]},t.Positioning=W,t.PositioningService=C,t.positionElements=$,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-bootstrap-positioning.umd.min.js.map