mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-24 21:23:44 +00:00
1 line
No EOL
73 KiB
JavaScript
1 line
No EOL
73 KiB
JavaScript
if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());(function(a){var b=this.Canvas||(this.Canvas={});b.base={};var q=Array.prototype.slice;if(!Array.prototype.indexOf){Array.prototype.indexOf=function(u,v){var t=this.length>>>0;v=Number(v)||0;v=Math[v<0?"ceil":"floor"](v);if(v<0){v+=t}for(;v<t;v++){if(v in this&&this[v]===u){return v}}return -1}}if(!Array.prototype.forEach){Array.prototype.forEach=function(w,v){for(var u=0,t=this.length>>>0;u<t;u++){if(u in this){w.call(v,this[u],u,this)}}}}if(!Array.prototype.map){Array.prototype.map=function(x,w){var u=[];for(var v=0,t=this.length>>>0;v<t;v++){if(v in this){u[v]=x.call(w,this[v],v,this)}}return u}}if(!Array.prototype.every){Array.prototype.every=function(w,v){for(var u=0,t=this.length>>>0;u<t;u++){if(u in this&&!w.call(v,this[u],u,this)){return false}}return true}}if(!Array.prototype.some){Array.prototype.some=function(w,v){for(var u=0,t=this.length>>>0;u<t;u++){if(u in this&&w.call(v,this[u],u,this)){return true}}return false}}if(!Array.prototype.filter){Array.prototype.filter=function(x,w){var u=[],y;for(var v=0,t=this.length>>>0;v<t;v++){if(v in this){y=this[v];if(x.call(w,y,v,this)){u.push(y)}}}return res}}if(!Array.prototype.reduce){Array.prototype.reduce=function(v){var t=this.length>>>0,u=0,w;if(arguments.length>1){w=arguments[1]}else{do{if(u in this){w=this[u++];break}if(++u>=t){throw new TypeError()}}while(true)}for(;u<t;u++){if(u in this){w=v.call(null,w,this[u],u,this)}}return w}}function g(y,x){var v=q.call(arguments,2),u=[];for(var w=0,t=y.length;w<t;w++){u[w]=x.apply(y[w],v)}return u}function p(w,v){var u=w.length-1,t=w[u];while(u--){if(w[u]>=t){t=w[u]}}return t}function f(w,v){var u=w.length-1,t=w[u];while(u--){if(w[u]<t){t=w[u]}}return t}b.base.array={invoke:g,min:f,max:p};function n(t,v){for(var u in v){t[u]=v[u]}return t}function o(t){return n({},t)}b.base.object={extend:n,clone:o};if(!String.prototype.trim){String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")}}function c(t){return t.replace(/-+(.)?/g,function(u,v){return v?v.toUpperCase():""})}function k(t){return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}b.base.string={camelize:c,capitalize:k};(function(){var v=(function(){for(var x in {toString:1}){if(x==="toString"){return false}}return true})();var u;if(v){u=function(x,z){if(z.toString!==Object.prototype.toString){x.prototype.toString=z.toString}if(z.valueOf!==Object.prototype.valueOf){x.prototype.valueOf=z.valueOf}for(var y in z){x.prototype[y]=z[y]}}}else{u=function(x,z){for(var y in z){x.prototype[y]=z[y]}}}function t(){}function w(){var A=null,z=q.call(arguments,0);if(typeof z[0]==="function"){A=z.shift()}function x(){this.initialize.apply(this,arguments)}x.superclass=A;x.subclasses=[];if(A){t.prototype=A.prototype;x.prototype=new t;A.subclasses.push(x)}for(var y=0,B=z.length;y<B;y++){u(x,z[y])}if(!x.prototype.initialize){x.prototype.initialize=emptyFunction}x.prototype.constructor=x;return x}b.base.createClass=w})();(function(I){function E(M){var P=Array.prototype.slice.call(arguments,1),O,N,L=P.length;for(N=0;N<L;N++){O=typeof M[P[N]];if(!(/^(?:function|object|unknown)$/).test(O)){return false}}return true}var C=(function(){if(typeof document.documentElement.uniqueID!=="undefined"){return function(M){return M.uniqueID}}var L=0;return function(M){return M.__uniqueID||(M.__uniqueID="uniqueID__"+L++)}})();var z,J;(function(){var L={};z=function(M){return L[M]};J=function(N,M){L[N]=M}})();function x(L,M){return{handler:M,wrappedHandler:D(L,M)}}function D(L,M){return function(N){M.call(z(L),N||window.event)}}function y(M,L){return function(Q){if(G[M]&&G[M][L]){var O=G[M][L];for(var P=0,N=O.length;P<N;P++){O[P].call(this,Q||window.event)}}}}var H=(E(document.documentElement,"addEventListener","removeEventListener")&&E(window,"addEventListener","removeEventListener")),A=(E(document.documentElement,"attachEvent","detachEvent")&&E(window,"attachEvent","detachEvent")),F={},G={};if(H){addListener=function(M,L,N){M.addEventListener(L,N,false)};removeListener=function(M,L,N){M.removeEventListener(L,N,false)}}else{if(A){addListener=function(N,L,O){var M=C(N);J(M,N);if(!F[M]){F[M]={}}if(!F[M][L]){F[M][L]=[]}var P=x(M,O);F[M][L].push(P);N.attachEvent("on"+L,P.wrappedHandler)};removeListener=function(P,M,Q){var O=C(P),R;if(F[O]&&F[O][M]){for(var N=0,L=F[O][M].length;N<L;N++){R=F[O][M][N];if(R&&R.handler===Q){P.detachEvent("on"+M,R.wrappedHandler);F[O][M][N]=null}}}}}else{addListener=function(N,L,O){var M=C(N);if(!G[M]){G[M]={}}if(!G[M][L]){G[M][L]=[];var P=N["on"+L];if(P){G[M][L].push(P)}N["on"+L]=y(M,L)}G[M][L].push(O)};removeListener=function(Q,N,R){var P=C(Q);if(G[P]&&G[P][N]){var M=G[P][N];for(var O=0,L=M.length;O<L;O++){if(M[O]===R){M.splice(O,1)}}}}}}b.base.addListener=addListener;b.base.removeListener=removeListener;var u={};function w(L,M){if(!u[L]){u[L]=[]}u[L].push(M)}function K(N,M){if(!u[N]){return}for(var O=0,L=u[N].length;O<L;O++){try{u[N]({memo:M})}catch(P){setTimeout(function(){throw P},0)}}}b.base.observeEvent=w;b.base.fireEvent=K;function B(L){return{x:v(L),y:t(L)}}function v(N){var M=document.documentElement,L=document.body||{scrollLeft:0};return N.pageX||(N.clientX+(M.scrollLeft||L.scrollLeft)-(M.clientLeft||0))}function t(N){var M=document.documentElement,L=document.body||{scrollTop:0};return N.pageY||(N.clientY+(M.scrollTop||L.scrollTop)-(M.clientTop||0))}b.base.getPointer=B})(this);(function(){function x(C,E){var G=C.style,B;if(typeof E==="string"){C.style.cssText+=";"+E;return E.indexOf("opacity")>-1?v(C,E.match(/opacity:\s*(\d?\.?\d*)/)[1]):C}for(var F in E){if(F==="opacity"){v(C,E[F])}else{var D=(F==="float"||F==="cssFloat")?(typeof G.styleFloat==="undefined"?"cssFloat":"styleFloat"):F;G[D]=E[F]}}return C}var A=document.createElement("div"),z=typeof A.style.opacity==="string",u=typeof A.style.filter==="string",t=document.defaultView,y=t&&typeof t.getComputedStyle!=="undefined",w=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,v=function(B){return B};if(z){v=function(B,C){B.style.opacity=C;return B}}else{if(u){v=function(B,C){var D=B.style;if(B.currentStyle&&!B.currentStyle.hasLayout){D.zoom=1}if(w.test(D.filter)){C=C>=0.9999?"":("alpha(opacity="+(C*100)+")");D.filter=D.filter.replace(w,C)}else{D.filter+=" alpha(opacity="+(C*100)+")"}return B}}}b.base.setStyle=x})();function s(t){return typeof t==="string"?document.getElementById(t):t}function e(u){var t=[],v=u.length;while(v--){t[v]=u[v]}return t}function d(u,t){var v=document.createElement(u);for(var w in t){if(w==="class"){w="className"}else{if(w==="for"){w="htmlFor"}}v[w]=t[w]}return v}function m(t,u){if((" "+t.className+" ").indexOf(" "+u+" ")===-1){t.className+=(t.className?" ":"")+u}}function l(u,v,t){if(typeof v==="string"){v=d(v,t)}if(u.parentNode){u.parentNode.replaceChild(v,u)}v.appendChild(u);return v}function h(u){var t=0,v=0;do{t+=u.offsetTop||0;v+=u.offsetLeft||0;u=u.offsetParent}while(u);return({left:v,top:t})}function r(){return false}(function(){var t=document.documentElement.style;var u="userSelect" in t?"userSelect":"MozUserSelect" in t?"MozUserSelect":"WebkitUserSelect" in t?"WebkitUserSelect":"KhtmlUserSelect" in t?"KhtmlUserSelect":"";function v(w){if(typeof w.onselectstart!=="undefined"){w.onselectstart=r}if(u){w.style[u]="none"}else{if(typeof w.unselectable=="string"){w.unselectable="on"}}return w}b.base.makeElementUnselectable=v})();(function(){function t(w,A){var y=document.getElementsByTagName("head")[0],x=document.createElement("script"),z=true;x.type="text/javascript";x.setAttribute("runat","server");x.onload=x.onreadystatechange=function(B){if(z){if(typeof this.readyState=="string"&&this.readyState!=="loaded"&&this.readyState!=="complete"){return}z=false;A(B||window.event);x=x.onload=x.onreadystatechange=null}};x.src=w;y.appendChild(x)}function v(w,x){u.load(w);x()}b.base.getScript=t;var u=this.Jaxer;if(u&&u.load){b.base.getScript=v}})();b.base.getById=s;b.base.toArray=e;b.base.makeElement=d;b.base.addClass=m;b.base.wrapElement=l;b.base.getElementOffset=h})(this);(function(){var b=this.Canvas||(this.Canvas={});if(b.util){console.warn("Canvas.util is already defined");return}function f(k,h){var g=k.indexOf(h);if(g!==-1){k.splice(g,1)}return k}function e(h,g){return Math.floor(Math.random()*(g-h+1))+h}var c=Math.PI/180;function d(g){return g*c}function a(h,g){return parseFloat(Number(h).toFixed(g))}b.util={removeFromArray:f,degreesToRadians:d,toFixed:a,getRandomInt:e}})();(function(){var a=this.Canvas||(this.Canvas={});var d={cx:"left",x:"left",cy:"top",y:"top",r:"radius","fill-opacity":"opacity","fill-rule":"fillRule","stroke-width":"strokeWidth",transform:"transformMatrix"};function c(l,k){if(!l){return}var n,h,g={};if(l.parentNode&&/^g$/i.test(l.parentNode.nodeName)){g=a.parseAttributes(l.parentNode,k)}var m=k.reduce(function(p,o){n=l.getAttribute(o);h=parseFloat(n);if(n){if((o==="fill"||o==="stroke")&&n==="none"){n=""}if(o==="fill-rule"){n=(n==="evenodd")?"destination-over":n}if(o==="transform"){n=a.parseTransformAttribute(n)}if(o in d){o=d[o]}p[o]=isNaN(h)?n:h}return p},{});m=a.base.object.extend(a.parseStyleAttribute(l),m);return a.base.object.extend(g,m)}a.parseTransformAttribute=(function(){function g(B,C){var D=C[0];B[0]=Math.cos(D);B[1]=Math.sin(D);B[2]=-Math.sin(D);B[3]=Math.cos(D)}function n(D,E){var C=E[0],B=(E.length===2)?E[1]:E[0];D[0]=C;D[3]=B}function y(B,C){B[2]=C[0]}function k(B,C){B[1]=C[0]}function v(B,C){B[4]=C[0];if(C.length===2){B[5]=C[1]}}var p=[1,0,0,1,0,0],h="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)",z="(?:\\s+,?\\s*|,\\s*)",q="(?:(skewX)\\s*\\(\\s*("+h+")\\s*\\))",o="(?:(skewY)\\s*\\(\\s*("+h+")\\s*\\))",x="(?:(rotate)\\s*\\(\\s*("+h+")(?:"+z+"("+h+")"+z+"("+h+"))?\\s*\\))",A="(?:(scale)\\s*\\(\\s*("+h+")(?:"+z+"("+h+"))?\\s*\\))",t="(?:(translate)\\s*\\(\\s*("+h+")(?:"+z+"("+h+"))?\\s*\\))",w="(?:(matrix)\\s*\\(\\s*("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")\\s*\\))",u="(?:"+w+"|"+t+"|"+A+"|"+x+"|"+q+"|"+o+")",r="(?:"+u+"(?:"+z+u+")*)",l="^\\s*(?:"+r+"?)\\s*$",s=new RegExp(l),m=new RegExp(u);return function(C){var B=p.clone();if(!C||(C&&!s.test(C))){return B}C.replace(m,function(G){var D=new RegExp(u).exec(G).filter(function(H){return(H!==""&&H!=null)}),E=D[1],F=D.slice(2).map(parseFloat);switch(E){case"translate":v(B,F);break;case"rotate":g(B,F);break;case"scale":n(B,F);break;case"skewX":y(B,F);break;case"skewY":k(B,F);break;case"matrix":B=F;break}});return B}})();function b(h){if(!h){return null}h=h.trim().split(/\s+/);var g=h.reduce(function(k,l){l=l.split(",");k.push({x:parseFloat(l[0]),y:parseFloat(l[1])});return k},[]);if(g.length%2!==0){}return g}function f(h){var g={},k=h.getAttribute("style");if(k){if(typeof k=="string"){k=k.split(";");k.pop();g=k.reduce(function(n,q){var m=q.split(":"),o=m[0].trim(),p=m[1].trim();n[o]=p;return n},{})}else{for(var l in k){if(typeof k[l]!=="undefined"){g[l]=k[l]}}}}return g}function e(h,g){var k=h.map(function(m){var l=a[m.tagName.capitalize()];if(l&&l.fromElement){try{return l.fromElement(m,g)}catch(n){console.log(n.message||n)}}});k=k.filter(function(l){return l!=null});return k}a.parseSVGDocument=(function(){var g=/^(path|circle|polygon|polyline|ellipse|rect|line)$/;var k="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)";var l=new RegExp("^\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*$");function h(m,n){while(m&&(m=m.parentNode)){if(m.nodeName===n){return true}}return false}return function(u,w){if(!u){return}var t=a.base.toArray(u.getElementsByTagName("*"));var m=t.filter(function(y){return g.test(y.tagName)&&!h(y,"pattern")});if(!m||(m&&!m.length)){return}var n=u.getAttribute("viewBox"),r=u.getAttribute("width"),p=u.getAttribute("height"),o=null,v=null,s,q;if(n&&(n=n.match(l))){s=parseInt(n[1],10);q=parseInt(n[2],10);o=parseInt(n[3],10);v=parseInt(n[4],10)}o=r?parseFloat(r):o;v=p?parseFloat(p):v;var x={width:o,height:v};var m=a.parseElements(m,Object.clone(x));if(!m||(m&&!m.length)){return}if(w){w(m,x)}}})();a.base.object.extend(a,{parseAttributes:c,parseElements:e,parseStyleAttribute:f,parsePointsAttribute:b})})();(function(){var a=this.Canvas||(this.Canvas={});if(a.Point){console.warn("Canvas.Point is already defined");return}function b(c,d){if(arguments.length>0){this.init(c,d)}}b.prototype={constructor:b,init:function(c,d){this.x=c;this.y=d},add:function(c){return new b(this.x+c.x,this.y+c.y)},addEquals:function(c){this.x+=c.x;this.y+=c.y;return this},scalarAdd:function(c){return new b(this.x+c,this.y+c)},scalarAddEquals:function(c){this.x+=c;this.y+=c;return this},subtract:function(c){return new b(this.x-c.x,this.y-c.y)},subtractEquals:function(c){this.x-=c.x;this.y-=c.y;return this},scalarSubtract:function(c){return new b(this.x-c,this.y-c)},scalarSubtractEquals:function(c){this.x-=c;this.y-=c;return this},multiply:function(c){return new b(this.x*c,this.y*c)},multiplyEquals:function(c){this.x*=c;this.y*=c;return this},divide:function(c){return new b(this.x/c,this.y/c)},divideEquals:function(c){this.x/=c;this.y/=c;return this},eq:function(c){return(this.x==c.x&&this.y==c.y)},lt:function(c){return(this.x<c.x&&this.y<c.y)},lte:function(c){return(this.x<=c.x&&this.y<=c.y)},gt:function(c){return(this.x>c.x&&this.y>c.y)},gte:function(c){return(this.x>=c.x&&this.y>=c.y)},lerp:function(d,c){return new b(this.x+(d.x-this.x)*c,this.y+(d.y-this.y)*c)},distanceFrom:function(e){var d=this.x-e.x,c=this.y-e.y;return Math.sqrt(d*d+c*c)},min:function(c){return new b(Math.min(this.x,c.x),Math.min(this.y,c.y))},max:function(c){return new b(Math.max(this.x,c.x),Math.max(this.y,c.y))},toString:function(){return this.x+","+this.y},setXY:function(c,d){this.x=c;this.y=d},setFromPoint:function(c){this.x=c.x;this.y=c.y},swap:function(d){var c=this.x,e=this.y;this.x=d.x;this.y=d.y;d.x=c;d.y=e}};a.Point=b})();(function(){var b=this;var a=b.Canvas||(b.Canvas={});if(a.Intersection){console.warn("Canvas.Intersection is already defined");return}function c(d){if(arguments.length>0){this.init(d)}}c.prototype.init=function(d){this.status=d;this.points=[]};c.prototype.appendPoint=function(d){this.points.push(d)};c.prototype.appendPoints=function(d){this.points=this.points.concat(d)};c.intersectLineLine=function(h,f,n,m){var o,k=(m.x-n.x)*(h.y-n.y)-(m.y-n.y)*(h.x-n.x),l=(f.x-h.x)*(h.y-n.y)-(f.y-h.y)*(h.x-n.x),g=(m.y-n.y)*(f.x-h.x)-(m.x-n.x)*(f.y-h.y);if(g!=0){var e=k/g,d=l/g;if(0<=e&&e<=1&&0<=d&&d<=1){o=new c("Intersection");o.points.push(new a.Point(h.x+e*(f.x-h.x),h.y+e*(f.y-h.y)))}else{o=new c("No Intersection")}}else{if(k==0||l==0){o=new c("Coincident")}else{o=new c("Parallel")}}return o};c.intersectLinePolygon=function(e,d,m){var n=new c("No Intersection"),f=m.length;for(var h=0;h<f;h++){var l=m[h],k=m[(h+1)%f],g=c.intersectLineLine(e,d,l,k);n.appendPoints(g.points)}if(n.points.length>0){n.status="Intersection"}return n};c.intersectPolygonPolygon=function(k,h){var f=new c("No Intersection"),m=k.length;for(var l=0;l<m;l++){var g=k[l],e=k[(l+1)%m],d=c.intersectLinePolygon(g,e,h);f.appendPoints(d.points)}if(f.points.length>0){f.status="Intersection"}return f};c.intersectPolygonRectangle=function(p,e,d){var g=e.min(d),o=e.max(d),f=new a.Point(o.x,g.y),n=new a.Point(g.x,o.y),m=c.intersectLinePolygon(g,f,p),l=c.intersectLinePolygon(f,o,p),k=c.intersectLinePolygon(o,n,p),h=c.intersectLinePolygon(n,g,p),q=new c("No Intersection");q.appendPoints(m.points);q.appendPoints(l.points);q.appendPoints(k.points);q.appendPoints(h.points);if(q.points.length>0){q.status="Intersection"}return q};a.Intersection=c})();(function(){var a=this.Canvas||(this.Canvas={});if(a.Color){console.warn("Canvas.Color is already defined.");return}a.Color=b;function b(c){if(!c){this.setSource([0,0,0,1])}else{this._tryParsingColor(c)}}b.prototype._tryParsingColor=function(c){var d=b.sourceFromHex(c);if(!d){d=b.sourceFromRgb(c)}if(d){this.setSource(d)}};b.prototype.getSource=function(){return this._source};b.prototype.setSource=function(c){this._source=c};b.prototype.toRgb=function(){var c=this.getSource();return"rgb("+c[0]+","+c[1]+","+c[2]+")"};b.prototype.toRgba=function(){var c=this.getSource();return"rgba("+c[0]+","+c[1]+","+c[2]+","+c[3]+")"};b.prototype.toHex=function(){var f=this.getSource();var e=f[0].toString(16);e=(e.length==1)?("0"+e):e;var d=f[1].toString(16);d=(d.length==1)?("0"+d):d;var c=f[2].toString(16);c=(c.length==1)?("0"+c):c;return e.toUpperCase()+d.toUpperCase()+c.toUpperCase()};b.prototype.getAlpha=function(){return this.getSource()[3]};b.prototype.setAlpha=function(d){var c=this.getSource();c[3]=d;this.setSource(c);return this};b.prototype.toGrayscale=function(){var e=this.getSource(),d=parseInt((e[0]*0.3+e[1]*0.59+e[2]*0.11).toFixed(0),10),c=e[3];this.setSource([d,d,d,c]);return this};b.prototype.toBlackWhite=function(c){var f=this.getSource(),e=(f[0]*0.3+f[1]*0.59+f[2]*0.11).toFixed(0),d=f[3],c=c||127;e=(Number(e)<Number(c))?0:255;this.setSource([e,e,e,d]);return this};b.prototype.overlayWith=function(k){k=new b(k);var c=[],h=this.getAlpha(),f=0.5,g=this.getSource(),d=k.getSource();for(var e=0;e<3;e++){c.push(Math.round((g[e]*(1-f))+(d[e]*f)))}c[4]=h;this.setSource(c);return this};b.reRGBa=/^rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(\d+(?:\.\d+)?))?\)$/;b.reHex=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i;b.fromRgb=function(c){return b.fromSource(b.sourceFromRgb(c))};b.sourceFromRgb=function(c){var d=c.match(b.reRGBa);if(d){return[parseInt(d[1],10),parseInt(d[2],10),parseInt(d[3],10),d[4]?parseFloat(d[4]):1]}};b.fromRgba=b.fromRgb;b.fromHex=function(c){return b.fromSource(b.sourceFromHex(c))};b.sourceFromHex=function(e){if(e.match(b.reHex)){var k=e.slice(e.indexOf("#")+1),d=(k.length===3),h=d?(k.charAt(0)+k.charAt(0)):k.substring(0,2),f=d?(k.charAt(1)+k.charAt(1)):k.substring(2,4),c=d?(k.charAt(2)+k.charAt(2)):k.substring(4,6);return[parseInt(h,16),parseInt(f,16),parseInt(c,16),1]}};b.fromSource=function(c){var d=new b();d.setSource(c);return d}})();(function(){var c=this,h=c.window,k=h.document,d=c.Canvas||(c.Canvas={});if(d.Element){console.warn("Canvas.Element is already defined.");return}var g=new Error("Could not initialize `canvas` element"),f=500,a=0.5,m="decel",o=d.base.getPointer,l={tr:"ne-resize",br:"se-resize",bl:"sw-resize",tl:"nw-resize",ml:"w-resize",mt:"n-resize",mr:"e-resize",mb:"s-resize"};var e=(function(){var v=k.createElement("canvas"),s,w,u,r,q=200,x=300;v.width=v.height=x;if(!v.getContext){return}var p=v.getContext("2d");if(!p){return}s=new Date();for(r=q;r--;){p.clearRect(0,0,x,x)}w=new Date()-s;s=new Date();for(r=q;r--;){v.width=v.height}u=new Date()-s;if(u<w){return"width"}})();function b(p){p.clearRect(0,0,this._oConfig.width,this._oConfig.height);return this}var n=(function(){var q=k.createElement("canvas");if(!q||!q.getContext){return}var p=q.getContext("2d");if(!p){return}try{p.fillStyle="transparent";return true}catch(r){}return false})();d.Element=function(p,q){this._groupSelector=null;this._aObjects=[];this._oContext=null;this._oElement=null;this._currentTransform=null;this._activeGroup=null;this._oConfig={width:300,height:150};q=q||{};this._initElement(p);this._initConfig(q);if(q.overlayImage){this.setOverlayImage(q.overlayImage)}if(q.afterRender){this.afterRender=q.afterRender}this._createCanvasBackground();this._createCanvasContainer();this._initEvents();this.calcOffset()};d.base.object.extend(d.Element.prototype,{selectionColor:"rgba(100,100,255,0.3)",selectionBorderColor:"rgba(255,255,255,0.3)",selectionLineWidth:1,backgroundColor:"rgba(255,255,255,1)",includeDefaultValues:true,shouldCacheImages:false,CANVAS_WIDTH:600,CANVAS_HEIGHT:600,CANVAS_PRINT_WIDTH:3000,CANVAS_PRINT_HEIGHT:3000,onBeforeScaleRotate:function(){},calcOffset:function(){this._offset=d.base.getElementOffset(this.getElement());return this},setOverlayImage:function(q,s){if(q){var r=this,p=new Image();p.onload=function(){r.overlayImage=p;if(s){s()}p=p.onload=null};p.src=q}return this},_initElement:function(q){var s=d.base.getById(q);this._oElement=s||k.createElement("canvas");if(typeof this._oElement.getContext==="undefined"){G_vmlCanvasManager.initElement(this._oElement)}if(typeof this._oElement.getContext==="undefined"){throw g}if(!(this._oContextTop=this._oElement.getContext("2d"))){throw g}var r=this._oElement.width||0,p=this._oElement.height||0;this._initWrapperElement(r,p);this._setElementStyle(r,p)},_initWrapperElement:function(q,p){var r=d.base.wrapElement(this.getElement(),"div",{className:"canvas_container"});d.base.setStyle(r,{width:q+"px",height:p+"px"});d.base.makeElementUnselectable(r);this.wrapper=r},_setElementStyle:function(q,p){d.base.setStyle(this.getElement(),{position:"absolute",width:q+"px",height:p+"px",left:0,top:0})},_initConfig:function(p){d.base.object.extend(this._oConfig,p||{});this._oConfig.width=parseInt(this._oElement.width,10)||0;this._oConfig.height=parseInt(this._oElement.height,10)||0;this._oElement.style.width=this._oConfig.width+"px";this._oElement.style.height=this._oConfig.height+"px"},_initEvents:function(){var p=this;this._onMouseDown=function(q){p.__onMouseDown(q)};this._onMouseUp=function(q){p.__onMouseUp(q)};this._onMouseMove=function(q){p.__onMouseMove(q)};this._onResize=function(q){p.calcOffset()};d.base.addListener(this._oElement,"mousedown",this._onMouseDown);d.base.addListener(k,"mousemove",this._onMouseMove);d.base.addListener(k,"mouseup",this._onMouseUp);d.base.addListener(h,"resize",this._onResize)},_createCanvasElement:function(r){var q=k.createElement("canvas");if(!q){return}q.className=r;var p=this._oElement.parentNode.insertBefore(q,this._oElement);p.width=this.getWidth();p.height=this.getHeight();p.style.width=this.getWidth()+"px";p.style.height=this.getHeight()+"px";p.style.position="absolute";p.style.left=0;p.style.top=0;if(typeof q.getContext==="undefined"){G_vmlCanvasManager.initElement(q)}if(typeof q.getContext==="undefined"){throw g}d.base.makeElementUnselectable(p);return p},_createCanvasContainer:function(){var p=this._createCanvasElement("canvas-container");this._oContextContainerEl=p;this._oContextContainer=p.getContext("2d")},_createCanvasBackground:function(){var p=this._createCanvasElement("canvas-container");this._oContextBackgroundEl=p;this._oContextBackground=p.getContext("2d")},getWidth:function(){return this._oConfig.width},getHeight:function(){return this._oConfig.height},setWidth:function(p){return this._setDimension("width",p)},setHeight:function(p){return this._setDimension("height",p)},_setDimension:function(q,p){this._oContextContainerEl[q]=p;this._oContextContainerEl.style[q]=p+"px";this._oContextBackgroundEl[q]=p;this._oContextBackgroundEl.style[q]=p+"px";this._oElement[q]=p;this._oElement.style[q]=p+"px";this._oElement.parentNode.style[q]=p+"px";this._oConfig[q]=p;this.calcOffset();this.renderAll();return this},__onMouseUp:function(u){if(this._currentTransform){var q=this._currentTransform,t=q.target;if(t.__scaling){d.base.fireEvent("object:scaled",{target:t});t.__scaling=false}for(var r=0,p=this._aObjects.length;r<p;++r){this._aObjects[r].setCoords()}if(t.hasStateChanged()){t.isMoving=false;d.base.fireEvent("object:modified",{target:t})}}this._currentTransform=null;if(this._groupSelector){this._findSelectedObjects(u)}var s=this.getActiveGroup();if(s){if(s.hasStateChanged()&&s.containsPoint(this.getPointer(u))){d.base.fireEvent("group:modified",{target:s})}s.setObjectsCoords();s.set("isMoving",false);this._setCursor("default")}this._groupSelector=null;this.renderAll();this._setCursorFromEvent(u,t);this._setCursor("");var v=this;setTimeout(function(){v._setCursorFromEvent(u,t)},50)},shouldClearSelection:function(r){var q=this.findTarget(r),p=this.getActiveGroup();return(!q||(q&&p&&!p.contains(q)&&p!==q&&!r.shiftKey))},__onMouseDown:function(t){if(this._currentTransform){return}var s=this.findTarget(t),u=this.getPointer(t),q=this.getActiveGroup(),r;if(this.shouldClearSelection(t)){this._groupSelector={ex:u.x,ey:u.y,top:0,left:0};this.deactivateAllWithDispatch()}else{s.saveState();if(r=s._findTargetCorner(t,this._offset)){this.onBeforeScaleRotate(s)}this._setupCurrentTransform(t,s);var p=t.shiftKey&&(q||this.getActiveObject());if(p){this._handleGroupLogic(t,s)}else{if(s!==this.getActiveGroup()){this.deactivateAll()}this.setActiveObject(s)}}this.renderAll()},getElement:function(){return this._oElement},deactivateAllWithDispatch:function(){var p=this.getActiveGroup();if(p){d.base.fireEvent("before:group:destroyed",{target:p})}this.deactivateAll();if(p){d.base.fireEvent("after:group:destroyed")}d.base.fireEvent("selection:cleared");return this},_setupCurrentTransform:function(s,r){var q="drag",p,t=o(s);if(p=r._findTargetCorner(s,this._offset)){q=/ml|mr/.test(p)?"scaleX":/mt|mb/.test(p)?"scaleY":"rotate"}this._currentTransform={target:r,action:q,scaleX:r.scaleX,scaleY:r.scaleY,offsetX:t.x-r.left,offsetY:t.y-r.top,ex:t.x,ey:t.y,left:r.left,top:r.top,theta:r.theta,width:r.width*r.scaleX};this._currentTransform.original={left:r.left,top:r.top}},_handleGroupLogic:function(s,r){if(r.isType("group")){r=this.findTarget(s,true);if(!r||r.isType("group")){return}}var p=this.getActiveGroup();if(p){if(p.contains(r)){p.remove(r);r.setActive(false);if(p.size()===1){this.removeActiveGroup()}}else{p.add(r)}d.base.fireEvent("group:selected",{target:p});p.setActive(true)}else{if(this._activeObject){if(r!==this._activeObject){var q=new d.Group([this._activeObject,r]);this.setActiveGroup(q);p=this.getActiveGroup()}}r.setActive(true)}if(p){p.saveCoords()}},__onMouseMove:function(t){if(this._groupSelector!==null){var u=o(t);this._groupSelector.left=u.x-this._offset.left-this._groupSelector.ex;this._groupSelector.top=u.y-this._offset.top-this._groupSelector.ey;this.renderTop()}else{if(!this._currentTransform){var r=this._oElement.style;var s=this.findTarget(t);if(!s){for(var q=this._aObjects.length;q--;){if(!this._aObjects[q].active){this._aObjects[q].setActive(false)}}r.cursor="default"}else{this._setCursorFromEvent(t,s);if(s.isActive()){s.setCornersVisibility&&s.setCornersVisibility(true)}}}else{var u=o(t),p=u.x,v=u.y;this._currentTransform.target.isMoving=true;if(this._currentTransform.action==="rotate"){if(!t.shiftKey){this._rotateObject(p,v)}this._scaleObject(p,v)}else{if(this._currentTransform.action==="scaleX"){this._scaleObject(p,v,"x")}else{if(this._currentTransform.action==="scaleY"){this._scaleObject(p,v,"y")}else{this._translateObject(p,v)}}}this.renderAll()}}},_translateObject:function(p,r){var q=this._currentTransform.target;q.set("left",p-this._currentTransform.offsetX);q.set("top",r-this._currentTransform.offsetY)},_scaleObject:function(p,u,t){var s=Math.sqrt(Math.pow(this._currentTransform.ey-this._currentTransform.top-this._offset.top,2)+Math.pow(this._currentTransform.ex-this._currentTransform.left-this._offset.left,2));var q=Math.sqrt(Math.pow(u-this._currentTransform.top-this._offset.top,2)+Math.pow(p-this._currentTransform.left-this._offset.left,2));var r=this._currentTransform.target;r.__scaling=true;if(!t){r.set("scaleX",this._currentTransform.scaleX*q/s);r.set("scaleY",this._currentTransform.scaleY*q/s)}else{if(t==="x"){r.set("scaleX",this._currentTransform.scaleX*q/s)}else{if(t==="y"){r.set("scaleY",this._currentTransform.scaleY*q/s)}}}},_rotateObject:function(p,s){var q=Math.atan2(this._currentTransform.ey-this._currentTransform.top-this._offset.top,this._currentTransform.ex-this._currentTransform.left-this._offset.left);var r=Math.atan2(s-this._currentTransform.top-this._offset.top,p-this._currentTransform.left-this._offset.left);this._currentTransform.target.set("theta",(r-q)+this._currentTransform.theta)},_setCursor:function(p){this._oElement.style.cursor=p},_setCursorFromEvent:function(u,t){var q=this._oElement.style;if(!t){q.cursor="default";return false}else{var p=this.getActiveGroup();var r=!!t._findTargetCorner&&(!p||!p.contains(t))&&t._findTargetCorner(u,this._offset);if(!r){q.cursor="move"}else{if(r in l){q.cursor=l[r]}else{q.cursor="default";return false}}}return true},_draw:function(p,q){q&&q.render(p)},_drawSelection:function(){var s=this._groupSelector.left,r=this._groupSelector.top,q=Math.abs(s),p=Math.abs(r);this._oContextTop.fillStyle=this.selectionColor;this._oContextTop.fillRect(this._groupSelector.ex-((s>0)?0:-s),this._groupSelector.ey-((r>0)?0:-r),q,p);this._oContextTop.lineWidth=this.selectionLineWidth;this._oContextTop.strokeStyle=this.selectionBorderColor;this._oContextTop.strokeRect(this._groupSelector.ex+a-((s>0)?0:q),this._groupSelector.ey+a-((r>0)?0:p),q,p)},_findSelectedObjects:function(v){var w,r,B=[],q=this._groupSelector.ex,A=this._groupSelector.ey,p=q+this._groupSelector.left,y=A+this._groupSelector.top,x,u=new d.Point(Math.min(q,p),Math.min(A,y)),z=new d.Point(Math.max(q,p),Math.max(A,y));for(var s=0,t=this._aObjects.length;s<t;++s){x=this._aObjects[s];if(x.intersectsWithRect(u,z)||x.isContainedWithinRect(u,z)){x.setActive(true);B.push(x)}}if(B.length===1){this.setActiveObject(B[0]);d.base.fireEvent("object:selected",{target:B[0]})}else{if(B.length>1){var B=new d.Group(B);this.setActiveGroup(B);B.saveCoords();d.base.fireEvent("group:selected",{target:B})}}this.renderAll()},add:function(){this._aObjects.push.apply(this._aObjects,arguments);this.renderAll();return this},insertAt:function(q,p){this._aObjects.splice(p,0,q);this.renderAll();return this},getObjects:function(){return this._aObjects},getContext:function(){return this._oContextTop},clearContext:b,clear:function(){this._aObjects.length=0;this.clearContext(this._oContextTop);this.clearContext(this._oContextContainer);this.renderAll();return this},renderAll:function(q){var p=this._oConfig.width,t=this._oConfig.height;var x=q?this._oContextTop:this._oContextContainer;this.clearContext(this._oContextTop);if(x!==this._oContextTop){this.clearContext(x)}if(q){if(!n&&this.backgroundColor==="transparent"){var v=true}if(!v){x.fillStyle=this.backgroundColor}x.fillRect(0,0,p,t)}var u=this._aObjects.length,s=this.getActiveGroup();if(u){for(var r=0;r<u;++r){if(!s||(s&&!s.contains(this._aObjects[r]))){this._draw(x,this._aObjects[r])}}}if(s){this._draw(this._oContextTop,s)}if(this.overlayImage){this._oContextTop.drawImage(this.overlayImage,0,0)}if(this.afterRender){this.afterRender()}return this},renderTop:function(){this.clearContext(this._oContextTop);if(this.overlayImage){this._oContextTop.drawImage(this.overlayImage,0,0)}if(this._groupSelector){this._drawSelection()}var p=this.getActiveGroup();if(p){p.render(this._oContextTop)}if(this.afterRender){this.afterRender()}return this},containsPoint:function(u,t){var v=this.getPointer(u),s=this._normalizePointer(t,v),p=s.x,w=s.y;var q=t._getImageLines(t.oCoords),r=t._findCrossPoints(p,w,q);if((r&&r%2===1)||t._findTargetCorner(u,this._offset)){return true}return false},_normalizePointer:function(q,t){var s=this.getActiveGroup(),p=t.x,u=t.y;var r=(s&&q.type!=="group"&&s.contains(q));if(r){p-=s.left;u-=s.top}return{x:p,y:u}},findTarget:function(t,q){var s,u=this.getPointer(t);var r=this.getActiveGroup();if(r&&!q&&this.containsPoint(t,r)){s=r;return s}for(var p=this._aObjects.length;p--;){if(this.containsPoint(t,this._aObjects[p])){s=this._aObjects[p];this.relatedTarget=s;break}}return s},toDataURL:function(q){var p;if(!q){q="png"}if(q==="jpeg"||q==="png"){this.renderAll(true);p=this.getElement().toDataURL("image/"+q)}return p},toDataURLWithMultiplier:function(s,w){var v=this.getWidth(),u=this.getHeight(),q=v*w,r=u*w,p=this.getActiveObject();this.setWidth(q).setHeight(r);this._oContextTop.scale(w,w);if(p){this.deactivateAll().renderAll()}var t=this.toDataURL(s);this._oContextTop.scale(1/w,1/w);this.setWidth(v).setHeight(u);if(p){this.setActiveObject(p)}this.renderAll();return t},getPointer:function(p){var q=o(p);return{x:q.x-this._offset.left,y:q.y-this._offset.top}},getCenter:function(){return{top:this.getHeight()/2,left:this.getWidth()/2}},centerObjectH:function(p){p.set("left",this.getCenter().left);this.renderAll();return this},fxCenterObjectH:function(r){var u=this,t=new APE.anim.Animation(),q=r.get("left"),p=u.getCenter().left,s=p-q;t.run=function(v){r.set("left",q+s*v);u.renderAll()};t.onend=function(){r.setCoords()};t.duration=f;t.transition=APE.anim.Transitions[m];t.start();return this},centerObjectV:function(p){p.set("top",this.getCenter().top);this.renderAll();return this},fxCenterObjectV:function(r){var u=this,t=new APE.anim.Animation(),q=r.get("top"),p=u.getCenter().top,s=p-q;t.run=function(v){r.set("top",q+s*v).setCoords();u.renderAll()};t.onend=function(){r.setCoords()};t.duration=f;t.transition=APE.anim.Transitions[m];t.start()},straightenObject:function(p){p.straighten();this.renderAll();return this},fxStraightenObject:function(p){p.fxStraighten({onChange:this.renderAll.bind(this)});return this},toJSON:function(){return JSON.stringify(this.toObject())},toDatalessJSON:function(){return JSON.stringify(this.toDatalessObject())},toObject:function(){return this._toObjectMethod("toObject")},toDatalessObject:function(){return this._toObjectMethod("toDatalessObject")},_toObjectMethod:function(p){return{objects:this._aObjects.map(function(q){if(!this.includeDefaultValues){var r=q.includeDefaultValues;q.includeDefaultValues=false}var s=q[p]();if(!this.includeDefaultValues){q.includeDefaultValues=r}return s},this),background:this.backgroundColor}},isEmpty:function(){return this._aObjects.length===0},loadFromJSON:function(p,r){if(!p){return}var q=p.evalJSON();if(!q||(q&&!q.objects)){return}this.clear();this._enlivenObjects(q.objects,function(){this.backgroundColor=q.background;if(r){r()}}.bind(this));return this},_enlivenObjects:function(q,t){var r=0,p=q.filter(function(u){return u.type==="image"}).length;var s=this;q.forEach(function(v){if(!v.type){return}switch(v.type){case"image":case"font":d[v.type.capitalize()].fromObject(v,function(w){s.add(w);if(++r===p){if(t){t()}}});break;default:var u=d[v.type.capitalize().camelize()];if(u&&u.fromObject){s.add(u.fromObject(v))}break}});if(p===0&&t){t()}},loadFromDatalessJSON:function(p,r){if(!p){return}var q=(typeof p==="string")?p.evalJSON():p;if(!q||(q&&!q.objects)){return}this.clear();this._enlivenDatalessObjects(q.objects,r)},_enlivenDatalessObjects:function(q,v){function u(x,w){t.insertAt(x,w);x.setCoords();if(++s===p){v&&v()}}var t=this,s=0,p=q.length;try{q.forEach(function(C,A){var x=C.paths?"paths":"path";var B=C[x];delete C[x];if(typeof B!=="string"){switch(C.type){case"image":case"text":d[C.type.capitalize()].fromObject(C,function(D){u(D)});break;default:var w=d[C.type.capitalize().camelize()];if(w&&w.fromObject){u(w.fromObject(C))}break}}else{if(C.type==="image"){t.loadImageFromURL(B,function(D){D.setSourcePath(B);d.base.object.extend(D,C);D.setAngle(C.angle);u(D,A)})}else{if(C.type==="text"){C.path=B;var z=d.Text.fromObject(C);h.__context=t;var y=function(){if(Prototype.Browser.Opera){setTimeout(function(){u(z,A)},500)}else{u(z,A)}};d.base.getScript(B,y)}else{t.loadSVGFromURL(B,function(F,E){if(F.length>1){var D=new d.PathGroup(F,C)}else{var D=F[0]}D.setSourcePath(B);if(!(D instanceof d.PathGroup)){d.base.object.extend(D,C);if(typeof C.angle!=="undefined"){D.setAngle(C.angle)}}u(D,A)})}}}},this)}catch(r){console.log(r.message)}},loadImageFromURL:(function(){var p={};return function(q,u){var t=this;function r(){var v=k.getElementById(p[q]);if(v.width&&v.height){u(new d.Image(v))}else{setTimeout(r,50)}}if(p[q]){r()}else{var s=new Image();s.onload=function(){s.onload=null;t._resizeImageToFit(s);var v=new d.Image(s);u(v)};s.className="canvas-img-clone";s.src=q;if(this.shouldCacheImages){p[q]=Element.identify(s)}k.body.appendChild(s)}}})(),loadSVGFromURL:function(p,t){var s=this;p=p.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(p,function(u){if(u){s.cache.get(p,function(w){var v=s._enlivenCachedObject(w);t(v.objects,v.options)})}else{new Ajax.Request(p,{method:"get",onComplete:r,onFailure:q})}});function r(v){var u=v.responseXML;if(!u){return}var w=u.documentElement;if(!w){return}d.parseSVGDocument(w,function(y,x){s.cache.set(p,{objects:y.invoke("toObject"),options:x});t(y,x)})}function q(){console.log("ERROR!")}},_enlivenCachedObject:function(r){var q=r.objects;var p=r.options;q=q.map(function(s){return d[s.type.capitalize()].fromObject(s)});return({objects:q,options:p})},remove:function(p){d.util.removeFromArray(this._aObjects,p);this.renderAll();return p},fxRemove:function(p,r){var q=this;p.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){q.remove(p);if(typeof r==="function"){r()}}});return this},sendToBack:function(p){d.util.removeFromArray(this._aObjects,p);this._aObjects.unshift(p);return this.renderAll()},bringToFront:function(p){d.util.removeFromArray(this._aObjects,p);this._aObjects.push(p);return this.renderAll()},sendBackwards:function(r){var q=this._aObjects.indexOf(r),p=q;if(q!==0){for(var s=q-1;s>=0;--s){if(r.intersectsWithObject(this._aObjects[s])){p=s;break}}d.util.removeFromArray(this._aObjects,r);this._aObjects.splice(p,0,r)}return this.renderAll()},bringForward:function(s){var u=this.getObjects(),q=u.indexOf(s),p=q;if(q!==u.length-1){for(var t=q+1,r=this._aObjects.length;t<r;++t){if(s.intersectsWithObject(u[t])){p=t;break}}d.util.removeFromArray(u,s);u.splice(p,0,s)}this.renderAll()},setActiveObject:function(p){if(this._activeObject){this._activeObject.setActive(false)}this._activeObject=p;p.setActive(true);this.renderAll();d.base.fireEvent("object:selected",{target:p});return this},getActiveObject:function(){return this._activeObject},removeActiveObject:function(){if(this._activeObject){this._activeObject.setActive(false)}this._activeObject=null;return this},setActiveGroup:function(p){this._activeGroup=p;return this},getActiveGroup:function(){return this._activeGroup},removeActiveGroup:function(){var p=this.getActiveGroup();if(p){p.destroy()}return this.setActiveGroup(null)},item:function(p){return this.getObjects()[p]},deactivateAll:function(){var q=this.getObjects(),r=0,p=q.length;for(;r<p;r++){q[r].setActive(false)}this.removeActiveGroup();this.removeActiveObject();return this},complexity:function(){return this.getObjects().reduce(function(p,q){p+=q.complexity?q.complexity():0;return p},0)},dispose:function(){this.clear();Event.stopObserving(this.getElement(),"mousedown",this._onMouseDown);Event.stopObserving(k,"mouseup",this._onMouseUp);Event.stopObserving(k,"mousemove",this._onMouseMove);Event.stopObserving(h,"resize",this._onResize);return this},clone:function(r){var p=k.createElement("canvas");p.width=this.getWidth();p.height=this.getHeight();var q=this.__clone||(this.__clone=new d.Element(p));return q.loadFromJSON(this.toJSON(),function(){if(r){r(q)}})},_toDataURL:function(p,q){this.clone(function(r){q(r.toDataURL(p))})},_toDataURLWithMultiplier:function(p,r,q){this.clone(function(s){q(s.toDataURLWithMultiplier(p,r))})},_resizeImageToFit:function(t){var s=1,q=1,r=t.width||t.offsetWidth,p=t.height||t.offsetHeight;if(r&&p){t.width=r*s;t.height=p*q}},cache:{has:function(p,q){q(false)},get:function(){},set:function(){}}});d.Element.prototype.toString=function(){return"#<Canvas.Element ("+this.complexity()+"): { objects: "+this.getObjects().length+" }>"};d.base.object.extend(d.Element,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(s){var r=s.getContext("2d"),w=r.getImageData(0,0,s.width,s.height),u=w.data,p=w.width,v=w.height,q,t;for(i=0;i<p;i++){for(j=0;j<v;j++){q=(i*4)*v+(j*4);t=(u[q]+u[q+1]+u[q+2])/3;u[q]=t;u[q+1]=t;u[q+2]=t}}r.putImageData(w,0,0)},supports:function(q){var r=k.createElement("canvas");if(!r||!r.getContext){return null}var p=r.getContext("2d");if(!p){return null}switch(q){case"getImageData":return typeof p.getImageData!=="undefined";case"toDataURL":return typeof r.toDataURL!=="undefined";default:return null}}})})();(function(){var c=this;var a=c.Canvas||(c.Canvas={});if(a.Object){return}var b=Array.prototype.slice;a.Object=a.base.createClass({type:"object",includeDefaultValues:true,NUM_FRACTION_DIGITS:2,FX_DURATION:500,FX_TRANSITION:"decel",MIN_SCALE_LIMIT:0.1,stateProperties:("top left width height scaleX scaleY flipX flipY theta angle opacity cornersize fill overlayFill stroke strokeWidth fillRule borderScaleFactor transformMatrix").split(" "),options:{top:0,left:0,width:100,height:100,scaleX:1,scaleY:1,flipX:false,flipY:false,theta:0,opacity:1,angle:0,cornersize:10,padding:0,borderColor:"rgba(102,153,255,0.75)",cornerColor:"rgba(102,153,255,0.5)",fill:"rgb(0,0,0)",overlayFill:null,stroke:null,strokeWidth:1,fillRule:"source-over",borderOpacityWhenMoving:0.4,borderScaleFactor:1,transformMatrix:null},callSuper:function(d){var e=this.constructor.superclass.prototype[d];return(arguments.length>1)?e.apply(this,b.call(arguments,1)):e.call(this)},initialize:function(d){this.setOptions(d);this._importProperties();this.originalState={};this.setCoords();this.saveState()},setOptions:function(d){this.options=a.base.object.extend(this._getOptions(),d)},_getOptions:function(){return a.base.object.extend(a.base.object.clone(this._getSuperOptions()),this.options)},_getSuperOptions:function(){var f=this.constructor;if(f){var d=f.superclass;if(d){var e=d.prototype;if(e&&typeof e._getOptions=="function"){return e._getOptions()}}}return{}},_importProperties:function(){this.stateProperties.forEach(function(d){(d==="angle")?this.setAngle(this.options[d]):(this[d]=this.options[d])},this)},transform:function(d){d.globalAlpha=this.opacity;d.translate(this.left,this.top);d.rotate(this.theta);d.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toJSON:function(){return JSON.stringify(this.toObject())},toObject:function(){var d=a.util.toFixed;var e={type:this.type,left:d(this.left,this.NUM_FRACTION_DIGITS),top:d(this.top,this.NUM_FRACTION_DIGITS),width:d(this.width,this.NUM_FRACTION_DIGITS),height:d(this.height,this.NUM_FRACTION_DIGITS),fill:this.fill,overlayFill:this.overlayFill,stroke:this.stroke,strokeWidth:this.strokeWidth,scaleX:d(this.scaleX,this.NUM_FRACTION_DIGITS),scaleY:d(this.scaleY,this.NUM_FRACTION_DIGITS),angle:d(this.getAngle(),this.NUM_FRACTION_DIGITS),flipX:this.flipX,flipY:this.flipY,opacity:d(this.opacity,this.NUM_FRACTION_DIGITS)};if(!this.includeDefaultValues){e=this._removeDefaultValues(e)}return e},toDatalessObject:function(){return this.toObject()},_removeDefaultValues:function(e){var d=a.Object.prototype.options;this.stateProperties.forEach(function(f){if(e[f]===d[f]){delete e[f]}});return e},isActive:function(){return !!this.active},setActive:function(d){this.active=!!d;return this},toString:function(){return"#<Canvas."+this.type.capitalize()+">"},set:function(e,d){var f=(e==="scaleX"||e==="scaleY")&&d<this.MIN_SCALE_LIMIT;if(f){d=this.MIN_SCALE_LIMIT}if(e==="angle"){this.setAngle(d)}else{if(e==="fill"&&this.overlayFill){this.overlayFill=d}else{this[e]=d}}return this},toggle:function(e){var d=this.get(e);if(typeof d==="boolean"){this.set(e,!d)}return this},setSourcePath:function(d){this.sourcePath=d;return this},get:function(d){return(d==="angle")?this.getAngle():this[d]},render:function(e,f){if(this.width===0||this.height===0){return}e.save();var d=this.transformMatrix;if(d){e.setTransform(d[0],d[1],d[2],d[3],d[4],d[5])}if(!f){this.transform(e)}if(this.stroke){e.lineWidth=this.strokeWidth;e.strokeStyle=this.stroke}if(this.overlayFill){e.fillStyle=this.overlayFill}else{if(this.fill){e.fillStyle=this.fill}}this._render(e);if(this.active&&!f){this.drawBorders(e);this.drawCorners(e)}e.restore()},getWidth:function(){return this.width*this.scaleX},getHeight:function(){return this.height*this.scaleY},scale:function(d){this.scaleX=d;this.scaleY=d;return this},scaleToWidth:function(d){return this.scale(d/this.width)},scaleToHeight:function(d){return this.scale(d/this.height)},setOpacity:function(d){this.set("opacity",d);return this},getAngle:function(){return this.theta*180/Math.PI},setAngle:function(d){this.theta=d/180*Math.PI;this.angle=d;return this},setCoords:function(){this.currentWidth=this.width*this.scaleX;this.currentHeight=this.height*this.scaleY;this._hypotenuse=Math.sqrt(Math.pow(this.currentWidth/2,2)+Math.pow(this.currentHeight/2,2));this._angle=Math.atan(this.currentHeight/this.currentWidth);var l=Math.cos(this._angle+this.theta)*this._hypotenuse,k=Math.sin(this._angle+this.theta)*this._hypotenuse,f=this.theta,o=Math.sin(f),m=Math.cos(f);var r={x:this.left-l,y:this.top-k};var n={x:r.x+(this.currentWidth*m),y:r.y+(this.currentWidth*o)};var q={x:n.x-(this.currentHeight*o),y:n.y+(this.currentHeight*m)};var g={x:r.x-(this.currentHeight*o),y:r.y+(this.currentHeight*m)};var h={x:r.x-(this.currentHeight/2*o),y:r.y+(this.currentHeight/2*m)};var d={x:r.x+(this.currentWidth/2*m),y:r.y+(this.currentWidth/2*o)};var e={x:n.x-(this.currentHeight/2*o),y:n.y+(this.currentHeight/2*m)};var p={x:g.x+(this.currentWidth/2*m),y:g.y+(this.currentWidth/2*o)};this.oCoords={tl:r,tr:n,br:q,bl:g,ml:h,mt:d,mr:e,mb:p};this._setCornerCoords();return this},drawBorders:function(e){var n=this.options,m=n.padding,g=m*2;e.save();e.globalAlpha=this.isMoving?n.borderOpacityWhenMoving:1;e.strokeStyle=n.borderColor;var k=1/(this.scaleX<this.MIN_SCALE_LIMIT?this.MIN_SCALE_LIMIT:this.scaleX);var f=1/(this.scaleY<this.MIN_SCALE_LIMIT?this.MIN_SCALE_LIMIT:this.scaleY);e.lineWidth=1/this.borderScaleFactor;e.scale(k,f);var d=this.getWidth(),l=this.getHeight();e.strokeRect(Math.floor(-(d/2)-m)+0.5,Math.floor(-(l/2)-m)+0.5,Math.floor(d+g),Math.floor(l+g));e.restore();return this},drawCorners:function(q){var s=this.options.cornersize,o=s/2,n=this.options.padding,f=-(this.width/2),m=-(this.height/2),r,p,e=s/this.scaleX,d=s/this.scaleY,g=(n+o)/this.scaleY,h=(n+o)/this.scaleX,l=(n+o-s)/this.scaleX,k=(n+o-s)/this.scaleY;q.save();q.globalAlpha=this.isMoving?this.options.borderOpacityWhenMoving:1;q.fillStyle=this.options.cornerColor;r=f-h;p=m-g;q.fillRect(r,p,e,d);r=f+this.width-h;p=m-g;q.fillRect(r,p,e,d);r=f-h;p=m+this.height+k;q.fillRect(r,p,e,d);r=f+this.width+l;p=m+this.height+k;q.fillRect(r,p,e,d);r=f+this.width/2-h;p=m-g;q.fillRect(r,p,e,d);r=f+this.width/2-h;p=m+this.height+k;q.fillRect(r,p,e,d);r=f+this.width+l;p=m+this.height/2-g;q.fillRect(r,p,e,d);r=f-h;p=m+this.height/2-g;q.fillRect(r,p,e,d);q.restore();return this},clone:function(d){if(this.constructor.fromObject){return this.constructor.fromObject(this.toObject(),d)}return new a.Object(this.toObject())},cloneAsImage:function(f){if(a.Image){var d=new Image();d.onload=function(){if(f){f(new a.Image(d),e)}d=d.onload=null};var e={angle:this.get("angle"),flipX:this.get("flipX"),flipY:this.get("flipY")};this.set("angle",0).set("flipX",false).set("flipY",false);d.src=this.toDataURL()}return this},toDataURL:function(){var e=document.createElement("canvas");e.width=this.getWidth();e.height=this.getHeight();a.base.wrapElement(e,"div");var d=new a.Element(e);d.backgroundColor="transparent";d.renderAll();var g=this.clone();g.left=e.width/2;g.top=e.height/2;g.setActive(false);d.add(g);var f=d.toDataURL("png");d.dispose();d=g=null;return f},hasStateChanged:function(){return this.stateProperties.some(function(d){return this[d]!==this.originalState[d]},this)},saveState:function(){this.stateProperties.forEach(function(d){this.originalState[d]=this.get(d)},this);return this},intersectsWithRect:function(f,h){var m=this.oCoords,d=new a.Point(m.tl.x,m.tl.y),g=new a.Point(m.tr.x,m.tr.y),l=new a.Point(m.bl.x,m.bl.y),e=new a.Point(m.br.x,m.br.y);var k=a.Intersection.intersectPolygonRectangle([d,g,e,l],f,h);return(k.status==="Intersection")},intersectsWithObject:function(d){function e(k){return{tl:new a.Point(k.tl.x,k.tl.y),tr:new a.Point(k.tr.x,k.tr.y),bl:new a.Point(k.bl.x,k.bl.y),br:new a.Point(k.br.x,k.br.y)}}var f=e(this.oCoords),h=e(d.oCoords);var g=a.Intersection.intersectPolygonPolygon([f.tl,f.tr,f.br,f.bl],[h.tl,h.tr,h.br,h.bl]);return(g.status==="Intersection")},isContainedWithinRect:function(f,h){var l=this.oCoords,d=new a.Point(l.tl.x,l.tl.y),g=new a.Point(l.tr.x,l.tr.y),k=new a.Point(l.bl.x,l.bl.y),e=new a.Point(l.br.x,l.br.y);return d.x>f.x&&g.x<h.x&&d.y>f.y&&k.y<h.y},isType:function(d){return this.type===d},_findTargetCorner:function(l,n){var m=a.base.getPointer(l),k=m.x-n.left,f=m.y-n.top,h,d;for(var g in this.oCoords){d=this._getImageLines(this.oCoords[g].corner,g);h=this._findCrossPoints(k,f,d);if(h%2==1&&h!=0){this.__corner=g;return g}}return false},_findCrossPoints:function(m,l,d){var p,o,f,e,n,k,h=0,g;for(var q in d){g=d[q];if((g.o.y<l)&&(g.d.y<l)){continue}if((g.o.y>=l)&&(g.d.y>=l)){continue}if((g.o.x==g.d.x)&&(g.o.x>=m)){n=g.o.x;k=l}else{p=0;o=(g.d.y-g.o.y)/(g.d.x-g.o.x);f=l-p*m;e=g.o.y-o*g.o.x;n=-(f-e)/(p-o);k=f+p*n}if(n>=m){h+=1}if(h==2){break}}return h},_getImageLines:function(e,d){return{topline:{o:e.tl,d:e.tr},rightline:{o:e.tr,d:e.br},bottomline:{o:e.br,d:e.bl},leftline:{o:e.bl,d:e.tl}}},_setCornerCoords:function(){var m=this.oCoords,h=this.theta,g=this.cornersize*Math.cos(h),f=this.cornersize*Math.sin(h),k=this.cornersize/2,e=k-f,d=k,l;m.tl.x-=e;m.tl.y-=d;m.tl.corner={tl:{x:m.tl.x,y:m.tl.y},tr:{x:m.tl.x+g,y:m.tl.y+f},bl:{x:m.tl.x-f,y:m.tl.y+g}};m.tl.corner.br={x:m.tl.corner.tr.x-f,y:m.tl.corner.tr.y+g};m.tl.x+=e;m.tl.y+=d;m.tr.x+=k;m.tr.y-=k;m.tr.corner={tl:{x:m.tr.x-g,y:m.tr.y-f},tr:{x:m.tr.x,y:m.tr.y},br:{x:m.tr.x-f,y:m.tr.y+g}};m.tr.corner.bl={x:m.tr.corner.tl.x-f,y:m.tr.corner.tl.y+g};m.tr.x-=k;m.tr.y+=k;m.bl.x-=k;m.bl.y+=k;m.bl.corner={tl:{x:m.bl.x+f,y:m.bl.y-g},bl:{x:m.bl.x,y:m.bl.y},br:{x:m.bl.x+g,y:m.bl.y+f}};m.bl.corner.tr={x:m.bl.corner.br.x+f,y:m.bl.corner.br.y-g};m.bl.x+=k;m.bl.y-=k;m.br.x+=k;m.br.y+=k;m.br.corner={tr:{x:m.br.x+f,y:m.br.y-g},bl:{x:m.br.x-g,y:m.br.y-f},br:{x:m.br.x,y:m.br.y}};m.br.corner.tl={x:m.br.corner.bl.x+f,y:m.br.corner.bl.y-g};m.br.x-=k;m.br.y-=k;m.ml.x-=k;m.ml.y-=k;m.ml.corner={tl:{x:m.ml.x,y:m.ml.y},tr:{x:m.ml.x+g,y:m.ml.y+f},bl:{x:m.ml.x-f,y:m.ml.y+g}};m.ml.corner.br={x:m.ml.corner.tr.x-f,y:m.ml.corner.tr.y+g};m.ml.x+=k;m.ml.y+=k;m.mt.x-=k;m.mt.y-=k;m.mt.corner={tl:{x:m.mt.x,y:m.mt.y},tr:{x:m.mt.x+g,y:m.mt.y+f},bl:{x:m.mt.x-f,y:m.mt.y+g}};m.mt.corner.br={x:m.mt.corner.tr.x-f,y:m.mt.corner.tr.y+g};m.mt.x+=k;m.mt.y+=k;m.mr.x-=k;m.mr.y-=k;m.mr.corner={tl:{x:m.mr.x,y:m.mr.y},tr:{x:m.mr.x+g,y:m.mr.y+f},bl:{x:m.mr.x-f,y:m.mr.y+g}};m.mr.corner.br={x:m.mr.corner.tr.x-f,y:m.mr.corner.tr.y+g};m.mr.x+=k;m.mr.y+=k;m.mb.x-=k;m.mb.y-=k;m.mb.corner={tl:{x:m.mb.x,y:m.mb.y},tr:{x:m.mb.x+g,y:m.mb.y+f},bl:{x:m.mb.x-f,y:m.mb.y+g}};m.mb.corner.br={x:m.mb.corner.tr.x-f,y:m.mb.corner.tr.y+g};m.mb.x+=k;m.mb.y+=k;l=m.mb.corner;l.tl.x-=k;l.tl.y-=k;l.tr.x-=k;l.tr.y-=k;l.br.x-=k;l.br.y-=k;l.bl.x-=k;l.bl.y-=k},toGrayscale:function(){var d=this.get("fill");if(d){this.set("overlayFill",new a.Color(d).toGrayscale().toRgb())}return this},complexity:function(){return 0},getCenter:function(){return{x:this.get("left")+this.width/2,y:this.get("top")+this.height/2}},straighten:function(){var d=this._getAngleValueForStraighten();this.setAngle(d);return this},fxStraighten:function(g){g=g||{};g.onComplete=g.onComplete||Prototype.emptyFunction;g.onChange=g.onChange||Prototype.emptyFunction;var k=this,f=new APE.anim.Animation(),d=this.get("angle"),h=this._getAngleValueForStraighten(),e=h-d;f.run=function(l){k.setAngle(d+e*l);g.onChange()};f.onend=function(){k.setCoords();g.onComplete()};f.duration=this.FX_DURATION;f.transition=APE.anim.Transitions[this.FX_TRANSITION];f.start();return this},fxRemove:function(h){h=h||{};h.onComplete=h.onComplete||Prototype.emptyFunction;h.onChange=h.onChange||Prototype.emptyFunction;var k=this,g=new APE.anim.Animation(),e=this.get("opacity"),d=0,f=d-e;g.run=function(l){k.set("opacity",e+f*l);h.onChange()};g.onend=function(){h.onComplete()};g.onstart=function(){k.setActive(false)};g.duration=this.FX_DURATION;g.transition=APE.anim.Transitions[this.FX_TRANSITION];g.start();return this},_getAngleValueForStraighten:function(){var d=this.get("angle");if(d>-225&&d<=-135){return -180}else{if(d>-135&&d<=-45){return -90}else{if(d>-45&&d<=45){return 0}else{if(d>45&&d<=135){return 90}else{if(d>135&&d<=225){return 180}else{if(d>225&&d<=315){return 270}else{if(d>315){return 360}}}}}}}return 0}});a.Object.prototype.rotate=a.Object.prototype.setAngle})();(function(){var a=this.Canvas||(this.Canvas={});if(a.Line){return}a.Line=a.base.createClass(a.Object,{type:"line",initialize:function(c,b){if(!c){c=[0,0,0,0]}this.callSuper("initialize",b);this.set("x1",c[0]);this.set("y1",c[1]);this.set("x2",c[2]);this.set("y2",c[3]);this.set("width",this.x2-this.x1);this.set("height",this.y2-this.y1);this.set("left",this.x1+this.width/2);this.set("top",this.y1+this.height/2)},_render:function(b){b.beginPath();b.moveTo(-this.width/2,-this.height/2);b.lineTo(this.width/2,this.height/2);b.stroke()},complexity:function(){return 1},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{x1:this.get("x1"),y1:this.get("y1"),x2:this.get("x2"),y2:this.get("y2")})}});a.Element.ATTRIBUTE_NAMES="x1 y1 x2 y2 stroke stroke-width transform".split(" ");a.Line.fromElement=function(c,b){var e=a.parseAttributes(c,a.Element.ATTRIBUTE_NAMES);var d=[e.x1||0,e.y1||0,e.x2||0,e.y2||0];return new a.Line(d,a.base.object.extend(e,b))};a.Line.fromObject=function(b){var c=[b.x1,b.y1,b.x2,b.y2];return new a.Line(c,b)}})();(function(){var b=this,a=b.Canvas||(b.Canvas={}),d=Math.PI*2;if(a.Circle){console.warn("Canvas.Circle is already defined.");return}a.Circle=a.base.createClass(a.Object,{type:"circle",initialize:function(e){e=e||{};this.set("radius",e.radius||0);this.callSuper("initialize",e);var f=this.get("radius")*2*this.get("scaleX");this.set("width",f).set("height",f)},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{radius:this.get("radius")})},_render:function(e){e.beginPath();e.arc(0,0,this.radius,0,d,false);if(this.fill){e.fill()}if(this.stroke){e.stroke()}},complexity:function(){return 1}});a.Circle.ATTRIBUTE_NAMES="cx cy r fill fill-opacity stroke stroke-width transform".split(" ");a.Circle.fromElement=function(f,e){var g=a.parseAttributes(f,a.Circle.ATTRIBUTE_NAMES);if(!c(g)){throw Error("value of `r` attribute is required and can not be negative")}return new a.Circle(a.base.object.extend(g,e))};function c(e){return(("radius" in e)&&(e.radius>0))}a.Circle.fromObject=function(e){return new a.Circle(e)}})();(function(){var a=this.Canvas||(this.Canvas={});if(a.Ellipse){console.warn("Canvas.Ellipse is already defined.");return}a.Ellipse=a.base.createClass(a.Object,{type:"ellipse",initialize:function(b){b=b||{};this.callSuper("initialize",b);this.set("rx",b.rx||0);this.set("ry",b.ry||0);this.set("width",this.get("rx")*2);this.set("height",this.get("ry")*2)},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{rx:this.get("rx"),ry:this.get("ry")})},render:function(b,c){if(this.rx===0||this.ry===0){return}return this.callSuper("render",b,c)},_render:function(b){b.beginPath();b.save();b.transform(1,0,0,this.ry/this.rx,0,0);b.arc(0,0,this.rx,0,Math.PI*2,false);b.restore();if(this.stroke){b.stroke()}if(this.fill){b.fill()}},complexity:function(){return 1}});a.Ellipse.ATTRIBUTE_NAMES="cx cy rx ry fill fill-opacity stroke stroke-width transform".split(" ");a.Ellipse.fromElement=function(c,b){var d=a.parseAttributes(c,a.Ellipse.ATTRIBUTE_NAMES);return new a.Ellipse(a.base.object.extend(d,b))};a.Ellipse.fromObject=function(b){return new a.Ellipse(b)}})();(function(){var a=this.Canvas||(this.Canvas={});if(a.Rect){return}a.Rect=a.base.createClass(a.Object,{type:"rect",options:{rx:0,ry:0},initialize:function(c){this.callSuper("initialize",c);this._initRxRy()},_initRxRy:function(){if(this.options.rx&&!this.options.ry){this.options.ry=this.options.rx}else{if(this.options.ry&&!this.options.rx){this.options.rx=this.options.ry}}},_render:function(e){var k=this.options.rx||0,g=this.options.ry||0,c=-this.width/2,l=-this.height/2,d=this.width,f=this.height;e.beginPath();e.moveTo(c+k,l);e.lineTo(c+d-k,l);e.bezierCurveTo(c+d,l,c+d,l+g,c+d,l+g);e.lineTo(c+d,l+f-g);e.bezierCurveTo(c+d,l+f,c+d-k,l+f,c+d-k,l+f);e.lineTo(c+k,l+f);e.bezierCurveTo(c,l+f,c,l+f-g,c,l+f-g);e.lineTo(c,l+g);e.bezierCurveTo(c,l,c+k,l,c+k,l);e.closePath();if(this.fill){e.fill()}if(this.stroke){e.stroke()}},_normalizeLeftTopProperties:function(c){if(c.left){this.set("left",c.left+this.getWidth()/2)}if(c.top){this.set("top",c.top+this.getHeight()/2)}return this},complexity:function(){return 1}});a.Rect.ATTRIBUTE_NAMES="x y width height rx ry fill fill-opacity stroke stroke-width transform".split(" ");function b(c){c.left=c.left||0;c.top=c.top||0;return c}a.Rect.fromElement=function(d,c){if(!d){return null}var f=a.parseAttributes(d,a.Rect.ATTRIBUTE_NAMES);f=b(f);var e=new a.Rect(a.base.object.extend(c||{},f));e._normalizeLeftTopProperties(f);return e};a.Rect.fromObject=function(c){return new a.Rect(c)}})();(function(){var b=this.Canvas||(this.Canvas={});if(b.Polyline){console.warn("Canvas.Polyline is already defined");return}b.Polyline=b.base.createClass(b.Object,{type:"polyline",initialize:function(d,c){c=c||{};this.set("points",d);this.callSuper("initialize",c);this._calcDimensions()},_calcDimensions:function(){return b.Polygon.prototype._calcDimensions.call(this)},_toOrigin:function(){return b.Polygon.prototype._toOrigin.call(this)},toObject:function(){return b.Polygon.prototype.toObject.call(this)},_render:function(e){var d;e.beginPath();for(var f=0,c=this.points.length;f<c;f++){d=this.points[f];e.lineTo(d.x,d.y)}if(this.fill){e.fill()}if(this.stroke){e.stroke()}},complexity:function(){return this.get("points").length}});var a="fill fill-opacity stroke stroke-width transform".split(" ");b.Polyline.fromElement=function(d,c){if(!d){return null}var e=b.parsePointsAttribute(d.getAttribute("points")),f=b.parseAttributes(d,a);return new b.Polyline(e,b.base.object.extend(f,c))};b.Polyline.fromObject=function(c){var d=c.points;return new b.Polyline(d,c)}})();(function(){var a=this.Canvas||(this.Canvas={});if(a.Polygon){console.warn("Canvas.Polygon is already defined");return}function c(d){return d.x}function b(d){return d.y}a.Polygon=a.base.createClass(a.Object,{type:"polygon",initialize:function(e,d){d=d||{};this.points=e;this.callSuper("initialize",d);this._calcDimensions()},_calcDimensions:function(){var e=this.points,d=a.base.array.min(e,c),h=a.base.array.min(e,b),g=a.base.array.max(e,c),f=a.base.array.max(e,b);this.width=g-d;this.height=f-h;this.minX=d;this.minY=h},_toOrigin:function(){this.points=this.points.map(function(d){return{x:d.x-this.minX,y:d.y-this.minY}},this)},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{points:this.points.clone()})},_render:function(f){var e;f.beginPath();for(var g=0,d=this.points.length;g<d;g++){e=this.points[g];f.lineTo(e.x,e.y)}if(this.fill){f.fill()}if(this.stroke){f.closePath();f.stroke()}},complexity:function(){return this.points.length}});a.Polygon.ATTRIBUTE_NAMES="fill fill-opacity stroke stroke-width transform".split(" ");a.Polygon.fromElement=function(e,d){if(!e){return null}var f=a.parsePointsAttribute(e.getAttribute("points")),g=a.parseAttributes(e,a.Polygon.ATTRIBUTE_NAMES);return new a.Polygon(f,a.base.object.extend(g,d))};a.Polygon.fromObject=function(d){return new a.Polygon(d.points,d)}})();(function(){var b=this.Canvas||(this.Canvas={});if(b.Path){console.warn("Canvas.Path is already defined");return}if(!b.Object){console.warn("Canvas.Path requires Canvas.Object");return}b.Path=b.base.createClass(b.Object,b.IStub,{type:"path",initialize:function(e,d){d=d||{};this.setOptions(d);this._importProperties();this.originalState={};if(!e){throw Error("`path` argument is required")}var c=Object.isArray(e);this.path=c?e:e.match&&e.match(/[a-zA-Z][^a-zA-Z]*/g);if(!this.path){return}if(!c){this._initializeFromArray(d)}this.setCoords();if(d.sourcePath){this.setSourcePath(d.sourcePath)}},_initializeFromArray:function(d){var c="width" in d,e="height" in d;this.path=this._parsePath();if(!c||!e){b.base.object.extend(this,this._parseDimensions());if(c){this.width=this.options.width}if(e){this.height=this.options.height}}},_render:function(p){var k,n=0,m=0,c=0,q=0,g,f,d=-(this.width/2),o=-(this.height/2);for(var e=0,h=this.path.length;e<h;++e){k=this.path[e];switch(k[0]){case"l":n+=k[1];m+=k[2];p.lineTo(n+d,m+o);break;case"L":n=k[1];m=k[2];p.lineTo(n+d,m+o);break;case"h":n+=k[1];p.lineTo(n+d,m+o);break;case"H":n=k[1];p.lineTo(n+d,m+o);break;case"v":m+=k[1];p.lineTo(n+d,m+o);break;case"V":m=k[1];p.lineTo(n+d,m+o);break;case"m":n+=k[1];m+=k[2];p.moveTo(n+d,m+o);break;case"M":n=k[1];m=k[2];p.moveTo(n+d,m+o);break;case"c":g=n+k[5];f=m+k[6];c=n+k[3];q=m+k[4];p.bezierCurveTo(n+k[1]+d,m+k[2]+o,c+d,q+o,g+d,f+o);n=g;m=f;break;case"C":n=k[5];m=k[6];c=k[3];q=k[4];p.bezierCurveTo(k[1]+d,k[2]+o,c+d,q+o,n+d,m+o);break;case"s":g=n+k[3];f=m+k[4];c=2*n-c;q=2*m-q;p.bezierCurveTo(c+d,q+o,n+k[1]+d,m+k[2]+o,g+d,f+o);n=g;m=f;break;case"S":g=k[3];f=k[4];c=2*n-c;q=2*m-q;p.bezierCurveTo(c+d,q+o,k[1]+d,k[2]+o,g+d,f+o);n=g;m=f;break;case"q":n+=k[3];m+=k[4];p.quadraticCurveTo(k[1]+d,k[2]+o,n+d,m+o);break;case"Q":n=k[3];m=k[4];c=k[1];q=k[2];p.quadraticCurveTo(c+d,q+o,n+d,m+o);break;case"T":g=n;f=m;n=k[1];m=k[2];c=-c+2*g;q=-q+2*f;p.quadraticCurveTo(c+d,q+o,n+d,m+o);break;case"a":break;case"A":break;case"z":case"Z":p.closePath();break}}},render:function(d,e){d.save();var c=this.transformMatrix;if(c){d.transform(c[0],c[1],c[2],c[3],c[4],c[5])}if(!e){this.transform(d)}if(this.overlayFill){d.fillStyle=this.overlayFill}else{if(this.fill){d.fillStyle=this.fill}}if(this.stroke){d.strokeStyle=this.stroke}d.beginPath();if(this.stub){this.stub._render(d)}else{this._render(d)}if(this.fill){d.fill()}if(this.options.stroke){d.strokeStyle=this.options.stroke;d.lineWidth=this.options.strokeWidth;d.stroke()}if(!e&&this.active){this.drawBorders(d);this.hideCorners||this.drawCorners(d)}d.restore()},toString:function(){return"#<Canvas.Path ("+this.complexity()+"): "+JSON.stringify({top:this.top,left:this.left})+">"},toObject:function(){var c=b.base.object.extend(this.callSuper("toObject"),{path:this.path,sourcePath:this.sourcePath});if(this.transformMatrix){c.transformMatrix=this.transformMatrix}return c},toDatalessObject:function(){var c=this.toObject();if(this.sourcePath){c.path=this.sourcePath}delete c.sourcePath;return c},complexity:function(){return this.path.length},set:function(d,c){if(this.stub){this.stub.set(d,c)}return this.callSuper("set",d,c)},_parsePath:function(){var d=[],f,g;for(var e=0,c=this.path.length;e<c;e++){f=this.path[e];g=f.slice(1).trim().replace(/(\d)-/g,"$1###-").split(/\s|,|###/);d.push([f.charAt(0)].concat(g.map(parseFloat)))}return d},_parseDimensions:function(){var k=[],g=[],l,h,m=false,p,n;function r(o){if(o[0]==="H"){return o[1]}return o[o.length-2]}function q(o){if(o[0]==="V"){return o[1]}return o[o.length-1]}this.path.forEach(function(s,o){if(s[0]!=="H"){l=(o===0)?r(s):r(this.path[o-1])}if(s[0]!=="V"){h=(o===0)?q(s):q(this.path[o-1])}if(s[0]===s[0].toLowerCase()){m=true}p=m?l+r(s):s[0]==="V"?l:r(s);n=m?h+q(s):s[0]==="H"?h:q(s);k.push(p);g.push(n)},this);var e=k.min(),d=g.min(),f=deltaY=0;var c={top:d-deltaY,left:e-f,bottom:g.max()-deltaY,right:k.max()-f};c.width=c.right-c.left;c.height=c.bottom-c.top;return c}});b.Path.fromObject=function(c){return new b.Path(c.path,c)};var a=b.Path.ATTRIBUTE_NAMES="d fill fill-opacity fill-rule stroke stroke-width transform".split(" ");b.Path.fromElement=function(d,c){var e=b.parseAttributes(d,a),f=e.d;delete e.d;return new b.Path(f,b.base.object.extend(e,c))}})();(function(){var a=this.Canvas||(this.Canvas={});if(a.PathGroup){console.warn("Canvas.PathGroup is already defined");return}a.PathGroup=a.base.createClass(a.Path,a.IStub,{type:"path-group",forceFillOverwrite:false,initialize:function(d,c){c=c||{};this.originalState={};this.paths=d;this.setOptions(c);this.initProperties();this.setCoords();if(c.sourcePath){this.setSourcePath(c.sourcePath)}},initProperties:function(){this.stateProperties.forEach(function(c){if(c==="fill"){this.set(c,this.options[c])}else{if(c==="angle"){this.setAngle(this.options[c])}else{this[c]=this.options[c]}}},this)},render:function(e){if(this.stub){e.save();this.transform(e);this.stub.render(e,false);if(this.active){this.drawBorders(e);this.drawCorners(e)}e.restore()}else{e.save();var c=this.transformMatrix;if(c){e.transform(c[0],c[1],c[2],c[3],c[4],c[5])}this.transform(e);for(var f=0,d=this.paths.length;f<d;++f){this.paths[f].render(e,true)}if(this.active){this.drawBorders(e);this.hideCorners||this.drawCorners(e)}e.restore()}},set:function(e,d){if((e==="fill"||e==="overlayFill")&&this.isSameColor()){this[e]=d;var c=this.paths.length;while(c--){this.paths[c].set(e,d)}}else{a.Object.prototype.set.call(this,e,d)}return this},toObject:function(){var c=a.Object.prototype.toObject;return a.base.object.extend(c.call(this),{paths:this.getObjects().invoke("clone"),sourcePath:this.sourcePath})},toDatalessObject:function(){var c=this.toObject();if(this.sourcePath){c.paths=this.sourcePath}return c},toString:function(){return"#<Canvas.PathGroup ("+this.complexity()+"): { top: "+this.top+", left: "+this.left+" }>"},isSameColor:function(){var c=this.getObjects()[0].get("fill");return this.every(function(d){return d.get("fill")===c})},complexity:function(){return this.paths.reduce(function(c,d){return c+((d&&d.complexity)?d.complexity():0)},0)},toGrayscale:function(){var c=this.paths.length;while(c--){this.paths[c].toGrayscale()}return this},getObjects:function(){return this.paths}});function b(f){for(var e=0,c=f.length;e<c;e++){if(!(f[e] instanceof a.Object)){var d=f[e].type.camelize().capitalize();f[e]=a[d].fromObject(f[e])}}return f}a.PathGroup.fromObject=function(c){var d=b(c.paths);return new a.PathGroup(d,c)}})();(function(){var a=this.Canvas||(this.Canvas={});if(a.Group){return}a.Group=a.base.createClass(a.Object,{type:"group",initialize:function(c,b){this.objects=c||[];this.originalState={};this.callSuper("initialize");this._calcBounds();this._updateObjectsCoords();if(b){a.base.object.extend(this,b)}this._setOpacityIfSame();this.setCoords(true);this.saveCoords();this.activateAllObjects()},_updateObjectsCoords:function(){var c=this.left,b=this.top;this.forEachObject(function(d){var e=d.get("left"),f=d.get("top");d.set("originalLeft",e);d.set("originalTop",f);d.set("left",e-c);d.set("top",f-b);d.setCoords();d.hideCorners=true},this)},toString:function(){return"#<Canvas.Group: ("+this.complexity()+")>"},getObjects:function(){return this.objects},add:function(b){this._restoreObjectsState();this.objects.push(b);b.setActive(true);this._calcBounds();this._updateObjectsCoords();return this},remove:function(b){this._restoreObjectsState();a.util.removeFromArray(this.objects,b);b.setActive(false);this._calcBounds();this._updateObjectsCoords();return this},size:function(){return this.getObjects().length},set:function(b,d){if(typeof d=="function"){this.set(b,d(this[b]))}else{if(b==="fill"||b==="opacity"){var c=this.objects.length;this[b]=d;while(c--){this.objects[c].set(b,d)}}else{this[b]=d}}return this},contains:function(b){return this.objects.indexOf(b)>-1},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{objects:this.objects.invoke("clone")})},render:function(c){c.save();this.transform(c);var f=Math.max(this.scaleX,this.scaleY);for(var d=0,b=this.objects.length;d<b;d++){var e=this.objects[d].borderScaleFactor;this.objects[d].borderScaleFactor=f;this.objects[d].render(c);this.objects[d].borderScaleFactor=e}this.hideBorders||this.drawBorders(c);this.hideCorners||this.drawCorners(c);c.restore();this.setCoords()},item:function(b){return this.getObjects()[b]},complexity:function(){return this.getObjects().reduce(function(c,b){c+=(typeof b.complexity=="function")?b.complexity():0;return c},0)},_restoreObjectsState:function(){this.objects.forEach(this._restoreObjectState,this);return this},_restoreObjectState:function(d){var f=this.get("left"),g=this.get("top"),b=this.getAngle()*(Math.PI/180),e=d.get("originalLeft"),h=d.get("originalTop"),c=Math.cos(b)*d.get("top")+Math.sin(b)*d.get("left"),k=-Math.sin(b)*d.get("top")+Math.cos(b)*d.get("left");d.setAngle(d.getAngle()+this.getAngle());d.set("left",f+k*this.get("scaleX"));d.set("top",g+c*this.get("scaleY"));d.set("scaleX",d.get("scaleX")*this.get("scaleX"));d.set("scaleY",d.get("scaleY")*this.get("scaleY"));d.setCoords();d.hideCorners=false;d.setActive(false);d.setCoords();return this},destroy:function(){return this._restoreObjectsState()},saveCoords:function(){this._originalLeft=this.get("left");this._originalTop=this.get("top");return this},hasMoved:function(){return this._originalLeft!==this.get("left")||this._originalTop!==this.get("top")},setObjectsCoords:function(){this.forEachObject(function(b){b.setCoords()});return this},activateAllObjects:function(){return this.setActive(true)},setActive:function(b){this.forEachObject(function(c){c.setActive(b)});return this},forEachObject:function(e,c){var d=this.getObjects(),b=d.length;while(b--){e.call(c,d[b],b,d)}return this},_setOpacityIfSame:function(){var d=this.getObjects(),c=d[0]?d[0].get("opacity"):1;var b=d.every(function(e){return e.get("opacity")===c});if(b){this.opacity=c}},_calcBounds:function(){var m=[],k=[],h,g,d,b,f,e,p,l=0,n=this.objects.length;for(;l<n;++l){f=this.objects[l];f.setCoords();for(var c in f.oCoords){m.push(f.oCoords[c].x);k.push(f.oCoords[c].y)}}h=a.base.array.min(m);d=a.base.array.max(m);g=a.base.array.min(k);b=a.base.array.max(k);e=d-h;p=b-g;this.width=e;this.height=p;this.left=h+e/2;this.top=g+p/2},containsPoint:function(c){var f=this.get("width")/2,b=this.get("height")/2,e=this.get("left"),d=this.get("top");return e-f<c.x&&e+f>c.x&&d-b<c.y&&d+b>c.y},toGrayscale:function(){var b=this.objects.length;while(b--){this.objects[b].toGrayscale()}}});a.Group.fromObject=function(b){return new a.Group(b.objects,b)}})();(function(){var a=this.Canvas||(this.Canvas={});if(a.Text){console.warn("Canvas.Text is already defined");return}if(!a.Object){console.warn("Canvas.Text requires Canvas.Object");return}a.Text=a.base.createClass(a.Object,{options:{top:10,left:10,fontsize:20,fontweight:100,fontfamily:"Modernist_One_400",path:null},type:"text",initialize:function(c,b){this.originalState={};this.initStateProperties();this.text=c;this.setOptions(b);a.base.object.extend(this,this.options);this.theta=this.angle*(Math.PI/180);this.width=this.getWidth();this.setCoords()},initStateProperties:function(){var b;if((b=this.constructor)&&(b=b.superclass)&&(b=b.prototype)&&(b=b.stateProperties)&&b.clone){this.stateProperties=b.clone();this.stateProperties.push("fontfamily","fontweight","path")}},toString:function(){return"#<Canvas.Text ("+this.complexity()+"): "+JSON.stringify({text:this.text,fontfamily:this.fontfamily})+">"},_render:function(b){var d=Cufon.textOptions||(Cufon.textOptions={});d.left=this.left;d.top=this.top;d.context=b;d.color=this.fill;var c=this._initDummyElement();this.transform(b);Cufon.replaceElement(c,{separate:"none",fontFamily:this.fontfamily});this.width=d.width;this.height=d.height},_initDummyElement:function(){var b=document.createElement("div");b.innerHTML=this.text;b.style.fontSize="40px";b.style.fontWeight="400";b.style.fontStyle="normal";b.style.letterSpacing="normal";b.style.color="#000000";b.style.fontWeight="600";b.style.fontFamily="Verdana";return b},render:function(b){b.save();this._render(b);if(this.active){this.drawBorders(b);this.drawCorners(b)}b.restore()},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{text:this.text,fontsize:this.fontsize,fontweight:this.fontweight,fontfamily:this.fontfamily,path:this.path})},setColor:function(b){this.set("fill",b);return this},setFontsize:function(b){this.set("fontsize",b);this.setCoords();return this},getText:function(){return this.text},setText:function(b){this.set("text",b);this.setCoords();return this},set:function(b,c){this[b]=c;if(b==="fontfamily"){this.path=this.path.replace(/(.*?)([^\/]*)(\.font\.js)/,"$1"+c+"$3")}return this}});a.Text.fromObject=function(b){return new a.Text(b.text,Object.clone(b))};a.Text.fromElement=function(b){}})(); |