html2canvas/build/html2canvas.min.js

7 lines
19 KiB
JavaScript
Raw Normal View History

2013-09-07 22:24:41 +04:00
/*
2014-01-19 20:04:27 +04:00
html2canvas 0.5.0-rc1 <http://html2canvas.hertzen.com>
Copyright (c) 2014 Niklas von Hertzen
2013-09-07 22:24:41 +04:00
Released under MIT License
*/
(function(t,e,n){function o(){return Math.max(Math.max(e.body.scrollWidth,e.documentElement.scrollWidth),Math.max(e.body.offsetWidth,e.documentElement.offsetWidth),Math.max(e.body.clientWidth,e.documentElement.clientWidth))}function i(){return Math.max(Math.max(e.body.scrollHeight,e.documentElement.scrollHeight),Math.max(e.body.offsetHeight,e.documentElement.offsetHeight),Math.max(e.body.clientHeight,e.documentElement.clientHeight))}function r(t,e,n){var o=t.documentElement.cloneNode(!0),i=t.createElement("iframe");i.style.display="hidden",i.style.position="absolute",i.style.width=e+"px",i.style.height=n+"px",t.body.appendChild(i);var r=i.contentWindow.document;return r.replaceChild(r.adoptNode(o),r.documentElement),i}function s(t,e,n,o,i){this.renderer=e,this.options=i,this.range=null,this.support=n,this.stack=new _(!0,1,t.ownerDocument,null);var r=new P(t,null);r.visibile=r.isElementVisible(),this.nodes=[r].concat(this.getChildren(r)).filter(function(t){return t.visible=t.isElementVisible()}),this.images=o.fetch(this.nodes.filter(C)),this.createStackingContexts(),this.sortStackingContexts(this.stack),this.images.ready.then(N(function(){W("Images loaded, starting parsing"),this.parse(this.stack),i.onrendered(e.canvas)},this))}function a(t){return 0>t.cssInt("zIndex")}function c(t){return t.cssInt("zIndex")>0}function h(t){return 0===t.cssInt("zIndex")}function u(t){return-1!==["inline","inline-block","inline-table"].indexOf(t.css("display"))}function p(t){return t instanceof _}function d(t){return t.node.data.trim().length>0}function l(t){return/^(normal|none|0px)$/.test(t.parent.css("letterSpacing"))}function f(t,e,n,o,i,r,s){e[0]>0||e[1]>0?(t.push(["line",o[0].start.x,o[0].start.y]),o[0].curveTo(t),o[1].curveTo(t)):t.push(["line",r,s]),(n[0]>0||n[1]>0)&&t.push(["line",i[0].start.x,i[0].start.y])}function g(t){return["TopLeft","TopRight","BottomRight","BottomLeft"].map(function(e){var n=t.css("border"+e+"Radius"),o=n.split(" ");return 1>=o.length&&(o[1]=o[0]),o.map(m)})}function m(t){return parseInt(t,10)}function y(t,e,n,o){var i=4*((Math.sqrt(2)-1)/3),r=n*i,s=o*i,a=t+n,c=e+o;return{topLeft:w({x:t,y:c},{x:t,y:c-s},{x:a-r,y:e},{x:a,y:e}),topRight:w({x:t,y:e},{x:t+r,y:e},{x:a,y:c-s},{x:a,y:c}),bottomRight:w({x:a,y:e},{x:a,y:e+s},{x:t+r,y:c},{x:t,y:c}),bottomLeft:w({x:a,y:c},{x:a-r,y:c},{x:t,y:e+s},{x:t,y:e})}}function b(t,e,n){var o=t.left,i=t.top,r=t.width,s=t.height,a=e[0][0],c=e[0][1],h=e[1][0],u=e[1][1],p=e[2][0],d=e[2][1],l=e[3][0],f=e[3][1],g=r-h,m=s-d,b=r-p,w=s-f;return{topLeftOuter:y(o,i,a,c).topLeft.subdivide(.5),topLeftInner:y(o+n[3].width,i+n[0].width,Math.max(0,a-n[3].width),Math.max(0,c-n[0].width)).topLeft.subdivide(.5),topRightOuter:y(o+g,i,h,u).topRight.subdivide(.5),topRightInner:y(o+Math.min(g,r+n[3].width),i+n[0].width,g>r+n[3].width?0:h-n[3].width,u-n[0].width).topRight.subdivide(.5),bottomRightOuter:y(o+b,i+m,p,d).bottomRight.subdivide(.5),bottomRightInner:y(o+Math.min(b,r+n[3].width),i+Math.min(m,s+n[0].width),Math.max(0,p-n[1].width),Math.max(0,d-n[2].width)).bottomRight.subdivide(.5),bottomLeftOuter:y(o,i+w,l,f).bottomLeft.subdivide(.5),bottomLeftInner:y(o+n[3].width,i+w,Math.max(0,l-n[3].width),Math.max(0,f-n[2].width)).bottomLeft.subdivide(.5)}}function w(t,e,n,o){var i=function(t,e,n){return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}};return{start:t,startControl:e,endControl:n,end:o,subdivide:function(r){var s=i(t,e,r),a=i(e,n,r),c=i(n,o,r),h=i(s,a,r),u=i(a,c,r),p=i(h,u,r);return[w(t,s,h,p),w(p,u,c,o)]},curveTo:function(t){t.push(["bezierCurve",e.x,e.y,n.x,n.y,o.x,o.y])},curveToReversed:function(o){o.push(["bezierCurve",n.x,n.y,e.x,e.y,t.x,t.y])}}}function x(t,e,n,o,i,r,s){var a=[];return e[0]>0||e[1]>0?(a.push(["line",o[1].start.x,o[1].start.y]),o[1].curveTo(a)):a.push(["line",t.c1[0],t.c1[1]]),n[0]>0||n[1]>0?(a.push(["line",r[0].start.x,r[0].start.y]),r[0].curveTo(a),a.push(["line",s[0].end.x,s[0].end.y]),s[0].curveToReversed(a)):(a.push(["line",t.c2[0],t.c2[1]]),a.push(["line",t.c3[0],t.c3[1]])),e[0]>0||e[1]>0?(a.push(["line",i[1].end.x,i[1].end.y]),i[1].curveToReversed(a)):a.push(["line",t.c4[0