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