Skip to content

Commit 6a6e533

Browse files
committed
Fix StyleEditor Issue not saving the current theme
1 parent d4cbe20 commit 6a6e533

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

extensions-builtin/anapnoe-sd-theme-editor/javascript/ui_theme.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -129,43 +129,46 @@ function offsetColorsHSV(ohsl) {
129129
for (const key in styleobj) {
130130
let keyVal = styleobj[key];
131131

132-
if (keyVal.includes("#") || keyVal.includes("hsl")) {
133-
const colcomp = document.body.querySelector(`#${key} input`);
132+
if (key != "") {
134133

135-
if (colcomp) {
136-
let hsl;
134+
if (keyVal.includes("#") || keyVal.includes("hsl")) {
135+
const colcomp = document.body.querySelector(`#${key} input`);
137136

138-
if (keyVal.includes("#")) {
139-
keyVal = keyVal.replace(/\s+/g, "");
137+
if (colcomp) {
138+
let hsl;
140139

141-
if (isColorsInv) {
142-
keyVal = invertColor(keyVal);
143-
styleobj[key] = keyVal;
144-
}
140+
if (keyVal.includes("#")) {
141+
keyVal = keyVal.replace(/\s+/g, "");
142+
143+
if (isColorsInv) {
144+
keyVal = invertColor(keyVal);
145+
styleobj[key] = keyVal;
146+
}
145147

146-
hsl = rgbToHsl(hexToRgb(keyVal));
147-
} else {
148-
if (isColorsInv) {
149-
const c = toHSLArray(keyVal);
150-
const _hex = hslToHex(c[0], c[1], c[2]);
151-
styleobj[key] = invertColor(_hex);
152-
hsl = rgbToHsl(hexToRgb(styleobj[key]));
148+
hsl = rgbToHsl(hexToRgb(keyVal));
153149
} else {
154-
hsl = toHSLArray(keyVal);
150+
if (isColorsInv) {
151+
const c = toHSLArray(keyVal);
152+
const _hex = hslToHex(c[0], c[1], c[2]);
153+
styleobj[key] = invertColor(_hex);
154+
hsl = rgbToHsl(hexToRgb(styleobj[key]));
155+
} else {
156+
hsl = toHSLArray(keyVal);
157+
}
155158
}
156-
}
157159

158-
const h = (parseInt(hsl[0]) + parseInt(ohsl[0])) % 360;
159-
const s = Math.min(Math.max(parseInt(hsl[1]) + parseInt(ohsl[1]), 0), 100);
160-
const l = Math.min(Math.max(parseInt(hsl[2]) + parseInt(ohsl[2]), 0), 100);
160+
const h = (parseInt(hsl[0]) + parseInt(ohsl[0])) % 360;
161+
const s = Math.min(Math.max(parseInt(hsl[1]) + parseInt(ohsl[1]), 0), 100);
162+
const l = Math.min(Math.max(parseInt(hsl[2]) + parseInt(ohsl[2]), 0), 100);
161163

162-
const hex = hslToHex(h, s, l);
163-
colcomp.value = hex;
164-
hslobj[key] = `hsl(${h}deg ${s}% ${l}%)`;
165-
inner_styles += `${key}:${hslobj[key]};`;
164+
const hex = hslToHex(h, s, l);
165+
colcomp.value = hex;
166+
hslobj[key] = `hsl(${h}deg ${s}% ${l}%)`;
167+
inner_styles += `${key}:${hslobj[key]};`;
168+
}
169+
} else {
170+
inner_styles += `${key}:${styleobj[key]};`;
166171
}
167-
} else {
168-
inner_styles += `${key}:${styleobj[key]};`;
169172
}
170173
}
171174

@@ -229,6 +232,7 @@ function initTheme(styles) {
229232
const vars_textarea = document.body.querySelector("#theme_vars textarea");
230233
const css_textarea = document.body.querySelector("#theme_css textarea");
231234
vars_textarea.value = init_css_vars;
235+
window.updateInput(vars_textarea);
232236
const additional_styles = css_styles[1] !== undefined ? css_styles[1] : "";
233237
css_textarea.value = `/*BREAKPOINT_CSS_CONTENT*/${additional_styles}/*BREAKPOINT_CSS_CONTENT*/`;
234238
updateTheme(init_vars);
@@ -291,6 +295,7 @@ function initTheme(styles) {
291295
if (init_css_vars !== vars_textarea.value) {
292296
clearInterval(intervalCheck);
293297
init_css_vars = vars_textarea.value.replace(/\n|\r/g, "");
298+
init_css_vars = init_css_vars.split(":root{")[0];
294299
vars_textarea.value = init_css_vars;
295300
const vars = init_css_vars.split(";");
296301
updateTheme(vars);

extensions-builtin/anapnoe-sd-theme-editor/scripts/ui_theme.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def on_ui_tabs():
9292
def save_theme(vars_text, css_text, filename):
9393
style_data = ":root{" + vars_text + "}" + css_text
9494
with open(os.path.join(themes_folder, f"{filename}.css"), 'w', encoding="utf-8") as file:
95-
file.write(style_data) # Updated to save complete data
95+
file.write(vars_text)
96+
with open(webui_style_path, 'w', encoding="utf-8") as file:
97+
file.write(style_data)
9698
themes_dropdown.choices = get_files(themes_folder, [".css", ".txt"])
9799
return gr.update(choices=themes_dropdown.choices, value=f"{filename}.css")
98100

extensions-builtin/anapnoe-sd-theme-editor/themes/sdxl_thick_group_green.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)