@ctrl/tinycolor 3.4.0 → 3.5.0
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 +1 -1
- package/dist/bundles/tinycolor.umd.min.js +1 -1
- package/dist/bundles/tinycolor.umd.min.js.map +1 -1
- package/dist/conversion.d.ts +1 -1
- package/dist/conversion.js +26 -26
- package/dist/format-input.js +26 -25
- package/dist/from-ratio.js +3 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +28 -21
- package/dist/interfaces.d.ts +1 -1
- package/dist/module/format-input.js +4 -3
- package/dist/module/index.js +14 -7
- package/dist/module/random.js +1 -0
- package/dist/module/to-ms-filter.js +1 -1
- package/dist/module/umd_api.js +1 -2
- package/dist/module/util.js +1 -1
- package/dist/public_api.js +5 -1
- package/dist/random.js +1 -0
- package/dist/to-ms-filter.js +3 -3
- package/dist/umd_api.js +0 -1
- package/dist/util.js +1 -1
- package/package.json +17 -17
package/dist/conversion.js
CHANGED
@@ -12,9 +12,9 @@ var util_1 = require("./util");
|
|
12
12
|
*/
|
13
13
|
function rgbToRgb(r, g, b) {
|
14
14
|
return {
|
15
|
-
r: util_1.bound01(r, 255) * 255,
|
16
|
-
g: util_1.bound01(g, 255) * 255,
|
17
|
-
b: util_1.bound01(b, 255) * 255,
|
15
|
+
r: (0, util_1.bound01)(r, 255) * 255,
|
16
|
+
g: (0, util_1.bound01)(g, 255) * 255,
|
17
|
+
b: (0, util_1.bound01)(b, 255) * 255,
|
18
18
|
};
|
19
19
|
}
|
20
20
|
exports.rgbToRgb = rgbToRgb;
|
@@ -24,9 +24,9 @@ exports.rgbToRgb = rgbToRgb;
|
|
24
24
|
* *Returns:* { h, s, l } in [0,1]
|
25
25
|
*/
|
26
26
|
function rgbToHsl(r, g, b) {
|
27
|
-
r = util_1.bound01(r, 255);
|
28
|
-
g = util_1.bound01(g, 255);
|
29
|
-
b = util_1.bound01(b, 255);
|
27
|
+
r = (0, util_1.bound01)(r, 255);
|
28
|
+
g = (0, util_1.bound01)(g, 255);
|
29
|
+
b = (0, util_1.bound01)(b, 255);
|
30
30
|
var max = Math.max(r, g, b);
|
31
31
|
var min = Math.min(r, g, b);
|
32
32
|
var h = 0;
|
@@ -85,9 +85,9 @@ function hslToRgb(h, s, l) {
|
|
85
85
|
var r;
|
86
86
|
var g;
|
87
87
|
var b;
|
88
|
-
h = util_1.bound01(h, 360);
|
89
|
-
s = util_1.bound01(s, 100);
|
90
|
-
l = util_1.bound01(l, 100);
|
88
|
+
h = (0, util_1.bound01)(h, 360);
|
89
|
+
s = (0, util_1.bound01)(s, 100);
|
90
|
+
l = (0, util_1.bound01)(l, 100);
|
91
91
|
if (s === 0) {
|
92
92
|
// achromatic
|
93
93
|
g = l;
|
@@ -111,9 +111,9 @@ exports.hslToRgb = hslToRgb;
|
|
111
111
|
* *Returns:* { h, s, v } in [0,1]
|
112
112
|
*/
|
113
113
|
function rgbToHsv(r, g, b) {
|
114
|
-
r = util_1.bound01(r, 255);
|
115
|
-
g = util_1.bound01(g, 255);
|
116
|
-
b = util_1.bound01(b, 255);
|
114
|
+
r = (0, util_1.bound01)(r, 255);
|
115
|
+
g = (0, util_1.bound01)(g, 255);
|
116
|
+
b = (0, util_1.bound01)(b, 255);
|
117
117
|
var max = Math.max(r, g, b);
|
118
118
|
var min = Math.min(r, g, b);
|
119
119
|
var h = 0;
|
@@ -149,9 +149,9 @@ exports.rgbToHsv = rgbToHsv;
|
|
149
149
|
* *Returns:* { r, g, b } in the set [0, 255]
|
150
150
|
*/
|
151
151
|
function hsvToRgb(h, s, v) {
|
152
|
-
h = util_1.bound01(h, 360) * 6;
|
153
|
-
s = util_1.bound01(s, 100);
|
154
|
-
v = util_1.bound01(v, 100);
|
152
|
+
h = (0, util_1.bound01)(h, 360) * 6;
|
153
|
+
s = (0, util_1.bound01)(s, 100);
|
154
|
+
v = (0, util_1.bound01)(v, 100);
|
155
155
|
var i = Math.floor(h);
|
156
156
|
var f = h - i;
|
157
157
|
var p = v * (1 - s);
|
@@ -172,9 +172,9 @@ exports.hsvToRgb = hsvToRgb;
|
|
172
172
|
*/
|
173
173
|
function rgbToHex(r, g, b, allow3Char) {
|
174
174
|
var hex = [
|
175
|
-
util_1.pad2(Math.round(r).toString(16)),
|
176
|
-
util_1.pad2(Math.round(g).toString(16)),
|
177
|
-
util_1.pad2(Math.round(b).toString(16)),
|
175
|
+
(0, util_1.pad2)(Math.round(r).toString(16)),
|
176
|
+
(0, util_1.pad2)(Math.round(g).toString(16)),
|
177
|
+
(0, util_1.pad2)(Math.round(b).toString(16)),
|
178
178
|
];
|
179
179
|
// Return a 3 character hex if possible
|
180
180
|
if (allow3Char &&
|
@@ -195,10 +195,10 @@ exports.rgbToHex = rgbToHex;
|
|
195
195
|
// eslint-disable-next-line max-params
|
196
196
|
function rgbaToHex(r, g, b, a, allow4Char) {
|
197
197
|
var hex = [
|
198
|
-
util_1.pad2(Math.round(r).toString(16)),
|
199
|
-
util_1.pad2(Math.round(g).toString(16)),
|
200
|
-
util_1.pad2(Math.round(b).toString(16)),
|
201
|
-
util_1.pad2(convertDecimalToHex(a)),
|
198
|
+
(0, util_1.pad2)(Math.round(r).toString(16)),
|
199
|
+
(0, util_1.pad2)(Math.round(g).toString(16)),
|
200
|
+
(0, util_1.pad2)(Math.round(b).toString(16)),
|
201
|
+
(0, util_1.pad2)(convertDecimalToHex(a)),
|
202
202
|
];
|
203
203
|
// Return a 4 character hex if possible
|
204
204
|
if (allow4Char &&
|
@@ -217,10 +217,10 @@ exports.rgbaToHex = rgbaToHex;
|
|
217
217
|
*/
|
218
218
|
function rgbaToArgbHex(r, g, b, a) {
|
219
219
|
var hex = [
|
220
|
-
util_1.pad2(convertDecimalToHex(a)),
|
221
|
-
util_1.pad2(Math.round(r).toString(16)),
|
222
|
-
util_1.pad2(Math.round(g).toString(16)),
|
223
|
-
util_1.pad2(Math.round(b).toString(16)),
|
220
|
+
(0, util_1.pad2)(convertDecimalToHex(a)),
|
221
|
+
(0, util_1.pad2)(Math.round(r).toString(16)),
|
222
|
+
(0, util_1.pad2)(Math.round(g).toString(16)),
|
223
|
+
(0, util_1.pad2)(Math.round(b).toString(16)),
|
224
224
|
];
|
225
225
|
return hex.join('');
|
226
226
|
}
|
package/dist/format-input.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.isValidCSSUnit = exports.stringInputToObject = exports.inputToRGB = void 0;
|
4
|
+
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
4
5
|
var conversion_1 = require("./conversion");
|
5
6
|
var css_color_names_1 = require("./css-color-names");
|
6
7
|
var util_1 = require("./util");
|
@@ -35,21 +36,21 @@ function inputToRGB(color) {
|
|
35
36
|
}
|
36
37
|
if (typeof color === 'object') {
|
37
38
|
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
38
|
-
rgb = conversion_1.rgbToRgb(color.r, color.g, color.b);
|
39
|
+
rgb = (0, conversion_1.rgbToRgb)(color.r, color.g, color.b);
|
39
40
|
ok = true;
|
40
41
|
format = String(color.r).substr(-1) === '%' ? 'prgb' : 'rgb';
|
41
42
|
}
|
42
43
|
else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
43
|
-
s = util_1.convertToPercentage(color.s);
|
44
|
-
v = util_1.convertToPercentage(color.v);
|
45
|
-
rgb = conversion_1.hsvToRgb(color.h, s, v);
|
44
|
+
s = (0, util_1.convertToPercentage)(color.s);
|
45
|
+
v = (0, util_1.convertToPercentage)(color.v);
|
46
|
+
rgb = (0, conversion_1.hsvToRgb)(color.h, s, v);
|
46
47
|
ok = true;
|
47
48
|
format = 'hsv';
|
48
49
|
}
|
49
50
|
else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
50
|
-
s = util_1.convertToPercentage(color.s);
|
51
|
-
l = util_1.convertToPercentage(color.l);
|
52
|
-
rgb = conversion_1.hslToRgb(color.h, s, l);
|
51
|
+
s = (0, util_1.convertToPercentage)(color.s);
|
52
|
+
l = (0, util_1.convertToPercentage)(color.l);
|
53
|
+
rgb = (0, conversion_1.hslToRgb)(color.h, s, l);
|
53
54
|
ok = true;
|
54
55
|
format = 'hsl';
|
55
56
|
}
|
@@ -57,7 +58,7 @@ function inputToRGB(color) {
|
|
57
58
|
a = color.a;
|
58
59
|
}
|
59
60
|
}
|
60
|
-
a = util_1.boundAlpha(a);
|
61
|
+
a = (0, util_1.boundAlpha)(a);
|
61
62
|
return {
|
62
63
|
ok: ok,
|
63
64
|
format: color.format || format,
|
@@ -73,12 +74,12 @@ var CSS_INTEGER = '[-\\+]?\\d+%?';
|
|
73
74
|
// <http://www.w3.org/TR/css3-values/#number-value>
|
74
75
|
var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
|
75
76
|
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
|
76
|
-
var CSS_UNIT = "(?:"
|
77
|
+
var CSS_UNIT = "(?:".concat(CSS_NUMBER, ")|(?:").concat(CSS_INTEGER, ")");
|
77
78
|
// Actual matching.
|
78
79
|
// Parentheses and commas are optional, but not required.
|
79
80
|
// Whitespace can take the place of commas or opening paren
|
80
|
-
var PERMISSIVE_MATCH3 = "[\\s|\\(]+("
|
81
|
-
var PERMISSIVE_MATCH4 = "[\\s|\\(]+("
|
81
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(".concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")\\s*\\)?");
|
82
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(".concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")\\s*\\)?");
|
82
83
|
var matchers = {
|
83
84
|
CSS_UNIT: new RegExp(CSS_UNIT),
|
84
85
|
rgb: new RegExp('rgb' + PERMISSIVE_MATCH3),
|
@@ -140,38 +141,38 @@ function stringInputToObject(color) {
|
|
140
141
|
match = matchers.hex8.exec(color);
|
141
142
|
if (match) {
|
142
143
|
return {
|
143
|
-
r: conversion_1.parseIntFromHex(match[1]),
|
144
|
-
g: conversion_1.parseIntFromHex(match[2]),
|
145
|
-
b: conversion_1.parseIntFromHex(match[3]),
|
146
|
-
a: conversion_1.convertHexToDecimal(match[4]),
|
144
|
+
r: (0, conversion_1.parseIntFromHex)(match[1]),
|
145
|
+
g: (0, conversion_1.parseIntFromHex)(match[2]),
|
146
|
+
b: (0, conversion_1.parseIntFromHex)(match[3]),
|
147
|
+
a: (0, conversion_1.convertHexToDecimal)(match[4]),
|
147
148
|
format: named ? 'name' : 'hex8',
|
148
149
|
};
|
149
150
|
}
|
150
151
|
match = matchers.hex6.exec(color);
|
151
152
|
if (match) {
|
152
153
|
return {
|
153
|
-
r: conversion_1.parseIntFromHex(match[1]),
|
154
|
-
g: conversion_1.parseIntFromHex(match[2]),
|
155
|
-
b: conversion_1.parseIntFromHex(match[3]),
|
154
|
+
r: (0, conversion_1.parseIntFromHex)(match[1]),
|
155
|
+
g: (0, conversion_1.parseIntFromHex)(match[2]),
|
156
|
+
b: (0, conversion_1.parseIntFromHex)(match[3]),
|
156
157
|
format: named ? 'name' : 'hex',
|
157
158
|
};
|
158
159
|
}
|
159
160
|
match = matchers.hex4.exec(color);
|
160
161
|
if (match) {
|
161
162
|
return {
|
162
|
-
r: conversion_1.parseIntFromHex(match[1] + match[1]),
|
163
|
-
g: conversion_1.parseIntFromHex(match[2] + match[2]),
|
164
|
-
b: conversion_1.parseIntFromHex(match[3] + match[3]),
|
165
|
-
a: conversion_1.convertHexToDecimal(match[4] + match[4]),
|
163
|
+
r: (0, conversion_1.parseIntFromHex)(match[1] + match[1]),
|
164
|
+
g: (0, conversion_1.parseIntFromHex)(match[2] + match[2]),
|
165
|
+
b: (0, conversion_1.parseIntFromHex)(match[3] + match[3]),
|
166
|
+
a: (0, conversion_1.convertHexToDecimal)(match[4] + match[4]),
|
166
167
|
format: named ? 'name' : 'hex8',
|
167
168
|
};
|
168
169
|
}
|
169
170
|
match = matchers.hex3.exec(color);
|
170
171
|
if (match) {
|
171
172
|
return {
|
172
|
-
r: conversion_1.parseIntFromHex(match[1] + match[1]),
|
173
|
-
g: conversion_1.parseIntFromHex(match[2] + match[2]),
|
174
|
-
b: conversion_1.parseIntFromHex(match[3] + match[3]),
|
173
|
+
r: (0, conversion_1.parseIntFromHex)(match[1] + match[1]),
|
174
|
+
g: (0, conversion_1.parseIntFromHex)(match[2] + match[2]),
|
175
|
+
b: (0, conversion_1.parseIntFromHex)(match[3] + match[3]),
|
175
176
|
format: named ? 'name' : 'hex',
|
176
177
|
};
|
177
178
|
}
|
package/dist/from-ratio.js
CHANGED
@@ -9,9 +9,9 @@ var util_1 = require("./util");
|
|
9
9
|
*/
|
10
10
|
function fromRatio(ratio, opts) {
|
11
11
|
var newColor = {
|
12
|
-
r: util_1.convertToPercentage(ratio.r),
|
13
|
-
g: util_1.convertToPercentage(ratio.g),
|
14
|
-
b: util_1.convertToPercentage(ratio.b),
|
12
|
+
r: (0, util_1.convertToPercentage)(ratio.r),
|
13
|
+
g: (0, util_1.convertToPercentage)(ratio.g),
|
14
|
+
b: (0, util_1.convertToPercentage)(ratio.b),
|
15
15
|
};
|
16
16
|
if (ratio.a !== undefined) {
|
17
17
|
newColor.a = Number(ratio.a);
|
package/dist/index.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import { HSL, HSLA, HSV, HSVA, RGB, RGBA
|
1
|
+
import { HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces';
|
2
2
|
export interface TinyColorOptions {
|
3
3
|
format: string;
|
4
4
|
gradientType: string;
|
5
5
|
}
|
6
|
-
export
|
7
|
-
export
|
6
|
+
export type ColorInput = string | number | RGB | RGBA | HSL | HSLA | HSV | HSVA | TinyColor;
|
7
|
+
export type ColorFormats = 'rgb' | 'prgb' | 'hex' | 'hex3' | 'hex4' | 'hex6' | 'hex8' | 'name' | 'hsl' | 'hsv';
|
8
8
|
export declare class TinyColor {
|
9
9
|
/** red */
|
10
10
|
r: number;
|
@@ -44,6 +44,10 @@ export declare class TinyColor {
|
|
44
44
|
* @param alpha - The new alpha value. The accepted range is 0-1.
|
45
45
|
*/
|
46
46
|
setAlpha(alpha?: string | number): this;
|
47
|
+
/**
|
48
|
+
* Returns whether the color is monochrome.
|
49
|
+
*/
|
50
|
+
isMonochrome(): boolean;
|
47
51
|
/**
|
48
52
|
* Returns the object as a HSVA object.
|
49
53
|
*/
|
package/dist/index.js
CHANGED
@@ -16,10 +16,10 @@ var TinyColor = /** @class */ (function () {
|
|
16
16
|
return color;
|
17
17
|
}
|
18
18
|
if (typeof color === 'number') {
|
19
|
-
color = conversion_1.numberInputToObject(color);
|
19
|
+
color = (0, conversion_1.numberInputToObject)(color);
|
20
20
|
}
|
21
21
|
this.originalInput = color;
|
22
|
-
var rgb = format_input_1.inputToRGB(color);
|
22
|
+
var rgb = (0, format_input_1.inputToRGB)(color);
|
23
23
|
this.originalInput = color;
|
24
24
|
this.r = rgb.r;
|
25
25
|
this.g = rgb.g;
|
@@ -104,15 +104,22 @@ var TinyColor = /** @class */ (function () {
|
|
104
104
|
* @param alpha - The new alpha value. The accepted range is 0-1.
|
105
105
|
*/
|
106
106
|
TinyColor.prototype.setAlpha = function (alpha) {
|
107
|
-
this.a = util_1.boundAlpha(alpha);
|
107
|
+
this.a = (0, util_1.boundAlpha)(alpha);
|
108
108
|
this.roundA = Math.round(100 * this.a) / 100;
|
109
109
|
return this;
|
110
110
|
};
|
111
|
+
/**
|
112
|
+
* Returns whether the color is monochrome.
|
113
|
+
*/
|
114
|
+
TinyColor.prototype.isMonochrome = function () {
|
115
|
+
var s = this.toHsl().s;
|
116
|
+
return s === 0;
|
117
|
+
};
|
111
118
|
/**
|
112
119
|
* Returns the object as a HSVA object.
|
113
120
|
*/
|
114
121
|
TinyColor.prototype.toHsv = function () {
|
115
|
-
var hsv = conversion_1.rgbToHsv(this.r, this.g, this.b);
|
122
|
+
var hsv = (0, conversion_1.rgbToHsv)(this.r, this.g, this.b);
|
116
123
|
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this.a };
|
117
124
|
};
|
118
125
|
/**
|
@@ -120,17 +127,17 @@ var TinyColor = /** @class */ (function () {
|
|
120
127
|
* "hsva(xxx, xxx, xxx, xx)".
|
121
128
|
*/
|
122
129
|
TinyColor.prototype.toHsvString = function () {
|
123
|
-
var hsv = conversion_1.rgbToHsv(this.r, this.g, this.b);
|
130
|
+
var hsv = (0, conversion_1.rgbToHsv)(this.r, this.g, this.b);
|
124
131
|
var h = Math.round(hsv.h * 360);
|
125
132
|
var s = Math.round(hsv.s * 100);
|
126
133
|
var v = Math.round(hsv.v * 100);
|
127
|
-
return this.a === 1 ? "hsv("
|
134
|
+
return this.a === 1 ? "hsv(".concat(h, ", ").concat(s, "%, ").concat(v, "%)") : "hsva(".concat(h, ", ").concat(s, "%, ").concat(v, "%, ").concat(this.roundA, ")");
|
128
135
|
};
|
129
136
|
/**
|
130
137
|
* Returns the object as a HSLA object.
|
131
138
|
*/
|
132
139
|
TinyColor.prototype.toHsl = function () {
|
133
|
-
var hsl = conversion_1.rgbToHsl(this.r, this.g, this.b);
|
140
|
+
var hsl = (0, conversion_1.rgbToHsl)(this.r, this.g, this.b);
|
134
141
|
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this.a };
|
135
142
|
};
|
136
143
|
/**
|
@@ -138,11 +145,11 @@ var TinyColor = /** @class */ (function () {
|
|
138
145
|
* "hsla(xxx, xxx, xxx, xx)".
|
139
146
|
*/
|
140
147
|
TinyColor.prototype.toHslString = function () {
|
141
|
-
var hsl = conversion_1.rgbToHsl(this.r, this.g, this.b);
|
148
|
+
var hsl = (0, conversion_1.rgbToHsl)(this.r, this.g, this.b);
|
142
149
|
var h = Math.round(hsl.h * 360);
|
143
150
|
var s = Math.round(hsl.s * 100);
|
144
151
|
var l = Math.round(hsl.l * 100);
|
145
|
-
return this.a === 1 ? "hsl("
|
152
|
+
return this.a === 1 ? "hsl(".concat(h, ", ").concat(s, "%, ").concat(l, "%)") : "hsla(".concat(h, ", ").concat(s, "%, ").concat(l, "%, ").concat(this.roundA, ")");
|
146
153
|
};
|
147
154
|
/**
|
148
155
|
* Returns the hex value of the color.
|
@@ -150,7 +157,7 @@ var TinyColor = /** @class */ (function () {
|
|
150
157
|
*/
|
151
158
|
TinyColor.prototype.toHex = function (allow3Char) {
|
152
159
|
if (allow3Char === void 0) { allow3Char = false; }
|
153
|
-
return conversion_1.rgbToHex(this.r, this.g, this.b, allow3Char);
|
160
|
+
return (0, conversion_1.rgbToHex)(this.r, this.g, this.b, allow3Char);
|
154
161
|
};
|
155
162
|
/**
|
156
163
|
* Returns the hex value of the color -with a # appened.
|
@@ -166,7 +173,7 @@ var TinyColor = /** @class */ (function () {
|
|
166
173
|
*/
|
167
174
|
TinyColor.prototype.toHex8 = function (allow4Char) {
|
168
175
|
if (allow4Char === void 0) { allow4Char = false; }
|
169
|
-
return conversion_1.rgbaToHex(this.r, this.g, this.b, this.a, allow4Char);
|
176
|
+
return (0, conversion_1.rgbaToHex)(this.r, this.g, this.b, this.a, allow4Char);
|
170
177
|
};
|
171
178
|
/**
|
172
179
|
* Returns the hex 8 value of the color -with a # appened.
|
@@ -195,13 +202,13 @@ var TinyColor = /** @class */ (function () {
|
|
195
202
|
var r = Math.round(this.r);
|
196
203
|
var g = Math.round(this.g);
|
197
204
|
var b = Math.round(this.b);
|
198
|
-
return this.a === 1 ? "rgb("
|
205
|
+
return this.a === 1 ? "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")") : "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(this.roundA, ")");
|
199
206
|
};
|
200
207
|
/**
|
201
208
|
* Returns the object as a RGBA object.
|
202
209
|
*/
|
203
210
|
TinyColor.prototype.toPercentageRgb = function () {
|
204
|
-
var fmt = function (x) { return Math.round(util_1.bound01(x, 255) * 100)
|
211
|
+
var fmt = function (x) { return "".concat(Math.round((0, util_1.bound01)(x, 255) * 100), "%"); };
|
205
212
|
return {
|
206
213
|
r: fmt(this.r),
|
207
214
|
g: fmt(this.g),
|
@@ -213,10 +220,10 @@ var TinyColor = /** @class */ (function () {
|
|
213
220
|
* Returns the RGBA relative values interpolated into a string
|
214
221
|
*/
|
215
222
|
TinyColor.prototype.toPercentageRgbString = function () {
|
216
|
-
var rnd = function (x) { return Math.round(util_1.bound01(x, 255) * 100); };
|
223
|
+
var rnd = function (x) { return Math.round((0, util_1.bound01)(x, 255) * 100); };
|
217
224
|
return this.a === 1
|
218
|
-
? "rgb("
|
219
|
-
: "rgba("
|
225
|
+
? "rgb(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%)")
|
226
|
+
: "rgba(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%, ").concat(this.roundA, ")");
|
220
227
|
};
|
221
228
|
/**
|
222
229
|
* The 'real' name of the color -if there is one.
|
@@ -228,7 +235,7 @@ var TinyColor = /** @class */ (function () {
|
|
228
235
|
if (this.a < 1) {
|
229
236
|
return false;
|
230
237
|
}
|
231
|
-
var hex = '#' + conversion_1.rgbToHex(this.r, this.g, this.b, false);
|
238
|
+
var hex = '#' + (0, conversion_1.rgbToHex)(this.r, this.g, this.b, false);
|
232
239
|
for (var _i = 0, _a = Object.entries(css_color_names_1.names); _i < _a.length; _i++) {
|
233
240
|
var _b = _a[_i], key = _b[0], value = _b[1];
|
234
241
|
if (hex === value) {
|
@@ -294,7 +301,7 @@ var TinyColor = /** @class */ (function () {
|
|
294
301
|
if (amount === void 0) { amount = 10; }
|
295
302
|
var hsl = this.toHsl();
|
296
303
|
hsl.l += amount / 100;
|
297
|
-
hsl.l = util_1.clamp01(hsl.l);
|
304
|
+
hsl.l = (0, util_1.clamp01)(hsl.l);
|
298
305
|
return new TinyColor(hsl);
|
299
306
|
};
|
300
307
|
/**
|
@@ -318,7 +325,7 @@ var TinyColor = /** @class */ (function () {
|
|
318
325
|
if (amount === void 0) { amount = 10; }
|
319
326
|
var hsl = this.toHsl();
|
320
327
|
hsl.l -= amount / 100;
|
321
|
-
hsl.l = util_1.clamp01(hsl.l);
|
328
|
+
hsl.l = (0, util_1.clamp01)(hsl.l);
|
322
329
|
return new TinyColor(hsl);
|
323
330
|
};
|
324
331
|
/**
|
@@ -348,7 +355,7 @@ var TinyColor = /** @class */ (function () {
|
|
348
355
|
if (amount === void 0) { amount = 10; }
|
349
356
|
var hsl = this.toHsl();
|
350
357
|
hsl.s -= amount / 100;
|
351
|
-
hsl.s = util_1.clamp01(hsl.s);
|
358
|
+
hsl.s = (0, util_1.clamp01)(hsl.s);
|
352
359
|
return new TinyColor(hsl);
|
353
360
|
};
|
354
361
|
/**
|
@@ -359,7 +366,7 @@ var TinyColor = /** @class */ (function () {
|
|
359
366
|
if (amount === void 0) { amount = 10; }
|
360
367
|
var hsl = this.toHsl();
|
361
368
|
hsl.s += amount / 100;
|
362
|
-
hsl.s = util_1.clamp01(hsl.s);
|
369
|
+
hsl.s = (0, util_1.clamp01)(hsl.s);
|
363
370
|
return new TinyColor(hsl);
|
364
371
|
};
|
365
372
|
/**
|
package/dist/interfaces.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
1
2
|
import { convertHexToDecimal, hslToRgb, hsvToRgb, parseIntFromHex, rgbToRgb } from './conversion';
|
2
3
|
import { names } from './css-color-names';
|
3
4
|
import { boundAlpha, convertToPercentage } from './util';
|
@@ -69,12 +70,12 @@ var CSS_INTEGER = '[-\\+]?\\d+%?';
|
|
69
70
|
// <http://www.w3.org/TR/css3-values/#number-value>
|
70
71
|
var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
|
71
72
|
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
|
72
|
-
var CSS_UNIT = "(?:"
|
73
|
+
var CSS_UNIT = "(?:".concat(CSS_NUMBER, ")|(?:").concat(CSS_INTEGER, ")");
|
73
74
|
// Actual matching.
|
74
75
|
// Parentheses and commas are optional, but not required.
|
75
76
|
// Whitespace can take the place of commas or opening paren
|
76
|
-
var PERMISSIVE_MATCH3 = "[\\s|\\(]+("
|
77
|
-
var PERMISSIVE_MATCH4 = "[\\s|\\(]+("
|
77
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(".concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")\\s*\\)?");
|
78
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(".concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")\\s*\\)?");
|
78
79
|
var matchers = {
|
79
80
|
CSS_UNIT: new RegExp(CSS_UNIT),
|
80
81
|
rgb: new RegExp('rgb' + PERMISSIVE_MATCH3),
|
package/dist/module/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { rgbaToHex, rgbToHex, rgbToHsl, rgbToHsv
|
1
|
+
import { numberInputToObject, rgbaToHex, rgbToHex, rgbToHsl, rgbToHsv } from './conversion';
|
2
2
|
import { names } from './css-color-names';
|
3
3
|
import { inputToRGB } from './format-input';
|
4
4
|
import { bound01, boundAlpha, clamp01 } from './util';
|
@@ -105,6 +105,13 @@ var TinyColor = /** @class */ (function () {
|
|
105
105
|
this.roundA = Math.round(100 * this.a) / 100;
|
106
106
|
return this;
|
107
107
|
};
|
108
|
+
/**
|
109
|
+
* Returns whether the color is monochrome.
|
110
|
+
*/
|
111
|
+
TinyColor.prototype.isMonochrome = function () {
|
112
|
+
var s = this.toHsl().s;
|
113
|
+
return s === 0;
|
114
|
+
};
|
108
115
|
/**
|
109
116
|
* Returns the object as a HSVA object.
|
110
117
|
*/
|
@@ -121,7 +128,7 @@ var TinyColor = /** @class */ (function () {
|
|
121
128
|
var h = Math.round(hsv.h * 360);
|
122
129
|
var s = Math.round(hsv.s * 100);
|
123
130
|
var v = Math.round(hsv.v * 100);
|
124
|
-
return this.a === 1 ? "hsv("
|
131
|
+
return this.a === 1 ? "hsv(".concat(h, ", ").concat(s, "%, ").concat(v, "%)") : "hsva(".concat(h, ", ").concat(s, "%, ").concat(v, "%, ").concat(this.roundA, ")");
|
125
132
|
};
|
126
133
|
/**
|
127
134
|
* Returns the object as a HSLA object.
|
@@ -139,7 +146,7 @@ var TinyColor = /** @class */ (function () {
|
|
139
146
|
var h = Math.round(hsl.h * 360);
|
140
147
|
var s = Math.round(hsl.s * 100);
|
141
148
|
var l = Math.round(hsl.l * 100);
|
142
|
-
return this.a === 1 ? "hsl("
|
149
|
+
return this.a === 1 ? "hsl(".concat(h, ", ").concat(s, "%, ").concat(l, "%)") : "hsla(".concat(h, ", ").concat(s, "%, ").concat(l, "%, ").concat(this.roundA, ")");
|
143
150
|
};
|
144
151
|
/**
|
145
152
|
* Returns the hex value of the color.
|
@@ -192,13 +199,13 @@ var TinyColor = /** @class */ (function () {
|
|
192
199
|
var r = Math.round(this.r);
|
193
200
|
var g = Math.round(this.g);
|
194
201
|
var b = Math.round(this.b);
|
195
|
-
return this.a === 1 ? "rgb("
|
202
|
+
return this.a === 1 ? "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")") : "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(this.roundA, ")");
|
196
203
|
};
|
197
204
|
/**
|
198
205
|
* Returns the object as a RGBA object.
|
199
206
|
*/
|
200
207
|
TinyColor.prototype.toPercentageRgb = function () {
|
201
|
-
var fmt = function (x) { return Math.round(bound01(x, 255) * 100)
|
208
|
+
var fmt = function (x) { return "".concat(Math.round(bound01(x, 255) * 100), "%"); };
|
202
209
|
return {
|
203
210
|
r: fmt(this.r),
|
204
211
|
g: fmt(this.g),
|
@@ -212,8 +219,8 @@ var TinyColor = /** @class */ (function () {
|
|
212
219
|
TinyColor.prototype.toPercentageRgbString = function () {
|
213
220
|
var rnd = function (x) { return Math.round(bound01(x, 255) * 100); };
|
214
221
|
return this.a === 1
|
215
|
-
? "rgb("
|
216
|
-
: "rgba("
|
222
|
+
? "rgb(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%)")
|
223
|
+
: "rgba(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%, ").concat(this.roundA, ")");
|
217
224
|
};
|
218
225
|
/**
|
219
226
|
* The 'real' name of the color -if there is one.
|
package/dist/module/random.js
CHANGED
@@ -12,5 +12,5 @@ export function toMsFilter(firstColor, secondColor) {
|
|
12
12
|
var s = new TinyColor(secondColor);
|
13
13
|
secondHex8String = '#' + rgbaToArgbHex(s.r, s.g, s.b, s.a);
|
14
14
|
}
|
15
|
-
return "progid:DXImageTransform.Microsoft.gradient("
|
15
|
+
return "progid:DXImageTransform.Microsoft.gradient(".concat(gradientType, "startColorstr=").concat(hex8String, ",endColorstr=").concat(secondHex8String, ")");
|
16
16
|
}
|
package/dist/module/umd_api.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/member-ordering */
|
2
1
|
import { names } from './css-color-names';
|
3
2
|
import { inputToRGB, isValidCSSUnit, stringInputToObject } from './format-input';
|
4
3
|
import { fromRatio, legacyRandom } from './from-ratio';
|
5
|
-
import {
|
4
|
+
import { TinyColor, tinycolor } from './index';
|
6
5
|
import { random } from './random';
|
7
6
|
import { mostReadable, readability } from './readability';
|
8
7
|
import { toMsFilter } from './to-ms-filter';
|
package/dist/module/util.js
CHANGED
package/dist/public_api.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|
package/dist/random.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.bounds = exports.random = void 0;
|
4
|
+
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
4
5
|
// randomColor by David Merfield under the CC0 license
|
5
6
|
// https://github.com/davidmerfield/randomColor/
|
6
7
|
var index_1 = require("./index");
|
package/dist/to-ms-filter.js
CHANGED
@@ -8,13 +8,13 @@ var index_1 = require("./index");
|
|
8
8
|
*/
|
9
9
|
function toMsFilter(firstColor, secondColor) {
|
10
10
|
var color = new index_1.TinyColor(firstColor);
|
11
|
-
var hex8String = '#' + conversion_1.rgbaToArgbHex(color.r, color.g, color.b, color.a);
|
11
|
+
var hex8String = '#' + (0, conversion_1.rgbaToArgbHex)(color.r, color.g, color.b, color.a);
|
12
12
|
var secondHex8String = hex8String;
|
13
13
|
var gradientType = color.gradientType ? 'GradientType = 1, ' : '';
|
14
14
|
if (secondColor) {
|
15
15
|
var s = new index_1.TinyColor(secondColor);
|
16
|
-
secondHex8String = '#' + conversion_1.rgbaToArgbHex(s.r, s.g, s.b, s.a);
|
16
|
+
secondHex8String = '#' + (0, conversion_1.rgbaToArgbHex)(s.r, s.g, s.b, s.a);
|
17
17
|
}
|
18
|
-
return "progid:DXImageTransform.Microsoft.gradient("
|
18
|
+
return "progid:DXImageTransform.Microsoft.gradient(".concat(gradientType, "startColorstr=").concat(hex8String, ",endColorstr=").concat(secondHex8String, ")");
|
19
19
|
}
|
20
20
|
exports.toMsFilter = toMsFilter;
|
package/dist/umd_api.js
CHANGED