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/lib/constants.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// *********************
|
|
2
|
-
// Maths
|
|
3
|
-
// *********************
|
|
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;
|
|
9
|
-
// *********************
|
|
10
|
-
// Colors
|
|
11
|
-
// *********************
|
|
12
|
-
// X11 colors
|
|
13
|
-
// -> https://www.w3.org/TR/css-color-3/#svg-color
|
|
14
|
-
export var W3CX11 = {
|
|
15
|
-
aliceblue: 0xf0f8ff,
|
|
16
|
-
antiquewhite: 0xfaebd7,
|
|
17
|
-
aqua: 0x00ffff,
|
|
18
|
-
aquamarine: 0x7fffd4,
|
|
19
|
-
azure: 0xf0ffff,
|
|
20
|
-
beige: 0xf5f5dc,
|
|
21
|
-
bisque: 0xffe4c4,
|
|
22
|
-
black: 0x000000,
|
|
23
|
-
blanchedalmond: 0xffebcd,
|
|
24
|
-
blue: 0x0000ff,
|
|
25
|
-
blueviolet: 0x8a2be2,
|
|
26
|
-
brown: 0xa52a2a,
|
|
27
|
-
burlywood: 0xdeb887,
|
|
28
|
-
cadetblue: 0x5f9ea0,
|
|
29
|
-
chartreuse: 0x7fff00,
|
|
30
|
-
chocolate: 0xd2691e,
|
|
31
|
-
coral: 0xff7f50,
|
|
32
|
-
cornflower: 0x6495ed,
|
|
33
|
-
cornflowerblue: 0x6495ed,
|
|
34
|
-
cornsilk: 0xfff8dc,
|
|
35
|
-
crimson: 0xdc143c,
|
|
36
|
-
cyan: 0x00ffff,
|
|
37
|
-
darkblue: 0x00008b,
|
|
38
|
-
darkcyan: 0x008b8b,
|
|
39
|
-
darkgoldenrod: 0xb8860b,
|
|
40
|
-
darkgray: 0xa9a9a9,
|
|
41
|
-
darkgreen: 0x006400,
|
|
42
|
-
darkgrey: 0xa9a9a9,
|
|
43
|
-
darkkhaki: 0xbdb76b,
|
|
44
|
-
darkmagenta: 0x8b008b,
|
|
45
|
-
darkolivegreen: 0x556b2f,
|
|
46
|
-
darkorange: 0xff8c00,
|
|
47
|
-
darkorchid: 0x9932cc,
|
|
48
|
-
darkred: 0x8b0000,
|
|
49
|
-
darksalmon: 0xe9967a,
|
|
50
|
-
darkseagreen: 0x8fbc8f,
|
|
51
|
-
darkslateblue: 0x483d8b,
|
|
52
|
-
darkslategray: 0x2f4f4f,
|
|
53
|
-
darkslategrey: 0x2f4f4f,
|
|
54
|
-
darkturquoise: 0x00ced1,
|
|
55
|
-
darkviolet: 0x9400d3,
|
|
56
|
-
deeppink: 0xff1493,
|
|
57
|
-
deepskyblue: 0x00bfff,
|
|
58
|
-
dimgray: 0x696969,
|
|
59
|
-
dimgrey: 0x696969,
|
|
60
|
-
dodgerblue: 0x1e90ff,
|
|
61
|
-
firebrick: 0xb22222,
|
|
62
|
-
floralwhite: 0xfffaf0,
|
|
63
|
-
forestgreen: 0x228b22,
|
|
64
|
-
fuchsia: 0xff00ff,
|
|
65
|
-
gainsboro: 0xdcdcdc,
|
|
66
|
-
ghostwhite: 0xf8f8ff,
|
|
67
|
-
gold: 0xffd700,
|
|
68
|
-
goldenrod: 0xdaa520,
|
|
69
|
-
gray: 0x808080,
|
|
70
|
-
green: 0x008000,
|
|
71
|
-
greenyellow: 0xadff2f,
|
|
72
|
-
grey: 0x808080,
|
|
73
|
-
honeydew: 0xf0fff0,
|
|
74
|
-
hotpink: 0xff69b4,
|
|
75
|
-
indianred: 0xcd5c5c,
|
|
76
|
-
indigo: 0x4b0082,
|
|
77
|
-
ivory: 0xfffff0,
|
|
78
|
-
khaki: 0xf0e68c,
|
|
79
|
-
laserlemon: 0xffff54,
|
|
80
|
-
lavender: 0xe6e6fa,
|
|
81
|
-
lavenderblush: 0xfff0f5,
|
|
82
|
-
lawngreen: 0x7cfc00,
|
|
83
|
-
lemonchiffon: 0xfffacd,
|
|
84
|
-
lightblue: 0xadd8e6,
|
|
85
|
-
lightcoral: 0xf08080,
|
|
86
|
-
lightcyan: 0xe0ffff,
|
|
87
|
-
lightgoldenrod: 0xfafad2,
|
|
88
|
-
lightgoldenrodyellow: 0xfafad2,
|
|
89
|
-
lightgray: 0xd3d3d3,
|
|
90
|
-
lightgreen: 0x90ee90,
|
|
91
|
-
lightgrey: 0xd3d3d3,
|
|
92
|
-
lightpink: 0xffb6c1,
|
|
93
|
-
lightsalmon: 0xffa07a,
|
|
94
|
-
lightseagreen: 0x20b2aa,
|
|
95
|
-
lightskyblue: 0x87cefa,
|
|
96
|
-
lightslategray: 0x778899,
|
|
97
|
-
lightslategrey: 0x778899,
|
|
98
|
-
lightsteelblue: 0xb0c4de,
|
|
99
|
-
lightyellow: 0xffffe0,
|
|
100
|
-
lime: 0x00ff00,
|
|
101
|
-
limegreen: 0x32cd32,
|
|
102
|
-
linen: 0xfaf0e6,
|
|
103
|
-
magenta: 0xff00ff,
|
|
104
|
-
maroon: 0x800000,
|
|
105
|
-
maroon2: 0x7f0000,
|
|
106
|
-
maroon3: 0xb03060,
|
|
107
|
-
mediumaquamarine: 0x66cdaa,
|
|
108
|
-
mediumblue: 0x0000cd,
|
|
109
|
-
mediumorchid: 0xba55d3,
|
|
110
|
-
mediumpurple: 0x9370db,
|
|
111
|
-
mediumseagreen: 0x3cb371,
|
|
112
|
-
mediumslateblue: 0x7b68ee,
|
|
113
|
-
mediumspringgreen: 0x00fa9a,
|
|
114
|
-
mediumturquoise: 0x48d1cc,
|
|
115
|
-
mediumvioletred: 0xc71585,
|
|
116
|
-
midnightblue: 0x191970,
|
|
117
|
-
mintcream: 0xf5fffa,
|
|
118
|
-
mistyrose: 0xffe4e1,
|
|
119
|
-
moccasin: 0xffe4b5,
|
|
120
|
-
navajowhite: 0xffdead,
|
|
121
|
-
navy: 0x000080,
|
|
122
|
-
oldlace: 0xfdf5e6,
|
|
123
|
-
olive: 0x808000,
|
|
124
|
-
olivedrab: 0x6b8e23,
|
|
125
|
-
orange: 0xffa500,
|
|
126
|
-
orangered: 0xff4500,
|
|
127
|
-
orchid: 0xda70d6,
|
|
128
|
-
palegoldenrod: 0xeee8aa,
|
|
129
|
-
palegreen: 0x98fb98,
|
|
130
|
-
paleturquoise: 0xafeeee,
|
|
131
|
-
palevioletred: 0xdb7093,
|
|
132
|
-
papayawhip: 0xffefd5,
|
|
133
|
-
peachpuff: 0xffdab9,
|
|
134
|
-
peru: 0xcd853f,
|
|
135
|
-
pink: 0xffc0cb,
|
|
136
|
-
plum: 0xdda0dd,
|
|
137
|
-
powderblue: 0xb0e0e6,
|
|
138
|
-
purple: 0x800080,
|
|
139
|
-
purple2: 0x7f007f,
|
|
140
|
-
purple3: 0xa020f0,
|
|
141
|
-
rebeccapurple: 0x663399,
|
|
142
|
-
red: 0xff0000,
|
|
143
|
-
rosybrown: 0xbc8f8f,
|
|
144
|
-
royalblue: 0x4169e1,
|
|
145
|
-
saddlebrown: 0x8b4513,
|
|
146
|
-
salmon: 0xfa8072,
|
|
147
|
-
sandybrown: 0xf4a460,
|
|
148
|
-
seagreen: 0x2e8b57,
|
|
149
|
-
seashell: 0xfff5ee,
|
|
150
|
-
sienna: 0xa0522d,
|
|
151
|
-
silver: 0xc0c0c0,
|
|
152
|
-
skyblue: 0x87ceeb,
|
|
153
|
-
slateblue: 0x6a5acd,
|
|
154
|
-
slategray: 0x708090,
|
|
155
|
-
slategrey: 0x708090,
|
|
156
|
-
snow: 0xfffafa,
|
|
157
|
-
springgreen: 0x00ff7f,
|
|
158
|
-
steelblue: 0x4682b4,
|
|
159
|
-
tan: 0xd2b48c,
|
|
160
|
-
teal: 0x008080,
|
|
161
|
-
thistle: 0xd8bfd8,
|
|
162
|
-
tomato: 0xff6347,
|
|
163
|
-
turquoise: 0x40e0d0,
|
|
164
|
-
violet: 0xee82ee,
|
|
165
|
-
wheat: 0xf5deb3,
|
|
166
|
-
white: 0xffffff,
|
|
167
|
-
whitesmoke: 0xf5f5f5,
|
|
168
|
-
yellow: 0xffff00,
|
|
169
|
-
yellowgreen: 0x9acd32
|
|
170
|
-
};
|
package/lib/dom.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Find the closest parent that matches a selector
|
|
3
|
-
*
|
|
4
|
-
* @param {Element} element Target element
|
|
5
|
-
* @param {(Element|string)} selector Selector or parent to match
|
|
6
|
-
* @returns {Element|null}
|
|
7
|
-
*/
|
|
8
|
-
export declare function closest(element: Element, selector: Element | string): Element | null;
|
|
9
|
-
/**
|
|
10
|
-
* Create a canvas and 2d context
|
|
11
|
-
*
|
|
12
|
-
* @param {Number} width Width of the canvas
|
|
13
|
-
* @param {Number} height Height of the canvas
|
|
14
|
-
* @returns {{ canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D }}
|
|
15
|
-
*/
|
|
16
|
-
export declare function createCanvas(width: number, height: number): {
|
|
17
|
-
canvas: HTMLCanvasElement;
|
|
18
|
-
ctx: CanvasRenderingContext2D;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Inject CSS styles in `document.head`
|
|
22
|
-
*
|
|
23
|
-
* @param {string} styles CSS styles to inject
|
|
24
|
-
*/
|
|
25
|
-
export declare function injectStyles(styles: string): void;
|
package/lib/dom.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
var DOCUMENT_NODE_TYPE = 9;
|
|
2
|
-
/**
|
|
3
|
-
* Find the closest parent that matches a selector
|
|
4
|
-
*
|
|
5
|
-
* @param {Element} element Target element
|
|
6
|
-
* @param {(Element|string)} selector Selector or parent to match
|
|
7
|
-
* @returns {Element|null}
|
|
8
|
-
*/
|
|
9
|
-
export function closest(element, selector) {
|
|
10
|
-
var current = element;
|
|
11
|
-
while (current && current.nodeType !== DOCUMENT_NODE_TYPE) {
|
|
12
|
-
if ((typeof selector === 'string' && current.matches(selector)) || current === selector) {
|
|
13
|
-
return current;
|
|
14
|
-
}
|
|
15
|
-
current = element.parentNode;
|
|
16
|
-
}
|
|
17
|
-
return current;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Create a canvas and 2d context
|
|
21
|
-
*
|
|
22
|
-
* @param {Number} width Width of the canvas
|
|
23
|
-
* @param {Number} height Height of the canvas
|
|
24
|
-
* @returns {{ canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D }}
|
|
25
|
-
*/
|
|
26
|
-
export function createCanvas(width, height) {
|
|
27
|
-
var _a;
|
|
28
|
-
var canvas = document.createElement('canvas');
|
|
29
|
-
canvas.width = width;
|
|
30
|
-
canvas.height = height;
|
|
31
|
-
var ctx = (_a = canvas.getContext('2d')) !== null && _a !== void 0 ? _a : new CanvasRenderingContext2D();
|
|
32
|
-
return { canvas: canvas, ctx: ctx };
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Inject CSS styles in `document.head`
|
|
36
|
-
*
|
|
37
|
-
* @param {string} styles CSS styles to inject
|
|
38
|
-
*/
|
|
39
|
-
export function injectStyles(styles) {
|
|
40
|
-
var $style = document.createElement('style');
|
|
41
|
-
$style.innerHTML = styles;
|
|
42
|
-
var $before = document.querySelector('head link[rel=stylesheet], head style');
|
|
43
|
-
if ($before)
|
|
44
|
-
document.head.insertBefore($style, $before);
|
|
45
|
-
else
|
|
46
|
-
document.head.appendChild($style);
|
|
47
|
-
}
|
package/lib/files.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Download a Blob object into user files
|
|
3
|
-
*
|
|
4
|
-
* @param {Blob} blob Blob object to download
|
|
5
|
-
* @param {string} filename Downloaded file name
|
|
6
|
-
*/
|
|
7
|
-
export declare function download(blob: Blob, filename: string): void;
|
|
8
|
-
/**
|
|
9
|
-
* Upload a file from user files
|
|
10
|
-
*
|
|
11
|
-
* @param {Function} onLoad Callback called once the file is loaded
|
|
12
|
-
* @param {string} [accept=''] MIME type the file input should accept
|
|
13
|
-
*/
|
|
14
|
-
export declare function upload(onLoad: (dataUrl: string) => void, accept?: string): void;
|
package/lib/files.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Download a Blob object into user files
|
|
3
|
-
*
|
|
4
|
-
* @param {Blob} blob Blob object to download
|
|
5
|
-
* @param {string} filename Downloaded file name
|
|
6
|
-
*/
|
|
7
|
-
export function download(blob, filename) {
|
|
8
|
-
var link = document.createElement('a');
|
|
9
|
-
link.setAttribute('href', URL.createObjectURL(blob));
|
|
10
|
-
link.setAttribute('download', filename);
|
|
11
|
-
document.body.appendChild(link);
|
|
12
|
-
link.click();
|
|
13
|
-
document.body.removeChild(link);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Upload a file from user files
|
|
17
|
-
*
|
|
18
|
-
* @param {Function} onLoad Callback called once the file is loaded
|
|
19
|
-
* @param {string} [accept=''] MIME type the file input should accept
|
|
20
|
-
*/
|
|
21
|
-
export function upload(onLoad, accept) {
|
|
22
|
-
if (accept === void 0) { accept = ''; }
|
|
23
|
-
var input = document.createElement('input');
|
|
24
|
-
input.setAttribute('type', 'file');
|
|
25
|
-
input.setAttribute('accept', accept);
|
|
26
|
-
input.addEventListener('change', function (event) {
|
|
27
|
-
var _a, _b;
|
|
28
|
-
var file = (_b = (_a = event.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0];
|
|
29
|
-
if (file) {
|
|
30
|
-
var fileReader = new FileReader();
|
|
31
|
-
fileReader.addEventListener('load', function () { return onLoad(URL.createObjectURL(file)); });
|
|
32
|
-
fileReader.readAsDataURL(file);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
document.body.appendChild(input);
|
|
36
|
-
input.click();
|
|
37
|
-
document.body.removeChild(input);
|
|
38
|
-
}
|
package/lib/functions.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Deferred } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* No-op function
|
|
4
|
-
*/
|
|
5
|
-
export declare const noop: () => void;
|
|
6
|
-
/**
|
|
7
|
-
* Promise wrapped setTimeout
|
|
8
|
-
*
|
|
9
|
-
* @param {number} [timeout=0] Time to wait (in milliseconds)
|
|
10
|
-
* @returns {Promise}
|
|
11
|
-
*/
|
|
12
|
-
export declare function wait(timeout?: number): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Deferred promise implementation
|
|
15
|
-
*
|
|
16
|
-
* @returns {Deferred}
|
|
17
|
-
*/
|
|
18
|
-
export declare function defer<T = void>(): Deferred<T>;
|
|
19
|
-
/**
|
|
20
|
-
* Polyfill for `now()` functions
|
|
21
|
-
*/
|
|
22
|
-
export declare let now: () => number;
|
package/lib/functions.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* No-op function
|
|
3
|
-
*/
|
|
4
|
-
export var noop = function () { };
|
|
5
|
-
/**
|
|
6
|
-
* Promise wrapped setTimeout
|
|
7
|
-
*
|
|
8
|
-
* @param {number} [timeout=0] Time to wait (in milliseconds)
|
|
9
|
-
* @returns {Promise}
|
|
10
|
-
*/
|
|
11
|
-
export function wait(timeout) {
|
|
12
|
-
if (timeout === void 0) { timeout = 0; }
|
|
13
|
-
return new Promise(function (resolve) { return setTimeout(resolve, timeout); });
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Deferred promise implementation
|
|
17
|
-
*
|
|
18
|
-
* @returns {Deferred}
|
|
19
|
-
*/
|
|
20
|
-
export function defer() {
|
|
21
|
-
var resolve;
|
|
22
|
-
var reject;
|
|
23
|
-
var promise = new Promise(function (_resolve, _reject) {
|
|
24
|
-
resolve = _resolve;
|
|
25
|
-
reject = _reject;
|
|
26
|
-
});
|
|
27
|
-
return { promise: promise, resolve: resolve, reject: reject };
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Polyfill for `now()` functions
|
|
31
|
-
*/
|
|
32
|
-
export var now;
|
|
33
|
-
// In node.js, use `process.hrtime`
|
|
34
|
-
if (typeof process !== 'undefined' && process.hrtime) {
|
|
35
|
-
now = function () {
|
|
36
|
-
// Convert [seconds, nanoseconds] to milliseconds
|
|
37
|
-
var time = process.hrtime();
|
|
38
|
-
return time[0] * 1000 + time[1] / 1000000;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
// In a browser use `performance` or `Date`
|
|
42
|
-
else if (typeof performance !== 'undefined') {
|
|
43
|
-
// This must be bound, because directly assigning this function leads to an invocation exception in Chrome
|
|
44
|
-
now = performance.now.bind(performance);
|
|
45
|
-
}
|
|
46
|
-
else if (typeof Date.now !== 'undefined') {
|
|
47
|
-
now = Date.now;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
now = function () {
|
|
51
|
-
return new Date().getTime();
|
|
52
|
-
};
|
|
53
|
-
}
|
package/lib/geometry.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Vector3 } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Convert a radians value into degrees
|
|
4
|
-
*
|
|
5
|
-
* @param {number} radians Angle in radians
|
|
6
|
-
* @returns {number} Angle in degrees
|
|
7
|
-
*/
|
|
8
|
-
export declare function toDegrees(radians: number): number;
|
|
9
|
-
/**
|
|
10
|
-
* Convert a degrees value into radians
|
|
11
|
-
*
|
|
12
|
-
* @param {number} degrees Angle in degrees
|
|
13
|
-
* @returns {number} Angle in radians
|
|
14
|
-
*/
|
|
15
|
-
export declare function toRadians(degrees: number): number;
|
|
16
|
-
/**
|
|
17
|
-
* Calculate the angle from a point to another
|
|
18
|
-
*
|
|
19
|
-
* @param {number} x1 X value of the first point
|
|
20
|
-
* @param {number} y1 Y value of the first point
|
|
21
|
-
* @param {number} x2 X value of the second point
|
|
22
|
-
* @param {number} y2 Y value of the second point
|
|
23
|
-
* @returns {number} Angle
|
|
24
|
-
*/
|
|
25
|
-
export declare function angle(x1: number, y1: number, x2: number, y2: number): number;
|
|
26
|
-
/**
|
|
27
|
-
* Find the closest angle between to angles
|
|
28
|
-
*
|
|
29
|
-
* @param {number} source Source angle in radians
|
|
30
|
-
* @param {number} target Target angle in radians
|
|
31
|
-
* @returns {number} Closest angle
|
|
32
|
-
*/
|
|
33
|
-
export declare function closestAngle(source: number, target: number): number;
|
|
34
|
-
/**
|
|
35
|
-
* Calculate the distance between two points
|
|
36
|
-
*
|
|
37
|
-
* @param {number} x1 X coord of the first point
|
|
38
|
-
* @param {number} y1 Y coord of the first point
|
|
39
|
-
* @param {number} x2 X coord of the second point
|
|
40
|
-
* @param {number} y2 Y coord of the second point
|
|
41
|
-
* @returns {number} Computed distance
|
|
42
|
-
*/
|
|
43
|
-
export declare function distance(x1: number, y1: number, x2: number, y2: number): number;
|
|
44
|
-
/**
|
|
45
|
-
* Calculate the length of the diagonal of a rectangle
|
|
46
|
-
*
|
|
47
|
-
* @param {number} width Width of the rectangle
|
|
48
|
-
* @param {number} height Height of the rectangle
|
|
49
|
-
* @returns {number} Diagonal length
|
|
50
|
-
*/
|
|
51
|
-
export declare function diagonal(width: number, height: number): number;
|
|
52
|
-
/**
|
|
53
|
-
* Convert radians to a 3D point on the surface of a unit sphere
|
|
54
|
-
*
|
|
55
|
-
* @param {number} radius Radius of the sphere
|
|
56
|
-
* @param {number} phi Polar angle from the y (up) axis : [0, PI]
|
|
57
|
-
* @param {number} theta Equator angle around the y (up) axis : [0, 2*PI]
|
|
58
|
-
* @param {Vector3} target Target vector
|
|
59
|
-
* @returns {Vector3}
|
|
60
|
-
*/
|
|
61
|
-
export declare function radToSphere(radius: number, phi: number, theta: number, target?: Vector3): Vector3;
|
|
62
|
-
interface FitInput {
|
|
63
|
-
width: number;
|
|
64
|
-
height: number;
|
|
65
|
-
}
|
|
66
|
-
interface FitOutput {
|
|
67
|
-
left: number;
|
|
68
|
-
top: number;
|
|
69
|
-
width: number;
|
|
70
|
-
height: number;
|
|
71
|
-
scale: number;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Make a target fit a container (cover mode)
|
|
75
|
-
*
|
|
76
|
-
* @param {FitInput} target Dimension of the target
|
|
77
|
-
* @param {FitInput} container Dimension of the container
|
|
78
|
-
* @returns {FitOutput}
|
|
79
|
-
*/
|
|
80
|
-
export declare function cover(target: FitInput, container: FitInput): FitOutput;
|
|
81
|
-
/**
|
|
82
|
-
* Make a target fit a container (contain mode)
|
|
83
|
-
*
|
|
84
|
-
* @param {FitInput} target Dimension of the target
|
|
85
|
-
* @param {FitInput} container Dimension of the container
|
|
86
|
-
* @returns {FitOutput}
|
|
87
|
-
*/
|
|
88
|
-
export declare function contain(target: FitInput, container: FitInput): FitOutput;
|
|
89
|
-
export {};
|
package/lib/geometry.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { PI } from './constants';
|
|
2
|
-
/**
|
|
3
|
-
* Convert a radians value into degrees
|
|
4
|
-
*
|
|
5
|
-
* @param {number} radians Angle in radians
|
|
6
|
-
* @returns {number} Angle in degrees
|
|
7
|
-
*/
|
|
8
|
-
export function toDegrees(radians) {
|
|
9
|
-
return (radians * 180) / PI;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Convert a degrees value into radians
|
|
13
|
-
*
|
|
14
|
-
* @param {number} degrees Angle in degrees
|
|
15
|
-
* @returns {number} Angle in radians
|
|
16
|
-
*/
|
|
17
|
-
export function toRadians(degrees) {
|
|
18
|
-
return (degrees * PI) / 180;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Calculate the angle from a point to another
|
|
22
|
-
*
|
|
23
|
-
* @param {number} x1 X value of the first point
|
|
24
|
-
* @param {number} y1 Y value of the first point
|
|
25
|
-
* @param {number} x2 X value of the second point
|
|
26
|
-
* @param {number} y2 Y value of the second point
|
|
27
|
-
* @returns {number} Angle
|
|
28
|
-
*/
|
|
29
|
-
export function angle(x1, y1, x2, y2) {
|
|
30
|
-
return Math.atan2(y2 - y1, x2 - x1);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Find the closest angle between to angles
|
|
34
|
-
*
|
|
35
|
-
* @param {number} source Source angle in radians
|
|
36
|
-
* @param {number} target Target angle in radians
|
|
37
|
-
* @returns {number} Closest angle
|
|
38
|
-
*/
|
|
39
|
-
export function closestAngle(source, target) {
|
|
40
|
-
var delta = target - source;
|
|
41
|
-
return delta > PI ? target - 2 * PI : target < -PI ? delta + 2 * PI : target;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Calculate the distance between two points
|
|
45
|
-
*
|
|
46
|
-
* @param {number} x1 X coord of the first point
|
|
47
|
-
* @param {number} y1 Y coord of the first point
|
|
48
|
-
* @param {number} x2 X coord of the second point
|
|
49
|
-
* @param {number} y2 Y coord of the second point
|
|
50
|
-
* @returns {number} Computed distance
|
|
51
|
-
*/
|
|
52
|
-
export function distance(x1, y1, x2, y2) {
|
|
53
|
-
var dx = x1 - x2;
|
|
54
|
-
var dy = y1 - y2;
|
|
55
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Calculate the length of the diagonal of a rectangle
|
|
59
|
-
*
|
|
60
|
-
* @param {number} width Width of the rectangle
|
|
61
|
-
* @param {number} height Height of the rectangle
|
|
62
|
-
* @returns {number} Diagonal length
|
|
63
|
-
*/
|
|
64
|
-
export function diagonal(width, height) {
|
|
65
|
-
return Math.sqrt(width * width + height * height);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Convert radians to a 3D point on the surface of a unit sphere
|
|
69
|
-
*
|
|
70
|
-
* @param {number} radius Radius of the sphere
|
|
71
|
-
* @param {number} phi Polar angle from the y (up) axis : [0, PI]
|
|
72
|
-
* @param {number} theta Equator angle around the y (up) axis : [0, 2*PI]
|
|
73
|
-
* @param {Vector3} target Target vector
|
|
74
|
-
* @returns {Vector3}
|
|
75
|
-
*/
|
|
76
|
-
export function radToSphere(radius, phi, theta, target) {
|
|
77
|
-
if (target === void 0) { target = { x: 0, y: 0, z: 0 }; }
|
|
78
|
-
target.x = radius * Math.sin(phi) * Math.sin(theta);
|
|
79
|
-
target.y = radius * Math.cos(phi);
|
|
80
|
-
target.z = radius * Math.sin(phi) * Math.cos(theta);
|
|
81
|
-
return target;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Make a target fit a container
|
|
85
|
-
*
|
|
86
|
-
* @param {FitInput} target Dimension of the target
|
|
87
|
-
* @param {FitInput} container Dimension of the container
|
|
88
|
-
* @param {string} mode Can be 'contain' | 'cover'
|
|
89
|
-
* @returns {FitOutput}
|
|
90
|
-
*/
|
|
91
|
-
function fit(target, container, mode) {
|
|
92
|
-
var ratioWidth = container.width / target.width;
|
|
93
|
-
var ratioHeight = container.height / target.height;
|
|
94
|
-
var scale;
|
|
95
|
-
if (mode === 'contain') {
|
|
96
|
-
scale = ratioWidth < ratioHeight ? ratioWidth : ratioHeight;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
scale = ratioWidth > ratioHeight ? ratioWidth : ratioHeight;
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
left: (container.width - target.width * scale) >> 1,
|
|
103
|
-
top: (container.height - target.height * scale) >> 1,
|
|
104
|
-
width: target.width * scale,
|
|
105
|
-
height: target.height * scale,
|
|
106
|
-
scale: scale
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Make a target fit a container (cover mode)
|
|
111
|
-
*
|
|
112
|
-
* @param {FitInput} target Dimension of the target
|
|
113
|
-
* @param {FitInput} container Dimension of the container
|
|
114
|
-
* @returns {FitOutput}
|
|
115
|
-
*/
|
|
116
|
-
export function cover(target, container) {
|
|
117
|
-
return fit(target, container, 'cover');
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Make a target fit a container (contain mode)
|
|
121
|
-
*
|
|
122
|
-
* @param {FitInput} target Dimension of the target
|
|
123
|
-
* @param {FitInput} container Dimension of the container
|
|
124
|
-
* @returns {FitOutput}
|
|
125
|
-
*/
|
|
126
|
-
export function contain(target, container) {
|
|
127
|
-
return fit(target, container, 'contain');
|
|
128
|
-
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * as colors from './colors';
|
|
2
|
-
export * as dom from './dom';
|
|
3
|
-
export * as files from './files';
|
|
4
|
-
export * as functions from './functions';
|
|
5
|
-
export * as geometry from './geometry';
|
|
6
|
-
export * as maths from './maths';
|
|
7
|
-
export { default as now } from './now';
|
|
8
|
-
export * as random from './random';
|
|
9
|
-
export * as strings from './strings';
|
|
10
|
-
export type * from './types';
|
package/lib/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.strings = exports.random = exports.now = exports.maths = exports.geometry = exports.functions = exports.files = exports.dom = exports.colors = void 0;
|
|
30
|
-
exports.colors = __importStar(require("./colors"));
|
|
31
|
-
exports.dom = __importStar(require("./dom"));
|
|
32
|
-
exports.files = __importStar(require("./files"));
|
|
33
|
-
exports.functions = __importStar(require("./functions"));
|
|
34
|
-
exports.geometry = __importStar(require("./geometry"));
|
|
35
|
-
exports.maths = __importStar(require("./maths"));
|
|
36
|
-
var now_1 = require("./now");
|
|
37
|
-
Object.defineProperty(exports, "now", { enumerable: true, get: function () { return __importDefault(now_1).default; } });
|
|
38
|
-
exports.random = __importStar(require("./random"));
|
|
39
|
-
exports.strings = __importStar(require("./strings"));
|