-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0 | ||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience | ||
* Copyright (c) 2023 Vendicated and Vencord contributors | ||
*/ | ||
|
||
const digitRegex = "([a-zA-Z\\d.%\\*\\(\\)]+)"; | ||
const validFormats = ["rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"] as const; | ||
|
||
const colorRegexes = [ | ||
...validFormats.map(fmt => new RegExp(`(${fmt})\\(${new Array(3).fill(digitRegex).join(" *, *")}\\)`)), | ||
...validFormats.map(fmt => new RegExp(`(${fmt})a\\(${new Array(4).fill(digitRegex).join(" *, *")}\\)`)), | ||
...validFormats.map(fmt => new RegExp(`(${fmt})\\(${new Array(3).fill(digitRegex).join(" +")}\\)`)), | ||
...validFormats.map( | ||
fmt => new RegExp(`(${fmt})a?\\(${new Array(3).fill(digitRegex).join(" +")} ?/ ?${digitRegex}\\)`) | ||
) | ||
]; | ||
|
||
const hexRegex = /^#([\da-fA-F]{6})$/; | ||
const hexAlphaRegex = /^#([\da-fA-F]{6})[\da-fA-F]{2}$/; | ||
|
||
export const alpha = (original: string, alpha: number): string => { | ||
for (const regex of colorRegexes) { | ||
const match = original.match(regex); | ||
if (match) { | ||
const [, format, a, b, c] = match; | ||
return `${format}a(${a} ${b} ${c} / ${alpha})`; | ||
} | ||
} | ||
|
||
for (const regex of [hexRegex, hexAlphaRegex]) { | ||
const match = original.match(regex); | ||
if (match) { | ||
const [, str] = match; | ||
return `#${str}${Math.round(alpha * 255) | ||
.toString(16) | ||
.padStart(2, "0")}`; | ||
} | ||
} | ||
|
||
return original; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SPDX-License-Identifier: GPL-3.0 | ||
* Vesktop, a desktop app aiming to give you a snappier Discord Experience | ||
* Copyright (c) 2023 Vendicated and Vencord contributors | ||
*/ | ||
|
||
import { Settings } from "./settings"; | ||
|
||
function isValidColor(color: CSSStyleValue | undefined): color is CSSUnparsedValue & { [0]: string } { | ||
return color instanceof CSSUnparsedValue && typeof color[0] === "string" && CSS.supports("color", color[0]); | ||
} | ||
|
||
const updateSplashColors = () => { | ||
const bodyStyles = document.body.computedStyleMap(); | ||
|
||
const color = bodyStyles.get("--text-normal"); | ||
const backgroundColor = bodyStyles.get("--background-primary"); | ||
|
||
if (isValidColor(color)) { | ||
Settings.store.splashColor = color[0]; | ||
} | ||
|
||
if (isValidColor(backgroundColor)) { | ||
Settings.store.splashBackground = backgroundColor[0]; | ||
} | ||
}; | ||
|
||
if (document.readyState === "complete") { | ||
updateSplashColors(); | ||
} else { | ||
window.addEventListener("load", updateSplashColors); | ||
} | ||
|
||
window.addEventListener("beforeunload", updateSplashColors); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters