mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
shadow fix and small perf improve
This commit is contained in:
parent
db10dc5081
commit
1a45e953c2
71
konva.js
71
konva.js
@ -2,7 +2,7 @@
|
||||
* Konva JavaScript Framework v1.7.6
|
||||
* http://konvajs.github.io/
|
||||
* Licensed under the MIT
|
||||
* Date: Sat Mar 10 2018
|
||||
* Date: Mon Mar 12 2018
|
||||
*
|
||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||
@ -2012,22 +2012,34 @@
|
||||
},
|
||||
_fill: function(shape) {
|
||||
var hasColor = shape.fill(),
|
||||
hasPattern = shape.getFillPatternImage(),
|
||||
hasLinearGradient = shape.getFillLinearGradientColorStops(),
|
||||
hasRadialGradient = shape.getFillRadialGradientColorStops(),
|
||||
fillPriority = shape.getFillPriority();
|
||||
|
||||
// priority fills
|
||||
if (hasColor && fillPriority === 'color') {
|
||||
this._fillColor(shape);
|
||||
} else if (hasPattern && fillPriority === 'pattern') {
|
||||
return;
|
||||
}
|
||||
|
||||
var hasPattern = shape.getFillPatternImage();
|
||||
if (hasPattern && fillPriority === 'pattern') {
|
||||
this._fillPattern(shape);
|
||||
} else if (hasLinearGradient && fillPriority === 'linear-gradient') {
|
||||
return;
|
||||
}
|
||||
|
||||
var hasLinearGradient = shape.getFillLinearGradientColorStops();
|
||||
if (hasLinearGradient && fillPriority === 'linear-gradient') {
|
||||
this._fillLinearGradient(shape);
|
||||
} else if (hasRadialGradient && fillPriority === 'radial-gradient') {
|
||||
return;
|
||||
}
|
||||
|
||||
var hasRadialGradient = shape.getFillRadialGradientColorStops();
|
||||
if (hasRadialGradient && fillPriority === 'radial-gradient') {
|
||||
this._fillRadialGradient(shape);
|
||||
} else if (hasColor) {
|
||||
return;
|
||||
}
|
||||
|
||||
// now just try and fill with whatever is available
|
||||
if (hasColor) {
|
||||
this._fillColor(shape);
|
||||
} else if (hasPattern) {
|
||||
this._fillPattern(shape);
|
||||
@ -2108,7 +2120,7 @@
|
||||
this.setAttr('shadowColor', color);
|
||||
this.setAttr(
|
||||
'shadowBlur',
|
||||
blur * ratio * Math.min(Math.abs(scaleX), Math.abs(scaleY))
|
||||
blur * Math.min(Math.abs(scaleX), Math.abs(scaleY))
|
||||
);
|
||||
this.setAttr('shadowOffsetX', offset.x * scaleX);
|
||||
this.setAttr('shadowOffsetY', offset.y * scaleY);
|
||||
@ -12848,7 +12860,7 @@
|
||||
|
||||
/**
|
||||
* get/set drag bound function. This is used to override the default
|
||||
* drag and drop position
|
||||
* drag and drop position.
|
||||
* @name dragBoundFunc
|
||||
* @method
|
||||
* @memberof Konva.Node.prototype
|
||||
@ -12860,6 +12872,8 @@
|
||||
*
|
||||
* // create vertical drag and drop
|
||||
* node.dragBoundFunc(function(pos){
|
||||
* // important pos - is absolute position of the node
|
||||
* // you should return absolute position too
|
||||
* return {
|
||||
* x: this.getAbsolutePosition().x,
|
||||
* y: pos.y
|
||||
@ -16180,7 +16194,8 @@
|
||||
};
|
||||
};
|
||||
Konva.Path.getPointOnEllipticalArc = function(cx, cy, rx, ry, theta, psi) {
|
||||
var cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
|
||||
var cosPsi = Math.cos(psi),
|
||||
sinPsi = Math.sin(psi);
|
||||
var pt = {
|
||||
x: rx * Math.cos(theta),
|
||||
y: ry * Math.sin(theta)
|
||||
@ -16259,26 +16274,35 @@
|
||||
// create array
|
||||
var arr = cs.split('|');
|
||||
var ca = [];
|
||||
var coords = [];
|
||||
// init context point
|
||||
var cpx = 0;
|
||||
var cpy = 0;
|
||||
|
||||
var re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
|
||||
var match;
|
||||
for (n = 1; n < arr.length; n++) {
|
||||
var str = arr[n];
|
||||
var c = str.charAt(0);
|
||||
str = str.slice(1);
|
||||
// remove ,- for consistency
|
||||
str = str.replace(new RegExp(',-', 'g'), '-');
|
||||
// add commas so that it's easy to split
|
||||
str = str.replace(new RegExp('-', 'g'), ',-');
|
||||
str = str.replace(new RegExp('e,-', 'g'), 'e-');
|
||||
var p = str.split(',');
|
||||
if (p.length > 0 && p[0] === '') {
|
||||
p.shift();
|
||||
|
||||
coords.length = 0;
|
||||
while ((match = re.exec(str))) {
|
||||
coords.push(match[0]);
|
||||
}
|
||||
// convert strings to floats
|
||||
for (var i = 0; i < p.length; i++) {
|
||||
p[i] = parseFloat(p[i]);
|
||||
|
||||
// while ((match = re.exec(str))) {
|
||||
// coords.push(match[0]);
|
||||
// }
|
||||
var p = [];
|
||||
|
||||
for (var j = 0, jlen = coords.length; j < jlen; j++) {
|
||||
var parsed = parseFloat(coords[j]);
|
||||
if (!isNaN(parsed)) {
|
||||
p.push(parsed);
|
||||
}
|
||||
}
|
||||
|
||||
while (p.length > 0) {
|
||||
if (isNaN(p[0])) {
|
||||
// case for a trailing comma before next command
|
||||
@ -16287,7 +16311,8 @@
|
||||
|
||||
var cmd = null;
|
||||
var points = [];
|
||||
var startX = cpx, startY = cpy;
|
||||
var startX = cpx,
|
||||
startY = cpy;
|
||||
// Move var from within the switch to up here (jshint)
|
||||
var prevCmd, ctlPtx, ctlPty; // Ss, Tt
|
||||
var rx, ry, psi, fa, fs, x1, y1; // Aa
|
||||
|
6
konva.min.js
vendored
6
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -563,22 +563,34 @@
|
||||
},
|
||||
_fill: function(shape) {
|
||||
var hasColor = shape.fill(),
|
||||
hasPattern = shape.getFillPatternImage(),
|
||||
hasLinearGradient = shape.getFillLinearGradientColorStops(),
|
||||
hasRadialGradient = shape.getFillRadialGradientColorStops(),
|
||||
fillPriority = shape.getFillPriority();
|
||||
|
||||
// priority fills
|
||||
if (hasColor && fillPriority === 'color') {
|
||||
this._fillColor(shape);
|
||||
} else if (hasPattern && fillPriority === 'pattern') {
|
||||
return;
|
||||
}
|
||||
|
||||
var hasPattern = shape.getFillPatternImage();
|
||||
if (hasPattern && fillPriority === 'pattern') {
|
||||
this._fillPattern(shape);
|
||||
} else if (hasLinearGradient && fillPriority === 'linear-gradient') {
|
||||
return;
|
||||
}
|
||||
|
||||
var hasLinearGradient = shape.getFillLinearGradientColorStops();
|
||||
if (hasLinearGradient && fillPriority === 'linear-gradient') {
|
||||
this._fillLinearGradient(shape);
|
||||
} else if (hasRadialGradient && fillPriority === 'radial-gradient') {
|
||||
return;
|
||||
}
|
||||
|
||||
var hasRadialGradient = shape.getFillRadialGradientColorStops();
|
||||
if (hasRadialGradient && fillPriority === 'radial-gradient') {
|
||||
this._fillRadialGradient(shape);
|
||||
} else if (hasColor) {
|
||||
return;
|
||||
}
|
||||
|
||||
// now just try and fill with whatever is available
|
||||
if (hasColor) {
|
||||
this._fillColor(shape);
|
||||
} else if (hasPattern) {
|
||||
this._fillPattern(shape);
|
||||
@ -659,7 +671,7 @@
|
||||
this.setAttr('shadowColor', color);
|
||||
this.setAttr(
|
||||
'shadowBlur',
|
||||
blur * ratio * Math.min(Math.abs(scaleX), Math.abs(scaleY))
|
||||
blur * Math.min(Math.abs(scaleX), Math.abs(scaleY))
|
||||
);
|
||||
this.setAttr('shadowOffsetX', offset.x * scaleX);
|
||||
this.setAttr('shadowOffsetY', offset.y * scaleY);
|
||||
|
@ -725,10 +725,10 @@ suite('Caching', function() {
|
||||
group.cache();
|
||||
stage.draw();
|
||||
|
||||
cloneAndCompareLayer(layer, 150);
|
||||
cloneAndCompareLayer(layer, 200);
|
||||
});
|
||||
|
||||
test('test group with opacir', function() {
|
||||
test('test group with opacity', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
@ -756,7 +756,7 @@ suite('Caching', function() {
|
||||
group.cache();
|
||||
stage.draw();
|
||||
|
||||
cloneAndCompareLayer(layer, 150);
|
||||
cloneAndCompareLayer(layer, 210);
|
||||
});
|
||||
|
||||
test('cache group with rectangle with fill and opacity', function() {
|
||||
|
@ -504,7 +504,7 @@ suite('Shape', function() {
|
||||
context.shadowOffsetY = 10 * canvas.ratio;
|
||||
context.fill();
|
||||
|
||||
compareLayerAndCanvas(layer, canvas, 10);
|
||||
compareLayerAndCanvas(layer, canvas, 30);
|
||||
|
||||
var trace = layer.getContext().getTrace();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user