@ctrl/tinycolor 3.5.1 → 3.6.1
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 +12 -0
- 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 +27 -27
- package/dist/format-input.d.ts +1 -1
- package/dist/format-input.js +27 -27
- package/dist/from-ratio.d.ts +1 -1
- package/dist/from-ratio.js +7 -7
- package/dist/index.d.ts +8 -3
- package/dist/index.js +29 -21
- package/dist/module/conversion.js +1 -1
- package/dist/module/format-input.js +3 -3
- package/dist/module/from-ratio.js +2 -2
- package/dist/module/index.js +13 -5
- package/dist/module/public_api.js +10 -10
- package/dist/module/random.js +1 -1
- package/dist/module/readability.js +1 -1
- package/dist/module/to-ms-filter.js +2 -2
- package/dist/module/umd_api.js +7 -7
- package/dist/public_api.d.ts +10 -10
- package/dist/public_api.js +11 -11
- package/dist/random.d.ts +1 -1
- package/dist/random.js +3 -3
- package/dist/readability.d.ts +1 -1
- package/dist/readability.js +4 -4
- package/dist/to-ms-filter.d.ts +1 -1
- package/dist/to-ms-filter.js +6 -6
- package/dist/umd_api.d.ts +7 -7
- package/dist/umd_api.js +19 -19
- package/package.json +5 -2
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
|
-
var
|
4
|
+
var 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
|
/**
|
@@ -12,9 +12,9 @@ var util_1 = require("./util");
|
|
12
12
|
*/
|
13
13
|
function rgbToRgb(r, g, b) {
|
14
14
|
return {
|
15
|
-
r: (0,
|
16
|
-
g: (0,
|
17
|
-
b: (0,
|
15
|
+
r: (0, util_js_1.bound01)(r, 255) * 255,
|
16
|
+
g: (0, util_js_1.bound01)(g, 255) * 255,
|
17
|
+
b: (0, util_js_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 = (0,
|
28
|
-
g = (0,
|
29
|
-
b = (0,
|
27
|
+
r = (0, util_js_1.bound01)(r, 255);
|
28
|
+
g = (0, util_js_1.bound01)(g, 255);
|
29
|
+
b = (0, util_js_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 = (0,
|
89
|
-
s = (0,
|
90
|
-
l = (0,
|
88
|
+
h = (0, util_js_1.bound01)(h, 360);
|
89
|
+
s = (0, util_js_1.bound01)(s, 100);
|
90
|
+
l = (0, util_js_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 = (0,
|
115
|
-
g = (0,
|
116
|
-
b = (0,
|
114
|
+
r = (0, util_js_1.bound01)(r, 255);
|
115
|
+
g = (0, util_js_1.bound01)(g, 255);
|
116
|
+
b = (0, util_js_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 = (0,
|
153
|
-
s = (0,
|
154
|
-
v = (0,
|
152
|
+
h = (0, util_js_1.bound01)(h, 360) * 6;
|
153
|
+
s = (0, util_js_1.bound01)(s, 100);
|
154
|
+
v = (0, util_js_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
|
-
(0,
|
176
|
-
(0,
|
177
|
-
(0,
|
175
|
+
(0, util_js_1.pad2)(Math.round(r).toString(16)),
|
176
|
+
(0, util_js_1.pad2)(Math.round(g).toString(16)),
|
177
|
+
(0, util_js_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
|
-
(0,
|
199
|
-
(0,
|
200
|
-
(0,
|
201
|
-
(0,
|
198
|
+
(0, util_js_1.pad2)(Math.round(r).toString(16)),
|
199
|
+
(0, util_js_1.pad2)(Math.round(g).toString(16)),
|
200
|
+
(0, util_js_1.pad2)(Math.round(b).toString(16)),
|
201
|
+
(0, util_js_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
|
-
(0,
|
221
|
-
(0,
|
222
|
-
(0,
|
223
|
-
(0,
|
220
|
+
(0, util_js_1.pad2)(convertDecimalToHex(a)),
|
221
|
+
(0, util_js_1.pad2)(Math.round(r).toString(16)),
|
222
|
+
(0, util_js_1.pad2)(Math.round(g).toString(16)),
|
223
|
+
(0, util_js_1.pad2)(Math.round(b).toString(16)),
|
224
224
|
];
|
225
225
|
return hex.join('');
|
226
226
|
}
|
package/dist/format-input.d.ts
CHANGED
package/dist/format-input.js
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.isValidCSSUnit = exports.stringInputToObject = exports.inputToRGB = void 0;
|
4
4
|
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
5
|
-
var
|
6
|
-
var
|
7
|
-
var
|
5
|
+
var conversion_js_1 = require("./conversion.js");
|
6
|
+
var css_color_names_js_1 = require("./css-color-names.js");
|
7
|
+
var util_js_1 = require("./util.js");
|
8
8
|
/**
|
9
9
|
* Given a string or object, convert that input to RGB
|
10
10
|
*
|
@@ -36,21 +36,21 @@ function inputToRGB(color) {
|
|
36
36
|
}
|
37
37
|
if (typeof color === 'object') {
|
38
38
|
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
39
|
-
rgb = (0,
|
39
|
+
rgb = (0, conversion_js_1.rgbToRgb)(color.r, color.g, color.b);
|
40
40
|
ok = true;
|
41
41
|
format = String(color.r).substr(-1) === '%' ? 'prgb' : 'rgb';
|
42
42
|
}
|
43
43
|
else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
44
|
-
s = (0,
|
45
|
-
v = (0,
|
46
|
-
rgb = (0,
|
44
|
+
s = (0, util_js_1.convertToPercentage)(color.s);
|
45
|
+
v = (0, util_js_1.convertToPercentage)(color.v);
|
46
|
+
rgb = (0, conversion_js_1.hsvToRgb)(color.h, s, v);
|
47
47
|
ok = true;
|
48
48
|
format = 'hsv';
|
49
49
|
}
|
50
50
|
else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
51
|
-
s = (0,
|
52
|
-
l = (0,
|
53
|
-
rgb = (0,
|
51
|
+
s = (0, util_js_1.convertToPercentage)(color.s);
|
52
|
+
l = (0, util_js_1.convertToPercentage)(color.l);
|
53
|
+
rgb = (0, conversion_js_1.hslToRgb)(color.h, s, l);
|
54
54
|
ok = true;
|
55
55
|
format = 'hsl';
|
56
56
|
}
|
@@ -58,7 +58,7 @@ function inputToRGB(color) {
|
|
58
58
|
a = color.a;
|
59
59
|
}
|
60
60
|
}
|
61
|
-
a = (0,
|
61
|
+
a = (0, util_js_1.boundAlpha)(a);
|
62
62
|
return {
|
63
63
|
ok: ok,
|
64
64
|
format: color.format || format,
|
@@ -103,8 +103,8 @@ function stringInputToObject(color) {
|
|
103
103
|
return false;
|
104
104
|
}
|
105
105
|
var named = false;
|
106
|
-
if (
|
107
|
-
color =
|
106
|
+
if (css_color_names_js_1.names[color]) {
|
107
|
+
color = css_color_names_js_1.names[color];
|
108
108
|
named = true;
|
109
109
|
}
|
110
110
|
else if (color === 'transparent') {
|
@@ -141,38 +141,38 @@ function stringInputToObject(color) {
|
|
141
141
|
match = matchers.hex8.exec(color);
|
142
142
|
if (match) {
|
143
143
|
return {
|
144
|
-
r: (0,
|
145
|
-
g: (0,
|
146
|
-
b: (0,
|
147
|
-
a: (0,
|
144
|
+
r: (0, conversion_js_1.parseIntFromHex)(match[1]),
|
145
|
+
g: (0, conversion_js_1.parseIntFromHex)(match[2]),
|
146
|
+
b: (0, conversion_js_1.parseIntFromHex)(match[3]),
|
147
|
+
a: (0, conversion_js_1.convertHexToDecimal)(match[4]),
|
148
148
|
format: named ? 'name' : 'hex8',
|
149
149
|
};
|
150
150
|
}
|
151
151
|
match = matchers.hex6.exec(color);
|
152
152
|
if (match) {
|
153
153
|
return {
|
154
|
-
r: (0,
|
155
|
-
g: (0,
|
156
|
-
b: (0,
|
154
|
+
r: (0, conversion_js_1.parseIntFromHex)(match[1]),
|
155
|
+
g: (0, conversion_js_1.parseIntFromHex)(match[2]),
|
156
|
+
b: (0, conversion_js_1.parseIntFromHex)(match[3]),
|
157
157
|
format: named ? 'name' : 'hex',
|
158
158
|
};
|
159
159
|
}
|
160
160
|
match = matchers.hex4.exec(color);
|
161
161
|
if (match) {
|
162
162
|
return {
|
163
|
-
r: (0,
|
164
|
-
g: (0,
|
165
|
-
b: (0,
|
166
|
-
a: (0,
|
163
|
+
r: (0, conversion_js_1.parseIntFromHex)(match[1] + match[1]),
|
164
|
+
g: (0, conversion_js_1.parseIntFromHex)(match[2] + match[2]),
|
165
|
+
b: (0, conversion_js_1.parseIntFromHex)(match[3] + match[3]),
|
166
|
+
a: (0, conversion_js_1.convertHexToDecimal)(match[4] + match[4]),
|
167
167
|
format: named ? 'name' : 'hex8',
|
168
168
|
};
|
169
169
|
}
|
170
170
|
match = matchers.hex3.exec(color);
|
171
171
|
if (match) {
|
172
172
|
return {
|
173
|
-
r: (0,
|
174
|
-
g: (0,
|
175
|
-
b: (0,
|
173
|
+
r: (0, conversion_js_1.parseIntFromHex)(match[1] + match[1]),
|
174
|
+
g: (0, conversion_js_1.parseIntFromHex)(match[2] + match[2]),
|
175
|
+
b: (0, conversion_js_1.parseIntFromHex)(match[3] + match[3]),
|
176
176
|
format: named ? 'name' : 'hex',
|
177
177
|
};
|
178
178
|
}
|
package/dist/from-ratio.d.ts
CHANGED
package/dist/from-ratio.js
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.legacyRandom = exports.fromRatio = void 0;
|
4
|
-
var
|
5
|
-
var
|
4
|
+
var index_js_1 = require("./index.js");
|
5
|
+
var 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
|
var newColor = {
|
12
|
-
r: (0,
|
13
|
-
g: (0,
|
14
|
-
b: (0,
|
12
|
+
r: (0, util_js_1.convertToPercentage)(ratio.r),
|
13
|
+
g: (0, util_js_1.convertToPercentage)(ratio.g),
|
14
|
+
b: (0, util_js_1.convertToPercentage)(ratio.b),
|
15
15
|
};
|
16
16
|
if (ratio.a !== undefined) {
|
17
17
|
newColor.a = Number(ratio.a);
|
18
18
|
}
|
19
|
-
return new
|
19
|
+
return new index_js_1.TinyColor(newColor, opts);
|
20
20
|
}
|
21
21
|
exports.fromRatio = fromRatio;
|
22
22
|
/** old random function */
|
23
23
|
function legacyRandom() {
|
24
|
-
return new
|
24
|
+
return new index_js_1.TinyColor({
|
25
25
|
r: Math.random(),
|
26
26
|
g: Math.random(),
|
27
27
|
b: Math.random(),
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces';
|
1
|
+
import { HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces.js';
|
2
2
|
export interface TinyColorOptions {
|
3
3
|
format: string;
|
4
4
|
gradientType: string;
|
@@ -72,7 +72,7 @@ export declare class TinyColor {
|
|
72
72
|
*/
|
73
73
|
toHex(allow3Char?: boolean): string;
|
74
74
|
/**
|
75
|
-
* Returns the hex value of the color -with a #
|
75
|
+
* Returns the hex value of the color -with a # prefixed.
|
76
76
|
* @param allow3Char will shorten hex value to 3 char if possible
|
77
77
|
*/
|
78
78
|
toHexString(allow3Char?: boolean): string;
|
@@ -82,10 +82,15 @@ export declare class TinyColor {
|
|
82
82
|
*/
|
83
83
|
toHex8(allow4Char?: boolean): string;
|
84
84
|
/**
|
85
|
-
* Returns the hex 8 value of the color -with a #
|
85
|
+
* Returns the hex 8 value of the color -with a # prefixed.
|
86
86
|
* @param allow4Char will shorten hex value to 4 char if possible
|
87
87
|
*/
|
88
88
|
toHex8String(allow4Char?: boolean): string;
|
89
|
+
/**
|
90
|
+
* Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
|
91
|
+
* @param allowShortChar will shorten hex value to 3 or 4 char if possible
|
92
|
+
*/
|
93
|
+
toHexShortString(allowShortChar?: boolean): string;
|
89
94
|
/**
|
90
95
|
* Returns the object as a RGBA object.
|
91
96
|
*/
|
package/dist/index.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.tinycolor = exports.TinyColor = void 0;
|
4
|
-
var
|
5
|
-
var
|
4
|
+
var conversion_js_1 = require("./conversion.js");
|
5
|
+
var css_color_names_js_1 = require("./css-color-names.js");
|
6
6
|
var format_input_1 = require("./format-input");
|
7
|
-
var
|
7
|
+
var util_js_1 = require("./util.js");
|
8
8
|
var TinyColor = /** @class */ (function () {
|
9
9
|
function TinyColor(color, opts) {
|
10
10
|
if (color === void 0) { color = ''; }
|
@@ -16,7 +16,7 @@ var TinyColor = /** @class */ (function () {
|
|
16
16
|
return color;
|
17
17
|
}
|
18
18
|
if (typeof color === 'number') {
|
19
|
-
color = (0,
|
19
|
+
color = (0, conversion_js_1.numberInputToObject)(color);
|
20
20
|
}
|
21
21
|
this.originalInput = color;
|
22
22
|
var rgb = (0, format_input_1.inputToRGB)(color);
|
@@ -104,7 +104,7 @@ 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 = (0,
|
107
|
+
this.a = (0, util_js_1.boundAlpha)(alpha);
|
108
108
|
this.roundA = Math.round(100 * this.a) / 100;
|
109
109
|
return this;
|
110
110
|
};
|
@@ -119,7 +119,7 @@ var TinyColor = /** @class */ (function () {
|
|
119
119
|
* Returns the object as a HSVA object.
|
120
120
|
*/
|
121
121
|
TinyColor.prototype.toHsv = function () {
|
122
|
-
var hsv = (0,
|
122
|
+
var hsv = (0, conversion_js_1.rgbToHsv)(this.r, this.g, this.b);
|
123
123
|
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this.a };
|
124
124
|
};
|
125
125
|
/**
|
@@ -127,7 +127,7 @@ var TinyColor = /** @class */ (function () {
|
|
127
127
|
* "hsva(xxx, xxx, xxx, xx)".
|
128
128
|
*/
|
129
129
|
TinyColor.prototype.toHsvString = function () {
|
130
|
-
var hsv = (0,
|
130
|
+
var hsv = (0, conversion_js_1.rgbToHsv)(this.r, this.g, this.b);
|
131
131
|
var h = Math.round(hsv.h * 360);
|
132
132
|
var s = Math.round(hsv.s * 100);
|
133
133
|
var v = Math.round(hsv.v * 100);
|
@@ -137,7 +137,7 @@ var TinyColor = /** @class */ (function () {
|
|
137
137
|
* Returns the object as a HSLA object.
|
138
138
|
*/
|
139
139
|
TinyColor.prototype.toHsl = function () {
|
140
|
-
var hsl = (0,
|
140
|
+
var hsl = (0, conversion_js_1.rgbToHsl)(this.r, this.g, this.b);
|
141
141
|
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this.a };
|
142
142
|
};
|
143
143
|
/**
|
@@ -145,7 +145,7 @@ var TinyColor = /** @class */ (function () {
|
|
145
145
|
* "hsla(xxx, xxx, xxx, xx)".
|
146
146
|
*/
|
147
147
|
TinyColor.prototype.toHslString = function () {
|
148
|
-
var hsl = (0,
|
148
|
+
var hsl = (0, conversion_js_1.rgbToHsl)(this.r, this.g, this.b);
|
149
149
|
var h = Math.round(hsl.h * 360);
|
150
150
|
var s = Math.round(hsl.s * 100);
|
151
151
|
var l = Math.round(hsl.l * 100);
|
@@ -157,10 +157,10 @@ var TinyColor = /** @class */ (function () {
|
|
157
157
|
*/
|
158
158
|
TinyColor.prototype.toHex = function (allow3Char) {
|
159
159
|
if (allow3Char === void 0) { allow3Char = false; }
|
160
|
-
return (0,
|
160
|
+
return (0, conversion_js_1.rgbToHex)(this.r, this.g, this.b, allow3Char);
|
161
161
|
};
|
162
162
|
/**
|
163
|
-
* Returns the hex value of the color -with a #
|
163
|
+
* Returns the hex value of the color -with a # prefixed.
|
164
164
|
* @param allow3Char will shorten hex value to 3 char if possible
|
165
165
|
*/
|
166
166
|
TinyColor.prototype.toHexString = function (allow3Char) {
|
@@ -173,16 +173,24 @@ var TinyColor = /** @class */ (function () {
|
|
173
173
|
*/
|
174
174
|
TinyColor.prototype.toHex8 = function (allow4Char) {
|
175
175
|
if (allow4Char === void 0) { allow4Char = false; }
|
176
|
-
return (0,
|
176
|
+
return (0, conversion_js_1.rgbaToHex)(this.r, this.g, this.b, this.a, allow4Char);
|
177
177
|
};
|
178
178
|
/**
|
179
|
-
* Returns the hex 8 value of the color -with a #
|
179
|
+
* Returns the hex 8 value of the color -with a # prefixed.
|
180
180
|
* @param allow4Char will shorten hex value to 4 char if possible
|
181
181
|
*/
|
182
182
|
TinyColor.prototype.toHex8String = function (allow4Char) {
|
183
183
|
if (allow4Char === void 0) { allow4Char = false; }
|
184
184
|
return '#' + this.toHex8(allow4Char);
|
185
185
|
};
|
186
|
+
/**
|
187
|
+
* Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
|
188
|
+
* @param allowShortChar will shorten hex value to 3 or 4 char if possible
|
189
|
+
*/
|
190
|
+
TinyColor.prototype.toHexShortString = function (allowShortChar) {
|
191
|
+
if (allowShortChar === void 0) { allowShortChar = false; }
|
192
|
+
return this.a === 1 ? this.toHexString(allowShortChar) : this.toHex8String(allowShortChar);
|
193
|
+
};
|
186
194
|
/**
|
187
195
|
* Returns the object as a RGBA object.
|
188
196
|
*/
|
@@ -208,7 +216,7 @@ var TinyColor = /** @class */ (function () {
|
|
208
216
|
* Returns the object as a RGBA object.
|
209
217
|
*/
|
210
218
|
TinyColor.prototype.toPercentageRgb = function () {
|
211
|
-
var fmt = function (x) { return "".concat(Math.round((0,
|
219
|
+
var fmt = function (x) { return "".concat(Math.round((0, util_js_1.bound01)(x, 255) * 100), "%"); };
|
212
220
|
return {
|
213
221
|
r: fmt(this.r),
|
214
222
|
g: fmt(this.g),
|
@@ -220,7 +228,7 @@ var TinyColor = /** @class */ (function () {
|
|
220
228
|
* Returns the RGBA relative values interpolated into a string
|
221
229
|
*/
|
222
230
|
TinyColor.prototype.toPercentageRgbString = function () {
|
223
|
-
var rnd = function (x) { return Math.round((0,
|
231
|
+
var rnd = function (x) { return Math.round((0, util_js_1.bound01)(x, 255) * 100); };
|
224
232
|
return this.a === 1
|
225
233
|
? "rgb(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%)")
|
226
234
|
: "rgba(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%, ").concat(this.roundA, ")");
|
@@ -235,8 +243,8 @@ var TinyColor = /** @class */ (function () {
|
|
235
243
|
if (this.a < 1) {
|
236
244
|
return false;
|
237
245
|
}
|
238
|
-
var hex = '#' + (0,
|
239
|
-
for (var _i = 0, _a = Object.entries(
|
246
|
+
var hex = '#' + (0, conversion_js_1.rgbToHex)(this.r, this.g, this.b, false);
|
247
|
+
for (var _i = 0, _a = Object.entries(css_color_names_js_1.names); _i < _a.length; _i++) {
|
240
248
|
var _b = _a[_i], key = _b[0], value = _b[1];
|
241
249
|
if (hex === value) {
|
242
250
|
return key;
|
@@ -301,7 +309,7 @@ var TinyColor = /** @class */ (function () {
|
|
301
309
|
if (amount === void 0) { amount = 10; }
|
302
310
|
var hsl = this.toHsl();
|
303
311
|
hsl.l += amount / 100;
|
304
|
-
hsl.l = (0,
|
312
|
+
hsl.l = (0, util_js_1.clamp01)(hsl.l);
|
305
313
|
return new TinyColor(hsl);
|
306
314
|
};
|
307
315
|
/**
|
@@ -325,7 +333,7 @@ var TinyColor = /** @class */ (function () {
|
|
325
333
|
if (amount === void 0) { amount = 10; }
|
326
334
|
var hsl = this.toHsl();
|
327
335
|
hsl.l -= amount / 100;
|
328
|
-
hsl.l = (0,
|
336
|
+
hsl.l = (0, util_js_1.clamp01)(hsl.l);
|
329
337
|
return new TinyColor(hsl);
|
330
338
|
};
|
331
339
|
/**
|
@@ -355,7 +363,7 @@ var TinyColor = /** @class */ (function () {
|
|
355
363
|
if (amount === void 0) { amount = 10; }
|
356
364
|
var hsl = this.toHsl();
|
357
365
|
hsl.s -= amount / 100;
|
358
|
-
hsl.s = (0,
|
366
|
+
hsl.s = (0, util_js_1.clamp01)(hsl.s);
|
359
367
|
return new TinyColor(hsl);
|
360
368
|
};
|
361
369
|
/**
|
@@ -366,7 +374,7 @@ var TinyColor = /** @class */ (function () {
|
|
366
374
|
if (amount === void 0) { amount = 10; }
|
367
375
|
var hsl = this.toHsl();
|
368
376
|
hsl.s += amount / 100;
|
369
|
-
hsl.s = (0,
|
377
|
+
hsl.s = (0, util_js_1.clamp01)(hsl.s);
|
370
378
|
return new TinyColor(hsl);
|
371
379
|
};
|
372
380
|
/**
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
2
|
-
import { convertHexToDecimal, hslToRgb, hsvToRgb, parseIntFromHex, rgbToRgb } from './conversion';
|
3
|
-
import { names } from './css-color-names';
|
4
|
-
import { boundAlpha, convertToPercentage } from './util';
|
2
|
+
import { convertHexToDecimal, hslToRgb, hsvToRgb, parseIntFromHex, rgbToRgb, } from './conversion.js';
|
3
|
+
import { names } from './css-color-names.js';
|
4
|
+
import { boundAlpha, convertToPercentage } from './util.js';
|
5
5
|
/**
|
6
6
|
* Given a string or object, convert that input to RGB
|
7
7
|
*
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { TinyColor } from './index';
|
2
|
-
import { convertToPercentage } from './util';
|
1
|
+
import { TinyColor } from './index.js';
|
2
|
+
import { convertToPercentage } from './util.js';
|
3
3
|
/**
|
4
4
|
* If input is an object, force 1 into "1.0" to handle ratios properly
|
5
5
|
* String input requires "1.0" as input, so 1 will be treated as 1
|
package/dist/module/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { numberInputToObject, rgbaToHex, rgbToHex, rgbToHsl, rgbToHsv } from './conversion';
|
2
|
-
import { names } from './css-color-names';
|
1
|
+
import { numberInputToObject, rgbaToHex, rgbToHex, rgbToHsl, rgbToHsv } from './conversion.js';
|
2
|
+
import { names } from './css-color-names.js';
|
3
3
|
import { inputToRGB } from './format-input';
|
4
|
-
import { bound01, boundAlpha, clamp01 } from './util';
|
4
|
+
import { bound01, boundAlpha, clamp01 } from './util.js';
|
5
5
|
var TinyColor = /** @class */ (function () {
|
6
6
|
function TinyColor(color, opts) {
|
7
7
|
if (color === void 0) { color = ''; }
|
@@ -157,7 +157,7 @@ var TinyColor = /** @class */ (function () {
|
|
157
157
|
return rgbToHex(this.r, this.g, this.b, allow3Char);
|
158
158
|
};
|
159
159
|
/**
|
160
|
-
* Returns the hex value of the color -with a #
|
160
|
+
* Returns the hex value of the color -with a # prefixed.
|
161
161
|
* @param allow3Char will shorten hex value to 3 char if possible
|
162
162
|
*/
|
163
163
|
TinyColor.prototype.toHexString = function (allow3Char) {
|
@@ -173,13 +173,21 @@ var TinyColor = /** @class */ (function () {
|
|
173
173
|
return rgbaToHex(this.r, this.g, this.b, this.a, allow4Char);
|
174
174
|
};
|
175
175
|
/**
|
176
|
-
* Returns the hex 8 value of the color -with a #
|
176
|
+
* Returns the hex 8 value of the color -with a # prefixed.
|
177
177
|
* @param allow4Char will shorten hex value to 4 char if possible
|
178
178
|
*/
|
179
179
|
TinyColor.prototype.toHex8String = function (allow4Char) {
|
180
180
|
if (allow4Char === void 0) { allow4Char = false; }
|
181
181
|
return '#' + this.toHex8(allow4Char);
|
182
182
|
};
|
183
|
+
/**
|
184
|
+
* Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
|
185
|
+
* @param allowShortChar will shorten hex value to 3 or 4 char if possible
|
186
|
+
*/
|
187
|
+
TinyColor.prototype.toHexShortString = function (allowShortChar) {
|
188
|
+
if (allowShortChar === void 0) { allowShortChar = false; }
|
189
|
+
return this.a === 1 ? this.toHexString(allowShortChar) : this.toHex8String(allowShortChar);
|
190
|
+
};
|
183
191
|
/**
|
184
192
|
* Returns the object as a RGBA object.
|
185
193
|
*/
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import { tinycolor } from './index';
|
2
|
-
export * from './index';
|
3
|
-
export * from './css-color-names';
|
4
|
-
export * from './readability';
|
5
|
-
export * from './to-ms-filter';
|
6
|
-
export * from './from-ratio';
|
7
|
-
export * from './format-input';
|
8
|
-
export * from './random';
|
9
|
-
export * from './interfaces';
|
10
|
-
export * from './conversion';
|
1
|
+
import { tinycolor } from './index.js';
|
2
|
+
export * from './index.js';
|
3
|
+
export * from './css-color-names.js';
|
4
|
+
export * from './readability.js';
|
5
|
+
export * from './to-ms-filter.js';
|
6
|
+
export * from './from-ratio.js';
|
7
|
+
export * from './format-input.js';
|
8
|
+
export * from './random.js';
|
9
|
+
export * from './interfaces.js';
|
10
|
+
export * from './conversion.js';
|
11
11
|
// kept for backwards compatability with v1
|
12
12
|
export default tinycolor;
|
package/dist/module/random.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
|
2
2
|
// randomColor by David Merfield under the CC0 license
|
3
3
|
// https://github.com/davidmerfield/randomColor/
|
4
|
-
import { TinyColor } from './index';
|
4
|
+
import { TinyColor } from './index.js';
|
5
5
|
export function random(options) {
|
6
6
|
if (options === void 0) { options = {}; }
|
7
7
|
// Check if we need to generate multiple colors
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { rgbaToArgbHex } from './conversion';
|
2
|
-
import { TinyColor } from './index';
|
1
|
+
import { rgbaToArgbHex } from './conversion.js';
|
2
|
+
import { TinyColor } from './index.js';
|
3
3
|
/**
|
4
4
|
* Returns the color represented as a Microsoft filter for use in old versions of IE.
|
5
5
|
*/
|
package/dist/module/umd_api.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import { names } from './css-color-names';
|
2
|
-
import { inputToRGB, isValidCSSUnit, stringInputToObject } from './format-input';
|
3
|
-
import { fromRatio, legacyRandom } from './from-ratio';
|
4
|
-
import { TinyColor, tinycolor } from './index';
|
5
|
-
import { random } from './random';
|
6
|
-
import { mostReadable, readability } from './readability';
|
7
|
-
import { toMsFilter } from './to-ms-filter';
|
1
|
+
import { names } from './css-color-names.js';
|
2
|
+
import { inputToRGB, isValidCSSUnit, stringInputToObject } from './format-input.js';
|
3
|
+
import { fromRatio, legacyRandom } from './from-ratio.js';
|
4
|
+
import { TinyColor, tinycolor } from './index.js';
|
5
|
+
import { random } from './random.js';
|
6
|
+
import { mostReadable, readability } from './readability.js';
|
7
|
+
import { toMsFilter } from './to-ms-filter.js';
|
8
8
|
var tinycolorumd = tinycolor;
|
9
9
|
tinycolorumd.TinyColor = TinyColor;
|
10
10
|
tinycolorumd.readability = readability;
|
package/dist/public_api.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { tinycolor } from './index';
|
2
|
-
export * from './index';
|
3
|
-
export * from './css-color-names';
|
4
|
-
export * from './readability';
|
5
|
-
export * from './to-ms-filter';
|
6
|
-
export * from './from-ratio';
|
7
|
-
export * from './format-input';
|
8
|
-
export * from './random';
|
9
|
-
export * from './interfaces';
|
10
|
-
export * from './conversion';
|
1
|
+
import { tinycolor } from './index.js';
|
2
|
+
export * from './index.js';
|
3
|
+
export * from './css-color-names.js';
|
4
|
+
export * from './readability.js';
|
5
|
+
export * from './to-ms-filter.js';
|
6
|
+
export * from './from-ratio.js';
|
7
|
+
export * from './format-input.js';
|
8
|
+
export * from './random.js';
|
9
|
+
export * from './interfaces.js';
|
10
|
+
export * from './conversion.js';
|
11
11
|
export default tinycolor;
|