Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/common/color/convert-color.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const expand_hex = (hex: string): string => {
hex = hex.replace("#", "");
if (hex.length === 6) return hex;
let result = "";
for (const val of hex) {
result += val + val;
Expand All @@ -14,10 +16,7 @@ const rgb_hex = (component: number): string => {
// Conversion between HEX and RGB

export const hex2rgb = (hex: string): [number, number, number] => {
hex = hex.replace("#", "");
if (hex.length === 3 || hex.length === 4) {
hex = expand_hex(hex);
}
hex = expand_hex(hex);

return [
parseInt(hex.substring(0, 2), 16),
Expand Down Expand Up @@ -111,3 +110,18 @@ export const lab2hex = (lab: [number, number, number]): string => {
const rgb = lab2rgb(lab);
return rgb2hex(rgb);
};

// Blend two colors with percentage
export const blend = (color_1: string, color_2: string, mix = 50): string => {
Comment thread
maykar marked this conversation as resolved.
Outdated
let color = "";
color_1 = expand_hex(color_1);
color_2 = expand_hex(color_2);
for (let i = 0; i <= 5; i += 2) {
const c1 = parseInt(color_1.substr(i, 2), 16);
const c2 = parseInt(color_2.substr(i, 2), 16);
let hex = Math.floor(c2 + (c1 - c2) * (mix / 100)).toString(16);
while (hex.length < 2) hex = "0" + hex;
color += hex;
}
return `#${color}`;
};
Comment thread
maykar marked this conversation as resolved.
Outdated
8 changes: 8 additions & 0 deletions src/common/dom/apply_themes_on_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
lab2rgb,
rgb2hex,
rgb2lab,
blend,
} from "../color/convert-color";
import { labBrighten, labDarken } from "../color/lab";
import { rgbContrast } from "../color/rgb";
Expand Down Expand Up @@ -37,6 +38,13 @@ export const applyThemesOnElement = (
if (themeOptions.dark) {
cacheKey = `${cacheKey}__dark`;
themeRules = darkStyles;
if (themeOptions.primaryColor) {
themeRules["app-header-background-color"] = blend(
Comment thread
maykar marked this conversation as resolved.
Outdated
themeOptions.primaryColor,
"#111",
Comment thread
maykar marked this conversation as resolved.
Outdated
15
Comment thread
maykar marked this conversation as resolved.
Outdated
);
}
}
if (themeOptions.primaryColor) {
cacheKey = `${cacheKey}__primary_${themeOptions.primaryColor}`;
Expand Down
2 changes: 1 addition & 1 deletion src/resources/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const darkStyles = {
"secondary-text-color": "#9b9b9b",
"disabled-text-color": "#6f6f6f",
"app-header-text-color": "#e1e1e1",
"app-header-background-color": "#1c1c1c",
"app-header-background-color": "#0e2733",
"switch-unchecked-button-color": "#999999",
"switch-unchecked-track-color": "#9b9b9b",
"divider-color": "rgba(225, 225, 225, .12)",
Expand Down