UNPKG

color-theme-generator

Version:

Generates random color themes that are based in color theory.

66 lines (65 loc) 4.85 kB
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _Color_instances, _Color_validator, _Color_hue, _Color_saturation, _Color_lightness, _Color_hsl, _Color_validateHue, _Color_setHue, _Color_validateSaturation, _Color_setSaturation, _Color_validateLightness, _Color_setLightness, _Color_setHSL, _Color_generateHSL; import { ArgumentLimits } from '../enums/ArgumentLimits.js'; import { ValidationObject } from './ValidationObject.js'; import { Validator } from './Validator.js'; export class Color { constructor(hue, saturation, lightness) { _Color_instances.add(this); _Color_validator.set(this, void 0); _Color_hue.set(this, void 0); _Color_saturation.set(this, void 0); _Color_lightness.set(this, void 0); _Color_hsl.set(this, void 0); __classPrivateFieldSet(this, _Color_validator, new Validator(), "f"); __classPrivateFieldGet(this, _Color_instances, "m", _Color_validateHue).call(this, hue); __classPrivateFieldGet(this, _Color_instances, "m", _Color_setHue).call(this, hue); __classPrivateFieldGet(this, _Color_instances, "m", _Color_validateSaturation).call(this, saturation); __classPrivateFieldGet(this, _Color_instances, "m", _Color_setSaturation).call(this, saturation); __classPrivateFieldGet(this, _Color_instances, "m", _Color_validateLightness).call(this, lightness); __classPrivateFieldGet(this, _Color_instances, "m", _Color_setLightness).call(this, lightness); __classPrivateFieldGet(this, _Color_instances, "m", _Color_setHSL).call(this, __classPrivateFieldGet(this, _Color_instances, "m", _Color_generateHSL).call(this)); } get hue() { return __classPrivateFieldGet(this, _Color_hue, "f"); } get saturation() { return __classPrivateFieldGet(this, _Color_saturation, "f"); } get lightness() { return __classPrivateFieldGet(this, _Color_lightness, "f"); } get hsl() { return __classPrivateFieldGet(this, _Color_hsl, "f"); } } _Color_validator = new WeakMap(), _Color_hue = new WeakMap(), _Color_saturation = new WeakMap(), _Color_lightness = new WeakMap(), _Color_hsl = new WeakMap(), _Color_instances = new WeakSet(), _Color_validateHue = function _Color_validateHue(value) { const validationValues = new ValidationObject(ArgumentLimits.HueMax, ArgumentLimits.HueMin, value); __classPrivateFieldGet(this, _Color_validator, "f").validateNumberArgumentWithMaxAndMin(validationValues); }, _Color_setHue = function _Color_setHue(value) { __classPrivateFieldSet(this, _Color_hue, value, "f"); }, _Color_validateSaturation = function _Color_validateSaturation(value) { const validationValues = new ValidationObject(ArgumentLimits.SaturationMax, ArgumentLimits.SaturationMin, value); __classPrivateFieldGet(this, _Color_validator, "f").validateNumberArgumentWithMaxAndMin(validationValues); }, _Color_setSaturation = function _Color_setSaturation(value) { __classPrivateFieldSet(this, _Color_saturation, value, "f"); }, _Color_validateLightness = function _Color_validateLightness(value) { const validationValues = new ValidationObject(ArgumentLimits.LightnessMax, ArgumentLimits.LightnessMin, value); __classPrivateFieldGet(this, _Color_validator, "f").validateNumberArgumentWithMaxAndMin(validationValues); }, _Color_setLightness = function _Color_setLightness(value) { __classPrivateFieldSet(this, _Color_lightness, value, "f"); }, _Color_setHSL = function _Color_setHSL(value) { __classPrivateFieldSet(this, _Color_hsl, value, "f"); }, _Color_generateHSL = function _Color_generateHSL() { return `hsl(${__classPrivateFieldGet(this, _Color_hue, "f")}, ${__classPrivateFieldGet(this, _Color_saturation, "f")}%, ${__classPrivateFieldGet(this, _Color_lightness, "f")}%)`; };