Skip to content
Browse files

Simplify the implementation of fields extra

As a consequence color field classes became abbreviated. So instead of
targeting .color.hue, you'll need to use .color.h instead.
  • Loading branch information...
1 parent 88d0cbe commit 162a76bb943c8b752ca467edf9486a51e3cc852e @bebraw committed Nov 7, 2012
Showing with 34 additions and 59 deletions.
  1. +26 −39 dist/colorjoe.js
  2. +2 −2 dist/colorjoe.min.js
  3. +1 −1 package.json
  4. +5 −17 src/extras.js
View
65 dist/colorjoe.js
@@ -1,4 +1,4 @@
-/*! colorjoe - v0.7.0 - 2012-07-11
+/*! colorjoe - v0.7.0 - 2012-11-07
* http://bebraw.github.com/colorjoe/
* Copyright (c) 2012 Juho Vepsalainen; Licensed MIT */
@@ -295,6 +295,7 @@ function usedStyle(element, property) {
}
}));
+/*jshint evil:true, onevar:false*/
/*global define*/
var installedColorSpaces = [],
namedColors = {},
@@ -312,7 +313,7 @@ var installedColorSpaces = [],
"(?:," + alphaChannelRegExp.source + ")?" +
"\\)$", "i");
-function ONECOLOR (obj) {
+function ONECOLOR(obj) {
if (Object.prototype.toString.apply(obj) === '[object Array]') {
if (obj.length === 4) {
// Assumed 4 element int RGB array from canvas with all channels [0;255]
@@ -366,9 +367,8 @@ function ONECOLOR (obj) {
return new ONECOLOR.RGB((obj & 0xFF) / 255, ((obj & 0xFF00) >> 8) / 255, ((obj & 0xFF0000) >> 16) / 255);
}
return false;
-};
+}
-/*jslint evil:true*/
function installColorSpace(colorSpaceName, propertyNames, config) {
ONECOLOR[colorSpaceName] = new Function(propertyNames.join(","),
// Allow passing an array to the constructor:
@@ -447,7 +447,7 @@ function installColorSpace(colorSpaceName, propertyNames, config) {
// Generate getters and setters
propertyNames.forEach(function (propertyName, i) {
- prototype[propertyName] = new Function("value", "isDelta",
+ prototype[propertyName] = prototype[propertyName === 'black' ? 'k' : propertyName[0]] = new Function("value", "isDelta",
// Simple getter mode: color.red()
"if (typeof value === 'undefined') {" +
"return this._" + propertyName + ";" +
@@ -468,7 +468,7 @@ function installColorSpace(colorSpaceName, propertyNames, config) {
var obj = {};
obj[sourceColorSpaceName.toLowerCase()] = new Function("return this.rgb()." + sourceColorSpaceName.toLowerCase() + "();"); // Fallback
ONECOLOR[sourceColorSpaceName].propertyNames.forEach(function (propertyName, i) {
- obj[propertyName] = new Function("value", "isDelta", "return this." + sourceColorSpaceName.toLowerCase() + "()." + propertyName + "(value, isDelta);");
+ obj[propertyName] = obj[propertyName === 'black' ? 'k' : propertyName[0]] = new Function("value", "isDelta", "return this." + sourceColorSpaceName.toLowerCase() + "()." + propertyName + "(value, isDelta);");
});
for (var prop in obj) {
if (obj.hasOwnProperty(prop) && ONECOLOR[targetColorSpaceName].prototype[prop] === undefined) {
@@ -483,7 +483,7 @@ function installColorSpace(colorSpaceName, propertyNames, config) {
});
installedColorSpaces.push(colorSpaceName);
-};
+}
ONECOLOR.installMethod = function (name, fn) {
installedColorSpaces.forEach(function (colorSpace) {
@@ -509,16 +509,15 @@ installColorSpace('RGB', ['red', 'green', 'blue', 'alpha'], {
if (typeof module !== 'undefined') {
// Node module export
module.exports = ONECOLOR;
+} else if (typeof define === 'function' && !undef(define.amd)) {
+ define([], function () {
+ return ONECOLOR;
+ });
+} else if (typeof jQuery !== 'undefined' && undef(jQuery.color)) {
+ jQuery.color = ONECOLOR;
} else {
- // Browser
- if (typeof define === 'function' && !undef(define.amd)) {
- define([], function () {
- return ONECOLOR;
- });
- } else {
- one = window.one || {};
- one.color = ONECOLOR;
- }
+ one = window.one || {};
+ one.color = ONECOLOR;
}
/*global namedColors*/
@@ -836,7 +835,7 @@ ONECOLOR.installMethod('darken', function (amount) {
});
-ONECOLOR.installMethod('saturate', function (amount) {
+ONECOLOR.installMethod('desaturate', function (amount) {
return this.saturation(isNaN(amount) ? -0.1 : -amount, true);
});
@@ -857,7 +856,7 @@ ONECOLOR.installMethod('lighten', function (amount) {
ONECOLOR.installMethod('mix', function (otherColor, weight) {
otherColor = ONECOLOR(otherColor).rgb();
- weight = 1 - (weight || 0.5);
+ weight = 1 - (isNaN(weight) ? 0.5 : weight);
var w = weight * 2 - 1,
a = this._alpha - otherColor._alpha,
@@ -866,10 +865,10 @@ ONECOLOR.installMethod('mix', function (otherColor, weight) {
rgb = this.rgb();
return new ONECOLOR.RGB(
- this._red * weight1 + otherColor._red * weight2,
- this._green * weight1 + otherColor._green * weight2,
- this._blue * weight1 + otherColor._blue * weight2,
- this._alpha * weight + otherColor._alpha * (1 - weight)
+ rgb._red * weight1 + otherColor._red * weight2,
+ rgb._green * weight1 + otherColor._green * weight2,
+ rgb._blue * weight1 + otherColor._blue * weight2,
+ rgb._alpha * weight + otherColor._alpha * (1 - weight)
);
});
@@ -1039,24 +1038,10 @@ function fields(p, joe, o) {
var cs = o.space;
var fac = o.limit || 255;
var fix = o.fix >= 0? o.fix: 0;
- var methods = {
- R: 'red',
- G: 'green',
- B: 'blue',
- H: 'hue',
- S: 'saturation',
- V: 'value',
- L: 'lightness',
- C: 'cyan',
- M: 'magenta',
- Y: 'yellow',
- K: 'black',
- A: 'alpha'
- };
var inputLen = ('' + fac).length + fix;
inputLen = fix? inputLen + 1: inputLen;
- var initials = cs.split('').map(function(n) {return n.toUpperCase();});
+ var initials = cs.split('');
var useAlpha = cs[cs.length - 1] == 'A';
cs = useAlpha? cs.slice(0, -1): cs;
@@ -1065,7 +1050,9 @@ function fields(p, joe, o) {
var c = utils.div('colorFields', p);
var elems = initials.map(function(n, i) {
- var e = utils.labelInput('color ' + methods[n], n, c, inputLen);
+ n = n.toLowerCase();
+
+ var e = utils.labelInput('color ' + n, n, c, inputLen);
e.input.onkeyup = update;
return {name: n, e: e};
@@ -1084,7 +1071,7 @@ function fields(p, joe, o) {
return {
change: function(col) {
elems.forEach(function(o) {
- o.e.input.value = (col[methods[o.name]]() * fac).toFixed(fix);
+ o.e.input.value = (col[o.name]() * fac).toFixed(fix);
});
}
};
View
4 dist/colorjoe.min.js
@@ -1,4 +1,4 @@
-/*! colorjoe - v0.7.0 - 2012-07-11
+/*! colorjoe - v0.7.0 - 2012-11-07
* http://bebraw.github.com/colorjoe/
* Copyright (c) 2012 Juho Vepsalainen; Licensed MIT */
-function ONECOLOR(a){if(Object.prototype.toString.apply(a)==="[object Array]")return a.length===4?new ONECOLOR.RGB(a[0]/255,a[1]/255,a[2]/255,a[3]/255):new ONECOLOR[a[0]](a.slice(1,a.length));if(typeof a=="string"){var b=a.toLowerCase();namedColors[b]&&(a="#"+namedColors[b]);var c=a.match(cssColorRegExp);if(c){var d=c[1].toUpperCase(),e=undef(c[8])?c[8]:parseFloat(c[8]),f=d[0]==="H",g=c[3]?100:f?360:255,h=c[5]||f?100:255,i=c[7]||f?100:255;if(undef(ONECOLOR[d]))throw new Error("one.color."+d+" is not installed.");return new ONECOLOR[d](parseFloat(c[2])/g,parseFloat(c[4])/h,parseFloat(c[6])/i,e)}a.length<6&&(a=a.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var j=a.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(j)return new ONECOLOR.RGB(parseInt(j[1],16)/255,parseInt(j[2],16)/255,parseInt(j[3],16)/255)}else{if(typeof a=="object"&&a.isColor)return a;if(!isNaN(a))return new ONECOLOR.RGB((a&255)/255,((a&65280)>>8)/255,((a&16711680)>>16)/255)}return!1}function installColorSpace(a,b,c){function g(a,b){var c={};c[b.toLowerCase()]=new Function("return this.rgb()."+b.toLowerCase()+"();"),ONECOLOR[b].propertyNames.forEach(function(a,d){c[a]=new Function("value","isDelta","return this."+b.toLowerCase()+"()."+a+"(value, isDelta);")});for(var d in c)c.hasOwnProperty(d)&&ONECOLOR[a].prototype[d]===undefined&&(ONECOLOR[a].prototype[d]=c[d])}ONECOLOR[a]=new Function(b.join(","),"if (Object.prototype.toString.apply("+b[0]+") === '[object Array]') {"+b.map(function(a,c){return a+"="+b[0]+"["+c+"];"}).reverse().join("")+"}"+"if ("+b.filter(function(a){return a!=="alpha"}).map(function(a){return"isNaN("+a+")"}).join("||")+"){"+'throw new Error("['+a+']: Invalid color: ("+'+b.join('+","+')+'+")");}'+b.map(function(a){return a==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":a==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+a+"="+a+"<0?0:("+a+">1?1:"+a+")"}).join(";")+";"),ONECOLOR[a].propertyNames=b;var d=ONECOLOR[a].prototype;["valueOf","hex","css","cssa"].forEach(function(b){d[b]=d[b]||(a==="RGB"?d.hex:new Function("return this.rgb()."+b+"();"))}),d.isColor=!0,d.equals=function(c,d){undef(d)&&(d=1e-10),c=c[a.toLowerCase()]();for(var e=0;e<b.length;e=e+1)if(Math.abs(this["_"+b[e]]-c["_"+b[e]])>d)return!1;return!0},d.toJSON=new Function("return ['"+a+"', "+b.map(function(a){return"this._"+a},this).join(", ")+"];");for(var e in c)if(c.hasOwnProperty(e)){var f=e.match(/^from(.*)$/);f?ONECOLOR[f[1].toUpperCase()].prototype[a.toLowerCase()]=c[e]:d[e]=c[e]}d[a.toLowerCase()]=function(){return this},d.toString=new Function('return "[one.color.'+a+':"+'+b.map(function(a,c){return'" '+b[c]+'="+this._'+a}).join("+")+'+"]";'),b.forEach(function(a,c){d[a]=new Function("value","isDelta","if (typeof value === 'undefined') {return this._"+a+";"+"}"+"if (isDelta) {"+"return new this.constructor("+b.map(function(b,c){return"this._"+b+(a===b?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+b.map(function(b,c){return a===b?"value":"this._"+b}).join(", ")+");")}),installedColorSpaces.forEach(function(b){g(a,b),g(b,a)}),installedColorSpaces.push(a)}function gs(){var a=this.rgb(),b=a._red*.3+a._green*.59+a._blue*.11;return new ONECOLOR.RGB(b,b,b,this._alpha)}(function(a,b){typeof define=="function"&&define.amd?define(b):a.drag=b()})(this,function(){function a(a,b){if(!a){console.warn("drag is missing elem!");return}g()?h(a,b,"touchstart","touchmove","touchend"):h(a,b,"mousedown","mousemove","mouseup")}function b(b){var c=e(b["class"]||"",b.parent),f=e("pointer",c);return e("shape shape1",f),e("shape shape2",f),e("bg bg1",c),e("bg bg2",c),a(c,d(b.cbs,f)),{background:c,pointer:f}}function c(b){var c=e(b["class"],b.parent),f=e("pointer",c);return e("shape",f),e("bg",c),a(c,d(b.cbs,f)),{background:c,pointer:f}}function d(a,b){function e(a){return function(c){c.pointer=b,a(c)}}var c={};for(var d in a)c[d]=e(a[d]);return c}function e(a,b){return f("div",a,b)}function f(a,b,c){var d=document.createElement(a);return b&&(d.className=b),c.appendChild(d),d}function g(){return typeof window.ontouchstart!="undefined"}function h(a,b,c,d,e){var f=!1;b=k(b);var g=b.begin,h=b.change,l=b.end;i(a,c,function(b){function k(){f=!1,j(document,d,c),j(document,e,k),n(l,a,b)}f=!0;var c=o(n,h,a);i(document,d,c),i(document,e,k),n(g,a,b)})}function i(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)}function j(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)}function k(a){if(!a){var b,c;return{begin:function(a){b={x:a.elem.offsetLeft,y:a.elem.offsetTop},c=a.cursor},change:function(a){l(a.elem,"left",b.x+a.cursor.x-c.x+"px"),l(a.elem,"top",b.y+a.cursor.y-c.y+"px")},end:m}}return{begin:a.begin||m,change:a.change||m,end:a.end||m}}function l(a,b,c){a.style[b]=c}function m(){}function n(a,b,c){c.preventDefault();var d=p(b),e=b.clientWidth,f=b.clientHeight,g={x:q(b,c),y:r(b,c)},h=(g.x-d.x)/e,i=(g.y-d.y)/f;a({x:isNaN(h)?0:h,y:isNaN(i)?0:i,cursor:g,elem:b,e:c})}function o(a){var b=Array.prototype.slice,c=b.apply(arguments,[1]);return function(){return a.apply(null,c.concat(b.apply(arguments)))}}function p(a){var b=0,c=0;if(a.offsetParent)do b+=a.offsetLeft,c+=a.offsetTop;while(a=a.offsetParent);return{x:b,y:c}}function q(a,b){if(t(a)){var c=parseInt(u(document.body,"marginLeft"),10)-s(a,"scrollLeft")+window.pageXOffset+a.style.marginLeft;return b.clientX-c}if(b.pageX)return b.pageX;if(b.clientX)return b.clientX+document.body.scrollLeft}function r(a,b){if(t(a)){var c=parseInt(u(document.body,"marginTop"),10)-s(a,"scrollTop")+window.pageYOffset+a.style.marginTop;return b.clientY-c}if(b.pageY)return b.pageY;if(b.clientY)return b.clientY+document.body.scrollTop}function s(a,b){var c=0;while(a.nodeName!="HTML")c+=a[b],a=a.parentNode;return c}function t(a){while(a.nodeName!="HTML"&&v(a,"position")!="fixed")a=a.parentNode;return a.nodeName=="HTML"?!1:!0}function u(a,b){return a.currentStyle?a.currentStyle[b]:document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(a,"")[b]:a.style[b]}function v(a,b){var c;return window.getComputedStyle?c=window.getComputedStyle(a,null):c=a.currentStyle,c[b]}return a.xyslider=b,a.slider=c,a});var installedColorSpaces=[],namedColors={},undef=function(a){return typeof a=="undefined"},channelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,alphaChannelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,cssColorRegExp=new RegExp("^(rgb|hsl|hsv)a?\\("+channelRegExp.source+","+channelRegExp.source+","+channelRegExp.source+"(?:,"+alphaChannelRegExp.source+")?"+"\\)$","i");ONECOLOR.installMethod=function(a,b){installedColorSpaces.forEach(function(c){ONECOLOR[c].prototype[a]=b})},installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var a=(Math.round(255*this._red)*65536+Math.round(255*this._green)*256+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-a.length)+a},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}}),typeof module!="undefined"?module.exports=ONECOLOR:typeof define=="function"&&!undef(define.amd)?define([],function(){return ONECOLOR}):(one=window.one||{},one.color=ONECOLOR),namedColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgrey:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var a=this._hue,b=this._saturation,c=this._value,d=Math.min(5,Math.floor(a*6)),e=a*6-d,f=c*(1-b),g=c*(1-e*b),h=c*(1-(1-e)*b),i,j,k;switch(d){case 0:i=c,j=h,k=f;break;case 1:i=g,j=c,k=f;break;case 2:i=f,j=c,k=h;break;case 3:i=f,j=g,k=c;break;case 4:i=h,j=f,k=c;break;case 5:i=c,j=f,k=g}return new ONECOLOR.RGB(i,j,k,this._alpha)},hsl:function(){var a=(2-this._saturation)*this._value,b=this._saturation*this._value,c=a<=1?a:2-a,d;return c<1e-9?d=0:d=b/c,new ONECOLOR.HSL(this._hue,d,a/2,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=Math.max(a,b,c),e=Math.min(a,b,c),f=d-e,g,h=d===0?0:f/d,i=d;if(f===0)g=0;else switch(d){case a:g=(b-c)/f/6+(b<c?1:0);break;case b:g=(c-a)/f/6+1/3;break;case c:g=(a-b)/f/6+2/3}return new ONECOLOR.HSV(g,h,i,this._alpha)}}),installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var a=this._lightness*2,b=this._saturation*(a<=1?a:2-a),c;return a+b<1e-9?c=0:c=2*b/(a+b),new ONECOLOR.HSV(this._hue,c,(a+b)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}}),installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new ONECOLOR.RGB(1-this._cyan*(1-this._black)-this._black,1-this._magenta*(1-this._black)-this._black,1-this._yellow*(1-this._black)-this._black,this._alpha)},fromRgb:function(){var a=this._red,b=this._green,c=this._blue,d=1-a,e=1-b,f=1-c,g=1;return a||b||c?(g=Math.min(d,Math.min(e,f)),d=(d-g)/(1-g),e=(e-g)/(1-g),f=(f-g)/(1-g)):g=1,new ONECOLOR.CMYK(d,e,f,g,this._alpha)}}),ONECOLOR.installMethod("clearer",function(a){return this.alpha(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("darken",function(a){return this.lightness(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("saturate",function(a){return this.saturation(isNaN(a)?-0.1:-a,!0)}),ONECOLOR.installMethod("greyscale",gs),ONECOLOR.installMethod("grayscale",gs),ONECOLOR.installMethod("lighten",function(a){return this.lightness(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("mix",function(a,b){a=ONECOLOR(a).rgb(),b=1-(b||.5);var c=b*2-1,d=this._alpha-a._alpha,e=((c*d===-1?c:(c+d)/(1+c*d))+1)/2,f=1-e,g=this.rgb();return new ONECOLOR.RGB(this._red*e+a._red*f,this._green*e+a._green*f,this._blue*e+a._blue*f,this._alpha*b+a._alpha*(1-b))}),ONECOLOR.installMethod("negate",function(){var a=this.rgb();return new ONECOLOR.RGB(1-a._red,1-a._green,1-a._blue,this._alpha)}),ONECOLOR.installMethod("opaquer",function(a){return this.alpha(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("rotate",function(a){return this.hue((a||0)/360,!0)}),ONECOLOR.installMethod("saturate",function(a){return this.saturation(isNaN(a)?.1:a,!0)}),ONECOLOR.installMethod("toAlpha",function(a){var b=this.rgb(),c=ONECOLOR(a).rgb(),d=1e-10,e=new ONECOLOR.RGB(0,0,0,b._alpha),f=["_red","_green","_blue"];return f.forEach(function(a){b[a]<d?e[a]=b[a]:b[a]>c[a]?e[a]=(b[a]-c[a])/(1-c[a]):b[a]>c[a]?e[a]=(c[a]-b[a])/c[a]:e[a]=0}),e._red>e._green?e._red>e._blue?b._alpha=e._red:b._alpha=e._blue:e._green>e._blue?b._alpha=e._green:b._alpha=e._blue,b._alpha<d?b:(f.forEach(function(a){b[a]=(b[a]-c[a])/b._alpha+c[a]}),b._alpha*=e._alpha,b)}),function(a,b){typeof exports=="object"?module.exports=b():typeof define=="function"&&define.amd?define(b):a.elemutils=b()}(this,function(){function b(a,b,c){var d=document.createElement(a);return d.className=b,c.appendChild(d),d}function c(a){var b=Array.prototype.slice,c=b.apply(arguments,[1]);return function(){return a.apply(null,c.concat(b.apply(arguments)))}}function d(b,c,d,g){var h=a(b,d),i=e(c,h),j=f("text",h,g);return{label:i,input:j}}function e(a,c){var d=b("label","",c);return d.innerHTML=a,d}function f(a,c,d){var e=b("input","",c);return e.type=a,d&&(e.maxLength=d),e}function g(a,b){a.style.left=j(b*100,0,100)+"%"}function h(a,b){a.style.top=j(b*100,0,100)+"%"}function i(a,b){a.style.background=b}function j(a,b,c){return Math.min(Math.max(a,b),c)}var a=c(b,"div");return{clamp:j,e:b,div:a,partial:c,labelInput:d,X:g,Y:h,BG:i}}),function(a,b){typeof define=="function"&&define.amd?define(["./elemutils","./drag"],b):a.colorjoeextras=b(a.elemutils,a.drag)}(this,function(a,b){function c(b){var c=a.div("currentColorContainer",b),d=a.div("currentColor",c);return{change:function(b){a.BG(d,b.cssa())}}}function d(b,c,d){function n(){var a=[e];m.forEach(function(b){a.push(b.e.input.value/f)}),k||a.push(c.getAlpha()),c.set(a)}var e=d.space,f=d.limit||255,g=d.fix>=0?d.fix:0,h={R:"red",G:"green",B:"blue",H:"hue",S:"saturation",V:"value",L:"lightness",C:"cyan",M:"magenta",Y:"yellow",K:"black",A:"alpha"},i=(""+f).length+g;i=g?i+1:i;var j=e.split("").map(function(a){return a.toUpperCase()}),k=e[e.length-1]=="A";e=k?e.slice(0,-1):e;if(["RGB","HSL","HSV","CMYK"].indexOf(e)<0)return console.warn("Invalid field names",e);var l=a.div("colorFields",b),m=j.map(function(b,c){var d=a.labelInput("color "+h[b],b,l,i);return d.input.onkeyup=n,{name:b,e:d}});return{change:function(a){m.forEach(function(b){b.e.input.value=(a[h[b.name]]()*f).toFixed(g)})}}}function e(c,d){function f(b){var c=a.clamp(b.y,0,1);a.Y(b.pointer,c),d.setAlpha(1-c)}var e=b.slider({parent:c,"class":"oned alpha",cbs:{begin:f,change:f}});return{change:function(b){a.Y(e.pointer,1-b.alpha())}}}function f(b,c,d){var e=a.labelInput("hex",d.label||"",b,7);return e.input.value="#",e.input.onkeyup=function(a){var b=a.target.value;b=b[0]=="#"?b:"#"+b,b=g(b,7,"0"),c.set(b)},{change:function(a){e.input.value=e.input.value[0]=="#"?"#":"",e.input.value+=a.hex().slice(1)}}}function g(a,b,c){var d=a;for(var e=a.length,f=b;e<b;e++)d+=c;return d}return{currentColor:c,fields:d,hex:f,alpha:e}}),function(a,b){typeof define=="function"&&define.amd?define(["./onecolor","./drag","./elemutils","./extras"],b):a.colorjoe=b(a.ONECOLOR,a.drag,a.elemutils,a.colorjoeextras)}(this,function(a,b,c,d){function g(b,d){c.BG(b,(new a.HSV(d,1,1)).cssa())}function h(a){function g(a){m=e.xy(m,{x:c.clamp(a.x,0,1),y:c.clamp(a.y,0,1)},f,h),q()}function k(a){m=e.z(m,c.clamp(a.y,0,1),f,h),q()}function q(a){a=n(a)?a:[];var b=p.change,c;for(var d=0,e=b.length;d<e;d++)c=b[d],a.indexOf(c.name)==-1&&c.fn(m)}function r(){if(l.equals(m))return;for(var a=0,b=p.done.length;a<b;a++)p.done[a](m);l=m}if(!a.e)return console.warn("colorjoe: missing element");var d=o(a.e)?document.getElementById(a.e):a.e;d.className="colorPicker";var e=a.cbs,f=b.xyslider({parent:d,"class":"twod",cbs:{begin:g,change:g,end:r}}),h=b.slider({parent:d,"class":"oned",cbs:{begin:k,change:k,end:r}}),l=i(a.color),m=e.init(l,f,h),p={change:[],done:[]},s={e:d,update:function(a){return q(a),this},get:function(){return m},set:function(a){var b=this.get();return m=e.init(i(a),f,h),b.equals(m)||this.update(),this},getAlpha:function(){return m.alpha()},setAlpha:function(a){return m=m.alpha(a),this.update(),this},on:function(a,b,c){return a=="change"||a=="done"?p[a].push({name:c,fn:b}):console.warn('Passed invalid evt name "'+a+'" to colorjoe.on'),this},removeAllListeners:function(a){if(a)delete p[a];else for(var b in p)delete p[b];return this}};return j(d,s,a.extras),q(),s}function i(b){if(!p(b))return a("black");if(b.isColor)return b;var c=a(b);return c?c:(p(b)&&console.warn("Passed invalid color to colorjoe, using black instead"),a("black"))}function j(a,b,d){if(!d)return;var f=c.div("extras",a),g,h,i;d.forEach(function(a,c){n(a)?(h=a[0],i=a.length>1?a[1]:{}):(h=a,i={}),extra=h in e._extras?e._extras[h]:null;if(extra){g=extra(f,k(b,h+c),i);for(var d in g)b.on(d,g[d],h)}})}function k(a,b){var c=l(a);return c.update=function(){a.update([b])},c}function l(a){var b={};for(var c in a)b[c]=a[c];return b}function m(a,b){return b.map(a).filter(r).length==b.length}function n(a){return Object.prototype.toString.call(a)==="[object Array]"}function o(a){return typeof a=="string"}function p(a){return typeof a!="undefined"}function q(a){return typeof a=="function"}function r(a){return a}var e=function(a){return m(q,[a.init,a.xy,a.z])?function(b,c,d){return h({e:b,color:c,cbs:a,extras:d})}:console.warn("colorjoe: missing cb")};e.rgb=e({init:function(b,c,d){var e=a(b).hsl();return this.xy(e,{x:e.saturation(),y:1-e.value()},c,d),this.z(e,e.hue(),c,d),e},xy:function(a,b,d,e){return c.X(d.pointer,b.x),c.Y(d.pointer,b.y),a.saturation(b.x).value(1-b.y)},z:function(a,b,d,e){return c.Y(e.pointer,b),g(d.background,b),a.hue(b)}}),e.hsl=e({init:function(b,c,d){var e=a(b).hsl();return this.xy(e,{x:e.hue(),y:1-e.saturation()},c,d),this.z(e,1-e.lightness(),c,d),e},xy:function(a,b,d,e){return c.X(d.pointer,b.x),c.Y(d.pointer,b.y),g(e.background,b.x),a.hue(b.x).saturation(1-b.y)},z:function(a,b,d,e){return c.Y(e.pointer,b),a.lightness(1-b)}}),e._extras={},e.registerExtra=function(a,b){a in e._extras&&console.warn('Extra "'+a+'"has been registered already!'),e._extras[a]=b};for(var f in d)e.registerExtra(f,d[f]);return e});
+function ONECOLOR(e){if(Object.prototype.toString.apply(e)==="[object Array]")return e.length===4?new ONECOLOR.RGB(e[0]/255,e[1]/255,e[2]/255,e[3]/255):new ONECOLOR[e[0]](e.slice(1,e.length));if(typeof e=="string"){var t=e.toLowerCase();namedColors[t]&&(e="#"+namedColors[t]);var n=e.match(cssColorRegExp);if(n){var r=n[1].toUpperCase(),i=undef(n[8])?n[8]:parseFloat(n[8]),s=r[0]==="H",o=n[3]?100:s?360:255,u=n[5]||s?100:255,a=n[7]||s?100:255;if(undef(ONECOLOR[r]))throw new Error("one.color."+r+" is not installed.");return new ONECOLOR[r](parseFloat(n[2])/o,parseFloat(n[4])/u,parseFloat(n[6])/a,i)}e.length<6&&(e=e.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var f=e.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(f)return new ONECOLOR.RGB(parseInt(f[1],16)/255,parseInt(f[2],16)/255,parseInt(f[3],16)/255)}else{if(typeof e=="object"&&e.isColor)return e;if(!isNaN(e))return new ONECOLOR.RGB((e&255)/255,((e&65280)>>8)/255,((e&16711680)>>16)/255)}return!1}function installColorSpace(e,t,n){function o(e,t){var n={};n[t.toLowerCase()]=new Function("return this.rgb()."+t.toLowerCase()+"();"),ONECOLOR[t].propertyNames.forEach(function(e,r){n[e]=n[e==="black"?"k":e[0]]=new Function("value","isDelta","return this."+t.toLowerCase()+"()."+e+"(value, isDelta);")});for(var r in n)n.hasOwnProperty(r)&&ONECOLOR[e].prototype[r]===undefined&&(ONECOLOR[e].prototype[r]=n[r])}ONECOLOR[e]=new Function(t.join(","),"if (Object.prototype.toString.apply("+t[0]+") === '[object Array]') {"+t.map(function(e,n){return e+"="+t[0]+"["+n+"];"}).reverse().join("")+"}"+"if ("+t.filter(function(e){return e!=="alpha"}).map(function(e){return"isNaN("+e+")"}).join("||")+"){"+'throw new Error("['+e+']: Invalid color: ("+'+t.join('+","+')+'+")");}'+t.map(function(e){return e==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":e==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+e+"="+e+"<0?0:("+e+">1?1:"+e+")"}).join(";")+";"),ONECOLOR[e].propertyNames=t;var r=ONECOLOR[e].prototype;["valueOf","hex","css","cssa"].forEach(function(t){r[t]=r[t]||(e==="RGB"?r.hex:new Function("return this.rgb()."+t+"();"))}),r.isColor=!0,r.equals=function(n,r){undef(r)&&(r=1e-10),n=n[e.toLowerCase()]();for(var i=0;i<t.length;i+=1)if(Math.abs(this["_"+t[i]]-n["_"+t[i]])>r)return!1;return!0},r.toJSON=new Function("return ['"+e+"', "+t.map(function(e){return"this._"+e},this).join(", ")+"];");for(var i in n)if(n.hasOwnProperty(i)){var s=i.match(/^from(.*)$/);s?ONECOLOR[s[1].toUpperCase()].prototype[e.toLowerCase()]=n[i]:r[i]=n[i]}r[e.toLowerCase()]=function(){return this},r.toString=new Function('return "[one.color.'+e+':"+'+t.map(function(e,n){return'" '+t[n]+'="+this._'+e}).join("+")+'+"]";'),t.forEach(function(e,n){r[e]=r[e==="black"?"k":e[0]]=new Function("value","isDelta","if (typeof value === 'undefined') {return this._"+e+";"+"}"+"if (isDelta) {"+"return new this.constructor("+t.map(function(t,n){return"this._"+t+(e===t?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+t.map(function(t,n){return e===t?"value":"this._"+t}).join(", ")+");")}),installedColorSpaces.forEach(function(t){o(e,t),o(t,e)}),installedColorSpaces.push(e)}function gs(){var e=this.rgb(),t=e._red*.3+e._green*.59+e._blue*.11;return new ONECOLOR.RGB(t,t,t,this._alpha)}(function(e,t){typeof define=="function"&&define.amd?define(t):e.drag=t()})(this,function(){function e(e,t){if(!e){console.warn("drag is missing elem!");return}o()?u(e,t,"touchstart","touchmove","touchend"):u(e,t,"mousedown","mousemove","mouseup")}function t(t){var n=i(t["class"]||"",t.parent),s=i("pointer",n);return i("shape shape1",s),i("shape shape2",s),i("bg bg1",n),i("bg bg2",n),e(n,r(t.cbs,s)),{background:n,pointer:s}}function n(t){var n=i(t["class"],t.parent),s=i("pointer",n);return i("shape",s),i("bg",n),e(n,r(t.cbs,s)),{background:n,pointer:s}}function r(e,t){function i(e){return function(n){n.pointer=t,e(n)}}var n={};for(var r in e)n[r]=i(e[r]);return n}function i(e,t){return s("div",e,t)}function s(e,t,n){var r=document.createElement(e);return t&&(r.className=t),n.appendChild(r),r}function o(){return typeof window.ontouchstart!="undefined"}function u(e,t,n,r,i){var s=!1;t=l(t);var o=t.begin,u=t.change,c=t.end;a(e,n,function(t){function l(){s=!1,f(document,r,n),f(document,i,l),p(c,e,t)}s=!0;var n=d(p,u,e);a(document,r,n),a(document,i,l),p(o,e,t)})}function a(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,n)}function f(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent&&e.detachEvent("on"+t,n)}function l(e){if(!e){var t,n;return{begin:function(e){t={x:e.elem.offsetLeft,y:e.elem.offsetTop},n=e.cursor},change:function(e){c(e.elem,"left",t.x+e.cursor.x-n.x+"px"),c(e.elem,"top",t.y+e.cursor.y-n.y+"px")},end:h}}return{begin:e.begin||h,change:e.change||h,end:e.end||h}}function c(e,t,n){e.style[t]=n}function h(){}function p(e,t,n){n.preventDefault();var r=v(t),i=t.clientWidth,s=t.clientHeight,o={x:m(t,n),y:g(t,n)},u=(o.x-r.x)/i,a=(o.y-r.y)/s;e({x:isNaN(u)?0:u,y:isNaN(a)?0:a,cursor:o,elem:t,e:n})}function d(e){var t=Array.prototype.slice,n=t.apply(arguments,[1]);return function(){return e.apply(null,n.concat(t.apply(arguments)))}}function v(e){var t=0,n=0;if(e.offsetParent)do t+=e.offsetLeft,n+=e.offsetTop;while(e=e.offsetParent);return{x:t,y:n}}function m(e,t){if(b(e)){var n=parseInt(w(document.body,"marginLeft"),10)-y(e,"scrollLeft")+window.pageXOffset+e.style.marginLeft;return t.clientX-n}if(t.pageX)return t.pageX;if(t.clientX)return t.clientX+document.body.scrollLeft}function g(e,t){if(b(e)){var n=parseInt(w(document.body,"marginTop"),10)-y(e,"scrollTop")+window.pageYOffset+e.style.marginTop;return t.clientY-n}if(t.pageY)return t.pageY;if(t.clientY)return t.clientY+document.body.scrollTop}function y(e,t){var n=0;while(e.nodeName!="HTML")n+=e[t],e=e.parentNode;return n}function b(e){while(e.nodeName!="HTML"&&E(e,"position")!="fixed")e=e.parentNode;return e.nodeName=="HTML"?!1:!0}function w(e,t){return e.currentStyle?e.currentStyle[t]:document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(e,"")[t]:e.style[t]}function E(e,t){var n;return window.getComputedStyle?n=window.getComputedStyle(e,null):n=e.currentStyle,n[t]}return e.xyslider=t,e.slider=n,e});var installedColorSpaces=[],namedColors={},undef=function(e){return typeof e=="undefined"},channelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,alphaChannelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,cssColorRegExp=new RegExp("^(rgb|hsl|hsv)a?\\("+channelRegExp.source+","+channelRegExp.source+","+channelRegExp.source+"(?:,"+alphaChannelRegExp.source+")?"+"\\)$","i");ONECOLOR.installMethod=function(e,t){installedColorSpaces.forEach(function(n){ONECOLOR[n].prototype[e]=t})},installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var e=(Math.round(255*this._red)*65536+Math.round(255*this._green)*256+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-e.length)+e},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}}),typeof module!="undefined"?module.exports=ONECOLOR:typeof define=="function"&&!undef(define.amd)?define([],function(){return ONECOLOR}):typeof jQuery!="undefined"&&undef(jQuery.color)?jQuery.color=ONECOLOR:(one=window.one||{},one.color=ONECOLOR),namedColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgrey:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var e=this._hue,t=this._saturation,n=this._value,r=Math.min(5,Math.floor(e*6)),i=e*6-r,s=n*(1-t),o=n*(1-i*t),u=n*(1-(1-i)*t),a,f,l;switch(r){case 0:a=n,f=u,l=s;break;case 1:a=o,f=n,l=s;break;case 2:a=s,f=n,l=u;break;case 3:a=s,f=o,l=n;break;case 4:a=u,f=s,l=n;break;case 5:a=n,f=s,l=o}return new ONECOLOR.RGB(a,f,l,this._alpha)},hsl:function(){var e=(2-this._saturation)*this._value,t=this._saturation*this._value,n=e<=1?e:2-e,r;return n<1e-9?r=0:r=t/n,new ONECOLOR.HSL(this._hue,r,e/2,this._alpha)},fromRgb:function(){var e=this._red,t=this._green,n=this._blue,r=Math.max(e,t,n),i=Math.min(e,t,n),s=r-i,o,u=r===0?0:s/r,a=r;if(s===0)o=0;else switch(r){case e:o=(t-n)/s/6+(t<n?1:0);break;case t:o=(n-e)/s/6+1/3;break;case n:o=(e-t)/s/6+2/3}return new ONECOLOR.HSV(o,u,a,this._alpha)}}),installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var e=this._lightness*2,t=this._saturation*(e<=1?e:2-e),n;return e+t<1e-9?n=0:n=2*t/(e+t),new ONECOLOR.HSV(this._hue,n,(e+t)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}}),installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new ONECOLOR.RGB(1-this._cyan*(1-this._black)-this._black,1-this._magenta*(1-this._black)-this._black,1-this._yellow*(1-this._black)-this._black,this._alpha)},fromRgb:function(){var e=this._red,t=this._green,n=this._blue,r=1-e,i=1-t,s=1-n,o=1;return e||t||n?(o=Math.min(r,Math.min(i,s)),r=(r-o)/(1-o),i=(i-o)/(1-o),s=(s-o)/(1-o)):o=1,new ONECOLOR.CMYK(r,i,s,o,this._alpha)}}),ONECOLOR.installMethod("clearer",function(e){return this.alpha(isNaN(e)?-0.1:-e,!0)}),ONECOLOR.installMethod("darken",function(e){return this.lightness(isNaN(e)?-0.1:-e,!0)}),ONECOLOR.installMethod("desaturate",function(e){return this.saturation(isNaN(e)?-0.1:-e,!0)}),ONECOLOR.installMethod("greyscale",gs),ONECOLOR.installMethod("grayscale",gs),ONECOLOR.installMethod("lighten",function(e){return this.lightness(isNaN(e)?.1:e,!0)}),ONECOLOR.installMethod("mix",function(e,t){e=ONECOLOR(e).rgb(),t=1-(isNaN(t)?.5:t);var n=t*2-1,r=this._alpha-e._alpha,i=((n*r===-1?n:(n+r)/(1+n*r))+1)/2,s=1-i,o=this.rgb();return new ONECOLOR.RGB(o._red*i+e._red*s,o._green*i+e._green*s,o._blue*i+e._blue*s,o._alpha*t+e._alpha*(1-t))}),ONECOLOR.installMethod("negate",function(){var e=this.rgb();return new ONECOLOR.RGB(1-e._red,1-e._green,1-e._blue,this._alpha)}),ONECOLOR.installMethod("opaquer",function(e){return this.alpha(isNaN(e)?.1:e,!0)}),ONECOLOR.installMethod("rotate",function(e){return this.hue((e||0)/360,!0)}),ONECOLOR.installMethod("saturate",function(e){return this.saturation(isNaN(e)?.1:e,!0)}),ONECOLOR.installMethod("toAlpha",function(e){var t=this.rgb(),n=ONECOLOR(e).rgb(),r=1e-10,i=new ONECOLOR.RGB(0,0,0,t._alpha),s=["_red","_green","_blue"];return s.forEach(function(e){t[e]<r?i[e]=t[e]:t[e]>n[e]?i[e]=(t[e]-n[e])/(1-n[e]):t[e]>n[e]?i[e]=(n[e]-t[e])/n[e]:i[e]=0}),i._red>i._green?i._red>i._blue?t._alpha=i._red:t._alpha=i._blue:i._green>i._blue?t._alpha=i._green:t._alpha=i._blue,t._alpha<r?t:(s.forEach(function(e){t[e]=(t[e]-n[e])/t._alpha+n[e]}),t._alpha*=i._alpha,t)}),function(e,t){typeof exports=="object"?module.exports=t():typeof define=="function"&&define.amd?define(t):e.elemutils=t()}(this,function(){function t(e,t,n){var r=document.createElement(e);return r.className=t,n.appendChild(r),r}function n(e){var t=Array.prototype.slice,n=t.apply(arguments,[1]);return function(){return e.apply(null,n.concat(t.apply(arguments)))}}function r(t,n,r,o){var u=e(t,r),a=i(n,u),f=s("text",u,o);return{label:a,input:f}}function i(e,n){var r=t("label","",n);return r.innerHTML=e,r}function s(e,n,r){var i=t("input","",n);return i.type=e,r&&(i.maxLength=r),i}function o(e,t){e.style.left=f(t*100,0,100)+"%"}function u(e,t){e.style.top=f(t*100,0,100)+"%"}function a(e,t){e.style.background=t}function f(e,t,n){return Math.min(Math.max(e,t),n)}var e=n(t,"div");return{clamp:f,e:t,div:e,partial:n,labelInput:r,X:o,Y:u,BG:a}}),function(e,t){typeof define=="function"&&define.amd?define(["./elemutils","./drag"],t):e.colorjoeextras=t(e.elemutils,e.drag)}(this,function(e,t){function n(t){var n=e.div("currentColorContainer",t),r=e.div("currentColor",n);return{change:function(t){e.BG(r,t.cssa())}}}function r(t,n,r){function h(){var e=[i];c.forEach(function(t){e.push(t.e.input.value/s)}),f||e.push(n.getAlpha()),n.set(e)}var i=r.space,s=r.limit||255,o=r.fix>=0?r.fix:0,u=(""+s).length+o;u=o?u+1:u;var a=i.split(""),f=i[i.length-1]=="A";i=f?i.slice(0,-1):i;if(["RGB","HSL","HSV","CMYK"].indexOf(i)<0)return console.warn("Invalid field names",i);var l=e.div("colorFields",t),c=a.map(function(t,n){t=t.toLowerCase();var r=e.labelInput("color "+t,t,l,u);return r.input.onkeyup=h,{name:t,e:r}});return{change:function(e){c.forEach(function(t){t.e.input.value=(e[t.name]()*s).toFixed(o)})}}}function i(n,r){function s(t){var n=e.clamp(t.y,0,1);e.Y(t.pointer,n),r.setAlpha(1-n)}var i=t.slider({parent:n,"class":"oned alpha",cbs:{begin:s,change:s}});return{change:function(t){e.Y(i.pointer,1-t.alpha())}}}function s(t,n,r){var i=e.labelInput("hex",r.label||"",t,7);return i.input.value="#",i.input.onkeyup=function(e){var t=e.target.value;t=t[0]=="#"?t:"#"+t,t=o(t,7,"0"),n.set(t)},{change:function(e){i.input.value=i.input.value[0]=="#"?"#":"",i.input.value+=e.hex().slice(1)}}}function o(e,t,n){var r=e;for(var i=e.length,s=t;i<t;i++)r+=n;return r}return{currentColor:n,fields:r,hex:s,alpha:i}}),function(e,t){typeof define=="function"&&define.amd?define(["./onecolor","./drag","./elemutils","./extras"],t):e.colorjoe=t(e.ONECOLOR,e.drag,e.elemutils,e.colorjoeextras)}(this,function(e,t,n,r){function o(t,r){n.BG(t,(new e.HSV(r,1,1)).cssa())}function u(e){function o(e){h=i.xy(h,{x:n.clamp(e.x,0,1),y:n.clamp(e.y,0,1)},s,u),m()}function l(e){h=i.z(h,n.clamp(e.y,0,1),s,u),m()}function m(e){e=p(e)?e:[];var t=v.change,n;for(var r=0,i=t.length;r<i;r++)n=t[r],e.indexOf(n.name)==-1&&n.fn(h)}function g(){if(c.equals(h))return;for(var e=0,t=v.done.length;e<t;e++)v.done[e](h);c=h}if(!e.e)return console.warn("colorjoe: missing element");var r=d(e.e)?document.getElementById(e.e):e.e;r.className="colorPicker";var i=e.cbs,s=t.xyslider({parent:r,"class":"twod",cbs:{begin:o,change:o,end:g}}),u=t.slider({parent:r,"class":"oned",cbs:{begin:l,change:l,end:g}}),c=a(e.color),h=i.init(c,s,u),v={change:[],done:[]},y={e:r,update:function(e){return m(e),this},get:function(){return h},set:function(e){var t=this.get();return h=i.init(a(e),s,u),t.equals(h)||this.update(),this},getAlpha:function(){return h.alpha()},setAlpha:function(e){return h=h.alpha(e),this.update(),this},on:function(e,t,n){return e=="change"||e=="done"?v[e].push({name:n,fn:t}):console.warn('Passed invalid evt name "'+e+'" to colorjoe.on'),this},removeAllListeners:function(e){if(e)delete v[e];else for(var t in v)delete v[t];return this}};return f(r,y,e.extras),m(),y}function a(t){if(!v(t))return e("black");if(t.isColor)return t;var n=e(t);return n?n:(v(t)&&console.warn("Passed invalid color to colorjoe, using black instead"),e("black"))}function f(e,t,r){if(!r)return;var s=n.div("extras",e),o,u,a;r.forEach(function(e,n){p(e)?(u=e[0],a=e.length>1?e[1]:{}):(u=e,a={}),extra=u in i._extras?i._extras[u]:null;if(extra){o=extra(s,l(t,u+n),a);for(var r in o)t.on(r,o[r],u)}})}function l(e,t){var n=c(e);return n.update=function(){e.update([t])},n}function c(e){var t={};for(var n in e)t[n]=e[n];return t}function h(e,t){return t.map(e).filter(g).length==t.length}function p(e){return Object.prototype.toString.call(e)==="[object Array]"}function d(e){return typeof e=="string"}function v(e){return typeof e!="undefined"}function m(e){return typeof e=="function"}function g(e){return e}var i=function(e){return h(m,[e.init,e.xy,e.z])?function(t,n,r){return u({e:t,color:n,cbs:e,extras:r})}:console.warn("colorjoe: missing cb")};i.rgb=i({init:function(t,n,r){var i=e(t).hsl();return this.xy(i,{x:i.saturation(),y:1-i.value()},n,r),this.z(i,i.hue(),n,r),i},xy:function(e,t,r,i){return n.X(r.pointer,t.x),n.Y(r.pointer,t.y),e.saturation(t.x).value(1-t.y)},z:function(e,t,r,i){return n.Y(i.pointer,t),o(r.background,t),e.hue(t)}}),i.hsl=i({init:function(t,n,r){var i=e(t).hsl();return this.xy(i,{x:i.hue(),y:1-i.saturation()},n,r),this.z(i,1-i.lightness(),n,r),i},xy:function(e,t,r,i){return n.X(r.pointer,t.x),n.Y(r.pointer,t.y),o(i.background,t.x),e.hue(t.x).saturation(1-t.y)},z:function(e,t,r,i){return n.Y(i.pointer,t),e.lightness(1-t)}}),i._extras={},i.registerExtra=function(e,t){e in i._extras&&console.warn('Extra "'+e+'"has been registered already!'),i._extras[e]=t};for(var s in r)i.registerExtra(s,r[s]);return i});
View
2 package.json
@@ -6,7 +6,7 @@
"dependencies": {
"drag.js": "== 0.3.8",
- "onecolor": "== 2.2.6"
+ "onecolor": "== 2.3.0"
},
"repository": {
View
22 src/extras.js
@@ -18,24 +18,10 @@ function fields(p, joe, o) {
var cs = o.space;
var fac = o.limit || 255;
var fix = o.fix >= 0? o.fix: 0;
- var methods = {
- R: 'red',
- G: 'green',
- B: 'blue',
- H: 'hue',
- S: 'saturation',
- V: 'value',
- L: 'lightness',
- C: 'cyan',
- M: 'magenta',
- Y: 'yellow',
- K: 'black',
- A: 'alpha'
- };
var inputLen = ('' + fac).length + fix;
inputLen = fix? inputLen + 1: inputLen;
- var initials = cs.split('').map(function(n) {return n.toUpperCase();});
+ var initials = cs.split('');
var useAlpha = cs[cs.length - 1] == 'A';
cs = useAlpha? cs.slice(0, -1): cs;
@@ -44,7 +30,9 @@ function fields(p, joe, o) {
var c = utils.div('colorFields', p);
var elems = initials.map(function(n, i) {
- var e = utils.labelInput('color ' + methods[n], n, c, inputLen);
+ n = n.toLowerCase();
+
+ var e = utils.labelInput('color ' + n, n, c, inputLen);
e.input.onkeyup = update;
return {name: n, e: e};
@@ -63,7 +51,7 @@ function fields(p, joe, o) {
return {
change: function(col) {
elems.forEach(function(o) {
- o.e.input.value = (col[methods[o.name]]() * fac).toFixed(fix);
+ o.e.input.value = (col[o.name]() * fac).toFixed(fix);
});
}
};

0 comments on commit 162a76b

Please sign in to comment.
Something went wrong with that request. Please try again.