fix: bidirectional eingabe update, hexToHsl null check, import validation, harmony umlauts
This commit is contained in:
@@ -108,14 +108,17 @@ export function importCollection() {
|
|||||||
const data = load();
|
const data = load();
|
||||||
const existingFavHexes = new Set(data.favoriten.map(hslToHex));
|
const existingFavHexes = new Set(data.favoriten.map(hslToHex));
|
||||||
(imported.favoriten || []).forEach(hsl => {
|
(imported.favoriten || []).forEach(hsl => {
|
||||||
|
if (!hsl || typeof hsl.h !== 'number' || typeof hsl.s !== 'number' || typeof hsl.l !== 'number') return;
|
||||||
if (!existingFavHexes.has(hslToHex(hsl))) data.favoriten.push(hsl);
|
if (!existingFavHexes.has(hslToHex(hsl))) data.favoriten.push(hsl);
|
||||||
});
|
});
|
||||||
const existingSchemaNames = new Set(data.schemata.map(s => s.name));
|
const existingSchemaNames = new Set(data.schemata.map(s => s.name));
|
||||||
(imported.schemata || []).forEach(s => {
|
(imported.schemata || []).forEach(s => {
|
||||||
|
if (!s || typeof s.name !== 'string' || !Array.isArray(s.farben)) return;
|
||||||
if (!existingSchemaNames.has(s.name)) data.schemata.push(s);
|
if (!existingSchemaNames.has(s.name)) data.schemata.push(s);
|
||||||
});
|
});
|
||||||
const existingHistHexes = new Set(data.history.map(hslToHex));
|
const existingHistHexes = new Set(data.history.map(hslToHex));
|
||||||
(imported.history || []).forEach(hsl => {
|
(imported.history || []).forEach(hsl => {
|
||||||
|
if (!hsl || typeof hsl.h !== 'number' || typeof hsl.s !== 'number' || typeof hsl.l !== 'number') return;
|
||||||
if (!existingHistHexes.has(hslToHex(hsl))) data.history.push(hsl);
|
if (!existingHistHexes.has(hslToHex(hsl))) data.history.push(hsl);
|
||||||
});
|
});
|
||||||
if (data.history.length > 20) data.history = data.history.slice(0, 20);
|
if (data.history.length > 20) data.history = data.history.slice(0, 20);
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ export function hslToHex(hsl) {
|
|||||||
|
|
||||||
// Hex → HSL
|
// Hex → HSL
|
||||||
export function hexToHsl(hex) {
|
export function hexToHsl(hex) {
|
||||||
return rgbToHsl(hexToRgb(hex));
|
const rgb = hexToRgb(hex);
|
||||||
|
if (!rgb) return null;
|
||||||
|
return rgbToHsl(rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Harmonien — Input: HSL, Output: Objekt mit Arrays von HSL-Objekten
|
// Harmonien — Input: HSL, Output: Objekt mit Arrays von HSL-Objekten
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
|
|||||||
if (/^#[0-9a-fA-F]{6}$/.test(val)) {
|
if (/^#[0-9a-fA-F]{6}$/.test(val)) {
|
||||||
const hsl = hexToHsl(val);
|
const hsl = hexToHsl(val);
|
||||||
state.setColor(hsl);
|
state.setColor(hsl);
|
||||||
|
updateUI(hsl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
|
|||||||
if (rgb) {
|
if (rgb) {
|
||||||
const hsl = rgbToHsl(rgb);
|
const hsl = rgbToHsl(rgb);
|
||||||
state.setColor(hsl);
|
state.setColor(hsl);
|
||||||
|
updateUI(hsl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ export function initEingabe(onSaveFavorit, onSaveSchema) {
|
|||||||
const hsl = parseHsl(hslInput.value);
|
const hsl = parseHsl(hslInput.value);
|
||||||
if (hsl) {
|
if (hsl) {
|
||||||
state.setColor(hsl);
|
state.setColor(hsl);
|
||||||
|
updateUI(hsl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ function render(onSaveFavorit, onSaveSchema) {
|
|||||||
grid.textContent = '';
|
grid.textContent = '';
|
||||||
|
|
||||||
const h = getHarmonies(hsl);
|
const h = getHarmonies(hsl);
|
||||||
grid.appendChild(renderHarmony('Komplementar', h.komplementaer, onSaveFavorit, onSaveSchema));
|
grid.appendChild(renderHarmony('Komplementär', h.komplementaer, onSaveFavorit, onSaveSchema));
|
||||||
grid.appendChild(renderHarmony('Analog', h.analog, onSaveFavorit, onSaveSchema));
|
grid.appendChild(renderHarmony('Analog', h.analog, onSaveFavorit, onSaveSchema));
|
||||||
grid.appendChild(renderHarmony('Triade', h.triade, onSaveFavorit, onSaveSchema));
|
grid.appendChild(renderHarmony('Triade', h.triade, onSaveFavorit, onSaveSchema));
|
||||||
grid.appendChild(renderHarmony('Split-Komplementar', h.splitKomplementaer, onSaveFavorit, onSaveSchema));
|
grid.appendChild(renderHarmony('Split-Komplementär', h.splitKomplementaer, onSaveFavorit, onSaveSchema));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initHarmonien(onSaveFavorit, onSaveSchema) {
|
export function initHarmonien(onSaveFavorit, onSaveSchema) {
|
||||||
|
|||||||
Reference in New Issue
Block a user