Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

RgbColor

import { RgbColor } from "https://raw.githubusercontent.com/i-xi-dev/color.es/5.2.10/mod.ts";

A color represented by red, green, and blue channels

class RgbColor {
private constructor(
a: Alpha,
);
get space(): ColorSpace;
get red(): Rgb.Component;
get green(): Rgb.Component;
get blue(): Rgb.Component;
get alpha(): Alpha;
get hue(): Hue;
get saturation(): Hsl.Saturation;
get lightness(): Hsl.Lightness;
get whiteness(): Hwb.Whiteness;
get blackness(): Hwb.Blackness;
 
complementary(): RgbColor;
equalsBytes(other: RgbColor, options?: Options.CompareOptions): boolean;
invert(): RgbColor;
plusAlpha(relativeAlpha: number): RgbColor;
plusHue(relativeHue: number): RgbColor;
plusLightness(relativeLightness: number): RgbColor;
plusSaturation(relativeSaturation: number): RgbColor;
toHexString(options?: Options.ToHexStringOptions): string;
toHsl(options?: Options.ToOptions): Hsl;
toHwb(options?: Options.ToOptions): Hwb;
toJSON(): Rgb.Normalized & {
a: Alpha;
}
;
toRgb(options?: Options.ToRgbOptions): Rgb;
toString(): string;
toUint8Array(options?: Options.ToArrayOptions): Uint8Array;
toUint8ClampedArray(options?: Options.ToArrayOptions): Uint8ClampedArray;
withAlpha(absoluteAlpha: number): RgbColor;
withHue(absoluteHue: number): RgbColor;
withLightness(absoluteLightness: number): RgbColor;
withoutAlpha(): RgbColor;
withSaturation(absoluteSaturation: number): RgbColor;
 
static fromHexString(hexString: string, options?: Options.FromHexStringOptions): RgbColor;
static fromHsl(hsla: Hsl, options?: Options.FromOptions): RgbColor;
static fromHwb(hwba: Hwb, options?: Options.FromOptions): RgbColor;
static fromRgb(rgba: Rgb, options?: Options.FromRgbOptions): RgbColor;
static fromUint8Array(rgbaBytes: Uint8Array | Uint8ClampedArray, options?: Options.FromArrayOptions): RgbColor;
}

§Constructors

§
new RgbColor(r: Rgb.Component, g: Rgb.Component, b: Rgb.Component, a: Alpha) private
[src]

§Properties

§
space: ColorSpace readonly
[src]

Gets the color space.

Always returns "srgb" in the current version.

§
red: Rgb.Component readonly
[src]

Gets the red component value.

@example
const color = RgbColor.fromHexString("#ff0000");
const r = color.red;
// r
//   → 1
@example
const color = RgbColor.fromHexString("#88ffff");
const r = color.red;
// r
//   → 0.533333
§
green: Rgb.Component readonly
[src]

Gets the green component value.

@example
const color = RgbColor.fromHexString("#00ff00");
const g = color.green;
// g
//   → 1
@example
const color = RgbColor.fromHexString("#ff88ff");
const g = color.green;
// g
//   → 0.533333
§
blue: Rgb.Component readonly
[src]

Gets the blue component value.

@example
const color = RgbColor.fromHexString("#0000ff");
const b = color.blue;
// b
//   → 1
@example
const color = RgbColor.fromHexString("#ffff88");
const b = color.blue;
// b
//   → 0.533333
§
alpha: Alpha readonly
[src]

Gets the alpha component value.

@example
const color = RgbColor.fromHexString("#000000");
const a = color.alpha;
// a
//   → 1
@example
const color = RgbColor.fromHexString("#00000000");
const a = color.alpha;
// a
//   → 0
@example
const color = RgbColor.fromHexString("#ffffff88");
const a = color.alpha;
// a
//   → 0.533333
§
hue: Hue readonly
[src]

Get the hue value in degrees.

@example
const color = RgbColor.fromHexString("#598910");
const hue = color.hue;
// hue
//   → 83.801653
§
saturation: Hsl.Saturation readonly
[src]

Get the HSL saturation value.

@example
const color = RgbColor.fromHexString("#598910");
const saturation = color.saturation;
// saturation
//   → 0.790850
§
lightness: Hsl.Lightness readonly
[src]

Get the HSL lightness value.

@example
const color = RgbColor.fromHexString("#598910");
const lightness = color.lightness;
// lightness
//   → 0.300000
§
whiteness: Hwb.Whiteness readonly
[src]

Get the HWB whiteness value.

@example
const color = RgbColor.fromHexString("#598910");
const whiteness = color.whiteness;
// whiteness
//   → 0.062745
§
blackness: Hwb.Blackness readonly
[src]

Get the HWB blackness value.

@example
const color = RgbColor.fromHexString("#598910");
const blackness = color.blackness;
// blackness
//   → 0.462745

§Methods

§
complementary(): RgbColor
[src]

Returns a complementary color.

@return

A new instance of Color representing the complementary color of this color.

§
equalsBytes(other: RgbColor, options?: Options.CompareOptions): boolean
[src]
§
invert(): RgbColor
[src]

Returns a inverted color.

@return

A new instance of Color representing the inverted color of this color.

§
plusAlpha(relativeAlpha: number): RgbColor
[src]
§
plusHue(relativeHue: number): RgbColor
[src]
§
plusLightness(relativeLightness: number): RgbColor
[src]
§
plusSaturation(relativeSaturation: number): RgbColor
[src]
§
toHexString(options?: Options.ToHexStringOptions): string
[src]

