From 1354d17270961fff662d40f90521223f8fd0d73b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 14 Aug 2012 18:59:10 +0400 Subject: update dojo to 1.7.3 --- lib/dojo/_base/Color.js | 224 +----------------------------------------------- 1 file changed, 2 insertions(+), 222 deletions(-) (limited to 'lib/dojo/_base/Color.js') diff --git a/lib/dojo/_base/Color.js b/lib/dojo/_base/Color.js index 4707fa582..ad8e0ab3c 100644 --- a/lib/dojo/_base/Color.js +++ b/lib/dojo/_base/Color.js @@ -4,225 +4,5 @@ see: http://dojotoolkit.org/license for details */ - -if(!dojo._hasResource["dojo._base.Color"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojo._base.Color"] = true; -dojo.provide("dojo._base.Color"); -dojo.require("dojo._base.array"); -dojo.require("dojo._base.lang"); - - -(function(){ - - var d = dojo; - - dojo.Color = function(/*Array|String|Object*/ color){ - // summary: - // Takes a named string, hex string, array of rgb or rgba values, - // an object with r, g, b, and a properties, or another `dojo.Color` object - // and creates a new Color instance to work from. - // - // example: - // Work with a Color instance: - // | var c = new dojo.Color(); - // | c.setColor([0,0,0]); // black - // | var hex = c.toHex(); // #000000 - // - // example: - // Work with a node's color: - // | var color = dojo.style("someNode", "backgroundColor"); - // | var n = new dojo.Color(color); - // | // adjust the color some - // | n.r *= .5; - // | console.log(n.toString()); // rgb(128, 255, 255); - if(color){ this.setColor(color); } - }; - - // FIXME: - // there's got to be a more space-efficient way to encode or discover - // these!! Use hex? - dojo.Color.named = { - black: [0,0,0], - silver: [192,192,192], - gray: [128,128,128], - white: [255,255,255], - maroon: [128,0,0], - red: [255,0,0], - purple: [128,0,128], - fuchsia: [255,0,255], - green: [0,128,0], - lime: [0,255,0], - olive: [128,128,0], - yellow: [255,255,0], - navy: [0,0,128], - blue: [0,0,255], - teal: [0,128,128], - aqua: [0,255,255], - transparent: d.config.transparentColor || [255,255,255] - }; - - dojo.extend(dojo.Color, { - r: 255, g: 255, b: 255, a: 1, - _set: function(r, g, b, a){ - var t = this; t.r = r; t.g = g; t.b = b; t.a = a; - }, - setColor: function(/*Array|String|Object*/ color){ - // summary: - // Takes a named string, hex string, array of rgb or rgba values, - // an object with r, g, b, and a properties, or another `dojo.Color` object - // and sets this color instance to that value. - // - // example: - // | var c = new dojo.Color(); // no color - // | c.setColor("#ededed"); // greyish - if(d.isString(color)){ - d.colorFromString(color, this); - }else if(d.isArray(color)){ - d.colorFromArray(color, this); - }else{ - this._set(color.r, color.g, color.b, color.a); - if(!(color instanceof d.Color)){ this.sanitize(); } - } - return this; // dojo.Color - }, - sanitize: function(){ - // summary: - // Ensures the object has correct attributes - // description: - // the default implementation does nothing, include dojo.colors to - // augment it with real checks - return this; // dojo.Color - }, - toRgb: function(){ - // summary: - // Returns 3 component array of rgb values - // example: - // | var c = new dojo.Color("#000000"); - // | console.log(c.toRgb()); // [0,0,0] - var t = this; - return [t.r, t.g, t.b]; // Array - }, - toRgba: function(){ - // summary: - // Returns a 4 component array of rgba values from the color - // represented by this object. - var t = this; - return [t.r, t.g, t.b, t.a]; // Array - }, - toHex: function(){ - // summary: - // Returns a CSS color string in hexadecimal representation - // example: - // | console.log(new dojo.Color([0,0,0]).toHex()); // #000000 - var arr = d.map(["r", "g", "b"], function(x){ - var s = this[x].toString(16); - return s.length < 2 ? "0" + s : s; - }, this); - return "#" + arr.join(""); // String - }, - toCss: function(/*Boolean?*/ includeAlpha){ - // summary: - // Returns a css color string in rgb(a) representation - // example: - // | var c = new dojo.Color("#FFF").toCss(); - // | console.log(c); // rgb('255','255','255') - var t = this, rgb = t.r + ", " + t.g + ", " + t.b; - return (includeAlpha ? "rgba(" + rgb + ", " + t.a : "rgb(" + rgb) + ")"; // String - }, - toString: function(){ - // summary: - // Returns a visual representation of the color - return this.toCss(true); // String - } - }); - - dojo.blendColors = function( - /*dojo.Color*/ start, - /*dojo.Color*/ end, - /*Number*/ weight, - /*dojo.Color?*/ obj - ){ - // summary: - // Blend colors end and start with weight from 0 to 1, 0.5 being a 50/50 blend, - // can reuse a previously allocated dojo.Color object for the result - var t = obj || new d.Color(); - d.forEach(["r", "g", "b", "a"], function(x){ - t[x] = start[x] + (end[x] - start[x]) * weight; - if(x != "a"){ t[x] = Math.round(t[x]); } - }); - return t.sanitize(); // dojo.Color - }; - - dojo.colorFromRgb = function(/*String*/ color, /*dojo.Color?*/ obj){ - // summary: - // Returns a `dojo.Color` instance from a string of the form - // "rgb(...)" or "rgba(...)". Optionally accepts a `dojo.Color` - // object to update with the parsed value and return instead of - // creating a new object. - // returns: - // A dojo.Color object. If obj is passed, it will be the return value. - var m = color.toLowerCase().match(/^rgba?\(([\s\.,0-9]+)\)/); - return m && dojo.colorFromArray(m[1].split(/\s*,\s*/), obj); // dojo.Color - }; - - dojo.colorFromHex = function(/*String*/ color, /*dojo.Color?*/ obj){ - // summary: - // Converts a hex string with a '#' prefix to a color object. - // Supports 12-bit #rgb shorthand. Optionally accepts a - // `dojo.Color` object to update with the parsed value. - // - // returns: - // A dojo.Color object. If obj is passed, it will be the return value. - // - // example: - // | var thing = dojo.colorFromHex("#ededed"); // grey, longhand - // - // example: - // | var thing = dojo.colorFromHex("#000"); // black, shorthand - var t = obj || new d.Color(), - bits = (color.length == 4) ? 4 : 8, - mask = (1 << bits) - 1; - color = Number("0x" + color.substr(1)); - if(isNaN(color)){ - return null; // dojo.Color - } - d.forEach(["b", "g", "r"], function(x){ - var c = color & mask; - color >>= bits; - t[x] = bits == 4 ? 17 * c : c; - }); - t.a = 1; - return t; // dojo.Color - }; - - dojo.colorFromArray = function(/*Array*/ a, /*dojo.Color?*/ obj){ - // summary: - // Builds a `dojo.Color` from a 3 or 4 element array, mapping each - // element in sequence to the rgb(a) values of the color. - // example: - // | var myColor = dojo.colorFromArray([237,237,237,0.5]); // grey, 50% alpha - // returns: - // A dojo.Color object. If obj is passed, it will be the return value. - var t = obj || new d.Color(); - t._set(Number(a[0]), Number(a[1]), Number(a[2]), Number(a[3])); - if(isNaN(t.a)){ t.a = 1; } - return t.sanitize(); // dojo.Color - }; - - dojo.colorFromString = function(/*String*/ str, /*dojo.Color?*/ obj){ - // summary: - // Parses `str` for a color value. Accepts hex, rgb, and rgba - // style color values. - // description: - // Acceptable input values for str may include arrays of any form - // accepted by dojo.colorFromArray, hex strings such as "#aaaaaa", or - // rgb or rgba strings such as "rgb(133, 200, 16)" or "rgba(10, 10, - // 10, 50)" - // returns: - // A dojo.Color object. If obj is passed, it will be the return value. - var a = d.Color.named[str]; - return a && d.colorFromArray(a, obj) || d.colorFromRgb(str, obj) || d.colorFromHex(str, obj); - }; -})(); - -} +//>>built +define("dojo/_base/Color",["./kernel","./lang","./array","./config"],function(_1,_2,_3,_4){var _5=_1.Color=function(_6){if(_6){this.setColor(_6);}};_5.named={"black":[0,0,0],"silver":[192,192,192],"gray":[128,128,128],"white":[255,255,255],"maroon":[128,0,0],"red":[255,0,0],"purple":[128,0,128],"fuchsia":[255,0,255],"green":[0,128,0],"lime":[0,255,0],"olive":[128,128,0],"yellow":[255,255,0],"navy":[0,0,128],"blue":[0,0,255],"teal":[0,128,128],"aqua":[0,255,255],"transparent":_4.transparentColor||[0,0,0,0]};_2.extend(_5,{r:255,g:255,b:255,a:1,_set:function(r,g,b,a){var t=this;t.r=r;t.g=g;t.b=b;t.a=a;},setColor:function(_7){if(_2.isString(_7)){_5.fromString(_7,this);}else{if(_2.isArray(_7)){_5.fromArray(_7,this);}else{this._set(_7.r,_7.g,_7.b,_7.a);if(!(_7 instanceof _5)){this.sanitize();}}}return this;},sanitize:function(){return this;},toRgb:function(){var t=this;return [t.r,t.g,t.b];},toRgba:function(){var t=this;return [t.r,t.g,t.b,t.a];},toHex:function(){var _8=_3.map(["r","g","b"],function(x){var s=this[x].toString(16);return s.length<2?"0"+s:s;},this);return "#"+_8.join("");},toCss:function(_9){var t=this,_a=t.r+", "+t.g+", "+t.b;return (_9?"rgba("+_a+", "+t.a:"rgb("+_a)+")";},toString:function(){return this.toCss(true);}});_5.blendColors=_1.blendColors=function(_b,_c,_d,_e){var t=_e||new _5();_3.forEach(["r","g","b","a"],function(x){t[x]=_b[x]+(_c[x]-_b[x])*_d;if(x!="a"){t[x]=Math.round(t[x]);}});return t.sanitize();};_5.fromRgb=_1.colorFromRgb=function(_f,obj){var m=_f.toLowerCase().match(/^rgba?\(([\s\.,0-9]+)\)/);return m&&_5.fromArray(m[1].split(/\s*,\s*/),obj);};_5.fromHex=_1.colorFromHex=function(_10,obj){var t=obj||new _5(),_11=(_10.length==4)?4:8,_12=(1<<_11)-1;_10=Number("0x"+_10.substr(1));if(isNaN(_10)){return null;}_3.forEach(["b","g","r"],function(x){var c=_10&_12;_10>>=_11;t[x]=_11==4?17*c:c;});t.a=1;return t;};_5.fromArray=_1.colorFromArray=function(a,obj){var t=obj||new _5();t._set(Number(a[0]),Number(a[1]),Number(a[2]),Number(a[3]));if(isNaN(t.a)){t.a=1;}return t.sanitize();};_5.fromString=_1.colorFromString=function(str,obj){var a=_5.named[str];return a&&_5.fromArray(a,obj)||_5.fromRgb(str,obj)||_5.fromHex(str,obj);};return _5;}); \ No newline at end of file -- cgit v1.2.3