Introduce fabric.log and fabric.warn methods, as simple wrappers around console.log and console.warn (instead of declaring those methods right on console). This makes it easier to mock them when testing, and is generally safer due to less tinkering with host objects.

This commit is contained in:
kangax 2010-10-11 14:45:06 -04:00
parent 8ceca73561
commit e70830f7d6
20 changed files with 121 additions and 113 deletions

57
dist/all.js vendored
View file

@ -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;
}

File diff suppressed because one or more lines are too long

Binary file not shown.

52
dist/all.min.js vendored
View file

@ -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<v;q+=1)w[q]=e(q,s)||"null";u=w.length===0?"[]":d?"[\n"+d+w.join(",\n"+d)+"\n"+A+"]":"["+w.join(",")+"]";d=A;return u}if(b&&typeof b==="object"){v=b.length;for(q=0;q<v;q+=1){r=b[q];if(typeof r==="string")if(u=e(r,s))w.push(p(r)+(d?": ":":")+u)}}else for(r in s)if(Object.hasOwnProperty.call(s,r))if(u=e(r,s))w.push(p(r)+(d?": ":":")+u);u=w.length===0?"{}":d?"{\n"+d+w.join(",\n"+d)+
"\n"+A+"}":"{"+w.join(",")+"}";d=A;return u}}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+h(this.getUTCMonth()+1)+"-"+h(this.getUTCDate())+"T"+h(this.getUTCHours())+":"+h(this.getUTCMinutes())+":"+h(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()}}var l=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
@ -31,22 +31,22 @@ return function(q){var r=b.concat();if(!q||q&&!g.test(q))return r;q.replace(m,fu
""&&A!=null});u=v[1];v=v.slice(2).map(parseFloat);switch(u){case "translate":a(r,v);break;case "rotate":d(r,v);break;case "scale":c(r,v);break;case "skewX":r[2]=v[0];break;case "skewY":r[1]=v[0];break;case "matrix":r=v;break}});return r}}();h.parseSVGDocument=function(){var d=/^(path|circle|polygon|polyline|ellipse|rect|line)$/,c=RegExp("^\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)+)\\s*,?\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)+)\\s*,?\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)+)\\s*,?\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)+)\\s*$");
return function(a,b){if(a){var g=h.util.toArray(a.getElementsByTagName("*")).filter(function(A){var w;if(w=d.test(A.tagName)){a:{for(A=A;A&&(A=A.parentNode);)if(A.nodeName==="pattern"){A=true;break a}A=false}w=!A}return w});if(!(!g||g&&!g.length)){var m=a.getAttribute("viewBox"),q=a.getAttribute("width"),r=a.getAttribute("height"),u=null,v=null;if(m&&(m=m.match(c))){parseInt(m[1],10);parseInt(m[2],10);u=parseInt(m[3],10);v=parseInt(m[4],10)}u=q?parseFloat(q):u;v=r?parseFloat(r):v;m={width:u,height:v};
g=h.parseElements(g,l(m));!g||g&&!g.length||b&&b(g,m)}}}}();p(h,{parseAttributes:function(d,c){if(d){var a,b,g={};if(d.parentNode&&/^g$/i.test(d.parentNode.nodeName))g=h.parseAttributes(d.parentNode,c);var m=c.reduce(function(q,r){a=d.getAttribute(r);b=parseFloat(a);if(a){if((r==="fill"||r==="stroke")&&a==="none")a="";if(r==="fill-rule")a=a==="evenodd"?"destination-over":a;if(r==="transform")a=h.parseTransformAttribute(a);if(r in o)r=o[r];q[r]=isNaN(b)?a:b}return q},{});m=p(h.parseStyleAttribute(d),
m);return p(g,m)}},parseElements:function(d,c){var a=d.map(function(b){var g=h[e(b.tagName)];if(g&&g.fromElement)try{return g.fromElement(b,c)}catch(m){console.log(m.message||m)}});return a=a.filter(function(b){return b!=null})},parseStyleAttribute:function(d){var c={};if(d=d.getAttribute("style"))if(typeof d=="string"){d=d.split(";");d.pop();c=d.reduce(function(b,g){var m=g.split(":"),q=m[0].trim();m=m[1].trim();b[q]=m;return b},{})}else for(var a in d)if(typeof d[a]!=="undefined")c[a]=d[a];return c},
m);return p(g,m)}},parseElements:function(d,c){var a=d.map(function(b){var g=h[e(b.tagName)];if(g&&g.fromElement)try{return g.fromElement(b,c)}catch(m){h.log(m.message||m)}});return a=a.filter(function(b){return b!=null})},parseStyleAttribute:function(d){var c={};if(d=d.getAttribute("style"))if(typeof d=="string"){d=d.split(";");d.pop();c=d.reduce(function(b,g){var m=g.split(":"),q=m[0].trim();m=m[1].trim();b[q]=m;return b},{})}else for(var a in d)if(typeof d[a]!=="undefined")c[a]=d[a];return c},
parsePointsAttribute:function(d){if(!d)return null;d=d.trim();var c=d.indexOf(",")>-1;d=d.split(/\s+/);var a=[];if(c){c=0;for(var b=d.length;c<b;c++){var g=d[c].split(",");a.push({x:parseFloat(g[0]),y:parseFloat(g[1])})}}else{c=0;for(b=d.length;c<b;c+=2)a.push({x:parseFloat(d[c]),y:parseFloat(d[c+1])})}return a}})})();
(function(){function h(e,l){arguments.length>0&&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.y<e.y},lte:function(e){return this.x<=e.x&&this.y<=e.y},gt:function(e){return this.x>e.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;a<c;a++){var b=h.intersectLineLine(e,l,o[a],o[(a+1)%c]);d.appendPoints(b.points)}if(d.points.length>0)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.x<e.x&&
this.y<e.y},lte:function(e){return this.x<=e.x&&this.y<=e.y},gt:function(e){return this.x>e.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;a<c;a++){var b=h.intersectLineLine(e,l,o[a],o[(a+1)%c]);d.appendPoints(b.points)}if(d.points.length>0)d.status="Intersection";return d};h.intersectPolygonPolygon=
function(e,l){for(var o=new h("No Intersection"),d=e.length,c=0;c<d;c++){var a=h.intersectLinePolygon(e[c],e[(c+1)%d],l);o.appendPoints(a.points)}if(o.points.length>0)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)<Number(e)?0:255;this.setSource([o,o,o,l]);return this};h.prototype.overlayWith=function(e){e=new h(e);var l=[],o=this.getAlpha(),d=this.getSource();e=e.getSource();for(var c=0;c<3;c++)l.push(Math.round(d[c]*0.5+e[c]*0.5));l[4]=o;this.setSource(l);
return this};h.reRGBa=/^rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(\d+(?:\.\d+)?))?\)$/;h.reHex=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i;h.fromRgb=function(e){return h.fromSource(h.sourceFromRgb(e))};h.sourceFromRgb=function(e){if(e=e.match(h.reRGBa))return[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3],10),e[4]?parseFloat(e[4]):1]};h.fromRgba=h.fromRgb;h.fromHex=function(e){return h.fromSource(h.sourceFromHex(e))};h.sourceFromHex=function(e){if(e.match(h.reHex)){var l=e.slice(e.indexOf("#")+
1),o=l.length===3;e=o?l.charAt(0)+l.charAt(0):l.substring(0,2);var d=o?l.charAt(1)+l.charAt(1):l.substring(2,4);l=o?l.charAt(2)+l.charAt(2):l.substring(4,6);return[parseInt(e,16),parseInt(d,16),parseInt(l,16),1]}};h.fromSource=function(e){var l=new h;l.setSource(e);return l}}})();
(function(){if(fabric.Element)console.warn("fabric.Element is already defined.");else{var h=this.window,p=h.document,e=fabric.util.object.extend,l=fabric.util.string.capitalize,o=fabric.util.string.camelize,d=fabric.util.fireEvent,c=fabric.util.getPointer,a=fabric.util.getElementOffset,b=fabric.util.removeFromArray,g=fabric.util.addListener,m=fabric.util.removeListener,q=fabric.util.array.min,r=fabric.util.array.max,u=Math.sqrt,v=Math.pow,A=Math.atan2,w=Math.abs,s=Math.min,C=Math.max,z=Error("Could not initialize `canvas` element"),
(function(){if(fabric.Element)fabric.warn("fabric.Element is already defined.");else{var h=this.window,p=h.document,e=fabric.util.object.extend,l=fabric.util.string.capitalize,o=fabric.util.string.camelize,d=fabric.util.fireEvent,c=fabric.util.getPointer,a=fabric.util.getElementOffset,b=fabric.util.removeFromArray,g=fabric.util.addListener,m=fabric.util.removeListener,q=fabric.util.array.min,r=fabric.util.array.max,u=Math.sqrt,v=Math.pow,A=Math.atan2,w=Math.abs,s=Math.min,C=Math.max,z=Error("Could not initialize `canvas` element"),
E={tr:"ne-resize",br:"se-resize",bl:"sw-resize",tl:"nw-resize",ml:"w-resize",mt:"n-resize",mr:"e-resize",mb:"s-resize"};fabric.Element=function(f,k){this._groupSelector=null;this._objects=[];this._activeGroup=this._currentTransform=this._element=this._context=null;this._freeDrawingXPoints=[];this._freeDrawingYPoints=[];this._config={width:300,height:150};k=k||{};this._initElement(f);this._initConfig(k);k.overlayImage&&this.setOverlayImage(k.overlayImage);if(k.afterRender)this.afterRender=k.afterRender;
this._createCanvasBackground();this._createCanvasContainer();this._initEvents();this.calcOffset()};e(fabric.Element.prototype,{selectionColor:"rgba(100, 100, 255, 0.3)",selectionBorderColor:"rgba(255, 255, 255, 0.3)",freeDrawingColor:"rgb(0, 0, 0)",backgroundColor:"rgba(0, 0, 0, 0)",freeDrawingLineWidth:1,selectionLineWidth:1,includeDefaultValues:true,shouldCacheImages:false,CANVAS_WIDTH:600,CANVAS_HEIGHT:600,onBeforeScaleRotate:function(){},onFpsUpdate:function(){},calcOffset:function(){this._offset=
a(this.getElement());return this},setOverlayImage:function(f,k){if(f){var n=this,t=new Image;t.onload=function(){n.overlayImage=t;k&&k();t=t.onload=null};t.src=f}return this},_initElement:function(f){this._element=fabric.util.getById(f)||p.createElement("canvas");typeof this._element.getContext==="undefined"&&typeof G_vmlCanvasManager!=="undefined"&&G_vmlCanvasManager.initElement(this._element);if(typeof this._element.getContext==="undefined")throw z;if(!(this.contextTop=this._element.getContext("2d")))throw z;
@ -80,8 +80,8 @@ _toObjectMethod:function(f){return{objects:this._objects.map(function(k){if(!thi
k&&k()});return this}}},_enlivenObjects:function(f,k){var n=0,t=f.filter(function(y){return y.type==="image"}).length,x=this;f.forEach(function(y,B){if(y.type)switch(y.type){case "image":case "font":fabric[l(y.type)].fromObject(y,function(G){x.insertAt(G,B);++n===t&&k&&k()});break;default:var D=fabric[o(l(y.type))];D&&D.fromObject&&x.insertAt(D.fromObject(y),B);break}});t===0&&k&&k()},loadFromDatalessJSON:function(f,k){if(f){var n=typeof f==="string"?JSON.parse(f):f;if(!(!n||n&&!n.objects)){this.clear();
this.backgroundColor=n.background;this._enlivenDatalessObjects(n.objects,k)}}},_enlivenDatalessObjects:function(f,k){function n(D,G){t.insertAt(D,G);D.setCoords();++x===y&&k&&k()}var t=this,x=0,y=f.length;y===0&&k&&k();try{f.forEach(function(D,G){var I=D.paths?"paths":"path",H=D[I];delete D[I];if(typeof H!=="string")switch(D.type){case "image":case "text":fabric[l(D.type)].fromObject(D,function(F){n(F,G)});break;default:(I=fabric[o(l(D.type))])&&I.fromObject&&n(I.fromObject(D),G);break}else if(D.type===
"image")t.loadImageFromURL(H,function(F){F.setSourcePath(H);e(F,D);F.setAngle(D.angle);n(F,G)});else if(D.type==="text"){D.path=H;var J=fabric.Text.fromObject(D);fabric.util.getScript(H,function(){Object.prototype.toString.call(h.opera)==="[object Opera]"?setTimeout(function(){n(J,G)},500):n(J,G)})}else t.loadSVGFromURL(H,function(F){F=F.length>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;n<x;++n)if(f.intersectsWithObject(k[n])){t=n;break}b(k,f);k.splice(t,0,f)}this.renderAll()},setActiveObject:function(f){this._activeObject&&this._activeObject.setActive(false);this._activeObject=f;f.setActive(true);this.renderAll();
d("object:selected",{target:f});return this},getActiveObject:function(){return this._activeObject},removeActiveObject:function(){this._activeObject&&this._activeObject.setActive(false);this._activeObject=null;return this},setActiveGroup:function(f){this._activeGroup=f;return this},getActiveGroup:function(){return this._activeGroup},removeActiveGroup:function(){var f=this.getActiveGroup();f&&f.destroy();return this.setActiveGroup(null)},item:function(f){return this.getObjects()[f]},deactivateAll:function(){for(var f=
@ -115,23 +115,23 @@ return this},_getAngleValueForStraighten:function(){var a=this.get("angle");if(a
(function(){var h=this.fabric||(this.fabric={}),p=h.util.object.extend;if(!h.Line){h.Line=h.util.createClass(h.Object,{type:"line",initialize:function(e,l){e||(e=[0,0,0,0]);this.callSuper("initialize",l);this.set("x1",e[0]);this.set("y1",e[1]);this.set("x2",e[2]);this.set("y2",e[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(e){e.beginPath();e.moveTo(-this.width/2,-this.height/2);
e.lineTo(this.width/2,this.height/2);var l=e.strokeStyle;e.strokeStyle=e.fillStyle;e.stroke();e.strokeStyle=l},complexity:function(){return 1},toObject:function(){return p(this.callSuper("toObject"),{x1:this.get("x1"),y1:this.get("y1"),x2:this.get("x2"),y2:this.get("y2")})}});h.Element.ATTRIBUTE_NAMES="x1 y1 x2 y2 stroke stroke-width transform".split(" ");h.Line.fromElement=function(e,l){var o=h.parseAttributes(e,h.Element.ATTRIBUTE_NAMES);return new h.Line([o.x1||0,o.y1||0,o.x2||0,o.y2||0],p(o,l))};
h.Line.fromObject=function(e){return new h.Line([e.x1,e.y1,e.x2,e.y2],e)}}})();
(function(){var h=this.fabric||(this.fabric={}),p=Math.PI*2,e=h.util.object.extend;if(h.Circle)console.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={}),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<a;c++){o[c].x-=l.width/2||0;o[c].y-=l.height/2||0}return new h.Polyline(o,h.util.object.extend(d,l))};h.Polyline.fromObject=
function(e){return new h.Polyline(e.points,e)}}})();
(function(){var h=this.fabric||(this.fabric={}),p=h.util.object.extend,e=h.util.array.min,l=h.util.array.max;if(h.Polygon)console.warn("fabric.Polygon is already defined");else{h.Polygon=h.util.createClass(h.Object,{type:"polygon",initialize:function(o,d){d=d||{};this.points=o;this.callSuper("initialize",d);this._calcDimensions()},_calcDimensions:function(){var o=this.points,d=e(o,"x"),c=e(o,"y"),a=l(o,"x");o=l(o,"y");this.width=a-d;this.height=o-c;this.minX=d;this.minY=c},toObject:function(){return p(this.callSuper("toObject"),
(function(){var h=this.fabric||(this.fabric={}),p=h.util.object.extend,e=h.util.array.min,l=h.util.array.max;if(h.Polygon)h.warn("fabric.Polygon is already defined");else{h.Polygon=h.util.createClass(h.Object,{type:"polygon",initialize:function(o,d){d=d||{};this.points=o;this.callSuper("initialize",d);this._calcDimensions()},_calcDimensions:function(){var o=this.points,d=e(o,"x"),c=e(o,"y"),a=l(o,"x");o=l(o,"y");this.width=a-d;this.height=o-c;this.minX=d;this.minY=c},toObject:function(){return p(this.callSuper("toObject"),
{points:this.points.concat()})},_render:function(o){var d;o.beginPath();for(var c=0,a=this.points.length;c<a;c++){d=this.points[c];o.lineTo(d.x,d.y)}this.fill&&o.fill();if(this.stroke){o.closePath();o.stroke()}},complexity:function(){return this.points.length}});h.Polygon.ATTRIBUTE_NAMES="fill fill-opacity stroke stroke-width transform".split(" ");h.Polygon.fromElement=function(o,d){if(!o)return null;d||(d={});for(var c=h.parsePointsAttribute(o.getAttribute("points")),a=h.parseAttributes(o,h.Polygon.ATTRIBUTE_NAMES),
b=0,g=c.length;b<g;b++){c[b].x-=d.width/2||0;c[b].y-=d.height/2||0}return new h.Polygon(c,p(a,d))};h.Polygon.fromObject=function(o){return new h.Polygon(o.points,o)}}})();
(function(){var h=this.fabric||(this.fabric={}),p=h.util.array.min,e=h.util.array.max,l=h.util.object.extend;if(h.Path)console.warn("fabric.Path is already defined");else if(h.Object){h.Path=h.util.createClass(h.Object,{type:"path",initialize:function(d,c){c=c||{};this.setOptions(c);this._importProperties();this.originalState={};if(!d)throw Error("`path` argument is required");var a=Object.prototype.toString.call(d)==="[object Array]";if(this.path=a?d:d.match&&d.match(/[a-zA-Z][^a-zA-Z]*/g)){a||this._initializeFromArray(c);
(function(){var h=this.fabric||(this.fabric={}),p=h.util.array.min,e=h.util.array.max,l=h.util.object.extend;if(h.Path)h.warn("fabric.Path is already defined");else if(h.Object){h.Path=h.util.createClass(h.Object,{type:"path",initialize:function(d,c){c=c||{};this.setOptions(c);this._importProperties();this.originalState={};if(!d)throw Error("`path` argument is required");var a=Object.prototype.toString.call(d)==="[object Array]";if(this.path=a?d:d.match&&d.match(/[a-zA-Z][^a-zA-Z]*/g)){a||this._initializeFromArray(c);
this.setCoords();c.sourcePath&&this.setSourcePath(c.sourcePath)}},_initializeFromArray:function(d){var c="width"in d;d="height"in d;this.path=this._parsePath();if(!c||!d){l(this,this._parseDimensions());if(c)this.width=this.options.width;if(d)this.height=this.options.height}},_render:function(d){for(var c,a=0,b=0,g=0,m=0,q,r,u=-(this.width/2),v=-(this.height/2),A=0,w=this.path.length;A<w;++A){c=this.path[A];switch(c[0]){case "l":a+=c[1];b+=c[2];d.lineTo(a+u,b+v);break;case "L":a=c[1];b=c[2];d.lineTo(a+
u,b+v);break;case "h":a+=c[1];d.lineTo(a+u,b+v);break;case "H":a=c[1];d.lineTo(a+u,b+v);break;case "v":b+=c[1];d.lineTo(a+u,b+v);break;case "V":b=c[1];d.lineTo(a+u,b+v);break;case "m":a+=c[1];b+=c[2];d.moveTo(a+u,b+v);break;case "M":a=c[1];b=c[2];d.moveTo(a+u,b+v);break;case "c":q=a+c[5];r=b+c[6];g=a+c[3];m=b+c[4];d.bezierCurveTo(a+c[1]+u,b+c[2]+v,g+u,m+v,q+u,r+v);a=q;b=r;break;case "C":a=c[5];b=c[6];g=c[3];m=c[4];d.bezierCurveTo(c[1]+u,c[2]+v,g+u,m+v,a+u,b+v);break;case "s":q=a+c[3];r=b+c[4];g=2*
a-g;m=2*b-m;d.bezierCurveTo(g+u,m+v,a+c[1]+u,b+c[2]+v,q+u,r+v);a=q;b=r;break;case "S":q=c[3];r=c[4];g=2*a-g;m=2*b-m;d.bezierCurveTo(g+u,m+v,c[1]+u,c[2]+v,q+u,r+v);a=q;b=r;break;case "q":a+=c[3];b+=c[4];d.quadraticCurveTo(c[1]+u,c[2]+v,a+u,b+v);break;case "Q":a=c[3];b=c[4];g=c[1];m=c[2];d.quadraticCurveTo(g+u,m+v,a+u,b+v);break;case "T":q=a;r=b;a=c[1];b=c[2];g=-g+2*q;m=-m+2*r;d.quadraticCurveTo(g+u,m+v,a+u,b+v);break;case "a":break;case "A":break;case "z":case "Z":d.closePath();break}}},render:function(d,
@ -139,8 +139,8 @@ c){d.save();var a=this.transformMatrix;a&&d.transform(a[0],a[1],a[2],a[3],a[4],a
this.complexity()+"): "+JSON.stringify({top:this.top,left:this.left})+">"},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<g;b++){c=this.path[b];a=c.slice(1).trim().replace(/(\d)-/g,"$1###-").split(/\s|,|###/);d.push([c.charAt(0)].concat(a.map(parseFloat)))}return d},_parseDimensions:function(){function d(s){if(s[0]==="H")return s[1];return s[s.length-2]}function c(s){if(s[0]==="V")return s[1];return s[s.length-1]}var a=[],b=[],g,m,q=false,r,u;this.path.forEach(function(s,C){if(s[0]!=="H")g=C===0?d(s):d(this.path[C-1]);if(s[0]!=="V")m=C===0?c(s):c(this.path[C-1]);if(s[0]===s[0].toLowerCase())q=
true;r=q?g+d(s):s[0]==="V"?g:d(s);u=q?m+c(s):s[0]==="H"?m:c(s);var z=parseInt(r,10);isNaN(z)||a.push(z);z=parseInt(u,10);isNaN(z)||b.push(z)},this);var v=p(a),A=p(b),w=deltaY=0;v={top:A-deltaY,left:v-w,bottom:e(b)-deltaY,right:e(a)-w};v.width=v.right-v.left;v.height=v.bottom-v.top;return v}});h.Path.fromObject=function(d){return new h.Path(d.path,d)};var o=h.Path.ATTRIBUTE_NAMES="d fill fill-opacity fill-rule stroke stroke-width transform".split(" ");h.Path.fromElement=function(d,c){var a=h.parseAttributes(d,
o),b=a.d;delete a.d;return new h.Path(b,l(a,c))}}else console.warn("fabric.Path requires fabric.Object")})();
(function(){var h=this.fabric||(this.fabric={}),p=h.util.object.extend,e=h.util.array.invoke,l=h.Object.prototype.set,o=h.Object.prototype.toObject,d=h.util.string.camelize,c=h.util.string.capitalize;if(h.PathGroup)console.warn("fabric.PathGroup is already defined");else{h.PathGroup=h.util.createClass(h.Path,{type:"path-group",forceFillOverwrite:false,initialize:function(a,b){b=b||{};this.originalState={};this.paths=a;this.setOptions(b);this.initProperties();this.setCoords();b.sourcePath&&this.setSourcePath(b.sourcePath)},
o),b=a.d;delete a.d;return new h.Path(b,l(a,c))}}else h.warn("fabric.Path requires fabric.Object")})();
(function(){var h=this.fabric||(this.fabric={}),p=h.util.object.extend,e=h.util.array.invoke,l=h.Object.prototype.set,o=h.Object.prototype.toObject,d=h.util.string.camelize,c=h.util.string.capitalize;if(h.PathGroup)h.warn("fabric.PathGroup is already defined");else{h.PathGroup=h.util.createClass(h.Path,{type:"path-group",forceFillOverwrite:false,initialize:function(a,b){b=b||{};this.originalState={};this.paths=a;this.setOptions(b);this.initProperties();this.setCoords();b.sourcePath&&this.setSourcePath(b.sourcePath)},
initProperties:function(){this.stateProperties.forEach(function(a){if(a==="fill")this.set(a,this.options[a]);else if(a==="angle")this.setAngle(this.options[a]);else this[a]=this.options[a]},this)},render:function(a){if(this.stub){a.save();this.transform(a);this.stub.render(a,false);if(this.active){this.drawBorders(a);this.drawCorners(a)}}else{a.save();var b=this.transformMatrix;b&&a.transform(b[0],b[1],b[2],b[3],b[4],b[5]);this.transform(a);b=0;for(var g=this.paths.length;b<g;++b)this.paths[b].render(a,
true);if(this.active){this.drawBorders(a);this.hideCorners||this.drawCorners(a)}}a.restore()},set:function(a,b){if((a==="fill"||a==="overlayFill")&&this.isSameColor()){this[a]=b;for(var g=this.paths.length;g--;)this.paths[g].set(a,b)}else l.call(this,a,b);return this},toObject:function(){return p(o.call(this),{paths:e(this.getObjects(),"clone"),sourcePath:this.sourcePath})},toDatalessObject:function(){var a=this.toObject();if(this.sourcePath)a.paths=this.sourcePath;return a},toString:function(){return"#<fabric.PathGroup ("+
this.complexity()+"): { top: "+this.top+", left: "+this.left+" }>"},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;g<m;++g){b=this.objects[g];b.setCoords();for(var q in b.oCoords){c.push(b.oCoords[q].x);a.push(b.oCoords[q].y)}}b=e(c);g=l(c);c=e(a);a=l(a);g=g-b;a=a-c;this.width=
g;this.height=a;this.left=b+g/2;this.top=c+a/2},containsPoint:function(c){var a=this.get("width")/2,b=this.get("height")/2,g=this.get("left"),m=this.get("top");return g-a<c.x&&g+a>c.x&&m-b<c.y&&m+b>c.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"#<fabric.Text ("+this.complexity()+"): "+JSON.stringify({text:this.text,fontfamily:this.fontfamily})+">"},_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.height<e/l){normalizedWidth=~~(p.width*l/p.height);normalizedHeight=l}else if(l&&(p.height==p.width||p.height>p.width||p.height>l)){normalizedWidth=~~(p.width*l/p.height);normalizedHeight=l}else if(e&&e<p.width){normalizedHeight=~~(p.height*e/p.width);normalizedWidth=e}else{normalizedWidth=p.width;normalizedHeight=p.height}return{width:normalizedWidth,height:normalizedHeight}},getOriginalSize:function(){var p=this.getElement();
return{width:p.width,height:p.height}},setBorderVisibility:function(p){this._resetWidthHeight();this._adjustWidthHeightToBorders(p);this.setCoords()},setCornersVisibility:function(p){this.cornervisibility=!!p},render:function(p,e){p.save();e||this.transform(p);this._render(p);if(this.active&&!e){this.drawBorders(p);this.hideCorners||this.drawCorners(p)}p.restore()},toObject:function(){return h(this.callSuper("toObject"),{src:this.getSrc()})},getSrc:function(){return this.getElement().src},toString:function(){return'#<fabric.Image: { src: "'+
this.getSrc()+'" }>'},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")})();

View file

@ -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"

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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!');
}
},

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -285,7 +285,7 @@
return klass.fromElement(el, options);
}
catch(e) {
console.log(e.message || e);
fabric.log(e.message || e);
}
}
});

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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() {

View file

@ -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);
});
})();