@leafer-in/scroll
Version:
3 lines (2 loc) • 2.57 kB
JavaScript
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.scroll=function(t,s){"use strict";class i extends s.Group{get isOutside(){return!0}constructor(t,i){super(),this.config={theme:"light",padding:0,minSize:10},t.isApp&&(t.sky.add(this),t=t.tree),this.target=t,i&&s.DataHelper.assign(this.config,i),this.changeTheme(this.config.theme),this.waitLeafer(this.__listenEvents,this)}changeTheme(t){let i;"string"==typeof t?(i={fill:"black",stroke:"rgba(255,255,255,0.8)"},"dark"===t&&(i.fill="white",i.stroke="rgba(0,0,0,0.2)")):i=t,this.scrollXBar||this.addMany(this.scrollXBar=new s.Box,this.scrollYBar=new s.Box),i=Object.assign({strokeAlign:"center",opacity:.5,width:6,cornerRadius:3,hoverStyle:{opacity:.6},pressStyle:{opacity:.7}},i),i.height||(i.height=i.width),this.scrollXBar.set(Object.assign(Object.assign({},i),{visible:!1})),this.scrollYBar.set(Object.assign(Object.assign({},i),{visible:!1})),this.leafer&&this.update()}update(t){if(this.dragScrolling)return;const{minSize:i,padding:e}=this.config,{zoomLayer:r,canvas:h}=this.target.leafer,{worldRenderBounds:a}=r;if(t&&this.scrollBounds&&this.scrollBounds.isSame(a))return;this.scrollBounds=new s.Bounds(a);const n=h.bounds.clone().shrink(e),o=n.clone().add(a),l=this.ratioX=n.width/o.width,g=this.ratioY=n.height/o.height,d=(n.x-o.x)/o.width,c=(n.y-o.y)/o.height,u=l<1,v=g<1,{scrollXBar:f,scrollYBar:p}=this,{x:_,y:y,width:m,height:B}=n.shrink([2,v?p.width+6:2,u?f.height+6:2,2]);f.set({x:_+m*d,y:y+B+2,width:Math.max(m*l,i),visible:u}),p.set({x:_+m+2,y:y+B*c,height:Math.max(B*g,i),visible:v})}onDrag(t){this.dragScrolling=!0,this.__dragOut=this.app.config.move.dragOut,this.app.config.move.dragOut=!1;const s=t.current===this.scrollXBar,i=this.target.leafer.getValidMove(s?-t.moveX/this.ratioX:0,s?0:-t.moveY/this.ratioY);this.target.moveWorld(i.x,i.y),t.current.moveWorld(i.x&&-i.x*this.ratioX,i.y&&-i.y*this.ratioY)}onDragEnd(){this.dragScrolling=!1,this.app.config.move.dragOut=this.__dragOut}__listenEvents(){const{scrollXBar:t,scrollYBar:i}=this;this.__eventIds=[t.on_(s.DragEvent.DRAG,this.onDrag,this),i.on_(s.DragEvent.DRAG,this.onDrag,this),t.on_(s.DragEvent.END,this.onDragEnd,this),i.on_(s.DragEvent.END,this.onDragEnd,this),this.target.on_(s.RenderEvent.BEFORE,(()=>this.update(!0))),this.target.leafer.on_(s.ResizeEvent.RESIZE,(()=>this.update()))]}__removeListenEvents(){this.off_(this.__eventIds)}destroy(){this.destroyed||(this.__removeListenEvents(),this.target=this.config=null,super.destroy())}}return s.Plugin.add("scroll"),t.ScrollBar=i,t}({},LeaferUI);
//# sourceMappingURL=scroll.min.js.map