@floating-ui/core
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -230,3 +230,4 @@ import { getSideAxis, getAlignmentAxis, getAxisLength, getSide, getAlignment, evaluate, getPaddingObject, rectToClientRect, min, clamp, placements, getAlignmentSides, getOppositeAlignmentPlacement, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, sides, max, getOppositeAxis } from '@floating-ui/utils'; | ||
platform, | ||
elements | ||
elements, | ||
middlewareData | ||
} = state; | ||
@@ -279,5 +280,5 @@ // Since `element` is required, we don't Partial<> the type. | ||
// to point to nothing for an aligned placement, adjust the offset of the | ||
// floating element itself. This stops `shift()` from taking action, but can | ||
// be worked around by calling it again after the `arrow()` if desired. | ||
const shouldAddOffset = getAlignment(placement) != null && center != offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0; | ||
// floating element itself. To ensure `shift()` continues to take action, | ||
// a single reset is performed when this is true. | ||
const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center != offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0; | ||
const alignmentOffset = shouldAddOffset ? center < min$1 ? min$1 - center : max - center : 0; | ||
@@ -289,3 +290,4 @@ return { | ||
centerOffset: center - offset + alignmentOffset | ||
} | ||
}, | ||
reset: shouldAddOffset | ||
}; | ||
@@ -292,0 +294,0 @@ } |
@@ -350,3 +350,4 @@ (function (global, factory) { | ||
platform, | ||
elements | ||
elements, | ||
middlewareData | ||
} = state; | ||
@@ -399,5 +400,5 @@ // Since `element` is required, we don't Partial<> the type. | ||
// to point to nothing for an aligned placement, adjust the offset of the | ||
// floating element itself. This stops `shift()` from taking action, but can | ||
// be worked around by calling it again after the `arrow()` if desired. | ||
const shouldAddOffset = getAlignment(placement) != null && center != offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0; | ||
// floating element itself. To ensure `shift()` continues to take action, | ||
// a single reset is performed when this is true. | ||
const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center != offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0; | ||
const alignmentOffset = shouldAddOffset ? center < min$1 ? min$1 - center : max - center : 0; | ||
@@ -409,3 +410,4 @@ return { | ||
centerOffset: center - offset + alignmentOffset | ||
} | ||
}, | ||
reset: shouldAddOffset | ||
}; | ||
@@ -412,0 +414,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";const e=["top","right","bottom","left"],n=["start","end"],o=e.reduce(((t,e)=>t.concat(e,e+"-"+n[0],e+"-"+n[1])),[]),i=Math.min,r=Math.max,a={left:"right",right:"left",bottom:"top",top:"bottom"},l={start:"end",end:"start"};function s(t,e,n){return r(t,i(e,n))}function f(t,e){return"function"==typeof t?t(e):t}function c(t){return t.split("-")[0]}function u(t){return t.split("-")[1]}function m(t){return"x"===t?"y":"x"}function d(t){return"y"===t?"height":"width"}function g(t){return["top","bottom"].includes(c(t))?"y":"x"}function p(t){return m(g(t))}function h(t,e,n){void 0===n&&(n=!1);const o=u(t),i=p(t),r=d(i);let a="x"===i?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[r]>e.floating[r]&&(a=x(a)),[a,x(a)]}function y(t){return t.replace(/start|end/g,(t=>l[t]))}function x(t){return t.replace(/left|right|bottom|top/g,(t=>a[t]))}function w(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 v(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}function b(t,e,n){let{reference:o,floating:i}=t;const r=g(e),a=p(e),l=d(a),s=c(e),f="y"===r,m=o.x+o.width/2-i.width/2,h=o.y+o.height/2-i.height/2,y=o[l]/2-i[l]/2;let x;switch(s){case"top":x={x:m,y:o.y-i.height};break;case"bottom":x={x:m,y:o.y+o.height};break;case"right":x={x:o.x+o.width,y:h};break;case"left":x={x:o.x-i.width,y:h};break;default:x={x:o.x,y:o.y}}switch(u(e)){case"start":x[a]-=y*(n&&f?-1:1);break;case"end":x[a]+=y*(n&&f?-1:1)}return x}async function A(t,e){var n;void 0===e&&(e={});const{x:o,y:i,platform:r,rects:a,elements:l,strategy:s}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:m="floating",altBoundary:d=!1,padding:g=0}=f(e,t),p=w(g),h=l[d?"floating"===m?"reference":"floating":m],y=v(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(h)))||n?h:h.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:s})),x="floating"===m?{...a.floating,x:o,y:i}:a.reference,b=await(null==r.getOffsetParent?void 0:r.getOffsetParent(l.floating)),A=await(null==r.isElement?void 0:r.isElement(b))&&await(null==r.getScale?void 0:r.getScale(b))||{x:1,y:1},R=v(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({rect:x,offsetParent:b,strategy:s}):x);return{top:(y.top-R.top+p.top)/A.y,bottom:(R.bottom-y.bottom+p.bottom)/A.y,left:(y.left-R.left+p.left)/A.x,right:(R.right-y.right+p.right)/A.x}}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 P(t){return e.some((e=>t[e]>=0))}function T(t){const e=i(...t.map((t=>t.left))),n=i(...t.map((t=>t.top)));return{x:e,y:n,width:r(...t.map((t=>t.right)))-e,height:r(...t.map((t=>t.bottom)))-n}}t.arrow=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:a,platform:l,elements:c}=e,{element:m,padding:g=0}=f(t,e)||{};if(null==m)return{};const h=w(g),y={x:n,y:o},x=p(r),v=d(x),b=await l.getDimensions(m),A="y"===x,R=A?"top":"left",P=A?"bottom":"right",T=A?"clientHeight":"clientWidth",E=a.reference[v]+a.reference[x]-y[x]-a.floating[v],D=y[x]-a.reference[x],L=await(null==l.getOffsetParent?void 0:l.getOffsetParent(m));let O=L?L[T]:0;O&&await(null==l.isElement?void 0:l.isElement(L))||(O=c.floating[T]||a.floating[v]);const k=E/2-D/2,C=O/2-b[v]/2-1,B=i(h[R],C),H=i(h[P],C),S=B,F=O-b[v]-H,j=O/2-b[v]/2+k,z=s(S,j,F),M=null!=u(r)&&j!=z&&a.reference[v]/2-(j<S?B:H)-b[v]/2<0?j<S?S-j:F-j:0;return{[x]:y[x]-M,data:{[x]:z,centerOffset:j-z+M}}}}),t.autoPlacement=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var n,i,r;const{rects:a,middlewareData:l,placement:s,platform:m,elements:d}=e,{crossAxis:g=!1,alignment:p,allowedPlacements:x=o,autoAlignment:w=!0,...v}=f(t,e),b=void 0!==p||x===o?function(t,e,n){return(t?[...n.filter((e=>u(e)===t)),...n.filter((e=>u(e)!==t))]:n.filter((t=>c(t)===t))).filter((n=>!t||u(n)===t||!!e&&y(n)!==n))}(p||null,w,x):x,R=await A(e,v),P=(null==(n=l.autoPlacement)?void 0:n.index)||0,T=b[P];if(null==T)return{};const E=h(T,a,await(null==m.isRTL?void 0:m.isRTL(d.floating)));if(s!==T)return{reset:{placement:b[0]}};const D=[R[c(T)],R[E[0]],R[E[1]]],L=[...(null==(i=l.autoPlacement)?void 0:i.overflows)||[],{placement:T,overflows:D}],O=b[P+1];if(O)return{data:{index:P+1,overflows:L},reset:{placement:O}};const k=L.map((t=>{const e=u(t.placement);return[t.placement,e&&g?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),C=(null==(r=k.filter((t=>t[2].slice(0,u(t[0])?2:3).every((t=>t<=0))))[0])?void 0:r[0])||k[0][0];return C!==s?{data:{index:P+1,overflows:L},reset:{placement:C}}:{}}}},t.computePosition=async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:a}=n,l=r.filter(Boolean),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}=b(f,o,s),m=o,d={},g=0;for(let n=0;n<l.length;n++){const{name:r,fn:p}=l[n],{x:h,y:y,data:x,reset:w}=await p({x:c,y:u,initialPlacement:o,placement:m,strategy:i,middlewareData:d,rects:f,platform:a,elements:{reference:t,floating:e}});c=null!=h?h:c,u=null!=y?y:u,d={...d,[r]:{...d[r],...x}},w&&g<=50&&(g++,"object"==typeof w&&(w.placement&&(m=w.placement),w.rects&&(f=!0===w.rects?await a.getElementRects({reference:t,floating:e,strategy:i}):w.rects),({x:c,y:u}=b(f,m,s))),n=-1)}return{x:c,y:u,placement:m,strategy:i,middlewareData:d}},t.detectOverflow=A,t.flip=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n;const{placement:o,middlewareData:i,rects:r,initialPlacement:a,platform:l,elements:s}=e,{mainAxis:m=!0,crossAxis:d=!0,fallbackPlacements:g,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...b}=f(t,e),R=c(o),P=c(a)===a,T=await(null==l.isRTL?void 0:l.isRTL(s.floating)),E=g||(P||!v?[x(a)]:function(t){const e=x(t);return[y(t),e,y(e)]}(a));g||"none"===w||E.push(...function(t,e,n,o){const i=u(t);let r=function(t,e,n){const o=["left","right"],i=["right","left"],r=["top","bottom"],a=["bottom","top"];switch(t){case"top":case"bottom":return n?e?i:o:e?o:i;case"left":case"right":return e?r:a;default:return[]}}(c(t),"start"===n,o);return i&&(r=r.map((t=>t+"-"+i)),e&&(r=r.concat(r.map(y)))),r}(a,v,w,T));const D=[a,...E],L=await A(e,b),O=[];let k=(null==(n=i.flip)?void 0:n.overflows)||[];if(m&&O.push(L[R]),d){const t=h(o,r,T);O.push(L[t[0]],L[t[1]])}if(k=[...k,{placement:o,overflows:O}],!O.every((t=>t<=0))){var C,B;const t=((null==(C=i.flip)?void 0:C.index)||0)+1,e=D[t];if(e)return{data:{index:t,overflows:k},reset:{placement:e}};let n=null==(B=k.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=k.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=a}if(o!==n)return{reset:{placement:n}}}return{}}}},t.hide=function(t){return void 0===t&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:o="referenceHidden",...i}=f(t,e);switch(o){case"referenceHidden":{const t=R(await A(e,{...i,elementContext:"reference"}),n.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:P(t)}}}case"escaped":{const t=R(await A(e,{...i,altBoundary:!0}),n.floating);return{data:{escapedOffsets:t,escaped:P(t)}}}default:return{}}}}},t.inline=function(t){return void 0===t&&(t={}),{name:"inline",options:t,async fn(e){const{placement:n,elements:o,rects:a,platform:l,strategy:s}=e,{padding:u=2,x:m,y:d}=f(t,e),p=Array.from(await(null==l.getClientRects?void 0:l.getClientRects(o.reference))||[]),h=function(t){const e=t.slice().sort(((t,e)=>t.y-e.y)),n=[];let o=null;for(let t=0;t<e.length;t++){const i=e[t];!o||i.y-o.y>o.height/2?n.push([i]):n[n.length-1].push(i),o=i}return n.map((t=>v(T(t))))}(p),y=v(T(p)),x=w(u);const b=await l.getElementRects({reference:{getBoundingClientRect:function(){if(2===h.length&&h[0].left>h[1].right&&null!=m&&null!=d)return h.find((t=>m>t.left-x.left&&m<t.right+x.right&&d>t.top-x.top&&d<t.bottom+x.bottom))||y;if(h.length>=2){if("y"===g(n)){const t=h[0],e=h[h.length-1],o="top"===c(n),i=t.top,r=e.bottom,a=o?t.left:e.left,l=o?t.right:e.right;return{top:i,bottom:r,left:a,right:l,width:l-a,height:r-i,x:a,y:i}}const t="left"===c(n),e=r(...h.map((t=>t.right))),o=i(...h.map((t=>t.left))),a=h.filter((n=>t?n.left===o:n.right===e)),l=a[0].top,s=a[a.length-1].bottom;return{top:l,bottom:s,left:o,right:e,width:e-o,height:s-l,x:o,y:l}}return y}},floating:o.floating,strategy:s});return a.reference.x!==b.reference.x||a.reference.y!==b.reference.y||a.reference.width!==b.reference.width||a.reference.height!==b.reference.height?{reset:{rects:b}}:{}}}},t.limitShift=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:n,y:o,placement:i,rects:r,middlewareData:a}=e,{offset:l=0,mainAxis:s=!0,crossAxis:u=!0}=f(t,e),d={x:n,y:o},p=g(i),h=m(p);let y=d[h],x=d[p];const w=f(l,e),v="number"==typeof w?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(s){const t="y"===h?"height":"width",e=r.reference[h]-r.floating[t]+v.mainAxis,n=r.reference[h]+r.reference[t]-v.mainAxis;y<e?y=e:y>n&&(y=n)}if(u){var b,A;const t="y"===h?"width":"height",e=["top","left"].includes(c(i)),n=r.reference[p]-r.floating[t]+(e&&(null==(b=a.offset)?void 0:b[p])||0)+(e?0:v.crossAxis),o=r.reference[p]+r.reference[t]+(e?0:(null==(A=a.offset)?void 0:A[p])||0)-(e?v.crossAxis:0);x<n?x=n:x>o&&(x=o)}return{[h]:y,[p]:x}}}},t.offset=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){const{x:n,y:o}=e,i=await async function(t,e){const{placement:n,platform:o,elements:i}=t,r=await(null==o.isRTL?void 0:o.isRTL(i.floating)),a=c(n),l=u(n),s="y"===g(n),m=["left","top"].includes(a)?-1:1,d=r&&s?-1:1,p=f(e,t);let{mainAxis:h,crossAxis:y,alignmentAxis:x}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...p};return l&&"number"==typeof x&&(y="end"===l?-1*x:x),s?{x:y*d,y:h*m}:{x:h*m,y:y*d}}(e,t);return{x:n+i.x,y:o+i.y,data:i}}}},t.rectToClientRect=v,t.shift=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:o,placement:i}=e,{mainAxis:r=!0,crossAxis:a=!1,limiter:l={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...u}=f(t,e),d={x:n,y:o},p=await A(e,u),h=g(c(i)),y=m(h);let x=d[y],w=d[h];if(r){const t="y"===y?"bottom":"right";x=s(x+p["y"===y?"top":"left"],x,x-p[t])}if(a){const t="y"===h?"bottom":"right";w=s(w+p["y"===h?"top":"left"],w,w-p[t])}const v=l.fn({...e,[y]:x,[h]:w});return{...v,data:{x:v.x-n,y:v.y-o}}}}},t.size=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(e){const{placement:n,rects:o,platform:a,elements:l}=e,{apply:s=(()=>{}),...m}=f(t,e),d=await A(e,m),p=c(n),h=u(n),y="y"===g(n),{width:x,height:w}=o.floating;let v,b;"top"===p||"bottom"===p?(v=p,b=h===(await(null==a.isRTL?void 0:a.isRTL(l.floating))?"start":"end")?"left":"right"):(b=p,v="end"===h?"top":"bottom");const R=w-d[v],P=x-d[b],T=!e.middlewareData.shift;let E=R,D=P;if(y){const t=x-d.left-d.right;D=h||T?i(P,t):t}else{const t=w-d.top-d.bottom;E=h||T?i(R,t):t}if(T&&!h){const t=r(d.left,0),e=r(d.right,0),n=r(d.top,0),o=r(d.bottom,0);y?D=x-2*(0!==t||0!==e?t+e:r(d.left,d.right)):E=w-2*(0!==n||0!==o?n+o:r(d.top,d.bottom))}await s({...e,availableWidth:D,availableHeight:E});const L=await a.getDimensions(l.floating);return x!==L.width||w!==L.height?{reset:{rects:!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";const e=["top","right","bottom","left"],n=["start","end"],o=e.reduce(((t,e)=>t.concat(e,e+"-"+n[0],e+"-"+n[1])),[]),i=Math.min,r=Math.max,a={left:"right",right:"left",bottom:"top",top:"bottom"},l={start:"end",end:"start"};function s(t,e,n){return r(t,i(e,n))}function f(t,e){return"function"==typeof t?t(e):t}function c(t){return t.split("-")[0]}function u(t){return t.split("-")[1]}function m(t){return"x"===t?"y":"x"}function d(t){return"y"===t?"height":"width"}function g(t){return["top","bottom"].includes(c(t))?"y":"x"}function p(t){return m(g(t))}function h(t,e,n){void 0===n&&(n=!1);const o=u(t),i=p(t),r=d(i);let a="x"===i?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[r]>e.floating[r]&&(a=x(a)),[a,x(a)]}function y(t){return t.replace(/start|end/g,(t=>l[t]))}function x(t){return t.replace(/left|right|bottom|top/g,(t=>a[t]))}function w(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 v(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}function b(t,e,n){let{reference:o,floating:i}=t;const r=g(e),a=p(e),l=d(a),s=c(e),f="y"===r,m=o.x+o.width/2-i.width/2,h=o.y+o.height/2-i.height/2,y=o[l]/2-i[l]/2;let x;switch(s){case"top":x={x:m,y:o.y-i.height};break;case"bottom":x={x:m,y:o.y+o.height};break;case"right":x={x:o.x+o.width,y:h};break;case"left":x={x:o.x-i.width,y:h};break;default:x={x:o.x,y:o.y}}switch(u(e)){case"start":x[a]-=y*(n&&f?-1:1);break;case"end":x[a]+=y*(n&&f?-1:1)}return x}async function A(t,e){var n;void 0===e&&(e={});const{x:o,y:i,platform:r,rects:a,elements:l,strategy:s}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:m="floating",altBoundary:d=!1,padding:g=0}=f(e,t),p=w(g),h=l[d?"floating"===m?"reference":"floating":m],y=v(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(h)))||n?h:h.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:s})),x="floating"===m?{...a.floating,x:o,y:i}:a.reference,b=await(null==r.getOffsetParent?void 0:r.getOffsetParent(l.floating)),A=await(null==r.isElement?void 0:r.isElement(b))&&await(null==r.getScale?void 0:r.getScale(b))||{x:1,y:1},R=v(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({rect:x,offsetParent:b,strategy:s}):x);return{top:(y.top-R.top+p.top)/A.y,bottom:(R.bottom-y.bottom+p.bottom)/A.y,left:(y.left-R.left+p.left)/A.x,right:(R.right-y.right+p.right)/A.x}}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 P(t){return e.some((e=>t[e]>=0))}function T(t){const e=i(...t.map((t=>t.left))),n=i(...t.map((t=>t.top)));return{x:e,y:n,width:r(...t.map((t=>t.right)))-e,height:r(...t.map((t=>t.bottom)))-n}}t.arrow=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:o,placement:r,rects:a,platform:l,elements:c,middlewareData:m}=e,{element:g,padding:h=0}=f(t,e)||{};if(null==g)return{};const y=w(h),x={x:n,y:o},v=p(r),b=d(v),A=await l.getDimensions(g),R="y"===v,P=R?"top":"left",T=R?"bottom":"right",D=R?"clientHeight":"clientWidth",E=a.reference[b]+a.reference[v]-x[v]-a.floating[b],L=x[v]-a.reference[v],O=await(null==l.getOffsetParent?void 0:l.getOffsetParent(g));let k=O?O[D]:0;k&&await(null==l.isElement?void 0:l.isElement(O))||(k=c.floating[D]||a.floating[b]);const C=E/2-L/2,B=k/2-A[b]/2-1,H=i(y[P],B),S=i(y[T],B),F=H,j=k-A[b]-S,z=k/2-A[b]/2+C,M=s(F,z,j),V=!m.arrow&&null!=u(r)&&z!=M&&a.reference[b]/2-(z<F?H:S)-A[b]/2<0,W=V?z<F?F-z:j-z:0;return{[v]:x[v]-W,data:{[v]:M,centerOffset:z-M+W},reset:V}}}),t.autoPlacement=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var n,i,r;const{rects:a,middlewareData:l,placement:s,platform:m,elements:d}=e,{crossAxis:g=!1,alignment:p,allowedPlacements:x=o,autoAlignment:w=!0,...v}=f(t,e),b=void 0!==p||x===o?function(t,e,n){return(t?[...n.filter((e=>u(e)===t)),...n.filter((e=>u(e)!==t))]:n.filter((t=>c(t)===t))).filter((n=>!t||u(n)===t||!!e&&y(n)!==n))}(p||null,w,x):x,R=await A(e,v),P=(null==(n=l.autoPlacement)?void 0:n.index)||0,T=b[P];if(null==T)return{};const D=h(T,a,await(null==m.isRTL?void 0:m.isRTL(d.floating)));if(s!==T)return{reset:{placement:b[0]}};const E=[R[c(T)],R[D[0]],R[D[1]]],L=[...(null==(i=l.autoPlacement)?void 0:i.overflows)||[],{placement:T,overflows:E}],O=b[P+1];if(O)return{data:{index:P+1,overflows:L},reset:{placement:O}};const k=L.map((t=>{const e=u(t.placement);return[t.placement,e&&g?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),C=(null==(r=k.filter((t=>t[2].slice(0,u(t[0])?2:3).every((t=>t<=0))))[0])?void 0:r[0])||k[0][0];return C!==s?{data:{index:P+1,overflows:L},reset:{placement:C}}:{}}}},t.computePosition=async(t,e,n)=>{const{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:a}=n,l=r.filter(Boolean),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}=b(f,o,s),m=o,d={},g=0;for(let n=0;n<l.length;n++){const{name:r,fn:p}=l[n],{x:h,y:y,data:x,reset:w}=await p({x:c,y:u,initialPlacement:o,placement:m,strategy:i,middlewareData:d,rects:f,platform:a,elements:{reference:t,floating:e}});c=null!=h?h:c,u=null!=y?y:u,d={...d,[r]:{...d[r],...x}},w&&g<=50&&(g++,"object"==typeof w&&(w.placement&&(m=w.placement),w.rects&&(f=!0===w.rects?await a.getElementRects({reference:t,floating:e,strategy:i}):w.rects),({x:c,y:u}=b(f,m,s))),n=-1)}return{x:c,y:u,placement:m,strategy:i,middlewareData:d}},t.detectOverflow=A,t.flip=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n;const{placement:o,middlewareData:i,rects:r,initialPlacement:a,platform:l,elements:s}=e,{mainAxis:m=!0,crossAxis:d=!0,fallbackPlacements:g,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:w="none",flipAlignment:v=!0,...b}=f(t,e),R=c(o),P=c(a)===a,T=await(null==l.isRTL?void 0:l.isRTL(s.floating)),D=g||(P||!v?[x(a)]:function(t){const e=x(t);return[y(t),e,y(e)]}(a));g||"none"===w||D.push(...function(t,e,n,o){const i=u(t);let r=function(t,e,n){const o=["left","right"],i=["right","left"],r=["top","bottom"],a=["bottom","top"];switch(t){case"top":case"bottom":return n?e?i:o:e?o:i;case"left":case"right":return e?r:a;default:return[]}}(c(t),"start"===n,o);return i&&(r=r.map((t=>t+"-"+i)),e&&(r=r.concat(r.map(y)))),r}(a,v,w,T));const E=[a,...D],L=await A(e,b),O=[];let k=(null==(n=i.flip)?void 0:n.overflows)||[];if(m&&O.push(L[R]),d){const t=h(o,r,T);O.push(L[t[0]],L[t[1]])}if(k=[...k,{placement:o,overflows:O}],!O.every((t=>t<=0))){var C,B;const t=((null==(C=i.flip)?void 0:C.index)||0)+1,e=E[t];if(e)return{data:{index:t,overflows:k},reset:{placement:e}};let n=null==(B=k.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=k.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=a}if(o!==n)return{reset:{placement:n}}}return{}}}},t.hide=function(t){return void 0===t&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:o="referenceHidden",...i}=f(t,e);switch(o){case"referenceHidden":{const t=R(await A(e,{...i,elementContext:"reference"}),n.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:P(t)}}}case"escaped":{const t=R(await A(e,{...i,altBoundary:!0}),n.floating);return{data:{escapedOffsets:t,escaped:P(t)}}}default:return{}}}}},t.inline=function(t){return void 0===t&&(t={}),{name:"inline",options:t,async fn(e){const{placement:n,elements:o,rects:a,platform:l,strategy:s}=e,{padding:u=2,x:m,y:d}=f(t,e),p=Array.from(await(null==l.getClientRects?void 0:l.getClientRects(o.reference))||[]),h=function(t){const e=t.slice().sort(((t,e)=>t.y-e.y)),n=[];let o=null;for(let t=0;t<e.length;t++){const i=e[t];!o||i.y-o.y>o.height/2?n.push([i]):n[n.length-1].push(i),o=i}return n.map((t=>v(T(t))))}(p),y=v(T(p)),x=w(u);const b=await l.getElementRects({reference:{getBoundingClientRect:function(){if(2===h.length&&h[0].left>h[1].right&&null!=m&&null!=d)return h.find((t=>m>t.left-x.left&&m<t.right+x.right&&d>t.top-x.top&&d<t.bottom+x.bottom))||y;if(h.length>=2){if("y"===g(n)){const t=h[0],e=h[h.length-1],o="top"===c(n),i=t.top,r=e.bottom,a=o?t.left:e.left,l=o?t.right:e.right;return{top:i,bottom:r,left:a,right:l,width:l-a,height:r-i,x:a,y:i}}const t="left"===c(n),e=r(...h.map((t=>t.right))),o=i(...h.map((t=>t.left))),a=h.filter((n=>t?n.left===o:n.right===e)),l=a[0].top,s=a[a.length-1].bottom;return{top:l,bottom:s,left:o,right:e,width:e-o,height:s-l,x:o,y:l}}return y}},floating:o.floating,strategy:s});return a.reference.x!==b.reference.x||a.reference.y!==b.reference.y||a.reference.width!==b.reference.width||a.reference.height!==b.reference.height?{reset:{rects:b}}:{}}}},t.limitShift=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:n,y:o,placement:i,rects:r,middlewareData:a}=e,{offset:l=0,mainAxis:s=!0,crossAxis:u=!0}=f(t,e),d={x:n,y:o},p=g(i),h=m(p);let y=d[h],x=d[p];const w=f(l,e),v="number"==typeof w?{mainAxis:w,crossAxis:0}:{mainAxis:0,crossAxis:0,...w};if(s){const t="y"===h?"height":"width",e=r.reference[h]-r.floating[t]+v.mainAxis,n=r.reference[h]+r.reference[t]-v.mainAxis;y<e?y=e:y>n&&(y=n)}if(u){var b,A;const t="y"===h?"width":"height",e=["top","left"].includes(c(i)),n=r.reference[p]-r.floating[t]+(e&&(null==(b=a.offset)?void 0:b[p])||0)+(e?0:v.crossAxis),o=r.reference[p]+r.reference[t]+(e?0:(null==(A=a.offset)?void 0:A[p])||0)-(e?v.crossAxis:0);x<n?x=n:x>o&&(x=o)}return{[h]:y,[p]:x}}}},t.offset=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){const{x:n,y:o}=e,i=await async function(t,e){const{placement:n,platform:o,elements:i}=t,r=await(null==o.isRTL?void 0:o.isRTL(i.floating)),a=c(n),l=u(n),s="y"===g(n),m=["left","top"].includes(a)?-1:1,d=r&&s?-1:1,p=f(e,t);let{mainAxis:h,crossAxis:y,alignmentAxis:x}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...p};return l&&"number"==typeof x&&(y="end"===l?-1*x:x),s?{x:y*d,y:h*m}:{x:h*m,y:y*d}}(e,t);return{x:n+i.x,y:o+i.y,data:i}}}},t.rectToClientRect=v,t.shift=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:o,placement:i}=e,{mainAxis:r=!0,crossAxis:a=!1,limiter:l={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...u}=f(t,e),d={x:n,y:o},p=await A(e,u),h=g(c(i)),y=m(h);let x=d[y],w=d[h];if(r){const t="y"===y?"bottom":"right";x=s(x+p["y"===y?"top":"left"],x,x-p[t])}if(a){const t="y"===h?"bottom":"right";w=s(w+p["y"===h?"top":"left"],w,w-p[t])}const v=l.fn({...e,[y]:x,[h]:w});return{...v,data:{x:v.x-n,y:v.y-o}}}}},t.size=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(e){const{placement:n,rects:o,platform:a,elements:l}=e,{apply:s=(()=>{}),...m}=f(t,e),d=await A(e,m),p=c(n),h=u(n),y="y"===g(n),{width:x,height:w}=o.floating;let v,b;"top"===p||"bottom"===p?(v=p,b=h===(await(null==a.isRTL?void 0:a.isRTL(l.floating))?"start":"end")?"left":"right"):(b=p,v="end"===h?"top":"bottom");const R=w-d[v],P=x-d[b],T=!e.middlewareData.shift;let D=R,E=P;if(y){const t=x-d.left-d.right;E=h||T?i(P,t):t}else{const t=w-d.top-d.bottom;D=h||T?i(R,t):t}if(T&&!h){const t=r(d.left,0),e=r(d.right,0),n=r(d.top,0),o=r(d.bottom,0);y?E=x-2*(0!==t||0!==e?t+e:r(d.left,d.right)):D=w-2*(0!==n||0!==o?n+o:r(d.top,d.bottom))}await s({...e,availableWidth:E,availableHeight:D});const L=await a.getDimensions(l.floating);return x!==L.width||w!==L.height?{reset:{rects:!0}}:{}}}}})); |
{ | ||
"name": "@floating-ui/core", | ||
"version": "1.4.1", | ||
"@rollingversions": { | ||
"baseVersion": [ | ||
0, | ||
1, | ||
0 | ||
] | ||
}, | ||
"version": "1.4.2", | ||
"description": "Positioning library for floating elements: tooltips, popovers, dropdowns, and more", | ||
@@ -60,4 +53,4 @@ "publishConfig": { | ||
"dependencies": { | ||
"@floating-ui/utils": "^0.1.1" | ||
"@floating-ui/utils": "^0.1.3" | ||
} | ||
} |
@@ -109,5 +109,5 @@ import type { Axis, ClientRectObject, ElementRects, Length, Placement, Rect, SideObject, Strategy } from '@floating-ui/utils'; | ||
}; | ||
reset?: true | { | ||
reset?: boolean | { | ||
placement?: Placement; | ||
rects?: true | ElementRects; | ||
rects?: boolean | ElementRects; | ||
}; | ||
@@ -114,0 +114,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187982
4731
Updated@floating-ui/utils@^0.1.3