You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
12 KiB
1 lines
12 KiB
import{c as q}from"./context-KbjOeZY_.js";import{a as st,d as ut,p as at,g as dt,c as k,z as pt,L as ht}from"./fade-in-scale-up.cssr-CTZmXn_X.js";import{o as S,a as B}from"./delegate-CI_DDEu_.js";import{u as V}from"./use-memo-BgHp9YyU.js";import{i as M,s as A,v as G,S as j,d as L,P as ft,R as mt,y as Q,t as y,O as X,G as Y,Q as vt}from"./index-bVOhw2NF.js";import{E as ct}from"./light-Cua7cqmF.js";import{c as bt,o as wt,a as g}from"./cssr-CS9sbUmO.js";import{i as xt}from"./use-is-mounted-wlrzLfZo.js";let O=[];const U=new WeakMap;function Mt(){O.forEach(n=>n(...U.get(n))),O=[]}function $t(n,...t){U.set(n,t),!O.includes(n)&&O.push(n)===1&&requestAnimationFrame(Mt)}const Ft=q("n-internal-select-menu"),yt=q("n-internal-select-menu-body"),H="__disabled__";function J(n){const t=M(st,null),e=M(ut,null),l=M(at,null),u=M(yt,null),m=A();if(typeof document<"u"){m.value=document.fullscreenElement;const a=()=>{m.value=document.fullscreenElement};G(()=>{S("fullscreenchange",document,a)}),j(()=>{B("fullscreenchange",document,a)})}return V(()=>{var a;const{to:h}=n;return h!==void 0?h===!1?H:h===!0?m.value||"body":h:t!=null&&t.value?(a=t.value.$el)!==null&&a!==void 0?a:t.value:e!=null&&e.value?e.value:l!=null&&l.value?l.value:u!=null&&u.value?u.value:h??(m.value||"body")})}J.tdkey=H;J.propTo={type:[String,Object,Boolean],default:void 0};let x=null;function Z(){if(x===null&&(x=document.getElementById("v-binder-view-measurer"),x===null)){x=document.createElement("div"),x.id="v-binder-view-measurer";const{style:n}=x;n.position="fixed",n.left="0",n.right="0",n.top="0",n.bottom="0",n.pointerEvents="none",n.visibility="hidden",document.body.appendChild(x)}return x.getBoundingClientRect()}function gt(n,t){const e=Z();return{top:t,left:n,height:0,width:0,right:e.width-n,bottom:e.height-t}}function I(n){const t=n.getBoundingClientRect(),e=Z();return{left:t.left-e.left,top:t.top-e.top,bottom:e.height+e.top-t.bottom,right:e.width+e.left-t.right,width:t.width,height:t.height}}function zt(n){return n.nodeType===9?null:n.parentNode}function R(n){if(n===null)return null;const t=zt(n);if(t===null)return null;if(t.nodeType===9)return document;if(t.nodeType===1){const{overflow:e,overflowX:l,overflowY:u}=getComputedStyle(t);if(/(auto|scroll|overlay)/.test(e+u+l))return t}return R(t)}const _t=L({name:"Binder",props:{syncTargetWithParent:Boolean,syncTarget:{type:Boolean,default:!0}},setup(n){var t;ft("VBinder",(t=mt())===null||t===void 0?void 0:t.proxy);const e=M("VBinder",null),l=A(null),u=r=>{l.value=r,e&&n.syncTargetWithParent&&e.setTargetRef(r)};let m=[];const a=()=>{let r=l.value;for(;r=R(r),r!==null;)m.push(r);for(const c of m)S("scroll",c,b,!0)},h=()=>{for(const r of m)B("scroll",r,b,!0);m=[]},i=new Set,v=r=>{i.size===0&&a(),i.has(r)||i.add(r)},w=r=>{i.has(r)&&i.delete(r),i.size===0&&h()},b=()=>{$t(o)},o=()=>{i.forEach(r=>r())},s=new Set,p=r=>{s.size===0&&S("resize",window,f),s.has(r)||s.add(r)},d=r=>{s.has(r)&&s.delete(r),s.size===0&&B("resize",window,f)},f=()=>{s.forEach(r=>r())};return j(()=>{B("resize",window,f),h()}),{targetRef:l,setTargetRef:u,addScrollListener:v,removeScrollListener:w,addResizeListener:p,removeResizeListener:d}},render(){return dt("binder",this.$slots)}}),kt=L({name:"Target",setup(){const{setTargetRef:n,syncTarget:t}=M("VBinder");return{syncTarget:t,setTargetDirective:{mounted:n,updated:n}}},render(){const{syncTarget:n,setTargetDirective:t}=this;return n?Q(k("follower",this.$slots),[[t]]):k("follower",this.$slots)}}),z={top:"bottom",bottom:"top",left:"right",right:"left"},K={start:"end",center:"center",end:"start"},N={top:"height",bottom:"height",left:"width",right:"width"},Bt={"bottom-start":"top left",bottom:"top center","bottom-end":"top right","top-start":"bottom left",top:"bottom center","top-end":"bottom right","right-start":"top left",right:"center left","right-end":"bottom left","left-start":"top right",left:"center right","left-end":"bottom right"},At={"bottom-start":"bottom left",bottom:"bottom center","bottom-end":"bottom right","top-start":"top left",top:"top center","top-end":"top right","right-start":"top right",right:"center right","right-end":"bottom right","left-start":"top left",left:"center left","left-end":"bottom left"},Ot={"bottom-start":"right","bottom-end":"left","top-start":"right","top-end":"left","right-start":"bottom","right-end":"top","left-start":"bottom","left-end":"top"},P={top:!0,bottom:!1,left:!0,right:!1},T={top:"end",bottom:"start",left:"end",right:"start"};function Ct(n,t,e,l,u,m){if(!u||m)return{placement:n,top:0,left:0};const[a,h]=n.split("-");let i=h??"center",v={top:0,left:0};const w=(s,p,d)=>{let f=0,r=0;const c=e[s]-t[p]-t[s];return c>0&&l&&(d?r=P[p]?c:-c:f=P[p]?c:-c),{left:f,top:r}},b=a==="left"||a==="right";if(i!=="center"){const s=Ot[n],p=z[s],d=N[s];if(e[d]>t[d]){if(t[s]+t[d]<e[d]){const f=(e[d]-t[d])/2;t[s]<f||t[p]<f?t[s]<t[p]?(i=K[h],v=w(d,p,b)):v=w(d,s,b):i="center"}}else e[d]<t[d]&&t[p]<0&&t[s]>t[p]&&(i=K[h])}else{const s=a==="bottom"||a==="top"?"left":"top",p=z[s],d=N[s],f=(e[d]-t[d])/2;(t[s]<f||t[p]<f)&&(t[s]>t[p]?(i=T[s],v=w(d,s,b)):(i=T[p],v=w(d,p,b)))}let o=a;return t[a]<e[N[a]]&&t[a]<t[z[a]]&&(o=z[a]),{placement:i!=="center"?`${o}-${i}`:o,left:v.left,top:v.top}}function Et(n,t){return t?At[n]:Bt[n]}function Xt(n,t,e,l,u,m){if(m)switch(n){case"bottom-start":return{top:`${Math.round(e.top-t.top+e.height)}px`,left:`${Math.round(e.left-t.left)}px`,transform:"translateY(-100%)"};case"bottom-end":return{top:`${Math.round(e.top-t.top+e.height)}px`,left:`${Math.round(e.left-t.left+e.width)}px`,transform:"translateX(-100%) translateY(-100%)"};case"top-start":return{top:`${Math.round(e.top-t.top)}px`,left:`${Math.round(e.left-t.left)}px`,transform:""};case"top-end":return{top:`${Math.round(e.top-t.top)}px`,left:`${Math.round(e.left-t.left+e.width)}px`,transform:"translateX(-100%)"};case"right-start":return{top:`${Math.round(e.top-t.top)}px`,left:`${Math.round(e.left-t.left+e.width)}px`,transform:"translateX(-100%)"};case"right-end":return{top:`${Math.round(e.top-t.top+e.height)}px`,left:`${Math.round(e.left-t.left+e.width)}px`,transform:"translateX(-100%) translateY(-100%)"};case"left-start":return{top:`${Math.round(e.top-t.top)}px`,left:`${Math.round(e.left-t.left)}px`,transform:""};case"left-end":return{top:`${Math.round(e.top-t.top+e.height)}px`,left:`${Math.round(e.left-t.left)}px`,transform:"translateY(-100%)"};case"top":return{top:`${Math.round(e.top-t.top)}px`,left:`${Math.round(e.left-t.left+e.width/2)}px`,transform:"translateX(-50%)"};case"right":return{top:`${Math.round(e.top-t.top+e.height/2)}px`,left:`${Math.round(e.left-t.left+e.width)}px`,transform:"translateX(-100%) translateY(-50%)"};case"left":return{top:`${Math.round(e.top-t.top+e.height/2)}px`,left:`${Math.round(e.left-t.left)}px`,transform:"translateY(-50%)"};case"bottom":default:return{top:`${Math.round(e.top-t.top+e.height)}px`,left:`${Math.round(e.left-t.left+e.width/2)}px`,transform:"translateX(-50%) translateY(-100%)"}}switch(n){case"bottom-start":return{top:`${Math.round(e.top-t.top+e.height+l)}px`,left:`${Math.round(e.left-t.left+u)}px`,transform:""};case"bottom-end":return{top:`${Math.round(e.top-t.top+e.height+l)}px`,left:`${Math.round(e.left-t.left+e.width+u)}px`,transform:"translateX(-100%)"};case"top-start":return{top:`${Math.round(e.top-t.top+l)}px`,left:`${Math.round(e.left-t.left+u)}px`,transform:"translateY(-100%)"};case"top-end":return{top:`${Math.round(e.top-t.top+l)}px`,left:`${Math.round(e.left-t.left+e.width+u)}px`,transform:"translateX(-100%) translateY(-100%)"};case"right-start":return{top:`${Math.round(e.top-t.top+l)}px`,left:`${Math.round(e.left-t.left+e.width+u)}px`,transform:""};case"right-end":return{top:`${Math.round(e.top-t.top+e.height+l)}px`,left:`${Math.round(e.left-t.left+e.width+u)}px`,transform:"translateY(-100%)"};case"left-start":return{top:`${Math.round(e.top-t.top+l)}px`,left:`${Math.round(e.left-t.left+u)}px`,transform:"translateX(-100%)"};case"left-end":return{top:`${Math.round(e.top-t.top+e.height+l)}px`,left:`${Math.round(e.left-t.left+u)}px`,transform:"translateX(-100%) translateY(-100%)"};case"top":return{top:`${Math.round(e.top-t.top+l)}px`,left:`${Math.round(e.left-t.left+e.width/2+u)}px`,transform:"translateY(-100%) translateX(-50%)"};case"right":return{top:`${Math.round(e.top-t.top+e.height/2+l)}px`,left:`${Math.round(e.left-t.left+e.width+u)}px`,transform:"translateY(-50%)"};case"left":return{top:`${Math.round(e.top-t.top+e.height/2+l)}px`,left:`${Math.round(e.left-t.left+u)}px`,transform:"translateY(-50%) translateX(-100%)"};case"bottom":default:return{top:`${Math.round(e.top-t.top+e.height+l)}px`,left:`${Math.round(e.left-t.left+e.width/2+u)}px`,transform:"translateX(-50%)"}}}const Yt=g([g(".v-binder-follower-container",{position:"absolute",left:"0",right:"0",top:"0",height:"0",pointerEvents:"none",zIndex:"auto"}),g(".v-binder-follower-content",{position:"absolute",zIndex:"auto"},[g("> *",{pointerEvents:"all"})])]),Kt=L({name:"Follower",inheritAttrs:!1,props:{show:Boolean,enabled:{type:Boolean,default:void 0},placement:{type:String,default:"bottom"},syncTrigger:{type:Array,default:["resize","scroll"]},to:[String,Object],flip:{type:Boolean,default:!0},internalShift:Boolean,x:Number,y:Number,width:String,minWidth:String,containerClass:String,teleportDisabled:Boolean,zindexable:{type:Boolean,default:!0},zIndex:Number,overlap:Boolean},setup(n){const t=M("VBinder"),e=V(()=>n.enabled!==void 0?n.enabled:n.show),l=A(null),u=A(null),m=()=>{const{syncTrigger:o}=n;o.includes("scroll")&&t.addScrollListener(i),o.includes("resize")&&t.addResizeListener(i)},a=()=>{t.removeScrollListener(i),t.removeResizeListener(i)};G(()=>{e.value&&(i(),m())});const h=ct();Yt.mount({id:"vueuc/binder",head:!0,anchorMetaName:bt,ssr:h}),j(()=>{a()}),wt(()=>{e.value&&i()});const i=()=>{if(!e.value)return;const o=l.value;if(o===null)return;const s=t.targetRef,{x:p,y:d,overlap:f}=n,r=p!==void 0&&d!==void 0?gt(p,d):I(s);o.style.setProperty("--v-target-width",`${Math.round(r.width)}px`),o.style.setProperty("--v-target-height",`${Math.round(r.height)}px`);const{width:c,minWidth:C,placement:D,internalShift:tt,flip:et}=n;o.setAttribute("v-placement",D),f?o.setAttribute("v-overlap",""):o.removeAttribute("v-overlap");const{style:$}=o;c==="target"?$.width=`${r.width}px`:c!==void 0?$.width=c:$.width="",C==="target"?$.minWidth=`${r.width}px`:C!==void 0?$.minWidth=C:$.minWidth="";const nt=I(o),ot=I(u.value),{left:W,top:F,placement:E}=Ct(D,r,nt,tt,et,f),_=Et(E,f),{left:rt,top:it,transform:lt}=Xt(E,ot,r,F,W,f);o.setAttribute("v-placement",E),o.style.setProperty("--v-offset-left",`${Math.round(W)}px`),o.style.setProperty("--v-offset-top",`${Math.round(F)}px`),o.style.transform=`translateX(${rt}) translateY(${it}) ${lt}`,o.style.setProperty("--v-transform-origin",_),o.style.transformOrigin=_};y(e,o=>{o?(m(),v()):a()});const v=()=>{vt().then(i).catch(o=>console.error(o))};["placement","x","y","internalShift","flip","width","overlap","minWidth"].forEach(o=>{y(X(n,o),i)}),["teleportDisabled"].forEach(o=>{y(X(n,o),v)}),y(X(n,"syncTrigger"),o=>{o.includes("resize")?t.addResizeListener(i):t.removeResizeListener(i),o.includes("scroll")?t.addScrollListener(i):t.removeScrollListener(i)});const w=xt(),b=V(()=>{const{to:o}=n;if(o!==void 0)return o;w.value});return{VBinder:t,mergedEnabled:e,offsetContainerRef:u,followerRef:l,mergedTo:b,syncPosition:i}},render(){return Y(ht,{show:this.show,to:this.mergedTo,disabled:this.teleportDisabled},{default:()=>{var n,t;const e=Y("div",{class:["v-binder-follower-container",this.containerClass],ref:"offsetContainerRef"},[Y("div",{class:"v-binder-follower-content",ref:"followerRef"},(t=(n=this.$slots).default)===null||t===void 0?void 0:t.call(n))]);return this.zindexable?Q(e,[[pt,{enabled:this.mergedEnabled,zIndex:this.zIndex}]]):e}})}});export{_t as B,kt as V,Kt as a,$t as b,yt as c,Ft as i,J as u};
|