UNPKG

color-theme-generator

Version:

Generates random color themes that are based in color theory.

86 lines (85 loc) 5.47 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 _ColorThemeData_instances, _ColorThemeData_validator, _ColorThemeData_colorTheme, _ColorThemeData_colorsInTheme, _ColorThemeData_numberOfColorsInTheme, _ColorThemeData_validateColorTheme, _ColorThemeData_setColorTheme, _ColorThemeData_validateColorsInTheme, _ColorThemeData_setColorsInTheme, _ColorThemeData_setNumberOfColorsInTheme, _ColorThemeData_copyColor; import { Color } from './Color.js'; import { Validator } from './Validator.js'; export class ColorThemeData { constructor(colorTheme, colors) { _ColorThemeData_instances.add(this); _ColorThemeData_validator.set(this, void 0); /** * The name of the color theme. */ _ColorThemeData_colorTheme.set(this, void 0); _ColorThemeData_colorsInTheme.set(this, void 0); _ColorThemeData_numberOfColorsInTheme.set(this, void 0); __classPrivateFieldSet(this, _ColorThemeData_validator, new Validator(), "f"); __classPrivateFieldGet(this, _ColorThemeData_instances, "m", _ColorThemeData_validateColorTheme).call(this, colorTheme); __classPrivateFieldGet(this, _ColorThemeData_instances, "m", _ColorThemeData_setColorTheme).call(this, colorTheme); __classPrivateFieldGet(this, _ColorThemeData_instances, "m", _ColorThemeData_validateColorsInTheme).call(this, colors); __classPrivateFieldGet(this, _ColorThemeData_instances, "m", _ColorThemeData_setColorsInTheme).call(this, colors); __classPrivateFieldGet(this, _ColorThemeData_instances, "m", _ColorThemeData_setNumberOfColorsInTheme).call(this); } /** * The colors in the theme. * * @returns An array of the colors. */ get colorsInTheme() { // Copies the colors since they are refrence types. const copyOfColors = []; for (const color of __classPrivateFieldGet(this, _ColorThemeData_colorsInTheme, "f")) { copyOfColors.push(__classPrivateFieldGet(this, _ColorThemeData_instances, "m", _ColorThemeData_copyColor).call(this, color)); } return copyOfColors; } /** * The name of the theme. */ get colorTheme() { return __classPrivateFieldGet(this, _ColorThemeData_colorTheme, "f"); } get numberOfColorsInTheme() { return __classPrivateFieldGet(this, _ColorThemeData_numberOfColorsInTheme, "f"); } /** * Sorts the colors in the theme by hue in ascending order. */ sortColorsByHue() { __classPrivateFieldGet(this, _ColorThemeData_colorsInTheme, "f").sort((a, b) => a.hue - b.hue); } /** * Sorts the colors in the theme by saturation in ascending order. */ sortColorsBySaturation() { __classPrivateFieldGet(this, _ColorThemeData_colorsInTheme, "f").sort((a, b) => a.saturation - b.saturation); } /** * Sorts the colors in the theme by lightness in ascending order. */ sortColorsByLightness() { __classPrivateFieldGet(this, _ColorThemeData_colorsInTheme, "f").sort((a, b) => a.lightness - b.lightness); } } _ColorThemeData_validator = new WeakMap(), _ColorThemeData_colorTheme = new WeakMap(), _ColorThemeData_colorsInTheme = new WeakMap(), _ColorThemeData_numberOfColorsInTheme = new WeakMap(), _ColorThemeData_instances = new WeakSet(), _ColorThemeData_validateColorTheme = function _ColorThemeData_validateColorTheme(theme) { __classPrivateFieldGet(this, _ColorThemeData_validator, "f").validateColorThemesArgument(theme); }, _ColorThemeData_setColorTheme = function _ColorThemeData_setColorTheme(theme) { __classPrivateFieldSet(this, _ColorThemeData_colorTheme, theme, "f"); }, _ColorThemeData_validateColorsInTheme = function _ColorThemeData_validateColorsInTheme(colors) { __classPrivateFieldGet(this, _ColorThemeData_validator, "f").validateColorArrayArgument(colors); }, _ColorThemeData_setColorsInTheme = function _ColorThemeData_setColorsInTheme(colors) { __classPrivateFieldSet(this, _ColorThemeData_colorsInTheme, colors, "f"); }, _ColorThemeData_setNumberOfColorsInTheme = function _ColorThemeData_setNumberOfColorsInTheme() { __classPrivateFieldSet(this, _ColorThemeData_numberOfColorsInTheme, __classPrivateFieldGet(this, _ColorThemeData_colorsInTheme, "f").length, "f"); }, _ColorThemeData_copyColor = function _ColorThemeData_copyColor(color) { return new Color(color.hue, color.saturation, color.lightness); };