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