diff --git a/docs/configuration.md b/docs/configuration.md index d319e6b..e3d8232 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -21,6 +21,7 @@ These are all of the available configuration options. | onclone | `null` | Callback function which is called when the Document has been cloned for rendering, can be used to modify the contents that will be rendered without affecting the original source document. | proxy | `null` | Url to the [proxy](/proxy/) which is to be used for loading cross-origin images. If left empty, cross-origin images won't be loaded. | removeContainer | `true` | Whether to cleanup the cloned DOM elements html2canvas creates temporarily +| copyStylesInSVG | `true` | Whether to copy all computed styles inside every SVG node | scale | `window.devicePixelRatio` | The scale to use for rendering. Defaults to the browsers device pixel ratio. | useCORS | `false` | Whether to attempt to load images from a server using CORS | width | `Element` width | The width of the `canvas` diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index 2bf940d..6c74808 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -25,6 +25,7 @@ export interface CloneOptions { id: string; ignoreElements?: (element: Element) => boolean; onclone?: (document: Document) => void; + copyStylesInSVG?: boolean; } export type CloneConfigurations = CloneOptions & { @@ -308,7 +309,12 @@ export class DocumentCloner { this.counters.pop(counters); - if (style && (this.options.copyStyles || isSVGElementNode(node)) && !isIFrameElement(node)) { + if ( + style && + this.options.copyStylesInSVG && + (this.options.copyStyles || isSVGElementNode(node)) && + !isIFrameElement(node) + ) { copyCSSStyles(style, clone); } diff --git a/src/index.ts b/src/index.ts index 5b5fc8a..0847297 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,7 +90,8 @@ const renderElement = async (element: HTMLElement, opts: Partial): Prom onclone: options.onclone, ignoreElements: options.ignoreElements, inlineImages: options.foreignObjectRendering, - copyStyles: options.foreignObjectRendering + copyStyles: options.foreignObjectRendering, + copyStylesInSVG: options.copyStylesInSVG == null ? true : options.copyStylesInSVG }); const clonedElement = documentCloner.clonedReferenceElement; if (!clonedElement) {