diff options
author | Melissa Zhang <mzhang19096@gmail.com> | 2020-06-18 22:16:57 -0700 |
---|---|---|
committer | Melissa Zhang <mzhang19096@gmail.com> | 2020-06-18 22:16:57 -0700 |
commit | b79b5ebfd4f8ea8b4ae793e59f05b5bfe79b9b8a (patch) | |
tree | 3696946f79cd29007e9192fa9a93e5a3a9818a74 /src/Utils.ts | |
parent | 8a5c91740f1a8bc4dca2e99bba1da3a1ed1f591b (diff) | |
parent | d8feecd0542670233e6ea87006a89eb00d10a17e (diff) |
merge with master
Diffstat (limited to 'src/Utils.ts')
-rw-r--r-- | src/Utils.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index ef5002bec..dba802f98 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; @@ -382,6 +395,8 @@ export function returnZero() { return 0; } export function returnEmptyString() { return ""; } +export function returnEmptyFilter() { return [] as string[]; } + export let emptyPath = []; export function emptyFunction() { } |