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.
2 lines
14 KiB
2 lines
14 KiB
import{a as B}from"./use-config-816d55a6.js";import{a as I,o as $}from"./Scrollbar-35d51129.js";import{u as L}from"./use-memo-f04d43e5.js";import{k as w,r as S,P as Q,b3 as K,h as at,F as pt,bb as ht,d as X,p as ft,D as ct,s as N,dO as O,f as mt,a8 as Z,ep as xt,O as A,J as bt}from"./index-f4658ae7.js";import{b as yt}from"./next-frame-once-7035a838.js";import{u as vt}from"./light-0dfdc1ad.js";import{u as wt}from"./use-false-until-truthy-72e72eb9.js";import{c as $t,a as E}from"./cssr-e43ee704.js";import{o as Mt}from"./on-fonts-ready-d897575d.js";import{i as gt}from"./use-is-mounted-a34b74be.js";const Rt=B("n-internal-select-menu"),zt=B("n-internal-select-menu-body"),It=B("n-modal-body"),te=B("n-modal"),Bt=B("n-drawer-body"),At=B("n-popover-body"),R="__disabled__";function tt(n){const t=w(It,null),e=w(Bt,null),o=w(At,null),r=w(zt,null),p=S();if(typeof document!="undefined"){p.value=document.fullscreenElement;const u=()=>{p.value=document.fullscreenElement};Q(()=>{I("fullscreenchange",document,u)}),K(()=>{$("fullscreenchange",document,u)})}return L(()=>{var u;const{to:f}=n;return f!==void 0?f===!1?R:f===!0?p.value||"body":f:t!=null&&t.value?(u=t.value.$el)!==null&&u!==void 0?u:t.value:e!=null&&e.value?e.value:o!=null&&o.value?o.value:r!=null&&r.value?r.value:f!=null?f:p.value||"body"})}tt.tdkey=R;tt.propTo={type:[String,Object,Boolean],default:void 0};function D(n,t,e="default"){const o=t[e];if(o===void 0)throw new Error(`[vueuc/${n}]: slot[${e}] is empty.`);return o()}function F(n,t=!0,e=[]){return n.forEach(o=>{if(o!==null){if(typeof o!="object"){(typeof o=="string"||typeof o=="number")&&e.push(at(String(o)));return}if(Array.isArray(o)){F(o,t,e);return}if(o.type===pt){if(o.children===null)return;Array.isArray(o.children)&&F(o.children,t,e)}else o.type!==ht&&e.push(o)}}),e}function U(n,t,e="default"){const o=t[e];if(o===void 0)throw new Error(`[vueuc/${n}]: slot[${e}] is empty.`);const r=F(o());if(r.length===1)return r[0];throw new Error(`[vueuc/${n}]: slot[${e}] should have exactly one child.`)}let v=null;function et(){if(v===null&&(v=document.getElementById("v-binder-view-measurer"),v===null)){v=document.createElement("div"),v.id="v-binder-view-measurer";const{style:n}=v;n.position="fixed",n.left="0",n.right="0",n.top="0",n.bottom="0",n.pointerEvents="none",n.visibility="hidden",document.body.appendChild(v)}return v.getBoundingClientRect()}function Et(n,t){const e=et();return{top:t,left:n,height:0,width:0,right:e.width-n,bottom:e.height-t}}function V(n){const t=n.getBoundingClientRect(),e=et();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 Ct(n){return n.nodeType===9?null:n.parentNode}function nt(n){if(n===null)return null;const t=Ct(n);if(t===null)return null;if(t.nodeType===9)return document;if(t.nodeType===1){const{overflow:e,overflowX:o,overflowY:r}=getComputedStyle(t);if(/(auto|scroll|overlay)/.test(e+r+o))return t}return nt(t)}const Ot=X({name:"Binder",props:{syncTargetWithParent:Boolean,syncTarget:{type:Boolean,default:!0}},setup(n){var t;ft("VBinder",(t=ct())===null||t===void 0?void 0:t.proxy);const e=w("VBinder",null),o=S(null),r=s=>{o.value=s,e&&n.syncTargetWithParent&&e.setTargetRef(s)};let p=[];const u=()=>{let s=o.value;for(;s=nt(s),s!==null;)p.push(s);for(const x of p)I("scroll",x,b,!0)},f=()=>{for(const s of p)$("scroll",s,b,!0);p=[]},l=new Set,m=s=>{l.size===0&&u(),l.has(s)||l.add(s)},y=s=>{l.has(s)&&l.delete(s),l.size===0&&f()},b=()=>{yt(i)},i=()=>{l.forEach(s=>s())},d=new Set,h=s=>{d.size===0&&I("resize",window,c),d.has(s)||d.add(s)},a=s=>{d.has(s)&&d.delete(s),d.size===0&&$("resize",window,c)},c=()=>{d.forEach(s=>s())};return K(()=>{$("resize",window,c),f()}),{targetRef:o,setTargetRef:r,addScrollListener:m,removeScrollListener:y,addResizeListener:h,removeResizeListener:a}},render(){return D("binder",this.$slots)}}),ee=Ot,ne=X({name:"Target",setup(){const{setTargetRef:n,syncTarget:t}=w("VBinder");return{syncTarget:t,setTargetDirective:{mounted:n,updated:n}}},render(){const{syncTarget:n,setTargetDirective:t}=this;return n?N(U("follower",this.$slots),[[t]]):U("follower",this.$slots)}}),g="@@coContext",Zt={mounted(n,{value:t,modifiers:e}){n[g]={handler:void 0},typeof t=="function"&&(n[g].handler=t,I("clickoutside",n,t,{capture:e.capture}))},updated(n,{value:t,modifiers:e}){const o=n[g];typeof t=="function"?o.handler?o.handler!==t&&($("clickoutside",n,o.handler,{capture:e.capture}),o.handler=t,I("clickoutside",n,t,{capture:e.capture})):(n[g].handler=t,I("clickoutside",n,t,{capture:e.capture})):o.handler&&($("clickoutside",n,o.handler,{capture:e.capture}),o.handler=void 0)},unmounted(n,{modifiers:t}){const{handler:e}=n[g];e&&$("clickoutside",n,e,{capture:t.capture}),n[g].handler=void 0}},oe=Zt;class St{constructor(){this.elementZIndex=new Map,this.nextZIndex=2e3}get elementCount(){return this.elementZIndex.size}ensureZIndex(t,e){const{elementZIndex:o}=this;if(e!==void 0){t.style.zIndex=`${e}`,o.delete(t);return}const{nextZIndex:r}=this;o.has(t)&&o.get(t)+1===this.nextZIndex||(t.style.zIndex=`${r}`,o.set(t,r),this.nextZIndex=r+1,this.squashState())}unregister(t,e){const{elementZIndex:o}=this;o.has(t)?o.delete(t):e===void 0&&void 0,this.squashState()}squashState(){const{elementCount:t}=this;t||(this.nextZIndex=2e3),this.nextZIndex-t>2500&&this.rearrange()}rearrange(){const t=Array.from(this.elementZIndex.entries());t.sort((e,o)=>e[1]-o[1]),this.nextZIndex=2e3,t.forEach(e=>{const o=e[0],r=this.nextZIndex++;`${r}`!==o.style.zIndex&&(o.style.zIndex=`${r}`)})}}const j=new St,z="@@ziContext",Xt={mounted(n,t){const{value:e={}}=t,{zIndex:o,enabled:r}=e;n[z]={enabled:!!r,initialized:!1},r&&(j.ensureZIndex(n,o),n[z].initialized=!0)},updated(n,t){const{value:e={}}=t,{zIndex:o,enabled:r}=e,p=n[z].enabled;r&&!p&&(j.ensureZIndex(n,o),n[z].initialized=!0),n[z].enabled=!!r},unmounted(n,t){if(!n[z].initialized)return;const{value:e={}}=t,{zIndex:o}=e;j.unregister(n,o)}},Yt=Xt,kt=X({name:"LazyTeleport",props:{to:{type:[String,Object],default:void 0},disabled:Boolean,show:{type:Boolean,required:!0}},setup(n){return{showTeleport:wt(O(n,"show")),mergedTo:mt(()=>{const{to:t}=n;return t!=null?t:"body"})}},render(){return this.showTeleport?this.disabled?D("lazy-teleport",this.$slots):Z(xt,{disabled:this.disabled,to:this.mergedTo},D("lazy-teleport",this.$slots)):null}}),C={top:"bottom",bottom:"top",left:"right",right:"left"},J={start:"end",center:"center",end:"start"},T={top:"height",bottom:"height",left:"width",right:"width"},Vt={"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"},jt={"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"},Tt={"bottom-start":"right","bottom-end":"left","top-start":"right","top-end":"left","right-start":"bottom","right-end":"top","left-start":"bottom","left-end":"top"},G={top:!0,bottom:!1,left:!0,right:!1},H={top:"end",bottom:"start",left:"end",right:"start"};function Lt(n,t,e,o,r,p){if(!r||p)return{placement:n,top:0,left:0};const[u,f]=n.split("-");let l=f!=null?f:"center",m={top:0,left:0};const y=(d,h,a)=>{let c=0,s=0;const x=e[d]-t[h]-t[d];return x>0&&o&&(a?s=G[h]?x:-x:c=G[h]?x:-x),{left:c,top:s}},b=u==="left"||u==="right";if(l!=="center"){const d=Tt[n],h=C[d],a=T[d];if(e[a]>t[a]){if(t[d]+t[a]<e[a]){const c=(e[a]-t[a])/2;t[d]<c||t[h]<c?t[d]<t[h]?(l=J[f],m=y(a,h,b)):m=y(a,d,b):l="center"}}else e[a]<t[a]&&t[h]<0&&t[d]>t[h]&&(l=J[f])}else{const d=u==="bottom"||u==="top"?"left":"top",h=C[d],a=T[d],c=(e[a]-t[a])/2;(t[d]<c||t[h]<c)&&(t[d]>t[h]?(l=H[d],m=y(a,d,b)):(l=H[h],m=y(a,h,b)))}let i=u;return t[u]<e[T[u]]&&t[u]<t[C[u]]&&(i=C[u]),{placement:l!=="center"?`${i}-${l}`:i,left:m.left,top:m.top}}function Dt(n,t){return t?jt[n]:Vt[n]}function Ft(n,t,e,o,r,p){if(p)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+o)}px`,left:`${Math.round(e.left-t.left+r)}px`,transform:""};case"bottom-end":return{top:`${Math.round(e.top-t.top+e.height+o)}px`,left:`${Math.round(e.left-t.left+e.width+r)}px`,transform:"translateX(-100%)"};case"top-start":return{top:`${Math.round(e.top-t.top+o)}px`,left:`${Math.round(e.left-t.left+r)}px`,transform:"translateY(-100%)"};case"top-end":return{top:`${Math.round(e.top-t.top+o)}px`,left:`${Math.round(e.left-t.left+e.width+r)}px`,transform:"translateX(-100%) translateY(-100%)"};case"right-start":return{top:`${Math.round(e.top-t.top+o)}px`,left:`${Math.round(e.left-t.left+e.width+r)}px`,transform:""};case"right-end":return{top:`${Math.round(e.top-t.top+e.height+o)}px`,left:`${Math.round(e.left-t.left+e.width+r)}px`,transform:"translateY(-100%)"};case"left-start":return{top:`${Math.round(e.top-t.top+o)}px`,left:`${Math.round(e.left-t.left+r)}px`,transform:"translateX(-100%)"};case"left-end":return{top:`${Math.round(e.top-t.top+e.height+o)}px`,left:`${Math.round(e.left-t.left+r)}px`,transform:"translateX(-100%) translateY(-100%)"};case"top":return{top:`${Math.round(e.top-t.top+o)}px`,left:`${Math.round(e.left-t.left+e.width/2+r)}px`,transform:"translateY(-100%) translateX(-50%)"};case"right":return{top:`${Math.round(e.top-t.top+e.height/2+o)}px`,left:`${Math.round(e.left-t.left+e.width+r)}px`,transform:"translateY(-50%)"};case"left":return{top:`${Math.round(e.top-t.top+e.height/2+o)}px`,left:`${Math.round(e.left-t.left+r)}px`,transform:"translateY(-50%) translateX(-100%)"};case"bottom":default:return{top:`${Math.round(e.top-t.top+e.height+o)}px`,left:`${Math.round(e.left-t.left+e.width/2+r)}px`,transform:"translateX(-50%)"}}}const Kt=E([E(".v-binder-follower-container",{position:"absolute",left:"0",right:"0",top:"0",height:"0",pointerEvents:"none",zIndex:"auto"}),E(".v-binder-follower-content",{position:"absolute",zIndex:"auto"},[E("> *",{pointerEvents:"all"})])]),re=X({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=w("VBinder"),e=L(()=>n.enabled!==void 0?n.enabled:n.show),o=S(null),r=S(null),p=()=>{const{syncTrigger:i}=n;i.includes("scroll")&&t.addScrollListener(l),i.includes("resize")&&t.addResizeListener(l)},u=()=>{t.removeScrollListener(l),t.removeResizeListener(l)};Q(()=>{e.value&&(l(),p())});const f=vt();Kt.mount({id:"vueuc/binder",head:!0,anchorMetaName:$t,ssr:f}),K(()=>{u()}),Mt(()=>{e.value&&l()});const l=()=>{if(!e.value)return;const i=o.value;if(i===null)return;const d=t.targetRef,{x:h,y:a,overlap:c}=n,s=h!==void 0&&a!==void 0?Et(h,a):V(d);i.style.setProperty("--v-target-width",`${Math.round(s.width)}px`),i.style.setProperty("--v-target-height",`${Math.round(s.height)}px`);const{width:x,minWidth:Y,placement:W,internalShift:ot,flip:rt}=n;i.setAttribute("v-placement",W),c?i.setAttribute("v-overlap",""):i.removeAttribute("v-overlap");const{style:M}=i;x==="target"?M.width=`${s.width}px`:x!==void 0?M.width=x:M.width="",Y==="target"?M.minWidth=`${s.width}px`:Y!==void 0?M.minWidth=Y:M.minWidth="";const it=V(i),st=V(r.value),{left:_,top:P,placement:k}=Lt(W,s,it,ot,rt,c),q=Dt(k,c),{left:lt,top:dt,transform:ut}=Ft(k,st,s,P,_,c);i.setAttribute("v-placement",k),i.style.setProperty("--v-offset-left",`${Math.round(_)}px`),i.style.setProperty("--v-offset-top",`${Math.round(P)}px`),i.style.transform=`translateX(${lt}) translateY(${dt}) ${ut}`,i.style.setProperty("--v-transform-origin",q),i.style.transformOrigin=q};A(e,i=>{i?(p(),m()):u()});const m=()=>{bt().then(l).catch(i=>{})};["placement","x","y","internalShift","flip","width","overlap","minWidth"].forEach(i=>{A(O(n,i),l)}),["teleportDisabled"].forEach(i=>{A(O(n,i),m)}),A(O(n,"syncTrigger"),i=>{i.includes("resize")?t.addResizeListener(l):t.removeResizeListener(l),i.includes("scroll")?t.addScrollListener(l):t.removeScrollListener(l)});const y=gt(),b=L(()=>{const{to:i}=n;if(i!==void 0)return i;y.value});return{VBinder:t,mergedEnabled:e,offsetContainerRef:r,followerRef:o,mergedTo:b,syncPosition:l}},render(){return Z(kt,{show:this.show,to:this.mergedTo,disabled:this.teleportDisabled},{default:()=>{var n,t;const e=Z("div",{class:["v-binder-follower-container",this.containerClass],ref:"offsetContainerRef"},[Z("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?N(e,[[Yt,{enabled:this.mergedEnabled,zIndex:this.zIndex}]]):e}})}});export{kt as L,re as V,ne as a,ee as b,oe as c,Bt as d,te as e,zt as f,Rt as i,It as m,At as p,tt as u,Yt as z};
|