UNPKG

lib-colors

Version:

Simple node.js library for work with colors

39 lines (38 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Gray = void 0; const alpha_is_set_helper_1 = require("../helpers/alpha_is_set.helper"); const clamp_helper_1 = require("../helpers/clamp.helper"); const rgb_class_1 = require("../rgb/rgb.class"); const color_gray_const_1 = require("./consts/color.gray.const"); const max_gray_const_1 = require("./consts/max.gray.const"); const gray_to_rgb_helper_1 = require("./helpers/gray_to_rgb.helper"); const gray_to_string_helper_1 = require("./helpers/gray_to_string.helper"); class Gray { color = { ...color_gray_const_1.colorGray }; max = max_gray_const_1.maxGray; get g() { return this.color.g; } set g(value) { this.color.g = (0, clamp_helper_1.clamp)(value, 0, this.max.g); } get a() { return this.color.a; } set a(value) { this.color.a = (0, alpha_is_set_helper_1.alphaIsSet)(value) ? (0, clamp_helper_1.clamp)(Number(value), 0, 1) : undefined; } constructor(g, a) { this.g = g; this.a = a; } toString() { return (0, gray_to_string_helper_1.grayToString)(this.color); } rgb() { const { r, g, b, a } = (0, gray_to_rgb_helper_1.grayToRgb)(this.color); return new rgb_class_1.RGB(r, g, b, a); } } exports.Gray = Gray;