Build distribution

This commit is contained in:
kangax 2014-09-29 13:37:49 +02:00
parent 7f3f43c94b
commit 9ab511d037
4 changed files with 171 additions and 77 deletions

117
dist/fabric.js vendored
View file

@ -2880,7 +2880,7 @@ if (typeof console !== 'undefined') {
}
else if (attr === 'strokeDashArray') {
value = value.replace(/,/g, ' ').split(/\s+/).map(function(n) {
return parseInt(n);
return parseFloat(n);
});
}
else if (attr === 'transformMatrix') {
@ -3636,11 +3636,13 @@ if (typeof console !== 'undefined') {
// very crude parsing of style contents
for (var i = 0, len = styles.length; i < len; i++) {
var styleContents = styles[0].textContent;
var styleContents = styles[i].textContent;
// remove comments
styleContents = styleContents.replace(/\/\*[\s\S]*?\*\//g, '');
if (styleContents.trim() === '') {
continue;
}
rules = styleContents.match(/[^{]*\{[\s\S]*?\}/g);
rules = rules.map(function(rule) { return rule.trim(); });
@ -5714,6 +5716,13 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
*/
imageSmoothingEnabled: true,
/**
* Indicates whether objects should remain in current stack position when selected. When false objects are brought to top and rendered as part of the selection group
* @type Boolean
* @default
*/
preserveObjectStacking: false,
/**
* The transformation (in the format of Canvas transform) which focuses the viewport
* @type Array
@ -6283,13 +6292,22 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
ctx.save();
var v = this.viewportTransform;
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
object.render(ctx);
if (this._shouldRenderObject(object)) {
object.render(ctx);
}
ctx.restore();
if (!this.controlsAboveOverlay) {
object._renderControls(ctx);
}
},
_shouldRenderObject: function(object) {
if (!object) {
return false;
}
return (object !== this.getActiveGroup() || !this.preserveObjectStacking);
},
/**
* @private
* @param {fabric.Object} obj Object that was added
@ -6411,7 +6429,7 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
var i, length;
// fast path
if (!activeGroup) {
if (!activeGroup || this.preserveObjectStacking) {
for (i = 0, length = this._objects.length; i < length; ++i) {
this._draw(ctx, this._objects[i]);
}
@ -11366,16 +11384,16 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
//setup fill rule for current object
this._setupCompositeOperation(ctx);
this._transform(ctx, noTransform);
if (!noTransform) {
this.transform(ctx);
}
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
if (this.group && this.group.type === 'path-group') {
ctx.translate(-this.group.width/2, -this.group.height/2);
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
}
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
this._setOpacity(ctx);
this._setShadow(ctx);
@ -11388,17 +11406,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
ctx.restore();
},
_transform: function(ctx, noTransform) {
var m = this.transformMatrix;
if (m && !this.group) {
ctx.setTransform.apply(ctx, m);
}
if (!noTransform) {
this.transform(ctx);
}
},
/* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
@ -11532,7 +11539,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
if (1 & this.strokeDashArray.length) {
this.strokeDashArray.push.apply(this.strokeDashArray, this.strokeDashArray);
}
if (supportsLineDash) {
ctx.setLineDash(this.strokeDashArray);
this._stroke && this._stroke(ctx);
@ -14362,9 +14368,46 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
this.set('rx', options.rx || 0);
this.set('ry', options.ry || 0);
},
this.set('width', this.get('rx') * 2);
this.set('height', this.get('ry') * 2);
/**
* @private
* @param {String} key
* @param {Any} value
* @return {fabric.Ellipse} thisArg
*/
_set: function(key, value) {
this.callSuper('_set', key, value);
switch (key) {
case 'rx':
this.rx = value;
this.set('width', value * 2);
break;
case 'ry':
this.ry = value;
this.set('height', value * 2);
break;
}
return this;
},
/**
* Returns horizontal radius of an object (according to how an object is scaled)
* @return {Number}
*/
getRx: function() {
return this.get('rx') * this.get('scaleX');
},
/**
* Returns Vertical radius of an object (according to how an object is scaled)
* @return {Number}
*/
getRY: function() {
return this.get('ry') * this.get('scaleY');
},
/**
@ -15575,29 +15618,32 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
*/
render: function(ctx, noTransform) {
// do not render if width/height are zeros or object is not visible
if (this.width === 0 || this.height === 0 || !this.visible) {
if (!this.visible) {
return;
}
ctx.save();
this._setupCompositeOperation(ctx);
if (!noTransform) {
this.transform(ctx);
}
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
if (this.group && this.group.type === 'path-group') {
ctx.translate(-this.group.width/2, -this.group.height/2);
ctx.translate(-this.group.width / 2, -this.group.height / 2);
}
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
this._setOpacity(ctx);
this._setShadow(ctx);
this.clipTo && fabric.util.clipContext(this, ctx);
ctx.globalAlpha = this.group ? (ctx.globalAlpha * this.opacity) : this.opacity;
this._render(ctx, noTransform);
this.clipTo && ctx.restore();
this._removeShadow(ctx);
this._restoreCompositeOperation(ctx);
ctx.restore();
},
@ -19629,16 +19675,17 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
}
ctx.save();
this._transform(ctx, noTransform);
if (!noTransform) {
this.transform(ctx);
}
var m = this.transformMatrix,
isInPathGroup = this.group && this.group.type === 'path-group';
var isInPathGroup = this.group && this.group.type === 'path-group';
if (isInPathGroup) {
ctx.translate(-this.group.width/2, -this.group.height/2);
}
if (m) {
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
if (isInPathGroup) {
ctx.translate(this.left, this.top);

14
dist/fabric.min.js vendored

File diff suppressed because one or more lines are too long

BIN
dist/fabric.min.js.gz vendored

Binary file not shown.

117
dist/fabric.require.js vendored
View file

@ -2880,7 +2880,7 @@ if (typeof console !== 'undefined') {
}
else if (attr === 'strokeDashArray') {
value = value.replace(/,/g, ' ').split(/\s+/).map(function(n) {
return parseInt(n);
return parseFloat(n);
});
}
else if (attr === 'transformMatrix') {
@ -3636,11 +3636,13 @@ if (typeof console !== 'undefined') {
// very crude parsing of style contents
for (var i = 0, len = styles.length; i < len; i++) {
var styleContents = styles[0].textContent;
var styleContents = styles[i].textContent;
// remove comments
styleContents = styleContents.replace(/\/\*[\s\S]*?\*\//g, '');
if (styleContents.trim() === '') {
continue;
}
rules = styleContents.match(/[^{]*\{[\s\S]*?\}/g);
rules = rules.map(function(rule) { return rule.trim(); });
@ -5714,6 +5716,13 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
*/
imageSmoothingEnabled: true,
/**
* Indicates whether objects should remain in current stack position when selected. When false objects are brought to top and rendered as part of the selection group
* @type Boolean
* @default
*/
preserveObjectStacking: false,
/**
* The transformation (in the format of Canvas transform) which focuses the viewport
* @type Array
@ -6283,13 +6292,22 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
ctx.save();
var v = this.viewportTransform;
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
object.render(ctx);
if (this._shouldRenderObject(object)) {
object.render(ctx);
}
ctx.restore();
if (!this.controlsAboveOverlay) {
object._renderControls(ctx);
}
},
_shouldRenderObject: function(object) {
if (!object) {
return false;
}
return (object !== this.getActiveGroup() || !this.preserveObjectStacking);
},
/**
* @private
* @param {fabric.Object} obj Object that was added
@ -6411,7 +6429,7 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
var i, length;
// fast path
if (!activeGroup) {
if (!activeGroup || this.preserveObjectStacking) {
for (i = 0, length = this._objects.length; i < length; ++i) {
this._draw(ctx, this._objects[i]);
}
@ -11366,16 +11384,16 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
//setup fill rule for current object
this._setupCompositeOperation(ctx);
this._transform(ctx, noTransform);
if (!noTransform) {
this.transform(ctx);
}
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
if (this.group && this.group.type === 'path-group') {
ctx.translate(-this.group.width/2, -this.group.height/2);
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
}
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
this._setOpacity(ctx);
this._setShadow(ctx);
@ -11388,17 +11406,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
ctx.restore();
},
_transform: function(ctx, noTransform) {
var m = this.transformMatrix;
if (m && !this.group) {
ctx.setTransform.apply(ctx, m);
}
if (!noTransform) {
this.transform(ctx);
}
},
/* @private
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
@ -11532,7 +11539,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
if (1 & this.strokeDashArray.length) {
this.strokeDashArray.push.apply(this.strokeDashArray, this.strokeDashArray);
}
if (supportsLineDash) {
ctx.setLineDash(this.strokeDashArray);
this._stroke && this._stroke(ctx);
@ -14362,9 +14368,46 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
this.set('rx', options.rx || 0);
this.set('ry', options.ry || 0);
},
this.set('width', this.get('rx') * 2);
this.set('height', this.get('ry') * 2);
/**
* @private
* @param {String} key
* @param {Any} value
* @return {fabric.Ellipse} thisArg
*/
_set: function(key, value) {
this.callSuper('_set', key, value);
switch (key) {
case 'rx':
this.rx = value;
this.set('width', value * 2);
break;
case 'ry':
this.ry = value;
this.set('height', value * 2);
break;
}
return this;
},
/**
* Returns horizontal radius of an object (according to how an object is scaled)
* @return {Number}
*/
getRx: function() {
return this.get('rx') * this.get('scaleX');
},
/**
* Returns Vertical radius of an object (according to how an object is scaled)
* @return {Number}
*/
getRY: function() {
return this.get('ry') * this.get('scaleY');
},
/**
@ -15575,29 +15618,32 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
*/
render: function(ctx, noTransform) {
// do not render if width/height are zeros or object is not visible
if (this.width === 0 || this.height === 0 || !this.visible) {
if (!this.visible) {
return;
}
ctx.save();
this._setupCompositeOperation(ctx);
if (!noTransform) {
this.transform(ctx);
}
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
if (this.group && this.group.type === 'path-group') {
ctx.translate(-this.group.width/2, -this.group.height/2);
ctx.translate(-this.group.width / 2, -this.group.height / 2);
}
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
this._setStrokeStyles(ctx);
this._setFillStyles(ctx);
this._setOpacity(ctx);
this._setShadow(ctx);
this.clipTo && fabric.util.clipContext(this, ctx);
ctx.globalAlpha = this.group ? (ctx.globalAlpha * this.opacity) : this.opacity;
this._render(ctx, noTransform);
this.clipTo && ctx.restore();
this._removeShadow(ctx);
this._restoreCompositeOperation(ctx);
ctx.restore();
},
@ -19629,16 +19675,17 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
}
ctx.save();
this._transform(ctx, noTransform);
if (!noTransform) {
this.transform(ctx);
}
var m = this.transformMatrix,
isInPathGroup = this.group && this.group.type === 'path-group';
var isInPathGroup = this.group && this.group.type === 'path-group';
if (isInPathGroup) {
ctx.translate(-this.group.width/2, -this.group.height/2);
}
if (m) {
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
if (this.transformMatrix) {
ctx.transform.apply(ctx, this.transformMatrix);
}
if (isInPathGroup) {
ctx.translate(this.left, this.top);