|
|
@@ -1,125 +1,7 @@
|
|
|
import { Rect } from '../util/geom'
|
|
|
import { computeRect } from '../util/dom-geom'
|
|
|
+import { ScrollController, ElScrollController, WindowScrollController } from './scroll-controller'
|
|
|
|
|
|
-// TODO: join with RTL scroller normalization utils
|
|
|
-
|
|
|
-export abstract class ScrollController {
|
|
|
-
|
|
|
- abstract getScrollTop(): number
|
|
|
- abstract getScrollLeft(): number
|
|
|
- abstract setScrollTop(number): void
|
|
|
- abstract setScrollLeft(number): void
|
|
|
- abstract getClientWidth(): number
|
|
|
- abstract getClientHeight(): number
|
|
|
- abstract getScrollWidth(): number
|
|
|
- abstract getScrollHeight(): number
|
|
|
-
|
|
|
- getMaxScrollTop() {
|
|
|
- return this.getScrollHeight() - this.getClientHeight()
|
|
|
- }
|
|
|
-
|
|
|
- getMaxScrollLeft() {
|
|
|
- return this.getScrollWidth() - this.getClientWidth()
|
|
|
- }
|
|
|
-
|
|
|
- canScrollUp() {
|
|
|
- return this.getScrollTop() > 0
|
|
|
- }
|
|
|
-
|
|
|
- canScrollDown() {
|
|
|
- return this.getScrollTop() < this.getMaxScrollTop()
|
|
|
- }
|
|
|
-
|
|
|
- canScrollLeft() {
|
|
|
- return this.getScrollLeft() > 0
|
|
|
- }
|
|
|
-
|
|
|
- canScrollRight() {
|
|
|
- return this.getScrollLeft() < this.getMaxScrollLeft()
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-export class ElScrollController extends ScrollController {
|
|
|
-
|
|
|
- el: HTMLElement
|
|
|
-
|
|
|
- constructor(el: HTMLElement) {
|
|
|
- super()
|
|
|
- this.el = el
|
|
|
- }
|
|
|
-
|
|
|
- getScrollTop() {
|
|
|
- return this.el.scrollTop
|
|
|
- }
|
|
|
-
|
|
|
- getScrollLeft() {
|
|
|
- return this.el.scrollLeft
|
|
|
- }
|
|
|
-
|
|
|
- setScrollTop(n: number) {
|
|
|
- this.el.scrollTop = n
|
|
|
- }
|
|
|
-
|
|
|
- setScrollLeft(n: number) {
|
|
|
- this.el.scrollLeft = n
|
|
|
- }
|
|
|
-
|
|
|
- getScrollWidth() {
|
|
|
- return this.el.scrollWidth
|
|
|
- }
|
|
|
-
|
|
|
- getScrollHeight() {
|
|
|
- return this.el.scrollHeight
|
|
|
- }
|
|
|
-
|
|
|
- getClientHeight() {
|
|
|
- return this.el.clientHeight
|
|
|
- }
|
|
|
-
|
|
|
- getClientWidth() {
|
|
|
- return this.el.clientWidth
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-export class WindowScrollController extends ScrollController {
|
|
|
-
|
|
|
- getScrollTop() {
|
|
|
- return window.scrollY
|
|
|
- }
|
|
|
-
|
|
|
- getScrollLeft() {
|
|
|
- return window.scrollX
|
|
|
- }
|
|
|
-
|
|
|
- setScrollTop(n: number) {
|
|
|
- window.scroll(window.scrollX, n)
|
|
|
- }
|
|
|
-
|
|
|
- setScrollLeft(n: number) {
|
|
|
- window.scroll(n, window.scrollY)
|
|
|
- }
|
|
|
-
|
|
|
- getScrollWidth() {
|
|
|
- return document.documentElement.scrollWidth
|
|
|
- }
|
|
|
-
|
|
|
- getScrollHeight() {
|
|
|
- return document.documentElement.scrollHeight
|
|
|
- }
|
|
|
-
|
|
|
- getClientHeight() {
|
|
|
- return document.documentElement.clientHeight
|
|
|
- }
|
|
|
-
|
|
|
- getClientWidth() {
|
|
|
- return document.documentElement.clientWidth
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// TODO: more of a "dimensions" cache
|
|
|
export abstract class ScrollControllerCache extends ScrollController {
|
|
|
|
|
|
rect: Rect
|
|
|
@@ -220,6 +102,10 @@ export class ElScrollControllerCache extends ScrollControllerCache {
|
|
|
|
|
|
scrollController: ElScrollController
|
|
|
|
|
|
+ constructor(el: HTMLElement, doesListening) {
|
|
|
+ super(new ElScrollController(el), doesListening)
|
|
|
+ }
|
|
|
+
|
|
|
getEventTarget(): EventTarget {
|
|
|
return this.scrollController.el
|
|
|
}
|
|
|
@@ -234,6 +120,10 @@ export class WindowScrollControllerCache extends ScrollControllerCache {
|
|
|
|
|
|
scrollController: WindowScrollController
|
|
|
|
|
|
+ constructor(doesListening) {
|
|
|
+ super(new WindowScrollController(), doesListening)
|
|
|
+ }
|
|
|
+
|
|
|
getEventTarget(): EventTarget {
|
|
|
return window
|
|
|
}
|