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. # 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 = [ FILES = [
"license.js", "src/Global.js", "src/Transition.js", "src/filters/Grayscale.js", "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/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." 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] * @param {Number} [config.dragBounds.left]
*/ */
Kinetic.Group = function(config) { Kinetic.Group = function(config) {
this._groupInit(config); this._initGroup(config);
}; };
Kinetic.Group.prototype = { Kinetic.Group.prototype = {
_groupInit: function(config) { _initGroup: function(config) {
this.nodeType = 'Group'; this.nodeType = 'Group';
// call super constructor // call super constructor

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,8 +7,12 @@
* @augments Kinetic.Shape * @augments Kinetic.Shape
* @param {Object} config * @param {Object} config
*/ */
Kinetic.Text = Kinetic.Shape.extend({ Kinetic.Text = function(config) {
init: function(config) { this._initText(config);
};
Kinetic.Text.prototype = {
_initText: function(config) {
this.setDefaultAttrs({ this.setDefaultAttrs({
fontFamily: 'Calibri', fontFamily: 'Calibri',
text: '', text: '',
@ -29,7 +33,7 @@ Kinetic.Text = Kinetic.Shape.extend({
config.drawFunc = this.drawFunc; config.drawFunc = this.drawFunc;
// call super constructor // call super constructor
this._super(config); Kinetic.Shape.call(this, config);
// update text data for certain attr changes // update text data for certain attr changes
var attrs = ['fontFamily', 'fontSize', 'fontStyle', 'padding', 'align', 'lineHeight', 'text', 'width', 'height']; var attrs = ['fontFamily', 'fontSize', 'fontStyle', 'padding', 'align', 'lineHeight', 'text', 'width', 'height'];
@ -212,7 +216,9 @@ Kinetic.Text = Kinetic.Shape.extend({
} }
this.textArr = arr; this.textArr = arr;
} }
}); };
Kinetic.Global.extend(Kinetic.Text, Kinetic.Shape);
// add getters setters // 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']); 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 * @augments Kinetic.Shape
* @param {Object} config * @param {Object} config
*/ */
Kinetic.TextPath = Kinetic.Shape.extend({ Kinetic.TextPath = function(config) {
init: function(config) { this._initTextPath(config);
};
Kinetic.TextPath.prototype = {
_initTextPath: function(config) {
this.setDefaultAttrs({ this.setDefaultAttrs({
fontFamily: 'Calibri', fontFamily: 'Calibri',
fontSize: 12, fontSize: 12,
@ -25,7 +29,7 @@ Kinetic.TextPath = Kinetic.Shape.extend({
config.drawFunc = this.drawFunc; config.drawFunc = this.drawFunc;
// call super constructor // call super constructor
this._super(config); Kinetic.Shape.call(this, config);
this.dataArray = Kinetic.Path.parsePathData(this.attrs.data); this.dataArray = Kinetic.Path.parsePathData(this.attrs.data);
this.on('dataChange', function() { this.on('dataChange', function() {
that.dataArray = Kinetic.Path.parsePathData(this.attrs.data); that.dataArray = Kinetic.Path.parsePathData(this.attrs.data);
@ -279,7 +283,8 @@ Kinetic.TextPath = Kinetic.Shape.extend({
p0 = p1; p0 = p1;
} }
} }
}); };
Kinetic.Global.extend(Kinetic.TextPath, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.Node.addGettersSetters(Kinetic.TextPath, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'text']); Kinetic.Node.addGettersSetters(Kinetic.TextPath, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'text']);