UNPKG

lib-colors

Version:

Simple node.js library for work with colors

53 lines (52 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HSL = 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_hsl_const_1 = require("./consts/color.hsl.const"); const max_hsl_const_1 = require("./consts/max.hsl.const"); const hsl_to_rgb_helper_1 = require("./helpers/hsl_to_rgb.helper"); const hsl_to_string_helper_1 = require("./helpers/hsl_to_string.helper"); class HSL { color = { ...color_hsl_const_1.colorHSL }; max = max_hsl_const_1.maxHSL; get h() { return this.color.h; } set h(value) { this.color.h = Math.round(value % this.max.h); } get s() { return this.color.s; } set s(value) { this.color.s = (0, clamp_helper_1.clamp)(value, 0, this.max.s); } 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, alpha_is_set_helper_1.alphaIsSet)(value) ? (0, clamp_helper_1.clamp)(Number(value), 0, 1) : undefined; } constructor(h, s, l, a) { this.h = h; this.s = s; this.l = l; this.a = a; } toString() { return (0, hsl_to_string_helper_1.hslToString)(this.color); } rgb() { const { r, g, b, a } = (0, hsl_to_rgb_helper_1.hslToRgb)(this.color); return new rgb_class_1.RGB(r, g, b, a); } } exports.HSL = HSL;