()
| 137 | // array-normalization + data-start defaults below pick the same root the |
| 138 | // closure-based `resolveRootCompositionElement` does on multi-comp pages. |
| 139 | const findRootCompositionEl = (): HTMLElement | null => { |
| 140 | const explicitRoot = document.querySelector('[data-composition-id][data-root="true"]'); |
| 141 | if (explicitRoot instanceof HTMLElement) return explicitRoot; |
| 142 | const nodes = Array.from(document.querySelectorAll("[data-composition-id]")) as HTMLElement[]; |
| 143 | return ( |
| 144 | nodes.find((node) => !node.parentElement?.closest("[data-composition-id]")) ?? |
| 145 | nodes[0] ?? |
| 146 | null |
| 147 | ); |
| 148 | }; |
| 149 | |
| 150 | // Agents often write `window.__timelines = [tl]` (array) instead of the |
| 151 | // keyed-by-composition-id object the runtime expects. Normalize at init so |
no test coverage detected