@bodia_uz/popper.js
Version:
A kickass library to manage your poppers (lite version)
6 lines (5 loc) • 14.6 kB
JavaScript
/*
Copyright (C) Federico Zivolo 2018
Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT).
*/for(var a='undefined'!=typeof window&&'undefined'!=typeof document,b=['Edge','Trident','Firefox'],c=0,d=0;d<b.length;d+=1)if(a&&0<=navigator.userAgent.indexOf(b[d])){c=1;break}function e(a){var b=!1;return function(){b||(b=!0,window.Promise.resolve().then(function(){b=!1,a()}))}}function f(a){var b=!1;return function(){b||(b=!0,setTimeout(function(){b=!1,a()},c))}}var g=a&&window.Promise,h=g?e:f;function i(a){return a&&'[object Function]'==={}.toString.call(a)}function j(a,b){if(1!==a.nodeType)return[];var c=getComputedStyle(a,null);return b?c[b]:c}function k(a){return'HTML'===a.nodeName?a:a.parentNode||a.host}function l(a){if(!a)return document.body;switch(a.nodeName){case'HTML':case'BODY':return a.ownerDocument.body;case'#document':return a.body;}var b=j(a),c=b.overflow,d=b.overflowX,e=b.overflowY;return /(auto|scroll)/.test(c+e+d)?a:l(k(a))}function m(a){var b=a&&a.offsetParent,c=b&&b.nodeName;return c&&'BODY'!==c&&'HTML'!==c?-1!==['TD','TABLE'].indexOf(b.nodeName)&&'static'===j(b,'position')?m(b):b:a?a.ownerDocument.documentElement:document.documentElement}function n(a){var b=a.nodeName;return'BODY'!==b&&('HTML'===b||m(a.firstElementChild)===a)}function o(a){return null===a.parentNode?a:o(a.parentNode)}function p(a,b){if(!a||!a.nodeType||!b||!b.nodeType)return document.documentElement;var c=a.compareDocumentPosition(b)&Node.DOCUMENT_POSITION_FOLLOWING,d=c?a:b,e=c?b:a,f=document.createRange();f.setStart(d,0),f.setEnd(e,0);var g=f.commonAncestorContainer;if(a!==g&&b!==g||d.contains(e))return n(g)?g:m(g);var h=o(a);return h.host?p(h.host,b):p(a,o(b).host)}function q(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:'top',c='top'===b?'scrollTop':'scrollLeft',d=a.nodeName;if('BODY'===d||'HTML'===d){var e=a.ownerDocument.documentElement,f=a.ownerDocument.scrollingElement||e;return f[c]}return a[c]}function r(a,b){var c=2<arguments.length&&void 0!==arguments[2]&&arguments[2],d=q(b,'top'),e=q(b,'left'),f=c?-1:1;return a.top+=d*f,a.bottom+=d*f,a.left+=e*f,a.right+=e*f,a}function s(a,b){var c='x'===b?'Left':'Top',d='Left'==c?'Right':'Bottom';return parseFloat(a['border'+c+'Width'],10)+parseFloat(a['border'+d+'Width'],10)}var t,u=function(){return void 0==t&&(t=-1!==navigator.appVersion.indexOf('MSIE 10')),t};function v(a,b,c,d){return Math.max(b['offset'+a],b['scroll'+a],c['client'+a],c['offset'+a],c['scroll'+a],u()?c['offset'+a]+d['margin'+('Height'===a?'Top':'Left')]+d['margin'+('Height'===a?'Bottom':'Right')]:0)}function w(){var a=document.body,b=document.documentElement,c=u()&&getComputedStyle(b);return{height:v('Height',a,b,c),width:v('Width',a,b,c)}}var x=function(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')},y=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),z=function(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a},A=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};function B(a){return A({},a,{right:a.left+a.width,bottom:a.top+a.height})}function C(a){var b={};try{if(u()){b=a.getBoundingClientRect();var c=q(a,'top'),d=q(a,'left');b.top+=c,b.left+=d,b.bottom+=c,b.right+=d}else b=a.getBoundingClientRect()}catch(a){}var e={left:b.left,top:b.top,width:b.right-b.left,height:b.bottom-b.top},f='HTML'===a.nodeName?w():{},g=f.width||a.clientWidth||e.right-e.left,h=f.height||a.clientHeight||e.bottom-e.top,i=a.offsetWidth-g,k=a.offsetHeight-h;if(i||k){var l=j(a);i-=s(l,'x'),k-=s(l,'y'),e.width-=i,e.height-=k}return B(e)}function D(a,b){var c=u(),d='HTML'===b.nodeName,e=C(a),f=C(b),g=l(a),h=j(b),i=parseFloat(h.borderTopWidth,10),k=parseFloat(h.borderLeftWidth,10),m=B({top:e.top-f.top-i,left:e.left-f.left-k,width:e.width,height:e.height});if(m.marginTop=0,m.marginLeft=0,!c&&d){var n=parseFloat(h.marginTop,10),o=parseFloat(h.marginLeft,10);m.top-=i-n,m.bottom-=i-n,m.left-=k-o,m.right-=k-o,m.marginTop=n,m.marginLeft=o}return(c?b.contains(g):b===g&&'BODY'!==g.nodeName)&&(m=r(m,b)),m}function E(a){var b=Math.max,c=a.ownerDocument.documentElement,d=D(a,c),e=b(c.clientWidth,window.innerWidth||0),f=b(c.clientHeight,window.innerHeight||0),g=q(c),h=q(c,'left'),i={top:g-d.top+d.marginTop,left:h-d.left+d.marginLeft,width:e,height:f};return B(i)}function F(a){var b=a.nodeName;return'BODY'===b||'HTML'===b?!1:!('fixed'!==j(a,'position'))||F(k(a))}function G(a,b,c,d){var e=4<arguments.length&&void 0!==arguments[4]?arguments[4]:null,f={top:0,left:0},g=e||p(a,b);if('viewport'===d)f=E(g);else{var h;'scrollParent'===d?(h=l(k(b)),'BODY'===h.nodeName&&(h=a.ownerDocument.documentElement)):'window'===d?h=a.ownerDocument.documentElement:h=d;var i=D(h,g);if('HTML'===h.nodeName&&!F(g)){var j=w(),m=j.height,n=j.width;f.top+=i.top-i.marginTop,f.bottom=m+i.top,f.left+=i.left-i.marginLeft,f.right=n+i.left}else f=i}return f.left+=c,f.top+=c,f.right-=c,f.bottom-=c,f}function H(a){var b=a.width,c=a.height;return b*c}function I(a,b,c,d,e){var f=5<arguments.length&&arguments[5]!==void 0?arguments[5]:0;if(-1===a.indexOf('auto'))return a;var g=G(c,d,f,e,null),h={top:{width:g.width,height:b.top-g.top},right:{width:g.right-b.right,height:g.height},bottom:{width:g.width,height:g.bottom-b.bottom},left:{width:b.left-g.left,height:g.height}},i=Object.keys(h).map(function(a){return A({key:a},h[a],{area:H(h[a])})}).sort(function(c,a){return a.area-c.area}),j=i.filter(function(a){var b=a.width,d=a.height;return b>=c.clientWidth&&d>=c.clientHeight}),k=0<j.length?j[0].key:i[0].key,l=a.split('-')[1];return k+(l?'-'+l:'')}function J(a,b,c,d){var e=d||p(b,c);return D(c,e)}function K(a){var b=getComputedStyle(a),c=parseFloat(b.marginTop)+parseFloat(b.marginBottom),d=parseFloat(b.marginLeft)+parseFloat(b.marginRight),e={width:a.offsetWidth+d,height:a.offsetHeight+c};return e}function L(a){var b={left:'right',right:'left',bottom:'top',top:'bottom'};return a.replace(/left|right|bottom|top/g,function(a){return b[a]})}function M(a,b,c){c=c.split('-')[0];var d=K(a),e={width:d.width,height:d.height},f=-1!==['right','left'].indexOf(c),g=f?'top':'left',h=f?'left':'top',i=f?'height':'width',j=f?'width':'height';return e[g]=b[g]+b[i]/2-d[i]/2,e[h]=c===h?b[h]-d[j]:b[L(h)],e}function N(a,b){return Array.prototype.find?a.find(b):a.filter(b)[0]}function O(a,b,c){if(Array.prototype.findIndex)return a.findIndex(function(a){return a[b]===c});var d=N(a,function(a){return a[b]===c});return a.indexOf(d)}function P(a,b,c){var d=void 0===c?a:a.slice(0,O(a,'name',c));return d.forEach(function(a){a['function']&&console.warn('`modifier.function` is deprecated, use `modifier.fn`!');var c=a['function']||a.fn;a.enabled&&i(c)&&(b.offsets.popper=B(b.offsets.popper),b.offsets.reference=B(b.offsets.reference),b=c(b,a))}),b}function Q(a){if(this.state.isDestroyed)return void(a&&a(void 0));var b={instance:this,styles:{},arrowStyles:{},attributes:{},flipped:!1,offsets:{}};b.offsets.reference=J(this.state,this.popper,this.reference,this.options.positionFixed?window.document.documentElement:void 0),b.placement=I(this.options.placement,b.offsets.reference,this.popper,this.reference,this.options.modifiers.flip.boundariesElement,this.options.modifiers.flip.padding),b.originalPlacement=b.placement,b.positionFixed=this.options.positionFixed,b.offsets.popper=M(this.popper,b.offsets.reference,b.placement),b.offsets.popper.position=this.options.positionFixed?'fixed':'absolute',b=P(this.modifiers,b),this.state.isCreated?this.options.onUpdate(b):(this.state.isCreated=!0,this.options.onCreate(b)),a&&a(b)}function R(a,b){return a.some(function(a){var c=a.name,d=a.enabled;return d&&c===b})}function S(a){for(var b=[!1,'ms','Webkit','Moz','O'],c=a.charAt(0).toUpperCase()+a.slice(1),d=0;d<b.length-1;d++){var e=b[d],f=e?''+e+c:a;if('undefined'!=typeof document.body.style[f])return f}return null}function T(){return this.state.isDestroyed=!0,R(this.modifiers,'applyStyle')&&(this.popper.removeAttribute('data-popper-placement'),this.popper.style.left='',this.popper.style.position='',this.popper.style.top='',this.popper.style[S('transform')]=''),this.options.removeOnDestroy&&this.popper.parentNode.removeChild(this.popper),this}function U(a){var b=a.placement,c=b.split('-')[0],d=b.split('-')[1];if(d){var e=a.offsets,f=e.reference,g=e.popper,h=-1!==['bottom','top'].indexOf(c),i=h?'left':'top',j=h?'width':'height',k={start:z({},i,f[i]),end:z({},i,f[i]+f[j]-g[j])};a.offsets.popper=A({},g,k[d])}return a}function V(a,b){var c=a.positionFixed?window.document.documentElement:void 0,d=b.boundariesElement||c||m(a.instance.popper);a.instance.reference===d&&(d=m(d));var e=G(a.instance.popper,a.instance.reference,b.padding,d,c);b.boundaries=e;var f=b.priority,g=a.offsets.popper,h={primary:function(a){var c=g[a];return g[a]<e[a]&&!b.escapeWithReference&&(c=Math.max(g[a],e[a])),z({},a,c)},secondary:function(a){var c='right'===a?'left':'top',d=g[c];return g[a]>e[a]&&!b.escapeWithReference&&(d=Math.min(g[c],e[a]-('right'===a?g.width:g.height))),z({},c,d)}};return f.forEach(function(a){var b=-1===['left','top'].indexOf(a)?'secondary':'primary';g=A({},g,h[b](a))}),a.offsets.popper=g,a}function W(a){if('end'===a)return'start';return'start'===a?'end':a}var X=['auto-start','auto','auto-end','top-start','top','top-end','right-start','right','right-end','bottom-end','bottom','bottom-start','left-end','left','left-start'],Y=X.slice(3);function Z(a){var b=1<arguments.length&&arguments[1]!==void 0&&arguments[1],c=Y.indexOf(a),d=Y.slice(c+1).concat(Y.slice(0,c));return b?d.reverse():d}var $={FLIP:'flip',CLOCKWISE:'clockwise',COUNTERCLOCKWISE:'counterclockwise'};function _(a,b){if(R(a.instance.modifiers,'inner'))return a;if(a.flipped&&a.placement===a.originalPlacement)return a;var c=G(a.instance.popper,a.instance.reference,b.padding,b.boundariesElement,b.positionFixed?window.document.documentElement:void 0),d=a.placement.split('-')[0],e=L(d),f=a.placement.split('-')[1]||'',g=[];switch(b.behavior){case $.FLIP:g=[d,e];break;case $.CLOCKWISE:g=Z(d);break;case $.COUNTERCLOCKWISE:g=Z(d,!0);break;default:g=b.behavior;}return g.forEach(function(h,i){if(d!==h||g.length===i+1)return a;d=a.placement.split('-')[0],e=L(d);var j=a.offsets.popper,k=a.offsets.reference,l=Math.floor,m='left'===d&&l(j.right)>l(k.left)||'right'===d&&l(j.left)<l(k.right)||'top'===d&&l(j.bottom)>l(k.top)||'bottom'===d&&l(j.top)<l(k.bottom),n=l(j.left)<l(c.left),o=l(j.right)>l(c.right),p=l(j.top)<l(c.top),q=l(j.bottom)>l(c.bottom),r='left'===d&&n||'right'===d&&o||'top'===d&&p||'bottom'===d&&q,s=-1!==['top','bottom'].indexOf(d),t=!!b.flipVariations&&(s&&'start'===f&&n||s&&'end'===f&&o||!s&&'start'===f&&p||!s&&'end'===f&&q);(m||r||t)&&(a.flipped=!0,(m||r)&&(d=g[i+1]),t&&(f=W(f)),a.placement=d+(f?'-'+f:''),a.offsets.popper=A({},a.offsets.popper,M(a.instance.popper,a.offsets.reference,a.placement)),a=P(a.instance.modifiers,a,'flip'))}),a}function aa(a,b){var c=Math.floor,d=b.x,e=b.y,f=a.offsets.popper,g=N(a.instance.modifiers,function(a){return'applyStyle'===a.name}).gpuAcceleration;void 0!==g&&console.warn('WARNING: `gpuAcceleration` option moved to `computeStyle` modifier and will not be supported in future versions of Popper.js!');var h,i,j=void 0===g?b.gpuAcceleration:g,k=m(a.instance.popper),l=C(k),n={position:f.position},o={left:c(f.left),top:c(f.top),bottom:c(f.bottom),right:c(f.right)},p='bottom'===d?'top':'bottom',q='right'===e?'left':'right',r=S('transform');if(i='bottom'==p?-l.height+o.bottom:o.top,h='right'==q?-l.width+o.right:o.left,j&&r)n[r]='translate3d('+h+'px, '+i+'px, 0)',n[p]=0,n[q]=0,n.willChange='transform';else{var s='bottom'==p?-1:1,t='right'==q?-1:1;n[p]=i*s,n[q]=h*t,n.willChange=p+', '+q}var u={"data-popper-placement":a.placement};return a.attributes=A({},u,a.attributes),a.styles=A({},n,a.styles),a.arrowStyles=A({},a.offsets.arrow,a.arrowStyles),a}function ba(a){return''!==a&&!isNaN(parseFloat(a))&&isFinite(a)}function ca(a,b){Object.keys(b).forEach(function(c){var d='';-1!==['width','height','top','right','bottom','left'].indexOf(c)&&ba(b[c])&&(d='px'),a.style[c]=b[c]+d})}function da(a,b){Object.keys(b).forEach(function(c){var d=b[c];!1===d?a.removeAttribute(c):a.setAttribute(c,b[c])})}function ea(a){return ca(a.instance.popper,a.styles),da(a.instance.popper,a.attributes),a.arrowElement&&Object.keys(a.arrowStyles).length&&ca(a.arrowElement,a.arrowStyles),a}function fa(a,b,c,d,e){var f=J(e,b,a,c.positionFixed?window.document.documentElement:void 0),g=I(c.placement,f,b,a,c.modifiers.flip.boundariesElement,c.modifiers.flip.padding);return b.setAttribute('data-popper-placement',g),ca(b,{position:c.positionFixed?'fixed':'absolute'}),c}var ga={shift:{order:100,enabled:!0,fn:U},preventOverflow:{order:300,enabled:!0,fn:V,priority:['left','right','top','bottom'],padding:5,boundariesElement:'scrollParent'},flip:{order:600,enabled:!0,fn:_,behavior:'flip',padding:5,boundariesElement:'viewport'},computeStyle:{order:850,enabled:!0,fn:aa,gpuAcceleration:!0,x:'bottom',y:'right'},applyStyle:{order:900,enabled:!0,fn:ea,onLoad:fa,gpuAcceleration:void 0}},ha={placement:'bottom',positionFixed:!1,eventsEnabled:!0,removeOnDestroy:!1,onCreate:function(){},onUpdate:function(){},modifiers:ga},ia=function(){function a(b,c){var d=this,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};x(this,a),this.scheduleUpdate=function(){return new Promise(function(a){return requestAnimationFrame(function(){return d.debouncedUpdate(a)})})};var f=this.constructor.Defaults;this.debouncedUpdate=h(this.update.bind(this)),this.options=A({},f,e),this.state={isDestroyed:!1,isCreated:!1,scrollParents:[]},this.reference=b,this.popper=c,this.options.modifiers={},Object.keys(A({},f.modifiers,e.modifiers)).forEach(function(a){d.options.modifiers[a]=A({},f.modifiers[a]||{},e.modifiers?e.modifiers[a]:{})}),this.modifiers=Object.keys(this.options.modifiers).map(function(a){return A({name:a},d.options.modifiers[a])}).sort(function(c,a){return c.order-a.order}),this.modifiers.forEach(function(a){a.enabled&&i(a.onLoad)&&a.onLoad(d.reference,d.popper,d.options,a,d.state)}),this.debouncedUpdate()}return y(a,[{key:'update',value:function(a){return Q.call(this,a)}},{key:'destroy',value:function(){return T.call(this)}}]),a}();ia.Defaults=ha;export default ia;
//# sourceMappingURL=popper-lite.min.js.map