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