@ctrl/tinycolor 3.2.0 → 3.3.2
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.
- package/README.md +11 -1
- package/dist/bundles/tinycolor.umd.min.js.map +1 -1
- package/dist/conversion.js +32 -32
- package/dist/css-color-names.d.ts +1 -3
- package/dist/format-input.js +20 -20
- package/dist/from-ratio.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +183 -159
- package/dist/module/index.js +6 -3
- package/dist/public_api.js +1 -1
- package/dist/random.js +39 -37
- package/dist/readability.js +15 -12
- package/dist/to-ms-filter.js +8 -8
- package/dist/umd_api.js +8 -8
- package/dist/util.js +2 -2
- package/package.json +13 -13
package/dist/index.js
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.tinycolor = exports.TinyColor = void 0;
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
var conversion_1 = require("./conversion");
|
5
|
+
var css_color_names_1 = require("./css-color-names");
|
6
|
+
var format_input_1 = require("./format-input");
|
7
|
+
var util_1 = require("./util");
|
8
|
+
var TinyColor = /** @class */ (function () {
|
9
|
+
function TinyColor(color, opts) {
|
10
|
+
if (color === void 0) { color = ''; }
|
11
|
+
if (opts === void 0) { opts = {}; }
|
10
12
|
var _a;
|
11
13
|
// If input is already a tinycolor, return itself
|
12
14
|
if (color instanceof TinyColor) {
|
@@ -17,7 +19,7 @@ class TinyColor {
|
|
17
19
|
color = conversion_1.numberInputToObject(color);
|
18
20
|
}
|
19
21
|
this.originalInput = color;
|
20
|
-
|
22
|
+
var rgb = format_input_1.inputToRGB(color);
|
21
23
|
this.originalInput = color;
|
22
24
|
this.r = rgb.r;
|
23
25
|
this.g = rgb.g;
|
@@ -41,203 +43,211 @@ class TinyColor {
|
|
41
43
|
}
|
42
44
|
this.isValid = rgb.ok;
|
43
45
|
}
|
44
|
-
isDark() {
|
46
|
+
TinyColor.prototype.isDark = function () {
|
45
47
|
return this.getBrightness() < 128;
|
46
|
-
}
|
47
|
-
isLight() {
|
48
|
+
};
|
49
|
+
TinyColor.prototype.isLight = function () {
|
48
50
|
return !this.isDark();
|
49
|
-
}
|
51
|
+
};
|
50
52
|
/**
|
51
53
|
* Returns the perceived brightness of the color, from 0-255.
|
52
54
|
*/
|
53
|
-
getBrightness() {
|
55
|
+
TinyColor.prototype.getBrightness = function () {
|
54
56
|
// http://www.w3.org/TR/AERT#color-contrast
|
55
|
-
|
57
|
+
var rgb = this.toRgb();
|
56
58
|
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
|
57
|
-
}
|
59
|
+
};
|
58
60
|
/**
|
59
61
|
* Returns the perceived luminance of a color, from 0-1.
|
60
62
|
*/
|
61
|
-
getLuminance() {
|
63
|
+
TinyColor.prototype.getLuminance = function () {
|
62
64
|
// http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
var rgb = this.toRgb();
|
66
|
+
var R;
|
67
|
+
var G;
|
68
|
+
var B;
|
69
|
+
var RsRGB = rgb.r / 255;
|
70
|
+
var GsRGB = rgb.g / 255;
|
71
|
+
var BsRGB = rgb.b / 255;
|
70
72
|
if (RsRGB <= 0.03928) {
|
71
73
|
R = RsRGB / 12.92;
|
72
74
|
}
|
73
75
|
else {
|
74
|
-
|
76
|
+
// eslint-disable-next-line prefer-exponentiation-operator
|
77
|
+
R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
75
78
|
}
|
76
79
|
if (GsRGB <= 0.03928) {
|
77
80
|
G = GsRGB / 12.92;
|
78
81
|
}
|
79
82
|
else {
|
80
|
-
|
83
|
+
// eslint-disable-next-line prefer-exponentiation-operator
|
84
|
+
G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
81
85
|
}
|
82
86
|
if (BsRGB <= 0.03928) {
|
83
87
|
B = BsRGB / 12.92;
|
84
88
|
}
|
85
89
|
else {
|
86
|
-
|
90
|
+
// eslint-disable-next-line prefer-exponentiation-operator
|
91
|
+
B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
87
92
|
}
|
88
93
|
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
89
|
-
}
|
94
|
+
};
|
90
95
|
/**
|
91
96
|
* Returns the alpha value of a color, from 0-1.
|
92
97
|
*/
|
93
|
-
getAlpha() {
|
98
|
+
TinyColor.prototype.getAlpha = function () {
|
94
99
|
return this.a;
|
95
|
-
}
|
100
|
+
};
|
96
101
|
/**
|
97
102
|
* Sets the alpha value on the current color.
|
98
103
|
*
|
99
104
|
* @param alpha - The new alpha value. The accepted range is 0-1.
|
100
105
|
*/
|
101
|
-
setAlpha(alpha) {
|
106
|
+
TinyColor.prototype.setAlpha = function (alpha) {
|
102
107
|
this.a = util_1.boundAlpha(alpha);
|
103
108
|
this.roundA = Math.round(100 * this.a) / 100;
|
104
109
|
return this;
|
105
|
-
}
|
110
|
+
};
|
106
111
|
/**
|
107
112
|
* Returns the object as a HSVA object.
|
108
113
|
*/
|
109
|
-
toHsv() {
|
110
|
-
|
114
|
+
TinyColor.prototype.toHsv = function () {
|
115
|
+
var hsv = conversion_1.rgbToHsv(this.r, this.g, this.b);
|
111
116
|
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this.a };
|
112
|
-
}
|
117
|
+
};
|
113
118
|
/**
|
114
119
|
* Returns the hsva values interpolated into a string with the following format:
|
115
120
|
* "hsva(xxx, xxx, xxx, xx)".
|
116
121
|
*/
|
117
|
-
toHsvString() {
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
return this.a === 1 ?
|
123
|
-
}
|
122
|
+
TinyColor.prototype.toHsvString = function () {
|
123
|
+
var hsv = conversion_1.rgbToHsv(this.r, this.g, this.b);
|
124
|
+
var h = Math.round(hsv.h * 360);
|
125
|
+
var s = Math.round(hsv.s * 100);
|
126
|
+
var v = Math.round(hsv.v * 100);
|
127
|
+
return this.a === 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this.roundA + ")";
|
128
|
+
};
|
124
129
|
/**
|
125
130
|
* Returns the object as a HSLA object.
|
126
131
|
*/
|
127
|
-
toHsl() {
|
128
|
-
|
132
|
+
TinyColor.prototype.toHsl = function () {
|
133
|
+
var hsl = conversion_1.rgbToHsl(this.r, this.g, this.b);
|
129
134
|
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this.a };
|
130
|
-
}
|
135
|
+
};
|
131
136
|
/**
|
132
137
|
* Returns the hsla values interpolated into a string with the following format:
|
133
138
|
* "hsla(xxx, xxx, xxx, xx)".
|
134
139
|
*/
|
135
|
-
toHslString() {
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
return this.a === 1 ?
|
141
|
-
}
|
140
|
+
TinyColor.prototype.toHslString = function () {
|
141
|
+
var hsl = conversion_1.rgbToHsl(this.r, this.g, this.b);
|
142
|
+
var h = Math.round(hsl.h * 360);
|
143
|
+
var s = Math.round(hsl.s * 100);
|
144
|
+
var l = Math.round(hsl.l * 100);
|
145
|
+
return this.a === 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this.roundA + ")";
|
146
|
+
};
|
142
147
|
/**
|
143
148
|
* Returns the hex value of the color.
|
144
149
|
* @param allow3Char will shorten hex value to 3 char if possible
|
145
150
|
*/
|
146
|
-
toHex
|
151
|
+
TinyColor.prototype.toHex = function (allow3Char) {
|
152
|
+
if (allow3Char === void 0) { allow3Char = false; }
|
147
153
|
return conversion_1.rgbToHex(this.r, this.g, this.b, allow3Char);
|
148
|
-
}
|
154
|
+
};
|
149
155
|
/**
|
150
156
|
* Returns the hex value of the color -with a # appened.
|
151
157
|
* @param allow3Char will shorten hex value to 3 char if possible
|
152
158
|
*/
|
153
|
-
toHexString
|
159
|
+
TinyColor.prototype.toHexString = function (allow3Char) {
|
160
|
+
if (allow3Char === void 0) { allow3Char = false; }
|
154
161
|
return '#' + this.toHex(allow3Char);
|
155
|
-
}
|
162
|
+
};
|
156
163
|
/**
|
157
164
|
* Returns the hex 8 value of the color.
|
158
165
|
* @param allow4Char will shorten hex value to 4 char if possible
|
159
166
|
*/
|
160
|
-
toHex8
|
167
|
+
TinyColor.prototype.toHex8 = function (allow4Char) {
|
168
|
+
if (allow4Char === void 0) { allow4Char = false; }
|
161
169
|
return conversion_1.rgbaToHex(this.r, this.g, this.b, this.a, allow4Char);
|
162
|
-
}
|
170
|
+
};
|
163
171
|
/**
|
164
172
|
* Returns the hex 8 value of the color -with a # appened.
|
165
173
|
* @param allow4Char will shorten hex value to 4 char if possible
|
166
174
|
*/
|
167
|
-
toHex8String
|
175
|
+
TinyColor.prototype.toHex8String = function (allow4Char) {
|
176
|
+
if (allow4Char === void 0) { allow4Char = false; }
|
168
177
|
return '#' + this.toHex8(allow4Char);
|
169
|
-
}
|
178
|
+
};
|
170
179
|
/**
|
171
180
|
* Returns the object as a RGBA object.
|
172
181
|
*/
|
173
|
-
toRgb() {
|
182
|
+
TinyColor.prototype.toRgb = function () {
|
174
183
|
return {
|
175
184
|
r: Math.round(this.r),
|
176
185
|
g: Math.round(this.g),
|
177
186
|
b: Math.round(this.b),
|
178
187
|
a: this.a,
|
179
188
|
};
|
180
|
-
}
|
189
|
+
};
|
181
190
|
/**
|
182
191
|
* Returns the RGBA values interpolated into a string with the following format:
|
183
192
|
* "RGBA(xxx, xxx, xxx, xx)".
|
184
193
|
*/
|
185
|
-
toRgbString() {
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
return this.a === 1 ?
|
190
|
-
}
|
194
|
+
TinyColor.prototype.toRgbString = function () {
|
195
|
+
var r = Math.round(this.r);
|
196
|
+
var g = Math.round(this.g);
|
197
|
+
var b = Math.round(this.b);
|
198
|
+
return this.a === 1 ? "rgb(" + r + ", " + g + ", " + b + ")" : "rgba(" + r + ", " + g + ", " + b + ", " + this.roundA + ")";
|
199
|
+
};
|
191
200
|
/**
|
192
201
|
* Returns the object as a RGBA object.
|
193
202
|
*/
|
194
|
-
toPercentageRgb() {
|
195
|
-
|
203
|
+
TinyColor.prototype.toPercentageRgb = function () {
|
204
|
+
var fmt = function (x) { return Math.round(util_1.bound01(x, 255) * 100) + "%"; };
|
196
205
|
return {
|
197
206
|
r: fmt(this.r),
|
198
207
|
g: fmt(this.g),
|
199
208
|
b: fmt(this.b),
|
200
209
|
a: this.a,
|
201
210
|
};
|
202
|
-
}
|
211
|
+
};
|
203
212
|
/**
|
204
213
|
* Returns the RGBA relative values interpolated into a string
|
205
214
|
*/
|
206
|
-
toPercentageRgbString() {
|
207
|
-
|
215
|
+
TinyColor.prototype.toPercentageRgbString = function () {
|
216
|
+
var rnd = function (x) { return Math.round(util_1.bound01(x, 255) * 100); };
|
208
217
|
return this.a === 1
|
209
|
-
?
|
210
|
-
:
|
211
|
-
}
|
218
|
+
? "rgb(" + rnd(this.r) + "%, " + rnd(this.g) + "%, " + rnd(this.b) + "%)"
|
219
|
+
: "rgba(" + rnd(this.r) + "%, " + rnd(this.g) + "%, " + rnd(this.b) + "%, " + this.roundA + ")";
|
220
|
+
};
|
212
221
|
/**
|
213
222
|
* The 'real' name of the color -if there is one.
|
214
223
|
*/
|
215
|
-
toName() {
|
224
|
+
TinyColor.prototype.toName = function () {
|
216
225
|
if (this.a === 0) {
|
217
226
|
return 'transparent';
|
218
227
|
}
|
219
228
|
if (this.a < 1) {
|
220
229
|
return false;
|
221
230
|
}
|
222
|
-
|
223
|
-
for (
|
231
|
+
var hex = '#' + conversion_1.rgbToHex(this.r, this.g, this.b, false);
|
232
|
+
for (var _i = 0, _a = Object.entries(css_color_names_1.names); _i < _a.length; _i++) {
|
233
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
224
234
|
if (hex === value) {
|
225
235
|
return key;
|
226
236
|
}
|
227
237
|
}
|
228
238
|
return false;
|
229
|
-
}
|
239
|
+
};
|
230
240
|
/**
|
231
241
|
* String representation of the color.
|
232
242
|
*
|
233
243
|
* @param format - The format to be used when displaying the string representation.
|
234
244
|
*/
|
235
|
-
toString(format) {
|
236
|
-
|
245
|
+
TinyColor.prototype.toString = function (format) {
|
246
|
+
var formatSet = Boolean(format);
|
237
247
|
format = format !== null && format !== void 0 ? format : this.format;
|
238
|
-
|
239
|
-
|
240
|
-
|
248
|
+
var formattedString = false;
|
249
|
+
var hasAlpha = this.a < 1 && this.a >= 0;
|
250
|
+
var needsAlphaFormat = !formatSet && hasAlpha && (format.startsWith('hex') || format === 'name');
|
241
251
|
if (needsAlphaFormat) {
|
242
252
|
// Special case for "transparent", all other non-alpha formats
|
243
253
|
// will return rgba when there is transparency.
|
@@ -274,203 +284,217 @@ class TinyColor {
|
|
274
284
|
formattedString = this.toHsvString();
|
275
285
|
}
|
276
286
|
return formattedString || this.toHexString();
|
277
|
-
}
|
278
|
-
toNumber() {
|
287
|
+
};
|
288
|
+
TinyColor.prototype.toNumber = function () {
|
279
289
|
return (Math.round(this.r) << 16) + (Math.round(this.g) << 8) + Math.round(this.b);
|
280
|
-
}
|
281
|
-
clone() {
|
290
|
+
};
|
291
|
+
TinyColor.prototype.clone = function () {
|
282
292
|
return new TinyColor(this.toString());
|
283
|
-
}
|
293
|
+
};
|
284
294
|
/**
|
285
295
|
* Lighten the color a given amount. Providing 100 will always return white.
|
286
296
|
* @param amount - valid between 1-100
|
287
297
|
*/
|
288
|
-
lighten
|
289
|
-
|
298
|
+
TinyColor.prototype.lighten = function (amount) {
|
299
|
+
if (amount === void 0) { amount = 10; }
|
300
|
+
var hsl = this.toHsl();
|
290
301
|
hsl.l += amount / 100;
|
291
302
|
hsl.l = util_1.clamp01(hsl.l);
|
292
303
|
return new TinyColor(hsl);
|
293
|
-
}
|
304
|
+
};
|
294
305
|
/**
|
295
306
|
* Brighten the color a given amount, from 0 to 100.
|
296
307
|
* @param amount - valid between 1-100
|
297
308
|
*/
|
298
|
-
brighten
|
299
|
-
|
309
|
+
TinyColor.prototype.brighten = function (amount) {
|
310
|
+
if (amount === void 0) { amount = 10; }
|
311
|
+
var rgb = this.toRgb();
|
300
312
|
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
301
313
|
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
302
314
|
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
303
315
|
return new TinyColor(rgb);
|
304
|
-
}
|
316
|
+
};
|
305
317
|
/**
|
306
318
|
* Darken the color a given amount, from 0 to 100.
|
307
319
|
* Providing 100 will always return black.
|
308
320
|
* @param amount - valid between 1-100
|
309
321
|
*/
|
310
|
-
darken
|
311
|
-
|
322
|
+
TinyColor.prototype.darken = function (amount) {
|
323
|
+
if (amount === void 0) { amount = 10; }
|
324
|
+
var hsl = this.toHsl();
|
312
325
|
hsl.l -= amount / 100;
|
313
326
|
hsl.l = util_1.clamp01(hsl.l);
|
314
327
|
return new TinyColor(hsl);
|
315
|
-
}
|
328
|
+
};
|
316
329
|
/**
|
317
330
|
* Mix the color with pure white, from 0 to 100.
|
318
331
|
* Providing 0 will do nothing, providing 100 will always return white.
|
319
332
|
* @param amount - valid between 1-100
|
320
333
|
*/
|
321
|
-
tint
|
334
|
+
TinyColor.prototype.tint = function (amount) {
|
335
|
+
if (amount === void 0) { amount = 10; }
|
322
336
|
return this.mix('white', amount);
|
323
|
-
}
|
337
|
+
};
|
324
338
|
/**
|
325
339
|
* Mix the color with pure black, from 0 to 100.
|
326
340
|
* Providing 0 will do nothing, providing 100 will always return black.
|
327
341
|
* @param amount - valid between 1-100
|
328
342
|
*/
|
329
|
-
shade
|
343
|
+
TinyColor.prototype.shade = function (amount) {
|
344
|
+
if (amount === void 0) { amount = 10; }
|
330
345
|
return this.mix('black', amount);
|
331
|
-
}
|
346
|
+
};
|
332
347
|
/**
|
333
348
|
* Desaturate the color a given amount, from 0 to 100.
|
334
349
|
* Providing 100 will is the same as calling greyscale
|
335
350
|
* @param amount - valid between 1-100
|
336
351
|
*/
|
337
|
-
desaturate
|
338
|
-
|
352
|
+
TinyColor.prototype.desaturate = function (amount) {
|
353
|
+
if (amount === void 0) { amount = 10; }
|
354
|
+
var hsl = this.toHsl();
|
339
355
|
hsl.s -= amount / 100;
|
340
356
|
hsl.s = util_1.clamp01(hsl.s);
|
341
357
|
return new TinyColor(hsl);
|
342
|
-
}
|
358
|
+
};
|
343
359
|
/**
|
344
360
|
* Saturate the color a given amount, from 0 to 100.
|
345
361
|
* @param amount - valid between 1-100
|
346
362
|
*/
|
347
|
-
saturate
|
348
|
-
|
363
|
+
TinyColor.prototype.saturate = function (amount) {
|
364
|
+
if (amount === void 0) { amount = 10; }
|
365
|
+
var hsl = this.toHsl();
|
349
366
|
hsl.s += amount / 100;
|
350
367
|
hsl.s = util_1.clamp01(hsl.s);
|
351
368
|
return new TinyColor(hsl);
|
352
|
-
}
|
369
|
+
};
|
353
370
|
/**
|
354
371
|
* Completely desaturates a color into greyscale.
|
355
372
|
* Same as calling `desaturate(100)`
|
356
373
|
*/
|
357
|
-
greyscale() {
|
374
|
+
TinyColor.prototype.greyscale = function () {
|
358
375
|
return this.desaturate(100);
|
359
|
-
}
|
376
|
+
};
|
360
377
|
/**
|
361
378
|
* Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
|
362
379
|
* Values outside of this range will be wrapped into this range.
|
363
380
|
*/
|
364
|
-
spin(amount) {
|
365
|
-
|
366
|
-
|
381
|
+
TinyColor.prototype.spin = function (amount) {
|
382
|
+
var hsl = this.toHsl();
|
383
|
+
var hue = (hsl.h + amount) % 360;
|
367
384
|
hsl.h = hue < 0 ? 360 + hue : hue;
|
368
385
|
return new TinyColor(hsl);
|
369
|
-
}
|
386
|
+
};
|
370
387
|
/**
|
371
388
|
* Mix the current color a given amount with another color, from 0 to 100.
|
372
389
|
* 0 means no mixing (return current color).
|
373
390
|
*/
|
374
|
-
mix(color, amount
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
391
|
+
TinyColor.prototype.mix = function (color, amount) {
|
392
|
+
if (amount === void 0) { amount = 50; }
|
393
|
+
var rgb1 = this.toRgb();
|
394
|
+
var rgb2 = new TinyColor(color).toRgb();
|
395
|
+
var p = amount / 100;
|
396
|
+
var rgba = {
|
379
397
|
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
380
398
|
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
381
399
|
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
382
400
|
a: (rgb2.a - rgb1.a) * p + rgb1.a,
|
383
401
|
};
|
384
402
|
return new TinyColor(rgba);
|
385
|
-
}
|
386
|
-
analogous
|
387
|
-
|
388
|
-
|
389
|
-
|
403
|
+
};
|
404
|
+
TinyColor.prototype.analogous = function (results, slices) {
|
405
|
+
if (results === void 0) { results = 6; }
|
406
|
+
if (slices === void 0) { slices = 30; }
|
407
|
+
var hsl = this.toHsl();
|
408
|
+
var part = 360 / slices;
|
409
|
+
var ret = [this];
|
390
410
|
for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results;) {
|
391
411
|
hsl.h = (hsl.h + part) % 360;
|
392
412
|
ret.push(new TinyColor(hsl));
|
393
413
|
}
|
394
414
|
return ret;
|
395
|
-
}
|
415
|
+
};
|
396
416
|
/**
|
397
417
|
* taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js
|
398
418
|
*/
|
399
|
-
complement() {
|
400
|
-
|
419
|
+
TinyColor.prototype.complement = function () {
|
420
|
+
var hsl = this.toHsl();
|
401
421
|
hsl.h = (hsl.h + 180) % 360;
|
402
422
|
return new TinyColor(hsl);
|
403
|
-
}
|
404
|
-
monochromatic
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
423
|
+
};
|
424
|
+
TinyColor.prototype.monochromatic = function (results) {
|
425
|
+
if (results === void 0) { results = 6; }
|
426
|
+
var hsv = this.toHsv();
|
427
|
+
var h = hsv.h;
|
428
|
+
var s = hsv.s;
|
429
|
+
var v = hsv.v;
|
430
|
+
var res = [];
|
431
|
+
var modification = 1 / results;
|
411
432
|
while (results--) {
|
412
|
-
res.push(new TinyColor({ h, s, v }));
|
433
|
+
res.push(new TinyColor({ h: h, s: s, v: v }));
|
413
434
|
v = (v + modification) % 1;
|
414
435
|
}
|
415
436
|
return res;
|
416
|
-
}
|
417
|
-
splitcomplement() {
|
418
|
-
|
419
|
-
|
437
|
+
};
|
438
|
+
TinyColor.prototype.splitcomplement = function () {
|
439
|
+
var hsl = this.toHsl();
|
440
|
+
var h = hsl.h;
|
420
441
|
return [
|
421
442
|
this,
|
422
443
|
new TinyColor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }),
|
423
444
|
new TinyColor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }),
|
424
445
|
];
|
425
|
-
}
|
446
|
+
};
|
426
447
|
/**
|
427
448
|
* Compute how the color would appear on a background
|
428
449
|
*/
|
429
|
-
onBackground(background) {
|
430
|
-
|
431
|
-
|
450
|
+
TinyColor.prototype.onBackground = function (background) {
|
451
|
+
var fg = this.toRgb();
|
452
|
+
var bg = new TinyColor(background).toRgb();
|
432
453
|
return new TinyColor({
|
433
454
|
r: bg.r + (fg.r - bg.r) * fg.a,
|
434
455
|
g: bg.g + (fg.g - bg.g) * fg.a,
|
435
456
|
b: bg.b + (fg.b - bg.b) * fg.a,
|
436
457
|
});
|
437
|
-
}
|
458
|
+
};
|
438
459
|
/**
|
439
460
|
* Alias for `polyad(3)`
|
440
461
|
*/
|
441
|
-
triad() {
|
462
|
+
TinyColor.prototype.triad = function () {
|
442
463
|
return this.polyad(3);
|
443
|
-
}
|
464
|
+
};
|
444
465
|
/**
|
445
466
|
* Alias for `polyad(4)`
|
446
467
|
*/
|
447
|
-
tetrad() {
|
468
|
+
TinyColor.prototype.tetrad = function () {
|
448
469
|
return this.polyad(4);
|
449
|
-
}
|
470
|
+
};
|
450
471
|
/**
|
451
472
|
* Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...)
|
452
473
|
* monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc...
|
453
474
|
*/
|
454
|
-
polyad(n) {
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
for (
|
475
|
+
TinyColor.prototype.polyad = function (n) {
|
476
|
+
var hsl = this.toHsl();
|
477
|
+
var h = hsl.h;
|
478
|
+
var result = [this];
|
479
|
+
var increment = 360 / n;
|
480
|
+
for (var i = 1; i < n; i++) {
|
460
481
|
result.push(new TinyColor({ h: (h + i * increment) % 360, s: hsl.s, l: hsl.l }));
|
461
482
|
}
|
462
483
|
return result;
|
463
|
-
}
|
484
|
+
};
|
464
485
|
/**
|
465
486
|
* compare color vs current color
|
466
487
|
*/
|
467
|
-
equals(color) {
|
488
|
+
TinyColor.prototype.equals = function (color) {
|
468
489
|
return this.toRgbString() === new TinyColor(color).toRgbString();
|
469
|
-
}
|
470
|
-
|
490
|
+
};
|
491
|
+
return TinyColor;
|
492
|
+
}());
|
471
493
|
exports.TinyColor = TinyColor;
|
472
494
|
// kept for backwards compatability with v1
|
473
|
-
function tinycolor(color
|
495
|
+
function tinycolor(color, opts) {
|
496
|
+
if (color === void 0) { color = ''; }
|
497
|
+
if (opts === void 0) { opts = {}; }
|
474
498
|
return new TinyColor(color, opts);
|
475
499
|
}
|
476
500
|
exports.tinycolor = tinycolor;
|
package/dist/module/index.js
CHANGED
@@ -70,19 +70,22 @@ var TinyColor = /** @class */ (function () {
|
|
70
70
|
R = RsRGB / 12.92;
|
71
71
|
}
|
72
72
|
else {
|
73
|
-
|
73
|
+
// eslint-disable-next-line prefer-exponentiation-operator
|
74
|
+
R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
74
75
|
}
|
75
76
|
if (GsRGB <= 0.03928) {
|
76
77
|
G = GsRGB / 12.92;
|
77
78
|
}
|
78
79
|
else {
|
79
|
-
|
80
|
+
// eslint-disable-next-line prefer-exponentiation-operator
|
81
|
+
G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
80
82
|
}
|
81
83
|
if (BsRGB <= 0.03928) {
|
82
84
|
B = BsRGB / 12.92;
|
83
85
|
}
|
84
86
|
else {
|
85
|
-
|
87
|
+
// eslint-disable-next-line prefer-exponentiation-operator
|
88
|
+
B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
86
89
|
}
|
87
90
|
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
88
91
|
};
|
package/dist/public_api.js
CHANGED
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
11
|
};
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
-
|
13
|
+
var index_1 = require("./index");
|
14
14
|
__exportStar(require("./index"), exports);
|
15
15
|
__exportStar(require("./css-color-names"), exports);
|
16
16
|
__exportStar(require("./readability"), exports);
|