One-color.js

one-color-debug

one-color-debug.js

global window

  • namespace: one One.com global JavaScript namespace.
  • exports: window .one as one
if (typeof window !== 'undefined') {
	window.one = window.one || {};
} else {
	var one = {};
}

one.include = one.exclude = function () {}; // Ignore these in development mode

global one

  • namespace: one .color
one.color = one.color || {};

(function () {
  • exports: stringPrototype as String.prototype
var stringPrototype = String.prototype;

<p>Returns this string with the char at first position in uppercase.</p> <p>Example of use:</p><pre><code> "the brown Fox jumped over the lazy Dog".capitalize(); // = "The brown Fox jumped over the lazy Dog" </code></pre> - return: capitalized string. - memberOf: String .prototype

stringPrototype.capitalize = function () {
        return this.charAt(0).toUpperCase() + this.substring(1);
    };
}());

global one

jslint evil:true

one.color.installedColorSpaces = [];

one.color.installColorSpace = function (colorSpaceName, propertyDefinitions, config) {
    var propertyNames = propertyDefinitions.map(function (propertyDefinition) {
            return propertyDefinition.match(/[A-Z]/)[0].toLowerCase();
        }),
        longPropertyNames = propertyDefinitions.map(function (propertyDefinition) {
            return propertyDefinition.toLowerCase().capitalize();
        }),
        Constructor = one.color[colorSpaceName] = new Function(propertyNames.join(&quot;,&quot;),
            // Allow passing an array to the constructor:
            &quot;if (Object.prototype.toString.apply(&quot; + propertyNames[0] + &quot;) === '[object Array]') {&quot; +
                propertyNames.map(function (propertyName, i) {
                    return propertyName + &quot;=&quot; + propertyNames[0] + &quot;[&quot; + i + &quot;];&quot;;
                }).reverse().join(&quot;&quot;) +
            &quot;}&quot; +
            &quot;if (&quot; + propertyNames.filter(function (propertyName) {
                return propertyName !== 'a';
            }).map(function (propertyName) {
                return &quot;isNaN(&quot; + propertyName + &quot;)&quot;;
            }).join(&quot;||&quot;) + &quot;){&quot; + &quot;throw \&quot;[one.color.&quot; + colorSpaceName + &quot;]: Invalid color: (\&quot;+&quot; + propertyNames.join(&quot;+\&quot;,\&quot;+&quot;) + &quot;+\&quot;)\&quot;;}&quot; +
            propertyNames.map(function (propertyName) {
                if (propertyName === 'h') {
                    return &quot;this.h=h&lt;0?h-Math.floor(h):h%1&quot;; // Wrap
                } else if (propertyName === 'a') {
                    return &quot;this.a=(isNaN(a)||a&gt;1)?1:(a&lt;0?0:a);&quot;;
                } else {
                    return &quot;this.&quot; + propertyName + &quot;=&quot; + propertyName + &quot;&lt;0?0:(&quot; + propertyName + &quot;&gt;1?1:&quot; + propertyName + &quot;)&quot;;
                }
            }).join(&quot;;&quot;) + &quot;;&quot;
        ),
        prototype = Constructor.prototype;

    Constructor.propertyNames = propertyNames;
    Constructor.longPropertyNames = longPropertyNames;

    ['valueOf', 'toHex', 'toCSS', 'toCSSWithAlpha'].forEach(function (methodName) {
        prototype[methodName] = prototype[methodName] || (colorSpaceName === 'RGB' ? prototype.toHex : new Function(&quot;return this.toRGB().&quot; + methodName + &quot;();&quot;));
    });

    prototype.isColor = true;

    prototype.equals = function (otherColor, epsilon) {
        if (typeof epsilon === 'undefined') {
            epsilon = e-10;
        }

        otherColor = otherColor['to' + colorSpaceName]();

        for (var i = 0; i &lt; propertyNames.length; i = i + 1) {
            if (Math.abs(this[propertyNames[i]] - otherColor[propertyNames[i]]) &gt; epsilon) {
                return false;
            }
        }

        return true;
    };

    prototype.toJSON = new Function(
        &quot;return ['" + colorSpaceName + "', &quot; +
            propertyNames.map(function (propertyName) {
                return &quot;this.&quot; + propertyName;
            }, this).join(&quot;, &quot;) +
        &quot;];&quot;
    );

    if (config.fromRGB) {
        one.color.RGB.prototype['to' + colorSpaceName] = config.fromRGB;
        delete config.fromRGB;
    }
    for (var prop in config) {
        if (config.hasOwnProperty(prop)) {
            prototype[prop] = config[prop];
        }
    }

    // It is pretty easy to implement the conversion to the same color space:
    prototype['to' + colorSpaceName] = function () {
        return this;
    };
    prototype.toString = new Function(&quot;return \&quot;[one.color.&quot; + colorSpaceName + &quot;:\&quot;+&quot; + propertyNames.map(function (propertyName, i) {
        return &quot;\&quot; &quot; + longPropertyNames[i] + &quot;=\&quot;+this.&quot; + propertyName;
    }).join(&quot;+&quot;) + &quot;+\&quot;]\&quot;;&quot;);

    // Generate getters and setters
    propertyNames.forEach(function (propertyName, i) {
        var longPropertyName = longPropertyNames[i];
        prototype['get' + longPropertyName] = new Function(&quot;return this.&quot; + propertyName + &quot;;&quot;);
        prototype['set' + longPropertyName] = new Function(&quot;newValue&quot;, &quot;return new this.constructor(&quot; + propertyNames.map(function (otherPropertyName, i) {
            return propertyName === otherPropertyName ? &quot;newValue&quot; : &quot;this.&quot; + otherPropertyName;
        }).join(&quot;, &quot;) + &quot;);&quot;);
        prototype['adjust' + longPropertyName] = new Function(&quot;delta&quot;, &quot;return new this.constructor(&quot; + propertyNames.map(function (otherPropertyName, i) {
            return &quot;this.&quot; + otherPropertyName + (propertyName === otherPropertyName ? &quot;+delta&quot; : &quot;&quot;);
        }).join(&quot;, &quot;) + &quot;);&quot;);
    });

    function installForeignMethods(targetColorSpaceName, sourceColorSpaceName) {
        var obj = {};
        obj['to' + sourceColorSpaceName] = new Function(&quot;return this.toRGB().to&quot; + sourceColorSpaceName + &quot;();&quot;); // Fallback
        one.color[sourceColorSpaceName].propertyNames.forEach(function (property, i) {
            var longPropertyName = one.color[sourceColorSpaceName].longPropertyNames[i];
            obj['get' + longPropertyName] = new Function(&quot;return this.to&quot; + sourceColorSpaceName + &quot;().get&quot; + longPropertyName + &quot;();&quot;);
            obj['set' + longPropertyName] = new Function(&quot;newValue&quot;, &quot;return this.to&quot; + sourceColorSpaceName + &quot;().set&quot; + longPropertyName + &quot;(newValue);&quot;);
            obj['adjust' + longPropertyName] = new Function(&quot;delta&quot;, &quot;return this.to&quot; + sourceColorSpaceName + &quot;().adjust&quot; + longPropertyName + &quot;(delta);&quot;);
        });
        for (var prop in obj) {
            if (obj.hasOwnProperty(prop) &amp;&amp; one.color[targetColorSpaceName].prototype[prop] === undefined) {
                one.color[targetColorSpaceName].prototype[prop] = obj[prop];
            }
        }
    }

    one.color.installedColorSpaces.forEach(function (otherColorSpaceName) {
        installForeignMethods(colorSpaceName, otherColorSpaceName);
        installForeignMethods(otherColorSpaceName, colorSpaceName);
    });

    one.color.installedColorSpaces.push(colorSpaceName);
};

