diff --git a/dist/all.js b/dist/all.js index 1a103e89..8660150a 100644 --- a/dist/all.js +++ b/dist/all.js @@ -1,12 +1,23 @@ /*! Fabric.js Copyright 2010, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var console = console || { - log: function() { }, - warn: function() { } -}; - var fabric = fabric || { version: 0.1 }; +fabric.log = function() { }; +fabric.warn = function() { }; + +if (typeof console !== 'undefined') { + if (typeof console.log !== 'undefined' && console.log.apply) { + fabric.log = function() { + return console.log.apply(console, arguments); + }; + } + if (typeof console.warn !== 'undefined' && console.warn.apply) { + fabric.warn = function() { + return console.warn.apply(console, arguments); + }; + } +} + /* http://www.JSON.org/json2.js 2010-03-20 @@ -1497,7 +1508,7 @@ fabric.util.animate = animate; return klass.fromElement(el, options); } catch(e) { - console.log(e.message || e); + fabric.log(e.message || e); } } }); @@ -1598,7 +1609,7 @@ fabric.util.animate = animate; var fabric = this.fabric || (this.fabric = { }); if (fabric.Point) { - console.warn('fabric.Point is already defined'); + fabric.warn('fabric.Point is already defined'); return; } @@ -1724,7 +1735,7 @@ fabric.util.animate = animate; fabric = global.fabric || (global.fabric = { }); if (fabric.Intersection) { - console.warn('fabric.Intersection is already defined'); + fabric.warn('fabric.Intersection is already defined'); return; } @@ -1836,7 +1847,7 @@ fabric.util.animate = animate; var fabric = this.fabric || (this.fabric = { }); if (fabric.Color) { - console.warn('fabric.Color is already defined.'); + fabric.warn('fabric.Color is already defined.'); return; } @@ -2087,7 +2098,7 @@ fabric.util.animate = animate; (function () { if (fabric.Element) { - console.warn('fabric.Element is already defined.'); + fabric.warn('fabric.Element is already defined.'); return; } @@ -3719,7 +3730,7 @@ fabric.util.animate = animate; }, this); } catch(e) { - console.log(e.message); + fabric.log(e.message); } }, @@ -3811,7 +3822,7 @@ fabric.util.animate = animate; } function onFailure() { - console.log('ERROR!'); + fabric.log('ERROR!'); } }, @@ -5548,7 +5559,7 @@ fabric.util.animate = animate; extend = fabric.util.object.extend; if (fabric.Circle) { - console.warn('fabric.Circle is already defined.'); + fabric.warn('fabric.Circle is already defined.'); return; } @@ -5738,7 +5749,7 @@ fabric.util.animate = animate; extend = fabric.util.object.extend; if (fabric.Ellipse) { - console.warn('fabric.Ellipse is already defined.'); + fabric.warn('fabric.Ellipse is already defined.'); return; } @@ -5991,7 +6002,7 @@ fabric.util.animate = animate; var fabric = this.fabric || (this.fabric = { }); if (fabric.Polyline) { - console.warn('fabric.Polyline is already defined'); + fabric.warn('fabric.Polyline is already defined'); return; } @@ -6105,7 +6116,7 @@ fabric.util.animate = animate; max = fabric.util.array.max; if (fabric.Polygon) { - console.warn('fabric.Polygon is already defined'); + fabric.warn('fabric.Polygon is already defined'); return; } @@ -6236,11 +6247,11 @@ fabric.util.animate = animate; extend = fabric.util.object.extend; if (fabric.Path) { - console.warn('fabric.Path is already defined'); + fabric.warn('fabric.Path is already defined'); return; } if (!fabric.Object) { - console.warn('fabric.Path requires fabric.Object'); + fabric.warn('fabric.Path requires fabric.Object'); return; } @@ -6695,7 +6706,7 @@ fabric.util.animate = animate; capitalize = fabric.util.string.capitalize; if (fabric.PathGroup) { - console.warn('fabric.PathGroup is already defined'); + fabric.warn('fabric.PathGroup is already defined'); return; } @@ -7332,11 +7343,11 @@ fabric.util.animate = animate; clone = fabric.util.object.clone; if (fabric.Text) { - console.warn('fabric.Text is already defined'); + fabric.warn('fabric.Text is already defined'); return; } if (!fabric.Object) { - console.warn('fabric.Text requires fabric.Object'); + fabric.warn('fabric.Text requires fabric.Object'); return; } @@ -7522,12 +7533,12 @@ fabric.util.animate = animate; } if (global.fabric.Image) { - console.warn('fabric.Image is already defined.'); + fabric.warn('fabric.Image is already defined.'); return; }; if (!fabric.Object) { - console.warn('fabric.Object is required for fabric.Image initialization'); + fabric.warn('fabric.Object is required for fabric.Image initialization'); return; } diff --git a/dist/all.min-via-uglify.js b/dist/all.min-via-uglify.js deleted file mode 100644 index 2df71489..00000000 --- a/dist/all.min-via-uglify.js +++ /dev/null @@ -1 +0,0 @@ -if(typeof console=="undefined")var console={log:function(){},warn:function(){}};this.JSON||(this.JSON={});(function(){function f(a){return a<10?"0"+a:a}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(a){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(a){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(a){escapable.lastIndex=0;return escapable.test(a)?"\""+a.replace(escapable,function(a){var b=meta[a];return typeof b==="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+"\"":"\""+a+"\""}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i==="object"&&typeof i.toJSON==="function"&&(i=i.toJSON(a));typeof rep==="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent;h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c>>0;b=Number(b)||0;b=Math[b<0?"ceil":"floor"](b);b<0&&(b+=c);for(;b>>0;c>>0;d>>0;c>>0;c>>0;e>>0,c=0,d;if(arguments.length>1)d=arguments[1];else do{if(c in this){d=this[c++];break}if(++c>=b)throw new TypeError()}while(true);for(;c=d&&(d=a[c][b]);else while(c--)a[c]>=d&&(d=a[c]);return d}function f(a,b){var c=a.length-1,d=b?a[c][b]:a[c];if(b)while(c--)a[c][b]-1?i(a,b.match(/opacity:\s*(\d?\.?\d*)/)[1]):a}for(var e in b)if(e==="opacity")i(a,b[e]);else{var f=e==="float"||e==="cssFloat"?typeof c.styleFloat==="undefined"?"cssFloat":"styleFloat":e;c[f]=b[e]}return a}var c=document.createElement("div"),d=typeof c.style.opacity==="string",e=typeof c.style.filter==="string",f=document.defaultView,g=f&&typeof f.getComputedStyle!=="undefined",h=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,i=function(a){return a};d?i=function(a,b){a.style.opacity=b;return a}:e&&(i=function(a,b){var c=a.style;a.currentStyle&&!a.currentStyle.hasLayout&&(c.zoom=1);if(h.test(c.filter)){b=b>=0.9999?"":"alpha(opacity="+b*100+")";c.filter=c.filter.replace(h,b)}else c.filter+=" alpha(opacity="+b*100+")";return a});b.util.setStyle=a})();function k(a){return typeof a==="string"?document.getElementById(a):a}function l(a){var b=[],c=a.length;while(c--)b[c]=a[c];return b}function m(a,b){var c=document.createElement(a);for(var d in b)d==="class"?c.className=b[d]:d==="for"?c.htmlFor=b[d]:c.setAttribute(d,b[d]);return c}function n(a,b){(" "+a.className+" ").indexOf(" "+b+" ")===-1&&(a.className+=(a.className?" ":"")+b)}function o(a,b,c){typeof b==="string"&&(b=m(b,c));a.parentNode&&a.parentNode.replaceChild(b,a);b.appendChild(a);return b}function p(a){var b=0,c=0;do{b+=a.offsetTop||0;c+=a.offsetLeft||0;a=a.offsetParent}while(a);return{left:c,top:b}}(function(){var a=document.documentElement.style,c="userSelect"in a?"userSelect":"MozUserSelect"in a?"MozUserSelect":"WebkitUserSelect"in a?"WebkitUserSelect":"KhtmlUserSelect"in a?"KhtmlUserSelect":"";function d(a){typeof a.onselectstart!=="undefined"&&(a.onselectstart=b.util.falseFunction);c?a.style[c]="none":typeof a.unselectable=="string"&&(a.unselectable="on");return a}b.util.makeElementUnselectable=d})();(function(){function a(a,b){var c=document.getElementsByTagName("head")[0],d=document.createElement("script"),e=true;d.type="text/javascript";d.setAttribute("runat","server");d.onload=d.onreadystatechange=function(a){if(e){if(typeof this.readyState=="string"&&this.readyState!=="loaded"&&this.readyState!=="complete")return;e=false;b(a||window.event);d=d.onload=d.onreadystatechange=null}};d.src=a;c.appendChild(d)}function c(a,b){d.load(a);b()}b.util.getScript=a;var d=this.Jaxer;d&&d.load&&(b.util.getScript=c)})();function q(a){a||(a={});var b=+(new Date()),c=a.duration||500,d=b+c,e,f,g=a.onChange||function(){},h=a.easing||function(a){return-Math.cos(a*Math.PI)/2+0.5},i="startValue"in a?a.startValue:0,j="endValue"in a?a.endValue:100,k=i>j;a.onStart&&a.onStart();var l=setInterval(function(){e=+(new Date());f=e>d?1:(e-b)/c;g(k?i-(i-j)*h(f):i+(j-i)*h(f));if(e>d){clearInterval(l);a.onComplete&&a.onComplete()}},10)}b.util.getById=k;b.util.toArray=l;b.util.makeElement=m;b.util.addClass=n;b.util.wrapElement=o;b.util.getElementOffset=p;b.util.animate=q;(function(){function a(a,b){return a+(/\?/.test(a)?"&":"?")+b}var c=(function(){var a=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest()}];for(var b=a.length;b--;)try{var c=a[b]();if(c)return a[b]}catch(a){}})();function d(){}function e(b,e){e||(e={});var f=e.method?e.method.toUpperCase():"GET",g=e.onComplete||function(){},h=c(),i;h.onreadystatechange=function(){if(h.readyState===4){g(h);h.onreadystatechange=d}};if(f==="GET"){i=null;typeof e.parameters=="string"&&(b=a(b,e.parameters))}h.open(f,b,true);(f==="POST"||f==="PUT")&&h.setRequestHeader("Content-Type","application/x-www-form-urlencoded");h.send(i);return h}b.util.request=e})()})(this);(function(){var a=this.fabric||(this.fabric={}),b=a.util.object.extend,c=a.util.string.capitalize,d=a.util.object.clone,e={cx:"left",x:"left",cy:"top",y:"top",r:"radius","fill-opacity":"opacity","fill-rule":"fillRule","stroke-width":"strokeWidth",transform:"transformMatrix"};function f(c,d){if(!c)return;var f,g,h={};c.parentNode&&/^g$/i.test(c.parentNode.nodeName)&&(h=a.parseAttributes(c.parentNode,d));var i=d.reduce(function(b,d){f=c.getAttribute(d);g=parseFloat(f);if(f){(d==="fill"||d==="stroke")&&f==="none"&&(f="");d==="fill-rule"&&(f=f==="evenodd"?"destination-over":f);d==="transform"&&(f=a.parseTransformAttribute(f));d in e&&(d=e[d]);b[d]=isNaN(g)?f:g}return b},{});i=b(a.parseStyleAttribute(c),i);return b(h,i)}a.parseTransformAttribute=(function(){function a(a,b){var c=b[0];a[0]=Math.cos(c);a[1]=Math.sin(c);a[2]=-Math.sin(c);a[3]=Math.cos(c)}function b(a,b){var c=b[0],d=b.length===2?b[1]:b[0];a[0]=c;a[3]=d}function c(a,b){a[2]=b[0]}function d(a,b){a[1]=b[0]}function e(a,b){a[4]=b[0];b.length===2&&(a[5]=b[1])}var f=[1,0,0,1,0,0],g="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)",h="(?:\\s+,?\\s*|,\\s*)",i="(?:(skewX)\\s*\\(\\s*("+g+")\\s*\\))",j="(?:(skewY)\\s*\\(\\s*("+g+")\\s*\\))",k="(?:(rotate)\\s*\\(\\s*("+g+")(?:"+h+"("+g+")"+h+"("+g+"))?\\s*\\))",l="(?:(scale)\\s*\\(\\s*("+g+")(?:"+h+"("+g+"))?\\s*\\))",m="(?:(translate)\\s*\\(\\s*("+g+")(?:"+h+"("+g+"))?\\s*\\))",n="(?:(matrix)\\s*\\(\\s*("+g+")"+h+"("+g+")"+h+"("+g+")"+h+"("+g+")"+h+"("+g+")"+h+"("+g+")"+"\\s*\\))",o="(?:"+n+"|"+m+"|"+l+"|"+k+"|"+i+"|"+j+")",p="(?:"+o+"(?:"+h+o+")*"+")",q="^\\s*(?:"+p+"?)\\s*$",r=new RegExp(q),s=new RegExp(o);return function(g){var h=f.concat();if(!g||g&&!r.test(g))return h;g.replace(s,function(f){var g=(new RegExp(o)).exec(f).filter(function(a){return a!==""&&a!=null}),i=g[1],j=g.slice(2).map(parseFloat);switch(i){case"translate":e(h,j);break;case"rotate":a(h,j);break;case"scale":b(h,j);break;case"skewX":c(h,j);break;case"skewY":d(h,j);break;case"matrix":h=j;break}});return h}})();function g(a){if(!a)return null;a=a.trim().split(/\s+/);var b=a.reduce(function(a,b){b=b.split(",");a.push({x:parseFloat(b[0]),y:parseFloat(b[1])});return a},[]);if(b.length%2!==0)return null;return b}function h(a){var b={},c=a.getAttribute("style");if(c)if(typeof c=="string"){c=c.split(";");c.pop();b=c.reduce(function(a,b){var c=b.split(":"),d=c[0].trim(),e=c[1].trim();a[d]=e;return a},{})}else for(var d in c)typeof c[d]!=="undefined"&&(b[d]=c[d]);return b}function i(b,d){var e=b.map(function(b){var e=a[c(b.tagName)];if(e&&e.fromElement)try{return e.fromElement(b,d)}catch(a){console.log(a.message||a)}});e=e.filter(function(a){return a!=null});return e}a.parseSVGDocument=(function(){var b=/^(path|circle|polygon|polyline|ellipse|rect|line)$/,c="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)",e=new RegExp("^\\s*("+c+"+)\\s*,?"+"\\s*("+c+"+)\\s*,?"+"\\s*("+c+"+)\\s*,?"+"\\s*("+c+"+)\\s*"+"$");function f(a,b){while(a&&(a=a.parentNode)){if(a.nodeName===b)return true}return false}return function(c,g){if(!c)return;var h=a.util.toArray(c.getElementsByTagName("*")),i=h.filter(function(a){return b.test(a.tagName)&&!f(a,"pattern")});if(!i||i&&!i.length)return;var j=c.getAttribute("viewBox"),k=c.getAttribute("width"),l=c.getAttribute("height"),m=null,n=null,o,p;if(j&&(j=j.match(e))){o=parseInt(j[1],10);p=parseInt(j[2],10);m=parseInt(j[3],10);n=parseInt(j[4],10)}m=k?parseFloat(k):m;n=l?parseFloat(l):n;var q={width:m,height:n},i=a.parseElements(i,d(q));if(!i||i&&!i.length)return;g&&g(i,q)}})();b(a,{parseAttributes:f,parseElements:i,parseStyleAttribute:h,parsePointsAttribute:g})})();(function(){var a=this.fabric||(this.fabric={});if(a.Point){console.warn("fabric.Point is already defined");return}function b(a,b){arguments.length>0&&this.init(a,b)}b.prototype={constructor:b,init:function(a,b){this.x=a;this.y=b},add:function(a){return new b(this.x+a.x,this.y+a.y)},addEquals:function(a){this.x+=a.x;this.y+=a.y;return this},scalarAdd:function(a){return new b(this.x+a,this.y+a)},scalarAddEquals:function(a){this.x+=a;this.y+=a;return this},subtract:function(a){return new b(this.x-a.x,this.y-a.y)},subtractEquals:function(a){this.x-=a.x;this.y-=a.y;return this},scalarSubtract:function(a){return new b(this.x-a,this.y-a)},scalarSubtractEquals:function(a){this.x-=a;this.y-=a;return this},multiply:function(a){return new b(this.x*a,this.y*a)},multiplyEquals:function(a){this.x*=a;this.y*=a;return this},divide:function(a){return new b(this.x/a,this.y/a)},divideEquals:function(a){this.x/=a;this.y/=a;return this},eq:function(a){return this.x==a.x&&this.y==a.y},lt:function(a){return this.xa.x&&this.y>a.y},gte:function(a){return this.x>=a.x&&this.y>=a.y},lerp:function(a,c){return new b(this.x+(a.x-this.x)*c,this.y+(a.y-this.y)*c)},distanceFrom:function(a){var b=this.x-a.x,c=this.y-a.y;return Math.sqrt(b*b+c*c)},min:function(a){return new b(Math.min(this.x,a.x),Math.min(this.y,a.y))},max:function(a){return new b(Math.max(this.x,a.x),Math.max(this.y,a.y))},toString:function(){return this.x+","+this.y},setXY:function(a,b){this.x=a;this.y=b},setFromPoint:function(a){this.x=a.x;this.y=a.y},swap:function(a){var b=this.x,c=this.y;this.x=a.x;this.y=a.y;a.x=b;a.y=c}};a.Point=b})();(function(){var a=this,b=a.fabric||(a.fabric={});if(b.Intersection){console.warn("fabric.Intersection is already defined");return}function c(a){arguments.length>0&&this.init(a)}c.prototype.init=function(a){this.status=a;this.points=[]};c.prototype.appendPoint=function(a){this.points.push(a)};c.prototype.appendPoints=function(a){this.points=this.points.concat(a)};c.intersectLineLine=function(a,d,e,f){var g,h=(f.x-e.x)*(a.y-e.y)-(f.y-e.y)*(a.x-e.x),i=(d.x-a.x)*(a.y-e.y)-(d.y-a.y)*(a.x-e.x),j=(f.y-e.y)*(d.x-a.x)-(f.x-e.x)*(d.y-a.y);if(j!=0){var k=h/j,l=i/j;if(0<=k&&k<=1&&0<=l&&l<=1){g=new c("Intersection");g.points.push(new b.Point(a.x+k*(d.x-a.x),a.y+k*(d.y-a.y)))}else g=new c("No Intersection")}else h==0||i==0?g=new c("Coincident"):g=new c("Parallel");return g};c.intersectLinePolygon=function(a,b,d){var e=new c("No Intersection"),f=d.length;for(var g=0;g0&&(e.status="Intersection");return e};c.intersectPolygonPolygon=function(a,b){var d=new c("No Intersection"),e=a.length;for(var f=0;f0&&(d.status="Intersection");return d};c.intersectPolygonRectangle=function(a,d,e){var f=d.min(e),g=d.max(e),h=new b.Point(g.x,f.y),i=new b.Point(f.x,g.y),j=c.intersectLinePolygon(f,h,a),k=c.intersectLinePolygon(h,g,a),l=c.intersectLinePolygon(g,i,a),m=c.intersectLinePolygon(i,f,a),n=new c("No Intersection");n.appendPoints(j.points);n.appendPoints(k.points);n.appendPoints(l.points);n.appendPoints(m.points);n.points.length>0&&(n.status="Intersection");return n};b.Intersection=c})();(function(){var a=this.fabric||(this.fabric={});if(a.Color){console.warn("fabric.Color is already defined.");return}a.Color=b;function b(a){a?this._tryParsingColor(a):this.setSource([0,0,0,1])}b.prototype._tryParsingColor=function(a){var c=b.sourceFromHex(a);c||(c=b.sourceFromRgb(a));c&&this.setSource(c)};b.prototype.getSource=function(){return this._source};b.prototype.setSource=function(a){this._source=a};b.prototype.toRgb=function(){var a=this.getSource();return"rgb("+a[0]+","+a[1]+","+a[2]+")"};b.prototype.toRgba=function(){var a=this.getSource();return"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")"};b.prototype.toHex=function(){var a=this.getSource(),b=a[0].toString(16);b=b.length==1?"0"+b:b;var c=a[1].toString(16);c=c.length==1?"0"+c:c;var d=a[2].toString(16);d=d.length==1?"0"+d:d;return b.toUpperCase()+c.toUpperCase()+d.toUpperCase()};b.prototype.getAlpha=function(){return this.getSource()[3]};b.prototype.setAlpha=function(a){var b=this.getSource();b[3]=a;this.setSource(b);return this};b.prototype.toGrayscale=function(){var a=this.getSource(),b=parseInt((a[0]*0.3+a[1]*0.59+a[2]*0.11).toFixed(0),10),c=a[3];this.setSource([b,b,b,c]);return this};b.prototype.toBlackWhite=function(a){var b=this.getSource(),c=(b[0]*0.3+b[1]*0.59+b[2]*0.11).toFixed(0),d=b[3],a=a||127;c=Number(c)0?0:-b),a.ey-(c>0?0:-c),d,e);this.contextTop.lineWidth=this.selectionLineWidth;this.contextTop.strokeStyle=this.selectionBorderColor;this.contextTop.strokeRect(a.ex+y-(b>0?0:d),a.ey+y-(c>0?0:e),d,e)},_findSelectedObjects:function(a){var b,c,d=[],e=this._groupSelector.ex,f=this._groupSelector.ey,h=e+this._groupSelector.left,i=f+this._groupSelector.top,j,k=new fabric.Point(u(e,h),u(f,i)),l=new fabric.Point(v(e,h),v(f,i));for(var m=0,n=this._objects.length;m1){var d=new fabric.Group(d);this.setActiveGroup(d);d.saveCoords();g("group:selected",{target:d})}this.renderAll()},add:function(){this._objects.push.apply(this._objects,arguments);this.renderAll();return this},insertAt:function(a,b){this._objects.splice(b,0,a);this.renderAll();return this},getObjects:function(){return this._objects},getContext:function(){return this.contextTop},clearContext:function(a){a.clearRect(0,0,this._config.width,this._config.height);return this},clear:function(){this._objects.length=0;this.clearContext(this.contextTop);this.clearContext(this.contextContainer);this.renderAll();return this},renderAll:function(a){var b=this._config.width,c=this._config.height,d=a?this.contextTop:this.contextContainer;this.clearContext(this.contextTop);a||this.clearContext(d);if(!B&&this.backgroundColor==="transparent")var e=true;e||(d.fillStyle=this.backgroundColor);d.fillRect(0,0,b,c);var f=this._objects.length,g=this.getActiveGroup(),h=new Date();if(f)for(var i=0;i1)var f=new fabric.PathGroup(b,a);else var f=b[0];f.setSourcePath(j);if(!(f instanceof fabric.PathGroup)){d(f,a);typeof a.angle!=="undefined"&&f.setAngle(a.angle)}g(f,c)})},this)}catch(a){console.log(a.message)}},loadImageFromURL:(function(){var a={};return function(b,d){var e=this;function f(){var e=c.getElementById(a[b]);e.width&&e.height?d(new fabric.Image(e)):setTimeout(f,50)}if(a[b])f();else{var g=new Image();g.onload=function(){g.onload=null;e._resizeImageToFit(g);var a=new fabric.Image(g);d(a)};g.className="canvas-img-clone";g.src=b;this.shouldCacheImages&&(a[b]=Element.identify(g));c.body.appendChild(g)}}})(),loadSVGFromURL:function(a,b){var c=this;a=a.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(a,function(f){f?c.cache.get(a,function(a){var d=c._enlivenCachedObject(a);b(d.objects,d.options)}):new Ajax.Request(a,{method:"get",onComplete:d,onFailure:e})});function d(d){var e=d.responseXML;if(!e)return;var f=e.documentElement;if(!f)return;fabric.parseSVGDocument(f,function(d,e){c.cache.set(a,{objects:d.invoke("toObject"),options:e});b(d,e)})}function e(){console.log("ERROR!")}},_enlivenCachedObject:function(a){var b=a.objects,c=a.options;b=b.map(function(a){return fabric[e(a.type)].fromObject(a)});return{objects:b,options:c}},remove:function(a){l(this._objects,a);this.renderAll();return a},fxRemove:function(a,b){var c=this;a.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){c.remove(a);typeof b==="function"&&b()}});return this},sendToBack:function(a){l(this._objects,a);this._objects.unshift(a);return this.renderAll()},bringToFront:function(a){l(this._objects,a);this._objects.push(a);return this.renderAll()},sendBackwards:function(a){var b=this._objects.indexOf(a),c=b;if(b!==0){for(var d=b-1;d>=0;--d){if(a.intersectsWithObject(this._objects[d])){c=d;break}}l(this._objects,a);this._objects.splice(c,0,a)}return this.renderAll()},bringForward:function(a){var b=this.getObjects(),c=b.indexOf(a),d=c;if(c!==b.length-1){for(var e=c+1,f=this._objects.length;e"};d(fabric.Element,{EMPTY_JSON:"{\"objects\": [], \"background\": \"white\"}",toGrayscale:function(a){var b=a.getContext("2d"),c=b.getImageData(0,0,a.width,a.height),d=c.data,e=c.width,f=c.height,g,h;for(i=0;i1?b.apply(this,h.call(arguments,1)):b.call(this)},initialize:function(a){this.setOptions(a);this._importProperties();this.originalState={};this.setCoords();this.saveState()},setOptions:function(a){this.options=c(this._getOptions(),a)},_getOptions:function(){return c(d(this._getSuperOptions()),this.options)},_getSuperOptions:function(){var a=this.constructor;if(a){var b=a.superclass;if(b){var c=b.prototype;if(c&&typeof c._getOptions=="function")return c._getOptions()}}return{}},_importProperties:function(){this.stateProperties.forEach(function(a){a==="angle"?this.setAngle(this.options[a]):this[a]=this.options[a]},this)},transform:function(a){a.globalAlpha=this.opacity;a.translate(this.left,this.top);a.rotate(this.theta);a.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toObject:function(){var a={type:this.type,left:e(this.left,this.NUM_FRACTION_DIGITS),top:e(this.top,this.NUM_FRACTION_DIGITS),width:e(this.width,this.NUM_FRACTION_DIGITS),height:e(this.height,this.NUM_FRACTION_DIGITS),fill:this.fill,overlayFill:this.overlayFill,stroke:this.stroke,strokeWidth:this.strokeWidth,scaleX:e(this.scaleX,this.NUM_FRACTION_DIGITS),scaleY:e(this.scaleY,this.NUM_FRACTION_DIGITS),angle:e(this.getAngle(),this.NUM_FRACTION_DIGITS),flipX:this.flipX,flipY:this.flipY,opacity:e(this.opacity,this.NUM_FRACTION_DIGITS)};this.includeDefaultValues||(a=this._removeDefaultValues(a));return a},toDatalessObject:function(){return this.toObject()},_removeDefaultValues:function(a){var c=b.Object.prototype.options;this.stateProperties.forEach(function(b){a[b]===c[b]&&delete a[b]});return a},isActive:function(){return!(!this.active)},setActive:function(a){this.active=!(!a);return this},toString:function(){return"#"},set:function(a,b){var c=(a==="scaleX"||a==="scaleY")&&ba.x&&f.xa.y&&g.y=b&&k.d.y>=b)continue;if(k.o.x==k.d.x&&k.o.x>=a){h=k.o.x;i=b}else{d=0;e=(k.d.y-k.o.y)/(k.d.x-k.o.x);f=b-d*a;g=k.o.y-e*k.o.x;h=-(f-g)/(d-e);i=f+d*h}h>=a&&(j+=1);if(j==2)break}return j},_getImageLines:function(a,b){return{topline:{o:a.tl,d:a.tr},rightline:{o:a.tr,d:a.br},bottomline:{o:a.br,d:a.bl},leftline:{o:a.bl,d:a.tl}}},_setCornerCoords:function(){var a=this.oCoords,b=this.theta,c=this.cornersize*Math.cos(b),d=this.cornersize*Math.sin(b),e=this.cornersize/2,f=e-d,g=e,h;a.tl.x-=f;a.tl.y-=g;a.tl.corner={tl:{x:a.tl.x,y:a.tl.y},tr:{x:a.tl.x+c,y:a.tl.y+d},bl:{x:a.tl.x-d,y:a.tl.y+c}};a.tl.corner.br={x:a.tl.corner.tr.x-d,y:a.tl.corner.tr.y+c};a.tl.x+=f;a.tl.y+=g;a.tr.x+=e;a.tr.y-=e;a.tr.corner={tl:{x:a.tr.x-c,y:a.tr.y-d},tr:{x:a.tr.x,y:a.tr.y},br:{x:a.tr.x-d,y:a.tr.y+c}};a.tr.corner.bl={x:a.tr.corner.tl.x-d,y:a.tr.corner.tl.y+c};a.tr.x-=e;a.tr.y+=e;a.bl.x-=e;a.bl.y+=e;a.bl.corner={tl:{x:a.bl.x+d,y:a.bl.y-c},bl:{x:a.bl.x,y:a.bl.y},br:{x:a.bl.x+c,y:a.bl.y+d}};a.bl.corner.tr={x:a.bl.corner.br.x+d,y:a.bl.corner.br.y-c};a.bl.x+=e;a.bl.y-=e;a.br.x+=e;a.br.y+=e;a.br.corner={tr:{x:a.br.x+d,y:a.br.y-c},bl:{x:a.br.x-c,y:a.br.y-d},br:{x:a.br.x,y:a.br.y}};a.br.corner.tl={x:a.br.corner.bl.x+d,y:a.br.corner.bl.y-c};a.br.x-=e;a.br.y-=e;a.ml.x-=e;a.ml.y-=e;a.ml.corner={tl:{x:a.ml.x,y:a.ml.y},tr:{x:a.ml.x+c,y:a.ml.y+d},bl:{x:a.ml.x-d,y:a.ml.y+c}};a.ml.corner.br={x:a.ml.corner.tr.x-d,y:a.ml.corner.tr.y+c};a.ml.x+=e;a.ml.y+=e;a.mt.x-=e;a.mt.y-=e;a.mt.corner={tl:{x:a.mt.x,y:a.mt.y},tr:{x:a.mt.x+c,y:a.mt.y+d},bl:{x:a.mt.x-d,y:a.mt.y+c}};a.mt.corner.br={x:a.mt.corner.tr.x-d,y:a.mt.corner.tr.y+c};a.mt.x+=e;a.mt.y+=e;a.mr.x-=e;a.mr.y-=e;a.mr.corner={tl:{x:a.mr.x,y:a.mr.y},tr:{x:a.mr.x+c,y:a.mr.y+d},bl:{x:a.mr.x-d,y:a.mr.y+c}};a.mr.corner.br={x:a.mr.corner.tr.x-d,y:a.mr.corner.tr.y+c};a.mr.x+=e;a.mr.y+=e;a.mb.x-=e;a.mb.y-=e;a.mb.corner={tl:{x:a.mb.x,y:a.mb.y},tr:{x:a.mb.x+c,y:a.mb.y+d},bl:{x:a.mb.x-d,y:a.mb.y+c}};a.mb.corner.br={x:a.mb.corner.tr.x-d,y:a.mb.corner.tr.y+c};a.mb.x+=e;a.mb.y+=e;h=a.mb.corner;h.tl.x-=e;h.tl.y-=e;h.tr.x-=e;h.tr.y-=e;h.br.x-=e;h.br.y-=e;h.bl.x-=e;h.bl.y-=e},toGrayscale:function(){var a=this.get("fill");a&&this.set("overlayFill",(new b.Color(a)).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 a=this._getAngleValueForStraighten();this.setAngle(a);return this},fxStraighten:function(a){a=a||{};var c=function(){},d=a.onComplete||c,e=a.onChange||c,f=this;b.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(a){f.setAngle(a);e()},onComplete:function(){f.setCoords();d()},onStart:function(){f.setActive(false)}});return this},fxRemove:function(a){a||(a={});var c=function(){},d=a.onComplete||c,e=a.onChange||c,f=this;b.util.animate({startValue:this.get("opacity"),endValue:0,duration:this.FX_DURATION,onChange:function(a){f.set("opacity",a);e()},onComplete:d,onStart:function(){f.setActive(false)}});return this},_getAngleValueForStraighten:function(){var a=this.get("angle");{if(a>-225&&a<=-135)return-180;if(a>-135&&a<=-45)return-90;if(a>-45&&a<=45)return 0;if(a>45&&a<=135)return 90;if(a>135&&a<=225)return 180;if(a>225&&a<=315)return 270;if(a>315)return 360}return 0},toJSON:function(){return this.toObject()}});b.Object.prototype.rotate=b.Object.prototype.setAngle})();(function(){var a=this.fabric||(this.fabric={}),b=a.util.object.extend;if(a.Line)return;a.Line=a.util.createClass(a.Object,{type:"line",initialize:function(a,b){a||(a=[0,0,0,0]);this.callSuper("initialize",b);this.set("x1",a[0]);this.set("y1",a[1]);this.set("x2",a[2]);this.set("y2",a[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(a){a.beginPath();a.moveTo(-this.width/2,-this.height/2);a.lineTo(this.width/2,this.height/2);var b=a.strokeStyle;a.strokeStyle=a.fillStyle;a.stroke();a.strokeStyle=b},complexity:function(){return 1},toObject:function(){return b(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,d){var e=a.parseAttributes(c,a.Element.ATTRIBUTE_NAMES),f=[e.x1||0,e.y1||0,e.x2||0,e.y2||0];return new a.Line(f,b(e,d))};a.Line.fromObject=function(b){var c=[b.x1,b.y1,b.x2,b.y2];return new a.Line(c,b)}})();(function(){var a=this.fabric||(this.fabric={}),b=Math.PI*2,c=a.util.object.extend;if(a.Circle){console.warn("fabric.Circle is already defined.");return}a.Circle=a.util.createClass(a.Object,{type:"circle",initialize:function(a){a=a||{};this.set("radius",a.radius||0);this.callSuper("initialize",a);var b=this.get("radius")*2*this.get("scaleX");this.set("width",b).set("height",b)},toObject:function(){return c(this.callSuper("toObject"),{radius:this.get("radius")})},_render:function(a){a.beginPath();a.arc(0,0,this.radius,0,b,false);a.closePath();this.fill&&a.fill();this.stroke&&a.stroke()},complexity:function(){return 1}});a.Circle.ATTRIBUTE_NAMES="cx cy r fill fill-opacity stroke stroke-width transform".split(" ");a.Circle.fromElement=function(b,e){var f=a.parseAttributes(b,a.Circle.ATTRIBUTE_NAMES);if(!d(f))throw Error("value of `r` attribute is required and can not be negative");return new a.Circle(c(f,e))};function d(a){return"radius"in a&&a.radius>0}a.Circle.fromObject=function(b){return new a.Circle(b)}})();(function(){var a=this.fabric||(this.fabric={});if(a.Triangle)return;a.Triangle=a.util.createClass(a.Object,{type:"triangle",initialize:function(a){a=a||{};this.callSuper("initialize",a);this.set("width",a.width||100).set("height",a.height||100)},_render:function(a){var b=this.width/2,c=this.height/2;a.beginPath();a.moveTo(-b,c);a.lineTo(0,-c);a.lineTo(b,c);a.closePath();this.fill&&a.fill();this.stroke&&a.stroke()},complexity:function(){return 1}});a.Triangle.fromObject=function(b){return new a.Triangle(b)}})();(function(){var a=this.fabric||(this.fabric={}),b=a.util.object.extend;if(a.Ellipse){console.warn("fabric.Ellipse is already defined.");return}a.Ellipse=a.util.createClass(a.Object,{type:"ellipse",initialize:function(a){a=a||{};this.callSuper("initialize",a);this.set("rx",a.rx||0);this.set("ry",a.ry||0);this.set("width",this.get("rx")*2);this.set("height",this.get("ry")*2)},toObject:function(){return b(this.callSuper("toObject"),{rx:this.get("rx"),ry:this.get("ry")})},render:function(a,b){if(this.rx===0||this.ry===0)return;return this.callSuper("render",a,b)},_render:function(a){a.beginPath();a.save();a.transform(1,0,0,this.ry/this.rx,0,0);a.arc(0,0,this.rx,0,Math.PI*2,false);a.restore();this.stroke&&a.stroke();this.fill&&a.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,d){var e=a.parseAttributes(c,a.Ellipse.ATTRIBUTE_NAMES);return new a.Ellipse(b(e,d))};a.Ellipse.fromObject=function(b){return new a.Ellipse(b)}})();(function(){var a=this.fabric||(this.fabric={});if(a.Rect)return;a.Rect=a.util.createClass(a.Object,{type:"rect",options:{rx:0,ry:0},initialize:function(a){this.callSuper("initialize",a);this._initRxRy()},_initRxRy:function(){this.options.rx&&!this.options.ry?this.options.ry=this.options.rx:this.options.ry&&!this.options.rx&&(this.options.rx=this.options.ry)},_render:function(a){var b=this.options.rx||0,c=this.options.ry||0,d=-this.width/2,e=-this.height/2,f=this.width,g=this.height;a.beginPath();a.moveTo(d+b,e);a.lineTo(d+f-b,e);a.bezierCurveTo(d+f,e,d+f,e+c,d+f,e+c);a.lineTo(d+f,e+g-c);a.bezierCurveTo(d+f,e+g,d+f-b,e+g,d+f-b,e+g);a.lineTo(d+b,e+g);a.bezierCurveTo(d,e+g,d,e+g-c,d,e+g-c);a.lineTo(d,e+c);a.bezierCurveTo(d,e,d+b,e,d+b,e);a.closePath();this.fill&&a.fill();this.stroke&&a.stroke()},_normalizeLeftTopProperties:function(a){a.left&&this.set("left",a.left+this.getWidth()/2);a.top&&this.set("top",a.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(a){a.left=a.left||0;a.top=a.top||0;return a}a.Rect.fromElement=function(c,d){if(!c)return null;var e=a.parseAttributes(c,a.Rect.ATTRIBUTE_NAMES);e=b(e);var f=new a.Rect(a.util.object.extend(d||{},e));f._normalizeLeftTopProperties(e);return f};a.Rect.fromObject=function(b){return new a.Rect(b)}})();(function(){var a=this.fabric||(this.fabric={});if(a.Polyline){console.warn("fabric.Polyline is already defined");return}a.Polyline=a.util.createClass(a.Object,{type:"polyline",initialize:function(a,b){b=b||{};this.set("points",a);this.callSuper("initialize",b);this._calcDimensions()},_calcDimensions:function(){return a.Polygon.prototype._calcDimensions.call(this)},_toOrigin:function(){return a.Polygon.prototype._toOrigin.call(this)},toObject:function(){return a.Polygon.prototype.toObject.call(this)},_render:function(a){var b;a.beginPath();for(var c=0,d=this.points.length;c"},toObject:function(){var a=d(this.callSuper("toObject"),{path:this.path});this.sourcePath&&(a.sourcePath=this.sourcePath);this.transformMatrix&&(a.transformMatrix=this.transformMatrix);return a},toDatalessObject:function(){var a=this.toObject();this.sourcePath&&(a.path=this.sourcePath);delete a.sourcePath;return a},complexity:function(){return this.path.length},set:function(a,b){return this.callSuper("set",a,b)},_parsePath:function(){var a=[],b,c;for(var d=0,e=this.path.length;d"},isSameColor:function(){var a=this.getObjects()[0].get("fill");return this.getObjects().every(function(b){return b.get("fill")===a})},complexity:function(){return this.paths.reduce(function(a,b){return a+(b&&b.complexity?b.complexity():0)},0)},toGrayscale:function(){var a=this.paths.length;while(a--)this.paths[a].toGrayscale();return this},getObjects:function(){return this.paths}});function h(b){for(var c=0,d=b.length;c"},getObjects:function(){return this.objects},add:function(a){this._restoreObjectsState();this.objects.push(a);a.setActive(true);this._calcBounds();this._updateObjectsCoords();return this},remove:function(a){this._restoreObjectsState();f(this.objects,a);a.setActive(false);this._calcBounds();this._updateObjectsCoords();return this},size:function(){return this.getObjects().length},set:function(a,b){if(typeof b=="function")this.set(a,b(this[a]));else if(a==="fill"||a==="opacity"){var c=this.objects.length;this[a]=b;while(c--)this.objects[c].set(a,b)}else this[a]=b;return this},contains:function(a){return this.objects.indexOf(a)>-1},toObject:function(){return b(this.callSuper("toObject"),{objects:e(this.objects,"clone")})},render:function(a){a.save();this.transform(a);var b=Math.max(this.scaleX,this.scaleY);for(var c=0,d=this.objects.length,e;e=this.objects[c];c++){var f=e.borderScaleFactor;e.borderScaleFactor=b;e.render(a);e.borderScaleFactor=f}this.hideBorders||this.drawBorders(a);this.hideCorners||this.drawCorners(a);a.restore();this.setCoords()},item:function(a){return this.getObjects()[a]},complexity:function(){return this.getObjects().reduce(function(a,b){a+=typeof b.complexity=="function"?b.complexity():0;return a},0)},_restoreObjectsState:function(){this.objects.forEach(this._restoreObjectState,this);return this},_restoreObjectState:function(a){var b=this.get("left"),c=this.get("top"),d=this.getAngle()*(Math.PI/180),e=a.get("originalLeft"),f=a.get("originalTop"),g=Math.cos(d)*a.get("top")+Math.sin(d)*a.get("left"),h=-Math.sin(d)*a.get("top")+Math.cos(d)*a.get("left");a.setAngle(a.getAngle()+this.getAngle());a.set("left",b+h*this.get("scaleX"));a.set("top",c+g*this.get("scaleY"));a.set("scaleX",a.get("scaleX")*this.get("scaleX"));a.set("scaleY",a.get("scaleY")*this.get("scaleY"));a.setCoords();a.hideCorners=false;a.setActive(false);a.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(a){a.setCoords()});return this},activateAllObjects:function(){return this.setActive(true)},setActive:function(a){this.forEachObject(function(b){b.setActive(a)});return this},forEachObject:function(a,b){var c=this.getObjects(),d=c.length;while(d--)a.call(b,c[d],d,c);return this},_setOpacityIfSame:function(){var a=this.getObjects(),b=a[0]?a[0].get("opacity"):1,c=a.every(function(a){return a.get("opacity")===b});c&&(this.opacity=b)},_calcBounds:function(){var a=[],b=[],e,f,g,h,i,j,k,l=0,m=this.objects.length;for(;la.x&&e-ca.y},toGrayscale:function(){var a=this.objects.length;while(a--)this.objects[a].toGrayscale()}});a.Group.fromObject=function(b){return new a.Group(b.objects,b)}})();(function(){var a=this.fabric||(this.fabric={}),b=a.util.object.extend,c=a.util.object.clone;if(a.Text){console.warn("fabric.Text is already defined");return}if(!a.Object){console.warn("fabric.Text requires fabric.Object");return}a.Text=a.util.createClass(a.Object,{options:{top:10,left:10,fontsize:20,fontweight:100,fontfamily:"Modernist_One_400",path:null},type:"text",initialize:function(a,c){this.originalState={};this.initStateProperties();this.text=a;this.setOptions(c);b(this,this.options);this.theta=this.angle*(Math.PI/180);this.width=this.getWidth();this.setCoords()},initStateProperties:function(){var a;if((a=this.constructor)&&(a=a.superclass)&&(a=a.prototype)&&(a=a.stateProperties)&&a.clone){this.stateProperties=a.clone();this.stateProperties.push("fontfamily","fontweight","path")}},toString:function(){return"#"},_render:function(a){var b=Cufon.textOptions||(Cufon.textOptions={});b.left=this.left;b.top=this.top;b.context=a;b.color=this.fill;var c=this._initDummyElement();this.transform(a);Cufon.replaceElement(c,{separate:"none",fontFamily:this.fontfamily});this.width=b.width;this.height=b.height},_initDummyElement:function(){var a=document.createElement("div");a.innerHTML=this.text;a.style.fontSize="40px";a.style.fontWeight="400";a.style.fontStyle="normal";a.style.letterSpacing="normal";a.style.color="#000000";a.style.fontWeight="600";a.style.fontFamily="Verdana";return a},render:function(a){a.save();this._render(a);if(this.active){this.drawBorders(a);this.drawCorners(a)}a.restore()},toObject:function(){return b(this.callSuper("toObject"),{text:this.text,fontsize:this.fontsize,fontweight:this.fontweight,fontfamily:this.fontfamily,path:this.path})},setColor:function(a){this.set("fill",a);return this},setFontsize:function(a){this.set("fontsize",a);this.setCoords();return this},getText:function(){return this.text},setText:function(a){this.set("text",a);this.setCoords();return this},set:function(a,b){this[a]=b;a==="fontfamily"&&(this.path=this.path.replace(/(.*?)([^\\x2f]*)(\.font\.js)/,"$1"+b+"$3"));return this}});a.Text.fromObject=function(b){return new a.Text(b.text,c(b))};a.Text.fromElement=function(a){}})();(function(){var a=this,b=fabric.util.object.extend;a.fabric||(a.fabric={});if(a.fabric.Image){console.warn("fabric.Image is already defined.");return}if(!fabric.Object){console.warn("fabric.Object is required for fabric.Image initialization");return}fabric.Image=fabric.util.createClass(fabric.Object,{maxwidth:null,maxheight:null,active:false,bordervisibility:false,cornervisibility:false,type:"image",__isGrayscaled:false,initialize:function(a,b){this.callSuper("initialize",b);this._initElement(a);this._initConfig(b||{})},getElement:function(){return this._element},setElement:function(a){this._element=a;return this},getNormalizedSize:function(a,b,c){if(c&&b&&(a.width>a.height&&a.width/a.heighta.width||a.height>c)){normalizedWidth=~(~(a.width*c/a.height));normalizedHeight=c}else if(b&&b"},clone:function(a){this.constructor.fromObject(this.toObject(),a)},toGrayscale:function(a){if(this.__isGrayscaled)return;var b=this.getElement(),c=document.createElement("canvas"),d=document.createElement("img"),e=this;c.width=b.width;c.height=b.height;c.getContext("2d").drawImage(b,0,0);fabric.Element.toGrayscale(c);d.onload=function(){e.setElement(d);a&&a();d.onload=c=b=imageData=null};d.width=b.width;d.height=b.height;d.src=c.toDataURL("image/png");this.__isGrayscaled=true;return this},_render:function(a){var b=this.getOriginalSize();a.drawImage(this.getElement(),-b.width/2,-b.height/2,b.width,b.height)},_adjustWidthHeightToBorders:function(a){if(a){this.currentBorder=this.borderwidth;this.width+=2*this.currentBorder;this.height+=2*this.currentBorder}else this.currentBorder=0},_resetWidthHeight:function(){var a=this.getElement();this.set("width",a.width);this.set("height",a.height)},_initElement:function(a){this.setElement(fabric.util.getById(a));fabric.util.addClass(this.getElement(),fabric.Image.CSS_CANVAS)},_initConfig:function(a){this.setOptions(a);this._setBorder();this._setWidthHeight(a)},_setBorder:function(){this.bordervisibility?this.currentBorder=this.borderwidth:this.currentBorder=0},_setWidthHeight:function(a){var b=2*this.currentBorder;this.width=(this.getElement().width||0)+b;this.height=(this.getElement().height||0)+b},complexity:function(){return 1}});fabric.Image.CSS_CANVAS="canvas-img";fabric.Image.fromObject=function(a,b){var c=document.createElement("img"),d=a.src;a.width&&(c.width=a.width);a.height&&(c.height=a.height);c.onload=function(){b&&b(new fabric.Image(c,a));c=c.onload=null};c.src=d};fabric.Image.fromURL=function(a,b,c){var d=document.createElement("img");d.onload=function(){b&&b(new fabric.Image(d,c));d=d.onload=null};d.src=a}})() \ No newline at end of file diff --git a/dist/all.min-via-uglify.js.gz b/dist/all.min-via-uglify.js.gz deleted file mode 100644 index 5a1c43b8..00000000 Binary files a/dist/all.min-via-uglify.js.gz and /dev/null differ diff --git a/dist/all.min.js b/dist/all.min.js index 771edf79..77374de8 100644 --- a/dist/all.min.js +++ b/dist/all.min.js @@ -1,4 +1,4 @@ -var console=console||{log:function(){},warn:function(){}},fabric=fabric||{version:0.1};if(!this.JSON)this.JSON={}; +var fabric=fabric||{version:0.1};fabric.log=function(){};fabric.warn=function(){};if(typeof console!=="undefined"){if(typeof console.log!=="undefined"&&console.log.apply)fabric.log=function(){return console.log.apply(console,arguments)};if(typeof console.warn!=="undefined"&&console.warn.apply)fabric.warn=function(){return console.warn.apply(console,arguments)}}if(!this.JSON)this.JSON={}; (function(){function h(g){return g<10?"0"+g:g}function p(g){o.lastIndex=0;return o.test(g)?'"'+g.replace(o,function(m){var q=a[m];return typeof q==="string"?q:"\\u"+("0000"+m.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+g+'"'}function e(g,m){var q,r,u,v,A=d,w,s=m[g];if(s&&typeof s==="object"&&typeof s.toJSON==="function")s=s.toJSON(g);if(typeof b==="function")s=b.call(m,g,s);switch(typeof s){case "string":return p(s);case "number":return isFinite(s)?String(s):"null";case "boolean":case "null":return String(s); case "object":if(!s)return"null";d+=c;w=[];if(Object.prototype.toString.apply(s)==="[object Array]"){v=s.length;for(q=0;q-1;d=d.split(/\s+/);var a=[];if(c){c=0;for(var b=d.length;c0&&this.init(e,l)}var p=this.fabric||(this.fabric={});if(p.Point)console.warn("fabric.Point is already defined");else{h.prototype={constructor:h,init:function(e,l){this.x=e;this.y=l},add:function(e){return new h(this.x+e.x,this.y+e.y)},addEquals:function(e){this.x+=e.x;this.y+=e.y;return this},scalarAdd:function(e){return new h(this.x+e,this.y+e)},scalarAddEquals:function(e){this.x+=e;this.y+=e;return this},subtract:function(e){return new h(this.x-e.x, -this.y-e.y)},subtractEquals:function(e){this.x-=e.x;this.y-=e.y;return this},scalarSubtract:function(e){return new h(this.x-e,this.y-e)},scalarSubtractEquals:function(e){this.x-=e;this.y-=e;return this},multiply:function(e){return new h(this.x*e,this.y*e)},multiplyEquals:function(e){this.x*=e;this.y*=e;return this},divide:function(e){return new h(this.x/e,this.y/e)},divideEquals:function(e){this.x/=e;this.y/=e;return this},eq:function(e){return this.x==e.x&&this.y==e.y},lt:function(e){return this.x< -e.x&&this.ye.x&&this.y>e.y},gte:function(e){return this.x>=e.x&&this.y>=e.y},lerp:function(e,l){return new h(this.x+(e.x-this.x)*l,this.y+(e.y-this.y)*l)},distanceFrom:function(e){var l=this.x-e.x;e=this.y-e.y;return Math.sqrt(l*l+e*e)},min:function(e){return new h(Math.min(this.x,e.x),Math.min(this.y,e.y))},max:function(e){return new h(Math.max(this.x,e.x),Math.max(this.y,e.y))},toString:function(){return this.x+ -","+this.y},setXY:function(e,l){this.x=e;this.y=l},setFromPoint:function(e){this.x=e.x;this.y=e.y},swap:function(e){var l=this.x,o=this.y;this.x=e.x;this.y=e.y;e.x=l;e.y=o}};p.Point=h}})(); -(function(){function h(e){arguments.length>0&&this.init(e)}var p=this.fabric||(this.fabric={});if(p.Intersection)console.warn("fabric.Intersection is already defined");else{h.prototype.init=function(e){this.status=e;this.points=[]};h.prototype.appendPoint=function(e){this.points.push(e)};h.prototype.appendPoints=function(e){this.points=this.points.concat(e)};h.intersectLineLine=function(e,l,o,d){var c,a=(d.x-o.x)*(e.y-o.y)-(d.y-o.y)*(e.x-o.x);c=(l.x-e.x)*(e.y-o.y)-(l.y-e.y)*(e.x-o.x);o=(d.y-o.y)* -(l.x-e.x)-(d.x-o.x)*(l.y-e.y);if(o!=0){a=a/o;c=c/o;if(0<=a&&a<=1&&0<=c&&c<=1){c=new h("Intersection");c.points.push(new p.Point(e.x+a*(l.x-e.x),e.y+a*(l.y-e.y)))}else c=new h("No Intersection")}else c=a==0||c==0?new h("Coincident"):new h("Parallel");return c};h.intersectLinePolygon=function(e,l,o){for(var d=new h("No Intersection"),c=o.length,a=0;a0)d.status="Intersection";return d};h.intersectPolygonPolygon= +(function(){function h(e,l){arguments.length>0&&this.init(e,l)}var p=this.fabric||(this.fabric={});if(p.Point)p.warn("fabric.Point is already defined");else{h.prototype={constructor:h,init:function(e,l){this.x=e;this.y=l},add:function(e){return new h(this.x+e.x,this.y+e.y)},addEquals:function(e){this.x+=e.x;this.y+=e.y;return this},scalarAdd:function(e){return new h(this.x+e,this.y+e)},scalarAddEquals:function(e){this.x+=e;this.y+=e;return this},subtract:function(e){return new h(this.x-e.x,this.y- +e.y)},subtractEquals:function(e){this.x-=e.x;this.y-=e.y;return this},scalarSubtract:function(e){return new h(this.x-e,this.y-e)},scalarSubtractEquals:function(e){this.x-=e;this.y-=e;return this},multiply:function(e){return new h(this.x*e,this.y*e)},multiplyEquals:function(e){this.x*=e;this.y*=e;return this},divide:function(e){return new h(this.x/e,this.y/e)},divideEquals:function(e){this.x/=e;this.y/=e;return this},eq:function(e){return this.x==e.x&&this.y==e.y},lt:function(e){return this.xe.x&&this.y>e.y},gte:function(e){return this.x>=e.x&&this.y>=e.y},lerp:function(e,l){return new h(this.x+(e.x-this.x)*l,this.y+(e.y-this.y)*l)},distanceFrom:function(e){var l=this.x-e.x;e=this.y-e.y;return Math.sqrt(l*l+e*e)},min:function(e){return new h(Math.min(this.x,e.x),Math.min(this.y,e.y))},max:function(e){return new h(Math.max(this.x,e.x),Math.max(this.y,e.y))},toString:function(){return this.x+","+this.y}, +setXY:function(e,l){this.x=e;this.y=l},setFromPoint:function(e){this.x=e.x;this.y=e.y},swap:function(e){var l=this.x,o=this.y;this.x=e.x;this.y=e.y;e.x=l;e.y=o}};p.Point=h}})(); +(function(){function h(e){arguments.length>0&&this.init(e)}var p=this.fabric||(this.fabric={});if(p.Intersection)p.warn("fabric.Intersection is already defined");else{h.prototype.init=function(e){this.status=e;this.points=[]};h.prototype.appendPoint=function(e){this.points.push(e)};h.prototype.appendPoints=function(e){this.points=this.points.concat(e)};h.intersectLineLine=function(e,l,o,d){var c,a=(d.x-o.x)*(e.y-o.y)-(d.y-o.y)*(e.x-o.x);c=(l.x-e.x)*(e.y-o.y)-(l.y-e.y)*(e.x-o.x);o=(d.y-o.y)*(l.x-e.x)- +(d.x-o.x)*(l.y-e.y);if(o!=0){a=a/o;c=c/o;if(0<=a&&a<=1&&0<=c&&c<=1){c=new h("Intersection");c.points.push(new p.Point(e.x+a*(l.x-e.x),e.y+a*(l.y-e.y)))}else c=new h("No Intersection")}else c=a==0||c==0?new h("Coincident"):new h("Parallel");return c};h.intersectLinePolygon=function(e,l,o){for(var d=new h("No Intersection"),c=o.length,a=0;a0)d.status="Intersection";return d};h.intersectPolygonPolygon= function(e,l){for(var o=new h("No Intersection"),d=e.length,c=0;c0)o.status="Intersection";return o};h.intersectPolygonRectangle=function(e,l,o){var d=l.min(o),c=l.max(o);o=new p.Point(c.x,d.y);var a=new p.Point(d.x,c.y);l=h.intersectLinePolygon(d,o,e);o=h.intersectLinePolygon(o,c,e);c=h.intersectLinePolygon(c,a,e);e=h.intersectLinePolygon(a,d,e);d=new h("No Intersection");d.appendPoints(l.points); d.appendPoints(o.points);d.appendPoints(c.points);d.appendPoints(e.points);if(d.points.length>0)d.status="Intersection";return d};p.Intersection=h}})(); -(function(){function h(e){e?this._tryParsingColor(e):this.setSource([0,0,0,1])}var p=this.fabric||(this.fabric={});if(p.Color)console.warn("fabric.Color is already defined.");else{p.Color=h;h.prototype._tryParsingColor=function(e){var l=h.sourceFromHex(e);l||(l=h.sourceFromRgb(e));l&&this.setSource(l)};h.prototype.getSource=function(){return this._source};h.prototype.setSource=function(e){this._source=e};h.prototype.toRgb=function(){var e=this.getSource();return"rgb("+e[0]+","+e[1]+","+e[2]+")"}; -h.prototype.toRgba=function(){var e=this.getSource();return"rgba("+e[0]+","+e[1]+","+e[2]+","+e[3]+")"};h.prototype.toHex=function(){var e=this.getSource(),l=e[0].toString(16);l=l.length==1?"0"+l:l;var o=e[1].toString(16);o=o.length==1?"0"+o:o;e=e[2].toString(16);e=e.length==1?"0"+e:e;return l.toUpperCase()+o.toUpperCase()+e.toUpperCase()};h.prototype.getAlpha=function(){return this.getSource()[3]};h.prototype.setAlpha=function(e){var l=this.getSource();l[3]=e;this.setSource(l);return this};h.prototype.toGrayscale= +(function(){function h(e){e?this._tryParsingColor(e):this.setSource([0,0,0,1])}var p=this.fabric||(this.fabric={});if(p.Color)p.warn("fabric.Color is already defined.");else{p.Color=h;h.prototype._tryParsingColor=function(e){var l=h.sourceFromHex(e);l||(l=h.sourceFromRgb(e));l&&this.setSource(l)};h.prototype.getSource=function(){return this._source};h.prototype.setSource=function(e){this._source=e};h.prototype.toRgb=function(){var e=this.getSource();return"rgb("+e[0]+","+e[1]+","+e[2]+")"};h.prototype.toRgba= +function(){var e=this.getSource();return"rgba("+e[0]+","+e[1]+","+e[2]+","+e[3]+")"};h.prototype.toHex=function(){var e=this.getSource(),l=e[0].toString(16);l=l.length==1?"0"+l:l;var o=e[1].toString(16);o=o.length==1?"0"+o:o;e=e[2].toString(16);e=e.length==1?"0"+e:e;return l.toUpperCase()+o.toUpperCase()+e.toUpperCase()};h.prototype.getAlpha=function(){return this.getSource()[3]};h.prototype.setAlpha=function(e){var l=this.getSource();l[3]=e;this.setSource(l);return this};h.prototype.toGrayscale= function(){var e=this.getSource(),l=parseInt((e[0]*0.3+e[1]*0.59+e[2]*0.11).toFixed(0),10);this.setSource([l,l,l,e[3]]);return this};h.prototype.toBlackWhite=function(e){var l=this.getSource(),o=(l[0]*0.3+l[1]*0.59+l[2]*0.11).toFixed(0);l=l[3];e=e||127;o=Number(o)1?new fabric.PathGroup(F,D):F[0];F.setSourcePath(H);if(!(F instanceof fabric.PathGroup)){e(F,D);typeof D.angle!=="undefined"&&F.setAngle(D.angle)}n(F,G)})}, -this)}catch(B){console.log(B.message)}},loadImageFromURL:function(){var f={};return function(k,n){function t(){var B=p.getElementById(f[k]);B.width&&B.height?n(new fabric.Image(B)):setTimeout(t,50)}var x=this;if(f[k])t();else{var y=new Image;y.onload=function(){y.onload=null;x._resizeImageToFit(y);var B=new fabric.Image(y);n(B)};y.className="canvas-img-clone";y.src=k;if(this.shouldCacheImages)f[k]=Element.identify(y);p.body.appendChild(y)}}}(),loadSVGFromURL:function(f,k){function n(y){if(y=y.responseXML)(y= -y.documentElement)&&fabric.parseSVGDocument(y,function(B,D){x.cache.set(f,{objects:B.invoke("toObject"),options:D});k(B,D)})}function t(){console.log("ERROR!")}var x=this;f=f.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(f,function(y){if(y)x.cache.get(f,function(B){B=x._enlivenCachedObject(B);k(B.objects,B.options)});else new Ajax.Request(f,{method:"get",onComplete:n,onFailure:t})})},_enlivenCachedObject:function(f){var k=f.objects;f=f.options;k=k.map(function(n){return fabric[l(n.type)].fromObject(n)}); +this)}catch(B){fabric.log(B.message)}},loadImageFromURL:function(){var f={};return function(k,n){function t(){var B=p.getElementById(f[k]);B.width&&B.height?n(new fabric.Image(B)):setTimeout(t,50)}var x=this;if(f[k])t();else{var y=new Image;y.onload=function(){y.onload=null;x._resizeImageToFit(y);var B=new fabric.Image(y);n(B)};y.className="canvas-img-clone";y.src=k;if(this.shouldCacheImages)f[k]=Element.identify(y);p.body.appendChild(y)}}}(),loadSVGFromURL:function(f,k){function n(y){if(y=y.responseXML)(y= +y.documentElement)&&fabric.parseSVGDocument(y,function(B,D){x.cache.set(f,{objects:B.invoke("toObject"),options:D});k(B,D)})}function t(){fabric.log("ERROR!")}var x=this;f=f.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(f,function(y){if(y)x.cache.get(f,function(B){B=x._enlivenCachedObject(B);k(B.objects,B.options)});else new Ajax.Request(f,{method:"get",onComplete:n,onFailure:t})})},_enlivenCachedObject:function(f){var k=f.objects;f=f.options;k=k.map(function(n){return fabric[l(n.type)].fromObject(n)}); return{objects:k,options:f}},remove:function(f){b(this._objects,f);this.renderAll();return f},fxRemove:function(f,k){var n=this;f.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){n.remove(f);typeof k==="function"&&k()}});return this},sendToBack:function(f){b(this._objects,f);this._objects.unshift(f);return this.renderAll()},bringToFront:function(f){b(this._objects,f);this._objects.push(f);return this.renderAll()},sendBackwards:function(f){var k=this._objects.indexOf(f),n=k;if(k!== 0){for(k=k-1;k>=0;--k)if(f.intersectsWithObject(this._objects[k])){n=k;break}b(this._objects,f);this._objects.splice(n,0,f)}return this.renderAll()},bringForward:function(f){var k=this.getObjects(),n=k.indexOf(f),t=n;if(n!==k.length-1){n=n+1;for(var x=this._objects.length;n0))throw Error("value of `r` attribute is required and can not be negative");if("left"in d)d.left-=o.width/2||0;if("top"in d)d.top-=o.height/ -2||0;return new h.Circle(e(d,o))};h.Circle.fromObject=function(l){return new h.Circle(l)}}})(); +(function(){var h=this.fabric||(this.fabric={}),p=Math.PI*2,e=h.util.object.extend;if(h.Circle)h.warn("fabric.Circle is already defined.");else{h.Circle=h.util.createClass(h.Object,{type:"circle",initialize:function(l){l=l||{};this.set("radius",l.radius||0);this.callSuper("initialize",l);l=this.get("radius")*2*this.get("scaleX");this.set("width",l).set("height",l)},toObject:function(){return e(this.callSuper("toObject"),{radius:this.get("radius")})},_render:function(l,o){l.beginPath();l.arc(o?this.left: +0,o?this.top:0,this.radius,0,p,false);l.closePath();this.fill&&l.fill();this.stroke&&l.stroke()},complexity:function(){return 1}});h.Circle.ATTRIBUTE_NAMES="cx cy r fill fill-opacity stroke stroke-width transform".split(" ");h.Circle.fromElement=function(l,o){o||(o={});var d=h.parseAttributes(l,h.Circle.ATTRIBUTE_NAMES);if(!("radius"in d&&d.radius>0))throw Error("value of `r` attribute is required and can not be negative");if("left"in d)d.left-=o.width/2||0;if("top"in d)d.top-=o.height/2||0;return new h.Circle(e(d, +o))};h.Circle.fromObject=function(l){return new h.Circle(l)}}})(); (function(){var h=this.fabric||(this.fabric={});if(!h.Triangle){h.Triangle=h.util.createClass(h.Object,{type:"triangle",initialize:function(p){p=p||{};this.callSuper("initialize",p);this.set("width",p.width||100).set("height",p.height||100)},_render:function(p){var e=this.width/2,l=this.height/2;p.beginPath();p.moveTo(-e,l);p.lineTo(0,-l);p.lineTo(e,l);p.closePath();this.fill&&p.fill();this.stroke&&p.stroke()},complexity:function(){return 1}});h.Triangle.fromObject=function(p){return new h.Triangle(p)}}})(); -(function(){var h=this.fabric||(this.fabric={}),p=Math.PI*2,e=h.util.object.extend;if(h.Ellipse)console.warn("fabric.Ellipse is already defined.");else{h.Ellipse=h.util.createClass(h.Object,{type:"ellipse",initialize:function(l){l=l||{};this.callSuper("initialize",l);this.set("rx",l.rx||0);this.set("ry",l.ry||0);this.set("width",this.get("rx")*2);this.set("height",this.get("ry")*2)},toObject:function(){return e(this.callSuper("toObject"),{rx:this.get("rx"),ry:this.get("ry")})},render:function(l,o){if(!(this.rx=== +(function(){var h=this.fabric||(this.fabric={}),p=Math.PI*2,e=h.util.object.extend;if(h.Ellipse)h.warn("fabric.Ellipse is already defined.");else{h.Ellipse=h.util.createClass(h.Object,{type:"ellipse",initialize:function(l){l=l||{};this.callSuper("initialize",l);this.set("rx",l.rx||0);this.set("ry",l.ry||0);this.set("width",this.get("rx")*2);this.set("height",this.get("ry")*2)},toObject:function(){return e(this.callSuper("toObject"),{rx:this.get("rx"),ry:this.get("ry")})},render:function(l,o){if(!(this.rx=== 0||this.ry===0))return this.callSuper("render",l,o)},_render:function(l,o){l.beginPath();l.save();l.transform(1,0,0,this.ry/this.rx,0,0);l.arc(o?this.left:0,o?this.top:0,this.rx,0,p,false);l.restore();this.stroke&&l.stroke();this.fill&&l.fill()},complexity:function(){return 1}});h.Ellipse.ATTRIBUTE_NAMES="cx cy rx ry fill fill-opacity stroke stroke-width transform".split(" ");h.Ellipse.fromElement=function(l,o){o||(o={});var d=h.parseAttributes(l,h.Ellipse.ATTRIBUTE_NAMES);if("left"in d)d.left-=o.width/ 2||0;if("top"in d)d.top-=o.height/2||0;return new h.Ellipse(e(d,o))};h.Ellipse.fromObject=function(l){return new h.Ellipse(l)}}})(); (function(){var h=this.fabric||(this.fabric={});if(!h.Rect){h.Rect=h.util.createClass(h.Object,{type:"rect",options:{rx:0,ry:0},initialize:function(p){this.callSuper("initialize",p);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(p){var e=this.options.rx||0,l=this.options.ry||0,o=-this.width/2,d=-this.height/2,c=this.width,a=this.height;p.beginPath(); p.moveTo(o+e,d);p.lineTo(o+c-e,d);p.bezierCurveTo(o+c,d,o+c,d+l,o+c,d+l);p.lineTo(o+c,d+a-l);p.bezierCurveTo(o+c,d+a,o+c-e,d+a,o+c-e,d+a);p.lineTo(o+e,d+a);p.bezierCurveTo(o,d+a,o,d+a-l,o,d+a-l);p.lineTo(o,d+l);p.bezierCurveTo(o,d,o+e,d,o+e,d);p.closePath();this.fill&&p.fill();this.stroke&&p.stroke()},_normalizeLeftTopProperties:function(p){p.left&&this.set("left",p.left+this.getWidth()/2);p.top&&this.set("top",p.top+this.getHeight()/2);return this},complexity:function(){return 1}});h.Rect.ATTRIBUTE_NAMES= "x y width height rx ry fill fill-opacity stroke stroke-width transform".split(" ");h.Rect.fromElement=function(p,e){if(!p)return null;var l=h.parseAttributes(p,h.Rect.ATTRIBUTE_NAMES);l=l;l.left=l.left||0;l.top=l.top||0;l=l;var o=new h.Rect(h.util.object.extend(e||{},l));o._normalizeLeftTopProperties(l);return o};h.Rect.fromObject=function(p){return new h.Rect(p)}}})(); -(function(){var h=this.fabric||(this.fabric={});if(h.Polyline)console.warn("fabric.Polyline is already defined");else{h.Polyline=h.util.createClass(h.Object,{type:"polyline",initialize:function(e,l){l=l||{};this.set("points",e);this.callSuper("initialize",l);this._calcDimensions()},_calcDimensions:function(){return h.Polygon.prototype._calcDimensions.call(this)},toObject:function(){return h.Polygon.prototype.toObject.call(this)},_render:function(e){var l;e.beginPath();for(var o=0,d=this.points.length;o< +(function(){var h=this.fabric||(this.fabric={});if(h.Polyline)h.warn("fabric.Polyline is already defined");else{h.Polyline=h.util.createClass(h.Object,{type:"polyline",initialize:function(e,l){l=l||{};this.set("points",e);this.callSuper("initialize",l);this._calcDimensions()},_calcDimensions:function(){return h.Polygon.prototype._calcDimensions.call(this)},toObject:function(){return h.Polygon.prototype.toObject.call(this)},_render:function(e){var l;e.beginPath();for(var o=0,d=this.points.length;o< d;o++){l=this.points[o];e.lineTo(l.x,l.y)}this.fill&&e.fill();this.stroke&&e.stroke()},complexity:function(){return this.get("points").length}});var p="fill fill-opacity stroke stroke-width transform".split(" ");h.Polyline.fromElement=function(e,l){if(!e)return null;l||(l={});for(var o=h.parsePointsAttribute(e.getAttribute("points")),d=h.parseAttributes(e,p),c=0,a=o.length;c"},toObject:function(){var d=l(this.callSuper("toObject"),{path:this.path});if(this.sourcePath)d.sourcePath=this.sourcePath;if(this.transformMatrix)d.transformMatrix=this.transformMatrix;return d},toDatalessObject:function(){var d=this.toObject();if(this.sourcePath)d.path=this.sourcePath;delete d.sourcePath;return d},complexity:function(){return this.path.length},set:function(d,c){return this.callSuper("set",d,c)},_parsePath:function(){for(var d= [],c,a,b=0,g=this.path.length;b"},isSameColor:function(){var a=this.getObjects()[0].get("fill");return this.getObjects().every(function(b){return b.get("fill")===a})},complexity:function(){return this.paths.reduce(function(a,b){return a+(b&&b.complexity?b.complexity():0)},0)},toGrayscale:function(){for(var a=this.paths.length;a--;)this.paths[a].toGrayscale();return this},getObjects:function(){return this.paths}});h.PathGroup.fromObject=function(a){for(var b=a.paths, @@ -153,15 +153,15 @@ this);return this},_restoreObjectState:function(c){var a=this.get("left"),b=this c.hideCorners=false;c.setActive(false);c.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(c){c.setCoords()});return this},activateAllObjects:function(){return this.setActive(true)},setActive:function(c){this.forEachObject(function(a){a.setActive(c)}); return this},forEachObject:function(c,a){for(var b=this.getObjects(),g=b.length;g--;)c.call(a,b[g],g,b);return this},_setOpacityIfSame:function(){var c=this.getObjects(),a=c[0]?c[0].get("opacity"):1;if(c.every(function(b){return b.get("opacity")===a}))this.opacity=a},_calcBounds:function(){var c=[],a=[],b,g;g=0;for(var m=this.objects.length;gc.x&&m-bc.y},toGrayscale:function(){for(var c=this.objects.length;c--;)this.objects[c].toGrayscale()}});h.Group.fromObject=function(c){return new h.Group(c.objects,c)}}})(); -(function(){var h=this.fabric||(this.fabric={}),p=h.util.object.extend,e=h.util.object.clone;if(h.Text)console.warn("fabric.Text is already defined");else if(h.Object){h.Text=h.util.createClass(h.Object,{options:{top:10,left:10,fontsize:20,fontweight:100,fontfamily:"Modernist_One_400",path:null},type:"text",initialize:function(l,o){this.originalState={};this.initStateProperties();this.text=l;this.setOptions(o);p(this,this.options);this.theta=this.angle*(Math.PI/180);this.width=this.getWidth();this.setCoords()}, +(function(){var h=this.fabric||(this.fabric={}),p=h.util.object.extend,e=h.util.object.clone;if(h.Text)h.warn("fabric.Text is already defined");else if(h.Object){h.Text=h.util.createClass(h.Object,{options:{top:10,left:10,fontsize:20,fontweight:100,fontfamily:"Modernist_One_400",path:null},type:"text",initialize:function(l,o){this.originalState={};this.initStateProperties();this.text=l;this.setOptions(o);p(this,this.options);this.theta=this.angle*(Math.PI/180);this.width=this.getWidth();this.setCoords()}, initStateProperties:function(){var l;if((l=this.constructor)&&(l=l.superclass)&&(l=l.prototype)&&(l=l.stateProperties)&&l.clone){this.stateProperties=l.clone();this.stateProperties.push("fontfamily","fontweight","path")}},toString:function(){return"#"},_render:function(l){var o=Cufon.textOptions||(Cufon.textOptions={});o.left=this.left;o.top=this.top;o.context=l;o.color=this.fill;var d=this._initDummyElement(); this.transform(l);Cufon.replaceElement(d,{separate:"none",fontFamily:this.fontfamily});this.width=o.width;this.height=o.height},_initDummyElement:function(){var l=document.createElement("div");l.innerHTML=this.text;l.style.fontSize="40px";l.style.fontWeight="400";l.style.fontStyle="normal";l.style.letterSpacing="normal";l.style.color="#000000";l.style.fontWeight="600";l.style.fontFamily="Verdana";return l},render:function(l){l.save();this._render(l);if(this.active){this.drawBorders(l);this.drawCorners(l)}l.restore()}, toObject:function(){return p(this.callSuper("toObject"),{text:this.text,fontsize:this.fontsize,fontweight:this.fontweight,fontfamily:this.fontfamily,path:this.path})},setColor:function(l){this.set("fill",l);return this},setFontsize:function(l){this.set("fontsize",l);this.setCoords();return this},getText:function(){return this.text},setText:function(l){this.set("text",l);this.setCoords();return this},set:function(l,o){this[l]=o;if(l==="fontfamily")this.path=this.path.replace(/(.*?)([^\/]*)(\.font\.js)/, -"$1"+o+"$3");return this}});h.Text.fromObject=function(l){return new h.Text(l.text,e(l))};h.Text.fromElement=function(){}}else console.warn("fabric.Text requires fabric.Object")})(); -(function(){var h=fabric.util.object.extend;if(!this.fabric)this.fabric={};if(this.fabric.Image)console.warn("fabric.Image is already defined.");else if(fabric.Object){fabric.Image=fabric.util.createClass(fabric.Object,{maxwidth:null,maxheight:null,active:false,bordervisibility:false,cornervisibility:false,type:"image",__isGrayscaled:false,initialize:function(p,e){this.callSuper("initialize",e);this._initElement(p);this._initConfig(e||{})},getElement:function(){return this._element},setElement:function(p){this._element= +"$1"+o+"$3");return this}});h.Text.fromObject=function(l){return new h.Text(l.text,e(l))};h.Text.fromElement=function(){}}else h.warn("fabric.Text requires fabric.Object")})(); +(function(){var h=fabric.util.object.extend;if(!this.fabric)this.fabric={};if(this.fabric.Image)fabric.warn("fabric.Image is already defined.");else if(fabric.Object){fabric.Image=fabric.util.createClass(fabric.Object,{maxwidth:null,maxheight:null,active:false,bordervisibility:false,cornervisibility:false,type:"image",__isGrayscaled:false,initialize:function(p,e){this.callSuper("initialize",e);this._initElement(p);this._initConfig(e||{})},getElement:function(){return this._element},setElement:function(p){this._element= p;return this},getNormalizedSize:function(p,e,l){if(l&&e&&p.width>p.height&&p.width/p.heightp.width||p.height>l)){normalizedWidth=~~(p.width*l/p.height);normalizedHeight=l}else if(e&&e'},clone:function(p){this.constructor.fromObject(this.toObject(),p)},toGrayscale:function(p){if(!this.__isGrayscaled){var e=this.getElement(),l=document.createElement("canvas"),o=document.createElement("img"),d=this;l.width=e.width;l.height=e.height;l.getContext("2d").drawImage(e,0,0);fabric.Element.toGrayscale(l);o.onload=function(){d.setElement(o);p&&p();o.onload=l=e=imageData=null};o.width=e.width;o.height=e.height;o.src=l.toDataURL("image/png");this.__isGrayscaled=true;return this}}, _render:function(p){var e=this.getOriginalSize();p.drawImage(this.getElement(),-e.width/2,-e.height/2,e.width,e.height)},_adjustWidthHeightToBorders:function(p){if(p){this.currentBorder=this.borderwidth;this.width+=2*this.currentBorder;this.height+=2*this.currentBorder}else this.currentBorder=0},_resetWidthHeight:function(){var p=this.getElement();this.set("width",p.width);this.set("height",p.height)},_initElement:function(p){this.setElement(fabric.util.getById(p));fabric.util.addClass(this.getElement(), fabric.Image.CSS_CANVAS)},_initConfig:function(p){this.setOptions(p);this._setBorder();this._setWidthHeight(p)},_setBorder:function(){this.currentBorder=this.bordervisibility?this.borderwidth:0},_setWidthHeight:function(){var p=2*this.currentBorder;this.width=(this.getElement().width||0)+p;this.height=(this.getElement().height||0)+p},complexity:function(){return 1}});fabric.Image.CSS_CANVAS="canvas-img";fabric.Image.fromObject=function(p,e){var l=document.createElement("img"),o=p.src;if(p.width)l.width= -p.width;if(p.height)l.height=p.height;l.onload=function(){e&&e(new fabric.Image(l,p));l=l.onload=null};l.src=o};fabric.Image.fromURL=function(p,e,l){var o=document.createElement("img");o.onload=function(){e&&e(new fabric.Image(o,l));o=o.onload=null};o.src=p}}else console.warn("fabric.Object is required for fabric.Image initialization")})(); +p.width;if(p.height)l.height=p.height;l.onload=function(){e&&e(new fabric.Image(l,p));l=l.onload=null};l.src=o};fabric.Image.fromURL=function(p,e,l){var o=document.createElement("img");o.onload=function(){e&&e(new fabric.Image(o,l));o=o.onload=null};o.src=p}}else fabric.warn("fabric.Object is required for fabric.Image initialization")})(); diff --git a/fabric.js b/fabric.js index 92c9ec4d..4dc0d4b8 100644 --- a/fabric.js +++ b/fabric.js @@ -1,12 +1,23 @@ /*! Fabric.js Copyright 2010, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var console = console || { - log: function() { }, - warn: function() { } -}; - var fabric = fabric || { version: 0.1 }; +fabric.log = function() { }; +fabric.warn = function() { }; + +if (typeof console !== 'undefined') { + if (typeof console.log !== 'undefined' && console.log.apply) { + fabric.log = function() { + return console.log.apply(console, arguments); + }; + } + if (typeof console.warn !== 'undefined' && console.warn.apply) { + fabric.warn = function() { + return console.warn.apply(console, arguments); + }; + } +} + //= require "lib/json2" //= require "src/util" diff --git a/src/circle.class.js b/src/circle.class.js index ba480930..6ae61b69 100644 --- a/src/circle.class.js +++ b/src/circle.class.js @@ -7,7 +7,7 @@ extend = fabric.util.object.extend; if (fabric.Circle) { - console.warn('fabric.Circle is already defined.'); + fabric.warn('fabric.Circle is already defined.'); return; } diff --git a/src/color.class.js b/src/color.class.js index 81c2079c..dc0b1252 100644 --- a/src/color.class.js +++ b/src/color.class.js @@ -3,7 +3,7 @@ var fabric = this.fabric || (this.fabric = { }); if (fabric.Color) { - console.warn('fabric.Color is already defined.'); + fabric.warn('fabric.Color is already defined.'); return; } diff --git a/src/element.class.js b/src/element.class.js index 6ab686ce..c26d9880 100644 --- a/src/element.class.js +++ b/src/element.class.js @@ -1,7 +1,7 @@ (function () { if (fabric.Element) { - console.warn('fabric.Element is already defined.'); + fabric.warn('fabric.Element is already defined.'); return; } @@ -1694,7 +1694,7 @@ }, this); } catch(e) { - console.log(e.message); + fabric.log(e.message); } }, @@ -1790,7 +1790,7 @@ } function onFailure() { - console.log('ERROR!'); + fabric.log('ERROR!'); } }, diff --git a/src/ellipse.class.js b/src/ellipse.class.js index ff5bfb78..2eb93b9d 100644 --- a/src/ellipse.class.js +++ b/src/ellipse.class.js @@ -7,7 +7,7 @@ extend = fabric.util.object.extend; if (fabric.Ellipse) { - console.warn('fabric.Ellipse is already defined.'); + fabric.warn('fabric.Ellipse is already defined.'); return; } diff --git a/src/image.class.js b/src/image.class.js index 836e8bd6..ae19acd9 100644 --- a/src/image.class.js +++ b/src/image.class.js @@ -10,12 +10,12 @@ } if (global.fabric.Image) { - console.warn('fabric.Image is already defined.'); + fabric.warn('fabric.Image is already defined.'); return; }; if (!fabric.Object) { - console.warn('fabric.Object is required for fabric.Image initialization'); + fabric.warn('fabric.Object is required for fabric.Image initialization'); return; } diff --git a/src/intersection.class.js b/src/intersection.class.js index 8c33dc47..5931dd6e 100644 --- a/src/intersection.class.js +++ b/src/intersection.class.js @@ -8,7 +8,7 @@ fabric = global.fabric || (global.fabric = { }); if (fabric.Intersection) { - console.warn('fabric.Intersection is already defined'); + fabric.warn('fabric.Intersection is already defined'); return; } diff --git a/src/parser.js b/src/parser.js index 0c74e28b..1703d240 100644 --- a/src/parser.js +++ b/src/parser.js @@ -285,7 +285,7 @@ return klass.fromElement(el, options); } catch(e) { - console.log(e.message || e); + fabric.log(e.message || e); } } }); diff --git a/src/path.class.js b/src/path.class.js index f5f43af8..2f21e378 100644 --- a/src/path.class.js +++ b/src/path.class.js @@ -8,11 +8,11 @@ extend = fabric.util.object.extend; if (fabric.Path) { - console.warn('fabric.Path is already defined'); + fabric.warn('fabric.Path is already defined'); return; } if (!fabric.Object) { - console.warn('fabric.Path requires fabric.Object'); + fabric.warn('fabric.Path requires fabric.Object'); return; } diff --git a/src/path_group.class.js b/src/path_group.class.js index db243e62..a740a72a 100644 --- a/src/path_group.class.js +++ b/src/path_group.class.js @@ -11,7 +11,7 @@ capitalize = fabric.util.string.capitalize; if (fabric.PathGroup) { - console.warn('fabric.PathGroup is already defined'); + fabric.warn('fabric.PathGroup is already defined'); return; } diff --git a/src/point.class.js b/src/point.class.js index dc1190de..558a0904 100644 --- a/src/point.class.js +++ b/src/point.class.js @@ -5,7 +5,7 @@ var fabric = this.fabric || (this.fabric = { }); if (fabric.Point) { - console.warn('fabric.Point is already defined'); + fabric.warn('fabric.Point is already defined'); return; } diff --git a/src/polygon.class.js b/src/polygon.class.js index dd311f73..d5197c65 100644 --- a/src/polygon.class.js +++ b/src/polygon.class.js @@ -8,7 +8,7 @@ max = fabric.util.array.max; if (fabric.Polygon) { - console.warn('fabric.Polygon is already defined'); + fabric.warn('fabric.Polygon is already defined'); return; } diff --git a/src/polyline.class.js b/src/polyline.class.js index f55865e8..7f4a1dd3 100644 --- a/src/polyline.class.js +++ b/src/polyline.class.js @@ -5,7 +5,7 @@ var fabric = this.fabric || (this.fabric = { }); if (fabric.Polyline) { - console.warn('fabric.Polyline is already defined'); + fabric.warn('fabric.Polyline is already defined'); return; } diff --git a/src/text.class.js b/src/text.class.js index b67b5800..624eeda2 100644 --- a/src/text.class.js +++ b/src/text.class.js @@ -7,11 +7,11 @@ clone = fabric.util.object.clone; if (fabric.Text) { - console.warn('fabric.Text is already defined'); + fabric.warn('fabric.Text is already defined'); return; } if (!fabric.Object) { - console.warn('fabric.Text requires fabric.Object'); + fabric.warn('fabric.Text requires fabric.Object'); return; } diff --git a/test/unit/path_group.js b/test/unit/path_group.js index f052b6e6..a13075d6 100644 --- a/test/unit/path_group.js +++ b/test/unit/path_group.js @@ -65,13 +65,6 @@ var pathGroup = getPathGroupObject(); ok(typeof pathGroup.toObject == 'function'); var object = pathGroup.toObject(); - - /*same(fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), { - paths: object.paths - }), object); - console.log(fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), { - paths: object.paths - }), object);*/ }); test('complexity', function() { diff --git a/test/unit/text.js b/test/unit/text.js index 4c95e791..2775e0ff 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -94,60 +94,54 @@ }); asyncTest('Text already defined', function() { - var warnWasCalled = false; + var warnWasCalled = false, originalWarn = fabric.warn; function warn() { warnWasCalled = true; } - console.warn = warn; + fabric.warn = warn; - if (console.warn === warn) { - // some browsers (e.g. Safari 3.0.4) don't allow to override `console.warn` - var el = document.createElement('script'); - el.src = '../../src/text.class.js'; - document.body.appendChild(el); + var el = document.createElement('script'); + el.src = '../../src/text.class.js'; + document.body.appendChild(el); - setTimeout(function() { - ok(warnWasCalled); - start(); - }, 500); - } - else { + setTimeout(function() { + ok(warnWasCalled); + + fabric.warn = originalWarn; + start(); - } + }, 500); }); asyncTest('Object doesn\'t exist', function() { - var warnWasCalled = false; + var warnWasCalled = false, originalWarn = fabric.warn; function warn() { warnWasCalled = true; } - console.warn = warn; + fabric.warn = warn; - if (console.warn === warn) { - var originalObject = fabric.Object; - var originalText = fabric.Text; + var originalObject = fabric.Object; + var originalText = fabric.Text; - delete fabric.Text; - delete fabric.Object; + delete fabric.Text; + delete fabric.Object; - var el = document.createElement('script'); - el.src = '../../src/text.class.js'; - document.body.appendChild(el); + var el = document.createElement('script'); + el.src = '../../src/text.class.js'; + document.body.appendChild(el); - setTimeout(function() { - ok(warnWasCalled); + setTimeout(function() { + ok(warnWasCalled); - fabric.Object = originalObject; - fabric.Text = originalText; + fabric.Object = originalObject; + fabric.Text = originalText; + + fabric.warn = originalWarn; - start(); - }, 500); - } - else { start(); - } + }, 500); }); })(); \ No newline at end of file