| 1 |
- const t=["top","right","bottom","left"],e=["start","end"],n=t.reduce(((t,n)=>t.concat(n,n+"-"+e[0],n+"-"+e[1])),[]),r=Math.min,i=Math.max,o={left:"right",right:"left",bottom:"top",top:"bottom"};function a(t,e,n){return i(t,r(e,n))}function l(t,e){return"function"==typeof t?t(e):t}function s(t){return t.split("-")[0]}function c(t){return t.split("-")[1]}function f(t){return"x"===t?"y":"x"}function m(t){return"y"===t?"height":"width"}function u(t){const e=t[0];return"t"===e||"b"===e?"y":"x"}function d(t){return f(u(t))}function g(t,e,n){void 0===n&&(n=!1);const r=c(t),i=d(t),o=m(i);let a="x"===i?r===(n?"end":"start")?"right":"left":"start"===r?"bottom":"top";return e.reference[o]>e.floating[o]&&(a=b(a)),[a,b(a)]}function p(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const h=["left","right"],y=["right","left"],w=["top","bottom"],x=["bottom","top"];function v(t,e,n,r){const i=c(t);let o=function(t,e,n){switch(t){case"top":case"bottom":return n?e?y:h:e?h:y;case"left":case"right":return e?w:x;default:return[]}}(s(t),"start"===n,r);return i&&(o=o.map((t=>t+"-"+i)),e&&(o=o.concat(o.map(p)))),o}function b(t){const e=s(t);return o[e]+t.slice(e.length)}function A(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 R(t){const{x:e,y:n,width:r,height:i}=t;return{width:r,height:i,top:n,left:e,right:e+r,bottom:n+i,x:e,y:n}}function O(t,e,n){let{reference:r,floating:i}=t;const o=u(e),a=d(e),l=m(a),f=s(e),g="y"===o,p=r.x+r.width/2-i.width/2,h=r.y+r.height/2-i.height/2,y=r[l]/2-i[l]/2;let w;switch(f){case"top":w={x:p,y:r.y-i.height};break;case"bottom":w={x:p,y:r.y+r.height};break;case"right":w={x:r.x+r.width,y:h};break;case"left":w={x:r.x-i.width,y:h};break;default:w={x:r.x,y:r.y}}switch(c(e)){case"start":w[a]-=y*(n&&g?-1:1);break;case"end":w[a]+=y*(n&&g?-1:1)}return w}async function D(t,e){var n;void 0===e&&(e={});const{x:r,y:i,platform:o,rects:a,elements:s,strategy:c}=t,{boundary:f="clippingAncestors",rootBoundary:m="viewport",elementContext:u="floating",altBoundary:d=!1,padding:g=0}=l(e,t),p=A(g),h=s[d?"floating"===u?"reference":"floating":u],y=R(await o.getClippingRect({element:null==(n=await(null==o.isElement?void 0:o.isElement(h)))||n?h:h.contextElement||await(null==o.getDocumentElement?void 0:o.getDocumentElement(s.floating)),boundary:f,rootBoundary:m,strategy:c})),w="floating"===u?{x:r,y:i,width:a.floating.width,height:a.floating.height}:a.reference,x=await(null==o.getOffsetParent?void 0:o.getOffsetParent(s.floating)),v=await(null==o.isElement?void 0:o.isElement(x))&&await(null==o.getScale?void 0:o.getScale(x))||{x:1,y:1},b=R(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:s,rect:w,offsetParent:x,strategy:c}):w);return{top:(y.top-b.top+p.top)/v.y,bottom:(b.bottom-y.bottom+p.bottom)/v.y,left:(y.left-b.left+p.left)/v.x,right:(b.right-y.right+p.right)/v.x}}const P=async(t,e,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:o=[],platform:a}=n,l=a.detectOverflow?a:{...a,detectOverflow:D},s=await(null==a.isRTL?void 0:a.isRTL(e));let c=await a.getElementRects({reference:t,floating:e,strategy:i}),{x:f,y:m}=O(c,r,s),u=r,d=0;const g={};for(let n=0;n<o.length;n++){const p=o[n];if(!p)continue;const{name:h,fn:y}=p,{x:w,y:x,data:v,reset:b}=await y({x:f,y:m,initialPlacement:r,placement:u,strategy:i,middlewareData:g,rects:c,platform:l,elements:{reference:t,floating:e}});f=null!=w?w:f,m=null!=x?x:m,g[h]={...g[h],...v},b&&d<50&&(d++,"object"==typeof b&&(b.placement&&(u=b.placement),b.rects&&(c=!0===b.rects?await a.getElementRects({reference:t,floating:e,strategy:i}):b.rects),({x:f,y:m}=O(c,u,s))),n=-1)}return{x:f,y:m,placement:u,strategy:i,middlewareData:g}},E=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:i,placement:o,rects:s,platform:f,elements:u,middlewareData:g}=e,{element:p,padding:h=0}=l(t,e)||{};if(null==p)return{};const y=A(h),w={x:n,y:i},x=d(o),v=m(x),b=await f.getDimensions(p),R="y"===x,O=R?"top":"left",D=R?"bottom":"right",P=R?"clientHeight":"clientWidth",E=s.reference[v]+s.reference[x]-w[x]-s.floating[v],T=w[x]-s.reference[x],L=await(null==f.getOffsetParent?void 0:f.getOffsetParent(p));let k=L?L[P]:0;k&&await(null==f.isElement?void 0:f.isElement(L))||(k=u.floating[P]||s.floating[v]);const C=E/2-T/2,H=k/2-b[v]/2-1,B=r(y[O],H),S=r(y[D],H),F=B,M=k-b[v]-S,V=k/2-b[v]/2+C,W=a(F,V,M),j=!g.arrow&&null!=c(o)&&V!==W&&s.reference[v]/2-(V<F?B:S)-b[v]/2<0,z=j?V<F?V-F:V-M:0;return{[x]:w[x]+z,data:{[x]:W,centerOffset:V-W-z,...j&&{alignmentOffset:z}},reset:j}}});const T=function(t){return void 0===t&&(t={}),{name:"autoPlacement",options:t,async fn(e){var r,i,o;const{rects:a,middlewareData:f,placement:m,platform:u,elements:d}=e,{crossAxis:h=!1,alignment:y,allowedPlacements:w=n,autoAlignment:x=!0,...v}=l(t,e),b=void 0!==y||w===n?function(t,e,n){return(t?[...n.filter((e=>c(e)===t)),...n.filter((e=>c(e)!==t))]:n.filter((t=>s(t)===t))).filter((n=>!t||c(n)===t||!!e&&p(n)!==n))}(y||null,x,w):w,A=await u.detectOverflow(e,v),R=(null==(r=f.autoPlacement)?void 0:r.index)||0,O=b[R];if(null==O)return{};const D=g(O,a,await(null==u.isRTL?void 0:u.isRTL(d.floating)));if(m!==O)return{reset:{placement:b[0]}};const P=[A[s(O)],A[D[0]],A[D[1]]],E=[...(null==(i=f.autoPlacement)?void 0:i.overflows)||[],{placement:O,overflows:P}],T=b[R+1];if(T)return{data:{index:R+1,overflows:E},reset:{placement:T}};const L=E.map((t=>{const e=c(t.placement);return[t.placement,e&&h?t.overflows.slice(0,2).reduce(((t,e)=>t+e),0):t.overflows[0],t.overflows]})).sort(((t,e)=>t[1]-e[1])),k=(null==(o=L.filter((t=>t[2].slice(0,c(t[0])?2:3).every((t=>t<=0))))[0])?void 0:o[0])||L[0][0];return k!==m?{data:{index:R+1,overflows:E},reset:{placement:k}}:{}}}},L=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:i,middlewareData:o,rects:a,initialPlacement:c,platform:f,elements:m}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:y,fallbackStrategy:w="bestFit",fallbackAxisSideDirection:x="none",flipAlignment:A=!0,...R}=l(t,e);if(null!=(n=o.arrow)&&n.alignmentOffset)return{};const O=s(i),D=u(c),P=s(c)===c,E=await(null==f.isRTL?void 0:f.isRTL(m.floating)),T=y||(P||!A?[b(c)]:function(t){const e=b(t);return[p(t),e,p(e)]}(c)),L="none"!==x;!y&&L&&T.push(...v(c,A,x,E));const k=[c,...T],C=await f.detectOverflow(e,R),H=[];let B=(null==(r=o.flip)?void 0:r.overflows)||[];if(d&&H.push(C[O]),h){const t=g(i,a,E);H.push(C[t[0]],C[t[1]])}if(B=[...B,{placement:i,overflows:H}],!H.every((t=>t<=0))){var S,F;const t=((null==(S=o.flip)?void 0:S.index)||0)+1,e=k[t];if(e){if(!("alignment"===h&&D!==u(e))||B.every((t=>u(t.placement)!==D||t.overflows[0]>0)))return{data:{index:t,overflows:B},reset:{placement:e}}}let n=null==(F=B.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:F.placement;if(!n)switch(w){case"bestFit":{var M;const t=null==(M=B.filter((t=>{if(L){const e=u(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:M[0];t&&(n=t);break}case"initialPlacement":n=c}if(i!==n)return{reset:{placement:n}}}return{}}}};function k(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function C(e){return t.some((t=>e[t]>=0))}const H=function(t){return void 0===t&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n,platform:r}=e,{strategy:i="referenceHidden",...o}=l(t,e);switch(i){case"referenceHidden":{const t=k(await r.detectOverflow(e,{...o,elementContext:"reference"}),n.reference);return{data:{referenceHiddenOffsets:t,referenceHidden:C(t)}}}case"escaped":{const t=k(await r.detectOverflow(e,{...o,altBoundary:!0}),n.floating);return{data:{escapedOffsets:t,escaped:C(t)}}}default:return{}}}}};function B(t){const e=r(...t.map((t=>t.left))),n=r(...t.map((t=>t.top)));return{x:e,y:n,width:i(...t.map((t=>t.right)))-e,height:i(...t.map((t=>t.bottom)))-n}}const S=function(t){return void 0===t&&(t={}),{name:"inline",options:t,async fn(e){const{placement:n,elements:o,rects:a,platform:c,strategy:f}=e,{padding:m=2,x:d,y:g}=l(t,e),p=Array.from(await(null==c.getClientRects?void 0:c.getClientRects(o.reference))||[]),h=function(t){const e=t.slice().sort(((t,e)=>t.y-e.y)),n=[];let r=null;for(let t=0;t<e.length;t++){const i=e[t];!r||i.y-r.y>r.height/2?n.push([i]):n[n.length-1].push(i),r=i}return n.map((t=>R(B(t))))}(p),y=R(B(p)),w=A(m);const x=await c.getElementRects({reference:{getBoundingClientRect:function(){if(2===h.length&&h[0].left>h[1].right&&null!=d&&null!=g)return h.find((t=>d>t.left-w.left&&d<t.right+w.right&&g>t.top-w.top&&g<t.bottom+w.bottom))||y;if(h.length>=2){if("y"===u(n)){const t=h[0],e=h[h.length-1],r="top"===s(n),i=t.top,o=e.bottom,a=r?t.left:e.left,l=r?t.right:e.right;return{top:i,bottom:o,left:a,right:l,width:l-a,height:o-i,x:a,y:i}}const t="left"===s(n),e=i(...h.map((t=>t.right))),o=r(...h.map((t=>t.left))),a=h.filter((n=>t?n.left===o:n.right===e)),l=a[0].top,c=a[a.length-1].bottom;return{top:l,bottom:c,left:o,right:e,width:e-o,height:c-l,x:o,y:l}}return y}},floating:o.floating,strategy:f});return a.reference.x!==x.reference.x||a.reference.y!==x.reference.y||a.reference.width!==x.reference.width||a.reference.height!==x.reference.height?{reset:{rects:x}}:{}}}},F=new Set(["left","top"]);const M=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:i,y:o,placement:a,middlewareData:f}=e,m=await async function(t,e){const{placement:n,platform:r,elements:i}=t,o=await(null==r.isRTL?void 0:r.isRTL(i.floating)),a=s(n),f=c(n),m="y"===u(n),d=F.has(a)?-1:1,g=o&&m?-1:1,p=l(e,t);let{mainAxis:h,crossAxis:y,alignmentAxis:w}="number"==typeof p?{mainAxis:p,crossAxis:0,alignmentAxis:null}:{mainAxis:p.mainAxis||0,crossAxis:p.crossAxis||0,alignmentAxis:p.alignmentAxis};return f&&"number"==typeof w&&(y="end"===f?-1*w:w),m?{x:y*g,y:h*d}:{x:h*d,y:y*g}}(e,t);return a===(null==(n=f.offset)?void 0:n.placement)&&null!=(r=f.arrow)&&r.alignmentOffset?{}:{x:i+m.x,y:o+m.y,data:{...m,placement:a}}}}},V=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:i,platform:o}=e,{mainAxis:c=!0,crossAxis:m=!1,limiter:d={fn:t=>{let{x:e,y:n}=t;return{x:e,y:n}}},...g}=l(t,e),p={x:n,y:r},h=await o.detectOverflow(e,g),y=u(s(i)),w=f(y);let x=p[w],v=p[y];if(c){const t="y"===w?"bottom":"right";x=a(x+h["y"===w?"top":"left"],x,x-h[t])}if(m){const t="y"===y?"bottom":"right";v=a(v+h["y"===y?"top":"left"],v,v-h[t])}const b=d.fn({...e,[w]:x,[y]:v});return{...b,data:{x:b.x-n,y:b.y-r,enabled:{[w]:c,[y]:m}}}}}},W=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:n,y:r,placement:i,rects:o,middlewareData:a}=e,{offset:c=0,mainAxis:m=!0,crossAxis:d=!0}=l(t,e),g={x:n,y:r},p=u(i),h=f(p);let y=g[h],w=g[p];const x=l(c,e),v="number"==typeof x?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(m){const t="y"===h?"height":"width",e=o.reference[h]-o.floating[t]+v.mainAxis,n=o.reference[h]+o.reference[t]-v.mainAxis;y<e?y=e:y>n&&(y=n)}if(d){var b,A;const t="y"===h?"width":"height",e=F.has(s(i)),n=o.reference[p]-o.floating[t]+(e&&(null==(b=a.offset)?void 0:b[p])||0)+(e?0:v.crossAxis),r=o.reference[p]+o.reference[t]+(e?0:(null==(A=a.offset)?void 0:A[p])||0)-(e?v.crossAxis:0);w<n?w=n:w>r&&(w=r)}return{[h]:y,[p]:w}}}},j=function(t){return void 0===t&&(t={}),{name:"size",options:t,async fn(e){var n,o;const{placement:a,rects:f,platform:m,elements:d}=e,{apply:g=()=>{},...p}=l(t,e),h=await m.detectOverflow(e,p),y=s(a),w=c(a),x="y"===u(a),{width:v,height:b}=f.floating;let A,R;"top"===y||"bottom"===y?(A=y,R=w===(await(null==m.isRTL?void 0:m.isRTL(d.floating))?"start":"end")?"left":"right"):(R=y,A="end"===w?"top":"bottom");const O=b-h.top-h.bottom,D=v-h.left-h.right,P=r(b-h[A],O),E=r(v-h[R],D),T=!e.middlewareData.shift;let L=P,k=E;if(null!=(n=e.middlewareData.shift)&&n.enabled.x&&(k=D),null!=(o=e.middlewareData.shift)&&o.enabled.y&&(L=O),T&&!w){const t=i(h.left,0),e=i(h.right,0),n=i(h.top,0),r=i(h.bottom,0);x?k=v-2*(0!==t||0!==e?t+e:i(h.left,h.right)):L=b-2*(0!==n||0!==r?n+r:i(h.top,h.bottom))}await g({...e,availableWidth:k,availableHeight:L});const C=await m.getDimensions(d.floating);return v!==C.width||b!==C.height?{reset:{rects:!0}}:{}}}};export{E as arrow,T as autoPlacement,P as computePosition,D as detectOverflow,L as flip,H as hide,S as inline,W as limitShift,M as offset,R as rectToClientRect,V as shift,j as size};
|