Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/colorspace.js to ES6 module.

Anders Kaseorgf3fb01a430ae
diff --git a/.eslintrc.json b/.eslintrc.json
index 76de6c3cc56..6eb59bdce36 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -148,7 +148,6 @@
"channel": false,
"click_handlers": false,
"color_data": false,
- "colorspace": false,
"common": false,
"compose": false,
"compose_actions": false,
diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js
index 1b0263c0db8..22d7649cdd2 100644
--- a/frontend_tests/node_tests/drafts.js
+++ b/frontend_tests/node_tests/drafts.js
@@ -13,7 +13,6 @@ const localstorage = zrequire("localstorage");
const drafts = zrequire("drafts");
const timerender = zrequire("timerender");
zrequire("stream_color");
-zrequire("colorspace");
const ls_container = new Map();
const noop = function () {
diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js
index f3ae630e9ff..eb363a02ac7 100644
--- a/frontend_tests/node_tests/stream_list.js
+++ b/frontend_tests/node_tests/stream_list.js
@@ -13,7 +13,6 @@ set_global("$", make_zjquery());
zrequire("unread_ui");
const Filter = zrequire("Filter", "js/filter");
const stream_sort = zrequire("stream_sort");
-zrequire("colorspace");
const stream_color = zrequire("stream_color");
zrequire("hash_util");
const unread = zrequire("unread");
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index 9fb943d2787..7f33a1aa063 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -82,7 +82,6 @@ stub_templates(() => "some-html");
ui.get_scroll_element = (element) => element;
zrequire("hash_util");
-zrequire("colorspace");
zrequire("stream_color");
zrequire("stream_edit");
zrequire("color_data");
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 0ba490f83a6..c66a61a8002 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -118,7 +118,6 @@ import "../buddy_list";
import "../list_cursor";
import "../activity";
import "../user_events";
-import "../colorspace";
import "../timerender";
import "../tutorial";
import "../hotspots";
diff --git a/static/js/colorspace.js b/static/js/colorspace.js
index fa6c0a12c3d..3d49a09d316 100644
--- a/static/js/colorspace.js
+++ b/static/js/colorspace.js
@@ -1,28 +1,26 @@
-"use strict";
-
// Convert an sRGB value in [0, 255] to a linear intensity
// value in [0, 1].
//
// https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
-exports.sRGB_to_linear = function (v) {
+export function sRGB_to_linear(v) {
v = v / 255;
if (v <= 0.04045) {
return v / 12.92;
}
return Math.pow((v + 0.055) / 1.055, 2.4);
-};
+}
// Compute luminance (CIE Y stimulus) from linear intensity
// of sRGB / Rec. 709 primaries.
-exports.rgb_luminance = function (channel) {
+export function rgb_luminance(channel) {
return 0.2126 * channel[0] + 0.7152 * channel[1] + 0.0722 * channel[2];
-};
+}
// Convert luminance (photometric, CIE Y)
// to lightness (perceptual, CIE L*)
//
// https://en.wikipedia.org/wiki/Lab_color_space#Forward_transformation
-exports.luminance_to_lightness = function (luminance) {
+export function luminance_to_lightness(luminance) {
let v;
if (luminance <= 216 / 24389) {
v = (841 / 108) * luminance + 4 / 29;
@@ -31,31 +29,29 @@ exports.luminance_to_lightness = function (luminance) {
}
return 116 * v - 16;
-};
+}
-exports.getDecimalColor = function (hexcolor) {
+export function getDecimalColor(hexcolor) {
return {
r: Number.parseInt(hexcolor.slice(1, 3), 16),
g: Number.parseInt(hexcolor.slice(3, 5), 16),
b: Number.parseInt(hexcolor.slice(5, 7), 16),
};
-};
+}
-exports.getLighterColor = function (rgb, lightness) {
+export function getLighterColor(rgb, lightness) {
return {
r: Math.round(lightness * 255 + (1 - lightness) * rgb.r),
g: Math.round(lightness * 255 + (1 - lightness) * rgb.g),
b: Math.round(lightness * 255 + (1 - lightness) * rgb.b),
};
-};
+}
-exports.getHexColor = function (rgb) {
+export function getHexColor(rgb) {
return (
"#" +
Number.parseInt(rgb.r, 10).toString(16) +
Number.parseInt(rgb.g, 10).toString(16) +
Number.parseInt(rgb.b, 10).toString(16)
);
-};
-
-window.colorspace = exports;
+}
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 439008cae1c..a775ed78be4 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -21,7 +21,6 @@ declare let buddy_list: any;
declare let channel: any;
declare let click_handlers: any;
declare let color_data: any;
-declare let colorspace: any;
declare let common: any;
declare let compose: any;
declare let compose_actions: any;
diff --git a/static/js/stream_color.js b/static/js/stream_color.js
index 7d400cc4244..27f59242bcf 100644
--- a/static/js/stream_color.js
+++ b/static/js/stream_color.js
@@ -2,6 +2,8 @@
const _ = require("lodash");
+const colorspace = require("./colorspace");
+
exports.default_color = "#c2c2c2";
// Classes which could be returned by get_color_class.