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