removed john resig's Class class because it was really slowing down node instantiations. Created a custom solution that's much lighter weight, and about 50% faster

This commit is contained in:
Eric Rowell 2012-08-22 23:35:21 -07:00
parent 45cf237ce0
commit 1ad2530889
18 changed files with 2279 additions and 126 deletions

View File

@ -4,9 +4,9 @@ class Build < Thor
# This is the list of files to concatenate. The first file will appear at the top of the final file. All files are relative to the lib directory.
FILES = [
"license.js", "src/Global.js", "src/Transition.js", "src/filters/Grayscale.js",
"src/util/Type.js", "src/util/Canvas.js", "src/util/Class.js", "src/util/Tween.js", "src/util/Transform.js",
"src/util/Type.js", "src/util/Canvas.js", "src/util/Tween.js", "src/util/Transform.js",
"src/Animation.js", "src/Node.js", "src/Container.js", "src/Stage.js", "src/Layer.js", "src/Group.js", "src/Shape.js",
"src/shapes/Rect.js" #, "src/shapes/Ellipse.js", "src/shapes/Image.js", "src/shapes/Polygon.js", "src/shapes/Text.js", "src/shapes/Line.js", "src/shapes/Sprite.js", "src/shapes/Star.js", "src/shapes/RegularPolygon.js", "src/shapes/Path.js", "src/shapes/TextPath.js"
"src/shapes/Rect.js", "src/shapes/Ellipse.js", "src/shapes/Image.js", "src/shapes/Polygon.js", "src/shapes/Text.js", "src/shapes/Line.js", "src/shapes/Sprite.js", "src/shapes/Star.js", "src/shapes/RegularPolygon.js", "src/shapes/Path.js", "src/shapes/TextPath.js"
]
desc "dev", "Concatenate all the js files into /dist/kinetic-VERSION.js."

