mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Use correct canvas size for full document render
This commit is contained in:
parent
aafb0cfb9c
commit
7cc2b856cb
@ -78,6 +78,28 @@ export const calculateContentBox = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const parseDocumentSize = (document: Document): Bounds => {
|
||||||
|
const body = document.body;
|
||||||
|
const documentElement = document.documentElement;
|
||||||
|
|
||||||
|
if (!body || !documentElement) {
|
||||||
|
throw new Error(__DEV__ ? `Unable to get document size` : '');
|
||||||
|
}
|
||||||
|
const width = Math.max(
|
||||||
|
Math.max(body.scrollWidth, documentElement.scrollWidth),
|
||||||
|
Math.max(body.offsetWidth, documentElement.offsetWidth),
|
||||||
|
Math.max(body.clientWidth, documentElement.clientWidth)
|
||||||
|
);
|
||||||
|
|
||||||
|
const height = Math.max(
|
||||||
|
Math.max(body.scrollHeight, documentElement.scrollHeight),
|
||||||
|
Math.max(body.offsetHeight, documentElement.offsetHeight),
|
||||||
|
Math.max(body.clientHeight, documentElement.clientHeight)
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Bounds(0, 0, width, height);
|
||||||
|
};
|
||||||
|
|
||||||
export const parsePathForBorder = (curves: BoundCurves, borderSide: BorderSide): Path => {
|
export const parsePathForBorder = (curves: BoundCurves, borderSide: BorderSide): Path => {
|
||||||
switch (borderSide) {
|
switch (borderSide) {
|
||||||
case TOP:
|
case TOP:
|
||||||
|
14
src/index.js
14
src/index.js
@ -5,7 +5,7 @@ import {NodeParser} from './NodeParser';
|
|||||||
import CanvasRenderer from './CanvasRenderer';
|
import CanvasRenderer from './CanvasRenderer';
|
||||||
import Logger from './Logger';
|
import Logger from './Logger';
|
||||||
import ImageLoader from './ImageLoader';
|
import ImageLoader from './ImageLoader';
|
||||||
import {Bounds} from './Bounds';
|
import {Bounds, parseDocumentSize} from './Bounds';
|
||||||
import {cloneWindow} from './Clone';
|
import {cloneWindow} from './Clone';
|
||||||
import Color from './Color';
|
import Color from './Color';
|
||||||
|
|
||||||
@ -62,8 +62,10 @@ const html2canvas = (element: HTMLElement, config: Options): Promise<HTMLCanvasE
|
|||||||
}
|
}
|
||||||
const imageLoader = new ImageLoader(options, logger);
|
const imageLoader = new ImageLoader(options, logger);
|
||||||
const stack = NodeParser(clonedElement, imageLoader, logger);
|
const stack = NodeParser(clonedElement, imageLoader, logger);
|
||||||
const width = window.innerWidth;
|
const size =
|
||||||
const height = window.innerHeight;
|
options.type === 'view' ? windowBounds : parseDocumentSize(clonedElement.ownerDocument);
|
||||||
|
const width = size.width;
|
||||||
|
const height = size.height;
|
||||||
canvas.width = Math.floor(width * options.scale);
|
canvas.width = Math.floor(width * options.scale);
|
||||||
canvas.height = Math.floor(height * options.scale);
|
canvas.height = Math.floor(height * options.scale);
|
||||||
canvas.style.width = `${width}px`;
|
canvas.style.width = `${width}px`;
|
||||||
@ -71,10 +73,10 @@ const html2canvas = (element: HTMLElement, config: Options): Promise<HTMLCanvasE
|
|||||||
|
|
||||||
// http://www.w3.org/TR/css3-background/#special-backgrounds
|
// http://www.w3.org/TR/css3-background/#special-backgrounds
|
||||||
const backgroundColor =
|
const backgroundColor =
|
||||||
clonedElement === ownerDocument.documentElement
|
clonedElement === clonedElement.ownerDocument.documentElement
|
||||||
? stack.container.style.background.backgroundColor.isTransparent()
|
? stack.container.style.background.backgroundColor.isTransparent()
|
||||||
? ownerDocument.body
|
? clonedElement.ownerDocument.body
|
||||||
? new Color(getComputedStyle(ownerDocument.body).backgroundColor)
|
? new Color(getComputedStyle(clonedElement.ownerDocument.body).backgroundColor)
|
||||||
: null
|
: null
|
||||||
: stack.container.style.background.backgroundColor
|
: stack.container.style.background.backgroundColor
|
||||||
: null;
|
: null;
|
||||||
|
Loading…
Reference in New Issue
Block a user