UNPKG

@kelvininc/ui-components

Version:
1 lines 18.8 kB
const t=["top","right","bottom","left"],n=["start","end"],e=t.reduce(((t,e)=>t.concat(e,e+"-"+n[0],e+"-"+n[1])),[]),o=Math.min,r=Math.max,i=Math.round,a=Math.floor,l=t=>({x:t,y:t}),c={left:"right",right:"left",bottom:"top",top:"bottom"},s={start:"end",end:"start"};function u(t,n,e){return r(t,o(n,e))}function f(t,n){return"function"==typeof t?t(n):t}function d(t){return t.split("-")[0]}function m(t){return t.split("-")[1]}function p(t){return"x"===t?"y":"x"}function y(t){return"y"===t?"height":"width"}function h(t){return["top","bottom"].includes(d(t))?"y":"x"}function w(t){return p(h(t))}function g(t,n,e){void 0===e&&(e=!1);const o=m(t),r=w(t),i=y(r);let a="x"===r?o===(e?"end":"start")?"right":"left":"start"===o?"bottom":"top";return n.reference[i]>n.floating[i]&&(a=x(a)),[a,x(a)]}function v(t){return t.replace(/start|end/g,(t=>s[t]))}function x(t){return t.replace(/left|right|bottom|top/g,(t=>c[t]))}function b(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 A(t){const{x:n,y:e,width:o,height:r}=t;return{width:o,height:r,top:e,left:n,right:n+o,bottom:e+r,x:n,y:e}}function R(t,n,e){let{reference:o,floating:r}=t;const i=h(n),a=w(n),l=y(a),c=d(n),s="y"===i,u=o.x+o.width/2-r.width/2,f=o.y+o.height/2-r.height/2,p=o[l]/2-r[l]/2;let g;switch(c){case"top":g={x:u,y:o.y-r.height};break;case"bottom":g={x:u,y:o.y+o.height};break;case"right":g={x:o.x+o.width,y:f};break;case"left":g={x:o.x-r.width,y:f};break;default:g={x:o.x,y:o.y}}switch(m(n)){case"start":g[a]-=p*(e&&s?-1:1);break;case"end":g[a]+=p*(e&&s?-1:1)}return g}async function S(t,n){var e;void 0===n&&(n={});const{x:o,y:r,platform:i,rects:a,elements:l,strategy:c}=t,{boundary:s="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:m=!1,padding:p=0}=f(n,t),y=b(p),h=l[m?"floating"===d?"reference":"floating":d],w=A(await i.getClippingRect({element:null==(e=await(null==i.isElement?void 0:i.isElement(h)))||e?h:h.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(l.floating)),boundary:s,rootBoundary:u,strategy:c})),g="floating"===d?{x:o,y:r,width:a.floating.width,height:a.floating.height}:a.reference,v=await(null==i.getOffsetParent?void 0:i.getOffsetParent(l.floating)),x=await(null==i.isElement?void 0:i.isElement(v))&&await(null==i.getScale?void 0:i.getScale(v))||{x:1,y:1},R=A(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:g,offsetParent:v,strategy:c}):g);return{top:(w.top-R.top+y.top)/x.y,bottom:(R.bottom-w.bottom+y.bottom)/x.y,left:(w.left-R.left+y.left)/x.x,right:(R.right-w.right+y.right)/x.x}}function O(t,n){return{top:t.top-n.height,right:t.right-n.width,bottom:t.bottom-n.height,left:t.left-n.width}}function k(n){return t.some((t=>n[t]>=0))}function F(){return"undefined"!=typeof window}function P(t){return z(t)?(t.nodeName||"").toLowerCase():"#document"}function D(t){var n;return(null==t||null==(n=t.ownerDocument)?void 0:n.defaultView)||window}function T(t){var n;return null==(n=(z(t)?t.ownerDocument:t.document)||window.document)?void 0:n.documentElement}function z(t){return!!F()&&(t instanceof Node||t instanceof D(t).Node)}function C(t){return!!F()&&(t instanceof Element||t instanceof D(t).Element)}function H(t){return!!F()&&(t instanceof HTMLElement||t instanceof D(t).HTMLElement)}function M(t){return!(!F()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof D(t).ShadowRoot)}function B(t){const{overflow:n,overflowX:e,overflowY:o,display:r}=q(t);return/auto|scroll|overlay|hidden|clip/.test(n+o+e)&&!["inline","contents"].includes(r)}function L(t){return["table","td","th"].includes(P(t))}function E(t){return[":popover-open",":modal"].some((n=>{try{return t.matches(n)}catch(t){return!1}}))}function I(t){const n=N(),e=C(t)?q(t):t;return"none"!==e.transform||"none"!==e.perspective||!!e.containerType&&"normal"!==e.containerType||!n&&!!e.backdropFilter&&"none"!==e.backdropFilter||!n&&!!e.filter&&"none"!==e.filter||["transform","perspective","filter"].some((t=>(e.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(e.contain||"").includes(t)))}function N(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function j(t){return["html","body","#document"].includes(P(t))}function q(t){return D(t).getComputedStyle(t)}function W(t){return C(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function $(t){if("html"===P(t))return t;const n=t.assignedSlot||t.parentNode||M(t)&&t.host||T(t);return M(n)?n.host:n}function V(t){const n=$(t);return j(n)?t.ownerDocument?t.ownerDocument.body:t.body:H(n)&&B(n)?n:V(n)}function X(t,n,e){var o;void 0===n&&(n=[]),void 0===e&&(e=!0);const r=V(t),i=r===(null==(o=t.ownerDocument)?void 0:o.body),a=D(r);if(i){const t=Y(a);return n.concat(a,a.visualViewport||[],B(r)?r:[],t&&e?X(t):[])}return n.concat(r,X(r,[],e))}function Y(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function _(t){const n=q(t);let e=parseFloat(n.width)||0,o=parseFloat(n.height)||0;const r=H(t),a=r?t.offsetWidth:e,l=r?t.offsetHeight:o,c=i(e)!==a||i(o)!==l;return c&&(e=a,o=l),{width:e,height:o,$:c}}function G(t){return C(t)?t:t.contextElement}function J(t){const n=G(t);if(!H(n))return l(1);const e=n.getBoundingClientRect(),{width:o,height:r,$:a}=_(n);let c=(a?i(e.width):e.width)/o,s=(a?i(e.height):e.height)/r;return c&&Number.isFinite(c)||(c=1),s&&Number.isFinite(s)||(s=1),{x:c,y:s}}const K=l(0);function Q(t){const n=D(t);return N()&&n.visualViewport?{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}:K}function U(t,n,e,o){void 0===n&&(n=!1),void 0===e&&(e=!1);const r=t.getBoundingClientRect(),i=G(t);let a=l(1);n&&(o?C(o)&&(a=J(o)):a=J(t));const c=function(t,n,e){return void 0===n&&(n=!1),!(!e||n&&e!==D(t))&&n}(i,e,o)?Q(i):l(0);let s=(r.left+c.x)/a.x,u=(r.top+c.y)/a.y,f=r.width/a.x,d=r.height/a.y;if(i){const t=D(i),n=o&&C(o)?D(o):o;let e=t,r=Y(e);for(;r&&o&&n!==e;){const t=J(r),n=r.getBoundingClientRect(),o=q(r),i=n.left+(r.clientLeft+parseFloat(o.paddingLeft))*t.x,a=n.top+(r.clientTop+parseFloat(o.paddingTop))*t.y;s*=t.x,u*=t.y,f*=t.x,d*=t.y,s+=i,u+=a,e=D(r),r=Y(e)}}return A({width:f,height:d,x:s,y:u})}function Z(t,n){const e=W(t).scrollLeft;return n?n.left+e:U(T(t)).left+e}function tt(t,n,e){let o;if("viewport"===n)o=function(t,n){const e=D(t),o=T(t),r=e.visualViewport;let i=o.clientWidth,a=o.clientHeight,l=0,c=0;if(r){i=r.width,a=r.height;const t=N();(!t||t&&"fixed"===n)&&(l=r.offsetLeft,c=r.offsetTop)}return{width:i,height:a,x:l,y:c}}(t,e);else if("document"===n)o=function(t){const n=T(t),e=W(t),o=t.ownerDocument.body,i=r(n.scrollWidth,n.clientWidth,o.scrollWidth,o.clientWidth),a=r(n.scrollHeight,n.clientHeight,o.scrollHeight,o.clientHeight);let l=-e.scrollLeft+Z(t);const c=-e.scrollTop;return"rtl"===q(o).direction&&(l+=r(n.clientWidth,o.clientWidth)-i),{width:i,height:a,x:l,y:c}}(T(t));else if(C(n))o=function(t,n){const e=U(t,!0,"fixed"===n),o=e.top+t.clientTop,r=e.left+t.clientLeft,i=H(t)?J(t):l(1);return{width:t.clientWidth*i.x,height:t.clientHeight*i.y,x:r*i.x,y:o*i.y}}(n,e);else{const e=Q(t);o={...n,x:n.x-e.x,y:n.y-e.y}}return A(o)}function nt(t,n){const e=$(t);return!(e===n||!C(e)||j(e))&&("fixed"===q(e).position||nt(e,n))}function et(t,n,e){const o=H(n),r=T(n),i="fixed"===e,a=U(t,!0,i,n);let c={scrollLeft:0,scrollTop:0};const s=l(0);if(o||!o&&!i)if(("body"!==P(n)||B(r))&&(c=W(n)),o){const t=U(n,!0,i,n);s.x=t.x+n.clientLeft,s.y=t.y+n.clientTop}else r&&(s.x=Z(r));let u=0,f=0;if(r&&!o&&!i){const t=r.getBoundingClientRect();f=t.top+c.scrollTop,u=t.left+c.scrollLeft-Z(r,t)}return{x:a.left+c.scrollLeft-s.x-u,y:a.top+c.scrollTop-s.y-f,width:a.width,height:a.height}}function ot(t){return"static"===q(t).position}function rt(t,n){if(!H(t)||"fixed"===q(t).position)return null;if(n)return n(t);let e=t.offsetParent;return T(t)===e&&(e=e.ownerDocument.body),e}function it(t,n){const e=D(t);if(E(t))return e;if(!H(t)){let n=$(t);for(;n&&!j(n);){if(C(n)&&!ot(n))return n;n=$(n)}return e}let o=rt(t,n);for(;o&&L(o)&&ot(o);)o=rt(o,n);return o&&j(o)&&ot(o)&&!I(o)?e:o||function(t){let n=$(t);for(;H(n)&&!j(n);){if(I(n))return n;if(E(n))return null;n=$(n)}return null}(t)||e}const at={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:n,rect:e,offsetParent:o,strategy:r}=t;const i="fixed"===r,a=T(o),c=!!n&&E(n.floating);if(o===a||c&&i)return e;let s={scrollLeft:0,scrollTop:0},u=l(1);const f=l(0),d=H(o);if((d||!d&&!i)&&(("body"!==P(o)||B(a))&&(s=W(o)),H(o))){const t=U(o);u=J(o),f.x=t.x+o.clientLeft,f.y=t.y+o.clientTop}return{width:e.width*u.x,height:e.height*u.y,x:e.x*u.x-s.scrollLeft*u.x+f.x,y:e.y*u.y-s.scrollTop*u.y+f.y}},getDocumentElement:T,getClippingRect:function(t){let{element:n,boundary:e,rootBoundary:i,strategy:a}=t;const l=[..."clippingAncestors"===e?E(n)?[]:function(t,n){const e=n.get(t);if(e)return e;let o=X(t,[],!1).filter((t=>C(t)&&"body"!==P(t))),r=null;const i="fixed"===q(t).position;let a=i?$(t):t;for(;C(a)&&!j(a);){const n=q(a),e=I(a);e||"fixed"!==n.position||(r=null),(i?!e&&!r:!e&&"static"===n.position&&r&&["absolute","fixed"].includes(r.position)||B(a)&&!e&&nt(t,a))?o=o.filter((t=>t!==a)):r=n,a=$(a)}return n.set(t,o),o}(n,this._c):[].concat(e),i],c=l.reduce(((t,e)=>{const i=tt(n,e,a);return t.top=r(i.top,t.top),t.right=o(i.right,t.right),t.bottom=o(i.bottom,t.bottom),t.left=r(i.left,t.left),t}),tt(n,l[0],a));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}},getOffsetParent:it,getElementRects:async function(t){const n=this.getOffsetParent||it,e=this.getDimensions,o=await e(t.floating);return{reference:et(t.reference,await n(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:n,height:e}=_(t);return{width:n,height:e}},getScale:J,isElement:C,isRTL:function(t){return"rtl"===q(t).direction}};function lt(t,n,e,i){void 0===i&&(i={});const{ancestorScroll:l=!0,ancestorResize:c=!0,elementResize:s="function"==typeof ResizeObserver,layoutShift:u="function"==typeof IntersectionObserver,animationFrame:f=!1}=i,d=G(t),m=l||c?[...d?X(d):[],...X(n)]:[];m.forEach((t=>{l&&t.addEventListener("scroll",e,{passive:!0}),c&&t.addEventListener("resize",e)}));const p=d&&u?function(t,n){let e,i=null;const l=T(t);function c(){var t;clearTimeout(e),null==(t=i)||t.disconnect(),i=null}return function s(u,f){void 0===u&&(u=!1),void 0===f&&(f=1),c();const{left:d,top:m,width:p,height:y}=t.getBoundingClientRect();if(u||n(),!p||!y)return;const h={rootMargin:-a(m)+"px "+-a(l.clientWidth-(d+p))+"px "+-a(l.clientHeight-(m+y))+"px "+-a(d)+"px",threshold:r(0,o(1,f))||1};let w=!0;function g(t){const n=t[0].intersectionRatio;if(n!==f){if(!w)return s();n?s(!1,n):e=setTimeout((()=>{s(!1,1e-7)}),1e3)}w=!1}try{i=new IntersectionObserver(g,{...h,root:l.ownerDocument})}catch(t){i=new IntersectionObserver(g,h)}i.observe(t)}(!0),c}(d,e):null;let y,h=-1,w=null;s&&(w=new ResizeObserver((t=>{let[o]=t;o&&o.target===d&&w&&(w.unobserve(n),cancelAnimationFrame(h),h=requestAnimationFrame((()=>{var t;null==(t=w)||t.observe(n)}))),e()})),d&&!f&&w.observe(d),w.observe(n));let g=f?U(t):null;return f&&function n(){const o=U(t);!g||o.x===g.x&&o.y===g.y&&o.width===g.width&&o.height===g.height||e(),g=o,y=requestAnimationFrame(n)}(),e(),()=>{var t;m.forEach((t=>{l&&t.removeEventListener("scroll",e),c&&t.removeEventListener("resize",e)})),null==p||p(),null==(t=w)||t.disconnect(),w=null,f&&cancelAnimationFrame(y)}}const ct=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(n){var e,o;const{x:r,y:i,placement:a,middlewareData:l}=n,c=await async function(t,n){const{placement:e,platform:o,elements:r}=t,i=await(null==o.isRTL?void 0:o.isRTL(r.floating)),a=d(e),l=m(e),c="y"===h(e),s=["left","top"].includes(a)?-1:1,u=i&&c?-1:1,p=f(n,t);let{mainAxis:y,crossAxis:w,alignmentAxis:g}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return l&&"number"==typeof g&&(w="end"===l?-1*g:g),c?{x:w*u,y:y*s}:{x:y*s,y:w*u}}(n,t);return a===(null==(e=l.offset)?void 0:e.placement)&&null!=(o=l.arrow)&&o.alignmentOffset?{}:{x:r+c.x,y:i+c.y,data:{...c,placement:a}}}}},st=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(n){var o,r,i;const{rects:a,middlewareData:l,placement:c,platform:s,elements:u}=n,{crossAxis:p=!1,alignment:y,allowedPlacements:h=e,autoAlignment:w=!0,...x}=f(t,n),b=void 0!==y||h===e?function(t,n,e){return(t?[...e.filter((n=>m(n)===t)),...e.filter((n=>m(n)!==t))]:e.filter((t=>d(t)===t))).filter((e=>!t||m(e)===t||!!n&&v(e)!==e))}(y||null,w,h):h,A=await S(n,x),R=(null==(o=l.autoPlacement)?void 0:o.index)||0,O=b[R];if(null==O)return{};const k=g(O,a,await(null==s.isRTL?void 0:s.isRTL(u.floating)));if(c!==O)return{reset:{placement:b[0]}};const F=[A[d(O)],A[k[0]],A[k[1]]],P=[...(null==(r=l.autoPlacement)?void 0:r.overflows)||[],{placement:O,overflows:F}],D=b[R+1];if(D)return{data:{index:R+1,overflows:P},reset:{placement:D}};const T=P.map((t=>{const n=m(t.placement);return[t.placement,n&&p?t.overflows.slice(0,2).reduce(((t,n)=>t+n),0):t.overflows[0],t.overflows]})).sort(((t,n)=>t[1]-n[1])),z=(null==(i=T.filter((t=>t[2].slice(0,m(t[0])?2:3).every((t=>t<=0))))[0])?void 0:i[0])||T[0][0];return z!==c?{data:{index:R+1,overflows:P},reset:{placement:z}}:{}}}},ut=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(n){const{x:e,y:o,placement:r}=n,{mainAxis:i=!0,crossAxis:a=!1,limiter:l={fn:t=>{let{x:n,y:e}=t;return{x:n,y:e}}},...c}=f(t,n),s={x:e,y:o},m=await S(n,c),y=h(d(r)),w=p(y);let g=s[w],v=s[y];i&&(g=u(g+m["y"===w?"top":"left"],g,g-m["y"===w?"bottom":"right"])),a&&(v=u(v+m["y"===y?"top":"left"],v,v-m["y"===y?"bottom":"right"]));const x=l.fn({...n,[w]:g,[y]:v});return{...x,data:{x:x.x-e,y:x.y-o,enabled:{[w]:i,[y]:a}}}}}},ft=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(n){var e,o;const{placement:r,middlewareData:i,rects:a,initialPlacement:l,platform:c,elements:s}=n,{mainAxis:u=!0,crossAxis:p=!0,fallbackPlacements:y,fallbackStrategy:w="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:A=!0,...R}=f(t,n);if(null!=(e=i.arrow)&&e.alignmentOffset)return{};const O=d(r),k=h(l),F=d(l)===l,P=await(null==c.isRTL?void 0:c.isRTL(s.floating)),D=y||(F||!A?[x(l)]:function(t){const n=x(t);return[v(t),n,v(n)]}(l)),T="none"!==b;!y&&T&&D.push(...function(t,n,e,o){const r=m(t);let i=function(t,n,e){const o=["left","right"],r=["right","left"],i=["top","bottom"],a=["bottom","top"];switch(t){case"top":case"bottom":return e?n?r:o:n?o:r;case"left":case"right":return n?i:a;default:return[]}}(d(t),"start"===e,o);return r&&(i=i.map((t=>t+"-"+r)),n&&(i=i.concat(i.map(v)))),i}(l,A,b,P));const z=[l,...D],C=await S(n,R),H=[];let M=(null==(o=i.flip)?void 0:o.overflows)||[];if(u&&H.push(C[O]),p){const t=g(r,a,P);H.push(C[t[0]],C[t[1]])}if(M=[...M,{placement:r,overflows:H}],!H.every((t=>t<=0))){var B,L;const t=((null==(B=i.flip)?void 0:B.index)||0)+1,n=z[t];if(n)return{data:{index:t,overflows:M},reset:{placement:n}};let e=null==(L=M.filter((t=>t.overflows[0]<=0)).sort(((t,n)=>t.overflows[1]-n.overflows[1]))[0])?void 0:L.placement;if(!e)switch(w){case"bestFit":{var E;const t=null==(E=M.filter((t=>{if(T){const n=h(t.placement);return n===k||"y"===n}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,n)=>t+n),0)])).sort(((t,n)=>t[1]-n[1]))[0])?void 0:E[0];t&&(e=t);break}case"initialPlacement":e=l}if(r!==e)return{reset:{placement:e}}}return{}}}},dt=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(n){var e,i;const{placement:a,rects:l,platform:c,elements:s}=n,{apply:u=()=>{},...p}=f(t,n),y=await S(n,p),w=d(a),g=m(a),v="y"===h(a),{width:x,height:b}=l.floating;let A,R;"top"===w||"bottom"===w?(A=w,R=g===(await(null==c.isRTL?void 0:c.isRTL(s.floating))?"start":"end")?"left":"right"):(R=w,A="end"===g?"top":"bottom");const O=b-y.top-y.bottom,k=x-y.left-y.right;let F=o(b-y[A],O),P=o(x-y[R],k);if(null!=(e=n.middlewareData.shift)&&e.enabled.x&&(P=k),null!=(i=n.middlewareData.shift)&&i.enabled.y&&(F=O),!n.middlewareData.shift&&!g){const t=r(y.left,0),n=r(y.right,0),e=r(y.top,0),o=r(y.bottom,0);v?P=x-2*(0!==t||0!==n?t+n:r(y.left,y.right)):F=b-2*(0!==e||0!==o?e+o:r(y.top,y.bottom))}await u({...n,availableWidth:P,availableHeight:F});const D=await c.getDimensions(s.floating);return x!==D.width||b!==D.height?{reset:{rects:!0}}:{}}}},mt=function(t){return void 0===t&&(t={}),{name:"hide",options:t,async fn(n){const{rects:e}=n,{strategy:o="referenceHidden",...r}=f(t,n);switch(o){case"referenceHidden":{const t=O(await S(n,{...r,elementContext:"reference"}),e.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:k(t)}}}case"escaped":{const t=O(await S(n,{...r,altBoundary:!0}),e.floating);return{data:{escapedOffsets:t,escaped:k(t)}}}default:return{}}}}},pt=t=>({name:"arrow",options:t,async fn(n){const{x:e,y:r,placement:i,rects:a,platform:l,elements:c,middlewareData:s}=n,{element:d,padding:p=0}=f(t,n)||{};if(null==d)return{};const h=b(p),g={x:e,y:r},v=w(i),x=y(v),A=await l.getDimensions(d),R="y"===v,S=R?"top":"left",O=R?"bottom":"right",k=R?"clientHeight":"clientWidth",F=a.reference[x]+a.reference[v]-g[v]-a.floating[x],P=g[v]-a.reference[v],D=await(null==l.getOffsetParent?void 0:l.getOffsetParent(d));let T=D?D[k]:0;T&&await(null==l.isElement?void 0:l.isElement(D))||(T=c.floating[k]||a.floating[x]);const z=F/2-P/2,C=T/2-A[x]/2-1,H=o(h[S],C),M=o(h[O],C),B=H,L=T-A[x]-M,E=T/2-A[x]/2+z,I=u(B,E,L),N=!s.arrow&&null!=m(i)&&E!==I&&a.reference[x]/2-(E<B?H:M)-A[x]/2<0,j=N?E<B?E-B:E-L:0;return{[v]:g[v]+j,data:{[v]:I,centerOffset:E-I-j,...N&&{alignmentOffset:j}},reset:N}}}),yt=(t,n,e)=>{const o=new Map,r={platform:at,...e},i={...r.platform,_c:o};return(async(t,n,e)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:a}=e,l=i.filter(Boolean),c=await(null==a.isRTL?void 0:a.isRTL(n));let s=await a.getElementRects({reference:t,floating:n,strategy:r}),{x:u,y:f}=R(s,o,c),d=o,m={},p=0;for(let e=0;e<l.length;e++){const{name:i,fn:y}=l[e],{x:h,y:w,data:g,reset:v}=await y({x:u,y:f,initialPlacement:o,placement:d,strategy:r,middlewareData:m,rects:s,platform:a,elements:{reference:t,floating:n}});u=null!=h?h:u,f=null!=w?w:f,m={...m,[i]:{...m[i],...g}},v&&p<=50&&(p++,"object"==typeof v&&(v.placement&&(d=v.placement),v.rects&&(s=!0===v.rects?await a.getElementRects({reference:t,floating:n,strategy:r}):v.rects),({x:u,y:f}=R(s,d,c))),e=-1)}return{x:u,y:f,placement:d,strategy:r,middlewareData:m}})(t,n,{...r,platform:i})};export{st as a,ut as b,pt as c,yt as d,lt as e,ft as f,mt as h,ct as o,dt as s}