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/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
- exports.EPSILON = 1e-10;
8
- exports.PI = Math.PI;
9
- exports.TWO_PI = Math.PI * 2;
10
- exports.HALF_PI = Math.PI / 2;
11
- exports.QUARTER_PI = Math.PI / 4;
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
- exports.W3CX11 = {
18
- aliceblue: '#f0f8ff',
19
- antiquewhite: '#faebd7',
20
- aqua: '#00ffff',
21
- aquamarine: '#7fffd4',
22
- azure: '#f0ffff',
23
- beige: '#f5f5dc',
24
- bisque: '#ffe4c4',
25
- black: '#000000',
26
- blanchedalmond: '#ffebcd',
27
- blue: '#0000ff',
28
- blueviolet: '#8a2be2',
29
- brown: '#a52a2a',
30
- burlywood: '#deb887',
31
- cadetblue: '#5f9ea0',
32
- chartreuse: '#7fff00',
33
- chocolate: '#d2691e',
34
- coral: '#ff7f50',
35
- cornflower: '#6495ed',
36
- cornflowerblue: '#6495ed',
37
- cornsilk: '#fff8dc',
38
- crimson: '#dc143c',
39
- cyan: '#00ffff',
40
- darkblue: '#00008b',
41
- darkcyan: '#008b8b',
42
- darkgoldenrod: '#b8860b',
43
- darkgray: '#a9a9a9',
44
- darkgreen: '#006400',
45
- darkgrey: '#a9a9a9',
46
- darkkhaki: '#bdb76b',
47
- darkmagenta: '#8b008b',
48
- darkolivegreen: '#556b2f',
49
- darkorange: '#ff8c00',
50
- darkorchid: '#9932cc',
51
- darkred: '#8b0000',
52
- darksalmon: '#e9967a',
53
- darkseagreen: '#8fbc8f',
54
- darkslateblue: '#483d8b',
55
- darkslategray: '#2f4f4f',
56
- darkslategrey: '#2f4f4f',
57
- darkturquoise: '#00ced1',
58
- darkviolet: '#9400d3',
59
- deeppink: '#ff1493',
60
- deepskyblue: '#00bfff',
61
- dimgray: '#696969',
62
- dimgrey: '#696969',
63
- dodgerblue: '#1e90ff',
64
- firebrick: '#b22222',
65
- floralwhite: '#fffaf0',
66
- forestgreen: '#228b22',
67
- fuchsia: '#ff00ff',
68
- gainsboro: '#dcdcdc',
69
- ghostwhite: '#f8f8ff',
70
- gold: '#ffd700',
71
- goldenrod: '#daa520',
72
- gray: '#808080',
73
- green: '#008000',
74
- greenyellow: '#adff2f',
75
- grey: '#808080',
76
- honeydew: '#f0fff0',
77
- hotpink: '#ff69b4',
78
- indianred: '#cd5c5c',
79
- indigo: '#4b0082',
80
- ivory: '#fffff0',
81
- khaki: '#f0e68c',
82
- laserlemon: '#ffff54',
83
- lavender: '#e6e6fa',
84
- lavenderblush: '#fff0f5',
85
- lawngreen: '#7cfc00',
86
- lemonchiffon: '#fffacd',
87
- lightblue: '#add8e6',
88
- lightcoral: '#f08080',
89
- lightcyan: '#e0ffff',
90
- lightgoldenrod: '#fafad2',
91
- lightgoldenrodyellow: '#fafad2',
92
- lightgray: '#d3d3d3',
93
- lightgreen: '#90ee90',
94
- lightgrey: '#d3d3d3',
95
- lightpink: '#ffb6c1',
96
- lightsalmon: '#ffa07a',
97
- lightseagreen: '#20b2aa',
98
- lightskyblue: '#87cefa',
99
- lightslategray: '#778899',
100
- lightslategrey: '#778899',
101
- lightsteelblue: '#b0c4de',
102
- lightyellow: '#ffffe0',
103
- lime: '#00ff00',
104
- limegreen: '#32cd32',
105
- linen: '#faf0e6',
106
- magenta: '#ff00ff',
107
- maroon: '#800000',
108
- maroon2: '#7f0000',
109
- maroon3: '#b03060',
110
- mediumaquamarine: '#66cdaa',
111
- mediumblue: '#0000cd',
112
- mediumorchid: '#ba55d3',
113
- mediumpurple: '#9370db',
114
- mediumseagreen: '#3cb371',
115
- mediumslateblue: '#7b68ee',
116
- mediumspringgreen: '#00fa9a',
117
- mediumturquoise: '#48d1cc',
118
- mediumvioletred: '#c71585',
119
- midnightblue: '#191970',
120
- mintcream: '#f5fffa',
121
- mistyrose: '#ffe4e1',
122
- moccasin: '#ffe4b5',
123
- navajowhite: '#ffdead',
124
- navy: '#000080',
125
- oldlace: '#fdf5e6',
126
- olive: '#808000',
127
- olivedrab: '#6b8e23',
128
- orange: '#ffa500',
129
- orangered: '#ff4500',
130
- orchid: '#da70d6',
131
- palegoldenrod: '#eee8aa',
132
- palegreen: '#98fb98',
133
- paleturquoise: '#afeeee',
134
- palevioletred: '#db7093',
135
- papayawhip: '#ffefd5',
136
- peachpuff: '#ffdab9',
137
- peru: '#cd853f',
138
- pink: '#ffc0cb',
139
- plum: '#dda0dd',
140
- powderblue: '#b0e0e6',
141
- purple: '#800080',
142
- purple2: '#7f007f',
143
- purple3: '#a020f0',
144
- rebeccapurple: '#663399',
145
- red: '#ff0000',
146
- rosybrown: '#bc8f8f',
147
- royalblue: '#4169e1',
148
- saddlebrown: '#8b4513',
149
- salmon: '#fa8072',
150
- sandybrown: '#f4a460',
151
- seagreen: '#2e8b57',
152
- seashell: '#fff5ee',
153
- sienna: '#a0522d',
154
- silver: '#c0c0c0',
155
- skyblue: '#87ceeb',
156
- slateblue: '#6a5acd',
157
- slategray: '#708090',
158
- slategrey: '#708090',
159
- snow: '#fffafa',
160
- springgreen: '#00ff7f',
161
- steelblue: '#4682b4',
162
- tan: '#d2b48c',
163
- teal: '#008080',
164
- thistle: '#d8bfd8',
165
- tomato: '#ff6347',
166
- turquoise: '#40e0d0',
167
- violet: '#ee82ee',
168
- wheat: '#f5deb3',
169
- white: '#ffffff',
170
- whitesmoke: '#f5f5f5',
171
- yellow: '#ffff00',
172
- yellowgreen: '#9acd32'
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} cssContent CSS style to inject
23
+ * @param {string} styles CSS styles to inject
24
24
  */