Returns the RGB expressed as a string contains hexadecimal formatted bytes.

@param options
  • An options object.
@return

A RGB(A) byte sequence or the ARGB byte sequence.

@example
const color = RgbColor.fromHexString("#112233");
const hex = color.toHexString();
// hex
//   → "#112233FF" // RGBA
@example
const color = RgbColor.fromHexString("#112233");
const hex = color.toHexString({ discardAlpha: true });
// hex
//   → "#112233" // RGB
@example
const color = RgbColor.fromHexString("#112233");
const hex = color.toHexString({ order: "argb" });
// hex
//   → "#FF112233" // ARGB
@example
const color = RgbColor.fromHexString("#112233");
const hex = color.toHexString({ order: "argb", discardAlpha: true });
// hex
//   → "#FF112233" // ARGB
//   If the `order` is "argb", the `discardAlpha` and `omitAlphaIfOpaque` are ignored.
§
toHsl(options?: Options.ToOptions): Hsl
[src]

Returns the triplet of h (hue), s (saturation), and l (lightness).

@param options
  • An options object.
@return

A triplet of h, s, and l.

@example
const color = RgbColor.fromHexString("#ff0000");
const hsl = color.toHsl();
// hsl
//   → {
//       h: 0,
//       s: 1,
//       l: 0.5,
//       a: 1,
//     }
@example
const color = RgbColor.fromHexString("#ff0000");
const hsl = color.toHsl({ omitAlphaIfOpaque: true });
// hsl
//   → {
//       h: 0,
//       s: 1,
//       l: 0.5,
//     }
@example
const color = RgbColor.fromHexString("#ff000088");
const hsl = color.toHsl({ discardAlpha: true });
// hsl
//   → {
//       h: 0,
//       s: 1,
//       l: 0.5,
//     }
§
toHwb(options?: Options.ToOptions): Hwb
[src]

Returns the triplet of h (hue), w (whiteness), and b (blackness).

@param options
  • An options object.
@return

A triplet of h, w, and b.

@example
const color = RgbColor.fromHexString("#ff8888");
const hwb = color.toHwb();
// hwb
//   → {
//       h: 0,
//       w: 0.533333,
//       b: 0,
//       a: 1,
//     }
@example
const color = RgbColor.fromHexString("#ff8888");
const hwb = color.toHwb({ omitAlphaIfOpaque: true });
// hwb
//   → {
//       h: 0,
//       w: 0.533333,
//       b: 0,
//     }
@example
const color = RgbColor.fromHexString("#ff888888");
const hwb = color.toHwb({ discardAlpha: true });
// hwb
//   → {
//       h: 0,
//       w: 0.533333,
//       b: 0,
//     }
§
toJSON(): Rgb.Normalized & {
a: Alpha;
}
[src]
§
toString(): string
[src]

Equivalents to the toHexString method with no parameters.

@return
§
toUint8Array(options?: Options.ToArrayOptions): Uint8Array
[src]

Returns the RGB expressed as a byte sequence.

@param options
  • An options object.
@return

A RGB(A) byte sequence or the ARGB byte sequence.

@example
const color = RgbColor.fromHexString("#112233");
const bytes = color.toUint8Array();
// bytes
//   → Uint8Array[ 0x11, 0x22, 0x33, 0xFF ] // RGBA
@example
const color = RgbColor.fromHexString("#112233");
const bytes = color.toUint8Array({ discardAlpha: true });
// bytes
//   → Uint8Array[ 0x11, 0x22, 0x33 ] // RGB
@example
const color = RgbColor.fromHexString("#112233");
const bytes = color.toUint8Array({ order: "argb" });
// bytes
//   → Uint8Array[ 0xFF, 0x11, 0x22, 0x33 ] // ARGB
@example
const color = RgbColor.fromHexString("#112233");
const bytes = color.toUint8Array({ order: "argb", discardAlpha: true });
// bytes
//   → Uint8Array[ 0xFF, 0x11, 0x22, 0x33 ] // ARGB
//   If the `order` is "argb", the `discardAlpha` and `omitAlphaIfOpaque` are ignored.
§
toUint8ClampedArray(options?: Options.ToArrayOptions): Uint8ClampedArray
[src]

Returns the RGB expressed as a byte sequence.

@param options
  • An options object.
@return

A RGB(A) byte sequence or the ARGB byte sequence.

@example
const color = RgbColor.fromHexString("#112233");
const bytes = color.toUint8ClampedArray();
// bytes
//   → Uint8ClampedArray[ 0x11, 0x22, 0x33, 0xFF ] // RGBA
§
withAlpha(absoluteAlpha: number): RgbColor
[src]
§
withHue(absoluteHue: number): RgbColor
[src]
§
withLightness(absoluteLightness: number): RgbColor
[src]
§
withoutAlpha(): RgbColor
[src]
§
withSaturation(absoluteSaturation: number): RgbColor
[src]

§Static Methods

§
fromHexString(hexString: string, options?: Options.FromHexStringOptions): RgbColor
[src]
§
fromHsl(hsla: Hsl, options?: Options.FromOptions): RgbColor
[src]
§
fromHwb(hwba: Hwb, options?: Options.FromOptions): RgbColor
[src]
§
fromRgb(rgba: Rgb, options?: Options.FromRgbOptions): RgbColor
[src]
§
fromUint8Array(rgbaBytes: Uint8Array | Uint8ClampedArray, options?: Options.FromArrayOptions): RgbColor
[src]