@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.
@@ -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 util_js_1 = require("./util.js");
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
- var max = Math.max(r, g, b);
31
- var min = Math.min(r, g, b);
32
- var h = 0;
33
- var s = 0;
34
- var l = (max + min) / 2;
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
- var d = max - min;
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: h, s: s, l: l };
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
- var r;
86
- var g;
87
- var b;
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
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
99
- var p = 2 * l - q;
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
- var max = Math.max(r, g, b);
118
- var min = Math.min(r, g, b);
119
- var h = 0;
120
- var v = max;
121
- var d = max - min;
122
- var s = max === 0 ? 0 : d / max;
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: h, s: s, v: v };
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
- var i = Math.floor(h);
156
- var f = h - i;
157
- var p = v * (1 - s);
158
- var q = v * (1 - f * s);
159
- var t = v * (1 - (1 - f) * s);
160
- var mod = i % 6;
161
- var r = [v, q, p, p, t, v][mod];
162
- var g = [t, v, v, q, p, p][mod];
163
- var b = [p, p, t, v, v, q][mod];
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
- var hex = [
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
- var hex = [
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
- var hex = [
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)),
@@ -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
- /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
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");
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
- var rgb = { r: 0, g: 0, b: 0 };
28
- var a = 1;
29
- var s = null;
30
- var v = null;
31
- var l = null;
32
- var ok = false;
33
- var format = false;
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: 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: a,
67
+ a,
69
68
  };
70
69
  }
71
70
  exports.inputToRGB = inputToRGB;
72
71
  // <http://www.w3.org/TR/css3-values/#integers>
73
- var CSS_INTEGER = '[-\\+]?\\d+%?';
72
+ const CSS_INTEGER = '[-\\+]?\\d+%?';
74
73
  // <http://www.w3.org/TR/css3-values/#number-value>
75
- var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
74
+ const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
76
75
  // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
77
- var CSS_UNIT = "(?:".concat(CSS_NUMBER, ")|(?:").concat(CSS_INTEGER, ")");
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
- 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*\\)?");
83
- var matchers = {
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
- var named = false;
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
- var match = matchers.rgb.exec(color);
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
  }
@@ -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
- var index_js_1 = require("./index.js");
5
- var util_js_1 = require("./util.js");
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
- var newColor = {
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
@@ -204,4 +204,3 @@ export declare class TinyColor {
204
204
  */
205
205
  equals(color?: ColorInput): boolean;
206
206
  }
207
- export declare function tinycolor(color?: ColorInput, opts?: Partial<TinyColorOptions>): TinyColor;