2023-05-31 11:51:07 +08:00

2 lines
7.2 KiB
JavaScript

import{t as ae,c as W,v as oe,T as le,e as re}from"./event-ff03ec12.js";import{b as Y,u as Q,_ as U,i as Z,d as ne,a as H,e as j,w as ie,ai as ce}from"./base-962c0c23.js";import{d as N,D as ue,r as m,c as _,J as fe,$ as F,b as T,m as D,p as ee,L as ve,f as $,n as C,u as d,h as X,e as te,q as K,F as me,w as I,A as V,E as de,M as pe,o as he,W as ye,g as ge,U as be,C as we,k as Se}from"./runtime-core.esm-bundler-dc7a07d7.js";const se=Symbol("scrollbarContextKey"),E=4,ze={vertical:{offset:"offsetHeight",scroll:"scrollTop",scrollSize:"scrollHeight",size:"height",key:"vertical",axis:"Y",client:"clientY",direction:"top"},horizontal:{offset:"offsetWidth",scroll:"scrollLeft",scrollSize:"scrollWidth",size:"width",key:"horizontal",axis:"X",client:"clientX",direction:"left"}},Ee=({move:a,size:t,bar:s})=>({[s.size]:t,transform:`translate${s.axis}(${a}%)`}),_e=Y({vertical:Boolean,size:String,move:Number,ratio:{type:Number,required:!0},always:Boolean}),ke="Thumb",He=N({__name:"thumb",props:_e,setup(a){const t=a,s=ue(se),o=Q("scrollbar");s||ae(ke,"can not inject scrollbar context");const i=m(),u=m(),n=m({}),v=m(!1);let r=!1,p=!1,h=Z?document.onselectstart:null;const l=_(()=>ze[t.vertical?"vertical":"horizontal"]),g=_(()=>Ee({size:t.size,move:t.move,bar:l.value})),b=_(()=>i.value[l.value.offset]**2/s.wrapElement[l.value.scrollSize]/t.ratio/u.value[l.value.offset]),w=c=>{var e;if(c.stopPropagation(),c.ctrlKey||[1,2].includes(c.button))return;(e=window.getSelection())==null||e.removeAllRanges(),M(c);const f=c.currentTarget;f&&(n.value[l.value.axis]=f[l.value.offset]-(c[l.value.client]-f.getBoundingClientRect()[l.value.direction]))},P=c=>{if(!u.value||!i.value||!s.wrapElement)return;const e=Math.abs(c.target.getBoundingClientRect()[l.value.direction]-c[l.value.client]),f=u.value[l.value.offset]/2,S=(e-f)*100*b.value/i.value[l.value.offset];s.wrapElement[l.value.scroll]=S*s.wrapElement[l.value.scrollSize]/100},M=c=>{c.stopImmediatePropagation(),r=!0,document.addEventListener("mousemove",x),document.addEventListener("mouseup",z),h=document.onselectstart,document.onselectstart=()=>!1},x=c=>{if(!i.value||!u.value||r===!1)return;const e=n.value[l.value.axis];if(!e)return;const f=(i.value.getBoundingClientRect()[l.value.direction]-c[l.value.client])*-1,S=u.value[l.value.offset]-e,k=(f-S)*100*b.value/i.value[l.value.offset];s.wrapElement[l.value.scroll]=k*s.wrapElement[l.value.scrollSize]/100},z=()=>{r=!1,n.value[l.value.axis]=0,document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",z),B(),p&&(v.value=!1)},A=()=>{p=!1,v.value=!!t.size},O=()=>{p=!0,v.value=r};fe(()=>{B(),document.removeEventListener("mouseup",z)});const B=()=>{document.onselectstart!==h&&(document.onselectstart=h)};return W(F(s,"scrollbarElement"),"mousemove",A),W(F(s,"scrollbarElement"),"mouseleave",O),(c,e)=>(T(),D(le,{name:d(o).b("fade"),persisted:""},{default:ee(()=>[ve($("div",{ref_key:"instance",ref:i,class:C([d(o).e("bar"),d(o).is(d(l).key)]),onMousedown:P},[$("div",{ref_key:"thumb",ref:u,class:C(d(o).e("thumb")),style:X(d(g)),onMousedown:w},null,38)],34),[[oe,c.always||v.value]])]),_:1},8,["name"]))}});var q=U(He,[["__file","/home/runner/work/element-plus/element-plus/packages/components/scrollbar/src/thumb.vue"]]);const Te=Y({always:{type:Boolean,default:!0},width:String,height:String,ratioX:{type:Number,default:1},ratioY:{type:Number,default:1}}),Ce=N({__name:"bar",props:Te,setup(a,{expose:t}){const s=a,o=m(0),i=m(0);return t({handleScroll:n=>{if(n){const v=n.offsetHeight-E,r=n.offsetWidth-E;i.value=n.scrollTop*100/v*s.ratioY,o.value=n.scrollLeft*100/r*s.ratioX}}}),(n,v)=>(T(),te(me,null,[K(q,{move:o.value,ratio:n.ratioX,size:n.width,always:n.always},null,8,["move","ratio","size","always"]),K(q,{move:i.value,ratio:n.ratioY,size:n.height,vertical:"",always:n.always},null,8,["move","ratio","size","always"])],64))}});var xe=U(Ce,[["__file","/home/runner/work/element-plus/element-plus/packages/components/scrollbar/src/bar.vue"]]);const Be=Y({height:{type:[String,Number],default:""},maxHeight:{type:[String,Number],default:""},native:{type:Boolean,default:!1},wrapStyle:{type:ne([String,Object,Array]),default:""},wrapClass:{type:[String,Array],default:""},viewClass:{type:[String,Array],default:""},viewStyle:{type:[String,Array,Object],default:""},noresize:Boolean,tag:{type:String,default:"div"},always:Boolean,minSize:{type:Number,default:20}}),Re={scroll:({scrollTop:a,scrollLeft:t})=>[a,t].every(H)},Le="ElScrollbar",Ne=N({name:Le}),Pe=N({...Ne,props:Be,emits:Re,setup(a,{expose:t,emit:s}){const o=a,i=Q("scrollbar");let u,n;const v=m(),r=m(),p=m(),h=m("0"),l=m("0"),g=m(),b=m(1),w=m(1),P=_(()=>{const e={};return o.height&&(e.height=j(o.height)),o.maxHeight&&(e.maxHeight=j(o.maxHeight)),[o.wrapStyle,e]}),M=_(()=>[o.wrapClass,i.e("wrap"),{[i.em("wrap","hidden-default")]:!o.native}]),x=_(()=>[i.e("view"),o.viewClass]),z=()=>{var e;r.value&&((e=g.value)==null||e.handleScroll(r.value),s("scroll",{scrollTop:r.value.scrollTop,scrollLeft:r.value.scrollLeft}))};function A(e,f){Se(e)?r.value.scrollTo(e):H(e)&&H(f)&&r.value.scrollTo(e,f)}const O=e=>{H(e)&&(r.value.scrollTop=e)},B=e=>{H(e)&&(r.value.scrollLeft=e)},c=()=>{if(!r.value)return;const e=r.value.offsetHeight-E,f=r.value.offsetWidth-E,S=e**2/r.value.scrollHeight,k=f**2/r.value.scrollWidth,R=Math.max(S,o.minSize),L=Math.max(k,o.minSize);b.value=S/(e-S)/(R/(e-R)),w.value=k/(f-k)/(L/(f-L)),l.value=R+E<e?`${R}px`:"",h.value=L+E<f?`${L}px`:""};return I(()=>o.noresize,e=>{e?(u==null||u(),n==null||n()):({stop:u}=re(p,c),n=W("resize",c))},{immediate:!0}),I(()=>[o.maxHeight,o.height],()=>{o.native||V(()=>{var e;c(),r.value&&((e=g.value)==null||e.handleScroll(r.value))})}),de(se,pe({scrollbarElement:v,wrapElement:r})),he(()=>{o.native||V(()=>{c()})}),ye(()=>c()),t({wrapRef:r,update:c,scrollTo:A,setScrollTop:O,setScrollLeft:B,handleScroll:z}),(e,f)=>(T(),te("div",{ref_key:"scrollbarRef",ref:v,class:C(d(i).b())},[$("div",{ref_key:"wrapRef",ref:r,class:C(d(M)),style:X(d(P)),onScroll:z},[(T(),D(be(e.tag),{ref_key:"resizeRef",ref:p,class:C(d(x)),style:X(e.viewStyle)},{default:ee(()=>[ge(e.$slots,"default")]),_:3},8,["class","style"]))],38),e.native?we("v-if",!0):(T(),D(xe,{key:0,ref_key:"barRef",ref:g,height:l.value,width:h.value,always:e.always,"ratio-x":w.value,"ratio-y":b.value},null,8,["height","width","always","ratio-x","ratio-y"]))],2))}});var Me=U(Pe,[["__file","/home/runner/work/element-plus/element-plus/packages/components/scrollbar/src/scrollbar.vue"]]);const De=ie(Me),y=new Map;let G;Z&&(document.addEventListener("mousedown",a=>G=a),document.addEventListener("mouseup",a=>{for(const t of y.values())for(const{documentHandler:s}of t)s(a,G)}));function J(a,t){let s=[];return Array.isArray(t.arg)?s=t.arg:ce(t.arg)&&s.push(t.arg),function(o,i){const u=t.instance.popperRef,n=o.target,v=i==null?void 0:i.target,r=!t||!t.instance,p=!n||!v,h=a.contains(n)||a.contains(v),l=a===n,g=s.length&&s.some(w=>w==null?void 0:w.contains(n))||s.length&&s.includes(v),b=u&&(u.contains(n)||u.contains(v));r||p||h||l||g||b||t.value(o,i)}}const $e={beforeMount(a,t){y.has(a)||y.set(a,[]),y.get(a).push({documentHandler:J(a,t),bindingFn:t.value})},updated(a,t){y.has(a)||y.set(a,[]);const s=y.get(a),o=s.findIndex(u=>u.bindingFn===t.oldValue),i={documentHandler:J(a,t),bindingFn:t.value};o>=0?s.splice(o,1,i):s.push(i)},unmounted(a){y.delete(a)}};export{ze as B,$e as C,De as E};