import { parseHTML } from "linkedom"; export interface SourceMutationTarget { id?: string | null; selector?: string; selectorIndex?: number; } function parseSourceDocument(source: string): { document: Document; wrappedFragment: boolean } { const hasDocumentShell = /]/i.test(source); if (hasDocumentShell) { return { document: parseHTML(source).document, wrappedFragment: false }; } return { document: parseHTML(`${source}`).document, wrappedFragment: true, }; } function querySelectorAllWithTemplates(root: Document | Element, selector: string): Element[] { const matches = Array.from(root.querySelectorAll(selector)); if (matches.length > 0) return matches; // querySelectorAll doesn't traverse