UNPKG

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.3 kB
"use strict";var t=require("react"),e=require("react-dom");function n(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 o=n(t),r=n(e),i=function(){return i=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},i.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;const l=Math.min,c=Math.max,s=Math.round,a=Math.floor,f=t=>({x:t,y:t}),u={left:"right",right:"left",bottom:"top",top:"bottom"},d={start:"end",end:"start"};function p(t,e,n){return c(t,l(e,n))}function m(t,e){return"function"==typeof t?t(e):t}function h(t){return t.split("-")[0]}function g(t){return t.split("-")[1]}function y(t){return"x"===t?"y":"x"}function w(t){return"y"===t?"height":"width"}function x(t){return["top","bottom"].includes(h(t))?"y":"x"}function v(t){return y(x(t))}function b(t){return t.replace(/start|end/g,(t=>d[t]))}function R(t){return t.replace(/left|right|bottom|top/g,(t=>u[t]))}function O(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 E(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 S(t,e,n){let{reference:o,floating:r}=t;const i=x(e),l=v(e),c=w(l),s=h(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(g(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}=m(e,t),h=O(p),g=c[d?"floating"===u?"reference":"floating":u],y=E(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=E(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:w,offsetParent:x,strategy:s}):w);return{top:(y.top-b.top+h.top)/v.y,bottom:(b.bottom-y.bottom+h.bottom)/v.y,left:(y.left-b.left+h.left)/v.x,right:(b.right-y.right+h.right)/v.x}}function P(){return"undefined"!=typeof window}function T(t){return C(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function D(t){var e;return null==(e=(C(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function C(t){return!!P()&&(t instanceof Node||t instanceof A(t).Node)}function k(t){return!!P()&&(t instanceof Element||t instanceof A(t).Element)}function F(t){return!!P()&&(t instanceof HTMLElement||t instanceof A(t).HTMLElement)}function M(t){return!(!P()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof A(t).ShadowRoot)}function j(t){const{overflow:e,overflowX:n,overflowY:o,display:r}=I(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!["inline","contents"].includes(r)}function z(t){return["table","td","th"].includes(T(t))}function B(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function H(t){const e=W(),n=k(t)?I(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 W(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function V(t){return["html","body","#document"].includes(T(t))}function I(t){return A(t).getComputedStyle(t)}function N(t){return k(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function q(t){if("html"===T(t))return t;const e=t.assignedSlot||t.parentNode||M(t)&&t.host||D(t);return M(e)?e.host:e}function $(t){const e=q(t);return V(e)?t.ownerDocument?t.ownerDocument.body:t.body:F(e)&&j(e)?e:$(e)}function _(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=A(r);if(i){const t=X(l);return e.concat(l,l.visualViewport||[],j(r)?r:[],t&&n?_(t):[])}return e.concat(r,_(r,[],n))}function X(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Y(t){const e=I(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=F(t),i=r?t.offsetWidth:n,l=r?t.offsetHeight:o,c=s(n)!==i||s(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(!F(e))return f(1);const n=e.getBoundingClientRect(),{width:o,height:r,$:i}=Y(e);let l=(i?s(n.width):n.width)/o,c=(i?s(n.height):n.height)/r;return l&&Number.isFinite(l)||(l=1),c&&Number.isFinite(c)||(c=1),{x:l,y:c}}const K=f(0);function Q(t){const e=A(t);return W()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:K}function U(t,e,n,o){void 0===e&&(e=!1),void 0===n&&(n=!1);const r=t.getBoundingClientRect(),i=G(t);let l=f(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!==A(t))&&e}(i,n,o)?Q(i):f(0);let s=(r.left+c.x)/l.x,a=(r.top+c.y)/l.y,u=r.width/l.x,d=r.height/l.y;if(i){const t=A(i),e=o&&k(o)?A(o):o;let n=t,r=X(n);for(;r&&o&&e!==n;){const t=J(r),e=r.getBoundingClientRect(),o=I(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,u*=t.x,d*=t.y,s+=i,a+=l,n=A(r),r=X(n)}}return E({width:u,height:d,x:s,y:a})}function Z(t,e){const n=N(t).scrollLeft;return e?e.left+n:U(D(t)).left+n}function tt(t,e,n){void 0===n&&(n=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(n?0:Z(t,o)),y:o.top+e.scrollTop}}function et(t,e,n){let o;if("viewport"===e)o=function(t,e){const n=A(t),o=D(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=W();(!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=D(t),n=N(t),o=t.ownerDocument.body,r=c(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),i=c(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-n.scrollLeft+Z(t);const s=-n.scrollTop;return"rtl"===I(o).direction&&(l+=c(e.clientWidth,o.clientWidth)-r),{width:r,height:i,x:l,y:s}}(D(t));else if(k(e))o=function(t,e){const n=U(t,!0,"fixed"===e),o=n.top+t.clientTop,r=n.left+t.clientLeft,i=F(t)?J(t):f(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 E(o)}function nt(t,e){const n=q(t);return!(n===e||!k(n)||V(n))&&("fixed"===I(n).position||nt(n,e))}function ot(t,e,n){const o=F(e),r=D(e),i="fixed"===n,l=U(t,!0,i,e);let c={scrollLeft:0,scrollTop:0};const s=f(0);if(o||!o&&!i)if(("body"!==T(e)||j(r))&&(c=N(e)),o){const t=U(e,!0,i,e);s.x=t.x+e.clientLeft,s.y=t.y+e.clientTop}else r&&(s.x=Z(r));const a=!r||o||i?f(0):tt(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 rt(t){return"static"===I(t).position}function it(t,e){if(!F(t)||"fixed"===I(t).position)return null;if(e)return e(t);let n=t.offsetParent;return D(t)===n&&(n=n.ownerDocument.body),n}function lt(t,e){const n=A(t);if(B(t))return n;if(!F(t)){let e=q(t);for(;e&&!V(e);){if(k(e)&&!rt(e))return e;e=q(e)}return n}let o=it(t,e);for(;o&&z(o)&&rt(o);)o=it(o,e);return o&&V(o)&&rt(o)&&!H(o)?n:o||function(t){let e=q(t);for(;F(e)&&!V(e);){if(H(e))return e;if(B(e))return null;e=q(e)}return null}(t)||n}const ct={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:n,offsetParent:o,strategy:r}=t;const i="fixed"===r,l=D(o),c=!!e&&B(e.floating);if(o===l||c&&i)return n;let s={scrollLeft:0,scrollTop:0},a=f(1);const u=f(0),d=F(o);if((d||!d&&!i)&&(("body"!==T(o)||j(l))&&(s=N(o)),F(o))){const t=U(o);a=J(o),u.x=t.x+o.clientLeft,u.y=t.y+o.clientTop}const p=!l||d||i?f(0):tt(l,s,!0);return{width:n.width*a.x,height:n.height*a.y,x:n.x*a.x-s.scrollLeft*a.x+u.x+p.x,y:n.y*a.y-s.scrollTop*a.y+u.y+p.y}},getDocumentElement:D,getClippingRect:function(t){let{element:e,boundary:n,rootBoundary:o,strategy:r}=t;const i=[..."clippingAncestors"===n?B(e)?[]:function(t,e){const n=e.get(t);if(n)return n;let o=_(t,[],!1).filter((t=>k(t)&&"body"!==T(t))),r=null;const i="fixed"===I(t).position;let l=i?q(t):t;for(;k(l)&&!V(l);){const e=I(l),n=H(l);n||"fixed"!==e.position||(r=null),(i?!n&&!r:!n&&"static"===e.position&&r&&["absolute","fixed"].includes(r.position)||j(l)&&!n&&nt(t,l))?o=o.filter((t=>t!==l)):r=e,l=q(l)}return e.set(t,o),o}(e,this._c):[].concat(n),o],s=i[0],a=i.reduce(((t,n)=>{const o=et(e,n,r);return t.top=c(o.top,t.top),t.right=l(o.right,t.right),t.bottom=l(o.bottom,t.bottom),t.left=c(o.left,t.left),t}),et(e,s,r));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}},getOffsetParent:lt,getElementRects:async function(t){const e=this.getOffsetParent||lt,n=this.getDimensions,o=await n(t.floating);return{reference:ot(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}=Y(t);return{width:e,height:n}},getScale:J,isElement:k,isRTL:function(t){return"rtl"===I(t).direction}};function st(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function at(t,e,n,o){void 0===o&&(o={});const{ancestorScroll:r=!0,ancestorResize:i=!0,elementResize:s="function"==typeof ResizeObserver,layoutShift:f="function"==typeof IntersectionObserver,animationFrame:u=!1}=o,d=G(t),p=r||i?[...d?_(d):[],..._(e)]:[];p.forEach((t=>{r&&t.addEventListener("scroll",n,{passive:!0}),i&&t.addEventListener("resize",n)}));const m=d&&f?function(t,e){let n,o=null;const r=D(t);function i(){var t;clearTimeout(n),null==(t=o)||t.disconnect(),o=null}return function s(f,u){void 0===f&&(f=!1),void 0===u&&(u=1),i();const d=t.getBoundingClientRect(),{left:p,top:m,width:h,height:g}=d;if(f||e(),!h||!g)return;const y={rootMargin:-a(m)+"px "+-a(r.clientWidth-(p+h))+"px "+-a(r.clientHeight-(m+g))+"px "+-a(p)+"px",threshold:c(0,l(1,u))||1};let w=!0;function x(e){const o=e[0].intersectionRatio;if(o!==u){if(!w)return s();o?s(!1,o):n=setTimeout((()=>{s(!1,1e-7)}),1e3)}1!==o||st(d,t.getBoundingClientRect())||s(),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;s&&(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?U(t):null;return u&&function e(){const o=U(t);w&&!st(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 ft=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=h(n),c=g(n),s="y"===x(n),a=["left","top"].includes(l)?-1:1,f=i&&s?-1:1,u=m(e,t);let{mainAxis:d,crossAxis:p,alignmentAxis:y}="number"==typeof u?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return c&&"number"==typeof y&&(p="end"===c?-1*y:y),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}}}}},ut=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}=m(t,e),a={x:n,y:o},f=await L(e,s),u=x(h(r)),d=y(u);let g=a[d],w=a[u];if(i){const t="y"===d?"bottom":"right";g=p(g+f["y"===d?"top":"left"],g,g-f[t])}if(l){const t="y"===u?"bottom":"right";w=p(w+f["y"===u?"top":"left"],w,w-f[t])}const v=c.fn({...e,[d]:g,[u]:w});return{...v,data:{x:v.x-n,y:v.y-o,enabled:{[d]:i,[u]:l}}}}}},dt=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:y="none",flipAlignment:O=!0,...E}=m(t,e);if(null!=(n=i.arrow)&&n.alignmentOffset)return{};const S=h(r),P=x(c),T=h(c)===c,A=await(null==s.isRTL?void 0:s.isRTL(a.floating)),D=d||(T||!O?[R(c)]:function(t){const e=R(t);return[b(t),e,b(e)]}(c)),C="none"!==y;!d&&C&&D.push(...function(t,e,n,o){const r=g(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[]}}(h(t),"start"===n,o);return r&&(i=i.map((t=>t+"-"+r)),e&&(i=i.concat(i.map(b)))),i}(c,O,y,A));const k=[c,...D],F=await L(e,E),M=[];let j=(null==(o=i.flip)?void 0:o.overflows)||[];if(f&&M.push(F[S]),u){const t=function(t,e,n){void 0===n&&(n=!1);const o=g(t),r=v(t),i=w(r);let l="x"===r?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[i]>e.floating[i]&&(l=R(l)),[l,R(l)]}(r,l,A);M.push(F[t[0]],F[t[1]])}if(j=[...j,{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=k[t];if(e)return{data:{index:t,overflows:j},reset:{placement:e}};let n=null==(B=j.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=j.filter((t=>{if(C){const e=x(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{}}}},pt=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:i,platform:c,elements:s,middlewareData:a}=e,{element:f,padding:u=0}=m(t,e)||{};if(null==f)return{};const d=O(u),h={x:n,y:o},y=v(r),x=w(y),b=await c.getDimensions(f),R="y"===y,E=R?"top":"left",S=R?"bottom":"right",L=R?"clientHeight":"clientWidth",P=i.reference[x]+i.reference[y]-h[y]-i.floating[x],T=h[y]-i.reference[y],A=await(null==c.getOffsetParent?void 0:c.getOffsetParent(f));let D=A?A[L]:0;D&&await(null==c.isElement?void 0:c.isElement(A))||(D=s.floating[L]||i.floating[x]);const C=P/2-T/2,k=D/2-b[x]/2-1,F=l(d[E],k),M=l(d[S],k),j=F,z=D-b[x]-M,B=D/2-b[x]/2+C,H=p(j,B,z),W=!a.arrow&&null!=g(r)&&B!==H&&i.reference[x]/2-(B<j?F:M)-b[x]/2<0,V=W?B<j?B-j:B-z:0;return{[y]:h[y]+V,data:{[y]:H,centerOffset:B-H-V,...W&&{alignmentOffset:V}},reset:W}}}),mt=(t,e,n)=>{const o=new Map,r={platform:ct,...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}=S(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}=S(a,d,s))),n=-1)}return{x:f,y:u,placement:d,strategy:r,middlewareData:p}})(t,e,{...r,platform:i})};var ht="undefined"!=typeof document?t.useLayoutEffect:t.useEffect;function gt(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(!gt(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)&&!gt(t[n],e[n]))return!1}return!0}return t!=t&&e!=e}function yt(t){if("undefined"==typeof window)return 1;return(t.ownerDocument.defaultView||window).devicePixelRatio||1}function wt(t,e){const n=yt(t);return Math.round(e*n)/n}function xt(t){const e=o.useRef(t);return ht((()=>{e.current=t})),e}const vt=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?pt({element:n.current,padding:o}).fn(e):{}:n?pt({element:n,padding:o}).fn(e):{};var r}}),bt=(t,e)=>({...ft(t),options:[t,e]}),Rt=(t,e)=>({...ut(t),options:[t,e]}),Ot=(t,e)=>({...vt(t),options:[t,e]});function Et(t){var n=t.children,o=t.container;return e.createPortal(n,o||document.body)}module.exports=function(e){var n,l,c=e.portalContainer,s=e.reference,a=e.children,f=e.placement,u=void 0===f?"bottom":f,d=e.offset,p=void 0===d?4:d,m=e.zIndex,h=e.arrow,g=e.arrowSize,y=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}(e,["portalContainer","reference","children","placement","offset","zIndex","arrow","arrowSize"]),w=t.useRef(null),x=function(t){void 0===t&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:i=[],platform:l,elements:{reference:c,floating:s}={},transform:a=!0,whileElementsMounted:f,open:u}=t,[d,p]=o.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[m,h]=o.useState(i);gt(m,i)||h(i);const[g,y]=o.useState(null),[w,x]=o.useState(null),v=o.useCallback((t=>{t!==E.current&&(E.current=t,y(t))}),[]),b=o.useCallback((t=>{t!==S.current&&(S.current=t,x(t))}),[]),R=c||g,O=s||w,E=o.useRef(null),S=o.useRef(null),L=o.useRef(d),P=null!=f,T=xt(f),A=xt(l),D=xt(u),C=o.useCallback((()=>{if(!E.current||!S.current)return;const t={placement:e,strategy:n,middleware:m};A.current&&(t.platform=A.current),mt(E.current,S.current,t).then((t=>{const e={...t,isPositioned:!1!==D.current};k.current&&!gt(L.current,e)&&(L.current=e,r.flushSync((()=>{p(e)})))}))}),[m,e,n,A,D]);ht((()=>{!1===u&&L.current.isPositioned&&(L.current.isPositioned=!1,p((t=>({...t,isPositioned:!1}))))}),[u]);const k=o.useRef(!1);ht((()=>(k.current=!0,()=>{k.current=!1})),[]),ht((()=>{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,P]);const F=o.useMemo((()=>({reference:E,floating:S,setReference:v,setFloating:b})),[v,b]),M=o.useMemo((()=>({reference:R,floating:O})),[R,O]),j=o.useMemo((()=>{const t={position:n,left:0,top:0};if(!M.floating)return t;const e=wt(M.floating,d.x),o=wt(M.floating,d.y);return a?{...t,transform:"translate("+e+"px, "+o+"px)",...yt(M.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:e,top:o}}),[n,a,M.floating,d.x,d.y]);return o.useMemo((()=>({...d,update:C,refs:F,elements:M,floatingStyles:j})),[d,C,F,M,j])}({placement:u,strategy:"absolute",whileElementsMounted:at,middleware:[{...dt(n),options:[n,l]},Rt(),h?Ot({element:w}):void 0,bt(h?p+Math.sqrt(2*Math.pow(g,2))/2:p)]}),v=x.floatingStyles,b=x.refs,R=x.middlewareData,O=x.placement;return t.useLayoutEffect((function(){s&&b.setReference(s)}),[s,b]),t.createElement(Et,{container:c},t.createElement("div",i({className:"headless-popper",ref:b.setFloating,style:i({zIndex:m,position:"absolute",top:0,left:0},v)},y),"function"==typeof a?a({placement:O,arrowRef:w,floatingStyles:v,arrowStyles:function(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}(O,R.arrow,g)}):a))};