Socket
Socket
Sign inDemoInstall

@floating-ui/core

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@floating-ui/core - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

124

dist/floating-ui.core.esm.development.js

@@ -123,3 +123,2 @@ function getSide(placement) {

let middlewareData = {};
const skippedMiddlewareNames = new Set();
let _debug_loop_count_ = 0;

@@ -140,7 +139,2 @@

} = middleware[i];
if (skippedMiddlewareNames.has(name)) {
continue;
}
const {

@@ -191,6 +185,2 @@ x: nextX,

} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
if (reset.skip !== false) {
skippedMiddlewareNames.add(name);
}
}

@@ -452,2 +442,7 @@

const currentPlacement = placements[currentIndex];
if (currentPlacement == null) {
return {};
}
const {

@@ -463,3 +458,2 @@ main,

reset: {
skip: false,
placement: placements[0]

@@ -484,3 +478,2 @@ }

reset: {
skip: false,
placement: nextPlacement

@@ -498,7 +491,17 @@ }

})) == null ? void 0 : _placementsSortedByLe.placement;
return {
reset: {
placement: placementThatFitsOnAllSides != null ? placementThatFitsOnAllSides : placementsSortedByLeastOverflow[0].placement
}
};
const resetPlacement = placementThatFitsOnAllSides != null ? placementThatFitsOnAllSides : placementsSortedByLeastOverflow[0].placement;
if (resetPlacement !== placement) {
return {
data: {
index: currentIndex + 1,
overflows: allOverflows
},
reset: {
placement: resetPlacement
}
};
}
return {};
}

@@ -586,3 +589,2 @@

reset: {
skip: false,
placement: nextPlacement

@@ -614,7 +616,9 @@ }

return {
reset: {
placement: resetPlacement
}
};
if (placement !== resetPlacement) {
return {
reset: {
placement: resetPlacement
}
};
}
}

@@ -707,26 +711,27 @@

const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
let crossAxisMulti = 1;
if (alignment === 'end') {
crossAxisMulti = -1;
}
if (rtl && isVertical) {
crossAxisMulti *= -1;
}
const crossAxisMulti = rtl && isVertical ? -1 : 1;
const rawValue = typeof value === 'function' ? value({ ...rects,
placement
}) : value;
const {
const isNumber = typeof rawValue === 'number'; // eslint-disable-next-line prefer-const
let {
mainAxis,
crossAxis
} = typeof rawValue === 'number' ? {
crossAxis,
alignmentAxis
} = isNumber ? {
mainAxis: rawValue,
crossAxis: 0
crossAxis: 0,
alignmentAxis: null
} : {
mainAxis: 0,
crossAxis: 0,
alignmentAxis: null,
...rawValue
};
if (alignment && typeof alignmentAxis === 'number') {
crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
}
return isVertical ? {

@@ -984,10 +989,17 @@ x: crossAxis * crossAxisMulti,

};
const prevDimensions = await platform.getDimensions(elements.floating);
apply == null ? void 0 : apply({ ...dimensions,
...rects
});
return {
reset: {
rects: true
}
};
const nextDimensions = await platform.getDimensions(elements.floating);
if (prevDimensions.width !== nextDimensions.width || prevDimensions.height !== nextDimensions.height) {
return {
reset: {
rects: true
}
};
}
return {};
}

@@ -1096,13 +1108,19 @@

return {
reset: {
rects: await platform.getElementRects({
reference: {
getBoundingClientRect
},
floating: elements.floating,
strategy
})
}
};
const resetRects = await platform.getElementRects({
reference: {
getBoundingClientRect
},
floating: elements.floating,
strategy
});
if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) {
return {
reset: {
rects: resetRects
}
};
}
return {};
}

@@ -1109,0 +1127,0 @@

@@ -123,3 +123,2 @@ function getSide(placement) {

let middlewareData = {};
const skippedMiddlewareNames = new Set();
let _debug_loop_count_ = 0;

@@ -140,7 +139,2 @@

} = middleware[i];
if (skippedMiddlewareNames.has(name)) {
continue;
}
const {

@@ -191,6 +185,2 @@ x: nextX,

} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
if (reset.skip !== false) {
skippedMiddlewareNames.add(name);
}
}

@@ -452,2 +442,7 @@

const currentPlacement = placements[currentIndex];
if (currentPlacement == null) {
return {};
}
const {

@@ -463,3 +458,2 @@ main,

reset: {
skip: false,
placement: placements[0]

@@ -484,3 +478,2 @@ }

reset: {
skip: false,
placement: nextPlacement

@@ -498,7 +491,17 @@ }

})) == null ? void 0 : _placementsSortedByLe.placement;
return {
reset: {
placement: placementThatFitsOnAllSides != null ? placementThatFitsOnAllSides : placementsSortedByLeastOverflow[0].placement
}
};
const resetPlacement = placementThatFitsOnAllSides != null ? placementThatFitsOnAllSides : placementsSortedByLeastOverflow[0].placement;
if (resetPlacement !== placement) {
return {
data: {
index: currentIndex + 1,
overflows: allOverflows
},
reset: {
placement: resetPlacement
}
};
}
return {};
}

@@ -586,3 +589,2 @@

reset: {
skip: false,
placement: nextPlacement

@@ -614,7 +616,9 @@ }

return {
reset: {
placement: resetPlacement
}
};
if (placement !== resetPlacement) {
return {
reset: {
placement: resetPlacement
}
};
}
}

@@ -707,26 +711,27 @@

const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
let crossAxisMulti = 1;
if (alignment === 'end') {
crossAxisMulti = -1;
}
if (rtl && isVertical) {
crossAxisMulti *= -1;
}
const crossAxisMulti = rtl && isVertical ? -1 : 1;
const rawValue = typeof value === 'function' ? value({ ...rects,
placement
}) : value;
const {
const isNumber = typeof rawValue === 'number'; // eslint-disable-next-line prefer-const
let {
mainAxis,
crossAxis
} = typeof rawValue === 'number' ? {
crossAxis,
alignmentAxis
} = isNumber ? {
mainAxis: rawValue,
crossAxis: 0
crossAxis: 0,
alignmentAxis: null
} : {
mainAxis: 0,
crossAxis: 0,
alignmentAxis: null,
...rawValue
};
if (alignment && typeof alignmentAxis === 'number') {
crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
}
return isVertical ? {

@@ -984,10 +989,17 @@ x: crossAxis * crossAxisMulti,

};
const prevDimensions = await platform.getDimensions(elements.floating);
apply == null ? void 0 : apply({ ...dimensions,
...rects
});
return {
reset: {
rects: true
}
};
const nextDimensions = await platform.getDimensions(elements.floating);
if (prevDimensions.width !== nextDimensions.width || prevDimensions.height !== nextDimensions.height) {
return {
reset: {
rects: true
}
};
}
return {};
}

@@ -1096,13 +1108,19 @@

return {
reset: {
rects: await platform.getElementRects({
reference: {
getBoundingClientRect
},
floating: elements.floating,
strategy
})
}
};
const resetRects = await platform.getElementRects({
reference: {
getBoundingClientRect
},
floating: elements.floating,
strategy
});
if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) {
return {
reset: {
rects: resetRects
}
};
}
return {};
}

@@ -1109,0 +1127,0 @@

@@ -1,1 +0,1 @@

