diff --git a/dist/all.js b/dist/all.js index d4e7dbed..a6bee584 100644 --- a/dist/all.js +++ b/dist/all.js @@ -8328,17 +8328,18 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fab * @private * @method _shouldClearSelection */ - _shouldClearSelection: function (e) { - var target = this.findTarget(e), - activeGroup = this.getActiveGroup(); + _shouldClearSelection: function (e, target) { + var activeGroup = this.getActiveGroup(); + return ( !target || ( - target && - activeGroup && - !activeGroup.contains(target) && - activeGroup !== target && - !e.shiftKey - ) + target && + activeGroup && + !activeGroup.contains(target) && + activeGroup !== target && + !e.shiftKey) || ( + target && + !target.selectable) ); }, @@ -8775,9 +8776,8 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fab break; } } - if (target && target.selectable) { - return target; - } + + return target; }, /** @@ -9233,7 +9233,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fab var target = this.findTarget(e), corner; pointer = this.getPointer(e); - if (this._shouldClearSelection(e)) { + if (this._shouldClearSelection(e, target)) { this._groupSelector = { ex: pointer.x, ey: pointer.y, @@ -9241,7 +9241,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fab left: 0 }; this.deactivateAllWithDispatch(); - target && this.setActiveObject(target, e); + target && target.selectable && this.setActiveObject(target, e); } else { // determine if it's a drag or rotate case @@ -9306,7 +9306,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fab var groupSelector = this._groupSelector; // We initially clicked in an empty area, so we draw a box for multiple selection. - if (groupSelector !== null) { + if (groupSelector) { pointer = getPointer(e, this.upperCanvasEl); groupSelector.left = pointer.x - this._offset.left - groupSelector.ex; @@ -9324,7 +9324,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fab // performance. target = this.findTarget(e); - if (!target) { + if (!target || target && !target.selectable) { // image/text was hovered-out from, we remove its borders for (var i = this._objects.length; i--; ) { if (this._objects[i] && !this._objects[i].active) { @@ -9343,85 +9343,66 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @scope fab pointer = getPointer(e, this.upperCanvasEl); var x = pointer.x, - y = pointer.y; + y = pointer.y, + reset = false, + transform = this._currentTransform; - this._currentTransform.target.isMoving = true; + target = transform.target; + target.isMoving = true; - var t = this._currentTransform, reset = false; - if ( - (t.action === 'scale' || t.action === 'scaleX' || t.action === 'scaleY') - && - ( - // Switch from a normal resize to center-based - (e.altKey && (t.originX !== 'center' || t.originY !== 'center')) - || - // Switch from center-based resize to normal one - (!e.altKey && t.originX === 'center' && t.originY === 'center') - ) - ) { + if ((transform.action === 'scale' || transform.action === 'scaleX' || transform.action === 'scaleY') && + // Switch from a normal resize to center-based + ((e.altKey && (transform.originX !== 'center' || transform.originY !== 'center')) || + // Switch from center-based resize to normal one + (!e.altKey && transform.originX === 'center' && transform.originY === 'center')) + ) { this._resetCurrentTransform(e); reset = true; } - if (this._currentTransform.action === 'rotate') { + if (transform.action === 'rotate') { this._rotateObject(x, y); - this.fire('object:rotating', { - target: this._currentTransform.target, - e: e - }); - this._currentTransform.target.fire('rotating'); + this.fire('object:rotating', { target: target, e: e }); + target.fire('rotating', { e: e }); } - else if (this._currentTransform.action === 'scale') { + else if (transform.action === 'scale') { // rotate object only if shift key is not pressed // and if it is not a group we are transforming - - if (e.shiftKey || this.uniScaleTransform) { - this._currentTransform.currentAction = 'scale'; + if ((e.shiftKey || this.uniScaleTransform) && !target.get('lockUniScaling')) { + transform.currentAction = 'scale'; this._scaleObject(x, y); } else { - if (!reset && t.currentAction === 'scale') { - // Switch from a normal resize to proportional + // Switch from a normal resize to proportional + if (!reset && transform.currentAction === 'scale') { this._resetCurrentTransform(e); } - this._currentTransform.currentAction = 'scaleEqually'; + transform.currentAction = 'scaleEqually'; this._scaleObject(x, y, 'equally'); } - this.fire('object:scaling', { - target: this._currentTransform.target, - e: e - }); - this._currentTransform.target.fire('scaling', { e: e }); + this.fire('object:scaling', { target: target, e: e }); + target.fire('scaling', { e: e }); } - else if (this._currentTransform.action === 'scaleX') { + else if (transform.action === 'scaleX') { this._scaleObject(x, y, 'x'); - this.fire('object:scaling', { - target: this._currentTransform.target, - e: e - }); - this._currentTransform.target.fire('scaling', { e: e }); + this.fire('object:scaling', { target: target, e: e}); + target.fire('scaling', { e: e }); } - else if (this._currentTransform.action === 'scaleY') { + else if (transform.action === 'scaleY') { this._scaleObject(x, y, 'y'); - this.fire('object:scaling', { - target: this._currentTransform.target, - e: e - }); - this._currentTransform.target.fire('scaling', { e: e }); + this.fire('object:scaling', { target: target, e: e}); + target.fire('scaling', { e: e }); } else { this._translateObject(x, y); - this.fire('object:moving', { - target: this._currentTransform.target, - e: e - }); - this._currentTransform.target.fire('moving', { e: e }); + this.fire('object:moving', { target: target, e: e}); + target.fire('moving', { e: e }); this._setCursor(this.moveCursor); } @@ -9606,7 +9587,11 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @scope fabric.Stati ? JSON.parse(json) : json; - if (!serialized || (serialized && !serialized.objects)) return; + if (!serialized) return; + + if (!serialized.objects) { + serialized.objects = []; + } this.clear(); @@ -9761,6 +9746,10 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @scope fabric.Stati backgroundPatternLoaded, backgroundImageLoaded, overlayImageLoaded; + + var cbIfLoaded = function () { + callback && backgroundImageLoaded && overlayImageLoaded && backgroundPatternLoaded && callback(); + }; if (serialized.backgroundImage) { this.setBackgroundImage(serialized.backgroundImage, function() { @@ -9772,7 +9761,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @scope fabric.Stati backgroundImageLoaded = true; - callback && overlayImageLoaded && backgroundPatternLoaded && callback(); + cbIfLoaded(); }); } else { @@ -9788,7 +9777,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @scope fabric.Stati _this.renderAll(); overlayImageLoaded = true; - callback && backgroundImageLoaded && backgroundPatternLoaded && callback(); + cbIfLoaded(); }); } else { @@ -9801,7 +9790,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @scope fabric.Stati _this.renderAll(); backgroundPatternLoaded = true; - callback && overlayImageLoaded && backgroundImageLoaded && callback(); + cbIfLoaded(); }); } else { @@ -10392,7 +10381,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @scope fabric.Stati "stroke-width: ", (this.strokeWidth ? this.strokeWidth : '0'), "; ", "stroke-dasharray: ", (this.strokeDashArray ? this.strokeDashArray.join(' ') : "; "), "fill: ", (this.fill ? (this.fill && this.fill.toLive ? 'url(#SVGID_' + this.fill.id + ')' : this.fill) : 'none'), "; ", - "opacity: ", (this.opacity ? this.opacity : '1'), ";", + "opacity: ", (typeof this.opacity !== 'undefined' ? this.opacity : '1'), ";", (this.visible ? '' : " visibility: hidden;") ].join(""); }, @@ -16591,8 +16580,10 @@ fabric.Image.filters.Pixelate.fromObject = function(object) { * @method _initDimensions */ _initDimensions: function() { - var canvasEl = fabric.util.createCanvasElement(); - this._render(canvasEl.getContext('2d')); + if (!this._ctxForDimensions) { + this._ctxForDimensions = fabric.util.createCanvasElement().getContext('2d'); + } + this._render(this._ctxForDimensions); }, /** diff --git a/dist/all.min.js b/dist/all.min.js index 16ee4450..bb11fc5a 100644 --- a/dist/all.min.js +++ b/dist/all.min.js @@ -1,6 +1,6 @@ /* build: `node build.js modules=ALL exclude=gestures` *//*! Fabric.js Copyright 2008-2013, Printio (Juriy Zaytsev, Maxim Chernyak) */var fabric=fabric||{version:"1.1.7"};typeof exports!="undefined"&&(exports.fabric=fabric),typeof document!="undefined"&&typeof window!="undefined"?(fabric.document=document,fabric.window=window):(fabric.document=require("jsdom").jsdom("
"),fabric.window=fabric.document.createWindow()),fabric.isTouchSupported="ontouchstart"in fabric.document.documentElement,fabric.isLikelyNode=typeof Buffer!="undefined"&&typeof window=="undefined";var Cufon=function(){function r(e){var t=this.face=e.face;this.glyphs=e.glyphs,this.w=e.w,this.baseSize=parseInt(t["units-per-em"],10),this.family=t["font-family"].toLowerCase(),this.weight=t["font-weight"],this.style=t["font-style"]||"normal",this.viewBox=function(){var e=t.bbox.split(/\s+/),n={minX:parseInt(e[0],10),minY:parseInt(e[1],10),maxX:parseInt(e[2],10),maxY:parseInt(e[3],10)};return n.width=n.maxX-n.minX,n.height=n.maxY-n.minY,n.toString=function(){return[this.minX,this.minY,this.width,this.height].join(" ")},n}(),this.ascent=-parseInt(t.ascent,10),this.descent=-parseInt(t.descent,10),this.height=-this.ascent+this.descent}function i(){var e={},t={oblique:"italic",italic:"oblique"};this.add=function(t){(e[t.style]||(e[t.style]={}))[t.weight]=t},this.get=function(n,r){var i=e[n]||e[t[n]]||e.normal||e.italic||e.oblique;if(!i)return null;r={normal:400,bold:700}[r]||parseInt(r,10);if(i[r])return i[r];var s={1:1,99:0}[r%100],o=[],u,a;s===undefined&&(s=r>400),r==500&&(r=400);for(var f in i){f=parseInt(f,10);if(!u||fa)a=f;o.push(f)}return ra&&(r=a),o.sort(function(e,t){return(s?e>r&&t>r?e-1},complexity:function(){return this.getObjects().reduce(function(e,t){return e+=t.complexity?t.complexity():0,e},0)},toGrayscale:function(){return this.forEachObject(function(e){e.toGrayscale()})}},function(){function n(e,t){var n=e.indexOf(t);return n!==-1&&e.splice(n,1),e}function r(e,t){return Math.floor(Math.random()*(t-e+1))+e}function s(e){return e*i}function o(e){return e/i}function u(e,t,n){var r=Math.sin(n),i=Math.cos(n);e.subtractEquals(t);var s=e.x*i-e.y*r,o=e.x*r+e.y*i;return(new fabric.Point(s,o)).addEquals(t)}function a(e,t){return parseFloat(Number(e).toFixed(t))}function f(){return!1}function l(e){e||(e={});var t=+(new Date),n=e.duration||500,r=t+n,i,s=e.onChange||function(){},o=e.abort||function(){return!1},u=e.easing||function(e,t,n,r){return-n*Math.cos(e/r*(Math.PI/2))+n+t},a="startValue"in e?e.startValue:0,f="endValue"in e?e.endValue:100,l=e.byValue||f-a;e.onStart&&e.onStart(),function c(){i=+(new Date);var f=i>r?n:i-t;s(u(f,a,l,n));if(i>r||o()){e.onComplete&&e.onComplete();return}h(c)}()}function p(e,t,n){if(e){var r=new Image;r.onload=function(){t&&t.call(n,r),r=r.onload=null},r.src=e}else t&&t.call(n,e)}function d(e,t){function n(e){return fabric[fabric.util.string.camelize(fabric.util.string.capitalize(e))]}function r(){++s===o&&t&&t(i)}var i=[],s=0,o=e.length;e.forEach(function(e,t){if(!e.type)return;var s=n(e.type);s.async?s.fromObject(e,function(e,n){n||(i[t]=e),r()}):(i[t]=s.fromObject(e),r())})}function v(e,t,n){var r;return e.length>1?r=new fabric.PathGroup(e,t):r=e[0],typeof n!="undefined"&&r.setSourcePath(n),r}function m(e,t,n){if(n&&Object.prototype.toString.call(n)==="[object Array]")for(var r=0,i=n.length;rr)r+=u[p++%h],r>l&&(r=l),n[d?"lineTo":"moveTo"](r,0),d=!d;n.restore()}function y(e){return e||(e=fabric.document.createElement("canvas")),!e.getContext&&typeof G_vmlCanvasManager!="undefined"&&G_vmlCanvasManager.initElement(e),e}function b(e){var t=e.prototype;for(var n=t.stateProperties.length;n--;){var r=t.stateProperties[n],i=r.charAt(0).toUpperCase()+r.slice(1),s="set"+i,o="get"+i;t[o]||(t[o]=function(e){return new Function('return this.get("'+e+'")')}(r)),t[s]||(t[s]=function(e){return new Function("value",'return this.set("'+e+'", value)')}(r))}}function w(e,t){t.save(),t.beginPath(),e.clipTo(t),t.clip()}function E(e,t){var n=[[e[0],e[2],e[4]],[e[1],e[3],e[5]],[0,0,1]],r=[[t[0],t[2],t[4]],[t[1],t[3],t[5]],[0,0,1]],i=[];for(var s=0;s<3;s++){i[s]=[];for(var o=0;o<3;o++){var u=0;for(var a=0;a<3;a++)u+=n[s][a]*r[a][o];i[s][o]=u}}return[i[0][0],i[1][0],i[0][1],i[1][1],i[0][2],i[1][2]]}var e=Math.sqrt,t=Math.atan2;fabric.util={};var i=Math.PI/180,c=fabric.window.requestAnimationFrame||fabric.window.webkitRequestAnimationFrame||fabric.window.mozRequestAnimationFrame||fabric.window.oRequestAnimationFrame||fabric.window.msRequestAnimationFrame||function(e){fabric.window.setTimeout(e,1e3/60)},h=function(){return c.apply(fabric.window,arguments)};fabric.util.removeFromArray=n,fabric.util.degreesToRadians=s,fabric.util.radiansToDegrees=o,fabric.util.rotatePoint=u,fabric.util.toFixed=a,fabric.util.getRandomInt=r,fabric.util.falseFunction=f,fabric.util.animate=l,fabric.util.requestAnimFrame=h,fabric.util.loadImage=p,fabric.util.enlivenObjects=d,fabric.util.groupSVGElements=v,fabric.util.populateWithProperties=m,fabric.util.drawDashedLine=g,fabric.util.createCanvasElement=y,fabric.util.createAccessors=b,fabric.util.clipContext=w,fabric.util.multiplyTransformMatrices=E}(),function(){function t(t,n){var r=e.call(arguments,2),i=[];for(var s=0,o=t.length;s>>0,n=0,r;if(arguments.length>1)r=arguments[1];else do{if(n in this){r=this[n++];break}if(++n>=t)throw new TypeError}while(!0);for(;n0&&(i.status="Intersection"),i},t.Intersection.intersectPolygonPolygon=function(e,t){var r=new n("No Intersection"),i=e.length;for(var s=0;s0&&(r.status="Intersection"),r},t.Intersection.intersectPolygonRectangle=function(e,r,i){var s=r.min(i),o=r.max(i),u=new t.Point(o.x,s.y),a=new t.Point(s.x,o.y),f=n.intersectLinePolygon(s,u,e),l=n.intersectLinePolygon(u,o,e),c=n.intersectLinePolygon(o,a,e),h=n.intersectLinePolygon(a,s,e),p=new n("No Intersection");return p.appendPoints(f.points),p.appendPoints(l.points),p.appendPoints(c.points),p.appendPoints(h.points),p.points.length>0&&(p.status="Intersection"),p}}(typeof exports!="undefined"?exports:this),function(e){"use strict";function n(e){e?this._tryParsingColor(e):this.setSource([0,0,0,1])}var t=e.fabric||(e.fabric={});if(t.Color){t.warn("fabric.Color is already defined.");return}t.Color=n,t.Color.prototype={_tryParsingColor:function(e){var t;e in n.colorNameMap&&(e=n.colorNameMap[e]),t=n.sourceFromHex(e),t||(t=n.sourceFromRgb(e)),t&&this.setSource(t)},getSource:function(){return this._source},setSource:function(e){this._source=e},toRgb:function(){var e=this.getSource();return"rgb("+e[0]+","+e[1]+","+e[2]+")"},toRgba:function(){var e=this.getSource();return"rgba("+e[0]+","+e[1]+","+e[2]+","+e[3]+")"},toHex:function(){var e=this.getSource(),t=e[0].toString(16);t=t.length===1?"0"+t:t;var n=e[1].toString(16);n=n.length===1?"0"+n:n;var r=e[2].toString(16);return r=r.length===1?"0"+r:r,t.toUpperCase()+n.toUpperCase()+r.toUpperCase()},getAlpha:function(){return this.getSource()[3]},setAlpha:function(e){var t=this.getSource();return t[3]=e,this.setSource(t),this},toGrayscale:function(){var e=this.getSource(),t=parseInt((e[0]*.3+e[1]*.59+e[2]*.11).toFixed(0),10),n=e[3];return this.setSource([t,t,t,n]),this},toBlackWhite:function(e){var t=this.getSource(),n=(t[0]*.3+t[1]*.59+t[2]*.11).toFixed(0),r=t[3];return e=e||127,n=Number(n)