toosoon-utils 2.2.0 → 2.3.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/lib/classes/_pool.d.ts +56 -0
- package/lib/classes/_pool.js +92 -0
- package/lib/classes/color-scale.d.ts +52 -0
- package/lib/classes/color-scale.js +160 -0
- package/lib/classes/frame-rate.d.ts +25 -0
- package/lib/classes/frame-rate.js +48 -0
- package/lib/colors.d.ts +155 -0
- package/lib/colors.js +367 -0
- package/lib/constants.d.ts +162 -0
- package/lib/constants.js +170 -0
- package/lib/dom.d.ts +25 -0
- package/lib/dom.js +47 -0
- package/lib/files.d.ts +14 -0
- package/lib/files.js +38 -0
- package/lib/functions.d.ts +22 -0
- package/lib/functions.js +53 -0
- package/lib/geometry.d.ts +89 -0
- package/lib/geometry.js +128 -0
- package/lib/maths.d.ts +161 -0
- package/lib/maths.js +219 -0
- package/lib/prng.d.ts +123 -0
- package/lib/prng.js +234 -0
- package/lib/random.d.ts +91 -0
- package/lib/random.js +162 -0
- package/lib/strings.d.ts +14 -0
- package/lib/strings.js +18 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +18 -0
- package/lib/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export type PoolSettings = {
|
|
2
|
+
max?: number;
|
|
3
|
+
};
|
|
4
|
+
export declare const defaultSettings: Required<PoolSettings>;
|
|
5
|
+
interface PoolItem {
|
|
6
|
+
setup?: () => void;
|
|
7
|
+
reset?: () => void;
|
|
8
|
+
dispose?: () => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Abstract class for manipulating pool items
|
|
12
|
+
*
|
|
13
|
+
* @exports
|
|
14
|
+
* @class Pool
|
|
15
|
+
*/
|
|
16
|
+
export default abstract class Pool<I extends PoolItem> {
|
|
17
|
+
items: I[];
|
|
18
|
+
pool: I[];
|
|
19
|
+
settings: Required<PoolSettings>;
|
|
20
|
+
constructor(settings?: PoolSettings);
|
|
21
|
+
/**
|
|
22
|
+
* Abstract method to implement custom item creation
|
|
23
|
+
*
|
|
24
|
+
* @returns {PoolItem}
|
|
25
|
+
*/
|
|
26
|
+
protected abstract create(): I;
|
|
27
|
+
/**
|
|
28
|
+
* Add an item to the active items
|
|
29
|
+
*
|
|
30
|
+
* @param {PoolItem} item Item to add to the active items
|
|
31
|
+
*/
|
|
32
|
+
protected add(item: I): void;
|
|
33
|
+
/**
|
|
34
|
+
* Remove an item from the active items
|
|
35
|
+
*
|
|
36
|
+
* @param {PoolItem} item Item to remove from the active items
|
|
37
|
+
*/
|
|
38
|
+
protected remove(item: I): void;
|
|
39
|
+
/**
|
|
40
|
+
* Return an item from pool or create a new one
|
|
41
|
+
*
|
|
42
|
+
* @returns {PoolItem|undefined}
|
|
43
|
+
*/
|
|
44
|
+
get(): I | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Release an item from the active items and add it to the pool
|
|
47
|
+
*
|
|
48
|
+
* @param {PoolItem} item Item to release
|
|
49
|
+
*/
|
|
50
|
+
release(item: I): void;
|
|
51
|
+
/**
|
|
52
|
+
* Dispose all items
|
|
53
|
+
*/
|
|
54
|
+
dispose(): void;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// *********************
|
|
2
|
+
// WIP
|
|
3
|
+
// *********************
|
|
4
|
+
var __assign = (this && this.__assign) || function () {
|
|
5
|
+
__assign = Object.assign || function(t) {
|
|
6
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
7
|
+
s = arguments[i];
|
|
8
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
9
|
+
t[p] = s[p];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
return __assign.apply(this, arguments);
|
|
14
|
+
};
|
|
15
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
16
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
17
|
+
if (ar || !(i in from)) {
|
|
18
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
19
|
+
ar[i] = from[i];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
23
|
+
};
|
|
24
|
+
export var defaultSettings = {
|
|
25
|
+
max: Infinity
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Abstract class for manipulating pool items
|
|
29
|
+
*
|
|
30
|
+
* @exports
|
|
31
|
+
* @class Pool
|
|
32
|
+
*/
|
|
33
|
+
var Pool = /** @class */ (function () {
|
|
34
|
+
function Pool(settings) {
|
|
35
|
+
if (settings === void 0) { settings = __assign({}, defaultSettings); }
|
|
36
|
+
this.items = [];
|
|
37
|
+
this.pool = [];
|
|
38
|
+
this.settings = __assign({}, defaultSettings);
|
|
39
|
+
this.settings = Object.assign(this.settings, settings);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Add an item to the active items
|
|
43
|
+
*
|
|
44
|
+
* @param {PoolItem} item Item to add to the active items
|
|
45
|
+
*/
|
|
46
|
+
Pool.prototype.add = function (item) {
|
|
47
|
+
this.items.push(item);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Remove an item from the active items
|
|
51
|
+
*
|
|
52
|
+
* @param {PoolItem} item Item to remove from the active items
|
|
53
|
+
*/
|
|
54
|
+
Pool.prototype.remove = function (item) {
|
|
55
|
+
this.items = this.items.filter(function (_item) { return _item !== item; });
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Return an item from pool or create a new one
|
|
59
|
+
*
|
|
60
|
+
* @returns {PoolItem|undefined}
|
|
61
|
+
*/
|
|
62
|
+
Pool.prototype.get = function () {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
if (this.items.length >= this.settings.max)
|
|
65
|
+
return;
|
|
66
|
+
var item = (_a = this.pool.pop()) !== null && _a !== void 0 ? _a : this.create();
|
|
67
|
+
(_b = item.setup) === null || _b === void 0 ? void 0 : _b.call(item);
|
|
68
|
+
this.add(item);
|
|
69
|
+
return item;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Release an item from the active items and add it to the pool
|
|
73
|
+
*
|
|
74
|
+
* @param {PoolItem} item Item to release
|
|
75
|
+
*/
|
|
76
|
+
Pool.prototype.release = function (item) {
|
|
77
|
+
var _a;
|
|
78
|
+
this.pool.push(item);
|
|
79
|
+
(_a = item.reset) === null || _a === void 0 ? void 0 : _a.call(item);
|
|
80
|
+
this.remove(item);
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Dispose all items
|
|
84
|
+
*/
|
|
85
|
+
Pool.prototype.dispose = function () {
|
|
86
|
+
__spreadArray(__spreadArray([], this.items, true), this.pool, true).forEach(function (item) { var _a; return (_a = item.dispose) === null || _a === void 0 ? void 0 : _a.call(item); });
|
|
87
|
+
this.items = [];
|
|
88
|
+
this.pool = [];
|
|
89
|
+
};
|
|
90
|
+
return Pool;
|
|
91
|
+
}());
|
|
92
|
+
export default Pool;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ColorRepresentation } from '../types';
|
|
2
|
+
export type ColorScaleSettings = {
|
|
3
|
+
colorSpace: 'rgb' | 'hsl' | 'hsb';
|
|
4
|
+
} | {
|
|
5
|
+
colorSpace: 'hcl';
|
|
6
|
+
mode?: 'qualitative' | 'sequential' | 'diverging';
|
|
7
|
+
triangular?: number;
|
|
8
|
+
powerStrength?: number;
|
|
9
|
+
hueOffset?: number;
|
|
10
|
+
chromaOffset?: number;
|
|
11
|
+
luminanceOffset?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const defaultSettings: Required<ColorScaleSettings>;
|
|
14
|
+
/**
|
|
15
|
+
* Utility class for generating color scales and interpolating between colors
|
|
16
|
+
*
|
|
17
|
+
* @exports
|
|
18
|
+
* @class ColorScale
|
|
19
|
+
*/
|
|
20
|
+
export default class ColorScale {
|
|
21
|
+
/**
|
|
22
|
+
* Array of colors composing the color scale
|
|
23
|
+
*/
|
|
24
|
+
colors: Array<[number, number, number]>;
|
|
25
|
+
/**
|
|
26
|
+
* @param {ColorRepresentation} input Input color representation
|
|
27
|
+
* @param {ColorRepresentation} target Target color representation
|
|
28
|
+
* @param {number} [length=5] Amount of colors composing the color scale
|
|
29
|
+
* @param {ColorScaleSettings} [settings] Color scale generation settings
|
|
30
|
+
*/
|
|
31
|
+
constructor(input: ColorRepresentation, target: ColorRepresentation, length?: number, settings?: ColorScaleSettings);
|
|
32
|
+
/**
|
|
33
|
+
* Static method for generating a color scale
|
|
34
|
+
*
|
|
35
|
+
* @param {ColorRepresentation} input Input color representation
|
|
36
|
+
* @param {ColorRepresentation} target Target color representation
|
|
37
|
+
* @param {number} length Amount of colors composing the color scale
|
|
38
|
+
* @param {ColorScaleSettings} [settings] Color scale generation settings
|
|
39
|
+
* @returns {Array<[number, number, number]>} Color scale colors
|
|
40
|
+
*/
|
|
41
|
+
static generate(input: ColorRepresentation, target: ColorRepresentation, length: number, settings?: ColorScaleSettings): Array<[number, number, number]>;
|
|
42
|
+
/**
|
|
43
|
+
* Static method for interpolating between colors
|
|
44
|
+
*
|
|
45
|
+
* @param {[number,number,number]} inputColor Input color
|
|
46
|
+
* @param {[number,number,number]} targetColor Target color
|
|
47
|
+
* @param {number} value Interpolation normalized value
|
|
48
|
+
* @param {ColorScaleSettings} [settings] Color scale settings
|
|
49
|
+
* @returns {[number,number,number]} Interpolated color
|
|
50
|
+
*/
|
|
51
|
+
static interpolate(inputColor: [number, number, number], targetColor: [number, number, number], value: number, settings?: ColorScaleSettings): [number, number, number];
|
|
52
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { lerp, triLerp } from '../maths';
|
|
13
|
+
import { hclToRgb, hsbToRgb, hslToRgb, normalizeColor, rgbToHcl, rgbToHsb, rgbToHsl } from '../colors';
|
|
14
|
+
export var defaultSettings = {
|
|
15
|
+
colorSpace: 'rgb'
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Utility class for generating color scales and interpolating between colors
|
|
19
|
+
*
|
|
20
|
+
* @exports
|
|
21
|
+
* @class ColorScale
|
|
22
|
+
*/
|
|
23
|
+
var ColorScale = /** @class */ (function () {
|
|
24
|
+
/**
|
|
25
|
+
* @param {ColorRepresentation} input Input color representation
|
|
26
|
+
* @param {ColorRepresentation} target Target color representation
|
|
27
|
+
* @param {number} [length=5] Amount of colors composing the color scale
|
|
28
|
+
* @param {ColorScaleSettings} [settings] Color scale generation settings
|
|
29
|
+
*/
|
|
30
|
+
function ColorScale(input, target, length, settings) {
|
|
31
|
+
if (length === void 0) { length = 5; }
|
|
32
|
+
if (settings === void 0) { settings = __assign({}, defaultSettings); }
|
|
33
|
+
/**
|
|
34
|
+
* Array of colors composing the color scale
|
|
35
|
+
*/
|
|
36
|
+
this.colors = [];
|
|
37
|
+
this.colors = ColorScale.generate(input, target, length, settings);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Static method for generating a color scale
|
|
41
|
+
*
|
|
42
|
+
* @param {ColorRepresentation} input Input color representation
|
|
43
|
+
* @param {ColorRepresentation} target Target color representation
|
|
44
|
+
* @param {number} length Amount of colors composing the color scale
|
|
45
|
+
* @param {ColorScaleSettings} [settings] Color scale generation settings
|
|
46
|
+
* @returns {Array<[number, number, number]>} Color scale colors
|
|
47
|
+
*/
|
|
48
|
+
ColorScale.generate = function (input, target, length, settings) {
|
|
49
|
+
if (settings === void 0) { settings = __assign({}, defaultSettings); }
|
|
50
|
+
var colors = [];
|
|
51
|
+
var inputColor = normalizeColor(input);
|
|
52
|
+
var targetColor = normalizeColor(target);
|
|
53
|
+
for (var i = 0; i < length; i++) {
|
|
54
|
+
var value = i / Math.floor(length);
|
|
55
|
+
colors.push(ColorScale.interpolate(inputColor, targetColor, value, settings));
|
|
56
|
+
}
|
|
57
|
+
return colors;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Static method for interpolating between colors
|
|
61
|
+
*
|
|
62
|
+
* @param {[number,number,number]} inputColor Input color
|
|
63
|
+
* @param {[number,number,number]} targetColor Target color
|
|
64
|
+
* @param {number} value Interpolation normalized value
|
|
65
|
+
* @param {ColorScaleSettings} [settings] Color scale settings
|
|
66
|
+
* @returns {[number,number,number]} Interpolated color
|
|
67
|
+
*/
|
|
68
|
+
ColorScale.interpolate = function (inputColor, targetColor, value, settings) {
|
|
69
|
+
var _a, _b, _c, _d;
|
|
70
|
+
if (settings === void 0) { settings = __assign({}, defaultSettings); }
|
|
71
|
+
switch (settings.colorSpace) {
|
|
72
|
+
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
|
+
return [r, g, b];
|
|
77
|
+
}
|
|
78
|
+
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]);
|
|
85
|
+
}
|
|
86
|
+
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]);
|
|
93
|
+
}
|
|
94
|
+
case 'hcl':
|
|
95
|
+
var inputHcl = rgbToHcl(inputColor);
|
|
96
|
+
var targetHcl = rgbToHcl(targetColor);
|
|
97
|
+
var powerValue = Math.pow(value, (_a = settings.powerStrength) !== null && _a !== void 0 ? _a : 1);
|
|
98
|
+
var h1 = inputHcl[0];
|
|
99
|
+
var c1 = inputHcl[1];
|
|
100
|
+
var l1 = inputHcl[2];
|
|
101
|
+
var h2 = targetHcl[0] + ((_b = settings.hueOffset) !== null && _b !== void 0 ? _b : 0);
|
|
102
|
+
var c2 = targetHcl[1] + ((_c = settings.chromaOffset) !== null && _c !== void 0 ? _c : 0);
|
|
103
|
+
var l2 = targetHcl[2] + ((_d = settings.luminanceOffset) !== null && _d !== void 0 ? _d : 0);
|
|
104
|
+
var h = void 0, c = void 0, l = void 0;
|
|
105
|
+
// HCL color palettes
|
|
106
|
+
// -> https://colorspace.r-forge.r-project.org/articles/hcl_palettes.html
|
|
107
|
+
if (settings.mode === 'qualitative') {
|
|
108
|
+
/**
|
|
109
|
+
* Qualitative
|
|
110
|
+
* Designed for coding categorical information,
|
|
111
|
+
* where no particular ordering of categories is available
|
|
112
|
+
* and every color should receive the same perceptual weight.
|
|
113
|
+
*
|
|
114
|
+
* - Hue: Linear
|
|
115
|
+
* - Chroma: Constant
|
|
116
|
+
* - Luminance: Constant
|
|
117
|
+
*/
|
|
118
|
+
h = lerp(value, h1, h2);
|
|
119
|
+
c = c1;
|
|
120
|
+
l = l1;
|
|
121
|
+
}
|
|
122
|
+
else if (settings.mode === 'sequential') {
|
|
123
|
+
/**
|
|
124
|
+
* Sequential
|
|
125
|
+
* Designed for coding ordered/numeric information,
|
|
126
|
+
* going from high to low (or vice versa).
|
|
127
|
+
*
|
|
128
|
+
* - Hue: Constant | Linear
|
|
129
|
+
* - Chroma: Linear (+power) | Triangular (+power)
|
|
130
|
+
* - Luminance: Linear (+power)
|
|
131
|
+
*/
|
|
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
|
+
}
|
|
136
|
+
else if (settings.mode === 'diverging') {
|
|
137
|
+
/**
|
|
138
|
+
* Diverging
|
|
139
|
+
* Designed for coding ordered/numeric information around a central neutral value,
|
|
140
|
+
* where colors diverge from neutral to two extremes.
|
|
141
|
+
*
|
|
142
|
+
* - Hue: Constants (x2)
|
|
143
|
+
* - Chroma: Linear (+power) | Triangular (+power)
|
|
144
|
+
* - Luminance: Linear (+power)
|
|
145
|
+
*/
|
|
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
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
h = lerp(value, h1, h2);
|
|
152
|
+
c = lerp(value, c1, c2);
|
|
153
|
+
l = lerp(value, l1, l2);
|
|
154
|
+
}
|
|
155
|
+
return hclToRgb([h, c, l]);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
return ColorScale;
|
|
159
|
+
}());
|
|
160
|
+
export default ColorScale;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for controlling FPS calls
|
|
3
|
+
*
|
|
4
|
+
* @exports
|
|
5
|
+
* @class FrameRate
|
|
6
|
+
*/
|
|
7
|
+
export default class FrameRate {
|
|
8
|
+
private _fps;
|
|
9
|
+
private interval;
|
|
10
|
+
private time;
|
|
11
|
+
private elapsedTime;
|
|
12
|
+
private lastUpdate;
|
|
13
|
+
/**
|
|
14
|
+
* @param {number} [fps=30] Frame per second limit
|
|
15
|
+
*/
|
|
16
|
+
constructor(fps?: number);
|
|
17
|
+
/**
|
|
18
|
+
* Return true if elapsed time since last update is higher than current FPS
|
|
19
|
+
*
|
|
20
|
+
* @returns {boolean}
|
|
21
|
+
*/
|
|
22
|
+
update(): boolean;
|
|
23
|
+
get fps(): number;
|
|
24
|
+
set fps(fps: number);
|
|
25
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { now } from '../functions';
|
|
2
|
+
/**
|
|
3
|
+
* Utility class for controlling FPS calls
|
|
4
|
+
*
|
|
5
|
+
* @exports
|
|
6
|
+
* @class FrameRate
|
|
7
|
+
*/
|
|
8
|
+
var FrameRate = /** @class */ (function () {
|
|
9
|
+
/**
|
|
10
|
+
* @param {number} [fps=30] Frame per second limit
|
|
11
|
+
*/
|
|
12
|
+
function FrameRate(fps) {
|
|
13
|
+
if (fps === void 0) { fps = 30; }
|
|
14
|
+
this.interval = 0;
|
|
15
|
+
this.time = 0;
|
|
16
|
+
this.elapsedTime = 0;
|
|
17
|
+
this.lastUpdate = 0;
|
|
18
|
+
this._fps = fps;
|
|
19
|
+
this.fps = fps;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Return true if elapsed time since last update is higher than current FPS
|
|
23
|
+
*
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
FrameRate.prototype.update = function () {
|
|
27
|
+
this.time = now();
|
|
28
|
+
this.elapsedTime = this.time - this.lastUpdate;
|
|
29
|
+
if (this.elapsedTime < this.interval) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
this.lastUpdate = this.time - (this.elapsedTime % this.interval);
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(FrameRate.prototype, "fps", {
|
|
36
|
+
get: function () {
|
|
37
|
+
return this._fps;
|
|
38
|
+
},
|
|
39
|
+
set: function (fps) {
|
|
40
|
+
this._fps = fps;
|
|
41
|
+
this.interval = 1000 / fps;
|
|
42
|
+
},
|
|
43
|
+
enumerable: false,
|
|
44
|
+
configurable: true
|
|
45
|
+
});
|
|
46
|
+
return FrameRate;
|
|
47
|
+
}());
|
|
48
|
+
export default FrameRate;
|
package/lib/colors.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { ColorRepresentation } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize a color representation into RGB
|
|
4
|
+
*
|
|
5
|
+
* @param {ColorRepresentation} color Color representation
|
|
6
|
+
* @returns {[number,number,number]} Normalized RGB color
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeColor(color: ColorRepresentation): [number, number, number];
|
|
9
|
+
/**
|
|
10
|
+
* Normalize an hexadecimal string
|
|
11
|
+
*
|
|
12
|
+
* @param {string} hex Hexadecimal string
|
|
13
|
+
* @returns {string} Normalized hexadecimal string
|
|
14
|
+
*/
|
|
15
|
+
export declare function normalizeHexString(hex: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Convert RGB to hexadecimal
|
|
18
|
+
* Note: rgb values are contained in the interval [0, 1]
|
|
19
|
+
*
|
|
20
|
+
* @param {[number, number, number]} rgb RGB color
|
|
21
|
+
* @returns {number} Hexadecimal color
|
|
22
|
+
*/
|
|
23
|
+
export declare function rgbToHex([r, g, b]: [number, number, number]): number;
|
|
24
|
+
/**
|
|
25
|
+
* Convert RGB to hexadecimal string
|
|
26
|
+
* Note: rgb values are contained in the interval [0, 1]
|
|
27
|
+
*
|
|
28
|
+
* @param {[number, number, number]} rgb RGB color
|
|
29
|
+
* @returns {string} Hexadecimal string
|
|
30
|
+
*/
|
|
31
|
+
export declare function rgbToHexString([r, g, b]: [number, number, number]): string;
|
|
32
|
+
/**
|
|
33
|
+
* Convert hexadecimal to RGB
|
|
34
|
+
* Note: rgb values are contained in the interval [0, 1]
|
|
35
|
+
*
|
|
36
|
+
* @param {(number|string)} hex Hexadecimal color
|
|
37
|
+
* @returns {[number, number, number]} RGB color
|
|
38
|
+
*/
|
|
39
|
+
export declare function hexToRgb(hex: number | string): [number, number, number];
|
|
40
|
+
/**
|
|
41
|
+
* Lighten a color
|
|
42
|
+
*
|
|
43
|
+
* @param {string} hex Hexadecimal string
|
|
44
|
+
* @param {number} [amount=0] Amount of the color offset
|
|
45
|
+
* @returns {string} Computed hexadecimal
|
|
46
|
+
*/
|
|
47
|
+
export declare function lighten(hex: string, amount?: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* Darken a color
|
|
50
|
+
*
|
|
51
|
+
* @param {string} hex Hexadecimal string
|
|
52
|
+
* @param {number} [amount=0] Amount of the color offset
|
|
53
|
+
* @returns {string} Computed hexadecimal
|
|
54
|
+
*/
|
|
55
|
+
export declare function darken(hex: string, amount?: number): string;
|
|
56
|
+
/**
|
|
57
|
+
* Normalize an HSL string
|
|
58
|
+
* Note: hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
|
|
59
|
+
*
|
|
60
|
+
* @param {string} hsl HSL string (format: 'hsl(360, 100%, 100%)')
|
|
61
|
+
* @returns {[number, number, number]} Normalized HSL color
|
|
62
|
+
*/
|
|
63
|
+
export declare function normalizeHslString(hsl: string): [number, number, number];
|
|
64
|
+
/**
|
|
65
|
+
* Convert RGB to HSL
|
|
66
|
+
* Notes:
|
|
67
|
+
* - rgb values are contained in the interval [0, 1]
|
|
68
|
+
* - hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
|
|
69
|
+
*
|
|
70
|
+
* @param {[number, number, number]} rgb RGB color
|
|
71
|
+
* @returns {[number, number, number]} HSL color
|
|
72
|
+
*/
|
|
73
|
+
export declare function rgbToHsl([r, g, b]: [number, number, number]): [number, number, number];
|
|
74
|
+
/**
|
|
75
|
+
* Convert HSL to RGB
|
|
76
|
+
* Notes:
|
|
77
|
+
* - rgb values are contained in the interval [0, 1]
|
|
78
|
+
* - hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
|
|
79
|
+
*
|
|
80
|
+
* @param {[number, number, number]} hsl HSL color
|
|
81
|
+
* @returns {[number, number, number]} RGB color
|
|
82
|
+
*/
|
|
83
|
+
export declare function hslToRgb([h, s, l]: [number, number, number]): [number, number, number];
|
|
84
|
+
/**
|
|
85
|
+
* Convert RGB to HSB
|
|
86
|
+
* Notes:
|
|
87
|
+
* - rgb values are contained in the interval [0, 1]
|
|
88
|
+
* - hsb values are contained in the intervals H: [0, 360], S: [0, 1], B: [0, 1]
|
|
89
|
+
*
|
|
90
|
+
* @param {[number, number, number]} rgb RGB color
|
|
91
|
+
* @returns {[number, number, number]} HSB color
|
|
92
|
+
*/
|
|
93
|
+
export declare function rgbToHsb([r, g, b]: [number, number, number]): [number, number, number];
|
|
94
|
+
/**
|
|
95
|
+
* Convert HSB to RGB
|
|
96
|
+
* Notes:
|
|
97
|
+
* - rgb values are contained in the interval [0, 1]
|
|
98
|
+
* - hsb values are contained in the intervals H: [0, 360], S: [0, 1], B: [0, 1]
|
|
99
|
+
*
|
|
100
|
+
* @param {[number, number, number]} hsb HSB color
|
|
101
|
+
* @returns {[number, number, number]} RGB color
|
|
102
|
+
*/
|
|
103
|
+
export declare function hsbToRgb([h, s, b]: [number, number, number]): [number, number, number];
|
|
104
|
+
/**
|
|
105
|
+
* Convert LAB to HCL
|
|
106
|
+
* -> http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
|
|
107
|
+
*
|
|
108
|
+
* @param {[number, number, number]} lab LAB color
|
|
109
|
+
* @returns {[number, number, number]} HCL color
|
|
110
|
+
*/
|
|
111
|
+
export declare function labToHcl([l, a, b]: [number, number, number]): [number, number, number];
|
|
112
|
+
/**
|
|
113
|
+
* Convert HCL to LAB
|
|
114
|
+
* -> http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html
|
|
115
|
+
*
|
|
116
|
+
* @param {[number, number, number]} hcl HCL color
|
|
117
|
+
* @returns {[number, number, number]} LAB color space
|
|
118
|
+
*/
|
|
119
|
+
export declare function hclToLab([h, c, l]: [number, number, number]): [number, number, number];
|
|
120
|
+
/**
|
|
121
|
+
* Converts LAB to RGB
|
|
122
|
+
*
|
|
123
|
+
* @param {[number, number, number]} lab LAB color
|
|
124
|
+
* @returns {[number, number, number]} RGB color
|
|
125
|
+
*/
|
|
126
|
+
export declare function labToRgb([l, a, b]: [number, number, number]): [number, number, number];
|
|
127
|
+
/**
|
|
128
|
+
* Converts RGB to LAB
|
|
129
|
+
*
|
|
130
|
+
* @param {[number, number, number]} rgb RGB color
|
|
131
|
+
* @returns {[number, number, number]} LAB color
|
|
132
|
+
*/
|
|
133
|
+
export declare function rgbToLab([r, g, b]: [number, number, number]): [number, number, number];
|
|
134
|
+
/**
|
|
135
|
+
* Get the delta from two LAB colors
|
|
136
|
+
*
|
|
137
|
+
* @param {[number, number, number]} labA First LAB color
|
|
138
|
+
* @param {[number, number, number]} labB Second LAB color
|
|
139
|
+
* @returns {number} Delta
|
|
140
|
+
*/
|
|
141
|
+
export declare function deltaE(labA: [number, number, number], labB: [number, number, number]): number;
|
|
142
|
+
/**
|
|
143
|
+
* Convert RGB to HCL
|
|
144
|
+
*
|
|
145
|
+
* @param {[number, number, number]} rgb RGB color
|
|
146
|
+
* @returns {[number, number, number]} HCL color
|
|
147
|
+
*/
|
|
148
|
+
export declare function rgbToHcl([r, g, b]: [number, number, number]): [number, number, number];
|
|
149
|
+
/**
|
|
150
|
+
* Converts HCL to RGB
|
|
151
|
+
*
|
|
152
|
+
* @param {[number, number, number]} hcl RGB color
|
|
153
|
+
* @returns {[number, number, number]} RGB color
|
|
154
|
+
*/
|
|
155
|
+
export declare function hclToRgb([h, c, l]: [number, number, number]): [number, number, number];
|