Commit ·
4447a6f
1
Parent(s): 124e21b
3. Okt. 2024, 04:42
Browse files- _res/_custom.js +21 -37
_res/_custom.js
CHANGED
|
@@ -4,20 +4,15 @@ function gradioCustomJS() {
|
|
| 4 |
// MARK: berechne Helligkeit der Akzentfarbe
|
| 5 |
function berechneHelligkeit(rgb) {
|
| 6 |
const match = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/)
|
| 7 |
-
if (!match)
|
| 8 |
-
throw new Error("Ungültiges Farbformat")
|
| 9 |
-
}
|
| 10 |
|
| 11 |
const r = parseInt(match[1]) / 255
|
| 12 |
const g = parseInt(match[2]) / 255
|
| 13 |
const b = parseInt(match[3]) / 255
|
| 14 |
-
|
| 15 |
const rLin = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4)
|
| 16 |
const gLin = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4)
|
| 17 |
const bLin = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)
|
| 18 |
-
|
| 19 |
const luminanz = 0.2126 * rLin + 0.7152 * gLin + 0.0722 * bLin
|
| 20 |
-
|
| 21 |
return luminanz
|
| 22 |
}
|
| 23 |
|
|
@@ -26,7 +21,6 @@ function gradioCustomJS() {
|
|
| 26 |
const luminanz = berechneHelligkeit(farbe)
|
| 27 |
const textFarbe = luminanz > 0.4 ? "var(--neutral-950)" : "var(--neutral-50)"
|
| 28 |
console.log("Luminanz: " + luminanz + " Text-Farbe: " + textFarbe)
|
| 29 |
-
|
| 30 |
return textFarbe
|
| 31 |
}
|
| 32 |
|
|
@@ -35,36 +29,26 @@ function gradioCustomJS() {
|
|
| 35 |
body.className = "dark"
|
| 36 |
|
| 37 |
// Catppuccin colors
|
| 38 |
-
const
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
let usedColor = `rgb(${colors[Math.floor(Math.random() * colors.length)]})`
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
body.style.setProperty("--cat-mauve", "rgb(" + mauve + ")")
|
| 59 |
-
body.style.setProperty("--cat-red", "rgb(" + red + ")")
|
| 60 |
-
body.style.setProperty("--cat-maroon", "rgb(" + maroon + ")")
|
| 61 |
-
body.style.setProperty("--cat-peach", "rgb(" + peach + ")")
|
| 62 |
-
body.style.setProperty("--cat-yellow", "rgb(" + yellow + ")")
|
| 63 |
-
body.style.setProperty("--cat-green", "rgb(" + green + ")")
|
| 64 |
-
body.style.setProperty("--cat-teal", "rgb(" + teal + ")")
|
| 65 |
-
body.style.setProperty("--cat-sky", "rgb(" + sky + ")")
|
| 66 |
-
body.style.setProperty("--cat-sapphire", "rgb(" + sapphire + ")")
|
| 67 |
-
body.style.setProperty("--cat-blue", "rgb(" + blue + ")")
|
| 68 |
|
| 69 |
body.style.setProperty("--primary-600", usedColor)
|
| 70 |
body.style.setProperty("--primary-50", "color-mix(in srgb, var(--primary-600) 5%, white)")
|
|
|
|
| 4 |
// MARK: berechne Helligkeit der Akzentfarbe
|
| 5 |
function berechneHelligkeit(rgb) {
|
| 6 |
const match = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/)
|
| 7 |
+
if (!match) throw new Error("Ungültiges Farbformat")
|
|
|
|
|
|
|
| 8 |
|
| 9 |
const r = parseInt(match[1]) / 255
|
| 10 |
const g = parseInt(match[2]) / 255
|
| 11 |
const b = parseInt(match[3]) / 255
|
|
|
|
| 12 |
const rLin = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4)
|
| 13 |
const gLin = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4)
|
| 14 |
const bLin = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)
|
|
|
|
| 15 |
const luminanz = 0.2126 * rLin + 0.7152 * gLin + 0.0722 * bLin
|
|
|
|
| 16 |
return luminanz
|
| 17 |
}
|
| 18 |
|
|
|
|
| 21 |
const luminanz = berechneHelligkeit(farbe)
|
| 22 |
const textFarbe = luminanz > 0.4 ? "var(--neutral-950)" : "var(--neutral-50)"
|
| 23 |
console.log("Luminanz: " + luminanz + " Text-Farbe: " + textFarbe)
|
|
|
|
| 24 |
return textFarbe
|
| 25 |
}
|
| 26 |
|
|
|
|
| 29 |
body.className = "dark"
|
| 30 |
|
| 31 |
// Catppuccin colors
|
| 32 |
+
const colors = {
|
| 33 |
+
rosewater: "245, 224, 220",
|
| 34 |
+
flamingo: "242, 205, 205",
|
| 35 |
+
pink: "245, 194, 231",
|
| 36 |
+
mauve: "203, 166, 247",
|
| 37 |
+
red: "243, 139, 168",
|
| 38 |
+
maroon: "235, 160, 172",
|
| 39 |
+
peach: "250, 179, 135",
|
| 40 |
+
yellow: "249, 226, 175",
|
| 41 |
+
green: "166, 227, 161",
|
| 42 |
+
teal: "148, 226, 213",
|
| 43 |
+
sky: "137, 220, 235",
|
| 44 |
+
sapphire: "116, 199, 236",
|
| 45 |
+
blue: "137, 180, 250",
|
| 46 |
+
}
|
| 47 |
+
let usedColor = `rgb(${Object.values(colors)[Math.floor(Math.random() * Object.keys(colors).length)]})`
|
| 48 |
+
|
| 49 |
+
for (const [colorName, colorValues] of Object.entries(colors)) {
|
| 50 |
+
body.style.setProperty(`--cat-${colorName.replace(/,/g, "-")}`, `rgb(${colorValues})`)
|
| 51 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
body.style.setProperty("--primary-600", usedColor)
|
| 54 |
body.style.setProperty("--primary-50", "color-mix(in srgb, var(--primary-600) 5%, white)")
|