ohctechv3/.svn/pristine/22/226c78d086cca2b9fbacf8065621a0b850bc75bc.svn-base

2 lines
12 KiB
Plaintext
Raw Normal View History

2024-10-28 15:03:36 +05:30
const t=["top","right","bottom","left"],e=["start","end"],n=t.reduce(((t,n)=>t.concat(n,n+"-"+e[0],n+"-"+e[1])),[]),o=Math.min,r=Math.max,i={left:"right",right:"left",bottom:"top",top:"bottom"},a={start:"end",end:"start"};function l(t,e,n){return r(t,o(e,n))}function s(t,e){return"function"==typeof t?t(e):t}function c(t){return t.split("-")[0]}function f(t){return t.split("-")[1]}function m(t){return"x"===t?"y":"x"}function u(t){return"y"===t?"height":"width"}function g(t){return["top","bottom"].includes(c(t))?"y":"x"}function d(t){return m(g(t))}function p(t,e,n){void 0===n&&(n=!1);const o=f(t),r=d(t),i=u(r);let a="x"===r?o===(n?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[i]>e.floating[i]&&(a=y(a)),[a,y(a)]}function h(t){return t.replace(/start|end/g,(t=>a[t]))}function y(t){return t.replace(/left|right|bottom|top/g,(t=>i[t]))}function w(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 x(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}function v(t,e,n){let{reference:o,floating:r}=t;const i=g(e),a=d(e),l=u(a),s=c(e),m="y"===i,p=o.x+o.width/2-r.width/2,h=o.y+o.height/2-r.height/2,y=o[l]/2-r[l]/2;let w;switch(s){case"top":w={x:p,y:o.y-r.height};break;case"bottom":w={x:p,y:o.y+o.height};break;case"right":w={x:o.x+o.width,y:h};break;case"left":w={x:o.x-r.width,y:h};break;default:w={x:o.x,y:o.y}}switch(f(e)){case"start":w[a]-=y*(n&&m?-1:1);break;case"end":w[a]+=y*(n&&m?-1:1)}return w}const b=async(t,e,n)=>{const{placement:o="bottom",strategy:r="absolute",middleware:i=[],platform:a}=n,l=i.filter(Boolean),s=await(null==a.isRTL?void 0:a.isRTL(e));let c=await a.getElementRects({reference:t,floating:e,strategy:r}),{x:f,y:m}=v(c,o,s),u=o,g={},d=0;for(let n=0;n<l.length;n++){const{name:i,fn:p}=l[n],{x:h,y:y,data:w,reset:x}=await p({x:f,y:m,initialPlacement:o,placement:u,strategy:r,middlewareData:g,rects:c,platform:a,elements:{reference:t,floating:e}});f=null!=h?h:f,m=null!=y?y:m,g={...g,[i]:{...g[i],...w}},x&&d<=50&&(d++,"object"==typeof x&&(x.placement&&(u=x.placement),x.rects&&(c=!0===x.rects?await a.getElementRects({reference:t,floating:e,strategy:r}):x.rects),({x:f,y:m}=v(c,u,s))),n=-1)}return{x:f,y:m,placement:u,strategy:r,middlewareData:g}};async function A(t,e){var n;void 0===e&&(e={});const{x:o,y:r,platform:i,rects:a,elements:l,strategy:c}=t,{boundary:f="clippingAncestors",rootBoundary:m="viewport",elementContext:u="floating",altBoundary:g=!1,padding:d=0}=s(e,t),p=w(d),h=l[g?"floating"===u?"reference":"floating":u],y=x(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(h)))||n?h:h.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(l.floating)),boundary:f,rootBoundary:m,strategy:c})),v="floating"===u?{...a.floating,x:o,y:r}:a.reference,b=await(null==i.getOffsetParent?void 0:i.getOffsetParent(l.floating)),A=await(null==i.isElement?void 0:i.isElement(b))&&await(null==i.getScale?void 0:i.getScale(b))||{x:1,y:1},R=x(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:v,offsetParent:b,strategy:c}):v);return{top:(y.top-R.top+p.top)/A.y,bottom:(R.bottom-y.bottom+p.bottom)/A.y,left:(y.left-R.left+p.left)/A.x,right:(R.right-y.right+p.right)/A.x}}const R=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:i,rects:a,platform:c,elements:m,middlewareData:g}=e,{element:p,padding:h=0}=s(t,e)||{};if(null==p)return{};const y=w(h),x={x:n,y:r},v=d(i),b=u(v),A=await c.getDimensions(p),R="y"===v,P=R?"top":"left",D=R?"bottom":"right",E=R?"clientHeight":"clientWidth",O=a.reference[b]+a.reference[v]-x[v]-a.floating[b],T=x[v]-a.reference[v],L=await(null==c.getOffsetParent?void 0:c.getOffsetParent(p));let k=L?L[E]:0;k&&await(null==c.isElement?void 0:c.isElement(L))||(k=m.floating[E]||a.floating[b]);const B=O/2-T/2,C=k/2-A[b]/2-1,H=o(y[P],C),S=o(y[D],C),F=H,M=k-A[b]-S,V=k/2-A[b]/2+B,W=l(F,V,M),j=!g.arrow&&null!=f(i)&&V!==W&&a.reference[b]/2-(V<F?H:S)-A[b]/2<0,z=j?V<F?