function t(t){return t.split("-")[0]}function e(t){return t.split("-")[1]}function n(e){return["top","bottom"].includes(t(e))?"x":"y"}function o(t){return"y"===t?"height":"width"}function r(r,i,a){let{reference:l,floating:s}=r;const c=l.x+l.width/2-s.width/2,f=l.y+l.height/2-s.height/2,u=n(i),m=o(u),d=l[m]/2-s[m]/2,g="x"===u;let p;switch(t(i)){case"top":p={x:c,y:l.y-s.height};break;case"bottom":p={x:c,y:l.y+l.height};break;case"right":p={x:l.x+l.width,y:f};break;case"left":p={x:l.x-s.width,y:f};break;default:p={x:l.x,y:l.y}}switch(e(i)){case"start":p[u]-=d*(a&&g?-1:1);break;case"end":p[u]+=d*(a&&g?-1:1)}return p}const i=async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:a=[],platform:l}=n,s=await(null==l.isRTL?void 0:l.isRTL(e));let c=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:f,y:u}=r(c,o,s),m=o,d={};const g=new Set;for(let n=0;n<a.length;n++){const{name:p,fn:h}=a[n];if(g.has(p))continue;const{x:y,y:x,data:w,reset:v}=await h({x:f,y:u,initialPlacement:o,placement:m,strategy:i,middlewareData:d,rects:c,platform:l,elements:{reference:t,floating:e}});f=null!=y?y:f,u=null!=x?x:u,d={...d,[p]:{...d[p],...w}},v&&("object"==typeof v&&(v.placement&&(m=v.placement),v.rects&&(c=!0===v.rects?await l.getElementRects({reference:t,floating:e,strategy:i}):v.rects),({x:f,y:u}=r(c,m,s)),!1!==v.skip&&g.add(p)),n=-1)}return{x:f,y:u,placement:m,strategy:i,middlewareData:d}};function a(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 l(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}async function s(t,e){var n;void 0===e&&(e={});const{x:o,y:r,platform:i,rects:s,elements:c,strategy:f}=t,{boundary:u="clippingAncestors",rootBoundary:m="viewport",elementContext:d="floating",altBoundary:g=!1,padding:p=0}=e,h=a(p),y=c[g?"floating"===d?"reference":"floating":d],x=l(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(y)))||n?y:y.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(c.floating)),boundary:u,rootBoundary:m})),w=l(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===d?{...s.floating,x:o,y:r}:s.reference,offsetParent:await(null==i.getOffsetParent?void 0:i.getOffsetParent(c.floating)),strategy:f}):s[d]);return{top:x.top-w.top+h.top,bottom:w.bottom-x.bottom+h.bottom,left:x.left-w.left+h.left,right:w.right-x.right+h.right}}const c=Math.min,f=Math.max;function u(t,e,n){return f(t,c(e,n))}const m=t=>({name:"arrow",options:t,async fn(e){const{element:r,padding:i=0}=null!=t?t:{},{x:l,y:s,placement:c,rects:f,platform:m}=e;if(null==r)return{};const d=a(i),g={x:l,y:s},p=n(c),h=o(p),y=await m.getDimensions(r),x="y"===p?"top":"left",w="y"===p?"bottom":"right",v=f.reference[h]+f.reference[p]-g[p]-f.floating[h],b=g[p]-f.reference[p],R=await(null==m.getOffsetParent?void 0:m.getOffsetParent(r)),A=R?"y"===p?R.clientHeight||0:R.clientWidth||0:0,P=v/2-b/2,T=d[x],O=A-y[h]-d[w],k=A/2-y[h]/2+P,L=u(T,k,O);return{data:{[p]:L,centerOffset:k-L}}}}),d={left:"right",right:"left",bottom:"top",top:"bottom"};function g(t){return t.replace(/left|right|bottom|top/g,(t=>d[t]))}function p(t,r,i){void 0===i&&(i=!1);const a=e(t),l=n(t),s=o(l);let c="x"===l?a===(i?"end":"start")?"right":"left":"start"===a?"bottom":"top";return r.reference[s]>r.floating[s]&&(c=g(c)),{main:c,cross:g(c)}}const h={start:"end",end:"start"};function y(t){return t.replace(/start|end/g,(t=>h[t]))}const x=["top","right","bottom","left"],w=x.reduce(((t,e)=>t.concat(e,e+"-start",e+"-end")),[]);const v=function(n){return void 0===n&&(n={}),{name:"autoPlacement",options:n,async fn(o){var r,i,a,l,c;const{x:f,y:u,rects:m,middlewareData:d,placement:g,platform:h,elements:x}=o,{alignment:v=null,allowedPlacements:b=w,autoAlignment:R=!0,...A}=n,P=function(n,o,r){return(n?[...r.filter((t=>e(t)===n)),...r.filter((t=>e(t)!==n))]:r.filter((e=>t(e)===e))).filter((t=>!n||e(t)===n||!!o&&y(t)!==t))}(v,R,b),T=await s(o,A),O=null!=(r=null==(i=d.autoPlacement)?void 0:i.index)?r:0,k=P[O],{main:L,cross:D}=p(k,m,await(null==h.isRTL?void 0:h.isRTL(x.floating)));if(g!==k)return{x:f,y:u,reset:{skip:!1,placement:P[0]}};const E=[T[t(k)],T[L],T[D]],C=[...null!=(a=null==(l=d.autoPlacement)?void 0:l.overflows)?a:[],{placement:k,overflows:E}],B=P[O+1];if(B)return{data:{index:O+1,overflows:C},reset:{skip:!1,placement:B}};const H=C.slice().sort(((t,e)=>t.overflows[0]-e.overflows[0])),V=null==(c=H.find((t=>{let{overflows:e}=t;return e.every((t=>t<=0))})))?void 0:c.placement;return{reset:{placement:null!=V?V:H[0].placement}}}}};const b=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(n){var o;const{placement:r,middlewareData:i,rects:a,initialPlacement:l,platform:c,elements:f}=n,{mainAxis:u=!0,crossAxis:m=!0,fallbackPlacements:d,fallbackStrategy:h="bestFit",flipAlignment:x=!0,...w}=e,v=t(r),b=d||(v===l||!x?[g(l)]:function(t){const e=g(t);return[y(t),e,y(e)]}(l)),R=[l,...b],A=await s(n,w),P=[];let T=(null==(o=i.flip)?void 0:o.overflows)||[];if(u&&P.push(A[v]),m){const{main:t,cross:e}=p(r,a,await(null==c.isRTL?void 0:c.isRTL(f.floating)));P.push(A[t],A[e])}if(T=[...T,{placement:r,overflows:P}],!P.every((t=>t<=0))){var O,k;const t=(null!=(O=null==(k=i.flip)?void 0:k.index)?O:0)+1,e=R[t];if(e)return{data:{index:t,overflows:T},reset:{skip:!1,placement:e}};let n="bottom";switch(h){case"bestFit":{var L;const t=null==(L=T.slice().sort(((t,e)=>t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)-e.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)))[0])?void 0:L.placement;t&&(n=t);break}case"initialPlacement":n=l}return{reset:{placement:n}}}return{}}}};function R(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function A(t){return x.some((e=>t[e]>=0))}const P=function(t){let{strategy:e="referenceHidden",...n}=void 0===t?{}:t;return{name:"hide",async fn(t){const{rects:o}=t;switch(e){case"referenceHidden":{const e=R(await s(t,{...n,elementContext:"reference"}),o.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:A(e)}}}case"escaped":{const e=R(await s(t,{...n,altBoundary:!0}),o.floating);return{data:{escapedOffsets:e,escaped:A(e)}}}default:return{}}}}};const T=function(o){return void 0===o&&(o=0),{name:"offset",options:o,async fn(r){const{x:i,y:a,placement:l,rects:s,platform:c,elements:f}=r,u=function(o,r,i,a){void 0===a&&(a=!1);const l=t(o),s=e(o),c="x"===n(o),f=["left","top"].includes(l)?-1:1;let u=1;"end"===s&&(u=-1),a&&c&&(u*=-1);const m="function"==typeof i?i({...r,placement:o}):i,{mainAxis:d,crossAxis:g}="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};return c?{x:g*u,y:d*f}:{x:d*f,y:g*u}}(l,s,o,await(null==c.isRTL?void 0:c.isRTL(f.floating)));return{x:i+u.x,y:a+u.y,data:u}}}};function O(t){return"x"===t?"y":"x"}const k=function(e){return void 0===e&&(e={}),{name:"shift",options:e,async fn(o){const{x:r,y:i,placement:a}=o,{mainAxis:l=!0,crossAxis:c=!1,limiter:f={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...m}=e,d={x:r,y:i},g=await s(o,m),p=n(t(a)),h=O(p);let y=d[p],x=d[h];if(l){const t="y"===p?"bottom":"right";y=u(y+g["y"===p?"top":"left"],y,y-g[t])}if(c){const t="y"===h?"bottom":"right";x=u(x+g["y"===h?"top":"left"],x,x-g[t])}const w=f.fn({...o,[p]:y,[h]:x});return{...w,data:{x:w.x-r,y:w.y-i}}}}},L=function(e){return void 0===e&&(e={}),{options:e,fn(o){const{x:r,y:i,placement:a,rects:l,middlewareData:s}=o,{offset:c=0,mainAxis:f=!0,crossAxis:u=!0}=e,m={x:r,y:i},d=n(a),g=O(d);let p=m[d],h=m[g];const y="function"==typeof c?c({...l,placement:a}):c,x="number"==typeof y?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(f){const t="y"===d?"height":"width",e=l.reference[d]-l.floating[t]+x.mainAxis,n=l.reference[d]+l.reference[t]-x.mainAxis;p<e?p=e:p>n&&(p=n)}if(u){var w,v,b,R;const e="y"===d?"width":"height",n=["top","left"].includes(t(a)),o=l.reference[g]-l.floating[e]+(n&&null!=(w=null==(v=s.offset)?void 0:v[g])?w:0)+(n?0:x.crossAxis),r=l.reference[g]+l.reference[e]+(n?0:null!=(b=null==(R=s.offset)?void 0:R[g])?b:0)-(n?x.crossAxis:0);h<o?h=o:h>r&&(h=r)}return{[d]:p,[g]:h}}}},D=function(n){return void 0===n&&(n={}),{name:"size",options:n,async fn(o){const{placement:r,rects:i,platform:a,elements:l}=o,{apply:c,...u}=n,m=await s(o,u),d=t(r),g=e(r);let p,h;"top"===d||"bottom"===d?(p=d,h=g===(await(null==a.isRTL?void 0:a.isRTL(l.floating))?"start":"end")?"left":"right"):(h=d,p="end"===g?"top":"bottom");const y=f(m.left,0),x=f(m.right,0),w=f(m.top,0),v=f(m.bottom,0),b={height:i.floating.height-(["left","right"].includes(r)?2*(0!==w||0!==v?w+v:f(m.top,m.bottom)):m[p]),width:i.floating.width-(["top","bottom"].includes(r)?2*(0!==y||0!==x?y+x:f(m.left,m.right)):m[h])};return null==c||c({...b,...i}),{reset:{rects:!0}}}}},E=function(e){return void 0===e&&(e={}),{name:"inline",options:e,async fn(o){var r;const{placement:i,elements:s,rects:u,platform:m,strategy:d}=o,{padding:g=2,x:p,y:h}=e,y=l(m.convertOffsetParentRelativeRectToViewportRelativeRect?await m.convertOffsetParentRelativeRectToViewportRelativeRect({rect:u.reference,offsetParent:await(null==m.getOffsetParent?void 0:m.getOffsetParent(s.floating)),strategy:d}):u.reference),x=null!=(r=await(null==m.getClientRects?void 0:m.getClientRects(s.reference)))?r:[],w=a(g);return{reset:{rects:await m.getElementRects({reference:{getBoundingClientRect:function(){var e;if(2===x.length&&x[0].left>x[1].right&&null!=p&&null!=h)return null!=(e=x.find((t=>p>t.left-w.left&&p<t.right+w.right&&h>t.top-w.top&&h<t.bottom+w.bottom)))?e:y;if(x.length>=2){if("x"===n(i)){const e=x[0],n=x[x.length-1],o="top"===t(i),r=e.top,a=n.bottom,l=o?e.left:n.left,s=o?e.right:n.right;return{top:r,bottom:a,left:l,right:s,width:s-l,height:a-r,x:l,y:r}}const e="left"===t(i),o=f(...x.map((t=>t.right))),r=c(...x.map((t=>t.left))),a=x.filter((t=>e?t.left===r:t.right===o)),l=a[0].top,s=a[a.length-1].bottom;return{top:l,bottom:s,left:r,right:o,width:o-r,height:s-l,x:r,y:l}}return y}},floating:s.floating,strategy:d})}}}}};export{m as arrow,v as autoPlacement,i as computePosition,s as detectOverflow,b as flip,P as hide,E as inline,L as limitShift,T as offset,l as rectToClientRect,k as shift,D as size};
function t(t){return t.split("-")[0]}function e(t){return t.split("-")[1]}function n(e){return["top","bottom"].includes(t(e))?"x":"y"}function r(t){return"y"===t?"height":"width"}function i(i,o,l){let{reference:a,floating:s}=i;const c=a.x+a.width/2-s.width/2,f=a.y+a.height/2-s.height/2,u=n(o),m=r(u),g=a[m]/2-s[m]/2,d="x"===u;let p;switch(t(o)){case"top":p={x:c,y:a.y-s.height};break;case"bottom":p={x:c,y:a.y+a.height};break;case"right":p={x:a.x+a.width,y:f};break;case"left":p={x:a.x-s.width,y:f};break;default:p={x:a.x,y:a.y}}switch(e(o)){case"start":p[u]-=g*(l&&d?-1:1);break;case"end":p[u]+=g*(l&&d?-1:1)}return p}const o=async(t,e,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:l=[],platform:a}=n,s=await(null==a.isRTL?void 0:a.isRTL(e));let c=await a.getElementRects({reference:t,floating:e,strategy:o}),{x:f,y:u}=i(c,r,s),m=r,g={};for(let n=0;n<l.length;n++){const{name:d,fn:p}=l[n],{x:h,y:y,data:x,reset:w}=await p({x:f,y:u,initialPlacement:r,placement:m,strategy:o,middlewareData:g,rects:c,platform:a,elements:{reference:t,floating:e}});f=null!=h?h:f,u=null!=y?y:u,g={...g,[d]:{...g[d],...x}},w&&("object"==typeof w&&(w.placement&&(m=w.placement),w.rects&&(c=!0===w.rects?await a.getElementRects({reference:t,floating:e,strategy:o}):w.rects),({x:f,y:u}=i(c,m,s))),n=-1)}return{x:f,y:u,placement:m,strategy:o,middlewareData:g}};function l(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){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}async function s(t,e){var n;void 0===e&&(e={});const{x:r,y:i,platform:o,rects:s,elements:c,strategy:f}=t,{boundary:u="clippingAncestors",rootBoundary:m="viewport",elementContext:g="floating",altBoundary:d=!1,padding:p=0}=e,h=l(p),y=c[d?"floating"===g?"reference":"floating":g],x=a(await o.getClippingRect({element:null==(n=await(null==o.isElement?void 0:o.isElement(y)))||n?y:y.contextElement||await(null==o.getDocumentElement?void 0:o.getDocumentElement(c.floating)),boundary:u,rootBoundary:m})),w=a(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===g?{...s.floating,x:r,y:i}:s.reference,offsetParent:await(null==o.getOffsetParent?void 0:o.getOffsetParent(c.floating)),strategy:f}):s[g]);return{top:x.top-w.top+h.top,bottom:w.bottom-x.bottom+h.bottom,left:x.left-w.left+h.left,right:w.right-x.right+h.right}}const c=Math.min,f=Math.max;function u(t,e,n){return f(t,c(e,n))}const m=t=>({name:"arrow",options:t,async fn(e){const{element:i,padding:o=0}=null!=t?t:{},{x:a,y:s,placement:c,rects:f,platform:m}=e;if(null==i)return{};const g=l(o),d={x:a,y:s},p=n(c),h=r(p),y=await m.getDimensions(i),x="y"===p?"top":"left",w="y"===p?"bottom":"right",v=f.reference[h]+f.reference[p]-d[p]-f.floating[h],b=d[p]-f.reference[p],R=await(null==m.getOffsetParent?void 0:m.getOffsetParent(i)),A=R?"y"===p?R.clientHeight||0:R.clientWidth||0:0,P=v/2-b/2,T=g[x],O=A-y[h]-g[w],D=A/2-y[h]/2+P,L=u(T,D,O);return{data:{[p]:L,centerOffset:D-L}}}}),g={left:"right",right:"left",bottom:"top",top:"bottom"};function d(t){return t.replace(/left|right|bottom|top/g,(t=>g[t]))}function p(t,i,o){void 0===o&&(o=!1);const l=e(t),a=n(t),s=r(a);let c="x"===a?l===(o?"end":"start")?"right":"left":"start"===l?"bottom":"top";return i.reference[s]>i.floating[s]&&(c=d(c)),{main:c,cross:d(c)}}const h={start:"end",end:"start"};function y(t){return t.replace(/start|end/g,(t=>h[t]))}const x=["top","right","bottom","left"],w=x.reduce(((t,e)=>t.concat(e,e+"-start",e+"-end")),[]);const v=function(n){return void 0===n&&(n={}),{name:"autoPlacement",options:n,async fn(r){var i,o,l,a,c;const{x:f,y:u,rects:m,middlewareData:g,placement:d,platform:h,elements:x}=r,{alignment:v=null,allowedPlacements:b=w,autoAlignment:R=!0,...A}=n,P=function(n,r,i){return(n?[...i.filter((t=>e(t)===n)),...i.filter((t=>e(t)!==n))]:i.filter((e=>t(e)===e))).filter((t=>!n||e(t)===n||!!r&&y(t)!==t))}(v,R,b),T=await s(r,A),O=null!=(i=null==(o=g.autoPlacement)?void 0:o.index)?i:0,D=P[O];if(null==D)return{};const{main:L,cross:k}=p(D,m,await(null==h.isRTL?void 0:h.isRTL(x.floating)));if(d!==D)return{x:f,y:u,reset:{placement:P[0]}};const E=[T[t(D)],T[L],T[k]],C=[...null!=(l=null==(a=g.autoPlacement)?void 0:a.overflows)?l:[],{placement:D,overflows:E}],B=P[O+1];if(B)return{data:{index:O+1,overflows:C},reset:{placement:B}};const H=C.slice().sort(((t,e)=>t.overflows[0]-e.overflows[0])),V=null==(c=H.find((t=>{let{overflows:e}=t;return e.every((t=>t<=0))})))?void 0:c.placement,F=null!=V?V:H[0].placement;return F!==d?{data:{index:O+1,overflows:C},reset:{placement:F}}:{}}}};const b=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(n){var r;const{placement:i,middlewareData:o,rects:l,initialPlacement:a,platform:c,elements:f}=n,{mainAxis:u=!0,crossAxis:m=!0,fallbackPlacements:g,fallbackStrategy:h="bestFit",flipAlignment:x=!0,...w}=e,v=t(i),b=g||(v===a||!x?[d(a)]:function(t){const e=d(t);return[y(t),e,y(e)]}(a)),R=[a,...b],A=await s(n,w),P=[];let T=(null==(r=o.flip)?void 0:r.overflows)||[];if(u&&P.push(A[v]),m){const{main:t,cross:e}=p(i,l,await(null==c.isRTL?void 0:c.isRTL(f.floating)));P.push(A[t],A[e])}if(T=[...T,{placement:i,overflows:P}],!P.every((t=>t<=0))){var O,D;const t=(null!=(O=null==(D=o.flip)?void 0:D.index)?O:0)+1,e=R[t];if(e)return{data:{index:t,overflows:T},reset:{placement:e}};let n="bottom";switch(h){case"bestFit":{var L;const t=null==(L=T.slice().sort(((t,e)=>t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)-e.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)))[0])?void 0:L.placement;t&&(n=t);break}case"initialPlacement":n=a}if(i!==n)return{reset:{placement:n}}}return{}}}};function R(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function A(t){return x.some((e=>t[e]>=0))}const P=function(t){let{strategy:e="referenceHidden",...n}=void 0===t?{}:t;return{name:"hide",async fn(t){const{rects:r}=t;switch(e){case"referenceHidden":{const e=R(await s(t,{...n,elementContext:"reference"}),r.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:A(e)}}}case"escaped":{const e=R(await s(t,{...n,altBoundary:!0}),r.floating);return{data:{escapedOffsets:e,escaped:A(e)}}}default:return{}}}}};const T=function(r){return void 0===r&&(r=0),{name:"offset",options:r,async fn(i){const{x:o,y:l,placement:a,rects:s,platform:c,elements:f}=i,u=function(r,i,o,l){void 0===l&&(l=!1);const a=t(r),s=e(r),c="x"===n(r),f=["left","top"].includes(a)?-1:1,u=l&&c?-1:1,m="function"==typeof o?o({...i,placement:r}):o,g="number"==typeof m;let{mainAxis:d,crossAxis:p,alignmentAxis:h}=g?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...m};return s&&"number"==typeof h&&(p="end"===s?-1*h:h),c?{x:p*u,y:d*f}:{x:d*f,y:p*u}}(a,s,r,await(null==c.isRTL?void 0:c.isRTL(f.floating)));return{x:o+u.x,y:l+u.y,data:u}}}};function O(t){return"x"===t?"y":"x"}const D=function(e){return void 0===e&&(e={}),{name:"shift",options:e,async fn(r){const{x:i,y:o,placement:l}=r,{mainAxis:a=!0,crossAxis:c=!1,limiter:f={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...m}=e,g={x:i,y:o},d=await s(r,m),p=n(t(l)),h=O(p);let y=g[p],x=g[h];if(a){const t="y"===p?"bottom":"right";y=u(y+d["y"===p?"top":"left"],y,y-d[t])}if(c){const t="y"===h?"bottom":"right";x=u(x+d["y"===h?"top":"left"],x,x-d[t])}const w=f.fn({...r,[p]:y,[h]:x});return{...w,data:{x:w.x-i,y:w.y-o}}}}},L=function(e){return void 0===e&&(e={}),{options:e,fn(r){const{x:i,y:o,placement:l,rects:a,middlewareData:s}=r,{offset:c=0,mainAxis:f=!0,crossAxis:u=!0}=e,m={x:i,y:o},g=n(l),d=O(g);let p=m[g],h=m[d];const y="function"==typeof c?c({...a,placement:l}):c,x="number"==typeof y?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(f){const t="y"===g?"height":"width",e=a.reference[g]-a.floating[t]+x.mainAxis,n=a.reference[g]+a.reference[t]-x.mainAxis;p<e?p=e:p>n&&(p=n)}if(u){var w,v,b,R;const e="y"===g?"width":"height",n=["top","left"].includes(t(l)),r=a.reference[d]-a.floating[e]+(n&&null!=(w=null==(v=s.offset)?void 0:v[d])?w:0)+(n?0:x.crossAxis),i=a.reference[d]+a.reference[e]+(n?0:null!=(b=null==(R=s.offset)?void 0:R[d])?b:0)-(n?x.crossAxis:0);h<r?h=r:h>i&&(h=i)}return{[g]:p,[d]:h}}}},k=function(n){return void 0===n&&(n={}),{name:"size",options:n,async fn(r){const{placement:i,rects:o,platform:l,elements:a}=r,{apply:c,...u}=n,m=await s(r,u),g=t(i),d=e(i);let p,h;"top"===g||"bottom"===g?(p=g,h=d===(await(null==l.isRTL?void 0:l.isRTL(a.floating))?"start":"end")?"left":"right"):(h=g,p="end"===d?"top":"bottom");const y=f(m.left,0),x=f(m.right,0),w=f(m.top,0),v=f(m.bottom,0),b={height:o.floating.height-(["left","right"].includes(i)?2*(0!==w||0!==v?w+v:f(m.top,m.bottom)):m[p]),width:o.floating.width-(["top","bottom"].includes(i)?2*(0!==y||0!==x?y+x:f(m.left,m.right)):m[h])},R=await l.getDimensions(a.floating);null==c||c({...b,...o});const A=await l.getDimensions(a.floating);return R.width!==A.width||R.height!==A.height?{reset:{rects:!0}}:{}}}},E=function(e){return void 0===e&&(e={}),{name:"inline",options:e,async fn(r){var i;const{placement:o,elements:s,rects:u,platform:m,strategy:g}=r,{padding:d=2,x:p,y:h}=e,y=a(m.convertOffsetParentRelativeRectToViewportRelativeRect?await m.convertOffsetParentRelativeRectToViewportRelativeRect({rect:u.reference,offsetParent:await(null==m.getOffsetParent?void 0:m.getOffsetParent(s.floating)),strategy:g}):u.reference),x=null!=(i=await(null==m.getClientRects?void 0:m.getClientRects(s.reference)))?i:[],w=l(d);const v=await m.getElementRects({reference:{getBoundingClientRect:function(){var e;if(2===x.length&&x[0].left>x[1].right&&null!=p&&null!=h)return null!=(e=x.find((t=>p>t.left-w.left&&p<t.right+w.right&&h>t.top-w.top&&h<t.bottom+w.bottom)))?e:y;if(x.length>=2){if("x"===n(o)){const e=x[0],n=x[x.length-1],r="top"===t(o),i=e.top,l=n.bottom,a=r?e.left:n.left,s=r?e.right:n.right;return{top:i,bottom:l,left:a,right:s,width:s-a,height:l-i,x:a,y:i}}const e="left"===t(o),r=f(...x.map((t=>t.right))),i=c(...x.map((t=>t.left))),l=x.filter((t=>e?t.left===i:t.right===r)),a=l[0].top,s=l[l.length-1].bottom;return{top:a,bottom:s,left:i,right:r,width:r-i,height:s-a,x:i,y:a}}return y}},floating:s.floating,strategy:g});return u.reference.x!==v.reference.x||u.reference.y!==v.reference.y||u.reference.width!==v.reference.width||u.reference.height!==v.reference.height?{reset:{rects:v}}:{}}}};export{m as arrow,v as autoPlacement,o as computePosition,s as detectOverflow,b as flip,P as hide,E as inline,L as limitShift,T as offset,a as rectToClientRect,D as shift,k as size};

@@ -129,3 +129,2 @@ (function (global, factory) {

let middlewareData = {};
const skippedMiddlewareNames = new Set();
let _debug_loop_count_ = 0;

@@ -146,7 +145,2 @@

} = middleware[i];
if (skippedMiddlewareNames.has(name)) {
continue;
}
const {

@@ -197,6 +191,2 @@ x: nextX,

} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
if (reset.skip !== false) {
skippedMiddlewareNames.add(name);
}
}

@@ -458,2 +448,7 @@

const currentPlacement = placements[currentIndex];
if (currentPlacement == null) {
return {};
}
const {

@@ -469,3 +464,2 @@ main,

reset: {
skip: false,
placement: placements[0]

@@ -490,3 +484,2 @@ }

reset: {
skip: false,
placement: nextPlacement

@@ -504,7 +497,17 @@ }

})) == null ? void 0 : _placementsSortedByLe.placement;
return {
reset: {
placement: placementThatFitsOnAllSides != null ? placementThatFitsOnAllSides : placementsSortedByLeastOverflow[0].placement
}
};
const resetPlacement = placementThatFitsOnAllSides != null ? placementThatFitsOnAllSides : placementsSortedByLeastOverflow[0].placement;
if (resetPlacement !== placement) {
return {
data: {
index: currentIndex + 1,
overflows: allOverflows
},
reset: {
placement: resetPlacement
}
};
}
return {};
}

