obf 0.6.7 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tinycolor_convert.js +320 -164
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3772ad4028a2e7e780d943bfe384dacf59c17c9d
|
4
|
+
data.tar.gz: 76fb2dc4d209f5ad9b1fbd94f22e2fe0c6937a16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68f6499271a9b143c8c6e9b45752d5b1729e281e4b2d7bd17ffc544f0a0848cd1248e12976592523ab00c72e31a7e76210add30abba2504a92498b9e0584a174
|
7
|
+
data.tar.gz: 672095044ab8a2ae7cf309393456135e9ae4de967caf16d11f66a268c5500708a3d9868b8657e72af82cd61b928f2831c0c67faa99208a4c02d56de1743b8072
|
data/lib/tinycolor_convert.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
var tiny = null;
|
2
|
+
// TinyColor v1.1.1
|
2
3
|
// https://github.com/bgrins/TinyColor
|
3
|
-
//
|
4
|
+
// Brian Grinstead, MIT License
|
4
5
|
|
5
|
-
var tiny = null;
|
6
6
|
(function() {
|
7
7
|
|
8
8
|
var trimLeft = /^[\s,#]+/,
|
@@ -14,154 +14,239 @@ var trimLeft = /^[\s,#]+/,
|
|
14
14
|
mathMax = math.max,
|
15
15
|
mathRandom = math.random;
|
16
16
|
|
17
|
-
function tinycolor (color, opts) {
|
17
|
+
var tinycolor = function tinycolor (color, opts) {
|
18
18
|
|
19
19
|
color = (color) ? color : '';
|
20
20
|
opts = opts || { };
|
21
21
|
|
22
22
|
// If input is already a tinycolor, return itself
|
23
|
-
if (
|
23
|
+
if (color instanceof tinycolor) {
|
24
24
|
return color;
|
25
25
|
}
|
26
|
+
// If we are called as a function, call using new instead
|
27
|
+
if (!(this instanceof tinycolor)) {
|
28
|
+
return new tinycolor(color, opts);
|
29
|
+
}
|
26
30
|
|
27
31
|
var rgb = inputToRGB(color);
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
this._originalInput = color,
|
33
|
+
this._r = rgb.r,
|
34
|
+
this._g = rgb.g,
|
35
|
+
this._b = rgb.b,
|
36
|
+
this._a = rgb.a,
|
37
|
+
this._roundA = mathRound(100*this._a) / 100,
|
38
|
+
this._format = opts.format || rgb.format;
|
39
|
+
this._gradientType = opts.gradientType;
|
34
40
|
|
35
41
|
// Don't let the range of [0,255] come back in [0,1].
|
36
42
|
// Potentially lose a little bit of precision here, but will fix issues where
|
37
43
|
// .5 gets interpreted as half of the total, instead of half of 1
|
38
44
|
// If it was supposed to be 128, this was already taken care of by `inputToRgb`
|
39
|
-
if (
|
40
|
-
if (
|
41
|
-
if (
|
42
|
-
|
43
|
-
return {
|
44
|
-
ok: rgb.ok,
|
45
|
-
format: format,
|
46
|
-
_tc_id: tinyCounter++,
|
47
|
-
alpha: a,
|
48
|
-
getAlpha: function() {
|
49
|
-
return a;
|
50
|
-
},
|
51
|
-
setAlpha: function(value) {
|
52
|
-
a = boundAlpha(value);
|
53
|
-
roundA = mathRound(100*a) / 100;
|
54
|
-
},
|
55
|
-
toHsv: function() {
|
56
|
-
var hsv = rgbToHsv(r, g, b);
|
57
|
-
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: a };
|
58
|
-
},
|
59
|
-
toHsvString: function() {
|
60
|
-
var hsv = rgbToHsv(r, g, b);
|
61
|
-
var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
|
62
|
-
return (a == 1) ?
|
63
|
-
"hsv(" + h + ", " + s + "%, " + v + "%)" :
|
64
|
-
"hsva(" + h + ", " + s + "%, " + v + "%, "+ roundA + ")";
|
65
|
-
},
|
66
|
-
toHsl: function() {
|
67
|
-
var hsl = rgbToHsl(r, g, b);
|
68
|
-
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: a };
|
69
|
-
},
|
70
|
-
toHslString: function() {
|
71
|
-
var hsl = rgbToHsl(r, g, b);
|
72
|
-
var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
|
73
|
-
return (a == 1) ?
|
74
|
-
"hsl(" + h + ", " + s + "%, " + l + "%)" :
|
75
|
-
"hsla(" + h + ", " + s + "%, " + l + "%, "+ roundA + ")";
|
76
|
-
},
|
77
|
-
toHex: function(allow3Char) {
|
78
|
-
return rgbToHex(r, g, b, allow3Char);
|
79
|
-
},
|
80
|
-
toHexString: function(allow3Char) {
|
81
|
-
return '#' + this.toHex(allow3Char);
|
82
|
-
},
|
83
|
-
toHex8: function() {
|
84
|
-
return rgbaToHex(r, g, b, a);
|
85
|
-
},
|
86
|
-
toHex8String: function() {
|
87
|
-
return '#' + this.toHex8();
|
88
|
-
},
|
89
|
-
toRgb: function() {
|
90
|
-
return { r: mathRound(r), g: mathRound(g), b: mathRound(b), a: a };
|
91
|
-
},
|
92
|
-
toRgbString: function() {
|
93
|
-
return (a == 1) ?
|
94
|
-
"rgb(" + mathRound(r) + ", " + mathRound(g) + ", " + mathRound(b) + ")" :
|
95
|
-
"rgba(" + mathRound(r) + ", " + mathRound(g) + ", " + mathRound(b) + ", " + roundA + ")";
|
96
|
-
},
|
97
|
-
toPercentageRgb: function() {
|
98
|
-
return { r: mathRound(bound01(r, 255) * 100) + "%", g: mathRound(bound01(g, 255) * 100) + "%", b: mathRound(bound01(b, 255) * 100) + "%", a: a };
|
99
|
-
},
|
100
|
-
toPercentageRgbString: function() {
|
101
|
-
return (a == 1) ?
|
102
|
-
"rgb(" + mathRound(bound01(r, 255) * 100) + "%, " + mathRound(bound01(g, 255) * 100) + "%, " + mathRound(bound01(b, 255) * 100) + "%)" :
|
103
|
-
"rgba(" + mathRound(bound01(r, 255) * 100) + "%, " + mathRound(bound01(g, 255) * 100) + "%, " + mathRound(bound01(b, 255) * 100) + "%, " + roundA + ")";
|
104
|
-
},
|
105
|
-
toName: function() {
|
106
|
-
if (a === 0) {
|
107
|
-
return "transparent";
|
108
|
-
}
|
45
|
+
if (this._r < 1) { this._r = mathRound(this._r); }
|
46
|
+
if (this._g < 1) { this._g = mathRound(this._g); }
|
47
|
+
if (this._b < 1) { this._b = mathRound(this._b); }
|
109
48
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
var hex8String = '#' + rgbaToHex(r, g, b, a);
|
114
|
-
var secondHex8String = hex8String;
|
115
|
-
var gradientType = opts && opts.gradientType ? "GradientType = 1, " : "";
|
49
|
+
this._ok = rgb.ok;
|
50
|
+
this._tc_id = tinyCounter++;
|
51
|
+
};
|
116
52
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
53
|
+
tinycolor.prototype = {
|
54
|
+
isDark: function() {
|
55
|
+
return this.getBrightness() < 128;
|
56
|
+
},
|
57
|
+
isLight: function() {
|
58
|
+
return !this.isDark();
|
59
|
+
},
|
60
|
+
isValid: function() {
|
61
|
+
return this._ok;
|
62
|
+
},
|
63
|
+
getOriginalInput: function() {
|
64
|
+
return this._originalInput;
|
65
|
+
},
|
66
|
+
getFormat: function() {
|
67
|
+
return this._format;
|
68
|
+
},
|
69
|
+
getAlpha: function() {
|
70
|
+
return this._a;
|
71
|
+
},
|
72
|
+
getBrightness: function() {
|
73
|
+
var rgb = this.toRgb();
|
74
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
|
75
|
+
},
|
76
|
+
setAlpha: function(value) {
|
77
|
+
this._a = boundAlpha(value);
|
78
|
+
this._roundA = mathRound(100*this._a) / 100;
|
79
|
+
return this;
|
80
|
+
},
|
81
|
+
toHsv: function() {
|
82
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
83
|
+
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
|
84
|
+
},
|
85
|
+
toHsvString: function() {
|
86
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
87
|
+
var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
|
88
|
+
return (this._a == 1) ?
|
89
|
+
"hsv(" + h + ", " + s + "%, " + v + "%)" :
|
90
|
+
"hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
|
91
|
+
},
|
92
|
+
toHsl: function() {
|
93
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
94
|
+
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
|
95
|
+
},
|
96
|
+
toHslString: function() {
|
97
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
98
|
+
var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
|
99
|
+
return (this._a == 1) ?
|
100
|
+
"hsl(" + h + ", " + s + "%, " + l + "%)" :
|
101
|
+
"hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
|
102
|
+
},
|
103
|
+
toHex: function(allow3Char) {
|
104
|
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
105
|
+
},
|
106
|
+
toHexString: function(allow3Char) {
|
107
|
+
return '#' + this.toHex(allow3Char);
|
108
|
+
},
|
109
|
+
toHex8: function() {
|
110
|
+
return rgbaToHex(this._r, this._g, this._b, this._a);
|
111
|
+
},
|
112
|
+
toHex8String: function() {
|
113
|
+
return '#' + this.toHex8();
|
114
|
+
},
|
115
|
+
toRgb: function() {
|
116
|
+
return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
|
117
|
+
},
|
118
|
+
toRgbString: function() {
|
119
|
+
return (this._a == 1) ?
|
120
|
+
"rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
|
121
|
+
"rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
|
122
|
+
},
|
123
|
+
toPercentageRgb: function() {
|
124
|
+
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 };
|
125
|
+
},
|
126
|
+
toPercentageRgbString: function() {
|
127
|
+
return (this._a == 1) ?
|
128
|
+
"rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
|
129
|
+
"rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
130
|
+
},
|
131
|
+
toName: function() {
|
132
|
+
if (this._a === 0) {
|
133
|
+
return "transparent";
|
134
|
+
}
|
121
135
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
var formatSet = !!format;
|
126
|
-
format = format || this.format;
|
136
|
+
if (this._a < 1) {
|
137
|
+
return false;
|
138
|
+
}
|
127
139
|
|
128
|
-
|
129
|
-
|
130
|
-
|
140
|
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
141
|
+
},
|
142
|
+
toFilter: function(secondColor) {
|
143
|
+
var hex8String = '#' + rgbaToHex(this._r, this._g, this._b, this._a);
|
144
|
+
var secondHex8String = hex8String;
|
145
|
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
131
146
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
formattedString = this.toPercentageRgbString();
|
137
|
-
}
|
138
|
-
if (format === "hex" || format === "hex6") {
|
139
|
-
formattedString = this.toHexString();
|
140
|
-
}
|
141
|
-
if (format === "hex3") {
|
142
|
-
formattedString = this.toHexString(true);
|
143
|
-
}
|
144
|
-
if (format === "hex8") {
|
145
|
-
formattedString = this.toHex8String();
|
146
|
-
}
|
147
|
-
if (format === "name") {
|
148
|
-
formattedString = this.toName();
|
149
|
-
}
|
150
|
-
if (format === "hsl") {
|
151
|
-
formattedString = this.toHslString();
|
152
|
-
}
|
153
|
-
if (format === "hsv") {
|
154
|
-
formattedString = this.toHsvString();
|
155
|
-
}
|
147
|
+
if (secondColor) {
|
148
|
+
var s = tinycolor(secondColor);
|
149
|
+
secondHex8String = s.toHex8String();
|
150
|
+
}
|
156
151
|
|
157
|
-
|
158
|
-
|
152
|
+
return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
|
153
|
+
},
|
154
|
+
toString: function(format) {
|
155
|
+
var formatSet = !!format;
|
156
|
+
format = format || this._format;
|
157
|
+
|
158
|
+
var formattedString = false;
|
159
|
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
160
|
+
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "name");
|
161
|
+
|
162
|
+
if (needsAlphaFormat) {
|
163
|
+
// Special case for "transparent", all other non-alpha formats
|
164
|
+
// will return rgba when there is transparency.
|
165
|
+
if (format === "name" && this._a === 0) {
|
166
|
+
return this.toName();
|
159
167
|
}
|
160
|
-
|
161
|
-
return formattedString || this.toHexString();
|
168
|
+
return this.toRgbString();
|
162
169
|
}
|
163
|
-
|
164
|
-
|
170
|
+
if (format === "rgb") {
|
171
|
+
formattedString = this.toRgbString();
|
172
|
+
}
|
173
|
+
if (format === "prgb") {
|
174
|
+
formattedString = this.toPercentageRgbString();
|
175
|
+
}
|
176
|
+
if (format === "hex" || format === "hex6") {
|
177
|
+
formattedString = this.toHexString();
|
178
|
+
}
|
179
|
+
if (format === "hex3") {
|
180
|
+
formattedString = this.toHexString(true);
|
181
|
+
}
|
182
|
+
if (format === "hex8") {
|
183
|
+
formattedString = this.toHex8String();
|
184
|
+
}
|
185
|
+
if (format === "name") {
|
186
|
+
formattedString = this.toName();
|
187
|
+
}
|
188
|
+
if (format === "hsl") {
|
189
|
+
formattedString = this.toHslString();
|
190
|
+
}
|
191
|
+
if (format === "hsv") {
|
192
|
+
formattedString = this.toHsvString();
|
193
|
+
}
|
194
|
+
|
195
|
+
return formattedString || this.toHexString();
|
196
|
+
},
|
197
|
+
|
198
|
+
_applyModification: function(fn, args) {
|
199
|
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
200
|
+
this._r = color._r;
|
201
|
+
this._g = color._g;
|
202
|
+
this._b = color._b;
|
203
|
+
this.setAlpha(color._a);
|
204
|
+
return this;
|
205
|
+
},
|
206
|
+
lighten: function() {
|
207
|
+
return this._applyModification(lighten, arguments);
|
208
|
+
},
|
209
|
+
brighten: function() {
|
210
|
+
return this._applyModification(brighten, arguments);
|
211
|
+
},
|
212
|
+
darken: function() {
|
213
|
+
return this._applyModification(darken, arguments);
|
214
|
+
},
|
215
|
+
desaturate: function() {
|
216
|
+
return this._applyModification(desaturate, arguments);
|
217
|
+
},
|
218
|
+
saturate: function() {
|
219
|
+
return this._applyModification(saturate, arguments);
|
220
|
+
},
|
221
|
+
greyscale: function() {
|
222
|
+
return this._applyModification(greyscale, arguments);
|
223
|
+
},
|
224
|
+
spin: function() {
|
225
|
+
return this._applyModification(spin, arguments);
|
226
|
+
},
|
227
|
+
|
228
|
+
_applyCombination: function(fn, args) {
|
229
|
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
230
|
+
},
|
231
|
+
analogous: function() {
|
232
|
+
return this._applyCombination(analogous, arguments);
|
233
|
+
},
|
234
|
+
complement: function() {
|
235
|
+
return this._applyCombination(complement, arguments);
|
236
|
+
},
|
237
|
+
monochromatic: function() {
|
238
|
+
return this._applyCombination(monochromatic, arguments);
|
239
|
+
},
|
240
|
+
splitcomplement: function() {
|
241
|
+
return this._applyCombination(splitcomplement, arguments);
|
242
|
+
},
|
243
|
+
triad: function() {
|
244
|
+
return this._applyCombination(triad, arguments);
|
245
|
+
},
|
246
|
+
tetrad: function() {
|
247
|
+
return this._applyCombination(tetrad, arguments);
|
248
|
+
}
|
249
|
+
};
|
165
250
|
|
166
251
|
// If input is an object, force 1 into "1.0" to handle ratios properly
|
167
252
|
// String input requires "1.0" as input, so 1 will be treated as 1
|
@@ -441,50 +526,72 @@ tinycolor.random = function() {
|
|
441
526
|
// Thanks to less.js for some of the basics here
|
442
527
|
// <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
|
443
528
|
|
444
|
-
|
529
|
+
function desaturate(color, amount) {
|
445
530
|
amount = (amount === 0) ? 0 : (amount || 10);
|
446
531
|
var hsl = tinycolor(color).toHsl();
|
447
532
|
hsl.s -= amount / 100;
|
448
533
|
hsl.s = clamp01(hsl.s);
|
449
534
|
return tinycolor(hsl);
|
450
|
-
}
|
451
|
-
|
535
|
+
}
|
536
|
+
|
537
|
+
function saturate(color, amount) {
|
452
538
|
amount = (amount === 0) ? 0 : (amount || 10);
|
453
539
|
var hsl = tinycolor(color).toHsl();
|
454
540
|
hsl.s += amount / 100;
|
455
541
|
hsl.s = clamp01(hsl.s);
|
456
542
|
return tinycolor(hsl);
|
457
|
-
}
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
543
|
+
}
|
544
|
+
|
545
|
+
function greyscale(color) {
|
546
|
+
return tinycolor(color).desaturate(100);
|
547
|
+
}
|
548
|
+
|
549
|
+
function lighten (color, amount) {
|
462
550
|
amount = (amount === 0) ? 0 : (amount || 10);
|
463
551
|
var hsl = tinycolor(color).toHsl();
|
464
552
|
hsl.l += amount / 100;
|
465
553
|
hsl.l = clamp01(hsl.l);
|
466
554
|
return tinycolor(hsl);
|
467
|
-
}
|
468
|
-
|
555
|
+
}
|
556
|
+
|
557
|
+
function brighten(color, amount) {
|
558
|
+
amount = (amount === 0) ? 0 : (amount || 10);
|
559
|
+
var rgb = tinycolor(color).toRgb();
|
560
|
+
rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
|
561
|
+
rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
|
562
|
+
rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
|
563
|
+
return tinycolor(rgb);
|
564
|
+
}
|
565
|
+
|
566
|
+
function darken (color, amount) {
|
469
567
|
amount = (amount === 0) ? 0 : (amount || 10);
|
470
568
|
var hsl = tinycolor(color).toHsl();
|
471
569
|
hsl.l -= amount / 100;
|
472
570
|
hsl.l = clamp01(hsl.l);
|
473
571
|
return tinycolor(hsl);
|
474
|
-
}
|
475
|
-
|
572
|
+
}
|
573
|
+
|
574
|
+
// Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
|
575
|
+
// Values outside of this range will be wrapped into this range.
|
576
|
+
function spin(color, amount) {
|
476
577
|
var hsl = tinycolor(color).toHsl();
|
477
|
-
|
578
|
+
var hue = (mathRound(hsl.h) + amount) % 360;
|
579
|
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
478
580
|
return tinycolor(hsl);
|
479
|
-
}
|
480
|
-
|
581
|
+
}
|
481
582
|
|
482
583
|
// Combination Functions
|
483
584
|
// ---------------------
|
484
585
|
// Thanks to jQuery xColor for some of the ideas behind these
|
485
586
|
// <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
|
486
587
|
|
487
|
-
|
588
|
+
function complement(color) {
|
589
|
+
var hsl = tinycolor(color).toHsl();
|
590
|
+
hsl.h = (hsl.h + 180) % 360;
|
591
|
+
return tinycolor(hsl);
|
592
|
+
}
|
593
|
+
|
594
|
+
function triad(color) {
|
488
595
|
var hsl = tinycolor(color).toHsl();
|
489
596
|
var h = hsl.h;
|
490
597
|
return [
|
@@ -492,8 +599,9 @@ tinycolor.triad = function(color) {
|
|
492
599
|
tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
|
493
600
|
tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
|
494
601
|
];
|
495
|
-
}
|
496
|
-
|
602
|
+
}
|
603
|
+
|
604
|
+
function tetrad(color) {
|
497
605
|
var hsl = tinycolor(color).toHsl();
|
498
606
|
var h = hsl.h;
|
499
607
|
return [
|
@@ -502,8 +610,9 @@ tinycolor.tetrad = function(color) {
|
|
502
610
|
tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
|
503
611
|
tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
|
504
612
|
];
|
505
|
-
}
|
506
|
-
|
613
|
+
}
|
614
|
+
|
615
|
+
function splitcomplement(color) {
|
507
616
|
var hsl = tinycolor(color).toHsl();
|
508
617
|
var h = hsl.h;
|
509
618
|
return [
|
@@ -511,8 +620,9 @@ tinycolor.splitcomplement = function(color) {
|
|
511
620
|
tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
|
512
621
|
tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
|
513
622
|
];
|
514
|
-
}
|
515
|
-
|
623
|
+
}
|
624
|
+
|
625
|
+
function analogous(color, results, slices) {
|
516
626
|
results = results || 6;
|
517
627
|
slices = slices || 30;
|
518
628
|
|
@@ -525,8 +635,9 @@ tinycolor.analogous = function(color, results, slices) {
|
|
525
635
|
ret.push(tinycolor(hsl));
|
526
636
|
}
|
527
637
|
return ret;
|
528
|
-
}
|
529
|
-
|
638
|
+
}
|
639
|
+
|
640
|
+
function monochromatic(color, results) {
|
530
641
|
results = results || 6;
|
531
642
|
var hsv = tinycolor(color).toHsv();
|
532
643
|
var h = hsv.h, s = hsv.s, v = hsv.v;
|
@@ -539,6 +650,41 @@ tinycolor.monochromatic = function(color, results) {
|
|
539
650
|
}
|
540
651
|
|
541
652
|
return ret;
|
653
|
+
}
|
654
|
+
|
655
|
+
// Utility Functions
|
656
|
+
// ---------------------
|
657
|
+
|
658
|
+
tinycolor.mix = function(color1, color2, amount) {
|
659
|
+
amount = (amount === 0) ? 0 : (amount || 50);
|
660
|
+
|
661
|
+
var rgb1 = tinycolor(color1).toRgb();
|
662
|
+
var rgb2 = tinycolor(color2).toRgb();
|
663
|
+
|
664
|
+
var p = amount / 100;
|
665
|
+
var w = p * 2 - 1;
|
666
|
+
var a = rgb2.a - rgb1.a;
|
667
|
+
|
668
|
+
var w1;
|
669
|
+
|
670
|
+
if (w * a == -1) {
|
671
|
+
w1 = w;
|
672
|
+
} else {
|
673
|
+
w1 = (w + a) / (1 + w * a);
|
674
|
+
}
|
675
|
+
|
676
|
+
w1 = (w1 + 1) / 2;
|
677
|
+
|
678
|
+
var w2 = 1 - w1;
|
679
|
+
|
680
|
+
var rgba = {
|
681
|
+
r: rgb2.r * w1 + rgb1.r * w2,
|
682
|
+
g: rgb2.g * w1 + rgb1.g * w2,
|
683
|
+
b: rgb2.b * w1 + rgb1.b * w2,
|
684
|
+
a: rgb2.a * p + rgb1.a * (1 - p)
|
685
|
+
};
|
686
|
+
|
687
|
+
return tinycolor(rgba);
|
542
688
|
};
|
543
689
|
|
544
690
|
|
@@ -551,14 +697,16 @@ tinycolor.monochromatic = function(color, results) {
|
|
551
697
|
// `brightness`: difference in brightness between the two colors
|
552
698
|
// `color`: difference in color/hue between the two colors
|
553
699
|
tinycolor.readability = function(color1, color2) {
|
554
|
-
var
|
555
|
-
var
|
556
|
-
var
|
557
|
-
var
|
700
|
+
var c1 = tinycolor(color1);
|
701
|
+
var c2 = tinycolor(color2);
|
702
|
+
var rgb1 = c1.toRgb();
|
703
|
+
var rgb2 = c2.toRgb();
|
704
|
+
var brightnessA = c1.getBrightness();
|
705
|
+
var brightnessB = c2.getBrightness();
|
558
706
|
var colorDiff = (
|
559
|
-
Math.max(
|
560
|
-
Math.max(
|
561
|
-
Math.max(
|
707
|
+
Math.max(rgb1.r, rgb2.r) - Math.min(rgb1.r, rgb2.r) +
|
708
|
+
Math.max(rgb1.g, rgb2.g) - Math.min(rgb1.g, rgb2.g) +
|
709
|
+
Math.max(rgb1.b, rgb2.b) - Math.min(rgb1.b, rgb2.b)
|
562
710
|
);
|
563
711
|
|
564
712
|
return {
|
@@ -571,8 +719,8 @@ tinycolor.readability = function(color1, color2) {
|
|
571
719
|
// http://www.w3.org/TR/AERT#color-contrast
|
572
720
|
// Ensure that foreground and background color combinations provide sufficient contrast.
|
573
721
|
// *Example*
|
574
|
-
// tinycolor.
|
575
|
-
tinycolor.
|
722
|
+
// tinycolor.isReadable("#000", "#111") => false
|
723
|
+
tinycolor.isReadable = function(color1, color2) {
|
576
724
|
var readability = tinycolor.readability(color1, color2);
|
577
725
|
return readability.brightness > 125 && readability.color > 500;
|
578
726
|
};
|
@@ -731,6 +879,7 @@ var names = tinycolor.names = {
|
|
731
879
|
plum: "dda0dd",
|
732
880
|
powderblue: "b0e0e6",
|
733
881
|
purple: "800080",
|
882
|
+
rebeccapurple: "663399",
|
734
883
|
red: "f00",
|
735
884
|
rosybrown: "bc8f8f",
|
736
885
|
royalblue: "4169e1",
|
@@ -878,6 +1027,7 @@ var matchers = (function() {
|
|
878
1027
|
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
879
1028
|
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
880
1029
|
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
1030
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
881
1031
|
hex3: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
882
1032
|
hex6: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
883
1033
|
hex8: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
@@ -919,6 +1069,9 @@ function stringInputToObject(color) {
|
|
919
1069
|
if ((match = matchers.hsv.exec(color))) {
|
920
1070
|
return { h: match[1], s: match[2], v: match[3] };
|
921
1071
|
}
|
1072
|
+
if ((match = matchers.hsva.exec(color))) {
|
1073
|
+
return { h: match[1], s: match[2], v: match[3], a: match[4] };
|
1074
|
+
}
|
922
1075
|
if ((match = matchers.hex8.exec(color))) {
|
923
1076
|
return {
|
924
1077
|
a: convertHexToDecimal(match[1]),
|
@@ -954,7 +1107,7 @@ if (typeof module !== "undefined" && module.exports) {
|
|
954
1107
|
tiny = tinycolor;
|
955
1108
|
}
|
956
1109
|
// AMD/requirejs: Define the module
|
957
|
-
else if (typeof define
|
1110
|
+
else if (typeof define === 'function' && define.amd) {
|
958
1111
|
define(function () {return tinycolor;});
|
959
1112
|
}
|
960
1113
|
// Browser: Expose to window
|
@@ -964,10 +1117,13 @@ else {
|
|
964
1117
|
|
965
1118
|
})();
|
966
1119
|
|
967
|
-
|
968
1120
|
var color = tiny(process.argv[2]);
|
969
1121
|
if(process.argv[3] == 'rgb') {
|
970
1122
|
console.log(color.toRgbString());
|
971
1123
|
} else {
|
1124
|
+
if(color.getAlpha() < 1.0) {
|
1125
|
+
var brightness_factor = (255 - color.getBrightness()) / 255;
|
1126
|
+
color = color.lighten(100 * brightness_factor * (1.0 - color.getAlpha()));
|
1127
|
+
}
|
972
1128
|
console.log(color.toHex());
|
973
1129
|
}
|