aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-06-08 22:26:42 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-06-08 22:26:42 -0400
commit23d91c839bc7dd14fd906aa1b3c7b3cd16980dd4 (patch)
treec5f181d92e5edad3c12f4500128bc5420eb6616d /src/Utils.ts
parent01cc676b568c9d53757e1e4c8155672ecea95562 (diff)
parentc878c35dc06c6f0c653390d95d18feeaf2dfabd1 (diff)
Merge branch 'master' into RichTextEdition
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index bcb215804..e527634fd 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -2,6 +2,7 @@ import v4 = require('uuid/v4');
import v5 = require("uuid/v5");
import { Socket, Room } from 'socket.io';
import { Message } from './server/Message';
+import { ColorState } from 'react-color';
export namespace Utils {
export let DRAG_THRESHOLD = 4;
@@ -43,7 +44,7 @@ export namespace Utils {
}
/**
- * A convenience method. Prepends the full path (i.e. http://localhost:1050) to the
+ * A convenience method. Prepends the full path (i.e. http://localhost:<port>) to the
* requested extension
* @param extension the specified sub-path to append to the window origin
*/
@@ -75,6 +76,18 @@ export namespace Utils {
document.body.removeChild(textArea);
}
+ export function decimalToHexString(number: number) {
+ if (number < 0) {
+ number = 0xFFFFFFFF + number + 1;
+ }
+ return (number < 16 ? "0" : "") + number.toString(16).toUpperCase();
+ }
+
+ export function colorString(color: ColorState) {
+ return color.hex.startsWith("#") ?
+ color.hex + (color.rgb.a ? decimalToHexString(Math.round(color.rgb.a * 255)) : "ff") : color.hex;
+ }
+
export function fromRGBAstr(rgba: string) {
const rm = rgba.match(/rgb[a]?\(([ 0-9]+)/);
const r = rm ? Number(rm[1]) : 0;