mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-17 20:50:58 +00:00
toJSON now returns object instead of a string (fixes bug with JSON.stringify returning incorrect — double — serialization of an object).
This commit is contained in:
parent
2c8540f3b4
commit
a2bb25043c
6 changed files with 77 additions and 80 deletions
44
dist/all.js
vendored
44
dist/all.js
vendored
|
|
@ -3417,22 +3417,13 @@ fabric.util.animate = animate;
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returs JSON representation of canvas
|
||||
* @method toJSON
|
||||
* @return {String} json string
|
||||
*/
|
||||
toJSON: function () {
|
||||
return JSON.stringify(this.toObject());
|
||||
},
|
||||
|
||||
/**
|
||||
* Returs dataless JSON representation of canvas
|
||||
* @method toDatalessJSON
|
||||
* @return {String} json string
|
||||
*/
|
||||
toDatalessJSON: function () {
|
||||
return JSON.stringify(this.toDatalessObject());
|
||||
return this.toDatalessObject();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -4017,7 +4008,7 @@ fabric.util.animate = animate;
|
|||
|
||||
var clone = this.__clone || (this.__clone = new fabric.Element(el));
|
||||
|
||||
return clone.loadFromJSON(this.toJSON(), function () {
|
||||
return clone.loadFromJSON(JSON.stringify(this.toJSON()), function () {
|
||||
if (callback) {
|
||||
callback(clone);
|
||||
}
|
||||
|
|
@ -4132,6 +4123,13 @@ fabric.util.animate = animate;
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Returs JSON representation of canvas
|
||||
* @method toJSON
|
||||
* @return {String} json string
|
||||
*/
|
||||
fabric.Element.prototype.toJSON = fabric.Element.prototype.toObject;
|
||||
})();
|
||||
|
||||
(function(){
|
||||
|
|
@ -4295,15 +4293,6 @@ fabric.util.animate = animate;
|
|||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a JSON representation of an instance
|
||||
* @method toJSON
|
||||
* @return {String} json
|
||||
*/
|
||||
toJSON: function() {
|
||||
return JSON.stringify(this.toObject());
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns an object representation of an instance
|
||||
* @method toObject
|
||||
|
|
@ -5349,6 +5338,15 @@ fabric.util.animate = animate;
|
|||
else if (angle > 315) { return 360; }
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a JSON representation of an instance
|
||||
* @method toJSON
|
||||
* @return {String} json
|
||||
*/
|
||||
toJSON: function() {
|
||||
return this.toObject();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -6592,7 +6590,7 @@ fabric.util.animate = animate;
|
|||
path = parsedAttributes.d;
|
||||
delete parsedAttributes.d;
|
||||
return new fabric.Path(path, extend(parsedAttributes, options));
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(function(){
|
||||
|
|
@ -6782,7 +6780,7 @@ fabric.util.animate = animate;
|
|||
function instantiatePaths(paths) {
|
||||
for (var i = 0, len = paths.length; i < len; i++) {
|
||||
if (!(paths[i] instanceof fabric.Object)) {
|
||||
var klassName = capitalize(camelize(paths[i].type));
|
||||
var klassName = camelize(capitalize(paths[i].type));
|
||||
paths[i] = fabric[klassName].fromObject(paths[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -6798,7 +6796,7 @@ fabric.util.animate = animate;
|
|||
fabric.PathGroup.fromObject = function(object) {
|
||||
var paths = instantiatePaths(object.paths);
|
||||
return new fabric.PathGroup(paths, object);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
|
|
|
|||
70
dist/all.min.js
vendored
70
dist/all.min.js
vendored
|
|
@ -73,43 +73,43 @@ return this},renderTop:function(){this.clearContext(this._oContextTop);this.over
|
|||
return false},_normalizePointer:function(b,d){var m=this.getActiveGroup(),o=d.x,u=d.y;if(m&&b.type!=="group"&&m.contains(b)){o-=m.left;u-=m.top}return{x:o,y:u}},findTarget:function(b,d){var m;this.getPointer(b);var o=this.getActiveGroup();if(o&&!d&&this.containsPoint(b,o))return m=o;for(o=this._aObjects.length;o--;)if(this.containsPoint(b,this._aObjects[o])){this.relatedTarget=m=this._aObjects[o];break}return m},toDataURL:function(b){var d;b||(b="png");if(b==="jpeg"||b==="png"){this.renderAll(true);
|
||||
d=this.getElement().toDataURL("image/"+b)}return d},toDataURLWithMultiplier:function(b,d){var m=this.getWidth(),o=this.getHeight(),u=m*d,v=o*d,w=this.getActiveObject();this.setWidth(u).setHeight(v);this._oContextTop.scale(d,d);w&&this.deactivateAll().renderAll();u=this.toDataURL(b);this._oContextTop.scale(1/d,1/d);this.setWidth(m).setHeight(o);w&&this.setActiveObject(w);this.renderAll();return u},getPointer:function(b){b=c(b);return{x:b.x-this._offset.left,y:b.y-this._offset.top}},getCenter:function(){return{top:this.getHeight()/
|
||||
2,left:this.getWidth()/2}},centerObjectH:function(b){b.set("left",this.getCenter().left);this.renderAll();return this},fxCenterObjectH:function(b,d){d=d||{};var m=function(){},o=d.onComplete||m,u=d.onChange||m,v=this;fabric.util.animate({startValue:b.get("left"),endValue:this.getCenter().left,duration:this.FX_DURATION,onChange:function(w){b.set("left",w);v.renderAll();u()},onComplete:function(){b.setCoords();o()}});return this},centerObjectV:function(b){b.set("top",this.getCenter().top);this.renderAll();
|
||||
return this},fxCenterObjectV:function(b,d){d=d||{};var m=function(){},o=d.onComplete||m,u=d.onChange||m,v=this;fabric.util.animate({startValue:b.get("top"),endValue:this.getCenter().top,duration:this.FX_DURATION,onChange:function(w){b.set("top",w);v.renderAll();u()},onComplete:function(){b.setCoords();o()}});return this},straightenObject:function(b){b.straighten();this.renderAll();return this},fxStraightenObject:function(b){b.fxStraighten({onChange:this.renderAll.bind(this)});return this},toJSON:function(){return JSON.stringify(this.toObject())},
|
||||
toDatalessJSON:function(){return JSON.stringify(this.toDatalessObject())},toObject:function(){return this._toObjectMethod("toObject")},toDatalessObject:function(){return this._toObjectMethod("toDatalessObject")},_toObjectMethod:function(b){return{objects:this._aObjects.map(function(d){if(!this.includeDefaultValues){var m=d.includeDefaultValues;d.includeDefaultValues=false}var o=d[b]();if(!this.includeDefaultValues)d.includeDefaultValues=m;return o},this),background:this.backgroundColor}},isEmpty:function(){return this._aObjects.length===
|
||||
0},loadFromJSON:function(b,d){if(b){var m=JSON.parse(b);if(!(!m||m&&!m.objects)){this.clear();var o=this;this._enlivenObjects(m.objects,function(){o.backgroundColor=m.background;d&&d()});return this}}},_enlivenObjects:function(b,d){var m=0,o=b.filter(function(v){return v.type==="image"}).length,u=this;b.forEach(function(v){if(v.type)switch(v.type){case "image":case "font":fabric[n(v.type)].fromObject(v,function(x){u.add(x);++m===o&&d&&d()});break;default:var w=fabric[l(n(v.type))];w&&w.fromObject&&
|
||||
u.add(w.fromObject(v));break}});o===0&&d&&d()},loadFromDatalessJSON:function(b,d){if(b){var m=typeof b==="string"?JSON.parse(b):b;if(!(!m||m&&!m.objects)){this.clear();this._enlivenDatalessObjects(m.objects,d)}}},_enlivenDatalessObjects:function(b,d){function m(x,z){o.insertAt(x,z);x.setCoords();++u===v&&d&&d()}var o=this,u=0,v=b.length;try{b.forEach(function(x,z){var B=x.paths?"paths":"path",A=x[B];delete x[B];if(typeof A!=="string")switch(x.type){case "image":case "text":fabric[n(x.type)].fromObject(x,
|
||||
function(y){m(y,z)});break;default:(B=fabric[l(n(x.type))])&&B.fromObject&&m(B.fromObject(x),z);break}else if(x.type==="image")o.loadImageFromURL(A,function(y){y.setSourcePath(A);f(y,x);y.setAngle(x.angle);m(y,z)});else if(x.type==="text"){x.path=A;var C=fabric.Text.fromObject(x);fabric.util.getScript(A,function(){Object.prototype.toString.call(h.opera)==="[object Opera]"?setTimeout(function(){m(C,z)},500):m(C,z)})}else o.loadSVGFromURL(A,function(y){y=y.length>1?new fabric.PathGroup(y,x):y[0];y.setSourcePath(A);
|
||||
if(!(y instanceof fabric.PathGroup)){f(y,x);typeof x.angle!=="undefined"&&y.setAngle(x.angle)}m(y,z)})},this)}catch(w){console.log(w.message)}},loadImageFromURL:function(){var b={};return function(d,m){function o(){var w=q.getElementById(b[d]);w.width&&w.height?m(new fabric.Image(w)):setTimeout(o,50)}var u=this;if(b[d])o();else{var v=new Image;v.onload=function(){v.onload=null;u._resizeImageToFit(v);var w=new fabric.Image(v);m(w)};v.className="canvas-img-clone";v.src=d;if(this.shouldCacheImages)b[d]=
|
||||
Element.identify(v);q.body.appendChild(v)}}}(),loadSVGFromURL:function(b,d){function m(v){if(v=v.responseXML)(v=v.documentElement)&&fabric.parseSVGDocument(v,function(w,x){u.cache.set(b,{objects:w.invoke("toObject"),options:x});d(w,x)})}function o(){console.log("ERROR!")}var u=this;b=b.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(b,function(v){if(v)u.cache.get(b,function(w){w=u._enlivenCachedObject(w);d(w.objects,w.options)});else new Ajax.Request(b,{method:"get",onComplete:m,onFailure:o})})},
|
||||
_enlivenCachedObject:function(b){var d=b.objects;b=b.options;d=d.map(function(m){return fabric[n(m.type)].fromObject(m)});return{objects:d,options:b}},remove:function(b){e(this._aObjects,b);this.renderAll();return b},fxRemove:function(b,d){var m=this;b.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){m.remove(b);typeof d==="function"&&d()}});return this},sendToBack:function(b){e(this._aObjects,b);this._aObjects.unshift(b);return this.renderAll()},bringToFront:function(b){e(this._aObjects,
|
||||
b);this._aObjects.push(b);return this.renderAll()},sendBackwards:function(b){var d=this._aObjects.indexOf(b),m=d;if(d!==0){for(d=d-1;d>=0;--d)if(b.intersectsWithObject(this._aObjects[d])){m=d;break}e(this._aObjects,b);this._aObjects.splice(m,0,b)}return this.renderAll()},bringForward:function(b){var d=this.getObjects(),m=d.indexOf(b),o=m;if(m!==d.length-1){m=m+1;for(var u=this._aObjects.length;m<u;++m)if(b.intersectsWithObject(d[m])){o=m;break}e(d,b);d.splice(o,0,b)}this.renderAll()},setActiveObject:function(b){this._activeObject&&
|
||||
this._activeObject.setActive(false);this._activeObject=b;b.setActive(true);this.renderAll();g("object:selected",{target:b});return this},getActiveObject:function(){return this._activeObject},removeActiveObject:function(){this._activeObject&&this._activeObject.setActive(false);this._activeObject=null;return this},setActiveGroup:function(b){this._activeGroup=b;return this},getActiveGroup:function(){return this._activeGroup},removeActiveGroup:function(){var b=this.getActiveGroup();b&&b.destroy();return this.setActiveGroup(null)},
|
||||
item:function(b){return this.getObjects()[b]},deactivateAll:function(){for(var b=this.getObjects(),d=0,m=b.length;d<m;d++)b[d].setActive(false);this.removeActiveGroup();this.removeActiveObject();return this},complexity:function(){return this.getObjects().reduce(function(b,d){b+=d.complexity?d.complexity():0;return b},0)},dispose:function(){this.clear();p(this.getElement(),"mousedown",this._onMouseDown);p(q,"mouseup",this._onMouseUp);p(q,"mousemove",this._onMouseMove);p(h,"resize",this._onResize);
|
||||
return this},clone:function(b){var d=q.createElement("canvas");d.width=this.getWidth();d.height=this.getHeight();var m=this.__clone||(this.__clone=new fabric.Element(d));return m.loadFromJSON(this.toJSON(),function(){b&&b(m)})},_toDataURL:function(b,d){this.clone(function(m){d(m.toDataURL(b))})},_toDataURLWithMultiplier:function(b,d,m){this.clone(function(o){m(o.toDataURLWithMultiplier(b,d))})},_resizeImageToFit:function(b){var d=b.width||b.offsetWidth,m=this.getWidth()/d;if(d)b.width=d*m},cache:{has:function(b,
|
||||
d){d(false)},get:function(){},set:function(){}}});fabric.Element.prototype.toString=function(){return"#<fabric.Element ("+this.complexity()+"): { objects: "+this.getObjects().length+" }>"};f(fabric.Element,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(b){var d=b.getContext("2d");b=d.getImageData(0,0,b.width,b.height);var m=b.data,o=b.width,u=b.height,v,w;for(i=0;i<o;i++)for(j=0;j<u;j++){v=i*4*u+j*4;w=(m[v]+m[v+1]+m[v+2])/3;m[v]=w;m[v+1]=w;m[v+2]=w}d.putImageData(b,0,0)},
|
||||
supports:function(b){var d=q.createElement("canvas");if(!d||!d.getContext)return null;var m=d.getContext("2d");if(!m)return null;switch(b){case "getImageData":return typeof m.getImageData!=="undefined";case "toDataURL":return typeof d.toDataURL!=="undefined";default:return null}}})}})();
|
||||
return this},fxCenterObjectV:function(b,d){d=d||{};var m=function(){},o=d.onComplete||m,u=d.onChange||m,v=this;fabric.util.animate({startValue:b.get("top"),endValue:this.getCenter().top,duration:this.FX_DURATION,onChange:function(w){b.set("top",w);v.renderAll();u()},onComplete:function(){b.setCoords();o()}});return this},straightenObject:function(b){b.straighten();this.renderAll();return this},fxStraightenObject:function(b){b.fxStraighten({onChange:this.renderAll.bind(this)});return this},toDatalessJSON:function(){return this.toDatalessObject()},
|
||||
toObject:function(){return this._toObjectMethod("toObject")},toDatalessObject:function(){return this._toObjectMethod("toDatalessObject")},_toObjectMethod:function(b){return{objects:this._aObjects.map(function(d){if(!this.includeDefaultValues){var m=d.includeDefaultValues;d.includeDefaultValues=false}var o=d[b]();if(!this.includeDefaultValues)d.includeDefaultValues=m;return o},this),background:this.backgroundColor}},isEmpty:function(){return this._aObjects.length===0},loadFromJSON:function(b,d){if(b){var m=
|
||||
JSON.parse(b);if(!(!m||m&&!m.objects)){this.clear();var o=this;this._enlivenObjects(m.objects,function(){o.backgroundColor=m.background;d&&d()});return this}}},_enlivenObjects:function(b,d){var m=0,o=b.filter(function(v){return v.type==="image"}).length,u=this;b.forEach(function(v){if(v.type)switch(v.type){case "image":case "font":fabric[n(v.type)].fromObject(v,function(x){u.add(x);++m===o&&d&&d()});break;default:var w=fabric[l(n(v.type))];w&&w.fromObject&&u.add(w.fromObject(v));break}});o===0&&d&&
|
||||
d()},loadFromDatalessJSON:function(b,d){if(b){var m=typeof b==="string"?JSON.parse(b):b;if(!(!m||m&&!m.objects)){this.clear();this._enlivenDatalessObjects(m.objects,d)}}},_enlivenDatalessObjects:function(b,d){function m(x,z){o.insertAt(x,z);x.setCoords();++u===v&&d&&d()}var o=this,u=0,v=b.length;try{b.forEach(function(x,z){var B=x.paths?"paths":"path",A=x[B];delete x[B];if(typeof A!=="string")switch(x.type){case "image":case "text":fabric[n(x.type)].fromObject(x,function(y){m(y,z)});break;default:(B=
|
||||
fabric[l(n(x.type))])&&B.fromObject&&m(B.fromObject(x),z);break}else if(x.type==="image")o.loadImageFromURL(A,function(y){y.setSourcePath(A);f(y,x);y.setAngle(x.angle);m(y,z)});else if(x.type==="text"){x.path=A;var C=fabric.Text.fromObject(x);fabric.util.getScript(A,function(){Object.prototype.toString.call(h.opera)==="[object Opera]"?setTimeout(function(){m(C,z)},500):m(C,z)})}else o.loadSVGFromURL(A,function(y){y=y.length>1?new fabric.PathGroup(y,x):y[0];y.setSourcePath(A);if(!(y instanceof fabric.PathGroup)){f(y,
|
||||
x);typeof x.angle!=="undefined"&&y.setAngle(x.angle)}m(y,z)})},this)}catch(w){console.log(w.message)}},loadImageFromURL:function(){var b={};return function(d,m){function o(){var w=q.getElementById(b[d]);w.width&&w.height?m(new fabric.Image(w)):setTimeout(o,50)}var u=this;if(b[d])o();else{var v=new Image;v.onload=function(){v.onload=null;u._resizeImageToFit(v);var w=new fabric.Image(v);m(w)};v.className="canvas-img-clone";v.src=d;if(this.shouldCacheImages)b[d]=Element.identify(v);q.body.appendChild(v)}}}(),
|
||||
loadSVGFromURL:function(b,d){function m(v){if(v=v.responseXML)(v=v.documentElement)&&fabric.parseSVGDocument(v,function(w,x){u.cache.set(b,{objects:w.invoke("toObject"),options:x});d(w,x)})}function o(){console.log("ERROR!")}var u=this;b=b.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(b,function(v){if(v)u.cache.get(b,function(w){w=u._enlivenCachedObject(w);d(w.objects,w.options)});else new Ajax.Request(b,{method:"get",onComplete:m,onFailure:o})})},_enlivenCachedObject:function(b){var d=
|
||||
b.objects;b=b.options;d=d.map(function(m){return fabric[n(m.type)].fromObject(m)});return{objects:d,options:b}},remove:function(b){e(this._aObjects,b);this.renderAll();return b},fxRemove:function(b,d){var m=this;b.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){m.remove(b);typeof d==="function"&&d()}});return this},sendToBack:function(b){e(this._aObjects,b);this._aObjects.unshift(b);return this.renderAll()},bringToFront:function(b){e(this._aObjects,b);this._aObjects.push(b);return this.renderAll()},
|
||||
sendBackwards:function(b){var d=this._aObjects.indexOf(b),m=d;if(d!==0){for(d=d-1;d>=0;--d)if(b.intersectsWithObject(this._aObjects[d])){m=d;break}e(this._aObjects,b);this._aObjects.splice(m,0,b)}return this.renderAll()},bringForward:function(b){var d=this.getObjects(),m=d.indexOf(b),o=m;if(m!==d.length-1){m=m+1;for(var u=this._aObjects.length;m<u;++m)if(b.intersectsWithObject(d[m])){o=m;break}e(d,b);d.splice(o,0,b)}this.renderAll()},setActiveObject:function(b){this._activeObject&&this._activeObject.setActive(false);
|
||||
this._activeObject=b;b.setActive(true);this.renderAll();g("object:selected",{target:b});return this},getActiveObject:function(){return this._activeObject},removeActiveObject:function(){this._activeObject&&this._activeObject.setActive(false);this._activeObject=null;return this},setActiveGroup:function(b){this._activeGroup=b;return this},getActiveGroup:function(){return this._activeGroup},removeActiveGroup:function(){var b=this.getActiveGroup();b&&b.destroy();return this.setActiveGroup(null)},item:function(b){return this.getObjects()[b]},
|
||||
deactivateAll:function(){for(var b=this.getObjects(),d=0,m=b.length;d<m;d++)b[d].setActive(false);this.removeActiveGroup();this.removeActiveObject();return this},complexity:function(){return this.getObjects().reduce(function(b,d){b+=d.complexity?d.complexity():0;return b},0)},dispose:function(){this.clear();p(this.getElement(),"mousedown",this._onMouseDown);p(q,"mouseup",this._onMouseUp);p(q,"mousemove",this._onMouseMove);p(h,"resize",this._onResize);return this},clone:function(b){var d=q.createElement("canvas");
|
||||
d.width=this.getWidth();d.height=this.getHeight();var m=this.__clone||(this.__clone=new fabric.Element(d));return m.loadFromJSON(this.toJSON(),function(){b&&b(m)})},_toDataURL:function(b,d){this.clone(function(m){d(m.toDataURL(b))})},_toDataURLWithMultiplier:function(b,d,m){this.clone(function(o){m(o.toDataURLWithMultiplier(b,d))})},_resizeImageToFit:function(b){var d=b.width||b.offsetWidth,m=this.getWidth()/d;if(d)b.width=d*m},cache:{has:function(b,d){d(false)},get:function(){},set:function(){}}});
|
||||
fabric.Element.prototype.toString=function(){return"#<fabric.Element ("+this.complexity()+"): { objects: "+this.getObjects().length+" }>"};f(fabric.Element,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(b){var d=b.getContext("2d");b=d.getImageData(0,0,b.width,b.height);var m=b.data,o=b.width,u=b.height,v,w;for(i=0;i<o;i++)for(j=0;j<u;j++){v=i*4*u+j*4;w=(m[v]+m[v+1]+m[v+2])/3;m[v]=w;m[v+1]=w;m[v+2]=w}d.putImageData(b,0,0)},supports:function(b){var d=q.createElement("canvas");
|
||||
if(!d||!d.getContext)return null;var m=d.getContext("2d");if(!m)return null;switch(b){case "getImageData":return typeof m.getImageData!=="undefined";case "toDataURL":return typeof d.toDataURL!=="undefined";default:return null}}});fabric.Element.prototype.toJSON=fabric.Element.prototype.toObject}})();
|
||||
(function(){var h=this.fabric||(this.fabric={}),q=h.util.object.extend,f=h.util.object.clone,n=h.util.toFixed,l=h.util.string.capitalize,g=h.util.getPointer,c=Array.prototype.slice;if(!h.Object){h.Object=h.util.createClass({type:"object",includeDefaultValues:true,NUM_FRACTION_DIGITS:2,FX_DURATION:500,FX_TRANSITION:"decel",MIN_SCALE_LIMIT:0.1,stateProperties:"top left width height scaleX scaleY flipX flipY theta angle opacity cornersize fill overlayFill stroke strokeWidth fillRule borderScaleFactor transformMatrix".split(" "),
|
||||
options:{top:0,left:0,width:100,height:100,scaleX:1,scaleY:1,flipX:false,flipY:false,theta:0,opacity:1,angle:0,cornersize:10,padding:0,borderColor:"rgba(102,153,255,0.75)",cornerColor:"rgba(102,153,255,0.5)",fill:"rgb(0,0,0)",overlayFill:null,stroke:null,strokeWidth:1,fillRule:"source-over",borderOpacityWhenMoving:0.4,borderScaleFactor:1,transformMatrix:null},callSuper:function(a){var e=this.constructor.superclass.prototype[a];return arguments.length>1?e.apply(this,c.call(arguments,1)):e.call(this)},
|
||||
initialize:function(a){this.setOptions(a);this._importProperties();this.originalState={};this.setCoords();this.saveState()},setOptions:function(a){this.options=q(this._getOptions(),a)},_getOptions:function(){return q(f(this._getSuperOptions()),this.options)},_getSuperOptions:function(){var a=this.constructor;if(a)if(a=a.superclass)if((a=a.prototype)&&typeof a._getOptions=="function")return a._getOptions();return{}},_importProperties:function(){this.stateProperties.forEach(function(a){a==="angle"?
|
||||
this.setAngle(this.options[a]):this[a]=this.options[a]},this)},transform:function(a){a.globalAlpha=this.opacity;a.translate(this.left,this.top);a.rotate(this.theta);a.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toJSON:function(){return JSON.stringify(this.toObject())},toObject:function(){var a={type:this.type,left:n(this.left,this.NUM_FRACTION_DIGITS),top:n(this.top,this.NUM_FRACTION_DIGITS),width:n(this.width,this.NUM_FRACTION_DIGITS),height:n(this.height,this.NUM_FRACTION_DIGITS),
|
||||
fill:this.fill,overlayFill:this.overlayFill,stroke:this.stroke,strokeWidth:this.strokeWidth,scaleX:n(this.scaleX,this.NUM_FRACTION_DIGITS),scaleY:n(this.scaleY,this.NUM_FRACTION_DIGITS),angle:n(this.getAngle(),this.NUM_FRACTION_DIGITS),flipX:this.flipX,flipY:this.flipY,opacity:n(this.opacity,this.NUM_FRACTION_DIGITS)};this.includeDefaultValues||(a=this._removeDefaultValues(a));return a},toDatalessObject:function(){return this.toObject()},_removeDefaultValues:function(a){var e=h.Object.prototype.options;
|
||||
this.stateProperties.forEach(function(k){a[k]===e[k]&&delete a[k]});return a},isActive:function(){return!!this.active},setActive:function(a){this.active=!!a;return this},toString:function(){return"#<fabric."+l(this.type)+">"},set:function(a,e){if((a==="scaleX"||a==="scaleY")&&e<this.MIN_SCALE_LIMIT)e=this.MIN_SCALE_LIMIT;if(a==="angle")this.setAngle(e);else this[a]=e;return this},toggle:function(a){var e=this.get(a);typeof e==="boolean"&&this.set(a,!e);return this},setSourcePath:function(a){this.sourcePath=
|
||||
a;return this},get:function(a){return a==="angle"?this.getAngle():this[a]},render:function(a,e){if(!(this.width===0||this.height===0)){a.save();var k=this.transformMatrix;k&&a.setTransform(k[0],k[1],k[2],k[3],k[4],k[5]);e||this.transform(a);if(this.stroke){a.lineWidth=this.strokeWidth;a.strokeStyle=this.stroke}if(this.overlayFill)a.fillStyle=this.overlayFill;else if(this.fill)a.fillStyle=this.fill;this._render(a);if(this.active&&!e){this.drawBorders(a);this.drawCorners(a)}a.restore()}},getWidth:function(){return this.width*
|
||||
this.scaleX},getHeight:function(){return this.height*this.scaleY},scale:function(a){this.scaleY=this.scaleX=a;return this},scaleToWidth:function(a){return this.scale(a/this.width)},scaleToHeight:function(a){return this.scale(a/this.height)},setOpacity:function(a){this.set("opacity",a);return this},getAngle:function(){return this.theta*180/Math.PI},setAngle:function(a){this.theta=a/180*Math.PI;this.angle=a;return this},setCoords:function(){this.currentWidth=this.width*this.scaleX;this.currentHeight=
|
||||
this.height*this.scaleY;this._hypotenuse=Math.sqrt(Math.pow(this.currentWidth/2,2)+Math.pow(this.currentHeight/2,2));this._angle=Math.atan(this.currentHeight/this.currentWidth);var a=Math.cos(this._angle+this.theta)*this._hypotenuse,e=Math.sin(this._angle+this.theta)*this._hypotenuse,k=this.theta,p=Math.sin(k);k=Math.cos(k);a={x:this.left-a,y:this.top-e};e={x:a.x+this.currentWidth*k,y:a.y+this.currentWidth*p};var r={x:a.x-this.currentHeight*p,y:a.y+this.currentHeight*k};this.oCoords={tl:a,tr:e,br:{x:e.x-
|
||||
this.currentHeight*p,y:e.y+this.currentHeight*k},bl:r,ml:{x:a.x-this.currentHeight/2*p,y:a.y+this.currentHeight/2*k},mt:{x:a.x+this.currentWidth/2*k,y:a.y+this.currentWidth/2*p},mr:{x:e.x-this.currentHeight/2*p,y:e.y+this.currentHeight/2*k},mb:{x:r.x+this.currentWidth/2*k,y:r.y+this.currentWidth/2*p}};this._setCornerCoords();return this},drawBorders:function(a){var e=this.options,k=e.padding,p=k*2;a.save();a.globalAlpha=this.isMoving?e.borderOpacityWhenMoving:1;a.strokeStyle=e.borderColor;e=1/(this.scaleX<
|
||||
this.MIN_SCALE_LIMIT?this.MIN_SCALE_LIMIT:this.scaleX);var r=1/(this.scaleY<this.MIN_SCALE_LIMIT?this.MIN_SCALE_LIMIT:this.scaleY);a.lineWidth=1/this.borderScaleFactor;a.scale(e,r);e=this.getWidth();r=this.getHeight();a.strokeRect(Math.floor(-(e/2)-k)+0.5,Math.floor(-(r/2)-k)+0.5,Math.floor(e+p),Math.floor(r+p));a.restore();return this},drawCorners:function(a){var e=this.options.cornersize,k=e/2,p=this.options.padding,r=-(this.width/2),s=-(this.height/2),t=e/this.scaleX,b=e/this.scaleY,d=(p+k)/this.scaleY,
|
||||
m=(p+k)/this.scaleX,o=(p+k-e)/this.scaleX;p=(p+k-e)/this.scaleY;a.save();a.globalAlpha=this.isMoving?this.options.borderOpacityWhenMoving:1;a.fillStyle=this.options.cornerColor;e=r-m;k=s-d;a.fillRect(e,k,t,b);e=r+this.width-m;k=s-d;a.fillRect(e,k,t,b);e=r-m;k=s+this.height+p;a.fillRect(e,k,t,b);e=r+this.width+o;k=s+this.height+p;a.fillRect(e,k,t,b);e=r+this.width/2-m;k=s-d;a.fillRect(e,k,t,b);e=r+this.width/2-m;k=s+this.height+p;a.fillRect(e,k,t,b);e=r+this.width+o;k=s+this.height/2-d;a.fillRect(e,
|
||||
k,t,b);e=r-m;k=s+this.height/2-d;a.fillRect(e,k,t,b);a.restore();return this},clone:function(a){if(this.constructor.fromObject)return this.constructor.fromObject(this.toObject(),a);return new h.Object(this.toObject())},cloneAsImage:function(a){if(h.Image){var e=new Image;e.onload=function(){a&&a(new h.Image(e),k);e=e.onload=null};var k={angle:this.get("angle"),flipX:this.get("flipX"),flipY:this.get("flipY")};this.set("angle",0).set("flipX",false).set("flipY",false);e.src=this.toDataURL()}return this},
|
||||
toDataURL:function(){var a=document.createElement("canvas");a.width=this.getWidth();a.height=this.getHeight();h.util.wrapElement(a,"div");var e=new h.Element(a);e.backgroundColor="transparent";e.renderAll();var k=this.clone();k.left=a.width/2;k.top=a.height/2;k.setActive(false);e.add(k);a=e.toDataURL("png");e.dispose();return a},hasStateChanged:function(){return this.stateProperties.some(function(a){return this[a]!==this.originalState[a]},this)},saveState:function(){this.stateProperties.forEach(function(a){this.originalState[a]=
|
||||
this.get(a)},this);return this},intersectsWithRect:function(a,e){var k=this.oCoords,p=new h.Point(k.tl.x,k.tl.y),r=new h.Point(k.tr.x,k.tr.y),s=new h.Point(k.bl.x,k.bl.y);k=new h.Point(k.br.x,k.br.y);return h.Intersection.intersectPolygonRectangle([p,r,k,s],a,e).status==="Intersection"},intersectsWithObject:function(a){function e(p){return{tl:new h.Point(p.tl.x,p.tl.y),tr:new h.Point(p.tr.x,p.tr.y),bl:new h.Point(p.bl.x,p.bl.y),br:new h.Point(p.br.x,p.br.y)}}var k=e(this.oCoords);a=e(a.oCoords);return h.Intersection.intersectPolygonPolygon([k.tl,
|
||||
k.tr,k.br,k.bl],[a.tl,a.tr,a.br,a.bl]).status==="Intersection"},isContainedWithinRect:function(a,e){var k=this.oCoords,p=new h.Point(k.tl.x,k.tl.y),r=new h.Point(k.tr.x,k.tr.y),s=new h.Point(k.bl.x,k.bl.y);new h.Point(k.br.x,k.br.y);return p.x>a.x&&r.x<e.x&&p.y>a.y&&s.y<e.y},isType:function(a){return this.type===a},_findTargetCorner:function(a,e){var k=g(a),p=k.x-e.left;k=k.y-e.top;var r;for(var s in this.oCoords){r=this._getImageLines(this.oCoords[s].corner,s);r=this._findCrossPoints(p,k,r);if(r%
|
||||
2==1&&r!=0)return this.__corner=s}return false},_findCrossPoints:function(a,e,k){var p,r,s,t=0;for(var b in k){s=k[b];if(!(s.o.y<e&&s.d.y<e))if(!(s.o.y>=e&&s.d.y>=e)){if(s.o.x==s.d.x&&s.o.x>=a)p=s.o.x;else{p=(s.d.y-s.o.y)/(s.d.x-s.o.x);r=e-0*a;s=s.o.y-p*s.o.x;p=-(r-s)/(0-p)}if(p>=a)t+=1;if(t==2)break}}return t},_getImageLines:function(a){return{topline:{o:a.tl,d:a.tr},rightline:{o:a.tr,d:a.br},bottomline:{o:a.br,d:a.bl},leftline:{o:a.bl,d:a.tl}}},_setCornerCoords:function(){var a=this.oCoords,e=this.theta,
|
||||
k=this.cornersize*Math.cos(e),p=this.cornersize*Math.sin(e);e=this.cornersize/2;var r=e-p;a.tl.x-=r;a.tl.y-=e;a.tl.corner={tl:{x:a.tl.x,y:a.tl.y},tr:{x:a.tl.x+k,y:a.tl.y+p},bl:{x:a.tl.x-p,y:a.tl.y+k}};a.tl.corner.br={x:a.tl.corner.tr.x-p,y:a.tl.corner.tr.y+k};a.tl.x+=r;a.tl.y+=e;a.tr.x+=e;a.tr.y-=e;a.tr.corner={tl:{x:a.tr.x-k,y:a.tr.y-p},tr:{x:a.tr.x,y:a.tr.y},br:{x:a.tr.x-p,y:a.tr.y+k}};a.tr.corner.bl={x:a.tr.corner.tl.x-p,y:a.tr.corner.tl.y+k};a.tr.x-=e;a.tr.y+=e;a.bl.x-=e;a.bl.y+=e;a.bl.corner=
|
||||
{tl:{x:a.bl.x+p,y:a.bl.y-k},bl:{x:a.bl.x,y:a.bl.y},br:{x:a.bl.x+k,y:a.bl.y+p}};a.bl.corner.tr={x:a.bl.corner.br.x+p,y:a.bl.corner.br.y-k};a.bl.x+=e;a.bl.y-=e;a.br.x+=e;a.br.y+=e;a.br.corner={tr:{x:a.br.x+p,y:a.br.y-k},bl:{x:a.br.x-k,y:a.br.y-p},br:{x:a.br.x,y:a.br.y}};a.br.corner.tl={x:a.br.corner.bl.x+p,y:a.br.corner.bl.y-k};a.br.x-=e;a.br.y-=e;a.ml.x-=e;a.ml.y-=e;a.ml.corner={tl:{x:a.ml.x,y:a.ml.y},tr:{x:a.ml.x+k,y:a.ml.y+p},bl:{x:a.ml.x-p,y:a.ml.y+k}};a.ml.corner.br={x:a.ml.corner.tr.x-p,y:a.ml.corner.tr.y+
|
||||
k};a.ml.x+=e;a.ml.y+=e;a.mt.x-=e;a.mt.y-=e;a.mt.corner={tl:{x:a.mt.x,y:a.mt.y},tr:{x:a.mt.x+k,y:a.mt.y+p},bl:{x:a.mt.x-p,y:a.mt.y+k}};a.mt.corner.br={x:a.mt.corner.tr.x-p,y:a.mt.corner.tr.y+k};a.mt.x+=e;a.mt.y+=e;a.mr.x-=e;a.mr.y-=e;a.mr.corner={tl:{x:a.mr.x,y:a.mr.y},tr:{x:a.mr.x+k,y:a.mr.y+p},bl:{x:a.mr.x-p,y:a.mr.y+k}};a.mr.corner.br={x:a.mr.corner.tr.x-p,y:a.mr.corner.tr.y+k};a.mr.x+=e;a.mr.y+=e;a.mb.x-=e;a.mb.y-=e;a.mb.corner={tl:{x:a.mb.x,y:a.mb.y},tr:{x:a.mb.x+k,y:a.mb.y+p},bl:{x:a.mb.x-p,
|
||||
y:a.mb.y+k}};a.mb.corner.br={x:a.mb.corner.tr.x-p,y:a.mb.corner.tr.y+k};a.mb.x+=e;a.mb.y+=e;a=a.mb.corner;a.tl.x-=e;a.tl.y-=e;a.tr.x-=e;a.tr.y-=e;a.br.x-=e;a.br.y-=e;a.bl.x-=e;a.bl.y-=e},toGrayscale:function(){var a=this.get("fill");a&&this.set("overlayFill",(new h.Color(a)).toGrayscale().toRgb());return this},complexity:function(){return 0},getCenter:function(){return{x:this.get("left")+this.width/2,y:this.get("top")+this.height/2}},straighten:function(){this.setAngle(this._getAngleValueForStraighten());
|
||||
return this},fxStraighten:function(a){a=a||{};var e=function(){},k=a.onComplete||e,p=a.onChange||e,r=this;h.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(s){r.setAngle(s);p()},onComplete:function(){r.setCoords();k()},onStart:function(){r.setActive(false)}});return this},fxRemove:function(a){a||(a={});var e=function(){},k=a.onComplete||e,p=a.onChange||e,r=this;h.util.animate({startValue:this.get("opacity"),endValue:0,
|
||||
duration:this.FX_DURATION,onChange:function(s){r.set("opacity",s);p()},onComplete:k,onStart:function(){r.setActive(false)}});return this},_getAngleValueForStraighten:function(){var a=this.get("angle");if(a>-225&&a<=-135)return-180;else if(a>-135&&a<=-45)return-90;else if(a>-45&&a<=45)return 0;else if(a>45&&a<=135)return 90;else if(a>135&&a<=225)return 180;else if(a>225&&a<=315)return 270;else if(a>315)return 360;return 0}});h.Object.prototype.rotate=h.Object.prototype.setAngle}})();
|
||||
this.setAngle(this.options[a]):this[a]=this.options[a]},this)},transform:function(a){a.globalAlpha=this.opacity;a.translate(this.left,this.top);a.rotate(this.theta);a.scale(this.scaleX*(this.flipX?-1:1),this.scaleY*(this.flipY?-1:1))},toObject:function(){var a={type:this.type,left:n(this.left,this.NUM_FRACTION_DIGITS),top:n(this.top,this.NUM_FRACTION_DIGITS),width:n(this.width,this.NUM_FRACTION_DIGITS),height:n(this.height,this.NUM_FRACTION_DIGITS),fill:this.fill,overlayFill:this.overlayFill,stroke:this.stroke,
|
||||
strokeWidth:this.strokeWidth,scaleX:n(this.scaleX,this.NUM_FRACTION_DIGITS),scaleY:n(this.scaleY,this.NUM_FRACTION_DIGITS),angle:n(this.getAngle(),this.NUM_FRACTION_DIGITS),flipX:this.flipX,flipY:this.flipY,opacity:n(this.opacity,this.NUM_FRACTION_DIGITS)};this.includeDefaultValues||(a=this._removeDefaultValues(a));return a},toDatalessObject:function(){return this.toObject()},_removeDefaultValues:function(a){var e=h.Object.prototype.options;this.stateProperties.forEach(function(k){a[k]===e[k]&&delete a[k]});
|
||||
return a},isActive:function(){return!!this.active},setActive:function(a){this.active=!!a;return this},toString:function(){return"#<fabric."+l(this.type)+">"},set:function(a,e){if((a==="scaleX"||a==="scaleY")&&e<this.MIN_SCALE_LIMIT)e=this.MIN_SCALE_LIMIT;if(a==="angle")this.setAngle(e);else this[a]=e;return this},toggle:function(a){var e=this.get(a);typeof e==="boolean"&&this.set(a,!e);return this},setSourcePath:function(a){this.sourcePath=a;return this},get:function(a){return a==="angle"?this.getAngle():
|
||||
this[a]},render:function(a,e){if(!(this.width===0||this.height===0)){a.save();var k=this.transformMatrix;k&&a.setTransform(k[0],k[1],k[2],k[3],k[4],k[5]);e||this.transform(a);if(this.stroke){a.lineWidth=this.strokeWidth;a.strokeStyle=this.stroke}if(this.overlayFill)a.fillStyle=this.overlayFill;else if(this.fill)a.fillStyle=this.fill;this._render(a);if(this.active&&!e){this.drawBorders(a);this.drawCorners(a)}a.restore()}},getWidth:function(){return this.width*this.scaleX},getHeight:function(){return this.height*
|
||||
this.scaleY},scale:function(a){this.scaleY=this.scaleX=a;return this},scaleToWidth:function(a){return this.scale(a/this.width)},scaleToHeight:function(a){return this.scale(a/this.height)},setOpacity:function(a){this.set("opacity",a);return this},getAngle:function(){return this.theta*180/Math.PI},setAngle:function(a){this.theta=a/180*Math.PI;this.angle=a;return this},setCoords:function(){this.currentWidth=this.width*this.scaleX;this.currentHeight=this.height*this.scaleY;this._hypotenuse=Math.sqrt(Math.pow(this.currentWidth/
|
||||
2,2)+Math.pow(this.currentHeight/2,2));this._angle=Math.atan(this.currentHeight/this.currentWidth);var a=Math.cos(this._angle+this.theta)*this._hypotenuse,e=Math.sin(this._angle+this.theta)*this._hypotenuse,k=this.theta,p=Math.sin(k);k=Math.cos(k);a={x:this.left-a,y:this.top-e};e={x:a.x+this.currentWidth*k,y:a.y+this.currentWidth*p};var r={x:a.x-this.currentHeight*p,y:a.y+this.currentHeight*k};this.oCoords={tl:a,tr:e,br:{x:e.x-this.currentHeight*p,y:e.y+this.currentHeight*k},bl:r,ml:{x:a.x-this.currentHeight/
|
||||
2*p,y:a.y+this.currentHeight/2*k},mt:{x:a.x+this.currentWidth/2*k,y:a.y+this.currentWidth/2*p},mr:{x:e.x-this.currentHeight/2*p,y:e.y+this.currentHeight/2*k},mb:{x:r.x+this.currentWidth/2*k,y:r.y+this.currentWidth/2*p}};this._setCornerCoords();return this},drawBorders:function(a){var e=this.options,k=e.padding,p=k*2;a.save();a.globalAlpha=this.isMoving?e.borderOpacityWhenMoving:1;a.strokeStyle=e.borderColor;e=1/(this.scaleX<this.MIN_SCALE_LIMIT?this.MIN_SCALE_LIMIT:this.scaleX);var r=1/(this.scaleY<
|
||||
this.MIN_SCALE_LIMIT?this.MIN_SCALE_LIMIT:this.scaleY);a.lineWidth=1/this.borderScaleFactor;a.scale(e,r);e=this.getWidth();r=this.getHeight();a.strokeRect(Math.floor(-(e/2)-k)+0.5,Math.floor(-(r/2)-k)+0.5,Math.floor(e+p),Math.floor(r+p));a.restore();return this},drawCorners:function(a){var e=this.options.cornersize,k=e/2,p=this.options.padding,r=-(this.width/2),s=-(this.height/2),t=e/this.scaleX,b=e/this.scaleY,d=(p+k)/this.scaleY,m=(p+k)/this.scaleX,o=(p+k-e)/this.scaleX;p=(p+k-e)/this.scaleY;a.save();
|
||||
a.globalAlpha=this.isMoving?this.options.borderOpacityWhenMoving:1;a.fillStyle=this.options.cornerColor;e=r-m;k=s-d;a.fillRect(e,k,t,b);e=r+this.width-m;k=s-d;a.fillRect(e,k,t,b);e=r-m;k=s+this.height+p;a.fillRect(e,k,t,b);e=r+this.width+o;k=s+this.height+p;a.fillRect(e,k,t,b);e=r+this.width/2-m;k=s-d;a.fillRect(e,k,t,b);e=r+this.width/2-m;k=s+this.height+p;a.fillRect(e,k,t,b);e=r+this.width+o;k=s+this.height/2-d;a.fillRect(e,k,t,b);e=r-m;k=s+this.height/2-d;a.fillRect(e,k,t,b);a.restore();return this},
|
||||
clone:function(a){if(this.constructor.fromObject)return this.constructor.fromObject(this.toObject(),a);return new h.Object(this.toObject())},cloneAsImage:function(a){if(h.Image){var e=new Image;e.onload=function(){a&&a(new h.Image(e),k);e=e.onload=null};var k={angle:this.get("angle"),flipX:this.get("flipX"),flipY:this.get("flipY")};this.set("angle",0).set("flipX",false).set("flipY",false);e.src=this.toDataURL()}return this},toDataURL:function(){var a=document.createElement("canvas");a.width=this.getWidth();
|
||||
a.height=this.getHeight();h.util.wrapElement(a,"div");var e=new h.Element(a);e.backgroundColor="transparent";e.renderAll();var k=this.clone();k.left=a.width/2;k.top=a.height/2;k.setActive(false);e.add(k);a=e.toDataURL("png");e.dispose();return a},hasStateChanged:function(){return this.stateProperties.some(function(a){return this[a]!==this.originalState[a]},this)},saveState:function(){this.stateProperties.forEach(function(a){this.originalState[a]=this.get(a)},this);return this},intersectsWithRect:function(a,
|
||||
e){var k=this.oCoords,p=new h.Point(k.tl.x,k.tl.y),r=new h.Point(k.tr.x,k.tr.y),s=new h.Point(k.bl.x,k.bl.y);k=new h.Point(k.br.x,k.br.y);return h.Intersection.intersectPolygonRectangle([p,r,k,s],a,e).status==="Intersection"},intersectsWithObject:function(a){function e(p){return{tl:new h.Point(p.tl.x,p.tl.y),tr:new h.Point(p.tr.x,p.tr.y),bl:new h.Point(p.bl.x,p.bl.y),br:new h.Point(p.br.x,p.br.y)}}var k=e(this.oCoords);a=e(a.oCoords);return h.Intersection.intersectPolygonPolygon([k.tl,k.tr,k.br,k.bl],
|
||||
[a.tl,a.tr,a.br,a.bl]).status==="Intersection"},isContainedWithinRect:function(a,e){var k=this.oCoords,p=new h.Point(k.tl.x,k.tl.y),r=new h.Point(k.tr.x,k.tr.y),s=new h.Point(k.bl.x,k.bl.y);new h.Point(k.br.x,k.br.y);return p.x>a.x&&r.x<e.x&&p.y>a.y&&s.y<e.y},isType:function(a){return this.type===a},_findTargetCorner:function(a,e){var k=g(a),p=k.x-e.left;k=k.y-e.top;var r;for(var s in this.oCoords){r=this._getImageLines(this.oCoords[s].corner,s);r=this._findCrossPoints(p,k,r);if(r%2==1&&r!=0)return this.__corner=
|
||||
s}return false},_findCrossPoints:function(a,e,k){var p,r,s,t=0;for(var b in k){s=k[b];if(!(s.o.y<e&&s.d.y<e))if(!(s.o.y>=e&&s.d.y>=e)){if(s.o.x==s.d.x&&s.o.x>=a)p=s.o.x;else{p=(s.d.y-s.o.y)/(s.d.x-s.o.x);r=e-0*a;s=s.o.y-p*s.o.x;p=-(r-s)/(0-p)}if(p>=a)t+=1;if(t==2)break}}return t},_getImageLines:function(a){return{topline:{o:a.tl,d:a.tr},rightline:{o:a.tr,d:a.br},bottomline:{o:a.br,d:a.bl},leftline:{o:a.bl,d:a.tl}}},_setCornerCoords:function(){var a=this.oCoords,e=this.theta,k=this.cornersize*Math.cos(e),
|
||||
p=this.cornersize*Math.sin(e);e=this.cornersize/2;var r=e-p;a.tl.x-=r;a.tl.y-=e;a.tl.corner={tl:{x:a.tl.x,y:a.tl.y},tr:{x:a.tl.x+k,y:a.tl.y+p},bl:{x:a.tl.x-p,y:a.tl.y+k}};a.tl.corner.br={x:a.tl.corner.tr.x-p,y:a.tl.corner.tr.y+k};a.tl.x+=r;a.tl.y+=e;a.tr.x+=e;a.tr.y-=e;a.tr.corner={tl:{x:a.tr.x-k,y:a.tr.y-p},tr:{x:a.tr.x,y:a.tr.y},br:{x:a.tr.x-p,y:a.tr.y+k}};a.tr.corner.bl={x:a.tr.corner.tl.x-p,y:a.tr.corner.tl.y+k};a.tr.x-=e;a.tr.y+=e;a.bl.x-=e;a.bl.y+=e;a.bl.corner={tl:{x:a.bl.x+p,y:a.bl.y-k},bl:{x:a.bl.x,
|
||||
y:a.bl.y},br:{x:a.bl.x+k,y:a.bl.y+p}};a.bl.corner.tr={x:a.bl.corner.br.x+p,y:a.bl.corner.br.y-k};a.bl.x+=e;a.bl.y-=e;a.br.x+=e;a.br.y+=e;a.br.corner={tr:{x:a.br.x+p,y:a.br.y-k},bl:{x:a.br.x-k,y:a.br.y-p},br:{x:a.br.x,y:a.br.y}};a.br.corner.tl={x:a.br.corner.bl.x+p,y:a.br.corner.bl.y-k};a.br.x-=e;a.br.y-=e;a.ml.x-=e;a.ml.y-=e;a.ml.corner={tl:{x:a.ml.x,y:a.ml.y},tr:{x:a.ml.x+k,y:a.ml.y+p},bl:{x:a.ml.x-p,y:a.ml.y+k}};a.ml.corner.br={x:a.ml.corner.tr.x-p,y:a.ml.corner.tr.y+k};a.ml.x+=e;a.ml.y+=e;a.mt.x-=
|
||||
e;a.mt.y-=e;a.mt.corner={tl:{x:a.mt.x,y:a.mt.y},tr:{x:a.mt.x+k,y:a.mt.y+p},bl:{x:a.mt.x-p,y:a.mt.y+k}};a.mt.corner.br={x:a.mt.corner.tr.x-p,y:a.mt.corner.tr.y+k};a.mt.x+=e;a.mt.y+=e;a.mr.x-=e;a.mr.y-=e;a.mr.corner={tl:{x:a.mr.x,y:a.mr.y},tr:{x:a.mr.x+k,y:a.mr.y+p},bl:{x:a.mr.x-p,y:a.mr.y+k}};a.mr.corner.br={x:a.mr.corner.tr.x-p,y:a.mr.corner.tr.y+k};a.mr.x+=e;a.mr.y+=e;a.mb.x-=e;a.mb.y-=e;a.mb.corner={tl:{x:a.mb.x,y:a.mb.y},tr:{x:a.mb.x+k,y:a.mb.y+p},bl:{x:a.mb.x-p,y:a.mb.y+k}};a.mb.corner.br={x:a.mb.corner.tr.x-
|
||||
p,y:a.mb.corner.tr.y+k};a.mb.x+=e;a.mb.y+=e;a=a.mb.corner;a.tl.x-=e;a.tl.y-=e;a.tr.x-=e;a.tr.y-=e;a.br.x-=e;a.br.y-=e;a.bl.x-=e;a.bl.y-=e},toGrayscale:function(){var a=this.get("fill");a&&this.set("overlayFill",(new h.Color(a)).toGrayscale().toRgb());return this},complexity:function(){return 0},getCenter:function(){return{x:this.get("left")+this.width/2,y:this.get("top")+this.height/2}},straighten:function(){this.setAngle(this._getAngleValueForStraighten());return this},fxStraighten:function(a){a=
|
||||
a||{};var e=function(){},k=a.onComplete||e,p=a.onChange||e,r=this;h.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(s){r.setAngle(s);p()},onComplete:function(){r.setCoords();k()},onStart:function(){r.setActive(false)}});return this},fxRemove:function(a){a||(a={});var e=function(){},k=a.onComplete||e,p=a.onChange||e,r=this;h.util.animate({startValue:this.get("opacity"),endValue:0,duration:this.FX_DURATION,onChange:function(s){r.set("opacity",
|
||||
s);p()},onComplete:k,onStart:function(){r.setActive(false)}});return this},_getAngleValueForStraighten:function(){var a=this.get("angle");if(a>-225&&a<=-135)return-180;else if(a>-135&&a<=-45)return-90;else if(a>-45&&a<=45)return 0;else if(a>45&&a<=135)return 90;else if(a>135&&a<=225)return 180;else if(a>225&&a<=315)return 270;else if(a>315)return 360;return 0},toJSON:function(){return this.toObject()}});h.Object.prototype.rotate=h.Object.prototype.setAngle}})();
|
||||
(function(){var h=this.fabric||(this.fabric={}),q=h.util.object.extend;if(!h.Line){h.Line=h.util.createClass(h.Object,{type:"line",initialize:function(f,n){f||(f=[0,0,0,0]);this.callSuper("initialize",n);this.set("x1",f[0]);this.set("y1",f[1]);this.set("x2",f[2]);this.set("y2",f[3]);this.set("width",this.x2-this.x1);this.set("height",this.y2-this.y1);this.set("left",this.x1+this.width/2);this.set("top",this.y1+this.height/2)},_render:function(f){f.beginPath();f.moveTo(-this.width/2,-this.height/2);
|
||||
f.lineTo(this.width/2,this.height/2);var n=f.strokeStyle;f.strokeStyle=f.fillStyle;f.stroke();f.strokeStyle=n},complexity:function(){return 1},toObject:function(){return q(this.callSuper("toObject"),{x1:this.get("x1"),y1:this.get("y1"),x2:this.get("x2"),y2:this.get("y2")})}});h.Element.ATTRIBUTE_NAMES="x1 y1 x2 y2 stroke stroke-width transform".split(" ");h.Line.fromElement=function(f,n){var l=h.parseAttributes(f,h.Element.ATTRIBUTE_NAMES);return new h.Line([l.x1||0,l.y1||0,l.x2||0,l.y2||0],q(l,n))};
|
||||
h.Line.fromObject=function(f){return new h.Line([f.x1,f.y1,f.x2,f.y2],f)}}})();
|
||||
|
|
@ -141,7 +141,7 @@ l),e=a.d;delete a.d;return new h.Path(e,n(a,c))}}else console.warn("fabric.Path
|
|||
initProperties:function(){this.stateProperties.forEach(function(a){if(a==="fill")this.set(a,this.options[a]);else if(a==="angle")this.setAngle(this.options[a]);else this[a]=this.options[a]},this)},render:function(a){if(this.stub){a.save();this.transform(a);this.stub.render(a,false);if(this.active){this.drawBorders(a);this.drawCorners(a)}}else{a.save();var e=this.transformMatrix;e&&a.transform(e[0],e[1],e[2],e[3],e[4],e[5]);this.transform(a);e=0;for(var k=this.paths.length;e<k;++e)this.paths[e].render(a,
|
||||
true);if(this.active){this.drawBorders(a);this.hideCorners||this.drawCorners(a)}}a.restore()},set:function(a,e){if((a==="fill"||a==="overlayFill")&&this.isSameColor()){this[a]=e;for(var k=this.paths.length;k--;)this.paths[k].set(a,e)}else n.call(this,a,e);return this},toObject:function(){return q(l.call(this),{paths:f(this.getObjects(),"clone"),sourcePath:this.sourcePath})},toDatalessObject:function(){var a=this.toObject();if(this.sourcePath)a.paths=this.sourcePath;return a},toString:function(){return"#<fabric.PathGroup ("+
|
||||
this.complexity()+"): { top: "+this.top+", left: "+this.left+" }>"},isSameColor:function(){var a=this.getObjects()[0].get("fill");return this.getObjects().every(function(e){return e.get("fill")===a})},complexity:function(){return this.paths.reduce(function(a,e){return a+(e&&e.complexity?e.complexity():0)},0)},toGrayscale:function(){for(var a=this.paths.length;a--;)this.paths[a].toGrayscale();return this},getObjects:function(){return this.paths}});h.PathGroup.fromObject=function(a){for(var e=a.paths,
|
||||
k=0,p=e.length;k<p;k++)if(!(e[k]instanceof h.Object)){var r=c(g(e[k].type));e[k]=h[r].fromObject(e[k])}return new h.PathGroup(e,a)}}})();
|
||||
k=0,p=e.length;k<p;k++)if(!(e[k]instanceof h.Object)){var r=g(c(e[k].type));e[k]=h[r].fromObject(e[k])}return new h.PathGroup(e,a)}}})();
|
||||
(function(){var h=this.fabric||(this.fabric={}),q=h.util.object.extend,f=h.util.array.min,n=h.util.array.max,l=h.util.array.invoke,g=h.util.removeFromArray;if(!h.Group){h.Group=h.util.createClass(h.Object,{type:"group",initialize:function(c,a){this.objects=c||[];this.originalState={};this.callSuper("initialize");this._calcBounds();this._updateObjectsCoords();a&&q(this,a);this._setOpacityIfSame();this.setCoords(true);this.saveCoords();this.activateAllObjects()},_updateObjectsCoords:function(){var c=
|
||||
this.left,a=this.top;this.forEachObject(function(e){var k=e.get("left"),p=e.get("top");e.set("originalLeft",k);e.set("originalTop",p);e.set("left",k-c);e.set("top",p-a);e.setCoords();e.hideCorners=true},this)},toString:function(){return"#<fabric.Group: ("+this.complexity()+")>"},getObjects:function(){return this.objects},add:function(c){this._restoreObjectsState();this.objects.push(c);c.setActive(true);this._calcBounds();this._updateObjectsCoords();return this},remove:function(c){this._restoreObjectsState();
|
||||
g(this.objects,c);c.setActive(false);this._calcBounds();this._updateObjectsCoords();return this},size:function(){return this.getObjects().length},set:function(c,a){if(typeof a=="function")this.set(c,a(this[c]));else if(c==="fill"||c==="opacity"){var e=this.objects.length;for(this[c]=a;e--;)this.objects[e].set(c,a)}else this[c]=a;return this},contains:function(c){return this.objects.indexOf(c)>-1},toObject:function(){return q(this.callSuper("toObject"),{objects:l(this.objects,"clone")})},render:function(c){c.save();
|
||||
|
|
|
|||
|
|
@ -1405,22 +1405,13 @@
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returs JSON representation of canvas
|
||||
* @method toJSON
|
||||
* @return {String} json string
|
||||
*/
|
||||
toJSON: function () {
|
||||
return JSON.stringify(this.toObject());
|
||||
},
|
||||
|
||||
/**
|
||||
* Returs dataless JSON representation of canvas
|
||||
* @method toDatalessJSON
|
||||
* @return {String} json string
|
||||
*/
|
||||
toDatalessJSON: function () {
|
||||
return JSON.stringify(this.toDatalessObject());
|
||||
return this.toDatalessObject();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -2137,4 +2128,11 @@
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Returs JSON representation of canvas
|
||||
* @method toJSON
|
||||
* @return {String} json string
|
||||
*/
|
||||
fabric.Element.prototype.toJSON = fabric.Element.prototype.toObject;
|
||||
})();
|
||||
|
|
@ -166,15 +166,6 @@
|
|||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a JSON representation of an instance
|
||||
* @method toJSON
|
||||
* @return {String} json
|
||||
*/
|
||||
toJSON: function() {
|
||||
return JSON.stringify(this.toObject());
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns an object representation of an instance
|
||||
* @method toObject
|
||||
|
|
@ -1243,6 +1234,16 @@
|
|||
else if (angle > 315) { return 360; }
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a JSON representation of an instance
|
||||
* @method toJSON
|
||||
* @return {String} json
|
||||
*/
|
||||
toJSON: function() {
|
||||
// delegate, not alias
|
||||
return this.toObject();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -466,5 +466,5 @@
|
|||
path = parsedAttributes.d;
|
||||
delete parsedAttributes.d;
|
||||
return new fabric.Path(path, extend(parsedAttributes, options));
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
|
@ -189,7 +189,7 @@
|
|||
function instantiatePaths(paths) {
|
||||
for (var i = 0, len = paths.length; i < len; i++) {
|
||||
if (!(paths[i] instanceof fabric.Object)) {
|
||||
var klassName = capitalize(camelize(paths[i].type));
|
||||
var klassName = camelize(capitalize(paths[i].type));
|
||||
paths[i] = fabric[klassName].fromObject(paths[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -205,5 +205,5 @@
|
|||
fabric.PathGroup.fromObject = function(object) {
|
||||
var paths = instantiatePaths(object.paths);
|
||||
return new fabric.PathGroup(paths, object);
|
||||
}
|
||||
};
|
||||
})();
|
||||
Loading…
Reference in a new issue