@ctrl/tinycolor 3.6.1 → 4.0.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.js +32 -32
- package/dist/format-input.js +20 -21
- package/dist/from-ratio.js +3 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +164 -192
- package/dist/module/conversion.js +31 -31
- package/dist/module/css-color-names.js +1 -1
- package/dist/module/format-input.js +17 -18
- package/dist/module/from-ratio.js +1 -1
- package/dist/module/index.js +158 -186
- package/dist/module/public_api.js +0 -3
- package/dist/module/random.js +37 -40
- package/dist/module/readability.js +12 -16
- package/dist/module/to-ms-filter.js +6 -6
- package/dist/module/umd_api.js +14 -13
- package/dist/module/util.js +3 -3
- package/dist/public_api.d.ts +0 -2
- package/dist/public_api.js +0 -3
- package/dist/random.js +37 -40
- package/dist/readability.js +13 -17
- package/dist/to-ms-filter.js +8 -8
- package/dist/umd_api.d.ts +0 -1
- package/dist/umd_api.js +20 -19
- package/dist/util.js +3 -3
- package/package.json +19 -39
package/dist/conversion.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.numberInputToObject = exports.parseIntFromHex = exports.convertHexToDecimal = exports.convertDecimalToHex = exports.rgbaToArgbHex = exports.rgbaToHex = exports.rgbToHex = exports.hsvToRgb = exports.rgbToHsv = exports.hslToRgb = exports.rgbToHsl = exports.rgbToRgb = void 0;
|
4
|
-
|
4
|
+
const util_js_1 = require("./util.js");
|
5
5
|
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
|
6
6
|
// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
|
7
7
|
/**
|
@@ -27,17 +27,17 @@ function rgbToHsl(r, g, b) {
|
|
27
27
|
r = (0, util_js_1.bound01)(r, 255);
|
28
28
|
g = (0, util_js_1.bound01)(g, 255);
|
29
29
|
b = (0, util_js_1.bound01)(b, 255);
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
const max = Math.max(r, g, b);
|
31
|
+
const min = Math.min(r, g, b);
|
32
|
+
let h = 0;
|
33
|
+
let s = 0;
|
34
|
+
const l = (max + min) / 2;
|
35
35
|
if (max === min) {
|
36
36
|
s = 0;
|
37
37
|
h = 0; // achromatic
|
38
38
|
}
|
39
39
|
else {
|
40
|
-
|
40
|
+
const d = max - min;
|
41
41
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
42
42
|
switch (max) {
|
43
43
|
case r:
|
@@ -54,7 +54,7 @@ function rgbToHsl(r, g, b) {
|
|
54
54
|
}
|
55
55
|
h /= 6;
|
56
56
|
}
|
57
|
-
return { h
|
57
|
+
return { h, s, l };
|
58
58
|
}
|
59
59
|
exports.rgbToHsl = rgbToHsl;
|
60
60
|
function hue2rgb(p, q, t) {
|
@@ -82,9 +82,9 @@ function hue2rgb(p, q, t) {
|
|
82
82
|
* *Returns:* { r, g, b } in the set [0, 255]
|
83
83
|
*/
|
84
84
|
function hslToRgb(h, s, l) {
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
let r;
|
86
|
+
let g;
|
87
|
+
let b;
|
88
88
|
h = (0, util_js_1.bound01)(h, 360);
|
89
89
|
s = (0, util_js_1.bound01)(s, 100);
|
90
90
|
l = (0, util_js_1.bound01)(l, 100);
|
@@ -95,8 +95,8 @@ function hslToRgb(h, s, l) {
|
|
95
95
|
r = l;
|
96
96
|
}
|
97
97
|
else {
|
98
|
-
|
99
|
-
|
98
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
99
|
+
const p = 2 * l - q;
|
100
100
|
r = hue2rgb(p, q, h + 1 / 3);
|
101
101
|
g = hue2rgb(p, q, h);
|
102
102
|
b = hue2rgb(p, q, h - 1 / 3);
|
@@ -114,12 +114,12 @@ function rgbToHsv(r, g, b) {
|
|
114
114
|
r = (0, util_js_1.bound01)(r, 255);
|
115
115
|
g = (0, util_js_1.bound01)(g, 255);
|
116
116
|
b = (0, util_js_1.bound01)(b, 255);
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
117
|
+
const max = Math.max(r, g, b);
|
118
|
+
const min = Math.min(r, g, b);
|
119
|
+
let h = 0;
|
120
|
+
const v = max;
|
121
|
+
const d = max - min;
|
122
|
+
const s = max === 0 ? 0 : d / max;
|
123
123
|
if (max === min) {
|
124
124
|
h = 0; // achromatic
|
125
125
|
}
|
@@ -139,7 +139,7 @@ function rgbToHsv(r, g, b) {
|
|
139
139
|
}
|
140
140
|
h /= 6;
|
141
141
|
}
|
142
|
-
return { h
|
142
|
+
return { h, s, v };
|
143
143
|
}
|
144
144
|
exports.rgbToHsv = rgbToHsv;
|
145
145
|
/**
|
@@ -152,15 +152,15 @@ function hsvToRgb(h, s, v) {
|
|
152
152
|
h = (0, util_js_1.bound01)(h, 360) * 6;
|
153
153
|
s = (0, util_js_1.bound01)(s, 100);
|
154
154
|
v = (0, util_js_1.bound01)(v, 100);
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
155
|
+
const i = Math.floor(h);
|
156
|
+
const f = h - i;
|
157
|
+
const p = v * (1 - s);
|
158
|
+
const q = v * (1 - f * s);
|
159
|
+
const t = v * (1 - (1 - f) * s);
|
160
|
+
const mod = i % 6;
|
161
|
+
const r = [v, q, p, p, t, v][mod];
|
162
|
+
const g = [t, v, v, q, p, p][mod];
|
163
|
+
const b = [p, p, t, v, v, q][mod];
|
164
164
|
return { r: r * 255, g: g * 255, b: b * 255 };
|
165
165
|
}
|
166
166
|
exports.hsvToRgb = hsvToRgb;
|
@@ -171,7 +171,7 @@ exports.hsvToRgb = hsvToRgb;
|
|
171
171
|
* Returns a 3 or 6 character hex
|
172
172
|
*/
|
173
173
|
function rgbToHex(r, g, b, allow3Char) {
|
174
|
-
|
174
|
+
const hex = [
|
175
175
|
(0, util_js_1.pad2)(Math.round(r).toString(16)),
|
176
176
|
(0, util_js_1.pad2)(Math.round(g).toString(16)),
|
177
177
|
(0, util_js_1.pad2)(Math.round(b).toString(16)),
|
@@ -194,7 +194,7 @@ exports.rgbToHex = rgbToHex;
|
|
194
194
|
*/
|
195
195
|
// eslint-disable-next-line max-params
|
196
196
|
function rgbaToHex(r, g, b, a, allow4Char) {
|
197
|
-
|
197
|
+
const hex = [
|
198
198
|
(0, util_js_1.pad2)(Math.round(r).toString(16)),
|
199
199
|
(0, util_js_1.pad2)(Math.round(g).toString(16)),
|
200
200
|
(0, util_js_1.pad2)(Math.round(b).toString(16)),
|
@@ -216,7 +216,7 @@ exports.rgbaToHex = rgbaToHex;
|
|
216
216
|
* Rarely used, but required for "toFilter()"
|
217
217
|
*/
|
218
218
|
function rgbaToArgbHex(r, g, b, a) {
|
219
|
-
|
219
|
+
const hex = [
|
220
220
|
(0, util_js_1.pad2)(convertDecimalToHex(a)),
|
221
221
|
(0, util_js_1.pad2)(Math.round(r).toString(16)),
|
222
222
|
(0, util_js_1.pad2)(Math.round(g).toString(16)),
|
package/dist/format-input.js
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.isValidCSSUnit = exports.stringInputToObject = exports.inputToRGB = void 0;
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
var util_js_1 = require("./util.js");
|
4
|
+
const conversion_js_1 = require("./conversion.js");
|
5
|
+
const css_color_names_js_1 = require("./css-color-names.js");
|
6
|
+
const util_js_1 = require("./util.js");
|
8
7
|
/**
|
9
8
|
* Given a string or object, convert that input to RGB
|
10
9
|
*
|
@@ -24,13 +23,13 @@ var util_js_1 = require("./util.js");
|
|
24
23
|
* ```
|
25
24
|
*/
|
26
25
|
function inputToRGB(color) {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
let rgb = { r: 0, g: 0, b: 0 };
|
27
|
+
let a = 1;
|
28
|
+
let s = null;
|
29
|
+
let v = null;
|
30
|
+
let l = null;
|
31
|
+
let ok = false;
|
32
|
+
let format = false;
|
34
33
|
if (typeof color === 'string') {
|
35
34
|
color = stringInputToObject(color);
|
36
35
|
}
|
@@ -60,27 +59,27 @@ function inputToRGB(color) {
|
|
60
59
|
}
|
61
60
|
a = (0, util_js_1.boundAlpha)(a);
|
62
61
|
return {
|
63
|
-
ok
|
62
|
+
ok,
|
64
63
|
format: color.format || format,
|
65
64
|
r: Math.min(255, Math.max(rgb.r, 0)),
|
66
65
|
g: Math.min(255, Math.max(rgb.g, 0)),
|
67
66
|
b: Math.min(255, Math.max(rgb.b, 0)),
|
68
|
-
a
|
67
|
+
a,
|
69
68
|
};
|
70
69
|
}
|
71
70
|
exports.inputToRGB = inputToRGB;
|
72
71
|
// <http://www.w3.org/TR/css3-values/#integers>
|
73
|
-
|
72
|
+
const CSS_INTEGER = '[-\\+]?\\d+%?';
|
74
73
|
// <http://www.w3.org/TR/css3-values/#number-value>
|
75
|
-
|
74
|
+
const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
|
76
75
|
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
|
77
|
-
|
76
|
+
const CSS_UNIT = `(?:${CSS_NUMBER})|(?:${CSS_INTEGER})`;
|
78
77
|
// Actual matching.
|
79
78
|
// Parentheses and commas are optional, but not required.
|
80
79
|
// Whitespace can take the place of commas or opening paren
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
const PERMISSIVE_MATCH3 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`;
|
81
|
+
const PERMISSIVE_MATCH4 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`;
|
82
|
+
const matchers = {
|
84
83
|
CSS_UNIT: new RegExp(CSS_UNIT),
|
85
84
|
rgb: new RegExp('rgb' + PERMISSIVE_MATCH3),
|
86
85
|
rgba: new RegExp('rgba' + PERMISSIVE_MATCH4),
|
@@ -102,7 +101,7 @@ function stringInputToObject(color) {
|
|
102
101
|
if (color.length === 0) {
|
103
102
|
return false;
|
104
103
|
}
|
105
|
-
|
104
|
+
let named = false;
|
106
105
|
if (css_color_names_js_1.names[color]) {
|
107
106
|
color = css_color_names_js_1.names[color];
|
108
107
|
named = true;
|
@@ -114,7 +113,7 @@ function stringInputToObject(color) {
|
|
114
113
|
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
|
115
114
|
// Just return an object and let the conversion functions handle that.
|
116
115
|
// This way the result will be the same whether the tinycolor is initialized with string or object.
|
117
|
-
|
116
|
+
let match = matchers.rgb.exec(color);
|
118
117
|
if (match) {
|
119
118
|
return { r: match[1], g: match[2], b: match[3] };
|
120
119
|
}
|
package/dist/from-ratio.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.legacyRandom = exports.fromRatio = void 0;
|
4
|
-
|
5
|
-
|
4
|
+
const index_js_1 = require("./index.js");
|
5
|
+
const util_js_1 = require("./util.js");
|
6
6
|
/**
|
7
7
|
* If input is an object, force 1 into "1.0" to handle ratios properly
|
8
8
|
* String input requires "1.0" as input, so 1 will be treated as 1
|
9
9
|
*/
|
10
10
|
function fromRatio(ratio, opts) {
|
11
|
-
|
11
|
+
const newColor = {
|
12
12
|
r: (0, util_js_1.convertToPercentage)(ratio.r),
|
13
13
|
g: (0, util_js_1.convertToPercentage)(ratio.g),
|
14
14
|
b: (0, util_js_1.convertToPercentage)(ratio.b),
|
package/dist/index.d.ts
CHANGED