mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-10 06:44:44 +00:00
Remove try/catch from around event handlers (for perf. reasons). Remove APE.anim references from fxCenterObjectH and fxCenterObjectV.
This commit is contained in:
parent
0583d7718d
commit
313cffa57f
6 changed files with 79 additions and 84 deletions
26
dist/all.js
vendored
26
dist/all.js
vendored
|
|
@ -833,7 +833,6 @@ if (!Function.prototype.bind) {
|
|||
fabric.util.addListener = addListener;
|
||||
fabric.util.removeListener = removeListener;
|
||||
|
||||
|
||||
var customEventListeners = { };
|
||||
|
||||
function observeEvent(eventName, handler) {
|
||||
|
|
@ -844,16 +843,10 @@ if (!Function.prototype.bind) {
|
|||
}
|
||||
|
||||
function fireEvent(eventName, memo) {
|
||||
if (!customEventListeners[eventName]) return;
|
||||
for (var i = 0, len = customEventListeners[eventName].length; i < len; i++) {
|
||||
try {
|
||||
customEventListeners[eventName][i]({ memo: memo });
|
||||
}
|
||||
catch(err) {
|
||||
setTimeout(function () {
|
||||
throw err;
|
||||
}, 0);
|
||||
}
|
||||
var listenersForEvent = customEventListeners[eventName];
|
||||
if (!listenersForEvent) return;
|
||||
for (var i = 0, len = listenersForEvent.length; i < len; i++) {
|
||||
listenersForEvent[i]({ memo: memo });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2081,8 +2074,8 @@ fabric.util.animate = animate;
|
|||
getPointer = fabric.util.getPointer,
|
||||
getElementOffset = fabric.util.getElementOffset,
|
||||
removeFromArray = fabric.util.removeFromArray,
|
||||
addListener = fabric.util.addlistener,
|
||||
removeListener = fabric.util.removelistener,
|
||||
addListener = fabric.util.addListener,
|
||||
removeListener = fabric.util.removeListener,
|
||||
|
||||
CANVAS_INIT_ERROR = new Error('Could not initialize `canvas` element'),
|
||||
FX_DURATION = 500,
|
||||
|
|
@ -4139,14 +4132,13 @@ fabric.util.animate = animate;
|
|||
clone = fabric.util.object.clone,
|
||||
toFixed = fabric.util.toFixed,
|
||||
capitalize = fabric.util.string.capitalize,
|
||||
getPointer = fabric.util.getPointer;
|
||||
getPointer = fabric.util.getPointer,
|
||||
slice = Array.prototype.slice
|
||||
|
||||
if (fabric.Object) {
|
||||
return;
|
||||
}
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
|
||||
/**
|
||||
* @class Object
|
||||
* @memberOf Canvas
|
||||
|
|
@ -4216,7 +4208,7 @@ fabric.util.animate = animate;
|
|||
callSuper: function(methodName) {
|
||||
var fn = this.constructor.superclass.prototype[methodName];
|
||||
return (arguments.length > 1)
|
||||
? fn.apply(this, _slice.call(arguments, 1))
|
||||
? fn.apply(this, slice.call(arguments, 1))
|
||||
: fn.call(this);
|
||||
},
|
||||
|
||||
|
|
|
|||
22
dist/all.min.js
vendored
22
dist/all.min.js
vendored
|
|
@ -15,15 +15,15 @@ k.shift();a.superclass=c;a.subclasses=[];if(c){e.prototype=c.prototype;a.prototy
|
|||
function a(m,n){return function(v){if(b[m]&&b[m][n])for(var u=b[m][n],w=0,x=u.length;w<x;w++)u[w].call(this,v||window.event)}}var c=function(){if(typeof document.documentElement.uniqueID!=="undefined")return function(n){return n.uniqueID};var m=0;return function(n){return n.__uniqueID||(n.__uniqueID="uniqueID__"+m++)}}(),k,p;(function(){var m={};k=function(n){return m[n]};p=function(n,v){m[n]=v}})();var r=e(document.documentElement,"addEventListener","removeEventListener")&&e(window,"addEventListener",
|
||||
"removeEventListener"),s=e(document.documentElement,"attachEvent","detachEvent")&&e(window,"attachEvent","detachEvent"),t={},b={};if(r){addListener=function(m,n,v){m.addEventListener(n,v,false)};removeListener=function(m,n,v){m.removeEventListener(n,v,false)}}else if(s){addListener=function(m,n,v){var u=c(m);p(u,m);t[u]||(t[u]={});t[u][n]||(t[u][n]=[]);v={handler:v,wrappedHandler:d(u,v)};t[u][n].push(v);m.attachEvent("on"+n,v.wrappedHandler)};removeListener=function(m,n,v){var u=c(m),w;if(t[u]&&t[u][n])for(var x=
|
||||
0,z=t[u][n].length;x<z;x++)if((w=t[u][n][x])&&w.handler===v){m.detachEvent("on"+n,w.wrappedHandler);t[u][n][x]=null}}}else{addListener=function(m,n,v){var u=c(m);b[u]||(b[u]={});if(!b[u][n]){b[u][n]=[];var w=m["on"+n];w&&b[u][n].push(w);m["on"+n]=a(u,n)}b[u][n].push(v)};removeListener=function(m,n,v){m=c(m);if(b[m]&&b[m][n]){n=b[m][n];m=0;for(var u=n.length;m<u;m++)n[m]===v&&n.splice(m,1)}}}h.util.addListener=addListener;h.util.removeListener=removeListener;var g={};h.util.observeEvent=function(m,
|
||||
n){g[m]||(g[m]=[]);g[m].push(n)};h.util.fireEvent=function(m,n){if(g[m])for(var v=0,u=g[m].length;v<u;v++)try{g[m][v]({memo:n})}catch(w){setTimeout(function(){throw w;},0)}};h.util.getPointer=function(m){var n=document.documentElement,v=document.body||{scrollLeft:0},u=document.documentElement,w=document.body||{scrollTop:0};return{x:m.pageX||m.clientX+(n.scrollLeft||v.scrollLeft)-(n.clientLeft||0),y:m.pageY||m.clientY+(u.scrollTop||w.scrollTop)-(u.clientTop||0)}}})(this);(function(){var e=document.createElement("div"),
|
||||
d=typeof e.style.filter==="string",a=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,c=function(k){return k};if(typeof e.style.opacity==="string")c=function(k,p){k.style.opacity=p;return k};else if(d)c=function(k,p){var r=k.style;if(k.currentStyle&&!k.currentStyle.hasLayout)r.zoom=1;if(a.test(r.filter)){p=p>=0.9999?"":"alpha(opacity="+p*100+")";r.filter=r.filter.replace(a,p)}else r.filter+=" alpha(opacity="+p*100+")";return k};h.util.setStyle=function(k,p){var r=k.style;if(typeof p==="string"){k.style.cssText+=
|
||||
";"+p;return p.indexOf("opacity")>-1?c(k,p.match(/opacity:\s*(\d?\.?\d*)/)[1]):k}for(var s in p)if(s==="opacity")c(k,p[s]);else r[s==="float"||s==="cssFloat"?typeof r.styleFloat==="undefined"?"cssFloat":"styleFloat":s]=p[s];return k}})();(function(){var e=document.documentElement.style,d="userSelect"in e?"userSelect":"MozUserSelect"in e?"MozUserSelect":"WebkitUserSelect"in e?"WebkitUserSelect":"KhtmlUserSelect"in e?"KhtmlUserSelect":"";h.util.makeElementUnselectable=function(a){if(typeof a.onselectstart!==
|
||||
"undefined")a.onselectstart=f;if(d)a.style[d]="none";else if(typeof a.unselectable=="string")a.unselectable="on";return a}})();(function(){function e(a,c){d.load(a);c()}h.util.getScript=function(a,c){var k=document.getElementsByTagName("head")[0],p=document.createElement("script"),r=true;p.type="text/javascript";p.setAttribute("runat","server");p.onload=p.onreadystatechange=function(s){if(r)if(!(typeof this.readyState=="string"&&this.readyState!=="loaded"&&this.readyState!=="complete")){r=false;c(s||
|
||||
window.event);p=p.onload=p.onreadystatechange=null}};p.src=a;k.appendChild(p)};var d=this.Jaxer;if(d&&d.load)h.util.getScript=e})();h.util.getById=function(e){return typeof e==="string"?document.getElementById(e):e};h.util.toArray=function(e){for(var d=[],a=e.length;a--;)d[a]=e[a];return d};h.util.makeElement=q;h.util.addClass=function(e,d){if((" "+e.className+" ").indexOf(" "+d+" ")===-1)e.className+=(e.className?" ":"")+d};h.util.wrapElement=function(e,d,a){if(typeof d==="string")d=q(d,a);e.parentNode&&
|
||||
e.parentNode.replaceChild(d,e);d.appendChild(e);return d};h.util.getElementOffset=function(e){var d=0,a=0;do{d+=e.offsetTop||0;a+=e.offsetLeft||0;e=e.offsetParent}while(e);return{left:a,top:d}};h.util.animate=function(e){e||(e={});var d=+new Date,a=e.duration||500,c=d+a,k,p,r=e.onChange||function(){},s=e.easing||function(n){return-Math.cos(n*Math.PI)/2+0.5},t="startValue"in e?e.startValue:0,b="endValue"in e?e.endValue:100,g=t>b;e.onStart&&e.onStart();var m=setInterval(function(){k=+new Date;p=k>c?
|
||||
1:(k-d)/a;r(g?t-(t-b)*s(p):t+(b-t)*s(p));if(k>c){clearInterval(m);e.onComplete&&e.onComplete()}},10)};(function(){function e(){}var d=function(){for(var a=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest}],c=a.length;c--;)try{if(a[c]())return a[c]}catch(k){}}();h.util.request=function(a,c){c||(c={});var k=c.method?c.method.toUpperCase():"GET",
|
||||
p=c.onComplete||function(){},r=d(),s;r.onreadystatechange=function(){if(r.readyState===4){p(r);r.onreadystatechange=e}};if(k==="GET"){s=null;if(typeof c.parameters=="string")a=a+(/\?/.test(a)?"&":"?")+c.parameters}r.open(k,a,true);if(k==="POST"||k==="PUT")r.setRequestHeader("Content-Type","application/x-www-form-urlencoded");r.send(s);return r}})();(function(){var e=Math.PI/180;h.util.removeFromArray=function(d,a){var c=d.indexOf(a);c!==-1&&d.splice(c,1);return d};h.util.degreesToRadians=function(d){return d*
|
||||
e};h.util.toFixed=function(d,a){return parseFloat(Number(d).toFixed(a))};h.util.getRandomInt=function(d,a){return Math.floor(Math.random()*(a-d+1))+d}})()})(this);
|
||||
n){g[m]||(g[m]=[]);g[m].push(n)};h.util.fireEvent=function(m,n){var v=g[m];if(v)for(var u=0,w=v.length;u<w;u++)v[u]({memo:n})};h.util.getPointer=function(m){var n=document.documentElement,v=document.body||{scrollLeft:0},u=document.documentElement,w=document.body||{scrollTop:0};return{x:m.pageX||m.clientX+(n.scrollLeft||v.scrollLeft)-(n.clientLeft||0),y:m.pageY||m.clientY+(u.scrollTop||w.scrollTop)-(u.clientTop||0)}}})(this);(function(){var e=document.createElement("div"),d=typeof e.style.filter===
|
||||
"string",a=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,c=function(k){return k};if(typeof e.style.opacity==="string")c=function(k,p){k.style.opacity=p;return k};else if(d)c=function(k,p){var r=k.style;if(k.currentStyle&&!k.currentStyle.hasLayout)r.zoom=1;if(a.test(r.filter)){p=p>=0.9999?"":"alpha(opacity="+p*100+")";r.filter=r.filter.replace(a,p)}else r.filter+=" alpha(opacity="+p*100+")";return k};h.util.setStyle=function(k,p){var r=k.style;if(typeof p==="string"){k.style.cssText+=";"+p;return p.indexOf("opacity")>
|
||||
-1?c(k,p.match(/opacity:\s*(\d?\.?\d*)/)[1]):k}for(var s in p)if(s==="opacity")c(k,p[s]);else r[s==="float"||s==="cssFloat"?typeof r.styleFloat==="undefined"?"cssFloat":"styleFloat":s]=p[s];return k}})();(function(){var e=document.documentElement.style,d="userSelect"in e?"userSelect":"MozUserSelect"in e?"MozUserSelect":"WebkitUserSelect"in e?"WebkitUserSelect":"KhtmlUserSelect"in e?"KhtmlUserSelect":"";h.util.makeElementUnselectable=function(a){if(typeof a.onselectstart!=="undefined")a.onselectstart=
|
||||
f;if(d)a.style[d]="none";else if(typeof a.unselectable=="string")a.unselectable="on";return a}})();(function(){function e(a,c){d.load(a);c()}h.util.getScript=function(a,c){var k=document.getElementsByTagName("head")[0],p=document.createElement("script"),r=true;p.type="text/javascript";p.setAttribute("runat","server");p.onload=p.onreadystatechange=function(s){if(r)if(!(typeof this.readyState=="string"&&this.readyState!=="loaded"&&this.readyState!=="complete")){r=false;c(s||window.event);p=p.onload=
|
||||
p.onreadystatechange=null}};p.src=a;k.appendChild(p)};var d=this.Jaxer;if(d&&d.load)h.util.getScript=e})();h.util.getById=function(e){return typeof e==="string"?document.getElementById(e):e};h.util.toArray=function(e){for(var d=[],a=e.length;a--;)d[a]=e[a];return d};h.util.makeElement=q;h.util.addClass=function(e,d){if((" "+e.className+" ").indexOf(" "+d+" ")===-1)e.className+=(e.className?" ":"")+d};h.util.wrapElement=function(e,d,a){if(typeof d==="string")d=q(d,a);e.parentNode&&e.parentNode.replaceChild(d,
|
||||
e);d.appendChild(e);return d};h.util.getElementOffset=function(e){var d=0,a=0;do{d+=e.offsetTop||0;a+=e.offsetLeft||0;e=e.offsetParent}while(e);return{left:a,top:d}};h.util.animate=function(e){e||(e={});var d=+new Date,a=e.duration||500,c=d+a,k,p,r=e.onChange||function(){},s=e.easing||function(n){return-Math.cos(n*Math.PI)/2+0.5},t="startValue"in e?e.startValue:0,b="endValue"in e?e.endValue:100,g=t>b;e.onStart&&e.onStart();var m=setInterval(function(){k=+new Date;p=k>c?1:(k-d)/a;r(g?t-(t-b)*s(p):
|
||||
t+(b-t)*s(p));if(k>c){clearInterval(m);e.onComplete&&e.onComplete()}},10)};(function(){function e(){}var d=function(){for(var a=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0")},function(){return new XMLHttpRequest}],c=a.length;c--;)try{if(a[c]())return a[c]}catch(k){}}();h.util.request=function(a,c){c||(c={});var k=c.method?c.method.toUpperCase():"GET",p=c.onComplete||function(){},
|
||||
r=d(),s;r.onreadystatechange=function(){if(r.readyState===4){p(r);r.onreadystatechange=e}};if(k==="GET"){s=null;if(typeof c.parameters=="string")a=a+(/\?/.test(a)?"&":"?")+c.parameters}r.open(k,a,true);if(k==="POST"||k==="PUT")r.setRequestHeader("Content-Type","application/x-www-form-urlencoded");r.send(s);return r}})();(function(){var e=Math.PI/180;h.util.removeFromArray=function(d,a){var c=d.indexOf(a);c!==-1&&d.splice(c,1);return d};h.util.degreesToRadians=function(d){return d*e};h.util.toFixed=
|
||||
function(d,a){return parseFloat(Number(d).toFixed(a))};h.util.getRandomInt=function(d,a){return Math.floor(Math.random()*(a-d+1))+d}})()})(this);
|
||||
(function(){var l=this.fabric||(this.fabric={}),q=l.util.object.extend,f=l.util.string.capitalize,h=l.util.object.clone,o={cx:"left",x:"left",cy:"top",y:"top",r:"radius","fill-opacity":"opacity","fill-rule":"fillRule","stroke-width":"strokeWidth",transform:"transformMatrix"};l.parseTransformAttribute=function(){function e(r,s){var t=s[0];r[0]=Math.cos(t);r[1]=Math.sin(t);r[2]=-Math.sin(t);r[3]=Math.cos(t)}function d(r,s){var t=s.length===2?s[1]:s[0];r[0]=s[0];r[3]=t}function a(r,s){r[4]=s[0];if(s.length===
|
||||
2)r[5]=s[1]}var c=[1,0,0,1,0,0],k=RegExp("^\\s*(?:(?:(?:(?:(matr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(?:\\.\\d+)?(?:e[-+]?\\d+)?))(?:\\s+,?\\s*|,\\s*)((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))(?:\\s+,?\\s*|,\\s*)((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))(?:\\s+,?\\s*|,\\s*)((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))(?:\\s+,?\\s*|,\\s*)((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))\\s*\\))|(?:(translate)\\s*\\(\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))(?:(?:\\s+,?\\s*|,\\s*)((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)))?\\s*\\))|(?:(scale)\\s*\\(\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))(?:(?:\\s+,?\\s*|,\\s*)((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)))?\\s*\\))|(?:(rotate)\\s*\\(\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))(?:(?:\\s+,?\\s*|,\\s*)((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))(?:\\s+,?\\s*|,\\s*)((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?)))?\\s*\\))|(?:(skewX)\\s*\\(\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))\\s*\\))|(?:(skewY)\\s*\\(\\s*((?:[-+]?\\d+(?:\\.\\d+)?(?:e[-+]?\\d+)?))\\s*\\)))");
|
||||
|
|
@ -46,7 +46,7 @@ l.prototype.toRgba=function(){var f=this.getSource();return"rgba("+f[0]+","+f[1]
|
|||
function(){var f=this.getSource(),h=parseInt((f[0]*0.3+f[1]*0.59+f[2]*0.11).toFixed(0),10);this.setSource([h,h,h,f[3]]);return this};l.prototype.toBlackWhite=function(f){var h=this.getSource(),o=(h[0]*0.3+h[1]*0.59+h[2]*0.11).toFixed(0);h=h[3];f=f||127;o=Number(o)<Number(f)?0:255;this.setSource([o,o,o,h]);return this};l.prototype.overlayWith=function(f){f=new l(f);var h=[],o=this.getAlpha(),e=this.getSource();f=f.getSource();for(var d=0;d<3;d++)h.push(Math.round(e[d]*0.5+f[d]*0.5));h[4]=o;this.setSource(h);
|
||||
return this};l.reRGBa=/^rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(\d+(?:\.\d+)?))?\)$/;l.reHex=/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i;l.fromRgb=function(f){return l.fromSource(l.sourceFromRgb(f))};l.sourceFromRgb=function(f){if(f=f.match(l.reRGBa))return[parseInt(f[1],10),parseInt(f[2],10),parseInt(f[3],10),f[4]?parseFloat(f[4]):1]};l.fromRgba=l.fromRgb;l.fromHex=function(f){return l.fromSource(l.sourceFromHex(f))};l.sourceFromHex=function(f){if(f.match(l.reHex)){var h=f.slice(f.indexOf("#")+
|
||||
1),o=h.length===3;f=o?h.charAt(0)+h.charAt(0):h.substring(0,2);var e=o?h.charAt(1)+h.charAt(1):h.substring(2,4);h=o?h.charAt(2)+h.charAt(2):h.substring(4,6);return[parseInt(f,16),parseInt(e,16),parseInt(h,16),1]}};l.fromSource=function(f){var h=new l;h.setSource(f);return h}}})();
|
||||
(function(){if(fabric.Element)console.warn("fabric.Element is already defined.");else{var l=this.window,q=l.document,f=fabric.util.object.extend,h=fabric.util.string.capitalize,o=fabric.util.string.camelize,e=fabric.util.fireEvent,d=fabric.util.getPointer,a=fabric.util.getElementOffset,c=fabric.util.removeFromArray,k=fabric.util.addlistener,p=fabric.util.removelistener,r=Error("Could not initialize `canvas` element"),s={tr:"ne-resize",br:"se-resize",bl:"sw-resize",tl:"nw-resize",ml:"w-resize",mt:"n-resize",
|
||||
(function(){if(fabric.Element)console.warn("fabric.Element is already defined.");else{var l=this.window,q=l.document,f=fabric.util.object.extend,h=fabric.util.string.capitalize,o=fabric.util.string.camelize,e=fabric.util.fireEvent,d=fabric.util.getPointer,a=fabric.util.getElementOffset,c=fabric.util.removeFromArray,k=fabric.util.addListener,p=fabric.util.removeListener,r=Error("Could not initialize `canvas` element"),s={tr:"ne-resize",br:"se-resize",bl:"sw-resize",tl:"nw-resize",ml:"w-resize",mt:"n-resize",
|
||||
mr:"e-resize",mb:"s-resize"};(function(){var b=q.createElement("canvas"),g,m,n;b.width=b.height=300;if(b.getContext)if(m=b.getContext("2d")){g=new Date;for(n=200;n--;)m.clearRect(0,0,300,300);m=new Date-g;g=new Date;for(n=200;n--;)b.width=b.height;if(new Date-g<m)return"width"}})();var t=function(){var b=q.createElement("canvas");if(b&&b.getContext)if(b=b.getContext("2d")){try{b.fillStyle="transparent";return true}catch(g){}return false}}();fabric.Element=function(b,g){this._groupSelector=null;this._aObjects=
|
||||
[];this._activeGroup=this._currentTransform=this._oElement=this._oContext=null;this._oConfig={width:300,height:150};g=g||{};this._initElement(b);this._initConfig(g);g.overlayImage&&this.setOverlayImage(g.overlayImage);if(g.afterRender)this.afterRender=g.afterRender;this._createCanvasBackground();this._createCanvasContainer();this._initEvents();this.calcOffset()};f(fabric.Element.prototype,{selectionColor:"rgba(100,100,255,0.3)",selectionBorderColor:"rgba(255,255,255,0.3)",selectionLineWidth:1,backgroundColor:"rgba(255,255,255,1)",
|
||||
includeDefaultValues:true,shouldCacheImages:false,CANVAS_WIDTH:600,CANVAS_HEIGHT:600,onBeforeScaleRotate:function(){},calcOffset:function(){this._offset=a(this.getElement());return this},setOverlayImage:function(b,g){if(b){var m=this,n=new Image;n.onload=function(){m.overlayImage=n;g&&g();n=n.onload=null};n.src=b}return this},_initElement:function(b){this._oElement=fabric.util.getById(b)||q.createElement("canvas");typeof this._oElement.getContext==="undefined"&&G_vmlCanvasManager.initElement(this._oElement);
|
||||
|
|
@ -87,7 +87,7 @@ deactivateAll:function(){for(var b=this.getObjects(),g=0,m=b.length;g<m;g++)b[g]
|
|||
g.width=this.getWidth();g.height=this.getHeight();var m=this.__clone||(this.__clone=new fabric.Element(g));return m.loadFromJSON(this.toJSON(),function(){b&&b(m)})},_toDataURL:function(b,g){this.clone(function(m){g(m.toDataURL(b))})},_toDataURLWithMultiplier:function(b,g,m){this.clone(function(n){m(n.toDataURLWithMultiplier(b,g))})},_resizeImageToFit:function(b){var g=b.width||b.offsetWidth,m=b.height||b.offsetHeight,n=this.getWidth()/g,v=this.getHeight()/m;if(g&&m){b.width=g*n;b.height=m*v}},cache:{has:function(b,
|
||||
g){g(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 g=b.getContext("2d");b=g.getImageData(0,0,b.width,b.height);var m=b.data,n=b.width,v=b.height,u,w;for(i=0;i<n;i++)for(j=0;j<v;j++){u=i*4*v+j*4;w=(m[u]+m[u+1]+m[u+2])/3;m[u]=w;m[u+1]=w;m[u+2]=w}g.putImageData(b,0,0)},
|
||||
supports:function(b){var g=q.createElement("canvas");if(!g||!g.getContext)return null;var m=g.getContext("2d");if(!m)return null;switch(b){case "getImageData":return typeof m.getImageData!=="undefined";case "toDataURL":return typeof g.toDataURL!=="undefined";default:return null}}})}})();
|
||||
(function(){var l=this.fabric||(this.fabric={}),q=l.util.object.extend,f=l.util.object.clone,h=l.util.toFixed,o=l.util.string.capitalize,e=l.util.getPointer;if(!l.Object){var d=Array.prototype.slice;l.Object=l.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(" "),
|
||||
(function(){var l=this.fabric||(this.fabric={}),q=l.util.object.extend,f=l.util.object.clone,h=l.util.toFixed,o=l.util.string.capitalize,e=l.util.getPointer,d=Array.prototype.slice;if(!l.Object){l.Object=l.util.createClass({type:"object",includeDefaultValues:true,NUM_FRACTION_DIGITS:2,FX_DURATION:500,FX_TRANSITION:"decel",MIN_SCALE_LIMIT:0.1,stateProperties:"top left width height scaleX scaleY flipX flipY theta angle opacity cornersize fill overlayFill stroke strokeWidth fillRule borderScaleFactor transformMatrix".split(" "),
|
||||
options:{top:0,left:0,width:100,height:100,scaleX:1,scaleY:1,flipX:false,flipY:false,theta:0,opacity:1,angle:0,cornersize:10,padding:0,borderColor:"rgba(102,153,255,0.75)",cornerColor:"rgba(102,153,255,0.5)",fill:"rgb(0,0,0)",overlayFill:null,stroke:null,strokeWidth:1,fillRule:"source-over",borderOpacityWhenMoving:0.4,borderScaleFactor:1,transformMatrix:null},callSuper:function(a){var c=this.constructor.superclass.prototype[a];return arguments.length>1?c.apply(this,d.call(arguments,1)):c.call(this)},
|
||||
initialize:function(a){this.setOptions(a);this._importProperties();this.originalState={};this.setCoords();this.saveState()},setOptions:function(a){this.options=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:h(this.left,this.NUM_FRACTION_DIGITS),top:h(this.top,this.NUM_FRACTION_DIGITS),width:h(this.width,this.NUM_FRACTION_DIGITS),height:h(this.height,this.NUM_FRACTION_DIGITS),
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
getPointer = fabric.util.getPointer,
|
||||
getElementOffset = fabric.util.getElementOffset,
|
||||
removeFromArray = fabric.util.removeFromArray,
|
||||
addListener = fabric.util.addlistener,
|
||||
removeListener = fabric.util.removelistener,
|
||||
addListener = fabric.util.addListener,
|
||||
removeListener = fabric.util.removeListener,
|
||||
|
||||
CANVAS_INIT_ERROR = new Error('Could not initialize `canvas` element'),
|
||||
FX_DURATION = 500,
|
||||
|
|
@ -1309,25 +1309,28 @@
|
|||
* @chainable
|
||||
*/
|
||||
fxCenterObjectH: function (object) {
|
||||
var _this = this,
|
||||
fx = new APE.anim.Animation(),
|
||||
startValue = object.get('left'),
|
||||
endValue = _this.getCenter().left,
|
||||
step = endValue - startValue;
|
||||
callbacks = callbacks || { };
|
||||
|
||||
fx.run = function (percent) {
|
||||
object.set('left', startValue + step * percent);
|
||||
_this.renderAll();
|
||||
};
|
||||
|
||||
fx.onend = function () {
|
||||
object.setCoords();
|
||||
};
|
||||
var empty = function() { },
|
||||
onComplete = callbacks.onComplete || empty,
|
||||
onChange = callbacks.onChange || empty,
|
||||
_this = this;
|
||||
|
||||
fabric.util.animate({
|
||||
startValue: object.get('left'),
|
||||
endValue: this.getCenter().left,
|
||||
duration: this.FX_DURATION,
|
||||
onChange: function(value) {
|
||||
object.set('left', value);
|
||||
_this.renderAll();
|
||||
onChange();
|
||||
},
|
||||
onComplete: function() {
|
||||
object.setCoords();
|
||||
onComplete();
|
||||
}
|
||||
});
|
||||
|
||||
fx.duration = FX_DURATION;
|
||||
fx.transition = APE.anim.Transitions[FX_TRANSITION];
|
||||
fx.start();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -1352,25 +1355,29 @@
|
|||
* @chainable
|
||||
*/
|
||||
fxCenterObjectV: function (object) {
|
||||
var _this = this,
|
||||
fx = new APE.anim.Animation(),
|
||||
startValue = object.get('top'),
|
||||
endValue = _this.getCenter().top,
|
||||
step = endValue - startValue;
|
||||
callbacks = callbacks || { };
|
||||
|
||||
fx.run = function (percent) {
|
||||
object.set('top', startValue + step * percent).setCoords();
|
||||
_this.renderAll();
|
||||
};
|
||||
|
||||
fx.onend = function () {
|
||||
object.setCoords();
|
||||
};
|
||||
var empty = function() { },
|
||||
onComplete = callbacks.onComplete || empty,
|
||||
onChange = callbacks.onChange || empty,
|
||||
_this = this;
|
||||
|
||||
fx.duration = FX_DURATION;
|
||||
fx.transition = APE.anim.Transitions[FX_TRANSITION];
|
||||
fabric.util.animate({
|
||||
startValue: object.get('top'),
|
||||
endValue: this.getCenter().top,
|
||||
duration: this.FX_DURATION,
|
||||
onChange: function(value) {
|
||||
object.set('top', value);
|
||||
_this.renderAll();
|
||||
onChange();
|
||||
},
|
||||
onComplete: function() {
|
||||
object.setCoords();
|
||||
onComplete();
|
||||
}
|
||||
});
|
||||
|
||||
fx.start();
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,14 +11,13 @@
|
|||
clone = fabric.util.object.clone,
|
||||
toFixed = fabric.util.toFixed,
|
||||
capitalize = fabric.util.string.capitalize,
|
||||
getPointer = fabric.util.getPointer;
|
||||
getPointer = fabric.util.getPointer,
|
||||
slice = Array.prototype.slice
|
||||
|
||||
if (fabric.Object) {
|
||||
return;
|
||||
}
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
|
||||
/**
|
||||
* @class Object
|
||||
* @memberOf Canvas
|
||||
|
|
@ -89,7 +88,7 @@
|
|||
callSuper: function(methodName) {
|
||||
var fn = this.constructor.superclass.prototype[methodName];
|
||||
return (arguments.length > 1)
|
||||
? fn.apply(this, _slice.call(arguments, 1))
|
||||
? fn.apply(this, slice.call(arguments, 1))
|
||||
: fn.call(this);
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@
|
|||
|
||||
var fabric = this.fabric || (this.fabric = { }),
|
||||
extend = fabric.util.object.extend,
|
||||
invoke = fabric.util.array.invoke;
|
||||
invoke = fabric.util.array.invoke,
|
||||
parentSet = fabric.Object.prototype.set,
|
||||
parentToObject = fabric.Object.prototype.toObject,
|
||||
camelize = fabric.util.string.camelize,
|
||||
capitalize = fabric.util.string.capitalize;
|
||||
|
||||
if (fabric.PathGroup) {
|
||||
console.warn('fabric.PathGroup is already defined');
|
||||
|
|
@ -96,7 +100,7 @@
|
|||
}
|
||||
else {
|
||||
// skipping parent "class" - fabric.Path
|
||||
fabric.Object.prototype.set.call(this, prop, value);
|
||||
parentSet.call(this, prop, value);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
|
@ -106,8 +110,7 @@
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
var _super = fabric.Object.prototype.toObject;
|
||||
return extend(_super.call(this), {
|
||||
return extend(toObject.call(this), {
|
||||
paths: invoke(this.getObjects(), 'clone'),
|
||||
sourcePath: this.sourcePath
|
||||
});
|
||||
|
|
@ -186,8 +189,8 @@
|
|||
function instantiatePaths(paths) {
|
||||
for (var i = 0, len = paths.length; i < len; i++) {
|
||||
if (!(paths[i] instanceof fabric.Object)) {
|
||||
var klassName = paths[i].type.camelize().capitalize();
|
||||
paths[i] = Canvas[klassName].fromObject(paths[i]);
|
||||
var klassName = capitalize(camelize(paths[i].type));
|
||||
paths[i] = fabric[klassName].fromObject(paths[i]);
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
|
|
|
|||
|
|
@ -143,7 +143,6 @@
|
|||
fabric.util.addListener = addListener;
|
||||
fabric.util.removeListener = removeListener;
|
||||
|
||||
|
||||
var customEventListeners = { };
|
||||
|
||||
function observeEvent(eventName, handler) {
|
||||
|
|
@ -154,16 +153,11 @@
|
|||
}
|
||||
|
||||
function fireEvent(eventName, memo) {
|
||||
if (!customEventListeners[eventName]) return;
|
||||
for (var i = 0, len = customEventListeners[eventName].length; i < len; i++) {
|
||||
try {
|
||||
customEventListeners[eventName][i]({ memo: memo });
|
||||
}
|
||||
catch(err) {
|
||||
setTimeout(function () {
|
||||
throw err;
|
||||
}, 0);
|
||||
}
|
||||
var listenersForEvent = customEventListeners[eventName];
|
||||
if (!listenersForEvent) return;
|
||||
for (var i = 0, len = listenersForEvent.length; i < len; i++) {
|
||||
// avoiding try/catch for perf. reasons
|
||||
listenersForEvent[i]({ memo: memo });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue