'use strict' ; import type Chart from './Chart/Chart' ; import type Options from './Options' ; import type PointerEvent from './PointerEvent' ; import H from './Globals.js' ; const { charts , doc , noop , win } = H ; import Pointer from './Pointer.js' ; import U from './Utilities.js' ; const { addEvent , css , objectEach , removeEvent } = U ; const touches = { } as Record < string , PointerEvent > ; const hasPointerEvent = ! ! win . PointerEvent ; private function getWebkitTouches ( ) { const fake = [ ] as any ; fake . item = function ( i ) : any { return this [ i ] ; } ; objectEach ( touches , function ( touch ) : void { fake . push ( { pageX : touch . pageX , pageY : touch . pageY , target : touch . target } ) ; } ) ; return fake ; } private function translateMSPointer ( e , method , wktype , func ) { const chart = charts [ Pointer . hoverChartIndex || NaN ] ; if ( ( e . pointerType === 'touch' || e . pointerType === e . MSPOINTER_TYPE_TOUCH ) && chart ) { const p = chart . pointer ; func ( e ) ; p [ method ] ( { type : wktype , target : e . currentTarget , preventDefault : noop , touches : getWebkitTouches ( ) } ) ; } } private class MSPointer extends Pointer { public static isRequired ( ) { return ! ! ( ! H . hasTouch && ( win . PointerEvent || win . MSPointerEvent ) ) ; } private function private batchMSEvents ( fn ) { fn ( this . chart . container , hasPointerEvent ? 'pointerdown' : 'MSPointerDown' , this . onContainerPointerDown ) ; fn ( this . chart . container , hasPointerEvent ? 'pointermove' : 'MSPointerMove' , this . onContainerPointerMove ) ; fn ( doc , hasPointerEvent ? 'pointerup' : 'MSPointerUp' , this . onDocumentPointerUp ) ; } public destroy ( ) { this . batchMSEvents ( removeEvent ) ; super . destroy ( ) ; } public init ( chart , options ) { super . init ( chart , options ) ; if ( this . hasZoom ) { css ( chart . container , { '-ms-touch-action' : 'none' , 'touch-action' : 'none' } ) ; } } private function private onContainerPointerDown ( e ) { translateMSPointer ( e , 'onContainerTouchStart' , 'touchstart' , function ( e ) : void { ( touches as any ) [ e . pointerId ] = { pageX : e . pageX , pageY : e . pageY , target : e . currentTarget } ; } ) ; } private function private onContainerPointerMove ( e ) { translateMSPointer ( e , 'onContainerTouchMove' , 'touchmove' , function ( e ) : void { ( touches as any ) [ e . pointerId ] = ( { pageX : e . pageX , pageY : e . pageY } ) ; if ( ! ( touches as any ) [ e . pointerId ] . target ) { ( touches as any ) [ e . pointerId ] . target = e . currentTarget ; } } ) ; } private function private onDocumentPointerUp ( e ) { translateMSPointer ( e , 'onDocumentTouchEnd' , 'touchend' , function ( e ) : void { delete ( touches as any ) [ e . pointerId ] ; } ) ; } public setDOMEvents ( ) { super . setDOMEvents ( ) ; if ( this . hasZoom || this . followTouchMove ) { this . batchMSEvents ( addEvent ) ; } } } export default MSPointer ;