UNPKG

@promptbook/google

Version:

Promptbook: Turn your company's scattered knowledge into AI ready books

159 lines (158 loc) 5.59 kB
import type { string_color, string_url_image } from '../../types/typeAliases'; import type { WithTake } from '../take/interfaces/ITakeChain'; import { CSS_COLORS } from './css-colors'; /** * Color object represents an RGB color with alpha channel * * Note: There is no fromObject/toObject because the most logical way to serialize color is as a hex string (#009edd) * * @public exported from `@promptbook/color` */ export declare class Color { readonly red: number; readonly green: number; readonly blue: number; readonly alpha: number; /** * Creates a new Color instance from miscellaneous formats * - It can receive Color instance and just return the same instance * - It can receive color in string format for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)` * * Note: This is not including fromImage because detecting color from an image is heavy task which requires async stuff and we cannot safely determine with overloading if return value will be a promise * * @param color * @returns Color object */ static from(color: string_color | Color, _isSingleValue?: boolean): WithTake<Color>; /** * Creates a new Color instance from miscellaneous formats * It just does not throw error when it fails, it returns PROMPTBOOK_COLOR instead * * @param color * @returns Color object */ static fromSafe(color: string_color | Color): WithTake<Color>; /** * Creates a new Color instance from miscellaneous string formats * * @param color as a string for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)`, `red`, `darkgrey`,... * @returns Color object */ static fromString(color: string_color): WithTake<Color>; /** * Gets common color * * @param key as a css string like `midnightblue` * @returns Color object */ static get(key: keyof typeof CSS_COLORS): WithTake<Color>; /** * Creates a new Color instance from average color of given image * * @param image as a source for example `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdjYJh39z8ABJgCe/ZvAS4AAAAASUVORK5CYII=` * @returns Color object */ static fromImage(image: string_url_image): Promise<Color>; /** * Creates a new Color instance from color in hex format * * @param color in hex for example `#009edd`, `009edd`, `#555`,... * @returns Color object */ static fromHex(hex: string_color): WithTake<Color>; /** * Creates a new Color instance from color in hsl format * * @param color as a hsl for example `hsl(197.1,100%,43.3%)` * @returns Color object */ static fromHsl(hsl: string_color): WithTake<Color>; /** * Creates a new Color instance from color in rgb format * * @param color as a rgb for example `rgb(0,158,221)`, `rgb(0%,62%,86.7%)` * @returns Color object */ static fromRgbString(rgb: string_color): WithTake<Color>; /** * Creates a new Color instance from color in rbga format * * @param color as a rgba for example `rgba(0,158,221,0.5)`, `rgb(0%,62%,86.7%,50%)` * @returns Color object */ static fromRgbaString(rgba: string_color): WithTake<Color>; /** * Creates a new Color for color channels values * * @param red number from 0 to 255 * @param green number from 0 to 255 * @param blue number from 0 to 255 * @param alpha number from 0 (transparent) to 255 (opaque = default) * @returns Color object */ static fromValues(red: number, green: number, blue: number, alpha?: number): WithTake<Color>; /** * Checks if the given value is a valid Color object. * * @param {unknown} value - The value to check. * @return {value is WithTake<Color>} Returns true if the value is a valid Color object, false otherwise. */ static isColor(value: unknown): value is WithTake<Color>; /** * Checks if the given value is a valid hex color string * * @param value - value to check * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.) */ static isHexColorString(value: unknown): value is string_color; /** * Creates new Color object * * Note: Consider using one of static methods like `from` or `fromString` * * @param red number from 0 to 255 * @param green number from 0 to 255 * @param blue number from 0 to 255 * @param alpha number from 0 (transparent) to 255 (opaque) */ private constructor(); /** * Shortcut for `red` property * Number from 0 to 255 * @alias red */ get r(): number; /** * Shortcut for `green` property * Number from 0 to 255 * @alias green */ get g(): number; /** * Shortcut for `blue` property * Number from 0 to 255 * @alias blue */ get b(): number; /** * Shortcut for `alpha` property * Number from 0 (transparent) to 255 (opaque) * @alias alpha */ get a(): number; /** * Shortcut for `alpha` property * Number from 0 (transparent) to 255 (opaque) * @alias alpha */ get opacity(): number; /** * Shortcut for 1-`alpha` property */ get transparency(): number; clone(): WithTake<Color>; toString(): string_color; toHex(): string_color; toRgb(): string_color; toHsl(): string_color; }