MCPcopy Index your code
hub / github.com/Alphanimble/htmlstream / findDeepOpenElement

Function findDeepOpenElement

src/patch-streaming-html.ts:152–177  ·  view source on GitHub ↗

Walk DOM to the innermost open element matching the track stack

(
  container: HTMLElement,
  stack: string[],
)

Source from the content-addressed store, hash-verified

150
151/** Walk DOM to the innermost open element matching the track stack */
152function 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). */
180function findLastTextNode(root: Node): Text | null {

Callers 2

resolveStreamCaretRangeFunction · 0.85
patchStreamingHtmlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected