@@ -18,15 +18,29 @@ export function calculatePosition(element) {
1818 return 0 ;
1919 }
2020
21- const parent = element . parentElement ;
21+ // Get parent - could be Element or ShadowRoot
22+ const parent = element . parentNode ;
2223 if ( ! parent ) return 1 ;
2324
25+ // Get children - works for both Element and ShadowRoot
26+ // For ShadowRoot, we need to filter to get only element nodes
27+ const children =
28+ parent . children ||
29+ Array . from ( parent . childNodes ) . filter (
30+ ( node ) => node . nodeType === Node . ELEMENT_NODE
31+ ) ;
32+
33+ if ( ! children || children . length === 0 ) return 1 ;
34+
2435 let position = 0 ;
2536 let lastTag = null ;
2637 let foundTarget = false ;
2738
2839 // Iterate through all child elements
29- for ( const child of parent . children ) {
40+ for ( const child of children ) {
41+ // Skip non-element nodes (shouldn't happen with .children, but safe for childNodes)
42+ if ( child . nodeType !== Node . ELEMENT_NODE ) continue ;
43+
3044 const childTag = child . tagName . toLowerCase ( ) ;
3145
3246 // Skip non-map elements
@@ -36,14 +50,14 @@ export function calculatePosition(element) {
3650 if ( child === element ) {
3751 foundTarget = true ;
3852
39- // map-extent always needs a new position
53+ // map-extent always needs a new z-index
4054 if ( childTag === 'map-extent' ) {
4155 position ++ ;
4256 return position ;
4357 }
4458
4559 // For map-tile and map-feature:
46- // If this element continues a sequence of the same type, return the current position
60+ // If this element continues a sequence of the same type, return the current z-index
4761 if ( lastTag === childTag ) {
4862 return position ;
4963 }
@@ -56,13 +70,13 @@ export function calculatePosition(element) {
5670 // Before reaching target, count layer group transitions
5771 if ( ! foundTarget ) {
5872 if ( childTag === 'map-extent' ) {
59- // Each map-extent increments position
73+ // Each map-extent increments z-index
6074 position ++ ;
6175 } else if ( lastTag !== null && lastTag !== childTag ) {
6276 // Transition between different types (excluding map-extent)
6377 position ++ ;
6478 } else if ( lastTag === null ) {
65- // First valid element starts at position 1
79+ // First valid element starts at z-index 1
6680 position = 1 ;
6781 }
6882
0 commit comments