toosoon-utils 3.1.0 → 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 CHANGED
@@ -847,7 +847,7 @@ xoshiro128ss(a: number, b: number, c: number, d: number): number;
847
847
 
848
848
  #### PRNG functions
849
849
 
850
- Thanks to the above algorithms, a seed-based version of most of the [random functions](#random) are exist with additionnal parameters for a `seed` string and a PRNG `algorithm` function.
850
+ Thanks to the above algorithms, a seed-based version of most of the [random functions](#random) exist with additionnal parameters for a `seed` string and a PRNG `algorithm` function.
851
851
 
852
852
  PRNG parameters:
853
853
 
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // *********************
3
2
  // WIP
4
3
  // *********************
@@ -22,9 +21,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
22
21
  }
23
22
  return to.concat(ar || Array.prototype.slice.call(from));
24
23
  };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.defaultSettings = void 0;
27
- exports.defaultSettings = {
24
+ export var defaultSettings = {
28
25
  max: Infinity
29
26
  };
30
27
  /**
@@ -35,10 +32,10 @@ exports.defaultSettings = {
35
32
  */
36
33
  var Pool = /** @class */ (function () {
37
34
  function Pool(settings) {
38
- if (settings === void 0) { settings = __assign({}, exports.defaultSettings); }
35
+ if (settings === void 0) { settings = __assign({}, defaultSettings); }
39
36
  this.items = [];
40
37
  this.pool = [];
41
- this.settings = __assign({}, exports.defaultSettings);
38
+ this.settings = __assign({}, defaultSettings);
42
39
  this.settings = Object.assign(this.settings, settings);
43
40
  }
44
41
  /**
@@ -92,4 +89,4 @@ var Pool = /** @class */ (function () {
92
89
  };
93
90
  return Pool;
94
91
  }());
95
- exports.default = Pool;
92
+ export default Pool;
@@ -1,4 +1,4 @@
1
- import { ColorRepresentation } from '../types';
1
+ import type { ColorRepresentation } from '../types';
2
2
  export type ColorScaleSettings = {
3
3
  colorSpace: 'rgb';
4
4
  } | {
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __assign = (this && this.__assign) || function () {
3
2
  __assign = Object.assign || function(t) {
4
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -10,11 +9,9 @@ var __assign = (this && this.__assign) || function () {
10
9
  };
11
10
  return __assign.apply(this, arguments);
12
11
  };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.defaultSettings = void 0;
15
- var maths_1 = require("../maths");
16
- var colors_1 = require("../colors");
17
- exports.defaultSettings = {
12
+ import { lerp, triLerp } from '../maths';
13
+ import { hclToRgb, hsbToRgb, hslToRgb, normalizeColor, rgbToHcl, rgbToHsb, rgbToHsl } from '../colors';
14
+ export var defaultSettings = {
18
15
  colorSpace: 'rgb'
19
16
  };
20
17
  /**
@@ -32,7 +29,7 @@ var ColorScale = /** @class */ (function () {
32
29
  */
33
30
  function ColorScale(input, target, length, settings) {
34
31
  if (length === void 0) { length = 5; }
35
- if (settings === void 0) { settings = __assign({}, exports.defaultSettings); }
32
+ if (settings === void 0) { settings = __assign({}, defaultSettings); }
36
33
  /**
37
34
  * Array of colors composing the color scale
38
35
  */
@@ -49,10 +46,10 @@ var ColorScale = /** @class */ (function () {
49
46
  * @returns {Array<[number, number, number]>} Color scale colors
50
47
  */
51
48
  ColorScale.generate = function (input, target, length, settings) {
52
- if (settings === void 0) { settings = __assign({}, exports.defaultSettings); }
49
+ if (settings === void 0) { settings = __assign({}, defaultSettings); }
53
50
  var colors = [];
54
- var inputColor = (0, colors_1.normalizeColor)(input);
55
- var targetColor = (0, colors_1.normalizeColor)(target);
51
+ var inputColor = normalizeColor(input);
52
+ var targetColor = normalizeColor(target);
56
53
  for (var i = 0; i < length; i++) {
57
54
  var value = i / Math.floor(length);
58
55
  colors.push(ColorScale.interpolate(inputColor, targetColor, value, settings));
@@ -70,45 +67,45 @@ var ColorScale = /** @class */ (function () {
70
67
  */
71
68
  ColorScale.interpolate = function (inputColor, targetColor, value, settings) {
72
69
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
73
- if (settings === void 0) { settings = __assign({}, exports.defaultSettings); }
70
+ if (settings === void 0) { settings = __assign({}, defaultSettings); }
74
71
  switch (settings.colorSpace) {
75
72
  case 'rgb': {
76
- var r = (0, maths_1.lerp)(value, inputColor[0], targetColor[0]);
77
- var g = (0, maths_1.lerp)(value, inputColor[1], targetColor[1]);
78
- var b = (0, maths_1.lerp)(value, inputColor[2], targetColor[2]);
73
+ var r = lerp(value, inputColor[0], targetColor[0]);
74
+ var g = lerp(value, inputColor[1], targetColor[1]);
75
+ var b = lerp(value, inputColor[2], targetColor[2]);
79
76
  return [r, g, b];
80
77
  }
81
78
  case 'hsl': {
82
- var inputHsl = (0, colors_1.rgbToHsl)(inputColor);
83
- var targetHsl = (0, colors_1.rgbToHsl)(targetColor);
79
+ var inputHsl = rgbToHsl(inputColor);
80
+ var targetHsl = rgbToHsl(targetColor);
84
81
  var h1_1 = inputHsl[0];
85
82
  var s1 = inputHsl[1];
86
83
  var l1_1 = inputHsl[2];
87
84
  var h2_1 = targetHsl[0] + ((_a = settings.hueOffset) !== null && _a !== void 0 ? _a : 0);
88
85
  var s2 = targetHsl[1] + ((_b = settings.saturationOffset) !== null && _b !== void 0 ? _b : 0);
89
86
  var l2_1 = targetHsl[2] + ((_c = settings.lightnessOffset) !== null && _c !== void 0 ? _c : 0);
90
- var h_1 = (0, maths_1.lerp)(value, h1_1, h2_1);
91
- var s = (0, maths_1.lerp)(value, s1, s2);
92
- var l_1 = (0, maths_1.lerp)(value, l1_1, l2_1);
93
- return (0, colors_1.hslToRgb)([h_1, s, l_1]);
87
+ var h_1 = lerp(value, h1_1, h2_1);
88
+ var s = lerp(value, s1, s2);
89
+ var l_1 = lerp(value, l1_1, l2_1);
90
+ return hslToRgb([h_1, s, l_1]);
94
91
  }
95
92
  case 'hsb': {
96
- var inputHsb = (0, colors_1.rgbToHsb)(inputColor);
97
- var targetHsb = (0, colors_1.rgbToHsb)(targetColor);
93
+ var inputHsb = rgbToHsb(inputColor);
94
+ var targetHsb = rgbToHsb(targetColor);
98
95
  var h1_2 = inputHsb[0];
99
96
  var s1 = inputHsb[1];
100
97
  var b1 = inputHsb[2];
101
98
  var h2_2 = targetHsb[0] + ((_d = settings.hueOffset) !== null && _d !== void 0 ? _d : 0);
102
99
  var s2 = targetHsb[1] + ((_e = settings.saturationOffset) !== null && _e !== void 0 ? _e : 0);
103
100
  var b2 = targetHsb[2] + ((_f = settings.brightnessOffset) !== null && _f !== void 0 ? _f : 0);
104
- var h_2 = (0, maths_1.lerp)(value, h1_2, h2_2);
105
- var s = (0, maths_1.lerp)(value, s1, s2);
106
- var b = (0, maths_1.lerp)(value, b1, b2);
107
- return (0, colors_1.hsbToRgb)([h_2, s, b]);
101
+ var h_2 = lerp(value, h1_2, h2_2);
102
+ var s = lerp(value, s1, s2);
103
+ var b = lerp(value, b1, b2);
104
+ return hsbToRgb([h_2, s, b]);
108
105
  }
109
106
  case 'hcl':
110
- var inputHcl = (0, colors_1.rgbToHcl)(inputColor);
111
- var targetHcl = (0, colors_1.rgbToHcl)(targetColor);
107
+ var inputHcl = rgbToHcl(inputColor);
108
+ var targetHcl = rgbToHcl(targetColor);
112
109
  var powerValue = Math.pow(value, (_g = settings.powerStrength) !== null && _g !== void 0 ? _g : 1);
113
110
  var h1 = inputHcl[0];
114
111
  var c1 = inputHcl[1];
@@ -131,7 +128,7 @@ var ColorScale = /** @class */ (function () {
131
128
  * - Luminance: Constant
132
129
  */
133
130
  case 'qualitative': {
134
- h = (0, maths_1.lerp)(value, h1, h2);
131
+ h = lerp(value, h1, h2);
135
132
  c = c1;
136
133
  l = l1;
137
134
  }
@@ -145,9 +142,9 @@ var ColorScale = /** @class */ (function () {
145
142
  * - Luminance: Linear (+power)
146
143
  */
147
144
  case 'sequential': {
148
- h = (0, maths_1.lerp)(value, h1, h2);
149
- c = settings.triangular ? (0, maths_1.triLerp)(powerValue, c1, c2, settings.triangular) : (0, maths_1.lerp)(powerValue, c1, c2);
150
- l = (0, maths_1.lerp)(powerValue, l1, l2);
145
+ h = lerp(value, h1, h2);
146
+ c = settings.triangular ? triLerp(powerValue, c1, c2, settings.triangular) : lerp(powerValue, c1, c2);
147
+ l = lerp(powerValue, l1, l2);
151
148
  }
152
149
  /**
153
150
  * Diverging
@@ -159,19 +156,19 @@ var ColorScale = /** @class */ (function () {
159
156
  * - Luminance: Linear (+power)
160
157
  */
161
158
  case 'diverging': {
162
- h = value < 0.5 ? h1 : value > 0.5 ? h2 : (0, maths_1.lerp)(0.5, h1, h2);
163
- c = settings.triangular ? (0, maths_1.triLerp)(powerValue, c1, c2, settings.triangular) : (0, maths_1.lerp)(powerValue, c1, c2);
164
- l = (0, maths_1.lerp)(powerValue, l1, l2);
159
+ h = value < 0.5 ? h1 : value > 0.5 ? h2 : lerp(0.5, h1, h2);
160
+ c = settings.triangular ? triLerp(powerValue, c1, c2, settings.triangular) : lerp(powerValue, c1, c2);
161
+ l = lerp(powerValue, l1, l2);
165
162
  }
166
163
  default: {
167
- h = (0, maths_1.lerp)(value, h1, h2);
168
- c = (0, maths_1.lerp)(value, c1, c2);
169
- l = (0, maths_1.lerp)(value, l1, l2);
164
+ h = lerp(value, h1, h2);
165
+ c = lerp(value, c1, c2);
166
+ l = lerp(value, l1, l2);
170
167
  }
171
168
  }
172
- return (0, colors_1.hclToRgb)([h, c, l]);
169
+ return hclToRgb([h, c, l]);
173
170
  }
174
171
  };
175
172
  return ColorScale;
176
173
  }());
177
- exports.default = ColorScale;
174
+ export default ColorScale;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var functions_1 = require("../functions");
1
+ import { now } from '../functions';
4
2
  /**
5
3
  * Utility class for controlling FPS calls
6
4
  *
@@ -25,7 +23,7 @@ var FrameRate = /** @class */ (function () {
25
23
  * @returns {boolean}
26
24
  */
27
25
  FrameRate.prototype.update = function () {
28
- this._time = (0, functions_1.now)();
26
+ this._time = now();
29
27
  this._elapsedTime = this._time - this._lastUpdate;
30
28
  if (this._elapsedTime < this._interval) {
31
29
  return false;
@@ -46,4 +44,4 @@ var FrameRate = /** @class */ (function () {
46
44
  });
47
45
  return FrameRate;
48
46
  }());
49
- exports.default = FrameRate;
47
+ export default FrameRate;
package/lib/colors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ColorRepresentation } from './types';
1
+ import type { ColorRepresentation } from './types';
2
2
  /**
3
3
  * Normalize a color representation into RGB
4
4
  *
package/lib/colors.js CHANGED
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hclToRgb = exports.rgbToHcl = exports.deltaE = exports.rgbToLab = exports.labToRgb = exports.hclToLab = exports.labToHcl = exports.hsbToRgb = exports.rgbToHsb = exports.hslToRgb = exports.rgbToHsl = exports.normalizeHslString = exports.darken = exports.lighten = exports.hexToRgb = exports.rgbToHexString = exports.rgbToHex = exports.normalizeHexString = exports.normalizeColor = void 0;
4
- var constants_1 = require("./constants");
5
- var geometry_1 = require("./geometry");
6
- var maths_1 = require("./maths");
1
+ import { W3CX11 } from './constants';
2
+ import { toDegrees, toRadians } from './geometry';
3
+ import { clamp } from './maths';
7
4
  /**
8
5
  * Normalize a color representation into RGB
9
6
  *
10
7
  * @param {ColorRepresentation} color Color representation
11
8
  * @returns {[number,number,number]} Normalized RGB color
12
9
  */
13
- function normalizeColor(color) {
10
+ export function normalizeColor(color) {
14
11
  var _a;
15
12
  if (typeof color === 'string') {
16
- return hexToRgb((_a = constants_1.W3CX11[color]) !== null && _a !== void 0 ? _a : color);
13
+ return hexToRgb((_a = W3CX11[color]) !== null && _a !== void 0 ? _a : color);
17
14
  }
18
15
  else if (typeof color === 'number') {
19
16
  return hexToRgb(color);
@@ -22,7 +19,6 @@ function normalizeColor(color) {
22
19
  return color;
23
20
  }
24
21
  }
25
- exports.normalizeColor = normalizeColor;
26
22
  // ******************************************
27
23
  // RGB & Hexadecimal color spaces
28
24
  // ******************************************
@@ -32,7 +28,7 @@ exports.normalizeColor = normalizeColor;
32
28
  * @param {string} hex Hexadecimal string
33
29
  * @returns {string} Normalized hexadecimal string
34
30
  */
35
- function normalizeHexString(hex) {
31
+ export function normalizeHexString(hex) {
36
32
  var match;
37
33
  var result = '000000';
38
34
  hex = hex.toLocaleLowerCase();
@@ -50,7 +46,6 @@ function normalizeHexString(hex) {
50
46
  }
51
47
  return "#".concat(result);
52
48
  }
53
- exports.normalizeHexString = normalizeHexString;
54
49
  /**
55
50
  * Convert RGB to hexadecimal
56
51
  * Note: rgb values are contained in the interval [0, 1]
@@ -58,11 +53,10 @@ exports.normalizeHexString = normalizeHexString;
58
53
  * @param {[number, number, number]} rgb RGB color
59
54
  * @returns {number} Hexadecimal color
60
55
  */
61
- function rgbToHex(_a) {
56
+ export function rgbToHex(_a) {
62
57
  var r = _a[0], g = _a[1], b = _a[2];
63
58
  return ((r * 255) << 16) ^ ((g * 255) << 8) ^ ((b * 255) << 0);
64
59
  }
65
- exports.rgbToHex = rgbToHex;
66
60
  /**
67
61
  * Convert RGB to hexadecimal string
68
62
  * Note: rgb values are contained in the interval [0, 1]
@@ -70,15 +64,14 @@ exports.rgbToHex = rgbToHex;
70
64
  * @param {[number, number, number]} rgb RGB color
71
65
  * @returns {string} Hexadecimal string
72
66
  */
73
- function rgbToHexString(_a) {
67
+ export function rgbToHexString(_a) {
74
68
  var r = _a[0], g = _a[1], b = _a[2];
75
- r = (0, maths_1.clamp)(Math.round(r * 255), 0, 255);
76
- g = (0, maths_1.clamp)(Math.round(g * 255), 0, 255);
77
- b = (0, maths_1.clamp)(Math.round(b * 255), 0, 255);
69
+ r = clamp(Math.round(r * 255), 0, 255);
70
+ g = clamp(Math.round(g * 255), 0, 255);
71
+ b = clamp(Math.round(b * 255), 0, 255);
78
72
  var result = (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1);
79
73
  return "#".concat(result);
80
74
  }
81
- exports.rgbToHexString = rgbToHexString;
82
75
  /**
83
76
  * Convert hexadecimal to RGB
84
77
  * Note: rgb values are contained in the interval [0, 1]
@@ -86,7 +79,7 @@ exports.rgbToHexString = rgbToHexString;
86
79
  * @param {number|string} hex Hexadecimal color
87
80
  * @returns {[number, number, number]} RGB color
88
81
  */
89
- function hexToRgb(hex) {
82
+ export function hexToRgb(hex) {
90
83
  if (typeof hex === 'number') {
91
84
  hex = Math.floor(hex);
92
85
  }
@@ -99,7 +92,6 @@ function hexToRgb(hex) {
99
92
  var b = (hex & 255) / 255;
100
93
  return [r, g, b];
101
94
  }
102
- exports.hexToRgb = hexToRgb;
103
95
  /**
104
96
  * Lighten a color
105
97
  *
@@ -107,7 +99,7 @@ exports.hexToRgb = hexToRgb;
107
99
  * @param {number} [amount=0] Amount of the color offset
108
100
  * @returns {string} Computed hexadecimal
109
101
  */
110
- function lighten(hex, amount) {
102
+ export function lighten(hex, amount) {
111
103
  if (amount === void 0) { amount = 0; }
112
104
  var prefix = '';
113
105
  if (hex[0] === '#') {
@@ -115,16 +107,15 @@ function lighten(hex, amount) {
115
107
  prefix = '#';
116
108
  }
117
109
  var value = parseInt(hex, 16);
118
- var r = (0, maths_1.clamp)((value >> 16) + amount, 0, 255);
119
- var b = (0, maths_1.clamp)(((value >> 8) & 0x00ff) + amount, 0, 255);
120
- var g = (0, maths_1.clamp)((value & 0x0000ff) + amount, 0, 255);
110
+ var r = clamp((value >> 16) + amount, 0, 255);
111
+ var b = clamp(((value >> 8) & 0x00ff) + amount, 0, 255);
112
+ var g = clamp((value & 0x0000ff) + amount, 0, 255);
121
113
  var result = g | (b << 8) | (r << 16);
122
114
  if (r === 0 && g === 0 && b === 0 && amount !== 0) {
123
115
  result = '000000';
124
116
  }
125
117
  return prefix + result.toString(16);
126
118
  }
127
- exports.lighten = lighten;
128
119
  /**
129
120
  * Darken a color
130
121
  *
@@ -132,11 +123,10 @@ exports.lighten = lighten;
132
123
  * @param {number} [amount=0] Amount of the color offset
133
124
  * @returns {string} Computed hexadecimal
134
125
  */
135
- function darken(hex, amount) {
126
+ export function darken(hex, amount) {
136
127
  if (amount === void 0) { amount = 0; }
137
128
  return lighten(hex, -amount);
138
129
  }
139
- exports.darken = darken;
140
130
  // ***************************************************
141
131
  // RGB & Hue-Saturation-Lightness (HSL) color spaces
142
132
  // ***************************************************
@@ -147,12 +137,11 @@ exports.darken = darken;
147
137
  * @param {string} hsl HSL string (format: 'hsl(360, 100%, 100%)')
148
138
  * @returns {[number, number, number]} Normalized HSL color
149
139
  */
150
- function normalizeHslString(hsl) {
140
+ export function normalizeHslString(hsl) {
151
141
  var _a, _b;
152
142
  var _c = (_b = (_a = hsl.match(/\d+/g)) === null || _a === void 0 ? void 0 : _a.map(Number)) !== null && _b !== void 0 ? _b : [0, 0, 0], h = _c[0], s = _c[1], l = _c[2];
153
143
  return [h, s / 100, l / 100];
154
144
  }
155
- exports.normalizeHslString = normalizeHslString;
156
145
  /**
157
146
  * Convert RGB to HSL
158
147
  * Notes:
@@ -162,7 +151,7 @@ exports.normalizeHslString = normalizeHslString;
162
151
  * @param {[number, number, number]} rgb RGB color
163
152
  * @returns {[number, number, number]} HSL color
164
153
  */
165
- function rgbToHsl(_a) {
154
+ export function rgbToHsl(_a) {
166
155
  var r = _a[0], g = _a[1], b = _a[2];
167
156
  var l = Math.max(r, g, b);
168
157
  var s = l - Math.min(r, g, b);
@@ -173,7 +162,6 @@ function rgbToHsl(_a) {
173
162
  (2 * l - s) / 2
174
163
  ];
175
164
  }
176
- exports.rgbToHsl = rgbToHsl;
177
165
  /**
178
166
  * Convert HSL to RGB
179
167
  * Notes:
@@ -183,14 +171,13 @@ exports.rgbToHsl = rgbToHsl;
183
171
  * @param {[number, number, number]} hsl HSL color
184
172
  * @returns {[number, number, number]} RGB color
185
173
  */
186
- function hslToRgb(_a) {
174
+ export function hslToRgb(_a) {
187
175
  var h = _a[0], s = _a[1], l = _a[2];
188
176
  var a = s * Math.min(l, 1 - l);
189
177
  var k = function (v) { return (v + h / 30) % 12; };
190
178
  var f = function (v) { return l - a * Math.max(-1, Math.min(k(v) - 3, Math.min(9 - k(v), 1))); };
191
179
  return [f(0), f(8), f(4)];
192
180
  }
193
- exports.hslToRgb = hslToRgb;
194
181
  // ***************************************************
195
182
  // RGB & Hue-Saturation-Brightness (HSB) color spaces
196
183
  // ***************************************************
@@ -203,7 +190,7 @@ exports.hslToRgb = hslToRgb;
203
190
  * @param {[number, number, number]} rgb RGB color
204
191
  * @returns {[number, number, number]} HSB color
205
192
  */
206
- function rgbToHsb(_a) {
193
+ export function rgbToHsb(_a) {
207
194
  var r = _a[0], g = _a[1], b = _a[2];
208
195
  var max = Math.max(r, g, b);
209
196
  var min = Math.min(r, g, b);
@@ -211,7 +198,6 @@ function rgbToHsb(_a) {
211
198
  var h = delta === 0 ? 0 : delta && max === r ? (g - b) / delta : max === g ? 2 + (b - r) / delta : 4 + (r - g) / delta;
212
199
  return [60 * (h < 0 ? h + 6 : h), max && delta / max, max];
213
200
  }
214
- exports.rgbToHsb = rgbToHsb;
215
201
  /**
216
202
  * Convert HSB to RGB
217
203
  * Notes:
@@ -221,13 +207,12 @@ exports.rgbToHsb = rgbToHsb;
221
207
  * @param {[number, number, number]} hsb HSB color
222
208
  * @returns {[number, number, number]} RGB color
223
209
  */
224
- function hsbToRgb(_a) {
210
+ export function hsbToRgb(_a) {
225
211
  var h = _a[0], s = _a[1], b = _a[2];
226
212
  var k = function (v) { return (v + h / 60) % 6; };
227
213
  var f = function (v) { return b * (1 - s * Math.max(0, Math.min(k(v), 4 - k(v), 1))); };
228
214
  return [f(5), f(3), f(1)];
229
215
  }
230
- exports.hsbToRgb = hsbToRgb;
231
216
  // *********************************************
232
217
  // LAB & Hue-Chroma-Luminance (HCL) color spaces
233
218
  // *********************************************
@@ -238,13 +223,12 @@ exports.hsbToRgb = hsbToRgb;
238
223
  * @param {[number, number, number]} lab LAB color
239
224
  * @returns {[number, number, number]} HCL color
240
225
  */
241
- function labToHcl(_a) {
226
+ export function labToHcl(_a) {
242
227
  var l = _a[0], a = _a[1], b = _a[2];
243
228
  var c = Math.sqrt(a * a + b * b);
244
229
  var h = abToHue(a, b);
245
230
  return [h, c, l];
246
231
  }
247
- exports.labToHcl = labToHcl;
248
232
  /**
249
233
  * Convert HCL to LAB
250
234
  * -> http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html
@@ -252,13 +236,12 @@ exports.labToHcl = labToHcl;
252
236
  * @param {[number, number, number]} hcl HCL color
253
237
  * @returns {[number, number, number]} LAB color space
254
238
  */
255
- function hclToLab(_a) {
239
+ export function hclToLab(_a) {
256
240
  var h = _a[0], c = _a[1], l = _a[2];
257
- var a = c * Math.cos((0, geometry_1.toRadians)(h));
258
- var b = c * Math.sin((0, geometry_1.toRadians)(h));
241
+ var a = c * Math.cos(toRadians(h));
242
+ var b = c * Math.sin(toRadians(h));
259
243
  return [l, a, b];
260
244
  }
261
- exports.hclToLab = hclToLab;
262
245
  /**
263
246
  * Convert A and B of LAB to Hue of LCH
264
247
  * -> https://stackoverflow.com/questions/53733379/conversion-of-cielab-to-cielchab-not-yielding-correct-result
@@ -290,7 +273,7 @@ function abToHue(a, b) {
290
273
  else if (a > 0 && b < 0) {
291
274
  xBias = 360;
292
275
  }
293
- return (0, geometry_1.toDegrees)(Math.atan(b / a)) + xBias;
276
+ return toDegrees(Math.atan(b / a)) + xBias;
294
277
  }
295
278
  // ******************************************
296
279
  // LAB & RGB color spaces
@@ -305,7 +288,7 @@ var f4 = function (v) { return (v > 0.008856 ? Math.pow(v, 1 / 3) : 7.787 * v +
305
288
  * @param {[number, number, number]} lab LAB color
306
289
  * @returns {[number, number, number]} RGB color
307
290
  */
308
- function labToRgb(_a) {
291
+ export function labToRgb(_a) {
309
292
  var l = _a[0], a = _a[1], b = _a[2];
310
293
  var y = (l + 16) / 116;
311
294
  var x = a / 500 + y;
@@ -314,19 +297,18 @@ function labToRgb(_a) {
314
297
  y = 1.0 * f1(y);
315
298
  z = 1.08883 * f1(z);
316
299
  return [
317
- (0, maths_1.clamp)(f2(x * 3.2406 + y * -1.5372 + z * -0.4986)),
318
- (0, maths_1.clamp)(f2(x * -0.9689 + y * 1.8758 + z * 0.0415)),
319
- (0, maths_1.clamp)(f2(x * 0.0557 + y * -0.204 + z * 1.057))
300
+ clamp(f2(x * 3.2406 + y * -1.5372 + z * -0.4986)),
301
+ clamp(f2(x * -0.9689 + y * 1.8758 + z * 0.0415)),
302
+ clamp(f2(x * 0.0557 + y * -0.204 + z * 1.057))
320
303
  ];
321
304
  }
322
- exports.labToRgb = labToRgb;
323
305
  /**
324
306
  * Converts RGB to LAB
325
307
  *
326
308
  * @param {[number, number, number]} rgb RGB color
327
309
  * @returns {[number, number, number]} LAB color
328
310
  */
329
- function rgbToLab(_a) {
311
+ export function rgbToLab(_a) {
330
312
  var r = _a[0], g = _a[1], b = _a[2];
331
313
  r = f3(r);
332
314
  g = f3(g);
@@ -336,7 +318,6 @@ function rgbToLab(_a) {
336
318
  var z = f4((r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883);
337
319
  return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
338
320
  }
339
- exports.rgbToLab = rgbToLab;
340
321
  /**
341
322
  * Get the delta from two LAB colors
342
323
  *
@@ -344,7 +325,7 @@ exports.rgbToLab = rgbToLab;
344
325
  * @param {[number, number, number]} labB Second LAB color
345
326
  * @returns {number} Delta
346
327
  */
347
- function deltaE(labA, labB) {
328
+ export function deltaE(labA, labB) {
348
329
  var deltaL = labA[0] - labB[0];
349
330
  var deltaA = labA[1] - labB[1];
350
331
  var deltaB = labA[2] - labB[2];
@@ -361,7 +342,6 @@ function deltaE(labA, labB) {
361
342
  var i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
362
343
  return i < 0 ? 0 : Math.sqrt(i);
363
344
  }
364
- exports.deltaE = deltaE;
365
345
  // *********************************************
366
346
  // RGB & Hue-Chroma-Luminance (HCL) color spaces
367
347
  // *********************************************
@@ -371,19 +351,17 @@ exports.deltaE = deltaE;
371
351
  * @param {[number, number, number]} rgb RGB color
372
352
  * @returns {[number, number, number]} HCL color
373
353
  */
374
- function rgbToHcl(_a) {
354
+ export function rgbToHcl(_a) {
375
355
  var r = _a[0], g = _a[1], b = _a[2];
376
356
  return labToHcl(rgbToLab([r, g, b]));
377
357
  }
378
- exports.rgbToHcl = rgbToHcl;
379
358
  /**
380
359
  * Converts HCL to RGB
381
360
  *
382
361
  * @param {[number, number, number]} hcl RGB color
383
362
  * @returns {[number, number, number]} RGB color
384
363
  */
385
- function hclToRgb(_a) {
364
+ export function hclToRgb(_a) {
386
365
  var h = _a[0], c = _a[1], l = _a[2];
387
366
  return labToRgb(hclToLab([h, c, l]));
388
367
  }
389
- exports.hclToRgb = hclToRgb;
package/lib/constants.js CHANGED
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.W3CX11 = exports.QUARTER_PI = exports.HALF_PI = exports.TWO_PI = exports.PI = exports.EPSILON = void 0;
4
1
  // *********************
5
2
  // Maths
6
3
  // *********************
7
- exports.EPSILON = 1e-10;
8
- exports.PI = Math.PI;
9
- exports.TWO_PI = Math.PI * 2;
10
- exports.HALF_PI = Math.PI / 2;
11
- exports.QUARTER_PI = Math.PI / 4;
4
+ export var EPSILON = 1e-10;
5
+ export var PI = Math.PI;
6
+ export var TWO_PI = Math.PI * 2;
7
+ export var HALF_PI = Math.PI / 2;
8
+ export var QUARTER_PI = Math.PI / 4;
12
9
  // *********************
13
10
  // Colors
14
11
  // *********************
15
12
  // X11 colors
16
13
  // -> https://www.w3.org/TR/css-color-3/#svg-color
17
- exports.W3CX11 = {
14
+ export var W3CX11 = {
18
15
  aliceblue: 0xf0f8ff,
19
16
  antiquewhite: 0xfaebd7,
20
17
  aqua: 0x00ffff,
package/lib/dom.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.injectStyles = exports.createCanvas = exports.closest = void 0;
4
1
  var DOCUMENT_NODE_TYPE = 9;
5
2
  /**
6
3
  * Find the closest parent that matches a selector
@@ -9,7 +6,7 @@ var DOCUMENT_NODE_TYPE = 9;
9
6
  * @param {Element|string} selector Selector or parent to match
10
7
  * @returns {Element|null}
11
8
  */
12
- function closest(element, selector) {
9
+ export function closest(element, selector) {
13
10
  var current = element;
14
11
  while (current && current.nodeType !== DOCUMENT_NODE_TYPE) {
15
12
  if ((typeof selector === 'string' && current.matches(selector)) || current === selector) {
@@ -19,7 +16,6 @@ function closest(element, selector) {
19
16
  }
20
17
  return current;
21
18
  }
22
- exports.closest = closest;
23
19
  /**
24
20
  * Create a canvas and 2d context
25
21
  *
@@ -27,7 +23,7 @@ exports.closest = closest;
27
23
  * @param {number} height Height of the canvas
28
24
  * @returns {{ canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D }}
29
25
  */
30
- function createCanvas(width, height) {
26
+ export function createCanvas(width, height) {
31
27
  var _a;
32
28
  var canvas = document.createElement('canvas');
33
29
  canvas.width = width;
@@ -35,13 +31,12 @@ function createCanvas(width, height) {
35
31
  var ctx = (_a = canvas.getContext('2d')) !== null && _a !== void 0 ? _a : new CanvasRenderingContext2D();
36
32
  return { canvas: canvas, ctx: ctx };
37
33
  }
38
- exports.createCanvas = createCanvas;
39
34
  /**
40
35
  * Inject CSS styles in `document.head`
41
36
  *
42
37
  * @param {string} styles CSS styles to inject
43
38
  */
44
- function injectStyles(styles) {
39
+ export function injectStyles(styles) {
45
40
  var $style = document.createElement('style');
46
41
  $style.innerHTML = styles;
47
42
  var $before = document.querySelector('head link[rel=stylesheet], head style');
@@ -50,4 +45,3 @@ function injectStyles(styles) {
50
45
  else
51
46
  document.head.appendChild($style);
52
47
  }
53
- exports.injectStyles = injectStyles;