UNPKG

@lanaco/lnc-react-ui

Version:

React component library

2 lines (1 loc) 16 kB
"use strict";const X=Math.min,B=Math.max,K=Math.round,U=Math.floor,L=t=>({x:t,y:t}),kt={left:"right",right:"left",bottom:"top",top:"bottom"},Bt={start:"end",end:"start"};function gt(t,e,o){return B(t,X(e,o))}function Q(t,e){return typeof t=="function"?t(e):t}function M(t){return t.split("-")[0]}function Z(t){return t.split("-")[1]}function vt(t){return t==="x"?"y":"x"}function bt(t){return t==="y"?"height":"width"}function D(t){return["top","bottom"].includes(M(t))?"y":"x"}function At(t){return vt(D(t))}function Mt(t,e,o){o===void 0&&(o=!1);const n=Z(t),i=At(t),r=bt(i);let s=i==="x"?n===(o?"end":"start")?"right":"left":n==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=G(s)),[s,G(s)]}function Nt(t){const e=G(t);return[rt(t),e,rt(e)]}function rt(t){return t.replace(/start|end/g,e=>Bt[e])}function Vt(t,e,o){const n=["left","right"],i=["right","left"],r=["top","bottom"],s=["bottom","top"];switch(t){case"top":case"bottom":return o?e?i:n:e?n:i;case"left":case"right":return e?r:s;default:return[]}}function Wt(t,e,o,n){const i=Z(t);let r=Vt(M(t),o==="start",n);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(rt)))),r}function G(t){return t.replace(/left|right|bottom|top/g,e=>kt[e])}function Ht(t){return{top:0,right:0,bottom:0,left:0,...t}}function _t(t){return typeof t!="number"?Ht(t):{top:t,right:t,bottom:t,left:t}}function J(t){const{x:e,y:o,width:n,height:i}=t;return{width:n,height:i,top:o,left:e,right:e+n,bottom:o+i,x:e,y:o}}function pt(t,e,o){let{reference:n,floating:i}=t;const r=D(e),s=At(e),c=bt(s),l=M(e),f=r==="y",d=n.x+n.width/2-i.width/2,a=n.y+n.height/2-i.height/2,m=n[c]/2-i[c]/2;let u;switch(l){case"top":u={x:d,y:n.y-i.height};break;case"bottom":u={x:d,y:n.y+n.height};break;case"right":u={x:n.x+n.width,y:a};break;case"left":u={x:n.x-i.width,y:a};break;default:u={x:n.x,y:n.y}}switch(Z(e)){case"start":u[s]-=m*(o&&f?-1:1);break;case"end":u[s]+=m*(o&&f?-1:1);break}return u}const $t=async(t,e,o)=>{const{placement:n="bottom",strategy:i="absolute",middleware:r=[],platform:s}=o,c=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e));let f=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:a}=pt(f,n,l),m=n,u={},h=0;for(let p=0;p<c.length;p++){const{name:w,fn:g}=c[p],{x,y,data:b,reset:v}=await g({x:d,y:a,initialPlacement:n,placement:m,strategy:i,middlewareData:u,rects:f,platform:s,elements:{reference:t,floating:e}});d=x??d,a=y??a,u={...u,[w]:{...u[w],...b}},v&&h<=50&&(h++,typeof v=="object"&&(v.placement&&(m=v.placement),v.rects&&(f=v.rects===!0?await s.getElementRects({reference:t,floating:e,strategy:i}):v.rects),{x:d,y:a}=pt(f,m,l)),p=-1)}return{x:d,y:a,placement:m,strategy:i,middlewareData:u}};async function Rt(t,e){var o;e===void 0&&(e={});const{x:n,y:i,platform:r,rects:s,elements:c,strategy:l}=t,{boundary:f="clippingAncestors",rootBoundary:d="viewport",elementContext:a="floating",altBoundary:m=!1,padding:u=0}=Q(e,t),h=_t(u),w=c[m?a==="floating"?"reference":"floating":a],g=J(await r.getClippingRect({element:(o=await(r.isElement==null?void 0:r.isElement(w)))==null||o?w:w.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(c.floating)),boundary:f,rootBoundary:d,strategy:l})),x=a==="floating"?{x:n,y:i,width:s.floating.width,height:s.floating.height}:s.reference,y=await(r.getOffsetParent==null?void 0:r.getOffsetParent(c.floating)),b=await(r.isElement==null?void 0:r.isElement(y))?await(r.getScale==null?void 0:r.getScale(y))||{x:1,y:1}:{x:1,y:1},v=J(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:x,offsetParent:y,strategy:l}):x);return{top:(g.top-v.top+h.top)/b.y,bottom:(v.bottom-g.bottom+h.bottom)/b.y,left:(g.left-v.left+h.left)/b.x,right:(v.right-g.right+h.right)/b.x}}const zt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var o,n;const{placement:i,middlewareData:r,rects:s,initialPlacement:c,platform:l,elements:f}=e,{mainAxis:d=!0,crossAxis:a=!0,fallbackPlacements:m,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:h="none",flipAlignment:p=!0,...w}=Q(t,e);if((o=r.arrow)!=null&&o.alignmentOffset)return{};const g=M(i),x=D(c),y=M(c)===c,b=await(l.isRTL==null?void 0:l.isRTL(f.floating)),v=m||(y||!p?[G(c)]:Nt(c)),I=h!=="none";!m&&I&&v.push(...Wt(c,p,h,b));const V=[c,...v],ot=await Rt(e,w),q=[];let W=((n=r.flip)==null?void 0:n.overflows)||[];if(d&&q.push(ot[g]),a){const P=Mt(i,s,b);q.push(ot[P[0]],ot[P[1]])}if(W=[...W,{placement:i,overflows:q}],!q.every(P=>P<=0)){var dt,mt;const P=(((dt=r.flip)==null?void 0:dt.index)||0)+1,it=V[P];if(it&&(!(a==="alignment"?x!==D(it):!1)||W.every(R=>R.overflows[0]>0&&D(R.placement)===x)))return{data:{index:P,overflows:W},reset:{placement:it}};let j=(mt=W.filter(k=>k.overflows[0]<=0).sort((k,R)=>k.overflows[1]-R.overflows[1])[0])==null?void 0:mt.placement;if(!j)switch(u){case"bestFit":{var ht;const k=(ht=W.filter(R=>{if(I){const S=D(R.placement);return S===x||S==="y"}return!0}).map(R=>[R.placement,R.overflows.filter(S=>S>0).reduce((S,Pt)=>S+Pt,0)]).sort((R,S)=>R[1]-S[1])[0])==null?void 0:ht[0];k&&(j=k);break}case"initialPlacement":j=c;break}if(i!==j)return{reset:{placement:j}}}return{}}}};async function It(t,e){const{placement:o,platform:n,elements:i}=t,r=await(n.isRTL==null?void 0:n.isRTL(i.floating)),s=M(o),c=Z(o),l=D(o)==="y",f=["left","top"].includes(s)?-1:1,d=r&&l?-1:1,a=Q(e,t);let{mainAxis:m,crossAxis:u,alignmentAxis:h}=typeof a=="number"?{mainAxis:a,crossAxis:0,alignmentAxis:null}:{mainAxis:a.mainAxis||0,crossAxis:a.crossAxis||0,alignmentAxis:a.alignmentAxis};return c&&typeof h=="number"&&(u=c==="end"?h*-1:h),l?{x:u*d,y:m*f}:{x:m*f,y:u*d}}const jt=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var o,n;const{x:i,y:r,placement:s,middlewareData:c}=e,l=await It(e,t);return s===((o=c.offset)==null?void 0:o.placement)&&(n=c.arrow)!=null&&n.alignmentOffset?{}:{x:i+l.x,y:r+l.y,data:{...l,placement:s}}}}},Yt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:o,y:n,placement:i}=e,{mainAxis:r=!0,crossAxis:s=!1,limiter:c={fn:w=>{let{x:g,y:x}=w;return{x:g,y:x}}},...l}=Q(t,e),f={x:o,y:n},d=await Rt(e,l),a=D(M(i)),m=vt(a);let u=f[m],h=f[a];if(r){const w=m==="y"?"top":"left",g=m==="y"?"bottom":"right",x=u+d[w],y=u-d[g];u=gt(x,u,y)}if(s){const w=a==="y"?"top":"left",g=a==="y"?"bottom":"right",x=h+d[w],y=h-d[g];h=gt(x,h,y)}const p=c.fn({...e,[m]:u,[a]:h});return{...p,data:{x:p.x-o,y:p.y-n,enabled:{[m]:r,[a]:s}}}}}};function tt(){return typeof window<"u"}function z(t){return Ot(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function E(t){var e;return(e=(Ot(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ot(t){return tt()?t instanceof Node||t instanceof A(t).Node:!1}function O(t){return tt()?t instanceof Element||t instanceof A(t).Element:!1}function T(t){return tt()?t instanceof HTMLElement||t instanceof A(t).HTMLElement:!1}function wt(t){return!tt()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof A(t).ShadowRoot}function Y(t){const{overflow:e,overflowX:o,overflowY:n,display:i}=C(t);return/auto|scroll|overlay|hidden|clip/.test(e+n+o)&&!["inline","contents"].includes(i)}function qt(t){return["table","td","th"].includes(z(t))}function et(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function lt(t){const e=ft(),o=O(t)?C(t):t;return["transform","translate","scale","rotate","perspective"].some(n=>o[n]?o[n]!=="none":!1)||(o.containerType?o.containerType!=="normal":!1)||!e&&(o.backdropFilter?o.backdropFilter!=="none":!1)||!e&&(o.filter?o.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(n=>(o.willChange||"").includes(n))||["paint","layout","strict","content"].some(n=>(o.contain||"").includes(n))}function Ut(t){let e=F(t);for(;T(e)&&!_(e);){if(lt(e))return e;if(et(e))return null;e=F(e)}return null}function ft(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function _(t){return["html","body","#document"].includes(z(t))}function C(t){return A(t).getComputedStyle(t)}function nt(t){return O(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function F(t){if(z(t)==="html")return t;const e=t.assignedSlot||t.parentNode||wt(t)&&t.host||E(t);return wt(e)?e.host:e}function Ct(t){const e=F(t);return _(e)?t.ownerDocument?t.ownerDocument.body:t.body:T(e)&&Y(e)?e:Ct(e)}function $(t,e,o){var n;e===void 0&&(e=[]),o===void 0&&(o=!0);const i=Ct(t),r=i===((n=t.ownerDocument)==null?void 0:n.body),s=A(i);if(r){const c=ct(s);return e.concat(s,s.visualViewport||[],Y(i)?i:[],c&&o?$(c):[])}return e.concat(i,$(i,[],o))}function ct(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Lt(t){const e=C(t);let o=parseFloat(e.width)||0,n=parseFloat(e.height)||0;const i=T(t),r=i?t.offsetWidth:o,s=i?t.offsetHeight:n,c=K(o)!==r||K(n)!==s;return c&&(o=r,n=s),{width:o,height:n,$:c}}function at(t){return O(t)?t:t.contextElement}function H(t){const e=at(t);if(!T(e))return L(1);const o=e.getBoundingClientRect(),{width:n,height:i,$:r}=Lt(e);let s=(r?K(o.width):o.width)/n,c=(r?K(o.height):o.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}const Xt=L(0);function Tt(t){const e=A(t);return!ft()||!e.visualViewport?Xt:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Kt(t,e,o){return e===void 0&&(e=!1),!o||e&&o!==A(t)?!1:e}function N(t,e,o,n){e===void 0&&(e=!1),o===void 0&&(o=!1);const i=t.getBoundingClientRect(),r=at(t);let s=L(1);e&&(n?O(n)&&(s=H(n)):s=H(t));const c=Kt(r,o,n)?Tt(r):L(0);let l=(i.left+c.x)/s.x,f=(i.top+c.y)/s.y,d=i.width/s.x,a=i.height/s.y;if(r){const m=A(r),u=n&&O(n)?A(n):n;let h=m,p=ct(h);for(;p&&n&&u!==h;){const w=H(p),g=p.getBoundingClientRect(),x=C(p),y=g.left+(p.clientLeft+parseFloat(x.paddingLeft))*w.x,b=g.top+(p.clientTop+parseFloat(x.paddingTop))*w.y;l*=w.x,f*=w.y,d*=w.x,a*=w.y,l+=y,f+=b,h=A(p),p=ct(h)}}return J({width:d,height:a,x:l,y:f})}function ut(t,e){const o=nt(t).scrollLeft;return e?e.left+o:N(E(t)).left+o}function Et(t,e,o){o===void 0&&(o=!1);const n=t.getBoundingClientRect(),i=n.left+e.scrollLeft-(o?0:ut(t,n)),r=n.top+e.scrollTop;return{x:i,y:r}}function Gt(t){let{elements:e,rect:o,offsetParent:n,strategy:i}=t;const r=i==="fixed",s=E(n),c=e?et(e.floating):!1;if(n===s||c&&r)return o;let l={scrollLeft:0,scrollTop:0},f=L(1);const d=L(0),a=T(n);if((a||!a&&!r)&&((z(n)!=="body"||Y(s))&&(l=nt(n)),T(n))){const u=N(n);f=H(n),d.x=u.x+n.clientLeft,d.y=u.y+n.clientTop}const m=s&&!a&&!r?Et(s,l,!0):L(0);return{width:o.width*f.x,height:o.height*f.y,x:o.x*f.x-l.scrollLeft*f.x+d.x+m.x,y:o.y*f.y-l.scrollTop*f.y+d.y+m.y}}function Jt(t){return Array.from(t.getClientRects())}function Qt(t){const e=E(t),o=nt(t),n=t.ownerDocument.body,i=B(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),r=B(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight);let s=-o.scrollLeft+ut(t);const c=-o.scrollTop;return C(n).direction==="rtl"&&(s+=B(e.clientWidth,n.clientWidth)-i),{width:i,height:r,x:s,y:c}}function Zt(t,e){const o=A(t),n=E(t),i=o.visualViewport;let r=n.clientWidth,s=n.clientHeight,c=0,l=0;if(i){r=i.width,s=i.height;const f=ft();(!f||f&&e==="fixed")&&(c=i.offsetLeft,l=i.offsetTop)}return{width:r,height:s,x:c,y:l}}function te(t,e){const o=N(t,!0,e==="fixed"),n=o.top+t.clientTop,i=o.left+t.clientLeft,r=T(t)?H(t):L(1),s=t.clientWidth*r.x,c=t.clientHeight*r.y,l=i*r.x,f=n*r.y;return{width:s,height:c,x:l,y:f}}function xt(t,e,o){let n;if(e==="viewport")n=Zt(t,o);else if(e==="document")n=Qt(E(t));else if(O(e))n=te(e,o);else{const i=Tt(t);n={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return J(n)}function St(t,e){const o=F(t);return o===e||!O(o)||_(o)?!1:C(o).position==="fixed"||St(o,e)}function ee(t,e){const o=e.get(t);if(o)return o;let n=$(t,[],!1).filter(c=>O(c)&&z(c)!=="body"),i=null;const r=C(t).position==="fixed";let s=r?F(t):t;for(;O(s)&&!_(s);){const c=C(s),l=lt(s);!l&&c.position==="fixed"&&(i=null),(r?!l&&!i:!l&&c.position==="static"&&!!i&&["absolute","fixed"].includes(i.position)||Y(s)&&!l&&St(t,s))?n=n.filter(d=>d!==s):i=c,s=F(s)}return e.set(t,n),n}function ne(t){let{element:e,boundary:o,rootBoundary:n,strategy:i}=t;const s=[...o==="clippingAncestors"?et(e)?[]:ee(e,this._c):[].concat(o),n],c=s[0],l=s.reduce((f,d)=>{const a=xt(e,d,i);return f.top=B(a.top,f.top),f.right=X(a.right,f.right),f.bottom=X(a.bottom,f.bottom),f.left=B(a.left,f.left),f},xt(e,c,i));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function oe(t){const{width:e,height:o}=Lt(t);return{width:e,height:o}}function ie(t,e,o){const n=T(e),i=E(e),r=o==="fixed",s=N(t,!0,r,e);let c={scrollLeft:0,scrollTop:0};const l=L(0);function f(){l.x=ut(i)}if(n||!n&&!r)if((z(e)!=="body"||Y(i))&&(c=nt(e)),n){const u=N(e,!0,r,e);l.x=u.x+e.clientLeft,l.y=u.y+e.clientTop}else i&&f();r&&!n&&i&&f();const d=i&&!n&&!r?Et(i,c):L(0),a=s.left+c.scrollLeft-l.x-d.x,m=s.top+c.scrollTop-l.y-d.y;return{x:a,y:m,width:s.width,height:s.height}}function st(t){return C(t).position==="static"}function yt(t,e){if(!T(t)||C(t).position==="fixed")return null;if(e)return e(t);let o=t.offsetParent;return E(t)===o&&(o=o.ownerDocument.body),o}function Dt(t,e){const o=A(t);if(et(t))return o;if(!T(t)){let i=F(t);for(;i&&!_(i);){if(O(i)&&!st(i))return i;i=F(i)}return o}let n=yt(t,e);for(;n&&qt(n)&&st(n);)n=yt(n,e);return n&&_(n)&&st(n)&&!lt(n)?o:n||Ut(t)||o}const se=async function(t){const e=this.getOffsetParent||Dt,o=this.getDimensions,n=await o(t.floating);return{reference:ie(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function re(t){return C(t).direction==="rtl"}const ce={convertOffsetParentRelativeRectToViewportRelativeRect:Gt,getDocumentElement:E,getClippingRect:ne,getOffsetParent:Dt,getElementRects:se,getClientRects:Jt,getDimensions:oe,getScale:H,isElement:O,isRTL:re};function Ft(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function le(t,e){let o=null,n;const i=E(t);function r(){var c;clearTimeout(n),(c=o)==null||c.disconnect(),o=null}function s(c,l){c===void 0&&(c=!1),l===void 0&&(l=1),r();const f=t.getBoundingClientRect(),{left:d,top:a,width:m,height:u}=f;if(c||e(),!m||!u)return;const h=U(a),p=U(i.clientWidth-(d+m)),w=U(i.clientHeight-(a+u)),g=U(d),y={rootMargin:-h+"px "+-p+"px "+-w+"px "+-g+"px",threshold:B(0,X(1,l))||1};let b=!0;function v(I){const V=I[0].intersectionRatio;if(V!==l){if(!b)return s();V?s(!1,V):n=setTimeout(()=>{s(!1,1e-7)},1e3)}V===1&&!Ft(f,t.getBoundingClientRect())&&s(),b=!1}try{o=new IntersectionObserver(v,{...y,root:i.ownerDocument})}catch{o=new IntersectionObserver(v,y)}o.observe(t)}return s(!0),r}function fe(t,e,o,n){n===void 0&&(n={});const{ancestorScroll:i=!0,ancestorResize:r=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:l=!1}=n,f=at(t),d=i||r?[...f?$(f):[],...$(e)]:[];d.forEach(g=>{i&&g.addEventListener("scroll",o,{passive:!0}),r&&g.addEventListener("resize",o)});const a=f&&c?le(f,o):null;let m=-1,u=null;s&&(u=new ResizeObserver(g=>{let[x]=g;x&&x.target===f&&u&&(u.unobserve(e),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var y;(y=u)==null||y.observe(e)})),o()}),f&&!l&&u.observe(f),u.observe(e));let h,p=l?N(t):null;l&&w();function w(){const g=N(t);p&&!Ft(p,g)&&o(),p=g,h=requestAnimationFrame(w)}return o(),()=>{var g;d.forEach(x=>{i&&x.removeEventListener("scroll",o),r&&x.removeEventListener("resize",o)}),a==null||a(),(g=u)==null||g.disconnect(),u=null,l&&cancelAnimationFrame(h)}}const ae=jt,ue=Yt,de=zt,me=(t,e,o)=>{const n=new Map,i={platform:ce,...o},r={...i.platform,_c:n};return $t(t,e,{...i,platform:r})};exports.autoUpdate=fe;exports.computePosition=me;exports.flip=de;exports.getOverflowAncestors=$;exports.offset=ae;exports.shift=ue;