Fix a few more misc issues (TS errors, dupe files)
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
type AcceptNode = (
|
||||
node: HTMLElement
|
||||
) =>
|
||||
| typeof NodeFilter.FILTER_ACCEPT
|
||||
| typeof NodeFilter.FILTER_SKIP
|
||||
| typeof NodeFilter.FILTER_REJECT;
|
||||
|
||||
export function treeWalker({
|
||||
container,
|
||||
accept,
|
||||
walk,
|
||||
enabled,
|
||||
}: {
|
||||
container: HTMLElement | null;
|
||||
accept: AcceptNode;
|
||||
walk(node: HTMLElement): void;
|
||||
enabled?: boolean;
|
||||
}) {
|
||||
let root = container;
|
||||
if (!root) return;
|
||||
if (enabled !== undefined && !enabled) return;
|
||||
|
||||
let acceptNode = Object.assign((node: HTMLElement) => accept(node), {
|
||||
acceptNode: accept,
|
||||
});
|
||||
// @ts-ignore-error Typescript bug thinks this can only have 3 args
|
||||
let walker = document.createTreeWalker(
|
||||
root,
|
||||
NodeFilter.SHOW_ELEMENT,
|
||||
acceptNode,
|
||||
false
|
||||
);
|
||||
|
||||
while (walker.nextNode()) walk(walker.currentNode as HTMLElement);
|
||||
}
|
||||
Reference in New Issue
Block a user