Edit File by line
/home/barbar84/www/wp-inclu.../js/dist
File: components.js
[48000] Fix | Delete
function tinycolor (color, opts) {
[48001] Fix | Delete
[48002] Fix | Delete
color = (color) ? color : '';
[48003] Fix | Delete
opts = opts || { };
[48004] Fix | Delete
[48005] Fix | Delete
// If input is already a tinycolor, return itself
[48006] Fix | Delete
if (color instanceof tinycolor) {
[48007] Fix | Delete
return color;
[48008] Fix | Delete
}
[48009] Fix | Delete
// If we are called as a function, call using new instead
[48010] Fix | Delete
if (!(this instanceof tinycolor)) {
[48011] Fix | Delete
return new tinycolor(color, opts);
[48012] Fix | Delete
}
[48013] Fix | Delete
[48014] Fix | Delete
var rgb = inputToRGB(color);
[48015] Fix | Delete
this._originalInput = color,
[48016] Fix | Delete
this._r = rgb.r,
[48017] Fix | Delete
this._g = rgb.g,
[48018] Fix | Delete
this._b = rgb.b,
[48019] Fix | Delete
this._a = rgb.a,
[48020] Fix | Delete
this._roundA = mathRound(100*this._a) / 100,
[48021] Fix | Delete
this._format = opts.format || rgb.format;
[48022] Fix | Delete
this._gradientType = opts.gradientType;
[48023] Fix | Delete
[48024] Fix | Delete
// Don't let the range of [0,255] come back in [0,1].
[48025] Fix | Delete
// Potentially lose a little bit of precision here, but will fix issues where
[48026] Fix | Delete
// .5 gets interpreted as half of the total, instead of half of 1
[48027] Fix | Delete
// If it was supposed to be 128, this was already taken care of by `inputToRgb`
[48028] Fix | Delete
if (this._r < 1) { this._r = mathRound(this._r); }
[48029] Fix | Delete
if (this._g < 1) { this._g = mathRound(this._g); }
[48030] Fix | Delete
if (this._b < 1) { this._b = mathRound(this._b); }
[48031] Fix | Delete
[48032] Fix | Delete
this._ok = rgb.ok;
[48033] Fix | Delete
this._tc_id = tinyCounter++;
[48034] Fix | Delete
}
[48035] Fix | Delete
[48036] Fix | Delete
tinycolor.prototype = {
[48037] Fix | Delete
isDark: function() {
[48038] Fix | Delete
return this.getBrightness() < 128;
[48039] Fix | Delete
},
[48040] Fix | Delete
isLight: function() {
[48041] Fix | Delete
return !this.isDark();
[48042] Fix | Delete
},
[48043] Fix | Delete
isValid: function() {
[48044] Fix | Delete
return this._ok;
[48045] Fix | Delete
},
[48046] Fix | Delete
getOriginalInput: function() {
[48047] Fix | Delete
return this._originalInput;
[48048] Fix | Delete
},
[48049] Fix | Delete
getFormat: function() {
[48050] Fix | Delete
return this._format;
[48051] Fix | Delete
},
[48052] Fix | Delete
getAlpha: function() {
[48053] Fix | Delete
return this._a;
[48054] Fix | Delete
},
[48055] Fix | Delete
getBrightness: function() {
[48056] Fix | Delete
//http://www.w3.org/TR/AERT#color-contrast
[48057] Fix | Delete
var rgb = this.toRgb();
[48058] Fix | Delete
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
[48059] Fix | Delete
},
[48060] Fix | Delete
getLuminance: function() {
[48061] Fix | Delete
//http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
[48062] Fix | Delete
var rgb = this.toRgb();
[48063] Fix | Delete
var RsRGB, GsRGB, BsRGB, R, G, B;
[48064] Fix | Delete
RsRGB = rgb.r/255;
[48065] Fix | Delete
GsRGB = rgb.g/255;
[48066] Fix | Delete
BsRGB = rgb.b/255;
[48067] Fix | Delete
[48068] Fix | Delete
if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}
[48069] Fix | Delete
if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}
[48070] Fix | Delete
if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
[48071] Fix | Delete
return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
[48072] Fix | Delete
},
[48073] Fix | Delete
setAlpha: function(value) {
[48074] Fix | Delete
this._a = boundAlpha(value);
[48075] Fix | Delete
this._roundA = mathRound(100*this._a) / 100;
[48076] Fix | Delete
return this;
[48077] Fix | Delete
},
[48078] Fix | Delete
toHsv: function() {
[48079] Fix | Delete
var hsv = rgbToHsv(this._r, this._g, this._b);
[48080] Fix | Delete
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
[48081] Fix | Delete
},
[48082] Fix | Delete
toHsvString: function() {
[48083] Fix | Delete
var hsv = rgbToHsv(this._r, this._g, this._b);
[48084] Fix | Delete
var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
[48085] Fix | Delete
return (this._a == 1) ?
[48086] Fix | Delete
"hsv(" + h + ", " + s + "%, " + v + "%)" :
[48087] Fix | Delete
"hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
[48088] Fix | Delete
},
[48089] Fix | Delete
toHsl: function() {
[48090] Fix | Delete
var hsl = rgbToHsl(this._r, this._g, this._b);
[48091] Fix | Delete
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
[48092] Fix | Delete
},
[48093] Fix | Delete
toHslString: function() {
[48094] Fix | Delete
var hsl = rgbToHsl(this._r, this._g, this._b);
[48095] Fix | Delete
var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
[48096] Fix | Delete
return (this._a == 1) ?
[48097] Fix | Delete
"hsl(" + h + ", " + s + "%, " + l + "%)" :
[48098] Fix | Delete
"hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
[48099] Fix | Delete
},
[48100] Fix | Delete
toHex: function(allow3Char) {
[48101] Fix | Delete
return rgbToHex(this._r, this._g, this._b, allow3Char);
[48102] Fix | Delete
},
[48103] Fix | Delete
toHexString: function(allow3Char) {
[48104] Fix | Delete
return '#' + this.toHex(allow3Char);
[48105] Fix | Delete
},
[48106] Fix | Delete
toHex8: function(allow4Char) {
[48107] Fix | Delete
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
[48108] Fix | Delete
},
[48109] Fix | Delete
toHex8String: function(allow4Char) {
[48110] Fix | Delete
return '#' + this.toHex8(allow4Char);
[48111] Fix | Delete
},
[48112] Fix | Delete
toRgb: function() {
[48113] Fix | Delete
return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
[48114] Fix | Delete
},
[48115] Fix | Delete
toRgbString: function() {
[48116] Fix | Delete
return (this._a == 1) ?
[48117] Fix | Delete
"rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
[48118] Fix | Delete
"rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
[48119] Fix | Delete
},
[48120] Fix | Delete
toPercentageRgb: function() {
[48121] Fix | Delete
return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
[48122] Fix | Delete
},
[48123] Fix | Delete
toPercentageRgbString: function() {
[48124] Fix | Delete
return (this._a == 1) ?
[48125] Fix | Delete
"rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
[48126] Fix | Delete
"rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
[48127] Fix | Delete
},
[48128] Fix | Delete
toName: function() {
[48129] Fix | Delete
if (this._a === 0) {
[48130] Fix | Delete
return "transparent";
[48131] Fix | Delete
}
[48132] Fix | Delete
[48133] Fix | Delete
if (this._a < 1) {
[48134] Fix | Delete
return false;
[48135] Fix | Delete
}
[48136] Fix | Delete
[48137] Fix | Delete
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
[48138] Fix | Delete
},
[48139] Fix | Delete
toFilter: function(secondColor) {
[48140] Fix | Delete
var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);
[48141] Fix | Delete
var secondHex8String = hex8String;
[48142] Fix | Delete
var gradientType = this._gradientType ? "GradientType = 1, " : "";
[48143] Fix | Delete
[48144] Fix | Delete
if (secondColor) {
[48145] Fix | Delete
var s = tinycolor(secondColor);
[48146] Fix | Delete
secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);
[48147] Fix | Delete
}
[48148] Fix | Delete
[48149] Fix | Delete
return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
[48150] Fix | Delete
},
[48151] Fix | Delete
toString: function(format) {
[48152] Fix | Delete
var formatSet = !!format;
[48153] Fix | Delete
format = format || this._format;
[48154] Fix | Delete
[48155] Fix | Delete
var formattedString = false;
[48156] Fix | Delete
var hasAlpha = this._a < 1 && this._a >= 0;
[48157] Fix | Delete
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
[48158] Fix | Delete
[48159] Fix | Delete
if (needsAlphaFormat) {
[48160] Fix | Delete
// Special case for "transparent", all other non-alpha formats
[48161] Fix | Delete
// will return rgba when there is transparency.
[48162] Fix | Delete
if (format === "name" && this._a === 0) {
[48163] Fix | Delete
return this.toName();
[48164] Fix | Delete
}
[48165] Fix | Delete
return this.toRgbString();
[48166] Fix | Delete
}
[48167] Fix | Delete
if (format === "rgb") {
[48168] Fix | Delete
formattedString = this.toRgbString();
[48169] Fix | Delete
}
[48170] Fix | Delete
if (format === "prgb") {
[48171] Fix | Delete
formattedString = this.toPercentageRgbString();
[48172] Fix | Delete
}
[48173] Fix | Delete
if (format === "hex" || format === "hex6") {
[48174] Fix | Delete
formattedString = this.toHexString();
[48175] Fix | Delete
}
[48176] Fix | Delete
if (format === "hex3") {
[48177] Fix | Delete
formattedString = this.toHexString(true);
[48178] Fix | Delete
}
[48179] Fix | Delete
if (format === "hex4") {
[48180] Fix | Delete
formattedString = this.toHex8String(true);
[48181] Fix | Delete
}
[48182] Fix | Delete
if (format === "hex8") {
[48183] Fix | Delete
formattedString = this.toHex8String();
[48184] Fix | Delete
}
[48185] Fix | Delete
if (format === "name") {
[48186] Fix | Delete
formattedString = this.toName();
[48187] Fix | Delete
}
[48188] Fix | Delete
if (format === "hsl") {
[48189] Fix | Delete
formattedString = this.toHslString();
[48190] Fix | Delete
}
[48191] Fix | Delete
if (format === "hsv") {
[48192] Fix | Delete
formattedString = this.toHsvString();
[48193] Fix | Delete
}
[48194] Fix | Delete
[48195] Fix | Delete
return formattedString || this.toHexString();
[48196] Fix | Delete
},
[48197] Fix | Delete
clone: function() {
[48198] Fix | Delete
return tinycolor(this.toString());
[48199] Fix | Delete
},
[48200] Fix | Delete
[48201] Fix | Delete
_applyModification: function(fn, args) {
[48202] Fix | Delete
var color = fn.apply(null, [this].concat([].slice.call(args)));
[48203] Fix | Delete
this._r = color._r;
[48204] Fix | Delete
this._g = color._g;
[48205] Fix | Delete
this._b = color._b;
[48206] Fix | Delete
this.setAlpha(color._a);
[48207] Fix | Delete
return this;
[48208] Fix | Delete
},
[48209] Fix | Delete
lighten: function() {
[48210] Fix | Delete
return this._applyModification(lighten, arguments);
[48211] Fix | Delete
},
[48212] Fix | Delete
brighten: function() {
[48213] Fix | Delete
return this._applyModification(brighten, arguments);
[48214] Fix | Delete
},
[48215] Fix | Delete
darken: function() {
[48216] Fix | Delete
return this._applyModification(darken, arguments);
[48217] Fix | Delete
},
[48218] Fix | Delete
desaturate: function() {
[48219] Fix | Delete
return this._applyModification(desaturate, arguments);
[48220] Fix | Delete
},
[48221] Fix | Delete
saturate: function() {
[48222] Fix | Delete
return this._applyModification(saturate, arguments);
[48223] Fix | Delete
},
[48224] Fix | Delete
greyscale: function() {
[48225] Fix | Delete
return this._applyModification(greyscale, arguments);
[48226] Fix | Delete
},
[48227] Fix | Delete
spin: function() {
[48228] Fix | Delete
return this._applyModification(spin, arguments);
[48229] Fix | Delete
},
[48230] Fix | Delete
[48231] Fix | Delete
_applyCombination: function(fn, args) {
[48232] Fix | Delete
return fn.apply(null, [this].concat([].slice.call(args)));
[48233] Fix | Delete
},
[48234] Fix | Delete
analogous: function() {
[48235] Fix | Delete
return this._applyCombination(analogous, arguments);
[48236] Fix | Delete
},
[48237] Fix | Delete
complement: function() {
[48238] Fix | Delete
return this._applyCombination(complement, arguments);
[48239] Fix | Delete
},
[48240] Fix | Delete
monochromatic: function() {
[48241] Fix | Delete
return this._applyCombination(monochromatic, arguments);
[48242] Fix | Delete
},
[48243] Fix | Delete
splitcomplement: function() {
[48244] Fix | Delete
return this._applyCombination(splitcomplement, arguments);
[48245] Fix | Delete
},
[48246] Fix | Delete
triad: function() {
[48247] Fix | Delete
return this._applyCombination(triad, arguments);
[48248] Fix | Delete
},
[48249] Fix | Delete
tetrad: function() {
[48250] Fix | Delete
return this._applyCombination(tetrad, arguments);
[48251] Fix | Delete
}
[48252] Fix | Delete
};
[48253] Fix | Delete
[48254] Fix | Delete
// If input is an object, force 1 into "1.0" to handle ratios properly
[48255] Fix | Delete
// String input requires "1.0" as input, so 1 will be treated as 1
[48256] Fix | Delete
tinycolor.fromRatio = function(color, opts) {
[48257] Fix | Delete
if (typeof color == "object") {
[48258] Fix | Delete
var newColor = {};
[48259] Fix | Delete
for (var i in color) {
[48260] Fix | Delete
if (color.hasOwnProperty(i)) {
[48261] Fix | Delete
if (i === "a") {
[48262] Fix | Delete
newColor[i] = color[i];
[48263] Fix | Delete
}
[48264] Fix | Delete
else {
[48265] Fix | Delete
newColor[i] = convertToPercentage(color[i]);
[48266] Fix | Delete
}
[48267] Fix | Delete
}
[48268] Fix | Delete
}
[48269] Fix | Delete
color = newColor;
[48270] Fix | Delete
}
[48271] Fix | Delete
[48272] Fix | Delete
return tinycolor(color, opts);
[48273] Fix | Delete
};
[48274] Fix | Delete
[48275] Fix | Delete
// Given a string or object, convert that input to RGB
[48276] Fix | Delete
// Possible string inputs:
[48277] Fix | Delete
//
[48278] Fix | Delete
// "red"
[48279] Fix | Delete
// "#f00" or "f00"
[48280] Fix | Delete
// "#ff0000" or "ff0000"
[48281] Fix | Delete
// "#ff000000" or "ff000000"
[48282] Fix | Delete
// "rgb 255 0 0" or "rgb (255, 0, 0)"
[48283] Fix | Delete
// "rgb 1.0 0 0" or "rgb (1, 0, 0)"
[48284] Fix | Delete
// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
[48285] Fix | Delete
// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
[48286] Fix | Delete
// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
[48287] Fix | Delete
// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
[48288] Fix | Delete
// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
[48289] Fix | Delete
//
[48290] Fix | Delete
function inputToRGB(color) {
[48291] Fix | Delete
[48292] Fix | Delete
var rgb = { r: 0, g: 0, b: 0 };
[48293] Fix | Delete
var a = 1;
[48294] Fix | Delete
var s = null;
[48295] Fix | Delete
var v = null;
[48296] Fix | Delete
var l = null;
[48297] Fix | Delete
var ok = false;
[48298] Fix | Delete
var format = false;
[48299] Fix | Delete
[48300] Fix | Delete
if (typeof color == "string") {
[48301] Fix | Delete
color = stringInputToObject(color);
[48302] Fix | Delete
}
[48303] Fix | Delete
[48304] Fix | Delete
if (typeof color == "object") {
[48305] Fix | Delete
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
[48306] Fix | Delete
rgb = rgbToRgb(color.r, color.g, color.b);
[48307] Fix | Delete
ok = true;
[48308] Fix | Delete
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
[48309] Fix | Delete
}
[48310] Fix | Delete
else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
[48311] Fix | Delete
s = convertToPercentage(color.s);
[48312] Fix | Delete
v = convertToPercentage(color.v);
[48313] Fix | Delete
rgb = hsvToRgb(color.h, s, v);
[48314] Fix | Delete
ok = true;
[48315] Fix | Delete
format = "hsv";
[48316] Fix | Delete
}
[48317] Fix | Delete
else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
[48318] Fix | Delete
s = convertToPercentage(color.s);
[48319] Fix | Delete
l = convertToPercentage(color.l);
[48320] Fix | Delete
rgb = hslToRgb(color.h, s, l);
[48321] Fix | Delete
ok = true;
[48322] Fix | Delete
format = "hsl";
[48323] Fix | Delete
}
[48324] Fix | Delete
[48325] Fix | Delete
if (color.hasOwnProperty("a")) {
[48326] Fix | Delete
a = color.a;
[48327] Fix | Delete
}
[48328] Fix | Delete
}
[48329] Fix | Delete
[48330] Fix | Delete
a = boundAlpha(a);
[48331] Fix | Delete
[48332] Fix | Delete
return {
[48333] Fix | Delete
ok: ok,
[48334] Fix | Delete
format: color.format || format,
[48335] Fix | Delete
r: mathMin(255, mathMax(rgb.r, 0)),
[48336] Fix | Delete
g: mathMin(255, mathMax(rgb.g, 0)),
[48337] Fix | Delete
b: mathMin(255, mathMax(rgb.b, 0)),
[48338] Fix | Delete
a: a
[48339] Fix | Delete
};
[48340] Fix | Delete
}
[48341] Fix | Delete
[48342] Fix | Delete
[48343] Fix | Delete
// Conversion Functions
[48344] Fix | Delete
// --------------------
[48345] Fix | Delete
[48346] Fix | Delete
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
[48347] Fix | Delete
// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
[48348] Fix | Delete
[48349] Fix | Delete
// `rgbToRgb`
[48350] Fix | Delete
// Handle bounds / percentage checking to conform to CSS color spec
[48351] Fix | Delete
// <http://www.w3.org/TR/css3-color/>
[48352] Fix | Delete
// *Assumes:* r, g, b in [0, 255] or [0, 1]
[48353] Fix | Delete
// *Returns:* { r, g, b } in [0, 255]
[48354] Fix | Delete
function rgbToRgb(r, g, b){
[48355] Fix | Delete
return {
[48356] Fix | Delete
r: bound01(r, 255) * 255,
[48357] Fix | Delete
g: bound01(g, 255) * 255,
[48358] Fix | Delete
b: bound01(b, 255) * 255
[48359] Fix | Delete
};
[48360] Fix | Delete
}
[48361] Fix | Delete
[48362] Fix | Delete
// `rgbToHsl`
[48363] Fix | Delete
// Converts an RGB color value to HSL.
[48364] Fix | Delete
// *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
[48365] Fix | Delete
// *Returns:* { h, s, l } in [0,1]
[48366] Fix | Delete
function rgbToHsl(r, g, b) {
[48367] Fix | Delete
[48368] Fix | Delete
r = bound01(r, 255);
[48369] Fix | Delete
g = bound01(g, 255);
[48370] Fix | Delete
b = bound01(b, 255);
[48371] Fix | Delete
[48372] Fix | Delete
var max = mathMax(r, g, b), min = mathMin(r, g, b);
[48373] Fix | Delete
var h, s, l = (max + min) / 2;
[48374] Fix | Delete
[48375] Fix | Delete
if(max == min) {
[48376] Fix | Delete
h = s = 0; // achromatic
[48377] Fix | Delete
}
[48378] Fix | Delete
else {
[48379] Fix | Delete
var d = max - min;
[48380] Fix | Delete
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
[48381] Fix | Delete
switch(max) {
[48382] Fix | Delete
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
[48383] Fix | Delete
case g: h = (b - r) / d + 2; break;
[48384] Fix | Delete
case b: h = (r - g) / d + 4; break;
[48385] Fix | Delete
}
[48386] Fix | Delete
[48387] Fix | Delete
h /= 6;
[48388] Fix | Delete
}
[48389] Fix | Delete
[48390] Fix | Delete
return { h: h, s: s, l: l };
[48391] Fix | Delete
}
[48392] Fix | Delete
[48393] Fix | Delete
// `hslToRgb`
[48394] Fix | Delete
// Converts an HSL color value to RGB.
[48395] Fix | Delete
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
[48396] Fix | Delete
// *Returns:* { r, g, b } in the set [0, 255]
[48397] Fix | Delete
function hslToRgb(h, s, l) {
[48398] Fix | Delete
var r, g, b;
[48399] Fix | Delete
[48400] Fix | Delete
h = bound01(h, 360);
[48401] Fix | Delete
s = bound01(s, 100);
[48402] Fix | Delete
l = bound01(l, 100);
[48403] Fix | Delete
[48404] Fix | Delete
function hue2rgb(p, q, t) {
[48405] Fix | Delete
if(t < 0) t += 1;
[48406] Fix | Delete
if(t > 1) t -= 1;
[48407] Fix | Delete
if(t < 1/6) return p + (q - p) * 6 * t;
[48408] Fix | Delete
if(t < 1/2) return q;
[48409] Fix | Delete
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
[48410] Fix | Delete
return p;
[48411] Fix | Delete
}
[48412] Fix | Delete
[48413] Fix | Delete
if(s === 0) {
[48414] Fix | Delete
r = g = b = l; // achromatic
[48415] Fix | Delete
}
[48416] Fix | Delete
else {
[48417] Fix | Delete
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
[48418] Fix | Delete
var p = 2 * l - q;
[48419] Fix | Delete
r = hue2rgb(p, q, h + 1/3);
[48420] Fix | Delete
g = hue2rgb(p, q, h);
[48421] Fix | Delete
b = hue2rgb(p, q, h - 1/3);
[48422] Fix | Delete
}
[48423] Fix | Delete
[48424] Fix | Delete
return { r: r * 255, g: g * 255, b: b * 255 };
[48425] Fix | Delete
}
[48426] Fix | Delete
[48427] Fix | Delete
// `rgbToHsv`
[48428] Fix | Delete
// Converts an RGB color value to HSV
[48429] Fix | Delete
// *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
[48430] Fix | Delete
// *Returns:* { h, s, v } in [0,1]
[48431] Fix | Delete
function rgbToHsv(r, g, b) {
[48432] Fix | Delete
[48433] Fix | Delete
r = bound01(r, 255);
[48434] Fix | Delete
g = bound01(g, 255);
[48435] Fix | Delete
b = bound01(b, 255);
[48436] Fix | Delete
[48437] Fix | Delete
var max = mathMax(r, g, b), min = mathMin(r, g, b);
[48438] Fix | Delete
var h, s, v = max;
[48439] Fix | Delete
[48440] Fix | Delete
var d = max - min;
[48441] Fix | Delete
s = max === 0 ? 0 : d / max;
[48442] Fix | Delete
[48443] Fix | Delete
if(max == min) {
[48444] Fix | Delete
h = 0; // achromatic
[48445] Fix | Delete
}
[48446] Fix | Delete
else {
[48447] Fix | Delete
switch(max) {
[48448] Fix | Delete
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
[48449] Fix | Delete
case g: h = (b - r) / d + 2; break;
[48450] Fix | Delete
case b: h = (r - g) / d + 4; break;
[48451] Fix | Delete
}
[48452] Fix | Delete
h /= 6;
[48453] Fix | Delete
}
[48454] Fix | Delete
return { h: h, s: s, v: v };
[48455] Fix | Delete
}
[48456] Fix | Delete
[48457] Fix | Delete
// `hsvToRgb`
[48458] Fix | Delete
// Converts an HSV color value to RGB.
[48459] Fix | Delete
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
[48460] Fix | Delete
// *Returns:* { r, g, b } in the set [0, 255]
[48461] Fix | Delete
function hsvToRgb(h, s, v) {
[48462] Fix | Delete
[48463] Fix | Delete
h = bound01(h, 360) * 6;
[48464] Fix | Delete
s = bound01(s, 100);
[48465] Fix | Delete
v = bound01(v, 100);
[48466] Fix | Delete
[48467] Fix | Delete
var i = Math.floor(h),
[48468] Fix | Delete
f = h - i,
[48469] Fix | Delete
p = v * (1 - s),
[48470] Fix | Delete
q = v * (1 - f * s),
[48471] Fix | Delete
t = v * (1 - (1 - f) * s),
[48472] Fix | Delete
mod = i % 6,
[48473] Fix | Delete
r = [v, q, p, p, t, v][mod],
[48474] Fix | Delete
g = [t, v, v, q, p, p][mod],
[48475] Fix | Delete
b = [p, p, t, v, v, q][mod];
[48476] Fix | Delete
[48477] Fix | Delete
return { r: r * 255, g: g * 255, b: b * 255 };
[48478] Fix | Delete
}
[48479] Fix | Delete
[48480] Fix | Delete
// `rgbToHex`
[48481] Fix | Delete
// Converts an RGB color to hex
[48482] Fix | Delete
// Assumes r, g, and b are contained in the set [0, 255]
[48483] Fix | Delete
// Returns a 3 or 6 character hex
[48484] Fix | Delete
function rgbToHex(r, g, b, allow3Char) {
[48485] Fix | Delete
[48486] Fix | Delete
var hex = [
[48487] Fix | Delete
pad2(mathRound(r).toString(16)),
[48488] Fix | Delete
pad2(mathRound(g).toString(16)),
[48489] Fix | Delete
pad2(mathRound(b).toString(16))
[48490] Fix | Delete
];
[48491] Fix | Delete
[48492] Fix | Delete
// Return a 3 character hex if possible
[48493] Fix | Delete
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
[48494] Fix | Delete
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
[48495] Fix | Delete
}
[48496] Fix | Delete
[48497] Fix | Delete
return hex.join("");
[48498] Fix | Delete
}
[48499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function