html-to-image
Advanced tools
Comparing version 1.3.20 to 1.3.21
@@ -0,1 +1,8 @@ | ||
## [1.3.21](https://github.com/bubkoo/html-to-image/compare/v1.3.20...v1.3.21) (2021-01-13) | ||
### Bug Fixes | ||
* š [#74](https://github.com/bubkoo/html-to-image/issues/74) process reference ([#75](https://github.com/bubkoo/html-to-image/issues/75)) ([9e9d71b](https://github.com/bubkoo/html-to-image/commit/9e9d71ba80133c0f676053b04cf5787fd0469f80)) | ||
## [1.3.20](https://github.com/bubkoo/html-to-image/compare/v1.3.19...v1.3.20) (2020-10-28) | ||
@@ -2,0 +9,0 @@ |
@@ -15,2 +15,3 @@ export function applyStyleWithOptions(clonedNode, options) { | ||
Object.keys(manual).forEach((key) => { | ||
// @ts-expect-error | ||
style[key] = manual[key]; | ||
@@ -17,0 +18,0 @@ }); |
@@ -12,2 +12,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { shouldEmbed, embedResources } from './embedResources'; | ||
const cssFetchPromiseStore = {}; | ||
export function parseWebFontRules(clonedNode) { | ||
@@ -149,3 +150,6 @@ return __awaiter(this, void 0, void 0, function* () { | ||
function fetchCSS(url, sheet) { | ||
return fetch(url).then((res) => { | ||
if (cssFetchPromiseStore[url]) { | ||
return cssFetchPromiseStore[url]; | ||
} | ||
const promise = fetch(url).then((res) => { | ||
return { | ||
@@ -158,2 +162,4 @@ url, | ||
}); | ||
cssFetchPromiseStore[url] = promise; | ||
return promise; | ||
} | ||
@@ -160,0 +166,0 @@ function embedFonts(data) { |
@@ -8,9 +8,14 @@ /* tslint:disable:max-line-length */ | ||
const TIMEOUT = 30000; | ||
const cache = []; | ||
const cache = {}; | ||
function isFont(filename) { | ||
return /ttf|otf|eot|woff2?/i.test(filename); | ||
} | ||
export function getBlobFromURL(url, options) { | ||
const root = url.split('?')[0]; | ||
const found = cache.find((item) => item.url === root); | ||
if (found) { | ||
return found.promise; | ||
let href = url.replace(/\?.*/, ''); | ||
if (isFont(href)) { | ||
href = href.replace(/.*\//, ''); | ||
} | ||
if (cache[href]) { | ||
return cache[href]; | ||
} | ||
// cache bypass so we dont have CORS issues with cached images | ||
@@ -78,5 +83,5 @@ // ref: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache | ||
const promise = deferred.catch(failed); | ||
cache.push({ promise, url: root }); | ||
cache[href] = promise; | ||
return promise; | ||
} | ||
//# sourceMappingURL=getBlobFromURL.js.map |
@@ -17,3 +17,3 @@ export declare type Options = { | ||
*/ | ||
style?: CSSStyleDeclaration; | ||
style?: Partial<CSSStyleDeclaration>; | ||
/** | ||
@@ -20,0 +20,0 @@ * A function taking DOM node as argument. Should return `true` if passed |
@@ -99,3 +99,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
let ratio; | ||
const val = process && process.env ? process.env.devicePixelRatio : null; | ||
let FINAL_PROCESS; | ||
try { | ||
FINAL_PROCESS = process; | ||
} | ||
catch (e) { } | ||
const val = FINAL_PROCESS && FINAL_PROCESS.env | ||
? FINAL_PROCESS.env.devicePixelRatio | ||
: null; | ||
if (val) { | ||
@@ -102,0 +109,0 @@ ratio = parseInt(val, 10); |
@@ -18,2 +18,3 @@ "use strict"; | ||
Object.keys(manual).forEach(function (key) { | ||
// @ts-expect-error | ||
style[key] = manual[key]; | ||
@@ -20,0 +21,0 @@ }); |
@@ -42,2 +42,3 @@ "use strict"; | ||
var embedResources_1 = require("./embedResources"); | ||
var cssFetchPromiseStore = {}; | ||
function parseWebFontRules(clonedNode) { | ||
@@ -191,3 +192,6 @@ return __awaiter(this, void 0, void 0, function () { | ||
function fetchCSS(url, sheet) { | ||
return fetch(url).then(function (res) { | ||
if (cssFetchPromiseStore[url]) { | ||
return cssFetchPromiseStore[url]; | ||
} | ||
var promise = fetch(url).then(function (res) { | ||
return { | ||
@@ -200,2 +204,4 @@ url: url, | ||
}); | ||
cssFetchPromiseStore[url] = promise; | ||
return promise; | ||
} | ||
@@ -202,0 +208,0 @@ function embedFonts(data) { |
@@ -11,9 +11,14 @@ "use strict"; | ||
var TIMEOUT = 30000; | ||
var cache = []; | ||
var cache = {}; | ||
function isFont(filename) { | ||
return /ttf|otf|eot|woff2?/i.test(filename); | ||
} | ||
function getBlobFromURL(url, options) { | ||
var root = url.split('?')[0]; | ||
var found = cache.find(function (item) { return item.url === root; }); | ||
if (found) { | ||
return found.promise; | ||
var href = url.replace(/\?.*/, ''); | ||
if (isFont(href)) { | ||
href = href.replace(/.*\//, ''); | ||
} | ||
if (cache[href]) { | ||
return cache[href]; | ||
} | ||
// cache bypass so we dont have CORS issues with cached images | ||
@@ -83,3 +88,3 @@ // ref: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache | ||
var promise = deferred.catch(failed); | ||
cache.push({ promise: promise, url: root }); | ||
cache[href] = promise; | ||
return promise; | ||
@@ -86,0 +91,0 @@ } |
@@ -17,3 +17,3 @@ export declare type Options = { | ||
*/ | ||
style?: CSSStyleDeclaration; | ||
style?: Partial<CSSStyleDeclaration>; | ||
/** | ||
@@ -20,0 +20,0 @@ * A function taking DOM node as argument. Should return `true` if passed |
@@ -143,3 +143,10 @@ "use strict"; | ||
var ratio; | ||
var val = process && process.env ? process.env.devicePixelRatio : null; | ||
var FINAL_PROCESS; | ||
try { | ||
FINAL_PROCESS = process; | ||
} | ||
catch (e) { } | ||
var val = FINAL_PROCESS && FINAL_PROCESS.env | ||
? FINAL_PROCESS.env.devicePixelRatio | ||
: null; | ||
if (val) { | ||
@@ -146,0 +153,0 @@ ratio = parseInt(val, 10); |
{ | ||
"name": "html-to-image", | ||
"version": "1.3.20", | ||
"version": "1.3.21", | ||
"description": "Generates an image from a DOM node using HTML5 canvas and SVG.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -40,10 +40,12 @@ <h1 align="center">html-to-image</h1> | ||
- toSvg | ||
- toPng | ||
- toJpeg | ||
- toBlob | ||
- toPixelData | ||
- [toPng](#toPng) | ||
- [toSvg](#toSvg) | ||
- [toJpeg](#toJpeg) | ||
- [toBlob](#toBlob) | ||
- [toCanvas](#toCanvas) | ||
- [toPixelData](#toPixelData) | ||
Go with the following examples. | ||
#### toPng | ||
Get a PNG image base64-encoded data URL and display it right away: | ||
@@ -74,11 +76,17 @@ | ||
Get a PNG image blob and download it (using [FileSaver](https://github.com/eligrey/FileSaver.js)): | ||
#### toSvg | ||
Get an SVG data URL, but filter out all the `<i>` elements: | ||
```js | ||
htmlToImage.toBlob(document.getElementById('my-node')) | ||
.then(function (blob) { | ||
window.saveAs(blob, 'my-node.png'); | ||
function filter (node) { | ||
return (node.tagName !== 'i'); | ||
} | ||
htmlToImage.toSvg(document.getElementById('my-node'), { filter: filter }) | ||
.then(function (dataUrl) { | ||
/* do something */ | ||
}); | ||
``` | ||
#### toJpeg | ||
Save and download a compressed JPEG image: | ||
@@ -96,15 +104,23 @@ | ||
Get an SVG data URL, but filter out all the `<i>` elements: | ||
#### toBlob | ||
Get a PNG image blob and download it (using [FileSaver](https://github.com/eligrey/FileSaver.js)): | ||
```js | ||
function filter (node) { | ||
return (node.tagName !== 'i'); | ||
} | ||
htmlToImage.toBlob(document.getElementById('my-node')) | ||
.then(function (blob) { | ||
window.saveAs(blob, 'my-node.png'); | ||
}); | ||
``` | ||
htmlToImage.toSvg(document.getElementById('my-node'), { filter: filter }) | ||
.then(function (dataUrl) { | ||
/* do something */ | ||
#### toCanvas | ||
Get a HTMLCanvasElement, and display it right away: | ||
```js | ||
htmlToImage.toCanvas(document.getElementById('my-node')) | ||
.then(function (canvas) { | ||
document.body.appendChild(canvas); | ||
}); | ||
``` | ||
#### toPixelData | ||
Get the raw pixel data as a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) with every 4 array elements representing the RGBA data of a pixel: | ||
@@ -127,11 +143,2 @@ | ||
Get a HTMLCanvasElement, and display it right away: | ||
```js | ||
htmlToImage.toCanvas(document.getElementById('my-node')) | ||
.then(function (canvas) { | ||
document.body.appendChild(canvas); | ||
}); | ||
``` | ||
## Options | ||
@@ -138,0 +145,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
166240
2044
232