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
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { lerp, triLerp } from '../maths';
|
|
2
|
+
import { hclToRgb, hsbToRgb, hslToRgb, normalizeColor, rgbToHcl, rgbToHsb, rgbToHsl } from '../colors';
|
|
3
|
+
import { ColorRepresentation } from '../types';
|
|
4
|
+
|
|
5
|
+
export type ColorScaleSettings =
|
|
6
|
+
| {
|
|
7
|
+
colorSpace: 'rgb' | 'hsl' | 'hsb';
|
|
8
|
+
}
|
|
9
|
+
| {
|
|
10
|
+
colorSpace: 'hcl';
|
|
11
|
+
mode?: 'qualitative' | 'sequential' | 'diverging';
|
|
12
|
+
triangular?: number;
|
|
13
|
+
powerStrength?: number;
|
|
14
|
+
hueOffset?: number;
|
|
15
|
+
chromaOffset?: number;
|
|
16
|
+
luminanceOffset?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const defaultSettings: Required<ColorScaleSettings> = {
|
|
20
|
+
colorSpace: 'rgb'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Utility class for generating color scales and interpolating between colors
|
|
25
|
+
*
|
|
26
|
+
* @exports
|
|
27
|
+
* @class ColorScale
|
|
28
|
+
*/
|
|
29
|
+
export default class ColorScale {
|
|
30
|
+
/**
|
|
31
|
+
* Array of colors composing the color scale
|
|
32
|
+
*/
|
|
33
|
+
public colors: Array<[number, number, number]> = [];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {ColorRepresentation} input Input color representation
|
|
37
|
+
* @param {ColorRepresentation} target Target color representation
|
|
38
|
+
* @param {number} [length=5] Amount of colors composing the color scale
|
|
39
|
+
* @param {ColorScaleSettings} [settings] Color scale generation settings
|
|
40
|
+
*/
|
|
41
|
+
constructor(
|
|
42
|
+
input: ColorRepresentation,
|
|
43
|
+
target: ColorRepresentation,
|
|
44
|
+
length: number = 5,
|
|
45
|
+
settings: ColorScaleSettings = { ...defaultSettings }
|
|
46
|
+
) {
|
|
47
|
+
this.colors = ColorScale.generate(input, target, length, settings);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Static method for generating a color scale
|
|
52
|
+
*
|
|
53
|
+
* @param {ColorRepresentation} input Input color representation
|
|
54
|
+
* @param {ColorRepresentation} target Target color representation
|
|
55
|
+
* @param {number} length Amount of colors composing the color scale
|
|
56
|
+
* @param {ColorScaleSettings} [settings] Color scale generation settings
|
|
57
|
+
* @returns {Array<[number, number, number]>} Color scale colors
|
|
58
|
+
*/
|
|
59
|
+
static generate(
|
|
60
|
+
input: ColorRepresentation,
|
|
61
|
+
target: ColorRepresentation,
|
|
62
|
+
length: number,
|
|
63
|
+
settings: ColorScaleSettings = { ...defaultSettings }
|
|
64
|
+
): Array<[number, number, number]> {
|
|
65
|
+
const colors: Array<[number, number, number]> = [];
|
|
66
|
+
|
|
67
|
+
const inputColor = normalizeColor(input);
|
|
68
|
+
const targetColor = normalizeColor(target);
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < length; i++) {
|
|
71
|
+
const value = i / Math.floor(length);
|
|
72
|
+
colors.push(ColorScale.interpolate(inputColor, targetColor, value, settings));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return colors;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Static method for interpolating between colors
|
|
80
|
+
*
|
|
81
|
+
* @param {[number,number,number]} inputColor Input color
|
|
82
|
+
* @param {[number,number,number]} targetColor Target color
|
|
83
|
+
* @param {number} value Interpolation normalized value
|
|
84
|
+
* @param {ColorScaleSettings} [settings] Color scale settings
|
|
85
|
+
* @returns {[number,number,number]} Interpolated color
|
|
86
|
+
*/
|
|
87
|
+
static interpolate(
|
|
88
|
+
inputColor: [number, number, number],
|
|
89
|
+
targetColor: [number, number, number],
|
|
90
|
+
value: number,
|
|
91
|
+
settings: ColorScaleSettings = { ...defaultSettings }
|
|
92
|
+
): [number, number, number] {
|
|
93
|
+
switch (settings.colorSpace) {
|
|
94
|
+
case 'rgb': {
|
|
95
|
+
const r = lerp(value, inputColor[0], targetColor[0]);
|
|
96
|
+
const g = lerp(value, inputColor[1], targetColor[1]);
|
|
97
|
+
const b = lerp(value, inputColor[2], targetColor[2]);
|
|
98
|
+
return [r, g, b];
|
|
99
|
+
}
|
|
100
|
+
case 'hsl': {
|
|
101
|
+
const inputHsl = rgbToHsl(inputColor);
|
|
102
|
+
const targetHsl = rgbToHsl(targetColor);
|
|
103
|
+
const h = lerp(value, inputHsl[0], targetHsl[0]);
|
|
104
|
+
const s = lerp(value, inputHsl[1], targetHsl[1]);
|
|
105
|
+
const l = lerp(value, inputHsl[2], targetHsl[2]);
|
|
106
|
+
return hslToRgb([h, s, l]);
|
|
107
|
+
}
|
|
108
|
+
case 'hsb': {
|
|
109
|
+
const inputHsb = rgbToHsb(inputColor);
|
|
110
|
+
const targetHsb = rgbToHsb(targetColor);
|
|
111
|
+
const h = lerp(value, inputHsb[0], targetHsb[0]);
|
|
112
|
+
const s = lerp(value, inputHsb[1], targetHsb[1]);
|
|
113
|
+
const b = lerp(value, inputHsb[2], targetHsb[2]);
|
|
114
|
+
return hsbToRgb([h, s, b]);
|
|
115
|
+
}
|
|
116
|
+
case 'hcl':
|
|
117
|
+
const inputHcl = rgbToHcl(inputColor);
|
|
118
|
+
const targetHcl = rgbToHcl(targetColor);
|
|
119
|
+
const powerValue = Math.pow(value, settings.powerStrength ?? 1);
|
|
120
|
+
|
|
121
|
+
const h1 = inputHcl[0];
|
|
122
|
+
const c1 = inputHcl[1];
|
|
123
|
+
const l1 = inputHcl[2];
|
|
124
|
+
const h2 = targetHcl[0] + (settings.hueOffset ?? 0);
|
|
125
|
+
const c2 = targetHcl[1] + (settings.chromaOffset ?? 0);
|
|
126
|
+
const l2 = targetHcl[2] + (settings.luminanceOffset ?? 0);
|
|
127
|
+
|
|
128
|
+
let h, c, l;
|
|
129
|
+
|
|
130
|
+
// HCL color palettes
|
|
131
|
+
// -> https://colorspace.r-forge.r-project.org/articles/hcl_palettes.html
|
|
132
|
+
if (settings.mode === 'qualitative') {
|
|
133
|
+
/**
|
|
134
|
+
* Qualitative
|
|
135
|
+
* Designed for coding categorical information,
|
|
136
|
+
* where no particular ordering of categories is available
|
|
137
|
+
* and every color should receive the same perceptual weight.
|
|
138
|
+
*
|
|
139
|
+
* - Hue: Linear
|
|
140
|
+
* - Chroma: Constant
|
|
141
|
+
* - Luminance: Constant
|
|
142
|
+
*/
|
|
143
|
+
h = lerp(value, h1, h2);
|
|
144
|
+
c = c1;
|
|
145
|
+
l = l1;
|
|
146
|
+
} else if (settings.mode === 'sequential') {
|
|
147
|
+
/**
|
|
148
|
+
* Sequential
|
|
149
|
+
* Designed for coding ordered/numeric information,
|
|
150
|
+
* going from high to low (or vice versa).
|
|
151
|
+
*
|
|
152
|
+
* - Hue: Constant | Linear
|
|
153
|
+
* - Chroma: Linear (+power) | Triangular (+power)
|
|
154
|
+
* - Luminance: Linear (+power)
|
|
155
|
+
*/
|
|
156
|
+
h = lerp(value, h1, h2);
|
|
157
|
+
c = settings.triangular ? triLerp(powerValue, c1, c2, settings.triangular) : lerp(powerValue, c1, c2);
|
|
158
|
+
l = lerp(powerValue, l1, l2);
|
|
159
|
+
} else if (settings.mode === 'diverging') {
|
|
160
|
+
/**
|
|
161
|
+
* Diverging
|
|
162
|
+
* Designed for coding ordered/numeric information around a central neutral value,
|
|
163
|
+
* where colors diverge from neutral to two extremes.
|
|
164
|
+
*
|
|
165
|
+
* - Hue: Constants (x2)
|
|
166
|
+
* - Chroma: Linear (+power) | Triangular (+power)
|
|
167
|
+
* - Luminance: Linear (+power)
|
|
168
|
+
*/
|
|
169
|
+
h = value < 0.5 ? h1 : value > 0.5 ? h2 : lerp(0.5, h1, h2);
|
|
170
|
+
c = settings.triangular ? triLerp(powerValue, c1, c2, settings.triangular) : lerp(powerValue, c1, c2);
|
|
171
|
+
l = lerp(powerValue, l1, l2);
|
|
172
|
+
} else {
|
|
173
|
+
h = lerp(value, h1, h2);
|
|
174
|
+
c = lerp(value, c1, c2);
|
|
175
|
+
l = lerp(value, l1, l2);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return hclToRgb([h, c, l]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { now } from '../functions';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Utility class for controlling FPS calls
|
|
5
|
+
*
|
|
6
|
+
* @exports
|
|
7
|
+
* @class FrameRate
|
|
8
|
+
*/
|
|
9
|
+
export default class FrameRate {
|
|
10
|
+
private _fps: number;
|
|
11
|
+
private interval = 0;
|
|
12
|
+
private time = 0;
|
|
13
|
+
private elapsedTime = 0;
|
|
14
|
+
private lastUpdate = 0;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {number} [fps=30] Frame per second limit
|
|
18
|
+
*/
|
|
19
|
+
constructor(fps: number = 30) {
|
|
20
|
+
this._fps = fps;
|
|
21
|
+
this.fps = fps;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Return true if elapsed time since last update is higher than current FPS
|
|
26
|
+
*
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
update(): boolean {
|
|
30
|
+
this.time = now();
|
|
31
|
+
this.elapsedTime = this.time - this.lastUpdate;
|
|
32
|
+
|
|
33
|
+
if (this.elapsedTime < this.interval) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.lastUpdate = this.time - (this.elapsedTime % this.interval);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get fps(): number {
|
|
42
|
+
return this._fps;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
set fps(fps: number) {
|
|
46
|
+
this._fps = fps;
|
|
47
|
+
this.interval = 1000 / fps;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/colors.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
import { W3CX11 } from './constants';
|
|
1
2
|
import { toDegrees, toRadians } from './geometry';
|
|
2
3
|
import { clamp } from './maths';
|
|
4
|
+
import { ColorName, ColorRepresentation } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Normalize a color representation into RGB
|
|
8
|
+
*
|
|
9
|
+
* @param {ColorRepresentation} color Color representation
|
|
10
|
+
* @returns {[number,number,number]} Normalized RGB color
|
|
11
|
+
*/
|
|
12
|
+
export function normalizeColor(color: ColorRepresentation): [number, number, number] {
|
|
13
|
+
if (typeof color === 'string') {
|
|
14
|
+
return hexToRgb(W3CX11[color as ColorName] ?? color);
|
|
15
|
+
} else if (typeof color === 'number') {
|
|
16
|
+
return hexToRgb(color);
|
|
17
|
+
} else {
|
|
18
|
+
return color;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
3
21
|
|
|
4
22
|
// ******************************************
|
|
5
23
|
// RGB & Hexadecimal color spaces
|
|
@@ -8,7 +26,7 @@ import { clamp } from './maths';
|
|
|
8
26
|
/**
|
|
9
27
|
* Normalize an hexadecimal string
|
|
10
28
|
*
|
|
11
|
-
* @param
|
|
29
|
+
* @param {string} hex Hexadecimal string
|
|
12
30
|
* @returns {string} Normalized hexadecimal string
|
|
13
31
|
*/
|
|
14
32
|
export function normalizeHexString(hex: string): string {
|
|
@@ -49,11 +67,11 @@ export function rgbToHex([r, g, b]: [number, number, number]): number {
|
|
|
49
67
|
* @returns {string} Hexadecimal string
|
|
50
68
|
*/
|
|
51
69
|
export function rgbToHexString([r, g, b]: [number, number, number]): string {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
r = clamp(Math.round(r * 255), 0, 255);
|
|
71
|
+
g = clamp(Math.round(g * 255), 0, 255);
|
|
72
|
+
b = clamp(Math.round(b * 255), 0, 255);
|
|
55
73
|
|
|
56
|
-
const result = (
|
|
74
|
+
const result = (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1);
|
|
57
75
|
return `#${result}`;
|
|
58
76
|
}
|
|
59
77
|
|
|
@@ -72,11 +90,11 @@ export function hexToRgb(hex: number | string): [number, number, number] {
|
|
|
72
90
|
hex = parseInt(hex, 16);
|
|
73
91
|
}
|
|
74
92
|
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
93
|
+
const r = ((hex >> 16) & 255) / 255;
|
|
94
|
+
const g = ((hex >> 8) & 255) / 255;
|
|
95
|
+
const b = (hex & 255) / 255;
|
|
78
96
|
|
|
79
|
-
return [
|
|
97
|
+
return [r, g, b];
|
|
80
98
|
}
|
|
81
99
|
|
|
82
100
|
/**
|
|
@@ -96,14 +114,9 @@ export function lighten(hex: string, amount: number = 0): string {
|
|
|
96
114
|
|
|
97
115
|
const value = parseInt(hex, 16);
|
|
98
116
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
let b = ((value >> 8) & 0x00ff) + amount;
|
|
103
|
-
b = clamp(b, 0, 255);
|
|
104
|
-
|
|
105
|
-
let g = (value & 0x0000ff) + amount;
|
|
106
|
-
g = clamp(g, 0, 255);
|
|
117
|
+
const r = clamp((value >> 16) + amount, 0, 255);
|
|
118
|
+
const b = clamp(((value >> 8) & 0x00ff) + amount, 0, 255);
|
|
119
|
+
const g = clamp((value & 0x0000ff) + amount, 0, 255);
|
|
107
120
|
|
|
108
121
|
let result: number | string = g | (b << 8) | (r << 16);
|
|
109
122
|
if (r === 0 && g === 0 && b === 0 && amount !== 0) {
|
|
@@ -136,8 +149,8 @@ export function darken(hex: string, amount: number = 0): string {
|
|
|
136
149
|
* @returns {[number, number, number]} Normalized HSL color
|
|
137
150
|
*/
|
|
138
151
|
export function normalizeHslString(hsl: string): [number, number, number] {
|
|
139
|
-
const [
|
|
140
|
-
return [
|
|
152
|
+
const [h, s, l] = hsl.match(/\d+/g)?.map(Number) ?? [0, 0, 0];
|
|
153
|
+
return [h, s / 100, l / 100];
|
|
141
154
|
}
|
|
142
155
|
|
|
143
156
|
/**
|
package/src/constants.ts
CHANGED
|
@@ -14,159 +14,159 @@ export const QUARTER_PI = Math.PI / 4;
|
|
|
14
14
|
// X11 colors
|
|
15
15
|
// -> https://www.w3.org/TR/css-color-3/#svg-color
|
|
16
16
|
export const W3CX11 = {
|
|
17
|
-
aliceblue:
|
|
18
|
-
antiquewhite:
|
|
19
|
-
aqua:
|
|
20
|
-
aquamarine:
|
|
21
|
-
azure:
|
|
22
|
-
beige:
|
|
23
|
-
bisque:
|
|
24
|
-
black:
|
|
25
|
-
blanchedalmond:
|
|
26
|
-
blue:
|
|
27
|
-
blueviolet:
|
|
28
|
-
brown:
|
|
29
|
-
burlywood:
|
|
30
|
-
cadetblue:
|
|
31
|
-
chartreuse:
|
|
32
|
-
chocolate:
|
|
33
|
-
coral:
|
|
34
|
-
cornflower:
|
|
35
|
-
cornflowerblue:
|
|
36
|
-
cornsilk:
|
|
37
|
-
crimson:
|
|
38
|
-
cyan:
|
|
39
|
-
darkblue:
|
|
40
|
-
darkcyan:
|
|
41
|
-
darkgoldenrod:
|
|
42
|
-
darkgray:
|
|
43
|
-
darkgreen:
|
|
44
|
-
darkgrey:
|
|
45
|
-
darkkhaki:
|
|
46
|
-
darkmagenta:
|
|
47
|
-
darkolivegreen:
|
|
48
|
-
darkorange:
|
|
49
|
-
darkorchid:
|
|
50
|
-
darkred:
|
|
51
|
-
darksalmon:
|
|
52
|
-
darkseagreen:
|
|
53
|
-
darkslateblue:
|
|
54
|
-
darkslategray:
|
|
55
|
-
darkslategrey:
|
|
56
|
-
darkturquoise:
|
|
57
|
-
darkviolet:
|
|
58
|
-
deeppink:
|
|
59
|
-
deepskyblue:
|
|
60
|
-
dimgray:
|
|
61
|
-
dimgrey:
|
|
62
|
-
dodgerblue:
|
|
63
|
-
firebrick:
|
|
64
|
-
floralwhite:
|
|
65
|
-
forestgreen:
|
|
66
|
-
fuchsia:
|
|
67
|
-
gainsboro:
|
|
68
|
-
ghostwhite:
|
|
69
|
-
gold:
|
|
70
|
-
goldenrod:
|
|
71
|
-
gray:
|
|
72
|
-
green:
|
|
73
|
-
greenyellow:
|
|
74
|
-
grey:
|
|
75
|
-
honeydew:
|
|
76
|
-
hotpink:
|
|
77
|
-
indianred:
|
|
78
|
-
indigo:
|
|
79
|
-
ivory:
|
|
80
|
-
khaki:
|
|
81
|
-
laserlemon:
|
|
82
|
-
lavender:
|
|
83
|
-
lavenderblush:
|
|
84
|
-
lawngreen:
|
|
85
|
-
lemonchiffon:
|
|
86
|
-
lightblue:
|
|
87
|
-
lightcoral:
|
|
88
|
-
lightcyan:
|
|
89
|
-
lightgoldenrod:
|
|
90
|
-
lightgoldenrodyellow:
|
|
91
|
-
lightgray:
|
|
92
|
-
lightgreen:
|
|
93
|
-
lightgrey:
|
|
94
|
-
lightpink:
|
|
95
|
-
lightsalmon:
|
|
96
|
-
lightseagreen:
|
|
97
|
-
lightskyblue:
|
|
98
|
-
lightslategray:
|
|
99
|
-
lightslategrey:
|
|
100
|
-
lightsteelblue:
|
|
101
|
-
lightyellow:
|
|
102
|
-
lime:
|
|
103
|
-
limegreen:
|
|
104
|
-
linen:
|
|
105
|
-
magenta:
|
|
106
|
-
maroon:
|
|
107
|
-
maroon2:
|
|
108
|
-
maroon3:
|
|
109
|
-
mediumaquamarine:
|
|
110
|
-
mediumblue:
|
|
111
|
-
mediumorchid:
|
|
112
|
-
mediumpurple:
|
|
113
|
-
mediumseagreen:
|
|
114
|
-
mediumslateblue:
|
|
115
|
-
mediumspringgreen:
|
|
116
|
-
mediumturquoise:
|
|
117
|
-
mediumvioletred:
|
|
118
|
-
midnightblue:
|
|
119
|
-
mintcream:
|
|
120
|
-
mistyrose:
|
|
121
|
-
moccasin:
|
|
122
|
-
navajowhite:
|
|
123
|
-
navy:
|
|
124
|
-
oldlace:
|
|
125
|
-
olive:
|
|
126
|
-
olivedrab:
|
|
127
|
-
orange:
|
|
128
|
-
orangered:
|
|
129
|
-
orchid:
|
|
130
|
-
palegoldenrod:
|
|
131
|
-
palegreen:
|
|
132
|
-
paleturquoise:
|
|
133
|
-
palevioletred:
|
|
134
|
-
papayawhip:
|
|
135
|
-
peachpuff:
|
|
136
|
-
peru:
|
|
137
|
-
pink:
|
|
138
|
-
plum:
|
|
139
|
-
powderblue:
|
|
140
|
-
purple:
|
|
141
|
-
purple2:
|
|
142
|
-
purple3:
|
|
143
|
-
rebeccapurple:
|
|
144
|
-
red:
|
|
145
|
-
rosybrown:
|
|
146
|
-
royalblue:
|
|
147
|
-
saddlebrown:
|
|
148
|
-
salmon:
|
|
149
|
-
sandybrown:
|
|
150
|
-
seagreen:
|
|
151
|
-
seashell:
|
|
152
|
-
sienna:
|
|
153
|
-
silver:
|
|
154
|
-
skyblue:
|
|
155
|
-
slateblue:
|
|
156
|
-
slategray:
|
|
157
|
-
slategrey:
|
|
158
|
-
snow:
|
|
159
|
-
springgreen:
|
|
160
|
-
steelblue:
|
|
161
|
-
tan:
|
|
162
|
-
teal:
|
|
163
|
-
thistle:
|
|
164
|
-
tomato:
|
|
165
|
-
turquoise:
|
|
166
|
-
violet:
|
|
167
|
-
wheat:
|
|
168
|
-
white:
|
|
169
|
-
whitesmoke:
|
|
170
|
-
yellow:
|
|
171
|
-
yellowgreen:
|
|
17
|
+
aliceblue: 0xf0f8ff,
|
|
18
|
+
antiquewhite: 0xfaebd7,
|
|
19
|
+
aqua: 0x00ffff,
|
|
20
|
+
aquamarine: 0x7fffd4,
|
|
21
|
+
azure: 0xf0ffff,
|
|
22
|
+
beige: 0xf5f5dc,
|
|
23
|
+
bisque: 0xffe4c4,
|
|
24
|
+
black: 0x000000,
|
|
25
|
+
blanchedalmond: 0xffebcd,
|
|
26
|
+
blue: 0x0000ff,
|
|
27
|
+
blueviolet: 0x8a2be2,
|
|
28
|
+
brown: 0xa52a2a,
|
|
29
|
+
burlywood: 0xdeb887,
|
|
30
|
+
cadetblue: 0x5f9ea0,
|
|
31
|
+
chartreuse: 0x7fff00,
|
|
32
|
+
chocolate: 0xd2691e,
|
|
33
|
+
coral: 0xff7f50,
|
|
34
|
+
cornflower: 0x6495ed,
|
|
35
|
+
cornflowerblue: 0x6495ed,
|
|
36
|
+
cornsilk: 0xfff8dc,
|
|
37
|
+
crimson: 0xdc143c,
|
|
38
|
+
cyan: 0x00ffff,
|
|
39
|
+
darkblue: 0x00008b,
|
|
40
|
+
darkcyan: 0x008b8b,
|
|
41
|
+
darkgoldenrod: 0xb8860b,
|
|
42
|
+
darkgray: 0xa9a9a9,
|
|
43
|
+
darkgreen: 0x006400,
|
|
44
|
+
darkgrey: 0xa9a9a9,
|
|
45
|
+
darkkhaki: 0xbdb76b,
|
|
46
|
+
darkmagenta: 0x8b008b,
|
|
47
|
+
darkolivegreen: 0x556b2f,
|
|
48
|
+
darkorange: 0xff8c00,
|
|
49
|
+
darkorchid: 0x9932cc,
|
|
50
|
+
darkred: 0x8b0000,
|
|
51
|
+
darksalmon: 0xe9967a,
|
|
52
|
+
darkseagreen: 0x8fbc8f,
|
|
53
|
+
darkslateblue: 0x483d8b,
|
|
54
|
+
darkslategray: 0x2f4f4f,
|
|
55
|
+
darkslategrey: 0x2f4f4f,
|
|
56
|
+
darkturquoise: 0x00ced1,
|
|
57
|
+
darkviolet: 0x9400d3,
|
|
58
|
+
deeppink: 0xff1493,
|
|
59
|
+
deepskyblue: 0x00bfff,
|
|
60
|
+
dimgray: 0x696969,
|
|
61
|
+
dimgrey: 0x696969,
|
|
62
|
+
dodgerblue: 0x1e90ff,
|
|
63
|
+
firebrick: 0xb22222,
|
|
64
|
+
floralwhite: 0xfffaf0,
|
|
65
|
+
forestgreen: 0x228b22,
|
|
66
|
+
fuchsia: 0xff00ff,
|
|
67
|
+
gainsboro: 0xdcdcdc,
|
|
68
|
+
ghostwhite: 0xf8f8ff,
|
|
69
|
+
gold: 0xffd700,
|
|
70
|
+
goldenrod: 0xdaa520,
|
|
71
|
+
gray: 0x808080,
|
|
72
|
+
green: 0x008000,
|
|
73
|
+
greenyellow: 0xadff2f,
|
|
74
|
+
grey: 0x808080,
|
|
75
|
+
honeydew: 0xf0fff0,
|
|
76
|
+
hotpink: 0xff69b4,
|
|
77
|
+
indianred: 0xcd5c5c,
|
|
78
|
+
indigo: 0x4b0082,
|
|
79
|
+
ivory: 0xfffff0,
|
|
80
|
+
khaki: 0xf0e68c,
|
|
81
|
+
laserlemon: 0xffff54,
|
|
82
|
+
lavender: 0xe6e6fa,
|
|
83
|
+
lavenderblush: 0xfff0f5,
|
|
84
|
+
lawngreen: 0x7cfc00,
|
|
85
|
+
lemonchiffon: 0xfffacd,
|
|
86
|
+
lightblue: 0xadd8e6,
|
|
87
|
+
lightcoral: 0xf08080,
|
|
88
|
+
lightcyan: 0xe0ffff,
|
|
89
|
+
lightgoldenrod: 0xfafad2,
|
|
90
|
+
lightgoldenrodyellow: 0xfafad2,
|
|
91
|
+
lightgray: 0xd3d3d3,
|
|
92
|
+
lightgreen: 0x90ee90,
|
|
93
|
+
lightgrey: 0xd3d3d3,
|
|
94
|
+
lightpink: 0xffb6c1,
|
|
95
|
+
lightsalmon: 0xffa07a,
|
|
96
|
+
lightseagreen: 0x20b2aa,
|
|
97
|
+
lightskyblue: 0x87cefa,
|
|
98
|
+
lightslategray: 0x778899,
|
|
99
|
+
lightslategrey: 0x778899,
|
|
100
|
+
lightsteelblue: 0xb0c4de,
|
|
101
|
+
lightyellow: 0xffffe0,
|
|
102
|
+
lime: 0x00ff00,
|
|
103
|
+
limegreen: 0x32cd32,
|
|
104
|
+
linen: 0xfaf0e6,
|
|
105
|
+
magenta: 0xff00ff,
|
|
106
|
+
maroon: 0x800000,
|
|
107
|
+
maroon2: 0x7f0000,
|
|
108
|
+
maroon3: 0xb03060,
|
|
109
|
+
mediumaquamarine: 0x66cdaa,
|
|
110
|
+
mediumblue: 0x0000cd,
|
|
111
|
+
mediumorchid: 0xba55d3,
|
|
112
|
+
mediumpurple: 0x9370db,
|
|
113
|
+
mediumseagreen: 0x3cb371,
|
|
114
|
+
mediumslateblue: 0x7b68ee,
|
|
115
|
+
mediumspringgreen: 0x00fa9a,
|
|
116
|
+
mediumturquoise: 0x48d1cc,
|
|
117
|
+
mediumvioletred: 0xc71585,
|
|
118
|
+
midnightblue: 0x191970,
|
|
119
|
+
mintcream: 0xf5fffa,
|
|
120
|
+
mistyrose: 0xffe4e1,
|
|
121
|
+
moccasin: 0xffe4b5,
|
|
122
|
+
navajowhite: 0xffdead,
|
|
123
|
+
navy: 0x000080,
|
|
124
|
+
oldlace: 0xfdf5e6,
|
|
125
|
+
olive: 0x808000,
|
|
126
|
+
olivedrab: 0x6b8e23,
|
|
127
|
+
orange: 0xffa500,
|
|
128
|
+
orangered: 0xff4500,
|
|
129
|
+
orchid: 0xda70d6,
|
|
130
|
+
palegoldenrod: 0xeee8aa,
|
|
131
|
+
palegreen: 0x98fb98,
|
|
132
|
+
paleturquoise: 0xafeeee,
|
|
133
|
+
palevioletred: 0xdb7093,
|
|
134
|
+
papayawhip: 0xffefd5,
|
|
135
|
+
peachpuff: 0xffdab9,
|
|
136
|
+
peru: 0xcd853f,
|
|
137
|
+
pink: 0xffc0cb,
|
|
138
|
+
plum: 0xdda0dd,
|
|
139
|
+
powderblue: 0xb0e0e6,
|
|
140
|
+
purple: 0x800080,
|
|
141
|
+
purple2: 0x7f007f,
|
|
142
|
+
purple3: 0xa020f0,
|
|
143
|
+
rebeccapurple: 0x663399,
|
|
144
|
+
red: 0xff0000,
|
|
145
|
+
rosybrown: 0xbc8f8f,
|
|
146
|
+
royalblue: 0x4169e1,
|
|
147
|
+
saddlebrown: 0x8b4513,
|
|
148
|
+
salmon: 0xfa8072,
|
|
149
|
+
sandybrown: 0xf4a460,
|
|
150
|
+
seagreen: 0x2e8b57,
|
|
151
|
+
seashell: 0xfff5ee,
|
|
152
|
+
sienna: 0xa0522d,
|
|
153
|
+
silver: 0xc0c0c0,
|
|
154
|
+
skyblue: 0x87ceeb,
|
|
155
|
+
slateblue: 0x6a5acd,
|
|
156
|
+
slategray: 0x708090,
|
|
157
|
+
slategrey: 0x708090,
|
|
158
|
+
snow: 0xfffafa,
|
|
159
|
+
springgreen: 0x00ff7f,
|
|
160
|
+
steelblue: 0x4682b4,
|
|
161
|
+
tan: 0xd2b48c,
|
|
162
|
+
teal: 0x008080,
|
|
163
|
+
thistle: 0xd8bfd8,
|
|
164
|
+
tomato: 0xff6347,
|
|
165
|
+
turquoise: 0x40e0d0,
|
|
166
|
+
violet: 0xee82ee,
|
|
167
|
+
wheat: 0xf5deb3,
|
|
168
|
+
white: 0xffffff,
|
|
169
|
+
whitesmoke: 0xf5f5f5,
|
|
170
|
+
yellow: 0xffff00,
|
|
171
|
+
yellowgreen: 0x9acd32
|
|
172
172
|
};
|
package/src/dom.ts
CHANGED
|
@@ -39,11 +39,11 @@ export function createCanvas(
|
|
|
39
39
|
/**
|
|
40
40
|
* Inject CSS styles in `document.head`
|
|
41
41
|
*
|
|
42
|
-
* @param {string}
|
|
42
|
+
* @param {string} styles CSS styles to inject
|
|
43
43
|
*/
|
|
44
|
-
export function injectStyles(
|
|
44
|
+
export function injectStyles(styles: string): void {
|
|
45
45
|
const $style = document.createElement('style');
|
|
46
|
-
$style.innerHTML =
|
|
46
|
+
$style.innerHTML = styles;
|
|
47
47
|
const $before = document.querySelector('head link[rel=stylesheet], head style');
|
|
48
48
|
if ($before) document.head.insertBefore($style, $before);
|
|
49
49
|
else document.head.appendChild($style);
|
package/src/files.ts
CHANGED
|
@@ -20,7 +20,7 @@ export function download(blob: Blob, filename: string): void {
|
|
|
20
20
|
* Upload a file from user files
|
|
21
21
|
*
|
|
22
22
|
* @param {Function} onLoad Callback called once the file is loaded
|
|
23
|
-
* @param {string} [accept='']
|
|
23
|
+
* @param {string} [accept=''] MIME type the file input should accept
|
|
24
24
|
*/
|
|
25
25
|
export function upload(onLoad: (dataUrl: string) => void, accept: string = ''): void {
|
|
26
26
|
const input = document.createElement('input');
|