@popperjs/core
Version:
Tooltip and Popover Positioning Engine
7 lines (5 loc) • 8.08 kB
JavaScript
/**
* @popperjs/core v2.4.0 - MIT License
*/
;!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).Popper={})}(this,(function(t){function e(t){return{width:(t=t.getBoundingClientRect()).width,height:t.height,top:t.top,right:t.right,bottom:t.bottom,left:t.left,x:t.left,y:t.top}}function o(t){return"[object Window]"!==t.toString()?(t=t.ownerDocument)?t.defaultView:window:t}function n(t){return{scrollLeft:(t=o(t)).pageXOffset,scrollTop:t.pageYOffset}}function r(t){return t instanceof o(t).Element||t instanceof Element}function i(t){return t instanceof o(t).HTMLElement||t instanceof HTMLElement}function f(t){return t?(t.nodeName||"").toLowerCase():null}function a(t){return(r(t)?t.ownerDocument:t.document).documentElement}function c(t){return e(a(t)).left+n(t).scrollLeft}function s(t){return o(t).getComputedStyle(t)}function u(t){return t=s(t),/auto|scroll|overlay|hidden/.test(t.overflow+t.overflowY+t.overflowX)}function d(t,r,s){void 0===s&&(s=!1);var d=a(r);t=e(t);var l={scrollLeft:0,scrollTop:0},p={x:0,y:0};return s||(("body"!==f(r)||u(d))&&(l=r!==o(r)&&i(r)?{scrollLeft:r.scrollLeft,scrollTop:r.scrollTop}:n(r)),i(r)?((p=e(r)).x+=r.clientLeft,p.y+=r.clientTop):d&&(p.x=c(d))),{x:t.left+l.scrollLeft-p.x,y:t.top+l.scrollTop-p.y,width:t.width,height:t.height}}function l(t){return"html"===f(t)?t:t.assignedSlot||t.parentNode||t.host||a(t)}function p(t,e){void 0===e&&(e=[]);var n=function t(e){return 0<=["html","body","#document"].indexOf(f(e))?e.ownerDocument.body:i(e)&&u(e)?e:t(l(e))}(t);t="body"===f(n);var r=o(n);return n=t?[r].concat(r.visualViewport||[],u(n)?n:[]):n,e=e.concat(n),t?e:e.concat(p(l(n)))}function h(t){return i(t)&&"fixed"!==s(t).position?t.offsetParent:null}function m(t){var e=o(t);for(t=h(t);t&&0<=["table","td","th"].indexOf(f(t));)t=h(t);return t&&"body"===f(t)&&"static"===s(t).position?e:t||e}function g(t){var e=new Map,o=new Set,n=[];return t.forEach((function(t){e.set(t.name,t)})),t.forEach((function(t){o.has(t.name)||function t(r){o.add(r.name),[].concat(r.requires||[],r.requiresIfExists||[]).forEach((function(n){o.has(n)||(n=e.get(n))&&t(n)})),n.push(r)}(t)})),n}function v(t){var e;return function(){return e||(e=new Promise((function(o){Promise.resolve().then((function(){e=void 0,o(t())}))}))),e}}function b(){for(var t=arguments.length,e=Array(t),o=0;o<t;o++)e[o]=arguments[o];return!e.some((function(t){return!(t&&"function"==typeof t.getBoundingClientRect)}))}function y(t){void 0===t&&(t={});var e=t.defaultModifiers,o=void 0===e?[]:e,n=void 0===(t=t.defaultOptions)?L:t;return function(t,e,i){function f(){c.forEach((function(t){return t()})),c=[]}void 0===i&&(i=n);var a={placement:"bottom",orderedModifiers:[],options:Object.assign({},L,{},n),modifiersData:{},elements:{reference:t,popper:e},attributes:{},styles:{}},c=[],s=!1,u={state:a,setOptions:function(i){return f(),a.options=Object.assign({},n,{},a.options,{},i),a.scrollParents={reference:r(t)?p(t):t.contextElement?p(t.contextElement):[],popper:p(e)},i=function(t){var e=g(t);return E.reduce((function(t,o){return t.concat(e.filter((function(t){return t.phase===o})))}),[])}(function(t){var e=t.reduce((function(t,e){var o=t[e.name];return t[e.name]=o?Object.assign({},o,{},e,{options:Object.assign({},o.options,{},e.options),data:Object.assign({},o.data,{},e.data)}):e,t}),{});return Object.keys(e).map((function(t){return e[t]}))}([].concat(o,a.options.modifiers))),a.orderedModifiers=i.filter((function(t){return t.enabled})),a.orderedModifiers.forEach((function(t){var e=t.name,o=t.options;o=void 0===o?{}:o,"function"==typeof(t=t.effect)&&(e=t({state:a,name:e,instance:u,options:o}),c.push(e||function(){}))})),u.update()},forceUpdate:function(){if(!s){var t=a.elements,e=t.reference;if(b(e,t=t.popper))for(a.rects={reference:d(e,m(t),"fixed"===a.options.strategy),popper:{x:t.offsetLeft,y:t.offsetTop,width:t.offsetWidth,height:t.offsetHeight}},a.reset=!1,a.placement=a.options.placement,a.orderedModifiers.forEach((function(t){return a.modifiersData[t.name]=Object.assign({},t.data)})),e=0;e<a.orderedModifiers.length;e++)if(!0===a.reset)a.reset=!1,e=-1;else{var o=a.orderedModifiers[e];t=o.fn;var n=o.options;n=void 0===n?{}:n,o=o.name,"function"==typeof t&&(a=t({state:a,options:n,name:o,instance:u})||a)}}},update:v((function(){return new Promise((function(t){u.forceUpdate(),t(a)}))})),destroy:function(){f(),s=!0}};return b(t,e)?(u.setOptions(i).then((function(t){!s&&i.onFirstUpdate&&i.onFirstUpdate(t)})),u):u}}function x(t){return Object.assign({},t,{left:t.x,top:t.y,right:t.x+t.width,bottom:t.y+t.height})}function w(t,r){if("viewport"===r){var f=o(t);t=f.visualViewport,r=f.innerWidth,f=f.innerHeight,t&&/iPhone|iPod|iPad/.test(navigator.platform)&&(r=t.width,f=t.height),t=x({width:r,height:f,x:0,y:0})}else i(r)?t=e(r):(t=o(f=a(t)),r=n(f),(f=d(a(f),t)).height=Math.max(f.height,t.innerHeight),f.width=Math.max(f.width,t.innerWidth),f.x=-r.scrollLeft,f.y=-r.scrollTop,t=x(f));return t}function O(t,e,n){return e="clippingParents"===e?function(t){var e=p(t),o=0<=["absolute","fixed"].indexOf(s(t).position)&&i(t)?m(t):t;return r(o)?e.filter((function(t){var e;if(e=r(t))t:if(e=!(!o.getRootNode||!o.getRootNode().host),t.contains(o))e=!0;else{if(e){e=o;do{if(e&&t.isSameNode(e)){e=!0;break t}e=e.parentNode||e.host}while(e)}e=!1}return e})):[]}(t):[].concat(e),(n=(n=[].concat(e,[n])).reduce((function(e,n){var r=w(t,n),u=o(n=i(n)?n:a(t)),d=i(n)?s(n):{};parseFloat(d.borderTopWidth);var l=parseFloat(d.borderRightWidth)||0,p=parseFloat(d.borderBottomWidth)||0,h=parseFloat(d.borderLeftWidth)||0;d="html"===f(n);var m=c(n),g=n.clientWidth+l,v=n.clientHeight+p;return d&&50<u.innerHeight-n.clientHeight&&(v=u.innerHeight-p),p=d?0:n.clientTop,l=n.clientLeft>h?l:d?u.innerWidth-g-m:n.offsetWidth-g,u=d?u.innerHeight-v:n.offsetHeight-v,n=d?m:n.clientLeft,e.top=Math.max(r.top+p,e.top),e.right=Math.min(r.right-l,e.right),e.bottom=Math.min(r.bottom-u,e.bottom),e.left=Math.max(r.left+n,e.left),e}),w(t,n[0]))).width=n.right-n.left,n.height=n.bottom-n.top,n.x=n.left,n.y=n.top,n}var M=["top","bottom","right","left"],E="beforeRead read afterRead beforeMain main afterMain beforeWrite write afterWrite".split(" "),L={placement:"bottom",modifiers:[],strategy:"absolute"},j=y();t.createPopper=j,t.detectOverflow=function(t,o){void 0===o&&(o={});var n=o;o=void 0===(o=n.placement)?t.placement:o;var i=n.boundary,f=void 0===i?"clippingParents":i,c=void 0===(i=n.rootBoundary)?"viewport":i;i=void 0===(i=n.elementContext)?"popper":i;var s=n.altBoundary,u=void 0!==s&&s;n=void 0===(n=n.padding)?0:n,n=Object.assign({},{top:0,right:0,bottom:0,left:0},{},"number"!=typeof n?n:function(t,e){return e.reduce((function(e,o){return e[o]=t,e}),{})}(n,M));var d=t.elements.reference;s=t.rects.popper,f=O(r(u=t.elements[u?"popper"===i?"reference":"popper":i])?u:u.contextElement||a(t.elements.popper),f,c),u=function(t){var e=t.reference,o=t.element,n=(t=t.placement)?t.split("-")[0]:null;t=t?t.split("-")[1]:null;var r=e.x+e.width/2-o.width/2,i=e.y+e.height/2-o.height/2;switch(n){case"top":r={x:r,y:e.y-o.height};break;case"bottom":r={x:r,y:e.y+e.height};break;case"right":r={x:e.x+e.width,y:i};break;case"left":r={x:e.x-o.width,y:i};break;default:r={x:e.x,y:e.y}}if(null!=(n=n?0<=["top","bottom"].indexOf(n)?"x":"y":null))switch(i="y"===n?"height":"width",t){case"start":r[n]=Math.floor(r[n])-Math.floor(e[i]/2-o[i]/2);break;case"end":r[n]=Math.floor(r[n])+Math.ceil(e[i]/2-o[i]/2)}return r}({reference:c=e(d),element:s,strategy:"absolute",placement:o}),s=x(Object.assign({},s,{},u)),c="popper"===i?s:c;var l={top:f.top-c.top+n.top,bottom:c.bottom-f.bottom+n.bottom,left:f.left-c.left+n.left,right:c.right-f.right+n.right};if(t=t.modifiersData.offset,"popper"===i&&t){var p=t[o];Object.keys(l).forEach((function(t){var e=0<=["right","bottom"].indexOf(t)?1:-1,o=0<=["top","bottom"].indexOf(t)?"y":"x";l[t]+=p[o]*e}))}return l},t.popperGenerator=y,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=popper-base.min.js.map