global one

  • name: one .color.RGB
  • clas: s

<p>A color in the RGB colorspace with an optional alpha value.</p> <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be immutable; all the conversion, set, and adjust methods return new objects.</p> <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set and adjust methods from all other installed colorspaces, so although you can use the explicit conversion methods ({@link one.color.RGB#toHSL}, {@link one.color.RGB#toCMYK}...), the below will work just fine:</p><pre><code>

new one.color.RGB(.4, .3, .9). adjustLightness(+.2). // Implicit conversion to HSL setRed(-.1). // Implicit conversion back to RGB toHex(); // "#00a6f2" </code></pre>

  • constructo: r

Create a new one.color.RGB object. Values outside the supported range, [0..1], will be adjusted automatically. ##

  • param: Number r The red component, range: [0..1]

  • param: Number g The green component, range: [0..1]

  • param: Number b The blue component, range: [0..1]

  • param: Number [a] The alpha value, range: [0..1],

defaults to 1

one.color.installColorSpace('RGB', ['Red', 'Green', 'Blue', 'Alpha'], {

Get the standard RGB hex representation of the color. ##

  • return: String The hex string, e.g. "#f681df"

toHex: function () {
        var hexString = (Math.round(255 * this.r) * x10000 + Math.round(255 * this.g) * x100 + Math.round(255 * this.b)).toString(16);
        return '#' + ('00000'.substr(0, 6 - hexString.length)) + hexString;
    },

Get a valid CSS color representation of the color without an alpha value. ##

  • return: String The CSS color string, e.g. "rgb(123, 2, 202)"

toCSS: function () {
        return &quot;rgb(&quot; + Math.round(255 * this.r) + &quot;,&quot; + Math.round(255 * this.g) + &quot;,&quot; + Math.round(255 * this.b) + &quot;)&quot;;
    },

Get a valid CSS color representation of the color, including the alpha value. ##

  • return: String The CSS color string, e.g. "rgba(123, 2, 202, 0.253)"

toCSSWithAlpha: function () {
        return &quot;rgba(&quot; + Math.round(255 * this.r) + &quot;,&quot; + Math.round(255 * this.g) + &quot;,&quot; + Math.round(255 * this.b) + &quot;,&quot; + this.a + &quot;)&quot;;
    }
});
  • name: one .color.RGB.prototype.r
  • propert: y

  • type: Number

  • description: The red component, range: [0..1]

  • name: one .color.RGB.prototype.g
  • propert: y

  • type: Number

  • description: The green component, range: [0..1]

  • name: one .color.RGB.prototype.b
  • propert: y

  • type: Number

  • description: The blue component, range: [0..1]

  • name: one .color.RGB.prototype.a
  • propert: y

  • type: Number

  • description: The alpha value, range: [0..1]

  • name: one .color.RGB.prototype.setRed
  • functio: n

  • param: Number r The new red component, range: [0..1]

  • return: one.color.RGB New color object with the changed value.

  • name: one .color.RGB.prototype.setGreen
  • functio: n

  • param: Number g The new green component, range: [0..1]

  • return: one.color.RGB New color object with the changed value.

  • name: one .color.RGB.prototype.setBlue
  • functio: n

  • param: Number b The new blue component, range: [0..1]

  • return: one.color.RGB New color object with the changed value.

  • name: one .color.RGB.prototype.setAlpha
  • functio: n

  • param: Number a The new alpha value, range: [0..1]

  • return: one.color.RGB New color object with the changed value.

  • name: one .color.RGB.prototype.adjustRed
  • functio: n

  • param: Number r The value to add to the red component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.RGB New color object with the changed value.

  • name: one .color.RGB.prototype.adjustGreen
  • functio: n

  • param: Number g The value to add to the green component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.RGB New color object with the changed value.

  • name: one .color.RGB.prototype.adjustBlue
  • functio: n

  • param: Number b The value to add to the blue component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.RGB New color object with the changed value.

  • name: one .color.RGB.prototype.adjustAlpha
  • functio: n

  • param: Number a The value to add to the alpha value. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.RGB New color object with the changed value.

  • name: one .color.RGB.prototype.toJSON
  • description: Convert the color to a JSON representation.
  • functio: n

  • return: Array

  • name: one .color.RGB.prototype.toRGB
  • description: Convert the color to a {@link one.color.RGB} object, ie. return the object itself.
  • functio: n

  • return: one.color.RGB

  • name: one .color.RGB.prototype.toHSV
  • description: Convert the color to a {@link one.color.HSV} object.
  • functio: n

  • requires: one .color.HSV ##

  • return: one.color.HSV

  • name: one .color.RGB.prototype.toHSL
  • description: Convert the color to a {@link one.color.HSL} object.
  • functio: n

  • requires: one .color.HSL ##

  • return: one.color.HSL

  • name: one .color.RGB.prototype.toCMYK
  • description: Convert the color to a {@link one.color.CMYK} object.
  • functio: n

  • requires: one .color.CMYK ##

  • return: one.color.CMYK

jslint bitwise:false

global one

Parse a hex string, 24-bit integer or object representing a color. If a one.color.(RGB|HSL|HSV|CMYK) object is provided, it will be returned as-is, so in library code you can use {@link one.color.parse} to be flexible about how colors are provided to you: <pre><code> function foo (color) { color = color.parse(color); // Now we are sure that color is a one.color.(RGB|CMYK|HSL|HSV) object, even if it was provided as a hex string. } </code></pre> ##

  • param: String | Object obj A hex string, integer value, or

object to parse.

  • return: one.color.RGB | one.color.HSL | one.color.HSV | one.color.CMYK Color object representing the

parsed color, or false if the input couldn't be parsed.

one.color.parse = function (obj) {
    if (obj.charCodeAt) {
        return one.color.fromCSSRGBA(obj) || one.color.fromHex(obj);
    } else if (typeof obj === 'object' &amp;&amp; obj.isColor) {
        return obj;
    } else if (Object.prototype.toString.apply(obj) === '[object Array]') {
        return new one.color[obj[0]](obj.slice(1, obj.length));
    } else if (!isNaN(obj)) {
        // Strange integer representation sometimes returned by document.queryCommandValue in some browser...
        return new one.color.RGB((obj &amp; xFF) / 255, ((obj & 0xFF00) >> 8) / 255, ((obj &amp; xFF0000) &gt;&gt; 16) / 255);
    }
    return false;
};

global one

  • name: one .color.HSV
  • clas: s

<p>A color in the HSV colorspace, with an optional alpha value.</p> <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be immutable; all the conversion, set, and adjust methods return new objects.</p> <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set and adjust methods from all other installed colorspaces, so although you can use the explicit conversion methods ({@link one.color.HSV#toRGB}, {@link one.color.HSV#toHSL}...), the below will work just fine:</p><pre><code>

new one.color.HSV(.9, .2, .4). adjustBlue(-.4). // Implicit conversion to RGB setCyan(-.1). // Implicit conversion to CMYK toHex(); // "#665200" </code></pre>

  • constructo: r

Create a new one.color.HSV object. Component values outside the supported range, [0..1], will be adjusted automatically. ##

  • param: Number h The hue component, range: [0..1]

  • param: Number s The saturation component, range: [0..1]

  • param: Number v The value component, range: [0..1]

  • param: Number [a] The alpha value, range: [0..1],

defaults to 1

  • name: one .color.HSV.prototype.h
  • propert: y

  • type: Number

  • description: The hue component, range: [0..1]

  • name: one .color.HSV.prototype.s
  • propert: y

  • type: Number

  • description: The saturation component, range: [0..1]

  • name: one .color.HSV.prototype.v
  • propert: y

  • type: Number

  • description: The value component, range: [0..1]

  • name: one .color.HSV.prototype.a
  • propert: y

  • type: Number

  • description: The alpha value, range: [0..1]

  • name: one .color.HSV.prototype.setHue
  • functio: n

  • param: Number h The new hue component, range: [0..1]

  • return: one.color.HSV New color object with the changed value.

  • name: one .color.HSV.prototype.setSaturation
  • functio: n

  • param: Number s The new saturation component, range: [0..1]

  • return: one.color.HSV New color object with the changed value.

  • name: one .color.HSV.prototype.setValue
  • functio: n

  • param: Number l The new value component, range: [0..1]

  • return: one.color.HSV New color object with the changed value.

  • name: one .color.HSV.prototype.setAlpha
  • functio: n

  • param: Number a The new alpha value, range: [0..1]

  • return: one.color.HSV New color object with the changed value.

  • name: one .color.HSV.prototype.adjustHue
  • functio: n

  • param: Number h The value to add to the hue component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.HSV New color object with the changed value.

  • name: one .color.HSV.prototype.adjustSaturation
  • functio: n

  • param: Number s The value to add to the saturation component. If the

resulting value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.HSV New color object with the changed value.

  • name: one .color.HSV.prototype.adjustValue
  • functio: n

  • param: Number v The value to add to the value component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.HSV New color object with the changed value.

  • name: one .color.HSV.prototype.adjustAlpha
  • functio: n

  • param: Number a The value to add to the alpha value. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.HSV New color object with the changed value.

  • name: one .color.HSV.prototype.toJSON
  • description: Convert the color to a JSON representation.
  • functio: n

  • return: Array

  • name: one .color.HSV.prototype.toRGB
  • description: Convert the color to a {@link one.color.RGB} object.
  • functio: n

  • return: one.color.RGB

  • name: one .color.HSV.prototype.toHSV
  • description: Convert the color to a {@link one.color.HSV} object, ie. return the object itself.
  • functio: n

  • return: one.color.HSV

  • name: one .color.HSV.prototype.toHSL
  • description: Convert the color to a {@link one.color.HSL} object.
  • functio: n

  • requires: one .color.HSL ##

  • return: one.color.HSL

  • name: one .color.HSV.prototype.toCMYK
  • description: Convert the color to a {@link one.color.CMYK} object.
  • functio: n

  • include: one .color.CMYK ##

  • return: one.color.CMYK

  • name: one .color.HSV.prototype.toHex
  • description: Get the standard RGB hex representation of the color.
  • functio: n

  • return: String The hex string, e.g. "#f681df"

  • name: one .color.HSV.prototype.toCSS
  • description: Get a valid CSS color representation of the color without an alpha value.
  • functio: n

  • return: String The CSS color string, e.g. "rgb(123, 2, 202)"

  • name: one .color.HSV.prototype.toCSSWithAlpha
  • description: Get a valid CSS color representation of the color, including the alpha value.
  • functio: n

  • return: String The CSS color string, e.g. "rgba(123, 2, 202, 0.253)"

one.color.installColorSpace('HSV', ['Hue', 'Saturation', 'Value', 'Alpha'], {
    toRGB: function () {
        var r, g, b,
            i = Math.min(5, Math.floor(this.h * 6)),
            f = this.h * 6 - i,
            p = this.v * (1 - this.s),
            q = this.v * (1 - f * this.s),
            t = this.v * (1 - (1 - f) * this.s);
        switch (i) {
        case 0:
            r = this.v;
            g = t;
            b = p;
            break;
        case 1:
            r = q;
            g = this.v;
            b = p;
            break;
        case 2:
            r = p;
            g = this.v;
            b = t;
            break;
        case 3:
            r = p;
            g = q;
            b = this.v;
            break;
        case 4:
            r = t;
            g = p;
            b = this.v;
            break;
        case 5:
            r = this.v;
            g = p;
            b = q;
            break;
        }
        return new one.color.RGB(r, g, b, this.a);
    },

    toHSL: function () {
        // Algorithm adapted from http://wiki.secondlife.com/wiki/Color_conversion_scripts
        var s = this.s * this.v,
            l = (2 - this.s) * this.v;
        return new one.color.HSL(this.h, s / (l <= 1 ? l : (2 - l)), l / 2, this.a);
    },

    fromRGB: function () { // Becomes one.color.RGB.prototype.toHSV
        var max = Math.max(this.r, this.g, this.b),
            min = Math.min(this.r, this.g, this.b),
            delta = max - min,
            h,
            s = (max === 0) ? 0 : (delta / max),
            v = max;
        if (delta === 0) {
            h = 0;
        } else {
            switch (max) {
            case this.r:
                h = (this.g - this.b) / delta / 6 + (this.g &lt; this.b ? 1 : 0);
                break;
            case this.g:
                h = (this.b - this.r) / delta / 6 + 1 / 3;
                break;
            case this.b:
                h = (this.r - this.g) / delta / 6 + 2 / 3;
                break;
            }
        }
        return new one.color.HSV(h, s, v, this.a);
    }
});

global one

  • name: one .color.HSL
  • clas: s

<p>A color in the HSL colorspace, with an optional alpha value.</p> <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be immutable; all the conversion, set, and adjust methods return new objects.</p> <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set and adjust methods from all other installed colorspaces, so although you can use the explicit conversion methods ({@link one.color.HSL#toRGB}, {@link one.color.HSL#toHSV}...), the below will work just fine:</p><pre><code>

new one.color.HSL(.4, .3, .9, .9). // HSL with alpha adjustBlack(+.1). // Implicit conversion to CMYK (with alpha) setGreen(-.1). // Implicit conversion to RGB (with alpha) toCSSWithAlpha(); // "rgba(198,0,203,0.9)" </code></pre>

  • constructo: r

Create a new one.color.HSL object. Component values outside the supported range, [0..1], will be adjusted automatically. ##

  • param: Number h The hue component, range: [0..1]

  • param: Number s The saturation component, range: [0..1]

  • param: Number l The lightness component, range: [0..1]

  • param: Number [a] The alpha value, range: [0..1],

defaults to 1

one.color.installColorSpace('HSL', ['Hue', 'Saturation', 'Lightness', 'Alpha'], {
    toHSV: function () {
        // Algorithm adapted from http://wiki.secondlife.com/wiki/Color_conversion_scripts
        var s = this.s,
            l = this.l * 2;
        if (l &lt;= 1) {
            s *= l;
        } else {
            s *= (2 - l);
        }
        return new one.color.HSV(this.h, (2 * s) / (l + s), (l + s) / 2, this.a);
    },

    toRGB: function () {
        return this.toHSV().toRGB();
    },

    fromRGB: function () { // Becomes one.color.RGB.prototype.toHSV
        return this.toHSV().toHSL();
    }
});
  • name: one .color.HSL.prototype.h
  • propert: y

  • type: Number

  • description: The hue component, range: [0..1]

  • name: one .color.HSL.prototype.s
  • propert: y

  • type: Number

  • description: The saturation component, range: [0..1]

  • name: one .color.HSL.prototype.l
  • propert: y

  • type: Number

  • description: The lightness component, range: [0..1]

  • name: one .color.HSL.prototype.a
  • propert: y

  • type: Number

  • description: The alpha value, range: [0..1]

  • name: one .color.HSL.prototype.setHue
  • functio: n

  • param: Number h The new hue component, range: [0..1]

  • return: one.color.HSL New color object with the changed value.

  • name: one .color.HSL.prototype.setSaturation
  • functio: n

  • param: Number s The new saturation component, range: [0..1]

  • return: one.color.HSL New color object with the changed value.

  • name: one .color.HSL.prototype
  • function: setLightness

  • param: Number l The new lightness component, range: [0..1]

  • return: one.color.HSL New color object with the changed value.

  • name: one .color.HSL.prototype.setAlpha
  • functio: n

  • param: Number a The new alpha value, range: [0..1]

  • return: one.color.HSL New color object with the changed value.

  • name: one .color.HSL.prototype.adjustHue
  • functio: n

  • param: Number h The value to add to the hue component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.HSL New color object with the changed value.

  • name: one .color.HSL.prototype.adjustSaturation
  • functio: n

  • param: Number s The value to add to the saturation component. If the

resulting value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.HSL New color object with the changed value.

  • name: one .color.HSL.prototype.adjustLightness
  • functio: n

  • param: Number l The value to add to the lightness component. If the

resulting value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.HSL New color object with the changed value.

  • name: one .color.HSL.prototype.adjustAlpha
  • functio: n

  • param: Number a The value to add to the alpha value. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.HSL New color object with the changed value.

  • name: one .color.HSL.prototype.toJSON
  • description: Convert the color to a JSON representation.
  • functio: n

  • return: Array

  • name: one .color.HSL.prototype.toRGB
  • description: Convert the color to a {@link one.color.RGB} object.
  • functio: n

  • return: one.color.RGB

  • name: one .color.HSL.prototype.toHSV
  • description: Convert the color to a {@link one.color.HSV} object.
  • functio: n

  • return: one.color.HSV

  • requires: one .color.HSV

  • name: one .color.HSL.prototype.toHSL
  • description: Convert the color to a {@link one.color.HSL} object, ie. return the object itself.
  • functio: n

  • return: one.color.HSL

  • name: one .color.HSL.prototype.toCMYK
  • description: Convert the color to a {@link one.color.CMYK} object.
  • functio: n

  • requires: one .color.CMYK ##

  • return: one.color.CMYK

  • name: one .color.HSL.prototype.toHex
  • description: Get the standard RGB hex representation of the color.
  • functio: n

  • return: String The hex string, e.g. "#f681df"

  • name: one .color.HSL.prototype.toCSS
  • description: Get a valid CSS color representation of the color without an alpha value.
  • functio: n

  • return: String The CSS color string, e.g. "rgb(123, 2, 202)"

  • name: one .color.HSL.prototype.toCSSWithAlpha
  • description: Get a valid CSS color representation of the color, including the alpha value.
  • functio: n

  • return: String The CSS color string, e.g. "rgba(123, 2, 202, 0.253)"

global one

  • name: one .color.CMYK
  • clas: s

<p>A color in the CMYK colorspace, with an optional alpha value.</p> <p>one.color.(RGB|HSL|HSV|CMYK) objects are designed to be immutable; all the conversion, set, and adjust methods return new objects.</p> <p>one.color.(RGB|HSL|HSV|CMYK) objects automatically get the set and adjust methods from all other installed colorspaces, so although you can use the explicit conversion methods ({@link one.color.CMYK#toRGB}, {@link one.color.CMYK#toHSL}...), the below will work just fine:</p><pre><code>

new one.color.CMYK(.4, .2, .4, .9, .2). // CMYK with alpha setBlue(-.2). // Implicit conversion to RGB (with alpha) adjustHue(-.1). // Implicit conversion to HSL(/HSV) (with alpha) toCSSWithAlpha(); // "rgba(20,13,0,0.2)" </code></pre> - stati: c

  • constructo: r

Create a new one.color.CMYK object. Component values outside the supported range, [0..1], will be adjusted automatically. ##

  • param: Number c The cyan component, range: [0..1]

  • param: Number m The magenta component, range: [0..1]

  • param: Number y The yellow component, range: [0..1]

  • param: Number k The black component, range: [0..1]

  • param: Number [a] The alpha value, range: [0..1],

defaults to 1

  • name: one .color.CMYK.prototype.c
  • propert: y

  • type: Number

  • description: The cyan component, range: [0..1]

  • name: one .color.CMYK.prototype.m
  • propert: y

  • type: Number

  • description: The magenta component, range: [0..1]

  • name: one .color.CMYK.prototype.y
  • propert: y

  • type: Number

  • description: The yellow component, range: [0..1]

  • name: one .color.CMYK.prototype.k
  • propert: y

  • type: Number

  • description: The black component, range: [0..1]

  • name: one .color.CMYK.prototype.a
  • propert: y

  • type: Number

  • description: The alpha value, range: [0..1]

  • name: one .color.CMYK.prototype.setCyan
  • functio: n

  • param: Number c The new cyan component, range: [0..1]

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.setMagenta
  • functio: n

  • param: Number m The new magenta component, range: [0..1]

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.setYellow
  • functio: n

  • param: Number y The new yellow component, range: [0..1]

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.setBlack
  • functio: n

  • param: Number k The new black component, range: [0..1]

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.setAlpha
  • functio: n

  • param: Number a The new alpha value, range: [0..1]

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.adjustCyan
  • functio: n

  • param: Number c The value to add to the cyan component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.adjustMagenta
  • functio: n

  • param: Number m The value to add to the magenta component. If the

resulting value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.adjustYellow
  • functio: n

  • param: Number y The value to add to the yellow component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.adjustBlack
  • functio: n

  • param: Number k The value to add to the black component. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.adjustAlpha
  • functio: n

  • param: Number a The value to add to the alpha value. If the resulting

value falls outside the supported range, [0..1], it will be adjusted automatically.

  • return: one.color.CMYK New color object with the changed value.

  • name: one .color.CMYK.prototype.toJSON
  • description: Convert the color to a JSON representation.
  • functio: n

  • return: Array

  • name: one .color.CMYK.prototype.toRGB
  • description: Convert the color to a {@link one.color.RGB} object.
  • functio: n

  • return: one.color.RGB

  • name: one .color.CMYK.prototype.toHSV
  • description: Convert the color to a {@link one.color.HSV} object.
  • functio: n

  • requires: one .color.HSV ##

  • return: one.color.HSV

  • name: one .color.CMYK.prototype.toHSL
  • description: Convert the color to a {@link one.color.HSL} object.
  • functio: n

  • requires: one .color.HSL ##

  • return: one.color.HSL

  • name: one .color.CMYK.prototype.toCMYK
  • description: Convert the color to a {@link one.color.CMYK} object, ie. return the object itself.
  • functio: n

  • return: one.color.CMYK

  • name: one .color.CMYK.prototype.toHex
  • description: Get the standard RGB hex representation of the color.
  • functio: n

  • return: String The hex string, e.g. "#f681df"

  • name: one .color.CMYK.prototype.toCSS
  • description: Get a valid CSS color representation of the color without an alpha value.
  • functio: n

  • return: String The CSS color string, e.g. "rgb(123, 2, 202)"

  • name: one .color.CMYK.prototype.toCSSWithAlpha
  • description: Get a valid CSS color representation of the color, including the alpha value.
  • functio: n

  • return: String The CSS color string, e.g. "rgba(123, 2, 202, 0.253)"

one.color.installColorSpace('CMYK', ['Cyan', 'Magenta', 'Yellow', 'blacK', 'Alpha'], {
    toRGB: function () {
        return new one.color.RGB((1 - this.c * (1 - this.k) - this.k),
                                 (1 - this.m * (1 - this.k) - this.k),
                                 (1 - this.y * (1 - this.k) - this.k),
                                 this.a);
    },

    fromRGB: function () { // Becomes one.color.RGB.prototype.toCMYK
        // Adapted from http://www.javascripter.net/faq/rgb2cmyk.htm
        var c = 1 - this.r,
            m = 1 - this.g,
            y = 1 - this.b,
            k = 1;
        if (this.r || this.g || this.b) {
            k = Math.min(c, Math.min(m, y));
            c = (c - k) / (1 - k);
            m = (m - k) / (1 - k);
            y = (y - k) / (1 - k);
        } else {
            k = 1;
        }
        return new one.color.CMYK(c, m, y, k, this.a);
    }
});

// This file is purely for the build system

if (module) {
	module.exports = one.color;
}