toosoon-utils 1.1.0 → 1.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/README.md +703 -142
- 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 +9 -1
- package/lib/colors.js +59 -64
- package/lib/constants.d.ts +155 -155
- package/lib/constants.js +161 -164
- package/lib/dom.d.ts +2 -2
- package/lib/dom.js +5 -11
- package/lib/files.d.ts +1 -1
- package/lib/files.js +3 -8
- package/lib/functions.d.ts +6 -2
- package/lib/functions.js +30 -10
- package/lib/geometry.d.ts +2 -2
- package/lib/geometry.js +15 -27
- package/lib/maths.d.ts +11 -9
- package/lib/maths.js +32 -51
- package/lib/prng.d.ts +45 -0
- package/lib/prng.js +113 -0
- package/lib/random.d.ts +24 -24
- package/lib/random.js +36 -53
- package/lib/strings.js +2 -7
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +8 -5
- package/lib/types.js +1 -2
- package/package.json +6 -4
- package/src/classes/_pool.ts +92 -0
- package/src/classes/color-scale.ts +181 -0
- package/src/classes/frame-rate.ts +49 -0
- package/src/colors.ts +32 -19
- package/src/constants.ts +155 -155
- package/src/dom.ts +3 -3
- package/src/files.ts +1 -1
- package/src/functions.ts +27 -2
- package/src/geometry.ts +2 -2
- package/src/maths.ts +23 -12
- package/src/prng.ts +119 -0
- package/src/random.ts +24 -24
- package/src/types.ts +18 -9
- package/tsconfig.json +2 -1
- package/src/now.ts +0 -26
package/lib/constants.js
CHANGED
|
@@ -1,173 +1,170 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.W3CX11 = exports.QUARTER_PI = exports.HALF_PI = exports.TWO_PI = exports.PI = exports.EPSILON = void 0;
|
|
4
1
|
// *********************
|
|
5
2
|
// Maths
|
|
6
3
|
// *********************
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
export var EPSILON = 1e-10;
|
|
5
|
+
export var PI = Math.PI;
|
|
6
|
+
export var TWO_PI = Math.PI * 2;
|
|
7
|
+
export var HALF_PI = Math.PI / 2;
|
|
8
|
+
export var QUARTER_PI = Math.PI / 4;
|
|
12
9
|
// *********************
|
|
13
10
|
// Colors
|
|
14
11
|
// *********************
|
|
15
12
|
// X11 colors
|
|
16
13
|
// -> https://www.w3.org/TR/css-color-3/#svg-color
|
|
17
|
-
|
|
18
|
-
aliceblue:
|
|
19
|
-
antiquewhite:
|
|
20
|
-
aqua:
|
|
21
|
-
aquamarine:
|
|
22
|
-
azure:
|
|
23
|
-
beige:
|
|
24
|
-
bisque:
|
|
25
|
-
black:
|
|
26
|
-
blanchedalmond:
|
|
27
|
-
blue:
|
|
28
|
-
blueviolet:
|
|
29
|
-
brown:
|
|
30
|
-
burlywood:
|
|
31
|
-
cadetblue:
|
|
32
|
-
chartreuse:
|
|
33
|
-
chocolate:
|
|
34
|
-
coral:
|
|
35
|
-
cornflower:
|
|
36
|
-
cornflowerblue:
|
|
37
|
-
cornsilk:
|
|
38
|
-
crimson:
|
|
39
|
-
cyan:
|
|
40
|
-
darkblue:
|
|
41
|
-
darkcyan:
|
|
42
|
-
darkgoldenrod:
|
|
43
|
-
darkgray:
|
|
44
|
-
darkgreen:
|
|
45
|
-
darkgrey:
|
|
46
|
-
darkkhaki:
|
|
47
|
-
darkmagenta:
|
|
48
|
-
darkolivegreen:
|
|
49
|
-
darkorange:
|
|
50
|
-
darkorchid:
|
|
51
|
-
darkred:
|
|
52
|
-
darksalmon:
|
|
53
|
-
darkseagreen:
|
|
54
|
-
darkslateblue:
|
|
55
|
-
darkslategray:
|
|
56
|
-
darkslategrey:
|
|
57
|
-
darkturquoise:
|
|
58
|
-
darkviolet:
|
|
59
|
-
deeppink:
|
|
60
|
-
deepskyblue:
|
|
61
|
-
dimgray:
|
|
62
|
-
dimgrey:
|
|
63
|
-
dodgerblue:
|
|
64
|
-
firebrick:
|
|
65
|
-
floralwhite:
|
|
66
|
-
forestgreen:
|
|
67
|
-
fuchsia:
|
|
68
|
-
gainsboro:
|
|
69
|
-
ghostwhite:
|
|
70
|
-
gold:
|
|
71
|
-
goldenrod:
|
|
72
|
-
gray:
|
|
73
|
-
green:
|
|
74
|
-
greenyellow:
|
|
75
|
-
grey:
|
|
76
|
-
honeydew:
|
|
77
|
-
hotpink:
|
|
78
|
-
indianred:
|
|
79
|
-
indigo:
|
|
80
|
-
ivory:
|
|
81
|
-
khaki:
|
|
82
|
-
laserlemon:
|
|
83
|
-
lavender:
|
|
84
|
-
lavenderblush:
|
|
85
|
-
lawngreen:
|
|
86
|
-
lemonchiffon:
|
|
87
|
-
lightblue:
|
|
88
|
-
lightcoral:
|
|
89
|
-
lightcyan:
|
|
90
|
-
lightgoldenrod:
|
|
91
|
-
lightgoldenrodyellow:
|
|
92
|
-
lightgray:
|
|
93
|
-
lightgreen:
|
|
94
|
-
lightgrey:
|
|
95
|
-
lightpink:
|
|
96
|
-
lightsalmon:
|
|
97
|
-
lightseagreen:
|
|
98
|
-
lightskyblue:
|
|
99
|
-
lightslategray:
|
|
100
|
-
lightslategrey:
|
|
101
|
-
lightsteelblue:
|
|
102
|
-
lightyellow:
|
|
103
|
-
lime:
|
|
104
|
-
limegreen:
|
|
105
|
-
linen:
|
|
106
|
-
magenta:
|
|
107
|
-
maroon:
|
|
108
|
-
maroon2:
|
|
109
|
-
maroon3:
|
|
110
|
-
mediumaquamarine:
|
|
111
|
-
mediumblue:
|
|
112
|
-
mediumorchid:
|
|
113
|
-
mediumpurple:
|
|
114
|
-
mediumseagreen:
|
|
115
|
-
mediumslateblue:
|
|
116
|
-
mediumspringgreen:
|
|
117
|
-
mediumturquoise:
|
|
118
|
-
mediumvioletred:
|
|
119
|
-
midnightblue:
|
|
120
|
-
mintcream:
|
|
121
|
-
mistyrose:
|
|
122
|
-
moccasin:
|
|
123
|
-
navajowhite:
|
|
124
|
-
navy:
|
|
125
|
-
oldlace:
|
|
126
|
-
olive:
|
|
127
|
-
olivedrab:
|
|
128
|
-
orange:
|
|
129
|
-
orangered:
|
|
130
|
-
orchid:
|
|
131
|
-
palegoldenrod:
|
|
132
|
-
palegreen:
|
|
133
|
-
paleturquoise:
|
|
134
|
-
palevioletred:
|
|
135
|
-
papayawhip:
|
|
136
|
-
peachpuff:
|
|
137
|
-
peru:
|
|
138
|
-
pink:
|
|
139
|
-
plum:
|
|
140
|
-
powderblue:
|
|
141
|
-
purple:
|
|
142
|
-
purple2:
|
|
143
|
-
purple3:
|
|
144
|
-
rebeccapurple:
|
|
145
|
-
red:
|
|
146
|
-
rosybrown:
|
|
147
|
-
royalblue:
|
|
148
|
-
saddlebrown:
|
|
149
|
-
salmon:
|
|
150
|
-
sandybrown:
|
|
151
|
-
seagreen:
|
|
152
|
-
seashell:
|
|
153
|
-
sienna:
|
|
154
|
-
silver:
|
|
155
|
-
skyblue:
|
|
156
|
-
slateblue:
|
|
157
|
-
slategray:
|
|
158
|
-
slategrey:
|
|
159
|
-
snow:
|
|
160
|
-
springgreen:
|
|
161
|
-
steelblue:
|
|
162
|
-
tan:
|
|
163
|
-
teal:
|
|
164
|
-
thistle:
|
|
165
|
-
tomato:
|
|
166
|
-
turquoise:
|
|
167
|
-
violet:
|
|
168
|
-
wheat:
|
|
169
|
-
white:
|
|
170
|
-
whitesmoke:
|
|
171
|
-
yellow:
|
|
172
|
-
yellowgreen:
|
|
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
|
|
173
170
|
};
|
package/lib/dom.d.ts
CHANGED
|
@@ -20,6 +20,6 @@ export declare function createCanvas(width: number, height: number): {
|
|
|
20
20
|
/**
|
|
21
21
|
* Inject CSS styles in `document.head`
|
|
22
22
|
*
|
|
23
|
-
* @param {string}
|
|
23
|
+
* @param {string} styles CSS styles to inject
|
|
24
24
|
*/
|
|
25
|
-
export declare function injectStyles(
|
|
25
|
+
export declare function injectStyles(styles: string): void;
|
package/lib/dom.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.injectStyles = exports.createCanvas = exports.closest = void 0;
|
|
4
1
|
var DOCUMENT_NODE_TYPE = 9;
|
|
5
2
|
/**
|
|
6
3
|
* Find the closest parent that matches a selector
|
|
@@ -9,7 +6,7 @@ var DOCUMENT_NODE_TYPE = 9;
|
|
|
9
6
|
* @param {(Element|string)} selector Selector or parent to match
|
|
10
7
|
* @returns {Element|null}
|
|
11
8
|
*/
|
|
12
|
-
function closest(element, selector) {
|
|
9
|
+
export function closest(element, selector) {
|
|
13
10
|
var current = element;
|
|
14
11
|
while (current && current.nodeType !== DOCUMENT_NODE_TYPE) {
|
|
15
12
|
if ((typeof selector === 'string' && current.matches(selector)) || current === selector) {
|
|
@@ -19,7 +16,6 @@ function closest(element, selector) {
|
|
|
19
16
|
}
|
|
20
17
|
return current;
|
|
21
18
|
}
|
|
22
|
-
exports.closest = closest;
|
|
23
19
|
/**
|
|
24
20
|
* Create a canvas and 2d context
|
|
25
21
|
*
|
|
@@ -27,7 +23,7 @@ exports.closest = closest;
|
|
|
27
23
|
* @param {Number} height Height of the canvas
|
|
28
24
|
* @returns {{ canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D }}
|
|
29
25
|
*/
|
|
30
|
-
function createCanvas(width, height) {
|
|
26
|
+
export function createCanvas(width, height) {
|
|
31
27
|
var _a;
|
|
32
28
|
var canvas = document.createElement('canvas');
|
|
33
29
|
canvas.width = width;
|
|
@@ -35,19 +31,17 @@ function createCanvas(width, height) {
|
|
|
35
31
|
var ctx = (_a = canvas.getContext('2d')) !== null && _a !== void 0 ? _a : new CanvasRenderingContext2D();
|
|
36
32
|
return { canvas: canvas, ctx: ctx };
|
|
37
33
|
}
|
|
38
|
-
exports.createCanvas = createCanvas;
|
|
39
34
|
/**
|
|
40
35
|
* Inject CSS styles in `document.head`
|
|
41
36
|
*
|
|
42
|
-
* @param {string}
|
|
37
|
+
* @param {string} styles CSS styles to inject
|
|
43
38
|
*/
|
|
44
|
-
function injectStyles(
|
|
39
|
+
export function injectStyles(styles) {
|
|
45
40
|
var $style = document.createElement('style');
|
|
46
|
-
$style.innerHTML =
|
|
41
|
+
$style.innerHTML = styles;
|
|
47
42
|
var $before = document.querySelector('head link[rel=stylesheet], head style');
|
|
48
43
|
if ($before)
|
|
49
44
|
document.head.insertBefore($style, $before);
|
|
50
45
|
else
|
|
51
46
|
document.head.appendChild($style);
|
|
52
47
|
}
|
|
53
|
-
exports.injectStyles = injectStyles;
|
package/lib/files.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ export declare function download(blob: Blob, filename: string): void;
|
|
|
9
9
|
* Upload a file from user files
|
|
10
10
|
*
|
|
11
11
|
* @param {Function} onLoad Callback called once the file is loaded
|
|
12
|
-
* @param {string} [accept='']
|
|
12
|
+
* @param {string} [accept=''] MIME type the file input should accept
|
|
13
13
|
*/
|
|
14
14
|
export declare function upload(onLoad: (dataUrl: string) => void, accept?: string): void;
|
package/lib/files.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.upload = exports.download = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Download a Blob object into user files
|
|
6
3
|
*
|
|
7
4
|
* @param {Blob} blob Blob object to download
|
|
8
5
|
* @param {string} filename Downloaded file name
|
|
9
6
|
*/
|
|
10
|
-
function download(blob, filename) {
|
|
7
|
+
export function download(blob, filename) {
|
|
11
8
|
var link = document.createElement('a');
|
|
12
9
|
link.setAttribute('href', URL.createObjectURL(blob));
|
|
13
10
|
link.setAttribute('download', filename);
|
|
@@ -15,14 +12,13 @@ function download(blob, filename) {
|
|
|
15
12
|
link.click();
|
|
16
13
|
document.body.removeChild(link);
|
|
17
14
|
}
|
|
18
|
-
exports.download = download;
|
|
19
15
|
/**
|
|
20
16
|
* Upload a file from user files
|
|
21
17
|
*
|
|
22
18
|
* @param {Function} onLoad Callback called once the file is loaded
|
|
23
|
-
* @param {string} [accept='']
|
|
19
|
+
* @param {string} [accept=''] MIME type the file input should accept
|
|
24
20
|
*/
|
|
25
|
-
function upload(onLoad, accept) {
|
|
21
|
+
export function upload(onLoad, accept) {
|
|
26
22
|
if (accept === void 0) { accept = ''; }
|
|
27
23
|
var input = document.createElement('input');
|
|
28
24
|
input.setAttribute('type', 'file');
|
|
@@ -40,4 +36,3 @@ function upload(onLoad, accept) {
|
|
|
40
36
|
input.click();
|
|
41
37
|
document.body.removeChild(input);
|
|
42
38
|
}
|
|
43
|
-
exports.upload = upload;
|
package/lib/functions.d.ts
CHANGED
|
@@ -6,13 +6,17 @@ export declare const noop: () => void;
|
|
|
6
6
|
/**
|
|
7
7
|
* Promise wrapped setTimeout
|
|
8
8
|
*
|
|
9
|
-
* @param {number} timeout Time in
|
|
9
|
+
* @param {number} [timeout=0] Time to wait (in milliseconds)
|
|
10
10
|
* @returns {Promise}
|
|
11
11
|
*/
|
|
12
|
-
export declare function wait(timeout
|
|
12
|
+
export declare function wait(timeout?: number): Promise<void>;
|
|
13
13
|
/**
|
|
14
14
|
* Deferred promise implementation
|
|
15
15
|
*
|
|
16
16
|
* @returns {Deferred}
|
|
17
17
|
*/
|
|
18
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
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defer = exports.wait = exports.noop = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* No-op function
|
|
6
3
|
*/
|
|
7
|
-
var noop = function () { };
|
|
8
|
-
exports.noop = noop;
|
|
4
|
+
export var noop = function () { };
|
|
9
5
|
/**
|
|
10
6
|
* Promise wrapped setTimeout
|
|
11
7
|
*
|
|
12
|
-
* @param {number} timeout Time in
|
|
8
|
+
* @param {number} [timeout=0] Time to wait (in milliseconds)
|
|
13
9
|
* @returns {Promise}
|
|
14
10
|
*/
|
|
15
|
-
function wait(timeout) {
|
|
11
|
+
export function wait(timeout) {
|
|
12
|
+
if (timeout === void 0) { timeout = 0; }
|
|
16
13
|
return new Promise(function (resolve) { return setTimeout(resolve, timeout); });
|
|
17
14
|
}
|
|
18
|
-
exports.wait = wait;
|
|
19
15
|
/**
|
|
20
16
|
* Deferred promise implementation
|
|
21
17
|
*
|
|
22
18
|
* @returns {Deferred}
|
|
23
19
|
*/
|
|
24
|
-
function defer() {
|
|
20
|
+
export function defer() {
|
|
25
21
|
var resolve;
|
|
26
22
|
var reject;
|
|
27
23
|
var promise = new Promise(function (_resolve, _reject) {
|
|
@@ -30,4 +26,28 @@ function defer() {
|
|
|
30
26
|
});
|
|
31
27
|
return { promise: promise, resolve: resolve, reject: reject };
|
|
32
28
|
}
|
|
33
|
-
|
|
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
CHANGED
|
@@ -53,8 +53,8 @@ export declare function diagonal(width: number, height: number): number;
|
|
|
53
53
|
* Convert radians to a 3D point on the surface of a unit sphere
|
|
54
54
|
*
|
|
55
55
|
* @param {number} radius Radius of the sphere
|
|
56
|
-
* @param {number} phi Polar angle from the y (up) axis : 0
|
|
57
|
-
* @param {number} theta Equator angle around the y (up) axis : 0
|
|
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
58
|
* @param {Vector3} target Target vector
|
|
59
59
|
* @returns {Vector3}
|
|
60
60
|
*/
|
package/lib/geometry.js
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.contain = exports.cover = exports.radToSphere = exports.diagonal = exports.distance = exports.closestAngle = exports.angle = exports.toRadians = exports.toDegrees = void 0;
|
|
4
|
-
var constants_1 = require("./constants");
|
|
1
|
+
import { PI } from './constants';
|
|
5
2
|
/**
|
|
6
3
|
* Convert a radians value into degrees
|
|
7
4
|
*
|
|
8
5
|
* @param {number} radians Angle in radians
|
|
9
6
|
* @returns {number} Angle in degrees
|
|
10
7
|
*/
|
|
11
|
-
function toDegrees(radians) {
|
|
12
|
-
return (radians * 180) /
|
|
8
|
+
export function toDegrees(radians) {
|
|
9
|
+
return (radians * 180) / PI;
|
|
13
10
|
}
|
|
14
|
-
exports.toDegrees = toDegrees;
|
|
15
11
|
/**
|
|
16
12
|
* Convert a degrees value into radians
|
|
17
13
|
*
|
|
18
14
|
* @param {number} degrees Angle in degrees
|
|
19
15
|
* @returns {number} Angle in radians
|
|
20
16
|
*/
|
|
21
|
-
function toRadians(degrees) {
|
|
22
|
-
return (degrees *
|
|
17
|
+
export function toRadians(degrees) {
|
|
18
|
+
return (degrees * PI) / 180;
|
|
23
19
|
}
|
|
24
|
-
exports.toRadians = toRadians;
|
|
25
20
|
/**
|
|
26
21
|
* Calculate the angle from a point to another
|
|
27
22
|
*
|
|
@@ -31,10 +26,9 @@ exports.toRadians = toRadians;
|
|
|
31
26
|
* @param {number} y2 Y value of the second point
|
|
32
27
|
* @returns {number} Angle
|
|
33
28
|
*/
|
|
34
|
-
function angle(x1, y1, x2, y2) {
|
|
29
|
+
export function angle(x1, y1, x2, y2) {
|
|
35
30
|
return Math.atan2(y2 - y1, x2 - x1);
|
|
36
31
|
}
|
|
37
|
-
exports.angle = angle;
|
|
38
32
|
/**
|
|
39
33
|
* Find the closest angle between to angles
|
|
40
34
|
*
|
|
@@ -42,11 +36,10 @@ exports.angle = angle;
|
|
|
42
36
|
* @param {number} target Target angle in radians
|
|
43
37
|
* @returns {number} Closest angle
|
|
44
38
|
*/
|
|
45
|
-
function closestAngle(source, target) {
|
|
39
|
+
export function closestAngle(source, target) {
|
|
46
40
|
var delta = target - source;
|
|
47
|
-
return delta >
|
|
41
|
+
return delta > PI ? target - 2 * PI : target < -PI ? delta + 2 * PI : target;
|
|
48
42
|
}
|
|
49
|
-
exports.closestAngle = closestAngle;
|
|
50
43
|
/**
|
|
51
44
|
* Calculate the distance between two points
|
|
52
45
|
*
|
|
@@ -56,12 +49,11 @@ exports.closestAngle = closestAngle;
|
|
|
56
49
|
* @param {number} y2 Y coord of the second point
|
|
57
50
|
* @returns {number} Computed distance
|
|
58
51
|
*/
|
|
59
|
-
function distance(x1, y1, x2, y2) {
|
|
52
|
+
export function distance(x1, y1, x2, y2) {
|
|
60
53
|
var dx = x1 - x2;
|
|
61
54
|
var dy = y1 - y2;
|
|
62
55
|
return Math.sqrt(dx * dx + dy * dy);
|
|
63
56
|
}
|
|
64
|
-
exports.distance = distance;
|
|
65
57
|
/**
|
|
66
58
|
* Calculate the length of the diagonal of a rectangle
|
|
67
59
|
*
|
|
@@ -69,27 +61,25 @@ exports.distance = distance;
|
|
|
69
61
|
* @param {number} height Height of the rectangle
|
|
70
62
|
* @returns {number} Diagonal length
|
|
71
63
|
*/
|
|
72
|
-
function diagonal(width, height) {
|
|
64
|
+
export function diagonal(width, height) {
|
|
73
65
|
return Math.sqrt(width * width + height * height);
|
|
74
66
|
}
|
|
75
|
-
exports.diagonal = diagonal;
|
|
76
67
|
/**
|
|
77
68
|
* Convert radians to a 3D point on the surface of a unit sphere
|
|
78
69
|
*
|
|
79
70
|
* @param {number} radius Radius of the sphere
|
|
80
|
-
* @param {number} phi Polar angle from the y (up) axis : 0
|
|
81
|
-
* @param {number} theta Equator angle around the y (up) axis : 0
|
|
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]
|
|
82
73
|
* @param {Vector3} target Target vector
|
|
83
74
|
* @returns {Vector3}
|
|
84
75
|
*/
|
|
85
|
-
function radToSphere(radius, phi, theta, target) {
|
|
76
|
+
export function radToSphere(radius, phi, theta, target) {
|
|
86
77
|
if (target === void 0) { target = { x: 0, y: 0, z: 0 }; }
|
|
87
78
|
target.x = radius * Math.sin(phi) * Math.sin(theta);
|
|
88
79
|
target.y = radius * Math.cos(phi);
|
|
89
80
|
target.z = radius * Math.sin(phi) * Math.cos(theta);
|
|
90
81
|
return target;
|
|
91
82
|
}
|
|
92
|
-
exports.radToSphere = radToSphere;
|
|
93
83
|
/**
|
|
94
84
|
* Make a target fit a container
|
|
95
85
|
*
|
|
@@ -123,10 +113,9 @@ function fit(target, container, mode) {
|
|
|
123
113
|
* @param {FitInput} container Dimension of the container
|
|
124
114
|
* @returns {FitOutput}
|
|
125
115
|
*/
|
|
126
|
-
function cover(target, container) {
|
|
116
|
+
export function cover(target, container) {
|
|
127
117
|
return fit(target, container, 'cover');
|
|
128
118
|
}
|
|
129
|
-
exports.cover = cover;
|
|
130
119
|
/**
|
|
131
120
|
* Make a target fit a container (contain mode)
|
|
132
121
|
*
|
|
@@ -134,7 +123,6 @@ exports.cover = cover;
|
|
|
134
123
|
* @param {FitInput} container Dimension of the container
|
|
135
124
|
* @returns {FitOutput}
|
|
136
125
|
*/
|
|
137
|
-
function contain(target, container) {
|
|
126
|
+
export function contain(target, container) {
|
|
138
127
|
return fit(target, container, 'contain');
|
|
139
128
|
}
|
|
140
|
-
exports.contain = contain;
|