ts: Convert color_data module to TypeScript.

This commit is contained in:
Priyank Patel
2021-06-13 23:33:43 +00:00
committed by Tim Abbott
parent adf83c6eb7
commit 91573531bb

View File

@@ -1,6 +1,7 @@
import _ from "lodash"; import _ from "lodash";
export let unused_colors; export let unused_colors: string[];
// These colors are used now for streams. // These colors are used now for streams.
const stream_colors = [ const stream_colors = [
"#76ce90", "#76ce90",
@@ -33,13 +34,13 @@ const stream_colors = [
// bias toward "early" colors. // bias toward "early" colors.
export const colors = _.shuffle(stream_colors); export const colors = _.shuffle(stream_colors);
export function reset() { export function reset(): void {
unused_colors = colors.slice(); unused_colors = colors.slice();
} }
reset(); reset();
export function claim_color(color) { export function claim_color(color: string): void {
const i = unused_colors.indexOf(color); const i = unused_colors.indexOf(color);
if (i < 0) { if (i < 0) {
@@ -53,14 +54,14 @@ export function claim_color(color) {
} }
} }
export function claim_colors(subs) { export function claim_colors(subs: {color: string}[]): void {
const colors = new Set(subs.map((sub) => sub.color)); const colors = new Set(subs.map((sub) => sub.color));
for (const color of colors) { for (const color of colors) {
claim_color(color); claim_color(color);
} }
} }
export function pick_color() { export function pick_color(): string {
const color = unused_colors[0]; const color = unused_colors[0];
claim_color(color); claim_color(color);