diff options
author | usodhi <61431818+usodhi@users.noreply.github.com> | 2020-06-10 15:43:05 +0530 |
---|---|---|
committer | usodhi <61431818+usodhi@users.noreply.github.com> | 2020-06-10 15:43:05 +0530 |
commit | 84ccaf9703c945d4d47d5dc847f45ecaa3f5de17 (patch) | |
tree | dc5a881fedfff47355c85276a301f0ee5e9a1837 /src/Utils.ts | |
parent | ca2757e137e287f3d6d711c97e2b8a212dd28021 (diff) | |
parent | c3bbedc622080c6087c862d6fb0c8b3438d51edc (diff) |
merged
Diffstat (limited to 'src/Utils.ts')
-rw-r--r-- | src/Utils.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index ef5002bec..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; @@ -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; |