UNPKG

lib-colors

Version:

Simple node.js library for work with colors

70 lines (69 loc) 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CMYK = void 0; const alpha_is_set_helper_1 = require("../helpers/alpha_is_set.helper"); const clamp_helper_1 = require("../helpers/clamp.helper"); const lab_class_1 = require("../lab/lab.class"); const rgb_class_1 = require("../rgb/rgb.class"); const color_cmyk_const_1 = require("./consts/color.cmyk.const"); const max_cmyk_const_1 = require("./consts/max.cmyk.const"); const cmyk_to_lab_helper_1 = require("./helpers/cmyk_to_lab.helper"); const cmyk_to_rgb_helper_1 = require("./helpers/cmyk_to_rgb.helper"); const cmyk_to_string_helper_1 = require("./helpers/cmyk_to_string.helper"); class CMYK { color = { ...color_cmyk_const_1.colorCMYK }; max = max_cmyk_const_1.maxCMYK; get c() { return this.color.c; } set c(value) { this.color.c = (0, clamp_helper_1.clamp)(value, 0, this.max.c); } get m() { return this.color.m; } set m(value) { this.color.m = (0, clamp_helper_1.clamp)(value, 0, this.max.m); } get y() { return this.color.y; } set y(value) { this.color.y = (0, clamp_helper_1.clamp)(value, 0, this.max.y); } get k() { return this.color.k; } set k(value) { this.color.k = (0, clamp_helper_1.clamp)(value, 0, this.max.k); } 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(c, m, y, k, a) { this.c = c; this.m = m; this.y = y; this.k = k; this.a = a; } sum() { const { c, m, y, k } = this.color; return c + m + y + k; } toString() { return (0, cmyk_to_string_helper_1.cmykToString)(this.color); } lab() { const { l, a, b, alpha } = (0, cmyk_to_lab_helper_1.cmykToLab)(this.color); return new lab_class_1.LAB(l, a, b, alpha); } rgb() { const { r, g, b, a } = (0, cmyk_to_rgb_helper_1.cmykToRgb)(this.color); return new rgb_class_1.RGB(r, g, b, a); } } exports.CMYK = CMYK;