Sebastiankay commited on
Commit
b1c4191
1 Parent(s): d81de80
Files changed (1) hide show
  1. _res/_custom.js +66 -11
_res/_custom.js CHANGED
@@ -32,19 +32,74 @@ function gradioCustomJS() {
32
  //document.querySelector("body").style.setProperty("--primary-700", document.querySelector("#dominant_image_color > label > textarea").value)
33
  })
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  const body = document.querySelector("body")
36
  body.className = "dark"
37
- body.style.setProperty("--primary-700", "rgb(250, 179, 135)")
38
- body.style.setProperty("--primary-50", "color-mix(in srgb, var(--primary-700) 5%, white)")
39
- body.style.setProperty("--primary-100", "color-mix(in srgb, var(--primary-700) 10%, white)")
40
- body.style.setProperty("--primary-200", "color-mix(in srgb, var(--primary-700) 20%, white)")
41
- body.style.setProperty("--primary-300", "color-mix(in srgb, var(--primary-700) 60%, white)")
42
- body.style.setProperty("--primary-400", "color-mix(in srgb, var(--primary-700) 70%, white)")
43
- body.style.setProperty("--primary-500", "color-mix(in srgb, var(--primary-700) 80%, white)")
44
- body.style.setProperty("--primary-600", "color-mix(in srgb, var(--primary-700) 90%, white)")
45
- body.style.setProperty("--primary-800", "color-mix(in srgb, var(--primary-700) 70%, black)")
46
- body.style.setProperty("--primary-900", "color-mix(in srgb, var(--primary-700) 80%, black)")
47
- body.style.setProperty("--primary-950", "color-mix(in srgb, var(--primary-700) 90%, black)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  const prompt_input = document.querySelector("#prompt_input")
50
  prompt_input.setAttribute("autocomplete", "off")
 
32
  //document.querySelector("body").style.setProperty("--primary-700", document.querySelector("#dominant_image_color > label > textarea").value)
33
  })
34
 
35
+ // MARK: berechne Helligkeit der Akzentfarbe
36
+ function berechneHelligkeit(rgb) {
37
+ const match = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/)
38
+ if (!match) {
39
+ throw new Error("Ungültiges Farbformat")
40
+ }
41
+
42
+ const r = parseInt(match[1]) / 255
43
+ const g = parseInt(match[2]) / 255
44
+ const b = parseInt(match[3]) / 255
45
+
46
+ const rLin = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4)
47
+ const gLin = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4)
48
+ const bLin = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)
49
+
50
+ const luminanz = 0.2126 * rLin + 0.7152 * gLin + 0.0722 * bLin
51
+
52
+ return luminanz
53
+ }
54
+
55
+ // MARK: Textfarbe bestimmen
56
+ function anpasseTextfarbe(farbe) {
57
+ const luminanz = berechneHelligkeit(farbe)
58
+ const textFarbe = luminanz > 0.4 ? "var(--neutral-950)" : "var(--neutral-50)"
59
+ console.log("Luminanz: " + luminanz + " Text-Farbe: " + textFarbe)
60
+
61
+ return textFarbe
62
+ }
63
+
64
  const body = document.querySelector("body")
65
  body.className = "dark"
66
+
67
+ // Catppuccin colors
68
+ const usedColor = "rgb(250, 179, 135)"
69
+ body.style.setProperty("--cat-rosewater", "rgb(245, 224, 220)")
70
+ body.style.setProperty("--cat-flamingo", "rgb(242, 205, 205)")
71
+ body.style.setProperty("--cat-pink", "rgb(245, 194, 231)")
72
+ body.style.setProperty("--cat-mauve", "rgb(203, 166, 247)")
73
+ body.style.setProperty("--cat-red", "rgb(243, 139, 168)")
74
+ body.style.setProperty("--cat-maroon", "rgb(235, 160, 172)")
75
+ body.style.setProperty("--cat-peach", "rgb(250, 179, 135)")
76
+ body.style.setProperty("--cat-yellow", "rgb(249, 226, 175)")
77
+ body.style.setProperty("--cat-green", "rgb(166, 227, 161)")
78
+ body.style.setProperty("--cat-teal", "rgb(148, 226, 213)")
79
+ body.style.setProperty("--cat-sky", "rgb(137, 220, 235)")
80
+ body.style.setProperty("--cat-sapphire", "rgb(116, 199, 236)")
81
+ body.style.setProperty("--cat-blue", "rgb(137, 180, 250)")
82
+
83
+ body.style.setProperty("--primary-600", usedColor)
84
+ body.style.setProperty("--primary-50", "color-mix(in srgb, var(--primary-600) 5%, white)")
85
+ body.style.setProperty("--primary-100", "color-mix(in srgb, var(--primary-600) 10%, white)")
86
+ body.style.setProperty("--primary-200", "color-mix(in srgb, var(--primary-600) 20%, white)")
87
+ body.style.setProperty("--primary-300", "color-mix(in srgb, var(--primary-600) 60%, white)")
88
+ body.style.setProperty("--primary-400", "color-mix(in srgb, var(--primary-600) 70%, white)")
89
+ body.style.setProperty("--primary-500", "color-mix(in srgb, var(--primary-600) 80%, white)")
90
+ body.style.setProperty("--primary-700", "color-mix(in srgb, var(--primary-600) 60%, black)")
91
+ body.style.setProperty("--primary-800", "color-mix(in srgb, var(--primary-600) 70%, black)")
92
+ body.style.setProperty("--primary-900", "color-mix(in srgb, var(--primary-600) 80%, black)")
93
+ body.style.setProperty("--primary-950", "color-mix(in srgb, var(--primary-600) 90%, black)")
94
+
95
+ body.style.setProperty("--block-title-text-color", "var(--neutral-950)")
96
+ body.style.setProperty("--block-label-text-color", "var(--neutral-950)")
97
+ body.style.setProperty("--checkbox-label-text-color", "var(--neutral-950)")
98
+
99
+ body.style.setProperty("--text-color-by-luminance", anpasseTextfarbe(usedColor))
100
+ body.style.setProperty("--block-title-text-color", anpasseTextfarbe(usedColor))
101
+ body.style.setProperty("--block-label-text-color", anpasseTextfarbe(usedColor))
102
+ body.style.setProperty("--checkbox-label-text-color", anpasseTextfarbe(usedColor))
103
 
104
  const prompt_input = document.querySelector("#prompt_input")
105
  prompt_input.setAttribute("autocomplete", "off")