@@ -592,3 +595,2 @@

reset: {
skip: false,
placement: nextPlacement

@@ -620,7 +622,9 @@ }

return {
reset: {
placement: resetPlacement
}
};
if (placement !== resetPlacement) {
return {
reset: {
placement: resetPlacement
}
};
}
}

@@ -713,26 +717,27 @@

const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
let crossAxisMulti = 1;
if (alignment === 'end') {
crossAxisMulti = -1;
}
if (rtl && isVertical) {
crossAxisMulti *= -1;
}
const crossAxisMulti = rtl && isVertical ? -1 : 1;
const rawValue = typeof value === 'function' ? value({ ...rects,
placement
}) : value;
const {
const isNumber = typeof rawValue === 'number'; // eslint-disable-next-line prefer-const
let {
mainAxis,
crossAxis
} = typeof rawValue === 'number' ? {
crossAxis,
alignmentAxis
} = isNumber ? {
mainAxis: rawValue,
crossAxis: 0
crossAxis: 0,
alignmentAxis: null
} : {
mainAxis: 0,
crossAxis: 0,
alignmentAxis: null,
...rawValue
};
if (alignment && typeof alignmentAxis === 'number') {
crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
}
return isVertical ? {

@@ -990,10 +995,17 @@ x: crossAxis * crossAxisMulti,

};
const prevDimensions = await platform.getDimensions(elements.floating);
apply == null ? void 0 : apply({ ...dimensions,
...rects
});
return {
reset: {
rects: true
}
};
const nextDimensions = await platform.getDimensions(elements.floating);
if (prevDimensions.width !== nextDimensions.width || prevDimensions.height !== nextDimensions.height) {
return {
reset: {
rects: true
}
};
}
return {};
}

