From e6d09a98072e33dfdb42073bca893beb3bad4003 Mon Sep 17 00:00:00 2001 From: Dennis Francis Date: Wed, 11 Jan 2023 15:28:29 +0530 Subject: [PATCH] browser: fix TS eslint issues in ScrollSection Signed-off-by: Dennis Francis Change-Id: I08d345bea972f8fac44975a915bf939cb6396d93 --- browser/src/layer/tile/ScrollSection.ts | 90 ++++++++++++++----------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/browser/src/layer/tile/ScrollSection.ts b/browser/src/layer/tile/ScrollSection.ts index d08d2067d..8e9d1baa4 100644 --- a/browser/src/layer/tile/ScrollSection.ts +++ b/browser/src/layer/tile/ScrollSection.ts @@ -4,7 +4,9 @@ declare var L: any; declare var app: any; -class ScrollSection extends CanvasSectionObject { +namespace cool { + +export class ScrollSection extends CanvasSectionObject { map: any; autoScrollTimer: any; @@ -37,7 +39,7 @@ class ScrollSection extends CanvasSectionObject { this.map.on('updatescrolloffset', this.onUpdateScrollOffset, this); } - public onInitialize () { + public onInitialize (): void { this.sectionProperties.docLayer = this.map._docLayer; this.sectionProperties.mapPane = ((document.querySelectorAll('.leaflet-map-pane')[0])); this.sectionProperties.defaultCursorStyle = this.sectionProperties.mapPane.style.cursor; @@ -99,14 +101,15 @@ class ScrollSection extends CanvasSectionObject { this.sectionProperties.quickScrollHorizontalTimer = null; } - public completePendingScroll() { + public completePendingScroll(): void { if (this.pendingScrollEvent) { this.onScrollTo(this.pendingScrollEvent, true /* force */); this.pendingScrollEvent = null; } } - public onScrollTo (e: any, force: boolean = false) { + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + public onScrollTo (e: any, force: boolean = false): void { if (!force && !this.containerObject.drawingAllowed()) { // Only remember the last scroll-to position. this.pendingScrollEvent = e; @@ -117,7 +120,8 @@ class ScrollSection extends CanvasSectionObject { this.map.scrollLeft(e.x, {}); } - public onScrollBy (e: any) { + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + public onScrollBy (e: any): void { if (this.map._docLayer._docType !== 'spreadsheet') { this.scrollVerticalWithOffset(e.y); this.scrollHorizontalWithOffset(e.x); @@ -146,7 +150,8 @@ class ScrollSection extends CanvasSectionObject { } } - public onScrollVelocity (e: any) { + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + public onScrollVelocity (e: any): void { if (e.vx === 0 && e.vy === 0) { clearInterval(this.autoScrollTimer); this.autoScrollTimer = null; @@ -175,7 +180,8 @@ class ScrollSection extends CanvasSectionObject { } } - public onHandleAutoScroll (e :any) { + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + public onHandleAutoScroll (e :any): void { var vx = 0; var vy = 0; @@ -196,7 +202,7 @@ class ScrollSection extends CanvasSectionObject { this.onScrollVelocity({vx: vx, vy: vy}); } - private getVerticalScrollLength () :number { + private getVerticalScrollLength (): number { var result: number = this.containerObject.getDocumentAnchorSection().size[1]; this.sectionProperties.yOffset = this.containerObject.getDocumentAnchorSection().myTopLeft[1]; @@ -241,7 +247,8 @@ class ScrollSection extends CanvasSectionObject { } } - public getVerticalScrollProperties () :any { + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + public getVerticalScrollProperties (): any { this.calculateYMinMax(); var result: any = {}; result.scrollLength = this.getVerticalScrollLength(); // The length of the railway that the scroll bar moves on up & down. @@ -261,7 +268,7 @@ class ScrollSection extends CanvasSectionObject { return result; } - private getHorizontalScrollLength () :number { + private getHorizontalScrollLength (): number { var result: number = this.containerObject.getDocumentAnchorSection().size[0]; this.sectionProperties.xOffset = this.containerObject.getDocumentAnchorSection().myTopLeft[0]; @@ -281,12 +288,12 @@ class ScrollSection extends CanvasSectionObject { } } - private calculateHorizontalScrollSize (scrollLength: number) :number { + private calculateHorizontalScrollSize (scrollLength: number): number { var scrollSize = Math.round(scrollLength * scrollLength / app.view.size.pixels[0]); return scrollSize; } - private calculateXMinMax () { + private calculateXMinMax (): void { var diff: number = Math.round(app.view.size.pixels[0] - this.containerObject.getDocumentAnchorSection().size[0]); if (diff >= 0) { @@ -306,7 +313,8 @@ class ScrollSection extends CanvasSectionObject { } } - public getHorizontalScrollProperties () :any { + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + public getHorizontalScrollProperties (): any { this.calculateXMinMax(); var result: any = {}; result.scrollLength = this.getHorizontalScrollLength(); // The length of the railway that the scroll bar moves on left & right. @@ -326,14 +334,14 @@ class ScrollSection extends CanvasSectionObject { return result; } - public onUpdateScrollOffset () { + public onUpdateScrollOffset (): void { if (this.map._docLayer._docType === 'spreadsheet') { this.map._docLayer.refreshViewData(); this.map._docLayer.updateScollLimit(); } } - private DrawVerticalScrollBarMobile () { + private DrawVerticalScrollBarMobile (): void { var scrollProps: any = this.getVerticalScrollProperties(); if (this.sectionProperties.animatingVerticalScrollBar) @@ -383,7 +391,7 @@ class ScrollSection extends CanvasSectionObject { this.context.globalAlpha = 1.0; } - private drawVerticalScrollBar () { + private drawVerticalScrollBar (): void { var scrollProps: any = this.getVerticalScrollProperties(); var startX = this.isCalcRTL() ? this.sectionProperties.edgeOffset : this.size[0] - this.sectionProperties.scrollBarThickness - this.sectionProperties.edgeOffset; @@ -426,7 +434,7 @@ class ScrollSection extends CanvasSectionObject { } } - private drawHorizontalScrollBar () { + private drawHorizontalScrollBar (): void { var scrollProps: any = this.getHorizontalScrollProperties(); var startY = this.size[1] - this.sectionProperties.scrollBarThickness - this.sectionProperties.edgeOffset; @@ -473,7 +481,7 @@ class ScrollSection extends CanvasSectionObject { } - private calculateCurrentAlpha (elapsedTime: number) { + private calculateCurrentAlpha (elapsedTime: number): void { if (elapsedTime >= this.sectionProperties.fadeOutStartingTime) { this.sectionProperties.currentAlpha = Math.max((1 - ((elapsedTime - this.sectionProperties.fadeOutStartingTime) / this.sectionProperties.fadeOutDuration)) * this.sectionProperties.alphaWhenVisible, 0.1); } @@ -482,7 +490,7 @@ class ScrollSection extends CanvasSectionObject { } } - public onDraw (frameCount: number, elapsedTime: number) { + public onDraw (frameCount: number, elapsedTime: number): void { if (this.isAnimating && frameCount >= 0) this.calculateCurrentAlpha(elapsedTime); @@ -498,12 +506,12 @@ class ScrollSection extends CanvasSectionObject { } } - public onAnimationEnded (frameCount: number, elapsedTime: number) { + public onAnimationEnded (frameCount: number, elapsedTime: number): void { this.sectionProperties.animatingVerticalScrollBar = false; this.sectionProperties.animatingHorizontalScrollBar = false; } - private fadeOutHorizontalScrollBar () { + private fadeOutHorizontalScrollBar (): void { if (this.isAnimating) { this.resetAnimation(); this.sectionProperties.animatingHorizontalScrollBar = true; @@ -517,7 +525,7 @@ class ScrollSection extends CanvasSectionObject { } } - private fadeOutVerticalScrollBar () { + private fadeOutVerticalScrollBar (): void { if (this.isAnimating) { this.resetAnimation(); this.sectionProperties.animatingVerticalScrollBar = true; @@ -531,7 +539,7 @@ class ScrollSection extends CanvasSectionObject { } } - private hideVerticalScrollBar () { + private hideVerticalScrollBar (): void { if (this.sectionProperties.mouseIsOnVerticalScrollBar) { this.sectionProperties.mouseIsOnVerticalScrollBar = false; this.sectionProperties.mapPane.style.cursor = this.sectionProperties.defaultCursorStyle; @@ -548,7 +556,7 @@ class ScrollSection extends CanvasSectionObject { } } - private showVerticalScrollBar () { + private showVerticalScrollBar (): void { if (this.isAnimating && this.sectionProperties.animatingVerticalScrollBar) this.containerObject.stopAnimating(); @@ -561,7 +569,7 @@ class ScrollSection extends CanvasSectionObject { } } - private hideHorizontalScrollBar () { + private hideHorizontalScrollBar (): void { if (this.sectionProperties.mouseIsOnHorizontalScrollBar) { this.sectionProperties.mouseIsOnHorizontalScrollBar = false; this.sectionProperties.mapPane.style.cursor = this.sectionProperties.defaultCursorStyle; @@ -578,7 +586,7 @@ class ScrollSection extends CanvasSectionObject { } } - private showHorizontalScrollBar () { + private showHorizontalScrollBar (): void { if (this.isAnimating && this.sectionProperties.animatingHorizontalScrollBar) this.containerObject.stopAnimating(); @@ -591,7 +599,7 @@ class ScrollSection extends CanvasSectionObject { } } - private isMouseOnScrollBar (point: Array) { + private isMouseOnScrollBar (point: Array): void { const mirrorX = this.isCalcRTL(); if (this.documentTopLeft[1] >= 0) { if ((!mirrorX && point[0] >= this.size[0] - this.sectionProperties.usableThickness) @@ -624,12 +632,12 @@ class ScrollSection extends CanvasSectionObject { } } - public onMouseLeave () { + public onMouseLeave (): void { this.hideVerticalScrollBar(); this.hideHorizontalScrollBar(); } - public scrollVerticalWithOffset (offset: number) { + public scrollVerticalWithOffset (offset: number): void { var go = true; if (offset > 0) { if (this.documentTopLeft[1] + offset > this.sectionProperties.yMax) @@ -652,7 +660,7 @@ class ScrollSection extends CanvasSectionObject { } } - public scrollHorizontalWithOffset (offset: number) { + public scrollHorizontalWithOffset (offset: number): void { var go = true; if (offset > 0) { if (this.documentTopLeft[0] + offset > this.sectionProperties.xMax) @@ -678,6 +686,7 @@ class ScrollSection extends CanvasSectionObject { return this.containerObject.doesSectionIncludePoint(docSection, point); } + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types private isMousePointerSycnWithVerticalScrollBar (scrollProps: any, position: Array): boolean { // Keep this desktop-only for now. if (!(window).mode.isDesktop()) @@ -708,6 +717,7 @@ class ScrollSection extends CanvasSectionObject { return pointerIsSyncWithScrollBar; } + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types private isMousePointerSycnWithHorizontalScrollBar (scrollProps: any, position: Array): boolean { // Keep this desktop-only for now. if (!(window).mode.isDesktop()) @@ -743,7 +753,7 @@ class ScrollSection extends CanvasSectionObject { return pointerIsSyncWithScrollBar; } - public onMouseMove (position: Array, dragDistance: Array, e: MouseEvent) { + public onMouseMove (position: Array, dragDistance: Array, e: MouseEvent): void { this.clearQuickScrollTimeout(); if (this.sectionProperties.clickScrollVertical && this.containerObject.isDraggingSomething()) { @@ -794,7 +804,7 @@ class ScrollSection extends CanvasSectionObject { When user presses the button while the mouse pointer is on the railway of the scroll bar but not on the scroll bar directly, we quickly scroll the document to that position. */ - private quickScrollVertical (point: Array, originalSign?: number) { + private quickScrollVertical (point: Array, originalSign?: number): void { // Desktop only for now. if (!(window).mode.isDesktop()) return; @@ -826,7 +836,7 @@ class ScrollSection extends CanvasSectionObject { When user presses the button while the mouse pointer is on the railway of the scroll bar but not on the scroll bar directly, we quickly scroll the document to that position. */ - private quickScrollHorizontal (point: Array, originalSign?: number) { + private quickScrollHorizontal (point: Array, originalSign?: number): void { // Desktop only for now. if (!(window).mode.isDesktop()) return; @@ -878,7 +888,7 @@ class ScrollSection extends CanvasSectionObject { } } - public onMouseDown (point: Array, e: MouseEvent) { + public onMouseDown (point: Array, e: MouseEvent): void { this.clearQuickScrollTimeout(); this.onMouseMove(point, null, e); this.isMouseOnScrollBar(point); @@ -926,7 +936,7 @@ class ScrollSection extends CanvasSectionObject { } } - public onMouseUp (point: Array, e: MouseEvent) { + public onMouseUp (point: Array, e: MouseEvent): void { this.map.scrollingIsHandled = false; this.clearQuickScrollTimeout(); @@ -965,7 +975,7 @@ class ScrollSection extends CanvasSectionObject { this.onMouseMove(point, null, e); } - private performVerticalScroll (delta: number) { + private performVerticalScroll (delta: number): void { this.scrollVerticalWithOffset(delta); if (!this.sectionProperties.drawVerticalScrollBar) { if (this.isAnimating) { @@ -977,7 +987,7 @@ class ScrollSection extends CanvasSectionObject { } } - private performHorizontalScroll (delta: number) { + private performHorizontalScroll (delta: number): void { this.scrollHorizontalWithOffset(delta); if (!this.sectionProperties.drawHorizontalScrollBar) { if (this.isAnimating) { @@ -989,7 +999,7 @@ class ScrollSection extends CanvasSectionObject { } } - public onMouseWheel (point: Array, delta: Array, e: MouseEvent) { + public onMouseWheel (point: Array, delta: Array, e: MouseEvent): void { if (e.ctrlKey) return; @@ -1005,6 +1015,8 @@ class ScrollSection extends CanvasSectionObject { } } +} + L.getNewScrollSection = function () { - return new ScrollSection(); + return new cool.ScrollSection(); };