/*! Fabric.js Copyright 2008-2014, Printio (Juriy Zaytsev, Maxim Chernyak) */ ;var fabric=fabric||{version:"1.4.12"};if(typeof exports!=="undefined"){exports.fabric=fabric}if(typeof document!=="undefined"&&typeof window!=="undefined"){fabric.document=document;fabric.window=window}else{fabric.document=require("jsdom").jsdom("
");fabric.window=fabric.document.createWindow()}fabric.isTouchSupported="ontouchstart" in fabric.document.documentElement;fabric.isLikelyNode=typeof Buffer!=="undefined"&&typeof window==="undefined";fabric.SHARED_ATTRIBUTES=["display","transform","fill","fill-opacity","fill-rule","opacity","stroke","stroke-dasharray","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width"];fabric.DPI=96;(function(){function d(e,f){if(!this.__eventListeners[e]){return}if(f){fabric.util.removeFromArray(this.__eventListeners[e],f)}else{this.__eventListeners[e].length=0}}function c(e,f){if(!this.__eventListeners){this.__eventListeners={}}if(arguments.length===1){for(var g in e){this.on(g,e[g])}}else{if(!this.__eventListeners[e]){this.__eventListeners[e]=[]}this.__eventListeners[e].push(f)}return this}function a(e,f){if(!this.__eventListeners){return}if(arguments.length===0){this.__eventListeners={}}else{if(arguments.length===1&&typeof arguments[0]==="object"){for(var g in e){d.call(this,g,e[g])}}else{d.call(this,e,f)}}return this}function b(g,h){if(!this.__eventListeners){return}var f=this.__eventListeners[g];if(!f){return}for(var j=0,e=f.length;j','')}}x(o,{getGradientDefs:function(H){var K=H.getElementsByTagName("linearGradient"),z=H.getElementsByTagName("radialGradient"),B,F,E=0,A,D,G=[],I={},J={};G.length=K.length+z.length;F=K.length;while(F--){G[E++]=K[F]}F=z.length;while(F--){G[E++]=z[F]}while(E--){B=G[E];D=B.getAttribute("xlink:href");A=B.getAttribute("id");if(D){J[A]=D.substr(1)}I[A]=B}for(A in J){var C=I[J[A]].cloneNode(true);B=I[A];while(C.firstChild){B.appendChild(C.firstChild)}}return I},parseAttributes:function(C,B,z){if(!C){return}var E,A={};if(typeof z==="undefined"){z=C.getAttribute("svgUid")}if(C.parentNode&&/^symbol|[g|a]$/i.test(C.parentNode.nodeName)){A=o.parseAttributes(C.parentNode,B,z)}var D=B.reduce(function(G,F){E=C.getAttribute(F);if(E){F=a(F);E=i(F,E,A);G[F]=E}return G},{});D=x(D,x(w(C,z),o.parseStyleAttribute(C)));return c(x(A,D))},parseElements:function(B,C,A,z){new o.ElementsParser(B,C,A,z).parse()},parseStyleAttribute:function(A){var z={},B=A.getAttribute("style");if(!B){return z}if(typeof B==="string"){p(B,z)}else{m(B,z)}return z},parsePointsAttribute:function(C){if(!C){return null}C=C.replace(/,/g," ").trim();C=C.split(/\s+/);var A=[],B,z;B=0;z=C.length;for(;B /i,""))}if(!D||!D.documentElement){return}o.parseSVGDocument(D.documentElement,function(G,F){s.set(A,{objects:o.util.array.invoke(G,"toObject"),options:F});C(G,F)},z)}},loadSVGFromString:function(A,D,z){A=A.trim();var B;if(typeof DOMParser!=="undefined"){var C=new DOMParser();if(C&&C.parseFromString){B=C.parseFromString(A,"text/xml")}}else{if(o.window.ActiveXObject){B=new ActiveXObject("Microsoft.XMLDOM");B.async="false";B.loadXML(A.replace(//i,""))}}o.parseSVGDocument(B.documentElement,function(F,E){D(F,E)},z)},createSVGFontFacesMarkup:function(C){var A="";for(var B=0,z=C.length;B ',"",""].join("")}return A},createSVGRefElementsMarkup:function(A){var z=[];g(z,A,"backgroundColor");g(z,A,"overlayColor");return z.join("")}})})(typeof exports!=="undefined"?exports:this);fabric.ElementsParser=function(c,d,b,a){this.elements=c;this.callback=d;this.options=b;this.reviver=a;this.svgUid=(b&&b.svgUid)||0};fabric.ElementsParser.prototype.parse=function(){this.instances=new Array(this.elements.length);this.numElements=this.elements.length;this.createObjects()};fabric.ElementsParser.prototype.createObjects=function(){for(var b=0,a=this.elements.length;bd.x&&this.y>d.y)},gte:function(d){return(this.x>=d.x&&this.y>=d.y)},lerp:function(e,d){return new a(this.x+(e.x-this.x)*d,this.y+(e.y-this.y)*d)},distanceFrom:function(f){var e=this.x-f.x,d=this.y-f.y;return Math.sqrt(e*e+d*d)},midPointFrom:function(d){return new a(this.x+(d.x-this.x)/2,this.y+(d.y-this.y)/2)},min:function(d){return new a(Math.min(this.x,d.x),Math.min(this.y,d.y))},max:function(d){return new a(Math.max(this.x,d.x),Math.max(this.y,d.y))},toString:function(){return this.x+","+this.y},setXY:function(d,e){this.x=d;this.y=e},setFromPoint:function(d){this.x=d.x;this.y=d.y},swap:function(e){var d=this.x,f=this.y;this.x=e.x;this.y=e.y;e.x=d;e.y=f}}})(typeof exports!=="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={});if(b.Intersection){b.warn("fabric.Intersection is already defined");return}function c(d){this.status=d;this.points=[]}b.Intersection=c;b.Intersection.prototype={appendPoint:function(d){this.points.push(d)},appendPoints:function(d){this.points=this.points.concat(d)}};b.Intersection.intersectLineLine=function(h,g,l,k){var m,e=(k.x-l.x)*(h.y-l.y)-(k.y-l.y)*(h.x-l.x),j=(g.x-h.x)*(h.y-l.y)-(g.y-h.y)*(h.x-l.x),i=(k.y-l.y)*(g.x-h.x)-(k.x-l.x)*(g.y-h.y);if(i!==0){var f=e/i,d=j/i;if(0<=f&&f<=1&&0<=d&&d<=1){m=new c("Intersection");m.points.push(new b.Point(h.x+f*(g.x-h.x),h.y+f*(g.y-h.y)))}else{m=new c()}}else{if(e===0||j===0){m=new c("Coincident")}else{m=new c("Parallel")}}return m};b.Intersection.intersectLinePolygon=function(e,d,l){var m=new c(),f=l.length;for(var h=0;h 0){m.status="Intersection"}return m};b.Intersection.intersectPolygonPolygon=function(j,h){var f=new c(),l=j.length;for(var k=0;k 0){f.status="Intersection"}return f};b.Intersection.intersectPolygonRectangle=function(n,e,d){var g=e.min(d),m=e.max(d),f=new b.Point(m.x,g.y),l=new b.Point(g.x,m.y),k=c.intersectLinePolygon(g,f,n),j=c.intersectLinePolygon(f,m,n),i=c.intersectLinePolygon(m,l,n),h=c.intersectLinePolygon(l,g,n),o=new c();o.appendPoints(k.points);o.appendPoints(j.points);o.appendPoints(i.points);o.appendPoints(h.points);if(o.points.length>0){o.status="Intersection"}return o}})(typeof exports!=="undefined"?exports:this);(function(b){var c=b.fabric||(b.fabric={});if(c.Color){c.warn("fabric.Color is already defined.");return}function d(e){if(!e){this.setSource([0,0,0,1])}else{this._tryParsingColor(e)}}c.Color=d;c.Color.prototype={_tryParsingColor:function(e){var f;if(e in d.colorNameMap){e=d.colorNameMap[e]}if(e==="transparent"){this.setSource([255,255,255,0]);return}f=d.sourceFromHex(e);if(!f){f=d.sourceFromRgb(e)}if(!f){f=d.sourceFromHsl(e)}if(f){this.setSource(f)}},_rgbToHsl:function(e,k,n){e/=255,k/=255,n/=255;var j,p,f,o=c.util.array.max([e,k,n]),i=c.util.array.min([e,k,n]);f=(o+i)/2;if(o===i){j=p=0}else{var m=o-i;p=f>0.5?m/(2-o-i):m/(o+i);switch(o){case e:j=(k-n)/m+(k 1){e-=1}if(e<1/6){return g+(f-g)*6*e}if(e<1/2){return f}if(e<2/3){return g+(f-g)*(2/3-e)*6}return g}c.Color.fromRgb=function(e){return d.fromSource(d.sourceFromRgb(e))};c.Color.sourceFromRgb=function(f){var h=f.match(d.reRGBa);if(h){var j=parseInt(h[1],10)/(/%$/.test(h[1])?100:1)*(/%$/.test(h[1])?255:1),i=parseInt(h[2],10)/(/%$/.test(h[2])?100:1)*(/%$/.test(h[2])?255:1),e=parseInt(h[3],10)/(/%$/.test(h[3])?100:1)*(/%$/.test(h[3])?255:1);return[parseInt(j,10),parseInt(i,10),parseInt(e,10),h[4]?parseFloat(h[4]):1]}};c.Color.fromRgba=d.fromRgb;c.Color.fromHsl=function(e){return d.fromSource(d.sourceFromHsl(e))};c.Color.sourceFromHsl=function(k){var n=k.match(d.reHSLa);if(!n){return}var m=(((parseFloat(n[1])%360)+360)%360)/360,u=parseFloat(n[2])/(/%$/.test(n[2])?100:1),j=parseFloat(n[3])/(/%$/.test(n[3])?100:1),e,o,t;if(u===0){e=o=t=j}else{var f=j<=0.5?j*(u+1):j+u-j*u,i=j*2-f;e=a(i,f,m+1/3);o=a(i,f,m);t=a(i,f,m-1/3)}return[Math.round(e*255),Math.round(o*255),Math.round(t*255),n[4]?parseFloat(n[4]):1]};c.Color.fromHsla=d.fromHsl;c.Color.fromHex=function(e){return d.fromSource(d.sourceFromHex(e))};c.Color.sourceFromHex=function(h){if(h.match(d.reHex)){var k=h.slice(h.indexOf("#")+1),f=(k.length===3),j=f?(k.charAt(0)+k.charAt(0)):k.substring(0,2),i=f?(k.charAt(1)+k.charAt(1)):k.substring(2,4),e=f?(k.charAt(2)+k.charAt(2)):k.substring(4,6);return[parseInt(j,16),parseInt(i,16),parseInt(e,16),1]}};c.Color.fromSource=function(e){var f=new d();f.setSource(e);return f}})(typeof exports!=="undefined"?exports:this);(function(){function d(f){var e=f.getAttribute("style"),h=f.getAttribute("offset"),g,m,l;h=parseFloat(h)/(/%$/.test(h)?100:1);h=h<0?0:h>1?1:h;if(e){var k=e.split(/\s*;\s*/);if(k[k.length-1]===""){k.pop()}for(var j=k.length;j--;){var n=k[j].split(/\s*:\s*/),p=n[0].trim(),o=n[1].trim();if(p==="stop-color"){g=o}else{if(p==="stop-opacity"){l=o}}}}if(!g){g=f.getAttribute("stop-color")||"rgb(0,0,0)"}if(!l){l=f.getAttribute("stop-opacity")}g=new fabric.Color(g);m=g.getAlpha();l=isNaN(parseFloat(l))?1:parseFloat(l);l*=m;return{offset:h,color:g.toRgb(),opacity:l}}function b(e){return{x1:e.getAttribute("x1")||0,y1:e.getAttribute("y1")||0,x2:e.getAttribute("x2")||"100%",y2:e.getAttribute("y2")||0}}function c(e){return{x1:e.getAttribute("fx")||e.getAttribute("cx")||"50%",y1:e.getAttribute("fy")||e.getAttribute("cy")||"50%",r1:0,x2:e.getAttribute("cx")||"50%",y2:e.getAttribute("cy")||"50%",r2:e.getAttribute("r")||"50%"}}fabric.Gradient=fabric.util.createClass({offsetX:0,offsetY:0,initialize:function(e){e||(e={});var f={};this.id=fabric.Object.__uid++;this.type=e.type||"linear";f={x1:e.coords.x1||0,y1:e.coords.y1||0,x2:e.coords.x2||0,y2:e.coords.y2||0};if(this.type==="radial"){f.r1=e.coords.r1||0;f.r2=e.coords.r2||0}this.coords=f;this.colorStops=e.colorStops.slice();if(e.gradientTransform){this.gradientTransform=e.gradientTransform}this.offsetX=e.offsetX||this.offsetX;this.offsetY=e.offsetY||this.offsetY},addColorStop:function(f){for(var e in f){var g=new fabric.Color(f[e]);this.colorStops.push({offset:e,color:g.toRgb(),opacity:g.getAlpha()})}return this},toObject:function(){return{type:this.type,coords:this.coords,colorStops:this.colorStops,offsetX:this.offsetX,offsetY:this.offsetY}},toSVG:function(g){var j=fabric.util.object.clone(this.coords),f,e;this.colorStops.sort(function(l,i){return l.offset-i.offset});if(!(g.group&&g.group.type==="path-group")){for(var k in j){if(k==="x1"||k==="x2"||k==="r2"){j[k]+=this.offsetX-g.width/2}else{if(k==="y1"||k==="y2"){j[k]+=this.offsetY-g.height/2}}}}e='id="SVGID_'+this.id+'" gradientUnits="userSpaceOnUse"';if(this.gradientTransform){e+=' gradientTransform="matrix('+this.gradientTransform.join(" ")+')" '}if(this.type==="linear"){f=[" \n']}else{if(this.type==="radial"){f=[" \n":"\n"));return f.join("")},toLive:function(o,f){var m,n=fabric.util.object.clone(this.coords);if(!this.type){return}if(f.group&&f.group.type==="path-group"){for(var e in n){if(e==="x1"||e==="x2"){n[e]+=-this.offsetX+f.width/2}else{if(e==="y1"||e==="y2"){n[e]+=-this.offsetY+f.height/2}}}}if(this.type==="linear"){m=o.createLinearGradient(n.x1,n.y1,n.x2,n.y2)}else{if(this.type==="radial"){m=o.createRadialGradient(n.x1,n.y1,n.r1,n.x2,n.y2,n.r2)}}for(var j=0,l=this.colorStops.length;j\n']}}for(var h=0;h \n')}f.push((this.type==="linear"?" '},toLive:function(a){var b=typeof this.source==="function"?this.source():this.source;if(!b){return""}if(typeof b.src!=="undefined"){if(!b.complete){return""}if(b.naturalWidth===0||b.naturalHeight===0){return""}}return a.createPattern(b,this.repeat)}});(function(a){var b=a.fabric||(a.fabric={});if(b.Shadow){b.warn("fabric.Shadow is already defined.");return}b.Shadow=b.util.createClass({color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:false,includeDefaultValues:true,initialize:function(c){if(typeof c==="string"){c=this._parseShadow(c)}for(var d in c){this[d]=c[d]}this.id=b.Object.__uid++},_parseShadow:function(f){var e=f.trim(),d=b.Shadow.reOffsetsAndBlur.exec(e)||[],c=e.replace(b.Shadow.reOffsetsAndBlur,"")||"rgb(0,0,0)";return{color:c.trim(),offsetX:parseInt(d[1],10)||0,offsetY:parseInt(d[2],10)||0,blur:parseInt(d[3],10)||0}},toString:function(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")},toSVG:function(c){var d="SourceAlpha";if(c&&(c.fill===this.color||c.stroke===this.color)){d="SourceGraphic"}return(' ')},toObject:function(){if(this.includeDefaultValues){return{color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY}}var d={},c=b.Shadow.prototype;if(this.color!==c.color){d.color=this.color}if(this.blur!==c.blur){d.blur=this.blur}if(this.offsetX!==c.offsetX){d.offsetX=this.offsetX}if(this.offsetY!==c.offsetY){d.offsetY=this.offsetY}return d}});b.Shadow.reOffsetsAndBlur=/(?:\s|^)(-?\d+(?:px)?(?:\s?|$))?(-?\d+(?:px)?(?:\s?|$))?(\d+(?:px)?)?(?:\s?|$)(?:$|\s)/})(typeof exports!=="undefined"?exports:this);(function(){if(fabric.StaticCanvas){fabric.warn("fabric.StaticCanvas is already defined.");return}var d=fabric.util.object.extend,b=fabric.util.getElementOffset,c=fabric.util.removeFromArray,a=new Error("Could not initialize `canvas` element");fabric.StaticCanvas=fabric.util.createClass({initialize:function(f,e){e||(e={});this._initStatic(f,e);fabric.StaticCanvas.activeInstance=this},backgroundColor:"",backgroundImage:null,overlayColor:"",overlayImage:null,includeDefaultValues:true,stateful:true,renderOnAddRemove:true,clipTo:null,controlsAboveOverlay:false,allowTouchScrolling:false,imageSmoothingEnabled:true,preserveObjectStacking:false,viewportTransform:[1,0,0,1,0,0],onBeforeScaleRotate:function(){},_initStatic:function(f,e){this._objects=[];this._createLowerCanvas(f);this._initOptions(e);this._setImageSmoothing();if(e.overlayImage){this.setOverlayImage(e.overlayImage,this.renderAll.bind(this))}if(e.backgroundImage){this.setBackgroundImage(e.backgroundImage,this.renderAll.bind(this))}if(e.backgroundColor){this.setBackgroundColor(e.backgroundColor,this.renderAll.bind(this))}if(e.overlayColor){this.setOverlayColor(e.overlayColor,this.renderAll.bind(this))}this.calcOffset()},calcOffset:function(){this._offset=b(this.lowerCanvasEl);return this},setOverlayImage:function(f,g,e){return this.__setBgOverlayImage("overlayImage",f,g,e)},setBackgroundImage:function(f,g,e){return this.__setBgOverlayImage("backgroundImage",f,g,e)},setOverlayColor:function(f,e){return this.__setBgOverlayColor("overlayColor",f,e)},setBackgroundColor:function(e,f){return this.__setBgOverlayColor("backgroundColor",e,f)},_setImageSmoothing:function(){var e=this.getContext();e.imageSmoothingEnabled=this.imageSmoothingEnabled;e.webkitImageSmoothingEnabled=this.imageSmoothingEnabled;e.mozImageSmoothingEnabled=this.imageSmoothingEnabled;e.msImageSmoothingEnabled=this.imageSmoothingEnabled;e.oImageSmoothingEnabled=this.imageSmoothingEnabled},__setBgOverlayImage:function(f,g,h,e){if(typeof g==="string"){fabric.util.loadImage(g,function(i){this[f]=new fabric.Image(i,e);h&&h()},this)}else{this[f]=g;h&&h()}return this},__setBgOverlayColor:function(f,e,h){if(e&&e.source){var g=this;fabric.util.loadImage(e.source,function(i){g[f]=new fabric.Pattern({source:i,repeat:e.repeat,offsetX:e.offsetX,offsetY:e.offsetY});h&&h()})}else{this[f]=e;h&&h()}return this},_createCanvasElement:function(){var e=fabric.document.createElement("canvas");if(!e.style){e.style={}}if(!e){throw a}this._initCanvasElement(e);return e},_initCanvasElement:function(e){fabric.util.createCanvasElement(e);if(typeof e.getContext==="undefined"){throw a}},_initOptions:function(e){for(var f in e){this[f]=e[f]}this.width=this.width||parseInt(this.lowerCanvasEl.width,10)||0;this.height=this.height||parseInt(this.lowerCanvasEl.height,10)||0;if(!this.lowerCanvasEl.style){return}this.lowerCanvasEl.width=this.width;this.lowerCanvasEl.height=this.height;this.lowerCanvasEl.style.width=this.width+"px";this.lowerCanvasEl.style.height=this.height+"px";this.viewportTransform=this.viewportTransform.slice()},_createLowerCanvas:function(e){this.lowerCanvasEl=fabric.util.getById(e)||this._createCanvasElement();this._initCanvasElement(this.lowerCanvasEl);fabric.util.addClass(this.lowerCanvasEl,"lower-canvas");if(this.interactive){this._applyCanvasStyle(this.lowerCanvasEl)}this.contextContainer=this.lowerCanvasEl.getContext("2d")},getWidth:function(){return this.width},getHeight:function(){return this.height},setWidth:function(f,e){return this.setDimensions({width:f},e)},setHeight:function(f,e){return this.setDimensions({height:f},e)},setDimensions:function(g,f){var e;f=f||{};for(var h in g){e=g[h];if(!f.cssOnly){this._setBackstoreDimension(h,g[h]);e+="px"}if(!f.backstoreOnly){this._setCssDimension(h,e)}}if(!f.cssOnly){this.renderAll()}this.calcOffset();return this},_setBackstoreDimension:function(f,e){this.lowerCanvasEl[f]=e;if(this.upperCanvasEl){this.upperCanvasEl[f]=e}if(this.cacheCanvasEl){this.cacheCanvasEl[f]=e}this[f]=e;return this},_setCssDimension:function(f,e){this.lowerCanvasEl.style[f]=e;if(this.upperCanvasEl){this.upperCanvasEl.style[f]=e}if(this.wrapperEl){this.wrapperEl.style[f]=e}return this},getZoom:function(){return Math.sqrt(this.viewportTransform[0]*this.viewportTransform[3])},setViewportTransform:function(g){this.viewportTransform=g;this.renderAll();for(var f=0,e=this._objects.length;f ");return f.join("")},_setSVGPreamble:function(e,f){if(!f.suppressPreamble){e.push('','\n')}},_setSVGHeader:function(f,g){var h,e,i;if(g.viewBox){h=g.viewBox.width;e=g.viewBox.height}else{h=this.width;e=this.height;if(!this.svgViewportTransformation){i=this.viewportTransform;h/=i[0];e/=i[3]}}f.push("