1- import { getElementParents } from "./utilities-dom.js" ;
1+ import { getElementParents , isShadowRoot } from "./utilities-dom.js" ;
22import { SELECTOR_SEPARATOR } from "./constants.js" ;
33import { CSS_SELECTOR_TYPE , CssSelector , OPERATOR } from "./types.js" ;
44import {
@@ -14,14 +14,14 @@ export function getElementFallbackSelector(
1414 root ?: ParentNode ,
1515) : CssSelector {
1616 const parentElements = getElementParents ( element , root ) . reverse ( ) ;
17- const isShadowRoot = root instanceof ShadowRoot ;
17+ const rootIsShadowRoot = isShadowRoot ( root ) ;
1818
1919 const elementsData = parentElements . map ( ( element , index ) => {
2020 const elementData = createElementData (
2121 element ,
2222 [ CSS_SELECTOR_TYPE . nthchild ] ,
2323 // do not use child combinator for the first element in ShadowRoot
24- isShadowRoot && index === 0 ? OPERATOR . NONE : OPERATOR . CHILD ,
24+ rootIsShadowRoot && index === 0 ? OPERATOR . NONE : OPERATOR . CHILD ,
2525 ) ;
2626 ( elementData . selectors . nthchild ?? [ ] ) . forEach ( ( selectorData ) => {
2727 selectorData . include = true ;
@@ -30,7 +30,7 @@ export function getElementFallbackSelector(
3030 } ) ;
3131
3232 // Don't use :scope prefix for ShadowRoot since it doesn't work correctly
33- const prefix = isShadowRoot ? "" : root ? ":scope" : ":root" ;
33+ const prefix = rootIsShadowRoot ? "" : root ? ":scope" : ":root" ;
3434
3535 return [ prefix , ...elementsData . map ( constructElementSelector ) ] . join ( "" ) ;
3636}
0 commit comments