Add additional options

This commit is contained in:
Yuri Papouski 2022-09-07 11:35:57 +00:00
parent 7c7aee3698
commit e816b25c31
2 changed files with 14 additions and 4 deletions

View File

@ -29,6 +29,8 @@ export interface CloneOptions {
ignoreElements?: (element: Element) => boolean;
onclone?: (document: Document, element: HTMLElement) => void;
allowTaint?: boolean;
hide_selector?: string;
masked_class?: string;
}
export interface WindowOptions {
@ -274,15 +276,21 @@ export class DocumentCloner {
}
appendChildNode(clone: HTMLElement | SVGElement, child: Node, copyStyles: boolean): void {
const {ignoreElements, hide_selector, masked_class = ''} = this.options;
if (
!isElementNode(child) ||
(!isScriptElement(child) &&
!child.hasAttribute(IGNORE_ATTRIBUTE) &&
(typeof this.options.ignoreElements !== 'function' || !this.options.ignoreElements(child)))
(typeof ignoreElements !== 'function' || !ignoreElements(child)))
) {
if (!this.options.copyStyles || !isElementNode(child) || !isStyleElement(child)) {
clone.appendChild(this.cloneNode(child, copyStyles));
const clonedNode = this.cloneNode(child, copyStyles);
if (hide_selector && isElementNode(clonedNode) && clonedNode.matches(hide_selector)) {
if (isImageElement(clonedNode)) {
clonedNode.style.visibility = 'hidden';
}
clonedNode.classList.add(masked_class);
}
clone.appendChild(clonedNode);
}
}

View File

@ -78,7 +78,9 @@ const renderElement = async (element: HTMLElement, opts: Partial<Options>): Prom
onclone: opts.onclone,
ignoreElements: opts.ignoreElements,
inlineImages: foreignObjectRendering,
copyStyles: foreignObjectRendering
copyStyles: foreignObjectRendering,
hide_selector: opts.hide_selector,
masked_class: opts.masked_class
};
context.logger.debug(