UNPKG

color-theme-generator

Version:

Generates random color themes that are based in color theory.

45 lines (44 loc) 2.76 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 _AnalogousThemeFactory_instances, _AnalogousThemeFactory_validateArgument, _AnalogousThemeFactory_calculateHueOfMainColor; import { ArgumentLimits } from '../enums/ArgumentLimits.js'; import { ColorThemes } from '../enums/ColorThemes.js'; import { ColorThemeData } from './ColorThemeData.js'; import { MultiHueColorThemeFactory } from './MultiHueColorThemeFactory.js'; import { ValidationObject } from './ValidationObject.js'; export class AnalogousThemeFactory extends MultiHueColorThemeFactory { constructor() { super(ArgumentLimits.AnalogousMin); _AnalogousThemeFactory_instances.add(this); this.setCalculateHueFunction(__classPrivateFieldGet(this, _AnalogousThemeFactory_instances, "m", _AnalogousThemeFactory_calculateHueOfMainColor)); } /** * Generates an analogous 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, _AnalogousThemeFactory_instances, "m", _AnalogousThemeFactory_validateArgument).call(this, numberOfColors); const colors = this.getColors(numberOfColors); const data = new ColorThemeData(ColorThemes.Analogous, colors); return data; } } _AnalogousThemeFactory_instances = new WeakSet(), _AnalogousThemeFactory_validateArgument = function _AnalogousThemeFactory_validateArgument(numberOfColors) { const validationValues = new ValidationObject(ArgumentLimits.AnalogousMax, ArgumentLimits.AnalogousMin, numberOfColors); this.validator.validateNumberArgumentWithMaxAndMin(validationValues); }, _AnalogousThemeFactory_calculateHueOfMainColor = function _AnalogousThemeFactory_calculateHueOfMainColor(hueIncrementFactor) { const numberOfHues = 360; const hueIncrement = 30; // 30 because each section of the colorwheel is 30 degrees. if (((this.hue + (hueIncrement * hueIncrementFactor)) % numberOfHues) === 0) { return this.hue + (hueIncrement * hueIncrementFactor); } else { return (this.hue + (hueIncrement * hueIncrementFactor)) % numberOfHues; } };