UNPKG

color-theme-generator

Version:

Generates random color themes that are based in color theory.

45 lines (44 loc) 2.7 kB
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 _TriadicThemeFactory_instances, _TriadicThemeFactory_validateArgument, _TriadicThemeFactory_calculateHueOfMainColor; import { ArgumentLimits } from '../enums/ArgumentLimits.js'; import { ColorThemeData } from './ColorThemeData.js'; import { ColorThemes } from '../enums/ColorThemes.js'; import { MultiHueColorThemeFactory } from './MultiHueColorThemeFactory.js'; import { ValidationObject } from './ValidationObject.js'; export class TriadicThemeFactory extends MultiHueColorThemeFactory { constructor() { super(ArgumentLimits.TriadicMin); _TriadicThemeFactory_instances.add(this); this.setCalculateHueFunction(__classPrivateFieldGet(this, _TriadicThemeFactory_instances, "m", _TriadicThemeFactory_calculateHueOfMainColor)); } /** * Generates an triadic color theme. * * @param numberOfColors - The number of colors to include ranging from 3 to 5. * @returns An object containing data about the generated color theme. * @throws Error if the arguments does not pass the validation. */ getColorTheme(numberOfColors) { __classPrivateFieldGet(this, _TriadicThemeFactory_instances, "m", _TriadicThemeFactory_validateArgument).call(this, numberOfColors); const colors = this.getColors(numberOfColors); const data = new ColorThemeData(ColorThemes.Triadic, colors); return data; } } _TriadicThemeFactory_instances = new WeakSet(), _TriadicThemeFactory_validateArgument = function _TriadicThemeFactory_validateArgument(numberOfColors) { const validationValues = new ValidationObject(ArgumentLimits.TriadicMax, ArgumentLimits.TriadicMin, numberOfColors); this.validator.validateNumberArgumentWithMaxAndMin(validationValues); }, _TriadicThemeFactory_calculateHueOfMainColor = function _TriadicThemeFactory_calculateHueOfMainColor(hueIncrementFactor) { const numberOfHues = 360; const hueIncrement = numberOfHues / this.numberOfMainColors; if (((this.hue + (hueIncrement * hueIncrementFactor)) % numberOfHues) === 0) { return this.hue + (hueIncrement * hueIncrementFactor); } else { return (this.hue + (hueIncrement * hueIncrementFactor)) % numberOfHues; } };