mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Compare commits
6 Commits
v1.0.0-alp
...
v1.0.0-alp
Author | SHA1 | Date | |
---|---|---|---|
ef5c59e26d | |||
8b653f89bc | |||
9db8580b97 | |||
4a09264103 | |||
b8178e92b4 | |||
166cbba7c2 |
@ -1,6 +1,11 @@
|
|||||||
### Changelog ###
|
### Changelog ###
|
||||||
|
|
||||||
#### v1.0.0-alpha1 - TBD ####
|
#### v1.0.0-alpha2 - TBD ####
|
||||||
|
* Fix scroll positions for CanvasRenderer (#1259)
|
||||||
|
* Fix `data-html2canvas-ignore` attribute (#1253)
|
||||||
|
* Fix decimal `letter-spacing` values (#1293)
|
||||||
|
|
||||||
|
#### v1.0.0-alpha1 - 5.12.2017 ####
|
||||||
* Complete rewrite of library
|
* Complete rewrite of library
|
||||||
##### Breaking Changes #####
|
##### Breaking Changes #####
|
||||||
* Remove deprecated onrendered callback, calling `html2canvas` returns a `Promise<HTMLCanvasElement>`
|
* Remove deprecated onrendered callback, calling `html2canvas` returns a `Promise<HTMLCanvasElement>`
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "html2canvas",
|
"name": "html2canvas",
|
||||||
"description": "Screenshots with JavaScript",
|
"description": "Screenshots with JavaScript",
|
||||||
"main": "dist/npm/index.js",
|
"main": "dist/npm/index.js",
|
||||||
"version": "1.0.0-alpha.1",
|
"version": "1.0.0-alpha.2",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Niklas von Hertzen",
|
"name": "Niklas von Hertzen",
|
||||||
"email": "niklasvh@gmail.com",
|
"email": "niklasvh@gmail.com",
|
||||||
|
11
src/Clone.js
11
src/Clone.js
@ -11,6 +11,8 @@ import {copyCSSStyles} from './Util';
|
|||||||
import {parseBackgroundImage} from './parsing/background';
|
import {parseBackgroundImage} from './parsing/background';
|
||||||
import CanvasRenderer from './renderer/CanvasRenderer';
|
import CanvasRenderer from './renderer/CanvasRenderer';
|
||||||
|
|
||||||
|
const IGNORE_ATTRIBUTE = 'data-html2canvas-ignore';
|
||||||
|
|
||||||
export class DocumentCloner {
|
export class DocumentCloner {
|
||||||
scrolledElements: Array<[HTMLElement, number, number]>;
|
scrolledElements: Array<[HTMLElement, number, number]>;
|
||||||
referenceElement: HTMLElement;
|
referenceElement: HTMLElement;
|
||||||
@ -233,7 +235,11 @@ export class DocumentCloner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let child = node.firstChild; child; child = child.nextSibling) {
|
for (let child = node.firstChild; child; child = child.nextSibling) {
|
||||||
if (child.nodeType !== Node.ELEMENT_NODE || child.nodeName !== 'SCRIPT') {
|
if (
|
||||||
|
child.nodeType !== Node.ELEMENT_NODE ||
|
||||||
|
// $FlowFixMe
|
||||||
|
(child.nodeName !== 'SCRIPT' && !child.hasAttribute(IGNORE_ATTRIBUTE))
|
||||||
|
) {
|
||||||
if (!this.copyStyles || child.nodeName !== 'STYLE') {
|
if (!this.copyStyles || child.nodeName !== 'STYLE') {
|
||||||
clone.appendChild(this.cloneNode(child));
|
clone.appendChild(this.cloneNode(child));
|
||||||
}
|
}
|
||||||
@ -247,7 +253,7 @@ export class DocumentCloner {
|
|||||||
}
|
}
|
||||||
this.inlineAllImages(clone);
|
this.inlineAllImages(clone);
|
||||||
if (node.scrollTop !== 0 || node.scrollLeft !== 0) {
|
if (node.scrollTop !== 0 || node.scrollLeft !== 0) {
|
||||||
this.scrolledElements.push([node, node.scrollLeft, node.scrollTop]);
|
this.scrolledElements.push([clone, node.scrollLeft, node.scrollTop]);
|
||||||
}
|
}
|
||||||
switch (node.nodeName) {
|
switch (node.nodeName) {
|
||||||
case 'CANVAS':
|
case 'CANVAS':
|
||||||
@ -493,6 +499,7 @@ const createIframeContainer = (
|
|||||||
cloneIframeContainer.width = bounds.width.toString();
|
cloneIframeContainer.width = bounds.width.toString();
|
||||||
cloneIframeContainer.height = bounds.height.toString();
|
cloneIframeContainer.height = bounds.height.toString();
|
||||||
cloneIframeContainer.scrolling = 'no'; // ios won't scroll without it
|
cloneIframeContainer.scrolling = 'no'; // ios won't scroll without it
|
||||||
|
cloneIframeContainer.setAttribute(IGNORE_ATTRIBUTE, 'true');
|
||||||
if (!ownerDocument.body) {
|
if (!ownerDocument.body) {
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
__DEV__ ? `Body element not found in Document that is getting rendered` : ''
|
__DEV__ ? `Body element not found in Document that is getting rendered` : ''
|
||||||
|
@ -39,6 +39,12 @@ const html2canvas = (element: HTMLElement, conf: ?Options): Promise<*> => {
|
|||||||
const config = conf || {};
|
const config = conf || {};
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
|
|
||||||
|
if (__DEV__ && typeof config.onrendered === 'function') {
|
||||||
|
logger.error(
|
||||||
|
`onrendered option is deprecated, html2canvas returns a Promise with the canvas as the value`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const ownerDocument = element.ownerDocument;
|
const ownerDocument = element.ownerDocument;
|
||||||
if (!ownerDocument) {
|
if (!ownerDocument) {
|
||||||
return Promise.reject(`Provided element is not within a Document`);
|
return Promise.reject(`Provided element is not within a Document`);
|
||||||
|
@ -5,6 +5,6 @@ export const parseLetterSpacing = (letterSpacing: string): number => {
|
|||||||
if (letterSpacing === 'normal') {
|
if (letterSpacing === 'normal') {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const value = parseInt(letterSpacing, 10);
|
const value = parseFloat(letterSpacing);
|
||||||
return isNaN(value) ? 0 : value;
|
return isNaN(value) ? 0 : value;
|
||||||
};
|
};
|
||||||
|
41
tests/reftests/options/ignore.html
Normal file
41
tests/reftests/options/ignore.html
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>element render test</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<script>
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript" src="../../test.js"></script>
|
||||||
|
<style>
|
||||||
|
#div1 {
|
||||||
|
|
||||||
|
width: 100px;
|
||||||
|
height: 100px;
|
||||||
|
background: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ignored {
|
||||||
|
background: red;
|
||||||
|
width: 100px;
|
||||||
|
height: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body, html {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="ignored" data-html2canvas-ignore>
|
||||||
|
great failure
|
||||||
|
</div>
|
||||||
|
<div id="div1">
|
||||||
|
great success
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -65,6 +65,20 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div style="overflow:scroll; height: 100px;" id="scroll">
|
||||||
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s
|
||||||
|
|
||||||
|
with the release of <div style="border-width:10px 0 5px 0;background:green;">a</div>Letraset sheets containing Lorem Ipsum passages, <img src="../../assets/image.jpg" /> and more recently with desktop publishing software like <b>Aldus PageMaker</b> including versions of Lorem Ipsum.
|
||||||
|
|
||||||
|
|
||||||
|
<div style="overflow:visible;position:relative;"><u>position:relative within a overflow:hidden element</u><br /> <br />
|
||||||
|
|
||||||
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like <b>Aldus PageMaker</b> including versions of Lorem Ipsum.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
document.querySelector('#scroll').scrollTo(0, 200);
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -126,6 +126,7 @@
|
|||||||
<li style="word-spacing:5px;">word-spacing:5px; (as each letter is rendered individually, the bounds will always be correct)</li>
|
<li style="word-spacing:5px;">word-spacing:5px; (as each letter is rendered individually, the bounds will always be correct)</li>
|
||||||
<li style="line-height:35px;">line-height:35px; <br />(same goes for line-height)</li>
|
<li style="line-height:35px;">line-height:35px; <br />(same goes for line-height)</li>
|
||||||
<li style="letter-spacing:5px;">letter-spacing:5px;</li>
|
<li style="letter-spacing:5px;">letter-spacing:5px;</li>
|
||||||
|
<li style="letter-spacing:0.9px;">letter-spacing:0.9px;</li>
|
||||||
<li style="text-align:right;width:300px;">text-align:right;width:300px;</li>
|
<li style="text-align:right;width:300px;">text-align:right;width:300px;</li>
|
||||||
<li style="font-variant:small-caps;">font-variant:small-caps; </li>
|
<li style="font-variant:small-caps;">font-variant:small-caps; </li>
|
||||||
</ul>
|
</ul>
|
||||||
|
Reference in New Issue
Block a user