UNPKG

color-theme-generator

Version:

Generates random color themes that are based in color theory.

45 lines (44 loc) 2.81 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 _ComplementaryThemeFactory_instances, _ComplementaryThemeFactory_validateArgument, _ComplementaryThemeFactory_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 ComplementaryThemeFactory extends MultiHueColorThemeFactory { constructor() { super(ArgumentLimits.ComplementaryMin); _ComplementaryThemeFactory_instances.add(this); this.setCalculateHueFunction(__classPrivateFieldGet(this, _ComplementaryThemeFactory_instances, "m", _ComplementaryThemeFactory_calculateHueOfMainColor)); } /** * Generates a complementary color theme. * * @param numberOfColors - The number of colors to include ranging from 2 to 4. * @returns An object containing data about the generated color theme. * @throws Error if the arguments does not pass the validation. */ getColorTheme(numberOfColors) { __classPrivateFieldGet(this, _ComplementaryThemeFactory_instances, "m", _ComplementaryThemeFactory_validateArgument).call(this, numberOfColors); const colors = this.getColors(numberOfColors); const data = new ColorThemeData(ColorThemes.Complementary, colors); return data; } } _ComplementaryThemeFactory_instances = new WeakSet(), _ComplementaryThemeFactory_validateArgument = function _ComplementaryThemeFactory_validateArgument(numberOfColors) { const validationValues = new ValidationObject(ArgumentLimits.ComplementaryMax, ArgumentLimits.ComplementaryMin, numberOfColors); this.validator.validateNumberArgumentWithMaxAndMin(validationValues); }, _ComplementaryThemeFactory_calculateHueOfMainColor = function _ComplementaryThemeFactory_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; } };