ngx-bootstrap-positioning.umd.min.js 13 KB

12
  1. !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<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function i(t,e){if(1!==t.nodeType)return[];var o=t.ownerDocument.defaultView.getComputedStyle(t,null);return e?o[e]:o}function a(t){return"HTML"===t.nodeName?t:t.parentNode||t.host}function f(t){if(!t)return document.body;switch(t.nodeName){case"HTML":case"BODY":return t.ownerDocument.body;case"#document":return t.body}var e=i(t),o=e.overflow,n=e.overflowX,r=e.overflowY;return/(auto|scroll|overlay)/.test(String(o)+String(r)+String(n))?t:f(a(t))}var s="undefined"!=typeof window&&"undefined"!=typeof document,l=s&&!(!window.MSInputMethodContext||!document.documentMode),u=s&&!(!window.MSInputMethodContext||!/MSIE 10/.test(navigator.userAgent));function p(t){return 11===t?l:10===t?u:l||u}function h(t){if(!t)return document.documentElement;for(var e,o=p(10)?document.body:null,n=t.offsetParent||null;n===o&&t.nextElementSibling&&e!==t.nextElementSibling;)n=(e=t.nextElementSibling).offsetParent;var r=n&&n.nodeName;return r&&"BODY"!==r&&"HTML"!==r?-1!==["TH","TD","TABLE"].indexOf(n.nodeName)&&"static"===i(n,"position")?h(n):n:e?e.ownerDocument.documentElement:document.documentElement}function c(t){return null!==t.parentNode?c(t.parentNode):t}function m(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 a,f,s=i.commonAncestorContainer;if(t!==s&&e!==s||n.contains(r))return"BODY"===(f=(a=s).nodeName)||"HTML"!==f&&h(a.firstElementChild)!==a?h(s):s;var l=c(t);return l.host?m(l.host,e):m(t,c(e).host)}function g(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 d(t,e,o,n){return Math.max(e["offset"+t],e["scroll"+t],o["client"+t],o["offset"+t],o["scroll"+t],p(10)?parseInt(o["offset"+t],10)+parseInt(n["margin"+("Height"===t?"Top":"Left")],10)+parseInt(n["margin"+("Height"===t?"Bottom":"Right")],10):0)}function b(t){var e=t.body,o=t.documentElement,n=p(10)&&getComputedStyle(o);return{height:d("Height",e,o,n),width:d("Width",e,o,n)}}function v(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 w(t){return r({},t,{right:t.left+t.width,bottom:t.top+t.height})}function y(t){var e={};try{if(p(10)){e=t.getBoundingClientRect();var o=v(t,"top"),n=v(t,"left");e.top+=o,e.left+=n,e.bottom+=o,e.right+=n}else e=t.getBoundingClientRect()}catch(t){return}var r={left:e.left,top:e.top,width:e.right-e.left,height:e.bottom-e.top},a="HTML"===t.nodeName?b(t.ownerDocument):{},f=a.width||t.clientWidth||r.right-r.left,s=a.height||t.clientHeight||r.bottom-r.top,l=t.offsetWidth-f,u=t.offsetHeight-s;if(l||u){var h=i(t);l-=g(h,"x"),u-=g(h,"y"),r.width-=l,r.height-=u}return w(r)}function M(t,e,o){void 0===o&&(o=!1);var n=p(10),r="HTML"===e.nodeName,a=y(t),s=y(e),l=f(t),u=i(e),h=parseFloat(u.borderTopWidth),c=parseFloat(u.borderLeftWidth);o&&r&&(s.top=Math.max(s.top,0),s.left=Math.max(s.left,0));var m=w({top:a.top-s.top-h,left:a.left-s.left-c,width:a.width,height:a.height});if(m.marginTop=0,m.marginLeft=0,!n&&r){var g=parseFloat(u.marginTop),d=parseFloat(u.marginLeft);m.top-=h-g,m.bottom-=h-g,m.left-=c-d,m.right-=c-d,m.marginTop=g,m.marginLeft=d}return(n&&!o?e.contains(l):e===l&&"BODY"!==l.nodeName)&&(m=function(t,e,o){void 0===o&&(o=!1);var n=v(e,"top"),r=v(e,"left"),i=o?-1:1;return t.top+=n*i,t.bottom+=n*i,t.left+=r*i,t.right+=r*i,t}(m,e)),m}function x(t){if(!t||!t.parentElement||p())return document.documentElement;for(var e=t.parentElement;e&&"none"===i(e,"transform");)e=e.parentElement;return e||document.documentElement}function E(t,e,o,n,r){void 0===o&&(o=0),void 0===r&&(r=!1);var s={top:0,left:0},l=r?x(t):m(t,e);if("viewport"===n)s=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),a=e?0:v(o),f=e?0:v(o,"left");return w({top:a-Number(n.top)+Number(n.marginTop),left:f-Number(n.left)+Number(n.marginLeft),width:r,height:i})}(l,r);else{var u=void 0;"scrollParent"===n?"BODY"===(u=f(a(e))).nodeName&&(u=t.ownerDocument.documentElement):u="window"===n?t.ownerDocument.documentElement:n;var p=M(u,l,r);if("HTML"!==u.nodeName||function t(e){var o=e.nodeName;return"BODY"!==o&&"HTML"!==o&&("fixed"===i(e,"position")||t(a(e)))}(l))s=p;else{var h=b(t.ownerDocument),c=h.height,g=h.width;s.top+=p.top-p.marginTop,s.bottom=Number(c)+Number(p.top),s.left+=p.left-p.marginLeft,s.right=Number(g)+Number(p.left)}}return s.left+=o,s.top+=o,s.right-=o,s.bottom-=o,s}function N(t,e,o,n,i,a,f){if(void 0===i&&(i=["top","bottom","right","left"]),void 0===a&&(a="viewport"),void 0===f&&(f=0),-1===t.indexOf("auto"))return t;var s=E(o,n,f,a),l={top:{width:s.width,height:e.top-s.top},right:{width:s.right-e.right,height:s.height},bottom:{width:s.width,height:s.bottom-e.bottom},left:{width:e.left-s.left,height:s.height}},u=Object.keys(l).map(function(t){return r({key:t},l[t],{area:(e=l[t],e.width*e.height)});var e}).sort(function(t,e){return e.area-t.area}),p=u.filter(function(t){var e=t.width,n=t.height;return e>=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]-p<o[s]&&(o[s]-=o[s]-(t.offsets.host[u]-p)),Number(t.offsets.host[s])+Number(p)>o[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.right)||"top"===o&&Math.floor(t.offsets.target.bottom)>Math.floor(t.offsets.host.top)||"bottom"===o&&Math.floor(t.offsets.target.top)<Math.floor(t.offsets.host.bottom),l=Math.floor(t.offsets.target.left)<Math.floor(e.left),u=Math.floor(t.offsets.target.right)>Math.floor(e.right),p=Math.floor(t.offsets.target.top)<Math.floor(e.top),h=Math.floor(t.offsets.target.bottom)>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]&&(n=Math.max(t.offsets.target[e],a[e])),(o={})[e]=n,o},secondary:function(e){var o,n="right"===e?"left":"top",r=t.offsets.target[n];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})});
  2. //# sourceMappingURL=ngx-bootstrap-positioning.umd.min.js.map