mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Fix issue with svg-gradient breaking the opacity
This commit is contained in:
@@ -554,8 +554,7 @@ tree.functions = {
|
||||
}
|
||||
positionValue = position ? position.toCSS(renderEnv) : i === 0 ? "0%" : "100%";
|
||||
alpha = color.alpha;
|
||||
color.alpha = 1;
|
||||
returner += '<stop offset="' + positionValue + '" stop-color="' + color.toCSS(renderEnv) + '"' + (alpha < 1 ? ' stop-opacity="' + alpha + '"' : '') + '/>';
|
||||
returner += '<stop offset="' + positionValue + '" stop-color="' + color.toRGB() + '"' + (alpha < 1 ? ' stop-opacity="' + alpha + '"' : '') + '/>';
|
||||
}
|
||||
returner += '</' + gradientType + 'Gradient>' +
|
||||
'<rect ' + rectangleDimension + ' fill="url(#gradient)" /></svg>';
|
||||
|
||||
@@ -40,24 +40,18 @@ tree.Color.prototype = {
|
||||
return Math.round(c);
|
||||
}).concat(this.alpha).join(',' + (compress ? '' : ' ')) + ")";
|
||||
} else {
|
||||
var color = this.rgb.map(function (i) {
|
||||
i = Math.round(i);
|
||||
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
|
||||
return i.length === 1 ? '0' + i : i;
|
||||
}).join('');
|
||||
var color = this.toRGB();
|
||||
|
||||
if (compress) {
|
||||
color = color.split('');
|
||||
var splitcolor = color.split('');
|
||||
|
||||
// Convert color to short format
|
||||
if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) {
|
||||
color = color[0] + color[2] + color[4];
|
||||
} else {
|
||||
color = color.join('');
|
||||
if (splitcolor[1] == splitcolor[2] && splitcolor[3] == splitcolor[4] && splitcolor[5] == splitcolor[6]) {
|
||||
color = '#' + splitcolor[1] + splitcolor[3] + splitcolor[5];
|
||||
}
|
||||
}
|
||||
|
||||
return '#' + color;
|
||||
return color;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -80,6 +74,14 @@ tree.Color.prototype = {
|
||||
return new(tree.Color)(result, this.alpha + other.alpha);
|
||||
},
|
||||
|
||||
toRGB: function () {
|
||||
return '#' + this.rgb.map(function (i) {
|
||||
i = Math.round(i);
|
||||
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
|
||||
return i.length === 1 ? '0' + i : i;
|
||||
}).join('');
|
||||
},
|
||||
|
||||
toHSL: function () {
|
||||
var r = this.rgb[0] / 255,
|
||||
g = this.rgb[1] / 255,
|
||||
|
||||
Reference in New Issue
Block a user