@@ -61,12 +61,7 @@ function updateCropArea(event: TouchEvent | MouseEvent | KeyboardEvent) {
6161 const target = event . target
6262 if ( ! ( target instanceof HTMLElement ) ) return
6363
64- let el
65- if ( target instanceof ImageCropElement ) {
66- el = target
67- } else {
68- el = getShadowRootHost ( target )
69- }
64+ const el = getShadowHost ( target )
7065 if ( ! ( el instanceof ImageCropElement ) ) return
7166
7267 const { box} = constructedElements . get ( el ) || { }
@@ -97,15 +92,17 @@ function updateCropArea(event: TouchEvent | MouseEvent | KeyboardEvent) {
9792 if ( deltaX && deltaY ) updateDimensions ( el , deltaX , deltaY , ! ( event instanceof KeyboardEvent ) )
9893}
9994
100- function getShadowRootHost ( el : Element ) : ImageCropElement {
101- return ( el . getRootNode ( ) as ShadowRoot ) . host as ImageCropElement
95+ function getShadowHost ( el : HTMLElement ) {
96+ const rootNode = el . getRootNode ( )
97+ if ( ! ( rootNode instanceof ShadowRoot ) ) return el
98+ return rootNode . host
10299}
103100
104101function startUpdate ( event : TouchEvent | MouseEvent ) {
105102 const currentTarget = event . currentTarget
106103 if ( ! ( currentTarget instanceof HTMLElement ) ) return
107104
108- const el = getShadowRootHost ( currentTarget )
105+ const el = getShadowHost ( currentTarget )
109106 if ( ! ( el instanceof ImageCropElement ) ) return
110107
111108 const { box} = constructedElements . get ( el ) || { }
0 commit comments