@@ -127,6 +127,53 @@ export function containsOffset (el: HTMLElement, offsetX?: number, offsetY?: num
127127 ( typeof offsetY === 'undefined' || offsetY >= 0 && maxY >= offsetY ) ;
128128}
129129
130+ export function getEventAbsoluteCoordinates ( ev : MouseEvent ) : AxisValues < number > {
131+ const el = ev . target || ev . srcElement ;
132+ const pageCoordinates = getEventPageCoordinates ( ev ) ;
133+ const curDocument = domUtils . findDocument ( el ) ;
134+ let xOffset = 0 ;
135+ let yOffset = 0 ;
136+
137+ if ( domUtils . isElementInIframe ( curDocument . documentElement ) ) {
138+ const currentIframe = domUtils . getIframeByElement ( curDocument ) ;
139+
140+ if ( currentIframe ) {
141+ const iframeOffset = getOffsetPosition ( currentIframe ) ;
142+ const iframeBorders = styleUtils . getBordersWidth ( currentIframe ) ;
143+
144+ xOffset = iframeOffset . left + iframeBorders . left ;
145+ yOffset = iframeOffset . top + iframeBorders . top ;
146+ }
147+ }
148+
149+ return new AxisValues ( pageCoordinates . x + xOffset , pageCoordinates . y + yOffset ) ;
150+ }
151+
152+ export function getEventPageCoordinates ( ev : MouseEvent ) : AxisValues < number > {
153+ const curCoordObject = / ^ t o u c h / . test ( ev . type ) && ( ev as unknown as TouchEvent ) . targetTouches ? ( ev as unknown as TouchEvent ) . targetTouches [ 0 ] || ( ev as unknown as TouchEvent ) . changedTouches [ 0 ] : ev ;
154+
155+ const bothPageCoordinatesAreZero = curCoordObject . pageX === 0 && curCoordObject . pageY === 0 ;
156+ const notBothClientCoordinatesAreZero = curCoordObject . clientX !== 0 || curCoordObject . clientY !== 0 ;
157+
158+ if ( ( curCoordObject . pageX === null || bothPageCoordinatesAreZero && notBothClientCoordinatesAreZero ) &&
159+ curCoordObject . clientX !== null ) {
160+ const currentDocument = domUtils . findDocument ( ev . target || ev . srcElement ) ;
161+ const html = currentDocument . documentElement ;
162+ const body = currentDocument . body ;
163+
164+ return new AxisValues < number > (
165+ Math . round ( curCoordObject . clientX + ( html && html . scrollLeft || body && body . scrollLeft || 0 ) -
166+ ( html . clientLeft || 0 ) ) ,
167+ Math . round ( curCoordObject . clientY + ( html && html . scrollTop || body && body . scrollTop || 0 ) -
168+ ( html . clientTop || 0 ) )
169+ ) ;
170+ }
171+ return new AxisValues < number > (
172+ Math . round ( curCoordObject . pageX ) ,
173+ Math . round ( curCoordObject . pageY )
174+ ) ;
175+ }
176+
130177export function getIframePointRelativeToParentFrame ( pos : AxisValues < number > , iframeWin : Window ) : AxisValues < number > {
131178 const iframe = domUtils . findIframeByWindow ( iframeWin ) ;
132179 const iframeOffset = getOffsetPosition ( iframe ) ;
0 commit comments