|
@@ -84,26 +84,7 @@
|
|
|
},
|
|
|
|
|
|
handleConfirm() {
|
|
|
- const valid = this.showAlpha ? this.validRGBA(this.customInput) : this.validRGBHex(this.customInput);
|
|
|
- if (valid) {
|
|
|
- this.color.fromString(this.customInput);
|
|
|
- } else {
|
|
|
- this.customInput = this.currentColor;
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- validRGBHex(color) {
|
|
|
- return /^#[A-Fa-f0-9]{6}$/.test(color);
|
|
|
- },
|
|
|
-
|
|
|
- validRGBA(color) {
|
|
|
- const matches = color.match(/^rgba\((\d+), ?(\d+), ?(\d+), ?([.0-9]+)\)$/);
|
|
|
- if (!matches) return false;
|
|
|
- const list = matches.map(v => parseInt(v, 10)).slice(1);
|
|
|
- if (list.some(v => isNaN(v))) return false;
|
|
|
- const [r, g, b, a] = list;
|
|
|
- if ([r, g, b].some(v => v < 0 || v > 255) || a < 0 || a > 1) return false;
|
|
|
- return true;
|
|
|
+ this.color.fromString(this.customInput);
|
|
|
}
|
|
|
},
|
|
|
|