Sebastiankay commited on
Commit
3798fc3
1 Parent(s): dcdd362

24. Sept. 2024, 22:12

Browse files
Files changed (1) hide show
  1. _res/_custom.js +36 -37
_res/_custom.js CHANGED
@@ -66,39 +66,6 @@ function gradioCustomJS() {
66
  body.style.setProperty("--blur-value", "0px")
67
  body.style.setProperty("--text-color-by-luminance", anpasseTextfarbe(usedColor))
68
 
69
- // MARK: DOM Change Detection
70
- function onDomChange(callback) {
71
- const observer = new MutationObserver(callback)
72
- observer.observe(document.querySelector("#dominant_image_color"), {
73
- childList: true,
74
- subtree: true,
75
- })
76
- }
77
-
78
- onDomChange(() => {
79
- console.log("changed: " + document.querySelector("#dominant_image_color > label > textarea").value)
80
- if (document.querySelector("#dominant_image_color > label > textarea").value.match(/^rgb\((\d{1,3}),(\s\d{1,3}),(\s\d{1,3})\)$/) && document.querySelector("#output_image > div.image-container.svelte-1p15vfy > button > div > img").src) {
81
- document.querySelector("#output_image > div.image-container.svelte-1p15vfy > button > div > img").style.opacity = "0"
82
- document.querySelector("body > gradio-app > div").classList.add("fade-bg")
83
- document.querySelector("gradio-app").style.opacity = "0"
84
- setTimeout(() => {
85
- usedColor = document.querySelector("#dominant_image_color > label > textarea").value
86
- document.querySelector("body").style.setProperty("--primary-600", usedColor)
87
- document.querySelector("gradio-app").classList.add("has-bg-image")
88
- document.querySelector("body").style.setProperty("--bg-image-path", `url("${document.querySelector("#output_image > div.image-container.svelte-1p15vfy > button > div > img").src}")`)
89
- }, 400)
90
- setTimeout(() => {
91
- document.querySelector("gradio-app").style.opacity = "1"
92
- document.querySelector("#output_image > div.image-container.svelte-1p15vfy > button > div > img").style.opacity = "1"
93
- document.querySelector("#dominant_image_color > label > textarea").value = ""
94
- }, 800)
95
- setTimeout(() => {
96
- //document.querySelector("body > gradio-app > div").classList.remove("fade-bg")
97
- }, 2000)
98
- }
99
- //document.querySelector("body").style.setProperty("--primary-700", document.querySelector("#dominant_image_color > label > textarea").value)
100
- })
101
-
102
  // MARK: Selectors & Elements
103
  const gradioApp = document.querySelector("gradio-app")
104
  const gradioContainer = document.querySelector("body > gradio-app > div.gradio-container")
@@ -146,12 +113,44 @@ function gradioCustomJS() {
146
  prompt_input.setAttribute("autocapitalize", "off")
147
  prompt_input.setAttribute("spellcheck", "false")
148
 
149
- const imageRatioBtns = document.querySelectorAll("#image_ratio_buttons > div label")
150
- const width_selector = document.querySelector("#image_width_selector > label > input")
151
- const hight_selector = document.querySelector("#image_height_selector > label > input")
152
  const switch_width_height = document.querySelector("#switch_width_height")
153
-
154
  const random_prompt_btn = document.querySelector("#random_prompt_btn")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  random_prompt_btn.innerHTML =
156
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><g data-name="Ebene_1"><path fill="none" d="M0 48V0h48v48z"/><path d="M42.15 9.85C41.58 9.28 40.9 9 40.12 9H7.88c-.78 0-1.46.28-2.03.85S5 11.1 5 11.88v24.23c0 .78.28 1.46.85 2.03s1.25.85 2.03.85h32.23c.78 0 1.46-.28 2.03-.85s.85-1.25.85-2.03V11.88c0-.78-.28-1.46-.85-2.03ZM13.66 30.78c-.68 0-1.24-.55-1.24-1.24s.55-1.24 1.24-1.24 1.24.55 1.24 1.24-.55 1.24-1.24 1.24Zm2.8-7.78-1.3 1.8c-.32.45-.41.76-.48 1.23-.04.26-.13.48-.28.64-.17.19-.42.29-.73.29s-.56-.12-.73-.31c-.16-.18-.25-.42-.25-.73 0-.68.12-1.09.65-1.8l1.48-2c.33-.45.58-.87.58-1.47 0-1.04-.75-1.83-1.83-1.83-.52 0-.99.15-1.36.52-.29.29-.43.65-.55 1.12-.06.22-.16.47-.27.58-.15.17-.39.29-.7.29-.26 0-.49-.1-.66-.29-.18-.2-.23-.42-.23-.71 0-.67.35-1.58 1.03-2.22.68-.65 1.62-1.03 2.73-1.03 2.11 0 3.79 1.4 3.79 3.57 0 1-.35 1.62-.89 2.36Zm7.28 7.78c-.68 0-1.24-.55-1.24-1.24s.55-1.24 1.24-1.24 1.24.55 1.24 1.24-.55 1.24-1.24 1.24Zm2.8-7.78-1.3 1.8c-.32.45-.41.76-.48 1.23-.04.26-.13.48-.28.64-.17.19-.42.29-.73.29s-.56-.12-.73-.31c-.16-.18-.25-.42-.25-.73 0-.68.12-1.09.65-1.8l1.48-2c.33-.45.58-.87.58-1.47 0-1.04-.75-1.83-1.83-1.83-.52 0-.99.15-1.36.52-.29.29-.43.65-.55 1.12-.06.22-.16.47-.27.58-.15.17-.39.29-.7.29-.26 0-.49-.1-.66-.29-.18-.2-.23-.42-.23-.71 0-.67.35-1.58 1.03-2.22.68-.65 1.62-1.03 2.73-1.03 2.11 0 3.79 1.4 3.79 3.57 0 1-.35 1.62-.89 2.36Zm7.28 7.78c-.68 0-1.24-.55-1.24-1.24s.55-1.24 1.24-1.24 1.24.55 1.24 1.24-.55 1.24-1.24 1.24Zm2.8-7.78-1.3 1.8c-.32.45-.41.76-.48 1.23-.04.26-.13.48-.28.64-.17.19-.42.29-.73.29s-.56-.12-.73-.31c-.16-.18-.25-.42-.25-.73 0-.68.12-1.09.65-1.8l1.48-2c.33-.45.58-.87.58-1.47 0-1.04-.75-1.83-1.83-1.83-.52 0-.99.15-1.36.52-.29.29-.43.65-.55 1.12-.06.22-.16.47-.27.58-.15.17-.39.29-.7.29-.26 0-.49-.1-.66-.29-.18-.2-.23-.42-.23-.71 0-.67.35-1.58 1.03-2.22.68-.65 1.62-1.03 2.73-1.03 2.11 0 3.79 1.4 3.79 3.57 0 1-.35 1.62-.89 2.36Z"/></g></svg>'
157
  const enhance_prompt_btn = document.querySelector("#enhance_prompt_btn")
 
66
  body.style.setProperty("--blur-value", "0px")
67
  body.style.setProperty("--text-color-by-luminance", anpasseTextfarbe(usedColor))
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  // MARK: Selectors & Elements
70
  const gradioApp = document.querySelector("gradio-app")
71
  const gradioContainer = document.querySelector("body > gradio-app > div.gradio-container")
 
113
  prompt_input.setAttribute("autocapitalize", "off")
114
  prompt_input.setAttribute("spellcheck", "false")
115
 
 
 
 
116
  const switch_width_height = document.querySelector("#switch_width_height")
 
117
  const random_prompt_btn = document.querySelector("#random_prompt_btn")
118
+
119
+ // MARK: DOM Change Detection
120
+ function onDomChange(callback) {
121
+ const observer = new MutationObserver(callback)
122
+ observer.observe(document.querySelector("#dominant_image_color"), {
123
+ childList: true,
124
+ subtree: true,
125
+ })
126
+ }
127
+
128
+ onDomChange(() => {
129
+ console.log("changed: " + document.querySelector("#dominant_image_color > label > textarea").value)
130
+ if (document.querySelector("#dominant_image_color > label > textarea").value.match(/^rgb\((\d{1,3}),(\s\d{1,3}),(\s\d{1,3})\)$/) && document.querySelector("#output_image > div.image-container.svelte-1p15vfy > button > div > img").src) {
131
+ document.querySelector("#output_image > div.image-container.svelte-1p15vfy > button > div > img").style.opacity = "0"
132
+ document.querySelector("body > gradio-app > div").classList.add("fade-bg")
133
+ document.querySelector("gradio-app").style.opacity = "0"
134
+ setTimeout(() => {
135
+ usedColor = document.querySelector("#dominant_image_color > label > textarea").value
136
+ body.style.setProperty("--primary-600", usedColor)
137
+ body.style.setProperty("--text-color-by-luminance", anpasseTextfarbe(usedColor))
138
+ document.querySelector("gradio-app").classList.add("has-bg-image")
139
+ body.style.setProperty("--bg-image-path", `url("${document.querySelector("#output_image > div.image-container.svelte-1p15vfy > button > div > img").src}")`)
140
+ }, 400)
141
+ setTimeout(() => {
142
+ document.querySelector("gradio-app").style.opacity = "1"
143
+ document.querySelector("#output_image > div.image-container.svelte-1p15vfy > button > div > img").style.opacity = "1"
144
+ document.querySelector("#dominant_image_color > label > textarea").value = ""
145
+ }, 800)
146
+ setTimeout(() => {
147
+ //document.querySelector("body > gradio-app > div").classList.remove("fade-bg")
148
+ }, 2000)
149
+ }
150
+ //document.querySelector("body").style.setProperty("--primary-700", document.querySelector("#dominant_image_color > label > textarea").value)
151
+ })
152
+
153
+ // MARK: SVGs
154
  random_prompt_btn.innerHTML =
155
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><g data-name="Ebene_1"><path fill="none" d="M0 48V0h48v48z"/><path d="M42.15 9.85C41.58 9.28 40.9 9 40.12 9H7.88c-.78 0-1.46.28-2.03.85S5 11.1 5 11.88v24.23c0 .78.28 1.46.85 2.03s1.25.85 2.03.85h32.23c.78 0 1.46-.28 2.03-.85s.85-1.25.85-2.03V11.88c0-.78-.28-1.46-.85-2.03ZM13.66 30.78c-.68 0-1.24-.55-1.24-1.24s.55-1.24 1.24-1.24 1.24.55 1.24 1.24-.55 1.24-1.24 1.24Zm2.8-7.78-1.3 1.8c-.32.45-.41.76-.48 1.23-.04.26-.13.48-.28.64-.17.19-.42.29-.73.29s-.56-.12-.73-.31c-.16-.18-.25-.42-.25-.73 0-.68.12-1.09.65-1.8l1.48-2c.33-.45.58-.87.58-1.47 0-1.04-.75-1.83-1.83-1.83-.52 0-.99.15-1.36.52-.29.29-.43.65-.55 1.12-.06.22-.16.47-.27.58-.15.17-.39.29-.7.29-.26 0-.49-.1-.66-.29-.18-.2-.23-.42-.23-.71 0-.67.35-1.58 1.03-2.22.68-.65 1.62-1.03 2.73-1.03 2.11 0 3.79 1.4 3.79 3.57 0 1-.35 1.62-.89 2.36Zm7.28 7.78c-.68 0-1.24-.55-1.24-1.24s.55-1.24 1.24-1.24 1.24.55 1.24 1.24-.55 1.24-1.24 1.24Zm2.8-7.78-1.3 1.8c-.32.45-.41.76-.48 1.23-.04.26-.13.48-.28.64-.17.19-.42.29-.73.29s-.56-.12-.73-.31c-.16-.18-.25-.42-.25-.73 0-.68.12-1.09.65-1.8l1.48-2c.33-.45.58-.87.58-1.47 0-1.04-.75-1.83-1.83-1.83-.52 0-.99.15-1.36.52-.29.29-.43.65-.55 1.12-.06.22-.16.47-.27.58-.15.17-.39.29-.7.29-.26 0-.49-.1-.66-.29-.18-.2-.23-.42-.23-.71 0-.67.35-1.58 1.03-2.22.68-.65 1.62-1.03 2.73-1.03 2.11 0 3.79 1.4 3.79 3.57 0 1-.35 1.62-.89 2.36Zm7.28 7.78c-.68 0-1.24-.55-1.24-1.24s.55-1.24 1.24-1.24 1.24.55 1.24 1.24-.55 1.24-1.24 1.24Zm2.8-7.78-1.3 1.8c-.32.45-.41.76-.48 1.23-.04.26-.13.48-.28.64-.17.19-.42.29-.73.29s-.56-.12-.73-.31c-.16-.18-.25-.42-.25-.73 0-.68.12-1.09.65-1.8l1.48-2c.33-.45.58-.87.58-1.47 0-1.04-.75-1.83-1.83-1.83-.52 0-.99.15-1.36.52-.29.29-.43.65-.55 1.12-.06.22-.16.47-.27.58-.15.17-.39.29-.7.29-.26 0-.49-.1-.66-.29-.18-.2-.23-.42-.23-.71 0-.67.35-1.58 1.03-2.22.68-.65 1.62-1.03 2.73-1.03 2.11 0 3.79 1.4 3.79 3.57 0 1-.35 1.62-.89 2.36Z"/></g></svg>'
156
  const enhance_prompt_btn = document.querySelector("#enhance_prompt_btn")