UNPKG

color-theme-generator

Version:

Generates random color themes that are based in color theory.

86 lines (85 loc) 4.8 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 _ColorStyles_instances, _ColorStyles_validator, _ColorStyles_validateColor; import { Style } from './Style.js'; import { Validator } from './Validator.js'; export class ColorStyles { constructor() { _ColorStyles_instances.add(this); _ColorStyles_validator.set(this, void 0); __classPrivateFieldSet(this, _ColorStyles_validator, new Validator(), "f"); } /** * Creates a declaration for the CSS property color. * * @param color - The color to use as value for the property color. * @returns An object containing the declaration. * @throws Error if the argument does not pass the validation. */ getColorDeclaration(color) { __classPrivateFieldGet(this, _ColorStyles_instances, "m", _ColorStyles_validateColor).call(this, color); return new Style('color', color.hsl); } /** * Creates a declaration for the CSS property background-color. * * @param color - The color to use as value for the property background-color. * @returns An object containing the declaration. * @throws Error if the argument does not pass the validation. */ getBackgroundColorDeclaration(color) { __classPrivateFieldGet(this, _ColorStyles_instances, "m", _ColorStyles_validateColor).call(this, color); return new Style('background-color', color.hsl); } /** * Creates a declaration for the CSS property border. * The declaration uses border shorthand to set border-color and border-style. * * @param color - The color to use as value for the property border-color. * @param borderStyle - The value of the property border-style. * @returns An object containing the declaration. * @throws Error if the argument does not pass the validation. */ getBorderDeclaration(color, borderStyle) { __classPrivateFieldGet(this, _ColorStyles_instances, "m", _ColorStyles_validateColor).call(this, color); return new Style('border', `${borderStyle} ${color.hsl}`); } /** * Creates a declaration for the CSS property outline. * The declaration uses outline shorthand to set outline-color and outline-style. * * @param color - The color to use as value for the property outline-color. * @param outlineStyle - The value of the property outline-style. * @returns An object containing the declaration. * @throws Error if the argument does not pass the validation. */ getOutlineDeclaration(color, outlineStyle) { __classPrivateFieldGet(this, _ColorStyles_instances, "m", _ColorStyles_validateColor).call(this, color); return new Style('outline', `${outlineStyle} ${color.hsl}`); } /** * Creates a declaration for the CSS property text-decoration. * The declaration uses text-decoration shorthand to set text-decoration-line and text-decoration-color. * * @param color - The color to use as the value for the property text-decoration-color. * @param textDecorationLine - The value of the property text-decoration-line. * @returns An object containing the declaration. * @throws Error if the argument does not pass the validation. */ getTextDecorationDeclaration(color, textDecorationLine) { __classPrivateFieldGet(this, _ColorStyles_instances, "m", _ColorStyles_validateColor).call(this, color); return new Style('text-decoration', `${textDecorationLine} ${color.hsl}`); } } _ColorStyles_validator = new WeakMap(), _ColorStyles_instances = new WeakSet(), _ColorStyles_validateColor = function _ColorStyles_validateColor(color) { __classPrivateFieldGet(this, _ColorStyles_validator, "f").validateColorArgument(color); };