diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..515294e0 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,40 @@ +{ + "globals": { + "__fontDefinitions": true, + "Cufon": true, + "G_vmlCanvasManager": true, + "fabric": true, + "ActiveXObject": true + }, + + "node": true, + "es5": false, + "browser": true, + + "boss": false, + "curly": false, + "debug": false, + "devel": false, + "eqeqeq": true, + "eqnull": true, + "evil": true, + "expr": true, + "forin": false, + "immed": true, + "laxbreak": true, + "loopfunc": true, + "multistr": true, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "unused": true +} \ No newline at end of file diff --git a/HEADER.js b/HEADER.js index e1c1f55d..d2345393 100644 --- a/HEADER.js +++ b/HEADER.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2012, Printio (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.9.13" }; +var fabric = fabric || { version: "0.9.14" }; if (typeof exports != 'undefined') { exports.fabric = fabric; diff --git a/dist/all.js b/dist/all.js index e5e6767e..e17e8ce2 100644 --- a/dist/all.js +++ b/dist/all.js @@ -1,7 +1,7 @@ /* build: `node build.js modules=ALL` */ /*! Fabric.js Copyright 2008-2012, Printio (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.9.13" }; +var fabric = fabric || { version: "0.9.14" }; if (typeof exports != 'undefined') { exports.fabric = fabric; @@ -1796,7 +1796,7 @@ fabric.Observable = { */ fire: function(eventName, options) { if (!this.__eventListeners) { - this.__eventListeners = { } + this.__eventListeners = { }; } var listenersForEvent = this.__eventListeners[eventName]; if (!listenersForEvent) return; @@ -1842,7 +1842,7 @@ fabric.Observable.off = fabric.Observable.stopObserving; array.splice(idx, 1); } return array; - }; + } /** * Returns random number between 2 specified ones. @@ -1914,19 +1914,19 @@ fabric.Observable.off = fabric.Observable.stopObserving; var start = +new Date(), duration = options.duration || 500, - finish = start + duration, time, pos, + finish = start + duration, time, onChange = options.onChange || function() { }, abort = options.abort || function() { return false; }, easing = options.easing || function(t, b, c, d) {return -c * Math.cos(t/d * (Math.PI/2)) + c + b;}, startValue = 'startValue' in options ? options.startValue : 0, - endValue = 'endValue' in options ? options.endValue : 100; + endValue = 'endValue' in options ? options.endValue : 100, byValue = options.byValue || endValue - startValue; options.onStart && options.onStart(); (function tick() { time = +new Date(); - currentTime = time > finish ? duration : (time - start); + var currentTime = time > finish ? duration : (time - start); onChange(easing(currentTime, startValue, byValue, duration)); if (time > finish || abort()) { options.onComplete && options.onComplete(); @@ -1941,7 +1941,7 @@ fabric.Observable.off = fabric.Observable.stopObserving; fabric.window.mozRequestAnimationFrame || fabric.window.oRequestAnimationFrame || fabric.window.msRequestAnimationFrame || - function(callback, element) { + function(callback) { fabric.window.setTimeout(callback, 1000 / 60); }; /** @@ -2014,6 +2014,15 @@ fabric.Observable.off = fabric.Observable.stopObserving; }); } + /** + * Groups SVG elements (usually those retrieved from SVG document) + * @static + * @memberOf fabric.util + * @method groupSVGElements + * @param {Array} elements + * @param {Object} options optional + * @return {String} path optional + */ function groupSVGElements(elements, options, path) { var object = elements.length > 1 ? new fabric.PathGroup(elements, options) @@ -2037,9 +2046,9 @@ fabric.Observable.off = fabric.Observable.stopObserving; fabric.util.groupSVGElements = groupSVGElements; })(); (function() { - + var slice = Array.prototype.slice; - + if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { if (this === void 0 || this === null) { @@ -2069,7 +2078,7 @@ fabric.Observable.off = fabric.Observable.stopObserving; } } return -1; - } + }; } if (!Array.prototype.forEach) { @@ -2077,7 +2086,7 @@ fabric.Observable.off = fabric.Observable.stopObserving; for (var i = 0, len = this.length >>> 0; i < len; i++) { if (i in this) { fn.call(context, this[i], i, this); - } + } } }; } @@ -2186,8 +2195,8 @@ fabric.Observable.off = fabric.Observable.stopObserving; */ function max(array, byProperty) { if (!array || array.length === 0) return undefined; - - var i = array.length - 1, + + var i = array.length - 1, result = byProperty ? array[i][byProperty] : array[i]; if (byProperty) { while (i--) { @@ -2215,8 +2224,8 @@ fabric.Observable.off = fabric.Observable.stopObserving; */ function min(array, byProperty) { if (!array || array.length === 0) return undefined; - - var i = array.length - 1, + + var i = array.length - 1, result = byProperty ? array[i][byProperty] : array[i]; if (byProperty) { @@ -2242,7 +2251,7 @@ fabric.Observable.off = fabric.Observable.stopObserving; min: min, max: max }; - + })(); (function(){ @@ -2333,11 +2342,11 @@ fabric.util.string = { }()); (function() { - + var slice = Array.prototype.slice, apply = Function.prototype.apply, - dummy = function() { }; - + Dummy = function() { }; + if (!Function.prototype.bind) { /** * Cross-browser approximation of ES5 Function.prototype.bind (not fully spec conforming) @@ -2349,22 +2358,22 @@ fabric.util.string = { Function.prototype.bind = function(thisArg) { var fn = this, args = slice.call(arguments, 1), bound; if (args.length) { - bound = function() { - return apply.call(fn, this instanceof dummy ? this : thisArg, args.concat(slice.call(arguments))); + bound = function() { + return apply.call(fn, this instanceof Dummy ? this : thisArg, args.concat(slice.call(arguments))); }; } else { - bound = function() { - return apply.call(fn, this instanceof dummy ? this : thisArg, arguments); + bound = function() { + return apply.call(fn, this instanceof Dummy ? this : thisArg, arguments); }; } - dummy.prototype = this.prototype; - bound.prototype = new dummy; - + Dummy.prototype = this.prototype; + bound.prototype = new Dummy(); + return bound; }; } - + })(); (function() { @@ -2381,7 +2390,7 @@ fabric.util.string = { var addMethods = function(klass, source, parent) { for (var property in source) { - if (property in klass.prototype && typeof klass.prototype[property] == 'function') { + if (property in klass.prototype && typeof klass.prototype[property] === 'function') { klass.prototype[property] = (function(property) { return function() { @@ -2394,7 +2403,7 @@ fabric.util.string = { if (property !== 'initialize') { return returnValue; } - } + }; })(property); } else { @@ -2412,7 +2421,7 @@ fabric.util.string = { } }; - function subclass() { }; + function Subclass() { } /** * Helper for creation of "classes" @@ -2434,8 +2443,8 @@ fabric.util.string = { klass.subclasses = [ ]; if (parent) { - subclass.prototype = parent.prototype; - klass.prototype = new subclass; + Subclass.prototype = parent.prototype; + klass.prototype = new Subclass(); parent.subclasses.push(klass); } for (var i = 0, length = properties.length; i < length; i++) { @@ -2450,7 +2459,7 @@ fabric.util.string = { fabric.util.createClass = createClass; })(); -(function (global) { +(function () { /* EVENT HANDLING */ @@ -2635,26 +2644,26 @@ fabric.util.string = { return { x: pointerX(event), y: pointerY(event) }; } - function pointerX(event) { + var pointerX = function(event) { var docElement = fabric.document.documentElement, body = fabric.document.body || { scrollLeft: 0 }; // looks like in IE (<9) clientX at certain point (apparently when mouseup fires on VML element) // is represented as COM object, with all the consequences, like "unknown" type and error on [[Get]] // need to investigate later - return event.pageX || ((typeof event.clientX != 'unknown' ? event.clientX : 0) + + return event.pageX || ((typeof event.clientX !== 'unknown' ? event.clientX : 0) + (docElement.scrollLeft || body.scrollLeft) - (docElement.clientLeft || 0)); - } + }; - function pointerY(event) { + var pointerY = function(event) { var docElement = fabric.document.documentElement, body = fabric.document.body || { scrollTop: 0 }; - return event.pageY || ((typeof event.clientY != 'unknown' ? event.clientY : 0) + + return event.pageY || ((typeof event.clientY !== 'unknown' ? event.clientY : 0) + (docElement.scrollTop || body.scrollTop) - (docElement.clientTop || 0)); - } + }; if (fabric.isTouchSupported) { pointerX = function(event) { @@ -2669,7 +2678,7 @@ fabric.util.string = { fabric.util.object.extend(fabric.util, fabric.Observable); -})(this); +})(); (function () { /** @@ -2681,7 +2690,7 @@ fabric.util.string = { * @return {HTMLElement} Element that was passed as a first argument */ function setStyle(element, styles) { - var elementStyle = element.style, match; + var elementStyle = element.style; if (!elementStyle) { return element; } @@ -2708,8 +2717,6 @@ fabric.util.string = { var parseEl = fabric.document.createElement('div'), supportsOpacity = typeof parseEl.style.opacity === 'string', supportsFilters = typeof parseEl.style.filter === 'string', - view = fabric.document.defaultView, - supportsGCS = view && typeof view.getComputedStyle !== 'undefined', reOpacity = /alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/, /** @ignore */ @@ -2744,7 +2751,7 @@ fabric.util.string = { })(); (function() { - + var _slice = Array.prototype.slice; /** @@ -2765,12 +2772,13 @@ fabric.util.string = { * @param {Object} arrayLike * @return {Array} */ - function toArray(arrayLike) { + var toArray = function(arrayLike) { return _slice.call(arrayLike, 0); - } + }; + var sliceCanConvertNodelists; try { - var sliceCanConvertNodelists = toArray(fabric.document.childNodes) instanceof Array; + sliceCanConvertNodelists = toArray(fabric.document.childNodes) instanceof Array; } catch(err) { } @@ -2818,7 +2826,7 @@ fabric.util.string = { function addClass(element, className) { if ((' ' + element.className + ' ').indexOf(' ' + className + ' ') === -1) { element.className += (element.className ? ' ' : '') + className; - } + } } /** @@ -2856,7 +2864,7 @@ fabric.util.string = { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; element = element.offsetParent; - } + } while (element); return ({ left: valueL, top: valueT }); } @@ -2866,12 +2874,12 @@ fabric.util.string = { var selectProp = 'userSelect' in style ? 'userSelect' - : 'MozUserSelect' in style - ? 'MozUserSelect' - : 'WebkitUserSelect' in style - ? 'WebkitUserSelect' - : 'KhtmlUserSelect' in style - ? 'KhtmlUserSelect' + : 'MozUserSelect' in style + ? 'MozUserSelect' + : 'WebkitUserSelect' in style + ? 'WebkitUserSelect' + : 'KhtmlUserSelect' in style + ? 'KhtmlUserSelect' : ''; /** @@ -2888,7 +2896,7 @@ fabric.util.string = { if (selectProp) { element.style[selectProp] = 'none'; } - else if (typeof element.unselectable == 'string') { + else if (typeof element.unselectable === 'string') { element.unselectable = 'on'; } return element; @@ -2908,7 +2916,7 @@ fabric.util.string = { if (selectProp) { element.style[selectProp] = ''; } - else if (typeof element.unselectable == 'string') { + else if (typeof element.unselectable === 'string') { element.unselectable = ''; } return element; @@ -2928,28 +2936,28 @@ fabric.util.string = { * @param {Function} callback Callback to execute when script is finished loading */ function getScript(url, callback) { - var headEl = fabric.document.getElementsByTagName("head")[0], - scriptEl = fabric.document.createElement('script'), - loading = true; + var headEl = fabric.document.getElementsByTagName("head")[0], + scriptEl = fabric.document.createElement('script'), + loading = true; - scriptEl.type = 'text/javascript'; - scriptEl.setAttribute('runat', 'server'); + scriptEl.type = 'text/javascript'; + scriptEl.setAttribute('runat', 'server'); - /** @ignore */ - scriptEl.onload = /** @ignore */ scriptEl.onreadystatechange = function(e) { - if (loading) { - if (typeof this.readyState == 'string' && - this.readyState !== 'loaded' && - this.readyState !== 'complete') return; - loading = false; - callback(e || fabric.window.event); - scriptEl = scriptEl.onload = scriptEl.onreadystatechange = null; - } - }; - scriptEl.src = url; - headEl.appendChild(scriptEl); - // causes issue in Opera - // headEl.removeChild(scriptEl); + /** @ignore */ + scriptEl.onload = /** @ignore */ scriptEl.onreadystatechange = function(e) { + if (loading) { + if (typeof this.readyState === 'string' && + this.readyState !== 'loaded' && + this.readyState !== 'complete') return; + loading = false; + callback(e || fabric.window.event); + scriptEl = scriptEl.onload = scriptEl.onreadystatechange = null; + } + }; + scriptEl.src = url; + headEl.appendChild(scriptEl); + // causes issue in Opera + // headEl.removeChild(scriptEl); } fabric.util.getScript = getScript; @@ -2961,14 +2969,14 @@ fabric.util.string = { fabric.util.addClass = addClass; fabric.util.wrapElement = wrapElement; fabric.util.getElementOffset = getElementOffset; - + })(); (function(){ - + function addParamToUrl(url, param) { return url + (/\?/.test(url) ? '&' : '?') + param; } - + var makeXHR = (function() { var factories = [ function() { return new ActiveXObject("Microsoft.XMLHTTP"); }, @@ -2987,8 +2995,8 @@ fabric.util.string = { } })(); - function emptyFn() { }; - + function emptyFn() { } + /** * Cross-browser abstraction for sending XMLHttpRequest * @method request @@ -3005,34 +3013,34 @@ fabric.util.string = { var method = options.method ? options.method.toUpperCase() : 'GET', onComplete = options.onComplete || function() { }, - request = makeXHR(), + xhr = makeXHR(), body; - + /** @ignore */ - request.onreadystatechange = function() { - if (request.readyState === 4) { - onComplete(request); - request.onreadystatechange = emptyFn; + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + onComplete(xhr); + xhr.onreadystatechange = emptyFn; } }; - + if (method === 'GET') { body = null; - if (typeof options.parameters == 'string') { + if (typeof options.parameters === 'string') { url = addParamToUrl(url, options.parameters); } } - request.open(method, url, true); - + xhr.open(method, url, true); + if (method === 'POST' || method === 'PUT') { - request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); } - request.send(body); - return request; - }; - + xhr.send(body); + return xhr; + } + fabric.util.request = request; })(); (function() { @@ -3058,7 +3066,8 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInOutQuad(t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t + b; + t /= (d/2); + if (t < 1) return c/2*t*t + b; return -c/2 * ((--t)*(t-2) - 1) + b; } @@ -3083,7 +3092,8 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInOutCubic(t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t + b; + t /= d/2; + if (t < 1) return c/2*t*t*t + b; return c/2*((t-=2)*t*t + 2) + b; } @@ -3108,7 +3118,8 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInOutQuart(t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t*t + b; + t /= d/2; + if (t < 1) return c/2*t*t*t*t + b; return -c/2 * ((t-=2)*t*t*t - 2) + b; } @@ -3133,7 +3144,8 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInOutQuint(t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; + t /= d/2; + if (t < 1) return c/2*t*t*t*t*t + b; return c/2*((t-=2)*t*t*t*t + 2) + b; } @@ -3166,7 +3178,7 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInExpo(t, b, c, d) { - return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; + return (t===0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; } /** @@ -3174,7 +3186,7 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeOutExpo(t, b, c, d) { - return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; + return (t===d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; } /** @@ -3182,9 +3194,10 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInOutExpo(t, b, c, d) { - if (t==0) return b; - if (t==d) return b+c; - if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; + if (t===0) return b; + if (t===d) return b+c; + t /= d/2; + if (t < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; } @@ -3209,7 +3222,8 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInOutCirc(t, b, c, d) { - if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; + t /= d/2; + if (t < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; } @@ -3219,9 +3233,12 @@ fabric.util.string = { */ function easeInElastic(t, b, c, d) { var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); + if (t===0) return b; + t /= d; + if (t===1) return b+c; + if (!p) p=d*0.3; + if (a < Math.abs(c)) { a=c; s=p/4; } + else s = p/(2*Math.PI) * Math.asin (c/a); return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; } @@ -3231,9 +3248,12 @@ fabric.util.string = { */ function easeOutElastic(t, b, c, d) { var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); + if (t===0) return b; + t /= d; + if (t===1) return b+c; + if (!p) p=d*0.3; + if (a < Math.abs(c)) { a=c; s=p/4; } + else s = p/(2*Math.PI) * Math.asin (c/a); return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; } @@ -3243,11 +3263,14 @@ fabric.util.string = { */ function easeInOutElastic(t, b, c, d) { var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); - if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; - return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; + if (t===0) return b; + t /= d/2; + if (t===2) return b+c; + if (!p) p=d*(0.3*1.5); + if (a < Math.abs(c)) { a=c; s=p/4; } + else s = p/(2*Math.PI) * Math.asin (c/a); + if (t < 1) return -0.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b; } /** @@ -3255,7 +3278,7 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInBack(t, b, c, d, s) { - if (s == undefined) s = 1.70158; + if (s === undefined) s = 1.70158; return c*(t/=d)*t*((s+1)*t - s) + b; } @@ -3264,7 +3287,7 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeOutBack(t, b, c, d, s) { - if (s == undefined) s = 1.70158; + if (s === undefined) s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; } @@ -3273,8 +3296,9 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInOutBack(t, b, c, d, s) { - if (s == undefined) s = 1.70158; - if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; + if (s === undefined) s = 1.70158; + t /= d/2; + if (t < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; } @@ -3294,11 +3318,11 @@ fabric.util.string = { if ((t/=d) < (1/2.75)) { return c*(7.5625*t*t) + b; } else if (t < (2/2.75)) { - return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; + return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b; } else if (t < (2.5/2.75)) { - return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; + return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b; } else { - return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; + return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b; } } @@ -3307,8 +3331,8 @@ fabric.util.string = { * @memberOf fabric.util.ease */ function easeInOutBounce(t, b, c, d) { - if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b; - return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b; + if (t < d/2) return easeInBounce (t*2, 0, c, d) * 0.5 + b; + return easeOutBounce (t*2-d, 0, c, d) * 0.5 + c*0.5 + b; } /** @namespace fabric.util.ease */ @@ -3435,7 +3459,7 @@ fabric.util.string = { ownAttributes = extend(ownAttributes, extend(getGlobalStylesForElement(element), fabric.parseStyleAttribute(element))); return extend(parentAttributes, ownAttributes); - }; + } /** * Parses "transform" attribute, returning an array of values @@ -3566,9 +3590,9 @@ fabric.util.string = { matrix = args; break; } - }) + }); return matrix; - } + }; })(); /** @@ -3588,17 +3612,21 @@ fabric.util.string = { var asPairs = points.indexOf(',') > -1; points = points.split(/\s+/); - var parsedPoints = [ ]; + var parsedPoints = [ ], i, len; // points could look like "10,20 30,40" or "10 20 30 40" if (asPairs) { - for (var i = 0, len = points.length; i < len; i++) { - var pair = points[i].split(','); - parsedPoints.push({ x: parseFloat(pair[0]), y: parseFloat(pair[1]) }); - } + i = 0; + len = points.length; + for (; i < len; i++) { + var pair = points[i].split(','); + parsedPoints.push({ x: parseFloat(pair[0]), y: parseFloat(pair[1]) }); + } } else { - for (var i = 0, len = points.length; i < len; i+=2) { + i = 0; + len = points.length; + for (; i < len; i+=2) { parsedPoints.push({ x: parseFloat(points[i]), y: parseFloat(points[i+1]) }); } } @@ -3609,7 +3637,7 @@ fabric.util.string = { } return parsedPoints; - }; + } /** * Parses "style" attribute, retuning an object with values @@ -3622,22 +3650,24 @@ fabric.util.string = { function parseStyleAttribute(element) { var oStyle = { }, style = element.getAttribute('style'); - if (style) { - if (typeof style == 'string') { - style = style.replace(/;$/, '').split(';').forEach(function (current) { - var attr = current.split(':'); - oStyle[normalizeAttr(attr[0].trim().toLowerCase())] = attr[1].trim(); - }); - } else { - for (var prop in style) { - if (typeof style[prop] !== 'undefined') { - oStyle[normalizeAttr(prop.toLowerCase())] = style[prop]; - } - } + + if (!style) return oStyle; + + if (typeof style === 'string') { + style = style.replace(/;$/, '').split(';').forEach(function (current) { + var attr = current.split(':'); + oStyle[normalizeAttr(attr[0].trim().toLowerCase())] = attr[1].trim(); + }); + } + else { + for (var prop in style) { + if (typeof style[prop] === 'undefined') continue; + oStyle[normalizeAttr(prop.toLowerCase())] = style[prop]; } } + return oStyle; - }; + } function resolveGradients(instances) { for (var i = instances.length; i--; ) { @@ -3666,7 +3696,7 @@ fabric.util.string = { * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created. */ function parseElements(elements, callback, options, reviver) { - var instances = Array(elements.length), i = elements.length; + var instances = new Array(elements.length), i = elements.length; function checkIfDone() { if (--i === 0) { @@ -3707,7 +3737,7 @@ fabric.util.string = { checkIfDone(); } } - }; + } /** * Returns CSS rules for a given SVG document @@ -3731,12 +3761,12 @@ fabric.util.string = { styleContents = styleContents.replace(/\/\*[\s\S]*?\*\//g, ''); rules = styleContents.match(/[^{]*\{[\s\S]*?\}/g); - rules = rules.map(function(rule) { return rule.trim() }); + rules = rules.map(function(rule) { return rule.trim(); }); rules.forEach(function(rule) { - var match = rule.match(/([\s\S]*?)\s*\{([^}]*)\}/), - rule = match[1], - declaration = match[2].trim(), + var match = rule.match(/([\s\S]*?)\s*\{([^}]*)\}/); + rule = match[1]; + var declaration = match[2].trim(), propertyValuePairs = declaration.replace(/;$/, '').split(/\s*;\s*/); if (!allRules[rule]) { @@ -3898,7 +3928,7 @@ fabric.util.string = { * @param {String} url * @param {Function} callback */ - get: function (url, callback) { + get: function () { /* NOOP */ }, @@ -3907,7 +3937,7 @@ fabric.util.string = { * @param {String} url * @param {Object} object */ - set: function (url, object) { + set: function () { /* NOOP */ } }; @@ -3991,7 +4021,7 @@ fabric.util.string = { } } else if (fabric.window.ActiveXObject) { - var doc = new ActiveXObject('Microsoft.XMLDOM'); + doc = new ActiveXObject('Microsoft.XMLDOM'); doc.async = 'false'; //IE chokes on DOCTYPE doc.loadXML(string.replace(//i,'')); @@ -4045,7 +4075,7 @@ fabric.util.string = { createSVGFontFacesMarkup: createSVGFontFacesMarkup }); -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function() { @@ -4140,10 +4170,8 @@ fabric.util.string = { */ var colorStopEls = el.getElementsByTagName('stop'), - el, offset, colorStops = { }, - colorStopFromStyle, coords = { x1: el.getAttribute('x1') || 0, y1: el.getAttribute('y1') || 0, @@ -4215,15 +4243,17 @@ fabric.util.string = { function getGradientDefs(doc) { var linearGradientEls = doc.getElementsByTagName('linearGradient'), radialGradientEls = doc.getElementsByTagName('radialGradient'), - el, + el, i, gradientDefs = { }; - for (var i = linearGradientEls.length; i--; ) { + i = linearGradientEls.length; + for (; i--; ) { el = linearGradientEls[i]; gradientDefs[el.getAttribute('id')] = el; } - for (var i = radialGradientEls.length; i--; ) { + i = radialGradientEls.length; + for (; i--; ) { el = radialGradientEls[i]; gradientDefs[el.getAttribute('id')] = el; } @@ -4235,20 +4265,20 @@ fabric.util.string = { })(); (function(global) { - + "use strict"; - + /* Adaptation of work of Kevin Lindsey (kevin@kevlindev.com) */ - + var fabric = global.fabric || (global.fabric = { }); - if (fabric.Point) { + if (fabric.Point) { fabric.warn('fabric.Point is already defined'); return; } fabric.Point = Point; - + /** * @name Point * @memberOf fabric @@ -4262,11 +4292,11 @@ fabric.util.string = { this.init(x, y); } } - + Point.prototype = /** @scope fabric.Point.prototype */ { - + constructor: Point, - + /** * @method init * @param {Number} x @@ -4276,7 +4306,7 @@ fabric.util.string = { this.x = x; this.y = y; }, - + /** * @method add * @param {fabric.Point} that @@ -4285,7 +4315,7 @@ fabric.util.string = { add: function (that) { return new Point(this.x + that.x, this.y + that.y); }, - + /** * @method addEquals * @param {fabric.Point} that @@ -4296,7 +4326,7 @@ fabric.util.string = { this.y += that.y; return this; }, - + /** * @method scalarAdd * @param {Number} scalar @@ -4305,7 +4335,7 @@ fabric.util.string = { scalarAdd: function (scalar) { return new Point(this.x + scalar, this.y + scalar); }, - + /** * @method scalarAddEquals * @param {Number} scalar @@ -4316,7 +4346,7 @@ fabric.util.string = { this.y += scalar; return this; }, - + /** * @method subtract * @param {fabric.Point} that @@ -4325,7 +4355,7 @@ fabric.util.string = { subtract: function (that) { return new Point(this.x - that.x, this.y - that.y); }, - + /** * @method subtractEquals * @param {fabric.Point} that @@ -4336,89 +4366,89 @@ fabric.util.string = { this.y -= that.y; return this; }, - + scalarSubtract: function (scalar) { return new Point(this.x - scalar, this.y - scalar); }, - + scalarSubtractEquals: function (scalar) { this.x -= scalar; this.y -= scalar; return this; }, - + multiply: function (scalar) { return new Point(this.x * scalar, this.y * scalar); }, - + multiplyEquals: function (scalar) { this.x *= scalar; this.y *= scalar; return this; }, - + divide: function (scalar) { return new Point(this.x / scalar, this.y / scalar); }, - + divideEquals: function (scalar) { this.x /= scalar; this.y /= scalar; return this; }, - + eq: function (that) { - return (this.x == that.x && this.y == that.y); + return (this.x === that.x && this.y === that.y); }, - + lt: function (that) { return (this.x < that.x && this.y < that.y); }, - + lte: function (that) { return (this.x <= that.x && this.y <= that.y); }, - + gt: function (that) { return (this.x > that.x && this.y > that.y); }, - + gte: function (that) { return (this.x >= that.x && this.y >= that.y); }, - + lerp: function (that, t) { return new Point(this.x + (that.x - this.x) * t, this.y + (that.y - this.y) * t); }, - + distanceFrom: function (that) { var dx = this.x - that.x, dy = this.y - that.y; return Math.sqrt(dx * dx + dy * dy); }, - + min: function (that) { return new Point(Math.min(this.x, that.x), Math.min(this.y, that.y)); }, - + max: function (that) { return new Point(Math.max(this.x, that.x), Math.max(this.y, that.y)); }, - + toString: function () { return this.x + "," + this.y; }, - + setXY: function (x, y) { this.x = x; this.y = y; }, - + setFromPoint: function (that) { this.x = that.x; this.y = that.y; }, - + swap: function (that) { var x = this.x, y = this.y; @@ -4428,8 +4458,8 @@ fabric.util.string = { that.y = y; } }; - -})(typeof exports != 'undefined' ? exports : this); + +})(typeof exports !== 'undefined' ? exports : this); (function(global) { "use strict"; @@ -4492,7 +4522,7 @@ fabric.util.string = { ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x), ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x), u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y); - if (u_b != 0) { + if (u_b !== 0) { var ua = ua_t / u_b, ub = ub_t / u_b; if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) { @@ -4504,7 +4534,7 @@ fabric.util.string = { } } else { - if (ua_t == 0 || ub_t == 0) { + if (ua_t === 0 || ub_t === 0) { result = new Intersection("Coincident"); } else { @@ -4578,18 +4608,18 @@ fabric.util.string = { return result; }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { - + "use strict"; - + var fabric = global.fabric || (global.fabric = { }); - + if (fabric.Color) { fabric.warn('fabric.Color is already defined.'); return; } - + /** * The purpose of {@link fabric.Color} is to abstract and encapsulate common color operations; * {@link fabric.Color} is a constructor and creates instances of {@link fabric.Color} objects. @@ -4606,11 +4636,11 @@ fabric.util.string = { this._tryParsingColor(color); } } - + fabric.Color = Color; - + fabric.Color.prototype = /** @scope fabric.Color.prototype */ { - + /** * @private * @method _tryParsingColor @@ -4672,19 +4702,19 @@ fabric.util.string = { var source = this.getSource(); var r = source[0].toString(16); - r = (r.length == 1) ? ('0' + r) : r; + r = (r.length === 1) ? ('0' + r) : r; var g = source[1].toString(16); - g = (g.length == 1) ? ('0' + g) : g; + g = (g.length === 1) ? ('0' + g) : g; var b = source[2].toString(16); - b = (b.length == 1) ? ('0' + b) : b; + b = (b.length === 1) ? ('0' + b) : b; return r.toUpperCase() + g.toUpperCase() + b.toUpperCase(); }, /** - * Gets value of alpha channel for this color + * Gets value of alpha channel for this color * @method getAlpha * @return {Number} 0-1 */ @@ -4726,8 +4756,9 @@ fabric.util.string = { toBlackWhite: function(threshold) { var source = this.getSource(), average = (source[0] * 0.3 + source[1] * 0.59 + source[2] * 0.11).toFixed(0), - currentAlpha = source[3], - threshold = threshold || 127; + currentAlpha = source[3]; + + threshold = threshold || 127; average = (Number(average) < Number(threshold)) ? 0 : 255; this.setSource([average, average, average, currentAlpha]); @@ -4760,14 +4791,14 @@ fabric.util.string = { return this; } }; - + /** * Regex matching color in RGB or RGBA formats (ex: rgb(0, 0, 0), rgb(255, 100, 10, 0.5), rgb(1,1,1)) * @static * @field */ fabric.Color.reRGBa = /^rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(\d+(?:\.\d+)?))?\)$/; - + /** * Regex matching color in HEX format (ex: #FF5555, 010155, aff) * @static @@ -4784,7 +4815,7 @@ fabric.util.string = { fabric.Color.fromRgb = function(color) { return Color.fromSource(Color.sourceFromRgb(color)); }; - + /** * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in RGB or RGBA format * @method sourceFromRgb @@ -4822,7 +4853,7 @@ fabric.util.string = { fabric.Color.fromHex = function(color) { return Color.fromSource(Color.sourceFromHex(color)); }; - + /** * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HEX format * @static @@ -4846,7 +4877,7 @@ fabric.util.string = { ]; } }; - + /** * Returns new color object, when given color in array representation (ex: [200, 100, 100, 0.5]) * @static @@ -4859,8 +4890,8 @@ fabric.util.string = { return oColor; }; -})(typeof exports != 'undefined' ? exports : this); -(function (global) { +})(typeof exports !== 'undefined' ? exports : this); +(function () { "use strict"; @@ -4965,7 +4996,7 @@ fabric.util.string = { * @method onBeforeScaleRotate * @param {fabric.Object} target Object that's about to be scaled/rotated */ - onBeforeScaleRotate: function (target) { + onBeforeScaleRotate: function () { /* NOOP */ }, @@ -5343,39 +5374,24 @@ fabric.util.string = { this.clearContext(canvasToDrawOn); } - var length = this._objects.length, - activeGroup = this.getActiveGroup(), + var activeGroup = this.getActiveGroup(), startTime = new Date(); if (this.clipTo) { - canvasToDrawOn.save(); - canvasToDrawOn.beginPath(); - this.clipTo(canvasToDrawOn); - canvasToDrawOn.clip(); + this._clipCanvas(canvasToDrawOn); } canvasToDrawOn.fillStyle = this.backgroundColor; canvasToDrawOn.fillRect(0, 0, this.width, this.height); - if (typeof this.backgroundImage == 'object') { - canvasToDrawOn.save(); - canvasToDrawOn.globalAlpha = this.backgroundImageOpacity; - - if (this.backgroundImageStretch) { - canvasToDrawOn.drawImage(this.backgroundImage, 0, 0, this.width, this.height); - } - else { - canvasToDrawOn.drawImage(this.backgroundImage, 0, 0); - } - canvasToDrawOn.restore(); + if (typeof this.backgroundImage === 'object') { + this._drawBackroundImage(canvasToDrawOn); } - if (length) { - for (var i = 0; i < length; ++i) { - if (!activeGroup || - (activeGroup && this._objects[i] && !activeGroup.contains(this._objects[i]))) { - this._draw(canvasToDrawOn, this._objects[i]); - } + for (var i = 0, length = this._objects.length; i < length; ++i) { + if (!activeGroup || + (activeGroup && this._objects[i] && !activeGroup.contains(this._objects[i]))) { + this._draw(canvasToDrawOn, this._objects[i]); } } @@ -5406,6 +5422,26 @@ fabric.util.string = { return this; }, + _clipCanvas: function(canvasToDrawOn) { + canvasToDrawOn.save(); + canvasToDrawOn.beginPath(); + this.clipTo(canvasToDrawOn); + canvasToDrawOn.clip(); + }, + + _drawBackroundImage: function(canvasToDrawOn) { + canvasToDrawOn.save(); + canvasToDrawOn.globalAlpha = this.backgroundImageOpacity; + + if (this.backgroundImageStretch) { + canvasToDrawOn.drawImage(this.backgroundImage, 0, 0, this.width, this.height); + } + else { + canvasToDrawOn.drawImage(this.backgroundImage, 0, 0); + } + canvasToDrawOn.restore(); + }, + /** * Method to render only the top canvas. * Also used to render the group selection box. @@ -5638,8 +5674,9 @@ fabric.util.string = { var data = { objects: this._objects.map(function (instance) { // TODO (kangax): figure out how to clean this up + var originalValue; if (!this.includeDefaultValues) { - var originalValue = instance.includeDefaultValues; + originalValue = instance.includeDefaultValues; instance.includeDefaultValues = false; } var object = instance[methodName](); @@ -5964,9 +6001,9 @@ fabric.util.string = { try { el.toDataURL('image/jpeg', 0); return true; - } catch (e) { - return false; } + catch (e) { } + return false; default: return null; @@ -5982,8 +6019,7 @@ fabric.util.string = { */ fabric.StaticCanvas.prototype.toJSON = fabric.StaticCanvas.prototype.toObject; -})(typeof exports != 'undefined' ? exports : this); - +})(); (function() { var extend = fabric.util.object.extend, @@ -6032,7 +6068,7 @@ fabric.util.string = { function ProtoProxy(){ } ProtoProxy.prototype = fabric.StaticCanvas.prototype; - fabric.Canvas.prototype = new ProtoProxy; + fabric.Canvas.prototype = new ProtoProxy(); var InteractiveMethods = /** @scope fabric.Canvas.prototype */ { @@ -6175,7 +6211,7 @@ fabric.util.string = { _this.__onMouseMove(e); }; - this._onResize = function (e) { + this._onResize = function () { _this.calcOffset(); }; @@ -6202,6 +6238,8 @@ fabric.util.string = { */ __onMouseUp: function (e) { + var target; + if (this.isDrawingMode && this._isCurrentlyDrawing) { this._finalizeDrawingPath(); this.fire('mouse:up', { e: e }); @@ -6210,9 +6248,9 @@ fabric.util.string = { if (this._currentTransform) { - var transform = this._currentTransform, - target = transform.target; + var transform = this._currentTransform; + target = transform.target; if (target._scaling) { target._scaling = false; } @@ -6259,7 +6297,7 @@ fabric.util.string = { }, 50); this.fire('mouse:up', { target: target, e: e }); - target && target.fire('mouseup', { e: e }) + target && target.fire('mouseup', { e: e }); }, /** @@ -6274,7 +6312,7 @@ fabric.util.string = { __onMouseDown: function (e) { // accept only left clicks - var isLeftClick = 'which' in e ? e.which == 1 : e.button == 1; + var isLeftClick = 'which' in e ? e.which === 1 : e.button === 1; if (!isLeftClick && !fabric.isTouchSupported) return; if (this.isDrawingMode) { @@ -6310,7 +6348,7 @@ fabric.util.string = { // rotate and scale will happen at the same time this.stateful && target.saveState(); - if (corner = target._findTargetCorner(e, this._offset)) { + if ((corner = target._findTargetCorner(e, this._offset))) { this.onBeforeScaleRotate(target); } @@ -6346,6 +6384,8 @@ fabric.util.string = { */ __onMouseMove: function (e) { + var target; + if (this.isDrawingMode) { if (this._isCurrentlyDrawing) { this._captureDrawingPath(e); @@ -6354,11 +6394,12 @@ fabric.util.string = { return; } - var groupSelector = this._groupSelector; + var groupSelector = this._groupSelector, pointer; // We initially clicked in an empty area, so we draw a box for multiple selection. if (groupSelector !== null) { - var pointer = getPointer(e); + pointer = getPointer(e); + groupSelector.left = pointer.x - this._offset.left - groupSelector.ex; groupSelector.top = pointer.y - this._offset.top - groupSelector.ey; this.renderTop(); @@ -6372,7 +6413,7 @@ fabric.util.string = { // what part of the pictures we are hovering to change the caret symbol. // We won't do that while dragging or rotating in order to improve the // performance. - var target = this.findTarget(e); + target = this.findTarget(e); if (!target) { // image/text was hovered-out from, we remove its borders @@ -6394,8 +6435,9 @@ fabric.util.string = { } else { // object is being transformed (scaled/rotated/moved/etc.) - var pointer = getPointer(e), - x = pointer.x, + pointer = getPointer(e); + + var x = pointer.x, y = pointer.y; this._currentTransform.target.isMoving = true; @@ -6582,7 +6624,7 @@ fabric.util.string = { corner, pointer = getPointer(e); - if (corner = target._findTargetCorner(e, this._offset)) { + if ((corner = target._findTargetCorner(e, this._offset))) { action = (corner === 'ml' || corner === 'mr') ? 'scaleX' : (corner === 'mt' || corner === 'mb') @@ -6712,17 +6754,14 @@ fabric.util.string = { minY = utilMin(this._freeDrawingYPoints), maxX = utilMax(this._freeDrawingXPoints), maxY = utilMax(this._freeDrawingYPoints), - ctx = this.contextTop, path = [ ], - xPoint, - yPoint, xPoints = this._freeDrawingXPoints, yPoints = this._freeDrawingYPoints; path.push('M ', xPoints[0] - minX, ' ', yPoints[0] - minY, ' '); - for (var i = 1; xPoint = xPoints[i], yPoint = yPoints[i]; i++) { - path.push('L ', xPoint - minX, ' ', yPoint - minY, ' '); + for (var i = 1, len = xPoints.length; i < len; i++) { + path.push('L ', xPoints[i] - minX, ' ', yPoints[i] - minY, ' '); } // TODO (kangax): maybe remove Path creation from here, to decouple fabric.Canvas from fabric.Path, @@ -6887,9 +6926,7 @@ fabric.util.string = { }, _findSelectedObjects: function (e) { - var target, - targetRegion, - group = [ ], + var group = [ ], x1 = this._groupSelector.ex, y1 = this._groupSelector.ey, x2 = x1 + this._groupSelector.left, @@ -6918,7 +6955,7 @@ fabric.util.string = { this.setActiveObject(group[0], e); } else if (group.length > 1) { - var group = new fabric.Group(group); + group = new fabric.Group(group); this.setActiveGroup(group); group.saveCoords(); this.fire('selection:created', { target: group }); @@ -6961,11 +6998,11 @@ fabric.util.string = { } } } - for (var i = 0, len = possibleTargets.length; i < len; i++) { - var pointer = this.getPointer(e); - var isTransparent = this._isTargetTransparent(possibleTargets[i], pointer.x, pointer.y); + for (var j = 0, len = possibleTargets.length; j < len; j++) { + pointer = this.getPointer(e); + var isTransparent = this._isTargetTransparent(possibleTargets[j], pointer.x, pointer.y); if (!isTransparent) { - target = possibleTargets[i]; + target = possibleTargets[j]; this.relatedTarget = target; break; } @@ -7362,6 +7399,86 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { } } + /** @ignore */ + function loadObject(obj, index) { + + var pathProp = obj.paths ? 'paths' : 'path'; + var path = obj[pathProp]; + + delete obj[pathProp]; + + if (typeof path !== 'string') { + if (obj.type === 'image') { + fabric[fabric.util.string.capitalize(obj.type)].fromObject(obj, function (o) { + onObjectLoaded(o, index); + }); + } + else { + var klass = fabric[fabric.util.string.camelize(fabric.util.string.capitalize(obj.type))]; + if (!klass || !klass.fromObject) return; + + // restore path + if (path) { + obj[pathProp] = path; + } + onObjectLoaded(klass.fromObject(obj), index); + } + } + else { + if (obj.type === 'image') { + fabric.util.loadImage(path, function (image) { + var oImg = new fabric.Image(image); + + oImg.setSourcePath(path); + + fabric.util.object.extend(oImg, obj); + oImg.setAngle(obj.angle); + + onObjectLoaded(oImg, index); + }); + } + else if (obj.type === 'text') { + + if (obj.useNative) { + onObjectLoaded(fabric.Text.fromObject(obj), index); + } + else { + obj.path = path; + var object = fabric.Text.fromObject(obj); + var onscriptload = function () { + // TODO (kangax): find out why Opera refuses to work without this timeout + if (Object.prototype.toString.call(fabric.window.opera) === '[object Opera]') { + setTimeout(function () { + onObjectLoaded(object, index); + }, 500); + } + else { + onObjectLoaded(object, index); + } + }; + + fabric.util.getScript(path, onscriptload); + } + } + else { + fabric.loadSVGFromURL(path, function (elements) { + var object = fabric.util.groupSVGElements(elements, obj, path); + + // copy parameters from serialied json to object (left, top, scaleX, scaleY, etc.) + // skip this step if an object is a PathGroup, since we already passed it options object before + if (!(object instanceof fabric.PathGroup)) { + fabric.util.object.extend(object, obj); + if (typeof obj.angle !== 'undefined') { + object.setAngle(obj.angle); + } + } + + onObjectLoaded(object, index); + }); + } + } + } + var _this = this, numLoadedObjects = 0, numTotalObjects = objects.length; @@ -7371,86 +7488,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { } try { - objects.forEach(function (obj, index) { - - var pathProp = obj.paths ? 'paths' : 'path'; - var path = obj[pathProp]; - - delete obj[pathProp]; - - if (typeof path !== 'string') { - switch (obj.type) { - case 'image': - fabric[fabric.util.string.capitalize(obj.type)].fromObject(obj, function (o) { - onObjectLoaded(o, index); - }); - break; - default: - var klass = fabric[fabric.util.string.camelize(fabric.util.string.capitalize(obj.type))]; - if (klass && klass.fromObject) { - // restore path - if (path) { - obj[pathProp] = path; - } - onObjectLoaded(klass.fromObject(obj), index); - } - break; - } - } - else { - if (obj.type === 'image') { - fabric.util.loadImage(path, function (image) { - var oImg = new fabric.Image(image); - - oImg.setSourcePath(path); - - fabric.util.object.extend(oImg, obj); - oImg.setAngle(obj.angle); - - onObjectLoaded(oImg, index); - }); - } - else if (obj.type === 'text') { - - if (obj.useNative) { - onObjectLoaded(fabric.Text.fromObject(obj), index); - } - else { - obj.path = path; - var object = fabric.Text.fromObject(obj); - var onscriptload = function () { - // TODO (kangax): find out why Opera refuses to work without this timeout - if (Object.prototype.toString.call(fabric.window.opera) === '[object Opera]') { - setTimeout(function () { - onObjectLoaded(object, index); - }, 500); - } - else { - onObjectLoaded(object, index); - } - } - - fabric.util.getScript(path, onscriptload); - } - } - else { - fabric.loadSVGFromURL(path, function (elements, options) { - var object = fabric.util.groupSVGElements(elements, obj, path); - - // copy parameters from serialied json to object (left, top, scaleX, scaleY, etc.) - // skip this step if an object is a PathGroup, since we already passed it options object before - if (!(object instanceof fabric.PathGroup)) { - fabric.util.object.extend(object, obj); - if (typeof obj.angle !== 'undefined') { - object.setAngle(obj.angle); - } - } - - onObjectLoaded(object, index); - }); - } - } - }, this); + objects.forEach(loadObject, this); } catch(e) { fabric.log(e.message); @@ -7586,7 +7624,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var fabric = global.fabric || (global.fabric = { }), extend = fabric.util.object.extend, - clone = fabric.util.object.clone, toFixed = fabric.util.toFixed, capitalize = fabric.util.string.capitalize, getPointer = fabric.util.getPointer, @@ -7840,7 +7877,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { * @method initGradient */ _initGradient: function(options) { - if (options.fill && typeof options.fill == 'object' && !(options.fill instanceof fabric.Gradient)) { + if (options.fill && typeof options.fill === 'object' && !(options.fill instanceof fabric.Gradient)) { this.set('fill', new fabric.Gradient(options.fill)); } }, @@ -8374,8 +8411,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { : -h - (strokeWidth * this.scaleY) - (padding * 2) ) / 2; - var rotateWidth = (-w/2); - ctx.beginPath(); ctx.moveTo(0, rotateHeight); ctx.lineTo(0, rotateHeight + (this.flipY ? this.rotatingPointOffset : -this.rotatingPointOffset)); @@ -8398,8 +8433,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { x = -this.width/2, y = -this.height/2, _this = this, padding = this.padding, - width = this.getWidth(), - height = this.getHeight(), dashedArrayLength = this.strokeDashArray.length; ctx.save(); @@ -8408,6 +8441,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { function renderSide(xMultiplier, yMultiplier) { var lineLength = 0, + lengthDiff = 0, sideLength = (yMultiplier ? _this.height : _this.width) + padding * 2; while (lineLength < sideLength) { @@ -8416,7 +8450,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { lineLength += lengthOfSubPath; if (lineLength > sideLength) { - var lengthDiff = lineLength - sideLength; + lengthDiff = lineLength - sideLength; } // track coords @@ -8612,7 +8646,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { */ toDataURL: function(callback) { var el = fabric.document.createElement('canvas'); - if (!el.getContext && typeof G_vmlCanvasManager != 'undefined') { + if (!el.getContext && typeof G_vmlCanvasManager !== 'undefined') { G_vmlCanvasManager.initElement(el); } @@ -8714,7 +8748,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { tr: new fabric.Point(oCoords.tr.x, oCoords.tr.y), bl: new fabric.Point(oCoords.bl.x, oCoords.bl.y), br: new fabric.Point(oCoords.br.x, oCoords.br.y) - } + }; } var thisCoords = getCoords(this.oCoords), otherCoords = getCoords(other.oCoords); @@ -8748,8 +8782,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var oCoords = this.oCoords, tl = new fabric.Point(oCoords.tl.x, oCoords.tl.y), tr = new fabric.Point(oCoords.tr.x, oCoords.tr.y), - bl = new fabric.Point(oCoords.bl.x, oCoords.bl.y), - br = new fabric.Point(oCoords.br.x, oCoords.br.y); + bl = new fabric.Point(oCoords.bl.x, oCoords.bl.y); return tl.x > selectionTL.x && tr.x < selectionBR.x @@ -8810,7 +8843,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { // canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2); xpoints = this._findCrossPoints(ex, ey, lines); - if (xpoints % 2 == 1 && xpoints != 0) { + if (xpoints % 2 === 1 && xpoints !== 0) { this.__corner = i; return i; } @@ -8843,7 +8876,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { continue; } // optimisation 3: vertical line case - if ((iLine.o.x == iLine.d.x) && (iLine.o.x >= ex)) { + if ((iLine.o.x === iLine.d.x) && (iLine.o.x >= ex)) { xi = iLine.o.x; yi = ey; } @@ -8862,7 +8895,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { xcount += 1; } // optimisation 4: specific for square images - if (xcount == 2) { + if (xcount === 2) { break; } } @@ -8875,7 +8908,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { * @private * @param oCoords {Object} coordinates of the image corners */ - _getImageLines: function(oCoords, i) { + _getImageLines: function(oCoords) { return { topline: { o: oCoords.tl, @@ -8893,7 +8926,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { o: oCoords.bl, d: oCoords.tl } - } + }; }, /** @@ -9136,7 +9169,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { * */ animate: function() { - if (arguments[0] && typeof arguments[0] == 'object') { + if (arguments[0] && typeof arguments[0] === 'object') { for (var prop in arguments[0]) { this._animate(prop, arguments[0][prop], arguments[1]); } @@ -9160,7 +9193,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { options.from = this.get(property); } - if (/[+-]/.test((to + '').charAt(0))) { + if (/[+\-]/.test((to + '').charAt(0))) { to = this.get(property) + parseFloat(to); } @@ -9313,7 +9346,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { }); -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { @@ -9321,7 +9354,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var fabric = global.fabric || (global.fabric = { }), extend = fabric.util.object.extend, - parentSet = fabric.Object.prototype.set, coordProps = { 'x1': 1, 'x2': 1, 'y1': 1, 'y2': 1 }; if (fabric.Line) { @@ -9498,7 +9530,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.Line(points, object); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { "use strict"; @@ -9642,7 +9674,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { options || (options = { }); var parsedAttributes = fabric.parseAttributes(element, fabric.Circle.ATTRIBUTE_NAMES); if (!isValidRadius(parsedAttributes)) { - throw Error('value of `r` attribute is required and can not be negative'); + throw new Error('value of `r` attribute is required and can not be negative'); } if ('left' in parsedAttributes) { parsedAttributes.left -= (options.width / 2) || 0; @@ -9671,30 +9703,30 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.Circle(object); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { - + "use strict"; - + var fabric = global.fabric || (global.fabric = { }); - + if (fabric.Triangle) { fabric.warn('fabric.Triangle is already defined'); return; } - - /** + + /** * @class Triangle * @extends fabric.Object */ fabric.Triangle = fabric.util.createClass(fabric.Object, /** @scope fabric.Triangle.prototype */ { - + /** * @property * @type String */ type: 'triangle', - + /** * Constructor * @method initialize @@ -9703,28 +9735,28 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { */ initialize: function(options) { options = options || { }; - + this.callSuper('initialize', options); - + this.set('width', options.width || 100) .set('height', options.height || 100); }, - + /** * @private * @method _render * @param ctx {CanvasRenderingContext2D} Context to render on */ - _render: function(ctx) { + _render: function(ctx) { var widthBy2 = this.width / 2, heightBy2 = this.height / 2; - + ctx.beginPath(); ctx.moveTo(-widthBy2, heightBy2); ctx.lineTo(0, -heightBy2); ctx.lineTo(widthBy2, heightBy2); ctx.closePath(); - + if (this.fill) { ctx.fill(); } @@ -9732,7 +9764,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { ctx.stroke(); } }, - + /** * Returns complexity of an instance * @method complexity @@ -9741,7 +9773,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { complexity: function() { return 1; }, - + /** * Returns svg representation of an instance * @method toSVG @@ -9765,7 +9797,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { '/>'; } }); - + /** * Returns fabric.Triangle instance from an object representation * @static @@ -9777,7 +9809,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.Triangle(object); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global){ "use strict"; @@ -9942,7 +9974,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.Ellipse(object); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { "use strict"; @@ -10162,7 +10194,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.Rect(object); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { "use strict"; @@ -10314,7 +10346,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.Polyline(points, object); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { "use strict"; @@ -10330,9 +10362,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return; } - function byX(p) { return p.x; } - function byY(p) { return p.y; } - /** * @class Polygon * @extends fabric.Object @@ -10485,7 +10514,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.Polygon(object.points, object); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { var commandLengths = { @@ -10554,7 +10583,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var sfactor_sq = 1 / d - 0.25; if (sfactor_sq < 0) sfactor_sq = 0; var sfactor = Math.sqrt(sfactor_sq); - if (sweep == large) sfactor = -sfactor; + if (sweep === large) sfactor = -sfactor; var xc = 0.5 * (x0 + x1) - sfactor * (y1-y0); var yc = 0.5 * (y0 + y1) + sfactor * (x1-x0); @@ -10562,9 +10591,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var th1 = Math.atan2(y1-yc, x1-xc); var th_arc = th1-th0; - if (th_arc < 0 && sweep == 1){ + if (th_arc < 0 && sweep === 1){ th_arc += 2*Math.PI; - } else if (th_arc > 0 && sweep == 0) { + } else if (th_arc > 0 && sweep === 0) { th_arc -= 2 * Math.PI; } @@ -10667,7 +10696,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { this.setOptions(options); if (!path) { - throw Error('`path` argument is required'); + throw new Error('`path` argument is required'); } var fromArray = _toString.call(path) === '[object Array]'; @@ -11119,7 +11148,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { chunks, parsed; - for (var i = 0, j, chunksParsed, len = this.path.length; i < len; i++) { + for (var i = 0, chunksParsed, len = this.path.length; i < len; i++) { currentPath = this.path[i]; chunks = currentPath.slice(1).trim().replace(/(\d)-/g, '$1###-').split(/\s|,|###/); chunksParsed = [ currentPath.charAt(0) ]; @@ -11247,7 +11276,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.Path(parsedAttributes.d, extend(parsedAttributes, options)); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { "use strict"; @@ -11255,7 +11284,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var fabric = global.fabric || (global.fabric = { }), extend = fabric.util.object.extend, invoke = fabric.util.array.invoke, - parentSet = fabric.Object.prototype.set, parentToObject = fabric.Object.prototype.toObject, camelize = fabric.util.string.camelize, capitalize = fabric.util.string.capitalize; @@ -11487,7 +11515,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { return new fabric.PathGroup(paths, object); }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global){ "use strict"; @@ -11698,8 +11726,11 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var groupScaleFactor = Math.max(this.scaleX, this.scaleY); - for (var i = 0, len = this.objects.length, object; object = this.objects[i]; i++) { + for (var i = 0, len = this.objects.length; i < len; i++) { + + var object = this.objects[i]; var originalScaleFactor = object.borderScaleFactor; + object.borderScaleFactor = groupScaleFactor; object.render(ctx); object.borderScaleFactor = originalScaleFactor; @@ -11729,7 +11760,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { */ complexity: function() { return this.getObjects().reduce(function(total, object) { - total += (typeof object.complexity == 'function') ? object.complexity() : 0; + total += (typeof object.complexity === 'function') ? object.complexity() : 0; return total; }, 0); }, @@ -11758,8 +11789,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var groupLeft = this.get('left'), groupTop = this.get('top'), groupAngle = this.getAngle() * (Math.PI / 180), - objectLeft = object.get('originalLeft'), - objectTop = object.get('originalTop'), rotatedTop = Math.cos(groupAngle) * object.get('top') + Math.sin(groupAngle) * object.get('left'), rotatedLeft = -Math.sin(groupAngle) * object.get('top') + Math.cos(groupAngle) * object.get('left'); @@ -11889,7 +11918,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { aX.push(o.oCoords[prop].x); aY.push(o.oCoords[prop].y); } - }; + } minX = min(aX); maxX = max(aX); @@ -11971,7 +12000,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { fabric.Group.async = true; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function(global) { "use strict"; @@ -11985,7 +12014,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { if (global.fabric.Image) { fabric.warn('fabric.Image is already defined.'); return; - }; + } if (!fabric.Object) { fabric.warn('fabric.Object is required for fabric.Image initialization'); @@ -12083,9 +12112,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { * @method setBorderVisibility * @param {Boolean} visible When true, border is set to be visible */ - setBorderVisibility: function(visible) { + setBorderVisibility: function() { this._resetWidthHeight(); - this._adjustWidthHeightToBorders(showBorder); + this._adjustWidthHeightToBorders(); this.setCoords(); }, @@ -12197,10 +12226,10 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { var isLikelyNode = typeof Buffer !== 'undefined' && typeof window === 'undefined', imgEl = this._originalImage, canvasEl = fabric.document.createElement('canvas'), - replacement = isLikelyNode ? new (require('canvas').Image) : fabric.document.createElement('img'), + replacement = isLikelyNode ? new (require('canvas').Image)() : fabric.document.createElement('img'), _this = this; - if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') { + if (!canvasEl.getContext && typeof G_vmlCanvasManager !== 'undefined') { G_vmlCanvasManager.initElement(canvasEl); } @@ -12430,7 +12459,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { fabric.Image.async = true; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); fabric.util.object.extend(fabric.Object.prototype, { @@ -12992,29 +13021,29 @@ fabric.Image.filters.Tint = fabric.util.createClass( /** @scope fabric.Image.fil * @param {Object} canvasEl Canvas element to apply filter to */ applyTo: function(canvasEl) { - + var context = canvasEl.getContext('2d'), imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height), data = imageData.data, - iLen = data.length, i, - r, g, b, a; - - var rgb = parseInt(this.color).toString(16); - var cr = parseInt('0x'+rgb.substr(0, 2)); - var cg = parseInt('0x'+rgb.substr(2, 2)); - var cb = parseInt('0x'+rgb.substr(4, 2)); - + iLen = data.length, i, a; + + var rgb = parseInt(this.color, 10).toString(16); + + var cr = parseInt('0x' + rgb.substr(0, 2), 16); + var cg = parseInt('0x' + rgb.substr(2, 2), 16); + var cb = parseInt('0x' + rgb.substr(4, 2), 16); + for (i = 0; i < iLen; i+=4) { a = data[i+3]; - - if (a > 0){ + + if (a > 0){ data[i] = cr; data[i+1] = cg; - data[i+2] = cb; - } + data[i+2] = cb; + } } - + context.putImageData(imageData, 0, 0); }, @@ -13168,7 +13197,7 @@ fabric.Image.filters.Tint.fromObject = function(object) { _initDimensions: function() { var canvasEl = fabric.document.createElement('canvas'); - if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') { + if (!canvasEl.getContext && typeof G_vmlCanvasManager !== 'undefined') { G_vmlCanvasManager.initElement(canvasEl); } @@ -13480,29 +13509,30 @@ fabric.Image.filters.Tint.fromObject = function(object) { _renderTextDecoration: function(ctx, textLines) { var halfOfVerticalBox = this._getTextHeight(ctx, textLines) / 2; + var _this = this; function renderLinesAtOffset(offset) { for (var i = 0, len = textLines.length; i < len; i++) { var lineWidth = ctx.measureText(textLines[i]).width; - var lineLeftOffset = this._getLineLeftOffset(lineWidth); + var lineLeftOffset = _this._getLineLeftOffset(lineWidth); ctx.fillRect( - (-this.width / 2) + lineLeftOffset, - (offset + (i * this.fontSize * this.lineHeight)) - halfOfVerticalBox, + (-_this.width / 2) + lineLeftOffset, + (offset + (i * _this.fontSize * _this.lineHeight)) - halfOfVerticalBox, lineWidth, 1); } } if (this.textDecoration.indexOf('underline') > -1) { - renderLinesAtOffset.call(this, this.fontSize); + renderLinesAtOffset(this.fontSize); } if (this.textDecoration.indexOf('line-through') > -1) { - renderLinesAtOffset.call(this, this.fontSize / 2); + renderLinesAtOffset(this.fontSize / 2); } if (this.textDecoration.indexOf('overline') > -1) { - renderLinesAtOffset.call(this, 0); + renderLinesAtOffset(0); } }, @@ -13530,7 +13560,7 @@ fabric.Image.filters.Tint.fromObject = function(object) { // Cufon doesn't play nice with textDecoration=underline if element doesn't have a parent container.appendChild(el); - if (typeof G_vmlCanvasManager == 'undefined') { + if (typeof G_vmlCanvasManager === 'undefined') { el.innerHTML = this.text; } else { @@ -13814,16 +13844,16 @@ fabric.Image.filters.Tint.fromObject = function(object) { } var parsedAttributes = fabric.parseAttributes(element, fabric.Text.ATTRIBUTE_NAMES); - var options = fabric.util.object.extend((options ? fabric.util.object.clone(options) : { }), parsedAttributes); + options = fabric.util.object.extend((options ? fabric.util.object.clone(options) : { }), parsedAttributes); var text = new fabric.Text(element.textContent, options); return text; }; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); (function() { - if (typeof document != 'undefined' && typeof window != 'undefined') { + if (typeof document !== 'undefined' && typeof window !== 'undefined') { return; } @@ -13837,7 +13867,7 @@ fabric.Image.filters.Tint.fromObject = function(object) { function request(url, encoding, callback) { var oURL = URL.parse(url), client = HTTP.createClient(oURL.port, oURL.hostname), - request = client.request('GET', oURL.pathname, { 'host': oURL.hostname }); + req = client.request('GET', oURL.pathname, { 'host': oURL.hostname }); client.addListener('error', function(err) { if (err.errno === process.ECONNREFUSED) { @@ -13848,8 +13878,8 @@ fabric.Image.filters.Tint.fromObject = function(object) { } }); - request.end(); - request.on('response', function (response) { + req.end(); + req.on('response', function (response) { var body = ""; if (encoding) { response.setEncoding(encoding); @@ -13858,7 +13888,7 @@ fabric.Image.filters.Tint.fromObject = function(object) { callback(body); }); response.on('data', function (chunk) { - if (response.statusCode == 200) { + if (response.statusCode === 200) { body += chunk; } }); @@ -13924,8 +13954,8 @@ fabric.Image.filters.Tint.fromObject = function(object) { canvasEl.width = nodeCanvas.width; canvasEl.height = nodeCanvas.height; - var canvas = fabric.Canvas || fabric.StaticCanvas; - var fabricCanvas = new canvas(canvasEl); + var FabricCanvas = fabric.Canvas || fabric.StaticCanvas; + var fabricCanvas = new FabricCanvas(canvasEl); fabricCanvas.contextContainer = nodeCanvas.getContext('2d'); fabricCanvas.nodeCanvas = nodeCanvas; @@ -13935,9 +13965,6 @@ fabric.Image.filters.Tint.fromObject = function(object) { fabric.StaticCanvas.prototype.createPNGStream = function() { return this.nodeCanvas.createPNGStream(); }; - if (fabric.Canvas) { - fabric.Canvas.prototype.createPNGStream - } var origSetWidth = fabric.StaticCanvas.prototype.setWidth; fabric.StaticCanvas.prototype.setWidth = function(width) { diff --git a/dist/all.min.js b/dist/all.min.js index 0cbf1fca..f63be99f 100644 --- a/dist/all.min.js +++ b/dist/all.min.js @@ -1,7 +1,7 @@ /* Fabric.js Copyright 2008-2012, Printio (Juriy Zaytsev, Maxim Chernyak) */ -var fabric=fabric||{version:"0.9.13"};if(typeof exports!="undefined"){exports.fabric=fabric}if(typeof document!="undefined"&&typeof window!="undefined"){fabric.document=document;fabric.window=window}else{fabric.document=require("jsdom").jsdom("");fabric.window=fabric.document.createWindow()}fabric.isTouchSupported="ontouchstart" in fabric.document.documentElement;fabric.isLikelyNode=typeof Buffer!=="undefined"&&typeof window==="undefined"; +var fabric=fabric||{version:"0.9.14"};if(typeof exports!="undefined"){exports.fabric=fabric}if(typeof document!="undefined"&&typeof window!="undefined"){fabric.document=document;fabric.window=window}else{fabric.document=require("jsdom").jsdom("");fabric.window=fabric.document.createWindow()}fabric.isTouchSupported="ontouchstart" in fabric.document.documentElement;fabric.isLikelyNode=typeof Buffer!=="undefined"&&typeof window==="undefined"; /* * Copyright (c) 2009 Simo Kinnunen. * Licensed under the MIT license. */ -var Cufon=(function(){var k=function(){return k.replace.apply(null,arguments)};var u=k.DOM={ready:(function(){var z=false,B={loaded:1,complete:1};var y=[],A=function(){if(z){return}z=true;for(var C;C=y.shift();C()){}};if(fabric.document.addEventListener){fabric.document.addEventListener("DOMContentLoaded",A,false);fabric.window.addEventListener("pageshow",A,false)}if(!fabric.window.opera&&fabric.document.readyState){(function(){B[fabric.document.readyState]?A():setTimeout(arguments.callee,10)})()}if(fabric.document.readyState&&fabric.document.createStyleSheet){(function(){try{fabric.document.body.doScroll("left");A()}catch(C){setTimeout(arguments.callee,1)}})()}o(fabric.window,"load",A);return function(C){if(!arguments.length){A()}else{z?C():y.push(C)}}})()};var l=k.CSS={Size:function(z,y){this.value=parseFloat(z);this.unit=String(z).match(/[a-z%]*$/)[0]||"px";this.convert=function(A){return A/y*this.value};this.convertFrom=function(A){return A/this.value*y};this.toString=function(){return this.value+this.unit}},getStyle:function(y){return new a(y.style)},quotedList:i(function(B){var A=[],z=/\s*((["'])([\s\S]*?[^\\])\2|[^,]+)\s*/g,y;while(y=z.exec(B)){A.push(y[3]||y[1])}return A}),ready:(function(){var A=false;var z=[],B=function(){A=true;for(var D;D=z.shift();D()){}};var y=Object.prototype.propertyIsEnumerable?f("style"):{length:0};var C=f("link");u.ready(function(){var G=0,F;for(var E=0,D=C.length;F=C[E],E=y.length+G){B()}else{setTimeout(arguments.callee,10)}});return function(D){if(A){D()}else{z.push(D)}}})(),supports:function(A,z){var y=fabric.document.createElement("span").style;if(y[A]===undefined){return false}y[A]=z;return y[A]===z},textAlign:function(B,A,y,z){if(A.get("textAlign")=="right"){if(y>0){B=" "+B}}else{if(y400}if(F==500){F=400}for(var G in D){G=parseInt(G,10);if(!C||GA){A=G}H.push(G)}if(FA){F=A}H.sort(function(J,I){return(B?(J>F&&I>F)?JI:(JI:Jz){z=e}L.push(e);e=0;continue}var B=ab.glyphs[ag[aa]]||ab.missingGlyph;if(!B){continue}e+=D=Number(B.w||ab.w)+U}L.push(e);e=Math.max(z,e);var m=[];for(var aa=L.length;aa--;){m[aa]=e-L[aa]}if(D===null){return null}V+=(H.width-D);C+=H.minX;var v,p;if(n){v=J;p=J.firstChild}else{v=fabric.document.createElement("span");v.className="cufon cufon-canvas";v.alt=E;p=fabric.document.createElement("canvas");v.appendChild(p);if(A.printable){var Y=fabric.document.createElement("span");Y.className="cufon-alt";Y.appendChild(fabric.document.createTextNode(E));v.appendChild(Y)}}var ah=v.style;var O=p.style||{};var k=o.convert(H.height-I+T);var af=Math.ceil(k);var S=af/k;p.width=Math.ceil(o.convert(e+V-C)*S);p.height=af;I+=H.minY;O.top=Math.round(o.convert(I-ab.ascent))+"px";O.left=Math.round(o.convert(C))+"px";var j=Math.ceil(o.convert(e*S));var t=j+"px";var s=o.convert(ab.height);var F=(A.lineHeight-1)*o.convert(-ab.ascent/5)*(M-1);Cufon.textOptions.width=j;Cufon.textOptions.height=(s*M)+F;Cufon.textOptions.lines=M;Cufon.textOptions.totalLineHeight=F;if(a){ah.width=t;ah.height=s+"px"}else{ah.paddingLeft=t;ah.paddingBottom=(s-1)+"px"}var ad=Cufon.textOptions.context||p.getContext("2d"),K=af/H.height;Cufon.textOptions.fontAscent=ab.ascent*K;Cufon.textOptions.boundaries=null;for(var w=Cufon.textOptions.shadowOffsets,aa=R.length;aa--;){w[aa]=[R[aa][0]*K,R[aa][1]*K]}ad.save();ad.scale(K,K);ad.translate(-C-((1/K*p.width)/2)+(Cufon.fonts[ab.family].offsetLeft||0),-I-((Cufon.textOptions.height/K)/2)+(Cufon.fonts[ab.family].offsetTop||0));ad.lineWidth=ab.face["underline-thickness"];ad.save();function q(l,i){ad.strokeStyle=i;ad.beginPath();ad.moveTo(0,l);ad.lineTo(e,l);ad.stroke()}var r=Cufon.getTextDecoration(A),u=A.fontStyle==="italic";function ae(){ad.save();ad.fillStyle=A.backgroundColor;var aj=0,an=0,y=[{left:0}];if(A.textAlign==="right"){ad.translate(m[an],0);y[0].left=m[an]*K}else{if(A.textAlign==="center"){ad.translate(m[an]/2,0);y[0].left=m[an]/2*K}}for(var al=0,ak=ag.length;al.cufon-vml-canvas{text-indent:0}@media screen{cvml\\:shape,cvml\\:shadow{behavior:url(#default#VML);display:block;antialias:true;position:absolute}.cufon-vml-canvas{position:absolute;text-align:left}.cufon-vml{display:inline-block;position:relative;vertical-align:middle}.cufon-vml .cufon-alt{position:absolute;left:-10000in;font-size:1px}a .cufon-vml{cursor:pointer}}@media print{.cufon-vml *{display:none}.cufon-vml .cufon-alt{display:inline}}');function c(e,f){return a(e,/(?:em|ex|%)$/i.test(f)?"1em":f)}function a(h,i){if(/px$/i.test(i)){return parseFloat(i)}var g=h.style.left,f=h.runtimeStyle.left;h.runtimeStyle.left=h.currentStyle.left;h.style.left=i;var e=h.style.pixelLeft;h.style.left=g;h.runtimeStyle.left=f;return e}return function(T,z,O,w,D,U,M){var h=(z===null);if(h){z=D.alt}var B=T.viewBox;var j=O.computedFontSize||(O.computedFontSize=new Cufon.CSS.Size(c(U,O.get("fontSize"))+"px",T.baseSize));var L=O.computedLSpacing;if(L==undefined){L=O.get("letterSpacing");O.computedLSpacing=L=(L=="normal")?0:~~j.convertFrom(a(U,L))}var t,m;if(h){t=D;m=D.firstChild}else{t=fabric.document.createElement("span");t.className="cufon cufon-vml";t.alt=z;m=fabric.document.createElement("span");m.className="cufon-vml-canvas";t.appendChild(m);if(w.printable){var R=fabric.document.createElement("span");R.className="cufon-alt";R.appendChild(fabric.document.createTextNode(z));t.appendChild(R)}if(!M){t.appendChild(fabric.document.createElement("cvml:shape"))}}var Z=t.style;var G=m.style;var f=j.convert(B.height),W=Math.ceil(f);var K=W/f;var J=B.minX,I=B.minY;G.height=W;G.top=Math.round(j.convert(I-T.ascent));G.left=Math.round(j.convert(J));Z.height=j.convert(T.height)+"px";var p=Cufon.getTextDecoration(w);var y=O.get("color");var X=Cufon.CSS.textTransform(z,O).split("");var e=0,H=0,q=null;var x,r,A=w.textShadow;for(var S=0,Q=0,P=X.length;Sw?p:(o-n);s(t(currentTime,m,byValue,p));if(o>w||q()){x.onComplete&&x.onComplete();return}k(r)})()}var f=fabric.window.requestAnimationFrame||fabric.window.webkitRequestAnimationFrame||fabric.window.mozRequestAnimationFrame||fabric.window.oRequestAnimationFrame||fabric.window.msRequestAnimationFrame||function(n,m){fabric.window.setTimeout(n,1000/60)};var k=function(){return f.apply(fabric.window,arguments)};function b(n,p,o){if(n){var m=new Image();m.onload=function(){p&&p.call(o,m);m=m.onload=null};m.src=n}else{p&&p.call(o,n)}}function i(p,s){function o(t){return fabric[fabric.util.string.camelize(fabric.util.string.capitalize(t))]}function n(){if(++r===m){if(s){s(q)}}}var q=[],r=0,m=p.length;p.forEach(function(v,u){if(!v.type){return}var t=o(v.type);if(t.async){t.fromObject(v,function(w){q[u]=w;n()})}else{q[u]=t.fromObject(v);n()}})}function a(o,n,p){var m=o.length>1?new fabric.PathGroup(o,n):o[0];if(typeof p!=="undefined"){m.setSourcePath(p)}return m}fabric.util.removeFromArray=j;fabric.util.degreesToRadians=c;fabric.util.toFixed=e;fabric.util.getRandomInt=g;fabric.util.falseFunction=l;fabric.util.animate=d;fabric.util.requestAnimFrame=k;fabric.util.loadImage=b;fabric.util.enlivenObjects=i;fabric.util.groupSVGElements=a})();(function(){var d=Array.prototype.slice;if(!Array.prototype.indexOf){Array.prototype.indexOf=function(g){if(this===void 0||this===null){throw new TypeError()}var h=Object(this),e=h.length>>>0;if(e===0){return -1}var i=0;if(arguments.length>0){i=Number(arguments[1]);if(i!==i){i=0}else{if(i!==0&&i!==(1/0)&&i!==-(1/0)){i=(i>0||-1)*Math.floor(Math.abs(i))}}}if(i>=e){return -1}var f=i>=0?i:Math.max(e-Math.abs(i),0);for(;f>>0;f>>0;g>>0;f>>0;f>>0;g>>0,f=0,h;if(arguments.length>1){h=arguments[1]}else{do{if(f in this){h=this[f++];break}if(++f>=e){throw new TypeError()}}while(true)}for(;f=e){e=h[f][g]}}}else{while(f--){if(h[f]>=e){e=h[f]}}}return e}function c(h,g){if(!h||h.length===0){return undefined}var f=h.length-1,e=g?h[f][g]:h[f];if(g){while(f--){if(h[f][g]/g,">")}fabric.util.string={camelize:b,capitalize:c,escapeXml:a}}());(function(){var c=Array.prototype.slice,a=Function.prototype.apply,b=function(){};if(!Function.prototype.bind){Function.prototype.bind=function(d){var g=this,e=c.call(arguments,1),f;if(e.length){f=function(){return a.call(g,this instanceof b?this:d,e.concat(c.call(arguments)))}}else{f=function(){return a.call(g,this instanceof b?this:d,arguments)}}b.prototype=this.prototype;f.prototype=new b;return f}}})();(function(){var f=Array.prototype.slice,e=function(){};var c=(function(){for(var g in {toString:1}){if(g==="toString"){return false}}return true})();var b=function(g,j,h){for(var i in j){if(i in g.prototype&&typeof g.prototype[i]=="function"){g.prototype[i]=(function(k){return function(){var m=this.constructor.superclass;this.constructor.superclass=h;var l=j[k].apply(this,arguments);this.constructor.superclass=m;if(k!=="initialize"){return l}}})(i)}else{g.prototype[i]=j[i]}if(c){if(j.toString!==Object.prototype.toString){g.prototype.toString=j.toString}if(j.valueOf!==Object.prototype.valueOf){g.prototype.valueOf=j.valueOf}}}};function a(){}function d(){var k=null,j=f.call(arguments,0);if(typeof j[0]==="function"){k=j.shift()}function g(){this.initialize.apply(this,arguments)}g.superclass=k;g.subclasses=[];if(k){a.prototype=k.prototype;g.prototype=new a;k.subclasses.push(g)}for(var h=0,l=j.length;h-1?c(j,l.match(/opacity:\s*(\d?\.?\d*)/)[1]):j}for(var m in l){if(m==="opacity"){c(j,l[m])}else{var k=(m==="float"||m==="cssFloat")?(typeof n.styleFloat==="undefined"?"cssFloat":"styleFloat"):m;n[k]=l[m]}}return j}var h=fabric.document.createElement("div"),g=typeof h.style.opacity==="string",b=typeof h.style.filter==="string",a=fabric.document.defaultView,f=a&&typeof a.getComputedStyle!=="undefined",d=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,c=function(i){return i};if(g){c=function(i,j){i.style.opacity=j;return i}}else{if(b){c=function(i,j){var k=i.style;if(i.currentStyle&&!i.currentStyle.hasLayout){k.zoom=1}if(d.test(k.filter)){j=j>=0.9999?"":("alpha(opacity="+(j*100)+")");k.filter=k.filter.replace(d,j)}else{k.filter+=" alpha(opacity="+(j*100)+")"}return i}}}fabric.util.setStyle=e})();(function(){var h=Array.prototype.slice;function g(j){return typeof j==="string"?fabric.document.getElementById(j):j}function b(j){return h.call(j,0)}try{var i=b(fabric.document.childNodes) instanceof Array}catch(a){}if(!i){b=function(k){var j=new Array(k.length),l=k.length;while(l--){j[l]=k[l]}return j}}function c(k,j){var l=fabric.document.createElement(k);for(var m in j){if(m==="class"){l.className=j[m]}else{if(m==="for"){l.htmlFor=j[m]}else{l.setAttribute(m,j[m])}}}return l}function f(j,k){if((" "+j.className+" ").indexOf(" "+k+" ")===-1){j.className+=(j.className?" ":"")+k}}function e(k,l,j){if(typeof l==="string"){l=c(l,j)}if(k.parentNode){k.parentNode.replaceChild(l,k)}l.appendChild(k);return l}function d(k){var j=0,l=0;do{j+=k.offsetTop||0;l+=k.offsetLeft||0;k=k.offsetParent}while(k);return({left:l,top:j})}(function(){var k=fabric.document.documentElement.style;var l="userSelect" in k?"userSelect":"MozUserSelect" in k?"MozUserSelect":"WebkitUserSelect" in k?"WebkitUserSelect":"KhtmlUserSelect" in k?"KhtmlUserSelect":"";function m(n){if(typeof n.onselectstart!=="undefined"){n.onselectstart=fabric.util.falseFunction}if(l){n.style[l]="none"}else{if(typeof n.unselectable=="string"){n.unselectable="on"}}return n}function j(n){if(typeof n.onselectstart!=="undefined"){n.onselectstart=null}if(l){n.style[l]=""}else{if(typeof n.unselectable=="string"){n.unselectable=""}}return n}fabric.util.makeElementUnselectable=m;fabric.util.makeElementSelectable=j})();(function(){function j(k,o){var m=fabric.document.getElementsByTagName("head")[0],l=fabric.document.createElement("script"),n=true;l.type="text/javascript";l.setAttribute("runat","server");l.onload=l.onreadystatechange=function(p){if(n){if(typeof this.readyState=="string"&&this.readyState!=="loaded"&&this.readyState!=="complete"){return}n=false;o(p||fabric.window.event);l=l.onload=l.onreadystatechange=null}};l.src=k;m.appendChild(l)}fabric.util.getScript=j})();fabric.util.getById=g;fabric.util.toArray=b;fabric.util.makeElement=c;fabric.util.addClass=f;fabric.util.wrapElement=e;fabric.util.getElementOffset=d})();(function(){function d(e,f){return e+(/\?/.test(e)?"&":"?")+f}var c=(function(){var h=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest()}];for(var e=h.length;e--;){try{var g=h[e]();if(g){return h[e]}}catch(f){}}})();function a(){}function b(g,f){f||(f={});var j=f.method?f.method.toUpperCase():"GET",i=f.onComplete||function(){},h=c(),e;h.onreadystatechange=function(){if(h.readyState===4){i(h);h.onreadystatechange=a}};if(j==="GET"){e=null;if(typeof f.parameters=="string"){g=d(g,f.parameters)}}h.open(j,g,true);if(j==="POST"||j==="PUT"){h.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}h.send(e);return h}fabric.util.request=b})();(function(){function d(F,E,H,G){return H*(F/=G)*F+E}function l(F,E,H,G){return -H*(F/=G)*(F-2)+E}function r(F,E,H,G){if((F/=G/2)<1){return H/2*F*F+E}return -H/2*((--F)*(F-2)-1)+E}function B(F,E,H,G){return H*(F/=G)*F*F+E}function q(F,E,H,G){return H*((F=F/G-1)*F*F+1)+E}function u(F,E,H,G){if((F/=G/2)<1){return H/2*F*F*F+E}return H/2*((F-=2)*F*F+2)+E}function t(F,E,H,G){return H*(F/=G)*F*F*F+E}function g(F,E,H,G){return -H*((F=F/G-1)*F*F*F-1)+E}function k(F,E,H,G){if((F/=G/2)<1){return H/2*F*F*F*F+E}return -H/2*((F-=2)*F*F*F-2)+E}function y(F,E,H,G){return H*(F/=G)*F*F*F*F+E}function j(F,E,H,G){return H*((F=F/G-1)*F*F*F*F+1)+E}function n(F,E,H,G){if((F/=G/2)<1){return H/2*F*F*F*F*F+E}return H/2*((F-=2)*F*F*F*F+2)+E}function f(F,E,H,G){return -H*Math.cos(F/G*(Math.PI/2))+H+E}function o(F,E,H,G){return H*Math.sin(F/G*(Math.PI/2))+E}function v(F,E,H,G){return -H/2*(Math.cos(Math.PI*F/G)-1)+E}function D(F,E,H,G){return(F==0)?E:H*Math.pow(2,10*(F/G-1))+E}function c(F,E,H,G){return(F==G)?E+H:H*(-Math.pow(2,-10*F/G)+1)+E}function i(F,E,H,G){if(F==0){return E}if(F==G){return E+H}if((F/=G/2)<1){return H/2*Math.pow(2,10*(F-1))+E}return H/2*(-Math.pow(2,-10*--F)+2)+E}function h(F,E,H,G){return -H*(Math.sqrt(1-(F/=G)*F)-1)+E}function p(F,E,H,G){return H*Math.sqrt(1-(F=F/G-1)*F)+E}function x(F,E,H,G){if((F/=G/2)<1){return -H/2*(Math.sqrt(1-F*F)-1)+E}return H/2*(Math.sqrt(1-(F-=2)*F)+1)+E}function s(G,E,K,J){var H=1.70158;var I=0;var F=K;if(G==0){return E}if((G/=J)==1){return E+K}if(!I){I=J*0.3}if(F-1;w=w.split(/\s+/);var u=[];if(y){for(var v=0,t=w.length;v/i,""))}if(!x.documentElement){return}h.parseSVGDocument(x.documentElement,function(A,z){k.set(u,{objects:h.util.array.invoke(A,"toObject"),options:z});w(A,z)},t)}}function b(v){var u=v.objects,t=v.options;u=u.map(function(w){return h[f(w.type)].fromObject(w)});return({objects:u,options:t})}function n(u,x,t){u=u.trim();var v;if(typeof DOMParser!=="undefined"){var w=new DOMParser();if(w&&w.parseFromString){v=w.parseFromString(u,"text/xml")}}else{if(h.window.ActiveXObject){var v=new ActiveXObject("Microsoft.XMLDOM");v.async="false";v.loadXML(u.replace(//i,""))}}h.parseSVGDocument(v.documentElement,function(z,y){x(z,y)},t)}function m(w){var u="";for(var v=0,t=w.length;v",'",""].join("")}return u}p(h,{parseAttributes:e,parseElements:g,parseStyleAttribute:i,parsePointsAttribute:s,getCSSRules:d,loadSVGFromURL:c,loadSVGFromString:n,createSVGFontFacesMarkup:m})})(typeof exports!="undefined"?exports:this);(function(){function c(h){var g=h.getAttribute("style");if(g){var k=g.split(/\s*;\s*/);if(k[k.length-1]===""){k.pop()}for(var f=k.length;f--;){var e=k[f].split(/\s*:\s*/),d=e[0].trim(),j=e[1].trim();if(d==="stop-color"){return j}}}}fabric.Gradient=fabric.util.createClass({initialize:function(d){d||(d={});this.x1=d.x1||0;this.y1=d.y1||0;this.x2=d.x2||0;this.y2=d.y2||0;this.colorStops=d.colorStops},toObject:function(){return{x1:this.x1,x2:this.x2,y1:this.y1,y2:this.y2,colorStops:this.colorStops}},toLiveGradient:function(e){var g=e.createLinearGradient(this.x1,this.y1,this.x2||e.canvas.width,this.y2);for(var d in this.colorStops){var f=this.colorStops[d];g.addColorStop(parseFloat(d),f)}return g}});fabric.util.object.extend(fabric.Gradient,{fromElement:function(h,e){var l=h.getElementsByTagName("stop"),h,k,f={},d,j={x1:h.getAttribute("x1")||0,y1:h.getAttribute("y1")||0,x2:h.getAttribute("x2")||"100%",y2:h.getAttribute("y2")||0};for(var g=l.length;g--;){h=l[g];k=h.getAttribute("offset");k=parseFloat(k)/(/%$/.test(k)?100:1);f[k]=c(h)||h.getAttribute("stop-color")}a(e,j);return new fabric.Gradient({x1:j.x1,y1:j.y1,x2:j.x2,y2:j.y2,colorStops:f})},forObject:function(e,d){d||(d={});a(e,d);return new fabric.Gradient(d)}});function a(f,e){for(var g in e){if(typeof e[g]==="string"&&/^\d+%$/.test(e[g])){var d=parseFloat(e[g],10);if(g==="x1"||g==="x2"){e[g]=f.width*d/100}else{if(g==="y1"||g==="y2"){e[g]=f.height*d/100}}}if(g==="x1"||g==="x2"){e[g]-=f.width/2}else{if(g==="y1"||g==="y2"){e[g]-=f.height/2}}}}function b(j){var f=j.getElementsByTagName("linearGradient"),d=j.getElementsByTagName("radialGradient"),g,h={};for(var e=f.length;e--;){g=f[e];h[g.getAttribute("id")]=g}for(var e=d.length;e--;){g=d[e];h[g.getAttribute("id")]=g}return h}fabric.getGradientDefs=b})();(function(b){var c=b.fabric||(b.fabric={});if(c.Point){c.warn("fabric.Point is already defined");return}c.Point=a;function a(d,e){if(arguments.length>0){this.init(d,e)}}a.prototype={constructor:a,init:function(d,e){this.x=d;this.y=e},add:function(d){return new a(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 a(this.x+d,this.y+d)},scalarAddEquals:function(d){this.x+=d;this.y+=d;return this},subtract:function(d){return new a(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 a(this.x-d,this.y-d)},scalarSubtractEquals:function(d){this.x-=d;this.y-=d;return this},multiply:function(d){return new a(this.x*d,this.y*d)},multiplyEquals:function(d){this.x*=d;this.y*=d;return this},divide:function(d){return new a(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.xd.x&&this.y>d.y)},gte:function(d){return(this.x>=d.x&&this.y>=d.y)},lerp:function(e,d){return new a(this.x+(e.x-this.x)*d,this.y+(e.y-this.y)*d)},distanceFrom:function(f){var e=this.x-f.x,d=this.y-f.y;return Math.sqrt(e*e+d*d)},min:function(d){return new a(Math.min(this.x,d.x),Math.min(this.y,d.y))},max:function(d){return new a(Math.max(this.x,d.x),Math.max(this.y,d.y))},toString:function(){return this.x+","+this.y},setXY:function(d,e){this.x=d;this.y=e},setFromPoint:function(d){this.x=d.x;this.y=d.y},swap:function(e){var d=this.x,f=this.y;this.x=e.x;this.y=e.y;e.x=d;e.y=f}}})(typeof exports!="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={});if(b.Intersection){b.warn("fabric.Intersection is already defined");return}function c(d){if(arguments.length>0){this.init(d)}}b.Intersection=c;b.Intersection.prototype={init:function(d){this.status=d;this.points=[]},appendPoint:function(d){this.points.push(d)},appendPoints:function(d){this.points=this.points.concat(d)}};b.Intersection.intersectLineLine=function(h,f,l,k){var m,i=(k.x-l.x)*(h.y-l.y)-(k.y-l.y)*(h.x-l.x),j=(f.x-h.x)*(h.y-l.y)-(f.y-h.y)*(h.x-l.x),g=(k.y-l.y)*(f.x-h.x)-(k.x-l.x)*(f.y-h.y);if(g!=0){var e=i/g,d=j/g;if(0<=e&&e<=1&&0<=d&&d<=1){m=new c("Intersection");m.points.push(new b.Point(h.x+e*(f.x-h.x),h.y+e*(f.y-h.y)))}else{m=new c("No Intersection")}}else{if(i==0||j==0){m=new c("Coincident")}else{m=new c("Parallel")}}return m};b.Intersection.intersectLinePolygon=function(e,d,l){var m=new c("No Intersection"),f=l.length;for(var h=0;h0){m.status="Intersection"}return m};b.Intersection.intersectPolygonPolygon=function(j,h){var f=new c("No Intersection"),l=j.length;for(var k=0;k0){f.status="Intersection"}return f};b.Intersection.intersectPolygonRectangle=function(n,e,d){var g=e.min(d),m=e.max(d),f=new b.Point(m.x,g.y),l=new b.Point(g.x,m.y),k=c.intersectLinePolygon(g,f,n),j=c.intersectLinePolygon(f,m,n),i=c.intersectLinePolygon(m,l,n),h=c.intersectLinePolygon(l,g,n),o=new c("No Intersection");o.appendPoints(k.points);o.appendPoints(j.points);o.appendPoints(i.points);o.appendPoints(h.points);if(o.points.length>0){o.status="Intersection"}return o}})(typeof exports!="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={});if(b.Color){b.warn("fabric.Color is already defined.");return}function c(d){if(!d){this.setSource([0,0,0,1])}else{this._tryParsingColor(d)}}b.Color=c;b.Color.prototype={_tryParsingColor:function(d){var e=c.sourceFromHex(d);if(!e){e=c.sourceFromRgb(d)}if(e){this.setSource(e)}},getSource:function(){return this._source},setSource:function(d){this._source=d},toRgb:function(){var d=this.getSource();return"rgb("+d[0]+","+d[1]+","+d[2]+")"},toRgba:function(){var d=this.getSource();return"rgba("+d[0]+","+d[1]+","+d[2]+","+d[3]+")"},toHex:function(){var h=this.getSource();var f=h[0].toString(16);f=(f.length==1)?("0"+f):f;var e=h[1].toString(16);e=(e.length==1)?("0"+e):e;var d=h[2].toString(16);d=(d.length==1)?("0"+d):d;return f.toUpperCase()+e.toUpperCase()+d.toUpperCase()},getAlpha:function(){return this.getSource()[3]},setAlpha:function(e){var d=this.getSource();d[3]=e;this.setSource(d);return this},toGrayscale:function(){var f=this.getSource(),e=parseInt((f[0]*0.3+f[1]*0.59+f[2]*0.11).toFixed(0),10),d=f[3];this.setSource([e,e,e,d]);return this},toBlackWhite:function(d){var g=this.getSource(),f=(g[0]*0.3+g[1]*0.59+g[2]*0.11).toFixed(0),e=g[3],d=d||127;f=(Number(f)','',"',"Created with Fabric.js ",fabric.version,"",fabric.createSVGFontFacesMarkup(this.getObjects())];if(this.backgroundImage){h.push('')}for(var j=0,k=this.getObjects(),g=k.length;j");return h.join("")},isEmpty:function(){return this._objects.length===0},remove:function(g){e(this._objects,g);if(this.getActiveObject()===g){this.fire("before:selection:cleared",{target:g});this.discardActiveObject();this.fire("selection:cleared")}this.renderAll();return g},sendToBack:function(g){e(this._objects,g);this._objects.unshift(g);return this.renderAll()},bringToFront:function(g){e(this._objects,g);this._objects.push(g);return this.renderAll()},sendBackwards:function(j){var h=this._objects.indexOf(j),g=h;if(h!==0){for(var k=h-1;k>=0;--k){if(j.intersectsWithObject(this._objects[k])||j.isContainedWithinObject(this._objects[k])){g=k;break}}e(this._objects,j);this._objects.splice(g,0,j)}return this.renderAll()},bringForward:function(k){var n=this.getObjects(),h=n.indexOf(k),g=h;if(h!==n.length-1){for(var m=h+1,j=this._objects.length;m"};f(fabric.StaticCanvas,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(l){var k=l.getContext("2d"),g=k.getImageData(0,0,l.width,l.height),p=g.data,m=g.width,r=g.height,q,h,o,n;for(o=0;o0){if(B>this.targetFindTolerance){B-=this.targetFindTolerance}else{B=0}if(A>this.targetFindTolerance){A-=this.targetFindTolerance}else{A=0}}var v=true;var r=w.getImageData(B,A,(this.targetFindTolerance*2)||1,(this.targetFindTolerance*2)||1);for(var u=3;u0)?0:-v),r.ey-((u>0)?0:-u),t,s);this.contextTop.lineWidth=this.selectionLineWidth;this.contextTop.strokeStyle=this.selectionBorderColor;this.contextTop.strokeRect(r.ex+a-((v>0)?0:t),r.ey+a-((u>0)?0:s),t,s)},_findSelectedObjects:function(x){var y,t,D=[],s=this._groupSelector.ex,C=this._groupSelector.ey,r=s+this._groupSelector.left,A=C+this._groupSelector.top,z,w=new fabric.Point(f(s,r),f(C,A)),B=new fabric.Point(l(s,r),l(C,A));for(var u=0,v=this._objects.length;u1){var D=new fabric.Group(D);this.setActiveGroup(D);D.saveCoords();this.fire("selection:created",{target:D})}}this.renderAll()},findTarget:function(y,u){var z,r=this.getPointer(y);var t=this.getActiveGroup();if(t&&!u&&this.containsPoint(y,t)){z=t;return z}var s=[];for(var v=this._objects.length;v--;){if(this._objects[v]&&this.containsPoint(y,this._objects[v])){if(this.perPixelTargetFind||this._objects[v].perPixelTargetFind){s[s.length]=this._objects[v]}else{z=this._objects[v];this.relatedTarget=z;break}}}for(var v=0,x=s.length;v1)?q.apply(this,o.call(arguments,1)):q.call(this)},initialize:function(i){if(i){this.setOptions(i)}},_initGradient:function(i){if(i.fill&&typeof i.fill=="object"&&!(i.fill instanceof d.Gradient)){this.set("fill",new d.Gradient(i.fill))}},setOptions:function(q){var r=this.stateProperties.length,s;while(r--){s=this.stateProperties[r];if(s in q){this.set(s,q[s])}}this._initGradient(q)},transform:function(i){i.globalAlpha=this.opacity;i.translate(this.left,this.top);i.rotate(this._theta);i.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toObject:function(){var q=d.Object.NUM_FRACTION_DIGITS;var i={type:this.type,left:c(this.left,q),top:c(this.top,q),width:c(this.width,q),height:c(this.height,q),fill:(this.fill&&this.fill.toObject)?this.fill.toObject():this.fill,overlayFill:this.overlayFill,stroke:this.stroke,strokeWidth:this.strokeWidth,strokeDashArray:this.strokeDashArray,scaleX:c(this.scaleX,q),scaleY:c(this.scaleY,q),angle:c(this.getAngle(),q),flipX:this.flipX,flipY:this.flipY,opacity:c(this.opacity,q),selectable:this.selectable,hasControls:this.hasControls,hasBorders:this.hasBorders,hasRotatingPoint:this.hasRotatingPoint,transparentCorners:this.transparentCorners,perPixelTargetFind:this.perPixelTargetFind};if(!this.includeDefaultValues){i=this._removeDefaultValues(i)}return i},toDatalessObject:function(){return this.toObject()},getSvgStyles:function(){return["stroke: ",(this.stroke?this.stroke:"none"),"; ","stroke-width: ",(this.strokeWidth?this.strokeWidth:"0"),"; ","stroke-dasharray: ",(this.strokeDashArray?this.strokeDashArray.join(" "):"; "),"fill: ",(this.fill?this.fill:"none"),"; ","opacity: ",(this.opacity?this.opacity:"1"),";"].join("")},getSvgTransform:function(){var i=this.getAngle();return["translate(",c(this.left,2)," ",c(this.top,2),")",i!==0?(" rotate("+c(i,2)+")"):"",(this.scaleX===1&&this.scaleY===1)?"":(" scale("+c(this.scaleX,2)+" "+c(this.scaleY,2)+")")].join("")},_removeDefaultValues:function(q){var i=d.Object.prototype.options;if(i){this.stateProperties.forEach(function(r){if(q[r]===i[r]){delete q[r]}})}return q},isActive:function(){return !!this.active},setActive:function(i){this.active=!!i;return this},toString:function(){return"#"},set:function(i,q){if(typeof i==="object"){for(var r in i){this._set(r,i[r])}}else{if(typeof q==="function"){this._set(i,q(this.get(i)))}else{this._set(i,q)}}return this},_set:function(i,q){var r=(i==="scaleX"||i==="scaleY")&&q1?this.strokeWidth:0,B=this.padding;this.currentWidth=(this.width+z)*this.scaleX+B*2;this.currentHeight=(this.height+z)*this.scaleY+B*2;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 w=Math.cos(this._angle+this._theta)*this._hypotenuse,v=Math.sin(this._angle+this._theta)*this._hypotenuse,r=this._theta,A=Math.sin(r),y=Math.cos(r);var E={x:this.left-w,y:this.top-v};var x={x:E.x+(this.currentWidth*y),y:E.y+(this.currentWidth*A)};var D={x:x.x-(this.currentHeight*A),y:x.y+(this.currentHeight*y)};var s={x:E.x-(this.currentHeight*A),y:E.y+(this.currentHeight*y)};var u={x:E.x-(this.currentHeight/2*A),y:E.y+(this.currentHeight/2*y)};var i={x:E.x+(this.currentWidth/2*y),y:E.y+(this.currentWidth/2*A)};var q={x:x.x-(this.currentHeight/2*A),y:x.y+(this.currentHeight/2*y)};var C={x:s.x+(this.currentWidth/2*y),y:s.y+(this.currentWidth/2*A)};var t={x:E.x+(this.currentWidth/2*y),y:E.y+(this.currentWidth/2*A)};this.oCoords={tl:E,tr:x,br:D,bl:s,ml:u,mt:i,mr:q,mb:C,mtr:t};this._setCornerCoords();return this},getBoundingRectWidth:function(){this.oCoords||this.setCoords();var q=[this.oCoords.tl.x,this.oCoords.tr.x,this.oCoords.br.x,this.oCoords.bl.x];var i=d.util.array.min(q);var r=d.util.array.max(q);return Math.abs(i-r)},getBoundingRectHeight:function(){this.oCoords||this.setCoords();var i=[this.oCoords.tl.y,this.oCoords.tr.y,this.oCoords.br.y,this.oCoords.bl.y];var r=d.util.array.min(i);var q=d.util.array.max(i);return Math.abs(r-q)},drawBorders:function(A){if(!this.hasBorders){return}var t=d.Object.MIN_SCALE_LIMIT,v=this.padding,i=v*2,u=this.strokeWidth>1?this.strokeWidth:0;A.save();A.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;A.strokeStyle=this.borderColor;var z=1/(this.scaleXi){var C=x-i}if(E){z+=(D*E)-(C*E||0)}else{v+=(D*y)-(C*y||0)}B[1&s?"moveTo":"lineTo"](z,v);if(s>=u){s=0}}}q(1,0);q(0,1);q(-1,0);q(0,-1);B.stroke();B.closePath();B.restore()},drawCorners:function(B){if(!this.hasControls){return}var x=this.cornersize,r=x/2,i=this.strokeWidth/2,q=-(this.width/2),v=-(this.height/2),H,C,z=x/this.scaleX,w=x/this.scaleY,E=this.padding/this.scaleX,D=this.padding/this.scaleY,F=r/this.scaleY,G=r/this.scaleX,t=(r-x)/this.scaleX,s=(r-x)/this.scaleY,y=this.height,A=this.width,u=this.transparentCorners?"strokeRect":"fillRect";B.save();B.lineWidth=1/Math.max(this.scaleX,this.scaleY);B.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;B.strokeStyle=B.fillStyle=this.cornerColor;H=q-G-i-E;C=v-F-i-D;B.clearRect(H,C,z,w);B[u](H,C,z,w);H=q+A-G+i+E;C=v-F-i-D;B.clearRect(H,C,z,w);B[u](H,C,z,w);H=q-G-i-E;C=v+y+s+i+D;B.clearRect(H,C,z,w);B[u](H,C,z,w);H=q+A+t+i+E;C=v+y+s+i+D;B.clearRect(H,C,z,w);B[u](H,C,z,w);if(!this.lockUniScaling){H=q+A/2-G;C=v-F-i-D;B.clearRect(H,C,z,w);B[u](H,C,z,w);H=q+A/2-G;C=v+y+s+i+D;B.clearRect(H,C,z,w);B[u](H,C,z,w);H=q+A+t+i+E;C=v+y/2-F;B.clearRect(H,C,z,w);B[u](H,C,z,w);H=q-G-i-E;C=v+y/2-F;B.clearRect(H,C,z,w);B[u](H,C,z,w)}if(this.hasRotatingPoint){H=q+A/2-G;C=this.flipY?(v+y+(this.rotatingPointOffset/this.scaleY)-w/2+i+D):(v-(this.rotatingPointOffset/this.scaleY)-w/2-i-D);B.clearRect(H,C,z,w);B[u](H,C,z,w)}B.restore();return this},clone:function(i){if(this.constructor.fromObject){return this.constructor.fromObject(this.toObject(),i)}return new d.Object(this.toObject())},cloneAsImage:function(s){if(d.Image){var q=new Image();q.onload=function(){if(s){s(new d.Image(q),r)}q=q.onload=null};var r={angle:this.get("angle"),flipX:this.get("flipX"),flipY:this.get("flipY")};this.set("angle",0).set("flipX",false).set("flipY",false);this.toDataURL(function(i){q.src=i})}return this},toDataURL:function(s){var q=d.document.createElement("canvas");if(!q.getContext&&typeof G_vmlCanvasManager!="undefined"){G_vmlCanvasManager.initElement(q)}q.width=this.getBoundingRectWidth();q.height=this.getBoundingRectHeight();d.util.wrapElement(q,"div");var i=new d.Canvas(q);i.backgroundColor="transparent";i.renderAll();if(this.constructor.async){this.clone(r)}else{r(this.clone())}function r(u){u.left=q.width/2;u.top=q.height/2;u.setActive(false);i.add(u);var t=i.toDataURL("png");i.dispose();i=u=null;s&&s(t)}},hasStateChanged:function(){return this.stateProperties.some(function(i){return this[i]!==this.originalState[i]},this)},saveState:function(){this.stateProperties.forEach(function(i){this.originalState[i]=this.get(i)},this);return this},setupState:function(){this.originalState={};this.saveState()},intersectsWithRect:function(r,t){var w=this.oCoords,i=new d.Point(w.tl.x,w.tl.y),s=new d.Point(w.tr.x,w.tr.y),v=new d.Point(w.bl.x,w.bl.y),q=new d.Point(w.br.x,w.br.y);var u=d.Intersection.intersectPolygonRectangle([i,s,q,v],r,t);return(u.status==="Intersection")},intersectsWithObject:function(i){function q(u){return{tl:new d.Point(u.tl.x,u.tl.y),tr:new d.Point(u.tr.x,u.tr.y),bl:new d.Point(u.bl.x,u.bl.y),br:new d.Point(u.br.x,u.br.y)}}var r=q(this.oCoords),t=q(i.oCoords);var s=d.Intersection.intersectPolygonPolygon([r.tl,r.tr,r.br,r.bl],[t.tl,t.tr,t.br,t.bl]);return(s.status==="Intersection")},isContainedWithinObject:function(i){return this.isContainedWithinRect(i.oCoords.tl,i.oCoords.br)},isContainedWithinRect:function(r,t){var v=this.oCoords,i=new d.Point(v.tl.x,v.tl.y),s=new d.Point(v.tr.x,v.tr.y),u=new d.Point(v.bl.x,v.bl.y),q=new d.Point(v.br.x,v.br.y);return i.x>r.x&&s.xr.y&&u.y=v)&&(s.d.y>=v)){continue}if((s.o.x==s.d.x)&&(s.o.x>=w)){x=s.o.x;u=v}else{z=0;y=(s.d.y-s.o.y)/(s.d.x-s.o.x);r=v-z*w;q=s.o.y-y*s.o.x;x=-(r-q)/(z-y);u=r+z*x}if(x>=w){t+=1}if(t==2){break}}return t},_getImageLines:function(r,q){return{topline:{o:r.tl,d:r.tr},rightline:{o:r.tr,d:r.br},bottomline:{o:r.br,d:r.bl},leftline:{o:r.bl,d:r.tl}}},_setCornerCoords:function(){var u=this.oCoords,q=b(45-this.getAngle()),s=Math.sqrt(2*Math.pow(this.cornersize,2))/2,i=s*Math.cos(q),r=s*Math.sin(q),v=Math.sin(this._theta),t=Math.cos(this._theta);u.tl.corner={tl:{x:u.tl.x-r,y:u.tl.y-i},tr:{x:u.tl.x+i,y:u.tl.y-r},bl:{x:u.tl.x-i,y:u.tl.y+r},br:{x:u.tl.x+r,y:u.tl.y+i}};u.tr.corner={tl:{x:u.tr.x-r,y:u.tr.y-i},tr:{x:u.tr.x+i,y:u.tr.y-r},br:{x:u.tr.x+r,y:u.tr.y+i},bl:{x:u.tr.x-i,y:u.tr.y+r}};u.bl.corner={tl:{x:u.bl.x-r,y:u.bl.y-i},bl:{x:u.bl.x-i,y:u.bl.y+r},br:{x:u.bl.x+r,y:u.bl.y+i},tr:{x:u.bl.x+i,y:u.bl.y-r}};u.br.corner={tr:{x:u.br.x+i,y:u.br.y-r},bl:{x:u.br.x-i,y:u.br.y+r},br:{x:u.br.x+r,y:u.br.y+i},tl:{x:u.br.x-r,y:u.br.y-i}};u.ml.corner={tl:{x:u.ml.x-r,y:u.ml.y-i},tr:{x:u.ml.x+i,y:u.ml.y-r},bl:{x:u.ml.x-i,y:u.ml.y+r},br:{x:u.ml.x+r,y:u.ml.y+i}};u.mt.corner={tl:{x:u.mt.x-r,y:u.mt.y-i},tr:{x:u.mt.x+i,y:u.mt.y-r},bl:{x:u.mt.x-i,y:u.mt.y+r},br:{x:u.mt.x+r,y:u.mt.y+i}};u.mr.corner={tl:{x:u.mr.x-r,y:u.mr.y-i},tr:{x:u.mr.x+i,y:u.mr.y-r},bl:{x:u.mr.x-i,y:u.mr.y+r},br:{x:u.mr.x+r,y:u.mr.y+i}};u.mb.corner={tl:{x:u.mb.x-r,y:u.mb.y-i},tr:{x:u.mb.x+i,y:u.mb.y-r},bl:{x:u.mb.x-i,y:u.mb.y+r},br:{x:u.mb.x+r,y:u.mb.y+i}};u.mtr.corner={tl:{x:u.mtr.x-r+(v*this.rotatingPointOffset),y:u.mtr.y-i-(t*this.rotatingPointOffset)},tr:{x:u.mtr.x+i+(v*this.rotatingPointOffset),y:u.mtr.y-r-(t*this.rotatingPointOffset)},bl:{x:u.mtr.x-i+(v*this.rotatingPointOffset),y:u.mtr.y+r-(t*this.rotatingPointOffset)},br:{x:u.mtr.x+r+(v*this.rotatingPointOffset),y:u.mtr.y+i-(t*this.rotatingPointOffset)}}},toGrayscale:function(){var i=this.get("fill");if(i){this.set("overlayFill",new d.Color(i).toGrayscale().toRgb())}return this},complexity:function(){return 0},toJSON:function(){return this.toObject()},setGradientFill:function(i){this.set("fill",d.Gradient.forObject(this,i))},animate:function(){if(arguments[0]&&typeof arguments[0]=="object"){for(var i in arguments[0]){this._animate(i,arguments[0][i],arguments[1])}}else{this._animate.apply(this,arguments)}return this},_animate:function(q,s,i){var r=this;i||(i={});if(!("from" in i)){i.from=this.get(q)}if(/[+-]/.test((s+"").charAt(0))){s=this.get(q)+parseFloat(s)}d.util.animate({startValue:i.from,endValue:s,byValue:i.by,easing:i.easing,duration:i.duration,onChange:function(t){r.set(q,t);i.onChange&&i.onChange()},onComplete:function(){r.setCoords();i.onComplete&&i.onComplete()}})},centerH:function(){this.canvas.centerObjectH(this);return this},centerV:function(){this.canvas.centerObjectV(this);return this},center:function(){return this.centerH().centerV()},remove:function(){return this.canvas.remove(this)},sendToBack:function(){this.canvas.sendToBack(this);return this},bringToFront:function(){this.canvas.bringToFront(this);return this},sendBackwards:function(){this.canvas.sendBackwards(this);return this},bringForward:function(){this.canvas.bringForward(this);return this}});d.Object.prototype.rotate=d.Object.prototype.setAngle;var j=d.Object.prototype;for(var g=j.stateProperties.length;g--;){var h=j.stateProperties[g],e=h.charAt(0).toUpperCase()+h.slice(1),f="set"+e,n="get"+e;if(!j[n]){j[n]=(function(i){return new Function('return this.get("'+i+'")')})(h)}if(!j[f]){j[f]=(function(i){return new Function("value",'return this.set("'+i+'", value)')})(h)}}l(d.Object.prototype,d.Observable);l(d.Object,{NUM_FRACTION_DIGITS:2,MIN_SCALE_LIMIT:0.1})})(typeof exports!="undefined"?exports:this);(function(b){var c=b.fabric||(b.fabric={}),e=c.util.object.extend,d=c.Object.prototype.set,a={x1:1,x2:1,y1:1,y2:1};if(c.Line){c.warn("fabric.Line is already defined");return}c.Line=c.util.createClass(c.Object,{type:"line",initialize:function(g,f){if(!g){g=[0,0,0,0]}this.callSuper("initialize",f);this.set("x1",g[0]);this.set("y1",g[1]);this.set("x2",g[2]);this.set("y2",g[3]);this._setWidthHeight(f)},_setWidthHeight:function(f){f||(f={});this.set("width",(this.x2-this.x1)||1);this.set("height",(this.y2-this.y1)||1);this.set("left","left" in f?f.left:(this.x1+this.width/2));this.set("top","top" in f?f.top:(this.y1+this.height/2))},_set:function(f,g){this[f]=g;if(f in a){this._setWidthHeight()}return this},_render:function(f){f.beginPath();if(this.group){f.translate(-this.group.width/2+this.left,-this.group.height/2+this.top)}f.moveTo(this.width===1?0:(-this.width/2),this.height===1?0:(-this.height/2));f.lineTo(this.width===1?0:(this.width/2),this.height===1?0:(this.height/2));f.lineWidth=this.strokeWidth;var g=f.strokeStyle;f.strokeStyle=f.fillStyle;f.stroke();f.strokeStyle=g},complexity:function(){return 1},toObject:function(){return e(this.callSuper("toObject"),{x1:this.get("x1"),y1:this.get("y1"),x2:this.get("x2"),y2:this.get("y2")})},toSVG:function(){return[""].join("")}});c.Line.ATTRIBUTE_NAMES="x1 y1 x2 y2 stroke stroke-width transform".split(" ");c.Line.fromElement=function(g,f){var i=c.parseAttributes(g,c.Line.ATTRIBUTE_NAMES);var h=[i.x1||0,i.y1||0,i.x2||0,i.y2||0];return new c.Line(h,e(i,f))};c.Line.fromObject=function(f){var g=[f.x1,f.y1,f.x2,f.y2];return new c.Line(g,f)}})(typeof exports!="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={}),d=Math.PI*2,e=b.util.object.extend;if(b.Circle){b.warn("fabric.Circle is already defined.");return}b.Circle=b.util.createClass(b.Object,{type:"circle",initialize:function(f){f=f||{};this.set("radius",f.radius||0);this.callSuper("initialize",f);var g=this.get("radius")*2;this.set("width",g).set("height",g)},toObject:function(){return e(this.callSuper("toObject"),{radius:this.get("radius")})},toSVG:function(){return('')},_render:function(f,g){f.beginPath();f.globalAlpha*=this.opacity;f.arc(g?this.left:0,g?this.top:0,this.radius,0,d,false);f.closePath();if(this.fill){f.fill()}if(this.stroke){f.stroke()}},getRadiusX:function(){return this.get("radius")*this.get("scaleX")},getRadiusY:function(){return this.get("radius")*this.get("scaleY")},setRadius:function(f){this.radius=f;this.set("width",f*2).set("height",f*2)},complexity:function(){return 1}});b.Circle.ATTRIBUTE_NAMES="cx cy r fill fill-opacity opacity stroke stroke-width transform".split(" ");b.Circle.fromElement=function(g,f){f||(f={});var h=b.parseAttributes(g,b.Circle.ATTRIBUTE_NAMES);if(!c(h)){throw Error("value of `r` attribute is required and can not be negative")}if("left" in h){h.left-=(f.width/2)||0}if("top" in h){h.top-=(f.height/2)||0}return new b.Circle(e(h,f))};function c(f){return(("radius" in f)&&(f.radius>0))}b.Circle.fromObject=function(f){return new b.Circle(f)}})(typeof exports!="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={});if(b.Triangle){b.warn("fabric.Triangle is already defined");return}b.Triangle=b.util.createClass(b.Object,{type:"triangle",initialize:function(c){c=c||{};this.callSuper("initialize",c);this.set("width",c.width||100).set("height",c.height||100)},_render:function(c){var d=this.width/2,e=this.height/2;c.beginPath();c.moveTo(-d,e);c.lineTo(0,-e);c.lineTo(d,e);c.closePath();if(this.fill){c.fill()}if(this.stroke){c.stroke()}},complexity:function(){return 1},toSVG:function(){var c=this.width/2,d=this.height/2;var e=[-c+" "+d,"0 "+-d,c+" "+d].join(",");return''}});b.Triangle.fromObject=function(c){return new b.Triangle(c)}})(typeof exports!="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={}),c=Math.PI*2,d=b.util.object.extend;if(b.Ellipse){b.warn("fabric.Ellipse is already defined.");return}b.Ellipse=b.util.createClass(b.Object,{type:"ellipse",initialize:function(e){e=e||{};this.callSuper("initialize",e);this.set("rx",e.rx||0);this.set("ry",e.ry||0);this.set("width",this.get("rx")*2);this.set("height",this.get("ry")*2)},toObject:function(){return d(this.callSuper("toObject"),{rx:this.get("rx"),ry:this.get("ry")})},toSVG:function(){return[""].join("")},render:function(e,f){if(this.rx===0||this.ry===0){return}return this.callSuper("render",e,f)},_render:function(e,f){e.beginPath();e.save();e.globalAlpha*=this.opacity;if(this.transformMatrix&&this.group){e.translate(this.cx,this.cy)}e.transform(1,0,0,this.ry/this.rx,0,0);e.arc(f?this.left:0,f?this.top:0,this.rx,0,c,false);if(this.stroke){e.stroke()}if(this.fill){e.fill()}e.restore()},complexity:function(){return 1}});b.Ellipse.ATTRIBUTE_NAMES="cx cy rx ry fill fill-opacity opacity stroke stroke-width transform".split(" ");b.Ellipse.fromElement=function(g,f){f||(f={});var i=b.parseAttributes(g,b.Ellipse.ATTRIBUTE_NAMES);var e=i.left;var j=i.top;if("left" in i){i.left-=(f.width/2)||0}if("top" in i){i.top-=(f.height/2)||0}var h=new b.Ellipse(d(i,f));h.cx=e||0;h.cy=j||0;return h};b.Ellipse.fromObject=function(e){return new b.Ellipse(e)}})(typeof exports!="undefined"?exports:this);(function(b){var c=b.fabric||(b.fabric={});if(c.Rect){console.warn("fabric.Rect is already defined");return}c.Rect=c.util.createClass(c.Object,{type:"rect",rx:0,ry:0,initialize:function(d){this._initStateProperties();this.callSuper("initialize",d);this._initRxRy()},_initStateProperties:function(){this.stateProperties=this.stateProperties.concat(["rx","ry"])},_initRxRy:function(){if(this.rx&&!this.ry){this.ry=this.rx}else{if(this.ry&&!this.rx){this.rx=this.ry}}},_render:function(f){var j=this.rx||0,i=this.ry||0,d=-this.width/2,k=-this.height/2,e=this.width,g=this.height;f.beginPath();f.globalAlpha*=this.opacity;if(this.transformMatrix&&this.group){f.translate(this.width/2+this.x,this.height/2+this.y)}if(!this.transformMatrix&&this.group){f.translate(-this.group.width/2+this.width/2+this.x,-this.group.height/2+this.height/2+this.y)}f.moveTo(d+j,k);f.lineTo(d+e-j,k);f.quadraticCurveTo(d+e,k,d+e,k+i,d+e,k+i);f.lineTo(d+e,k+g-i);f.quadraticCurveTo(d+e,k+g,d+e-j,k+g,d+e-j,k+g);f.lineTo(d+j,k+g);f.quadraticCurveTo(d,k+g,d,k+g-i,d,k+g-i);f.lineTo(d,k+i);f.quadraticCurveTo(d,k,d+j,k,d+j,k);f.closePath();if(this.fill){f.fill()}if(this.strokeDashArray){this._renderDashedStroke(f)}else{if(this.stroke){f.stroke()}}},_normalizeLeftTopProperties:function(d){if(d.left){this.set("left",d.left+this.getWidth()/2)}this.set("x",d.left||0);if(d.top){this.set("top",d.top+this.getHeight()/2)}this.set("y",d.top||0);return this},complexity:function(){return 1},toObject:function(){return c.util.object.extend(this.callSuper("toObject"),{rx:this.get("rx")||0,ry:this.get("ry")||0})},toSVG:function(){return''}});c.Rect.ATTRIBUTE_NAMES="x y width height rx ry fill fill-opacity opacity stroke stroke-width transform".split(" ");function a(d){d.left=d.left||0;d.top=d.top||0;return d}c.Rect.fromElement=function(e,d){if(!e){return null}var g=c.parseAttributes(e,c.Rect.ATTRIBUTE_NAMES);g=a(g);var f=new c.Rect(c.util.object.extend((d?c.util.object.clone(d):{}),g));f._normalizeLeftTopProperties(g);return f};c.Rect.fromObject=function(d){return new c.Rect(d)}})(typeof exports!="undefined"?exports:this);(function(b){var c=b.fabric||(b.fabric={}),a=c.util.toFixed;if(c.Polyline){c.warn("fabric.Polyline is already defined");return}c.Polyline=c.util.createClass(c.Object,{type:"polyline",initialize:function(e,d){d=d||{};this.set("points",e);this.callSuper("initialize",d);this._calcDimensions()},_calcDimensions:function(){return c.Polygon.prototype._calcDimensions.call(this)},toObject:function(){return c.Polygon.prototype.toObject.call(this)},toSVG:function(){var f=[];for(var e=0,d=this.points.length;e"].join("")},_render:function(f){var e;f.beginPath();f.moveTo(this.points[0].x,this.points[0].y);for(var g=0,d=this.points.length;g"].join("")},_render:function(l){var k;l.beginPath();l.moveTo(this.points[0].x,this.points[0].y);for(var m=0,j=this.points.length;m1){E=Math.sqrt(E);O*=E;N*=E}var R=aa/O;var Q=W/O;var D=(-W)/N;var C=(aa)/N;var H=R*M+Q*L;var q=D*M+C*L;var F=R*T+Q*S;var ab=D*T+C*S;var Z=(F-H)*(F-H)+(ab-q)*(ab-q);var U=1/Z-0.25;if(U<0){U=0}var w=Math.sqrt(U);if(P==J){w=-w}var V=0.5*(H+F)-w*(ab-q);var K=0.5*(q+ab)+w*(F-H);var v=Math.atan2(q-K,H-V);var u=Math.atan2(ab-K,F-V);var Y=u-v;if(Y<0&&P==1){Y+=2*Math.PI}else{if(Y>0&&P==0){Y-=2*Math.PI}}var B=Math.ceil(Math.abs(Y/(Math.PI*0.5+0.001)));var I=[];for(var X=0;X"},toObject:function(){var q=g(this.callSuper("toObject"),{path:this.path});if(this.sourcePath){q.sourcePath=this.sourcePath}if(this.transformMatrix){q.transformMatrix=this.transformMatrix}return q},toDatalessObject:function(){var q=this.toObject();if(this.sourcePath){q.path=this.sourcePath}delete q.sourcePath;return q},toSVG:function(){var t=[];for(var r=0,q=this.path.length;r',"',""].join("")},complexity:function(){return this.path.length},_parsePath:function(){var C=[],z,v,y;for(var u=0,t,q,w=this.path.length;uB){for(var r=1,x=q.length;r"];for(var l=0,j=m.length;l");return k.join("")},toString:function(){return"#"},isSameColor:function(){var j=this.getObjects()[0].get("fill");return this.getObjects().every(function(k){return k.get("fill")===j})},complexity:function(){return this.paths.reduce(function(j,k){return j+((k&&k.complexity)?k.complexity():0)},0)},toGrayscale:function(){var j=this.paths.length;while(j--){this.paths[j].toGrayscale()}return this},getObjects:function(){return this.paths}});function c(m){for(var l=0,j=m.length;l"},getObjects:function(){return this.objects},addWithUpdate:function(h){this._restoreObjectsState();this.objects.push(h);this._calcBounds();this._updateObjectsCoords();return this},removeWithUpdate:function(h){this._restoreObjectsState();f(this.objects,h);h.setActive(false);this._calcBounds();this._updateObjectsCoords();return this},add:function(h){this.objects.push(h);return this},remove:function(h){f(this.objects,h);return this},size:function(){return this.getObjects().length},_set:function(j,k){if(j==="fill"||j==="opacity"){var h=this.objects.length;this[j]=k;while(h--){this.objects[h].set(j,k)}}else{this[j]=k}},contains:function(h){return this.objects.indexOf(h)>-1},toObject:function(){return g(this.callSuper("toObject"),{objects:b(this.objects,"toObject")})},render:function(j,o){j.save();this.transform(j);var n=Math.max(this.scaleX,this.scaleY);for(var l=0,h=this.objects.length,k;k=this.objects[l];l++){var m=k.borderScaleFactor;k.borderScaleFactor=n;k.render(j);k.borderScaleFactor=m}if(!o&&this.active){this.drawBorders(j);this.hideCorners||this.drawCorners(j)}j.restore();this.setCoords()},item:function(h){return this.getObjects()[h]},complexity:function(){return this.getObjects().reduce(function(i,h){i+=(typeof h.complexity=="function")?h.complexity():0;return i},0)},_restoreObjectsState:function(){this.objects.forEach(this._restoreObjectState,this);return this},_restoreObjectState:function(j){var l=this.get("left"),m=this.get("top"),h=this.getAngle()*(Math.PI/180),k=j.get("originalLeft"),n=j.get("originalTop"),i=Math.cos(h)*j.get("top")+Math.sin(h)*j.get("left"),o=-Math.sin(h)*j.get("top")+Math.cos(h)*j.get("left");j.setAngle(j.getAngle()+this.getAngle());j.set("left",l+o*this.get("scaleX"));j.set("top",m+i*this.get("scaleY"));j.set("scaleX",j.get("scaleX")*this.get("scaleX"));j.set("scaleY",j.get("scaleY")*this.get("scaleY"));j.setCoords();j.hideCorners=false;j.setActive(false);j.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(h){h.setCoords()});return this},activateAllObjects:function(){this.forEachObject(function(h){h.setActive()});return this},forEachObject:e.StaticCanvas.prototype.forEachObject,_setOpacityIfSame:function(){var j=this.getObjects(),i=j[0]?j[0].get("opacity"):1;var h=j.every(function(k){return k.get("opacity")===i});if(h){this.opacity=i}},_calcBounds:function(){var s=[],q=[],p,n,k,h,m,l,u,r=0,t=this.objects.length;for(;ri.x&&j-hi.y},toGrayscale:function(){var h=this.objects.length;while(h--){this.objects[h].toGrayscale()}},toSVG:function(){var k=[];for(var j=0,h=this.objects.length;j'+k.join("")+"")}});e.Group.fromObject=function(h,i){e.util.enlivenObjects(h.objects,function(j){delete h.objects;i&&i(new e.Group(j,h))})};e.Group.async=true})(typeof exports!="undefined"?exports:this);(function(a){var b=fabric.util.object.extend;if(!a.fabric){a.fabric={}}if(a.fabric.Image){fabric.warn("fabric.Image is already defined.");return}if(!fabric.Object){fabric.warn("fabric.Object is required for fabric.Image initialization");return}fabric.Image=fabric.util.createClass(fabric.Object,{active:false,bordervisibility:false,cornervisibility:false,type:"image",initialize:function(d,c){c||(c={});this.callSuper("initialize",c);this._initElement(d);this._originalImage=this.getElement();this._initConfig(c);this.filters=[];if(c.filters){this.filters=c.filters;this.applyFilters()}},getElement:function(){return this._element},setElement:function(c){this._element=c;this._initConfig();return this},getOriginalSize:function(){var c=this.getElement();return{width:c.width,height:c.height}},setBorderVisibility:function(c){this._resetWidthHeight();this._adjustWidthHeightToBorders(showBorder);this.setCoords()},setCornersVisibility:function(c){this.cornervisibility=!!c},render:function(d,e){d.save();var c=this.transformMatrix;this._resetWidthHeight();if(this.group){d.translate(-this.group.width/2+this.width/2,-this.group.height/2+this.height/2)}if(c){d.transform(c[0],c[1],c[2],c[3],c[4],c[5])}if(!e){this.transform(d)}this._render(d);if(this.active&&!e){this.drawBorders(d);this.hideCorners||this.drawCorners(d)}d.restore()},toObject:function(){return b(this.callSuper("toObject"),{src:this._originalImage.src||this._originalImage._src,filters:this.filters.concat()})},toSVG:function(){return''},getSrc:function(){return this.getElement().src||this.getElement()._src},toString:function(){return'#'},clone:function(c){this.constructor.fromObject(this.toObject(),c)},applyFilters:function(i){if(this.filters.length===0){this.setElement(this._originalImage);i&&i();return}var c=typeof Buffer!=="undefined"&&typeof window==="undefined",g=this._originalImage,e=fabric.document.createElement("canvas"),f=c?new (require("canvas").Image):fabric.document.createElement("img"),h=this;if(!e.getContext&&typeof G_vmlCanvasManager!="undefined"){G_vmlCanvasManager.initElement(e)}e.width=g.width;e.height=g.height;e.getContext("2d").drawImage(g,0,0,g.width,g.height);this.filters.forEach(function(j){j&&j.applyTo(e)});f.onload=function(){h._element=f;i&&i();f.onload=e=g=null};f.width=g.width;f.height=g.height;if(c){var d=e.toDataURL("image/png").replace(/data:image\/png;base64,/,"");f.src=new Buffer(d,"base64");h._element=f;i&&i()}else{f.src=e.toDataURL("image/png")}return this},_render:function(c){c.drawImage(this.getElement(),-this.width/2,-this.height/2,this.width,this.height)},_adjustWidthHeightToBorders:function(c){if(c){this.currentBorder=this.borderwidth;this.width+=(2*this.currentBorder);this.height+=(2*this.currentBorder)}else{this.currentBorder=0}},_resetWidthHeight:function(){var c=this.getElement();this.set("width",c.width);this.set("height",c.height)},_initElement:function(c){this.setElement(fabric.util.getById(c));fabric.util.addClass(this.getElement(),fabric.Image.CSS_CANVAS)},_initConfig:function(c){c||(c={});this.setOptions(c);this._setBorder();this._setWidthHeight(c)},_initFilters:function(c){if(c.filters&&c.filters.length){this.filters=c.filters.map(function(d){return d&&fabric.Image.filters[d.type].fromObject(d)})}},_setBorder:function(){if(this.bordervisibility){this.currentBorder=this.borderwidth}else{this.currentBorder=0}},_setWidthHeight:function(c){var d=2*this.currentBorder;this.width="width" in c?c.width:((this.getElement().width||0)+d);this.height="height" in c?c.height:((this.getElement().height||0)+d)},complexity:function(){return 1}});fabric.Image.CSS_CANVAS="canvas-img";fabric.Image.prototype.getSvgSrc=fabric.Image.prototype.getSrc;fabric.Image.fromObject=function(d,f){var c=fabric.document.createElement("img"),e=d.src;if(d.width){c.width=d.width}if(d.height){c.height=d.height}c.onload=function(){fabric.Image.prototype._initFilters.call(d,d);var g=new fabric.Image(c,d);f&&f(g);c=c.onload=null};c.src=e};fabric.Image.fromURL=function(d,f,e){var c=fabric.document.createElement("img");c.onload=function(){if(f){f(new fabric.Image(c,e))}c=c.onload=null};c.src=d};fabric.Image.ATTRIBUTE_NAMES="x y width height fill fill-opacity opacity stroke stroke-width transform xlink:href".split(" ");fabric.Image.fromElement=function(d,f,c){c||(c={});var e=fabric.parseAttributes(d,fabric.Image.ATTRIBUTE_NAMES);fabric.Image.fromURL(e["xlink:href"],f,b(e,c))};fabric.Image.async=true})(typeof exports!="undefined"?exports:this);fabric.util.object.extend(fabric.Object.prototype,{_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},straighten:function(){var a=this._getAngleValueForStraighten();this.setAngle(a);return this},fxStraighten:function(b){b=b||{};var c=function(){},d=b.onComplete||c,a=b.onChange||c,e=this;fabric.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(f){e.setAngle(f);a()},onComplete:function(){e.setCoords();d()},onStart:function(){e.setActive(false)}});return this}});fabric.util.object.extend(fabric.StaticCanvas.prototype,{straightenObject:function(a){a.straighten();this.renderAll();return this},fxStraightenObject:function(a){a.fxStraighten({onChange:this.renderAll.bind(this)});return this}});fabric.Image.filters={};fabric.Image.filters.Grayscale=fabric.util.createClass({type:"Grayscale",applyTo:function(d){var c=d.getContext("2d"),a=c.getImageData(0,0,d.width,d.height),h=a.data,e=a.width,l=a.height,k,b,g,f;for(g=0;gh&&m>h&&o>h&&p(a-m)0){l[m]=o;l[m+1]=e;l[m+2]=k}}f.putImageData(c,0,0)},toJSON:function(){return{type:this.type,color:this.color}}});fabric.Image.filters.Tint.fromObject=function(a){return new fabric.Image.filters.Tint(a)};(function(b){var c=b.fabric||(b.fabric={}),e=c.util.object.extend,d=c.util.object.clone,a=c.util.toFixed;if(c.Text){c.warn("fabric.Text is already defined");return}if(!c.Object){c.warn("fabric.Text requires fabric.Object");return}c.Text=c.util.createClass(c.Object,{fontSize:40,fontWeight:100,fontFamily:"Times New Roman",textDecoration:"",textShadow:"",textAlign:"left",fontStyle:"",lineHeight:1.3,strokeStyle:"",strokeWidth:1,backgroundColor:"",path:null,type:"text",useNative:true,initialize:function(g,f){this._initStateProperties();this.text=g;this.setOptions(f||{});this._theta=this.angle*Math.PI/180;this._initDimensions();this.setCoords()},_initDimensions:function(){var f=c.document.createElement("canvas");if(!f.getContext&&typeof G_vmlCanvasManager!="undefined"){G_vmlCanvasManager.initElement(f)}this._render(f.getContext("2d"))},_initStateProperties:function(){this.stateProperties=this.stateProperties.concat();this.stateProperties.push("fontFamily","fontWeight","fontSize","path","text","textDecoration","textShadow","textAlign","fontStyle","lineHeight","strokeStyle","strokeWidth","backgroundColor","useNative");c.util.removeFromArray(this.stateProperties,"width")},toString:function(){return"#'},_render:function(f){if(typeof Cufon==="undefined"||this.useNative===true){this._renderViaNative(f)}else{this._renderViaCufon(f)}},_renderViaCufon:function(f){var h=Cufon.textOptions||(Cufon.textOptions={});h.left=this.left;h.top=this.top;h.context=f;h.color=this.fill;var g=this._initDummyElementForCufon();this.transform(f);Cufon.replaceElement(g,{engine:"canvas",separate:"none",fontFamily:this.fontFamily,fontWeight:this.fontWeight,textDecoration:this.textDecoration,textShadow:this.textShadow,textAlign:this.textAlign,fontStyle:this.fontStyle,lineHeight:this.lineHeight,strokeStyle:this.strokeStyle,strokeWidth:this.strokeWidth,backgroundColor:this.backgroundColor});this.width=h.width;this.height=h.height;this._totalLineHeight=h.totalLineHeight;this._fontAscent=h.fontAscent;this._boundaries=h.boundaries;this._shadowOffsets=h.shadowOffsets;this._shadows=h.shadows||[];g=null;this.setCoords()},_renderViaNative:function(f){this.transform(f);this._setTextStyles(f);var g=this.text.split(/\r?\n/);this.width=this._getTextWidth(f,g);this.height=this._getTextHeight(f,g);this._renderTextBackground(f,g);if(this.textAlign!=="left"){f.save();f.translate(this.textAlign==="center"?(this.width/2):this.width,0)}this._setTextShadow(f);this._renderTextFill(f,g);this.textShadow&&f.restore();this._renderTextStroke(f,g);if(this.textAlign!=="left"){f.restore()}this._renderTextDecoration(f,g);this._setBoundaries(f,g);this._totalLineHeight=0;this.setCoords()},_setBoundaries:function(h,k){this._boundaries=[];for(var j=0,g=k.length;jk){k=l}}return k},_setTextShadow:function(f){if(this.textShadow){var j=/\s+(-?\d+)(?:px)?\s+(-?\d+)(?:px)?\s+(\d+)(?:px)?\s*/;var g=this.textShadow;var i=j.exec(this.textShadow);var h=g.replace(j,"");f.save();f.shadowColor=h;f.shadowOffsetX=parseInt(i[1],10);f.shadowOffsetY=parseInt(i[2],10);f.shadowBlur=parseInt(i[3],10);this._shadows=[{blur:f.shadowBlur,color:f.shadowColor,offX:f.shadowOffsetX,offY:f.shadowOffsetY}];this._shadowOffsets=[[parseInt(f.shadowOffsetX,10),parseInt(f.shadowOffsetY,10)]]}},_renderTextFill:function(g,j){this._boundaries=[];for(var h=0,f=j.length;h-1){f.call(this,this.fontSize)}if(this.textDecoration.indexOf("line-through")>-1){f.call(this,this.fontSize/2)}if(this.textDecoration.indexOf("overline")>-1){f.call(this,0)}},_getFontDeclaration:function(){return[this.fontStyle,this.fontWeight,this.fontSize+"px",(c.isLikelyNode?('"'+this.fontFamily+'"'):this.fontFamily)].join(" ")},_initDummyElementForCufon:function(){var g=c.document.createElement("pre"),f=c.document.createElement("div");f.appendChild(g);if(typeof G_vmlCanvasManager=="undefined"){g.innerHTML=this.text}else{g.innerText=this.text.replace(/\r?\n/gi,"\r")}g.style.fontSize=this.fontSize+"px";g.style.letterSpacing="normal";return g},render:function(f,g){f.save();this._render(f);if(!g&&this.active){this.drawBorders(f);this.hideCorners||this.drawCorners(f)}f.restore()},toObject:function(){return e(this.callSuper("toObject"),{text:this.text,fontSize:this.fontSize,fontWeight:this.fontWeight,fontFamily:this.fontFamily,fontStyle:this.fontStyle,lineHeight:this.lineHeight,textDecoration:this.textDecoration,textShadow:this.textShadow,textAlign:this.textAlign,path:this.path,strokeStyle:this.strokeStyle,strokeWidth:this.strokeWidth,backgroundColor:this.backgroundColor,useNative:this.useNative})},toSVG:function(){var i=this.text.split(/\r?\n/),j=this.useNative?this.fontSize*this.lineHeight:(-this._fontAscent-((this._fontAscent/5)*this.lineHeight)),g=-(this.width/2),f=this.useNative?this.fontSize-1:(this.height/2)-(i.length*this.fontSize)-this._totalLineHeight,h=this._getSVGTextAndBg(j,g,i),k=this._getSVGShadows(j,i);f+=(this._fontAscent?((this._fontAscent/5)*this.lineHeight):0);return['',h.textBgRects.join(""),"',k.join(""),h.textSpans.join(""),"",""].join("")},_getSVGShadows:function(h,n){var o=[],k,l,p,g,f=1;if(!this._shadows||!this._boundaries){return o}for(k=0,p=this._shadows.length;k",c.util.string.escapeXml(n[l]),"");f=1}else{f++}}}return o},_getSVGTextAndBg:function(j,h,n){var g=[],k=[],l,m,o,f=1;for(l=0,o=n.length;l",c.util.string.escapeXml(n[l]),"");f=1}else{f++}if(!this.backgroundColor||!this._boundaries){continue}k.push("')}return{textSpans:g,textBgRects:k}},_getFillAttributes:function(f){var g=f?new c.Color(f):"";if(!g||!g.getSource()||g.getAlpha()===1){return'fill="'+f+'"'}return'opacity="'+g.getAlpha()+'" fill="'+g.setAlpha(1).toRgb()+'"'},setColor:function(f){this.set("fill",f);return this},setFontsize:function(f){this.set("fontSize",f);this._initDimensions();this.setCoords();return this},getText:function(){return this.text},setText:function(f){this.set("text",f);this._initDimensions();this.setCoords();return this},_set:function(f,g){if(f==="fontFamily"&&this.path){this.path=this.path.replace(/(.*?)([^\/]*)(\.font\.js)/,"$1"+g+"$3")}this.callSuper("_set",f,g)}});c.Text.ATTRIBUTE_NAMES=("x y fill fill-opacity opacity stroke stroke-width transform font-family font-style font-weight font-size text-decoration").split(" ");c.Text.fromObject=function(f){return new c.Text(f.text,d(f))};c.Text.fromElement=function(g,f){if(!g){return null}var h=c.parseAttributes(g,c.Text.ATTRIBUTE_NAMES);var f=c.util.object.extend((f?c.util.object.clone(f):{}),h);var i=new c.Text(g.textContent,f);return i}})(typeof exports!="undefined"?exports:this);(function(){if(typeof document!="undefined"&&typeof window!="undefined"){return}var DOMParser=new require("xmldom").DOMParser,URL=require("url"),HTTP=require("http"),Canvas=require("canvas"),Image=require("canvas").Image;function request(url,encoding,callback){var oURL=URL.parse(url),client=HTTP.createClient(oURL.port,oURL.hostname),request=client.request("GET",oURL.pathname,{host:oURL.hostname});client.addListener("error",function(err){if(err.errno===process.ECONNREFUSED){fabric.log("ECONNREFUSED: connection refused to "+client.host+":"+client.port)}else{fabric.log(err.message)}});request.end();request.on("response",function(response){var body="";if(encoding){response.setEncoding(encoding)}response.on("end",function(){callback(body)});response.on("data",function(chunk){if(response.statusCode==200){body+=chunk}})})}fabric.util.loadImage=function(url,callback){request(url,"binary",function(body){var img=new Image();img.src=new Buffer(body,"binary");img._src=url;callback(img)})};fabric.loadSVGFromURL=function(url,callback){url=url.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();request(url,"",function(body){fabric.loadSVGFromString(body,callback)})};fabric.loadSVGFromString=function(string,callback){var doc=new DOMParser().parseFromString(string);fabric.parseSVGDocument(doc.documentElement,function(results,options){callback(results,options)})};fabric.util.getScript=function(url,callback){request(url,"",function(body){eval(body);callback&&callback()})};fabric.Image.fromObject=function(object,callback){fabric.util.loadImage(object.src,function(img){var oImg=new fabric.Image(img);oImg._initConfig(object);oImg._initFilters(object);callback(oImg)})};fabric.createCanvasForNode=function(width,height){var canvasEl=fabric.document.createElement("canvas"),nodeCanvas=new Canvas(width||600,height||600);canvasEl.style={};canvasEl.width=nodeCanvas.width;canvasEl.height=nodeCanvas.height;var canvas=fabric.Canvas||fabric.StaticCanvas;var fabricCanvas=new canvas(canvasEl);fabricCanvas.contextContainer=nodeCanvas.getContext("2d");fabricCanvas.nodeCanvas=nodeCanvas;return fabricCanvas};fabric.StaticCanvas.prototype.createPNGStream=function(){return this.nodeCanvas.createPNGStream()};if(fabric.Canvas){fabric.Canvas.prototype.createPNGStream}var origSetWidth=fabric.StaticCanvas.prototype.setWidth;fabric.StaticCanvas.prototype.setWidth=function(width){origSetWidth.call(this);this.nodeCanvas.width=width;return this};if(fabric.Canvas){fabric.Canvas.prototype.setWidth=fabric.StaticCanvas.prototype.setWidth}var origSetHeight=fabric.StaticCanvas.prototype.setHeight;fabric.StaticCanvas.prototype.setHeight=function(height){origSetHeight.call(this);this.nodeCanvas.height=height;return this};if(fabric.Canvas){fabric.Canvas.prototype.setHeight=fabric.StaticCanvas.prototype.setHeight}})(); \ No newline at end of file +var Cufon=(function(){var k=function(){return k.replace.apply(null,arguments)};var u=k.DOM={ready:(function(){var z=false,B={loaded:1,complete:1};var y=[],A=function(){if(z){return}z=true;for(var C;C=y.shift();C()){}};if(fabric.document.addEventListener){fabric.document.addEventListener("DOMContentLoaded",A,false);fabric.window.addEventListener("pageshow",A,false)}if(!fabric.window.opera&&fabric.document.readyState){(function(){B[fabric.document.readyState]?A():setTimeout(arguments.callee,10)})()}if(fabric.document.readyState&&fabric.document.createStyleSheet){(function(){try{fabric.document.body.doScroll("left");A()}catch(C){setTimeout(arguments.callee,1)}})()}o(fabric.window,"load",A);return function(C){if(!arguments.length){A()}else{z?C():y.push(C)}}})()};var l=k.CSS={Size:function(z,y){this.value=parseFloat(z);this.unit=String(z).match(/[a-z%]*$/)[0]||"px";this.convert=function(A){return A/y*this.value};this.convertFrom=function(A){return A/this.value*y};this.toString=function(){return this.value+this.unit}},getStyle:function(y){return new a(y.style)},quotedList:i(function(B){var A=[],z=/\s*((["'])([\s\S]*?[^\\])\2|[^,]+)\s*/g,y;while(y=z.exec(B)){A.push(y[3]||y[1])}return A}),ready:(function(){var A=false;var z=[],B=function(){A=true;for(var D;D=z.shift();D()){}};var y=Object.prototype.propertyIsEnumerable?f("style"):{length:0};var C=f("link");u.ready(function(){var G=0,F;for(var E=0,D=C.length;F=C[E],E=y.length+G){B()}else{setTimeout(arguments.callee,10)}});return function(D){if(A){D()}else{z.push(D)}}})(),supports:function(A,z){var y=fabric.document.createElement("span").style;if(y[A]===undefined){return false}y[A]=z;return y[A]===z},textAlign:function(B,A,y,z){if(A.get("textAlign")=="right"){if(y>0){B=" "+B}}else{if(y400}if(F==500){F=400}for(var G in D){G=parseInt(G,10);if(!C||GA){A=G}H.push(G)}if(FA){F=A}H.sort(function(J,I){return(B?(J>F&&I>F)?JI:(JI:Jz){z=e}L.push(e);e=0;continue}var B=ab.glyphs[ag[aa]]||ab.missingGlyph;if(!B){continue}e+=D=Number(B.w||ab.w)+U}L.push(e);e=Math.max(z,e);var m=[];for(var aa=L.length;aa--;){m[aa]=e-L[aa]}if(D===null){return null}V+=(H.width-D);C+=H.minX;var v,p;if(n){v=J;p=J.firstChild}else{v=fabric.document.createElement("span");v.className="cufon cufon-canvas";v.alt=E;p=fabric.document.createElement("canvas");v.appendChild(p);if(A.printable){var Y=fabric.document.createElement("span");Y.className="cufon-alt";Y.appendChild(fabric.document.createTextNode(E));v.appendChild(Y)}}var ah=v.style;var O=p.style||{};var k=o.convert(H.height-I+T);var af=Math.ceil(k);var S=af/k;p.width=Math.ceil(o.convert(e+V-C)*S);p.height=af;I+=H.minY;O.top=Math.round(o.convert(I-ab.ascent))+"px";O.left=Math.round(o.convert(C))+"px";var j=Math.ceil(o.convert(e*S));var t=j+"px";var s=o.convert(ab.height);var F=(A.lineHeight-1)*o.convert(-ab.ascent/5)*(M-1);Cufon.textOptions.width=j;Cufon.textOptions.height=(s*M)+F;Cufon.textOptions.lines=M;Cufon.textOptions.totalLineHeight=F;if(a){ah.width=t;ah.height=s+"px"}else{ah.paddingLeft=t;ah.paddingBottom=(s-1)+"px"}var ad=Cufon.textOptions.context||p.getContext("2d"),K=af/H.height;Cufon.textOptions.fontAscent=ab.ascent*K;Cufon.textOptions.boundaries=null;for(var w=Cufon.textOptions.shadowOffsets,aa=R.length;aa--;){w[aa]=[R[aa][0]*K,R[aa][1]*K]}ad.save();ad.scale(K,K);ad.translate(-C-((1/K*p.width)/2)+(Cufon.fonts[ab.family].offsetLeft||0),-I-((Cufon.textOptions.height/K)/2)+(Cufon.fonts[ab.family].offsetTop||0));ad.lineWidth=ab.face["underline-thickness"];ad.save();function q(l,i){ad.strokeStyle=i;ad.beginPath();ad.moveTo(0,l);ad.lineTo(e,l);ad.stroke()}var r=Cufon.getTextDecoration(A),u=A.fontStyle==="italic";function ae(){ad.save();ad.fillStyle=A.backgroundColor;var aj=0,an=0,y=[{left:0}];if(A.textAlign==="right"){ad.translate(m[an],0);y[0].left=m[an]*K}else{if(A.textAlign==="center"){ad.translate(m[an]/2,0);y[0].left=m[an]/2*K}}for(var al=0,ak=ag.length;al.cufon-vml-canvas{text-indent:0}@media screen{cvml\\:shape,cvml\\:shadow{behavior:url(#default#VML);display:block;antialias:true;position:absolute}.cufon-vml-canvas{position:absolute;text-align:left}.cufon-vml{display:inline-block;position:relative;vertical-align:middle}.cufon-vml .cufon-alt{position:absolute;left:-10000in;font-size:1px}a .cufon-vml{cursor:pointer}}@media print{.cufon-vml *{display:none}.cufon-vml .cufon-alt{display:inline}}');function c(e,f){return a(e,/(?:em|ex|%)$/i.test(f)?"1em":f)}function a(h,i){if(/px$/i.test(i)){return parseFloat(i)}var g=h.style.left,f=h.runtimeStyle.left;h.runtimeStyle.left=h.currentStyle.left;h.style.left=i;var e=h.style.pixelLeft;h.style.left=g;h.runtimeStyle.left=f;return e}return function(T,z,O,w,D,U,M){var h=(z===null);if(h){z=D.alt}var B=T.viewBox;var j=O.computedFontSize||(O.computedFontSize=new Cufon.CSS.Size(c(U,O.get("fontSize"))+"px",T.baseSize));var L=O.computedLSpacing;if(L==undefined){L=O.get("letterSpacing");O.computedLSpacing=L=(L=="normal")?0:~~j.convertFrom(a(U,L))}var t,m;if(h){t=D;m=D.firstChild}else{t=fabric.document.createElement("span");t.className="cufon cufon-vml";t.alt=z;m=fabric.document.createElement("span");m.className="cufon-vml-canvas";t.appendChild(m);if(w.printable){var R=fabric.document.createElement("span");R.className="cufon-alt";R.appendChild(fabric.document.createTextNode(z));t.appendChild(R)}if(!M){t.appendChild(fabric.document.createElement("cvml:shape"))}}var Z=t.style;var G=m.style;var f=j.convert(B.height),W=Math.ceil(f);var K=W/f;var J=B.minX,I=B.minY;G.height=W;G.top=Math.round(j.convert(I-T.ascent));G.left=Math.round(j.convert(J));Z.height=j.convert(T.height)+"px";var p=Cufon.getTextDecoration(w);var y=O.get("color");var X=Cufon.CSS.textTransform(z,O).split("");var e=0,H=0,q=null;var x,r,A=w.textShadow;for(var S=0,Q=0,P=X.length;Sv?p:(o-n);s(t(y,m,w,p));if(o>v||q()){x.onComplete&&x.onComplete();return}k(r)})()}var f=fabric.window.requestAnimationFrame||fabric.window.webkitRequestAnimationFrame||fabric.window.mozRequestAnimationFrame||fabric.window.oRequestAnimationFrame||fabric.window.msRequestAnimationFrame||function(m){fabric.window.setTimeout(m,1000/60)};var k=function(){return f.apply(fabric.window,arguments)};function b(n,p,o){if(n){var m=new Image();m.onload=function(){p&&p.call(o,m);m=m.onload=null};m.src=n}else{p&&p.call(o,n)}}function i(p,s){function o(t){return fabric[fabric.util.string.camelize(fabric.util.string.capitalize(t))]}function n(){if(++r===m){if(s){s(q)}}}var q=[],r=0,m=p.length;p.forEach(function(v,u){if(!v.type){return}var t=o(v.type);if(t.async){t.fromObject(v,function(w){q[u]=w;n()})}else{q[u]=t.fromObject(v);n()}})}function a(o,n,p){var m=o.length>1?new fabric.PathGroup(o,n):o[0];if(typeof p!=="undefined"){m.setSourcePath(p)}return m}fabric.util.removeFromArray=j;fabric.util.degreesToRadians=c;fabric.util.toFixed=e;fabric.util.getRandomInt=g;fabric.util.falseFunction=l;fabric.util.animate=d;fabric.util.requestAnimFrame=k;fabric.util.loadImage=b;fabric.util.enlivenObjects=i;fabric.util.groupSVGElements=a})();(function(){var d=Array.prototype.slice;if(!Array.prototype.indexOf){Array.prototype.indexOf=function(g){if(this===void 0||this===null){throw new TypeError()}var h=Object(this),e=h.length>>>0;if(e===0){return -1}var i=0;if(arguments.length>0){i=Number(arguments[1]);if(i!==i){i=0}else{if(i!==0&&i!==(1/0)&&i!==-(1/0)){i=(i>0||-1)*Math.floor(Math.abs(i))}}}if(i>=e){return -1}var f=i>=0?i:Math.max(e-Math.abs(i),0);for(;f>>0;f>>0;g>>0;f>>0;f>>0;g>>0,f=0,h;if(arguments.length>1){h=arguments[1]}else{do{if(f in this){h=this[f++];break}if(++f>=e){throw new TypeError()}}while(true)}for(;f=e){e=h[f][g]}}}else{while(f--){if(h[f]>=e){e=h[f]}}}return e}function c(h,g){if(!h||h.length===0){return undefined}var f=h.length-1,e=g?h[f][g]:h[f];if(g){while(f--){if(h[f][g]/g,">")}fabric.util.string={camelize:b,capitalize:c,escapeXml:a}}());(function(){var c=Array.prototype.slice,a=Function.prototype.apply,b=function(){};if(!Function.prototype.bind){Function.prototype.bind=function(d){var g=this,e=c.call(arguments,1),f;if(e.length){f=function(){return a.call(g,this instanceof b?this:d,e.concat(c.call(arguments)))}}else{f=function(){return a.call(g,this instanceof b?this:d,arguments)}}b.prototype=this.prototype;f.prototype=new b();return f}}})();(function(){var f=Array.prototype.slice,e=function(){};var c=(function(){for(var g in {toString:1}){if(g==="toString"){return false}}return true})();var b=function(g,j,h){for(var i in j){if(i in g.prototype&&typeof g.prototype[i]==="function"){g.prototype[i]=(function(k){return function(){var m=this.constructor.superclass;this.constructor.superclass=h;var l=j[k].apply(this,arguments);this.constructor.superclass=m;if(k!=="initialize"){return l}}})(i)}else{g.prototype[i]=j[i]}if(c){if(j.toString!==Object.prototype.toString){g.prototype.toString=j.toString}if(j.valueOf!==Object.prototype.valueOf){g.prototype.valueOf=j.valueOf}}}};function a(){}function d(){var k=null,j=f.call(arguments,0);if(typeof j[0]==="function"){k=j.shift()}function g(){this.initialize.apply(this,arguments)}g.superclass=k;g.subclasses=[];if(k){a.prototype=k.prototype;g.prototype=new a();k.subclasses.push(g)}for(var h=0,l=j.length;h-1?b(g,i.match(/opacity:\s*(\d?\.?\d*)/)[1]):g}for(var j in i){if(j==="opacity"){b(g,i[j])}else{var h=(j==="float"||j==="cssFloat")?(typeof k.styleFloat==="undefined"?"cssFloat":"styleFloat"):j;k[h]=i[j]}}return g}var f=fabric.document.createElement("div"),e=typeof f.style.opacity==="string",a=typeof f.style.filter==="string",c=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,b=function(g){return g};if(e){b=function(g,h){g.style.opacity=h;return g}}else{if(a){b=function(g,h){var i=g.style;if(g.currentStyle&&!g.currentStyle.hasLayout){i.zoom=1}if(c.test(i.filter)){h=h>=0.9999?"":("alpha(opacity="+(h*100)+")");i.filter=i.filter.replace(c,h)}else{i.filter+=" alpha(opacity="+(h*100)+")"}return g}}}fabric.util.setStyle=d})();(function(){var h=Array.prototype.slice;function g(j){return typeof j==="string"?fabric.document.getElementById(j):j}var b=function(j){return h.call(j,0)};var i;try{i=b(fabric.document.childNodes) instanceof Array}catch(a){}if(!i){b=function(k){var j=new Array(k.length),l=k.length;while(l--){j[l]=k[l]}return j}}function c(k,j){var l=fabric.document.createElement(k);for(var m in j){if(m==="class"){l.className=j[m]}else{if(m==="for"){l.htmlFor=j[m]}else{l.setAttribute(m,j[m])}}}return l}function f(j,k){if((" "+j.className+" ").indexOf(" "+k+" ")===-1){j.className+=(j.className?" ":"")+k}}function e(k,l,j){if(typeof l==="string"){l=c(l,j)}if(k.parentNode){k.parentNode.replaceChild(l,k)}l.appendChild(k);return l}function d(k){var j=0,l=0;do{j+=k.offsetTop||0;l+=k.offsetLeft||0;k=k.offsetParent}while(k);return({left:l,top:j})}(function(){var k=fabric.document.documentElement.style;var l="userSelect" in k?"userSelect":"MozUserSelect" in k?"MozUserSelect":"WebkitUserSelect" in k?"WebkitUserSelect":"KhtmlUserSelect" in k?"KhtmlUserSelect":"";function m(n){if(typeof n.onselectstart!=="undefined"){n.onselectstart=fabric.util.falseFunction}if(l){n.style[l]="none"}else{if(typeof n.unselectable==="string"){n.unselectable="on"}}return n}function j(n){if(typeof n.onselectstart!=="undefined"){n.onselectstart=null}if(l){n.style[l]=""}else{if(typeof n.unselectable==="string"){n.unselectable=""}}return n}fabric.util.makeElementUnselectable=m;fabric.util.makeElementSelectable=j})();(function(){function j(k,o){var m=fabric.document.getElementsByTagName("head")[0],l=fabric.document.createElement("script"),n=true;l.type="text/javascript";l.setAttribute("runat","server");l.onload=l.onreadystatechange=function(p){if(n){if(typeof this.readyState==="string"&&this.readyState!=="loaded"&&this.readyState!=="complete"){return}n=false;o(p||fabric.window.event);l=l.onload=l.onreadystatechange=null}};l.src=k;m.appendChild(l)}fabric.util.getScript=j})();fabric.util.getById=g;fabric.util.toArray=b;fabric.util.makeElement=c;fabric.util.addClass=f;fabric.util.wrapElement=e;fabric.util.getElementOffset=d})();(function(){function d(e,f){return e+(/\?/.test(e)?"&":"?")+f}var c=(function(){var h=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest()}];for(var e=h.length;e--;){try{var g=h[e]();if(g){return h[e]}}catch(f){}}})();function a(){}function b(g,f){f||(f={});var j=f.method?f.method.toUpperCase():"GET",h=f.onComplete||function(){},i=c(),e;i.onreadystatechange=function(){if(i.readyState===4){h(i);i.onreadystatechange=a}};if(j==="GET"){e=null;if(typeof f.parameters==="string"){g=d(g,f.parameters)}}i.open(j,g,true);if(j==="POST"||j==="PUT"){i.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}i.send(e);return i}fabric.util.request=b})();(function(){function d(F,E,H,G){return H*(F/=G)*F+E}function l(F,E,H,G){return -H*(F/=G)*(F-2)+E}function r(F,E,H,G){F/=(G/2);if(F<1){return H/2*F*F+E}return -H/2*((--F)*(F-2)-1)+E}function B(F,E,H,G){return H*(F/=G)*F*F+E}function q(F,E,H,G){return H*((F=F/G-1)*F*F+1)+E}function u(F,E,H,G){F/=G/2;if(F<1){return H/2*F*F*F+E}return H/2*((F-=2)*F*F+2)+E}function t(F,E,H,G){return H*(F/=G)*F*F*F+E}function g(F,E,H,G){return -H*((F=F/G-1)*F*F*F-1)+E}function k(F,E,H,G){F/=G/2;if(F<1){return H/2*F*F*F*F+E}return -H/2*((F-=2)*F*F*F-2)+E}function y(F,E,H,G){return H*(F/=G)*F*F*F*F+E}function j(F,E,H,G){return H*((F=F/G-1)*F*F*F*F+1)+E}function n(F,E,H,G){F/=G/2;if(F<1){return H/2*F*F*F*F*F+E}return H/2*((F-=2)*F*F*F*F+2)+E}function f(F,E,H,G){return -H*Math.cos(F/G*(Math.PI/2))+H+E}function o(F,E,H,G){return H*Math.sin(F/G*(Math.PI/2))+E}function v(F,E,H,G){return -H/2*(Math.cos(Math.PI*F/G)-1)+E}function D(F,E,H,G){return(F===0)?E:H*Math.pow(2,10*(F/G-1))+E}function c(F,E,H,G){return(F===G)?E+H:H*(-Math.pow(2,-10*F/G)+1)+E}function i(F,E,H,G){if(F===0){return E}if(F===G){return E+H}F/=G/2;if(F<1){return H/2*Math.pow(2,10*(F-1))+E}return H/2*(-Math.pow(2,-10*--F)+2)+E}function h(F,E,H,G){return -H*(Math.sqrt(1-(F/=G)*F)-1)+E}function p(F,E,H,G){return H*Math.sqrt(1-(F=F/G-1)*F)+E}function x(F,E,H,G){F/=G/2;if(F<1){return -H/2*(Math.sqrt(1-F*F)-1)+E}return H/2*(Math.sqrt(1-(F-=2)*F)+1)+E}function s(G,E,K,J){var H=1.70158;var I=0;var F=K;if(G===0){return E}G/=J;if(G===1){return E+K}if(!I){I=J*0.3}if(F-1;w=w.split(/\s+/);var u=[],v,t;if(y){v=0;t=w.length;for(;v/i,""))}if(!x.documentElement){return}h.parseSVGDocument(x.documentElement,function(A,z){k.set(u,{objects:h.util.array.invoke(A,"toObject"),options:z});w(A,z)},t)}}function b(v){var u=v.objects,t=v.options;u=u.map(function(w){return h[f(w.type)].fromObject(w)});return({objects:u,options:t})}function n(u,x,t){u=u.trim();var v;if(typeof DOMParser!=="undefined"){var w=new DOMParser();if(w&&w.parseFromString){v=w.parseFromString(u,"text/xml")}}else{if(h.window.ActiveXObject){v=new ActiveXObject("Microsoft.XMLDOM");v.async="false";v.loadXML(u.replace(//i,""))}}h.parseSVGDocument(v.documentElement,function(z,y){x(z,y)},t)}function m(w){var u="";for(var v=0,t=w.length;v",'",""].join("")}return u}p(h,{parseAttributes:e,parseElements:g,parseStyleAttribute:i,parsePointsAttribute:s,getCSSRules:d,loadSVGFromURL:c,loadSVGFromString:n,createSVGFontFacesMarkup:m})})(typeof exports!=="undefined"?exports:this);(function(){function c(h){var g=h.getAttribute("style");if(g){var k=g.split(/\s*;\s*/);if(k[k.length-1]===""){k.pop()}for(var f=k.length;f--;){var e=k[f].split(/\s*:\s*/),d=e[0].trim(),j=e[1].trim();if(d==="stop-color"){return j}}}}fabric.Gradient=fabric.util.createClass({initialize:function(d){d||(d={});this.x1=d.x1||0;this.y1=d.y1||0;this.x2=d.x2||0;this.y2=d.y2||0;this.colorStops=d.colorStops},toObject:function(){return{x1:this.x1,x2:this.x2,y1:this.y1,y2:this.y2,colorStops:this.colorStops}},toLiveGradient:function(e){var g=e.createLinearGradient(this.x1,this.y1,this.x2||e.canvas.width,this.y2);for(var d in this.colorStops){var f=this.colorStops[d];g.addColorStop(parseFloat(d),f)}return g}});fabric.util.object.extend(fabric.Gradient,{fromElement:function(g,d){var k=g.getElementsByTagName("stop"),j,e={},h={x1:g.getAttribute("x1")||0,y1:g.getAttribute("y1")||0,x2:g.getAttribute("x2")||"100%",y2:g.getAttribute("y2")||0};for(var f=k.length;f--;){g=k[f];j=g.getAttribute("offset");j=parseFloat(j)/(/%$/.test(j)?100:1);e[j]=c(g)||g.getAttribute("stop-color")}a(d,h);return new fabric.Gradient({x1:h.x1,y1:h.y1,x2:h.x2,y2:h.y2,colorStops:e})},forObject:function(e,d){d||(d={});a(e,d);return new fabric.Gradient(d)}});function a(f,e){for(var g in e){if(typeof e[g]==="string"&&/^\d+%$/.test(e[g])){var d=parseFloat(e[g],10);if(g==="x1"||g==="x2"){e[g]=f.width*d/100}else{if(g==="y1"||g==="y2"){e[g]=f.height*d/100}}}if(g==="x1"||g==="x2"){e[g]-=f.width/2}else{if(g==="y1"||g==="y2"){e[g]-=f.height/2}}}}function b(j){var f=j.getElementsByTagName("linearGradient"),d=j.getElementsByTagName("radialGradient"),g,e,h={};e=f.length;for(;e--;){g=f[e];h[g.getAttribute("id")]=g}e=d.length;for(;e--;){g=d[e];h[g.getAttribute("id")]=g}return h}fabric.getGradientDefs=b})();(function(b){var c=b.fabric||(b.fabric={});if(c.Point){c.warn("fabric.Point is already defined");return}c.Point=a;function a(d,e){if(arguments.length>0){this.init(d,e)}}a.prototype={constructor:a,init:function(d,e){this.x=d;this.y=e},add:function(d){return new a(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 a(this.x+d,this.y+d)},scalarAddEquals:function(d){this.x+=d;this.y+=d;return this},subtract:function(d){return new a(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 a(this.x-d,this.y-d)},scalarSubtractEquals:function(d){this.x-=d;this.y-=d;return this},multiply:function(d){return new a(this.x*d,this.y*d)},multiplyEquals:function(d){this.x*=d;this.y*=d;return this},divide:function(d){return new a(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.xd.x&&this.y>d.y)},gte:function(d){return(this.x>=d.x&&this.y>=d.y)},lerp:function(e,d){return new a(this.x+(e.x-this.x)*d,this.y+(e.y-this.y)*d)},distanceFrom:function(f){var e=this.x-f.x,d=this.y-f.y;return Math.sqrt(e*e+d*d)},min:function(d){return new a(Math.min(this.x,d.x),Math.min(this.y,d.y))},max:function(d){return new a(Math.max(this.x,d.x),Math.max(this.y,d.y))},toString:function(){return this.x+","+this.y},setXY:function(d,e){this.x=d;this.y=e},setFromPoint:function(d){this.x=d.x;this.y=d.y},swap:function(e){var d=this.x,f=this.y;this.x=e.x;this.y=e.y;e.x=d;e.y=f}}})(typeof exports!=="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={});if(b.Intersection){b.warn("fabric.Intersection is already defined");return}function c(d){if(arguments.length>0){this.init(d)}}b.Intersection=c;b.Intersection.prototype={init:function(d){this.status=d;this.points=[]},appendPoint:function(d){this.points.push(d)},appendPoints:function(d){this.points=this.points.concat(d)}};b.Intersection.intersectLineLine=function(h,f,l,k){var m,i=(k.x-l.x)*(h.y-l.y)-(k.y-l.y)*(h.x-l.x),j=(f.x-h.x)*(h.y-l.y)-(f.y-h.y)*(h.x-l.x),g=(k.y-l.y)*(f.x-h.x)-(k.x-l.x)*(f.y-h.y);if(g!==0){var e=i/g,d=j/g;if(0<=e&&e<=1&&0<=d&&d<=1){m=new c("Intersection");m.points.push(new b.Point(h.x+e*(f.x-h.x),h.y+e*(f.y-h.y)))}else{m=new c("No Intersection")}}else{if(i===0||j===0){m=new c("Coincident")}else{m=new c("Parallel")}}return m};b.Intersection.intersectLinePolygon=function(e,d,l){var m=new c("No Intersection"),f=l.length;for(var h=0;h0){m.status="Intersection"}return m};b.Intersection.intersectPolygonPolygon=function(j,h){var f=new c("No Intersection"),l=j.length;for(var k=0;k0){f.status="Intersection"}return f};b.Intersection.intersectPolygonRectangle=function(n,e,d){var g=e.min(d),m=e.max(d),f=new b.Point(m.x,g.y),l=new b.Point(g.x,m.y),k=c.intersectLinePolygon(g,f,n),j=c.intersectLinePolygon(f,m,n),i=c.intersectLinePolygon(m,l,n),h=c.intersectLinePolygon(l,g,n),o=new c("No Intersection");o.appendPoints(k.points);o.appendPoints(j.points);o.appendPoints(i.points);o.appendPoints(h.points);if(o.points.length>0){o.status="Intersection"}return o}})(typeof exports!=="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={});if(b.Color){b.warn("fabric.Color is already defined.");return}function c(d){if(!d){this.setSource([0,0,0,1])}else{this._tryParsingColor(d)}}b.Color=c;b.Color.prototype={_tryParsingColor:function(d){var e=c.sourceFromHex(d);if(!e){e=c.sourceFromRgb(d)}if(e){this.setSource(e)}},getSource:function(){return this._source},setSource:function(d){this._source=d},toRgb:function(){var d=this.getSource();return"rgb("+d[0]+","+d[1]+","+d[2]+")"},toRgba:function(){var d=this.getSource();return"rgba("+d[0]+","+d[1]+","+d[2]+","+d[3]+")"},toHex:function(){var h=this.getSource();var f=h[0].toString(16);f=(f.length===1)?("0"+f):f;var e=h[1].toString(16);e=(e.length===1)?("0"+e):e;var d=h[2].toString(16);d=(d.length===1)?("0"+d):d;return f.toUpperCase()+e.toUpperCase()+d.toUpperCase()},getAlpha:function(){return this.getSource()[3]},setAlpha:function(e){var d=this.getSource();d[3]=e;this.setSource(d);return this},toGrayscale:function(){var f=this.getSource(),e=parseInt((f[0]*0.3+f[1]*0.59+f[2]*0.11).toFixed(0),10),d=f[3];this.setSource([e,e,e,d]);return this},toBlackWhite:function(d){var g=this.getSource(),f=(g[0]*0.3+g[1]*0.59+g[2]*0.11).toFixed(0),e=g[3];d=d||127;f=(Number(f)','',"',"Created with Fabric.js ",fabric.version,"",fabric.createSVGFontFacesMarkup(this.getObjects())];if(this.backgroundImage){g.push('')}for(var h=0,j=this.getObjects(),f=j.length;h");return g.join("")},isEmpty:function(){return this._objects.length===0},remove:function(f){d(this._objects,f);if(this.getActiveObject()===f){this.fire("before:selection:cleared",{target:f});this.discardActiveObject();this.fire("selection:cleared")}this.renderAll();return f},sendToBack:function(f){d(this._objects,f);this._objects.unshift(f);return this.renderAll()},bringToFront:function(f){d(this._objects,f);this._objects.push(f);return this.renderAll()},sendBackwards:function(h){var g=this._objects.indexOf(h),f=g;if(g!==0){for(var j=g-1;j>=0;--j){if(h.intersectsWithObject(this._objects[j])||h.isContainedWithinObject(this._objects[j])){f=j;break}}d(this._objects,h);this._objects.splice(f,0,h)}return this.renderAll()},bringForward:function(j){var m=this.getObjects(),g=m.indexOf(j),f=g;if(g!==m.length-1){for(var k=g+1,h=this._objects.length;k"};e(fabric.StaticCanvas,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(k){var h=k.getContext("2d"),f=h.getImageData(0,0,k.width,k.height),o=f.data,l=f.width,q=f.height,p,g,n,m;for(n=0;n0){if(B>this.targetFindTolerance){B-=this.targetFindTolerance}else{B=0}if(A>this.targetFindTolerance){A-=this.targetFindTolerance}else{A=0}}var v=true;var r=w.getImageData(B,A,(this.targetFindTolerance*2)||1,(this.targetFindTolerance*2)||1);for(var u=3;u0)?0:-v),r.ey-((u>0)?0:-u),t,s);this.contextTop.lineWidth=this.selectionLineWidth;this.contextTop.strokeStyle=this.selectionBorderColor;this.contextTop.strokeRect(r.ex+a-((v>0)?0:t),r.ey+a-((u>0)?0:s),t,s)},_findSelectedObjects:function(v){var B=[],s=this._groupSelector.ex,A=this._groupSelector.ey,r=s+this._groupSelector.left,y=A+this._groupSelector.top,x,w=new fabric.Point(f(s,r),f(A,y)),z=new fabric.Point(l(s,r),l(A,y));for(var t=0,u=this._objects.length;t1){B=new fabric.Group(B);this.setActiveGroup(B);B.saveCoords();this.fire("selection:created",{target:B})}}this.renderAll()},findTarget:function(z,u){var A,r=this.getPointer(z);var t=this.getActiveGroup();if(t&&!u&&this.containsPoint(z,t)){A=t;return A}var s=[];for(var w=this._objects.length;w--;){if(this._objects[w]&&this.containsPoint(z,this._objects[w])){if(this.perPixelTargetFind||this._objects[w].perPixelTargetFind){s[s.length]=this._objects[w]}else{A=this._objects[w];this.relatedTarget=A;break}}}for(var v=0,y=s.length;v1)?p.apply(this,n.call(arguments,1)):p.call(this)},initialize:function(i){if(i){this.setOptions(i)}},_initGradient:function(i){if(i.fill&&typeof i.fill==="object"&&!(i.fill instanceof d.Gradient)){this.set("fill",new d.Gradient(i.fill))}},setOptions:function(p){var q=this.stateProperties.length,r;while(q--){r=this.stateProperties[q];if(r in p){this.set(r,p[r])}}this._initGradient(p)},transform:function(i){i.globalAlpha=this.opacity;i.translate(this.left,this.top);i.rotate(this._theta);i.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toObject:function(){var p=d.Object.NUM_FRACTION_DIGITS;var i={type:this.type,left:c(this.left,p),top:c(this.top,p),width:c(this.width,p),height:c(this.height,p),fill:(this.fill&&this.fill.toObject)?this.fill.toObject():this.fill,overlayFill:this.overlayFill,stroke:this.stroke,strokeWidth:this.strokeWidth,strokeDashArray:this.strokeDashArray,scaleX:c(this.scaleX,p),scaleY:c(this.scaleY,p),angle:c(this.getAngle(),p),flipX:this.flipX,flipY:this.flipY,opacity:c(this.opacity,p),selectable:this.selectable,hasControls:this.hasControls,hasBorders:this.hasBorders,hasRotatingPoint:this.hasRotatingPoint,transparentCorners:this.transparentCorners,perPixelTargetFind:this.perPixelTargetFind};if(!this.includeDefaultValues){i=this._removeDefaultValues(i)}return i},toDatalessObject:function(){return this.toObject()},getSvgStyles:function(){return["stroke: ",(this.stroke?this.stroke:"none"),"; ","stroke-width: ",(this.strokeWidth?this.strokeWidth:"0"),"; ","stroke-dasharray: ",(this.strokeDashArray?this.strokeDashArray.join(" "):"; "),"fill: ",(this.fill?this.fill:"none"),"; ","opacity: ",(this.opacity?this.opacity:"1"),";"].join("")},getSvgTransform:function(){var i=this.getAngle();return["translate(",c(this.left,2)," ",c(this.top,2),")",i!==0?(" rotate("+c(i,2)+")"):"",(this.scaleX===1&&this.scaleY===1)?"":(" scale("+c(this.scaleX,2)+" "+c(this.scaleY,2)+")")].join("")},_removeDefaultValues:function(p){var i=d.Object.prototype.options;if(i){this.stateProperties.forEach(function(q){if(p[q]===i[q]){delete p[q]}})}return p},isActive:function(){return !!this.active},setActive:function(i){this.active=!!i;return this},toString:function(){return"#"},set:function(i,p){if(typeof i==="object"){for(var q in i){this._set(q,i[q])}}else{if(typeof p==="function"){this._set(i,p(this.get(i)))}else{this._set(i,p)}}return this},_set:function(i,p){var q=(i==="scaleX"||i==="scaleY")&&p1?this.strokeWidth:0,A=this.padding;this.currentWidth=(this.width+y)*this.scaleX+A*2;this.currentHeight=(this.height+y)*this.scaleY+A*2;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 v=Math.cos(this._angle+this._theta)*this._hypotenuse,u=Math.sin(this._angle+this._theta)*this._hypotenuse,q=this._theta,z=Math.sin(q),x=Math.cos(q);var D={x:this.left-v,y:this.top-u};var w={x:D.x+(this.currentWidth*x),y:D.y+(this.currentWidth*z)};var C={x:w.x-(this.currentHeight*z),y:w.y+(this.currentHeight*x)};var r={x:D.x-(this.currentHeight*z),y:D.y+(this.currentHeight*x)};var t={x:D.x-(this.currentHeight/2*z),y:D.y+(this.currentHeight/2*x)};var i={x:D.x+(this.currentWidth/2*x),y:D.y+(this.currentWidth/2*z)};var p={x:w.x-(this.currentHeight/2*z),y:w.y+(this.currentHeight/2*x)};var B={x:r.x+(this.currentWidth/2*x),y:r.y+(this.currentWidth/2*z)};var s={x:D.x+(this.currentWidth/2*x),y:D.y+(this.currentWidth/2*z)};this.oCoords={tl:D,tr:w,br:C,bl:r,ml:t,mt:i,mr:p,mb:B,mtr:s};this._setCornerCoords();return this},getBoundingRectWidth:function(){this.oCoords||this.setCoords();var p=[this.oCoords.tl.x,this.oCoords.tr.x,this.oCoords.br.x,this.oCoords.bl.x];var i=d.util.array.min(p);var q=d.util.array.max(p);return Math.abs(i-q)},getBoundingRectHeight:function(){this.oCoords||this.setCoords();var i=[this.oCoords.tl.y,this.oCoords.tr.y,this.oCoords.br.y,this.oCoords.bl.y];var q=d.util.array.min(i);var p=d.util.array.max(i);return Math.abs(q-p)},drawBorders:function(y){if(!this.hasBorders){return}var r=d.Object.MIN_SCALE_LIMIT,t=this.padding,i=t*2,s=this.strokeWidth>1?this.strokeWidth:0;y.save();y.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;y.strokeStyle=this.borderColor;var x=1/(this.scaleXi){z=x-i}if(B){p+=(A*B)-(z*B||0)}else{w+=(A*y)-(z*y||0)}q[1&s?"moveTo":"lineTo"](p,w);if(s>=t){s=0}}}r(1,0);r(0,1);r(-1,0);r(0,-1);q.stroke();q.closePath();q.restore()},drawCorners:function(A){if(!this.hasControls){return}var w=this.cornersize,q=w/2,i=this.strokeWidth/2,p=-(this.width/2),u=-(this.height/2),G,B,y=w/this.scaleX,v=w/this.scaleY,D=this.padding/this.scaleX,C=this.padding/this.scaleY,E=q/this.scaleY,F=q/this.scaleX,s=(q-w)/this.scaleX,r=(q-w)/this.scaleY,x=this.height,z=this.width,t=this.transparentCorners?"strokeRect":"fillRect";A.save();A.lineWidth=1/Math.max(this.scaleX,this.scaleY);A.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1;A.strokeStyle=A.fillStyle=this.cornerColor;G=p-F-i-D;B=u-E-i-C;A.clearRect(G,B,y,v);A[t](G,B,y,v);G=p+z-F+i+D;B=u-E-i-C;A.clearRect(G,B,y,v);A[t](G,B,y,v);G=p-F-i-D;B=u+x+r+i+C;A.clearRect(G,B,y,v);A[t](G,B,y,v);G=p+z+s+i+D;B=u+x+r+i+C;A.clearRect(G,B,y,v);A[t](G,B,y,v);if(!this.lockUniScaling){G=p+z/2-F;B=u-E-i-C;A.clearRect(G,B,y,v);A[t](G,B,y,v);G=p+z/2-F;B=u+x+r+i+C;A.clearRect(G,B,y,v);A[t](G,B,y,v);G=p+z+s+i+D;B=u+x/2-E;A.clearRect(G,B,y,v);A[t](G,B,y,v);G=p-F-i-D;B=u+x/2-E;A.clearRect(G,B,y,v);A[t](G,B,y,v)}if(this.hasRotatingPoint){G=p+z/2-F;B=this.flipY?(u+x+(this.rotatingPointOffset/this.scaleY)-v/2+i+C):(u-(this.rotatingPointOffset/this.scaleY)-v/2-i-C);A.clearRect(G,B,y,v);A[t](G,B,y,v)}A.restore();return this},clone:function(i){if(this.constructor.fromObject){return this.constructor.fromObject(this.toObject(),i)}return new d.Object(this.toObject())},cloneAsImage:function(r){if(d.Image){var p=new Image();p.onload=function(){if(r){r(new d.Image(p),q)}p=p.onload=null};var q={angle:this.get("angle"),flipX:this.get("flipX"),flipY:this.get("flipY")};this.set("angle",0).set("flipX",false).set("flipY",false);this.toDataURL(function(i){p.src=i})}return this},toDataURL:function(r){var p=d.document.createElement("canvas");if(!p.getContext&&typeof G_vmlCanvasManager!=="undefined"){G_vmlCanvasManager.initElement(p)}p.width=this.getBoundingRectWidth();p.height=this.getBoundingRectHeight();d.util.wrapElement(p,"div");var i=new d.Canvas(p);i.backgroundColor="transparent";i.renderAll();if(this.constructor.async){this.clone(q)}else{q(this.clone())}function q(t){t.left=p.width/2;t.top=p.height/2;t.setActive(false);i.add(t);var s=i.toDataURL("png");i.dispose();i=t=null;r&&r(s)}},hasStateChanged:function(){return this.stateProperties.some(function(i){return this[i]!==this.originalState[i]},this)},saveState:function(){this.stateProperties.forEach(function(i){this.originalState[i]=this.get(i)},this);return this},setupState:function(){this.originalState={};this.saveState()},intersectsWithRect:function(q,s){var v=this.oCoords,i=new d.Point(v.tl.x,v.tl.y),r=new d.Point(v.tr.x,v.tr.y),u=new d.Point(v.bl.x,v.bl.y),p=new d.Point(v.br.x,v.br.y);var t=d.Intersection.intersectPolygonRectangle([i,r,p,u],q,s);return(t.status==="Intersection")},intersectsWithObject:function(i){function p(t){return{tl:new d.Point(t.tl.x,t.tl.y),tr:new d.Point(t.tr.x,t.tr.y),bl:new d.Point(t.bl.x,t.bl.y),br:new d.Point(t.br.x,t.br.y)}}var q=p(this.oCoords),s=p(i.oCoords);var r=d.Intersection.intersectPolygonPolygon([q.tl,q.tr,q.br,q.bl],[s.tl,s.tr,s.br,s.bl]);return(r.status==="Intersection")},isContainedWithinObject:function(i){return this.isContainedWithinRect(i.oCoords.tl,i.oCoords.br)},isContainedWithinRect:function(p,r){var t=this.oCoords,i=new d.Point(t.tl.x,t.tl.y),q=new d.Point(t.tr.x,t.tr.y),s=new d.Point(t.bl.x,t.bl.y);return i.x>p.x&&q.xp.y&&s.y=u)&&(r.d.y>=u)){continue}if((r.o.x===r.d.x)&&(r.o.x>=v)){w=r.o.x;t=u}else{y=0;x=(r.d.y-r.o.y)/(r.d.x-r.o.x);q=u-y*v;p=r.o.y-x*r.o.x;w=-(q-p)/(y-x);t=q+y*w}if(w>=v){s+=1}if(s===2){break}}return s},_getImageLines:function(i){return{topline:{o:i.tl,d:i.tr},rightline:{o:i.tr,d:i.br},bottomline:{o:i.br,d:i.bl},leftline:{o:i.bl,d:i.tl}}},_setCornerCoords:function(){var t=this.oCoords,p=b(45-this.getAngle()),r=Math.sqrt(2*Math.pow(this.cornersize,2))/2,i=r*Math.cos(p),q=r*Math.sin(p),u=Math.sin(this._theta),s=Math.cos(this._theta);t.tl.corner={tl:{x:t.tl.x-q,y:t.tl.y-i},tr:{x:t.tl.x+i,y:t.tl.y-q},bl:{x:t.tl.x-i,y:t.tl.y+q},br:{x:t.tl.x+q,y:t.tl.y+i}};t.tr.corner={tl:{x:t.tr.x-q,y:t.tr.y-i},tr:{x:t.tr.x+i,y:t.tr.y-q},br:{x:t.tr.x+q,y:t.tr.y+i},bl:{x:t.tr.x-i,y:t.tr.y+q}};t.bl.corner={tl:{x:t.bl.x-q,y:t.bl.y-i},bl:{x:t.bl.x-i,y:t.bl.y+q},br:{x:t.bl.x+q,y:t.bl.y+i},tr:{x:t.bl.x+i,y:t.bl.y-q}};t.br.corner={tr:{x:t.br.x+i,y:t.br.y-q},bl:{x:t.br.x-i,y:t.br.y+q},br:{x:t.br.x+q,y:t.br.y+i},tl:{x:t.br.x-q,y:t.br.y-i}};t.ml.corner={tl:{x:t.ml.x-q,y:t.ml.y-i},tr:{x:t.ml.x+i,y:t.ml.y-q},bl:{x:t.ml.x-i,y:t.ml.y+q},br:{x:t.ml.x+q,y:t.ml.y+i}};t.mt.corner={tl:{x:t.mt.x-q,y:t.mt.y-i},tr:{x:t.mt.x+i,y:t.mt.y-q},bl:{x:t.mt.x-i,y:t.mt.y+q},br:{x:t.mt.x+q,y:t.mt.y+i}};t.mr.corner={tl:{x:t.mr.x-q,y:t.mr.y-i},tr:{x:t.mr.x+i,y:t.mr.y-q},bl:{x:t.mr.x-i,y:t.mr.y+q},br:{x:t.mr.x+q,y:t.mr.y+i}};t.mb.corner={tl:{x:t.mb.x-q,y:t.mb.y-i},tr:{x:t.mb.x+i,y:t.mb.y-q},bl:{x:t.mb.x-i,y:t.mb.y+q},br:{x:t.mb.x+q,y:t.mb.y+i}};t.mtr.corner={tl:{x:t.mtr.x-q+(u*this.rotatingPointOffset),y:t.mtr.y-i-(s*this.rotatingPointOffset)},tr:{x:t.mtr.x+i+(u*this.rotatingPointOffset),y:t.mtr.y-q-(s*this.rotatingPointOffset)},bl:{x:t.mtr.x-i+(u*this.rotatingPointOffset),y:t.mtr.y+q-(s*this.rotatingPointOffset)},br:{x:t.mtr.x+q+(u*this.rotatingPointOffset),y:t.mtr.y+i-(s*this.rotatingPointOffset)}}},toGrayscale:function(){var i=this.get("fill");if(i){this.set("overlayFill",new d.Color(i).toGrayscale().toRgb())}return this},complexity:function(){return 0},toJSON:function(){return this.toObject()},setGradientFill:function(i){this.set("fill",d.Gradient.forObject(this,i))},animate:function(){if(arguments[0]&&typeof arguments[0]==="object"){for(var i in arguments[0]){this._animate(i,arguments[0][i],arguments[1])}}else{this._animate.apply(this,arguments)}return this},_animate:function(p,r,i){var q=this;i||(i={});if(!("from" in i)){i.from=this.get(p)}if(/[+\-]/.test((r+"").charAt(0))){r=this.get(p)+parseFloat(r)}d.util.animate({startValue:i.from,endValue:r,byValue:i.by,easing:i.easing,duration:i.duration,onChange:function(s){q.set(p,s);i.onChange&&i.onChange()},onComplete:function(){q.setCoords();i.onComplete&&i.onComplete()}})},centerH:function(){this.canvas.centerObjectH(this);return this},centerV:function(){this.canvas.centerObjectV(this);return this},center:function(){return this.centerH().centerV()},remove:function(){return this.canvas.remove(this)},sendToBack:function(){this.canvas.sendToBack(this);return this},bringToFront:function(){this.canvas.bringToFront(this);return this},sendBackwards:function(){this.canvas.sendBackwards(this);return this},bringForward:function(){this.canvas.bringForward(this);return this}});d.Object.prototype.rotate=d.Object.prototype.setAngle;var j=d.Object.prototype;for(var g=j.stateProperties.length;g--;){var h=j.stateProperties[g],e=h.charAt(0).toUpperCase()+h.slice(1),f="set"+e,m="get"+e;if(!j[m]){j[m]=(function(i){return new Function('return this.get("'+i+'")')})(h)}if(!j[f]){j[f]=(function(i){return new Function("value",'return this.set("'+i+'", value)')})(h)}}l(d.Object.prototype,d.Observable);l(d.Object,{NUM_FRACTION_DIGITS:2,MIN_SCALE_LIMIT:0.1})})(typeof exports!=="undefined"?exports:this);(function(b){var c=b.fabric||(b.fabric={}),d=c.util.object.extend,a={x1:1,x2:1,y1:1,y2:1};if(c.Line){c.warn("fabric.Line is already defined");return}c.Line=c.util.createClass(c.Object,{type:"line",initialize:function(f,e){if(!f){f=[0,0,0,0]}this.callSuper("initialize",e);this.set("x1",f[0]);this.set("y1",f[1]);this.set("x2",f[2]);this.set("y2",f[3]);this._setWidthHeight(e)},_setWidthHeight:function(e){e||(e={});this.set("width",(this.x2-this.x1)||1);this.set("height",(this.y2-this.y1)||1);this.set("left","left" in e?e.left:(this.x1+this.width/2));this.set("top","top" in e?e.top:(this.y1+this.height/2))},_set:function(e,f){this[e]=f;if(e in a){this._setWidthHeight()}return this},_render:function(e){e.beginPath();if(this.group){e.translate(-this.group.width/2+this.left,-this.group.height/2+this.top)}e.moveTo(this.width===1?0:(-this.width/2),this.height===1?0:(-this.height/2));e.lineTo(this.width===1?0:(this.width/2),this.height===1?0:(this.height/2));e.lineWidth=this.strokeWidth;var f=e.strokeStyle;e.strokeStyle=e.fillStyle;e.stroke();e.strokeStyle=f},complexity:function(){return 1},toObject:function(){return d(this.callSuper("toObject"),{x1:this.get("x1"),y1:this.get("y1"),x2:this.get("x2"),y2:this.get("y2")})},toSVG:function(){return[""].join("")}});c.Line.ATTRIBUTE_NAMES="x1 y1 x2 y2 stroke stroke-width transform".split(" ");c.Line.fromElement=function(f,e){var h=c.parseAttributes(f,c.Line.ATTRIBUTE_NAMES);var g=[h.x1||0,h.y1||0,h.x2||0,h.y2||0];return new c.Line(g,d(h,e))};c.Line.fromObject=function(e){var f=[e.x1,e.y1,e.x2,e.y2];return new c.Line(f,e)}})(typeof exports!=="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={}),d=Math.PI*2,e=b.util.object.extend;if(b.Circle){b.warn("fabric.Circle is already defined.");return}b.Circle=b.util.createClass(b.Object,{type:"circle",initialize:function(f){f=f||{};this.set("radius",f.radius||0);this.callSuper("initialize",f);var g=this.get("radius")*2;this.set("width",g).set("height",g)},toObject:function(){return e(this.callSuper("toObject"),{radius:this.get("radius")})},toSVG:function(){return('')},_render:function(f,g){f.beginPath();f.globalAlpha*=this.opacity;f.arc(g?this.left:0,g?this.top:0,this.radius,0,d,false);f.closePath();if(this.fill){f.fill()}if(this.stroke){f.stroke()}},getRadiusX:function(){return this.get("radius")*this.get("scaleX")},getRadiusY:function(){return this.get("radius")*this.get("scaleY")},setRadius:function(f){this.radius=f;this.set("width",f*2).set("height",f*2)},complexity:function(){return 1}});b.Circle.ATTRIBUTE_NAMES="cx cy r fill fill-opacity opacity stroke stroke-width transform".split(" ");b.Circle.fromElement=function(g,f){f||(f={});var h=b.parseAttributes(g,b.Circle.ATTRIBUTE_NAMES);if(!c(h)){throw new Error("value of `r` attribute is required and can not be negative")}if("left" in h){h.left-=(f.width/2)||0}if("top" in h){h.top-=(f.height/2)||0}return new b.Circle(e(h,f))};function c(f){return(("radius" in f)&&(f.radius>0))}b.Circle.fromObject=function(f){return new b.Circle(f)}})(typeof exports!=="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={});if(b.Triangle){b.warn("fabric.Triangle is already defined");return}b.Triangle=b.util.createClass(b.Object,{type:"triangle",initialize:function(c){c=c||{};this.callSuper("initialize",c);this.set("width",c.width||100).set("height",c.height||100)},_render:function(c){var d=this.width/2,e=this.height/2;c.beginPath();c.moveTo(-d,e);c.lineTo(0,-e);c.lineTo(d,e);c.closePath();if(this.fill){c.fill()}if(this.stroke){c.stroke()}},complexity:function(){return 1},toSVG:function(){var c=this.width/2,d=this.height/2;var e=[-c+" "+d,"0 "+-d,c+" "+d].join(",");return''}});b.Triangle.fromObject=function(c){return new b.Triangle(c)}})(typeof exports!=="undefined"?exports:this);(function(a){var b=a.fabric||(a.fabric={}),c=Math.PI*2,d=b.util.object.extend;if(b.Ellipse){b.warn("fabric.Ellipse is already defined.");return}b.Ellipse=b.util.createClass(b.Object,{type:"ellipse",initialize:function(e){e=e||{};this.callSuper("initialize",e);this.set("rx",e.rx||0);this.set("ry",e.ry||0);this.set("width",this.get("rx")*2);this.set("height",this.get("ry")*2)},toObject:function(){return d(this.callSuper("toObject"),{rx:this.get("rx"),ry:this.get("ry")})},toSVG:function(){return[""].join("")},render:function(e,f){if(this.rx===0||this.ry===0){return}return this.callSuper("render",e,f)},_render:function(e,f){e.beginPath();e.save();e.globalAlpha*=this.opacity;if(this.transformMatrix&&this.group){e.translate(this.cx,this.cy)}e.transform(1,0,0,this.ry/this.rx,0,0);e.arc(f?this.left:0,f?this.top:0,this.rx,0,c,false);if(this.stroke){e.stroke()}if(this.fill){e.fill()}e.restore()},complexity:function(){return 1}});b.Ellipse.ATTRIBUTE_NAMES="cx cy rx ry fill fill-opacity opacity stroke stroke-width transform".split(" ");b.Ellipse.fromElement=function(g,f){f||(f={});var i=b.parseAttributes(g,b.Ellipse.ATTRIBUTE_NAMES);var e=i.left;var j=i.top;if("left" in i){i.left-=(f.width/2)||0}if("top" in i){i.top-=(f.height/2)||0}var h=new b.Ellipse(d(i,f));h.cx=e||0;h.cy=j||0;return h};b.Ellipse.fromObject=function(e){return new b.Ellipse(e)}})(typeof exports!=="undefined"?exports:this);(function(b){var c=b.fabric||(b.fabric={});if(c.Rect){console.warn("fabric.Rect is already defined");return}c.Rect=c.util.createClass(c.Object,{type:"rect",rx:0,ry:0,initialize:function(d){this._initStateProperties();this.callSuper("initialize",d);this._initRxRy()},_initStateProperties:function(){this.stateProperties=this.stateProperties.concat(["rx","ry"])},_initRxRy:function(){if(this.rx&&!this.ry){this.ry=this.rx}else{if(this.ry&&!this.rx){this.rx=this.ry}}},_render:function(f){var j=this.rx||0,i=this.ry||0,d=-this.width/2,k=-this.height/2,e=this.width,g=this.height;f.beginPath();f.globalAlpha*=this.opacity;if(this.transformMatrix&&this.group){f.translate(this.width/2+this.x,this.height/2+this.y)}if(!this.transformMatrix&&this.group){f.translate(-this.group.width/2+this.width/2+this.x,-this.group.height/2+this.height/2+this.y)}f.moveTo(d+j,k);f.lineTo(d+e-j,k);f.quadraticCurveTo(d+e,k,d+e,k+i,d+e,k+i);f.lineTo(d+e,k+g-i);f.quadraticCurveTo(d+e,k+g,d+e-j,k+g,d+e-j,k+g);f.lineTo(d+j,k+g);f.quadraticCurveTo(d,k+g,d,k+g-i,d,k+g-i);f.lineTo(d,k+i);f.quadraticCurveTo(d,k,d+j,k,d+j,k);f.closePath();if(this.fill){f.fill()}if(this.strokeDashArray){this._renderDashedStroke(f)}else{if(this.stroke){f.stroke()}}},_normalizeLeftTopProperties:function(d){if(d.left){this.set("left",d.left+this.getWidth()/2)}this.set("x",d.left||0);if(d.top){this.set("top",d.top+this.getHeight()/2)}this.set("y",d.top||0);return this},complexity:function(){return 1},toObject:function(){return c.util.object.extend(this.callSuper("toObject"),{rx:this.get("rx")||0,ry:this.get("ry")||0})},toSVG:function(){return''}});c.Rect.ATTRIBUTE_NAMES="x y width height rx ry fill fill-opacity opacity stroke stroke-width transform".split(" ");function a(d){d.left=d.left||0;d.top=d.top||0;return d}c.Rect.fromElement=function(e,d){if(!e){return null}var g=c.parseAttributes(e,c.Rect.ATTRIBUTE_NAMES);g=a(g);var f=new c.Rect(c.util.object.extend((d?c.util.object.clone(d):{}),g));f._normalizeLeftTopProperties(g);return f};c.Rect.fromObject=function(d){return new c.Rect(d)}})(typeof exports!=="undefined"?exports:this);(function(b){var c=b.fabric||(b.fabric={}),a=c.util.toFixed;if(c.Polyline){c.warn("fabric.Polyline is already defined");return}c.Polyline=c.util.createClass(c.Object,{type:"polyline",initialize:function(e,d){d=d||{};this.set("points",e);this.callSuper("initialize",d);this._calcDimensions()},_calcDimensions:function(){return c.Polygon.prototype._calcDimensions.call(this)},toObject:function(){return c.Polygon.prototype.toObject.call(this)},toSVG:function(){var f=[];for(var e=0,d=this.points.length;e"].join("")},_render:function(f){var e;f.beginPath();f.moveTo(this.points[0].x,this.points[0].y);for(var g=0,d=this.points.length;g"].join("")},_render:function(j){var h;j.beginPath();j.moveTo(this.points[0].x,this.points[0].y);for(var k=0,g=this.points.length;k1){E=Math.sqrt(E);O*=E;N*=E}var R=aa/O;var Q=W/O;var D=(-W)/N;var C=(aa)/N;var H=R*M+Q*L;var q=D*M+C*L;var F=R*T+Q*S;var ab=D*T+C*S;var Z=(F-H)*(F-H)+(ab-q)*(ab-q);var U=1/Z-0.25;if(U<0){U=0}var w=Math.sqrt(U);if(P===J){w=-w}var V=0.5*(H+F)-w*(ab-q);var K=0.5*(q+ab)+w*(F-H);var v=Math.atan2(q-K,H-V);var u=Math.atan2(ab-K,F-V);var Y=u-v;if(Y<0&&P===1){Y+=2*Math.PI}else{if(Y>0&&P===0){Y-=2*Math.PI}}var B=Math.ceil(Math.abs(Y/(Math.PI*0.5+0.001)));var I=[];for(var X=0;X"},toObject:function(){var q=g(this.callSuper("toObject"),{path:this.path});if(this.sourcePath){q.sourcePath=this.sourcePath}if(this.transformMatrix){q.transformMatrix=this.transformMatrix}return q},toDatalessObject:function(){var q=this.toObject();if(this.sourcePath){q.path=this.sourcePath}delete q.sourcePath;return q},toSVG:function(){var t=[];for(var r=0,q=this.path.length;r',"',""].join("")},complexity:function(){return this.path.length},_parsePath:function(){var C=[],z,v,y;for(var u=0,q,w=this.path.length;uB){for(var r=1,x=q.length;r"];for(var l=0,j=m.length;l");return k.join("")},toString:function(){return"#"},isSameColor:function(){var i=this.getObjects()[0].get("fill");return this.getObjects().every(function(j){return j.get("fill")===i})},complexity:function(){return this.paths.reduce(function(i,j){return i+((j&&j.complexity)?j.complexity():0)},0)},toGrayscale:function(){var j=this.paths.length;while(j--){this.paths[j].toGrayscale()}return this},getObjects:function(){return this.paths}});function d(m){for(var l=0,j=m.length;l"},getObjects:function(){return this.objects},addWithUpdate:function(h){this._restoreObjectsState();this.objects.push(h);this._calcBounds();this._updateObjectsCoords();return this},removeWithUpdate:function(h){this._restoreObjectsState();f(this.objects,h);h.setActive(false);this._calcBounds();this._updateObjectsCoords();return this},add:function(h){this.objects.push(h);return this},remove:function(h){f(this.objects,h);return this},size:function(){return this.getObjects().length},_set:function(j,k){if(j==="fill"||j==="opacity"){var h=this.objects.length;this[j]=k;while(h--){this.objects[h].set(j,k)}}else{this[j]=k}},contains:function(h){return this.objects.indexOf(h)>-1},toObject:function(){return g(this.callSuper("toObject"),{objects:b(this.objects,"toObject")})},render:function(j,o){j.save();this.transform(j);var n=Math.max(this.scaleX,this.scaleY);for(var l=0,h=this.objects.length;li.x&&j-hi.y},toGrayscale:function(){var h=this.objects.length;while(h--){this.objects[h].toGrayscale()}},toSVG:function(){var k=[];for(var j=0,h=this.objects.length;j'+k.join("")+"")}});e.Group.fromObject=function(h,i){e.util.enlivenObjects(h.objects,function(j){delete h.objects;i&&i(new e.Group(j,h))})};e.Group.async=true})(typeof exports!=="undefined"?exports:this);(function(a){var b=fabric.util.object.extend;if(!a.fabric){a.fabric={}}if(a.fabric.Image){fabric.warn("fabric.Image is already defined.");return}if(!fabric.Object){fabric.warn("fabric.Object is required for fabric.Image initialization");return}fabric.Image=fabric.util.createClass(fabric.Object,{active:false,bordervisibility:false,cornervisibility:false,type:"image",initialize:function(d,c){c||(c={});this.callSuper("initialize",c);this._initElement(d);this._originalImage=this.getElement();this._initConfig(c);this.filters=[];if(c.filters){this.filters=c.filters;this.applyFilters()}},getElement:function(){return this._element},setElement:function(c){this._element=c;this._initConfig();return this},getOriginalSize:function(){var c=this.getElement();return{width:c.width,height:c.height}},setBorderVisibility:function(){this._resetWidthHeight();this._adjustWidthHeightToBorders();this.setCoords()},setCornersVisibility:function(c){this.cornervisibility=!!c},render:function(d,e){d.save();var c=this.transformMatrix;this._resetWidthHeight();if(this.group){d.translate(-this.group.width/2+this.width/2,-this.group.height/2+this.height/2)}if(c){d.transform(c[0],c[1],c[2],c[3],c[4],c[5])}if(!e){this.transform(d)}this._render(d);if(this.active&&!e){this.drawBorders(d);this.hideCorners||this.drawCorners(d)}d.restore()},toObject:function(){return b(this.callSuper("toObject"),{src:this._originalImage.src||this._originalImage._src,filters:this.filters.concat()})},toSVG:function(){return''},getSrc:function(){return this.getElement().src||this.getElement()._src},toString:function(){return'#'},clone:function(c){this.constructor.fromObject(this.toObject(),c)},applyFilters:function(i){if(this.filters.length===0){this.setElement(this._originalImage);i&&i();return}var c=typeof Buffer!=="undefined"&&typeof window==="undefined",g=this._originalImage,e=fabric.document.createElement("canvas"),f=c?new (require("canvas").Image)():fabric.document.createElement("img"),h=this;if(!e.getContext&&typeof G_vmlCanvasManager!=="undefined"){G_vmlCanvasManager.initElement(e)}e.width=g.width;e.height=g.height;e.getContext("2d").drawImage(g,0,0,g.width,g.height);this.filters.forEach(function(j){j&&j.applyTo(e)});f.onload=function(){h._element=f;i&&i();f.onload=e=g=null};f.width=g.width;f.height=g.height;if(c){var d=e.toDataURL("image/png").replace(/data:image\/png;base64,/,"");f.src=new Buffer(d,"base64");h._element=f;i&&i()}else{f.src=e.toDataURL("image/png")}return this},_render:function(c){c.drawImage(this.getElement(),-this.width/2,-this.height/2,this.width,this.height)},_adjustWidthHeightToBorders:function(c){if(c){this.currentBorder=this.borderwidth;this.width+=(2*this.currentBorder);this.height+=(2*this.currentBorder)}else{this.currentBorder=0}},_resetWidthHeight:function(){var c=this.getElement();this.set("width",c.width);this.set("height",c.height)},_initElement:function(c){this.setElement(fabric.util.getById(c));fabric.util.addClass(this.getElement(),fabric.Image.CSS_CANVAS)},_initConfig:function(c){c||(c={});this.setOptions(c);this._setBorder();this._setWidthHeight(c)},_initFilters:function(c){if(c.filters&&c.filters.length){this.filters=c.filters.map(function(d){return d&&fabric.Image.filters[d.type].fromObject(d)})}},_setBorder:function(){if(this.bordervisibility){this.currentBorder=this.borderwidth}else{this.currentBorder=0}},_setWidthHeight:function(c){var d=2*this.currentBorder;this.width="width" in c?c.width:((this.getElement().width||0)+d);this.height="height" in c?c.height:((this.getElement().height||0)+d)},complexity:function(){return 1}});fabric.Image.CSS_CANVAS="canvas-img";fabric.Image.prototype.getSvgSrc=fabric.Image.prototype.getSrc;fabric.Image.fromObject=function(d,f){var c=fabric.document.createElement("img"),e=d.src;if(d.width){c.width=d.width}if(d.height){c.height=d.height}c.onload=function(){fabric.Image.prototype._initFilters.call(d,d);var g=new fabric.Image(c,d);f&&f(g);c=c.onload=null};c.src=e};fabric.Image.fromURL=function(d,f,e){var c=fabric.document.createElement("img");c.onload=function(){if(f){f(new fabric.Image(c,e))}c=c.onload=null};c.src=d};fabric.Image.ATTRIBUTE_NAMES="x y width height fill fill-opacity opacity stroke stroke-width transform xlink:href".split(" ");fabric.Image.fromElement=function(d,f,c){c||(c={});var e=fabric.parseAttributes(d,fabric.Image.ATTRIBUTE_NAMES);fabric.Image.fromURL(e["xlink:href"],f,b(e,c))};fabric.Image.async=true})(typeof exports!=="undefined"?exports:this);fabric.util.object.extend(fabric.Object.prototype,{_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},straighten:function(){var a=this._getAngleValueForStraighten();this.setAngle(a);return this},fxStraighten:function(b){b=b||{};var c=function(){},d=b.onComplete||c,a=b.onChange||c,e=this;fabric.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(f){e.setAngle(f);a()},onComplete:function(){e.setCoords();d()},onStart:function(){e.setActive(false)}});return this}});fabric.util.object.extend(fabric.StaticCanvas.prototype,{straightenObject:function(a){a.straighten();this.renderAll();return this},fxStraightenObject:function(a){a.fxStraighten({onChange:this.renderAll.bind(this)});return this}});fabric.Image.filters={};fabric.Image.filters.Grayscale=fabric.util.createClass({type:"Grayscale",applyTo:function(d){var c=d.getContext("2d"),a=c.getImageData(0,0,d.width,d.height),h=a.data,e=a.width,l=a.height,k,b,g,f;for(g=0;gh&&m>h&&o>h&&p(a-m)0){h[j]=k;h[j+1]=c;h[j+2]=g}}d.putImageData(b,0,0)},toJSON:function(){return{type:this.type,color:this.color}}});fabric.Image.filters.Tint.fromObject=function(a){return new fabric.Image.filters.Tint(a)};(function(b){var c=b.fabric||(b.fabric={}),e=c.util.object.extend,d=c.util.object.clone,a=c.util.toFixed;if(c.Text){c.warn("fabric.Text is already defined");return}if(!c.Object){c.warn("fabric.Text requires fabric.Object");return}c.Text=c.util.createClass(c.Object,{fontSize:40,fontWeight:100,fontFamily:"Times New Roman",textDecoration:"",textShadow:"",textAlign:"left",fontStyle:"",lineHeight:1.3,strokeStyle:"",strokeWidth:1,backgroundColor:"",path:null,type:"text",useNative:true,initialize:function(g,f){this._initStateProperties();this.text=g;this.setOptions(f||{});this._theta=this.angle*Math.PI/180;this._initDimensions();this.setCoords()},_initDimensions:function(){var f=c.document.createElement("canvas");if(!f.getContext&&typeof G_vmlCanvasManager!=="undefined"){G_vmlCanvasManager.initElement(f)}this._render(f.getContext("2d"))},_initStateProperties:function(){this.stateProperties=this.stateProperties.concat();this.stateProperties.push("fontFamily","fontWeight","fontSize","path","text","textDecoration","textShadow","textAlign","fontStyle","lineHeight","strokeStyle","strokeWidth","backgroundColor","useNative");c.util.removeFromArray(this.stateProperties,"width")},toString:function(){return"#'},_render:function(f){if(typeof Cufon==="undefined"||this.useNative===true){this._renderViaNative(f)}else{this._renderViaCufon(f)}},_renderViaCufon:function(f){var h=Cufon.textOptions||(Cufon.textOptions={});h.left=this.left;h.top=this.top;h.context=f;h.color=this.fill;var g=this._initDummyElementForCufon();this.transform(f);Cufon.replaceElement(g,{engine:"canvas",separate:"none",fontFamily:this.fontFamily,fontWeight:this.fontWeight,textDecoration:this.textDecoration,textShadow:this.textShadow,textAlign:this.textAlign,fontStyle:this.fontStyle,lineHeight:this.lineHeight,strokeStyle:this.strokeStyle,strokeWidth:this.strokeWidth,backgroundColor:this.backgroundColor});this.width=h.width;this.height=h.height;this._totalLineHeight=h.totalLineHeight;this._fontAscent=h.fontAscent;this._boundaries=h.boundaries;this._shadowOffsets=h.shadowOffsets;this._shadows=h.shadows||[];g=null;this.setCoords()},_renderViaNative:function(f){this.transform(f);this._setTextStyles(f);var g=this.text.split(/\r?\n/);this.width=this._getTextWidth(f,g);this.height=this._getTextHeight(f,g);this._renderTextBackground(f,g);if(this.textAlign!=="left"){f.save();f.translate(this.textAlign==="center"?(this.width/2):this.width,0)}this._setTextShadow(f);this._renderTextFill(f,g);this.textShadow&&f.restore();this._renderTextStroke(f,g);if(this.textAlign!=="left"){f.restore()}this._renderTextDecoration(f,g);this._setBoundaries(f,g);this._totalLineHeight=0;this.setCoords()},_setBoundaries:function(h,k){this._boundaries=[];for(var j=0,g=k.length;jk){k=l}}return k},_setTextShadow:function(f){if(this.textShadow){var j=/\s+(-?\d+)(?:px)?\s+(-?\d+)(?:px)?\s+(\d+)(?:px)?\s*/;var g=this.textShadow;var i=j.exec(this.textShadow);var h=g.replace(j,"");f.save();f.shadowColor=h;f.shadowOffsetX=parseInt(i[1],10);f.shadowOffsetY=parseInt(i[2],10);f.shadowBlur=parseInt(i[3],10);this._shadows=[{blur:f.shadowBlur,color:f.shadowColor,offX:f.shadowOffsetX,offY:f.shadowOffsetY}];this._shadowOffsets=[[parseInt(f.shadowOffsetX,10),parseInt(f.shadowOffsetY,10)]]}},_renderTextFill:function(g,j){this._boundaries=[];for(var h=0,f=j.length;h-1){f(this.fontSize)}if(this.textDecoration.indexOf("line-through")>-1){f(this.fontSize/2)}if(this.textDecoration.indexOf("overline")>-1){f(0)}},_getFontDeclaration:function(){return[this.fontStyle,this.fontWeight,this.fontSize+"px",(c.isLikelyNode?('"'+this.fontFamily+'"'):this.fontFamily)].join(" ")},_initDummyElementForCufon:function(){var g=c.document.createElement("pre"),f=c.document.createElement("div");f.appendChild(g);if(typeof G_vmlCanvasManager==="undefined"){g.innerHTML=this.text}else{g.innerText=this.text.replace(/\r?\n/gi,"\r")}g.style.fontSize=this.fontSize+"px";g.style.letterSpacing="normal";return g},render:function(f,g){f.save();this._render(f);if(!g&&this.active){this.drawBorders(f);this.hideCorners||this.drawCorners(f)}f.restore()},toObject:function(){return e(this.callSuper("toObject"),{text:this.text,fontSize:this.fontSize,fontWeight:this.fontWeight,fontFamily:this.fontFamily,fontStyle:this.fontStyle,lineHeight:this.lineHeight,textDecoration:this.textDecoration,textShadow:this.textShadow,textAlign:this.textAlign,path:this.path,strokeStyle:this.strokeStyle,strokeWidth:this.strokeWidth,backgroundColor:this.backgroundColor,useNative:this.useNative})},toSVG:function(){var i=this.text.split(/\r?\n/),j=this.useNative?this.fontSize*this.lineHeight:(-this._fontAscent-((this._fontAscent/5)*this.lineHeight)),g=-(this.width/2),f=this.useNative?this.fontSize-1:(this.height/2)-(i.length*this.fontSize)-this._totalLineHeight,h=this._getSVGTextAndBg(j,g,i),k=this._getSVGShadows(j,i);f+=(this._fontAscent?((this._fontAscent/5)*this.lineHeight):0);return['',h.textBgRects.join(""),"',k.join(""),h.textSpans.join(""),"",""].join("")},_getSVGShadows:function(h,n){var o=[],k,l,p,g,f=1;if(!this._shadows||!this._boundaries){return o}for(k=0,p=this._shadows.length;k",c.util.string.escapeXml(n[l]),"");f=1}else{f++}}}return o},_getSVGTextAndBg:function(j,h,n){var g=[],k=[],l,m,o,f=1;for(l=0,o=n.length;l",c.util.string.escapeXml(n[l]),"");f=1}else{f++}if(!this.backgroundColor||!this._boundaries){continue}k.push("')}return{textSpans:g,textBgRects:k}},_getFillAttributes:function(f){var g=f?new c.Color(f):"";if(!g||!g.getSource()||g.getAlpha()===1){return'fill="'+f+'"'}return'opacity="'+g.getAlpha()+'" fill="'+g.setAlpha(1).toRgb()+'"'},setColor:function(f){this.set("fill",f);return this},setFontsize:function(f){this.set("fontSize",f);this._initDimensions();this.setCoords();return this},getText:function(){return this.text},setText:function(f){this.set("text",f);this._initDimensions();this.setCoords();return this},_set:function(f,g){if(f==="fontFamily"&&this.path){this.path=this.path.replace(/(.*?)([^\/]*)(\.font\.js)/,"$1"+g+"$3")}this.callSuper("_set",f,g)}});c.Text.ATTRIBUTE_NAMES=("x y fill fill-opacity opacity stroke stroke-width transform font-family font-style font-weight font-size text-decoration").split(" ");c.Text.fromObject=function(f){return new c.Text(f.text,d(f))};c.Text.fromElement=function(g,f){if(!g){return null}var h=c.parseAttributes(g,c.Text.ATTRIBUTE_NAMES);f=c.util.object.extend((f?c.util.object.clone(f):{}),h);var i=new c.Text(g.textContent,f);return i}})(typeof exports!=="undefined"?exports:this);(function(){if(typeof document!=="undefined"&&typeof window!=="undefined"){return}var DOMParser=new require("xmldom").DOMParser,URL=require("url"),HTTP=require("http"),Canvas=require("canvas"),Image=require("canvas").Image;function request(url,encoding,callback){var oURL=URL.parse(url),client=HTTP.createClient(oURL.port,oURL.hostname),req=client.request("GET",oURL.pathname,{host:oURL.hostname});client.addListener("error",function(err){if(err.errno===process.ECONNREFUSED){fabric.log("ECONNREFUSED: connection refused to "+client.host+":"+client.port)}else{fabric.log(err.message)}});req.end();req.on("response",function(response){var body="";if(encoding){response.setEncoding(encoding)}response.on("end",function(){callback(body)});response.on("data",function(chunk){if(response.statusCode===200){body+=chunk}})})}fabric.util.loadImage=function(url,callback){request(url,"binary",function(body){var img=new Image();img.src=new Buffer(body,"binary");img._src=url;callback(img)})};fabric.loadSVGFromURL=function(url,callback){url=url.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();request(url,"",function(body){fabric.loadSVGFromString(body,callback)})};fabric.loadSVGFromString=function(string,callback){var doc=new DOMParser().parseFromString(string);fabric.parseSVGDocument(doc.documentElement,function(results,options){callback(results,options)})};fabric.util.getScript=function(url,callback){request(url,"",function(body){eval(body);callback&&callback()})};fabric.Image.fromObject=function(object,callback){fabric.util.loadImage(object.src,function(img){var oImg=new fabric.Image(img);oImg._initConfig(object);oImg._initFilters(object);callback(oImg)})};fabric.createCanvasForNode=function(width,height){var canvasEl=fabric.document.createElement("canvas"),nodeCanvas=new Canvas(width||600,height||600);canvasEl.style={};canvasEl.width=nodeCanvas.width;canvasEl.height=nodeCanvas.height;var FabricCanvas=fabric.Canvas||fabric.StaticCanvas;var fabricCanvas=new FabricCanvas(canvasEl);fabricCanvas.contextContainer=nodeCanvas.getContext("2d");fabricCanvas.nodeCanvas=nodeCanvas;return fabricCanvas};fabric.StaticCanvas.prototype.createPNGStream=function(){return this.nodeCanvas.createPNGStream()};var origSetWidth=fabric.StaticCanvas.prototype.setWidth;fabric.StaticCanvas.prototype.setWidth=function(width){origSetWidth.call(this);this.nodeCanvas.width=width;return this};if(fabric.Canvas){fabric.Canvas.prototype.setWidth=fabric.StaticCanvas.prototype.setWidth}var origSetHeight=fabric.StaticCanvas.prototype.setHeight;fabric.StaticCanvas.prototype.setHeight=function(height){origSetHeight.call(this);this.nodeCanvas.height=height;return this};if(fabric.Canvas){fabric.Canvas.prototype.setHeight=fabric.StaticCanvas.prototype.setHeight}})(); \ No newline at end of file diff --git a/dist/all.min.js.gz b/dist/all.min.js.gz index 165319fc..a46582ab 100644 Binary files a/dist/all.min.js.gz and b/dist/all.min.js.gz differ diff --git a/package.json b/package.json index 02d26a79..c8d475b0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fabric", "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.", - "version": "0.9.13", + "version": "0.9.14", "author": "Juriy Zaytsev ", "keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"], "repository": "git://github.com/kangax/fabric.js", @@ -19,7 +19,8 @@ "xmldom": ">=0.1.7" }, "devDependencies": { - "qunit": "0.5.x" + "qunit": "0.5.x", + "jshint": "0.9.x" }, "engines": { "node": ">=0.4.0 && <0.9.0" }, "main": "./dist/all.js" diff --git a/src/canvas.class.js b/src/canvas.class.js index 7c324083..ca9ca152 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -46,7 +46,7 @@ function ProtoProxy(){ } ProtoProxy.prototype = fabric.StaticCanvas.prototype; - fabric.Canvas.prototype = new ProtoProxy; + fabric.Canvas.prototype = new ProtoProxy(); var InteractiveMethods = /** @scope fabric.Canvas.prototype */ { @@ -189,7 +189,7 @@ _this.__onMouseMove(e); }; - this._onResize = function (e) { + this._onResize = function () { _this.calcOffset(); }; @@ -216,6 +216,8 @@ */ __onMouseUp: function (e) { + var target; + if (this.isDrawingMode && this._isCurrentlyDrawing) { this._finalizeDrawingPath(); this.fire('mouse:up', { e: e }); @@ -224,9 +226,9 @@ if (this._currentTransform) { - var transform = this._currentTransform, - target = transform.target; + var transform = this._currentTransform; + target = transform.target; if (target._scaling) { target._scaling = false; } @@ -273,7 +275,7 @@ }, 50); this.fire('mouse:up', { target: target, e: e }); - target && target.fire('mouseup', { e: e }) + target && target.fire('mouseup', { e: e }); }, /** @@ -288,7 +290,7 @@ __onMouseDown: function (e) { // accept only left clicks - var isLeftClick = 'which' in e ? e.which == 1 : e.button == 1; + var isLeftClick = 'which' in e ? e.which === 1 : e.button === 1; if (!isLeftClick && !fabric.isTouchSupported) return; if (this.isDrawingMode) { @@ -324,7 +326,7 @@ // rotate and scale will happen at the same time this.stateful && target.saveState(); - if (corner = target._findTargetCorner(e, this._offset)) { + if ((corner = target._findTargetCorner(e, this._offset))) { this.onBeforeScaleRotate(target); } @@ -360,6 +362,8 @@ */ __onMouseMove: function (e) { + var target; + if (this.isDrawingMode) { if (this._isCurrentlyDrawing) { this._captureDrawingPath(e); @@ -368,11 +372,12 @@ return; } - var groupSelector = this._groupSelector; + var groupSelector = this._groupSelector, pointer; // We initially clicked in an empty area, so we draw a box for multiple selection. if (groupSelector !== null) { - var pointer = getPointer(e); + pointer = getPointer(e); + groupSelector.left = pointer.x - this._offset.left - groupSelector.ex; groupSelector.top = pointer.y - this._offset.top - groupSelector.ey; this.renderTop(); @@ -386,7 +391,7 @@ // what part of the pictures we are hovering to change the caret symbol. // We won't do that while dragging or rotating in order to improve the // performance. - var target = this.findTarget(e); + target = this.findTarget(e); if (!target) { // image/text was hovered-out from, we remove its borders @@ -408,8 +413,9 @@ } else { // object is being transformed (scaled/rotated/moved/etc.) - var pointer = getPointer(e), - x = pointer.x, + pointer = getPointer(e); + + var x = pointer.x, y = pointer.y; this._currentTransform.target.isMoving = true; @@ -596,7 +602,7 @@ corner, pointer = getPointer(e); - if (corner = target._findTargetCorner(e, this._offset)) { + if ((corner = target._findTargetCorner(e, this._offset))) { action = (corner === 'ml' || corner === 'mr') ? 'scaleX' : (corner === 'mt' || corner === 'mb') @@ -726,17 +732,14 @@ minY = utilMin(this._freeDrawingYPoints), maxX = utilMax(this._freeDrawingXPoints), maxY = utilMax(this._freeDrawingYPoints), - ctx = this.contextTop, path = [ ], - xPoint, - yPoint, xPoints = this._freeDrawingXPoints, yPoints = this._freeDrawingYPoints; path.push('M ', xPoints[0] - minX, ' ', yPoints[0] - minY, ' '); - for (var i = 1; xPoint = xPoints[i], yPoint = yPoints[i]; i++) { - path.push('L ', xPoint - minX, ' ', yPoint - minY, ' '); + for (var i = 1, len = xPoints.length; i < len; i++) { + path.push('L ', xPoints[i] - minX, ' ', yPoints[i] - minY, ' '); } // TODO (kangax): maybe remove Path creation from here, to decouple fabric.Canvas from fabric.Path, @@ -901,9 +904,7 @@ }, _findSelectedObjects: function (e) { - var target, - targetRegion, - group = [ ], + var group = [ ], x1 = this._groupSelector.ex, y1 = this._groupSelector.ey, x2 = x1 + this._groupSelector.left, @@ -932,7 +933,7 @@ this.setActiveObject(group[0], e); } else if (group.length > 1) { - var group = new fabric.Group(group); + group = new fabric.Group(group); this.setActiveGroup(group); group.saveCoords(); this.fire('selection:created', { target: group }); @@ -975,11 +976,11 @@ } } } - for (var i = 0, len = possibleTargets.length; i < len; i++) { - var pointer = this.getPointer(e); - var isTransparent = this._isTargetTransparent(possibleTargets[i], pointer.x, pointer.y); + for (var j = 0, len = possibleTargets.length; j < len; j++) { + pointer = this.getPointer(e); + var isTransparent = this._isTargetTransparent(possibleTargets[j], pointer.x, pointer.y); if (!isTransparent) { - target = possibleTargets[i]; + target = possibleTargets[j]; this.relatedTarget = target; break; } diff --git a/src/canvas.serialization.js b/src/canvas.serialization.js index f8d27962..2f5565ca 100644 --- a/src/canvas.serialization.js +++ b/src/canvas.serialization.js @@ -47,6 +47,86 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { } } + /** @ignore */ + function loadObject(obj, index) { + + var pathProp = obj.paths ? 'paths' : 'path'; + var path = obj[pathProp]; + + delete obj[pathProp]; + + if (typeof path !== 'string') { + if (obj.type === 'image') { + fabric[fabric.util.string.capitalize(obj.type)].fromObject(obj, function (o) { + onObjectLoaded(o, index); + }); + } + else { + var klass = fabric[fabric.util.string.camelize(fabric.util.string.capitalize(obj.type))]; + if (!klass || !klass.fromObject) return; + + // restore path + if (path) { + obj[pathProp] = path; + } + onObjectLoaded(klass.fromObject(obj), index); + } + } + else { + if (obj.type === 'image') { + fabric.util.loadImage(path, function (image) { + var oImg = new fabric.Image(image); + + oImg.setSourcePath(path); + + fabric.util.object.extend(oImg, obj); + oImg.setAngle(obj.angle); + + onObjectLoaded(oImg, index); + }); + } + else if (obj.type === 'text') { + + if (obj.useNative) { + onObjectLoaded(fabric.Text.fromObject(obj), index); + } + else { + obj.path = path; + var object = fabric.Text.fromObject(obj); + var onscriptload = function () { + // TODO (kangax): find out why Opera refuses to work without this timeout + if (Object.prototype.toString.call(fabric.window.opera) === '[object Opera]') { + setTimeout(function () { + onObjectLoaded(object, index); + }, 500); + } + else { + onObjectLoaded(object, index); + } + }; + + fabric.util.getScript(path, onscriptload); + } + } + else { + fabric.loadSVGFromURL(path, function (elements) { + var object = fabric.util.groupSVGElements(elements, obj, path); + + // copy parameters from serialied json to object (left, top, scaleX, scaleY, etc.) + // skip this step if an object is a PathGroup, since we already passed it options object before + if (!(object instanceof fabric.PathGroup)) { + fabric.util.object.extend(object, obj); + if (typeof obj.angle !== 'undefined') { + object.setAngle(obj.angle); + } + } + + onObjectLoaded(object, index); + }); + } + } + } + var _this = this, numLoadedObjects = 0, numTotalObjects = objects.length; @@ -56,86 +136,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, { } try { - objects.forEach(function (obj, index) { - - var pathProp = obj.paths ? 'paths' : 'path'; - var path = obj[pathProp]; - - delete obj[pathProp]; - - if (typeof path !== 'string') { - switch (obj.type) { - case 'image': - fabric[fabric.util.string.capitalize(obj.type)].fromObject(obj, function (o) { - onObjectLoaded(o, index); - }); - break; - default: - var klass = fabric[fabric.util.string.camelize(fabric.util.string.capitalize(obj.type))]; - if (klass && klass.fromObject) { - // restore path - if (path) { - obj[pathProp] = path; - } - onObjectLoaded(klass.fromObject(obj), index); - } - break; - } - } - else { - if (obj.type === 'image') { - fabric.util.loadImage(path, function (image) { - var oImg = new fabric.Image(image); - - oImg.setSourcePath(path); - - fabric.util.object.extend(oImg, obj); - oImg.setAngle(obj.angle); - - onObjectLoaded(oImg, index); - }); - } - else if (obj.type === 'text') { - - if (obj.useNative) { - onObjectLoaded(fabric.Text.fromObject(obj), index); - } - else { - obj.path = path; - var object = fabric.Text.fromObject(obj); - var onscriptload = function () { - // TODO (kangax): find out why Opera refuses to work without this timeout - if (Object.prototype.toString.call(fabric.window.opera) === '[object Opera]') { - setTimeout(function () { - onObjectLoaded(object, index); - }, 500); - } - else { - onObjectLoaded(object, index); - } - } - - fabric.util.getScript(path, onscriptload); - } - } - else { - fabric.loadSVGFromURL(path, function (elements, options) { - var object = fabric.util.groupSVGElements(elements, obj, path); - - // copy parameters from serialied json to object (left, top, scaleX, scaleY, etc.) - // skip this step if an object is a PathGroup, since we already passed it options object before - if (!(object instanceof fabric.PathGroup)) { - fabric.util.object.extend(object, obj); - if (typeof obj.angle !== 'undefined') { - object.setAngle(obj.angle); - } - } - - onObjectLoaded(object, index); - }); - } - } - }, this); + objects.forEach(loadObject, this); } catch(e) { fabric.log(e.message); diff --git a/src/circle.class.js b/src/circle.class.js index a1e09231..28c6419a 100644 --- a/src/circle.class.js +++ b/src/circle.class.js @@ -141,7 +141,7 @@ options || (options = { }); var parsedAttributes = fabric.parseAttributes(element, fabric.Circle.ATTRIBUTE_NAMES); if (!isValidRadius(parsedAttributes)) { - throw Error('value of `r` attribute is required and can not be negative'); + throw new Error('value of `r` attribute is required and can not be negative'); } if ('left' in parsedAttributes) { parsedAttributes.left -= (options.width / 2) || 0; @@ -170,4 +170,4 @@ return new fabric.Circle(object); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/color.class.js b/src/color.class.js index f86609d4..8772c4bd 100644 --- a/src/color.class.js +++ b/src/color.class.js @@ -1,14 +1,14 @@ (function(global) { - + "use strict"; - + var fabric = global.fabric || (global.fabric = { }); - + if (fabric.Color) { fabric.warn('fabric.Color is already defined.'); return; } - + /** * The purpose of {@link fabric.Color} is to abstract and encapsulate common color operations; * {@link fabric.Color} is a constructor and creates instances of {@link fabric.Color} objects. @@ -25,11 +25,11 @@ this._tryParsingColor(color); } } - + fabric.Color = Color; - + fabric.Color.prototype = /** @scope fabric.Color.prototype */ { - + /** * @private * @method _tryParsingColor @@ -91,19 +91,19 @@ var source = this.getSource(); var r = source[0].toString(16); - r = (r.length == 1) ? ('0' + r) : r; + r = (r.length === 1) ? ('0' + r) : r; var g = source[1].toString(16); - g = (g.length == 1) ? ('0' + g) : g; + g = (g.length === 1) ? ('0' + g) : g; var b = source[2].toString(16); - b = (b.length == 1) ? ('0' + b) : b; + b = (b.length === 1) ? ('0' + b) : b; return r.toUpperCase() + g.toUpperCase() + b.toUpperCase(); }, /** - * Gets value of alpha channel for this color + * Gets value of alpha channel for this color * @method getAlpha * @return {Number} 0-1 */ @@ -145,8 +145,9 @@ toBlackWhite: function(threshold) { var source = this.getSource(), average = (source[0] * 0.3 + source[1] * 0.59 + source[2] * 0.11).toFixed(0), - currentAlpha = source[3], - threshold = threshold || 127; + currentAlpha = source[3]; + + threshold = threshold || 127; average = (Number(average) < Number(threshold)) ? 0 : 255; this.setSource([average, average, average, currentAlpha]); @@ -179,14 +180,14 @@ return this; } }; - + /** * Regex matching color in RGB or RGBA formats (ex: rgb(0, 0, 0), rgb(255, 100, 10, 0.5), rgb(1,1,1)) * @static * @field */ fabric.Color.reRGBa = /^rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(\d+(?:\.\d+)?))?\)$/; - + /** * Regex matching color in HEX format (ex: #FF5555, 010155, aff) * @static @@ -203,7 +204,7 @@ fabric.Color.fromRgb = function(color) { return Color.fromSource(Color.sourceFromRgb(color)); }; - + /** * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in RGB or RGBA format * @method sourceFromRgb @@ -241,7 +242,7 @@ fabric.Color.fromHex = function(color) { return Color.fromSource(Color.sourceFromHex(color)); }; - + /** * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HEX format * @static @@ -265,7 +266,7 @@ ]; } }; - + /** * Returns new color object, when given color in array representation (ex: [200, 100, 100, 0.5]) * @static @@ -278,4 +279,4 @@ return oColor; }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/ellipse.class.js b/src/ellipse.class.js index 26b70d84..07f25329 100644 --- a/src/ellipse.class.js +++ b/src/ellipse.class.js @@ -162,4 +162,4 @@ return new fabric.Ellipse(object); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/gradient.class.js b/src/gradient.class.js index fb3c9829..b1efa447 100644 --- a/src/gradient.class.js +++ b/src/gradient.class.js @@ -91,10 +91,8 @@ */ var colorStopEls = el.getElementsByTagName('stop'), - el, offset, colorStops = { }, - colorStopFromStyle, coords = { x1: el.getAttribute('x1') || 0, y1: el.getAttribute('y1') || 0, @@ -166,15 +164,17 @@ function getGradientDefs(doc) { var linearGradientEls = doc.getElementsByTagName('linearGradient'), radialGradientEls = doc.getElementsByTagName('radialGradient'), - el, + el, i, gradientDefs = { }; - for (var i = linearGradientEls.length; i--; ) { + i = linearGradientEls.length; + for (; i--; ) { el = linearGradientEls[i]; gradientDefs[el.getAttribute('id')] = el; } - for (var i = radialGradientEls.length; i--; ) { + i = radialGradientEls.length; + for (; i--; ) { el = radialGradientEls[i]; gradientDefs[el.getAttribute('id')] = el; } diff --git a/src/group.class.js b/src/group.class.js index 27b5d629..06930439 100644 --- a/src/group.class.js +++ b/src/group.class.js @@ -208,8 +208,11 @@ var groupScaleFactor = Math.max(this.scaleX, this.scaleY); - for (var i = 0, len = this.objects.length, object; object = this.objects[i]; i++) { + for (var i = 0, len = this.objects.length; i < len; i++) { + + var object = this.objects[i]; var originalScaleFactor = object.borderScaleFactor; + object.borderScaleFactor = groupScaleFactor; object.render(ctx); object.borderScaleFactor = originalScaleFactor; @@ -239,7 +242,7 @@ */ complexity: function() { return this.getObjects().reduce(function(total, object) { - total += (typeof object.complexity == 'function') ? object.complexity() : 0; + total += (typeof object.complexity === 'function') ? object.complexity() : 0; return total; }, 0); }, @@ -268,8 +271,6 @@ var groupLeft = this.get('left'), groupTop = this.get('top'), groupAngle = this.getAngle() * (Math.PI / 180), - objectLeft = object.get('originalLeft'), - objectTop = object.get('originalTop'), rotatedTop = Math.cos(groupAngle) * object.get('top') + Math.sin(groupAngle) * object.get('left'), rotatedLeft = -Math.sin(groupAngle) * object.get('top') + Math.cos(groupAngle) * object.get('left'); @@ -399,7 +400,7 @@ aX.push(o.oCoords[prop].x); aY.push(o.oCoords[prop].y); } - }; + } minX = min(aX); maxX = max(aX); @@ -481,4 +482,4 @@ fabric.Group.async = true; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/image.class.js b/src/image.class.js index 4eb72aaf..a441fd27 100644 --- a/src/image.class.js +++ b/src/image.class.js @@ -11,7 +11,7 @@ if (global.fabric.Image) { fabric.warn('fabric.Image is already defined.'); return; - }; + } if (!fabric.Object) { fabric.warn('fabric.Object is required for fabric.Image initialization'); @@ -109,9 +109,9 @@ * @method setBorderVisibility * @param {Boolean} visible When true, border is set to be visible */ - setBorderVisibility: function(visible) { + setBorderVisibility: function() { this._resetWidthHeight(); - this._adjustWidthHeightToBorders(showBorder); + this._adjustWidthHeightToBorders(); this.setCoords(); }, @@ -223,10 +223,10 @@ var isLikelyNode = typeof Buffer !== 'undefined' && typeof window === 'undefined', imgEl = this._originalImage, canvasEl = fabric.document.createElement('canvas'), - replacement = isLikelyNode ? new (require('canvas').Image) : fabric.document.createElement('img'), + replacement = isLikelyNode ? new (require('canvas').Image)() : fabric.document.createElement('img'), _this = this; - if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') { + if (!canvasEl.getContext && typeof G_vmlCanvasManager !== 'undefined') { G_vmlCanvasManager.initElement(canvasEl); } @@ -456,4 +456,4 @@ fabric.Image.async = true; -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); diff --git a/src/image_filters.js b/src/image_filters.js index 15314877..ecf755e5 100644 --- a/src/image_filters.js +++ b/src/image_filters.js @@ -457,29 +457,29 @@ fabric.Image.filters.Tint = fabric.util.createClass( /** @scope fabric.Image.fil * @param {Object} canvasEl Canvas element to apply filter to */ applyTo: function(canvasEl) { - + var context = canvasEl.getContext('2d'), imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height), data = imageData.data, - iLen = data.length, i, - r, g, b, a; - - var rgb = parseInt(this.color).toString(16); - var cr = parseInt('0x'+rgb.substr(0, 2)); - var cg = parseInt('0x'+rgb.substr(2, 2)); - var cb = parseInt('0x'+rgb.substr(4, 2)); - + iLen = data.length, i, a; + + var rgb = parseInt(this.color, 10).toString(16); + + var cr = parseInt('0x' + rgb.substr(0, 2), 16); + var cg = parseInt('0x' + rgb.substr(2, 2), 16); + var cb = parseInt('0x' + rgb.substr(4, 2), 16); + for (i = 0; i < iLen; i+=4) { a = data[i+3]; - - if (a > 0){ + + if (a > 0){ data[i] = cr; data[i+1] = cg; - data[i+2] = cb; - } + data[i+2] = cb; + } } - + context.putImageData(imageData, 0, 0); }, diff --git a/src/intersection.class.js b/src/intersection.class.js index 61258a44..904ce85b 100644 --- a/src/intersection.class.js +++ b/src/intersection.class.js @@ -60,7 +60,7 @@ ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x), ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x), u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y); - if (u_b != 0) { + if (u_b !== 0) { var ua = ua_t / u_b, ub = ub_t / u_b; if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) { @@ -72,7 +72,7 @@ } } else { - if (ua_t == 0 || ub_t == 0) { + if (ua_t === 0 || ub_t === 0) { result = new Intersection("Coincident"); } else { @@ -146,4 +146,4 @@ return result; }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/line.class.js b/src/line.class.js index 96fce884..76dc4117 100644 --- a/src/line.class.js +++ b/src/line.class.js @@ -4,7 +4,6 @@ var fabric = global.fabric || (global.fabric = { }), extend = fabric.util.object.extend, - parentSet = fabric.Object.prototype.set, coordProps = { 'x1': 1, 'x2': 1, 'y1': 1, 'y2': 1 }; if (fabric.Line) { @@ -181,4 +180,4 @@ return new fabric.Line(points, object); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/node.js b/src/node.js index f3044f79..a2ced898 100644 --- a/src/node.js +++ b/src/node.js @@ -1,6 +1,6 @@ (function() { - if (typeof document != 'undefined' && typeof window != 'undefined') { + if (typeof document !== 'undefined' && typeof window !== 'undefined') { return; } @@ -14,7 +14,7 @@ function request(url, encoding, callback) { var oURL = URL.parse(url), client = HTTP.createClient(oURL.port, oURL.hostname), - request = client.request('GET', oURL.pathname, { 'host': oURL.hostname }); + req = client.request('GET', oURL.pathname, { 'host': oURL.hostname }); client.addListener('error', function(err) { if (err.errno === process.ECONNREFUSED) { @@ -25,8 +25,8 @@ } }); - request.end(); - request.on('response', function (response) { + req.end(); + req.on('response', function (response) { var body = ""; if (encoding) { response.setEncoding(encoding); @@ -35,7 +35,7 @@ callback(body); }); response.on('data', function (chunk) { - if (response.statusCode == 200) { + if (response.statusCode === 200) { body += chunk; } }); @@ -101,8 +101,8 @@ canvasEl.width = nodeCanvas.width; canvasEl.height = nodeCanvas.height; - var canvas = fabric.Canvas || fabric.StaticCanvas; - var fabricCanvas = new canvas(canvasEl); + var FabricCanvas = fabric.Canvas || fabric.StaticCanvas; + var fabricCanvas = new FabricCanvas(canvasEl); fabricCanvas.contextContainer = nodeCanvas.getContext('2d'); fabricCanvas.nodeCanvas = nodeCanvas; @@ -112,9 +112,6 @@ fabric.StaticCanvas.prototype.createPNGStream = function() { return this.nodeCanvas.createPNGStream(); }; - if (fabric.Canvas) { - fabric.Canvas.prototype.createPNGStream - } var origSetWidth = fabric.StaticCanvas.prototype.setWidth; fabric.StaticCanvas.prototype.setWidth = function(width) { diff --git a/src/object.class.js b/src/object.class.js index 52123751..99d22d75 100644 --- a/src/object.class.js +++ b/src/object.class.js @@ -4,7 +4,6 @@ var fabric = global.fabric || (global.fabric = { }), extend = fabric.util.object.extend, - clone = fabric.util.object.clone, toFixed = fabric.util.toFixed, capitalize = fabric.util.string.capitalize, getPointer = fabric.util.getPointer, @@ -258,7 +257,7 @@ * @method initGradient */ _initGradient: function(options) { - if (options.fill && typeof options.fill == 'object' && !(options.fill instanceof fabric.Gradient)) { + if (options.fill && typeof options.fill === 'object' && !(options.fill instanceof fabric.Gradient)) { this.set('fill', new fabric.Gradient(options.fill)); } }, @@ -792,8 +791,6 @@ : -h - (strokeWidth * this.scaleY) - (padding * 2) ) / 2; - var rotateWidth = (-w/2); - ctx.beginPath(); ctx.moveTo(0, rotateHeight); ctx.lineTo(0, rotateHeight + (this.flipY ? this.rotatingPointOffset : -this.rotatingPointOffset)); @@ -816,8 +813,6 @@ x = -this.width/2, y = -this.height/2, _this = this, padding = this.padding, - width = this.getWidth(), - height = this.getHeight(), dashedArrayLength = this.strokeDashArray.length; ctx.save(); @@ -826,6 +821,7 @@ function renderSide(xMultiplier, yMultiplier) { var lineLength = 0, + lengthDiff = 0, sideLength = (yMultiplier ? _this.height : _this.width) + padding * 2; while (lineLength < sideLength) { @@ -834,7 +830,7 @@ lineLength += lengthOfSubPath; if (lineLength > sideLength) { - var lengthDiff = lineLength - sideLength; + lengthDiff = lineLength - sideLength; } // track coords @@ -1030,7 +1026,7 @@ */ toDataURL: function(callback) { var el = fabric.document.createElement('canvas'); - if (!el.getContext && typeof G_vmlCanvasManager != 'undefined') { + if (!el.getContext && typeof G_vmlCanvasManager !== 'undefined') { G_vmlCanvasManager.initElement(el); } @@ -1132,7 +1128,7 @@ tr: new fabric.Point(oCoords.tr.x, oCoords.tr.y), bl: new fabric.Point(oCoords.bl.x, oCoords.bl.y), br: new fabric.Point(oCoords.br.x, oCoords.br.y) - } + }; } var thisCoords = getCoords(this.oCoords), otherCoords = getCoords(other.oCoords); @@ -1166,8 +1162,7 @@ var oCoords = this.oCoords, tl = new fabric.Point(oCoords.tl.x, oCoords.tl.y), tr = new fabric.Point(oCoords.tr.x, oCoords.tr.y), - bl = new fabric.Point(oCoords.bl.x, oCoords.bl.y), - br = new fabric.Point(oCoords.br.x, oCoords.br.y); + bl = new fabric.Point(oCoords.bl.x, oCoords.bl.y); return tl.x > selectionTL.x && tr.x < selectionBR.x @@ -1228,7 +1223,7 @@ // canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2); xpoints = this._findCrossPoints(ex, ey, lines); - if (xpoints % 2 == 1 && xpoints != 0) { + if (xpoints % 2 === 1 && xpoints !== 0) { this.__corner = i; return i; } @@ -1261,7 +1256,7 @@ continue; } // optimisation 3: vertical line case - if ((iLine.o.x == iLine.d.x) && (iLine.o.x >= ex)) { + if ((iLine.o.x === iLine.d.x) && (iLine.o.x >= ex)) { xi = iLine.o.x; yi = ey; } @@ -1280,7 +1275,7 @@ xcount += 1; } // optimisation 4: specific for square images - if (xcount == 2) { + if (xcount === 2) { break; } } @@ -1293,7 +1288,7 @@ * @private * @param oCoords {Object} coordinates of the image corners */ - _getImageLines: function(oCoords, i) { + _getImageLines: function(oCoords) { return { topline: { o: oCoords.tl, @@ -1311,7 +1306,7 @@ o: oCoords.bl, d: oCoords.tl } - } + }; }, /** @@ -1554,7 +1549,7 @@ * */ animate: function() { - if (arguments[0] && typeof arguments[0] == 'object') { + if (arguments[0] && typeof arguments[0] === 'object') { for (var prop in arguments[0]) { this._animate(prop, arguments[0][prop], arguments[1]); } @@ -1578,7 +1573,7 @@ options.from = this.get(property); } - if (/[+-]/.test((to + '').charAt(0))) { + if (/[+\-]/.test((to + '').charAt(0))) { to = this.get(property) + parseFloat(to); } @@ -1731,4 +1726,4 @@ }); -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); diff --git a/src/observable.js b/src/observable.js index b59c4125..c0e0790f 100644 --- a/src/observable.js +++ b/src/observable.js @@ -52,7 +52,7 @@ fabric.Observable = { */ fire: function(eventName, options) { if (!this.__eventListeners) { - this.__eventListeners = { } + this.__eventListeners = { }; } var listenersForEvent = this.__eventListeners[eventName]; if (!listenersForEvent) return; diff --git a/src/parser.js b/src/parser.js index f78173a2..a40d75a2 100644 --- a/src/parser.js +++ b/src/parser.js @@ -87,7 +87,7 @@ ownAttributes = extend(ownAttributes, extend(getGlobalStylesForElement(element), fabric.parseStyleAttribute(element))); return extend(parentAttributes, ownAttributes); - }; + } /** * Parses "transform" attribute, returning an array of values @@ -218,9 +218,9 @@ matrix = args; break; } - }) + }); return matrix; - } + }; })(); /** @@ -240,17 +240,21 @@ var asPairs = points.indexOf(',') > -1; points = points.split(/\s+/); - var parsedPoints = [ ]; + var parsedPoints = [ ], i, len; // points could look like "10,20 30,40" or "10 20 30 40" if (asPairs) { - for (var i = 0, len = points.length; i < len; i++) { - var pair = points[i].split(','); - parsedPoints.push({ x: parseFloat(pair[0]), y: parseFloat(pair[1]) }); - } + i = 0; + len = points.length; + for (; i < len; i++) { + var pair = points[i].split(','); + parsedPoints.push({ x: parseFloat(pair[0]), y: parseFloat(pair[1]) }); + } } else { - for (var i = 0, len = points.length; i < len; i+=2) { + i = 0; + len = points.length; + for (; i < len; i+=2) { parsedPoints.push({ x: parseFloat(points[i]), y: parseFloat(points[i+1]) }); } } @@ -261,7 +265,7 @@ } return parsedPoints; - }; + } /** * Parses "style" attribute, retuning an object with values @@ -274,22 +278,24 @@ function parseStyleAttribute(element) { var oStyle = { }, style = element.getAttribute('style'); - if (style) { - if (typeof style == 'string') { - style = style.replace(/;$/, '').split(';').forEach(function (current) { - var attr = current.split(':'); - oStyle[normalizeAttr(attr[0].trim().toLowerCase())] = attr[1].trim(); - }); - } else { - for (var prop in style) { - if (typeof style[prop] !== 'undefined') { - oStyle[normalizeAttr(prop.toLowerCase())] = style[prop]; - } - } + + if (!style) return oStyle; + + if (typeof style === 'string') { + style = style.replace(/;$/, '').split(';').forEach(function (current) { + var attr = current.split(':'); + oStyle[normalizeAttr(attr[0].trim().toLowerCase())] = attr[1].trim(); + }); + } + else { + for (var prop in style) { + if (typeof style[prop] === 'undefined') continue; + oStyle[normalizeAttr(prop.toLowerCase())] = style[prop]; } } + return oStyle; - }; + } function resolveGradients(instances) { for (var i = instances.length; i--; ) { @@ -318,7 +324,7 @@ * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created. */ function parseElements(elements, callback, options, reviver) { - var instances = Array(elements.length), i = elements.length; + var instances = new Array(elements.length), i = elements.length; function checkIfDone() { if (--i === 0) { @@ -359,7 +365,7 @@ checkIfDone(); } } - }; + } /** * Returns CSS rules for a given SVG document @@ -383,12 +389,12 @@ styleContents = styleContents.replace(/\/\*[\s\S]*?\*\//g, ''); rules = styleContents.match(/[^{]*\{[\s\S]*?\}/g); - rules = rules.map(function(rule) { return rule.trim() }); + rules = rules.map(function(rule) { return rule.trim(); }); rules.forEach(function(rule) { - var match = rule.match(/([\s\S]*?)\s*\{([^}]*)\}/), - rule = match[1], - declaration = match[2].trim(), + var match = rule.match(/([\s\S]*?)\s*\{([^}]*)\}/); + rule = match[1]; + var declaration = match[2].trim(), propertyValuePairs = declaration.replace(/;$/, '').split(/\s*;\s*/); if (!allRules[rule]) { @@ -550,7 +556,7 @@ * @param {String} url * @param {Function} callback */ - get: function (url, callback) { + get: function () { /* NOOP */ }, @@ -559,7 +565,7 @@ * @param {String} url * @param {Object} object */ - set: function (url, object) { + set: function () { /* NOOP */ } }; @@ -643,7 +649,7 @@ } } else if (fabric.window.ActiveXObject) { - var doc = new ActiveXObject('Microsoft.XMLDOM'); + doc = new ActiveXObject('Microsoft.XMLDOM'); doc.async = 'false'; //IE chokes on DOCTYPE doc.loadXML(string.replace(//i,'')); @@ -697,4 +703,4 @@ createSVGFontFacesMarkup: createSVGFontFacesMarkup }); -})(typeof exports != 'undefined' ? exports : this); +})(typeof exports !== 'undefined' ? exports : this); diff --git a/src/path.class.js b/src/path.class.js index 309d8901..ed2631b7 100644 --- a/src/path.class.js +++ b/src/path.class.js @@ -66,7 +66,7 @@ var sfactor_sq = 1 / d - 0.25; if (sfactor_sq < 0) sfactor_sq = 0; var sfactor = Math.sqrt(sfactor_sq); - if (sweep == large) sfactor = -sfactor; + if (sweep === large) sfactor = -sfactor; var xc = 0.5 * (x0 + x1) - sfactor * (y1-y0); var yc = 0.5 * (y0 + y1) + sfactor * (x1-x0); @@ -74,9 +74,9 @@ var th1 = Math.atan2(y1-yc, x1-xc); var th_arc = th1-th0; - if (th_arc < 0 && sweep == 1){ + if (th_arc < 0 && sweep === 1){ th_arc += 2*Math.PI; - } else if (th_arc > 0 && sweep == 0) { + } else if (th_arc > 0 && sweep === 0) { th_arc -= 2 * Math.PI; } @@ -179,7 +179,7 @@ this.setOptions(options); if (!path) { - throw Error('`path` argument is required'); + throw new Error('`path` argument is required'); } var fromArray = _toString.call(path) === '[object Array]'; @@ -631,7 +631,7 @@ chunks, parsed; - for (var i = 0, j, chunksParsed, len = this.path.length; i < len; i++) { + for (var i = 0, chunksParsed, len = this.path.length; i < len; i++) { currentPath = this.path[i]; chunks = currentPath.slice(1).trim().replace(/(\d)-/g, '$1###-').split(/\s|,|###/); chunksParsed = [ currentPath.charAt(0) ]; @@ -759,4 +759,4 @@ return new fabric.Path(parsedAttributes.d, extend(parsedAttributes, options)); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/path_group.class.js b/src/path_group.class.js index e0b9d8be..46fa6791 100644 --- a/src/path_group.class.js +++ b/src/path_group.class.js @@ -5,7 +5,6 @@ var fabric = global.fabric || (global.fabric = { }), extend = fabric.util.object.extend, invoke = fabric.util.array.invoke, - parentSet = fabric.Object.prototype.set, parentToObject = fabric.Object.prototype.toObject, camelize = fabric.util.string.camelize, capitalize = fabric.util.string.capitalize; @@ -237,4 +236,4 @@ return new fabric.PathGroup(paths, object); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/point.class.js b/src/point.class.js index 59375edb..ba455a46 100644 --- a/src/point.class.js +++ b/src/point.class.js @@ -1,18 +1,18 @@ (function(global) { - + "use strict"; - + /* Adaptation of work of Kevin Lindsey (kevin@kevlindev.com) */ - + var fabric = global.fabric || (global.fabric = { }); - if (fabric.Point) { + if (fabric.Point) { fabric.warn('fabric.Point is already defined'); return; } fabric.Point = Point; - + /** * @name Point * @memberOf fabric @@ -26,11 +26,11 @@ this.init(x, y); } } - + Point.prototype = /** @scope fabric.Point.prototype */ { - + constructor: Point, - + /** * @method init * @param {Number} x @@ -40,7 +40,7 @@ this.x = x; this.y = y; }, - + /** * @method add * @param {fabric.Point} that @@ -49,7 +49,7 @@ add: function (that) { return new Point(this.x + that.x, this.y + that.y); }, - + /** * @method addEquals * @param {fabric.Point} that @@ -60,7 +60,7 @@ this.y += that.y; return this; }, - + /** * @method scalarAdd * @param {Number} scalar @@ -69,7 +69,7 @@ scalarAdd: function (scalar) { return new Point(this.x + scalar, this.y + scalar); }, - + /** * @method scalarAddEquals * @param {Number} scalar @@ -80,7 +80,7 @@ this.y += scalar; return this; }, - + /** * @method subtract * @param {fabric.Point} that @@ -89,7 +89,7 @@ subtract: function (that) { return new Point(this.x - that.x, this.y - that.y); }, - + /** * @method subtractEquals * @param {fabric.Point} that @@ -100,89 +100,89 @@ this.y -= that.y; return this; }, - + scalarSubtract: function (scalar) { return new Point(this.x - scalar, this.y - scalar); }, - + scalarSubtractEquals: function (scalar) { this.x -= scalar; this.y -= scalar; return this; }, - + multiply: function (scalar) { return new Point(this.x * scalar, this.y * scalar); }, - + multiplyEquals: function (scalar) { this.x *= scalar; this.y *= scalar; return this; }, - + divide: function (scalar) { return new Point(this.x / scalar, this.y / scalar); }, - + divideEquals: function (scalar) { this.x /= scalar; this.y /= scalar; return this; }, - + eq: function (that) { - return (this.x == that.x && this.y == that.y); + return (this.x === that.x && this.y === that.y); }, - + lt: function (that) { return (this.x < that.x && this.y < that.y); }, - + lte: function (that) { return (this.x <= that.x && this.y <= that.y); }, - + gt: function (that) { return (this.x > that.x && this.y > that.y); }, - + gte: function (that) { return (this.x >= that.x && this.y >= that.y); }, - + lerp: function (that, t) { return new Point(this.x + (that.x - this.x) * t, this.y + (that.y - this.y) * t); }, - + distanceFrom: function (that) { var dx = this.x - that.x, dy = this.y - that.y; return Math.sqrt(dx * dx + dy * dy); }, - + min: function (that) { return new Point(Math.min(this.x, that.x), Math.min(this.y, that.y)); }, - + max: function (that) { return new Point(Math.max(this.x, that.x), Math.max(this.y, that.y)); }, - + toString: function () { return this.x + "," + this.y; }, - + setXY: function (x, y) { this.x = x; this.y = y; }, - + setFromPoint: function (that) { this.x = that.x; this.y = that.y; }, - + swap: function (that) { var x = this.x, y = this.y; @@ -192,5 +192,5 @@ that.y = y; } }; - -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file + +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/polygon.class.js b/src/polygon.class.js index f7256f7e..e0e2fe4c 100644 --- a/src/polygon.class.js +++ b/src/polygon.class.js @@ -13,9 +13,6 @@ return; } - function byX(p) { return p.x; } - function byY(p) { return p.y; } - /** * @class Polygon * @extends fabric.Object @@ -168,4 +165,4 @@ return new fabric.Polygon(object.points, object); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/polyline.class.js b/src/polyline.class.js index ec29d25c..6946ffd7 100644 --- a/src/polyline.class.js +++ b/src/polyline.class.js @@ -149,4 +149,4 @@ return new fabric.Polyline(points, object); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/rect.class.js b/src/rect.class.js index f06c2251..c49625cd 100644 --- a/src/rect.class.js +++ b/src/rect.class.js @@ -217,4 +217,4 @@ return new fabric.Rect(object); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/static_canvas.class.js b/src/static_canvas.class.js index 184b4fe1..f990d587 100644 --- a/src/static_canvas.class.js +++ b/src/static_canvas.class.js @@ -1,4 +1,4 @@ -(function (global) { +(function () { "use strict"; @@ -103,7 +103,7 @@ * @method onBeforeScaleRotate * @param {fabric.Object} target Object that's about to be scaled/rotated */ - onBeforeScaleRotate: function (target) { + onBeforeScaleRotate: function () { /* NOOP */ }, @@ -481,39 +481,24 @@ this.clearContext(canvasToDrawOn); } - var length = this._objects.length, - activeGroup = this.getActiveGroup(), + var activeGroup = this.getActiveGroup(), startTime = new Date(); if (this.clipTo) { - canvasToDrawOn.save(); - canvasToDrawOn.beginPath(); - this.clipTo(canvasToDrawOn); - canvasToDrawOn.clip(); + this._clipCanvas(canvasToDrawOn); } canvasToDrawOn.fillStyle = this.backgroundColor; canvasToDrawOn.fillRect(0, 0, this.width, this.height); - if (typeof this.backgroundImage == 'object') { - canvasToDrawOn.save(); - canvasToDrawOn.globalAlpha = this.backgroundImageOpacity; - - if (this.backgroundImageStretch) { - canvasToDrawOn.drawImage(this.backgroundImage, 0, 0, this.width, this.height); - } - else { - canvasToDrawOn.drawImage(this.backgroundImage, 0, 0); - } - canvasToDrawOn.restore(); + if (typeof this.backgroundImage === 'object') { + this._drawBackroundImage(canvasToDrawOn); } - if (length) { - for (var i = 0; i < length; ++i) { - if (!activeGroup || - (activeGroup && this._objects[i] && !activeGroup.contains(this._objects[i]))) { - this._draw(canvasToDrawOn, this._objects[i]); - } + for (var i = 0, length = this._objects.length; i < length; ++i) { + if (!activeGroup || + (activeGroup && this._objects[i] && !activeGroup.contains(this._objects[i]))) { + this._draw(canvasToDrawOn, this._objects[i]); } } @@ -544,6 +529,26 @@ return this; }, + _clipCanvas: function(canvasToDrawOn) { + canvasToDrawOn.save(); + canvasToDrawOn.beginPath(); + this.clipTo(canvasToDrawOn); + canvasToDrawOn.clip(); + }, + + _drawBackroundImage: function(canvasToDrawOn) { + canvasToDrawOn.save(); + canvasToDrawOn.globalAlpha = this.backgroundImageOpacity; + + if (this.backgroundImageStretch) { + canvasToDrawOn.drawImage(this.backgroundImage, 0, 0, this.width, this.height); + } + else { + canvasToDrawOn.drawImage(this.backgroundImage, 0, 0); + } + canvasToDrawOn.restore(); + }, + /** * Method to render only the top canvas. * Also used to render the group selection box. @@ -776,8 +781,9 @@ var data = { objects: this._objects.map(function (instance) { // TODO (kangax): figure out how to clean this up + var originalValue; if (!this.includeDefaultValues) { - var originalValue = instance.includeDefaultValues; + originalValue = instance.includeDefaultValues; instance.includeDefaultValues = false; } var object = instance[methodName](); @@ -1102,9 +1108,9 @@ try { el.toDataURL('image/jpeg', 0); return true; - } catch (e) { - return false; } + catch (e) { } + return false; default: return null; @@ -1120,4 +1126,4 @@ */ fabric.StaticCanvas.prototype.toJSON = fabric.StaticCanvas.prototype.toObject; -})(typeof exports != 'undefined' ? exports : this); +})(); \ No newline at end of file diff --git a/src/text.class.js b/src/text.class.js index ed901093..3bd4c05d 100644 --- a/src/text.class.js +++ b/src/text.class.js @@ -133,7 +133,7 @@ _initDimensions: function() { var canvasEl = fabric.document.createElement('canvas'); - if (!canvasEl.getContext && typeof G_vmlCanvasManager != 'undefined') { + if (!canvasEl.getContext && typeof G_vmlCanvasManager !== 'undefined') { G_vmlCanvasManager.initElement(canvasEl); } @@ -445,29 +445,30 @@ _renderTextDecoration: function(ctx, textLines) { var halfOfVerticalBox = this._getTextHeight(ctx, textLines) / 2; + var _this = this; function renderLinesAtOffset(offset) { for (var i = 0, len = textLines.length; i < len; i++) { var lineWidth = ctx.measureText(textLines[i]).width; - var lineLeftOffset = this._getLineLeftOffset(lineWidth); + var lineLeftOffset = _this._getLineLeftOffset(lineWidth); ctx.fillRect( - (-this.width / 2) + lineLeftOffset, - (offset + (i * this.fontSize * this.lineHeight)) - halfOfVerticalBox, + (-_this.width / 2) + lineLeftOffset, + (offset + (i * _this.fontSize * _this.lineHeight)) - halfOfVerticalBox, lineWidth, 1); } } if (this.textDecoration.indexOf('underline') > -1) { - renderLinesAtOffset.call(this, this.fontSize); + renderLinesAtOffset(this.fontSize); } if (this.textDecoration.indexOf('line-through') > -1) { - renderLinesAtOffset.call(this, this.fontSize / 2); + renderLinesAtOffset(this.fontSize / 2); } if (this.textDecoration.indexOf('overline') > -1) { - renderLinesAtOffset.call(this, 0); + renderLinesAtOffset(0); } }, @@ -495,7 +496,7 @@ // Cufon doesn't play nice with textDecoration=underline if element doesn't have a parent container.appendChild(el); - if (typeof G_vmlCanvasManager == 'undefined') { + if (typeof G_vmlCanvasManager === 'undefined') { el.innerHTML = this.text; } else { @@ -779,10 +780,10 @@ } var parsedAttributes = fabric.parseAttributes(element, fabric.Text.ATTRIBUTE_NAMES); - var options = fabric.util.object.extend((options ? fabric.util.object.clone(options) : { }), parsedAttributes); + options = fabric.util.object.extend((options ? fabric.util.object.clone(options) : { }), parsedAttributes); var text = new fabric.Text(element.textContent, options); return text; }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/triangle.class.js b/src/triangle.class.js index e46f00cb..771a7601 100644 --- a/src/triangle.class.js +++ b/src/triangle.class.js @@ -1,26 +1,26 @@ (function(global) { - + "use strict"; - + var fabric = global.fabric || (global.fabric = { }); - + if (fabric.Triangle) { fabric.warn('fabric.Triangle is already defined'); return; } - - /** + + /** * @class Triangle * @extends fabric.Object */ fabric.Triangle = fabric.util.createClass(fabric.Object, /** @scope fabric.Triangle.prototype */ { - + /** * @property * @type String */ type: 'triangle', - + /** * Constructor * @method initialize @@ -29,28 +29,28 @@ */ initialize: function(options) { options = options || { }; - + this.callSuper('initialize', options); - + this.set('width', options.width || 100) .set('height', options.height || 100); }, - + /** * @private * @method _render * @param ctx {CanvasRenderingContext2D} Context to render on */ - _render: function(ctx) { + _render: function(ctx) { var widthBy2 = this.width / 2, heightBy2 = this.height / 2; - + ctx.beginPath(); ctx.moveTo(-widthBy2, heightBy2); ctx.lineTo(0, -heightBy2); ctx.lineTo(widthBy2, heightBy2); ctx.closePath(); - + if (this.fill) { ctx.fill(); } @@ -58,7 +58,7 @@ ctx.stroke(); } }, - + /** * Returns complexity of an instance * @method complexity @@ -67,7 +67,7 @@ complexity: function() { return 1; }, - + /** * Returns svg representation of an instance * @method toSVG @@ -91,7 +91,7 @@ '/>'; } }); - + /** * Returns fabric.Triangle instance from an object representation * @static @@ -103,4 +103,4 @@ return new fabric.Triangle(object); }; -})(typeof exports != 'undefined' ? exports : this); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : this); \ No newline at end of file diff --git a/src/util/anim_ease.js b/src/util/anim_ease.js index ce268030..1c069cdd 100644 --- a/src/util/anim_ease.js +++ b/src/util/anim_ease.js @@ -21,7 +21,8 @@ * @memberOf fabric.util.ease */ function easeInOutQuad(t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t + b; + t /= (d/2); + if (t < 1) return c/2*t*t + b; return -c/2 * ((--t)*(t-2) - 1) + b; } @@ -46,7 +47,8 @@ * @memberOf fabric.util.ease */ function easeInOutCubic(t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t + b; + t /= d/2; + if (t < 1) return c/2*t*t*t + b; return c/2*((t-=2)*t*t + 2) + b; } @@ -71,7 +73,8 @@ * @memberOf fabric.util.ease */ function easeInOutQuart(t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t*t + b; + t /= d/2; + if (t < 1) return c/2*t*t*t*t + b; return -c/2 * ((t-=2)*t*t*t - 2) + b; } @@ -96,7 +99,8 @@ * @memberOf fabric.util.ease */ function easeInOutQuint(t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; + t /= d/2; + if (t < 1) return c/2*t*t*t*t*t + b; return c/2*((t-=2)*t*t*t*t + 2) + b; } @@ -129,7 +133,7 @@ * @memberOf fabric.util.ease */ function easeInExpo(t, b, c, d) { - return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; + return (t===0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; } /** @@ -137,7 +141,7 @@ * @memberOf fabric.util.ease */ function easeOutExpo(t, b, c, d) { - return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; + return (t===d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; } /** @@ -145,9 +149,10 @@ * @memberOf fabric.util.ease */ function easeInOutExpo(t, b, c, d) { - if (t==0) return b; - if (t==d) return b+c; - if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; + if (t===0) return b; + if (t===d) return b+c; + t /= d/2; + if (t < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; } @@ -172,7 +177,8 @@ * @memberOf fabric.util.ease */ function easeInOutCirc(t, b, c, d) { - if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; + t /= d/2; + if (t < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; } @@ -182,9 +188,12 @@ */ function easeInElastic(t, b, c, d) { var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); + if (t===0) return b; + t /= d; + if (t===1) return b+c; + if (!p) p=d*0.3; + if (a < Math.abs(c)) { a=c; s=p/4; } + else s = p/(2*Math.PI) * Math.asin (c/a); return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; } @@ -194,9 +203,12 @@ */ function easeOutElastic(t, b, c, d) { var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); + if (t===0) return b; + t /= d; + if (t===1) return b+c; + if (!p) p=d*0.3; + if (a < Math.abs(c)) { a=c; s=p/4; } + else s = p/(2*Math.PI) * Math.asin (c/a); return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; } @@ -206,11 +218,14 @@ */ function easeInOutElastic(t, b, c, d) { var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); - if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; - return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; + if (t===0) return b; + t /= d/2; + if (t===2) return b+c; + if (!p) p=d*(0.3*1.5); + if (a < Math.abs(c)) { a=c; s=p/4; } + else s = p/(2*Math.PI) * Math.asin (c/a); + if (t < 1) return -0.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b; } /** @@ -218,7 +233,7 @@ * @memberOf fabric.util.ease */ function easeInBack(t, b, c, d, s) { - if (s == undefined) s = 1.70158; + if (s === undefined) s = 1.70158; return c*(t/=d)*t*((s+1)*t - s) + b; } @@ -227,7 +242,7 @@ * @memberOf fabric.util.ease */ function easeOutBack(t, b, c, d, s) { - if (s == undefined) s = 1.70158; + if (s === undefined) s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; } @@ -236,8 +251,9 @@ * @memberOf fabric.util.ease */ function easeInOutBack(t, b, c, d, s) { - if (s == undefined) s = 1.70158; - if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; + if (s === undefined) s = 1.70158; + t /= d/2; + if (t < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; } @@ -257,11 +273,11 @@ if ((t/=d) < (1/2.75)) { return c*(7.5625*t*t) + b; } else if (t < (2/2.75)) { - return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; + return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b; } else if (t < (2.5/2.75)) { - return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; + return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b; } else { - return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; + return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b; } } @@ -270,8 +286,8 @@ * @memberOf fabric.util.ease */ function easeInOutBounce(t, b, c, d) { - if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b; - return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b; + if (t < d/2) return easeInBounce (t*2, 0, c, d) * 0.5 + b; + return easeOutBounce (t*2-d, 0, c, d) * 0.5 + c*0.5 + b; } /** @namespace fabric.util.ease */ diff --git a/src/util/dom_event.js b/src/util/dom_event.js index 709e9977..b3667209 100644 --- a/src/util/dom_event.js +++ b/src/util/dom_event.js @@ -1,4 +1,4 @@ -(function (global) { +(function () { /* EVENT HANDLING */ @@ -183,26 +183,26 @@ return { x: pointerX(event), y: pointerY(event) }; } - function pointerX(event) { + var pointerX = function(event) { var docElement = fabric.document.documentElement, body = fabric.document.body || { scrollLeft: 0 }; // looks like in IE (<9) clientX at certain point (apparently when mouseup fires on VML element) // is represented as COM object, with all the consequences, like "unknown" type and error on [[Get]] // need to investigate later - return event.pageX || ((typeof event.clientX != 'unknown' ? event.clientX : 0) + + return event.pageX || ((typeof event.clientX !== 'unknown' ? event.clientX : 0) + (docElement.scrollLeft || body.scrollLeft) - (docElement.clientLeft || 0)); - } + }; - function pointerY(event) { + var pointerY = function(event) { var docElement = fabric.document.documentElement, body = fabric.document.body || { scrollTop: 0 }; - return event.pageY || ((typeof event.clientY != 'unknown' ? event.clientY : 0) + + return event.pageY || ((typeof event.clientY !== 'unknown' ? event.clientY : 0) + (docElement.scrollTop || body.scrollTop) - (docElement.clientTop || 0)); - } + }; if (fabric.isTouchSupported) { pointerX = function(event) { @@ -217,4 +217,4 @@ fabric.util.object.extend(fabric.util, fabric.Observable); -})(this); \ No newline at end of file +})(); \ No newline at end of file diff --git a/src/util/dom_misc.js b/src/util/dom_misc.js index fb48c4b6..5a964a53 100644 --- a/src/util/dom_misc.js +++ b/src/util/dom_misc.js @@ -1,5 +1,5 @@ (function() { - + var _slice = Array.prototype.slice; /** @@ -20,12 +20,13 @@ * @param {Object} arrayLike * @return {Array} */ - function toArray(arrayLike) { + var toArray = function(arrayLike) { return _slice.call(arrayLike, 0); - } + }; + var sliceCanConvertNodelists; try { - var sliceCanConvertNodelists = toArray(fabric.document.childNodes) instanceof Array; + sliceCanConvertNodelists = toArray(fabric.document.childNodes) instanceof Array; } catch(err) { } @@ -73,7 +74,7 @@ function addClass(element, className) { if ((' ' + element.className + ' ').indexOf(' ' + className + ' ') === -1) { element.className += (element.className ? ' ' : '') + className; - } + } } /** @@ -111,7 +112,7 @@ valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; element = element.offsetParent; - } + } while (element); return ({ left: valueL, top: valueT }); } @@ -121,12 +122,12 @@ var selectProp = 'userSelect' in style ? 'userSelect' - : 'MozUserSelect' in style - ? 'MozUserSelect' - : 'WebkitUserSelect' in style - ? 'WebkitUserSelect' - : 'KhtmlUserSelect' in style - ? 'KhtmlUserSelect' + : 'MozUserSelect' in style + ? 'MozUserSelect' + : 'WebkitUserSelect' in style + ? 'WebkitUserSelect' + : 'KhtmlUserSelect' in style + ? 'KhtmlUserSelect' : ''; /** @@ -143,7 +144,7 @@ if (selectProp) { element.style[selectProp] = 'none'; } - else if (typeof element.unselectable == 'string') { + else if (typeof element.unselectable === 'string') { element.unselectable = 'on'; } return element; @@ -163,7 +164,7 @@ if (selectProp) { element.style[selectProp] = ''; } - else if (typeof element.unselectable == 'string') { + else if (typeof element.unselectable === 'string') { element.unselectable = ''; } return element; @@ -183,28 +184,28 @@ * @param {Function} callback Callback to execute when script is finished loading */ function getScript(url, callback) { - var headEl = fabric.document.getElementsByTagName("head")[0], - scriptEl = fabric.document.createElement('script'), - loading = true; + var headEl = fabric.document.getElementsByTagName("head")[0], + scriptEl = fabric.document.createElement('script'), + loading = true; - scriptEl.type = 'text/javascript'; - scriptEl.setAttribute('runat', 'server'); + scriptEl.type = 'text/javascript'; + scriptEl.setAttribute('runat', 'server'); - /** @ignore */ - scriptEl.onload = /** @ignore */ scriptEl.onreadystatechange = function(e) { - if (loading) { - if (typeof this.readyState == 'string' && - this.readyState !== 'loaded' && - this.readyState !== 'complete') return; - loading = false; - callback(e || fabric.window.event); - scriptEl = scriptEl.onload = scriptEl.onreadystatechange = null; - } - }; - scriptEl.src = url; - headEl.appendChild(scriptEl); - // causes issue in Opera - // headEl.removeChild(scriptEl); + /** @ignore */ + scriptEl.onload = /** @ignore */ scriptEl.onreadystatechange = function(e) { + if (loading) { + if (typeof this.readyState === 'string' && + this.readyState !== 'loaded' && + this.readyState !== 'complete') return; + loading = false; + callback(e || fabric.window.event); + scriptEl = scriptEl.onload = scriptEl.onreadystatechange = null; + } + }; + scriptEl.src = url; + headEl.appendChild(scriptEl); + // causes issue in Opera + // headEl.removeChild(scriptEl); } fabric.util.getScript = getScript; @@ -216,5 +217,5 @@ fabric.util.addClass = addClass; fabric.util.wrapElement = wrapElement; fabric.util.getElementOffset = getElementOffset; - + })(); \ No newline at end of file diff --git a/src/util/dom_request.js b/src/util/dom_request.js index d68e5d36..5a53915f 100644 --- a/src/util/dom_request.js +++ b/src/util/dom_request.js @@ -1,9 +1,9 @@ (function(){ - + function addParamToUrl(url, param) { return url + (/\?/.test(url) ? '&' : '?') + param; } - + var makeXHR = (function() { var factories = [ function() { return new ActiveXObject("Microsoft.XMLHTTP"); }, @@ -22,8 +22,8 @@ } })(); - function emptyFn() { }; - + function emptyFn() { } + /** * Cross-browser abstraction for sending XMLHttpRequest * @method request @@ -40,33 +40,33 @@ var method = options.method ? options.method.toUpperCase() : 'GET', onComplete = options.onComplete || function() { }, - request = makeXHR(), + xhr = makeXHR(), body; - + /** @ignore */ - request.onreadystatechange = function() { - if (request.readyState === 4) { - onComplete(request); - request.onreadystatechange = emptyFn; + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + onComplete(xhr); + xhr.onreadystatechange = emptyFn; } }; - + if (method === 'GET') { body = null; - if (typeof options.parameters == 'string') { + if (typeof options.parameters === 'string') { url = addParamToUrl(url, options.parameters); } } - request.open(method, url, true); - + xhr.open(method, url, true); + if (method === 'POST' || method === 'PUT') { - request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); } - request.send(body); - return request; - }; - + xhr.send(body); + return xhr; + } + fabric.util.request = request; })(); \ No newline at end of file diff --git a/src/util/dom_style.js b/src/util/dom_style.js index ee604cf5..e1d1c37a 100644 --- a/src/util/dom_style.js +++ b/src/util/dom_style.js @@ -9,7 +9,7 @@ * @return {HTMLElement} Element that was passed as a first argument */ function setStyle(element, styles) { - var elementStyle = element.style, match; + var elementStyle = element.style; if (!elementStyle) { return element; } @@ -36,8 +36,6 @@ var parseEl = fabric.document.createElement('div'), supportsOpacity = typeof parseEl.style.opacity === 'string', supportsFilters = typeof parseEl.style.filter === 'string', - view = fabric.document.defaultView, - supportsGCS = view && typeof view.getComputedStyle !== 'undefined', reOpacity = /alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/, /** @ignore */ diff --git a/src/util/lang_array.js b/src/util/lang_array.js index 4ebdb3db..0866966a 100644 --- a/src/util/lang_array.js +++ b/src/util/lang_array.js @@ -1,7 +1,7 @@ (function() { - + var slice = Array.prototype.slice; - + if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { if (this === void 0 || this === null) { @@ -31,7 +31,7 @@ } } return -1; - } + }; } if (!Array.prototype.forEach) { @@ -39,7 +39,7 @@ for (var i = 0, len = this.length >>> 0; i < len; i++) { if (i in this) { fn.call(context, this[i], i, this); - } + } } }; } @@ -148,8 +148,8 @@ */ function max(array, byProperty) { if (!array || array.length === 0) return undefined; - - var i = array.length - 1, + + var i = array.length - 1, result = byProperty ? array[i][byProperty] : array[i]; if (byProperty) { while (i--) { @@ -177,8 +177,8 @@ */ function min(array, byProperty) { if (!array || array.length === 0) return undefined; - - var i = array.length - 1, + + var i = array.length - 1, result = byProperty ? array[i][byProperty] : array[i]; if (byProperty) { @@ -204,5 +204,5 @@ min: min, max: max }; - + })(); \ No newline at end of file diff --git a/src/util/lang_class.js b/src/util/lang_class.js index 57b11716..75086960 100644 --- a/src/util/lang_class.js +++ b/src/util/lang_class.js @@ -13,7 +13,7 @@ var addMethods = function(klass, source, parent) { for (var property in source) { - if (property in klass.prototype && typeof klass.prototype[property] == 'function') { + if (property in klass.prototype && typeof klass.prototype[property] === 'function') { klass.prototype[property] = (function(property) { return function() { @@ -26,7 +26,7 @@ if (property !== 'initialize') { return returnValue; } - } + }; })(property); } else { @@ -44,7 +44,7 @@ } }; - function subclass() { }; + function Subclass() { } /** * Helper for creation of "classes" @@ -66,8 +66,8 @@ klass.subclasses = [ ]; if (parent) { - subclass.prototype = parent.prototype; - klass.prototype = new subclass; + Subclass.prototype = parent.prototype; + klass.prototype = new Subclass(); parent.subclasses.push(klass); } for (var i = 0, length = properties.length; i < length; i++) { diff --git a/src/util/lang_function.js b/src/util/lang_function.js index 9a640da9..dc4131e9 100644 --- a/src/util/lang_function.js +++ b/src/util/lang_function.js @@ -1,9 +1,9 @@ (function() { - + var slice = Array.prototype.slice, apply = Function.prototype.apply, - dummy = function() { }; - + Dummy = function() { }; + if (!Function.prototype.bind) { /** * Cross-browser approximation of ES5 Function.prototype.bind (not fully spec conforming) @@ -15,20 +15,20 @@ Function.prototype.bind = function(thisArg) { var fn = this, args = slice.call(arguments, 1), bound; if (args.length) { - bound = function() { - return apply.call(fn, this instanceof dummy ? this : thisArg, args.concat(slice.call(arguments))); + bound = function() { + return apply.call(fn, this instanceof Dummy ? this : thisArg, args.concat(slice.call(arguments))); }; } else { - bound = function() { - return apply.call(fn, this instanceof dummy ? this : thisArg, arguments); + bound = function() { + return apply.call(fn, this instanceof Dummy ? this : thisArg, arguments); }; } - dummy.prototype = this.prototype; - bound.prototype = new dummy; - + Dummy.prototype = this.prototype; + bound.prototype = new Dummy(); + return bound; }; } - + })(); \ No newline at end of file diff --git a/src/util/misc.js b/src/util/misc.js index ef91a29f..fce0d673 100644 --- a/src/util/misc.js +++ b/src/util/misc.js @@ -21,7 +21,7 @@ array.splice(idx, 1); } return array; - }; + } /** * Returns random number between 2 specified ones. @@ -93,19 +93,19 @@ var start = +new Date(), duration = options.duration || 500, - finish = start + duration, time, pos, + finish = start + duration, time, onChange = options.onChange || function() { }, abort = options.abort || function() { return false; }, easing = options.easing || function(t, b, c, d) {return -c * Math.cos(t/d * (Math.PI/2)) + c + b;}, startValue = 'startValue' in options ? options.startValue : 0, - endValue = 'endValue' in options ? options.endValue : 100; + endValue = 'endValue' in options ? options.endValue : 100, byValue = options.byValue || endValue - startValue; options.onStart && options.onStart(); (function tick() { time = +new Date(); - currentTime = time > finish ? duration : (time - start); + var currentTime = time > finish ? duration : (time - start); onChange(easing(currentTime, startValue, byValue, duration)); if (time > finish || abort()) { options.onComplete && options.onComplete(); @@ -120,7 +120,7 @@ fabric.window.mozRequestAnimationFrame || fabric.window.oRequestAnimationFrame || fabric.window.msRequestAnimationFrame || - function(callback, element) { + function(callback) { fabric.window.setTimeout(callback, 1000 / 60); }; /** @@ -193,6 +193,15 @@ }); } + /** + * Groups SVG elements (usually those retrieved from SVG document) + * @static + * @memberOf fabric.util + * @method groupSVGElements + * @param {Array} elements + * @param {Object} options optional + * @return {String} path optional + */ function groupSVGElements(elements, options, path) { var object = elements.length > 1 ? new fabric.PathGroup(elements, options)