Don't copy styles for regular computed rendering

This commit is contained in:
Niklas von Hertzen 2017-08-18 20:52:29 +08:00
parent 4f96abfb7b
commit f79ae2b73a
4 changed files with 12 additions and 8 deletions

View File

@ -18,11 +18,11 @@ export class DocumentCloner {
inlineImages: boolean; inlineImages: boolean;
copyStyles: boolean; copyStyles: boolean;
constructor(element: HTMLElement, options: Options, logger: Logger) { constructor(element: HTMLElement, options: Options, logger: Logger, copyInline: boolean) {
this.referenceElement = element; this.referenceElement = element;
this.scrolledElements = []; this.scrolledElements = [];
this.copyStyles = true; this.copyStyles = copyInline;
this.inlineImages = true; this.inlineImages = copyInline;
this.logger = logger; this.logger = logger;
this.imageLoader = new ImageLoader(options, logger, window); this.imageLoader = new ImageLoader(options, logger, window);
// $FlowFixMe // $FlowFixMe
@ -237,7 +237,7 @@ export const cloneWindow = (
options: Options, options: Options,
logger: Logger logger: Logger
): Promise<[HTMLIFrameElement, HTMLElement]> => { ): Promise<[HTMLIFrameElement, HTMLElement]> => {
const cloner = new DocumentCloner(referenceElement, options, logger); const cloner = new DocumentCloner(referenceElement, options, logger, false);
const cloneIframeContainer = ownerDocument.createElement('iframe'); const cloneIframeContainer = ownerDocument.createElement('iframe');
cloneIframeContainer.className = 'html2canvas-container'; cloneIframeContainer.className = 'html2canvas-container';

View File

@ -38,7 +38,11 @@ export default class ImageLoader<T> {
return this.addImage(src, src); return this.addImage(src, src);
} }
} else { } else {
if (this.options.allowTaint === true || isInlineBase64Image(src) || this.isSameOrigin(src)) { if (
this.options.allowTaint === true ||
isInlineBase64Image(src) ||
this.isSameOrigin(src)
) {
return this.addImage(src, src); return this.addImage(src, src);
} else if (typeof this.options.proxy === 'string' && !this.isSameOrigin(src)) { } else if (typeof this.options.proxy === 'string' && !this.isSameOrigin(src)) {
// TODO proxy // TODO proxy

View File

@ -23,7 +23,7 @@ export type Options = {
proxy: ?string, proxy: ?string,
removeContainer: ?boolean, removeContainer: ?boolean,
scale: number, scale: number,
target: RenderTarget<*> | Array<RenderTarget<*>>, target: RenderTarget<*>,
type: ?string, type: ?string,
windowWidth: number, windowWidth: number,
windowHeight: number, windowHeight: number,
@ -98,7 +98,7 @@ const html2canvas = (element: HTMLElement, config: Options): Promise<*> => {
scale: options.scale scale: options.scale
}); });
}); });
})(new DocumentCloner(element, options, logger)) })(new DocumentCloner(element, options, logger, true))
: cloneWindow( : cloneWindow(
ownerDocument, ownerDocument,
windowBounds, windowBounds,

View File

@ -115,7 +115,7 @@ const assertPath = (result, expected, desc) => {
.html2canvas(testContainer.contentWindow.document.documentElement, { .html2canvas(testContainer.contentWindow.document.documentElement, {
removeContainer: true removeContainer: true
}) })
.then((canvas) => { .then(canvas => {
try { try {
canvas canvas
.getContext('2d') .getContext('2d')