@ctrl/tinycolor 3.6.1 → 4.0.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.
@@ -23,17 +23,17 @@ export function rgbToHsl(r, g, b) {
23
23
  r = bound01(r, 255);
24
24
  g = bound01(g, 255);
25
25
  b = bound01(b, 255);
26
- var max = Math.max(r, g, b);
27
- var min = Math.min(r, g, b);
28
- var h = 0;
29
- var s = 0;
30
- var l = (max + min) / 2;
26
+ const max = Math.max(r, g, b);
27
+ const min = Math.min(r, g, b);
28
+ let h = 0;
29
+ let s = 0;
30
+ const l = (max + min) / 2;
31
31
  if (max === min) {
32
32
  s = 0;
33
33
  h = 0; // achromatic
34
34
  }
35
35
  else {
36
- var d = max - min;
36
+ const d = max - min;
37
37
  s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
38
38
  switch (max) {
39
39
  case r:
@@ -50,7 +50,7 @@ export function rgbToHsl(r, g, b) {
50
50
  }
51
51
  h /= 6;
52
52
  }
53
- return { h: h, s: s, l: l };
53
+ return { h, s, l };
54
54
  }
55
55
  function hue2rgb(p, q, t) {
56
56
  if (t < 0) {
@@ -77,9 +77,9 @@ function hue2rgb(p, q, t) {
77
77
  * *Returns:* { r, g, b } in the set [0, 255]
78
78
  */
79
79
  export function hslToRgb(h, s, l) {
80
- var r;
81
- var g;
82
- var b;
80
+ let r;
81
+ let g;
82
+ let b;
83
83
  h = bound01(h, 360);
84
84
  s = bound01(s, 100);
85
85
  l = bound01(l, 100);
@@ -90,8 +90,8 @@ export function hslToRgb(h, s, l) {
90
90
  r = l;
91
91
  }
92
92
  else {
93
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
94
- var p = 2 * l - q;
93
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
94
+ const p = 2 * l - q;
95
95
  r = hue2rgb(p, q, h + 1 / 3);
96
96
  g = hue2rgb(p, q, h);
97
97
  b = hue2rgb(p, q, h - 1 / 3);
@@ -108,12 +108,12 @@ export function rgbToHsv(r, g, b) {
108
108
  r = bound01(r, 255);
109
109
  g = bound01(g, 255);
110
110
  b = bound01(b, 255);
111
- var max = Math.max(r, g, b);
112
- var min = Math.min(r, g, b);
113
- var h = 0;
114
- var v = max;
115
- var d = max - min;
116
- var s = max === 0 ? 0 : d / max;
111
+ const max = Math.max(r, g, b);
112
+ const min = Math.min(r, g, b);
113
+ let h = 0;
114
+ const v = max;
115
+ const d = max - min;
116
+ const s = max === 0 ? 0 : d / max;
117
117
  if (max === min) {
118
118
  h = 0; // achromatic
119
119
  }
@@ -133,7 +133,7 @@ export function rgbToHsv(r, g, b) {
133
133
  }
134
134
  h /= 6;
135
135
  }
136
- return { h: h, s: s, v: v };
136
+ return { h, s, v };
137
137
  }
138
138
  /**
139
139
  * Converts an HSV color value to RGB.
@@ -145,15 +145,15 @@ export function hsvToRgb(h, s, v) {
145
145
  h = bound01(h, 360) * 6;
146
146
  s = bound01(s, 100);
147
147
  v = bound01(v, 100);
148
- var i = Math.floor(h);
149
- var f = h - i;
150
- var p = v * (1 - s);
151
- var q = v * (1 - f * s);
152
- var t = v * (1 - (1 - f) * s);
153
- var mod = i % 6;
154
- var r = [v, q, p, p, t, v][mod];
155
- var g = [t, v, v, q, p, p][mod];
156
- var b = [p, p, t, v, v, q][mod];
148
+ const i = Math.floor(h);
149
+ const f = h - i;
150
+ const p = v * (1 - s);
151
+ const q = v * (1 - f * s);
152
+ const t = v * (1 - (1 - f) * s);
153
+ const mod = i % 6;
154
+ const r = [v, q, p, p, t, v][mod];
155
+ const g = [t, v, v, q, p, p][mod];
156
+ const b = [p, p, t, v, v, q][mod];
157
157
  return { r: r * 255, g: g * 255, b: b * 255 };
158
158
  }
159
159
  /**
@@ -163,7 +163,7 @@ export function hsvToRgb(h, s, v) {
163
163
  * Returns a 3 or 6 character hex
164
164
  */
165
165
  export function rgbToHex(r, g, b, allow3Char) {
166
- var hex = [
166
+ const hex = [
167
167
  pad2(Math.round(r).toString(16)),
168
168
  pad2(Math.round(g).toString(16)),
169
169
  pad2(Math.round(b).toString(16)),
@@ -185,7 +185,7 @@ export function rgbToHex(r, g, b, allow3Char) {
185
185
  */
186
186
  // eslint-disable-next-line max-params
187
187
  export function rgbaToHex(r, g, b, a, allow4Char) {
188
- var hex = [
188
+ const hex = [
189
189
  pad2(Math.round(r).toString(16)),
190
190
  pad2(Math.round(g).toString(16)),
191
191
  pad2(Math.round(b).toString(16)),
@@ -206,7 +206,7 @@ export function rgbaToHex(r, g, b, a, allow4Char) {
206
206
  * Rarely used, but required for "toFilter()"
207
207
  */
208
208
  export function rgbaToArgbHex(r, g, b, a) {
209
- var hex = [
209
+ const hex = [
210
210
  pad2(convertDecimalToHex(a)),
211
211
  pad2(Math.round(r).toString(16)),
212
212
  pad2(Math.round(g).toString(16)),
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * @hidden
4
4
  */
5
- export var names = {
5
+ export const names = {
6
6
  aliceblue: '#f0f8ff',
7
7
  antiquewhite: '#faebd7',
8
8
  aqua: '#00ffff',
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
2
1
  import { convertHexToDecimal, hslToRgb, hsvToRgb, parseIntFromHex, rgbToRgb, } from './conversion.js';
3
2
  import { names } from './css-color-names.js';
4
3
  import { boundAlpha, convertToPercentage } from './util.js';
@@ -21,13 +20,13 @@ import { boundAlpha, convertToPercentage } from './util.js';
21
20
  * ```
22
21
  */
23
22
  export function inputToRGB(color) {
24
- var rgb = { r: 0, g: 0, b: 0 };
25
- var a = 1;
26
- var s = null;
27
- var v = null;
28
- var l = null;
29
- var ok = false;
30
- var format = false;
23
+ let rgb = { r: 0, g: 0, b: 0 };
24
+ let a = 1;
25
+ let s = null;
26
+ let v = null;
27
+ let l = null;
28
+ let ok = false;
29
+ let format = false;
31
30
  if (typeof color === 'string') {
32
31
  color = stringInputToObject(color);
33
32
  }
@@ -57,26 +56,26 @@ export function inputToRGB(color) {
57
56
  }
58
57
  a = boundAlpha(a);
59
58
  return {
60
- ok: ok,
59
+ ok,
61
60
  format: color.format || format,
62
61
  r: Math.min(255, Math.max(rgb.r, 0)),
63
62
  g: Math.min(255, Math.max(rgb.g, 0)),
64
63
  b: Math.min(255, Math.max(rgb.b, 0)),
65
- a: a,
64
+ a,
66
65
  };
67
66
  }
68
67
  // <http://www.w3.org/TR/css3-values/#integers>
69
- var CSS_INTEGER = '[-\\+]?\\d+%?';
68
+ const CSS_INTEGER = '[-\\+]?\\d+%?';
70
69
  // <http://www.w3.org/TR/css3-values/#number-value>
71
- var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
70
+ const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
72
71
  // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
73
- var CSS_UNIT = "(?:".concat(CSS_NUMBER, ")|(?:").concat(CSS_INTEGER, ")");
72
+ const CSS_UNIT = `(?:${CSS_NUMBER})|(?:${CSS_INTEGER})`;
74
73
  // Actual matching.
75
74
  // Parentheses and commas are optional, but not required.
76
75
  // Whitespace can take the place of commas or opening paren
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*\\)?");
79
- var matchers = {
76
+ const PERMISSIVE_MATCH3 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`;
77
+ const PERMISSIVE_MATCH4 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`;
78
+ const matchers = {
80
79
  CSS_UNIT: new RegExp(CSS_UNIT),
81
80
  rgb: new RegExp('rgb' + PERMISSIVE_MATCH3),
82
81
  rgba: new RegExp('rgba' + PERMISSIVE_MATCH4),
@@ -98,7 +97,7 @@ export function stringInputToObject(color) {
98
97
  if (color.length === 0) {
99
98
  return false;
100
99
  }
101
- var named = false;
100
+ let named = false;
102
101
  if (names[color]) {
103
102
  color = names[color];
104
103
  named = true;
@@ -110,7 +109,7 @@ export function stringInputToObject(color) {
110
109
  // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
111
110
  // Just return an object and let the conversion functions handle that.
112
111
  // This way the result will be the same whether the tinycolor is initialized with string or object.
113
- var match = matchers.rgb.exec(color);
112
+ let match = matchers.rgb.exec(color);
114
113
  if (match) {
115
114
  return { r: match[1], g: match[2], b: match[3] };
116
115
  }
@@ -5,7 +5,7 @@ import { convertToPercentage } from './util.js';
5
5
  * String input requires "1.0" as input, so 1 will be treated as 1
6
6
  */
7
7
  export function fromRatio(ratio, opts) {
8
- var newColor = {
8
+ const newColor = {
9
9
  r: convertToPercentage(ratio.r),
10
10
  g: convertToPercentage(ratio.g),
11
11
  b: convertToPercentage(ratio.b),