mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 13:27:33 +08:00
migrate to eslint
This commit is contained in:
parent
3dff461592
commit
2908fa975b
26
.eslintrc
Normal file
26
.eslintrc
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"ecmaFeatures": {
|
||||
"blockBindings": true,
|
||||
"forOf": true,
|
||||
"jsx": true
|
||||
},
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
"semi": 2,
|
||||
"quotes": "single",
|
||||
"no-underscore-dangle": false,
|
||||
"valid-jsdoc": true,
|
||||
"no-constant-condition": false,
|
||||
"strict": "never",
|
||||
"camelcase": false,
|
||||
"space-infix-ops": false,
|
||||
"new-cap": false
|
||||
},
|
||||
"globals": {
|
||||
"Konva" : false,
|
||||
"define": false
|
||||
}
|
||||
}
|
29
.jshintrc
29
.jshintrc
@ -1,29 +0,0 @@
|
||||
{
|
||||
"esnext" : true,
|
||||
"curly": true,
|
||||
"immed": true,
|
||||
"latedef": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"sub": true,
|
||||
"undef": true,
|
||||
"boss": true,
|
||||
"eqnull": true,
|
||||
"node": true,
|
||||
"latedef": true,
|
||||
"quotmark": "single",
|
||||
"unused": true,
|
||||
"trailing" : true,
|
||||
"laxbreak" : true,
|
||||
"globals": {
|
||||
"document": false,
|
||||
"window" : false,
|
||||
"Konva" : false,
|
||||
"navigator" : false,
|
||||
"define" : false,
|
||||
"Image" : false,
|
||||
"assert" : false,
|
||||
"test": false,
|
||||
"addStage" : false
|
||||
}
|
||||
}
|
24
gulpfile.js
24
gulpfile.js
@ -1,12 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var gulp = require('gulp');
|
||||
var rename = require('gulp-rename');
|
||||
var uglify = require('gulp-uglify');
|
||||
var concat = require('gulp-concat');
|
||||
var replace = require('gulp-replace');
|
||||
var jshint = require('gulp-jshint');
|
||||
var mochaPhantomJS = require('gulp-mocha-phantomjs');
|
||||
var jsdoc = require('gulp-jsdoc');
|
||||
var connect = require('gulp-connect');
|
||||
var jscpd = require('gulp-jscpd');
|
||||
var eslint = require('gulp-eslint');
|
||||
|
||||
var fs = require('fs');
|
||||
var NodeParams = fs.readFileSync('./resources/doc-includes/NodeParams.txt').toString();
|
||||
@ -115,8 +118,23 @@ gulp.task('server', function() {
|
||||
|
||||
gulp.task('lint', function() {
|
||||
return gulp.src('./src/**/*.js')
|
||||
.pipe(jshint())
|
||||
.pipe(jshint.reporter('default'));
|
||||
.pipe(eslint({
|
||||
configFile: './.eslintrc'
|
||||
}))
|
||||
// eslint.format() outputs the lint results to the console.
|
||||
// Alternatively use eslint.formatEach() (see Docs).
|
||||
.pipe(eslint.format())
|
||||
// To have the process exit with an error code (1) on
|
||||
// lint error, return the stream and pipe to failOnError last.
|
||||
.pipe(eslint.failOnError());
|
||||
});
|
||||
|
||||
gulp.task('inspect', function() {
|
||||
return gulp.src('./src/**/*.js')
|
||||
.pipe(jscpd({
|
||||
'min-lines': 10,
|
||||
verbose: true
|
||||
}));
|
||||
});
|
||||
|
||||
gulp.task('api', function() {
|
||||
|
@ -7,8 +7,9 @@
|
||||
"gulp": "^3.8.10",
|
||||
"gulp-concat": "^2.5.2",
|
||||
"gulp-connect": "^2.2.0",
|
||||
"gulp-eslint": "^0.11.1",
|
||||
"gulp-jscpd": "0.0.3",
|
||||
"gulp-jsdoc": "^0.1.4",
|
||||
"gulp-jshint": "^1.10.0",
|
||||
"gulp-mocha-phantomjs": "^0.6.1",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-replace": "^0.5.3",
|
||||
|
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
(function(Konva) {
|
||||
'use strict';
|
||||
var BATCH_DRAW_STOP_TIME_DIFF = 500;
|
||||
|
||||
var now = (function() {
|
||||
@ -14,6 +15,10 @@
|
||||
}
|
||||
})();
|
||||
|
||||
function FRAF(callback) {
|
||||
setTimeout(callback, 1000 / 60);
|
||||
}
|
||||
|
||||
var RAF = (function(){
|
||||
return Konva.root.requestAnimationFrame
|
||||
|| Konva.root.webkitRequestAnimationFrame
|
||||
@ -23,9 +28,7 @@
|
||||
|| FRAF;
|
||||
})();
|
||||
|
||||
function FRAF(callback) {
|
||||
setTimeout(callback, 1000 / 60);
|
||||
}
|
||||
|
||||
|
||||
function requestAnimFrame() {
|
||||
return RAF.apply(Konva.root, arguments);
|
||||
@ -110,10 +113,7 @@
|
||||
*/
|
||||
addLayer: function(layer) {
|
||||
var layers = this.layers,
|
||||
len, n;
|
||||
|
||||
if (layers) {
|
||||
len = layers.length;
|
||||
len = layers.length, n;
|
||||
|
||||
// don't add the layer if it already exists
|
||||
for (n = 0; n < len; n++) {
|
||||
@ -121,10 +121,6 @@
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.layers = [];
|
||||
}
|
||||
|
||||
this.layers.push(layer);
|
||||
return true;
|
||||
@ -228,7 +224,9 @@
|
||||
} else {
|
||||
needRedraw = true;
|
||||
}
|
||||
if (needRedraw) {
|
||||
if (!needRedraw) {
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < layersLen; i++) {
|
||||
layer = layers[i];
|
||||
|
||||
@ -237,7 +235,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (key in layerHash) {
|
||||
layerHash[key].draw();
|
||||
@ -302,4 +299,4 @@
|
||||
layer.batchDraw();
|
||||
});
|
||||
};
|
||||
})(this);
|
||||
})(Konva);
|
||||
|
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
/**
|
||||
* BaseLayer constructor.
|
||||
* @constructor
|
||||
@ -100,19 +101,21 @@
|
||||
},
|
||||
// extend Node.prototype.moveUp
|
||||
moveUp: function() {
|
||||
if(Konva.Node.prototype.moveUp.call(this)) {
|
||||
var moved = Konva.Node.prototype.moveUp.call(this);
|
||||
if (!moved){
|
||||
return;
|
||||
}
|
||||
var stage = this.getStage();
|
||||
if(stage) {
|
||||
if(!stage) {
|
||||
return;
|
||||
}
|
||||
stage.content.removeChild(this.getCanvas()._canvas);
|
||||
|
||||
if(this.index < stage.getChildren().length - 1) {
|
||||
stage.content.insertBefore(this.getCanvas()._canvas, stage.getChildren()[this.index + 1].getCanvas()._canvas);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
stage.content.appendChild(this.getCanvas()._canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
// extend Node.prototype.moveDown
|
||||
moveDown: function() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
// calculate pixel ratio
|
||||
var canvas = Konva.Util.createCanvasElement(),
|
||||
context = canvas.getContext('2d'),
|
||||
|
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
/**
|
||||
* Container constructor. Containers are used to contain nodes or other containers
|
||||
* @constructor
|
||||
@ -413,16 +414,16 @@
|
||||
|
||||
});
|
||||
|
||||
var rect = {
|
||||
var selfRect = {
|
||||
x: minX,
|
||||
y: minY,
|
||||
width: maxX - minX,
|
||||
height: maxY - minY
|
||||
};
|
||||
if (!skipTransform) {
|
||||
return this._transformedRect(rect);
|
||||
return this._transformedRect(selfRect);
|
||||
}
|
||||
return rect;
|
||||
return selfRect;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
var COMMA = ',',
|
||||
OPEN_PAREN = '(',
|
||||
CLOSE_PAREN = ')',
|
||||
@ -435,7 +436,7 @@
|
||||
return this._context[prop];
|
||||
},
|
||||
set: function (val) {
|
||||
return this._context[prop] = val;
|
||||
this._context[prop] = val;
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -458,13 +459,11 @@
|
||||
shape._fillFunc(this);
|
||||
},
|
||||
_fillPattern: function(shape) {
|
||||
var fillPatternImage = shape.getFillPatternImage(),
|
||||
fillPatternX = shape.getFillPatternX(),
|
||||
var fillPatternX = shape.getFillPatternX(),
|
||||
fillPatternY = shape.getFillPatternY(),
|
||||
fillPatternScale = shape.getFillPatternScale(),
|
||||
fillPatternRotation = Konva.getAngle(shape.getFillPatternRotation()),
|
||||
fillPatternOffset = shape.getFillPatternOffset(),
|
||||
fillPatternRepeat = shape.getFillPatternRepeat();
|
||||
fillPatternOffset = shape.getFillPatternOffset();
|
||||
|
||||
if(fillPatternX || fillPatternY) {
|
||||
this.translate(fillPatternX || 0, fillPatternY || 0);
|
||||
@ -479,7 +478,7 @@
|
||||
this.translate(-1 * fillPatternOffset.x, -1 * fillPatternOffset.y);
|
||||
}
|
||||
|
||||
this.setAttr('fillStyle', this.createPattern(fillPatternImage, fillPatternRepeat || 'repeat'));
|
||||
this.setAttr('fillStyle', this.createPattern(shape.getFillPatternImage(), shape.getFillPatternRepeat() || 'repeat'));
|
||||
this.fill();
|
||||
},
|
||||
_fillLinearGradient: function(shape) {
|
||||
@ -596,7 +595,6 @@
|
||||
this.setAttr('shadowBlur', blur);
|
||||
this.setAttr('shadowOffsetX', offset.x * scaleX);
|
||||
this.setAttr('shadowOffsetY', offset.y * scaleY);
|
||||
|
||||
}
|
||||
};
|
||||
Konva.Util.extend(Konva.SceneContext, Konva.Context);
|
||||
|
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
Konva.DD = {
|
||||
// properties
|
||||
anim: new Konva.Animation(function() {
|
||||
@ -53,10 +54,9 @@
|
||||
_endDragBefore: function(evt) {
|
||||
var dd = Konva.DD,
|
||||
node = dd.node,
|
||||
nodeType, layer;
|
||||
layer;
|
||||
|
||||
if(node) {
|
||||
nodeType = node.nodeType;
|
||||
layer = node.getLayer();
|
||||
dd.anim.stop();
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
/*jshint unused:false */
|
||||
(function() {
|
||||
'use strict';
|
||||
// CONSTANTS
|
||||
var GET = 'get',
|
||||
RGB = 'RGB',
|
||||
SET = 'set';
|
||||
|
||||
Konva.Factory = {
|
||||
|
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
/**
|
||||
* FastLayer constructor. Layers are tied to their own canvas element and are used
|
||||
* to contain shapes only. If you don't need node nesting, mouse and touch interactions,
|
||||
|
@ -33,6 +33,7 @@
|
||||
/*jshint -W079, -W020*/
|
||||
var Konva = {};
|
||||
(function(root) {
|
||||
'use strict';
|
||||
var PI_OVER_180 = Math.PI / 180;
|
||||
|
||||
Konva = {
|
||||
@ -153,9 +154,13 @@ var Konva = {};
|
||||
}
|
||||
},
|
||||
_removeName: function(name, _id) {
|
||||
if(name !== undefined) {
|
||||
if(!name) {
|
||||
return;
|
||||
}
|
||||
var nodes = this.names[name];
|
||||
if(nodes !== undefined) {
|
||||
if(!nodes) {
|
||||
return;
|
||||
}
|
||||
for(var n = 0; n < nodes.length; n++) {
|
||||
var no = nodes[n];
|
||||
if(no._id === _id) {
|
||||
@ -165,8 +170,6 @@ var Konva = {};
|
||||
if(nodes.length === 0) {
|
||||
delete this.names[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
getAngle: function(angle) {
|
||||
return this.angleDeg ? angle * PI_OVER_180 : angle;
|
||||
@ -220,6 +223,7 @@ var Konva = {};
|
||||
|
||||
// if the module has no dependencies, the above pattern can be simplified to
|
||||
( function(root, factory) {
|
||||
'use strict';
|
||||
if( typeof exports === 'object') {
|
||||
var KonvaJS = factory();
|
||||
// runtime-check for browserify and nw.js (node-webkit)
|
||||
@ -250,8 +254,8 @@ var Konva = {};
|
||||
Konva.document = document;
|
||||
Konva.window = window;
|
||||
Konva.root = root;
|
||||
|
||||
}(this, function() {
|
||||
'use strict';
|
||||
// Just return a value to define the module export.
|
||||
// This example returns an object, but the module
|
||||
// can return a function as the exported value.
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
/**
|
||||
* Group constructor. Groups are used to contain shapes or other groups.
|
||||
* @constructor
|
||||
|
12
src/Layer.js
12
src/Layer.js
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
// constants
|
||||
var HASH = '#',
|
||||
BEFORE_DRAW = 'beforeDraw',
|
||||
@ -75,7 +76,9 @@
|
||||
getIntersection: function(pos) {
|
||||
var obj, i, intersectionOffset, shape;
|
||||
|
||||
if(this.hitGraphEnabled() && this.isVisible()) {
|
||||
if(!this.hitGraphEnabled() || !this.isVisible()) {
|
||||
return null;
|
||||
}
|
||||
// in some cases antialiased area may be bigger than 1px
|
||||
// it is possible if we will cache node, then scale it a lot
|
||||
// TODO: check { 0; 0 } point before loop, and remove it from INTERSECTION_OFFSETS.
|
||||
@ -94,24 +97,19 @@
|
||||
}
|
||||
// we should continue search if we found antialiased pixel
|
||||
// that means our node somewhere very close
|
||||
else {
|
||||
continueSearch = !!obj.antialiased;
|
||||
// stop search if found empty pixel
|
||||
if (!obj.antialiased) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if no shape, and no antialiased pixel, we should end searching
|
||||
if (continueSearch) {
|
||||
spiralSearchDistance += 1;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
_getImageData: function(x, y) {
|
||||
var width = this.hitCanvas.width || 1,
|
||||
|
27
src/Node.js
27
src/Node.js
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
(function(Konva) {
|
||||
'use strict';
|
||||
// CONSTANTS
|
||||
var ABSOLUTE_OPACITY = 'absoluteOpacity',
|
||||
ABSOLUTE_TRANSFORM = 'absoluteTransform',
|
||||
@ -622,12 +623,13 @@
|
||||
setAttrs: function(config) {
|
||||
var key, method;
|
||||
|
||||
if(config) {
|
||||
if(!config) {
|
||||
return this;
|
||||
}
|
||||
for(key in config) {
|
||||
if (key === CHILDREN) {
|
||||
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
method = SET + Konva.Util._capitalize(key);
|
||||
// use setter if available
|
||||
if(Konva.Util._isFunction(this[method])) {
|
||||
@ -638,8 +640,6 @@
|
||||
this._setAttr(key, config[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
@ -998,7 +998,7 @@
|
||||
moveToTop: function() {
|
||||
if (!this.parent) {
|
||||
Konva.Util.warn('Node has no parent. moveToTop function is ignored.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
var index = this.index;
|
||||
this.parent.children.splice(index, 1);
|
||||
@ -1015,7 +1015,7 @@
|
||||
moveUp: function() {
|
||||
if (!this.parent) {
|
||||
Konva.Util.warn('Node has no parent. moveUp function is ignored.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
var index = this.index,
|
||||
len = this.parent.getChildren().length;
|
||||
@ -1036,7 +1036,7 @@
|
||||
moveDown: function() {
|
||||
if (!this.parent) {
|
||||
Konva.Util.warn('Node has no parent. moveDown function is ignored.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
var index = this.index;
|
||||
if(index > 0) {
|
||||
@ -1056,7 +1056,7 @@
|
||||
moveToBottom: function() {
|
||||
if (!this.parent) {
|
||||
Konva.Util.warn('Node has no parent. moveToBottom function is ignored.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
var index = this.index;
|
||||
if(index > 0) {
|
||||
@ -1077,7 +1077,7 @@
|
||||
setZIndex: function(zIndex) {
|
||||
if (!this.parent) {
|
||||
Konva.Util.warn('Node has no parent. zIndex parameter is ignored.');
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
var index = this.index;
|
||||
this.parent.children.splice(index, 1);
|
||||
@ -1450,9 +1450,6 @@
|
||||
width: this.getWidth(),
|
||||
height: this.getHeight()
|
||||
};
|
||||
},
|
||||
getTransformedSize : function() {
|
||||
|
||||
},
|
||||
getWidth: function() {
|
||||
return this.attrs.width || 0;
|
||||
@ -2216,4 +2213,4 @@
|
||||
});
|
||||
|
||||
Konva.Collection.mapMethods(Konva.Node);
|
||||
})();
|
||||
})(Konva);
|
||||
|
34
src/Shape.js
34
src/Shape.js
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
(function(Konva) {
|
||||
'use strict';
|
||||
var HAS_SHADOW = 'hasShadow';
|
||||
var SHADOW_RGBA = 'shadowRGBA';
|
||||
|
||||
@ -242,14 +243,19 @@
|
||||
hasStroke = this.hasStroke(),
|
||||
stage, bufferCanvas, bufferContext;
|
||||
|
||||
if(this.isVisible()) {
|
||||
if(!this.isVisible()) {
|
||||
return this;
|
||||
}
|
||||
if (cachedCanvas) {
|
||||
context.save();
|
||||
layer._applyTransform(this, context, top);
|
||||
this._drawCachedSceneCanvas(context);
|
||||
context.restore();
|
||||
return this;
|
||||
}
|
||||
if (!drawFunc) {
|
||||
return this;
|
||||
}
|
||||
else if (drawFunc) {
|
||||
context.save();
|
||||
// if buffer canvas is needed
|
||||
if (this._useBufferCanvas(caching)) {
|
||||
@ -327,9 +333,6 @@
|
||||
}
|
||||
}
|
||||
context.restore();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
drawHit: function(can, top, caching) {
|
||||
@ -340,7 +343,9 @@
|
||||
cachedCanvas = this._cache.canvas,
|
||||
cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
||||
|
||||
if(this.shouldDrawHit(canvas)) {
|
||||
if(!this.shouldDrawHit(canvas)) {
|
||||
return this;
|
||||
}
|
||||
if (layer) {
|
||||
layer.clearHitCache();
|
||||
}
|
||||
@ -349,8 +354,11 @@
|
||||
layer._applyTransform(this, context, top);
|
||||
this._drawCachedHitCanvas(context);
|
||||
context.restore();
|
||||
return this;
|
||||
}
|
||||
if (!drawFunc) {
|
||||
return this;
|
||||
}
|
||||
else if (drawFunc) {
|
||||
context.save();
|
||||
context._applyLineJoin(this);
|
||||
if (!caching) {
|
||||
@ -361,13 +369,8 @@
|
||||
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
||||
}
|
||||
}
|
||||
|
||||
drawFunc.call(this, context);
|
||||
context.restore();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
@ -689,7 +692,6 @@
|
||||
* @example
|
||||
* // apply dashed stroke that is 10px long and 5 pixels apart
|
||||
* line.dash([10, 5]);
|
||||
*
|
||||
* // apply dashed stroke that is made up of alternating dashed
|
||||
* // lines that are 10px long and 20px apart, and dots that have
|
||||
* // a radius of 5px and are 20px apart
|
||||
@ -1014,7 +1016,6 @@
|
||||
* @example
|
||||
* // get fill pattern x
|
||||
* var fillPatternX = shape.fillPatternX();
|
||||
*
|
||||
* // set fill pattern x
|
||||
* shape.fillPatternX(20);
|
||||
*/
|
||||
@ -1031,7 +1032,6 @@
|
||||
* @example
|
||||
* // get fill pattern y
|
||||
* var fillPatternY = shape.fillPatternY();
|
||||
*
|
||||
* // set fill pattern y
|
||||
* shape.fillPatternY(20);
|
||||
*/
|
||||
@ -1603,4 +1603,4 @@
|
||||
});
|
||||
|
||||
Konva.Collection.mapMethods(Konva.Shape);
|
||||
})();
|
||||
})(Konva);
|
||||
|
18
src/Stage.js
18
src/Stage.js
@ -1,5 +1,5 @@
|
||||
/*jshint unused:false */
|
||||
(function() {
|
||||
'use strict';
|
||||
// CONSTANTS
|
||||
var STAGE = 'Stage',
|
||||
STRING = 'string',
|
||||
@ -168,7 +168,6 @@
|
||||
obj = {};
|
||||
}
|
||||
obj.container = Konva.document.createElement(DIV);
|
||||
|
||||
return Konva.Container.prototype.clone.call(this, obj);
|
||||
},
|
||||
/**
|
||||
@ -330,7 +329,6 @@
|
||||
this.content.style.height = height + PX;
|
||||
|
||||
this.bufferCanvas.setSize(width, height);
|
||||
// this.bufferCanvas2.setSize(width, height);
|
||||
this.bufferHitCanvas.setSize(width, height);
|
||||
|
||||
// set layer dimensions
|
||||
@ -354,7 +352,7 @@
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
this.add(arguments[i]);
|
||||
}
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
Konva.Container.prototype.add.call(this, layer);
|
||||
layer._setCanvasSize(this.width(), this.height());
|
||||
@ -407,18 +405,16 @@
|
||||
}
|
||||
},
|
||||
_mousemove: function(evt) {
|
||||
|
||||
// workaround for mobile IE to force touch event when unhandled pointer event elevates into a mouse event
|
||||
if (Konva.UA.ieMobile) {
|
||||
return this._touchmove(evt);
|
||||
}
|
||||
|
||||
// workaround fake mousemove event in chrome browser https://code.google.com/p/chromium/issues/detail?id=161464
|
||||
if ((typeof evt.webkitMovementX !== 'undefined' || typeof evt.webkitMovementY !== 'undefined') && evt.webkitMovementY === 0 && evt.webkitMovementX === 0) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (Konva.UA.mobile) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
this._setPointerPosition(evt);
|
||||
var dd = Konva.DD, shape;
|
||||
@ -466,12 +462,10 @@
|
||||
}
|
||||
},
|
||||
_mousedown: function(evt) {
|
||||
|
||||
// workaround for mobile IE to force touch event when unhandled pointer event elevates into a mouse event
|
||||
if (Konva.UA.ieMobile) {
|
||||
return this._touchstart(evt);
|
||||
}
|
||||
|
||||
if (!Konva.UA.mobile) {
|
||||
this._setPointerPosition(evt);
|
||||
var shape = this.getIntersection(this.getPointerPosition());
|
||||
@ -731,9 +725,6 @@
|
||||
this.bufferCanvas = new Konva.SceneCanvas({
|
||||
pixelRatio: 1
|
||||
});
|
||||
// this.bufferCanvas2 = new Konva.SceneCanvas({
|
||||
// pixelRatio: 1
|
||||
// });
|
||||
this.bufferHitCanvas = new Konva.HitCanvas();
|
||||
|
||||
this._resizeDOM();
|
||||
@ -771,7 +762,6 @@
|
||||
* @example
|
||||
* // get container
|
||||
* var container = stage.container();
|
||||
*
|
||||
* // set container
|
||||
* var container = document.createElement('div');
|
||||
* body.appendChild(container);
|
||||
|
245
src/Tween.js
245
src/Tween.js
@ -1,4 +1,5 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
var blacklist = {
|
||||
node: 1,
|
||||
duration: 1,
|
||||
@ -14,6 +15,123 @@
|
||||
idCounter = 0,
|
||||
colorAttrs = ['fill', 'stroke', 'shadowColor'];
|
||||
|
||||
var Tween = function(prop, propFunc, func, begin, finish, duration, yoyo) {
|
||||
this.prop = prop;
|
||||
this.propFunc = propFunc;
|
||||
this.begin = begin;
|
||||
this._pos = begin;
|
||||
this.duration = duration;
|
||||
this._change = 0;
|
||||
this.prevPos = 0;
|
||||
this.yoyo = yoyo;
|
||||
this._time = 0;
|
||||
this._position = 0;
|
||||
this._startTime = 0;
|
||||
this._finish = 0;
|
||||
this.func = func;
|
||||
this._change = finish - this.begin;
|
||||
this.pause();
|
||||
};
|
||||
/*
|
||||
* Tween methods
|
||||
*/
|
||||
Tween.prototype = {
|
||||
fire: function(str) {
|
||||
var handler = this[str];
|
||||
if (handler) {
|
||||
handler();
|
||||
}
|
||||
},
|
||||
setTime: function(t) {
|
||||
if(t > this.duration) {
|
||||
if(this.yoyo) {
|
||||
this._time = this.duration;
|
||||
this.reverse();
|
||||
}
|
||||
else {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
else if(t < 0) {
|
||||
if(this.yoyo) {
|
||||
this._time = 0;
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._time = t;
|
||||
this.update();
|
||||
}
|
||||
},
|
||||
getTime: function() {
|
||||
return this._time;
|
||||
},
|
||||
setPosition: function(p) {
|
||||
this.prevPos = this._pos;
|
||||
this.propFunc(p);
|
||||
this._pos = p;
|
||||
},
|
||||
getPosition: function(t) {
|
||||
if(t === undefined) {
|
||||
t = this._time;
|
||||
}
|
||||
return this.func(t, this.begin, this._change, this.duration);
|
||||
},
|
||||
play: function() {
|
||||
this.state = PLAYING;
|
||||
this._startTime = this.getTimer() - this._time;
|
||||
this.onEnterFrame();
|
||||
this.fire('onPlay');
|
||||
},
|
||||
reverse: function() {
|
||||
this.state = REVERSING;
|
||||
this._time = this.duration - this._time;
|
||||
this._startTime = this.getTimer() - this._time;
|
||||
this.onEnterFrame();
|
||||
this.fire('onReverse');
|
||||
},
|
||||
seek: function(t) {
|
||||
this.pause();
|
||||
this._time = t;
|
||||
this.update();
|
||||
this.fire('onSeek');
|
||||
},
|
||||
reset: function() {
|
||||
this.pause();
|
||||
this._time = 0;
|
||||
this.update();
|
||||
this.fire('onReset');
|
||||
},
|
||||
finish: function() {
|
||||
this.pause();
|
||||
this._time = this.duration;
|
||||
this.update();
|
||||
this.fire('onFinish');
|
||||
},
|
||||
update: function() {
|
||||
this.setPosition(this.getPosition(this._time));
|
||||
},
|
||||
onEnterFrame: function() {
|
||||
var t = this.getTimer() - this._startTime;
|
||||
if(this.state === PLAYING) {
|
||||
this.setTime(t);
|
||||
}
|
||||
else if (this.state === REVERSING) {
|
||||
this.setTime(this.duration - t);
|
||||
}
|
||||
},
|
||||
pause: function() {
|
||||
this.state = PAUSED;
|
||||
this.fire('onPause');
|
||||
},
|
||||
getTimer: function() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Tween constructor. Tweens enable you to animate a node between the current state and a new state.
|
||||
* You can play, pause, reverse, seek, reset, and finish tweens. By default, tweens are animated using
|
||||
@ -181,7 +299,7 @@
|
||||
};
|
||||
this.tween.onFinish = function() {
|
||||
if (that.onFinish) {
|
||||
that.onFinish();
|
||||
that.onFinish.call(that);
|
||||
}
|
||||
};
|
||||
this.tween.onReset = function() {
|
||||
@ -289,7 +407,7 @@
|
||||
var onFinish = params.onFinish;
|
||||
params.node = this;
|
||||
params.onFinish = function() {
|
||||
tween.destroy();
|
||||
this.destroy();
|
||||
if (onFinish) {
|
||||
onFinish();
|
||||
}
|
||||
@ -298,123 +416,6 @@
|
||||
tween.play();
|
||||
};
|
||||
|
||||
var Tween = function(prop, propFunc, func, begin, finish, duration, yoyo) {
|
||||
this.prop = prop;
|
||||
this.propFunc = propFunc;
|
||||
this.begin = begin;
|
||||
this._pos = begin;
|
||||
this.duration = duration;
|
||||
this._change = 0;
|
||||
this.prevPos = 0;
|
||||
this.yoyo = yoyo;
|
||||
this._time = 0;
|
||||
this._position = 0;
|
||||
this._startTime = 0;
|
||||
this._finish = 0;
|
||||
this.func = func;
|
||||
this._change = finish - this.begin;
|
||||
this.pause();
|
||||
};
|
||||
/*
|
||||
* Tween methods
|
||||
*/
|
||||
Tween.prototype = {
|
||||
fire: function(str) {
|
||||
var handler = this[str];
|
||||
if (handler) {
|
||||
handler();
|
||||
}
|
||||
},
|
||||
setTime: function(t) {
|
||||
if(t > this.duration) {
|
||||
if(this.yoyo) {
|
||||
this._time = this.duration;
|
||||
this.reverse();
|
||||
}
|
||||
else {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
else if(t < 0) {
|
||||
if(this.yoyo) {
|
||||
this._time = 0;
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._time = t;
|
||||
this.update();
|
||||
}
|
||||
},
|
||||
getTime: function() {
|
||||
return this._time;
|
||||
},
|
||||
setPosition: function(p) {
|
||||
this.prevPos = this._pos;
|
||||
this.propFunc(p);
|
||||
this._pos = p;
|
||||
},
|
||||
getPosition: function(t) {
|
||||
if(t === undefined) {
|
||||
t = this._time;
|
||||
}
|
||||
return this.func(t, this.begin, this._change, this.duration);
|
||||
},
|
||||
play: function() {
|
||||
this.state = PLAYING;
|
||||
this._startTime = this.getTimer() - this._time;
|
||||
this.onEnterFrame();
|
||||
this.fire('onPlay');
|
||||
},
|
||||
reverse: function() {
|
||||
this.state = REVERSING;
|
||||
this._time = this.duration - this._time;
|
||||
this._startTime = this.getTimer() - this._time;
|
||||
this.onEnterFrame();
|
||||
this.fire('onReverse');
|
||||
},
|
||||
seek: function(t) {
|
||||
this.pause();
|
||||
this._time = t;
|
||||
this.update();
|
||||
this.fire('onSeek');
|
||||
},
|
||||
reset: function() {
|
||||
this.pause();
|
||||
this._time = 0;
|
||||
this.update();
|
||||
this.fire('onReset');
|
||||
},
|
||||
finish: function() {
|
||||
this.pause();
|
||||
this._time = this.duration;
|
||||
this.update();
|
||||
this.fire('onFinish');
|
||||
},
|
||||
update: function() {
|
||||
this.setPosition(this.getPosition(this._time));
|
||||
},
|
||||
onEnterFrame: function() {
|
||||
var t = this.getTimer() - this._startTime;
|
||||
if(this.state === PLAYING) {
|
||||
this.setTime(t);
|
||||
}
|
||||
else if (this.state === REVERSING) {
|
||||
this.setTime(this.duration - t);
|
||||
}
|
||||
},
|
||||
pause: function() {
|
||||
this.state = PAUSED;
|
||||
this.fire('onPause');
|
||||
},
|
||||
getTimer: function() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* These eases were ported from an Adobe Flash tweening library to JavaScript
|
||||
* by Xaric
|
||||
@ -466,7 +467,7 @@
|
||||
if(t === 0) {
|
||||
return b;
|
||||
}
|
||||
if((t /= d) == 1) {
|
||||
if((t /= d) === 1) {
|
||||
return b + c;
|
||||
}
|
||||
if(!p) {
|
||||
@ -492,7 +493,7 @@
|
||||
if(t === 0) {
|
||||
return b;
|
||||
}
|
||||
if((t /= d) == 1) {
|
||||
if((t /= d) === 1) {
|
||||
return b + c;
|
||||
}
|
||||
if(!p) {
|
||||
@ -518,7 +519,7 @@
|
||||
if(t === 0) {
|
||||
return b;
|
||||
}
|
||||
if((t /= d / 2) == 2) {
|
||||
if((t /= d / 2) === 2) {
|
||||
return b + c;
|
||||
}
|
||||
if(!p) {
|
||||
|
20
src/Util.js
20
src/Util.js
@ -1,4 +1,6 @@
|
||||
/*eslint-disable eqeqeq, no-cond-assign, no-empty*/
|
||||
(function() {
|
||||
'use strict';
|
||||
/**
|
||||
* Collection constructor. Collection extends
|
||||
* Array. This class is used in conjunction with {@link Konva.Container#get}
|
||||
@ -473,16 +475,16 @@
|
||||
return !!(obj && obj.constructor && obj.call && obj.apply);
|
||||
},
|
||||
_isObject: function(obj) {
|
||||
return (!!obj && obj.constructor == Object);
|
||||
return (!!obj && obj.constructor === Object);
|
||||
},
|
||||
_isArray: function(obj) {
|
||||
return Object.prototype.toString.call(obj) == OBJECT_ARRAY;
|
||||
return Object.prototype.toString.call(obj) === OBJECT_ARRAY;
|
||||
},
|
||||
_isNumber: function(obj) {
|
||||
return Object.prototype.toString.call(obj) == OBJECT_NUMBER;
|
||||
return Object.prototype.toString.call(obj) === OBJECT_NUMBER;
|
||||
},
|
||||
_isString: function(obj) {
|
||||
return Object.prototype.toString.call(obj) == OBJECT_STRING;
|
||||
return Object.prototype.toString.call(obj) === OBJECT_STRING;
|
||||
},
|
||||
// Returns a function, that, when invoked, will only be triggered at most once
|
||||
// during a given window of time. Normally, the throttled function will run
|
||||
@ -725,7 +727,7 @@
|
||||
_namedColorToRBA: function(str) {
|
||||
var c = COLORS[str.toLowerCase()];
|
||||
if (!c) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
r: c[0],
|
||||
@ -839,11 +841,11 @@
|
||||
this.constructor = child;
|
||||
}
|
||||
Ctor.prototype = parent.prototype;
|
||||
var old_proto = child.prototype;
|
||||
var oldProto = child.prototype;
|
||||
child.prototype = new Ctor();
|
||||
for (var key in old_proto) {
|
||||
if (old_proto.hasOwnProperty(key)) {
|
||||
child.prototype[key] = old_proto[key];
|
||||
for (var key in oldProto) {
|
||||
if (oldProto.hasOwnProperty(key)) {
|
||||
child.prototype[key] = oldProto[key];
|
||||
}
|
||||
}
|
||||
child.__super__ = parent.prototype;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
the Gauss filter
|
||||
master repo: https://github.com/pavelpower/konvajsGaussFilter/
|
||||
master repo: https://github.com/pavelpower/kineticjsGaussFilter
|
||||
*/
|
||||
(function() {
|
||||
/*
|
||||
@ -116,7 +116,7 @@
|
||||
|
||||
for ( i = 1; i < div; i++ ) {
|
||||
stack = stack.next = new BlurStack();
|
||||
if ( i == radiusPlus1 ){
|
||||
if ( i === radiusPlus1 ){
|
||||
stackEnd = stack;
|
||||
}
|
||||
}
|
||||
|
@ -178,5 +178,3 @@
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
})();
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
/*jshint newcap:false */
|
||||
(function () {
|
||||
|
||||
/*
|
||||
|
@ -1,3 +1,4 @@
|
||||
/*eslint-disable no-shadow*/
|
||||
(function () {
|
||||
/**
|
||||
* Path constructor.
|
||||
|
@ -161,16 +161,16 @@
|
||||
currentT = 0;
|
||||
var pathData = that.dataArray;
|
||||
|
||||
for(var i = pIndex + 1; i < pathData.length; i++) {
|
||||
if(pathData[i].pathLength > 0) {
|
||||
pIndex = i;
|
||||
for(var j = pIndex + 1; j < pathData.length; j++) {
|
||||
if(pathData[j].pathLength > 0) {
|
||||
pIndex = j;
|
||||
|
||||
return pathData[i];
|
||||
return pathData[j];
|
||||
}
|
||||
else if(pathData[i].command == 'M') {
|
||||
else if(pathData[j].command === 'M') {
|
||||
p0 = {
|
||||
x: pathData[i].points[0],
|
||||
y: pathData[i].points[1]
|
||||
x: pathData[j].points[0],
|
||||
y: pathData[j].points[1]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@
|
||||
width = this.getWidth(),
|
||||
height = this.getHeight();
|
||||
|
||||
|
||||
context.beginPath();
|
||||
|
||||
if(!cornerRadius) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
(function() {
|
||||
// the 0.0001 offset fixes a bug in Chrome 27
|
||||
var PIx2 = (Math.PI * 2) - 0.0001;
|
||||
|
||||
/**
|
||||
* Ring constructor
|
||||
* @constructor
|
||||
@ -88,7 +87,6 @@
|
||||
* // set inner radius
|
||||
* ring.innerRadius(20);
|
||||
*/
|
||||
|
||||
Konva.Factory.addGetter(Konva.Ring, 'outerRadius', 0);
|
||||
Konva.Factory.addOverloadedGetterSetter(Konva.Ring, 'outerRadius');
|
||||
|
||||
|
@ -41,6 +41,13 @@ suite('Circle', function(){
|
||||
assert.equal(trace, 'clearRect(0,0,578,200);clearRect(0,0,578,200);save();transform(1,0,0,1,100,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();');
|
||||
});
|
||||
|
||||
test('clone', function() {
|
||||
var circle = new Konva.Circle();
|
||||
var clone = circle.clone();
|
||||
assert.equal(clone instanceof Konva.Circle, true);
|
||||
assert.equal(clone.className, 'Circle');
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('add circle with pattern fill', function(done) {
|
||||
var imageObj = new Image();
|
||||
|
Loading…
Reference in New Issue
Block a user