react-uni-popper
Version:
A universal, headless React popper component powered by Floating UI. Build tooltips, dropdowns, selects, comboboxes, and more — all with one flexible component.
2 lines (1 loc) • 21.4 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime"),e=require("react"),n=require("react-dom");function o(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var r=o(e),i=o(n),l=function(){return l=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},l.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;const c=Math.min,s=Math.max,a=Math.round,f=Math.floor,u=t=>({x:t,y:t}),d={left:"right",right:"left",bottom:"top",top:"bottom"},p={start:"end",end:"start"};function m(t,e,n){return s(t,c(e,n))}function h(t,e){return"function"==typeof t?t(e):t}function g(t){return t.split("-")[0]}function y(t){return t.split("-")[1]}function w(t){return"x"===t?"y":"x"}function x(t){return"y"===t?"height":"width"}function v(t){return["top","bottom"].includes(g(t))?"y":"x"}function b(t){return w(v(t))}function R(t){return t.replace(/start|end/g,(t=>p[t]))}function O(t){return t.replace(/left|right|bottom|top/g,(t=>d[t]))}function E(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}function S(t){const{x:e,y:n,width:o,height:r}=t;return{width:o,height:r,top:n,left:e,right:e+o,bottom:n+r,x:e,y:n}}function P(t,e,n){let{reference:o,floating:r}=t;const i=v(e),l=b(e),c=x(l),s=g(e),a="y"===i,f=o.x+o.width/2-r.width/2,u=o.y+o.height/2-r.height/2,d=o[c]/2-r[c]/2;let p;switch(s){case"top":p={x:f,y:o.y-r.height};break;case"bottom":p={x:f,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:u};break;case"left":p={x:o.x-r.width,y:u};break;default:p={x:o.x,y:o.y}}switch(y(e)){case"start":p[l]-=d*(n&&a?-1:1);break;case"end":p[l]+=d*(n&&a?-1:1)}return p}async function L(t,e){var n;void 0===e&&(e={});const{x:o,y:r,platform:i,rects:l,elements:c,strategy:s}=t,{boundary:a="clippingAncestors",rootBoundary:f="viewport",elementContext:u="floating",altBoundary:d=!1,padding:p=0}=h(e,t),m=E(p),g=c[d?"floating"===u?"reference":"floating":u],y=S(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(g)))||n?g:g.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(c.floating)),boundary:a,rootBoundary:f,strategy:s})),w="floating"===u?{x:o,y:r,width:l.floating.width,height:l.floating.height}:l.reference,x=await(null==i.getOffsetParent?void 0:i.getOffsetParent(c.floating)),v=await(null==i.isElement?void 0:i.isElement(x))&&await(null==i.getScale?void 0:i.getScale(x))||{x:1,y:1},b=S(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:w,offsetParent:x,strategy:s}):w);return{top:(y.top-b.top+m.top)/v.y,bottom:(b.bottom-y.bottom+m.bottom)/v.y,left:(y.left-b.left+m.left)/v.x,right:(b.right-y.right+m.right)/v.x}}function T(){return"undefined"!=typeof window}function A(t){return j(t)?(t.nodeName||"").toLowerCase():"#document"}function D(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function C(t){var e;return null==(e=(j(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function j(t){return!!T()&&(t instanceof Node||t instanceof D(t).Node)}function k(t){return!!T()&&(t instanceof Element||t instanceof D(t).Element)}function M(t){return!!T()&&(t instanceof HTMLElement||t instanceof D(t).HTMLElement)}function F(t){return!(!T()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof D(t).ShadowRoot)}function z(t){const{overflow:e,overflowX:n,overflowY:o,display:r}=N(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!["inline","contents"].includes(r)}function B(t){return["table","td","th"].includes(A(t))}function H(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function W(t){const e=V(),n=k(t)?N(t):t;return["transform","translate","scale","rotate","perspective"].some((t=>!!n[t]&&"none"!==n[t]))||!!n.containerType&&"normal"!==n.containerType||!e&&!!n.backdropFilter&&"none"!==n.backdropFilter||!e&&!!n.filter&&"none"!==n.filter||["transform","translate","scale","rotate","perspective","filter"].some((t=>(n.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(n.contain||"").includes(t)))}function V(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function I(t){return["html","body","#document"].includes(A(t))}function N(t){return D(t).getComputedStyle(t)}function q(t){return k(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function _(t){if("html"===A(t))return t;const e=t.assignedSlot||t.parentNode||F(t)&&t.host||C(t);return F(e)?e.host:e}function $(t){const e=_(t);return I(e)?t.ownerDocument?t.ownerDocument.body:t.body:M(e)&&z(e)?e:$(e)}function X(t,e,n){var o;void 0===e&&(e=[]),void 0===n&&(n=!0);const r=$(t),i=r===(null==(o=t.ownerDocument)?void 0:o.body),l=D(r);if(i){const t=Y(l);return e.concat(l,l.visualViewport||[],z(r)?r:[],t&&n?X(t):[])}return e.concat(r,X(r,[],n))}function Y(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function U(t){const e=N(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=M(t),i=r?t.offsetWidth:n,l=r?t.offsetHeight:o,c=a(n)!==i||a(o)!==l;return c&&(n=i,o=l),{width:n,height:o,$:c}}function G(t){return k(t)?t:t.contextElement}function J(t){const e=G(t);if(!M(e))return u(1);const n=e.getBoundingClientRect(),{width:o,height:r,$:i}=U(e);let l=(i?a(n.width):n.width)/o,c=(i?a(n.height):n.height)/r;return l&&Number.isFinite(l)||(l=1),c&&Number.isFinite(c)||(c=1),{x:l,y:c}}const K=u(0);function Q(t){const e=D(t);return V()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:K}function Z(t,e,n,o){void 0===e&&(e=!1),void 0===n&&(n=!1);const r=t.getBoundingClientRect(),i=G(t);let l=u(1);e&&(o?k(o)&&(l=J(o)):l=J(t));const c=function(t,e,n){return void 0===e&&(e=!1),!(!n||e&&n!==D(t))&&e}(i,n,o)?Q(i):u(0);let s=(r.left+c.x)/l.x,a=(r.top+c.y)/l.y,f=r.width/l.x,d=r.height/l.y;if(i){const t=D(i),e=o&&k(o)?D(o):o;let n=t,r=Y(n);for(;r&&o&&e!==n;){const t=J(r),e=r.getBoundingClientRect(),o=N(r),i=e.left+(r.clientLeft+parseFloat(o.paddingLeft))*t.x,l=e.top+(r.clientTop+parseFloat(o.paddingTop))*t.y;s*=t.x,a*=t.y,f*=t.x,d*=t.y,s+=i,a+=l,n=D(r),r=Y(n)}}return S({width:f,height:d,x:s,y:a})}function tt(t,e){const n=q(t).scrollLeft;return e?e.left+n:Z(C(t)).left+n}function et(t,e,n){void 0===n&&(n=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(n?0:tt(t,o)),y:o.top+e.scrollTop}}function nt(t,e,n){let o;if("viewport"===e)o=function(t,e){const n=D(t),o=C(t),r=n.visualViewport;let i=o.clientWidth,l=o.clientHeight,c=0,s=0;if(r){i=r.width,l=r.height;const t=V();(!t||t&&"fixed"===e)&&(c=r.offsetLeft,s=r.offsetTop)}return{width:i,height:l,x:c,y:s}}(t,n);else if("document"===e)o=function(t){const e=C(t),n=q(t),o=t.ownerDocument.body,r=s(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),i=s(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-n.scrollLeft+tt(t);const c=-n.scrollTop;return"rtl"===N(o).direction&&(l+=s(e.clientWidth,o.clientWidth)-r),{width:r,height:i,x:l,y:c}}(C(t));else if(k(e))o=function(t,e){const n=Z(t,!0,"fixed"===e),o=n.top+t.clientTop,r=n.left+t.clientLeft,i=M(t)?J(t):u(1);return{width:t.clientWidth*i.x,height:t.clientHeight*i.y,x:r*i.x,y:o*i.y}}(e,n);else{const n=Q(t);o={x:e.x-n.x,y:e.y-n.y,width:e.width,height:e.height}}return S(o)}function ot(t,e){const n=_(t);return!(n===e||!k(n)||I(n))&&("fixed"===N(n).position||ot(n,e))}function rt(t,e,n){const o=M(e),r=C(e),i="fixed"===n,l=Z(t,!0,i,e);let c={scrollLeft:0,scrollTop:0};const s=u(0);if(o||!o&&!i)if(("body"!==A(e)||z(r))&&(c=q(e)),o){const t=Z(e,!0,i,e);s.x=t.x+e.clientLeft,s.y=t.y+e.clientTop}else r&&(s.x=tt(r));const a=!r||o||i?u(0):et(r,c);return{x:l.left+c.scrollLeft-s.x-a.x,y:l.top+c.scrollTop-s.y-a.y,width:l.width,height:l.height}}function it(t){return"static"===N(t).position}function lt(t,e){if(!M(t)||"fixed"===N(t).position)return null;if(e)return e(t);let n=t.offsetParent;return C(t)===n&&(n=n.ownerDocument.body),n}function ct(t,e){const n=D(t);if(H(t))return n;if(!M(t)){let e=_(t);for(;e&&!I(e);){if(k(e)&&!it(e))return e;e=_(e)}return n}let o=lt(t,e);for(;o&&B(o)&&it(o);)o=lt(o,e);return o&&I(o)&&it(o)&&!W(o)?n:o||function(t){let e=_(t);for(;M(e)&&!I(e);){if(W(e))return e;if(H(e))return null;e=_(e)}return null}(t)||n}const st={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:n,offsetParent:o,strategy:r}=t;const i="fixed"===r,l=C(o),c=!!e&&H(e.floating);if(o===l||c&&i)return n;let s={scrollLeft:0,scrollTop:0},a=u(1);const f=u(0),d=M(o);if((d||!d&&!i)&&(("body"!==A(o)||z(l))&&(s=q(o)),M(o))){const t=Z(o);a=J(o),f.x=t.x+o.clientLeft,f.y=t.y+o.clientTop}const p=!l||d||i?u(0):et(l,s,!0);return{width:n.width*a.x,height:n.height*a.y,x:n.x*a.x-s.scrollLeft*a.x+f.x+p.x,y:n.y*a.y-s.scrollTop*a.y+f.y+p.y}},getDocumentElement:C,getClippingRect:function(t){let{element:e,boundary:n,rootBoundary:o,strategy:r}=t;const i=[..."clippingAncestors"===n?H(e)?[]:function(t,e){const n=e.get(t);if(n)return n;let o=X(t,[],!1).filter((t=>k(t)&&"body"!==A(t))),r=null;const i="fixed"===N(t).position;let l=i?_(t):t;for(;k(l)&&!I(l);){const e=N(l),n=W(l);n||"fixed"!==e.position||(r=null),(i?!n&&!r:!n&&"static"===e.position&&r&&["absolute","fixed"].includes(r.position)||z(l)&&!n&&ot(t,l))?o=o.filter((t=>t!==l)):r=e,l=_(l)}return e.set(t,o),o}(e,this._c):[].concat(n),o],l=i[0],a=i.reduce(((t,n)=>{const o=nt(e,n,r);return t.top=s(o.top,t.top),t.right=c(o.right,t.right),t.bottom=c(o.bottom,t.bottom),t.left=s(o.left,t.left),t}),nt(e,l,r));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}},getOffsetParent:ct,getElementRects:async function(t){const e=this.getOffsetParent||ct,n=this.getDimensions,o=await n(t.floating);return{reference:rt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:n}=U(t);return{width:e,height:n}},getScale:J,isElement:k,isRTL:function(t){return"rtl"===N(t).direction}};function at(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function ft(t,e,n,o){void 0===o&&(o={});const{ancestorScroll:r=!0,ancestorResize:i=!0,elementResize:l="function"==typeof ResizeObserver,layoutShift:a="function"==typeof IntersectionObserver,animationFrame:u=!1}=o,d=G(t),p=r||i?[...d?X(d):[],...X(e)]:[];p.forEach((t=>{r&&t.addEventListener("scroll",n,{passive:!0}),i&&t.addEventListener("resize",n)}));const m=d&&a?function(t,e){let n,o=null;const r=C(t);function i(){var t;clearTimeout(n),null==(t=o)||t.disconnect(),o=null}return function l(a,u){void 0===a&&(a=!1),void 0===u&&(u=1),i();const d=t.getBoundingClientRect(),{left:p,top:m,width:h,height:g}=d;if(a||e(),!h||!g)return;const y={rootMargin:-f(m)+"px "+-f(r.clientWidth-(p+h))+"px "+-f(r.clientHeight-(m+g))+"px "+-f(p)+"px",threshold:s(0,c(1,u))||1};let w=!0;function x(e){const o=e[0].intersectionRatio;if(o!==u){if(!w)return l();o?l(!1,o):n=setTimeout((()=>{l(!1,1e-7)}),1e3)}1!==o||at(d,t.getBoundingClientRect())||l(),w=!1}try{o=new IntersectionObserver(x,{...y,root:r.ownerDocument})}catch(t){o=new IntersectionObserver(x,y)}o.observe(t)}(!0),i}(d,n):null;let h,g=-1,y=null;l&&(y=new ResizeObserver((t=>{let[o]=t;o&&o.target===d&&y&&(y.unobserve(e),cancelAnimationFrame(g),g=requestAnimationFrame((()=>{var t;null==(t=y)||t.observe(e)}))),n()})),d&&!u&&y.observe(d),y.observe(e));let w=u?Z(t):null;return u&&function e(){const o=Z(t);w&&!at(w,o)&&n();w=o,h=requestAnimationFrame(e)}(),n(),()=>{var t;p.forEach((t=>{r&&t.removeEventListener("scroll",n),i&&t.removeEventListener("resize",n)})),null==m||m(),null==(t=y)||t.disconnect(),y=null,u&&cancelAnimationFrame(h)}}const ut=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:r,y:i,placement:l,middlewareData:c}=e,s=await async function(t,e){const{placement:n,platform:o,elements:r}=t,i=await(null==o.isRTL?void 0:o.isRTL(r.floating)),l=g(n),c=y(n),s="y"===v(n),a=["left","top"].includes(l)?-1:1,f=i&&s?-1:1,u=h(e,t);let{mainAxis:d,crossAxis:p,alignmentAxis:m}="number"==typeof u?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return c&&"number"==typeof m&&(p="end"===c?-1*m:m),s?{x:p*f,y:d*a}:{x:d*a,y:p*f}}(e,t);return l===(null==(n=c.offset)?void 0:n.placement)&&null!=(o=c.arrow)&&o.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:l}}}}},dt=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:o,placement:r}=e,{mainAxis:i=!0,crossAxis:l=!1,limiter:c={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...s}=h(t,e),a={x:n,y:o},f=await L(e,s),u=v(g(r)),d=w(u);let p=a[d],y=a[u];if(i){const t="y"===d?"bottom":"right";p=m(p+f["y"===d?"top":"left"],p,p-f[t])}if(l){const t="y"===u?"bottom":"right";y=m(y+f["y"===u?"top":"left"],y,y-f[t])}const x=c.fn({...e,[d]:p,[u]:y});return{...x,data:{x:x.x-n,y:x.y-o,enabled:{[d]:i,[u]:l}}}}}},pt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n,o;const{placement:r,middlewareData:i,rects:l,initialPlacement:c,platform:s,elements:a}=e,{mainAxis:f=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:w=!0,...E}=h(t,e);if(null!=(n=i.arrow)&&n.alignmentOffset)return{};const S=g(r),P=v(c),T=g(c)===c,A=await(null==s.isRTL?void 0:s.isRTL(a.floating)),D=d||(T||!w?[O(c)]:function(t){const e=O(t);return[R(t),e,R(e)]}(c)),C="none"!==m;!d&&C&&D.push(...function(t,e,n,o){const r=y(t);let i=function(t,e,n){const o=["left","right"],r=["right","left"],i=["top","bottom"],l=["bottom","top"];switch(t){case"top":case"bottom":return n?e?r:o:e?o:r;case"left":case"right":return e?i:l;default:return[]}}(g(t),"start"===n,o);return r&&(i=i.map((t=>t+"-"+r)),e&&(i=i.concat(i.map(R)))),i}(c,w,m,A));const j=[c,...D],k=await L(e,E),M=[];let F=(null==(o=i.flip)?void 0:o.overflows)||[];if(f&&M.push(k[S]),u){const t=function(t,e,n){void 0===n&&(n=!1);const o=y(t),r=b(t),i=x(r);let l="x"===r?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[i]>e.floating[i]&&(l=O(l)),[l,O(l)]}(r,l,A);M.push(k[t[0]],k[t[1]])}if(F=[...F,{placement:r,overflows:M}],!M.every((t=>t<=0))){var z,B;const t=((null==(z=i.flip)?void 0:z.index)||0)+1,e=j[t];if(e)return{data:{index:t,overflows:F},reset:{placement:e}};let n=null==(B=F.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:B.placement;if(!n)switch(p){case"bestFit":{var H;const t=null==(H=F.filter((t=>{if(C){const e=v(t.placement);return e===P||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:H[0];t&&(n=t);break}case"initialPlacement":n=c}if(r!==n)return{reset:{placement:n}}}return{}}}},mt=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:i,platform:l,elements:s,middlewareData:a}=e,{element:f,padding:u=0}=h(t,e)||{};if(null==f)return{};const d=E(u),p={x:n,y:o},g=b(r),w=x(g),v=await l.getDimensions(f),R="y"===g,O=R?"top":"left",S=R?"bottom":"right",P=R?"clientHeight":"clientWidth",L=i.reference[w]+i.reference[g]-p[g]-i.floating[w],T=p[g]-i.reference[g],A=await(null==l.getOffsetParent?void 0:l.getOffsetParent(f));let D=A?A[P]:0;D&&await(null==l.isElement?void 0:l.isElement(A))||(D=s.floating[P]||i.floating[w]);const C=L/2-T/2,j=D/2-v[w]/2-1,k=c(d[O],j),M=c(d[S],j),F=k,z=D-v[w]-M,B=D/2-v[w]/2+C,H=m(F,B,z),W=!a.arrow&&null!=y(r)&&B!==H&&i.reference[w]/2-(B<F?k:M)-v[w]/2<0,V=W?B<F?B-F:B-z:0;return{[g]:p[g]+V,data:{[g]:H,centerOffset:B-H-V,...W&&{alignmentOffset:V}},reset:W}}}),ht=(t,e,n)=>{const o=new Map,r={platform:st,...n},i={...r.platform,_c:o};return(async(t,e,n)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:l}=n,c=i.filter(Boolean),s=await(null==l.isRTL?void 0:l.isRTL(e));let a=await l.getElementRects({reference:t,floating:e,strategy:r}),{x:f,y:u}=P(a,o,s),d=o,p={},m=0;for(let n=0;n<c.length;n++){const{name:i,fn:h}=c[n],{x:g,y:y,data:w,reset:x}=await h({x:f,y:u,initialPlacement:o,placement:d,strategy:r,middlewareData:p,rects:a,platform:l,elements:{reference:t,floating:e}});f=null!=g?g:f,u=null!=y?y:u,p={...p,[i]:{...p[i],...w}},x&&m<=50&&(m++,"object"==typeof x&&(x.placement&&(d=x.placement),x.rects&&(a=!0===x.rects?await l.getElementRects({reference:t,floating:e,strategy:r}):x.rects),({x:f,y:u}=P(a,d,s))),n=-1)}return{x:f,y:u,placement:d,strategy:r,middlewareData:p}})(t,e,{...r,platform:i})};var gt="undefined"!=typeof document?e.useLayoutEffect:e.useEffect;function yt(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if("function"==typeof t&&t.toString()===e.toString())return!0;let n,o,r;if(t&&e&&"object"==typeof t){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(o=n;0!=o--;)if(!yt(t[o],e[o]))return!1;return!0}if(r=Object.keys(t),n=r.length,n!==Object.keys(e).length)return!1;for(o=n;0!=o--;)if(!{}.hasOwnProperty.call(e,r[o]))return!1;for(o=n;0!=o--;){const n=r[o];if(("_owner"!==n||!t.$$typeof)&&!yt(t[n],e[n]))return!1}return!0}return t!=t&&e!=e}function wt(t){if("undefined"==typeof window)return 1;return(t.ownerDocument.defaultView||window).devicePixelRatio||1}function xt(t,e){const n=wt(t);return Math.round(e*n)/n}function vt(t){const e=r.useRef(t);return gt((()=>{e.current=t})),e}const bt=t=>({name:"arrow",options:t,fn(e){const{element:n,padding:o}="function"==typeof t?t(e):t;return n&&(r=n,{}.hasOwnProperty.call(r,"current"))?null!=n.current?mt({element:n.current,padding:o}).fn(e):{}:n?mt({element:n,padding:o}).fn(e):{};var r}}),Rt=(t,e)=>({...ut(t),options:[t,e]}),Ot=(t,e)=>({...dt(t),options:[t,e]}),Et=(t,e)=>({...bt(t),options:[t,e]});function St(t,e,n){var o;void 0===e&&(e={});var r=t.split("-")[0];return(o={left:null!=e.x?"".concat(e.x,"px"):"",top:null!=e.y?"".concat(e.y,"px"):"",right:"",bottom:""})[{top:"bottom",right:"left",bottom:"top",left:"right"}[r]]="".concat(-n/2,"px"),o}function Pt(t){var e=t.children,o=t.container;return n.createPortal(e,o||document.body)}function Lt(n){var o,c,s=n.portalContainer,a=n.reference,f=n.children,u=n.placement,d=void 0===u?"bottom":u,p=n.offset,m=void 0===p?4:p,h=n.zIndex,g=n.arrow,y=n.arrowSize,w=function(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]])}return n}(n,["portalContainer","reference","children","placement","offset","zIndex","arrow","arrowSize"]),x=e.useRef(null),v=function(t){void 0===t&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:o=[],platform:l,elements:{reference:c,floating:s}={},transform:a=!0,whileElementsMounted:f,open:u}=t,[d,p]=r.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[m,h]=r.useState(o);yt(m,o)||h(o);const[g,y]=r.useState(null),[w,x]=r.useState(null),v=r.useCallback((t=>{t!==E.current&&(E.current=t,y(t))}),[]),b=r.useCallback((t=>{t!==S.current&&(S.current=t,x(t))}),[]),R=c||g,O=s||w,E=r.useRef(null),S=r.useRef(null),P=r.useRef(d),L=null!=f,T=vt(f),A=vt(l),D=vt(u),C=r.useCallback((()=>{if(!E.current||!S.current)return;const t={placement:e,strategy:n,middleware:m};A.current&&(t.platform=A.current),ht(E.current,S.current,t).then((t=>{const e={...t,isPositioned:!1!==D.current};j.current&&!yt(P.current,e)&&(P.current=e,i.flushSync((()=>{p(e)})))}))}),[m,e,n,A,D]);gt((()=>{!1===u&&P.current.isPositioned&&(P.current.isPositioned=!1,p((t=>({...t,isPositioned:!1}))))}),[u]);const j=r.useRef(!1);gt((()=>(j.current=!0,()=>{j.current=!1})),[]),gt((()=>{if(R&&(E.current=R),O&&(S.current=O),R&&O){if(T.current)return T.current(R,O,C);C()}}),[R,O,C,T,L]);const k=r.useMemo((()=>({reference:E,floating:S,setReference:v,setFloating:b})),[v,b]),M=r.useMemo((()=>({reference:R,floating:O})),[R,O]),F=r.useMemo((()=>{const t={position:n,left:0,top:0};if(!M.floating)return t;const e=xt(M.floating,d.x),o=xt(M.floating,d.y);return a?{...t,transform:"translate("+e+"px, "+o+"px)",...wt(M.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:e,top:o}}),[n,a,M.floating,d.x,d.y]);return r.useMemo((()=>({...d,update:C,refs:k,elements:M,floatingStyles:F})),[d,C,k,M,F])}({placement:d,strategy:"absolute",whileElementsMounted:ft,middleware:[{...pt(o),options:[o,c]},Ot(),g?Et({element:x}):void 0,Rt(g?m+Math.sqrt(2*Math.pow(y,2))/2:m)]}),b=v.floatingStyles,R=v.refs,O=v.middlewareData,E=v.placement;return e.useLayoutEffect((function(){a&&R.setReference(a)}),[a,R]),t.jsx(Pt,{container:s,children:t.jsx("div",l({className:"headless-popper",ref:R.setFloating,style:l({zIndex:h,position:"absolute",top:0,left:0},b)},w,{children:"function"==typeof f?f({placement:E,arrowRef:x,floatingStyles:b,arrowStyles:St(E,O.arrow,y)}):f}))})}exports.ReactUniPopper=Lt,exports.default=Lt;
;