import { Injectable , Inject , NgZone } from '@angular/core' ; import { ThyClickDispatcher } from './event-dispatchers/index' ; export interface ThyClickPosition { x : number ; y : number ; } @ Injectable ( { providedIn : 'root' } ) export class ThyClickPositioner { private lastPosition : ThyClickPosition = null ; private initialized = false ; constructor ( private clickDispatcher ) { } get lastClickPosition ( ) : ThyClickPosition | null { return this . lastPosition ; } runTaskUseLastPosition ( task ) { setTimeout ( ( ) => { task ( this . lastClickPosition ) ; } ) ; } initialize ( ) { if ( this . initialized ) { return ; } this . initialized = true ; this . clickDispatcher . clicked ( 0 ) . subscribe ( ( event ) => { this . lastPosition = { x : event . clientX , y : event . clientY } ; } ) ; } }