@@ -1102,13 +1114,19 @@

return {
reset: {
rects: await platform.getElementRects({
reference: {
getBoundingClientRect
},
floating: elements.floating,
strategy
})
}
};
const resetRects = await platform.getElementRects({
reference: {
getBoundingClientRect
},
floating: elements.floating,
strategy
});
if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) {
return {
reset: {
rects: resetRects
}
};
}
return {};
}

@@ -1115,0 +1133,0 @@

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).FloatingUICore={})}(this,(function(t){"use strict";function e(t){return t.split("-")[0]}function n(t){return t.split("-")[1]}function o(t){return["top","bottom"].includes(e(t))?"x":"y"}function i(t){return"y"===t?"height":"width"}function r(t,r,l){let{reference:a,floating:s}=t;const f=a.x+a.width/2-s.width/2,c=a.y+a.height/2-s.height/2,u=o(r),m=i(u),d=a[m]/2-s[m]/2,p="x"===u;let g;switch(e(r)){case"top":g={x:f,y:a.y-s.height};break;case"bottom":g={x:f,y:a.y+a.height};break;case"right":g={x:a.x+a.width,y:c};break;case"left":g={x:a.x-s.width,y:c};break;default:g={x:a.x,y:a.y}}switch(n(r)){case"start":g[u]-=d*(l&&p?-1:1);break;case"end":g[u]+=d*(l&&p?-1:1)}return g}function l(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){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}async function s(t,e){var n;void 0===e&&(e={});const{x:o,y:i,platform:r,rects:s,elements:f,strategy:c}=t,{boundary:u="clippingAncestors",rootBoundary:m="viewport",elementContext:d="floating",altBoundary:p=!1,padding:g=0}=e,h=l(g),y=f[p?"floating"===d?"reference":"floating":d],x=a(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(y)))||n?y:y.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(f.floating)),boundary:u,rootBoundary:m})),w=a(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===d?{...s.floating,x:o,y:i}:s.reference,offsetParent:await(null==r.getOffsetParent?void 0:r.getOffsetParent(f.floating)),strategy:c}):s[d]);return{top:x.top-w.top+h.top,bottom:w.bottom-x.bottom+h.bottom,left:x.left-w.left+h.left,right:w.right-x.right+h.right}}const f=Math.min,c=Math.max;function u(t,e,n){return c(t,f(e,n))}const m={left:"right",right:"left",bottom:"top",top:"bottom"};function d(t){return t.replace(/left|right|bottom|top/g,(t=>m[t]))}function p(t,e,r){void 0===r&&(r=!1);const l=n(t),a=o(t),s=i(a);let f="x"===a?l===(r?"end":"start")?"right":"left":"start"===l?"bottom":"top";return e.reference[s]>e.floating[s]&&(f=d(f)),{main:f,cross:d(f)}}const g={start:"end",end:"start"};function h(t){return t.replace(/start|end/g,(t=>g[t]))}const y=["top","right","bottom","left"],x=y.reduce(((t,e)=>t.concat(e,e+"-start",e+"-end")),[]);function w(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function v(t){return y.some((e=>t[e]>=0))}function b(t){return"x"===t?"y":"x"}t.arrow=t=>({name:"arrow",options:t,async fn(e){const{element:n,padding:r=0}=null!=t?t:{},{x:a,y:s,placement:f,rects:c,platform:m}=e;if(null==n)return{};const d=l(r),p={x:a,y:s},g=o(f),h=i(g),y=await m.getDimensions(n),x="y"===g?"top":"left",w="y"===g?"bottom":"right",v=c.reference[h]+c.reference[g]-p[g]-c.floating[h],b=p[g]-c.reference[g],R=await(null==m.getOffsetParent?void 0:m.getOffsetParent(n)),A=R?"y"===g?R.clientHeight||0:R.clientWidth||0:0,P=v/2-b/2,T=d[x],O=A-y[h]-d[w],k=A/2-y[h]/2+P,L=u(T,k,O);return{data:{[g]:L,centerOffset:k-L}}}}),t.autoPlacement=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(o){var i,r,l,a,f;const{x:c,y:u,rects:m,middlewareData:d,placement:g,platform:y,elements:w}=o,{alignment:v=null,allowedPlacements:b=x,autoAlignment:R=!0,...A}=t,P=function(t,o,i){return(t?[...i.filter((e=>n(e)===t)),...i.filter((e=>n(e)!==t))]:i.filter((t=>e(t)===t))).filter((e=>!t||n(e)===t||!!o&&h(e)!==e))}(v,R,b),T=await s(o,A),O=null!=(i=null==(r=d.autoPlacement)?void 0:r.index)?i:0,k=P[O],{main:L,cross:C}=p(k,m,await(null==y.isRTL?void 0:y.isRTL(w.floating)));if(g!==k)return{x:c,y:u,reset:{skip:!1,placement:P[0]}};const D=[T[e(k)],T[L],T[C]],E=[...null!=(l=null==(a=d.autoPlacement)?void 0:a.overflows)?l:[],{placement:k,overflows:D}],B=P[O+1];if(B)return{data:{index:O+1,overflows:E},reset:{skip:!1,placement:B}};const H=E.slice().sort(((t,e)=>t.overflows[0]-e.overflows[0])),V=null==(f=H.find((t=>{let{overflows:e}=t;return e.every((t=>t<=0))})))?void 0:f.placement;return{reset:{placement:null!=V?V:H[0].placement}}}}},t.computePosition=async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:l=[],platform:a}=n,s=await(null==a.isRTL?void 0:a.isRTL(e));let f=await a.getElementRects({reference:t,floating:e,strategy:i}),{x:c,y:u}=r(f,o,s),m=o,d={};const p=new Set;for(let n=0;n<l.length;n++){const{name:g,fn:h}=l[n];if(p.has(g))continue;const{x:y,y:x,data:w,reset:v}=await h({x:c,y:u,initialPlacement:o,placement:m,strategy:i,middlewareData:d,rects:f,platform:a,elements:{reference:t,floating:e}});c=null!=y?y:c,u=null!=x?x:u,d={...d,[g]:{...d[g],...w}},v&&("object"==typeof v&&(v.placement&&(m=v.placement),v.rects&&(f=!0===v.rects?await a.getElementRects({reference:t,floating:e,strategy:i}):v.rects),({x:c,y:u}=r(f,m,s)),!1!==v.skip&&p.add(g)),n=-1)}return{x:c,y:u,placement:m,strategy:i,middlewareData:d}},t.detectOverflow=s,t.flip=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(n){var o;const{placement:i,middlewareData:r,rects:l,initialPlacement:a,platform:f,elements:c}=n,{mainAxis:u=!0,crossAxis:m=!0,fallbackPlacements:g,fallbackStrategy:y="bestFit",flipAlignment:x=!0,...w}=t,v=e(i),b=g||(v===a||!x?[d(a)]:function(t){const e=d(t);return[h(t),e,h(e)]}(a)),R=[a,...b],A=await s(n,w),P=[];let T=(null==(o=r.flip)?void 0:o.overflows)||[];if(u&&P.push(A[v]),m){const{main:t,cross:e}=p(i,l,await(null==f.isRTL?void 0:f.isRTL(c.floating)));P.push(A[t],A[e])}if(T=[...T,{placement:i,overflows:P}],!P.every((t=>t<=0))){var O,k;const t=(null!=(O=null==(k=r.flip)?void 0:k.index)?O:0)+1,e=R[t];if(e)return{data:{index:t,overflows:T},reset:{skip:!1,placement:e}};let n="bottom";switch(y){case"bestFit":{var L;const t=null==(L=T.slice().sort(((t,e)=>t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)-e.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)))[0])?void 0:L.placement;t&&(n=t);break}case"initialPlacement":n=a}return{reset:{placement:n}}}return{}}}},t.hide=function(t){let{strategy:e="referenceHidden",...n}=void 0===t?{}:t;return{name:"hide",async fn(t){const{rects:o}=t;switch(e){case"referenceHidden":{const e=w(await s(t,{...n,elementContext:"reference"}),o.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:v(e)}}}case"escaped":{const e=w(await s(t,{...n,altBoundary:!0}),o.floating);return{data:{escapedOffsets:e,escaped:v(e)}}}default:return{}}}}},t.inline=function(t){return void 0===t&&(t={}),{name:"inline",options:t,async fn(n){var i;const{placement:r,elements:s,rects:u,platform:m,strategy:d}=n,{padding:p=2,x:g,y:h}=t,y=a(m.convertOffsetParentRelativeRectToViewportRelativeRect?await m.convertOffsetParentRelativeRectToViewportRelativeRect({rect:u.reference,offsetParent:await(null==m.getOffsetParent?void 0:m.getOffsetParent(s.floating)),strategy:d}):u.reference),x=null!=(i=await(null==m.getClientRects?void 0:m.getClientRects(s.reference)))?i:[],w=l(p);return{reset:{rects:await m.getElementRects({reference:{getBoundingClientRect:function(){var t;if(2===x.length&&x[0].left>x[1].right&&null!=g&&null!=h)return null!=(t=x.find((t=>g>t.left-w.left&&g<t.right+w.right&&h>t.top-w.top&&h<t.bottom+w.bottom)))?t:y;if(x.length>=2){if("x"===o(r)){const t=x[0],n=x[x.length-1],o="top"===e(r),i=t.top,l=n.bottom,a=o?t.left:n.left,s=o?t.right:n.right;return{top:i,bottom:l,left:a,right:s,width:s-a,height:l-i,x:a,y:i}}const t="left"===e(r),n=c(...x.map((t=>t.right))),i=f(...x.map((t=>t.left))),l=x.filter((e=>t?e.left===i:e.right===n)),a=l[0].top,s=l[l.length-1].bottom;return{top:a,bottom:s,left:i,right:n,width:n-i,height:s-a,x:i,y:a}}return y}},floating:s.floating,strategy:d})}}}}},t.limitShift=function(t){return void 0===t&&(t={}),{options:t,fn(n){const{x:i,y:r,placement:l,rects:a,middlewareData:s}=n,{offset:f=0,mainAxis:c=!0,crossAxis:u=!0}=t,m={x:i,y:r},d=o(l),p=b(d);let g=m[d],h=m[p];const y="function"==typeof f?f({...a,placement:l}):f,x="number"==typeof y?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(c){const t="y"===d?"height":"width",e=a.reference[d]-a.floating[t]+x.mainAxis,n=a.reference[d]+a.reference[t]-x.mainAxis;g<e?g=e:g>n&&(g=n)}if(u){var w,v,R,A;const t="y"===d?"width":"height",n=["top","left"].includes(e(l)),o=a.reference[p]-a.floating[t]+(n&&null!=(w=null==(v=s.offset)?void 0:v[p])?w:0)+(n?0:x.crossAxis),i=a.reference[p]+a.reference[t]+(n?0:null!=(R=null==(A=s.offset)?void 0:A[p])?R:0)-(n?x.crossAxis:0);h<o?h=o:h>i&&(h=i)}return{[d]:g,[p]:h}}}},t.offset=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(i){const{x:r,y:l,placement:a,rects:s,platform:f,elements:c}=i,u=function(t,i,r,l){void 0===l&&(l=!1);const a=e(t),s=n(t),f="x"===o(t),c=["left","top"].includes(a)?-1:1;let u=1;"end"===s&&(u=-1),l&&f&&(u*=-1);const m="function"==typeof r?r({...i,placement:t}):r,{mainAxis:d,crossAxis:p}="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};return f?{x:p*u,y:d*c}:{x:d*c,y:p*u}}(a,s,t,await(null==f.isRTL?void 0:f.isRTL(c.floating)));return{x:r+u.x,y:l+u.y,data:u}}}},t.rectToClientRect=a,t.shift=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(n){const{x:i,y:r,placement:l}=n,{mainAxis:a=!0,crossAxis:f=!1,limiter:c={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...m}=t,d={x:i,y:r},p=await s(n,m),g=o(e(l)),h=b(g);let y=d[g],x=d[h];if(a){const t="y"===g?"bottom":"right";y=u(y+p["y"===g?"top":"left"],y,y-p[t])}if(f){const t="y"===h?"bottom":"right";x=u(x+p["y"===h?"top":"left"],x,x-p[t])}const w=c.fn({...n,[g]:y,[h]:x});return{...w,data:{x:w.x-i,y:w.y-r}}}}},t.size=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(o){const{placement:i,rects:r,platform:l,elements:a}=o,{apply:f,...u}=t,m=await s(o,u),d=e(i),p=n(i);let g,h;"top"===d||"bottom"===d?(g=d,h=p===(await(null==l.isRTL?void 0:l.isRTL(a.floating))?"start":"end")?"left":"right"):(h=d,g="end"===p?"top":"bottom");const y=c(m.left,0),x=c(m.right,0),w=c(m.top,0),v=c(m.bottom,0),b={height:r.floating.height-(["left","right"].includes(i)?2*(0!==w||0!==v?w+v:c(m.top,m.bottom)):m[g]),width:r.floating.width-(["top","bottom"].includes(i)?2*(0!==y||0!==x?y+x:c(m.left,m.right)):m[h])};return null==f||f({...b,...r}),{reset:{rects:!0}}}}},Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).FloatingUICore={})}(this,(function(t){"use strict";function e(t){return t.split("-")[0]}function n(t){return t.split("-")[1]}function i(t){return["top","bottom"].includes(e(t))?"x":"y"}function o(t){return"y"===t?"height":"width"}function r(t,r,l){let{reference:a,floating:s}=t;const f=a.x+a.width/2-s.width/2,c=a.y+a.height/2-s.height/2,u=i(r),m=o(u),d=a[m]/2-s[m]/2,g="x"===u;let p;switch(e(r)){case"top":p={x:f,y:a.y-s.height};break;case"bottom":p={x:f,y:a.y+a.height};break;case"right":p={x:a.x+a.width,y:c};break;case"left":p={x:a.x-s.width,y:c};break;default:p={x:a.x,y:a.y}}switch(n(r)){case"start":p[u]-=d*(l&&g?-1:1);break;case"end":p[u]+=d*(l&&g?-1:1)}return p}function l(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){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}async function s(t,e){var n;void 0===e&&(e={});const{x:i,y:o,platform:r,rects:s,elements:f,strategy:c}=t,{boundary:u="clippingAncestors",rootBoundary:m="viewport",elementContext:d="floating",altBoundary:g=!1,padding:p=0}=e,h=l(p),y=f[g?"floating"===d?"reference":"floating":d],x=a(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(y)))||n?y:y.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(f.floating)),boundary:u,rootBoundary:m})),w=a(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===d?{...s.floating,x:i,y:o}:s.reference,offsetParent:await(null==r.getOffsetParent?void 0:r.getOffsetParent(f.floating)),strategy:c}):s[d]);return{top:x.top-w.top+h.top,bottom:w.bottom-x.bottom+h.bottom,left:x.left-w.left+h.left,right:w.right-x.right+h.right}}const f=Math.min,c=Math.max;function u(t,e,n){return c(t,f(e,n))}const m={left:"right",right:"left",bottom:"top",top:"bottom"};function d(t){return t.replace(/left|right|bottom|top/g,(t=>m[t]))}function g(t,e,r){void 0===r&&(r=!1);const l=n(t),a=i(t),s=o(a);let f="x"===a?l===(r?"end":"start")?"right":"left":"start"===l?"bottom":"top";return e.reference[s]>e.floating[s]&&(f=d(f)),{main:f,cross:d(f)}}const p={start:"end",end:"start"};function h(t){return t.replace(/start|end/g,(t=>p[t]))}const y=["top","right","bottom","left"],x=y.reduce(((t,e)=>t.concat(e,e+"-start",e+"-end")),[]);function w(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function v(t){return y.some((e=>t[e]>=0))}function b(t){return"x"===t?"y":"x"}t.arrow=t=>({name:"arrow",options:t,async fn(e){const{element:n,padding:r=0}=null!=t?t:{},{x:a,y:s,placement:f,rects:c,platform:m}=e;if(null==n)return{};const d=l(r),g={x:a,y:s},p=i(f),h=o(p),y=await m.getDimensions(n),x="y"===p?"top":"left",w="y"===p?"bottom":"right",v=c.reference[h]+c.reference[p]-g[p]-c.floating[h],b=g[p]-c.reference[p],R=await(null==m.getOffsetParent?void 0:m.getOffsetParent(n)),A=R?"y"===p?R.clientHeight||0:R.clientWidth||0:0,P=v/2-b/2,T=d[x],O=A-y[h]-d[w],D=A/2-y[h]/2+P,L=u(T,D,O);return{data:{[p]:L,centerOffset:D-L}}}}),t.autoPlacement=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(i){var o,r,l,a,f;const{x:c,y:u,rects:m,middlewareData:d,placement:p,platform:y,elements:w}=i,{alignment:v=null,allowedPlacements:b=x,autoAlignment:R=!0,...A}=t,P=function(t,i,o){return(t?[...o.filter((e=>n(e)===t)),...o.filter((e=>n(e)!==t))]:o.filter((t=>e(t)===t))).filter((e=>!t||n(e)===t||!!i&&h(e)!==e))}(v,R,b),T=await s(i,A),O=null!=(o=null==(r=d.autoPlacement)?void 0:r.index)?o:0,D=P[O];if(null==D)return{};const{main:L,cross:k}=g(D,m,await(null==y.isRTL?void 0:y.isRTL(w.floating)));if(p!==D)return{x:c,y:u,reset:{placement:P[0]}};const C=[T[e(D)],T[L],T[k]],E=[...null!=(l=null==(a=d.autoPlacement)?void 0:a.overflows)?l:[],{placement:D,overflows:C}],B=P[O+1];if(B)return{data:{index:O+1,overflows:E},reset:{placement:B}};const H=E.slice().sort(((t,e)=>t.overflows[0]-e.overflows[0])),V=null==(f=H.find((t=>{let{overflows:e}=t;return e.every((t=>t<=0))})))?void 0:f.placement,j=null!=V?V:H[0].placement;return j!==p?{data:{index:O+1,overflows:E},reset:{placement:j}}:{}}}},t.computePosition=async(t,e,n)=>{const{placement:i="bottom",strategy:o="absolute",middleware:l=[],platform:a}=n,s=await(null==a.isRTL?void 0:a.isRTL(e));let f=await a.getElementRects({reference:t,floating:e,strategy:o}),{x:c,y:u}=r(f,i,s),m=i,d={};for(let n=0;n<l.length;n++){const{name:g,fn:p}=l[n],{x:h,y:y,data:x,reset:w}=await p({x:c,y:u,initialPlacement:i,placement:m,strategy:o,middlewareData:d,rects:f,platform:a,elements:{reference:t,floating:e}});c=null!=h?h:c,u=null!=y?y:u,d={...d,[g]:{...d[g],...x}},w&&("object"==typeof w&&(w.placement&&(m=w.placement),w.rects&&(f=!0===w.rects?await a.getElementRects({reference:t,floating:e,strategy:o}):w.rects),({x:c,y:u}=r(f,m,s))),n=-1)}return{x:c,y:u,placement:m,strategy:o,middlewareData:d}},t.detectOverflow=s,t.flip=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(n){var i;const{placement:o,middlewareData:r,rects:l,initialPlacement:a,platform:f,elements:c}=n,{mainAxis:u=!0,crossAxis:m=!0,fallbackPlacements:p,fallbackStrategy:y="bestFit",flipAlignment:x=!0,...w}=t,v=e(o),b=p||(v===a||!x?[d(a)]:function(t){const e=d(t);return[h(t),e,h(e)]}(a)),R=[a,...b],A=await s(n,w),P=[];let T=(null==(i=r.flip)?void 0:i.overflows)||[];if(u&&P.push(A[v]),m){const{main:t,cross:e}=g(o,l,await(null==f.isRTL?void 0:f.isRTL(c.floating)));P.push(A[t],A[e])}if(T=[...T,{placement:o,overflows:P}],!P.every((t=>t<=0))){var O,D;const t=(null!=(O=null==(D=r.flip)?void 0:D.index)?O:0)+1,e=R[t];if(e)return{data:{index:t,overflows:T},reset:{placement:e}};let n="bottom";switch(y){case"bestFit":{var L;const t=null==(L=T.slice().sort(((t,e)=>t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)-e.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)))[0])?void 0:L.placement;t&&(n=t);break}case"initialPlacement":n=a}if(o!==n)return{reset:{placement:n}}}return{}}}},t.hide=function(t){let{strategy:e="referenceHidden",...n}=void 0===t?{}:t;return{name:"hide",async fn(t){const{rects:i}=t;switch(e){case"referenceHidden":{const e=w(await s(t,{...n,elementContext:"reference"}),i.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:v(e)}}}case"escaped":{const e=w(await s(t,{...n,altBoundary:!0}),i.floating);return{data:{escapedOffsets:e,escaped:v(e)}}}default:return{}}}}},t.inline=function(t){return void 0===t&&(t={}),{name:"inline",options:t,async fn(n){var o;const{placement:r,elements:s,rects:u,platform:m,strategy:d}=n,{padding:g=2,x:p,y:h}=t,y=a(m.convertOffsetParentRelativeRectToViewportRelativeRect?await m.convertOffsetParentRelativeRectToViewportRelativeRect({rect:u.reference,offsetParent:await(null==m.getOffsetParent?void 0:m.getOffsetParent(s.floating)),strategy:d}):u.reference),x=null!=(o=await(null==m.getClientRects?void 0:m.getClientRects(s.reference)))?o:[],w=l(g);const v=await m.getElementRects({reference:{getBoundingClientRect:function(){var t;if(2===x.length&&x[0].left>x[1].right&&null!=p&&null!=h)return null!=(t=x.find((t=>p>t.left-w.left&&p<t.right+w.right&&h>t.top-w.top&&h<t.bottom+w.bottom)))?t:y;if(x.length>=2){if("x"===i(r)){const t=x[0],n=x[x.length-1],i="top"===e(r),o=t.top,l=n.bottom,a=i?t.left:n.left,s=i?t.right:n.right;return{top:o,bottom:l,left:a,right:s,width:s-a,height:l-o,x:a,y:o}}const t="left"===e(r),n=c(...x.map((t=>t.right))),o=f(...x.map((t=>t.left))),l=x.filter((e=>t?e.left===o:e.right===n)),a=l[0].top,s=l[l.length-1].bottom;return{top:a,bottom:s,left:o,right:n,width:n-o,height:s-a,x:o,y:a}}return y}},floating:s.floating,strategy:d});return u.reference.x!==v.reference.x||u.reference.y!==v.reference.y||u.reference.width!==v.reference.width||u.reference.height!==v.reference.height?{reset:{rects:v}}:{}}}},t.limitShift=function(t){return void 0===t&&(t={}),{options:t,fn(n){const{x:o,y:r,placement:l,rects:a,middlewareData:s}=n,{offset:f=0,mainAxis:c=!0,crossAxis:u=!0}=t,m={x:o,y:r},d=i(l),g=b(d);let p=m[d],h=m[g];const y="function"==typeof f?f({...a,placement:l}):f,x="number"==typeof y?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(c){const t="y"===d?"height":"width",e=a.reference[d]-a.floating[t]+x.mainAxis,n=a.reference[d]+a.reference[t]-x.mainAxis;p<e?p=e:p>n&&(p=n)}if(u){var w,v,R,A;const t="y"===d?"width":"height",n=["top","left"].includes(e(l)),i=a.reference[g]-a.floating[t]+(n&&null!=(w=null==(v=s.offset)?void 0:v[g])?w:0)+(n?0:x.crossAxis),o=a.reference[g]+a.reference[t]+(n?0:null!=(R=null==(A=s.offset)?void 0:A[g])?R:0)-(n?x.crossAxis:0);h<i?h=i:h>o&&(h=o)}return{[d]:p,[g]:h}}}},t.offset=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(o){const{x:r,y:l,placement:a,rects:s,platform:f,elements:c}=o,u=function(t,o,r,l){void 0===l&&(l=!1);const a=e(t),s=n(t),f="x"===i(t),c=["left","top"].includes(a)?-1:1,u=l&&f?-1:1,m="function"==typeof r?r({...o,placement:t}):r,d="number"==typeof m;let{mainAxis:g,crossAxis:p,alignmentAxis:h}=d?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...m};return s&&"number"==typeof h&&(p="end"===s?-1*h:h),f?{x:p*u,y:g*c}:{x:g*c,y:p*u}}(a,s,t,await(null==f.isRTL?void 0:f.isRTL(c.floating)));return{x:r+u.x,y:l+u.y,data:u}}}},t.rectToClientRect=a,t.shift=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(n){const{x:o,y:r,placement:l}=n,{mainAxis:a=!0,crossAxis:f=!1,limiter:c={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...m}=t,d={x:o,y:r},g=await s(n,m),p=i(e(l)),h=b(p);let y=d[p],x=d[h];if(a){const t="y"===p?"bottom":"right";y=u(y+g["y"===p?"top":"left"],y,y-g[t])}if(f){const t="y"===h?"bottom":"right";x=u(x+g["y"===h?"top":"left"],x,x-g[t])}const w=c.fn({...n,[p]:y,[h]:x});return{...w,data:{x:w.x-o,y:w.y-r}}}}},t.size=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(i){const{placement:o,rects:r,platform:l,elements:a}=i,{apply:f,...u}=t,m=await s(i,u),d=e(o),g=n(o);let p,h;"top"===d||"bottom"===d?(p=d,h=g===(await(null==l.isRTL?void 0:l.isRTL(a.floating))?"start":"end")?"left":"right"):(h=d,p="end"===g?"top":"bottom");const y=c(m.left,0),x=c(m.right,0),w=c(m.top,0),v=c(m.bottom,0),b={height:r.floating.height-(["left","right"].includes(o)?2*(0!==w||0!==v?w+v:c(m.top,m.bottom)):m[p]),width:r.floating.width-(["top","bottom"].includes(o)?2*(0!==y||0!==x?y+x:c(m.left,m.right)):m[h])},R=await l.getDimensions(a.floating);null==f||f({...b,...r});const A=await l.getDimensions(a.floating);return R.width!==A.width||R.height!==A.height?{reset:{rects:!0}}:{}}}},Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "@floating-ui/core",
"version": "0.5.1",
"version": "0.6.0",
"@rollingversions": {

@@ -5,0 +5,0 @@ "baseVersion": [

@@ -5,2 +5,3 @@ import type { Placement, Rect, Coords, Middleware, ElementRects } from '../types';

* The axis that runs along the side of the floating element.
* @default 0
*/

@@ -10,4 +11,13 @@ mainAxis?: number;

* The axis that runs along the alignment of the floating element.
* @default 0
*/
crossAxis?: number;
/**
* When set to a number, overrides the `crossAxis` value for aligned
* (non-centered/base) placements and works logically. A positive number
* will move the floating element in the direction of the opposite edge
* to the one that is aligned, while a negative number the reverse.
* @default null
*/
alignmentAxis?: number | null;
};

@@ -14,0 +24,0 @@ declare type OffsetFunction = (args: {

@@ -89,3 +89,2 @@ export declare type Alignment = 'start' | 'end';

rects?: true | ElementRects;
skip?: false;
};

@@ -92,0 +91,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc