diff --git a/dist/dom-to-image.min.js b/dist/dom-to-image.min.js index bc732274..8616ecec 100644 --- a/dist/dom-to-image.min.js +++ b/dist/dom-to-image.min.js @@ -1,2 +1,2 @@ -/*! dom-to-image 10-06-2017 */ -!function(a){"use strict";function b(a,b){function c(a){return b.bgcolor&&(a.style.backgroundColor=b.bgcolor),b.width&&(a.style.width=b.width+"px"),b.height&&(a.style.height=b.height+"px"),b.style&&Object.keys(b.style).forEach(function(c){a.style[c]=b.style[c]}),a}return b=b||{},g(b),Promise.resolve(a).then(function(a){return i(a,b.filter,!0)}).then(j).then(k).then(c).then(function(c){return l(c,b.width||q.width(a),b.height||q.height(a))})}function c(a,b){return h(a,b||{}).then(function(b){return b.getContext("2d").getImageData(0,0,q.width(a),q.height(a)).data})}function d(a,b){return h(a,b||{}).then(function(a){return a.toDataURL()})}function e(a,b){return b=b||{},h(a,b).then(function(a){return a.toDataURL("image/jpeg",b.quality||1)})}function f(a,b){return h(a,b||{}).then(q.canvasToBlob)}function g(a){"undefined"==typeof a.imagePlaceholder?v.impl.options.imagePlaceholder=u.imagePlaceholder:v.impl.options.imagePlaceholder=a.imagePlaceholder,"undefined"==typeof a.cacheBust?v.impl.options.cacheBust=u.cacheBust:v.impl.options.cacheBust=a.cacheBust}function h(a,c){function d(a){var b=document.createElement("canvas");if(b.width=c.width||q.width(a),b.height=c.height||q.height(a),c.bgcolor){var d=b.getContext("2d");d.fillStyle=c.bgcolor,d.fillRect(0,0,b.width,b.height)}return b}return b(a,c).then(q.makeImage).then(q.delay(100)).then(function(b){var c=d(a);return c.getContext("2d").drawImage(b,0,0),c})}function i(a,b,c){function d(a){return a instanceof HTMLCanvasElement?q.makeImage(a.toDataURL()):a.cloneNode(!1)}function e(a,b,c){function d(a,b,c){var d=Promise.resolve();return b.forEach(function(b){d=d.then(function(){return i(b,c)}).then(function(b){b&&a.appendChild(b)})}),d}var e=a.childNodes;return 0===e.length?Promise.resolve(b):d(b,q.asArray(e),c).then(function(){return b})}function f(a,b){function c(){function c(a,b){function c(a,b){q.asArray(a).forEach(function(c){b.setProperty(c,a.getPropertyValue(c),a.getPropertyPriority(c))})}a.cssText?b.cssText=a.cssText:c(a,b)}c(window.getComputedStyle(a),b.style)}function d(){function c(c){function d(a,b,c){function d(a){var b=a.getPropertyValue("content");return a.cssText+" content: "+b+";"}function e(a){function b(b){return b+": "+a.getPropertyValue(b)+(a.getPropertyPriority(b)?" !important":"")}return q.asArray(a).map(b).join("; ")+";"}var f="."+a+":"+b,g=c.cssText?d(c):e(c);return document.createTextNode(f+"{"+g+"}")}var e=window.getComputedStyle(a,c),f=e.getPropertyValue("content");if(""!==f&&"none"!==f){var g=q.uid();b.className=b.className+" "+g;var h=document.createElement("style");h.appendChild(d(g,c,e)),b.appendChild(h)}}[":before",":after"].forEach(function(a){c(a)})}function e(){a instanceof HTMLTextAreaElement&&(b.innerHTML=a.value),a instanceof HTMLInputElement&&b.setAttribute("value",a.value)}function f(){b instanceof SVGElement&&(b.setAttribute("xmlns","http://www.w3.org/2000/svg"),b instanceof SVGRectElement&&["width","height"].forEach(function(a){var c=b.getAttribute(a);c&&b.style.setProperty(a,c)}))}return b instanceof Element?Promise.resolve().then(c).then(d).then(e).then(f).then(function(){return b}):b}return c||!b||b(a)?Promise.resolve(a).then(d).then(function(c){return e(a,c,b)}).then(function(b){return f(a,b)}):Promise.resolve()}function j(a){return s.resolveAll().then(function(b){var c=document.createElement("style");return a.appendChild(c),c.appendChild(document.createTextNode(b)),a})}function k(a){return t.inlineAll(a).then(function(){return a})}function l(a,b,c){return Promise.resolve(a).then(function(a){return a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),(new XMLSerializer).serializeToString(a)}).then(q.escapeXhtml).then(function(a){return''+a+""}).then(function(a){return''+a+""}).then(function(a){return"data:image/svg+xml;charset=utf-8,"+a})}function m(){function a(){var a="application/font-woff",b="image/jpeg";return{woff:a,woff2:a,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:b,jpeg:b,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}function b(a){var b=/\.([^\.\/]*?)$/g.exec(a);return b?b[1]:""}function c(c){var d=b(c).toLowerCase();return a()[d]||""}function d(a){return a.search(/^(data:)/)!==-1}function e(a){return new Promise(function(b){for(var c=window.atob(a.toDataURL().split(",")[1]),d=c.length,e=new Uint8Array(d),f=0;f'+a+""}).then(function(a){return''+a+""}).then(function(a){return"data:image/svg+xml;charset=utf-8,"+a})}function m(){function a(){var a="application/font-woff",b="image/jpeg";return{woff:a,woff2:a,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:b,jpeg:b,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}function b(a){var b=/\.([^\.\/]*?)$/g.exec(a);return b?b[1]:""}function c(c){var d=b(c).toLowerCase();return a()[d]||""}function d(a){return a.search(/^(data:)/)!==-1}function e(a){return new Promise(function(b){for(var c=window.atob(a.toDataURL().split(",")[1]),d=c.length,e=new Uint8Array(d),f=0;f=s.ERROR&&console.error(a)}function r(a){y.impl.options.logLevel>=s.WARNING&&console.warn(a)}var s={ERROR:1,WARNING:2},t=m(),u=n(),v=o(),w=p(),x={imagePlaceholder:void 0,cacheBust:!1,logLevel:s.WARNING},y={toSvg:b,toPng:d,toJpeg:e,toBlob:f,toPixelData:c,logLevels:s,impl:{fontFaces:v,images:w,util:t,inliner:u,options:{}}};"undefined"!=typeof module?module.exports=y:a.domtoimage=y}(this); \ No newline at end of file diff --git a/src/dom-to-image.js b/src/dom-to-image.js index 27201ac9..6e438c6b 100644 --- a/src/dom-to-image.js +++ b/src/dom-to-image.js @@ -1,6 +1,10 @@ (function (global) { 'use strict'; + var logLevels = { + ERROR: 1, + WARNING: 2, + }; var util = newUtil(); var inliner = newInliner(); var fontFaces = newFontFaces(); @@ -11,7 +15,8 @@ // Default is to fail on error, no placeholder imagePlaceholder: undefined, // Default cache bust is false, it will use the cache - cacheBust: false + cacheBust: false, + logLevel: logLevels.WARNING, }; var domtoimage = { @@ -20,6 +25,7 @@ toJpeg: toJpeg, toBlob: toBlob, toPixelData: toPixelData, + logLevels: logLevels, impl: { fontFaces: fontFaces, images: images, @@ -147,6 +153,11 @@ } else { domtoimage.impl.options.cacheBust = options.cacheBust; } + if(typeof(options.logLevel) === 'undefined') { + domtoimage.impl.options.logLevel = domtoimage.impl.options.logLevel || defaultOptions.logLevel; + } else { + domtoimage.impl.options.logLevel = options.logLevel; + } } function draw(domNode, options) { @@ -516,7 +527,7 @@ } function fail(message) { - console.error(message); + error(message); resolve(''); } }); @@ -681,7 +692,7 @@ try { util.asArray(sheet.cssRules || []).forEach(cssRules.push.bind(cssRules)); } catch (e) { - console.log('Error while reading CSS rules from ' + sheet.href, e.toString()); + warn('Error while reading CSS rules from ' + sheet.href, e.toString()); } }); return cssRules; @@ -766,4 +777,16 @@ } } } + + function error(message) { + if (domtoimage.impl.options.logLevel >= logLevels.ERROR) { + console.error(message); + } + } + + function warn(message) { + if (domtoimage.impl.options.logLevel >= logLevels.WARNING) { + console.warn(message); + } + } })(this);