{"version":3,"sources":["../../src/app/components/scrollpanel/scrollpanel.ts"],"names":["ScrollPanel","el","zone","cd","this","timeoutFrame","fn","setTimeout","prototype","ngAfterViewInit","_this","runOutsideAngular","moveBar","bind","onXBarMouseDown","onYBarMouseDown","onDocumentMouseMove","onDocumentMouseUp","window","addEventListener","contentViewChild","nativeElement","xBarViewChild","yBarViewChild","calculateContainerHeight","initialized","ngAfterContentInit","templates","forEach","item","getType","contentTemplate","template","container","containerViewChild","content","xBar","containerStyles","getComputedStyle","xBarStyles","pureContainerHeight","DomHandler","getHeight","parseInt","offsetHeight","style","height","parseFloat","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth","totalWidth","scrollWidth","ownWidth","clientWidth","bottom","clientHeight","scrollXRatio","yBar","totalHeight","scrollHeight","ownHeight","right","scrollYRatio","requestAnimationFrame","addClass","removeClass","xBarWidth","Math","max","xBarLeft","scrollLeft","cssText","yBarHeight","yBarTop","scrollTop","e","isYBarClicked","lastPageY","pageY","document","body","preventDefault","isXBarClicked","lastPageX","pageX","onMouseMoveForXBar","onMouseMoveForYBar","deltaX","deltaY","scrollableHeight","removeEventListener","f","ngOnDestroy","refresh","Component","args","selector","changeDetection","ChangeDetectionStrategy","OnPush","encapsulation","ViewEncapsulation","None","ElementRef","NgZone","ChangeDetectorRef","Input","ViewChild","ContentChildren","PrimeTemplate","NgModule","imports","CommonModule","exports","declarations"],"mappings":"shBA6BI,SAAAA,EAAmBC,EAAuBC,EAAqBC,GAA5CC,KAAAH,GAAAA,EAAuBG,KAAAF,KAAAA,EAAqBE,KAAAD,GAAAA,EAgB/DC,KAAAC,aAAoB,SAACC,GAAO,OAAAC,WAAWD,EAAI,WAc3CN,EAAAQ,UAAAC,gBAAA,WAAA,IAAAC,EAAAN,KACIA,KAAKF,KAAKS,mBAAkB,WACxBD,EAAKE,UACLF,EAAKE,QAAUF,EAAKE,QAAQC,KAAKH,GACjCA,EAAKI,gBAAkBJ,EAAKI,gBAAgBD,KAAKH,GACjDA,EA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import { NgModule, Component, Input, AfterViewInit, OnDestroy, ElementRef, NgZone, ViewChild, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, AfterContentInit, ContentChildren, QueryList, TemplateRef } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { DomHandler } from 'primeng/dom';\nimport { PrimeTemplate } from 'primeng/api';\n\n@Component({\n selector: 'p-scrollPanel',\n template: `\n
\n
\n
\n \n \n
\n
\n
\n
\n
\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n styleUrls: ['./scrollpanel.css']\n})\nexport class ScrollPanel implements AfterViewInit, AfterContentInit, OnDestroy {\n\n @Input() style: any;\n\n @Input() styleClass: string;\n \n constructor(public el: ElementRef, public zone: NgZone, public cd: ChangeDetectorRef) {}\n\n @ViewChild('container') containerViewChild: ElementRef;\n\n @ViewChild('content') contentViewChild: ElementRef;\n\n @ViewChild('xBar') xBarViewChild: ElementRef;\n \n @ViewChild('yBar') yBarViewChild: ElementRef;\n\n @ContentChildren(PrimeTemplate) templates: QueryList;\n\n scrollYRatio: number;\n\n scrollXRatio: number;\n\n timeoutFrame: any = (fn) => setTimeout(fn, 0);\n\n initialized: boolean;\n\n lastPageY: number;\n\n lastPageX: number;\n\n isXBarClicked: boolean;\n\n isYBarClicked: boolean;\n\n contentTemplate: TemplateRef;\n\n ngAfterViewInit() {\n this.zone.runOutsideAngular(() => {\n this.moveBar();\n this.moveBar = this.moveBar.bind(this);\n this.onXBarMouseDown = this.onXBarMouseDown.bind(this);\n this.onYBarMouseDown = this.onYBarMouseDown.bind(this);\n this.onDocumentMouseMove = this.onDocumentMouseMove.bind(this);\n this.onDocumentMouseUp = this.onDocumentMouseUp.bind(this);\n \n window.addEventListener('resize', this.moveBar);\n this.contentViewChild.nativeElement.addEventListener('scroll', this.moveBar);\n this.contentViewChild.nativeElement.addEventListener('mouseenter', this.moveBar);\n this.xBarViewChild.nativeElement.addEventListener('mousedown', this.onXBarMouseDown);\n this.yBarViewChild.nativeElement.addEventListener('mousedown', this.onYBarMouseDown);\n\n this.calculateContainerHeight();\n\n this.initialized = true;\n });\n }\n\n ngAfterContentInit() {\n this.templates.forEach((item) => {\n switch(item.getType()) {\n case 'content':\n this.contentTemplate = item.template;\n break;\n\n default:\n this.contentTemplate = item.template;\n break;\n }\n });\n }\n\n calculateContainerHeight() {\n let container = this.containerViewChild.nativeElement;\n let content = this.contentViewChild.nativeElement;\n let xBar = this.xBarViewChild.nativeElement;\n\n let containerStyles = getComputedStyle(container),\n xBarStyles = getComputedStyle(xBar),\n pureContainerHeight = DomHandler.getHeight(container) - parseInt(xBarStyles['height'], 10);\n\n if (containerStyles['max-height'] != \"none\" && pureContainerHeight == 0) {\n if (content.offsetHeight + parseInt(xBarStyles['height'], 10) > parseInt(containerStyles['max-height'], 10)) {\n container.style.height = containerStyles['max-height'];\n }\n else {\n container.style.height = content.offsetHeight + parseFloat(containerStyles.paddingTop) + parseFloat(containerStyles.paddingBottom) + parseFloat(containerStyles.borderTopWidth) + parseFloat(containerStyles.borderBottomWidth) + \"px\";\n }\n }\n }\n\n moveBar() {\n let container = this.containerViewChild.nativeElement;\n let content = this.contentViewChild.nativeElement;\n\n /* horizontal scroll */\n let xBar = this.xBarViewChild.nativeElement;\n let totalWidth = content.scrollWidth;\n let ownWidth = content.clientWidth;\n let bottom = (container.clientHeight - xBar.clientHeight) * -1;\n\n this.scrollXRatio = ownWidth / totalWidth;\n\n /* vertical scroll */\n let yBar = this.yBarViewChild.nativeElement;\n let totalHeight = content.scrollHeight;\n let ownHeight = content.clientHeight;\n let right = (container.clientWidth - yBar.clientWidth) * -1;\n\n this.scrollYRatio = ownHeight / totalHeight;\n\n this.requestAnimationFrame(() => {\n if (this.scrollXRatio >= 1) {\n DomHandler.addClass(xBar, 'p-scrollpanel-hidden');\n } \n else {\n DomHandler.removeClass(xBar, 'p-scrollpanel-hidden');\n const xBarWidth = Math.max(this.scrollXRatio * 100, 10);\n const xBarLeft = content.scrollLeft * (100 - xBarWidth) / (totalWidth - ownWidth);\n xBar.style.cssText = 'width:' + xBarWidth + '%; left:' + xBarLeft + '%;bottom:' + bottom + 'px;';\n }\n\n if (this.scrollYRatio >= 1) {\n DomHandler.addClass(yBar, 'p-scrollpanel-hidden');\n } \n else {\n DomHandler.removeClass(yBar, 'p-scrollpanel-hidden');\n const yBarHeight = Math.max(this.scrollYRatio * 100, 10);\n const yBarTop = content.scrollTop * (100 - yBarHeight) / (totalHeight - ownHeight);\n yBar.style.cssText = 'height:' + yBarHeight + '%; top: calc(' + yBarTop + '% - ' + xBar.clientHeight + 'px);right:' + right + 'px;';\n }\n });\n }\n\n onYBarMouseDown(e: MouseEvent) {\n this.isYBarClicked = true;\n this.lastPageY = e.pageY;\n DomHandler.addClass(this.yBarViewChild.nativeElement, 'p-scrollpanel-grabbed');\n \n DomHandler.addClass(document.body, 'p-scrollpanel-grabbed');\n\n document.addEventListener('mousemove', this.onDocumentMouseMove);\n document.addEventListener('mouseup', this.onDocumentMouseUp);\n e.preventDefault();\n }\n\n onXBarMouseDown(e: MouseEvent) {\n this.isXBarClicked = true;\n this.lastPageX = e.pageX;\n DomHandler.addClass(this.xBarViewChild.nativeElement, 'p-scrollpanel-grabbed');\n\n DomHandler.addClass(document.body, 'p-scrollpanel-grabbed');\n\n document.addEventListener('mousemove', this.onDocumentMouseMove);\n document.addEventListener('mouseup', this.onDocumentMouseUp);\n e.preventDefault();\n }\n\n onDocumentMouseMove(e: MouseEvent) {\n if (this.isXBarClicked) {\n this.onMouseMoveForXBar(e);\n }\n else if (this.isYBarClicked) {\n this.onMouseMoveForYBar(e);\n }\n else {\n this.onMouseMoveForXBar(e);\n this.onMouseMoveForYBar(e);\n }\n \n }\n\n onMouseMoveForXBar(e: MouseEvent) {\n let deltaX = e.pageX - this.lastPageX;\n this.lastPageX = e.pageX;\n\n this.requestAnimationFrame(() => {\n this.contentViewChild.nativeElement.scrollLeft += deltaX / this.scrollXRatio;\n });\n }\n\n onMouseMoveForYBar(e: MouseEvent) {\n let deltaY = e.pageY - this.lastPageY;\n this.lastPageY = e.pageY;\n\n this.requestAnimationFrame(() => {\n this.contentViewChild.nativeElement.scrollTop += deltaY / this.scrollYRatio;\n });\n }\n\n scrollTop(scrollTop: number) {\n let scrollableHeight = this.contentViewChild.nativeElement.scrollHeight - this.contentViewChild.nativeElement.clientHeight;\n scrollTop = scrollTop > scrollableHeight ? scrollableHeight : scrollTop > 0 ? scrollTop : 0;\n this.contentViewChild.nativeElement.scrollTop = scrollTop;\n }\n\n onDocumentMouseUp(e: Event) {\n DomHandler.removeClass(this.yBarViewChild.nativeElement, 'p-scrollpanel-grabbed');\n DomHandler.removeClass(this.xBarViewChild.nativeElement, 'p-scrollpanel-grabbed');\n DomHandler.removeClass(document.body, 'p-scrollpanel-grabbed');\n\n document.removeEventListener('mousemove', this.onDocumentMouseMove);\n document.removeEventListener('mouseup', this.onDocumentMouseUp);\n this.isXBarClicked = false;\n this.isYBarClicked = false;\n }\n\n requestAnimationFrame(f: Function) {\n let frame = window.requestAnimationFrame || this.timeoutFrame;\n frame(f);\n }\n\n ngOnDestroy() {\n if (this.initialized) {\n window.removeEventListener('resize', this.moveBar);\n this.contentViewChild.nativeElement.removeEventListener('scroll', this.moveBar);\n this.contentViewChild.nativeElement.removeEventListener('mouseenter', this.moveBar);\n this.xBarViewChild.nativeElement.removeEventListener('mousedown', this.onXBarMouseDown);\n this.yBarViewChild.nativeElement.removeEventListener('mousedown', this.onYBarMouseDown);\n }\n }\n\n refresh() {\n this.moveBar();\n }\n\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [ScrollPanel],\n declarations: [ScrollPanel]\n})\nexport class ScrollPanelModule { }\n"]}