Fix: crashes when applying css

This commit is contained in:
vakrilov
2015-07-27 16:29:24 +03:00
parent 6e58c5242e
commit 4a6c841f0e
4 changed files with 30 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ import types = require("utils/types");
import knownColors = require("color/known-colors");
var AMP = "#";
var HEX_REGEX = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i;
export class Color implements definition.Color {
private _a: number;
@@ -107,6 +108,18 @@ export class Color implements definition.Color {
return value1.equals(value2);
}
public static isValid(value: string): boolean {
if (!types.isString(value)) {
return false;
}
if (knownColors.isKnownName(value)) {
return true;
}
return HEX_REGEX.test(value);
}
private _buildHex(): string {
return AMP + this._componentToHex(this._a) + this._componentToHex(this._r) + this._componentToHex(this._g) + this._componentToHex(this._b);
}