Walk DOM to the innermost open element matching the track stack
( container: HTMLElement, stack: string[], )
| 150 | |
| 151 | /** Walk DOM to the innermost open element matching the track stack */ |
| 152 | function findDeepOpenElement( |
| 153 | container: HTMLElement, |
| 154 | stack: string[], |
| 155 | ): HTMLElement | null { |
| 156 | let node: Element = container; |
| 157 | |
| 158 | for (const tag of stack) { |
| 159 | const tagLower = tag.toLowerCase(); |
| 160 | let matched: Element | null = null; |
| 161 | |
| 162 | for (let i = node.children.length - 1; i >= 0; i--) { |
| 163 | const child = node.children[i]!; |
| 164 | if (child.tagName.toLowerCase() === tagLower) { |
| 165 | matched = child; |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if (!matched) { |
| 171 | return null; |
| 172 | } |
| 173 | node = matched; |
| 174 | } |
| 175 | |
| 176 | return node as HTMLElement; |
| 177 | } |
| 178 | |
| 179 | /** Deepest last text node under `root` (matches insertAdjacentText tail). */ |
| 180 | function findLastTextNode(root: Node): Text | null { |
no outgoing calls
no test coverage detected