Nutrient Web SDK
    Preparing search index...

    Color objects are used in annotations for defining colors. We're using an rgb representation internally with the r, g, b values clipped between 0 and 255 inclusive, and a transparent flag that can be used to indicate that the color is transparent, in which case the provided r, g, and b values are ignored and set to 0 in the instantiated Color.

    It is an Immutable.Record and thus can be updated using set(key, value), for example: color.set("r", 255).

    However, in order to obtain a transparent color the static TRANSPARENT value should be used instead.

    The difference between using Color.TRANSPARENT and null as values for annotation color properties may depend on the context; if the annotation is being created or updated:

    • If an annotation with a non-transparent color value is updated to have a color value of Color.TRANSPARENT, the color value will be updated and be transparent.
    • But if that same annotation is updated to have a color value of null, the color change will not be saved to the document, although it may appear as transparent in the viewer.

    To avoid inconsistencies, it is recommended to always use Color.TRANSPARENT instead of null when updating annotations.

    Create and update a color.

    var color = new NutrientViewer.Color({ r: 245, g: 0, b: 0 });
    color = color.set("r", 255);
    color.r; // => 255

    An object used to initialize the color. If r, g or b is omitted, 0 will be used instead.

    { r: 0, g: 0, b: 0, transparent: false }
    

    Hierarchy

    • Record<{ b: number; g: number; r: number; transparent: boolean }, this> & Readonly<
          { b: number; g: number; r: number; transparent: boolean },
      >
      • Color
    Index

    Constructors

    • Parameters

      • color: { b?: number; g?: number; r?: number; transparent?: boolean }

      Returns NutrientViewer.Color

    Properties

    b: number = 0

    The blue value of the color.

    0
    
    g: number = 0

    The green value of the color.

    0
    
    r: number = 0

    The red value of the color.

    0
    
    transparent: boolean = false

    Transparency of the color.

    false
    
    BLACK: NutrientViewer.Color = ...

    Simple black (CSS: rgb(0, 0, 0))

    BLUE: NutrientViewer.Color = ...

    Blue (CSS: rgb(34, 147, 251))

    DARK_BLUE: NutrientViewer.Color = ...

    Blue (CSS: rgb(36, 131, 199))

    DARK_GREY: NutrientViewer.Color = ...

    Dark grey (CSS: rgb(64, 64, 64))

    GREEN: NutrientViewer.Color = ...

    Green (CSS: rgb(110, 176, 0))

    GREY: NutrientViewer.Color = ...

    Grey (CSS: rgb(128, 128, 128))

    LIGHT_BLUE: NutrientViewer.Color = ...

    Light blue (CSS: rgb(141, 184, 255))

    LIGHT_GREEN: NutrientViewer.Color = ...

    Light green (CSS: rgb(162, 250, 123))

    LIGHT_GREY: NutrientViewer.Color = ...

    Light grey (CSS: rgb(192, 192, 192))

    LIGHT_ORANGE: NutrientViewer.Color = ...

    Light orange (CSS: rgb(255, 139, 94))

    LIGHT_RED: NutrientViewer.Color = ...

    Light red (CSS: rgb(247, 141, 138))

    LIGHT_YELLOW: NutrientViewer.Color = ...

    Light yellow (CSS: rgb(252, 238, 124))

    MAUVE: NutrientViewer.Color = ...

    Mauve (CSS: rgb(245, 135, 255))

    ORANGE: NutrientViewer.Color = ...

    Orange (CSS: rgb(243, 149, 0))

    PINK: NutrientViewer.Color = ...

    Pink (CSS: rgb(255, 114, 147))

    PURPLE: NutrientViewer.Color = ...

    Purple (CSS: rgb(255, 0, 255))

    Red (CSS: rgb(248, 36, 0))

    TRANSPARENT: NutrientViewer.Color = ...

    Transparent (CSS: transparent)

    WHITE: NutrientViewer.Color = ...

    Simple white (CSS: rgb(255, 255, 255))

    YELLOW: NutrientViewer.Color = ...

    Yellow (CSS: rgb(255, 255, 0))

    Methods

    • Returns IterableIterator<["r" | "g" | "b" | "transparent", number | boolean]>

    • Returns this

      Map#asImmutable

    • Returns this

      Map#asMutable

    • Returns a new instance of this Record type with all values set to their default values.

      Returns this

    • Returns a darker version of the current Color.

      Parameters

      • percent: number

        The percentage of lightness between 0 and 100.

      Returns NutrientViewer.Color

      A Color with the new values.

      const color = NutrientViewer.Color.RED.darker(50);
      
    • Returns a new instance of this Record type with the value for the specific key set to its default value.

      Type Parameters

      • K extends "r" | "g" | "b" | "transparent"

      Parameters

      • key: K

      Returns this

      remove

    • Parameters

      Returns this

      removeIn

    • Returns true if the provided color or object and the current Color have the same RGB values.

      Parameters

      • color: NutrientViewer.Color | { b: number; g: number; r: number; transparent: boolean }

        Color instance or RGB object.

      Returns boolean

      True if equal, false otherwise.

      const color = NutrientViewer.Color.RED.equals({ r: 248, g: 36, b: 0 });
      
    • Returns the value associated with the provided key, which may be the default value defined when creating the Record factory function.

      If the requested key is not defined by this Record type, then notSetValue will be returned if provided. Note that this scenario would produce an error when using Flow or TypeScript.

      Type Parameters

      • K extends "r" | "g" | "b" | "transparent"

      Parameters

      • key: K
      • OptionalnotSetValue: any

      Returns { b: number; g: number; r: number; transparent: boolean }[K]

    • Type Parameters

      • T

      Parameters

      • key: string
      • notSetValue: T

      Returns T

    • Parameters

      Returns any

    • Parameters

      • key: string

      Returns key is "r" | "g" | "b" | "transparent"

    • Returns number

    • Parameters

      Returns boolean

    • Returns a lighter version of the current Color.

      Parameters

      • percent: number

        The percentage of lightness between 0 and 100.

      Returns NutrientViewer.Color

      A Color with the new values.

      const color = NutrientViewer.Color.RED.lighter(50);
      
    • Parameters

      • ...collections: (
            | Iterable<[string, any]>
            | Partial<{ b: number; g: number; r: number; transparent: boolean }>
        )[]

      Returns this

    • Parameters

      • ...collections: (
            | Iterable<[string, any]>
            | Partial<{ b: number; g: number; r: number; transparent: boolean }>
        )[]

      Returns this

    • Parameters

      • keyPath: Iterable<any>
      • ...collections: any[]

      Returns this

    • Parameters

      • merger: (oldVal: any, newVal: any, key: any) => any
      • ...collections: (
            | Iterable<[string, any]>
            | Partial<{ b: number; g: number; r: number; transparent: boolean }>
        )[]

      Returns this

    • Parameters

      • keyPath: Iterable<any>
      • ...collections: any[]

      Returns this

    • Parameters

      • merger: (oldVal: any, newVal: any, key: "r" | "g" | "b" | "transparent") => any
      • ...collections: (
            | Iterable<[string, any]>
            | Partial<{ b: number; g: number; r: number; transparent: boolean }>
        )[]

      Returns this

    • Returns number

    • Type Parameters

      • K extends "r" | "g" | "b" | "transparent"

      Parameters

      • key: K

      Returns this

    • Parameters

      Returns this

    • Modifies the saturation of the Color and returns a new one.

      Parameters

      • percent: number

        The percentage of saturation between 0 and 100.

      Returns NutrientViewer.Color

      A Color with the new values.

      const color = NutrientViewer.Color.RED.saturate(50);
      
    • Type Parameters

      • K extends "r" | "g" | "b" | "transparent"

      Parameters

      • key: K
      • value: { b: number; g: number; r: number; transparent: boolean }[K]

      Returns this

    • Parameters

      Returns this

    • Parameters

      • RGBComponent: number

      Returns number

    • Converts the color to a CSS value (e.g. rgb(255, 0, 0)).

      Returns string

      A CSS color value in rgb format.

      NutrientViewer.Color.RED.toCSSValue(); // => 'rgb(248, 36, 0)'
      
    • Converts the color to a Hex value (e.g. #000000).

      Returns string

      A CSS color value in hex format.

      NutrientViewer.Color.RED.toHex(); // => '#f82400'
      
    • Deeply converts this Record to equivalent native JavaScript Object.

      Note: This method may not be overridden. Objects with custom serialization to plain JS may override toJSON() instead.

      Returns { b: any; g: any; r: any; transparent: any }

      • b: any

        The blue value of the color.

        0
        
      • g: any

        The green value of the color.

        0
        
      • r: any

        The red value of the color.

        0
        
      • transparent: any

        Transparency of the color.

        false
        
    • Shallowly converts this Record to equivalent native JavaScript Object.

      Returns { b: number; g: number; r: number; transparent: boolean }

      • b: number

        The blue value of the color.

        0
        
      • g: number

        The green value of the color.

        0
        
      • r: number

        The red value of the color.

        0
        
      • transparent: boolean

        Transparency of the color.

        false
        
    • Shallowly converts this Record to equivalent JavaScript Object.

      Returns { b: number; g: number; r: number; transparent: boolean }

      • b: number

        The blue value of the color.

        0
        
      • g: number

        The green value of the color.

        0
        
      • r: number

        The red value of the color.

        0
        
      • transparent: boolean

        Transparency of the color.

        false
        
    • Returns Keyed<"r" | "g" | "b" | "transparent", number | boolean>

    • Type Parameters

      • K extends "r" | "g" | "b" | "transparent"

      Parameters

      • key: K
      • updater: (
            value: { b: number; g: number; r: number; transparent: boolean }[K],
        ) => { b: number; g: number; r: number; transparent: boolean }[K]

      Returns this

    • Parameters

      • keyPath: Iterable<any>
      • updater: (value: any) => any

      Returns this

    • Returns boolean

      Map#wasAltered

    • Note: Not all methods can be used on a mutable collection or within withMutations! Only set may be used mutatively.

      Parameters

      • mutator: (mutable: this) => any

      Returns this

      Map#withMutations

    • Converts a hex color value to a Color instance.

      Parameters

      • hexColor: string

        The hex color value to convert.

      Returns NutrientViewer.Color

      A Color instance.