You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1 lines
8.7 KiB

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react-dom"),require("react")):"function"==typeof define&&define.amd?define(["react-dom","react"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ElementPopper=e(t.ReactDOM,t.React)}(this,(function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(e);function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function a(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==r)return;var n,o,i=[],a=!0,l=!1;try{for(r=r.call(t);!(a=(n=r.next()).done)&&(i.push(n.value),!e||i.length!==e);a=!0);}catch(t){l=!0,o=t}finally{try{a||null==r.return||r.return()}finally{if(l)throw o}}return i}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return c(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return c(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function u(r,o){var a=r.element,l=r.popper,c=r.position,u=void 0===c?"bottom-center":c,s=r.containerStyle,d=r.containerClassName,p=void 0===d?"":d,h=r.arrow,m=r.arrowStyle,v=void 0===m?{}:m,b=r.arrowClassName,y=void 0===b?"":b,g=r.fixMainPosition,w=r.fixRelativePosition,O=r.offsetY,E=r.offsetX,P=r.animations,x=r.zIndex,j=void 0===x?0:x,M=r.popperShadow,T=r.onChange,S=r.active,C=void 0===S||S,N=r.portal,L=r.portalTarget,R="undefined"!=typeof window,A=R&&L instanceof HTMLElement,z=!0===h,I=l&&!0===C,X=e.useRef(),D=e.useRef(),H=e.useRef(),Y=e.useRef(),k=e.useMemo((function(){return{position:u,fixMainPosition:g,fixRelativePosition:w,offsetY:O,offsetX:E,defaultArrow:z,animations:P,zIndex:j,onChange:T}}),[u,g,w,O,E,z,P,T,j]),V=e.useCallback((function(){H.current&&(H.current.style.transition=""),D.current&&(D.current.parentNode.style.transition="")}),[]),W={element:i({display:"inline-block",height:"max-content"},s),arrow:i({visibility:"hidden",left:"0",top:"0",position:"absolute"},v),popper:{position:"absolute",left:"0",top:"0",willChange:"transform",visibility:"hidden",zIndex:j}};R&&!Y.current&&(Y.current=document.createElement("div"),Y.current.data={portal:N,isValidPortalTarget:A}),e.useEffect((function(){if(N&&!A){var t=Y.current;return document.body.appendChild(t),function(){return document.body.removeChild(t)}}}),[N,A]),e.useEffect((function(){if(!I)return V(),D.current.parentNode.style.visibility="hidden",void(H.current&&(H.current.style.visibility="hidden"));function t(t){t&&"resize"!==t.type&&!t.target.contains(X.current)||(t&&V(),f(X,D,H,k,t))}return t(),document.addEventListener("scroll",t,!0),window.addEventListener("resize",t),function(){document.removeEventListener("scroll",t,!0),window.removeEventListener("resize",t)}}),[I,k,V]),e.useEffect((function(){var t={portal:N,isValidPortalTarget:A},e=Y.current.data;JSON.stringify(t)!==JSON.stringify(e)&&(Y.current.data=t,X.current.refreshPosition())}),[N,A]);var q=n.default.createElement(n.default.Fragment,null,function(){if(!h||!I)return null;var t=n.default.createElement("div",{ref:H,style:W.arrow}),r=e.isValidElement(h)?{children:h}:{className:"ep-arrow ".concat(M?"ep-shadow":""," ").concat(y)};return e.cloneElement(t,r)}(),n.default.createElement("div",{className:M?"ep-popper-shadow":"",style:W.popper},n.default.createElement("div",{ref:D},l)));return n.default.createElement("div",{ref:function(t){t&&(t.removeTransition=V,t.refreshPosition=function(){return setTimeout((function(){return f(X,D,H,k,{})}),10)});if(X.current=t,o instanceof Function)return o(t);o&&(o.current=t)},className:p,style:W.element},a,N&&R?t.createPortal(q,A?L:Y.current):q)}function f(t,e,r,n,o){var a=n.position,c=n.fixMainPosition,u=n.fixRelativePosition,f=n.offsetY,h=void 0===f?0:f,m=n.offsetX,v=void 0===m?0:m,b=n.defaultArrow,y=n.animations,g=void 0===y?[]:y,w=n.zIndex,O=n.onChange;if(t.current&&e.current){var E,P,x,j,M=(P=void 0!==window.pageXOffset,x="CSS1Compat"===(document.compatMode||""),{scrollLeft:P?window.pageXOffset:x?document.documentElement.scrollLeft:document.body.scrollLeft,scrollTop:P?window.pageYOffset:x?document.documentElement.scrollTop:document.body.scrollTop}),T=M.scrollLeft,S=M.scrollTop,C=s(t.current,T,S),N=C.top,L=C.left,R=C.height,A=C.width,z=C.right,I=C.bottom,X=s(e.current,T,S),D=X.top,H=X.left,Y=X.height,k=X.width,V=document.documentElement,W=V.clientHeight,q=V.clientWidth,F=e.current.parentNode,J=function(t){if(!t)return[0,0];var e=l((t.style.transform.match(/translate\((.*?)px,\s(.*?)px\)/)||[]).map((function(t){return Number(t)})),3),r=e[1],n=void 0===r?0:r,o=e[2];return[n,void 0===o?0:o]}(F),B=l(J,2),U=B[0],$=B[1],G=function(t){var e=l(t.split("-"),2),r=e[0],n=void 0===r?"bottom":r,o=e[1],i=void 0===o?"center":o;"auto"===n&&(n="bottom");"auto"===i&&(i="center");var a="top"===n||"bottom"===n,c="left"===n||"right"===n;c&&("start"===i&&(i="top"),"end"===i&&(i="bottom"));a&&("start"===i&&(i="left"),"end"===i&&(i="right"));return[n,i,a,c]}(a),K=l(G,4),Q=K[0],Z=K[1],_=K[2],tt=K[3],et=Q,rt=function(t,e){return"translate(".concat(t,"px, ").concat(e,"px)")},nt=A-k,ot=R-Y,it="left"===Z?0:"right"===Z?nt:nt/2,at=nt-it,lt="top"===Z?0:"bottom"===Z?ot:ot/2,ct=ot-lt,ut=L-H+U,ft=N-D+$,st=0,dt=0,pt=d(t.current),ht=[],mt=r.current,vt=s(mt,T,S)||{},bt=vt.height,yt=void 0===bt?0:bt,gt=vt.width,wt=void 0===gt?0:gt,Ot=ut,Et=ft,Pt={top:"bottom",bottom:"top",left:"right",right:"left"};for(_&&(ut+=it,ft+="top"===Q?-Y:R,b&&(yt=11,wt=20)),tt&&(ut+="left"===Q?-k:A,ft+=lt,b&&(yt=20,wt=11));pt;)ht.push(pt),jt(s(pt,T,S)),pt=d(pt.parentNode);if(jt({top:S,bottom:S+W,left:T,right:T+q,height:W,width:q}),_&&(ft+="bottom"===et?h:-h),tt&&(ut+="right"===et?v:-v),ut-=st,ft-=dt,E=Pt[et],mt)_&&((j=A<k)?Ot+=A/2:Ot=ut+k/2,Ot-=wt/2,"bottom"===et&&(Et=ft,ft+=yt),"top"===et&&(Et=(ft-=yt)+Y),st<0&&st-it<0&&(j?Ot+=(it-st)/2:A-it+st<k&&(Ot+=(A-it+st-k)/2)),st>0&&st+at>0&&(j?Ot-=(st+at)/2:A-st-at<k&&(Ot-=(A-st-at-k)/2))),tt&&((j=R<Y)?Et+=R/2:Et=ft+Y/2,Et-=yt/2,"left"===et&&(Ot=(ut-=wt)+k),"right"===et&&(Ot=ut,ut+=wt),dt<0&&dt-lt<0&&(j?Et+=(lt-dt)/2:R-lt+dt<Y&&(Et+=(R-lt+dt-Y)/2)),dt>0&&dt+ct>0&&(j?Et-=(dt+ct)/2:R-dt-ct<Y&&(Et-=(R-dt-ct-Y)/2))),mt.setAttribute("direction",E),mt.style.height=yt+"px",mt.style.width=wt+"px",mt.style.transform=rt(Ot,Et),mt.style.visibility="visible",mt.style.zIndex=w+1;F.style.transform=rt(ut,ft);var xt={popper:{top:ft,bottom:ft+Y,left:ut,right:ut+k,height:Y,width:k},element:{top:N,bottom:I,left:L,right:z,height:R,width:A},arrow:{top:Et,bottom:Et+yt,left:Ot,right:Ot+wt,height:yt,width:wt,direction:E},position:et+"-"+(0!==st?"auto":Z),scroll:{scrollLeft:T,scrollTop:S},scrollableParents:ht,event:o};o||g.forEach((function(t){t({popper:F,arrow:mt,data:i(i({},xt),{},{getTransform:rt,mirror:Pt})})})),F.style.visibility="visible","function"==typeof O&&O(xt)}function jt(t){var e=t.top,r=t.bottom,n=t.left,o=t.right,i=t.height,a=t.width;if(_){var l=Math.round(N-e+R/2),f=Math.round(i/2);c||(N-(Y+h+yt)<e&&l<=f&&"top"===et?(ft+=Y+R,et="bottom"):I+Y+h+yt>i+e&&l>=f&&"bottom"===et&&(ft-=Y+R,et="top")),u||(L+it<n&&(st=p(z-wt>n?L+it-n:-A+it+wt,st)),z-at>o&&(st=p(L+wt<o?z-at-o:A-at-wt,st)))}if(tt){var s=Math.round(L-n+A/2),d=Math.round(a/2);c||(L-(k+v+wt)<n&&s<d&&"left"===et?(ut+=A+k,et="right"):z+k+v+wt>o&&s>d&&"right"===et&&(ut-=A+k,et="left")),u||(N+lt<e&&(dt=p(I-yt>e?N+lt-e:-R+lt+yt,dt)),I-ct>r&&(dt=p(N+yt<r?I-ct-r:R-ct-yt,dt)))}}}function s(t,e,r){if(t){var n=t.getBoundingClientRect(),o=n.top,i=n.left,a=n.width,l=n.height,c=o+r,u=i+e;return{top:c,bottom:c+l,left:u,right:u+a,width:a,height:l}}}function d(t){if(t&&"HTML"!==t.tagName){var e=window.getComputedStyle(t),r=function(t){return["auto","scroll"].includes(t)};return t.clientHeight<t.scrollHeight&&r(e.overflowX)||t.clientWidth<t.scrollWidth&&r(e.overflowY)?t:d(t.parentNode)}}function p(t,e){return Math.round(Math.abs(t))>Math.round(Math.abs(e))?t:e}return e.forwardRef(u)}));