@thi.ng/color
Version:
Array-based color types, CSS parsing, conversions, transformations, declarative theme generation, gradients, presets
72 lines • 2.91 kB
TypeScript
import type { Without } from "@thi.ng/api";
import type { ColorRange, ColorRangeOpts, ColorRangePreset, ColorThemePart, ColorThemePartTuple } from "./api/ranges.js";
import { type LCH } from "./lch/lch.js";
/**
* Preset {@link ColorRange}s for use with {@link colorsFromRange},
* {@link colorsFromTheme} etc.
*/
export declare const COLOR_RANGES: Record<ColorRangePreset, ColorRange>;
/**
* Takes a {@link ColorRange} and options to produce a single new result color.
* This color is randomized within the channel limits of the given `range`
* descriptor. If a `base` color is provided (via {@link ColorRangeOpts}), its
* hue is used as bias and the `variance` option defines the max. -/+ normalized
* hue shift of the result color.
*
* @remarks
* If the base color is a shade of gray (incl. black & white), the result will
* be another gray and is based on the range's black and white point sub-ranges.
*
* The alpha channel of the result color will only be randomized (based on
* `range.a` settings) iff no `base` color was provided. If `base` is given, the
* result will used the same alpha.
*
* A custom PRNG can be defined via the `rnd` option (default: `Math.random`).
*
* @param range -
* @param opts -
*/
export declare const colorFromRange: (range: ColorRange | keyof typeof COLOR_RANGES, opts?: Partial<Pick<ColorRangeOpts, "base" | "variance" | "eps" | "rnd">>) => LCH;
/**
* Generator version of {@link colorFromRange}, by default yielding an infinite
* sequence of random colors based on given range, base color (optional) and
* other opts. Use `num` option to limit number of results.
*
* @param range -
* @param opts -
*/
export declare function colorsFromRange(range: ColorRange | keyof typeof COLOR_RANGES, opts?: Partial<ColorRangeOpts>): Generator<LCH, void, unknown>;
/**
* Probabilistic color theme generator. Yield randomized colors based on given
* weighted set of theme part specs.
*
* @remarks
* Each theme part is a tuple of either:
*
* - `[range, color, weight?]`
* - `[range, weight?]`
* - `[color, weight?]`
*
* `range` can be either a {@link ColorRange} or the name of a
* {@link COLOR_RANGES} preset. Likewise, `color` can be a color instance or CSS
* color name. The `weight` of each part defines the relative
* importance/probability of this theme part, compared to others. Default weight
* is 1.0.
*
* @example
* ```ts tangle:../export/colors-from-theme.ts
* import { colorsFromTheme } from "@thi.ng/color";
*
* console.log(
* [...colorsFromTheme(
* [["cool", "aliceblue"], ["bright", "orange", 0.25], ["hotpink", 0.1]],
* { num: 10 }
* )]
* );
* ```
*
* @param parts -
* @param opts -
*/
export declare function colorsFromTheme(parts: (ColorThemePart | ColorThemePartTuple)[], opts?: Partial<Without<ColorRangeOpts, "base">>): Generator<LCH, void, unknown>;
//# sourceMappingURL=color-range.d.ts.map