@gathertown/floating-ui-core
Advanced tools
Comparing version 1.6.26 to 1.6.27
@@ -636,2 +636,12 @@ import { getSideAxis, getAlignmentAxis, getAxisLength, getSide, getAlignment, evaluate, getPaddingObject, rectToClientRect, min, clamp, placements, getAlignmentSides, getOppositeAlignmentPlacement, max, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, sides, getOppositeAxis } from '@gathertown/floating-ui-utils'; | ||
} = state; | ||
const intersections = await detectIntersections(state, { | ||
obstacles: Array.from(document.querySelectorAll('[data-floating-ui-obstacle]')).map(el => el.getBoundingClientRect()) | ||
}); | ||
if (intersections.length) { | ||
return { | ||
data: { | ||
referenceHidden: true | ||
} | ||
}; | ||
} | ||
const { | ||
@@ -948,3 +958,2 @@ strategy = 'referenceHidden', | ||
if (intersections.length) { | ||
console.log(intersections.length); | ||
if (mainAxis === 'x') { | ||
@@ -951,0 +960,0 @@ mainAxisCoord += intersections[0].x * (intersections[0].xSide === 'right' ? 1 : -1); |
@@ -770,2 +770,12 @@ (function (global, factory) { | ||
} = state; | ||
const intersections = await detectIntersections(state, { | ||
obstacles: Array.from(document.querySelectorAll('[data-floating-ui-obstacle]')).map(el => el.getBoundingClientRect()) | ||
}); | ||
if (intersections.length) { | ||
return { | ||
data: { | ||
referenceHidden: true | ||
} | ||
}; | ||
} | ||
const { | ||
@@ -1082,3 +1092,2 @@ strategy = 'referenceHidden', | ||
if (intersections.length) { | ||
console.log("intersections", intersections.length); | ||
if (mainAxis === 'x') { | ||
@@ -1085,0 +1094,0 @@ mainAxisCoord += intersections[0].x * (intersections[0].xSide === 'right' ? 1 : -1); |
@@ -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 g(t){return"y"===t?"height":"width"}function d(t){return["top","bottom"].includes(c(t))?"y":"x"}function h(t){return m(d(t))}function p(t,e,n){void 0===n&&(n=!1);const o=u(t),i=h(t),r=g(i);let a="x"===i?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[r]>e.floating[r]&&(a=w(a)),[a,w(a)]}function y(t){return t.replace(/start|end/g,(t=>l[t]))}function w(t){return t.replace(/left|right|bottom|top/g,(t=>a[t]))}function x(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){const{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function b(t,e,n){let{reference:o,floating:i}=t;const r=d(e),a=h(e),l=g(a),s=c(e),f="y"===r,m=o.x+o.width/2-i.width/2,p=o.y+o.height/2-i.height/2,y=o[l]/2-i[l]/2;let w;switch(s){case"top":w={x:m,y:o.y-i.height};break;case"bottom":w={x:m,y:o.y+o.height};break;case"right":w={x:o.x+o.width,y:p};break;case"left":w={x:o.x-i.width,y:p};break;default:w={x:o.x,y:o.y}}switch(u(e)){case"start":w[a]-=y*(n&&f?-1:1);break;case"end":w[a]+=y*(n&&f?-1:1)}return w}async function R(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:g=!1,padding:d=0}=f(e,t),h=x(d),p=l[g?"floating"===m?"reference":"floating":m],y=v(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(p)))||n?p:p.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:s})),w="floating"===m?{x:o,y:i,width:a.floating.width,height:a.floating.height}:a.reference,b=await(null==r.getOffsetParent?void 0:r.getOffsetParent(l.floating)),R=await(null==r.isElement?void 0:r.isElement(b))&&await(null==r.getScale?void 0:r.getScale(b))||{x:1,y:1},A=v(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:w,offsetParent:b,strategy:s}):w);return{top:(y.top-A.top+h.top)/R.y,bottom:(A.bottom-y.bottom+h.bottom)/R.y,left:(y.left-A.left+h.left)/R.x,right:(A.right-y.right+h.right)/R.x}}async function A(t,e){void 0===e&&(e={});const{x:n,y:o,platform:a,rects:l,elements:s,strategy:f}=t,{obstacles:c=[],padding:u=0}=e,m=x(u),g={...l.floating,x:n,y:o},d=await(null==a.getOffsetParent?void 0:a.getOffsetParent(s.floating)),h=v(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({rect:g,offsetParent:d,strategy:f}):g),p=h.top-m.top,y=h.left-m.left,w=h.bottom+m.bottom,b=h.right+m.right,R=h.width,A=h.height;return c.filter((t=>!(Math.round(t.width)===Math.round(h.width)&&Math.round(t.height)===Math.round(h.height))&&function(t){const{top:e,left:n,bottom:o,right:i}=t;return p<o&&w>e&&y<i&&b>n}(t))).map((t=>{const e=t.top,n=t.left,o=t.bottom,a=t.right,l=t.width,s=t.height,f=y+R/2<n+l/2?"left":"right",c=p+A/2<e+s/2?"top":"bottom",u="right"===f?b>a:b<a,m="bottom"===c?p<e:p>e,g="bottom"===c?w>o:w<o,d=("right"===f?y<n:y>n)?i(y,n):r(y,n),h=u?i(b,a):r(b,a),x=m?i(p,e):r(p,e);return{x:h-d,y:(g?i(w,o):r(w,o))-x,xSide:f,ySide:c}}))}function P(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function O(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:d,padding:p=0}=f(t,e)||{};if(null==d)return{};const y=x(p),w={x:n,y:o},v=h(r),b=g(v),R=await l.getDimensions(d),A="y"===v,P=A?"top":"left",O=A?"bottom":"right",T=A?"clientHeight":"clientWidth",D=a.reference[b]+a.reference[v]-w[v]-a.floating[b],E=w[v]-a.reference[v],S=await(null==l.getOffsetParent?void 0:l.getOffsetParent(d));let C=S?S[T]:0;C&&await(null==l.isElement?void 0:l.isElement(S))||(C=c.floating[T]||a.floating[b]);const L=D/2-E/2,k=C/2-R[b]/2-1,B=i(y[P],k),H=i(y[O],k),M=B,V=C-R[b]-H,F=C/2-R[b]/2+L,j=s(M,F,V),q=!m.arrow&&null!=u(r)&&F!==j&&a.reference[b]/2-(F<M?B:H)-R[b]/2<0,z=q?F<M?F-M:F-V:0;return{[v]:w[v]+z,data:{[v]:j,centerOffset:F-j-z,...q&&{alignmentOffset:z}},reset:q}}}),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:g}=e,{crossAxis:d=!1,alignment:h,allowedPlacements:w=o,autoAlignment:x=!0,...v}=f(t,e),b=void 0!==h||w===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))}(h||null,x,w):w,A=await R(e,v),P=(null==(n=l.autoPlacement)?void 0:n.index)||0,O=b[P];if(null==O)return{};const T=p(O,a,await(null==m.isRTL?void 0:m.isRTL(g.floating)));if(s!==O)return{reset:{placement:b[0]}};const D=[A[c(O)],A[T[0]],A[T[1]]],E=[...(null==(i=l.autoPlacement)?void 0:i.overflows)||[],{placement:O,overflows:D}],S=b[P+1];if(S)return{data:{index:P+1,overflows:E},reset:{placement:S}};const C=E.map((t=>{const e=u(t.placement);return[t.placement,e&&d?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),L=(null==(r=C.filter((t=>t[2].slice(0,u(t[0])?2:3).every((t=>t<=0))))[0])?void 0:r[0])||C[0][0];return L!==s?{data:{index:P+1,overflows:E},reset:{placement:L}}:{}}}},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,g={},d=0;for(let n=0;n<l.length;n++){const{name:r,fn:h}=l[n],{x:p,y:y,data:w,reset:x}=await h({x:c,y:u,initialPlacement:o,placement:m,strategy:i,middlewareData:g,rects:f,platform:a,elements:{reference:t,floating:e}});c=null!=p?p:c,u=null!=y?y:u,g={...g,[r]:{...g[r],...w}},x&&d<=50&&(d++,"object"==typeof x&&(x.placement&&(m=x.placement),x.rects&&(f=!0===x.rects?await a.getElementRects({reference:t,floating:e,strategy:i}):x.rects),({x:c,y:u}=b(f,m,s))),n=-1)}return{x:c,y:u,placement:m,strategy:i,middlewareData:g}},t.detectOverflow=R,t.flip=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n,o;const{placement:i,middlewareData:r,rects:a,initialPlacement:l,platform:s,elements:m}=e,{mainAxis:g=!0,crossAxis:h=!0,fallbackPlacements:x,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:P=!0,...O}=f(t,e);if(null!=(n=r.arrow)&&n.alignmentOffset)return{};const T=c(i),D=d(l),E=c(l)===l,S=await(null==s.isRTL?void 0:s.isRTL(m.floating)),C=x||(E||!P?[w(l)]:function(t){const e=w(t);return[y(t),e,y(e)]}(l)),L="none"!==b;!x&&L&&C.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}(l,P,b,S));const k=[l,...C],B=await R(e,O),H=await A(e,{obstacles:Array.from(document.querySelectorAll("[data-floating-ui-obstacle]")).map((t=>t.getBoundingClientRect()))}),M=[];let V=(null==(o=r.flip)?void 0:o.overflows)||[];if(g&&M.push(B[T]),h){const t=p(i,a,S);M.push(B[t[0]],B[t[1]])}if(V=[...V,{placement:i,overflows:M}],!M.every((t=>t<=0))||H.length){var F,j;const t=((null==(F=r.flip)?void 0:F.index)||0)+1,e=k[t];if(e)return{data:{index:t,overflows:V},reset:{placement:e}};let n=null==(j=V.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:j.placement;if(!n)switch(v){case"bestFit":{var q;const t=null==(q=V.filter((t=>{if(L){const e=d(t.placement);return e===D||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:q[0];t&&(n=t);break}case"initialPlacement":n=l}}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=P(await R(e,{...i,elementContext:"reference"}),n.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:O(t)}}}case"escaped":{const t=P(await R(e,{...i,altBoundary:!0}),n.floating);return{data:{escapedOffsets:t,escaped:O(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:g}=f(t,e),h=Array.from(await(null==l.getClientRects?void 0:l.getClientRects(o.reference))||[]),p=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))))}(h),y=v(T(h)),w=x(u);const b=await l.getElementRects({reference:{getBoundingClientRect:function(){if(2===p.length&&p[0].left>p[1].right&&null!=m&&null!=g)return p.find((t=>m>t.left-w.left&&m<t.right+w.right&&g>t.top-w.top&&g<t.bottom+w.bottom))||y;if(p.length>=2){if("y"===d(n)){const t=p[0],e=p[p.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(...p.map((t=>t.right))),o=i(...p.map((t=>t.left))),a=p.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),g={x:n,y:o},h=d(i),p=m(h);let y=g[p],w=g[h];const x=f(l,e),v="number"==typeof x?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(s){const t="y"===p?"height":"width",e=r.reference[p]-r.floating[t]+v.mainAxis,n=r.reference[p]+r.reference[t]-v.mainAxis;y<e?y=e:y>n&&(y=n)}if(u){var b,R;const t="y"===p?"width":"height",e=["top","left"].includes(c(i)),n=r.reference[h]-r.floating[t]+(e&&(null==(b=a.offset)?void 0:b[h])||0)+(e?0:v.crossAxis),o=r.reference[h]+r.reference[t]+(e?0:(null==(R=a.offset)?void 0:R[h])||0)-(e?v.crossAxis:0);w<n?w=n:w>o&&(w=o)}return{[p]:y,[h]:w}}}},t.offset=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:i,y:r,placement:a,middlewareData:l}=e,s=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"===d(n),m=["left","top"].includes(a)?-1:1,g=r&&s?-1:1,h=f(e,t);let{mainAxis:p,crossAxis:y,alignmentAxis:w}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...h};return l&&"number"==typeof w&&(y="end"===l?-1*w:w),s?{x:y*g,y:p*m}:{x:p*m,y:y*g}}(e,t);return a===(null==(n=l.offset)?void 0:n.placement)&&null!=(o=l.arrow)&&o.alignmentOffset?{}:{x:i+s.x,y:r+s.y,data:{...s,placement:a}}}}},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),g={x:n,y:o},h=await R(e,u),p=await A(e,{obstacles:Array.from(document.querySelectorAll("[data-floating-ui-obstacle]")).map((t=>t.getBoundingClientRect()))}),y=d(c(i)),w=m(y);let x=g[w],v=g[y];if(r){const t="y"===w?"bottom":"right",e=x+h["y"===w?"top":"left"],n=x-h[t];p.length&&(console.log("intersections",p.length),x+="x"===w?p[0].x*("right"===p[0].xSide?1:-1):p[0].y*("bottom"===p[0].ySide?1:-1)),x=s(e,x,n)}if(a){const t="y"===y?"bottom":"right";v=s(v+h["y"===y?"top":"left"],v,v-h[t])}const b=l.fn({...e,[w]:x,[y]:v});return{...b,data:{x:b.x-n,y:b.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),g=await R(e,m),h=c(n),p=u(n),y="y"===d(n),{width:w,height:x}=o.floating;let v,b;"top"===h||"bottom"===h?(v=h,b=p===(await(null==a.isRTL?void 0:a.isRTL(l.floating))?"start":"end")?"left":"right"):(b=h,v="end"===p?"top":"bottom");const A=x-g.top-g.bottom,P=w-g.left-g.right,O=i(x-g[v],A),T=i(w-g[b],P),D=!e.middlewareData.shift;let E=O,S=T;if(y?S=p||D?i(T,P):P:E=p||D?i(O,A):A,D&&!p){const t=r(g.left,0),e=r(g.right,0),n=r(g.top,0),o=r(g.bottom,0);y?S=w-2*(0!==t||0!==e?t+e:r(g.left,g.right)):E=x-2*(0!==n||0!==o?n+o:r(g.top,g.bottom))}await s({...e,availableWidth:S,availableHeight:E});const C=await a.getDimensions(l.floating);return w!==C.width||x!==C.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 h(t){return m(g(t))}function p(t,e,n){void 0===n&&(n=!1);const o=u(t),i=h(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=w(a)),[a,w(a)]}function y(t){return t.replace(/start|end/g,(t=>l[t]))}function w(t){return t.replace(/left|right|bottom|top/g,(t=>a[t]))}function x(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){const{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function b(t,e,n){let{reference:o,floating:i}=t;const r=g(e),a=h(e),l=d(a),s=c(e),f="y"===r,m=o.x+o.width/2-i.width/2,p=o.y+o.height/2-i.height/2,y=o[l]/2-i[l]/2;let w;switch(s){case"top":w={x:m,y:o.y-i.height};break;case"bottom":w={x:m,y:o.y+o.height};break;case"right":w={x:o.x+o.width,y:p};break;case"left":w={x:o.x-i.width,y:p};break;default:w={x:o.x,y:o.y}}switch(u(e)){case"start":w[a]-=y*(n&&f?-1:1);break;case"end":w[a]+=y*(n&&f?-1:1)}return w}async function R(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),h=x(g),p=l[d?"floating"===m?"reference":"floating":m],y=v(await r.getClippingRect({element:null==(n=await(null==r.isElement?void 0:r.isElement(p)))||n?p:p.contextElement||await(null==r.getDocumentElement?void 0:r.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:s})),w="floating"===m?{x:o,y:i,width:a.floating.width,height:a.floating.height}:a.reference,b=await(null==r.getOffsetParent?void 0:r.getOffsetParent(l.floating)),R=await(null==r.isElement?void 0:r.isElement(b))&&await(null==r.getScale?void 0:r.getScale(b))||{x:1,y:1},A=v(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:w,offsetParent:b,strategy:s}):w);return{top:(y.top-A.top+h.top)/R.y,bottom:(A.bottom-y.bottom+h.bottom)/R.y,left:(y.left-A.left+h.left)/R.x,right:(A.right-y.right+h.right)/R.x}}async function A(t,e){void 0===e&&(e={});const{x:n,y:o,platform:a,rects:l,elements:s,strategy:f}=t,{obstacles:c=[],padding:u=0}=e,m=x(u),d={...l.floating,x:n,y:o},g=await(null==a.getOffsetParent?void 0:a.getOffsetParent(s.floating)),h=v(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({rect:d,offsetParent:g,strategy:f}):d),p=h.top-m.top,y=h.left-m.left,w=h.bottom+m.bottom,b=h.right+m.right,R=h.width,A=h.height;return c.filter((t=>!(Math.round(t.width)===Math.round(h.width)&&Math.round(t.height)===Math.round(h.height))&&function(t){const{top:e,left:n,bottom:o,right:i}=t;return p<o&&w>e&&y<i&&b>n}(t))).map((t=>{const e=t.top,n=t.left,o=t.bottom,a=t.right,l=t.width,s=t.height,f=y+R/2<n+l/2?"left":"right",c=p+A/2<e+s/2?"top":"bottom",u="right"===f?b>a:b<a,m="bottom"===c?p<e:p>e,d="bottom"===c?w>o:w<o,g=("right"===f?y<n:y>n)?i(y,n):r(y,n),h=u?i(b,a):r(b,a),x=m?i(p,e):r(p,e);return{x:h-g,y:(d?i(w,o):r(w,o))-x,xSide:f,ySide:c}}))}function P(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function O(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:p=0}=f(t,e)||{};if(null==g)return{};const y=x(p),w={x:n,y:o},v=h(r),b=d(v),R=await l.getDimensions(g),A="y"===v,P=A?"top":"left",O=A?"bottom":"right",T=A?"clientHeight":"clientWidth",D=a.reference[b]+a.reference[v]-w[v]-a.floating[b],E=w[v]-a.reference[v],S=await(null==l.getOffsetParent?void 0:l.getOffsetParent(g));let C=S?S[T]:0;C&&await(null==l.isElement?void 0:l.isElement(S))||(C=c.floating[T]||a.floating[b]);const L=D/2-E/2,k=C/2-R[b]/2-1,B=i(y[P],k),H=i(y[O],k),M=B,V=C-R[b]-H,q=C/2-R[b]/2+L,F=s(M,q,V),j=!m.arrow&&null!=u(r)&&q!==F&&a.reference[b]/2-(q<M?B:H)-R[b]/2<0,z=j?q<M?q-M:q-V:0;return{[v]:w[v]+z,data:{[v]:F,centerOffset:q-F-z,...j&&{alignmentOffset:z}},reset:j}}}),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:h,allowedPlacements:w=o,autoAlignment:x=!0,...v}=f(t,e),b=void 0!==h||w===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))}(h||null,x,w):w,A=await R(e,v),P=(null==(n=l.autoPlacement)?void 0:n.index)||0,O=b[P];if(null==O)return{};const T=p(O,a,await(null==m.isRTL?void 0:m.isRTL(d.floating)));if(s!==O)return{reset:{placement:b[0]}};const D=[A[c(O)],A[T[0]],A[T[1]]],E=[...(null==(i=l.autoPlacement)?void 0:i.overflows)||[],{placement:O,overflows:D}],S=b[P+1];if(S)return{data:{index:P+1,overflows:E},reset:{placement:S}};const C=E.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])),L=(null==(r=C.filter((t=>t[2].slice(0,u(t[0])?2:3).every((t=>t<=0))))[0])?void 0:r[0])||C[0][0];return L!==s?{data:{index:P+1,overflows:E},reset:{placement:L}}:{}}}},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:h}=l[n],{x:p,y:y,data:w,reset:x}=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!=p?p:c,u=null!=y?y:u,d={...d,[r]:{...d[r],...w}},x&&g<=50&&(g++,"object"==typeof x&&(x.placement&&(m=x.placement),x.rects&&(f=!0===x.rects?await a.getElementRects({reference:t,floating:e,strategy:i}):x.rects),({x:c,y:u}=b(f,m,s))),n=-1)}return{x:c,y:u,placement:m,strategy:i,middlewareData:d}},t.detectOverflow=R,t.flip=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n,o;const{placement:i,middlewareData:r,rects:a,initialPlacement:l,platform:s,elements:m}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:x,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:P=!0,...O}=f(t,e);if(null!=(n=r.arrow)&&n.alignmentOffset)return{};const T=c(i),D=g(l),E=c(l)===l,S=await(null==s.isRTL?void 0:s.isRTL(m.floating)),C=x||(E||!P?[w(l)]:function(t){const e=w(t);return[y(t),e,y(e)]}(l)),L="none"!==b;!x&&L&&C.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}(l,P,b,S));const k=[l,...C],B=await R(e,O),H=await A(e,{obstacles:Array.from(document.querySelectorAll("[data-floating-ui-obstacle]")).map((t=>t.getBoundingClientRect()))}),M=[];let V=(null==(o=r.flip)?void 0:o.overflows)||[];if(d&&M.push(B[T]),h){const t=p(i,a,S);M.push(B[t[0]],B[t[1]])}if(V=[...V,{placement:i,overflows:M}],!M.every((t=>t<=0))||H.length){var q,F;const t=((null==(q=r.flip)?void 0:q.index)||0)+1,e=k[t];if(e)return{data:{index:t,overflows:V},reset:{placement:e}};let n=null==(F=V.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:F.placement;if(!n)switch(v){case"bestFit":{var j;const t=null==(j=V.filter((t=>{if(L){const e=g(t.placement);return e===D||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:j[0];t&&(n=t);break}case"initialPlacement":n=l}}return{}}}},t.hide=function(t){return void 0===t&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e;if((await A(e,{obstacles:Array.from(document.querySelectorAll("[data-floating-ui-obstacle]")).map((t=>t.getBoundingClientRect()))})).length)return{data:{referenceHidden:!0}};const{strategy:o="referenceHidden",...i}=f(t,e);switch(o){case"referenceHidden":{const t=P(await R(e,{...i,elementContext:"reference"}),n.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:O(t)}}}case"escaped":{const t=P(await R(e,{...i,altBoundary:!0}),n.floating);return{data:{escapedOffsets:t,escaped:O(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),h=Array.from(await(null==l.getClientRects?void 0:l.getClientRects(o.reference))||[]),p=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))))}(h),y=v(T(h)),w=x(u);const b=await l.getElementRects({reference:{getBoundingClientRect:function(){if(2===p.length&&p[0].left>p[1].right&&null!=m&&null!=d)return p.find((t=>m>t.left-w.left&&m<t.right+w.right&&d>t.top-w.top&&d<t.bottom+w.bottom))||y;if(p.length>=2){if("y"===g(n)){const t=p[0],e=p[p.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(...p.map((t=>t.right))),o=i(...p.map((t=>t.left))),a=p.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},h=g(i),p=m(h);let y=d[p],w=d[h];const x=f(l,e),v="number"==typeof x?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(s){const t="y"===p?"height":"width",e=r.reference[p]-r.floating[t]+v.mainAxis,n=r.reference[p]+r.reference[t]-v.mainAxis;y<e?y=e:y>n&&(y=n)}if(u){var b,R;const t="y"===p?"width":"height",e=["top","left"].includes(c(i)),n=r.reference[h]-r.floating[t]+(e&&(null==(b=a.offset)?void 0:b[h])||0)+(e?0:v.crossAxis),o=r.reference[h]+r.reference[t]+(e?0:(null==(R=a.offset)?void 0:R[h])||0)-(e?v.crossAxis:0);w<n?w=n:w>o&&(w=o)}return{[p]:y,[h]:w}}}},t.offset=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,o;const{x:i,y:r,placement:a,middlewareData:l}=e,s=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,h=f(e,t);let{mainAxis:p,crossAxis:y,alignmentAxis:w}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...h};return l&&"number"==typeof w&&(y="end"===l?-1*w:w),s?{x:y*d,y:p*m}:{x:p*m,y:y*d}}(e,t);return a===(null==(n=l.offset)?void 0:n.placement)&&null!=(o=l.arrow)&&o.alignmentOffset?{}:{x:i+s.x,y:r+s.y,data:{...s,placement:a}}}}},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},h=await R(e,u),p=await A(e,{obstacles:Array.from(document.querySelectorAll("[data-floating-ui-obstacle]")).map((t=>t.getBoundingClientRect()))}),y=g(c(i)),w=m(y);let x=d[w],v=d[y];if(r){const t="y"===w?"bottom":"right",e=x+h["y"===w?"top":"left"],n=x-h[t];p.length&&(x+="x"===w?p[0].x*("right"===p[0].xSide?1:-1):p[0].y*("bottom"===p[0].ySide?1:-1)),x=s(e,x,n)}if(a){const t="y"===y?"bottom":"right";v=s(v+h["y"===y?"top":"left"],v,v-h[t])}const b=l.fn({...e,[w]:x,[y]:v});return{...b,data:{x:b.x-n,y:b.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 R(e,m),h=c(n),p=u(n),y="y"===g(n),{width:w,height:x}=o.floating;let v,b;"top"===h||"bottom"===h?(v=h,b=p===(await(null==a.isRTL?void 0:a.isRTL(l.floating))?"start":"end")?"left":"right"):(b=h,v="end"===p?"top":"bottom");const A=x-d.top-d.bottom,P=w-d.left-d.right,O=i(x-d[v],A),T=i(w-d[b],P),D=!e.middlewareData.shift;let E=O,S=T;if(y?S=p||D?i(T,P):P:E=p||D?i(O,A):A,D&&!p){const t=r(d.left,0),e=r(d.right,0),n=r(d.top,0),o=r(d.bottom,0);y?S=w-2*(0!==t||0!==e?t+e:r(d.left,d.right)):E=x-2*(0!==n||0!==o?n+o:r(d.top,d.bottom))}await s({...e,availableWidth:S,availableHeight:E});const C=await a.getDimensions(l.floating);return w!==C.width||x!==C.height?{reset:{rects:!0}}:{}}}}})); |
{ | ||
"name": "@gathertown/floating-ui-core", | ||
"version": "1.6.26", | ||
"version": "1.6.27", | ||
"description": "Positioning library for floating elements: tooltips, popovers, dropdowns, and more", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
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
232089
5288