mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Update document-cloner.ts
This commit is contained in:
parent
9103ae2f66
commit
d0e63a8f56
@ -24,6 +24,7 @@ import {CSSParsedCounterDeclaration, CSSParsedPseudoDeclaration} from '../css/in
|
|||||||
import {getQuote} from '../css/property-descriptors/quotes';
|
import {getQuote} from '../css/property-descriptors/quotes';
|
||||||
import {Context} from '../core/context';
|
import {Context} from '../core/context';
|
||||||
import {DebuggerType, isDebugging} from '../core/debugger';
|
import {DebuggerType, isDebugging} from '../core/debugger';
|
||||||
|
import {serializeDoctype} from './serialize-doctype';
|
||||||
|
|
||||||
export interface CloneOptions {
|
export interface CloneOptions {
|
||||||
ignoreElements?: (element: Element) => boolean;
|
ignoreElements?: (element: Element) => boolean;
|
||||||
@ -130,7 +131,7 @@ export class DocumentCloner {
|
|||||||
});
|
});
|
||||||
|
|
||||||
documentClone.open();
|
documentClone.open();
|
||||||
documentClone.write(`${serializeDoctype(document.doctype)}<html></html>`);
|
documentClone.write(serializeDoctype(document.doctype));
|
||||||
// Chrome scrolls the parent document for some reason after the write to the cloned window???
|
// Chrome scrolls the parent document for some reason after the write to the cloned window???
|
||||||
restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
|
restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
|
||||||
documentClone.replaceChild(documentClone.adoptNode(this.documentElement), documentClone.documentElement);
|
documentClone.replaceChild(documentClone.adoptNode(this.documentElement), documentClone.documentElement);
|
||||||
@ -568,32 +569,6 @@ export const copyCSSStyles = <T extends HTMLElement | SVGElement>(style: CSSStyl
|
|||||||
return target;
|
return target;
|
||||||
};
|
};
|
||||||
|
|
||||||
const serializeDoctype = (doctype?: DocumentType | null): string => {
|
|
||||||
let str = '';
|
|
||||||
if (doctype) {
|
|
||||||
str += '<!DOCTYPE ';
|
|
||||||
if (doctype.name) {
|
|
||||||
str += doctype.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doctype.internalSubset) {
|
|
||||||
str += doctype.internalSubset;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doctype.publicId) {
|
|
||||||
str += `"${doctype.publicId}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doctype.systemId) {
|
|
||||||
str += `"${doctype.systemId}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
str += '>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
};
|
|
||||||
|
|
||||||
const restoreOwnerScroll = (ownerDocument: Document | null, x: number, y: number) => {
|
const restoreOwnerScroll = (ownerDocument: Document | null, x: number, y: number) => {
|
||||||
if (
|
if (
|
||||||
ownerDocument &&
|
ownerDocument &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user