UNPKG

lib-colors

Version:

Simple node.js library for work with colors

61 lines (60 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LAB = void 0; const cmyk_class_1 = require("../cmyk/cmyk.class"); 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_lab_const_1 = require("./consts/color.lab.const"); const max_lab_const_1 = require("./consts/max.lab.const"); const lab_to_cmyk_helper_1 = require("./helpers/lab_to_cmyk.helper"); const lab_to_rgb_helper_1 = require("./helpers/lab_to_rgb.helper"); const lab_to_string_helper_1 = require("./helpers/lab_to_string.helper"); class LAB { color = { ...color_lab_const_1.colorLAB }; max = max_lab_const_1.maxLAB; get l() { return this.color.l; } set l(value) { this.color.l = (0, clamp_helper_1.clamp)(value, 0, this.max.l); } get a() { return this.color.a; } set a(value) { this.color.a = (0, clamp_helper_1.clamp)(value, -128, this.max.a); } get b() { return this.color.b; } set b(value) { this.color.b = (0, clamp_helper_1.clamp)(value, -128, this.max.b); } get alpha() { return this.color.alpha; } set alpha(value) { this.color.alpha = (0, alpha_is_set_helper_1.alphaIsSet)(value) ? (0, clamp_helper_1.clamp)(Number(value), 0, 1) : undefined; } constructor(l, a, b, alpha) { this.l = l; this.a = a; this.b = b; this.alpha = alpha; } toString() { return (0, lab_to_string_helper_1.labToString)(this.color); } cmyk() { const { c, m, y, k, a } = (0, lab_to_cmyk_helper_1.labToCmyk)(this.color); return new cmyk_class_1.CMYK(c, m, y, k, a); } rgb() { const { r, g, b, a } = (0, lab_to_rgb_helper_1.labToRgb)(this.color); return new rgb_class_1.RGB(r, g, b, a); } } exports.LAB = LAB;