mirror of
https://github.com/konvajs/konva.git
synced 2025-12-19 10:58:20 +08:00
better HDPI support
update packages
This commit is contained in:
12
.eslintrc
12
.eslintrc
@@ -26,7 +26,7 @@
|
|||||||
"no-empty": 2,
|
"no-empty": 2,
|
||||||
"no-empty-class": 0,
|
"no-empty-class": 0,
|
||||||
"no-empty-character-class": 2,
|
"no-empty-character-class": 2,
|
||||||
"no-empty-label": 2,
|
"no-labels": 2,
|
||||||
"no-eq-null": 2,
|
"no-eq-null": 2,
|
||||||
"no-eval": 2,
|
"no-eval": 2,
|
||||||
"no-ex-assign": 2,
|
"no-ex-assign": 2,
|
||||||
@@ -45,7 +45,6 @@
|
|||||||
"no-irregular-whitespace": 2,
|
"no-irregular-whitespace": 2,
|
||||||
"no-iterator": 2,
|
"no-iterator": 2,
|
||||||
"no-label-var": 2,
|
"no-label-var": 2,
|
||||||
"no-labels": 2,
|
|
||||||
"no-lone-blocks": 2,
|
"no-lone-blocks": 2,
|
||||||
"no-lonely-if": 0,
|
"no-lonely-if": 0,
|
||||||
"no-loop-func": 2,
|
"no-loop-func": 2,
|
||||||
@@ -106,12 +105,11 @@
|
|||||||
"block-scoped-var": 0,
|
"block-scoped-var": 0,
|
||||||
"brace-style": [0, "1tbs"],
|
"brace-style": [0, "1tbs"],
|
||||||
"camelcase": 1,
|
"camelcase": 1,
|
||||||
"comma-dangle": [2, "never"],
|
|
||||||
"comma-spacing": 2,
|
"comma-spacing": 2,
|
||||||
"comma-style": 0,
|
"comma-style": 0,
|
||||||
"complexity": [1, 11],
|
"complexity": [1, 11],
|
||||||
"computed-property-spacing": [0, "never"],
|
"computed-property-spacing": [0, "never"],
|
||||||
"consistent-return": 2,
|
"consistent-return": 1,
|
||||||
"consistent-this": [0, "that"],
|
"consistent-this": [0, "that"],
|
||||||
"curly": [2, "all"],
|
"curly": [2, "all"],
|
||||||
"default-case": 0,
|
"default-case": 0,
|
||||||
@@ -156,11 +154,11 @@
|
|||||||
"space-in-brackets": [0, "never"],
|
"space-in-brackets": [0, "never"],
|
||||||
"space-in-parens": [0, "never"],
|
"space-in-parens": [0, "never"],
|
||||||
"space-infix-ops": 2,
|
"space-infix-ops": 2,
|
||||||
"space-return-throw-case": 2,
|
"keyword-spacing": 1,
|
||||||
"space-unary-ops": [2, { "words": true, "nonwords": false }],
|
"space-unary-ops": [2, { "words": true, "nonwords": false }],
|
||||||
"spaced-comment": 0,
|
"spaced-comment": 0,
|
||||||
"spaced-line-comment": [0, "always"],
|
"spaced-line-comment": [0, "always"],
|
||||||
"strict": 2,
|
"strict": [2, "function"],
|
||||||
"use-isnan": 2,
|
"use-isnan": 2,
|
||||||
"valid-jsdoc": 0,
|
"valid-jsdoc": 0,
|
||||||
"valid-typeof": 2,
|
"valid-typeof": 2,
|
||||||
@@ -176,5 +174,5 @@
|
|||||||
"assert": false,
|
"assert": false,
|
||||||
"addStage": false,
|
"addStage": false,
|
||||||
"suite": false
|
"suite": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
## Fixed
|
## Fixed
|
||||||
- repair `cancelBubble` event property behaviour
|
- repair `cancelBubble` event property behaviour
|
||||||
- fix wrong `Path` `getClientRect()` calculation
|
- fix wrong `Path` `getClientRect()` calculation
|
||||||
|
- better HDPI support
|
||||||
|
|
||||||
## [0.11.1][2016-01-16]
|
## [0.11.1][2016-01-16]
|
||||||
|
|
||||||
|
|||||||
45
konva.js
45
konva.js
@@ -3,7 +3,7 @@
|
|||||||
* Konva JavaScript Framework v0.11.1
|
* Konva JavaScript Framework v0.11.1
|
||||||
* http://konvajs.github.io/
|
* http://konvajs.github.io/
|
||||||
* Licensed under the MIT or GPL Version 2 licenses.
|
* Licensed under the MIT or GPL Version 2 licenses.
|
||||||
* Date: Fri Feb 05 2016
|
* Date: Sun Feb 28 2016
|
||||||
*
|
*
|
||||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||||
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
|
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
|
||||||
@@ -200,29 +200,29 @@
|
|||||||
UA: undefined
|
UA: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
var global =
|
var glob =
|
||||||
typeof window !== 'undefined' ? window :
|
typeof window !== 'undefined' ? window :
|
||||||
typeof global !== 'undefined' ? global :
|
typeof global !== 'undefined' ? global :
|
||||||
typeof WorkerGlobalScope !== 'undefined' ? self : {};
|
typeof WorkerGlobalScope !== 'undefined' ? self : {};
|
||||||
|
|
||||||
|
|
||||||
Konva.UA = Konva._parseUA((global.navigator && global.navigator.userAgent) || '');
|
Konva.UA = Konva._parseUA((glob.navigator && glob.navigator.userAgent) || '');
|
||||||
|
|
||||||
if (global.Konva) {
|
if (glob.Konva) {
|
||||||
console.error(
|
console.error(
|
||||||
'Konva instance is already exist in current eviroment. ' +
|
'Konva instance is already exist in current eviroment. ' +
|
||||||
'Please use only one instance.'
|
'Please use only one instance.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
global.Konva = Konva;
|
glob.Konva = Konva;
|
||||||
Konva.global = global;
|
Konva.global = glob;
|
||||||
|
|
||||||
|
|
||||||
if( typeof exports === 'object') {
|
if( typeof exports === 'object') {
|
||||||
// runtime-check for browserify and nw.js (node-webkit)
|
// runtime-check for browserify and nw.js (node-webkit)
|
||||||
if(global.window && global.window.document) {
|
if(glob.window && glob.window.document) {
|
||||||
Konva.document = global.window.document;
|
Konva.document = glob.window.document;
|
||||||
Konva.window = global.window;
|
Konva.window = glob.window;
|
||||||
} else {
|
} else {
|
||||||
// Node. Does not work with strict CommonJS, but
|
// Node. Does not work with strict CommonJS, but
|
||||||
// only CommonJS-like enviroments that support module.exports,
|
// only CommonJS-like enviroments that support module.exports,
|
||||||
@@ -1847,10 +1847,6 @@
|
|||||||
args = _simplifyArray(Array.prototype.slice.call(arguments, 0));
|
args = _simplifyArray(Array.prototype.slice.call(arguments, 0));
|
||||||
ret = origMethod.apply(that, arguments);
|
ret = origMethod.apply(that, arguments);
|
||||||
|
|
||||||
if (methodName === 'clearRect') {
|
|
||||||
args[2] = args[2] / that.canvas.getPixelRatio();
|
|
||||||
args[3] = args[3] / that.canvas.getPixelRatio();
|
|
||||||
}
|
|
||||||
that._trace({
|
that._trace({
|
||||||
method: methodName,
|
method: methodName,
|
||||||
args: args
|
args: args
|
||||||
@@ -2530,10 +2526,10 @@
|
|||||||
maxY = Math.max(maxY, transformed.y);
|
maxY = Math.max(maxY, transformed.y);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
x: Math.round(minX),
|
x: minX,
|
||||||
y: Math.round(minY),
|
y: minY,
|
||||||
width: Math.round(maxX - minX),
|
width: maxX - minX,
|
||||||
height: Math.round(maxY - minY)
|
height: maxY - minY
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
_drawCachedSceneCanvas: function(context) {
|
_drawCachedSceneCanvas: function(context) {
|
||||||
@@ -7406,15 +7402,16 @@
|
|||||||
drawFunc.call(this, bufferContext);
|
drawFunc.call(this, bufferContext);
|
||||||
bufferContext.restore();
|
bufferContext.restore();
|
||||||
|
|
||||||
|
var ratio = bufferCanvas.pixelRatio;
|
||||||
if (hasShadow && !canvas.hitCanvas) {
|
if (hasShadow && !canvas.hitCanvas) {
|
||||||
context.save();
|
context.save();
|
||||||
context._applyShadow(this);
|
context._applyShadow(this);
|
||||||
context._applyOpacity(this);
|
context._applyOpacity(this);
|
||||||
context.drawImage(bufferCanvas._canvas, 0, 0);
|
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
|
||||||
context.restore();
|
context.restore();
|
||||||
} else {
|
} else {
|
||||||
context._applyOpacity(this);
|
context._applyOpacity(this);
|
||||||
context.drawImage(bufferCanvas._canvas, 0, 0);
|
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if buffer canvas is not needed
|
// if buffer canvas is not needed
|
||||||
@@ -9260,10 +9257,8 @@
|
|||||||
// the buffer canvas pixel ratio must be 1 because it is used as an
|
// the buffer canvas pixel ratio must be 1 because it is used as an
|
||||||
// intermediate canvas before copying the result onto a scene canvas.
|
// intermediate canvas before copying the result onto a scene canvas.
|
||||||
// not setting it to 1 will result in an over compensation
|
// not setting it to 1 will result in an over compensation
|
||||||
this.bufferCanvas = new Konva.SceneCanvas({
|
this.bufferCanvas = new Konva.SceneCanvas();
|
||||||
pixelRatio: 1
|
this.bufferHitCanvas = new Konva.HitCanvas({pixelRatio: 1});
|
||||||
});
|
|
||||||
this.bufferHitCanvas = new Konva.HitCanvas();
|
|
||||||
|
|
||||||
this._resizeDOM();
|
this._resizeDOM();
|
||||||
},
|
},
|
||||||
@@ -10145,8 +10140,8 @@
|
|||||||
len = animations.length,
|
len = animations.length,
|
||||||
n;
|
n;
|
||||||
|
|
||||||
for(n = 0; n < len; n++) {
|
for (n = 0; n < len; n++) {
|
||||||
if(animations[n].id === this.id) {
|
if (animations[n].id === this.id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
konva.min.js
vendored
12
konva.min.js
vendored
File diff suppressed because one or more lines are too long
15
package.json
15
package.json
@@ -4,22 +4,23 @@
|
|||||||
"author": "Anton Lavrenov",
|
"author": "Anton Lavrenov",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "gulp",
|
"start": "gulp",
|
||||||
"full-build": "gulp lint test build"
|
"full-build": "gulp lint test build",
|
||||||
|
"test": "gulp test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "3.2.0",
|
"chai": "3.5.0",
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.0",
|
||||||
"gulp-concat": "^2.6.0",
|
"gulp-concat": "^2.6.0",
|
||||||
"gulp-connect": "^2.2.0",
|
"gulp-connect": "^3.0.0",
|
||||||
"gulp-eslint": "^1.0.0",
|
"gulp-eslint": "^2.0.0",
|
||||||
"gulp-jscpd": "0.0.4",
|
"gulp-jscpd": "0.0.6",
|
||||||
"gulp-jsdoc": "^0.1.4",
|
"gulp-jsdoc": "^0.1.4",
|
||||||
"gulp-mocha-phantomjs": "^0.9.0",
|
"gulp-mocha-phantomjs": "^0.11.0",
|
||||||
"gulp-rename": "^1.2.2",
|
"gulp-rename": "^1.2.2",
|
||||||
"gulp-replace": "^0.5.4",
|
"gulp-replace": "^0.5.4",
|
||||||
"gulp-uglify": "^1.3.0",
|
"gulp-uglify": "^1.3.0",
|
||||||
"gulp-util": "^3.0.6",
|
"gulp-util": "^3.0.6",
|
||||||
"mocha": "2.2.5"
|
"mocha": "2.4.5"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"canvas",
|
"canvas",
|
||||||
|
|||||||
@@ -140,8 +140,8 @@
|
|||||||
len = animations.length,
|
len = animations.length,
|
||||||
n;
|
n;
|
||||||
|
|
||||||
for(n = 0; n < len; n++) {
|
for (n = 0; n < len; n++) {
|
||||||
if(animations[n].id === this.id) {
|
if (animations[n].id === this.id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -402,10 +402,6 @@
|
|||||||
args = _simplifyArray(Array.prototype.slice.call(arguments, 0));
|
args = _simplifyArray(Array.prototype.slice.call(arguments, 0));
|
||||||
ret = origMethod.apply(that, arguments);
|
ret = origMethod.apply(that, arguments);
|
||||||
|
|
||||||
if (methodName === 'clearRect') {
|
|
||||||
args[2] = args[2] / that.canvas.getPixelRatio();
|
|
||||||
args[3] = args[3] / that.canvas.getPixelRatio();
|
|
||||||
}
|
|
||||||
that._trace({
|
that._trace({
|
||||||
method: methodName,
|
method: methodName,
|
||||||
args: args
|
args: args
|
||||||
|
|||||||
@@ -200,29 +200,29 @@
|
|||||||
UA: undefined
|
UA: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
var global =
|
var glob =
|
||||||
typeof window !== 'undefined' ? window :
|
typeof window !== 'undefined' ? window :
|
||||||
typeof global !== 'undefined' ? global :
|
typeof global !== 'undefined' ? global :
|
||||||
typeof WorkerGlobalScope !== 'undefined' ? self : {};
|
typeof WorkerGlobalScope !== 'undefined' ? self : {};
|
||||||
|
|
||||||
|
|
||||||
Konva.UA = Konva._parseUA((global.navigator && global.navigator.userAgent) || '');
|
Konva.UA = Konva._parseUA((glob.navigator && glob.navigator.userAgent) || '');
|
||||||
|
|
||||||
if (global.Konva) {
|
if (glob.Konva) {
|
||||||
console.error(
|
console.error(
|
||||||
'Konva instance is already exist in current eviroment. ' +
|
'Konva instance is already exist in current eviroment. ' +
|
||||||
'Please use only one instance.'
|
'Please use only one instance.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
global.Konva = Konva;
|
glob.Konva = Konva;
|
||||||
Konva.global = global;
|
Konva.global = glob;
|
||||||
|
|
||||||
|
|
||||||
if( typeof exports === 'object') {
|
if( typeof exports === 'object') {
|
||||||
// runtime-check for browserify and nw.js (node-webkit)
|
// runtime-check for browserify and nw.js (node-webkit)
|
||||||
if(global.window && global.window.document) {
|
if(glob.window && glob.window.document) {
|
||||||
Konva.document = global.window.document;
|
Konva.document = glob.window.document;
|
||||||
Konva.window = global.window;
|
Konva.window = glob.window;
|
||||||
} else {
|
} else {
|
||||||
// Node. Does not work with strict CommonJS, but
|
// Node. Does not work with strict CommonJS, but
|
||||||
// only CommonJS-like enviroments that support module.exports,
|
// only CommonJS-like enviroments that support module.exports,
|
||||||
|
|||||||
@@ -293,10 +293,10 @@
|
|||||||
maxY = Math.max(maxY, transformed.y);
|
maxY = Math.max(maxY, transformed.y);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
x: Math.round(minX),
|
x: minX,
|
||||||
y: Math.round(minY),
|
y: minY,
|
||||||
width: Math.round(maxX - minX),
|
width: maxX - minX,
|
||||||
height: Math.round(maxY - minY)
|
height: maxY - minY
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
_drawCachedSceneCanvas: function(context) {
|
_drawCachedSceneCanvas: function(context) {
|
||||||
|
|||||||
@@ -279,15 +279,16 @@
|
|||||||
drawFunc.call(this, bufferContext);
|
drawFunc.call(this, bufferContext);
|
||||||
bufferContext.restore();
|
bufferContext.restore();
|
||||||
|
|
||||||
|
var ratio = bufferCanvas.pixelRatio;
|
||||||
if (hasShadow && !canvas.hitCanvas) {
|
if (hasShadow && !canvas.hitCanvas) {
|
||||||
context.save();
|
context.save();
|
||||||
context._applyShadow(this);
|
context._applyShadow(this);
|
||||||
context._applyOpacity(this);
|
context._applyOpacity(this);
|
||||||
context.drawImage(bufferCanvas._canvas, 0, 0);
|
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
|
||||||
context.restore();
|
context.restore();
|
||||||
} else {
|
} else {
|
||||||
context._applyOpacity(this);
|
context._applyOpacity(this);
|
||||||
context.drawImage(bufferCanvas._canvas, 0, 0);
|
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if buffer canvas is not needed
|
// if buffer canvas is not needed
|
||||||
|
|||||||
@@ -698,10 +698,8 @@
|
|||||||
// the buffer canvas pixel ratio must be 1 because it is used as an
|
// the buffer canvas pixel ratio must be 1 because it is used as an
|
||||||
// intermediate canvas before copying the result onto a scene canvas.
|
// intermediate canvas before copying the result onto a scene canvas.
|
||||||
// not setting it to 1 will result in an over compensation
|
// not setting it to 1 will result in an over compensation
|
||||||
this.bufferCanvas = new Konva.SceneCanvas({
|
this.bufferCanvas = new Konva.SceneCanvas();
|
||||||
pixelRatio: 1
|
this.bufferHitCanvas = new Konva.HitCanvas({pixelRatio: 1});
|
||||||
});
|
|
||||||
this.bufferHitCanvas = new Konva.HitCanvas();
|
|
||||||
|
|
||||||
this._resizeDOM();
|
this._resizeDOM();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -38,4 +38,4 @@ suite('Canvas', function() {
|
|||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -388,19 +388,8 @@ suite('Caching', function() {
|
|||||||
|
|
||||||
layer.add(group);
|
layer.add(group);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
var canvas = createCanvas();
|
|
||||||
var context = canvas.getContext('2d');
|
|
||||||
context.translate(100, 50);
|
|
||||||
context.rotate(Math.PI / 4);
|
|
||||||
context.beginPath();
|
|
||||||
context.rect(0, 0, 100, 50);
|
|
||||||
context.closePath();
|
|
||||||
context.fillStyle = 'green';
|
|
||||||
context.fill();
|
|
||||||
if (!window.isPhantomJS) {
|
if (!window.isPhantomJS) {
|
||||||
compareLayerAndCanvas(layer, canvas, 150);
|
cloneAndCompareLayer(layer, 200);
|
||||||
cloneAndCompareLayer(layer, 150);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -738,7 +727,7 @@ suite('Caching', function() {
|
|||||||
group.add(circle);
|
group.add(circle);
|
||||||
group.cache();
|
group.cache();
|
||||||
stage.draw();
|
stage.draw();
|
||||||
|
|
||||||
cloneAndCompareLayer(layer, 150);
|
cloneAndCompareLayer(layer, 150);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ suite('Node', function() {
|
|||||||
assert.equal(image.width(), stage.width() * 2, 'image has double size');
|
assert.equal(image.width(), stage.width() * 2, 'image has double size');
|
||||||
layer2.add(image);
|
layer2.add(image);
|
||||||
layer2.draw();
|
layer2.draw();
|
||||||
compareLayers(layer, layer2);
|
compareLayers(layer, layer2, 50);
|
||||||
Konva.pixelRatio = oldRatio;
|
Konva.pixelRatio = oldRatio;
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -2128,7 +2128,7 @@ suite('Node', function() {
|
|||||||
var bufferTrace = stage.bufferCanvas.getContext().getTrace();
|
var bufferTrace = stage.bufferCanvas.getContext().getTrace();
|
||||||
//console.log(bufferTrace);
|
//console.log(bufferTrace);
|
||||||
|
|
||||||
assert.equal(sceneTrace, 'clearRect(0,0,578,200);save();globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0);restore();');
|
assert.equal(sceneTrace, 'clearRect(0,0,578,200);save();globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0,578,200);restore();');
|
||||||
assert.equal(bufferTrace, 'clearRect(0,0,578,200);save();transform(1,0,0,1,289,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=20;strokeStyle=black;stroke();restore();');
|
assert.equal(bufferTrace, 'clearRect(0,0,578,200);save();transform(1,0,0,1,289,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=20;strokeStyle=black;stroke();restore();');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ suite('Shape', function() {
|
|||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
assert.equal(rect.intersects({
|
assert.equal(rect.intersects({
|
||||||
x: 200,
|
x: 201,
|
||||||
y: 100
|
y: 101
|
||||||
}), true, '(200,100) should intersect the shape');
|
}), true, '(201,101) should intersect the shape');
|
||||||
|
|
||||||
assert.equal(rect.intersects({
|
assert.equal(rect.intersects({
|
||||||
x: 197,
|
x: 197,
|
||||||
@@ -544,18 +544,17 @@ suite('Shape', function() {
|
|||||||
|
|
||||||
var canvas = createCanvas();
|
var canvas = createCanvas();
|
||||||
var context = canvas.getContext('2d');
|
var context = canvas.getContext('2d');
|
||||||
context.globalAlpha = 0.5;
|
context.globalAlpha = 0.1;
|
||||||
|
|
||||||
// draw shadow
|
// draw shadow
|
||||||
var offset = 200;
|
|
||||||
context.save();
|
context.save();
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.rect(95 - offset, 45 - offset, 110, 60);
|
context.rect(95, 45, 110, 60);
|
||||||
context.closePath();
|
context.closePath();
|
||||||
context.shadowColor = 'grey';
|
context.shadowColor = 'grey';
|
||||||
context.shadowBlur = 1;
|
context.shadowBlur = 1;
|
||||||
context.shadowOffsetX = 20 + offset;
|
context.shadowOffsetX = 20;
|
||||||
context.shadowOffsetY = 20 + offset;
|
context.shadowOffsetY = 20;
|
||||||
context.fillStyle = 'black';
|
context.fillStyle = 'black';
|
||||||
context.fill();
|
context.fill();
|
||||||
context.restore();
|
context.restore();
|
||||||
@@ -585,12 +584,12 @@ suite('Shape', function() {
|
|||||||
// don't test in PhantomJS as it use old chrome engine
|
// don't test in PhantomJS as it use old chrome engine
|
||||||
// it it has opacity + shadow bug
|
// it it has opacity + shadow bug
|
||||||
if (!window.mochaPhantomJS) {
|
if (!window.mochaPhantomJS) {
|
||||||
compareLayerAndCanvas(layer, canvas, 210);
|
compareLayerAndCanvas(layer, canvas, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
var trace = layer.getContext().getTrace();
|
var trace = layer.getContext().getTrace();
|
||||||
//console.log(trace);
|
//console.log(trace);
|
||||||
assert.equal(trace, 'clearRect(0,0,578,200);save();save();shadowColor=rgba(128,128,128,1);shadowBlur=1;shadowOffsetX=20;shadowOffsetY=20;globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0);restore();restore();');
|
assert.equal(trace, 'clearRect(0,0,578,200);save();save();shadowColor=rgba(128,128,128,1);shadowBlur=1;shadowOffsetX=20;shadowOffsetY=20;globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0,578,200);restore();restore();');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -648,11 +647,13 @@ suite('Shape', function() {
|
|||||||
context.fillStyle = 'green';
|
context.fillStyle = 'green';
|
||||||
context.fillText('Test TEXT', 50, 75);
|
context.fillText('Test TEXT', 50, 75);
|
||||||
|
|
||||||
context.lineWidth = 2;
|
context.lineWidth = 2;
|
||||||
context.strokeStyle = 'black';
|
context.strokeStyle = 'black';
|
||||||
context.strokeText('Test TEXT', 50, 75);
|
context.strokeText('Test TEXT', 50, 75);
|
||||||
|
|
||||||
compareLayerAndCanvas(layer, canvas, 50);
|
if (!window.isPhantomJS) {
|
||||||
|
compareLayerAndCanvas(layer, canvas, 254);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ suite('Stage', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
assert.equal(stage.bufferCanvas.getPixelRatio(), 1);
|
assert.equal(stage.bufferCanvas.getPixelRatio(), 2);
|
||||||
assert.equal(stage.bufferHitCanvas.getPixelRatio(), 2);
|
assert.equal(stage.bufferHitCanvas.getPixelRatio(), 1);
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
Konva.pixelRatio = 1;
|
Konva.pixelRatio = 1;
|
||||||
@@ -138,8 +138,8 @@ suite('Stage', function() {
|
|||||||
assert.equal(stage.getSize().height, 155);
|
assert.equal(stage.getSize().height, 155);
|
||||||
assert.equal(stage.getContent().style.width, '333px');
|
assert.equal(stage.getContent().style.width, '333px');
|
||||||
assert.equal(stage.getContent().style.height, '155px');
|
assert.equal(stage.getContent().style.height, '155px');
|
||||||
assert.equal(layer.getCanvas()._canvas.width, 333);
|
assert.equal(layer.getCanvas()._canvas.width, 333 * layer.getCanvas().getPixelRatio());
|
||||||
assert.equal(layer.getCanvas()._canvas.height, 155);
|
assert.equal(layer.getCanvas()._canvas.height, 155 * layer.getCanvas().getPixelRatio());
|
||||||
});
|
});
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ suite('RGB', function() {
|
|||||||
|
|
||||||
var imageObj = new Image();
|
var imageObj = new Image();
|
||||||
imageObj.onload = function() {
|
imageObj.onload = function() {
|
||||||
|
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
darth = new Konva.Image({
|
darth = new Konva.Image({
|
||||||
x: 10,
|
x: 10,
|
||||||
@@ -23,7 +23,7 @@ suite('RGB', function() {
|
|||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
// Assert fails even though '[255,0,128] = [255,0,128]'
|
// Assert fails even though '[255,0,128] = [255,0,128]'
|
||||||
//assert.equal(darth.getFilterColorizeColor(), [255,0,128]);
|
// assert.deepEqual(darth.getFilterColorizeColor(), [255,0,128]);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
@@ -37,7 +37,7 @@ suite('RGB', function() {
|
|||||||
|
|
||||||
var imageObj = new Image();
|
var imageObj = new Image();
|
||||||
imageObj.onload = function() {
|
imageObj.onload = function() {
|
||||||
|
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
darth = new Konva.Image({
|
darth = new Konva.Image({
|
||||||
x: 10,
|
x: 10,
|
||||||
@@ -55,7 +55,7 @@ suite('RGB', function() {
|
|||||||
darth.red(0).green(255).blue(0);
|
darth.red(0).green(255).blue(0);
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
// assert.equal(darth.getFilterColorizeColor(), [0,255,0]);
|
// assert.deepEqual(darth.getFilterColorizeColor(), [0,255,0]);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ suite('RGB', function() {
|
|||||||
for( i=0; i<l; i+=1 ){
|
for( i=0; i<l; i+=1 ){
|
||||||
var imageObj = new Image();
|
var imageObj = new Image();
|
||||||
imageObj.onload = (function(color,x){ return function() {
|
imageObj.onload = (function(color,x){ return function() {
|
||||||
|
|
||||||
var darth = new Konva.Image({
|
var darth = new Konva.Image({
|
||||||
x: x,
|
x: x,
|
||||||
y: 32,
|
y: 32,
|
||||||
|
|||||||
@@ -2,12 +2,6 @@ suite('RGBA', function() {
|
|||||||
// ======================================================
|
// ======================================================
|
||||||
test('colorize basic', function(done) {
|
test('colorize basic', function(done) {
|
||||||
var data = [
|
var data = [
|
||||||
{
|
|
||||||
color: '#ff0000',
|
|
||||||
filter: [170, 170, 170, 0.5],
|
|
||||||
// Actually 212 but in tests rounding half up
|
|
||||||
result: [213, 85, 85, 255]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
color: '#2a6511',
|
color: '#2a6511',
|
||||||
filter: [242, 193, 168, 0.33],
|
filter: [242, 193, 168, 0.33],
|
||||||
@@ -67,11 +61,9 @@ suite('RGBA', function() {
|
|||||||
|
|
||||||
var a0 = imageDataToArray(0);
|
var a0 = imageDataToArray(0);
|
||||||
var a1 = imageDataToArray(1);
|
var a1 = imageDataToArray(1);
|
||||||
var a2 = imageDataToArray(2);
|
|
||||||
|
|
||||||
assert.deepEqual(a0, data[0].result);
|
assert.deepEqual(a0, data[0].result);
|
||||||
assert.deepEqual(a1, data[1].result);
|
assert.deepEqual(a1, data[1].result);
|
||||||
assert.deepEqual(a2, data[2].result);
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ suite('RegularPolygon', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('polygon cache', function() {
|
test('polygon cache', function() {
|
||||||
|
Konva.pixelRatio = 1;
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ suite('RegularPolygon', function() {
|
|||||||
sides: 5,
|
sides: 5,
|
||||||
radius: 50,
|
radius: 50,
|
||||||
fill: 'green',
|
fill: 'green',
|
||||||
stroke: 'blue',
|
stroke: 'black',
|
||||||
strokeWidth: 5,
|
strokeWidth: 5,
|
||||||
name: 'foobar'
|
name: 'foobar'
|
||||||
});
|
});
|
||||||
@@ -143,8 +144,10 @@ suite('RegularPolygon', function() {
|
|||||||
width : 100
|
width : 100
|
||||||
});
|
});
|
||||||
if (!window.isPhantomJS) {
|
if (!window.isPhantomJS) {
|
||||||
cloneAndCompareLayer(layer, 200);
|
cloneAndCompareLayer(layer, 254);
|
||||||
}
|
}
|
||||||
|
Konva.pixelRatio = undefined;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -96,6 +96,6 @@ suite('Ellipse', function(){
|
|||||||
context.fill();
|
context.fill();
|
||||||
context.lineWidth = 8;
|
context.lineWidth = 8;
|
||||||
context.stroke();
|
context.stroke();
|
||||||
compareLayerAndCanvas(layer, canvas, 50);
|
compareLayerAndCanvas(layer, canvas, 80);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ suite('Image', function(){
|
|||||||
|
|
||||||
var trace = layer.getContext().getTrace();
|
var trace = layer.getContext().getTrace();
|
||||||
//console.log(trace);
|
//console.log(trace);
|
||||||
assert.equal(trace, 'clearRect(0,0,578,200);save();save();shadowColor=rgba(0,0,0,0.5);shadowBlur=10;shadowOffsetX=20;shadowOffsetY=20;globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0);restore();restore();');
|
assert.equal(trace, 'clearRect(0,0,578,200);save();save();shadowColor=rgba(0,0,0,0.5);shadowBlur=10;shadowOffsetX=20;shadowOffsetY=20;globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0,578,200);restore();restore();');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user