Comparing version 2.0.1 to 2.0.2
@@ -36,3 +36,11 @@ /*global one*/ | ||
one.color = function (obj) { | ||
if (obj.charCodeAt) { | ||
if (Object.prototype.toString.apply(obj) === '[object Array]') { | ||
if (obj[0].length === 4) { | ||
// Assumed 4 element int RGB array from canvas with all channels [0;255] | ||
return new one.color.RGB(obj[0] / 255, obj[1] / 255, obj[2] / 255, obj[3] / 255); | ||
} else { | ||
// Assumed destringified array from one.color.JSON() | ||
return new one.color[obj[0]](obj.slice(1, obj.length)); | ||
} | ||
} else if (obj.charCodeAt) { | ||
// Test for CSS rgb(....) string | ||
@@ -73,4 +81,2 @@ var matchCssSyntax = obj.match(cssColorRegExp); | ||
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)) { | ||
@@ -77,0 +83,0 @@ // Strange integer representation sometimes returned by document.queryCommandValue in some browser... |
@@ -49,3 +49,11 @@ /*global window*/ | ||
one.color = function (obj) { | ||
if (obj.charCodeAt) { | ||
if (Object.prototype.toString.apply(obj) === '[object Array]') { | ||
if (obj[0].length === 4) { | ||
// Assumed 4 element int RGB array from canvas with all channels [0;255] | ||
return new one.color.RGB(obj[0] / 255, obj[1] / 255, obj[2] / 255, obj[3] / 255); | ||
} else { | ||
// Assumed destringified array from one.color.JSON() | ||
return new one.color[obj[0]](obj.slice(1, obj.length)); | ||
} | ||
} else if (obj.charCodeAt) { | ||
// Test for CSS rgb(....) string | ||
@@ -86,4 +94,2 @@ var matchCssSyntax = obj.match(cssColorRegExp); | ||
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)) { | ||
@@ -90,0 +96,0 @@ // Strange integer representation sometimes returned by document.queryCommandValue in some browser... |
@@ -1,1 +0,1 @@ | ||
if(typeof window!=="undefined"){window.one=window.one||{}}else{var one={}}one.include=one.exclude=function(){};(function(){var d=[],b=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,a=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,c=new RegExp("^(rgb|hsl|hsv)a?\\("+b.source+","+b.source+","+b.source+"(?:,"+a.source+")?\\)$","i");one.color=function(l){if(l.charCodeAt){var i=l.match(c);if(i){var m=i[1].toUpperCase(),k=typeof i[8]==="undefined"?i[8]:parseFloat(i[8]),e=m[0]==="H",g=i[3]?100:(e?360:255),h=(i[5]||e)?100:255,j=(i[7]||e)?100:255;if(!(m in one.color)){throw new Error("one.color."+m+" is not installed.")}return new one.color[m](parseFloat(i[2])/g,parseFloat(i[4])/h,parseFloat(i[6])/j,k)}if(l.length<6){l=l.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3")}var f=l.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(f){return new one.color.RGB(parseInt(f[1],16)/255,parseInt(f[2],16)/255,parseInt(f[3],16)/255)}}else{if(typeof l==="object"&&l.isColor){return l}else{if(Object.prototype.toString.apply(l)==="[object Array]"){return new one.color[l[0]](l.slice(1,l.length))}else{if(!isNaN(l)){return new one.color.RGB((l&255)/255,((l&65280)>>8)/255,((l&16711680)>>16)/255)}}}}return false};one.color.installColorSpace=function(k,h,j){one.color[k]=new Function(h.join(","),"if (Object.prototype.toString.apply("+h[0]+") === '[object Array]') {"+h.map(function(l,m){return l+"="+h[0]+"["+m+"];"}).reverse().join("")+"}if ("+h.filter(function(l){return l!=="alpha"}).map(function(l){return"isNaN("+l+")"}).join("||")+'){throw new Error("[one.color.'+k+']: Invalid color: ("+'+h.join('+","+')+'+")");}'+h.map(function(l){if(l==="hue"){return"this._hue=hue<0?hue-Math.floor(hue):hue%1"}else{if(l==="alpha"){return"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);"}else{return"this._"+l+"="+l+"<0?0:("+l+">1?1:"+l+")"}}}).join(";")+";");one.color[k].propertyNames=h;var i=one.color[k].prototype;["valueOf","hex","css","cssa"].forEach(function(l){i[l]=i[l]||(k==="RGB"?i.hex:new Function("return this.rgb()."+l+"();"))});i.isColor=true;i.equals=function(n,m){if(typeof m==="undefined"){m=1e-10}n=n[k.toLowerCase()]();for(var l=0;l<h.length;l=l+1){if(Math.abs(this["_"+h[l]]-n["_"+h[l]])>m){return false}}return true};i.toJSON=new Function("return ['"+k+"', "+h.map(function(l){return"this._"+l},this).join(", ")+"];");for(var g in j){if(j.hasOwnProperty(g)){var f=g.match(/^from(.*)$/);if(f){one.color[f[1].toUpperCase()].prototype[k.toLowerCase()]=j[g]}else{i[g]=j[g]}}}i[k.toLowerCase()]=function(){return this};i.toString=new Function('return "[one.color.'+k+':"+'+h.map(function(l,m){return'" '+h[m]+'="+this._'+l}).join("+")+'+"]";');h.forEach(function(l,m){i[l]=new Function("value","isDelta","if (typeof value === 'undefined') {return this._"+l+";}if (isDelta) {return new this.constructor("+h.map(function(o,n){return"this._"+o+(l===o?"+value":"")}).join(", ")+");}return new this.constructor("+h.map(function(o,n){return l===o?"value":"this._"+o}).join(", ")+");")});function e(m,l){var n={};n[l.toLowerCase()]=new Function("return this.rgb()."+l.toLowerCase()+"();");one.color[l].propertyNames.forEach(function(p,q){n[p]=new Function("value","isDelta","return this."+l.toLowerCase()+"()."+p+"(value, isDelta);")});for(var o in n){if(n.hasOwnProperty(o)&&one.color[m].prototype[o]===undefined){one.color[m].prototype[o]=n[o]}}}d.forEach(function(l){e(k,l);e(l,k)});d.push(k)}}());(function(){var a=Math.round;one.color.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var b=(a(255*this._red)*65536+a(255*this._green)*256+a(255*this._blue)).toString(16);return"#"+("00000".substr(0,6-b.length))+b},css:function(){return"rgb("+a(255*this._red)+","+a(255*this._green)+","+a(255*this._blue)+")"},cssa:function(){return"rgba("+a(255*this._red)+","+a(255*this._green)+","+a(255*this._blue)+","+this._alpha+")"}})}());one.color.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var h=this._hue,g=this._saturation,l=this._value,e=Math.min(5,Math.floor(h*6)),j=h*6-e,b=l*(1-g),a=l*(1-j*g),m=l*(1-(1-j)*g),c,d,k;switch(e){case 0:c=l;d=m;k=b;break;case 1:c=a;d=l;k=b;break;case 2:c=b;d=l;k=m;break;case 3:c=b;d=a;k=l;break;case 4:c=m;d=b;k=l;break;case 5:c=l;d=b;k=a;break}return new one.color.RGB(c,d,k,this._alpha)},hsl:function(){var b=(2-this._saturation)*this._value,a=this._saturation*this._value,d=b<=1?b:(2-b),c;if(d<1e-9){c=0}else{c=a/d}return new one.color.HSL(this._hue,c,b/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,h=this._blue,f=Math.max(a,b,h),c=Math.min(a,b,h),i=f-c,e,d=(f===0)?0:(i/f),g=f;if(i===0){e=0}else{switch(f){case a:e=(b-h)/i/6+(b<h?1:0);break;case b:e=(h-a)/i/6+1/3;break;case h:e=(a-b)/i/6+2/3;break}}return new one.color.HSV(e,d,g,this._alpha)}});one.color.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*((a<=1)?a:2-a),c;if(a+b<1e-9){c=0}else{c=(2*b)/(a+b)}return new one.color.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}});if(typeof module!=="undefined"){module.exports=one.color}; | ||
if(typeof window!=="undefined"){window.one=window.one||{}}else{var one={}}one.include=one.exclude=function(){};(function(){var d=[],b=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,a=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,c=new RegExp("^(rgb|hsl|hsv)a?\\("+b.source+","+b.source+","+b.source+"(?:,"+a.source+")?\\)$","i");one.color=function(l){if(Object.prototype.toString.apply(l)==="[object Array]"){if(l[0].length===4){return new one.color.RGB(l[0]/255,l[1]/255,l[2]/255,l[3]/255)}else{return new one.color[l[0]](l.slice(1,l.length))}}else{if(l.charCodeAt){var i=l.match(c);if(i){var m=i[1].toUpperCase(),k=typeof i[8]==="undefined"?i[8]:parseFloat(i[8]),e=m[0]==="H",g=i[3]?100:(e?360:255),h=(i[5]||e)?100:255,j=(i[7]||e)?100:255;if(!(m in one.color)){throw new Error("one.color."+m+" is not installed.")}return new one.color[m](parseFloat(i[2])/g,parseFloat(i[4])/h,parseFloat(i[6])/j,k)}if(l.length<6){l=l.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3")}var f=l.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(f){return new one.color.RGB(parseInt(f[1],16)/255,parseInt(f[2],16)/255,parseInt(f[3],16)/255)}}else{if(typeof l==="object"&&l.isColor){return l}else{if(!isNaN(l)){return new one.color.RGB((l&255)/255,((l&65280)>>8)/255,((l&16711680)>>16)/255)}}}}return false};one.color.installColorSpace=function(k,h,j){one.color[k]=new Function(h.join(","),"if (Object.prototype.toString.apply("+h[0]+") === '[object Array]') {"+h.map(function(l,m){return l+"="+h[0]+"["+m+"];"}).reverse().join("")+"}if ("+h.filter(function(l){return l!=="alpha"}).map(function(l){return"isNaN("+l+")"}).join("||")+'){throw new Error("[one.color.'+k+']: Invalid color: ("+'+h.join('+","+')+'+")");}'+h.map(function(l){if(l==="hue"){return"this._hue=hue<0?hue-Math.floor(hue):hue%1"}else{if(l==="alpha"){return"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);"}else{return"this._"+l+"="+l+"<0?0:("+l+">1?1:"+l+")"}}}).join(";")+";");one.color[k].propertyNames=h;var i=one.color[k].prototype;["valueOf","hex","css","cssa"].forEach(function(l){i[l]=i[l]||(k==="RGB"?i.hex:new Function("return this.rgb()."+l+"();"))});i.isColor=true;i.equals=function(n,m){if(typeof m==="undefined"){m=1e-10}n=n[k.toLowerCase()]();for(var l=0;l<h.length;l=l+1){if(Math.abs(this["_"+h[l]]-n["_"+h[l]])>m){return false}}return true};i.toJSON=new Function("return ['"+k+"', "+h.map(function(l){return"this._"+l},this).join(", ")+"];");for(var g in j){if(j.hasOwnProperty(g)){var f=g.match(/^from(.*)$/);if(f){one.color[f[1].toUpperCase()].prototype[k.toLowerCase()]=j[g]}else{i[g]=j[g]}}}i[k.toLowerCase()]=function(){return this};i.toString=new Function('return "[one.color.'+k+':"+'+h.map(function(l,m){return'" '+h[m]+'="+this._'+l}).join("+")+'+"]";');h.forEach(function(l,m){i[l]=new Function("value","isDelta","if (typeof value === 'undefined') {return this._"+l+";}if (isDelta) {return new this.constructor("+h.map(function(o,n){return"this._"+o+(l===o?"+value":"")}).join(", ")+");}return new this.constructor("+h.map(function(o,n){return l===o?"value":"this._"+o}).join(", ")+");")});function e(m,l){var n={};n[l.toLowerCase()]=new Function("return this.rgb()."+l.toLowerCase()+"();");one.color[l].propertyNames.forEach(function(p,q){n[p]=new Function("value","isDelta","return this."+l.toLowerCase()+"()."+p+"(value, isDelta);")});for(var o in n){if(n.hasOwnProperty(o)&&one.color[m].prototype[o]===undefined){one.color[m].prototype[o]=n[o]}}}d.forEach(function(l){e(k,l);e(l,k)});d.push(k)}}());(function(){var a=Math.round;one.color.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var b=(a(255*this._red)*65536+a(255*this._green)*256+a(255*this._blue)).toString(16);return"#"+("00000".substr(0,6-b.length))+b},css:function(){return"rgb("+a(255*this._red)+","+a(255*this._green)+","+a(255*this._blue)+")"},cssa:function(){return"rgba("+a(255*this._red)+","+a(255*this._green)+","+a(255*this._blue)+","+this._alpha+")"}})}());one.color.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var h=this._hue,g=this._saturation,l=this._value,e=Math.min(5,Math.floor(h*6)),j=h*6-e,b=l*(1-g),a=l*(1-j*g),m=l*(1-(1-j)*g),c,d,k;switch(e){case 0:c=l;d=m;k=b;break;case 1:c=a;d=l;k=b;break;case 2:c=b;d=l;k=m;break;case 3:c=b;d=a;k=l;break;case 4:c=m;d=b;k=l;break;case 5:c=l;d=b;k=a;break}return new one.color.RGB(c,d,k,this._alpha)},hsl:function(){var b=(2-this._saturation)*this._value,a=this._saturation*this._value,d=b<=1?b:(2-b),c;if(d<1e-9){c=0}else{c=a/d}return new one.color.HSL(this._hue,c,b/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,h=this._blue,f=Math.max(a,b,h),c=Math.min(a,b,h),i=f-c,e,d=(f===0)?0:(i/f),g=f;if(i===0){e=0}else{switch(f){case a:e=(b-h)/i/6+(b<h?1:0);break;case b:e=(h-a)/i/6+1/3;break;case h:e=(a-b)/i/6+2/3;break}}return new one.color.HSV(e,d,g,this._alpha)}});one.color.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*((a<=1)?a:2-a),c;if(a+b<1e-9){c=0}else{c=(2*b)/(a+b)}return new one.color.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}});if(typeof module!=="undefined"){module.exports=one.color}; |
@@ -5,3 +5,3 @@ { | ||
"repository": "git@github.com:One-com/one-color.git", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"maintainers": [ | ||
@@ -18,3 +18,3 @@ { | ||
"devDependencies": { | ||
"assetgraph-builder": "= 0.2.11" | ||
"assetgraph-builder": "= 0.2.36" | ||
}, | ||
@@ -30,3 +30,4 @@ "engines": { | ||
}, | ||
"main": "one-color-debug.js" | ||
"main": "one-color-debug.js", | ||
"prepublish": "make" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2127754
3716