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