UNPKG

@bodia_uz/popper.js

Version:

A kickass library to manage your poppers (lite version)

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