@@ -30,12 +30,12 @@ import {
3030 Animation ,
3131 clone ,
3232 distance ,
33- getClosest ,
33+ getEventTarget ,
34+ getMatchingTarget ,
3435 getPosition ,
3536 getTouchData ,
36- hasParent ,
3737 isEmpty ,
38- throttle ,
38+ throttle
3939} from '../utils' ;
4040import { PressHandler } from '../utils/PressHandler' ;
4141import type { Viewer } from '../Viewer' ;
@@ -156,7 +156,7 @@ export class EventsHandler extends AbstractService {
156156 case 'fullscreenchange' : this . __onFullscreenChange ( ) ; break ;
157157 }
158158
159- if ( ! getClosest ( evt . target as HTMLElement , '.' + CAPTURE_EVENTS_CLASS ) ) {
159+ if ( ! getMatchingTarget ( evt , '.' + CAPTURE_EVENTS_CLASS ) ) {
160160 // prettier-ignore
161161 switch ( evt . type ) {
162162 case 'mousedown' : this . __onMouseDown ( evt as MouseEvent ) ; break ;
@@ -243,7 +243,7 @@ export class EventsHandler extends AbstractService {
243243 */
244244 private __onMouseUp ( evt : MouseEvent ) {
245245 if ( this . step . is ( Step . CLICK , Step . MOVING ) ) {
246- this . __stopMove ( evt . clientX , evt . clientY , evt . target , evt . button === 2 ) ;
246+ this . __stopMove ( evt . clientX , evt . clientY , evt , evt . button === 2 ) ;
247247 }
248248 }
249249
@@ -271,7 +271,7 @@ export class EventsHandler extends AbstractService {
271271 if ( ! this . data . longtouchTimeout ) {
272272 this . data . longtouchTimeout = setTimeout ( ( ) => {
273273 const touch = evt . touches [ 0 ] ;
274- this . __stopMove ( touch . clientX , touch . clientY , touch . target , true ) ;
274+ this . __stopMove ( touch . clientX , touch . clientY , evt , true ) ;
275275 this . data . longtouchTimeout = null ;
276276 } , LONGTOUCH_DELAY ) ;
277277 }
@@ -301,7 +301,7 @@ export class EventsHandler extends AbstractService {
301301 this . __stopMove ( this . data . mouseX , this . data . mouseY ) ;
302302 } else if ( evt . touches . length === 0 ) {
303303 const touch = evt . changedTouches [ 0 ] ;
304- this . __stopMove ( touch . clientX , touch . clientY , touch . target ) ;
304+ this . __stopMove ( touch . clientX , touch . clientY , evt ) ;
305305 }
306306 }
307307 }
@@ -442,7 +442,7 @@ export class EventsHandler extends AbstractService {
442442 * Stops the movement
443443 * @description If the move threshold was not reached a click event is triggered, otherwise an animation is launched to simulate inertia
444444 */
445- private __stopMove ( clientX : number , clientY : number , target ?: EventTarget , rightclick = false ) {
445+ private __stopMove ( clientX : number , clientY : number , event ?: Event , rightclick = false ) {
446446 if ( this . step . is ( Step . MOVING ) ) {
447447 if ( this . config . moveInertia ) {
448448 this . __logMouseMove ( clientX , clientY ) ;
@@ -453,7 +453,7 @@ export class EventsHandler extends AbstractService {
453453 }
454454 } else {
455455 if ( this . step . is ( Step . CLICK ) && ! this . __moveThresholdReached ( clientX , clientY ) ) {
456- this . __doClick ( clientX , clientY , target , rightclick ) ;
456+ this . __doClick ( clientX , clientY , event , rightclick ) ;
457457 }
458458 this . step . remove ( Step . CLICK ) ;
459459 if ( ! this . step . is ( Step . INERTIA ) ) {
@@ -518,7 +518,7 @@ export class EventsHandler extends AbstractService {
518518 /**
519519 * Triggers an event with all coordinates when a simple click is performed
520520 */
521- private __doClick ( clientX : number , clientY : number , target : EventTarget , rightclick = false ) {
521+ private __doClick ( clientX : number , clientY : number , event ?: Event , rightclick = false ) {
522522 const boundingRect = this . viewer . container . getBoundingClientRect ( ) ;
523523
524524 const viewerX = clientX - boundingRect . left ;
@@ -532,7 +532,8 @@ export class EventsHandler extends AbstractService {
532532
533533 const data : ClickData = {
534534 rightclick : rightclick ,
535- target : target as HTMLElement ,
535+ originalEvent : event ,
536+ target : getEventTarget ( event ) ,
536537 clientX,
537538 clientY,
538539 viewerX,
@@ -576,7 +577,7 @@ export class EventsHandler extends AbstractService {
576577 * Trigger events for observed THREE objects
577578 */
578579 private __handleObjectsEvents ( evt : MouseEvent ) {
579- if ( ! isEmpty ( this . state . objectsObservers ) && hasParent ( evt . target as HTMLElement , this . viewer . container ) ) {
580+ if ( ! isEmpty ( this . state . objectsObservers ) && evt . composedPath ( ) . includes ( this . viewer . container ) ) {
580581 const viewerPos = getPosition ( this . viewer . container ) ;
581582
582583 const viewerPoint : Point = {
0 commit comments