mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-10 14:54:42 +00:00
reHSLa and reRGBa ignore case (#5017)
* fabric.Color.reRGBa regex ignore case ignore case for rgba * fabric.Color.reHSLa ignore case ignore case for hsla * test case RGBA / HSLA added test case for RGB/RGBA and HSL/HSLA (uppercase) * Update color.js
This commit is contained in:
parent
4af1c0d6b5
commit
87d67eb04c
2 changed files with 42 additions and 2 deletions
|
|
@ -280,7 +280,7 @@
|
|||
* @memberOf fabric.Color
|
||||
*/
|
||||
// eslint-disable-next-line max-len
|
||||
fabric.Color.reRGBa = /^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/;
|
||||
fabric.Color.reRGBa = /^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/i;
|
||||
|
||||
/**
|
||||
* Regex matching color in HSL or HSLA formats (ex: hsl(200, 80%, 10%), hsla(300, 50%, 80%, 0.5), hsla( 300 , 50% , 80% , 0.5 ))
|
||||
|
|
@ -288,7 +288,7 @@
|
|||
* @field
|
||||
* @memberOf fabric.Color
|
||||
*/
|
||||
fabric.Color.reHSLa = /^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/;
|
||||
fabric.Color.reHSLa = /^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/i;
|
||||
|
||||
/**
|
||||
* Regex matching color in HEX format (ex: #FF5544CC, #FF5555, 010155, aff)
|
||||
|
|
|
|||
|
|
@ -173,6 +173,25 @@
|
|||
assert.equal(oColor.toHex(), 'FFFFFF');
|
||||
});
|
||||
|
||||
QUnit.test('fromRgb (uppercase)', function(assert) {
|
||||
assert.ok(typeof fabric.Color.fromRgb === 'function');
|
||||
var originalRgb = 'RGB(255,255,255)';
|
||||
var oColor = fabric.Color.fromRgb(originalRgb);
|
||||
assert.ok(oColor);
|
||||
assert.ok(oColor instanceof fabric.Color);
|
||||
assert.equal(oColor.toHex(), 'FFFFFF');
|
||||
});
|
||||
|
||||
QUnit.test('fromRgba (uppercase)', function(assert) {
|
||||
assert.ok(typeof fabric.Color.fromRgba === 'function');
|
||||
var originalRgba = 'RGBA(255,255,255,0.5)';
|
||||
var oColor = fabric.Color.fromRgba(originalRgba);
|
||||
assert.ok(oColor);
|
||||
assert.ok(oColor instanceof fabric.Color);
|
||||
assert.equal(oColor.toHex(), 'FFFFFF');
|
||||
assert.equal(oColor.getAlpha(), 0.5, 'alpha should be set properly');
|
||||
});
|
||||
|
||||
QUnit.test('fromRgba', function(assert) {
|
||||
assert.ok(typeof fabric.Color.fromRgba === 'function');
|
||||
var originalRgba = 'rgba(255,255,255,0.5)';
|
||||
|
|
@ -253,6 +272,27 @@
|
|||
assert.equal(oColor.toHex(), '180637');
|
||||
});
|
||||
|
||||
QUnit.test('fromHsl (uppercase)', function(assert) {
|
||||
assert.ok(typeof fabric.Color.fromHsl === 'function');
|
||||
var originalHsl = 'HSL(270,50%,40%)';
|
||||
var oColor = fabric.Color.fromHsl(originalHsl);
|
||||
assert.ok(oColor);
|
||||
assert.ok(oColor instanceof fabric.Color);
|
||||
assert.equal(oColor.toHex(), '663399');
|
||||
assert.equal(oColor.toRgba(), 'rgba(102,51,153,1)');
|
||||
});
|
||||
|
||||
QUnit.test('fromHsla (uppercase)', function(assert) {
|
||||
assert.ok(typeof fabric.Color.fromHsla === 'function');
|
||||
var originalHsla = 'HSLA(108,50%,50%,0.7)';
|
||||
var oColor = fabric.Color.fromHsla(originalHsla);
|
||||
assert.ok(oColor);
|
||||
assert.ok(oColor instanceof fabric.Color);
|
||||
assert.equal(oColor.toHex(), '59BF40');
|
||||
assert.equal(oColor.toRgba(), 'rgba(89,191,64,0.7)');
|
||||
assert.equal(oColor.getAlpha(), 0.7, 'alpha should be set properly');
|
||||
});
|
||||
|
||||
QUnit.test('fromHsla', function(assert) {
|
||||
assert.ok(typeof fabric.Color.fromHsla === 'function');
|
||||
var originalHsla = 'hsla(262,80%,12%,0.2)';
|
||||
|
|
|
|||
Loading…
Reference in a new issue