0?M-=2*c:1===a&&M<0&&(M+=2*c);for(var P=Math.ceil(Math.abs(M/c*2)),A=[],D=M/P,F=8/3*Math.sin(D/4)*Math.sin(D/4)/Math.sin(D/2),R=j+D,L=0;L2;for(e=e||0,h&&(l=t[2].xt[i-2].x?1:s.x===t[i-2].x?0:-1,c=s.y>t[i-2].y?1:s.y===t[i-2].y?0:-1),n.push(["L",s.x+l*e,s.y+c*e]),n},r.util.getPathSegmentsInfo=a,r.util.getBoundsOfCurve=function(e,i,n,s,o,a,l,c){if(r.cachesBoundsOfCurve&&(h=t.call(arguments),r.boundsOfCurveCache[h]))return r.boundsOfCurveCache[h];var h,u,f,d,g,p,m,y,b,x=Math.sqrt,_=Math.min,C=Math.max,S=Math.abs,w=[],T=[[],[]];f=6*e-12*n+6*o,u=-3*e+9*n-9*o+3*l,d=3*n-3*e;for(var O=0;O<2;++O){if(O>0&&(f=6*i-12*s+6*a,u=-3*i+9*s-9*a+3*c,d=3*s-3*i),1e-12>S(u)){if(1e-12>S(f))continue;0<(g=-d/f)&&g<1&&w.push(g);continue}!((y=f*f-4*d*u)<0)&&(0<(p=(-f+(b=x(y)))/(2*u))&&p<1&&w.push(p),0<(m=(-f-b)/(2*u))&&m<1&&w.push(m))}for(var k,E,j,M=w.length,P=M;M--;)k=(j=1-(g=w[M]))*j*j*e+3*j*j*g*n+3*j*g*g*o+g*g*g*l,T[0][M]=k,E=j*j*j*i+3*j*j*g*s+3*j*g*g*a+g*g*g*c,T[1][M]=E;T[0][P]=e,T[1][P]=i,T[0][P+1]=l,T[1][P+1]=c;var A=[{x:_.apply(null,T[0]),y:_.apply(null,T[1])},{x:C.apply(null,T[0]),y:C.apply(null,T[1])}];return r.cachesBoundsOfCurve&&(r.boundsOfCurveCache[h]=A),A},r.util.getPointOnPath=function(t,e,i){i||(i=a(t));for(var n=0;e-i[n].length>0&&n1e-4;)i=l(o),r=o,(n=s(c.x,c.y,i.x,i.y))+a>e?(o-=h,h/=2):(c=i,o+=h,a+=n);return i.angle=u(r),i}(l,e)}},r.util.transformPath=function(t,e,i){return i&&(e=r.util.multiplyTransformMatrices(e,[1,0,0,1,-i.x,-i.y])),t.map(function(t){for(var i=t.slice(0),n={},s=1;s=e})}}}(),function(){function t(e,i,n){if(n)if(!r.isLikelyNode&&i instanceof Element)e=i;else if(i instanceof Array){e=[];for(var s=0,o=i.length;s/g,">")},graphemeSplit:function(t){var e,i=0,n=[];for(i=0;i57343)return t.charAt(e);if(55296<=i&&i<=56319){if(t.length<=e+1)throw"High surrogate without following low surrogate";var n=t.charCodeAt(e+1);if(56320>n||n>57343)throw"High surrogate without following low surrogate";return t.charAt(e)+t.charAt(e+1)}if(0===e)throw"Low surrogate without preceding high surrogate";var r=t.charCodeAt(e-1);if(55296>r||r>56319)throw"Low surrogate without preceding high surrogate";return!1}(t,i))&&n.push(e);return n}},function(){var t=Array.prototype.slice,e=function(){},i=function(){for(var t in{toString:1})if("toString"===t)return!1;return!0}(),n=function(t,e,n){for(var r in e)r in t.prototype&&"function"==typeof t.prototype[r]&&(e[r]+"").indexOf("callSuper")>-1?t.prototype[r]=function(t){return function(){var i=this.constructor.superclass;this.constructor.superclass=n;var r=e[t].apply(this,arguments);if(this.constructor.superclass=i,"initialize"!==t)return r}}(r):t.prototype[r]=e[r],i&&(e.toString!==Object.prototype.toString&&(t.prototype.toString=e.toString),e.valueOf!==Object.prototype.valueOf&&(t.prototype.valueOf=e.valueOf))};function s(){}function o(e){for(var i=null,n=this;n.constructor.superclass;){var r=n.constructor.superclass.prototype[e];if(n[e]!==r){i=r;break}n=n.constructor.superclass.prototype}return i?arguments.length>1?i.apply(this,t.call(arguments,1)):i.call(this):console.log("tried to callSuper "+e+", method not found in prototype chain",this)}r.util.createClass=function(){var i=null,r=t.call(arguments,0);function a(){this.initialize.apply(this,arguments)}"function"==typeof r[0]&&(i=r.shift()),a.superclass=i,a.subclasses=[],i&&(s.prototype=i.prototype,a.prototype=new s,i.subclasses.push(a));for(var l=0,c=r.length;l-1||"touch"===t.pointerType}}(),function(){var t=r.document.createElement("div"),e="string"==typeof t.style.opacity,i="string"==typeof t.style.filter,n=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,s=function(t){return t};e?s=function(t,e){return t.style.opacity=e,t}:i&&(s=function(t,e){var i=t.style;return t.currentStyle&&!t.currentStyle.hasLayout&&(i.zoom=1),n.test(i.filter)?(e=e>=.9999?"":"alpha(opacity="+100*e+")",i.filter=i.filter.replace(n,e)):i.filter+=" alpha(opacity="+100*e+")",t}),r.util.setStyle=function(t,e){var i=t.style;if(!i)return t;if("string"==typeof e)return t.style.cssText+=";"+e,e.indexOf("opacity")>-1?s(t,e.match(/opacity:\s*(\d?\.?\d*)/)[1]):t;for(var n in e)if("opacity"===n)s(t,e[n]);else{var r="float"===n||"cssFloat"===n?void 0===i.styleFloat?"cssFloat":"styleFloat":n;i.setProperty(r,e[n])}return t}}(),function(){var t,e,i,n,s=Array.prototype.slice,o=function(t){return s.call(t,0)};try{n=o(r.document.childNodes)instanceof Array}catch(t){}function a(t,e){var i=r.document.createElement(t);for(var n in e)"class"===n?i.className=e[n]:"for"===n?i.htmlFor=e[n]:i.setAttribute(n,e[n]);return i}function l(t){for(var e=0,i=0,n=r.document.documentElement,s=r.document.body||{scrollLeft:0,scrollTop:0};t&&(t.parentNode||t.host)&&((t=t.parentNode||t.host)===r.document?(e=s.scrollLeft||n.scrollLeft||0,i=s.scrollTop||n.scrollTop||0):(e+=t.scrollLeft||0,i+=t.scrollTop||0),1!==t.nodeType||"fixed"!==t.style.position););return{left:e,top:i}}n||(o=function(t){for(var e=Array(t.length),i=t.length;i--;)e[i]=t[i];return e}),i=r.document.defaultView&&r.document.defaultView.getComputedStyle?function(t,e){var i=r.document.defaultView.getComputedStyle(t,null);return i?i[e]:void 0}:function(t,e){var i=t.style[e];return!i&&t.currentStyle&&(i=t.currentStyle[e]),i},e="userSelect"in(t=r.document.documentElement.style)?"userSelect":"MozUserSelect"in t?"MozUserSelect":"WebkitUserSelect"in t?"WebkitUserSelect":"KhtmlUserSelect"in t?"KhtmlUserSelect":"",r.util.makeElementUnselectable=function(t){return void 0!==t.onselectstart&&(t.onselectstart=r.util.falseFunction),e?t.style[e]="none":"string"==typeof t.unselectable&&(t.unselectable="on"),t},r.util.makeElementSelectable=function(t){return void 0!==t.onselectstart&&(t.onselectstart=null),e?t.style[e]="":"string"==typeof t.unselectable&&(t.unselectable=""),t},r.util.setImageSmoothing=function(t,e){t.imageSmoothingEnabled=t.imageSmoothingEnabled||t.webkitImageSmoothingEnabled||t.mozImageSmoothingEnabled||t.msImageSmoothingEnabled||t.oImageSmoothingEnabled,t.imageSmoothingEnabled=e},r.util.getById=function(t){return"string"==typeof t?r.document.getElementById(t):t},r.util.toArray=o,r.util.addClass=function(t,e){t&&-1===(" "+t.className+" ").indexOf(" "+e+" ")&&(t.className+=(t.className?" ":"")+e)},r.util.makeElement=a,r.util.wrapElement=function(t,e,i){return"string"==typeof e&&(e=a(e,i)),t.parentNode&&t.parentNode.replaceChild(e,t),e.appendChild(t),e},r.util.getScrollLeftTop=l,r.util.getElementOffset=function(t){var e,n,r=t&&t.ownerDocument,s={left:0,top:0},o={left:0,top:0},a={borderLeftWidth:"left",borderTopWidth:"top",paddingLeft:"left",paddingTop:"top"};if(!r)return o;for(var c in a)o[a[c]]+=parseInt(i(t,c),10)||0;return e=r.documentElement,void 0!==t.getBoundingClientRect&&(s=t.getBoundingClientRect()),n=l(t),{left:s.left+n.left-(e.clientLeft||0)+o.left,top:s.top+n.top-(e.clientTop||0)+o.top}},r.util.getNodeCanvas=function(t){var e=r.jsdomImplForWrapper(t);return e._canvas||e._image},r.util.cleanUpJsdomNode=function(t){if(r.isLikelyNode){var e=r.jsdomImplForWrapper(t);e&&(e._image=null,e._canvas=null,e._currentSrc=null,e._attributes=null,e._classList=null)}}}(),function(){function t(){}r.util.request=function(e,i){i||(i={});var n,s,o=i.method?i.method.toUpperCase():"GET",a=i.onComplete||function(){},l=new r.window.XMLHttpRequest,c=i.body||i.parameters;return l.onreadystatechange=function(){4===l.readyState&&(a(l),l.onreadystatechange=t)},"GET"===o&&(c=null,"string"==typeof i.parameters&&(n=e,s=i.parameters,e=n+(/\?/.test(n)?"&":"?")+s)),l.open(o,e,!0),("POST"===o||"PUT"===o)&&l.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),l.send(c),l}}(),r.log=console.log,r.warn=console.warn,function(){var t=r.util.object.extend,e=r.util.object.clone,i=[];function n(){return!1}function s(t,e,i,n){return-i*Math.cos(t/n*(Math.PI/2))+i+e}r.util.object.extend(i,{cancelAll:function(){var t=this.splice(0);return t.forEach(function(t){t.cancel()}),t},cancelByCanvas:function(t){if(!t)return[];var e=this.filter(function(e){return"object"==typeof e.target&&e.target.canvas===t});return e.forEach(function(t){t.cancel()}),e},cancelByTarget:function(t){var e=this.findAnimationsByTarget(t);return e.forEach(function(t){t.cancel()}),e},findAnimationIndex:function(t){return this.indexOf(this.findAnimation(t))},findAnimation:function(t){return this.find(function(e){return e.cancel===t})},findAnimationsByTarget:function(t){return t?this.filter(function(e){return e.target===t}):[]}});var o=r.window.requestAnimationFrame||r.window.webkitRequestAnimationFrame||r.window.mozRequestAnimationFrame||r.window.oRequestAnimationFrame||r.window.msRequestAnimationFrame||function(t){return r.window.setTimeout(t,1e3/60)},a=r.window.cancelAnimationFrame||r.window.clearTimeout;function l(){return o.apply(r.window,arguments)}r.util.animate=function(i){i||(i={});var o,a=!1,c=function(){var t=r.runningAnimations.indexOf(o);return t>-1&&r.runningAnimations.splice(t,1)[0]};return o=t(e(i),{cancel:function(){return a=!0,c()},currentValue:"startValue"in i?i.startValue:0,completionRate:0,durationRate:0}),r.runningAnimations.push(o),l(function(t){var e,r=t||+new Date,h=i.duration||500,u=r+h,f=i.onChange||n,d=i.abort||n,g=i.onComplete||n,p=i.easing||s,m="startValue"in i&&i.startValue.length>0,y="startValue"in i?i.startValue:0,b="endValue"in i?i.endValue:100,x=i.byValue||(m?y.map(function(t,e){return b[e]-y[e]}):b-y);i.onStart&&i.onStart(),function t(i){var n=(e=i||+new Date)>u?h:e-r,s=n/h,_=m?y.map(function(t,e){return p(n,y[e],x[e],h)}):p(n,y,x,h),C=m?Math.abs((_[0]-y[0])/x[0]):Math.abs((_-y)/x);if(o.currentValue=m?_.slice():_,o.completionRate=C,o.durationRate=s,!a){if(d(_,C,s))return void c();if(e>u){o.currentValue=m?b.slice():b,o.completionRate=1,o.durationRate=1,f(m?b.slice():b,1,1),g(b,1,1),c();return}f(_,C,s),l(t)}}(r)}),o.cancel},r.util.requestAnimFrame=l,r.util.cancelAnimFrame=function(){return a.apply(r.window,arguments)},r.runningAnimations=i}(),function(){function t(t,e,i){var n="rgba("+parseInt(t[0]+i*(e[0]-t[0]),10)+","+parseInt(t[1]+i*(e[1]-t[1]),10)+","+parseInt(t[2]+i*(e[2]-t[2]),10);return n+(","+(t&&e?parseFloat(t[3]+i*(e[3]-t[3])):1)+")")}r.util.animateColor=function(e,i,n,s){var o=new r.Color(e).getSource(),a=new r.Color(i).getSource(),l=s.onComplete,c=s.onChange;return s=s||{},r.util.animate(r.util.object.extend(s,{duration:n||500,startValue:o,endValue:a,byValue:a,easing:function(e,i,n,r){return t(i,n,s.colorEasing?s.colorEasing(e,r):1-Math.cos(e/r*(Math.PI/2)))},onComplete:function(e,i,n){if(l)return l(t(a,a,0),i,n)},onChange:function(e,i,n){if(c){if(Array.isArray(e))return c(t(e,e,0),i,n);c(e,i,n)}}}))}}(),function(){function t(t,e,i,n){return t1;)s.shift(),o=e.util.multiplyTransformMatrices(o,s[0]);return o}}();var p=RegExp("^\\s*("+e.reNum+"+)\\s*,?\\s*("+e.reNum+"+)\\s*,?\\s*("+e.reNum+"+)\\s*,?\\s*("+e.reNum+"+)\\s*$");function m(t){if(!e.svgViewBoxElementsRegEx.test(t.nodeName))return{};var i,n,r,o,a=t.getAttribute("viewBox"),l=1,c=1,h=0,u=0,f=t.getAttribute("width"),d=t.getAttribute("height"),g=t.getAttribute("x")||0,m=t.getAttribute("y")||0,y=t.getAttribute("preserveAspectRatio")||"",b=!a||!(a=a.match(p)),x=!f||!d||"100%"===f||"100%"===d,_=b&&x,C={},S="",w=0,T=0;if(C.width=0,C.height=0,C.toBeParsed=_,b&&(g||m)&&t.parentNode&&"#document"!==t.parentNode.nodeName&&(S=" translate("+s(g)+" "+s(m)+") ",r=(t.getAttribute("transform")||"")+S,t.setAttribute("transform",r),t.removeAttribute("x"),t.removeAttribute("y")),_)return C;if(b)return C.width=s(f),C.height=s(d),C;if(h=-parseFloat(a[1]),u=-parseFloat(a[2]),i=parseFloat(a[3]),n=parseFloat(a[4]),C.minX=h,C.minY=u,C.viewBoxWidth=i,C.viewBoxHeight=n,x?(C.width=i,C.height=n):(C.width=s(f),C.height=s(d),l=C.width/i,c=C.height/n),"none"!==(y=e.util.parsePreserveAspectRatioAttribute(y)).alignX&&("meet"===y.meetOrSlice&&(c=l=l>c?c:l),"slice"===y.meetOrSlice&&(c=l=l>c?l:c),w=C.width-i*l,T=C.height-n*l,"Mid"===y.alignX&&(w/=2),"Mid"===y.alignY&&(T/=2),"Min"===y.alignX&&(w=0),"Min"===y.alignY&&(T=0)),1===l&&1===c&&0===h&&0===u&&0===g&&0===m)return C;if((g||m)&&"#document"!==t.parentNode.nodeName&&(S=" translate("+s(g)+" "+s(m)+") "),r=S+" matrix("+l+" 0 0 "+c+" "+(h*l+w)+" "+(u*c+T)+") ","svg"===t.nodeName){for(o=t.ownerDocument.createElementNS(e.svgNS,"g");t.firstChild;)o.appendChild(t.firstChild);t.appendChild(o)}else(o=t).removeAttribute("x"),o.removeAttribute("y"),r=o.getAttribute("transform")+r;return o.setAttribute("transform",r),C}e.parseSVGDocument=function(t,i,r,s){if(t){!function(t){for(var i=f(t,["use","svg:use"]),n=0;i.length&&n-1&&h>-1&&h-1&&(i="stroke")}else{if("href"===t||"xlink:href"===t||"font"===t)return i;if("imageSmoothing"===t)return"optimizeQuality"===i;a=l?i.map(s):s(i,r)}return!l&&isNaN(a)?i:a}(x=S in a?a[S]:S,y[S],m,g),C[x]=_;C&&C.font&&e.parseFontDeclaration(C.font,C);var w=i(m,C);return e.svgValidParentsRegEx.test(t.nodeName)?w:function(t){for(var i in l)if(void 0!==t[l[i]]&&""!==t[i]){if(void 0===t[i]){if(!e.Object.prototype[i])continue;t[i]=e.Object.prototype[i]}if(0!==t[i].indexOf("url(")){var n=new e.Color(t[i]);t[i]=n.setAlpha(r(n.getAlpha()*t[l[i]],2)).toRgba()}}return t}(w)}},parseElements:function(t,i,n,r,s){new e.ElementsParser(t,i,n,r,s).parse()},parseStyleAttribute:function(t){var e,i,n,r,s={},o=t.getAttribute("style");if(!o)return s;if("string"==typeof o)o.replace(/;\s*$/,"").split(";").forEach(function(t){var n=t.split(":");e=n[0].trim().toLowerCase(),i=n[1].trim(),s[e]=i});else{for(var a in o)void 0!==o[a]&&(n=a.toLowerCase(),r=o[a],s[n]=r)}return s},parsePointsAttribute:function(t){if(!t)return null;t=(t=t.replace(/,/g," ").trim()).split(/\s+/);var e,i,n=[];for(e=0,i=t.length;et.x&&this.y>t.y},gte:function(t){return this.x>=t.x&&this.y>=t.y},lerp:function(t,e){return void 0===e&&(e=.5),e=Math.max(Math.min(1,e),0),new i(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)},distanceFrom:function(t){var e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)},midPointFrom:function(t){return this.lerp(t)},min:function(t){return new i(Math.min(this.x,t.x),Math.min(this.y,t.y))},max:function(t){return new i(Math.max(this.x,t.x),Math.max(this.y,t.y))},toString:function(){return this.x+","+this.y},setXY:function(t,e){return this.x=t,this.y=e,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setFromPoint:function(t){return this.x=t.x,this.y=t.y,this},swap:function(t){var e=this.x,i=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=i},clone:function(){return new i(this.x,this.y)}}}(i),function(t){"use strict";var e=t.fabric||(t.fabric={});if(e.Intersection)return e.warn("fabric.Intersection is already defined");function i(t){this.status=t,this.points=[]}e.Intersection=i,e.Intersection.prototype={constructor:i,appendPoint:function(t){return this.points.push(t),this},appendPoints:function(t){return this.points=this.points.concat(t),this}},e.Intersection.intersectLineLine=function(t,n,r,s){var o,a=(s.x-r.x)*(t.y-r.y)-(s.y-r.y)*(t.x-r.x),l=(n.x-t.x)*(t.y-r.y)-(n.y-t.y)*(t.x-r.x),c=(s.y-r.y)*(n.x-t.x)-(s.x-r.x)*(n.y-t.y);if(0!==c){var h=a/c,u=l/c;0<=h&&h<=1&&0<=u&&u<=1?(o=new i("Intersection")).appendPoint(new e.Point(t.x+h*(n.x-t.x),t.y+h*(n.y-t.y))):o=new i}else o=new i(0===a||0===l?"Coincident":"Parallel");return o},e.Intersection.intersectLinePolygon=function(t,e,n){var r,s,o,a,l=new i,c=n.length;for(a=0;a0&&(l.status="Intersection"),l},e.Intersection.intersectPolygonPolygon=function(t,e){var n,r=new i,s=t.length;for(n=0;n0&&(r.status="Intersection"),r},e.Intersection.intersectPolygonRectangle=function(t,n,r){var s=n.min(r),o=n.max(r),a=new e.Point(o.x,s.y),l=new e.Point(s.x,o.y),c=i.intersectLinePolygon(s,a,t),h=i.intersectLinePolygon(a,o,t),u=i.intersectLinePolygon(o,l,t),f=i.intersectLinePolygon(l,s,t),d=new i;return d.appendPoints(c.points),d.appendPoints(h.points),d.appendPoints(u.points),d.appendPoints(f.points),d.points.length>0&&(d.status="Intersection"),d}}(i),function(t){"use strict";var e=t.fabric||(t.fabric={});if(e.Color)return e.warn("fabric.Color is already defined.");function i(t){t?this._tryParsingColor(t):this.setSource([0,0,0,1])}function n(t,e,i){return(i<0&&(i+=1),i>1&&(i-=1),i<1/6)?t+(e-t)*6*i:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}e.Color=i,e.Color.prototype={_tryParsingColor:function(t){var e;t in i.colorNameMap&&(t=i.colorNameMap[t]),"transparent"===t&&(e=[255,255,255,0]),e||(e=i.sourceFromHex(t)),e||(e=i.sourceFromRgb(t)),e||(e=i.sourceFromHsl(t)),e||(e=[0,0,0,1]),e&&this.setSource(e)},_rgbToHsl:function(t,i,n){t/=255,i/=255,n/=255;var r,s,o,a=e.util.array.max([t,i,n]),l=e.util.array.min([t,i,n]);if(o=(a+l)/2,a===l)r=s=0;else{var c=a-l;switch(s=o>.5?c/(2-a-l):c/(a+l),a){case t:r=(i-n)/c+6*(i0)-(t<0)||+t};function f(t,e){return Math.round((t.angle+h(Math.atan2(e.y,e.x))+360)%360/45)}function d(t,i){var n=i.transform.target,r=n.canvas,s=e.util.object.clone(i);s.target=n,r&&r.fire("object:"+t,s),n.fire(t,i)}function g(t,e){var i=e.canvas,n=t[i.uniScaleKey];return i.uniformScaling&&!n||!i.uniformScaling&&n}function p(t){return t.originX===l&&t.originY===l}function m(t,e,i){var n=t.lockScalingX,r=t.lockScalingY;return!!n&&!!r||!e&&(!!n||!!r)&&!!i||!!n&&"x"===e||!!r&&"y"===e||!1}function y(t,e,i,n){return{e:t,transform:e,pointer:{x:i,y:n}}}function b(t){return function(e,i,n,r){var s=i.target,o=s.getCenterPoint(),a=s.translateToOriginPoint(o,i.originX,i.originY),l=t(e,i,n,r);return s.setPositionByOrigin(a,i.originX,i.originY),l}}function x(t,e){return function(i,n,r,s){var o=e(i,n,r,s);return o&&d(t,y(i,n,r,s)),o}}function _(t,i,n,r,s){var o=t.target,a=o.controls[t.corner],l=o.canvas.getZoom(),c=o.padding/l,h=o.toLocalPoint(new e.Point(r,s),i,n);return h.x>=c&&(h.x-=c),h.x<=-c&&(h.x+=c),h.y>=c&&(h.y-=c),h.y<=c&&(h.y+=c),h.x-=a.offsetX,h.y-=a.offsetY,h}function C(t){return t.flipX!==t.flipY}function S(t,e,i,n,r){if(0!==t[e]){var s=r/t._getTransformedDimensions()[n]*t[i];t.set(i,s)}}function w(t,e,i,n){var r,l=e.target,c=l._getTransformedDimensions(0,l.skewY),u=Math.abs(2*_(e,e.originX,e.originY,i,n).x)-c.x,f=l.skewX;u<2?r=0:(r=h(Math.atan2(u/l.scaleX,c.y/l.scaleY)),e.originX===s&&e.originY===a&&(r=-r),e.originX===o&&"top"===e.originY&&(r=-r),C(l)&&(r=-r));var d=f!==r;if(d){var g=l._getTransformedDimensions().y;l.set("skewX",r),S(l,"skewY","scaleY","y",g)}return d}function T(t,e,i,n){var r,l=e.target,c=l._getTransformedDimensions(l.skewX,0),u=Math.abs(2*_(e,e.originX,e.originY,i,n).y)-c.y,f=l.skewY;u<2?r=0:(r=h(Math.atan2(u/l.scaleY,c.x/l.scaleX)),e.originX===s&&e.originY===a&&(r=-r),e.originX===o&&"top"===e.originY&&(r=-r),C(l)&&(r=-r));var d=f!==r;if(d){var g=l._getTransformedDimensions().x;l.set("skewY",r),S(l,"skewX","scaleX","x",g)}return d}function O(t,e,i,n,r){r=r||{};var s,o,a,l,h,f,d=e.target,y=d.lockScalingX,b=d.lockScalingY,x=r.by,C=g(t,d),S=m(d,x,C),w=e.gestureScale;if(S)return!1;if(w)o=e.scaleX*w,a=e.scaleY*w;else{if(s=_(e,e.originX,e.originY,i,n),h="y"!==x?u(s.x):1,f="x"!==x?u(s.y):1,e.signX||(e.signX=h),e.signY||(e.signY=f),d.lockScalingFlip&&(e.signX!==h||e.signY!==f))return!1;if(l=d._getTransformedDimensions(),C&&!x){var T=Math.abs(s.x)+Math.abs(s.y),O=e.original,k=T/(Math.abs(l.x*O.scaleX/d.scaleX)+Math.abs(l.y*O.scaleY/d.scaleY));o=O.scaleX*k,a=O.scaleY*k}else o=Math.abs(s.x*d.scaleX/l.x),a=Math.abs(s.y*d.scaleY/l.y);p(e)&&(o*=2,a*=2),e.signX!==h&&"y"!==x&&(e.originX=c[e.originX],o*=-1,e.signX=h),e.signY!==f&&"x"!==x&&(e.originY=c[e.originY],a*=-1,e.signY=f)}var E=d.scaleX,j=d.scaleY;return x?("x"===x&&d.set("scaleX",o),"y"===x&&d.set("scaleY",a)):(y||d.set("scaleX",o),b||d.set("scaleY",a)),E!==d.scaleX||j!==d.scaleY}r.scaleCursorStyleHandler=function(t,e,n){var r=g(t,n),s="";return(0!==e.x&&0===e.y?s="x":0===e.x&&0!==e.y&&(s="y"),m(n,s,r))?"not-allowed":i[f(n,e)]+"-resize"},r.skewCursorStyleHandler=function(t,e,i){return 0!==e.x&&i.lockSkewingY||0!==e.y&&i.lockSkewingX?"not-allowed":n[f(i,e)%4]+"-resize"},r.scaleSkewCursorStyleHandler=function(t,e,i){return t[i.canvas.altActionKey]?r.skewCursorStyleHandler(t,e,i):r.scaleCursorStyleHandler(t,e,i)},r.rotationWithSnapping=x("rotating",b(function(t,e,i,n){var r=e.target,s=r.translateToOriginPoint(r.getCenterPoint(),e.originX,e.originY);if(r.lockRotation)return!1;var o=Math.atan2(e.ey-s.y,e.ex-s.x),a=h(Math.atan2(n-s.y,i-s.x)-o+e.theta),l=!0;if(r.snapAngle>0){var c=r.snapAngle,u=r.snapThreshold||c,f=Math.ceil(a/c)*c,d=Math.floor(a/c)*c;Math.abs(a-d)0?s:o:(c>0&&(r="top"===h?s:o),c<0&&(r="top"===h?o:s),C(a)&&(r=r===s?o:s)),e.originX=r,x("skewing",b(w))(t,e,i,n))},r.skewHandlerY=function(t,e,i,n){var r,o=e.target,c=o.skewY,h=e.originX;return!o.lockSkewingY&&(0===c?r=_(e,l,l,i,n).y>0?"top":a:(c>0&&(r=h===s?"top":a),c<0&&(r=h===s?a:"top"),C(o)&&(r="top"===r?a:"top")),e.originY=r,x("skewing",b(T))(t,e,i,n))},r.dragHandler=function(t,e,i,n){var r=e.target,s=i-e.offsetX,o=n-e.offsetY,a=!r.get("lockMovementX")&&r.left!==s,l=!r.get("lockMovementY")&&r.top!==o;return a&&r.set("left",s),l&&r.set("top",o),(a||l)&&d("moving",y(t,e,i,n)),a||l},r.scaleOrSkewActionName=function(t,e,i){var n=t[i.canvas.altActionKey];return 0===e.x?n?"skewX":"scaleY":0===e.y?n?"skewY":"scaleX":void 0},r.rotationStyleHandler=function(t,e,i){return i.lockRotation?"not-allowed":e.cursorStyle},r.fireEvent=d,r.wrapWithFixedAnchor=b,r.wrapWithFireEvent=x,r.getLocalPoint=_,e.controlsUtils=r}(i),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.degreesToRadians,n=e.controlsUtils;n.renderCircleControl=function(t,e,i,n,r){n=n||{};var s,o=this.sizeX||n.cornerSize||r.cornerSize,a=this.sizeY||n.cornerSize||r.cornerSize,l=void 0!==n.transparentCorners?n.transparentCorners:r.transparentCorners,c=!l&&(n.cornerStrokeColor||r.cornerStrokeColor),h=e,u=i;t.save(),t.fillStyle=n.cornerColor||r.cornerColor,t.strokeStyle=n.cornerStrokeColor||r.cornerStrokeColor,o>a?(s=o,t.scale(1,a/o),u=i*o/a):a>o?(s=a,t.scale(o/a,1),h=e*a/o):s=o,t.lineWidth=1,t.beginPath(),t.arc(h,u,s/2,0,2*Math.PI,!1),t[l?"stroke":"fill"](),c&&t.stroke(),t.restore()},n.renderSquareControl=function(t,e,n,r,s){r=r||{};var o=this.sizeX||r.cornerSize||s.cornerSize,a=this.sizeY||r.cornerSize||s.cornerSize,l=void 0!==r.transparentCorners?r.transparentCorners:s.transparentCorners,c=!l&&(r.cornerStrokeColor||s.cornerStrokeColor),h=o/2,u=a/2;t.save(),t.fillStyle=r.cornerColor||s.cornerColor,t.strokeStyle=r.cornerStrokeColor||s.cornerStrokeColor,t.lineWidth=1,t.translate(e,n),t.rotate(i(s.angle)),t[(l?"stroke":"fill")+"Rect"](-h,-u,o,a),c&&t.strokeRect(-h,-u,o,a),t.restore()}}(i),function(t){"use strict";var e=t.fabric||(t.fabric={});e.Control=function(t){for(var e in t)this[e]=t[e]},e.Control.prototype={visible:!0,actionName:"scale",angle:0,x:0,y:0,offsetX:0,offsetY:0,sizeX:null,sizeY:null,touchSizeX:null,touchSizeY:null,cursorStyle:"crosshair",withConnection:!1,actionHandler:function(){},mouseDownHandler:function(){},mouseUpHandler:function(){},getActionHandler:function(){return this.actionHandler},getMouseDownHandler:function(){return this.mouseDownHandler},getMouseUpHandler:function(){return this.mouseUpHandler},cursorStyleHandler:function(t,e){return e.cursorStyle},getActionName:function(t,e){return e.actionName},getVisibility:function(t,e){var i=t._controlsVisibility;return i&&void 0!==i[e]?i[e]:this.visible},setVisibility:function(t){this.visible=t},positionHandler:function(t,i){return e.util.transformPoint({x:this.x*t.x+this.offsetX,y:this.y*t.y+this.offsetY},i)},calcCornerCoords:function(t,i,n,r,s){var o,a,l,c,h=s?this.touchSizeX:this.sizeX,u=s?this.touchSizeY:this.sizeY;if(h&&u&&h!==u){var f=Math.atan2(u,h),d=Math.sqrt(h*h+u*u)/2,g=f-e.util.degreesToRadians(t),p=Math.PI/2-f-e.util.degreesToRadians(t);o=d*e.util.cos(g),a=d*e.util.sin(g),l=d*e.util.cos(p),c=d*e.util.sin(p)}else{d=.7071067812*(h&&u?h:i);var g=e.util.degreesToRadians(45-t);o=l=d*e.util.cos(g),a=c=d*e.util.sin(g)}return{tl:{x:n-c,y:r-l},tr:{x:n+o,y:r-a},bl:{x:n-o,y:r+a},br:{x:n+c,y:r+l}}},render:function(t,i,n,r,s){"circle"===((r=r||{}).cornerStyle||s.cornerStyle)?e.controlsUtils.renderCircleControl.call(this,t,i,n,r,s):e.controlsUtils.renderSquareControl.call(this,t,i,n,r,s)}}}(i),function(){var t=r.util.object.clone;r.Gradient=r.util.createClass({offsetX:0,offsetY:0,gradientTransform:null,gradientUnits:"pixels",type:"linear",initialize:function(t){t||(t={}),t.coords||(t.coords={});var e,i=this;Object.keys(t).forEach(function(e){i[e]=t[e]}),this.id?this.id+="_"+r.Object.__uid++:this.id=r.Object.__uid++,e={x1:t.coords.x1||0,y1:t.coords.y1||0,x2:t.coords.x2||0,y2:t.coords.y2||0},"radial"===this.type&&(e.r1=t.coords.r1||0,e.r2=t.coords.r2||0),this.coords=e,this.colorStops=t.colorStops.slice()},addColorStop:function(t){for(var e in t){var i=new r.Color(t[e]);this.colorStops.push({offset:parseFloat(e),color:i.toRgb(),opacity:i.getAlpha()})}return this},toObject:function(t){var e={type:this.type,coords:this.coords,colorStops:this.colorStops,offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?this.gradientTransform.concat():this.gradientTransform};return r.util.populateWithProperties(this,e,t),e},toSVG:function(e,i){var n,s,o,a,l=t(this.coords,!0),i=i||{},c=t(this.colorStops,!0),h=l.r1>l.r2,u=this.gradientTransform?this.gradientTransform.concat():r.iMatrix.concat(),f=-this.offsetX,d=-this.offsetY,g=!!i.additionalTransform,p="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox";if(c.sort(function(t,e){return t.offset-e.offset}),"objectBoundingBox"===p?(f/=e.width,d/=e.height):(f+=e.width/2,d+=e.height/2),"path"===e.type&&"percentage"!==this.gradientUnits&&(f-=e.pathOffset.x,d-=e.pathOffset.y),u[4]-=f,u[5]-=d,a='id="SVGID_'+this.id+'" gradientUnits="'+p+'"'+(' gradientTransform="'+(g?i.additionalTransform+" ":"")+r.util.matrixToSVG(u))+'" ',"linear"===this.type?o=["\n']:"radial"===this.type&&(o=["\n']),"radial"===this.type){if(h)for((c=c.concat()).reverse(),n=0,s=c.length;n0){var y=m/Math.max(l.r1,l.r2);for(n=0,s=c.length;n\n')}return o.push("linear"===this.type?"\n":"\n"),o.join("")},toLive:function(t){var e,i,n,s=r.util.object.clone(this.coords);if(this.type){for("linear"===this.type?e=t.createLinearGradient(s.x1,s.y1,s.x2,s.y2):"radial"===this.type&&(e=t.createRadialGradient(s.x1,s.y1,s.r1,s.x2,s.y2,s.r2)),i=0,n=this.colorStops.length;i1?1:u)&&(u=1);var f,d,g,p,m=t.getElementsByTagName("stop"),y="userSpaceOnUse"===t.getAttribute("gradientUnits")?"pixels":"percentage",b=t.getAttribute("gradientTransform")||"",x=[],_=0,C=0;for("linearGradient"===t.nodeName||"LINEARGRADIENT"===t.nodeName?(f="linear",d={x1:t.getAttribute("x1")||0,y1:t.getAttribute("y1")||0,x2:t.getAttribute("x2")||"100%",y2:t.getAttribute("y2")||0}):(f="radial",d={x1:t.getAttribute("fx")||t.getAttribute("cx")||"50%",y1:t.getAttribute("fy")||t.getAttribute("cy")||"50%",r1:0,x2:t.getAttribute("cx")||"50%",y2:t.getAttribute("cy")||"50%",r2:t.getAttribute("r")||"50%"}),g=m.length;g--;)x.push(function(t,e){var i,n,s,o,a=t.getAttribute("style"),l=t.getAttribute("offset")||0;if(l=(l=parseFloat(l)/(/%$/.test(l)?100:1))<0?0:l>1?1:l,a){var c=a.split(/\s*;\s*/);for(""===c[c.length-1]&&c.pop(),o=c.length;o--;){var h=c[o].split(/\s*:\s*/),u=h[0].trim(),f=h[1].trim();"stop-color"===u?i=f:"stop-opacity"===u&&(s=f)}}return i||(i=t.getAttribute("stop-color")||"rgb(0,0,0)"),s||(s=t.getAttribute("stop-opacity")),n=(i=new r.Color(i)).getAlpha(),s=(isNaN(parseFloat(s))?1:parseFloat(s))*(n*e),{offset:l,color:i.toRgb(),opacity:s}}(m[g],u));return p=r.parseTransformAttribute(b),s=0,o=d,a=n,l=y,Object.keys(o).forEach(function(t){"Infinity"===(c=o[t])?h=1:"-Infinity"===c?h=0:(h=parseFloat(o[t],10),"string"==typeof c&&/^(\d+\.\d+)%|(\d+)%$/.test(c)&&(h*=.01,"pixels"===l&&(("x1"===t||"x2"===t||"r2"===t)&&(h*=a.viewBoxWidth||a.width),("y1"===t||"y2"===t)&&(h*=a.viewBoxHeight||a.height)))),o[t]=h}),"pixels"===y&&(_=-e.left,C=-e.top),new r.Gradient({id:t.getAttribute("id"),type:f,coords:d,colorStops:x,gradientUnits:y,gradientTransform:p,offsetX:_,offsetY:C})}})}(),function(){"use strict";var t=r.util.toFixed;r.Pattern=r.util.createClass({repeat:"repeat",offsetX:0,offsetY:0,crossOrigin:"",patternTransform:null,initialize:function(t,e){if(t||(t={}),this.id=r.Object.__uid++,this.setOptions(t),!t.source||t.source&&"string"!=typeof t.source){e&&e(this);return}var i=this;this.source=r.util.createImage(),r.util.loadImage(t.source,function(t,n){i.source=t,e&&e(i,n)},null,this.crossOrigin)},toObject:function(e){var i,n,s=r.Object.NUM_FRACTION_DIGITS;return"string"==typeof this.source.src?i=this.source.src:"object"==typeof this.source&&this.source.toDataURL&&(i=this.source.toDataURL()),n={type:"pattern",source:i,repeat:this.repeat,crossOrigin:this.crossOrigin,offsetX:t(this.offsetX,s),offsetY:t(this.offsetY,s),patternTransform:this.patternTransform?this.patternTransform.concat():null},r.util.populateWithProperties(this,n,e),n},toSVG:function(t){var e="function"==typeof this.source?this.source():this.source,i=e.width/t.width,n=e.height/t.height,r=this.offsetX/t.width,s=this.offsetY/t.height,o="";return("repeat-x"===this.repeat||"no-repeat"===this.repeat)&&(n=1,s&&(n+=Math.abs(s))),("repeat-y"===this.repeat||"no-repeat"===this.repeat)&&(i=1,r&&(i+=Math.abs(r))),e.src?o=e.src:e.toDataURL&&(o=e.toDataURL()),'\n\n\n'},setOptions:function(t){for(var e in t)this[e]=t[e]},toLive:function(t){var e=this.source;return e&&(void 0===e.src||e.complete&&0!==e.naturalWidth&&0!==e.naturalHeight)?t.createPattern(e,this.repeat):""}})}(),function(t){"use strict";var e=t.fabric||(t.fabric={}),i=e.util.toFixed;if(e.Shadow)return e.warn("fabric.Shadow is already defined.");e.Shadow=e.util.createClass({color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1,initialize:function(t){for(var i in"string"==typeof t&&(t=this._parseShadow(t)),t)this[i]=t[i];this.id=e.Object.__uid++},_parseShadow:function(t){var i=t.trim(),n=e.Shadow.reOffsetsAndBlur.exec(i)||[];return{color:(i.replace(e.Shadow.reOffsetsAndBlur,"")||"rgb(0,0,0)").trim(),offsetX:parseFloat(n[1],10)||0,offsetY:parseFloat(n[2],10)||0,blur:parseFloat(n[3],10)||0}},toString:function(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")},toSVG:function(t){var n=40,r=40,s=e.Object.NUM_FRACTION_DIGITS,o=e.util.rotateVector({x:this.offsetX,y:this.offsetY},e.util.degreesToRadians(-t.angle)),a=new e.Color(this.color);return t.width&&t.height&&(n=100*i((Math.abs(o.x)+this.blur)/t.width,s)+20,r=100*i((Math.abs(o.y)+this.blur)/t.height,s)+20),t.flipX&&(o.x*=-1),t.flipY&&(o.y*=-1),'\n \n \n \n \n \n \n \n \n\n'},toObject:function(){if(this.includeDefaultValues)return{color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling};var t={},i=e.Shadow.prototype;return["color","blur","offsetX","offsetY","affectStroke","nonScaling"].forEach(function(e){this[e]!==i[e]&&(t[e]=this[e])},this),t}}),e.Shadow.reOffsetsAndBlur=/(?:\s|^)(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(\d+(?:\.\d*)?(?:px)?)?(?:\s?|$)(?:$|\s)/}(i),function(){"use strict";if(r.StaticCanvas)return r.warn("fabric.StaticCanvas is already defined.");var t=r.util.object.extend,e=r.util.getElementOffset,i=r.util.removeFromArray,n=r.util.toFixed,s=r.util.transformPoint,o=r.util.invertTransform,a=r.util.getNodeCanvas,l=r.util.createCanvasElement,c=Error("Could not initialize `canvas` element");r.StaticCanvas=r.util.createClass(r.CommonMethods,{initialize:function(t,e){e||(e={}),this.renderAndResetBound=this.renderAndReset.bind(this),this.requestRenderAllBound=this.requestRenderAll.bind(this),this._initStatic(t,e)},backgroundColor:"",backgroundImage:null,overlayColor:"",overlayImage:null,includeDefaultValues:!0,stateful:!1,renderOnAddRemove:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,imageSmoothingEnabled:!0,viewportTransform:r.iMatrix.concat(),backgroundVpt:!0,overlayVpt:!0,enableRetinaScaling:!0,vptCoords:{},skipOffscreen:!0,clipPath:void 0,_initStatic:function(t,e){var i=this.requestRenderAllBound;this._objects=[],this._createLowerCanvas(t),this._initOptions(e),this.interactive||this._initRetinaScaling(),e.overlayImage&&this.setOverlayImage(e.overlayImage,i),e.backgroundImage&&this.setBackgroundImage(e.backgroundImage,i),e.backgroundColor&&this.setBackgroundColor(e.backgroundColor,i),e.overlayColor&&this.setOverlayColor(e.overlayColor,i),this.calcOffset()},_isRetinaScaling:function(){return r.devicePixelRatio>1&&this.enableRetinaScaling},getRetinaScaling:function(){return this._isRetinaScaling()?Math.max(1,r.devicePixelRatio):1},_initRetinaScaling:function(){if(this._isRetinaScaling()){var t=r.devicePixelRatio;this.__initRetinaScaling(t,this.lowerCanvasEl,this.contextContainer),this.upperCanvasEl&&this.__initRetinaScaling(t,this.upperCanvasEl,this.contextTop)}},__initRetinaScaling:function(t,e,i){e.setAttribute("width",this.width*t),e.setAttribute("height",this.height*t),i.scale(t,t)},calcOffset:function(){return this._offset=e(this.lowerCanvasEl),this},setOverlayImage:function(t,e,i){return this.__setBgOverlayImage("overlayImage",t,e,i)},setBackgroundImage:function(t,e,i){return this.__setBgOverlayImage("backgroundImage",t,e,i)},setOverlayColor:function(t,e){return this.__setBgOverlayColor("overlayColor",t,e)},setBackgroundColor:function(t,e){return this.__setBgOverlayColor("backgroundColor",t,e)},__setBgOverlayImage:function(t,e,i,n){return"string"==typeof e?r.util.loadImage(e,function(e,s){if(e){var o=new r.Image(e,n);this[t]=o,o.canvas=this}i&&i(e,s)},this,n&&n.crossOrigin):(n&&e.setOptions(n),this[t]=e,e&&(e.canvas=this),i&&i(e,!1)),this},__setBgOverlayColor:function(t,e,i){return this[t]=e,this._initGradient(e,t),this._initPattern(e,t,i),this},_createCanvasElement:function(){var t=l();if(!t||(t.style||(t.style={}),void 0===t.getContext))throw c;return t},_initOptions:function(t){var e=this.lowerCanvasEl;this._setOptions(t),this.width=this.width||parseInt(e.width,10)||0,this.height=this.height||parseInt(e.height,10)||0,this.lowerCanvasEl.style&&(e.width=this.width,e.height=this.height,e.style.width=this.width+"px",e.style.height=this.height+"px",this.viewportTransform=this.viewportTransform.slice())},_createLowerCanvas:function(t){t&&t.getContext?this.lowerCanvasEl=t:this.lowerCanvasEl=r.util.getById(t)||this._createCanvasElement(),r.util.addClass(this.lowerCanvasEl,"lower-canvas"),this._originalCanvasStyle=this.lowerCanvasEl.style,this.interactive&&this._applyCanvasStyle(this.lowerCanvasEl),this.contextContainer=this.lowerCanvasEl.getContext("2d")},getWidth:function(){return this.width},getHeight:function(){return this.height},setWidth:function(t,e){return this.setDimensions({width:t},e)},setHeight:function(t,e){return this.setDimensions({height:t},e)},setDimensions:function(t,e){var i;for(var n in e=e||{},t)i=t[n],e.cssOnly||(this._setBackstoreDimension(n,t[n]),i+="px",this.hasLostContext=!0),e.backstoreOnly||this._setCssDimension(n,i);return this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(this.contextTop),this._initRetinaScaling(),this.calcOffset(),e.cssOnly||this.requestRenderAll(),this},_setBackstoreDimension:function(t,e){return this.lowerCanvasEl[t]=e,this.upperCanvasEl&&(this.upperCanvasEl[t]=e),this.cacheCanvasEl&&(this.cacheCanvasEl[t]=e),this[t]=e,this},_setCssDimension:function(t,e){return this.lowerCanvasEl.style[t]=e,this.upperCanvasEl&&(this.upperCanvasEl.style[t]=e),this.wrapperEl&&(this.wrapperEl.style[t]=e),this},getZoom:function(){return this.viewportTransform[0]},setViewportTransform:function(t){var e,i,n,r=this._activeObject,s=this.backgroundImage,o=this.overlayImage;for(i=0,this.viewportTransform=t,n=this._objects.length;i\n'),this._setSVGBgOverlayColor(i,"background"),this._setSVGBgOverlayImage(i,"backgroundImage",e),this._setSVGObjects(i,e),this.clipPath&&i.push("\n"),this._setSVGBgOverlayColor(i,"overlay"),this._setSVGBgOverlayImage(i,"overlayImage",e),i.push("