mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 21:29:38 +02:00
3 lines
12 KiB
JavaScript
3 lines
12 KiB
JavaScript
|
import{getSideAxis as t,getAlignmentAxis as e,getAxisLength as n,getSide as o,getAlignment as s,evaluate as c,getPaddingObject as i,rectToClientRect as r,min as l,clamp as a,getOppositeAlignmentPlacement as f,placements as m,getAlignmentSides as u,getOppositePlacement as d,getExpandedPlacements as g,getOppositeAxisPlacements as p,sides as y,max as h,getOppositeAxis as w}from"@floating-ui/utils";export{rectToClientRect}from"@floating-ui/utils";function computeCoordsFromPlacement(c,i,r){let{reference:l,floating:a}=c;const f=t(i);const m=e(i);const u=n(m);const d=o(i);const g=f==="y";const p=l.x+l.width/2-a.width/2;const y=l.y+l.height/2-a.height/2;const h=l[u]/2-a[u]/2;let w;switch(d){case"top":w={x:p,y:l.y-a.height};break;case"bottom":w={x:p,y:l.y+l.height};break;case"right":w={x:l.x+l.width,y:y};break;case"left":w={x:l.x-a.width,y:y};break;default:w={x:l.x,y:l.y}}switch(s(i)){case"start":w[m]-=h*(r&&g?-1:1);break;case"end":w[m]+=h*(r&&g?-1:1);break}return w}const computePosition=async(t,e,n)=>{const{placement:o="bottom",strategy:s="absolute",middleware:c=[],platform:i}=n;const r=c.filter(Boolean);const l=await(i.isRTL==null?void 0:i.isRTL(e));let a=await i.getElementRects({reference:t,floating:e,strategy:s});let{x:f,y:m}=computeCoordsFromPlacement(a,o,l);let u=o;let d={};let g=0;for(let n=0;n<r.length;n++){const{name:c,fn:p}=r[n];const{x:y,y:h,data:w,reset:v}=await p({x:f,y:m,initialPlacement:o,placement:u,strategy:s,middlewareData:d,rects:a,platform:i,elements:{reference:t,floating:e}});f=y!=null?y:f;m=h!=null?h:m;d={...d,[c]:{...d[c],...w}};if(v&&g<=50){g++;if(typeof v==="object"){v.placement&&(u=v.placement);v.rects&&(a=v.rects===true?await i.getElementRects({reference:t,floating:e,strategy:s}):v.rects);({x:f,y:m}=computeCoordsFromPlacement(a,u,l))}n=-1}}return{x:f,y:m,placement:u,strategy:s,middlewareData:d}};async function detectOverflow(t,e){var n;e===void 0&&(e={});const{x:o,y:s,platform:l,rects:a,elements:f,strategy:m}=t;const{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:g="floating",altBoundary:p=false,padding:y=0}=c(e,t);const h=i(y);const w=g==="floating"?"reference":"floating";const v=f[p?w:g];const x=r(await l.getClippingRect({element:(n=await(l.isElement==null?void 0:l.isElement(v)))==null||n?v:v.contextElement||await(l.getDocumentElement==null?void 0:l.getDocumentElement(f.floating)),boundary:u,rootBoundary:d,strategy:m}));const b=g==="floating"?{x:o,y:s,width:a.floating.width,height:a.floating.height}:a.reference;const R=await(l.getOffsetParent==null?void 0:l.getOffsetParent(f.floating));const A=await(l.isElement==null?void 0:l.isElement(R))&&await(l.getScale==null?void 0:l.getScale(R))||{x:1,y:1};const O=r(l.convertOffsetParentRelativeRectToViewportRelativeRect?await l.convertOffsetParentRelativeRectToViewportRelativeRect({elements:f,rect:b,offsetParent:R,strategy:m}):b);return{top:(x.top-O.top+h.top)/A.y,bottom:(O.bottom-x.bottom+h.bottom)/A.y,left:(x.left-O.left+h.left)/A.x,right:(O.right-x.right+h.right)/A.x}}const arrow=t=>({name:"arrow",options:t,async fn(o){const{x:r,y:f,placement:m,rects:u,platform:d,elements:g,middlewareData:p}=o;const{element:y,padding:h=0}=c(t,o)||{};if(y==null)return{};const w=i(h);const v={x:r,y:f};const x=e(m);const b=n(x);const R=await d.getDimensions(y);const A=x==="y";const O=A?"top":"left";const P=A?"bottom":"right";const C=A?"clientHeight":"clientWidth";const T=u.reference[b]+u.reference[x]-v[x]-u.floating[b];const L=v[x]-u.reference[x];const B=await(d.getOffsetParent==null?void 0:d.getOffsetParent(y));let D=B?B[C]:0;D&&await(d.isElement==null?void 0:d.isElement(B))||(D=g.floating[C]||u.floating[b]);const E=T/2-L/2;const k=D/2-R[b]/2-1;const S=l(w[O],k);const F=l(w[P],k);const H=S;const V=D-R[b]-F;const W=D/2-R[b]/2+E;const j=a(H,W,V);const z=!p.arrow&&s(m)!=null&&W!==j&&u.reference[b]/2-(W<H?S:F)-R[b]/2<0;const q=z?W<H?W-H:W-V:0;return{[x]:v[x]+q,data:{[x]:j,centerOffset:W-j-q,...z&&{alignmentOffset:q}},reset:z}}});function getPlacementList(t,e,n){const c=t?[...n.filter((e=>s(e)===t)),...n.filter((e=>s(e)!==t))]:n.filter((t=>o(t)===t));retur
|
||
|
|