diff --git a/dist/all.js b/dist/all.js index bf29bc2a..c5005da1 100644 --- a/dist/all.js +++ b/dist/all.js @@ -1,7 +1,10 @@ /*! Fabric.js Copyright 2010, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ if (typeof console == 'undefined') { - var console = { log: function() { }, warn: function() { } }; + var console = { + log: function() { }, + warn: function() { } + }; } /* @@ -414,10 +417,10 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { (function (global) { - var fabric = this.fabric || (this.fabric = { }); - fabric.base = { }; + var fabric = this.fabric || (this.fabric = { }), + slice = Array.prototype.slice; - var slice = Array.prototype.slice; + fabric.util = { }; if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(value, from) { @@ -574,7 +577,7 @@ function min(array, byProperty) { return result; } -fabric.base.array = { +fabric.util.array = { invoke: invoke, min: min, max: max @@ -590,7 +593,7 @@ function clone(object) { return extend({ }, object); } -fabric.base.object = { +fabric.util.object = { extend: extend, clone: clone }; @@ -610,7 +613,7 @@ function capitalize(string) { return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); } -fabric.base.string = { +fabric.util.string = { camelize: camelize, capitalize: capitalize }; @@ -684,7 +687,7 @@ if (!Function.prototype.bind) { return klass; } - fabric.base.createClass = createClass; + fabric.util.createClass = createClass; })(); (function (global) { @@ -827,8 +830,8 @@ if (!Function.prototype.bind) { }; } - fabric.base.addListener = addListener; - fabric.base.removeListener = removeListener; + fabric.util.addListener = addListener; + fabric.util.removeListener = removeListener; var customEventListeners = { }; @@ -854,8 +857,8 @@ if (!Function.prototype.bind) { } } - fabric.base.observeEvent = observeEvent; - fabric.base.fireEvent = fireEvent; + fabric.util.observeEvent = observeEvent; + fabric.util.fireEvent = fireEvent; function getPointer(event) { return { x: pointerX(event), y: pointerY(event) }; @@ -879,7 +882,7 @@ if (!Function.prototype.bind) { (docElement.clientTop || 0)); } - fabric.base.getPointer = getPointer; + fabric.util.getPointer = getPointer; })(this); (function () { @@ -936,7 +939,7 @@ if (!Function.prototype.bind) { }; } - fabric.base.setStyle = setStyle; + fabric.util.setStyle = setStyle; })(); function getById(id) { @@ -1021,7 +1024,7 @@ function falseFunction() { return false; }; return element; } - fabric.base.makeElementUnselectable = makeElementUnselectable + fabric.util.makeElementUnselectable = makeElementUnselectable })(); (function(){ @@ -1052,11 +1055,11 @@ function falseFunction() { return false; }; callback(); } - fabric.base.getScript = getScript; + fabric.util.getScript = getScript; var Jaxer = this.Jaxer; if (Jaxer && Jaxer.load) { - fabric.base.getScript = getScriptJaxer; + fabric.util.getScript = getScriptJaxer; } })(); @@ -1086,13 +1089,13 @@ function animate(options) { }, 10); } -fabric.base.getById = getById; -fabric.base.toArray = toArray; -fabric.base.makeElement = makeElement; -fabric.base.addClass = addClass; -fabric.base.wrapElement = wrapElement; -fabric.base.getElementOffset = getElementOffset; -fabric.base.animate = animate; +fabric.util.getById = getById; +fabric.util.toArray = toArray; +fabric.util.makeElement = makeElement; +fabric.util.addClass = addClass; +fabric.util.wrapElement = wrapElement; +fabric.util.getElementOffset = getElementOffset; +fabric.util.animate = animate; (function(){ @@ -1153,20 +1156,11 @@ fabric.base.animate = animate; return request; }; - fabric.base.request = request; + fabric.util.request = request; })(); -})(this); - (function(){ - var fabric = this.fabric || (this.fabric = { }); - - if (fabric.util) { - console.warn('fabric.util is already defined'); - return; - } - /** * @static * Removes value from an array. @@ -1216,13 +1210,13 @@ fabric.base.animate = animate; return parseFloat(Number(number).toFixed(fractionDigits)); } - fabric.util = { - removeFromArray: removeFromArray, - degreesToRadians: degreesToRadians, - toFixed: toFixed, - getRandomInt: getRandomInt - }; + fabric.util.removeFromArray = removeFromArray; + fabric.util.degreesToRadians = degreesToRadians; + fabric.util.toFixed = toFixed; + fabric.util.getRandomInt = getRandomInt; })(); + +})(this); (function(){ var fabric = this.fabric || (this.fabric = { }); @@ -1281,8 +1275,8 @@ fabric.base.animate = animate; return memo; }, { }); - ownAttributes = fabric.base.object.extend(fabric.parseStyleAttribute(element), ownAttributes); - return fabric.base.object.extend(parentAttributes, ownAttributes); + ownAttributes = fabric.util.object.extend(fabric.parseStyleAttribute(element), ownAttributes); + return fabric.util.object.extend(parentAttributes, ownAttributes); }; /** @@ -1469,7 +1463,7 @@ fabric.base.animate = animate; */ function parseElements(elements, options) { var _elements = elements.map(function(el) { - var klass = fabric[fabric.base.string.capitalize(el.tagName)]; + var klass = fabric[fabric.util.string.capitalize(el.tagName)]; if (klass && klass.fromElement) { try { return klass.fromElement(el, options); @@ -1519,7 +1513,7 @@ fabric.base.animate = animate; return function(doc, callback) { if (!doc) return; - var descendants = fabric.base.toArray(doc.getElementsByTagName('*')); + var descendants = fabric.util.toArray(doc.getElementsByTagName('*')); var elements = descendants.filter(function(el) { return reAllowedSVGTagNames.test(el.tagName) && @@ -1551,7 +1545,7 @@ fabric.base.animate = animate; height: height }; - var elements = fabric.parseElements(elements, fabric.base.object.clone(options)); + var elements = fabric.parseElements(elements, fabric.util.object.clone(options)); if (!elements || (elements && !elements.length)) return; if (callback) { @@ -1560,7 +1554,7 @@ fabric.base.animate = animate; }; })(); - fabric.base.object.extend(fabric, { + fabric.util.object.extend(fabric, { parseAttributes: parseAttributes, parseElements: parseElements, parseStyleAttribute: parseStyleAttribute, @@ -2080,7 +2074,7 @@ fabric.base.animate = animate; STROKE_OFFSET = 0.5, FX_TRANSITION = 'decel', - getPointer = fabric.base.getPointer, + getPointer = fabric.util.getPointer, cursorMap = { 'tr': 'ne-resize', @@ -2241,7 +2235,7 @@ fabric.base.animate = animate; this.calcOffset(); }; - fabric.base.object.extend(fabric.Element.prototype, { + fabric.util.object.extend(fabric.Element.prototype, { selectionColor: 'rgba(100,100,255,0.3)', // blue selectionBorderColor: 'rgba(255,255,255,0.3)', @@ -2266,7 +2260,7 @@ fabric.base.animate = animate; * @chainable */ calcOffset: function () { - this._offset = fabric.base.getElementOffset(this.getElement()); + this._offset = fabric.util.getElementOffset(this.getElement()); return this; }, @@ -2302,7 +2296,7 @@ fabric.base.animate = animate; * */ _initElement: function (canvasEl) { - var el = fabric.base.getById(canvasEl); + var el = fabric.util.getById(canvasEl); this._oElement = el || document.createElement('canvas'); if (typeof this._oElement.getContext === 'undefined') { @@ -2327,12 +2321,12 @@ fabric.base.animate = animate; * @method _initWrapperElement */ _initWrapperElement: function (width, height) { - var wrapper = fabric.base.wrapElement(this.getElement(), 'div', { className: 'canvas_container' }); - fabric.base.setStyle(wrapper, { + var wrapper = fabric.util.wrapElement(this.getElement(), 'div', { className: 'canvas_container' }); + fabric.util.setStyle(wrapper, { width: width + 'px', height: height + 'px' }); - fabric.base.makeElementUnselectable(wrapper); + fabric.util.makeElementUnselectable(wrapper); this.wrapper = wrapper; }, @@ -2341,7 +2335,7 @@ fabric.base.animate = animate; * @method _setElementStyle */ _setElementStyle: function (width, height) { - fabric.base.setStyle(this.getElement(), { + fabric.util.setStyle(this.getElement(), { position: 'absolute', width: width + 'px', height: height + 'px', @@ -2358,7 +2352,7 @@ fabric.base.animate = animate; * See configuration documentation for more details. */ _initConfig: function (oConfig) { - fabric.base.object.extend(this._oConfig, oConfig || { }); + fabric.util.object.extend(this._oConfig, oConfig || { }); this._oConfig.width = parseInt(this._oElement.width, 10) || 0; this._oConfig.height = parseInt(this._oElement.height, 10) || 0; @@ -2382,10 +2376,10 @@ fabric.base.animate = animate; this._onMouseMove = function (e){ _this.__onMouseMove(e); }; this._onResize = function (e) { _this.calcOffset() }; - fabric.base.addListener(this._oElement, 'mousedown', this._onMouseDown); - fabric.base.addListener(document, 'mousemove', this._onMouseMove); - fabric.base.addListener(document, 'mouseup', this._onMouseUp); - fabric.base.addListener(window, 'resize', this._onResize); + fabric.util.addListener(this._oElement, 'mousedown', this._onMouseDown); + fabric.util.addListener(document, 'mousemove', this._onMouseMove); + fabric.util.addListener(document, 'mouseup', this._onMouseUp); + fabric.util.addListener(window, 'resize', this._onResize); }, /** @@ -2417,7 +2411,7 @@ fabric.base.animate = animate; if (typeof element.getContext === 'undefined') { throw CANVAS_INIT_ERROR; } - fabric.base.makeElementUnselectable(oContainer); + fabric.util.makeElementUnselectable(oContainer); return oContainer; }, @@ -2529,7 +2523,7 @@ fabric.base.animate = animate; target = transform.target; if (target.__scaling) { - fabric.base.fireEvent('object:scaled', { target: target }); + fabric.util.fireEvent('object:scaled', { target: target }); target.__scaling = false; } @@ -2539,7 +2533,7 @@ fabric.base.animate = animate; if (target.hasStateChanged()) { target.isMoving = false; - fabric.base.fireEvent('object:modified', { target: target }); + fabric.util.fireEvent('object:modified', { target: target }); } } @@ -2552,7 +2546,7 @@ fabric.base.animate = animate; if (activeGroup) { if (activeGroup.hasStateChanged() && activeGroup.containsPoint(this.getPointer(e))) { - fabric.base.fireEvent('group:modified', { target: activeGroup }); + fabric.util.fireEvent('group:modified', { target: activeGroup }); } activeGroup.setObjectsCoords(); activeGroup.set('isMoving', false); @@ -2653,15 +2647,15 @@ fabric.base.animate = animate; deactivateAllWithDispatch: function () { var activeGroup = this.getActiveGroup(); if (activeGroup) { - fabric.base.fireEvent('before:group:destroyed', { + fabric.util.fireEvent('before:group:destroyed', { target: activeGroup }); } this.deactivateAll(); if (activeGroup) { - fabric.base.fireEvent('after:group:destroyed'); + fabric.util.fireEvent('after:group:destroyed'); } - fabric.base.fireEvent('selection:cleared'); + fabric.util.fireEvent('selection:cleared'); return this; }, @@ -2722,7 +2716,7 @@ fabric.base.animate = animate; else { activeGroup.add(target); } - fabric.base.fireEvent('group:selected', { target: activeGroup }); + fabric.util.fireEvent('group:selected', { target: activeGroup }); activeGroup.setActive(true); } else { @@ -2970,7 +2964,7 @@ fabric.base.animate = animate; } if (group.length === 1) { this.setActiveObject(group[0]); - fabric.base.fireEvent('object:selected', { + fabric.util.fireEvent('object:selected', { target: group[0] }); } @@ -2978,7 +2972,7 @@ fabric.base.animate = animate; var group = new fabric.Group(group); this.setActiveGroup(group); group.saveCoords(); - fabric.base.fireEvent('group:selected', { target: group }); + fabric.util.fireEvent('group:selected', { target: group }); } this.renderAll(); }, @@ -3508,7 +3502,7 @@ fabric.base.animate = animate; switch (o.type) { case 'image': case 'font': - fabric[fabric.base.string.capitalize(o.type)].fromObject(o, function (o) { + fabric[fabric.util.string.capitalize(o.type)].fromObject(o, function (o) { _this.add(o); if (++numLoadedImages === numTotalImages) { if (callback) callback(); @@ -3516,7 +3510,7 @@ fabric.base.animate = animate; }); break; default: - var klass = fabric[fabric.base.string.camelize(fabric.base.string.capitalize(o.type))]; + var klass = fabric[fabric.util.string.camelize(fabric.util.string.capitalize(o.type))]; if (klass && klass.fromObject) { _this.add(klass.fromObject(o)); } @@ -3589,7 +3583,7 @@ fabric.base.animate = animate; _this.loadImageFromURL(path, function (image) { image.setSourcePath(path); - fabric.base.object.extend(image, obj); + fabric.util.object.extend(image, obj); image.setAngle(obj.angle); onObjectLoaded(image, index); @@ -3611,7 +3605,7 @@ fabric.base.animate = animate; } } - fabric.base.getScript(path, onscriptload); + fabric.util.getScript(path, onscriptload); } else { _this.loadSVGFromURL(path, function (elements, options) { @@ -3624,7 +3618,7 @@ fabric.base.animate = animate; object.setSourcePath(path); if (!(object instanceof fabric.PathGroup)) { - fabric.base.object.extend(object, obj); + fabric.util.object.extend(object, obj); if (typeof obj.angle !== 'undefined') { object.setAngle(obj.angle); } @@ -3873,7 +3867,7 @@ fabric.base.animate = animate; this.renderAll(); - fabric.base.fireEvent('object:selected', { target: object }); + fabric.util.fireEvent('object:selected', { target: object }); return this; }, @@ -3980,10 +3974,10 @@ fabric.base.animate = animate; */ dispose: function () { this.clear(); - fabric.base.removeListener(this.getElement(), 'mousedown', this._onMouseDown); - fabric.base.removeListener(document, 'mouseup', this._onMouseUp); - fabric.base.removeListener(document, 'mousemove', this._onMouseMove); - fabric.base.removeListener(window, 'resize', this._onResize); + fabric.util.removeListener(this.getElement(), 'mousedown', this._onMouseDown); + fabric.util.removeListener(document, 'mouseup', this._onMouseUp); + fabric.util.removeListener(document, 'mousemove', this._onMouseMove); + fabric.util.removeListener(window, 'resize', this._onResize); return this; }, @@ -4049,7 +4043,7 @@ fabric.base.animate = animate; '{ objects: ' + this.getObjects().length + ' }>'; }; - fabric.base.object.extend(fabric.Element, { + fabric.util.object.extend(fabric.Element, { /** * @property EMPTY_JSON @@ -4139,7 +4133,7 @@ fabric.base.animate = animate; * @class Object * @memberOf Canvas */ - fabric.Object = fabric.base.createClass({ + fabric.Object = fabric.util.createClass({ type: 'object', @@ -4221,7 +4215,7 @@ fabric.base.animate = animate; }, setOptions: function(options) { - this.options = fabric.base.object.extend(this._getOptions(), options); + this.options = fabric.util.object.extend(this._getOptions(), options); }, /** @@ -4229,7 +4223,7 @@ fabric.base.animate = animate; * @method _getOptions */ _getOptions: function() { - return fabric.base.object.extend(fabric.base.object.clone(this._getSuperOptions()), this.options); + return fabric.util.object.extend(fabric.util.object.clone(this._getSuperOptions()), this.options); }, /** @@ -4361,7 +4355,7 @@ fabric.base.animate = animate; * @return {String} */ toString: function() { - return "#"; + return "#"; }, /** @@ -4771,7 +4765,7 @@ fabric.base.animate = animate; el.width = this.getWidth(); el.height = this.getHeight(); - fabric.base.wrapElement(el, 'div'); + fabric.util.wrapElement(el, 'div'); var canvas = new fabric.Element(el); canvas.backgroundColor = 'transparent'; @@ -4897,7 +4891,7 @@ fabric.base.animate = animate; * @return {String|Boolean} corner code (tl, tr, bl, br, etc.), or false if nothing is found */ _findTargetCorner: function(e, offset) { - var pointer = fabric.base.getPointer(e), + var pointer = fabric.util.getPointer(e), ex = pointer.x - offset.left, ey = pointer.y - offset.top, xpoints, @@ -5262,7 +5256,7 @@ fabric.base.animate = animate; onChange = callbacks.onChange || empty, _this = this; - fabric.base.animate({ + fabric.util.animate({ startValue: this.get('angle'), endValue: this._getAngleValueForStraighten(), duration: this.FX_DURATION, @@ -5296,7 +5290,7 @@ fabric.base.animate = animate; onChange = callbacks.onChange || empty, _this = this; - fabric.base.animate({ + fabric.util.animate({ startValue: this.get('opacity'), endValue: 0, duration: this.FX_DURATION, @@ -5347,7 +5341,7 @@ fabric.base.animate = animate; return; } - fabric.Line = fabric.base.createClass(fabric.Object, { + fabric.Line = fabric.util.createClass(fabric.Object, { type: 'line', @@ -5401,7 +5395,7 @@ fabric.base.animate = animate; * @return {Object} */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { x1: this.get('x1'), y1: this.get('y1'), x2: this.get('x2'), @@ -5427,7 +5421,7 @@ fabric.base.animate = animate; parsedAttributes.x2 || 0, parsedAttributes.y2 || 0 ]; - return new fabric.Line(points, fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Line(points, fabric.util.object.extend(parsedAttributes, options)); }; /** @@ -5453,7 +5447,7 @@ fabric.base.animate = animate; return; } - fabric.Circle = fabric.base.createClass(fabric.Object, /** @lends fabric.Circle.prototype */ { + fabric.Circle = fabric.util.createClass(fabric.Object, /** @lends fabric.Circle.prototype */ { /** * @field @@ -5482,7 +5476,7 @@ fabric.base.animate = animate; * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { radius: this.get('radius') }); }, @@ -5531,7 +5525,7 @@ fabric.base.animate = animate; if (!isValidRadius(parsedAttributes)) { throw Error('value of `r` attribute is required and can not be negative'); } - return new fabric.Circle(fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Circle(fabric.util.object.extend(parsedAttributes, options)); }; /** @@ -5561,7 +5555,7 @@ fabric.base.animate = animate; return; } - fabric.Ellipse = fabric.base.createClass(fabric.Object, { + fabric.Ellipse = fabric.util.createClass(fabric.Object, { type: 'ellipse', @@ -5589,7 +5583,7 @@ fabric.base.animate = animate; * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { rx: this.get('rx'), ry: this.get('ry') }) @@ -5644,7 +5638,7 @@ fabric.base.animate = animate; */ fabric.Ellipse.fromElement = function(element, options) { var parsedAttributes = fabric.parseAttributes(element, fabric.Ellipse.ATTRIBUTE_NAMES); - return new fabric.Ellipse(fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Ellipse(fabric.util.object.extend(parsedAttributes, options)); }; /** @@ -5670,7 +5664,7 @@ fabric.base.animate = animate; * @class Rect * @extends fabric.Object */ - fabric.Rect = fabric.base.createClass(fabric.Object, /** @lends fabric.Rect.prototype */ { + fabric.Rect = fabric.util.createClass(fabric.Object, /** @lends fabric.Rect.prototype */ { type: 'rect', @@ -5781,7 +5775,7 @@ fabric.base.animate = animate; var parsedAttributes = fabric.parseAttributes(element, fabric.Rect.ATTRIBUTE_NAMES); parsedAttributes = _setDefaultLeftTopValues(parsedAttributes); - var rect = new fabric.Rect(fabric.base.object.extend(options || { }, parsedAttributes)); + var rect = new fabric.Rect(fabric.util.object.extend(options || { }, parsedAttributes)); rect._normalizeLeftTopProperties(parsedAttributes); return rect; @@ -5807,7 +5801,7 @@ fabric.base.animate = animate; return; } - fabric.Polyline = fabric.base.createClass(fabric.Object, { + fabric.Polyline = fabric.util.createClass(fabric.Object, { type: 'polyline', @@ -5895,7 +5889,7 @@ fabric.base.animate = animate; var points = fabric.parsePointsAttribute(element.getAttribute('points')), parsedAttributes = fabric.parseAttributes(element, ATTRIBUTE_NAMES); - return new fabric.Polyline(points, fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Polyline(points, fabric.util.object.extend(parsedAttributes, options)); }; /** @@ -5922,7 +5916,7 @@ fabric.base.animate = animate; function byX(p) { return p.x; } function byY(p) { return p.y; } - fabric.Polygon = fabric.base.createClass(fabric.Object, { + fabric.Polygon = fabric.util.createClass(fabric.Object, { type: 'polygon', @@ -5947,10 +5941,10 @@ fabric.base.animate = animate; _calcDimensions: function() { var points = this.points, - minX = fabric.base.array.min(points, 'x'), - minY = fabric.base.array.min(points, 'y'), - maxX = fabric.base.array.max(points, 'x'), - maxY = fabric.base.array.max(points, 'y'); + minX = fabric.util.array.min(points, 'x'), + minY = fabric.util.array.min(points, 'y'), + maxX = fabric.util.array.max(points, 'x'), + maxY = fabric.util.array.max(points, 'y'); this.width = maxX - minX; this.height = maxY - minY; @@ -5977,7 +5971,7 @@ fabric.base.animate = animate; * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { points: this.points.concat() }); }, @@ -6029,7 +6023,7 @@ fabric.base.animate = animate; var points = fabric.parsePointsAttribute(element.getAttribute('points')), parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES); - return new fabric.Polygon(points, fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Polygon(points, fabric.util.object.extend(parsedAttributes, options)); }; /** @@ -6057,7 +6051,7 @@ fabric.base.animate = animate; return; } - fabric.Path = fabric.base.createClass(fabric.Object, { + fabric.Path = fabric.util.createClass(fabric.Object, { type: 'path', @@ -6105,7 +6099,7 @@ fabric.base.animate = animate; this.path = this._parsePath(); if (!isWidthSet || !isHeightSet) { - fabric.base.object.extend(this, this._parseDimensions()); + fabric.util.object.extend(this, this._parseDimensions()); if (isWidthSet) { this.width = this.options.width; } @@ -6354,7 +6348,7 @@ fabric.base.animate = animate; * @return {Object} */ toObject: function() { - var o = fabric.base.object.extend(this.callSuper('toObject'), { + var o = fabric.util.object.extend(this.callSuper('toObject'), { path: this.path }); if (this.sourcePath) { @@ -6458,15 +6452,15 @@ fabric.base.animate = animate; }, this); - var minX = fabric.base.array.min(aX), - minY = fabric.base.array.min(aY), + var minX = fabric.util.array.min(aX), + minY = fabric.util.array.min(aY), deltaX = deltaY = 0; var o = { top: minY - deltaY, left: minX - deltaX, - bottom: fabric.base.array.max(aY) - deltaY, - right: fabric.base.array.max(aX) - deltaX + bottom: fabric.util.array.max(aY) - deltaY, + right: fabric.util.array.max(aX) - deltaX }; o.width = o.right - o.left; @@ -6499,7 +6493,7 @@ fabric.base.animate = animate; var parsedAttributes = fabric.parseAttributes(element, ATTRIBUTE_NAMES), path = parsedAttributes.d; delete parsedAttributes.d; - return new fabric.Path(path, fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Path(path, fabric.util.object.extend(parsedAttributes, options)); } })(); @@ -6512,7 +6506,7 @@ fabric.base.animate = animate; return; } - fabric.PathGroup = fabric.base.createClass(fabric.Path, { + fabric.PathGroup = fabric.util.createClass(fabric.Path, { type: 'path-group', forceFillOverwrite: false, @@ -6606,8 +6600,8 @@ fabric.base.animate = animate; */ toObject: function() { var _super = fabric.Object.prototype.toObject; - return fabric.base.object.extend(_super.call(this), { - paths: fabric.base.array.invoke(this.getObjects(), 'clone'), + return fabric.util.object.extend(_super.call(this), { + paths: fabric.util.array.invoke(this.getObjects(), 'clone'), sourcePath: this.sourcePath }); }, @@ -6712,7 +6706,7 @@ fabric.base.animate = animate; return; } - fabric.Group = fabric.base.createClass(fabric.Object, { + fabric.Group = fabric.util.createClass(fabric.Object, { /** * @property type @@ -6734,7 +6728,7 @@ fabric.base.animate = animate; this._updateObjectsCoords(); if (options) { - fabric.base.object.extend(this, options); + fabric.util.object.extend(this, options); } this._setOpacityIfSame(); @@ -6867,8 +6861,8 @@ fabric.base.animate = animate; * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { - objects: fabric.base.array.invoke(this.objects, 'clone') + return fabric.util.object.extend(this.callSuper('toObject'), { + objects: fabric.util.array.invoke(this.objects, 'clone') }); }, @@ -7079,10 +7073,10 @@ fabric.base.animate = animate; } }; - minX = fabric.base.array.min(aX); - maxX = fabric.base.array.max(aX); - minY = fabric.base.array.min(aY); - maxY = fabric.base.array.max(aY); + minX = fabric.util.array.min(aX); + maxX = fabric.util.array.max(aX); + minY = fabric.util.array.min(aY); + maxY = fabric.util.array.max(aY); width = maxX - minX; height = maxY - minY; @@ -7146,7 +7140,7 @@ fabric.base.animate = animate; return; } - fabric.Text = fabric.base.createClass(fabric.Object, { + fabric.Text = fabric.util.createClass(fabric.Object, { options: { top: 10, @@ -7164,7 +7158,7 @@ fabric.base.animate = animate; this.initStateProperties(); this.text = text; this.setOptions(options); - fabric.base.object.extend(this, this.options); + fabric.util.object.extend(this, this.options); this.theta = this.angle * (Math.PI/180); this.width = this.getWidth(); this.setCoords(); @@ -7238,7 +7232,7 @@ fabric.base.animate = animate; * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { text: this.text, fontsize: this.fontsize, fontweight: this.fontweight, @@ -7305,7 +7299,7 @@ fabric.base.animate = animate; * @return {fabric.Text} an instance */ fabric.Text.fromObject = function(object) { - return new fabric.Text(object.text, fabric.base.object.clone(object)); + return new fabric.Text(object.text, fabric.util.object.clone(object)); }; /** @@ -7337,7 +7331,7 @@ fabric.base.animate = animate; } - fabric.Image = fabric.base.createClass(fabric.Object, { + fabric.Image = fabric.util.createClass(fabric.Object, { maxwidth: null, maxheight: null, @@ -7460,7 +7454,7 @@ fabric.base.animate = animate; * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { src: this.getSrc() }); }, @@ -7570,8 +7564,8 @@ fabric.base.animate = animate; * @param {HTMLImageElement|String} el The element representing the image */ _initElement: function(element) { - this.setElement(fabric.base.getById(element)); - fabric.base.addClass(this.getElement(), fabric.Image.CSS_CANVAS); + this.setElement(fabric.util.getById(element)); + fabric.util.addClass(this.getElement(), fabric.Image.CSS_CANVAS); }, /** diff --git a/dist/all.min.js b/dist/all.min.js index 9047065b..77e4f4a6 100644 --- a/dist/all.min.js +++ b/dist/all.min.js @@ -1,2 +1,2 @@ /* Fabric.js Copyright 2010, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -if(typeof console=="undefined"){var console={log:function(){},warn:function(){}}}if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i>>0;w=Number(w)||0;w=Math[w<0?"ceil":"floor"](w);if(w<0){w+=u}for(;w>>0;v>>0;w>>0;v>>0;v>>0;w>>0,v=0,x;if(arguments.length>1){x=arguments[1]}else{do{if(v in this){x=this[v++];break}if(++v>=u){throw new TypeError()}}while(true)}for(;v=u){u=x[v][w]}}}else{while(v--){if(x[v]>=u){u=x[v]}}}return u}function l(x,w){var v=x.length-1,u=w?x[v][w]:x[v];if(w){while(v--){if(x[v][w]-1?w(D,F.match(/opacity:\s*(\d?\.?\d*)/)[1]):D}for(var G in F){if(G==="opacity"){w(D,F[G])}else{var E=(G==="float"||G==="cssFloat")?(typeof H.styleFloat==="undefined"?"cssFloat":"styleFloat"):G;H[E]=F[G]}}return D}var B=document.createElement("div"),A=typeof B.style.opacity==="string",v=typeof B.style.filter==="string",u=document.defaultView,z=u&&typeof u.getComputedStyle!=="undefined",x=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,w=function(C){return C};if(A){w=function(C,D){C.style.opacity=D;return C}}else{if(v){w=function(C,D){var E=C.style;if(C.currentStyle&&!C.currentStyle.hasLayout){E.zoom=1}if(x.test(E.filter)){D=D>=0.9999?"":("alpha(opacity="+(D*100)+")");E.filter=E.filter.replace(x,D)}else{E.filter+=" alpha(opacity="+(D*100)+")"}return C}}}g.base.setStyle=y})();function p(u){return typeof u==="string"?document.getElementById(u):u}function n(v){var u=[],w=v.length;while(w--){u[w]=v[w]}return u}function b(v,u){var w=document.createElement(v);for(var x in u){if(x==="class"){x="className"}else{if(x==="for"){x="htmlFor"}}w.setAttribute(x,u[x])}return w}function f(u,v){if((" "+u.className+" ").indexOf(" "+v+" ")===-1){u.className+=(u.className?" ":"")+v}}function a(v,w,u){if(typeof w==="string"){w=b(w,u)}if(v.parentNode){v.parentNode.replaceChild(w,v)}w.appendChild(v);return w}function k(v){var u=0,w=0;do{u+=v.offsetTop||0;w+=v.offsetLeft||0;v=v.offsetParent}while(v);return({left:w,top:u})}function e(){return false}(function(){var u=document.documentElement.style;var v="userSelect" in u?"userSelect":"MozUserSelect" in u?"MozUserSelect":"WebkitUserSelect" in u?"WebkitUserSelect":"KhtmlUserSelect" in u?"KhtmlUserSelect":"";function w(x){if(typeof x.onselectstart!=="undefined"){x.onselectstart=e}if(v){x.style[v]="none"}else{if(typeof x.unselectable=="string"){x.unselectable="on"}}return x}g.base.makeElementUnselectable=w})();(function(){function u(x,B){var z=document.getElementsByTagName("head")[0],y=document.createElement("script"),A=true;y.type="text/javascript";y.setAttribute("runat","server");y.onload=y.onreadystatechange=function(C){if(A){if(typeof this.readyState=="string"&&this.readyState!=="loaded"&&this.readyState!=="complete"){return}A=false;B(C||window.event);y=y.onload=y.onreadystatechange=null}};y.src=x;z.appendChild(y)}function w(x,y){v.load(x);y()}g.base.getScript=u;var v=this.Jaxer;if(v&&v.load){g.base.getScript=w}})();function c(F){F||(F={});var v=+new Date(),z=F.duration||500,E=v+z,y,D,A=F.onChange||function(){},B=F.easing||function(G){return(-Math.cos(G*Math.PI)/2)+0.5},u="startValue" in F?F.startValue:0,C="endValue" in F?F.endValue:100,x=u>C;F.onStart&&F.onStart();var w=setInterval(function(){y=+new Date();D=y>E?1:(y-v)/z;A(x?(u-(u-C)*B(D)):(u+(C-u)*B(D)));if(y>E){clearInterval(w);F.onComplete&&F.onComplete()}},10)}g.base.getById=p;g.base.toArray=n;g.base.makeElement=b;g.base.addClass=f;g.base.wrapElement=a;g.base.getElementOffset=k;g.base.animate=c;(function(){function x(y,z){return y+(/\?/.test(y)?"&":"?")+z}var w=(function(){var B=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest()}];for(var y=B.length;y--;){try{var A=B[y]();if(A){return B[y]}}catch(z){}}})();function u(){}function v(A,z){z||(z={});var D=z.method?z.method.toUpperCase():"GET",C=z.onComplete||function(){},B=w(),y;B.onreadystatechange=function(){if(B.readyState===4){C(B);B.onreadystatechange=u}};if(D==="GET"){y=null;if(typeof z.parameters=="string"){A=x(A,z.parameters)}}B.open(D,A,true);if(D==="POST"||D==="PUT"){B.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}B.send(y);return B}g.base.request=v})()})(this);(function(){var e=this.fabric||(this.fabric={});if(e.util){console.warn("fabric.util is already defined");return}function f(k,h){var g=k.indexOf(h);if(g!==-1){k.splice(g,1)}return k}function d(h,g){return Math.floor(Math.random()*(g-h+1))+h}var b=Math.PI/180;function c(g){return g*b}function a(h,g){return parseFloat(Number(h).toFixed(g))}e.util={removeFromArray:f,degreesToRadians:c,toFixed:a,getRandomInt:d}})();(function(){var f=this.fabric||(this.fabric={});var c={cx:"left",x:"left",cy:"top",y:"top",r:"radius","fill-opacity":"opacity","fill-rule":"fillRule","stroke-width":"strokeWidth",transform:"transformMatrix"};function b(l,k){if(!l){return}var n,h,g={};if(l.parentNode&&/^g$/i.test(l.parentNode.nodeName)){g=f.parseAttributes(l.parentNode,k)}var m=k.reduce(function(p,o){n=l.getAttribute(o);h=parseFloat(n);if(n){if((o==="fill"||o==="stroke")&&n==="none"){n=""}if(o==="fill-rule"){n=(n==="evenodd")?"destination-over":n}if(o==="transform"){n=f.parseTransformAttribute(n)}if(o in c){o=c[o]}p[o]=isNaN(h)?n:h}return p},{});m=f.base.object.extend(f.parseStyleAttribute(l),m);return f.base.object.extend(g,m)}f.parseTransformAttribute=(function(){function g(B,C){var D=C[0];B[0]=Math.cos(D);B[1]=Math.sin(D);B[2]=-Math.sin(D);B[3]=Math.cos(D)}function n(D,E){var C=E[0],B=(E.length===2)?E[1]:E[0];D[0]=C;D[3]=B}function y(B,C){B[2]=C[0]}function k(B,C){B[1]=C[0]}function v(B,C){B[4]=C[0];if(C.length===2){B[5]=C[1]}}var p=[1,0,0,1,0,0],h="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)",z="(?:\\s+,?\\s*|,\\s*)",q="(?:(skewX)\\s*\\(\\s*("+h+")\\s*\\))",o="(?:(skewY)\\s*\\(\\s*("+h+")\\s*\\))",x="(?:(rotate)\\s*\\(\\s*("+h+")(?:"+z+"("+h+")"+z+"("+h+"))?\\s*\\))",A="(?:(scale)\\s*\\(\\s*("+h+")(?:"+z+"("+h+"))?\\s*\\))",t="(?:(translate)\\s*\\(\\s*("+h+")(?:"+z+"("+h+"))?\\s*\\))",w="(?:(matrix)\\s*\\(\\s*("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")\\s*\\))",u="(?:"+w+"|"+t+"|"+A+"|"+x+"|"+q+"|"+o+")",r="(?:"+u+"(?:"+z+u+")*)",l="^\\s*(?:"+r+"?)\\s*$",s=new RegExp(l),m=new RegExp(u);return function(C){var B=p.concat();if(!C||(C&&!s.test(C))){return B}C.replace(m,function(G){var D=new RegExp(u).exec(G).filter(function(H){return(H!==""&&H!=null)}),E=D[1],F=D.slice(2).map(parseFloat);switch(E){case"translate":v(B,F);break;case"rotate":g(B,F);break;case"scale":n(B,F);break;case"skewX":y(B,F);break;case"skewY":k(B,F);break;case"matrix":B=F;break}});return B}})();function a(h){if(!h){return null}h=h.trim().split(/\s+/);var g=h.reduce(function(k,l){l=l.split(",");k.push({x:parseFloat(l[0]),y:parseFloat(l[1])});return k},[]);if(g.length%2!==0){}return g}function e(h){var g={},k=h.getAttribute("style");if(k){if(typeof k=="string"){k=k.split(";");k.pop();g=k.reduce(function(n,q){var m=q.split(":"),o=m[0].trim(),p=m[1].trim();n[o]=p;return n},{})}else{for(var l in k){if(typeof k[l]!=="undefined"){g[l]=k[l]}}}}return g}function d(h,g){var k=h.map(function(m){var l=f[f.base.string.capitalize(m.tagName)];if(l&&l.fromElement){try{return l.fromElement(m,g)}catch(n){console.log(n.message||n)}}});k=k.filter(function(l){return l!=null});return k}f.parseSVGDocument=(function(){var g=/^(path|circle|polygon|polyline|ellipse|rect|line)$/;var k="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)";var l=new RegExp("^\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*$");function h(m,n){while(m&&(m=m.parentNode)){if(m.nodeName===n){return true}}return false}return function(u,w){if(!u){return}var t=f.base.toArray(u.getElementsByTagName("*"));var m=t.filter(function(y){return g.test(y.tagName)&&!h(y,"pattern")});if(!m||(m&&!m.length)){return}var n=u.getAttribute("viewBox"),r=u.getAttribute("width"),p=u.getAttribute("height"),o=null,v=null,s,q;if(n&&(n=n.match(l))){s=parseInt(n[1],10);q=parseInt(n[2],10);o=parseInt(n[3],10);v=parseInt(n[4],10)}o=r?parseFloat(r):o;v=p?parseFloat(p):v;var x={width:o,height:v};var m=f.parseElements(m,f.base.object.clone(x));if(!m||(m&&!m.length)){return}if(w){w(m,x)}}})();f.base.object.extend(f,{parseAttributes:b,parseElements:d,parseStyleAttribute:e,parsePointsAttribute:a})})();(function(){var b=this.fabric||(this.fabric={});if(b.Point){console.warn("fabric.Point is already defined");return}function a(c,d){if(arguments.length>0){this.init(c,d)}}a.prototype={constructor:a,init:function(c,d){this.x=c;this.y=d},add:function(c){return new a(this.x+c.x,this.y+c.y)},addEquals:function(c){this.x+=c.x;this.y+=c.y;return this},scalarAdd:function(c){return new a(this.x+c,this.y+c)},scalarAddEquals:function(c){this.x+=c;this.y+=c;return this},subtract:function(c){return new a(this.x-c.x,this.y-c.y)},subtractEquals:function(c){this.x-=c.x;this.y-=c.y;return this},scalarSubtract:function(c){return new a(this.x-c,this.y-c)},scalarSubtractEquals:function(c){this.x-=c;this.y-=c;return this},multiply:function(c){return new a(this.x*c,this.y*c)},multiplyEquals:function(c){this.x*=c;this.y*=c;return this},divide:function(c){return new a(this.x/c,this.y/c)},divideEquals:function(c){this.x/=c;this.y/=c;return this},eq:function(c){return(this.x==c.x&&this.y==c.y)},lt:function(c){return(this.xc.x&&this.y>c.y)},gte:function(c){return(this.x>=c.x&&this.y>=c.y)},lerp:function(d,c){return new a(this.x+(d.x-this.x)*c,this.y+(d.y-this.y)*c)},distanceFrom:function(e){var d=this.x-e.x,c=this.y-e.y;return Math.sqrt(d*d+c*c)},min:function(c){return new a(Math.min(this.x,c.x),Math.min(this.y,c.y))},max:function(c){return new a(Math.max(this.x,c.x),Math.max(this.y,c.y))},toString:function(){return this.x+","+this.y},setXY:function(c,d){this.x=c;this.y=d},setFromPoint:function(c){this.x=c.x;this.y=c.y},swap:function(d){var c=this.x,e=this.y;this.x=d.x;this.y=d.y;d.x=c;d.y=e}};b.Point=a})();(function(){var a=this,b=a.fabric||(a.fabric={});if(b.Intersection){console.warn("fabric.Intersection is already defined");return}function c(d){if(arguments.length>0){this.init(d)}}c.prototype.init=function(d){this.status=d;this.points=[]};c.prototype.appendPoint=function(d){this.points.push(d)};c.prototype.appendPoints=function(d){this.points=this.points.concat(d)};c.intersectLineLine=function(h,f,n,m){var o,k=(m.x-n.x)*(h.y-n.y)-(m.y-n.y)*(h.x-n.x),l=(f.x-h.x)*(h.y-n.y)-(f.y-h.y)*(h.x-n.x),g=(m.y-n.y)*(f.x-h.x)-(m.x-n.x)*(f.y-h.y);if(g!=0){var e=k/g,d=l/g;if(0<=e&&e<=1&&0<=d&&d<=1){o=new c("Intersection");o.points.push(new b.Point(h.x+e*(f.x-h.x),h.y+e*(f.y-h.y)))}else{o=new c("No Intersection")}}else{if(k==0||l==0){o=new c("Coincident")}else{o=new c("Parallel")}}return o};c.intersectLinePolygon=function(e,d,m){var n=new c("No Intersection"),f=m.length;for(var h=0;h0){n.status="Intersection"}return n};c.intersectPolygonPolygon=function(k,h){var f=new c("No Intersection"),m=k.length;for(var l=0;l0){f.status="Intersection"}return f};c.intersectPolygonRectangle=function(p,e,d){var g=e.min(d),o=e.max(d),f=new b.Point(o.x,g.y),n=new b.Point(g.x,o.y),m=c.intersectLinePolygon(g,f,p),l=c.intersectLinePolygon(f,o,p),k=c.intersectLinePolygon(o,n,p),h=c.intersectLinePolygon(n,g,p),q=new c("No Intersection");q.appendPoints(m.points);q.appendPoints(l.points);q.appendPoints(k.points);q.appendPoints(h.points);if(q.points.length>0){q.status="Intersection"}return q};b.Intersection=c})();(function(){var a=this.fabric||(this.fabric={});if(a.Color){console.warn("fabric.Color is already defined.");return}a.Color=b;function b(c){if(!c){this.setSource([0,0,0,1])}else{this._tryParsingColor(c)}}b.prototype._tryParsingColor=function(c){var d=b.sourceFromHex(c);if(!d){d=b.sourceFromRgb(c)}if(d){this.setSource(d)}};b.prototype.getSource=function(){return this._source};b.prototype.setSource=function(c){this._source=c};b.prototype.toRgb=function(){var c=this.getSource();return"rgb("+c[0]+","+c[1]+","+c[2]+")"};b.prototype.toRgba=function(){var c=this.getSource();return"rgba("+c[0]+","+c[1]+","+c[2]+","+c[3]+")"};b.prototype.toHex=function(){var f=this.getSource();var e=f[0].toString(16);e=(e.length==1)?("0"+e):e;var d=f[1].toString(16);d=(d.length==1)?("0"+d):d;var c=f[2].toString(16);c=(c.length==1)?("0"+c):c;return e.toUpperCase()+d.toUpperCase()+c.toUpperCase()};b.prototype.getAlpha=function(){return this.getSource()[3]};b.prototype.setAlpha=function(d){var c=this.getSource();c[3]=d;this.setSource(c);return this};b.prototype.toGrayscale=function(){var e=this.getSource(),d=parseInt((e[0]*0.3+e[1]*0.59+e[2]*0.11).toFixed(0),10),c=e[3];this.setSource([d,d,d,c]);return this};b.prototype.toBlackWhite=function(c){var f=this.getSource(),e=(f[0]*0.3+f[1]*0.59+f[2]*0.11).toFixed(0),d=f[3],c=c||127;e=(Number(e)0)?0:-s),this._groupSelector.ey-((r>0)?0:-r),q,p);this._oContextTop.lineWidth=this.selectionLineWidth;this._oContextTop.strokeStyle=this.selectionBorderColor;this._oContextTop.strokeRect(this._groupSelector.ex+a-((s>0)?0:q),this._groupSelector.ey+a-((r>0)?0:p),q,p)},_findSelectedObjects:function(v){var w,r,B=[],q=this._groupSelector.ex,A=this._groupSelector.ey,p=q+this._groupSelector.left,y=A+this._groupSelector.top,x,u=new fabric.Point(Math.min(q,p),Math.min(A,y)),z=new fabric.Point(Math.max(q,p),Math.max(A,y));for(var s=0,t=this._aObjects.length;s1){var B=new fabric.Group(B);this.setActiveGroup(B);B.saveCoords();fabric.base.fireEvent("group:selected",{target:B})}}this.renderAll()},add:function(){this._aObjects.push.apply(this._aObjects,arguments);this.renderAll();return this},insertAt:function(q,p){this._aObjects.splice(p,0,q);this.renderAll();return this},getObjects:function(){return this._aObjects},getContext:function(){return this._oContextTop},clearContext:b,clear:function(){this._aObjects.length=0;this.clearContext(this._oContextTop);this.clearContext(this._oContextContainer);this.renderAll();return this},renderAll:function(q){var p=this._oConfig.width,t=this._oConfig.height;var x=q?this._oContextTop:this._oContextContainer;this.clearContext(this._oContextTop);if(x!==this._oContextTop){this.clearContext(x)}if(q){if(!n&&this.backgroundColor==="transparent"){var v=true}if(!v){x.fillStyle=this.backgroundColor}x.fillRect(0,0,p,t)}var u=this._aObjects.length,s=this.getActiveGroup();if(u){for(var r=0;r1){var D=new fabric.PathGroup(F,C)}else{var D=F[0]}D.setSourcePath(B);if(!(D instanceof fabric.PathGroup)){fabric.base.object.extend(D,C);if(typeof C.angle!=="undefined"){D.setAngle(C.angle)}}u(D,A)})}}}},this)}catch(r){console.log(r.message)}},loadImageFromURL:(function(){var p={};return function(q,u){var t=this;function r(){var v=k.getElementById(p[q]);if(v.width&&v.height){u(new fabric.Image(v))}else{setTimeout(r,50)}}if(p[q]){r()}else{var s=new Image();s.onload=function(){s.onload=null;t._resizeImageToFit(s);var v=new fabric.Image(s);u(v)};s.className="canvas-img-clone";s.src=q;if(this.shouldCacheImages){p[q]=Element.identify(s)}k.body.appendChild(s)}}})(),loadSVGFromURL:function(p,t){var s=this;p=p.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(p,function(u){if(u){s.cache.get(p,function(w){var v=s._enlivenCachedObject(w);t(v.objects,v.options)})}else{new Ajax.Request(p,{method:"get",onComplete:r,onFailure:q})}});function r(v){var u=v.responseXML;if(!u){return}var w=u.documentElement;if(!w){return}fabric.parseSVGDocument(w,function(y,x){s.cache.set(p,{objects:y.invoke("toObject"),options:x});t(y,x)})}function q(){console.log("ERROR!")}},_enlivenCachedObject:function(r){var q=r.objects;var p=r.options;q=q.map(function(s){return d[s.type.capitalize()].fromObject(s)});return({objects:q,options:p})},remove:function(p){fabric.util.removeFromArray(this._aObjects,p);this.renderAll();return p},fxRemove:function(p,r){var q=this;p.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){q.remove(p);if(typeof r==="function"){r()}}});return this},sendToBack:function(p){fabric.util.removeFromArray(this._aObjects,p);this._aObjects.unshift(p);return this.renderAll()},bringToFront:function(p){fabric.util.removeFromArray(this._aObjects,p);this._aObjects.push(p);return this.renderAll()},sendBackwards:function(r){var q=this._aObjects.indexOf(r),p=q;if(q!==0){for(var s=q-1;s>=0;--s){if(r.intersectsWithObject(this._aObjects[s])){p=s;break}}fabric.util.removeFromArray(this._aObjects,r);this._aObjects.splice(p,0,r)}return this.renderAll()},bringForward:function(s){var u=this.getObjects(),q=u.indexOf(s),p=q;if(q!==u.length-1){for(var t=q+1,r=this._aObjects.length;t"};fabric.base.object.extend(fabric.Element,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(s){var r=s.getContext("2d"),w=r.getImageData(0,0,s.width,s.height),u=w.data,p=w.width,v=w.height,q,t;for(i=0;i1)?e.apply(this,a.call(arguments,1)):e.call(this)},initialize:function(d){this.setOptions(d);this._importProperties();this.originalState={};this.setCoords();this.saveState()},setOptions:function(d){this.options=c.base.object.extend(this._getOptions(),d)},_getOptions:function(){return c.base.object.extend(c.base.object.clone(this._getSuperOptions()),this.options)},_getSuperOptions:function(){var f=this.constructor;if(f){var d=f.superclass;if(d){var e=d.prototype;if(e&&typeof e._getOptions=="function"){return e._getOptions()}}}return{}},_importProperties:function(){this.stateProperties.forEach(function(d){(d==="angle")?this.setAngle(this.options[d]):(this[d]=this.options[d])},this)},transform:function(d){d.globalAlpha=this.opacity;d.translate(this.left,this.top);d.rotate(this.theta);d.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toJSON:function(){return JSON.stringify(this.toObject())},toObject:function(){var d=c.util.toFixed;var e={type:this.type,left:d(this.left,this.NUM_FRACTION_DIGITS),top:d(this.top,this.NUM_FRACTION_DIGITS),width:d(this.width,this.NUM_FRACTION_DIGITS),height:d(this.height,this.NUM_FRACTION_DIGITS),fill:this.fill,overlayFill:this.overlayFill,stroke:this.stroke,strokeWidth:this.strokeWidth,scaleX:d(this.scaleX,this.NUM_FRACTION_DIGITS),scaleY:d(this.scaleY,this.NUM_FRACTION_DIGITS),angle:d(this.getAngle(),this.NUM_FRACTION_DIGITS),flipX:this.flipX,flipY:this.flipY,opacity:d(this.opacity,this.NUM_FRACTION_DIGITS)};if(!this.includeDefaultValues){e=this._removeDefaultValues(e)}return e},toDatalessObject:function(){return this.toObject()},_removeDefaultValues:function(e){var d=c.Object.prototype.options;this.stateProperties.forEach(function(f){if(e[f]===d[f]){delete e[f]}});return e},isActive:function(){return !!this.active},setActive:function(d){this.active=!!d;return this},toString:function(){return"#"},set:function(e,d){var f=(e==="scaleX"||e==="scaleY")&&df.x&&g.xf.y&&k.y=l)&&(g.d.y>=l)){continue}if((g.o.x==g.d.x)&&(g.o.x>=m)){n=g.o.x;k=l}else{p=0;o=(g.d.y-g.o.y)/(g.d.x-g.o.x);f=l-p*m;e=g.o.y-o*g.o.x;n=-(f-e)/(p-o);k=f+p*n}if(n>=m){h+=1}if(h==2){break}}return h},_getImageLines:function(e,d){return{topline:{o:e.tl,d:e.tr},rightline:{o:e.tr,d:e.br},bottomline:{o:e.br,d:e.bl},leftline:{o:e.bl,d:e.tl}}},_setCornerCoords:function(){var m=this.oCoords,h=this.theta,g=this.cornersize*Math.cos(h),f=this.cornersize*Math.sin(h),k=this.cornersize/2,e=k-f,d=k,l;m.tl.x-=e;m.tl.y-=d;m.tl.corner={tl:{x:m.tl.x,y:m.tl.y},tr:{x:m.tl.x+g,y:m.tl.y+f},bl:{x:m.tl.x-f,y:m.tl.y+g}};m.tl.corner.br={x:m.tl.corner.tr.x-f,y:m.tl.corner.tr.y+g};m.tl.x+=e;m.tl.y+=d;m.tr.x+=k;m.tr.y-=k;m.tr.corner={tl:{x:m.tr.x-g,y:m.tr.y-f},tr:{x:m.tr.x,y:m.tr.y},br:{x:m.tr.x-f,y:m.tr.y+g}};m.tr.corner.bl={x:m.tr.corner.tl.x-f,y:m.tr.corner.tl.y+g};m.tr.x-=k;m.tr.y+=k;m.bl.x-=k;m.bl.y+=k;m.bl.corner={tl:{x:m.bl.x+f,y:m.bl.y-g},bl:{x:m.bl.x,y:m.bl.y},br:{x:m.bl.x+g,y:m.bl.y+f}};m.bl.corner.tr={x:m.bl.corner.br.x+f,y:m.bl.corner.br.y-g};m.bl.x+=k;m.bl.y-=k;m.br.x+=k;m.br.y+=k;m.br.corner={tr:{x:m.br.x+f,y:m.br.y-g},bl:{x:m.br.x-g,y:m.br.y-f},br:{x:m.br.x,y:m.br.y}};m.br.corner.tl={x:m.br.corner.bl.x+f,y:m.br.corner.bl.y-g};m.br.x-=k;m.br.y-=k;m.ml.x-=k;m.ml.y-=k;m.ml.corner={tl:{x:m.ml.x,y:m.ml.y},tr:{x:m.ml.x+g,y:m.ml.y+f},bl:{x:m.ml.x-f,y:m.ml.y+g}};m.ml.corner.br={x:m.ml.corner.tr.x-f,y:m.ml.corner.tr.y+g};m.ml.x+=k;m.ml.y+=k;m.mt.x-=k;m.mt.y-=k;m.mt.corner={tl:{x:m.mt.x,y:m.mt.y},tr:{x:m.mt.x+g,y:m.mt.y+f},bl:{x:m.mt.x-f,y:m.mt.y+g}};m.mt.corner.br={x:m.mt.corner.tr.x-f,y:m.mt.corner.tr.y+g};m.mt.x+=k;m.mt.y+=k;m.mr.x-=k;m.mr.y-=k;m.mr.corner={tl:{x:m.mr.x,y:m.mr.y},tr:{x:m.mr.x+g,y:m.mr.y+f},bl:{x:m.mr.x-f,y:m.mr.y+g}};m.mr.corner.br={x:m.mr.corner.tr.x-f,y:m.mr.corner.tr.y+g};m.mr.x+=k;m.mr.y+=k;m.mb.x-=k;m.mb.y-=k;m.mb.corner={tl:{x:m.mb.x,y:m.mb.y},tr:{x:m.mb.x+g,y:m.mb.y+f},bl:{x:m.mb.x-f,y:m.mb.y+g}};m.mb.corner.br={x:m.mb.corner.tr.x-f,y:m.mb.corner.tr.y+g};m.mb.x+=k;m.mb.y+=k;l=m.mb.corner;l.tl.x-=k;l.tl.y-=k;l.tr.x-=k;l.tr.y-=k;l.br.x-=k;l.br.y-=k;l.bl.x-=k;l.bl.y-=k},toGrayscale:function(){var d=this.get("fill");if(d){this.set("overlayFill",new c.Color(d).toGrayscale().toRgb())}return this},complexity:function(){return 0},getCenter:function(){return{x:this.get("left")+this.width/2,y:this.get("top")+this.height/2}},straighten:function(){var d=this._getAngleValueForStraighten();this.setAngle(d);return this},fxStraighten:function(e){e=e||{};var f=function(){},g=e.onComplete||f,d=e.onChange||f,h=this;c.base.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(k){h.setAngle(k);d()},onComplete:function(){h.setCoords();g()},onStart:function(){h.setActive(false)}});return this},fxRemove:function(e){e||(e={});var f=function(){},g=e.onComplete||f,d=e.onChange||f,h=this;c.base.animate({startValue:this.get("opacity"),endValue:0,duration:this.FX_DURATION,onChange:function(k){h.set("opacity",k);d()},onComplete:g,onStart:function(){h.setActive(false)}});return this},_getAngleValueForStraighten:function(){var d=this.get("angle");if(d>-225&&d<=-135){return -180}else{if(d>-135&&d<=-45){return -90}else{if(d>-45&&d<=45){return 0}else{if(d>45&&d<=135){return 90}else{if(d>135&&d<=225){return 180}else{if(d>225&&d<=315){return 270}else{if(d>315){return 360}}}}}}}return 0}});c.Object.prototype.rotate=c.Object.prototype.setAngle})();(function(){var a=this.fabric||(this.fabric={});if(a.Line){return}a.Line=a.base.createClass(a.Object,{type:"line",initialize:function(c,b){if(!c){c=[0,0,0,0]}this.callSuper("initialize",b);this.set("x1",c[0]);this.set("y1",c[1]);this.set("x2",c[2]);this.set("y2",c[3]);this.set("width",this.x2-this.x1);this.set("height",this.y2-this.y1);this.set("left",this.x1+this.width/2);this.set("top",this.y1+this.height/2)},_render:function(b){b.beginPath();b.moveTo(-this.width/2,-this.height/2);b.lineTo(this.width/2,this.height/2);b.stroke()},complexity:function(){return 1},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{x1:this.get("x1"),y1:this.get("y1"),x2:this.get("x2"),y2:this.get("y2")})}});a.Element.ATTRIBUTE_NAMES="x1 y1 x2 y2 stroke stroke-width transform".split(" ");a.Line.fromElement=function(c,b){var e=a.parseAttributes(c,a.Element.ATTRIBUTE_NAMES);var d=[e.x1||0,e.y1||0,e.x2||0,e.y2||0];return new a.Line(d,a.base.object.extend(e,b))};a.Line.fromObject=function(b){var c=[b.x1,b.y1,b.x2,b.y2];return new a.Line(c,b)}})();(function(){var a=this,b=a.fabric||(a.fabric={}),d=Math.PI*2;if(b.Circle){console.warn("fabric.Circle is already defined.");return}b.Circle=b.base.createClass(b.Object,{type:"circle",initialize:function(e){e=e||{};this.set("radius",e.radius||0);this.callSuper("initialize",e);var f=this.get("radius")*2*this.get("scaleX");this.set("width",f).set("height",f)},toObject:function(){return b.base.object.extend(this.callSuper("toObject"),{radius:this.get("radius")})},_render:function(e){e.beginPath();e.arc(0,0,this.radius,0,d,false);if(this.fill){e.fill()}if(this.stroke){e.stroke()}},complexity:function(){return 1}});b.Circle.ATTRIBUTE_NAMES="cx cy r fill fill-opacity stroke stroke-width transform".split(" ");b.Circle.fromElement=function(f,e){var g=b.parseAttributes(f,b.Circle.ATTRIBUTE_NAMES);if(!c(g)){throw Error("value of `r` attribute is required and can not be negative")}return new b.Circle(b.base.object.extend(g,e))};function c(e){return(("radius" in e)&&(e.radius>0))}b.Circle.fromObject=function(e){return new b.Circle(e)}})();(function(){var a=this.fabric||(this.fabric={});if(a.Ellipse){console.warn("fabric.Ellipse is already defined.");return}a.Ellipse=a.base.createClass(a.Object,{type:"ellipse",initialize:function(b){b=b||{};this.callSuper("initialize",b);this.set("rx",b.rx||0);this.set("ry",b.ry||0);this.set("width",this.get("rx")*2);this.set("height",this.get("ry")*2)},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{rx:this.get("rx"),ry:this.get("ry")})},render:function(b,c){if(this.rx===0||this.ry===0){return}return this.callSuper("render",b,c)},_render:function(b){b.beginPath();b.save();b.transform(1,0,0,this.ry/this.rx,0,0);b.arc(0,0,this.rx,0,Math.PI*2,false);b.restore();if(this.stroke){b.stroke()}if(this.fill){b.fill()}},complexity:function(){return 1}});a.Ellipse.ATTRIBUTE_NAMES="cx cy rx ry fill fill-opacity stroke stroke-width transform".split(" ");a.Ellipse.fromElement=function(c,b){var d=a.parseAttributes(c,a.Ellipse.ATTRIBUTE_NAMES);return new a.Ellipse(a.base.object.extend(d,b))};a.Ellipse.fromObject=function(b){return new a.Ellipse(b)}})();(function(){var b=this.fabric||(this.fabric={});if(b.Rect){return}b.Rect=b.base.createClass(b.Object,{type:"rect",options:{rx:0,ry:0},initialize:function(c){this.callSuper("initialize",c);this._initRxRy()},_initRxRy:function(){if(this.options.rx&&!this.options.ry){this.options.ry=this.options.rx}else{if(this.options.ry&&!this.options.rx){this.options.rx=this.options.ry}}},_render:function(e){var k=this.options.rx||0,g=this.options.ry||0,c=-this.width/2,l=-this.height/2,d=this.width,f=this.height;e.beginPath();e.moveTo(c+k,l);e.lineTo(c+d-k,l);e.bezierCurveTo(c+d,l,c+d,l+g,c+d,l+g);e.lineTo(c+d,l+f-g);e.bezierCurveTo(c+d,l+f,c+d-k,l+f,c+d-k,l+f);e.lineTo(c+k,l+f);e.bezierCurveTo(c,l+f,c,l+f-g,c,l+f-g);e.lineTo(c,l+g);e.bezierCurveTo(c,l,c+k,l,c+k,l);e.closePath();if(this.fill){e.fill()}if(this.stroke){e.stroke()}},_normalizeLeftTopProperties:function(c){if(c.left){this.set("left",c.left+this.getWidth()/2)}if(c.top){this.set("top",c.top+this.getHeight()/2)}return this},complexity:function(){return 1}});b.Rect.ATTRIBUTE_NAMES="x y width height rx ry fill fill-opacity stroke stroke-width transform".split(" ");function a(c){c.left=c.left||0;c.top=c.top||0;return c}b.Rect.fromElement=function(d,c){if(!d){return null}var f=b.parseAttributes(d,b.Rect.ATTRIBUTE_NAMES);f=a(f);var e=new b.Rect(b.base.object.extend(c||{},f));e._normalizeLeftTopProperties(f);return e};b.Rect.fromObject=function(c){return new b.Rect(c)}})();(function(){var b=this.fabric||(this.fabric={});if(b.Polyline){console.warn("fabric.Polyline is already defined");return}b.Polyline=b.base.createClass(b.Object,{type:"polyline",initialize:function(d,c){c=c||{};this.set("points",d);this.callSuper("initialize",c);this._calcDimensions()},_calcDimensions:function(){return b.Polygon.prototype._calcDimensions.call(this)},_toOrigin:function(){return b.Polygon.prototype._toOrigin.call(this)},toObject:function(){return b.Polygon.prototype.toObject.call(this)},_render:function(e){var d;e.beginPath();for(var f=0,c=this.points.length;f"},toObject:function(){var c=b.base.object.extend(this.callSuper("toObject"),{path:this.path});if(this.sourcePath){c.sourcePath=this.sourcePath}if(this.transformMatrix){c.transformMatrix=this.transformMatrix}return c},toDatalessObject:function(){var c=this.toObject();if(this.sourcePath){c.path=this.sourcePath}delete c.sourcePath;return c},complexity:function(){return this.path.length},set:function(d,c){if(this.stub){this.stub.set(d,c)}return this.callSuper("set",d,c)},_parsePath:function(){var d=[],f,g;for(var e=0,c=this.path.length;e"},isSameColor:function(){var c=this.getObjects()[0].get("fill");return this.getObjects().every(function(d){return d.get("fill")===c})},complexity:function(){return this.paths.reduce(function(c,d){return c+((d&&d.complexity)?d.complexity():0)},0)},toGrayscale:function(){var c=this.paths.length;while(c--){this.paths[c].toGrayscale()}return this},getObjects:function(){return this.paths}});function a(f){for(var e=0,c=f.length;e"},getObjects:function(){return this.objects},add:function(b){this._restoreObjectsState();this.objects.push(b);b.setActive(true);this._calcBounds();this._updateObjectsCoords();return this},remove:function(b){this._restoreObjectsState();a.util.removeFromArray(this.objects,b);b.setActive(false);this._calcBounds();this._updateObjectsCoords();return this},size:function(){return this.getObjects().length},set:function(b,d){if(typeof d=="function"){this.set(b,d(this[b]))}else{if(b==="fill"||b==="opacity"){var c=this.objects.length;this[b]=d;while(c--){this.objects[c].set(b,d)}}else{this[b]=d}}return this},contains:function(b){return this.objects.indexOf(b)>-1},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{objects:a.base.array.invoke(this.objects,"clone")})},render:function(c){c.save();this.transform(c);var f=Math.max(this.scaleX,this.scaleY);for(var d=0,b=this.objects.length;dc.x&&d-bc.y},toGrayscale:function(){var b=this.objects.length;while(b--){this.objects[b].toGrayscale()}}});a.Group.fromObject=function(b){return new a.Group(b.objects,b)}})();(function(){var a=this.fabric||(this.fabric={});if(a.Text){console.warn("fabric.Text is already defined");return}if(!a.Object){console.warn("fabric.Text requires fabric.Object");return}a.Text=a.base.createClass(a.Object,{options:{top:10,left:10,fontsize:20,fontweight:100,fontfamily:"Modernist_One_400",path:null},type:"text",initialize:function(c,b){this.originalState={};this.initStateProperties();this.text=c;this.setOptions(b);a.base.object.extend(this,this.options);this.theta=this.angle*(Math.PI/180);this.width=this.getWidth();this.setCoords()},initStateProperties:function(){var b;if((b=this.constructor)&&(b=b.superclass)&&(b=b.prototype)&&(b=b.stateProperties)&&b.clone){this.stateProperties=b.clone();this.stateProperties.push("fontfamily","fontweight","path")}},toString:function(){return"#"},_render:function(b){var d=Cufon.textOptions||(Cufon.textOptions={});d.left=this.left;d.top=this.top;d.context=b;d.color=this.fill;var c=this._initDummyElement();this.transform(b);Cufon.replaceElement(c,{separate:"none",fontFamily:this.fontfamily});this.width=d.width;this.height=d.height},_initDummyElement:function(){var b=document.createElement("div");b.innerHTML=this.text;b.style.fontSize="40px";b.style.fontWeight="400";b.style.fontStyle="normal";b.style.letterSpacing="normal";b.style.color="#000000";b.style.fontWeight="600";b.style.fontFamily="Verdana";return b},render:function(b){b.save();this._render(b);if(this.active){this.drawBorders(b);this.drawCorners(b)}b.restore()},toObject:function(){return a.base.object.extend(this.callSuper("toObject"),{text:this.text,fontsize:this.fontsize,fontweight:this.fontweight,fontfamily:this.fontfamily,path:this.path})},setColor:function(b){this.set("fill",b);return this},setFontsize:function(b){this.set("fontsize",b);this.setCoords();return this},getText:function(){return this.text},setText:function(b){this.set("text",b);this.setCoords();return this},set:function(b,c){this[b]=c;if(b==="fontfamily"){this.path=this.path.replace(/(.*?)([^\/]*)(\.font\.js)/,"$1"+c+"$3")}return this}});a.Text.fromObject=function(b){return new a.Text(b.text,a.base.object.clone(b))};a.Text.fromElement=function(b){}})();(function(){var a=this;if(!a.fabric){a.fabric={}}if(a.fabric.Image){console.warn("fabric.Image is already defined.");return}if(!fabric.Object){console.warn("fabric.Object is required for fabric.Image initialization");return}fabric.Image=fabric.base.createClass(fabric.Object,{maxwidth:null,maxheight:null,active:false,bordervisibility:false,cornervisibility:false,type:"image",__isGrayscaled:false,initialize:function(c,b){this.callSuper("initialize",b);this._initElement(c);this._initConfig(b||{})},getElement:function(){return this._element},setElement:function(b){this._element=b;return this},getNormalizedSize:function(c,b,d){if(d&&b&&(c.width>c.height&&(c.width/c.height)<(b/d))){normalizedWidth=Math.floor((c.width*d)/c.height);normalizedHeight=d}else{if(d&&((c.height==c.width)||(c.height>c.width)||(c.height>d))){normalizedWidth=Math.floor((c.width*d)/c.height);normalizedHeight=d}else{if(b&&(b'},clone:function(b){this.constructor.fromObject(this.toObject(),b)},toGrayscale:function(f){if(this.__isGrayscaled){return}var d=this.getElement(),b=document.createElement("canvas"),c=document.createElement("img"),e=this;b.width=d.width;b.height=d.height;b.getContext("2d").drawImage(d,0,0);fabric.Element.toGrayscale(b);c.onload=function(){e.setElement(c);f&&f();c.onload=b=d=imageData=null};c.width=d.width;c.height=d.height;c.src=b.toDataURL("image/png");this.__isGrayscaled=true;return this},_render:function(c){var b=this.getOriginalSize();c.drawImage(this.getElement(),-b.width/2,-b.height/2,b.width,b.height)},_adjustWidthHeightToBorders:function(b){if(b){this.currentBorder=this.borderwidth;this.width+=(2*this.currentBorder);this.height+=(2*this.currentBorder)}else{this.currentBorder=0}},_resetWidthHeight:function(){var b=this.getElement();this.set("width",b.width);this.set("height",b.height)},_initElement:function(b){this.setElement(fabric.base.getById(b));fabric.base.addClass(this.getElement(),fabric.Image.CSS_CANVAS)},_initConfig:function(b){this.setOptions(b);this._setBorder();this._setWidthHeight(b)},_setBorder:function(){if(this.bordervisibility){this.currentBorder=this.borderwidth}else{this.currentBorder=0}},_setWidthHeight:function(b){var c=2*this.currentBorder;this.width=(this.getElement().width||0)+c;this.height=(this.getElement().height||0)+c}});fabric.Image.CSS_CANVAS="canvas-img";fabric.Image.fromObject=function(c,e){var b=document.createElement("img"),d=c.src;if(c.width){b.width=c.width}if(c.height){b.height=c.height}b.onload=function(){if(e){e(new fabric.Image(b,c))}b=b.onload=null};b.src=d};fabric.Image.fromURL=function(c,e,d){var b=document.createElement("img");b.onload=function(){if(e){e(new fabric.Image(b,d))}b=b.onload=null};b.src=c}})(); \ No newline at end of file +if(typeof console=="undefined"){var console={log:function(){},warn:function(){}}}if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i>>0;w=Number(w)||0;w=Math[w<0?"ceil":"floor"](w);if(w<0){w+=u}for(;w>>0;v>>0;w>>0;v>>0;v>>0;w>>0,v=0,x;if(arguments.length>1){x=arguments[1]}else{do{if(v in this){x=this[v++];break}if(++v>=u){throw new TypeError()}}while(true)}for(;v=u){u=x[v][w]}}}else{while(v--){if(x[v]>=u){u=x[v]}}}return u}function l(x,w){var v=x.length-1,u=w?x[v][w]:x[v];if(w){while(v--){if(x[v][w]-1?w(D,F.match(/opacity:\s*(\d?\.?\d*)/)[1]):D}for(var G in F){if(G==="opacity"){w(D,F[G])}else{var E=(G==="float"||G==="cssFloat")?(typeof H.styleFloat==="undefined"?"cssFloat":"styleFloat"):G;H[E]=F[G]}}return D}var B=document.createElement("div"),A=typeof B.style.opacity==="string",v=typeof B.style.filter==="string",u=document.defaultView,z=u&&typeof u.getComputedStyle!=="undefined",x=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,w=function(C){return C};if(A){w=function(C,D){C.style.opacity=D;return C}}else{if(v){w=function(C,D){var E=C.style;if(C.currentStyle&&!C.currentStyle.hasLayout){E.zoom=1}if(x.test(E.filter)){D=D>=0.9999?"":("alpha(opacity="+(D*100)+")");E.filter=E.filter.replace(x,D)}else{E.filter+=" alpha(opacity="+(D*100)+")"}return C}}}g.util.setStyle=y})();function p(u){return typeof u==="string"?document.getElementById(u):u}function n(v){var u=[],w=v.length;while(w--){u[w]=v[w]}return u}function b(v,u){var w=document.createElement(v);for(var x in u){if(x==="class"){x="className"}else{if(x==="for"){x="htmlFor"}}w.setAttribute(x,u[x])}return w}function f(u,v){if((" "+u.className+" ").indexOf(" "+v+" ")===-1){u.className+=(u.className?" ":"")+v}}function a(v,w,u){if(typeof w==="string"){w=b(w,u)}if(v.parentNode){v.parentNode.replaceChild(w,v)}w.appendChild(v);return w}function k(v){var u=0,w=0;do{u+=v.offsetTop||0;w+=v.offsetLeft||0;v=v.offsetParent}while(v);return({left:w,top:u})}function e(){return false}(function(){var u=document.documentElement.style;var v="userSelect" in u?"userSelect":"MozUserSelect" in u?"MozUserSelect":"WebkitUserSelect" in u?"WebkitUserSelect":"KhtmlUserSelect" in u?"KhtmlUserSelect":"";function w(x){if(typeof x.onselectstart!=="undefined"){x.onselectstart=e}if(v){x.style[v]="none"}else{if(typeof x.unselectable=="string"){x.unselectable="on"}}return x}g.util.makeElementUnselectable=w})();(function(){function u(x,B){var z=document.getElementsByTagName("head")[0],y=document.createElement("script"),A=true;y.type="text/javascript";y.setAttribute("runat","server");y.onload=y.onreadystatechange=function(C){if(A){if(typeof this.readyState=="string"&&this.readyState!=="loaded"&&this.readyState!=="complete"){return}A=false;B(C||window.event);y=y.onload=y.onreadystatechange=null}};y.src=x;z.appendChild(y)}function w(x,y){v.load(x);y()}g.util.getScript=u;var v=this.Jaxer;if(v&&v.load){g.util.getScript=w}})();function c(F){F||(F={});var v=+new Date(),z=F.duration||500,E=v+z,y,D,A=F.onChange||function(){},B=F.easing||function(G){return(-Math.cos(G*Math.PI)/2)+0.5},u="startValue" in F?F.startValue:0,C="endValue" in F?F.endValue:100,x=u>C;F.onStart&&F.onStart();var w=setInterval(function(){y=+new Date();D=y>E?1:(y-v)/z;A(x?(u-(u-C)*B(D)):(u+(C-u)*B(D)));if(y>E){clearInterval(w);F.onComplete&&F.onComplete()}},10)}g.util.getById=p;g.util.toArray=n;g.util.makeElement=b;g.util.addClass=f;g.util.wrapElement=a;g.util.getElementOffset=k;g.util.animate=c;(function(){function x(y,z){return y+(/\?/.test(y)?"&":"?")+z}var w=(function(){var B=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest()}];for(var y=B.length;y--;){try{var A=B[y]();if(A){return B[y]}}catch(z){}}})();function u(){}function v(A,z){z||(z={});var D=z.method?z.method.toUpperCase():"GET",C=z.onComplete||function(){},B=w(),y;B.onreadystatechange=function(){if(B.readyState===4){C(B);B.onreadystatechange=u}};if(D==="GET"){y=null;if(typeof z.parameters=="string"){A=x(A,z.parameters)}}B.open(D,A,true);if(D==="POST"||D==="PUT"){B.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}B.send(y);return B}g.util.request=v})();(function(){function y(B,A){var z=B.indexOf(A);if(z!==-1){B.splice(z,1)}return B}function x(A,z){return Math.floor(Math.random()*(z-A+1))+A}var v=Math.PI/180;function w(z){return z*v}function u(A,z){return parseFloat(Number(A).toFixed(z))}g.util.removeFromArray=y;g.util.degreesToRadians=w;g.util.toFixed=u;g.util.getRandomInt=x})()})(this);(function(){var f=this.fabric||(this.fabric={});var c={cx:"left",x:"left",cy:"top",y:"top",r:"radius","fill-opacity":"opacity","fill-rule":"fillRule","stroke-width":"strokeWidth",transform:"transformMatrix"};function b(l,k){if(!l){return}var n,h,g={};if(l.parentNode&&/^g$/i.test(l.parentNode.nodeName)){g=f.parseAttributes(l.parentNode,k)}var m=k.reduce(function(p,o){n=l.getAttribute(o);h=parseFloat(n);if(n){if((o==="fill"||o==="stroke")&&n==="none"){n=""}if(o==="fill-rule"){n=(n==="evenodd")?"destination-over":n}if(o==="transform"){n=f.parseTransformAttribute(n)}if(o in c){o=c[o]}p[o]=isNaN(h)?n:h}return p},{});m=f.util.object.extend(f.parseStyleAttribute(l),m);return f.util.object.extend(g,m)}f.parseTransformAttribute=(function(){function g(B,C){var D=C[0];B[0]=Math.cos(D);B[1]=Math.sin(D);B[2]=-Math.sin(D);B[3]=Math.cos(D)}function n(D,E){var C=E[0],B=(E.length===2)?E[1]:E[0];D[0]=C;D[3]=B}function y(B,C){B[2]=C[0]}function k(B,C){B[1]=C[0]}function v(B,C){B[4]=C[0];if(C.length===2){B[5]=C[1]}}var p=[1,0,0,1,0,0],h="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)",z="(?:\\s+,?\\s*|,\\s*)",q="(?:(skewX)\\s*\\(\\s*("+h+")\\s*\\))",o="(?:(skewY)\\s*\\(\\s*("+h+")\\s*\\))",x="(?:(rotate)\\s*\\(\\s*("+h+")(?:"+z+"("+h+")"+z+"("+h+"))?\\s*\\))",A="(?:(scale)\\s*\\(\\s*("+h+")(?:"+z+"("+h+"))?\\s*\\))",t="(?:(translate)\\s*\\(\\s*("+h+")(?:"+z+"("+h+"))?\\s*\\))",w="(?:(matrix)\\s*\\(\\s*("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")"+z+"("+h+")\\s*\\))",u="(?:"+w+"|"+t+"|"+A+"|"+x+"|"+q+"|"+o+")",r="(?:"+u+"(?:"+z+u+")*)",l="^\\s*(?:"+r+"?)\\s*$",s=new RegExp(l),m=new RegExp(u);return function(C){var B=p.concat();if(!C||(C&&!s.test(C))){return B}C.replace(m,function(G){var D=new RegExp(u).exec(G).filter(function(H){return(H!==""&&H!=null)}),E=D[1],F=D.slice(2).map(parseFloat);switch(E){case"translate":v(B,F);break;case"rotate":g(B,F);break;case"scale":n(B,F);break;case"skewX":y(B,F);break;case"skewY":k(B,F);break;case"matrix":B=F;break}});return B}})();function a(h){if(!h){return null}h=h.trim().split(/\s+/);var g=h.reduce(function(k,l){l=l.split(",");k.push({x:parseFloat(l[0]),y:parseFloat(l[1])});return k},[]);if(g.length%2!==0){}return g}function e(h){var g={},k=h.getAttribute("style");if(k){if(typeof k=="string"){k=k.split(";");k.pop();g=k.reduce(function(n,q){var m=q.split(":"),o=m[0].trim(),p=m[1].trim();n[o]=p;return n},{})}else{for(var l in k){if(typeof k[l]!=="undefined"){g[l]=k[l]}}}}return g}function d(h,g){var k=h.map(function(m){var l=f[f.util.string.capitalize(m.tagName)];if(l&&l.fromElement){try{return l.fromElement(m,g)}catch(n){console.log(n.message||n)}}});k=k.filter(function(l){return l!=null});return k}f.parseSVGDocument=(function(){var g=/^(path|circle|polygon|polyline|ellipse|rect|line)$/;var k="(?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)";var l=new RegExp("^\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*,?\\s*("+k+"+)\\s*$");function h(m,n){while(m&&(m=m.parentNode)){if(m.nodeName===n){return true}}return false}return function(u,w){if(!u){return}var t=f.util.toArray(u.getElementsByTagName("*"));var m=t.filter(function(y){return g.test(y.tagName)&&!h(y,"pattern")});if(!m||(m&&!m.length)){return}var n=u.getAttribute("viewBox"),r=u.getAttribute("width"),p=u.getAttribute("height"),o=null,v=null,s,q;if(n&&(n=n.match(l))){s=parseInt(n[1],10);q=parseInt(n[2],10);o=parseInt(n[3],10);v=parseInt(n[4],10)}o=r?parseFloat(r):o;v=p?parseFloat(p):v;var x={width:o,height:v};var m=f.parseElements(m,f.util.object.clone(x));if(!m||(m&&!m.length)){return}if(w){w(m,x)}}})();f.util.object.extend(f,{parseAttributes:b,parseElements:d,parseStyleAttribute:e,parsePointsAttribute:a})})();(function(){var b=this.fabric||(this.fabric={});if(b.Point){console.warn("fabric.Point is already defined");return}function a(c,d){if(arguments.length>0){this.init(c,d)}}a.prototype={constructor:a,init:function(c,d){this.x=c;this.y=d},add:function(c){return new a(this.x+c.x,this.y+c.y)},addEquals:function(c){this.x+=c.x;this.y+=c.y;return this},scalarAdd:function(c){return new a(this.x+c,this.y+c)},scalarAddEquals:function(c){this.x+=c;this.y+=c;return this},subtract:function(c){return new a(this.x-c.x,this.y-c.y)},subtractEquals:function(c){this.x-=c.x;this.y-=c.y;return this},scalarSubtract:function(c){return new a(this.x-c,this.y-c)},scalarSubtractEquals:function(c){this.x-=c;this.y-=c;return this},multiply:function(c){return new a(this.x*c,this.y*c)},multiplyEquals:function(c){this.x*=c;this.y*=c;return this},divide:function(c){return new a(this.x/c,this.y/c)},divideEquals:function(c){this.x/=c;this.y/=c;return this},eq:function(c){return(this.x==c.x&&this.y==c.y)},lt:function(c){return(this.xc.x&&this.y>c.y)},gte:function(c){return(this.x>=c.x&&this.y>=c.y)},lerp:function(d,c){return new a(this.x+(d.x-this.x)*c,this.y+(d.y-this.y)*c)},distanceFrom:function(e){var d=this.x-e.x,c=this.y-e.y;return Math.sqrt(d*d+c*c)},min:function(c){return new a(Math.min(this.x,c.x),Math.min(this.y,c.y))},max:function(c){return new a(Math.max(this.x,c.x),Math.max(this.y,c.y))},toString:function(){return this.x+","+this.y},setXY:function(c,d){this.x=c;this.y=d},setFromPoint:function(c){this.x=c.x;this.y=c.y},swap:function(d){var c=this.x,e=this.y;this.x=d.x;this.y=d.y;d.x=c;d.y=e}};b.Point=a})();(function(){var a=this,b=a.fabric||(a.fabric={});if(b.Intersection){console.warn("fabric.Intersection is already defined");return}function c(d){if(arguments.length>0){this.init(d)}}c.prototype.init=function(d){this.status=d;this.points=[]};c.prototype.appendPoint=function(d){this.points.push(d)};c.prototype.appendPoints=function(d){this.points=this.points.concat(d)};c.intersectLineLine=function(h,f,n,m){var o,k=(m.x-n.x)*(h.y-n.y)-(m.y-n.y)*(h.x-n.x),l=(f.x-h.x)*(h.y-n.y)-(f.y-h.y)*(h.x-n.x),g=(m.y-n.y)*(f.x-h.x)-(m.x-n.x)*(f.y-h.y);if(g!=0){var e=k/g,d=l/g;if(0<=e&&e<=1&&0<=d&&d<=1){o=new c("Intersection");o.points.push(new b.Point(h.x+e*(f.x-h.x),h.y+e*(f.y-h.y)))}else{o=new c("No Intersection")}}else{if(k==0||l==0){o=new c("Coincident")}else{o=new c("Parallel")}}return o};c.intersectLinePolygon=function(e,d,m){var n=new c("No Intersection"),f=m.length;for(var h=0;h0){n.status="Intersection"}return n};c.intersectPolygonPolygon=function(k,h){var f=new c("No Intersection"),m=k.length;for(var l=0;l0){f.status="Intersection"}return f};c.intersectPolygonRectangle=function(p,e,d){var g=e.min(d),o=e.max(d),f=new b.Point(o.x,g.y),n=new b.Point(g.x,o.y),m=c.intersectLinePolygon(g,f,p),l=c.intersectLinePolygon(f,o,p),k=c.intersectLinePolygon(o,n,p),h=c.intersectLinePolygon(n,g,p),q=new c("No Intersection");q.appendPoints(m.points);q.appendPoints(l.points);q.appendPoints(k.points);q.appendPoints(h.points);if(q.points.length>0){q.status="Intersection"}return q};b.Intersection=c})();(function(){var a=this.fabric||(this.fabric={});if(a.Color){console.warn("fabric.Color is already defined.");return}a.Color=b;function b(c){if(!c){this.setSource([0,0,0,1])}else{this._tryParsingColor(c)}}b.prototype._tryParsingColor=function(c){var d=b.sourceFromHex(c);if(!d){d=b.sourceFromRgb(c)}if(d){this.setSource(d)}};b.prototype.getSource=function(){return this._source};b.prototype.setSource=function(c){this._source=c};b.prototype.toRgb=function(){var c=this.getSource();return"rgb("+c[0]+","+c[1]+","+c[2]+")"};b.prototype.toRgba=function(){var c=this.getSource();return"rgba("+c[0]+","+c[1]+","+c[2]+","+c[3]+")"};b.prototype.toHex=function(){var f=this.getSource();var e=f[0].toString(16);e=(e.length==1)?("0"+e):e;var d=f[1].toString(16);d=(d.length==1)?("0"+d):d;var c=f[2].toString(16);c=(c.length==1)?("0"+c):c;return e.toUpperCase()+d.toUpperCase()+c.toUpperCase()};b.prototype.getAlpha=function(){return this.getSource()[3]};b.prototype.setAlpha=function(d){var c=this.getSource();c[3]=d;this.setSource(c);return this};b.prototype.toGrayscale=function(){var e=this.getSource(),d=parseInt((e[0]*0.3+e[1]*0.59+e[2]*0.11).toFixed(0),10),c=e[3];this.setSource([d,d,d,c]);return this};b.prototype.toBlackWhite=function(c){var f=this.getSource(),e=(f[0]*0.3+f[1]*0.59+f[2]*0.11).toFixed(0),d=f[3],c=c||127;e=(Number(e)0)?0:-s),this._groupSelector.ey-((r>0)?0:-r),q,p);this._oContextTop.lineWidth=this.selectionLineWidth;this._oContextTop.strokeStyle=this.selectionBorderColor;this._oContextTop.strokeRect(this._groupSelector.ex+a-((s>0)?0:q),this._groupSelector.ey+a-((r>0)?0:p),q,p)},_findSelectedObjects:function(v){var w,r,B=[],q=this._groupSelector.ex,A=this._groupSelector.ey,p=q+this._groupSelector.left,y=A+this._groupSelector.top,x,u=new fabric.Point(Math.min(q,p),Math.min(A,y)),z=new fabric.Point(Math.max(q,p),Math.max(A,y));for(var s=0,t=this._aObjects.length;s1){var B=new fabric.Group(B);this.setActiveGroup(B);B.saveCoords();fabric.util.fireEvent("group:selected",{target:B})}}this.renderAll()},add:function(){this._aObjects.push.apply(this._aObjects,arguments);this.renderAll();return this},insertAt:function(q,p){this._aObjects.splice(p,0,q);this.renderAll();return this},getObjects:function(){return this._aObjects},getContext:function(){return this._oContextTop},clearContext:b,clear:function(){this._aObjects.length=0;this.clearContext(this._oContextTop);this.clearContext(this._oContextContainer);this.renderAll();return this},renderAll:function(q){var p=this._oConfig.width,t=this._oConfig.height;var x=q?this._oContextTop:this._oContextContainer;this.clearContext(this._oContextTop);if(x!==this._oContextTop){this.clearContext(x)}if(q){if(!n&&this.backgroundColor==="transparent"){var v=true}if(!v){x.fillStyle=this.backgroundColor}x.fillRect(0,0,p,t)}var u=this._aObjects.length,s=this.getActiveGroup();if(u){for(var r=0;r1){var D=new fabric.PathGroup(F,C)}else{var D=F[0]}D.setSourcePath(B);if(!(D instanceof fabric.PathGroup)){fabric.util.object.extend(D,C);if(typeof C.angle!=="undefined"){D.setAngle(C.angle)}}u(D,A)})}}}},this)}catch(r){console.log(r.message)}},loadImageFromURL:(function(){var p={};return function(q,u){var t=this;function r(){var v=k.getElementById(p[q]);if(v.width&&v.height){u(new fabric.Image(v))}else{setTimeout(r,50)}}if(p[q]){r()}else{var s=new Image();s.onload=function(){s.onload=null;t._resizeImageToFit(s);var v=new fabric.Image(s);u(v)};s.className="canvas-img-clone";s.src=q;if(this.shouldCacheImages){p[q]=Element.identify(s)}k.body.appendChild(s)}}})(),loadSVGFromURL:function(p,t){var s=this;p=p.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(p,function(u){if(u){s.cache.get(p,function(w){var v=s._enlivenCachedObject(w);t(v.objects,v.options)})}else{new Ajax.Request(p,{method:"get",onComplete:r,onFailure:q})}});function r(v){var u=v.responseXML;if(!u){return}var w=u.documentElement;if(!w){return}fabric.parseSVGDocument(w,function(y,x){s.cache.set(p,{objects:y.invoke("toObject"),options:x});t(y,x)})}function q(){console.log("ERROR!")}},_enlivenCachedObject:function(r){var q=r.objects;var p=r.options;q=q.map(function(s){return d[s.type.capitalize()].fromObject(s)});return({objects:q,options:p})},remove:function(p){fabric.util.removeFromArray(this._aObjects,p);this.renderAll();return p},fxRemove:function(p,r){var q=this;p.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){q.remove(p);if(typeof r==="function"){r()}}});return this},sendToBack:function(p){fabric.util.removeFromArray(this._aObjects,p);this._aObjects.unshift(p);return this.renderAll()},bringToFront:function(p){fabric.util.removeFromArray(this._aObjects,p);this._aObjects.push(p);return this.renderAll()},sendBackwards:function(r){var q=this._aObjects.indexOf(r),p=q;if(q!==0){for(var s=q-1;s>=0;--s){if(r.intersectsWithObject(this._aObjects[s])){p=s;break}}fabric.util.removeFromArray(this._aObjects,r);this._aObjects.splice(p,0,r)}return this.renderAll()},bringForward:function(s){var u=this.getObjects(),q=u.indexOf(s),p=q;if(q!==u.length-1){for(var t=q+1,r=this._aObjects.length;t"};fabric.util.object.extend(fabric.Element,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(s){var r=s.getContext("2d"),w=r.getImageData(0,0,s.width,s.height),u=w.data,p=w.width,v=w.height,q,t;for(i=0;i1)?e.apply(this,a.call(arguments,1)):e.call(this)},initialize:function(d){this.setOptions(d);this._importProperties();this.originalState={};this.setCoords();this.saveState()},setOptions:function(d){this.options=c.util.object.extend(this._getOptions(),d)},_getOptions:function(){return c.util.object.extend(c.util.object.clone(this._getSuperOptions()),this.options)},_getSuperOptions:function(){var f=this.constructor;if(f){var d=f.superclass;if(d){var e=d.prototype;if(e&&typeof e._getOptions=="function"){return e._getOptions()}}}return{}},_importProperties:function(){this.stateProperties.forEach(function(d){(d==="angle")?this.setAngle(this.options[d]):(this[d]=this.options[d])},this)},transform:function(d){d.globalAlpha=this.opacity;d.translate(this.left,this.top);d.rotate(this.theta);d.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toJSON:function(){return JSON.stringify(this.toObject())},toObject:function(){var d=c.util.toFixed;var e={type:this.type,left:d(this.left,this.NUM_FRACTION_DIGITS),top:d(this.top,this.NUM_FRACTION_DIGITS),width:d(this.width,this.NUM_FRACTION_DIGITS),height:d(this.height,this.NUM_FRACTION_DIGITS),fill:this.fill,overlayFill:this.overlayFill,stroke:this.stroke,strokeWidth:this.strokeWidth,scaleX:d(this.scaleX,this.NUM_FRACTION_DIGITS),scaleY:d(this.scaleY,this.NUM_FRACTION_DIGITS),angle:d(this.getAngle(),this.NUM_FRACTION_DIGITS),flipX:this.flipX,flipY:this.flipY,opacity:d(this.opacity,this.NUM_FRACTION_DIGITS)};if(!this.includeDefaultValues){e=this._removeDefaultValues(e)}return e},toDatalessObject:function(){return this.toObject()},_removeDefaultValues:function(e){var d=c.Object.prototype.options;this.stateProperties.forEach(function(f){if(e[f]===d[f]){delete e[f]}});return e},isActive:function(){return !!this.active},setActive:function(d){this.active=!!d;return this},toString:function(){return"#"},set:function(e,d){var f=(e==="scaleX"||e==="scaleY")&&df.x&&g.xf.y&&k.y=l)&&(g.d.y>=l)){continue}if((g.o.x==g.d.x)&&(g.o.x>=m)){n=g.o.x;k=l}else{p=0;o=(g.d.y-g.o.y)/(g.d.x-g.o.x);f=l-p*m;e=g.o.y-o*g.o.x;n=-(f-e)/(p-o);k=f+p*n}if(n>=m){h+=1}if(h==2){break}}return h},_getImageLines:function(e,d){return{topline:{o:e.tl,d:e.tr},rightline:{o:e.tr,d:e.br},bottomline:{o:e.br,d:e.bl},leftline:{o:e.bl,d:e.tl}}},_setCornerCoords:function(){var m=this.oCoords,h=this.theta,g=this.cornersize*Math.cos(h),f=this.cornersize*Math.sin(h),k=this.cornersize/2,e=k-f,d=k,l;m.tl.x-=e;m.tl.y-=d;m.tl.corner={tl:{x:m.tl.x,y:m.tl.y},tr:{x:m.tl.x+g,y:m.tl.y+f},bl:{x:m.tl.x-f,y:m.tl.y+g}};m.tl.corner.br={x:m.tl.corner.tr.x-f,y:m.tl.corner.tr.y+g};m.tl.x+=e;m.tl.y+=d;m.tr.x+=k;m.tr.y-=k;m.tr.corner={tl:{x:m.tr.x-g,y:m.tr.y-f},tr:{x:m.tr.x,y:m.tr.y},br:{x:m.tr.x-f,y:m.tr.y+g}};m.tr.corner.bl={x:m.tr.corner.tl.x-f,y:m.tr.corner.tl.y+g};m.tr.x-=k;m.tr.y+=k;m.bl.x-=k;m.bl.y+=k;m.bl.corner={tl:{x:m.bl.x+f,y:m.bl.y-g},bl:{x:m.bl.x,y:m.bl.y},br:{x:m.bl.x+g,y:m.bl.y+f}};m.bl.corner.tr={x:m.bl.corner.br.x+f,y:m.bl.corner.br.y-g};m.bl.x+=k;m.bl.y-=k;m.br.x+=k;m.br.y+=k;m.br.corner={tr:{x:m.br.x+f,y:m.br.y-g},bl:{x:m.br.x-g,y:m.br.y-f},br:{x:m.br.x,y:m.br.y}};m.br.corner.tl={x:m.br.corner.bl.x+f,y:m.br.corner.bl.y-g};m.br.x-=k;m.br.y-=k;m.ml.x-=k;m.ml.y-=k;m.ml.corner={tl:{x:m.ml.x,y:m.ml.y},tr:{x:m.ml.x+g,y:m.ml.y+f},bl:{x:m.ml.x-f,y:m.ml.y+g}};m.ml.corner.br={x:m.ml.corner.tr.x-f,y:m.ml.corner.tr.y+g};m.ml.x+=k;m.ml.y+=k;m.mt.x-=k;m.mt.y-=k;m.mt.corner={tl:{x:m.mt.x,y:m.mt.y},tr:{x:m.mt.x+g,y:m.mt.y+f},bl:{x:m.mt.x-f,y:m.mt.y+g}};m.mt.corner.br={x:m.mt.corner.tr.x-f,y:m.mt.corner.tr.y+g};m.mt.x+=k;m.mt.y+=k;m.mr.x-=k;m.mr.y-=k;m.mr.corner={tl:{x:m.mr.x,y:m.mr.y},tr:{x:m.mr.x+g,y:m.mr.y+f},bl:{x:m.mr.x-f,y:m.mr.y+g}};m.mr.corner.br={x:m.mr.corner.tr.x-f,y:m.mr.corner.tr.y+g};m.mr.x+=k;m.mr.y+=k;m.mb.x-=k;m.mb.y-=k;m.mb.corner={tl:{x:m.mb.x,y:m.mb.y},tr:{x:m.mb.x+g,y:m.mb.y+f},bl:{x:m.mb.x-f,y:m.mb.y+g}};m.mb.corner.br={x:m.mb.corner.tr.x-f,y:m.mb.corner.tr.y+g};m.mb.x+=k;m.mb.y+=k;l=m.mb.corner;l.tl.x-=k;l.tl.y-=k;l.tr.x-=k;l.tr.y-=k;l.br.x-=k;l.br.y-=k;l.bl.x-=k;l.bl.y-=k},toGrayscale:function(){var d=this.get("fill");if(d){this.set("overlayFill",new c.Color(d).toGrayscale().toRgb())}return this},complexity:function(){return 0},getCenter:function(){return{x:this.get("left")+this.width/2,y:this.get("top")+this.height/2}},straighten:function(){var d=this._getAngleValueForStraighten();this.setAngle(d);return this},fxStraighten:function(e){e=e||{};var f=function(){},g=e.onComplete||f,d=e.onChange||f,h=this;c.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(k){h.setAngle(k);d()},onComplete:function(){h.setCoords();g()},onStart:function(){h.setActive(false)}});return this},fxRemove:function(e){e||(e={});var f=function(){},g=e.onComplete||f,d=e.onChange||f,h=this;c.util.animate({startValue:this.get("opacity"),endValue:0,duration:this.FX_DURATION,onChange:function(k){h.set("opacity",k);d()},onComplete:g,onStart:function(){h.setActive(false)}});return this},_getAngleValueForStraighten:function(){var d=this.get("angle");if(d>-225&&d<=-135){return -180}else{if(d>-135&&d<=-45){return -90}else{if(d>-45&&d<=45){return 0}else{if(d>45&&d<=135){return 90}else{if(d>135&&d<=225){return 180}else{if(d>225&&d<=315){return 270}else{if(d>315){return 360}}}}}}}return 0}});c.Object.prototype.rotate=c.Object.prototype.setAngle})();(function(){var a=this.fabric||(this.fabric={});if(a.Line){return}a.Line=a.util.createClass(a.Object,{type:"line",initialize:function(c,b){if(!c){c=[0,0,0,0]}this.callSuper("initialize",b);this.set("x1",c[0]);this.set("y1",c[1]);this.set("x2",c[2]);this.set("y2",c[3]);this.set("width",this.x2-this.x1);this.set("height",this.y2-this.y1);this.set("left",this.x1+this.width/2);this.set("top",this.y1+this.height/2)},_render:function(b){b.beginPath();b.moveTo(-this.width/2,-this.height/2);b.lineTo(this.width/2,this.height/2);b.stroke()},complexity:function(){return 1},toObject:function(){return a.util.object.extend(this.callSuper("toObject"),{x1:this.get("x1"),y1:this.get("y1"),x2:this.get("x2"),y2:this.get("y2")})}});a.Element.ATTRIBUTE_NAMES="x1 y1 x2 y2 stroke stroke-width transform".split(" ");a.Line.fromElement=function(c,b){var e=a.parseAttributes(c,a.Element.ATTRIBUTE_NAMES);var d=[e.x1||0,e.y1||0,e.x2||0,e.y2||0];return new a.Line(d,a.util.object.extend(e,b))};a.Line.fromObject=function(b){var c=[b.x1,b.y1,b.x2,b.y2];return new a.Line(c,b)}})();(function(){var a=this,b=a.fabric||(a.fabric={}),d=Math.PI*2;if(b.Circle){console.warn("fabric.Circle is already defined.");return}b.Circle=b.util.createClass(b.Object,{type:"circle",initialize:function(e){e=e||{};this.set("radius",e.radius||0);this.callSuper("initialize",e);var f=this.get("radius")*2*this.get("scaleX");this.set("width",f).set("height",f)},toObject:function(){return b.util.object.extend(this.callSuper("toObject"),{radius:this.get("radius")})},_render:function(e){e.beginPath();e.arc(0,0,this.radius,0,d,false);if(this.fill){e.fill()}if(this.stroke){e.stroke()}},complexity:function(){return 1}});b.Circle.ATTRIBUTE_NAMES="cx cy r fill fill-opacity stroke stroke-width transform".split(" ");b.Circle.fromElement=function(f,e){var g=b.parseAttributes(f,b.Circle.ATTRIBUTE_NAMES);if(!c(g)){throw Error("value of `r` attribute is required and can not be negative")}return new b.Circle(b.util.object.extend(g,e))};function c(e){return(("radius" in e)&&(e.radius>0))}b.Circle.fromObject=function(e){return new b.Circle(e)}})();(function(){var a=this.fabric||(this.fabric={});if(a.Ellipse){console.warn("fabric.Ellipse is already defined.");return}a.Ellipse=a.util.createClass(a.Object,{type:"ellipse",initialize:function(b){b=b||{};this.callSuper("initialize",b);this.set("rx",b.rx||0);this.set("ry",b.ry||0);this.set("width",this.get("rx")*2);this.set("height",this.get("ry")*2)},toObject:function(){return a.util.object.extend(this.callSuper("toObject"),{rx:this.get("rx"),ry:this.get("ry")})},render:function(b,c){if(this.rx===0||this.ry===0){return}return this.callSuper("render",b,c)},_render:function(b){b.beginPath();b.save();b.transform(1,0,0,this.ry/this.rx,0,0);b.arc(0,0,this.rx,0,Math.PI*2,false);b.restore();if(this.stroke){b.stroke()}if(this.fill){b.fill()}},complexity:function(){return 1}});a.Ellipse.ATTRIBUTE_NAMES="cx cy rx ry fill fill-opacity stroke stroke-width transform".split(" ");a.Ellipse.fromElement=function(c,b){var d=a.parseAttributes(c,a.Ellipse.ATTRIBUTE_NAMES);return new a.Ellipse(a.util.object.extend(d,b))};a.Ellipse.fromObject=function(b){return new a.Ellipse(b)}})();(function(){var b=this.fabric||(this.fabric={});if(b.Rect){return}b.Rect=b.util.createClass(b.Object,{type:"rect",options:{rx:0,ry:0},initialize:function(c){this.callSuper("initialize",c);this._initRxRy()},_initRxRy:function(){if(this.options.rx&&!this.options.ry){this.options.ry=this.options.rx}else{if(this.options.ry&&!this.options.rx){this.options.rx=this.options.ry}}},_render:function(e){var k=this.options.rx||0,g=this.options.ry||0,c=-this.width/2,l=-this.height/2,d=this.width,f=this.height;e.beginPath();e.moveTo(c+k,l);e.lineTo(c+d-k,l);e.bezierCurveTo(c+d,l,c+d,l+g,c+d,l+g);e.lineTo(c+d,l+f-g);e.bezierCurveTo(c+d,l+f,c+d-k,l+f,c+d-k,l+f);e.lineTo(c+k,l+f);e.bezierCurveTo(c,l+f,c,l+f-g,c,l+f-g);e.lineTo(c,l+g);e.bezierCurveTo(c,l,c+k,l,c+k,l);e.closePath();if(this.fill){e.fill()}if(this.stroke){e.stroke()}},_normalizeLeftTopProperties:function(c){if(c.left){this.set("left",c.left+this.getWidth()/2)}if(c.top){this.set("top",c.top+this.getHeight()/2)}return this},complexity:function(){return 1}});b.Rect.ATTRIBUTE_NAMES="x y width height rx ry fill fill-opacity stroke stroke-width transform".split(" ");function a(c){c.left=c.left||0;c.top=c.top||0;return c}b.Rect.fromElement=function(d,c){if(!d){return null}var f=b.parseAttributes(d,b.Rect.ATTRIBUTE_NAMES);f=a(f);var e=new b.Rect(b.util.object.extend(c||{},f));e._normalizeLeftTopProperties(f);return e};b.Rect.fromObject=function(c){return new b.Rect(c)}})();(function(){var b=this.fabric||(this.fabric={});if(b.Polyline){console.warn("fabric.Polyline is already defined");return}b.Polyline=b.util.createClass(b.Object,{type:"polyline",initialize:function(d,c){c=c||{};this.set("points",d);this.callSuper("initialize",c);this._calcDimensions()},_calcDimensions:function(){return b.Polygon.prototype._calcDimensions.call(this)},_toOrigin:function(){return b.Polygon.prototype._toOrigin.call(this)},toObject:function(){return b.Polygon.prototype.toObject.call(this)},_render:function(e){var d;e.beginPath();for(var f=0,c=this.points.length;f"},toObject:function(){var c=b.util.object.extend(this.callSuper("toObject"),{path:this.path});if(this.sourcePath){c.sourcePath=this.sourcePath}if(this.transformMatrix){c.transformMatrix=this.transformMatrix}return c},toDatalessObject:function(){var c=this.toObject();if(this.sourcePath){c.path=this.sourcePath}delete c.sourcePath;return c},complexity:function(){return this.path.length},set:function(d,c){if(this.stub){this.stub.set(d,c)}return this.callSuper("set",d,c)},_parsePath:function(){var d=[],f,g;for(var e=0,c=this.path.length;e"},isSameColor:function(){var c=this.getObjects()[0].get("fill");return this.getObjects().every(function(d){return d.get("fill")===c})},complexity:function(){return this.paths.reduce(function(c,d){return c+((d&&d.complexity)?d.complexity():0)},0)},toGrayscale:function(){var c=this.paths.length;while(c--){this.paths[c].toGrayscale()}return this},getObjects:function(){return this.paths}});function a(f){for(var e=0,c=f.length;e"},getObjects:function(){return this.objects},add:function(b){this._restoreObjectsState();this.objects.push(b);b.setActive(true);this._calcBounds();this._updateObjectsCoords();return this},remove:function(b){this._restoreObjectsState();a.util.removeFromArray(this.objects,b);b.setActive(false);this._calcBounds();this._updateObjectsCoords();return this},size:function(){return this.getObjects().length},set:function(b,d){if(typeof d=="function"){this.set(b,d(this[b]))}else{if(b==="fill"||b==="opacity"){var c=this.objects.length;this[b]=d;while(c--){this.objects[c].set(b,d)}}else{this[b]=d}}return this},contains:function(b){return this.objects.indexOf(b)>-1},toObject:function(){return a.util.object.extend(this.callSuper("toObject"),{objects:a.util.array.invoke(this.objects,"clone")})},render:function(c){c.save();this.transform(c);var f=Math.max(this.scaleX,this.scaleY);for(var d=0,b=this.objects.length;dc.x&&d-bc.y},toGrayscale:function(){var b=this.objects.length;while(b--){this.objects[b].toGrayscale()}}});a.Group.fromObject=function(b){return new a.Group(b.objects,b)}})();(function(){var a=this.fabric||(this.fabric={});if(a.Text){console.warn("fabric.Text is already defined");return}if(!a.Object){console.warn("fabric.Text requires fabric.Object");return}a.Text=a.util.createClass(a.Object,{options:{top:10,left:10,fontsize:20,fontweight:100,fontfamily:"Modernist_One_400",path:null},type:"text",initialize:function(c,b){this.originalState={};this.initStateProperties();this.text=c;this.setOptions(b);a.util.object.extend(this,this.options);this.theta=this.angle*(Math.PI/180);this.width=this.getWidth();this.setCoords()},initStateProperties:function(){var b;if((b=this.constructor)&&(b=b.superclass)&&(b=b.prototype)&&(b=b.stateProperties)&&b.clone){this.stateProperties=b.clone();this.stateProperties.push("fontfamily","fontweight","path")}},toString:function(){return"#"},_render:function(b){var d=Cufon.textOptions||(Cufon.textOptions={});d.left=this.left;d.top=this.top;d.context=b;d.color=this.fill;var c=this._initDummyElement();this.transform(b);Cufon.replaceElement(c,{separate:"none",fontFamily:this.fontfamily});this.width=d.width;this.height=d.height},_initDummyElement:function(){var b=document.createElement("div");b.innerHTML=this.text;b.style.fontSize="40px";b.style.fontWeight="400";b.style.fontStyle="normal";b.style.letterSpacing="normal";b.style.color="#000000";b.style.fontWeight="600";b.style.fontFamily="Verdana";return b},render:function(b){b.save();this._render(b);if(this.active){this.drawBorders(b);this.drawCorners(b)}b.restore()},toObject:function(){return a.util.object.extend(this.callSuper("toObject"),{text:this.text,fontsize:this.fontsize,fontweight:this.fontweight,fontfamily:this.fontfamily,path:this.path})},setColor:function(b){this.set("fill",b);return this},setFontsize:function(b){this.set("fontsize",b);this.setCoords();return this},getText:function(){return this.text},setText:function(b){this.set("text",b);this.setCoords();return this},set:function(b,c){this[b]=c;if(b==="fontfamily"){this.path=this.path.replace(/(.*?)([^\/]*)(\.font\.js)/,"$1"+c+"$3")}return this}});a.Text.fromObject=function(b){return new a.Text(b.text,a.util.object.clone(b))};a.Text.fromElement=function(b){}})();(function(){var a=this;if(!a.fabric){a.fabric={}}if(a.fabric.Image){console.warn("fabric.Image is already defined.");return}if(!fabric.Object){console.warn("fabric.Object is required for fabric.Image initialization");return}fabric.Image=fabric.util.createClass(fabric.Object,{maxwidth:null,maxheight:null,active:false,bordervisibility:false,cornervisibility:false,type:"image",__isGrayscaled:false,initialize:function(c,b){this.callSuper("initialize",b);this._initElement(c);this._initConfig(b||{})},getElement:function(){return this._element},setElement:function(b){this._element=b;return this},getNormalizedSize:function(c,b,d){if(d&&b&&(c.width>c.height&&(c.width/c.height)<(b/d))){normalizedWidth=Math.floor((c.width*d)/c.height);normalizedHeight=d}else{if(d&&((c.height==c.width)||(c.height>c.width)||(c.height>d))){normalizedWidth=Math.floor((c.width*d)/c.height);normalizedHeight=d}else{if(b&&(b'},clone:function(b){this.constructor.fromObject(this.toObject(),b)},toGrayscale:function(f){if(this.__isGrayscaled){return}var d=this.getElement(),b=document.createElement("canvas"),c=document.createElement("img"),e=this;b.width=d.width;b.height=d.height;b.getContext("2d").drawImage(d,0,0);fabric.Element.toGrayscale(b);c.onload=function(){e.setElement(c);f&&f();c.onload=b=d=imageData=null};c.width=d.width;c.height=d.height;c.src=b.toDataURL("image/png");this.__isGrayscaled=true;return this},_render:function(c){var b=this.getOriginalSize();c.drawImage(this.getElement(),-b.width/2,-b.height/2,b.width,b.height)},_adjustWidthHeightToBorders:function(b){if(b){this.currentBorder=this.borderwidth;this.width+=(2*this.currentBorder);this.height+=(2*this.currentBorder)}else{this.currentBorder=0}},_resetWidthHeight:function(){var b=this.getElement();this.set("width",b.width);this.set("height",b.height)},_initElement:function(b){this.setElement(fabric.util.getById(b));fabric.util.addClass(this.getElement(),fabric.Image.CSS_CANVAS)},_initConfig:function(b){this.setOptions(b);this._setBorder();this._setWidthHeight(b)},_setBorder:function(){if(this.bordervisibility){this.currentBorder=this.borderwidth}else{this.currentBorder=0}},_setWidthHeight:function(b){var c=2*this.currentBorder;this.width=(this.getElement().width||0)+c;this.height=(this.getElement().height||0)+c}});fabric.Image.CSS_CANVAS="canvas-img";fabric.Image.fromObject=function(c,e){var b=document.createElement("img"),d=c.src;if(c.width){b.width=c.width}if(c.height){b.height=c.height}b.onload=function(){if(e){e(new fabric.Image(b,c))}b=b.onload=null};b.src=d};fabric.Image.fromURL=function(c,e,d){var b=document.createElement("img");b.onload=function(){if(e){e(new fabric.Image(b,d))}b=b.onload=null};b.src=c}})(); \ No newline at end of file diff --git a/fabric.js b/fabric.js index a9368a00..7cea3927 100644 --- a/fabric.js +++ b/fabric.js @@ -1,36 +1,37 @@ /*! Fabric.js Copyright 2010, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ if (typeof console == 'undefined') { - var console = { log: function() { }, warn: function() { } }; + var console = { + log: function() { }, + warn: function() { } + }; } //= require "lib/json2" -//= require "src/canvas_base" +//= require "src/util" +//= require "src/parser" + +//= require "src/point.class" +//= require "src/intersection.class" -//= require "src/canvas_util" -//= require "src/canvas_parser" +//= require "src/color.class" -//= require "src/canvas_point.class" -//= require "src/canvas_intersection.class" +//= require "src/element.class" -//= require "src/canvas_color.class" +//= require "src/object.class" +//= require "src/line.class" +//= require "src/circle.class" +//= require "src/ellipse.class" +//= require "src/rect.class" +//= require "src/polyline.class" +//= require "src/polygon.class" -//= require "src/canvas_element.class" +//= require "src/path.class" +//= require "src/path_group.class" -//= require "src/canvas_object.class" -//= require "src/canvas_line.class" -//= require "src/canvas_circle.class" -//= require "src/canvas_ellipse.class" -//= require "src/canvas_rect.class" -//= require "src/canvas_polyline.class" -//= require "src/canvas_polygon.class" +//= require "src/group.class" -//= require "src/canvas_path.class" -//= require "src/canvas_path_group.class" +//= require "src/text.class" -//= require "src/canvas_group.class" - -//= require "src/canvas_text.class" - -//= require "src/canvas_image.class" \ No newline at end of file +//= require "src/image.class" \ No newline at end of file diff --git a/src/canvas_base.js b/src/canvas_base.js deleted file mode 100644 index dae1d3e2..00000000 --- a/src/canvas_base.js +++ /dev/null @@ -1,21 +0,0 @@ -(function (global) { - - var fabric = this.fabric || (this.fabric = { }); - fabric.base = { }; - - var slice = Array.prototype.slice; - - //= require "canvas_base/lang_array" - //= require "canvas_base/lang_object" - //= require "canvas_base/lang_string" - //= require "canvas_base/lang_function" - - //= require "canvas_base/lang_class" - - //= require "canvas_base/dom_event" - //= require "canvas_base/dom_style" - //= require "canvas_base/dom_misc" - - //= require "canvas_base/dom_request" - -})(this); \ No newline at end of file diff --git a/src/canvas_circle.class.js b/src/circle.class.js similarity index 92% rename from src/canvas_circle.class.js rename to src/circle.class.js index e7c8510b..e79bf824 100644 --- a/src/canvas_circle.class.js +++ b/src/circle.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function() { @@ -11,7 +11,7 @@ return; } - fabric.Circle = fabric.base.createClass(fabric.Object, /** @lends fabric.Circle.prototype */ { + fabric.Circle = fabric.util.createClass(fabric.Object, /** @lends fabric.Circle.prototype */ { /** * @field @@ -40,7 +40,7 @@ * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { radius: this.get('radius') }); }, @@ -89,7 +89,7 @@ if (!isValidRadius(parsedAttributes)) { throw Error('value of `r` attribute is required and can not be negative'); } - return new fabric.Circle(fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Circle(fabric.util.object.extend(parsedAttributes, options)); }; /** diff --git a/src/canvas_color.class.js b/src/color.class.js similarity index 100% rename from src/canvas_color.class.js rename to src/color.class.js diff --git a/src/canvas_element.class.js b/src/element.class.js similarity index 96% rename from src/canvas_element.class.js rename to src/element.class.js index c3abc5a7..a919826a 100644 --- a/src/canvas_element.class.js +++ b/src/element.class.js @@ -16,7 +16,7 @@ STROKE_OFFSET = 0.5, FX_TRANSITION = 'decel', - getPointer = fabric.base.getPointer, + getPointer = fabric.util.getPointer, cursorMap = { 'tr': 'ne-resize', @@ -182,7 +182,7 @@ this.calcOffset(); }; - fabric.base.object.extend(fabric.Element.prototype, { + fabric.util.object.extend(fabric.Element.prototype, { selectionColor: 'rgba(100,100,255,0.3)', // blue selectionBorderColor: 'rgba(255,255,255,0.3)', @@ -207,7 +207,7 @@ * @chainable */ calcOffset: function () { - this._offset = fabric.base.getElementOffset(this.getElement()); + this._offset = fabric.util.getElementOffset(this.getElement()); return this; }, @@ -244,7 +244,7 @@ * */ _initElement: function (canvasEl) { - var el = fabric.base.getById(canvasEl); + var el = fabric.util.getById(canvasEl); this._oElement = el || document.createElement('canvas'); if (typeof this._oElement.getContext === 'undefined') { @@ -269,12 +269,12 @@ * @method _initWrapperElement */ _initWrapperElement: function (width, height) { - var wrapper = fabric.base.wrapElement(this.getElement(), 'div', { className: 'canvas_container' }); - fabric.base.setStyle(wrapper, { + var wrapper = fabric.util.wrapElement(this.getElement(), 'div', { className: 'canvas_container' }); + fabric.util.setStyle(wrapper, { width: width + 'px', height: height + 'px' }); - fabric.base.makeElementUnselectable(wrapper); + fabric.util.makeElementUnselectable(wrapper); this.wrapper = wrapper; }, @@ -283,7 +283,7 @@ * @method _setElementStyle */ _setElementStyle: function (width, height) { - fabric.base.setStyle(this.getElement(), { + fabric.util.setStyle(this.getElement(), { position: 'absolute', width: width + 'px', height: height + 'px', @@ -300,7 +300,7 @@ * See configuration documentation for more details. */ _initConfig: function (oConfig) { - fabric.base.object.extend(this._oConfig, oConfig || { }); + fabric.util.object.extend(this._oConfig, oConfig || { }); this._oConfig.width = parseInt(this._oElement.width, 10) || 0; this._oConfig.height = parseInt(this._oElement.height, 10) || 0; @@ -324,10 +324,10 @@ this._onMouseMove = function (e){ _this.__onMouseMove(e); }; this._onResize = function (e) { _this.calcOffset() }; - fabric.base.addListener(this._oElement, 'mousedown', this._onMouseDown); - fabric.base.addListener(document, 'mousemove', this._onMouseMove); - fabric.base.addListener(document, 'mouseup', this._onMouseUp); - fabric.base.addListener(window, 'resize', this._onResize); + fabric.util.addListener(this._oElement, 'mousedown', this._onMouseDown); + fabric.util.addListener(document, 'mousemove', this._onMouseMove); + fabric.util.addListener(document, 'mouseup', this._onMouseUp); + fabric.util.addListener(window, 'resize', this._onResize); }, /** @@ -361,7 +361,7 @@ // if that didn't work, throw error throw CANVAS_INIT_ERROR; } - fabric.base.makeElementUnselectable(oContainer); + fabric.util.makeElementUnselectable(oContainer); return oContainer; }, @@ -476,7 +476,7 @@ target = transform.target; if (target.__scaling) { - fabric.base.fireEvent('object:scaled', { target: target }); + fabric.util.fireEvent('object:scaled', { target: target }); target.__scaling = false; } @@ -488,7 +488,7 @@ // only fire :modified event if target coordinates were changed during mousedown-mouseup if (target.hasStateChanged()) { target.isMoving = false; - fabric.base.fireEvent('object:modified', { target: target }); + fabric.util.fireEvent('object:modified', { target: target }); } } @@ -502,7 +502,7 @@ if (activeGroup) { if (activeGroup.hasStateChanged() && activeGroup.containsPoint(this.getPointer(e))) { - fabric.base.fireEvent('group:modified', { target: activeGroup }); + fabric.util.fireEvent('group:modified', { target: activeGroup }); } activeGroup.setObjectsCoords(); activeGroup.set('isMoving', false); @@ -609,15 +609,15 @@ deactivateAllWithDispatch: function () { var activeGroup = this.getActiveGroup(); if (activeGroup) { - fabric.base.fireEvent('before:group:destroyed', { + fabric.util.fireEvent('before:group:destroyed', { target: activeGroup }); } this.deactivateAll(); if (activeGroup) { - fabric.base.fireEvent('after:group:destroyed'); + fabric.util.fireEvent('after:group:destroyed'); } - fabric.base.fireEvent('selection:cleared'); + fabric.util.fireEvent('selection:cleared'); return this; }, @@ -681,7 +681,7 @@ else { activeGroup.add(target); } - fabric.base.fireEvent('group:selected', { target: activeGroup }); + fabric.util.fireEvent('group:selected', { target: activeGroup }); activeGroup.setActive(true); } else { @@ -948,7 +948,7 @@ // do not create group for 1 element only if (group.length === 1) { this.setActiveObject(group[0]); - fabric.base.fireEvent('object:selected', { + fabric.util.fireEvent('object:selected', { target: group[0] }); } @@ -956,7 +956,7 @@ var group = new fabric.Group(group); this.setActiveGroup(group); group.saveCoords(); - fabric.base.fireEvent('group:selected', { target: group }); + fabric.util.fireEvent('group:selected', { target: group }); } this.renderAll(); }, @@ -1503,7 +1503,7 @@ switch (o.type) { case 'image': case 'font': - fabric[fabric.base.string.capitalize(o.type)].fromObject(o, function (o) { + fabric[fabric.util.string.capitalize(o.type)].fromObject(o, function (o) { _this.add(o); if (++numLoadedImages === numTotalImages) { if (callback) callback(); @@ -1511,7 +1511,7 @@ }); break; default: - var klass = fabric[fabric.base.string.camelize(fabric.base.string.capitalize(o.type))]; + var klass = fabric[fabric.util.string.camelize(fabric.util.string.capitalize(o.type))]; if (klass && klass.fromObject) { _this.add(klass.fromObject(o)); } @@ -1585,7 +1585,7 @@ _this.loadImageFromURL(path, function (image) { image.setSourcePath(path); - fabric.base.object.extend(image, obj); + fabric.util.object.extend(image, obj); image.setAngle(obj.angle); onObjectLoaded(image, index); @@ -1608,7 +1608,7 @@ } } - fabric.base.getScript(path, onscriptload); + fabric.util.getScript(path, onscriptload); } else { _this.loadSVGFromURL(path, function (elements, options) { @@ -1623,7 +1623,7 @@ // 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.base.object.extend(object, obj); + fabric.util.object.extend(object, obj); if (typeof obj.angle !== 'undefined') { object.setAngle(obj.angle); } @@ -1880,7 +1880,7 @@ this.renderAll(); - fabric.base.fireEvent('object:selected', { target: object }); + fabric.util.fireEvent('object:selected', { target: object }); return this; }, @@ -1987,10 +1987,10 @@ */ dispose: function () { this.clear(); - fabric.base.removeListener(this.getElement(), 'mousedown', this._onMouseDown); - fabric.base.removeListener(document, 'mouseup', this._onMouseUp); - fabric.base.removeListener(document, 'mousemove', this._onMouseMove); - fabric.base.removeListener(window, 'resize', this._onResize); + fabric.util.removeListener(this.getElement(), 'mousedown', this._onMouseDown); + fabric.util.removeListener(document, 'mouseup', this._onMouseUp); + fabric.util.removeListener(document, 'mousemove', this._onMouseMove); + fabric.util.removeListener(window, 'resize', this._onResize); return this; }, @@ -2059,7 +2059,7 @@ '{ objects: ' + this.getObjects().length + ' }>'; }; - fabric.base.object.extend(fabric.Element, { + fabric.util.object.extend(fabric.Element, { /** * @property EMPTY_JSON diff --git a/src/canvas_ellipse.class.js b/src/ellipse.class.js similarity index 92% rename from src/canvas_ellipse.class.js rename to src/ellipse.class.js index df7edd3c..c10fda18 100644 --- a/src/canvas_ellipse.class.js +++ b/src/ellipse.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function(){ @@ -9,7 +9,7 @@ return; } - fabric.Ellipse = fabric.base.createClass(fabric.Object, { + fabric.Ellipse = fabric.util.createClass(fabric.Object, { type: 'ellipse', @@ -37,7 +37,7 @@ * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { rx: this.get('rx'), ry: this.get('ry') }) @@ -93,7 +93,7 @@ */ fabric.Ellipse.fromElement = function(element, options) { var parsedAttributes = fabric.parseAttributes(element, fabric.Ellipse.ATTRIBUTE_NAMES); - return new fabric.Ellipse(fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Ellipse(fabric.util.object.extend(parsedAttributes, options)); }; /** diff --git a/src/canvas_group.class.js b/src/group.class.js similarity index 96% rename from src/canvas_group.class.js rename to src/group.class.js index 5605250a..1d398781 100644 --- a/src/canvas_group.class.js +++ b/src/group.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function(){ @@ -7,7 +7,7 @@ return; } - fabric.Group = fabric.base.createClass(fabric.Object, { + fabric.Group = fabric.util.createClass(fabric.Object, { /** * @property type @@ -29,7 +29,7 @@ this._updateObjectsCoords(); if (options) { - fabric.base.object.extend(this, options); + fabric.util.object.extend(this, options); } this._setOpacityIfSame(); @@ -165,8 +165,8 @@ * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { - objects: fabric.base.array.invoke(this.objects, 'clone') + return fabric.util.object.extend(this.callSuper('toObject'), { + objects: fabric.util.array.invoke(this.objects, 'clone') }); }, @@ -377,10 +377,10 @@ } }; - minX = fabric.base.array.min(aX); - maxX = fabric.base.array.max(aX); - minY = fabric.base.array.min(aY); - maxY = fabric.base.array.max(aY); + minX = fabric.util.array.min(aX); + maxX = fabric.util.array.max(aX); + minY = fabric.util.array.min(aY); + maxY = fabric.util.array.max(aY); width = maxX - minX; height = maxY - minY; diff --git a/src/canvas_image.class.js b/src/image.class.js similarity index 96% rename from src/canvas_image.class.js rename to src/image.class.js index 05982e8c..69f472b5 100644 --- a/src/canvas_image.class.js +++ b/src/image.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function() { @@ -19,7 +19,7 @@ } - fabric.Image = fabric.base.createClass(fabric.Object, { + fabric.Image = fabric.util.createClass(fabric.Object, { maxwidth: null, maxheight: null, @@ -145,7 +145,7 @@ * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { src: this.getSrc() }); }, @@ -255,8 +255,8 @@ * @param {HTMLImageElement|String} el The element representing the image */ _initElement: function(element) { - this.setElement(fabric.base.getById(element)); - fabric.base.addClass(this.getElement(), fabric.Image.CSS_CANVAS); + this.setElement(fabric.util.getById(element)); + fabric.util.addClass(this.getElement(), fabric.Image.CSS_CANVAS); }, /** diff --git a/src/canvas_intersection.class.js b/src/intersection.class.js similarity index 95% rename from src/canvas_intersection.class.js rename to src/intersection.class.js index 82511660..8c33dc47 100644 --- a/src/canvas_intersection.class.js +++ b/src/intersection.class.js @@ -1,4 +1,4 @@ -//= require 'canvas_point.class' +//= require 'point.class' (function() { diff --git a/src/canvas_line.class.js b/src/line.class.js similarity index 92% rename from src/canvas_line.class.js rename to src/line.class.js index 09c6a5cc..e21bf68e 100644 --- a/src/canvas_line.class.js +++ b/src/line.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function(){ @@ -7,7 +7,7 @@ return; } - fabric.Line = fabric.base.createClass(fabric.Object, { + fabric.Line = fabric.util.createClass(fabric.Object, { type: 'line', @@ -62,7 +62,7 @@ * @return {Object} */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { x1: this.get('x1'), y1: this.get('y1'), x2: this.get('x2'), @@ -89,7 +89,7 @@ parsedAttributes.x2 || 0, parsedAttributes.y2 || 0 ]; - return new fabric.Line(points, fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Line(points, fabric.util.object.extend(parsedAttributes, options)); }; /** diff --git a/src/canvas_object.class.js b/src/object.class.js similarity index 98% rename from src/canvas_object.class.js rename to src/object.class.js index 4f5022b2..297a6386 100644 --- a/src/canvas_object.class.js +++ b/src/object.class.js @@ -18,7 +18,7 @@ * @class Object * @memberOf Canvas */ - fabric.Object = fabric.base.createClass({ + fabric.Object = fabric.util.createClass({ type: 'object', @@ -107,7 +107,7 @@ setOptions: function(options) { // this.constructor.superclass.prototype.options -> this.options -> options - this.options = fabric.base.object.extend(this._getOptions(), options); + this.options = fabric.util.object.extend(this._getOptions(), options); }, /** @@ -115,7 +115,7 @@ * @method _getOptions */ _getOptions: function() { - return fabric.base.object.extend(fabric.base.object.clone(this._getSuperOptions()), this.options); + return fabric.util.object.extend(fabric.util.object.clone(this._getSuperOptions()), this.options); }, /** @@ -248,7 +248,7 @@ * @return {String} */ toString: function() { - return "#"; + return "#"; }, /** @@ -672,7 +672,7 @@ el.width = this.getWidth(); el.height = this.getHeight(); - fabric.base.wrapElement(el, 'div'); + fabric.util.wrapElement(el, 'div'); var canvas = new fabric.Element(el); canvas.backgroundColor = 'transparent'; @@ -799,7 +799,7 @@ * @return {String|Boolean} corner code (tl, tr, bl, br, etc.), or false if nothing is found */ _findTargetCorner: function(e, offset) { - var pointer = fabric.base.getPointer(e), + var pointer = fabric.util.getPointer(e), ex = pointer.x - offset.left, ey = pointer.y - offset.top, xpoints, @@ -1170,7 +1170,7 @@ onChange = callbacks.onChange || empty, _this = this; - fabric.base.animate({ + fabric.util.animate({ startValue: this.get('angle'), endValue: this._getAngleValueForStraighten(), duration: this.FX_DURATION, @@ -1204,7 +1204,7 @@ onChange = callbacks.onChange || empty, _this = this; - fabric.base.animate({ + fabric.util.animate({ startValue: this.get('opacity'), endValue: 0, duration: this.FX_DURATION, diff --git a/src/canvas_parser.js b/src/parser.js similarity index 96% rename from src/canvas_parser.js rename to src/parser.js index afcd98aa..e6eb6458 100644 --- a/src/canvas_parser.js +++ b/src/parser.js @@ -61,8 +61,8 @@ // add values parsed from style // TODO (kangax): check the presedence of values from the style attribute - ownAttributes = fabric.base.object.extend(fabric.parseStyleAttribute(element), ownAttributes); - return fabric.base.object.extend(parentAttributes, ownAttributes); + ownAttributes = fabric.util.object.extend(fabric.parseStyleAttribute(element), ownAttributes); + return fabric.util.object.extend(parentAttributes, ownAttributes); }; /** @@ -260,7 +260,7 @@ function parseElements(elements, options) { // transform svg elements to fabric.Path elements var _elements = elements.map(function(el) { - var klass = fabric[fabric.base.string.capitalize(el.tagName)]; + var klass = fabric[fabric.util.string.capitalize(el.tagName)]; if (klass && klass.fromElement) { try { return klass.fromElement(el, options); @@ -313,7 +313,7 @@ return function(doc, callback) { if (!doc) return; - var descendants = fabric.base.toArray(doc.getElementsByTagName('*')); + var descendants = fabric.util.toArray(doc.getElementsByTagName('*')); var elements = descendants.filter(function(el) { return reAllowedSVGTagNames.test(el.tagName) && @@ -346,7 +346,7 @@ height: height }; - var elements = fabric.parseElements(elements, fabric.base.object.clone(options)); + var elements = fabric.parseElements(elements, fabric.util.object.clone(options)); if (!elements || (elements && !elements.length)) return; if (callback) { @@ -355,7 +355,7 @@ }; })(); - fabric.base.object.extend(fabric, { + fabric.util.object.extend(fabric, { parseAttributes: parseAttributes, parseElements: parseElements, parseStyleAttribute: parseStyleAttribute, diff --git a/src/canvas_path.class.js b/src/path.class.js similarity index 96% rename from src/canvas_path.class.js rename to src/path.class.js index 657eacb8..67d08a2a 100644 --- a/src/canvas_path.class.js +++ b/src/path.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function(){ @@ -14,7 +14,7 @@ } // Instance methods - fabric.Path = fabric.base.createClass(fabric.Object, { + fabric.Path = fabric.util.createClass(fabric.Object, { type: 'path', @@ -63,7 +63,7 @@ this.path = this._parsePath(); if (!isWidthSet || !isHeightSet) { - fabric.base.object.extend(this, this._parseDimensions()); + fabric.util.object.extend(this, this._parseDimensions()); if (isWidthSet) { this.width = this.options.width; } @@ -320,7 +320,7 @@ * @return {Object} */ toObject: function() { - var o = fabric.base.object.extend(this.callSuper('toObject'), { + var o = fabric.util.object.extend(this.callSuper('toObject'), { path: this.path }); if (this.sourcePath) { @@ -430,15 +430,15 @@ }, this); - var minX = fabric.base.array.min(aX), - minY = fabric.base.array.min(aY), + var minX = fabric.util.array.min(aX), + minY = fabric.util.array.min(aY), deltaX = deltaY = 0; var o = { top: minY - deltaY, left: minX - deltaX, - bottom: fabric.base.array.max(aY) - deltaY, - right: fabric.base.array.max(aX) - deltaX + bottom: fabric.util.array.max(aY) - deltaY, + right: fabric.util.array.max(aX) - deltaX }; o.width = o.right - o.left; @@ -471,6 +471,6 @@ var parsedAttributes = fabric.parseAttributes(element, ATTRIBUTE_NAMES), path = parsedAttributes.d; delete parsedAttributes.d; - return new fabric.Path(path, fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Path(path, fabric.util.object.extend(parsedAttributes, options)); } })(); \ No newline at end of file diff --git a/src/canvas_path_group.class.js b/src/path_group.class.js similarity index 95% rename from src/canvas_path_group.class.js rename to src/path_group.class.js index d5c83897..85d7a168 100644 --- a/src/canvas_path_group.class.js +++ b/src/path_group.class.js @@ -1,4 +1,4 @@ -//= require "canvas_path.class" +//= require "path.class" (function(){ @@ -9,7 +9,7 @@ return; } - fabric.PathGroup = fabric.base.createClass(fabric.Path, { + fabric.PathGroup = fabric.util.createClass(fabric.Path, { type: 'path-group', forceFillOverwrite: false, @@ -105,8 +105,8 @@ */ toObject: function() { var _super = fabric.Object.prototype.toObject; - return fabric.base.object.extend(_super.call(this), { - paths: fabric.base.array.invoke(this.getObjects(), 'clone'), + return fabric.util.object.extend(_super.call(this), { + paths: fabric.util.array.invoke(this.getObjects(), 'clone'), sourcePath: this.sourcePath }); }, diff --git a/src/canvas_point.class.js b/src/point.class.js similarity index 100% rename from src/canvas_point.class.js rename to src/point.class.js diff --git a/src/canvas_polygon.class.js b/src/polygon.class.js similarity index 87% rename from src/canvas_polygon.class.js rename to src/polygon.class.js index 34e7e586..fa08fe67 100644 --- a/src/canvas_polygon.class.js +++ b/src/polygon.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function(){ @@ -12,7 +12,7 @@ function byX(p) { return p.x; } function byY(p) { return p.y; } - fabric.Polygon = fabric.base.createClass(fabric.Object, { + fabric.Polygon = fabric.util.createClass(fabric.Object, { type: 'polygon', @@ -37,10 +37,10 @@ _calcDimensions: function() { var points = this.points, - minX = fabric.base.array.min(points, 'x'), - minY = fabric.base.array.min(points, 'y'), - maxX = fabric.base.array.max(points, 'x'), - maxY = fabric.base.array.max(points, 'y'); + minX = fabric.util.array.min(points, 'x'), + minY = fabric.util.array.min(points, 'y'), + maxX = fabric.util.array.max(points, 'x'), + maxY = fabric.util.array.max(points, 'y'); this.width = maxX - minX; this.height = maxY - minY; @@ -67,7 +67,7 @@ * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { points: this.points.concat() }); }, @@ -120,7 +120,7 @@ var points = fabric.parsePointsAttribute(element.getAttribute('points')), parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES); - return new fabric.Polygon(points, fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Polygon(points, fabric.util.object.extend(parsedAttributes, options)); }; /** diff --git a/src/canvas_polyline.class.js b/src/polyline.class.js similarity index 94% rename from src/canvas_polyline.class.js rename to src/polyline.class.js index 91975645..2aa62cd1 100644 --- a/src/canvas_polyline.class.js +++ b/src/polyline.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function(){ @@ -9,7 +9,7 @@ return; } - fabric.Polyline = fabric.base.createClass(fabric.Object, { + fabric.Polyline = fabric.util.createClass(fabric.Object, { type: 'polyline', @@ -98,7 +98,7 @@ var points = fabric.parsePointsAttribute(element.getAttribute('points')), parsedAttributes = fabric.parseAttributes(element, ATTRIBUTE_NAMES); - return new fabric.Polyline(points, fabric.base.object.extend(parsedAttributes, options)); + return new fabric.Polyline(points, fabric.util.object.extend(parsedAttributes, options)); }; /** diff --git a/src/canvas_rect.class.js b/src/rect.class.js similarity index 95% rename from src/canvas_rect.class.js rename to src/rect.class.js index 559ed947..310352dc 100644 --- a/src/canvas_rect.class.js +++ b/src/rect.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function(){ @@ -12,7 +12,7 @@ * @class Rect * @extends fabric.Object */ - fabric.Rect = fabric.base.createClass(fabric.Object, /** @lends fabric.Rect.prototype */ { + fabric.Rect = fabric.util.createClass(fabric.Object, /** @lends fabric.Rect.prototype */ { type: 'rect', @@ -125,7 +125,7 @@ var parsedAttributes = fabric.parseAttributes(element, fabric.Rect.ATTRIBUTE_NAMES); parsedAttributes = _setDefaultLeftTopValues(parsedAttributes); - var rect = new fabric.Rect(fabric.base.object.extend(options || { }, parsedAttributes)); + var rect = new fabric.Rect(fabric.util.object.extend(options || { }, parsedAttributes)); rect._normalizeLeftTopProperties(parsedAttributes); return rect; diff --git a/src/canvas_text.class.js b/src/text.class.js similarity index 94% rename from src/canvas_text.class.js rename to src/text.class.js index 16870705..9eb4fbc6 100644 --- a/src/canvas_text.class.js +++ b/src/text.class.js @@ -1,4 +1,4 @@ -//= require "canvas_object.class" +//= require "object.class" (function(){ @@ -13,7 +13,7 @@ return; } - fabric.Text = fabric.base.createClass(fabric.Object, { + fabric.Text = fabric.util.createClass(fabric.Object, { options: { top: 10, @@ -31,7 +31,7 @@ this.initStateProperties(); this.text = text; this.setOptions(options); - fabric.base.object.extend(this, this.options); + fabric.util.object.extend(this, this.options); this.theta = this.angle * (Math.PI/180); this.width = this.getWidth(); this.setCoords(); @@ -110,7 +110,7 @@ * @return {Object} object representation of an instance */ toObject: function() { - return fabric.base.object.extend(this.callSuper('toObject'), { + return fabric.util.object.extend(this.callSuper('toObject'), { text: this.text, fontsize: this.fontsize, fontweight: this.fontweight, @@ -177,7 +177,7 @@ * @return {fabric.Text} an instance */ fabric.Text.fromObject = function(object) { - return new fabric.Text(object.text, fabric.base.object.clone(object)); + return new fabric.Text(object.text, fabric.util.object.clone(object)); }; /** diff --git a/src/util.js b/src/util.js new file mode 100644 index 00000000..a7c2bc2d --- /dev/null +++ b/src/util.js @@ -0,0 +1,23 @@ +(function (global) { + + var fabric = this.fabric || (this.fabric = { }), + slice = Array.prototype.slice; + + fabric.util = { }; + + //= require "util/lang_array" + //= require "util/lang_object" + //= require "util/lang_string" + //= require "util/lang_function" + + //= require "util/lang_class" + + //= require "util/dom_event" + //= require "util/dom_style" + //= require "util/dom_misc" + + //= require "util/dom_request" + + //= require "util/misc" + +})(this); \ No newline at end of file diff --git a/src/canvas_base/dom_event.js b/src/util/dom_event.js similarity index 96% rename from src/canvas_base/dom_event.js rename to src/util/dom_event.js index 86ec86df..00b5f5df 100644 --- a/src/canvas_base/dom_event.js +++ b/src/util/dom_event.js @@ -140,8 +140,8 @@ }; } - fabric.base.addListener = addListener; - fabric.base.removeListener = removeListener; + fabric.util.addListener = addListener; + fabric.util.removeListener = removeListener; var customEventListeners = { }; @@ -167,8 +167,8 @@ } } - fabric.base.observeEvent = observeEvent; - fabric.base.fireEvent = fireEvent; + fabric.util.observeEvent = observeEvent; + fabric.util.fireEvent = fireEvent; // TODO (kangax): this method needs fixing function getPointer(event) { @@ -193,5 +193,5 @@ (docElement.clientTop || 0)); } - fabric.base.getPointer = getPointer; + fabric.util.getPointer = getPointer; })(this); \ No newline at end of file diff --git a/src/canvas_base/dom_misc.js b/src/util/dom_misc.js similarity index 90% rename from src/canvas_base/dom_misc.js rename to src/util/dom_misc.js index 1d5459f7..18a86f07 100644 --- a/src/canvas_base/dom_misc.js +++ b/src/util/dom_misc.js @@ -82,7 +82,7 @@ function falseFunction() { return false; }; return element; } - fabric.base.makeElementUnselectable = makeElementUnselectable + fabric.util.makeElementUnselectable = makeElementUnselectable })(); (function(){ @@ -115,11 +115,11 @@ function falseFunction() { return false; }; callback(); } - fabric.base.getScript = getScript; + fabric.util.getScript = getScript; var Jaxer = this.Jaxer; if (Jaxer && Jaxer.load) { - fabric.base.getScript = getScriptJaxer; + fabric.util.getScript = getScriptJaxer; } })(); @@ -149,10 +149,10 @@ function animate(options) { }, 10); } -fabric.base.getById = getById; -fabric.base.toArray = toArray; -fabric.base.makeElement = makeElement; -fabric.base.addClass = addClass; -fabric.base.wrapElement = wrapElement; -fabric.base.getElementOffset = getElementOffset; -fabric.base.animate = animate; \ No newline at end of file +fabric.util.getById = getById; +fabric.util.toArray = toArray; +fabric.util.makeElement = makeElement; +fabric.util.addClass = addClass; +fabric.util.wrapElement = wrapElement; +fabric.util.getElementOffset = getElementOffset; +fabric.util.animate = animate; \ No newline at end of file diff --git a/src/canvas_base/dom_request.js b/src/util/dom_request.js similarity index 97% rename from src/canvas_base/dom_request.js rename to src/util/dom_request.js index 4c48191c..d6dfc0e2 100644 --- a/src/canvas_base/dom_request.js +++ b/src/util/dom_request.js @@ -57,5 +57,5 @@ return request; }; - fabric.base.request = request; + fabric.util.request = request; })(); \ No newline at end of file diff --git a/src/canvas_base/dom_style.js b/src/util/dom_style.js similarity index 98% rename from src/canvas_base/dom_style.js rename to src/util/dom_style.js index ca157166..8618b85c 100644 --- a/src/canvas_base/dom_style.js +++ b/src/util/dom_style.js @@ -53,6 +53,6 @@ }; } - fabric.base.setStyle = setStyle; + fabric.util.setStyle = setStyle; })(); \ No newline at end of file diff --git a/src/canvas_base/lang_array.js b/src/util/lang_array.js similarity index 99% rename from src/canvas_base/lang_array.js rename to src/util/lang_array.js index e06fd01d..ff528470 100644 --- a/src/canvas_base/lang_array.js +++ b/src/util/lang_array.js @@ -154,7 +154,7 @@ function min(array, byProperty) { return result; } -fabric.base.array = { +fabric.util.array = { invoke: invoke, min: min, max: max diff --git a/src/canvas_base/lang_class.js b/src/util/lang_class.js similarity index 97% rename from src/canvas_base/lang_class.js rename to src/util/lang_class.js index 7d2c585b..49abdee8 100644 --- a/src/canvas_base/lang_class.js +++ b/src/util/lang_class.js @@ -59,5 +59,5 @@ return klass; } - fabric.base.createClass = createClass; + fabric.util.createClass = createClass; })(); \ No newline at end of file diff --git a/src/canvas_base/lang_function.js b/src/util/lang_function.js similarity index 100% rename from src/canvas_base/lang_function.js rename to src/util/lang_function.js diff --git a/src/canvas_base/lang_object.js b/src/util/lang_object.js similarity index 91% rename from src/canvas_base/lang_object.js rename to src/util/lang_object.js index ffb57afa..b32e5ea4 100644 --- a/src/canvas_base/lang_object.js +++ b/src/util/lang_object.js @@ -9,7 +9,7 @@ function clone(object) { return extend({ }, object); } -fabric.base.object = { +fabric.util.object = { extend: extend, clone: clone }; \ No newline at end of file diff --git a/src/canvas_base/lang_string.js b/src/util/lang_string.js similarity index 95% rename from src/canvas_base/lang_string.js rename to src/util/lang_string.js index e46cb067..acbe736d 100644 --- a/src/canvas_base/lang_string.js +++ b/src/util/lang_string.js @@ -14,7 +14,7 @@ function capitalize(string) { return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); } -fabric.base.string = { +fabric.util.string = { camelize: camelize, capitalize: capitalize }; \ No newline at end of file diff --git a/src/canvas_util.js b/src/util/misc.js similarity index 79% rename from src/canvas_util.js rename to src/util/misc.js index 6e9cd6d9..10a6c1aa 100644 --- a/src/canvas_util.js +++ b/src/util/misc.js @@ -1,12 +1,5 @@ (function(){ - var fabric = this.fabric || (this.fabric = { }); - - if (fabric.util) { - console.warn('fabric.util is already defined'); - return; - } - /** * @static * Removes value from an array. @@ -56,10 +49,8 @@ return parseFloat(Number(number).toFixed(fractionDigits)); } - fabric.util = { - removeFromArray: removeFromArray, - degreesToRadians: degreesToRadians, - toFixed: toFixed, - getRandomInt: getRandomInt - }; + fabric.util.removeFromArray = removeFromArray; + fabric.util.degreesToRadians = degreesToRadians; + fabric.util.toFixed = toFixed; + fabric.util.getRandomInt = getRandomInt; })(); \ No newline at end of file diff --git a/test/unit/canvas_circle.js b/test/unit/canvas_circle.js index 34adaaf3..6d52a247 100644 --- a/test/unit/canvas_circle.js +++ b/test/unit/canvas_circle.js @@ -44,7 +44,7 @@ circle.set('left', 100).set('top', 200).set('radius', 15); - var augmentedProperties = fabric.base.object.extend(fabric.base.object.clone(defaultProperties), { + var augmentedProperties = fabric.util.object.extend(fabric.util.object.clone(defaultProperties), { left: 100, top: 200, radius: 15 diff --git a/test/unit/canvas_element.js b/test/unit/canvas_element.js index 1ba16098..26226e45 100644 --- a/test/unit/canvas_element.js +++ b/test/unit/canvas_element.js @@ -34,7 +34,7 @@ function makeRect(options) { var defaultOptions = { width: 10, height: 10 }; - return new fabric.Rect(fabric.base.object.extend(defaultOptions, options || { })); + return new fabric.Rect(fabric.util.object.extend(defaultOptions, options || { })); } module('fabric.Element', { @@ -158,7 +158,7 @@ test('getPointer', function() { ok(typeof canvas.getPointer == 'function'); - fabric.base.addListener(canvasEl, 'click', function(e) { + fabric.util.addListener(canvasEl, 'click', function(e) { var pointer = canvas.getPointer(e); equals(pointer.x, 101, 'pointer.x should be correct'); equals(pointer.y, 102, 'pointer.y should be correct'); @@ -526,16 +526,16 @@ }; var target; - fabric.base.observeEvent('before:group:destroyed', function (e) { + fabric.util.observeEvent('before:group:destroyed', function (e) { eventsFired.beforeGroupDestroyed = true; equals(canvas.getActiveGroup(), e.memo.target, 'event should have active group as its `target` property'); }); - fabric.base.observeEvent('after:group:destroyed', function(){ + fabric.util.observeEvent('after:group:destroyed', function(){ eventsFired.afterGroupDestroyed = true; }); - fabric.base.observeEvent('selection:cleared', function(){ + fabric.util.observeEvent('selection:cleared', function(){ eventsFired.selectionCleared = true; }); @@ -647,7 +647,7 @@ canvas.add(rect); var canvasEl = canvas.getElement(), - canvasOffset = fabric.base.getElementOffset(canvasEl); + canvasOffset = fabric.util.getElementOffset(canvasEl); var eventStub = { pageX: canvasOffset.left + 100, @@ -700,7 +700,7 @@ asyncTest('resizeImageToFit', function() { ok(typeof canvas._resizeImageToFit == 'function'); - var imgEl = fabric.base.makeElement('img', { src: '../fixtures/very_large_image.jpg' }), + var imgEl = fabric.util.makeElement('img', { src: '../fixtures/very_large_image.jpg' }), ORIGINAL_WIDTH = 3888, ORIGINAL_HEIGHT = 2592; diff --git a/test/unit/canvas_ellipse.js b/test/unit/canvas_ellipse.js index 6fc32b1b..fa7bfc7c 100644 --- a/test/unit/canvas_ellipse.js +++ b/test/unit/canvas_ellipse.js @@ -45,7 +45,7 @@ ellipse.set('left', 100).set('top', 200).set('rx', 15).set('ry', 25); - var augmentedProperties = fabric.base.object.extend(fabric.base.object.clone(defaultProperties), { + var augmentedProperties = fabric.util.object.extend(fabric.util.object.clone(defaultProperties), { left: 100, top: 200, rx: 15, diff --git a/test/unit/canvas_group.js b/test/unit/canvas_group.js index 15798c5a..07597f95 100644 --- a/test/unit/canvas_group.js +++ b/test/unit/canvas_group.js @@ -271,10 +271,10 @@ ok(typeof group.setActive == 'function'); group.setActive(false); - same([false, false], fabric.base.array.invoke(group.getObjects(), 'isActive')); + same([false, false], fabric.util.array.invoke(group.getObjects(), 'isActive')); group.setActive(true); - same([true, true], fabric.base.array.invoke(group.getObjects(), 'isActive')); + same([true, true], fabric.util.array.invoke(group.getObjects(), 'isActive')); }); test('fromObject', function() { diff --git a/test/unit/canvas_parser.js b/test/unit/canvas_parser.js index 1b14b959..fddb839c 100644 --- a/test/unit/canvas_parser.js +++ b/test/unit/canvas_parser.js @@ -87,16 +87,16 @@ ok(fabric.parseElements); function getOptions(options) { - return fabric.base.object.extend(fabric.base.object.clone({ + return fabric.util.object.extend(fabric.util.object.clone({ left: 10, top: 20, width: 30, height: 40 }), options || { }); } var elements = [ - fabric.base.makeElement('rect', getOptions()), - fabric.base.makeElement('circle', getOptions({ r: 14 })), - fabric.base.makeElement('path', getOptions({ d: 'M 100 100 L 300 100 L 200 300 z' })), - fabric.base.makeElement('inexistent', getOptions()) + fabric.util.makeElement('rect', getOptions()), + fabric.util.makeElement('circle', getOptions({ r: 14 })), + fabric.util.makeElement('path', getOptions({ d: 'M 100 100 L 300 100 L 200 300 z' })), + fabric.util.makeElement('inexistent', getOptions()) ]; var parsedElements, error; @@ -206,7 +206,7 @@ ok(fabric.parseSVGDocument); var data; - fabric.base.request('../fixtures/path.svg', { + fabric.util.request('../fixtures/path.svg', { method: 'get', onComplete: function(resp) { var doc = resp.responseXML; diff --git a/test/unit/canvas_path.js b/test/unit/canvas_path.js index 8544c16f..8c93eebb 100644 --- a/test/unit/canvas_path.js +++ b/test/unit/canvas_path.js @@ -77,7 +77,7 @@ var src = 'http://example.com/'; path.setSourcePath(src); - same(fabric.base.object.extend(fabric.base.object.clone(REFERENCE_PATH_OBJECT), { + same(fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_OBJECT), { path: src }), path.toDatalessObject()); }); @@ -111,7 +111,7 @@ var path = fabric.Path.fromElement(elPath); ok(path instanceof fabric.Path); - same(fabric.base.object.extend(REFERENCE_PATH_OBJECT, { + same(fabric.util.object.extend(REFERENCE_PATH_OBJECT, { transformMatrix: [2, 0, 0, 2, 0, 0] }), path.toObject()); diff --git a/test/unit/canvas_path_group.js b/test/unit/canvas_path_group.js index 33660cef..f052b6e6 100644 --- a/test/unit/canvas_path_group.js +++ b/test/unit/canvas_path_group.js @@ -66,10 +66,10 @@ ok(typeof pathGroup.toObject == 'function'); var object = pathGroup.toObject(); - /*same(fabric.base.object.extend(fabric.base.object.clone(REFERENCE_PATH_GROUP_OBJECT), { + /*same(fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), { paths: object.paths }), object); - console.log(fabric.base.object.extend(fabric.base.object.clone(REFERENCE_PATH_GROUP_OBJECT), { + console.log(fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), { paths: object.paths }), object);*/ }); @@ -99,7 +99,7 @@ ok(typeof pathGroup.toDatalessObject == 'function'); pathGroup.setSourcePath('http://example.com/'); - var expectedObject = fabric.base.object.extend(fabric.base.object.clone(REFERENCE_PATH_GROUP_OBJECT), { + var expectedObject = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), { 'paths': 'http://example.com/', 'sourcePath': 'http://example.com/' }); diff --git a/test/unit/canvas_polygon.js b/test/unit/canvas_polygon.js index f12aad82..6139f848 100644 --- a/test/unit/canvas_polygon.js +++ b/test/unit/canvas_polygon.js @@ -82,7 +82,7 @@ var polygonWithAttrs = fabric.Polygon.fromElement(elPolygonWithAttrs); var expectedPoints = [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}, {x: 10, y: 10}]; - same(fabric.base.object.extend(REFERENCE_OBJECT, { + same(fabric.util.object.extend(REFERENCE_OBJECT, { 'width': 20, 'height': 20, 'fill': 'rgb(255,255,255)', diff --git a/test/unit/canvas_polyline.js b/test/unit/canvas_polyline.js index 046a0152..f734028e 100644 --- a/test/unit/canvas_polyline.js +++ b/test/unit/canvas_polyline.js @@ -81,7 +81,7 @@ var polylineWithAttrs = fabric.Polyline.fromElement(elPolylineWithAttrs); //var expectedPoints = [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}, {x: 10, y: 10}]; /* - same(fabric.base.object.extend(REFERENCE_OBJECT, { + same(fabric.util.object.extend(REFERENCE_OBJECT, { 'width': 20, 'height': 20, 'fill': 'rgb(255,255,255)', diff --git a/test/unit/canvas_rect.js b/test/unit/canvas_rect.js index 5d3a9d83..e5c5e061 100644 --- a/test/unit/canvas_rect.js +++ b/test/unit/canvas_rect.js @@ -78,7 +78,7 @@ var rectWithAttrs = fabric.Rect.fromElement(elRectWithAttrs); ok(rectWithAttrs instanceof fabric.Rect); - var expectedObject = fabric.base.object.extend(REFERENCE_RECT, { + var expectedObject = fabric.util.object.extend(REFERENCE_RECT, { left: 121, top: 186.5, width: 222, diff --git a/test/unit/extensions/ape_extensions.html b/test/unit/extensions/ape_extensions.html deleted file mode 100644 index 33b896a3..00000000 --- a/test/unit/extensions/ape_extensions.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - APE extensions unit tests - - - - - - - -

APE extensions unit tests

-
- - \ No newline at end of file diff --git a/test/unit/extensions/ape_extensions.js b/test/unit/extensions/ape_extensions.js deleted file mode 100644 index a9cc7c71..00000000 --- a/test/unit/extensions/ape_extensions.js +++ /dev/null @@ -1,34 +0,0 @@ -function init() { - new Test.Unit.Runner({ - testGetElement: function() { - this.assertRespondsTo('getElement', APE); - - var el = document.createElement('div'); - el.id = 'foo'; - document.body.appendChild(el); - - this.assertIdentical(el, APE.getElement('foo')); - this.assertIdentical(el, APE.getElement(el)); - }, - testEventPublisherRemove: function() { - - this.assertRespondsTo('remove', APE.EventPublisher); - - - var docEl = document.documentElement; - var numInvocations = 0; - - function onclick() { - numInvocations++; - } - - APE.EventPublisher.add(docEl, 'onclick', onclick); - Event.simulate(docEl, 'click'); - this.assertIdentical(1, numInvocations); - - APE.EventPublisher.remove(docEl, 'onclick', onclick); - Event.simulate(docEl, 'click'); - this.assertIdentical(1, numInvocations, 'listener should be removed'); - } - }); -} \ No newline at end of file diff --git a/test/unit/extensions/prototype_extensions.html b/test/unit/extensions/prototype_extensions.html deleted file mode 100644 index 40c96107..00000000 --- a/test/unit/extensions/prototype_extensions.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - Prototype extensions unit tests - - - - - - - -

Prototype extensions unit tests

-
- - \ No newline at end of file diff --git a/test/unit/extensions/prototype_extensions.js b/test/unit/extensions/prototype_extensions.js deleted file mode 100644 index f8e5a76a..00000000 --- a/test/unit/extensions/prototype_extensions.js +++ /dev/null @@ -1,114 +0,0 @@ -function init() { - - var global = (function(){ return this; })(); - - new Test.Unit.Runner({ - testFalseFunction: function() { - this.assertRespondsTo('falseFunction', Prototype); - this.assertIdentical(false, Prototype.falseFunction()); - }, - testGetScript: function() { - this.assert(Prototype.getScript); - this.assertUndefined(global.foo); - - var callbackFired = false; - - Prototype.getScript('../../fixtures/test_script.js', function(){ - callbackFired = true; - }); - - this.wait(500, function(){ - this.assertIdentical('bar', global.foo); - this.assert(callbackFired); - }); - }, - - testButtonEnableDisable: function(){ - var buttonEl = document.createElement('button'); - - this.assertRespondsTo('enable', buttonEl); - this.assertRespondsTo('disable', buttonEl); - - buttonEl.disabled = true; - - buttonEl.enable(); - this.assert(!buttonEl.disabled); - - buttonEl.disable(); - this.assert(buttonEl.disabled); - }, - - testMakeUnselectable: function() { - var el = document.createElement('div'); - - this.assertRespondsTo('makeUnselectable', el); - - el.makeUnselectable(); - this.assertIdentical(false, el.onselectstart(), 'onselectstart should be a function that returns `false`'); - }, - - testAssertEnumEqualUnordered: function() { - this.assertRespondsTo('assertEnumEqualUnordered', this); - - this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [1,2,3])); - this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [1,3,2])); - this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [2,1,3])); - this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [2,3,1])); - this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [3,1,2])); - this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [3,2,1])); - - this.assert(!Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [1,1,1])); - this.assert(!Test.Unit.Assertions._isEnumEqualUnordered([4,5,6], [1,2,3])); - - this.assert(!Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], ['1',2,3])); - }, - - testAssertObjectIdentical: function() { - this.assertRespondsTo('assertObjectIdentical', this); - - // Array objects - this.assert(Test.Unit.Assertions._isIdenticalRecursive([1,2,3], [1,2,3])); - this.assert(!Test.Unit.Assertions._isIdenticalRecursive([1,2,3], [3,2,1])); - this.assert(Test.Unit.Assertions._isIdenticalRecursive([], [])); - this.assert(Test.Unit.Assertions._isIdenticalRecursive( - [false, false, true, false, true], - [false, false, true, false, true] - )); - - // Object objects - this.assert(Test.Unit.Assertions._isIdenticalRecursive( - { x: 1, y: 2 }, - { x: 1, y: 2 } - )); - this.assert(Test.Unit.Assertions._isIdenticalRecursive( - { foo: true, bar: 12, baz: [12, 13, 14], qux: { x: null, y: 'boo' } }, - { foo: true, bar: 12, baz: [12, 13, 14], qux: { x: null, y: 'boo' } } - )); - - this.assert(Test.Unit.Assertions._isIdenticalRecursive(function(){}, function(){})); - this.assert(Test.Unit.Assertions._isIdenticalRecursive( - { x: undefined, y: null, z: NaN }, - { x: undefined, y: null, z: NaN } - )); - - this.assert(Test.Unit.Assertions._isIdenticalRecursive( - { level1: { level2: { level3: { level4: { level5: 'boo' } }}, x: 1.1234 }}, - { level1: { level2: { level3: { level4: { level5: 'boo' } }}, x: 1.1234 }} - )); - - this.assert(!Test.Unit.Assertions._isIdenticalRecursive({ x: 1 }, { })); - this.assert(Test.Unit.Assertions._isIdenticalRecursive({ }, { })); - - // primitives - this.assert(Test.Unit.Assertions._isIdenticalRecursive(5, 5)); - this.assert(!Test.Unit.Assertions._isIdenticalRecursive(5, '5')); - - this.assert(Test.Unit.Assertions._isIdenticalRecursive(NaN, NaN)); - this.assert(Test.Unit.Assertions._isIdenticalRecursive('x', 'x')); - this.assert(Test.Unit.Assertions._isIdenticalRecursive(false, false)); - this.assert(Test.Unit.Assertions._isIdenticalRecursive(null, null)); - this.assert(Test.Unit.Assertions._isIdenticalRecursive(undefined, undefined)); - - } - }); -} \ No newline at end of file