2246
dist/kinetic-core.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -31,11 +31,11 @@
* @param {Number} [config.dragBounds.left]
*/
Kinetic.Group = function(config) {
this._groupInit(config);
this._initGroup(config);
};
Kinetic.Group.prototype = {
_groupInit: function(config) {
_initGroup: function(config) {
this.nodeType = 'Group';
// call super constructor

View File

@ -34,11 +34,11 @@
* @param {Number} [config.dragBounds.left]
*/
Kinetic.Layer = function(config) {
this._layerInit(config);
this._initLayer(config);
};
Kinetic.Layer.prototype = {
_layerInit: function(config) {
_initLayer: function(config) {
this.setDefaultAttrs({
clearBeforeDraw: true
});

View File

@ -60,11 +60,11 @@
* @param {Number} [config.dragBounds.left]
*/
Kinetic.Shape = function(config) {
this._shapeInit(config);
this._initShape(config);
};
Kinetic.Shape.prototype = {
_shapeInit: function(config) {
_initShape: function(config) {
this.nodeType = 'Shape';
this.appliedShadow = false;

View File

@ -34,11 +34,11 @@
* @param {Number} [config.dragBounds.left]
*/
Kinetic.Stage = function(config) {
this._stageInit(config);
this._initStage(config);
};
Kinetic.Stage.prototype = {
_stageInit: function(config) {
_initStage: function(config) {
this.setDefaultAttrs({
width: 400,
height: 200

View File

@ -7,8 +7,12 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.Ellipse = Kinetic.Shape.extend({
init: function(config) {
Kinetic.Ellipse = function(config) {
this._initEllipse(config);
};
Kinetic.Ellipse.prototype = {
_initEllipse: function(config) {
this.setDefaultAttrs({
radius: {
x: 0,
@ -20,7 +24,7 @@ Kinetic.Ellipse = Kinetic.Shape.extend({
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
this._convertRadius();
var that = this;
this.on('radiusChange.kinetic', function() {
@ -57,7 +61,8 @@ Kinetic.Ellipse = Kinetic.Shape.extend({
*/
this.attrs.radius = type._getXY(radius);
}
});
};
Kinetic.Global.extend(Kinetic.Ellipse, Kinetic.Shape);
// Circle backwards compatibility
Kinetic.Circle = Kinetic.Ellipse;

View File

@ -11,12 +11,16 @@
* @param {Number} [config.height]
* @param {Object} [config.crop]
*/
Kinetic.Image = Kinetic.Shape.extend({
init: function(config) {
Kinetic.Image = function(config) {
this._initImage(config);
};
Kinetic.Image.prototype = {
_initImage: function(config) {
this.shapeType = "Image";
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
var that = this;
this.on('imageChange', function(evt) {
@ -157,7 +161,8 @@ Kinetic.Image = Kinetic.Shape.extend({
}
}
}
});
};
Kinetic.Global.extend(Kinetic.Image, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Image, ['image', 'crop', 'filter', 'width', 'height']);

View File

@ -7,8 +7,12 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.Line = Kinetic.Shape.extend({
init: function(config) {
Kinetic.Line = function(config) {
this._initLine(config);
};
Kinetic.Line.prototype = {
_initLine: function(config) {
this.setDefaultAttrs({
points: [],
lineCap: 'butt',
@ -19,7 +23,7 @@ Kinetic.Line = Kinetic.Shape.extend({
this.shapeType = "Line";
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
},
drawFunc: function(context) {
var lastPos = {};
@ -94,7 +98,8 @@ Kinetic.Line = Kinetic.Shape.extend({
context.moveTo(x2, y2);
}
});
};
Kinetic.Global.extend(Kinetic.Line, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Line, ['dashArray', 'lineCap', 'points']);

View File

@ -8,15 +8,19 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.Path = Kinetic.Shape.extend({
init: function(config) {
Kinetic.Path = function(config) {
this._initPath(config);
};
Kinetic.Path.prototype = {
_initPath: function(config) {
this.shapeType = "Path";
this.dataArray = [];
var that = this;
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
this.dataArray = Kinetic.Path.parsePathData(this.attrs.data);
this.on('dataChange', function() {
that.dataArray = Kinetic.Path.parsePathData(that.attrs.data);
@ -66,7 +70,8 @@ Kinetic.Path = Kinetic.Shape.extend({
this.fill(context);
this.stroke(context);
}
});
};
Kinetic.Global.extend(Kinetic.Path, Kinetic.Shape);
/*
* Utility methods written by jfollas to

View File

@ -7,8 +7,12 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.Polygon = Kinetic.Shape.extend({
init: function(config) {
Kinetic.Polygon = function(config) {
this._initPolygon(config);
};
Kinetic.Polygon.prototype = {
_initPolygon: function(config) {
this.setDefaultAttrs({
points: []
});
@ -16,7 +20,7 @@ Kinetic.Polygon = Kinetic.Shape.extend({
this.shapeType = "Polygon";
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
},
drawFunc: function(context) {
context.beginPath();
@ -28,7 +32,8 @@ Kinetic.Polygon = Kinetic.Shape.extend({
this.fill(context);
this.stroke(context);
}
});
};
Kinetic.Global.extend(Kinetic.Polygon, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Polygon, ['points']);

View File

@ -8,10 +8,10 @@
* @param {Object} config
*/
Kinetic.Rect = function(config) {
this._rectInit(config);
this._initRect(config);
}
Kinetic.Rect.prototype = {
_rectInit: function(config) {
_initRect: function(config) {
this.setDefaultAttrs({
width: 0,
height: 0,

View File

@ -7,8 +7,12 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.RegularPolygon = Kinetic.Shape.extend({
init: function(config) {
Kinetic.RegularPolygon = function(config) {
this._initRegularPolygon(config);
};
Kinetic.RegularPolygon.prototype = {
_initRegularPolygon: function(config) {
this.setDefaultAttrs({
radius: 0,
sides: 0
@ -17,7 +21,7 @@ Kinetic.RegularPolygon = Kinetic.Shape.extend({
this.shapeType = "RegularPolygon";
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
},
drawFunc: function(context) {
context.beginPath();
@ -32,7 +36,8 @@ Kinetic.RegularPolygon = Kinetic.Shape.extend({
this.fill(context);
this.stroke(context);
}
});
};
Kinetic.Global.extend(Kinetic.RegularPolygon, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGettersSetters(Kinetic.RegularPolygon, ['radius', 'sides']);

View File

@ -7,8 +7,12 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.Sprite = Kinetic.Shape.extend({
init: function(config) {
Kinetic.Sprite = function(config) {
this._initSprite(config);
};
Kinetic.Sprite.prototype = {
_initSprite: function(config) {
this.setDefaultAttrs({
index: 0,
frameRate: 17
@ -16,7 +20,7 @@ Kinetic.Sprite = Kinetic.Shape.extend({
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
this.anim = new Kinetic.Animation();
var that = this;
this.on('animationChange.kinetic', function() {
@ -101,7 +105,8 @@ Kinetic.Sprite = Kinetic.Shape.extend({
this.attrs.index = 0;
}
}
});
};
Kinetic.Global.extend(Kinetic.Sprite, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Sprite, ['animation', 'animations', 'index']);

View File

@ -7,8 +7,12 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.Star = Kinetic.Shape.extend({
init: function(config) {
Kinetic.Star = function(config) {
this._initStar(config);
};
Kinetic.Star.prototype = {
_initStar: function(config) {
this.setDefaultAttrs({
numPoints: 0,
innerRadius: 0,
@ -18,7 +22,7 @@ Kinetic.Star = Kinetic.Shape.extend({
this.shapeType = "Star";
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
},
drawFunc: function(context) {
context.beginPath();
@ -35,7 +39,8 @@ Kinetic.Star = Kinetic.Shape.extend({
this.fill(context);
this.stroke(context);
}
});
};
Kinetic.Global.extend(Kinetic.Star, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']);

View File

@ -7,8 +7,12 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.Text = Kinetic.Shape.extend({
init: function(config) {
Kinetic.Text = function(config) {
this._initText(config);
};
Kinetic.Text.prototype = {
_initText: function(config) {
this.setDefaultAttrs({
fontFamily: 'Calibri',
text: '',
@ -29,7 +33,7 @@ Kinetic.Text = Kinetic.Shape.extend({
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
// update text data for certain attr changes
var attrs = ['fontFamily', 'fontSize', 'fontStyle', 'padding', 'align', 'lineHeight', 'text', 'width', 'height'];
@ -212,7 +216,9 @@ Kinetic.Text = Kinetic.Shape.extend({
}
this.textArr = arr;
}
});
};
Kinetic.Global.extend(Kinetic.Text, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGettersSetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'padding', 'align', 'lineHeight', 'text', 'width', 'height', 'cornerRadius', 'fill', 'stroke', 'strokeWidth', 'shadow']);

View File

@ -8,8 +8,12 @@
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.TextPath = Kinetic.Shape.extend({
init: function(config) {
Kinetic.TextPath = function(config) {
this._initTextPath(config);
};
Kinetic.TextPath.prototype = {
_initTextPath: function(config) {
this.setDefaultAttrs({
fontFamily: 'Calibri',
fontSize: 12,
@ -25,7 +29,7 @@ Kinetic.TextPath = Kinetic.Shape.extend({
config.drawFunc = this.drawFunc;
// call super constructor
this._super(config);
Kinetic.Shape.call(this, config);
this.dataArray = Kinetic.Path.parsePathData(this.attrs.data);
this.on('dataChange', function() {
that.dataArray = Kinetic.Path.parsePathData(this.attrs.data);
@ -279,7 +283,8 @@ Kinetic.TextPath = Kinetic.Shape.extend({
p0 = p1;
}
}
});
};
Kinetic.Global.extend(Kinetic.TextPath, Kinetic.Shape);
// add setters and getters
Kinetic.Node.addGettersSetters(Kinetic.TextPath, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'text']);