mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-13 00:03:10 +00:00
Fix typo, add hsl/hsla (with whitespaces) unit tests and move stuff outside of functions
This commit is contained in:
parent
1ba6d1345e
commit
2c29c0cfab
4 changed files with 45 additions and 17 deletions
|
|
@ -294,6 +294,22 @@
|
|||
'yellow': '#FFFF00'
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Number} p
|
||||
* @param {Number} q
|
||||
* @param {Number} t
|
||||
* @return {Number}
|
||||
*/
|
||||
function hue2rgb(p, q, t){
|
||||
if(t < 0) t += 1;
|
||||
if(t > 1) t -= 1;
|
||||
if(t < 1/6) return p + (q - p) * 6 * t;
|
||||
if(t < 1/2) return q;
|
||||
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new color object, when given a color in RGB format
|
||||
* @param {String} color ex: rgb(0-255,0-255,0-255)
|
||||
|
|
@ -358,15 +374,6 @@
|
|||
l = parseFloat(match[3]) / (/%$/.test(match[3]) ? 100 : 1),
|
||||
r, g, b;
|
||||
|
||||
function hue2rgb(p, q, t){
|
||||
if(t < 0) t += 1;
|
||||
if(t > 1) t -= 1;
|
||||
if(t < 1/6) return p + (q - p) * 6 * t;
|
||||
if(t < 1/2) return q;
|
||||
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
|
||||
return p;
|
||||
}
|
||||
|
||||
if (s === 0) {
|
||||
r = g = b = l;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@
|
|||
'transform': 'transformMatrix'
|
||||
};
|
||||
|
||||
var colorAttributes = {
|
||||
'stroke': 'strokeOpacity',
|
||||
'fill': 'fillOpacity'
|
||||
};
|
||||
|
||||
function normalizeAttr(attr) {
|
||||
// transform attribute names
|
||||
if (attr in attributesMap) {
|
||||
|
|
@ -84,11 +89,6 @@
|
|||
* @param {Object} attributes Array of attributes to parse
|
||||
*/
|
||||
function _setStrokeFillOpacity(attributes) {
|
||||
var colorAttributes = {
|
||||
'stroke': 'strokeOpacity',
|
||||
'fill': 'fillOpacity'
|
||||
};
|
||||
|
||||
for (var attr in colorAttributes) {
|
||||
if (!attributes[attr] || typeof attributes[colorAttributes[attr]] === 'undefined') continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@
|
|||
fontFamily: 'Times New Roman',
|
||||
|
||||
/**
|
||||
* Text decoration Possible valus: "", "underline", "overline" or "line-through".
|
||||
* Text decoration Possible values: "", "underline", "overline" or "line-through".
|
||||
* @type String
|
||||
* @default
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@
|
|||
equal(oColor.toHex(), 'FFFFFF');
|
||||
});
|
||||
|
||||
test('fromRgb (with withspaces)', function() {
|
||||
test('fromRgb (with whitespaces)', function() {
|
||||
ok(typeof fabric.Color.fromRgb == 'function');
|
||||
var originalRgb = 'rgb( 255 , 255 , 255 )';
|
||||
var oColor = fabric.Color.fromRgb(originalRgb);
|
||||
|
|
@ -167,7 +167,7 @@
|
|||
equal(oColor.getAlpha(), 0.5, 'alpha should be set properly');
|
||||
});
|
||||
|
||||
test('fromRgba (with withspaces)', function() {
|
||||
test('fromRgba (with whitespaces)', function() {
|
||||
var originalRgba = 'rgba( 255 , 255 , 255 , 0.5 )';
|
||||
oColor = fabric.Color.fromRgba(originalRgba);
|
||||
ok(oColor);
|
||||
|
|
@ -207,6 +207,16 @@
|
|||
equal(oColor.toHex(), '180637');
|
||||
});
|
||||
|
||||
test('fromHsl (with whitespaces)', function() {
|
||||
ok(typeof fabric.Color.fromHsl == 'function');
|
||||
var originalHsl = 'hsl( 262 , 80% , 12% )';
|
||||
var oColor = fabric.Color.fromHsl(originalHsl);
|
||||
ok(oColor);
|
||||
ok(oColor instanceof fabric.Color);
|
||||
equal(oColor.toHsl(), 'hsl(262,80%,12%)');
|
||||
equal(oColor.toHex(), '180637');
|
||||
});
|
||||
|
||||
test('fromHsla', function() {
|
||||
ok(typeof fabric.Color.fromHsla == 'function');
|
||||
var originalHsla = 'hsla(262,80%,12%,0.2)';
|
||||
|
|
@ -218,6 +228,17 @@
|
|||
equal(oColor.getAlpha(), 0.2, 'alpha should be set properly');
|
||||
});
|
||||
|
||||
test('fromHsla (with whitespaces)', function() {
|
||||
ok(typeof fabric.Color.fromHsla == 'function');
|
||||
var originalHsla = 'hsla( 262 , 80% , 12% , 0.2 )';
|
||||
var oColor = fabric.Color.fromHsla(originalHsla);
|
||||
ok(oColor);
|
||||
ok(oColor instanceof fabric.Color);
|
||||
equal(oColor.toHsla(), 'hsla(262,80%,12%,0.2)');
|
||||
equal(oColor.toHex(), '180637');
|
||||
equal(oColor.getAlpha(), 0.2, 'alpha should be set properly');
|
||||
});
|
||||
|
||||
test('fromHex', function() {
|
||||
ok(typeof fabric.Color.fromHex == 'function');
|
||||
var originalHex = 'FF5555';
|
||||
|
|
|
|||
Loading…
Reference in a new issue