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