Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
package.dist.prod.delegate.ScrollEnablement.js.map Maven / Gradle / Ivy
{
"version": 3,
"sources": ["../../../src/delegate/ScrollEnablement.ts"],
"sourcesContent": ["import { supportsTouch } from \"../Device.js\";\nimport EventProvider from \"../EventProvider.js\";\nimport scroll from \"../animations/scroll.js\";\nimport type UI5Element from \"../UI5Element.js\";\n\nconst scrollEventName = \"scroll\";\nconst touchEndEventName = supportsTouch() ? \"touchend\" : \"mouseup\";\n\ntype ScrollEnablementEventListenerParam = {\n\tisLeft: boolean;\n\tisRight: boolean\n}\ntype ScrollEnablementEventListenerReturn = void;\n\nclass ScrollEnablement extends EventProvider {\n\tcontainerComponent: UI5Element;\n\tmouseMove: (event: MouseEvent | TouchEvent) => void;\n\tmouseUp: (event: MouseEvent | TouchEvent) => void;\n\ttouchStart: (event: MouseEvent | TouchEvent) => void;\n\tcachedValue: { dragX: number, dragY: number };\n\tstartX: number;\n\tstartY: number;\n\t_container?: HTMLElement;\n\tsupportsTouch = supportsTouch();\n\t_canScroll?: boolean;\n\t_prevDragX?: number;\n\t_prevDragY?: number;\n\n\tconstructor(containerComponent: UI5Element) {\n\t\tsuper();\n\t\tthis.containerComponent = containerComponent;\n\t\tthis.mouseMove = this.ontouchmove.bind(this);\n\t\tthis.mouseUp = this.ontouchend.bind(this);\n\t\tthis.touchStart = this.ontouchstart.bind(this);\n\n\t\tthis.supportsTouch = supportsTouch();\n\n\t\t// On Android devices touchmove is thrown one more time than neccessary (together with touchend)\n\t\t// so we have to cache the previus coordinates in order to provide correct parameters in the\n\t\t// event for Android\n\t\tthis.cachedValue = { dragX: 0, dragY: 0 };\n\n\t\t// In components like Carousel you need to know if the user has clicked on something or swiped\n\t\t// in order to throw the needed event or not\n\t\tthis.startX = 0;\n\t\tthis.startY = 0;\n\n\t\tif (this.supportsTouch) {\n\t\t\tcontainerComponent.addEventListener(\"touchstart\", this.touchStart, { passive: true });\n\t\t\tcontainerComponent.addEventListener(\"touchmove\", this.mouseMove, { passive: true });\n\t\t\tcontainerComponent.addEventListener(\"touchend\", this.mouseUp, { passive: true });\n\t\t} else {\n\t\t\tcontainerComponent.addEventListener(\"mousedown\", this.touchStart, { passive: true });\n\t\t}\n\t}\n\n\tset scrollContainer(container: HTMLElement) {\n\t\tthis._container = container;\n\t}\n\n\tget scrollContainer() {\n\t\treturn this._container!;\n\t}\n\n\t/**\n\t * Scrolls the container to the left/top position, retrying retryCount times, if the container is not yet painted\n\t *\n\t * @param left\n\t * @param top\n\t * @param retryCount\n\t * @param retryInterval\n\t * @returns {Promise} resolved when scrolled successfully\n\t */\n\tasync scrollTo(left: number, top: number, retryCount = 0, retryInterval = 0) {\n\t\tlet containerPainted = this.scrollContainer.clientHeight > 0 && this.scrollContainer.clientWidth > 0;\n\n\t\t/* eslint-disable no-loop-func, no-await-in-loop */\n\t\twhile (!containerPainted && retryCount > 0) {\n\t\t\tawait new Promise(resolve => {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tcontainerPainted = this.scrollContainer.clientHeight > 0 && this.scrollContainer.clientWidth > 0;\n\t\t\t\t\tretryCount--;\n\t\t\t\t\tresolve();\n\t\t\t\t}, retryInterval);\n\t\t\t});\n\t\t}\n\t\t/* eslint-disable no-loop-func, no-await-in-loop */\n\n\t\tthis._container!.scrollLeft = left;\n\t\tthis._container!.scrollTop = top;\n\t}\n\n\tmove(dx: number, dy: number, disableAnimation: boolean) {\n\t\tif (disableAnimation) {\n\t\t\tthis._container!.scrollLeft += dx;\n\t\t\tthis._container!.scrollTop += dy;\n\t\t\treturn;\n\t\t}\n\n\t\tif (this._container) {\n\t\t\treturn scroll(this._container, dx, dy);\n\t\t}\n\t}\n\n\tgetScrollLeft() {\n\t\treturn this._container!.scrollLeft;\n\t}\n\n\tgetScrollTop() {\n\t\treturn this._container!.scrollTop;\n\t}\n\n\t_isTouchInside(event: TouchEvent | MouseEvent) {\n\t\tlet touch = null;\n\t\tif (this.supportsTouch && event instanceof TouchEvent) {\n\t\t\ttouch = event.touches[0];\n\t\t}\n\n\t\tconst rect = this._container!.getBoundingClientRect();\n\t\tconst x = this.supportsTouch ? (touch as TouchInit).clientX : (event as MouseEvent).x;\n\t\tconst y = this.supportsTouch ? (touch as TouchInit).clientY : (event as MouseEvent).y;\n\n\t\treturn x! >= rect.left && x! <= rect.right\n\t\t\t&& y! >= rect.top && y! <= rect.bottom;\n\t}\n\n\tontouchstart(event: TouchEvent | MouseEvent) {\n\t\tlet touch = null;\n\t\tif (this.supportsTouch && event instanceof TouchEvent) {\n\t\t\ttouch = event.touches[0];\n\t\t}\n\n\t\tif (!touch) {\n\t\t\tdocument.addEventListener(\"mouseup\", this.mouseUp, { passive: true });\n\t\t\tdocument.addEventListener(\"mousemove\", this.mouseMove, { passive: true });\n\t\t} else {\n\t\t\t// Needed only on mobile\n\t\t\tthis.startX = touch.pageX;\n\t\t\tthis.startY = touch.pageY;\n\t\t}\n\n\t\tif (touch) {\n\t\t\tthis._prevDragX = touch.pageX;\n\t\t\tthis._prevDragY = touch.pageY;\n\t\t}\n\n\t\tif (event instanceof MouseEvent) {\n\t\t\tthis._prevDragX = event.x;\n\t\t\tthis._prevDragY = event.y;\n\t\t}\n\n\t\tthis._canScroll = this._isTouchInside(event);\n\t}\n\n\tontouchmove(event: TouchEvent | MouseEvent) {\n\t\tif (!this._canScroll) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst container = this._container;\n\t\tconst touch = this.supportsTouch ? (event as TouchEvent).touches[0] : null;\n\n\t\tconst dragX = this.supportsTouch ? (touch as TouchInit).pageX : (event as MouseEvent).x;\n\t\tconst dragY = this.supportsTouch ? (touch as TouchInit).pageY : (event as MouseEvent).y;\n\n\t\tcontainer!.scrollLeft += this._prevDragX! - dragX!;\n\t\tcontainer!.scrollTop += this._prevDragY! - dragY!;\n\n\t\tthis.fireEvent(scrollEventName, {\n\t\t\tisLeft: dragX! > this._prevDragX!,\n\t\t\tisRight: dragX! < this._prevDragX!,\n\t\t});\n\n\t\tthis.cachedValue.dragX = this._prevDragX!;\n\t\tthis.cachedValue.dragY = this._prevDragY!;\n\n\t\tthis._prevDragX = dragX;\n\t\tthis._prevDragY = dragY;\n\t}\n\n\tontouchend(event: TouchEvent | MouseEvent) {\n\t\tif (this.supportsTouch) {\n\t\t\tconst deltaX = Math.abs((event as TouchEvent).changedTouches[0].pageX - this.startX);\n\t\t\tconst deltaY = Math.abs((event as TouchEvent).changedTouches[0].pageY - this.startY);\n\n\t\t\tif (deltaX < 10 && deltaY < 10) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tif (!this._canScroll) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst container = this._container;\n\t\tconst dragX = this.supportsTouch ? (event as TouchEvent).changedTouches[0].pageX : (event as MouseEvent).x;\n\t\tconst dragY = this.supportsTouch ? (event as TouchEvent).changedTouches[0].pageY : (event as MouseEvent).y;\n\n\t\tcontainer!.scrollLeft += this._prevDragX! - dragX;\n\t\tcontainer!.scrollTop += this._prevDragY! - dragY;\n\n\t\tconst useCachedValues = dragX === this._prevDragX;\n\t\tconst _dragX = useCachedValues ? this.cachedValue.dragX : dragX;\n\t\t// const _dragY = useCachedValues ? this.cachedValue.dragY : dragY; add if needed\n\n\t\tthis.fireEvent(touchEndEventName, {\n\t\t\tisLeft: _dragX < this._prevDragX!,\n\t\t\tisRight: _dragX > this._prevDragX!,\n\t\t});\n\n\t\tthis._prevDragX = dragX;\n\t\tthis._prevDragY = dragY;\n\n\t\tif (!this.supportsTouch) {\n\t\t\tdocument.removeEventListener(\"mousemove\", this.mouseMove);\n\t\t\tdocument.removeEventListener(\"mouseup\", this.mouseUp);\n\t\t}\n\t}\n}\n\nexport default ScrollEnablement;\nexport type {\n\tScrollEnablementEventListenerParam,\n};\n"],
"mappings": "aAAA,OAAS,iBAAAA,MAAqB,eAC9B,OAAOC,MAAmB,sBAC1B,OAAO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AASD,EAAqB,EAEtFV,EAAW,YAAc,KAAK,WAAce,EAC5Cf,EAAW,WAAa,KAAK,WAAcgB,EAE3C,KAAK,UAAUpB,EAAiB,CAC/B,OAAQmB,EAAS,KAAK,WACtB,QAASA,EAAS,KAAK,UACxB,CAAC,EAED,KAAK,YAAY,MAAQ,KAAK,WAC9B,KAAK,YAAY,MAAQ,KAAK,WAE9B,KAAK,WAAaA,EAClB,KAAK,WAAaC,CACnB,CAEA,WAAWN,EAAgC,CAC1C,GAAI,KAAK,cAAe,CACvB,MAAMO,EAAS,KAAK,IAAKP,EAAqB,eAAe,CAAC,EAAE,MAAQ,KAAK,MAAM,EAC7EQ,EAAS,KAAK,IAAKR,EAAqB,eAAe,CAAC,EAAE,MAAQ,KAAK,MAAM,EAEnF,GAAIO,EAAS,IAAMC,EAAS,GAC3B,MAEF,CAEA,GAAI,CAAC,KAAK,WACT,OAGD,MAAMlB,EAAY,KAAK,WACjBe,EAAQ,KAAK,cAAiBL,EAAqB,eAAe,CAAC,EAAE,MAASA,EAAqB,EACnGM,EAAQ,KAAK,cAAiBN,EAAqB,eAAe,CAAC,EAAE,MAASA,EAAqB,EAEzGV,EAAW,YAAc,KAAK,WAAce,EAC5Cf,EAAW,WAAa,KAAK,WAAcgB,EAG3C,MAAMG,EADkBJ,IAAU,KAAK,WACN,KAAK,YAAY,MAAQA,EAG1D,KAAK,UAAUlB,EAAmB,CACjC,OAAQsB,EAAS,KAAK,WACtB,QAASA,EAAS,KAAK,UACxB,CAAC,EAED,KAAK,WAAaJ,EAClB,KAAK,WAAaC,EAEb,KAAK,gBACT,SAAS,oBAAoB,YAAa,KAAK,SAAS,EACxD,SAAS,oBAAoB,UAAW,KAAK,OAAO,EAEtD,CACD,CAEA,eAAelB",
"names": ["supportsTouch", "EventProvider", "scroll", "scrollEventName", "touchEndEventName", "ScrollEnablement", "containerComponent", "container", "left", "top", "retryCount", "retryInterval", "containerPainted", "resolve", "dx", "dy", "disableAnimation", "event", "touch", "rect", "x", "y", "dragX", "dragY", "deltaX", "deltaY", "_dragX"]
}