html2canvas/build/html2canvas.min.js

8 lines
37 KiB
JavaScript
Raw Normal View History

2013-09-07 22:24:41 +04:00
/*
html2canvas 0.4.1 <http://html2canvas.hertzen.com>
Copyright (c) 2013 Niklas von Hertzen
Released under MIT License
*/
!function(a,b,c){"use strict";function d(a,b,c){var d,e=a.runtimeStyle&&a.runtimeStyle[b],f=a.style;return!/^-?[0-9]+\.?[0-9]*(?:px)?$/i.test(c)&&/^-?\d/.test(c)&&(d=f.left,e&&(a.runtimeStyle.left=a.currentStyle.left),f.left="fontSize"===b?"1em":c||0,c=f.pixelLeft+"px",f.left=d,e&&(a.runtimeStyle.left=e)),/^(thin|medium|thick)$/i.test(c)?c:Math.round(parseFloat(c))+"px"}function e(a){return parseInt(a,10)}function f(a,b,e,f){if(a=(a||"").split(","),a=a[f||0]||a[0]||"auto",a=k.Util.trimText(a).split(" "),"backgroundSize"!==e||a[0]&&!a[0].match(/cover|contain|auto/)){if(a[0]=-1===a[0].indexOf("%")?d(b,e+"X",a[0]):a[0],a[1]===c){if("backgroundSize"===e)return a[1]="auto",a;a[1]=a[0]}a[1]=-1===a[1].indexOf("%")?d(b,e+"Y",a[1]):a[1]}else;return a}function g(a,b,c,d,e,f){var g,h,i,j,l=k.Util.getCSS(b,a,e);if(1===l.length&&(j=l[0],l=[],l[0]=j,l[1]=j),-1!==l[0].toString().indexOf("%"))i=parseFloat(l[0])/100,h=c.width*i,"backgroundSize"!==a&&(h-=(f||d).width*i);else if("backgroundSize"===a)if("auto"===l[0])h=d.width;else if(/contain|cover/.test(l[0])){var m=k.Util.resizeBounds(d.width,d.height,c.width,c.height,l[0]);h=m.width,g=m.height}else h=parseInt(l[0],10);else h=parseInt(l[0],10);return"auto"===l[1]?g=h/d.width*d.height:-1!==l[1].toString().indexOf("%")?(i=parseFloat(l[1])/100,g=c.height*i,"backgroundSize"!==a&&(g-=(f||d).height*i)):g=parseInt(l[1],10),[h,g]}function h(a,b){var c=[];return{storage:c,width:a,height:b,clip:function(){c.push({type:"function",name:"clip",arguments:arguments})},translate:function(){c.push({type:"function",name:"translate",arguments:arguments})},fill:function(){c.push({type:"function",name:"fill",arguments:arguments})},save:function(){c.push({type:"function",name:"save",arguments:arguments})},restore:function(){c.push({type:"function",name:"restore",arguments:arguments})},fillRect:function(){c.push({type:"function",name:"fillRect",arguments:arguments})},createPattern:function(){c.push({type:"function",name:"createPattern",arguments:arguments})},drawShape:function(){var a=[];return c.push({type:"function",name:"drawShape",arguments:a}),{moveTo:function(){a.push({name:"moveTo",arguments:arguments})},lineTo:function(){a.push({name:"lineTo",arguments:arguments})},arcTo:function(){a.push({name:"arcTo",arguments:arguments})},bezierCurveTo:function(){a.push({name:"bezierCurveTo",arguments:arguments})},quadraticCurveTo:function(){a.push({name:"quadraticCurveTo",arguments:arguments})}}},drawImage:function(){c.push({type:"function",name:"drawImage",arguments:arguments})},fillText:function(){c.push({type:"function",name:"fillText",arguments:arguments})},setVariable:function(a,b){return c.push({type:"variable",name:a,arguments:b}),b}}}var i,j,k={};k.Util={},k.Util.log=function(b){k.logging&&a.console&&a.console.log&&a.console.log(b)},k.Util.trimText=function(a){return function(b){return a?a.apply(b):((b||"")+"").replace(/^\s+|\s+$/g,"")}}(String.prototype.trim),k.Util.asFloat=function(a){return parseFloat(a)},function(){var a=/((rgba|rgb)\([^\)]+\)(\s-?\d+px){0,})/g,b=/(-?\d+px)|(#.+)|(rgb\(.+\))|(rgba\(.+\))/g;k.Util.parseTextShadows=function(c){if(!c||"none"===c)return[];for(var d=c.match(a),e=[],f=0;d&&f<d.length;f++){var g=d[f].match(b);e.push({color:g[0],offsetX:g[1]?g[1].replace("px",""):0,offsetY:g[2]?g[2].replace("px",""):0,blur:g[3]?g[3].replace("px",""):0})}return e}}(),k.Util.parseBackgroundImage=function(a){var b,c,d,e,f,g,h,i,j=" \r\n ",k=[],l=0,m=0,n=function(){b&&('"'===c.substr(0,1)&&(c=c.substr(1,c.length-2)),c&&i.push(c),"-"===b.substr(0,1)&&(e=b.indexOf("-",1)+1)>0&&(d=b.substr(0,e),b=b.substr(e)),k.push({prefix:d,method:b.toLowerCase(),value:f,args:i})),i=[],b=d=c=f=""};n();for(var o=0,p=a.length;p>o;o++)if(g=a[o],!(0===l&&j.indexOf(g)>-1)){switch(g){case'"':h?h===g&&(h=null):h=g;break;case"(":if(h)break;if(0===l){l=1,f+=g;continue}m++;break;case")":if(h)break;if(1===l){if(0===m){l=0,f+=g,n();continue}m--}break;case",":if(h)break;if(0===l){n();continue}if(1===l&&0===m&&!b.match(/^url$/i)){i.push(c),c="",f+=g;continue}}f+=g,0===l?b+=g:c+=g}return n(),k},k.Util.Bounds=function(a){var b,c={
try{delete a[g.callbackname]}catch(i){}g.script&&g.script.parentNode&&(g.script.setAttribute("src","about:blank"),g.script.parentNode.removeChild(g.script)),t.numLoaded++,t.numFailed++,u.log("html2canvas: Cleaned up failed img: '"+h+"' Steps: "+t.numLoaded+" / "+t.numTotal)}a.stop!==c?a.stop():b.execCommand!==c&&b.execCommand("Stop",!1),b.close!==c&&b.close(),t.cleanupDone=!0,e&&"string"==typeof e||f()}},renderingDone:function(){s&&a.clearTimeout(s)}},d.timeout>0&&(s=a.setTimeout(q.cleanupDOM,d.timeout)),u.log("html2canvas: Preload starts: finding background-images"),t.firstRun=!0,n(w),u.log("html2canvas: Preload: Finding images"),r=0;z>r;r+=1)q.loadImage(y[r].getAttribute("src"));return t.firstRun=!1,u.log("html2canvas: Preload: Done."),t.numTotal===t.numLoaded&&f(),q},k.Renderer=function(a,d){function e(a){function b(a){Object.keys(a).sort().forEach(function(c){var d=[],f=[],g=[],h=[];a[c].forEach(function(a){a.node.zIndex.isPositioned||a.node.zIndex.opacity<1?g.push(a):a.node.zIndex.isFloated?f.push(a):d.push(a)}),function i(a){a.forEach(function(a){h.push(a),a.children&&i(a.children)})}(d.concat(f,g)),h.forEach(function(a){a.context?b(a.context):e.push(a.node)})})}var d,e=[];return d=function(a){function b(a,d,e){var f="auto"===d.zIndex.zindex?0:Number(d.zIndex.zindex),g=a,h=d.zIndex.isPositioned,i=d.zIndex.isFloated,j={node:d},k=e;d.zIndex.ownStacking?(g=j.context={"!":[{node:d,children:[]}]},k=c):(h||i)&&(k=j.children=[]),0===f&&e?e.push(j):(a[f]||(a[f]=[]),a[f].push(j)),d.zIndex.children.forEach(function(a){b(g,a,k)})}var d={};return b(d,a),d}(a),b(d),e}function f(a){var b;if("string"==typeof d.renderer&&k.Renderer[a]!==c)b=k.Renderer[a](d);else{if("function"!=typeof a)throw new Error("Unknown renderer");b=a(d)}if("function"!=typeof b)throw new Error("Invalid renderer defined");return b}return f(d.renderer)(a,d,b,e(a.stack),k)},k.Util.Support=function(a,b){function d(){var a=new Image,d=b.createElement("canvas"),e=d.getContext===c?!1:d.getContext("2d");if(e===!1)return!1;d.width=d.height=10,a.src=["data:image/svg+xml,","<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'>","<foreignObject width='10' height='10'>","<div xmlns='http://www.w3.org/1999/xhtml' style='width:10;height:10;'>","sup","</div>","</foreignObject>","</svg>"].join("");try{e.drawImage(a,0,0),d.toDataURL()}catch(f){return!1}return k.Util.log("html2canvas: Parse: SVG powered rendering available"),!0}function e(){var a,c,d,e,f=!1;return b.createRange&&(a=b.createRange(),a.getBoundingClientRect&&(c=b.createElement("boundtest"),c.style.height="123px",c.style.display="block",b.body.appendChild(c),a.selectNode(c),d=a.getBoundingClientRect(),e=d.height,123===e&&(f=!0),b.body.removeChild(c))),f}return{rangeBounds:e(),svgRendering:a.svgRendering&&d()}},a.html2canvas=function(b,c){b=b.length?b:[b];var d,e={logging:!1,elements:b,background:"#fff",proxy:null,timeout:0,useCORS:!1,allowTaint:!1,svgRendering:!1,ignoreElements:"IFRAME|OBJECT|PARAM",useOverflow:!0,letterRendering:!1,chinese:!1,async:!1,width:null,height:null,taintTest:!0,renderer:"Canvas"};return e=k.Util.Extend(c,e),k.logging=e.logging,e.complete=function(a){("function"!=typeof e.onpreloaded||e.onpreloaded(a)!==!1)&&k.Parse(a,e,function(a){("function"!=typeof e.onparsed||e.onparsed(a)!==!1)&&(d=k.Renderer(a,e),"function"==typeof e.onrendered&&e.onrendered(d))})},a.setTimeout(function(){k.Preload(e)},0),{render:function(a,b){return k.Renderer(a,k.Util.Extend(b,e))},parse:function(a,b){return k.Parse(a,k.Util.Extend(b,e))},preload:function(a){return k.Preload(k.Util.Extend(a,e))},log:k.Util.log}},a.html2canvas.log=k.Util.log,a.html2canvas.Renderer={Canvas:c},k.Renderer.Canvas=function(a){function d(a,b){a.beginPath(),b.forEach(function(b){a[b.name].apply(a,b.arguments)}),a.closePath()}function e(a){if(-1===h.indexOf(a.arguments[0].src)){j.drawImage(a.arguments[0],0,0);try{j.getImageData(0,0,1,1)}catch(b){return i=g.createElement("canvas"),j=i.getContext("2d"),!1}h.push(a.arguments[0].src)}return!0}function f(b,c){switch(c.type){case"variable":b[c.name]=c.arguments;break;case"function":s