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