25
- export declare function injectStyles(cssContent: string): void;
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} cssContent CSS style to inject
37
+ * @param {string} styles CSS styles to inject
43
38
  */
44
- function injectStyles(cssContent) {
39
+ export function injectStyles(styles) {
45
40
  var $style = document.createElement('style');
46
- $style.innerHTML = cssContent;
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=''] Types the file input should 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=''] Types the file input should 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;
@@ -6,13 +6,17 @@ export declare const noop: () => void;
6
6
  /**
7
7
  * Promise wrapped setTimeout
8
8
  *
9
- * @param {number} timeout Time in ms
9
+ * @param {number} [timeout=0] Time to wait (in milliseconds)
10
10
  * @returns {Promise}
11
11
  */
12
- export declare function wait(timeout: number): Promise<void>;
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 ms
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
- exports.defer = defer;
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 to PI
57
- * @param {number} theta Equator angle around the y (up) axis : 0 to 2 PI
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
- "use strict";
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) / constants_1.PI;
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 * constants_1.PI) / 180;
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 > constants_1.PI ? target - 2 * constants_1.PI : target < -constants_1.PI ? delta + 2 * constants_1.PI : target;
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 to PI
81
- * @param {number} theta Equator angle around the y (up) axis : 0 to 2 PI
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;