@ec0lint/plugin-css
Version:
ec0lint plugin that provides rules to verify CSS definition objects
64 lines (63 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbsColor = void 0;
class AbsColor {
toHex(format) {
if (!this.isComplete()) {
return null;
}
const hex = this.toHexImpl();
if (hex == null) {
return null;
}
return format === "RGB"
? toHexRGB(hex)
: format === "RRGGBB"
? toHexRRGGBB(hex)
: hex;
}
toName() {
var _a;
if (!this.isComplete()) {
return null;
}
return (_a = this.toNameImpl()) !== null && _a !== void 0 ? _a : null;
}
toHexImpl() {
var _a;
return (_a = this.getColord()) === null || _a === void 0 ? void 0 : _a.toHex();
}
toNameImpl() {
var _a;
return (_a = this.getColord()) === null || _a === void 0 ? void 0 : _a.toName();
}
getColord() {
return this.colordCache !== undefined
? this.colordCache
: (this.colordCache = this.newColord());
}
}
exports.AbsColor = AbsColor;
function toHexRGB(hex) {
if (hex.length === 7 || hex.length === 9) {
const [, r1, r2, g1, g2, b1, b2, a1, a2] = hex;
if (equalsIgnoreCase(r1, r2) &&
equalsIgnoreCase(g1, g2) &&
equalsIgnoreCase(b1, b2) &&
equalsIgnoreCase(a1, a2)) {
return `#${r1}${g1}${b1}${a1 !== null && a1 !== void 0 ? a1 : ""}`;
}
return null;
}
return hex;
}
function toHexRRGGBB(hex) {
if (hex.length === 4 || hex.length === 5) {
const [, r, g, b, a] = hex;
return `#${r}${r}${g}${g}${b}${b}${a == null ? "" : `${a}${a}`}`;
}
return hex;
}
function equalsIgnoreCase(s1, s2) {
return (s1 === null || s1 === void 0 ? void 0 : s1.toLowerCase()) === (s2 === null || s2 === void 0 ? void 0 : s2.toLowerCase());
}