quicksave

This commit is contained in:
Schmelczer András 2019-12-28 17:21:35 +01:00
parent f74c86f4b1
commit 98160edc72
23 changed files with 226 additions and 153 deletions

View file

@ -24,3 +24,51 @@ export const randomInInterval = (
export const sum = (list: ArrayLike<number>): number =>
Array.prototype.reduce.call(list, (a, sum) => a + sum, 0);
export const getHeight = (e: HTMLElement): number => {
const computedStyle = window.getComputedStyle(e);
return (
// ignores margin collapse
e.clientHeight +
parseInt(computedStyle.marginTop) +
parseInt(computedStyle.marginBottom) +
parseInt(computedStyle.borderTopWidth) +
parseInt(computedStyle.borderBottomWidth)
);
};
export const mixColors = (
hexColorA: string,
hexColorB: string,
qA: number
): string => {
const colorA = hexToRGB(normalizeHex(hexColorA));
const colorB = hexToRGB(normalizeHex(hexColorB));
const mixedColor: [number, number, number] = [
colorA[0] * qA + colorB[0] * (1 - qA),
colorA[1] * qA + colorB[1] * (1 - qA),
colorA[2] * qA + colorB[2] * (1 - qA)
];
return RGBToHex(mixedColor);
};
const normalizeHex = (hex: string): string => {
hex = hex.trim();
if (hex.startsWith("#")) {
hex = hex.substr(1);
}
return hex;
};
const hexToRGB = (hex: string): [number, number, number] => {
const [r1, r2, g1, g2, b1, b2] = hex;
return [
Number.parseInt(r1 + r2, 16),
Number.parseInt(g1 + g2, 16),
Number.parseInt(b1 + b2, 16)
];
};
const RGBToHex = (rgb: [number, number, number]): string =>
rgb.map(n => Math.round(n).toString(16)).join("");