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.6 KiB

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react-dom"),e=require("react");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=r(e);function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,o)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(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 o,n,i=[],a=!0,l=!1;try{for(r=r.call(t);!(a=(o=r.next()).done)&&(i.push(o.value),!e||i.length!==e);a=!0);}catch(t){l=!0,n=t}finally{try{a||null==r.return||r.return()}finally{if(l)throw n}}return i}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return u(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 u(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 u(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,o=new Array(e);r<e;r++)o[r]=t[r];return o}function c(r,n){var a=r.element,l=r.popper,u=r.position,c=void 0===u?"bottom-center":u,f=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,S=r.onChange,C=r.active,N=void 0===C||C,T=r.portal,L=r.portalTarget,A="undefined"!=typeof window,R=A&&L instanceof HTMLElement,z=!0===h,I=l&&!0===N,X=e.useRef(),H=e.useRef(),Y=e.useRef(),D=e.useRef(),k=e.useMemo((function(){return{position:c,fixMainPosition:g,fixRelativePosition:w,offsetY:O,offsetX:E,defaultArrow:z,animations:P,zIndex:j,onChange:S}}),[c,g,w,O,E,z,P,S,j]),V=e.useCallback((function(){Y.current&&(Y.current.style.transition=""),H.current&&(H.current.parentNode.style.transition="")}),[]),W={element:i({display:"inline-block",height:"max-content"},f),arrow:i({visibility:"hidden",left:"0",top:"0",position:"absolute"},v),popper:{position:"absolute",left:"0",top:"0",willChange:"transform",visibility:"hidden",zIndex:j}};A&&!D.current&&(D.current=document.createElement("div"),D.current.data={portal:T,isValidPortalTarget:R}),e.useEffect((function(){if(T&&!R){var t=D.current;return document.body.appendChild(t),function(){return document.body.removeChild(t)}}}),[T,R]),e.useEffect((function(){if(!I)return V(),H.current.parentNode.style.visibility="hidden",void(Y.current&&(Y.current.style.visibility="hidden"));function t(t){t&&"resize"!==t.type&&!t.target.contains(X.current)||(t&&V(),s(X,H,Y,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:T,isValidPortalTarget:R},e=D.current.data;JSON.stringify(t)!==JSON.stringify(e)&&(D.current.data=t,X.current.refreshPosition())}),[T,R]);var q=o.default.createElement(o.default.Fragment,null,function(){if(!h||!I)return null;var t=o.default.createElement("div",{ref:Y,style:W.arrow}),r=e.isValidElement(h)?{children:h}:{className:"ep-arrow ".concat(M?"ep-shadow":""," ").concat(y)};return e.cloneElement(t,r)}(),o.default.createElement("div",{className:M?"ep-popper-shadow":"",style:W.popper},o.default.createElement("div",{ref:H},l)));return o.default.createElement("div",{ref:function(t){t&&(t.removeTransition=V,t.refreshPosition=function(){return setTimeout((function(){return s(X,H,Y,k,{})}),10)});if(X.current=t,n instanceof Function)return n(t);n&&(n.current=t)},className:p,style:W.element},a,T&&A?t.createPortal(q,R?L:D.current):q)}var f=e.forwardRef(c);function s(t,e,r,o,n){var a=o.position,u=o.fixMainPosition,c=o.fixRelativePosition,f=o.offsetY,s=void 0===f?0:f,m=o.offsetX,v=void 0===m?0:m,b=o.defaultArrow,y=o.animations,g=void 0===y?[]:y,w=o.zIndex,O=o.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}),S=M.scrollLeft,C=M.scrollTop,N=d(t.current,S,C),T=N.top,L=N.left,A=N.height,R=N.width,z=N.right,I=N.bottom,X=d(e.current,S,C),H=X.top,Y=X.left,D=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],o=void 0===r?0:r,n=e[2];return[o,void 0===n?0:n]}(F),_=l(J,2),B=_[0],U=_[1],$=function(t){var e=l(t.split("-"),2),r=e[0],o=void 0===r?"bottom":r,n=e[1],i=void 0===n?"center":n;"auto"===o&&(o="bottom");"auto"===i&&(i="center");var a="top"===o||"bottom"===o,u="left"===o||"right"===o;u&&("start"===i&&(i="top"),"end"===i&&(i="bottom"));a&&("start"===i&&(i="left"),"end"===i&&(i="right"));return[o,i,a,u]}(a),G=l($,4),K=G[0],Q=G[1],Z=G[2],tt=G[3],et=K,rt=function(t,e){return"translate(".concat(t,"px, ").concat(e,"px)")},ot=R-k,nt=A-D,it="left"===Q?0:"right"===Q?ot:ot/2,at=ot-it,lt="top"===Q?0:"bottom"===Q?nt:nt/2,ut=nt-lt,ct=L-Y+B,ft=T-H+U,st=0,dt=0,pt=p(t.current),ht=[],mt=r.current,vt=d(mt,S,C)||{},bt=vt.height,yt=void 0===bt?0:bt,gt=vt.width,wt=void 0===gt?0:gt,Ot=ct,Et=ft,Pt={top:"bottom",bottom:"top",left:"right",right:"left"};for(Z&&(ct+=it,ft+="top"===K?-D:A,b&&(yt=11,wt=20)),tt&&(ct+="left"===K?-k:R,ft+=lt,b&&(yt=20,wt=11));pt;)ht.push(pt),jt(d(pt,S,C)),pt=p(pt.parentNode);if(jt({top:C,bottom:C+W,left:S,right:S+q,height:W,width:q}),Z&&(ft+="bottom"===et?s:-s),tt&&(ct+="right"===et?v:-v),ct-=st,ft-=dt,E=Pt[et],mt)Z&&((j=R<k)?Ot+=R/2:Ot=ct+k/2,Ot-=wt/2,"bottom"===et&&(Et=ft,ft+=yt),"top"===et&&(Et=(ft-=yt)+D),st<0&&st-it<0&&(j?Ot+=(it-st)/2:R-it+st<k&&(Ot+=(R-it+st-k)/2)),st>0&&st+at>0&&(j?Ot-=(st+at)/2:R-st-at<k&&(Ot-=(R-st-at-k)/2))),tt&&((j=A<D)?Et+=A/2:Et=ft+D/2,Et-=yt/2,"left"===et&&(Ot=(ct-=wt)+k),"right"===et&&(Ot=ct,ct+=wt),dt<0&&dt-lt<0&&(j?Et+=(lt-dt)/2:A-lt+dt<D&&(Et+=(A-lt+dt-D)/2)),dt>0&&dt+ut>0&&(j?Et-=(dt+ut)/2:A-dt-ut<D&&(Et-=(A-dt-ut-D)/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(ct,ft);var xt={popper:{top:ft,bottom:ft+D,left:ct,right:ct+k,height:D,width:k},element:{top:T,bottom:I,left:L,right:z,height:A,width:R},arrow:{top:Et,bottom:Et+yt,left:Ot,right:Ot+wt,height:yt,width:wt,direction:E},position:et+"-"+(0!==st?"auto":Q),scroll:{scrollLeft:S,scrollTop:C},scrollableParents:ht,event:n};n||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,o=t.left,n=t.right,i=t.height,a=t.width;if(Z){var l=Math.round(T-e+A/2),f=Math.round(i/2);u||(T-(D+s+yt)<e&&l<=f&&"top"===et?(ft+=D+A,et="bottom"):I+D+s+yt>i+e&&l>=f&&"bottom"===et&&(ft-=D+A,et="top")),c||(L+it<o&&(st=h(z-wt>o?L+it-o:-R+it+wt,st)),z-at>n&&(st=h(L+wt<n?z-at-n:R-at-wt,st)))}if(tt){var d=Math.round(L-o+R/2),p=Math.round(a/2);u||(L-(k+v+wt)<o&&d<p&&"left"===et?(ct+=R+k,et="right"):z+k+v+wt>n&&d>p&&"right"===et&&(ct-=R+k,et="left")),c||(T+lt<e&&(dt=h(I-yt>e?T+lt-e:-A+lt+yt,dt)),I-ut>r&&(dt=h(T+yt<r?I-ut-r:A-ut-yt,dt)))}}}function d(t,e,r){if(t){var o=t.getBoundingClientRect(),n=o.top,i=o.left,a=o.width,l=o.height,u=n+r,c=i+e;return{top:u,bottom:u+l,left:c,right:c+a,width:a,height:l}}}function p(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:p(t.parentNode)}}function h(t,e){return Math.round(Math.abs(t))>Math.round(Math.abs(e))?t:e}exports.default=f;