Sebastiankay commited on
Commit
ca22f42
·
1 Parent(s): 2e4117f

28. Sept. 2024, 22:17

Browse files
Files changed (2) hide show
  1. _res/_custom.css +2 -12
  2. _res/_custom.js +153 -0
_res/_custom.css CHANGED
@@ -169,7 +169,7 @@ span.svelte-1gfkn6j,
169
  span.svelte-1gfkn6j,
170
  .primary.svelte-cmf5ev,
171
  label.selected.svelte-1k4wjf2.svelte-1k4wjf2.svelte-1k4wjf2 {
172
- color: var(--neutral-900) !important;
173
  }
174
 
175
  .md-header {
@@ -182,16 +182,6 @@ label.selected.svelte-1k4wjf2.svelte-1k4wjf2.svelte-1k4wjf2 {
182
  line-height: 1.5 !important;
183
  }
184
 
185
- & i.emoji-puls {
186
- color: var(--primary-100) !important;
187
- animation-name: beat;
188
- animation-delay: 0s;
189
- animation-direction: normal;
190
- animation-duration: 0.6s;
191
- animation-iteration-count: infinite;
192
- animation-timing-function: ease-in-out;
193
- }
194
-
195
  & i.waving {
196
  animation: wink 2s ease infinite;
197
  }
@@ -201,7 +191,7 @@ label.selected.svelte-1k4wjf2.svelte-1k4wjf2.svelte-1k4wjf2 {
201
  }
202
 
203
  & .heart {
204
- color: red;
205
  }
206
 
207
  }
 
169
  span.svelte-1gfkn6j,
170
  .primary.svelte-cmf5ev,
171
  label.selected.svelte-1k4wjf2.svelte-1k4wjf2.svelte-1k4wjf2 {
172
+ color: var(--text-color-by-luminance) !important;
173
  }
174
 
175
  .md-header {
 
182
  line-height: 1.5 !important;
183
  }
184
 
 
 
 
 
 
 
 
 
 
 
185
  & i.waving {
186
  animation: wink 2s ease infinite;
187
  }
 
191
  }
192
 
193
  & .heart {
194
+ color: var(--cat-red) !important;
195
  }
196
 
197
  }
_res/_custom.js CHANGED
@@ -1,6 +1,104 @@
1
  function gradioCustomJS() {
2
  console.log("gradioCustomJS Started")
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  //component-15
5
  const tabNav = document.querySelector("div.tab-nav")
6
  tabNav.addEventListener("mouseover", () => {
@@ -25,5 +123,60 @@ function gradioCustomJS() {
25
  })
26
  })
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  return "Custom Gradio JS"
29
  }
 
