fix: prevent double updateUI, move imports to top, label for attributes

This commit is contained in:
Ferdinand
2026-04-01 16:22:37 +02:00
parent cf9cdb2f6e
commit 36d0253668
3 changed files with 13 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
import { hexToRgb, rgbToHex, hexToHsl, hslToHex, hslToRgb, rgbToHsl } from './converter.js';
import { hexToHsl, hslToHex, hslToRgb, rgbToHsl } from './converter.js';
import { state } from './app.js';
function hslToDisplay({ h, s, l }) { return h + ', ' + s + '%, ' + l + '%'; }
@@ -39,7 +39,6 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
if (/^#[0-9a-fA-F]{6}$/.test(val)) {
const hsl = hexToHsl(val);
state.setColor(hsl);
updateUI(hsl);
}
});
@@ -48,7 +47,6 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
if (rgb) {
const hsl = rgbToHsl(rgb);
state.setColor(hsl);
updateUI(hsl);
}
});
@@ -56,11 +54,16 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
const hsl = parseHsl(hslInput.value);
if (hsl) {
state.setColor(hsl);
updateUI(hsl);
}
});
document.addEventListener('colorChanged', () => updateUI(state.color));
document.addEventListener('colorChanged', () => {
if (document.activeElement !== hexInput &&
document.activeElement !== rgbInput &&
document.activeElement !== hslInput) {
updateUI(state.color);
}
});
document.getElementById('eingabe-fav-btn').addEventListener('click', () => {
onSaveFavorit(state.color);