mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
11 lines
9.3 KiB
JavaScript
11 lines
9.3 KiB
JavaScript
|
import{rectToClientRect as t,detectOverflow as e,offset as n,autoPlacement as i,shift as o,flip as s,size as c,hide as r,arrow as l,inline as f,limitShift as a,computePosition as u}from"@floating-ui/core";import{round as g,createCoords as h,max as d,min as p,floor as m}from"@floating-ui/utils";import{getComputedStyle as w,isHTMLElement as x,isElement as R,getWindow as v,isWebKit as y,getFrameElement as C,getDocumentElement as O,isTopLayer as b,getNodeName as T,isOverflowElement as P,getNodeScroll as L,getParentNode as B,isLastTraversableNode as S,getOverflowAncestors as A,isContainingBlock as F,isTableElement as E,getContainingBlock as V}from"@floating-ui/utils/dom";export{getOverflowAncestors}from"@floating-ui/utils/dom";function getCssDimensions(t){const e=w(t);let n=parseFloat(e.width)||0;let i=parseFloat(e.height)||0;const o=x(t);const s=o?t.offsetWidth:n;const c=o?t.offsetHeight:i;const r=g(n)!==s||g(i)!==c;if(r){n=s;i=c}return{width:n,height:i,$:r}}function unwrapElement(t){return R(t)?t:t.contextElement}function getScale(t){const e=unwrapElement(t);if(!x(e))return h(1);const n=e.getBoundingClientRect();const{width:i,height:o,$:s}=getCssDimensions(e);let c=(s?g(n.width):n.width)/i;let r=(s?g(n.height):n.height)/o;c&&Number.isFinite(c)||(c=1);r&&Number.isFinite(r)||(r=1);return{x:c,y:r}}const W=h(0);function getVisualOffsets(t){const e=v(t);return y()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:W}function shouldAddVisualOffsets(t,e,n){e===void 0&&(e=false);return!(!n||e&&n!==v(t))&&e}function getBoundingClientRect(e,n,i,o){n===void 0&&(n=false);i===void 0&&(i=false);const s=e.getBoundingClientRect();const c=unwrapElement(e);let r=h(1);n&&(o?R(o)&&(r=getScale(o)):r=getScale(e));const l=shouldAddVisualOffsets(c,i,o)?getVisualOffsets(c):h(0);let f=(s.left+l.x)/r.x;let a=(s.top+l.y)/r.y;let u=s.width/r.x;let g=s.height/r.y;if(c){const t=v(c);const e=o&&R(o)?v(o):o;let n=t;let i=C(n);while(i&&o&&e!==n){const t=getScale(i);const e=i.getBoundingClientRect();const o=w(i);const s=e.left+(i.clientLeft+parseFloat(o.paddingLeft))*t.x;const c=e.top+(i.clientTop+parseFloat(o.paddingTop))*t.y;f*=t.x;a*=t.y;u*=t.x;g*=t.y;f+=s;a+=c;n=v(i);i=C(n)}}return t({width:u,height:g,x:f,y:a})}function convertOffsetParentRelativeRectToViewportRelativeRect(t){let{elements:e,rect:n,offsetParent:i,strategy:o}=t;const s=o==="fixed";const c=O(i);const r=!!e&&b(e.floating);if(i===c||r&&s)return n;let l={scrollLeft:0,scrollTop:0};let f=h(1);const a=h(0);const u=x(i);if(u||!u&&!s){(T(i)!=="body"||P(c))&&(l=L(i));if(x(i)){const t=getBoundingClientRect(i);f=getScale(i);a.x=t.x+i.clientLeft;a.y=t.y+i.clientTop}}return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-l.scrollLeft*f.x+a.x,y:n.y*f.y-l.scrollTop*f.y+a.y}}function getClientRects(t){return Array.from(t.getClientRects())}function getWindowScrollBarX(t){return getBoundingClientRect(O(t)).left+L(t).scrollLeft}function getDocumentRect(t){const e=O(t);const n=L(t);const i=t.ownerDocument.body;const o=d(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth);const s=d(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let c=-n.scrollLeft+getWindowScrollBarX(t);const r=-n.scrollTop;w(i).direction==="rtl"&&(c+=d(e.clientWidth,i.clientWidth)-o);return{width:o,height:s,x:c,y:r}}function getViewportRect(t,e){const n=v(t);const i=O(t);const o=n.visualViewport;let s=i.clientWidth;let c=i.clientHeight;let r=0;let l=0;if(o){s=o.width;c=o.height;const t=y();if(!t||t&&e==="fixed"){r=o.offsetLeft;l=o.offsetTop}}return{width:s,height:c,x:r,y:l}}function getInnerBoundingClientRect(t,e){const n=getBoundingClientRect(t,true,e==="fixed");const i=n.top+t.clientTop;const o=n.left+t.clientLeft;const s=x(t)?getScale(t):h(1);const c=t.clientWidth*s.x;const r=t.clientHeight*s.y;const l=o*s.x;const f=i*s.y;return{width:c,height:r,x:l,y:f}}function getClientRectFromClippingAncestor(e,n,i){let o;if(n==="viewport")o=getViewportRect(e,i);else if(n==="document")o=getDocumentRect(O(e));else if(R(n))o=getInnerBoundingClientRect(n,i);else{const t=getVisualOffsets(e);o={...n,x:n.x-t.x,y
|
||
|
/**
|
||
|
* Automatically updates the position of the floating element when necessary.
|
||
|
* Should only be called when the floating element is mounted on the DOM or
|
||
|
* visible on the screen.
|
||
|
* @returns cleanup function that should be invoked when the floating element is
|
||
|
* removed from the DOM or hidden from the screen.
|
||
|
* @see https://floating-ui.com/docs/autoUpdate
|
||
|
*/function autoUpdate(t,e,n,i){i===void 0&&(i={});const{ancestorScroll:o=true,ancestorResize:s=true,elementResize:c=typeof ResizeObserver==="function",layoutShift:r=typeof IntersectionObserver==="function",animationFrame:l=false}=i;const f=unwrapElement(t);const a=o||s?[...f?A(f):[],...A(e)]:[];a.forEach((t=>{o&&t.addEventListener("scroll",n,{passive:true});s&&t.addEventListener("resize",n)}));const u=f&&r?observeMove(f,n):null;let g=-1;let h=null;if(c){h=new ResizeObserver((t=>{let[i]=t;if(i&&i.target===f&&h){h.unobserve(e);cancelAnimationFrame(g);g=requestAnimationFrame((()=>{var t;(t=h)==null||t.observe(e)}))}n()}));f&&!l&&h.observe(f);h.observe(e)}let d;let p=l?getBoundingClientRect(t):null;l&&frameLoop();function frameLoop(){const e=getBoundingClientRect(t);!p||e.x===p.x&&e.y===p.y&&e.width===p.width&&e.height===p.height||n();p=e;d=requestAnimationFrame(frameLoop)}n();return()=>{var t;a.forEach((t=>{o&&t.removeEventListener("scroll",n);s&&t.removeEventListener("resize",n)}));u==null||u();(t=h)==null||t.disconnect();h=null;l&&cancelAnimationFrame(d)}}const H=e;const z=n;const I=i;const M=o;const X=s;const q=c;const N=r;const U=l;const $=f;const _=a;const computePosition=(t,e,n)=>{const i=new Map;const o={platform:D,...n};const s={...o.platform,_c:i};return u(t,e,{...o,platform:s})};export{U as arrow,I as autoPlacement,autoUpdate,computePosition,H as detectOverflow,X as flip,N as hide,$ as inline,_ as limitShift,z as offset,D as platform,M as shift,q as size};
|
||
|
|