diff --git a/dist/rasterizeHTML.allinone.js b/dist/rasterizeHTML.allinone.js index dc5f2cbc..498d08c3 100644 --- a/dist/rasterizeHTML.allinone.js +++ b/dist/rasterizeHTML.allinone.js @@ -1,4 +1,4 @@ -/*! rasterizeHTML.js - v0.9.0 - 2014-06-06 +/*! rasterizeHTML.js - v0.9.1 - 2014-06-06 * http://www.github.com/cburgmer/rasterizeHTML.js * Copyright (c) 2014 Christoph Burgmer; Licensed MIT */ /* Integrated dependencies: diff --git a/dist/rasterizeHTML.js b/dist/rasterizeHTML.js index a052d5f9..92204e6e 100644 --- a/dist/rasterizeHTML.js +++ b/dist/rasterizeHTML.js @@ -1,4 +1,4 @@ -/*! rasterizeHTML.js - v0.9.0 - 2014-06-06 +/*! rasterizeHTML.js - v0.9.1 - 2014-06-06 * http://www.github.com/cburgmer/rasterizeHTML.js * Copyright (c) 2014 Christoph Burgmer; Licensed MIT */ (function(root, factory) { diff --git a/dist/rasterizeHTML.min.js b/dist/rasterizeHTML.min.js index 6a5d485e..490686f5 100644 --- a/dist/rasterizeHTML.min.js +++ b/dist/rasterizeHTML.min.js @@ -1,4 +1,4 @@ -/*! rasterizeHTML.js - v0.9.0 - 2014-06-06 +/*! rasterizeHTML.js - v0.9.1 - 2014-06-06 * http://www.github.com/cburgmer/rasterizeHTML.js * Copyright (c) 2014 Christoph Burgmer; Licensed MIT */ !function(a,b){"object"==typeof exports?module.exports=b(require("url"),require("xmlserializer"),require("ayepromise"),require("inlineresources")):"function"==typeof define&&define.amd?define(["url","xmlserializer","ayepromise","inlineresources"],b):a.rasterizeHTML=b(a.url,a.xmlserializer,a.ayepromise,a.inlineresources)}(this,function(a,b,c,d){var e=function(a){"use strict";var b={},c=[];b.joinUrl=function(b,c){return b?a.resolve(b,c):c},b.getConstantUniqueIdFor=function(a){return c.indexOf(a)<0&&c.push(a),c.indexOf(a)},b.clone=function(a){var b,c={};for(b in a)a.hasOwnProperty(b)&&(c[b]=a[b]);return c};var d=function(a){return"object"==typeof a&&null!==a},e=function(a){return d(a)&&Object.prototype.toString.apply(a).match(/\[object (Canvas|HTMLCanvasElement)\]/i)},f=function(a){return"function"==typeof a};return b.parseOptionalParameters=function(a){var c={canvas:null,options:{},callback:null};return f(a[0])?c.callback=a[0]:null==a[0]||e(a[0])?(c.canvas=a[0]||null,f(a[1])?c.callback=a[1]:(c.options=b.clone(a[1]),c.callback=a[2]||null)):(c.options=b.clone(a[0]),c.callback=a[1]||null),c},b}(a),f=function(a,b){var c={};return c.baseUrlRespecting=function(b,c){var d=function(){var d=new b,e=d.open;return d.open=function(){var b=Array.prototype.slice.call(arguments),d=b.shift(),f=b.shift(),g=a.joinUrl(c,f);return e.apply(this,[d,g].concat(b))},d};return d},c.finishNotifying=function(a){var c=0,d=0,e=!1,f=b.defer(),g=function(){var a=c-d;0>=a&&e&&f.resolve({totalCount:c})},h=function(){var b=new a,e=b.send;return b.send=function(){return c+=1,e.apply(this,arguments)},b.addEventListener("load",function(){d+=1,g()}),b};return h.waitForRequestsToFinish=function(){return e=!0,g(),f.promise},h},c}(e,c),g=function(){"use strict";var a={},b=function(a){return Array.prototype.slice.call(a)};a.addClassNameRecursively=function(b,c){b.className+=" "+c,b.parentNode!==b.ownerDocument&&a.addClassNameRecursively(b.parentNode,c)};var c=function(a,c){var d=a.parentStyleSheet,e=b(d.cssRules).indexOf(a);d.insertRule(c,e+1),d.deleteRule(e)},d=function(a,b){var d=a.cssText.replace(/^[^\{]+/,""),e=b+" "+d;c(a,e)},e=function(a){return b(a).reduce(function(a,b){return a+b.cssText},"")},f=function(a){a.textContent=e(a.sheet.cssRules)};return a.rewriteStyleRuleSelector=function(a,c,e){var g=c+"(?=\\W|$)";b(a.querySelectorAll("style")).forEach(function(a){var c=b(a.sheet.cssRules).filter(function(a){return a.selectorText&&new RegExp(g).test(a.selectorText)});c.length&&(c.forEach(function(a){var b=a.selectorText.replace(new RegExp(g,"g"),e);d(a,b)}),f(a))})},a}(),h=function(a){"use strict";var b={},c=function(a){return Array.prototype.slice.call(a)};return b.fakeHover=function(b,c){var d=b.querySelector(c),e="rasterizehtmlhover";d&&(a.addClassNameRecursively(d,e),a.rewriteStyleRuleSelector(b,":hover","."+e))},b.fakeActive=function(b,c){var d=b.querySelector(c),e="rasterizehtmlactive";d&&(a.addClassNameRecursively(d,e),a.rewriteStyleRuleSelector(b,":active","."+e))},b.persistInputValues=function(a){var b=a.querySelectorAll("input"),d=a.querySelectorAll("textarea"),e=function(a){return"checkbox"===a.type||"radio"===a.type};c(b).filter(e).forEach(function(a){a.checked?a.setAttribute("checked",""):a.removeAttribute("checked")}),c(b).filter(function(a){return!e(a)}).forEach(function(a){a.setAttribute("value",a.value)}),c(d).forEach(function(a){a.textContent=a.value})},b}(g),i=function(a,b,c,d){"use strict";var e={},f=function(a,b){var c=a.createElement(b);return c.style.visibility="hidden",c.style.width="0px",c.style.height="0px",c.style.position="absolute",c.style.top="-10000px",c.style.left="-10000px",a.getElementsByTagName("body")[0].appendChild(c),c};e.executeJavascript=function(a,e,g){var h=f(d.document,"iframe"),i=a.documentElement.outerHTML,j=[],k=c.defer(),l=function(){var a=h.contentDocument;d.document.getElementsByTagName("body")[0].removeChild(h),k.resolve({document:a,errors:j})},m=function(){var a=c.defer();return g>0?setTimeout(a.resolve,g):a.resolve(),a.promise};h.onload=function(){m().then(o.waitForRequestsToFinish).then(l)};var n=h.contentWindow.XMLHttpRequest,o=b.finishNotifying(n),p=b.baseUrlRespecting(o,e);return h.contentDocument.open(),h.contentWindow.XMLHttpRequest=p,h.contentWindow.onerror=function(a){j.push({resourceType:"scriptExecution",msg:a})},h.contentDocument.write(i),h.contentDocument.close(),k.promise};var g=function(a,b,c){var d=a.createElement("iframe");return d.style.width=b+"px",d.style.height=c+"px",d.style.visibility="hidden",d.style.position="absolute",d.style.top=-1e4-c+"px",d.style.left=-1e4-b+"px",d.sandbox="allow-same-origin",a.getElementsByTagName("body")[0].appendChild(d),d};e.calculateDocumentContentSize=function(a,b,e){var f=a.documentElement.outerHTML,h=g(d.document,b,e),i=c.defer();return h.onload=function(){var a=h.contentDocument,b=Math.max(a.documentElement.scrollWidth,a.body.clientWidth),c=Math.max(a.documentElement.scrollHeight,a.body.scrollHeight,a.body.clientHeight);d.document.getElementsByTagName("body")[0].removeChild(h),i.resolve({width:b,height:c})},h.contentDocument.open(),h.contentDocument.write(f),h.contentDocument.close(),i.promise};var h=function(a,b){var c,e,f,g,h=/]*)?)>/im.exec(b),i=d.document.implementation.createHTMLDocument("");if(h)for(c="",i.documentElement.innerHTML=c,f=i.querySelector("div"),e=0;e","text/html")?b=(new DOMParser).parseFromString(a,"text/html"):(b=d.document.implementation.createHTMLDocument(""),b.documentElement.innerHTML=a,h(b,a)),b};var i=function(a){var b=new DOMParser,c=b.parseFromString("<","text/xml"),d=c.getElementsByTagName("parsererror")[0].namespaceURI;return"http://www.w3.org/1999/xhtml"===d?a.getElementsByTagName("parsererror").length>0:a.getElementsByTagNameNS(d,"parsererror").length>0},j=function(a){if(i(a))throw{message:"Invalid source"}};e.validateXHTML=function(a){var b=new DOMParser,c=b.parseFromString(a,"application/xml");j(c)};var k=null,l=function(a,b){return b===!1||"none"===b||"repeated"===b?((null===k||"repeated"!==b)&&(k=Date.now()),a+"?_="+k):a},m=function(b,d){var e=new window.XMLHttpRequest,f=a.joinUrl(d.baseUrl,b),g=l(f,d.cache),h=c.defer(),i=function(){h.reject({message:"Unable to load page"})};e.addEventListener("load",function(){200===e.status||0===e.status?h.resolve(e.responseXML):i()},!1),e.addEventListener("error",function(){i()},!1);try{e.open("GET",g,!0),e.responseType="document",e.send(null)}catch(j){i()}return h.promise};return e.loadDocument=function(a,b){return m(a,b).then(function(a){return j(a),a})},e}(e,f,c,window),j=function(a,b,c,d,e,f){"use strict";var g={},h=function(a){return Array.prototype.slice.call(a)},i=function(){if(f.navigator.userAgent.indexOf("WebKit")>=0&&f.navigator.userAgent.indexOf("Chrome")<0)return!1;if(f.BlobBuilder||f.MozBlobBuilder||f.WebKitBlobBuilder)return!0;if(f.Blob)try{return new f.Blob([""],{type:"text/xml"}),!0}catch(a){return!1}return!1},j=function(a){var b,c="image/svg+xml;charset=utf-8",d=f.BlobBuilder||f.MozBlobBuilder||f.WebKitBlobBuilder;return d?(b=new d,b.append(a),b.getBlob(c)):new f.Blob([a],{type:c})},k=function(a){var b=f.URL||f.webkitURL||f;return i()?b.createObjectURL(j(a)):"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(a)},l=function(a){var b=f.URL||f.webkitURL||f;i()&&b.revokeObjectURL(a)},m=function(a,b){var c=a.createElement(b);return c.style.visibility="hidden",c.style.width="0px",c.style.height="0px",c.style.position="absolute",c.style.top="-10000px",c.style.left="-10000px",a.getElementsByTagName("body")[0].appendChild(c),c},n=function(a,b){var c=a.getElementById(b);return c||(c=m(a,"div"),c.id=b),c},o="rasterizeHTML_js_FirefoxWorkaround",p=function(){var a=f.navigator.userAgent.match(/Firefox\/(\d+).0/);return!a||!a[1]||parseInt(a[1],10)<17},q=function(b,c){var d,e=a.getConstantUniqueIdFor(b),g=c?c.ownerDocument:f.document;p()&&(d=n(g,o+e),d.innerHTML=b,d.className=o)},r=function(a){f.navigator.userAgent.indexOf("WebKit")>=0&&h(a.getElementsByTagName("style")).forEach(function(a){a.textContent="span {}\n"+a.textContent})},s=function(b,c){var d=a.getConstantUniqueIdFor(b),e=c?c.ownerDocument:f.document,g=e.getElementById(o+d);g&&g.parentNode.removeChild(g)},t=function(a,b,c){var d,e,f="";return c=c||1,d=Math.round(a/c),e=Math.round(b/c),1!==c&&(f=' style="-webkit-transform: scale('+c+"); -webkit-transform-origin: top left; transform: scale("+c+'); transform-origin: top left;"'),' width="'+d+'" height="'+e+'"'+f};g.getSvgForDocument=function(a,c,e,f){var g;return r(a),g=d.serializeToString(a),b.validateXHTML(g),'"+g+""};var u=function(){return{message:"Error rendering page"}};g.renderSvg=function(a,b){var c,d,g=e.defer(),h=function(){d.onload=null,d.onerror=null},i=function(){c&&l(c),s(a,b)};return q(a,b),c=k(a),d=new f.Image,d.onload=function(){h(),i(),g.resolve(d)},d.onerror=function(){i(),g.reject(u())},d.src=c,g.promise},g.drawImageOnCanvas=function(a,b){try{b.getContext("2d").drawImage(a,0,0)}catch(c){throw u()}};var v=function(a,b){var c=300,d=200,e=a?a.width:c,f=a?a.height:d,g=void 0!==b.width?b.width:e,h=void 0!==b.height?b.height:f;return{width:g,height:h}};return g.drawDocumentImage=function(a,d,e){var f=v(d,e);return e.hover&&c.fakeHover(a,e.hover),e.active&&c.fakeActive(a,e.active),b.calculateDocumentContentSize(a,f.width,f.height).then(function(b){return g.getSvgForDocument(a,b.width,b.height,e.zoom)}).then(function(a){return g.renderSvg(a,d)})},g}(e,i,h,b,c,window),k=function(a,b,c,d,e){"use strict";var f={},g=function(a,b,c){return d.drawDocumentImage(a,b,c).then(function(a){return b&&d.drawImageOnCanvas(a,b),a})},h=function(a,d){var e=d.executeJsTimeout||0;return b.executeJavascript(a,d.baseUrl,e).then(function(a){var b=a.document;return c.persistInputValues(b),{document:b,errors:a.errors}})},i=function(b,c,d){var f;return f=a.clone(d),f.inlineScripts=d.executeJs===!0,e.inlineReferences(b,f).then(function(a){return d.executeJs?h(b,d).then(function(b){return{document:b.document,errors:a.concat(b.errors)}}):{document:b,errors:a}}).then(function(a){return g(a.document,c,d).then(function(b){return{image:b,errors:a.errors}})})};f.drawDocument=function(){var b=arguments[0],c=Array.prototype.slice.call(arguments,1),d=a.parseOptionalParameters(c),e=i(b,d.canvas,d.options);return d.callback&&e.then(function(a){d.callback(a.image,a.errors)},function(){d.callback(null,[{resourceType:"document",msg:"Error rendering page"}])}),e};var j=function(a,c,d,e){var g=b.parseHTML(a);return f.drawDocument(g,c,d,e)};f.drawHTML=function(){var b=arguments[0],c=Array.prototype.slice.call(arguments,1),d=a.parseOptionalParameters(c);return j(b,d.canvas,d.options,d.callback)};var k=function(a,c,d,e){var g=b.loadDocument(a,d).then(function(a){return f.drawDocument(a,c,d)});return e&&g.then(function(a){e(a.image,a.errors)},function(b){e(null,[{resourceType:"page",url:a,msg:b.message+" "+a}])}),g};return f.drawURL=function(){var b=arguments[0],c=Array.prototype.slice.call(arguments,1),d=a.parseOptionalParameters(c);return k(b,d.canvas,d.options,d.callback)},f}(e,i,h,j,d);return k}); \ No newline at end of file diff --git a/package.json b/package.json index da342061..4698bcfe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "rasterizehtml", "title": "rasterizeHTML.js", - "version": "0.9.0", + "version": "0.9.1", "description": "Renders HTML into the browser's canvas.", "keywords": [ "canvas",