1
  function gradioCustomJS() {
2
  console.log("gradioCustomJS Started")
3
 
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
+
24
+ // MARK: Textfarbe bestimmen
25
+ function anpasseTextfarbe(farbe) {
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
+
33
+ // MARK: Body Styles
34
+ const body = document.querySelector("body")
35
+ body.className = "dark"
36
+
37
+ // MARK: Catppuccin colors
38
+ const usedColor = "rgb(166, 227, 161)"
39
+ body.style.setProperty("--cat-rosewater", "rgb(245, 224, 220)")
40
+ body.style.setProperty("--cat-flamingo", "rgb(242, 205, 205)")
41
+ body.style.setProperty("--cat-pink", "rgb(245, 194, 231)")
42
+ body.style.setProperty("--cat-mauve", "rgb(203, 166, 247)")
43
+ body.style.setProperty("--cat-red", "rgb(243, 139, 168)")
44
+ body.style.setProperty("--cat-maroon", "rgb(235, 160, 172)")
45
+ body.style.setProperty("--cat-peach", "rgb(250, 179, 135)")
46
+ body.style.setProperty("--cat-yellow", "rgb(249, 226, 175)")
47
+ body.style.setProperty("--cat-green", "rgb(166, 227, 161)")
48
+ body.style.setProperty("--cat-teal", "rgb(148, 226, 213)")
49
+ body.style.setProperty("--cat-sky", "rgb(137, 220, 235)")
50
+ body.style.setProperty("--cat-sapphire", "rgb(116, 199, 236)")
51
+ body.style.setProperty("--cat-blue", "rgb(137, 180, 250)")
52
+
53
+ body.style.setProperty("--primary-600", usedColor)
54
+ body.style.setProperty("--primary-50", "color-mix(in srgb, var(--primary-600) 5%, white)")
55
+ body.style.setProperty("--primary-100", "color-mix(in srgb, var(--primary-600) 10%, white)")
56
+ body.style.setProperty("--primary-200", "color-mix(in srgb, var(--primary-600) 20%, white)")
57
+ body.style.setProperty("--primary-300", "color-mix(in srgb, var(--primary-600) 60%, white)")
58
+ body.style.setProperty("--primary-400", "color-mix(in srgb, var(--primary-600) 70%, white)")
59
+ body.style.setProperty("--primary-500", "color-mix(in srgb, var(--primary-600) 80%, white)")
60
+ body.style.setProperty("--primary-700", "color-mix(in srgb, var(--primary-600) 80%, black)")
61
+ body.style.setProperty("--primary-800", "color-mix(in srgb, var(--primary-600) 65%, black)")
62
+ body.style.setProperty("--primary-900", "color-mix(in srgb, var(--primary-600) 40%, black)")
63
+ body.style.setProperty("--primary-950", "color-mix(in srgb, var(--primary-600) 30%, black)")
64
+
65
+ body.style.setProperty("--button-primary-background-fill", "var(--primary-600)")
66
+ body.style.setProperty("--button-primary-background-fill-hover", "var(--primary-500)")
67
+ body.style.setProperty("--blur-value", "0px")
68
+ body.style.setProperty("--text-color-by-luminance", anpasseTextfarbe(usedColor))
69
+
70
+ // MARK: Selectors & Elements
71
+ const gradioApp = document.querySelector("gradio-app")
72
+ const gradioContainer = document.querySelector("body > gradio-app > div.gradio-container")
73
+ const alertModalElem = document.createElement("div")
74
+ const alertModalElemP = document.createElement("p")
75
+ const alertModalElemI = document.createElement("i")
76
+ alertModalElemI.className = "fas fa-exclamation-circle"
77
+ const alertModalElemSpan = document.createElement("span")
78
+ alertModalElemSpan.id = "alertModalText"
79
+ const alertModalElemButton = document.createElement("button")
80
+ alertModalElemButton.className = "lg primary run-btn svelte-cmf5ev"
81
+ alertModalElemButton.id = "alertModalBtn"
82
+ alertModalElemButton.textContent = "Ok"
83
+ alertModalElemP.id = "alertModalP"
84
+ alertModalElemP.append(alertModalElemI, alertModalElemSpan)
85
+ alertModalElem.id = "alertModal"
86
+ alertModalElem.style.display = "none"
87
+ alertModalElem.append(alertModalElemP, alertModalElemButton)
88
+ //alertModalElem.innerHTML = '<p></p>'
89
+ gradioApp.appendChild(alertModalElem)
90
+
91
+ alertModalElemButton.addEventListener("click", () => {
92
+ oldText = alertModalElemSpan.textContent
93
+ alertModalElemButton.disabled = true
94
+ alertModalElemSpan.innerHTML = 'Der "Ok" Button ändert nur diesen Text. 🫢<br/>In 2.5 Sekunden wird wieder die ursprüngliche Meldung gezeigt. Cool oder?'
95
+ setTimeout(() => {
96
+ alertModalElemSpan.textContent = oldText
97
+ alertModalElemButton.disabled = false
98
+ alertModalElemButton.textContent = "Noch mal?"
99
+ }, 2500)
100
+ })
101
+
102
  //component-15
103
  const tabNav = document.querySelector("div.tab-nav")
104
  tabNav.addEventListener("mouseover", () => {
 
123
  })
124
  })
125
 
126
+ // MARK: Element-Ready function
127
+ function elementReady(selector) {
128
+ return new Promise((resolve, reject) => {
129
+ const el = document.querySelector(selector)
130
+ if (el) {
131
+ resolve(el)
132
+ }
133
+
134
+ new MutationObserver((mutationRecords, observer) => {
135
+ Array.from(document.querySelectorAll(selector)).forEach((element) => {
136
+ resolve(element)
137
+ observer.disconnect()
138
+ })
139
+ }).observe(document.documentElement, {
140
+ childList: true,
141
+ subtree: true,
142
+ })
143
+ })
144
+ }
145
+
146
+ // MARK: Mobile Check
147
+ function istMobile() {
148
+ // Überprüfen, ob das Gerät ein Touchscreen hat
149
+ if ("ontouchstart" in window || (navigator.maxTouchPoints && window.innerWidth < 768)) {
150
+ gradioContainer.classList.add("blur-container")
151
+ body.style.setProperty("--blur-value", "12px")
152
+ gradioApp.style.height = "calc(100vh - 120px)"
153
+ alertModalElem.style.display = ""
154
+ alertModalElemSpan.textContent = "Diese Seite ist nicht für mobile Geräte optimiert. Bitte besuche diese Seite von einem Desktop-Computer aus."
155
+ } else if (window.innerWidth < 1024) {
156
+ gradioContainer.classList.add("blur-container")
157
+ body.style.setProperty("--blur-value", "12px")
158
+ gradioApp.style.height = "calc(100vh - 120px)"
159
+ alertModalElem.style.display = ""
160
+ alertModalElemSpan.textContent = "Bildschirm Auflösung oder Fensterbreite zu gering. Bitte besuche diese Seite von einem Desktop-Computer aus."
161
+ } else {
162
+ gradioContainer.classList.remove("blur-container")
163
+ body.style.setProperty("--blur-value", "0px")
164
+ gradioApp.style.height = ""
165
+ alertModalElem.style.display = "none"
166
+ alertModalElemSpan.textContent = ""
167
+ }
168
+ }
169
+
170
+ // MARK: Event Listeners
171
+ window.addEventListener("resize", () => {
172
+ console.log("Event Window resize.")
173
+ istMobile()
174
+ })
175
+
176
+ elementReady("body > gradio-app > div.gradio-container").then((element) => {
177
+ console.log("Element exist: " + element)
178
+ istMobile()
179
+ })
180
+
181
  return "Custom Gradio JS"
182
  }