toosoon-utils 1.4.0 → 2.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 +27 -23
- package/package.json +8 -4
- package/tsconfig.json +1 -3
- package/lib/classes/_pool.d.ts +0 -56
- package/lib/classes/_pool.js +0 -92
- package/lib/classes/color-scale.d.ts +0 -52
- package/lib/classes/color-scale.js +0 -160
- package/lib/classes/frame-rate.d.ts +0 -25
- package/lib/classes/frame-rate.js +0 -48
- package/lib/colors.d.ts +0 -155
- package/lib/colors.js +0 -367
- package/lib/constants.d.ts +0 -162
- package/lib/constants.js +0 -170
- package/lib/dom.d.ts +0 -25
- package/lib/dom.js +0 -47
- package/lib/files.d.ts +0 -14
- package/lib/files.js +0 -38
- package/lib/functions.d.ts +0 -22
- package/lib/functions.js +0 -53
- package/lib/geometry.d.ts +0 -89
- package/lib/geometry.js +0 -128
- package/lib/index.d.ts +0 -10
- package/lib/index.js +0 -39
- package/lib/maths.d.ts +0 -161
- package/lib/maths.js +0 -219
- package/lib/now.d.ts +0 -5
- package/lib/now.js +0 -28
- package/lib/prng.d.ts +0 -124
- package/lib/prng.js +0 -234
- package/lib/random.d.ts +0 -91
- package/lib/random.js +0 -162
- package/lib/strings.d.ts +0 -14
- package/lib/strings.js +0 -18
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types.d.ts +0 -18
- package/lib/types.js +0 -1
- package/src/classes/_pool.ts +0 -92
- package/src/classes/color-scale.ts +0 -181
- package/src/classes/frame-rate.ts +0 -49
- package/src/colors.ts +0 -389
- package/src/constants.ts +0 -172
- package/src/dom.ts +0 -50
- package/src/files.ts +0 -42
- package/src/functions.ts +0 -56
- package/src/geometry.ts +0 -160
- package/src/maths.ts +0 -241
- package/src/prng.ts +0 -250
- package/src/random.ts +0 -162
- package/src/strings.ts +0 -19
- package/src/types.ts +0 -33
package/README.md
CHANGED
|
@@ -687,104 +687,108 @@ xoshiro128ss(a: number, b: number, c: number, d: number): number;
|
|
|
687
687
|
|
|
688
688
|
#### PRNG functions
|
|
689
689
|
|
|
690
|
-
Thanks to the above algorithms, a seed-based version of most of the [random functions](#random) are
|
|
690
|
+
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.
|
|
691
691
|
|
|
692
|
-
|
|
692
|
+
PRNG parameters:
|
|
693
693
|
|
|
694
|
-
|
|
694
|
+
```ts
|
|
695
|
+
type PRNGParameters = string | { seed: string; algorithm: (...args: number[]) => number };
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
##### random(prng)
|
|
699
|
+
|
|
700
|
+
Generate a pseudo-random number in the interval [0, 1]. It is the PRNG equivalent of `Math.random()`.
|
|
695
701
|
|
|
696
|
-
- `prng`:
|
|
697
|
-
- `[prng.seed]`: Seed used for pseudo-random number generation.
|
|
698
|
-
- `[prng.algorithm=splitmix32]`: PRNG algorithm function generating a pseudo-random number.
|
|
702
|
+
- `prng`: PRNG parameters.
|
|
699
703
|
|
|
700
704
|
```ts
|
|
701
|
-
random(prng:
|
|
705
|
+
random(prng: PRNGParameters): number;
|
|
702
706
|
```
|
|
703
707
|
|
|
704
708
|
##### randomBoolean(prng)
|
|
705
709
|
|
|
706
710
|
Generate a pseudo-random boolean (true or false).
|
|
707
711
|
|
|
708
|
-
- `prng
|
|
712
|
+
- `prng`: PRNG parameters.
|
|
709
713
|
- `[probability=0.5]`: Probability to get true.
|
|
710
714
|
|
|
711
715
|
```ts
|
|
712
|
-
randomBoolean(prng:
|
|
716
|
+
randomBoolean(prng: PRNGParameters, probability?: number): boolean;
|
|
713
717
|
```
|
|
714
718
|
|
|
715
719
|
##### randomSign(prng)
|
|
716
720
|
|
|
717
721
|
Generate a pseudo-random sign (1 or -1).
|
|
718
722
|
|
|
719
|
-
- `prng
|
|
723
|
+
- `prng`: PRNG parameters.
|
|
720
724
|
- `[probability=0.5]`: Probability to get 1.
|
|
721
725
|
|
|
722
726
|
```ts
|
|
723
|
-
randomSign(prng:
|
|
727
|
+
randomSign(prng: PRNGParameters, probability?: number): number;
|
|
724
728
|
```
|
|
725
729
|
|
|
726
730
|
##### randomFloat(prng, min, max)
|
|
727
731
|
|
|
728
732
|
Generate a pseudo-random floating-point number within a specified range.
|
|
729
733
|
|
|
730
|
-
- `prng
|
|
734
|
+
- `prng`: PRNG parameters.
|
|
731
735
|
- `[min=0]`: Minimum boundary.
|
|
732
736
|
- `[max=1]`: Maximum boundary.
|
|
733
737
|
- `[precision=2]`: Number of digits after the decimal point.
|
|
734
738
|
|
|
735
739
|
```ts
|
|
736
|
-
randomFloat(prng:
|
|
740
|
+
randomFloat(prng: PRNGParameters, min?: number, max?: number, precision?: number): number;
|
|
737
741
|
```
|
|
738
742
|
|
|
739
743
|
##### randomInt(prng, min, max)
|
|
740
744
|
|
|
741
745
|
Generate a pseudo-random integer number within a specified range.
|
|
742
746
|
|
|
743
|
-
- `prng
|
|
747
|
+
- `prng`: PRNG parameters.
|
|
744
748
|
- `min`: Minimum boundary.
|
|
745
749
|
- `max`: Maximum boundary.
|
|
746
750
|
|
|
747
751
|
```ts
|
|
748
|
-
randomInt(prng:
|
|
752
|
+
randomInt(prng: PRNGParameters, min: number, max: number): number;
|
|
749
753
|
```
|
|
750
754
|
|
|
751
755
|
##### randomHexColor(prng)
|
|
752
756
|
|
|
753
757
|
Generate a pseudo-random hexadecimal color.
|
|
754
758
|
|
|
755
|
-
- `prng
|
|
759
|
+
- `prng`: PRNG parameters.
|
|
756
760
|
|
|
757
761
|
```ts
|
|
758
|
-
randomHexColor(prng:
|
|
762
|
+
randomHexColor(prng: PRNGParameters): string;
|
|
759
763
|
```
|
|
760
764
|
|
|
761
765
|
##### randomItem(prng, array)
|
|
762
766
|
|
|
763
767
|
Pick a pseudo-random item from a given array.
|
|
764
768
|
|
|
765
|
-
- `prng
|
|
769
|
+
- `prng`: PRNG parameters.
|
|
766
770
|
- `array`: Array to pick the item from.
|
|
767
771
|
|
|
768
772
|
```ts
|
|
769
|
-
randomItem<T>(prng:
|
|
773
|
+
randomItem<T>(prng: PRNGParameters, array: T[]): T | undefined;
|
|
770
774
|
```
|
|
771
775
|
|
|
772
776
|
##### randomObjectProperty(prng)
|
|
773
777
|
|
|
774
778
|
Pick a pseudo-random property value from a given object.
|
|
775
779
|
|
|
776
|
-
- `prng
|
|
780
|
+
- `prng`: PRNG parameters.
|
|
777
781
|
- `object`: Object to pick the property from.
|
|
778
782
|
|
|
779
783
|
```ts
|
|
780
|
-
randomObjectProperty<T>(prng:
|
|
784
|
+
randomObjectProperty<T>(prng: PRNGParameters, object: Record<string, T>): T | undefined;
|
|
781
785
|
```
|
|
782
786
|
|
|
783
787
|
##### randomIndex(prng)
|
|
784
788
|
|
|
785
789
|
Select a pseudo-random index from an array of weighted items.
|
|
786
790
|
|
|
787
|
-
- `prng
|
|
791
|
+
- `prng`: PRNG parameters.
|
|
788
792
|
- `weights`: Array of weights.
|
|
789
793
|
|
|
790
794
|
```ts
|
|
@@ -1074,4 +1078,4 @@ FrameRate.update(): boolean;
|
|
|
1074
1078
|
|
|
1075
1079
|
## License
|
|
1076
1080
|
|
|
1077
|
-
MIT License, see [LICENSE](https://github.com/toosoon-dev/toosoon-utils/tree/master/LICENSE) for details
|
|
1081
|
+
MIT License, see [LICENSE](https://github.com/toosoon-dev/toosoon-utils/tree/master/LICENSE) for details.
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toosoon-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Utility functions & classes",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=16"
|
|
8
|
+
},
|
|
5
9
|
"main": "",
|
|
10
|
+
"types": "./lib/types.d.ts",
|
|
6
11
|
"exports": {
|
|
7
12
|
"./colors": "./lib/colors.js",
|
|
8
13
|
"./dom": "./lib/dom.js",
|
|
@@ -15,8 +20,7 @@
|
|
|
15
20
|
"./strings": "./lib/strings.js",
|
|
16
21
|
"./constants": "./lib/constants.js",
|
|
17
22
|
"./color-scale": "./lib/classes/color-scale.js",
|
|
18
|
-
"./frame-rate": "./lib/classes/frame-rate.js"
|
|
19
|
-
"./types": "./lib/types.d.ts"
|
|
23
|
+
"./frame-rate": "./lib/classes/frame-rate.js"
|
|
20
24
|
},
|
|
21
25
|
"scripts": {
|
|
22
26
|
"build": "npx tsc",
|
|
@@ -27,7 +31,7 @@
|
|
|
27
31
|
"url": "git+https://github.com/toosoon-dev/toosoon-utils.git"
|
|
28
32
|
},
|
|
29
33
|
"keywords": [
|
|
30
|
-
"
|
|
34
|
+
"toosoon",
|
|
31
35
|
"utils",
|
|
32
36
|
"colors",
|
|
33
37
|
"dom",
|
package/tsconfig.json
CHANGED
|
@@ -9,10 +9,8 @@
|
|
|
9
9
|
"moduleResolution": "Bundler",
|
|
10
10
|
"lib": ["DOM", "ESNext"],
|
|
11
11
|
"allowJs": true,
|
|
12
|
-
"
|
|
12
|
+
"checkJs": true,
|
|
13
13
|
"declaration": true,
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
"experimentalDecorators": true,
|
|
16
14
|
"forceConsistentCasingInFileNames": true,
|
|
17
15
|
"isolatedModules": true,
|
|
18
16
|
"incremental": true,
|
package/lib/classes/_pool.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
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 {};
|
package/lib/classes/_pool.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
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;
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
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;
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
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;
|