Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    xyzw-rgbapublic

    xyzw-rgba

    Color vectors and transforms

    Install

    $ npm install xyzw-rgba

    Use

    xyzw-rgba is an extension of xyzw providing methods to easily work with colors and convert them from and to common color formats.

    import Vector3 from 'xyzw/source/Vector3';
    import Vector4 from 'xyzw/source/Vector4';
     
    import Vector3RGB from 'xyzw-rgba/source/Vector3RGB';
    import Vector4RGBA from 'xyzw-rgba/source/Vector4RGBA';
     
     
    Vector3RGB
        .CSS('rgb(255,127, 63)')
        .multiplyScalarEQ(0.5)
        .toCSS();   //'rgb(127,63,31)'
     
    Vector3RGB
        .CSS('#ff00ff')
        .addEQ(new Vector3([1.0, 1.0, 1.0]))
        .toCSS();   //'rgb(255,255,255)'
     
    Vector4RGBA
        .CSS('rgba(255,127,63,1.0)')
        .multiplyScalarEQ(0.5)
        .toCSS();  //'rgba(127,63,31,0.5)'
     
    Vector4RGBA
        .Int(0xffff7f3f)
        .subtractEQ(new Vector4([0.5, 0.0, -0.25, 0.5]))
        .toCSS();  //'rgba(127,127,127,0.5)

    Table of Contents

    floatToInt

    Returns the rgb8 value representing f

    Parameters

    • f number The floating point value

    Returns int

    intToFloat

    Returns the floating point value representing i

    Parameters

    • i int The rgb8 value

    Returns number

    floatToPct

    Returns the percent value representing f

    Parameters

    • f number The floating point value

    Returns int

    pctToFloat

    Returns the floating point value representing i

    Parameters

    • i int The percent value

    Returns number

    radToDeg

    Returns the degree value representing f

    Parameters

    Returns int

    degToRad

    Returns the radian value representing i

    Parameters

    • i int The degree value

    Returns number

    intIntIntToFloat

    Returns the floating point value representation of abc

    Parameters

    • abc Array<int> The rgb8-rgb8-rgb8 components
    • $0 Array
      • $0.a
      • $0.b
      • $0.c

    Returns Array<number>

    floatToIntIntInt

    Returns the rgb8 representation of abc

    Parameters

    Returns Array<int>

    degPctPctToFloat

    Returns the floating point representation of abc

    Parameters

    • abc Array<int> The deg-pct-pct components
    • $0 Array
      • $0.a
      • $0.b
      • $0.c

    Returns Array<number>

    floatToDegPctPct

    Returns the deg-pct-pct representation of abc

    Parameters

    Returns Array<int>

    parse

    Returns the component descriptor representing css

    Parameters

    Returns Object

    stringify

    Returns the shortest css string representing the color descriptor

    Parameters

    • descriptor Object

      • descriptor.type string The color model type
      • descriptor.components Array<number> The color components
    • $0 Object

      • $0.type
      • $0.components
    • Throws TypeError if descriptor.type is not a valid color model type

    • Throws TypeError if descriptor.components is not an array

    Returns string

    chroma

    Returns the chroma of s and l

    Parameters

    Returns number

    hslToRgb

    Returns the [r,g,b] representation of [h,s,l]

    Parameters

    Returns Array<number>

    rgbToHsl

    Returns the [h,s,l] representation of [r,g,b]

    Parameters

    Returns Array<number>

    HSLA

    HSLA color model transform

    constructor

    Creates a new instance

    Parameters

    h

    The hue

    s

    The saturation

    l

    The luminosity

    a

    The alpha

    define

    Redefines the instance

    Parameters

    Returns HSLA

    chroma

    The chroma

    copyOf

    The copy of source

    Parameters

    • source HSLA The source instance

    Returns HSLA

    toRGBA

    Returns a Vector4 rgba representation of the instance

    Parameters

    • target Vector4? the target vector

    Returns Vector4

    toRGB

    Returns a Vector3 rgb representation of the instance

    Parameters

    • matte Vector3? The alpha matte rgb vector
    • target Vector3? The target vector

    Returns Vector3

    toCSS

    Returns a css-formated hsl or hsla representation of the instance

    Returns string

    toString

    Returns a string representation of the instance

    Returns string

    Define

    Returns a defined instance

    Parameters

    Returns HSLA

    RGBA

    Returns an instance representing v

    Parameters

    • v Vector4 The source rgba vector
    • target HSLA? The target instance

    Returns HSLA

    RGB

    Returns an instance representing v

    Parameters

    • v Vector3 The source rgb vector
    • target HSLA? The target instance

    Returns HSLA

    Copy

    Returns the copy of source

    Parameters

    • source HSLA The source instance
    • target HSLA? The target instance

    Returns HSLA

    isEQ

    Returns true if a == b, false otherwise

    Parameters

    Returns boolean

    Vector3RGB

    Extends Vector3

    RGB three component vector representation

    r

    The r component Alias of Vector3#x

    g

    The g component Alias of Vector3#y

    b

    The b component Alias of Vector3#z

    toCSS

    Returns a css representation of the instance

    Parameters

    • fast bool? True if string should be generated fast, false if generated string should be small (optional, default false)

    Returns string

    toInt

    Returns a 0xrrggbb hex encoded integer representation of the instance

    Returns int

    toString

    Returns a css representation of the instance

    Returns string

    valueOf

    Returns a rrggbb hex encoded representation of the instance

    Returns int

    Define

    Returns a new instance

    Parameters

    Returns Vector3RGB

    CSS

    Returns an instance representing string

    Parameters

    • string string The css color string
    • matte Vector3?= rgb[1], a), Math.mix(mn[2 The transparency matte vector
    • target Vector3RGB? The target instance

    Returns Vector3RGB

    Int

    Returns an instance representing 0xrrggbb hex encoded i

    Parameters

    • i int The bit encoded Int
    • target Vector3? The target instance

    Returns Vector3RGB

    Vector4RGBA

    Extends Vector4

    RGBA Four component vector representation

    r

    The r component Alias of Vector4#x

    g

    The g component Alias of Vector4#y

    b

    The b component Alias of Vector4#z

    a

    The a component Alias of Vector4#w

    toCSS

    Returns a css color string representation of the instance

    Parameters

    • fast bool? True if css string should be generated fast, false if generated string should be small (optional, default false)

    Returns string

    toInt

    Returns a 0xaarrggbb hex encoded integer representation of the instance

    Returns int

    toString

    Returns a css color string representation of the instance

    Returns string

    valueOf

    Returns a aarrggbb hex encoded int representation of the instance

    Returns int

    Define

    Returns a defined instance

    Parameters

    Returns Vector4RGBA

    CSS

    Returns an instance representing string

    Parameters

    Returns Vector4RGBA

    Int

    Returns an instance representing 0xaarrggbb hex encoded i

    Parameters

    • i int The hex encoded color
    • target Vector4RGBA? The target instance

    Returns Vector4RGBA

    install

    npm i xyzw-rgba

    Downloadsweekly downloads

    6

    version

    0.9.5

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar