@ctrl/tinycolor 3.2.0 → 3.3.2

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/dist/random.js CHANGED
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bounds = exports.random = void 0;
4
4
  // randomColor by David Merfield under the CC0 license
5
5
  // https://github.com/davidmerfield/randomColor/
6
- const index_1 = require("./index");
7
- function random(options = {}) {
6
+ var index_1 = require("./index");
7
+ function random(options) {
8
+ if (options === void 0) { options = {}; }
8
9
  // Check if we need to generate multiple colors
9
10
  if (options.count !== undefined &&
10
11
  options.count !== null) {
11
- const totalColors = options.count;
12
- const colors = [];
12
+ var totalColors = options.count;
13
+ var colors = [];
13
14
  options.count = undefined;
14
15
  while (totalColors > colors.length) {
15
16
  // Since we're generating multiple colors,
@@ -25,12 +26,12 @@ function random(options = {}) {
25
26
  return colors;
26
27
  }
27
28
  // First we pick a hue (H)
28
- const h = pickHue(options.hue, options.seed);
29
+ var h = pickHue(options.hue, options.seed);
29
30
  // Then use H to determine saturation (S)
30
- const s = pickSaturation(h, options);
31
+ var s = pickSaturation(h, options);
31
32
  // Then use S and H to determine brightness (B).
32
- const v = pickBrightness(h, s, options);
33
- const res = { h, s, v };
33
+ var v = pickBrightness(h, s, options);
34
+ var res = { h: h, s: s, v: v };
34
35
  if (options.alpha !== undefined) {
35
36
  res.a = options.alpha;
36
37
  }
@@ -39,8 +40,8 @@ function random(options = {}) {
39
40
  }
40
41
  exports.random = random;
41
42
  function pickHue(hue, seed) {
42
- const hueRange = getHueRange(hue);
43
- let res = randomWithin(hueRange, seed);
43
+ var hueRange = getHueRange(hue);
44
+ var res = randomWithin(hueRange, seed);
44
45
  // Instead of storing red as two seperate ranges,
45
46
  // we group them, using negative numbers
46
47
  if (res < 0) {
@@ -55,9 +56,9 @@ function pickSaturation(hue, options) {
55
56
  if (options.luminosity === 'random') {
56
57
  return randomWithin([0, 100], options.seed);
57
58
  }
58
- const { saturationRange } = getColorInfo(hue);
59
- let sMin = saturationRange[0];
60
- let sMax = saturationRange[1];
59
+ var saturationRange = getColorInfo(hue).saturationRange;
60
+ var sMin = saturationRange[0];
61
+ var sMax = saturationRange[1];
61
62
  switch (options.luminosity) {
62
63
  case 'bright':
63
64
  sMin = 55;
@@ -74,8 +75,8 @@ function pickSaturation(hue, options) {
74
75
  return randomWithin([sMin, sMax], options.seed);
75
76
  }
76
77
  function pickBrightness(H, S, options) {
77
- let bMin = getMinimumBrightness(H, S);
78
- let bMax = 100;
78
+ var bMin = getMinimumBrightness(H, S);
79
+ var bMax = 100;
79
80
  switch (options.luminosity) {
80
81
  case 'dark':
81
82
  bMax = bMin + 20;
@@ -93,36 +94,36 @@ function pickBrightness(H, S, options) {
93
94
  return randomWithin([bMin, bMax], options.seed);
94
95
  }
95
96
  function getMinimumBrightness(H, S) {
96
- const { lowerBounds } = getColorInfo(H);
97
- for (let i = 0; i < lowerBounds.length - 1; i++) {
98
- const s1 = lowerBounds[i][0];
99
- const v1 = lowerBounds[i][1];
100
- const s2 = lowerBounds[i + 1][0];
101
- const v2 = lowerBounds[i + 1][1];
97
+ var lowerBounds = getColorInfo(H).lowerBounds;
98
+ for (var i = 0; i < lowerBounds.length - 1; i++) {
99
+ var s1 = lowerBounds[i][0];
100
+ var v1 = lowerBounds[i][1];
101
+ var s2 = lowerBounds[i + 1][0];
102
+ var v2 = lowerBounds[i + 1][1];
102
103
  if (S >= s1 && S <= s2) {
103
- const m = (v2 - v1) / (s2 - s1);
104
- const b = v1 - m * s1;
104
+ var m = (v2 - v1) / (s2 - s1);
105
+ var b = v1 - m * s1;
105
106
  return m * S + b;
106
107
  }
107
108
  }
108
109
  return 0;
109
110
  }
110
111
  function getHueRange(colorInput) {
111
- const num = parseInt(colorInput, 10);
112
+ var num = parseInt(colorInput, 10);
112
113
  if (!Number.isNaN(num) && num < 360 && num > 0) {
113
114
  return [num, num];
114
115
  }
115
116
  if (typeof colorInput === 'string') {
116
- const namedColor = exports.bounds.find(n => n.name === colorInput);
117
+ var namedColor = exports.bounds.find(function (n) { return n.name === colorInput; });
117
118
  if (namedColor) {
118
- const color = defineColor(namedColor);
119
+ var color = defineColor(namedColor);
119
120
  if (color.hueRange) {
120
121
  return color.hueRange;
121
122
  }
122
123
  }
123
- const parsed = new index_1.TinyColor(colorInput);
124
+ var parsed = new index_1.TinyColor(colorInput);
124
125
  if (parsed.isValid) {
125
- const hue = parsed.toHsv().h;
126
+ var hue = parsed.toHsv().h;
126
127
  return [hue, hue];
127
128
  }
128
129
  }
@@ -133,8 +134,9 @@ function getColorInfo(hue) {
133
134
  if (hue >= 334 && hue <= 360) {
134
135
  hue -= 360;
135
136
  }
136
- for (const bound of exports.bounds) {
137
- const color = defineColor(bound);
137
+ for (var _i = 0, bounds_1 = exports.bounds; _i < bounds_1.length; _i++) {
138
+ var bound = bounds_1[_i];
139
+ var color = defineColor(bound);
138
140
  if (color.hueRange && hue >= color.hueRange[0] && hue <= color.hueRange[1]) {
139
141
  return color;
140
142
  }
@@ -146,17 +148,17 @@ function randomWithin(range, seed) {
146
148
  return Math.floor(range[0] + Math.random() * (range[1] + 1 - range[0]));
147
149
  }
148
150
  // Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/
149
- const max = range[1] || 1;
150
- const min = range[0] || 0;
151
+ var max = range[1] || 1;
152
+ var min = range[0] || 0;
151
153
  seed = (seed * 9301 + 49297) % 233280;
152
- const rnd = seed / 233280.0;
154
+ var rnd = seed / 233280.0;
153
155
  return Math.floor(min + rnd * (max - min));
154
156
  }
155
157
  function defineColor(bound) {
156
- const sMin = bound.lowerBounds[0][0];
157
- const sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0];
158
- const bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1];
159
- const bMax = bound.lowerBounds[0][1];
158
+ var sMin = bound.lowerBounds[0][0];
159
+ var sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0];
160
+ var bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1];
161
+ var bMax = bound.lowerBounds[0][1];
160
162
  return {
161
163
  name: bound.name,
162
164
  hueRange: bound.hueRange,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mostReadable = exports.isReadable = exports.readability = void 0;
4
- const index_1 = require("./index");
4
+ var index_1 = require("./index");
5
5
  // Readability Functions
6
6
  // ---------------------
7
7
  // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
@@ -11,8 +11,8 @@ const index_1 = require("./index");
11
11
  * Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
12
12
  */
13
13
  function readability(color1, color2) {
14
- const c1 = new index_1.TinyColor(color1);
15
- const c2 = new index_1.TinyColor(color2);
14
+ var c1 = new index_1.TinyColor(color1);
15
+ var c2 = new index_1.TinyColor(color2);
16
16
  return ((Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) /
17
17
  (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05));
18
18
  }
@@ -30,9 +30,10 @@ exports.readability = readability;
30
30
  * new TinyColor().isReadable('#000', '#111', { level: 'AA', size: 'large' }) => false
31
31
  * ```
32
32
  */
33
- function isReadable(color1, color2, wcag2 = { level: 'AA', size: 'small' }) {
33
+ function isReadable(color1, color2, wcag2) {
34
34
  var _a, _b;
35
- const readabilityLevel = readability(color1, color2);
35
+ if (wcag2 === void 0) { wcag2 = { level: 'AA', size: 'small' }; }
36
+ var readabilityLevel = readability(color1, color2);
36
37
  switch (((_a = wcag2.level) !== null && _a !== void 0 ? _a : 'AA') + ((_b = wcag2.size) !== null && _b !== void 0 ? _b : 'small')) {
37
38
  case 'AAsmall':
38
39
  case 'AAAlarge':
@@ -63,18 +64,20 @@ exports.isReadable = isReadable;
63
64
  * new TinyColor().mostReadable('#a8015a', ["#faf3f3"], { includeFallbackColors:true, level: 'AAA', size: 'small' }).toHexString(); // "#ffffff"
64
65
  * ```
65
66
  */
66
- function mostReadable(baseColor, colorList, args = { includeFallbackColors: false, level: 'AA', size: 'small' }) {
67
- let bestColor = null;
68
- let bestScore = 0;
69
- const { includeFallbackColors, level, size } = args;
70
- for (const color of colorList) {
71
- const score = readability(baseColor, color);
67
+ function mostReadable(baseColor, colorList, args) {
68
+ if (args === void 0) { args = { includeFallbackColors: false, level: 'AA', size: 'small' }; }
69
+ var bestColor = null;
70
+ var bestScore = 0;
71
+ var includeFallbackColors = args.includeFallbackColors, level = args.level, size = args.size;
72
+ for (var _i = 0, colorList_1 = colorList; _i < colorList_1.length; _i++) {
73
+ var color = colorList_1[_i];
74
+ var score = readability(baseColor, color);
72
75
  if (score > bestScore) {
73
76
  bestScore = score;
74
77
  bestColor = new index_1.TinyColor(color);
75
78
  }
76
79
  }
77
- if (isReadable(baseColor, bestColor, { level, size }) || !includeFallbackColors) {
80
+ if (isReadable(baseColor, bestColor, { level: level, size: size }) || !includeFallbackColors) {
78
81
  return bestColor;
79
82
  }
80
83
  args.includeFallbackColors = false;
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toMsFilter = void 0;
4
- const conversion_1 = require("./conversion");
5
- const index_1 = require("./index");
4
+ var conversion_1 = require("./conversion");
5
+ var index_1 = require("./index");
6
6
  /**
7
7
  * Returns the color represented as a Microsoft filter for use in old versions of IE.
8
8
  */
9
9
  function toMsFilter(firstColor, secondColor) {
10
- const color = new index_1.TinyColor(firstColor);
11
- const hex8String = '#' + conversion_1.rgbaToArgbHex(color.r, color.g, color.b, color.a);
12
- let secondHex8String = hex8String;
13
- const gradientType = color.gradientType ? 'GradientType = 1, ' : '';
10
+ var color = new index_1.TinyColor(firstColor);
11
+ var hex8String = '#' + conversion_1.rgbaToArgbHex(color.r, color.g, color.b, color.a);
12
+ var secondHex8String = hex8String;
13
+ var gradientType = color.gradientType ? 'GradientType = 1, ' : '';
14
14
  if (secondColor) {
15
- const s = new index_1.TinyColor(secondColor);
15
+ var s = new index_1.TinyColor(secondColor);
16
16
  secondHex8String = '#' + conversion_1.rgbaToArgbHex(s.r, s.g, s.b, s.a);
17
17
  }
18
- return `progid:DXImageTransform.Microsoft.gradient(${gradientType}startColorstr=${hex8String},endColorstr=${secondHex8String})`;
18
+ return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
19
19
  }
20
20
  exports.toMsFilter = toMsFilter;
package/dist/umd_api.js CHANGED
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/member-ordering */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const css_color_names_1 = require("./css-color-names");
5
- const format_input_1 = require("./format-input");
6
- const from_ratio_1 = require("./from-ratio");
7
- const index_1 = require("./index");
8
- const random_1 = require("./random");
9
- const readability_1 = require("./readability");
10
- const to_ms_filter_1 = require("./to-ms-filter");
11
- const tinycolorumd = index_1.tinycolor;
4
+ var css_color_names_1 = require("./css-color-names");
5
+ var format_input_1 = require("./format-input");
6
+ var from_ratio_1 = require("./from-ratio");
7
+ var index_1 = require("./index");
8
+ var random_1 = require("./random");
9
+ var readability_1 = require("./readability");
10
+ var to_ms_filter_1 = require("./to-ms-filter");
11
+ var tinycolorumd = index_1.tinycolor;
12
12
  tinycolorumd.TinyColor = index_1.TinyColor;
13
13
  tinycolorumd.readability = readability_1.readability;
14
14
  tinycolorumd.mostReadable = readability_1.mostReadable;
package/dist/util.js CHANGED
@@ -9,7 +9,7 @@ function bound01(n, max) {
9
9
  if (isOnePointZero(n)) {
10
10
  n = '100%';
11
11
  }
12
- const isPercent = isPercentage(n);
12
+ var isPercent = isPercentage(n);
13
13
  n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n)));
14
14
  // Automatically convert percentage into number
15
15
  if (isPercent) {
@@ -77,7 +77,7 @@ exports.boundAlpha = boundAlpha;
77
77
  */
78
78
  function convertToPercentage(n) {
79
79
  if (n <= 1) {
80
- return `${Number(n) * 100}%`;
80
+ return Number(n) * 100 + "%";
81
81
  }
82
82
  return n;
83
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl/tinycolor",
3
- "version": "3.2.0",
3
+ "version": "3.3.2",
4
4
  "description": "Fast, small color manipulation and conversion for JavaScript",
5
5
  "author": "Scott Cooper <scttcper@gmail.com>",
6
6
  "publishConfig": {
@@ -31,7 +31,7 @@
31
31
  "lint:fix": "eslint --fix --ext .js,.ts, .",
32
32
  "prepare": "npm run build",
33
33
  "build": "del-cli dist && tsc -p tsconfig.build.json && tsc -p tsconfig.module.json && ts-node build",
34
- "build:docs": "typedoc --out demo/public/docs --hideGenerator --target ES6 --mode file src",
34
+ "build:docs": "typedoc --out demo/public/docs --hideGenerator --tsconfig tsconfig.build.json src/public_api.ts",
35
35
  "test": "jest",
36
36
  "test:ci": "jest --ci --runInBand --reporters=default --reporters=jest-junit --coverage",
37
37
  "test:watch": "jest --watch"
@@ -39,23 +39,23 @@
39
39
  "dependencies": {},
40
40
  "devDependencies": {
41
41
  "@babel/plugin-transform-modules-commonjs": "7.12.1",
42
- "@babel/preset-typescript": "7.12.1",
43
- "@ctrl/eslint-config": "1.2.4",
44
- "@jest/globals": "26.5.3",
45
- "@types/node": "14.11.9",
42
+ "@babel/preset-typescript": "7.12.7",
43
+ "@ctrl/eslint-config": "1.2.8",
44
+ "@jest/globals": "26.6.2",
45
+ "@types/node": "14.14.16",
46
46
  "del-cli": "3.0.1",
47
- "jest": "26.5.3",
47
+ "jest": "26.6.3",
48
48
  "jest-junit": "12.0.0",
49
- "rollup": "2.31.0",
49
+ "rollup": "2.35.1",
50
50
  "rollup-plugin-livereload": "2.0.0",
51
- "rollup-plugin-serve": "1.0.4",
51
+ "rollup-plugin-serve": "1.1.0",
52
52
  "rollup-plugin-sourcemaps": "0.6.3",
53
53
  "rollup-plugin-terser": "7.0.2",
54
- "rollup-plugin-typescript2": "0.27.3",
54
+ "rollup-plugin-typescript2": "0.29.0",
55
55
  "rollup-plugin-uglify": "6.0.4",
56
- "ts-node": "9.0.0",
57
- "typedoc": "0.19.2",
58
- "typescript": "4.0.3"
56
+ "ts-node": "9.1.1",
57
+ "typedoc": "0.20.4",
58
+ "typescript": "4.1.3"
59
59
  },
60
60
  "jest": {
61
61
  "testEnvironment": "node"